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.17"
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
;
424 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
426 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
428 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
430 kfree(ibm
->acpi
->driver
);
431 ibm
->acpi
->driver
= NULL
;
433 ibm
->flags
.acpi_driver_registered
= 1;
439 /****************************************************************************
440 ****************************************************************************
444 ****************************************************************************
445 ****************************************************************************/
447 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
448 int count
, int *eof
, void *data
)
450 struct ibm_struct
*ibm
= data
;
453 if (!ibm
|| !ibm
->read
)
456 len
= ibm
->read(page
);
460 if (len
<= off
+ count
)
472 static int dispatch_procfs_write(struct file
*file
,
473 const char __user
* userbuf
,
474 unsigned long count
, void *data
)
476 struct ibm_struct
*ibm
= data
;
480 if (!ibm
|| !ibm
->write
)
483 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
487 if (copy_from_user(kernbuf
, userbuf
, count
)) {
493 strcat(kernbuf
, ",");
494 ret
= ibm
->write(kernbuf
);
503 static char *next_cmd(char **cmds
)
508 while ((end
= strchr(start
, ',')) && end
== start
)
520 /****************************************************************************
521 ****************************************************************************
523 * Device model: input, hwmon and platform
525 ****************************************************************************
526 ****************************************************************************/
528 static struct platform_device
*tpacpi_pdev
;
529 static struct platform_device
*tpacpi_sensors_pdev
;
530 static struct class_device
*tpacpi_hwmon
;
531 static struct input_dev
*tpacpi_inputdev
;
532 static struct mutex tpacpi_inputdev_send_mutex
;
535 static int tpacpi_resume_handler(struct platform_device
*pdev
)
537 struct ibm_struct
*ibm
, *itmp
;
539 list_for_each_entry_safe(ibm
, itmp
,
549 static struct platform_driver tpacpi_pdriver
= {
551 .name
= IBM_DRVR_NAME
,
552 .owner
= THIS_MODULE
,
554 .resume
= tpacpi_resume_handler
,
557 static struct platform_driver tpacpi_hwmon_pdriver
= {
559 .name
= IBM_HWMON_DRVR_NAME
,
560 .owner
= THIS_MODULE
,
564 /*************************************************************************
565 * thinkpad-acpi driver attributes
568 /* interface_version --------------------------------------------------- */
569 static ssize_t
tpacpi_driver_interface_version_show(
570 struct device_driver
*drv
,
573 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
576 static DRIVER_ATTR(interface_version
, S_IRUGO
,
577 tpacpi_driver_interface_version_show
, NULL
);
579 /* debug_level --------------------------------------------------------- */
580 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
583 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
586 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
587 const char *buf
, size_t count
)
591 if (parse_strtoul(buf
, 0xffff, &t
))
599 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
600 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
602 /* version ------------------------------------------------------------- */
603 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
606 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
609 static DRIVER_ATTR(version
, S_IRUGO
,
610 tpacpi_driver_version_show
, NULL
);
612 /* --------------------------------------------------------------------- */
614 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
615 &driver_attr_debug_level
, &driver_attr_version
,
616 &driver_attr_interface_version
,
619 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
625 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
626 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
633 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
637 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
638 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
641 /*************************************************************************
642 * sysfs support helpers
645 struct attribute_set_obj
{
646 struct attribute_set s
;
648 } __attribute__((packed
));
650 static struct attribute_set
*create_attr_set(unsigned int max_members
,
653 struct attribute_set_obj
*sobj
;
655 if (max_members
== 0)
658 /* Allocates space for implicit NULL at the end too */
659 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
660 max_members
* sizeof(struct attribute
*),
664 sobj
->s
.max_members
= max_members
;
665 sobj
->s
.group
.attrs
= &sobj
->a
;
666 sobj
->s
.group
.name
= name
;
671 /* not multi-threaded safe, use it in a single thread per set */
672 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
677 if (s
->members
>= s
->max_members
)
680 s
->group
.attrs
[s
->members
] = attr
;
686 static int add_many_to_attr_set(struct attribute_set
* s
,
687 struct attribute
**attr
,
692 for (i
= 0; i
< count
; i
++) {
693 res
= add_to_attr_set(s
, attr
[i
]);
701 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
703 sysfs_remove_group(kobj
, &s
->group
);
707 static int parse_strtoul(const char *buf
,
708 unsigned long max
, unsigned long *value
)
712 while (*buf
&& isspace(*buf
))
714 *value
= simple_strtoul(buf
, &endp
, 0);
715 while (*endp
&& isspace(*endp
))
717 if (*endp
|| *value
> max
)
723 /****************************************************************************
724 ****************************************************************************
728 ****************************************************************************
729 ****************************************************************************/
731 /*************************************************************************
732 * thinkpad-acpi init subdriver
735 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
737 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
738 printk(IBM_INFO
"%s\n", IBM_URL
);
740 printk(IBM_INFO
"ThinkPad BIOS %s, EC %s\n",
741 (thinkpad_id
.bios_version_str
) ?
742 thinkpad_id
.bios_version_str
: "unknown",
743 (thinkpad_id
.ec_version_str
) ?
744 thinkpad_id
.ec_version_str
: "unknown");
746 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
747 printk(IBM_INFO
"%s %s\n",
748 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
749 "IBM" : ((thinkpad_id
.vendor
==
750 PCI_VENDOR_ID_LENOVO
) ?
751 "Lenovo" : "Unknown vendor"),
752 thinkpad_id
.model_str
);
757 static int thinkpad_acpi_driver_read(char *p
)
761 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
762 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
767 static struct ibm_struct thinkpad_acpi_driver_data
= {
769 .read
= thinkpad_acpi_driver_read
,
772 /*************************************************************************
776 static int hotkey_orig_status
;
777 static u32 hotkey_orig_mask
;
778 static u32 hotkey_all_mask
;
779 static u32 hotkey_reserved_mask
;
781 static u16
*hotkey_keycode_map
;
783 static struct attribute_set
*hotkey_dev_attributes
;
785 static int hotkey_get_wlsw(int *status
)
787 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
792 /* sysfs hotkey enable ------------------------------------------------- */
793 static ssize_t
hotkey_enable_show(struct device
*dev
,
794 struct device_attribute
*attr
,
800 res
= hotkey_get(&status
, &mask
);
804 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
807 static ssize_t
hotkey_enable_store(struct device
*dev
,
808 struct device_attribute
*attr
,
809 const char *buf
, size_t count
)
815 if (parse_strtoul(buf
, 1, &t
))
818 res
= hotkey_get(&status
, &mask
);
820 res
= hotkey_set(t
, mask
);
822 return (res
) ? res
: count
;
825 static struct device_attribute dev_attr_hotkey_enable
=
826 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
827 hotkey_enable_show
, hotkey_enable_store
);
829 /* sysfs hotkey mask --------------------------------------------------- */
830 static ssize_t
hotkey_mask_show(struct device
*dev
,
831 struct device_attribute
*attr
,
837 res
= hotkey_get(&status
, &mask
);
841 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
844 static ssize_t
hotkey_mask_store(struct device
*dev
,
845 struct device_attribute
*attr
,
846 const char *buf
, size_t count
)
852 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
855 res
= hotkey_get(&status
, &mask
);
857 hotkey_set(status
, t
);
859 return (res
) ? res
: count
;
862 static struct device_attribute dev_attr_hotkey_mask
=
863 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
864 hotkey_mask_show
, hotkey_mask_store
);
866 /* sysfs hotkey bios_enabled ------------------------------------------- */
867 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
868 struct device_attribute
*attr
,
871 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
874 static struct device_attribute dev_attr_hotkey_bios_enabled
=
875 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
877 /* sysfs hotkey bios_mask ---------------------------------------------- */
878 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
879 struct device_attribute
*attr
,
882 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
885 static struct device_attribute dev_attr_hotkey_bios_mask
=
886 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
888 /* sysfs hotkey all_mask ----------------------------------------------- */
889 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
890 struct device_attribute
*attr
,
893 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_all_mask
);
896 static struct device_attribute dev_attr_hotkey_all_mask
=
897 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
899 /* sysfs hotkey recommended_mask --------------------------------------- */
900 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
901 struct device_attribute
*attr
,
904 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
905 hotkey_all_mask
& ~hotkey_reserved_mask
);
908 static struct device_attribute dev_attr_hotkey_recommended_mask
=
909 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
910 hotkey_recommended_mask_show
, NULL
);
912 /* sysfs hotkey radio_sw ----------------------------------------------- */
913 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
914 struct device_attribute
*attr
,
918 res
= hotkey_get_wlsw(&s
);
922 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
925 static struct device_attribute dev_attr_hotkey_radio_sw
=
926 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
928 /* sysfs hotkey report_mode -------------------------------------------- */
929 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
930 struct device_attribute
*attr
,
933 return snprintf(buf
, PAGE_SIZE
, "%d\n",
934 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
937 static struct device_attribute dev_attr_hotkey_report_mode
=
938 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
940 /* --------------------------------------------------------------------- */
942 static struct attribute
*hotkey_attributes
[] __initdata
= {
943 &dev_attr_hotkey_enable
.attr
,
944 &dev_attr_hotkey_report_mode
.attr
,
947 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
948 &dev_attr_hotkey_mask
.attr
,
949 &dev_attr_hotkey_bios_enabled
.attr
,
950 &dev_attr_hotkey_bios_mask
.attr
,
951 &dev_attr_hotkey_all_mask
.attr
,
952 &dev_attr_hotkey_recommended_mask
.attr
,
955 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
957 /* Requirements for changing the default keymaps:
959 * 1. Many of the keys are mapped to KEY_RESERVED for very
960 * good reasons. Do not change them unless you have deep
961 * knowledge on the IBM and Lenovo ThinkPad firmware for
962 * the various ThinkPad models. The driver behaves
963 * differently for KEY_RESERVED: such keys have their
964 * hot key mask *unset* in mask_recommended, and also
965 * in the initial hot key mask programmed into the
966 * firmware at driver load time, which means the firm-
967 * ware may react very differently if you change them to
970 * 2. You must be subscribed to the linux-thinkpad and
971 * ibm-acpi-devel mailing lists, and you should read the
972 * list archives since 2007 if you want to change the
973 * keymaps. This requirement exists so that you will
974 * know the past history of problems with the thinkpad-
975 * acpi driver keymaps, and also that you will be
976 * listening to any bug reports;
978 * 3. Do not send thinkpad-acpi specific patches directly to
979 * for merging, *ever*. Send them to the linux-acpi
980 * mailinglist for comments. Merging is to be done only
981 * through acpi-test and the ACPI maintainer.
983 * If the above is too much to ask, don't change the keymap.
984 * Ask the thinkpad-acpi maintainer to do it, instead.
986 static u16 ibm_keycode_map
[] __initdata
= {
987 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
988 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
989 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
990 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
992 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
993 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
994 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
995 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
997 /* brightness: firmware always reacts to them, unless
998 * X.org did some tricks in the radeon BIOS scratch
999 * registers of *some* models */
1000 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1001 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1003 /* Thinklight: firmware always react to it */
1004 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1006 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1007 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1009 /* Volume: firmware always react to it and reprograms
1010 * the built-in *extra* mixer. Never map it to control
1011 * another mixer by default. */
1012 KEY_RESERVED
, /* 0x14: VOLUME UP */
1013 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1014 KEY_RESERVED
, /* 0x16: MUTE */
1016 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1018 /* (assignments unknown, please report if found) */
1019 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1020 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1022 static u16 lenovo_keycode_map
[] __initdata
= {
1023 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1024 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1025 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1026 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1028 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1029 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1030 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1031 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1033 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1034 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1036 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1038 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1039 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1041 /* Volume: z60/z61, T60 (BIOS version?): firmware always
1042 * react to it and reprograms the built-in *extra* mixer.
1043 * Never map it to control another mixer by default.
1045 * T60?, T61, R60?, R61: firmware and EC tries to send
1046 * these over the regular keyboard, so these are no-ops,
1047 * but there are still weird bugs re. MUTE, so do not
1048 * change unless you get test reports from all Lenovo
1049 * models. May cause the BIOS to interfere with the
1052 KEY_RESERVED
, /* 0x14: VOLUME UP */
1053 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1054 KEY_RESERVED
, /* 0x16: MUTE */
1056 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1058 /* (assignments unknown, please report if found) */
1059 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1060 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1063 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1064 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1065 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1071 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1073 BUG_ON(!tpacpi_inputdev
);
1075 IBM_ACPIHANDLE_INIT(hkey
);
1076 mutex_init(&hotkey_mutex
);
1078 /* hotkey not supported on 570 */
1079 tp_features
.hotkey
= hkey_handle
!= NULL
;
1081 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1082 str_supported(tp_features
.hotkey
));
1084 if (tp_features
.hotkey
) {
1085 hotkey_dev_attributes
= create_attr_set(8, NULL
);
1086 if (!hotkey_dev_attributes
)
1088 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1090 ARRAY_SIZE(hotkey_attributes
));
1094 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1095 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1096 for HKEY interface version 0x100 */
1097 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1098 if ((hkeyv
>> 8) != 1) {
1099 printk(IBM_ERR
"unknown version of the "
1100 "HKEY interface: 0x%x\n", hkeyv
);
1101 printk(IBM_ERR
"please report this to %s\n",
1105 * MHKV 0x100 in A31, R40, R40e,
1106 * T4x, X31, and later
1108 tp_features
.hotkey_mask
= 1;
1112 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1113 str_supported(tp_features
.hotkey_mask
));
1115 if (tp_features
.hotkey_mask
) {
1116 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1119 "missing MHKA handler, "
1120 "please report this to %s\n",
1122 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
1126 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
1127 if (!res
&& tp_features
.hotkey_mask
) {
1128 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1129 hotkey_mask_attributes
,
1130 ARRAY_SIZE(hotkey_mask_attributes
));
1133 /* Not all thinkpads have a hardware radio switch */
1134 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1135 tp_features
.hotkey_wlsw
= 1;
1137 "radio switch found; radios are %s\n",
1138 enabled(status
, 0));
1139 res
= add_to_attr_set(hotkey_dev_attributes
,
1140 &dev_attr_hotkey_radio_sw
.attr
);
1144 res
= register_attr_set_with_sysfs(
1145 hotkey_dev_attributes
,
1146 &tpacpi_pdev
->dev
.kobj
);
1150 /* Set up key map */
1152 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1154 if (!hotkey_keycode_map
) {
1155 printk(IBM_ERR
"failed to allocate memory for key map\n");
1159 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1160 dbg_printk(TPACPI_DBG_INIT
,
1161 "using Lenovo default hot key map\n");
1162 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1163 TPACPI_HOTKEY_MAP_SIZE
);
1165 dbg_printk(TPACPI_DBG_INIT
,
1166 "using IBM default hot key map\n");
1167 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1168 TPACPI_HOTKEY_MAP_SIZE
);
1171 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1172 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1173 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1174 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1175 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1176 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1177 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1178 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1179 set_bit(hotkey_keycode_map
[i
],
1180 tpacpi_inputdev
->keybit
);
1182 if (i
< sizeof(hotkey_reserved_mask
)*8)
1183 hotkey_reserved_mask
|= 1 << i
;
1187 if (tp_features
.hotkey_wlsw
) {
1188 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1189 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1192 dbg_printk(TPACPI_DBG_INIT
,
1193 "enabling hot key handling\n");
1194 res
= hotkey_set(1, (hotkey_all_mask
& ~hotkey_reserved_mask
)
1195 | hotkey_orig_mask
);
1199 dbg_printk(TPACPI_DBG_INIT
,
1200 "legacy hot key reporting over procfs %s\n",
1201 (hotkey_report_mode
< 2) ?
1202 "enabled" : "disabled");
1205 return (tp_features
.hotkey
)? 0 : 1;
1208 static void hotkey_exit(void)
1212 if (tp_features
.hotkey
) {
1213 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
1214 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
1216 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
1219 if (hotkey_dev_attributes
) {
1220 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1221 hotkey_dev_attributes
= NULL
;
1225 static void tpacpi_input_send_key(unsigned int scancode
,
1226 unsigned int keycode
)
1228 if (keycode
!= KEY_RESERVED
) {
1229 mutex_lock(&tpacpi_inputdev_send_mutex
);
1231 input_report_key(tpacpi_inputdev
, keycode
, 1);
1232 if (keycode
== KEY_UNKNOWN
)
1233 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1235 input_sync(tpacpi_inputdev
);
1237 input_report_key(tpacpi_inputdev
, keycode
, 0);
1238 if (keycode
== KEY_UNKNOWN
)
1239 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1241 input_sync(tpacpi_inputdev
);
1243 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1247 static void tpacpi_input_send_radiosw(void)
1251 mutex_lock(&tpacpi_inputdev_send_mutex
);
1253 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1254 input_report_switch(tpacpi_inputdev
,
1256 input_sync(tpacpi_inputdev
);
1259 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1262 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1265 unsigned int keycode
, scancode
;
1269 if (event
!= 0x80) {
1270 printk(IBM_ERR
"unknown HKEY notification event %d\n", event
);
1271 /* forward it to userspace, maybe it knows how to handle it */
1272 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
1273 ibm
->acpi
->device
->dev
.bus_id
,
1279 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1280 printk(IBM_ERR
"failed to retrieve HKEY event\n");
1292 switch (hkey
>> 12) {
1294 /* 0x1000-0x1FFF: key presses */
1295 scancode
= hkey
& 0xfff;
1296 if (scancode
> 0 && scancode
< 0x21) {
1298 keycode
= hotkey_keycode_map
[scancode
];
1299 tpacpi_input_send_key(scancode
, keycode
);
1302 "hotkey 0x%04x out of range for keyboard map\n",
1308 /* 0x5000-0x5FFF: LID */
1309 /* we don't handle it through this path, just
1310 * eat up known LID events */
1311 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1313 "unknown LID-related HKEY event: 0x%04x\n",
1321 /* 0x7000-0x7FFF: misc */
1322 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1323 tpacpi_input_send_radiosw();
1326 /* fallthrough to default */
1328 /* case 2: dock-related */
1329 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1330 /* case 3: ultra-bay related. maybe bay in dock? */
1331 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1332 printk(IBM_NOTICE
"unhandled HKEY event 0x%04x\n", hkey
);
1337 if (!ignore_acpi_ev
&& (send_acpi_ev
|| hotkey_report_mode
< 2)) {
1338 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, hkey
);
1341 /* netlink events */
1342 if (!ignore_acpi_ev
&& send_acpi_ev
) {
1343 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
1344 ibm
->acpi
->device
->dev
.bus_id
,
1350 static void hotkey_resume(void)
1352 tpacpi_input_send_radiosw();
1356 * Call with hotkey_mutex held
1358 static int hotkey_get(int *status
, u32
*mask
)
1360 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1363 if (tp_features
.hotkey_mask
)
1364 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1371 * Call with hotkey_mutex held
1373 static int hotkey_set(int status
, u32 mask
)
1377 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1380 if (tp_features
.hotkey_mask
)
1381 for (i
= 0; i
< 32; i
++) {
1382 int bit
= ((1 << i
) & mask
) != 0;
1383 if (!acpi_evalf(hkey_handle
,
1384 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1391 /* procfs -------------------------------------------------------------- */
1392 static int hotkey_read(char *p
)
1398 if (!tp_features
.hotkey
) {
1399 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1403 if (mutex_lock_interruptible(&hotkey_mutex
))
1404 return -ERESTARTSYS
;
1405 res
= hotkey_get(&status
, &mask
);
1406 mutex_unlock(&hotkey_mutex
);
1410 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1411 if (tp_features
.hotkey_mask
) {
1412 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1413 len
+= sprintf(p
+ len
,
1414 "commands:\tenable, disable, reset, <mask>\n");
1416 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1417 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1423 static int hotkey_write(char *buf
)
1430 if (!tp_features
.hotkey
)
1433 if (mutex_lock_interruptible(&hotkey_mutex
))
1434 return -ERESTARTSYS
;
1436 res
= hotkey_get(&status
, &mask
);
1441 while ((cmd
= next_cmd(&buf
))) {
1442 if (strlencmp(cmd
, "enable") == 0) {
1444 } else if (strlencmp(cmd
, "disable") == 0) {
1446 } else if (strlencmp(cmd
, "reset") == 0) {
1447 status
= hotkey_orig_status
;
1448 mask
= hotkey_orig_mask
;
1449 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1451 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1461 res
= hotkey_set(status
, mask
);
1464 mutex_unlock(&hotkey_mutex
);
1468 static const struct acpi_device_id ibm_htk_device_ids
[] = {
1473 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1474 .hid
= ibm_htk_device_ids
,
1475 .notify
= hotkey_notify
,
1476 .handle
= &hkey_handle
,
1477 .type
= ACPI_DEVICE_NOTIFY
,
1480 static struct ibm_struct hotkey_driver_data
= {
1482 .read
= hotkey_read
,
1483 .write
= hotkey_write
,
1484 .exit
= hotkey_exit
,
1485 .resume
= hotkey_resume
,
1486 .acpi
= &ibm_hotkey_acpidriver
,
1489 /*************************************************************************
1490 * Bluetooth subdriver
1493 /* sysfs bluetooth enable ---------------------------------------------- */
1494 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1495 struct device_attribute
*attr
,
1500 status
= bluetooth_get_radiosw();
1504 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1507 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1508 struct device_attribute
*attr
,
1509 const char *buf
, size_t count
)
1514 if (parse_strtoul(buf
, 1, &t
))
1517 res
= bluetooth_set_radiosw(t
);
1519 return (res
) ? res
: count
;
1522 static struct device_attribute dev_attr_bluetooth_enable
=
1523 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1524 bluetooth_enable_show
, bluetooth_enable_store
);
1526 /* --------------------------------------------------------------------- */
1528 static struct attribute
*bluetooth_attributes
[] = {
1529 &dev_attr_bluetooth_enable
.attr
,
1533 static const struct attribute_group bluetooth_attr_group
= {
1534 .attrs
= bluetooth_attributes
,
1537 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1542 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1544 IBM_ACPIHANDLE_INIT(hkey
);
1546 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1547 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1548 tp_features
.bluetooth
= hkey_handle
&&
1549 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1551 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1552 str_supported(tp_features
.bluetooth
),
1555 if (tp_features
.bluetooth
) {
1556 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1557 /* no bluetooth hardware present in system */
1558 tp_features
.bluetooth
= 0;
1559 dbg_printk(TPACPI_DBG_INIT
,
1560 "bluetooth hardware not installed\n");
1562 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1563 &bluetooth_attr_group
);
1569 return (tp_features
.bluetooth
)? 0 : 1;
1572 static void bluetooth_exit(void)
1574 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1575 &bluetooth_attr_group
);
1578 static int bluetooth_get_radiosw(void)
1582 if (!tp_features
.bluetooth
)
1585 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1588 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1591 static int bluetooth_set_radiosw(int radio_on
)
1595 if (!tp_features
.bluetooth
)
1598 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1601 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1603 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1604 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1610 /* procfs -------------------------------------------------------------- */
1611 static int bluetooth_read(char *p
)
1614 int status
= bluetooth_get_radiosw();
1616 if (!tp_features
.bluetooth
)
1617 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1619 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1620 (status
)? "enabled" : "disabled");
1621 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1627 static int bluetooth_write(char *buf
)
1631 if (!tp_features
.bluetooth
)
1634 while ((cmd
= next_cmd(&buf
))) {
1635 if (strlencmp(cmd
, "enable") == 0) {
1636 bluetooth_set_radiosw(1);
1637 } else if (strlencmp(cmd
, "disable") == 0) {
1638 bluetooth_set_radiosw(0);
1646 static struct ibm_struct bluetooth_driver_data
= {
1647 .name
= "bluetooth",
1648 .read
= bluetooth_read
,
1649 .write
= bluetooth_write
,
1650 .exit
= bluetooth_exit
,
1653 /*************************************************************************
1657 /* sysfs wan enable ---------------------------------------------------- */
1658 static ssize_t
wan_enable_show(struct device
*dev
,
1659 struct device_attribute
*attr
,
1664 status
= wan_get_radiosw();
1668 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1671 static ssize_t
wan_enable_store(struct device
*dev
,
1672 struct device_attribute
*attr
,
1673 const char *buf
, size_t count
)
1678 if (parse_strtoul(buf
, 1, &t
))
1681 res
= wan_set_radiosw(t
);
1683 return (res
) ? res
: count
;
1686 static struct device_attribute dev_attr_wan_enable
=
1687 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1688 wan_enable_show
, wan_enable_store
);
1690 /* --------------------------------------------------------------------- */
1692 static struct attribute
*wan_attributes
[] = {
1693 &dev_attr_wan_enable
.attr
,
1697 static const struct attribute_group wan_attr_group
= {
1698 .attrs
= wan_attributes
,
1701 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1706 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1708 IBM_ACPIHANDLE_INIT(hkey
);
1710 tp_features
.wan
= hkey_handle
&&
1711 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1713 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1714 str_supported(tp_features
.wan
),
1717 if (tp_features
.wan
) {
1718 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1719 /* no wan hardware present in system */
1720 tp_features
.wan
= 0;
1721 dbg_printk(TPACPI_DBG_INIT
,
1722 "wan hardware not installed\n");
1724 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1731 return (tp_features
.wan
)? 0 : 1;
1734 static void wan_exit(void)
1736 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1740 static int wan_get_radiosw(void)
1744 if (!tp_features
.wan
)
1747 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1750 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1753 static int wan_set_radiosw(int radio_on
)
1757 if (!tp_features
.wan
)
1760 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1763 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1765 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1766 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1772 /* procfs -------------------------------------------------------------- */
1773 static int wan_read(char *p
)
1776 int status
= wan_get_radiosw();
1778 if (!tp_features
.wan
)
1779 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1781 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1782 (status
)? "enabled" : "disabled");
1783 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1789 static int wan_write(char *buf
)
1793 if (!tp_features
.wan
)
1796 while ((cmd
= next_cmd(&buf
))) {
1797 if (strlencmp(cmd
, "enable") == 0) {
1799 } else if (strlencmp(cmd
, "disable") == 0) {
1808 static struct ibm_struct wan_driver_data
= {
1813 .flags
.experimental
= 1,
1816 /*************************************************************************
1820 static enum video_access_mode video_supported
;
1821 static int video_orig_autosw
;
1823 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1824 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1825 "\\_SB.PCI0.VID0", /* 770e */
1826 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1827 "\\_SB.PCI0.AGP.VID", /* all others */
1830 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1832 static int __init
video_init(struct ibm_init_struct
*iibm
)
1836 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1838 IBM_ACPIHANDLE_INIT(vid
);
1839 IBM_ACPIHANDLE_INIT(vid2
);
1841 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1842 /* G41, assume IVGA doesn't change */
1843 vid_handle
= vid2_handle
;
1846 /* video switching not supported on R30, R31 */
1847 video_supported
= TPACPI_VIDEO_NONE
;
1848 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1850 video_supported
= TPACPI_VIDEO_570
;
1851 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1852 /* 600e/x, 770e, 770x */
1853 video_supported
= TPACPI_VIDEO_770
;
1856 video_supported
= TPACPI_VIDEO_NEW
;
1858 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1859 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1862 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1865 static void video_exit(void)
1867 dbg_printk(TPACPI_DBG_EXIT
,
1868 "restoring original video autoswitch mode\n");
1869 if (video_autosw_set(video_orig_autosw
))
1870 printk(IBM_ERR
"error while trying to restore original "
1871 "video autoswitch mode\n");
1874 static int video_outputsw_get(void)
1879 switch (video_supported
) {
1880 case TPACPI_VIDEO_570
:
1881 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1882 TP_ACPI_VIDEO_570_PHSCMD
))
1884 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1886 case TPACPI_VIDEO_770
:
1887 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1890 status
|= TP_ACPI_VIDEO_S_LCD
;
1891 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1894 status
|= TP_ACPI_VIDEO_S_CRT
;
1896 case TPACPI_VIDEO_NEW
:
1897 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1898 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1901 status
|= TP_ACPI_VIDEO_S_CRT
;
1903 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1904 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1907 status
|= TP_ACPI_VIDEO_S_LCD
;
1908 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1911 status
|= TP_ACPI_VIDEO_S_DVI
;
1920 static int video_outputsw_set(int status
)
1925 switch (video_supported
) {
1926 case TPACPI_VIDEO_570
:
1927 res
= acpi_evalf(NULL
, NULL
,
1928 "\\_SB.PHS2", "vdd",
1929 TP_ACPI_VIDEO_570_PHS2CMD
,
1930 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1932 case TPACPI_VIDEO_770
:
1933 autosw
= video_autosw_get();
1937 res
= video_autosw_set(1);
1940 res
= acpi_evalf(vid_handle
, NULL
,
1941 "ASWT", "vdd", status
* 0x100, 0);
1942 if (!autosw
&& video_autosw_set(autosw
)) {
1943 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1947 case TPACPI_VIDEO_NEW
:
1948 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1949 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1955 return (res
)? 0 : -EIO
;
1958 static int video_autosw_get(void)
1962 switch (video_supported
) {
1963 case TPACPI_VIDEO_570
:
1964 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1967 case TPACPI_VIDEO_770
:
1968 case TPACPI_VIDEO_NEW
:
1969 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1979 static int video_autosw_set(int enable
)
1981 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1986 static int video_outputsw_cycle(void)
1988 int autosw
= video_autosw_get();
1994 switch (video_supported
) {
1995 case TPACPI_VIDEO_570
:
1996 res
= video_autosw_set(1);
1999 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
2001 case TPACPI_VIDEO_770
:
2002 case TPACPI_VIDEO_NEW
:
2003 res
= video_autosw_set(1);
2006 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
2011 if (!autosw
&& video_autosw_set(autosw
)) {
2012 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
2016 return (res
)? 0 : -EIO
;
2019 static int video_expand_toggle(void)
2021 switch (video_supported
) {
2022 case TPACPI_VIDEO_570
:
2023 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
2025 case TPACPI_VIDEO_770
:
2026 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
2028 case TPACPI_VIDEO_NEW
:
2029 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
2037 static int video_read(char *p
)
2042 if (video_supported
== TPACPI_VIDEO_NONE
) {
2043 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2047 status
= video_outputsw_get();
2051 autosw
= video_autosw_get();
2055 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2056 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2057 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2058 if (video_supported
== TPACPI_VIDEO_NEW
)
2059 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2060 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2061 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2062 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2063 if (video_supported
== TPACPI_VIDEO_NEW
)
2064 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2065 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2066 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2071 static int video_write(char *buf
)
2074 int enable
, disable
, status
;
2077 if (video_supported
== TPACPI_VIDEO_NONE
)
2083 while ((cmd
= next_cmd(&buf
))) {
2084 if (strlencmp(cmd
, "lcd_enable") == 0) {
2085 enable
|= TP_ACPI_VIDEO_S_LCD
;
2086 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2087 disable
|= TP_ACPI_VIDEO_S_LCD
;
2088 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2089 enable
|= TP_ACPI_VIDEO_S_CRT
;
2090 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2091 disable
|= TP_ACPI_VIDEO_S_CRT
;
2092 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2093 strlencmp(cmd
, "dvi_enable") == 0) {
2094 enable
|= TP_ACPI_VIDEO_S_DVI
;
2095 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2096 strlencmp(cmd
, "dvi_disable") == 0) {
2097 disable
|= TP_ACPI_VIDEO_S_DVI
;
2098 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2099 res
= video_autosw_set(1);
2102 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2103 res
= video_autosw_set(0);
2106 } else if (strlencmp(cmd
, "video_switch") == 0) {
2107 res
= video_outputsw_cycle();
2110 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2111 res
= video_expand_toggle();
2118 if (enable
|| disable
) {
2119 status
= video_outputsw_get();
2122 res
= video_outputsw_set((status
& ~disable
) | enable
);
2130 static struct ibm_struct video_driver_data
= {
2133 .write
= video_write
,
2137 /*************************************************************************
2138 * Light (thinklight) subdriver
2141 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2142 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2144 static int __init
light_init(struct ibm_init_struct
*iibm
)
2146 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2148 IBM_ACPIHANDLE_INIT(ledb
);
2149 IBM_ACPIHANDLE_INIT(lght
);
2150 IBM_ACPIHANDLE_INIT(cmos
);
2152 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2153 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2155 if (tp_features
.light
)
2156 /* light status not supported on
2157 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2158 tp_features
.light_status
=
2159 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2161 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2162 str_supported(tp_features
.light
));
2164 return (tp_features
.light
)? 0 : 1;
2167 static int light_read(char *p
)
2172 if (!tp_features
.light
) {
2173 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2174 } else if (!tp_features
.light_status
) {
2175 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2176 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2178 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2180 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2181 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2187 static int light_write(char *buf
)
2189 int cmos_cmd
, lght_cmd
;
2193 if (!tp_features
.light
)
2196 while ((cmd
= next_cmd(&buf
))) {
2197 if (strlencmp(cmd
, "on") == 0) {
2200 } else if (strlencmp(cmd
, "off") == 0) {
2206 success
= cmos_handle
?
2207 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2208 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2216 static struct ibm_struct light_driver_data
= {
2219 .write
= light_write
,
2222 /*************************************************************************
2226 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2228 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2229 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2230 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2231 "\\_SB.PCI.ISA.SLCE", /* 570 */
2232 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2234 /* don't list other alternatives as we install a notify handler on the 570 */
2235 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2237 static const struct acpi_device_id ibm_pci_device_ids
[] = {
2238 {PCI_ROOT_HID_STRING
, 0},
2242 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2244 .notify
= dock_notify
,
2245 .handle
= &dock_handle
,
2246 .type
= ACPI_SYSTEM_NOTIFY
,
2249 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2250 * We just use it to get notifications of dock hotplug
2251 * in very old thinkpads */
2252 .hid
= ibm_pci_device_ids
,
2253 .notify
= dock_notify
,
2254 .handle
= &pci_handle
,
2255 .type
= ACPI_SYSTEM_NOTIFY
,
2259 static struct ibm_struct dock_driver_data
[2] = {
2263 .write
= dock_write
,
2264 .acpi
= &ibm_dock_acpidriver
[0],
2268 .acpi
= &ibm_dock_acpidriver
[1],
2272 #define dock_docked() (_sta(dock_handle) & 1)
2274 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2276 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2278 IBM_ACPIHANDLE_INIT(dock
);
2280 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2281 str_supported(dock_handle
!= NULL
));
2283 return (dock_handle
)? 0 : 1;
2286 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2290 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2292 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2293 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2294 IBM_ACPIHANDLE_INIT(pci
);
2295 dock2_needed
= (pci_handle
!= NULL
);
2296 vdbg_printk(TPACPI_DBG_INIT
,
2297 "dock PCI handler for the TP 570 is %s\n",
2298 str_supported(dock2_needed
));
2300 vdbg_printk(TPACPI_DBG_INIT
,
2301 "dock subdriver part 2 not required\n");
2305 return (dock2_needed
)? 0 : 1;
2308 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2310 int docked
= dock_docked();
2311 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
2312 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
2315 if (event
== 1 && !pci
) /* 570 */
2316 data
= 1; /* button */
2317 else if (event
== 1 && pci
) /* 570 */
2318 data
= 3; /* dock */
2319 else if (event
== 3 && docked
)
2320 data
= 1; /* button */
2321 else if (event
== 3 && !docked
)
2322 data
= 2; /* undock */
2323 else if (event
== 0 && docked
)
2324 data
= 3; /* dock */
2326 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2327 event
, _sta(dock_handle
));
2328 data
= 0; /* unknown */
2330 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
2331 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
2332 ibm
->acpi
->device
->dev
.bus_id
,
2336 static int dock_read(char *p
)
2339 int docked
= dock_docked();
2342 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2344 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2346 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2347 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2353 static int dock_write(char *buf
)
2360 while ((cmd
= next_cmd(&buf
))) {
2361 if (strlencmp(cmd
, "undock") == 0) {
2362 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2363 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2365 } else if (strlencmp(cmd
, "dock") == 0) {
2366 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2375 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2377 /*************************************************************************
2381 #ifdef CONFIG_THINKPAD_ACPI_BAY
2382 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2383 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2384 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2385 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2386 ); /* A21e, R30, R31 */
2387 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2388 "_EJ0", /* all others */
2389 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2390 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2391 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2393 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2397 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2399 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2401 IBM_ACPIHANDLE_INIT(bay
);
2403 IBM_ACPIHANDLE_INIT(bay_ej
);
2404 IBM_ACPIHANDLE_INIT(bay2
);
2406 IBM_ACPIHANDLE_INIT(bay2_ej
);
2408 tp_features
.bay_status
= bay_handle
&&
2409 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2410 tp_features
.bay_status2
= bay2_handle
&&
2411 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2413 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2414 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2415 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2416 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2418 vdbg_printk(TPACPI_DBG_INIT
,
2419 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2420 str_supported(tp_features
.bay_status
),
2421 str_supported(tp_features
.bay_eject
),
2422 str_supported(tp_features
.bay_status2
),
2423 str_supported(tp_features
.bay_eject2
));
2425 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2426 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2429 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2431 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
2432 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
2433 ibm
->acpi
->device
->dev
.bus_id
,
2437 #define bay_occupied(b) (_sta(b##_handle) & 1)
2439 static int bay_read(char *p
)
2442 int occupied
= bay_occupied(bay
);
2443 int occupied2
= bay_occupied(bay2
);
2446 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2447 tp_features
.bay_status
?
2448 (occupied
? "occupied" : "unoccupied") :
2450 if (tp_features
.bay_status2
)
2451 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2452 "occupied" : "unoccupied");
2454 eject
= tp_features
.bay_eject
&& occupied
;
2455 eject2
= tp_features
.bay_eject2
&& occupied2
;
2457 if (eject
&& eject2
)
2458 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2460 len
+= sprintf(p
+ len
, "commands:\teject\n");
2462 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2467 static int bay_write(char *buf
)
2471 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2474 while ((cmd
= next_cmd(&buf
))) {
2475 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2476 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2478 } else if (tp_features
.bay_eject2
&&
2479 strlencmp(cmd
, "eject2") == 0) {
2480 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2489 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2490 .notify
= bay_notify
,
2491 .handle
= &bay_handle
,
2492 .type
= ACPI_SYSTEM_NOTIFY
,
2495 static struct ibm_struct bay_driver_data
= {
2499 .acpi
= &ibm_bay_acpidriver
,
2502 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2504 /*************************************************************************
2508 /* sysfs cmos_command -------------------------------------------------- */
2509 static ssize_t
cmos_command_store(struct device
*dev
,
2510 struct device_attribute
*attr
,
2511 const char *buf
, size_t count
)
2513 unsigned long cmos_cmd
;
2516 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2519 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2520 return (res
)? res
: count
;
2523 static struct device_attribute dev_attr_cmos_command
=
2524 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2526 /* --------------------------------------------------------------------- */
2528 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2532 vdbg_printk(TPACPI_DBG_INIT
,
2533 "initializing cmos commands subdriver\n");
2535 IBM_ACPIHANDLE_INIT(cmos
);
2537 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2538 str_supported(cmos_handle
!= NULL
));
2540 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2544 return (cmos_handle
)? 0 : 1;
2547 static void cmos_exit(void)
2549 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2552 static int cmos_read(char *p
)
2556 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2557 R30, R31, T20-22, X20-21 */
2559 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2561 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2562 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2568 static int cmos_write(char *buf
)
2573 while ((cmd
= next_cmd(&buf
))) {
2574 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2575 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2580 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2588 static struct ibm_struct cmos_driver_data
= {
2591 .write
= cmos_write
,
2595 /*************************************************************************
2599 static enum led_access_mode led_supported
;
2601 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2602 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2603 "LED", /* all others */
2606 static int __init
led_init(struct ibm_init_struct
*iibm
)
2608 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2610 IBM_ACPIHANDLE_INIT(led
);
2613 /* led not supported on R30, R31 */
2614 led_supported
= TPACPI_LED_NONE
;
2615 else if (strlencmp(led_path
, "SLED") == 0)
2617 led_supported
= TPACPI_LED_570
;
2618 else if (strlencmp(led_path
, "SYSL") == 0)
2619 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2620 led_supported
= TPACPI_LED_OLD
;
2623 led_supported
= TPACPI_LED_NEW
;
2625 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2626 str_supported(led_supported
), led_supported
);
2628 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2631 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2633 static int led_read(char *p
)
2637 if (!led_supported
) {
2638 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2641 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2643 if (led_supported
== TPACPI_LED_570
) {
2646 for (i
= 0; i
< 8; i
++) {
2647 if (!acpi_evalf(ec_handle
,
2648 &status
, "GLED", "dd", 1 << i
))
2650 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2651 i
, led_status(status
));
2655 len
+= sprintf(p
+ len
, "commands:\t"
2656 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2661 /* off, on, blink */
2662 static const int led_sled_arg1
[] = { 0, 1, 3 };
2663 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2664 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2665 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2667 static int led_write(char *buf
)
2675 while ((cmd
= next_cmd(&buf
))) {
2676 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2679 if (strstr(cmd
, "off")) {
2681 } else if (strstr(cmd
, "on")) {
2683 } else if (strstr(cmd
, "blink")) {
2688 if (led_supported
== TPACPI_LED_570
) {
2691 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2692 led
, led_sled_arg1
[ind
]))
2694 } else if (led_supported
== TPACPI_LED_OLD
) {
2695 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2697 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2700 ec_write(TPACPI_LED_EC_HLBL
,
2701 led
* led_exp_hlbl
[ind
]);
2704 ec_write(TPACPI_LED_EC_HLCL
,
2705 led
* led_exp_hlcl
[ind
]);
2710 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2711 led
, led_led_arg1
[ind
]))
2719 static struct ibm_struct led_driver_data
= {
2725 /*************************************************************************
2729 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2731 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2733 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2735 IBM_ACPIHANDLE_INIT(beep
);
2737 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2738 str_supported(beep_handle
!= NULL
));
2740 return (beep_handle
)? 0 : 1;
2743 static int beep_read(char *p
)
2748 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2750 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2751 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2757 static int beep_write(char *buf
)
2765 while ((cmd
= next_cmd(&buf
))) {
2766 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2767 beep_cmd
>= 0 && beep_cmd
<= 17) {
2771 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2778 static struct ibm_struct beep_driver_data
= {
2781 .write
= beep_write
,
2784 /*************************************************************************
2788 static enum thermal_access_mode thermal_read_mode
;
2790 /* sysfs temp##_input -------------------------------------------------- */
2792 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2793 struct device_attribute
*attr
,
2796 struct sensor_device_attribute
*sensor_attr
=
2797 to_sensor_dev_attr(attr
);
2798 int idx
= sensor_attr
->index
;
2802 res
= thermal_get_sensor(idx
, &value
);
2805 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2808 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2811 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2812 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2814 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2815 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2816 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2817 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2818 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2819 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2820 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2821 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2822 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2823 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2824 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2825 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2826 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2827 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2828 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2829 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2830 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2833 #define THERMAL_ATTRS(X) \
2834 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2836 static struct attribute
*thermal_temp_input_attr
[] = {
2856 static const struct attribute_group thermal_temp_input16_group
= {
2857 .attrs
= thermal_temp_input_attr
2860 static const struct attribute_group thermal_temp_input8_group
= {
2861 .attrs
= &thermal_temp_input_attr
[8]
2864 #undef THERMAL_SENSOR_ATTR_TEMP
2865 #undef THERMAL_ATTRS
2867 /* --------------------------------------------------------------------- */
2869 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2876 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2878 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2880 if (thinkpad_id
.ec_model
) {
2882 * Direct EC access mode: sensors at registers
2883 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2884 * non-implemented, thermal sensors return 0x80 when
2889 for (i
= 0; i
< 8; i
++) {
2890 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2896 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2904 /* This is sheer paranoia, but we handle it anyway */
2907 "ThinkPad ACPI EC access misbehaving, "
2908 "falling back to ACPI TMPx access mode\n");
2909 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2912 "ThinkPad ACPI EC access misbehaving, "
2913 "disabling thermal sensors access\n");
2914 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2919 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2921 } else if (acpi_tmp7
) {
2922 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2923 /* 600e/x, 770e, 770x */
2924 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2926 /* Standard ACPI TMPx access, max 8 sensors */
2927 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2930 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2931 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2934 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2935 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2938 switch(thermal_read_mode
) {
2939 case TPACPI_THERMAL_TPEC_16
:
2940 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2941 &thermal_temp_input16_group
);
2945 case TPACPI_THERMAL_TPEC_8
:
2946 case TPACPI_THERMAL_ACPI_TMP07
:
2947 case TPACPI_THERMAL_ACPI_UPDT
:
2948 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2949 &thermal_temp_input8_group
);
2953 case TPACPI_THERMAL_NONE
:
2961 static void thermal_exit(void)
2963 switch(thermal_read_mode
) {
2964 case TPACPI_THERMAL_TPEC_16
:
2965 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2966 &thermal_temp_input16_group
);
2968 case TPACPI_THERMAL_TPEC_8
:
2969 case TPACPI_THERMAL_ACPI_TMP07
:
2970 case TPACPI_THERMAL_ACPI_UPDT
:
2971 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2972 &thermal_temp_input16_group
);
2974 case TPACPI_THERMAL_NONE
:
2980 /* idx is zero-based */
2981 static int thermal_get_sensor(int idx
, s32
*value
)
2987 t
= TP_EC_THERMAL_TMP0
;
2989 switch (thermal_read_mode
) {
2990 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2991 case TPACPI_THERMAL_TPEC_16
:
2992 if (idx
>= 8 && idx
<= 15) {
2993 t
= TP_EC_THERMAL_TMP8
;
2998 case TPACPI_THERMAL_TPEC_8
:
3000 if (!acpi_ec_read(t
+ idx
, &tmp
))
3002 *value
= tmp
* 1000;
3007 case TPACPI_THERMAL_ACPI_UPDT
:
3009 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3010 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
3012 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3014 *value
= (t
- 2732) * 100;
3019 case TPACPI_THERMAL_ACPI_TMP07
:
3021 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3022 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3024 if (t
> 127 || t
< -127)
3025 t
= TP_EC_THERMAL_TMP_NA
;
3031 case TPACPI_THERMAL_NONE
:
3039 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
3050 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
3053 for(i
= 0 ; i
< n
; i
++) {
3054 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3062 static int thermal_read(char *p
)
3066 struct ibm_thermal_sensors_struct t
;
3068 n
= thermal_get_sensors(&t
);
3069 if (unlikely(n
< 0))
3072 len
+= sprintf(p
+ len
, "temperatures:\t");
3075 for (i
= 0; i
< (n
- 1); i
++)
3076 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3077 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3079 len
+= sprintf(p
+ len
, "not supported\n");
3084 static struct ibm_struct thermal_driver_data
= {
3086 .read
= thermal_read
,
3087 .exit
= thermal_exit
,
3090 /*************************************************************************
3094 static u8 ecdump_regs
[256];
3096 static int ecdump_read(char *p
)
3102 len
+= sprintf(p
+ len
, "EC "
3103 " +00 +01 +02 +03 +04 +05 +06 +07"
3104 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
3105 for (i
= 0; i
< 256; i
+= 16) {
3106 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
3107 for (j
= 0; j
< 16; j
++) {
3108 if (!acpi_ec_read(i
+ j
, &v
))
3110 if (v
!= ecdump_regs
[i
+ j
])
3111 len
+= sprintf(p
+ len
, " *%02x", v
);
3113 len
+= sprintf(p
+ len
, " %02x", v
);
3114 ecdump_regs
[i
+ j
] = v
;
3116 len
+= sprintf(p
+ len
, "\n");
3121 /* These are way too dangerous to advertise openly... */
3123 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3124 " (<offset> is 00-ff, <value> is 00-ff)\n");
3125 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3126 " (<offset> is 00-ff, <value> is 0-255)\n");
3131 static int ecdump_write(char *buf
)
3136 while ((cmd
= next_cmd(&buf
))) {
3137 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3139 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3143 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3144 if (!acpi_ec_write(i
, v
))
3153 static struct ibm_struct ecdump_driver_data
= {
3155 .read
= ecdump_read
,
3156 .write
= ecdump_write
,
3157 .flags
.experimental
= 1,
3160 /*************************************************************************
3161 * Backlight/brightness subdriver
3164 static struct backlight_device
*ibm_backlight_device
;
3166 static struct backlight_ops ibm_backlight_data
= {
3167 .get_brightness
= brightness_get
,
3168 .update_status
= brightness_update_status
,
3171 static struct mutex brightness_mutex
;
3173 static int __init
tpacpi_query_bcll_levels(acpi_handle handle
)
3175 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
3176 union acpi_object
*obj
;
3179 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
3180 obj
= (union acpi_object
*)buffer
.pointer
;
3181 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
3182 printk(IBM_ERR
"Unknown BCLL data, "
3183 "please report this to %s\n", IBM_MAIL
);
3186 rc
= obj
->package
.count
;
3192 kfree(buffer
.pointer
);
3196 static acpi_status __init
brightness_find_bcll(acpi_handle handle
, u32 lvl
,
3197 void *context
, void **rv
)
3199 char name
[ACPI_PATH_SEGMENT_LENGTH
];
3200 struct acpi_buffer buffer
= { sizeof(name
), &name
};
3202 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
3203 !strncmp("BCLL", name
, sizeof(name
) - 1)) {
3204 if (tpacpi_query_bcll_levels(handle
) == 16) {
3206 return AE_CTRL_TERMINATE
;
3215 static int __init
brightness_check_levels(void)
3218 void *found_node
= NULL
;
3221 IBM_ACPIHANDLE_INIT(vid
);
3226 /* Search for a BCLL package with 16 levels */
3227 status
= acpi_walk_namespace(ACPI_TYPE_PACKAGE
, vid_handle
, 3,
3228 brightness_find_bcll
, NULL
, &found_node
);
3230 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
3233 static acpi_status __init
brightness_find_bcl(acpi_handle handle
, u32 lvl
,
3234 void *context
, void **rv
)
3236 char name
[ACPI_PATH_SEGMENT_LENGTH
];
3237 struct acpi_buffer buffer
= { sizeof(name
), &name
};
3239 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
3240 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
3242 return AE_CTRL_TERMINATE
;
3248 static int __init
brightness_check_std_acpi_support(void)
3251 void *found_node
= NULL
;
3254 IBM_ACPIHANDLE_INIT(vid
);
3259 /* Search for a _BCL method, but don't execute it */
3260 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
3261 brightness_find_bcl
, NULL
, &found_node
);
3263 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
3266 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
3270 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
3272 mutex_init(&brightness_mutex
);
3274 if (!brightness_enable
) {
3275 dbg_printk(TPACPI_DBG_INIT
,
3276 "brightness support disabled by module parameter\n");
3278 } else if (brightness_enable
> 1) {
3279 if (brightness_check_std_acpi_support()) {
3281 "standard ACPI backlight interface available, not loading native one...\n");
3286 if (!brightness_mode
) {
3287 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
3288 brightness_mode
= 2;
3290 brightness_mode
= 3;
3292 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
3296 if (brightness_mode
> 3)
3299 tp_features
.bright_16levels
=
3300 thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
&&
3301 brightness_check_levels();
3303 b
= brightness_get(NULL
);
3307 if (tp_features
.bright_16levels
)
3308 printk(IBM_INFO
"detected a 16-level brightness capable ThinkPad\n");
3310 ibm_backlight_device
= backlight_device_register(
3311 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
3312 &ibm_backlight_data
);
3313 if (IS_ERR(ibm_backlight_device
)) {
3314 printk(IBM_ERR
"Could not register backlight device\n");
3315 return PTR_ERR(ibm_backlight_device
);
3317 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
3319 ibm_backlight_device
->props
.max_brightness
=
3320 (tp_features
.bright_16levels
)? 15 : 7;
3321 ibm_backlight_device
->props
.brightness
= b
;
3322 backlight_update_status(ibm_backlight_device
);
3327 static void brightness_exit(void)
3329 if (ibm_backlight_device
) {
3330 vdbg_printk(TPACPI_DBG_EXIT
,
3331 "calling backlight_device_unregister()\n");
3332 backlight_device_unregister(ibm_backlight_device
);
3333 ibm_backlight_device
= NULL
;
3337 static int brightness_update_status(struct backlight_device
*bd
)
3339 /* it is the backlight class's job (caller) to handle
3340 * EINTR and other errors properly */
3341 return brightness_set(
3342 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
3343 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
3344 bd
->props
.brightness
: 0);
3348 * ThinkPads can read brightness from two places: EC 0x31, or
3349 * CMOS NVRAM byte 0x5E, bits 0-3.
3351 static int brightness_get(struct backlight_device
*bd
)
3353 u8 lec
= 0, lcmos
= 0, level
= 0;
3355 if (brightness_mode
& 1) {
3356 if (!acpi_ec_read(brightness_offset
, &lec
))
3358 lec
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3361 if (brightness_mode
& 2) {
3362 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3363 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3364 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3365 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3369 if (brightness_mode
== 3 && lec
!= lcmos
) {
3371 "CMOS NVRAM (%u) and EC (%u) do not agree "
3372 "on display brightness level\n",
3373 (unsigned int) lcmos
,
3374 (unsigned int) lec
);
3381 /* May return EINTR which can always be mapped to ERESTARTSYS */
3382 static int brightness_set(int value
)
3384 int cmos_cmd
, inc
, i
, res
;
3387 if (value
> ((tp_features
.bright_16levels
)? 15 : 7))
3390 res
= mutex_lock_interruptible(&brightness_mutex
);
3394 current_value
= brightness_get(NULL
);
3395 if (current_value
< 0) {
3396 res
= current_value
;
3400 cmos_cmd
= value
> current_value
?
3401 TP_CMOS_BRIGHTNESS_UP
:
3402 TP_CMOS_BRIGHTNESS_DOWN
;
3403 inc
= (value
> current_value
)? 1 : -1;
3406 for (i
= current_value
; i
!= value
; i
+= inc
) {
3407 if ((brightness_mode
& 2) &&
3408 issue_thinkpad_cmos_command(cmos_cmd
)) {
3412 if ((brightness_mode
& 1) &&
3413 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
3420 mutex_unlock(&brightness_mutex
);
3424 static int brightness_read(char *p
)
3429 if ((level
= brightness_get(NULL
)) < 0) {
3430 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3432 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
3433 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3434 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3435 " (<level> is 0-%d)\n",
3436 (tp_features
.bright_16levels
) ? 15 : 7);
3442 static int brightness_write(char *buf
)
3447 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
3449 level
= brightness_get(NULL
);
3453 while ((cmd
= next_cmd(&buf
))) {
3454 if (strlencmp(cmd
, "up") == 0) {
3455 if (level
< max_level
)
3457 } else if (strlencmp(cmd
, "down") == 0) {
3460 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
3461 level
>= 0 && level
<= max_level
) {
3468 * Now we know what the final level should be, so we try to set it.
3469 * Doing it this way makes the syscall restartable in case of EINTR
3471 rc
= brightness_set(level
);
3472 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
3475 static struct ibm_struct brightness_driver_data
= {
3476 .name
= "brightness",
3477 .read
= brightness_read
,
3478 .write
= brightness_write
,
3479 .exit
= brightness_exit
,
3482 /*************************************************************************
3486 static int volume_read(char *p
)
3491 if (!acpi_ec_read(volume_offset
, &level
)) {
3492 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3494 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3495 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3496 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3497 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3498 " (<level> is 0-15)\n");
3504 static int volume_write(char *buf
)
3506 int cmos_cmd
, inc
, i
;
3508 int new_level
, new_mute
;
3511 while ((cmd
= next_cmd(&buf
))) {
3512 if (!acpi_ec_read(volume_offset
, &level
))
3514 new_mute
= mute
= level
& 0x40;
3515 new_level
= level
= level
& 0xf;
3517 if (strlencmp(cmd
, "up") == 0) {
3521 new_level
= level
== 15 ? 15 : level
+ 1;
3522 } else if (strlencmp(cmd
, "down") == 0) {
3526 new_level
= level
== 0 ? 0 : level
- 1;
3527 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3528 new_level
>= 0 && new_level
<= 15) {
3530 } else if (strlencmp(cmd
, "mute") == 0) {
3535 if (new_level
!= level
) { /* mute doesn't change */
3536 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3537 inc
= new_level
> level
? 1 : -1;
3539 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3540 !acpi_ec_write(volume_offset
, level
)))
3543 for (i
= level
; i
!= new_level
; i
+= inc
)
3544 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3545 !acpi_ec_write(volume_offset
, i
+ inc
))
3548 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3549 !acpi_ec_write(volume_offset
,
3554 if (new_mute
!= mute
) { /* level doesn't change */
3555 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3557 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3558 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3566 static struct ibm_struct volume_driver_data
= {
3568 .read
= volume_read
,
3569 .write
= volume_write
,
3572 /*************************************************************************
3579 * TPACPI_FAN_RD_ACPI_GFAN:
3580 * ACPI GFAN method: returns fan level
3582 * see TPACPI_FAN_WR_ACPI_SFAN
3583 * EC 0x2f (HFSP) not available if GFAN exists
3585 * TPACPI_FAN_WR_ACPI_SFAN:
3586 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3588 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3591 * TPACPI_FAN_WR_TPEC:
3592 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3593 * Supported on almost all ThinkPads
3595 * Fan speed changes of any sort (including those caused by the
3596 * disengaged mode) are usually done slowly by the firmware as the
3597 * maximum ammount of fan duty cycle change per second seems to be
3600 * Reading is not available if GFAN exists.
3601 * Writing is not available if SFAN exists.
3604 * 7 automatic mode engaged;
3605 * (default operation mode of the ThinkPad)
3606 * fan level is ignored in this mode.
3607 * 6 full speed mode (takes precedence over bit 7);
3608 * not available on all thinkpads. May disable
3609 * the tachometer while the fan controller ramps up
3610 * the speed (which can take up to a few *minutes*).
3611 * Speeds up fan to 100% duty-cycle, which is far above
3612 * the standard RPM levels. It is not impossible that
3613 * it could cause hardware damage.
3614 * 5-3 unused in some models. Extra bits for fan level
3615 * in others, but still useless as all values above
3616 * 7 map to the same speed as level 7 in these models.
3617 * 2-0 fan level (0..7 usually)
3619 * 0x07 = max (set when temperatures critical)
3620 * Some ThinkPads may have other levels, see
3621 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3623 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3624 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3625 * does so, its initial value is meaningless (0x07).
3627 * For firmware bugs, refer to:
3628 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3632 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3633 * Main fan tachometer reading (in RPM)
3635 * This register is present on all ThinkPads with a new-style EC, and
3636 * it is known not to be present on the A21m/e, and T22, as there is
3637 * something else in offset 0x84 according to the ACPI DSDT. Other
3638 * ThinkPads from this same time period (and earlier) probably lack the
3639 * tachometer as well.
3641 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3642 * was never fixed by IBM to report the EC firmware version string
3643 * probably support the tachometer (like the early X models), so
3644 * detecting it is quite hard. We need more data to know for sure.
3646 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3649 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3652 * For firmware bugs, refer to:
3653 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3655 * TPACPI_FAN_WR_ACPI_FANS:
3656 * ThinkPad X31, X40, X41. Not available in the X60.
3658 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3659 * high speed. ACPI DSDT seems to map these three speeds to levels
3660 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3661 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3663 * The speeds are stored on handles
3664 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3666 * There are three default speed sets, acessible as handles:
3667 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3669 * ACPI DSDT switches which set is in use depending on various
3672 * TPACPI_FAN_WR_TPEC is also available and should be used to
3673 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3674 * but the ACPI tables just mention level 7.
3677 static enum fan_status_access_mode fan_status_access_mode
;
3678 static enum fan_control_access_mode fan_control_access_mode
;
3679 static enum fan_control_commands fan_control_commands
;
3681 static u8 fan_control_initial_status
;
3682 static u8 fan_control_desired_level
;
3684 static void fan_watchdog_fire(struct work_struct
*ignored
);
3685 static int fan_watchdog_maxinterval
;
3686 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3688 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3689 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3690 "\\FSPD", /* 600e/x, 770e, 770x */
3692 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3693 "JFNS", /* 770x-JL */
3697 * SYSFS fan layout: hwmon compatible (device)
3700 * 0: "disengaged" mode
3702 * 2: native EC "auto" mode (recommended, hardware default)
3704 * pwm*: set speed in manual mode, ignored otherwise.
3705 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3708 * fan*_input: tachometer reading, RPM
3711 * SYSFS fan layout: extensions
3713 * fan_watchdog (driver):
3714 * fan watchdog interval in seconds, 0 disables (default), max 120
3717 /* sysfs fan pwm1_enable ----------------------------------------------- */
3718 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3719 struct device_attribute
*attr
,
3725 res
= fan_get_status_safe(&status
);
3729 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3730 if (status
!= fan_control_initial_status
) {
3731 tp_features
.fan_ctrl_status_undef
= 0;
3733 /* Return most likely status. In fact, it
3734 * might be the only possible status */
3735 status
= TP_EC_FAN_AUTO
;
3739 if (status
& TP_EC_FAN_FULLSPEED
) {
3741 } else if (status
& TP_EC_FAN_AUTO
) {
3746 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3749 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3750 struct device_attribute
*attr
,
3751 const char *buf
, size_t count
)
3756 if (parse_strtoul(buf
, 2, &t
))
3761 level
= TP_EC_FAN_FULLSPEED
;
3764 level
= TPACPI_FAN_LAST_LEVEL
;
3767 level
= TP_EC_FAN_AUTO
;
3770 /* reserved for software-controlled auto mode */
3776 res
= fan_set_level_safe(level
);
3782 fan_watchdog_reset();
3787 static struct device_attribute dev_attr_fan_pwm1_enable
=
3788 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3789 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3791 /* sysfs fan pwm1 ------------------------------------------------------ */
3792 static ssize_t
fan_pwm1_show(struct device
*dev
,
3793 struct device_attribute
*attr
,
3799 res
= fan_get_status_safe(&status
);
3803 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3804 if (status
!= fan_control_initial_status
) {
3805 tp_features
.fan_ctrl_status_undef
= 0;
3807 status
= TP_EC_FAN_AUTO
;
3812 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3813 status
= fan_control_desired_level
;
3818 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3821 static ssize_t
fan_pwm1_store(struct device
*dev
,
3822 struct device_attribute
*attr
,
3823 const char *buf
, size_t count
)
3827 u8 status
, newlevel
;
3829 if (parse_strtoul(buf
, 255, &s
))
3832 /* scale down from 0-255 to 0-7 */
3833 newlevel
= (s
>> 5) & 0x07;
3835 if (mutex_lock_interruptible(&fan_mutex
))
3836 return -ERESTARTSYS
;
3838 rc
= fan_get_status(&status
);
3839 if (!rc
&& (status
&
3840 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3841 rc
= fan_set_level(newlevel
);
3845 fan_update_desired_level(newlevel
);
3846 fan_watchdog_reset();
3850 mutex_unlock(&fan_mutex
);
3851 return (rc
)? rc
: count
;
3854 static struct device_attribute dev_attr_fan_pwm1
=
3855 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3856 fan_pwm1_show
, fan_pwm1_store
);
3858 /* sysfs fan fan1_input ------------------------------------------------ */
3859 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3860 struct device_attribute
*attr
,
3866 res
= fan_get_speed(&speed
);
3870 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3873 static struct device_attribute dev_attr_fan_fan1_input
=
3874 __ATTR(fan1_input
, S_IRUGO
,
3875 fan_fan1_input_show
, NULL
);
3877 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
3878 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3881 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3884 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3885 const char *buf
, size_t count
)
3889 if (parse_strtoul(buf
, 120, &t
))
3892 if (!fan_control_allowed
)
3895 fan_watchdog_maxinterval
= t
;
3896 fan_watchdog_reset();
3901 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3902 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3904 /* --------------------------------------------------------------------- */
3905 static struct attribute
*fan_attributes
[] = {
3906 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3907 &dev_attr_fan_fan1_input
.attr
,
3911 static const struct attribute_group fan_attr_group
= {
3912 .attrs
= fan_attributes
,
3915 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3919 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3921 mutex_init(&fan_mutex
);
3922 fan_status_access_mode
= TPACPI_FAN_NONE
;
3923 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3924 fan_control_commands
= 0;
3925 fan_watchdog_maxinterval
= 0;
3926 tp_features
.fan_ctrl_status_undef
= 0;
3927 fan_control_desired_level
= 7;
3929 IBM_ACPIHANDLE_INIT(fans
);
3930 IBM_ACPIHANDLE_INIT(gfan
);
3931 IBM_ACPIHANDLE_INIT(sfan
);
3934 /* 570, 600e/x, 770e, 770x */
3935 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3937 /* all other ThinkPads: note that even old-style
3938 * ThinkPad ECs supports the fan control register */
3939 if (likely(acpi_ec_read(fan_status_offset
,
3940 &fan_control_initial_status
))) {
3941 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3943 /* In some ThinkPads, neither the EC nor the ACPI
3944 * DSDT initialize the fan status, and it ends up
3945 * being set to 0x07 when it *could* be either
3948 * Enable for TP-1Y (T43), TP-78 (R51e),
3949 * TP-76 (R52), TP-70 (T43, R52), which are known
3951 if (fan_control_initial_status
== 0x07) {
3952 switch (thinkpad_id
.ec_model
) {
3953 case 0x5931: /* TP-1Y */
3954 case 0x3837: /* TP-78 */
3955 case 0x3637: /* TP-76 */
3956 case 0x3037: /* TP-70 */
3958 "fan_init: initial fan status is "
3959 "unknown, assuming it is in auto "
3961 tp_features
.fan_ctrl_status_undef
= 1;
3967 "ThinkPad ACPI EC access misbehaving, "
3968 "fan status and control unavailable\n");
3975 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3976 fan_control_commands
|=
3977 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3980 /* gfan without sfan means no fan control */
3981 /* all other models implement TP EC 0x2f control */
3985 fan_control_access_mode
=
3986 TPACPI_FAN_WR_ACPI_FANS
;
3987 fan_control_commands
|=
3988 TPACPI_FAN_CMD_SPEED
|
3989 TPACPI_FAN_CMD_LEVEL
|
3990 TPACPI_FAN_CMD_ENABLE
;
3992 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3993 fan_control_commands
|=
3994 TPACPI_FAN_CMD_LEVEL
|
3995 TPACPI_FAN_CMD_ENABLE
;
4000 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
4001 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
4002 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
4003 fan_status_access_mode
, fan_control_access_mode
);
4005 /* fan control master switch */
4006 if (!fan_control_allowed
) {
4007 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
4008 fan_control_commands
= 0;
4009 dbg_printk(TPACPI_DBG_INIT
,
4010 "fan control features disabled by parameter\n");
4013 /* update fan_control_desired_level */
4014 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
4015 fan_get_status_safe(NULL
);
4017 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
4018 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
4019 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4022 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
4023 &driver_attr_fan_watchdog
);
4032 * Call with fan_mutex held
4034 static void fan_update_desired_level(u8 status
)
4037 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4039 fan_control_desired_level
= 7;
4041 fan_control_desired_level
= status
;
4045 static int fan_get_status(u8
*status
)
4050 * Add TPACPI_FAN_RD_ACPI_FANS ? */
4052 switch (fan_status_access_mode
) {
4053 case TPACPI_FAN_RD_ACPI_GFAN
:
4054 /* 570, 600e/x, 770e, 770x */
4056 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
4064 case TPACPI_FAN_RD_TPEC
:
4065 /* all except 570, 600e/x, 770e, 770x */
4066 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
4081 static int fan_get_status_safe(u8
*status
)
4086 if (mutex_lock_interruptible(&fan_mutex
))
4087 return -ERESTARTSYS
;
4088 rc
= fan_get_status(&s
);
4090 fan_update_desired_level(s
);
4091 mutex_unlock(&fan_mutex
);
4099 static void fan_exit(void)
4101 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
4103 /* FIXME: can we really do this unconditionally? */
4104 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
4105 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
, &driver_attr_fan_watchdog
);
4107 cancel_delayed_work(&fan_watchdog_task
);
4108 flush_scheduled_work();
4111 static int fan_get_speed(unsigned int *speed
)
4115 switch (fan_status_access_mode
) {
4116 case TPACPI_FAN_RD_TPEC
:
4117 /* all except 570, 600e/x, 770e, 770x */
4118 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4119 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4123 *speed
= (hi
<< 8) | lo
;
4134 static void fan_watchdog_fire(struct work_struct
*ignored
)
4138 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
4141 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
4142 rc
= fan_set_enable();
4144 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
4145 "will try again later...\n", -rc
);
4146 /* reschedule for later */
4147 fan_watchdog_reset();
4151 static void fan_watchdog_reset(void)
4153 static int fan_watchdog_active
;
4155 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
4158 if (fan_watchdog_active
)
4159 cancel_delayed_work(&fan_watchdog_task
);
4161 if (fan_watchdog_maxinterval
> 0 &&
4162 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
4163 fan_watchdog_active
= 1;
4164 if (!schedule_delayed_work(&fan_watchdog_task
,
4165 msecs_to_jiffies(fan_watchdog_maxinterval
4167 printk(IBM_ERR
"failed to schedule the fan watchdog, "
4168 "watchdog will not trigger\n");
4171 fan_watchdog_active
= 0;
4174 static int fan_set_level(int level
)
4176 if (!fan_control_allowed
)
4179 switch (fan_control_access_mode
) {
4180 case TPACPI_FAN_WR_ACPI_SFAN
:
4181 if (level
>= 0 && level
<= 7) {
4182 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4188 case TPACPI_FAN_WR_ACPI_FANS
:
4189 case TPACPI_FAN_WR_TPEC
:
4190 if ((level
!= TP_EC_FAN_AUTO
) &&
4191 (level
!= TP_EC_FAN_FULLSPEED
) &&
4192 ((level
< 0) || (level
> 7)))
4195 /* safety net should the EC not support AUTO
4196 * or FULLSPEED mode bits and just ignore them */
4197 if (level
& TP_EC_FAN_FULLSPEED
)
4198 level
|= 7; /* safety min speed 7 */
4199 else if (level
& TP_EC_FAN_FULLSPEED
)
4200 level
|= 4; /* safety min speed 4 */
4202 if (!acpi_ec_write(fan_status_offset
, level
))
4205 tp_features
.fan_ctrl_status_undef
= 0;
4214 static int fan_set_level_safe(int level
)
4218 if (!fan_control_allowed
)
4221 if (mutex_lock_interruptible(&fan_mutex
))
4222 return -ERESTARTSYS
;
4224 if (level
== TPACPI_FAN_LAST_LEVEL
)
4225 level
= fan_control_desired_level
;
4227 rc
= fan_set_level(level
);
4229 fan_update_desired_level(level
);
4231 mutex_unlock(&fan_mutex
);
4235 static int fan_set_enable(void)
4240 if (!fan_control_allowed
)
4243 if (mutex_lock_interruptible(&fan_mutex
))
4244 return -ERESTARTSYS
;
4246 switch (fan_control_access_mode
) {
4247 case TPACPI_FAN_WR_ACPI_FANS
:
4248 case TPACPI_FAN_WR_TPEC
:
4249 rc
= fan_get_status(&s
);
4253 /* Don't go out of emergency fan mode */
4256 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4259 if (!acpi_ec_write(fan_status_offset
, s
))
4262 tp_features
.fan_ctrl_status_undef
= 0;
4267 case TPACPI_FAN_WR_ACPI_SFAN
:
4268 rc
= fan_get_status(&s
);
4274 /* Set fan to at least level 4 */
4277 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4287 mutex_unlock(&fan_mutex
);
4291 static int fan_set_disable(void)
4295 if (!fan_control_allowed
)
4298 if (mutex_lock_interruptible(&fan_mutex
))
4299 return -ERESTARTSYS
;
4302 switch (fan_control_access_mode
) {
4303 case TPACPI_FAN_WR_ACPI_FANS
:
4304 case TPACPI_FAN_WR_TPEC
:
4305 if (!acpi_ec_write(fan_status_offset
, 0x00))
4308 fan_control_desired_level
= 0;
4309 tp_features
.fan_ctrl_status_undef
= 0;
4313 case TPACPI_FAN_WR_ACPI_SFAN
:
4314 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4317 fan_control_desired_level
= 0;
4325 mutex_unlock(&fan_mutex
);
4329 static int fan_set_speed(int speed
)
4333 if (!fan_control_allowed
)
4336 if (mutex_lock_interruptible(&fan_mutex
))
4337 return -ERESTARTSYS
;
4340 switch (fan_control_access_mode
) {
4341 case TPACPI_FAN_WR_ACPI_FANS
:
4342 if (speed
>= 0 && speed
<= 65535) {
4343 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4344 speed
, speed
, speed
))
4354 mutex_unlock(&fan_mutex
);
4358 static int fan_read(char *p
)
4363 unsigned int speed
= 0;
4365 switch (fan_status_access_mode
) {
4366 case TPACPI_FAN_RD_ACPI_GFAN
:
4367 /* 570, 600e/x, 770e, 770x */
4368 if ((rc
= fan_get_status_safe(&status
)) < 0)
4371 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
4373 (status
!= 0) ? "enabled" : "disabled", status
);
4376 case TPACPI_FAN_RD_TPEC
:
4377 /* all except 570, 600e/x, 770e, 770x */
4378 if ((rc
= fan_get_status_safe(&status
)) < 0)
4381 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4382 if (status
!= fan_control_initial_status
)
4383 tp_features
.fan_ctrl_status_undef
= 0;
4385 /* Return most likely status. In fact, it
4386 * might be the only possible status */
4387 status
= TP_EC_FAN_AUTO
;
4390 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4391 (status
!= 0) ? "enabled" : "disabled");
4393 if ((rc
= fan_get_speed(&speed
)) < 0)
4396 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
4398 if (status
& TP_EC_FAN_FULLSPEED
)
4399 /* Disengaged mode takes precedence */
4400 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
4401 else if (status
& TP_EC_FAN_AUTO
)
4402 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
4404 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
4407 case TPACPI_FAN_NONE
:
4409 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4412 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
4413 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
4415 switch (fan_control_access_mode
) {
4416 case TPACPI_FAN_WR_ACPI_SFAN
:
4417 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4421 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4422 "auto, disengaged, full-speed)\n");
4427 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4428 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4429 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4430 "1-120 (seconds))\n");
4432 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4433 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4434 " (<speed> is 0-65535)\n");
4439 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4443 if (strlencmp(cmd
, "level auto") == 0)
4444 level
= TP_EC_FAN_AUTO
;
4445 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4446 (strlencmp(cmd
, "level full-speed") == 0))
4447 level
= TP_EC_FAN_FULLSPEED
;
4448 else if (sscanf(cmd
, "level %d", &level
) != 1)
4451 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4452 printk(IBM_ERR
"level command accepted for unsupported "
4453 "access mode %d", fan_control_access_mode
);
4458 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4460 if (strlencmp(cmd
, "enable") != 0)
4463 if ((*rc
= fan_set_enable()) == -ENXIO
)
4464 printk(IBM_ERR
"enable command accepted for unsupported "
4465 "access mode %d", fan_control_access_mode
);
4470 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4472 if (strlencmp(cmd
, "disable") != 0)
4475 if ((*rc
= fan_set_disable()) == -ENXIO
)
4476 printk(IBM_ERR
"disable command accepted for unsupported "
4477 "access mode %d", fan_control_access_mode
);
4482 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4487 * Support speed <low> <medium> <high> ? */
4489 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4492 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4493 printk(IBM_ERR
"speed command accepted for unsupported "
4494 "access mode %d", fan_control_access_mode
);
4499 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4503 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4506 if (interval
< 0 || interval
> 120)
4509 fan_watchdog_maxinterval
= interval
;
4514 static int fan_write(char *buf
)
4519 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4520 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4521 fan_write_cmd_level(cmd
, &rc
)) &&
4522 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4523 (fan_write_cmd_enable(cmd
, &rc
) ||
4524 fan_write_cmd_disable(cmd
, &rc
) ||
4525 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4526 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4527 fan_write_cmd_speed(cmd
, &rc
))
4531 fan_watchdog_reset();
4537 static struct ibm_struct fan_driver_data
= {
4544 /****************************************************************************
4545 ****************************************************************************
4549 ****************************************************************************
4550 ****************************************************************************/
4552 /* sysfs name ---------------------------------------------------------- */
4553 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
4554 struct device_attribute
*attr
,
4557 return snprintf(buf
, PAGE_SIZE
, "%s\n", IBM_NAME
);
4560 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
4561 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
4563 /* --------------------------------------------------------------------- */
4566 static struct proc_dir_entry
*proc_dir
;
4568 /* Subdriver registry */
4569 static LIST_HEAD(tpacpi_all_drivers
);
4573 * Module and infrastructure proble, init and exit handling
4576 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4577 static const char * __init
str_supported(int is_supported
)
4579 static char text_unsupported
[] __initdata
= "not supported";
4581 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4583 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4585 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4588 struct ibm_struct
*ibm
= iibm
->data
;
4589 struct proc_dir_entry
*entry
;
4591 BUG_ON(ibm
== NULL
);
4593 INIT_LIST_HEAD(&ibm
->all_drivers
);
4595 if (ibm
->flags
.experimental
&& !experimental
)
4598 dbg_printk(TPACPI_DBG_INIT
,
4599 "probing for %s\n", ibm
->name
);
4602 ret
= iibm
->init(iibm
);
4604 return 0; /* probe failed */
4608 ibm
->flags
.init_called
= 1;
4612 if (ibm
->acpi
->hid
) {
4613 ret
= register_tpacpi_subdriver(ibm
);
4618 if (ibm
->acpi
->notify
) {
4619 ret
= setup_acpi_notify(ibm
);
4620 if (ret
== -ENODEV
) {
4621 printk(IBM_NOTICE
"disabling subdriver %s\n",
4631 dbg_printk(TPACPI_DBG_INIT
,
4632 "%s installed\n", ibm
->name
);
4635 entry
= create_proc_entry(ibm
->name
,
4636 S_IFREG
| S_IRUGO
| S_IWUSR
,
4639 printk(IBM_ERR
"unable to create proc entry %s\n",
4644 entry
->owner
= THIS_MODULE
;
4646 entry
->read_proc
= &dispatch_procfs_read
;
4648 entry
->write_proc
= &dispatch_procfs_write
;
4649 ibm
->flags
.proc_created
= 1;
4652 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4657 dbg_printk(TPACPI_DBG_INIT
,
4658 "%s: at error exit path with result %d\n",
4662 return (ret
< 0)? ret
: 0;
4665 static void ibm_exit(struct ibm_struct
*ibm
)
4667 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4669 list_del_init(&ibm
->all_drivers
);
4671 if (ibm
->flags
.acpi_notify_installed
) {
4672 dbg_printk(TPACPI_DBG_EXIT
,
4673 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4675 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4677 dispatch_acpi_notify
);
4678 ibm
->flags
.acpi_notify_installed
= 0;
4679 ibm
->flags
.acpi_notify_installed
= 0;
4682 if (ibm
->flags
.proc_created
) {
4683 dbg_printk(TPACPI_DBG_EXIT
,
4684 "%s: remove_proc_entry\n", ibm
->name
);
4685 remove_proc_entry(ibm
->name
, proc_dir
);
4686 ibm
->flags
.proc_created
= 0;
4689 if (ibm
->flags
.acpi_driver_registered
) {
4690 dbg_printk(TPACPI_DBG_EXIT
,
4691 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4693 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4694 kfree(ibm
->acpi
->driver
);
4695 ibm
->acpi
->driver
= NULL
;
4696 ibm
->flags
.acpi_driver_registered
= 0;
4699 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4701 ibm
->flags
.init_called
= 0;
4704 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4709 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
4711 struct dmi_device
*dev
= NULL
;
4712 char ec_fw_string
[18];
4717 memset(tp
, 0, sizeof(*tp
));
4719 if (dmi_name_in_vendors("IBM"))
4720 tp
->vendor
= PCI_VENDOR_ID_IBM
;
4721 else if (dmi_name_in_vendors("LENOVO"))
4722 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
4726 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
4728 if (!tp
->bios_version_str
)
4730 tp
->bios_model
= tp
->bios_version_str
[0]
4731 | (tp
->bios_version_str
[1] << 8);
4734 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4735 * X32 or newer, all Z series; Some models must have an
4736 * up-to-date BIOS or they will not be detected.
4738 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4740 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4741 if (sscanf(dev
->name
,
4742 "IBM ThinkPad Embedded Controller -[%17c",
4743 ec_fw_string
) == 1) {
4744 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4745 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4747 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
4748 tp
->ec_model
= ec_fw_string
[0]
4749 | (ec_fw_string
[1] << 8);
4754 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
4756 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
4757 kfree(tp
->model_str
);
4758 tp
->model_str
= NULL
;
4762 static int __init
probe_for_thinkpad(void)
4770 * Non-ancient models have better DMI tagging, but very old models
4773 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
4775 /* ec is required because many other handles are relative to it */
4776 IBM_ACPIHANDLE_INIT(ec
);
4780 "Not yet supported ThinkPad detected!\n");
4785 * Risks a regression on very old machines, but reduces potential
4786 * false positives a damn great deal
4789 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
4791 if (!is_thinkpad
&& !force_load
)
4798 /* Module init, exit, parameters */
4800 static struct ibm_init_struct ibms_init
[] __initdata
= {
4802 .init
= thinkpad_acpi_driver_init
,
4803 .data
= &thinkpad_acpi_driver_data
,
4806 .init
= hotkey_init
,
4807 .data
= &hotkey_driver_data
,
4810 .init
= bluetooth_init
,
4811 .data
= &bluetooth_driver_data
,
4815 .data
= &wan_driver_data
,
4819 .data
= &video_driver_data
,
4823 .data
= &light_driver_data
,
4825 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4828 .data
= &dock_driver_data
[0],
4832 .data
= &dock_driver_data
[1],
4835 #ifdef CONFIG_THINKPAD_ACPI_BAY
4838 .data
= &bay_driver_data
,
4843 .data
= &cmos_driver_data
,
4847 .data
= &led_driver_data
,
4851 .data
= &beep_driver_data
,
4854 .init
= thermal_init
,
4855 .data
= &thermal_driver_data
,
4858 .data
= &ecdump_driver_data
,
4861 .init
= brightness_init
,
4862 .data
= &brightness_driver_data
,
4865 .data
= &volume_driver_data
,
4869 .data
= &fan_driver_data
,
4873 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4876 struct ibm_struct
*ibm
;
4878 if (!kp
|| !kp
->name
|| !val
)
4881 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4882 ibm
= ibms_init
[i
].data
;
4883 WARN_ON(ibm
== NULL
);
4885 if (!ibm
|| !ibm
->name
)
4888 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4889 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4891 strcpy(ibms_init
[i
].param
, val
);
4892 strcat(ibms_init
[i
].param
, ",");
4900 static int experimental
;
4901 module_param(experimental
, int, 0);
4903 static u32 dbg_level
;
4904 module_param_named(debug
, dbg_level
, uint
, 0);
4906 static int force_load
;
4907 module_param(force_load
, bool, 0);
4909 static int fan_control_allowed
;
4910 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
4912 static int brightness_mode
;
4913 module_param_named(brightness_mode
, brightness_mode
, int, 0);
4915 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
4916 module_param(brightness_enable
, uint
, 0);
4918 static unsigned int hotkey_report_mode
;
4919 module_param(hotkey_report_mode
, uint
, 0);
4921 #define IBM_PARAM(feature) \
4922 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4925 IBM_PARAM(bluetooth
);
4928 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4931 #ifdef CONFIG_THINKPAD_ACPI_BAY
4933 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4938 IBM_PARAM(brightness
);
4942 static int __init
thinkpad_acpi_module_init(void)
4946 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
4948 /* Parameter checking */
4949 if (hotkey_report_mode
> 2)
4952 /* Driver-level probe */
4954 get_thinkpad_model_data(&thinkpad_id
);
4955 ret
= probe_for_thinkpad();
4957 thinkpad_acpi_module_exit();
4961 /* Driver initialization */
4963 IBM_ACPIHANDLE_INIT(ecrd
);
4964 IBM_ACPIHANDLE_INIT(ecwr
);
4966 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4968 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4969 thinkpad_acpi_module_exit();
4972 proc_dir
->owner
= THIS_MODULE
;
4974 ret
= platform_driver_register(&tpacpi_pdriver
);
4976 printk(IBM_ERR
"unable to register main platform driver\n");
4977 thinkpad_acpi_module_exit();
4980 tp_features
.platform_drv_registered
= 1;
4982 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
4984 printk(IBM_ERR
"unable to register hwmon platform driver\n");
4985 thinkpad_acpi_module_exit();
4988 tp_features
.sensors_pdrv_registered
= 1;
4990 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4992 tp_features
.platform_drv_attrs_registered
= 1;
4993 ret
= tpacpi_create_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
4996 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4997 thinkpad_acpi_module_exit();
5000 tp_features
.sensors_pdrv_attrs_registered
= 1;
5003 /* Device initialization */
5004 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
5006 if (IS_ERR(tpacpi_pdev
)) {
5007 ret
= PTR_ERR(tpacpi_pdev
);
5009 printk(IBM_ERR
"unable to register platform device\n");
5010 thinkpad_acpi_module_exit();
5013 tpacpi_sensors_pdev
= platform_device_register_simple(
5014 IBM_HWMON_DRVR_NAME
,
5016 if (IS_ERR(tpacpi_sensors_pdev
)) {
5017 ret
= PTR_ERR(tpacpi_sensors_pdev
);
5018 tpacpi_sensors_pdev
= NULL
;
5019 printk(IBM_ERR
"unable to register hwmon platform device\n");
5020 thinkpad_acpi_module_exit();
5023 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
5024 &dev_attr_thinkpad_acpi_pdev_name
);
5027 "unable to create sysfs hwmon device attributes\n");
5028 thinkpad_acpi_module_exit();
5031 tp_features
.sensors_pdev_attrs_registered
= 1;
5032 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
5033 if (IS_ERR(tpacpi_hwmon
)) {
5034 ret
= PTR_ERR(tpacpi_hwmon
);
5035 tpacpi_hwmon
= NULL
;
5036 printk(IBM_ERR
"unable to register hwmon device\n");
5037 thinkpad_acpi_module_exit();
5040 mutex_init(&tpacpi_inputdev_send_mutex
);
5041 tpacpi_inputdev
= input_allocate_device();
5042 if (!tpacpi_inputdev
) {
5043 printk(IBM_ERR
"unable to allocate input device\n");
5044 thinkpad_acpi_module_exit();
5047 /* Prepare input device, but don't register */
5048 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
5049 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
5050 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
5051 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
5052 thinkpad_id
.vendor
:
5054 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
5055 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
5057 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5058 ret
= ibm_init(&ibms_init
[i
]);
5059 if (ret
>= 0 && *ibms_init
[i
].param
)
5060 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
5062 thinkpad_acpi_module_exit();
5066 ret
= input_register_device(tpacpi_inputdev
);
5068 printk(IBM_ERR
"unable to register input device\n");
5069 thinkpad_acpi_module_exit();
5072 tp_features
.input_device_registered
= 1;
5075 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
5079 static void thinkpad_acpi_module_exit(void)
5081 struct ibm_struct
*ibm
, *itmp
;
5083 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
5085 list_for_each_entry_safe_reverse(ibm
, itmp
,
5086 &tpacpi_all_drivers
,
5091 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
5093 if (tpacpi_inputdev
) {
5094 if (tp_features
.input_device_registered
)
5095 input_unregister_device(tpacpi_inputdev
);
5097 input_free_device(tpacpi_inputdev
);
5101 hwmon_device_unregister(tpacpi_hwmon
);
5103 if (tp_features
.sensors_pdev_attrs_registered
)
5104 device_remove_file(&tpacpi_sensors_pdev
->dev
,
5105 &dev_attr_thinkpad_acpi_pdev_name
);
5106 if (tpacpi_sensors_pdev
)
5107 platform_device_unregister(tpacpi_sensors_pdev
);
5109 platform_device_unregister(tpacpi_pdev
);
5111 if (tp_features
.sensors_pdrv_attrs_registered
)
5112 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
5113 if (tp_features
.platform_drv_attrs_registered
)
5114 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
5116 if (tp_features
.sensors_pdrv_registered
)
5117 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
5119 if (tp_features
.platform_drv_registered
)
5120 platform_driver_unregister(&tpacpi_pdriver
);
5123 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
5125 kfree(thinkpad_id
.bios_version_str
);
5126 kfree(thinkpad_id
.ec_version_str
);
5127 kfree(thinkpad_id
.model_str
);
5130 module_init(thinkpad_acpi_module_init
);
5131 module_exit(thinkpad_acpi_module_exit
);