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 static int issue_thinkpad_cmos_command(int cmos_cmd
)
281 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
287 /*************************************************************************
291 static void drv_acpi_handle_init(char *name
,
292 acpi_handle
*handle
, acpi_handle parent
,
293 char **paths
, int num_paths
, char **path
)
298 for (i
= 0; i
< num_paths
; i
++) {
299 status
= acpi_get_handle(parent
, paths
[i
], handle
);
300 if (ACPI_SUCCESS(status
)) {
309 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
311 struct ibm_struct
*ibm
= data
;
313 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
316 ibm
->acpi
->notify(ibm
, event
);
319 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
326 if (!*ibm
->acpi
->handle
)
329 dbg_printk(TPACPI_DBG_INIT
,
330 "setting up ACPI notify for %s\n", ibm
->name
);
332 ret
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
334 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
338 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
339 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
340 IBM_ACPI_EVENT_PREFIX
,
343 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
344 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
345 if (ACPI_FAILURE(status
)) {
346 if (status
== AE_ALREADY_EXISTS
) {
347 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
350 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
355 ibm
->flags
.acpi_notify_installed
= 1;
359 static int __init
tpacpi_device_add(struct acpi_device
*device
)
364 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
368 dbg_printk(TPACPI_DBG_INIT
,
369 "registering %s as an ACPI driver\n", ibm
->name
);
373 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
374 if (!ibm
->acpi
->driver
) {
375 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
379 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
380 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
381 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
383 ret
= acpi_bus_register_driver(ibm
->acpi
->driver
);
385 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
386 ibm
->acpi
->hid
, ret
);
387 kfree(ibm
->acpi
->driver
);
388 ibm
->acpi
->driver
= NULL
;
390 ibm
->flags
.acpi_driver_registered
= 1;
396 /****************************************************************************
397 ****************************************************************************
401 ****************************************************************************
402 ****************************************************************************/
404 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
405 int count
, int *eof
, void *data
)
407 struct ibm_struct
*ibm
= data
;
410 if (!ibm
|| !ibm
->read
)
413 len
= ibm
->read(page
);
417 if (len
<= off
+ count
)
429 static int dispatch_procfs_write(struct file
*file
,
430 const char __user
* userbuf
,
431 unsigned long count
, void *data
)
433 struct ibm_struct
*ibm
= data
;
437 if (!ibm
|| !ibm
->write
)
440 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
444 if (copy_from_user(kernbuf
, userbuf
, count
)) {
450 strcat(kernbuf
, ",");
451 ret
= ibm
->write(kernbuf
);
460 static char *next_cmd(char **cmds
)
465 while ((end
= strchr(start
, ',')) && end
== start
)
477 /****************************************************************************
478 ****************************************************************************
482 ****************************************************************************
483 ****************************************************************************/
485 /*************************************************************************
486 * thinkpad-acpi init subdriver
489 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
491 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
492 printk(IBM_INFO
"%s\n", IBM_URL
);
494 if (ibm_thinkpad_ec_found
)
495 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
496 ibm_thinkpad_ec_found
);
501 static int thinkpad_acpi_driver_read(char *p
)
505 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
506 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
511 static struct ibm_struct thinkpad_acpi_driver_data
= {
513 .read
= thinkpad_acpi_driver_read
,
516 /*************************************************************************
520 static int hotkey_orig_status
;
521 static int hotkey_orig_mask
;
523 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
527 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
529 IBM_ACPIHANDLE_INIT(hkey
);
531 /* hotkey not supported on 570 */
532 tp_features
.hotkey
= hkey_handle
!= NULL
;
534 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
535 str_supported(tp_features
.hotkey
));
537 if (tp_features
.hotkey
) {
538 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
539 A30, R30, R31, T20-22, X20-21, X22-24 */
540 tp_features
.hotkey_mask
=
541 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
543 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
544 str_supported(tp_features
.hotkey_mask
));
546 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
551 return (tp_features
.hotkey
)? 0 : 1;
554 static void hotkey_exit(void)
558 if (tp_features
.hotkey
) {
559 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
560 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
562 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
566 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
570 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
571 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
573 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
574 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
578 static int hotkey_get(int *status
, int *mask
)
580 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
583 if (tp_features
.hotkey_mask
)
584 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
590 static int hotkey_set(int status
, int mask
)
594 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
597 if (tp_features
.hotkey_mask
)
598 for (i
= 0; i
< 32; i
++) {
599 int bit
= ((1 << i
) & mask
) != 0;
600 if (!acpi_evalf(hkey_handle
,
601 NULL
, "MHKM", "vdd", i
+ 1, bit
))
608 static int hotkey_read(char *p
)
610 int res
, status
, mask
;
613 if (!tp_features
.hotkey
) {
614 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
618 res
= hotkey_get(&status
, &mask
);
622 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
623 if (tp_features
.hotkey_mask
) {
624 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
625 len
+= sprintf(p
+ len
,
626 "commands:\tenable, disable, reset, <mask>\n");
628 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
629 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
635 static int hotkey_write(char *buf
)
637 int res
, status
, mask
;
641 if (!tp_features
.hotkey
)
644 res
= hotkey_get(&status
, &mask
);
648 while ((cmd
= next_cmd(&buf
))) {
649 if (strlencmp(cmd
, "enable") == 0) {
651 } else if (strlencmp(cmd
, "disable") == 0) {
653 } else if (strlencmp(cmd
, "reset") == 0) {
654 status
= hotkey_orig_status
;
655 mask
= hotkey_orig_mask
;
656 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
658 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
666 res
= hotkey_set(status
, mask
);
674 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
676 .notify
= hotkey_notify
,
677 .handle
= &hkey_handle
,
678 .type
= ACPI_DEVICE_NOTIFY
,
681 static struct ibm_struct hotkey_driver_data
= {
684 .write
= hotkey_write
,
686 .acpi
= &ibm_hotkey_acpidriver
,
689 /*************************************************************************
690 * Bluetooth subdriver
693 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
697 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
699 IBM_ACPIHANDLE_INIT(hkey
);
701 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
702 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
703 tp_features
.bluetooth
= hkey_handle
&&
704 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
706 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
707 str_supported(tp_features
.bluetooth
),
710 if (tp_features
.bluetooth
&&
711 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
712 /* no bluetooth hardware present in system */
713 tp_features
.bluetooth
= 0;
714 dbg_printk(TPACPI_DBG_INIT
,
715 "bluetooth hardware not installed\n");
718 return (tp_features
.bluetooth
)? 0 : 1;
721 static int bluetooth_get_radiosw(void)
725 if (!tp_features
.bluetooth
)
728 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
731 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
734 static int bluetooth_set_radiosw(int radio_on
)
738 if (!tp_features
.bluetooth
)
741 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
744 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
746 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
747 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
753 static int bluetooth_read(char *p
)
756 int status
= bluetooth_get_radiosw();
758 if (!tp_features
.bluetooth
)
759 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
761 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
762 (status
)? "enabled" : "disabled");
763 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
769 static int bluetooth_write(char *buf
)
773 if (!tp_features
.bluetooth
)
776 while ((cmd
= next_cmd(&buf
))) {
777 if (strlencmp(cmd
, "enable") == 0) {
778 bluetooth_set_radiosw(1);
779 } else if (strlencmp(cmd
, "disable") == 0) {
780 bluetooth_set_radiosw(0);
788 static struct ibm_struct bluetooth_driver_data
= {
790 .read
= bluetooth_read
,
791 .write
= bluetooth_write
,
794 /*************************************************************************
798 static int __init
wan_init(struct ibm_init_struct
*iibm
)
802 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
804 IBM_ACPIHANDLE_INIT(hkey
);
806 tp_features
.wan
= hkey_handle
&&
807 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
809 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
810 str_supported(tp_features
.wan
),
813 if (tp_features
.wan
&&
814 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
815 /* no wan hardware present in system */
817 dbg_printk(TPACPI_DBG_INIT
,
818 "wan hardware not installed\n");
821 return (tp_features
.wan
)? 0 : 1;
824 static int wan_get_radiosw(void)
828 if (!tp_features
.wan
)
831 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
834 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
837 static int wan_set_radiosw(int radio_on
)
841 if (!tp_features
.wan
)
844 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
847 status
|= TP_ACPI_WANCARD_RADIOSSW
;
849 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
850 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
856 static int wan_read(char *p
)
859 int status
= wan_get_radiosw();
861 if (!tp_features
.wan
)
862 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
864 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
865 (status
)? "enabled" : "disabled");
866 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
872 static int wan_write(char *buf
)
876 if (!tp_features
.wan
)
879 while ((cmd
= next_cmd(&buf
))) {
880 if (strlencmp(cmd
, "enable") == 0) {
882 } else if (strlencmp(cmd
, "disable") == 0) {
891 static struct ibm_struct wan_driver_data
= {
895 .flags
.experimental
= 1,
898 /*************************************************************************
902 static enum video_access_mode video_supported
;
903 static int video_orig_autosw
;
905 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
906 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
907 "\\_SB.PCI0.VID0", /* 770e */
908 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
909 "\\_SB.PCI0.AGP.VID", /* all others */
912 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
914 static int __init
video_init(struct ibm_init_struct
*iibm
)
918 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
920 IBM_ACPIHANDLE_INIT(vid
);
921 IBM_ACPIHANDLE_INIT(vid2
);
923 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
924 /* G41, assume IVGA doesn't change */
925 vid_handle
= vid2_handle
;
928 /* video switching not supported on R30, R31 */
929 video_supported
= TPACPI_VIDEO_NONE
;
930 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
932 video_supported
= TPACPI_VIDEO_570
;
933 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
934 /* 600e/x, 770e, 770x */
935 video_supported
= TPACPI_VIDEO_770
;
938 video_supported
= TPACPI_VIDEO_NEW
;
940 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
941 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
944 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
947 static void video_exit(void)
949 dbg_printk(TPACPI_DBG_EXIT
,
950 "restoring original video autoswitch mode\n");
951 if (video_autosw_set(video_orig_autosw
))
952 printk(IBM_ERR
"error while trying to restore original "
953 "video autoswitch mode\n");
956 static int video_outputsw_get(void)
961 switch (video_supported
) {
962 case TPACPI_VIDEO_570
:
963 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
964 TP_ACPI_VIDEO_570_PHSCMD
))
966 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
968 case TPACPI_VIDEO_770
:
969 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
972 status
|= TP_ACPI_VIDEO_S_LCD
;
973 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
976 status
|= TP_ACPI_VIDEO_S_CRT
;
978 case TPACPI_VIDEO_NEW
:
979 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
980 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
983 status
|= TP_ACPI_VIDEO_S_CRT
;
985 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
986 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
989 status
|= TP_ACPI_VIDEO_S_LCD
;
990 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
993 status
|= TP_ACPI_VIDEO_S_DVI
;
1002 static int video_outputsw_set(int status
)
1007 switch (video_supported
) {
1008 case TPACPI_VIDEO_570
:
1009 res
= acpi_evalf(NULL
, NULL
,
1010 "\\_SB.PHS2", "vdd",
1011 TP_ACPI_VIDEO_570_PHS2CMD
,
1012 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1014 case TPACPI_VIDEO_770
:
1015 autosw
= video_autosw_get();
1019 res
= video_autosw_set(1);
1022 res
= acpi_evalf(vid_handle
, NULL
,
1023 "ASWT", "vdd", status
* 0x100, 0);
1024 if (!autosw
&& video_autosw_set(autosw
)) {
1025 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1029 case TPACPI_VIDEO_NEW
:
1030 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1031 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1037 return (res
)? 0 : -EIO
;
1040 static int video_autosw_get(void)
1044 switch (video_supported
) {
1045 case TPACPI_VIDEO_570
:
1046 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1049 case TPACPI_VIDEO_770
:
1050 case TPACPI_VIDEO_NEW
:
1051 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1061 static int video_autosw_set(int enable
)
1063 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1068 static int video_outputsw_cycle(void)
1070 int autosw
= video_autosw_get();
1076 switch (video_supported
) {
1077 case TPACPI_VIDEO_570
:
1078 res
= video_autosw_set(1);
1081 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1083 case TPACPI_VIDEO_770
:
1084 case TPACPI_VIDEO_NEW
:
1085 res
= video_autosw_set(1);
1088 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1093 if (!autosw
&& video_autosw_set(autosw
)) {
1094 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1098 return (res
)? 0 : -EIO
;
1101 static int video_expand_toggle(void)
1103 switch (video_supported
) {
1104 case TPACPI_VIDEO_570
:
1105 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1107 case TPACPI_VIDEO_770
:
1108 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1110 case TPACPI_VIDEO_NEW
:
1111 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1119 static int video_read(char *p
)
1124 if (video_supported
== TPACPI_VIDEO_NONE
) {
1125 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1129 status
= video_outputsw_get();
1133 autosw
= video_autosw_get();
1137 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1138 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
1139 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
1140 if (video_supported
== TPACPI_VIDEO_NEW
)
1141 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
1142 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
1143 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
1144 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
1145 if (video_supported
== TPACPI_VIDEO_NEW
)
1146 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
1147 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
1148 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
1153 static int video_write(char *buf
)
1156 int enable
, disable
, status
;
1159 if (video_supported
== TPACPI_VIDEO_NONE
)
1165 while ((cmd
= next_cmd(&buf
))) {
1166 if (strlencmp(cmd
, "lcd_enable") == 0) {
1167 enable
|= TP_ACPI_VIDEO_S_LCD
;
1168 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1169 disable
|= TP_ACPI_VIDEO_S_LCD
;
1170 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1171 enable
|= TP_ACPI_VIDEO_S_CRT
;
1172 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1173 disable
|= TP_ACPI_VIDEO_S_CRT
;
1174 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1175 strlencmp(cmd
, "dvi_enable") == 0) {
1176 enable
|= TP_ACPI_VIDEO_S_DVI
;
1177 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1178 strlencmp(cmd
, "dvi_disable") == 0) {
1179 disable
|= TP_ACPI_VIDEO_S_DVI
;
1180 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1181 res
= video_autosw_set(1);
1184 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1185 res
= video_autosw_set(0);
1188 } else if (strlencmp(cmd
, "video_switch") == 0) {
1189 res
= video_outputsw_cycle();
1192 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1193 res
= video_expand_toggle();
1200 if (enable
|| disable
) {
1201 status
= video_outputsw_get();
1204 res
= video_outputsw_set((status
& ~disable
) | enable
);
1212 static struct ibm_struct video_driver_data
= {
1215 .write
= video_write
,
1219 /*************************************************************************
1220 * Light (thinklight) subdriver
1223 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1224 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1226 static int __init
light_init(struct ibm_init_struct
*iibm
)
1228 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
1230 IBM_ACPIHANDLE_INIT(ledb
);
1231 IBM_ACPIHANDLE_INIT(lght
);
1232 IBM_ACPIHANDLE_INIT(cmos
);
1234 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1235 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1237 if (tp_features
.light
)
1238 /* light status not supported on
1239 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1240 tp_features
.light_status
=
1241 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
1243 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
1244 str_supported(tp_features
.light
));
1246 return (tp_features
.light
)? 0 : 1;
1249 static int light_read(char *p
)
1254 if (!tp_features
.light
) {
1255 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1256 } else if (!tp_features
.light_status
) {
1257 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1258 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1260 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1262 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1263 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1269 static int light_write(char *buf
)
1271 int cmos_cmd
, lght_cmd
;
1275 if (!tp_features
.light
)
1278 while ((cmd
= next_cmd(&buf
))) {
1279 if (strlencmp(cmd
, "on") == 0) {
1282 } else if (strlencmp(cmd
, "off") == 0) {
1288 success
= cmos_handle
?
1289 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1290 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1298 static struct ibm_struct light_driver_data
= {
1301 .write
= light_write
,
1304 /*************************************************************************
1308 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1310 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
1311 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1312 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1313 "\\_SB.PCI.ISA.SLCE", /* 570 */
1314 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1316 /* don't list other alternatives as we install a notify handler on the 570 */
1317 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
1319 #define dock_docked() (_sta(dock_handle) & 1)
1321 static int __init
dock_init(struct ibm_init_struct
*iibm
)
1323 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
1325 IBM_ACPIHANDLE_INIT(dock
);
1326 IBM_ACPIHANDLE_INIT(pci
);
1328 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
1329 str_supported(dock_handle
!= NULL
));
1331 return (dock_handle
)? 0 : 1;
1334 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1336 int docked
= dock_docked();
1337 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, IBM_PCI_HID
);
1339 if (event
== 1 && !pci
) /* 570 */
1340 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1341 else if (event
== 1 && pci
) /* 570 */
1342 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1343 else if (event
== 3 && docked
)
1344 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1345 else if (event
== 3 && !docked
)
1346 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
1347 else if (event
== 0 && docked
)
1348 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1350 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1351 event
, _sta(dock_handle
));
1352 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
1356 static int dock_read(char *p
)
1359 int docked
= dock_docked();
1362 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1364 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1366 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1367 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1373 static int dock_write(char *buf
)
1380 while ((cmd
= next_cmd(&buf
))) {
1381 if (strlencmp(cmd
, "undock") == 0) {
1382 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1383 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1385 } else if (strlencmp(cmd
, "dock") == 0) {
1386 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1395 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
1397 .notify
= dock_notify
,
1398 .handle
= &dock_handle
,
1399 .type
= ACPI_SYSTEM_NOTIFY
,
1403 .notify
= dock_notify
,
1404 .handle
= &pci_handle
,
1405 .type
= ACPI_SYSTEM_NOTIFY
,
1409 static struct ibm_struct dock_driver_data
[2] = {
1413 .write
= dock_write
,
1414 .acpi
= &ibm_dock_acpidriver
[0],
1418 .acpi
= &ibm_dock_acpidriver
[1],
1422 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1424 /*************************************************************************
1428 #ifdef CONFIG_THINKPAD_ACPI_BAY
1429 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1430 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1431 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1432 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1433 ); /* A21e, R30, R31 */
1434 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
1435 "_EJ0", /* all others */
1436 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1437 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1438 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1440 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
1444 static int __init
bay_init(struct ibm_init_struct
*iibm
)
1446 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
1448 IBM_ACPIHANDLE_INIT(bay
);
1450 IBM_ACPIHANDLE_INIT(bay_ej
);
1451 IBM_ACPIHANDLE_INIT(bay2
);
1453 IBM_ACPIHANDLE_INIT(bay2_ej
);
1455 tp_features
.bay_status
= bay_handle
&&
1456 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1457 tp_features
.bay_status2
= bay2_handle
&&
1458 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1460 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
1461 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1462 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
1463 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1465 vdbg_printk(TPACPI_DBG_INIT
,
1466 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1467 str_supported(tp_features
.bay_status
),
1468 str_supported(tp_features
.bay_eject
),
1469 str_supported(tp_features
.bay_status2
),
1470 str_supported(tp_features
.bay_eject2
));
1472 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
1473 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
1476 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1478 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1481 #define bay_occupied(b) (_sta(b##_handle) & 1)
1483 static int bay_read(char *p
)
1486 int occupied
= bay_occupied(bay
);
1487 int occupied2
= bay_occupied(bay2
);
1490 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1491 tp_features
.bay_status
?
1492 (occupied
? "occupied" : "unoccupied") :
1494 if (tp_features
.bay_status2
)
1495 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1496 "occupied" : "unoccupied");
1498 eject
= tp_features
.bay_eject
&& occupied
;
1499 eject2
= tp_features
.bay_eject2
&& occupied2
;
1501 if (eject
&& eject2
)
1502 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1504 len
+= sprintf(p
+ len
, "commands:\teject\n");
1506 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1511 static int bay_write(char *buf
)
1515 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
1518 while ((cmd
= next_cmd(&buf
))) {
1519 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
1520 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1522 } else if (tp_features
.bay_eject2
&&
1523 strlencmp(cmd
, "eject2") == 0) {
1524 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1533 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
1534 .notify
= bay_notify
,
1535 .handle
= &bay_handle
,
1536 .type
= ACPI_SYSTEM_NOTIFY
,
1539 static struct ibm_struct bay_driver_data
= {
1543 .acpi
= &ibm_bay_acpidriver
,
1546 #endif /* CONFIG_THINKPAD_ACPI_BAY */
1548 /*************************************************************************
1552 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
1554 vdbg_printk(TPACPI_DBG_INIT
,
1555 "initializing cmos commands subdriver\n");
1557 IBM_ACPIHANDLE_INIT(cmos
);
1559 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
1560 str_supported(cmos_handle
!= NULL
));
1561 return (cmos_handle
)? 0 : 1;
1564 static int cmos_read(char *p
)
1568 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1569 R30, R31, T20-22, X20-21 */
1571 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1573 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1574 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1580 static int cmos_write(char *buf
)
1585 while ((cmd
= next_cmd(&buf
))) {
1586 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1587 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1592 res
= issue_thinkpad_cmos_command(cmos_cmd
);
1600 static struct ibm_struct cmos_driver_data
= {
1603 .write
= cmos_write
,
1606 /*************************************************************************
1610 static enum led_access_mode led_supported
;
1612 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
1613 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1614 "LED", /* all others */
1617 static int __init
led_init(struct ibm_init_struct
*iibm
)
1619 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
1621 IBM_ACPIHANDLE_INIT(led
);
1624 /* led not supported on R30, R31 */
1625 led_supported
= TPACPI_LED_NONE
;
1626 else if (strlencmp(led_path
, "SLED") == 0)
1628 led_supported
= TPACPI_LED_570
;
1629 else if (strlencmp(led_path
, "SYSL") == 0)
1630 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1631 led_supported
= TPACPI_LED_OLD
;
1634 led_supported
= TPACPI_LED_NEW
;
1636 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
1637 str_supported(led_supported
), led_supported
);
1639 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
1642 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1644 static int led_read(char *p
)
1648 if (!led_supported
) {
1649 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1652 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1654 if (led_supported
== TPACPI_LED_570
) {
1657 for (i
= 0; i
< 8; i
++) {
1658 if (!acpi_evalf(ec_handle
,
1659 &status
, "GLED", "dd", 1 << i
))
1661 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1662 i
, led_status(status
));
1666 len
+= sprintf(p
+ len
, "commands:\t"
1667 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1672 /* off, on, blink */
1673 static const int led_sled_arg1
[] = { 0, 1, 3 };
1674 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
1675 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
1676 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
1678 static int led_write(char *buf
)
1686 while ((cmd
= next_cmd(&buf
))) {
1687 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1690 if (strstr(cmd
, "off")) {
1692 } else if (strstr(cmd
, "on")) {
1694 } else if (strstr(cmd
, "blink")) {
1699 if (led_supported
== TPACPI_LED_570
) {
1702 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1703 led
, led_sled_arg1
[ind
]))
1705 } else if (led_supported
== TPACPI_LED_OLD
) {
1706 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1708 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
1711 ec_write(TPACPI_LED_EC_HLBL
,
1712 led
* led_exp_hlbl
[ind
]);
1715 ec_write(TPACPI_LED_EC_HLCL
,
1716 led
* led_exp_hlcl
[ind
]);
1721 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1722 led
, led_led_arg1
[ind
]))
1730 static struct ibm_struct led_driver_data
= {
1736 /*************************************************************************
1740 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
1742 static int __init
beep_init(struct ibm_init_struct
*iibm
)
1744 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
1746 IBM_ACPIHANDLE_INIT(beep
);
1748 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
1749 str_supported(beep_handle
!= NULL
));
1751 return (beep_handle
)? 0 : 1;
1754 static int beep_read(char *p
)
1759 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1761 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1762 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1768 static int beep_write(char *buf
)
1776 while ((cmd
= next_cmd(&buf
))) {
1777 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1778 beep_cmd
>= 0 && beep_cmd
<= 17) {
1782 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1789 static struct ibm_struct beep_driver_data
= {
1792 .write
= beep_write
,
1795 /*************************************************************************
1799 static enum thermal_access_mode thermal_read_mode
;
1801 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
1807 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
1809 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
1811 if (ibm_thinkpad_ec_found
&& experimental
) {
1813 * Direct EC access mode: sensors at registers
1814 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1815 * non-implemented, thermal sensors return 0x80 when
1820 for (i
= 0; i
< 8; i
++) {
1821 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
1827 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
1835 /* This is sheer paranoia, but we handle it anyway */
1838 "ThinkPad ACPI EC access misbehaving, "
1839 "falling back to ACPI TMPx access mode\n");
1840 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
1843 "ThinkPad ACPI EC access misbehaving, "
1844 "disabling thermal sensors access\n");
1845 thermal_read_mode
= TPACPI_THERMAL_NONE
;
1850 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
1852 } else if (acpi_tmp7
) {
1853 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
1854 /* 600e/x, 770e, 770x */
1855 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
1857 /* Standard ACPI TMPx access, max 8 sensors */
1858 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
1861 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1862 thermal_read_mode
= TPACPI_THERMAL_NONE
;
1865 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
1866 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
1869 return (thermal_read_mode
!= TPACPI_THERMAL_NONE
)? 0 : 1;
1872 /* idx is zero-based */
1873 static int thermal_get_sensor(int idx
, s32
*value
)
1879 t
= TP_EC_THERMAL_TMP0
;
1881 switch (thermal_read_mode
) {
1882 #if TPACPI_MAX_THERMAL_SENSORS >= 16
1883 case TPACPI_THERMAL_TPEC_16
:
1884 if (idx
>= 8 && idx
<= 15) {
1885 t
= TP_EC_THERMAL_TMP8
;
1890 case TPACPI_THERMAL_TPEC_8
:
1892 if (!acpi_ec_read(t
+ idx
, &tmp
))
1894 *value
= tmp
* 1000;
1899 case TPACPI_THERMAL_ACPI_UPDT
:
1901 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
1902 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
1904 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1906 *value
= (t
- 2732) * 100;
1911 case TPACPI_THERMAL_ACPI_TMP07
:
1913 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
1914 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1921 case TPACPI_THERMAL_NONE
:
1929 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
1940 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
1943 for(i
= 0 ; i
< n
; i
++) {
1944 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
1952 static int thermal_read(char *p
)
1956 struct ibm_thermal_sensors_struct t
;
1958 n
= thermal_get_sensors(&t
);
1959 if (unlikely(n
< 0))
1962 len
+= sprintf(p
+ len
, "temperatures:\t");
1965 for (i
= 0; i
< (n
- 1); i
++)
1966 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
1967 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
1969 len
+= sprintf(p
+ len
, "not supported\n");
1974 static struct ibm_struct thermal_driver_data
= {
1976 .read
= thermal_read
,
1979 /*************************************************************************
1983 static u8 ecdump_regs
[256];
1985 static int ecdump_read(char *p
)
1991 len
+= sprintf(p
+ len
, "EC "
1992 " +00 +01 +02 +03 +04 +05 +06 +07"
1993 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1994 for (i
= 0; i
< 256; i
+= 16) {
1995 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
1996 for (j
= 0; j
< 16; j
++) {
1997 if (!acpi_ec_read(i
+ j
, &v
))
1999 if (v
!= ecdump_regs
[i
+ j
])
2000 len
+= sprintf(p
+ len
, " *%02x", v
);
2002 len
+= sprintf(p
+ len
, " %02x", v
);
2003 ecdump_regs
[i
+ j
] = v
;
2005 len
+= sprintf(p
+ len
, "\n");
2010 /* These are way too dangerous to advertise openly... */
2012 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
2013 " (<offset> is 00-ff, <value> is 00-ff)\n");
2014 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
2015 " (<offset> is 00-ff, <value> is 0-255)\n");
2020 static int ecdump_write(char *buf
)
2025 while ((cmd
= next_cmd(&buf
))) {
2026 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
2028 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
2032 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
2033 if (!acpi_ec_write(i
, v
))
2042 static struct ibm_struct ecdump_driver_data
= {
2044 .read
= ecdump_read
,
2045 .write
= ecdump_write
,
2046 .flags
.experimental
= 1,
2049 /*************************************************************************
2050 * Backlight/brightness subdriver
2053 static struct backlight_device
*ibm_backlight_device
= NULL
;
2055 static struct backlight_ops ibm_backlight_data
= {
2056 .get_brightness
= brightness_get
,
2057 .update_status
= brightness_update_status
,
2060 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
2064 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
2066 b
= brightness_get(NULL
);
2070 ibm_backlight_device
= backlight_device_register("ibm", NULL
, NULL
,
2071 &ibm_backlight_data
);
2072 if (IS_ERR(ibm_backlight_device
)) {
2073 printk(IBM_ERR
"Could not register backlight device\n");
2074 return PTR_ERR(ibm_backlight_device
);
2076 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
2078 ibm_backlight_device
->props
.max_brightness
= 7;
2079 ibm_backlight_device
->props
.brightness
= b
;
2080 backlight_update_status(ibm_backlight_device
);
2085 static void brightness_exit(void)
2087 if (ibm_backlight_device
) {
2088 vdbg_printk(TPACPI_DBG_EXIT
,
2089 "calling backlight_device_unregister()\n");
2090 backlight_device_unregister(ibm_backlight_device
);
2091 ibm_backlight_device
= NULL
;
2095 static int brightness_update_status(struct backlight_device
*bd
)
2097 return brightness_set(
2098 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
2099 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
2100 bd
->props
.brightness
: 0);
2103 static int brightness_get(struct backlight_device
*bd
)
2106 if (!acpi_ec_read(brightness_offset
, &level
))
2114 static int brightness_set(int value
)
2116 int cmos_cmd
, inc
, i
;
2117 int current_value
= brightness_get(NULL
);
2121 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
2122 inc
= value
> current_value
? 1 : -1;
2123 for (i
= current_value
; i
!= value
; i
+= inc
) {
2124 if (issue_thinkpad_cmos_command(cmos_cmd
))
2126 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
2133 static int brightness_read(char *p
)
2138 if ((level
= brightness_get(NULL
)) < 0) {
2139 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2141 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
2142 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
2143 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2144 " (<level> is 0-7)\n");
2150 static int brightness_write(char *buf
)
2156 while ((cmd
= next_cmd(&buf
))) {
2157 if ((level
= brightness_get(NULL
)) < 0)
2161 if (strlencmp(cmd
, "up") == 0) {
2162 new_level
= level
== 7 ? 7 : level
+ 1;
2163 } else if (strlencmp(cmd
, "down") == 0) {
2164 new_level
= level
== 0 ? 0 : level
- 1;
2165 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2166 new_level
>= 0 && new_level
<= 7) {
2171 brightness_set(new_level
);
2177 static struct ibm_struct brightness_driver_data
= {
2178 .name
= "brightness",
2179 .read
= brightness_read
,
2180 .write
= brightness_write
,
2181 .exit
= brightness_exit
,
2184 /*************************************************************************
2188 static int volume_read(char *p
)
2193 if (!acpi_ec_read(volume_offset
, &level
)) {
2194 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2196 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
2197 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
2198 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
2199 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2200 " (<level> is 0-15)\n");
2206 static int volume_write(char *buf
)
2208 int cmos_cmd
, inc
, i
;
2210 int new_level
, new_mute
;
2213 while ((cmd
= next_cmd(&buf
))) {
2214 if (!acpi_ec_read(volume_offset
, &level
))
2216 new_mute
= mute
= level
& 0x40;
2217 new_level
= level
= level
& 0xf;
2219 if (strlencmp(cmd
, "up") == 0) {
2223 new_level
= level
== 15 ? 15 : level
+ 1;
2224 } else if (strlencmp(cmd
, "down") == 0) {
2228 new_level
= level
== 0 ? 0 : level
- 1;
2229 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2230 new_level
>= 0 && new_level
<= 15) {
2232 } else if (strlencmp(cmd
, "mute") == 0) {
2237 if (new_level
!= level
) { /* mute doesn't change */
2238 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
2239 inc
= new_level
> level
? 1 : -1;
2241 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
2242 !acpi_ec_write(volume_offset
, level
)))
2245 for (i
= level
; i
!= new_level
; i
+= inc
)
2246 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2247 !acpi_ec_write(volume_offset
, i
+ inc
))
2250 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
2251 !acpi_ec_write(volume_offset
,
2256 if (new_mute
!= mute
) { /* level doesn't change */
2257 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
2259 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2260 !acpi_ec_write(volume_offset
, level
+ new_mute
))
2268 static struct ibm_struct volume_driver_data
= {
2270 .read
= volume_read
,
2271 .write
= volume_write
,
2274 /*************************************************************************
2281 * TPACPI_FAN_RD_ACPI_GFAN:
2282 * ACPI GFAN method: returns fan level
2284 * see TPACPI_FAN_WR_ACPI_SFAN
2285 * EC 0x2f (HFSP) not available if GFAN exists
2287 * TPACPI_FAN_WR_ACPI_SFAN:
2288 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2290 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2293 * TPACPI_FAN_WR_TPEC:
2294 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2295 * Supported on almost all ThinkPads
2297 * Fan speed changes of any sort (including those caused by the
2298 * disengaged mode) are usually done slowly by the firmware as the
2299 * maximum ammount of fan duty cycle change per second seems to be
2302 * Reading is not available if GFAN exists.
2303 * Writing is not available if SFAN exists.
2306 * 7 automatic mode engaged;
2307 * (default operation mode of the ThinkPad)
2308 * fan level is ignored in this mode.
2309 * 6 full speed mode (takes precedence over bit 7);
2310 * not available on all thinkpads. May disable
2311 * the tachometer while the fan controller ramps up
2312 * the speed (which can take up to a few *minutes*).
2313 * Speeds up fan to 100% duty-cycle, which is far above
2314 * the standard RPM levels. It is not impossible that
2315 * it could cause hardware damage.
2316 * 5-3 unused in some models. Extra bits for fan level
2317 * in others, but still useless as all values above
2318 * 7 map to the same speed as level 7 in these models.
2319 * 2-0 fan level (0..7 usually)
2321 * 0x07 = max (set when temperatures critical)
2322 * Some ThinkPads may have other levels, see
2323 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2325 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2326 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2327 * does so, its initial value is meaningless (0x07).
2329 * For firmware bugs, refer to:
2330 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2334 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2335 * Main fan tachometer reading (in RPM)
2337 * This register is present on all ThinkPads with a new-style EC, and
2338 * it is known not to be present on the A21m/e, and T22, as there is
2339 * something else in offset 0x84 according to the ACPI DSDT. Other
2340 * ThinkPads from this same time period (and earlier) probably lack the
2341 * tachometer as well.
2343 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2344 * was never fixed by IBM to report the EC firmware version string
2345 * probably support the tachometer (like the early X models), so
2346 * detecting it is quite hard. We need more data to know for sure.
2348 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2351 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2354 * For firmware bugs, refer to:
2355 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2357 * TPACPI_FAN_WR_ACPI_FANS:
2358 * ThinkPad X31, X40, X41. Not available in the X60.
2360 * FANS ACPI handle: takes three arguments: low speed, medium speed,
2361 * high speed. ACPI DSDT seems to map these three speeds to levels
2362 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
2363 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
2365 * The speeds are stored on handles
2366 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
2368 * There are three default speed sets, acessible as handles:
2369 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
2371 * ACPI DSDT switches which set is in use depending on various
2374 * TPACPI_FAN_WR_TPEC is also available and should be used to
2375 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
2376 * but the ACPI tables just mention level 7.
2379 static enum fan_status_access_mode fan_status_access_mode
;
2380 static enum fan_control_access_mode fan_control_access_mode
;
2381 static enum fan_control_commands fan_control_commands
;
2383 static u8 fan_control_initial_status
;
2385 static void fan_watchdog_fire(struct work_struct
*ignored
);
2386 static int fan_watchdog_maxinterval
;
2387 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
2389 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
2390 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
2391 "\\FSPD", /* 600e/x, 770e, 770x */
2393 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
2394 "JFNS", /* 770x-JL */
2397 static int __init
fan_init(struct ibm_init_struct
*iibm
)
2399 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
2401 fan_status_access_mode
= TPACPI_FAN_NONE
;
2402 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
2403 fan_control_commands
= 0;
2404 fan_watchdog_maxinterval
= 0;
2405 tp_features
.fan_ctrl_status_undef
= 0;
2407 IBM_ACPIHANDLE_INIT(fans
);
2408 IBM_ACPIHANDLE_INIT(gfan
);
2409 IBM_ACPIHANDLE_INIT(sfan
);
2412 /* 570, 600e/x, 770e, 770x */
2413 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
2415 /* all other ThinkPads: note that even old-style
2416 * ThinkPad ECs supports the fan control register */
2417 if (likely(acpi_ec_read(fan_status_offset
,
2418 &fan_control_initial_status
))) {
2419 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
2421 /* In some ThinkPads, neither the EC nor the ACPI
2422 * DSDT initialize the fan status, and it ends up
2423 * being set to 0x07 when it *could* be either
2426 * Enable for TP-1Y (T43), TP-78 (R51e),
2427 * TP-76 (R52), TP-70 (T43, R52), which are known
2429 if (fan_control_initial_status
== 0x07 &&
2430 ibm_thinkpad_ec_found
&&
2431 ((ibm_thinkpad_ec_found
[0] == '1' &&
2432 ibm_thinkpad_ec_found
[1] == 'Y') ||
2433 (ibm_thinkpad_ec_found
[0] == '7' &&
2434 (ibm_thinkpad_ec_found
[1] == '6' ||
2435 ibm_thinkpad_ec_found
[1] == '8' ||
2436 ibm_thinkpad_ec_found
[1] == '0'))
2439 "fan_init: initial fan status is "
2440 "unknown, assuming it is in auto "
2442 tp_features
.fan_ctrl_status_undef
= 1;
2446 "ThinkPad ACPI EC access misbehaving, "
2447 "fan status and control unavailable\n");
2454 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
2455 fan_control_commands
|=
2456 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
2459 /* gfan without sfan means no fan control */
2460 /* all other models implement TP EC 0x2f control */
2464 fan_control_access_mode
=
2465 TPACPI_FAN_WR_ACPI_FANS
;
2466 fan_control_commands
|=
2467 TPACPI_FAN_CMD_SPEED
|
2468 TPACPI_FAN_CMD_LEVEL
|
2469 TPACPI_FAN_CMD_ENABLE
;
2471 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
2472 fan_control_commands
|=
2473 TPACPI_FAN_CMD_LEVEL
|
2474 TPACPI_FAN_CMD_ENABLE
;
2479 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
2480 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
2481 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
2482 fan_status_access_mode
, fan_control_access_mode
);
2484 return (fan_status_access_mode
!= TPACPI_FAN_NONE
||
2485 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
)?
2489 static int fan_get_status(u8
*status
)
2494 * Add TPACPI_FAN_RD_ACPI_FANS ? */
2496 switch (fan_status_access_mode
) {
2497 case TPACPI_FAN_RD_ACPI_GFAN
:
2498 /* 570, 600e/x, 770e, 770x */
2500 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
2508 case TPACPI_FAN_RD_TPEC
:
2509 /* all except 570, 600e/x, 770e, 770x */
2510 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
2525 static void fan_exit(void)
2527 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending watchdogs\n");
2528 cancel_delayed_work(&fan_watchdog_task
);
2529 flush_scheduled_work();
2532 static int fan_get_speed(unsigned int *speed
)
2536 switch (fan_status_access_mode
) {
2537 case TPACPI_FAN_RD_TPEC
:
2538 /* all except 570, 600e/x, 770e, 770x */
2539 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
2540 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
2544 *speed
= (hi
<< 8) | lo
;
2555 static void fan_watchdog_fire(struct work_struct
*ignored
)
2557 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
2558 if (fan_set_enable()) {
2559 printk(IBM_ERR
"fan watchdog: error while enabling fan\n");
2560 /* reschedule for later */
2561 fan_watchdog_reset();
2565 static void fan_watchdog_reset(void)
2567 static int fan_watchdog_active
= 0;
2569 if (fan_watchdog_active
)
2570 cancel_delayed_work(&fan_watchdog_task
);
2572 if (fan_watchdog_maxinterval
> 0) {
2573 fan_watchdog_active
= 1;
2574 if (!schedule_delayed_work(&fan_watchdog_task
,
2575 msecs_to_jiffies(fan_watchdog_maxinterval
2577 printk(IBM_ERR
"failed to schedule the fan watchdog, "
2578 "watchdog will not trigger\n");
2581 fan_watchdog_active
= 0;
2584 static int fan_set_level(int level
)
2586 switch (fan_control_access_mode
) {
2587 case TPACPI_FAN_WR_ACPI_SFAN
:
2588 if (level
>= 0 && level
<= 7) {
2589 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
2595 case TPACPI_FAN_WR_ACPI_FANS
:
2596 case TPACPI_FAN_WR_TPEC
:
2597 if ((level
!= TP_EC_FAN_AUTO
) &&
2598 (level
!= TP_EC_FAN_FULLSPEED
) &&
2599 ((level
< 0) || (level
> 7)))
2602 if (!acpi_ec_write(fan_status_offset
, level
))
2605 tp_features
.fan_ctrl_status_undef
= 0;
2614 static int fan_set_enable(void)
2619 switch (fan_control_access_mode
) {
2620 case TPACPI_FAN_WR_ACPI_FANS
:
2621 case TPACPI_FAN_WR_TPEC
:
2622 if ((rc
= fan_get_status(&s
)) < 0)
2625 /* Don't go out of emergency fan mode */
2629 if (!acpi_ec_write(fan_status_offset
, s
))
2632 tp_features
.fan_ctrl_status_undef
= 0;
2635 case TPACPI_FAN_WR_ACPI_SFAN
:
2636 if ((rc
= fan_get_status(&s
)) < 0)
2641 /* Set fan to at least level 4 */
2645 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
2655 static int fan_set_disable(void)
2657 switch (fan_control_access_mode
) {
2658 case TPACPI_FAN_WR_ACPI_FANS
:
2659 case TPACPI_FAN_WR_TPEC
:
2660 if (!acpi_ec_write(fan_status_offset
, 0x00))
2663 tp_features
.fan_ctrl_status_undef
= 0;
2666 case TPACPI_FAN_WR_ACPI_SFAN
:
2667 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
2677 static int fan_set_speed(int speed
)
2679 switch (fan_control_access_mode
) {
2680 case TPACPI_FAN_WR_ACPI_FANS
:
2681 if (speed
>= 0 && speed
<= 65535) {
2682 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
2683 speed
, speed
, speed
))
2695 static int fan_read(char *p
)
2700 unsigned int speed
= 0;
2702 switch (fan_status_access_mode
) {
2703 case TPACPI_FAN_RD_ACPI_GFAN
:
2704 /* 570, 600e/x, 770e, 770x */
2705 if ((rc
= fan_get_status(&status
)) < 0)
2708 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
2710 (status
!= 0) ? "enabled" : "disabled", status
);
2713 case TPACPI_FAN_RD_TPEC
:
2714 /* all except 570, 600e/x, 770e, 770x */
2715 if ((rc
= fan_get_status(&status
)) < 0)
2718 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
2719 if (status
!= fan_control_initial_status
)
2720 tp_features
.fan_ctrl_status_undef
= 0;
2722 /* Return most likely status. In fact, it
2723 * might be the only possible status */
2724 status
= TP_EC_FAN_AUTO
;
2727 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2728 (status
!= 0) ? "enabled" : "disabled");
2730 if ((rc
= fan_get_speed(&speed
)) < 0)
2733 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
2735 if (status
& TP_EC_FAN_FULLSPEED
)
2736 /* Disengaged mode takes precedence */
2737 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
2738 else if (status
& TP_EC_FAN_AUTO
)
2739 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
2741 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
2744 case TPACPI_FAN_NONE
:
2746 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2749 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
2750 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
2752 switch (fan_control_access_mode
) {
2753 case TPACPI_FAN_WR_ACPI_SFAN
:
2754 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
2758 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
2759 "auto, disengaged)\n");
2764 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
2765 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
2766 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2767 "1-120 (seconds))\n");
2769 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
2770 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
2771 " (<speed> is 0-65535)\n");
2776 static int fan_write_cmd_level(const char *cmd
, int *rc
)
2780 if (strlencmp(cmd
, "level auto") == 0)
2781 level
= TP_EC_FAN_AUTO
;
2782 else if (strlencmp(cmd
, "level disengaged") == 0)
2783 level
= TP_EC_FAN_FULLSPEED
;
2784 else if (sscanf(cmd
, "level %d", &level
) != 1)
2787 if ((*rc
= fan_set_level(level
)) == -ENXIO
)
2788 printk(IBM_ERR
"level command accepted for unsupported "
2789 "access mode %d", fan_control_access_mode
);
2794 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
2796 if (strlencmp(cmd
, "enable") != 0)
2799 if ((*rc
= fan_set_enable()) == -ENXIO
)
2800 printk(IBM_ERR
"enable command accepted for unsupported "
2801 "access mode %d", fan_control_access_mode
);
2806 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
2808 if (strlencmp(cmd
, "disable") != 0)
2811 if ((*rc
= fan_set_disable()) == -ENXIO
)
2812 printk(IBM_ERR
"disable command accepted for unsupported "
2813 "access mode %d", fan_control_access_mode
);
2818 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
2823 * Support speed <low> <medium> <high> ? */
2825 if (sscanf(cmd
, "speed %d", &speed
) != 1)
2828 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
2829 printk(IBM_ERR
"speed command accepted for unsupported "
2830 "access mode %d", fan_control_access_mode
);
2835 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
2839 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
2842 if (interval
< 0 || interval
> 120)
2845 fan_watchdog_maxinterval
= interval
;
2850 static int fan_write(char *buf
)
2855 while (!rc
&& (cmd
= next_cmd(&buf
))) {
2856 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
2857 fan_write_cmd_level(cmd
, &rc
)) &&
2858 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
2859 (fan_write_cmd_enable(cmd
, &rc
) ||
2860 fan_write_cmd_disable(cmd
, &rc
) ||
2861 fan_write_cmd_watchdog(cmd
, &rc
))) &&
2862 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
2863 fan_write_cmd_speed(cmd
, &rc
))
2867 fan_watchdog_reset();
2873 static struct ibm_struct fan_driver_data
= {
2878 .flags
.experimental
= 1,
2881 /****************************************************************************
2882 ****************************************************************************
2886 ****************************************************************************
2887 ****************************************************************************/
2890 static struct proc_dir_entry
*proc_dir
= NULL
;
2892 /* Subdriver registry */
2893 static LIST_HEAD(tpacpi_all_drivers
);
2897 * Module and infrastructure proble, init and exit handling
2900 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
2901 static const char * __init
str_supported(int is_supported
)
2903 static char text_unsupported
[] __initdata
= "not supported";
2905 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
2907 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
2909 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
2912 struct ibm_struct
*ibm
= iibm
->data
;
2913 struct proc_dir_entry
*entry
;
2915 BUG_ON(ibm
== NULL
);
2917 INIT_LIST_HEAD(&ibm
->all_drivers
);
2919 if (ibm
->flags
.experimental
&& !experimental
)
2922 dbg_printk(TPACPI_DBG_INIT
,
2923 "probing for %s\n", ibm
->name
);
2926 ret
= iibm
->init(iibm
);
2928 return 0; /* probe failed */
2932 ibm
->flags
.init_called
= 1;
2936 if (ibm
->acpi
->hid
) {
2937 ret
= register_tpacpi_subdriver(ibm
);
2942 if (ibm
->acpi
->notify
) {
2943 ret
= setup_acpi_notify(ibm
);
2944 if (ret
== -ENODEV
) {
2945 printk(IBM_NOTICE
"disabling subdriver %s\n",
2955 dbg_printk(TPACPI_DBG_INIT
,
2956 "%s installed\n", ibm
->name
);
2959 entry
= create_proc_entry(ibm
->name
,
2960 S_IFREG
| S_IRUGO
| S_IWUSR
,
2963 printk(IBM_ERR
"unable to create proc entry %s\n",
2968 entry
->owner
= THIS_MODULE
;
2970 entry
->read_proc
= &dispatch_procfs_read
;
2972 entry
->write_proc
= &dispatch_procfs_write
;
2973 ibm
->flags
.proc_created
= 1;
2976 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
2981 dbg_printk(TPACPI_DBG_INIT
,
2982 "%s: at error exit path with result %d\n",
2986 return (ret
< 0)? ret
: 0;
2989 static void ibm_exit(struct ibm_struct
*ibm
)
2991 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
2993 list_del_init(&ibm
->all_drivers
);
2995 if (ibm
->flags
.acpi_notify_installed
) {
2996 dbg_printk(TPACPI_DBG_EXIT
,
2997 "%s: acpi_remove_notify_handler\n", ibm
->name
);
2999 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
3001 dispatch_acpi_notify
);
3002 ibm
->flags
.acpi_notify_installed
= 0;
3003 ibm
->flags
.acpi_notify_installed
= 0;
3006 if (ibm
->flags
.proc_created
) {
3007 dbg_printk(TPACPI_DBG_EXIT
,
3008 "%s: remove_proc_entry\n", ibm
->name
);
3009 remove_proc_entry(ibm
->name
, proc_dir
);
3010 ibm
->flags
.proc_created
= 0;
3013 if (ibm
->flags
.acpi_driver_registered
) {
3014 dbg_printk(TPACPI_DBG_EXIT
,
3015 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
3017 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
3018 kfree(ibm
->acpi
->driver
);
3019 ibm
->acpi
->driver
= NULL
;
3020 ibm
->flags
.acpi_driver_registered
= 0;
3023 if (ibm
->flags
.init_called
&& ibm
->exit
) {
3025 ibm
->flags
.init_called
= 0;
3028 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
3033 static char *ibm_thinkpad_ec_found
= NULL
;
3035 static char* __init
check_dmi_for_ec(void)
3037 struct dmi_device
*dev
= NULL
;
3038 char ec_fw_string
[18];
3041 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
3042 * X32 or newer, all Z series; Some models must have an
3043 * up-to-date BIOS or they will not be detected.
3045 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
3047 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
3048 if (sscanf(dev
->name
,
3049 "IBM ThinkPad Embedded Controller -[%17c",
3050 ec_fw_string
) == 1) {
3051 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
3052 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
3053 return kstrdup(ec_fw_string
, GFP_KERNEL
);
3059 static int __init
probe_for_thinkpad(void)
3067 * Non-ancient models have better DMI tagging, but very old models
3070 is_thinkpad
= dmi_name_in_vendors("ThinkPad");
3072 /* ec is required because many other handles are relative to it */
3073 IBM_ACPIHANDLE_INIT(ec
);
3077 "Not yet supported ThinkPad detected!\n");
3082 * Risks a regression on very old machines, but reduces potential
3083 * false positives a damn great deal
3086 is_thinkpad
= dmi_name_in_vendors("IBM");
3088 if (!is_thinkpad
&& !force_load
)
3095 /* Module init, exit, parameters */
3097 static struct ibm_init_struct ibms_init
[] __initdata
= {
3099 .init
= thinkpad_acpi_driver_init
,
3100 .data
= &thinkpad_acpi_driver_data
,
3103 .init
= hotkey_init
,
3104 .data
= &hotkey_driver_data
,
3107 .init
= bluetooth_init
,
3108 .data
= &bluetooth_driver_data
,
3112 .data
= &wan_driver_data
,
3116 .data
= &video_driver_data
,
3120 .data
= &light_driver_data
,
3122 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3125 .data
= &dock_driver_data
[0],
3128 .data
= &dock_driver_data
[1],
3131 #ifdef CONFIG_THINKPAD_ACPI_BAY
3134 .data
= &bay_driver_data
,
3139 .data
= &cmos_driver_data
,
3143 .data
= &led_driver_data
,
3147 .data
= &beep_driver_data
,
3150 .init
= thermal_init
,
3151 .data
= &thermal_driver_data
,
3154 .data
= &ecdump_driver_data
,
3157 .init
= brightness_init
,
3158 .data
= &brightness_driver_data
,
3161 .data
= &volume_driver_data
,
3165 .data
= &fan_driver_data
,
3169 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
3172 struct ibm_struct
*ibm
;
3174 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
3175 ibm
= ibms_init
[i
].data
;
3176 BUG_ON(ibm
== NULL
);
3178 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
3179 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
3181 strcpy(ibms_init
[i
].param
, val
);
3182 strcat(ibms_init
[i
].param
, ",");
3190 static int experimental
;
3191 module_param(experimental
, int, 0);
3193 static u32 dbg_level
;
3194 module_param_named(debug
, dbg_level
, uint
, 0);
3196 static int force_load
;
3197 module_param(force_load
, int, 0);
3199 #define IBM_PARAM(feature) \
3200 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
3203 IBM_PARAM(bluetooth
);
3206 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3209 #ifdef CONFIG_THINKPAD_ACPI_BAY
3211 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3216 IBM_PARAM(brightness
);
3220 static int __init
thinkpad_acpi_module_init(void)
3224 ret
= probe_for_thinkpad();
3228 ibm_thinkpad_ec_found
= check_dmi_for_ec();
3229 IBM_ACPIHANDLE_INIT(ecrd
);
3230 IBM_ACPIHANDLE_INIT(ecwr
);
3232 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
3234 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
3235 thinkpad_acpi_module_exit();
3238 proc_dir
->owner
= THIS_MODULE
;
3240 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
3241 ret
= ibm_init(&ibms_init
[i
]);
3242 if (ret
>= 0 && *ibms_init
[i
].param
)
3243 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
3245 thinkpad_acpi_module_exit();
3253 static void thinkpad_acpi_module_exit(void)
3255 struct ibm_struct
*ibm
, *itmp
;
3257 list_for_each_entry_safe_reverse(ibm
, itmp
,
3258 &tpacpi_all_drivers
,
3263 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
3266 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
3268 kfree(ibm_thinkpad_ec_found
);
3271 module_init(thinkpad_acpi_module_init
);
3272 module_exit(thinkpad_acpi_module_exit
);