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.16"
25 #define TPACPI_SYSFS_VERSION 0x020000
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))
121 TPACPI_LIFE_INIT
= 0,
126 /****************************************************************************
127 ****************************************************************************
129 * ACPI Helpers and device model
131 ****************************************************************************
132 ****************************************************************************/
134 /*************************************************************************
138 static acpi_handle root_handle
;
140 #define IBM_HANDLE(object, parent, paths...) \
141 static acpi_handle object##_handle; \
142 static acpi_handle *object##_parent = &parent##_handle; \
143 static char *object##_path; \
144 static char *object##_paths[] = { paths }
146 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
147 "\\_SB.PCI.ISA.EC", /* 570 */
148 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
149 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
150 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
151 "\\_SB.PCI0.ICH3.EC0", /* R31 */
152 "\\_SB.PCI0.LPC.EC", /* all others */
155 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
156 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
159 /*************************************************************************
163 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
164 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
165 "\\CMS", /* R40, R40e */
168 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
169 "^HKEY", /* R30, R31 */
170 "HKEY", /* all others */
174 /*************************************************************************
178 static int acpi_evalf(acpi_handle handle
,
179 void *res
, char *method
, char *fmt
, ...)
182 struct acpi_object_list params
;
183 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
184 struct acpi_buffer result
, *resultp
;
185 union acpi_object out_obj
;
193 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
206 params
.pointer
= &in_objs
[0];
213 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
214 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
216 /* add more types as needed */
218 printk(IBM_ERR
"acpi_evalf() called "
219 "with invalid format character '%c'\n", c
);
225 if (res_type
!= 'v') {
226 result
.length
= sizeof(out_obj
);
227 result
.pointer
= &out_obj
;
232 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
237 *(int *)res
= out_obj
.integer
.value
;
238 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
241 success
= status
== AE_OK
;
243 /* add more types as needed */
245 printk(IBM_ERR
"acpi_evalf() called "
246 "with invalid format character '%c'\n", res_type
);
250 if (!success
&& !quiet
)
251 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
252 method
, fmt0
, status
);
257 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
261 if (acpi_evalf(handle
, &i
, method
, "d"))
262 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
264 printk(IBM_ERR
"error calling %s\n", method
);
267 static int acpi_ec_read(int i
, u8
* p
)
272 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
276 if (ec_read(i
, p
) < 0)
283 static int acpi_ec_write(int i
, u8 v
)
286 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
289 if (ec_write(i
, v
) < 0)
296 static int _sta(acpi_handle handle
)
300 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
306 static int issue_thinkpad_cmos_command(int cmos_cmd
)
311 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
317 /*************************************************************************
321 static void drv_acpi_handle_init(char *name
,
322 acpi_handle
*handle
, acpi_handle parent
,
323 char **paths
, int num_paths
, char **path
)
328 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
331 for (i
= 0; i
< num_paths
; i
++) {
332 status
= acpi_get_handle(parent
, paths
[i
], handle
);
333 if (ACPI_SUCCESS(status
)) {
335 dbg_printk(TPACPI_DBG_INIT
,
336 "Found ACPI handle %s for %s\n",
342 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
347 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
349 struct ibm_struct
*ibm
= data
;
351 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
354 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
357 ibm
->acpi
->notify(ibm
, event
);
360 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
367 if (!*ibm
->acpi
->handle
)
370 vdbg_printk(TPACPI_DBG_INIT
,
371 "setting up ACPI notify for %s\n", ibm
->name
);
373 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
375 printk(IBM_ERR
"acpi_bus_get_device(%s) failed: %d\n",
380 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
381 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
382 IBM_ACPI_EVENT_PREFIX
,
385 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
386 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
387 if (ACPI_FAILURE(status
)) {
388 if (status
== AE_ALREADY_EXISTS
) {
389 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
392 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
397 ibm
->flags
.acpi_notify_installed
= 1;
401 static int __init
tpacpi_device_add(struct acpi_device
*device
)
406 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
410 dbg_printk(TPACPI_DBG_INIT
,
411 "registering %s as an ACPI driver\n", ibm
->name
);
415 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
416 if (!ibm
->acpi
->driver
) {
417 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
421 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
422 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
423 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
425 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
427 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
429 kfree(ibm
->acpi
->driver
);
430 ibm
->acpi
->driver
= NULL
;
432 ibm
->flags
.acpi_driver_registered
= 1;
438 /****************************************************************************
439 ****************************************************************************
443 ****************************************************************************
444 ****************************************************************************/
446 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
447 int count
, int *eof
, void *data
)
449 struct ibm_struct
*ibm
= data
;
452 if (!ibm
|| !ibm
->read
)
455 len
= ibm
->read(page
);
459 if (len
<= off
+ count
)
471 static int dispatch_procfs_write(struct file
*file
,
472 const char __user
* userbuf
,
473 unsigned long count
, void *data
)
475 struct ibm_struct
*ibm
= data
;
479 if (!ibm
|| !ibm
->write
)
482 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
486 if (copy_from_user(kernbuf
, userbuf
, count
)) {
492 strcat(kernbuf
, ",");
493 ret
= ibm
->write(kernbuf
);
502 static char *next_cmd(char **cmds
)
507 while ((end
= strchr(start
, ',')) && end
== start
)
519 /****************************************************************************
520 ****************************************************************************
522 * Device model: input, hwmon and platform
524 ****************************************************************************
525 ****************************************************************************/
527 static struct platform_device
*tpacpi_pdev
;
528 static struct platform_device
*tpacpi_sensors_pdev
;
529 static struct class_device
*tpacpi_hwmon
;
530 static struct input_dev
*tpacpi_inputdev
;
531 static struct mutex tpacpi_inputdev_send_mutex
;
534 static int tpacpi_resume_handler(struct platform_device
*pdev
)
536 struct ibm_struct
*ibm
, *itmp
;
538 list_for_each_entry_safe(ibm
, itmp
,
548 static struct platform_driver tpacpi_pdriver
= {
550 .name
= IBM_DRVR_NAME
,
551 .owner
= THIS_MODULE
,
553 .resume
= tpacpi_resume_handler
,
556 static struct platform_driver tpacpi_hwmon_pdriver
= {
558 .name
= IBM_HWMON_DRVR_NAME
,
559 .owner
= THIS_MODULE
,
563 /*************************************************************************
564 * thinkpad-acpi driver attributes
567 /* interface_version --------------------------------------------------- */
568 static ssize_t
tpacpi_driver_interface_version_show(
569 struct device_driver
*drv
,
572 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
575 static DRIVER_ATTR(interface_version
, S_IRUGO
,
576 tpacpi_driver_interface_version_show
, NULL
);
578 /* debug_level --------------------------------------------------------- */
579 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
582 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
585 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
586 const char *buf
, size_t count
)
590 if (parse_strtoul(buf
, 0xffff, &t
))
598 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
599 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
601 /* version ------------------------------------------------------------- */
602 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
605 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
608 static DRIVER_ATTR(version
, S_IRUGO
,
609 tpacpi_driver_version_show
, NULL
);
611 /* --------------------------------------------------------------------- */
613 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
614 &driver_attr_debug_level
, &driver_attr_version
,
615 &driver_attr_interface_version
,
618 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
624 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
625 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
632 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
636 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
637 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
640 /*************************************************************************
641 * sysfs support helpers
644 struct attribute_set_obj
{
645 struct attribute_set s
;
647 } __attribute__((packed
));
649 static struct attribute_set
*create_attr_set(unsigned int max_members
,
652 struct attribute_set_obj
*sobj
;
654 if (max_members
== 0)
657 /* Allocates space for implicit NULL at the end too */
658 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
659 max_members
* sizeof(struct attribute
*),
663 sobj
->s
.max_members
= max_members
;
664 sobj
->s
.group
.attrs
= &sobj
->a
;
665 sobj
->s
.group
.name
= name
;
670 /* not multi-threaded safe, use it in a single thread per set */
671 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
676 if (s
->members
>= s
->max_members
)
679 s
->group
.attrs
[s
->members
] = attr
;
685 static int add_many_to_attr_set(struct attribute_set
* s
,
686 struct attribute
**attr
,
691 for (i
= 0; i
< count
; i
++) {
692 res
= add_to_attr_set(s
, attr
[i
]);
700 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
702 sysfs_remove_group(kobj
, &s
->group
);
706 static int parse_strtoul(const char *buf
,
707 unsigned long max
, unsigned long *value
)
711 while (*buf
&& isspace(*buf
))
713 *value
= simple_strtoul(buf
, &endp
, 0);
714 while (*endp
&& isspace(*endp
))
716 if (*endp
|| *value
> max
)
722 /****************************************************************************
723 ****************************************************************************
727 ****************************************************************************
728 ****************************************************************************/
730 /*************************************************************************
731 * thinkpad-acpi init subdriver
734 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
736 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
737 printk(IBM_INFO
"%s\n", IBM_URL
);
739 printk(IBM_INFO
"ThinkPad BIOS %s, EC %s\n",
740 (thinkpad_id
.bios_version_str
) ?
741 thinkpad_id
.bios_version_str
: "unknown",
742 (thinkpad_id
.ec_version_str
) ?
743 thinkpad_id
.ec_version_str
: "unknown");
745 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
746 printk(IBM_INFO
"%s %s\n",
747 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
748 "IBM" : ((thinkpad_id
.vendor
==
749 PCI_VENDOR_ID_LENOVO
) ?
750 "Lenovo" : "Unknown vendor"),
751 thinkpad_id
.model_str
);
756 static int thinkpad_acpi_driver_read(char *p
)
760 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
761 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
766 static struct ibm_struct thinkpad_acpi_driver_data
= {
768 .read
= thinkpad_acpi_driver_read
,
771 /*************************************************************************
775 static int hotkey_orig_status
;
776 static u32 hotkey_orig_mask
;
777 static u32 hotkey_all_mask
;
778 static u32 hotkey_reserved_mask
;
780 static u16
*hotkey_keycode_map
;
782 static struct attribute_set
*hotkey_dev_attributes
;
784 static int hotkey_get_wlsw(int *status
)
786 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
791 /* sysfs hotkey enable ------------------------------------------------- */
792 static ssize_t
hotkey_enable_show(struct device
*dev
,
793 struct device_attribute
*attr
,
799 res
= hotkey_get(&status
, &mask
);
803 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
806 static ssize_t
hotkey_enable_store(struct device
*dev
,
807 struct device_attribute
*attr
,
808 const char *buf
, size_t count
)
814 if (parse_strtoul(buf
, 1, &t
))
817 res
= hotkey_get(&status
, &mask
);
819 res
= hotkey_set(t
, mask
);
821 return (res
) ? res
: count
;
824 static struct device_attribute dev_attr_hotkey_enable
=
825 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
826 hotkey_enable_show
, hotkey_enable_store
);
828 /* sysfs hotkey mask --------------------------------------------------- */
829 static ssize_t
hotkey_mask_show(struct device
*dev
,
830 struct device_attribute
*attr
,
836 res
= hotkey_get(&status
, &mask
);
840 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
843 static ssize_t
hotkey_mask_store(struct device
*dev
,
844 struct device_attribute
*attr
,
845 const char *buf
, size_t count
)
851 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
854 res
= hotkey_get(&status
, &mask
);
856 hotkey_set(status
, t
);
858 return (res
) ? res
: count
;
861 static struct device_attribute dev_attr_hotkey_mask
=
862 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
863 hotkey_mask_show
, hotkey_mask_store
);
865 /* sysfs hotkey bios_enabled ------------------------------------------- */
866 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
867 struct device_attribute
*attr
,
870 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
873 static struct device_attribute dev_attr_hotkey_bios_enabled
=
874 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
876 /* sysfs hotkey bios_mask ---------------------------------------------- */
877 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
878 struct device_attribute
*attr
,
881 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
884 static struct device_attribute dev_attr_hotkey_bios_mask
=
885 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
887 /* sysfs hotkey all_mask ----------------------------------------------- */
888 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
889 struct device_attribute
*attr
,
892 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_all_mask
);
895 static struct device_attribute dev_attr_hotkey_all_mask
=
896 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
898 /* sysfs hotkey recommended_mask --------------------------------------- */
899 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
900 struct device_attribute
*attr
,
903 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
904 hotkey_all_mask
& ~hotkey_reserved_mask
);
907 static struct device_attribute dev_attr_hotkey_recommended_mask
=
908 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
909 hotkey_recommended_mask_show
, NULL
);
911 /* sysfs hotkey radio_sw ----------------------------------------------- */
912 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
913 struct device_attribute
*attr
,
917 res
= hotkey_get_wlsw(&s
);
921 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
924 static struct device_attribute dev_attr_hotkey_radio_sw
=
925 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
927 /* sysfs hotkey report_mode -------------------------------------------- */
928 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
929 struct device_attribute
*attr
,
932 return snprintf(buf
, PAGE_SIZE
, "%d\n",
933 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
936 static ssize_t
hotkey_report_mode_store(struct device
*dev
,
937 struct device_attribute
*attr
,
938 const char *buf
, size_t count
)
943 if (parse_strtoul(buf
, 2, &t
) || (t
< 1))
946 if (t
!= hotkey_report_mode
) {
947 if (tp_features
.hotkey_report_mode_locked
)
949 hotkey_report_mode
= t
;
950 printk(IBM_NOTICE
"hot key report mode set to %d\n",
954 return (res
) ? res
: count
;
957 static struct device_attribute dev_attr_hotkey_report_mode
=
958 __ATTR(hotkey_report_mode
, S_IWUSR
| S_IRUGO
,
959 hotkey_report_mode_show
, hotkey_report_mode_store
);
961 /* --------------------------------------------------------------------- */
963 static struct attribute
*hotkey_attributes
[] __initdata
= {
964 &dev_attr_hotkey_enable
.attr
,
965 &dev_attr_hotkey_report_mode
.attr
,
968 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
969 &dev_attr_hotkey_mask
.attr
,
970 &dev_attr_hotkey_bios_enabled
.attr
,
971 &dev_attr_hotkey_bios_mask
.attr
,
972 &dev_attr_hotkey_all_mask
.attr
,
973 &dev_attr_hotkey_recommended_mask
.attr
,
976 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
979 static u16 ibm_keycode_map
[] __initdata
= {
980 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
981 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
982 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
983 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
984 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
985 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
986 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
987 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
988 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
989 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
990 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
991 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
992 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
993 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
994 KEY_RESERVED
, /* 0x14: VOLUME UP */
995 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
996 KEY_RESERVED
, /* 0x16: MUTE */
997 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
998 /* (assignments unknown, please report if found) */
999 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1000 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1002 static u16 lenovo_keycode_map
[] __initdata
= {
1003 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1004 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1005 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1006 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1007 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
1008 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1009 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1010 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1011 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
1012 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1013 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
1014 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1015 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1016 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1017 KEY_RESERVED
, /* 0x14: VOLUME UP */
1018 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1019 KEY_RESERVED
, /* 0x16: MUTE */
1020 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1021 /* (assignments unknown, please report if found) */
1022 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1023 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1026 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1027 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1028 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1034 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1036 BUG_ON(!tpacpi_inputdev
);
1038 IBM_ACPIHANDLE_INIT(hkey
);
1039 mutex_init(&hotkey_mutex
);
1041 /* hotkey not supported on 570 */
1042 tp_features
.hotkey
= hkey_handle
!= NULL
;
1044 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1045 str_supported(tp_features
.hotkey
));
1047 if (tp_features
.hotkey
) {
1048 hotkey_dev_attributes
= create_attr_set(8, NULL
);
1049 if (!hotkey_dev_attributes
)
1051 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1053 ARRAY_SIZE(hotkey_attributes
));
1057 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1058 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1059 for HKEY interface version 0x100 */
1060 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1061 if ((hkeyv
>> 8) != 1) {
1062 printk(IBM_ERR
"unknown version of the "
1063 "HKEY interface: 0x%x\n", hkeyv
);
1064 printk(IBM_ERR
"please report this to %s\n",
1068 * MHKV 0x100 in A31, R40, R40e,
1069 * T4x, X31, and later
1071 tp_features
.hotkey_mask
= 1;
1075 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1076 str_supported(tp_features
.hotkey_mask
));
1078 if (tp_features
.hotkey_mask
) {
1079 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1082 "missing MHKA handler, "
1083 "please report this to %s\n",
1085 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
1089 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
1090 if (!res
&& tp_features
.hotkey_mask
) {
1091 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1092 hotkey_mask_attributes
,
1093 ARRAY_SIZE(hotkey_mask_attributes
));
1096 /* Not all thinkpads have a hardware radio switch */
1097 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1098 tp_features
.hotkey_wlsw
= 1;
1100 "radio switch found; radios are %s\n",
1101 enabled(status
, 0));
1102 res
= add_to_attr_set(hotkey_dev_attributes
,
1103 &dev_attr_hotkey_radio_sw
.attr
);
1107 res
= register_attr_set_with_sysfs(
1108 hotkey_dev_attributes
,
1109 &tpacpi_pdev
->dev
.kobj
);
1113 /* Set up key map */
1115 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1117 if (!hotkey_keycode_map
) {
1118 printk(IBM_ERR
"failed to allocate memory for key map\n");
1122 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1123 dbg_printk(TPACPI_DBG_INIT
,
1124 "using Lenovo default hot key map\n");
1125 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1126 TPACPI_HOTKEY_MAP_SIZE
);
1128 dbg_printk(TPACPI_DBG_INIT
,
1129 "using IBM default hot key map\n");
1130 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1131 TPACPI_HOTKEY_MAP_SIZE
);
1134 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1135 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1136 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1137 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1138 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1139 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1140 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1141 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1142 set_bit(hotkey_keycode_map
[i
],
1143 tpacpi_inputdev
->keybit
);
1145 if (i
< sizeof(hotkey_reserved_mask
)*8)
1146 hotkey_reserved_mask
|= 1 << i
;
1150 if (tp_features
.hotkey_wlsw
) {
1151 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1152 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1155 dbg_printk(TPACPI_DBG_INIT
,
1156 "enabling hot key handling\n");
1157 res
= hotkey_set(1, (hotkey_all_mask
& ~hotkey_reserved_mask
)
1158 | hotkey_orig_mask
);
1162 if (hotkey_report_mode
> 0) {
1163 tp_features
.hotkey_report_mode_locked
= 1;
1165 hotkey_report_mode
= 1;
1166 vdbg_printk(TPACPI_DBG_INIT
,
1167 "hot key reporting mode can be "
1168 "changed at runtime\n");
1171 dbg_printk(TPACPI_DBG_INIT
,
1172 "legacy hot key reporting over procfs %s\n",
1173 (hotkey_report_mode
< 2) ?
1174 "enabled" : "disabled");
1177 return (tp_features
.hotkey
)? 0 : 1;
1180 static void hotkey_exit(void)
1184 if (tp_features
.hotkey
) {
1185 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
1186 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
1188 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
1191 if (hotkey_dev_attributes
) {
1192 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1193 hotkey_dev_attributes
= NULL
;
1197 static void tpacpi_input_send_key(unsigned int scancode
,
1198 unsigned int keycode
)
1200 if (keycode
!= KEY_RESERVED
) {
1201 mutex_lock(&tpacpi_inputdev_send_mutex
);
1203 input_report_key(tpacpi_inputdev
, keycode
, 1);
1204 if (keycode
== KEY_UNKNOWN
)
1205 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1207 input_sync(tpacpi_inputdev
);
1209 input_report_key(tpacpi_inputdev
, keycode
, 0);
1210 if (keycode
== KEY_UNKNOWN
)
1211 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1213 input_sync(tpacpi_inputdev
);
1215 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1219 static void tpacpi_input_send_radiosw(void)
1223 mutex_lock(&tpacpi_inputdev_send_mutex
);
1225 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1226 input_report_switch(tpacpi_inputdev
,
1228 input_sync(tpacpi_inputdev
);
1231 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1234 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1237 unsigned int keycode
, scancode
;
1241 if (event
!= 0x80) {
1242 printk(IBM_ERR
"unknown HKEY notification event %d\n", event
);
1243 /* forward it to userspace, maybe it knows how to handle it */
1244 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1250 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1251 printk(IBM_ERR
"failed to retrieve HKEY event\n");
1263 switch (hkey
>> 12) {
1265 /* 0x1000-0x1FFF: key presses */
1266 scancode
= hkey
& 0xfff;
1267 if (scancode
> 0 && scancode
< 0x21) {
1269 keycode
= hotkey_keycode_map
[scancode
];
1270 tpacpi_input_send_key(scancode
, keycode
);
1273 "hotkey 0x%04x out of range for keyboard map\n",
1279 /* 0x5000-0x5FFF: LID */
1280 /* we don't handle it through this path, just
1281 * eat up known LID events */
1282 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1284 "unknown LID-related HKEY event: 0x%04x\n",
1292 /* 0x7000-0x7FFF: misc */
1293 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1294 tpacpi_input_send_radiosw();
1297 /* fallthrough to default */
1299 /* case 2: dock-related */
1300 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1301 /* case 3: ultra-bay related. maybe bay in dock? */
1302 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1303 printk(IBM_NOTICE
"unhandled HKEY event 0x%04x\n", hkey
);
1307 if (!ignore_acpi_ev
&& (send_acpi_ev
|| hotkey_report_mode
< 2)) {
1308 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
1313 static void hotkey_resume(void)
1315 tpacpi_input_send_radiosw();
1319 * Call with hotkey_mutex held
1321 static int hotkey_get(int *status
, u32
*mask
)
1323 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1326 if (tp_features
.hotkey_mask
)
1327 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1334 * Call with hotkey_mutex held
1336 static int hotkey_set(int status
, u32 mask
)
1340 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1343 if (tp_features
.hotkey_mask
)
1344 for (i
= 0; i
< 32; i
++) {
1345 int bit
= ((1 << i
) & mask
) != 0;
1346 if (!acpi_evalf(hkey_handle
,
1347 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1354 /* procfs -------------------------------------------------------------- */
1355 static int hotkey_read(char *p
)
1361 if (!tp_features
.hotkey
) {
1362 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1366 res
= mutex_lock_interruptible(&hotkey_mutex
);
1369 res
= hotkey_get(&status
, &mask
);
1370 mutex_unlock(&hotkey_mutex
);
1374 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1375 if (tp_features
.hotkey_mask
) {
1376 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1377 len
+= sprintf(p
+ len
,
1378 "commands:\tenable, disable, reset, <mask>\n");
1380 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1381 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1387 static int hotkey_write(char *buf
)
1394 if (!tp_features
.hotkey
)
1397 res
= mutex_lock_interruptible(&hotkey_mutex
);
1401 res
= hotkey_get(&status
, &mask
);
1406 while ((cmd
= next_cmd(&buf
))) {
1407 if (strlencmp(cmd
, "enable") == 0) {
1409 } else if (strlencmp(cmd
, "disable") == 0) {
1411 } else if (strlencmp(cmd
, "reset") == 0) {
1412 status
= hotkey_orig_status
;
1413 mask
= hotkey_orig_mask
;
1414 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1416 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1426 res
= hotkey_set(status
, mask
);
1429 mutex_unlock(&hotkey_mutex
);
1433 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1434 .hid
= IBM_HKEY_HID
,
1435 .notify
= hotkey_notify
,
1436 .handle
= &hkey_handle
,
1437 .type
= ACPI_DEVICE_NOTIFY
,
1440 static struct ibm_struct hotkey_driver_data
= {
1442 .read
= hotkey_read
,
1443 .write
= hotkey_write
,
1444 .exit
= hotkey_exit
,
1445 .resume
= hotkey_resume
,
1446 .acpi
= &ibm_hotkey_acpidriver
,
1449 /*************************************************************************
1450 * Bluetooth subdriver
1453 /* sysfs bluetooth enable ---------------------------------------------- */
1454 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1455 struct device_attribute
*attr
,
1460 status
= bluetooth_get_radiosw();
1464 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1467 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1468 struct device_attribute
*attr
,
1469 const char *buf
, size_t count
)
1474 if (parse_strtoul(buf
, 1, &t
))
1477 res
= bluetooth_set_radiosw(t
);
1479 return (res
) ? res
: count
;
1482 static struct device_attribute dev_attr_bluetooth_enable
=
1483 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1484 bluetooth_enable_show
, bluetooth_enable_store
);
1486 /* --------------------------------------------------------------------- */
1488 static struct attribute
*bluetooth_attributes
[] = {
1489 &dev_attr_bluetooth_enable
.attr
,
1493 static const struct attribute_group bluetooth_attr_group
= {
1494 .attrs
= bluetooth_attributes
,
1497 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1502 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1504 IBM_ACPIHANDLE_INIT(hkey
);
1506 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1507 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1508 tp_features
.bluetooth
= hkey_handle
&&
1509 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1511 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1512 str_supported(tp_features
.bluetooth
),
1515 if (tp_features
.bluetooth
) {
1516 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1517 /* no bluetooth hardware present in system */
1518 tp_features
.bluetooth
= 0;
1519 dbg_printk(TPACPI_DBG_INIT
,
1520 "bluetooth hardware not installed\n");
1522 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1523 &bluetooth_attr_group
);
1529 return (tp_features
.bluetooth
)? 0 : 1;
1532 static void bluetooth_exit(void)
1534 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1535 &bluetooth_attr_group
);
1538 static int bluetooth_get_radiosw(void)
1542 if (!tp_features
.bluetooth
)
1545 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1548 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1551 static int bluetooth_set_radiosw(int radio_on
)
1555 if (!tp_features
.bluetooth
)
1558 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1561 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1563 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1564 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1570 /* procfs -------------------------------------------------------------- */
1571 static int bluetooth_read(char *p
)
1574 int status
= bluetooth_get_radiosw();
1576 if (!tp_features
.bluetooth
)
1577 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1579 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1580 (status
)? "enabled" : "disabled");
1581 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1587 static int bluetooth_write(char *buf
)
1591 if (!tp_features
.bluetooth
)
1594 while ((cmd
= next_cmd(&buf
))) {
1595 if (strlencmp(cmd
, "enable") == 0) {
1596 bluetooth_set_radiosw(1);
1597 } else if (strlencmp(cmd
, "disable") == 0) {
1598 bluetooth_set_radiosw(0);
1606 static struct ibm_struct bluetooth_driver_data
= {
1607 .name
= "bluetooth",
1608 .read
= bluetooth_read
,
1609 .write
= bluetooth_write
,
1610 .exit
= bluetooth_exit
,
1613 /*************************************************************************
1617 /* sysfs wan enable ---------------------------------------------------- */
1618 static ssize_t
wan_enable_show(struct device
*dev
,
1619 struct device_attribute
*attr
,
1624 status
= wan_get_radiosw();
1628 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1631 static ssize_t
wan_enable_store(struct device
*dev
,
1632 struct device_attribute
*attr
,
1633 const char *buf
, size_t count
)
1638 if (parse_strtoul(buf
, 1, &t
))
1641 res
= wan_set_radiosw(t
);
1643 return (res
) ? res
: count
;
1646 static struct device_attribute dev_attr_wan_enable
=
1647 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1648 wan_enable_show
, wan_enable_store
);
1650 /* --------------------------------------------------------------------- */
1652 static struct attribute
*wan_attributes
[] = {
1653 &dev_attr_wan_enable
.attr
,
1657 static const struct attribute_group wan_attr_group
= {
1658 .attrs
= wan_attributes
,
1661 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1666 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1668 IBM_ACPIHANDLE_INIT(hkey
);
1670 tp_features
.wan
= hkey_handle
&&
1671 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1673 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1674 str_supported(tp_features
.wan
),
1677 if (tp_features
.wan
) {
1678 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1679 /* no wan hardware present in system */
1680 tp_features
.wan
= 0;
1681 dbg_printk(TPACPI_DBG_INIT
,
1682 "wan hardware not installed\n");
1684 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1691 return (tp_features
.wan
)? 0 : 1;
1694 static void wan_exit(void)
1696 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1700 static int wan_get_radiosw(void)
1704 if (!tp_features
.wan
)
1707 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1710 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1713 static int wan_set_radiosw(int radio_on
)
1717 if (!tp_features
.wan
)
1720 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1723 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1725 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1726 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1732 /* procfs -------------------------------------------------------------- */
1733 static int wan_read(char *p
)
1736 int status
= wan_get_radiosw();
1738 if (!tp_features
.wan
)
1739 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1741 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1742 (status
)? "enabled" : "disabled");
1743 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1749 static int wan_write(char *buf
)
1753 if (!tp_features
.wan
)
1756 while ((cmd
= next_cmd(&buf
))) {
1757 if (strlencmp(cmd
, "enable") == 0) {
1759 } else if (strlencmp(cmd
, "disable") == 0) {
1768 static struct ibm_struct wan_driver_data
= {
1773 .flags
.experimental
= 1,
1776 /*************************************************************************
1780 static enum video_access_mode video_supported
;
1781 static int video_orig_autosw
;
1783 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1784 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1785 "\\_SB.PCI0.VID0", /* 770e */
1786 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1787 "\\_SB.PCI0.AGP.VID", /* all others */
1790 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1792 static int __init
video_init(struct ibm_init_struct
*iibm
)
1796 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1798 IBM_ACPIHANDLE_INIT(vid
);
1799 IBM_ACPIHANDLE_INIT(vid2
);
1801 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1802 /* G41, assume IVGA doesn't change */
1803 vid_handle
= vid2_handle
;
1806 /* video switching not supported on R30, R31 */
1807 video_supported
= TPACPI_VIDEO_NONE
;
1808 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1810 video_supported
= TPACPI_VIDEO_570
;
1811 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1812 /* 600e/x, 770e, 770x */
1813 video_supported
= TPACPI_VIDEO_770
;
1816 video_supported
= TPACPI_VIDEO_NEW
;
1818 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1819 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1822 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1825 static void video_exit(void)
1827 dbg_printk(TPACPI_DBG_EXIT
,
1828 "restoring original video autoswitch mode\n");
1829 if (video_autosw_set(video_orig_autosw
))
1830 printk(IBM_ERR
"error while trying to restore original "
1831 "video autoswitch mode\n");
1834 static int video_outputsw_get(void)
1839 switch (video_supported
) {
1840 case TPACPI_VIDEO_570
:
1841 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1842 TP_ACPI_VIDEO_570_PHSCMD
))
1844 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1846 case TPACPI_VIDEO_770
:
1847 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1850 status
|= TP_ACPI_VIDEO_S_LCD
;
1851 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1854 status
|= TP_ACPI_VIDEO_S_CRT
;
1856 case TPACPI_VIDEO_NEW
:
1857 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1858 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1861 status
|= TP_ACPI_VIDEO_S_CRT
;
1863 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1864 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1867 status
|= TP_ACPI_VIDEO_S_LCD
;
1868 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1871 status
|= TP_ACPI_VIDEO_S_DVI
;
1880 static int video_outputsw_set(int status
)
1885 switch (video_supported
) {
1886 case TPACPI_VIDEO_570
:
1887 res
= acpi_evalf(NULL
, NULL
,
1888 "\\_SB.PHS2", "vdd",
1889 TP_ACPI_VIDEO_570_PHS2CMD
,
1890 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1892 case TPACPI_VIDEO_770
:
1893 autosw
= video_autosw_get();
1897 res
= video_autosw_set(1);
1900 res
= acpi_evalf(vid_handle
, NULL
,
1901 "ASWT", "vdd", status
* 0x100, 0);
1902 if (!autosw
&& video_autosw_set(autosw
)) {
1903 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1907 case TPACPI_VIDEO_NEW
:
1908 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1909 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1915 return (res
)? 0 : -EIO
;
1918 static int video_autosw_get(void)
1922 switch (video_supported
) {
1923 case TPACPI_VIDEO_570
:
1924 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1927 case TPACPI_VIDEO_770
:
1928 case TPACPI_VIDEO_NEW
:
1929 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1939 static int video_autosw_set(int enable
)
1941 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1946 static int video_outputsw_cycle(void)
1948 int autosw
= video_autosw_get();
1954 switch (video_supported
) {
1955 case TPACPI_VIDEO_570
:
1956 res
= video_autosw_set(1);
1959 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1961 case TPACPI_VIDEO_770
:
1962 case TPACPI_VIDEO_NEW
:
1963 res
= video_autosw_set(1);
1966 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1971 if (!autosw
&& video_autosw_set(autosw
)) {
1972 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1976 return (res
)? 0 : -EIO
;
1979 static int video_expand_toggle(void)
1981 switch (video_supported
) {
1982 case TPACPI_VIDEO_570
:
1983 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1985 case TPACPI_VIDEO_770
:
1986 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1988 case TPACPI_VIDEO_NEW
:
1989 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1997 static int video_read(char *p
)
2002 if (video_supported
== TPACPI_VIDEO_NONE
) {
2003 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2007 status
= video_outputsw_get();
2011 autosw
= video_autosw_get();
2015 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2016 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2017 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2018 if (video_supported
== TPACPI_VIDEO_NEW
)
2019 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2020 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2021 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2022 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2023 if (video_supported
== TPACPI_VIDEO_NEW
)
2024 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2025 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2026 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2031 static int video_write(char *buf
)
2034 int enable
, disable
, status
;
2037 if (video_supported
== TPACPI_VIDEO_NONE
)
2043 while ((cmd
= next_cmd(&buf
))) {
2044 if (strlencmp(cmd
, "lcd_enable") == 0) {
2045 enable
|= TP_ACPI_VIDEO_S_LCD
;
2046 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2047 disable
|= TP_ACPI_VIDEO_S_LCD
;
2048 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2049 enable
|= TP_ACPI_VIDEO_S_CRT
;
2050 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2051 disable
|= TP_ACPI_VIDEO_S_CRT
;
2052 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2053 strlencmp(cmd
, "dvi_enable") == 0) {
2054 enable
|= TP_ACPI_VIDEO_S_DVI
;
2055 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2056 strlencmp(cmd
, "dvi_disable") == 0) {
2057 disable
|= TP_ACPI_VIDEO_S_DVI
;
2058 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2059 res
= video_autosw_set(1);
2062 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2063 res
= video_autosw_set(0);
2066 } else if (strlencmp(cmd
, "video_switch") == 0) {
2067 res
= video_outputsw_cycle();
2070 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2071 res
= video_expand_toggle();
2078 if (enable
|| disable
) {
2079 status
= video_outputsw_get();
2082 res
= video_outputsw_set((status
& ~disable
) | enable
);
2090 static struct ibm_struct video_driver_data
= {
2093 .write
= video_write
,
2097 /*************************************************************************
2098 * Light (thinklight) subdriver
2101 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2102 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2104 static int __init
light_init(struct ibm_init_struct
*iibm
)
2106 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2108 IBM_ACPIHANDLE_INIT(ledb
);
2109 IBM_ACPIHANDLE_INIT(lght
);
2110 IBM_ACPIHANDLE_INIT(cmos
);
2112 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2113 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2115 if (tp_features
.light
)
2116 /* light status not supported on
2117 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2118 tp_features
.light_status
=
2119 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2121 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2122 str_supported(tp_features
.light
));
2124 return (tp_features
.light
)? 0 : 1;
2127 static int light_read(char *p
)
2132 if (!tp_features
.light
) {
2133 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2134 } else if (!tp_features
.light_status
) {
2135 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2136 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2138 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2140 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2141 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2147 static int light_write(char *buf
)
2149 int cmos_cmd
, lght_cmd
;
2153 if (!tp_features
.light
)
2156 while ((cmd
= next_cmd(&buf
))) {
2157 if (strlencmp(cmd
, "on") == 0) {
2160 } else if (strlencmp(cmd
, "off") == 0) {
2166 success
= cmos_handle
?
2167 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2168 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2176 static struct ibm_struct light_driver_data
= {
2179 .write
= light_write
,
2182 /*************************************************************************
2186 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2188 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2189 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2190 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2191 "\\_SB.PCI.ISA.SLCE", /* 570 */
2192 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2194 /* don't list other alternatives as we install a notify handler on the 570 */
2195 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2197 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2199 .notify
= dock_notify
,
2200 .handle
= &dock_handle
,
2201 .type
= ACPI_SYSTEM_NOTIFY
,
2204 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2205 * We just use it to get notifications of dock hotplug
2206 * in very old thinkpads */
2207 .hid
= PCI_ROOT_HID_STRING
,
2208 .notify
= dock_notify
,
2209 .handle
= &pci_handle
,
2210 .type
= ACPI_SYSTEM_NOTIFY
,
2214 static struct ibm_struct dock_driver_data
[2] = {
2218 .write
= dock_write
,
2219 .acpi
= &ibm_dock_acpidriver
[0],
2223 .acpi
= &ibm_dock_acpidriver
[1],
2227 #define dock_docked() (_sta(dock_handle) & 1)
2229 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2231 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2233 IBM_ACPIHANDLE_INIT(dock
);
2235 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2236 str_supported(dock_handle
!= NULL
));
2238 return (dock_handle
)? 0 : 1;
2241 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2245 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2247 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2248 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2249 IBM_ACPIHANDLE_INIT(pci
);
2250 dock2_needed
= (pci_handle
!= NULL
);
2251 vdbg_printk(TPACPI_DBG_INIT
,
2252 "dock PCI handler for the TP 570 is %s\n",
2253 str_supported(dock2_needed
));
2255 vdbg_printk(TPACPI_DBG_INIT
,
2256 "dock subdriver part 2 not required\n");
2260 return (dock2_needed
)? 0 : 1;
2263 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2265 int docked
= dock_docked();
2266 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, PCI_ROOT_HID_STRING
);
2268 if (event
== 1 && !pci
) /* 570 */
2269 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2270 else if (event
== 1 && pci
) /* 570 */
2271 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2272 else if (event
== 3 && docked
)
2273 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2274 else if (event
== 3 && !docked
)
2275 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
2276 else if (event
== 0 && docked
)
2277 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2279 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2280 event
, _sta(dock_handle
));
2281 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
2285 static int dock_read(char *p
)
2288 int docked
= dock_docked();
2291 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2293 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2295 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2296 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2302 static int dock_write(char *buf
)
2309 while ((cmd
= next_cmd(&buf
))) {
2310 if (strlencmp(cmd
, "undock") == 0) {
2311 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2312 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2314 } else if (strlencmp(cmd
, "dock") == 0) {
2315 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2324 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2326 /*************************************************************************
2330 #ifdef CONFIG_THINKPAD_ACPI_BAY
2331 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2332 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2333 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2334 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2335 ); /* A21e, R30, R31 */
2336 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2337 "_EJ0", /* all others */
2338 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2339 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2340 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2342 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2346 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2348 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2350 IBM_ACPIHANDLE_INIT(bay
);
2352 IBM_ACPIHANDLE_INIT(bay_ej
);
2353 IBM_ACPIHANDLE_INIT(bay2
);
2355 IBM_ACPIHANDLE_INIT(bay2_ej
);
2357 tp_features
.bay_status
= bay_handle
&&
2358 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2359 tp_features
.bay_status2
= bay2_handle
&&
2360 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2362 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2363 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2364 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2365 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2367 vdbg_printk(TPACPI_DBG_INIT
,
2368 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2369 str_supported(tp_features
.bay_status
),
2370 str_supported(tp_features
.bay_eject
),
2371 str_supported(tp_features
.bay_status2
),
2372 str_supported(tp_features
.bay_eject2
));
2374 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2375 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2378 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2380 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
2383 #define bay_occupied(b) (_sta(b##_handle) & 1)
2385 static int bay_read(char *p
)
2388 int occupied
= bay_occupied(bay
);
2389 int occupied2
= bay_occupied(bay2
);
2392 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2393 tp_features
.bay_status
?
2394 (occupied
? "occupied" : "unoccupied") :
2396 if (tp_features
.bay_status2
)
2397 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2398 "occupied" : "unoccupied");
2400 eject
= tp_features
.bay_eject
&& occupied
;
2401 eject2
= tp_features
.bay_eject2
&& occupied2
;
2403 if (eject
&& eject2
)
2404 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2406 len
+= sprintf(p
+ len
, "commands:\teject\n");
2408 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2413 static int bay_write(char *buf
)
2417 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2420 while ((cmd
= next_cmd(&buf
))) {
2421 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2422 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2424 } else if (tp_features
.bay_eject2
&&
2425 strlencmp(cmd
, "eject2") == 0) {
2426 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2435 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2436 .notify
= bay_notify
,
2437 .handle
= &bay_handle
,
2438 .type
= ACPI_SYSTEM_NOTIFY
,
2441 static struct ibm_struct bay_driver_data
= {
2445 .acpi
= &ibm_bay_acpidriver
,
2448 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2450 /*************************************************************************
2454 /* sysfs cmos_command -------------------------------------------------- */
2455 static ssize_t
cmos_command_store(struct device
*dev
,
2456 struct device_attribute
*attr
,
2457 const char *buf
, size_t count
)
2459 unsigned long cmos_cmd
;
2462 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2465 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2466 return (res
)? res
: count
;
2469 static struct device_attribute dev_attr_cmos_command
=
2470 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2472 /* --------------------------------------------------------------------- */
2474 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2478 vdbg_printk(TPACPI_DBG_INIT
,
2479 "initializing cmos commands subdriver\n");
2481 IBM_ACPIHANDLE_INIT(cmos
);
2483 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2484 str_supported(cmos_handle
!= NULL
));
2486 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2490 return (cmos_handle
)? 0 : 1;
2493 static void cmos_exit(void)
2495 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2498 static int cmos_read(char *p
)
2502 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2503 R30, R31, T20-22, X20-21 */
2505 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2507 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2508 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2514 static int cmos_write(char *buf
)
2519 while ((cmd
= next_cmd(&buf
))) {
2520 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2521 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2526 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2534 static struct ibm_struct cmos_driver_data
= {
2537 .write
= cmos_write
,
2541 /*************************************************************************
2545 static enum led_access_mode led_supported
;
2547 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2548 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2549 "LED", /* all others */
2552 static int __init
led_init(struct ibm_init_struct
*iibm
)
2554 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2556 IBM_ACPIHANDLE_INIT(led
);
2559 /* led not supported on R30, R31 */
2560 led_supported
= TPACPI_LED_NONE
;
2561 else if (strlencmp(led_path
, "SLED") == 0)
2563 led_supported
= TPACPI_LED_570
;
2564 else if (strlencmp(led_path
, "SYSL") == 0)
2565 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2566 led_supported
= TPACPI_LED_OLD
;
2569 led_supported
= TPACPI_LED_NEW
;
2571 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2572 str_supported(led_supported
), led_supported
);
2574 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2577 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2579 static int led_read(char *p
)
2583 if (!led_supported
) {
2584 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2587 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2589 if (led_supported
== TPACPI_LED_570
) {
2592 for (i
= 0; i
< 8; i
++) {
2593 if (!acpi_evalf(ec_handle
,
2594 &status
, "GLED", "dd", 1 << i
))
2596 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2597 i
, led_status(status
));
2601 len
+= sprintf(p
+ len
, "commands:\t"
2602 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2607 /* off, on, blink */
2608 static const int led_sled_arg1
[] = { 0, 1, 3 };
2609 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2610 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2611 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2613 static int led_write(char *buf
)
2621 while ((cmd
= next_cmd(&buf
))) {
2622 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2625 if (strstr(cmd
, "off")) {
2627 } else if (strstr(cmd
, "on")) {
2629 } else if (strstr(cmd
, "blink")) {
2634 if (led_supported
== TPACPI_LED_570
) {
2637 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2638 led
, led_sled_arg1
[ind
]))
2640 } else if (led_supported
== TPACPI_LED_OLD
) {
2641 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2643 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2646 ec_write(TPACPI_LED_EC_HLBL
,
2647 led
* led_exp_hlbl
[ind
]);
2650 ec_write(TPACPI_LED_EC_HLCL
,
2651 led
* led_exp_hlcl
[ind
]);
2656 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2657 led
, led_led_arg1
[ind
]))
2665 static struct ibm_struct led_driver_data
= {
2671 /*************************************************************************
2675 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2677 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2679 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2681 IBM_ACPIHANDLE_INIT(beep
);
2683 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2684 str_supported(beep_handle
!= NULL
));
2686 return (beep_handle
)? 0 : 1;
2689 static int beep_read(char *p
)
2694 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2696 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2697 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2703 static int beep_write(char *buf
)
2711 while ((cmd
= next_cmd(&buf
))) {
2712 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2713 beep_cmd
>= 0 && beep_cmd
<= 17) {
2717 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2724 static struct ibm_struct beep_driver_data
= {
2727 .write
= beep_write
,
2730 /*************************************************************************
2734 static enum thermal_access_mode thermal_read_mode
;
2736 /* sysfs temp##_input -------------------------------------------------- */
2738 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2739 struct device_attribute
*attr
,
2742 struct sensor_device_attribute
*sensor_attr
=
2743 to_sensor_dev_attr(attr
);
2744 int idx
= sensor_attr
->index
;
2748 res
= thermal_get_sensor(idx
, &value
);
2751 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2754 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2757 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2758 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2760 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2761 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2762 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2763 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2764 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2765 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2766 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2767 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2768 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2769 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2770 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2771 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2772 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2773 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2774 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2775 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2776 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2779 #define THERMAL_ATTRS(X) \
2780 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2782 static struct attribute
*thermal_temp_input_attr
[] = {
2802 static const struct attribute_group thermal_temp_input16_group
= {
2803 .attrs
= thermal_temp_input_attr
2806 static const struct attribute_group thermal_temp_input8_group
= {
2807 .attrs
= &thermal_temp_input_attr
[8]
2810 #undef THERMAL_SENSOR_ATTR_TEMP
2811 #undef THERMAL_ATTRS
2813 /* --------------------------------------------------------------------- */
2815 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2822 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2824 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2826 if (thinkpad_id
.ec_model
) {
2828 * Direct EC access mode: sensors at registers
2829 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2830 * non-implemented, thermal sensors return 0x80 when
2835 for (i
= 0; i
< 8; i
++) {
2836 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2842 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2850 /* This is sheer paranoia, but we handle it anyway */
2853 "ThinkPad ACPI EC access misbehaving, "
2854 "falling back to ACPI TMPx access mode\n");
2855 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2858 "ThinkPad ACPI EC access misbehaving, "
2859 "disabling thermal sensors access\n");
2860 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2865 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2867 } else if (acpi_tmp7
) {
2868 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2869 /* 600e/x, 770e, 770x */
2870 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2872 /* Standard ACPI TMPx access, max 8 sensors */
2873 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2876 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2877 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2880 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2881 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2884 switch(thermal_read_mode
) {
2885 case TPACPI_THERMAL_TPEC_16
:
2886 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2887 &thermal_temp_input16_group
);
2891 case TPACPI_THERMAL_TPEC_8
:
2892 case TPACPI_THERMAL_ACPI_TMP07
:
2893 case TPACPI_THERMAL_ACPI_UPDT
:
2894 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2895 &thermal_temp_input8_group
);
2899 case TPACPI_THERMAL_NONE
:
2907 static void thermal_exit(void)
2909 switch(thermal_read_mode
) {
2910 case TPACPI_THERMAL_TPEC_16
:
2911 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2912 &thermal_temp_input16_group
);
2914 case TPACPI_THERMAL_TPEC_8
:
2915 case TPACPI_THERMAL_ACPI_TMP07
:
2916 case TPACPI_THERMAL_ACPI_UPDT
:
2917 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2918 &thermal_temp_input16_group
);
2920 case TPACPI_THERMAL_NONE
:
2926 /* idx is zero-based */
2927 static int thermal_get_sensor(int idx
, s32
*value
)
2933 t
= TP_EC_THERMAL_TMP0
;
2935 switch (thermal_read_mode
) {
2936 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2937 case TPACPI_THERMAL_TPEC_16
:
2938 if (idx
>= 8 && idx
<= 15) {
2939 t
= TP_EC_THERMAL_TMP8
;
2944 case TPACPI_THERMAL_TPEC_8
:
2946 if (!acpi_ec_read(t
+ idx
, &tmp
))
2948 *value
= tmp
* 1000;
2953 case TPACPI_THERMAL_ACPI_UPDT
:
2955 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2956 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2958 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2960 *value
= (t
- 2732) * 100;
2965 case TPACPI_THERMAL_ACPI_TMP07
:
2967 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2968 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2970 if (t
> 127 || t
< -127)
2971 t
= TP_EC_THERMAL_TMP_NA
;
2977 case TPACPI_THERMAL_NONE
:
2985 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2996 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2999 for(i
= 0 ; i
< n
; i
++) {
3000 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3008 static int thermal_read(char *p
)
3012 struct ibm_thermal_sensors_struct t
;
3014 n
= thermal_get_sensors(&t
);
3015 if (unlikely(n
< 0))
3018 len
+= sprintf(p
+ len
, "temperatures:\t");
3021 for (i
= 0; i
< (n
- 1); i
++)
3022 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3023 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3025 len
+= sprintf(p
+ len
, "not supported\n");
3030 static struct ibm_struct thermal_driver_data
= {
3032 .read
= thermal_read
,
3033 .exit
= thermal_exit
,
3036 /*************************************************************************
3040 static u8 ecdump_regs
[256];
3042 static int ecdump_read(char *p
)
3048 len
+= sprintf(p
+ len
, "EC "
3049 " +00 +01 +02 +03 +04 +05 +06 +07"
3050 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
3051 for (i
= 0; i
< 256; i
+= 16) {
3052 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
3053 for (j
= 0; j
< 16; j
++) {
3054 if (!acpi_ec_read(i
+ j
, &v
))
3056 if (v
!= ecdump_regs
[i
+ j
])
3057 len
+= sprintf(p
+ len
, " *%02x", v
);
3059 len
+= sprintf(p
+ len
, " %02x", v
);
3060 ecdump_regs
[i
+ j
] = v
;
3062 len
+= sprintf(p
+ len
, "\n");
3067 /* These are way too dangerous to advertise openly... */
3069 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3070 " (<offset> is 00-ff, <value> is 00-ff)\n");
3071 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3072 " (<offset> is 00-ff, <value> is 0-255)\n");
3077 static int ecdump_write(char *buf
)
3082 while ((cmd
= next_cmd(&buf
))) {
3083 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3085 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3089 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3090 if (!acpi_ec_write(i
, v
))
3099 static struct ibm_struct ecdump_driver_data
= {
3101 .read
= ecdump_read
,
3102 .write
= ecdump_write
,
3103 .flags
.experimental
= 1,
3106 /*************************************************************************
3107 * Backlight/brightness subdriver
3110 static struct backlight_device
*ibm_backlight_device
;
3112 static struct backlight_ops ibm_backlight_data
= {
3113 .get_brightness
= brightness_get
,
3114 .update_status
= brightness_update_status
,
3117 static struct mutex brightness_mutex
;
3119 static int __init
tpacpi_query_bcll_levels(acpi_handle handle
)
3121 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
3122 union acpi_object
*obj
;
3125 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
3126 obj
= (union acpi_object
*)buffer
.pointer
;
3127 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
3128 printk(IBM_ERR
"Unknown BCLL data, "
3129 "please report this to %s\n", IBM_MAIL
);
3132 rc
= obj
->package
.count
;
3138 kfree(buffer
.pointer
);
3142 static acpi_status __init
brightness_find_bcll(acpi_handle handle
, u32 lvl
,
3143 void *context
, void **rv
)
3145 char name
[ACPI_PATH_SEGMENT_LENGTH
];
3146 struct acpi_buffer buffer
= { sizeof(name
), &name
};
3148 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
3149 !strncmp("BCLL", name
, sizeof(name
) - 1)) {
3150 if (tpacpi_query_bcll_levels(handle
) == 16) {
3152 return AE_CTRL_TERMINATE
;
3161 static int __init
brightness_check_levels(void)
3164 void *found_node
= NULL
;
3167 IBM_ACPIHANDLE_INIT(vid
);
3172 /* Search for a BCLL package with 16 levels */
3173 status
= acpi_walk_namespace(ACPI_TYPE_PACKAGE
, vid_handle
, 3,
3174 brightness_find_bcll
, NULL
, &found_node
);
3176 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
3179 static acpi_status __init
brightness_find_bcl(acpi_handle handle
, u32 lvl
,
3180 void *context
, void **rv
)
3182 char name
[ACPI_PATH_SEGMENT_LENGTH
];
3183 struct acpi_buffer buffer
= { sizeof(name
), &name
};
3185 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
3186 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
3188 return AE_CTRL_TERMINATE
;
3194 static int __init
brightness_check_std_acpi_support(void)
3197 void *found_node
= NULL
;
3200 IBM_ACPIHANDLE_INIT(vid
);
3205 /* Search for a _BCL method, but don't execute it */
3206 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
3207 brightness_find_bcl
, NULL
, &found_node
);
3209 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
3212 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
3216 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
3218 mutex_init(&brightness_mutex
);
3220 if (!brightness_enable
) {
3221 dbg_printk(TPACPI_DBG_INIT
,
3222 "brightness support disabled by module parameter\n");
3224 } else if (brightness_enable
> 1) {
3225 if (brightness_check_std_acpi_support()) {
3227 "standard ACPI backlight interface available, not loading native one...\n");
3232 if (!brightness_mode
) {
3233 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
3234 brightness_mode
= 2;
3236 brightness_mode
= 3;
3238 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
3242 if (brightness_mode
> 3)
3245 tp_features
.bright_16levels
=
3246 thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
&&
3247 brightness_check_levels();
3249 b
= brightness_get(NULL
);
3253 if (tp_features
.bright_16levels
)
3254 printk(IBM_INFO
"detected a 16-level brightness capable ThinkPad\n");
3256 ibm_backlight_device
= backlight_device_register(
3257 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
3258 &ibm_backlight_data
);
3259 if (IS_ERR(ibm_backlight_device
)) {
3260 printk(IBM_ERR
"Could not register backlight device\n");
3261 return PTR_ERR(ibm_backlight_device
);
3263 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
3265 ibm_backlight_device
->props
.max_brightness
=
3266 (tp_features
.bright_16levels
)? 15 : 7;
3267 ibm_backlight_device
->props
.brightness
= b
;
3268 backlight_update_status(ibm_backlight_device
);
3273 static void brightness_exit(void)
3275 if (ibm_backlight_device
) {
3276 vdbg_printk(TPACPI_DBG_EXIT
,
3277 "calling backlight_device_unregister()\n");
3278 backlight_device_unregister(ibm_backlight_device
);
3279 ibm_backlight_device
= NULL
;
3283 static int brightness_update_status(struct backlight_device
*bd
)
3285 return brightness_set(
3286 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
3287 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
3288 bd
->props
.brightness
: 0);
3292 * ThinkPads can read brightness from two places: EC 0x31, or
3293 * CMOS NVRAM byte 0x5E, bits 0-3.
3295 static int brightness_get(struct backlight_device
*bd
)
3297 u8 lec
= 0, lcmos
= 0, level
= 0;
3299 if (brightness_mode
& 1) {
3300 if (!acpi_ec_read(brightness_offset
, &lec
))
3302 lec
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3305 if (brightness_mode
& 2) {
3306 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3307 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3308 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3309 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3313 if (brightness_mode
== 3 && lec
!= lcmos
) {
3315 "CMOS NVRAM (%u) and EC (%u) do not agree "
3316 "on display brightness level\n",
3317 (unsigned int) lcmos
,
3318 (unsigned int) lec
);
3325 static int brightness_set(int value
)
3327 int cmos_cmd
, inc
, i
, res
;
3330 if (value
> ((tp_features
.bright_16levels
)? 15 : 7))
3333 res
= mutex_lock_interruptible(&brightness_mutex
);
3337 current_value
= brightness_get(NULL
);
3338 if (current_value
< 0) {
3339 res
= current_value
;
3343 cmos_cmd
= value
> current_value
?
3344 TP_CMOS_BRIGHTNESS_UP
:
3345 TP_CMOS_BRIGHTNESS_DOWN
;
3346 inc
= (value
> current_value
)? 1 : -1;
3349 for (i
= current_value
; i
!= value
; i
+= inc
) {
3350 if ((brightness_mode
& 2) &&
3351 issue_thinkpad_cmos_command(cmos_cmd
)) {
3355 if ((brightness_mode
& 1) &&
3356 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
3363 mutex_unlock(&brightness_mutex
);
3367 static int brightness_read(char *p
)
3372 if ((level
= brightness_get(NULL
)) < 0) {
3373 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3375 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
3376 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3377 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3378 " (<level> is 0-%d)\n",
3379 (tp_features
.bright_16levels
) ? 15 : 7);
3385 static int brightness_write(char *buf
)
3390 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
3392 while ((cmd
= next_cmd(&buf
))) {
3393 if ((level
= brightness_get(NULL
)) < 0)
3396 if (strlencmp(cmd
, "up") == 0) {
3397 new_level
= level
== (max_level
)?
3398 max_level
: level
+ 1;
3399 } else if (strlencmp(cmd
, "down") == 0) {
3400 new_level
= level
== 0? 0 : level
- 1;
3401 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3402 new_level
>= 0 && new_level
<= max_level
) {
3407 brightness_set(new_level
);
3413 static struct ibm_struct brightness_driver_data
= {
3414 .name
= "brightness",
3415 .read
= brightness_read
,
3416 .write
= brightness_write
,
3417 .exit
= brightness_exit
,
3420 /*************************************************************************
3424 static int volume_read(char *p
)
3429 if (!acpi_ec_read(volume_offset
, &level
)) {
3430 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3432 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3433 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3434 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3435 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3436 " (<level> is 0-15)\n");
3442 static int volume_write(char *buf
)
3444 int cmos_cmd
, inc
, i
;
3446 int new_level
, new_mute
;
3449 while ((cmd
= next_cmd(&buf
))) {
3450 if (!acpi_ec_read(volume_offset
, &level
))
3452 new_mute
= mute
= level
& 0x40;
3453 new_level
= level
= level
& 0xf;
3455 if (strlencmp(cmd
, "up") == 0) {
3459 new_level
= level
== 15 ? 15 : level
+ 1;
3460 } else if (strlencmp(cmd
, "down") == 0) {
3464 new_level
= level
== 0 ? 0 : level
- 1;
3465 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3466 new_level
>= 0 && new_level
<= 15) {
3468 } else if (strlencmp(cmd
, "mute") == 0) {
3473 if (new_level
!= level
) { /* mute doesn't change */
3474 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3475 inc
= new_level
> level
? 1 : -1;
3477 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3478 !acpi_ec_write(volume_offset
, level
)))
3481 for (i
= level
; i
!= new_level
; i
+= inc
)
3482 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3483 !acpi_ec_write(volume_offset
, i
+ inc
))
3486 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3487 !acpi_ec_write(volume_offset
,
3492 if (new_mute
!= mute
) { /* level doesn't change */
3493 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3495 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3496 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3504 static struct ibm_struct volume_driver_data
= {
3506 .read
= volume_read
,
3507 .write
= volume_write
,
3510 /*************************************************************************
3517 * TPACPI_FAN_RD_ACPI_GFAN:
3518 * ACPI GFAN method: returns fan level
3520 * see TPACPI_FAN_WR_ACPI_SFAN
3521 * EC 0x2f (HFSP) not available if GFAN exists
3523 * TPACPI_FAN_WR_ACPI_SFAN:
3524 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3526 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3529 * TPACPI_FAN_WR_TPEC:
3530 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3531 * Supported on almost all ThinkPads
3533 * Fan speed changes of any sort (including those caused by the
3534 * disengaged mode) are usually done slowly by the firmware as the
3535 * maximum ammount of fan duty cycle change per second seems to be
3538 * Reading is not available if GFAN exists.
3539 * Writing is not available if SFAN exists.
3542 * 7 automatic mode engaged;
3543 * (default operation mode of the ThinkPad)
3544 * fan level is ignored in this mode.
3545 * 6 full speed mode (takes precedence over bit 7);
3546 * not available on all thinkpads. May disable
3547 * the tachometer while the fan controller ramps up
3548 * the speed (which can take up to a few *minutes*).
3549 * Speeds up fan to 100% duty-cycle, which is far above
3550 * the standard RPM levels. It is not impossible that
3551 * it could cause hardware damage.
3552 * 5-3 unused in some models. Extra bits for fan level
3553 * in others, but still useless as all values above
3554 * 7 map to the same speed as level 7 in these models.
3555 * 2-0 fan level (0..7 usually)
3557 * 0x07 = max (set when temperatures critical)
3558 * Some ThinkPads may have other levels, see
3559 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3561 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3562 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3563 * does so, its initial value is meaningless (0x07).
3565 * For firmware bugs, refer to:
3566 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3570 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3571 * Main fan tachometer reading (in RPM)
3573 * This register is present on all ThinkPads with a new-style EC, and
3574 * it is known not to be present on the A21m/e, and T22, as there is
3575 * something else in offset 0x84 according to the ACPI DSDT. Other
3576 * ThinkPads from this same time period (and earlier) probably lack the
3577 * tachometer as well.
3579 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3580 * was never fixed by IBM to report the EC firmware version string
3581 * probably support the tachometer (like the early X models), so
3582 * detecting it is quite hard. We need more data to know for sure.
3584 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3587 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3590 * For firmware bugs, refer to:
3591 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3593 * TPACPI_FAN_WR_ACPI_FANS:
3594 * ThinkPad X31, X40, X41. Not available in the X60.
3596 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3597 * high speed. ACPI DSDT seems to map these three speeds to levels
3598 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3599 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3601 * The speeds are stored on handles
3602 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3604 * There are three default speed sets, acessible as handles:
3605 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3607 * ACPI DSDT switches which set is in use depending on various
3610 * TPACPI_FAN_WR_TPEC is also available and should be used to
3611 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3612 * but the ACPI tables just mention level 7.
3615 static enum fan_status_access_mode fan_status_access_mode
;
3616 static enum fan_control_access_mode fan_control_access_mode
;
3617 static enum fan_control_commands fan_control_commands
;
3619 static u8 fan_control_initial_status
;
3620 static u8 fan_control_desired_level
;
3622 static void fan_watchdog_fire(struct work_struct
*ignored
);
3623 static int fan_watchdog_maxinterval
;
3624 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3626 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3627 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3628 "\\FSPD", /* 600e/x, 770e, 770x */
3630 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3631 "JFNS", /* 770x-JL */
3635 * SYSFS fan layout: hwmon compatible (device)
3638 * 0: "disengaged" mode
3640 * 2: native EC "auto" mode (recommended, hardware default)
3642 * pwm*: set speed in manual mode, ignored otherwise.
3643 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3646 * fan*_input: tachometer reading, RPM
3649 * SYSFS fan layout: extensions
3651 * fan_watchdog (driver):
3652 * fan watchdog interval in seconds, 0 disables (default), max 120
3655 /* sysfs fan pwm1_enable ----------------------------------------------- */
3656 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3657 struct device_attribute
*attr
,
3663 res
= fan_get_status_safe(&status
);
3667 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3668 if (status
!= fan_control_initial_status
) {
3669 tp_features
.fan_ctrl_status_undef
= 0;
3671 /* Return most likely status. In fact, it
3672 * might be the only possible status */
3673 status
= TP_EC_FAN_AUTO
;
3677 if (status
& TP_EC_FAN_FULLSPEED
) {
3679 } else if (status
& TP_EC_FAN_AUTO
) {
3684 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3687 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3688 struct device_attribute
*attr
,
3689 const char *buf
, size_t count
)
3694 if (parse_strtoul(buf
, 2, &t
))
3699 level
= TP_EC_FAN_FULLSPEED
;
3702 level
= TPACPI_FAN_LAST_LEVEL
;
3705 level
= TP_EC_FAN_AUTO
;
3708 /* reserved for software-controlled auto mode */
3714 res
= fan_set_level_safe(level
);
3720 fan_watchdog_reset();
3725 static struct device_attribute dev_attr_fan_pwm1_enable
=
3726 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3727 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3729 /* sysfs fan pwm1 ------------------------------------------------------ */
3730 static ssize_t
fan_pwm1_show(struct device
*dev
,
3731 struct device_attribute
*attr
,
3737 res
= fan_get_status_safe(&status
);
3741 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3742 if (status
!= fan_control_initial_status
) {
3743 tp_features
.fan_ctrl_status_undef
= 0;
3745 status
= TP_EC_FAN_AUTO
;
3750 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3751 status
= fan_control_desired_level
;
3756 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3759 static ssize_t
fan_pwm1_store(struct device
*dev
,
3760 struct device_attribute
*attr
,
3761 const char *buf
, size_t count
)
3765 u8 status
, newlevel
;
3767 if (parse_strtoul(buf
, 255, &s
))
3770 /* scale down from 0-255 to 0-7 */
3771 newlevel
= (s
>> 5) & 0x07;
3773 rc
= mutex_lock_interruptible(&fan_mutex
);
3777 rc
= fan_get_status(&status
);
3778 if (!rc
&& (status
&
3779 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3780 rc
= fan_set_level(newlevel
);
3784 fan_update_desired_level(newlevel
);
3785 fan_watchdog_reset();
3789 mutex_unlock(&fan_mutex
);
3790 return (rc
)? rc
: count
;
3793 static struct device_attribute dev_attr_fan_pwm1
=
3794 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3795 fan_pwm1_show
, fan_pwm1_store
);
3797 /* sysfs fan fan1_input ------------------------------------------------ */
3798 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3799 struct device_attribute
*attr
,
3805 res
= fan_get_speed(&speed
);
3809 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3812 static struct device_attribute dev_attr_fan_fan1_input
=
3813 __ATTR(fan1_input
, S_IRUGO
,
3814 fan_fan1_input_show
, NULL
);
3816 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
3817 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3820 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3823 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3824 const char *buf
, size_t count
)
3828 if (parse_strtoul(buf
, 120, &t
))
3831 if (!fan_control_allowed
)
3834 fan_watchdog_maxinterval
= t
;
3835 fan_watchdog_reset();
3840 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3841 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3843 /* --------------------------------------------------------------------- */
3844 static struct attribute
*fan_attributes
[] = {
3845 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3846 &dev_attr_fan_fan1_input
.attr
,
3850 static const struct attribute_group fan_attr_group
= {
3851 .attrs
= fan_attributes
,
3854 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3858 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3860 mutex_init(&fan_mutex
);
3861 fan_status_access_mode
= TPACPI_FAN_NONE
;
3862 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3863 fan_control_commands
= 0;
3864 fan_watchdog_maxinterval
= 0;
3865 tp_features
.fan_ctrl_status_undef
= 0;
3866 fan_control_desired_level
= 7;
3868 IBM_ACPIHANDLE_INIT(fans
);
3869 IBM_ACPIHANDLE_INIT(gfan
);
3870 IBM_ACPIHANDLE_INIT(sfan
);
3873 /* 570, 600e/x, 770e, 770x */
3874 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3876 /* all other ThinkPads: note that even old-style
3877 * ThinkPad ECs supports the fan control register */
3878 if (likely(acpi_ec_read(fan_status_offset
,
3879 &fan_control_initial_status
))) {
3880 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3882 /* In some ThinkPads, neither the EC nor the ACPI
3883 * DSDT initialize the fan status, and it ends up
3884 * being set to 0x07 when it *could* be either
3887 * Enable for TP-1Y (T43), TP-78 (R51e),
3888 * TP-76 (R52), TP-70 (T43, R52), which are known
3890 if (fan_control_initial_status
== 0x07) {
3891 switch (thinkpad_id
.ec_model
) {
3892 case 0x5931: /* TP-1Y */
3893 case 0x3837: /* TP-78 */
3894 case 0x3637: /* TP-76 */
3895 case 0x3037: /* TP-70 */
3897 "fan_init: initial fan status is "
3898 "unknown, assuming it is in auto "
3900 tp_features
.fan_ctrl_status_undef
= 1;
3906 "ThinkPad ACPI EC access misbehaving, "
3907 "fan status and control unavailable\n");
3914 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3915 fan_control_commands
|=
3916 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3919 /* gfan without sfan means no fan control */
3920 /* all other models implement TP EC 0x2f control */
3924 fan_control_access_mode
=
3925 TPACPI_FAN_WR_ACPI_FANS
;
3926 fan_control_commands
|=
3927 TPACPI_FAN_CMD_SPEED
|
3928 TPACPI_FAN_CMD_LEVEL
|
3929 TPACPI_FAN_CMD_ENABLE
;
3931 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3932 fan_control_commands
|=
3933 TPACPI_FAN_CMD_LEVEL
|
3934 TPACPI_FAN_CMD_ENABLE
;
3939 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3940 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3941 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3942 fan_status_access_mode
, fan_control_access_mode
);
3944 /* fan control master switch */
3945 if (!fan_control_allowed
) {
3946 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3947 fan_control_commands
= 0;
3948 dbg_printk(TPACPI_DBG_INIT
,
3949 "fan control features disabled by parameter\n");
3952 /* update fan_control_desired_level */
3953 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3954 fan_get_status_safe(NULL
);
3956 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3957 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3958 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3961 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
3962 &driver_attr_fan_watchdog
);
3971 * Call with fan_mutex held
3973 static void fan_update_desired_level(u8 status
)
3976 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3978 fan_control_desired_level
= 7;
3980 fan_control_desired_level
= status
;
3984 static int fan_get_status(u8
*status
)
3989 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3991 switch (fan_status_access_mode
) {
3992 case TPACPI_FAN_RD_ACPI_GFAN
:
3993 /* 570, 600e/x, 770e, 770x */
3995 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
4003 case TPACPI_FAN_RD_TPEC
:
4004 /* all except 570, 600e/x, 770e, 770x */
4005 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
4020 static int fan_get_status_safe(u8
*status
)
4025 rc
= mutex_lock_interruptible(&fan_mutex
);
4028 rc
= fan_get_status(&s
);
4030 fan_update_desired_level(s
);
4031 mutex_unlock(&fan_mutex
);
4039 static void fan_exit(void)
4041 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
4043 /* FIXME: can we really do this unconditionally? */
4044 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
4045 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
, &driver_attr_fan_watchdog
);
4047 cancel_delayed_work(&fan_watchdog_task
);
4048 flush_scheduled_work();
4051 static int fan_get_speed(unsigned int *speed
)
4055 switch (fan_status_access_mode
) {
4056 case TPACPI_FAN_RD_TPEC
:
4057 /* all except 570, 600e/x, 770e, 770x */
4058 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4059 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4063 *speed
= (hi
<< 8) | lo
;
4074 static void fan_watchdog_fire(struct work_struct
*ignored
)
4078 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
4081 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
4082 rc
= fan_set_enable();
4084 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
4085 "will try again later...\n", -rc
);
4086 /* reschedule for later */
4087 fan_watchdog_reset();
4091 static void fan_watchdog_reset(void)
4093 static int fan_watchdog_active
;
4095 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
4098 if (fan_watchdog_active
)
4099 cancel_delayed_work(&fan_watchdog_task
);
4101 if (fan_watchdog_maxinterval
> 0 &&
4102 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
4103 fan_watchdog_active
= 1;
4104 if (!schedule_delayed_work(&fan_watchdog_task
,
4105 msecs_to_jiffies(fan_watchdog_maxinterval
4107 printk(IBM_ERR
"failed to schedule the fan watchdog, "
4108 "watchdog will not trigger\n");
4111 fan_watchdog_active
= 0;
4114 static int fan_set_level(int level
)
4116 if (!fan_control_allowed
)
4119 switch (fan_control_access_mode
) {
4120 case TPACPI_FAN_WR_ACPI_SFAN
:
4121 if (level
>= 0 && level
<= 7) {
4122 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4128 case TPACPI_FAN_WR_ACPI_FANS
:
4129 case TPACPI_FAN_WR_TPEC
:
4130 if ((level
!= TP_EC_FAN_AUTO
) &&
4131 (level
!= TP_EC_FAN_FULLSPEED
) &&
4132 ((level
< 0) || (level
> 7)))
4135 /* safety net should the EC not support AUTO
4136 * or FULLSPEED mode bits and just ignore them */
4137 if (level
& TP_EC_FAN_FULLSPEED
)
4138 level
|= 7; /* safety min speed 7 */
4139 else if (level
& TP_EC_FAN_FULLSPEED
)
4140 level
|= 4; /* safety min speed 4 */
4142 if (!acpi_ec_write(fan_status_offset
, level
))
4145 tp_features
.fan_ctrl_status_undef
= 0;
4154 static int fan_set_level_safe(int level
)
4158 if (!fan_control_allowed
)
4161 rc
= mutex_lock_interruptible(&fan_mutex
);
4165 if (level
== TPACPI_FAN_LAST_LEVEL
)
4166 level
= fan_control_desired_level
;
4168 rc
= fan_set_level(level
);
4170 fan_update_desired_level(level
);
4172 mutex_unlock(&fan_mutex
);
4176 static int fan_set_enable(void)
4181 if (!fan_control_allowed
)
4184 rc
= mutex_lock_interruptible(&fan_mutex
);
4188 switch (fan_control_access_mode
) {
4189 case TPACPI_FAN_WR_ACPI_FANS
:
4190 case TPACPI_FAN_WR_TPEC
:
4191 rc
= fan_get_status(&s
);
4195 /* Don't go out of emergency fan mode */
4198 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4201 if (!acpi_ec_write(fan_status_offset
, s
))
4204 tp_features
.fan_ctrl_status_undef
= 0;
4209 case TPACPI_FAN_WR_ACPI_SFAN
:
4210 rc
= fan_get_status(&s
);
4216 /* Set fan to at least level 4 */
4219 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4229 mutex_unlock(&fan_mutex
);
4233 static int fan_set_disable(void)
4237 if (!fan_control_allowed
)
4240 rc
= mutex_lock_interruptible(&fan_mutex
);
4245 switch (fan_control_access_mode
) {
4246 case TPACPI_FAN_WR_ACPI_FANS
:
4247 case TPACPI_FAN_WR_TPEC
:
4248 if (!acpi_ec_write(fan_status_offset
, 0x00))
4251 fan_control_desired_level
= 0;
4252 tp_features
.fan_ctrl_status_undef
= 0;
4256 case TPACPI_FAN_WR_ACPI_SFAN
:
4257 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4260 fan_control_desired_level
= 0;
4268 mutex_unlock(&fan_mutex
);
4272 static int fan_set_speed(int speed
)
4276 if (!fan_control_allowed
)
4279 rc
= mutex_lock_interruptible(&fan_mutex
);
4284 switch (fan_control_access_mode
) {
4285 case TPACPI_FAN_WR_ACPI_FANS
:
4286 if (speed
>= 0 && speed
<= 65535) {
4287 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4288 speed
, speed
, speed
))
4298 mutex_unlock(&fan_mutex
);
4302 static int fan_read(char *p
)
4307 unsigned int speed
= 0;
4309 switch (fan_status_access_mode
) {
4310 case TPACPI_FAN_RD_ACPI_GFAN
:
4311 /* 570, 600e/x, 770e, 770x */
4312 if ((rc
= fan_get_status_safe(&status
)) < 0)
4315 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
4317 (status
!= 0) ? "enabled" : "disabled", status
);
4320 case TPACPI_FAN_RD_TPEC
:
4321 /* all except 570, 600e/x, 770e, 770x */
4322 if ((rc
= fan_get_status_safe(&status
)) < 0)
4325 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4326 if (status
!= fan_control_initial_status
)
4327 tp_features
.fan_ctrl_status_undef
= 0;
4329 /* Return most likely status. In fact, it
4330 * might be the only possible status */
4331 status
= TP_EC_FAN_AUTO
;
4334 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4335 (status
!= 0) ? "enabled" : "disabled");
4337 if ((rc
= fan_get_speed(&speed
)) < 0)
4340 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
4342 if (status
& TP_EC_FAN_FULLSPEED
)
4343 /* Disengaged mode takes precedence */
4344 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
4345 else if (status
& TP_EC_FAN_AUTO
)
4346 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
4348 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
4351 case TPACPI_FAN_NONE
:
4353 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4356 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
4357 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
4359 switch (fan_control_access_mode
) {
4360 case TPACPI_FAN_WR_ACPI_SFAN
:
4361 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4365 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4366 "auto, disengaged, full-speed)\n");
4371 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4372 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4373 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4374 "1-120 (seconds))\n");
4376 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4377 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4378 " (<speed> is 0-65535)\n");
4383 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4387 if (strlencmp(cmd
, "level auto") == 0)
4388 level
= TP_EC_FAN_AUTO
;
4389 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4390 (strlencmp(cmd
, "level full-speed") == 0))
4391 level
= TP_EC_FAN_FULLSPEED
;
4392 else if (sscanf(cmd
, "level %d", &level
) != 1)
4395 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4396 printk(IBM_ERR
"level command accepted for unsupported "
4397 "access mode %d", fan_control_access_mode
);
4402 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4404 if (strlencmp(cmd
, "enable") != 0)
4407 if ((*rc
= fan_set_enable()) == -ENXIO
)
4408 printk(IBM_ERR
"enable command accepted for unsupported "
4409 "access mode %d", fan_control_access_mode
);
4414 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4416 if (strlencmp(cmd
, "disable") != 0)
4419 if ((*rc
= fan_set_disable()) == -ENXIO
)
4420 printk(IBM_ERR
"disable command accepted for unsupported "
4421 "access mode %d", fan_control_access_mode
);
4426 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4431 * Support speed <low> <medium> <high> ? */
4433 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4436 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4437 printk(IBM_ERR
"speed command accepted for unsupported "
4438 "access mode %d", fan_control_access_mode
);
4443 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4447 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4450 if (interval
< 0 || interval
> 120)
4453 fan_watchdog_maxinterval
= interval
;
4458 static int fan_write(char *buf
)
4463 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4464 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4465 fan_write_cmd_level(cmd
, &rc
)) &&
4466 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4467 (fan_write_cmd_enable(cmd
, &rc
) ||
4468 fan_write_cmd_disable(cmd
, &rc
) ||
4469 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4470 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4471 fan_write_cmd_speed(cmd
, &rc
))
4475 fan_watchdog_reset();
4481 static struct ibm_struct fan_driver_data
= {
4488 /****************************************************************************
4489 ****************************************************************************
4493 ****************************************************************************
4494 ****************************************************************************/
4496 /* sysfs name ---------------------------------------------------------- */
4497 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
4498 struct device_attribute
*attr
,
4501 return snprintf(buf
, PAGE_SIZE
, "%s\n", IBM_NAME
);
4504 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
4505 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
4507 /* --------------------------------------------------------------------- */
4510 static struct proc_dir_entry
*proc_dir
;
4512 /* Subdriver registry */
4513 static LIST_HEAD(tpacpi_all_drivers
);
4517 * Module and infrastructure proble, init and exit handling
4520 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4521 static const char * __init
str_supported(int is_supported
)
4523 static char text_unsupported
[] __initdata
= "not supported";
4525 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4527 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4529 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4532 struct ibm_struct
*ibm
= iibm
->data
;
4533 struct proc_dir_entry
*entry
;
4535 BUG_ON(ibm
== NULL
);
4537 INIT_LIST_HEAD(&ibm
->all_drivers
);
4539 if (ibm
->flags
.experimental
&& !experimental
)
4542 dbg_printk(TPACPI_DBG_INIT
,
4543 "probing for %s\n", ibm
->name
);
4546 ret
= iibm
->init(iibm
);
4548 return 0; /* probe failed */
4552 ibm
->flags
.init_called
= 1;
4556 if (ibm
->acpi
->hid
) {
4557 ret
= register_tpacpi_subdriver(ibm
);
4562 if (ibm
->acpi
->notify
) {
4563 ret
= setup_acpi_notify(ibm
);
4564 if (ret
== -ENODEV
) {
4565 printk(IBM_NOTICE
"disabling subdriver %s\n",
4575 dbg_printk(TPACPI_DBG_INIT
,
4576 "%s installed\n", ibm
->name
);
4579 entry
= create_proc_entry(ibm
->name
,
4580 S_IFREG
| S_IRUGO
| S_IWUSR
,
4583 printk(IBM_ERR
"unable to create proc entry %s\n",
4588 entry
->owner
= THIS_MODULE
;
4590 entry
->read_proc
= &dispatch_procfs_read
;
4592 entry
->write_proc
= &dispatch_procfs_write
;
4593 ibm
->flags
.proc_created
= 1;
4596 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4601 dbg_printk(TPACPI_DBG_INIT
,
4602 "%s: at error exit path with result %d\n",
4606 return (ret
< 0)? ret
: 0;
4609 static void ibm_exit(struct ibm_struct
*ibm
)
4611 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4613 list_del_init(&ibm
->all_drivers
);
4615 if (ibm
->flags
.acpi_notify_installed
) {
4616 dbg_printk(TPACPI_DBG_EXIT
,
4617 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4619 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4621 dispatch_acpi_notify
);
4622 ibm
->flags
.acpi_notify_installed
= 0;
4623 ibm
->flags
.acpi_notify_installed
= 0;
4626 if (ibm
->flags
.proc_created
) {
4627 dbg_printk(TPACPI_DBG_EXIT
,
4628 "%s: remove_proc_entry\n", ibm
->name
);
4629 remove_proc_entry(ibm
->name
, proc_dir
);
4630 ibm
->flags
.proc_created
= 0;
4633 if (ibm
->flags
.acpi_driver_registered
) {
4634 dbg_printk(TPACPI_DBG_EXIT
,
4635 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4637 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4638 kfree(ibm
->acpi
->driver
);
4639 ibm
->acpi
->driver
= NULL
;
4640 ibm
->flags
.acpi_driver_registered
= 0;
4643 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4645 ibm
->flags
.init_called
= 0;
4648 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4653 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
4655 struct dmi_device
*dev
= NULL
;
4656 char ec_fw_string
[18];
4661 memset(tp
, 0, sizeof(*tp
));
4663 if (dmi_name_in_vendors("IBM"))
4664 tp
->vendor
= PCI_VENDOR_ID_IBM
;
4665 else if (dmi_name_in_vendors("LENOVO"))
4666 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
4670 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
4672 if (!tp
->bios_version_str
)
4674 tp
->bios_model
= tp
->bios_version_str
[0]
4675 | (tp
->bios_version_str
[1] << 8);
4678 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4679 * X32 or newer, all Z series; Some models must have an
4680 * up-to-date BIOS or they will not be detected.
4682 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4684 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4685 if (sscanf(dev
->name
,
4686 "IBM ThinkPad Embedded Controller -[%17c",
4687 ec_fw_string
) == 1) {
4688 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4689 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4691 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
4692 tp
->ec_model
= ec_fw_string
[0]
4693 | (ec_fw_string
[1] << 8);
4698 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
4700 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
4701 kfree(tp
->model_str
);
4702 tp
->model_str
= NULL
;
4706 static int __init
probe_for_thinkpad(void)
4714 * Non-ancient models have better DMI tagging, but very old models
4717 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
4719 /* ec is required because many other handles are relative to it */
4720 IBM_ACPIHANDLE_INIT(ec
);
4724 "Not yet supported ThinkPad detected!\n");
4729 * Risks a regression on very old machines, but reduces potential
4730 * false positives a damn great deal
4733 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
4735 if (!is_thinkpad
&& !force_load
)
4742 /* Module init, exit, parameters */
4744 static struct ibm_init_struct ibms_init
[] __initdata
= {
4746 .init
= thinkpad_acpi_driver_init
,
4747 .data
= &thinkpad_acpi_driver_data
,
4750 .init
= hotkey_init
,
4751 .data
= &hotkey_driver_data
,
4754 .init
= bluetooth_init
,
4755 .data
= &bluetooth_driver_data
,
4759 .data
= &wan_driver_data
,
4763 .data
= &video_driver_data
,
4767 .data
= &light_driver_data
,
4769 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4772 .data
= &dock_driver_data
[0],
4776 .data
= &dock_driver_data
[1],
4779 #ifdef CONFIG_THINKPAD_ACPI_BAY
4782 .data
= &bay_driver_data
,
4787 .data
= &cmos_driver_data
,
4791 .data
= &led_driver_data
,
4795 .data
= &beep_driver_data
,
4798 .init
= thermal_init
,
4799 .data
= &thermal_driver_data
,
4802 .data
= &ecdump_driver_data
,
4805 .init
= brightness_init
,
4806 .data
= &brightness_driver_data
,
4809 .data
= &volume_driver_data
,
4813 .data
= &fan_driver_data
,
4817 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4820 struct ibm_struct
*ibm
;
4822 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4823 ibm
= ibms_init
[i
].data
;
4824 BUG_ON(ibm
== NULL
);
4826 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4827 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4829 strcpy(ibms_init
[i
].param
, val
);
4830 strcat(ibms_init
[i
].param
, ",");
4838 static int experimental
;
4839 module_param(experimental
, int, 0);
4841 static u32 dbg_level
;
4842 module_param_named(debug
, dbg_level
, uint
, 0);
4844 static int force_load
;
4845 module_param(force_load
, bool, 0);
4847 static int fan_control_allowed
;
4848 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
4850 static int brightness_mode
;
4851 module_param_named(brightness_mode
, brightness_mode
, int, 0);
4853 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
4854 module_param(brightness_enable
, uint
, 0);
4856 static unsigned int hotkey_report_mode
;
4857 module_param(hotkey_report_mode
, uint
, 0);
4859 #define IBM_PARAM(feature) \
4860 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4863 IBM_PARAM(bluetooth
);
4866 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4869 #ifdef CONFIG_THINKPAD_ACPI_BAY
4871 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4876 IBM_PARAM(brightness
);
4880 static int __init
thinkpad_acpi_module_init(void)
4884 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
4886 /* Parameter checking */
4887 if (hotkey_report_mode
> 2)
4890 /* Driver-level probe */
4892 get_thinkpad_model_data(&thinkpad_id
);
4893 ret
= probe_for_thinkpad();
4895 thinkpad_acpi_module_exit();
4899 /* Driver initialization */
4901 IBM_ACPIHANDLE_INIT(ecrd
);
4902 IBM_ACPIHANDLE_INIT(ecwr
);
4904 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4906 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4907 thinkpad_acpi_module_exit();
4910 proc_dir
->owner
= THIS_MODULE
;
4912 ret
= platform_driver_register(&tpacpi_pdriver
);
4914 printk(IBM_ERR
"unable to register main platform driver\n");
4915 thinkpad_acpi_module_exit();
4918 tp_features
.platform_drv_registered
= 1;
4920 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
4922 printk(IBM_ERR
"unable to register hwmon platform driver\n");
4923 thinkpad_acpi_module_exit();
4926 tp_features
.sensors_pdrv_registered
= 1;
4928 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4930 tp_features
.platform_drv_attrs_registered
= 1;
4931 ret
= tpacpi_create_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
4934 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4935 thinkpad_acpi_module_exit();
4938 tp_features
.sensors_pdrv_attrs_registered
= 1;
4941 /* Device initialization */
4942 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4944 if (IS_ERR(tpacpi_pdev
)) {
4945 ret
= PTR_ERR(tpacpi_pdev
);
4947 printk(IBM_ERR
"unable to register platform device\n");
4948 thinkpad_acpi_module_exit();
4951 tpacpi_sensors_pdev
= platform_device_register_simple(
4952 IBM_HWMON_DRVR_NAME
,
4954 if (IS_ERR(tpacpi_sensors_pdev
)) {
4955 ret
= PTR_ERR(tpacpi_sensors_pdev
);
4956 tpacpi_sensors_pdev
= NULL
;
4957 printk(IBM_ERR
"unable to register hwmon platform device\n");
4958 thinkpad_acpi_module_exit();
4961 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
4962 &dev_attr_thinkpad_acpi_pdev_name
);
4965 "unable to create sysfs hwmon device attributes\n");
4966 thinkpad_acpi_module_exit();
4969 tp_features
.sensors_pdev_attrs_registered
= 1;
4970 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
4971 if (IS_ERR(tpacpi_hwmon
)) {
4972 ret
= PTR_ERR(tpacpi_hwmon
);
4973 tpacpi_hwmon
= NULL
;
4974 printk(IBM_ERR
"unable to register hwmon device\n");
4975 thinkpad_acpi_module_exit();
4978 mutex_init(&tpacpi_inputdev_send_mutex
);
4979 tpacpi_inputdev
= input_allocate_device();
4980 if (!tpacpi_inputdev
) {
4981 printk(IBM_ERR
"unable to allocate input device\n");
4982 thinkpad_acpi_module_exit();
4985 /* Prepare input device, but don't register */
4986 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
4987 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
4988 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
4989 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
4990 thinkpad_id
.vendor
:
4992 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
4993 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
4995 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4996 ret
= ibm_init(&ibms_init
[i
]);
4997 if (ret
>= 0 && *ibms_init
[i
].param
)
4998 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
5000 thinkpad_acpi_module_exit();
5004 ret
= input_register_device(tpacpi_inputdev
);
5006 printk(IBM_ERR
"unable to register input device\n");
5007 thinkpad_acpi_module_exit();
5010 tp_features
.input_device_registered
= 1;
5013 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
5017 static void thinkpad_acpi_module_exit(void)
5019 struct ibm_struct
*ibm
, *itmp
;
5021 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
5023 list_for_each_entry_safe_reverse(ibm
, itmp
,
5024 &tpacpi_all_drivers
,
5029 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
5031 if (tpacpi_inputdev
) {
5032 if (tp_features
.input_device_registered
)
5033 input_unregister_device(tpacpi_inputdev
);
5035 input_free_device(tpacpi_inputdev
);
5039 hwmon_device_unregister(tpacpi_hwmon
);
5041 if (tp_features
.sensors_pdev_attrs_registered
)
5042 device_remove_file(&tpacpi_sensors_pdev
->dev
,
5043 &dev_attr_thinkpad_acpi_pdev_name
);
5044 if (tpacpi_sensors_pdev
)
5045 platform_device_unregister(tpacpi_sensors_pdev
);
5047 platform_device_unregister(tpacpi_pdev
);
5049 if (tp_features
.sensors_pdrv_attrs_registered
)
5050 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
5051 if (tp_features
.platform_drv_attrs_registered
)
5052 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
5054 if (tp_features
.sensors_pdrv_registered
)
5055 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
5057 if (tp_features
.platform_drv_registered
)
5058 platform_driver_unregister(&tpacpi_pdriver
);
5061 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
5063 kfree(thinkpad_id
.bios_version_str
);
5064 kfree(thinkpad_id
.ec_version_str
);
5065 kfree(thinkpad_id
.model_str
);
5068 module_init(thinkpad_acpi_module_init
);
5069 module_exit(thinkpad_acpi_module_exit
);