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 0x000100
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: hwmon and platform
515 ****************************************************************************
516 ****************************************************************************/
518 static struct platform_device
*tpacpi_pdev
;
519 static struct class_device
*tpacpi_hwmon
;
521 static struct platform_driver tpacpi_pdriver
= {
523 .name
= IBM_DRVR_NAME
,
524 .owner
= THIS_MODULE
,
529 /*************************************************************************
530 * thinkpad-acpi driver attributes
533 /* interface_version --------------------------------------------------- */
534 static ssize_t
tpacpi_driver_interface_version_show(
535 struct device_driver
*drv
,
538 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
541 static DRIVER_ATTR(interface_version
, S_IRUGO
,
542 tpacpi_driver_interface_version_show
, NULL
);
544 /* debug_level --------------------------------------------------------- */
545 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
548 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
551 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
552 const char *buf
, size_t count
)
556 if (parse_strtoul(buf
, 0xffff, &t
))
564 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
565 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
567 /* version ------------------------------------------------------------- */
568 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
571 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
574 static DRIVER_ATTR(version
, S_IRUGO
,
575 tpacpi_driver_version_show
, NULL
);
577 /* --------------------------------------------------------------------- */
579 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
580 &driver_attr_debug_level
, &driver_attr_version
,
581 &driver_attr_interface_version
,
584 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
590 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
591 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
598 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
602 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
603 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
606 /*************************************************************************
607 * sysfs support helpers
610 struct attribute_set_obj
{
611 struct attribute_set s
;
613 } __attribute__((packed
));
615 static struct attribute_set
*create_attr_set(unsigned int max_members
,
618 struct attribute_set_obj
*sobj
;
620 if (max_members
== 0)
623 /* Allocates space for implicit NULL at the end too */
624 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
625 max_members
* sizeof(struct attribute
*),
629 sobj
->s
.max_members
= max_members
;
630 sobj
->s
.group
.attrs
= &sobj
->a
;
631 sobj
->s
.group
.name
= name
;
636 /* not multi-threaded safe, use it in a single thread per set */
637 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
642 if (s
->members
>= s
->max_members
)
645 s
->group
.attrs
[s
->members
] = attr
;
651 static int add_many_to_attr_set(struct attribute_set
* s
,
652 struct attribute
**attr
,
657 for (i
= 0; i
< count
; i
++) {
658 res
= add_to_attr_set(s
, attr
[i
]);
666 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
668 sysfs_remove_group(kobj
, &s
->group
);
672 static int parse_strtoul(const char *buf
,
673 unsigned long max
, unsigned long *value
)
677 *value
= simple_strtoul(buf
, &endp
, 0);
678 while (*endp
&& isspace(*endp
))
680 if (*endp
|| *value
> max
)
686 /****************************************************************************
687 ****************************************************************************
691 ****************************************************************************
692 ****************************************************************************/
694 /*************************************************************************
695 * thinkpad-acpi init subdriver
698 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
700 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
701 printk(IBM_INFO
"%s\n", IBM_URL
);
703 if (ibm_thinkpad_ec_found
)
704 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
705 ibm_thinkpad_ec_found
);
710 static int thinkpad_acpi_driver_read(char *p
)
714 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
715 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
720 static struct ibm_struct thinkpad_acpi_driver_data
= {
722 .read
= thinkpad_acpi_driver_read
,
725 /*************************************************************************
729 static int hotkey_orig_status
;
730 static u32 hotkey_orig_mask
;
732 static struct attribute_set
*hotkey_dev_attributes
;
734 /* sysfs hotkey enable ------------------------------------------------- */
735 static ssize_t
hotkey_enable_show(struct device
*dev
,
736 struct device_attribute
*attr
,
742 res
= hotkey_get(&status
, &mask
);
746 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
749 static ssize_t
hotkey_enable_store(struct device
*dev
,
750 struct device_attribute
*attr
,
751 const char *buf
, size_t count
)
757 if (parse_strtoul(buf
, 1, &t
))
760 res
= hotkey_get(&status
, &mask
);
762 res
= hotkey_set(t
, mask
);
764 return (res
) ? res
: count
;
767 static struct device_attribute dev_attr_hotkey_enable
=
768 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
769 hotkey_enable_show
, hotkey_enable_store
);
771 /* sysfs hotkey mask --------------------------------------------------- */
772 static ssize_t
hotkey_mask_show(struct device
*dev
,
773 struct device_attribute
*attr
,
779 res
= hotkey_get(&status
, &mask
);
783 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
786 static ssize_t
hotkey_mask_store(struct device
*dev
,
787 struct device_attribute
*attr
,
788 const char *buf
, size_t count
)
794 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
797 res
= hotkey_get(&status
, &mask
);
799 hotkey_set(status
, t
);
801 return (res
) ? res
: count
;
804 static struct device_attribute dev_attr_hotkey_mask
=
805 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
806 hotkey_mask_show
, hotkey_mask_store
);
808 /* sysfs hotkey bios_enabled ------------------------------------------- */
809 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
810 struct device_attribute
*attr
,
813 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
816 static struct device_attribute dev_attr_hotkey_bios_enabled
=
817 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
819 /* sysfs hotkey bios_mask ---------------------------------------------- */
820 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
821 struct device_attribute
*attr
,
824 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
827 static struct device_attribute dev_attr_hotkey_bios_mask
=
828 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
830 /* --------------------------------------------------------------------- */
832 static struct attribute
*hotkey_mask_attributes
[] = {
833 &dev_attr_hotkey_mask
.attr
,
834 &dev_attr_hotkey_bios_enabled
.attr
,
835 &dev_attr_hotkey_bios_mask
.attr
,
838 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
842 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
844 IBM_ACPIHANDLE_INIT(hkey
);
845 mutex_init(&hotkey_mutex
);
847 /* hotkey not supported on 570 */
848 tp_features
.hotkey
= hkey_handle
!= NULL
;
850 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
851 str_supported(tp_features
.hotkey
));
853 if (tp_features
.hotkey
) {
854 hotkey_dev_attributes
= create_attr_set(4, NULL
);
855 if (!hotkey_dev_attributes
)
857 res
= add_to_attr_set(hotkey_dev_attributes
,
858 &dev_attr_hotkey_enable
.attr
);
862 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
863 A30, R30, R31, T20-22, X20-21, X22-24 */
864 tp_features
.hotkey_mask
=
865 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
867 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
868 str_supported(tp_features
.hotkey_mask
));
870 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
871 if (!res
&& tp_features
.hotkey_mask
) {
872 res
= add_many_to_attr_set(hotkey_dev_attributes
,
873 hotkey_mask_attributes
,
874 ARRAY_SIZE(hotkey_mask_attributes
));
877 res
= register_attr_set_with_sysfs(
878 hotkey_dev_attributes
,
879 &tpacpi_pdev
->dev
.kobj
);
885 return (tp_features
.hotkey
)? 0 : 1;
888 static void hotkey_exit(void)
892 if (tp_features
.hotkey
) {
893 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
894 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
896 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
899 if (hotkey_dev_attributes
) {
900 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
901 hotkey_dev_attributes
= NULL
;
905 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
909 if (event
== 0x80 && acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
910 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
912 printk(IBM_ERR
"unknown hotkey notification event %d\n", event
);
913 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
918 * Call with hotkey_mutex held
920 static int hotkey_get(int *status
, u32
*mask
)
922 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
925 if (tp_features
.hotkey_mask
)
926 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
933 * Call with hotkey_mutex held
935 static int hotkey_set(int status
, u32 mask
)
939 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
942 if (tp_features
.hotkey_mask
)
943 for (i
= 0; i
< 32; i
++) {
944 int bit
= ((1 << i
) & mask
) != 0;
945 if (!acpi_evalf(hkey_handle
,
946 NULL
, "MHKM", "vdd", i
+ 1, bit
))
953 /* procfs -------------------------------------------------------------- */
954 static int hotkey_read(char *p
)
960 if (!tp_features
.hotkey
) {
961 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
965 res
= mutex_lock_interruptible(&hotkey_mutex
);
968 res
= hotkey_get(&status
, &mask
);
969 mutex_unlock(&hotkey_mutex
);
973 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
974 if (tp_features
.hotkey_mask
) {
975 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
976 len
+= sprintf(p
+ len
,
977 "commands:\tenable, disable, reset, <mask>\n");
979 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
980 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
986 static int hotkey_write(char *buf
)
993 if (!tp_features
.hotkey
)
996 res
= mutex_lock_interruptible(&hotkey_mutex
);
1000 res
= hotkey_get(&status
, &mask
);
1005 while ((cmd
= next_cmd(&buf
))) {
1006 if (strlencmp(cmd
, "enable") == 0) {
1008 } else if (strlencmp(cmd
, "disable") == 0) {
1010 } else if (strlencmp(cmd
, "reset") == 0) {
1011 status
= hotkey_orig_status
;
1012 mask
= hotkey_orig_mask
;
1013 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1015 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1025 res
= hotkey_set(status
, mask
);
1028 mutex_unlock(&hotkey_mutex
);
1032 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1033 .hid
= IBM_HKEY_HID
,
1034 .notify
= hotkey_notify
,
1035 .handle
= &hkey_handle
,
1036 .type
= ACPI_DEVICE_NOTIFY
,
1039 static struct ibm_struct hotkey_driver_data
= {
1041 .read
= hotkey_read
,
1042 .write
= hotkey_write
,
1043 .exit
= hotkey_exit
,
1044 .acpi
= &ibm_hotkey_acpidriver
,
1047 /*************************************************************************
1048 * Bluetooth subdriver
1051 /* sysfs bluetooth enable ---------------------------------------------- */
1052 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1053 struct device_attribute
*attr
,
1058 status
= bluetooth_get_radiosw();
1062 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1065 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1066 struct device_attribute
*attr
,
1067 const char *buf
, size_t count
)
1072 if (parse_strtoul(buf
, 1, &t
))
1075 res
= bluetooth_set_radiosw(t
);
1077 return (res
) ? res
: count
;
1080 static struct device_attribute dev_attr_bluetooth_enable
=
1081 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1082 bluetooth_enable_show
, bluetooth_enable_store
);
1084 /* --------------------------------------------------------------------- */
1086 static struct attribute
*bluetooth_attributes
[] = {
1087 &dev_attr_bluetooth_enable
.attr
,
1091 static const struct attribute_group bluetooth_attr_group
= {
1092 .attrs
= bluetooth_attributes
,
1095 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1100 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1102 IBM_ACPIHANDLE_INIT(hkey
);
1104 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1105 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1106 tp_features
.bluetooth
= hkey_handle
&&
1107 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1109 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1110 str_supported(tp_features
.bluetooth
),
1113 if (tp_features
.bluetooth
) {
1114 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1115 /* no bluetooth hardware present in system */
1116 tp_features
.bluetooth
= 0;
1117 dbg_printk(TPACPI_DBG_INIT
,
1118 "bluetooth hardware not installed\n");
1120 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1121 &bluetooth_attr_group
);
1127 return (tp_features
.bluetooth
)? 0 : 1;
1130 static void bluetooth_exit(void)
1132 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1133 &bluetooth_attr_group
);
1136 static int bluetooth_get_radiosw(void)
1140 if (!tp_features
.bluetooth
)
1143 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1146 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1149 static int bluetooth_set_radiosw(int radio_on
)
1153 if (!tp_features
.bluetooth
)
1156 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1159 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1161 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1162 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1168 /* procfs -------------------------------------------------------------- */
1169 static int bluetooth_read(char *p
)
1172 int status
= bluetooth_get_radiosw();
1174 if (!tp_features
.bluetooth
)
1175 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1177 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1178 (status
)? "enabled" : "disabled");
1179 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1185 static int bluetooth_write(char *buf
)
1189 if (!tp_features
.bluetooth
)
1192 while ((cmd
= next_cmd(&buf
))) {
1193 if (strlencmp(cmd
, "enable") == 0) {
1194 bluetooth_set_radiosw(1);
1195 } else if (strlencmp(cmd
, "disable") == 0) {
1196 bluetooth_set_radiosw(0);
1204 static struct ibm_struct bluetooth_driver_data
= {
1205 .name
= "bluetooth",
1206 .read
= bluetooth_read
,
1207 .write
= bluetooth_write
,
1208 .exit
= bluetooth_exit
,
1211 /*************************************************************************
1215 /* sysfs wan enable ---------------------------------------------------- */
1216 static ssize_t
wan_enable_show(struct device
*dev
,
1217 struct device_attribute
*attr
,
1222 status
= wan_get_radiosw();
1226 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1229 static ssize_t
wan_enable_store(struct device
*dev
,
1230 struct device_attribute
*attr
,
1231 const char *buf
, size_t count
)
1236 if (parse_strtoul(buf
, 1, &t
))
1239 res
= wan_set_radiosw(t
);
1241 return (res
) ? res
: count
;
1244 static struct device_attribute dev_attr_wan_enable
=
1245 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1246 wan_enable_show
, wan_enable_store
);
1248 /* --------------------------------------------------------------------- */
1250 static struct attribute
*wan_attributes
[] = {
1251 &dev_attr_wan_enable
.attr
,
1255 static const struct attribute_group wan_attr_group
= {
1256 .attrs
= wan_attributes
,
1259 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1264 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1266 IBM_ACPIHANDLE_INIT(hkey
);
1268 tp_features
.wan
= hkey_handle
&&
1269 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1271 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1272 str_supported(tp_features
.wan
),
1275 if (tp_features
.wan
) {
1276 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1277 /* no wan hardware present in system */
1278 tp_features
.wan
= 0;
1279 dbg_printk(TPACPI_DBG_INIT
,
1280 "wan hardware not installed\n");
1282 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1289 return (tp_features
.wan
)? 0 : 1;
1292 static void wan_exit(void)
1294 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1298 static int wan_get_radiosw(void)
1302 if (!tp_features
.wan
)
1305 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1308 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1311 static int wan_set_radiosw(int radio_on
)
1315 if (!tp_features
.wan
)
1318 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1321 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1323 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1324 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1330 /* procfs -------------------------------------------------------------- */
1331 static int wan_read(char *p
)
1334 int status
= wan_get_radiosw();
1336 if (!tp_features
.wan
)
1337 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1339 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1340 (status
)? "enabled" : "disabled");
1341 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1347 static int wan_write(char *buf
)
1351 if (!tp_features
.wan
)
1354 while ((cmd
= next_cmd(&buf
))) {
1355 if (strlencmp(cmd
, "enable") == 0) {
1357 } else if (strlencmp(cmd
, "disable") == 0) {
1366 static struct ibm_struct wan_driver_data
= {
1371 .flags
.experimental
= 1,
1374 /*************************************************************************
1378 static enum video_access_mode video_supported
;
1379 static int video_orig_autosw
;
1381 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1382 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1383 "\\_SB.PCI0.VID0", /* 770e */
1384 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1385 "\\_SB.PCI0.AGP.VID", /* all others */
1388 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1390 static int __init
video_init(struct ibm_init_struct
*iibm
)
1394 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1396 IBM_ACPIHANDLE_INIT(vid
);
1397 IBM_ACPIHANDLE_INIT(vid2
);
1399 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1400 /* G41, assume IVGA doesn't change */
1401 vid_handle
= vid2_handle
;
1404 /* video switching not supported on R30, R31 */
1405 video_supported
= TPACPI_VIDEO_NONE
;
1406 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1408 video_supported
= TPACPI_VIDEO_570
;
1409 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1410 /* 600e/x, 770e, 770x */
1411 video_supported
= TPACPI_VIDEO_770
;
1414 video_supported
= TPACPI_VIDEO_NEW
;
1416 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1417 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1420 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1423 static void video_exit(void)
1425 dbg_printk(TPACPI_DBG_EXIT
,
1426 "restoring original video autoswitch mode\n");
1427 if (video_autosw_set(video_orig_autosw
))
1428 printk(IBM_ERR
"error while trying to restore original "
1429 "video autoswitch mode\n");
1432 static int video_outputsw_get(void)
1437 switch (video_supported
) {
1438 case TPACPI_VIDEO_570
:
1439 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1440 TP_ACPI_VIDEO_570_PHSCMD
))
1442 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1444 case TPACPI_VIDEO_770
:
1445 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1448 status
|= TP_ACPI_VIDEO_S_LCD
;
1449 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1452 status
|= TP_ACPI_VIDEO_S_CRT
;
1454 case TPACPI_VIDEO_NEW
:
1455 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1456 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1459 status
|= TP_ACPI_VIDEO_S_CRT
;
1461 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1462 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1465 status
|= TP_ACPI_VIDEO_S_LCD
;
1466 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1469 status
|= TP_ACPI_VIDEO_S_DVI
;
1478 static int video_outputsw_set(int status
)
1483 switch (video_supported
) {
1484 case TPACPI_VIDEO_570
:
1485 res
= acpi_evalf(NULL
, NULL
,
1486 "\\_SB.PHS2", "vdd",
1487 TP_ACPI_VIDEO_570_PHS2CMD
,
1488 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1490 case TPACPI_VIDEO_770
:
1491 autosw
= video_autosw_get();
1495 res
= video_autosw_set(1);
1498 res
= acpi_evalf(vid_handle
, NULL
,
1499 "ASWT", "vdd", status
* 0x100, 0);
1500 if (!autosw
&& video_autosw_set(autosw
)) {
1501 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1505 case TPACPI_VIDEO_NEW
:
1506 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1507 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1513 return (res
)? 0 : -EIO
;
1516 static int video_autosw_get(void)
1520 switch (video_supported
) {
1521 case TPACPI_VIDEO_570
:
1522 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1525 case TPACPI_VIDEO_770
:
1526 case TPACPI_VIDEO_NEW
:
1527 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1537 static int video_autosw_set(int enable
)
1539 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1544 static int video_outputsw_cycle(void)
1546 int autosw
= video_autosw_get();
1552 switch (video_supported
) {
1553 case TPACPI_VIDEO_570
:
1554 res
= video_autosw_set(1);
1557 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1559 case TPACPI_VIDEO_770
:
1560 case TPACPI_VIDEO_NEW
:
1561 res
= video_autosw_set(1);
1564 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1569 if (!autosw
&& video_autosw_set(autosw
)) {
1570 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1574 return (res
)? 0 : -EIO
;
1577 static int video_expand_toggle(void)
1579 switch (video_supported
) {
1580 case TPACPI_VIDEO_570
:
1581 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1583 case TPACPI_VIDEO_770
:
1584 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1586 case TPACPI_VIDEO_NEW
:
1587 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1595 static int video_read(char *p
)
1600 if (video_supported
== TPACPI_VIDEO_NONE
) {
1601 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1605 status
= video_outputsw_get();
1609 autosw
= video_autosw_get();
1613 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1614 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
1615 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
1616 if (video_supported
== TPACPI_VIDEO_NEW
)
1617 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
1618 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
1619 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
1620 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
1621 if (video_supported
== TPACPI_VIDEO_NEW
)
1622 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
1623 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
1624 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
1629 static int video_write(char *buf
)
1632 int enable
, disable
, status
;
1635 if (video_supported
== TPACPI_VIDEO_NONE
)
1641 while ((cmd
= next_cmd(&buf
))) {
1642 if (strlencmp(cmd
, "lcd_enable") == 0) {
1643 enable
|= TP_ACPI_VIDEO_S_LCD
;
1644 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1645 disable
|= TP_ACPI_VIDEO_S_LCD
;
1646 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1647 enable
|= TP_ACPI_VIDEO_S_CRT
;
1648 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1649 disable
|= TP_ACPI_VIDEO_S_CRT
;
1650 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1651 strlencmp(cmd
, "dvi_enable") == 0) {
1652 enable
|= TP_ACPI_VIDEO_S_DVI
;
1653 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1654 strlencmp(cmd
, "dvi_disable") == 0) {
1655 disable
|= TP_ACPI_VIDEO_S_DVI
;
1656 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1657 res
= video_autosw_set(1);
1660 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1661 res
= video_autosw_set(0);
1664 } else if (strlencmp(cmd
, "video_switch") == 0) {
1665 res
= video_outputsw_cycle();
1668 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1669 res
= video_expand_toggle();
1676 if (enable
|| disable
) {
1677 status
= video_outputsw_get();
1680 res
= video_outputsw_set((status
& ~disable
) | enable
);
1688 static struct ibm_struct video_driver_data
= {
1691 .write
= video_write
,
1695 /*************************************************************************
1696 * Light (thinklight) subdriver
1699 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1700 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1702 static int __init
light_init(struct ibm_init_struct
*iibm
)
1704 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
1706 IBM_ACPIHANDLE_INIT(ledb
);
1707 IBM_ACPIHANDLE_INIT(lght
);
1708 IBM_ACPIHANDLE_INIT(cmos
);
1710 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1711 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1713 if (tp_features
.light
)
1714 /* light status not supported on
1715 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1716 tp_features
.light_status
=
1717 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
1719 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
1720 str_supported(tp_features
.light
));
1722 return (tp_features
.light
)? 0 : 1;
1725 static int light_read(char *p
)
1730 if (!tp_features
.light
) {
1731 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1732 } else if (!tp_features
.light_status
) {
1733 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1734 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1736 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1738 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1739 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1745 static int light_write(char *buf
)
1747 int cmos_cmd
, lght_cmd
;
1751 if (!tp_features
.light
)
1754 while ((cmd
= next_cmd(&buf
))) {
1755 if (strlencmp(cmd
, "on") == 0) {
1758 } else if (strlencmp(cmd
, "off") == 0) {
1764 success
= cmos_handle
?
1765 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1766 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1774 static struct ibm_struct light_driver_data
= {
1777 .write
= light_write
,
1780 /*************************************************************************
1784 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1786 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
1787 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1788 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1789 "\\_SB.PCI.ISA.SLCE", /* 570 */
1790 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1792 /* don't list other alternatives as we install a notify handler on the 570 */
1793 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
1795 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
1797 .notify
= dock_notify
,
1798 .handle
= &dock_handle
,
1799 .type
= ACPI_SYSTEM_NOTIFY
,
1803 .notify
= dock_notify
,
1804 .handle
= &pci_handle
,
1805 .type
= ACPI_SYSTEM_NOTIFY
,
1809 static struct ibm_struct dock_driver_data
[2] = {
1813 .write
= dock_write
,
1814 .acpi
= &ibm_dock_acpidriver
[0],
1818 .acpi
= &ibm_dock_acpidriver
[1],
1822 #define dock_docked() (_sta(dock_handle) & 1)
1824 static int __init
dock_init(struct ibm_init_struct
*iibm
)
1826 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
1828 IBM_ACPIHANDLE_INIT(dock
);
1830 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
1831 str_supported(dock_handle
!= NULL
));
1833 return (dock_handle
)? 0 : 1;
1836 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
1840 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
1842 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
1843 dock_driver_data
[0].flags
.acpi_notify_installed
) {
1844 IBM_ACPIHANDLE_INIT(pci
);
1845 dock2_needed
= (pci_handle
!= NULL
);
1846 vdbg_printk(TPACPI_DBG_INIT
,
1847 "dock PCI handler for the TP 570 is %s\n",
1848 str_supported(dock2_needed
));
1850 vdbg_printk(TPACPI_DBG_INIT
,
1851 "dock subdriver part 2 not required\n");
1855 return (dock2_needed
)? 0 : 1;
1858 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1860 int docked
= dock_docked();
1861 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, IBM_PCI_HID
);
1863 if (event
== 1 && !pci
) /* 570 */
1864 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1865 else if (event
== 1 && pci
) /* 570 */
1866 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1867 else if (event
== 3 && docked
)
1868 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1869 else if (event
== 3 && !docked
)
1870 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
1871 else if (event
== 0 && docked
)
1872 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1874 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1875 event
, _sta(dock_handle
));
1876 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
1880 static int dock_read(char *p
)
1883 int docked
= dock_docked();
1886 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1888 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1890 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1891 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1897 static int dock_write(char *buf
)
1904 while ((cmd
= next_cmd(&buf
))) {
1905 if (strlencmp(cmd
, "undock") == 0) {
1906 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1907 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1909 } else if (strlencmp(cmd
, "dock") == 0) {
1910 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1919 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1921 /*************************************************************************
1925 #ifdef CONFIG_THINKPAD_ACPI_BAY
1926 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1927 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1928 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1929 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1930 ); /* A21e, R30, R31 */
1931 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
1932 "_EJ0", /* all others */
1933 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1934 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1935 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1937 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
1941 static int __init
bay_init(struct ibm_init_struct
*iibm
)
1943 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
1945 IBM_ACPIHANDLE_INIT(bay
);
1947 IBM_ACPIHANDLE_INIT(bay_ej
);
1948 IBM_ACPIHANDLE_INIT(bay2
);
1950 IBM_ACPIHANDLE_INIT(bay2_ej
);
1952 tp_features
.bay_status
= bay_handle
&&
1953 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1954 tp_features
.bay_status2
= bay2_handle
&&
1955 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1957 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
1958 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1959 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
1960 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1962 vdbg_printk(TPACPI_DBG_INIT
,
1963 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1964 str_supported(tp_features
.bay_status
),
1965 str_supported(tp_features
.bay_eject
),
1966 str_supported(tp_features
.bay_status2
),
1967 str_supported(tp_features
.bay_eject2
));
1969 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
1970 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
1973 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1975 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1978 #define bay_occupied(b) (_sta(b##_handle) & 1)
1980 static int bay_read(char *p
)
1983 int occupied
= bay_occupied(bay
);
1984 int occupied2
= bay_occupied(bay2
);
1987 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1988 tp_features
.bay_status
?
1989 (occupied
? "occupied" : "unoccupied") :
1991 if (tp_features
.bay_status2
)
1992 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1993 "occupied" : "unoccupied");
1995 eject
= tp_features
.bay_eject
&& occupied
;
1996 eject2
= tp_features
.bay_eject2
&& occupied2
;
1998 if (eject
&& eject2
)
1999 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2001 len
+= sprintf(p
+ len
, "commands:\teject\n");
2003 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2008 static int bay_write(char *buf
)
2012 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2015 while ((cmd
= next_cmd(&buf
))) {
2016 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2017 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2019 } else if (tp_features
.bay_eject2
&&
2020 strlencmp(cmd
, "eject2") == 0) {
2021 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2030 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2031 .notify
= bay_notify
,
2032 .handle
= &bay_handle
,
2033 .type
= ACPI_SYSTEM_NOTIFY
,
2036 static struct ibm_struct bay_driver_data
= {
2040 .acpi
= &ibm_bay_acpidriver
,
2043 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2045 /*************************************************************************
2049 /* sysfs cmos_command -------------------------------------------------- */
2050 static ssize_t
cmos_command_store(struct device
*dev
,
2051 struct device_attribute
*attr
,
2052 const char *buf
, size_t count
)
2054 unsigned long cmos_cmd
;
2057 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2060 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2061 return (res
)? res
: count
;
2064 static struct device_attribute dev_attr_cmos_command
=
2065 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2067 /* --------------------------------------------------------------------- */
2069 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2073 vdbg_printk(TPACPI_DBG_INIT
,
2074 "initializing cmos commands subdriver\n");
2076 IBM_ACPIHANDLE_INIT(cmos
);
2078 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2079 str_supported(cmos_handle
!= NULL
));
2081 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2085 return (cmos_handle
)? 0 : 1;
2088 static void cmos_exit(void)
2090 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2093 static int cmos_read(char *p
)
2097 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2098 R30, R31, T20-22, X20-21 */
2100 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2102 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2103 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2109 static int cmos_write(char *buf
)
2114 while ((cmd
= next_cmd(&buf
))) {
2115 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2116 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2121 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2129 static struct ibm_struct cmos_driver_data
= {
2132 .write
= cmos_write
,
2136 /*************************************************************************
2140 static enum led_access_mode led_supported
;
2142 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2143 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2144 "LED", /* all others */
2147 static int __init
led_init(struct ibm_init_struct
*iibm
)
2149 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2151 IBM_ACPIHANDLE_INIT(led
);
2154 /* led not supported on R30, R31 */
2155 led_supported
= TPACPI_LED_NONE
;
2156 else if (strlencmp(led_path
, "SLED") == 0)
2158 led_supported
= TPACPI_LED_570
;
2159 else if (strlencmp(led_path
, "SYSL") == 0)
2160 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2161 led_supported
= TPACPI_LED_OLD
;
2164 led_supported
= TPACPI_LED_NEW
;
2166 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2167 str_supported(led_supported
), led_supported
);
2169 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2172 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2174 static int led_read(char *p
)
2178 if (!led_supported
) {
2179 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2182 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2184 if (led_supported
== TPACPI_LED_570
) {
2187 for (i
= 0; i
< 8; i
++) {
2188 if (!acpi_evalf(ec_handle
,
2189 &status
, "GLED", "dd", 1 << i
))
2191 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2192 i
, led_status(status
));
2196 len
+= sprintf(p
+ len
, "commands:\t"
2197 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2202 /* off, on, blink */
2203 static const int led_sled_arg1
[] = { 0, 1, 3 };
2204 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2205 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2206 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2208 static int led_write(char *buf
)
2216 while ((cmd
= next_cmd(&buf
))) {
2217 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2220 if (strstr(cmd
, "off")) {
2222 } else if (strstr(cmd
, "on")) {
2224 } else if (strstr(cmd
, "blink")) {
2229 if (led_supported
== TPACPI_LED_570
) {
2232 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2233 led
, led_sled_arg1
[ind
]))
2235 } else if (led_supported
== TPACPI_LED_OLD
) {
2236 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2238 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2241 ec_write(TPACPI_LED_EC_HLBL
,
2242 led
* led_exp_hlbl
[ind
]);
2245 ec_write(TPACPI_LED_EC_HLCL
,
2246 led
* led_exp_hlcl
[ind
]);
2251 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2252 led
, led_led_arg1
[ind
]))
2260 static struct ibm_struct led_driver_data
= {
2266 /*************************************************************************
2270 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2272 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2274 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2276 IBM_ACPIHANDLE_INIT(beep
);
2278 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2279 str_supported(beep_handle
!= NULL
));
2281 return (beep_handle
)? 0 : 1;
2284 static int beep_read(char *p
)
2289 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2291 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2292 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2298 static int beep_write(char *buf
)
2306 while ((cmd
= next_cmd(&buf
))) {
2307 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2308 beep_cmd
>= 0 && beep_cmd
<= 17) {
2312 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2319 static struct ibm_struct beep_driver_data
= {
2322 .write
= beep_write
,
2325 /*************************************************************************
2329 static enum thermal_access_mode thermal_read_mode
;
2331 /* sysfs temp##_input -------------------------------------------------- */
2333 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2334 struct device_attribute
*attr
,
2337 struct sensor_device_attribute
*sensor_attr
=
2338 to_sensor_dev_attr(attr
);
2339 int idx
= sensor_attr
->index
;
2343 res
= thermal_get_sensor(idx
, &value
);
2346 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2349 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2352 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2353 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2355 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2356 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2357 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2358 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2359 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2360 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2361 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2362 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2363 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2364 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2365 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2366 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2367 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2368 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2369 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2370 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2371 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2374 #define THERMAL_ATTRS(X) \
2375 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2377 static struct attribute
*thermal_temp_input_attr
[] = {
2397 static const struct attribute_group thermal_temp_input16_group
= {
2398 .attrs
= thermal_temp_input_attr
2401 static const struct attribute_group thermal_temp_input8_group
= {
2402 .attrs
= &thermal_temp_input_attr
[8]
2405 #undef THERMAL_SENSOR_ATTR_TEMP
2406 #undef THERMAL_ATTRS
2408 /* --------------------------------------------------------------------- */
2410 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2417 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2419 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2421 if (ibm_thinkpad_ec_found
&& experimental
) {
2423 * Direct EC access mode: sensors at registers
2424 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2425 * non-implemented, thermal sensors return 0x80 when
2430 for (i
= 0; i
< 8; i
++) {
2431 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2437 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2445 /* This is sheer paranoia, but we handle it anyway */
2448 "ThinkPad ACPI EC access misbehaving, "
2449 "falling back to ACPI TMPx access mode\n");
2450 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2453 "ThinkPad ACPI EC access misbehaving, "
2454 "disabling thermal sensors access\n");
2455 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2460 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2462 } else if (acpi_tmp7
) {
2463 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2464 /* 600e/x, 770e, 770x */
2465 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2467 /* Standard ACPI TMPx access, max 8 sensors */
2468 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2471 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2472 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2475 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2476 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2479 switch(thermal_read_mode
) {
2480 case TPACPI_THERMAL_TPEC_16
:
2481 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2482 &thermal_temp_input16_group
);
2486 case TPACPI_THERMAL_TPEC_8
:
2487 case TPACPI_THERMAL_ACPI_TMP07
:
2488 case TPACPI_THERMAL_ACPI_UPDT
:
2489 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2490 &thermal_temp_input8_group
);
2494 case TPACPI_THERMAL_NONE
:
2502 static void thermal_exit(void)
2504 switch(thermal_read_mode
) {
2505 case TPACPI_THERMAL_TPEC_16
:
2506 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2507 &thermal_temp_input16_group
);
2509 case TPACPI_THERMAL_TPEC_8
:
2510 case TPACPI_THERMAL_ACPI_TMP07
:
2511 case TPACPI_THERMAL_ACPI_UPDT
:
2512 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2513 &thermal_temp_input16_group
);
2515 case TPACPI_THERMAL_NONE
:
2521 /* idx is zero-based */
2522 static int thermal_get_sensor(int idx
, s32
*value
)
2528 t
= TP_EC_THERMAL_TMP0
;
2530 switch (thermal_read_mode
) {
2531 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2532 case TPACPI_THERMAL_TPEC_16
:
2533 if (idx
>= 8 && idx
<= 15) {
2534 t
= TP_EC_THERMAL_TMP8
;
2539 case TPACPI_THERMAL_TPEC_8
:
2541 if (!acpi_ec_read(t
+ idx
, &tmp
))
2543 *value
= tmp
* 1000;
2548 case TPACPI_THERMAL_ACPI_UPDT
:
2550 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2551 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2553 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2555 *value
= (t
- 2732) * 100;
2560 case TPACPI_THERMAL_ACPI_TMP07
:
2562 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2563 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2570 case TPACPI_THERMAL_NONE
:
2578 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2589 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2592 for(i
= 0 ; i
< n
; i
++) {
2593 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
2601 static int thermal_read(char *p
)
2605 struct ibm_thermal_sensors_struct t
;
2607 n
= thermal_get_sensors(&t
);
2608 if (unlikely(n
< 0))
2611 len
+= sprintf(p
+ len
, "temperatures:\t");
2614 for (i
= 0; i
< (n
- 1); i
++)
2615 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
2616 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
2618 len
+= sprintf(p
+ len
, "not supported\n");
2623 static struct ibm_struct thermal_driver_data
= {
2625 .read
= thermal_read
,
2626 .exit
= thermal_exit
,
2629 /*************************************************************************
2633 static u8 ecdump_regs
[256];
2635 static int ecdump_read(char *p
)
2641 len
+= sprintf(p
+ len
, "EC "
2642 " +00 +01 +02 +03 +04 +05 +06 +07"
2643 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2644 for (i
= 0; i
< 256; i
+= 16) {
2645 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
2646 for (j
= 0; j
< 16; j
++) {
2647 if (!acpi_ec_read(i
+ j
, &v
))
2649 if (v
!= ecdump_regs
[i
+ j
])
2650 len
+= sprintf(p
+ len
, " *%02x", v
);
2652 len
+= sprintf(p
+ len
, " %02x", v
);
2653 ecdump_regs
[i
+ j
] = v
;
2655 len
+= sprintf(p
+ len
, "\n");
2660 /* These are way too dangerous to advertise openly... */
2662 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
2663 " (<offset> is 00-ff, <value> is 00-ff)\n");
2664 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
2665 " (<offset> is 00-ff, <value> is 0-255)\n");
2670 static int ecdump_write(char *buf
)
2675 while ((cmd
= next_cmd(&buf
))) {
2676 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
2678 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
2682 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
2683 if (!acpi_ec_write(i
, v
))
2692 static struct ibm_struct ecdump_driver_data
= {
2694 .read
= ecdump_read
,
2695 .write
= ecdump_write
,
2696 .flags
.experimental
= 1,
2699 /*************************************************************************
2700 * Backlight/brightness subdriver
2703 static struct backlight_device
*ibm_backlight_device
;
2705 static struct backlight_ops ibm_backlight_data
= {
2706 .get_brightness
= brightness_get
,
2707 .update_status
= brightness_update_status
,
2710 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
2714 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
2716 b
= brightness_get(NULL
);
2720 ibm_backlight_device
= backlight_device_register(
2721 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
2722 &ibm_backlight_data
);
2723 if (IS_ERR(ibm_backlight_device
)) {
2724 printk(IBM_ERR
"Could not register backlight device\n");
2725 return PTR_ERR(ibm_backlight_device
);
2727 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
2729 ibm_backlight_device
->props
.max_brightness
= 7;
2730 ibm_backlight_device
->props
.brightness
= b
;
2731 backlight_update_status(ibm_backlight_device
);
2736 static void brightness_exit(void)
2738 if (ibm_backlight_device
) {
2739 vdbg_printk(TPACPI_DBG_EXIT
,
2740 "calling backlight_device_unregister()\n");
2741 backlight_device_unregister(ibm_backlight_device
);
2742 ibm_backlight_device
= NULL
;
2746 static int brightness_update_status(struct backlight_device
*bd
)
2748 return brightness_set(
2749 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
2750 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
2751 bd
->props
.brightness
: 0);
2754 static int brightness_get(struct backlight_device
*bd
)
2757 if (!acpi_ec_read(brightness_offset
, &level
))
2765 static int brightness_set(int value
)
2767 int cmos_cmd
, inc
, i
;
2768 int current_value
= brightness_get(NULL
);
2772 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
2773 inc
= value
> current_value
? 1 : -1;
2774 for (i
= current_value
; i
!= value
; i
+= inc
) {
2775 if (issue_thinkpad_cmos_command(cmos_cmd
))
2777 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
2784 static int brightness_read(char *p
)
2789 if ((level
= brightness_get(NULL
)) < 0) {
2790 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2792 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
2793 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
2794 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2795 " (<level> is 0-7)\n");
2801 static int brightness_write(char *buf
)
2807 while ((cmd
= next_cmd(&buf
))) {
2808 if ((level
= brightness_get(NULL
)) < 0)
2812 if (strlencmp(cmd
, "up") == 0) {
2813 new_level
= level
== 7 ? 7 : level
+ 1;
2814 } else if (strlencmp(cmd
, "down") == 0) {
2815 new_level
= level
== 0 ? 0 : level
- 1;
2816 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2817 new_level
>= 0 && new_level
<= 7) {
2822 brightness_set(new_level
);
2828 static struct ibm_struct brightness_driver_data
= {
2829 .name
= "brightness",
2830 .read
= brightness_read
,
2831 .write
= brightness_write
,
2832 .exit
= brightness_exit
,
2835 /*************************************************************************
2839 static int volume_read(char *p
)
2844 if (!acpi_ec_read(volume_offset
, &level
)) {
2845 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2847 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
2848 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
2849 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
2850 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2851 " (<level> is 0-15)\n");
2857 static int volume_write(char *buf
)
2859 int cmos_cmd
, inc
, i
;
2861 int new_level
, new_mute
;
2864 while ((cmd
= next_cmd(&buf
))) {
2865 if (!acpi_ec_read(volume_offset
, &level
))
2867 new_mute
= mute
= level
& 0x40;
2868 new_level
= level
= level
& 0xf;
2870 if (strlencmp(cmd
, "up") == 0) {
2874 new_level
= level
== 15 ? 15 : level
+ 1;
2875 } else if (strlencmp(cmd
, "down") == 0) {
2879 new_level
= level
== 0 ? 0 : level
- 1;
2880 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2881 new_level
>= 0 && new_level
<= 15) {
2883 } else if (strlencmp(cmd
, "mute") == 0) {
2888 if (new_level
!= level
) { /* mute doesn't change */
2889 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
2890 inc
= new_level
> level
? 1 : -1;
2892 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
2893 !acpi_ec_write(volume_offset
, level
)))
2896 for (i
= level
; i
!= new_level
; i
+= inc
)
2897 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2898 !acpi_ec_write(volume_offset
, i
+ inc
))
2901 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
2902 !acpi_ec_write(volume_offset
,
2907 if (new_mute
!= mute
) { /* level doesn't change */
2908 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
2910 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2911 !acpi_ec_write(volume_offset
, level
+ new_mute
))
2919 static struct ibm_struct volume_driver_data
= {
2921 .read
= volume_read
,
2922 .write
= volume_write
,
2925 /*************************************************************************
2932 * TPACPI_FAN_RD_ACPI_GFAN:
2933 * ACPI GFAN method: returns fan level
2935 * see TPACPI_FAN_WR_ACPI_SFAN
2936 * EC 0x2f (HFSP) not available if GFAN exists
2938 * TPACPI_FAN_WR_ACPI_SFAN:
2939 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2941 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2944 * TPACPI_FAN_WR_TPEC:
2945 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2946 * Supported on almost all ThinkPads
2948 * Fan speed changes of any sort (including those caused by the
2949 * disengaged mode) are usually done slowly by the firmware as the
2950 * maximum ammount of fan duty cycle change per second seems to be
2953 * Reading is not available if GFAN exists.
2954 * Writing is not available if SFAN exists.
2957 * 7 automatic mode engaged;
2958 * (default operation mode of the ThinkPad)
2959 * fan level is ignored in this mode.
2960 * 6 full speed mode (takes precedence over bit 7);
2961 * not available on all thinkpads. May disable
2962 * the tachometer while the fan controller ramps up
2963 * the speed (which can take up to a few *minutes*).
2964 * Speeds up fan to 100% duty-cycle, which is far above
2965 * the standard RPM levels. It is not impossible that
2966 * it could cause hardware damage.
2967 * 5-3 unused in some models. Extra bits for fan level
2968 * in others, but still useless as all values above
2969 * 7 map to the same speed as level 7 in these models.
2970 * 2-0 fan level (0..7 usually)
2972 * 0x07 = max (set when temperatures critical)
2973 * Some ThinkPads may have other levels, see
2974 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2976 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2977 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2978 * does so, its initial value is meaningless (0x07).
2980 * For firmware bugs, refer to:
2981 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2985 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2986 * Main fan tachometer reading (in RPM)
2988 * This register is present on all ThinkPads with a new-style EC, and
2989 * it is known not to be present on the A21m/e, and T22, as there is
2990 * something else in offset 0x84 according to the ACPI DSDT. Other
2991 * ThinkPads from this same time period (and earlier) probably lack the
2992 * tachometer as well.
2994 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2995 * was never fixed by IBM to report the EC firmware version string
2996 * probably support the tachometer (like the early X models), so
2997 * detecting it is quite hard. We need more data to know for sure.
2999 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3002 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3005 * For firmware bugs, refer to:
3006 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3008 * TPACPI_FAN_WR_ACPI_FANS:
3009 * ThinkPad X31, X40, X41. Not available in the X60.
3011 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3012 * high speed. ACPI DSDT seems to map these three speeds to levels
3013 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3014 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3016 * The speeds are stored on handles
3017 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3019 * There are three default speed sets, acessible as handles:
3020 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3022 * ACPI DSDT switches which set is in use depending on various
3025 * TPACPI_FAN_WR_TPEC is also available and should be used to
3026 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3027 * but the ACPI tables just mention level 7.
3030 static enum fan_status_access_mode fan_status_access_mode
;
3031 static enum fan_control_access_mode fan_control_access_mode
;
3032 static enum fan_control_commands fan_control_commands
;
3034 static u8 fan_control_initial_status
;
3035 static u8 fan_control_desired_level
;
3037 static void fan_watchdog_fire(struct work_struct
*ignored
);
3038 static int fan_watchdog_maxinterval
;
3039 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3041 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3042 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3043 "\\FSPD", /* 600e/x, 770e, 770x */
3045 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3046 "JFNS", /* 770x-JL */
3050 * SYSFS fan layout: hwmon compatible (device)
3053 * 0: "disengaged" mode
3055 * 2: native EC "auto" mode (recommended, hardware default)
3057 * pwm*: set speed in manual mode, ignored otherwise.
3058 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3061 * fan*_input: tachometer reading, RPM
3064 * SYSFS fan layout: extensions
3066 * fan_watchdog (driver):
3067 * fan watchdog interval in seconds, 0 disables (default), max 120
3070 /* sysfs fan pwm1_enable ----------------------------------------------- */
3071 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3072 struct device_attribute
*attr
,
3078 res
= fan_get_status_safe(&status
);
3082 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3083 if (status
!= fan_control_initial_status
) {
3084 tp_features
.fan_ctrl_status_undef
= 0;
3086 /* Return most likely status. In fact, it
3087 * might be the only possible status */
3088 status
= TP_EC_FAN_AUTO
;
3092 if (status
& TP_EC_FAN_FULLSPEED
) {
3094 } else if (status
& TP_EC_FAN_AUTO
) {
3099 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3102 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3103 struct device_attribute
*attr
,
3104 const char *buf
, size_t count
)
3109 if (parse_strtoul(buf
, 2, &t
))
3114 level
= TP_EC_FAN_FULLSPEED
;
3117 level
= TPACPI_FAN_LAST_LEVEL
;
3120 level
= TP_EC_FAN_AUTO
;
3123 /* reserved for software-controlled auto mode */
3129 res
= fan_set_level_safe(level
);
3135 fan_watchdog_reset();
3140 static struct device_attribute dev_attr_fan_pwm1_enable
=
3141 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3142 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3144 /* sysfs fan pwm1 ------------------------------------------------------ */
3145 static ssize_t
fan_pwm1_show(struct device
*dev
,
3146 struct device_attribute
*attr
,
3152 res
= fan_get_status_safe(&status
);
3156 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3157 if (status
!= fan_control_initial_status
) {
3158 tp_features
.fan_ctrl_status_undef
= 0;
3160 status
= TP_EC_FAN_AUTO
;
3165 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3166 status
= fan_control_desired_level
;
3171 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3174 static ssize_t
fan_pwm1_store(struct device
*dev
,
3175 struct device_attribute
*attr
,
3176 const char *buf
, size_t count
)
3180 u8 status
, newlevel
;
3182 if (parse_strtoul(buf
, 255, &s
))
3185 /* scale down from 0-255 to 0-7 */
3186 newlevel
= (s
>> 5) & 0x07;
3188 rc
= mutex_lock_interruptible(&fan_mutex
);
3192 rc
= fan_get_status(&status
);
3193 if (!rc
&& (status
&
3194 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3195 rc
= fan_set_level(newlevel
);
3199 fan_update_desired_level(newlevel
);
3200 fan_watchdog_reset();
3204 mutex_unlock(&fan_mutex
);
3205 return (rc
)? rc
: count
;
3208 static struct device_attribute dev_attr_fan_pwm1
=
3209 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3210 fan_pwm1_show
, fan_pwm1_store
);
3212 /* sysfs fan fan1_input ------------------------------------------------ */
3213 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3214 struct device_attribute
*attr
,
3220 res
= fan_get_speed(&speed
);
3224 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3227 static struct device_attribute dev_attr_fan_fan1_input
=
3228 __ATTR(fan1_input
, S_IRUGO
,
3229 fan_fan1_input_show
, NULL
);
3231 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
3232 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3235 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3238 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3239 const char *buf
, size_t count
)
3243 if (parse_strtoul(buf
, 120, &t
))
3246 if (!fan_control_allowed
)
3249 fan_watchdog_maxinterval
= t
;
3250 fan_watchdog_reset();
3255 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3256 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3258 /* --------------------------------------------------------------------- */
3259 static struct attribute
*fan_attributes
[] = {
3260 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3261 &dev_attr_fan_fan1_input
.attr
,
3265 static const struct attribute_group fan_attr_group
= {
3266 .attrs
= fan_attributes
,
3269 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3273 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3275 mutex_init(&fan_mutex
);
3276 fan_status_access_mode
= TPACPI_FAN_NONE
;
3277 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3278 fan_control_commands
= 0;
3279 fan_watchdog_maxinterval
= 0;
3280 tp_features
.fan_ctrl_status_undef
= 0;
3281 fan_control_desired_level
= 7;
3283 IBM_ACPIHANDLE_INIT(fans
);
3284 IBM_ACPIHANDLE_INIT(gfan
);
3285 IBM_ACPIHANDLE_INIT(sfan
);
3288 /* 570, 600e/x, 770e, 770x */
3289 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3291 /* all other ThinkPads: note that even old-style
3292 * ThinkPad ECs supports the fan control register */
3293 if (likely(acpi_ec_read(fan_status_offset
,
3294 &fan_control_initial_status
))) {
3295 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3297 /* In some ThinkPads, neither the EC nor the ACPI
3298 * DSDT initialize the fan status, and it ends up
3299 * being set to 0x07 when it *could* be either
3302 * Enable for TP-1Y (T43), TP-78 (R51e),
3303 * TP-76 (R52), TP-70 (T43, R52), which are known
3305 if (fan_control_initial_status
== 0x07 &&
3306 ibm_thinkpad_ec_found
&&
3307 ((ibm_thinkpad_ec_found
[0] == '1' &&
3308 ibm_thinkpad_ec_found
[1] == 'Y') ||
3309 (ibm_thinkpad_ec_found
[0] == '7' &&
3310 (ibm_thinkpad_ec_found
[1] == '6' ||
3311 ibm_thinkpad_ec_found
[1] == '8' ||
3312 ibm_thinkpad_ec_found
[1] == '0'))
3315 "fan_init: initial fan status is "
3316 "unknown, assuming it is in auto "
3318 tp_features
.fan_ctrl_status_undef
= 1;
3322 "ThinkPad ACPI EC access misbehaving, "
3323 "fan status and control unavailable\n");
3330 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3331 fan_control_commands
|=
3332 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3335 /* gfan without sfan means no fan control */
3336 /* all other models implement TP EC 0x2f control */
3340 fan_control_access_mode
=
3341 TPACPI_FAN_WR_ACPI_FANS
;
3342 fan_control_commands
|=
3343 TPACPI_FAN_CMD_SPEED
|
3344 TPACPI_FAN_CMD_LEVEL
|
3345 TPACPI_FAN_CMD_ENABLE
;
3347 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3348 fan_control_commands
|=
3349 TPACPI_FAN_CMD_LEVEL
|
3350 TPACPI_FAN_CMD_ENABLE
;
3355 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3356 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3357 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3358 fan_status_access_mode
, fan_control_access_mode
);
3360 /* fan control master switch */
3361 if (!fan_control_allowed
) {
3362 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3363 fan_control_commands
= 0;
3364 dbg_printk(TPACPI_DBG_INIT
,
3365 "fan control features disabled by parameter\n");
3368 /* update fan_control_desired_level */
3369 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3370 fan_get_status_safe(NULL
);
3372 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3373 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3374 rc
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3377 rc
= driver_create_file(&tpacpi_pdriver
.driver
,
3378 &driver_attr_fan_watchdog
);
3387 * Call with fan_mutex held
3389 static void fan_update_desired_level(u8 status
)
3392 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3394 fan_control_desired_level
= 7;
3396 fan_control_desired_level
= status
;
3400 static int fan_get_status(u8
*status
)
3405 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3407 switch (fan_status_access_mode
) {
3408 case TPACPI_FAN_RD_ACPI_GFAN
:
3409 /* 570, 600e/x, 770e, 770x */
3411 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
3419 case TPACPI_FAN_RD_TPEC
:
3420 /* all except 570, 600e/x, 770e, 770x */
3421 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
3436 static int fan_get_status_safe(u8
*status
)
3441 rc
= mutex_lock_interruptible(&fan_mutex
);
3444 rc
= fan_get_status(&s
);
3446 fan_update_desired_level(s
);
3447 mutex_unlock(&fan_mutex
);
3455 static void fan_exit(void)
3457 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
3459 /* FIXME: can we really do this unconditionally? */
3460 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
, &fan_attr_group
);
3461 driver_remove_file(&tpacpi_pdriver
.driver
, &driver_attr_fan_watchdog
);
3463 cancel_delayed_work(&fan_watchdog_task
);
3464 flush_scheduled_work();
3467 static int fan_get_speed(unsigned int *speed
)
3471 switch (fan_status_access_mode
) {
3472 case TPACPI_FAN_RD_TPEC
:
3473 /* all except 570, 600e/x, 770e, 770x */
3474 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
3475 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
3479 *speed
= (hi
<< 8) | lo
;
3490 static void fan_watchdog_fire(struct work_struct
*ignored
)
3494 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
3495 rc
= fan_set_enable();
3497 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
3498 "will try again later...\n", -rc
);
3499 /* reschedule for later */
3500 fan_watchdog_reset();
3504 static void fan_watchdog_reset(void)
3506 static int fan_watchdog_active
;
3508 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
3511 if (fan_watchdog_active
)
3512 cancel_delayed_work(&fan_watchdog_task
);
3514 if (fan_watchdog_maxinterval
> 0) {
3515 fan_watchdog_active
= 1;
3516 if (!schedule_delayed_work(&fan_watchdog_task
,
3517 msecs_to_jiffies(fan_watchdog_maxinterval
3519 printk(IBM_ERR
"failed to schedule the fan watchdog, "
3520 "watchdog will not trigger\n");
3523 fan_watchdog_active
= 0;
3526 static int fan_set_level(int level
)
3528 if (!fan_control_allowed
)
3531 switch (fan_control_access_mode
) {
3532 case TPACPI_FAN_WR_ACPI_SFAN
:
3533 if (level
>= 0 && level
<= 7) {
3534 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
3540 case TPACPI_FAN_WR_ACPI_FANS
:
3541 case TPACPI_FAN_WR_TPEC
:
3542 if ((level
!= TP_EC_FAN_AUTO
) &&
3543 (level
!= TP_EC_FAN_FULLSPEED
) &&
3544 ((level
< 0) || (level
> 7)))
3547 /* safety net should the EC not support AUTO
3548 * or FULLSPEED mode bits and just ignore them */
3549 if (level
& TP_EC_FAN_FULLSPEED
)
3550 level
|= 7; /* safety min speed 7 */
3551 else if (level
& TP_EC_FAN_FULLSPEED
)
3552 level
|= 4; /* safety min speed 4 */
3554 if (!acpi_ec_write(fan_status_offset
, level
))
3557 tp_features
.fan_ctrl_status_undef
= 0;
3566 static int fan_set_level_safe(int level
)
3570 if (!fan_control_allowed
)
3573 rc
= mutex_lock_interruptible(&fan_mutex
);
3577 if (level
== TPACPI_FAN_LAST_LEVEL
)
3578 level
= fan_control_desired_level
;
3580 rc
= fan_set_level(level
);
3582 fan_update_desired_level(level
);
3584 mutex_unlock(&fan_mutex
);
3588 static int fan_set_enable(void)
3593 if (!fan_control_allowed
)
3596 rc
= mutex_lock_interruptible(&fan_mutex
);
3600 switch (fan_control_access_mode
) {
3601 case TPACPI_FAN_WR_ACPI_FANS
:
3602 case TPACPI_FAN_WR_TPEC
:
3603 rc
= fan_get_status(&s
);
3607 /* Don't go out of emergency fan mode */
3610 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
3613 if (!acpi_ec_write(fan_status_offset
, s
))
3616 tp_features
.fan_ctrl_status_undef
= 0;
3621 case TPACPI_FAN_WR_ACPI_SFAN
:
3622 rc
= fan_get_status(&s
);
3628 /* Set fan to at least level 4 */
3631 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
3641 mutex_unlock(&fan_mutex
);
3645 static int fan_set_disable(void)
3649 if (!fan_control_allowed
)
3652 rc
= mutex_lock_interruptible(&fan_mutex
);
3657 switch (fan_control_access_mode
) {
3658 case TPACPI_FAN_WR_ACPI_FANS
:
3659 case TPACPI_FAN_WR_TPEC
:
3660 if (!acpi_ec_write(fan_status_offset
, 0x00))
3663 fan_control_desired_level
= 0;
3664 tp_features
.fan_ctrl_status_undef
= 0;
3668 case TPACPI_FAN_WR_ACPI_SFAN
:
3669 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
3672 fan_control_desired_level
= 0;
3680 mutex_unlock(&fan_mutex
);
3684 static int fan_set_speed(int speed
)
3688 if (!fan_control_allowed
)
3691 rc
= mutex_lock_interruptible(&fan_mutex
);
3696 switch (fan_control_access_mode
) {
3697 case TPACPI_FAN_WR_ACPI_FANS
:
3698 if (speed
>= 0 && speed
<= 65535) {
3699 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
3700 speed
, speed
, speed
))
3710 mutex_unlock(&fan_mutex
);
3714 static int fan_read(char *p
)
3719 unsigned int speed
= 0;
3721 switch (fan_status_access_mode
) {
3722 case TPACPI_FAN_RD_ACPI_GFAN
:
3723 /* 570, 600e/x, 770e, 770x */
3724 if ((rc
= fan_get_status_safe(&status
)) < 0)
3727 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
3729 (status
!= 0) ? "enabled" : "disabled", status
);
3732 case TPACPI_FAN_RD_TPEC
:
3733 /* all except 570, 600e/x, 770e, 770x */
3734 if ((rc
= fan_get_status_safe(&status
)) < 0)
3737 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3738 if (status
!= fan_control_initial_status
)
3739 tp_features
.fan_ctrl_status_undef
= 0;
3741 /* Return most likely status. In fact, it
3742 * might be the only possible status */
3743 status
= TP_EC_FAN_AUTO
;
3746 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3747 (status
!= 0) ? "enabled" : "disabled");
3749 if ((rc
= fan_get_speed(&speed
)) < 0)
3752 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
3754 if (status
& TP_EC_FAN_FULLSPEED
)
3755 /* Disengaged mode takes precedence */
3756 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
3757 else if (status
& TP_EC_FAN_AUTO
)
3758 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
3760 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
3763 case TPACPI_FAN_NONE
:
3765 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3768 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
3769 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
3771 switch (fan_control_access_mode
) {
3772 case TPACPI_FAN_WR_ACPI_SFAN
:
3773 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
3777 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
3778 "auto, disengaged, full-speed)\n");
3783 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
3784 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
3785 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
3786 "1-120 (seconds))\n");
3788 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
3789 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
3790 " (<speed> is 0-65535)\n");
3795 static int fan_write_cmd_level(const char *cmd
, int *rc
)
3799 if (strlencmp(cmd
, "level auto") == 0)
3800 level
= TP_EC_FAN_AUTO
;
3801 else if ((strlencmp(cmd
, "level disengaged") == 0) |
3802 (strlencmp(cmd
, "level full-speed") == 0))
3803 level
= TP_EC_FAN_FULLSPEED
;
3804 else if (sscanf(cmd
, "level %d", &level
) != 1)
3807 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
3808 printk(IBM_ERR
"level command accepted for unsupported "
3809 "access mode %d", fan_control_access_mode
);
3814 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
3816 if (strlencmp(cmd
, "enable") != 0)
3819 if ((*rc
= fan_set_enable()) == -ENXIO
)
3820 printk(IBM_ERR
"enable command accepted for unsupported "
3821 "access mode %d", fan_control_access_mode
);
3826 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
3828 if (strlencmp(cmd
, "disable") != 0)
3831 if ((*rc
= fan_set_disable()) == -ENXIO
)
3832 printk(IBM_ERR
"disable command accepted for unsupported "
3833 "access mode %d", fan_control_access_mode
);
3838 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
3843 * Support speed <low> <medium> <high> ? */
3845 if (sscanf(cmd
, "speed %d", &speed
) != 1)
3848 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
3849 printk(IBM_ERR
"speed command accepted for unsupported "
3850 "access mode %d", fan_control_access_mode
);
3855 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
3859 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
3862 if (interval
< 0 || interval
> 120)
3865 fan_watchdog_maxinterval
= interval
;
3870 static int fan_write(char *buf
)
3875 while (!rc
&& (cmd
= next_cmd(&buf
))) {
3876 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
3877 fan_write_cmd_level(cmd
, &rc
)) &&
3878 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
3879 (fan_write_cmd_enable(cmd
, &rc
) ||
3880 fan_write_cmd_disable(cmd
, &rc
) ||
3881 fan_write_cmd_watchdog(cmd
, &rc
))) &&
3882 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
3883 fan_write_cmd_speed(cmd
, &rc
))
3887 fan_watchdog_reset();
3893 static struct ibm_struct fan_driver_data
= {
3900 /****************************************************************************
3901 ****************************************************************************
3905 ****************************************************************************
3906 ****************************************************************************/
3909 static struct proc_dir_entry
*proc_dir
;
3911 /* Subdriver registry */
3912 static LIST_HEAD(tpacpi_all_drivers
);
3916 * Module and infrastructure proble, init and exit handling
3919 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
3920 static const char * __init
str_supported(int is_supported
)
3922 static char text_unsupported
[] __initdata
= "not supported";
3924 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
3926 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
3928 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
3931 struct ibm_struct
*ibm
= iibm
->data
;
3932 struct proc_dir_entry
*entry
;
3934 BUG_ON(ibm
== NULL
);
3936 INIT_LIST_HEAD(&ibm
->all_drivers
);
3938 if (ibm
->flags
.experimental
&& !experimental
)
3941 dbg_printk(TPACPI_DBG_INIT
,
3942 "probing for %s\n", ibm
->name
);
3945 ret
= iibm
->init(iibm
);
3947 return 0; /* probe failed */
3951 ibm
->flags
.init_called
= 1;
3955 if (ibm
->acpi
->hid
) {
3956 ret
= register_tpacpi_subdriver(ibm
);
3961 if (ibm
->acpi
->notify
) {
3962 ret
= setup_acpi_notify(ibm
);
3963 if (ret
== -ENODEV
) {
3964 printk(IBM_NOTICE
"disabling subdriver %s\n",
3974 dbg_printk(TPACPI_DBG_INIT
,
3975 "%s installed\n", ibm
->name
);
3978 entry
= create_proc_entry(ibm
->name
,
3979 S_IFREG
| S_IRUGO
| S_IWUSR
,
3982 printk(IBM_ERR
"unable to create proc entry %s\n",
3987 entry
->owner
= THIS_MODULE
;
3989 entry
->read_proc
= &dispatch_procfs_read
;
3991 entry
->write_proc
= &dispatch_procfs_write
;
3992 ibm
->flags
.proc_created
= 1;
3995 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4000 dbg_printk(TPACPI_DBG_INIT
,
4001 "%s: at error exit path with result %d\n",
4005 return (ret
< 0)? ret
: 0;
4008 static void ibm_exit(struct ibm_struct
*ibm
)
4010 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4012 list_del_init(&ibm
->all_drivers
);
4014 if (ibm
->flags
.acpi_notify_installed
) {
4015 dbg_printk(TPACPI_DBG_EXIT
,
4016 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4018 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4020 dispatch_acpi_notify
);
4021 ibm
->flags
.acpi_notify_installed
= 0;
4022 ibm
->flags
.acpi_notify_installed
= 0;
4025 if (ibm
->flags
.proc_created
) {
4026 dbg_printk(TPACPI_DBG_EXIT
,
4027 "%s: remove_proc_entry\n", ibm
->name
);
4028 remove_proc_entry(ibm
->name
, proc_dir
);
4029 ibm
->flags
.proc_created
= 0;
4032 if (ibm
->flags
.acpi_driver_registered
) {
4033 dbg_printk(TPACPI_DBG_EXIT
,
4034 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4036 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4037 kfree(ibm
->acpi
->driver
);
4038 ibm
->acpi
->driver
= NULL
;
4039 ibm
->flags
.acpi_driver_registered
= 0;
4042 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4044 ibm
->flags
.init_called
= 0;
4047 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4052 static char *ibm_thinkpad_ec_found
;
4054 static char* __init
check_dmi_for_ec(void)
4056 struct dmi_device
*dev
= NULL
;
4057 char ec_fw_string
[18];
4060 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4061 * X32 or newer, all Z series; Some models must have an
4062 * up-to-date BIOS or they will not be detected.
4064 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4066 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4067 if (sscanf(dev
->name
,
4068 "IBM ThinkPad Embedded Controller -[%17c",
4069 ec_fw_string
) == 1) {
4070 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4071 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4072 return kstrdup(ec_fw_string
, GFP_KERNEL
);
4078 static int __init
probe_for_thinkpad(void)
4086 * Non-ancient models have better DMI tagging, but very old models
4089 is_thinkpad
= dmi_name_in_vendors("ThinkPad");
4091 /* ec is required because many other handles are relative to it */
4092 IBM_ACPIHANDLE_INIT(ec
);
4096 "Not yet supported ThinkPad detected!\n");
4101 * Risks a regression on very old machines, but reduces potential
4102 * false positives a damn great deal
4105 is_thinkpad
= dmi_name_in_vendors("IBM");
4107 if (!is_thinkpad
&& !force_load
)
4114 /* Module init, exit, parameters */
4116 static struct ibm_init_struct ibms_init
[] __initdata
= {
4118 .init
= thinkpad_acpi_driver_init
,
4119 .data
= &thinkpad_acpi_driver_data
,
4122 .init
= hotkey_init
,
4123 .data
= &hotkey_driver_data
,
4126 .init
= bluetooth_init
,
4127 .data
= &bluetooth_driver_data
,
4131 .data
= &wan_driver_data
,
4135 .data
= &video_driver_data
,
4139 .data
= &light_driver_data
,
4141 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4144 .data
= &dock_driver_data
[0],
4148 .data
= &dock_driver_data
[1],
4151 #ifdef CONFIG_THINKPAD_ACPI_BAY
4154 .data
= &bay_driver_data
,
4159 .data
= &cmos_driver_data
,
4163 .data
= &led_driver_data
,
4167 .data
= &beep_driver_data
,
4170 .init
= thermal_init
,
4171 .data
= &thermal_driver_data
,
4174 .data
= &ecdump_driver_data
,
4177 .init
= brightness_init
,
4178 .data
= &brightness_driver_data
,
4181 .data
= &volume_driver_data
,
4185 .data
= &fan_driver_data
,
4189 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4192 struct ibm_struct
*ibm
;
4194 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4195 ibm
= ibms_init
[i
].data
;
4196 BUG_ON(ibm
== NULL
);
4198 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4199 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4201 strcpy(ibms_init
[i
].param
, val
);
4202 strcat(ibms_init
[i
].param
, ",");
4210 static int experimental
;
4211 module_param(experimental
, int, 0);
4213 static u32 dbg_level
;
4214 module_param_named(debug
, dbg_level
, uint
, 0);
4216 static int force_load
;
4217 module_param(force_load
, int, 0);
4219 static int fan_control_allowed
;
4220 module_param_named(fan_control
, fan_control_allowed
, int, 0);
4222 #define IBM_PARAM(feature) \
4223 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4226 IBM_PARAM(bluetooth
);
4229 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4232 #ifdef CONFIG_THINKPAD_ACPI_BAY
4234 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4239 IBM_PARAM(brightness
);
4243 static int __init
thinkpad_acpi_module_init(void)
4247 /* Driver-level probe */
4248 ret
= probe_for_thinkpad();
4252 /* Driver initialization */
4253 ibm_thinkpad_ec_found
= check_dmi_for_ec();
4254 IBM_ACPIHANDLE_INIT(ecrd
);
4255 IBM_ACPIHANDLE_INIT(ecwr
);
4257 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4259 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4260 thinkpad_acpi_module_exit();
4263 proc_dir
->owner
= THIS_MODULE
;
4265 ret
= platform_driver_register(&tpacpi_pdriver
);
4267 printk(IBM_ERR
"unable to register platform driver\n");
4268 thinkpad_acpi_module_exit();
4271 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4273 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4274 thinkpad_acpi_module_exit();
4279 /* Device initialization */
4280 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4282 if (IS_ERR(tpacpi_pdev
)) {
4283 ret
= PTR_ERR(tpacpi_pdev
);
4285 printk(IBM_ERR
"unable to register platform device\n");
4286 thinkpad_acpi_module_exit();
4289 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
4290 if (IS_ERR(tpacpi_hwmon
)) {
4291 ret
= PTR_ERR(tpacpi_hwmon
);
4292 tpacpi_hwmon
= NULL
;
4293 printk(IBM_ERR
"unable to register hwmon device\n");
4294 thinkpad_acpi_module_exit();
4297 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4298 ret
= ibm_init(&ibms_init
[i
]);
4299 if (ret
>= 0 && *ibms_init
[i
].param
)
4300 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
4302 thinkpad_acpi_module_exit();
4310 static void thinkpad_acpi_module_exit(void)
4312 struct ibm_struct
*ibm
, *itmp
;
4314 list_for_each_entry_safe_reverse(ibm
, itmp
,
4315 &tpacpi_all_drivers
,
4320 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
4323 hwmon_device_unregister(tpacpi_hwmon
);
4326 platform_device_unregister(tpacpi_pdev
);
4328 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
4329 platform_driver_unregister(&tpacpi_pdriver
);
4332 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
4334 kfree(ibm_thinkpad_ec_found
);
4337 module_init(thinkpad_acpi_module_init
);
4338 module_exit(thinkpad_acpi_module_exit
);