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.14"
25 #define TPACPI_SYSFS_VERSION 0x000200
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 if (ibm_thinkpad_ec_found
)
721 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
722 ibm_thinkpad_ec_found
);
727 static int thinkpad_acpi_driver_read(char *p
)
731 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
732 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
737 static struct ibm_struct thinkpad_acpi_driver_data
= {
739 .read
= thinkpad_acpi_driver_read
,
742 /*************************************************************************
746 static int hotkey_orig_status
;
747 static u32 hotkey_orig_mask
;
748 static u32 hotkey_all_mask
;
749 static u32 hotkey_reserved_mask
;
751 static u16 hotkey_keycode_map
[] = {
752 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
753 KEY_FN_F1
, KEY_FN_F2
, KEY_FN_F3
, KEY_SLEEP
,
754 KEY_FN_F5
, KEY_FN_F6
, KEY_FN_F7
, KEY_FN_F8
,
755 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
756 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
757 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
758 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
759 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
760 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
761 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
762 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
763 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
764 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
765 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
766 KEY_RESERVED
, /* 0x14: VOLUME UP */
767 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
768 KEY_RESERVED
, /* 0x16: MUTE */
769 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
770 /* (assignments unknown, please report if found) */
771 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
772 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
775 static struct attribute_set
*hotkey_dev_attributes
;
777 static int hotkey_get_wlsw(int *status
)
779 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
784 /* sysfs hotkey enable ------------------------------------------------- */
785 static ssize_t
hotkey_enable_show(struct device
*dev
,
786 struct device_attribute
*attr
,
792 res
= hotkey_get(&status
, &mask
);
796 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
799 static ssize_t
hotkey_enable_store(struct device
*dev
,
800 struct device_attribute
*attr
,
801 const char *buf
, size_t count
)
807 if (parse_strtoul(buf
, 1, &t
))
810 res
= hotkey_get(&status
, &mask
);
812 res
= hotkey_set(t
, mask
);
814 return (res
) ? res
: count
;
817 static struct device_attribute dev_attr_hotkey_enable
=
818 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
819 hotkey_enable_show
, hotkey_enable_store
);
821 /* sysfs hotkey mask --------------------------------------------------- */
822 static ssize_t
hotkey_mask_show(struct device
*dev
,
823 struct device_attribute
*attr
,
829 res
= hotkey_get(&status
, &mask
);
833 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
836 static ssize_t
hotkey_mask_store(struct device
*dev
,
837 struct device_attribute
*attr
,
838 const char *buf
, size_t count
)
844 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
847 res
= hotkey_get(&status
, &mask
);
849 hotkey_set(status
, t
);
851 return (res
) ? res
: count
;
854 static struct device_attribute dev_attr_hotkey_mask
=
855 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
856 hotkey_mask_show
, hotkey_mask_store
);
858 /* sysfs hotkey bios_enabled ------------------------------------------- */
859 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
860 struct device_attribute
*attr
,
863 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
866 static struct device_attribute dev_attr_hotkey_bios_enabled
=
867 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
869 /* sysfs hotkey bios_mask ---------------------------------------------- */
870 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
871 struct device_attribute
*attr
,
874 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
877 static struct device_attribute dev_attr_hotkey_bios_mask
=
878 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
880 /* sysfs hotkey all_mask ----------------------------------------------- */
881 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
882 struct device_attribute
*attr
,
885 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_all_mask
);
888 static struct device_attribute dev_attr_hotkey_all_mask
=
889 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
891 /* sysfs hotkey recommended_mask --------------------------------------- */
892 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
893 struct device_attribute
*attr
,
896 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
897 hotkey_all_mask
& ~hotkey_reserved_mask
);
900 static struct device_attribute dev_attr_hotkey_recommended_mask
=
901 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
902 hotkey_recommended_mask_show
, NULL
);
904 /* sysfs hotkey radio_sw ----------------------------------------------- */
905 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
906 struct device_attribute
*attr
,
910 res
= hotkey_get_wlsw(&s
);
914 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
917 static struct device_attribute dev_attr_hotkey_radio_sw
=
918 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
920 /* --------------------------------------------------------------------- */
922 static struct attribute
*hotkey_mask_attributes
[] = {
923 &dev_attr_hotkey_mask
.attr
,
924 &dev_attr_hotkey_bios_enabled
.attr
,
925 &dev_attr_hotkey_bios_mask
.attr
,
926 &dev_attr_hotkey_all_mask
.attr
,
927 &dev_attr_hotkey_recommended_mask
.attr
,
930 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
935 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
937 BUG_ON(!tpacpi_inputdev
);
939 IBM_ACPIHANDLE_INIT(hkey
);
940 mutex_init(&hotkey_mutex
);
942 /* hotkey not supported on 570 */
943 tp_features
.hotkey
= hkey_handle
!= NULL
;
945 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
946 str_supported(tp_features
.hotkey
));
948 if (tp_features
.hotkey
) {
949 hotkey_dev_attributes
= create_attr_set(7, NULL
);
950 if (!hotkey_dev_attributes
)
952 res
= add_to_attr_set(hotkey_dev_attributes
,
953 &dev_attr_hotkey_enable
.attr
);
957 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
958 A30, R30, R31, T20-22, X20-21, X22-24 */
959 tp_features
.hotkey_mask
=
960 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
962 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
963 str_supported(tp_features
.hotkey_mask
));
965 if (tp_features
.hotkey_mask
) {
966 /* MHKA available in A31, R40, R40e, T4x, X31, and later */
967 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
969 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
972 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
973 if (!res
&& tp_features
.hotkey_mask
) {
974 res
= add_many_to_attr_set(hotkey_dev_attributes
,
975 hotkey_mask_attributes
,
976 ARRAY_SIZE(hotkey_mask_attributes
));
979 /* Not all thinkpads have a hardware radio switch */
980 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
981 tp_features
.hotkey_wlsw
= 1;
983 "radio switch found; radios are %s\n",
985 res
= add_to_attr_set(hotkey_dev_attributes
,
986 &dev_attr_hotkey_radio_sw
.attr
);
990 res
= register_attr_set_with_sysfs(
991 hotkey_dev_attributes
,
992 &tpacpi_pdev
->dev
.kobj
);
996 #ifndef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
997 for (i
= 0; i
< 12; i
++)
998 hotkey_keycode_map
[i
] = KEY_UNKNOWN
;
999 #endif /* ! CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
1001 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1002 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1003 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1004 tpacpi_inputdev
->keycodesize
= sizeof(hotkey_keycode_map
[0]);
1005 tpacpi_inputdev
->keycodemax
= ARRAY_SIZE(hotkey_keycode_map
);
1006 tpacpi_inputdev
->keycode
= &hotkey_keycode_map
;
1007 for (i
= 0; i
< ARRAY_SIZE(hotkey_keycode_map
); i
++) {
1008 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1009 set_bit(hotkey_keycode_map
[i
],
1010 tpacpi_inputdev
->keybit
);
1012 if (i
< sizeof(hotkey_reserved_mask
)*8)
1013 hotkey_reserved_mask
|= 1 << i
;
1017 if (tp_features
.hotkey_wlsw
) {
1018 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1019 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1022 #ifdef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
1023 dbg_printk(TPACPI_DBG_INIT
,
1024 "enabling hot key handling\n");
1025 res
= hotkey_set(1, (hotkey_all_mask
& ~hotkey_reserved_mask
)
1026 | hotkey_orig_mask
);
1029 #endif /* CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
1032 return (tp_features
.hotkey
)? 0 : 1;
1035 static void hotkey_exit(void)
1039 if (tp_features
.hotkey
) {
1040 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
1041 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
1043 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
1046 if (hotkey_dev_attributes
) {
1047 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1048 hotkey_dev_attributes
= NULL
;
1052 static void tpacpi_input_send_key(unsigned int scancode
,
1053 unsigned int keycode
)
1055 if (keycode
!= KEY_RESERVED
) {
1056 input_report_key(tpacpi_inputdev
, keycode
, 1);
1057 if (keycode
== KEY_UNKNOWN
)
1058 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1060 input_sync(tpacpi_inputdev
);
1062 input_report_key(tpacpi_inputdev
, keycode
, 0);
1063 if (keycode
== KEY_UNKNOWN
)
1064 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1066 input_sync(tpacpi_inputdev
);
1070 static void tpacpi_input_send_radiosw(void)
1074 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
))
1075 input_report_switch(tpacpi_inputdev
,
1079 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1082 unsigned int keycode
, scancode
;
1085 if (event
== 0x80 && acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1086 if (tpacpi_inputdev
->users
> 0) {
1087 switch (hkey
>> 12) {
1089 /* 0x1000-0x1FFF: key presses */
1090 scancode
= hkey
& 0xfff;
1091 if (scancode
> 0 && scancode
< 0x21) {
1093 keycode
= hotkey_keycode_map
[scancode
];
1094 tpacpi_input_send_key(scancode
, keycode
);
1095 sendacpi
= (keycode
== KEY_RESERVED
1096 || keycode
== KEY_UNKNOWN
);
1099 "hotkey 0x%04x out of range for keyboard map\n",
1104 /* 0x5000-0x5FFF: LID */
1105 /* we don't handle it through this path, just
1106 * eat up known LID events */
1107 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1109 "unknown LID-related hotkey event: 0x%04x\n",
1114 /* 0x7000-0x7FFF: misc */
1115 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1116 tpacpi_input_send_radiosw();
1120 /* fallthrough to default */
1122 /* case 2: dock-related */
1123 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1124 /* case 3: ultra-bay related. maybe bay in dock? */
1125 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1126 printk(IBM_NOTICE
"unhandled hotkey event 0x%04x\n", hkey
);
1131 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
1133 printk(IBM_ERR
"unknown hotkey notification event %d\n", event
);
1134 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1138 static void hotkey_resume(void)
1140 tpacpi_input_send_radiosw();
1144 * Call with hotkey_mutex held
1146 static int hotkey_get(int *status
, u32
*mask
)
1148 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1151 if (tp_features
.hotkey_mask
)
1152 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1159 * Call with hotkey_mutex held
1161 static int hotkey_set(int status
, u32 mask
)
1165 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1168 if (tp_features
.hotkey_mask
)
1169 for (i
= 0; i
< 32; i
++) {
1170 int bit
= ((1 << i
) & mask
) != 0;
1171 if (!acpi_evalf(hkey_handle
,
1172 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1179 /* procfs -------------------------------------------------------------- */
1180 static int hotkey_read(char *p
)
1186 if (!tp_features
.hotkey
) {
1187 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1191 res
= mutex_lock_interruptible(&hotkey_mutex
);
1194 res
= hotkey_get(&status
, &mask
);
1195 mutex_unlock(&hotkey_mutex
);
1199 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1200 if (tp_features
.hotkey_mask
) {
1201 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1202 len
+= sprintf(p
+ len
,
1203 "commands:\tenable, disable, reset, <mask>\n");
1205 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1206 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1212 static int hotkey_write(char *buf
)
1219 if (!tp_features
.hotkey
)
1222 res
= mutex_lock_interruptible(&hotkey_mutex
);
1226 res
= hotkey_get(&status
, &mask
);
1231 while ((cmd
= next_cmd(&buf
))) {
1232 if (strlencmp(cmd
, "enable") == 0) {
1234 } else if (strlencmp(cmd
, "disable") == 0) {
1236 } else if (strlencmp(cmd
, "reset") == 0) {
1237 status
= hotkey_orig_status
;
1238 mask
= hotkey_orig_mask
;
1239 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1241 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1251 res
= hotkey_set(status
, mask
);
1254 mutex_unlock(&hotkey_mutex
);
1258 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1259 .hid
= IBM_HKEY_HID
,
1260 .notify
= hotkey_notify
,
1261 .handle
= &hkey_handle
,
1262 .type
= ACPI_DEVICE_NOTIFY
,
1265 static struct ibm_struct hotkey_driver_data
= {
1267 .read
= hotkey_read
,
1268 .write
= hotkey_write
,
1269 .exit
= hotkey_exit
,
1270 .resume
= hotkey_resume
,
1271 .acpi
= &ibm_hotkey_acpidriver
,
1274 /*************************************************************************
1275 * Bluetooth subdriver
1278 /* sysfs bluetooth enable ---------------------------------------------- */
1279 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1280 struct device_attribute
*attr
,
1285 status
= bluetooth_get_radiosw();
1289 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1292 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1293 struct device_attribute
*attr
,
1294 const char *buf
, size_t count
)
1299 if (parse_strtoul(buf
, 1, &t
))
1302 res
= bluetooth_set_radiosw(t
);
1304 return (res
) ? res
: count
;
1307 static struct device_attribute dev_attr_bluetooth_enable
=
1308 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1309 bluetooth_enable_show
, bluetooth_enable_store
);
1311 /* --------------------------------------------------------------------- */
1313 static struct attribute
*bluetooth_attributes
[] = {
1314 &dev_attr_bluetooth_enable
.attr
,
1318 static const struct attribute_group bluetooth_attr_group
= {
1319 .attrs
= bluetooth_attributes
,
1322 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1327 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1329 IBM_ACPIHANDLE_INIT(hkey
);
1331 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1332 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1333 tp_features
.bluetooth
= hkey_handle
&&
1334 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1336 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1337 str_supported(tp_features
.bluetooth
),
1340 if (tp_features
.bluetooth
) {
1341 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1342 /* no bluetooth hardware present in system */
1343 tp_features
.bluetooth
= 0;
1344 dbg_printk(TPACPI_DBG_INIT
,
1345 "bluetooth hardware not installed\n");
1347 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1348 &bluetooth_attr_group
);
1354 return (tp_features
.bluetooth
)? 0 : 1;
1357 static void bluetooth_exit(void)
1359 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1360 &bluetooth_attr_group
);
1363 static int bluetooth_get_radiosw(void)
1367 if (!tp_features
.bluetooth
)
1370 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1373 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1376 static int bluetooth_set_radiosw(int radio_on
)
1380 if (!tp_features
.bluetooth
)
1383 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1386 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1388 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1389 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1395 /* procfs -------------------------------------------------------------- */
1396 static int bluetooth_read(char *p
)
1399 int status
= bluetooth_get_radiosw();
1401 if (!tp_features
.bluetooth
)
1402 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1404 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1405 (status
)? "enabled" : "disabled");
1406 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1412 static int bluetooth_write(char *buf
)
1416 if (!tp_features
.bluetooth
)
1419 while ((cmd
= next_cmd(&buf
))) {
1420 if (strlencmp(cmd
, "enable") == 0) {
1421 bluetooth_set_radiosw(1);
1422 } else if (strlencmp(cmd
, "disable") == 0) {
1423 bluetooth_set_radiosw(0);
1431 static struct ibm_struct bluetooth_driver_data
= {
1432 .name
= "bluetooth",
1433 .read
= bluetooth_read
,
1434 .write
= bluetooth_write
,
1435 .exit
= bluetooth_exit
,
1438 /*************************************************************************
1442 /* sysfs wan enable ---------------------------------------------------- */
1443 static ssize_t
wan_enable_show(struct device
*dev
,
1444 struct device_attribute
*attr
,
1449 status
= wan_get_radiosw();
1453 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1456 static ssize_t
wan_enable_store(struct device
*dev
,
1457 struct device_attribute
*attr
,
1458 const char *buf
, size_t count
)
1463 if (parse_strtoul(buf
, 1, &t
))
1466 res
= wan_set_radiosw(t
);
1468 return (res
) ? res
: count
;
1471 static struct device_attribute dev_attr_wan_enable
=
1472 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1473 wan_enable_show
, wan_enable_store
);
1475 /* --------------------------------------------------------------------- */
1477 static struct attribute
*wan_attributes
[] = {
1478 &dev_attr_wan_enable
.attr
,
1482 static const struct attribute_group wan_attr_group
= {
1483 .attrs
= wan_attributes
,
1486 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1491 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1493 IBM_ACPIHANDLE_INIT(hkey
);
1495 tp_features
.wan
= hkey_handle
&&
1496 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1498 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1499 str_supported(tp_features
.wan
),
1502 if (tp_features
.wan
) {
1503 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1504 /* no wan hardware present in system */
1505 tp_features
.wan
= 0;
1506 dbg_printk(TPACPI_DBG_INIT
,
1507 "wan hardware not installed\n");
1509 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1516 return (tp_features
.wan
)? 0 : 1;
1519 static void wan_exit(void)
1521 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1525 static int wan_get_radiosw(void)
1529 if (!tp_features
.wan
)
1532 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1535 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1538 static int wan_set_radiosw(int radio_on
)
1542 if (!tp_features
.wan
)
1545 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1548 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1550 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1551 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1557 /* procfs -------------------------------------------------------------- */
1558 static int wan_read(char *p
)
1561 int status
= wan_get_radiosw();
1563 if (!tp_features
.wan
)
1564 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1566 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1567 (status
)? "enabled" : "disabled");
1568 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1574 static int wan_write(char *buf
)
1578 if (!tp_features
.wan
)
1581 while ((cmd
= next_cmd(&buf
))) {
1582 if (strlencmp(cmd
, "enable") == 0) {
1584 } else if (strlencmp(cmd
, "disable") == 0) {
1593 static struct ibm_struct wan_driver_data
= {
1598 .flags
.experimental
= 1,
1601 /*************************************************************************
1605 static enum video_access_mode video_supported
;
1606 static int video_orig_autosw
;
1608 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1609 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1610 "\\_SB.PCI0.VID0", /* 770e */
1611 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1612 "\\_SB.PCI0.AGP.VID", /* all others */
1615 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1617 static int __init
video_init(struct ibm_init_struct
*iibm
)
1621 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1623 IBM_ACPIHANDLE_INIT(vid
);
1624 IBM_ACPIHANDLE_INIT(vid2
);
1626 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1627 /* G41, assume IVGA doesn't change */
1628 vid_handle
= vid2_handle
;
1631 /* video switching not supported on R30, R31 */
1632 video_supported
= TPACPI_VIDEO_NONE
;
1633 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1635 video_supported
= TPACPI_VIDEO_570
;
1636 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1637 /* 600e/x, 770e, 770x */
1638 video_supported
= TPACPI_VIDEO_770
;
1641 video_supported
= TPACPI_VIDEO_NEW
;
1643 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1644 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1647 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1650 static void video_exit(void)
1652 dbg_printk(TPACPI_DBG_EXIT
,
1653 "restoring original video autoswitch mode\n");
1654 if (video_autosw_set(video_orig_autosw
))
1655 printk(IBM_ERR
"error while trying to restore original "
1656 "video autoswitch mode\n");
1659 static int video_outputsw_get(void)
1664 switch (video_supported
) {
1665 case TPACPI_VIDEO_570
:
1666 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1667 TP_ACPI_VIDEO_570_PHSCMD
))
1669 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1671 case TPACPI_VIDEO_770
:
1672 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1675 status
|= TP_ACPI_VIDEO_S_LCD
;
1676 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1679 status
|= TP_ACPI_VIDEO_S_CRT
;
1681 case TPACPI_VIDEO_NEW
:
1682 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1683 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1686 status
|= TP_ACPI_VIDEO_S_CRT
;
1688 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1689 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1692 status
|= TP_ACPI_VIDEO_S_LCD
;
1693 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1696 status
|= TP_ACPI_VIDEO_S_DVI
;
1705 static int video_outputsw_set(int status
)
1710 switch (video_supported
) {
1711 case TPACPI_VIDEO_570
:
1712 res
= acpi_evalf(NULL
, NULL
,
1713 "\\_SB.PHS2", "vdd",
1714 TP_ACPI_VIDEO_570_PHS2CMD
,
1715 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1717 case TPACPI_VIDEO_770
:
1718 autosw
= video_autosw_get();
1722 res
= video_autosw_set(1);
1725 res
= acpi_evalf(vid_handle
, NULL
,
1726 "ASWT", "vdd", status
* 0x100, 0);
1727 if (!autosw
&& video_autosw_set(autosw
)) {
1728 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1732 case TPACPI_VIDEO_NEW
:
1733 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1734 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1740 return (res
)? 0 : -EIO
;
1743 static int video_autosw_get(void)
1747 switch (video_supported
) {
1748 case TPACPI_VIDEO_570
:
1749 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1752 case TPACPI_VIDEO_770
:
1753 case TPACPI_VIDEO_NEW
:
1754 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1764 static int video_autosw_set(int enable
)
1766 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1771 static int video_outputsw_cycle(void)
1773 int autosw
= video_autosw_get();
1779 switch (video_supported
) {
1780 case TPACPI_VIDEO_570
:
1781 res
= video_autosw_set(1);
1784 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1786 case TPACPI_VIDEO_770
:
1787 case TPACPI_VIDEO_NEW
:
1788 res
= video_autosw_set(1);
1791 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1796 if (!autosw
&& video_autosw_set(autosw
)) {
1797 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1801 return (res
)? 0 : -EIO
;
1804 static int video_expand_toggle(void)
1806 switch (video_supported
) {
1807 case TPACPI_VIDEO_570
:
1808 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1810 case TPACPI_VIDEO_770
:
1811 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1813 case TPACPI_VIDEO_NEW
:
1814 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1822 static int video_read(char *p
)
1827 if (video_supported
== TPACPI_VIDEO_NONE
) {
1828 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1832 status
= video_outputsw_get();
1836 autosw
= video_autosw_get();
1840 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1841 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
1842 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
1843 if (video_supported
== TPACPI_VIDEO_NEW
)
1844 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
1845 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
1846 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
1847 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
1848 if (video_supported
== TPACPI_VIDEO_NEW
)
1849 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
1850 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
1851 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
1856 static int video_write(char *buf
)
1859 int enable
, disable
, status
;
1862 if (video_supported
== TPACPI_VIDEO_NONE
)
1868 while ((cmd
= next_cmd(&buf
))) {
1869 if (strlencmp(cmd
, "lcd_enable") == 0) {
1870 enable
|= TP_ACPI_VIDEO_S_LCD
;
1871 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1872 disable
|= TP_ACPI_VIDEO_S_LCD
;
1873 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1874 enable
|= TP_ACPI_VIDEO_S_CRT
;
1875 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1876 disable
|= TP_ACPI_VIDEO_S_CRT
;
1877 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1878 strlencmp(cmd
, "dvi_enable") == 0) {
1879 enable
|= TP_ACPI_VIDEO_S_DVI
;
1880 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1881 strlencmp(cmd
, "dvi_disable") == 0) {
1882 disable
|= TP_ACPI_VIDEO_S_DVI
;
1883 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1884 res
= video_autosw_set(1);
1887 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1888 res
= video_autosw_set(0);
1891 } else if (strlencmp(cmd
, "video_switch") == 0) {
1892 res
= video_outputsw_cycle();
1895 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1896 res
= video_expand_toggle();
1903 if (enable
|| disable
) {
1904 status
= video_outputsw_get();
1907 res
= video_outputsw_set((status
& ~disable
) | enable
);
1915 static struct ibm_struct video_driver_data
= {
1918 .write
= video_write
,
1922 /*************************************************************************
1923 * Light (thinklight) subdriver
1926 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1927 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1929 static int __init
light_init(struct ibm_init_struct
*iibm
)
1931 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
1933 IBM_ACPIHANDLE_INIT(ledb
);
1934 IBM_ACPIHANDLE_INIT(lght
);
1935 IBM_ACPIHANDLE_INIT(cmos
);
1937 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1938 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1940 if (tp_features
.light
)
1941 /* light status not supported on
1942 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1943 tp_features
.light_status
=
1944 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
1946 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
1947 str_supported(tp_features
.light
));
1949 return (tp_features
.light
)? 0 : 1;
1952 static int light_read(char *p
)
1957 if (!tp_features
.light
) {
1958 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1959 } else if (!tp_features
.light_status
) {
1960 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1961 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1963 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1965 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1966 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1972 static int light_write(char *buf
)
1974 int cmos_cmd
, lght_cmd
;
1978 if (!tp_features
.light
)
1981 while ((cmd
= next_cmd(&buf
))) {
1982 if (strlencmp(cmd
, "on") == 0) {
1985 } else if (strlencmp(cmd
, "off") == 0) {
1991 success
= cmos_handle
?
1992 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1993 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2001 static struct ibm_struct light_driver_data
= {
2004 .write
= light_write
,
2007 /*************************************************************************
2011 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2013 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2014 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2015 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2016 "\\_SB.PCI.ISA.SLCE", /* 570 */
2017 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2019 /* don't list other alternatives as we install a notify handler on the 570 */
2020 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2022 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2024 .notify
= dock_notify
,
2025 .handle
= &dock_handle
,
2026 .type
= ACPI_SYSTEM_NOTIFY
,
2030 .notify
= dock_notify
,
2031 .handle
= &pci_handle
,
2032 .type
= ACPI_SYSTEM_NOTIFY
,
2036 static struct ibm_struct dock_driver_data
[2] = {
2040 .write
= dock_write
,
2041 .acpi
= &ibm_dock_acpidriver
[0],
2045 .acpi
= &ibm_dock_acpidriver
[1],
2049 #define dock_docked() (_sta(dock_handle) & 1)
2051 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2053 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2055 IBM_ACPIHANDLE_INIT(dock
);
2057 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2058 str_supported(dock_handle
!= NULL
));
2060 return (dock_handle
)? 0 : 1;
2063 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2067 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2069 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2070 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2071 IBM_ACPIHANDLE_INIT(pci
);
2072 dock2_needed
= (pci_handle
!= NULL
);
2073 vdbg_printk(TPACPI_DBG_INIT
,
2074 "dock PCI handler for the TP 570 is %s\n",
2075 str_supported(dock2_needed
));
2077 vdbg_printk(TPACPI_DBG_INIT
,
2078 "dock subdriver part 2 not required\n");
2082 return (dock2_needed
)? 0 : 1;
2085 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2087 int docked
= dock_docked();
2088 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, IBM_PCI_HID
);
2090 if (event
== 1 && !pci
) /* 570 */
2091 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2092 else if (event
== 1 && pci
) /* 570 */
2093 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2094 else if (event
== 3 && docked
)
2095 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2096 else if (event
== 3 && !docked
)
2097 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
2098 else if (event
== 0 && docked
)
2099 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2101 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2102 event
, _sta(dock_handle
));
2103 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
2107 static int dock_read(char *p
)
2110 int docked
= dock_docked();
2113 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2115 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2117 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2118 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2124 static int dock_write(char *buf
)
2131 while ((cmd
= next_cmd(&buf
))) {
2132 if (strlencmp(cmd
, "undock") == 0) {
2133 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2134 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2136 } else if (strlencmp(cmd
, "dock") == 0) {
2137 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2146 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2148 /*************************************************************************
2152 #ifdef CONFIG_THINKPAD_ACPI_BAY
2153 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2154 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2155 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2156 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2157 ); /* A21e, R30, R31 */
2158 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2159 "_EJ0", /* all others */
2160 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2161 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2162 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2164 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2168 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2170 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2172 IBM_ACPIHANDLE_INIT(bay
);
2174 IBM_ACPIHANDLE_INIT(bay_ej
);
2175 IBM_ACPIHANDLE_INIT(bay2
);
2177 IBM_ACPIHANDLE_INIT(bay2_ej
);
2179 tp_features
.bay_status
= bay_handle
&&
2180 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2181 tp_features
.bay_status2
= bay2_handle
&&
2182 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2184 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2185 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2186 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2187 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2189 vdbg_printk(TPACPI_DBG_INIT
,
2190 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2191 str_supported(tp_features
.bay_status
),
2192 str_supported(tp_features
.bay_eject
),
2193 str_supported(tp_features
.bay_status2
),
2194 str_supported(tp_features
.bay_eject2
));
2196 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2197 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2200 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2202 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
2205 #define bay_occupied(b) (_sta(b##_handle) & 1)
2207 static int bay_read(char *p
)
2210 int occupied
= bay_occupied(bay
);
2211 int occupied2
= bay_occupied(bay2
);
2214 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2215 tp_features
.bay_status
?
2216 (occupied
? "occupied" : "unoccupied") :
2218 if (tp_features
.bay_status2
)
2219 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2220 "occupied" : "unoccupied");
2222 eject
= tp_features
.bay_eject
&& occupied
;
2223 eject2
= tp_features
.bay_eject2
&& occupied2
;
2225 if (eject
&& eject2
)
2226 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2228 len
+= sprintf(p
+ len
, "commands:\teject\n");
2230 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2235 static int bay_write(char *buf
)
2239 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2242 while ((cmd
= next_cmd(&buf
))) {
2243 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2244 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2246 } else if (tp_features
.bay_eject2
&&
2247 strlencmp(cmd
, "eject2") == 0) {
2248 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2257 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2258 .notify
= bay_notify
,
2259 .handle
= &bay_handle
,
2260 .type
= ACPI_SYSTEM_NOTIFY
,
2263 static struct ibm_struct bay_driver_data
= {
2267 .acpi
= &ibm_bay_acpidriver
,
2270 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2272 /*************************************************************************
2276 /* sysfs cmos_command -------------------------------------------------- */
2277 static ssize_t
cmos_command_store(struct device
*dev
,
2278 struct device_attribute
*attr
,
2279 const char *buf
, size_t count
)
2281 unsigned long cmos_cmd
;
2284 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2287 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2288 return (res
)? res
: count
;
2291 static struct device_attribute dev_attr_cmos_command
=
2292 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2294 /* --------------------------------------------------------------------- */
2296 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2300 vdbg_printk(TPACPI_DBG_INIT
,
2301 "initializing cmos commands subdriver\n");
2303 IBM_ACPIHANDLE_INIT(cmos
);
2305 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2306 str_supported(cmos_handle
!= NULL
));
2308 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2312 return (cmos_handle
)? 0 : 1;
2315 static void cmos_exit(void)
2317 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2320 static int cmos_read(char *p
)
2324 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2325 R30, R31, T20-22, X20-21 */
2327 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2329 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2330 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2336 static int cmos_write(char *buf
)
2341 while ((cmd
= next_cmd(&buf
))) {
2342 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2343 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2348 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2356 static struct ibm_struct cmos_driver_data
= {
2359 .write
= cmos_write
,
2363 /*************************************************************************
2367 static enum led_access_mode led_supported
;
2369 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2370 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2371 "LED", /* all others */
2374 static int __init
led_init(struct ibm_init_struct
*iibm
)
2376 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2378 IBM_ACPIHANDLE_INIT(led
);
2381 /* led not supported on R30, R31 */
2382 led_supported
= TPACPI_LED_NONE
;
2383 else if (strlencmp(led_path
, "SLED") == 0)
2385 led_supported
= TPACPI_LED_570
;
2386 else if (strlencmp(led_path
, "SYSL") == 0)
2387 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2388 led_supported
= TPACPI_LED_OLD
;
2391 led_supported
= TPACPI_LED_NEW
;
2393 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2394 str_supported(led_supported
), led_supported
);
2396 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2399 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2401 static int led_read(char *p
)
2405 if (!led_supported
) {
2406 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2409 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2411 if (led_supported
== TPACPI_LED_570
) {
2414 for (i
= 0; i
< 8; i
++) {
2415 if (!acpi_evalf(ec_handle
,
2416 &status
, "GLED", "dd", 1 << i
))
2418 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2419 i
, led_status(status
));
2423 len
+= sprintf(p
+ len
, "commands:\t"
2424 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2429 /* off, on, blink */
2430 static const int led_sled_arg1
[] = { 0, 1, 3 };
2431 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2432 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2433 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2435 static int led_write(char *buf
)
2443 while ((cmd
= next_cmd(&buf
))) {
2444 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2447 if (strstr(cmd
, "off")) {
2449 } else if (strstr(cmd
, "on")) {
2451 } else if (strstr(cmd
, "blink")) {
2456 if (led_supported
== TPACPI_LED_570
) {
2459 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2460 led
, led_sled_arg1
[ind
]))
2462 } else if (led_supported
== TPACPI_LED_OLD
) {
2463 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2465 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2468 ec_write(TPACPI_LED_EC_HLBL
,
2469 led
* led_exp_hlbl
[ind
]);
2472 ec_write(TPACPI_LED_EC_HLCL
,
2473 led
* led_exp_hlcl
[ind
]);
2478 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2479 led
, led_led_arg1
[ind
]))
2487 static struct ibm_struct led_driver_data
= {
2493 /*************************************************************************
2497 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2499 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2501 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2503 IBM_ACPIHANDLE_INIT(beep
);
2505 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2506 str_supported(beep_handle
!= NULL
));
2508 return (beep_handle
)? 0 : 1;
2511 static int beep_read(char *p
)
2516 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2518 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2519 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2525 static int beep_write(char *buf
)
2533 while ((cmd
= next_cmd(&buf
))) {
2534 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2535 beep_cmd
>= 0 && beep_cmd
<= 17) {
2539 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2546 static struct ibm_struct beep_driver_data
= {
2549 .write
= beep_write
,
2552 /*************************************************************************
2556 static enum thermal_access_mode thermal_read_mode
;
2558 /* sysfs temp##_input -------------------------------------------------- */
2560 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2561 struct device_attribute
*attr
,
2564 struct sensor_device_attribute
*sensor_attr
=
2565 to_sensor_dev_attr(attr
);
2566 int idx
= sensor_attr
->index
;
2570 res
= thermal_get_sensor(idx
, &value
);
2573 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2576 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2579 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2580 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2582 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2583 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2584 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2585 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2586 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2587 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2588 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2589 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2590 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2591 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2592 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2593 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2594 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2595 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2596 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2597 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2598 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2601 #define THERMAL_ATTRS(X) \
2602 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2604 static struct attribute
*thermal_temp_input_attr
[] = {
2624 static const struct attribute_group thermal_temp_input16_group
= {
2625 .attrs
= thermal_temp_input_attr
2628 static const struct attribute_group thermal_temp_input8_group
= {
2629 .attrs
= &thermal_temp_input_attr
[8]
2632 #undef THERMAL_SENSOR_ATTR_TEMP
2633 #undef THERMAL_ATTRS
2635 /* --------------------------------------------------------------------- */
2637 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2644 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2646 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2648 if (ibm_thinkpad_ec_found
&& experimental
) {
2650 * Direct EC access mode: sensors at registers
2651 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2652 * non-implemented, thermal sensors return 0x80 when
2657 for (i
= 0; i
< 8; i
++) {
2658 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2664 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2672 /* This is sheer paranoia, but we handle it anyway */
2675 "ThinkPad ACPI EC access misbehaving, "
2676 "falling back to ACPI TMPx access mode\n");
2677 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2680 "ThinkPad ACPI EC access misbehaving, "
2681 "disabling thermal sensors access\n");
2682 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2687 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2689 } else if (acpi_tmp7
) {
2690 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2691 /* 600e/x, 770e, 770x */
2692 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2694 /* Standard ACPI TMPx access, max 8 sensors */
2695 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2698 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2699 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2702 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2703 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2706 switch(thermal_read_mode
) {
2707 case TPACPI_THERMAL_TPEC_16
:
2708 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2709 &thermal_temp_input16_group
);
2713 case TPACPI_THERMAL_TPEC_8
:
2714 case TPACPI_THERMAL_ACPI_TMP07
:
2715 case TPACPI_THERMAL_ACPI_UPDT
:
2716 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2717 &thermal_temp_input8_group
);
2721 case TPACPI_THERMAL_NONE
:
2729 static void thermal_exit(void)
2731 switch(thermal_read_mode
) {
2732 case TPACPI_THERMAL_TPEC_16
:
2733 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2734 &thermal_temp_input16_group
);
2736 case TPACPI_THERMAL_TPEC_8
:
2737 case TPACPI_THERMAL_ACPI_TMP07
:
2738 case TPACPI_THERMAL_ACPI_UPDT
:
2739 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2740 &thermal_temp_input16_group
);
2742 case TPACPI_THERMAL_NONE
:
2748 /* idx is zero-based */
2749 static int thermal_get_sensor(int idx
, s32
*value
)
2755 t
= TP_EC_THERMAL_TMP0
;
2757 switch (thermal_read_mode
) {
2758 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2759 case TPACPI_THERMAL_TPEC_16
:
2760 if (idx
>= 8 && idx
<= 15) {
2761 t
= TP_EC_THERMAL_TMP8
;
2766 case TPACPI_THERMAL_TPEC_8
:
2768 if (!acpi_ec_read(t
+ idx
, &tmp
))
2770 *value
= tmp
* 1000;
2775 case TPACPI_THERMAL_ACPI_UPDT
:
2777 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2778 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2780 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2782 *value
= (t
- 2732) * 100;
2787 case TPACPI_THERMAL_ACPI_TMP07
:
2789 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2790 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2797 case TPACPI_THERMAL_NONE
:
2805 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2816 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2819 for(i
= 0 ; i
< n
; i
++) {
2820 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
2828 static int thermal_read(char *p
)
2832 struct ibm_thermal_sensors_struct t
;
2834 n
= thermal_get_sensors(&t
);
2835 if (unlikely(n
< 0))
2838 len
+= sprintf(p
+ len
, "temperatures:\t");
2841 for (i
= 0; i
< (n
- 1); i
++)
2842 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
2843 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
2845 len
+= sprintf(p
+ len
, "not supported\n");
2850 static struct ibm_struct thermal_driver_data
= {
2852 .read
= thermal_read
,
2853 .exit
= thermal_exit
,
2856 /*************************************************************************
2860 static u8 ecdump_regs
[256];
2862 static int ecdump_read(char *p
)
2868 len
+= sprintf(p
+ len
, "EC "
2869 " +00 +01 +02 +03 +04 +05 +06 +07"
2870 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2871 for (i
= 0; i
< 256; i
+= 16) {
2872 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
2873 for (j
= 0; j
< 16; j
++) {
2874 if (!acpi_ec_read(i
+ j
, &v
))
2876 if (v
!= ecdump_regs
[i
+ j
])
2877 len
+= sprintf(p
+ len
, " *%02x", v
);
2879 len
+= sprintf(p
+ len
, " %02x", v
);
2880 ecdump_regs
[i
+ j
] = v
;
2882 len
+= sprintf(p
+ len
, "\n");
2887 /* These are way too dangerous to advertise openly... */
2889 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
2890 " (<offset> is 00-ff, <value> is 00-ff)\n");
2891 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
2892 " (<offset> is 00-ff, <value> is 0-255)\n");
2897 static int ecdump_write(char *buf
)
2902 while ((cmd
= next_cmd(&buf
))) {
2903 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
2905 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
2909 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
2910 if (!acpi_ec_write(i
, v
))
2919 static struct ibm_struct ecdump_driver_data
= {
2921 .read
= ecdump_read
,
2922 .write
= ecdump_write
,
2923 .flags
.experimental
= 1,
2926 /*************************************************************************
2927 * Backlight/brightness subdriver
2930 static struct backlight_device
*ibm_backlight_device
;
2932 static struct backlight_ops ibm_backlight_data
= {
2933 .get_brightness
= brightness_get
,
2934 .update_status
= brightness_update_status
,
2937 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
2941 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
2943 b
= brightness_get(NULL
);
2947 ibm_backlight_device
= backlight_device_register(
2948 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
2949 &ibm_backlight_data
);
2950 if (IS_ERR(ibm_backlight_device
)) {
2951 printk(IBM_ERR
"Could not register backlight device\n");
2952 return PTR_ERR(ibm_backlight_device
);
2954 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
2956 ibm_backlight_device
->props
.max_brightness
= 7;
2957 ibm_backlight_device
->props
.brightness
= b
;
2958 backlight_update_status(ibm_backlight_device
);
2963 static void brightness_exit(void)
2965 if (ibm_backlight_device
) {
2966 vdbg_printk(TPACPI_DBG_EXIT
,
2967 "calling backlight_device_unregister()\n");
2968 backlight_device_unregister(ibm_backlight_device
);
2969 ibm_backlight_device
= NULL
;
2973 static int brightness_update_status(struct backlight_device
*bd
)
2975 return brightness_set(
2976 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
2977 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
2978 bd
->props
.brightness
: 0);
2981 static int brightness_get(struct backlight_device
*bd
)
2984 if (!acpi_ec_read(brightness_offset
, &level
))
2992 static int brightness_set(int value
)
2994 int cmos_cmd
, inc
, i
;
2995 int current_value
= brightness_get(NULL
);
2999 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
3000 inc
= value
> current_value
? 1 : -1;
3001 for (i
= current_value
; i
!= value
; i
+= inc
) {
3002 if (issue_thinkpad_cmos_command(cmos_cmd
))
3004 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
3011 static int brightness_read(char *p
)
3016 if ((level
= brightness_get(NULL
)) < 0) {
3017 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3019 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
3020 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3021 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3022 " (<level> is 0-7)\n");
3028 static int brightness_write(char *buf
)
3034 while ((cmd
= next_cmd(&buf
))) {
3035 if ((level
= brightness_get(NULL
)) < 0)
3039 if (strlencmp(cmd
, "up") == 0) {
3040 new_level
= level
== 7 ? 7 : level
+ 1;
3041 } else if (strlencmp(cmd
, "down") == 0) {
3042 new_level
= level
== 0 ? 0 : level
- 1;
3043 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3044 new_level
>= 0 && new_level
<= 7) {
3049 brightness_set(new_level
);
3055 static struct ibm_struct brightness_driver_data
= {
3056 .name
= "brightness",
3057 .read
= brightness_read
,
3058 .write
= brightness_write
,
3059 .exit
= brightness_exit
,
3062 /*************************************************************************
3066 static int volume_read(char *p
)
3071 if (!acpi_ec_read(volume_offset
, &level
)) {
3072 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3074 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3075 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3076 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3077 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3078 " (<level> is 0-15)\n");
3084 static int volume_write(char *buf
)
3086 int cmos_cmd
, inc
, i
;
3088 int new_level
, new_mute
;
3091 while ((cmd
= next_cmd(&buf
))) {
3092 if (!acpi_ec_read(volume_offset
, &level
))
3094 new_mute
= mute
= level
& 0x40;
3095 new_level
= level
= level
& 0xf;
3097 if (strlencmp(cmd
, "up") == 0) {
3101 new_level
= level
== 15 ? 15 : level
+ 1;
3102 } else if (strlencmp(cmd
, "down") == 0) {
3106 new_level
= level
== 0 ? 0 : level
- 1;
3107 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3108 new_level
>= 0 && new_level
<= 15) {
3110 } else if (strlencmp(cmd
, "mute") == 0) {
3115 if (new_level
!= level
) { /* mute doesn't change */
3116 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3117 inc
= new_level
> level
? 1 : -1;
3119 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3120 !acpi_ec_write(volume_offset
, level
)))
3123 for (i
= level
; i
!= new_level
; i
+= inc
)
3124 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3125 !acpi_ec_write(volume_offset
, i
+ inc
))
3128 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3129 !acpi_ec_write(volume_offset
,
3134 if (new_mute
!= mute
) { /* level doesn't change */
3135 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3137 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3138 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3146 static struct ibm_struct volume_driver_data
= {
3148 .read
= volume_read
,
3149 .write
= volume_write
,
3152 /*************************************************************************
3159 * TPACPI_FAN_RD_ACPI_GFAN:
3160 * ACPI GFAN method: returns fan level
3162 * see TPACPI_FAN_WR_ACPI_SFAN
3163 * EC 0x2f (HFSP) not available if GFAN exists
3165 * TPACPI_FAN_WR_ACPI_SFAN:
3166 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3168 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3171 * TPACPI_FAN_WR_TPEC:
3172 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3173 * Supported on almost all ThinkPads
3175 * Fan speed changes of any sort (including those caused by the
3176 * disengaged mode) are usually done slowly by the firmware as the
3177 * maximum ammount of fan duty cycle change per second seems to be
3180 * Reading is not available if GFAN exists.
3181 * Writing is not available if SFAN exists.
3184 * 7 automatic mode engaged;
3185 * (default operation mode of the ThinkPad)
3186 * fan level is ignored in this mode.
3187 * 6 full speed mode (takes precedence over bit 7);
3188 * not available on all thinkpads. May disable
3189 * the tachometer while the fan controller ramps up
3190 * the speed (which can take up to a few *minutes*).
3191 * Speeds up fan to 100% duty-cycle, which is far above
3192 * the standard RPM levels. It is not impossible that
3193 * it could cause hardware damage.
3194 * 5-3 unused in some models. Extra bits for fan level
3195 * in others, but still useless as all values above
3196 * 7 map to the same speed as level 7 in these models.
3197 * 2-0 fan level (0..7 usually)
3199 * 0x07 = max (set when temperatures critical)
3200 * Some ThinkPads may have other levels, see
3201 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3203 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3204 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3205 * does so, its initial value is meaningless (0x07).
3207 * For firmware bugs, refer to:
3208 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3212 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3213 * Main fan tachometer reading (in RPM)
3215 * This register is present on all ThinkPads with a new-style EC, and
3216 * it is known not to be present on the A21m/e, and T22, as there is
3217 * something else in offset 0x84 according to the ACPI DSDT. Other
3218 * ThinkPads from this same time period (and earlier) probably lack the
3219 * tachometer as well.
3221 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3222 * was never fixed by IBM to report the EC firmware version string
3223 * probably support the tachometer (like the early X models), so
3224 * detecting it is quite hard. We need more data to know for sure.
3226 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3229 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3232 * For firmware bugs, refer to:
3233 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3235 * TPACPI_FAN_WR_ACPI_FANS:
3236 * ThinkPad X31, X40, X41. Not available in the X60.
3238 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3239 * high speed. ACPI DSDT seems to map these three speeds to levels
3240 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3241 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3243 * The speeds are stored on handles
3244 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3246 * There are three default speed sets, acessible as handles:
3247 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3249 * ACPI DSDT switches which set is in use depending on various
3252 * TPACPI_FAN_WR_TPEC is also available and should be used to
3253 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3254 * but the ACPI tables just mention level 7.
3257 static enum fan_status_access_mode fan_status_access_mode
;
3258 static enum fan_control_access_mode fan_control_access_mode
;
3259 static enum fan_control_commands fan_control_commands
;
3261 static u8 fan_control_initial_status
;
3262 static u8 fan_control_desired_level
;
3264 static void fan_watchdog_fire(struct work_struct
*ignored
);
3265 static int fan_watchdog_maxinterval
;
3266 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3268 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3269 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3270 "\\FSPD", /* 600e/x, 770e, 770x */
3272 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3273 "JFNS", /* 770x-JL */
3277 * SYSFS fan layout: hwmon compatible (device)
3280 * 0: "disengaged" mode
3282 * 2: native EC "auto" mode (recommended, hardware default)
3284 * pwm*: set speed in manual mode, ignored otherwise.
3285 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3288 * fan*_input: tachometer reading, RPM
3291 * SYSFS fan layout: extensions
3293 * fan_watchdog (driver):
3294 * fan watchdog interval in seconds, 0 disables (default), max 120
3297 /* sysfs fan pwm1_enable ----------------------------------------------- */
3298 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3299 struct device_attribute
*attr
,
3305 res
= fan_get_status_safe(&status
);
3309 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3310 if (status
!= fan_control_initial_status
) {
3311 tp_features
.fan_ctrl_status_undef
= 0;
3313 /* Return most likely status. In fact, it
3314 * might be the only possible status */
3315 status
= TP_EC_FAN_AUTO
;
3319 if (status
& TP_EC_FAN_FULLSPEED
) {
3321 } else if (status
& TP_EC_FAN_AUTO
) {
3326 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3329 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3330 struct device_attribute
*attr
,
3331 const char *buf
, size_t count
)
3336 if (parse_strtoul(buf
, 2, &t
))
3341 level
= TP_EC_FAN_FULLSPEED
;
3344 level
= TPACPI_FAN_LAST_LEVEL
;
3347 level
= TP_EC_FAN_AUTO
;
3350 /* reserved for software-controlled auto mode */
3356 res
= fan_set_level_safe(level
);
3362 fan_watchdog_reset();
3367 static struct device_attribute dev_attr_fan_pwm1_enable
=
3368 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3369 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3371 /* sysfs fan pwm1 ------------------------------------------------------ */
3372 static ssize_t
fan_pwm1_show(struct device
*dev
,
3373 struct device_attribute
*attr
,
3379 res
= fan_get_status_safe(&status
);
3383 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3384 if (status
!= fan_control_initial_status
) {
3385 tp_features
.fan_ctrl_status_undef
= 0;
3387 status
= TP_EC_FAN_AUTO
;
3392 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3393 status
= fan_control_desired_level
;
3398 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3401 static ssize_t
fan_pwm1_store(struct device
*dev
,
3402 struct device_attribute
*attr
,
3403 const char *buf
, size_t count
)
3407 u8 status
, newlevel
;
3409 if (parse_strtoul(buf
, 255, &s
))
3412 /* scale down from 0-255 to 0-7 */
3413 newlevel
= (s
>> 5) & 0x07;
3415 rc
= mutex_lock_interruptible(&fan_mutex
);
3419 rc
= fan_get_status(&status
);
3420 if (!rc
&& (status
&
3421 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3422 rc
= fan_set_level(newlevel
);
3426 fan_update_desired_level(newlevel
);
3427 fan_watchdog_reset();
3431 mutex_unlock(&fan_mutex
);
3432 return (rc
)? rc
: count
;
3435 static struct device_attribute dev_attr_fan_pwm1
=
3436 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3437 fan_pwm1_show
, fan_pwm1_store
);
3439 /* sysfs fan fan1_input ------------------------------------------------ */
3440 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3441 struct device_attribute
*attr
,
3447 res
= fan_get_speed(&speed
);
3451 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3454 static struct device_attribute dev_attr_fan_fan1_input
=
3455 __ATTR(fan1_input
, S_IRUGO
,
3456 fan_fan1_input_show
, NULL
);
3458 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
3459 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3462 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3465 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3466 const char *buf
, size_t count
)
3470 if (parse_strtoul(buf
, 120, &t
))
3473 if (!fan_control_allowed
)
3476 fan_watchdog_maxinterval
= t
;
3477 fan_watchdog_reset();
3482 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3483 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3485 /* --------------------------------------------------------------------- */
3486 static struct attribute
*fan_attributes
[] = {
3487 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3488 &dev_attr_fan_fan1_input
.attr
,
3492 static const struct attribute_group fan_attr_group
= {
3493 .attrs
= fan_attributes
,
3496 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3500 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3502 mutex_init(&fan_mutex
);
3503 fan_status_access_mode
= TPACPI_FAN_NONE
;
3504 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3505 fan_control_commands
= 0;
3506 fan_watchdog_maxinterval
= 0;
3507 tp_features
.fan_ctrl_status_undef
= 0;
3508 fan_control_desired_level
= 7;
3510 IBM_ACPIHANDLE_INIT(fans
);
3511 IBM_ACPIHANDLE_INIT(gfan
);
3512 IBM_ACPIHANDLE_INIT(sfan
);
3515 /* 570, 600e/x, 770e, 770x */
3516 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3518 /* all other ThinkPads: note that even old-style
3519 * ThinkPad ECs supports the fan control register */
3520 if (likely(acpi_ec_read(fan_status_offset
,
3521 &fan_control_initial_status
))) {
3522 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3524 /* In some ThinkPads, neither the EC nor the ACPI
3525 * DSDT initialize the fan status, and it ends up
3526 * being set to 0x07 when it *could* be either
3529 * Enable for TP-1Y (T43), TP-78 (R51e),
3530 * TP-76 (R52), TP-70 (T43, R52), which are known
3532 if (fan_control_initial_status
== 0x07 &&
3533 ibm_thinkpad_ec_found
&&
3534 ((ibm_thinkpad_ec_found
[0] == '1' &&
3535 ibm_thinkpad_ec_found
[1] == 'Y') ||
3536 (ibm_thinkpad_ec_found
[0] == '7' &&
3537 (ibm_thinkpad_ec_found
[1] == '6' ||
3538 ibm_thinkpad_ec_found
[1] == '8' ||
3539 ibm_thinkpad_ec_found
[1] == '0'))
3542 "fan_init: initial fan status is "
3543 "unknown, assuming it is in auto "
3545 tp_features
.fan_ctrl_status_undef
= 1;
3549 "ThinkPad ACPI EC access misbehaving, "
3550 "fan status and control unavailable\n");
3557 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3558 fan_control_commands
|=
3559 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3562 /* gfan without sfan means no fan control */
3563 /* all other models implement TP EC 0x2f control */
3567 fan_control_access_mode
=
3568 TPACPI_FAN_WR_ACPI_FANS
;
3569 fan_control_commands
|=
3570 TPACPI_FAN_CMD_SPEED
|
3571 TPACPI_FAN_CMD_LEVEL
|
3572 TPACPI_FAN_CMD_ENABLE
;
3574 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3575 fan_control_commands
|=
3576 TPACPI_FAN_CMD_LEVEL
|
3577 TPACPI_FAN_CMD_ENABLE
;
3582 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3583 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3584 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3585 fan_status_access_mode
, fan_control_access_mode
);
3587 /* fan control master switch */
3588 if (!fan_control_allowed
) {
3589 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3590 fan_control_commands
= 0;
3591 dbg_printk(TPACPI_DBG_INIT
,
3592 "fan control features disabled by parameter\n");
3595 /* update fan_control_desired_level */
3596 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3597 fan_get_status_safe(NULL
);
3599 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3600 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3601 rc
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3604 rc
= driver_create_file(&tpacpi_pdriver
.driver
,
3605 &driver_attr_fan_watchdog
);
3614 * Call with fan_mutex held
3616 static void fan_update_desired_level(u8 status
)
3619 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3621 fan_control_desired_level
= 7;
3623 fan_control_desired_level
= status
;
3627 static int fan_get_status(u8
*status
)
3632 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3634 switch (fan_status_access_mode
) {
3635 case TPACPI_FAN_RD_ACPI_GFAN
:
3636 /* 570, 600e/x, 770e, 770x */
3638 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
3646 case TPACPI_FAN_RD_TPEC
:
3647 /* all except 570, 600e/x, 770e, 770x */
3648 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
3663 static int fan_get_status_safe(u8
*status
)
3668 rc
= mutex_lock_interruptible(&fan_mutex
);
3671 rc
= fan_get_status(&s
);
3673 fan_update_desired_level(s
);
3674 mutex_unlock(&fan_mutex
);
3682 static void fan_exit(void)
3684 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
3686 /* FIXME: can we really do this unconditionally? */
3687 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
, &fan_attr_group
);
3688 driver_remove_file(&tpacpi_pdriver
.driver
, &driver_attr_fan_watchdog
);
3690 cancel_delayed_work(&fan_watchdog_task
);
3691 flush_scheduled_work();
3694 static int fan_get_speed(unsigned int *speed
)
3698 switch (fan_status_access_mode
) {
3699 case TPACPI_FAN_RD_TPEC
:
3700 /* all except 570, 600e/x, 770e, 770x */
3701 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
3702 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
3706 *speed
= (hi
<< 8) | lo
;
3717 static void fan_watchdog_fire(struct work_struct
*ignored
)
3721 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
3722 rc
= fan_set_enable();
3724 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
3725 "will try again later...\n", -rc
);
3726 /* reschedule for later */
3727 fan_watchdog_reset();
3731 static void fan_watchdog_reset(void)
3733 static int fan_watchdog_active
;
3735 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
3738 if (fan_watchdog_active
)
3739 cancel_delayed_work(&fan_watchdog_task
);
3741 if (fan_watchdog_maxinterval
> 0) {
3742 fan_watchdog_active
= 1;
3743 if (!schedule_delayed_work(&fan_watchdog_task
,
3744 msecs_to_jiffies(fan_watchdog_maxinterval
3746 printk(IBM_ERR
"failed to schedule the fan watchdog, "
3747 "watchdog will not trigger\n");
3750 fan_watchdog_active
= 0;
3753 static int fan_set_level(int level
)
3755 if (!fan_control_allowed
)
3758 switch (fan_control_access_mode
) {
3759 case TPACPI_FAN_WR_ACPI_SFAN
:
3760 if (level
>= 0 && level
<= 7) {
3761 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
3767 case TPACPI_FAN_WR_ACPI_FANS
:
3768 case TPACPI_FAN_WR_TPEC
:
3769 if ((level
!= TP_EC_FAN_AUTO
) &&
3770 (level
!= TP_EC_FAN_FULLSPEED
) &&
3771 ((level
< 0) || (level
> 7)))
3774 /* safety net should the EC not support AUTO
3775 * or FULLSPEED mode bits and just ignore them */
3776 if (level
& TP_EC_FAN_FULLSPEED
)
3777 level
|= 7; /* safety min speed 7 */
3778 else if (level
& TP_EC_FAN_FULLSPEED
)
3779 level
|= 4; /* safety min speed 4 */
3781 if (!acpi_ec_write(fan_status_offset
, level
))
3784 tp_features
.fan_ctrl_status_undef
= 0;
3793 static int fan_set_level_safe(int level
)
3797 if (!fan_control_allowed
)
3800 rc
= mutex_lock_interruptible(&fan_mutex
);
3804 if (level
== TPACPI_FAN_LAST_LEVEL
)
3805 level
= fan_control_desired_level
;
3807 rc
= fan_set_level(level
);
3809 fan_update_desired_level(level
);
3811 mutex_unlock(&fan_mutex
);
3815 static int fan_set_enable(void)
3820 if (!fan_control_allowed
)
3823 rc
= mutex_lock_interruptible(&fan_mutex
);
3827 switch (fan_control_access_mode
) {
3828 case TPACPI_FAN_WR_ACPI_FANS
:
3829 case TPACPI_FAN_WR_TPEC
:
3830 rc
= fan_get_status(&s
);
3834 /* Don't go out of emergency fan mode */
3837 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
3840 if (!acpi_ec_write(fan_status_offset
, s
))
3843 tp_features
.fan_ctrl_status_undef
= 0;
3848 case TPACPI_FAN_WR_ACPI_SFAN
:
3849 rc
= fan_get_status(&s
);
3855 /* Set fan to at least level 4 */
3858 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
3868 mutex_unlock(&fan_mutex
);
3872 static int fan_set_disable(void)
3876 if (!fan_control_allowed
)
3879 rc
= mutex_lock_interruptible(&fan_mutex
);
3884 switch (fan_control_access_mode
) {
3885 case TPACPI_FAN_WR_ACPI_FANS
:
3886 case TPACPI_FAN_WR_TPEC
:
3887 if (!acpi_ec_write(fan_status_offset
, 0x00))
3890 fan_control_desired_level
= 0;
3891 tp_features
.fan_ctrl_status_undef
= 0;
3895 case TPACPI_FAN_WR_ACPI_SFAN
:
3896 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
3899 fan_control_desired_level
= 0;
3907 mutex_unlock(&fan_mutex
);
3911 static int fan_set_speed(int speed
)
3915 if (!fan_control_allowed
)
3918 rc
= mutex_lock_interruptible(&fan_mutex
);
3923 switch (fan_control_access_mode
) {
3924 case TPACPI_FAN_WR_ACPI_FANS
:
3925 if (speed
>= 0 && speed
<= 65535) {
3926 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
3927 speed
, speed
, speed
))
3937 mutex_unlock(&fan_mutex
);
3941 static int fan_read(char *p
)
3946 unsigned int speed
= 0;
3948 switch (fan_status_access_mode
) {
3949 case TPACPI_FAN_RD_ACPI_GFAN
:
3950 /* 570, 600e/x, 770e, 770x */
3951 if ((rc
= fan_get_status_safe(&status
)) < 0)
3954 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
3956 (status
!= 0) ? "enabled" : "disabled", status
);
3959 case TPACPI_FAN_RD_TPEC
:
3960 /* all except 570, 600e/x, 770e, 770x */
3961 if ((rc
= fan_get_status_safe(&status
)) < 0)
3964 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3965 if (status
!= fan_control_initial_status
)
3966 tp_features
.fan_ctrl_status_undef
= 0;
3968 /* Return most likely status. In fact, it
3969 * might be the only possible status */
3970 status
= TP_EC_FAN_AUTO
;
3973 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3974 (status
!= 0) ? "enabled" : "disabled");
3976 if ((rc
= fan_get_speed(&speed
)) < 0)
3979 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
3981 if (status
& TP_EC_FAN_FULLSPEED
)
3982 /* Disengaged mode takes precedence */
3983 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
3984 else if (status
& TP_EC_FAN_AUTO
)
3985 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
3987 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
3990 case TPACPI_FAN_NONE
:
3992 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3995 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
3996 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
3998 switch (fan_control_access_mode
) {
3999 case TPACPI_FAN_WR_ACPI_SFAN
:
4000 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4004 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4005 "auto, disengaged, full-speed)\n");
4010 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4011 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4012 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4013 "1-120 (seconds))\n");
4015 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4016 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4017 " (<speed> is 0-65535)\n");
4022 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4026 if (strlencmp(cmd
, "level auto") == 0)
4027 level
= TP_EC_FAN_AUTO
;
4028 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4029 (strlencmp(cmd
, "level full-speed") == 0))
4030 level
= TP_EC_FAN_FULLSPEED
;
4031 else if (sscanf(cmd
, "level %d", &level
) != 1)
4034 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4035 printk(IBM_ERR
"level command accepted for unsupported "
4036 "access mode %d", fan_control_access_mode
);
4041 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4043 if (strlencmp(cmd
, "enable") != 0)
4046 if ((*rc
= fan_set_enable()) == -ENXIO
)
4047 printk(IBM_ERR
"enable command accepted for unsupported "
4048 "access mode %d", fan_control_access_mode
);
4053 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4055 if (strlencmp(cmd
, "disable") != 0)
4058 if ((*rc
= fan_set_disable()) == -ENXIO
)
4059 printk(IBM_ERR
"disable command accepted for unsupported "
4060 "access mode %d", fan_control_access_mode
);
4065 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4070 * Support speed <low> <medium> <high> ? */
4072 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4075 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4076 printk(IBM_ERR
"speed command accepted for unsupported "
4077 "access mode %d", fan_control_access_mode
);
4082 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4086 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4089 if (interval
< 0 || interval
> 120)
4092 fan_watchdog_maxinterval
= interval
;
4097 static int fan_write(char *buf
)
4102 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4103 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4104 fan_write_cmd_level(cmd
, &rc
)) &&
4105 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4106 (fan_write_cmd_enable(cmd
, &rc
) ||
4107 fan_write_cmd_disable(cmd
, &rc
) ||
4108 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4109 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4110 fan_write_cmd_speed(cmd
, &rc
))
4114 fan_watchdog_reset();
4120 static struct ibm_struct fan_driver_data
= {
4127 /****************************************************************************
4128 ****************************************************************************
4132 ****************************************************************************
4133 ****************************************************************************/
4136 static struct proc_dir_entry
*proc_dir
;
4138 /* Subdriver registry */
4139 static LIST_HEAD(tpacpi_all_drivers
);
4143 * Module and infrastructure proble, init and exit handling
4146 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4147 static const char * __init
str_supported(int is_supported
)
4149 static char text_unsupported
[] __initdata
= "not supported";
4151 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4153 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4155 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4158 struct ibm_struct
*ibm
= iibm
->data
;
4159 struct proc_dir_entry
*entry
;
4161 BUG_ON(ibm
== NULL
);
4163 INIT_LIST_HEAD(&ibm
->all_drivers
);
4165 if (ibm
->flags
.experimental
&& !experimental
)
4168 dbg_printk(TPACPI_DBG_INIT
,
4169 "probing for %s\n", ibm
->name
);
4172 ret
= iibm
->init(iibm
);
4174 return 0; /* probe failed */
4178 ibm
->flags
.init_called
= 1;
4182 if (ibm
->acpi
->hid
) {
4183 ret
= register_tpacpi_subdriver(ibm
);
4188 if (ibm
->acpi
->notify
) {
4189 ret
= setup_acpi_notify(ibm
);
4190 if (ret
== -ENODEV
) {
4191 printk(IBM_NOTICE
"disabling subdriver %s\n",
4201 dbg_printk(TPACPI_DBG_INIT
,
4202 "%s installed\n", ibm
->name
);
4205 entry
= create_proc_entry(ibm
->name
,
4206 S_IFREG
| S_IRUGO
| S_IWUSR
,
4209 printk(IBM_ERR
"unable to create proc entry %s\n",
4214 entry
->owner
= THIS_MODULE
;
4216 entry
->read_proc
= &dispatch_procfs_read
;
4218 entry
->write_proc
= &dispatch_procfs_write
;
4219 ibm
->flags
.proc_created
= 1;
4222 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4227 dbg_printk(TPACPI_DBG_INIT
,
4228 "%s: at error exit path with result %d\n",
4232 return (ret
< 0)? ret
: 0;
4235 static void ibm_exit(struct ibm_struct
*ibm
)
4237 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4239 list_del_init(&ibm
->all_drivers
);
4241 if (ibm
->flags
.acpi_notify_installed
) {
4242 dbg_printk(TPACPI_DBG_EXIT
,
4243 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4245 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4247 dispatch_acpi_notify
);
4248 ibm
->flags
.acpi_notify_installed
= 0;
4249 ibm
->flags
.acpi_notify_installed
= 0;
4252 if (ibm
->flags
.proc_created
) {
4253 dbg_printk(TPACPI_DBG_EXIT
,
4254 "%s: remove_proc_entry\n", ibm
->name
);
4255 remove_proc_entry(ibm
->name
, proc_dir
);
4256 ibm
->flags
.proc_created
= 0;
4259 if (ibm
->flags
.acpi_driver_registered
) {
4260 dbg_printk(TPACPI_DBG_EXIT
,
4261 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4263 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4264 kfree(ibm
->acpi
->driver
);
4265 ibm
->acpi
->driver
= NULL
;
4266 ibm
->flags
.acpi_driver_registered
= 0;
4269 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4271 ibm
->flags
.init_called
= 0;
4274 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4279 static char *ibm_thinkpad_ec_found
;
4281 static char* __init
check_dmi_for_ec(void)
4283 struct dmi_device
*dev
= NULL
;
4284 char ec_fw_string
[18];
4287 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4288 * X32 or newer, all Z series; Some models must have an
4289 * up-to-date BIOS or they will not be detected.
4291 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4293 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4294 if (sscanf(dev
->name
,
4295 "IBM ThinkPad Embedded Controller -[%17c",
4296 ec_fw_string
) == 1) {
4297 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4298 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4299 return kstrdup(ec_fw_string
, GFP_KERNEL
);
4305 static int __init
probe_for_thinkpad(void)
4313 * Non-ancient models have better DMI tagging, but very old models
4316 is_thinkpad
= dmi_name_in_vendors("ThinkPad");
4318 /* ec is required because many other handles are relative to it */
4319 IBM_ACPIHANDLE_INIT(ec
);
4323 "Not yet supported ThinkPad detected!\n");
4328 * Risks a regression on very old machines, but reduces potential
4329 * false positives a damn great deal
4332 is_thinkpad
= dmi_name_in_vendors("IBM");
4334 if (!is_thinkpad
&& !force_load
)
4341 /* Module init, exit, parameters */
4343 static struct ibm_init_struct ibms_init
[] __initdata
= {
4345 .init
= thinkpad_acpi_driver_init
,
4346 .data
= &thinkpad_acpi_driver_data
,
4349 .init
= hotkey_init
,
4350 .data
= &hotkey_driver_data
,
4353 .init
= bluetooth_init
,
4354 .data
= &bluetooth_driver_data
,
4358 .data
= &wan_driver_data
,
4362 .data
= &video_driver_data
,
4366 .data
= &light_driver_data
,
4368 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4371 .data
= &dock_driver_data
[0],
4375 .data
= &dock_driver_data
[1],
4378 #ifdef CONFIG_THINKPAD_ACPI_BAY
4381 .data
= &bay_driver_data
,
4386 .data
= &cmos_driver_data
,
4390 .data
= &led_driver_data
,
4394 .data
= &beep_driver_data
,
4397 .init
= thermal_init
,
4398 .data
= &thermal_driver_data
,
4401 .data
= &ecdump_driver_data
,
4404 .init
= brightness_init
,
4405 .data
= &brightness_driver_data
,
4408 .data
= &volume_driver_data
,
4412 .data
= &fan_driver_data
,
4416 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4419 struct ibm_struct
*ibm
;
4421 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4422 ibm
= ibms_init
[i
].data
;
4423 BUG_ON(ibm
== NULL
);
4425 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4426 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4428 strcpy(ibms_init
[i
].param
, val
);
4429 strcat(ibms_init
[i
].param
, ",");
4437 static int experimental
;
4438 module_param(experimental
, int, 0);
4440 static u32 dbg_level
;
4441 module_param_named(debug
, dbg_level
, uint
, 0);
4443 static int force_load
;
4444 module_param(force_load
, int, 0);
4446 static int fan_control_allowed
;
4447 module_param_named(fan_control
, fan_control_allowed
, int, 0);
4449 #define IBM_PARAM(feature) \
4450 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4453 IBM_PARAM(bluetooth
);
4456 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4459 #ifdef CONFIG_THINKPAD_ACPI_BAY
4461 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4466 IBM_PARAM(brightness
);
4470 static int __init
thinkpad_acpi_module_init(void)
4474 /* Driver-level probe */
4475 ret
= probe_for_thinkpad();
4479 /* Driver initialization */
4480 ibm_thinkpad_ec_found
= check_dmi_for_ec();
4481 IBM_ACPIHANDLE_INIT(ecrd
);
4482 IBM_ACPIHANDLE_INIT(ecwr
);
4484 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4486 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4487 thinkpad_acpi_module_exit();
4490 proc_dir
->owner
= THIS_MODULE
;
4492 ret
= platform_driver_register(&tpacpi_pdriver
);
4494 printk(IBM_ERR
"unable to register platform driver\n");
4495 thinkpad_acpi_module_exit();
4498 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4500 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4501 thinkpad_acpi_module_exit();
4506 /* Device initialization */
4507 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4509 if (IS_ERR(tpacpi_pdev
)) {
4510 ret
= PTR_ERR(tpacpi_pdev
);
4512 printk(IBM_ERR
"unable to register platform device\n");
4513 thinkpad_acpi_module_exit();
4516 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
4517 if (IS_ERR(tpacpi_hwmon
)) {
4518 ret
= PTR_ERR(tpacpi_hwmon
);
4519 tpacpi_hwmon
= NULL
;
4520 printk(IBM_ERR
"unable to register hwmon device\n");
4521 thinkpad_acpi_module_exit();
4524 tpacpi_inputdev
= input_allocate_device();
4525 if (!tpacpi_inputdev
) {
4526 printk(IBM_ERR
"unable to allocate input device\n");
4527 thinkpad_acpi_module_exit();
4530 /* Prepare input device, but don't register */
4531 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
4532 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
4533 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
4534 tpacpi_inputdev
->id
.vendor
= TPACPI_HKEY_INPUT_VENDOR
;
4535 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
4536 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
4538 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4539 ret
= ibm_init(&ibms_init
[i
]);
4540 if (ret
>= 0 && *ibms_init
[i
].param
)
4541 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
4543 thinkpad_acpi_module_exit();
4547 ret
= input_register_device(tpacpi_inputdev
);
4549 printk(IBM_ERR
"unable to register input device\n");
4550 thinkpad_acpi_module_exit();
4553 tp_features
.input_device_registered
= 1;
4559 static void thinkpad_acpi_module_exit(void)
4561 struct ibm_struct
*ibm
, *itmp
;
4563 list_for_each_entry_safe_reverse(ibm
, itmp
,
4564 &tpacpi_all_drivers
,
4569 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
4571 if (tpacpi_inputdev
) {
4572 if (tp_features
.input_device_registered
)
4573 input_unregister_device(tpacpi_inputdev
);
4575 input_free_device(tpacpi_inputdev
);
4579 hwmon_device_unregister(tpacpi_hwmon
);
4582 platform_device_unregister(tpacpi_pdev
);
4584 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
4585 platform_driver_unregister(&tpacpi_pdriver
);
4588 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
4590 kfree(ibm_thinkpad_ec_found
);
4593 module_init(thinkpad_acpi_module_init
);
4594 module_exit(thinkpad_acpi_module_exit
);