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 0x000200
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");
96 * DMI matching for module autoloading
98 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
99 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
101 * Only models listed in thinkwiki will be supported, so add yours
102 * if it is not there yet.
104 #define IBM_BIOS_MODULE_ALIAS(__type) \
105 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
107 /* Non-ancient thinkpads */
108 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
109 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
111 /* Ancient thinkpad BIOSes have to be identified by
112 * BIOS type or model number, and there are far less
113 * BIOS types than model numbers... */
114 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
115 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
116 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
118 #define __unused __attribute__ ((unused))
120 /****************************************************************************
121 ****************************************************************************
123 * ACPI Helpers and device model
125 ****************************************************************************
126 ****************************************************************************/
128 /*************************************************************************
132 static acpi_handle root_handle
;
134 #define IBM_HANDLE(object, parent, paths...) \
135 static acpi_handle object##_handle; \
136 static acpi_handle *object##_parent = &parent##_handle; \
137 static char *object##_path; \
138 static char *object##_paths[] = { paths }
140 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
141 "\\_SB.PCI.ISA.EC", /* 570 */
142 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
143 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
144 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
145 "\\_SB.PCI0.ICH3.EC0", /* R31 */
146 "\\_SB.PCI0.LPC.EC", /* all others */
149 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
150 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
153 /*************************************************************************
157 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
158 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
159 "\\CMS", /* R40, R40e */
162 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
163 "^HKEY", /* R30, R31 */
164 "HKEY", /* all others */
168 /*************************************************************************
172 static int acpi_evalf(acpi_handle handle
,
173 void *res
, char *method
, char *fmt
, ...)
176 struct acpi_object_list params
;
177 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
178 struct acpi_buffer result
, *resultp
;
179 union acpi_object out_obj
;
187 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
200 params
.pointer
= &in_objs
[0];
207 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
208 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
210 /* add more types as needed */
212 printk(IBM_ERR
"acpi_evalf() called "
213 "with invalid format character '%c'\n", c
);
219 if (res_type
!= 'v') {
220 result
.length
= sizeof(out_obj
);
221 result
.pointer
= &out_obj
;
226 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
231 *(int *)res
= out_obj
.integer
.value
;
232 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
235 success
= status
== AE_OK
;
237 /* add more types as needed */
239 printk(IBM_ERR
"acpi_evalf() called "
240 "with invalid format character '%c'\n", res_type
);
244 if (!success
&& !quiet
)
245 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
246 method
, fmt0
, status
);
251 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
255 if (acpi_evalf(handle
, &i
, method
, "d"))
256 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
258 printk(IBM_ERR
"error calling %s\n", method
);
261 static int acpi_ec_read(int i
, u8
* p
)
266 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
270 if (ec_read(i
, p
) < 0)
277 static int acpi_ec_write(int i
, u8 v
)
280 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
283 if (ec_write(i
, v
) < 0)
290 static int _sta(acpi_handle handle
)
294 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
300 static int issue_thinkpad_cmos_command(int cmos_cmd
)
305 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
311 /*************************************************************************
315 static void drv_acpi_handle_init(char *name
,
316 acpi_handle
*handle
, acpi_handle parent
,
317 char **paths
, int num_paths
, char **path
)
322 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
325 for (i
= 0; i
< num_paths
; i
++) {
326 status
= acpi_get_handle(parent
, paths
[i
], handle
);
327 if (ACPI_SUCCESS(status
)) {
329 dbg_printk(TPACPI_DBG_INIT
,
330 "Found ACPI handle %s for %s\n",
336 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
341 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
343 struct ibm_struct
*ibm
= data
;
345 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
348 ibm
->acpi
->notify(ibm
, event
);
351 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
358 if (!*ibm
->acpi
->handle
)
361 vdbg_printk(TPACPI_DBG_INIT
,
362 "setting up ACPI notify for %s\n", ibm
->name
);
364 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
366 printk(IBM_ERR
"acpi_bus_get_device(%s) failed: %d\n",
371 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
372 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
373 IBM_ACPI_EVENT_PREFIX
,
376 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
377 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
378 if (ACPI_FAILURE(status
)) {
379 if (status
== AE_ALREADY_EXISTS
) {
380 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
383 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
388 ibm
->flags
.acpi_notify_installed
= 1;
392 static int __init
tpacpi_device_add(struct acpi_device
*device
)
397 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
401 dbg_printk(TPACPI_DBG_INIT
,
402 "registering %s as an ACPI driver\n", ibm
->name
);
406 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
407 if (!ibm
->acpi
->driver
) {
408 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
412 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
413 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
414 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
416 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
418 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
420 kfree(ibm
->acpi
->driver
);
421 ibm
->acpi
->driver
= NULL
;
423 ibm
->flags
.acpi_driver_registered
= 1;
429 /****************************************************************************
430 ****************************************************************************
434 ****************************************************************************
435 ****************************************************************************/
437 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
438 int count
, int *eof
, void *data
)
440 struct ibm_struct
*ibm
= data
;
443 if (!ibm
|| !ibm
->read
)
446 len
= ibm
->read(page
);
450 if (len
<= off
+ count
)
462 static int dispatch_procfs_write(struct file
*file
,
463 const char __user
* userbuf
,
464 unsigned long count
, void *data
)
466 struct ibm_struct
*ibm
= data
;
470 if (!ibm
|| !ibm
->write
)
473 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
477 if (copy_from_user(kernbuf
, userbuf
, count
)) {
483 strcat(kernbuf
, ",");
484 ret
= ibm
->write(kernbuf
);
493 static char *next_cmd(char **cmds
)
498 while ((end
= strchr(start
, ',')) && end
== start
)
510 /****************************************************************************
511 ****************************************************************************
513 * Device model: input, hwmon and platform
515 ****************************************************************************
516 ****************************************************************************/
518 static struct platform_device
*tpacpi_pdev
;
519 static struct class_device
*tpacpi_hwmon
;
520 static struct input_dev
*tpacpi_inputdev
;
522 static struct platform_driver tpacpi_pdriver
= {
524 .name
= IBM_DRVR_NAME
,
525 .owner
= THIS_MODULE
,
530 /*************************************************************************
531 * thinkpad-acpi driver attributes
534 /* interface_version --------------------------------------------------- */
535 static ssize_t
tpacpi_driver_interface_version_show(
536 struct device_driver
*drv
,
539 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
542 static DRIVER_ATTR(interface_version
, S_IRUGO
,
543 tpacpi_driver_interface_version_show
, NULL
);
545 /* debug_level --------------------------------------------------------- */
546 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
549 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
552 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
553 const char *buf
, size_t count
)
557 if (parse_strtoul(buf
, 0xffff, &t
))
565 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
566 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
568 /* version ------------------------------------------------------------- */
569 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
572 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
575 static DRIVER_ATTR(version
, S_IRUGO
,
576 tpacpi_driver_version_show
, NULL
);
578 /* --------------------------------------------------------------------- */
580 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
581 &driver_attr_debug_level
, &driver_attr_version
,
582 &driver_attr_interface_version
,
585 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
591 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
592 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
599 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
603 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
604 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
607 /*************************************************************************
608 * sysfs support helpers
611 struct attribute_set_obj
{
612 struct attribute_set s
;
614 } __attribute__((packed
));
616 static struct attribute_set
*create_attr_set(unsigned int max_members
,
619 struct attribute_set_obj
*sobj
;
621 if (max_members
== 0)
624 /* Allocates space for implicit NULL at the end too */
625 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
626 max_members
* sizeof(struct attribute
*),
630 sobj
->s
.max_members
= max_members
;
631 sobj
->s
.group
.attrs
= &sobj
->a
;
632 sobj
->s
.group
.name
= name
;
637 /* not multi-threaded safe, use it in a single thread per set */
638 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
643 if (s
->members
>= s
->max_members
)
646 s
->group
.attrs
[s
->members
] = attr
;
652 static int add_many_to_attr_set(struct attribute_set
* s
,
653 struct attribute
**attr
,
658 for (i
= 0; i
< count
; i
++) {
659 res
= add_to_attr_set(s
, attr
[i
]);
667 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
669 sysfs_remove_group(kobj
, &s
->group
);
673 static int parse_strtoul(const char *buf
,
674 unsigned long max
, unsigned long *value
)
678 *value
= simple_strtoul(buf
, &endp
, 0);
679 while (*endp
&& isspace(*endp
))
681 if (*endp
|| *value
> max
)
687 /****************************************************************************
688 ****************************************************************************
692 ****************************************************************************
693 ****************************************************************************/
695 /*************************************************************************
696 * thinkpad-acpi init subdriver
699 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
701 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
702 printk(IBM_INFO
"%s\n", IBM_URL
);
704 if (ibm_thinkpad_ec_found
)
705 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
706 ibm_thinkpad_ec_found
);
711 static int thinkpad_acpi_driver_read(char *p
)
715 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
716 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
721 static struct ibm_struct thinkpad_acpi_driver_data
= {
723 .read
= thinkpad_acpi_driver_read
,
726 /*************************************************************************
730 static int hotkey_orig_status
;
731 static u32 hotkey_orig_mask
;
732 static u32 hotkey_all_mask
;
733 static u32 hotkey_reserved_mask
= 0x00778000;
735 static struct attribute_set
*hotkey_dev_attributes
;
737 static int hotkey_get_wlsw(int *status
)
739 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
744 /* sysfs hotkey enable ------------------------------------------------- */
745 static ssize_t
hotkey_enable_show(struct device
*dev
,
746 struct device_attribute
*attr
,
752 res
= hotkey_get(&status
, &mask
);
756 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
759 static ssize_t
hotkey_enable_store(struct device
*dev
,
760 struct device_attribute
*attr
,
761 const char *buf
, size_t count
)
767 if (parse_strtoul(buf
, 1, &t
))
770 res
= hotkey_get(&status
, &mask
);
772 res
= hotkey_set(t
, mask
);
774 return (res
) ? res
: count
;
777 static struct device_attribute dev_attr_hotkey_enable
=
778 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
779 hotkey_enable_show
, hotkey_enable_store
);
781 /* sysfs hotkey mask --------------------------------------------------- */
782 static ssize_t
hotkey_mask_show(struct device
*dev
,
783 struct device_attribute
*attr
,
789 res
= hotkey_get(&status
, &mask
);
793 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
796 static ssize_t
hotkey_mask_store(struct device
*dev
,
797 struct device_attribute
*attr
,
798 const char *buf
, size_t count
)
804 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
807 res
= hotkey_get(&status
, &mask
);
809 hotkey_set(status
, t
);
811 return (res
) ? res
: count
;
814 static struct device_attribute dev_attr_hotkey_mask
=
815 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
816 hotkey_mask_show
, hotkey_mask_store
);
818 /* sysfs hotkey bios_enabled ------------------------------------------- */
819 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
820 struct device_attribute
*attr
,
823 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
826 static struct device_attribute dev_attr_hotkey_bios_enabled
=
827 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
829 /* sysfs hotkey bios_mask ---------------------------------------------- */
830 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
831 struct device_attribute
*attr
,
834 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
837 static struct device_attribute dev_attr_hotkey_bios_mask
=
838 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
840 /* sysfs hotkey all_mask ----------------------------------------------- */
841 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
842 struct device_attribute
*attr
,
845 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_all_mask
);
848 static struct device_attribute dev_attr_hotkey_all_mask
=
849 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
851 /* sysfs hotkey recommended_mask --------------------------------------- */
852 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
853 struct device_attribute
*attr
,
856 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
857 hotkey_all_mask
& ~hotkey_reserved_mask
);
860 static struct device_attribute dev_attr_hotkey_recommended_mask
=
861 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
862 hotkey_recommended_mask_show
, NULL
);
864 /* sysfs hotkey radio_sw ----------------------------------------------- */
865 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
866 struct device_attribute
*attr
,
870 res
= hotkey_get_wlsw(&s
);
874 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
877 static struct device_attribute dev_attr_hotkey_radio_sw
=
878 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
880 /* --------------------------------------------------------------------- */
882 static struct attribute
*hotkey_mask_attributes
[] = {
883 &dev_attr_hotkey_mask
.attr
,
884 &dev_attr_hotkey_bios_enabled
.attr
,
885 &dev_attr_hotkey_bios_mask
.attr
,
886 &dev_attr_hotkey_all_mask
.attr
,
887 &dev_attr_hotkey_recommended_mask
.attr
,
890 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
895 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
897 IBM_ACPIHANDLE_INIT(hkey
);
898 mutex_init(&hotkey_mutex
);
900 /* hotkey not supported on 570 */
901 tp_features
.hotkey
= hkey_handle
!= NULL
;
903 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
904 str_supported(tp_features
.hotkey
));
906 if (tp_features
.hotkey
) {
907 hotkey_dev_attributes
= create_attr_set(7, NULL
);
908 if (!hotkey_dev_attributes
)
910 res
= add_to_attr_set(hotkey_dev_attributes
,
911 &dev_attr_hotkey_enable
.attr
);
915 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
916 A30, R30, R31, T20-22, X20-21, X22-24 */
917 tp_features
.hotkey_mask
=
918 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
920 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
921 str_supported(tp_features
.hotkey_mask
));
923 if (tp_features
.hotkey_mask
) {
924 /* MHKA available in A31, R40, R40e, T4x, X31, and later */
925 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
927 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
930 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
931 if (!res
&& tp_features
.hotkey_mask
) {
932 res
= add_many_to_attr_set(hotkey_dev_attributes
,
933 hotkey_mask_attributes
,
934 ARRAY_SIZE(hotkey_mask_attributes
));
937 /* Not all thinkpads have a hardware radio switch */
938 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
939 tp_features
.hotkey_wlsw
= 1;
941 "radio switch found; radios are %s\n",
943 res
= add_to_attr_set(hotkey_dev_attributes
,
944 &dev_attr_hotkey_radio_sw
.attr
);
948 res
= register_attr_set_with_sysfs(
949 hotkey_dev_attributes
,
950 &tpacpi_pdev
->dev
.kobj
);
955 return (tp_features
.hotkey
)? 0 : 1;
958 static void hotkey_exit(void)
962 if (tp_features
.hotkey
) {
963 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
964 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
966 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
969 if (hotkey_dev_attributes
) {
970 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
971 hotkey_dev_attributes
= NULL
;
975 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
979 if (event
== 0x80 && acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
980 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
982 printk(IBM_ERR
"unknown hotkey notification event %d\n", event
);
983 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
988 * Call with hotkey_mutex held
990 static int hotkey_get(int *status
, u32
*mask
)
992 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
995 if (tp_features
.hotkey_mask
)
996 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1003 * Call with hotkey_mutex held
1005 static int hotkey_set(int status
, u32 mask
)
1009 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1012 if (tp_features
.hotkey_mask
)
1013 for (i
= 0; i
< 32; i
++) {
1014 int bit
= ((1 << i
) & mask
) != 0;
1015 if (!acpi_evalf(hkey_handle
,
1016 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1023 /* procfs -------------------------------------------------------------- */
1024 static int hotkey_read(char *p
)
1030 if (!tp_features
.hotkey
) {
1031 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1035 res
= mutex_lock_interruptible(&hotkey_mutex
);
1038 res
= hotkey_get(&status
, &mask
);
1039 mutex_unlock(&hotkey_mutex
);
1043 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1044 if (tp_features
.hotkey_mask
) {
1045 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1046 len
+= sprintf(p
+ len
,
1047 "commands:\tenable, disable, reset, <mask>\n");
1049 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1050 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1056 static int hotkey_write(char *buf
)
1063 if (!tp_features
.hotkey
)
1066 res
= mutex_lock_interruptible(&hotkey_mutex
);
1070 res
= hotkey_get(&status
, &mask
);
1075 while ((cmd
= next_cmd(&buf
))) {
1076 if (strlencmp(cmd
, "enable") == 0) {
1078 } else if (strlencmp(cmd
, "disable") == 0) {
1080 } else if (strlencmp(cmd
, "reset") == 0) {
1081 status
= hotkey_orig_status
;
1082 mask
= hotkey_orig_mask
;
1083 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1085 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1095 res
= hotkey_set(status
, mask
);
1098 mutex_unlock(&hotkey_mutex
);
1102 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1103 .hid
= IBM_HKEY_HID
,
1104 .notify
= hotkey_notify
,
1105 .handle
= &hkey_handle
,
1106 .type
= ACPI_DEVICE_NOTIFY
,
1109 static struct ibm_struct hotkey_driver_data
= {
1111 .read
= hotkey_read
,
1112 .write
= hotkey_write
,
1113 .exit
= hotkey_exit
,
1114 .acpi
= &ibm_hotkey_acpidriver
,
1117 /*************************************************************************
1118 * Bluetooth subdriver
1121 /* sysfs bluetooth enable ---------------------------------------------- */
1122 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1123 struct device_attribute
*attr
,
1128 status
= bluetooth_get_radiosw();
1132 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1135 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1136 struct device_attribute
*attr
,
1137 const char *buf
, size_t count
)
1142 if (parse_strtoul(buf
, 1, &t
))
1145 res
= bluetooth_set_radiosw(t
);
1147 return (res
) ? res
: count
;
1150 static struct device_attribute dev_attr_bluetooth_enable
=
1151 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1152 bluetooth_enable_show
, bluetooth_enable_store
);
1154 /* --------------------------------------------------------------------- */
1156 static struct attribute
*bluetooth_attributes
[] = {
1157 &dev_attr_bluetooth_enable
.attr
,
1161 static const struct attribute_group bluetooth_attr_group
= {
1162 .attrs
= bluetooth_attributes
,
1165 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1170 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1172 IBM_ACPIHANDLE_INIT(hkey
);
1174 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1175 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1176 tp_features
.bluetooth
= hkey_handle
&&
1177 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1179 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1180 str_supported(tp_features
.bluetooth
),
1183 if (tp_features
.bluetooth
) {
1184 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1185 /* no bluetooth hardware present in system */
1186 tp_features
.bluetooth
= 0;
1187 dbg_printk(TPACPI_DBG_INIT
,
1188 "bluetooth hardware not installed\n");
1190 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1191 &bluetooth_attr_group
);
1197 return (tp_features
.bluetooth
)? 0 : 1;
1200 static void bluetooth_exit(void)
1202 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1203 &bluetooth_attr_group
);
1206 static int bluetooth_get_radiosw(void)
1210 if (!tp_features
.bluetooth
)
1213 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1216 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1219 static int bluetooth_set_radiosw(int radio_on
)
1223 if (!tp_features
.bluetooth
)
1226 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1229 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1231 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1232 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1238 /* procfs -------------------------------------------------------------- */
1239 static int bluetooth_read(char *p
)
1242 int status
= bluetooth_get_radiosw();
1244 if (!tp_features
.bluetooth
)
1245 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1247 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1248 (status
)? "enabled" : "disabled");
1249 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1255 static int bluetooth_write(char *buf
)
1259 if (!tp_features
.bluetooth
)
1262 while ((cmd
= next_cmd(&buf
))) {
1263 if (strlencmp(cmd
, "enable") == 0) {
1264 bluetooth_set_radiosw(1);
1265 } else if (strlencmp(cmd
, "disable") == 0) {
1266 bluetooth_set_radiosw(0);
1274 static struct ibm_struct bluetooth_driver_data
= {
1275 .name
= "bluetooth",
1276 .read
= bluetooth_read
,
1277 .write
= bluetooth_write
,
1278 .exit
= bluetooth_exit
,
1281 /*************************************************************************
1285 /* sysfs wan enable ---------------------------------------------------- */
1286 static ssize_t
wan_enable_show(struct device
*dev
,
1287 struct device_attribute
*attr
,
1292 status
= wan_get_radiosw();
1296 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1299 static ssize_t
wan_enable_store(struct device
*dev
,
1300 struct device_attribute
*attr
,
1301 const char *buf
, size_t count
)
1306 if (parse_strtoul(buf
, 1, &t
))
1309 res
= wan_set_radiosw(t
);
1311 return (res
) ? res
: count
;
1314 static struct device_attribute dev_attr_wan_enable
=
1315 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1316 wan_enable_show
, wan_enable_store
);
1318 /* --------------------------------------------------------------------- */
1320 static struct attribute
*wan_attributes
[] = {
1321 &dev_attr_wan_enable
.attr
,
1325 static const struct attribute_group wan_attr_group
= {
1326 .attrs
= wan_attributes
,
1329 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1334 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1336 IBM_ACPIHANDLE_INIT(hkey
);
1338 tp_features
.wan
= hkey_handle
&&
1339 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1341 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1342 str_supported(tp_features
.wan
),
1345 if (tp_features
.wan
) {
1346 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1347 /* no wan hardware present in system */
1348 tp_features
.wan
= 0;
1349 dbg_printk(TPACPI_DBG_INIT
,
1350 "wan hardware not installed\n");
1352 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1359 return (tp_features
.wan
)? 0 : 1;
1362 static void wan_exit(void)
1364 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1368 static int wan_get_radiosw(void)
1372 if (!tp_features
.wan
)
1375 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1378 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1381 static int wan_set_radiosw(int radio_on
)
1385 if (!tp_features
.wan
)
1388 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1391 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1393 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1394 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1400 /* procfs -------------------------------------------------------------- */
1401 static int wan_read(char *p
)
1404 int status
= wan_get_radiosw();
1406 if (!tp_features
.wan
)
1407 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1409 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1410 (status
)? "enabled" : "disabled");
1411 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1417 static int wan_write(char *buf
)
1421 if (!tp_features
.wan
)
1424 while ((cmd
= next_cmd(&buf
))) {
1425 if (strlencmp(cmd
, "enable") == 0) {
1427 } else if (strlencmp(cmd
, "disable") == 0) {
1436 static struct ibm_struct wan_driver_data
= {
1441 .flags
.experimental
= 1,
1444 /*************************************************************************
1448 static enum video_access_mode video_supported
;
1449 static int video_orig_autosw
;
1451 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1452 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1453 "\\_SB.PCI0.VID0", /* 770e */
1454 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1455 "\\_SB.PCI0.AGP.VID", /* all others */
1458 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1460 static int __init
video_init(struct ibm_init_struct
*iibm
)
1464 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1466 IBM_ACPIHANDLE_INIT(vid
);
1467 IBM_ACPIHANDLE_INIT(vid2
);
1469 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1470 /* G41, assume IVGA doesn't change */
1471 vid_handle
= vid2_handle
;
1474 /* video switching not supported on R30, R31 */
1475 video_supported
= TPACPI_VIDEO_NONE
;
1476 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1478 video_supported
= TPACPI_VIDEO_570
;
1479 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1480 /* 600e/x, 770e, 770x */
1481 video_supported
= TPACPI_VIDEO_770
;
1484 video_supported
= TPACPI_VIDEO_NEW
;
1486 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1487 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1490 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1493 static void video_exit(void)
1495 dbg_printk(TPACPI_DBG_EXIT
,
1496 "restoring original video autoswitch mode\n");
1497 if (video_autosw_set(video_orig_autosw
))
1498 printk(IBM_ERR
"error while trying to restore original "
1499 "video autoswitch mode\n");
1502 static int video_outputsw_get(void)
1507 switch (video_supported
) {
1508 case TPACPI_VIDEO_570
:
1509 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1510 TP_ACPI_VIDEO_570_PHSCMD
))
1512 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1514 case TPACPI_VIDEO_770
:
1515 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1518 status
|= TP_ACPI_VIDEO_S_LCD
;
1519 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1522 status
|= TP_ACPI_VIDEO_S_CRT
;
1524 case TPACPI_VIDEO_NEW
:
1525 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1526 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1529 status
|= TP_ACPI_VIDEO_S_CRT
;
1531 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1532 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1535 status
|= TP_ACPI_VIDEO_S_LCD
;
1536 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1539 status
|= TP_ACPI_VIDEO_S_DVI
;
1548 static int video_outputsw_set(int status
)
1553 switch (video_supported
) {
1554 case TPACPI_VIDEO_570
:
1555 res
= acpi_evalf(NULL
, NULL
,
1556 "\\_SB.PHS2", "vdd",
1557 TP_ACPI_VIDEO_570_PHS2CMD
,
1558 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1560 case TPACPI_VIDEO_770
:
1561 autosw
= video_autosw_get();
1565 res
= video_autosw_set(1);
1568 res
= acpi_evalf(vid_handle
, NULL
,
1569 "ASWT", "vdd", status
* 0x100, 0);
1570 if (!autosw
&& video_autosw_set(autosw
)) {
1571 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1575 case TPACPI_VIDEO_NEW
:
1576 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1577 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1583 return (res
)? 0 : -EIO
;
1586 static int video_autosw_get(void)
1590 switch (video_supported
) {
1591 case TPACPI_VIDEO_570
:
1592 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1595 case TPACPI_VIDEO_770
:
1596 case TPACPI_VIDEO_NEW
:
1597 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1607 static int video_autosw_set(int enable
)
1609 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1614 static int video_outputsw_cycle(void)
1616 int autosw
= video_autosw_get();
1622 switch (video_supported
) {
1623 case TPACPI_VIDEO_570
:
1624 res
= video_autosw_set(1);
1627 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1629 case TPACPI_VIDEO_770
:
1630 case TPACPI_VIDEO_NEW
:
1631 res
= video_autosw_set(1);
1634 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1639 if (!autosw
&& video_autosw_set(autosw
)) {
1640 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1644 return (res
)? 0 : -EIO
;
1647 static int video_expand_toggle(void)
1649 switch (video_supported
) {
1650 case TPACPI_VIDEO_570
:
1651 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1653 case TPACPI_VIDEO_770
:
1654 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1656 case TPACPI_VIDEO_NEW
:
1657 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1665 static int video_read(char *p
)
1670 if (video_supported
== TPACPI_VIDEO_NONE
) {
1671 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1675 status
= video_outputsw_get();
1679 autosw
= video_autosw_get();
1683 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1684 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
1685 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
1686 if (video_supported
== TPACPI_VIDEO_NEW
)
1687 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
1688 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
1689 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
1690 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
1691 if (video_supported
== TPACPI_VIDEO_NEW
)
1692 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
1693 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
1694 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
1699 static int video_write(char *buf
)
1702 int enable
, disable
, status
;
1705 if (video_supported
== TPACPI_VIDEO_NONE
)
1711 while ((cmd
= next_cmd(&buf
))) {
1712 if (strlencmp(cmd
, "lcd_enable") == 0) {
1713 enable
|= TP_ACPI_VIDEO_S_LCD
;
1714 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1715 disable
|= TP_ACPI_VIDEO_S_LCD
;
1716 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1717 enable
|= TP_ACPI_VIDEO_S_CRT
;
1718 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1719 disable
|= TP_ACPI_VIDEO_S_CRT
;
1720 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1721 strlencmp(cmd
, "dvi_enable") == 0) {
1722 enable
|= TP_ACPI_VIDEO_S_DVI
;
1723 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1724 strlencmp(cmd
, "dvi_disable") == 0) {
1725 disable
|= TP_ACPI_VIDEO_S_DVI
;
1726 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1727 res
= video_autosw_set(1);
1730 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1731 res
= video_autosw_set(0);
1734 } else if (strlencmp(cmd
, "video_switch") == 0) {
1735 res
= video_outputsw_cycle();
1738 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1739 res
= video_expand_toggle();
1746 if (enable
|| disable
) {
1747 status
= video_outputsw_get();
1750 res
= video_outputsw_set((status
& ~disable
) | enable
);
1758 static struct ibm_struct video_driver_data
= {
1761 .write
= video_write
,
1765 /*************************************************************************
1766 * Light (thinklight) subdriver
1769 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1770 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1772 static int __init
light_init(struct ibm_init_struct
*iibm
)
1774 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
1776 IBM_ACPIHANDLE_INIT(ledb
);
1777 IBM_ACPIHANDLE_INIT(lght
);
1778 IBM_ACPIHANDLE_INIT(cmos
);
1780 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1781 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1783 if (tp_features
.light
)
1784 /* light status not supported on
1785 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1786 tp_features
.light_status
=
1787 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
1789 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
1790 str_supported(tp_features
.light
));
1792 return (tp_features
.light
)? 0 : 1;
1795 static int light_read(char *p
)
1800 if (!tp_features
.light
) {
1801 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1802 } else if (!tp_features
.light_status
) {
1803 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1804 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1806 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1808 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1809 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1815 static int light_write(char *buf
)
1817 int cmos_cmd
, lght_cmd
;
1821 if (!tp_features
.light
)
1824 while ((cmd
= next_cmd(&buf
))) {
1825 if (strlencmp(cmd
, "on") == 0) {
1828 } else if (strlencmp(cmd
, "off") == 0) {
1834 success
= cmos_handle
?
1835 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1836 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1844 static struct ibm_struct light_driver_data
= {
1847 .write
= light_write
,
1850 /*************************************************************************
1854 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1856 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
1857 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1858 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1859 "\\_SB.PCI.ISA.SLCE", /* 570 */
1860 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1862 /* don't list other alternatives as we install a notify handler on the 570 */
1863 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
1865 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
1867 .notify
= dock_notify
,
1868 .handle
= &dock_handle
,
1869 .type
= ACPI_SYSTEM_NOTIFY
,
1873 .notify
= dock_notify
,
1874 .handle
= &pci_handle
,
1875 .type
= ACPI_SYSTEM_NOTIFY
,
1879 static struct ibm_struct dock_driver_data
[2] = {
1883 .write
= dock_write
,
1884 .acpi
= &ibm_dock_acpidriver
[0],
1888 .acpi
= &ibm_dock_acpidriver
[1],
1892 #define dock_docked() (_sta(dock_handle) & 1)
1894 static int __init
dock_init(struct ibm_init_struct
*iibm
)
1896 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
1898 IBM_ACPIHANDLE_INIT(dock
);
1900 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
1901 str_supported(dock_handle
!= NULL
));
1903 return (dock_handle
)? 0 : 1;
1906 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
1910 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
1912 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
1913 dock_driver_data
[0].flags
.acpi_notify_installed
) {
1914 IBM_ACPIHANDLE_INIT(pci
);
1915 dock2_needed
= (pci_handle
!= NULL
);
1916 vdbg_printk(TPACPI_DBG_INIT
,
1917 "dock PCI handler for the TP 570 is %s\n",
1918 str_supported(dock2_needed
));
1920 vdbg_printk(TPACPI_DBG_INIT
,
1921 "dock subdriver part 2 not required\n");
1925 return (dock2_needed
)? 0 : 1;
1928 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1930 int docked
= dock_docked();
1931 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, IBM_PCI_HID
);
1933 if (event
== 1 && !pci
) /* 570 */
1934 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1935 else if (event
== 1 && pci
) /* 570 */
1936 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1937 else if (event
== 3 && docked
)
1938 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1939 else if (event
== 3 && !docked
)
1940 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
1941 else if (event
== 0 && docked
)
1942 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1944 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1945 event
, _sta(dock_handle
));
1946 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
1950 static int dock_read(char *p
)
1953 int docked
= dock_docked();
1956 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1958 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1960 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1961 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1967 static int dock_write(char *buf
)
1974 while ((cmd
= next_cmd(&buf
))) {
1975 if (strlencmp(cmd
, "undock") == 0) {
1976 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1977 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1979 } else if (strlencmp(cmd
, "dock") == 0) {
1980 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1989 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1991 /*************************************************************************
1995 #ifdef CONFIG_THINKPAD_ACPI_BAY
1996 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1997 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1998 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1999 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2000 ); /* A21e, R30, R31 */
2001 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2002 "_EJ0", /* all others */
2003 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2004 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2005 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2007 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2011 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2013 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2015 IBM_ACPIHANDLE_INIT(bay
);
2017 IBM_ACPIHANDLE_INIT(bay_ej
);
2018 IBM_ACPIHANDLE_INIT(bay2
);
2020 IBM_ACPIHANDLE_INIT(bay2_ej
);
2022 tp_features
.bay_status
= bay_handle
&&
2023 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2024 tp_features
.bay_status2
= bay2_handle
&&
2025 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2027 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2028 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2029 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2030 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2032 vdbg_printk(TPACPI_DBG_INIT
,
2033 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2034 str_supported(tp_features
.bay_status
),
2035 str_supported(tp_features
.bay_eject
),
2036 str_supported(tp_features
.bay_status2
),
2037 str_supported(tp_features
.bay_eject2
));
2039 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2040 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2043 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2045 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
2048 #define bay_occupied(b) (_sta(b##_handle) & 1)
2050 static int bay_read(char *p
)
2053 int occupied
= bay_occupied(bay
);
2054 int occupied2
= bay_occupied(bay2
);
2057 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2058 tp_features
.bay_status
?
2059 (occupied
? "occupied" : "unoccupied") :
2061 if (tp_features
.bay_status2
)
2062 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2063 "occupied" : "unoccupied");
2065 eject
= tp_features
.bay_eject
&& occupied
;
2066 eject2
= tp_features
.bay_eject2
&& occupied2
;
2068 if (eject
&& eject2
)
2069 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2071 len
+= sprintf(p
+ len
, "commands:\teject\n");
2073 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2078 static int bay_write(char *buf
)
2082 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2085 while ((cmd
= next_cmd(&buf
))) {
2086 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2087 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2089 } else if (tp_features
.bay_eject2
&&
2090 strlencmp(cmd
, "eject2") == 0) {
2091 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2100 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2101 .notify
= bay_notify
,
2102 .handle
= &bay_handle
,
2103 .type
= ACPI_SYSTEM_NOTIFY
,
2106 static struct ibm_struct bay_driver_data
= {
2110 .acpi
= &ibm_bay_acpidriver
,
2113 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2115 /*************************************************************************
2119 /* sysfs cmos_command -------------------------------------------------- */
2120 static ssize_t
cmos_command_store(struct device
*dev
,
2121 struct device_attribute
*attr
,
2122 const char *buf
, size_t count
)
2124 unsigned long cmos_cmd
;
2127 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2130 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2131 return (res
)? res
: count
;
2134 static struct device_attribute dev_attr_cmos_command
=
2135 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2137 /* --------------------------------------------------------------------- */
2139 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2143 vdbg_printk(TPACPI_DBG_INIT
,
2144 "initializing cmos commands subdriver\n");
2146 IBM_ACPIHANDLE_INIT(cmos
);
2148 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2149 str_supported(cmos_handle
!= NULL
));
2151 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2155 return (cmos_handle
)? 0 : 1;
2158 static void cmos_exit(void)
2160 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2163 static int cmos_read(char *p
)
2167 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2168 R30, R31, T20-22, X20-21 */
2170 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2172 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2173 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2179 static int cmos_write(char *buf
)
2184 while ((cmd
= next_cmd(&buf
))) {
2185 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2186 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2191 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2199 static struct ibm_struct cmos_driver_data
= {
2202 .write
= cmos_write
,
2206 /*************************************************************************
2210 static enum led_access_mode led_supported
;
2212 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2213 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2214 "LED", /* all others */
2217 static int __init
led_init(struct ibm_init_struct
*iibm
)
2219 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2221 IBM_ACPIHANDLE_INIT(led
);
2224 /* led not supported on R30, R31 */
2225 led_supported
= TPACPI_LED_NONE
;
2226 else if (strlencmp(led_path
, "SLED") == 0)
2228 led_supported
= TPACPI_LED_570
;
2229 else if (strlencmp(led_path
, "SYSL") == 0)
2230 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2231 led_supported
= TPACPI_LED_OLD
;
2234 led_supported
= TPACPI_LED_NEW
;
2236 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2237 str_supported(led_supported
), led_supported
);
2239 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2242 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2244 static int led_read(char *p
)
2248 if (!led_supported
) {
2249 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2252 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2254 if (led_supported
== TPACPI_LED_570
) {
2257 for (i
= 0; i
< 8; i
++) {
2258 if (!acpi_evalf(ec_handle
,
2259 &status
, "GLED", "dd", 1 << i
))
2261 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2262 i
, led_status(status
));
2266 len
+= sprintf(p
+ len
, "commands:\t"
2267 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2272 /* off, on, blink */
2273 static const int led_sled_arg1
[] = { 0, 1, 3 };
2274 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2275 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2276 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2278 static int led_write(char *buf
)
2286 while ((cmd
= next_cmd(&buf
))) {
2287 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2290 if (strstr(cmd
, "off")) {
2292 } else if (strstr(cmd
, "on")) {
2294 } else if (strstr(cmd
, "blink")) {
2299 if (led_supported
== TPACPI_LED_570
) {
2302 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2303 led
, led_sled_arg1
[ind
]))
2305 } else if (led_supported
== TPACPI_LED_OLD
) {
2306 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2308 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2311 ec_write(TPACPI_LED_EC_HLBL
,
2312 led
* led_exp_hlbl
[ind
]);
2315 ec_write(TPACPI_LED_EC_HLCL
,
2316 led
* led_exp_hlcl
[ind
]);
2321 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2322 led
, led_led_arg1
[ind
]))
2330 static struct ibm_struct led_driver_data
= {
2336 /*************************************************************************
2340 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2342 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2344 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2346 IBM_ACPIHANDLE_INIT(beep
);
2348 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2349 str_supported(beep_handle
!= NULL
));
2351 return (beep_handle
)? 0 : 1;
2354 static int beep_read(char *p
)
2359 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2361 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2362 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2368 static int beep_write(char *buf
)
2376 while ((cmd
= next_cmd(&buf
))) {
2377 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2378 beep_cmd
>= 0 && beep_cmd
<= 17) {
2382 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2389 static struct ibm_struct beep_driver_data
= {
2392 .write
= beep_write
,
2395 /*************************************************************************
2399 static enum thermal_access_mode thermal_read_mode
;
2401 /* sysfs temp##_input -------------------------------------------------- */
2403 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2404 struct device_attribute
*attr
,
2407 struct sensor_device_attribute
*sensor_attr
=
2408 to_sensor_dev_attr(attr
);
2409 int idx
= sensor_attr
->index
;
2413 res
= thermal_get_sensor(idx
, &value
);
2416 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2419 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2422 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2423 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2425 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2426 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2427 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2428 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2429 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2430 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2431 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2432 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2433 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2434 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2435 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2436 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2437 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2438 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2439 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2440 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2441 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2444 #define THERMAL_ATTRS(X) \
2445 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2447 static struct attribute
*thermal_temp_input_attr
[] = {
2467 static const struct attribute_group thermal_temp_input16_group
= {
2468 .attrs
= thermal_temp_input_attr
2471 static const struct attribute_group thermal_temp_input8_group
= {
2472 .attrs
= &thermal_temp_input_attr
[8]
2475 #undef THERMAL_SENSOR_ATTR_TEMP
2476 #undef THERMAL_ATTRS
2478 /* --------------------------------------------------------------------- */
2480 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2487 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2489 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2491 if (ibm_thinkpad_ec_found
&& experimental
) {
2493 * Direct EC access mode: sensors at registers
2494 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2495 * non-implemented, thermal sensors return 0x80 when
2500 for (i
= 0; i
< 8; i
++) {
2501 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2507 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2515 /* This is sheer paranoia, but we handle it anyway */
2518 "ThinkPad ACPI EC access misbehaving, "
2519 "falling back to ACPI TMPx access mode\n");
2520 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2523 "ThinkPad ACPI EC access misbehaving, "
2524 "disabling thermal sensors access\n");
2525 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2530 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2532 } else if (acpi_tmp7
) {
2533 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2534 /* 600e/x, 770e, 770x */
2535 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2537 /* Standard ACPI TMPx access, max 8 sensors */
2538 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2541 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2542 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2545 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2546 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2549 switch(thermal_read_mode
) {
2550 case TPACPI_THERMAL_TPEC_16
:
2551 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2552 &thermal_temp_input16_group
);
2556 case TPACPI_THERMAL_TPEC_8
:
2557 case TPACPI_THERMAL_ACPI_TMP07
:
2558 case TPACPI_THERMAL_ACPI_UPDT
:
2559 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2560 &thermal_temp_input8_group
);
2564 case TPACPI_THERMAL_NONE
:
2572 static void thermal_exit(void)
2574 switch(thermal_read_mode
) {
2575 case TPACPI_THERMAL_TPEC_16
:
2576 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2577 &thermal_temp_input16_group
);
2579 case TPACPI_THERMAL_TPEC_8
:
2580 case TPACPI_THERMAL_ACPI_TMP07
:
2581 case TPACPI_THERMAL_ACPI_UPDT
:
2582 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2583 &thermal_temp_input16_group
);
2585 case TPACPI_THERMAL_NONE
:
2591 /* idx is zero-based */
2592 static int thermal_get_sensor(int idx
, s32
*value
)
2598 t
= TP_EC_THERMAL_TMP0
;
2600 switch (thermal_read_mode
) {
2601 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2602 case TPACPI_THERMAL_TPEC_16
:
2603 if (idx
>= 8 && idx
<= 15) {
2604 t
= TP_EC_THERMAL_TMP8
;
2609 case TPACPI_THERMAL_TPEC_8
:
2611 if (!acpi_ec_read(t
+ idx
, &tmp
))
2613 *value
= tmp
* 1000;
2618 case TPACPI_THERMAL_ACPI_UPDT
:
2620 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2621 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2623 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2625 *value
= (t
- 2732) * 100;
2630 case TPACPI_THERMAL_ACPI_TMP07
:
2632 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2633 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2640 case TPACPI_THERMAL_NONE
:
2648 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2659 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2662 for(i
= 0 ; i
< n
; i
++) {
2663 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
2671 static int thermal_read(char *p
)
2675 struct ibm_thermal_sensors_struct t
;
2677 n
= thermal_get_sensors(&t
);
2678 if (unlikely(n
< 0))
2681 len
+= sprintf(p
+ len
, "temperatures:\t");
2684 for (i
= 0; i
< (n
- 1); i
++)
2685 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
2686 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
2688 len
+= sprintf(p
+ len
, "not supported\n");
2693 static struct ibm_struct thermal_driver_data
= {
2695 .read
= thermal_read
,
2696 .exit
= thermal_exit
,
2699 /*************************************************************************
2703 static u8 ecdump_regs
[256];
2705 static int ecdump_read(char *p
)
2711 len
+= sprintf(p
+ len
, "EC "
2712 " +00 +01 +02 +03 +04 +05 +06 +07"
2713 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2714 for (i
= 0; i
< 256; i
+= 16) {
2715 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
2716 for (j
= 0; j
< 16; j
++) {
2717 if (!acpi_ec_read(i
+ j
, &v
))
2719 if (v
!= ecdump_regs
[i
+ j
])
2720 len
+= sprintf(p
+ len
, " *%02x", v
);
2722 len
+= sprintf(p
+ len
, " %02x", v
);
2723 ecdump_regs
[i
+ j
] = v
;
2725 len
+= sprintf(p
+ len
, "\n");
2730 /* These are way too dangerous to advertise openly... */
2732 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
2733 " (<offset> is 00-ff, <value> is 00-ff)\n");
2734 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
2735 " (<offset> is 00-ff, <value> is 0-255)\n");
2740 static int ecdump_write(char *buf
)
2745 while ((cmd
= next_cmd(&buf
))) {
2746 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
2748 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
2752 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
2753 if (!acpi_ec_write(i
, v
))
2762 static struct ibm_struct ecdump_driver_data
= {
2764 .read
= ecdump_read
,
2765 .write
= ecdump_write
,
2766 .flags
.experimental
= 1,
2769 /*************************************************************************
2770 * Backlight/brightness subdriver
2773 static struct backlight_device
*ibm_backlight_device
;
2775 static struct backlight_properties ibm_backlight_data
= {
2776 .owner
= THIS_MODULE
,
2777 .get_brightness
= brightness_get
,
2778 .update_status
= brightness_update_status
,
2779 .max_brightness
= 7,
2782 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
2786 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
2788 b
= brightness_get(NULL
);
2792 ibm_backlight_device
= backlight_device_register(
2793 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
2794 &ibm_backlight_data
);
2795 if (IS_ERR(ibm_backlight_device
)) {
2796 printk(IBM_ERR
"Could not register backlight device\n");
2797 return PTR_ERR(ibm_backlight_device
);
2799 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
2801 ibm_backlight_device
->props
->brightness
= b
;
2802 brightness_update_status(ibm_backlight_device
);
2807 static void brightness_exit(void)
2809 if (ibm_backlight_device
) {
2810 vdbg_printk(TPACPI_DBG_EXIT
,
2811 "calling backlight_device_unregister()\n");
2812 backlight_device_unregister(ibm_backlight_device
);
2813 ibm_backlight_device
= NULL
;
2817 static int brightness_update_status(struct backlight_device
*bd
)
2819 return brightness_set(
2820 (bd
->props
->fb_blank
== FB_BLANK_UNBLANK
&&
2821 bd
->props
->power
== FB_BLANK_UNBLANK
) ?
2822 bd
->props
->brightness
: 0);
2825 static int brightness_get(struct backlight_device
*bd
)
2828 if (!acpi_ec_read(brightness_offset
, &level
))
2836 static int brightness_set(int value
)
2838 int cmos_cmd
, inc
, i
;
2839 int current_value
= brightness_get(NULL
);
2843 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
2844 inc
= value
> current_value
? 1 : -1;
2845 for (i
= current_value
; i
!= value
; i
+= inc
) {
2846 if (issue_thinkpad_cmos_command(cmos_cmd
))
2848 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
2855 static int brightness_read(char *p
)
2860 if ((level
= brightness_get(NULL
)) < 0) {
2861 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2863 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
2864 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
2865 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2866 " (<level> is 0-7)\n");
2872 static int brightness_write(char *buf
)
2878 while ((cmd
= next_cmd(&buf
))) {
2879 if ((level
= brightness_get(NULL
)) < 0)
2883 if (strlencmp(cmd
, "up") == 0) {
2884 new_level
= level
== 7 ? 7 : level
+ 1;
2885 } else if (strlencmp(cmd
, "down") == 0) {
2886 new_level
= level
== 0 ? 0 : level
- 1;
2887 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2888 new_level
>= 0 && new_level
<= 7) {
2893 brightness_set(new_level
);
2899 static struct ibm_struct brightness_driver_data
= {
2900 .name
= "brightness",
2901 .read
= brightness_read
,
2902 .write
= brightness_write
,
2903 .exit
= brightness_exit
,
2906 /*************************************************************************
2910 static int volume_read(char *p
)
2915 if (!acpi_ec_read(volume_offset
, &level
)) {
2916 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2918 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
2919 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
2920 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
2921 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2922 " (<level> is 0-15)\n");
2928 static int volume_write(char *buf
)
2930 int cmos_cmd
, inc
, i
;
2932 int new_level
, new_mute
;
2935 while ((cmd
= next_cmd(&buf
))) {
2936 if (!acpi_ec_read(volume_offset
, &level
))
2938 new_mute
= mute
= level
& 0x40;
2939 new_level
= level
= level
& 0xf;
2941 if (strlencmp(cmd
, "up") == 0) {
2945 new_level
= level
== 15 ? 15 : level
+ 1;
2946 } else if (strlencmp(cmd
, "down") == 0) {
2950 new_level
= level
== 0 ? 0 : level
- 1;
2951 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2952 new_level
>= 0 && new_level
<= 15) {
2954 } else if (strlencmp(cmd
, "mute") == 0) {
2959 if (new_level
!= level
) { /* mute doesn't change */
2960 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
2961 inc
= new_level
> level
? 1 : -1;
2963 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
2964 !acpi_ec_write(volume_offset
, level
)))
2967 for (i
= level
; i
!= new_level
; i
+= inc
)
2968 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2969 !acpi_ec_write(volume_offset
, i
+ inc
))
2972 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
2973 !acpi_ec_write(volume_offset
,
2978 if (new_mute
!= mute
) { /* level doesn't change */
2979 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
2981 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2982 !acpi_ec_write(volume_offset
, level
+ new_mute
))
2990 static struct ibm_struct volume_driver_data
= {
2992 .read
= volume_read
,
2993 .write
= volume_write
,
2996 /*************************************************************************
3003 * TPACPI_FAN_RD_ACPI_GFAN:
3004 * ACPI GFAN method: returns fan level
3006 * see TPACPI_FAN_WR_ACPI_SFAN
3007 * EC 0x2f (HFSP) not available if GFAN exists
3009 * TPACPI_FAN_WR_ACPI_SFAN:
3010 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3012 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3015 * TPACPI_FAN_WR_TPEC:
3016 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3017 * Supported on almost all ThinkPads
3019 * Fan speed changes of any sort (including those caused by the
3020 * disengaged mode) are usually done slowly by the firmware as the
3021 * maximum ammount of fan duty cycle change per second seems to be
3024 * Reading is not available if GFAN exists.
3025 * Writing is not available if SFAN exists.
3028 * 7 automatic mode engaged;
3029 * (default operation mode of the ThinkPad)
3030 * fan level is ignored in this mode.
3031 * 6 full speed mode (takes precedence over bit 7);
3032 * not available on all thinkpads. May disable
3033 * the tachometer while the fan controller ramps up
3034 * the speed (which can take up to a few *minutes*).
3035 * Speeds up fan to 100% duty-cycle, which is far above
3036 * the standard RPM levels. It is not impossible that
3037 * it could cause hardware damage.
3038 * 5-3 unused in some models. Extra bits for fan level
3039 * in others, but still useless as all values above
3040 * 7 map to the same speed as level 7 in these models.
3041 * 2-0 fan level (0..7 usually)
3043 * 0x07 = max (set when temperatures critical)
3044 * Some ThinkPads may have other levels, see
3045 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3047 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3048 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3049 * does so, its initial value is meaningless (0x07).
3051 * For firmware bugs, refer to:
3052 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3056 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3057 * Main fan tachometer reading (in RPM)
3059 * This register is present on all ThinkPads with a new-style EC, and
3060 * it is known not to be present on the A21m/e, and T22, as there is
3061 * something else in offset 0x84 according to the ACPI DSDT. Other
3062 * ThinkPads from this same time period (and earlier) probably lack the
3063 * tachometer as well.
3065 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3066 * was never fixed by IBM to report the EC firmware version string
3067 * probably support the tachometer (like the early X models), so
3068 * detecting it is quite hard. We need more data to know for sure.
3070 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3073 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3076 * For firmware bugs, refer to:
3077 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3079 * TPACPI_FAN_WR_ACPI_FANS:
3080 * ThinkPad X31, X40, X41. Not available in the X60.
3082 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3083 * high speed. ACPI DSDT seems to map these three speeds to levels
3084 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3085 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3087 * The speeds are stored on handles
3088 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3090 * There are three default speed sets, acessible as handles:
3091 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3093 * ACPI DSDT switches which set is in use depending on various
3096 * TPACPI_FAN_WR_TPEC is also available and should be used to
3097 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3098 * but the ACPI tables just mention level 7.
3101 static enum fan_status_access_mode fan_status_access_mode
;
3102 static enum fan_control_access_mode fan_control_access_mode
;
3103 static enum fan_control_commands fan_control_commands
;
3105 static u8 fan_control_initial_status
;
3106 static u8 fan_control_desired_level
;
3108 static void fan_watchdog_fire(struct work_struct
*ignored
);
3109 static int fan_watchdog_maxinterval
;
3110 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3112 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3113 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3114 "\\FSPD", /* 600e/x, 770e, 770x */
3116 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3117 "JFNS", /* 770x-JL */
3121 * SYSFS fan layout: hwmon compatible (device)
3124 * 0: "disengaged" mode
3126 * 2: native EC "auto" mode (recommended, hardware default)
3128 * pwm*: set speed in manual mode, ignored otherwise.
3129 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3132 * fan*_input: tachometer reading, RPM
3135 * SYSFS fan layout: extensions
3137 * fan_watchdog (driver):
3138 * fan watchdog interval in seconds, 0 disables (default), max 120
3141 /* sysfs fan pwm1_enable ----------------------------------------------- */
3142 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3143 struct device_attribute
*attr
,
3149 res
= fan_get_status_safe(&status
);
3153 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3154 if (status
!= fan_control_initial_status
) {
3155 tp_features
.fan_ctrl_status_undef
= 0;
3157 /* Return most likely status. In fact, it
3158 * might be the only possible status */
3159 status
= TP_EC_FAN_AUTO
;
3163 if (status
& TP_EC_FAN_FULLSPEED
) {
3165 } else if (status
& TP_EC_FAN_AUTO
) {
3170 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3173 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3174 struct device_attribute
*attr
,
3175 const char *buf
, size_t count
)
3180 if (parse_strtoul(buf
, 2, &t
))
3185 level
= TP_EC_FAN_FULLSPEED
;
3188 level
= TPACPI_FAN_LAST_LEVEL
;
3191 level
= TP_EC_FAN_AUTO
;
3194 /* reserved for software-controlled auto mode */
3200 res
= fan_set_level_safe(level
);
3206 fan_watchdog_reset();
3211 static struct device_attribute dev_attr_fan_pwm1_enable
=
3212 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3213 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3215 /* sysfs fan pwm1 ------------------------------------------------------ */
3216 static ssize_t
fan_pwm1_show(struct device
*dev
,
3217 struct device_attribute
*attr
,
3223 res
= fan_get_status_safe(&status
);
3227 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3228 if (status
!= fan_control_initial_status
) {
3229 tp_features
.fan_ctrl_status_undef
= 0;
3231 status
= TP_EC_FAN_AUTO
;
3236 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3237 status
= fan_control_desired_level
;
3242 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3245 static ssize_t
fan_pwm1_store(struct device
*dev
,
3246 struct device_attribute
*attr
,
3247 const char *buf
, size_t count
)
3251 u8 status
, newlevel
;
3253 if (parse_strtoul(buf
, 255, &s
))
3256 /* scale down from 0-255 to 0-7 */
3257 newlevel
= (s
>> 5) & 0x07;
3259 rc
= mutex_lock_interruptible(&fan_mutex
);
3263 rc
= fan_get_status(&status
);
3264 if (!rc
&& (status
&
3265 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3266 rc
= fan_set_level(newlevel
);
3270 fan_update_desired_level(newlevel
);
3271 fan_watchdog_reset();
3275 mutex_unlock(&fan_mutex
);
3276 return (rc
)? rc
: count
;
3279 static struct device_attribute dev_attr_fan_pwm1
=
3280 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3281 fan_pwm1_show
, fan_pwm1_store
);
3283 /* sysfs fan fan1_input ------------------------------------------------ */
3284 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3285 struct device_attribute
*attr
,
3291 res
= fan_get_speed(&speed
);
3295 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3298 static struct device_attribute dev_attr_fan_fan1_input
=
3299 __ATTR(fan1_input
, S_IRUGO
,
3300 fan_fan1_input_show
, NULL
);
3302 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
3303 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3306 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3309 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3310 const char *buf
, size_t count
)
3314 if (parse_strtoul(buf
, 120, &t
))
3317 if (!fan_control_allowed
)
3320 fan_watchdog_maxinterval
= t
;
3321 fan_watchdog_reset();
3326 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3327 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3329 /* --------------------------------------------------------------------- */
3330 static struct attribute
*fan_attributes
[] = {
3331 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3332 &dev_attr_fan_fan1_input
.attr
,
3336 static const struct attribute_group fan_attr_group
= {
3337 .attrs
= fan_attributes
,
3340 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3344 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3346 mutex_init(&fan_mutex
);
3347 fan_status_access_mode
= TPACPI_FAN_NONE
;
3348 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3349 fan_control_commands
= 0;
3350 fan_watchdog_maxinterval
= 0;
3351 tp_features
.fan_ctrl_status_undef
= 0;
3352 fan_control_desired_level
= 7;
3354 IBM_ACPIHANDLE_INIT(fans
);
3355 IBM_ACPIHANDLE_INIT(gfan
);
3356 IBM_ACPIHANDLE_INIT(sfan
);
3359 /* 570, 600e/x, 770e, 770x */
3360 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3362 /* all other ThinkPads: note that even old-style
3363 * ThinkPad ECs supports the fan control register */
3364 if (likely(acpi_ec_read(fan_status_offset
,
3365 &fan_control_initial_status
))) {
3366 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3368 /* In some ThinkPads, neither the EC nor the ACPI
3369 * DSDT initialize the fan status, and it ends up
3370 * being set to 0x07 when it *could* be either
3373 * Enable for TP-1Y (T43), TP-78 (R51e),
3374 * TP-76 (R52), TP-70 (T43, R52), which are known
3376 if (fan_control_initial_status
== 0x07 &&
3377 ibm_thinkpad_ec_found
&&
3378 ((ibm_thinkpad_ec_found
[0] == '1' &&
3379 ibm_thinkpad_ec_found
[1] == 'Y') ||
3380 (ibm_thinkpad_ec_found
[0] == '7' &&
3381 (ibm_thinkpad_ec_found
[1] == '6' ||
3382 ibm_thinkpad_ec_found
[1] == '8' ||
3383 ibm_thinkpad_ec_found
[1] == '0'))
3386 "fan_init: initial fan status is "
3387 "unknown, assuming it is in auto "
3389 tp_features
.fan_ctrl_status_undef
= 1;
3393 "ThinkPad ACPI EC access misbehaving, "
3394 "fan status and control unavailable\n");
3401 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3402 fan_control_commands
|=
3403 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3406 /* gfan without sfan means no fan control */
3407 /* all other models implement TP EC 0x2f control */
3411 fan_control_access_mode
=
3412 TPACPI_FAN_WR_ACPI_FANS
;
3413 fan_control_commands
|=
3414 TPACPI_FAN_CMD_SPEED
|
3415 TPACPI_FAN_CMD_LEVEL
|
3416 TPACPI_FAN_CMD_ENABLE
;
3418 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3419 fan_control_commands
|=
3420 TPACPI_FAN_CMD_LEVEL
|
3421 TPACPI_FAN_CMD_ENABLE
;
3426 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3427 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3428 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3429 fan_status_access_mode
, fan_control_access_mode
);
3431 /* fan control master switch */
3432 if (!fan_control_allowed
) {
3433 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3434 fan_control_commands
= 0;
3435 dbg_printk(TPACPI_DBG_INIT
,
3436 "fan control features disabled by parameter\n");
3439 /* update fan_control_desired_level */
3440 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3441 fan_get_status_safe(NULL
);
3443 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3444 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3445 rc
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3448 rc
= driver_create_file(&tpacpi_pdriver
.driver
,
3449 &driver_attr_fan_watchdog
);
3458 * Call with fan_mutex held
3460 static void fan_update_desired_level(u8 status
)
3463 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3465 fan_control_desired_level
= 7;
3467 fan_control_desired_level
= status
;
3471 static int fan_get_status(u8
*status
)
3476 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3478 switch (fan_status_access_mode
) {
3479 case TPACPI_FAN_RD_ACPI_GFAN
:
3480 /* 570, 600e/x, 770e, 770x */
3482 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
3490 case TPACPI_FAN_RD_TPEC
:
3491 /* all except 570, 600e/x, 770e, 770x */
3492 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
3507 static int fan_get_status_safe(u8
*status
)
3512 rc
= mutex_lock_interruptible(&fan_mutex
);
3515 rc
= fan_get_status(&s
);
3517 fan_update_desired_level(s
);
3518 mutex_unlock(&fan_mutex
);
3526 static void fan_exit(void)
3528 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
3530 /* FIXME: can we really do this unconditionally? */
3531 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
, &fan_attr_group
);
3532 driver_remove_file(&tpacpi_pdriver
.driver
, &driver_attr_fan_watchdog
);
3534 cancel_delayed_work(&fan_watchdog_task
);
3535 flush_scheduled_work();
3538 static int fan_get_speed(unsigned int *speed
)
3542 switch (fan_status_access_mode
) {
3543 case TPACPI_FAN_RD_TPEC
:
3544 /* all except 570, 600e/x, 770e, 770x */
3545 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
3546 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
3550 *speed
= (hi
<< 8) | lo
;
3561 static void fan_watchdog_fire(struct work_struct
*ignored
)
3565 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
3566 rc
= fan_set_enable();
3568 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
3569 "will try again later...\n", -rc
);
3570 /* reschedule for later */
3571 fan_watchdog_reset();
3575 static void fan_watchdog_reset(void)
3577 static int fan_watchdog_active
;
3579 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
3582 if (fan_watchdog_active
)
3583 cancel_delayed_work(&fan_watchdog_task
);
3585 if (fan_watchdog_maxinterval
> 0) {
3586 fan_watchdog_active
= 1;
3587 if (!schedule_delayed_work(&fan_watchdog_task
,
3588 msecs_to_jiffies(fan_watchdog_maxinterval
3590 printk(IBM_ERR
"failed to schedule the fan watchdog, "
3591 "watchdog will not trigger\n");
3594 fan_watchdog_active
= 0;
3597 static int fan_set_level(int level
)
3599 if (!fan_control_allowed
)
3602 switch (fan_control_access_mode
) {
3603 case TPACPI_FAN_WR_ACPI_SFAN
:
3604 if (level
>= 0 && level
<= 7) {
3605 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
3611 case TPACPI_FAN_WR_ACPI_FANS
:
3612 case TPACPI_FAN_WR_TPEC
:
3613 if ((level
!= TP_EC_FAN_AUTO
) &&
3614 (level
!= TP_EC_FAN_FULLSPEED
) &&
3615 ((level
< 0) || (level
> 7)))
3618 /* safety net should the EC not support AUTO
3619 * or FULLSPEED mode bits and just ignore them */
3620 if (level
& TP_EC_FAN_FULLSPEED
)
3621 level
|= 7; /* safety min speed 7 */
3622 else if (level
& TP_EC_FAN_FULLSPEED
)
3623 level
|= 4; /* safety min speed 4 */
3625 if (!acpi_ec_write(fan_status_offset
, level
))
3628 tp_features
.fan_ctrl_status_undef
= 0;
3637 static int fan_set_level_safe(int level
)
3641 if (!fan_control_allowed
)
3644 rc
= mutex_lock_interruptible(&fan_mutex
);
3648 if (level
== TPACPI_FAN_LAST_LEVEL
)
3649 level
= fan_control_desired_level
;
3651 rc
= fan_set_level(level
);
3653 fan_update_desired_level(level
);
3655 mutex_unlock(&fan_mutex
);
3659 static int fan_set_enable(void)
3664 if (!fan_control_allowed
)
3667 rc
= mutex_lock_interruptible(&fan_mutex
);
3671 switch (fan_control_access_mode
) {
3672 case TPACPI_FAN_WR_ACPI_FANS
:
3673 case TPACPI_FAN_WR_TPEC
:
3674 rc
= fan_get_status(&s
);
3678 /* Don't go out of emergency fan mode */
3681 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
3684 if (!acpi_ec_write(fan_status_offset
, s
))
3687 tp_features
.fan_ctrl_status_undef
= 0;
3692 case TPACPI_FAN_WR_ACPI_SFAN
:
3693 rc
= fan_get_status(&s
);
3699 /* Set fan to at least level 4 */
3702 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
3712 mutex_unlock(&fan_mutex
);
3716 static int fan_set_disable(void)
3720 if (!fan_control_allowed
)
3723 rc
= mutex_lock_interruptible(&fan_mutex
);
3728 switch (fan_control_access_mode
) {
3729 case TPACPI_FAN_WR_ACPI_FANS
:
3730 case TPACPI_FAN_WR_TPEC
:
3731 if (!acpi_ec_write(fan_status_offset
, 0x00))
3734 fan_control_desired_level
= 0;
3735 tp_features
.fan_ctrl_status_undef
= 0;
3739 case TPACPI_FAN_WR_ACPI_SFAN
:
3740 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
3743 fan_control_desired_level
= 0;
3751 mutex_unlock(&fan_mutex
);
3755 static int fan_set_speed(int speed
)
3759 if (!fan_control_allowed
)
3762 rc
= mutex_lock_interruptible(&fan_mutex
);
3767 switch (fan_control_access_mode
) {
3768 case TPACPI_FAN_WR_ACPI_FANS
:
3769 if (speed
>= 0 && speed
<= 65535) {
3770 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
3771 speed
, speed
, speed
))
3781 mutex_unlock(&fan_mutex
);
3785 static int fan_read(char *p
)
3790 unsigned int speed
= 0;
3792 switch (fan_status_access_mode
) {
3793 case TPACPI_FAN_RD_ACPI_GFAN
:
3794 /* 570, 600e/x, 770e, 770x */
3795 if ((rc
= fan_get_status_safe(&status
)) < 0)
3798 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
3800 (status
!= 0) ? "enabled" : "disabled", status
);
3803 case TPACPI_FAN_RD_TPEC
:
3804 /* all except 570, 600e/x, 770e, 770x */
3805 if ((rc
= fan_get_status_safe(&status
)) < 0)
3808 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3809 if (status
!= fan_control_initial_status
)
3810 tp_features
.fan_ctrl_status_undef
= 0;
3812 /* Return most likely status. In fact, it
3813 * might be the only possible status */
3814 status
= TP_EC_FAN_AUTO
;
3817 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3818 (status
!= 0) ? "enabled" : "disabled");
3820 if ((rc
= fan_get_speed(&speed
)) < 0)
3823 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
3825 if (status
& TP_EC_FAN_FULLSPEED
)
3826 /* Disengaged mode takes precedence */
3827 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
3828 else if (status
& TP_EC_FAN_AUTO
)
3829 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
3831 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
3834 case TPACPI_FAN_NONE
:
3836 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3839 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
3840 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
3842 switch (fan_control_access_mode
) {
3843 case TPACPI_FAN_WR_ACPI_SFAN
:
3844 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
3848 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
3849 "auto, disengaged, full-speed)\n");
3854 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
3855 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
3856 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
3857 "1-120 (seconds))\n");
3859 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
3860 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
3861 " (<speed> is 0-65535)\n");
3866 static int fan_write_cmd_level(const char *cmd
, int *rc
)
3870 if (strlencmp(cmd
, "level auto") == 0)
3871 level
= TP_EC_FAN_AUTO
;
3872 else if ((strlencmp(cmd
, "level disengaged") == 0) |
3873 (strlencmp(cmd
, "level full-speed") == 0))
3874 level
= TP_EC_FAN_FULLSPEED
;
3875 else if (sscanf(cmd
, "level %d", &level
) != 1)
3878 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
3879 printk(IBM_ERR
"level command accepted for unsupported "
3880 "access mode %d", fan_control_access_mode
);
3885 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
3887 if (strlencmp(cmd
, "enable") != 0)
3890 if ((*rc
= fan_set_enable()) == -ENXIO
)
3891 printk(IBM_ERR
"enable command accepted for unsupported "
3892 "access mode %d", fan_control_access_mode
);
3897 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
3899 if (strlencmp(cmd
, "disable") != 0)
3902 if ((*rc
= fan_set_disable()) == -ENXIO
)
3903 printk(IBM_ERR
"disable command accepted for unsupported "
3904 "access mode %d", fan_control_access_mode
);
3909 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
3914 * Support speed <low> <medium> <high> ? */
3916 if (sscanf(cmd
, "speed %d", &speed
) != 1)
3919 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
3920 printk(IBM_ERR
"speed command accepted for unsupported "
3921 "access mode %d", fan_control_access_mode
);
3926 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
3930 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
3933 if (interval
< 0 || interval
> 120)
3936 fan_watchdog_maxinterval
= interval
;
3941 static int fan_write(char *buf
)
3946 while (!rc
&& (cmd
= next_cmd(&buf
))) {
3947 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
3948 fan_write_cmd_level(cmd
, &rc
)) &&
3949 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
3950 (fan_write_cmd_enable(cmd
, &rc
) ||
3951 fan_write_cmd_disable(cmd
, &rc
) ||
3952 fan_write_cmd_watchdog(cmd
, &rc
))) &&
3953 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
3954 fan_write_cmd_speed(cmd
, &rc
))
3958 fan_watchdog_reset();
3964 static struct ibm_struct fan_driver_data
= {
3971 /****************************************************************************
3972 ****************************************************************************
3976 ****************************************************************************
3977 ****************************************************************************/
3980 static struct proc_dir_entry
*proc_dir
;
3982 /* Subdriver registry */
3983 static LIST_HEAD(tpacpi_all_drivers
);
3987 * Module and infrastructure proble, init and exit handling
3990 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
3991 static const char * __init
str_supported(int is_supported
)
3993 static char text_unsupported
[] __initdata
= "not supported";
3995 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
3997 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
3999 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4002 struct ibm_struct
*ibm
= iibm
->data
;
4003 struct proc_dir_entry
*entry
;
4005 BUG_ON(ibm
== NULL
);
4007 INIT_LIST_HEAD(&ibm
->all_drivers
);
4009 if (ibm
->flags
.experimental
&& !experimental
)
4012 dbg_printk(TPACPI_DBG_INIT
,
4013 "probing for %s\n", ibm
->name
);
4016 ret
= iibm
->init(iibm
);
4018 return 0; /* probe failed */
4022 ibm
->flags
.init_called
= 1;
4026 if (ibm
->acpi
->hid
) {
4027 ret
= register_tpacpi_subdriver(ibm
);
4032 if (ibm
->acpi
->notify
) {
4033 ret
= setup_acpi_notify(ibm
);
4034 if (ret
== -ENODEV
) {
4035 printk(IBM_NOTICE
"disabling subdriver %s\n",
4045 dbg_printk(TPACPI_DBG_INIT
,
4046 "%s installed\n", ibm
->name
);
4049 entry
= create_proc_entry(ibm
->name
,
4050 S_IFREG
| S_IRUGO
| S_IWUSR
,
4053 printk(IBM_ERR
"unable to create proc entry %s\n",
4058 entry
->owner
= THIS_MODULE
;
4060 entry
->read_proc
= &dispatch_procfs_read
;
4062 entry
->write_proc
= &dispatch_procfs_write
;
4063 ibm
->flags
.proc_created
= 1;
4066 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4071 dbg_printk(TPACPI_DBG_INIT
,
4072 "%s: at error exit path with result %d\n",
4076 return (ret
< 0)? ret
: 0;
4079 static void ibm_exit(struct ibm_struct
*ibm
)
4081 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4083 list_del_init(&ibm
->all_drivers
);
4085 if (ibm
->flags
.acpi_notify_installed
) {
4086 dbg_printk(TPACPI_DBG_EXIT
,
4087 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4089 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4091 dispatch_acpi_notify
);
4092 ibm
->flags
.acpi_notify_installed
= 0;
4093 ibm
->flags
.acpi_notify_installed
= 0;
4096 if (ibm
->flags
.proc_created
) {
4097 dbg_printk(TPACPI_DBG_EXIT
,
4098 "%s: remove_proc_entry\n", ibm
->name
);
4099 remove_proc_entry(ibm
->name
, proc_dir
);
4100 ibm
->flags
.proc_created
= 0;
4103 if (ibm
->flags
.acpi_driver_registered
) {
4104 dbg_printk(TPACPI_DBG_EXIT
,
4105 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4107 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4108 kfree(ibm
->acpi
->driver
);
4109 ibm
->acpi
->driver
= NULL
;
4110 ibm
->flags
.acpi_driver_registered
= 0;
4113 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4115 ibm
->flags
.init_called
= 0;
4118 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4123 static char *ibm_thinkpad_ec_found
;
4125 static char* __init
check_dmi_for_ec(void)
4127 struct dmi_device
*dev
= NULL
;
4128 char ec_fw_string
[18];
4131 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4132 * X32 or newer, all Z series; Some models must have an
4133 * up-to-date BIOS or they will not be detected.
4135 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4137 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4138 if (sscanf(dev
->name
,
4139 "IBM ThinkPad Embedded Controller -[%17c",
4140 ec_fw_string
) == 1) {
4141 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4142 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4143 return kstrdup(ec_fw_string
, GFP_KERNEL
);
4149 static int __init
probe_for_thinkpad(void)
4157 * Non-ancient models have better DMI tagging, but very old models
4160 is_thinkpad
= dmi_name_in_vendors("ThinkPad");
4162 /* ec is required because many other handles are relative to it */
4163 IBM_ACPIHANDLE_INIT(ec
);
4167 "Not yet supported ThinkPad detected!\n");
4172 * Risks a regression on very old machines, but reduces potential
4173 * false positives a damn great deal
4176 is_thinkpad
= dmi_name_in_vendors("IBM");
4178 if (!is_thinkpad
&& !force_load
)
4185 /* Module init, exit, parameters */
4187 static struct ibm_init_struct ibms_init
[] __initdata
= {
4189 .init
= thinkpad_acpi_driver_init
,
4190 .data
= &thinkpad_acpi_driver_data
,
4193 .init
= hotkey_init
,
4194 .data
= &hotkey_driver_data
,
4197 .init
= bluetooth_init
,
4198 .data
= &bluetooth_driver_data
,
4202 .data
= &wan_driver_data
,
4206 .data
= &video_driver_data
,
4210 .data
= &light_driver_data
,
4212 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4215 .data
= &dock_driver_data
[0],
4219 .data
= &dock_driver_data
[1],
4222 #ifdef CONFIG_THINKPAD_ACPI_BAY
4225 .data
= &bay_driver_data
,
4230 .data
= &cmos_driver_data
,
4234 .data
= &led_driver_data
,
4238 .data
= &beep_driver_data
,
4241 .init
= thermal_init
,
4242 .data
= &thermal_driver_data
,
4245 .data
= &ecdump_driver_data
,
4248 .init
= brightness_init
,
4249 .data
= &brightness_driver_data
,
4252 .data
= &volume_driver_data
,
4256 .data
= &fan_driver_data
,
4260 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4263 struct ibm_struct
*ibm
;
4265 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4266 ibm
= ibms_init
[i
].data
;
4267 BUG_ON(ibm
== NULL
);
4269 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4270 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4272 strcpy(ibms_init
[i
].param
, val
);
4273 strcat(ibms_init
[i
].param
, ",");
4281 static int experimental
;
4282 module_param(experimental
, int, 0);
4284 static u32 dbg_level
;
4285 module_param_named(debug
, dbg_level
, uint
, 0);
4287 static int force_load
;
4288 module_param(force_load
, int, 0);
4290 static int fan_control_allowed
;
4291 module_param_named(fan_control
, fan_control_allowed
, int, 0);
4293 #define IBM_PARAM(feature) \
4294 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4297 IBM_PARAM(bluetooth
);
4300 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4303 #ifdef CONFIG_THINKPAD_ACPI_BAY
4305 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4310 IBM_PARAM(brightness
);
4314 static int __init
thinkpad_acpi_module_init(void)
4318 /* Driver-level probe */
4319 ret
= probe_for_thinkpad();
4323 /* Driver initialization */
4324 ibm_thinkpad_ec_found
= check_dmi_for_ec();
4325 IBM_ACPIHANDLE_INIT(ecrd
);
4326 IBM_ACPIHANDLE_INIT(ecwr
);
4328 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4330 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4331 thinkpad_acpi_module_exit();
4334 proc_dir
->owner
= THIS_MODULE
;
4336 ret
= platform_driver_register(&tpacpi_pdriver
);
4338 printk(IBM_ERR
"unable to register platform driver\n");
4339 thinkpad_acpi_module_exit();
4342 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4344 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4345 thinkpad_acpi_module_exit();
4350 /* Device initialization */
4351 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4353 if (IS_ERR(tpacpi_pdev
)) {
4354 ret
= PTR_ERR(tpacpi_pdev
);
4356 printk(IBM_ERR
"unable to register platform device\n");
4357 thinkpad_acpi_module_exit();
4360 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
4361 if (IS_ERR(tpacpi_hwmon
)) {
4362 ret
= PTR_ERR(tpacpi_hwmon
);
4363 tpacpi_hwmon
= NULL
;
4364 printk(IBM_ERR
"unable to register hwmon device\n");
4365 thinkpad_acpi_module_exit();
4368 tpacpi_inputdev
= input_allocate_device();
4369 if (!tpacpi_inputdev
) {
4370 printk(IBM_ERR
"unable to allocate input device\n");
4371 thinkpad_acpi_module_exit();
4374 /* Prepare input device, but don't register */
4375 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
4376 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
4377 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
4378 tpacpi_inputdev
->id
.vendor
= TPACPI_HKEY_INPUT_VENDOR
;
4379 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
4380 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
4382 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4383 ret
= ibm_init(&ibms_init
[i
]);
4384 if (ret
>= 0 && *ibms_init
[i
].param
)
4385 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
4387 thinkpad_acpi_module_exit();
4391 ret
= input_register_device(tpacpi_inputdev
);
4393 printk(IBM_ERR
"unable to register input device\n");
4394 thinkpad_acpi_module_exit();
4397 tp_features
.input_device_registered
= 1;
4403 static void thinkpad_acpi_module_exit(void)
4405 struct ibm_struct
*ibm
, *itmp
;
4407 list_for_each_entry_safe_reverse(ibm
, itmp
,
4408 &tpacpi_all_drivers
,
4413 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
4415 if (tpacpi_inputdev
) {
4416 if (tp_features
.input_device_registered
)
4417 input_unregister_device(tpacpi_inputdev
);
4419 input_free_device(tpacpi_inputdev
);
4423 hwmon_device_unregister(tpacpi_hwmon
);
4426 platform_device_unregister(tpacpi_pdev
);
4428 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
4429 platform_driver_unregister(&tpacpi_pdriver
);
4432 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
4434 kfree(ibm_thinkpad_ec_found
);
4437 module_init(thinkpad_acpi_module_init
);
4438 module_exit(thinkpad_acpi_module_exit
);