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 0x010000
29 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
32 * 2006-11-22 0.13 new maintainer
33 * changelog now lives in git commit history, and will
34 * not be updated further in-file.
36 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
37 * 2005-03-17 0.11 support for 600e, 770x
38 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
39 * support for 770e, G41
40 * G40 and G41 don't have a thinklight
41 * temperatures no longer experimental
42 * experimental brightness control
43 * experimental volume control
44 * experimental fan enable/disable
45 * 2005-01-16 0.10 fix module loading on R30, R31
46 * 2005-01-16 0.9 support for 570, R30, R31
47 * ultrabay support on A22p, A3x
48 * limit arg for cmos, led, beep, drop experimental status
49 * more capable led control on A21e, A22p, T20-22, X20
50 * experimental temperatures and fan speed
51 * experimental embedded controller register dump
52 * mark more functions as __init, drop incorrect __exit
54 * thanks to Henrik Brix Andersen <brix@gentoo.org>
55 * fix parameter passing on module loading
56 * thanks to Rusty Russell <rusty@rustcorp.com.au>
57 * thanks to Jim Radford <radford@blackbean.org>
58 * 2004-11-08 0.8 fix init error case, don't return from a macro
59 * thanks to Chris Wright <chrisw@osdl.org>
60 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
61 * fix led control on A21e
62 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
63 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
64 * proc file format changed
65 * video_switch command
66 * experimental cmos control
67 * experimental led control
68 * experimental acpi sounds
69 * 2004-09-16 0.4 support for module parameters
70 * hotkey mask can be prefixed by 0x
71 * video output switching
72 * video expansion control
73 * ultrabay eject support
74 * removed lcd brightness/on/off control, didn't work
75 * 2004-08-17 0.3 support for R40
76 * lcd off, brightness control
78 * 2004-08-14 0.2 support for T series, X20
79 * bluetooth enable/disable
80 * hotkey events disabled by default
81 * removed fan control, currently useless
82 * 2004-08-09 0.1 initial release, support for X series
85 #include "thinkpad_acpi.h"
87 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
88 MODULE_DESCRIPTION(IBM_DESC
);
89 MODULE_VERSION(IBM_VERSION
);
90 MODULE_LICENSE("GPL");
92 /* Please remove this in year 2009 */
93 MODULE_ALIAS("ibm_acpi");
96 * DMI matching for module autoloading
98 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
99 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
101 * Only models listed in thinkwiki will be supported, so add yours
102 * if it is not there yet.
104 #define IBM_BIOS_MODULE_ALIAS(__type) \
105 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
107 /* Non-ancient thinkpads */
108 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
109 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
111 /* Ancient thinkpad BIOSes have to be identified by
112 * BIOS type or model number, and there are far less
113 * BIOS types than model numbers... */
114 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
115 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
116 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
118 #define __unused __attribute__ ((unused))
120 /****************************************************************************
121 ****************************************************************************
123 * ACPI Helpers and device model
125 ****************************************************************************
126 ****************************************************************************/
128 /*************************************************************************
132 static acpi_handle root_handle
;
134 #define IBM_HANDLE(object, parent, paths...) \
135 static acpi_handle object##_handle; \
136 static acpi_handle *object##_parent = &parent##_handle; \
137 static char *object##_path; \
138 static char *object##_paths[] = { paths }
140 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
141 "\\_SB.PCI.ISA.EC", /* 570 */
142 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
143 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
144 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
145 "\\_SB.PCI0.ICH3.EC0", /* R31 */
146 "\\_SB.PCI0.LPC.EC", /* all others */
149 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
150 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
153 /*************************************************************************
157 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
158 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
159 "\\CMS", /* R40, R40e */
162 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
163 "^HKEY", /* R30, R31 */
164 "HKEY", /* all others */
168 /*************************************************************************
172 static int acpi_evalf(acpi_handle handle
,
173 void *res
, char *method
, char *fmt
, ...)
176 struct acpi_object_list params
;
177 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
178 struct acpi_buffer result
, *resultp
;
179 union acpi_object out_obj
;
187 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
200 params
.pointer
= &in_objs
[0];
207 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
208 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
210 /* add more types as needed */
212 printk(IBM_ERR
"acpi_evalf() called "
213 "with invalid format character '%c'\n", c
);
219 if (res_type
!= 'v') {
220 result
.length
= sizeof(out_obj
);
221 result
.pointer
= &out_obj
;
226 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
231 *(int *)res
= out_obj
.integer
.value
;
232 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
235 success
= status
== AE_OK
;
237 /* add more types as needed */
239 printk(IBM_ERR
"acpi_evalf() called "
240 "with invalid format character '%c'\n", res_type
);
244 if (!success
&& !quiet
)
245 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
246 method
, fmt0
, status
);
251 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
255 if (acpi_evalf(handle
, &i
, method
, "d"))
256 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
258 printk(IBM_ERR
"error calling %s\n", method
);
261 static int acpi_ec_read(int i
, u8
* p
)
266 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
270 if (ec_read(i
, p
) < 0)
277 static int acpi_ec_write(int i
, u8 v
)
280 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
283 if (ec_write(i
, v
) < 0)
290 static int _sta(acpi_handle handle
)
294 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
300 static int issue_thinkpad_cmos_command(int cmos_cmd
)
305 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
311 /*************************************************************************
315 static void drv_acpi_handle_init(char *name
,
316 acpi_handle
*handle
, acpi_handle parent
,
317 char **paths
, int num_paths
, char **path
)
322 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
325 for (i
= 0; i
< num_paths
; i
++) {
326 status
= acpi_get_handle(parent
, paths
[i
], handle
);
327 if (ACPI_SUCCESS(status
)) {
329 dbg_printk(TPACPI_DBG_INIT
,
330 "Found ACPI handle %s for %s\n",
336 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
341 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
343 struct ibm_struct
*ibm
= data
;
345 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
348 ibm
->acpi
->notify(ibm
, event
);
351 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
358 if (!*ibm
->acpi
->handle
)
361 vdbg_printk(TPACPI_DBG_INIT
,
362 "setting up ACPI notify for %s\n", ibm
->name
);
364 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
366 printk(IBM_ERR
"acpi_bus_get_device(%s) failed: %d\n",
371 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
372 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
373 IBM_ACPI_EVENT_PREFIX
,
376 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
377 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
378 if (ACPI_FAILURE(status
)) {
379 if (status
== AE_ALREADY_EXISTS
) {
380 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
383 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
388 ibm
->flags
.acpi_notify_installed
= 1;
392 static int __init
tpacpi_device_add(struct acpi_device
*device
)
397 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
401 dbg_printk(TPACPI_DBG_INIT
,
402 "registering %s as an ACPI driver\n", ibm
->name
);
406 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
407 if (!ibm
->acpi
->driver
) {
408 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
412 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
413 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
414 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
416 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
418 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
420 kfree(ibm
->acpi
->driver
);
421 ibm
->acpi
->driver
= NULL
;
423 ibm
->flags
.acpi_driver_registered
= 1;
429 /****************************************************************************
430 ****************************************************************************
434 ****************************************************************************
435 ****************************************************************************/
437 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
438 int count
, int *eof
, void *data
)
440 struct ibm_struct
*ibm
= data
;
443 if (!ibm
|| !ibm
->read
)
446 len
= ibm
->read(page
);
450 if (len
<= off
+ count
)
462 static int dispatch_procfs_write(struct file
*file
,
463 const char __user
* userbuf
,
464 unsigned long count
, void *data
)
466 struct ibm_struct
*ibm
= data
;
470 if (!ibm
|| !ibm
->write
)
473 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
477 if (copy_from_user(kernbuf
, userbuf
, count
)) {
483 strcat(kernbuf
, ",");
484 ret
= ibm
->write(kernbuf
);
493 static char *next_cmd(char **cmds
)
498 while ((end
= strchr(start
, ',')) && end
== start
)
510 /****************************************************************************
511 ****************************************************************************
513 * Device model: input, hwmon and platform
515 ****************************************************************************
516 ****************************************************************************/
518 static struct platform_device
*tpacpi_pdev
;
519 static struct class_device
*tpacpi_hwmon
;
520 static struct input_dev
*tpacpi_inputdev
;
523 static int tpacpi_resume_handler(struct platform_device
*pdev
)
525 struct ibm_struct
*ibm
, *itmp
;
527 list_for_each_entry_safe(ibm
, itmp
,
537 static struct platform_driver tpacpi_pdriver
= {
539 .name
= IBM_DRVR_NAME
,
540 .owner
= THIS_MODULE
,
542 .resume
= tpacpi_resume_handler
,
546 /*************************************************************************
547 * thinkpad-acpi driver attributes
550 /* interface_version --------------------------------------------------- */
551 static ssize_t
tpacpi_driver_interface_version_show(
552 struct device_driver
*drv
,
555 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
558 static DRIVER_ATTR(interface_version
, S_IRUGO
,
559 tpacpi_driver_interface_version_show
, NULL
);
561 /* debug_level --------------------------------------------------------- */
562 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
565 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
568 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
569 const char *buf
, size_t count
)
573 if (parse_strtoul(buf
, 0xffff, &t
))
581 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
582 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
584 /* version ------------------------------------------------------------- */
585 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
588 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
591 static DRIVER_ATTR(version
, S_IRUGO
,
592 tpacpi_driver_version_show
, NULL
);
594 /* --------------------------------------------------------------------- */
596 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
597 &driver_attr_debug_level
, &driver_attr_version
,
598 &driver_attr_interface_version
,
601 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
607 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
608 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
615 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
619 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
620 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
623 /*************************************************************************
624 * sysfs support helpers
627 struct attribute_set_obj
{
628 struct attribute_set s
;
630 } __attribute__((packed
));
632 static struct attribute_set
*create_attr_set(unsigned int max_members
,
635 struct attribute_set_obj
*sobj
;
637 if (max_members
== 0)
640 /* Allocates space for implicit NULL at the end too */
641 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
642 max_members
* sizeof(struct attribute
*),
646 sobj
->s
.max_members
= max_members
;
647 sobj
->s
.group
.attrs
= &sobj
->a
;
648 sobj
->s
.group
.name
= name
;
653 /* not multi-threaded safe, use it in a single thread per set */
654 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
659 if (s
->members
>= s
->max_members
)
662 s
->group
.attrs
[s
->members
] = attr
;
668 static int add_many_to_attr_set(struct attribute_set
* s
,
669 struct attribute
**attr
,
674 for (i
= 0; i
< count
; i
++) {
675 res
= add_to_attr_set(s
, attr
[i
]);
683 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
685 sysfs_remove_group(kobj
, &s
->group
);
689 static int parse_strtoul(const char *buf
,
690 unsigned long max
, unsigned long *value
)
694 *value
= simple_strtoul(buf
, &endp
, 0);
695 while (*endp
&& isspace(*endp
))
697 if (*endp
|| *value
> max
)
703 /****************************************************************************
704 ****************************************************************************
708 ****************************************************************************
709 ****************************************************************************/
711 /*************************************************************************
712 * thinkpad-acpi init subdriver
715 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
717 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
718 printk(IBM_INFO
"%s\n", IBM_URL
);
720 printk(IBM_INFO
"ThinkPad BIOS %s, EC %s\n",
721 (thinkpad_id
.bios_version_str
) ?
722 thinkpad_id
.bios_version_str
: "unknown",
723 (thinkpad_id
.ec_version_str
) ?
724 thinkpad_id
.ec_version_str
: "unknown");
726 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
727 printk(IBM_INFO
"%s %s\n",
728 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
729 "IBM" : ((thinkpad_id
.vendor
==
730 PCI_VENDOR_ID_LENOVO
) ?
731 "Lenovo" : "Unknown vendor"),
732 thinkpad_id
.model_str
);
737 static int thinkpad_acpi_driver_read(char *p
)
741 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
742 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
747 static struct ibm_struct thinkpad_acpi_driver_data
= {
749 .read
= thinkpad_acpi_driver_read
,
752 /*************************************************************************
756 static int hotkey_orig_status
;
757 static u32 hotkey_orig_mask
;
758 static u32 hotkey_all_mask
;
759 static u32 hotkey_reserved_mask
;
761 static u16 hotkey_keycode_map
[] = {
762 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
763 KEY_FN_F1
, KEY_FN_F2
, KEY_FN_F3
, KEY_SLEEP
,
764 KEY_FN_F5
, KEY_FN_F6
, KEY_FN_F7
, KEY_FN_F8
,
765 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
766 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
767 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
768 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
769 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
770 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
771 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
772 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
773 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
774 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
775 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
776 KEY_RESERVED
, /* 0x14: VOLUME UP */
777 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
778 KEY_RESERVED
, /* 0x16: MUTE */
779 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
780 /* (assignments unknown, please report if found) */
781 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
782 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
785 static struct attribute_set
*hotkey_dev_attributes
;
787 static int hotkey_get_wlsw(int *status
)
789 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
794 /* sysfs hotkey enable ------------------------------------------------- */
795 static ssize_t
hotkey_enable_show(struct device
*dev
,
796 struct device_attribute
*attr
,
802 res
= hotkey_get(&status
, &mask
);
806 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
809 static ssize_t
hotkey_enable_store(struct device
*dev
,
810 struct device_attribute
*attr
,
811 const char *buf
, size_t count
)
817 if (parse_strtoul(buf
, 1, &t
))
820 res
= hotkey_get(&status
, &mask
);
822 res
= hotkey_set(t
, mask
);
824 return (res
) ? res
: count
;
827 static struct device_attribute dev_attr_hotkey_enable
=
828 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
829 hotkey_enable_show
, hotkey_enable_store
);
831 /* sysfs hotkey mask --------------------------------------------------- */
832 static ssize_t
hotkey_mask_show(struct device
*dev
,
833 struct device_attribute
*attr
,
839 res
= hotkey_get(&status
, &mask
);
843 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
846 static ssize_t
hotkey_mask_store(struct device
*dev
,
847 struct device_attribute
*attr
,
848 const char *buf
, size_t count
)
854 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
857 res
= hotkey_get(&status
, &mask
);
859 hotkey_set(status
, t
);
861 return (res
) ? res
: count
;
864 static struct device_attribute dev_attr_hotkey_mask
=
865 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
866 hotkey_mask_show
, hotkey_mask_store
);
868 /* sysfs hotkey bios_enabled ------------------------------------------- */
869 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
870 struct device_attribute
*attr
,
873 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
876 static struct device_attribute dev_attr_hotkey_bios_enabled
=
877 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
879 /* sysfs hotkey bios_mask ---------------------------------------------- */
880 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
881 struct device_attribute
*attr
,
884 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
887 static struct device_attribute dev_attr_hotkey_bios_mask
=
888 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
890 /* sysfs hotkey all_mask ----------------------------------------------- */
891 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
892 struct device_attribute
*attr
,
895 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_all_mask
);
898 static struct device_attribute dev_attr_hotkey_all_mask
=
899 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
901 /* sysfs hotkey recommended_mask --------------------------------------- */
902 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
903 struct device_attribute
*attr
,
906 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
907 hotkey_all_mask
& ~hotkey_reserved_mask
);
910 static struct device_attribute dev_attr_hotkey_recommended_mask
=
911 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
912 hotkey_recommended_mask_show
, NULL
);
914 /* sysfs hotkey radio_sw ----------------------------------------------- */
915 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
916 struct device_attribute
*attr
,
920 res
= hotkey_get_wlsw(&s
);
924 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
927 static struct device_attribute dev_attr_hotkey_radio_sw
=
928 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
930 /* --------------------------------------------------------------------- */
932 static struct attribute
*hotkey_mask_attributes
[] = {
933 &dev_attr_hotkey_mask
.attr
,
934 &dev_attr_hotkey_bios_enabled
.attr
,
935 &dev_attr_hotkey_bios_mask
.attr
,
936 &dev_attr_hotkey_all_mask
.attr
,
937 &dev_attr_hotkey_recommended_mask
.attr
,
940 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
945 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
947 BUG_ON(!tpacpi_inputdev
);
949 IBM_ACPIHANDLE_INIT(hkey
);
950 mutex_init(&hotkey_mutex
);
952 /* hotkey not supported on 570 */
953 tp_features
.hotkey
= hkey_handle
!= NULL
;
955 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
956 str_supported(tp_features
.hotkey
));
958 if (tp_features
.hotkey
) {
959 hotkey_dev_attributes
= create_attr_set(7, NULL
);
960 if (!hotkey_dev_attributes
)
962 res
= add_to_attr_set(hotkey_dev_attributes
,
963 &dev_attr_hotkey_enable
.attr
);
967 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
968 A30, R30, R31, T20-22, X20-21, X22-24 */
969 tp_features
.hotkey_mask
=
970 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
972 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
973 str_supported(tp_features
.hotkey_mask
));
975 if (tp_features
.hotkey_mask
) {
976 /* MHKA available in A31, R40, R40e, T4x, X31, and later */
977 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
979 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
982 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
983 if (!res
&& tp_features
.hotkey_mask
) {
984 res
= add_many_to_attr_set(hotkey_dev_attributes
,
985 hotkey_mask_attributes
,
986 ARRAY_SIZE(hotkey_mask_attributes
));
989 /* Not all thinkpads have a hardware radio switch */
990 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
991 tp_features
.hotkey_wlsw
= 1;
993 "radio switch found; radios are %s\n",
995 res
= add_to_attr_set(hotkey_dev_attributes
,
996 &dev_attr_hotkey_radio_sw
.attr
);
1000 res
= register_attr_set_with_sysfs(
1001 hotkey_dev_attributes
,
1002 &tpacpi_pdev
->dev
.kobj
);
1006 #ifndef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
1007 for (i
= 0; i
< 12; i
++)
1008 hotkey_keycode_map
[i
] = KEY_UNKNOWN
;
1009 #endif /* ! CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
1011 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1012 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1013 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1014 tpacpi_inputdev
->keycodesize
= sizeof(hotkey_keycode_map
[0]);
1015 tpacpi_inputdev
->keycodemax
= ARRAY_SIZE(hotkey_keycode_map
);
1016 tpacpi_inputdev
->keycode
= &hotkey_keycode_map
;
1017 for (i
= 0; i
< ARRAY_SIZE(hotkey_keycode_map
); i
++) {
1018 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1019 set_bit(hotkey_keycode_map
[i
],
1020 tpacpi_inputdev
->keybit
);
1022 if (i
< sizeof(hotkey_reserved_mask
)*8)
1023 hotkey_reserved_mask
|= 1 << i
;
1027 if (tp_features
.hotkey_wlsw
) {
1028 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1029 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1032 #ifdef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
1033 dbg_printk(TPACPI_DBG_INIT
,
1034 "enabling hot key handling\n");
1035 res
= hotkey_set(1, (hotkey_all_mask
& ~hotkey_reserved_mask
)
1036 | hotkey_orig_mask
);
1039 #endif /* CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
1042 return (tp_features
.hotkey
)? 0 : 1;
1045 static void hotkey_exit(void)
1049 if (tp_features
.hotkey
) {
1050 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
1051 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
1053 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
1056 if (hotkey_dev_attributes
) {
1057 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1058 hotkey_dev_attributes
= NULL
;
1062 static void tpacpi_input_send_key(unsigned int scancode
,
1063 unsigned int keycode
)
1065 if (keycode
!= KEY_RESERVED
) {
1066 input_report_key(tpacpi_inputdev
, keycode
, 1);
1067 if (keycode
== KEY_UNKNOWN
)
1068 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1070 input_sync(tpacpi_inputdev
);
1072 input_report_key(tpacpi_inputdev
, keycode
, 0);
1073 if (keycode
== KEY_UNKNOWN
)
1074 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1076 input_sync(tpacpi_inputdev
);
1080 static void tpacpi_input_send_radiosw(void)
1084 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
))
1085 input_report_switch(tpacpi_inputdev
,
1089 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1092 unsigned int keycode
, scancode
;
1095 if (event
== 0x80 && acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1096 if (tpacpi_inputdev
->users
> 0) {
1097 switch (hkey
>> 12) {
1099 /* 0x1000-0x1FFF: key presses */
1100 scancode
= hkey
& 0xfff;
1101 if (scancode
> 0 && scancode
< 0x21) {
1103 keycode
= hotkey_keycode_map
[scancode
];
1104 tpacpi_input_send_key(scancode
, keycode
);
1105 sendacpi
= (keycode
== KEY_RESERVED
1106 || keycode
== KEY_UNKNOWN
);
1109 "hotkey 0x%04x out of range for keyboard map\n",
1114 /* 0x5000-0x5FFF: LID */
1115 /* we don't handle it through this path, just
1116 * eat up known LID events */
1117 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1119 "unknown LID-related hotkey event: 0x%04x\n",
1124 /* 0x7000-0x7FFF: misc */
1125 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1126 tpacpi_input_send_radiosw();
1130 /* fallthrough to default */
1132 /* case 2: dock-related */
1133 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1134 /* case 3: ultra-bay related. maybe bay in dock? */
1135 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1136 printk(IBM_NOTICE
"unhandled hotkey event 0x%04x\n", hkey
);
1141 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
1143 printk(IBM_ERR
"unknown hotkey notification event %d\n", event
);
1144 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1148 static void hotkey_resume(void)
1150 tpacpi_input_send_radiosw();
1154 * Call with hotkey_mutex held
1156 static int hotkey_get(int *status
, u32
*mask
)
1158 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1161 if (tp_features
.hotkey_mask
)
1162 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1169 * Call with hotkey_mutex held
1171 static int hotkey_set(int status
, u32 mask
)
1175 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1178 if (tp_features
.hotkey_mask
)
1179 for (i
= 0; i
< 32; i
++) {
1180 int bit
= ((1 << i
) & mask
) != 0;
1181 if (!acpi_evalf(hkey_handle
,
1182 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1189 /* procfs -------------------------------------------------------------- */
1190 static int hotkey_read(char *p
)
1196 if (!tp_features
.hotkey
) {
1197 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1201 res
= mutex_lock_interruptible(&hotkey_mutex
);
1204 res
= hotkey_get(&status
, &mask
);
1205 mutex_unlock(&hotkey_mutex
);
1209 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1210 if (tp_features
.hotkey_mask
) {
1211 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1212 len
+= sprintf(p
+ len
,
1213 "commands:\tenable, disable, reset, <mask>\n");
1215 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1216 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1222 static int hotkey_write(char *buf
)
1229 if (!tp_features
.hotkey
)
1232 res
= mutex_lock_interruptible(&hotkey_mutex
);
1236 res
= hotkey_get(&status
, &mask
);
1241 while ((cmd
= next_cmd(&buf
))) {
1242 if (strlencmp(cmd
, "enable") == 0) {
1244 } else if (strlencmp(cmd
, "disable") == 0) {
1246 } else if (strlencmp(cmd
, "reset") == 0) {
1247 status
= hotkey_orig_status
;
1248 mask
= hotkey_orig_mask
;
1249 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1251 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1261 res
= hotkey_set(status
, mask
);
1264 mutex_unlock(&hotkey_mutex
);
1268 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1269 .hid
= IBM_HKEY_HID
,
1270 .notify
= hotkey_notify
,
1271 .handle
= &hkey_handle
,
1272 .type
= ACPI_DEVICE_NOTIFY
,
1275 static struct ibm_struct hotkey_driver_data
= {
1277 .read
= hotkey_read
,
1278 .write
= hotkey_write
,
1279 .exit
= hotkey_exit
,
1280 .resume
= hotkey_resume
,
1281 .acpi
= &ibm_hotkey_acpidriver
,
1284 /*************************************************************************
1285 * Bluetooth subdriver
1288 /* sysfs bluetooth enable ---------------------------------------------- */
1289 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1290 struct device_attribute
*attr
,
1295 status
= bluetooth_get_radiosw();
1299 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1302 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1303 struct device_attribute
*attr
,
1304 const char *buf
, size_t count
)
1309 if (parse_strtoul(buf
, 1, &t
))
1312 res
= bluetooth_set_radiosw(t
);
1314 return (res
) ? res
: count
;
1317 static struct device_attribute dev_attr_bluetooth_enable
=
1318 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1319 bluetooth_enable_show
, bluetooth_enable_store
);
1321 /* --------------------------------------------------------------------- */
1323 static struct attribute
*bluetooth_attributes
[] = {
1324 &dev_attr_bluetooth_enable
.attr
,
1328 static const struct attribute_group bluetooth_attr_group
= {
1329 .attrs
= bluetooth_attributes
,
1332 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1337 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1339 IBM_ACPIHANDLE_INIT(hkey
);
1341 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1342 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1343 tp_features
.bluetooth
= hkey_handle
&&
1344 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1346 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1347 str_supported(tp_features
.bluetooth
),
1350 if (tp_features
.bluetooth
) {
1351 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1352 /* no bluetooth hardware present in system */
1353 tp_features
.bluetooth
= 0;
1354 dbg_printk(TPACPI_DBG_INIT
,
1355 "bluetooth hardware not installed\n");
1357 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1358 &bluetooth_attr_group
);
1364 return (tp_features
.bluetooth
)? 0 : 1;
1367 static void bluetooth_exit(void)
1369 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1370 &bluetooth_attr_group
);
1373 static int bluetooth_get_radiosw(void)
1377 if (!tp_features
.bluetooth
)
1380 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1383 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1386 static int bluetooth_set_radiosw(int radio_on
)
1390 if (!tp_features
.bluetooth
)
1393 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1396 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1398 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1399 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1405 /* procfs -------------------------------------------------------------- */
1406 static int bluetooth_read(char *p
)
1409 int status
= bluetooth_get_radiosw();
1411 if (!tp_features
.bluetooth
)
1412 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1414 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1415 (status
)? "enabled" : "disabled");
1416 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1422 static int bluetooth_write(char *buf
)
1426 if (!tp_features
.bluetooth
)
1429 while ((cmd
= next_cmd(&buf
))) {
1430 if (strlencmp(cmd
, "enable") == 0) {
1431 bluetooth_set_radiosw(1);
1432 } else if (strlencmp(cmd
, "disable") == 0) {
1433 bluetooth_set_radiosw(0);
1441 static struct ibm_struct bluetooth_driver_data
= {
1442 .name
= "bluetooth",
1443 .read
= bluetooth_read
,
1444 .write
= bluetooth_write
,
1445 .exit
= bluetooth_exit
,
1448 /*************************************************************************
1452 /* sysfs wan enable ---------------------------------------------------- */
1453 static ssize_t
wan_enable_show(struct device
*dev
,
1454 struct device_attribute
*attr
,
1459 status
= wan_get_radiosw();
1463 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1466 static ssize_t
wan_enable_store(struct device
*dev
,
1467 struct device_attribute
*attr
,
1468 const char *buf
, size_t count
)
1473 if (parse_strtoul(buf
, 1, &t
))
1476 res
= wan_set_radiosw(t
);
1478 return (res
) ? res
: count
;
1481 static struct device_attribute dev_attr_wan_enable
=
1482 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1483 wan_enable_show
, wan_enable_store
);
1485 /* --------------------------------------------------------------------- */
1487 static struct attribute
*wan_attributes
[] = {
1488 &dev_attr_wan_enable
.attr
,
1492 static const struct attribute_group wan_attr_group
= {
1493 .attrs
= wan_attributes
,
1496 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1501 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1503 IBM_ACPIHANDLE_INIT(hkey
);
1505 tp_features
.wan
= hkey_handle
&&
1506 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1508 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1509 str_supported(tp_features
.wan
),
1512 if (tp_features
.wan
) {
1513 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1514 /* no wan hardware present in system */
1515 tp_features
.wan
= 0;
1516 dbg_printk(TPACPI_DBG_INIT
,
1517 "wan hardware not installed\n");
1519 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1526 return (tp_features
.wan
)? 0 : 1;
1529 static void wan_exit(void)
1531 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1535 static int wan_get_radiosw(void)
1539 if (!tp_features
.wan
)
1542 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1545 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1548 static int wan_set_radiosw(int radio_on
)
1552 if (!tp_features
.wan
)
1555 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1558 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1560 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1561 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1567 /* procfs -------------------------------------------------------------- */
1568 static int wan_read(char *p
)
1571 int status
= wan_get_radiosw();
1573 if (!tp_features
.wan
)
1574 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1576 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1577 (status
)? "enabled" : "disabled");
1578 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1584 static int wan_write(char *buf
)
1588 if (!tp_features
.wan
)
1591 while ((cmd
= next_cmd(&buf
))) {
1592 if (strlencmp(cmd
, "enable") == 0) {
1594 } else if (strlencmp(cmd
, "disable") == 0) {
1603 static struct ibm_struct wan_driver_data
= {
1608 .flags
.experimental
= 1,
1611 /*************************************************************************
1615 static enum video_access_mode video_supported
;
1616 static int video_orig_autosw
;
1618 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1619 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1620 "\\_SB.PCI0.VID0", /* 770e */
1621 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1622 "\\_SB.PCI0.AGP.VID", /* all others */
1625 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1627 static int __init
video_init(struct ibm_init_struct
*iibm
)
1631 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1633 IBM_ACPIHANDLE_INIT(vid
);
1634 IBM_ACPIHANDLE_INIT(vid2
);
1636 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1637 /* G41, assume IVGA doesn't change */
1638 vid_handle
= vid2_handle
;
1641 /* video switching not supported on R30, R31 */
1642 video_supported
= TPACPI_VIDEO_NONE
;
1643 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1645 video_supported
= TPACPI_VIDEO_570
;
1646 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1647 /* 600e/x, 770e, 770x */
1648 video_supported
= TPACPI_VIDEO_770
;
1651 video_supported
= TPACPI_VIDEO_NEW
;
1653 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1654 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1657 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1660 static void video_exit(void)
1662 dbg_printk(TPACPI_DBG_EXIT
,
1663 "restoring original video autoswitch mode\n");
1664 if (video_autosw_set(video_orig_autosw
))
1665 printk(IBM_ERR
"error while trying to restore original "
1666 "video autoswitch mode\n");
1669 static int video_outputsw_get(void)
1674 switch (video_supported
) {
1675 case TPACPI_VIDEO_570
:
1676 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1677 TP_ACPI_VIDEO_570_PHSCMD
))
1679 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1681 case TPACPI_VIDEO_770
:
1682 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1685 status
|= TP_ACPI_VIDEO_S_LCD
;
1686 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1689 status
|= TP_ACPI_VIDEO_S_CRT
;
1691 case TPACPI_VIDEO_NEW
:
1692 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1693 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1696 status
|= TP_ACPI_VIDEO_S_CRT
;
1698 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1699 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1702 status
|= TP_ACPI_VIDEO_S_LCD
;
1703 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1706 status
|= TP_ACPI_VIDEO_S_DVI
;
1715 static int video_outputsw_set(int status
)
1720 switch (video_supported
) {
1721 case TPACPI_VIDEO_570
:
1722 res
= acpi_evalf(NULL
, NULL
,
1723 "\\_SB.PHS2", "vdd",
1724 TP_ACPI_VIDEO_570_PHS2CMD
,
1725 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1727 case TPACPI_VIDEO_770
:
1728 autosw
= video_autosw_get();
1732 res
= video_autosw_set(1);
1735 res
= acpi_evalf(vid_handle
, NULL
,
1736 "ASWT", "vdd", status
* 0x100, 0);
1737 if (!autosw
&& video_autosw_set(autosw
)) {
1738 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1742 case TPACPI_VIDEO_NEW
:
1743 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1744 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1750 return (res
)? 0 : -EIO
;
1753 static int video_autosw_get(void)
1757 switch (video_supported
) {
1758 case TPACPI_VIDEO_570
:
1759 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1762 case TPACPI_VIDEO_770
:
1763 case TPACPI_VIDEO_NEW
:
1764 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1774 static int video_autosw_set(int enable
)
1776 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1781 static int video_outputsw_cycle(void)
1783 int autosw
= video_autosw_get();
1789 switch (video_supported
) {
1790 case TPACPI_VIDEO_570
:
1791 res
= video_autosw_set(1);
1794 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1796 case TPACPI_VIDEO_770
:
1797 case TPACPI_VIDEO_NEW
:
1798 res
= video_autosw_set(1);
1801 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1806 if (!autosw
&& video_autosw_set(autosw
)) {
1807 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1811 return (res
)? 0 : -EIO
;
1814 static int video_expand_toggle(void)
1816 switch (video_supported
) {
1817 case TPACPI_VIDEO_570
:
1818 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1820 case TPACPI_VIDEO_770
:
1821 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1823 case TPACPI_VIDEO_NEW
:
1824 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1832 static int video_read(char *p
)
1837 if (video_supported
== TPACPI_VIDEO_NONE
) {
1838 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1842 status
= video_outputsw_get();
1846 autosw
= video_autosw_get();
1850 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1851 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
1852 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
1853 if (video_supported
== TPACPI_VIDEO_NEW
)
1854 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
1855 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
1856 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
1857 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
1858 if (video_supported
== TPACPI_VIDEO_NEW
)
1859 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
1860 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
1861 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
1866 static int video_write(char *buf
)
1869 int enable
, disable
, status
;
1872 if (video_supported
== TPACPI_VIDEO_NONE
)
1878 while ((cmd
= next_cmd(&buf
))) {
1879 if (strlencmp(cmd
, "lcd_enable") == 0) {
1880 enable
|= TP_ACPI_VIDEO_S_LCD
;
1881 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1882 disable
|= TP_ACPI_VIDEO_S_LCD
;
1883 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1884 enable
|= TP_ACPI_VIDEO_S_CRT
;
1885 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1886 disable
|= TP_ACPI_VIDEO_S_CRT
;
1887 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1888 strlencmp(cmd
, "dvi_enable") == 0) {
1889 enable
|= TP_ACPI_VIDEO_S_DVI
;
1890 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1891 strlencmp(cmd
, "dvi_disable") == 0) {
1892 disable
|= TP_ACPI_VIDEO_S_DVI
;
1893 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1894 res
= video_autosw_set(1);
1897 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1898 res
= video_autosw_set(0);
1901 } else if (strlencmp(cmd
, "video_switch") == 0) {
1902 res
= video_outputsw_cycle();
1905 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1906 res
= video_expand_toggle();
1913 if (enable
|| disable
) {
1914 status
= video_outputsw_get();
1917 res
= video_outputsw_set((status
& ~disable
) | enable
);
1925 static struct ibm_struct video_driver_data
= {
1928 .write
= video_write
,
1932 /*************************************************************************
1933 * Light (thinklight) subdriver
1936 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1937 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1939 static int __init
light_init(struct ibm_init_struct
*iibm
)
1941 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
1943 IBM_ACPIHANDLE_INIT(ledb
);
1944 IBM_ACPIHANDLE_INIT(lght
);
1945 IBM_ACPIHANDLE_INIT(cmos
);
1947 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1948 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1950 if (tp_features
.light
)
1951 /* light status not supported on
1952 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1953 tp_features
.light_status
=
1954 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
1956 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
1957 str_supported(tp_features
.light
));
1959 return (tp_features
.light
)? 0 : 1;
1962 static int light_read(char *p
)
1967 if (!tp_features
.light
) {
1968 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1969 } else if (!tp_features
.light_status
) {
1970 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1971 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1973 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1975 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1976 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1982 static int light_write(char *buf
)
1984 int cmos_cmd
, lght_cmd
;
1988 if (!tp_features
.light
)
1991 while ((cmd
= next_cmd(&buf
))) {
1992 if (strlencmp(cmd
, "on") == 0) {
1995 } else if (strlencmp(cmd
, "off") == 0) {
2001 success
= cmos_handle
?
2002 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2003 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2011 static struct ibm_struct light_driver_data
= {
2014 .write
= light_write
,
2017 /*************************************************************************
2021 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2023 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2024 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2025 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2026 "\\_SB.PCI.ISA.SLCE", /* 570 */
2027 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2029 /* don't list other alternatives as we install a notify handler on the 570 */
2030 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2032 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2034 .notify
= dock_notify
,
2035 .handle
= &dock_handle
,
2036 .type
= ACPI_SYSTEM_NOTIFY
,
2039 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2040 * We just use it to get notifications of dock hotplug
2041 * in very old thinkpads */
2042 .hid
= PCI_ROOT_HID_STRING
,
2043 .notify
= dock_notify
,
2044 .handle
= &pci_handle
,
2045 .type
= ACPI_SYSTEM_NOTIFY
,
2049 static struct ibm_struct dock_driver_data
[2] = {
2053 .write
= dock_write
,
2054 .acpi
= &ibm_dock_acpidriver
[0],
2058 .acpi
= &ibm_dock_acpidriver
[1],
2062 #define dock_docked() (_sta(dock_handle) & 1)
2064 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2066 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2068 IBM_ACPIHANDLE_INIT(dock
);
2070 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2071 str_supported(dock_handle
!= NULL
));
2073 return (dock_handle
)? 0 : 1;
2076 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2080 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2082 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2083 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2084 IBM_ACPIHANDLE_INIT(pci
);
2085 dock2_needed
= (pci_handle
!= NULL
);
2086 vdbg_printk(TPACPI_DBG_INIT
,
2087 "dock PCI handler for the TP 570 is %s\n",
2088 str_supported(dock2_needed
));
2090 vdbg_printk(TPACPI_DBG_INIT
,
2091 "dock subdriver part 2 not required\n");
2095 return (dock2_needed
)? 0 : 1;
2098 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2100 int docked
= dock_docked();
2101 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, PCI_ROOT_HID_STRING
);
2103 if (event
== 1 && !pci
) /* 570 */
2104 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2105 else if (event
== 1 && pci
) /* 570 */
2106 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2107 else if (event
== 3 && docked
)
2108 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2109 else if (event
== 3 && !docked
)
2110 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
2111 else if (event
== 0 && docked
)
2112 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2114 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2115 event
, _sta(dock_handle
));
2116 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
2120 static int dock_read(char *p
)
2123 int docked
= dock_docked();
2126 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2128 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2130 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2131 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2137 static int dock_write(char *buf
)
2144 while ((cmd
= next_cmd(&buf
))) {
2145 if (strlencmp(cmd
, "undock") == 0) {
2146 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2147 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2149 } else if (strlencmp(cmd
, "dock") == 0) {
2150 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2159 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2161 /*************************************************************************
2165 #ifdef CONFIG_THINKPAD_ACPI_BAY
2166 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2167 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2168 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2169 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2170 ); /* A21e, R30, R31 */
2171 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2172 "_EJ0", /* all others */
2173 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2174 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2175 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2177 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2181 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2183 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2185 IBM_ACPIHANDLE_INIT(bay
);
2187 IBM_ACPIHANDLE_INIT(bay_ej
);
2188 IBM_ACPIHANDLE_INIT(bay2
);
2190 IBM_ACPIHANDLE_INIT(bay2_ej
);
2192 tp_features
.bay_status
= bay_handle
&&
2193 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2194 tp_features
.bay_status2
= bay2_handle
&&
2195 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2197 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2198 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2199 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2200 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2202 vdbg_printk(TPACPI_DBG_INIT
,
2203 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2204 str_supported(tp_features
.bay_status
),
2205 str_supported(tp_features
.bay_eject
),
2206 str_supported(tp_features
.bay_status2
),
2207 str_supported(tp_features
.bay_eject2
));
2209 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2210 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2213 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2215 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
2218 #define bay_occupied(b) (_sta(b##_handle) & 1)
2220 static int bay_read(char *p
)
2223 int occupied
= bay_occupied(bay
);
2224 int occupied2
= bay_occupied(bay2
);
2227 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2228 tp_features
.bay_status
?
2229 (occupied
? "occupied" : "unoccupied") :
2231 if (tp_features
.bay_status2
)
2232 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2233 "occupied" : "unoccupied");
2235 eject
= tp_features
.bay_eject
&& occupied
;
2236 eject2
= tp_features
.bay_eject2
&& occupied2
;
2238 if (eject
&& eject2
)
2239 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2241 len
+= sprintf(p
+ len
, "commands:\teject\n");
2243 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2248 static int bay_write(char *buf
)
2252 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2255 while ((cmd
= next_cmd(&buf
))) {
2256 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2257 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2259 } else if (tp_features
.bay_eject2
&&
2260 strlencmp(cmd
, "eject2") == 0) {
2261 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2270 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2271 .notify
= bay_notify
,
2272 .handle
= &bay_handle
,
2273 .type
= ACPI_SYSTEM_NOTIFY
,
2276 static struct ibm_struct bay_driver_data
= {
2280 .acpi
= &ibm_bay_acpidriver
,
2283 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2285 /*************************************************************************
2289 /* sysfs cmos_command -------------------------------------------------- */
2290 static ssize_t
cmos_command_store(struct device
*dev
,
2291 struct device_attribute
*attr
,
2292 const char *buf
, size_t count
)
2294 unsigned long cmos_cmd
;
2297 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2300 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2301 return (res
)? res
: count
;
2304 static struct device_attribute dev_attr_cmos_command
=
2305 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2307 /* --------------------------------------------------------------------- */
2309 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2313 vdbg_printk(TPACPI_DBG_INIT
,
2314 "initializing cmos commands subdriver\n");
2316 IBM_ACPIHANDLE_INIT(cmos
);
2318 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2319 str_supported(cmos_handle
!= NULL
));
2321 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2325 return (cmos_handle
)? 0 : 1;
2328 static void cmos_exit(void)
2330 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2333 static int cmos_read(char *p
)
2337 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2338 R30, R31, T20-22, X20-21 */
2340 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2342 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2343 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2349 static int cmos_write(char *buf
)
2354 while ((cmd
= next_cmd(&buf
))) {
2355 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2356 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2361 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2369 static struct ibm_struct cmos_driver_data
= {
2372 .write
= cmos_write
,
2376 /*************************************************************************
2380 static enum led_access_mode led_supported
;
2382 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2383 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2384 "LED", /* all others */
2387 static int __init
led_init(struct ibm_init_struct
*iibm
)
2389 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2391 IBM_ACPIHANDLE_INIT(led
);
2394 /* led not supported on R30, R31 */
2395 led_supported
= TPACPI_LED_NONE
;
2396 else if (strlencmp(led_path
, "SLED") == 0)
2398 led_supported
= TPACPI_LED_570
;
2399 else if (strlencmp(led_path
, "SYSL") == 0)
2400 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2401 led_supported
= TPACPI_LED_OLD
;
2404 led_supported
= TPACPI_LED_NEW
;
2406 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2407 str_supported(led_supported
), led_supported
);
2409 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2412 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2414 static int led_read(char *p
)
2418 if (!led_supported
) {
2419 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2422 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2424 if (led_supported
== TPACPI_LED_570
) {
2427 for (i
= 0; i
< 8; i
++) {
2428 if (!acpi_evalf(ec_handle
,
2429 &status
, "GLED", "dd", 1 << i
))
2431 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2432 i
, led_status(status
));
2436 len
+= sprintf(p
+ len
, "commands:\t"
2437 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2442 /* off, on, blink */
2443 static const int led_sled_arg1
[] = { 0, 1, 3 };
2444 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2445 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2446 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2448 static int led_write(char *buf
)
2456 while ((cmd
= next_cmd(&buf
))) {
2457 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2460 if (strstr(cmd
, "off")) {
2462 } else if (strstr(cmd
, "on")) {
2464 } else if (strstr(cmd
, "blink")) {
2469 if (led_supported
== TPACPI_LED_570
) {
2472 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2473 led
, led_sled_arg1
[ind
]))
2475 } else if (led_supported
== TPACPI_LED_OLD
) {
2476 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2478 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2481 ec_write(TPACPI_LED_EC_HLBL
,
2482 led
* led_exp_hlbl
[ind
]);
2485 ec_write(TPACPI_LED_EC_HLCL
,
2486 led
* led_exp_hlcl
[ind
]);
2491 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2492 led
, led_led_arg1
[ind
]))
2500 static struct ibm_struct led_driver_data
= {
2506 /*************************************************************************
2510 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2512 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2514 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2516 IBM_ACPIHANDLE_INIT(beep
);
2518 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2519 str_supported(beep_handle
!= NULL
));
2521 return (beep_handle
)? 0 : 1;
2524 static int beep_read(char *p
)
2529 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2531 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2532 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2538 static int beep_write(char *buf
)
2546 while ((cmd
= next_cmd(&buf
))) {
2547 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2548 beep_cmd
>= 0 && beep_cmd
<= 17) {
2552 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2559 static struct ibm_struct beep_driver_data
= {
2562 .write
= beep_write
,
2565 /*************************************************************************
2569 static enum thermal_access_mode thermal_read_mode
;
2571 /* sysfs temp##_input -------------------------------------------------- */
2573 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2574 struct device_attribute
*attr
,
2577 struct sensor_device_attribute
*sensor_attr
=
2578 to_sensor_dev_attr(attr
);
2579 int idx
= sensor_attr
->index
;
2583 res
= thermal_get_sensor(idx
, &value
);
2586 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2589 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2592 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2593 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2595 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2596 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2597 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2598 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2599 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2600 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2601 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2602 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2603 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2604 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2605 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2606 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2607 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2608 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2609 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2610 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2611 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2614 #define THERMAL_ATTRS(X) \
2615 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2617 static struct attribute
*thermal_temp_input_attr
[] = {
2637 static const struct attribute_group thermal_temp_input16_group
= {
2638 .attrs
= thermal_temp_input_attr
2641 static const struct attribute_group thermal_temp_input8_group
= {
2642 .attrs
= &thermal_temp_input_attr
[8]
2645 #undef THERMAL_SENSOR_ATTR_TEMP
2646 #undef THERMAL_ATTRS
2648 /* --------------------------------------------------------------------- */
2650 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2657 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2659 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2661 if (thinkpad_id
.ec_model
&& experimental
) {
2663 * Direct EC access mode: sensors at registers
2664 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2665 * non-implemented, thermal sensors return 0x80 when
2670 for (i
= 0; i
< 8; i
++) {
2671 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2677 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2685 /* This is sheer paranoia, but we handle it anyway */
2688 "ThinkPad ACPI EC access misbehaving, "
2689 "falling back to ACPI TMPx access mode\n");
2690 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2693 "ThinkPad ACPI EC access misbehaving, "
2694 "disabling thermal sensors access\n");
2695 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2700 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2702 } else if (acpi_tmp7
) {
2703 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2704 /* 600e/x, 770e, 770x */
2705 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2707 /* Standard ACPI TMPx access, max 8 sensors */
2708 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2711 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2712 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2715 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2716 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2719 switch(thermal_read_mode
) {
2720 case TPACPI_THERMAL_TPEC_16
:
2721 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2722 &thermal_temp_input16_group
);
2726 case TPACPI_THERMAL_TPEC_8
:
2727 case TPACPI_THERMAL_ACPI_TMP07
:
2728 case TPACPI_THERMAL_ACPI_UPDT
:
2729 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2730 &thermal_temp_input8_group
);
2734 case TPACPI_THERMAL_NONE
:
2742 static void thermal_exit(void)
2744 switch(thermal_read_mode
) {
2745 case TPACPI_THERMAL_TPEC_16
:
2746 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2747 &thermal_temp_input16_group
);
2749 case TPACPI_THERMAL_TPEC_8
:
2750 case TPACPI_THERMAL_ACPI_TMP07
:
2751 case TPACPI_THERMAL_ACPI_UPDT
:
2752 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2753 &thermal_temp_input16_group
);
2755 case TPACPI_THERMAL_NONE
:
2761 /* idx is zero-based */
2762 static int thermal_get_sensor(int idx
, s32
*value
)
2768 t
= TP_EC_THERMAL_TMP0
;
2770 switch (thermal_read_mode
) {
2771 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2772 case TPACPI_THERMAL_TPEC_16
:
2773 if (idx
>= 8 && idx
<= 15) {
2774 t
= TP_EC_THERMAL_TMP8
;
2779 case TPACPI_THERMAL_TPEC_8
:
2781 if (!acpi_ec_read(t
+ idx
, &tmp
))
2783 *value
= tmp
* 1000;
2788 case TPACPI_THERMAL_ACPI_UPDT
:
2790 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2791 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2793 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2795 *value
= (t
- 2732) * 100;
2800 case TPACPI_THERMAL_ACPI_TMP07
:
2802 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2803 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2810 case TPACPI_THERMAL_NONE
:
2818 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2829 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2832 for(i
= 0 ; i
< n
; i
++) {
2833 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
2841 static int thermal_read(char *p
)
2845 struct ibm_thermal_sensors_struct t
;
2847 n
= thermal_get_sensors(&t
);
2848 if (unlikely(n
< 0))
2851 len
+= sprintf(p
+ len
, "temperatures:\t");
2854 for (i
= 0; i
< (n
- 1); i
++)
2855 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
2856 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
2858 len
+= sprintf(p
+ len
, "not supported\n");
2863 static struct ibm_struct thermal_driver_data
= {
2865 .read
= thermal_read
,
2866 .exit
= thermal_exit
,
2869 /*************************************************************************
2873 static u8 ecdump_regs
[256];
2875 static int ecdump_read(char *p
)
2881 len
+= sprintf(p
+ len
, "EC "
2882 " +00 +01 +02 +03 +04 +05 +06 +07"
2883 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2884 for (i
= 0; i
< 256; i
+= 16) {
2885 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
2886 for (j
= 0; j
< 16; j
++) {
2887 if (!acpi_ec_read(i
+ j
, &v
))
2889 if (v
!= ecdump_regs
[i
+ j
])
2890 len
+= sprintf(p
+ len
, " *%02x", v
);
2892 len
+= sprintf(p
+ len
, " %02x", v
);
2893 ecdump_regs
[i
+ j
] = v
;
2895 len
+= sprintf(p
+ len
, "\n");
2900 /* These are way too dangerous to advertise openly... */
2902 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
2903 " (<offset> is 00-ff, <value> is 00-ff)\n");
2904 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
2905 " (<offset> is 00-ff, <value> is 0-255)\n");
2910 static int ecdump_write(char *buf
)
2915 while ((cmd
= next_cmd(&buf
))) {
2916 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
2918 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
2922 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
2923 if (!acpi_ec_write(i
, v
))
2932 static struct ibm_struct ecdump_driver_data
= {
2934 .read
= ecdump_read
,
2935 .write
= ecdump_write
,
2936 .flags
.experimental
= 1,
2939 /*************************************************************************
2940 * Backlight/brightness subdriver
2943 static struct backlight_device
*ibm_backlight_device
;
2945 static struct backlight_ops ibm_backlight_data
= {
2946 .get_brightness
= brightness_get
,
2947 .update_status
= brightness_update_status
,
2950 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
2954 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
2956 b
= brightness_get(NULL
);
2960 ibm_backlight_device
= backlight_device_register(
2961 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
2962 &ibm_backlight_data
);
2963 if (IS_ERR(ibm_backlight_device
)) {
2964 printk(IBM_ERR
"Could not register backlight device\n");
2965 return PTR_ERR(ibm_backlight_device
);
2967 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
2969 ibm_backlight_device
->props
.max_brightness
= 7;
2970 ibm_backlight_device
->props
.brightness
= b
;
2971 backlight_update_status(ibm_backlight_device
);
2976 static void brightness_exit(void)
2978 if (ibm_backlight_device
) {
2979 vdbg_printk(TPACPI_DBG_EXIT
,
2980 "calling backlight_device_unregister()\n");
2981 backlight_device_unregister(ibm_backlight_device
);
2982 ibm_backlight_device
= NULL
;
2986 static int brightness_update_status(struct backlight_device
*bd
)
2988 return brightness_set(
2989 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
2990 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
2991 bd
->props
.brightness
: 0);
2994 static int brightness_get(struct backlight_device
*bd
)
2997 if (!acpi_ec_read(brightness_offset
, &level
))
3005 static int brightness_set(int value
)
3007 int cmos_cmd
, inc
, i
;
3008 int current_value
= brightness_get(NULL
);
3012 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
3013 inc
= value
> current_value
? 1 : -1;
3014 for (i
= current_value
; i
!= value
; i
+= inc
) {
3015 if (issue_thinkpad_cmos_command(cmos_cmd
))
3017 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
3024 static int brightness_read(char *p
)
3029 if ((level
= brightness_get(NULL
)) < 0) {
3030 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3032 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
3033 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3034 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3035 " (<level> is 0-7)\n");
3041 static int brightness_write(char *buf
)
3047 while ((cmd
= next_cmd(&buf
))) {
3048 if ((level
= brightness_get(NULL
)) < 0)
3052 if (strlencmp(cmd
, "up") == 0) {
3053 new_level
= level
== 7 ? 7 : level
+ 1;
3054 } else if (strlencmp(cmd
, "down") == 0) {
3055 new_level
= level
== 0 ? 0 : level
- 1;
3056 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3057 new_level
>= 0 && new_level
<= 7) {
3062 brightness_set(new_level
);
3068 static struct ibm_struct brightness_driver_data
= {
3069 .name
= "brightness",
3070 .read
= brightness_read
,
3071 .write
= brightness_write
,
3072 .exit
= brightness_exit
,
3075 /*************************************************************************
3079 static int volume_read(char *p
)
3084 if (!acpi_ec_read(volume_offset
, &level
)) {
3085 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3087 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3088 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3089 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3090 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3091 " (<level> is 0-15)\n");
3097 static int volume_write(char *buf
)
3099 int cmos_cmd
, inc
, i
;
3101 int new_level
, new_mute
;
3104 while ((cmd
= next_cmd(&buf
))) {
3105 if (!acpi_ec_read(volume_offset
, &level
))
3107 new_mute
= mute
= level
& 0x40;
3108 new_level
= level
= level
& 0xf;
3110 if (strlencmp(cmd
, "up") == 0) {
3114 new_level
= level
== 15 ? 15 : level
+ 1;
3115 } else if (strlencmp(cmd
, "down") == 0) {
3119 new_level
= level
== 0 ? 0 : level
- 1;
3120 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3121 new_level
>= 0 && new_level
<= 15) {
3123 } else if (strlencmp(cmd
, "mute") == 0) {
3128 if (new_level
!= level
) { /* mute doesn't change */
3129 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3130 inc
= new_level
> level
? 1 : -1;
3132 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3133 !acpi_ec_write(volume_offset
, level
)))
3136 for (i
= level
; i
!= new_level
; i
+= inc
)
3137 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3138 !acpi_ec_write(volume_offset
, i
+ inc
))
3141 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3142 !acpi_ec_write(volume_offset
,
3147 if (new_mute
!= mute
) { /* level doesn't change */
3148 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3150 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3151 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3159 static struct ibm_struct volume_driver_data
= {
3161 .read
= volume_read
,
3162 .write
= volume_write
,
3165 /*************************************************************************
3172 * TPACPI_FAN_RD_ACPI_GFAN:
3173 * ACPI GFAN method: returns fan level
3175 * see TPACPI_FAN_WR_ACPI_SFAN
3176 * EC 0x2f (HFSP) not available if GFAN exists
3178 * TPACPI_FAN_WR_ACPI_SFAN:
3179 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3181 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3184 * TPACPI_FAN_WR_TPEC:
3185 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3186 * Supported on almost all ThinkPads
3188 * Fan speed changes of any sort (including those caused by the
3189 * disengaged mode) are usually done slowly by the firmware as the
3190 * maximum ammount of fan duty cycle change per second seems to be
3193 * Reading is not available if GFAN exists.
3194 * Writing is not available if SFAN exists.
3197 * 7 automatic mode engaged;
3198 * (default operation mode of the ThinkPad)
3199 * fan level is ignored in this mode.
3200 * 6 full speed mode (takes precedence over bit 7);
3201 * not available on all thinkpads. May disable
3202 * the tachometer while the fan controller ramps up
3203 * the speed (which can take up to a few *minutes*).
3204 * Speeds up fan to 100% duty-cycle, which is far above
3205 * the standard RPM levels. It is not impossible that
3206 * it could cause hardware damage.
3207 * 5-3 unused in some models. Extra bits for fan level
3208 * in others, but still useless as all values above
3209 * 7 map to the same speed as level 7 in these models.
3210 * 2-0 fan level (0..7 usually)
3212 * 0x07 = max (set when temperatures critical)
3213 * Some ThinkPads may have other levels, see
3214 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3216 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3217 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3218 * does so, its initial value is meaningless (0x07).
3220 * For firmware bugs, refer to:
3221 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3225 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3226 * Main fan tachometer reading (in RPM)
3228 * This register is present on all ThinkPads with a new-style EC, and
3229 * it is known not to be present on the A21m/e, and T22, as there is
3230 * something else in offset 0x84 according to the ACPI DSDT. Other
3231 * ThinkPads from this same time period (and earlier) probably lack the
3232 * tachometer as well.
3234 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3235 * was never fixed by IBM to report the EC firmware version string
3236 * probably support the tachometer (like the early X models), so
3237 * detecting it is quite hard. We need more data to know for sure.
3239 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3242 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3245 * For firmware bugs, refer to:
3246 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3248 * TPACPI_FAN_WR_ACPI_FANS:
3249 * ThinkPad X31, X40, X41. Not available in the X60.
3251 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3252 * high speed. ACPI DSDT seems to map these three speeds to levels
3253 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3254 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3256 * The speeds are stored on handles
3257 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3259 * There are three default speed sets, acessible as handles:
3260 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3262 * ACPI DSDT switches which set is in use depending on various
3265 * TPACPI_FAN_WR_TPEC is also available and should be used to
3266 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3267 * but the ACPI tables just mention level 7.
3270 static enum fan_status_access_mode fan_status_access_mode
;
3271 static enum fan_control_access_mode fan_control_access_mode
;
3272 static enum fan_control_commands fan_control_commands
;
3274 static u8 fan_control_initial_status
;
3275 static u8 fan_control_desired_level
;
3277 static void fan_watchdog_fire(struct work_struct
*ignored
);
3278 static int fan_watchdog_maxinterval
;
3279 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3281 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3282 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3283 "\\FSPD", /* 600e/x, 770e, 770x */
3285 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3286 "JFNS", /* 770x-JL */
3290 * SYSFS fan layout: hwmon compatible (device)
3293 * 0: "disengaged" mode
3295 * 2: native EC "auto" mode (recommended, hardware default)
3297 * pwm*: set speed in manual mode, ignored otherwise.
3298 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3301 * fan*_input: tachometer reading, RPM
3304 * SYSFS fan layout: extensions
3306 * fan_watchdog (driver):
3307 * fan watchdog interval in seconds, 0 disables (default), max 120
3310 /* sysfs fan pwm1_enable ----------------------------------------------- */
3311 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3312 struct device_attribute
*attr
,
3318 res
= fan_get_status_safe(&status
);
3322 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3323 if (status
!= fan_control_initial_status
) {
3324 tp_features
.fan_ctrl_status_undef
= 0;
3326 /* Return most likely status. In fact, it
3327 * might be the only possible status */
3328 status
= TP_EC_FAN_AUTO
;
3332 if (status
& TP_EC_FAN_FULLSPEED
) {
3334 } else if (status
& TP_EC_FAN_AUTO
) {
3339 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3342 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3343 struct device_attribute
*attr
,
3344 const char *buf
, size_t count
)
3349 if (parse_strtoul(buf
, 2, &t
))
3354 level
= TP_EC_FAN_FULLSPEED
;
3357 level
= TPACPI_FAN_LAST_LEVEL
;
3360 level
= TP_EC_FAN_AUTO
;
3363 /* reserved for software-controlled auto mode */
3369 res
= fan_set_level_safe(level
);
3375 fan_watchdog_reset();
3380 static struct device_attribute dev_attr_fan_pwm1_enable
=
3381 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3382 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3384 /* sysfs fan pwm1 ------------------------------------------------------ */
3385 static ssize_t
fan_pwm1_show(struct device
*dev
,
3386 struct device_attribute
*attr
,
3392 res
= fan_get_status_safe(&status
);
3396 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3397 if (status
!= fan_control_initial_status
) {
3398 tp_features
.fan_ctrl_status_undef
= 0;
3400 status
= TP_EC_FAN_AUTO
;
3405 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3406 status
= fan_control_desired_level
;
3411 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3414 static ssize_t
fan_pwm1_store(struct device
*dev
,
3415 struct device_attribute
*attr
,
3416 const char *buf
, size_t count
)
3420 u8 status
, newlevel
;
3422 if (parse_strtoul(buf
, 255, &s
))
3425 /* scale down from 0-255 to 0-7 */
3426 newlevel
= (s
>> 5) & 0x07;
3428 rc
= mutex_lock_interruptible(&fan_mutex
);
3432 rc
= fan_get_status(&status
);
3433 if (!rc
&& (status
&
3434 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3435 rc
= fan_set_level(newlevel
);
3439 fan_update_desired_level(newlevel
);
3440 fan_watchdog_reset();
3444 mutex_unlock(&fan_mutex
);
3445 return (rc
)? rc
: count
;
3448 static struct device_attribute dev_attr_fan_pwm1
=
3449 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3450 fan_pwm1_show
, fan_pwm1_store
);
3452 /* sysfs fan fan1_input ------------------------------------------------ */
3453 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3454 struct device_attribute
*attr
,
3460 res
= fan_get_speed(&speed
);
3464 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3467 static struct device_attribute dev_attr_fan_fan1_input
=
3468 __ATTR(fan1_input
, S_IRUGO
,
3469 fan_fan1_input_show
, NULL
);
3471 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
3472 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3475 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3478 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3479 const char *buf
, size_t count
)
3483 if (parse_strtoul(buf
, 120, &t
))
3486 if (!fan_control_allowed
)
3489 fan_watchdog_maxinterval
= t
;
3490 fan_watchdog_reset();
3495 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3496 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3498 /* --------------------------------------------------------------------- */
3499 static struct attribute
*fan_attributes
[] = {
3500 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3501 &dev_attr_fan_fan1_input
.attr
,
3505 static const struct attribute_group fan_attr_group
= {
3506 .attrs
= fan_attributes
,
3509 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3513 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3515 mutex_init(&fan_mutex
);
3516 fan_status_access_mode
= TPACPI_FAN_NONE
;
3517 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3518 fan_control_commands
= 0;
3519 fan_watchdog_maxinterval
= 0;
3520 tp_features
.fan_ctrl_status_undef
= 0;
3521 fan_control_desired_level
= 7;
3523 IBM_ACPIHANDLE_INIT(fans
);
3524 IBM_ACPIHANDLE_INIT(gfan
);
3525 IBM_ACPIHANDLE_INIT(sfan
);
3528 /* 570, 600e/x, 770e, 770x */
3529 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3531 /* all other ThinkPads: note that even old-style
3532 * ThinkPad ECs supports the fan control register */
3533 if (likely(acpi_ec_read(fan_status_offset
,
3534 &fan_control_initial_status
))) {
3535 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3537 /* In some ThinkPads, neither the EC nor the ACPI
3538 * DSDT initialize the fan status, and it ends up
3539 * being set to 0x07 when it *could* be either
3542 * Enable for TP-1Y (T43), TP-78 (R51e),
3543 * TP-76 (R52), TP-70 (T43, R52), which are known
3545 if (fan_control_initial_status
== 0x07) {
3546 switch (thinkpad_id
.ec_model
) {
3547 case 0x5931: /* TP-1Y */
3548 case 0x3837: /* TP-78 */
3549 case 0x3637: /* TP-76 */
3550 case 0x3037: /* TP-70 */
3552 "fan_init: initial fan status is "
3553 "unknown, assuming it is in auto "
3555 tp_features
.fan_ctrl_status_undef
= 1;
3561 "ThinkPad ACPI EC access misbehaving, "
3562 "fan status and control unavailable\n");
3569 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3570 fan_control_commands
|=
3571 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3574 /* gfan without sfan means no fan control */
3575 /* all other models implement TP EC 0x2f control */
3579 fan_control_access_mode
=
3580 TPACPI_FAN_WR_ACPI_FANS
;
3581 fan_control_commands
|=
3582 TPACPI_FAN_CMD_SPEED
|
3583 TPACPI_FAN_CMD_LEVEL
|
3584 TPACPI_FAN_CMD_ENABLE
;
3586 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3587 fan_control_commands
|=
3588 TPACPI_FAN_CMD_LEVEL
|
3589 TPACPI_FAN_CMD_ENABLE
;
3594 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3595 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3596 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3597 fan_status_access_mode
, fan_control_access_mode
);
3599 /* fan control master switch */
3600 if (!fan_control_allowed
) {
3601 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3602 fan_control_commands
= 0;
3603 dbg_printk(TPACPI_DBG_INIT
,
3604 "fan control features disabled by parameter\n");
3607 /* update fan_control_desired_level */
3608 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3609 fan_get_status_safe(NULL
);
3611 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3612 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3613 rc
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3616 rc
= driver_create_file(&tpacpi_pdriver
.driver
,
3617 &driver_attr_fan_watchdog
);
3626 * Call with fan_mutex held
3628 static void fan_update_desired_level(u8 status
)
3631 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3633 fan_control_desired_level
= 7;
3635 fan_control_desired_level
= status
;
3639 static int fan_get_status(u8
*status
)
3644 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3646 switch (fan_status_access_mode
) {
3647 case TPACPI_FAN_RD_ACPI_GFAN
:
3648 /* 570, 600e/x, 770e, 770x */
3650 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
3658 case TPACPI_FAN_RD_TPEC
:
3659 /* all except 570, 600e/x, 770e, 770x */
3660 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
3675 static int fan_get_status_safe(u8
*status
)
3680 rc
= mutex_lock_interruptible(&fan_mutex
);
3683 rc
= fan_get_status(&s
);
3685 fan_update_desired_level(s
);
3686 mutex_unlock(&fan_mutex
);
3694 static void fan_exit(void)
3696 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
3698 /* FIXME: can we really do this unconditionally? */
3699 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
, &fan_attr_group
);
3700 driver_remove_file(&tpacpi_pdriver
.driver
, &driver_attr_fan_watchdog
);
3702 cancel_delayed_work(&fan_watchdog_task
);
3703 flush_scheduled_work();
3706 static int fan_get_speed(unsigned int *speed
)
3710 switch (fan_status_access_mode
) {
3711 case TPACPI_FAN_RD_TPEC
:
3712 /* all except 570, 600e/x, 770e, 770x */
3713 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
3714 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
3718 *speed
= (hi
<< 8) | lo
;
3729 static void fan_watchdog_fire(struct work_struct
*ignored
)
3733 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
3734 rc
= fan_set_enable();
3736 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
3737 "will try again later...\n", -rc
);
3738 /* reschedule for later */
3739 fan_watchdog_reset();
3743 static void fan_watchdog_reset(void)
3745 static int fan_watchdog_active
;
3747 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
3750 if (fan_watchdog_active
)
3751 cancel_delayed_work(&fan_watchdog_task
);
3753 if (fan_watchdog_maxinterval
> 0) {
3754 fan_watchdog_active
= 1;
3755 if (!schedule_delayed_work(&fan_watchdog_task
,
3756 msecs_to_jiffies(fan_watchdog_maxinterval
3758 printk(IBM_ERR
"failed to schedule the fan watchdog, "
3759 "watchdog will not trigger\n");
3762 fan_watchdog_active
= 0;
3765 static int fan_set_level(int level
)
3767 if (!fan_control_allowed
)
3770 switch (fan_control_access_mode
) {
3771 case TPACPI_FAN_WR_ACPI_SFAN
:
3772 if (level
>= 0 && level
<= 7) {
3773 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
3779 case TPACPI_FAN_WR_ACPI_FANS
:
3780 case TPACPI_FAN_WR_TPEC
:
3781 if ((level
!= TP_EC_FAN_AUTO
) &&
3782 (level
!= TP_EC_FAN_FULLSPEED
) &&
3783 ((level
< 0) || (level
> 7)))
3786 /* safety net should the EC not support AUTO
3787 * or FULLSPEED mode bits and just ignore them */
3788 if (level
& TP_EC_FAN_FULLSPEED
)
3789 level
|= 7; /* safety min speed 7 */
3790 else if (level
& TP_EC_FAN_FULLSPEED
)
3791 level
|= 4; /* safety min speed 4 */
3793 if (!acpi_ec_write(fan_status_offset
, level
))
3796 tp_features
.fan_ctrl_status_undef
= 0;
3805 static int fan_set_level_safe(int level
)
3809 if (!fan_control_allowed
)
3812 rc
= mutex_lock_interruptible(&fan_mutex
);
3816 if (level
== TPACPI_FAN_LAST_LEVEL
)
3817 level
= fan_control_desired_level
;
3819 rc
= fan_set_level(level
);
3821 fan_update_desired_level(level
);
3823 mutex_unlock(&fan_mutex
);
3827 static int fan_set_enable(void)
3832 if (!fan_control_allowed
)
3835 rc
= mutex_lock_interruptible(&fan_mutex
);
3839 switch (fan_control_access_mode
) {
3840 case TPACPI_FAN_WR_ACPI_FANS
:
3841 case TPACPI_FAN_WR_TPEC
:
3842 rc
= fan_get_status(&s
);
3846 /* Don't go out of emergency fan mode */
3849 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
3852 if (!acpi_ec_write(fan_status_offset
, s
))
3855 tp_features
.fan_ctrl_status_undef
= 0;
3860 case TPACPI_FAN_WR_ACPI_SFAN
:
3861 rc
= fan_get_status(&s
);
3867 /* Set fan to at least level 4 */
3870 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
3880 mutex_unlock(&fan_mutex
);
3884 static int fan_set_disable(void)
3888 if (!fan_control_allowed
)
3891 rc
= mutex_lock_interruptible(&fan_mutex
);
3896 switch (fan_control_access_mode
) {
3897 case TPACPI_FAN_WR_ACPI_FANS
:
3898 case TPACPI_FAN_WR_TPEC
:
3899 if (!acpi_ec_write(fan_status_offset
, 0x00))
3902 fan_control_desired_level
= 0;
3903 tp_features
.fan_ctrl_status_undef
= 0;
3907 case TPACPI_FAN_WR_ACPI_SFAN
:
3908 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
3911 fan_control_desired_level
= 0;
3919 mutex_unlock(&fan_mutex
);
3923 static int fan_set_speed(int speed
)
3927 if (!fan_control_allowed
)
3930 rc
= mutex_lock_interruptible(&fan_mutex
);
3935 switch (fan_control_access_mode
) {
3936 case TPACPI_FAN_WR_ACPI_FANS
:
3937 if (speed
>= 0 && speed
<= 65535) {
3938 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
3939 speed
, speed
, speed
))
3949 mutex_unlock(&fan_mutex
);
3953 static int fan_read(char *p
)
3958 unsigned int speed
= 0;
3960 switch (fan_status_access_mode
) {
3961 case TPACPI_FAN_RD_ACPI_GFAN
:
3962 /* 570, 600e/x, 770e, 770x */
3963 if ((rc
= fan_get_status_safe(&status
)) < 0)
3966 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
3968 (status
!= 0) ? "enabled" : "disabled", status
);
3971 case TPACPI_FAN_RD_TPEC
:
3972 /* all except 570, 600e/x, 770e, 770x */
3973 if ((rc
= fan_get_status_safe(&status
)) < 0)
3976 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3977 if (status
!= fan_control_initial_status
)
3978 tp_features
.fan_ctrl_status_undef
= 0;
3980 /* Return most likely status. In fact, it
3981 * might be the only possible status */
3982 status
= TP_EC_FAN_AUTO
;
3985 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3986 (status
!= 0) ? "enabled" : "disabled");
3988 if ((rc
= fan_get_speed(&speed
)) < 0)
3991 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
3993 if (status
& TP_EC_FAN_FULLSPEED
)
3994 /* Disengaged mode takes precedence */
3995 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
3996 else if (status
& TP_EC_FAN_AUTO
)
3997 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
3999 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
4002 case TPACPI_FAN_NONE
:
4004 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4007 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
4008 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
4010 switch (fan_control_access_mode
) {
4011 case TPACPI_FAN_WR_ACPI_SFAN
:
4012 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4016 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4017 "auto, disengaged, full-speed)\n");
4022 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4023 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4024 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4025 "1-120 (seconds))\n");
4027 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4028 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4029 " (<speed> is 0-65535)\n");
4034 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4038 if (strlencmp(cmd
, "level auto") == 0)
4039 level
= TP_EC_FAN_AUTO
;
4040 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4041 (strlencmp(cmd
, "level full-speed") == 0))
4042 level
= TP_EC_FAN_FULLSPEED
;
4043 else if (sscanf(cmd
, "level %d", &level
) != 1)
4046 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4047 printk(IBM_ERR
"level command accepted for unsupported "
4048 "access mode %d", fan_control_access_mode
);
4053 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4055 if (strlencmp(cmd
, "enable") != 0)
4058 if ((*rc
= fan_set_enable()) == -ENXIO
)
4059 printk(IBM_ERR
"enable command accepted for unsupported "
4060 "access mode %d", fan_control_access_mode
);
4065 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4067 if (strlencmp(cmd
, "disable") != 0)
4070 if ((*rc
= fan_set_disable()) == -ENXIO
)
4071 printk(IBM_ERR
"disable command accepted for unsupported "
4072 "access mode %d", fan_control_access_mode
);
4077 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4082 * Support speed <low> <medium> <high> ? */
4084 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4087 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4088 printk(IBM_ERR
"speed command accepted for unsupported "
4089 "access mode %d", fan_control_access_mode
);
4094 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4098 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4101 if (interval
< 0 || interval
> 120)
4104 fan_watchdog_maxinterval
= interval
;
4109 static int fan_write(char *buf
)
4114 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4115 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4116 fan_write_cmd_level(cmd
, &rc
)) &&
4117 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4118 (fan_write_cmd_enable(cmd
, &rc
) ||
4119 fan_write_cmd_disable(cmd
, &rc
) ||
4120 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4121 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4122 fan_write_cmd_speed(cmd
, &rc
))
4126 fan_watchdog_reset();
4132 static struct ibm_struct fan_driver_data
= {
4139 /****************************************************************************
4140 ****************************************************************************
4144 ****************************************************************************
4145 ****************************************************************************/
4148 static struct proc_dir_entry
*proc_dir
;
4150 /* Subdriver registry */
4151 static LIST_HEAD(tpacpi_all_drivers
);
4155 * Module and infrastructure proble, init and exit handling
4158 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4159 static const char * __init
str_supported(int is_supported
)
4161 static char text_unsupported
[] __initdata
= "not supported";
4163 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4165 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4167 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4170 struct ibm_struct
*ibm
= iibm
->data
;
4171 struct proc_dir_entry
*entry
;
4173 BUG_ON(ibm
== NULL
);
4175 INIT_LIST_HEAD(&ibm
->all_drivers
);
4177 if (ibm
->flags
.experimental
&& !experimental
)
4180 dbg_printk(TPACPI_DBG_INIT
,
4181 "probing for %s\n", ibm
->name
);
4184 ret
= iibm
->init(iibm
);
4186 return 0; /* probe failed */
4190 ibm
->flags
.init_called
= 1;
4194 if (ibm
->acpi
->hid
) {
4195 ret
= register_tpacpi_subdriver(ibm
);
4200 if (ibm
->acpi
->notify
) {
4201 ret
= setup_acpi_notify(ibm
);
4202 if (ret
== -ENODEV
) {
4203 printk(IBM_NOTICE
"disabling subdriver %s\n",
4213 dbg_printk(TPACPI_DBG_INIT
,
4214 "%s installed\n", ibm
->name
);
4217 entry
= create_proc_entry(ibm
->name
,
4218 S_IFREG
| S_IRUGO
| S_IWUSR
,
4221 printk(IBM_ERR
"unable to create proc entry %s\n",
4226 entry
->owner
= THIS_MODULE
;
4228 entry
->read_proc
= &dispatch_procfs_read
;
4230 entry
->write_proc
= &dispatch_procfs_write
;
4231 ibm
->flags
.proc_created
= 1;
4234 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4239 dbg_printk(TPACPI_DBG_INIT
,
4240 "%s: at error exit path with result %d\n",
4244 return (ret
< 0)? ret
: 0;
4247 static void ibm_exit(struct ibm_struct
*ibm
)
4249 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4251 list_del_init(&ibm
->all_drivers
);
4253 if (ibm
->flags
.acpi_notify_installed
) {
4254 dbg_printk(TPACPI_DBG_EXIT
,
4255 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4257 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4259 dispatch_acpi_notify
);
4260 ibm
->flags
.acpi_notify_installed
= 0;
4261 ibm
->flags
.acpi_notify_installed
= 0;
4264 if (ibm
->flags
.proc_created
) {
4265 dbg_printk(TPACPI_DBG_EXIT
,
4266 "%s: remove_proc_entry\n", ibm
->name
);
4267 remove_proc_entry(ibm
->name
, proc_dir
);
4268 ibm
->flags
.proc_created
= 0;
4271 if (ibm
->flags
.acpi_driver_registered
) {
4272 dbg_printk(TPACPI_DBG_EXIT
,
4273 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4275 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4276 kfree(ibm
->acpi
->driver
);
4277 ibm
->acpi
->driver
= NULL
;
4278 ibm
->flags
.acpi_driver_registered
= 0;
4281 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4283 ibm
->flags
.init_called
= 0;
4286 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4291 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
4293 struct dmi_device
*dev
= NULL
;
4294 char ec_fw_string
[18];
4299 memset(tp
, 0, sizeof(*tp
));
4301 if (dmi_name_in_vendors("IBM"))
4302 tp
->vendor
= PCI_VENDOR_ID_IBM
;
4303 else if (dmi_name_in_vendors("LENOVO"))
4304 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
4308 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
4310 if (!tp
->bios_version_str
)
4312 tp
->bios_model
= tp
->bios_version_str
[0]
4313 | (tp
->bios_version_str
[1] << 8);
4316 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4317 * X32 or newer, all Z series; Some models must have an
4318 * up-to-date BIOS or they will not be detected.
4320 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4322 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4323 if (sscanf(dev
->name
,
4324 "IBM ThinkPad Embedded Controller -[%17c",
4325 ec_fw_string
) == 1) {
4326 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4327 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4329 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
4330 tp
->ec_model
= ec_fw_string
[0]
4331 | (ec_fw_string
[1] << 8);
4336 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
4338 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
4339 kfree(tp
->model_str
);
4340 tp
->model_str
= NULL
;
4344 static int __init
probe_for_thinkpad(void)
4352 * Non-ancient models have better DMI tagging, but very old models
4355 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
4357 /* ec is required because many other handles are relative to it */
4358 IBM_ACPIHANDLE_INIT(ec
);
4362 "Not yet supported ThinkPad detected!\n");
4367 * Risks a regression on very old machines, but reduces potential
4368 * false positives a damn great deal
4371 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
4373 if (!is_thinkpad
&& !force_load
)
4380 /* Module init, exit, parameters */
4382 static struct ibm_init_struct ibms_init
[] __initdata
= {
4384 .init
= thinkpad_acpi_driver_init
,
4385 .data
= &thinkpad_acpi_driver_data
,
4388 .init
= hotkey_init
,
4389 .data
= &hotkey_driver_data
,
4392 .init
= bluetooth_init
,
4393 .data
= &bluetooth_driver_data
,
4397 .data
= &wan_driver_data
,
4401 .data
= &video_driver_data
,
4405 .data
= &light_driver_data
,
4407 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4410 .data
= &dock_driver_data
[0],
4414 .data
= &dock_driver_data
[1],
4417 #ifdef CONFIG_THINKPAD_ACPI_BAY
4420 .data
= &bay_driver_data
,
4425 .data
= &cmos_driver_data
,
4429 .data
= &led_driver_data
,
4433 .data
= &beep_driver_data
,
4436 .init
= thermal_init
,
4437 .data
= &thermal_driver_data
,
4440 .data
= &ecdump_driver_data
,
4443 .init
= brightness_init
,
4444 .data
= &brightness_driver_data
,
4447 .data
= &volume_driver_data
,
4451 .data
= &fan_driver_data
,
4455 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4458 struct ibm_struct
*ibm
;
4460 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4461 ibm
= ibms_init
[i
].data
;
4462 BUG_ON(ibm
== NULL
);
4464 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4465 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4467 strcpy(ibms_init
[i
].param
, val
);
4468 strcat(ibms_init
[i
].param
, ",");
4476 static int experimental
;
4477 module_param(experimental
, int, 0);
4479 static u32 dbg_level
;
4480 module_param_named(debug
, dbg_level
, uint
, 0);
4482 static int force_load
;
4483 module_param(force_load
, bool, 0);
4485 static int fan_control_allowed
;
4486 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
4488 #define IBM_PARAM(feature) \
4489 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4492 IBM_PARAM(bluetooth
);
4495 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4498 #ifdef CONFIG_THINKPAD_ACPI_BAY
4500 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4505 IBM_PARAM(brightness
);
4509 static int __init
thinkpad_acpi_module_init(void)
4513 /* Driver-level probe */
4515 get_thinkpad_model_data(&thinkpad_id
);
4516 ret
= probe_for_thinkpad();
4518 thinkpad_acpi_module_exit();
4522 /* Driver initialization */
4524 IBM_ACPIHANDLE_INIT(ecrd
);
4525 IBM_ACPIHANDLE_INIT(ecwr
);
4527 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4529 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4530 thinkpad_acpi_module_exit();
4533 proc_dir
->owner
= THIS_MODULE
;
4535 ret
= platform_driver_register(&tpacpi_pdriver
);
4537 printk(IBM_ERR
"unable to register platform driver\n");
4538 thinkpad_acpi_module_exit();
4541 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4543 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4544 thinkpad_acpi_module_exit();
4549 /* Device initialization */
4550 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4552 if (IS_ERR(tpacpi_pdev
)) {
4553 ret
= PTR_ERR(tpacpi_pdev
);
4555 printk(IBM_ERR
"unable to register platform device\n");
4556 thinkpad_acpi_module_exit();
4559 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
4560 if (IS_ERR(tpacpi_hwmon
)) {
4561 ret
= PTR_ERR(tpacpi_hwmon
);
4562 tpacpi_hwmon
= NULL
;
4563 printk(IBM_ERR
"unable to register hwmon device\n");
4564 thinkpad_acpi_module_exit();
4567 tpacpi_inputdev
= input_allocate_device();
4568 if (!tpacpi_inputdev
) {
4569 printk(IBM_ERR
"unable to allocate input device\n");
4570 thinkpad_acpi_module_exit();
4573 /* Prepare input device, but don't register */
4574 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
4575 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
4576 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
4577 tpacpi_inputdev
->id
.vendor
= TPACPI_HKEY_INPUT_VENDOR
;
4578 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
4579 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
4581 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4582 ret
= ibm_init(&ibms_init
[i
]);
4583 if (ret
>= 0 && *ibms_init
[i
].param
)
4584 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
4586 thinkpad_acpi_module_exit();
4590 ret
= input_register_device(tpacpi_inputdev
);
4592 printk(IBM_ERR
"unable to register input device\n");
4593 thinkpad_acpi_module_exit();
4596 tp_features
.input_device_registered
= 1;
4602 static void thinkpad_acpi_module_exit(void)
4604 struct ibm_struct
*ibm
, *itmp
;
4606 list_for_each_entry_safe_reverse(ibm
, itmp
,
4607 &tpacpi_all_drivers
,
4612 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
4614 if (tpacpi_inputdev
) {
4615 if (tp_features
.input_device_registered
)
4616 input_unregister_device(tpacpi_inputdev
);
4618 input_free_device(tpacpi_inputdev
);
4622 hwmon_device_unregister(tpacpi_hwmon
);
4625 platform_device_unregister(tpacpi_pdev
);
4627 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
4628 platform_driver_unregister(&tpacpi_pdriver
);
4631 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
4633 kfree(thinkpad_id
.bios_version_str
);
4634 kfree(thinkpad_id
.ec_version_str
);
4635 kfree(thinkpad_id
.model_str
);
4638 module_init(thinkpad_acpi_module_init
);
4639 module_exit(thinkpad_acpi_module_exit
);