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"
25 #define TPACPI_SYSFS_VERSION 0x000100
29 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
32 * 2006-11-22 0.13 new maintainer
33 * changelog now lives in git commit history, and will
34 * not be updated further in-file.
36 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
37 * 2005-03-17 0.11 support for 600e, 770x
38 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
39 * support for 770e, G41
40 * G40 and G41 don't have a thinklight
41 * temperatures no longer experimental
42 * experimental brightness control
43 * experimental volume control
44 * experimental fan enable/disable
45 * 2005-01-16 0.10 fix module loading on R30, R31
46 * 2005-01-16 0.9 support for 570, R30, R31
47 * ultrabay support on A22p, A3x
48 * limit arg for cmos, led, beep, drop experimental status
49 * more capable led control on A21e, A22p, T20-22, X20
50 * experimental temperatures and fan speed
51 * experimental embedded controller register dump
52 * mark more functions as __init, drop incorrect __exit
54 * thanks to Henrik Brix Andersen <brix@gentoo.org>
55 * fix parameter passing on module loading
56 * thanks to Rusty Russell <rusty@rustcorp.com.au>
57 * thanks to Jim Radford <radford@blackbean.org>
58 * 2004-11-08 0.8 fix init error case, don't return from a macro
59 * thanks to Chris Wright <chrisw@osdl.org>
60 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
61 * fix led control on A21e
62 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
63 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
64 * proc file format changed
65 * video_switch command
66 * experimental cmos control
67 * experimental led control
68 * experimental acpi sounds
69 * 2004-09-16 0.4 support for module parameters
70 * hotkey mask can be prefixed by 0x
71 * video output switching
72 * video expansion control
73 * ultrabay eject support
74 * removed lcd brightness/on/off control, didn't work
75 * 2004-08-17 0.3 support for R40
76 * lcd off, brightness control
78 * 2004-08-14 0.2 support for T series, X20
79 * bluetooth enable/disable
80 * hotkey events disabled by default
81 * removed fan control, currently useless
82 * 2004-08-09 0.1 initial release, support for X series
85 #include "thinkpad_acpi.h"
87 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
88 MODULE_DESCRIPTION(IBM_DESC
);
89 MODULE_VERSION(IBM_VERSION
);
90 MODULE_LICENSE("GPL");
92 /* Please remove this in year 2009 */
93 MODULE_ALIAS("ibm_acpi");
95 #define __unused __attribute__ ((unused))
97 /****************************************************************************
98 ****************************************************************************
100 * ACPI Helpers and device model
102 ****************************************************************************
103 ****************************************************************************/
105 /*************************************************************************
109 static acpi_handle root_handle
= NULL
;
111 #define IBM_HANDLE(object, parent, paths...) \
112 static acpi_handle object##_handle; \
113 static acpi_handle *object##_parent = &parent##_handle; \
114 static char *object##_path; \
115 static char *object##_paths[] = { paths }
117 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
118 "\\_SB.PCI.ISA.EC", /* 570 */
119 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
120 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
121 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
122 "\\_SB.PCI0.ICH3.EC0", /* R31 */
123 "\\_SB.PCI0.LPC.EC", /* all others */
126 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
127 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
130 /*************************************************************************
134 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
135 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
136 "\\CMS", /* R40, R40e */
139 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
140 "^HKEY", /* R30, R31 */
141 "HKEY", /* all others */
145 /*************************************************************************
149 static int acpi_evalf(acpi_handle handle
,
150 void *res
, char *method
, char *fmt
, ...)
153 struct acpi_object_list params
;
154 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
155 struct acpi_buffer result
, *resultp
;
156 union acpi_object out_obj
;
164 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
177 params
.pointer
= &in_objs
[0];
184 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
185 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
187 /* add more types as needed */
189 printk(IBM_ERR
"acpi_evalf() called "
190 "with invalid format character '%c'\n", c
);
196 if (res_type
!= 'v') {
197 result
.length
= sizeof(out_obj
);
198 result
.pointer
= &out_obj
;
203 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
208 *(int *)res
= out_obj
.integer
.value
;
209 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
212 success
= status
== AE_OK
;
214 /* add more types as needed */
216 printk(IBM_ERR
"acpi_evalf() called "
217 "with invalid format character '%c'\n", res_type
);
221 if (!success
&& !quiet
)
222 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
223 method
, fmt0
, status
);
228 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
232 if (acpi_evalf(handle
, &i
, method
, "d"))
233 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
235 printk(IBM_ERR
"error calling %s\n", method
);
238 static int acpi_ec_read(int i
, u8
* p
)
243 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
247 if (ec_read(i
, p
) < 0)
254 static int acpi_ec_write(int i
, u8 v
)
257 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
260 if (ec_write(i
, v
) < 0)
267 static int _sta(acpi_handle handle
)
271 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
277 static int issue_thinkpad_cmos_command(int cmos_cmd
)
282 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
288 /*************************************************************************
292 static void drv_acpi_handle_init(char *name
,
293 acpi_handle
*handle
, acpi_handle parent
,
294 char **paths
, int num_paths
, char **path
)
299 for (i
= 0; i
< num_paths
; i
++) {
300 status
= acpi_get_handle(parent
, paths
[i
], handle
);
301 if (ACPI_SUCCESS(status
)) {
310 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
312 struct ibm_struct
*ibm
= data
;
314 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
317 ibm
->acpi
->notify(ibm
, event
);
320 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
327 if (!*ibm
->acpi
->handle
)
330 dbg_printk(TPACPI_DBG_INIT
,
331 "setting up ACPI notify for %s\n", ibm
->name
);
333 ret
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
335 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
339 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
340 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
341 IBM_ACPI_EVENT_PREFIX
,
344 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
345 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
346 if (ACPI_FAILURE(status
)) {
347 if (status
== AE_ALREADY_EXISTS
) {
348 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
351 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
356 ibm
->flags
.acpi_notify_installed
= 1;
360 static int __init
tpacpi_device_add(struct acpi_device
*device
)
365 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
369 dbg_printk(TPACPI_DBG_INIT
,
370 "registering %s as an ACPI driver\n", ibm
->name
);
374 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
375 if (!ibm
->acpi
->driver
) {
376 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
380 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
381 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
382 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
384 ret
= acpi_bus_register_driver(ibm
->acpi
->driver
);
386 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
387 ibm
->acpi
->hid
, ret
);
388 kfree(ibm
->acpi
->driver
);
389 ibm
->acpi
->driver
= NULL
;
391 ibm
->flags
.acpi_driver_registered
= 1;
397 /****************************************************************************
398 ****************************************************************************
402 ****************************************************************************
403 ****************************************************************************/
405 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
406 int count
, int *eof
, void *data
)
408 struct ibm_struct
*ibm
= data
;
411 if (!ibm
|| !ibm
->read
)
414 len
= ibm
->read(page
);
418 if (len
<= off
+ count
)
430 static int dispatch_procfs_write(struct file
*file
,
431 const char __user
* userbuf
,
432 unsigned long count
, void *data
)
434 struct ibm_struct
*ibm
= data
;
438 if (!ibm
|| !ibm
->write
)
441 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
445 if (copy_from_user(kernbuf
, userbuf
, count
)) {
451 strcat(kernbuf
, ",");
452 ret
= ibm
->write(kernbuf
);
461 static char *next_cmd(char **cmds
)
466 while ((end
= strchr(start
, ',')) && end
== start
)
478 /****************************************************************************
479 ****************************************************************************
481 * Device model: hwmon and platform
483 ****************************************************************************
484 ****************************************************************************/
486 static struct platform_device
*tpacpi_pdev
= NULL
;
487 static struct class_device
*tpacpi_hwmon
= NULL
;
489 static struct platform_driver tpacpi_pdriver
= {
491 .name
= IBM_DRVR_NAME
,
492 .owner
= THIS_MODULE
,
497 /*************************************************************************
498 * thinkpad-acpi driver attributes
501 /* interface_version --------------------------------------------------- */
502 static ssize_t
tpacpi_driver_interface_version_show(
503 struct device_driver
*drv
,
506 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
509 static DRIVER_ATTR(interface_version
, S_IRUGO
,
510 tpacpi_driver_interface_version_show
, NULL
);
512 /* debug_level --------------------------------------------------------- */
513 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
516 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
519 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
520 const char *buf
, size_t count
)
524 if (parse_strtoul(buf
, 0xffff, &t
))
532 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
533 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
535 /* version ------------------------------------------------------------- */
536 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
539 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
542 static DRIVER_ATTR(version
, S_IRUGO
,
543 tpacpi_driver_version_show
, NULL
);
545 /* --------------------------------------------------------------------- */
547 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
548 &driver_attr_debug_level
, &driver_attr_version
,
549 &driver_attr_interface_version
,
552 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
558 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
559 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
566 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
570 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
571 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
574 /*************************************************************************
575 * sysfs support helpers
578 struct attribute_set_obj
{
579 struct attribute_set s
;
581 } __attribute__((packed
));
583 static struct attribute_set
*create_attr_set(unsigned int max_members
,
586 struct attribute_set_obj
*sobj
;
588 if (max_members
== 0)
591 /* Allocates space for implicit NULL at the end too */
592 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
593 max_members
* sizeof(struct attribute
*),
597 sobj
->s
.max_members
= max_members
;
598 sobj
->s
.group
.attrs
= &sobj
->a
;
599 sobj
->s
.group
.name
= name
;
604 /* not multi-threaded safe, use it in a single thread per set */
605 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
610 if (s
->members
>= s
->max_members
)
613 s
->group
.attrs
[s
->members
] = attr
;
619 static int add_many_to_attr_set(struct attribute_set
* s
,
620 struct attribute
**attr
,
625 for (i
= 0; i
< count
; i
++) {
626 res
= add_to_attr_set(s
, attr
[i
]);
634 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
636 sysfs_remove_group(kobj
, &s
->group
);
640 static int parse_strtoul(const char *buf
,
641 unsigned long max
, unsigned long *value
)
645 *value
= simple_strtoul(buf
, &endp
, 0);
646 while (*endp
&& isspace(*endp
))
648 if (*endp
|| *value
> max
)
654 /****************************************************************************
655 ****************************************************************************
659 ****************************************************************************
660 ****************************************************************************/
662 /*************************************************************************
663 * thinkpad-acpi init subdriver
666 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
668 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
669 printk(IBM_INFO
"%s\n", IBM_URL
);
671 if (ibm_thinkpad_ec_found
)
672 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
673 ibm_thinkpad_ec_found
);
678 static int thinkpad_acpi_driver_read(char *p
)
682 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
683 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
688 static struct ibm_struct thinkpad_acpi_driver_data
= {
690 .read
= thinkpad_acpi_driver_read
,
693 /*************************************************************************
697 static int hotkey_orig_status
;
698 static int hotkey_orig_mask
;
700 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
704 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
706 IBM_ACPIHANDLE_INIT(hkey
);
707 mutex_init(&hotkey_mutex
);
709 /* hotkey not supported on 570 */
710 tp_features
.hotkey
= hkey_handle
!= NULL
;
712 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
713 str_supported(tp_features
.hotkey
));
715 if (tp_features
.hotkey
) {
716 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
717 A30, R30, R31, T20-22, X20-21, X22-24 */
718 tp_features
.hotkey_mask
=
719 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
721 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
722 str_supported(tp_features
.hotkey_mask
));
724 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
729 return (tp_features
.hotkey
)? 0 : 1;
732 static void hotkey_exit(void)
736 if (tp_features
.hotkey
) {
737 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
738 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
740 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
744 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
748 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
749 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
751 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
752 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
757 * Call with hotkey_mutex held
759 static int hotkey_get(int *status
, int *mask
)
761 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
764 if (tp_features
.hotkey_mask
)
765 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
772 * Call with hotkey_mutex held
774 static int hotkey_set(int status
, int mask
)
778 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
781 if (tp_features
.hotkey_mask
)
782 for (i
= 0; i
< 32; i
++) {
783 int bit
= ((1 << i
) & mask
) != 0;
784 if (!acpi_evalf(hkey_handle
,
785 NULL
, "MHKM", "vdd", i
+ 1, bit
))
792 static int hotkey_read(char *p
)
794 int res
, status
, mask
;
797 if (!tp_features
.hotkey
) {
798 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
802 res
= mutex_lock_interruptible(&hotkey_mutex
);
805 res
= hotkey_get(&status
, &mask
);
806 mutex_unlock(&hotkey_mutex
);
810 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
811 if (tp_features
.hotkey_mask
) {
812 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
813 len
+= sprintf(p
+ len
,
814 "commands:\tenable, disable, reset, <mask>\n");
816 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
817 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
823 static int hotkey_write(char *buf
)
825 int res
, status
, mask
;
829 if (!tp_features
.hotkey
)
832 res
= mutex_lock_interruptible(&hotkey_mutex
);
836 res
= hotkey_get(&status
, &mask
);
841 while ((cmd
= next_cmd(&buf
))) {
842 if (strlencmp(cmd
, "enable") == 0) {
844 } else if (strlencmp(cmd
, "disable") == 0) {
846 } else if (strlencmp(cmd
, "reset") == 0) {
847 status
= hotkey_orig_status
;
848 mask
= hotkey_orig_mask
;
849 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
851 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
861 res
= hotkey_set(status
, mask
);
864 mutex_unlock(&hotkey_mutex
);
868 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
870 .notify
= hotkey_notify
,
871 .handle
= &hkey_handle
,
872 .type
= ACPI_DEVICE_NOTIFY
,
875 static struct ibm_struct hotkey_driver_data
= {
878 .write
= hotkey_write
,
880 .acpi
= &ibm_hotkey_acpidriver
,
883 /*************************************************************************
884 * Bluetooth subdriver
887 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
891 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
893 IBM_ACPIHANDLE_INIT(hkey
);
895 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
896 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
897 tp_features
.bluetooth
= hkey_handle
&&
898 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
900 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
901 str_supported(tp_features
.bluetooth
),
904 if (tp_features
.bluetooth
&&
905 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
906 /* no bluetooth hardware present in system */
907 tp_features
.bluetooth
= 0;
908 dbg_printk(TPACPI_DBG_INIT
,
909 "bluetooth hardware not installed\n");
912 return (tp_features
.bluetooth
)? 0 : 1;
915 static int bluetooth_get_radiosw(void)
919 if (!tp_features
.bluetooth
)
922 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
925 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
928 static int bluetooth_set_radiosw(int radio_on
)
932 if (!tp_features
.bluetooth
)
935 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
938 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
940 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
941 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
947 static int bluetooth_read(char *p
)
950 int status
= bluetooth_get_radiosw();
952 if (!tp_features
.bluetooth
)
953 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
955 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
956 (status
)? "enabled" : "disabled");
957 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
963 static int bluetooth_write(char *buf
)
967 if (!tp_features
.bluetooth
)
970 while ((cmd
= next_cmd(&buf
))) {
971 if (strlencmp(cmd
, "enable") == 0) {
972 bluetooth_set_radiosw(1);
973 } else if (strlencmp(cmd
, "disable") == 0) {
974 bluetooth_set_radiosw(0);
982 static struct ibm_struct bluetooth_driver_data
= {
984 .read
= bluetooth_read
,
985 .write
= bluetooth_write
,
988 /*************************************************************************
992 static int __init
wan_init(struct ibm_init_struct
*iibm
)
996 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
998 IBM_ACPIHANDLE_INIT(hkey
);
1000 tp_features
.wan
= hkey_handle
&&
1001 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1003 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1004 str_supported(tp_features
.wan
),
1007 if (tp_features
.wan
&&
1008 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1009 /* no wan hardware present in system */
1010 tp_features
.wan
= 0;
1011 dbg_printk(TPACPI_DBG_INIT
,
1012 "wan hardware not installed\n");
1015 return (tp_features
.wan
)? 0 : 1;
1018 static int wan_get_radiosw(void)
1022 if (!tp_features
.wan
)
1025 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1028 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1031 static int wan_set_radiosw(int radio_on
)
1035 if (!tp_features
.wan
)
1038 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1041 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1043 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1044 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1050 static int wan_read(char *p
)
1053 int status
= wan_get_radiosw();
1055 if (!tp_features
.wan
)
1056 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1058 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1059 (status
)? "enabled" : "disabled");
1060 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1066 static int wan_write(char *buf
)
1070 if (!tp_features
.wan
)
1073 while ((cmd
= next_cmd(&buf
))) {
1074 if (strlencmp(cmd
, "enable") == 0) {
1076 } else if (strlencmp(cmd
, "disable") == 0) {
1085 static struct ibm_struct wan_driver_data
= {
1089 .flags
.experimental
= 1,
1092 /*************************************************************************
1096 static enum video_access_mode video_supported
;
1097 static int video_orig_autosw
;
1099 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1100 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1101 "\\_SB.PCI0.VID0", /* 770e */
1102 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1103 "\\_SB.PCI0.AGP.VID", /* all others */
1106 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1108 static int __init
video_init(struct ibm_init_struct
*iibm
)
1112 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1114 IBM_ACPIHANDLE_INIT(vid
);
1115 IBM_ACPIHANDLE_INIT(vid2
);
1117 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1118 /* G41, assume IVGA doesn't change */
1119 vid_handle
= vid2_handle
;
1122 /* video switching not supported on R30, R31 */
1123 video_supported
= TPACPI_VIDEO_NONE
;
1124 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1126 video_supported
= TPACPI_VIDEO_570
;
1127 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1128 /* 600e/x, 770e, 770x */
1129 video_supported
= TPACPI_VIDEO_770
;
1132 video_supported
= TPACPI_VIDEO_NEW
;
1134 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1135 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1138 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1141 static void video_exit(void)
1143 dbg_printk(TPACPI_DBG_EXIT
,
1144 "restoring original video autoswitch mode\n");
1145 if (video_autosw_set(video_orig_autosw
))
1146 printk(IBM_ERR
"error while trying to restore original "
1147 "video autoswitch mode\n");
1150 static int video_outputsw_get(void)
1155 switch (video_supported
) {
1156 case TPACPI_VIDEO_570
:
1157 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1158 TP_ACPI_VIDEO_570_PHSCMD
))
1160 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1162 case TPACPI_VIDEO_770
:
1163 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1166 status
|= TP_ACPI_VIDEO_S_LCD
;
1167 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1170 status
|= TP_ACPI_VIDEO_S_CRT
;
1172 case TPACPI_VIDEO_NEW
:
1173 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1174 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1177 status
|= TP_ACPI_VIDEO_S_CRT
;
1179 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1180 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1183 status
|= TP_ACPI_VIDEO_S_LCD
;
1184 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1187 status
|= TP_ACPI_VIDEO_S_DVI
;
1196 static int video_outputsw_set(int status
)
1201 switch (video_supported
) {
1202 case TPACPI_VIDEO_570
:
1203 res
= acpi_evalf(NULL
, NULL
,
1204 "\\_SB.PHS2", "vdd",
1205 TP_ACPI_VIDEO_570_PHS2CMD
,
1206 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1208 case TPACPI_VIDEO_770
:
1209 autosw
= video_autosw_get();
1213 res
= video_autosw_set(1);
1216 res
= acpi_evalf(vid_handle
, NULL
,
1217 "ASWT", "vdd", status
* 0x100, 0);
1218 if (!autosw
&& video_autosw_set(autosw
)) {
1219 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1223 case TPACPI_VIDEO_NEW
:
1224 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1225 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1231 return (res
)? 0 : -EIO
;
1234 static int video_autosw_get(void)
1238 switch (video_supported
) {
1239 case TPACPI_VIDEO_570
:
1240 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1243 case TPACPI_VIDEO_770
:
1244 case TPACPI_VIDEO_NEW
:
1245 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1255 static int video_autosw_set(int enable
)
1257 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1262 static int video_outputsw_cycle(void)
1264 int autosw
= video_autosw_get();
1270 switch (video_supported
) {
1271 case TPACPI_VIDEO_570
:
1272 res
= video_autosw_set(1);
1275 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1277 case TPACPI_VIDEO_770
:
1278 case TPACPI_VIDEO_NEW
:
1279 res
= video_autosw_set(1);
1282 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1287 if (!autosw
&& video_autosw_set(autosw
)) {
1288 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1292 return (res
)? 0 : -EIO
;
1295 static int video_expand_toggle(void)
1297 switch (video_supported
) {
1298 case TPACPI_VIDEO_570
:
1299 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1301 case TPACPI_VIDEO_770
:
1302 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1304 case TPACPI_VIDEO_NEW
:
1305 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1313 static int video_read(char *p
)
1318 if (video_supported
== TPACPI_VIDEO_NONE
) {
1319 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1323 status
= video_outputsw_get();
1327 autosw
= video_autosw_get();
1331 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1332 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
1333 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
1334 if (video_supported
== TPACPI_VIDEO_NEW
)
1335 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
1336 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
1337 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
1338 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
1339 if (video_supported
== TPACPI_VIDEO_NEW
)
1340 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
1341 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
1342 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
1347 static int video_write(char *buf
)
1350 int enable
, disable
, status
;
1353 if (video_supported
== TPACPI_VIDEO_NONE
)
1359 while ((cmd
= next_cmd(&buf
))) {
1360 if (strlencmp(cmd
, "lcd_enable") == 0) {
1361 enable
|= TP_ACPI_VIDEO_S_LCD
;
1362 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1363 disable
|= TP_ACPI_VIDEO_S_LCD
;
1364 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1365 enable
|= TP_ACPI_VIDEO_S_CRT
;
1366 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1367 disable
|= TP_ACPI_VIDEO_S_CRT
;
1368 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1369 strlencmp(cmd
, "dvi_enable") == 0) {
1370 enable
|= TP_ACPI_VIDEO_S_DVI
;
1371 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1372 strlencmp(cmd
, "dvi_disable") == 0) {
1373 disable
|= TP_ACPI_VIDEO_S_DVI
;
1374 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1375 res
= video_autosw_set(1);
1378 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1379 res
= video_autosw_set(0);
1382 } else if (strlencmp(cmd
, "video_switch") == 0) {
1383 res
= video_outputsw_cycle();
1386 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1387 res
= video_expand_toggle();
1394 if (enable
|| disable
) {
1395 status
= video_outputsw_get();
1398 res
= video_outputsw_set((status
& ~disable
) | enable
);
1406 static struct ibm_struct video_driver_data
= {
1409 .write
= video_write
,
1413 /*************************************************************************
1414 * Light (thinklight) subdriver
1417 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1418 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1420 static int __init
light_init(struct ibm_init_struct
*iibm
)
1422 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
1424 IBM_ACPIHANDLE_INIT(ledb
);
1425 IBM_ACPIHANDLE_INIT(lght
);
1426 IBM_ACPIHANDLE_INIT(cmos
);
1428 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1429 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1431 if (tp_features
.light
)
1432 /* light status not supported on
1433 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1434 tp_features
.light_status
=
1435 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
1437 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
1438 str_supported(tp_features
.light
));
1440 return (tp_features
.light
)? 0 : 1;
1443 static int light_read(char *p
)
1448 if (!tp_features
.light
) {
1449 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1450 } else if (!tp_features
.light_status
) {
1451 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1452 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1454 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1456 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1457 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1463 static int light_write(char *buf
)
1465 int cmos_cmd
, lght_cmd
;
1469 if (!tp_features
.light
)
1472 while ((cmd
= next_cmd(&buf
))) {
1473 if (strlencmp(cmd
, "on") == 0) {
1476 } else if (strlencmp(cmd
, "off") == 0) {
1482 success
= cmos_handle
?
1483 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1484 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1492 static struct ibm_struct light_driver_data
= {
1495 .write
= light_write
,
1498 /*************************************************************************
1502 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1504 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
1505 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1506 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1507 "\\_SB.PCI.ISA.SLCE", /* 570 */
1508 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1510 /* don't list other alternatives as we install a notify handler on the 570 */
1511 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
1513 #define dock_docked() (_sta(dock_handle) & 1)
1515 static int __init
dock_init(struct ibm_init_struct
*iibm
)
1517 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
1519 IBM_ACPIHANDLE_INIT(dock
);
1520 IBM_ACPIHANDLE_INIT(pci
);
1522 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
1523 str_supported(dock_handle
!= NULL
));
1525 return (dock_handle
)? 0 : 1;
1528 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1530 int docked
= dock_docked();
1531 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, IBM_PCI_HID
);
1533 if (event
== 1 && !pci
) /* 570 */
1534 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1535 else if (event
== 1 && pci
) /* 570 */
1536 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1537 else if (event
== 3 && docked
)
1538 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1539 else if (event
== 3 && !docked
)
1540 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
1541 else if (event
== 0 && docked
)
1542 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1544 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1545 event
, _sta(dock_handle
));
1546 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
1550 static int dock_read(char *p
)
1553 int docked
= dock_docked();
1556 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1558 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1560 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1561 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1567 static int dock_write(char *buf
)
1574 while ((cmd
= next_cmd(&buf
))) {
1575 if (strlencmp(cmd
, "undock") == 0) {
1576 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1577 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1579 } else if (strlencmp(cmd
, "dock") == 0) {
1580 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1589 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
1591 .notify
= dock_notify
,
1592 .handle
= &dock_handle
,
1593 .type
= ACPI_SYSTEM_NOTIFY
,
1597 .notify
= dock_notify
,
1598 .handle
= &pci_handle
,
1599 .type
= ACPI_SYSTEM_NOTIFY
,
1603 static struct ibm_struct dock_driver_data
[2] = {
1607 .write
= dock_write
,
1608 .acpi
= &ibm_dock_acpidriver
[0],
1612 .acpi
= &ibm_dock_acpidriver
[1],
1616 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1618 /*************************************************************************
1622 #ifdef CONFIG_THINKPAD_ACPI_BAY
1623 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1624 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1625 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1626 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1627 ); /* A21e, R30, R31 */
1628 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
1629 "_EJ0", /* all others */
1630 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1631 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1632 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1634 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
1638 static int __init
bay_init(struct ibm_init_struct
*iibm
)
1640 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
1642 IBM_ACPIHANDLE_INIT(bay
);
1644 IBM_ACPIHANDLE_INIT(bay_ej
);
1645 IBM_ACPIHANDLE_INIT(bay2
);
1647 IBM_ACPIHANDLE_INIT(bay2_ej
);
1649 tp_features
.bay_status
= bay_handle
&&
1650 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1651 tp_features
.bay_status2
= bay2_handle
&&
1652 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1654 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
1655 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1656 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
1657 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1659 vdbg_printk(TPACPI_DBG_INIT
,
1660 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1661 str_supported(tp_features
.bay_status
),
1662 str_supported(tp_features
.bay_eject
),
1663 str_supported(tp_features
.bay_status2
),
1664 str_supported(tp_features
.bay_eject2
));
1666 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
1667 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
1670 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1672 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1675 #define bay_occupied(b) (_sta(b##_handle) & 1)
1677 static int bay_read(char *p
)
1680 int occupied
= bay_occupied(bay
);
1681 int occupied2
= bay_occupied(bay2
);
1684 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1685 tp_features
.bay_status
?
1686 (occupied
? "occupied" : "unoccupied") :
1688 if (tp_features
.bay_status2
)
1689 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1690 "occupied" : "unoccupied");
1692 eject
= tp_features
.bay_eject
&& occupied
;
1693 eject2
= tp_features
.bay_eject2
&& occupied2
;
1695 if (eject
&& eject2
)
1696 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1698 len
+= sprintf(p
+ len
, "commands:\teject\n");
1700 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1705 static int bay_write(char *buf
)
1709 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
1712 while ((cmd
= next_cmd(&buf
))) {
1713 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
1714 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1716 } else if (tp_features
.bay_eject2
&&
1717 strlencmp(cmd
, "eject2") == 0) {
1718 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1727 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
1728 .notify
= bay_notify
,
1729 .handle
= &bay_handle
,
1730 .type
= ACPI_SYSTEM_NOTIFY
,
1733 static struct ibm_struct bay_driver_data
= {
1737 .acpi
= &ibm_bay_acpidriver
,
1740 #endif /* CONFIG_THINKPAD_ACPI_BAY */
1742 /*************************************************************************
1746 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
1748 vdbg_printk(TPACPI_DBG_INIT
,
1749 "initializing cmos commands subdriver\n");
1751 IBM_ACPIHANDLE_INIT(cmos
);
1753 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
1754 str_supported(cmos_handle
!= NULL
));
1755 return (cmos_handle
)? 0 : 1;
1758 static int cmos_read(char *p
)
1762 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1763 R30, R31, T20-22, X20-21 */
1765 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1767 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1768 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1774 static int cmos_write(char *buf
)
1779 while ((cmd
= next_cmd(&buf
))) {
1780 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1781 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1786 res
= issue_thinkpad_cmos_command(cmos_cmd
);
1794 static struct ibm_struct cmos_driver_data
= {
1797 .write
= cmos_write
,
1800 /*************************************************************************
1804 static enum led_access_mode led_supported
;
1806 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
1807 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1808 "LED", /* all others */
1811 static int __init
led_init(struct ibm_init_struct
*iibm
)
1813 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
1815 IBM_ACPIHANDLE_INIT(led
);
1818 /* led not supported on R30, R31 */
1819 led_supported
= TPACPI_LED_NONE
;
1820 else if (strlencmp(led_path
, "SLED") == 0)
1822 led_supported
= TPACPI_LED_570
;
1823 else if (strlencmp(led_path
, "SYSL") == 0)
1824 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1825 led_supported
= TPACPI_LED_OLD
;
1828 led_supported
= TPACPI_LED_NEW
;
1830 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
1831 str_supported(led_supported
), led_supported
);
1833 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
1836 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1838 static int led_read(char *p
)
1842 if (!led_supported
) {
1843 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1846 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1848 if (led_supported
== TPACPI_LED_570
) {
1851 for (i
= 0; i
< 8; i
++) {
1852 if (!acpi_evalf(ec_handle
,
1853 &status
, "GLED", "dd", 1 << i
))
1855 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1856 i
, led_status(status
));
1860 len
+= sprintf(p
+ len
, "commands:\t"
1861 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1866 /* off, on, blink */
1867 static const int led_sled_arg1
[] = { 0, 1, 3 };
1868 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
1869 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
1870 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
1872 static int led_write(char *buf
)
1880 while ((cmd
= next_cmd(&buf
))) {
1881 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1884 if (strstr(cmd
, "off")) {
1886 } else if (strstr(cmd
, "on")) {
1888 } else if (strstr(cmd
, "blink")) {
1893 if (led_supported
== TPACPI_LED_570
) {
1896 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1897 led
, led_sled_arg1
[ind
]))
1899 } else if (led_supported
== TPACPI_LED_OLD
) {
1900 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1902 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
1905 ec_write(TPACPI_LED_EC_HLBL
,
1906 led
* led_exp_hlbl
[ind
]);
1909 ec_write(TPACPI_LED_EC_HLCL
,
1910 led
* led_exp_hlcl
[ind
]);
1915 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1916 led
, led_led_arg1
[ind
]))
1924 static struct ibm_struct led_driver_data
= {
1930 /*************************************************************************
1934 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
1936 static int __init
beep_init(struct ibm_init_struct
*iibm
)
1938 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
1940 IBM_ACPIHANDLE_INIT(beep
);
1942 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
1943 str_supported(beep_handle
!= NULL
));
1945 return (beep_handle
)? 0 : 1;
1948 static int beep_read(char *p
)
1953 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1955 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1956 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1962 static int beep_write(char *buf
)
1970 while ((cmd
= next_cmd(&buf
))) {
1971 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1972 beep_cmd
>= 0 && beep_cmd
<= 17) {
1976 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1983 static struct ibm_struct beep_driver_data
= {
1986 .write
= beep_write
,
1989 /*************************************************************************
1993 static enum thermal_access_mode thermal_read_mode
;
1995 /* sysfs temp##_input -------------------------------------------------- */
1997 static ssize_t
thermal_temp_input_show(struct device
*dev
,
1998 struct device_attribute
*attr
,
2001 struct sensor_device_attribute
*sensor_attr
=
2002 to_sensor_dev_attr(attr
);
2003 int idx
= sensor_attr
->index
;
2007 res
= thermal_get_sensor(idx
, &value
);
2010 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2013 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2016 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2017 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2019 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2020 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2021 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2022 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2023 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2024 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2025 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2026 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2027 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2028 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2029 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2030 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2031 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2032 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2033 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2034 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2035 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2038 #define THERMAL_ATTRS(X) \
2039 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2041 static struct attribute
*thermal_temp_input_attr
[] = {
2061 static const struct attribute_group thermal_temp_input16_group
= {
2062 .attrs
= thermal_temp_input_attr
2065 static const struct attribute_group thermal_temp_input8_group
= {
2066 .attrs
= &thermal_temp_input_attr
[8]
2069 #undef THERMAL_SENSOR_ATTR_TEMP
2070 #undef THERMAL_ATTRS
2072 /* --------------------------------------------------------------------- */
2074 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2081 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2083 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2085 if (ibm_thinkpad_ec_found
&& experimental
) {
2087 * Direct EC access mode: sensors at registers
2088 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2089 * non-implemented, thermal sensors return 0x80 when
2094 for (i
= 0; i
< 8; i
++) {
2095 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2101 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2109 /* This is sheer paranoia, but we handle it anyway */
2112 "ThinkPad ACPI EC access misbehaving, "
2113 "falling back to ACPI TMPx access mode\n");
2114 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2117 "ThinkPad ACPI EC access misbehaving, "
2118 "disabling thermal sensors access\n");
2119 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2124 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2126 } else if (acpi_tmp7
) {
2127 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2128 /* 600e/x, 770e, 770x */
2129 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2131 /* Standard ACPI TMPx access, max 8 sensors */
2132 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2135 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2136 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2139 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2140 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2143 switch(thermal_read_mode
) {
2144 case TPACPI_THERMAL_TPEC_16
:
2145 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2146 &thermal_temp_input16_group
);
2150 case TPACPI_THERMAL_TPEC_8
:
2151 case TPACPI_THERMAL_ACPI_TMP07
:
2152 case TPACPI_THERMAL_ACPI_UPDT
:
2153 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2154 &thermal_temp_input8_group
);
2158 case TPACPI_THERMAL_NONE
:
2166 static void thermal_exit(void)
2168 switch(thermal_read_mode
) {
2169 case TPACPI_THERMAL_TPEC_16
:
2170 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2171 &thermal_temp_input16_group
);
2173 case TPACPI_THERMAL_TPEC_8
:
2174 case TPACPI_THERMAL_ACPI_TMP07
:
2175 case TPACPI_THERMAL_ACPI_UPDT
:
2176 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2177 &thermal_temp_input16_group
);
2179 case TPACPI_THERMAL_NONE
:
2185 /* idx is zero-based */
2186 static int thermal_get_sensor(int idx
, s32
*value
)
2192 t
= TP_EC_THERMAL_TMP0
;
2194 switch (thermal_read_mode
) {
2195 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2196 case TPACPI_THERMAL_TPEC_16
:
2197 if (idx
>= 8 && idx
<= 15) {
2198 t
= TP_EC_THERMAL_TMP8
;
2203 case TPACPI_THERMAL_TPEC_8
:
2205 if (!acpi_ec_read(t
+ idx
, &tmp
))
2207 *value
= tmp
* 1000;
2212 case TPACPI_THERMAL_ACPI_UPDT
:
2214 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2215 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2217 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2219 *value
= (t
- 2732) * 100;
2224 case TPACPI_THERMAL_ACPI_TMP07
:
2226 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2227 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2234 case TPACPI_THERMAL_NONE
:
2242 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2253 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2256 for(i
= 0 ; i
< n
; i
++) {
2257 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
2265 static int thermal_read(char *p
)
2269 struct ibm_thermal_sensors_struct t
;
2271 n
= thermal_get_sensors(&t
);
2272 if (unlikely(n
< 0))
2275 len
+= sprintf(p
+ len
, "temperatures:\t");
2278 for (i
= 0; i
< (n
- 1); i
++)
2279 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
2280 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
2282 len
+= sprintf(p
+ len
, "not supported\n");
2287 static struct ibm_struct thermal_driver_data
= {
2289 .read
= thermal_read
,
2290 .exit
= thermal_exit
,
2293 /*************************************************************************
2297 static u8 ecdump_regs
[256];
2299 static int ecdump_read(char *p
)
2305 len
+= sprintf(p
+ len
, "EC "
2306 " +00 +01 +02 +03 +04 +05 +06 +07"
2307 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2308 for (i
= 0; i
< 256; i
+= 16) {
2309 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
2310 for (j
= 0; j
< 16; j
++) {
2311 if (!acpi_ec_read(i
+ j
, &v
))
2313 if (v
!= ecdump_regs
[i
+ j
])
2314 len
+= sprintf(p
+ len
, " *%02x", v
);
2316 len
+= sprintf(p
+ len
, " %02x", v
);
2317 ecdump_regs
[i
+ j
] = v
;
2319 len
+= sprintf(p
+ len
, "\n");
2324 /* These are way too dangerous to advertise openly... */
2326 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
2327 " (<offset> is 00-ff, <value> is 00-ff)\n");
2328 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
2329 " (<offset> is 00-ff, <value> is 0-255)\n");
2334 static int ecdump_write(char *buf
)
2339 while ((cmd
= next_cmd(&buf
))) {
2340 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
2342 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
2346 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
2347 if (!acpi_ec_write(i
, v
))
2356 static struct ibm_struct ecdump_driver_data
= {
2358 .read
= ecdump_read
,
2359 .write
= ecdump_write
,
2360 .flags
.experimental
= 1,
2363 /*************************************************************************
2364 * Backlight/brightness subdriver
2367 static struct backlight_device
*ibm_backlight_device
= NULL
;
2369 static struct backlight_properties ibm_backlight_data
= {
2370 .owner
= THIS_MODULE
,
2371 .get_brightness
= brightness_get
,
2372 .update_status
= brightness_update_status
,
2373 .max_brightness
= 7,
2376 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
2380 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
2382 b
= brightness_get(NULL
);
2386 ibm_backlight_device
= backlight_device_register("ibm", NULL
, NULL
,
2387 &ibm_backlight_data
);
2388 if (IS_ERR(ibm_backlight_device
)) {
2389 printk(IBM_ERR
"Could not register backlight device\n");
2390 return PTR_ERR(ibm_backlight_device
);
2392 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
2394 ibm_backlight_device
->props
->brightness
= b
;
2395 brightness_update_status(ibm_backlight_device
);
2400 static void brightness_exit(void)
2402 if (ibm_backlight_device
) {
2403 vdbg_printk(TPACPI_DBG_EXIT
,
2404 "calling backlight_device_unregister()\n");
2405 backlight_device_unregister(ibm_backlight_device
);
2406 ibm_backlight_device
= NULL
;
2410 static int brightness_update_status(struct backlight_device
*bd
)
2412 return brightness_set(
2413 (bd
->props
->fb_blank
== FB_BLANK_UNBLANK
&&
2414 bd
->props
->power
== FB_BLANK_UNBLANK
) ?
2415 bd
->props
->brightness
: 0);
2418 static int brightness_get(struct backlight_device
*bd
)
2421 if (!acpi_ec_read(brightness_offset
, &level
))
2429 static int brightness_set(int value
)
2431 int cmos_cmd
, inc
, i
;
2432 int current_value
= brightness_get(NULL
);
2436 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
2437 inc
= value
> current_value
? 1 : -1;
2438 for (i
= current_value
; i
!= value
; i
+= inc
) {
2439 if (issue_thinkpad_cmos_command(cmos_cmd
))
2441 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
2448 static int brightness_read(char *p
)
2453 if ((level
= brightness_get(NULL
)) < 0) {
2454 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2456 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
2457 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
2458 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2459 " (<level> is 0-7)\n");
2465 static int brightness_write(char *buf
)
2471 while ((cmd
= next_cmd(&buf
))) {
2472 if ((level
= brightness_get(NULL
)) < 0)
2476 if (strlencmp(cmd
, "up") == 0) {
2477 new_level
= level
== 7 ? 7 : level
+ 1;
2478 } else if (strlencmp(cmd
, "down") == 0) {
2479 new_level
= level
== 0 ? 0 : level
- 1;
2480 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2481 new_level
>= 0 && new_level
<= 7) {
2486 brightness_set(new_level
);
2492 static struct ibm_struct brightness_driver_data
= {
2493 .name
= "brightness",
2494 .read
= brightness_read
,
2495 .write
= brightness_write
,
2496 .exit
= brightness_exit
,
2499 /*************************************************************************
2503 static int volume_read(char *p
)
2508 if (!acpi_ec_read(volume_offset
, &level
)) {
2509 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2511 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
2512 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
2513 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
2514 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2515 " (<level> is 0-15)\n");
2521 static int volume_write(char *buf
)
2523 int cmos_cmd
, inc
, i
;
2525 int new_level
, new_mute
;
2528 while ((cmd
= next_cmd(&buf
))) {
2529 if (!acpi_ec_read(volume_offset
, &level
))
2531 new_mute
= mute
= level
& 0x40;
2532 new_level
= level
= level
& 0xf;
2534 if (strlencmp(cmd
, "up") == 0) {
2538 new_level
= level
== 15 ? 15 : level
+ 1;
2539 } else if (strlencmp(cmd
, "down") == 0) {
2543 new_level
= level
== 0 ? 0 : level
- 1;
2544 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2545 new_level
>= 0 && new_level
<= 15) {
2547 } else if (strlencmp(cmd
, "mute") == 0) {
2552 if (new_level
!= level
) { /* mute doesn't change */
2553 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
2554 inc
= new_level
> level
? 1 : -1;
2556 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
2557 !acpi_ec_write(volume_offset
, level
)))
2560 for (i
= level
; i
!= new_level
; i
+= inc
)
2561 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2562 !acpi_ec_write(volume_offset
, i
+ inc
))
2565 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
2566 !acpi_ec_write(volume_offset
,
2571 if (new_mute
!= mute
) { /* level doesn't change */
2572 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
2574 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2575 !acpi_ec_write(volume_offset
, level
+ new_mute
))
2583 static struct ibm_struct volume_driver_data
= {
2585 .read
= volume_read
,
2586 .write
= volume_write
,
2589 /*************************************************************************
2596 * TPACPI_FAN_RD_ACPI_GFAN:
2597 * ACPI GFAN method: returns fan level
2599 * see TPACPI_FAN_WR_ACPI_SFAN
2600 * EC 0x2f (HFSP) not available if GFAN exists
2602 * TPACPI_FAN_WR_ACPI_SFAN:
2603 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2605 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2608 * TPACPI_FAN_WR_TPEC:
2609 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2610 * Supported on almost all ThinkPads
2612 * Fan speed changes of any sort (including those caused by the
2613 * disengaged mode) are usually done slowly by the firmware as the
2614 * maximum ammount of fan duty cycle change per second seems to be
2617 * Reading is not available if GFAN exists.
2618 * Writing is not available if SFAN exists.
2621 * 7 automatic mode engaged;
2622 * (default operation mode of the ThinkPad)
2623 * fan level is ignored in this mode.
2624 * 6 full speed mode (takes precedence over bit 7);
2625 * not available on all thinkpads. May disable
2626 * the tachometer while the fan controller ramps up
2627 * the speed (which can take up to a few *minutes*).
2628 * Speeds up fan to 100% duty-cycle, which is far above
2629 * the standard RPM levels. It is not impossible that
2630 * it could cause hardware damage.
2631 * 5-3 unused in some models. Extra bits for fan level
2632 * in others, but still useless as all values above
2633 * 7 map to the same speed as level 7 in these models.
2634 * 2-0 fan level (0..7 usually)
2636 * 0x07 = max (set when temperatures critical)
2637 * Some ThinkPads may have other levels, see
2638 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2640 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2641 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2642 * does so, its initial value is meaningless (0x07).
2644 * For firmware bugs, refer to:
2645 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2649 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2650 * Main fan tachometer reading (in RPM)
2652 * This register is present on all ThinkPads with a new-style EC, and
2653 * it is known not to be present on the A21m/e, and T22, as there is
2654 * something else in offset 0x84 according to the ACPI DSDT. Other
2655 * ThinkPads from this same time period (and earlier) probably lack the
2656 * tachometer as well.
2658 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2659 * was never fixed by IBM to report the EC firmware version string
2660 * probably support the tachometer (like the early X models), so
2661 * detecting it is quite hard. We need more data to know for sure.
2663 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2666 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2669 * For firmware bugs, refer to:
2670 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2672 * TPACPI_FAN_WR_ACPI_FANS:
2673 * ThinkPad X31, X40, X41. Not available in the X60.
2675 * FANS ACPI handle: takes three arguments: low speed, medium speed,
2676 * high speed. ACPI DSDT seems to map these three speeds to levels
2677 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
2678 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
2680 * The speeds are stored on handles
2681 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
2683 * There are three default speed sets, acessible as handles:
2684 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
2686 * ACPI DSDT switches which set is in use depending on various
2689 * TPACPI_FAN_WR_TPEC is also available and should be used to
2690 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
2691 * but the ACPI tables just mention level 7.
2694 static enum fan_status_access_mode fan_status_access_mode
;
2695 static enum fan_control_access_mode fan_control_access_mode
;
2696 static enum fan_control_commands fan_control_commands
;
2698 static u8 fan_control_initial_status
;
2700 static void fan_watchdog_fire(struct work_struct
*ignored
);
2701 static int fan_watchdog_maxinterval
;
2702 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
2704 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
2705 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
2706 "\\FSPD", /* 600e/x, 770e, 770x */
2708 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
2709 "JFNS", /* 770x-JL */
2712 static int __init
fan_init(struct ibm_init_struct
*iibm
)
2714 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
2716 mutex_init(&fan_mutex
);
2717 fan_status_access_mode
= TPACPI_FAN_NONE
;
2718 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
2719 fan_control_commands
= 0;
2720 fan_watchdog_maxinterval
= 0;
2721 tp_features
.fan_ctrl_status_undef
= 0;
2723 IBM_ACPIHANDLE_INIT(fans
);
2724 IBM_ACPIHANDLE_INIT(gfan
);
2725 IBM_ACPIHANDLE_INIT(sfan
);
2728 /* 570, 600e/x, 770e, 770x */
2729 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
2731 /* all other ThinkPads: note that even old-style
2732 * ThinkPad ECs supports the fan control register */
2733 if (likely(acpi_ec_read(fan_status_offset
,
2734 &fan_control_initial_status
))) {
2735 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
2737 /* In some ThinkPads, neither the EC nor the ACPI
2738 * DSDT initialize the fan status, and it ends up
2739 * being set to 0x07 when it *could* be either
2742 * Enable for TP-1Y (T43), TP-78 (R51e),
2743 * TP-76 (R52), TP-70 (T43, R52), which are known
2745 if (fan_control_initial_status
== 0x07 &&
2746 ibm_thinkpad_ec_found
&&
2747 ((ibm_thinkpad_ec_found
[0] == '1' &&
2748 ibm_thinkpad_ec_found
[1] == 'Y') ||
2749 (ibm_thinkpad_ec_found
[0] == '7' &&
2750 (ibm_thinkpad_ec_found
[1] == '6' ||
2751 ibm_thinkpad_ec_found
[1] == '8' ||
2752 ibm_thinkpad_ec_found
[1] == '0'))
2755 "fan_init: initial fan status is "
2756 "unknown, assuming it is in auto "
2758 tp_features
.fan_ctrl_status_undef
= 1;
2762 "ThinkPad ACPI EC access misbehaving, "
2763 "fan status and control unavailable\n");
2770 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
2771 fan_control_commands
|=
2772 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
2775 /* gfan without sfan means no fan control */
2776 /* all other models implement TP EC 0x2f control */
2780 fan_control_access_mode
=
2781 TPACPI_FAN_WR_ACPI_FANS
;
2782 fan_control_commands
|=
2783 TPACPI_FAN_CMD_SPEED
|
2784 TPACPI_FAN_CMD_LEVEL
|
2785 TPACPI_FAN_CMD_ENABLE
;
2787 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
2788 fan_control_commands
|=
2789 TPACPI_FAN_CMD_LEVEL
|
2790 TPACPI_FAN_CMD_ENABLE
;
2795 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
2796 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
2797 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
2798 fan_status_access_mode
, fan_control_access_mode
);
2800 return (fan_status_access_mode
!= TPACPI_FAN_NONE
||
2801 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
)?
2805 static int fan_get_status(u8
*status
)
2810 * Add TPACPI_FAN_RD_ACPI_FANS ? */
2812 switch (fan_status_access_mode
) {
2813 case TPACPI_FAN_RD_ACPI_GFAN
:
2814 /* 570, 600e/x, 770e, 770x */
2816 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
2824 case TPACPI_FAN_RD_TPEC
:
2825 /* all except 570, 600e/x, 770e, 770x */
2826 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
2841 static void fan_exit(void)
2843 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
2844 cancel_delayed_work(&fan_watchdog_task
);
2845 flush_scheduled_work();
2848 static int fan_get_speed(unsigned int *speed
)
2852 switch (fan_status_access_mode
) {
2853 case TPACPI_FAN_RD_TPEC
:
2854 /* all except 570, 600e/x, 770e, 770x */
2855 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
2856 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
2860 *speed
= (hi
<< 8) | lo
;
2871 static void fan_watchdog_fire(struct work_struct
*ignored
)
2875 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
2876 rc
= fan_set_enable();
2878 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
2879 "will try again later...\n", -rc
);
2880 /* reschedule for later */
2881 fan_watchdog_reset();
2885 static void fan_watchdog_reset(void)
2887 static int fan_watchdog_active
= 0;
2889 if (fan_watchdog_active
)
2890 cancel_delayed_work(&fan_watchdog_task
);
2892 if (fan_watchdog_maxinterval
> 0) {
2893 fan_watchdog_active
= 1;
2894 if (!schedule_delayed_work(&fan_watchdog_task
,
2895 msecs_to_jiffies(fan_watchdog_maxinterval
2897 printk(IBM_ERR
"failed to schedule the fan watchdog, "
2898 "watchdog will not trigger\n");
2901 fan_watchdog_active
= 0;
2904 static int fan_set_level(int level
)
2908 switch (fan_control_access_mode
) {
2909 case TPACPI_FAN_WR_ACPI_SFAN
:
2910 if (level
>= 0 && level
<= 7) {
2911 res
= mutex_lock_interruptible(&fan_mutex
);
2914 res
= acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
);
2915 mutex_unlock(&fan_mutex
);
2922 case TPACPI_FAN_WR_ACPI_FANS
:
2923 case TPACPI_FAN_WR_TPEC
:
2924 if ((level
!= TP_EC_FAN_AUTO
) &&
2925 (level
!= TP_EC_FAN_FULLSPEED
) &&
2926 ((level
< 0) || (level
> 7)))
2929 res
= mutex_lock_interruptible(&fan_mutex
);
2932 res
= acpi_ec_write(fan_status_offset
, level
);
2933 mutex_unlock(&fan_mutex
);
2937 tp_features
.fan_ctrl_status_undef
= 0;
2946 static int fan_set_enable(void)
2951 rc
= mutex_lock_interruptible(&fan_mutex
);
2955 switch (fan_control_access_mode
) {
2956 case TPACPI_FAN_WR_ACPI_FANS
:
2957 case TPACPI_FAN_WR_TPEC
:
2958 rc
= fan_get_status(&s
);
2962 /* Don't go out of emergency fan mode */
2966 if (!acpi_ec_write(fan_status_offset
, s
))
2969 tp_features
.fan_ctrl_status_undef
= 0;
2974 case TPACPI_FAN_WR_ACPI_SFAN
:
2975 rc
= fan_get_status(&s
);
2981 /* Set fan to at least level 4 */
2985 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
2995 mutex_unlock(&fan_mutex
);
2999 static int fan_set_disable(void)
3003 rc
= mutex_lock_interruptible(&fan_mutex
);
3008 switch (fan_control_access_mode
) {
3009 case TPACPI_FAN_WR_ACPI_FANS
:
3010 case TPACPI_FAN_WR_TPEC
:
3011 if (!acpi_ec_write(fan_status_offset
, 0x00))
3014 tp_features
.fan_ctrl_status_undef
= 0;
3017 case TPACPI_FAN_WR_ACPI_SFAN
:
3018 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
3026 mutex_unlock(&fan_mutex
);
3030 static int fan_set_speed(int speed
)
3034 rc
= mutex_lock_interruptible(&fan_mutex
);
3039 switch (fan_control_access_mode
) {
3040 case TPACPI_FAN_WR_ACPI_FANS
:
3041 if (speed
>= 0 && speed
<= 65535) {
3042 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
3043 speed
, speed
, speed
))
3053 mutex_unlock(&fan_mutex
);
3057 static int fan_read(char *p
)
3062 unsigned int speed
= 0;
3064 switch (fan_status_access_mode
) {
3065 case TPACPI_FAN_RD_ACPI_GFAN
:
3066 /* 570, 600e/x, 770e, 770x */
3067 if ((rc
= fan_get_status(&status
)) < 0)
3070 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
3072 (status
!= 0) ? "enabled" : "disabled", status
);
3075 case TPACPI_FAN_RD_TPEC
:
3076 /* all except 570, 600e/x, 770e, 770x */
3077 if ((rc
= fan_get_status(&status
)) < 0)
3080 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3081 if (status
!= fan_control_initial_status
)
3082 tp_features
.fan_ctrl_status_undef
= 0;
3084 /* Return most likely status. In fact, it
3085 * might be the only possible status */
3086 status
= TP_EC_FAN_AUTO
;
3089 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3090 (status
!= 0) ? "enabled" : "disabled");
3092 if ((rc
= fan_get_speed(&speed
)) < 0)
3095 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
3097 if (status
& TP_EC_FAN_FULLSPEED
)
3098 /* Disengaged mode takes precedence */
3099 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
3100 else if (status
& TP_EC_FAN_AUTO
)
3101 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
3103 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
3106 case TPACPI_FAN_NONE
:
3108 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3111 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
3112 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
3114 switch (fan_control_access_mode
) {
3115 case TPACPI_FAN_WR_ACPI_SFAN
:
3116 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
3120 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
3121 "auto, disengaged)\n");
3126 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
3127 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
3128 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
3129 "1-120 (seconds))\n");
3131 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
3132 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
3133 " (<speed> is 0-65535)\n");
3138 static int fan_write_cmd_level(const char *cmd
, int *rc
)
3142 if (strlencmp(cmd
, "level auto") == 0)
3143 level
= TP_EC_FAN_AUTO
;
3144 else if (strlencmp(cmd
, "level disengaged") == 0)
3145 level
= TP_EC_FAN_FULLSPEED
;
3146 else if (sscanf(cmd
, "level %d", &level
) != 1)
3149 if ((*rc
= fan_set_level(level
)) == -ENXIO
)
3150 printk(IBM_ERR
"level command accepted for unsupported "
3151 "access mode %d", fan_control_access_mode
);
3156 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
3158 if (strlencmp(cmd
, "enable") != 0)
3161 if ((*rc
= fan_set_enable()) == -ENXIO
)
3162 printk(IBM_ERR
"enable command accepted for unsupported "
3163 "access mode %d", fan_control_access_mode
);
3168 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
3170 if (strlencmp(cmd
, "disable") != 0)
3173 if ((*rc
= fan_set_disable()) == -ENXIO
)
3174 printk(IBM_ERR
"disable command accepted for unsupported "
3175 "access mode %d", fan_control_access_mode
);
3180 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
3185 * Support speed <low> <medium> <high> ? */
3187 if (sscanf(cmd
, "speed %d", &speed
) != 1)
3190 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
3191 printk(IBM_ERR
"speed command accepted for unsupported "
3192 "access mode %d", fan_control_access_mode
);
3197 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
3201 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
3204 if (interval
< 0 || interval
> 120)
3207 fan_watchdog_maxinterval
= interval
;
3212 static int fan_write(char *buf
)
3217 while (!rc
&& (cmd
= next_cmd(&buf
))) {
3218 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
3219 fan_write_cmd_level(cmd
, &rc
)) &&
3220 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
3221 (fan_write_cmd_enable(cmd
, &rc
) ||
3222 fan_write_cmd_disable(cmd
, &rc
) ||
3223 fan_write_cmd_watchdog(cmd
, &rc
))) &&
3224 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
3225 fan_write_cmd_speed(cmd
, &rc
))
3229 fan_watchdog_reset();
3235 static struct ibm_struct fan_driver_data
= {
3240 .flags
.experimental
= 1,
3243 /****************************************************************************
3244 ****************************************************************************
3248 ****************************************************************************
3249 ****************************************************************************/
3252 static struct proc_dir_entry
*proc_dir
= NULL
;
3254 /* Subdriver registry */
3255 static LIST_HEAD(tpacpi_all_drivers
);
3259 * Module and infrastructure proble, init and exit handling
3262 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
3263 static const char * __init
str_supported(int is_supported
)
3265 static char text_unsupported
[] __initdata
= "not supported";
3267 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
3269 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
3271 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
3274 struct ibm_struct
*ibm
= iibm
->data
;
3275 struct proc_dir_entry
*entry
;
3277 BUG_ON(ibm
== NULL
);
3279 INIT_LIST_HEAD(&ibm
->all_drivers
);
3281 if (ibm
->flags
.experimental
&& !experimental
)
3284 dbg_printk(TPACPI_DBG_INIT
,
3285 "probing for %s\n", ibm
->name
);
3288 ret
= iibm
->init(iibm
);
3290 return 0; /* probe failed */
3294 ibm
->flags
.init_called
= 1;
3298 if (ibm
->acpi
->hid
) {
3299 ret
= register_tpacpi_subdriver(ibm
);
3304 if (ibm
->acpi
->notify
) {
3305 ret
= setup_acpi_notify(ibm
);
3306 if (ret
== -ENODEV
) {
3307 printk(IBM_NOTICE
"disabling subdriver %s\n",
3317 dbg_printk(TPACPI_DBG_INIT
,
3318 "%s installed\n", ibm
->name
);
3321 entry
= create_proc_entry(ibm
->name
,
3322 S_IFREG
| S_IRUGO
| S_IWUSR
,
3325 printk(IBM_ERR
"unable to create proc entry %s\n",
3330 entry
->owner
= THIS_MODULE
;
3332 entry
->read_proc
= &dispatch_procfs_read
;
3334 entry
->write_proc
= &dispatch_procfs_write
;
3335 ibm
->flags
.proc_created
= 1;
3338 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
3343 dbg_printk(TPACPI_DBG_INIT
,
3344 "%s: at error exit path with result %d\n",
3348 return (ret
< 0)? ret
: 0;
3351 static void ibm_exit(struct ibm_struct
*ibm
)
3353 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
3355 list_del_init(&ibm
->all_drivers
);
3357 if (ibm
->flags
.acpi_notify_installed
) {
3358 dbg_printk(TPACPI_DBG_EXIT
,
3359 "%s: acpi_remove_notify_handler\n", ibm
->name
);
3361 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
3363 dispatch_acpi_notify
);
3364 ibm
->flags
.acpi_notify_installed
= 0;
3365 ibm
->flags
.acpi_notify_installed
= 0;
3368 if (ibm
->flags
.proc_created
) {
3369 dbg_printk(TPACPI_DBG_EXIT
,
3370 "%s: remove_proc_entry\n", ibm
->name
);
3371 remove_proc_entry(ibm
->name
, proc_dir
);
3372 ibm
->flags
.proc_created
= 0;
3375 if (ibm
->flags
.acpi_driver_registered
) {
3376 dbg_printk(TPACPI_DBG_EXIT
,
3377 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
3379 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
3380 kfree(ibm
->acpi
->driver
);
3381 ibm
->acpi
->driver
= NULL
;
3382 ibm
->flags
.acpi_driver_registered
= 0;
3385 if (ibm
->flags
.init_called
&& ibm
->exit
) {
3387 ibm
->flags
.init_called
= 0;
3390 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
3395 static char *ibm_thinkpad_ec_found
= NULL
;
3397 static char* __init
check_dmi_for_ec(void)
3399 struct dmi_device
*dev
= NULL
;
3400 char ec_fw_string
[18];
3403 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
3404 * X32 or newer, all Z series; Some models must have an
3405 * up-to-date BIOS or they will not be detected.
3407 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
3409 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
3410 if (sscanf(dev
->name
,
3411 "IBM ThinkPad Embedded Controller -[%17c",
3412 ec_fw_string
) == 1) {
3413 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
3414 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
3415 return kstrdup(ec_fw_string
, GFP_KERNEL
);
3421 static int __init
probe_for_thinkpad(void)
3429 * Non-ancient models have better DMI tagging, but very old models
3432 is_thinkpad
= dmi_name_in_vendors("ThinkPad");
3434 /* ec is required because many other handles are relative to it */
3435 IBM_ACPIHANDLE_INIT(ec
);
3439 "Not yet supported ThinkPad detected!\n");
3444 * Risks a regression on very old machines, but reduces potential
3445 * false positives a damn great deal
3448 is_thinkpad
= dmi_name_in_vendors("IBM");
3450 if (!is_thinkpad
&& !force_load
)
3457 /* Module init, exit, parameters */
3459 static struct ibm_init_struct ibms_init
[] __initdata
= {
3461 .init
= thinkpad_acpi_driver_init
,
3462 .data
= &thinkpad_acpi_driver_data
,
3465 .init
= hotkey_init
,
3466 .data
= &hotkey_driver_data
,
3469 .init
= bluetooth_init
,
3470 .data
= &bluetooth_driver_data
,
3474 .data
= &wan_driver_data
,
3478 .data
= &video_driver_data
,
3482 .data
= &light_driver_data
,
3484 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3487 .data
= &dock_driver_data
[0],
3490 .data
= &dock_driver_data
[1],
3493 #ifdef CONFIG_THINKPAD_ACPI_BAY
3496 .data
= &bay_driver_data
,
3501 .data
= &cmos_driver_data
,
3505 .data
= &led_driver_data
,
3509 .data
= &beep_driver_data
,
3512 .init
= thermal_init
,
3513 .data
= &thermal_driver_data
,
3516 .data
= &ecdump_driver_data
,
3519 .init
= brightness_init
,
3520 .data
= &brightness_driver_data
,
3523 .data
= &volume_driver_data
,
3527 .data
= &fan_driver_data
,
3531 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
3534 struct ibm_struct
*ibm
;
3536 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
3537 ibm
= ibms_init
[i
].data
;
3538 BUG_ON(ibm
== NULL
);
3540 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
3541 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
3543 strcpy(ibms_init
[i
].param
, val
);
3544 strcat(ibms_init
[i
].param
, ",");
3552 static int experimental
;
3553 module_param(experimental
, int, 0);
3555 static u32 dbg_level
;
3556 module_param_named(debug
, dbg_level
, uint
, 0);
3558 static int force_load
;
3559 module_param(force_load
, int, 0);
3561 #define IBM_PARAM(feature) \
3562 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
3565 IBM_PARAM(bluetooth
);
3568 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3571 #ifdef CONFIG_THINKPAD_ACPI_BAY
3573 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3578 IBM_PARAM(brightness
);
3582 static int __init
thinkpad_acpi_module_init(void)
3586 /* Driver-level probe */
3587 ret
= probe_for_thinkpad();
3591 /* Driver initialization */
3592 ibm_thinkpad_ec_found
= check_dmi_for_ec();
3593 IBM_ACPIHANDLE_INIT(ecrd
);
3594 IBM_ACPIHANDLE_INIT(ecwr
);
3596 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
3598 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
3599 thinkpad_acpi_module_exit();
3602 proc_dir
->owner
= THIS_MODULE
;
3604 ret
= platform_driver_register(&tpacpi_pdriver
);
3606 printk(IBM_ERR
"unable to register platform driver\n");
3607 thinkpad_acpi_module_exit();
3610 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
3612 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
3613 thinkpad_acpi_module_exit();
3618 /* Device initialization */
3619 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
3621 if (IS_ERR(tpacpi_pdev
)) {
3622 ret
= PTR_ERR(tpacpi_pdev
);
3624 printk(IBM_ERR
"unable to register platform device\n");
3625 thinkpad_acpi_module_exit();
3628 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
3629 if (IS_ERR(tpacpi_hwmon
)) {
3630 ret
= PTR_ERR(tpacpi_hwmon
);
3631 tpacpi_hwmon
= NULL
;
3632 printk(IBM_ERR
"unable to register hwmon device\n");
3633 thinkpad_acpi_module_exit();
3636 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
3637 ret
= ibm_init(&ibms_init
[i
]);
3638 if (ret
>= 0 && *ibms_init
[i
].param
)
3639 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
3641 thinkpad_acpi_module_exit();
3649 static void thinkpad_acpi_module_exit(void)
3651 struct ibm_struct
*ibm
, *itmp
;
3653 list_for_each_entry_safe_reverse(ibm
, itmp
,
3654 &tpacpi_all_drivers
,
3659 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
3662 hwmon_device_unregister(tpacpi_hwmon
);
3665 platform_device_unregister(tpacpi_pdev
);
3667 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
3668 platform_driver_unregister(&tpacpi_pdriver
);
3671 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
3673 kfree(ibm_thinkpad_ec_found
);
3676 module_init(thinkpad_acpi_module_init
);
3677 module_exit(thinkpad_acpi_module_exit
);