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.15"
25 #define TPACPI_SYSFS_VERSION 0x010000
29 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
32 * 2006-11-22 0.13 new maintainer
33 * changelog now lives in git commit history, and will
34 * not be updated further in-file.
36 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
37 * 2005-03-17 0.11 support for 600e, 770x
38 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
39 * support for 770e, G41
40 * G40 and G41 don't have a thinklight
41 * temperatures no longer experimental
42 * experimental brightness control
43 * experimental volume control
44 * experimental fan enable/disable
45 * 2005-01-16 0.10 fix module loading on R30, R31
46 * 2005-01-16 0.9 support for 570, R30, R31
47 * ultrabay support on A22p, A3x
48 * limit arg for cmos, led, beep, drop experimental status
49 * more capable led control on A21e, A22p, T20-22, X20
50 * experimental temperatures and fan speed
51 * experimental embedded controller register dump
52 * mark more functions as __init, drop incorrect __exit
54 * thanks to Henrik Brix Andersen <brix@gentoo.org>
55 * fix parameter passing on module loading
56 * thanks to Rusty Russell <rusty@rustcorp.com.au>
57 * thanks to Jim Radford <radford@blackbean.org>
58 * 2004-11-08 0.8 fix init error case, don't return from a macro
59 * thanks to Chris Wright <chrisw@osdl.org>
60 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
61 * fix led control on A21e
62 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
63 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
64 * proc file format changed
65 * video_switch command
66 * experimental cmos control
67 * experimental led control
68 * experimental acpi sounds
69 * 2004-09-16 0.4 support for module parameters
70 * hotkey mask can be prefixed by 0x
71 * video output switching
72 * video expansion control
73 * ultrabay eject support
74 * removed lcd brightness/on/off control, didn't work
75 * 2004-08-17 0.3 support for R40
76 * lcd off, brightness control
78 * 2004-08-14 0.2 support for T series, X20
79 * bluetooth enable/disable
80 * hotkey events disabled by default
81 * removed fan control, currently useless
82 * 2004-08-09 0.1 initial release, support for X series
85 #include "thinkpad_acpi.h"
87 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
88 MODULE_DESCRIPTION(IBM_DESC
);
89 MODULE_VERSION(IBM_VERSION
);
90 MODULE_LICENSE("GPL");
92 /* Please remove this in year 2009 */
93 MODULE_ALIAS("ibm_acpi");
96 * DMI matching for module autoloading
98 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
99 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
101 * Only models listed in thinkwiki will be supported, so add yours
102 * if it is not there yet.
104 #define IBM_BIOS_MODULE_ALIAS(__type) \
105 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
107 /* Non-ancient thinkpads */
108 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
109 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
111 /* Ancient thinkpad BIOSes have to be identified by
112 * BIOS type or model number, and there are far less
113 * BIOS types than model numbers... */
114 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
115 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
116 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
118 #define __unused __attribute__ ((unused))
120 /****************************************************************************
121 ****************************************************************************
123 * ACPI Helpers and device model
125 ****************************************************************************
126 ****************************************************************************/
128 /*************************************************************************
132 static acpi_handle root_handle
;
134 #define IBM_HANDLE(object, parent, paths...) \
135 static acpi_handle object##_handle; \
136 static acpi_handle *object##_parent = &parent##_handle; \
137 static char *object##_path; \
138 static char *object##_paths[] = { paths }
140 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
141 "\\_SB.PCI.ISA.EC", /* 570 */
142 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
143 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
144 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
145 "\\_SB.PCI0.ICH3.EC0", /* R31 */
146 "\\_SB.PCI0.LPC.EC", /* all others */
149 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
150 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
153 /*************************************************************************
157 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
158 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
159 "\\CMS", /* R40, R40e */
162 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
163 "^HKEY", /* R30, R31 */
164 "HKEY", /* all others */
168 /*************************************************************************
172 static int acpi_evalf(acpi_handle handle
,
173 void *res
, char *method
, char *fmt
, ...)
176 struct acpi_object_list params
;
177 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
178 struct acpi_buffer result
, *resultp
;
179 union acpi_object out_obj
;
187 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
200 params
.pointer
= &in_objs
[0];
207 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
208 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
210 /* add more types as needed */
212 printk(IBM_ERR
"acpi_evalf() called "
213 "with invalid format character '%c'\n", c
);
219 if (res_type
!= 'v') {
220 result
.length
= sizeof(out_obj
);
221 result
.pointer
= &out_obj
;
226 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
231 *(int *)res
= out_obj
.integer
.value
;
232 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
235 success
= status
== AE_OK
;
237 /* add more types as needed */
239 printk(IBM_ERR
"acpi_evalf() called "
240 "with invalid format character '%c'\n", res_type
);
244 if (!success
&& !quiet
)
245 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
246 method
, fmt0
, status
);
251 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
255 if (acpi_evalf(handle
, &i
, method
, "d"))
256 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
258 printk(IBM_ERR
"error calling %s\n", method
);
261 static int acpi_ec_read(int i
, u8
* p
)
266 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
270 if (ec_read(i
, p
) < 0)
277 static int acpi_ec_write(int i
, u8 v
)
280 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
283 if (ec_write(i
, v
) < 0)
290 static int _sta(acpi_handle handle
)
294 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
300 static int issue_thinkpad_cmos_command(int cmos_cmd
)
305 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
311 /*************************************************************************
315 static void drv_acpi_handle_init(char *name
,
316 acpi_handle
*handle
, acpi_handle parent
,
317 char **paths
, int num_paths
, char **path
)
322 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
325 for (i
= 0; i
< num_paths
; i
++) {
326 status
= acpi_get_handle(parent
, paths
[i
], handle
);
327 if (ACPI_SUCCESS(status
)) {
329 dbg_printk(TPACPI_DBG_INIT
,
330 "Found ACPI handle %s for %s\n",
336 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
341 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
343 struct ibm_struct
*ibm
= data
;
345 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
348 ibm
->acpi
->notify(ibm
, event
);
351 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
358 if (!*ibm
->acpi
->handle
)
361 vdbg_printk(TPACPI_DBG_INIT
,
362 "setting up ACPI notify for %s\n", ibm
->name
);
364 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
366 printk(IBM_ERR
"acpi_bus_get_device(%s) failed: %d\n",
371 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
372 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
373 IBM_ACPI_EVENT_PREFIX
,
376 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
377 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
378 if (ACPI_FAILURE(status
)) {
379 if (status
== AE_ALREADY_EXISTS
) {
380 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
383 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
388 ibm
->flags
.acpi_notify_installed
= 1;
392 static int __init
tpacpi_device_add(struct acpi_device
*device
)
397 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
401 dbg_printk(TPACPI_DBG_INIT
,
402 "registering %s as an ACPI driver\n", ibm
->name
);
406 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
407 if (!ibm
->acpi
->driver
) {
408 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
412 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
413 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
415 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
417 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
419 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
421 kfree(ibm
->acpi
->driver
);
422 ibm
->acpi
->driver
= NULL
;
424 ibm
->flags
.acpi_driver_registered
= 1;
430 /****************************************************************************
431 ****************************************************************************
435 ****************************************************************************
436 ****************************************************************************/
438 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
439 int count
, int *eof
, void *data
)
441 struct ibm_struct
*ibm
= data
;
444 if (!ibm
|| !ibm
->read
)
447 len
= ibm
->read(page
);
451 if (len
<= off
+ count
)
463 static int dispatch_procfs_write(struct file
*file
,
464 const char __user
* userbuf
,
465 unsigned long count
, void *data
)
467 struct ibm_struct
*ibm
= data
;
471 if (!ibm
|| !ibm
->write
)
474 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
478 if (copy_from_user(kernbuf
, userbuf
, count
)) {
484 strcat(kernbuf
, ",");
485 ret
= ibm
->write(kernbuf
);
494 static char *next_cmd(char **cmds
)
499 while ((end
= strchr(start
, ',')) && end
== start
)
511 /****************************************************************************
512 ****************************************************************************
514 * Device model: input, hwmon and platform
516 ****************************************************************************
517 ****************************************************************************/
519 static struct platform_device
*tpacpi_pdev
;
520 static struct class_device
*tpacpi_hwmon
;
521 static struct input_dev
*tpacpi_inputdev
;
524 static int tpacpi_resume_handler(struct platform_device
*pdev
)
526 struct ibm_struct
*ibm
, *itmp
;
528 list_for_each_entry_safe(ibm
, itmp
,
538 static struct platform_driver tpacpi_pdriver
= {
540 .name
= IBM_DRVR_NAME
,
541 .owner
= THIS_MODULE
,
543 .resume
= tpacpi_resume_handler
,
547 /*************************************************************************
548 * thinkpad-acpi driver attributes
551 /* interface_version --------------------------------------------------- */
552 static ssize_t
tpacpi_driver_interface_version_show(
553 struct device_driver
*drv
,
556 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
559 static DRIVER_ATTR(interface_version
, S_IRUGO
,
560 tpacpi_driver_interface_version_show
, NULL
);
562 /* debug_level --------------------------------------------------------- */
563 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
566 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
569 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
570 const char *buf
, size_t count
)
574 if (parse_strtoul(buf
, 0xffff, &t
))
582 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
583 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
585 /* version ------------------------------------------------------------- */
586 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
589 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
592 static DRIVER_ATTR(version
, S_IRUGO
,
593 tpacpi_driver_version_show
, NULL
);
595 /* --------------------------------------------------------------------- */
597 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
598 &driver_attr_debug_level
, &driver_attr_version
,
599 &driver_attr_interface_version
,
602 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
608 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
609 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
616 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
620 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
621 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
624 /*************************************************************************
625 * sysfs support helpers
628 struct attribute_set_obj
{
629 struct attribute_set s
;
631 } __attribute__((packed
));
633 static struct attribute_set
*create_attr_set(unsigned int max_members
,
636 struct attribute_set_obj
*sobj
;
638 if (max_members
== 0)
641 /* Allocates space for implicit NULL at the end too */
642 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
643 max_members
* sizeof(struct attribute
*),
647 sobj
->s
.max_members
= max_members
;
648 sobj
->s
.group
.attrs
= &sobj
->a
;
649 sobj
->s
.group
.name
= name
;
654 /* not multi-threaded safe, use it in a single thread per set */
655 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
660 if (s
->members
>= s
->max_members
)
663 s
->group
.attrs
[s
->members
] = attr
;
669 static int add_many_to_attr_set(struct attribute_set
* s
,
670 struct attribute
**attr
,
675 for (i
= 0; i
< count
; i
++) {
676 res
= add_to_attr_set(s
, attr
[i
]);
684 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
686 sysfs_remove_group(kobj
, &s
->group
);
690 static int parse_strtoul(const char *buf
,
691 unsigned long max
, unsigned long *value
)
695 *value
= simple_strtoul(buf
, &endp
, 0);
696 while (*endp
&& isspace(*endp
))
698 if (*endp
|| *value
> max
)
704 /****************************************************************************
705 ****************************************************************************
709 ****************************************************************************
710 ****************************************************************************/
712 /*************************************************************************
713 * thinkpad-acpi init subdriver
716 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
718 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
719 printk(IBM_INFO
"%s\n", IBM_URL
);
721 printk(IBM_INFO
"ThinkPad BIOS %s, EC %s\n",
722 (thinkpad_id
.bios_version_str
) ?
723 thinkpad_id
.bios_version_str
: "unknown",
724 (thinkpad_id
.ec_version_str
) ?
725 thinkpad_id
.ec_version_str
: "unknown");
727 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
728 printk(IBM_INFO
"%s %s\n",
729 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
730 "IBM" : ((thinkpad_id
.vendor
==
731 PCI_VENDOR_ID_LENOVO
) ?
732 "Lenovo" : "Unknown vendor"),
733 thinkpad_id
.model_str
);
738 static int thinkpad_acpi_driver_read(char *p
)
742 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
743 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
748 static struct ibm_struct thinkpad_acpi_driver_data
= {
750 .read
= thinkpad_acpi_driver_read
,
753 /*************************************************************************
757 static int hotkey_orig_status
;
758 static u32 hotkey_orig_mask
;
759 static u32 hotkey_all_mask
;
760 static u32 hotkey_reserved_mask
;
762 static u16
*hotkey_keycode_map
;
764 static struct attribute_set
*hotkey_dev_attributes
;
766 static int hotkey_get_wlsw(int *status
)
768 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
773 /* sysfs hotkey enable ------------------------------------------------- */
774 static ssize_t
hotkey_enable_show(struct device
*dev
,
775 struct device_attribute
*attr
,
781 res
= hotkey_get(&status
, &mask
);
785 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
788 static ssize_t
hotkey_enable_store(struct device
*dev
,
789 struct device_attribute
*attr
,
790 const char *buf
, size_t count
)
796 if (parse_strtoul(buf
, 1, &t
))
799 res
= hotkey_get(&status
, &mask
);
801 res
= hotkey_set(t
, mask
);
803 return (res
) ? res
: count
;
806 static struct device_attribute dev_attr_hotkey_enable
=
807 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
808 hotkey_enable_show
, hotkey_enable_store
);
810 /* sysfs hotkey mask --------------------------------------------------- */
811 static ssize_t
hotkey_mask_show(struct device
*dev
,
812 struct device_attribute
*attr
,
818 res
= hotkey_get(&status
, &mask
);
822 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
825 static ssize_t
hotkey_mask_store(struct device
*dev
,
826 struct device_attribute
*attr
,
827 const char *buf
, size_t count
)
833 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
836 res
= hotkey_get(&status
, &mask
);
838 hotkey_set(status
, t
);
840 return (res
) ? res
: count
;
843 static struct device_attribute dev_attr_hotkey_mask
=
844 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
845 hotkey_mask_show
, hotkey_mask_store
);
847 /* sysfs hotkey bios_enabled ------------------------------------------- */
848 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
849 struct device_attribute
*attr
,
852 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
855 static struct device_attribute dev_attr_hotkey_bios_enabled
=
856 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
858 /* sysfs hotkey bios_mask ---------------------------------------------- */
859 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
860 struct device_attribute
*attr
,
863 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
866 static struct device_attribute dev_attr_hotkey_bios_mask
=
867 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
869 /* sysfs hotkey all_mask ----------------------------------------------- */
870 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
871 struct device_attribute
*attr
,
874 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_all_mask
);
877 static struct device_attribute dev_attr_hotkey_all_mask
=
878 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
880 /* sysfs hotkey recommended_mask --------------------------------------- */
881 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
882 struct device_attribute
*attr
,
885 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
886 hotkey_all_mask
& ~hotkey_reserved_mask
);
889 static struct device_attribute dev_attr_hotkey_recommended_mask
=
890 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
891 hotkey_recommended_mask_show
, NULL
);
893 /* sysfs hotkey radio_sw ----------------------------------------------- */
894 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
895 struct device_attribute
*attr
,
899 res
= hotkey_get_wlsw(&s
);
903 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
906 static struct device_attribute dev_attr_hotkey_radio_sw
=
907 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
909 /* --------------------------------------------------------------------- */
911 static struct attribute
*hotkey_mask_attributes
[] = {
912 &dev_attr_hotkey_mask
.attr
,
913 &dev_attr_hotkey_bios_enabled
.attr
,
914 &dev_attr_hotkey_bios_mask
.attr
,
915 &dev_attr_hotkey_all_mask
.attr
,
916 &dev_attr_hotkey_recommended_mask
.attr
,
919 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
922 static u16 ibm_keycode_map
[] __initdata
= {
923 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
924 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
925 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
926 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
927 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
928 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
929 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
930 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
931 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
932 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
933 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
934 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
935 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
936 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
937 KEY_RESERVED
, /* 0x14: VOLUME UP */
938 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
939 KEY_RESERVED
, /* 0x16: MUTE */
940 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
941 /* (assignments unknown, please report if found) */
942 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
943 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
945 static u16 lenovo_keycode_map
[] __initdata
= {
946 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
947 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
948 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
949 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
950 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
951 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
952 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
953 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
954 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
955 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
956 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
957 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
958 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
959 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
960 KEY_RESERVED
, /* 0x14: VOLUME UP */
961 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
962 KEY_RESERVED
, /* 0x16: MUTE */
963 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
964 /* (assignments unknown, please report if found) */
965 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
966 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
969 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
970 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
971 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
976 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
978 BUG_ON(!tpacpi_inputdev
);
980 IBM_ACPIHANDLE_INIT(hkey
);
981 mutex_init(&hotkey_mutex
);
983 /* hotkey not supported on 570 */
984 tp_features
.hotkey
= hkey_handle
!= NULL
;
986 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
987 str_supported(tp_features
.hotkey
));
989 if (tp_features
.hotkey
) {
990 hotkey_dev_attributes
= create_attr_set(7, NULL
);
991 if (!hotkey_dev_attributes
)
993 res
= add_to_attr_set(hotkey_dev_attributes
,
994 &dev_attr_hotkey_enable
.attr
);
998 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
999 A30, R30, R31, T20-22, X20-21, X22-24 */
1000 tp_features
.hotkey_mask
=
1001 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
1003 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1004 str_supported(tp_features
.hotkey_mask
));
1006 if (tp_features
.hotkey_mask
) {
1007 /* MHKA available in A31, R40, R40e, T4x, X31, and later */
1008 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1010 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
1013 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
1014 if (!res
&& tp_features
.hotkey_mask
) {
1015 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1016 hotkey_mask_attributes
,
1017 ARRAY_SIZE(hotkey_mask_attributes
));
1020 /* Not all thinkpads have a hardware radio switch */
1021 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1022 tp_features
.hotkey_wlsw
= 1;
1024 "radio switch found; radios are %s\n",
1025 enabled(status
, 0));
1026 res
= add_to_attr_set(hotkey_dev_attributes
,
1027 &dev_attr_hotkey_radio_sw
.attr
);
1031 res
= register_attr_set_with_sysfs(
1032 hotkey_dev_attributes
,
1033 &tpacpi_pdev
->dev
.kobj
);
1037 /* Set up key map */
1039 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1041 if (!hotkey_keycode_map
) {
1042 printk(IBM_ERR
"failed to allocate memory for key map\n");
1046 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1047 dbg_printk(TPACPI_DBG_INIT
,
1048 "using Lenovo default hot key map\n");
1049 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1050 TPACPI_HOTKEY_MAP_SIZE
);
1052 dbg_printk(TPACPI_DBG_INIT
,
1053 "using IBM default hot key map\n");
1054 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1055 TPACPI_HOTKEY_MAP_SIZE
);
1058 #ifndef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
1059 for (i
= 0; i
< 12; i
++)
1060 hotkey_keycode_map
[i
] = KEY_UNKNOWN
;
1061 #endif /* ! CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
1063 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1064 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1065 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1066 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1067 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1068 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1069 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1070 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1071 set_bit(hotkey_keycode_map
[i
],
1072 tpacpi_inputdev
->keybit
);
1074 if (i
< sizeof(hotkey_reserved_mask
)*8)
1075 hotkey_reserved_mask
|= 1 << i
;
1079 if (tp_features
.hotkey_wlsw
) {
1080 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1081 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1084 #ifdef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
1085 dbg_printk(TPACPI_DBG_INIT
,
1086 "enabling hot key handling\n");
1087 res
= hotkey_set(1, (hotkey_all_mask
& ~hotkey_reserved_mask
)
1088 | hotkey_orig_mask
);
1091 #endif /* CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
1094 return (tp_features
.hotkey
)? 0 : 1;
1097 static void hotkey_exit(void)
1101 if (tp_features
.hotkey
) {
1102 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
1103 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
1105 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
1108 if (hotkey_dev_attributes
) {
1109 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1110 hotkey_dev_attributes
= NULL
;
1114 static void tpacpi_input_send_key(unsigned int scancode
,
1115 unsigned int keycode
)
1117 if (keycode
!= KEY_RESERVED
) {
1118 input_report_key(tpacpi_inputdev
, keycode
, 1);
1119 if (keycode
== KEY_UNKNOWN
)
1120 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1122 input_sync(tpacpi_inputdev
);
1124 input_report_key(tpacpi_inputdev
, keycode
, 0);
1125 if (keycode
== KEY_UNKNOWN
)
1126 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1128 input_sync(tpacpi_inputdev
);
1132 static void tpacpi_input_send_radiosw(void)
1136 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
))
1137 input_report_switch(tpacpi_inputdev
,
1141 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1144 unsigned int keycode
, scancode
;
1147 if (event
== 0x80 && acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1148 if (tpacpi_inputdev
->users
> 0) {
1149 switch (hkey
>> 12) {
1151 /* 0x1000-0x1FFF: key presses */
1152 scancode
= hkey
& 0xfff;
1153 if (scancode
> 0 && scancode
< 0x21) {
1155 keycode
= hotkey_keycode_map
[scancode
];
1156 tpacpi_input_send_key(scancode
, keycode
);
1157 sendacpi
= (keycode
== KEY_RESERVED
1158 || keycode
== KEY_UNKNOWN
);
1161 "hotkey 0x%04x out of range for keyboard map\n",
1166 /* 0x5000-0x5FFF: LID */
1167 /* we don't handle it through this path, just
1168 * eat up known LID events */
1169 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1171 "unknown LID-related hotkey event: 0x%04x\n",
1176 /* 0x7000-0x7FFF: misc */
1177 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1178 tpacpi_input_send_radiosw();
1182 /* fallthrough to default */
1184 /* case 2: dock-related */
1185 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1186 /* case 3: ultra-bay related. maybe bay in dock? */
1187 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1188 printk(IBM_NOTICE
"unhandled hotkey event 0x%04x\n", hkey
);
1193 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, hkey
);
1195 printk(IBM_ERR
"unknown hotkey notification event %d\n", event
);
1196 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
1200 static void hotkey_resume(void)
1202 tpacpi_input_send_radiosw();
1206 * Call with hotkey_mutex held
1208 static int hotkey_get(int *status
, u32
*mask
)
1210 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1213 if (tp_features
.hotkey_mask
)
1214 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1221 * Call with hotkey_mutex held
1223 static int hotkey_set(int status
, u32 mask
)
1227 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1230 if (tp_features
.hotkey_mask
)
1231 for (i
= 0; i
< 32; i
++) {
1232 int bit
= ((1 << i
) & mask
) != 0;
1233 if (!acpi_evalf(hkey_handle
,
1234 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1241 /* procfs -------------------------------------------------------------- */
1242 static int hotkey_read(char *p
)
1248 if (!tp_features
.hotkey
) {
1249 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1253 res
= mutex_lock_interruptible(&hotkey_mutex
);
1256 res
= hotkey_get(&status
, &mask
);
1257 mutex_unlock(&hotkey_mutex
);
1261 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1262 if (tp_features
.hotkey_mask
) {
1263 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1264 len
+= sprintf(p
+ len
,
1265 "commands:\tenable, disable, reset, <mask>\n");
1267 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1268 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1274 static int hotkey_write(char *buf
)
1281 if (!tp_features
.hotkey
)
1284 res
= mutex_lock_interruptible(&hotkey_mutex
);
1288 res
= hotkey_get(&status
, &mask
);
1293 while ((cmd
= next_cmd(&buf
))) {
1294 if (strlencmp(cmd
, "enable") == 0) {
1296 } else if (strlencmp(cmd
, "disable") == 0) {
1298 } else if (strlencmp(cmd
, "reset") == 0) {
1299 status
= hotkey_orig_status
;
1300 mask
= hotkey_orig_mask
;
1301 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1303 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1313 res
= hotkey_set(status
, mask
);
1316 mutex_unlock(&hotkey_mutex
);
1320 static const struct acpi_device_id ibm_htk_device_ids
[] = {
1325 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1326 .hid
= ibm_htk_device_ids
,
1327 .notify
= hotkey_notify
,
1328 .handle
= &hkey_handle
,
1329 .type
= ACPI_DEVICE_NOTIFY
,
1332 static struct ibm_struct hotkey_driver_data
= {
1334 .read
= hotkey_read
,
1335 .write
= hotkey_write
,
1336 .exit
= hotkey_exit
,
1337 .resume
= hotkey_resume
,
1338 .acpi
= &ibm_hotkey_acpidriver
,
1341 /*************************************************************************
1342 * Bluetooth subdriver
1345 /* sysfs bluetooth enable ---------------------------------------------- */
1346 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1347 struct device_attribute
*attr
,
1352 status
= bluetooth_get_radiosw();
1356 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1359 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1360 struct device_attribute
*attr
,
1361 const char *buf
, size_t count
)
1366 if (parse_strtoul(buf
, 1, &t
))
1369 res
= bluetooth_set_radiosw(t
);
1371 return (res
) ? res
: count
;
1374 static struct device_attribute dev_attr_bluetooth_enable
=
1375 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1376 bluetooth_enable_show
, bluetooth_enable_store
);
1378 /* --------------------------------------------------------------------- */
1380 static struct attribute
*bluetooth_attributes
[] = {
1381 &dev_attr_bluetooth_enable
.attr
,
1385 static const struct attribute_group bluetooth_attr_group
= {
1386 .attrs
= bluetooth_attributes
,
1389 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1394 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1396 IBM_ACPIHANDLE_INIT(hkey
);
1398 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1399 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1400 tp_features
.bluetooth
= hkey_handle
&&
1401 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1403 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1404 str_supported(tp_features
.bluetooth
),
1407 if (tp_features
.bluetooth
) {
1408 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1409 /* no bluetooth hardware present in system */
1410 tp_features
.bluetooth
= 0;
1411 dbg_printk(TPACPI_DBG_INIT
,
1412 "bluetooth hardware not installed\n");
1414 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1415 &bluetooth_attr_group
);
1421 return (tp_features
.bluetooth
)? 0 : 1;
1424 static void bluetooth_exit(void)
1426 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1427 &bluetooth_attr_group
);
1430 static int bluetooth_get_radiosw(void)
1434 if (!tp_features
.bluetooth
)
1437 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1440 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1443 static int bluetooth_set_radiosw(int radio_on
)
1447 if (!tp_features
.bluetooth
)
1450 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1453 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1455 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1456 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1462 /* procfs -------------------------------------------------------------- */
1463 static int bluetooth_read(char *p
)
1466 int status
= bluetooth_get_radiosw();
1468 if (!tp_features
.bluetooth
)
1469 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1471 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1472 (status
)? "enabled" : "disabled");
1473 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1479 static int bluetooth_write(char *buf
)
1483 if (!tp_features
.bluetooth
)
1486 while ((cmd
= next_cmd(&buf
))) {
1487 if (strlencmp(cmd
, "enable") == 0) {
1488 bluetooth_set_radiosw(1);
1489 } else if (strlencmp(cmd
, "disable") == 0) {
1490 bluetooth_set_radiosw(0);
1498 static struct ibm_struct bluetooth_driver_data
= {
1499 .name
= "bluetooth",
1500 .read
= bluetooth_read
,
1501 .write
= bluetooth_write
,
1502 .exit
= bluetooth_exit
,
1505 /*************************************************************************
1509 /* sysfs wan enable ---------------------------------------------------- */
1510 static ssize_t
wan_enable_show(struct device
*dev
,
1511 struct device_attribute
*attr
,
1516 status
= wan_get_radiosw();
1520 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1523 static ssize_t
wan_enable_store(struct device
*dev
,
1524 struct device_attribute
*attr
,
1525 const char *buf
, size_t count
)
1530 if (parse_strtoul(buf
, 1, &t
))
1533 res
= wan_set_radiosw(t
);
1535 return (res
) ? res
: count
;
1538 static struct device_attribute dev_attr_wan_enable
=
1539 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1540 wan_enable_show
, wan_enable_store
);
1542 /* --------------------------------------------------------------------- */
1544 static struct attribute
*wan_attributes
[] = {
1545 &dev_attr_wan_enable
.attr
,
1549 static const struct attribute_group wan_attr_group
= {
1550 .attrs
= wan_attributes
,
1553 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1558 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1560 IBM_ACPIHANDLE_INIT(hkey
);
1562 tp_features
.wan
= hkey_handle
&&
1563 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1565 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1566 str_supported(tp_features
.wan
),
1569 if (tp_features
.wan
) {
1570 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1571 /* no wan hardware present in system */
1572 tp_features
.wan
= 0;
1573 dbg_printk(TPACPI_DBG_INIT
,
1574 "wan hardware not installed\n");
1576 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1583 return (tp_features
.wan
)? 0 : 1;
1586 static void wan_exit(void)
1588 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1592 static int wan_get_radiosw(void)
1596 if (!tp_features
.wan
)
1599 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1602 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1605 static int wan_set_radiosw(int radio_on
)
1609 if (!tp_features
.wan
)
1612 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1615 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1617 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1618 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1624 /* procfs -------------------------------------------------------------- */
1625 static int wan_read(char *p
)
1628 int status
= wan_get_radiosw();
1630 if (!tp_features
.wan
)
1631 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1633 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1634 (status
)? "enabled" : "disabled");
1635 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1641 static int wan_write(char *buf
)
1645 if (!tp_features
.wan
)
1648 while ((cmd
= next_cmd(&buf
))) {
1649 if (strlencmp(cmd
, "enable") == 0) {
1651 } else if (strlencmp(cmd
, "disable") == 0) {
1660 static struct ibm_struct wan_driver_data
= {
1665 .flags
.experimental
= 1,
1668 /*************************************************************************
1672 static enum video_access_mode video_supported
;
1673 static int video_orig_autosw
;
1675 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1676 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1677 "\\_SB.PCI0.VID0", /* 770e */
1678 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1679 "\\_SB.PCI0.AGP.VID", /* all others */
1682 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1684 static int __init
video_init(struct ibm_init_struct
*iibm
)
1688 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1690 IBM_ACPIHANDLE_INIT(vid
);
1691 IBM_ACPIHANDLE_INIT(vid2
);
1693 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1694 /* G41, assume IVGA doesn't change */
1695 vid_handle
= vid2_handle
;
1698 /* video switching not supported on R30, R31 */
1699 video_supported
= TPACPI_VIDEO_NONE
;
1700 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1702 video_supported
= TPACPI_VIDEO_570
;
1703 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1704 /* 600e/x, 770e, 770x */
1705 video_supported
= TPACPI_VIDEO_770
;
1708 video_supported
= TPACPI_VIDEO_NEW
;
1710 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1711 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1714 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1717 static void video_exit(void)
1719 dbg_printk(TPACPI_DBG_EXIT
,
1720 "restoring original video autoswitch mode\n");
1721 if (video_autosw_set(video_orig_autosw
))
1722 printk(IBM_ERR
"error while trying to restore original "
1723 "video autoswitch mode\n");
1726 static int video_outputsw_get(void)
1731 switch (video_supported
) {
1732 case TPACPI_VIDEO_570
:
1733 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1734 TP_ACPI_VIDEO_570_PHSCMD
))
1736 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1738 case TPACPI_VIDEO_770
:
1739 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1742 status
|= TP_ACPI_VIDEO_S_LCD
;
1743 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1746 status
|= TP_ACPI_VIDEO_S_CRT
;
1748 case TPACPI_VIDEO_NEW
:
1749 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1750 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1753 status
|= TP_ACPI_VIDEO_S_CRT
;
1755 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1756 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1759 status
|= TP_ACPI_VIDEO_S_LCD
;
1760 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1763 status
|= TP_ACPI_VIDEO_S_DVI
;
1772 static int video_outputsw_set(int status
)
1777 switch (video_supported
) {
1778 case TPACPI_VIDEO_570
:
1779 res
= acpi_evalf(NULL
, NULL
,
1780 "\\_SB.PHS2", "vdd",
1781 TP_ACPI_VIDEO_570_PHS2CMD
,
1782 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1784 case TPACPI_VIDEO_770
:
1785 autosw
= video_autosw_get();
1789 res
= video_autosw_set(1);
1792 res
= acpi_evalf(vid_handle
, NULL
,
1793 "ASWT", "vdd", status
* 0x100, 0);
1794 if (!autosw
&& video_autosw_set(autosw
)) {
1795 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1799 case TPACPI_VIDEO_NEW
:
1800 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1801 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1807 return (res
)? 0 : -EIO
;
1810 static int video_autosw_get(void)
1814 switch (video_supported
) {
1815 case TPACPI_VIDEO_570
:
1816 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1819 case TPACPI_VIDEO_770
:
1820 case TPACPI_VIDEO_NEW
:
1821 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1831 static int video_autosw_set(int enable
)
1833 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1838 static int video_outputsw_cycle(void)
1840 int autosw
= video_autosw_get();
1846 switch (video_supported
) {
1847 case TPACPI_VIDEO_570
:
1848 res
= video_autosw_set(1);
1851 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1853 case TPACPI_VIDEO_770
:
1854 case TPACPI_VIDEO_NEW
:
1855 res
= video_autosw_set(1);
1858 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1863 if (!autosw
&& video_autosw_set(autosw
)) {
1864 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1868 return (res
)? 0 : -EIO
;
1871 static int video_expand_toggle(void)
1873 switch (video_supported
) {
1874 case TPACPI_VIDEO_570
:
1875 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1877 case TPACPI_VIDEO_770
:
1878 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1880 case TPACPI_VIDEO_NEW
:
1881 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1889 static int video_read(char *p
)
1894 if (video_supported
== TPACPI_VIDEO_NONE
) {
1895 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1899 status
= video_outputsw_get();
1903 autosw
= video_autosw_get();
1907 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1908 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
1909 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
1910 if (video_supported
== TPACPI_VIDEO_NEW
)
1911 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
1912 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
1913 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
1914 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
1915 if (video_supported
== TPACPI_VIDEO_NEW
)
1916 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
1917 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
1918 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
1923 static int video_write(char *buf
)
1926 int enable
, disable
, status
;
1929 if (video_supported
== TPACPI_VIDEO_NONE
)
1935 while ((cmd
= next_cmd(&buf
))) {
1936 if (strlencmp(cmd
, "lcd_enable") == 0) {
1937 enable
|= TP_ACPI_VIDEO_S_LCD
;
1938 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1939 disable
|= TP_ACPI_VIDEO_S_LCD
;
1940 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1941 enable
|= TP_ACPI_VIDEO_S_CRT
;
1942 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1943 disable
|= TP_ACPI_VIDEO_S_CRT
;
1944 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1945 strlencmp(cmd
, "dvi_enable") == 0) {
1946 enable
|= TP_ACPI_VIDEO_S_DVI
;
1947 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1948 strlencmp(cmd
, "dvi_disable") == 0) {
1949 disable
|= TP_ACPI_VIDEO_S_DVI
;
1950 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1951 res
= video_autosw_set(1);
1954 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1955 res
= video_autosw_set(0);
1958 } else if (strlencmp(cmd
, "video_switch") == 0) {
1959 res
= video_outputsw_cycle();
1962 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1963 res
= video_expand_toggle();
1970 if (enable
|| disable
) {
1971 status
= video_outputsw_get();
1974 res
= video_outputsw_set((status
& ~disable
) | enable
);
1982 static struct ibm_struct video_driver_data
= {
1985 .write
= video_write
,
1989 /*************************************************************************
1990 * Light (thinklight) subdriver
1993 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1994 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1996 static int __init
light_init(struct ibm_init_struct
*iibm
)
1998 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2000 IBM_ACPIHANDLE_INIT(ledb
);
2001 IBM_ACPIHANDLE_INIT(lght
);
2002 IBM_ACPIHANDLE_INIT(cmos
);
2004 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2005 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2007 if (tp_features
.light
)
2008 /* light status not supported on
2009 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2010 tp_features
.light_status
=
2011 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2013 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2014 str_supported(tp_features
.light
));
2016 return (tp_features
.light
)? 0 : 1;
2019 static int light_read(char *p
)
2024 if (!tp_features
.light
) {
2025 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2026 } else if (!tp_features
.light_status
) {
2027 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2028 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2030 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2032 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2033 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2039 static int light_write(char *buf
)
2041 int cmos_cmd
, lght_cmd
;
2045 if (!tp_features
.light
)
2048 while ((cmd
= next_cmd(&buf
))) {
2049 if (strlencmp(cmd
, "on") == 0) {
2052 } else if (strlencmp(cmd
, "off") == 0) {
2058 success
= cmos_handle
?
2059 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2060 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2068 static struct ibm_struct light_driver_data
= {
2071 .write
= light_write
,
2074 /*************************************************************************
2078 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2080 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2081 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2082 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2083 "\\_SB.PCI.ISA.SLCE", /* 570 */
2084 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2086 /* don't list other alternatives as we install a notify handler on the 570 */
2087 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2089 static const struct acpi_device_id ibm_pci_device_ids
[] = {
2090 {PCI_ROOT_HID_STRING
, 0},
2094 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2096 .notify
= dock_notify
,
2097 .handle
= &dock_handle
,
2098 .type
= ACPI_SYSTEM_NOTIFY
,
2101 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2102 * We just use it to get notifications of dock hotplug
2103 * in very old thinkpads */
2104 .hid
= ibm_pci_device_ids
,
2105 .notify
= dock_notify
,
2106 .handle
= &pci_handle
,
2107 .type
= ACPI_SYSTEM_NOTIFY
,
2111 static struct ibm_struct dock_driver_data
[2] = {
2115 .write
= dock_write
,
2116 .acpi
= &ibm_dock_acpidriver
[0],
2120 .acpi
= &ibm_dock_acpidriver
[1],
2124 #define dock_docked() (_sta(dock_handle) & 1)
2126 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2128 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2130 IBM_ACPIHANDLE_INIT(dock
);
2132 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2133 str_supported(dock_handle
!= NULL
));
2135 return (dock_handle
)? 0 : 1;
2138 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2142 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2144 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2145 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2146 IBM_ACPIHANDLE_INIT(pci
);
2147 dock2_needed
= (pci_handle
!= NULL
);
2148 vdbg_printk(TPACPI_DBG_INIT
,
2149 "dock PCI handler for the TP 570 is %s\n",
2150 str_supported(dock2_needed
));
2152 vdbg_printk(TPACPI_DBG_INIT
,
2153 "dock subdriver part 2 not required\n");
2157 return (dock2_needed
)? 0 : 1;
2160 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2162 int docked
= dock_docked();
2163 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
2164 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
2167 if (event
== 1 && !pci
) /* 570 */
2168 data
= 1; /* button */
2169 else if (event
== 1 && pci
) /* 570 */
2170 data
= 3; /* dock */
2171 else if (event
== 3 && docked
)
2172 data
= 1; /* button */
2173 else if (event
== 3 && !docked
)
2174 data
= 2; /* undock */
2175 else if (event
== 0 && docked
)
2176 data
= 3; /* dock */
2178 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2179 event
, _sta(dock_handle
));
2180 data
= 0; /* unknown */
2182 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
2183 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
2184 ibm
->acpi
->device
->dev
.bus_id
,
2188 static int dock_read(char *p
)
2191 int docked
= dock_docked();
2194 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2196 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2198 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2199 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2205 static int dock_write(char *buf
)
2212 while ((cmd
= next_cmd(&buf
))) {
2213 if (strlencmp(cmd
, "undock") == 0) {
2214 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2215 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2217 } else if (strlencmp(cmd
, "dock") == 0) {
2218 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2227 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2229 /*************************************************************************
2233 #ifdef CONFIG_THINKPAD_ACPI_BAY
2234 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2235 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2236 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2237 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2238 ); /* A21e, R30, R31 */
2239 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2240 "_EJ0", /* all others */
2241 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2242 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2243 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2245 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2249 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2251 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2253 IBM_ACPIHANDLE_INIT(bay
);
2255 IBM_ACPIHANDLE_INIT(bay_ej
);
2256 IBM_ACPIHANDLE_INIT(bay2
);
2258 IBM_ACPIHANDLE_INIT(bay2_ej
);
2260 tp_features
.bay_status
= bay_handle
&&
2261 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2262 tp_features
.bay_status2
= bay2_handle
&&
2263 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2265 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2266 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2267 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2268 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2270 vdbg_printk(TPACPI_DBG_INIT
,
2271 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2272 str_supported(tp_features
.bay_status
),
2273 str_supported(tp_features
.bay_eject
),
2274 str_supported(tp_features
.bay_status2
),
2275 str_supported(tp_features
.bay_eject2
));
2277 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2278 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2281 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2283 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
2284 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
2285 ibm
->acpi
->device
->dev
.bus_id
,
2289 #define bay_occupied(b) (_sta(b##_handle) & 1)
2291 static int bay_read(char *p
)
2294 int occupied
= bay_occupied(bay
);
2295 int occupied2
= bay_occupied(bay2
);
2298 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2299 tp_features
.bay_status
?
2300 (occupied
? "occupied" : "unoccupied") :
2302 if (tp_features
.bay_status2
)
2303 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2304 "occupied" : "unoccupied");
2306 eject
= tp_features
.bay_eject
&& occupied
;
2307 eject2
= tp_features
.bay_eject2
&& occupied2
;
2309 if (eject
&& eject2
)
2310 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2312 len
+= sprintf(p
+ len
, "commands:\teject\n");
2314 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2319 static int bay_write(char *buf
)
2323 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2326 while ((cmd
= next_cmd(&buf
))) {
2327 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2328 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2330 } else if (tp_features
.bay_eject2
&&
2331 strlencmp(cmd
, "eject2") == 0) {
2332 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2341 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2342 .notify
= bay_notify
,
2343 .handle
= &bay_handle
,
2344 .type
= ACPI_SYSTEM_NOTIFY
,
2347 static struct ibm_struct bay_driver_data
= {
2351 .acpi
= &ibm_bay_acpidriver
,
2354 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2356 /*************************************************************************
2360 /* sysfs cmos_command -------------------------------------------------- */
2361 static ssize_t
cmos_command_store(struct device
*dev
,
2362 struct device_attribute
*attr
,
2363 const char *buf
, size_t count
)
2365 unsigned long cmos_cmd
;
2368 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2371 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2372 return (res
)? res
: count
;
2375 static struct device_attribute dev_attr_cmos_command
=
2376 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2378 /* --------------------------------------------------------------------- */
2380 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2384 vdbg_printk(TPACPI_DBG_INIT
,
2385 "initializing cmos commands subdriver\n");
2387 IBM_ACPIHANDLE_INIT(cmos
);
2389 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2390 str_supported(cmos_handle
!= NULL
));
2392 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2396 return (cmos_handle
)? 0 : 1;
2399 static void cmos_exit(void)
2401 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2404 static int cmos_read(char *p
)
2408 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2409 R30, R31, T20-22, X20-21 */
2411 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2413 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2414 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2420 static int cmos_write(char *buf
)
2425 while ((cmd
= next_cmd(&buf
))) {
2426 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2427 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2432 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2440 static struct ibm_struct cmos_driver_data
= {
2443 .write
= cmos_write
,
2447 /*************************************************************************
2451 static enum led_access_mode led_supported
;
2453 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2454 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2455 "LED", /* all others */
2458 static int __init
led_init(struct ibm_init_struct
*iibm
)
2460 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2462 IBM_ACPIHANDLE_INIT(led
);
2465 /* led not supported on R30, R31 */
2466 led_supported
= TPACPI_LED_NONE
;
2467 else if (strlencmp(led_path
, "SLED") == 0)
2469 led_supported
= TPACPI_LED_570
;
2470 else if (strlencmp(led_path
, "SYSL") == 0)
2471 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2472 led_supported
= TPACPI_LED_OLD
;
2475 led_supported
= TPACPI_LED_NEW
;
2477 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2478 str_supported(led_supported
), led_supported
);
2480 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2483 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2485 static int led_read(char *p
)
2489 if (!led_supported
) {
2490 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2493 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2495 if (led_supported
== TPACPI_LED_570
) {
2498 for (i
= 0; i
< 8; i
++) {
2499 if (!acpi_evalf(ec_handle
,
2500 &status
, "GLED", "dd", 1 << i
))
2502 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2503 i
, led_status(status
));
2507 len
+= sprintf(p
+ len
, "commands:\t"
2508 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2513 /* off, on, blink */
2514 static const int led_sled_arg1
[] = { 0, 1, 3 };
2515 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2516 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2517 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2519 static int led_write(char *buf
)
2527 while ((cmd
= next_cmd(&buf
))) {
2528 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2531 if (strstr(cmd
, "off")) {
2533 } else if (strstr(cmd
, "on")) {
2535 } else if (strstr(cmd
, "blink")) {
2540 if (led_supported
== TPACPI_LED_570
) {
2543 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2544 led
, led_sled_arg1
[ind
]))
2546 } else if (led_supported
== TPACPI_LED_OLD
) {
2547 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2549 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2552 ec_write(TPACPI_LED_EC_HLBL
,
2553 led
* led_exp_hlbl
[ind
]);
2556 ec_write(TPACPI_LED_EC_HLCL
,
2557 led
* led_exp_hlcl
[ind
]);
2562 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2563 led
, led_led_arg1
[ind
]))
2571 static struct ibm_struct led_driver_data
= {
2577 /*************************************************************************
2581 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2583 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2585 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2587 IBM_ACPIHANDLE_INIT(beep
);
2589 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2590 str_supported(beep_handle
!= NULL
));
2592 return (beep_handle
)? 0 : 1;
2595 static int beep_read(char *p
)
2600 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2602 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2603 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2609 static int beep_write(char *buf
)
2617 while ((cmd
= next_cmd(&buf
))) {
2618 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2619 beep_cmd
>= 0 && beep_cmd
<= 17) {
2623 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2630 static struct ibm_struct beep_driver_data
= {
2633 .write
= beep_write
,
2636 /*************************************************************************
2640 static enum thermal_access_mode thermal_read_mode
;
2642 /* sysfs temp##_input -------------------------------------------------- */
2644 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2645 struct device_attribute
*attr
,
2648 struct sensor_device_attribute
*sensor_attr
=
2649 to_sensor_dev_attr(attr
);
2650 int idx
= sensor_attr
->index
;
2654 res
= thermal_get_sensor(idx
, &value
);
2657 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2660 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2663 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2664 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2666 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2667 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2668 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2669 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2670 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2671 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2672 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2673 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2674 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2675 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2676 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2677 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2678 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2679 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2680 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2681 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2682 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2685 #define THERMAL_ATTRS(X) \
2686 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2688 static struct attribute
*thermal_temp_input_attr
[] = {
2708 static const struct attribute_group thermal_temp_input16_group
= {
2709 .attrs
= thermal_temp_input_attr
2712 static const struct attribute_group thermal_temp_input8_group
= {
2713 .attrs
= &thermal_temp_input_attr
[8]
2716 #undef THERMAL_SENSOR_ATTR_TEMP
2717 #undef THERMAL_ATTRS
2719 /* --------------------------------------------------------------------- */
2721 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2728 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2730 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2732 if (thinkpad_id
.ec_model
) {
2734 * Direct EC access mode: sensors at registers
2735 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2736 * non-implemented, thermal sensors return 0x80 when
2741 for (i
= 0; i
< 8; i
++) {
2742 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2748 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2756 /* This is sheer paranoia, but we handle it anyway */
2759 "ThinkPad ACPI EC access misbehaving, "
2760 "falling back to ACPI TMPx access mode\n");
2761 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2764 "ThinkPad ACPI EC access misbehaving, "
2765 "disabling thermal sensors access\n");
2766 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2771 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2773 } else if (acpi_tmp7
) {
2774 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2775 /* 600e/x, 770e, 770x */
2776 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2778 /* Standard ACPI TMPx access, max 8 sensors */
2779 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2782 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2783 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2786 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2787 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2790 switch(thermal_read_mode
) {
2791 case TPACPI_THERMAL_TPEC_16
:
2792 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2793 &thermal_temp_input16_group
);
2797 case TPACPI_THERMAL_TPEC_8
:
2798 case TPACPI_THERMAL_ACPI_TMP07
:
2799 case TPACPI_THERMAL_ACPI_UPDT
:
2800 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2801 &thermal_temp_input8_group
);
2805 case TPACPI_THERMAL_NONE
:
2813 static void thermal_exit(void)
2815 switch(thermal_read_mode
) {
2816 case TPACPI_THERMAL_TPEC_16
:
2817 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2818 &thermal_temp_input16_group
);
2820 case TPACPI_THERMAL_TPEC_8
:
2821 case TPACPI_THERMAL_ACPI_TMP07
:
2822 case TPACPI_THERMAL_ACPI_UPDT
:
2823 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2824 &thermal_temp_input16_group
);
2826 case TPACPI_THERMAL_NONE
:
2832 /* idx is zero-based */
2833 static int thermal_get_sensor(int idx
, s32
*value
)
2839 t
= TP_EC_THERMAL_TMP0
;
2841 switch (thermal_read_mode
) {
2842 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2843 case TPACPI_THERMAL_TPEC_16
:
2844 if (idx
>= 8 && idx
<= 15) {
2845 t
= TP_EC_THERMAL_TMP8
;
2850 case TPACPI_THERMAL_TPEC_8
:
2852 if (!acpi_ec_read(t
+ idx
, &tmp
))
2854 *value
= tmp
* 1000;
2859 case TPACPI_THERMAL_ACPI_UPDT
:
2861 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2862 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2864 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2866 *value
= (t
- 2732) * 100;
2871 case TPACPI_THERMAL_ACPI_TMP07
:
2873 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2874 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2876 if (t
> 127 || t
< -127)
2877 t
= TP_EC_THERMAL_TMP_NA
;
2883 case TPACPI_THERMAL_NONE
:
2891 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2902 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2905 for(i
= 0 ; i
< n
; i
++) {
2906 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
2914 static int thermal_read(char *p
)
2918 struct ibm_thermal_sensors_struct t
;
2920 n
= thermal_get_sensors(&t
);
2921 if (unlikely(n
< 0))
2924 len
+= sprintf(p
+ len
, "temperatures:\t");
2927 for (i
= 0; i
< (n
- 1); i
++)
2928 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
2929 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
2931 len
+= sprintf(p
+ len
, "not supported\n");
2936 static struct ibm_struct thermal_driver_data
= {
2938 .read
= thermal_read
,
2939 .exit
= thermal_exit
,
2942 /*************************************************************************
2946 static u8 ecdump_regs
[256];
2948 static int ecdump_read(char *p
)
2954 len
+= sprintf(p
+ len
, "EC "
2955 " +00 +01 +02 +03 +04 +05 +06 +07"
2956 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2957 for (i
= 0; i
< 256; i
+= 16) {
2958 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
2959 for (j
= 0; j
< 16; j
++) {
2960 if (!acpi_ec_read(i
+ j
, &v
))
2962 if (v
!= ecdump_regs
[i
+ j
])
2963 len
+= sprintf(p
+ len
, " *%02x", v
);
2965 len
+= sprintf(p
+ len
, " %02x", v
);
2966 ecdump_regs
[i
+ j
] = v
;
2968 len
+= sprintf(p
+ len
, "\n");
2973 /* These are way too dangerous to advertise openly... */
2975 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
2976 " (<offset> is 00-ff, <value> is 00-ff)\n");
2977 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
2978 " (<offset> is 00-ff, <value> is 0-255)\n");
2983 static int ecdump_write(char *buf
)
2988 while ((cmd
= next_cmd(&buf
))) {
2989 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
2991 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
2995 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
2996 if (!acpi_ec_write(i
, v
))
3005 static struct ibm_struct ecdump_driver_data
= {
3007 .read
= ecdump_read
,
3008 .write
= ecdump_write
,
3009 .flags
.experimental
= 1,
3012 /*************************************************************************
3013 * Backlight/brightness subdriver
3016 static struct backlight_device
*ibm_backlight_device
;
3018 static struct backlight_ops ibm_backlight_data
= {
3019 .get_brightness
= brightness_get
,
3020 .update_status
= brightness_update_status
,
3023 static struct mutex brightness_mutex
;
3025 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
3029 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
3031 mutex_init(&brightness_mutex
);
3033 if (!brightness_mode
) {
3034 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
3035 brightness_mode
= 2;
3037 brightness_mode
= 3;
3039 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
3043 if (brightness_mode
> 3)
3046 b
= brightness_get(NULL
);
3050 ibm_backlight_device
= backlight_device_register(
3051 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
3052 &ibm_backlight_data
);
3053 if (IS_ERR(ibm_backlight_device
)) {
3054 printk(IBM_ERR
"Could not register backlight device\n");
3055 return PTR_ERR(ibm_backlight_device
);
3057 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
3059 ibm_backlight_device
->props
.max_brightness
= 7;
3060 ibm_backlight_device
->props
.brightness
= b
;
3061 backlight_update_status(ibm_backlight_device
);
3066 static void brightness_exit(void)
3068 if (ibm_backlight_device
) {
3069 vdbg_printk(TPACPI_DBG_EXIT
,
3070 "calling backlight_device_unregister()\n");
3071 backlight_device_unregister(ibm_backlight_device
);
3072 ibm_backlight_device
= NULL
;
3076 static int brightness_update_status(struct backlight_device
*bd
)
3078 return brightness_set(
3079 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
3080 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
3081 bd
->props
.brightness
: 0);
3085 * ThinkPads can read brightness from two places: EC 0x31, or
3086 * CMOS NVRAM byte 0x5E, bits 0-3.
3088 static int brightness_get(struct backlight_device
*bd
)
3090 u8 lec
= 0, lcmos
= 0, level
= 0;
3092 if (brightness_mode
& 1) {
3093 if (!acpi_ec_read(brightness_offset
, &lec
))
3098 if (brightness_mode
& 2) {
3099 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3100 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3101 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3105 if (brightness_mode
== 3 && lec
!= lcmos
) {
3107 "CMOS NVRAM (%u) and EC (%u) do not agree "
3108 "on display brightness level\n",
3109 (unsigned int) lcmos
,
3110 (unsigned int) lec
);
3117 static int brightness_set(int value
)
3119 int cmos_cmd
, inc
, i
, res
;
3125 res
= mutex_lock_interruptible(&brightness_mutex
);
3129 current_value
= brightness_get(NULL
);
3130 if (current_value
< 0) {
3131 res
= current_value
;
3135 cmos_cmd
= value
> current_value
?
3136 TP_CMOS_BRIGHTNESS_UP
:
3137 TP_CMOS_BRIGHTNESS_DOWN
;
3138 inc
= value
> current_value
? 1 : -1;
3141 for (i
= current_value
; i
!= value
; i
+= inc
) {
3142 if ((brightness_mode
& 2) &&
3143 issue_thinkpad_cmos_command(cmos_cmd
)) {
3147 if ((brightness_mode
& 1) &&
3148 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
3155 mutex_unlock(&brightness_mutex
);
3159 static int brightness_read(char *p
)
3164 if ((level
= brightness_get(NULL
)) < 0) {
3165 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3167 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
3168 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3169 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3170 " (<level> is 0-7)\n");
3176 static int brightness_write(char *buf
)
3182 while ((cmd
= next_cmd(&buf
))) {
3183 if ((level
= brightness_get(NULL
)) < 0)
3187 if (strlencmp(cmd
, "up") == 0) {
3188 new_level
= level
== 7 ? 7 : level
+ 1;
3189 } else if (strlencmp(cmd
, "down") == 0) {
3190 new_level
= level
== 0 ? 0 : level
- 1;
3191 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3192 new_level
>= 0 && new_level
<= 7) {
3197 brightness_set(new_level
);
3203 static struct ibm_struct brightness_driver_data
= {
3204 .name
= "brightness",
3205 .read
= brightness_read
,
3206 .write
= brightness_write
,
3207 .exit
= brightness_exit
,
3210 /*************************************************************************
3214 static int volume_read(char *p
)
3219 if (!acpi_ec_read(volume_offset
, &level
)) {
3220 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3222 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3223 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3224 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3225 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3226 " (<level> is 0-15)\n");
3232 static int volume_write(char *buf
)
3234 int cmos_cmd
, inc
, i
;
3236 int new_level
, new_mute
;
3239 while ((cmd
= next_cmd(&buf
))) {
3240 if (!acpi_ec_read(volume_offset
, &level
))
3242 new_mute
= mute
= level
& 0x40;
3243 new_level
= level
= level
& 0xf;
3245 if (strlencmp(cmd
, "up") == 0) {
3249 new_level
= level
== 15 ? 15 : level
+ 1;
3250 } else if (strlencmp(cmd
, "down") == 0) {
3254 new_level
= level
== 0 ? 0 : level
- 1;
3255 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3256 new_level
>= 0 && new_level
<= 15) {
3258 } else if (strlencmp(cmd
, "mute") == 0) {
3263 if (new_level
!= level
) { /* mute doesn't change */
3264 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3265 inc
= new_level
> level
? 1 : -1;
3267 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3268 !acpi_ec_write(volume_offset
, level
)))
3271 for (i
= level
; i
!= new_level
; i
+= inc
)
3272 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3273 !acpi_ec_write(volume_offset
, i
+ inc
))
3276 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3277 !acpi_ec_write(volume_offset
,
3282 if (new_mute
!= mute
) { /* level doesn't change */
3283 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3285 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3286 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3294 static struct ibm_struct volume_driver_data
= {
3296 .read
= volume_read
,
3297 .write
= volume_write
,
3300 /*************************************************************************
3307 * TPACPI_FAN_RD_ACPI_GFAN:
3308 * ACPI GFAN method: returns fan level
3310 * see TPACPI_FAN_WR_ACPI_SFAN
3311 * EC 0x2f (HFSP) not available if GFAN exists
3313 * TPACPI_FAN_WR_ACPI_SFAN:
3314 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3316 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3319 * TPACPI_FAN_WR_TPEC:
3320 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3321 * Supported on almost all ThinkPads
3323 * Fan speed changes of any sort (including those caused by the
3324 * disengaged mode) are usually done slowly by the firmware as the
3325 * maximum ammount of fan duty cycle change per second seems to be
3328 * Reading is not available if GFAN exists.
3329 * Writing is not available if SFAN exists.
3332 * 7 automatic mode engaged;
3333 * (default operation mode of the ThinkPad)
3334 * fan level is ignored in this mode.
3335 * 6 full speed mode (takes precedence over bit 7);
3336 * not available on all thinkpads. May disable
3337 * the tachometer while the fan controller ramps up
3338 * the speed (which can take up to a few *minutes*).
3339 * Speeds up fan to 100% duty-cycle, which is far above
3340 * the standard RPM levels. It is not impossible that
3341 * it could cause hardware damage.
3342 * 5-3 unused in some models. Extra bits for fan level
3343 * in others, but still useless as all values above
3344 * 7 map to the same speed as level 7 in these models.
3345 * 2-0 fan level (0..7 usually)
3347 * 0x07 = max (set when temperatures critical)
3348 * Some ThinkPads may have other levels, see
3349 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3351 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3352 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3353 * does so, its initial value is meaningless (0x07).
3355 * For firmware bugs, refer to:
3356 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3360 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3361 * Main fan tachometer reading (in RPM)
3363 * This register is present on all ThinkPads with a new-style EC, and
3364 * it is known not to be present on the A21m/e, and T22, as there is
3365 * something else in offset 0x84 according to the ACPI DSDT. Other
3366 * ThinkPads from this same time period (and earlier) probably lack the
3367 * tachometer as well.
3369 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3370 * was never fixed by IBM to report the EC firmware version string
3371 * probably support the tachometer (like the early X models), so
3372 * detecting it is quite hard. We need more data to know for sure.
3374 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3377 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3380 * For firmware bugs, refer to:
3381 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3383 * TPACPI_FAN_WR_ACPI_FANS:
3384 * ThinkPad X31, X40, X41. Not available in the X60.
3386 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3387 * high speed. ACPI DSDT seems to map these three speeds to levels
3388 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3389 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3391 * The speeds are stored on handles
3392 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3394 * There are three default speed sets, acessible as handles:
3395 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3397 * ACPI DSDT switches which set is in use depending on various
3400 * TPACPI_FAN_WR_TPEC is also available and should be used to
3401 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3402 * but the ACPI tables just mention level 7.
3405 static enum fan_status_access_mode fan_status_access_mode
;
3406 static enum fan_control_access_mode fan_control_access_mode
;
3407 static enum fan_control_commands fan_control_commands
;
3409 static u8 fan_control_initial_status
;
3410 static u8 fan_control_desired_level
;
3412 static void fan_watchdog_fire(struct work_struct
*ignored
);
3413 static int fan_watchdog_maxinterval
;
3414 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3416 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3417 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3418 "\\FSPD", /* 600e/x, 770e, 770x */
3420 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3421 "JFNS", /* 770x-JL */
3425 * SYSFS fan layout: hwmon compatible (device)
3428 * 0: "disengaged" mode
3430 * 2: native EC "auto" mode (recommended, hardware default)
3432 * pwm*: set speed in manual mode, ignored otherwise.
3433 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3436 * fan*_input: tachometer reading, RPM
3439 * SYSFS fan layout: extensions
3441 * fan_watchdog (driver):
3442 * fan watchdog interval in seconds, 0 disables (default), max 120
3445 /* sysfs fan pwm1_enable ----------------------------------------------- */
3446 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3447 struct device_attribute
*attr
,
3453 res
= fan_get_status_safe(&status
);
3457 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3458 if (status
!= fan_control_initial_status
) {
3459 tp_features
.fan_ctrl_status_undef
= 0;
3461 /* Return most likely status. In fact, it
3462 * might be the only possible status */
3463 status
= TP_EC_FAN_AUTO
;
3467 if (status
& TP_EC_FAN_FULLSPEED
) {
3469 } else if (status
& TP_EC_FAN_AUTO
) {
3474 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3477 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3478 struct device_attribute
*attr
,
3479 const char *buf
, size_t count
)
3484 if (parse_strtoul(buf
, 2, &t
))
3489 level
= TP_EC_FAN_FULLSPEED
;
3492 level
= TPACPI_FAN_LAST_LEVEL
;
3495 level
= TP_EC_FAN_AUTO
;
3498 /* reserved for software-controlled auto mode */
3504 res
= fan_set_level_safe(level
);
3510 fan_watchdog_reset();
3515 static struct device_attribute dev_attr_fan_pwm1_enable
=
3516 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3517 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3519 /* sysfs fan pwm1 ------------------------------------------------------ */
3520 static ssize_t
fan_pwm1_show(struct device
*dev
,
3521 struct device_attribute
*attr
,
3527 res
= fan_get_status_safe(&status
);
3531 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3532 if (status
!= fan_control_initial_status
) {
3533 tp_features
.fan_ctrl_status_undef
= 0;
3535 status
= TP_EC_FAN_AUTO
;
3540 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3541 status
= fan_control_desired_level
;
3546 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3549 static ssize_t
fan_pwm1_store(struct device
*dev
,
3550 struct device_attribute
*attr
,
3551 const char *buf
, size_t count
)
3555 u8 status
, newlevel
;
3557 if (parse_strtoul(buf
, 255, &s
))
3560 /* scale down from 0-255 to 0-7 */
3561 newlevel
= (s
>> 5) & 0x07;
3563 rc
= mutex_lock_interruptible(&fan_mutex
);
3567 rc
= fan_get_status(&status
);
3568 if (!rc
&& (status
&
3569 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3570 rc
= fan_set_level(newlevel
);
3574 fan_update_desired_level(newlevel
);
3575 fan_watchdog_reset();
3579 mutex_unlock(&fan_mutex
);
3580 return (rc
)? rc
: count
;
3583 static struct device_attribute dev_attr_fan_pwm1
=
3584 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3585 fan_pwm1_show
, fan_pwm1_store
);
3587 /* sysfs fan fan1_input ------------------------------------------------ */
3588 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3589 struct device_attribute
*attr
,
3595 res
= fan_get_speed(&speed
);
3599 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3602 static struct device_attribute dev_attr_fan_fan1_input
=
3603 __ATTR(fan1_input
, S_IRUGO
,
3604 fan_fan1_input_show
, NULL
);
3606 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
3607 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3610 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3613 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3614 const char *buf
, size_t count
)
3618 if (parse_strtoul(buf
, 120, &t
))
3621 if (!fan_control_allowed
)
3624 fan_watchdog_maxinterval
= t
;
3625 fan_watchdog_reset();
3630 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3631 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3633 /* --------------------------------------------------------------------- */
3634 static struct attribute
*fan_attributes
[] = {
3635 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3636 &dev_attr_fan_fan1_input
.attr
,
3640 static const struct attribute_group fan_attr_group
= {
3641 .attrs
= fan_attributes
,
3644 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3648 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3650 mutex_init(&fan_mutex
);
3651 fan_status_access_mode
= TPACPI_FAN_NONE
;
3652 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3653 fan_control_commands
= 0;
3654 fan_watchdog_maxinterval
= 0;
3655 tp_features
.fan_ctrl_status_undef
= 0;
3656 fan_control_desired_level
= 7;
3658 IBM_ACPIHANDLE_INIT(fans
);
3659 IBM_ACPIHANDLE_INIT(gfan
);
3660 IBM_ACPIHANDLE_INIT(sfan
);
3663 /* 570, 600e/x, 770e, 770x */
3664 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3666 /* all other ThinkPads: note that even old-style
3667 * ThinkPad ECs supports the fan control register */
3668 if (likely(acpi_ec_read(fan_status_offset
,
3669 &fan_control_initial_status
))) {
3670 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3672 /* In some ThinkPads, neither the EC nor the ACPI
3673 * DSDT initialize the fan status, and it ends up
3674 * being set to 0x07 when it *could* be either
3677 * Enable for TP-1Y (T43), TP-78 (R51e),
3678 * TP-76 (R52), TP-70 (T43, R52), which are known
3680 if (fan_control_initial_status
== 0x07) {
3681 switch (thinkpad_id
.ec_model
) {
3682 case 0x5931: /* TP-1Y */
3683 case 0x3837: /* TP-78 */
3684 case 0x3637: /* TP-76 */
3685 case 0x3037: /* TP-70 */
3687 "fan_init: initial fan status is "
3688 "unknown, assuming it is in auto "
3690 tp_features
.fan_ctrl_status_undef
= 1;
3696 "ThinkPad ACPI EC access misbehaving, "
3697 "fan status and control unavailable\n");
3704 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3705 fan_control_commands
|=
3706 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3709 /* gfan without sfan means no fan control */
3710 /* all other models implement TP EC 0x2f control */
3714 fan_control_access_mode
=
3715 TPACPI_FAN_WR_ACPI_FANS
;
3716 fan_control_commands
|=
3717 TPACPI_FAN_CMD_SPEED
|
3718 TPACPI_FAN_CMD_LEVEL
|
3719 TPACPI_FAN_CMD_ENABLE
;
3721 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3722 fan_control_commands
|=
3723 TPACPI_FAN_CMD_LEVEL
|
3724 TPACPI_FAN_CMD_ENABLE
;
3729 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3730 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3731 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3732 fan_status_access_mode
, fan_control_access_mode
);
3734 /* fan control master switch */
3735 if (!fan_control_allowed
) {
3736 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3737 fan_control_commands
= 0;
3738 dbg_printk(TPACPI_DBG_INIT
,
3739 "fan control features disabled by parameter\n");
3742 /* update fan_control_desired_level */
3743 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3744 fan_get_status_safe(NULL
);
3746 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3747 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3748 rc
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3751 rc
= driver_create_file(&tpacpi_pdriver
.driver
,
3752 &driver_attr_fan_watchdog
);
3761 * Call with fan_mutex held
3763 static void fan_update_desired_level(u8 status
)
3766 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3768 fan_control_desired_level
= 7;
3770 fan_control_desired_level
= status
;
3774 static int fan_get_status(u8
*status
)
3779 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3781 switch (fan_status_access_mode
) {
3782 case TPACPI_FAN_RD_ACPI_GFAN
:
3783 /* 570, 600e/x, 770e, 770x */
3785 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
3793 case TPACPI_FAN_RD_TPEC
:
3794 /* all except 570, 600e/x, 770e, 770x */
3795 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
3810 static int fan_get_status_safe(u8
*status
)
3815 rc
= mutex_lock_interruptible(&fan_mutex
);
3818 rc
= fan_get_status(&s
);
3820 fan_update_desired_level(s
);
3821 mutex_unlock(&fan_mutex
);
3829 static void fan_exit(void)
3831 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
3833 /* FIXME: can we really do this unconditionally? */
3834 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
, &fan_attr_group
);
3835 driver_remove_file(&tpacpi_pdriver
.driver
, &driver_attr_fan_watchdog
);
3837 cancel_delayed_work(&fan_watchdog_task
);
3838 flush_scheduled_work();
3841 static int fan_get_speed(unsigned int *speed
)
3845 switch (fan_status_access_mode
) {
3846 case TPACPI_FAN_RD_TPEC
:
3847 /* all except 570, 600e/x, 770e, 770x */
3848 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
3849 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
3853 *speed
= (hi
<< 8) | lo
;
3864 static void fan_watchdog_fire(struct work_struct
*ignored
)
3868 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
3869 rc
= fan_set_enable();
3871 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
3872 "will try again later...\n", -rc
);
3873 /* reschedule for later */
3874 fan_watchdog_reset();
3878 static void fan_watchdog_reset(void)
3880 static int fan_watchdog_active
;
3882 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
3885 if (fan_watchdog_active
)
3886 cancel_delayed_work(&fan_watchdog_task
);
3888 if (fan_watchdog_maxinterval
> 0) {
3889 fan_watchdog_active
= 1;
3890 if (!schedule_delayed_work(&fan_watchdog_task
,
3891 msecs_to_jiffies(fan_watchdog_maxinterval
3893 printk(IBM_ERR
"failed to schedule the fan watchdog, "
3894 "watchdog will not trigger\n");
3897 fan_watchdog_active
= 0;
3900 static int fan_set_level(int level
)
3902 if (!fan_control_allowed
)
3905 switch (fan_control_access_mode
) {
3906 case TPACPI_FAN_WR_ACPI_SFAN
:
3907 if (level
>= 0 && level
<= 7) {
3908 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
3914 case TPACPI_FAN_WR_ACPI_FANS
:
3915 case TPACPI_FAN_WR_TPEC
:
3916 if ((level
!= TP_EC_FAN_AUTO
) &&
3917 (level
!= TP_EC_FAN_FULLSPEED
) &&
3918 ((level
< 0) || (level
> 7)))
3921 /* safety net should the EC not support AUTO
3922 * or FULLSPEED mode bits and just ignore them */
3923 if (level
& TP_EC_FAN_FULLSPEED
)
3924 level
|= 7; /* safety min speed 7 */
3925 else if (level
& TP_EC_FAN_FULLSPEED
)
3926 level
|= 4; /* safety min speed 4 */
3928 if (!acpi_ec_write(fan_status_offset
, level
))
3931 tp_features
.fan_ctrl_status_undef
= 0;
3940 static int fan_set_level_safe(int level
)
3944 if (!fan_control_allowed
)
3947 rc
= mutex_lock_interruptible(&fan_mutex
);
3951 if (level
== TPACPI_FAN_LAST_LEVEL
)
3952 level
= fan_control_desired_level
;
3954 rc
= fan_set_level(level
);
3956 fan_update_desired_level(level
);
3958 mutex_unlock(&fan_mutex
);
3962 static int fan_set_enable(void)
3967 if (!fan_control_allowed
)
3970 rc
= mutex_lock_interruptible(&fan_mutex
);
3974 switch (fan_control_access_mode
) {
3975 case TPACPI_FAN_WR_ACPI_FANS
:
3976 case TPACPI_FAN_WR_TPEC
:
3977 rc
= fan_get_status(&s
);
3981 /* Don't go out of emergency fan mode */
3984 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
3987 if (!acpi_ec_write(fan_status_offset
, s
))
3990 tp_features
.fan_ctrl_status_undef
= 0;
3995 case TPACPI_FAN_WR_ACPI_SFAN
:
3996 rc
= fan_get_status(&s
);
4002 /* Set fan to at least level 4 */
4005 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4015 mutex_unlock(&fan_mutex
);
4019 static int fan_set_disable(void)
4023 if (!fan_control_allowed
)
4026 rc
= mutex_lock_interruptible(&fan_mutex
);
4031 switch (fan_control_access_mode
) {
4032 case TPACPI_FAN_WR_ACPI_FANS
:
4033 case TPACPI_FAN_WR_TPEC
:
4034 if (!acpi_ec_write(fan_status_offset
, 0x00))
4037 fan_control_desired_level
= 0;
4038 tp_features
.fan_ctrl_status_undef
= 0;
4042 case TPACPI_FAN_WR_ACPI_SFAN
:
4043 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4046 fan_control_desired_level
= 0;
4054 mutex_unlock(&fan_mutex
);
4058 static int fan_set_speed(int speed
)
4062 if (!fan_control_allowed
)
4065 rc
= mutex_lock_interruptible(&fan_mutex
);
4070 switch (fan_control_access_mode
) {
4071 case TPACPI_FAN_WR_ACPI_FANS
:
4072 if (speed
>= 0 && speed
<= 65535) {
4073 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4074 speed
, speed
, speed
))
4084 mutex_unlock(&fan_mutex
);
4088 static int fan_read(char *p
)
4093 unsigned int speed
= 0;
4095 switch (fan_status_access_mode
) {
4096 case TPACPI_FAN_RD_ACPI_GFAN
:
4097 /* 570, 600e/x, 770e, 770x */
4098 if ((rc
= fan_get_status_safe(&status
)) < 0)
4101 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
4103 (status
!= 0) ? "enabled" : "disabled", status
);
4106 case TPACPI_FAN_RD_TPEC
:
4107 /* all except 570, 600e/x, 770e, 770x */
4108 if ((rc
= fan_get_status_safe(&status
)) < 0)
4111 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4112 if (status
!= fan_control_initial_status
)
4113 tp_features
.fan_ctrl_status_undef
= 0;
4115 /* Return most likely status. In fact, it
4116 * might be the only possible status */
4117 status
= TP_EC_FAN_AUTO
;
4120 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4121 (status
!= 0) ? "enabled" : "disabled");
4123 if ((rc
= fan_get_speed(&speed
)) < 0)
4126 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
4128 if (status
& TP_EC_FAN_FULLSPEED
)
4129 /* Disengaged mode takes precedence */
4130 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
4131 else if (status
& TP_EC_FAN_AUTO
)
4132 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
4134 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
4137 case TPACPI_FAN_NONE
:
4139 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4142 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
4143 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
4145 switch (fan_control_access_mode
) {
4146 case TPACPI_FAN_WR_ACPI_SFAN
:
4147 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4151 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4152 "auto, disengaged, full-speed)\n");
4157 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4158 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4159 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4160 "1-120 (seconds))\n");
4162 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4163 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4164 " (<speed> is 0-65535)\n");
4169 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4173 if (strlencmp(cmd
, "level auto") == 0)
4174 level
= TP_EC_FAN_AUTO
;
4175 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4176 (strlencmp(cmd
, "level full-speed") == 0))
4177 level
= TP_EC_FAN_FULLSPEED
;
4178 else if (sscanf(cmd
, "level %d", &level
) != 1)
4181 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4182 printk(IBM_ERR
"level command accepted for unsupported "
4183 "access mode %d", fan_control_access_mode
);
4188 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4190 if (strlencmp(cmd
, "enable") != 0)
4193 if ((*rc
= fan_set_enable()) == -ENXIO
)
4194 printk(IBM_ERR
"enable command accepted for unsupported "
4195 "access mode %d", fan_control_access_mode
);
4200 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4202 if (strlencmp(cmd
, "disable") != 0)
4205 if ((*rc
= fan_set_disable()) == -ENXIO
)
4206 printk(IBM_ERR
"disable command accepted for unsupported "
4207 "access mode %d", fan_control_access_mode
);
4212 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4217 * Support speed <low> <medium> <high> ? */
4219 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4222 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4223 printk(IBM_ERR
"speed command accepted for unsupported "
4224 "access mode %d", fan_control_access_mode
);
4229 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4233 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4236 if (interval
< 0 || interval
> 120)
4239 fan_watchdog_maxinterval
= interval
;
4244 static int fan_write(char *buf
)
4249 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4250 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4251 fan_write_cmd_level(cmd
, &rc
)) &&
4252 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4253 (fan_write_cmd_enable(cmd
, &rc
) ||
4254 fan_write_cmd_disable(cmd
, &rc
) ||
4255 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4256 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4257 fan_write_cmd_speed(cmd
, &rc
))
4261 fan_watchdog_reset();
4267 static struct ibm_struct fan_driver_data
= {
4274 /****************************************************************************
4275 ****************************************************************************
4279 ****************************************************************************
4280 ****************************************************************************/
4283 static struct proc_dir_entry
*proc_dir
;
4285 /* Subdriver registry */
4286 static LIST_HEAD(tpacpi_all_drivers
);
4290 * Module and infrastructure proble, init and exit handling
4293 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4294 static const char * __init
str_supported(int is_supported
)
4296 static char text_unsupported
[] __initdata
= "not supported";
4298 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4300 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4302 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4305 struct ibm_struct
*ibm
= iibm
->data
;
4306 struct proc_dir_entry
*entry
;
4308 BUG_ON(ibm
== NULL
);
4310 INIT_LIST_HEAD(&ibm
->all_drivers
);
4312 if (ibm
->flags
.experimental
&& !experimental
)
4315 dbg_printk(TPACPI_DBG_INIT
,
4316 "probing for %s\n", ibm
->name
);
4319 ret
= iibm
->init(iibm
);
4321 return 0; /* probe failed */
4325 ibm
->flags
.init_called
= 1;
4329 if (ibm
->acpi
->hid
) {
4330 ret
= register_tpacpi_subdriver(ibm
);
4335 if (ibm
->acpi
->notify
) {
4336 ret
= setup_acpi_notify(ibm
);
4337 if (ret
== -ENODEV
) {
4338 printk(IBM_NOTICE
"disabling subdriver %s\n",
4348 dbg_printk(TPACPI_DBG_INIT
,
4349 "%s installed\n", ibm
->name
);
4352 entry
= create_proc_entry(ibm
->name
,
4353 S_IFREG
| S_IRUGO
| S_IWUSR
,
4356 printk(IBM_ERR
"unable to create proc entry %s\n",
4361 entry
->owner
= THIS_MODULE
;
4363 entry
->read_proc
= &dispatch_procfs_read
;
4365 entry
->write_proc
= &dispatch_procfs_write
;
4366 ibm
->flags
.proc_created
= 1;
4369 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4374 dbg_printk(TPACPI_DBG_INIT
,
4375 "%s: at error exit path with result %d\n",
4379 return (ret
< 0)? ret
: 0;
4382 static void ibm_exit(struct ibm_struct
*ibm
)
4384 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4386 list_del_init(&ibm
->all_drivers
);
4388 if (ibm
->flags
.acpi_notify_installed
) {
4389 dbg_printk(TPACPI_DBG_EXIT
,
4390 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4392 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4394 dispatch_acpi_notify
);
4395 ibm
->flags
.acpi_notify_installed
= 0;
4396 ibm
->flags
.acpi_notify_installed
= 0;
4399 if (ibm
->flags
.proc_created
) {
4400 dbg_printk(TPACPI_DBG_EXIT
,
4401 "%s: remove_proc_entry\n", ibm
->name
);
4402 remove_proc_entry(ibm
->name
, proc_dir
);
4403 ibm
->flags
.proc_created
= 0;
4406 if (ibm
->flags
.acpi_driver_registered
) {
4407 dbg_printk(TPACPI_DBG_EXIT
,
4408 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4410 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4411 kfree(ibm
->acpi
->driver
);
4412 ibm
->acpi
->driver
= NULL
;
4413 ibm
->flags
.acpi_driver_registered
= 0;
4416 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4418 ibm
->flags
.init_called
= 0;
4421 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4426 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
4428 struct dmi_device
*dev
= NULL
;
4429 char ec_fw_string
[18];
4434 memset(tp
, 0, sizeof(*tp
));
4436 if (dmi_name_in_vendors("IBM"))
4437 tp
->vendor
= PCI_VENDOR_ID_IBM
;
4438 else if (dmi_name_in_vendors("LENOVO"))
4439 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
4443 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
4445 if (!tp
->bios_version_str
)
4447 tp
->bios_model
= tp
->bios_version_str
[0]
4448 | (tp
->bios_version_str
[1] << 8);
4451 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4452 * X32 or newer, all Z series; Some models must have an
4453 * up-to-date BIOS or they will not be detected.
4455 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4457 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4458 if (sscanf(dev
->name
,
4459 "IBM ThinkPad Embedded Controller -[%17c",
4460 ec_fw_string
) == 1) {
4461 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4462 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4464 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
4465 tp
->ec_model
= ec_fw_string
[0]
4466 | (ec_fw_string
[1] << 8);
4471 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
4473 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
4474 kfree(tp
->model_str
);
4475 tp
->model_str
= NULL
;
4479 static int __init
probe_for_thinkpad(void)
4487 * Non-ancient models have better DMI tagging, but very old models
4490 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
4492 /* ec is required because many other handles are relative to it */
4493 IBM_ACPIHANDLE_INIT(ec
);
4497 "Not yet supported ThinkPad detected!\n");
4502 * Risks a regression on very old machines, but reduces potential
4503 * false positives a damn great deal
4506 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
4508 if (!is_thinkpad
&& !force_load
)
4515 /* Module init, exit, parameters */
4517 static struct ibm_init_struct ibms_init
[] __initdata
= {
4519 .init
= thinkpad_acpi_driver_init
,
4520 .data
= &thinkpad_acpi_driver_data
,
4523 .init
= hotkey_init
,
4524 .data
= &hotkey_driver_data
,
4527 .init
= bluetooth_init
,
4528 .data
= &bluetooth_driver_data
,
4532 .data
= &wan_driver_data
,
4536 .data
= &video_driver_data
,
4540 .data
= &light_driver_data
,
4542 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4545 .data
= &dock_driver_data
[0],
4549 .data
= &dock_driver_data
[1],
4552 #ifdef CONFIG_THINKPAD_ACPI_BAY
4555 .data
= &bay_driver_data
,
4560 .data
= &cmos_driver_data
,
4564 .data
= &led_driver_data
,
4568 .data
= &beep_driver_data
,
4571 .init
= thermal_init
,
4572 .data
= &thermal_driver_data
,
4575 .data
= &ecdump_driver_data
,
4578 .init
= brightness_init
,
4579 .data
= &brightness_driver_data
,
4582 .data
= &volume_driver_data
,
4586 .data
= &fan_driver_data
,
4590 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4593 struct ibm_struct
*ibm
;
4595 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4596 ibm
= ibms_init
[i
].data
;
4597 BUG_ON(ibm
== NULL
);
4599 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4600 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4602 strcpy(ibms_init
[i
].param
, val
);
4603 strcat(ibms_init
[i
].param
, ",");
4611 static int experimental
;
4612 module_param(experimental
, int, 0);
4614 static u32 dbg_level
;
4615 module_param_named(debug
, dbg_level
, uint
, 0);
4617 static int force_load
;
4618 module_param(force_load
, bool, 0);
4620 static int fan_control_allowed
;
4621 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
4623 static int brightness_mode
;
4624 module_param_named(brightness_mode
, brightness_mode
, int, 0);
4626 #define IBM_PARAM(feature) \
4627 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4630 IBM_PARAM(bluetooth
);
4633 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4636 #ifdef CONFIG_THINKPAD_ACPI_BAY
4638 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4643 IBM_PARAM(brightness
);
4647 static int __init
thinkpad_acpi_module_init(void)
4651 /* Driver-level probe */
4653 get_thinkpad_model_data(&thinkpad_id
);
4654 ret
= probe_for_thinkpad();
4656 thinkpad_acpi_module_exit();
4660 /* Driver initialization */
4662 IBM_ACPIHANDLE_INIT(ecrd
);
4663 IBM_ACPIHANDLE_INIT(ecwr
);
4665 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4667 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4668 thinkpad_acpi_module_exit();
4671 proc_dir
->owner
= THIS_MODULE
;
4673 ret
= platform_driver_register(&tpacpi_pdriver
);
4675 printk(IBM_ERR
"unable to register platform driver\n");
4676 thinkpad_acpi_module_exit();
4679 tp_features
.platform_drv_registered
= 1;
4681 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4683 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4684 thinkpad_acpi_module_exit();
4687 tp_features
.platform_drv_attrs_registered
= 1;
4690 /* Device initialization */
4691 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4693 if (IS_ERR(tpacpi_pdev
)) {
4694 ret
= PTR_ERR(tpacpi_pdev
);
4696 printk(IBM_ERR
"unable to register platform device\n");
4697 thinkpad_acpi_module_exit();
4700 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
4701 if (IS_ERR(tpacpi_hwmon
)) {
4702 ret
= PTR_ERR(tpacpi_hwmon
);
4703 tpacpi_hwmon
= NULL
;
4704 printk(IBM_ERR
"unable to register hwmon device\n");
4705 thinkpad_acpi_module_exit();
4708 tpacpi_inputdev
= input_allocate_device();
4709 if (!tpacpi_inputdev
) {
4710 printk(IBM_ERR
"unable to allocate input device\n");
4711 thinkpad_acpi_module_exit();
4714 /* Prepare input device, but don't register */
4715 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
4716 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
4717 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
4718 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
4719 thinkpad_id
.vendor
:
4721 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
4722 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
4724 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4725 ret
= ibm_init(&ibms_init
[i
]);
4726 if (ret
>= 0 && *ibms_init
[i
].param
)
4727 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
4729 thinkpad_acpi_module_exit();
4733 ret
= input_register_device(tpacpi_inputdev
);
4735 printk(IBM_ERR
"unable to register input device\n");
4736 thinkpad_acpi_module_exit();
4739 tp_features
.input_device_registered
= 1;
4745 static void thinkpad_acpi_module_exit(void)
4747 struct ibm_struct
*ibm
, *itmp
;
4749 list_for_each_entry_safe_reverse(ibm
, itmp
,
4750 &tpacpi_all_drivers
,
4755 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
4757 if (tpacpi_inputdev
) {
4758 if (tp_features
.input_device_registered
)
4759 input_unregister_device(tpacpi_inputdev
);
4761 input_free_device(tpacpi_inputdev
);
4765 hwmon_device_unregister(tpacpi_hwmon
);
4768 platform_device_unregister(tpacpi_pdev
);
4770 if (tp_features
.platform_drv_attrs_registered
)
4771 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
4773 if (tp_features
.platform_drv_registered
)
4774 platform_driver_unregister(&tpacpi_pdriver
);
4777 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
4779 kfree(thinkpad_id
.bios_version_str
);
4780 kfree(thinkpad_id
.ec_version_str
);
4781 kfree(thinkpad_id
.model_str
);
4784 module_init(thinkpad_acpi_module_init
);
4785 module_exit(thinkpad_acpi_module_exit
);