2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define IBM_VERSION "0.15"
25 #define TPACPI_SYSFS_VERSION 0x010000
29 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
32 * 2006-11-22 0.13 new maintainer
33 * changelog now lives in git commit history, and will
34 * not be updated further in-file.
36 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
37 * 2005-03-17 0.11 support for 600e, 770x
38 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
39 * support for 770e, G41
40 * G40 and G41 don't have a thinklight
41 * temperatures no longer experimental
42 * experimental brightness control
43 * experimental volume control
44 * experimental fan enable/disable
45 * 2005-01-16 0.10 fix module loading on R30, R31
46 * 2005-01-16 0.9 support for 570, R30, R31
47 * ultrabay support on A22p, A3x
48 * limit arg for cmos, led, beep, drop experimental status
49 * more capable led control on A21e, A22p, T20-22, X20
50 * experimental temperatures and fan speed
51 * experimental embedded controller register dump
52 * mark more functions as __init, drop incorrect __exit
54 * thanks to Henrik Brix Andersen <brix@gentoo.org>
55 * fix parameter passing on module loading
56 * thanks to Rusty Russell <rusty@rustcorp.com.au>
57 * thanks to Jim Radford <radford@blackbean.org>
58 * 2004-11-08 0.8 fix init error case, don't return from a macro
59 * thanks to Chris Wright <chrisw@osdl.org>
60 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
61 * fix led control on A21e
62 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
63 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
64 * proc file format changed
65 * video_switch command
66 * experimental cmos control
67 * experimental led control
68 * experimental acpi sounds
69 * 2004-09-16 0.4 support for module parameters
70 * hotkey mask can be prefixed by 0x
71 * video output switching
72 * video expansion control
73 * ultrabay eject support
74 * removed lcd brightness/on/off control, didn't work
75 * 2004-08-17 0.3 support for R40
76 * lcd off, brightness control
78 * 2004-08-14 0.2 support for T series, X20
79 * bluetooth enable/disable
80 * hotkey events disabled by default
81 * removed fan control, currently useless
82 * 2004-08-09 0.1 initial release, support for X series
85 #include "thinkpad_acpi.h"
87 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
88 MODULE_DESCRIPTION(IBM_DESC
);
89 MODULE_VERSION(IBM_VERSION
);
90 MODULE_LICENSE("GPL");
92 /* Please remove this in year 2009 */
93 MODULE_ALIAS("ibm_acpi");
96 * DMI matching for module autoloading
98 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
99 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
101 * Only models listed in thinkwiki will be supported, so add yours
102 * if it is not there yet.
104 #define IBM_BIOS_MODULE_ALIAS(__type) \
105 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
107 /* Non-ancient thinkpads */
108 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
109 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
111 /* Ancient thinkpad BIOSes have to be identified by
112 * BIOS type or model number, and there are far less
113 * BIOS types than model numbers... */
114 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
115 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
116 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
118 #define __unused __attribute__ ((unused))
120 /****************************************************************************
121 ****************************************************************************
123 * ACPI Helpers and device model
125 ****************************************************************************
126 ****************************************************************************/
128 /*************************************************************************
132 static acpi_handle root_handle
;
134 #define IBM_HANDLE(object, parent, paths...) \
135 static acpi_handle object##_handle; \
136 static acpi_handle *object##_parent = &parent##_handle; \
137 static char *object##_path; \
138 static char *object##_paths[] = { paths }
140 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
141 "\\_SB.PCI.ISA.EC", /* 570 */
142 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
143 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
144 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
145 "\\_SB.PCI0.ICH3.EC0", /* R31 */
146 "\\_SB.PCI0.LPC.EC", /* all others */
149 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
150 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
153 /*************************************************************************
157 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
158 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
159 "\\CMS", /* R40, R40e */
162 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
163 "^HKEY", /* R30, R31 */
164 "HKEY", /* all others */
168 /*************************************************************************
172 static int acpi_evalf(acpi_handle handle
,
173 void *res
, char *method
, char *fmt
, ...)
176 struct acpi_object_list params
;
177 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
178 struct acpi_buffer result
, *resultp
;
179 union acpi_object out_obj
;
187 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
200 params
.pointer
= &in_objs
[0];
207 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
208 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
210 /* add more types as needed */
212 printk(IBM_ERR
"acpi_evalf() called "
213 "with invalid format character '%c'\n", c
);
219 if (res_type
!= 'v') {
220 result
.length
= sizeof(out_obj
);
221 result
.pointer
= &out_obj
;
226 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
231 *(int *)res
= out_obj
.integer
.value
;
232 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
235 success
= status
== AE_OK
;
237 /* add more types as needed */
239 printk(IBM_ERR
"acpi_evalf() called "
240 "with invalid format character '%c'\n", res_type
);
244 if (!success
&& !quiet
)
245 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
246 method
, fmt0
, status
);
251 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
255 if (acpi_evalf(handle
, &i
, method
, "d"))
256 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
258 printk(IBM_ERR
"error calling %s\n", method
);
261 static int acpi_ec_read(int i
, u8
* p
)
266 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
270 if (ec_read(i
, p
) < 0)
277 static int acpi_ec_write(int i
, u8 v
)
280 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
283 if (ec_write(i
, v
) < 0)
290 static int _sta(acpi_handle handle
)
294 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
300 static int issue_thinkpad_cmos_command(int cmos_cmd
)
305 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
311 /*************************************************************************
315 static void drv_acpi_handle_init(char *name
,
316 acpi_handle
*handle
, acpi_handle parent
,
317 char **paths
, int num_paths
, char **path
)
322 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
325 for (i
= 0; i
< num_paths
; i
++) {
326 status
= acpi_get_handle(parent
, paths
[i
], handle
);
327 if (ACPI_SUCCESS(status
)) {
329 dbg_printk(TPACPI_DBG_INIT
,
330 "Found ACPI handle %s for %s\n",
336 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
341 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
343 struct ibm_struct
*ibm
= data
;
345 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
348 ibm
->acpi
->notify(ibm
, event
);
351 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
358 if (!*ibm
->acpi
->handle
)
361 vdbg_printk(TPACPI_DBG_INIT
,
362 "setting up ACPI notify for %s\n", ibm
->name
);
364 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
366 printk(IBM_ERR
"acpi_bus_get_device(%s) failed: %d\n",
371 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
372 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
373 IBM_ACPI_EVENT_PREFIX
,
376 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
377 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
378 if (ACPI_FAILURE(status
)) {
379 if (status
== AE_ALREADY_EXISTS
) {
380 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
383 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
388 ibm
->flags
.acpi_notify_installed
= 1;
392 static int __init
tpacpi_device_add(struct acpi_device
*device
)
397 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
401 dbg_printk(TPACPI_DBG_INIT
,
402 "registering %s as an ACPI driver\n", ibm
->name
);
406 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
407 if (!ibm
->acpi
->driver
) {
408 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
412 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
413 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
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
;
523 static int tpacpi_resume_handler(struct platform_device
*pdev
)
525 struct ibm_struct
*ibm
, *itmp
;
527 list_for_each_entry_safe(ibm
, itmp
,
537 static struct platform_driver tpacpi_pdriver
= {
539 .name
= IBM_DRVR_NAME
,
540 .owner
= THIS_MODULE
,
542 .resume
= tpacpi_resume_handler
,
546 /*************************************************************************
547 * thinkpad-acpi driver attributes
550 /* interface_version --------------------------------------------------- */
551 static ssize_t
tpacpi_driver_interface_version_show(
552 struct device_driver
*drv
,
555 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
558 static DRIVER_ATTR(interface_version
, S_IRUGO
,
559 tpacpi_driver_interface_version_show
, NULL
);
561 /* debug_level --------------------------------------------------------- */
562 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
565 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
568 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
569 const char *buf
, size_t count
)
573 if (parse_strtoul(buf
, 0xffff, &t
))
581 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
582 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
584 /* version ------------------------------------------------------------- */
585 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
588 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
591 static DRIVER_ATTR(version
, S_IRUGO
,
592 tpacpi_driver_version_show
, NULL
);
594 /* --------------------------------------------------------------------- */
596 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
597 &driver_attr_debug_level
, &driver_attr_version
,
598 &driver_attr_interface_version
,
601 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
607 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
608 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
615 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
619 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
620 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
623 /*************************************************************************
624 * sysfs support helpers
627 struct attribute_set_obj
{
628 struct attribute_set s
;
630 } __attribute__((packed
));
632 static struct attribute_set
*create_attr_set(unsigned int max_members
,
635 struct attribute_set_obj
*sobj
;
637 if (max_members
== 0)
640 /* Allocates space for implicit NULL at the end too */
641 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
642 max_members
* sizeof(struct attribute
*),
646 sobj
->s
.max_members
= max_members
;
647 sobj
->s
.group
.attrs
= &sobj
->a
;
648 sobj
->s
.group
.name
= name
;
653 /* not multi-threaded safe, use it in a single thread per set */
654 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
659 if (s
->members
>= s
->max_members
)
662 s
->group
.attrs
[s
->members
] = attr
;
668 static int add_many_to_attr_set(struct attribute_set
* s
,
669 struct attribute
**attr
,
674 for (i
= 0; i
< count
; i
++) {
675 res
= add_to_attr_set(s
, attr
[i
]);
683 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
685 sysfs_remove_group(kobj
, &s
->group
);
689 static int parse_strtoul(const char *buf
,
690 unsigned long max
, unsigned long *value
)
694 *value
= simple_strtoul(buf
, &endp
, 0);
695 while (*endp
&& isspace(*endp
))
697 if (*endp
|| *value
> max
)
703 /****************************************************************************
704 ****************************************************************************
708 ****************************************************************************
709 ****************************************************************************/
711 /*************************************************************************
712 * thinkpad-acpi init subdriver
715 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
717 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
718 printk(IBM_INFO
"%s\n", IBM_URL
);
720 printk(IBM_INFO
"ThinkPad BIOS %s, EC %s\n",
721 (thinkpad_id
.bios_version_str
) ?
722 thinkpad_id
.bios_version_str
: "unknown",
723 (thinkpad_id
.ec_version_str
) ?
724 thinkpad_id
.ec_version_str
: "unknown");
726 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
727 printk(IBM_INFO
"%s %s\n",
728 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
729 "IBM" : ((thinkpad_id
.vendor
==
730 PCI_VENDOR_ID_LENOVO
) ?
731 "Lenovo" : "Unknown vendor"),
732 thinkpad_id
.model_str
);
737 static int thinkpad_acpi_driver_read(char *p
)
741 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
742 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
747 static struct ibm_struct thinkpad_acpi_driver_data
= {
749 .read
= thinkpad_acpi_driver_read
,
752 /*************************************************************************
756 static int hotkey_orig_status
;
757 static u32 hotkey_orig_mask
;
758 static u32 hotkey_all_mask
;
759 static u32 hotkey_reserved_mask
;
761 static u16
*hotkey_keycode_map
;
763 static struct attribute_set
*hotkey_dev_attributes
;
765 static int hotkey_get_wlsw(int *status
)
767 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
772 /* sysfs hotkey enable ------------------------------------------------- */
773 static ssize_t
hotkey_enable_show(struct device
*dev
,
774 struct device_attribute
*attr
,
780 res
= hotkey_get(&status
, &mask
);
784 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
787 static ssize_t
hotkey_enable_store(struct device
*dev
,
788 struct device_attribute
*attr
,
789 const char *buf
, size_t count
)
795 if (parse_strtoul(buf
, 1, &t
))
798 res
= hotkey_get(&status
, &mask
);
800 res
= hotkey_set(t
, mask
);
802 return (res
) ? res
: count
;
805 static struct device_attribute dev_attr_hotkey_enable
=
806 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
807 hotkey_enable_show
, hotkey_enable_store
);
809 /* sysfs hotkey mask --------------------------------------------------- */
810 static ssize_t
hotkey_mask_show(struct device
*dev
,
811 struct device_attribute
*attr
,
817 res
= hotkey_get(&status
, &mask
);
821 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
824 static ssize_t
hotkey_mask_store(struct device
*dev
,
825 struct device_attribute
*attr
,
826 const char *buf
, size_t count
)
832 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
835 res
= hotkey_get(&status
, &mask
);
837 hotkey_set(status
, t
);
839 return (res
) ? res
: count
;
842 static struct device_attribute dev_attr_hotkey_mask
=
843 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
844 hotkey_mask_show
, hotkey_mask_store
);
846 /* sysfs hotkey bios_enabled ------------------------------------------- */
847 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
848 struct device_attribute
*attr
,
851 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
854 static struct device_attribute dev_attr_hotkey_bios_enabled
=
855 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
857 /* sysfs hotkey bios_mask ---------------------------------------------- */
858 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
859 struct device_attribute
*attr
,
862 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
865 static struct device_attribute dev_attr_hotkey_bios_mask
=
866 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
868 /* sysfs hotkey all_mask ----------------------------------------------- */
869 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
870 struct device_attribute
*attr
,
873 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_all_mask
);
876 static struct device_attribute dev_attr_hotkey_all_mask
=
877 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
879 /* sysfs hotkey recommended_mask --------------------------------------- */
880 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
881 struct device_attribute
*attr
,
884 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
885 hotkey_all_mask
& ~hotkey_reserved_mask
);
888 static struct device_attribute dev_attr_hotkey_recommended_mask
=
889 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
890 hotkey_recommended_mask_show
, NULL
);
892 /* sysfs hotkey radio_sw ----------------------------------------------- */
893 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
894 struct device_attribute
*attr
,
898 res
= hotkey_get_wlsw(&s
);
902 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
905 static struct device_attribute dev_attr_hotkey_radio_sw
=
906 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
908 /* sysfs hotkey report_mode -------------------------------------------- */
909 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
910 struct device_attribute
*attr
,
913 return snprintf(buf
, PAGE_SIZE
, "%d\n",
914 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
917 static ssize_t
hotkey_report_mode_store(struct device
*dev
,
918 struct device_attribute
*attr
,
919 const char *buf
, size_t count
)
924 if (parse_strtoul(buf
, 2, &t
) || (t
< 1))
927 if (t
!= hotkey_report_mode
) {
928 if (tp_features
.hotkey_report_mode_locked
)
930 hotkey_report_mode
= t
;
931 printk(IBM_NOTICE
"hot key report mode set to %d\n",
935 return (res
) ? res
: count
;
938 static struct device_attribute dev_attr_hotkey_report_mode
=
939 __ATTR(hotkey_report_mode
, S_IWUSR
| S_IRUGO
,
940 hotkey_report_mode_show
, hotkey_report_mode_store
);
942 /* --------------------------------------------------------------------- */
944 static struct attribute
*hotkey_attributes
[] __initdata
= {
945 &dev_attr_hotkey_enable
.attr
,
946 &dev_attr_hotkey_report_mode
.attr
,
949 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
950 &dev_attr_hotkey_mask
.attr
,
951 &dev_attr_hotkey_bios_enabled
.attr
,
952 &dev_attr_hotkey_bios_mask
.attr
,
953 &dev_attr_hotkey_all_mask
.attr
,
954 &dev_attr_hotkey_recommended_mask
.attr
,
957 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
960 static u16 ibm_keycode_map
[] __initdata
= {
961 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
962 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
963 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
964 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
965 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
966 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
967 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
968 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
969 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
970 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
971 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
972 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
973 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
974 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
975 KEY_RESERVED
, /* 0x14: VOLUME UP */
976 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
977 KEY_RESERVED
, /* 0x16: MUTE */
978 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
979 /* (assignments unknown, please report if found) */
980 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
981 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
983 static u16 lenovo_keycode_map
[] __initdata
= {
984 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
985 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
986 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
987 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
988 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
989 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
990 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
991 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
992 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
993 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
994 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
995 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
996 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
997 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
998 KEY_RESERVED
, /* 0x14: VOLUME UP */
999 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1000 KEY_RESERVED
, /* 0x16: MUTE */
1001 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1002 /* (assignments unknown, please report if found) */
1003 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1004 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1007 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1008 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1009 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1014 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1016 BUG_ON(!tpacpi_inputdev
);
1018 IBM_ACPIHANDLE_INIT(hkey
);
1019 mutex_init(&hotkey_mutex
);
1021 /* hotkey not supported on 570 */
1022 tp_features
.hotkey
= hkey_handle
!= NULL
;
1024 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1025 str_supported(tp_features
.hotkey
));
1027 if (tp_features
.hotkey
) {
1028 hotkey_dev_attributes
= create_attr_set(8, NULL
);
1029 if (!hotkey_dev_attributes
)
1031 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1033 ARRAY_SIZE(hotkey_attributes
));
1037 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1038 A30, R30, R31, T20-22, X20-21, X22-24 */
1039 tp_features
.hotkey_mask
=
1040 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
1042 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1043 str_supported(tp_features
.hotkey_mask
));
1045 if (tp_features
.hotkey_mask
) {
1046 /* MHKA available in A31, R40, R40e, T4x, X31, and later */
1047 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1049 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
1052 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
1053 if (!res
&& tp_features
.hotkey_mask
) {
1054 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1055 hotkey_mask_attributes
,
1056 ARRAY_SIZE(hotkey_mask_attributes
));
1059 /* Not all thinkpads have a hardware radio switch */
1060 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1061 tp_features
.hotkey_wlsw
= 1;
1063 "radio switch found; radios are %s\n",
1064 enabled(status
, 0));
1065 res
= add_to_attr_set(hotkey_dev_attributes
,
1066 &dev_attr_hotkey_radio_sw
.attr
);
1070 res
= register_attr_set_with_sysfs(
1071 hotkey_dev_attributes
,
1072 &tpacpi_pdev
->dev
.kobj
);
1076 /* Set up key map */
1078 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1080 if (!hotkey_keycode_map
) {
1081 printk(IBM_ERR
"failed to allocate memory for key map\n");
1085 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1086 dbg_printk(TPACPI_DBG_INIT
,
1087 "using Lenovo default hot key map\n");
1088 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1089 TPACPI_HOTKEY_MAP_SIZE
);
1091 dbg_printk(TPACPI_DBG_INIT
,
1092 "using IBM default hot key map\n");
1093 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1094 TPACPI_HOTKEY_MAP_SIZE
);
1097 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1098 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1099 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1100 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1101 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1102 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1103 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1104 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1105 set_bit(hotkey_keycode_map
[i
],
1106 tpacpi_inputdev
->keybit
);
1108 if (i
< sizeof(hotkey_reserved_mask
)*8)
1109 hotkey_reserved_mask
|= 1 << i
;
1113 if (tp_features
.hotkey_wlsw
) {
1114 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1115 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1118 dbg_printk(TPACPI_DBG_INIT
,
1119 "enabling hot key handling\n");
1120 res
= hotkey_set(1, (hotkey_all_mask
& ~hotkey_reserved_mask
)
1121 | hotkey_orig_mask
);
1125 if (hotkey_report_mode
> 0) {
1126 tp_features
.hotkey_report_mode_locked
= 1;
1128 hotkey_report_mode
= 1;
1129 vdbg_printk(TPACPI_DBG_INIT
,
1130 "hot key reporting mode can be "
1131 "changed at runtime\n");
1134 dbg_printk(TPACPI_DBG_INIT
,
1135 "legacy hot key reporting over procfs %s\n",
1136 (hotkey_report_mode
< 2) ?
1137 "enabled" : "disabled");
1140 return (tp_features
.hotkey
)? 0 : 1;
1143 static void hotkey_exit(void)
1147 if (tp_features
.hotkey
) {
1148 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
1149 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
1151 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
1154 if (hotkey_dev_attributes
) {
1155 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1156 hotkey_dev_attributes
= NULL
;
1160 static void tpacpi_input_send_key(unsigned int scancode
,
1161 unsigned int keycode
)
1163 if (keycode
!= KEY_RESERVED
) {
1164 input_report_key(tpacpi_inputdev
, keycode
, 1);
1165 if (keycode
== KEY_UNKNOWN
)
1166 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1168 input_sync(tpacpi_inputdev
);
1170 input_report_key(tpacpi_inputdev
, keycode
, 0);
1171 if (keycode
== KEY_UNKNOWN
)
1172 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1174 input_sync(tpacpi_inputdev
);
1178 static void tpacpi_input_send_radiosw(void)
1182 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
))
1183 input_report_switch(tpacpi_inputdev
,
1187 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1190 unsigned int keycode
, scancode
;
1191 int send_acpi_ev
= 0;
1193 if (event
== 0x80 && acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1194 switch (hkey
>> 12) {
1196 /* 0x1000-0x1FFF: key presses */
1197 scancode
= hkey
& 0xfff;
1198 if (scancode
> 0 && scancode
< 0x21) {
1200 keycode
= hotkey_keycode_map
[scancode
];
1201 tpacpi_input_send_key(scancode
, keycode
);
1204 "hotkey 0x%04x out of range for keyboard map\n",
1210 /* 0x5000-0x5FFF: LID */
1211 /* we don't handle it through this path, just
1212 * eat up known LID events */
1213 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1215 "unknown LID-related hotkey event: 0x%04x\n",
1221 /* 0x7000-0x7FFF: misc */
1222 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1223 tpacpi_input_send_radiosw();
1226 /* fallthrough to default */
1228 /* case 2: dock-related */
1229 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1230 /* case 3: ultra-bay related. maybe bay in dock? */
1231 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1232 printk(IBM_NOTICE
"unhandled HKEY event 0x%04x\n", hkey
);
1236 printk(IBM_ERR
"unknown hotkey notification event %d\n", event
);
1241 if (send_acpi_ev
|| hotkey_report_mode
< 2) {
1242 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
1246 static void hotkey_resume(void)
1248 tpacpi_input_send_radiosw();
1252 * Call with hotkey_mutex held
1254 static int hotkey_get(int *status
, u32
*mask
)
1256 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1259 if (tp_features
.hotkey_mask
)
1260 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1267 * Call with hotkey_mutex held
1269 static int hotkey_set(int status
, u32 mask
)
1273 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1276 if (tp_features
.hotkey_mask
)
1277 for (i
= 0; i
< 32; i
++) {
1278 int bit
= ((1 << i
) & mask
) != 0;
1279 if (!acpi_evalf(hkey_handle
,
1280 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1287 /* procfs -------------------------------------------------------------- */
1288 static int hotkey_read(char *p
)
1294 if (!tp_features
.hotkey
) {
1295 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1299 res
= mutex_lock_interruptible(&hotkey_mutex
);
1302 res
= hotkey_get(&status
, &mask
);
1303 mutex_unlock(&hotkey_mutex
);
1307 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1308 if (tp_features
.hotkey_mask
) {
1309 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1310 len
+= sprintf(p
+ len
,
1311 "commands:\tenable, disable, reset, <mask>\n");
1313 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1314 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1320 static int hotkey_write(char *buf
)
1327 if (!tp_features
.hotkey
)
1330 res
= mutex_lock_interruptible(&hotkey_mutex
);
1334 res
= hotkey_get(&status
, &mask
);
1339 while ((cmd
= next_cmd(&buf
))) {
1340 if (strlencmp(cmd
, "enable") == 0) {
1342 } else if (strlencmp(cmd
, "disable") == 0) {
1344 } else if (strlencmp(cmd
, "reset") == 0) {
1345 status
= hotkey_orig_status
;
1346 mask
= hotkey_orig_mask
;
1347 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1349 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1359 res
= hotkey_set(status
, mask
);
1362 mutex_unlock(&hotkey_mutex
);
1366 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1367 .hid
= IBM_HKEY_HID
,
1368 .notify
= hotkey_notify
,
1369 .handle
= &hkey_handle
,
1370 .type
= ACPI_DEVICE_NOTIFY
,
1373 static struct ibm_struct hotkey_driver_data
= {
1375 .read
= hotkey_read
,
1376 .write
= hotkey_write
,
1377 .exit
= hotkey_exit
,
1378 .resume
= hotkey_resume
,
1379 .acpi
= &ibm_hotkey_acpidriver
,
1382 /*************************************************************************
1383 * Bluetooth subdriver
1386 /* sysfs bluetooth enable ---------------------------------------------- */
1387 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1388 struct device_attribute
*attr
,
1393 status
= bluetooth_get_radiosw();
1397 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1400 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1401 struct device_attribute
*attr
,
1402 const char *buf
, size_t count
)
1407 if (parse_strtoul(buf
, 1, &t
))
1410 res
= bluetooth_set_radiosw(t
);
1412 return (res
) ? res
: count
;
1415 static struct device_attribute dev_attr_bluetooth_enable
=
1416 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1417 bluetooth_enable_show
, bluetooth_enable_store
);
1419 /* --------------------------------------------------------------------- */
1421 static struct attribute
*bluetooth_attributes
[] = {
1422 &dev_attr_bluetooth_enable
.attr
,
1426 static const struct attribute_group bluetooth_attr_group
= {
1427 .attrs
= bluetooth_attributes
,
1430 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1435 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1437 IBM_ACPIHANDLE_INIT(hkey
);
1439 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1440 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1441 tp_features
.bluetooth
= hkey_handle
&&
1442 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1444 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1445 str_supported(tp_features
.bluetooth
),
1448 if (tp_features
.bluetooth
) {
1449 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1450 /* no bluetooth hardware present in system */
1451 tp_features
.bluetooth
= 0;
1452 dbg_printk(TPACPI_DBG_INIT
,
1453 "bluetooth hardware not installed\n");
1455 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1456 &bluetooth_attr_group
);
1462 return (tp_features
.bluetooth
)? 0 : 1;
1465 static void bluetooth_exit(void)
1467 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1468 &bluetooth_attr_group
);
1471 static int bluetooth_get_radiosw(void)
1475 if (!tp_features
.bluetooth
)
1478 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1481 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1484 static int bluetooth_set_radiosw(int radio_on
)
1488 if (!tp_features
.bluetooth
)
1491 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1494 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1496 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1497 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1503 /* procfs -------------------------------------------------------------- */
1504 static int bluetooth_read(char *p
)
1507 int status
= bluetooth_get_radiosw();
1509 if (!tp_features
.bluetooth
)
1510 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1512 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1513 (status
)? "enabled" : "disabled");
1514 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1520 static int bluetooth_write(char *buf
)
1524 if (!tp_features
.bluetooth
)
1527 while ((cmd
= next_cmd(&buf
))) {
1528 if (strlencmp(cmd
, "enable") == 0) {
1529 bluetooth_set_radiosw(1);
1530 } else if (strlencmp(cmd
, "disable") == 0) {
1531 bluetooth_set_radiosw(0);
1539 static struct ibm_struct bluetooth_driver_data
= {
1540 .name
= "bluetooth",
1541 .read
= bluetooth_read
,
1542 .write
= bluetooth_write
,
1543 .exit
= bluetooth_exit
,
1546 /*************************************************************************
1550 /* sysfs wan enable ---------------------------------------------------- */
1551 static ssize_t
wan_enable_show(struct device
*dev
,
1552 struct device_attribute
*attr
,
1557 status
= wan_get_radiosw();
1561 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1564 static ssize_t
wan_enable_store(struct device
*dev
,
1565 struct device_attribute
*attr
,
1566 const char *buf
, size_t count
)
1571 if (parse_strtoul(buf
, 1, &t
))
1574 res
= wan_set_radiosw(t
);
1576 return (res
) ? res
: count
;
1579 static struct device_attribute dev_attr_wan_enable
=
1580 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1581 wan_enable_show
, wan_enable_store
);
1583 /* --------------------------------------------------------------------- */
1585 static struct attribute
*wan_attributes
[] = {
1586 &dev_attr_wan_enable
.attr
,
1590 static const struct attribute_group wan_attr_group
= {
1591 .attrs
= wan_attributes
,
1594 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1599 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1601 IBM_ACPIHANDLE_INIT(hkey
);
1603 tp_features
.wan
= hkey_handle
&&
1604 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1606 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1607 str_supported(tp_features
.wan
),
1610 if (tp_features
.wan
) {
1611 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1612 /* no wan hardware present in system */
1613 tp_features
.wan
= 0;
1614 dbg_printk(TPACPI_DBG_INIT
,
1615 "wan hardware not installed\n");
1617 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1624 return (tp_features
.wan
)? 0 : 1;
1627 static void wan_exit(void)
1629 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1633 static int wan_get_radiosw(void)
1637 if (!tp_features
.wan
)
1640 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1643 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1646 static int wan_set_radiosw(int radio_on
)
1650 if (!tp_features
.wan
)
1653 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1656 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1658 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1659 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1665 /* procfs -------------------------------------------------------------- */
1666 static int wan_read(char *p
)
1669 int status
= wan_get_radiosw();
1671 if (!tp_features
.wan
)
1672 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1674 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1675 (status
)? "enabled" : "disabled");
1676 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1682 static int wan_write(char *buf
)
1686 if (!tp_features
.wan
)
1689 while ((cmd
= next_cmd(&buf
))) {
1690 if (strlencmp(cmd
, "enable") == 0) {
1692 } else if (strlencmp(cmd
, "disable") == 0) {
1701 static struct ibm_struct wan_driver_data
= {
1706 .flags
.experimental
= 1,
1709 /*************************************************************************
1713 static enum video_access_mode video_supported
;
1714 static int video_orig_autosw
;
1716 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1717 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1718 "\\_SB.PCI0.VID0", /* 770e */
1719 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1720 "\\_SB.PCI0.AGP.VID", /* all others */
1723 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1725 static int __init
video_init(struct ibm_init_struct
*iibm
)
1729 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1731 IBM_ACPIHANDLE_INIT(vid
);
1732 IBM_ACPIHANDLE_INIT(vid2
);
1734 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1735 /* G41, assume IVGA doesn't change */
1736 vid_handle
= vid2_handle
;
1739 /* video switching not supported on R30, R31 */
1740 video_supported
= TPACPI_VIDEO_NONE
;
1741 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1743 video_supported
= TPACPI_VIDEO_570
;
1744 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1745 /* 600e/x, 770e, 770x */
1746 video_supported
= TPACPI_VIDEO_770
;
1749 video_supported
= TPACPI_VIDEO_NEW
;
1751 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1752 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1755 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1758 static void video_exit(void)
1760 dbg_printk(TPACPI_DBG_EXIT
,
1761 "restoring original video autoswitch mode\n");
1762 if (video_autosw_set(video_orig_autosw
))
1763 printk(IBM_ERR
"error while trying to restore original "
1764 "video autoswitch mode\n");
1767 static int video_outputsw_get(void)
1772 switch (video_supported
) {
1773 case TPACPI_VIDEO_570
:
1774 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1775 TP_ACPI_VIDEO_570_PHSCMD
))
1777 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1779 case TPACPI_VIDEO_770
:
1780 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1783 status
|= TP_ACPI_VIDEO_S_LCD
;
1784 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1787 status
|= TP_ACPI_VIDEO_S_CRT
;
1789 case TPACPI_VIDEO_NEW
:
1790 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1791 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1794 status
|= TP_ACPI_VIDEO_S_CRT
;
1796 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1797 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1800 status
|= TP_ACPI_VIDEO_S_LCD
;
1801 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1804 status
|= TP_ACPI_VIDEO_S_DVI
;
1813 static int video_outputsw_set(int status
)
1818 switch (video_supported
) {
1819 case TPACPI_VIDEO_570
:
1820 res
= acpi_evalf(NULL
, NULL
,
1821 "\\_SB.PHS2", "vdd",
1822 TP_ACPI_VIDEO_570_PHS2CMD
,
1823 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1825 case TPACPI_VIDEO_770
:
1826 autosw
= video_autosw_get();
1830 res
= video_autosw_set(1);
1833 res
= acpi_evalf(vid_handle
, NULL
,
1834 "ASWT", "vdd", status
* 0x100, 0);
1835 if (!autosw
&& video_autosw_set(autosw
)) {
1836 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1840 case TPACPI_VIDEO_NEW
:
1841 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1842 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1848 return (res
)? 0 : -EIO
;
1851 static int video_autosw_get(void)
1855 switch (video_supported
) {
1856 case TPACPI_VIDEO_570
:
1857 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1860 case TPACPI_VIDEO_770
:
1861 case TPACPI_VIDEO_NEW
:
1862 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1872 static int video_autosw_set(int enable
)
1874 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1879 static int video_outputsw_cycle(void)
1881 int autosw
= video_autosw_get();
1887 switch (video_supported
) {
1888 case TPACPI_VIDEO_570
:
1889 res
= video_autosw_set(1);
1892 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1894 case TPACPI_VIDEO_770
:
1895 case TPACPI_VIDEO_NEW
:
1896 res
= video_autosw_set(1);
1899 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1904 if (!autosw
&& video_autosw_set(autosw
)) {
1905 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1909 return (res
)? 0 : -EIO
;
1912 static int video_expand_toggle(void)
1914 switch (video_supported
) {
1915 case TPACPI_VIDEO_570
:
1916 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1918 case TPACPI_VIDEO_770
:
1919 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1921 case TPACPI_VIDEO_NEW
:
1922 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1930 static int video_read(char *p
)
1935 if (video_supported
== TPACPI_VIDEO_NONE
) {
1936 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1940 status
= video_outputsw_get();
1944 autosw
= video_autosw_get();
1948 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1949 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
1950 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
1951 if (video_supported
== TPACPI_VIDEO_NEW
)
1952 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
1953 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
1954 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
1955 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
1956 if (video_supported
== TPACPI_VIDEO_NEW
)
1957 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
1958 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
1959 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
1964 static int video_write(char *buf
)
1967 int enable
, disable
, status
;
1970 if (video_supported
== TPACPI_VIDEO_NONE
)
1976 while ((cmd
= next_cmd(&buf
))) {
1977 if (strlencmp(cmd
, "lcd_enable") == 0) {
1978 enable
|= TP_ACPI_VIDEO_S_LCD
;
1979 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1980 disable
|= TP_ACPI_VIDEO_S_LCD
;
1981 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1982 enable
|= TP_ACPI_VIDEO_S_CRT
;
1983 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1984 disable
|= TP_ACPI_VIDEO_S_CRT
;
1985 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1986 strlencmp(cmd
, "dvi_enable") == 0) {
1987 enable
|= TP_ACPI_VIDEO_S_DVI
;
1988 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1989 strlencmp(cmd
, "dvi_disable") == 0) {
1990 disable
|= TP_ACPI_VIDEO_S_DVI
;
1991 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1992 res
= video_autosw_set(1);
1995 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1996 res
= video_autosw_set(0);
1999 } else if (strlencmp(cmd
, "video_switch") == 0) {
2000 res
= video_outputsw_cycle();
2003 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2004 res
= video_expand_toggle();
2011 if (enable
|| disable
) {
2012 status
= video_outputsw_get();
2015 res
= video_outputsw_set((status
& ~disable
) | enable
);
2023 static struct ibm_struct video_driver_data
= {
2026 .write
= video_write
,
2030 /*************************************************************************
2031 * Light (thinklight) subdriver
2034 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2035 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2037 static int __init
light_init(struct ibm_init_struct
*iibm
)
2039 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2041 IBM_ACPIHANDLE_INIT(ledb
);
2042 IBM_ACPIHANDLE_INIT(lght
);
2043 IBM_ACPIHANDLE_INIT(cmos
);
2045 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2046 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2048 if (tp_features
.light
)
2049 /* light status not supported on
2050 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2051 tp_features
.light_status
=
2052 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2054 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2055 str_supported(tp_features
.light
));
2057 return (tp_features
.light
)? 0 : 1;
2060 static int light_read(char *p
)
2065 if (!tp_features
.light
) {
2066 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2067 } else if (!tp_features
.light_status
) {
2068 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2069 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2071 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2073 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2074 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2080 static int light_write(char *buf
)
2082 int cmos_cmd
, lght_cmd
;
2086 if (!tp_features
.light
)
2089 while ((cmd
= next_cmd(&buf
))) {
2090 if (strlencmp(cmd
, "on") == 0) {
2093 } else if (strlencmp(cmd
, "off") == 0) {
2099 success
= cmos_handle
?
2100 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2101 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2109 static struct ibm_struct light_driver_data
= {
2112 .write
= light_write
,
2115 /*************************************************************************
2119 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2121 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2122 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2123 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2124 "\\_SB.PCI.ISA.SLCE", /* 570 */
2125 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2127 /* don't list other alternatives as we install a notify handler on the 570 */
2128 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2130 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2132 .notify
= dock_notify
,
2133 .handle
= &dock_handle
,
2134 .type
= ACPI_SYSTEM_NOTIFY
,
2137 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2138 * We just use it to get notifications of dock hotplug
2139 * in very old thinkpads */
2140 .hid
= PCI_ROOT_HID_STRING
,
2141 .notify
= dock_notify
,
2142 .handle
= &pci_handle
,
2143 .type
= ACPI_SYSTEM_NOTIFY
,
2147 static struct ibm_struct dock_driver_data
[2] = {
2151 .write
= dock_write
,
2152 .acpi
= &ibm_dock_acpidriver
[0],
2156 .acpi
= &ibm_dock_acpidriver
[1],
2160 #define dock_docked() (_sta(dock_handle) & 1)
2162 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2164 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2166 IBM_ACPIHANDLE_INIT(dock
);
2168 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2169 str_supported(dock_handle
!= NULL
));
2171 return (dock_handle
)? 0 : 1;
2174 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2178 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2180 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2181 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2182 IBM_ACPIHANDLE_INIT(pci
);
2183 dock2_needed
= (pci_handle
!= NULL
);
2184 vdbg_printk(TPACPI_DBG_INIT
,
2185 "dock PCI handler for the TP 570 is %s\n",
2186 str_supported(dock2_needed
));
2188 vdbg_printk(TPACPI_DBG_INIT
,
2189 "dock subdriver part 2 not required\n");
2193 return (dock2_needed
)? 0 : 1;
2196 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2198 int docked
= dock_docked();
2199 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, PCI_ROOT_HID_STRING
);
2201 if (event
== 1 && !pci
) /* 570 */
2202 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2203 else if (event
== 1 && pci
) /* 570 */
2204 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2205 else if (event
== 3 && docked
)
2206 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2207 else if (event
== 3 && !docked
)
2208 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
2209 else if (event
== 0 && docked
)
2210 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2212 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2213 event
, _sta(dock_handle
));
2214 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
2218 static int dock_read(char *p
)
2221 int docked
= dock_docked();
2224 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2226 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2228 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2229 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2235 static int dock_write(char *buf
)
2242 while ((cmd
= next_cmd(&buf
))) {
2243 if (strlencmp(cmd
, "undock") == 0) {
2244 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2245 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2247 } else if (strlencmp(cmd
, "dock") == 0) {
2248 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2257 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2259 /*************************************************************************
2263 #ifdef CONFIG_THINKPAD_ACPI_BAY
2264 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2265 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2266 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2267 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2268 ); /* A21e, R30, R31 */
2269 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2270 "_EJ0", /* all others */
2271 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2272 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2273 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2275 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2279 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2281 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2283 IBM_ACPIHANDLE_INIT(bay
);
2285 IBM_ACPIHANDLE_INIT(bay_ej
);
2286 IBM_ACPIHANDLE_INIT(bay2
);
2288 IBM_ACPIHANDLE_INIT(bay2_ej
);
2290 tp_features
.bay_status
= bay_handle
&&
2291 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2292 tp_features
.bay_status2
= bay2_handle
&&
2293 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2295 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2296 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2297 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2298 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2300 vdbg_printk(TPACPI_DBG_INIT
,
2301 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2302 str_supported(tp_features
.bay_status
),
2303 str_supported(tp_features
.bay_eject
),
2304 str_supported(tp_features
.bay_status2
),
2305 str_supported(tp_features
.bay_eject2
));
2307 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2308 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2311 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2313 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
2316 #define bay_occupied(b) (_sta(b##_handle) & 1)
2318 static int bay_read(char *p
)
2321 int occupied
= bay_occupied(bay
);
2322 int occupied2
= bay_occupied(bay2
);
2325 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2326 tp_features
.bay_status
?
2327 (occupied
? "occupied" : "unoccupied") :
2329 if (tp_features
.bay_status2
)
2330 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2331 "occupied" : "unoccupied");
2333 eject
= tp_features
.bay_eject
&& occupied
;
2334 eject2
= tp_features
.bay_eject2
&& occupied2
;
2336 if (eject
&& eject2
)
2337 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2339 len
+= sprintf(p
+ len
, "commands:\teject\n");
2341 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2346 static int bay_write(char *buf
)
2350 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2353 while ((cmd
= next_cmd(&buf
))) {
2354 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2355 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2357 } else if (tp_features
.bay_eject2
&&
2358 strlencmp(cmd
, "eject2") == 0) {
2359 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2368 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2369 .notify
= bay_notify
,
2370 .handle
= &bay_handle
,
2371 .type
= ACPI_SYSTEM_NOTIFY
,
2374 static struct ibm_struct bay_driver_data
= {
2378 .acpi
= &ibm_bay_acpidriver
,
2381 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2383 /*************************************************************************
2387 /* sysfs cmos_command -------------------------------------------------- */
2388 static ssize_t
cmos_command_store(struct device
*dev
,
2389 struct device_attribute
*attr
,
2390 const char *buf
, size_t count
)
2392 unsigned long cmos_cmd
;
2395 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2398 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2399 return (res
)? res
: count
;
2402 static struct device_attribute dev_attr_cmos_command
=
2403 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2405 /* --------------------------------------------------------------------- */
2407 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2411 vdbg_printk(TPACPI_DBG_INIT
,
2412 "initializing cmos commands subdriver\n");
2414 IBM_ACPIHANDLE_INIT(cmos
);
2416 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2417 str_supported(cmos_handle
!= NULL
));
2419 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2423 return (cmos_handle
)? 0 : 1;
2426 static void cmos_exit(void)
2428 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2431 static int cmos_read(char *p
)
2435 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2436 R30, R31, T20-22, X20-21 */
2438 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2440 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2441 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2447 static int cmos_write(char *buf
)
2452 while ((cmd
= next_cmd(&buf
))) {
2453 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2454 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2459 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2467 static struct ibm_struct cmos_driver_data
= {
2470 .write
= cmos_write
,
2474 /*************************************************************************
2478 static enum led_access_mode led_supported
;
2480 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2481 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2482 "LED", /* all others */
2485 static int __init
led_init(struct ibm_init_struct
*iibm
)
2487 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2489 IBM_ACPIHANDLE_INIT(led
);
2492 /* led not supported on R30, R31 */
2493 led_supported
= TPACPI_LED_NONE
;
2494 else if (strlencmp(led_path
, "SLED") == 0)
2496 led_supported
= TPACPI_LED_570
;
2497 else if (strlencmp(led_path
, "SYSL") == 0)
2498 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2499 led_supported
= TPACPI_LED_OLD
;
2502 led_supported
= TPACPI_LED_NEW
;
2504 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2505 str_supported(led_supported
), led_supported
);
2507 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2510 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2512 static int led_read(char *p
)
2516 if (!led_supported
) {
2517 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2520 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2522 if (led_supported
== TPACPI_LED_570
) {
2525 for (i
= 0; i
< 8; i
++) {
2526 if (!acpi_evalf(ec_handle
,
2527 &status
, "GLED", "dd", 1 << i
))
2529 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2530 i
, led_status(status
));
2534 len
+= sprintf(p
+ len
, "commands:\t"
2535 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2540 /* off, on, blink */
2541 static const int led_sled_arg1
[] = { 0, 1, 3 };
2542 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2543 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2544 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2546 static int led_write(char *buf
)
2554 while ((cmd
= next_cmd(&buf
))) {
2555 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2558 if (strstr(cmd
, "off")) {
2560 } else if (strstr(cmd
, "on")) {
2562 } else if (strstr(cmd
, "blink")) {
2567 if (led_supported
== TPACPI_LED_570
) {
2570 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2571 led
, led_sled_arg1
[ind
]))
2573 } else if (led_supported
== TPACPI_LED_OLD
) {
2574 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2576 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2579 ec_write(TPACPI_LED_EC_HLBL
,
2580 led
* led_exp_hlbl
[ind
]);
2583 ec_write(TPACPI_LED_EC_HLCL
,
2584 led
* led_exp_hlcl
[ind
]);
2589 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2590 led
, led_led_arg1
[ind
]))
2598 static struct ibm_struct led_driver_data
= {
2604 /*************************************************************************
2608 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2610 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2612 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2614 IBM_ACPIHANDLE_INIT(beep
);
2616 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2617 str_supported(beep_handle
!= NULL
));
2619 return (beep_handle
)? 0 : 1;
2622 static int beep_read(char *p
)
2627 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2629 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2630 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2636 static int beep_write(char *buf
)
2644 while ((cmd
= next_cmd(&buf
))) {
2645 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2646 beep_cmd
>= 0 && beep_cmd
<= 17) {
2650 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2657 static struct ibm_struct beep_driver_data
= {
2660 .write
= beep_write
,
2663 /*************************************************************************
2667 static enum thermal_access_mode thermal_read_mode
;
2669 /* sysfs temp##_input -------------------------------------------------- */
2671 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2672 struct device_attribute
*attr
,
2675 struct sensor_device_attribute
*sensor_attr
=
2676 to_sensor_dev_attr(attr
);
2677 int idx
= sensor_attr
->index
;
2681 res
= thermal_get_sensor(idx
, &value
);
2684 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2687 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2690 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2691 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2693 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2694 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2695 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2696 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2697 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2698 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2699 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2700 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2701 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2702 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2703 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2704 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2705 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2706 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2707 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2708 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2709 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2712 #define THERMAL_ATTRS(X) \
2713 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2715 static struct attribute
*thermal_temp_input_attr
[] = {
2735 static const struct attribute_group thermal_temp_input16_group
= {
2736 .attrs
= thermal_temp_input_attr
2739 static const struct attribute_group thermal_temp_input8_group
= {
2740 .attrs
= &thermal_temp_input_attr
[8]
2743 #undef THERMAL_SENSOR_ATTR_TEMP
2744 #undef THERMAL_ATTRS
2746 /* --------------------------------------------------------------------- */
2748 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2755 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2757 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2759 if (thinkpad_id
.ec_model
) {
2761 * Direct EC access mode: sensors at registers
2762 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2763 * non-implemented, thermal sensors return 0x80 when
2768 for (i
= 0; i
< 8; i
++) {
2769 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2775 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2783 /* This is sheer paranoia, but we handle it anyway */
2786 "ThinkPad ACPI EC access misbehaving, "
2787 "falling back to ACPI TMPx access mode\n");
2788 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2791 "ThinkPad ACPI EC access misbehaving, "
2792 "disabling thermal sensors access\n");
2793 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2798 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2800 } else if (acpi_tmp7
) {
2801 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2802 /* 600e/x, 770e, 770x */
2803 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2805 /* Standard ACPI TMPx access, max 8 sensors */
2806 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2809 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2810 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2813 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2814 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2817 switch(thermal_read_mode
) {
2818 case TPACPI_THERMAL_TPEC_16
:
2819 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2820 &thermal_temp_input16_group
);
2824 case TPACPI_THERMAL_TPEC_8
:
2825 case TPACPI_THERMAL_ACPI_TMP07
:
2826 case TPACPI_THERMAL_ACPI_UPDT
:
2827 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2828 &thermal_temp_input8_group
);
2832 case TPACPI_THERMAL_NONE
:
2840 static void thermal_exit(void)
2842 switch(thermal_read_mode
) {
2843 case TPACPI_THERMAL_TPEC_16
:
2844 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2845 &thermal_temp_input16_group
);
2847 case TPACPI_THERMAL_TPEC_8
:
2848 case TPACPI_THERMAL_ACPI_TMP07
:
2849 case TPACPI_THERMAL_ACPI_UPDT
:
2850 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2851 &thermal_temp_input16_group
);
2853 case TPACPI_THERMAL_NONE
:
2859 /* idx is zero-based */
2860 static int thermal_get_sensor(int idx
, s32
*value
)
2866 t
= TP_EC_THERMAL_TMP0
;
2868 switch (thermal_read_mode
) {
2869 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2870 case TPACPI_THERMAL_TPEC_16
:
2871 if (idx
>= 8 && idx
<= 15) {
2872 t
= TP_EC_THERMAL_TMP8
;
2877 case TPACPI_THERMAL_TPEC_8
:
2879 if (!acpi_ec_read(t
+ idx
, &tmp
))
2881 *value
= tmp
* 1000;
2886 case TPACPI_THERMAL_ACPI_UPDT
:
2888 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2889 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2891 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2893 *value
= (t
- 2732) * 100;
2898 case TPACPI_THERMAL_ACPI_TMP07
:
2900 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2901 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2903 if (t
> 127 || t
< -127)
2904 t
= TP_EC_THERMAL_TMP_NA
;
2910 case TPACPI_THERMAL_NONE
:
2918 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2929 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2932 for(i
= 0 ; i
< n
; i
++) {
2933 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
2941 static int thermal_read(char *p
)
2945 struct ibm_thermal_sensors_struct t
;
2947 n
= thermal_get_sensors(&t
);
2948 if (unlikely(n
< 0))
2951 len
+= sprintf(p
+ len
, "temperatures:\t");
2954 for (i
= 0; i
< (n
- 1); i
++)
2955 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
2956 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
2958 len
+= sprintf(p
+ len
, "not supported\n");
2963 static struct ibm_struct thermal_driver_data
= {
2965 .read
= thermal_read
,
2966 .exit
= thermal_exit
,
2969 /*************************************************************************
2973 static u8 ecdump_regs
[256];
2975 static int ecdump_read(char *p
)
2981 len
+= sprintf(p
+ len
, "EC "
2982 " +00 +01 +02 +03 +04 +05 +06 +07"
2983 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2984 for (i
= 0; i
< 256; i
+= 16) {
2985 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
2986 for (j
= 0; j
< 16; j
++) {
2987 if (!acpi_ec_read(i
+ j
, &v
))
2989 if (v
!= ecdump_regs
[i
+ j
])
2990 len
+= sprintf(p
+ len
, " *%02x", v
);
2992 len
+= sprintf(p
+ len
, " %02x", v
);
2993 ecdump_regs
[i
+ j
] = v
;
2995 len
+= sprintf(p
+ len
, "\n");
3000 /* These are way too dangerous to advertise openly... */
3002 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3003 " (<offset> is 00-ff, <value> is 00-ff)\n");
3004 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3005 " (<offset> is 00-ff, <value> is 0-255)\n");
3010 static int ecdump_write(char *buf
)
3015 while ((cmd
= next_cmd(&buf
))) {
3016 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3018 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3022 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3023 if (!acpi_ec_write(i
, v
))
3032 static struct ibm_struct ecdump_driver_data
= {
3034 .read
= ecdump_read
,
3035 .write
= ecdump_write
,
3036 .flags
.experimental
= 1,
3039 /*************************************************************************
3040 * Backlight/brightness subdriver
3043 static struct backlight_device
*ibm_backlight_device
;
3045 static struct backlight_ops ibm_backlight_data
= {
3046 .get_brightness
= brightness_get
,
3047 .update_status
= brightness_update_status
,
3050 static struct mutex brightness_mutex
;
3052 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
3056 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
3058 mutex_init(&brightness_mutex
);
3060 if (!brightness_mode
) {
3061 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
3062 brightness_mode
= 2;
3064 brightness_mode
= 3;
3066 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
3070 if (brightness_mode
> 3)
3073 b
= brightness_get(NULL
);
3077 ibm_backlight_device
= backlight_device_register(
3078 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
3079 &ibm_backlight_data
);
3080 if (IS_ERR(ibm_backlight_device
)) {
3081 printk(IBM_ERR
"Could not register backlight device\n");
3082 return PTR_ERR(ibm_backlight_device
);
3084 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
3086 ibm_backlight_device
->props
.max_brightness
= 7;
3087 ibm_backlight_device
->props
.brightness
= b
;
3088 backlight_update_status(ibm_backlight_device
);
3093 static void brightness_exit(void)
3095 if (ibm_backlight_device
) {
3096 vdbg_printk(TPACPI_DBG_EXIT
,
3097 "calling backlight_device_unregister()\n");
3098 backlight_device_unregister(ibm_backlight_device
);
3099 ibm_backlight_device
= NULL
;
3103 static int brightness_update_status(struct backlight_device
*bd
)
3105 return brightness_set(
3106 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
3107 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
3108 bd
->props
.brightness
: 0);
3112 * ThinkPads can read brightness from two places: EC 0x31, or
3113 * CMOS NVRAM byte 0x5E, bits 0-3.
3115 static int brightness_get(struct backlight_device
*bd
)
3117 u8 lec
= 0, lcmos
= 0, level
= 0;
3119 if (brightness_mode
& 1) {
3120 if (!acpi_ec_read(brightness_offset
, &lec
))
3125 if (brightness_mode
& 2) {
3126 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3127 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3128 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3132 if (brightness_mode
== 3 && lec
!= lcmos
) {
3134 "CMOS NVRAM (%u) and EC (%u) do not agree "
3135 "on display brightness level\n",
3136 (unsigned int) lcmos
,
3137 (unsigned int) lec
);
3144 static int brightness_set(int value
)
3146 int cmos_cmd
, inc
, i
, res
;
3152 res
= mutex_lock_interruptible(&brightness_mutex
);
3156 current_value
= brightness_get(NULL
);
3157 if (current_value
< 0) {
3158 res
= current_value
;
3162 cmos_cmd
= value
> current_value
?
3163 TP_CMOS_BRIGHTNESS_UP
:
3164 TP_CMOS_BRIGHTNESS_DOWN
;
3165 inc
= value
> current_value
? 1 : -1;
3168 for (i
= current_value
; i
!= value
; i
+= inc
) {
3169 if ((brightness_mode
& 2) &&
3170 issue_thinkpad_cmos_command(cmos_cmd
)) {
3174 if ((brightness_mode
& 1) &&
3175 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
3182 mutex_unlock(&brightness_mutex
);
3186 static int brightness_read(char *p
)
3191 if ((level
= brightness_get(NULL
)) < 0) {
3192 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3194 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
3195 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3196 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3197 " (<level> is 0-7)\n");
3203 static int brightness_write(char *buf
)
3209 while ((cmd
= next_cmd(&buf
))) {
3210 if ((level
= brightness_get(NULL
)) < 0)
3214 if (strlencmp(cmd
, "up") == 0) {
3215 new_level
= level
== 7 ? 7 : level
+ 1;
3216 } else if (strlencmp(cmd
, "down") == 0) {
3217 new_level
= level
== 0 ? 0 : level
- 1;
3218 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3219 new_level
>= 0 && new_level
<= 7) {
3224 brightness_set(new_level
);
3230 static struct ibm_struct brightness_driver_data
= {
3231 .name
= "brightness",
3232 .read
= brightness_read
,
3233 .write
= brightness_write
,
3234 .exit
= brightness_exit
,
3237 /*************************************************************************
3241 static int volume_read(char *p
)
3246 if (!acpi_ec_read(volume_offset
, &level
)) {
3247 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3249 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3250 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3251 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3252 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3253 " (<level> is 0-15)\n");
3259 static int volume_write(char *buf
)
3261 int cmos_cmd
, inc
, i
;
3263 int new_level
, new_mute
;
3266 while ((cmd
= next_cmd(&buf
))) {
3267 if (!acpi_ec_read(volume_offset
, &level
))
3269 new_mute
= mute
= level
& 0x40;
3270 new_level
= level
= level
& 0xf;
3272 if (strlencmp(cmd
, "up") == 0) {
3276 new_level
= level
== 15 ? 15 : level
+ 1;
3277 } else if (strlencmp(cmd
, "down") == 0) {
3281 new_level
= level
== 0 ? 0 : level
- 1;
3282 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3283 new_level
>= 0 && new_level
<= 15) {
3285 } else if (strlencmp(cmd
, "mute") == 0) {
3290 if (new_level
!= level
) { /* mute doesn't change */
3291 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3292 inc
= new_level
> level
? 1 : -1;
3294 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3295 !acpi_ec_write(volume_offset
, level
)))
3298 for (i
= level
; i
!= new_level
; i
+= inc
)
3299 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3300 !acpi_ec_write(volume_offset
, i
+ inc
))
3303 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3304 !acpi_ec_write(volume_offset
,
3309 if (new_mute
!= mute
) { /* level doesn't change */
3310 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3312 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3313 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3321 static struct ibm_struct volume_driver_data
= {
3323 .read
= volume_read
,
3324 .write
= volume_write
,
3327 /*************************************************************************
3334 * TPACPI_FAN_RD_ACPI_GFAN:
3335 * ACPI GFAN method: returns fan level
3337 * see TPACPI_FAN_WR_ACPI_SFAN
3338 * EC 0x2f (HFSP) not available if GFAN exists
3340 * TPACPI_FAN_WR_ACPI_SFAN:
3341 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3343 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3346 * TPACPI_FAN_WR_TPEC:
3347 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3348 * Supported on almost all ThinkPads
3350 * Fan speed changes of any sort (including those caused by the
3351 * disengaged mode) are usually done slowly by the firmware as the
3352 * maximum ammount of fan duty cycle change per second seems to be
3355 * Reading is not available if GFAN exists.
3356 * Writing is not available if SFAN exists.
3359 * 7 automatic mode engaged;
3360 * (default operation mode of the ThinkPad)
3361 * fan level is ignored in this mode.
3362 * 6 full speed mode (takes precedence over bit 7);
3363 * not available on all thinkpads. May disable
3364 * the tachometer while the fan controller ramps up
3365 * the speed (which can take up to a few *minutes*).
3366 * Speeds up fan to 100% duty-cycle, which is far above
3367 * the standard RPM levels. It is not impossible that
3368 * it could cause hardware damage.
3369 * 5-3 unused in some models. Extra bits for fan level
3370 * in others, but still useless as all values above
3371 * 7 map to the same speed as level 7 in these models.
3372 * 2-0 fan level (0..7 usually)
3374 * 0x07 = max (set when temperatures critical)
3375 * Some ThinkPads may have other levels, see
3376 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3378 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3379 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3380 * does so, its initial value is meaningless (0x07).
3382 * For firmware bugs, refer to:
3383 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3387 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3388 * Main fan tachometer reading (in RPM)
3390 * This register is present on all ThinkPads with a new-style EC, and
3391 * it is known not to be present on the A21m/e, and T22, as there is
3392 * something else in offset 0x84 according to the ACPI DSDT. Other
3393 * ThinkPads from this same time period (and earlier) probably lack the
3394 * tachometer as well.
3396 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3397 * was never fixed by IBM to report the EC firmware version string
3398 * probably support the tachometer (like the early X models), so
3399 * detecting it is quite hard. We need more data to know for sure.
3401 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3404 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3407 * For firmware bugs, refer to:
3408 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3410 * TPACPI_FAN_WR_ACPI_FANS:
3411 * ThinkPad X31, X40, X41. Not available in the X60.
3413 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3414 * high speed. ACPI DSDT seems to map these three speeds to levels
3415 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3416 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3418 * The speeds are stored on handles
3419 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3421 * There are three default speed sets, acessible as handles:
3422 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3424 * ACPI DSDT switches which set is in use depending on various
3427 * TPACPI_FAN_WR_TPEC is also available and should be used to
3428 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3429 * but the ACPI tables just mention level 7.
3432 static enum fan_status_access_mode fan_status_access_mode
;
3433 static enum fan_control_access_mode fan_control_access_mode
;
3434 static enum fan_control_commands fan_control_commands
;
3436 static u8 fan_control_initial_status
;
3437 static u8 fan_control_desired_level
;
3439 static void fan_watchdog_fire(struct work_struct
*ignored
);
3440 static int fan_watchdog_maxinterval
;
3441 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3443 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3444 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3445 "\\FSPD", /* 600e/x, 770e, 770x */
3447 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3448 "JFNS", /* 770x-JL */
3452 * SYSFS fan layout: hwmon compatible (device)
3455 * 0: "disengaged" mode
3457 * 2: native EC "auto" mode (recommended, hardware default)
3459 * pwm*: set speed in manual mode, ignored otherwise.
3460 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3463 * fan*_input: tachometer reading, RPM
3466 * SYSFS fan layout: extensions
3468 * fan_watchdog (driver):
3469 * fan watchdog interval in seconds, 0 disables (default), max 120
3472 /* sysfs fan pwm1_enable ----------------------------------------------- */
3473 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3474 struct device_attribute
*attr
,
3480 res
= fan_get_status_safe(&status
);
3484 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3485 if (status
!= fan_control_initial_status
) {
3486 tp_features
.fan_ctrl_status_undef
= 0;
3488 /* Return most likely status. In fact, it
3489 * might be the only possible status */
3490 status
= TP_EC_FAN_AUTO
;
3494 if (status
& TP_EC_FAN_FULLSPEED
) {
3496 } else if (status
& TP_EC_FAN_AUTO
) {
3501 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3504 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3505 struct device_attribute
*attr
,
3506 const char *buf
, size_t count
)
3511 if (parse_strtoul(buf
, 2, &t
))
3516 level
= TP_EC_FAN_FULLSPEED
;
3519 level
= TPACPI_FAN_LAST_LEVEL
;
3522 level
= TP_EC_FAN_AUTO
;
3525 /* reserved for software-controlled auto mode */
3531 res
= fan_set_level_safe(level
);
3537 fan_watchdog_reset();
3542 static struct device_attribute dev_attr_fan_pwm1_enable
=
3543 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3544 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3546 /* sysfs fan pwm1 ------------------------------------------------------ */
3547 static ssize_t
fan_pwm1_show(struct device
*dev
,
3548 struct device_attribute
*attr
,
3554 res
= fan_get_status_safe(&status
);
3558 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3559 if (status
!= fan_control_initial_status
) {
3560 tp_features
.fan_ctrl_status_undef
= 0;
3562 status
= TP_EC_FAN_AUTO
;
3567 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3568 status
= fan_control_desired_level
;
3573 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3576 static ssize_t
fan_pwm1_store(struct device
*dev
,
3577 struct device_attribute
*attr
,
3578 const char *buf
, size_t count
)
3582 u8 status
, newlevel
;
3584 if (parse_strtoul(buf
, 255, &s
))
3587 /* scale down from 0-255 to 0-7 */
3588 newlevel
= (s
>> 5) & 0x07;
3590 rc
= mutex_lock_interruptible(&fan_mutex
);
3594 rc
= fan_get_status(&status
);
3595 if (!rc
&& (status
&
3596 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3597 rc
= fan_set_level(newlevel
);
3601 fan_update_desired_level(newlevel
);
3602 fan_watchdog_reset();
3606 mutex_unlock(&fan_mutex
);
3607 return (rc
)? rc
: count
;
3610 static struct device_attribute dev_attr_fan_pwm1
=
3611 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3612 fan_pwm1_show
, fan_pwm1_store
);
3614 /* sysfs fan fan1_input ------------------------------------------------ */
3615 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3616 struct device_attribute
*attr
,
3622 res
= fan_get_speed(&speed
);
3626 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3629 static struct device_attribute dev_attr_fan_fan1_input
=
3630 __ATTR(fan1_input
, S_IRUGO
,
3631 fan_fan1_input_show
, NULL
);
3633 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
3634 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3637 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3640 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3641 const char *buf
, size_t count
)
3645 if (parse_strtoul(buf
, 120, &t
))
3648 if (!fan_control_allowed
)
3651 fan_watchdog_maxinterval
= t
;
3652 fan_watchdog_reset();
3657 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3658 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3660 /* --------------------------------------------------------------------- */
3661 static struct attribute
*fan_attributes
[] = {
3662 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3663 &dev_attr_fan_fan1_input
.attr
,
3667 static const struct attribute_group fan_attr_group
= {
3668 .attrs
= fan_attributes
,
3671 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3675 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3677 mutex_init(&fan_mutex
);
3678 fan_status_access_mode
= TPACPI_FAN_NONE
;
3679 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3680 fan_control_commands
= 0;
3681 fan_watchdog_maxinterval
= 0;
3682 tp_features
.fan_ctrl_status_undef
= 0;
3683 fan_control_desired_level
= 7;
3685 IBM_ACPIHANDLE_INIT(fans
);
3686 IBM_ACPIHANDLE_INIT(gfan
);
3687 IBM_ACPIHANDLE_INIT(sfan
);
3690 /* 570, 600e/x, 770e, 770x */
3691 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3693 /* all other ThinkPads: note that even old-style
3694 * ThinkPad ECs supports the fan control register */
3695 if (likely(acpi_ec_read(fan_status_offset
,
3696 &fan_control_initial_status
))) {
3697 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3699 /* In some ThinkPads, neither the EC nor the ACPI
3700 * DSDT initialize the fan status, and it ends up
3701 * being set to 0x07 when it *could* be either
3704 * Enable for TP-1Y (T43), TP-78 (R51e),
3705 * TP-76 (R52), TP-70 (T43, R52), which are known
3707 if (fan_control_initial_status
== 0x07) {
3708 switch (thinkpad_id
.ec_model
) {
3709 case 0x5931: /* TP-1Y */
3710 case 0x3837: /* TP-78 */
3711 case 0x3637: /* TP-76 */
3712 case 0x3037: /* TP-70 */
3714 "fan_init: initial fan status is "
3715 "unknown, assuming it is in auto "
3717 tp_features
.fan_ctrl_status_undef
= 1;
3723 "ThinkPad ACPI EC access misbehaving, "
3724 "fan status and control unavailable\n");
3731 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3732 fan_control_commands
|=
3733 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3736 /* gfan without sfan means no fan control */
3737 /* all other models implement TP EC 0x2f control */
3741 fan_control_access_mode
=
3742 TPACPI_FAN_WR_ACPI_FANS
;
3743 fan_control_commands
|=
3744 TPACPI_FAN_CMD_SPEED
|
3745 TPACPI_FAN_CMD_LEVEL
|
3746 TPACPI_FAN_CMD_ENABLE
;
3748 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3749 fan_control_commands
|=
3750 TPACPI_FAN_CMD_LEVEL
|
3751 TPACPI_FAN_CMD_ENABLE
;
3756 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3757 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3758 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3759 fan_status_access_mode
, fan_control_access_mode
);
3761 /* fan control master switch */
3762 if (!fan_control_allowed
) {
3763 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3764 fan_control_commands
= 0;
3765 dbg_printk(TPACPI_DBG_INIT
,
3766 "fan control features disabled by parameter\n");
3769 /* update fan_control_desired_level */
3770 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3771 fan_get_status_safe(NULL
);
3773 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3774 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3775 rc
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3778 rc
= driver_create_file(&tpacpi_pdriver
.driver
,
3779 &driver_attr_fan_watchdog
);
3788 * Call with fan_mutex held
3790 static void fan_update_desired_level(u8 status
)
3793 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3795 fan_control_desired_level
= 7;
3797 fan_control_desired_level
= status
;
3801 static int fan_get_status(u8
*status
)
3806 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3808 switch (fan_status_access_mode
) {
3809 case TPACPI_FAN_RD_ACPI_GFAN
:
3810 /* 570, 600e/x, 770e, 770x */
3812 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
3820 case TPACPI_FAN_RD_TPEC
:
3821 /* all except 570, 600e/x, 770e, 770x */
3822 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
3837 static int fan_get_status_safe(u8
*status
)
3842 rc
= mutex_lock_interruptible(&fan_mutex
);
3845 rc
= fan_get_status(&s
);
3847 fan_update_desired_level(s
);
3848 mutex_unlock(&fan_mutex
);
3856 static void fan_exit(void)
3858 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
3860 /* FIXME: can we really do this unconditionally? */
3861 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
, &fan_attr_group
);
3862 driver_remove_file(&tpacpi_pdriver
.driver
, &driver_attr_fan_watchdog
);
3864 cancel_delayed_work(&fan_watchdog_task
);
3865 flush_scheduled_work();
3868 static int fan_get_speed(unsigned int *speed
)
3872 switch (fan_status_access_mode
) {
3873 case TPACPI_FAN_RD_TPEC
:
3874 /* all except 570, 600e/x, 770e, 770x */
3875 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
3876 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
3880 *speed
= (hi
<< 8) | lo
;
3891 static void fan_watchdog_fire(struct work_struct
*ignored
)
3895 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
3896 rc
= fan_set_enable();
3898 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
3899 "will try again later...\n", -rc
);
3900 /* reschedule for later */
3901 fan_watchdog_reset();
3905 static void fan_watchdog_reset(void)
3907 static int fan_watchdog_active
;
3909 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
3912 if (fan_watchdog_active
)
3913 cancel_delayed_work(&fan_watchdog_task
);
3915 if (fan_watchdog_maxinterval
> 0) {
3916 fan_watchdog_active
= 1;
3917 if (!schedule_delayed_work(&fan_watchdog_task
,
3918 msecs_to_jiffies(fan_watchdog_maxinterval
3920 printk(IBM_ERR
"failed to schedule the fan watchdog, "
3921 "watchdog will not trigger\n");
3924 fan_watchdog_active
= 0;
3927 static int fan_set_level(int level
)
3929 if (!fan_control_allowed
)
3932 switch (fan_control_access_mode
) {
3933 case TPACPI_FAN_WR_ACPI_SFAN
:
3934 if (level
>= 0 && level
<= 7) {
3935 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
3941 case TPACPI_FAN_WR_ACPI_FANS
:
3942 case TPACPI_FAN_WR_TPEC
:
3943 if ((level
!= TP_EC_FAN_AUTO
) &&
3944 (level
!= TP_EC_FAN_FULLSPEED
) &&
3945 ((level
< 0) || (level
> 7)))
3948 /* safety net should the EC not support AUTO
3949 * or FULLSPEED mode bits and just ignore them */
3950 if (level
& TP_EC_FAN_FULLSPEED
)
3951 level
|= 7; /* safety min speed 7 */
3952 else if (level
& TP_EC_FAN_FULLSPEED
)
3953 level
|= 4; /* safety min speed 4 */
3955 if (!acpi_ec_write(fan_status_offset
, level
))
3958 tp_features
.fan_ctrl_status_undef
= 0;
3967 static int fan_set_level_safe(int level
)
3971 if (!fan_control_allowed
)
3974 rc
= mutex_lock_interruptible(&fan_mutex
);
3978 if (level
== TPACPI_FAN_LAST_LEVEL
)
3979 level
= fan_control_desired_level
;
3981 rc
= fan_set_level(level
);
3983 fan_update_desired_level(level
);
3985 mutex_unlock(&fan_mutex
);
3989 static int fan_set_enable(void)
3994 if (!fan_control_allowed
)
3997 rc
= mutex_lock_interruptible(&fan_mutex
);
4001 switch (fan_control_access_mode
) {
4002 case TPACPI_FAN_WR_ACPI_FANS
:
4003 case TPACPI_FAN_WR_TPEC
:
4004 rc
= fan_get_status(&s
);
4008 /* Don't go out of emergency fan mode */
4011 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4014 if (!acpi_ec_write(fan_status_offset
, s
))
4017 tp_features
.fan_ctrl_status_undef
= 0;
4022 case TPACPI_FAN_WR_ACPI_SFAN
:
4023 rc
= fan_get_status(&s
);
4029 /* Set fan to at least level 4 */
4032 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4042 mutex_unlock(&fan_mutex
);
4046 static int fan_set_disable(void)
4050 if (!fan_control_allowed
)
4053 rc
= mutex_lock_interruptible(&fan_mutex
);
4058 switch (fan_control_access_mode
) {
4059 case TPACPI_FAN_WR_ACPI_FANS
:
4060 case TPACPI_FAN_WR_TPEC
:
4061 if (!acpi_ec_write(fan_status_offset
, 0x00))
4064 fan_control_desired_level
= 0;
4065 tp_features
.fan_ctrl_status_undef
= 0;
4069 case TPACPI_FAN_WR_ACPI_SFAN
:
4070 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4073 fan_control_desired_level
= 0;
4081 mutex_unlock(&fan_mutex
);
4085 static int fan_set_speed(int speed
)
4089 if (!fan_control_allowed
)
4092 rc
= mutex_lock_interruptible(&fan_mutex
);
4097 switch (fan_control_access_mode
) {
4098 case TPACPI_FAN_WR_ACPI_FANS
:
4099 if (speed
>= 0 && speed
<= 65535) {
4100 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4101 speed
, speed
, speed
))
4111 mutex_unlock(&fan_mutex
);
4115 static int fan_read(char *p
)
4120 unsigned int speed
= 0;
4122 switch (fan_status_access_mode
) {
4123 case TPACPI_FAN_RD_ACPI_GFAN
:
4124 /* 570, 600e/x, 770e, 770x */
4125 if ((rc
= fan_get_status_safe(&status
)) < 0)
4128 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
4130 (status
!= 0) ? "enabled" : "disabled", status
);
4133 case TPACPI_FAN_RD_TPEC
:
4134 /* all except 570, 600e/x, 770e, 770x */
4135 if ((rc
= fan_get_status_safe(&status
)) < 0)
4138 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4139 if (status
!= fan_control_initial_status
)
4140 tp_features
.fan_ctrl_status_undef
= 0;
4142 /* Return most likely status. In fact, it
4143 * might be the only possible status */
4144 status
= TP_EC_FAN_AUTO
;
4147 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4148 (status
!= 0) ? "enabled" : "disabled");
4150 if ((rc
= fan_get_speed(&speed
)) < 0)
4153 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
4155 if (status
& TP_EC_FAN_FULLSPEED
)
4156 /* Disengaged mode takes precedence */
4157 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
4158 else if (status
& TP_EC_FAN_AUTO
)
4159 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
4161 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
4164 case TPACPI_FAN_NONE
:
4166 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4169 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
4170 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
4172 switch (fan_control_access_mode
) {
4173 case TPACPI_FAN_WR_ACPI_SFAN
:
4174 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4178 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4179 "auto, disengaged, full-speed)\n");
4184 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4185 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4186 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4187 "1-120 (seconds))\n");
4189 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4190 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4191 " (<speed> is 0-65535)\n");
4196 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4200 if (strlencmp(cmd
, "level auto") == 0)
4201 level
= TP_EC_FAN_AUTO
;
4202 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4203 (strlencmp(cmd
, "level full-speed") == 0))
4204 level
= TP_EC_FAN_FULLSPEED
;
4205 else if (sscanf(cmd
, "level %d", &level
) != 1)
4208 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4209 printk(IBM_ERR
"level command accepted for unsupported "
4210 "access mode %d", fan_control_access_mode
);
4215 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4217 if (strlencmp(cmd
, "enable") != 0)
4220 if ((*rc
= fan_set_enable()) == -ENXIO
)
4221 printk(IBM_ERR
"enable command accepted for unsupported "
4222 "access mode %d", fan_control_access_mode
);
4227 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4229 if (strlencmp(cmd
, "disable") != 0)
4232 if ((*rc
= fan_set_disable()) == -ENXIO
)
4233 printk(IBM_ERR
"disable command accepted for unsupported "
4234 "access mode %d", fan_control_access_mode
);
4239 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4244 * Support speed <low> <medium> <high> ? */
4246 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4249 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4250 printk(IBM_ERR
"speed command accepted for unsupported "
4251 "access mode %d", fan_control_access_mode
);
4256 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4260 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4263 if (interval
< 0 || interval
> 120)
4266 fan_watchdog_maxinterval
= interval
;
4271 static int fan_write(char *buf
)
4276 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4277 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4278 fan_write_cmd_level(cmd
, &rc
)) &&
4279 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4280 (fan_write_cmd_enable(cmd
, &rc
) ||
4281 fan_write_cmd_disable(cmd
, &rc
) ||
4282 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4283 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4284 fan_write_cmd_speed(cmd
, &rc
))
4288 fan_watchdog_reset();
4294 static struct ibm_struct fan_driver_data
= {
4301 /****************************************************************************
4302 ****************************************************************************
4306 ****************************************************************************
4307 ****************************************************************************/
4310 static struct proc_dir_entry
*proc_dir
;
4312 /* Subdriver registry */
4313 static LIST_HEAD(tpacpi_all_drivers
);
4317 * Module and infrastructure proble, init and exit handling
4320 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4321 static const char * __init
str_supported(int is_supported
)
4323 static char text_unsupported
[] __initdata
= "not supported";
4325 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4327 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4329 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4332 struct ibm_struct
*ibm
= iibm
->data
;
4333 struct proc_dir_entry
*entry
;
4335 BUG_ON(ibm
== NULL
);
4337 INIT_LIST_HEAD(&ibm
->all_drivers
);
4339 if (ibm
->flags
.experimental
&& !experimental
)
4342 dbg_printk(TPACPI_DBG_INIT
,
4343 "probing for %s\n", ibm
->name
);
4346 ret
= iibm
->init(iibm
);
4348 return 0; /* probe failed */
4352 ibm
->flags
.init_called
= 1;
4356 if (ibm
->acpi
->hid
) {
4357 ret
= register_tpacpi_subdriver(ibm
);
4362 if (ibm
->acpi
->notify
) {
4363 ret
= setup_acpi_notify(ibm
);
4364 if (ret
== -ENODEV
) {
4365 printk(IBM_NOTICE
"disabling subdriver %s\n",
4375 dbg_printk(TPACPI_DBG_INIT
,
4376 "%s installed\n", ibm
->name
);
4379 entry
= create_proc_entry(ibm
->name
,
4380 S_IFREG
| S_IRUGO
| S_IWUSR
,
4383 printk(IBM_ERR
"unable to create proc entry %s\n",
4388 entry
->owner
= THIS_MODULE
;
4390 entry
->read_proc
= &dispatch_procfs_read
;
4392 entry
->write_proc
= &dispatch_procfs_write
;
4393 ibm
->flags
.proc_created
= 1;
4396 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4401 dbg_printk(TPACPI_DBG_INIT
,
4402 "%s: at error exit path with result %d\n",
4406 return (ret
< 0)? ret
: 0;
4409 static void ibm_exit(struct ibm_struct
*ibm
)
4411 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4413 list_del_init(&ibm
->all_drivers
);
4415 if (ibm
->flags
.acpi_notify_installed
) {
4416 dbg_printk(TPACPI_DBG_EXIT
,
4417 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4419 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4421 dispatch_acpi_notify
);
4422 ibm
->flags
.acpi_notify_installed
= 0;
4423 ibm
->flags
.acpi_notify_installed
= 0;
4426 if (ibm
->flags
.proc_created
) {
4427 dbg_printk(TPACPI_DBG_EXIT
,
4428 "%s: remove_proc_entry\n", ibm
->name
);
4429 remove_proc_entry(ibm
->name
, proc_dir
);
4430 ibm
->flags
.proc_created
= 0;
4433 if (ibm
->flags
.acpi_driver_registered
) {
4434 dbg_printk(TPACPI_DBG_EXIT
,
4435 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4437 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4438 kfree(ibm
->acpi
->driver
);
4439 ibm
->acpi
->driver
= NULL
;
4440 ibm
->flags
.acpi_driver_registered
= 0;
4443 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4445 ibm
->flags
.init_called
= 0;
4448 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4453 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
4455 struct dmi_device
*dev
= NULL
;
4456 char ec_fw_string
[18];
4461 memset(tp
, 0, sizeof(*tp
));
4463 if (dmi_name_in_vendors("IBM"))
4464 tp
->vendor
= PCI_VENDOR_ID_IBM
;
4465 else if (dmi_name_in_vendors("LENOVO"))
4466 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
4470 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
4472 if (!tp
->bios_version_str
)
4474 tp
->bios_model
= tp
->bios_version_str
[0]
4475 | (tp
->bios_version_str
[1] << 8);
4478 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4479 * X32 or newer, all Z series; Some models must have an
4480 * up-to-date BIOS or they will not be detected.
4482 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4484 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4485 if (sscanf(dev
->name
,
4486 "IBM ThinkPad Embedded Controller -[%17c",
4487 ec_fw_string
) == 1) {
4488 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4489 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4491 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
4492 tp
->ec_model
= ec_fw_string
[0]
4493 | (ec_fw_string
[1] << 8);
4498 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
4500 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
4501 kfree(tp
->model_str
);
4502 tp
->model_str
= NULL
;
4506 static int __init
probe_for_thinkpad(void)
4514 * Non-ancient models have better DMI tagging, but very old models
4517 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
4519 /* ec is required because many other handles are relative to it */
4520 IBM_ACPIHANDLE_INIT(ec
);
4524 "Not yet supported ThinkPad detected!\n");
4529 * Risks a regression on very old machines, but reduces potential
4530 * false positives a damn great deal
4533 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
4535 if (!is_thinkpad
&& !force_load
)
4542 /* Module init, exit, parameters */
4544 static struct ibm_init_struct ibms_init
[] __initdata
= {
4546 .init
= thinkpad_acpi_driver_init
,
4547 .data
= &thinkpad_acpi_driver_data
,
4550 .init
= hotkey_init
,
4551 .data
= &hotkey_driver_data
,
4554 .init
= bluetooth_init
,
4555 .data
= &bluetooth_driver_data
,
4559 .data
= &wan_driver_data
,
4563 .data
= &video_driver_data
,
4567 .data
= &light_driver_data
,
4569 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4572 .data
= &dock_driver_data
[0],
4576 .data
= &dock_driver_data
[1],
4579 #ifdef CONFIG_THINKPAD_ACPI_BAY
4582 .data
= &bay_driver_data
,
4587 .data
= &cmos_driver_data
,
4591 .data
= &led_driver_data
,
4595 .data
= &beep_driver_data
,
4598 .init
= thermal_init
,
4599 .data
= &thermal_driver_data
,
4602 .data
= &ecdump_driver_data
,
4605 .init
= brightness_init
,
4606 .data
= &brightness_driver_data
,
4609 .data
= &volume_driver_data
,
4613 .data
= &fan_driver_data
,
4617 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4620 struct ibm_struct
*ibm
;
4622 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4623 ibm
= ibms_init
[i
].data
;
4624 BUG_ON(ibm
== NULL
);
4626 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4627 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4629 strcpy(ibms_init
[i
].param
, val
);
4630 strcat(ibms_init
[i
].param
, ",");
4638 static int experimental
;
4639 module_param(experimental
, int, 0);
4641 static u32 dbg_level
;
4642 module_param_named(debug
, dbg_level
, uint
, 0);
4644 static int force_load
;
4645 module_param(force_load
, bool, 0);
4647 static int fan_control_allowed
;
4648 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
4650 static int brightness_mode
;
4651 module_param_named(brightness_mode
, brightness_mode
, int, 0);
4653 static unsigned int hotkey_report_mode
;
4654 module_param(hotkey_report_mode
, uint
, 0);
4656 #define IBM_PARAM(feature) \
4657 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4660 IBM_PARAM(bluetooth
);
4663 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4666 #ifdef CONFIG_THINKPAD_ACPI_BAY
4668 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4673 IBM_PARAM(brightness
);
4677 static int __init
thinkpad_acpi_module_init(void)
4681 /* Parameter checking */
4682 if (hotkey_report_mode
> 2)
4685 /* Driver-level probe */
4687 get_thinkpad_model_data(&thinkpad_id
);
4688 ret
= probe_for_thinkpad();
4690 thinkpad_acpi_module_exit();
4694 /* Driver initialization */
4696 IBM_ACPIHANDLE_INIT(ecrd
);
4697 IBM_ACPIHANDLE_INIT(ecwr
);
4699 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4701 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4702 thinkpad_acpi_module_exit();
4705 proc_dir
->owner
= THIS_MODULE
;
4707 ret
= platform_driver_register(&tpacpi_pdriver
);
4709 printk(IBM_ERR
"unable to register platform driver\n");
4710 thinkpad_acpi_module_exit();
4713 tp_features
.platform_drv_registered
= 1;
4715 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4717 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4718 thinkpad_acpi_module_exit();
4721 tp_features
.platform_drv_attrs_registered
= 1;
4724 /* Device initialization */
4725 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4727 if (IS_ERR(tpacpi_pdev
)) {
4728 ret
= PTR_ERR(tpacpi_pdev
);
4730 printk(IBM_ERR
"unable to register platform device\n");
4731 thinkpad_acpi_module_exit();
4734 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
4735 if (IS_ERR(tpacpi_hwmon
)) {
4736 ret
= PTR_ERR(tpacpi_hwmon
);
4737 tpacpi_hwmon
= NULL
;
4738 printk(IBM_ERR
"unable to register hwmon device\n");
4739 thinkpad_acpi_module_exit();
4742 tpacpi_inputdev
= input_allocate_device();
4743 if (!tpacpi_inputdev
) {
4744 printk(IBM_ERR
"unable to allocate input device\n");
4745 thinkpad_acpi_module_exit();
4748 /* Prepare input device, but don't register */
4749 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
4750 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
4751 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
4752 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
4753 thinkpad_id
.vendor
:
4755 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
4756 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
4758 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4759 ret
= ibm_init(&ibms_init
[i
]);
4760 if (ret
>= 0 && *ibms_init
[i
].param
)
4761 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
4763 thinkpad_acpi_module_exit();
4767 ret
= input_register_device(tpacpi_inputdev
);
4769 printk(IBM_ERR
"unable to register input device\n");
4770 thinkpad_acpi_module_exit();
4773 tp_features
.input_device_registered
= 1;
4779 static void thinkpad_acpi_module_exit(void)
4781 struct ibm_struct
*ibm
, *itmp
;
4783 list_for_each_entry_safe_reverse(ibm
, itmp
,
4784 &tpacpi_all_drivers
,
4789 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
4791 if (tpacpi_inputdev
) {
4792 if (tp_features
.input_device_registered
)
4793 input_unregister_device(tpacpi_inputdev
);
4795 input_free_device(tpacpi_inputdev
);
4799 hwmon_device_unregister(tpacpi_hwmon
);
4802 platform_device_unregister(tpacpi_pdev
);
4804 if (tp_features
.platform_drv_attrs_registered
)
4805 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
4807 if (tp_features
.platform_drv_registered
)
4808 platform_driver_unregister(&tpacpi_pdriver
);
4811 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
4813 kfree(thinkpad_id
.bios_version_str
);
4814 kfree(thinkpad_id
.ec_version_str
);
4815 kfree(thinkpad_id
.model_str
);
4818 module_init(thinkpad_acpi_module_init
);
4819 module_exit(thinkpad_acpi_module_exit
);