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
;
731 static u32 hotkey_all_mask
;
732 static u32 hotkey_reserved_mask
= 0x00778000;
734 static struct attribute_set
*hotkey_dev_attributes
;
736 /* sysfs hotkey enable ------------------------------------------------- */
737 static ssize_t
hotkey_enable_show(struct device
*dev
,
738 struct device_attribute
*attr
,
744 res
= hotkey_get(&status
, &mask
);
748 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
751 static ssize_t
hotkey_enable_store(struct device
*dev
,
752 struct device_attribute
*attr
,
753 const char *buf
, size_t count
)
759 if (parse_strtoul(buf
, 1, &t
))
762 res
= hotkey_get(&status
, &mask
);
764 res
= hotkey_set(t
, mask
);
766 return (res
) ? res
: count
;
769 static struct device_attribute dev_attr_hotkey_enable
=
770 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
771 hotkey_enable_show
, hotkey_enable_store
);
773 /* sysfs hotkey mask --------------------------------------------------- */
774 static ssize_t
hotkey_mask_show(struct device
*dev
,
775 struct device_attribute
*attr
,
781 res
= hotkey_get(&status
, &mask
);
785 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
788 static ssize_t
hotkey_mask_store(struct device
*dev
,
789 struct device_attribute
*attr
,
790 const char *buf
, size_t count
)
796 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
799 res
= hotkey_get(&status
, &mask
);
801 hotkey_set(status
, t
);
803 return (res
) ? res
: count
;
806 static struct device_attribute dev_attr_hotkey_mask
=
807 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
808 hotkey_mask_show
, hotkey_mask_store
);
810 /* sysfs hotkey bios_enabled ------------------------------------------- */
811 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
812 struct device_attribute
*attr
,
815 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
818 static struct device_attribute dev_attr_hotkey_bios_enabled
=
819 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
821 /* sysfs hotkey bios_mask ---------------------------------------------- */
822 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
823 struct device_attribute
*attr
,
826 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
829 static struct device_attribute dev_attr_hotkey_bios_mask
=
830 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
832 /* sysfs hotkey all_mask ----------------------------------------------- */
833 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
834 struct device_attribute
*attr
,
837 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_all_mask
);
840 static struct device_attribute dev_attr_hotkey_all_mask
=
841 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
843 /* sysfs hotkey recommended_mask --------------------------------------- */
844 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
845 struct device_attribute
*attr
,
848 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
849 hotkey_all_mask
& ~hotkey_reserved_mask
);
852 static struct device_attribute dev_attr_hotkey_recommended_mask
=
853 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
854 hotkey_recommended_mask_show
, NULL
);
856 /* --------------------------------------------------------------------- */
858 static struct attribute
*hotkey_mask_attributes
[] = {
859 &dev_attr_hotkey_mask
.attr
,
860 &dev_attr_hotkey_bios_enabled
.attr
,
861 &dev_attr_hotkey_bios_mask
.attr
,
862 &dev_attr_hotkey_all_mask
.attr
,
863 &dev_attr_hotkey_recommended_mask
.attr
,
866 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
870 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
872 IBM_ACPIHANDLE_INIT(hkey
);
873 mutex_init(&hotkey_mutex
);
875 /* hotkey not supported on 570 */
876 tp_features
.hotkey
= hkey_handle
!= NULL
;
878 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
879 str_supported(tp_features
.hotkey
));
881 if (tp_features
.hotkey
) {
882 hotkey_dev_attributes
= create_attr_set(6, NULL
);
883 if (!hotkey_dev_attributes
)
885 res
= add_to_attr_set(hotkey_dev_attributes
,
886 &dev_attr_hotkey_enable
.attr
);
890 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
891 A30, R30, R31, T20-22, X20-21, X22-24 */
892 tp_features
.hotkey_mask
=
893 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
895 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
896 str_supported(tp_features
.hotkey_mask
));
898 if (tp_features
.hotkey_mask
) {
899 /* MHKA available in A31, R40, R40e, T4x, X31, and later */
900 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
902 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
905 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
906 if (!res
&& tp_features
.hotkey_mask
) {
907 res
= add_many_to_attr_set(hotkey_dev_attributes
,
908 hotkey_mask_attributes
,
909 ARRAY_SIZE(hotkey_mask_attributes
));
912 res
= register_attr_set_with_sysfs(
913 hotkey_dev_attributes
,
914 &tpacpi_pdev
->dev
.kobj
);
920 return (tp_features
.hotkey
)? 0 : 1;
923 static void hotkey_exit(void)
927 if (tp_features
.hotkey
) {
928 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
929 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
931 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
934 if (hotkey_dev_attributes
) {
935 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
936 hotkey_dev_attributes
= NULL
;
940 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
944 if (event
== 0x80 && acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
945 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
947 printk(IBM_ERR
"unknown hotkey notification event %d\n", event
);
948 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
953 * Call with hotkey_mutex held
955 static int hotkey_get(int *status
, u32
*mask
)
957 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
960 if (tp_features
.hotkey_mask
)
961 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
968 * Call with hotkey_mutex held
970 static int hotkey_set(int status
, u32 mask
)
974 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
977 if (tp_features
.hotkey_mask
)
978 for (i
= 0; i
< 32; i
++) {
979 int bit
= ((1 << i
) & mask
) != 0;
980 if (!acpi_evalf(hkey_handle
,
981 NULL
, "MHKM", "vdd", i
+ 1, bit
))
988 /* procfs -------------------------------------------------------------- */
989 static int hotkey_read(char *p
)
995 if (!tp_features
.hotkey
) {
996 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1000 res
= mutex_lock_interruptible(&hotkey_mutex
);
1003 res
= hotkey_get(&status
, &mask
);
1004 mutex_unlock(&hotkey_mutex
);
1008 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1009 if (tp_features
.hotkey_mask
) {
1010 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1011 len
+= sprintf(p
+ len
,
1012 "commands:\tenable, disable, reset, <mask>\n");
1014 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1015 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1021 static int hotkey_write(char *buf
)
1028 if (!tp_features
.hotkey
)
1031 res
= mutex_lock_interruptible(&hotkey_mutex
);
1035 res
= hotkey_get(&status
, &mask
);
1040 while ((cmd
= next_cmd(&buf
))) {
1041 if (strlencmp(cmd
, "enable") == 0) {
1043 } else if (strlencmp(cmd
, "disable") == 0) {
1045 } else if (strlencmp(cmd
, "reset") == 0) {
1046 status
= hotkey_orig_status
;
1047 mask
= hotkey_orig_mask
;
1048 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1050 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1060 res
= hotkey_set(status
, mask
);
1063 mutex_unlock(&hotkey_mutex
);
1067 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1068 .hid
= IBM_HKEY_HID
,
1069 .notify
= hotkey_notify
,
1070 .handle
= &hkey_handle
,
1071 .type
= ACPI_DEVICE_NOTIFY
,
1074 static struct ibm_struct hotkey_driver_data
= {
1076 .read
= hotkey_read
,
1077 .write
= hotkey_write
,
1078 .exit
= hotkey_exit
,
1079 .acpi
= &ibm_hotkey_acpidriver
,
1082 /*************************************************************************
1083 * Bluetooth subdriver
1086 /* sysfs bluetooth enable ---------------------------------------------- */
1087 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1088 struct device_attribute
*attr
,
1093 status
= bluetooth_get_radiosw();
1097 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1100 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1101 struct device_attribute
*attr
,
1102 const char *buf
, size_t count
)
1107 if (parse_strtoul(buf
, 1, &t
))
1110 res
= bluetooth_set_radiosw(t
);
1112 return (res
) ? res
: count
;
1115 static struct device_attribute dev_attr_bluetooth_enable
=
1116 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1117 bluetooth_enable_show
, bluetooth_enable_store
);
1119 /* --------------------------------------------------------------------- */
1121 static struct attribute
*bluetooth_attributes
[] = {
1122 &dev_attr_bluetooth_enable
.attr
,
1126 static const struct attribute_group bluetooth_attr_group
= {
1127 .attrs
= bluetooth_attributes
,
1130 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1135 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1137 IBM_ACPIHANDLE_INIT(hkey
);
1139 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1140 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1141 tp_features
.bluetooth
= hkey_handle
&&
1142 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1144 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1145 str_supported(tp_features
.bluetooth
),
1148 if (tp_features
.bluetooth
) {
1149 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1150 /* no bluetooth hardware present in system */
1151 tp_features
.bluetooth
= 0;
1152 dbg_printk(TPACPI_DBG_INIT
,
1153 "bluetooth hardware not installed\n");
1155 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1156 &bluetooth_attr_group
);
1162 return (tp_features
.bluetooth
)? 0 : 1;
1165 static void bluetooth_exit(void)
1167 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1168 &bluetooth_attr_group
);
1171 static int bluetooth_get_radiosw(void)
1175 if (!tp_features
.bluetooth
)
1178 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1181 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1184 static int bluetooth_set_radiosw(int radio_on
)
1188 if (!tp_features
.bluetooth
)
1191 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1194 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1196 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1197 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1203 /* procfs -------------------------------------------------------------- */
1204 static int bluetooth_read(char *p
)
1207 int status
= bluetooth_get_radiosw();
1209 if (!tp_features
.bluetooth
)
1210 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1212 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1213 (status
)? "enabled" : "disabled");
1214 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1220 static int bluetooth_write(char *buf
)
1224 if (!tp_features
.bluetooth
)
1227 while ((cmd
= next_cmd(&buf
))) {
1228 if (strlencmp(cmd
, "enable") == 0) {
1229 bluetooth_set_radiosw(1);
1230 } else if (strlencmp(cmd
, "disable") == 0) {
1231 bluetooth_set_radiosw(0);
1239 static struct ibm_struct bluetooth_driver_data
= {
1240 .name
= "bluetooth",
1241 .read
= bluetooth_read
,
1242 .write
= bluetooth_write
,
1243 .exit
= bluetooth_exit
,
1246 /*************************************************************************
1250 /* sysfs wan enable ---------------------------------------------------- */
1251 static ssize_t
wan_enable_show(struct device
*dev
,
1252 struct device_attribute
*attr
,
1257 status
= wan_get_radiosw();
1261 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1264 static ssize_t
wan_enable_store(struct device
*dev
,
1265 struct device_attribute
*attr
,
1266 const char *buf
, size_t count
)
1271 if (parse_strtoul(buf
, 1, &t
))
1274 res
= wan_set_radiosw(t
);
1276 return (res
) ? res
: count
;
1279 static struct device_attribute dev_attr_wan_enable
=
1280 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1281 wan_enable_show
, wan_enable_store
);
1283 /* --------------------------------------------------------------------- */
1285 static struct attribute
*wan_attributes
[] = {
1286 &dev_attr_wan_enable
.attr
,
1290 static const struct attribute_group wan_attr_group
= {
1291 .attrs
= wan_attributes
,
1294 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1299 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1301 IBM_ACPIHANDLE_INIT(hkey
);
1303 tp_features
.wan
= hkey_handle
&&
1304 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1306 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1307 str_supported(tp_features
.wan
),
1310 if (tp_features
.wan
) {
1311 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1312 /* no wan hardware present in system */
1313 tp_features
.wan
= 0;
1314 dbg_printk(TPACPI_DBG_INIT
,
1315 "wan hardware not installed\n");
1317 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1324 return (tp_features
.wan
)? 0 : 1;
1327 static void wan_exit(void)
1329 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1333 static int wan_get_radiosw(void)
1337 if (!tp_features
.wan
)
1340 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1343 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1346 static int wan_set_radiosw(int radio_on
)
1350 if (!tp_features
.wan
)
1353 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1356 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1358 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1359 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1365 /* procfs -------------------------------------------------------------- */
1366 static int wan_read(char *p
)
1369 int status
= wan_get_radiosw();
1371 if (!tp_features
.wan
)
1372 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1374 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1375 (status
)? "enabled" : "disabled");
1376 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1382 static int wan_write(char *buf
)
1386 if (!tp_features
.wan
)
1389 while ((cmd
= next_cmd(&buf
))) {
1390 if (strlencmp(cmd
, "enable") == 0) {
1392 } else if (strlencmp(cmd
, "disable") == 0) {
1401 static struct ibm_struct wan_driver_data
= {
1406 .flags
.experimental
= 1,
1409 /*************************************************************************
1413 static enum video_access_mode video_supported
;
1414 static int video_orig_autosw
;
1416 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1417 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1418 "\\_SB.PCI0.VID0", /* 770e */
1419 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1420 "\\_SB.PCI0.AGP.VID", /* all others */
1423 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1425 static int __init
video_init(struct ibm_init_struct
*iibm
)
1429 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1431 IBM_ACPIHANDLE_INIT(vid
);
1432 IBM_ACPIHANDLE_INIT(vid2
);
1434 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1435 /* G41, assume IVGA doesn't change */
1436 vid_handle
= vid2_handle
;
1439 /* video switching not supported on R30, R31 */
1440 video_supported
= TPACPI_VIDEO_NONE
;
1441 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1443 video_supported
= TPACPI_VIDEO_570
;
1444 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1445 /* 600e/x, 770e, 770x */
1446 video_supported
= TPACPI_VIDEO_770
;
1449 video_supported
= TPACPI_VIDEO_NEW
;
1451 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1452 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1455 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1458 static void video_exit(void)
1460 dbg_printk(TPACPI_DBG_EXIT
,
1461 "restoring original video autoswitch mode\n");
1462 if (video_autosw_set(video_orig_autosw
))
1463 printk(IBM_ERR
"error while trying to restore original "
1464 "video autoswitch mode\n");
1467 static int video_outputsw_get(void)
1472 switch (video_supported
) {
1473 case TPACPI_VIDEO_570
:
1474 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1475 TP_ACPI_VIDEO_570_PHSCMD
))
1477 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1479 case TPACPI_VIDEO_770
:
1480 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1483 status
|= TP_ACPI_VIDEO_S_LCD
;
1484 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1487 status
|= TP_ACPI_VIDEO_S_CRT
;
1489 case TPACPI_VIDEO_NEW
:
1490 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1491 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1494 status
|= TP_ACPI_VIDEO_S_CRT
;
1496 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1497 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1500 status
|= TP_ACPI_VIDEO_S_LCD
;
1501 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1504 status
|= TP_ACPI_VIDEO_S_DVI
;
1513 static int video_outputsw_set(int status
)
1518 switch (video_supported
) {
1519 case TPACPI_VIDEO_570
:
1520 res
= acpi_evalf(NULL
, NULL
,
1521 "\\_SB.PHS2", "vdd",
1522 TP_ACPI_VIDEO_570_PHS2CMD
,
1523 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1525 case TPACPI_VIDEO_770
:
1526 autosw
= video_autosw_get();
1530 res
= video_autosw_set(1);
1533 res
= acpi_evalf(vid_handle
, NULL
,
1534 "ASWT", "vdd", status
* 0x100, 0);
1535 if (!autosw
&& video_autosw_set(autosw
)) {
1536 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1540 case TPACPI_VIDEO_NEW
:
1541 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1542 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1548 return (res
)? 0 : -EIO
;
1551 static int video_autosw_get(void)
1555 switch (video_supported
) {
1556 case TPACPI_VIDEO_570
:
1557 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1560 case TPACPI_VIDEO_770
:
1561 case TPACPI_VIDEO_NEW
:
1562 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1572 static int video_autosw_set(int enable
)
1574 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1579 static int video_outputsw_cycle(void)
1581 int autosw
= video_autosw_get();
1587 switch (video_supported
) {
1588 case TPACPI_VIDEO_570
:
1589 res
= video_autosw_set(1);
1592 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1594 case TPACPI_VIDEO_770
:
1595 case TPACPI_VIDEO_NEW
:
1596 res
= video_autosw_set(1);
1599 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1604 if (!autosw
&& video_autosw_set(autosw
)) {
1605 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1609 return (res
)? 0 : -EIO
;
1612 static int video_expand_toggle(void)
1614 switch (video_supported
) {
1615 case TPACPI_VIDEO_570
:
1616 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1618 case TPACPI_VIDEO_770
:
1619 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1621 case TPACPI_VIDEO_NEW
:
1622 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1630 static int video_read(char *p
)
1635 if (video_supported
== TPACPI_VIDEO_NONE
) {
1636 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1640 status
= video_outputsw_get();
1644 autosw
= video_autosw_get();
1648 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1649 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
1650 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
1651 if (video_supported
== TPACPI_VIDEO_NEW
)
1652 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
1653 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
1654 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
1655 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
1656 if (video_supported
== TPACPI_VIDEO_NEW
)
1657 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
1658 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
1659 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
1664 static int video_write(char *buf
)
1667 int enable
, disable
, status
;
1670 if (video_supported
== TPACPI_VIDEO_NONE
)
1676 while ((cmd
= next_cmd(&buf
))) {
1677 if (strlencmp(cmd
, "lcd_enable") == 0) {
1678 enable
|= TP_ACPI_VIDEO_S_LCD
;
1679 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1680 disable
|= TP_ACPI_VIDEO_S_LCD
;
1681 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1682 enable
|= TP_ACPI_VIDEO_S_CRT
;
1683 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1684 disable
|= TP_ACPI_VIDEO_S_CRT
;
1685 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1686 strlencmp(cmd
, "dvi_enable") == 0) {
1687 enable
|= TP_ACPI_VIDEO_S_DVI
;
1688 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1689 strlencmp(cmd
, "dvi_disable") == 0) {
1690 disable
|= TP_ACPI_VIDEO_S_DVI
;
1691 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1692 res
= video_autosw_set(1);
1695 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1696 res
= video_autosw_set(0);
1699 } else if (strlencmp(cmd
, "video_switch") == 0) {
1700 res
= video_outputsw_cycle();
1703 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1704 res
= video_expand_toggle();
1711 if (enable
|| disable
) {
1712 status
= video_outputsw_get();
1715 res
= video_outputsw_set((status
& ~disable
) | enable
);
1723 static struct ibm_struct video_driver_data
= {
1726 .write
= video_write
,
1730 /*************************************************************************
1731 * Light (thinklight) subdriver
1734 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1735 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1737 static int __init
light_init(struct ibm_init_struct
*iibm
)
1739 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
1741 IBM_ACPIHANDLE_INIT(ledb
);
1742 IBM_ACPIHANDLE_INIT(lght
);
1743 IBM_ACPIHANDLE_INIT(cmos
);
1745 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1746 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1748 if (tp_features
.light
)
1749 /* light status not supported on
1750 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1751 tp_features
.light_status
=
1752 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
1754 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
1755 str_supported(tp_features
.light
));
1757 return (tp_features
.light
)? 0 : 1;
1760 static int light_read(char *p
)
1765 if (!tp_features
.light
) {
1766 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1767 } else if (!tp_features
.light_status
) {
1768 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1769 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1771 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1773 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1774 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1780 static int light_write(char *buf
)
1782 int cmos_cmd
, lght_cmd
;
1786 if (!tp_features
.light
)
1789 while ((cmd
= next_cmd(&buf
))) {
1790 if (strlencmp(cmd
, "on") == 0) {
1793 } else if (strlencmp(cmd
, "off") == 0) {
1799 success
= cmos_handle
?
1800 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1801 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1809 static struct ibm_struct light_driver_data
= {
1812 .write
= light_write
,
1815 /*************************************************************************
1819 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1821 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
1822 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1823 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1824 "\\_SB.PCI.ISA.SLCE", /* 570 */
1825 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1827 /* don't list other alternatives as we install a notify handler on the 570 */
1828 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
1830 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
1832 .notify
= dock_notify
,
1833 .handle
= &dock_handle
,
1834 .type
= ACPI_SYSTEM_NOTIFY
,
1838 .notify
= dock_notify
,
1839 .handle
= &pci_handle
,
1840 .type
= ACPI_SYSTEM_NOTIFY
,
1844 static struct ibm_struct dock_driver_data
[2] = {
1848 .write
= dock_write
,
1849 .acpi
= &ibm_dock_acpidriver
[0],
1853 .acpi
= &ibm_dock_acpidriver
[1],
1857 #define dock_docked() (_sta(dock_handle) & 1)
1859 static int __init
dock_init(struct ibm_init_struct
*iibm
)
1861 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
1863 IBM_ACPIHANDLE_INIT(dock
);
1865 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
1866 str_supported(dock_handle
!= NULL
));
1868 return (dock_handle
)? 0 : 1;
1871 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
1875 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
1877 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
1878 dock_driver_data
[0].flags
.acpi_notify_installed
) {
1879 IBM_ACPIHANDLE_INIT(pci
);
1880 dock2_needed
= (pci_handle
!= NULL
);
1881 vdbg_printk(TPACPI_DBG_INIT
,
1882 "dock PCI handler for the TP 570 is %s\n",
1883 str_supported(dock2_needed
));
1885 vdbg_printk(TPACPI_DBG_INIT
,
1886 "dock subdriver part 2 not required\n");
1890 return (dock2_needed
)? 0 : 1;
1893 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1895 int docked
= dock_docked();
1896 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, IBM_PCI_HID
);
1898 if (event
== 1 && !pci
) /* 570 */
1899 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1900 else if (event
== 1 && pci
) /* 570 */
1901 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1902 else if (event
== 3 && docked
)
1903 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1904 else if (event
== 3 && !docked
)
1905 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
1906 else if (event
== 0 && docked
)
1907 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1909 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1910 event
, _sta(dock_handle
));
1911 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
1915 static int dock_read(char *p
)
1918 int docked
= dock_docked();
1921 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1923 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1925 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1926 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1932 static int dock_write(char *buf
)
1939 while ((cmd
= next_cmd(&buf
))) {
1940 if (strlencmp(cmd
, "undock") == 0) {
1941 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1942 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1944 } else if (strlencmp(cmd
, "dock") == 0) {
1945 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1954 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1956 /*************************************************************************
1960 #ifdef CONFIG_THINKPAD_ACPI_BAY
1961 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1962 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1963 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1964 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1965 ); /* A21e, R30, R31 */
1966 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
1967 "_EJ0", /* all others */
1968 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1969 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1970 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1972 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
1976 static int __init
bay_init(struct ibm_init_struct
*iibm
)
1978 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
1980 IBM_ACPIHANDLE_INIT(bay
);
1982 IBM_ACPIHANDLE_INIT(bay_ej
);
1983 IBM_ACPIHANDLE_INIT(bay2
);
1985 IBM_ACPIHANDLE_INIT(bay2_ej
);
1987 tp_features
.bay_status
= bay_handle
&&
1988 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1989 tp_features
.bay_status2
= bay2_handle
&&
1990 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1992 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
1993 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1994 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
1995 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1997 vdbg_printk(TPACPI_DBG_INIT
,
1998 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1999 str_supported(tp_features
.bay_status
),
2000 str_supported(tp_features
.bay_eject
),
2001 str_supported(tp_features
.bay_status2
),
2002 str_supported(tp_features
.bay_eject2
));
2004 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2005 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2008 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2010 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
2013 #define bay_occupied(b) (_sta(b##_handle) & 1)
2015 static int bay_read(char *p
)
2018 int occupied
= bay_occupied(bay
);
2019 int occupied2
= bay_occupied(bay2
);
2022 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2023 tp_features
.bay_status
?
2024 (occupied
? "occupied" : "unoccupied") :
2026 if (tp_features
.bay_status2
)
2027 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2028 "occupied" : "unoccupied");
2030 eject
= tp_features
.bay_eject
&& occupied
;
2031 eject2
= tp_features
.bay_eject2
&& occupied2
;
2033 if (eject
&& eject2
)
2034 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2036 len
+= sprintf(p
+ len
, "commands:\teject\n");
2038 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2043 static int bay_write(char *buf
)
2047 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2050 while ((cmd
= next_cmd(&buf
))) {
2051 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2052 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2054 } else if (tp_features
.bay_eject2
&&
2055 strlencmp(cmd
, "eject2") == 0) {
2056 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2065 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2066 .notify
= bay_notify
,
2067 .handle
= &bay_handle
,
2068 .type
= ACPI_SYSTEM_NOTIFY
,
2071 static struct ibm_struct bay_driver_data
= {
2075 .acpi
= &ibm_bay_acpidriver
,
2078 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2080 /*************************************************************************
2084 /* sysfs cmos_command -------------------------------------------------- */
2085 static ssize_t
cmos_command_store(struct device
*dev
,
2086 struct device_attribute
*attr
,
2087 const char *buf
, size_t count
)
2089 unsigned long cmos_cmd
;
2092 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2095 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2096 return (res
)? res
: count
;
2099 static struct device_attribute dev_attr_cmos_command
=
2100 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2102 /* --------------------------------------------------------------------- */
2104 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2108 vdbg_printk(TPACPI_DBG_INIT
,
2109 "initializing cmos commands subdriver\n");
2111 IBM_ACPIHANDLE_INIT(cmos
);
2113 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2114 str_supported(cmos_handle
!= NULL
));
2116 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2120 return (cmos_handle
)? 0 : 1;
2123 static void cmos_exit(void)
2125 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2128 static int cmos_read(char *p
)
2132 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2133 R30, R31, T20-22, X20-21 */
2135 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2137 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2138 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2144 static int cmos_write(char *buf
)
2149 while ((cmd
= next_cmd(&buf
))) {
2150 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2151 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2156 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2164 static struct ibm_struct cmos_driver_data
= {
2167 .write
= cmos_write
,
2171 /*************************************************************************
2175 static enum led_access_mode led_supported
;
2177 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2178 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2179 "LED", /* all others */
2182 static int __init
led_init(struct ibm_init_struct
*iibm
)
2184 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2186 IBM_ACPIHANDLE_INIT(led
);
2189 /* led not supported on R30, R31 */
2190 led_supported
= TPACPI_LED_NONE
;
2191 else if (strlencmp(led_path
, "SLED") == 0)
2193 led_supported
= TPACPI_LED_570
;
2194 else if (strlencmp(led_path
, "SYSL") == 0)
2195 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2196 led_supported
= TPACPI_LED_OLD
;
2199 led_supported
= TPACPI_LED_NEW
;
2201 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2202 str_supported(led_supported
), led_supported
);
2204 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2207 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2209 static int led_read(char *p
)
2213 if (!led_supported
) {
2214 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2217 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2219 if (led_supported
== TPACPI_LED_570
) {
2222 for (i
= 0; i
< 8; i
++) {
2223 if (!acpi_evalf(ec_handle
,
2224 &status
, "GLED", "dd", 1 << i
))
2226 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2227 i
, led_status(status
));
2231 len
+= sprintf(p
+ len
, "commands:\t"
2232 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2237 /* off, on, blink */
2238 static const int led_sled_arg1
[] = { 0, 1, 3 };
2239 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2240 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2241 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2243 static int led_write(char *buf
)
2251 while ((cmd
= next_cmd(&buf
))) {
2252 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2255 if (strstr(cmd
, "off")) {
2257 } else if (strstr(cmd
, "on")) {
2259 } else if (strstr(cmd
, "blink")) {
2264 if (led_supported
== TPACPI_LED_570
) {
2267 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2268 led
, led_sled_arg1
[ind
]))
2270 } else if (led_supported
== TPACPI_LED_OLD
) {
2271 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2273 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2276 ec_write(TPACPI_LED_EC_HLBL
,
2277 led
* led_exp_hlbl
[ind
]);
2280 ec_write(TPACPI_LED_EC_HLCL
,
2281 led
* led_exp_hlcl
[ind
]);
2286 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2287 led
, led_led_arg1
[ind
]))
2295 static struct ibm_struct led_driver_data
= {
2301 /*************************************************************************
2305 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2307 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2309 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2311 IBM_ACPIHANDLE_INIT(beep
);
2313 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2314 str_supported(beep_handle
!= NULL
));
2316 return (beep_handle
)? 0 : 1;
2319 static int beep_read(char *p
)
2324 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2326 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2327 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2333 static int beep_write(char *buf
)
2341 while ((cmd
= next_cmd(&buf
))) {
2342 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2343 beep_cmd
>= 0 && beep_cmd
<= 17) {
2347 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2354 static struct ibm_struct beep_driver_data
= {
2357 .write
= beep_write
,
2360 /*************************************************************************
2364 static enum thermal_access_mode thermal_read_mode
;
2366 /* sysfs temp##_input -------------------------------------------------- */
2368 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2369 struct device_attribute
*attr
,
2372 struct sensor_device_attribute
*sensor_attr
=
2373 to_sensor_dev_attr(attr
);
2374 int idx
= sensor_attr
->index
;
2378 res
= thermal_get_sensor(idx
, &value
);
2381 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2384 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2387 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2388 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2390 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2391 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2392 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2393 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2394 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2395 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2396 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2397 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2398 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2399 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2400 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2401 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2402 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2403 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2404 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2405 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2406 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2409 #define THERMAL_ATTRS(X) \
2410 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2412 static struct attribute
*thermal_temp_input_attr
[] = {
2432 static const struct attribute_group thermal_temp_input16_group
= {
2433 .attrs
= thermal_temp_input_attr
2436 static const struct attribute_group thermal_temp_input8_group
= {
2437 .attrs
= &thermal_temp_input_attr
[8]
2440 #undef THERMAL_SENSOR_ATTR_TEMP
2441 #undef THERMAL_ATTRS
2443 /* --------------------------------------------------------------------- */
2445 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2452 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2454 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2456 if (ibm_thinkpad_ec_found
&& experimental
) {
2458 * Direct EC access mode: sensors at registers
2459 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2460 * non-implemented, thermal sensors return 0x80 when
2465 for (i
= 0; i
< 8; i
++) {
2466 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2472 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2480 /* This is sheer paranoia, but we handle it anyway */
2483 "ThinkPad ACPI EC access misbehaving, "
2484 "falling back to ACPI TMPx access mode\n");
2485 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2488 "ThinkPad ACPI EC access misbehaving, "
2489 "disabling thermal sensors access\n");
2490 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2495 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2497 } else if (acpi_tmp7
) {
2498 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2499 /* 600e/x, 770e, 770x */
2500 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2502 /* Standard ACPI TMPx access, max 8 sensors */
2503 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2506 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2507 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2510 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2511 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2514 switch(thermal_read_mode
) {
2515 case TPACPI_THERMAL_TPEC_16
:
2516 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2517 &thermal_temp_input16_group
);
2521 case TPACPI_THERMAL_TPEC_8
:
2522 case TPACPI_THERMAL_ACPI_TMP07
:
2523 case TPACPI_THERMAL_ACPI_UPDT
:
2524 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2525 &thermal_temp_input8_group
);
2529 case TPACPI_THERMAL_NONE
:
2537 static void thermal_exit(void)
2539 switch(thermal_read_mode
) {
2540 case TPACPI_THERMAL_TPEC_16
:
2541 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2542 &thermal_temp_input16_group
);
2544 case TPACPI_THERMAL_TPEC_8
:
2545 case TPACPI_THERMAL_ACPI_TMP07
:
2546 case TPACPI_THERMAL_ACPI_UPDT
:
2547 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2548 &thermal_temp_input16_group
);
2550 case TPACPI_THERMAL_NONE
:
2556 /* idx is zero-based */
2557 static int thermal_get_sensor(int idx
, s32
*value
)
2563 t
= TP_EC_THERMAL_TMP0
;
2565 switch (thermal_read_mode
) {
2566 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2567 case TPACPI_THERMAL_TPEC_16
:
2568 if (idx
>= 8 && idx
<= 15) {
2569 t
= TP_EC_THERMAL_TMP8
;
2574 case TPACPI_THERMAL_TPEC_8
:
2576 if (!acpi_ec_read(t
+ idx
, &tmp
))
2578 *value
= tmp
* 1000;
2583 case TPACPI_THERMAL_ACPI_UPDT
:
2585 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2586 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2588 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2590 *value
= (t
- 2732) * 100;
2595 case TPACPI_THERMAL_ACPI_TMP07
:
2597 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2598 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2605 case TPACPI_THERMAL_NONE
:
2613 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2624 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2627 for(i
= 0 ; i
< n
; i
++) {
2628 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
2636 static int thermal_read(char *p
)
2640 struct ibm_thermal_sensors_struct t
;
2642 n
= thermal_get_sensors(&t
);
2643 if (unlikely(n
< 0))
2646 len
+= sprintf(p
+ len
, "temperatures:\t");
2649 for (i
= 0; i
< (n
- 1); i
++)
2650 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
2651 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
2653 len
+= sprintf(p
+ len
, "not supported\n");
2658 static struct ibm_struct thermal_driver_data
= {
2660 .read
= thermal_read
,
2661 .exit
= thermal_exit
,
2664 /*************************************************************************
2668 static u8 ecdump_regs
[256];
2670 static int ecdump_read(char *p
)
2676 len
+= sprintf(p
+ len
, "EC "
2677 " +00 +01 +02 +03 +04 +05 +06 +07"
2678 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2679 for (i
= 0; i
< 256; i
+= 16) {
2680 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
2681 for (j
= 0; j
< 16; j
++) {
2682 if (!acpi_ec_read(i
+ j
, &v
))
2684 if (v
!= ecdump_regs
[i
+ j
])
2685 len
+= sprintf(p
+ len
, " *%02x", v
);
2687 len
+= sprintf(p
+ len
, " %02x", v
);
2688 ecdump_regs
[i
+ j
] = v
;
2690 len
+= sprintf(p
+ len
, "\n");
2695 /* These are way too dangerous to advertise openly... */
2697 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
2698 " (<offset> is 00-ff, <value> is 00-ff)\n");
2699 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
2700 " (<offset> is 00-ff, <value> is 0-255)\n");
2705 static int ecdump_write(char *buf
)
2710 while ((cmd
= next_cmd(&buf
))) {
2711 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
2713 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
2717 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
2718 if (!acpi_ec_write(i
, v
))
2727 static struct ibm_struct ecdump_driver_data
= {
2729 .read
= ecdump_read
,
2730 .write
= ecdump_write
,
2731 .flags
.experimental
= 1,
2734 /*************************************************************************
2735 * Backlight/brightness subdriver
2738 static struct backlight_device
*ibm_backlight_device
;
2740 static struct backlight_properties ibm_backlight_data
= {
2741 .owner
= THIS_MODULE
,
2742 .get_brightness
= brightness_get
,
2743 .update_status
= brightness_update_status
,
2744 .max_brightness
= 7,
2747 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
2751 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
2753 b
= brightness_get(NULL
);
2757 ibm_backlight_device
= backlight_device_register(
2758 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
2759 &ibm_backlight_data
);
2760 if (IS_ERR(ibm_backlight_device
)) {
2761 printk(IBM_ERR
"Could not register backlight device\n");
2762 return PTR_ERR(ibm_backlight_device
);
2764 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
2766 ibm_backlight_device
->props
->brightness
= b
;
2767 brightness_update_status(ibm_backlight_device
);
2772 static void brightness_exit(void)
2774 if (ibm_backlight_device
) {
2775 vdbg_printk(TPACPI_DBG_EXIT
,
2776 "calling backlight_device_unregister()\n");
2777 backlight_device_unregister(ibm_backlight_device
);
2778 ibm_backlight_device
= NULL
;
2782 static int brightness_update_status(struct backlight_device
*bd
)
2784 return brightness_set(
2785 (bd
->props
->fb_blank
== FB_BLANK_UNBLANK
&&
2786 bd
->props
->power
== FB_BLANK_UNBLANK
) ?
2787 bd
->props
->brightness
: 0);
2790 static int brightness_get(struct backlight_device
*bd
)
2793 if (!acpi_ec_read(brightness_offset
, &level
))
2801 static int brightness_set(int value
)
2803 int cmos_cmd
, inc
, i
;
2804 int current_value
= brightness_get(NULL
);
2808 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
2809 inc
= value
> current_value
? 1 : -1;
2810 for (i
= current_value
; i
!= value
; i
+= inc
) {
2811 if (issue_thinkpad_cmos_command(cmos_cmd
))
2813 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
2820 static int brightness_read(char *p
)
2825 if ((level
= brightness_get(NULL
)) < 0) {
2826 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2828 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
2829 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
2830 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2831 " (<level> is 0-7)\n");
2837 static int brightness_write(char *buf
)
2843 while ((cmd
= next_cmd(&buf
))) {
2844 if ((level
= brightness_get(NULL
)) < 0)
2848 if (strlencmp(cmd
, "up") == 0) {
2849 new_level
= level
== 7 ? 7 : level
+ 1;
2850 } else if (strlencmp(cmd
, "down") == 0) {
2851 new_level
= level
== 0 ? 0 : level
- 1;
2852 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2853 new_level
>= 0 && new_level
<= 7) {
2858 brightness_set(new_level
);
2864 static struct ibm_struct brightness_driver_data
= {
2865 .name
= "brightness",
2866 .read
= brightness_read
,
2867 .write
= brightness_write
,
2868 .exit
= brightness_exit
,
2871 /*************************************************************************
2875 static int volume_read(char *p
)
2880 if (!acpi_ec_read(volume_offset
, &level
)) {
2881 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2883 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
2884 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
2885 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
2886 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2887 " (<level> is 0-15)\n");
2893 static int volume_write(char *buf
)
2895 int cmos_cmd
, inc
, i
;
2897 int new_level
, new_mute
;
2900 while ((cmd
= next_cmd(&buf
))) {
2901 if (!acpi_ec_read(volume_offset
, &level
))
2903 new_mute
= mute
= level
& 0x40;
2904 new_level
= level
= level
& 0xf;
2906 if (strlencmp(cmd
, "up") == 0) {
2910 new_level
= level
== 15 ? 15 : level
+ 1;
2911 } else if (strlencmp(cmd
, "down") == 0) {
2915 new_level
= level
== 0 ? 0 : level
- 1;
2916 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2917 new_level
>= 0 && new_level
<= 15) {
2919 } else if (strlencmp(cmd
, "mute") == 0) {
2924 if (new_level
!= level
) { /* mute doesn't change */
2925 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
2926 inc
= new_level
> level
? 1 : -1;
2928 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
2929 !acpi_ec_write(volume_offset
, level
)))
2932 for (i
= level
; i
!= new_level
; i
+= inc
)
2933 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2934 !acpi_ec_write(volume_offset
, i
+ inc
))
2937 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
2938 !acpi_ec_write(volume_offset
,
2943 if (new_mute
!= mute
) { /* level doesn't change */
2944 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
2946 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2947 !acpi_ec_write(volume_offset
, level
+ new_mute
))
2955 static struct ibm_struct volume_driver_data
= {
2957 .read
= volume_read
,
2958 .write
= volume_write
,
2961 /*************************************************************************
2968 * TPACPI_FAN_RD_ACPI_GFAN:
2969 * ACPI GFAN method: returns fan level
2971 * see TPACPI_FAN_WR_ACPI_SFAN
2972 * EC 0x2f (HFSP) not available if GFAN exists
2974 * TPACPI_FAN_WR_ACPI_SFAN:
2975 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2977 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2980 * TPACPI_FAN_WR_TPEC:
2981 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2982 * Supported on almost all ThinkPads
2984 * Fan speed changes of any sort (including those caused by the
2985 * disengaged mode) are usually done slowly by the firmware as the
2986 * maximum ammount of fan duty cycle change per second seems to be
2989 * Reading is not available if GFAN exists.
2990 * Writing is not available if SFAN exists.
2993 * 7 automatic mode engaged;
2994 * (default operation mode of the ThinkPad)
2995 * fan level is ignored in this mode.
2996 * 6 full speed mode (takes precedence over bit 7);
2997 * not available on all thinkpads. May disable
2998 * the tachometer while the fan controller ramps up
2999 * the speed (which can take up to a few *minutes*).
3000 * Speeds up fan to 100% duty-cycle, which is far above
3001 * the standard RPM levels. It is not impossible that
3002 * it could cause hardware damage.
3003 * 5-3 unused in some models. Extra bits for fan level
3004 * in others, but still useless as all values above
3005 * 7 map to the same speed as level 7 in these models.
3006 * 2-0 fan level (0..7 usually)
3008 * 0x07 = max (set when temperatures critical)
3009 * Some ThinkPads may have other levels, see
3010 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3012 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3013 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3014 * does so, its initial value is meaningless (0x07).
3016 * For firmware bugs, refer to:
3017 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3021 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3022 * Main fan tachometer reading (in RPM)
3024 * This register is present on all ThinkPads with a new-style EC, and
3025 * it is known not to be present on the A21m/e, and T22, as there is
3026 * something else in offset 0x84 according to the ACPI DSDT. Other
3027 * ThinkPads from this same time period (and earlier) probably lack the
3028 * tachometer as well.
3030 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3031 * was never fixed by IBM to report the EC firmware version string
3032 * probably support the tachometer (like the early X models), so
3033 * detecting it is quite hard. We need more data to know for sure.
3035 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3038 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3041 * For firmware bugs, refer to:
3042 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3044 * TPACPI_FAN_WR_ACPI_FANS:
3045 * ThinkPad X31, X40, X41. Not available in the X60.
3047 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3048 * high speed. ACPI DSDT seems to map these three speeds to levels
3049 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3050 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3052 * The speeds are stored on handles
3053 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3055 * There are three default speed sets, acessible as handles:
3056 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3058 * ACPI DSDT switches which set is in use depending on various
3061 * TPACPI_FAN_WR_TPEC is also available and should be used to
3062 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3063 * but the ACPI tables just mention level 7.
3066 static enum fan_status_access_mode fan_status_access_mode
;
3067 static enum fan_control_access_mode fan_control_access_mode
;
3068 static enum fan_control_commands fan_control_commands
;
3070 static u8 fan_control_initial_status
;
3071 static u8 fan_control_desired_level
;
3073 static void fan_watchdog_fire(struct work_struct
*ignored
);
3074 static int fan_watchdog_maxinterval
;
3075 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3077 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3078 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3079 "\\FSPD", /* 600e/x, 770e, 770x */
3081 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3082 "JFNS", /* 770x-JL */
3086 * SYSFS fan layout: hwmon compatible (device)
3089 * 0: "disengaged" mode
3091 * 2: native EC "auto" mode (recommended, hardware default)
3093 * pwm*: set speed in manual mode, ignored otherwise.
3094 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3097 * fan*_input: tachometer reading, RPM
3100 * SYSFS fan layout: extensions
3102 * fan_watchdog (driver):
3103 * fan watchdog interval in seconds, 0 disables (default), max 120
3106 /* sysfs fan pwm1_enable ----------------------------------------------- */
3107 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3108 struct device_attribute
*attr
,
3114 res
= fan_get_status_safe(&status
);
3118 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3119 if (status
!= fan_control_initial_status
) {
3120 tp_features
.fan_ctrl_status_undef
= 0;
3122 /* Return most likely status. In fact, it
3123 * might be the only possible status */
3124 status
= TP_EC_FAN_AUTO
;
3128 if (status
& TP_EC_FAN_FULLSPEED
) {
3130 } else if (status
& TP_EC_FAN_AUTO
) {
3135 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3138 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3139 struct device_attribute
*attr
,
3140 const char *buf
, size_t count
)
3145 if (parse_strtoul(buf
, 2, &t
))
3150 level
= TP_EC_FAN_FULLSPEED
;
3153 level
= TPACPI_FAN_LAST_LEVEL
;
3156 level
= TP_EC_FAN_AUTO
;
3159 /* reserved for software-controlled auto mode */
3165 res
= fan_set_level_safe(level
);
3171 fan_watchdog_reset();
3176 static struct device_attribute dev_attr_fan_pwm1_enable
=
3177 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3178 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3180 /* sysfs fan pwm1 ------------------------------------------------------ */
3181 static ssize_t
fan_pwm1_show(struct device
*dev
,
3182 struct device_attribute
*attr
,
3188 res
= fan_get_status_safe(&status
);
3192 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3193 if (status
!= fan_control_initial_status
) {
3194 tp_features
.fan_ctrl_status_undef
= 0;
3196 status
= TP_EC_FAN_AUTO
;
3201 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3202 status
= fan_control_desired_level
;
3207 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3210 static ssize_t
fan_pwm1_store(struct device
*dev
,
3211 struct device_attribute
*attr
,
3212 const char *buf
, size_t count
)
3216 u8 status
, newlevel
;
3218 if (parse_strtoul(buf
, 255, &s
))
3221 /* scale down from 0-255 to 0-7 */
3222 newlevel
= (s
>> 5) & 0x07;
3224 rc
= mutex_lock_interruptible(&fan_mutex
);
3228 rc
= fan_get_status(&status
);
3229 if (!rc
&& (status
&
3230 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3231 rc
= fan_set_level(newlevel
);
3235 fan_update_desired_level(newlevel
);
3236 fan_watchdog_reset();
3240 mutex_unlock(&fan_mutex
);
3241 return (rc
)? rc
: count
;
3244 static struct device_attribute dev_attr_fan_pwm1
=
3245 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3246 fan_pwm1_show
, fan_pwm1_store
);
3248 /* sysfs fan fan1_input ------------------------------------------------ */
3249 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3250 struct device_attribute
*attr
,
3256 res
= fan_get_speed(&speed
);
3260 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3263 static struct device_attribute dev_attr_fan_fan1_input
=
3264 __ATTR(fan1_input
, S_IRUGO
,
3265 fan_fan1_input_show
, NULL
);
3267 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
3268 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3271 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3274 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3275 const char *buf
, size_t count
)
3279 if (parse_strtoul(buf
, 120, &t
))
3282 if (!fan_control_allowed
)
3285 fan_watchdog_maxinterval
= t
;
3286 fan_watchdog_reset();
3291 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3292 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3294 /* --------------------------------------------------------------------- */
3295 static struct attribute
*fan_attributes
[] = {
3296 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3297 &dev_attr_fan_fan1_input
.attr
,
3301 static const struct attribute_group fan_attr_group
= {
3302 .attrs
= fan_attributes
,
3305 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3309 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3311 mutex_init(&fan_mutex
);
3312 fan_status_access_mode
= TPACPI_FAN_NONE
;
3313 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3314 fan_control_commands
= 0;
3315 fan_watchdog_maxinterval
= 0;
3316 tp_features
.fan_ctrl_status_undef
= 0;
3317 fan_control_desired_level
= 7;
3319 IBM_ACPIHANDLE_INIT(fans
);
3320 IBM_ACPIHANDLE_INIT(gfan
);
3321 IBM_ACPIHANDLE_INIT(sfan
);
3324 /* 570, 600e/x, 770e, 770x */
3325 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3327 /* all other ThinkPads: note that even old-style
3328 * ThinkPad ECs supports the fan control register */
3329 if (likely(acpi_ec_read(fan_status_offset
,
3330 &fan_control_initial_status
))) {
3331 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3333 /* In some ThinkPads, neither the EC nor the ACPI
3334 * DSDT initialize the fan status, and it ends up
3335 * being set to 0x07 when it *could* be either
3338 * Enable for TP-1Y (T43), TP-78 (R51e),
3339 * TP-76 (R52), TP-70 (T43, R52), which are known
3341 if (fan_control_initial_status
== 0x07 &&
3342 ibm_thinkpad_ec_found
&&
3343 ((ibm_thinkpad_ec_found
[0] == '1' &&
3344 ibm_thinkpad_ec_found
[1] == 'Y') ||
3345 (ibm_thinkpad_ec_found
[0] == '7' &&
3346 (ibm_thinkpad_ec_found
[1] == '6' ||
3347 ibm_thinkpad_ec_found
[1] == '8' ||
3348 ibm_thinkpad_ec_found
[1] == '0'))
3351 "fan_init: initial fan status is "
3352 "unknown, assuming it is in auto "
3354 tp_features
.fan_ctrl_status_undef
= 1;
3358 "ThinkPad ACPI EC access misbehaving, "
3359 "fan status and control unavailable\n");
3366 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3367 fan_control_commands
|=
3368 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3371 /* gfan without sfan means no fan control */
3372 /* all other models implement TP EC 0x2f control */
3376 fan_control_access_mode
=
3377 TPACPI_FAN_WR_ACPI_FANS
;
3378 fan_control_commands
|=
3379 TPACPI_FAN_CMD_SPEED
|
3380 TPACPI_FAN_CMD_LEVEL
|
3381 TPACPI_FAN_CMD_ENABLE
;
3383 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3384 fan_control_commands
|=
3385 TPACPI_FAN_CMD_LEVEL
|
3386 TPACPI_FAN_CMD_ENABLE
;
3391 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3392 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3393 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3394 fan_status_access_mode
, fan_control_access_mode
);
3396 /* fan control master switch */
3397 if (!fan_control_allowed
) {
3398 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3399 fan_control_commands
= 0;
3400 dbg_printk(TPACPI_DBG_INIT
,
3401 "fan control features disabled by parameter\n");
3404 /* update fan_control_desired_level */
3405 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3406 fan_get_status_safe(NULL
);
3408 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3409 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3410 rc
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3413 rc
= driver_create_file(&tpacpi_pdriver
.driver
,
3414 &driver_attr_fan_watchdog
);
3423 * Call with fan_mutex held
3425 static void fan_update_desired_level(u8 status
)
3428 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3430 fan_control_desired_level
= 7;
3432 fan_control_desired_level
= status
;
3436 static int fan_get_status(u8
*status
)
3441 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3443 switch (fan_status_access_mode
) {
3444 case TPACPI_FAN_RD_ACPI_GFAN
:
3445 /* 570, 600e/x, 770e, 770x */
3447 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
3455 case TPACPI_FAN_RD_TPEC
:
3456 /* all except 570, 600e/x, 770e, 770x */
3457 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
3472 static int fan_get_status_safe(u8
*status
)
3477 rc
= mutex_lock_interruptible(&fan_mutex
);
3480 rc
= fan_get_status(&s
);
3482 fan_update_desired_level(s
);
3483 mutex_unlock(&fan_mutex
);
3491 static void fan_exit(void)
3493 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
3495 /* FIXME: can we really do this unconditionally? */
3496 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
, &fan_attr_group
);
3497 driver_remove_file(&tpacpi_pdriver
.driver
, &driver_attr_fan_watchdog
);
3499 cancel_delayed_work(&fan_watchdog_task
);
3500 flush_scheduled_work();
3503 static int fan_get_speed(unsigned int *speed
)
3507 switch (fan_status_access_mode
) {
3508 case TPACPI_FAN_RD_TPEC
:
3509 /* all except 570, 600e/x, 770e, 770x */
3510 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
3511 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
3515 *speed
= (hi
<< 8) | lo
;
3526 static void fan_watchdog_fire(struct work_struct
*ignored
)
3530 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
3531 rc
= fan_set_enable();
3533 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
3534 "will try again later...\n", -rc
);
3535 /* reschedule for later */
3536 fan_watchdog_reset();
3540 static void fan_watchdog_reset(void)
3542 static int fan_watchdog_active
;
3544 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
3547 if (fan_watchdog_active
)
3548 cancel_delayed_work(&fan_watchdog_task
);
3550 if (fan_watchdog_maxinterval
> 0) {
3551 fan_watchdog_active
= 1;
3552 if (!schedule_delayed_work(&fan_watchdog_task
,
3553 msecs_to_jiffies(fan_watchdog_maxinterval
3555 printk(IBM_ERR
"failed to schedule the fan watchdog, "
3556 "watchdog will not trigger\n");
3559 fan_watchdog_active
= 0;
3562 static int fan_set_level(int level
)
3564 if (!fan_control_allowed
)
3567 switch (fan_control_access_mode
) {
3568 case TPACPI_FAN_WR_ACPI_SFAN
:
3569 if (level
>= 0 && level
<= 7) {
3570 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
3576 case TPACPI_FAN_WR_ACPI_FANS
:
3577 case TPACPI_FAN_WR_TPEC
:
3578 if ((level
!= TP_EC_FAN_AUTO
) &&
3579 (level
!= TP_EC_FAN_FULLSPEED
) &&
3580 ((level
< 0) || (level
> 7)))
3583 /* safety net should the EC not support AUTO
3584 * or FULLSPEED mode bits and just ignore them */
3585 if (level
& TP_EC_FAN_FULLSPEED
)
3586 level
|= 7; /* safety min speed 7 */
3587 else if (level
& TP_EC_FAN_FULLSPEED
)
3588 level
|= 4; /* safety min speed 4 */
3590 if (!acpi_ec_write(fan_status_offset
, level
))
3593 tp_features
.fan_ctrl_status_undef
= 0;
3602 static int fan_set_level_safe(int level
)
3606 if (!fan_control_allowed
)
3609 rc
= mutex_lock_interruptible(&fan_mutex
);
3613 if (level
== TPACPI_FAN_LAST_LEVEL
)
3614 level
= fan_control_desired_level
;
3616 rc
= fan_set_level(level
);
3618 fan_update_desired_level(level
);
3620 mutex_unlock(&fan_mutex
);
3624 static int fan_set_enable(void)
3629 if (!fan_control_allowed
)
3632 rc
= mutex_lock_interruptible(&fan_mutex
);
3636 switch (fan_control_access_mode
) {
3637 case TPACPI_FAN_WR_ACPI_FANS
:
3638 case TPACPI_FAN_WR_TPEC
:
3639 rc
= fan_get_status(&s
);
3643 /* Don't go out of emergency fan mode */
3646 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
3649 if (!acpi_ec_write(fan_status_offset
, s
))
3652 tp_features
.fan_ctrl_status_undef
= 0;
3657 case TPACPI_FAN_WR_ACPI_SFAN
:
3658 rc
= fan_get_status(&s
);
3664 /* Set fan to at least level 4 */
3667 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
3677 mutex_unlock(&fan_mutex
);
3681 static int fan_set_disable(void)
3685 if (!fan_control_allowed
)
3688 rc
= mutex_lock_interruptible(&fan_mutex
);
3693 switch (fan_control_access_mode
) {
3694 case TPACPI_FAN_WR_ACPI_FANS
:
3695 case TPACPI_FAN_WR_TPEC
:
3696 if (!acpi_ec_write(fan_status_offset
, 0x00))
3699 fan_control_desired_level
= 0;
3700 tp_features
.fan_ctrl_status_undef
= 0;
3704 case TPACPI_FAN_WR_ACPI_SFAN
:
3705 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
3708 fan_control_desired_level
= 0;
3716 mutex_unlock(&fan_mutex
);
3720 static int fan_set_speed(int speed
)
3724 if (!fan_control_allowed
)
3727 rc
= mutex_lock_interruptible(&fan_mutex
);
3732 switch (fan_control_access_mode
) {
3733 case TPACPI_FAN_WR_ACPI_FANS
:
3734 if (speed
>= 0 && speed
<= 65535) {
3735 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
3736 speed
, speed
, speed
))
3746 mutex_unlock(&fan_mutex
);
3750 static int fan_read(char *p
)
3755 unsigned int speed
= 0;
3757 switch (fan_status_access_mode
) {
3758 case TPACPI_FAN_RD_ACPI_GFAN
:
3759 /* 570, 600e/x, 770e, 770x */
3760 if ((rc
= fan_get_status_safe(&status
)) < 0)
3763 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
3765 (status
!= 0) ? "enabled" : "disabled", status
);
3768 case TPACPI_FAN_RD_TPEC
:
3769 /* all except 570, 600e/x, 770e, 770x */
3770 if ((rc
= fan_get_status_safe(&status
)) < 0)
3773 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3774 if (status
!= fan_control_initial_status
)
3775 tp_features
.fan_ctrl_status_undef
= 0;
3777 /* Return most likely status. In fact, it
3778 * might be the only possible status */
3779 status
= TP_EC_FAN_AUTO
;
3782 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3783 (status
!= 0) ? "enabled" : "disabled");
3785 if ((rc
= fan_get_speed(&speed
)) < 0)
3788 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
3790 if (status
& TP_EC_FAN_FULLSPEED
)
3791 /* Disengaged mode takes precedence */
3792 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
3793 else if (status
& TP_EC_FAN_AUTO
)
3794 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
3796 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
3799 case TPACPI_FAN_NONE
:
3801 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3804 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
3805 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
3807 switch (fan_control_access_mode
) {
3808 case TPACPI_FAN_WR_ACPI_SFAN
:
3809 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
3813 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
3814 "auto, disengaged, full-speed)\n");
3819 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
3820 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
3821 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
3822 "1-120 (seconds))\n");
3824 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
3825 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
3826 " (<speed> is 0-65535)\n");
3831 static int fan_write_cmd_level(const char *cmd
, int *rc
)
3835 if (strlencmp(cmd
, "level auto") == 0)
3836 level
= TP_EC_FAN_AUTO
;
3837 else if ((strlencmp(cmd
, "level disengaged") == 0) |
3838 (strlencmp(cmd
, "level full-speed") == 0))
3839 level
= TP_EC_FAN_FULLSPEED
;
3840 else if (sscanf(cmd
, "level %d", &level
) != 1)
3843 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
3844 printk(IBM_ERR
"level command accepted for unsupported "
3845 "access mode %d", fan_control_access_mode
);
3850 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
3852 if (strlencmp(cmd
, "enable") != 0)
3855 if ((*rc
= fan_set_enable()) == -ENXIO
)
3856 printk(IBM_ERR
"enable command accepted for unsupported "
3857 "access mode %d", fan_control_access_mode
);
3862 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
3864 if (strlencmp(cmd
, "disable") != 0)
3867 if ((*rc
= fan_set_disable()) == -ENXIO
)
3868 printk(IBM_ERR
"disable command accepted for unsupported "
3869 "access mode %d", fan_control_access_mode
);
3874 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
3879 * Support speed <low> <medium> <high> ? */
3881 if (sscanf(cmd
, "speed %d", &speed
) != 1)
3884 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
3885 printk(IBM_ERR
"speed command accepted for unsupported "
3886 "access mode %d", fan_control_access_mode
);
3891 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
3895 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
3898 if (interval
< 0 || interval
> 120)
3901 fan_watchdog_maxinterval
= interval
;
3906 static int fan_write(char *buf
)
3911 while (!rc
&& (cmd
= next_cmd(&buf
))) {
3912 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
3913 fan_write_cmd_level(cmd
, &rc
)) &&
3914 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
3915 (fan_write_cmd_enable(cmd
, &rc
) ||
3916 fan_write_cmd_disable(cmd
, &rc
) ||
3917 fan_write_cmd_watchdog(cmd
, &rc
))) &&
3918 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
3919 fan_write_cmd_speed(cmd
, &rc
))
3923 fan_watchdog_reset();
3929 static struct ibm_struct fan_driver_data
= {
3936 /****************************************************************************
3937 ****************************************************************************
3941 ****************************************************************************
3942 ****************************************************************************/
3945 static struct proc_dir_entry
*proc_dir
;
3947 /* Subdriver registry */
3948 static LIST_HEAD(tpacpi_all_drivers
);
3952 * Module and infrastructure proble, init and exit handling
3955 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
3956 static const char * __init
str_supported(int is_supported
)
3958 static char text_unsupported
[] __initdata
= "not supported";
3960 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
3962 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
3964 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
3967 struct ibm_struct
*ibm
= iibm
->data
;
3968 struct proc_dir_entry
*entry
;
3970 BUG_ON(ibm
== NULL
);
3972 INIT_LIST_HEAD(&ibm
->all_drivers
);
3974 if (ibm
->flags
.experimental
&& !experimental
)
3977 dbg_printk(TPACPI_DBG_INIT
,
3978 "probing for %s\n", ibm
->name
);
3981 ret
= iibm
->init(iibm
);
3983 return 0; /* probe failed */
3987 ibm
->flags
.init_called
= 1;
3991 if (ibm
->acpi
->hid
) {
3992 ret
= register_tpacpi_subdriver(ibm
);
3997 if (ibm
->acpi
->notify
) {
3998 ret
= setup_acpi_notify(ibm
);
3999 if (ret
== -ENODEV
) {
4000 printk(IBM_NOTICE
"disabling subdriver %s\n",
4010 dbg_printk(TPACPI_DBG_INIT
,
4011 "%s installed\n", ibm
->name
);
4014 entry
= create_proc_entry(ibm
->name
,
4015 S_IFREG
| S_IRUGO
| S_IWUSR
,
4018 printk(IBM_ERR
"unable to create proc entry %s\n",
4023 entry
->owner
= THIS_MODULE
;
4025 entry
->read_proc
= &dispatch_procfs_read
;
4027 entry
->write_proc
= &dispatch_procfs_write
;
4028 ibm
->flags
.proc_created
= 1;
4031 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4036 dbg_printk(TPACPI_DBG_INIT
,
4037 "%s: at error exit path with result %d\n",
4041 return (ret
< 0)? ret
: 0;
4044 static void ibm_exit(struct ibm_struct
*ibm
)
4046 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4048 list_del_init(&ibm
->all_drivers
);
4050 if (ibm
->flags
.acpi_notify_installed
) {
4051 dbg_printk(TPACPI_DBG_EXIT
,
4052 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4054 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4056 dispatch_acpi_notify
);
4057 ibm
->flags
.acpi_notify_installed
= 0;
4058 ibm
->flags
.acpi_notify_installed
= 0;
4061 if (ibm
->flags
.proc_created
) {
4062 dbg_printk(TPACPI_DBG_EXIT
,
4063 "%s: remove_proc_entry\n", ibm
->name
);
4064 remove_proc_entry(ibm
->name
, proc_dir
);
4065 ibm
->flags
.proc_created
= 0;
4068 if (ibm
->flags
.acpi_driver_registered
) {
4069 dbg_printk(TPACPI_DBG_EXIT
,
4070 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4072 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4073 kfree(ibm
->acpi
->driver
);
4074 ibm
->acpi
->driver
= NULL
;
4075 ibm
->flags
.acpi_driver_registered
= 0;
4078 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4080 ibm
->flags
.init_called
= 0;
4083 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4088 static char *ibm_thinkpad_ec_found
;
4090 static char* __init
check_dmi_for_ec(void)
4092 struct dmi_device
*dev
= NULL
;
4093 char ec_fw_string
[18];
4096 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4097 * X32 or newer, all Z series; Some models must have an
4098 * up-to-date BIOS or they will not be detected.
4100 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4102 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4103 if (sscanf(dev
->name
,
4104 "IBM ThinkPad Embedded Controller -[%17c",
4105 ec_fw_string
) == 1) {
4106 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4107 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4108 return kstrdup(ec_fw_string
, GFP_KERNEL
);
4114 static int __init
probe_for_thinkpad(void)
4122 * Non-ancient models have better DMI tagging, but very old models
4125 is_thinkpad
= dmi_name_in_vendors("ThinkPad");
4127 /* ec is required because many other handles are relative to it */
4128 IBM_ACPIHANDLE_INIT(ec
);
4132 "Not yet supported ThinkPad detected!\n");
4137 * Risks a regression on very old machines, but reduces potential
4138 * false positives a damn great deal
4141 is_thinkpad
= dmi_name_in_vendors("IBM");
4143 if (!is_thinkpad
&& !force_load
)
4150 /* Module init, exit, parameters */
4152 static struct ibm_init_struct ibms_init
[] __initdata
= {
4154 .init
= thinkpad_acpi_driver_init
,
4155 .data
= &thinkpad_acpi_driver_data
,
4158 .init
= hotkey_init
,
4159 .data
= &hotkey_driver_data
,
4162 .init
= bluetooth_init
,
4163 .data
= &bluetooth_driver_data
,
4167 .data
= &wan_driver_data
,
4171 .data
= &video_driver_data
,
4175 .data
= &light_driver_data
,
4177 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4180 .data
= &dock_driver_data
[0],
4184 .data
= &dock_driver_data
[1],
4187 #ifdef CONFIG_THINKPAD_ACPI_BAY
4190 .data
= &bay_driver_data
,
4195 .data
= &cmos_driver_data
,
4199 .data
= &led_driver_data
,
4203 .data
= &beep_driver_data
,
4206 .init
= thermal_init
,
4207 .data
= &thermal_driver_data
,
4210 .data
= &ecdump_driver_data
,
4213 .init
= brightness_init
,
4214 .data
= &brightness_driver_data
,
4217 .data
= &volume_driver_data
,
4221 .data
= &fan_driver_data
,
4225 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4228 struct ibm_struct
*ibm
;
4230 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4231 ibm
= ibms_init
[i
].data
;
4232 BUG_ON(ibm
== NULL
);
4234 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4235 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4237 strcpy(ibms_init
[i
].param
, val
);
4238 strcat(ibms_init
[i
].param
, ",");
4246 static int experimental
;
4247 module_param(experimental
, int, 0);
4249 static u32 dbg_level
;
4250 module_param_named(debug
, dbg_level
, uint
, 0);
4252 static int force_load
;
4253 module_param(force_load
, int, 0);
4255 static int fan_control_allowed
;
4256 module_param_named(fan_control
, fan_control_allowed
, int, 0);
4258 #define IBM_PARAM(feature) \
4259 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4262 IBM_PARAM(bluetooth
);
4265 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4268 #ifdef CONFIG_THINKPAD_ACPI_BAY
4270 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4275 IBM_PARAM(brightness
);
4279 static int __init
thinkpad_acpi_module_init(void)
4283 /* Driver-level probe */
4284 ret
= probe_for_thinkpad();
4288 /* Driver initialization */
4289 ibm_thinkpad_ec_found
= check_dmi_for_ec();
4290 IBM_ACPIHANDLE_INIT(ecrd
);
4291 IBM_ACPIHANDLE_INIT(ecwr
);
4293 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4295 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4296 thinkpad_acpi_module_exit();
4299 proc_dir
->owner
= THIS_MODULE
;
4301 ret
= platform_driver_register(&tpacpi_pdriver
);
4303 printk(IBM_ERR
"unable to register platform driver\n");
4304 thinkpad_acpi_module_exit();
4307 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4309 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4310 thinkpad_acpi_module_exit();
4315 /* Device initialization */
4316 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4318 if (IS_ERR(tpacpi_pdev
)) {
4319 ret
= PTR_ERR(tpacpi_pdev
);
4321 printk(IBM_ERR
"unable to register platform device\n");
4322 thinkpad_acpi_module_exit();
4325 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
4326 if (IS_ERR(tpacpi_hwmon
)) {
4327 ret
= PTR_ERR(tpacpi_hwmon
);
4328 tpacpi_hwmon
= NULL
;
4329 printk(IBM_ERR
"unable to register hwmon device\n");
4330 thinkpad_acpi_module_exit();
4333 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4334 ret
= ibm_init(&ibms_init
[i
]);
4335 if (ret
>= 0 && *ibms_init
[i
].param
)
4336 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
4338 thinkpad_acpi_module_exit();
4346 static void thinkpad_acpi_module_exit(void)
4348 struct ibm_struct
*ibm
, *itmp
;
4350 list_for_each_entry_safe_reverse(ibm
, itmp
,
4351 &tpacpi_all_drivers
,
4356 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
4359 hwmon_device_unregister(tpacpi_hwmon
);
4362 platform_device_unregister(tpacpi_pdev
);
4364 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
4365 platform_driver_unregister(&tpacpi_pdriver
);
4368 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
4370 kfree(ibm_thinkpad_ec_found
);
4373 module_init(thinkpad_acpi_module_init
);
4374 module_exit(thinkpad_acpi_module_exit
);