2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define IBM_VERSION "0.16"
25 #define TPACPI_SYSFS_VERSION 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
;
414 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
416 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
418 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
420 kfree(ibm
->acpi
->driver
);
421 ibm
->acpi
->driver
= NULL
;
423 ibm
->flags
.acpi_driver_registered
= 1;
429 /****************************************************************************
430 ****************************************************************************
434 ****************************************************************************
435 ****************************************************************************/
437 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
438 int count
, int *eof
, void *data
)
440 struct ibm_struct
*ibm
= data
;
443 if (!ibm
|| !ibm
->read
)
446 len
= ibm
->read(page
);
450 if (len
<= off
+ count
)
462 static int dispatch_procfs_write(struct file
*file
,
463 const char __user
* userbuf
,
464 unsigned long count
, void *data
)
466 struct ibm_struct
*ibm
= data
;
470 if (!ibm
|| !ibm
->write
)
473 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
477 if (copy_from_user(kernbuf
, userbuf
, count
)) {
483 strcat(kernbuf
, ",");
484 ret
= ibm
->write(kernbuf
);
493 static char *next_cmd(char **cmds
)
498 while ((end
= strchr(start
, ',')) && end
== start
)
510 /****************************************************************************
511 ****************************************************************************
513 * Device model: input, hwmon and platform
515 ****************************************************************************
516 ****************************************************************************/
518 static struct platform_device
*tpacpi_pdev
;
519 static struct class_device
*tpacpi_hwmon
;
520 static struct input_dev
*tpacpi_inputdev
;
521 static struct mutex tpacpi_inputdev_send_mutex
;
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 /* sysfs hotkey report_mode -------------------------------------------- */
910 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
911 struct device_attribute
*attr
,
914 return snprintf(buf
, PAGE_SIZE
, "%d\n",
915 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
918 static ssize_t
hotkey_report_mode_store(struct device
*dev
,
919 struct device_attribute
*attr
,
920 const char *buf
, size_t count
)
925 if (parse_strtoul(buf
, 2, &t
) || (t
< 1))
928 if (t
!= hotkey_report_mode
) {
929 if (tp_features
.hotkey_report_mode_locked
)
931 hotkey_report_mode
= t
;
932 printk(IBM_NOTICE
"hot key report mode set to %d\n",
936 return (res
) ? res
: count
;
939 static struct device_attribute dev_attr_hotkey_report_mode
=
940 __ATTR(hotkey_report_mode
, S_IWUSR
| S_IRUGO
,
941 hotkey_report_mode_show
, hotkey_report_mode_store
);
943 /* --------------------------------------------------------------------- */
945 static struct attribute
*hotkey_attributes
[] __initdata
= {
946 &dev_attr_hotkey_enable
.attr
,
947 &dev_attr_hotkey_report_mode
.attr
,
950 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
951 &dev_attr_hotkey_mask
.attr
,
952 &dev_attr_hotkey_bios_enabled
.attr
,
953 &dev_attr_hotkey_bios_mask
.attr
,
954 &dev_attr_hotkey_all_mask
.attr
,
955 &dev_attr_hotkey_recommended_mask
.attr
,
958 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
961 static u16 ibm_keycode_map
[] __initdata
= {
962 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
963 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
964 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
965 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
966 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
967 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
968 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
969 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
970 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
971 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
972 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
973 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
974 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
975 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
976 KEY_RESERVED
, /* 0x14: VOLUME UP */
977 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
978 KEY_RESERVED
, /* 0x16: MUTE */
979 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
980 /* (assignments unknown, please report if found) */
981 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
982 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
984 static u16 lenovo_keycode_map
[] __initdata
= {
985 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
986 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
987 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
988 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
989 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
990 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
991 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
992 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
993 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
994 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
995 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
996 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
997 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
998 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
999 KEY_RESERVED
, /* 0x14: VOLUME UP */
1000 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1001 KEY_RESERVED
, /* 0x16: MUTE */
1002 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1003 /* (assignments unknown, please report if found) */
1004 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1005 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1008 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1009 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1010 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1015 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1017 BUG_ON(!tpacpi_inputdev
);
1019 IBM_ACPIHANDLE_INIT(hkey
);
1020 mutex_init(&hotkey_mutex
);
1022 /* hotkey not supported on 570 */
1023 tp_features
.hotkey
= hkey_handle
!= NULL
;
1025 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1026 str_supported(tp_features
.hotkey
));
1028 if (tp_features
.hotkey
) {
1029 hotkey_dev_attributes
= create_attr_set(8, NULL
);
1030 if (!hotkey_dev_attributes
)
1032 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1034 ARRAY_SIZE(hotkey_attributes
));
1038 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1039 A30, R30, R31, T20-22, X20-21, X22-24 */
1040 tp_features
.hotkey_mask
=
1041 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
1043 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1044 str_supported(tp_features
.hotkey_mask
));
1046 if (tp_features
.hotkey_mask
) {
1047 /* MHKA available in A31, R40, R40e, T4x, X31, and later */
1048 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1050 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
1053 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
1054 if (!res
&& tp_features
.hotkey_mask
) {
1055 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1056 hotkey_mask_attributes
,
1057 ARRAY_SIZE(hotkey_mask_attributes
));
1060 /* Not all thinkpads have a hardware radio switch */
1061 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1062 tp_features
.hotkey_wlsw
= 1;
1064 "radio switch found; radios are %s\n",
1065 enabled(status
, 0));
1066 res
= add_to_attr_set(hotkey_dev_attributes
,
1067 &dev_attr_hotkey_radio_sw
.attr
);
1071 res
= register_attr_set_with_sysfs(
1072 hotkey_dev_attributes
,
1073 &tpacpi_pdev
->dev
.kobj
);
1077 /* Set up key map */
1079 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1081 if (!hotkey_keycode_map
) {
1082 printk(IBM_ERR
"failed to allocate memory for key map\n");
1086 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1087 dbg_printk(TPACPI_DBG_INIT
,
1088 "using Lenovo default hot key map\n");
1089 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1090 TPACPI_HOTKEY_MAP_SIZE
);
1092 dbg_printk(TPACPI_DBG_INIT
,
1093 "using IBM default hot key map\n");
1094 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1095 TPACPI_HOTKEY_MAP_SIZE
);
1098 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1099 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1100 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1101 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1102 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1103 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1104 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1105 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1106 set_bit(hotkey_keycode_map
[i
],
1107 tpacpi_inputdev
->keybit
);
1109 if (i
< sizeof(hotkey_reserved_mask
)*8)
1110 hotkey_reserved_mask
|= 1 << i
;
1114 if (tp_features
.hotkey_wlsw
) {
1115 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1116 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1119 dbg_printk(TPACPI_DBG_INIT
,
1120 "enabling hot key handling\n");
1121 res
= hotkey_set(1, (hotkey_all_mask
& ~hotkey_reserved_mask
)
1122 | hotkey_orig_mask
);
1126 if (hotkey_report_mode
> 0) {
1127 tp_features
.hotkey_report_mode_locked
= 1;
1129 hotkey_report_mode
= 1;
1130 vdbg_printk(TPACPI_DBG_INIT
,
1131 "hot key reporting mode can be "
1132 "changed at runtime\n");
1135 dbg_printk(TPACPI_DBG_INIT
,
1136 "legacy hot key reporting over procfs %s\n",
1137 (hotkey_report_mode
< 2) ?
1138 "enabled" : "disabled");
1141 return (tp_features
.hotkey
)? 0 : 1;
1144 static void hotkey_exit(void)
1148 if (tp_features
.hotkey
) {
1149 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
1150 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
1152 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
1155 if (hotkey_dev_attributes
) {
1156 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1157 hotkey_dev_attributes
= NULL
;
1161 static void tpacpi_input_send_key(unsigned int scancode
,
1162 unsigned int keycode
)
1164 if (keycode
!= KEY_RESERVED
) {
1165 mutex_lock(&tpacpi_inputdev_send_mutex
);
1167 input_report_key(tpacpi_inputdev
, keycode
, 1);
1168 if (keycode
== KEY_UNKNOWN
)
1169 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1171 input_sync(tpacpi_inputdev
);
1173 input_report_key(tpacpi_inputdev
, keycode
, 0);
1174 if (keycode
== KEY_UNKNOWN
)
1175 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1177 input_sync(tpacpi_inputdev
);
1179 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1183 static void tpacpi_input_send_radiosw(void)
1187 mutex_lock(&tpacpi_inputdev_send_mutex
);
1189 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1190 input_report_switch(tpacpi_inputdev
,
1192 input_sync(tpacpi_inputdev
);
1195 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1198 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1201 unsigned int keycode
, scancode
;
1202 int send_acpi_ev
= 0;
1204 if (event
== 0x80 && acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1205 switch (hkey
>> 12) {
1207 /* 0x1000-0x1FFF: key presses */
1208 scancode
= hkey
& 0xfff;
1209 if (scancode
> 0 && scancode
< 0x21) {
1211 keycode
= hotkey_keycode_map
[scancode
];
1212 tpacpi_input_send_key(scancode
, keycode
);
1215 "hotkey 0x%04x out of range for keyboard map\n",
1221 /* 0x5000-0x5FFF: LID */
1222 /* we don't handle it through this path, just
1223 * eat up known LID events */
1224 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1226 "unknown LID-related hotkey event: 0x%04x\n",
1232 /* 0x7000-0x7FFF: misc */
1233 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1234 tpacpi_input_send_radiosw();
1237 /* fallthrough to default */
1239 /* case 2: dock-related */
1240 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1241 /* case 3: ultra-bay related. maybe bay in dock? */
1242 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1243 printk(IBM_NOTICE
"unhandled HKEY event 0x%04x\n", hkey
);
1247 printk(IBM_ERR
"unknown hotkey notification event %d\n", event
);
1252 if (send_acpi_ev
|| hotkey_report_mode
< 2) {
1253 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
1257 static void hotkey_resume(void)
1259 tpacpi_input_send_radiosw();
1263 * Call with hotkey_mutex held
1265 static int hotkey_get(int *status
, u32
*mask
)
1267 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1270 if (tp_features
.hotkey_mask
)
1271 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1278 * Call with hotkey_mutex held
1280 static int hotkey_set(int status
, u32 mask
)
1284 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1287 if (tp_features
.hotkey_mask
)
1288 for (i
= 0; i
< 32; i
++) {
1289 int bit
= ((1 << i
) & mask
) != 0;
1290 if (!acpi_evalf(hkey_handle
,
1291 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1298 /* procfs -------------------------------------------------------------- */
1299 static int hotkey_read(char *p
)
1305 if (!tp_features
.hotkey
) {
1306 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1310 res
= mutex_lock_interruptible(&hotkey_mutex
);
1313 res
= hotkey_get(&status
, &mask
);
1314 mutex_unlock(&hotkey_mutex
);
1318 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1319 if (tp_features
.hotkey_mask
) {
1320 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1321 len
+= sprintf(p
+ len
,
1322 "commands:\tenable, disable, reset, <mask>\n");
1324 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1325 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1331 static int hotkey_write(char *buf
)
1338 if (!tp_features
.hotkey
)
1341 res
= mutex_lock_interruptible(&hotkey_mutex
);
1345 res
= hotkey_get(&status
, &mask
);
1350 while ((cmd
= next_cmd(&buf
))) {
1351 if (strlencmp(cmd
, "enable") == 0) {
1353 } else if (strlencmp(cmd
, "disable") == 0) {
1355 } else if (strlencmp(cmd
, "reset") == 0) {
1356 status
= hotkey_orig_status
;
1357 mask
= hotkey_orig_mask
;
1358 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1360 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1370 res
= hotkey_set(status
, mask
);
1373 mutex_unlock(&hotkey_mutex
);
1377 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1378 .hid
= IBM_HKEY_HID
,
1379 .notify
= hotkey_notify
,
1380 .handle
= &hkey_handle
,
1381 .type
= ACPI_DEVICE_NOTIFY
,
1384 static struct ibm_struct hotkey_driver_data
= {
1386 .read
= hotkey_read
,
1387 .write
= hotkey_write
,
1388 .exit
= hotkey_exit
,
1389 .resume
= hotkey_resume
,
1390 .acpi
= &ibm_hotkey_acpidriver
,
1393 /*************************************************************************
1394 * Bluetooth subdriver
1397 /* sysfs bluetooth enable ---------------------------------------------- */
1398 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1399 struct device_attribute
*attr
,
1404 status
= bluetooth_get_radiosw();
1408 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1411 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1412 struct device_attribute
*attr
,
1413 const char *buf
, size_t count
)
1418 if (parse_strtoul(buf
, 1, &t
))
1421 res
= bluetooth_set_radiosw(t
);
1423 return (res
) ? res
: count
;
1426 static struct device_attribute dev_attr_bluetooth_enable
=
1427 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1428 bluetooth_enable_show
, bluetooth_enable_store
);
1430 /* --------------------------------------------------------------------- */
1432 static struct attribute
*bluetooth_attributes
[] = {
1433 &dev_attr_bluetooth_enable
.attr
,
1437 static const struct attribute_group bluetooth_attr_group
= {
1438 .attrs
= bluetooth_attributes
,
1441 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1446 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1448 IBM_ACPIHANDLE_INIT(hkey
);
1450 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1451 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1452 tp_features
.bluetooth
= hkey_handle
&&
1453 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1455 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1456 str_supported(tp_features
.bluetooth
),
1459 if (tp_features
.bluetooth
) {
1460 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1461 /* no bluetooth hardware present in system */
1462 tp_features
.bluetooth
= 0;
1463 dbg_printk(TPACPI_DBG_INIT
,
1464 "bluetooth hardware not installed\n");
1466 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1467 &bluetooth_attr_group
);
1473 return (tp_features
.bluetooth
)? 0 : 1;
1476 static void bluetooth_exit(void)
1478 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1479 &bluetooth_attr_group
);
1482 static int bluetooth_get_radiosw(void)
1486 if (!tp_features
.bluetooth
)
1489 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1492 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1495 static int bluetooth_set_radiosw(int radio_on
)
1499 if (!tp_features
.bluetooth
)
1502 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1505 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1507 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1508 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1514 /* procfs -------------------------------------------------------------- */
1515 static int bluetooth_read(char *p
)
1518 int status
= bluetooth_get_radiosw();
1520 if (!tp_features
.bluetooth
)
1521 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1523 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1524 (status
)? "enabled" : "disabled");
1525 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1531 static int bluetooth_write(char *buf
)
1535 if (!tp_features
.bluetooth
)
1538 while ((cmd
= next_cmd(&buf
))) {
1539 if (strlencmp(cmd
, "enable") == 0) {
1540 bluetooth_set_radiosw(1);
1541 } else if (strlencmp(cmd
, "disable") == 0) {
1542 bluetooth_set_radiosw(0);
1550 static struct ibm_struct bluetooth_driver_data
= {
1551 .name
= "bluetooth",
1552 .read
= bluetooth_read
,
1553 .write
= bluetooth_write
,
1554 .exit
= bluetooth_exit
,
1557 /*************************************************************************
1561 /* sysfs wan enable ---------------------------------------------------- */
1562 static ssize_t
wan_enable_show(struct device
*dev
,
1563 struct device_attribute
*attr
,
1568 status
= wan_get_radiosw();
1572 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1575 static ssize_t
wan_enable_store(struct device
*dev
,
1576 struct device_attribute
*attr
,
1577 const char *buf
, size_t count
)
1582 if (parse_strtoul(buf
, 1, &t
))
1585 res
= wan_set_radiosw(t
);
1587 return (res
) ? res
: count
;
1590 static struct device_attribute dev_attr_wan_enable
=
1591 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1592 wan_enable_show
, wan_enable_store
);
1594 /* --------------------------------------------------------------------- */
1596 static struct attribute
*wan_attributes
[] = {
1597 &dev_attr_wan_enable
.attr
,
1601 static const struct attribute_group wan_attr_group
= {
1602 .attrs
= wan_attributes
,
1605 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1610 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1612 IBM_ACPIHANDLE_INIT(hkey
);
1614 tp_features
.wan
= hkey_handle
&&
1615 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1617 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1618 str_supported(tp_features
.wan
),
1621 if (tp_features
.wan
) {
1622 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1623 /* no wan hardware present in system */
1624 tp_features
.wan
= 0;
1625 dbg_printk(TPACPI_DBG_INIT
,
1626 "wan hardware not installed\n");
1628 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1635 return (tp_features
.wan
)? 0 : 1;
1638 static void wan_exit(void)
1640 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1644 static int wan_get_radiosw(void)
1648 if (!tp_features
.wan
)
1651 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1654 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1657 static int wan_set_radiosw(int radio_on
)
1661 if (!tp_features
.wan
)
1664 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1667 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1669 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1670 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1676 /* procfs -------------------------------------------------------------- */
1677 static int wan_read(char *p
)
1680 int status
= wan_get_radiosw();
1682 if (!tp_features
.wan
)
1683 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1685 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1686 (status
)? "enabled" : "disabled");
1687 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1693 static int wan_write(char *buf
)
1697 if (!tp_features
.wan
)
1700 while ((cmd
= next_cmd(&buf
))) {
1701 if (strlencmp(cmd
, "enable") == 0) {
1703 } else if (strlencmp(cmd
, "disable") == 0) {
1712 static struct ibm_struct wan_driver_data
= {
1717 .flags
.experimental
= 1,
1720 /*************************************************************************
1724 static enum video_access_mode video_supported
;
1725 static int video_orig_autosw
;
1727 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1728 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1729 "\\_SB.PCI0.VID0", /* 770e */
1730 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1731 "\\_SB.PCI0.AGP.VID", /* all others */
1734 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1736 static int __init
video_init(struct ibm_init_struct
*iibm
)
1740 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1742 IBM_ACPIHANDLE_INIT(vid
);
1743 IBM_ACPIHANDLE_INIT(vid2
);
1745 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1746 /* G41, assume IVGA doesn't change */
1747 vid_handle
= vid2_handle
;
1750 /* video switching not supported on R30, R31 */
1751 video_supported
= TPACPI_VIDEO_NONE
;
1752 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1754 video_supported
= TPACPI_VIDEO_570
;
1755 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1756 /* 600e/x, 770e, 770x */
1757 video_supported
= TPACPI_VIDEO_770
;
1760 video_supported
= TPACPI_VIDEO_NEW
;
1762 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1763 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1766 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1769 static void video_exit(void)
1771 dbg_printk(TPACPI_DBG_EXIT
,
1772 "restoring original video autoswitch mode\n");
1773 if (video_autosw_set(video_orig_autosw
))
1774 printk(IBM_ERR
"error while trying to restore original "
1775 "video autoswitch mode\n");
1778 static int video_outputsw_get(void)
1783 switch (video_supported
) {
1784 case TPACPI_VIDEO_570
:
1785 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1786 TP_ACPI_VIDEO_570_PHSCMD
))
1788 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1790 case TPACPI_VIDEO_770
:
1791 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1794 status
|= TP_ACPI_VIDEO_S_LCD
;
1795 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1798 status
|= TP_ACPI_VIDEO_S_CRT
;
1800 case TPACPI_VIDEO_NEW
:
1801 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1802 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1805 status
|= TP_ACPI_VIDEO_S_CRT
;
1807 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1808 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1811 status
|= TP_ACPI_VIDEO_S_LCD
;
1812 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1815 status
|= TP_ACPI_VIDEO_S_DVI
;
1824 static int video_outputsw_set(int status
)
1829 switch (video_supported
) {
1830 case TPACPI_VIDEO_570
:
1831 res
= acpi_evalf(NULL
, NULL
,
1832 "\\_SB.PHS2", "vdd",
1833 TP_ACPI_VIDEO_570_PHS2CMD
,
1834 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1836 case TPACPI_VIDEO_770
:
1837 autosw
= video_autosw_get();
1841 res
= video_autosw_set(1);
1844 res
= acpi_evalf(vid_handle
, NULL
,
1845 "ASWT", "vdd", status
* 0x100, 0);
1846 if (!autosw
&& video_autosw_set(autosw
)) {
1847 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1851 case TPACPI_VIDEO_NEW
:
1852 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1853 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1859 return (res
)? 0 : -EIO
;
1862 static int video_autosw_get(void)
1866 switch (video_supported
) {
1867 case TPACPI_VIDEO_570
:
1868 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1871 case TPACPI_VIDEO_770
:
1872 case TPACPI_VIDEO_NEW
:
1873 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1883 static int video_autosw_set(int enable
)
1885 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1890 static int video_outputsw_cycle(void)
1892 int autosw
= video_autosw_get();
1898 switch (video_supported
) {
1899 case TPACPI_VIDEO_570
:
1900 res
= video_autosw_set(1);
1903 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1905 case TPACPI_VIDEO_770
:
1906 case TPACPI_VIDEO_NEW
:
1907 res
= video_autosw_set(1);
1910 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1915 if (!autosw
&& video_autosw_set(autosw
)) {
1916 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1920 return (res
)? 0 : -EIO
;
1923 static int video_expand_toggle(void)
1925 switch (video_supported
) {
1926 case TPACPI_VIDEO_570
:
1927 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1929 case TPACPI_VIDEO_770
:
1930 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1932 case TPACPI_VIDEO_NEW
:
1933 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1941 static int video_read(char *p
)
1946 if (video_supported
== TPACPI_VIDEO_NONE
) {
1947 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1951 status
= video_outputsw_get();
1955 autosw
= video_autosw_get();
1959 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1960 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
1961 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
1962 if (video_supported
== TPACPI_VIDEO_NEW
)
1963 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
1964 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
1965 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
1966 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
1967 if (video_supported
== TPACPI_VIDEO_NEW
)
1968 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
1969 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
1970 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
1975 static int video_write(char *buf
)
1978 int enable
, disable
, status
;
1981 if (video_supported
== TPACPI_VIDEO_NONE
)
1987 while ((cmd
= next_cmd(&buf
))) {
1988 if (strlencmp(cmd
, "lcd_enable") == 0) {
1989 enable
|= TP_ACPI_VIDEO_S_LCD
;
1990 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1991 disable
|= TP_ACPI_VIDEO_S_LCD
;
1992 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1993 enable
|= TP_ACPI_VIDEO_S_CRT
;
1994 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1995 disable
|= TP_ACPI_VIDEO_S_CRT
;
1996 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1997 strlencmp(cmd
, "dvi_enable") == 0) {
1998 enable
|= TP_ACPI_VIDEO_S_DVI
;
1999 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2000 strlencmp(cmd
, "dvi_disable") == 0) {
2001 disable
|= TP_ACPI_VIDEO_S_DVI
;
2002 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2003 res
= video_autosw_set(1);
2006 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2007 res
= video_autosw_set(0);
2010 } else if (strlencmp(cmd
, "video_switch") == 0) {
2011 res
= video_outputsw_cycle();
2014 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2015 res
= video_expand_toggle();
2022 if (enable
|| disable
) {
2023 status
= video_outputsw_get();
2026 res
= video_outputsw_set((status
& ~disable
) | enable
);
2034 static struct ibm_struct video_driver_data
= {
2037 .write
= video_write
,
2041 /*************************************************************************
2042 * Light (thinklight) subdriver
2045 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2046 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2048 static int __init
light_init(struct ibm_init_struct
*iibm
)
2050 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2052 IBM_ACPIHANDLE_INIT(ledb
);
2053 IBM_ACPIHANDLE_INIT(lght
);
2054 IBM_ACPIHANDLE_INIT(cmos
);
2056 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2057 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2059 if (tp_features
.light
)
2060 /* light status not supported on
2061 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2062 tp_features
.light_status
=
2063 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2065 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2066 str_supported(tp_features
.light
));
2068 return (tp_features
.light
)? 0 : 1;
2071 static int light_read(char *p
)
2076 if (!tp_features
.light
) {
2077 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2078 } else if (!tp_features
.light_status
) {
2079 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2080 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2082 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2084 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2085 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2091 static int light_write(char *buf
)
2093 int cmos_cmd
, lght_cmd
;
2097 if (!tp_features
.light
)
2100 while ((cmd
= next_cmd(&buf
))) {
2101 if (strlencmp(cmd
, "on") == 0) {
2104 } else if (strlencmp(cmd
, "off") == 0) {
2110 success
= cmos_handle
?
2111 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2112 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2120 static struct ibm_struct light_driver_data
= {
2123 .write
= light_write
,
2126 /*************************************************************************
2130 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2132 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2133 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2134 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2135 "\\_SB.PCI.ISA.SLCE", /* 570 */
2136 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2138 /* don't list other alternatives as we install a notify handler on the 570 */
2139 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2141 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2143 .notify
= dock_notify
,
2144 .handle
= &dock_handle
,
2145 .type
= ACPI_SYSTEM_NOTIFY
,
2148 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2149 * We just use it to get notifications of dock hotplug
2150 * in very old thinkpads */
2151 .hid
= PCI_ROOT_HID_STRING
,
2152 .notify
= dock_notify
,
2153 .handle
= &pci_handle
,
2154 .type
= ACPI_SYSTEM_NOTIFY
,
2158 static struct ibm_struct dock_driver_data
[2] = {
2162 .write
= dock_write
,
2163 .acpi
= &ibm_dock_acpidriver
[0],
2167 .acpi
= &ibm_dock_acpidriver
[1],
2171 #define dock_docked() (_sta(dock_handle) & 1)
2173 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2175 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2177 IBM_ACPIHANDLE_INIT(dock
);
2179 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2180 str_supported(dock_handle
!= NULL
));
2182 return (dock_handle
)? 0 : 1;
2185 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2189 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2191 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2192 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2193 IBM_ACPIHANDLE_INIT(pci
);
2194 dock2_needed
= (pci_handle
!= NULL
);
2195 vdbg_printk(TPACPI_DBG_INIT
,
2196 "dock PCI handler for the TP 570 is %s\n",
2197 str_supported(dock2_needed
));
2199 vdbg_printk(TPACPI_DBG_INIT
,
2200 "dock subdriver part 2 not required\n");
2204 return (dock2_needed
)? 0 : 1;
2207 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2209 int docked
= dock_docked();
2210 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, PCI_ROOT_HID_STRING
);
2212 if (event
== 1 && !pci
) /* 570 */
2213 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2214 else if (event
== 1 && pci
) /* 570 */
2215 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2216 else if (event
== 3 && docked
)
2217 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2218 else if (event
== 3 && !docked
)
2219 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
2220 else if (event
== 0 && docked
)
2221 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2223 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2224 event
, _sta(dock_handle
));
2225 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
2229 static int dock_read(char *p
)
2232 int docked
= dock_docked();
2235 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2237 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2239 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2240 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2246 static int dock_write(char *buf
)
2253 while ((cmd
= next_cmd(&buf
))) {
2254 if (strlencmp(cmd
, "undock") == 0) {
2255 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2256 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2258 } else if (strlencmp(cmd
, "dock") == 0) {
2259 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2268 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2270 /*************************************************************************
2274 #ifdef CONFIG_THINKPAD_ACPI_BAY
2275 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2276 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2277 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2278 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2279 ); /* A21e, R30, R31 */
2280 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2281 "_EJ0", /* all others */
2282 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2283 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2284 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2286 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2290 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2292 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2294 IBM_ACPIHANDLE_INIT(bay
);
2296 IBM_ACPIHANDLE_INIT(bay_ej
);
2297 IBM_ACPIHANDLE_INIT(bay2
);
2299 IBM_ACPIHANDLE_INIT(bay2_ej
);
2301 tp_features
.bay_status
= bay_handle
&&
2302 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2303 tp_features
.bay_status2
= bay2_handle
&&
2304 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2306 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2307 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2308 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2309 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2311 vdbg_printk(TPACPI_DBG_INIT
,
2312 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2313 str_supported(tp_features
.bay_status
),
2314 str_supported(tp_features
.bay_eject
),
2315 str_supported(tp_features
.bay_status2
),
2316 str_supported(tp_features
.bay_eject2
));
2318 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2319 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2322 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2324 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
2327 #define bay_occupied(b) (_sta(b##_handle) & 1)
2329 static int bay_read(char *p
)
2332 int occupied
= bay_occupied(bay
);
2333 int occupied2
= bay_occupied(bay2
);
2336 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2337 tp_features
.bay_status
?
2338 (occupied
? "occupied" : "unoccupied") :
2340 if (tp_features
.bay_status2
)
2341 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2342 "occupied" : "unoccupied");
2344 eject
= tp_features
.bay_eject
&& occupied
;
2345 eject2
= tp_features
.bay_eject2
&& occupied2
;
2347 if (eject
&& eject2
)
2348 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2350 len
+= sprintf(p
+ len
, "commands:\teject\n");
2352 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2357 static int bay_write(char *buf
)
2361 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2364 while ((cmd
= next_cmd(&buf
))) {
2365 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2366 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2368 } else if (tp_features
.bay_eject2
&&
2369 strlencmp(cmd
, "eject2") == 0) {
2370 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2379 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2380 .notify
= bay_notify
,
2381 .handle
= &bay_handle
,
2382 .type
= ACPI_SYSTEM_NOTIFY
,
2385 static struct ibm_struct bay_driver_data
= {
2389 .acpi
= &ibm_bay_acpidriver
,
2392 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2394 /*************************************************************************
2398 /* sysfs cmos_command -------------------------------------------------- */
2399 static ssize_t
cmos_command_store(struct device
*dev
,
2400 struct device_attribute
*attr
,
2401 const char *buf
, size_t count
)
2403 unsigned long cmos_cmd
;
2406 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2409 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2410 return (res
)? res
: count
;
2413 static struct device_attribute dev_attr_cmos_command
=
2414 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2416 /* --------------------------------------------------------------------- */
2418 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2422 vdbg_printk(TPACPI_DBG_INIT
,
2423 "initializing cmos commands subdriver\n");
2425 IBM_ACPIHANDLE_INIT(cmos
);
2427 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2428 str_supported(cmos_handle
!= NULL
));
2430 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2434 return (cmos_handle
)? 0 : 1;
2437 static void cmos_exit(void)
2439 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2442 static int cmos_read(char *p
)
2446 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2447 R30, R31, T20-22, X20-21 */
2449 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2451 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2452 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2458 static int cmos_write(char *buf
)
2463 while ((cmd
= next_cmd(&buf
))) {
2464 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2465 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2470 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2478 static struct ibm_struct cmos_driver_data
= {
2481 .write
= cmos_write
,
2485 /*************************************************************************
2489 static enum led_access_mode led_supported
;
2491 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2492 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2493 "LED", /* all others */
2496 static int __init
led_init(struct ibm_init_struct
*iibm
)
2498 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2500 IBM_ACPIHANDLE_INIT(led
);
2503 /* led not supported on R30, R31 */
2504 led_supported
= TPACPI_LED_NONE
;
2505 else if (strlencmp(led_path
, "SLED") == 0)
2507 led_supported
= TPACPI_LED_570
;
2508 else if (strlencmp(led_path
, "SYSL") == 0)
2509 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2510 led_supported
= TPACPI_LED_OLD
;
2513 led_supported
= TPACPI_LED_NEW
;
2515 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2516 str_supported(led_supported
), led_supported
);
2518 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2521 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2523 static int led_read(char *p
)
2527 if (!led_supported
) {
2528 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2531 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2533 if (led_supported
== TPACPI_LED_570
) {
2536 for (i
= 0; i
< 8; i
++) {
2537 if (!acpi_evalf(ec_handle
,
2538 &status
, "GLED", "dd", 1 << i
))
2540 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2541 i
, led_status(status
));
2545 len
+= sprintf(p
+ len
, "commands:\t"
2546 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2551 /* off, on, blink */
2552 static const int led_sled_arg1
[] = { 0, 1, 3 };
2553 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2554 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2555 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2557 static int led_write(char *buf
)
2565 while ((cmd
= next_cmd(&buf
))) {
2566 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2569 if (strstr(cmd
, "off")) {
2571 } else if (strstr(cmd
, "on")) {
2573 } else if (strstr(cmd
, "blink")) {
2578 if (led_supported
== TPACPI_LED_570
) {
2581 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2582 led
, led_sled_arg1
[ind
]))
2584 } else if (led_supported
== TPACPI_LED_OLD
) {
2585 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2587 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2590 ec_write(TPACPI_LED_EC_HLBL
,
2591 led
* led_exp_hlbl
[ind
]);
2594 ec_write(TPACPI_LED_EC_HLCL
,
2595 led
* led_exp_hlcl
[ind
]);
2600 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2601 led
, led_led_arg1
[ind
]))
2609 static struct ibm_struct led_driver_data
= {
2615 /*************************************************************************
2619 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2621 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2623 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2625 IBM_ACPIHANDLE_INIT(beep
);
2627 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2628 str_supported(beep_handle
!= NULL
));
2630 return (beep_handle
)? 0 : 1;
2633 static int beep_read(char *p
)
2638 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2640 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2641 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2647 static int beep_write(char *buf
)
2655 while ((cmd
= next_cmd(&buf
))) {
2656 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2657 beep_cmd
>= 0 && beep_cmd
<= 17) {
2661 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2668 static struct ibm_struct beep_driver_data
= {
2671 .write
= beep_write
,
2674 /*************************************************************************
2678 static enum thermal_access_mode thermal_read_mode
;
2680 /* sysfs temp##_input -------------------------------------------------- */
2682 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2683 struct device_attribute
*attr
,
2686 struct sensor_device_attribute
*sensor_attr
=
2687 to_sensor_dev_attr(attr
);
2688 int idx
= sensor_attr
->index
;
2692 res
= thermal_get_sensor(idx
, &value
);
2695 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2698 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2701 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2702 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2704 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2705 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2706 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2707 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2708 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2709 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2710 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2711 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2712 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2713 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2714 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2715 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2716 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2717 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2718 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2719 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2720 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2723 #define THERMAL_ATTRS(X) \
2724 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2726 static struct attribute
*thermal_temp_input_attr
[] = {
2746 static const struct attribute_group thermal_temp_input16_group
= {
2747 .attrs
= thermal_temp_input_attr
2750 static const struct attribute_group thermal_temp_input8_group
= {
2751 .attrs
= &thermal_temp_input_attr
[8]
2754 #undef THERMAL_SENSOR_ATTR_TEMP
2755 #undef THERMAL_ATTRS
2757 /* --------------------------------------------------------------------- */
2759 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2766 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2768 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2770 if (thinkpad_id
.ec_model
) {
2772 * Direct EC access mode: sensors at registers
2773 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2774 * non-implemented, thermal sensors return 0x80 when
2779 for (i
= 0; i
< 8; i
++) {
2780 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2786 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2794 /* This is sheer paranoia, but we handle it anyway */
2797 "ThinkPad ACPI EC access misbehaving, "
2798 "falling back to ACPI TMPx access mode\n");
2799 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2802 "ThinkPad ACPI EC access misbehaving, "
2803 "disabling thermal sensors access\n");
2804 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2809 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2811 } else if (acpi_tmp7
) {
2812 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2813 /* 600e/x, 770e, 770x */
2814 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2816 /* Standard ACPI TMPx access, max 8 sensors */
2817 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2820 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2821 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2824 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2825 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2828 switch(thermal_read_mode
) {
2829 case TPACPI_THERMAL_TPEC_16
:
2830 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2831 &thermal_temp_input16_group
);
2835 case TPACPI_THERMAL_TPEC_8
:
2836 case TPACPI_THERMAL_ACPI_TMP07
:
2837 case TPACPI_THERMAL_ACPI_UPDT
:
2838 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2839 &thermal_temp_input8_group
);
2843 case TPACPI_THERMAL_NONE
:
2851 static void thermal_exit(void)
2853 switch(thermal_read_mode
) {
2854 case TPACPI_THERMAL_TPEC_16
:
2855 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2856 &thermal_temp_input16_group
);
2858 case TPACPI_THERMAL_TPEC_8
:
2859 case TPACPI_THERMAL_ACPI_TMP07
:
2860 case TPACPI_THERMAL_ACPI_UPDT
:
2861 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2862 &thermal_temp_input16_group
);
2864 case TPACPI_THERMAL_NONE
:
2870 /* idx is zero-based */
2871 static int thermal_get_sensor(int idx
, s32
*value
)
2877 t
= TP_EC_THERMAL_TMP0
;
2879 switch (thermal_read_mode
) {
2880 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2881 case TPACPI_THERMAL_TPEC_16
:
2882 if (idx
>= 8 && idx
<= 15) {
2883 t
= TP_EC_THERMAL_TMP8
;
2888 case TPACPI_THERMAL_TPEC_8
:
2890 if (!acpi_ec_read(t
+ idx
, &tmp
))
2892 *value
= tmp
* 1000;
2897 case TPACPI_THERMAL_ACPI_UPDT
:
2899 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2900 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2902 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2904 *value
= (t
- 2732) * 100;
2909 case TPACPI_THERMAL_ACPI_TMP07
:
2911 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2912 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2914 if (t
> 127 || t
< -127)
2915 t
= TP_EC_THERMAL_TMP_NA
;
2921 case TPACPI_THERMAL_NONE
:
2929 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2940 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2943 for(i
= 0 ; i
< n
; i
++) {
2944 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
2952 static int thermal_read(char *p
)
2956 struct ibm_thermal_sensors_struct t
;
2958 n
= thermal_get_sensors(&t
);
2959 if (unlikely(n
< 0))
2962 len
+= sprintf(p
+ len
, "temperatures:\t");
2965 for (i
= 0; i
< (n
- 1); i
++)
2966 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
2967 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
2969 len
+= sprintf(p
+ len
, "not supported\n");
2974 static struct ibm_struct thermal_driver_data
= {
2976 .read
= thermal_read
,
2977 .exit
= thermal_exit
,
2980 /*************************************************************************
2984 static u8 ecdump_regs
[256];
2986 static int ecdump_read(char *p
)
2992 len
+= sprintf(p
+ len
, "EC "
2993 " +00 +01 +02 +03 +04 +05 +06 +07"
2994 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2995 for (i
= 0; i
< 256; i
+= 16) {
2996 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
2997 for (j
= 0; j
< 16; j
++) {
2998 if (!acpi_ec_read(i
+ j
, &v
))
3000 if (v
!= ecdump_regs
[i
+ j
])
3001 len
+= sprintf(p
+ len
, " *%02x", v
);
3003 len
+= sprintf(p
+ len
, " %02x", v
);
3004 ecdump_regs
[i
+ j
] = v
;
3006 len
+= sprintf(p
+ len
, "\n");
3011 /* These are way too dangerous to advertise openly... */
3013 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3014 " (<offset> is 00-ff, <value> is 00-ff)\n");
3015 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3016 " (<offset> is 00-ff, <value> is 0-255)\n");
3021 static int ecdump_write(char *buf
)
3026 while ((cmd
= next_cmd(&buf
))) {
3027 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3029 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3033 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3034 if (!acpi_ec_write(i
, v
))
3043 static struct ibm_struct ecdump_driver_data
= {
3045 .read
= ecdump_read
,
3046 .write
= ecdump_write
,
3047 .flags
.experimental
= 1,
3050 /*************************************************************************
3051 * Backlight/brightness subdriver
3054 static struct backlight_device
*ibm_backlight_device
;
3056 static struct backlight_properties ibm_backlight_data
= {
3057 .owner
= THIS_MODULE
,
3058 .get_brightness
= brightness_get
,
3059 .update_status
= brightness_update_status
,
3060 .max_brightness
= 7,
3063 static struct mutex brightness_mutex
;
3065 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
3069 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
3071 mutex_init(&brightness_mutex
);
3073 if (!brightness_mode
) {
3074 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
3075 brightness_mode
= 2;
3077 brightness_mode
= 3;
3079 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
3083 if (brightness_mode
> 3)
3086 b
= brightness_get(NULL
);
3090 ibm_backlight_device
= backlight_device_register(
3091 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
3092 &ibm_backlight_data
);
3093 if (IS_ERR(ibm_backlight_device
)) {
3094 printk(IBM_ERR
"Could not register backlight device\n");
3095 return PTR_ERR(ibm_backlight_device
);
3097 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
3099 ibm_backlight_device
->props
->brightness
= b
;
3100 brightness_update_status(ibm_backlight_device
);
3105 static void brightness_exit(void)
3107 if (ibm_backlight_device
) {
3108 vdbg_printk(TPACPI_DBG_EXIT
,
3109 "calling backlight_device_unregister()\n");
3110 backlight_device_unregister(ibm_backlight_device
);
3111 ibm_backlight_device
= NULL
;
3115 static int brightness_update_status(struct backlight_device
*bd
)
3117 return brightness_set(
3118 (bd
->props
->fb_blank
== FB_BLANK_UNBLANK
&&
3119 bd
->props
->power
== FB_BLANK_UNBLANK
) ?
3120 bd
->props
->brightness
: 0);
3124 * ThinkPads can read brightness from two places: EC 0x31, or
3125 * CMOS NVRAM byte 0x5E, bits 0-3.
3127 static int brightness_get(struct backlight_device
*bd
)
3129 u8 lec
= 0, lcmos
= 0, level
= 0;
3131 if (brightness_mode
& 1) {
3132 if (!acpi_ec_read(brightness_offset
, &lec
))
3137 if (brightness_mode
& 2) {
3138 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3139 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3140 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3144 if (brightness_mode
== 3 && lec
!= lcmos
) {
3146 "CMOS NVRAM (%u) and EC (%u) do not agree "
3147 "on display brightness level\n",
3148 (unsigned int) lcmos
,
3149 (unsigned int) lec
);
3156 static int brightness_set(int value
)
3158 int cmos_cmd
, inc
, i
, res
;
3164 res
= mutex_lock_interruptible(&brightness_mutex
);
3168 current_value
= brightness_get(NULL
);
3169 if (current_value
< 0) {
3170 res
= current_value
;
3174 cmos_cmd
= value
> current_value
?
3175 TP_CMOS_BRIGHTNESS_UP
:
3176 TP_CMOS_BRIGHTNESS_DOWN
;
3177 inc
= value
> current_value
? 1 : -1;
3180 for (i
= current_value
; i
!= value
; i
+= inc
) {
3181 if ((brightness_mode
& 2) &&
3182 issue_thinkpad_cmos_command(cmos_cmd
)) {
3186 if ((brightness_mode
& 1) &&
3187 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
3194 mutex_unlock(&brightness_mutex
);
3198 static int brightness_read(char *p
)
3203 if ((level
= brightness_get(NULL
)) < 0) {
3204 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3206 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
3207 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3208 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3209 " (<level> is 0-7)\n");
3215 static int brightness_write(char *buf
)
3221 while ((cmd
= next_cmd(&buf
))) {
3222 if ((level
= brightness_get(NULL
)) < 0)
3226 if (strlencmp(cmd
, "up") == 0) {
3227 new_level
= level
== 7 ? 7 : level
+ 1;
3228 } else if (strlencmp(cmd
, "down") == 0) {
3229 new_level
= level
== 0 ? 0 : level
- 1;
3230 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3231 new_level
>= 0 && new_level
<= 7) {
3236 brightness_set(new_level
);
3242 static struct ibm_struct brightness_driver_data
= {
3243 .name
= "brightness",
3244 .read
= brightness_read
,
3245 .write
= brightness_write
,
3246 .exit
= brightness_exit
,
3249 /*************************************************************************
3253 static int volume_read(char *p
)
3258 if (!acpi_ec_read(volume_offset
, &level
)) {
3259 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3261 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3262 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3263 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3264 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3265 " (<level> is 0-15)\n");
3271 static int volume_write(char *buf
)
3273 int cmos_cmd
, inc
, i
;
3275 int new_level
, new_mute
;
3278 while ((cmd
= next_cmd(&buf
))) {
3279 if (!acpi_ec_read(volume_offset
, &level
))
3281 new_mute
= mute
= level
& 0x40;
3282 new_level
= level
= level
& 0xf;
3284 if (strlencmp(cmd
, "up") == 0) {
3288 new_level
= level
== 15 ? 15 : level
+ 1;
3289 } else if (strlencmp(cmd
, "down") == 0) {
3293 new_level
= level
== 0 ? 0 : level
- 1;
3294 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3295 new_level
>= 0 && new_level
<= 15) {
3297 } else if (strlencmp(cmd
, "mute") == 0) {
3302 if (new_level
!= level
) { /* mute doesn't change */
3303 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3304 inc
= new_level
> level
? 1 : -1;
3306 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3307 !acpi_ec_write(volume_offset
, level
)))
3310 for (i
= level
; i
!= new_level
; i
+= inc
)
3311 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3312 !acpi_ec_write(volume_offset
, i
+ inc
))
3315 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3316 !acpi_ec_write(volume_offset
,
3321 if (new_mute
!= mute
) { /* level doesn't change */
3322 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3324 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3325 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3333 static struct ibm_struct volume_driver_data
= {
3335 .read
= volume_read
,
3336 .write
= volume_write
,
3339 /*************************************************************************
3346 * TPACPI_FAN_RD_ACPI_GFAN:
3347 * ACPI GFAN method: returns fan level
3349 * see TPACPI_FAN_WR_ACPI_SFAN
3350 * EC 0x2f (HFSP) not available if GFAN exists
3352 * TPACPI_FAN_WR_ACPI_SFAN:
3353 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3355 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3358 * TPACPI_FAN_WR_TPEC:
3359 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3360 * Supported on almost all ThinkPads
3362 * Fan speed changes of any sort (including those caused by the
3363 * disengaged mode) are usually done slowly by the firmware as the
3364 * maximum ammount of fan duty cycle change per second seems to be
3367 * Reading is not available if GFAN exists.
3368 * Writing is not available if SFAN exists.
3371 * 7 automatic mode engaged;
3372 * (default operation mode of the ThinkPad)
3373 * fan level is ignored in this mode.
3374 * 6 full speed mode (takes precedence over bit 7);
3375 * not available on all thinkpads. May disable
3376 * the tachometer while the fan controller ramps up
3377 * the speed (which can take up to a few *minutes*).
3378 * Speeds up fan to 100% duty-cycle, which is far above
3379 * the standard RPM levels. It is not impossible that
3380 * it could cause hardware damage.
3381 * 5-3 unused in some models. Extra bits for fan level
3382 * in others, but still useless as all values above
3383 * 7 map to the same speed as level 7 in these models.
3384 * 2-0 fan level (0..7 usually)
3386 * 0x07 = max (set when temperatures critical)
3387 * Some ThinkPads may have other levels, see
3388 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3390 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3391 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3392 * does so, its initial value is meaningless (0x07).
3394 * For firmware bugs, refer to:
3395 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3399 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3400 * Main fan tachometer reading (in RPM)
3402 * This register is present on all ThinkPads with a new-style EC, and
3403 * it is known not to be present on the A21m/e, and T22, as there is
3404 * something else in offset 0x84 according to the ACPI DSDT. Other
3405 * ThinkPads from this same time period (and earlier) probably lack the
3406 * tachometer as well.
3408 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3409 * was never fixed by IBM to report the EC firmware version string
3410 * probably support the tachometer (like the early X models), so
3411 * detecting it is quite hard. We need more data to know for sure.
3413 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3416 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3419 * For firmware bugs, refer to:
3420 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3422 * TPACPI_FAN_WR_ACPI_FANS:
3423 * ThinkPad X31, X40, X41. Not available in the X60.
3425 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3426 * high speed. ACPI DSDT seems to map these three speeds to levels
3427 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3428 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3430 * The speeds are stored on handles
3431 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3433 * There are three default speed sets, acessible as handles:
3434 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3436 * ACPI DSDT switches which set is in use depending on various
3439 * TPACPI_FAN_WR_TPEC is also available and should be used to
3440 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3441 * but the ACPI tables just mention level 7.
3444 static enum fan_status_access_mode fan_status_access_mode
;
3445 static enum fan_control_access_mode fan_control_access_mode
;
3446 static enum fan_control_commands fan_control_commands
;
3448 static u8 fan_control_initial_status
;
3449 static u8 fan_control_desired_level
;
3451 static void fan_watchdog_fire(struct work_struct
*ignored
);
3452 static int fan_watchdog_maxinterval
;
3453 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3455 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3456 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3457 "\\FSPD", /* 600e/x, 770e, 770x */
3459 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3460 "JFNS", /* 770x-JL */
3464 * SYSFS fan layout: hwmon compatible (device)
3467 * 0: "disengaged" mode
3469 * 2: native EC "auto" mode (recommended, hardware default)
3471 * pwm*: set speed in manual mode, ignored otherwise.
3472 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3475 * fan*_input: tachometer reading, RPM
3478 * SYSFS fan layout: extensions
3480 * fan_watchdog (driver):
3481 * fan watchdog interval in seconds, 0 disables (default), max 120
3484 /* sysfs fan pwm1_enable ----------------------------------------------- */
3485 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3486 struct device_attribute
*attr
,
3492 res
= fan_get_status_safe(&status
);
3496 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3497 if (status
!= fan_control_initial_status
) {
3498 tp_features
.fan_ctrl_status_undef
= 0;
3500 /* Return most likely status. In fact, it
3501 * might be the only possible status */
3502 status
= TP_EC_FAN_AUTO
;
3506 if (status
& TP_EC_FAN_FULLSPEED
) {
3508 } else if (status
& TP_EC_FAN_AUTO
) {
3513 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3516 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3517 struct device_attribute
*attr
,
3518 const char *buf
, size_t count
)
3523 if (parse_strtoul(buf
, 2, &t
))
3528 level
= TP_EC_FAN_FULLSPEED
;
3531 level
= TPACPI_FAN_LAST_LEVEL
;
3534 level
= TP_EC_FAN_AUTO
;
3537 /* reserved for software-controlled auto mode */
3543 res
= fan_set_level_safe(level
);
3549 fan_watchdog_reset();
3554 static struct device_attribute dev_attr_fan_pwm1_enable
=
3555 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3556 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3558 /* sysfs fan pwm1 ------------------------------------------------------ */
3559 static ssize_t
fan_pwm1_show(struct device
*dev
,
3560 struct device_attribute
*attr
,
3566 res
= fan_get_status_safe(&status
);
3570 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3571 if (status
!= fan_control_initial_status
) {
3572 tp_features
.fan_ctrl_status_undef
= 0;
3574 status
= TP_EC_FAN_AUTO
;
3579 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3580 status
= fan_control_desired_level
;
3585 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3588 static ssize_t
fan_pwm1_store(struct device
*dev
,
3589 struct device_attribute
*attr
,
3590 const char *buf
, size_t count
)
3594 u8 status
, newlevel
;
3596 if (parse_strtoul(buf
, 255, &s
))
3599 /* scale down from 0-255 to 0-7 */
3600 newlevel
= (s
>> 5) & 0x07;
3602 rc
= mutex_lock_interruptible(&fan_mutex
);
3606 rc
= fan_get_status(&status
);
3607 if (!rc
&& (status
&
3608 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3609 rc
= fan_set_level(newlevel
);
3613 fan_update_desired_level(newlevel
);
3614 fan_watchdog_reset();
3618 mutex_unlock(&fan_mutex
);
3619 return (rc
)? rc
: count
;
3622 static struct device_attribute dev_attr_fan_pwm1
=
3623 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3624 fan_pwm1_show
, fan_pwm1_store
);
3626 /* sysfs fan fan1_input ------------------------------------------------ */
3627 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3628 struct device_attribute
*attr
,
3634 res
= fan_get_speed(&speed
);
3638 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3641 static struct device_attribute dev_attr_fan_fan1_input
=
3642 __ATTR(fan1_input
, S_IRUGO
,
3643 fan_fan1_input_show
, NULL
);
3645 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
3646 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3649 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3652 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3653 const char *buf
, size_t count
)
3657 if (parse_strtoul(buf
, 120, &t
))
3660 if (!fan_control_allowed
)
3663 fan_watchdog_maxinterval
= t
;
3664 fan_watchdog_reset();
3669 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3670 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3672 /* --------------------------------------------------------------------- */
3673 static struct attribute
*fan_attributes
[] = {
3674 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3675 &dev_attr_fan_fan1_input
.attr
,
3679 static const struct attribute_group fan_attr_group
= {
3680 .attrs
= fan_attributes
,
3683 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3687 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3689 mutex_init(&fan_mutex
);
3690 fan_status_access_mode
= TPACPI_FAN_NONE
;
3691 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3692 fan_control_commands
= 0;
3693 fan_watchdog_maxinterval
= 0;
3694 tp_features
.fan_ctrl_status_undef
= 0;
3695 fan_control_desired_level
= 7;
3697 IBM_ACPIHANDLE_INIT(fans
);
3698 IBM_ACPIHANDLE_INIT(gfan
);
3699 IBM_ACPIHANDLE_INIT(sfan
);
3702 /* 570, 600e/x, 770e, 770x */
3703 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3705 /* all other ThinkPads: note that even old-style
3706 * ThinkPad ECs supports the fan control register */
3707 if (likely(acpi_ec_read(fan_status_offset
,
3708 &fan_control_initial_status
))) {
3709 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3711 /* In some ThinkPads, neither the EC nor the ACPI
3712 * DSDT initialize the fan status, and it ends up
3713 * being set to 0x07 when it *could* be either
3716 * Enable for TP-1Y (T43), TP-78 (R51e),
3717 * TP-76 (R52), TP-70 (T43, R52), which are known
3719 if (fan_control_initial_status
== 0x07) {
3720 switch (thinkpad_id
.ec_model
) {
3721 case 0x5931: /* TP-1Y */
3722 case 0x3837: /* TP-78 */
3723 case 0x3637: /* TP-76 */
3724 case 0x3037: /* TP-70 */
3726 "fan_init: initial fan status is "
3727 "unknown, assuming it is in auto "
3729 tp_features
.fan_ctrl_status_undef
= 1;
3735 "ThinkPad ACPI EC access misbehaving, "
3736 "fan status and control unavailable\n");
3743 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3744 fan_control_commands
|=
3745 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3748 /* gfan without sfan means no fan control */
3749 /* all other models implement TP EC 0x2f control */
3753 fan_control_access_mode
=
3754 TPACPI_FAN_WR_ACPI_FANS
;
3755 fan_control_commands
|=
3756 TPACPI_FAN_CMD_SPEED
|
3757 TPACPI_FAN_CMD_LEVEL
|
3758 TPACPI_FAN_CMD_ENABLE
;
3760 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3761 fan_control_commands
|=
3762 TPACPI_FAN_CMD_LEVEL
|
3763 TPACPI_FAN_CMD_ENABLE
;
3768 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3769 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3770 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3771 fan_status_access_mode
, fan_control_access_mode
);
3773 /* fan control master switch */
3774 if (!fan_control_allowed
) {
3775 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3776 fan_control_commands
= 0;
3777 dbg_printk(TPACPI_DBG_INIT
,
3778 "fan control features disabled by parameter\n");
3781 /* update fan_control_desired_level */
3782 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3783 fan_get_status_safe(NULL
);
3785 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3786 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3787 rc
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3790 rc
= driver_create_file(&tpacpi_pdriver
.driver
,
3791 &driver_attr_fan_watchdog
);
3800 * Call with fan_mutex held
3802 static void fan_update_desired_level(u8 status
)
3805 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3807 fan_control_desired_level
= 7;
3809 fan_control_desired_level
= status
;
3813 static int fan_get_status(u8
*status
)
3818 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3820 switch (fan_status_access_mode
) {
3821 case TPACPI_FAN_RD_ACPI_GFAN
:
3822 /* 570, 600e/x, 770e, 770x */
3824 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
3832 case TPACPI_FAN_RD_TPEC
:
3833 /* all except 570, 600e/x, 770e, 770x */
3834 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
3849 static int fan_get_status_safe(u8
*status
)
3854 rc
= mutex_lock_interruptible(&fan_mutex
);
3857 rc
= fan_get_status(&s
);
3859 fan_update_desired_level(s
);
3860 mutex_unlock(&fan_mutex
);
3868 static void fan_exit(void)
3870 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
3872 /* FIXME: can we really do this unconditionally? */
3873 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
, &fan_attr_group
);
3874 driver_remove_file(&tpacpi_pdriver
.driver
, &driver_attr_fan_watchdog
);
3876 cancel_delayed_work(&fan_watchdog_task
);
3877 flush_scheduled_work();
3880 static int fan_get_speed(unsigned int *speed
)
3884 switch (fan_status_access_mode
) {
3885 case TPACPI_FAN_RD_TPEC
:
3886 /* all except 570, 600e/x, 770e, 770x */
3887 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
3888 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
3892 *speed
= (hi
<< 8) | lo
;
3903 static void fan_watchdog_fire(struct work_struct
*ignored
)
3907 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
3908 rc
= fan_set_enable();
3910 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
3911 "will try again later...\n", -rc
);
3912 /* reschedule for later */
3913 fan_watchdog_reset();
3917 static void fan_watchdog_reset(void)
3919 static int fan_watchdog_active
;
3921 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
3924 if (fan_watchdog_active
)
3925 cancel_delayed_work(&fan_watchdog_task
);
3927 if (fan_watchdog_maxinterval
> 0) {
3928 fan_watchdog_active
= 1;
3929 if (!schedule_delayed_work(&fan_watchdog_task
,
3930 msecs_to_jiffies(fan_watchdog_maxinterval
3932 printk(IBM_ERR
"failed to schedule the fan watchdog, "
3933 "watchdog will not trigger\n");
3936 fan_watchdog_active
= 0;
3939 static int fan_set_level(int level
)
3941 if (!fan_control_allowed
)
3944 switch (fan_control_access_mode
) {
3945 case TPACPI_FAN_WR_ACPI_SFAN
:
3946 if (level
>= 0 && level
<= 7) {
3947 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
3953 case TPACPI_FAN_WR_ACPI_FANS
:
3954 case TPACPI_FAN_WR_TPEC
:
3955 if ((level
!= TP_EC_FAN_AUTO
) &&
3956 (level
!= TP_EC_FAN_FULLSPEED
) &&
3957 ((level
< 0) || (level
> 7)))
3960 /* safety net should the EC not support AUTO
3961 * or FULLSPEED mode bits and just ignore them */
3962 if (level
& TP_EC_FAN_FULLSPEED
)
3963 level
|= 7; /* safety min speed 7 */
3964 else if (level
& TP_EC_FAN_FULLSPEED
)
3965 level
|= 4; /* safety min speed 4 */
3967 if (!acpi_ec_write(fan_status_offset
, level
))
3970 tp_features
.fan_ctrl_status_undef
= 0;
3979 static int fan_set_level_safe(int level
)
3983 if (!fan_control_allowed
)
3986 rc
= mutex_lock_interruptible(&fan_mutex
);
3990 if (level
== TPACPI_FAN_LAST_LEVEL
)
3991 level
= fan_control_desired_level
;
3993 rc
= fan_set_level(level
);
3995 fan_update_desired_level(level
);
3997 mutex_unlock(&fan_mutex
);
4001 static int fan_set_enable(void)
4006 if (!fan_control_allowed
)
4009 rc
= mutex_lock_interruptible(&fan_mutex
);
4013 switch (fan_control_access_mode
) {
4014 case TPACPI_FAN_WR_ACPI_FANS
:
4015 case TPACPI_FAN_WR_TPEC
:
4016 rc
= fan_get_status(&s
);
4020 /* Don't go out of emergency fan mode */
4023 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4026 if (!acpi_ec_write(fan_status_offset
, s
))
4029 tp_features
.fan_ctrl_status_undef
= 0;
4034 case TPACPI_FAN_WR_ACPI_SFAN
:
4035 rc
= fan_get_status(&s
);
4041 /* Set fan to at least level 4 */
4044 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4054 mutex_unlock(&fan_mutex
);
4058 static int fan_set_disable(void)
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 case TPACPI_FAN_WR_TPEC
:
4073 if (!acpi_ec_write(fan_status_offset
, 0x00))
4076 fan_control_desired_level
= 0;
4077 tp_features
.fan_ctrl_status_undef
= 0;
4081 case TPACPI_FAN_WR_ACPI_SFAN
:
4082 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4085 fan_control_desired_level
= 0;
4093 mutex_unlock(&fan_mutex
);
4097 static int fan_set_speed(int speed
)
4101 if (!fan_control_allowed
)
4104 rc
= mutex_lock_interruptible(&fan_mutex
);
4109 switch (fan_control_access_mode
) {
4110 case TPACPI_FAN_WR_ACPI_FANS
:
4111 if (speed
>= 0 && speed
<= 65535) {
4112 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4113 speed
, speed
, speed
))
4123 mutex_unlock(&fan_mutex
);
4127 static int fan_read(char *p
)
4132 unsigned int speed
= 0;
4134 switch (fan_status_access_mode
) {
4135 case TPACPI_FAN_RD_ACPI_GFAN
:
4136 /* 570, 600e/x, 770e, 770x */
4137 if ((rc
= fan_get_status_safe(&status
)) < 0)
4140 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
4142 (status
!= 0) ? "enabled" : "disabled", status
);
4145 case TPACPI_FAN_RD_TPEC
:
4146 /* all except 570, 600e/x, 770e, 770x */
4147 if ((rc
= fan_get_status_safe(&status
)) < 0)
4150 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4151 if (status
!= fan_control_initial_status
)
4152 tp_features
.fan_ctrl_status_undef
= 0;
4154 /* Return most likely status. In fact, it
4155 * might be the only possible status */
4156 status
= TP_EC_FAN_AUTO
;
4159 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4160 (status
!= 0) ? "enabled" : "disabled");
4162 if ((rc
= fan_get_speed(&speed
)) < 0)
4165 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
4167 if (status
& TP_EC_FAN_FULLSPEED
)
4168 /* Disengaged mode takes precedence */
4169 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
4170 else if (status
& TP_EC_FAN_AUTO
)
4171 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
4173 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
4176 case TPACPI_FAN_NONE
:
4178 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4181 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
4182 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
4184 switch (fan_control_access_mode
) {
4185 case TPACPI_FAN_WR_ACPI_SFAN
:
4186 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4190 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4191 "auto, disengaged, full-speed)\n");
4196 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4197 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4198 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4199 "1-120 (seconds))\n");
4201 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4202 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4203 " (<speed> is 0-65535)\n");
4208 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4212 if (strlencmp(cmd
, "level auto") == 0)
4213 level
= TP_EC_FAN_AUTO
;
4214 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4215 (strlencmp(cmd
, "level full-speed") == 0))
4216 level
= TP_EC_FAN_FULLSPEED
;
4217 else if (sscanf(cmd
, "level %d", &level
) != 1)
4220 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4221 printk(IBM_ERR
"level command accepted for unsupported "
4222 "access mode %d", fan_control_access_mode
);
4227 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4229 if (strlencmp(cmd
, "enable") != 0)
4232 if ((*rc
= fan_set_enable()) == -ENXIO
)
4233 printk(IBM_ERR
"enable command accepted for unsupported "
4234 "access mode %d", fan_control_access_mode
);
4239 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4241 if (strlencmp(cmd
, "disable") != 0)
4244 if ((*rc
= fan_set_disable()) == -ENXIO
)
4245 printk(IBM_ERR
"disable command accepted for unsupported "
4246 "access mode %d", fan_control_access_mode
);
4251 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4256 * Support speed <low> <medium> <high> ? */
4258 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4261 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4262 printk(IBM_ERR
"speed command accepted for unsupported "
4263 "access mode %d", fan_control_access_mode
);
4268 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4272 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4275 if (interval
< 0 || interval
> 120)
4278 fan_watchdog_maxinterval
= interval
;
4283 static int fan_write(char *buf
)
4288 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4289 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4290 fan_write_cmd_level(cmd
, &rc
)) &&
4291 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4292 (fan_write_cmd_enable(cmd
, &rc
) ||
4293 fan_write_cmd_disable(cmd
, &rc
) ||
4294 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4295 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4296 fan_write_cmd_speed(cmd
, &rc
))
4300 fan_watchdog_reset();
4306 static struct ibm_struct fan_driver_data
= {
4313 /****************************************************************************
4314 ****************************************************************************
4318 ****************************************************************************
4319 ****************************************************************************/
4322 static struct proc_dir_entry
*proc_dir
;
4324 /* Subdriver registry */
4325 static LIST_HEAD(tpacpi_all_drivers
);
4329 * Module and infrastructure proble, init and exit handling
4332 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4333 static const char * __init
str_supported(int is_supported
)
4335 static char text_unsupported
[] __initdata
= "not supported";
4337 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4339 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4341 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4344 struct ibm_struct
*ibm
= iibm
->data
;
4345 struct proc_dir_entry
*entry
;
4347 BUG_ON(ibm
== NULL
);
4349 INIT_LIST_HEAD(&ibm
->all_drivers
);
4351 if (ibm
->flags
.experimental
&& !experimental
)
4354 dbg_printk(TPACPI_DBG_INIT
,
4355 "probing for %s\n", ibm
->name
);
4358 ret
= iibm
->init(iibm
);
4360 return 0; /* probe failed */
4364 ibm
->flags
.init_called
= 1;
4368 if (ibm
->acpi
->hid
) {
4369 ret
= register_tpacpi_subdriver(ibm
);
4374 if (ibm
->acpi
->notify
) {
4375 ret
= setup_acpi_notify(ibm
);
4376 if (ret
== -ENODEV
) {
4377 printk(IBM_NOTICE
"disabling subdriver %s\n",
4387 dbg_printk(TPACPI_DBG_INIT
,
4388 "%s installed\n", ibm
->name
);
4391 entry
= create_proc_entry(ibm
->name
,
4392 S_IFREG
| S_IRUGO
| S_IWUSR
,
4395 printk(IBM_ERR
"unable to create proc entry %s\n",
4400 entry
->owner
= THIS_MODULE
;
4402 entry
->read_proc
= &dispatch_procfs_read
;
4404 entry
->write_proc
= &dispatch_procfs_write
;
4405 ibm
->flags
.proc_created
= 1;
4408 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4413 dbg_printk(TPACPI_DBG_INIT
,
4414 "%s: at error exit path with result %d\n",
4418 return (ret
< 0)? ret
: 0;
4421 static void ibm_exit(struct ibm_struct
*ibm
)
4423 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4425 list_del_init(&ibm
->all_drivers
);
4427 if (ibm
->flags
.acpi_notify_installed
) {
4428 dbg_printk(TPACPI_DBG_EXIT
,
4429 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4431 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4433 dispatch_acpi_notify
);
4434 ibm
->flags
.acpi_notify_installed
= 0;
4435 ibm
->flags
.acpi_notify_installed
= 0;
4438 if (ibm
->flags
.proc_created
) {
4439 dbg_printk(TPACPI_DBG_EXIT
,
4440 "%s: remove_proc_entry\n", ibm
->name
);
4441 remove_proc_entry(ibm
->name
, proc_dir
);
4442 ibm
->flags
.proc_created
= 0;
4445 if (ibm
->flags
.acpi_driver_registered
) {
4446 dbg_printk(TPACPI_DBG_EXIT
,
4447 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4449 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4450 kfree(ibm
->acpi
->driver
);
4451 ibm
->acpi
->driver
= NULL
;
4452 ibm
->flags
.acpi_driver_registered
= 0;
4455 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4457 ibm
->flags
.init_called
= 0;
4460 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4465 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
4467 struct dmi_device
*dev
= NULL
;
4468 char ec_fw_string
[18];
4473 memset(tp
, 0, sizeof(*tp
));
4475 if (dmi_name_in_vendors("IBM"))
4476 tp
->vendor
= PCI_VENDOR_ID_IBM
;
4477 else if (dmi_name_in_vendors("LENOVO"))
4478 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
4482 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
4484 if (!tp
->bios_version_str
)
4486 tp
->bios_model
= tp
->bios_version_str
[0]
4487 | (tp
->bios_version_str
[1] << 8);
4490 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4491 * X32 or newer, all Z series; Some models must have an
4492 * up-to-date BIOS or they will not be detected.
4494 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4496 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4497 if (sscanf(dev
->name
,
4498 "IBM ThinkPad Embedded Controller -[%17c",
4499 ec_fw_string
) == 1) {
4500 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4501 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4503 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
4504 tp
->ec_model
= ec_fw_string
[0]
4505 | (ec_fw_string
[1] << 8);
4510 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
4512 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
4513 kfree(tp
->model_str
);
4514 tp
->model_str
= NULL
;
4518 static int __init
probe_for_thinkpad(void)
4526 * Non-ancient models have better DMI tagging, but very old models
4529 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
4531 /* ec is required because many other handles are relative to it */
4532 IBM_ACPIHANDLE_INIT(ec
);
4536 "Not yet supported ThinkPad detected!\n");
4541 * Risks a regression on very old machines, but reduces potential
4542 * false positives a damn great deal
4545 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
4547 if (!is_thinkpad
&& !force_load
)
4554 /* Module init, exit, parameters */
4556 static struct ibm_init_struct ibms_init
[] __initdata
= {
4558 .init
= thinkpad_acpi_driver_init
,
4559 .data
= &thinkpad_acpi_driver_data
,
4562 .init
= hotkey_init
,
4563 .data
= &hotkey_driver_data
,
4566 .init
= bluetooth_init
,
4567 .data
= &bluetooth_driver_data
,
4571 .data
= &wan_driver_data
,
4575 .data
= &video_driver_data
,
4579 .data
= &light_driver_data
,
4581 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4584 .data
= &dock_driver_data
[0],
4588 .data
= &dock_driver_data
[1],
4591 #ifdef CONFIG_THINKPAD_ACPI_BAY
4594 .data
= &bay_driver_data
,
4599 .data
= &cmos_driver_data
,
4603 .data
= &led_driver_data
,
4607 .data
= &beep_driver_data
,
4610 .init
= thermal_init
,
4611 .data
= &thermal_driver_data
,
4614 .data
= &ecdump_driver_data
,
4617 .init
= brightness_init
,
4618 .data
= &brightness_driver_data
,
4621 .data
= &volume_driver_data
,
4625 .data
= &fan_driver_data
,
4629 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4632 struct ibm_struct
*ibm
;
4634 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4635 ibm
= ibms_init
[i
].data
;
4636 BUG_ON(ibm
== NULL
);
4638 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4639 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4641 strcpy(ibms_init
[i
].param
, val
);
4642 strcat(ibms_init
[i
].param
, ",");
4650 static int experimental
;
4651 module_param(experimental
, int, 0);
4653 static u32 dbg_level
;
4654 module_param_named(debug
, dbg_level
, uint
, 0);
4656 static int force_load
;
4657 module_param(force_load
, bool, 0);
4659 static int fan_control_allowed
;
4660 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
4662 static int brightness_mode
;
4663 module_param_named(brightness_mode
, brightness_mode
, int, 0);
4665 static unsigned int hotkey_report_mode
;
4666 module_param(hotkey_report_mode
, uint
, 0);
4668 #define IBM_PARAM(feature) \
4669 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4672 IBM_PARAM(bluetooth
);
4675 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4678 #ifdef CONFIG_THINKPAD_ACPI_BAY
4680 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4685 IBM_PARAM(brightness
);
4689 static int __init
thinkpad_acpi_module_init(void)
4693 /* Parameter checking */
4694 if (hotkey_report_mode
> 2)
4697 /* Driver-level probe */
4699 get_thinkpad_model_data(&thinkpad_id
);
4700 ret
= probe_for_thinkpad();
4702 thinkpad_acpi_module_exit();
4706 /* Driver initialization */
4708 IBM_ACPIHANDLE_INIT(ecrd
);
4709 IBM_ACPIHANDLE_INIT(ecwr
);
4711 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4713 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4714 thinkpad_acpi_module_exit();
4717 proc_dir
->owner
= THIS_MODULE
;
4719 ret
= platform_driver_register(&tpacpi_pdriver
);
4721 printk(IBM_ERR
"unable to register platform driver\n");
4722 thinkpad_acpi_module_exit();
4725 tp_features
.platform_drv_registered
= 1;
4727 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4729 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4730 thinkpad_acpi_module_exit();
4733 tp_features
.platform_drv_attrs_registered
= 1;
4736 /* Device initialization */
4737 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4739 if (IS_ERR(tpacpi_pdev
)) {
4740 ret
= PTR_ERR(tpacpi_pdev
);
4742 printk(IBM_ERR
"unable to register platform device\n");
4743 thinkpad_acpi_module_exit();
4746 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
4747 if (IS_ERR(tpacpi_hwmon
)) {
4748 ret
= PTR_ERR(tpacpi_hwmon
);
4749 tpacpi_hwmon
= NULL
;
4750 printk(IBM_ERR
"unable to register hwmon device\n");
4751 thinkpad_acpi_module_exit();
4754 mutex_init(&tpacpi_inputdev_send_mutex
);
4755 tpacpi_inputdev
= input_allocate_device();
4756 if (!tpacpi_inputdev
) {
4757 printk(IBM_ERR
"unable to allocate input device\n");
4758 thinkpad_acpi_module_exit();
4761 /* Prepare input device, but don't register */
4762 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
4763 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
4764 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
4765 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
4766 thinkpad_id
.vendor
:
4768 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
4769 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
4771 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4772 ret
= ibm_init(&ibms_init
[i
]);
4773 if (ret
>= 0 && *ibms_init
[i
].param
)
4774 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
4776 thinkpad_acpi_module_exit();
4780 ret
= input_register_device(tpacpi_inputdev
);
4782 printk(IBM_ERR
"unable to register input device\n");
4783 thinkpad_acpi_module_exit();
4786 tp_features
.input_device_registered
= 1;
4792 static void thinkpad_acpi_module_exit(void)
4794 struct ibm_struct
*ibm
, *itmp
;
4796 list_for_each_entry_safe_reverse(ibm
, itmp
,
4797 &tpacpi_all_drivers
,
4802 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
4804 if (tpacpi_inputdev
) {
4805 if (tp_features
.input_device_registered
)
4806 input_unregister_device(tpacpi_inputdev
);
4808 input_free_device(tpacpi_inputdev
);
4812 hwmon_device_unregister(tpacpi_hwmon
);
4815 platform_device_unregister(tpacpi_pdev
);
4817 if (tp_features
.platform_drv_attrs_registered
)
4818 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
4820 if (tp_features
.platform_drv_registered
)
4821 platform_driver_unregister(&tpacpi_pdriver
);
4824 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
4826 kfree(thinkpad_id
.bios_version_str
);
4827 kfree(thinkpad_id
.ec_version_str
);
4828 kfree(thinkpad_id
.model_str
);
4831 module_init(thinkpad_acpi_module_init
);
4832 module_exit(thinkpad_acpi_module_exit
);