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 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
;
780 static u32 hotkey_mask
;
782 static u16
*hotkey_keycode_map
;
784 static struct attribute_set
*hotkey_dev_attributes
;
786 static int hotkey_get_wlsw(int *status
)
788 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
794 * Call with hotkey_mutex held
796 static int hotkey_mask_get(void)
798 if (tp_features
.hotkey_mask
) {
799 if (!acpi_evalf(hkey_handle
, &hotkey_mask
, "DHKN", "d"))
807 * Call with hotkey_mutex held
809 static int hotkey_mask_set(u32 mask
)
814 if (tp_features
.hotkey_mask
) {
815 for (i
= 0; i
< 32; i
++) {
817 if (!acpi_evalf(hkey_handle
,
818 NULL
, "MHKM", "vdd", i
+ 1,
823 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
827 /* hotkey_mask_get must be called unconditionally below */
828 if (!hotkey_mask_get() && !rc
&& hotkey_mask
!= mask
) {
830 "requested hot key mask 0x%08x, but "
831 "firmware forced it to 0x%08x\n",
839 static int hotkey_status_get(int *status
)
841 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
847 static int hotkey_status_set(int status
)
849 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
855 /* sysfs hotkey enable ------------------------------------------------- */
856 static ssize_t
hotkey_enable_show(struct device
*dev
,
857 struct device_attribute
*attr
,
862 res
= hotkey_status_get(&status
);
866 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
869 static ssize_t
hotkey_enable_store(struct device
*dev
,
870 struct device_attribute
*attr
,
871 const char *buf
, size_t count
)
876 if (parse_strtoul(buf
, 1, &t
))
879 res
= hotkey_status_set(t
);
881 return (res
) ? res
: count
;
884 static struct device_attribute dev_attr_hotkey_enable
=
885 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
886 hotkey_enable_show
, hotkey_enable_store
);
888 /* sysfs hotkey mask --------------------------------------------------- */
889 static ssize_t
hotkey_mask_show(struct device
*dev
,
890 struct device_attribute
*attr
,
895 if (mutex_lock_interruptible(&hotkey_mutex
))
897 res
= hotkey_mask_get();
898 mutex_unlock(&hotkey_mutex
);
901 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
904 static ssize_t
hotkey_mask_store(struct device
*dev
,
905 struct device_attribute
*attr
,
906 const char *buf
, size_t count
)
911 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
914 if (mutex_lock_interruptible(&hotkey_mutex
))
917 res
= hotkey_mask_set(t
);
918 mutex_unlock(&hotkey_mutex
);
920 return (res
) ? res
: count
;
923 static struct device_attribute dev_attr_hotkey_mask
=
924 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
925 hotkey_mask_show
, hotkey_mask_store
);
927 /* sysfs hotkey bios_enabled ------------------------------------------- */
928 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
929 struct device_attribute
*attr
,
932 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
935 static struct device_attribute dev_attr_hotkey_bios_enabled
=
936 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
938 /* sysfs hotkey bios_mask ---------------------------------------------- */
939 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
940 struct device_attribute
*attr
,
943 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
946 static struct device_attribute dev_attr_hotkey_bios_mask
=
947 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
949 /* sysfs hotkey all_mask ----------------------------------------------- */
950 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
951 struct device_attribute
*attr
,
954 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_all_mask
);
957 static struct device_attribute dev_attr_hotkey_all_mask
=
958 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
960 /* sysfs hotkey recommended_mask --------------------------------------- */
961 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
962 struct device_attribute
*attr
,
965 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
966 hotkey_all_mask
& ~hotkey_reserved_mask
);
969 static struct device_attribute dev_attr_hotkey_recommended_mask
=
970 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
971 hotkey_recommended_mask_show
, NULL
);
973 /* sysfs hotkey radio_sw ----------------------------------------------- */
974 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
975 struct device_attribute
*attr
,
979 res
= hotkey_get_wlsw(&s
);
983 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
986 static struct device_attribute dev_attr_hotkey_radio_sw
=
987 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
989 /* sysfs hotkey report_mode -------------------------------------------- */
990 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
991 struct device_attribute
*attr
,
994 return snprintf(buf
, PAGE_SIZE
, "%d\n",
995 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
998 static struct device_attribute dev_attr_hotkey_report_mode
=
999 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
1001 /* --------------------------------------------------------------------- */
1003 static struct attribute
*hotkey_attributes
[] __initdata
= {
1004 &dev_attr_hotkey_enable
.attr
,
1005 &dev_attr_hotkey_report_mode
.attr
,
1008 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
1009 &dev_attr_hotkey_mask
.attr
,
1010 &dev_attr_hotkey_bios_enabled
.attr
,
1011 &dev_attr_hotkey_bios_mask
.attr
,
1012 &dev_attr_hotkey_all_mask
.attr
,
1013 &dev_attr_hotkey_recommended_mask
.attr
,
1016 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
1018 /* Requirements for changing the default keymaps:
1020 * 1. Many of the keys are mapped to KEY_RESERVED for very
1021 * good reasons. Do not change them unless you have deep
1022 * knowledge on the IBM and Lenovo ThinkPad firmware for
1023 * the various ThinkPad models. The driver behaves
1024 * differently for KEY_RESERVED: such keys have their
1025 * hot key mask *unset* in mask_recommended, and also
1026 * in the initial hot key mask programmed into the
1027 * firmware at driver load time, which means the firm-
1028 * ware may react very differently if you change them to
1031 * 2. You must be subscribed to the linux-thinkpad and
1032 * ibm-acpi-devel mailing lists, and you should read the
1033 * list archives since 2007 if you want to change the
1034 * keymaps. This requirement exists so that you will
1035 * know the past history of problems with the thinkpad-
1036 * acpi driver keymaps, and also that you will be
1037 * listening to any bug reports;
1039 * 3. Do not send thinkpad-acpi specific patches directly to
1040 * for merging, *ever*. Send them to the linux-acpi
1041 * mailinglist for comments. Merging is to be done only
1042 * through acpi-test and the ACPI maintainer.
1044 * If the above is too much to ask, don't change the keymap.
1045 * Ask the thinkpad-acpi maintainer to do it, instead.
1047 static u16 ibm_keycode_map
[] __initdata
= {
1048 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1049 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
1050 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1051 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1053 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1054 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1055 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1056 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1058 /* brightness: firmware always reacts to them, unless
1059 * X.org did some tricks in the radeon BIOS scratch
1060 * registers of *some* models */
1061 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1062 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1064 /* Thinklight: firmware always react to it */
1065 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1067 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1068 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1070 /* Volume: firmware always react to it and reprograms
1071 * the built-in *extra* mixer. Never map it to control
1072 * another mixer by default. */
1073 KEY_RESERVED
, /* 0x14: VOLUME UP */
1074 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1075 KEY_RESERVED
, /* 0x16: MUTE */
1077 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1079 /* (assignments unknown, please report if found) */
1080 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1081 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1083 static u16 lenovo_keycode_map
[] __initdata
= {
1084 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1085 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1086 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1087 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1089 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1090 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1091 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1092 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1094 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1095 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1097 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1099 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1100 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1102 /* Volume: z60/z61, T60 (BIOS version?): firmware always
1103 * react to it and reprograms the built-in *extra* mixer.
1104 * Never map it to control another mixer by default.
1106 * T60?, T61, R60?, R61: firmware and EC tries to send
1107 * these over the regular keyboard, so these are no-ops,
1108 * but there are still weird bugs re. MUTE, so do not
1109 * change unless you get test reports from all Lenovo
1110 * models. May cause the BIOS to interfere with the
1113 KEY_RESERVED
, /* 0x14: VOLUME UP */
1114 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1115 KEY_RESERVED
, /* 0x16: MUTE */
1117 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1119 /* (assignments unknown, please report if found) */
1120 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1121 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1124 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1125 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1126 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1132 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1134 BUG_ON(!tpacpi_inputdev
);
1136 IBM_ACPIHANDLE_INIT(hkey
);
1137 mutex_init(&hotkey_mutex
);
1139 /* hotkey not supported on 570 */
1140 tp_features
.hotkey
= hkey_handle
!= NULL
;
1142 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1143 str_supported(tp_features
.hotkey
));
1145 if (tp_features
.hotkey
) {
1146 hotkey_dev_attributes
= create_attr_set(8, NULL
);
1147 if (!hotkey_dev_attributes
)
1149 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1151 ARRAY_SIZE(hotkey_attributes
));
1155 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1156 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1157 for HKEY interface version 0x100 */
1158 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1159 if ((hkeyv
>> 8) != 1) {
1160 printk(IBM_ERR
"unknown version of the "
1161 "HKEY interface: 0x%x\n", hkeyv
);
1162 printk(IBM_ERR
"please report this to %s\n",
1166 * MHKV 0x100 in A31, R40, R40e,
1167 * T4x, X31, and later
1169 tp_features
.hotkey_mask
= 1;
1173 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1174 str_supported(tp_features
.hotkey_mask
));
1176 if (tp_features
.hotkey_mask
) {
1177 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1180 "missing MHKA handler, "
1181 "please report this to %s\n",
1183 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
1187 res
= hotkey_status_get(&hotkey_orig_status
);
1188 if (!res
&& tp_features
.hotkey_mask
) {
1189 res
= hotkey_mask_get();
1190 hotkey_orig_mask
= hotkey_mask
;
1192 res
= add_many_to_attr_set(
1193 hotkey_dev_attributes
,
1194 hotkey_mask_attributes
,
1195 ARRAY_SIZE(hotkey_mask_attributes
));
1199 /* Not all thinkpads have a hardware radio switch */
1200 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1201 tp_features
.hotkey_wlsw
= 1;
1203 "radio switch found; radios are %s\n",
1204 enabled(status
, 0));
1205 res
= add_to_attr_set(hotkey_dev_attributes
,
1206 &dev_attr_hotkey_radio_sw
.attr
);
1210 res
= register_attr_set_with_sysfs(
1211 hotkey_dev_attributes
,
1212 &tpacpi_pdev
->dev
.kobj
);
1216 /* Set up key map */
1218 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1220 if (!hotkey_keycode_map
) {
1221 printk(IBM_ERR
"failed to allocate memory for key map\n");
1225 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1226 dbg_printk(TPACPI_DBG_INIT
,
1227 "using Lenovo default hot key map\n");
1228 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1229 TPACPI_HOTKEY_MAP_SIZE
);
1231 dbg_printk(TPACPI_DBG_INIT
,
1232 "using IBM default hot key map\n");
1233 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1234 TPACPI_HOTKEY_MAP_SIZE
);
1237 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1238 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1239 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1240 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1241 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1242 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1243 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1244 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1245 set_bit(hotkey_keycode_map
[i
],
1246 tpacpi_inputdev
->keybit
);
1248 if (i
< sizeof(hotkey_reserved_mask
)*8)
1249 hotkey_reserved_mask
|= 1 << i
;
1253 if (tp_features
.hotkey_wlsw
) {
1254 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1255 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1258 dbg_printk(TPACPI_DBG_INIT
,
1259 "enabling hot key handling\n");
1260 res
= hotkey_status_set(1);
1263 res
= hotkey_mask_set((hotkey_all_mask
& ~hotkey_reserved_mask
)
1264 | hotkey_orig_mask
);
1268 dbg_printk(TPACPI_DBG_INIT
,
1269 "legacy hot key reporting over procfs %s\n",
1270 (hotkey_report_mode
< 2) ?
1271 "enabled" : "disabled");
1274 return (tp_features
.hotkey
)? 0 : 1;
1277 static void hotkey_exit(void)
1279 if (tp_features
.hotkey
) {
1280 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hot key mask\n");
1281 /* no short-circuit boolean operator below! */
1282 if ((hotkey_mask_set(hotkey_orig_mask
) |
1283 hotkey_status_set(hotkey_orig_status
)) != 0)
1284 printk(IBM_ERR
"failed to restore hot key mask to BIOS defaults\n");
1287 if (hotkey_dev_attributes
) {
1288 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1289 hotkey_dev_attributes
= NULL
;
1293 static void tpacpi_input_send_key(unsigned int scancode
,
1294 unsigned int keycode
)
1296 if (keycode
!= KEY_RESERVED
) {
1297 mutex_lock(&tpacpi_inputdev_send_mutex
);
1299 input_report_key(tpacpi_inputdev
, keycode
, 1);
1300 if (keycode
== KEY_UNKNOWN
)
1301 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1303 input_sync(tpacpi_inputdev
);
1305 input_report_key(tpacpi_inputdev
, keycode
, 0);
1306 if (keycode
== KEY_UNKNOWN
)
1307 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1309 input_sync(tpacpi_inputdev
);
1311 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1315 static void tpacpi_input_send_radiosw(void)
1319 mutex_lock(&tpacpi_inputdev_send_mutex
);
1321 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1322 input_report_switch(tpacpi_inputdev
,
1324 input_sync(tpacpi_inputdev
);
1327 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1330 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1333 unsigned int keycode
, scancode
;
1337 if (event
!= 0x80) {
1338 printk(IBM_ERR
"unknown HKEY notification event %d\n", event
);
1339 /* forward it to userspace, maybe it knows how to handle it */
1340 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
1341 ibm
->acpi
->device
->dev
.bus_id
,
1347 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1348 printk(IBM_ERR
"failed to retrieve HKEY event\n");
1360 switch (hkey
>> 12) {
1362 /* 0x1000-0x1FFF: key presses */
1363 scancode
= hkey
& 0xfff;
1364 if (scancode
> 0 && scancode
< 0x21) {
1366 keycode
= hotkey_keycode_map
[scancode
];
1367 tpacpi_input_send_key(scancode
, keycode
);
1370 "hotkey 0x%04x out of range for keyboard map\n",
1376 /* 0x5000-0x5FFF: LID */
1377 /* we don't handle it through this path, just
1378 * eat up known LID events */
1379 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1381 "unknown LID-related HKEY event: 0x%04x\n",
1389 /* 0x7000-0x7FFF: misc */
1390 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1391 tpacpi_input_send_radiosw();
1394 /* fallthrough to default */
1396 /* case 2: dock-related */
1397 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1398 /* case 3: ultra-bay related. maybe bay in dock? */
1399 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1400 printk(IBM_NOTICE
"unhandled HKEY event 0x%04x\n", hkey
);
1405 if (!ignore_acpi_ev
&& (send_acpi_ev
|| hotkey_report_mode
< 2)) {
1406 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, hkey
);
1409 /* netlink events */
1410 if (!ignore_acpi_ev
&& send_acpi_ev
) {
1411 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
1412 ibm
->acpi
->device
->dev
.bus_id
,
1418 static void hotkey_resume(void)
1420 if (hotkey_mask_get())
1421 printk(IBM_ERR
"error while trying to read hot key mask from firmware\n");
1422 tpacpi_input_send_radiosw();
1425 /* procfs -------------------------------------------------------------- */
1426 static int hotkey_read(char *p
)
1431 if (!tp_features
.hotkey
) {
1432 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1436 if (mutex_lock_interruptible(&hotkey_mutex
))
1437 return -ERESTARTSYS
;
1438 res
= hotkey_status_get(&status
);
1440 res
= hotkey_mask_get();
1441 mutex_unlock(&hotkey_mutex
);
1445 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1446 if (tp_features
.hotkey_mask
) {
1447 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
1448 len
+= sprintf(p
+ len
,
1449 "commands:\tenable, disable, reset, <mask>\n");
1451 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1452 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1458 static int hotkey_write(char *buf
)
1464 if (!tp_features
.hotkey
)
1467 if (mutex_lock_interruptible(&hotkey_mutex
))
1468 return -ERESTARTSYS
;
1474 while ((cmd
= next_cmd(&buf
))) {
1475 if (strlencmp(cmd
, "enable") == 0) {
1477 } else if (strlencmp(cmd
, "disable") == 0) {
1479 } else if (strlencmp(cmd
, "reset") == 0) {
1480 status
= hotkey_orig_status
;
1481 mask
= hotkey_orig_mask
;
1482 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1484 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1492 res
= hotkey_status_set(status
);
1494 if (!res
&& mask
!= hotkey_mask
)
1495 res
= hotkey_mask_set(mask
);
1498 mutex_unlock(&hotkey_mutex
);
1502 static const struct acpi_device_id ibm_htk_device_ids
[] = {
1507 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1508 .hid
= ibm_htk_device_ids
,
1509 .notify
= hotkey_notify
,
1510 .handle
= &hkey_handle
,
1511 .type
= ACPI_DEVICE_NOTIFY
,
1514 static struct ibm_struct hotkey_driver_data
= {
1516 .read
= hotkey_read
,
1517 .write
= hotkey_write
,
1518 .exit
= hotkey_exit
,
1519 .resume
= hotkey_resume
,
1520 .acpi
= &ibm_hotkey_acpidriver
,
1523 /*************************************************************************
1524 * Bluetooth subdriver
1527 /* sysfs bluetooth enable ---------------------------------------------- */
1528 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1529 struct device_attribute
*attr
,
1534 status
= bluetooth_get_radiosw();
1538 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1541 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1542 struct device_attribute
*attr
,
1543 const char *buf
, size_t count
)
1548 if (parse_strtoul(buf
, 1, &t
))
1551 res
= bluetooth_set_radiosw(t
);
1553 return (res
) ? res
: count
;
1556 static struct device_attribute dev_attr_bluetooth_enable
=
1557 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1558 bluetooth_enable_show
, bluetooth_enable_store
);
1560 /* --------------------------------------------------------------------- */
1562 static struct attribute
*bluetooth_attributes
[] = {
1563 &dev_attr_bluetooth_enable
.attr
,
1567 static const struct attribute_group bluetooth_attr_group
= {
1568 .attrs
= bluetooth_attributes
,
1571 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1576 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1578 IBM_ACPIHANDLE_INIT(hkey
);
1580 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1581 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1582 tp_features
.bluetooth
= hkey_handle
&&
1583 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1585 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1586 str_supported(tp_features
.bluetooth
),
1589 if (tp_features
.bluetooth
) {
1590 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1591 /* no bluetooth hardware present in system */
1592 tp_features
.bluetooth
= 0;
1593 dbg_printk(TPACPI_DBG_INIT
,
1594 "bluetooth hardware not installed\n");
1596 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1597 &bluetooth_attr_group
);
1603 return (tp_features
.bluetooth
)? 0 : 1;
1606 static void bluetooth_exit(void)
1608 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1609 &bluetooth_attr_group
);
1612 static int bluetooth_get_radiosw(void)
1616 if (!tp_features
.bluetooth
)
1619 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1622 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1625 static int bluetooth_set_radiosw(int radio_on
)
1629 if (!tp_features
.bluetooth
)
1632 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1635 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1637 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1638 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1644 /* procfs -------------------------------------------------------------- */
1645 static int bluetooth_read(char *p
)
1648 int status
= bluetooth_get_radiosw();
1650 if (!tp_features
.bluetooth
)
1651 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1653 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1654 (status
)? "enabled" : "disabled");
1655 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1661 static int bluetooth_write(char *buf
)
1665 if (!tp_features
.bluetooth
)
1668 while ((cmd
= next_cmd(&buf
))) {
1669 if (strlencmp(cmd
, "enable") == 0) {
1670 bluetooth_set_radiosw(1);
1671 } else if (strlencmp(cmd
, "disable") == 0) {
1672 bluetooth_set_radiosw(0);
1680 static struct ibm_struct bluetooth_driver_data
= {
1681 .name
= "bluetooth",
1682 .read
= bluetooth_read
,
1683 .write
= bluetooth_write
,
1684 .exit
= bluetooth_exit
,
1687 /*************************************************************************
1691 /* sysfs wan enable ---------------------------------------------------- */
1692 static ssize_t
wan_enable_show(struct device
*dev
,
1693 struct device_attribute
*attr
,
1698 status
= wan_get_radiosw();
1702 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1705 static ssize_t
wan_enable_store(struct device
*dev
,
1706 struct device_attribute
*attr
,
1707 const char *buf
, size_t count
)
1712 if (parse_strtoul(buf
, 1, &t
))
1715 res
= wan_set_radiosw(t
);
1717 return (res
) ? res
: count
;
1720 static struct device_attribute dev_attr_wan_enable
=
1721 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1722 wan_enable_show
, wan_enable_store
);
1724 /* --------------------------------------------------------------------- */
1726 static struct attribute
*wan_attributes
[] = {
1727 &dev_attr_wan_enable
.attr
,
1731 static const struct attribute_group wan_attr_group
= {
1732 .attrs
= wan_attributes
,
1735 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1740 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1742 IBM_ACPIHANDLE_INIT(hkey
);
1744 tp_features
.wan
= hkey_handle
&&
1745 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1747 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1748 str_supported(tp_features
.wan
),
1751 if (tp_features
.wan
) {
1752 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1753 /* no wan hardware present in system */
1754 tp_features
.wan
= 0;
1755 dbg_printk(TPACPI_DBG_INIT
,
1756 "wan hardware not installed\n");
1758 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1765 return (tp_features
.wan
)? 0 : 1;
1768 static void wan_exit(void)
1770 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1774 static int wan_get_radiosw(void)
1778 if (!tp_features
.wan
)
1781 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1784 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1787 static int wan_set_radiosw(int radio_on
)
1791 if (!tp_features
.wan
)
1794 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1797 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1799 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1800 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1806 /* procfs -------------------------------------------------------------- */
1807 static int wan_read(char *p
)
1810 int status
= wan_get_radiosw();
1812 if (!tp_features
.wan
)
1813 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1815 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1816 (status
)? "enabled" : "disabled");
1817 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1823 static int wan_write(char *buf
)
1827 if (!tp_features
.wan
)
1830 while ((cmd
= next_cmd(&buf
))) {
1831 if (strlencmp(cmd
, "enable") == 0) {
1833 } else if (strlencmp(cmd
, "disable") == 0) {
1842 static struct ibm_struct wan_driver_data
= {
1847 .flags
.experimental
= 1,
1850 /*************************************************************************
1854 static enum video_access_mode video_supported
;
1855 static int video_orig_autosw
;
1857 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1858 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1859 "\\_SB.PCI0.VID0", /* 770e */
1860 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1861 "\\_SB.PCI0.AGP.VID", /* all others */
1864 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1866 static int __init
video_init(struct ibm_init_struct
*iibm
)
1870 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1872 IBM_ACPIHANDLE_INIT(vid
);
1873 IBM_ACPIHANDLE_INIT(vid2
);
1875 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1876 /* G41, assume IVGA doesn't change */
1877 vid_handle
= vid2_handle
;
1880 /* video switching not supported on R30, R31 */
1881 video_supported
= TPACPI_VIDEO_NONE
;
1882 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1884 video_supported
= TPACPI_VIDEO_570
;
1885 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1886 /* 600e/x, 770e, 770x */
1887 video_supported
= TPACPI_VIDEO_770
;
1890 video_supported
= TPACPI_VIDEO_NEW
;
1892 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1893 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1896 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1899 static void video_exit(void)
1901 dbg_printk(TPACPI_DBG_EXIT
,
1902 "restoring original video autoswitch mode\n");
1903 if (video_autosw_set(video_orig_autosw
))
1904 printk(IBM_ERR
"error while trying to restore original "
1905 "video autoswitch mode\n");
1908 static int video_outputsw_get(void)
1913 switch (video_supported
) {
1914 case TPACPI_VIDEO_570
:
1915 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1916 TP_ACPI_VIDEO_570_PHSCMD
))
1918 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1920 case TPACPI_VIDEO_770
:
1921 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1924 status
|= TP_ACPI_VIDEO_S_LCD
;
1925 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1928 status
|= TP_ACPI_VIDEO_S_CRT
;
1930 case TPACPI_VIDEO_NEW
:
1931 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1932 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1935 status
|= TP_ACPI_VIDEO_S_CRT
;
1937 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1938 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1941 status
|= TP_ACPI_VIDEO_S_LCD
;
1942 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1945 status
|= TP_ACPI_VIDEO_S_DVI
;
1954 static int video_outputsw_set(int status
)
1959 switch (video_supported
) {
1960 case TPACPI_VIDEO_570
:
1961 res
= acpi_evalf(NULL
, NULL
,
1962 "\\_SB.PHS2", "vdd",
1963 TP_ACPI_VIDEO_570_PHS2CMD
,
1964 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1966 case TPACPI_VIDEO_770
:
1967 autosw
= video_autosw_get();
1971 res
= video_autosw_set(1);
1974 res
= acpi_evalf(vid_handle
, NULL
,
1975 "ASWT", "vdd", status
* 0x100, 0);
1976 if (!autosw
&& video_autosw_set(autosw
)) {
1977 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1981 case TPACPI_VIDEO_NEW
:
1982 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1983 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1989 return (res
)? 0 : -EIO
;
1992 static int video_autosw_get(void)
1996 switch (video_supported
) {
1997 case TPACPI_VIDEO_570
:
1998 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
2001 case TPACPI_VIDEO_770
:
2002 case TPACPI_VIDEO_NEW
:
2003 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
2013 static int video_autosw_set(int enable
)
2015 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
2020 static int video_outputsw_cycle(void)
2022 int autosw
= video_autosw_get();
2028 switch (video_supported
) {
2029 case TPACPI_VIDEO_570
:
2030 res
= video_autosw_set(1);
2033 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
2035 case TPACPI_VIDEO_770
:
2036 case TPACPI_VIDEO_NEW
:
2037 res
= video_autosw_set(1);
2040 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
2045 if (!autosw
&& video_autosw_set(autosw
)) {
2046 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
2050 return (res
)? 0 : -EIO
;
2053 static int video_expand_toggle(void)
2055 switch (video_supported
) {
2056 case TPACPI_VIDEO_570
:
2057 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
2059 case TPACPI_VIDEO_770
:
2060 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
2062 case TPACPI_VIDEO_NEW
:
2063 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
2071 static int video_read(char *p
)
2076 if (video_supported
== TPACPI_VIDEO_NONE
) {
2077 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2081 status
= video_outputsw_get();
2085 autosw
= video_autosw_get();
2089 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2090 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2091 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2092 if (video_supported
== TPACPI_VIDEO_NEW
)
2093 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2094 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2095 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2096 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2097 if (video_supported
== TPACPI_VIDEO_NEW
)
2098 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2099 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2100 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2105 static int video_write(char *buf
)
2108 int enable
, disable
, status
;
2111 if (video_supported
== TPACPI_VIDEO_NONE
)
2117 while ((cmd
= next_cmd(&buf
))) {
2118 if (strlencmp(cmd
, "lcd_enable") == 0) {
2119 enable
|= TP_ACPI_VIDEO_S_LCD
;
2120 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2121 disable
|= TP_ACPI_VIDEO_S_LCD
;
2122 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2123 enable
|= TP_ACPI_VIDEO_S_CRT
;
2124 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2125 disable
|= TP_ACPI_VIDEO_S_CRT
;
2126 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2127 strlencmp(cmd
, "dvi_enable") == 0) {
2128 enable
|= TP_ACPI_VIDEO_S_DVI
;
2129 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2130 strlencmp(cmd
, "dvi_disable") == 0) {
2131 disable
|= TP_ACPI_VIDEO_S_DVI
;
2132 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2133 res
= video_autosw_set(1);
2136 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2137 res
= video_autosw_set(0);
2140 } else if (strlencmp(cmd
, "video_switch") == 0) {
2141 res
= video_outputsw_cycle();
2144 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2145 res
= video_expand_toggle();
2152 if (enable
|| disable
) {
2153 status
= video_outputsw_get();
2156 res
= video_outputsw_set((status
& ~disable
) | enable
);
2164 static struct ibm_struct video_driver_data
= {
2167 .write
= video_write
,
2171 /*************************************************************************
2172 * Light (thinklight) subdriver
2175 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2176 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2178 static int __init
light_init(struct ibm_init_struct
*iibm
)
2180 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2182 IBM_ACPIHANDLE_INIT(ledb
);
2183 IBM_ACPIHANDLE_INIT(lght
);
2184 IBM_ACPIHANDLE_INIT(cmos
);
2186 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2187 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2189 if (tp_features
.light
)
2190 /* light status not supported on
2191 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2192 tp_features
.light_status
=
2193 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2195 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2196 str_supported(tp_features
.light
));
2198 return (tp_features
.light
)? 0 : 1;
2201 static int light_read(char *p
)
2206 if (!tp_features
.light
) {
2207 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2208 } else if (!tp_features
.light_status
) {
2209 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2210 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2212 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2214 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2215 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2221 static int light_write(char *buf
)
2223 int cmos_cmd
, lght_cmd
;
2227 if (!tp_features
.light
)
2230 while ((cmd
= next_cmd(&buf
))) {
2231 if (strlencmp(cmd
, "on") == 0) {
2234 } else if (strlencmp(cmd
, "off") == 0) {
2240 success
= cmos_handle
?
2241 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2242 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2250 static struct ibm_struct light_driver_data
= {
2253 .write
= light_write
,
2256 /*************************************************************************
2260 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2262 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2263 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2264 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2265 "\\_SB.PCI.ISA.SLCE", /* 570 */
2266 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2268 /* don't list other alternatives as we install a notify handler on the 570 */
2269 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2271 static const struct acpi_device_id ibm_pci_device_ids
[] = {
2272 {PCI_ROOT_HID_STRING
, 0},
2276 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2278 .notify
= dock_notify
,
2279 .handle
= &dock_handle
,
2280 .type
= ACPI_SYSTEM_NOTIFY
,
2283 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2284 * We just use it to get notifications of dock hotplug
2285 * in very old thinkpads */
2286 .hid
= ibm_pci_device_ids
,
2287 .notify
= dock_notify
,
2288 .handle
= &pci_handle
,
2289 .type
= ACPI_SYSTEM_NOTIFY
,
2293 static struct ibm_struct dock_driver_data
[2] = {
2297 .write
= dock_write
,
2298 .acpi
= &ibm_dock_acpidriver
[0],
2302 .acpi
= &ibm_dock_acpidriver
[1],
2306 #define dock_docked() (_sta(dock_handle) & 1)
2308 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2310 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2312 IBM_ACPIHANDLE_INIT(dock
);
2314 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2315 str_supported(dock_handle
!= NULL
));
2317 return (dock_handle
)? 0 : 1;
2320 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2324 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2326 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2327 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2328 IBM_ACPIHANDLE_INIT(pci
);
2329 dock2_needed
= (pci_handle
!= NULL
);
2330 vdbg_printk(TPACPI_DBG_INIT
,
2331 "dock PCI handler for the TP 570 is %s\n",
2332 str_supported(dock2_needed
));
2334 vdbg_printk(TPACPI_DBG_INIT
,
2335 "dock subdriver part 2 not required\n");
2339 return (dock2_needed
)? 0 : 1;
2342 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2344 int docked
= dock_docked();
2345 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
2346 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
2349 if (event
== 1 && !pci
) /* 570 */
2350 data
= 1; /* button */
2351 else if (event
== 1 && pci
) /* 570 */
2352 data
= 3; /* dock */
2353 else if (event
== 3 && docked
)
2354 data
= 1; /* button */
2355 else if (event
== 3 && !docked
)
2356 data
= 2; /* undock */
2357 else if (event
== 0 && docked
)
2358 data
= 3; /* dock */
2360 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2361 event
, _sta(dock_handle
));
2362 data
= 0; /* unknown */
2364 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
2365 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
2366 ibm
->acpi
->device
->dev
.bus_id
,
2370 static int dock_read(char *p
)
2373 int docked
= dock_docked();
2376 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2378 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2380 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2381 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2387 static int dock_write(char *buf
)
2394 while ((cmd
= next_cmd(&buf
))) {
2395 if (strlencmp(cmd
, "undock") == 0) {
2396 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2397 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2399 } else if (strlencmp(cmd
, "dock") == 0) {
2400 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2409 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2411 /*************************************************************************
2415 #ifdef CONFIG_THINKPAD_ACPI_BAY
2416 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2417 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2418 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2419 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2420 ); /* A21e, R30, R31 */
2421 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2422 "_EJ0", /* all others */
2423 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2424 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2425 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2427 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2431 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2433 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2435 IBM_ACPIHANDLE_INIT(bay
);
2437 IBM_ACPIHANDLE_INIT(bay_ej
);
2438 IBM_ACPIHANDLE_INIT(bay2
);
2440 IBM_ACPIHANDLE_INIT(bay2_ej
);
2442 tp_features
.bay_status
= bay_handle
&&
2443 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2444 tp_features
.bay_status2
= bay2_handle
&&
2445 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2447 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2448 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2449 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2450 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2452 vdbg_printk(TPACPI_DBG_INIT
,
2453 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2454 str_supported(tp_features
.bay_status
),
2455 str_supported(tp_features
.bay_eject
),
2456 str_supported(tp_features
.bay_status2
),
2457 str_supported(tp_features
.bay_eject2
));
2459 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2460 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2463 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2465 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
2466 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
2467 ibm
->acpi
->device
->dev
.bus_id
,
2471 #define bay_occupied(b) (_sta(b##_handle) & 1)
2473 static int bay_read(char *p
)
2476 int occupied
= bay_occupied(bay
);
2477 int occupied2
= bay_occupied(bay2
);
2480 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2481 tp_features
.bay_status
?
2482 (occupied
? "occupied" : "unoccupied") :
2484 if (tp_features
.bay_status2
)
2485 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2486 "occupied" : "unoccupied");
2488 eject
= tp_features
.bay_eject
&& occupied
;
2489 eject2
= tp_features
.bay_eject2
&& occupied2
;
2491 if (eject
&& eject2
)
2492 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2494 len
+= sprintf(p
+ len
, "commands:\teject\n");
2496 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2501 static int bay_write(char *buf
)
2505 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2508 while ((cmd
= next_cmd(&buf
))) {
2509 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2510 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2512 } else if (tp_features
.bay_eject2
&&
2513 strlencmp(cmd
, "eject2") == 0) {
2514 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2523 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2524 .notify
= bay_notify
,
2525 .handle
= &bay_handle
,
2526 .type
= ACPI_SYSTEM_NOTIFY
,
2529 static struct ibm_struct bay_driver_data
= {
2533 .acpi
= &ibm_bay_acpidriver
,
2536 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2538 /*************************************************************************
2542 /* sysfs cmos_command -------------------------------------------------- */
2543 static ssize_t
cmos_command_store(struct device
*dev
,
2544 struct device_attribute
*attr
,
2545 const char *buf
, size_t count
)
2547 unsigned long cmos_cmd
;
2550 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2553 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2554 return (res
)? res
: count
;
2557 static struct device_attribute dev_attr_cmos_command
=
2558 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2560 /* --------------------------------------------------------------------- */
2562 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2566 vdbg_printk(TPACPI_DBG_INIT
,
2567 "initializing cmos commands subdriver\n");
2569 IBM_ACPIHANDLE_INIT(cmos
);
2571 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2572 str_supported(cmos_handle
!= NULL
));
2574 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2578 return (cmos_handle
)? 0 : 1;
2581 static void cmos_exit(void)
2583 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2586 static int cmos_read(char *p
)
2590 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2591 R30, R31, T20-22, X20-21 */
2593 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2595 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2596 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2602 static int cmos_write(char *buf
)
2607 while ((cmd
= next_cmd(&buf
))) {
2608 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2609 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2614 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2622 static struct ibm_struct cmos_driver_data
= {
2625 .write
= cmos_write
,
2629 /*************************************************************************
2633 static enum led_access_mode led_supported
;
2635 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2636 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2637 "LED", /* all others */
2640 static int __init
led_init(struct ibm_init_struct
*iibm
)
2642 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2644 IBM_ACPIHANDLE_INIT(led
);
2647 /* led not supported on R30, R31 */
2648 led_supported
= TPACPI_LED_NONE
;
2649 else if (strlencmp(led_path
, "SLED") == 0)
2651 led_supported
= TPACPI_LED_570
;
2652 else if (strlencmp(led_path
, "SYSL") == 0)
2653 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2654 led_supported
= TPACPI_LED_OLD
;
2657 led_supported
= TPACPI_LED_NEW
;
2659 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2660 str_supported(led_supported
), led_supported
);
2662 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2665 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2667 static int led_read(char *p
)
2671 if (!led_supported
) {
2672 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2675 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2677 if (led_supported
== TPACPI_LED_570
) {
2680 for (i
= 0; i
< 8; i
++) {
2681 if (!acpi_evalf(ec_handle
,
2682 &status
, "GLED", "dd", 1 << i
))
2684 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2685 i
, led_status(status
));
2689 len
+= sprintf(p
+ len
, "commands:\t"
2690 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2695 /* off, on, blink */
2696 static const int led_sled_arg1
[] = { 0, 1, 3 };
2697 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2698 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2699 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2701 static int led_write(char *buf
)
2709 while ((cmd
= next_cmd(&buf
))) {
2710 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2713 if (strstr(cmd
, "off")) {
2715 } else if (strstr(cmd
, "on")) {
2717 } else if (strstr(cmd
, "blink")) {
2722 if (led_supported
== TPACPI_LED_570
) {
2725 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2726 led
, led_sled_arg1
[ind
]))
2728 } else if (led_supported
== TPACPI_LED_OLD
) {
2729 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2731 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2734 ec_write(TPACPI_LED_EC_HLBL
,
2735 led
* led_exp_hlbl
[ind
]);
2738 ec_write(TPACPI_LED_EC_HLCL
,
2739 led
* led_exp_hlcl
[ind
]);
2744 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2745 led
, led_led_arg1
[ind
]))
2753 static struct ibm_struct led_driver_data
= {
2759 /*************************************************************************
2763 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2765 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2767 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2769 IBM_ACPIHANDLE_INIT(beep
);
2771 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2772 str_supported(beep_handle
!= NULL
));
2774 return (beep_handle
)? 0 : 1;
2777 static int beep_read(char *p
)
2782 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2784 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2785 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2791 static int beep_write(char *buf
)
2799 while ((cmd
= next_cmd(&buf
))) {
2800 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2801 beep_cmd
>= 0 && beep_cmd
<= 17) {
2805 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2812 static struct ibm_struct beep_driver_data
= {
2815 .write
= beep_write
,
2818 /*************************************************************************
2822 static enum thermal_access_mode thermal_read_mode
;
2824 /* sysfs temp##_input -------------------------------------------------- */
2826 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2827 struct device_attribute
*attr
,
2830 struct sensor_device_attribute
*sensor_attr
=
2831 to_sensor_dev_attr(attr
);
2832 int idx
= sensor_attr
->index
;
2836 res
= thermal_get_sensor(idx
, &value
);
2839 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2842 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2845 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2846 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2848 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2849 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2850 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2851 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2852 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2853 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2854 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2855 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2856 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2857 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2858 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2859 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2860 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2861 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2862 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2863 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2864 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2867 #define THERMAL_ATTRS(X) \
2868 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2870 static struct attribute
*thermal_temp_input_attr
[] = {
2890 static const struct attribute_group thermal_temp_input16_group
= {
2891 .attrs
= thermal_temp_input_attr
2894 static const struct attribute_group thermal_temp_input8_group
= {
2895 .attrs
= &thermal_temp_input_attr
[8]
2898 #undef THERMAL_SENSOR_ATTR_TEMP
2899 #undef THERMAL_ATTRS
2901 /* --------------------------------------------------------------------- */
2903 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2910 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2912 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2914 if (thinkpad_id
.ec_model
) {
2916 * Direct EC access mode: sensors at registers
2917 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2918 * non-implemented, thermal sensors return 0x80 when
2923 for (i
= 0; i
< 8; i
++) {
2924 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2930 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2938 /* This is sheer paranoia, but we handle it anyway */
2941 "ThinkPad ACPI EC access misbehaving, "
2942 "falling back to ACPI TMPx access mode\n");
2943 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2946 "ThinkPad ACPI EC access misbehaving, "
2947 "disabling thermal sensors access\n");
2948 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2953 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2955 } else if (acpi_tmp7
) {
2956 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2957 /* 600e/x, 770e, 770x */
2958 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2960 /* Standard ACPI TMPx access, max 8 sensors */
2961 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2964 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2965 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2968 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2969 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2972 switch(thermal_read_mode
) {
2973 case TPACPI_THERMAL_TPEC_16
:
2974 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2975 &thermal_temp_input16_group
);
2979 case TPACPI_THERMAL_TPEC_8
:
2980 case TPACPI_THERMAL_ACPI_TMP07
:
2981 case TPACPI_THERMAL_ACPI_UPDT
:
2982 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2983 &thermal_temp_input8_group
);
2987 case TPACPI_THERMAL_NONE
:
2995 static void thermal_exit(void)
2997 switch(thermal_read_mode
) {
2998 case TPACPI_THERMAL_TPEC_16
:
2999 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3000 &thermal_temp_input16_group
);
3002 case TPACPI_THERMAL_TPEC_8
:
3003 case TPACPI_THERMAL_ACPI_TMP07
:
3004 case TPACPI_THERMAL_ACPI_UPDT
:
3005 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3006 &thermal_temp_input16_group
);
3008 case TPACPI_THERMAL_NONE
:
3014 /* idx is zero-based */
3015 static int thermal_get_sensor(int idx
, s32
*value
)
3021 t
= TP_EC_THERMAL_TMP0
;
3023 switch (thermal_read_mode
) {
3024 #if TPACPI_MAX_THERMAL_SENSORS >= 16
3025 case TPACPI_THERMAL_TPEC_16
:
3026 if (idx
>= 8 && idx
<= 15) {
3027 t
= TP_EC_THERMAL_TMP8
;
3032 case TPACPI_THERMAL_TPEC_8
:
3034 if (!acpi_ec_read(t
+ idx
, &tmp
))
3036 *value
= tmp
* 1000;
3041 case TPACPI_THERMAL_ACPI_UPDT
:
3043 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3044 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
3046 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3048 *value
= (t
- 2732) * 100;
3053 case TPACPI_THERMAL_ACPI_TMP07
:
3055 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3056 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3058 if (t
> 127 || t
< -127)
3059 t
= TP_EC_THERMAL_TMP_NA
;
3065 case TPACPI_THERMAL_NONE
:
3073 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
3084 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
3087 for(i
= 0 ; i
< n
; i
++) {
3088 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3096 static int thermal_read(char *p
)
3100 struct ibm_thermal_sensors_struct t
;
3102 n
= thermal_get_sensors(&t
);
3103 if (unlikely(n
< 0))
3106 len
+= sprintf(p
+ len
, "temperatures:\t");
3109 for (i
= 0; i
< (n
- 1); i
++)
3110 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3111 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3113 len
+= sprintf(p
+ len
, "not supported\n");
3118 static struct ibm_struct thermal_driver_data
= {
3120 .read
= thermal_read
,
3121 .exit
= thermal_exit
,
3124 /*************************************************************************
3128 static u8 ecdump_regs
[256];
3130 static int ecdump_read(char *p
)
3136 len
+= sprintf(p
+ len
, "EC "
3137 " +00 +01 +02 +03 +04 +05 +06 +07"
3138 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
3139 for (i
= 0; i
< 256; i
+= 16) {
3140 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
3141 for (j
= 0; j
< 16; j
++) {
3142 if (!acpi_ec_read(i
+ j
, &v
))
3144 if (v
!= ecdump_regs
[i
+ j
])
3145 len
+= sprintf(p
+ len
, " *%02x", v
);
3147 len
+= sprintf(p
+ len
, " %02x", v
);
3148 ecdump_regs
[i
+ j
] = v
;
3150 len
+= sprintf(p
+ len
, "\n");
3155 /* These are way too dangerous to advertise openly... */
3157 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3158 " (<offset> is 00-ff, <value> is 00-ff)\n");
3159 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3160 " (<offset> is 00-ff, <value> is 0-255)\n");
3165 static int ecdump_write(char *buf
)
3170 while ((cmd
= next_cmd(&buf
))) {
3171 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3173 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3177 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3178 if (!acpi_ec_write(i
, v
))
3187 static struct ibm_struct ecdump_driver_data
= {
3189 .read
= ecdump_read
,
3190 .write
= ecdump_write
,
3191 .flags
.experimental
= 1,
3194 /*************************************************************************
3195 * Backlight/brightness subdriver
3198 static struct backlight_device
*ibm_backlight_device
;
3200 static struct backlight_ops ibm_backlight_data
= {
3201 .get_brightness
= brightness_get
,
3202 .update_status
= brightness_update_status
,
3205 static struct mutex brightness_mutex
;
3207 static int __init
tpacpi_query_bcll_levels(acpi_handle handle
)
3209 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
3210 union acpi_object
*obj
;
3213 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
3214 obj
= (union acpi_object
*)buffer
.pointer
;
3215 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
3216 printk(IBM_ERR
"Unknown BCLL data, "
3217 "please report this to %s\n", IBM_MAIL
);
3220 rc
= obj
->package
.count
;
3226 kfree(buffer
.pointer
);
3230 static acpi_status __init
brightness_find_bcll(acpi_handle handle
, u32 lvl
,
3231 void *context
, void **rv
)
3233 char name
[ACPI_PATH_SEGMENT_LENGTH
];
3234 struct acpi_buffer buffer
= { sizeof(name
), &name
};
3236 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
3237 !strncmp("BCLL", name
, sizeof(name
) - 1)) {
3238 if (tpacpi_query_bcll_levels(handle
) == 16) {
3240 return AE_CTRL_TERMINATE
;
3249 static int __init
brightness_check_levels(void)
3252 void *found_node
= NULL
;
3255 IBM_ACPIHANDLE_INIT(vid
);
3260 /* Search for a BCLL package with 16 levels */
3261 status
= acpi_walk_namespace(ACPI_TYPE_PACKAGE
, vid_handle
, 3,
3262 brightness_find_bcll
, NULL
, &found_node
);
3264 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
3267 static acpi_status __init
brightness_find_bcl(acpi_handle handle
, u32 lvl
,
3268 void *context
, void **rv
)
3270 char name
[ACPI_PATH_SEGMENT_LENGTH
];
3271 struct acpi_buffer buffer
= { sizeof(name
), &name
};
3273 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
3274 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
3276 return AE_CTRL_TERMINATE
;
3282 static int __init
brightness_check_std_acpi_support(void)
3285 void *found_node
= NULL
;
3288 IBM_ACPIHANDLE_INIT(vid
);
3293 /* Search for a _BCL method, but don't execute it */
3294 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
3295 brightness_find_bcl
, NULL
, &found_node
);
3297 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
3300 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
3304 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
3306 mutex_init(&brightness_mutex
);
3308 if (!brightness_enable
) {
3309 dbg_printk(TPACPI_DBG_INIT
,
3310 "brightness support disabled by module parameter\n");
3312 } else if (brightness_enable
> 1) {
3313 if (brightness_check_std_acpi_support()) {
3315 "standard ACPI backlight interface available, not loading native one...\n");
3320 if (!brightness_mode
) {
3321 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
3322 brightness_mode
= 2;
3324 brightness_mode
= 3;
3326 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
3330 if (brightness_mode
> 3)
3333 tp_features
.bright_16levels
=
3334 thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
&&
3335 brightness_check_levels();
3337 b
= brightness_get(NULL
);
3341 if (tp_features
.bright_16levels
)
3342 printk(IBM_INFO
"detected a 16-level brightness capable ThinkPad\n");
3344 ibm_backlight_device
= backlight_device_register(
3345 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
3346 &ibm_backlight_data
);
3347 if (IS_ERR(ibm_backlight_device
)) {
3348 printk(IBM_ERR
"Could not register backlight device\n");
3349 return PTR_ERR(ibm_backlight_device
);
3351 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
3353 ibm_backlight_device
->props
.max_brightness
=
3354 (tp_features
.bright_16levels
)? 15 : 7;
3355 ibm_backlight_device
->props
.brightness
= b
;
3356 backlight_update_status(ibm_backlight_device
);
3361 static void brightness_exit(void)
3363 if (ibm_backlight_device
) {
3364 vdbg_printk(TPACPI_DBG_EXIT
,
3365 "calling backlight_device_unregister()\n");
3366 backlight_device_unregister(ibm_backlight_device
);
3367 ibm_backlight_device
= NULL
;
3371 static int brightness_update_status(struct backlight_device
*bd
)
3373 /* it is the backlight class's job (caller) to handle
3374 * EINTR and other errors properly */
3375 return brightness_set(
3376 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
3377 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
3378 bd
->props
.brightness
: 0);
3382 * ThinkPads can read brightness from two places: EC 0x31, or
3383 * CMOS NVRAM byte 0x5E, bits 0-3.
3385 static int brightness_get(struct backlight_device
*bd
)
3387 u8 lec
= 0, lcmos
= 0, level
= 0;
3389 if (brightness_mode
& 1) {
3390 if (!acpi_ec_read(brightness_offset
, &lec
))
3392 lec
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3395 if (brightness_mode
& 2) {
3396 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3397 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3398 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3399 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3403 if (brightness_mode
== 3 && lec
!= lcmos
) {
3405 "CMOS NVRAM (%u) and EC (%u) do not agree "
3406 "on display brightness level\n",
3407 (unsigned int) lcmos
,
3408 (unsigned int) lec
);
3415 /* May return EINTR which can always be mapped to ERESTARTSYS */
3416 static int brightness_set(int value
)
3418 int cmos_cmd
, inc
, i
, res
;
3421 if (value
> ((tp_features
.bright_16levels
)? 15 : 7))
3424 res
= mutex_lock_interruptible(&brightness_mutex
);
3428 current_value
= brightness_get(NULL
);
3429 if (current_value
< 0) {
3430 res
= current_value
;
3434 cmos_cmd
= value
> current_value
?
3435 TP_CMOS_BRIGHTNESS_UP
:
3436 TP_CMOS_BRIGHTNESS_DOWN
;
3437 inc
= (value
> current_value
)? 1 : -1;
3440 for (i
= current_value
; i
!= value
; i
+= inc
) {
3441 if ((brightness_mode
& 2) &&
3442 issue_thinkpad_cmos_command(cmos_cmd
)) {
3446 if ((brightness_mode
& 1) &&
3447 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
3454 mutex_unlock(&brightness_mutex
);
3458 static int brightness_read(char *p
)
3463 if ((level
= brightness_get(NULL
)) < 0) {
3464 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3466 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
3467 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3468 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3469 " (<level> is 0-%d)\n",
3470 (tp_features
.bright_16levels
) ? 15 : 7);
3476 static int brightness_write(char *buf
)
3481 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
3483 level
= brightness_get(NULL
);
3487 while ((cmd
= next_cmd(&buf
))) {
3488 if (strlencmp(cmd
, "up") == 0) {
3489 if (level
< max_level
)
3491 } else if (strlencmp(cmd
, "down") == 0) {
3494 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
3495 level
>= 0 && level
<= max_level
) {
3502 * Now we know what the final level should be, so we try to set it.
3503 * Doing it this way makes the syscall restartable in case of EINTR
3505 rc
= brightness_set(level
);
3506 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
3509 static struct ibm_struct brightness_driver_data
= {
3510 .name
= "brightness",
3511 .read
= brightness_read
,
3512 .write
= brightness_write
,
3513 .exit
= brightness_exit
,
3516 /*************************************************************************
3520 static int volume_read(char *p
)
3525 if (!acpi_ec_read(volume_offset
, &level
)) {
3526 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3528 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3529 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3530 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3531 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3532 " (<level> is 0-15)\n");
3538 static int volume_write(char *buf
)
3540 int cmos_cmd
, inc
, i
;
3542 int new_level
, new_mute
;
3545 while ((cmd
= next_cmd(&buf
))) {
3546 if (!acpi_ec_read(volume_offset
, &level
))
3548 new_mute
= mute
= level
& 0x40;
3549 new_level
= level
= level
& 0xf;
3551 if (strlencmp(cmd
, "up") == 0) {
3555 new_level
= level
== 15 ? 15 : level
+ 1;
3556 } else if (strlencmp(cmd
, "down") == 0) {
3560 new_level
= level
== 0 ? 0 : level
- 1;
3561 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3562 new_level
>= 0 && new_level
<= 15) {
3564 } else if (strlencmp(cmd
, "mute") == 0) {
3569 if (new_level
!= level
) { /* mute doesn't change */
3570 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3571 inc
= new_level
> level
? 1 : -1;
3573 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3574 !acpi_ec_write(volume_offset
, level
)))
3577 for (i
= level
; i
!= new_level
; i
+= inc
)
3578 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3579 !acpi_ec_write(volume_offset
, i
+ inc
))
3582 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3583 !acpi_ec_write(volume_offset
,
3588 if (new_mute
!= mute
) { /* level doesn't change */
3589 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3591 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3592 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3600 static struct ibm_struct volume_driver_data
= {
3602 .read
= volume_read
,
3603 .write
= volume_write
,
3606 /*************************************************************************
3613 * TPACPI_FAN_RD_ACPI_GFAN:
3614 * ACPI GFAN method: returns fan level
3616 * see TPACPI_FAN_WR_ACPI_SFAN
3617 * EC 0x2f (HFSP) not available if GFAN exists
3619 * TPACPI_FAN_WR_ACPI_SFAN:
3620 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3622 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3625 * TPACPI_FAN_WR_TPEC:
3626 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3627 * Supported on almost all ThinkPads
3629 * Fan speed changes of any sort (including those caused by the
3630 * disengaged mode) are usually done slowly by the firmware as the
3631 * maximum ammount of fan duty cycle change per second seems to be
3634 * Reading is not available if GFAN exists.
3635 * Writing is not available if SFAN exists.
3638 * 7 automatic mode engaged;
3639 * (default operation mode of the ThinkPad)
3640 * fan level is ignored in this mode.
3641 * 6 full speed mode (takes precedence over bit 7);
3642 * not available on all thinkpads. May disable
3643 * the tachometer while the fan controller ramps up
3644 * the speed (which can take up to a few *minutes*).
3645 * Speeds up fan to 100% duty-cycle, which is far above
3646 * the standard RPM levels. It is not impossible that
3647 * it could cause hardware damage.
3648 * 5-3 unused in some models. Extra bits for fan level
3649 * in others, but still useless as all values above
3650 * 7 map to the same speed as level 7 in these models.
3651 * 2-0 fan level (0..7 usually)
3653 * 0x07 = max (set when temperatures critical)
3654 * Some ThinkPads may have other levels, see
3655 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3657 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3658 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3659 * does so, its initial value is meaningless (0x07).
3661 * For firmware bugs, refer to:
3662 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3666 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3667 * Main fan tachometer reading (in RPM)
3669 * This register is present on all ThinkPads with a new-style EC, and
3670 * it is known not to be present on the A21m/e, and T22, as there is
3671 * something else in offset 0x84 according to the ACPI DSDT. Other
3672 * ThinkPads from this same time period (and earlier) probably lack the
3673 * tachometer as well.
3675 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3676 * was never fixed by IBM to report the EC firmware version string
3677 * probably support the tachometer (like the early X models), so
3678 * detecting it is quite hard. We need more data to know for sure.
3680 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3683 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3686 * For firmware bugs, refer to:
3687 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3689 * TPACPI_FAN_WR_ACPI_FANS:
3690 * ThinkPad X31, X40, X41. Not available in the X60.
3692 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3693 * high speed. ACPI DSDT seems to map these three speeds to levels
3694 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3695 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3697 * The speeds are stored on handles
3698 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3700 * There are three default speed sets, acessible as handles:
3701 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3703 * ACPI DSDT switches which set is in use depending on various
3706 * TPACPI_FAN_WR_TPEC is also available and should be used to
3707 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3708 * but the ACPI tables just mention level 7.
3711 static enum fan_status_access_mode fan_status_access_mode
;
3712 static enum fan_control_access_mode fan_control_access_mode
;
3713 static enum fan_control_commands fan_control_commands
;
3715 static u8 fan_control_initial_status
;
3716 static u8 fan_control_desired_level
;
3718 static void fan_watchdog_fire(struct work_struct
*ignored
);
3719 static int fan_watchdog_maxinterval
;
3720 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3722 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3723 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3724 "\\FSPD", /* 600e/x, 770e, 770x */
3726 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3727 "JFNS", /* 770x-JL */
3731 * SYSFS fan layout: hwmon compatible (device)
3734 * 0: "disengaged" mode
3736 * 2: native EC "auto" mode (recommended, hardware default)
3738 * pwm*: set speed in manual mode, ignored otherwise.
3739 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3742 * fan*_input: tachometer reading, RPM
3745 * SYSFS fan layout: extensions
3747 * fan_watchdog (driver):
3748 * fan watchdog interval in seconds, 0 disables (default), max 120
3751 /* sysfs fan pwm1_enable ----------------------------------------------- */
3752 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3753 struct device_attribute
*attr
,
3759 res
= fan_get_status_safe(&status
);
3763 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3764 if (status
!= fan_control_initial_status
) {
3765 tp_features
.fan_ctrl_status_undef
= 0;
3767 /* Return most likely status. In fact, it
3768 * might be the only possible status */
3769 status
= TP_EC_FAN_AUTO
;
3773 if (status
& TP_EC_FAN_FULLSPEED
) {
3775 } else if (status
& TP_EC_FAN_AUTO
) {
3780 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3783 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3784 struct device_attribute
*attr
,
3785 const char *buf
, size_t count
)
3790 if (parse_strtoul(buf
, 2, &t
))
3795 level
= TP_EC_FAN_FULLSPEED
;
3798 level
= TPACPI_FAN_LAST_LEVEL
;
3801 level
= TP_EC_FAN_AUTO
;
3804 /* reserved for software-controlled auto mode */
3810 res
= fan_set_level_safe(level
);
3816 fan_watchdog_reset();
3821 static struct device_attribute dev_attr_fan_pwm1_enable
=
3822 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3823 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3825 /* sysfs fan pwm1 ------------------------------------------------------ */
3826 static ssize_t
fan_pwm1_show(struct device
*dev
,
3827 struct device_attribute
*attr
,
3833 res
= fan_get_status_safe(&status
);
3837 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3838 if (status
!= fan_control_initial_status
) {
3839 tp_features
.fan_ctrl_status_undef
= 0;
3841 status
= TP_EC_FAN_AUTO
;
3846 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3847 status
= fan_control_desired_level
;
3852 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3855 static ssize_t
fan_pwm1_store(struct device
*dev
,
3856 struct device_attribute
*attr
,
3857 const char *buf
, size_t count
)
3861 u8 status
, newlevel
;
3863 if (parse_strtoul(buf
, 255, &s
))
3866 /* scale down from 0-255 to 0-7 */
3867 newlevel
= (s
>> 5) & 0x07;
3869 if (mutex_lock_interruptible(&fan_mutex
))
3870 return -ERESTARTSYS
;
3872 rc
= fan_get_status(&status
);
3873 if (!rc
&& (status
&
3874 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3875 rc
= fan_set_level(newlevel
);
3879 fan_update_desired_level(newlevel
);
3880 fan_watchdog_reset();
3884 mutex_unlock(&fan_mutex
);
3885 return (rc
)? rc
: count
;
3888 static struct device_attribute dev_attr_fan_pwm1
=
3889 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3890 fan_pwm1_show
, fan_pwm1_store
);
3892 /* sysfs fan fan1_input ------------------------------------------------ */
3893 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3894 struct device_attribute
*attr
,
3900 res
= fan_get_speed(&speed
);
3904 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3907 static struct device_attribute dev_attr_fan_fan1_input
=
3908 __ATTR(fan1_input
, S_IRUGO
,
3909 fan_fan1_input_show
, NULL
);
3911 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
3912 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3915 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3918 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3919 const char *buf
, size_t count
)
3923 if (parse_strtoul(buf
, 120, &t
))
3926 if (!fan_control_allowed
)
3929 fan_watchdog_maxinterval
= t
;
3930 fan_watchdog_reset();
3935 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3936 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3938 /* --------------------------------------------------------------------- */
3939 static struct attribute
*fan_attributes
[] = {
3940 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3941 &dev_attr_fan_fan1_input
.attr
,
3945 static const struct attribute_group fan_attr_group
= {
3946 .attrs
= fan_attributes
,
3949 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3953 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3955 mutex_init(&fan_mutex
);
3956 fan_status_access_mode
= TPACPI_FAN_NONE
;
3957 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3958 fan_control_commands
= 0;
3959 fan_watchdog_maxinterval
= 0;
3960 tp_features
.fan_ctrl_status_undef
= 0;
3961 fan_control_desired_level
= 7;
3963 IBM_ACPIHANDLE_INIT(fans
);
3964 IBM_ACPIHANDLE_INIT(gfan
);
3965 IBM_ACPIHANDLE_INIT(sfan
);
3968 /* 570, 600e/x, 770e, 770x */
3969 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3971 /* all other ThinkPads: note that even old-style
3972 * ThinkPad ECs supports the fan control register */
3973 if (likely(acpi_ec_read(fan_status_offset
,
3974 &fan_control_initial_status
))) {
3975 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3977 /* In some ThinkPads, neither the EC nor the ACPI
3978 * DSDT initialize the fan status, and it ends up
3979 * being set to 0x07 when it *could* be either
3982 * Enable for TP-1Y (T43), TP-78 (R51e),
3983 * TP-76 (R52), TP-70 (T43, R52), which are known
3985 if (fan_control_initial_status
== 0x07) {
3986 switch (thinkpad_id
.ec_model
) {
3987 case 0x5931: /* TP-1Y */
3988 case 0x3837: /* TP-78 */
3989 case 0x3637: /* TP-76 */
3990 case 0x3037: /* TP-70 */
3992 "fan_init: initial fan status is "
3993 "unknown, assuming it is in auto "
3995 tp_features
.fan_ctrl_status_undef
= 1;
4001 "ThinkPad ACPI EC access misbehaving, "
4002 "fan status and control unavailable\n");
4009 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
4010 fan_control_commands
|=
4011 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
4014 /* gfan without sfan means no fan control */
4015 /* all other models implement TP EC 0x2f control */
4019 fan_control_access_mode
=
4020 TPACPI_FAN_WR_ACPI_FANS
;
4021 fan_control_commands
|=
4022 TPACPI_FAN_CMD_SPEED
|
4023 TPACPI_FAN_CMD_LEVEL
|
4024 TPACPI_FAN_CMD_ENABLE
;
4026 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
4027 fan_control_commands
|=
4028 TPACPI_FAN_CMD_LEVEL
|
4029 TPACPI_FAN_CMD_ENABLE
;
4034 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
4035 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
4036 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
4037 fan_status_access_mode
, fan_control_access_mode
);
4039 /* fan control master switch */
4040 if (!fan_control_allowed
) {
4041 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
4042 fan_control_commands
= 0;
4043 dbg_printk(TPACPI_DBG_INIT
,
4044 "fan control features disabled by parameter\n");
4047 /* update fan_control_desired_level */
4048 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
4049 fan_get_status_safe(NULL
);
4051 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
4052 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
4053 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4056 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
4057 &driver_attr_fan_watchdog
);
4066 * Call with fan_mutex held
4068 static void fan_update_desired_level(u8 status
)
4071 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4073 fan_control_desired_level
= 7;
4075 fan_control_desired_level
= status
;
4079 static int fan_get_status(u8
*status
)
4084 * Add TPACPI_FAN_RD_ACPI_FANS ? */
4086 switch (fan_status_access_mode
) {
4087 case TPACPI_FAN_RD_ACPI_GFAN
:
4088 /* 570, 600e/x, 770e, 770x */
4090 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
4098 case TPACPI_FAN_RD_TPEC
:
4099 /* all except 570, 600e/x, 770e, 770x */
4100 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
4115 static int fan_get_status_safe(u8
*status
)
4120 if (mutex_lock_interruptible(&fan_mutex
))
4121 return -ERESTARTSYS
;
4122 rc
= fan_get_status(&s
);
4124 fan_update_desired_level(s
);
4125 mutex_unlock(&fan_mutex
);
4133 static void fan_exit(void)
4135 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
4137 /* FIXME: can we really do this unconditionally? */
4138 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
4139 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
, &driver_attr_fan_watchdog
);
4141 cancel_delayed_work(&fan_watchdog_task
);
4142 flush_scheduled_work();
4145 static int fan_get_speed(unsigned int *speed
)
4149 switch (fan_status_access_mode
) {
4150 case TPACPI_FAN_RD_TPEC
:
4151 /* all except 570, 600e/x, 770e, 770x */
4152 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4153 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4157 *speed
= (hi
<< 8) | lo
;
4168 static void fan_watchdog_fire(struct work_struct
*ignored
)
4172 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
4175 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
4176 rc
= fan_set_enable();
4178 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
4179 "will try again later...\n", -rc
);
4180 /* reschedule for later */
4181 fan_watchdog_reset();
4185 static void fan_watchdog_reset(void)
4187 static int fan_watchdog_active
;
4189 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
4192 if (fan_watchdog_active
)
4193 cancel_delayed_work(&fan_watchdog_task
);
4195 if (fan_watchdog_maxinterval
> 0 &&
4196 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
4197 fan_watchdog_active
= 1;
4198 if (!schedule_delayed_work(&fan_watchdog_task
,
4199 msecs_to_jiffies(fan_watchdog_maxinterval
4201 printk(IBM_ERR
"failed to schedule the fan watchdog, "
4202 "watchdog will not trigger\n");
4205 fan_watchdog_active
= 0;
4208 static int fan_set_level(int level
)
4210 if (!fan_control_allowed
)
4213 switch (fan_control_access_mode
) {
4214 case TPACPI_FAN_WR_ACPI_SFAN
:
4215 if (level
>= 0 && level
<= 7) {
4216 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4222 case TPACPI_FAN_WR_ACPI_FANS
:
4223 case TPACPI_FAN_WR_TPEC
:
4224 if ((level
!= TP_EC_FAN_AUTO
) &&
4225 (level
!= TP_EC_FAN_FULLSPEED
) &&
4226 ((level
< 0) || (level
> 7)))
4229 /* safety net should the EC not support AUTO
4230 * or FULLSPEED mode bits and just ignore them */
4231 if (level
& TP_EC_FAN_FULLSPEED
)
4232 level
|= 7; /* safety min speed 7 */
4233 else if (level
& TP_EC_FAN_FULLSPEED
)
4234 level
|= 4; /* safety min speed 4 */
4236 if (!acpi_ec_write(fan_status_offset
, level
))
4239 tp_features
.fan_ctrl_status_undef
= 0;
4248 static int fan_set_level_safe(int level
)
4252 if (!fan_control_allowed
)
4255 if (mutex_lock_interruptible(&fan_mutex
))
4256 return -ERESTARTSYS
;
4258 if (level
== TPACPI_FAN_LAST_LEVEL
)
4259 level
= fan_control_desired_level
;
4261 rc
= fan_set_level(level
);
4263 fan_update_desired_level(level
);
4265 mutex_unlock(&fan_mutex
);
4269 static int fan_set_enable(void)
4274 if (!fan_control_allowed
)
4277 if (mutex_lock_interruptible(&fan_mutex
))
4278 return -ERESTARTSYS
;
4280 switch (fan_control_access_mode
) {
4281 case TPACPI_FAN_WR_ACPI_FANS
:
4282 case TPACPI_FAN_WR_TPEC
:
4283 rc
= fan_get_status(&s
);
4287 /* Don't go out of emergency fan mode */
4290 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4293 if (!acpi_ec_write(fan_status_offset
, s
))
4296 tp_features
.fan_ctrl_status_undef
= 0;
4301 case TPACPI_FAN_WR_ACPI_SFAN
:
4302 rc
= fan_get_status(&s
);
4308 /* Set fan to at least level 4 */
4311 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4321 mutex_unlock(&fan_mutex
);
4325 static int fan_set_disable(void)
4329 if (!fan_control_allowed
)
4332 if (mutex_lock_interruptible(&fan_mutex
))
4333 return -ERESTARTSYS
;
4336 switch (fan_control_access_mode
) {
4337 case TPACPI_FAN_WR_ACPI_FANS
:
4338 case TPACPI_FAN_WR_TPEC
:
4339 if (!acpi_ec_write(fan_status_offset
, 0x00))
4342 fan_control_desired_level
= 0;
4343 tp_features
.fan_ctrl_status_undef
= 0;
4347 case TPACPI_FAN_WR_ACPI_SFAN
:
4348 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4351 fan_control_desired_level
= 0;
4359 mutex_unlock(&fan_mutex
);
4363 static int fan_set_speed(int speed
)
4367 if (!fan_control_allowed
)
4370 if (mutex_lock_interruptible(&fan_mutex
))
4371 return -ERESTARTSYS
;
4374 switch (fan_control_access_mode
) {
4375 case TPACPI_FAN_WR_ACPI_FANS
:
4376 if (speed
>= 0 && speed
<= 65535) {
4377 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4378 speed
, speed
, speed
))
4388 mutex_unlock(&fan_mutex
);
4392 static int fan_read(char *p
)
4397 unsigned int speed
= 0;
4399 switch (fan_status_access_mode
) {
4400 case TPACPI_FAN_RD_ACPI_GFAN
:
4401 /* 570, 600e/x, 770e, 770x */
4402 if ((rc
= fan_get_status_safe(&status
)) < 0)
4405 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
4407 (status
!= 0) ? "enabled" : "disabled", status
);
4410 case TPACPI_FAN_RD_TPEC
:
4411 /* all except 570, 600e/x, 770e, 770x */
4412 if ((rc
= fan_get_status_safe(&status
)) < 0)
4415 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4416 if (status
!= fan_control_initial_status
)
4417 tp_features
.fan_ctrl_status_undef
= 0;
4419 /* Return most likely status. In fact, it
4420 * might be the only possible status */
4421 status
= TP_EC_FAN_AUTO
;
4424 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4425 (status
!= 0) ? "enabled" : "disabled");
4427 if ((rc
= fan_get_speed(&speed
)) < 0)
4430 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
4432 if (status
& TP_EC_FAN_FULLSPEED
)
4433 /* Disengaged mode takes precedence */
4434 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
4435 else if (status
& TP_EC_FAN_AUTO
)
4436 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
4438 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
4441 case TPACPI_FAN_NONE
:
4443 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4446 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
4447 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
4449 switch (fan_control_access_mode
) {
4450 case TPACPI_FAN_WR_ACPI_SFAN
:
4451 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4455 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4456 "auto, disengaged, full-speed)\n");
4461 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4462 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4463 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4464 "1-120 (seconds))\n");
4466 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4467 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4468 " (<speed> is 0-65535)\n");
4473 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4477 if (strlencmp(cmd
, "level auto") == 0)
4478 level
= TP_EC_FAN_AUTO
;
4479 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4480 (strlencmp(cmd
, "level full-speed") == 0))
4481 level
= TP_EC_FAN_FULLSPEED
;
4482 else if (sscanf(cmd
, "level %d", &level
) != 1)
4485 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4486 printk(IBM_ERR
"level command accepted for unsupported "
4487 "access mode %d", fan_control_access_mode
);
4492 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4494 if (strlencmp(cmd
, "enable") != 0)
4497 if ((*rc
= fan_set_enable()) == -ENXIO
)
4498 printk(IBM_ERR
"enable command accepted for unsupported "
4499 "access mode %d", fan_control_access_mode
);
4504 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4506 if (strlencmp(cmd
, "disable") != 0)
4509 if ((*rc
= fan_set_disable()) == -ENXIO
)
4510 printk(IBM_ERR
"disable command accepted for unsupported "
4511 "access mode %d", fan_control_access_mode
);
4516 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4521 * Support speed <low> <medium> <high> ? */
4523 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4526 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4527 printk(IBM_ERR
"speed command accepted for unsupported "
4528 "access mode %d", fan_control_access_mode
);
4533 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4537 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4540 if (interval
< 0 || interval
> 120)
4543 fan_watchdog_maxinterval
= interval
;
4548 static int fan_write(char *buf
)
4553 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4554 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4555 fan_write_cmd_level(cmd
, &rc
)) &&
4556 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4557 (fan_write_cmd_enable(cmd
, &rc
) ||
4558 fan_write_cmd_disable(cmd
, &rc
) ||
4559 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4560 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4561 fan_write_cmd_speed(cmd
, &rc
))
4565 fan_watchdog_reset();
4571 static struct ibm_struct fan_driver_data
= {
4578 /****************************************************************************
4579 ****************************************************************************
4583 ****************************************************************************
4584 ****************************************************************************/
4586 /* sysfs name ---------------------------------------------------------- */
4587 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
4588 struct device_attribute
*attr
,
4591 return snprintf(buf
, PAGE_SIZE
, "%s\n", IBM_NAME
);
4594 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
4595 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
4597 /* --------------------------------------------------------------------- */
4600 static struct proc_dir_entry
*proc_dir
;
4602 /* Subdriver registry */
4603 static LIST_HEAD(tpacpi_all_drivers
);
4607 * Module and infrastructure proble, init and exit handling
4610 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4611 static const char * __init
str_supported(int is_supported
)
4613 static char text_unsupported
[] __initdata
= "not supported";
4615 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4617 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4619 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4622 struct ibm_struct
*ibm
= iibm
->data
;
4623 struct proc_dir_entry
*entry
;
4625 BUG_ON(ibm
== NULL
);
4627 INIT_LIST_HEAD(&ibm
->all_drivers
);
4629 if (ibm
->flags
.experimental
&& !experimental
)
4632 dbg_printk(TPACPI_DBG_INIT
,
4633 "probing for %s\n", ibm
->name
);
4636 ret
= iibm
->init(iibm
);
4638 return 0; /* probe failed */
4642 ibm
->flags
.init_called
= 1;
4646 if (ibm
->acpi
->hid
) {
4647 ret
= register_tpacpi_subdriver(ibm
);
4652 if (ibm
->acpi
->notify
) {
4653 ret
= setup_acpi_notify(ibm
);
4654 if (ret
== -ENODEV
) {
4655 printk(IBM_NOTICE
"disabling subdriver %s\n",
4665 dbg_printk(TPACPI_DBG_INIT
,
4666 "%s installed\n", ibm
->name
);
4669 entry
= create_proc_entry(ibm
->name
,
4670 S_IFREG
| S_IRUGO
| S_IWUSR
,
4673 printk(IBM_ERR
"unable to create proc entry %s\n",
4678 entry
->owner
= THIS_MODULE
;
4680 entry
->read_proc
= &dispatch_procfs_read
;
4682 entry
->write_proc
= &dispatch_procfs_write
;
4683 ibm
->flags
.proc_created
= 1;
4686 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4691 dbg_printk(TPACPI_DBG_INIT
,
4692 "%s: at error exit path with result %d\n",
4696 return (ret
< 0)? ret
: 0;
4699 static void ibm_exit(struct ibm_struct
*ibm
)
4701 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4703 list_del_init(&ibm
->all_drivers
);
4705 if (ibm
->flags
.acpi_notify_installed
) {
4706 dbg_printk(TPACPI_DBG_EXIT
,
4707 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4709 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4711 dispatch_acpi_notify
);
4712 ibm
->flags
.acpi_notify_installed
= 0;
4713 ibm
->flags
.acpi_notify_installed
= 0;
4716 if (ibm
->flags
.proc_created
) {
4717 dbg_printk(TPACPI_DBG_EXIT
,
4718 "%s: remove_proc_entry\n", ibm
->name
);
4719 remove_proc_entry(ibm
->name
, proc_dir
);
4720 ibm
->flags
.proc_created
= 0;
4723 if (ibm
->flags
.acpi_driver_registered
) {
4724 dbg_printk(TPACPI_DBG_EXIT
,
4725 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4727 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4728 kfree(ibm
->acpi
->driver
);
4729 ibm
->acpi
->driver
= NULL
;
4730 ibm
->flags
.acpi_driver_registered
= 0;
4733 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4735 ibm
->flags
.init_called
= 0;
4738 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4743 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
4745 const struct dmi_device
*dev
= NULL
;
4746 char ec_fw_string
[18];
4751 memset(tp
, 0, sizeof(*tp
));
4753 if (dmi_name_in_vendors("IBM"))
4754 tp
->vendor
= PCI_VENDOR_ID_IBM
;
4755 else if (dmi_name_in_vendors("LENOVO"))
4756 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
4760 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
4762 if (!tp
->bios_version_str
)
4764 tp
->bios_model
= tp
->bios_version_str
[0]
4765 | (tp
->bios_version_str
[1] << 8);
4768 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4769 * X32 or newer, all Z series; Some models must have an
4770 * up-to-date BIOS or they will not be detected.
4772 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4774 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4775 if (sscanf(dev
->name
,
4776 "IBM ThinkPad Embedded Controller -[%17c",
4777 ec_fw_string
) == 1) {
4778 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4779 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4781 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
4782 tp
->ec_model
= ec_fw_string
[0]
4783 | (ec_fw_string
[1] << 8);
4788 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
4790 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
4791 kfree(tp
->model_str
);
4792 tp
->model_str
= NULL
;
4796 static int __init
probe_for_thinkpad(void)
4804 * Non-ancient models have better DMI tagging, but very old models
4807 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
4809 /* ec is required because many other handles are relative to it */
4810 IBM_ACPIHANDLE_INIT(ec
);
4814 "Not yet supported ThinkPad detected!\n");
4819 * Risks a regression on very old machines, but reduces potential
4820 * false positives a damn great deal
4823 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
4825 if (!is_thinkpad
&& !force_load
)
4832 /* Module init, exit, parameters */
4834 static struct ibm_init_struct ibms_init
[] __initdata
= {
4836 .init
= thinkpad_acpi_driver_init
,
4837 .data
= &thinkpad_acpi_driver_data
,
4840 .init
= hotkey_init
,
4841 .data
= &hotkey_driver_data
,
4844 .init
= bluetooth_init
,
4845 .data
= &bluetooth_driver_data
,
4849 .data
= &wan_driver_data
,
4853 .data
= &video_driver_data
,
4857 .data
= &light_driver_data
,
4859 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4862 .data
= &dock_driver_data
[0],
4866 .data
= &dock_driver_data
[1],
4869 #ifdef CONFIG_THINKPAD_ACPI_BAY
4872 .data
= &bay_driver_data
,
4877 .data
= &cmos_driver_data
,
4881 .data
= &led_driver_data
,
4885 .data
= &beep_driver_data
,
4888 .init
= thermal_init
,
4889 .data
= &thermal_driver_data
,
4892 .data
= &ecdump_driver_data
,
4895 .init
= brightness_init
,
4896 .data
= &brightness_driver_data
,
4899 .data
= &volume_driver_data
,
4903 .data
= &fan_driver_data
,
4907 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4910 struct ibm_struct
*ibm
;
4912 if (!kp
|| !kp
->name
|| !val
)
4915 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4916 ibm
= ibms_init
[i
].data
;
4917 WARN_ON(ibm
== NULL
);
4919 if (!ibm
|| !ibm
->name
)
4922 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4923 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4925 strcpy(ibms_init
[i
].param
, val
);
4926 strcat(ibms_init
[i
].param
, ",");
4934 static int experimental
;
4935 module_param(experimental
, int, 0);
4937 static u32 dbg_level
;
4938 module_param_named(debug
, dbg_level
, uint
, 0);
4940 static int force_load
;
4941 module_param(force_load
, bool, 0);
4943 static int fan_control_allowed
;
4944 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
4946 static int brightness_mode
;
4947 module_param_named(brightness_mode
, brightness_mode
, int, 0);
4949 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
4950 module_param(brightness_enable
, uint
, 0);
4952 static unsigned int hotkey_report_mode
;
4953 module_param(hotkey_report_mode
, uint
, 0);
4955 #define IBM_PARAM(feature) \
4956 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4959 IBM_PARAM(bluetooth
);
4962 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4965 #ifdef CONFIG_THINKPAD_ACPI_BAY
4967 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4972 IBM_PARAM(brightness
);
4976 static int __init
thinkpad_acpi_module_init(void)
4980 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
4982 /* Parameter checking */
4983 if (hotkey_report_mode
> 2)
4986 /* Driver-level probe */
4988 get_thinkpad_model_data(&thinkpad_id
);
4989 ret
= probe_for_thinkpad();
4991 thinkpad_acpi_module_exit();
4995 /* Driver initialization */
4997 IBM_ACPIHANDLE_INIT(ecrd
);
4998 IBM_ACPIHANDLE_INIT(ecwr
);
5000 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
5002 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
5003 thinkpad_acpi_module_exit();
5006 proc_dir
->owner
= THIS_MODULE
;
5008 ret
= platform_driver_register(&tpacpi_pdriver
);
5010 printk(IBM_ERR
"unable to register main platform driver\n");
5011 thinkpad_acpi_module_exit();
5014 tp_features
.platform_drv_registered
= 1;
5016 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
5018 printk(IBM_ERR
"unable to register hwmon platform driver\n");
5019 thinkpad_acpi_module_exit();
5022 tp_features
.sensors_pdrv_registered
= 1;
5024 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
5026 tp_features
.platform_drv_attrs_registered
= 1;
5027 ret
= tpacpi_create_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
5030 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
5031 thinkpad_acpi_module_exit();
5034 tp_features
.sensors_pdrv_attrs_registered
= 1;
5037 /* Device initialization */
5038 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
5040 if (IS_ERR(tpacpi_pdev
)) {
5041 ret
= PTR_ERR(tpacpi_pdev
);
5043 printk(IBM_ERR
"unable to register platform device\n");
5044 thinkpad_acpi_module_exit();
5047 tpacpi_sensors_pdev
= platform_device_register_simple(
5048 IBM_HWMON_DRVR_NAME
,
5050 if (IS_ERR(tpacpi_sensors_pdev
)) {
5051 ret
= PTR_ERR(tpacpi_sensors_pdev
);
5052 tpacpi_sensors_pdev
= NULL
;
5053 printk(IBM_ERR
"unable to register hwmon platform device\n");
5054 thinkpad_acpi_module_exit();
5057 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
5058 &dev_attr_thinkpad_acpi_pdev_name
);
5061 "unable to create sysfs hwmon device attributes\n");
5062 thinkpad_acpi_module_exit();
5065 tp_features
.sensors_pdev_attrs_registered
= 1;
5066 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
5067 if (IS_ERR(tpacpi_hwmon
)) {
5068 ret
= PTR_ERR(tpacpi_hwmon
);
5069 tpacpi_hwmon
= NULL
;
5070 printk(IBM_ERR
"unable to register hwmon device\n");
5071 thinkpad_acpi_module_exit();
5074 mutex_init(&tpacpi_inputdev_send_mutex
);
5075 tpacpi_inputdev
= input_allocate_device();
5076 if (!tpacpi_inputdev
) {
5077 printk(IBM_ERR
"unable to allocate input device\n");
5078 thinkpad_acpi_module_exit();
5081 /* Prepare input device, but don't register */
5082 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
5083 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
5084 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
5085 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
5086 thinkpad_id
.vendor
:
5088 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
5089 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
5091 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5092 ret
= ibm_init(&ibms_init
[i
]);
5093 if (ret
>= 0 && *ibms_init
[i
].param
)
5094 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
5096 thinkpad_acpi_module_exit();
5100 ret
= input_register_device(tpacpi_inputdev
);
5102 printk(IBM_ERR
"unable to register input device\n");
5103 thinkpad_acpi_module_exit();
5106 tp_features
.input_device_registered
= 1;
5109 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
5113 static void thinkpad_acpi_module_exit(void)
5115 struct ibm_struct
*ibm
, *itmp
;
5117 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
5119 list_for_each_entry_safe_reverse(ibm
, itmp
,
5120 &tpacpi_all_drivers
,
5125 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
5127 if (tpacpi_inputdev
) {
5128 if (tp_features
.input_device_registered
)
5129 input_unregister_device(tpacpi_inputdev
);
5131 input_free_device(tpacpi_inputdev
);
5135 hwmon_device_unregister(tpacpi_hwmon
);
5137 if (tp_features
.sensors_pdev_attrs_registered
)
5138 device_remove_file(&tpacpi_sensors_pdev
->dev
,
5139 &dev_attr_thinkpad_acpi_pdev_name
);
5140 if (tpacpi_sensors_pdev
)
5141 platform_device_unregister(tpacpi_sensors_pdev
);
5143 platform_device_unregister(tpacpi_pdev
);
5145 if (tp_features
.sensors_pdrv_attrs_registered
)
5146 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
5147 if (tp_features
.platform_drv_attrs_registered
)
5148 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
5150 if (tp_features
.sensors_pdrv_registered
)
5151 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
5153 if (tp_features
.platform_drv_registered
)
5154 platform_driver_unregister(&tpacpi_pdriver
);
5157 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
5159 kfree(thinkpad_id
.bios_version_str
);
5160 kfree(thinkpad_id
.ec_version_str
);
5161 kfree(thinkpad_id
.model_str
);
5164 module_init(thinkpad_acpi_module_init
);
5165 module_exit(thinkpad_acpi_module_exit
);