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 drv_acpi_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_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
300 struct ibm_struct
*ibm
= data
;
302 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
305 ibm
->acpi
->notify(ibm
, event
);
308 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
315 if (!*ibm
->acpi
->handle
)
318 dbg_printk(TPACPI_DBG_INIT
,
319 "setting up ACPI notify for %s\n", ibm
->name
);
321 ret
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
323 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
327 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
328 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
329 IBM_ACPI_EVENT_PREFIX
,
332 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
333 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
334 if (ACPI_FAILURE(status
)) {
335 if (status
== AE_ALREADY_EXISTS
) {
336 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
339 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
344 ibm
->flags
.acpi_notify_installed
= 1;
348 static int __init
tpacpi_device_add(struct acpi_device
*device
)
353 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
357 dbg_printk(TPACPI_DBG_INIT
,
358 "registering %s as an ACPI driver\n", ibm
->name
);
362 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
363 if (!ibm
->acpi
->driver
) {
364 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
368 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
369 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
370 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
372 ret
= acpi_bus_register_driver(ibm
->acpi
->driver
);
374 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
375 ibm
->acpi
->hid
, ret
);
376 kfree(ibm
->acpi
->driver
);
377 ibm
->acpi
->driver
= NULL
;
379 ibm
->flags
.acpi_driver_registered
= 1;
385 /****************************************************************************
386 ****************************************************************************
390 ****************************************************************************
391 ****************************************************************************/
393 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
394 int count
, int *eof
, void *data
)
396 struct ibm_struct
*ibm
= data
;
399 if (!ibm
|| !ibm
->read
)
402 len
= ibm
->read(page
);
406 if (len
<= off
+ count
)
418 static int dispatch_procfs_write(struct file
*file
,
419 const char __user
* userbuf
,
420 unsigned long count
, void *data
)
422 struct ibm_struct
*ibm
= data
;
426 if (!ibm
|| !ibm
->write
)
429 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
433 if (copy_from_user(kernbuf
, userbuf
, count
)) {
439 strcat(kernbuf
, ",");
440 ret
= ibm
->write(kernbuf
);
449 static char *next_cmd(char **cmds
)
454 while ((end
= strchr(start
, ',')) && end
== start
)
466 /****************************************************************************
467 ****************************************************************************
471 ****************************************************************************
472 ****************************************************************************/
474 /*************************************************************************
475 * thinkpad-acpi init subdriver
478 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
480 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
481 printk(IBM_INFO
"%s\n", IBM_URL
);
483 if (ibm_thinkpad_ec_found
)
484 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
485 ibm_thinkpad_ec_found
);
490 static int thinkpad_acpi_driver_read(char *p
)
494 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
495 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
500 static struct ibm_struct thinkpad_acpi_driver_data
= {
502 .read
= thinkpad_acpi_driver_read
,
505 /*************************************************************************
509 static int hotkey_orig_status
;
510 static int hotkey_orig_mask
;
512 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
514 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
516 IBM_ACPIHANDLE_INIT(hkey
);
518 /* hotkey not supported on 570 */
519 tp_features
.hotkey
= hkey_handle
!= NULL
;
521 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
522 str_supported(tp_features
.hotkey
));
524 if (tp_features
.hotkey
) {
525 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
526 A30, R30, R31, T20-22, X20-21, X22-24 */
527 tp_features
.hotkey_mask
=
528 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
530 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
531 str_supported(tp_features
.hotkey_mask
));
533 if (!hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
))
537 return (tp_features
.hotkey
)? 0 : 1;
540 static void hotkey_exit(void)
542 if (tp_features
.hotkey
) {
543 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
544 hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
548 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
552 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
553 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
555 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
556 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
560 static int hotkey_get(int *status
, int *mask
)
562 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
565 if (tp_features
.hotkey_mask
)
566 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
572 static int hotkey_set(int status
, int mask
)
576 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
579 if (tp_features
.hotkey_mask
)
580 for (i
= 0; i
< 32; i
++) {
581 int bit
= ((1 << i
) & mask
) != 0;
582 if (!acpi_evalf(hkey_handle
,
583 NULL
, "MHKM", "vdd", i
+ 1, bit
))
590 static int hotkey_read(char *p
)
595 if (!tp_features
.hotkey
) {
596 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
600 if (!hotkey_get(&status
, &mask
))
603 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
604 if (tp_features
.hotkey_mask
) {
605 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
606 len
+= sprintf(p
+ len
,
607 "commands:\tenable, disable, reset, <mask>\n");
609 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
610 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
616 static int hotkey_write(char *buf
)
622 if (!tp_features
.hotkey
)
625 if (!hotkey_get(&status
, &mask
))
628 while ((cmd
= next_cmd(&buf
))) {
629 if (strlencmp(cmd
, "enable") == 0) {
631 } else if (strlencmp(cmd
, "disable") == 0) {
633 } else if (strlencmp(cmd
, "reset") == 0) {
634 status
= hotkey_orig_status
;
635 mask
= hotkey_orig_mask
;
636 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
638 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
645 if (do_cmd
&& !hotkey_set(status
, mask
))
651 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
653 .notify
= hotkey_notify
,
654 .handle
= &hkey_handle
,
655 .type
= ACPI_DEVICE_NOTIFY
,
658 static struct ibm_struct hotkey_driver_data
= {
661 .write
= hotkey_write
,
663 .acpi
= &ibm_hotkey_acpidriver
,
666 /*************************************************************************
667 * Bluetooth subdriver
670 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
672 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
674 IBM_ACPIHANDLE_INIT(hkey
);
676 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
677 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
678 tp_features
.bluetooth
= hkey_handle
&&
679 acpi_evalf(hkey_handle
, NULL
, "GBDC", "qv");
681 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s\n",
682 str_supported(tp_features
.bluetooth
));
684 return (tp_features
.bluetooth
)? 0 : 1;
687 static int bluetooth_status(void)
691 if (!tp_features
.bluetooth
||
692 !acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
698 static int bluetooth_read(char *p
)
701 int status
= bluetooth_status();
703 if (!tp_features
.bluetooth
)
704 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
705 else if (!(status
& 1))
706 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
708 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
709 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
715 static int bluetooth_write(char *buf
)
717 int status
= bluetooth_status();
721 if (!tp_features
.bluetooth
)
724 while ((cmd
= next_cmd(&buf
))) {
725 if (strlencmp(cmd
, "enable") == 0) {
727 } else if (strlencmp(cmd
, "disable") == 0) {
734 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
740 static struct ibm_struct bluetooth_driver_data
= {
742 .read
= bluetooth_read
,
743 .write
= bluetooth_write
,
746 /*************************************************************************
750 static int __init
wan_init(struct ibm_init_struct
*iibm
)
752 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
754 IBM_ACPIHANDLE_INIT(hkey
);
756 tp_features
.wan
= hkey_handle
&&
757 acpi_evalf(hkey_handle
, NULL
, "GWAN", "qv");
759 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s\n",
760 str_supported(tp_features
.wan
));
762 return (tp_features
.wan
)? 0 : 1;
765 static int wan_status(void)
769 if (!tp_features
.wan
||
770 !acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
776 static int wan_read(char *p
)
779 int status
= wan_status();
781 if (!tp_features
.wan
)
782 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
783 else if (!(status
& 1))
784 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
786 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
787 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
793 static int wan_write(char *buf
)
795 int status
= wan_status();
799 if (!tp_features
.wan
)
802 while ((cmd
= next_cmd(&buf
))) {
803 if (strlencmp(cmd
, "enable") == 0) {
805 } else if (strlencmp(cmd
, "disable") == 0) {
812 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
818 static struct ibm_struct wan_driver_data
= {
822 .flags
.experimental
= 1,
825 /*************************************************************************
829 static enum video_access_mode video_supported
;
830 static int video_orig_autosw
;
832 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
833 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
834 "\\_SB.PCI0.VID0", /* 770e */
835 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
836 "\\_SB.PCI0.AGP.VID", /* all others */
839 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
841 static int __init
video_init(struct ibm_init_struct
*iibm
)
845 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
847 IBM_ACPIHANDLE_INIT(vid
);
848 IBM_ACPIHANDLE_INIT(vid2
);
850 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
851 /* G41, assume IVGA doesn't change */
852 vid_handle
= vid2_handle
;
855 /* video switching not supported on R30, R31 */
856 video_supported
= TPACPI_VIDEO_NONE
;
857 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
859 video_supported
= TPACPI_VIDEO_570
;
860 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
861 /* 600e/x, 770e, 770x */
862 video_supported
= TPACPI_VIDEO_770
;
865 video_supported
= TPACPI_VIDEO_NEW
;
867 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
868 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
871 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
874 static void video_exit(void)
876 dbg_printk(TPACPI_DBG_EXIT
, "restoring original video autoswitch mode\n");
877 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", video_orig_autosw
);
880 static int video_status(void)
885 if (video_supported
== TPACPI_VIDEO_570
) {
886 if (acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd", 0x87))
888 } else if (video_supported
== TPACPI_VIDEO_770
) {
889 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
891 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
893 } else if (video_supported
== TPACPI_VIDEO_NEW
) {
894 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1);
895 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
898 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0);
899 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
901 if (acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
908 static int video_autosw(void)
912 if (video_supported
== TPACPI_VIDEO_570
)
913 acpi_evalf(vid_handle
, &autosw
, "SWIT", "d");
914 else if (video_supported
== TPACPI_VIDEO_770
||
915 video_supported
== TPACPI_VIDEO_NEW
)
916 acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d");
921 static int video_switch(void)
923 int autosw
= video_autosw();
926 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
928 ret
= video_supported
== TPACPI_VIDEO_570
?
929 acpi_evalf(ec_handle
, NULL
, "_Q16", "v") :
930 acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
931 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
936 static int video_expand(void)
938 if (video_supported
== TPACPI_VIDEO_570
)
939 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v");
940 else if (video_supported
== TPACPI_VIDEO_770
)
941 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v");
943 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v");
946 static int video_switch2(int status
)
950 if (video_supported
== TPACPI_VIDEO_570
) {
951 ret
= acpi_evalf(NULL
, NULL
,
952 "\\_SB.PHS2", "vdd", 0x8b, status
| 0x80);
953 } else if (video_supported
== TPACPI_VIDEO_770
) {
954 int autosw
= video_autosw();
955 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
958 ret
= acpi_evalf(vid_handle
, NULL
,
959 "ASWT", "vdd", status
* 0x100, 0);
961 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
963 ret
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
964 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
970 static int video_read(char *p
)
972 int status
= video_status();
973 int autosw
= video_autosw();
976 if (!video_supported
) {
977 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
981 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
982 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
983 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
984 if (video_supported
== TPACPI_VIDEO_NEW
)
985 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
986 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
987 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
988 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
989 if (video_supported
== TPACPI_VIDEO_NEW
)
990 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
991 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
992 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
997 static int video_write(char *buf
)
1000 int enable
, disable
, status
;
1002 if (!video_supported
)
1005 enable
= disable
= 0;
1007 while ((cmd
= next_cmd(&buf
))) {
1008 if (strlencmp(cmd
, "lcd_enable") == 0) {
1010 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1012 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1014 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1016 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1017 strlencmp(cmd
, "dvi_enable") == 0) {
1019 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1020 strlencmp(cmd
, "dvi_disable") == 0) {
1022 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1023 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
1025 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1026 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 0))
1028 } else if (strlencmp(cmd
, "video_switch") == 0) {
1029 if (!video_switch())
1031 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1032 if (!video_expand())
1038 if (enable
|| disable
) {
1039 status
= (video_status() & 0x0f & ~disable
) | enable
;
1040 if (!video_switch2(status
))
1047 static struct ibm_struct video_driver_data
= {
1050 .write
= video_write
,
1054 /*************************************************************************
1055 * Light (thinklight) subdriver
1058 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1059 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1061 static int __init
light_init(struct ibm_init_struct
*iibm
)
1063 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
1065 IBM_ACPIHANDLE_INIT(ledb
);
1066 IBM_ACPIHANDLE_INIT(lght
);
1067 IBM_ACPIHANDLE_INIT(cmos
);
1069 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1070 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1072 if (tp_features
.light
)
1073 /* light status not supported on
1074 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1075 tp_features
.light_status
=
1076 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
1078 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
1079 str_supported(tp_features
.light
));
1081 return (tp_features
.light
)? 0 : 1;
1084 static int light_read(char *p
)
1089 if (!tp_features
.light
) {
1090 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1091 } else if (!tp_features
.light_status
) {
1092 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1093 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1095 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1097 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1098 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1104 static int light_write(char *buf
)
1106 int cmos_cmd
, lght_cmd
;
1110 if (!tp_features
.light
)
1113 while ((cmd
= next_cmd(&buf
))) {
1114 if (strlencmp(cmd
, "on") == 0) {
1117 } else if (strlencmp(cmd
, "off") == 0) {
1123 success
= cmos_handle
?
1124 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1125 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1133 static struct ibm_struct light_driver_data
= {
1136 .write
= light_write
,
1139 /*************************************************************************
1143 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1145 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
1146 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1147 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1148 "\\_SB.PCI.ISA.SLCE", /* 570 */
1149 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1151 /* don't list other alternatives as we install a notify handler on the 570 */
1152 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
1154 #define dock_docked() (_sta(dock_handle) & 1)
1156 static int __init
dock_init(struct ibm_init_struct
*iibm
)
1158 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
1160 IBM_ACPIHANDLE_INIT(dock
);
1161 IBM_ACPIHANDLE_INIT(pci
);
1163 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
1164 str_supported(dock_handle
!= NULL
));
1166 return (dock_handle
)? 0 : 1;
1169 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1171 int docked
= dock_docked();
1172 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, IBM_PCI_HID
);
1174 if (event
== 1 && !pci
) /* 570 */
1175 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1176 else if (event
== 1 && pci
) /* 570 */
1177 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1178 else if (event
== 3 && docked
)
1179 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1180 else if (event
== 3 && !docked
)
1181 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
1182 else if (event
== 0 && docked
)
1183 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1185 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1186 event
, _sta(dock_handle
));
1187 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
1191 static int dock_read(char *p
)
1194 int docked
= dock_docked();
1197 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1199 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1201 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1202 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1208 static int dock_write(char *buf
)
1215 while ((cmd
= next_cmd(&buf
))) {
1216 if (strlencmp(cmd
, "undock") == 0) {
1217 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1218 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1220 } else if (strlencmp(cmd
, "dock") == 0) {
1221 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1230 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
1232 .notify
= dock_notify
,
1233 .handle
= &dock_handle
,
1234 .type
= ACPI_SYSTEM_NOTIFY
,
1238 .notify
= dock_notify
,
1239 .handle
= &pci_handle
,
1240 .type
= ACPI_SYSTEM_NOTIFY
,
1244 static struct ibm_struct dock_driver_data
[2] = {
1248 .write
= dock_write
,
1249 .acpi
= &ibm_dock_acpidriver
[0],
1253 .acpi
= &ibm_dock_acpidriver
[1],
1257 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1259 /*************************************************************************
1263 #ifdef CONFIG_THINKPAD_ACPI_BAY
1264 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1265 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1266 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1267 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1268 ); /* A21e, R30, R31 */
1269 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
1270 "_EJ0", /* all others */
1271 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1272 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1273 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1275 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
1279 static int __init
bay_init(struct ibm_init_struct
*iibm
)
1281 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
1283 IBM_ACPIHANDLE_INIT(bay
);
1285 IBM_ACPIHANDLE_INIT(bay_ej
);
1286 IBM_ACPIHANDLE_INIT(bay2
);
1288 IBM_ACPIHANDLE_INIT(bay2_ej
);
1290 tp_features
.bay_status
= bay_handle
&&
1291 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1292 tp_features
.bay_status2
= bay2_handle
&&
1293 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1295 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
1296 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1297 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
1298 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1300 vdbg_printk(TPACPI_DBG_INIT
,
1301 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1302 str_supported(tp_features
.bay_status
),
1303 str_supported(tp_features
.bay_eject
),
1304 str_supported(tp_features
.bay_status2
),
1305 str_supported(tp_features
.bay_eject2
));
1307 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
1308 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
1311 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1313 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1316 #define bay_occupied(b) (_sta(b##_handle) & 1)
1318 static int bay_read(char *p
)
1321 int occupied
= bay_occupied(bay
);
1322 int occupied2
= bay_occupied(bay2
);
1325 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1326 tp_features
.bay_status
?
1327 (occupied
? "occupied" : "unoccupied") :
1329 if (tp_features
.bay_status2
)
1330 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1331 "occupied" : "unoccupied");
1333 eject
= tp_features
.bay_eject
&& occupied
;
1334 eject2
= tp_features
.bay_eject2
&& occupied2
;
1336 if (eject
&& eject2
)
1337 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1339 len
+= sprintf(p
+ len
, "commands:\teject\n");
1341 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1346 static int bay_write(char *buf
)
1350 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
1353 while ((cmd
= next_cmd(&buf
))) {
1354 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
1355 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1357 } else if (tp_features
.bay_eject2
&&
1358 strlencmp(cmd
, "eject2") == 0) {
1359 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1368 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
1369 .notify
= bay_notify
,
1370 .handle
= &bay_handle
,
1371 .type
= ACPI_SYSTEM_NOTIFY
,
1374 static struct ibm_struct bay_driver_data
= {
1378 .acpi
= &ibm_bay_acpidriver
,
1381 #endif /* CONFIG_THINKPAD_ACPI_BAY */
1383 /*************************************************************************
1387 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
1389 vdbg_printk(TPACPI_DBG_INIT
,
1390 "initializing cmos commands subdriver\n");
1392 IBM_ACPIHANDLE_INIT(cmos
);
1394 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
1395 str_supported(cmos_handle
!= NULL
));
1396 return (cmos_handle
)? 0 : 1;
1399 static int cmos_eval(int cmos_cmd
)
1402 return acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
);
1407 static int cmos_read(char *p
)
1411 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1412 R30, R31, T20-22, X20-21 */
1414 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1416 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1417 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1423 static int cmos_write(char *buf
)
1431 while ((cmd
= next_cmd(&buf
))) {
1432 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1433 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1438 if (!cmos_eval(cmos_cmd
))
1445 static struct ibm_struct cmos_driver_data
= {
1448 .write
= cmos_write
,
1451 /*************************************************************************
1455 static enum led_access_mode led_supported
;
1457 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
1458 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1459 "LED", /* all others */
1462 static int __init
led_init(struct ibm_init_struct
*iibm
)
1464 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
1466 IBM_ACPIHANDLE_INIT(led
);
1469 /* led not supported on R30, R31 */
1470 led_supported
= TPACPI_LED_NONE
;
1471 else if (strlencmp(led_path
, "SLED") == 0)
1473 led_supported
= TPACPI_LED_570
;
1474 else if (strlencmp(led_path
, "SYSL") == 0)
1475 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1476 led_supported
= TPACPI_LED_OLD
;
1479 led_supported
= TPACPI_LED_NEW
;
1481 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
1482 str_supported(led_supported
), led_supported
);
1484 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
1487 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1489 static int led_read(char *p
)
1493 if (!led_supported
) {
1494 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1497 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1499 if (led_supported
== TPACPI_LED_570
) {
1502 for (i
= 0; i
< 8; i
++) {
1503 if (!acpi_evalf(ec_handle
,
1504 &status
, "GLED", "dd", 1 << i
))
1506 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1507 i
, led_status(status
));
1511 len
+= sprintf(p
+ len
, "commands:\t"
1512 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1517 /* off, on, blink */
1518 static const int led_sled_arg1
[] = { 0, 1, 3 };
1519 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
1520 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
1521 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
1523 static int led_write(char *buf
)
1531 while ((cmd
= next_cmd(&buf
))) {
1532 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1535 if (strstr(cmd
, "off")) {
1537 } else if (strstr(cmd
, "on")) {
1539 } else if (strstr(cmd
, "blink")) {
1544 if (led_supported
== TPACPI_LED_570
) {
1547 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1548 led
, led_sled_arg1
[ind
]))
1550 } else if (led_supported
== TPACPI_LED_OLD
) {
1551 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1553 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
1556 ec_write(TPACPI_LED_EC_HLBL
,
1557 led
* led_exp_hlbl
[ind
]);
1560 ec_write(TPACPI_LED_EC_HLCL
,
1561 led
* led_exp_hlcl
[ind
]);
1566 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1567 led
, led_led_arg1
[ind
]))
1575 static struct ibm_struct led_driver_data
= {
1581 /*************************************************************************
1585 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
1587 static int __init
beep_init(struct ibm_init_struct
*iibm
)
1589 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
1591 IBM_ACPIHANDLE_INIT(beep
);
1593 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
1594 str_supported(beep_handle
!= NULL
));
1596 return (beep_handle
)? 0 : 1;
1599 static int beep_read(char *p
)
1604 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1606 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1607 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1613 static int beep_write(char *buf
)
1621 while ((cmd
= next_cmd(&buf
))) {
1622 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1623 beep_cmd
>= 0 && beep_cmd
<= 17) {
1627 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1634 static struct ibm_struct beep_driver_data
= {
1637 .write
= beep_write
,
1640 /*************************************************************************
1644 static enum thermal_access_mode thermal_read_mode
;
1646 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
1652 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
1654 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
1656 if (ibm_thinkpad_ec_found
&& experimental
) {
1658 * Direct EC access mode: sensors at registers
1659 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1660 * non-implemented, thermal sensors return 0x80 when
1665 for (i
= 0; i
< 8; i
++) {
1666 if (likely(acpi_ec_read(0x78 + i
, &t
))) {
1672 if (likely(acpi_ec_read(0xC0 + i
, &t
))) {
1680 /* This is sheer paranoia, but we handle it anyway */
1683 "ThinkPad ACPI EC access misbehaving, "
1684 "falling back to ACPI TMPx access mode\n");
1685 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
1688 "ThinkPad ACPI EC access misbehaving, "
1689 "disabling thermal sensors access\n");
1690 thermal_read_mode
= TPACPI_THERMAL_NONE
;
1695 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
1697 } else if (acpi_tmp7
) {
1698 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
1699 /* 600e/x, 770e, 770x */
1700 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
1702 /* Standard ACPI TMPx access, max 8 sensors */
1703 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
1706 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1707 thermal_read_mode
= TPACPI_THERMAL_NONE
;
1710 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
1711 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
1714 return (thermal_read_mode
!= TPACPI_THERMAL_NONE
)? 0 : 1;
1717 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
1721 char tmpi
[] = "TMPi";
1726 switch (thermal_read_mode
) {
1727 #if TPACPI_MAX_THERMAL_SENSORS >= 16
1728 case TPACPI_THERMAL_TPEC_16
:
1729 for (i
= 0; i
< 8; i
++) {
1730 if (!acpi_ec_read(0xC0 + i
, &tmp
))
1732 s
->temp
[i
+ 8] = tmp
* 1000;
1736 case TPACPI_THERMAL_TPEC_8
:
1737 for (i
= 0; i
< 8; i
++) {
1738 if (!acpi_ec_read(0x78 + i
, &tmp
))
1740 s
->temp
[i
] = tmp
* 1000;
1742 return (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
) ? 16 : 8;
1744 case TPACPI_THERMAL_ACPI_UPDT
:
1745 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
1747 for (i
= 0; i
< 8; i
++) {
1749 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1751 s
->temp
[i
] = (t
- 2732) * 100;
1755 case TPACPI_THERMAL_ACPI_TMP07
:
1756 for (i
= 0; i
< 8; i
++) {
1758 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1760 s
->temp
[i
] = t
* 1000;
1764 case TPACPI_THERMAL_NONE
:
1770 static int thermal_read(char *p
)
1774 struct ibm_thermal_sensors_struct t
;
1776 n
= thermal_get_sensors(&t
);
1777 if (unlikely(n
< 0))
1780 len
+= sprintf(p
+ len
, "temperatures:\t");
1783 for (i
= 0; i
< (n
- 1); i
++)
1784 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
1785 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
1787 len
+= sprintf(p
+ len
, "not supported\n");
1792 static struct ibm_struct thermal_driver_data
= {
1794 .read
= thermal_read
,
1797 /*************************************************************************
1801 static u8 ecdump_regs
[256];
1803 static int ecdump_read(char *p
)
1809 len
+= sprintf(p
+ len
, "EC "
1810 " +00 +01 +02 +03 +04 +05 +06 +07"
1811 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1812 for (i
= 0; i
< 256; i
+= 16) {
1813 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
1814 for (j
= 0; j
< 16; j
++) {
1815 if (!acpi_ec_read(i
+ j
, &v
))
1817 if (v
!= ecdump_regs
[i
+ j
])
1818 len
+= sprintf(p
+ len
, " *%02x", v
);
1820 len
+= sprintf(p
+ len
, " %02x", v
);
1821 ecdump_regs
[i
+ j
] = v
;
1823 len
+= sprintf(p
+ len
, "\n");
1828 /* These are way too dangerous to advertise openly... */
1830 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
1831 " (<offset> is 00-ff, <value> is 00-ff)\n");
1832 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
1833 " (<offset> is 00-ff, <value> is 0-255)\n");
1838 static int ecdump_write(char *buf
)
1843 while ((cmd
= next_cmd(&buf
))) {
1844 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
1846 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
1850 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
1851 if (!acpi_ec_write(i
, v
))
1860 static struct ibm_struct ecdump_driver_data
= {
1862 .read
= ecdump_read
,
1863 .write
= ecdump_write
,
1864 .flags
.experimental
= 1,
1867 /*************************************************************************
1868 * Backlight/brightness subdriver
1871 static struct backlight_device
*ibm_backlight_device
= NULL
;
1873 static struct backlight_ops ibm_backlight_data
= {
1874 .get_brightness
= brightness_get
,
1875 .update_status
= brightness_update_status
,
1878 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
1882 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
1884 b
= brightness_get(NULL
);
1888 ibm_backlight_device
= backlight_device_register("ibm", NULL
, NULL
,
1889 &ibm_backlight_data
);
1890 if (IS_ERR(ibm_backlight_device
)) {
1891 printk(IBM_ERR
"Could not register backlight device\n");
1892 return PTR_ERR(ibm_backlight_device
);
1894 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
1896 ibm_backlight_device
->props
.max_brightness
= 7;
1897 ibm_backlight_device
->props
.brightness
= b
;
1898 backlight_update_status(ibm_backlight_device
);
1903 static void brightness_exit(void)
1905 if (ibm_backlight_device
) {
1906 vdbg_printk(TPACPI_DBG_EXIT
,
1907 "calling backlight_device_unregister()\n");
1908 backlight_device_unregister(ibm_backlight_device
);
1909 ibm_backlight_device
= NULL
;
1913 static int brightness_update_status(struct backlight_device
*bd
)
1915 return brightness_set(
1916 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
1917 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
1918 bd
->props
.brightness
: 0);
1921 static int brightness_get(struct backlight_device
*bd
)
1924 if (!acpi_ec_read(brightness_offset
, &level
))
1932 static int brightness_set(int value
)
1934 int cmos_cmd
, inc
, i
;
1935 int current_value
= brightness_get(NULL
);
1939 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
1940 inc
= value
> current_value
? 1 : -1;
1941 for (i
= current_value
; i
!= value
; i
+= inc
) {
1942 if (!cmos_eval(cmos_cmd
))
1944 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
1951 static int brightness_read(char *p
)
1956 if ((level
= brightness_get(NULL
)) < 0) {
1957 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1959 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
1960 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
1961 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1962 " (<level> is 0-7)\n");
1968 static int brightness_write(char *buf
)
1974 while ((cmd
= next_cmd(&buf
))) {
1975 if ((level
= brightness_get(NULL
)) < 0)
1979 if (strlencmp(cmd
, "up") == 0) {
1980 new_level
= level
== 7 ? 7 : level
+ 1;
1981 } else if (strlencmp(cmd
, "down") == 0) {
1982 new_level
= level
== 0 ? 0 : level
- 1;
1983 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1984 new_level
>= 0 && new_level
<= 7) {
1989 brightness_set(new_level
);
1995 static struct ibm_struct brightness_driver_data
= {
1996 .name
= "brightness",
1997 .read
= brightness_read
,
1998 .write
= brightness_write
,
1999 .exit
= brightness_exit
,
2002 /*************************************************************************
2006 static int volume_read(char *p
)
2011 if (!acpi_ec_read(volume_offset
, &level
)) {
2012 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2014 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
2015 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
2016 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
2017 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2018 " (<level> is 0-15)\n");
2024 static int volume_write(char *buf
)
2026 int cmos_cmd
, inc
, i
;
2028 int new_level
, new_mute
;
2031 while ((cmd
= next_cmd(&buf
))) {
2032 if (!acpi_ec_read(volume_offset
, &level
))
2034 new_mute
= mute
= level
& 0x40;
2035 new_level
= level
= level
& 0xf;
2037 if (strlencmp(cmd
, "up") == 0) {
2041 new_level
= level
== 15 ? 15 : level
+ 1;
2042 } else if (strlencmp(cmd
, "down") == 0) {
2046 new_level
= level
== 0 ? 0 : level
- 1;
2047 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2048 new_level
>= 0 && new_level
<= 15) {
2050 } else if (strlencmp(cmd
, "mute") == 0) {
2055 if (new_level
!= level
) { /* mute doesn't change */
2056 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
2057 inc
= new_level
> level
? 1 : -1;
2059 if (mute
&& (!cmos_eval(cmos_cmd
) ||
2060 !acpi_ec_write(volume_offset
, level
)))
2063 for (i
= level
; i
!= new_level
; i
+= inc
)
2064 if (!cmos_eval(cmos_cmd
) ||
2065 !acpi_ec_write(volume_offset
, i
+ inc
))
2068 if (mute
&& (!cmos_eval(TP_CMOS_VOLUME_MUTE
) ||
2069 !acpi_ec_write(volume_offset
,
2074 if (new_mute
!= mute
) { /* level doesn't change */
2075 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
2077 if (!cmos_eval(cmos_cmd
) ||
2078 !acpi_ec_write(volume_offset
, level
+ new_mute
))
2086 static struct ibm_struct volume_driver_data
= {
2088 .read
= volume_read
,
2089 .write
= volume_write
,
2092 /*************************************************************************
2099 * TPACPI_FAN_RD_ACPI_GFAN:
2100 * ACPI GFAN method: returns fan level
2102 * see TPACPI_FAN_WR_ACPI_SFAN
2103 * EC 0x2f (HFSP) not available if GFAN exists
2105 * TPACPI_FAN_WR_ACPI_SFAN:
2106 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2108 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2111 * TPACPI_FAN_WR_TPEC:
2112 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2113 * Supported on almost all ThinkPads
2115 * Fan speed changes of any sort (including those caused by the
2116 * disengaged mode) are usually done slowly by the firmware as the
2117 * maximum ammount of fan duty cycle change per second seems to be
2120 * Reading is not available if GFAN exists.
2121 * Writing is not available if SFAN exists.
2124 * 7 automatic mode engaged;
2125 * (default operation mode of the ThinkPad)
2126 * fan level is ignored in this mode.
2127 * 6 full speed mode (takes precedence over bit 7);
2128 * not available on all thinkpads. May disable
2129 * the tachometer while the fan controller ramps up
2130 * the speed (which can take up to a few *minutes*).
2131 * Speeds up fan to 100% duty-cycle, which is far above
2132 * the standard RPM levels. It is not impossible that
2133 * it could cause hardware damage.
2134 * 5-3 unused in some models. Extra bits for fan level
2135 * in others, but still useless as all values above
2136 * 7 map to the same speed as level 7 in these models.
2137 * 2-0 fan level (0..7 usually)
2139 * 0x07 = max (set when temperatures critical)
2140 * Some ThinkPads may have other levels, see
2141 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2143 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2144 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2145 * does so, its initial value is meaningless (0x07).
2147 * For firmware bugs, refer to:
2148 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2152 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2153 * Main fan tachometer reading (in RPM)
2155 * This register is present on all ThinkPads with a new-style EC, and
2156 * it is known not to be present on the A21m/e, and T22, as there is
2157 * something else in offset 0x84 according to the ACPI DSDT. Other
2158 * ThinkPads from this same time period (and earlier) probably lack the
2159 * tachometer as well.
2161 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2162 * was never fixed by IBM to report the EC firmware version string
2163 * probably support the tachometer (like the early X models), so
2164 * detecting it is quite hard. We need more data to know for sure.
2166 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2169 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2172 * For firmware bugs, refer to:
2173 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2175 * TPACPI_FAN_WR_ACPI_FANS:
2176 * ThinkPad X31, X40, X41. Not available in the X60.
2178 * FANS ACPI handle: takes three arguments: low speed, medium speed,
2179 * high speed. ACPI DSDT seems to map these three speeds to levels
2180 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
2181 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
2183 * The speeds are stored on handles
2184 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
2186 * There are three default speed sets, acessible as handles:
2187 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
2189 * ACPI DSDT switches which set is in use depending on various
2192 * TPACPI_FAN_WR_TPEC is also available and should be used to
2193 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
2194 * but the ACPI tables just mention level 7.
2197 static enum fan_status_access_mode fan_status_access_mode
;
2198 static enum fan_control_access_mode fan_control_access_mode
;
2199 static enum fan_control_commands fan_control_commands
;
2201 static u8 fan_control_initial_status
;
2203 static void fan_watchdog_fire(struct work_struct
*ignored
);
2204 static int fan_watchdog_maxinterval
;
2205 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
2207 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
2208 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
2209 "\\FSPD", /* 600e/x, 770e, 770x */
2211 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
2212 "JFNS", /* 770x-JL */
2215 static int __init
fan_init(struct ibm_init_struct
*iibm
)
2217 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
2219 fan_status_access_mode
= TPACPI_FAN_NONE
;
2220 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
2221 fan_control_commands
= 0;
2222 fan_watchdog_maxinterval
= 0;
2223 tp_features
.fan_ctrl_status_undef
= 0;
2225 IBM_ACPIHANDLE_INIT(fans
);
2226 IBM_ACPIHANDLE_INIT(gfan
);
2227 IBM_ACPIHANDLE_INIT(sfan
);
2230 /* 570, 600e/x, 770e, 770x */
2231 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
2233 /* all other ThinkPads: note that even old-style
2234 * ThinkPad ECs supports the fan control register */
2235 if (likely(acpi_ec_read(fan_status_offset
,
2236 &fan_control_initial_status
))) {
2237 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
2239 /* In some ThinkPads, neither the EC nor the ACPI
2240 * DSDT initialize the fan status, and it ends up
2241 * being set to 0x07 when it *could* be either
2244 * Enable for TP-1Y (T43), TP-78 (R51e),
2245 * TP-76 (R52), TP-70 (T43, R52), which are known
2247 if (fan_control_initial_status
== 0x07 &&
2248 ibm_thinkpad_ec_found
&&
2249 ((ibm_thinkpad_ec_found
[0] == '1' &&
2250 ibm_thinkpad_ec_found
[1] == 'Y') ||
2251 (ibm_thinkpad_ec_found
[0] == '7' &&
2252 (ibm_thinkpad_ec_found
[1] == '6' ||
2253 ibm_thinkpad_ec_found
[1] == '8' ||
2254 ibm_thinkpad_ec_found
[1] == '0'))
2257 "fan_init: initial fan status is "
2258 "unknown, assuming it is in auto "
2260 tp_features
.fan_ctrl_status_undef
= 1;
2264 "ThinkPad ACPI EC access misbehaving, "
2265 "fan status and control unavailable\n");
2272 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
2273 fan_control_commands
|=
2274 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
2277 /* gfan without sfan means no fan control */
2278 /* all other models implement TP EC 0x2f control */
2282 fan_control_access_mode
=
2283 TPACPI_FAN_WR_ACPI_FANS
;
2284 fan_control_commands
|=
2285 TPACPI_FAN_CMD_SPEED
|
2286 TPACPI_FAN_CMD_LEVEL
|
2287 TPACPI_FAN_CMD_ENABLE
;
2289 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
2290 fan_control_commands
|=
2291 TPACPI_FAN_CMD_LEVEL
|
2292 TPACPI_FAN_CMD_ENABLE
;
2297 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
2298 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
2299 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
2300 fan_status_access_mode
, fan_control_access_mode
);
2302 return (fan_status_access_mode
!= TPACPI_FAN_NONE
||
2303 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
)?
2307 static int fan_get_status(u8
*status
)
2312 * Add TPACPI_FAN_RD_ACPI_FANS ? */
2314 switch (fan_status_access_mode
) {
2315 case TPACPI_FAN_RD_ACPI_GFAN
:
2316 /* 570, 600e/x, 770e, 770x */
2318 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
2326 case TPACPI_FAN_RD_TPEC
:
2327 /* all except 570, 600e/x, 770e, 770x */
2328 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
2343 static void fan_exit(void)
2345 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending watchdogs\n");
2346 cancel_delayed_work(&fan_watchdog_task
);
2347 flush_scheduled_work();
2350 static int fan_get_speed(unsigned int *speed
)
2354 switch (fan_status_access_mode
) {
2355 case TPACPI_FAN_RD_TPEC
:
2356 /* all except 570, 600e/x, 770e, 770x */
2357 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
2358 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
2362 *speed
= (hi
<< 8) | lo
;
2373 static void fan_watchdog_fire(struct work_struct
*ignored
)
2375 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
2376 if (fan_set_enable()) {
2377 printk(IBM_ERR
"fan watchdog: error while enabling fan\n");
2378 /* reschedule for later */
2379 fan_watchdog_reset();
2383 static void fan_watchdog_reset(void)
2385 static int fan_watchdog_active
= 0;
2387 if (fan_watchdog_active
)
2388 cancel_delayed_work(&fan_watchdog_task
);
2390 if (fan_watchdog_maxinterval
> 0) {
2391 fan_watchdog_active
= 1;
2392 if (!schedule_delayed_work(&fan_watchdog_task
,
2393 msecs_to_jiffies(fan_watchdog_maxinterval
2395 printk(IBM_ERR
"failed to schedule the fan watchdog, "
2396 "watchdog will not trigger\n");
2399 fan_watchdog_active
= 0;
2402 static int fan_set_level(int level
)
2404 switch (fan_control_access_mode
) {
2405 case TPACPI_FAN_WR_ACPI_SFAN
:
2406 if (level
>= 0 && level
<= 7) {
2407 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
2413 case TPACPI_FAN_WR_ACPI_FANS
:
2414 case TPACPI_FAN_WR_TPEC
:
2415 if ((level
!= TP_EC_FAN_AUTO
) &&
2416 (level
!= TP_EC_FAN_FULLSPEED
) &&
2417 ((level
< 0) || (level
> 7)))
2420 if (!acpi_ec_write(fan_status_offset
, level
))
2423 tp_features
.fan_ctrl_status_undef
= 0;
2432 static int fan_set_enable(void)
2437 switch (fan_control_access_mode
) {
2438 case TPACPI_FAN_WR_ACPI_FANS
:
2439 case TPACPI_FAN_WR_TPEC
:
2440 if ((rc
= fan_get_status(&s
)) < 0)
2443 /* Don't go out of emergency fan mode */
2447 if (!acpi_ec_write(fan_status_offset
, s
))
2450 tp_features
.fan_ctrl_status_undef
= 0;
2453 case TPACPI_FAN_WR_ACPI_SFAN
:
2454 if ((rc
= fan_get_status(&s
)) < 0)
2459 /* Set fan to at least level 4 */
2463 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
2473 static int fan_set_disable(void)
2475 switch (fan_control_access_mode
) {
2476 case TPACPI_FAN_WR_ACPI_FANS
:
2477 case TPACPI_FAN_WR_TPEC
:
2478 if (!acpi_ec_write(fan_status_offset
, 0x00))
2481 tp_features
.fan_ctrl_status_undef
= 0;
2484 case TPACPI_FAN_WR_ACPI_SFAN
:
2485 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
2495 static int fan_set_speed(int speed
)
2497 switch (fan_control_access_mode
) {
2498 case TPACPI_FAN_WR_ACPI_FANS
:
2499 if (speed
>= 0 && speed
<= 65535) {
2500 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
2501 speed
, speed
, speed
))
2513 static int fan_read(char *p
)
2518 unsigned int speed
= 0;
2520 switch (fan_status_access_mode
) {
2521 case TPACPI_FAN_RD_ACPI_GFAN
:
2522 /* 570, 600e/x, 770e, 770x */
2523 if ((rc
= fan_get_status(&status
)) < 0)
2526 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
2528 (status
!= 0) ? "enabled" : "disabled", status
);
2531 case TPACPI_FAN_RD_TPEC
:
2532 /* all except 570, 600e/x, 770e, 770x */
2533 if ((rc
= fan_get_status(&status
)) < 0)
2536 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
2537 if (status
!= fan_control_initial_status
)
2538 tp_features
.fan_ctrl_status_undef
= 0;
2540 /* Return most likely status. In fact, it
2541 * might be the only possible status */
2542 status
= TP_EC_FAN_AUTO
;
2545 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2546 (status
!= 0) ? "enabled" : "disabled");
2548 if ((rc
= fan_get_speed(&speed
)) < 0)
2551 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
2553 if (status
& TP_EC_FAN_FULLSPEED
)
2554 /* Disengaged mode takes precedence */
2555 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
2556 else if (status
& TP_EC_FAN_AUTO
)
2557 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
2559 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
2562 case TPACPI_FAN_NONE
:
2564 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2567 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
2568 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
2570 switch (fan_control_access_mode
) {
2571 case TPACPI_FAN_WR_ACPI_SFAN
:
2572 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
2576 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
2577 "auto, disengaged)\n");
2582 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
2583 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
2584 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2585 "1-120 (seconds))\n");
2587 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
2588 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
2589 " (<speed> is 0-65535)\n");
2594 static int fan_write_cmd_level(const char *cmd
, int *rc
)
2598 if (strlencmp(cmd
, "level auto") == 0)
2599 level
= TP_EC_FAN_AUTO
;
2600 else if (strlencmp(cmd
, "level disengaged") == 0)
2601 level
= TP_EC_FAN_FULLSPEED
;
2602 else if (sscanf(cmd
, "level %d", &level
) != 1)
2605 if ((*rc
= fan_set_level(level
)) == -ENXIO
)
2606 printk(IBM_ERR
"level command accepted for unsupported "
2607 "access mode %d", fan_control_access_mode
);
2612 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
2614 if (strlencmp(cmd
, "enable") != 0)
2617 if ((*rc
= fan_set_enable()) == -ENXIO
)
2618 printk(IBM_ERR
"enable command accepted for unsupported "
2619 "access mode %d", fan_control_access_mode
);
2624 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
2626 if (strlencmp(cmd
, "disable") != 0)
2629 if ((*rc
= fan_set_disable()) == -ENXIO
)
2630 printk(IBM_ERR
"disable command accepted for unsupported "
2631 "access mode %d", fan_control_access_mode
);
2636 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
2641 * Support speed <low> <medium> <high> ? */
2643 if (sscanf(cmd
, "speed %d", &speed
) != 1)
2646 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
2647 printk(IBM_ERR
"speed command accepted for unsupported "
2648 "access mode %d", fan_control_access_mode
);
2653 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
2657 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
2660 if (interval
< 0 || interval
> 120)
2663 fan_watchdog_maxinterval
= interval
;
2668 static int fan_write(char *buf
)
2673 while (!rc
&& (cmd
= next_cmd(&buf
))) {
2674 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
2675 fan_write_cmd_level(cmd
, &rc
)) &&
2676 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
2677 (fan_write_cmd_enable(cmd
, &rc
) ||
2678 fan_write_cmd_disable(cmd
, &rc
) ||
2679 fan_write_cmd_watchdog(cmd
, &rc
))) &&
2680 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
2681 fan_write_cmd_speed(cmd
, &rc
))
2685 fan_watchdog_reset();
2691 static struct ibm_struct fan_driver_data
= {
2696 .flags
.experimental
= 1,
2699 /****************************************************************************
2700 ****************************************************************************
2704 ****************************************************************************
2705 ****************************************************************************/
2708 static struct proc_dir_entry
*proc_dir
= NULL
;
2710 /* Subdriver registry */
2711 static LIST_HEAD(tpacpi_all_drivers
);
2715 * Module and infrastructure proble, init and exit handling
2718 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
2719 static const char * __init
str_supported(int is_supported
)
2721 static char text_unsupported
[] __initdata
= "not supported";
2723 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
2725 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
2727 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
2730 struct ibm_struct
*ibm
= iibm
->data
;
2731 struct proc_dir_entry
*entry
;
2733 BUG_ON(ibm
== NULL
);
2735 INIT_LIST_HEAD(&ibm
->all_drivers
);
2737 if (ibm
->flags
.experimental
&& !experimental
)
2740 dbg_printk(TPACPI_DBG_INIT
,
2741 "probing for %s\n", ibm
->name
);
2744 ret
= iibm
->init(iibm
);
2746 return 0; /* probe failed */
2750 ibm
->flags
.init_called
= 1;
2754 if (ibm
->acpi
->hid
) {
2755 ret
= register_tpacpi_subdriver(ibm
);
2760 if (ibm
->acpi
->notify
) {
2761 ret
= setup_acpi_notify(ibm
);
2762 if (ret
== -ENODEV
) {
2763 printk(IBM_NOTICE
"disabling subdriver %s\n",
2773 dbg_printk(TPACPI_DBG_INIT
,
2774 "%s installed\n", ibm
->name
);
2777 entry
= create_proc_entry(ibm
->name
,
2778 S_IFREG
| S_IRUGO
| S_IWUSR
,
2781 printk(IBM_ERR
"unable to create proc entry %s\n",
2786 entry
->owner
= THIS_MODULE
;
2788 entry
->read_proc
= &dispatch_procfs_read
;
2790 entry
->write_proc
= &dispatch_procfs_write
;
2791 ibm
->flags
.proc_created
= 1;
2794 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
2799 dbg_printk(TPACPI_DBG_INIT
,
2800 "%s: at error exit path with result %d\n",
2804 return (ret
< 0)? ret
: 0;
2807 static void ibm_exit(struct ibm_struct
*ibm
)
2809 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
2811 list_del_init(&ibm
->all_drivers
);
2813 if (ibm
->flags
.acpi_notify_installed
) {
2814 dbg_printk(TPACPI_DBG_EXIT
,
2815 "%s: acpi_remove_notify_handler\n", ibm
->name
);
2817 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
2819 dispatch_acpi_notify
);
2820 ibm
->flags
.acpi_notify_installed
= 0;
2821 ibm
->flags
.acpi_notify_installed
= 0;
2824 if (ibm
->flags
.proc_created
) {
2825 dbg_printk(TPACPI_DBG_EXIT
,
2826 "%s: remove_proc_entry\n", ibm
->name
);
2827 remove_proc_entry(ibm
->name
, proc_dir
);
2828 ibm
->flags
.proc_created
= 0;
2831 if (ibm
->flags
.acpi_driver_registered
) {
2832 dbg_printk(TPACPI_DBG_EXIT
,
2833 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
2835 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
2836 kfree(ibm
->acpi
->driver
);
2837 ibm
->acpi
->driver
= NULL
;
2838 ibm
->flags
.acpi_driver_registered
= 0;
2841 if (ibm
->flags
.init_called
&& ibm
->exit
) {
2843 ibm
->flags
.init_called
= 0;
2846 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
2851 static char *ibm_thinkpad_ec_found
= NULL
;
2853 static char* __init
check_dmi_for_ec(void)
2855 struct dmi_device
*dev
= NULL
;
2856 char ec_fw_string
[18];
2859 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2860 * X32 or newer, all Z series; Some models must have an
2861 * up-to-date BIOS or they will not be detected.
2863 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2865 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
2866 if (sscanf(dev
->name
,
2867 "IBM ThinkPad Embedded Controller -[%17c",
2868 ec_fw_string
) == 1) {
2869 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
2870 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
2871 return kstrdup(ec_fw_string
, GFP_KERNEL
);
2877 static int __init
probe_for_thinkpad(void)
2885 * Non-ancient models have better DMI tagging, but very old models
2888 is_thinkpad
= dmi_name_in_vendors("ThinkPad");
2890 /* ec is required because many other handles are relative to it */
2891 IBM_ACPIHANDLE_INIT(ec
);
2895 "Not yet supported ThinkPad detected!\n");
2900 * Risks a regression on very old machines, but reduces potential
2901 * false positives a damn great deal
2904 is_thinkpad
= dmi_name_in_vendors("IBM");
2906 if (!is_thinkpad
&& !force_load
)
2913 /* Module init, exit, parameters */
2915 static struct ibm_init_struct ibms_init
[] __initdata
= {
2917 .init
= thinkpad_acpi_driver_init
,
2918 .data
= &thinkpad_acpi_driver_data
,
2921 .init
= hotkey_init
,
2922 .data
= &hotkey_driver_data
,
2925 .init
= bluetooth_init
,
2926 .data
= &bluetooth_driver_data
,
2930 .data
= &wan_driver_data
,
2934 .data
= &video_driver_data
,
2938 .data
= &light_driver_data
,
2940 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2943 .data
= &dock_driver_data
[0],
2946 .data
= &dock_driver_data
[1],
2949 #ifdef CONFIG_THINKPAD_ACPI_BAY
2952 .data
= &bay_driver_data
,
2957 .data
= &cmos_driver_data
,
2961 .data
= &led_driver_data
,
2965 .data
= &beep_driver_data
,
2968 .init
= thermal_init
,
2969 .data
= &thermal_driver_data
,
2972 .data
= &ecdump_driver_data
,
2975 .init
= brightness_init
,
2976 .data
= &brightness_driver_data
,
2979 .data
= &volume_driver_data
,
2983 .data
= &fan_driver_data
,
2987 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
2990 struct ibm_struct
*ibm
;
2992 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
2993 ibm
= ibms_init
[i
].data
;
2994 BUG_ON(ibm
== NULL
);
2996 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
2997 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
2999 strcpy(ibms_init
[i
].param
, val
);
3000 strcat(ibms_init
[i
].param
, ",");
3008 static int experimental
;
3009 module_param(experimental
, int, 0);
3011 static u32 dbg_level
;
3012 module_param_named(debug
, dbg_level
, uint
, 0);
3014 static int force_load
;
3015 module_param(force_load
, int, 0);
3017 #define IBM_PARAM(feature) \
3018 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
3021 IBM_PARAM(bluetooth
);
3024 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3027 #ifdef CONFIG_THINKPAD_ACPI_BAY
3029 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3034 IBM_PARAM(brightness
);
3038 static int __init
thinkpad_acpi_module_init(void)
3042 ret
= probe_for_thinkpad();
3046 ibm_thinkpad_ec_found
= check_dmi_for_ec();
3047 IBM_ACPIHANDLE_INIT(ecrd
);
3048 IBM_ACPIHANDLE_INIT(ecwr
);
3050 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
3052 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
3053 thinkpad_acpi_module_exit();
3056 proc_dir
->owner
= THIS_MODULE
;
3058 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
3059 ret
= ibm_init(&ibms_init
[i
]);
3060 if (ret
>= 0 && *ibms_init
[i
].param
)
3061 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
3063 thinkpad_acpi_module_exit();
3071 static void thinkpad_acpi_module_exit(void)
3073 struct ibm_struct
*ibm
, *itmp
;
3075 list_for_each_entry_safe_reverse(ibm
, itmp
,
3076 &tpacpi_all_drivers
,
3081 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
3084 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
3086 kfree(ibm_thinkpad_ec_found
);
3089 module_init(thinkpad_acpi_module_init
);
3090 module_exit(thinkpad_acpi_module_exit
);