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
= NULL
;
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
= NULL
;
519 static struct class_device
*tpacpi_hwmon
= NULL
;
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 int hotkey_orig_mask
;
732 static struct attribute_set
*hotkey_dev_attributes
= NULL
;
734 /* sysfs hotkey enable ------------------------------------------------- */
735 static ssize_t
hotkey_enable_show(struct device
*dev
,
736 struct device_attribute
*attr
,
739 int res
, status
, mask
;
741 res
= hotkey_get(&status
, &mask
);
745 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
748 static ssize_t
hotkey_enable_store(struct device
*dev
,
749 struct device_attribute
*attr
,
750 const char *buf
, size_t count
)
753 int res
, status
, mask
;
755 if (parse_strtoul(buf
, 1, &t
))
758 res
= hotkey_get(&status
, &mask
);
760 res
= hotkey_set(t
, mask
);
762 return (res
) ? res
: count
;
765 static struct device_attribute dev_attr_hotkey_enable
=
766 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
767 hotkey_enable_show
, hotkey_enable_store
);
769 /* sysfs hotkey mask --------------------------------------------------- */
770 static ssize_t
hotkey_mask_show(struct device
*dev
,
771 struct device_attribute
*attr
,
774 int res
, status
, mask
;
776 res
= hotkey_get(&status
, &mask
);
780 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", mask
);
783 static ssize_t
hotkey_mask_store(struct device
*dev
,
784 struct device_attribute
*attr
,
785 const char *buf
, size_t count
)
788 int res
, status
, mask
;
790 if (parse_strtoul(buf
, 0xffff, &t
))
793 res
= hotkey_get(&status
, &mask
);
795 hotkey_set(status
, t
);
797 return (res
) ? res
: count
;
800 static struct device_attribute dev_attr_hotkey_mask
=
801 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
802 hotkey_mask_show
, hotkey_mask_store
);
804 /* sysfs hotkey bios_enabled ------------------------------------------- */
805 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
806 struct device_attribute
*attr
,
809 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
812 static struct device_attribute dev_attr_hotkey_bios_enabled
=
813 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
815 /* sysfs hotkey bios_mask ---------------------------------------------- */
816 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
817 struct device_attribute
*attr
,
820 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", hotkey_orig_mask
);
823 static struct device_attribute dev_attr_hotkey_bios_mask
=
824 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
826 /* --------------------------------------------------------------------- */
828 static struct attribute
*hotkey_mask_attributes
[] = {
829 &dev_attr_hotkey_mask
.attr
,
830 &dev_attr_hotkey_bios_enabled
.attr
,
831 &dev_attr_hotkey_bios_mask
.attr
,
834 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
838 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
840 IBM_ACPIHANDLE_INIT(hkey
);
841 mutex_init(&hotkey_mutex
);
843 /* hotkey not supported on 570 */
844 tp_features
.hotkey
= hkey_handle
!= NULL
;
846 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
847 str_supported(tp_features
.hotkey
));
849 if (tp_features
.hotkey
) {
850 hotkey_dev_attributes
= create_attr_set(4, NULL
);
851 if (!hotkey_dev_attributes
)
853 res
= add_to_attr_set(hotkey_dev_attributes
,
854 &dev_attr_hotkey_enable
.attr
);
858 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
859 A30, R30, R31, T20-22, X20-21, X22-24 */
860 tp_features
.hotkey_mask
=
861 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
863 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
864 str_supported(tp_features
.hotkey_mask
));
866 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
867 if (!res
&& tp_features
.hotkey_mask
) {
868 res
= add_many_to_attr_set(hotkey_dev_attributes
,
869 hotkey_mask_attributes
,
870 ARRAY_SIZE(hotkey_mask_attributes
));
873 res
= register_attr_set_with_sysfs(
874 hotkey_dev_attributes
,
875 &tpacpi_pdev
->dev
.kobj
);
881 return (tp_features
.hotkey
)? 0 : 1;
884 static void hotkey_exit(void)
888 if (tp_features
.hotkey
) {
889 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
890 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
892 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
895 if (hotkey_dev_attributes
) {
896 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
897 hotkey_dev_attributes
= NULL
;
901 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
905 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
906 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
908 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
909 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
914 * Call with hotkey_mutex held
916 static int hotkey_get(int *status
, int *mask
)
918 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
921 if (tp_features
.hotkey_mask
)
922 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
929 * Call with hotkey_mutex held
931 static int hotkey_set(int status
, int mask
)
935 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
938 if (tp_features
.hotkey_mask
)
939 for (i
= 0; i
< 32; i
++) {
940 int bit
= ((1 << i
) & mask
) != 0;
941 if (!acpi_evalf(hkey_handle
,
942 NULL
, "MHKM", "vdd", i
+ 1, bit
))
949 /* procfs -------------------------------------------------------------- */
950 static int hotkey_read(char *p
)
952 int res
, status
, mask
;
955 if (!tp_features
.hotkey
) {
956 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
960 res
= mutex_lock_interruptible(&hotkey_mutex
);
963 res
= hotkey_get(&status
, &mask
);
964 mutex_unlock(&hotkey_mutex
);
968 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
969 if (tp_features
.hotkey_mask
) {
970 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
971 len
+= sprintf(p
+ len
,
972 "commands:\tenable, disable, reset, <mask>\n");
974 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
975 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
981 static int hotkey_write(char *buf
)
983 int res
, status
, mask
;
987 if (!tp_features
.hotkey
)
990 res
= mutex_lock_interruptible(&hotkey_mutex
);
994 res
= hotkey_get(&status
, &mask
);
999 while ((cmd
= next_cmd(&buf
))) {
1000 if (strlencmp(cmd
, "enable") == 0) {
1002 } else if (strlencmp(cmd
, "disable") == 0) {
1004 } else if (strlencmp(cmd
, "reset") == 0) {
1005 status
= hotkey_orig_status
;
1006 mask
= hotkey_orig_mask
;
1007 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1009 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1019 res
= hotkey_set(status
, mask
);
1022 mutex_unlock(&hotkey_mutex
);
1026 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1027 .hid
= IBM_HKEY_HID
,
1028 .notify
= hotkey_notify
,
1029 .handle
= &hkey_handle
,
1030 .type
= ACPI_DEVICE_NOTIFY
,
1033 static struct ibm_struct hotkey_driver_data
= {
1035 .read
= hotkey_read
,
1036 .write
= hotkey_write
,
1037 .exit
= hotkey_exit
,
1038 .acpi
= &ibm_hotkey_acpidriver
,
1041 /*************************************************************************
1042 * Bluetooth subdriver
1045 /* sysfs bluetooth enable ---------------------------------------------- */
1046 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1047 struct device_attribute
*attr
,
1052 status
= bluetooth_get_radiosw();
1056 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1059 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1060 struct device_attribute
*attr
,
1061 const char *buf
, size_t count
)
1066 if (parse_strtoul(buf
, 1, &t
))
1069 res
= bluetooth_set_radiosw(t
);
1071 return (res
) ? res
: count
;
1074 static struct device_attribute dev_attr_bluetooth_enable
=
1075 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1076 bluetooth_enable_show
, bluetooth_enable_store
);
1078 /* --------------------------------------------------------------------- */
1080 static struct attribute
*bluetooth_attributes
[] = {
1081 &dev_attr_bluetooth_enable
.attr
,
1085 static const struct attribute_group bluetooth_attr_group
= {
1086 .attrs
= bluetooth_attributes
,
1089 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1094 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1096 IBM_ACPIHANDLE_INIT(hkey
);
1098 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1099 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1100 tp_features
.bluetooth
= hkey_handle
&&
1101 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1103 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1104 str_supported(tp_features
.bluetooth
),
1107 if (tp_features
.bluetooth
) {
1108 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1109 /* no bluetooth hardware present in system */
1110 tp_features
.bluetooth
= 0;
1111 dbg_printk(TPACPI_DBG_INIT
,
1112 "bluetooth hardware not installed\n");
1114 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1115 &bluetooth_attr_group
);
1121 return (tp_features
.bluetooth
)? 0 : 1;
1124 static void bluetooth_exit(void)
1126 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1127 &bluetooth_attr_group
);
1130 static int bluetooth_get_radiosw(void)
1134 if (!tp_features
.bluetooth
)
1137 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1140 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1143 static int bluetooth_set_radiosw(int radio_on
)
1147 if (!tp_features
.bluetooth
)
1150 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1153 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1155 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1156 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1162 /* procfs -------------------------------------------------------------- */
1163 static int bluetooth_read(char *p
)
1166 int status
= bluetooth_get_radiosw();
1168 if (!tp_features
.bluetooth
)
1169 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1171 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1172 (status
)? "enabled" : "disabled");
1173 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1179 static int bluetooth_write(char *buf
)
1183 if (!tp_features
.bluetooth
)
1186 while ((cmd
= next_cmd(&buf
))) {
1187 if (strlencmp(cmd
, "enable") == 0) {
1188 bluetooth_set_radiosw(1);
1189 } else if (strlencmp(cmd
, "disable") == 0) {
1190 bluetooth_set_radiosw(0);
1198 static struct ibm_struct bluetooth_driver_data
= {
1199 .name
= "bluetooth",
1200 .read
= bluetooth_read
,
1201 .write
= bluetooth_write
,
1202 .exit
= bluetooth_exit
,
1205 /*************************************************************************
1209 /* sysfs wan enable ---------------------------------------------------- */
1210 static ssize_t
wan_enable_show(struct device
*dev
,
1211 struct device_attribute
*attr
,
1216 status
= wan_get_radiosw();
1220 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1223 static ssize_t
wan_enable_store(struct device
*dev
,
1224 struct device_attribute
*attr
,
1225 const char *buf
, size_t count
)
1230 if (parse_strtoul(buf
, 1, &t
))
1233 res
= wan_set_radiosw(t
);
1235 return (res
) ? res
: count
;
1238 static struct device_attribute dev_attr_wan_enable
=
1239 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1240 wan_enable_show
, wan_enable_store
);
1242 /* --------------------------------------------------------------------- */
1244 static struct attribute
*wan_attributes
[] = {
1245 &dev_attr_wan_enable
.attr
,
1249 static const struct attribute_group wan_attr_group
= {
1250 .attrs
= wan_attributes
,
1253 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1258 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1260 IBM_ACPIHANDLE_INIT(hkey
);
1262 tp_features
.wan
= hkey_handle
&&
1263 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1265 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1266 str_supported(tp_features
.wan
),
1269 if (tp_features
.wan
) {
1270 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1271 /* no wan hardware present in system */
1272 tp_features
.wan
= 0;
1273 dbg_printk(TPACPI_DBG_INIT
,
1274 "wan hardware not installed\n");
1276 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1283 return (tp_features
.wan
)? 0 : 1;
1286 static void wan_exit(void)
1288 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1292 static int wan_get_radiosw(void)
1296 if (!tp_features
.wan
)
1299 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1302 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1305 static int wan_set_radiosw(int radio_on
)
1309 if (!tp_features
.wan
)
1312 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1315 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1317 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1318 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1324 /* procfs -------------------------------------------------------------- */
1325 static int wan_read(char *p
)
1328 int status
= wan_get_radiosw();
1330 if (!tp_features
.wan
)
1331 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1333 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1334 (status
)? "enabled" : "disabled");
1335 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1341 static int wan_write(char *buf
)
1345 if (!tp_features
.wan
)
1348 while ((cmd
= next_cmd(&buf
))) {
1349 if (strlencmp(cmd
, "enable") == 0) {
1351 } else if (strlencmp(cmd
, "disable") == 0) {
1360 static struct ibm_struct wan_driver_data
= {
1365 .flags
.experimental
= 1,
1368 /*************************************************************************
1372 static enum video_access_mode video_supported
;
1373 static int video_orig_autosw
;
1375 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1376 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1377 "\\_SB.PCI0.VID0", /* 770e */
1378 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1379 "\\_SB.PCI0.AGP.VID", /* all others */
1382 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1384 static int __init
video_init(struct ibm_init_struct
*iibm
)
1388 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1390 IBM_ACPIHANDLE_INIT(vid
);
1391 IBM_ACPIHANDLE_INIT(vid2
);
1393 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1394 /* G41, assume IVGA doesn't change */
1395 vid_handle
= vid2_handle
;
1398 /* video switching not supported on R30, R31 */
1399 video_supported
= TPACPI_VIDEO_NONE
;
1400 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1402 video_supported
= TPACPI_VIDEO_570
;
1403 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1404 /* 600e/x, 770e, 770x */
1405 video_supported
= TPACPI_VIDEO_770
;
1408 video_supported
= TPACPI_VIDEO_NEW
;
1410 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1411 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1414 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1417 static void video_exit(void)
1419 dbg_printk(TPACPI_DBG_EXIT
,
1420 "restoring original video autoswitch mode\n");
1421 if (video_autosw_set(video_orig_autosw
))
1422 printk(IBM_ERR
"error while trying to restore original "
1423 "video autoswitch mode\n");
1426 static int video_outputsw_get(void)
1431 switch (video_supported
) {
1432 case TPACPI_VIDEO_570
:
1433 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1434 TP_ACPI_VIDEO_570_PHSCMD
))
1436 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1438 case TPACPI_VIDEO_770
:
1439 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1442 status
|= TP_ACPI_VIDEO_S_LCD
;
1443 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1446 status
|= TP_ACPI_VIDEO_S_CRT
;
1448 case TPACPI_VIDEO_NEW
:
1449 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1450 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1453 status
|= TP_ACPI_VIDEO_S_CRT
;
1455 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1456 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1459 status
|= TP_ACPI_VIDEO_S_LCD
;
1460 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1463 status
|= TP_ACPI_VIDEO_S_DVI
;
1472 static int video_outputsw_set(int status
)
1477 switch (video_supported
) {
1478 case TPACPI_VIDEO_570
:
1479 res
= acpi_evalf(NULL
, NULL
,
1480 "\\_SB.PHS2", "vdd",
1481 TP_ACPI_VIDEO_570_PHS2CMD
,
1482 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1484 case TPACPI_VIDEO_770
:
1485 autosw
= video_autosw_get();
1489 res
= video_autosw_set(1);
1492 res
= acpi_evalf(vid_handle
, NULL
,
1493 "ASWT", "vdd", status
* 0x100, 0);
1494 if (!autosw
&& video_autosw_set(autosw
)) {
1495 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1499 case TPACPI_VIDEO_NEW
:
1500 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1501 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1507 return (res
)? 0 : -EIO
;
1510 static int video_autosw_get(void)
1514 switch (video_supported
) {
1515 case TPACPI_VIDEO_570
:
1516 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1519 case TPACPI_VIDEO_770
:
1520 case TPACPI_VIDEO_NEW
:
1521 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1531 static int video_autosw_set(int enable
)
1533 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1538 static int video_outputsw_cycle(void)
1540 int autosw
= video_autosw_get();
1546 switch (video_supported
) {
1547 case TPACPI_VIDEO_570
:
1548 res
= video_autosw_set(1);
1551 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1553 case TPACPI_VIDEO_770
:
1554 case TPACPI_VIDEO_NEW
:
1555 res
= video_autosw_set(1);
1558 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1563 if (!autosw
&& video_autosw_set(autosw
)) {
1564 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1568 return (res
)? 0 : -EIO
;
1571 static int video_expand_toggle(void)
1573 switch (video_supported
) {
1574 case TPACPI_VIDEO_570
:
1575 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1577 case TPACPI_VIDEO_770
:
1578 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1580 case TPACPI_VIDEO_NEW
:
1581 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1589 static int video_read(char *p
)
1594 if (video_supported
== TPACPI_VIDEO_NONE
) {
1595 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1599 status
= video_outputsw_get();
1603 autosw
= video_autosw_get();
1607 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1608 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
1609 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
1610 if (video_supported
== TPACPI_VIDEO_NEW
)
1611 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
1612 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
1613 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
1614 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
1615 if (video_supported
== TPACPI_VIDEO_NEW
)
1616 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
1617 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
1618 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
1623 static int video_write(char *buf
)
1626 int enable
, disable
, status
;
1629 if (video_supported
== TPACPI_VIDEO_NONE
)
1635 while ((cmd
= next_cmd(&buf
))) {
1636 if (strlencmp(cmd
, "lcd_enable") == 0) {
1637 enable
|= TP_ACPI_VIDEO_S_LCD
;
1638 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1639 disable
|= TP_ACPI_VIDEO_S_LCD
;
1640 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1641 enable
|= TP_ACPI_VIDEO_S_CRT
;
1642 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1643 disable
|= TP_ACPI_VIDEO_S_CRT
;
1644 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1645 strlencmp(cmd
, "dvi_enable") == 0) {
1646 enable
|= TP_ACPI_VIDEO_S_DVI
;
1647 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1648 strlencmp(cmd
, "dvi_disable") == 0) {
1649 disable
|= TP_ACPI_VIDEO_S_DVI
;
1650 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1651 res
= video_autosw_set(1);
1654 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1655 res
= video_autosw_set(0);
1658 } else if (strlencmp(cmd
, "video_switch") == 0) {
1659 res
= video_outputsw_cycle();
1662 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1663 res
= video_expand_toggle();
1670 if (enable
|| disable
) {
1671 status
= video_outputsw_get();
1674 res
= video_outputsw_set((status
& ~disable
) | enable
);
1682 static struct ibm_struct video_driver_data
= {
1685 .write
= video_write
,
1689 /*************************************************************************
1690 * Light (thinklight) subdriver
1693 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1694 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1696 static int __init
light_init(struct ibm_init_struct
*iibm
)
1698 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
1700 IBM_ACPIHANDLE_INIT(ledb
);
1701 IBM_ACPIHANDLE_INIT(lght
);
1702 IBM_ACPIHANDLE_INIT(cmos
);
1704 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1705 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1707 if (tp_features
.light
)
1708 /* light status not supported on
1709 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1710 tp_features
.light_status
=
1711 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
1713 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
1714 str_supported(tp_features
.light
));
1716 return (tp_features
.light
)? 0 : 1;
1719 static int light_read(char *p
)
1724 if (!tp_features
.light
) {
1725 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1726 } else if (!tp_features
.light_status
) {
1727 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1728 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1730 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1732 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1733 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1739 static int light_write(char *buf
)
1741 int cmos_cmd
, lght_cmd
;
1745 if (!tp_features
.light
)
1748 while ((cmd
= next_cmd(&buf
))) {
1749 if (strlencmp(cmd
, "on") == 0) {
1752 } else if (strlencmp(cmd
, "off") == 0) {
1758 success
= cmos_handle
?
1759 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1760 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1768 static struct ibm_struct light_driver_data
= {
1771 .write
= light_write
,
1774 /*************************************************************************
1778 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1780 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
1781 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1782 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1783 "\\_SB.PCI.ISA.SLCE", /* 570 */
1784 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1786 /* don't list other alternatives as we install a notify handler on the 570 */
1787 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
1789 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
1791 .notify
= dock_notify
,
1792 .handle
= &dock_handle
,
1793 .type
= ACPI_SYSTEM_NOTIFY
,
1797 .notify
= dock_notify
,
1798 .handle
= &pci_handle
,
1799 .type
= ACPI_SYSTEM_NOTIFY
,
1803 static struct ibm_struct dock_driver_data
[2] = {
1807 .write
= dock_write
,
1808 .acpi
= &ibm_dock_acpidriver
[0],
1812 .acpi
= &ibm_dock_acpidriver
[1],
1816 #define dock_docked() (_sta(dock_handle) & 1)
1818 static int __init
dock_init(struct ibm_init_struct
*iibm
)
1820 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
1822 IBM_ACPIHANDLE_INIT(dock
);
1824 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
1825 str_supported(dock_handle
!= NULL
));
1827 return (dock_handle
)? 0 : 1;
1830 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
1834 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
1836 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
1837 dock_driver_data
[0].flags
.acpi_notify_installed
) {
1838 IBM_ACPIHANDLE_INIT(pci
);
1839 dock2_needed
= (pci_handle
!= NULL
);
1840 vdbg_printk(TPACPI_DBG_INIT
,
1841 "dock PCI handler for the TP 570 is %s\n",
1842 str_supported(dock2_needed
));
1844 vdbg_printk(TPACPI_DBG_INIT
,
1845 "dock subdriver part 2 not required\n");
1849 return (dock2_needed
)? 0 : 1;
1852 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1854 int docked
= dock_docked();
1855 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, IBM_PCI_HID
);
1857 if (event
== 1 && !pci
) /* 570 */
1858 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1859 else if (event
== 1 && pci
) /* 570 */
1860 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1861 else if (event
== 3 && docked
)
1862 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1863 else if (event
== 3 && !docked
)
1864 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
1865 else if (event
== 0 && docked
)
1866 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1868 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1869 event
, _sta(dock_handle
));
1870 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
1874 static int dock_read(char *p
)
1877 int docked
= dock_docked();
1880 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1882 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1884 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1885 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1891 static int dock_write(char *buf
)
1898 while ((cmd
= next_cmd(&buf
))) {
1899 if (strlencmp(cmd
, "undock") == 0) {
1900 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1901 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1903 } else if (strlencmp(cmd
, "dock") == 0) {
1904 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1913 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1915 /*************************************************************************
1919 #ifdef CONFIG_THINKPAD_ACPI_BAY
1920 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1921 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1922 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1923 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1924 ); /* A21e, R30, R31 */
1925 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
1926 "_EJ0", /* all others */
1927 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1928 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1929 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1931 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
1935 static int __init
bay_init(struct ibm_init_struct
*iibm
)
1937 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
1939 IBM_ACPIHANDLE_INIT(bay
);
1941 IBM_ACPIHANDLE_INIT(bay_ej
);
1942 IBM_ACPIHANDLE_INIT(bay2
);
1944 IBM_ACPIHANDLE_INIT(bay2_ej
);
1946 tp_features
.bay_status
= bay_handle
&&
1947 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1948 tp_features
.bay_status2
= bay2_handle
&&
1949 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1951 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
1952 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1953 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
1954 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1956 vdbg_printk(TPACPI_DBG_INIT
,
1957 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1958 str_supported(tp_features
.bay_status
),
1959 str_supported(tp_features
.bay_eject
),
1960 str_supported(tp_features
.bay_status2
),
1961 str_supported(tp_features
.bay_eject2
));
1963 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
1964 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
1967 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1969 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1972 #define bay_occupied(b) (_sta(b##_handle) & 1)
1974 static int bay_read(char *p
)
1977 int occupied
= bay_occupied(bay
);
1978 int occupied2
= bay_occupied(bay2
);
1981 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1982 tp_features
.bay_status
?
1983 (occupied
? "occupied" : "unoccupied") :
1985 if (tp_features
.bay_status2
)
1986 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1987 "occupied" : "unoccupied");
1989 eject
= tp_features
.bay_eject
&& occupied
;
1990 eject2
= tp_features
.bay_eject2
&& occupied2
;
1992 if (eject
&& eject2
)
1993 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1995 len
+= sprintf(p
+ len
, "commands:\teject\n");
1997 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2002 static int bay_write(char *buf
)
2006 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2009 while ((cmd
= next_cmd(&buf
))) {
2010 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2011 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2013 } else if (tp_features
.bay_eject2
&&
2014 strlencmp(cmd
, "eject2") == 0) {
2015 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2024 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2025 .notify
= bay_notify
,
2026 .handle
= &bay_handle
,
2027 .type
= ACPI_SYSTEM_NOTIFY
,
2030 static struct ibm_struct bay_driver_data
= {
2034 .acpi
= &ibm_bay_acpidriver
,
2037 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2039 /*************************************************************************
2043 /* sysfs cmos_command -------------------------------------------------- */
2044 static ssize_t
cmos_command_store(struct device
*dev
,
2045 struct device_attribute
*attr
,
2046 const char *buf
, size_t count
)
2048 unsigned long cmos_cmd
;
2051 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2054 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2055 return (res
)? res
: count
;
2058 static struct device_attribute dev_attr_cmos_command
=
2059 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2061 /* --------------------------------------------------------------------- */
2063 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2067 vdbg_printk(TPACPI_DBG_INIT
,
2068 "initializing cmos commands subdriver\n");
2070 IBM_ACPIHANDLE_INIT(cmos
);
2072 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2073 str_supported(cmos_handle
!= NULL
));
2075 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2079 return (cmos_handle
)? 0 : 1;
2082 static void cmos_exit(void)
2084 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2087 static int cmos_read(char *p
)
2091 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2092 R30, R31, T20-22, X20-21 */
2094 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2096 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2097 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2103 static int cmos_write(char *buf
)
2108 while ((cmd
= next_cmd(&buf
))) {
2109 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2110 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2115 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2123 static struct ibm_struct cmos_driver_data
= {
2126 .write
= cmos_write
,
2130 /*************************************************************************
2134 static enum led_access_mode led_supported
;
2136 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2137 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2138 "LED", /* all others */
2141 static int __init
led_init(struct ibm_init_struct
*iibm
)
2143 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2145 IBM_ACPIHANDLE_INIT(led
);
2148 /* led not supported on R30, R31 */
2149 led_supported
= TPACPI_LED_NONE
;
2150 else if (strlencmp(led_path
, "SLED") == 0)
2152 led_supported
= TPACPI_LED_570
;
2153 else if (strlencmp(led_path
, "SYSL") == 0)
2154 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2155 led_supported
= TPACPI_LED_OLD
;
2158 led_supported
= TPACPI_LED_NEW
;
2160 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2161 str_supported(led_supported
), led_supported
);
2163 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2166 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2168 static int led_read(char *p
)
2172 if (!led_supported
) {
2173 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2176 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2178 if (led_supported
== TPACPI_LED_570
) {
2181 for (i
= 0; i
< 8; i
++) {
2182 if (!acpi_evalf(ec_handle
,
2183 &status
, "GLED", "dd", 1 << i
))
2185 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2186 i
, led_status(status
));
2190 len
+= sprintf(p
+ len
, "commands:\t"
2191 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2196 /* off, on, blink */
2197 static const int led_sled_arg1
[] = { 0, 1, 3 };
2198 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2199 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2200 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2202 static int led_write(char *buf
)
2210 while ((cmd
= next_cmd(&buf
))) {
2211 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2214 if (strstr(cmd
, "off")) {
2216 } else if (strstr(cmd
, "on")) {
2218 } else if (strstr(cmd
, "blink")) {
2223 if (led_supported
== TPACPI_LED_570
) {
2226 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2227 led
, led_sled_arg1
[ind
]))
2229 } else if (led_supported
== TPACPI_LED_OLD
) {
2230 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2232 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2235 ec_write(TPACPI_LED_EC_HLBL
,
2236 led
* led_exp_hlbl
[ind
]);
2239 ec_write(TPACPI_LED_EC_HLCL
,
2240 led
* led_exp_hlcl
[ind
]);
2245 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2246 led
, led_led_arg1
[ind
]))
2254 static struct ibm_struct led_driver_data
= {
2260 /*************************************************************************
2264 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2266 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2268 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2270 IBM_ACPIHANDLE_INIT(beep
);
2272 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2273 str_supported(beep_handle
!= NULL
));
2275 return (beep_handle
)? 0 : 1;
2278 static int beep_read(char *p
)
2283 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2285 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2286 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2292 static int beep_write(char *buf
)
2300 while ((cmd
= next_cmd(&buf
))) {
2301 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2302 beep_cmd
>= 0 && beep_cmd
<= 17) {
2306 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2313 static struct ibm_struct beep_driver_data
= {
2316 .write
= beep_write
,
2319 /*************************************************************************
2323 static enum thermal_access_mode thermal_read_mode
;
2325 /* sysfs temp##_input -------------------------------------------------- */
2327 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2328 struct device_attribute
*attr
,
2331 struct sensor_device_attribute
*sensor_attr
=
2332 to_sensor_dev_attr(attr
);
2333 int idx
= sensor_attr
->index
;
2337 res
= thermal_get_sensor(idx
, &value
);
2340 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2343 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2346 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2347 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2349 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2350 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2351 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2352 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2353 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2354 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2355 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2356 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2357 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2358 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2359 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2360 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2361 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2362 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2363 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2364 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2365 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2368 #define THERMAL_ATTRS(X) \
2369 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2371 static struct attribute
*thermal_temp_input_attr
[] = {
2391 static const struct attribute_group thermal_temp_input16_group
= {
2392 .attrs
= thermal_temp_input_attr
2395 static const struct attribute_group thermal_temp_input8_group
= {
2396 .attrs
= &thermal_temp_input_attr
[8]
2399 #undef THERMAL_SENSOR_ATTR_TEMP
2400 #undef THERMAL_ATTRS
2402 /* --------------------------------------------------------------------- */
2404 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2411 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2413 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2415 if (ibm_thinkpad_ec_found
&& experimental
) {
2417 * Direct EC access mode: sensors at registers
2418 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2419 * non-implemented, thermal sensors return 0x80 when
2424 for (i
= 0; i
< 8; i
++) {
2425 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2431 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2439 /* This is sheer paranoia, but we handle it anyway */
2442 "ThinkPad ACPI EC access misbehaving, "
2443 "falling back to ACPI TMPx access mode\n");
2444 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2447 "ThinkPad ACPI EC access misbehaving, "
2448 "disabling thermal sensors access\n");
2449 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2454 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2456 } else if (acpi_tmp7
) {
2457 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2458 /* 600e/x, 770e, 770x */
2459 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2461 /* Standard ACPI TMPx access, max 8 sensors */
2462 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2465 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2466 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2469 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2470 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2473 switch(thermal_read_mode
) {
2474 case TPACPI_THERMAL_TPEC_16
:
2475 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2476 &thermal_temp_input16_group
);
2480 case TPACPI_THERMAL_TPEC_8
:
2481 case TPACPI_THERMAL_ACPI_TMP07
:
2482 case TPACPI_THERMAL_ACPI_UPDT
:
2483 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2484 &thermal_temp_input8_group
);
2488 case TPACPI_THERMAL_NONE
:
2496 static void thermal_exit(void)
2498 switch(thermal_read_mode
) {
2499 case TPACPI_THERMAL_TPEC_16
:
2500 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2501 &thermal_temp_input16_group
);
2503 case TPACPI_THERMAL_TPEC_8
:
2504 case TPACPI_THERMAL_ACPI_TMP07
:
2505 case TPACPI_THERMAL_ACPI_UPDT
:
2506 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2507 &thermal_temp_input16_group
);
2509 case TPACPI_THERMAL_NONE
:
2515 /* idx is zero-based */
2516 static int thermal_get_sensor(int idx
, s32
*value
)
2522 t
= TP_EC_THERMAL_TMP0
;
2524 switch (thermal_read_mode
) {
2525 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2526 case TPACPI_THERMAL_TPEC_16
:
2527 if (idx
>= 8 && idx
<= 15) {
2528 t
= TP_EC_THERMAL_TMP8
;
2533 case TPACPI_THERMAL_TPEC_8
:
2535 if (!acpi_ec_read(t
+ idx
, &tmp
))
2537 *value
= tmp
* 1000;
2542 case TPACPI_THERMAL_ACPI_UPDT
:
2544 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2545 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2547 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2549 *value
= (t
- 2732) * 100;
2554 case TPACPI_THERMAL_ACPI_TMP07
:
2556 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2557 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2564 case TPACPI_THERMAL_NONE
:
2572 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2583 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2586 for(i
= 0 ; i
< n
; i
++) {
2587 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
2595 static int thermal_read(char *p
)
2599 struct ibm_thermal_sensors_struct t
;
2601 n
= thermal_get_sensors(&t
);
2602 if (unlikely(n
< 0))
2605 len
+= sprintf(p
+ len
, "temperatures:\t");
2608 for (i
= 0; i
< (n
- 1); i
++)
2609 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
2610 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
2612 len
+= sprintf(p
+ len
, "not supported\n");
2617 static struct ibm_struct thermal_driver_data
= {
2619 .read
= thermal_read
,
2620 .exit
= thermal_exit
,
2623 /*************************************************************************
2627 static u8 ecdump_regs
[256];
2629 static int ecdump_read(char *p
)
2635 len
+= sprintf(p
+ len
, "EC "
2636 " +00 +01 +02 +03 +04 +05 +06 +07"
2637 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2638 for (i
= 0; i
< 256; i
+= 16) {
2639 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
2640 for (j
= 0; j
< 16; j
++) {
2641 if (!acpi_ec_read(i
+ j
, &v
))
2643 if (v
!= ecdump_regs
[i
+ j
])
2644 len
+= sprintf(p
+ len
, " *%02x", v
);
2646 len
+= sprintf(p
+ len
, " %02x", v
);
2647 ecdump_regs
[i
+ j
] = v
;
2649 len
+= sprintf(p
+ len
, "\n");
2654 /* These are way too dangerous to advertise openly... */
2656 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
2657 " (<offset> is 00-ff, <value> is 00-ff)\n");
2658 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
2659 " (<offset> is 00-ff, <value> is 0-255)\n");
2664 static int ecdump_write(char *buf
)
2669 while ((cmd
= next_cmd(&buf
))) {
2670 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
2672 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
2676 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
2677 if (!acpi_ec_write(i
, v
))
2686 static struct ibm_struct ecdump_driver_data
= {
2688 .read
= ecdump_read
,
2689 .write
= ecdump_write
,
2690 .flags
.experimental
= 1,
2693 /*************************************************************************
2694 * Backlight/brightness subdriver
2697 static struct backlight_device
*ibm_backlight_device
= NULL
;
2699 static struct backlight_ops ibm_backlight_data
= {
2700 .get_brightness
= brightness_get
,
2701 .update_status
= brightness_update_status
,
2704 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
2708 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
2710 b
= brightness_get(NULL
);
2714 ibm_backlight_device
= backlight_device_register(
2715 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
2716 &ibm_backlight_data
);
2717 if (IS_ERR(ibm_backlight_device
)) {
2718 printk(IBM_ERR
"Could not register backlight device\n");
2719 return PTR_ERR(ibm_backlight_device
);
2721 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
2723 ibm_backlight_device
->props
.max_brightness
= 7;
2724 ibm_backlight_device
->props
.brightness
= b
;
2725 backlight_update_status(ibm_backlight_device
);
2730 static void brightness_exit(void)
2732 if (ibm_backlight_device
) {
2733 vdbg_printk(TPACPI_DBG_EXIT
,
2734 "calling backlight_device_unregister()\n");
2735 backlight_device_unregister(ibm_backlight_device
);
2736 ibm_backlight_device
= NULL
;
2740 static int brightness_update_status(struct backlight_device
*bd
)
2742 return brightness_set(
2743 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
2744 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
2745 bd
->props
.brightness
: 0);
2748 static int brightness_get(struct backlight_device
*bd
)
2751 if (!acpi_ec_read(brightness_offset
, &level
))
2759 static int brightness_set(int value
)
2761 int cmos_cmd
, inc
, i
;
2762 int current_value
= brightness_get(NULL
);
2766 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
2767 inc
= value
> current_value
? 1 : -1;
2768 for (i
= current_value
; i
!= value
; i
+= inc
) {
2769 if (issue_thinkpad_cmos_command(cmos_cmd
))
2771 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
2778 static int brightness_read(char *p
)
2783 if ((level
= brightness_get(NULL
)) < 0) {
2784 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2786 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
2787 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
2788 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2789 " (<level> is 0-7)\n");
2795 static int brightness_write(char *buf
)
2801 while ((cmd
= next_cmd(&buf
))) {
2802 if ((level
= brightness_get(NULL
)) < 0)
2806 if (strlencmp(cmd
, "up") == 0) {
2807 new_level
= level
== 7 ? 7 : level
+ 1;
2808 } else if (strlencmp(cmd
, "down") == 0) {
2809 new_level
= level
== 0 ? 0 : level
- 1;
2810 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2811 new_level
>= 0 && new_level
<= 7) {
2816 brightness_set(new_level
);
2822 static struct ibm_struct brightness_driver_data
= {
2823 .name
= "brightness",
2824 .read
= brightness_read
,
2825 .write
= brightness_write
,
2826 .exit
= brightness_exit
,
2829 /*************************************************************************
2833 static int volume_read(char *p
)
2838 if (!acpi_ec_read(volume_offset
, &level
)) {
2839 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2841 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
2842 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
2843 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
2844 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2845 " (<level> is 0-15)\n");
2851 static int volume_write(char *buf
)
2853 int cmos_cmd
, inc
, i
;
2855 int new_level
, new_mute
;
2858 while ((cmd
= next_cmd(&buf
))) {
2859 if (!acpi_ec_read(volume_offset
, &level
))
2861 new_mute
= mute
= level
& 0x40;
2862 new_level
= level
= level
& 0xf;
2864 if (strlencmp(cmd
, "up") == 0) {
2868 new_level
= level
== 15 ? 15 : level
+ 1;
2869 } else if (strlencmp(cmd
, "down") == 0) {
2873 new_level
= level
== 0 ? 0 : level
- 1;
2874 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2875 new_level
>= 0 && new_level
<= 15) {
2877 } else if (strlencmp(cmd
, "mute") == 0) {
2882 if (new_level
!= level
) { /* mute doesn't change */
2883 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
2884 inc
= new_level
> level
? 1 : -1;
2886 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
2887 !acpi_ec_write(volume_offset
, level
)))
2890 for (i
= level
; i
!= new_level
; i
+= inc
)
2891 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2892 !acpi_ec_write(volume_offset
, i
+ inc
))
2895 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
2896 !acpi_ec_write(volume_offset
,
2901 if (new_mute
!= mute
) { /* level doesn't change */
2902 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
2904 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2905 !acpi_ec_write(volume_offset
, level
+ new_mute
))
2913 static struct ibm_struct volume_driver_data
= {
2915 .read
= volume_read
,
2916 .write
= volume_write
,
2919 /*************************************************************************
2926 * TPACPI_FAN_RD_ACPI_GFAN:
2927 * ACPI GFAN method: returns fan level
2929 * see TPACPI_FAN_WR_ACPI_SFAN
2930 * EC 0x2f (HFSP) not available if GFAN exists
2932 * TPACPI_FAN_WR_ACPI_SFAN:
2933 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2935 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2938 * TPACPI_FAN_WR_TPEC:
2939 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2940 * Supported on almost all ThinkPads
2942 * Fan speed changes of any sort (including those caused by the
2943 * disengaged mode) are usually done slowly by the firmware as the
2944 * maximum ammount of fan duty cycle change per second seems to be
2947 * Reading is not available if GFAN exists.
2948 * Writing is not available if SFAN exists.
2951 * 7 automatic mode engaged;
2952 * (default operation mode of the ThinkPad)
2953 * fan level is ignored in this mode.
2954 * 6 full speed mode (takes precedence over bit 7);
2955 * not available on all thinkpads. May disable
2956 * the tachometer while the fan controller ramps up
2957 * the speed (which can take up to a few *minutes*).
2958 * Speeds up fan to 100% duty-cycle, which is far above
2959 * the standard RPM levels. It is not impossible that
2960 * it could cause hardware damage.
2961 * 5-3 unused in some models. Extra bits for fan level
2962 * in others, but still useless as all values above
2963 * 7 map to the same speed as level 7 in these models.
2964 * 2-0 fan level (0..7 usually)
2966 * 0x07 = max (set when temperatures critical)
2967 * Some ThinkPads may have other levels, see
2968 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2970 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2971 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2972 * does so, its initial value is meaningless (0x07).
2974 * For firmware bugs, refer to:
2975 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2979 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2980 * Main fan tachometer reading (in RPM)
2982 * This register is present on all ThinkPads with a new-style EC, and
2983 * it is known not to be present on the A21m/e, and T22, as there is
2984 * something else in offset 0x84 according to the ACPI DSDT. Other
2985 * ThinkPads from this same time period (and earlier) probably lack the
2986 * tachometer as well.
2988 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2989 * was never fixed by IBM to report the EC firmware version string
2990 * probably support the tachometer (like the early X models), so
2991 * detecting it is quite hard. We need more data to know for sure.
2993 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2996 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2999 * For firmware bugs, refer to:
3000 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3002 * TPACPI_FAN_WR_ACPI_FANS:
3003 * ThinkPad X31, X40, X41. Not available in the X60.
3005 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3006 * high speed. ACPI DSDT seems to map these three speeds to levels
3007 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3008 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3010 * The speeds are stored on handles
3011 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3013 * There are three default speed sets, acessible as handles:
3014 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3016 * ACPI DSDT switches which set is in use depending on various
3019 * TPACPI_FAN_WR_TPEC is also available and should be used to
3020 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3021 * but the ACPI tables just mention level 7.
3024 static enum fan_status_access_mode fan_status_access_mode
;
3025 static enum fan_control_access_mode fan_control_access_mode
;
3026 static enum fan_control_commands fan_control_commands
;
3028 static u8 fan_control_initial_status
;
3029 static u8 fan_control_desired_level
;
3031 static void fan_watchdog_fire(struct work_struct
*ignored
);
3032 static int fan_watchdog_maxinterval
;
3033 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3035 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3036 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3037 "\\FSPD", /* 600e/x, 770e, 770x */
3039 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3040 "JFNS", /* 770x-JL */
3044 * SYSFS fan layout: hwmon compatible (device)
3047 * 0: "disengaged" mode
3049 * 2: native EC "auto" mode (recommended, hardware default)
3051 * pwm*: set speed in manual mode, ignored otherwise.
3052 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3055 * fan*_input: tachometer reading, RPM
3058 * SYSFS fan layout: extensions
3060 * fan_watchdog (driver):
3061 * fan watchdog interval in seconds, 0 disables (default), max 120
3064 /* sysfs fan pwm1_enable ----------------------------------------------- */
3065 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3066 struct device_attribute
*attr
,
3072 res
= fan_get_status_safe(&status
);
3076 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3077 if (status
!= fan_control_initial_status
) {
3078 tp_features
.fan_ctrl_status_undef
= 0;
3080 /* Return most likely status. In fact, it
3081 * might be the only possible status */
3082 status
= TP_EC_FAN_AUTO
;
3086 if (status
& TP_EC_FAN_FULLSPEED
) {
3088 } else if (status
& TP_EC_FAN_AUTO
) {
3093 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3096 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3097 struct device_attribute
*attr
,
3098 const char *buf
, size_t count
)
3103 if (parse_strtoul(buf
, 2, &t
))
3108 level
= TP_EC_FAN_FULLSPEED
;
3111 level
= TPACPI_FAN_LAST_LEVEL
;
3114 level
= TP_EC_FAN_AUTO
;
3117 /* reserved for software-controlled auto mode */
3123 res
= fan_set_level_safe(level
);
3129 fan_watchdog_reset();
3134 static struct device_attribute dev_attr_fan_pwm1_enable
=
3135 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3136 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3138 /* sysfs fan pwm1 ------------------------------------------------------ */
3139 static ssize_t
fan_pwm1_show(struct device
*dev
,
3140 struct device_attribute
*attr
,
3146 res
= fan_get_status_safe(&status
);
3150 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3151 if (status
!= fan_control_initial_status
) {
3152 tp_features
.fan_ctrl_status_undef
= 0;
3154 status
= TP_EC_FAN_AUTO
;
3159 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3160 status
= fan_control_desired_level
;
3165 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3168 static ssize_t
fan_pwm1_store(struct device
*dev
,
3169 struct device_attribute
*attr
,
3170 const char *buf
, size_t count
)
3174 u8 status
, newlevel
;
3176 if (parse_strtoul(buf
, 255, &s
))
3179 /* scale down from 0-255 to 0-7 */
3180 newlevel
= (s
>> 5) & 0x07;
3182 rc
= mutex_lock_interruptible(&fan_mutex
);
3186 rc
= fan_get_status(&status
);
3187 if (!rc
&& (status
&
3188 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3189 rc
= fan_set_level(newlevel
);
3193 fan_update_desired_level(newlevel
);
3194 fan_watchdog_reset();
3198 mutex_unlock(&fan_mutex
);
3199 return (rc
)? rc
: count
;
3202 static struct device_attribute dev_attr_fan_pwm1
=
3203 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3204 fan_pwm1_show
, fan_pwm1_store
);
3206 /* sysfs fan fan1_input ------------------------------------------------ */
3207 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3208 struct device_attribute
*attr
,
3214 res
= fan_get_speed(&speed
);
3218 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3221 static struct device_attribute dev_attr_fan_fan1_input
=
3222 __ATTR(fan1_input
, S_IRUGO
,
3223 fan_fan1_input_show
, NULL
);
3225 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
3226 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3229 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3232 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3233 const char *buf
, size_t count
)
3237 if (parse_strtoul(buf
, 120, &t
))
3240 if (!fan_control_allowed
)
3243 fan_watchdog_maxinterval
= t
;
3244 fan_watchdog_reset();
3249 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3250 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3252 /* --------------------------------------------------------------------- */
3253 static struct attribute
*fan_attributes
[] = {
3254 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3255 &dev_attr_fan_fan1_input
.attr
,
3259 static const struct attribute_group fan_attr_group
= {
3260 .attrs
= fan_attributes
,
3263 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3267 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3269 mutex_init(&fan_mutex
);
3270 fan_status_access_mode
= TPACPI_FAN_NONE
;
3271 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3272 fan_control_commands
= 0;
3273 fan_watchdog_maxinterval
= 0;
3274 tp_features
.fan_ctrl_status_undef
= 0;
3275 fan_control_desired_level
= 7;
3277 IBM_ACPIHANDLE_INIT(fans
);
3278 IBM_ACPIHANDLE_INIT(gfan
);
3279 IBM_ACPIHANDLE_INIT(sfan
);
3282 /* 570, 600e/x, 770e, 770x */
3283 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3285 /* all other ThinkPads: note that even old-style
3286 * ThinkPad ECs supports the fan control register */
3287 if (likely(acpi_ec_read(fan_status_offset
,
3288 &fan_control_initial_status
))) {
3289 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3291 /* In some ThinkPads, neither the EC nor the ACPI
3292 * DSDT initialize the fan status, and it ends up
3293 * being set to 0x07 when it *could* be either
3296 * Enable for TP-1Y (T43), TP-78 (R51e),
3297 * TP-76 (R52), TP-70 (T43, R52), which are known
3299 if (fan_control_initial_status
== 0x07 &&
3300 ibm_thinkpad_ec_found
&&
3301 ((ibm_thinkpad_ec_found
[0] == '1' &&
3302 ibm_thinkpad_ec_found
[1] == 'Y') ||
3303 (ibm_thinkpad_ec_found
[0] == '7' &&
3304 (ibm_thinkpad_ec_found
[1] == '6' ||
3305 ibm_thinkpad_ec_found
[1] == '8' ||
3306 ibm_thinkpad_ec_found
[1] == '0'))
3309 "fan_init: initial fan status is "
3310 "unknown, assuming it is in auto "
3312 tp_features
.fan_ctrl_status_undef
= 1;
3316 "ThinkPad ACPI EC access misbehaving, "
3317 "fan status and control unavailable\n");
3324 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3325 fan_control_commands
|=
3326 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3329 /* gfan without sfan means no fan control */
3330 /* all other models implement TP EC 0x2f control */
3334 fan_control_access_mode
=
3335 TPACPI_FAN_WR_ACPI_FANS
;
3336 fan_control_commands
|=
3337 TPACPI_FAN_CMD_SPEED
|
3338 TPACPI_FAN_CMD_LEVEL
|
3339 TPACPI_FAN_CMD_ENABLE
;
3341 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3342 fan_control_commands
|=
3343 TPACPI_FAN_CMD_LEVEL
|
3344 TPACPI_FAN_CMD_ENABLE
;
3349 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3350 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3351 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3352 fan_status_access_mode
, fan_control_access_mode
);
3354 /* fan control master switch */
3355 if (!fan_control_allowed
) {
3356 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3357 fan_control_commands
= 0;
3358 dbg_printk(TPACPI_DBG_INIT
,
3359 "fan control features disabled by parameter\n");
3362 /* update fan_control_desired_level */
3363 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3364 fan_get_status_safe(NULL
);
3366 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3367 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3368 rc
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3371 rc
= driver_create_file(&tpacpi_pdriver
.driver
,
3372 &driver_attr_fan_watchdog
);
3381 * Call with fan_mutex held
3383 static void fan_update_desired_level(u8 status
)
3386 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3388 fan_control_desired_level
= 7;
3390 fan_control_desired_level
= status
;
3394 static int fan_get_status(u8
*status
)
3399 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3401 switch (fan_status_access_mode
) {
3402 case TPACPI_FAN_RD_ACPI_GFAN
:
3403 /* 570, 600e/x, 770e, 770x */
3405 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
3413 case TPACPI_FAN_RD_TPEC
:
3414 /* all except 570, 600e/x, 770e, 770x */
3415 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
3430 static int fan_get_status_safe(u8
*status
)
3435 rc
= mutex_lock_interruptible(&fan_mutex
);
3438 rc
= fan_get_status(&s
);
3440 fan_update_desired_level(s
);
3441 mutex_unlock(&fan_mutex
);
3449 static void fan_exit(void)
3451 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
3453 /* FIXME: can we really do this unconditionally? */
3454 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
, &fan_attr_group
);
3455 driver_remove_file(&tpacpi_pdriver
.driver
, &driver_attr_fan_watchdog
);
3457 cancel_delayed_work(&fan_watchdog_task
);
3458 flush_scheduled_work();
3461 static int fan_get_speed(unsigned int *speed
)
3465 switch (fan_status_access_mode
) {
3466 case TPACPI_FAN_RD_TPEC
:
3467 /* all except 570, 600e/x, 770e, 770x */
3468 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
3469 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
3473 *speed
= (hi
<< 8) | lo
;
3484 static void fan_watchdog_fire(struct work_struct
*ignored
)
3488 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
3489 rc
= fan_set_enable();
3491 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
3492 "will try again later...\n", -rc
);
3493 /* reschedule for later */
3494 fan_watchdog_reset();
3498 static void fan_watchdog_reset(void)
3500 static int fan_watchdog_active
= 0;
3502 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
3505 if (fan_watchdog_active
)
3506 cancel_delayed_work(&fan_watchdog_task
);
3508 if (fan_watchdog_maxinterval
> 0) {
3509 fan_watchdog_active
= 1;
3510 if (!schedule_delayed_work(&fan_watchdog_task
,
3511 msecs_to_jiffies(fan_watchdog_maxinterval
3513 printk(IBM_ERR
"failed to schedule the fan watchdog, "
3514 "watchdog will not trigger\n");
3517 fan_watchdog_active
= 0;
3520 static int fan_set_level(int level
)
3522 if (!fan_control_allowed
)
3525 switch (fan_control_access_mode
) {
3526 case TPACPI_FAN_WR_ACPI_SFAN
:
3527 if (level
>= 0 && level
<= 7) {
3528 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
3534 case TPACPI_FAN_WR_ACPI_FANS
:
3535 case TPACPI_FAN_WR_TPEC
:
3536 if ((level
!= TP_EC_FAN_AUTO
) &&
3537 (level
!= TP_EC_FAN_FULLSPEED
) &&
3538 ((level
< 0) || (level
> 7)))
3541 /* safety net should the EC not support AUTO
3542 * or FULLSPEED mode bits and just ignore them */
3543 if (level
& TP_EC_FAN_FULLSPEED
)
3544 level
|= 7; /* safety min speed 7 */
3545 else if (level
& TP_EC_FAN_FULLSPEED
)
3546 level
|= 4; /* safety min speed 4 */
3548 if (!acpi_ec_write(fan_status_offset
, level
))
3551 tp_features
.fan_ctrl_status_undef
= 0;
3560 static int fan_set_level_safe(int level
)
3564 if (!fan_control_allowed
)
3567 rc
= mutex_lock_interruptible(&fan_mutex
);
3571 if (level
== TPACPI_FAN_LAST_LEVEL
)
3572 level
= fan_control_desired_level
;
3574 rc
= fan_set_level(level
);
3576 fan_update_desired_level(level
);
3578 mutex_unlock(&fan_mutex
);
3582 static int fan_set_enable(void)
3587 if (!fan_control_allowed
)
3590 rc
= mutex_lock_interruptible(&fan_mutex
);
3594 switch (fan_control_access_mode
) {
3595 case TPACPI_FAN_WR_ACPI_FANS
:
3596 case TPACPI_FAN_WR_TPEC
:
3597 rc
= fan_get_status(&s
);
3601 /* Don't go out of emergency fan mode */
3604 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
3607 if (!acpi_ec_write(fan_status_offset
, s
))
3610 tp_features
.fan_ctrl_status_undef
= 0;
3615 case TPACPI_FAN_WR_ACPI_SFAN
:
3616 rc
= fan_get_status(&s
);
3622 /* Set fan to at least level 4 */
3625 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
3635 mutex_unlock(&fan_mutex
);
3639 static int fan_set_disable(void)
3643 if (!fan_control_allowed
)
3646 rc
= mutex_lock_interruptible(&fan_mutex
);
3651 switch (fan_control_access_mode
) {
3652 case TPACPI_FAN_WR_ACPI_FANS
:
3653 case TPACPI_FAN_WR_TPEC
:
3654 if (!acpi_ec_write(fan_status_offset
, 0x00))
3657 fan_control_desired_level
= 0;
3658 tp_features
.fan_ctrl_status_undef
= 0;
3662 case TPACPI_FAN_WR_ACPI_SFAN
:
3663 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
3666 fan_control_desired_level
= 0;
3674 mutex_unlock(&fan_mutex
);
3678 static int fan_set_speed(int speed
)
3682 if (!fan_control_allowed
)
3685 rc
= mutex_lock_interruptible(&fan_mutex
);
3690 switch (fan_control_access_mode
) {
3691 case TPACPI_FAN_WR_ACPI_FANS
:
3692 if (speed
>= 0 && speed
<= 65535) {
3693 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
3694 speed
, speed
, speed
))
3704 mutex_unlock(&fan_mutex
);
3708 static int fan_read(char *p
)
3713 unsigned int speed
= 0;
3715 switch (fan_status_access_mode
) {
3716 case TPACPI_FAN_RD_ACPI_GFAN
:
3717 /* 570, 600e/x, 770e, 770x */
3718 if ((rc
= fan_get_status_safe(&status
)) < 0)
3721 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
3723 (status
!= 0) ? "enabled" : "disabled", status
);
3726 case TPACPI_FAN_RD_TPEC
:
3727 /* all except 570, 600e/x, 770e, 770x */
3728 if ((rc
= fan_get_status_safe(&status
)) < 0)
3731 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3732 if (status
!= fan_control_initial_status
)
3733 tp_features
.fan_ctrl_status_undef
= 0;
3735 /* Return most likely status. In fact, it
3736 * might be the only possible status */
3737 status
= TP_EC_FAN_AUTO
;
3740 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3741 (status
!= 0) ? "enabled" : "disabled");
3743 if ((rc
= fan_get_speed(&speed
)) < 0)
3746 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
3748 if (status
& TP_EC_FAN_FULLSPEED
)
3749 /* Disengaged mode takes precedence */
3750 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
3751 else if (status
& TP_EC_FAN_AUTO
)
3752 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
3754 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
3757 case TPACPI_FAN_NONE
:
3759 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3762 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
3763 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
3765 switch (fan_control_access_mode
) {
3766 case TPACPI_FAN_WR_ACPI_SFAN
:
3767 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
3771 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
3772 "auto, disengaged, full-speed)\n");
3777 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
3778 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
3779 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
3780 "1-120 (seconds))\n");
3782 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
3783 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
3784 " (<speed> is 0-65535)\n");
3789 static int fan_write_cmd_level(const char *cmd
, int *rc
)
3793 if (strlencmp(cmd
, "level auto") == 0)
3794 level
= TP_EC_FAN_AUTO
;
3795 else if ((strlencmp(cmd
, "level disengaged") == 0) |
3796 (strlencmp(cmd
, "level full-speed") == 0))
3797 level
= TP_EC_FAN_FULLSPEED
;
3798 else if (sscanf(cmd
, "level %d", &level
) != 1)
3801 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
3802 printk(IBM_ERR
"level command accepted for unsupported "
3803 "access mode %d", fan_control_access_mode
);
3808 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
3810 if (strlencmp(cmd
, "enable") != 0)
3813 if ((*rc
= fan_set_enable()) == -ENXIO
)
3814 printk(IBM_ERR
"enable command accepted for unsupported "
3815 "access mode %d", fan_control_access_mode
);
3820 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
3822 if (strlencmp(cmd
, "disable") != 0)
3825 if ((*rc
= fan_set_disable()) == -ENXIO
)
3826 printk(IBM_ERR
"disable command accepted for unsupported "
3827 "access mode %d", fan_control_access_mode
);
3832 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
3837 * Support speed <low> <medium> <high> ? */
3839 if (sscanf(cmd
, "speed %d", &speed
) != 1)
3842 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
3843 printk(IBM_ERR
"speed command accepted for unsupported "
3844 "access mode %d", fan_control_access_mode
);
3849 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
3853 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
3856 if (interval
< 0 || interval
> 120)
3859 fan_watchdog_maxinterval
= interval
;
3864 static int fan_write(char *buf
)
3869 while (!rc
&& (cmd
= next_cmd(&buf
))) {
3870 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
3871 fan_write_cmd_level(cmd
, &rc
)) &&
3872 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
3873 (fan_write_cmd_enable(cmd
, &rc
) ||
3874 fan_write_cmd_disable(cmd
, &rc
) ||
3875 fan_write_cmd_watchdog(cmd
, &rc
))) &&
3876 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
3877 fan_write_cmd_speed(cmd
, &rc
))
3881 fan_watchdog_reset();
3887 static struct ibm_struct fan_driver_data
= {
3894 /****************************************************************************
3895 ****************************************************************************
3899 ****************************************************************************
3900 ****************************************************************************/
3903 static struct proc_dir_entry
*proc_dir
= NULL
;
3905 /* Subdriver registry */
3906 static LIST_HEAD(tpacpi_all_drivers
);
3910 * Module and infrastructure proble, init and exit handling
3913 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
3914 static const char * __init
str_supported(int is_supported
)
3916 static char text_unsupported
[] __initdata
= "not supported";
3918 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
3920 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
3922 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
3925 struct ibm_struct
*ibm
= iibm
->data
;
3926 struct proc_dir_entry
*entry
;
3928 BUG_ON(ibm
== NULL
);
3930 INIT_LIST_HEAD(&ibm
->all_drivers
);
3932 if (ibm
->flags
.experimental
&& !experimental
)
3935 dbg_printk(TPACPI_DBG_INIT
,
3936 "probing for %s\n", ibm
->name
);
3939 ret
= iibm
->init(iibm
);
3941 return 0; /* probe failed */
3945 ibm
->flags
.init_called
= 1;
3949 if (ibm
->acpi
->hid
) {
3950 ret
= register_tpacpi_subdriver(ibm
);
3955 if (ibm
->acpi
->notify
) {
3956 ret
= setup_acpi_notify(ibm
);
3957 if (ret
== -ENODEV
) {
3958 printk(IBM_NOTICE
"disabling subdriver %s\n",
3968 dbg_printk(TPACPI_DBG_INIT
,
3969 "%s installed\n", ibm
->name
);
3972 entry
= create_proc_entry(ibm
->name
,
3973 S_IFREG
| S_IRUGO
| S_IWUSR
,
3976 printk(IBM_ERR
"unable to create proc entry %s\n",
3981 entry
->owner
= THIS_MODULE
;
3983 entry
->read_proc
= &dispatch_procfs_read
;
3985 entry
->write_proc
= &dispatch_procfs_write
;
3986 ibm
->flags
.proc_created
= 1;
3989 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
3994 dbg_printk(TPACPI_DBG_INIT
,
3995 "%s: at error exit path with result %d\n",
3999 return (ret
< 0)? ret
: 0;
4002 static void ibm_exit(struct ibm_struct
*ibm
)
4004 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4006 list_del_init(&ibm
->all_drivers
);
4008 if (ibm
->flags
.acpi_notify_installed
) {
4009 dbg_printk(TPACPI_DBG_EXIT
,
4010 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4012 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4014 dispatch_acpi_notify
);
4015 ibm
->flags
.acpi_notify_installed
= 0;
4016 ibm
->flags
.acpi_notify_installed
= 0;
4019 if (ibm
->flags
.proc_created
) {
4020 dbg_printk(TPACPI_DBG_EXIT
,
4021 "%s: remove_proc_entry\n", ibm
->name
);
4022 remove_proc_entry(ibm
->name
, proc_dir
);
4023 ibm
->flags
.proc_created
= 0;
4026 if (ibm
->flags
.acpi_driver_registered
) {
4027 dbg_printk(TPACPI_DBG_EXIT
,
4028 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4030 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4031 kfree(ibm
->acpi
->driver
);
4032 ibm
->acpi
->driver
= NULL
;
4033 ibm
->flags
.acpi_driver_registered
= 0;
4036 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4038 ibm
->flags
.init_called
= 0;
4041 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4046 static char *ibm_thinkpad_ec_found
= NULL
;
4048 static char* __init
check_dmi_for_ec(void)
4050 struct dmi_device
*dev
= NULL
;
4051 char ec_fw_string
[18];
4054 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4055 * X32 or newer, all Z series; Some models must have an
4056 * up-to-date BIOS or they will not be detected.
4058 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4060 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4061 if (sscanf(dev
->name
,
4062 "IBM ThinkPad Embedded Controller -[%17c",
4063 ec_fw_string
) == 1) {
4064 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4065 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4066 return kstrdup(ec_fw_string
, GFP_KERNEL
);
4072 static int __init
probe_for_thinkpad(void)
4080 * Non-ancient models have better DMI tagging, but very old models
4083 is_thinkpad
= dmi_name_in_vendors("ThinkPad");
4085 /* ec is required because many other handles are relative to it */
4086 IBM_ACPIHANDLE_INIT(ec
);
4090 "Not yet supported ThinkPad detected!\n");
4095 * Risks a regression on very old machines, but reduces potential
4096 * false positives a damn great deal
4099 is_thinkpad
= dmi_name_in_vendors("IBM");
4101 if (!is_thinkpad
&& !force_load
)
4108 /* Module init, exit, parameters */
4110 static struct ibm_init_struct ibms_init
[] __initdata
= {
4112 .init
= thinkpad_acpi_driver_init
,
4113 .data
= &thinkpad_acpi_driver_data
,
4116 .init
= hotkey_init
,
4117 .data
= &hotkey_driver_data
,
4120 .init
= bluetooth_init
,
4121 .data
= &bluetooth_driver_data
,
4125 .data
= &wan_driver_data
,
4129 .data
= &video_driver_data
,
4133 .data
= &light_driver_data
,
4135 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4138 .data
= &dock_driver_data
[0],
4142 .data
= &dock_driver_data
[1],
4145 #ifdef CONFIG_THINKPAD_ACPI_BAY
4148 .data
= &bay_driver_data
,
4153 .data
= &cmos_driver_data
,
4157 .data
= &led_driver_data
,
4161 .data
= &beep_driver_data
,
4164 .init
= thermal_init
,
4165 .data
= &thermal_driver_data
,
4168 .data
= &ecdump_driver_data
,
4171 .init
= brightness_init
,
4172 .data
= &brightness_driver_data
,
4175 .data
= &volume_driver_data
,
4179 .data
= &fan_driver_data
,
4183 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4186 struct ibm_struct
*ibm
;
4188 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4189 ibm
= ibms_init
[i
].data
;
4190 BUG_ON(ibm
== NULL
);
4192 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4193 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4195 strcpy(ibms_init
[i
].param
, val
);
4196 strcat(ibms_init
[i
].param
, ",");
4204 static int experimental
;
4205 module_param(experimental
, int, 0);
4207 static u32 dbg_level
;
4208 module_param_named(debug
, dbg_level
, uint
, 0);
4210 static int force_load
;
4211 module_param(force_load
, int, 0);
4213 static int fan_control_allowed
;
4214 module_param_named(fan_control
, fan_control_allowed
, int, 0);
4216 #define IBM_PARAM(feature) \
4217 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4220 IBM_PARAM(bluetooth
);
4223 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4226 #ifdef CONFIG_THINKPAD_ACPI_BAY
4228 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4233 IBM_PARAM(brightness
);
4237 static int __init
thinkpad_acpi_module_init(void)
4241 /* Driver-level probe */
4242 ret
= probe_for_thinkpad();
4246 /* Driver initialization */
4247 ibm_thinkpad_ec_found
= check_dmi_for_ec();
4248 IBM_ACPIHANDLE_INIT(ecrd
);
4249 IBM_ACPIHANDLE_INIT(ecwr
);
4251 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4253 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4254 thinkpad_acpi_module_exit();
4257 proc_dir
->owner
= THIS_MODULE
;
4259 ret
= platform_driver_register(&tpacpi_pdriver
);
4261 printk(IBM_ERR
"unable to register platform driver\n");
4262 thinkpad_acpi_module_exit();
4265 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4267 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4268 thinkpad_acpi_module_exit();
4273 /* Device initialization */
4274 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4276 if (IS_ERR(tpacpi_pdev
)) {
4277 ret
= PTR_ERR(tpacpi_pdev
);
4279 printk(IBM_ERR
"unable to register platform device\n");
4280 thinkpad_acpi_module_exit();
4283 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
4284 if (IS_ERR(tpacpi_hwmon
)) {
4285 ret
= PTR_ERR(tpacpi_hwmon
);
4286 tpacpi_hwmon
= NULL
;
4287 printk(IBM_ERR
"unable to register hwmon device\n");
4288 thinkpad_acpi_module_exit();
4291 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4292 ret
= ibm_init(&ibms_init
[i
]);
4293 if (ret
>= 0 && *ibms_init
[i
].param
)
4294 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
4296 thinkpad_acpi_module_exit();
4304 static void thinkpad_acpi_module_exit(void)
4306 struct ibm_struct
*ibm
, *itmp
;
4308 list_for_each_entry_safe_reverse(ibm
, itmp
,
4309 &tpacpi_all_drivers
,
4314 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
4317 hwmon_device_unregister(tpacpi_hwmon
);
4320 platform_device_unregister(tpacpi_pdev
);
4322 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
4323 platform_driver_unregister(&tpacpi_pdriver
);
4326 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
4328 kfree(ibm_thinkpad_ec_found
);
4331 module_init(thinkpad_acpi_module_init
);
4332 module_exit(thinkpad_acpi_module_exit
);