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.16"
25 #define TPACPI_SYSFS_VERSION 0x020000
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))
121 TPACPI_LIFE_INIT
= 0,
126 /****************************************************************************
127 ****************************************************************************
129 * ACPI Helpers and device model
131 ****************************************************************************
132 ****************************************************************************/
134 /*************************************************************************
138 static acpi_handle root_handle
;
140 #define IBM_HANDLE(object, parent, paths...) \
141 static acpi_handle object##_handle; \
142 static acpi_handle *object##_parent = &parent##_handle; \
143 static char *object##_path; \
144 static char *object##_paths[] = { paths }
146 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
147 "\\_SB.PCI.ISA.EC", /* 570 */
148 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
149 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
150 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
151 "\\_SB.PCI0.ICH3.EC0", /* R31 */
152 "\\_SB.PCI0.LPC.EC", /* all others */
155 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
156 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
159 /*************************************************************************
163 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
164 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
165 "\\CMS", /* R40, R40e */
168 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
169 "^HKEY", /* R30, R31 */
170 "HKEY", /* all others */
174 /*************************************************************************
178 static int acpi_evalf(acpi_handle handle
,
179 void *res
, char *method
, char *fmt
, ...)
182 struct acpi_object_list params
;
183 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
184 struct acpi_buffer result
, *resultp
;
185 union acpi_object out_obj
;
193 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
206 params
.pointer
= &in_objs
[0];
213 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
214 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
216 /* add more types as needed */
218 printk(IBM_ERR
"acpi_evalf() called "
219 "with invalid format character '%c'\n", c
);
225 if (res_type
!= 'v') {
226 result
.length
= sizeof(out_obj
);
227 result
.pointer
= &out_obj
;
232 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
237 *(int *)res
= out_obj
.integer
.value
;
238 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
241 success
= status
== AE_OK
;
243 /* add more types as needed */
245 printk(IBM_ERR
"acpi_evalf() called "
246 "with invalid format character '%c'\n", res_type
);
250 if (!success
&& !quiet
)
251 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
252 method
, fmt0
, status
);
257 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
261 if (acpi_evalf(handle
, &i
, method
, "d"))
262 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
264 printk(IBM_ERR
"error calling %s\n", method
);
267 static int acpi_ec_read(int i
, u8
* p
)
272 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
276 if (ec_read(i
, p
) < 0)
283 static int acpi_ec_write(int i
, u8 v
)
286 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
289 if (ec_write(i
, v
) < 0)
296 static int _sta(acpi_handle handle
)
300 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
306 static int issue_thinkpad_cmos_command(int cmos_cmd
)
311 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
317 /*************************************************************************
321 static void drv_acpi_handle_init(char *name
,
322 acpi_handle
*handle
, acpi_handle parent
,
323 char **paths
, int num_paths
, char **path
)
328 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
331 for (i
= 0; i
< num_paths
; i
++) {
332 status
= acpi_get_handle(parent
, paths
[i
], handle
);
333 if (ACPI_SUCCESS(status
)) {
335 dbg_printk(TPACPI_DBG_INIT
,
336 "Found ACPI handle %s for %s\n",
342 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
347 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
349 struct ibm_struct
*ibm
= data
;
351 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
354 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
357 ibm
->acpi
->notify(ibm
, event
);
360 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
367 if (!*ibm
->acpi
->handle
)
370 vdbg_printk(TPACPI_DBG_INIT
,
371 "setting up ACPI notify for %s\n", ibm
->name
);
373 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
375 printk(IBM_ERR
"acpi_bus_get_device(%s) failed: %d\n",
380 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
381 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
382 IBM_ACPI_EVENT_PREFIX
,
385 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
386 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
387 if (ACPI_FAILURE(status
)) {
388 if (status
== AE_ALREADY_EXISTS
) {
389 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
392 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
397 ibm
->flags
.acpi_notify_installed
= 1;
401 static int __init
tpacpi_device_add(struct acpi_device
*device
)
406 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
410 dbg_printk(TPACPI_DBG_INIT
,
411 "registering %s as an ACPI driver\n", ibm
->name
);
415 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
416 if (!ibm
->acpi
->driver
) {
417 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
421 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
422 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
424 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
426 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
428 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
430 kfree(ibm
->acpi
->driver
);
431 ibm
->acpi
->driver
= NULL
;
433 ibm
->flags
.acpi_driver_registered
= 1;
439 /****************************************************************************
440 ****************************************************************************
444 ****************************************************************************
445 ****************************************************************************/
447 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
448 int count
, int *eof
, void *data
)
450 struct ibm_struct
*ibm
= data
;
453 if (!ibm
|| !ibm
->read
)
456 len
= ibm
->read(page
);
460 if (len
<= off
+ count
)
472 static int dispatch_procfs_write(struct file
*file
,
473 const char __user
* userbuf
,
474 unsigned long count
, void *data
)
476 struct ibm_struct
*ibm
= data
;
480 if (!ibm
|| !ibm
->write
)
483 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
487 if (copy_from_user(kernbuf
, userbuf
, count
)) {
493 strcat(kernbuf
, ",");
494 ret
= ibm
->write(kernbuf
);
503 static char *next_cmd(char **cmds
)
508 while ((end
= strchr(start
, ',')) && end
== start
)
520 /****************************************************************************
521 ****************************************************************************
523 * Device model: input, hwmon and platform
525 ****************************************************************************
526 ****************************************************************************/
528 static struct platform_device
*tpacpi_pdev
;
529 static struct platform_device
*tpacpi_sensors_pdev
;
530 static struct device
*tpacpi_hwmon
;
531 static struct input_dev
*tpacpi_inputdev
;
532 static struct mutex tpacpi_inputdev_send_mutex
;
535 static int tpacpi_resume_handler(struct platform_device
*pdev
)
537 struct ibm_struct
*ibm
, *itmp
;
539 list_for_each_entry_safe(ibm
, itmp
,
549 static struct platform_driver tpacpi_pdriver
= {
551 .name
= IBM_DRVR_NAME
,
552 .owner
= THIS_MODULE
,
554 .resume
= tpacpi_resume_handler
,
557 static struct platform_driver tpacpi_hwmon_pdriver
= {
559 .name
= IBM_HWMON_DRVR_NAME
,
560 .owner
= THIS_MODULE
,
564 /*************************************************************************
565 * thinkpad-acpi driver attributes
568 /* interface_version --------------------------------------------------- */
569 static ssize_t
tpacpi_driver_interface_version_show(
570 struct device_driver
*drv
,
573 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
576 static DRIVER_ATTR(interface_version
, S_IRUGO
,
577 tpacpi_driver_interface_version_show
, NULL
);
579 /* debug_level --------------------------------------------------------- */
580 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
583 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
586 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
587 const char *buf
, size_t count
)
591 if (parse_strtoul(buf
, 0xffff, &t
))
599 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
600 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
602 /* version ------------------------------------------------------------- */
603 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
606 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
609 static DRIVER_ATTR(version
, S_IRUGO
,
610 tpacpi_driver_version_show
, NULL
);
612 /* --------------------------------------------------------------------- */
614 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
615 &driver_attr_debug_level
, &driver_attr_version
,
616 &driver_attr_interface_version
,
619 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
625 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
626 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
633 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
637 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
638 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
641 /*************************************************************************
642 * sysfs support helpers
645 struct attribute_set_obj
{
646 struct attribute_set s
;
648 } __attribute__((packed
));
650 static struct attribute_set
*create_attr_set(unsigned int max_members
,
653 struct attribute_set_obj
*sobj
;
655 if (max_members
== 0)
658 /* Allocates space for implicit NULL at the end too */
659 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
660 max_members
* sizeof(struct attribute
*),
664 sobj
->s
.max_members
= max_members
;
665 sobj
->s
.group
.attrs
= &sobj
->a
;
666 sobj
->s
.group
.name
= name
;
671 /* not multi-threaded safe, use it in a single thread per set */
672 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
677 if (s
->members
>= s
->max_members
)
680 s
->group
.attrs
[s
->members
] = attr
;
686 static int add_many_to_attr_set(struct attribute_set
* s
,
687 struct attribute
**attr
,
692 for (i
= 0; i
< count
; i
++) {
693 res
= add_to_attr_set(s
, attr
[i
]);
701 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
703 sysfs_remove_group(kobj
, &s
->group
);
707 static int parse_strtoul(const char *buf
,
708 unsigned long max
, unsigned long *value
)
712 while (*buf
&& isspace(*buf
))
714 *value
= simple_strtoul(buf
, &endp
, 0);
715 while (*endp
&& isspace(*endp
))
717 if (*endp
|| *value
> max
)
723 /****************************************************************************
724 ****************************************************************************
728 ****************************************************************************
729 ****************************************************************************/
731 /*************************************************************************
732 * thinkpad-acpi init subdriver
735 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
737 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
738 printk(IBM_INFO
"%s\n", IBM_URL
);
740 printk(IBM_INFO
"ThinkPad BIOS %s, EC %s\n",
741 (thinkpad_id
.bios_version_str
) ?
742 thinkpad_id
.bios_version_str
: "unknown",
743 (thinkpad_id
.ec_version_str
) ?
744 thinkpad_id
.ec_version_str
: "unknown");
746 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
747 printk(IBM_INFO
"%s %s\n",
748 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
749 "IBM" : ((thinkpad_id
.vendor
==
750 PCI_VENDOR_ID_LENOVO
) ?
751 "Lenovo" : "Unknown vendor"),
752 thinkpad_id
.model_str
);
757 static int thinkpad_acpi_driver_read(char *p
)
761 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
762 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
767 static struct ibm_struct thinkpad_acpi_driver_data
= {
769 .read
= thinkpad_acpi_driver_read
,
772 /*************************************************************************
776 static int hotkey_orig_status
;
777 static u32 hotkey_orig_mask
;
778 static u32 hotkey_all_mask
;
779 static u32 hotkey_reserved_mask
;
781 static u16
*hotkey_keycode_map
;
783 static struct attribute_set
*hotkey_dev_attributes
;
785 static int hotkey_get_wlsw(int *status
)
787 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
792 /* sysfs hotkey enable ------------------------------------------------- */
793 static ssize_t
hotkey_enable_show(struct device
*dev
,
794 struct device_attribute
*attr
,
800 res
= hotkey_get(&status
, &mask
);
804 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
807 static ssize_t
hotkey_enable_store(struct device
*dev
,
808 struct device_attribute
*attr
,
809 const char *buf
, size_t count
)
815 if (parse_strtoul(buf
, 1, &t
))
818 res
= hotkey_get(&status
, &mask
);
820 res
= hotkey_set(t
, mask
);
822 return (res
) ? res
: count
;
825 static struct device_attribute dev_attr_hotkey_enable
=
826 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
827 hotkey_enable_show
, hotkey_enable_store
);
829 /* sysfs hotkey mask --------------------------------------------------- */
830 static ssize_t
hotkey_mask_show(struct device
*dev
,
831 struct device_attribute
*attr
,
837 res
= hotkey_get(&status
, &mask
);
841 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
844 static ssize_t
hotkey_mask_store(struct device
*dev
,
845 struct device_attribute
*attr
,
846 const char *buf
, size_t count
)
852 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
855 res
= hotkey_get(&status
, &mask
);
857 hotkey_set(status
, t
);
859 return (res
) ? res
: count
;
862 static struct device_attribute dev_attr_hotkey_mask
=
863 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
864 hotkey_mask_show
, hotkey_mask_store
);
866 /* sysfs hotkey bios_enabled ------------------------------------------- */
867 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
868 struct device_attribute
*attr
,
871 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
874 static struct device_attribute dev_attr_hotkey_bios_enabled
=
875 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
877 /* sysfs hotkey bios_mask ---------------------------------------------- */
878 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
879 struct device_attribute
*attr
,
882 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
885 static struct device_attribute dev_attr_hotkey_bios_mask
=
886 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
888 /* sysfs hotkey all_mask ----------------------------------------------- */
889 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
890 struct device_attribute
*attr
,
893 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_all_mask
);
896 static struct device_attribute dev_attr_hotkey_all_mask
=
897 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
899 /* sysfs hotkey recommended_mask --------------------------------------- */
900 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
901 struct device_attribute
*attr
,
904 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
905 hotkey_all_mask
& ~hotkey_reserved_mask
);
908 static struct device_attribute dev_attr_hotkey_recommended_mask
=
909 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
910 hotkey_recommended_mask_show
, NULL
);
912 /* sysfs hotkey radio_sw ----------------------------------------------- */
913 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
914 struct device_attribute
*attr
,
918 res
= hotkey_get_wlsw(&s
);
922 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
925 static struct device_attribute dev_attr_hotkey_radio_sw
=
926 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
928 /* sysfs hotkey report_mode -------------------------------------------- */
929 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
930 struct device_attribute
*attr
,
933 return snprintf(buf
, PAGE_SIZE
, "%d\n",
934 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
937 static struct device_attribute dev_attr_hotkey_report_mode
=
938 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
940 /* --------------------------------------------------------------------- */
942 static struct attribute
*hotkey_attributes
[] __initdata
= {
943 &dev_attr_hotkey_enable
.attr
,
944 &dev_attr_hotkey_report_mode
.attr
,
947 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
948 &dev_attr_hotkey_mask
.attr
,
949 &dev_attr_hotkey_bios_enabled
.attr
,
950 &dev_attr_hotkey_bios_mask
.attr
,
951 &dev_attr_hotkey_all_mask
.attr
,
952 &dev_attr_hotkey_recommended_mask
.attr
,
955 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
958 static u16 ibm_keycode_map
[] __initdata
= {
959 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
960 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
961 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
962 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
963 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
964 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
965 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
966 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
967 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
968 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
969 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
970 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
971 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
972 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
973 KEY_VOLUMEUP
, /* 0x14: VOLUME UP */
974 KEY_VOLUMEDOWN
, /* 0x15: VOLUME DOWN */
975 KEY_MUTE
, /* 0x16: MUTE */
976 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
977 /* (assignments unknown, please report if found) */
978 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
979 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
981 static u16 lenovo_keycode_map
[] __initdata
= {
982 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
983 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
984 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
985 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
986 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
987 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
988 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
989 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
990 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
991 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
992 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
993 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
994 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
995 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
996 KEY_VOLUMEUP
, /* 0x14: VOLUME UP */
997 KEY_VOLUMEDOWN
, /* 0x15: VOLUME DOWN */
998 KEY_MUTE
, /* 0x16: MUTE */
999 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1000 /* (assignments unknown, please report if found) */
1001 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1002 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1005 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1006 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1007 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1013 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1015 BUG_ON(!tpacpi_inputdev
);
1017 IBM_ACPIHANDLE_INIT(hkey
);
1018 mutex_init(&hotkey_mutex
);
1020 /* hotkey not supported on 570 */
1021 tp_features
.hotkey
= hkey_handle
!= NULL
;
1023 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1024 str_supported(tp_features
.hotkey
));
1026 if (tp_features
.hotkey
) {
1027 hotkey_dev_attributes
= create_attr_set(8, NULL
);
1028 if (!hotkey_dev_attributes
)
1030 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1032 ARRAY_SIZE(hotkey_attributes
));
1036 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1037 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1038 for HKEY interface version 0x100 */
1039 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1040 if ((hkeyv
>> 8) != 1) {
1041 printk(IBM_ERR
"unknown version of the "
1042 "HKEY interface: 0x%x\n", hkeyv
);
1043 printk(IBM_ERR
"please report this to %s\n",
1047 * MHKV 0x100 in A31, R40, R40e,
1048 * T4x, X31, and later
1050 tp_features
.hotkey_mask
= 1;
1054 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1055 str_supported(tp_features
.hotkey_mask
));
1057 if (tp_features
.hotkey_mask
) {
1058 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1061 "missing MHKA handler, "
1062 "please report this to %s\n",
1064 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
1068 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
1069 if (!res
&& tp_features
.hotkey_mask
) {
1070 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1071 hotkey_mask_attributes
,
1072 ARRAY_SIZE(hotkey_mask_attributes
));
1075 /* Not all thinkpads have a hardware radio switch */
1076 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1077 tp_features
.hotkey_wlsw
= 1;
1079 "radio switch found; radios are %s\n",
1080 enabled(status
, 0));
1081 res
= add_to_attr_set(hotkey_dev_attributes
,
1082 &dev_attr_hotkey_radio_sw
.attr
);
1086 res
= register_attr_set_with_sysfs(
1087 hotkey_dev_attributes
,
1088 &tpacpi_pdev
->dev
.kobj
);
1092 /* Set up key map */
1094 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1096 if (!hotkey_keycode_map
) {
1097 printk(IBM_ERR
"failed to allocate memory for key map\n");
1101 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1102 dbg_printk(TPACPI_DBG_INIT
,
1103 "using Lenovo default hot key map\n");
1104 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1105 TPACPI_HOTKEY_MAP_SIZE
);
1107 dbg_printk(TPACPI_DBG_INIT
,
1108 "using IBM default hot key map\n");
1109 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1110 TPACPI_HOTKEY_MAP_SIZE
);
1113 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1114 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1115 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1116 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1117 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1118 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1119 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1120 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1121 set_bit(hotkey_keycode_map
[i
],
1122 tpacpi_inputdev
->keybit
);
1124 if (i
< sizeof(hotkey_reserved_mask
)*8)
1125 hotkey_reserved_mask
|= 1 << i
;
1129 if (tp_features
.hotkey_wlsw
) {
1130 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1131 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1134 dbg_printk(TPACPI_DBG_INIT
,
1135 "enabling hot key handling\n");
1136 res
= hotkey_set(1, (hotkey_all_mask
& ~hotkey_reserved_mask
)
1137 | hotkey_orig_mask
);
1141 dbg_printk(TPACPI_DBG_INIT
,
1142 "legacy hot key reporting over procfs %s\n",
1143 (hotkey_report_mode
< 2) ?
1144 "enabled" : "disabled");
1147 return (tp_features
.hotkey
)? 0 : 1;
1150 static void hotkey_exit(void)
1154 if (tp_features
.hotkey
) {
1155 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
1156 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
1158 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
1161 if (hotkey_dev_attributes
) {
1162 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1163 hotkey_dev_attributes
= NULL
;
1167 static void tpacpi_input_send_key(unsigned int scancode
,
1168 unsigned int keycode
)
1170 if (keycode
!= KEY_RESERVED
) {
1171 mutex_lock(&tpacpi_inputdev_send_mutex
);
1173 input_report_key(tpacpi_inputdev
, keycode
, 1);
1174 if (keycode
== KEY_UNKNOWN
)
1175 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1177 input_sync(tpacpi_inputdev
);
1179 input_report_key(tpacpi_inputdev
, keycode
, 0);
1180 if (keycode
== KEY_UNKNOWN
)
1181 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1183 input_sync(tpacpi_inputdev
);
1185 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1189 static void tpacpi_input_send_radiosw(void)
1193 mutex_lock(&tpacpi_inputdev_send_mutex
);
1195 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1196 input_report_switch(tpacpi_inputdev
,
1198 input_sync(tpacpi_inputdev
);
1201 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1204 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1207 unsigned int keycode
, scancode
;
1211 if (event
!= 0x80) {
1212 printk(IBM_ERR
"unknown HKEY notification event %d\n", event
);
1213 /* forward it to userspace, maybe it knows how to handle it */
1214 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
1215 ibm
->acpi
->device
->dev
.bus_id
,
1221 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1222 printk(IBM_ERR
"failed to retrieve HKEY event\n");
1234 switch (hkey
>> 12) {
1236 /* 0x1000-0x1FFF: key presses */
1237 scancode
= hkey
& 0xfff;
1238 if (scancode
> 0 && scancode
< 0x21) {
1240 keycode
= hotkey_keycode_map
[scancode
];
1241 tpacpi_input_send_key(scancode
, keycode
);
1244 "hotkey 0x%04x out of range for keyboard map\n",
1250 /* 0x5000-0x5FFF: LID */
1251 /* we don't handle it through this path, just
1252 * eat up known LID events */
1253 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1255 "unknown LID-related HKEY event: 0x%04x\n",
1263 /* 0x7000-0x7FFF: misc */
1264 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1265 tpacpi_input_send_radiosw();
1268 /* fallthrough to default */
1270 /* case 2: dock-related */
1271 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1272 /* case 3: ultra-bay related. maybe bay in dock? */
1273 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1274 printk(IBM_NOTICE
"unhandled HKEY event 0x%04x\n", hkey
);
1279 if (!ignore_acpi_ev
&& (send_acpi_ev
|| hotkey_report_mode
< 2)) {
1280 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, hkey
);
1283 /* netlink events */
1284 if (!ignore_acpi_ev
&& send_acpi_ev
) {
1285 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
1286 ibm
->acpi
->device
->dev
.bus_id
,
1292 static void hotkey_resume(void)
1294 tpacpi_input_send_radiosw();
1298 * Call with hotkey_mutex held
1300 static int hotkey_get(int *status
, u32
*mask
)
1302 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1305 if (tp_features
.hotkey_mask
)
1306 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1313 * Call with hotkey_mutex held
1315 static int hotkey_set(int status
, u32 mask
)
1319 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1322 if (tp_features
.hotkey_mask
)
1323 for (i
= 0; i
< 32; i
++) {
1324 int bit
= ((1 << i
) & mask
) != 0;
1325 if (!acpi_evalf(hkey_handle
,
1326 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1333 /* procfs -------------------------------------------------------------- */
1334 static int hotkey_read(char *p
)
1340 if (!tp_features
.hotkey
) {
1341 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1345 res
= mutex_lock_interruptible(&hotkey_mutex
);
1348 res
= hotkey_get(&status
, &mask
);
1349 mutex_unlock(&hotkey_mutex
);
1353 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1354 if (tp_features
.hotkey_mask
) {
1355 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1356 len
+= sprintf(p
+ len
,
1357 "commands:\tenable, disable, reset, <mask>\n");
1359 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1360 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1366 static int hotkey_write(char *buf
)
1373 if (!tp_features
.hotkey
)
1376 res
= mutex_lock_interruptible(&hotkey_mutex
);
1380 res
= hotkey_get(&status
, &mask
);
1385 while ((cmd
= next_cmd(&buf
))) {
1386 if (strlencmp(cmd
, "enable") == 0) {
1388 } else if (strlencmp(cmd
, "disable") == 0) {
1390 } else if (strlencmp(cmd
, "reset") == 0) {
1391 status
= hotkey_orig_status
;
1392 mask
= hotkey_orig_mask
;
1393 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1395 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1405 res
= hotkey_set(status
, mask
);
1408 mutex_unlock(&hotkey_mutex
);
1412 static const struct acpi_device_id ibm_htk_device_ids
[] = {
1417 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1418 .hid
= ibm_htk_device_ids
,
1419 .notify
= hotkey_notify
,
1420 .handle
= &hkey_handle
,
1421 .type
= ACPI_DEVICE_NOTIFY
,
1424 static struct ibm_struct hotkey_driver_data
= {
1426 .read
= hotkey_read
,
1427 .write
= hotkey_write
,
1428 .exit
= hotkey_exit
,
1429 .resume
= hotkey_resume
,
1430 .acpi
= &ibm_hotkey_acpidriver
,
1433 /*************************************************************************
1434 * Bluetooth subdriver
1437 /* sysfs bluetooth enable ---------------------------------------------- */
1438 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1439 struct device_attribute
*attr
,
1444 status
= bluetooth_get_radiosw();
1448 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1451 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1452 struct device_attribute
*attr
,
1453 const char *buf
, size_t count
)
1458 if (parse_strtoul(buf
, 1, &t
))
1461 res
= bluetooth_set_radiosw(t
);
1463 return (res
) ? res
: count
;
1466 static struct device_attribute dev_attr_bluetooth_enable
=
1467 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1468 bluetooth_enable_show
, bluetooth_enable_store
);
1470 /* --------------------------------------------------------------------- */
1472 static struct attribute
*bluetooth_attributes
[] = {
1473 &dev_attr_bluetooth_enable
.attr
,
1477 static const struct attribute_group bluetooth_attr_group
= {
1478 .attrs
= bluetooth_attributes
,
1481 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1486 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1488 IBM_ACPIHANDLE_INIT(hkey
);
1490 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1491 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1492 tp_features
.bluetooth
= hkey_handle
&&
1493 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1495 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1496 str_supported(tp_features
.bluetooth
),
1499 if (tp_features
.bluetooth
) {
1500 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1501 /* no bluetooth hardware present in system */
1502 tp_features
.bluetooth
= 0;
1503 dbg_printk(TPACPI_DBG_INIT
,
1504 "bluetooth hardware not installed\n");
1506 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1507 &bluetooth_attr_group
);
1513 return (tp_features
.bluetooth
)? 0 : 1;
1516 static void bluetooth_exit(void)
1518 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1519 &bluetooth_attr_group
);
1522 static int bluetooth_get_radiosw(void)
1526 if (!tp_features
.bluetooth
)
1529 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1532 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1535 static int bluetooth_set_radiosw(int radio_on
)
1539 if (!tp_features
.bluetooth
)
1542 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1545 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1547 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1548 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1554 /* procfs -------------------------------------------------------------- */
1555 static int bluetooth_read(char *p
)
1558 int status
= bluetooth_get_radiosw();
1560 if (!tp_features
.bluetooth
)
1561 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1563 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1564 (status
)? "enabled" : "disabled");
1565 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1571 static int bluetooth_write(char *buf
)
1575 if (!tp_features
.bluetooth
)
1578 while ((cmd
= next_cmd(&buf
))) {
1579 if (strlencmp(cmd
, "enable") == 0) {
1580 bluetooth_set_radiosw(1);
1581 } else if (strlencmp(cmd
, "disable") == 0) {
1582 bluetooth_set_radiosw(0);
1590 static struct ibm_struct bluetooth_driver_data
= {
1591 .name
= "bluetooth",
1592 .read
= bluetooth_read
,
1593 .write
= bluetooth_write
,
1594 .exit
= bluetooth_exit
,
1597 /*************************************************************************
1601 /* sysfs wan enable ---------------------------------------------------- */
1602 static ssize_t
wan_enable_show(struct device
*dev
,
1603 struct device_attribute
*attr
,
1608 status
= wan_get_radiosw();
1612 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1615 static ssize_t
wan_enable_store(struct device
*dev
,
1616 struct device_attribute
*attr
,
1617 const char *buf
, size_t count
)
1622 if (parse_strtoul(buf
, 1, &t
))
1625 res
= wan_set_radiosw(t
);
1627 return (res
) ? res
: count
;
1630 static struct device_attribute dev_attr_wan_enable
=
1631 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1632 wan_enable_show
, wan_enable_store
);
1634 /* --------------------------------------------------------------------- */
1636 static struct attribute
*wan_attributes
[] = {
1637 &dev_attr_wan_enable
.attr
,
1641 static const struct attribute_group wan_attr_group
= {
1642 .attrs
= wan_attributes
,
1645 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1650 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1652 IBM_ACPIHANDLE_INIT(hkey
);
1654 tp_features
.wan
= hkey_handle
&&
1655 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1657 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1658 str_supported(tp_features
.wan
),
1661 if (tp_features
.wan
) {
1662 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1663 /* no wan hardware present in system */
1664 tp_features
.wan
= 0;
1665 dbg_printk(TPACPI_DBG_INIT
,
1666 "wan hardware not installed\n");
1668 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1675 return (tp_features
.wan
)? 0 : 1;
1678 static void wan_exit(void)
1680 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1684 static int wan_get_radiosw(void)
1688 if (!tp_features
.wan
)
1691 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1694 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1697 static int wan_set_radiosw(int radio_on
)
1701 if (!tp_features
.wan
)
1704 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1707 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1709 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1710 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1716 /* procfs -------------------------------------------------------------- */
1717 static int wan_read(char *p
)
1720 int status
= wan_get_radiosw();
1722 if (!tp_features
.wan
)
1723 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1725 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1726 (status
)? "enabled" : "disabled");
1727 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1733 static int wan_write(char *buf
)
1737 if (!tp_features
.wan
)
1740 while ((cmd
= next_cmd(&buf
))) {
1741 if (strlencmp(cmd
, "enable") == 0) {
1743 } else if (strlencmp(cmd
, "disable") == 0) {
1752 static struct ibm_struct wan_driver_data
= {
1757 .flags
.experimental
= 1,
1760 /*************************************************************************
1764 static enum video_access_mode video_supported
;
1765 static int video_orig_autosw
;
1767 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1768 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1769 "\\_SB.PCI0.VID0", /* 770e */
1770 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1771 "\\_SB.PCI0.AGP.VID", /* all others */
1774 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1776 static int __init
video_init(struct ibm_init_struct
*iibm
)
1780 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1782 IBM_ACPIHANDLE_INIT(vid
);
1783 IBM_ACPIHANDLE_INIT(vid2
);
1785 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1786 /* G41, assume IVGA doesn't change */
1787 vid_handle
= vid2_handle
;
1790 /* video switching not supported on R30, R31 */
1791 video_supported
= TPACPI_VIDEO_NONE
;
1792 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1794 video_supported
= TPACPI_VIDEO_570
;
1795 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1796 /* 600e/x, 770e, 770x */
1797 video_supported
= TPACPI_VIDEO_770
;
1800 video_supported
= TPACPI_VIDEO_NEW
;
1802 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1803 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1806 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1809 static void video_exit(void)
1811 dbg_printk(TPACPI_DBG_EXIT
,
1812 "restoring original video autoswitch mode\n");
1813 if (video_autosw_set(video_orig_autosw
))
1814 printk(IBM_ERR
"error while trying to restore original "
1815 "video autoswitch mode\n");
1818 static int video_outputsw_get(void)
1823 switch (video_supported
) {
1824 case TPACPI_VIDEO_570
:
1825 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1826 TP_ACPI_VIDEO_570_PHSCMD
))
1828 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1830 case TPACPI_VIDEO_770
:
1831 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1834 status
|= TP_ACPI_VIDEO_S_LCD
;
1835 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1838 status
|= TP_ACPI_VIDEO_S_CRT
;
1840 case TPACPI_VIDEO_NEW
:
1841 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1842 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1845 status
|= TP_ACPI_VIDEO_S_CRT
;
1847 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1848 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1851 status
|= TP_ACPI_VIDEO_S_LCD
;
1852 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1855 status
|= TP_ACPI_VIDEO_S_DVI
;
1864 static int video_outputsw_set(int status
)
1869 switch (video_supported
) {
1870 case TPACPI_VIDEO_570
:
1871 res
= acpi_evalf(NULL
, NULL
,
1872 "\\_SB.PHS2", "vdd",
1873 TP_ACPI_VIDEO_570_PHS2CMD
,
1874 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1876 case TPACPI_VIDEO_770
:
1877 autosw
= video_autosw_get();
1881 res
= video_autosw_set(1);
1884 res
= acpi_evalf(vid_handle
, NULL
,
1885 "ASWT", "vdd", status
* 0x100, 0);
1886 if (!autosw
&& video_autosw_set(autosw
)) {
1887 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1891 case TPACPI_VIDEO_NEW
:
1892 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1893 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1899 return (res
)? 0 : -EIO
;
1902 static int video_autosw_get(void)
1906 switch (video_supported
) {
1907 case TPACPI_VIDEO_570
:
1908 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1911 case TPACPI_VIDEO_770
:
1912 case TPACPI_VIDEO_NEW
:
1913 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1923 static int video_autosw_set(int enable
)
1925 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1930 static int video_outputsw_cycle(void)
1932 int autosw
= video_autosw_get();
1938 switch (video_supported
) {
1939 case TPACPI_VIDEO_570
:
1940 res
= video_autosw_set(1);
1943 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1945 case TPACPI_VIDEO_770
:
1946 case TPACPI_VIDEO_NEW
:
1947 res
= video_autosw_set(1);
1950 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1955 if (!autosw
&& video_autosw_set(autosw
)) {
1956 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1960 return (res
)? 0 : -EIO
;
1963 static int video_expand_toggle(void)
1965 switch (video_supported
) {
1966 case TPACPI_VIDEO_570
:
1967 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1969 case TPACPI_VIDEO_770
:
1970 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1972 case TPACPI_VIDEO_NEW
:
1973 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1981 static int video_read(char *p
)
1986 if (video_supported
== TPACPI_VIDEO_NONE
) {
1987 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1991 status
= video_outputsw_get();
1995 autosw
= video_autosw_get();
1999 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2000 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2001 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2002 if (video_supported
== TPACPI_VIDEO_NEW
)
2003 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2004 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2005 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2006 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2007 if (video_supported
== TPACPI_VIDEO_NEW
)
2008 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2009 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2010 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2015 static int video_write(char *buf
)
2018 int enable
, disable
, status
;
2021 if (video_supported
== TPACPI_VIDEO_NONE
)
2027 while ((cmd
= next_cmd(&buf
))) {
2028 if (strlencmp(cmd
, "lcd_enable") == 0) {
2029 enable
|= TP_ACPI_VIDEO_S_LCD
;
2030 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2031 disable
|= TP_ACPI_VIDEO_S_LCD
;
2032 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2033 enable
|= TP_ACPI_VIDEO_S_CRT
;
2034 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2035 disable
|= TP_ACPI_VIDEO_S_CRT
;
2036 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2037 strlencmp(cmd
, "dvi_enable") == 0) {
2038 enable
|= TP_ACPI_VIDEO_S_DVI
;
2039 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2040 strlencmp(cmd
, "dvi_disable") == 0) {
2041 disable
|= TP_ACPI_VIDEO_S_DVI
;
2042 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2043 res
= video_autosw_set(1);
2046 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2047 res
= video_autosw_set(0);
2050 } else if (strlencmp(cmd
, "video_switch") == 0) {
2051 res
= video_outputsw_cycle();
2054 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2055 res
= video_expand_toggle();
2062 if (enable
|| disable
) {
2063 status
= video_outputsw_get();
2066 res
= video_outputsw_set((status
& ~disable
) | enable
);
2074 static struct ibm_struct video_driver_data
= {
2077 .write
= video_write
,
2081 /*************************************************************************
2082 * Light (thinklight) subdriver
2085 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2086 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2088 static int __init
light_init(struct ibm_init_struct
*iibm
)
2090 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2092 IBM_ACPIHANDLE_INIT(ledb
);
2093 IBM_ACPIHANDLE_INIT(lght
);
2094 IBM_ACPIHANDLE_INIT(cmos
);
2096 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2097 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2099 if (tp_features
.light
)
2100 /* light status not supported on
2101 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2102 tp_features
.light_status
=
2103 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2105 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2106 str_supported(tp_features
.light
));
2108 return (tp_features
.light
)? 0 : 1;
2111 static int light_read(char *p
)
2116 if (!tp_features
.light
) {
2117 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2118 } else if (!tp_features
.light_status
) {
2119 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2120 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2122 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2124 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2125 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2131 static int light_write(char *buf
)
2133 int cmos_cmd
, lght_cmd
;
2137 if (!tp_features
.light
)
2140 while ((cmd
= next_cmd(&buf
))) {
2141 if (strlencmp(cmd
, "on") == 0) {
2144 } else if (strlencmp(cmd
, "off") == 0) {
2150 success
= cmos_handle
?
2151 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2152 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2160 static struct ibm_struct light_driver_data
= {
2163 .write
= light_write
,
2166 /*************************************************************************
2170 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2172 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2173 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2174 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2175 "\\_SB.PCI.ISA.SLCE", /* 570 */
2176 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2178 /* don't list other alternatives as we install a notify handler on the 570 */
2179 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2181 static const struct acpi_device_id ibm_pci_device_ids
[] = {
2182 {PCI_ROOT_HID_STRING
, 0},
2186 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2188 .notify
= dock_notify
,
2189 .handle
= &dock_handle
,
2190 .type
= ACPI_SYSTEM_NOTIFY
,
2193 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2194 * We just use it to get notifications of dock hotplug
2195 * in very old thinkpads */
2196 .hid
= ibm_pci_device_ids
,
2197 .notify
= dock_notify
,
2198 .handle
= &pci_handle
,
2199 .type
= ACPI_SYSTEM_NOTIFY
,
2203 static struct ibm_struct dock_driver_data
[2] = {
2207 .write
= dock_write
,
2208 .acpi
= &ibm_dock_acpidriver
[0],
2212 .acpi
= &ibm_dock_acpidriver
[1],
2216 #define dock_docked() (_sta(dock_handle) & 1)
2218 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2220 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2222 IBM_ACPIHANDLE_INIT(dock
);
2224 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2225 str_supported(dock_handle
!= NULL
));
2227 return (dock_handle
)? 0 : 1;
2230 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2234 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2236 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2237 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2238 IBM_ACPIHANDLE_INIT(pci
);
2239 dock2_needed
= (pci_handle
!= NULL
);
2240 vdbg_printk(TPACPI_DBG_INIT
,
2241 "dock PCI handler for the TP 570 is %s\n",
2242 str_supported(dock2_needed
));
2244 vdbg_printk(TPACPI_DBG_INIT
,
2245 "dock subdriver part 2 not required\n");
2249 return (dock2_needed
)? 0 : 1;
2252 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2254 int docked
= dock_docked();
2255 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
2256 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
2259 if (event
== 1 && !pci
) /* 570 */
2260 data
= 1; /* button */
2261 else if (event
== 1 && pci
) /* 570 */
2262 data
= 3; /* dock */
2263 else if (event
== 3 && docked
)
2264 data
= 1; /* button */
2265 else if (event
== 3 && !docked
)
2266 data
= 2; /* undock */
2267 else if (event
== 0 && docked
)
2268 data
= 3; /* dock */
2270 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2271 event
, _sta(dock_handle
));
2272 data
= 0; /* unknown */
2274 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
2275 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
2276 ibm
->acpi
->device
->dev
.bus_id
,
2280 static int dock_read(char *p
)
2283 int docked
= dock_docked();
2286 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2288 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2290 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2291 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2297 static int dock_write(char *buf
)
2304 while ((cmd
= next_cmd(&buf
))) {
2305 if (strlencmp(cmd
, "undock") == 0) {
2306 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2307 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2309 } else if (strlencmp(cmd
, "dock") == 0) {
2310 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2319 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2321 /*************************************************************************
2325 #ifdef CONFIG_THINKPAD_ACPI_BAY
2326 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2327 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2328 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2329 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2330 ); /* A21e, R30, R31 */
2331 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2332 "_EJ0", /* all others */
2333 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2334 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2335 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2337 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2341 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2343 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2345 IBM_ACPIHANDLE_INIT(bay
);
2347 IBM_ACPIHANDLE_INIT(bay_ej
);
2348 IBM_ACPIHANDLE_INIT(bay2
);
2350 IBM_ACPIHANDLE_INIT(bay2_ej
);
2352 tp_features
.bay_status
= bay_handle
&&
2353 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2354 tp_features
.bay_status2
= bay2_handle
&&
2355 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2357 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2358 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2359 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2360 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2362 vdbg_printk(TPACPI_DBG_INIT
,
2363 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2364 str_supported(tp_features
.bay_status
),
2365 str_supported(tp_features
.bay_eject
),
2366 str_supported(tp_features
.bay_status2
),
2367 str_supported(tp_features
.bay_eject2
));
2369 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2370 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2373 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2375 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
2376 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
2377 ibm
->acpi
->device
->dev
.bus_id
,
2381 #define bay_occupied(b) (_sta(b##_handle) & 1)
2383 static int bay_read(char *p
)
2386 int occupied
= bay_occupied(bay
);
2387 int occupied2
= bay_occupied(bay2
);
2390 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2391 tp_features
.bay_status
?
2392 (occupied
? "occupied" : "unoccupied") :
2394 if (tp_features
.bay_status2
)
2395 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2396 "occupied" : "unoccupied");
2398 eject
= tp_features
.bay_eject
&& occupied
;
2399 eject2
= tp_features
.bay_eject2
&& occupied2
;
2401 if (eject
&& eject2
)
2402 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2404 len
+= sprintf(p
+ len
, "commands:\teject\n");
2406 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2411 static int bay_write(char *buf
)
2415 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2418 while ((cmd
= next_cmd(&buf
))) {
2419 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2420 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2422 } else if (tp_features
.bay_eject2
&&
2423 strlencmp(cmd
, "eject2") == 0) {
2424 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2433 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2434 .notify
= bay_notify
,
2435 .handle
= &bay_handle
,
2436 .type
= ACPI_SYSTEM_NOTIFY
,
2439 static struct ibm_struct bay_driver_data
= {
2443 .acpi
= &ibm_bay_acpidriver
,
2446 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2448 /*************************************************************************
2452 /* sysfs cmos_command -------------------------------------------------- */
2453 static ssize_t
cmos_command_store(struct device
*dev
,
2454 struct device_attribute
*attr
,
2455 const char *buf
, size_t count
)
2457 unsigned long cmos_cmd
;
2460 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2463 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2464 return (res
)? res
: count
;
2467 static struct device_attribute dev_attr_cmos_command
=
2468 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2470 /* --------------------------------------------------------------------- */
2472 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2476 vdbg_printk(TPACPI_DBG_INIT
,
2477 "initializing cmos commands subdriver\n");
2479 IBM_ACPIHANDLE_INIT(cmos
);
2481 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2482 str_supported(cmos_handle
!= NULL
));
2484 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2488 return (cmos_handle
)? 0 : 1;
2491 static void cmos_exit(void)
2493 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2496 static int cmos_read(char *p
)
2500 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2501 R30, R31, T20-22, X20-21 */
2503 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2505 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2506 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2512 static int cmos_write(char *buf
)
2517 while ((cmd
= next_cmd(&buf
))) {
2518 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2519 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2524 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2532 static struct ibm_struct cmos_driver_data
= {
2535 .write
= cmos_write
,
2539 /*************************************************************************
2543 static enum led_access_mode led_supported
;
2545 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2546 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2547 "LED", /* all others */
2550 static int __init
led_init(struct ibm_init_struct
*iibm
)
2552 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2554 IBM_ACPIHANDLE_INIT(led
);
2557 /* led not supported on R30, R31 */
2558 led_supported
= TPACPI_LED_NONE
;
2559 else if (strlencmp(led_path
, "SLED") == 0)
2561 led_supported
= TPACPI_LED_570
;
2562 else if (strlencmp(led_path
, "SYSL") == 0)
2563 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2564 led_supported
= TPACPI_LED_OLD
;
2567 led_supported
= TPACPI_LED_NEW
;
2569 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2570 str_supported(led_supported
), led_supported
);
2572 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2575 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2577 static int led_read(char *p
)
2581 if (!led_supported
) {
2582 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2585 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2587 if (led_supported
== TPACPI_LED_570
) {
2590 for (i
= 0; i
< 8; i
++) {
2591 if (!acpi_evalf(ec_handle
,
2592 &status
, "GLED", "dd", 1 << i
))
2594 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2595 i
, led_status(status
));
2599 len
+= sprintf(p
+ len
, "commands:\t"
2600 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2605 /* off, on, blink */
2606 static const int led_sled_arg1
[] = { 0, 1, 3 };
2607 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2608 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2609 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2611 static int led_write(char *buf
)
2619 while ((cmd
= next_cmd(&buf
))) {
2620 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2623 if (strstr(cmd
, "off")) {
2625 } else if (strstr(cmd
, "on")) {
2627 } else if (strstr(cmd
, "blink")) {
2632 if (led_supported
== TPACPI_LED_570
) {
2635 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2636 led
, led_sled_arg1
[ind
]))
2638 } else if (led_supported
== TPACPI_LED_OLD
) {
2639 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2641 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2644 ec_write(TPACPI_LED_EC_HLBL
,
2645 led
* led_exp_hlbl
[ind
]);
2648 ec_write(TPACPI_LED_EC_HLCL
,
2649 led
* led_exp_hlcl
[ind
]);
2654 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2655 led
, led_led_arg1
[ind
]))
2663 static struct ibm_struct led_driver_data
= {
2669 /*************************************************************************
2673 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2675 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2677 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2679 IBM_ACPIHANDLE_INIT(beep
);
2681 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2682 str_supported(beep_handle
!= NULL
));
2684 return (beep_handle
)? 0 : 1;
2687 static int beep_read(char *p
)
2692 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2694 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2695 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2701 static int beep_write(char *buf
)
2709 while ((cmd
= next_cmd(&buf
))) {
2710 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2711 beep_cmd
>= 0 && beep_cmd
<= 17) {
2715 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2722 static struct ibm_struct beep_driver_data
= {
2725 .write
= beep_write
,
2728 /*************************************************************************
2732 static enum thermal_access_mode thermal_read_mode
;
2734 /* sysfs temp##_input -------------------------------------------------- */
2736 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2737 struct device_attribute
*attr
,
2740 struct sensor_device_attribute
*sensor_attr
=
2741 to_sensor_dev_attr(attr
);
2742 int idx
= sensor_attr
->index
;
2746 res
= thermal_get_sensor(idx
, &value
);
2749 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2752 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2755 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2756 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2758 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2759 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2760 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2761 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2762 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2763 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2764 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2765 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2766 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2767 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2768 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2769 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2770 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2771 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2772 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2773 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2774 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2777 #define THERMAL_ATTRS(X) \
2778 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2780 static struct attribute
*thermal_temp_input_attr
[] = {
2800 static const struct attribute_group thermal_temp_input16_group
= {
2801 .attrs
= thermal_temp_input_attr
2804 static const struct attribute_group thermal_temp_input8_group
= {
2805 .attrs
= &thermal_temp_input_attr
[8]
2808 #undef THERMAL_SENSOR_ATTR_TEMP
2809 #undef THERMAL_ATTRS
2811 /* --------------------------------------------------------------------- */
2813 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2820 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2822 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2824 if (thinkpad_id
.ec_model
) {
2826 * Direct EC access mode: sensors at registers
2827 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2828 * non-implemented, thermal sensors return 0x80 when
2833 for (i
= 0; i
< 8; i
++) {
2834 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2840 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2848 /* This is sheer paranoia, but we handle it anyway */
2851 "ThinkPad ACPI EC access misbehaving, "
2852 "falling back to ACPI TMPx access mode\n");
2853 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2856 "ThinkPad ACPI EC access misbehaving, "
2857 "disabling thermal sensors access\n");
2858 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2863 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2865 } else if (acpi_tmp7
) {
2866 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2867 /* 600e/x, 770e, 770x */
2868 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2870 /* Standard ACPI TMPx access, max 8 sensors */
2871 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2874 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2875 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2878 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2879 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2882 switch(thermal_read_mode
) {
2883 case TPACPI_THERMAL_TPEC_16
:
2884 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2885 &thermal_temp_input16_group
);
2889 case TPACPI_THERMAL_TPEC_8
:
2890 case TPACPI_THERMAL_ACPI_TMP07
:
2891 case TPACPI_THERMAL_ACPI_UPDT
:
2892 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2893 &thermal_temp_input8_group
);
2897 case TPACPI_THERMAL_NONE
:
2905 static void thermal_exit(void)
2907 switch(thermal_read_mode
) {
2908 case TPACPI_THERMAL_TPEC_16
:
2909 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2910 &thermal_temp_input16_group
);
2912 case TPACPI_THERMAL_TPEC_8
:
2913 case TPACPI_THERMAL_ACPI_TMP07
:
2914 case TPACPI_THERMAL_ACPI_UPDT
:
2915 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2916 &thermal_temp_input16_group
);
2918 case TPACPI_THERMAL_NONE
:
2924 /* idx is zero-based */
2925 static int thermal_get_sensor(int idx
, s32
*value
)
2931 t
= TP_EC_THERMAL_TMP0
;
2933 switch (thermal_read_mode
) {
2934 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2935 case TPACPI_THERMAL_TPEC_16
:
2936 if (idx
>= 8 && idx
<= 15) {
2937 t
= TP_EC_THERMAL_TMP8
;
2942 case TPACPI_THERMAL_TPEC_8
:
2944 if (!acpi_ec_read(t
+ idx
, &tmp
))
2946 *value
= tmp
* 1000;
2951 case TPACPI_THERMAL_ACPI_UPDT
:
2953 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2954 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2956 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2958 *value
= (t
- 2732) * 100;
2963 case TPACPI_THERMAL_ACPI_TMP07
:
2965 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2966 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2968 if (t
> 127 || t
< -127)
2969 t
= TP_EC_THERMAL_TMP_NA
;
2975 case TPACPI_THERMAL_NONE
:
2983 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2994 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2997 for(i
= 0 ; i
< n
; i
++) {
2998 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3006 static int thermal_read(char *p
)
3010 struct ibm_thermal_sensors_struct t
;
3012 n
= thermal_get_sensors(&t
);
3013 if (unlikely(n
< 0))
3016 len
+= sprintf(p
+ len
, "temperatures:\t");
3019 for (i
= 0; i
< (n
- 1); i
++)
3020 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3021 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3023 len
+= sprintf(p
+ len
, "not supported\n");
3028 static struct ibm_struct thermal_driver_data
= {
3030 .read
= thermal_read
,
3031 .exit
= thermal_exit
,
3034 /*************************************************************************
3038 static u8 ecdump_regs
[256];
3040 static int ecdump_read(char *p
)
3046 len
+= sprintf(p
+ len
, "EC "
3047 " +00 +01 +02 +03 +04 +05 +06 +07"
3048 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
3049 for (i
= 0; i
< 256; i
+= 16) {
3050 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
3051 for (j
= 0; j
< 16; j
++) {
3052 if (!acpi_ec_read(i
+ j
, &v
))
3054 if (v
!= ecdump_regs
[i
+ j
])
3055 len
+= sprintf(p
+ len
, " *%02x", v
);
3057 len
+= sprintf(p
+ len
, " %02x", v
);
3058 ecdump_regs
[i
+ j
] = v
;
3060 len
+= sprintf(p
+ len
, "\n");
3065 /* These are way too dangerous to advertise openly... */
3067 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3068 " (<offset> is 00-ff, <value> is 00-ff)\n");
3069 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3070 " (<offset> is 00-ff, <value> is 0-255)\n");
3075 static int ecdump_write(char *buf
)
3080 while ((cmd
= next_cmd(&buf
))) {
3081 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3083 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3087 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3088 if (!acpi_ec_write(i
, v
))
3097 static struct ibm_struct ecdump_driver_data
= {
3099 .read
= ecdump_read
,
3100 .write
= ecdump_write
,
3101 .flags
.experimental
= 1,
3104 /*************************************************************************
3105 * Backlight/brightness subdriver
3108 static struct backlight_device
*ibm_backlight_device
;
3110 static struct backlight_ops ibm_backlight_data
= {
3111 .get_brightness
= brightness_get
,
3112 .update_status
= brightness_update_status
,
3115 static struct mutex brightness_mutex
;
3117 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
3121 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
3123 mutex_init(&brightness_mutex
);
3125 if (!brightness_mode
) {
3126 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
3127 brightness_mode
= 2;
3129 brightness_mode
= 3;
3131 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
3135 if (brightness_mode
> 3)
3138 b
= brightness_get(NULL
);
3142 ibm_backlight_device
= backlight_device_register(
3143 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
3144 &ibm_backlight_data
);
3145 if (IS_ERR(ibm_backlight_device
)) {
3146 printk(IBM_ERR
"Could not register backlight device\n");
3147 return PTR_ERR(ibm_backlight_device
);
3149 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
3151 ibm_backlight_device
->props
.max_brightness
= 7;
3152 ibm_backlight_device
->props
.brightness
= b
;
3153 backlight_update_status(ibm_backlight_device
);
3158 static void brightness_exit(void)
3160 if (ibm_backlight_device
) {
3161 vdbg_printk(TPACPI_DBG_EXIT
,
3162 "calling backlight_device_unregister()\n");
3163 backlight_device_unregister(ibm_backlight_device
);
3164 ibm_backlight_device
= NULL
;
3168 static int brightness_update_status(struct backlight_device
*bd
)
3170 return brightness_set(
3171 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
3172 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
3173 bd
->props
.brightness
: 0);
3177 * ThinkPads can read brightness from two places: EC 0x31, or
3178 * CMOS NVRAM byte 0x5E, bits 0-3.
3180 static int brightness_get(struct backlight_device
*bd
)
3182 u8 lec
= 0, lcmos
= 0, level
= 0;
3184 if (brightness_mode
& 1) {
3185 if (!acpi_ec_read(brightness_offset
, &lec
))
3190 if (brightness_mode
& 2) {
3191 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3192 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3193 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3197 if (brightness_mode
== 3 && lec
!= lcmos
) {
3199 "CMOS NVRAM (%u) and EC (%u) do not agree "
3200 "on display brightness level\n",
3201 (unsigned int) lcmos
,
3202 (unsigned int) lec
);
3209 static int brightness_set(int value
)
3211 int cmos_cmd
, inc
, i
, res
;
3217 res
= mutex_lock_interruptible(&brightness_mutex
);
3221 current_value
= brightness_get(NULL
);
3222 if (current_value
< 0) {
3223 res
= current_value
;
3227 cmos_cmd
= value
> current_value
?
3228 TP_CMOS_BRIGHTNESS_UP
:
3229 TP_CMOS_BRIGHTNESS_DOWN
;
3230 inc
= value
> current_value
? 1 : -1;
3233 for (i
= current_value
; i
!= value
; i
+= inc
) {
3234 if ((brightness_mode
& 2) &&
3235 issue_thinkpad_cmos_command(cmos_cmd
)) {
3239 if ((brightness_mode
& 1) &&
3240 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
3247 mutex_unlock(&brightness_mutex
);
3251 static int brightness_read(char *p
)
3256 if ((level
= brightness_get(NULL
)) < 0) {
3257 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3259 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
3260 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3261 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3262 " (<level> is 0-7)\n");
3268 static int brightness_write(char *buf
)
3274 while ((cmd
= next_cmd(&buf
))) {
3275 if ((level
= brightness_get(NULL
)) < 0)
3279 if (strlencmp(cmd
, "up") == 0) {
3280 new_level
= level
== 7 ? 7 : level
+ 1;
3281 } else if (strlencmp(cmd
, "down") == 0) {
3282 new_level
= level
== 0 ? 0 : level
- 1;
3283 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3284 new_level
>= 0 && new_level
<= 7) {
3289 brightness_set(new_level
);
3295 static struct ibm_struct brightness_driver_data
= {
3296 .name
= "brightness",
3297 .read
= brightness_read
,
3298 .write
= brightness_write
,
3299 .exit
= brightness_exit
,
3302 /*************************************************************************
3306 static int volume_read(char *p
)
3311 if (!acpi_ec_read(volume_offset
, &level
)) {
3312 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3314 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3315 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3316 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3317 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3318 " (<level> is 0-15)\n");
3324 static int volume_write(char *buf
)
3326 int cmos_cmd
, inc
, i
;
3328 int new_level
, new_mute
;
3331 while ((cmd
= next_cmd(&buf
))) {
3332 if (!acpi_ec_read(volume_offset
, &level
))
3334 new_mute
= mute
= level
& 0x40;
3335 new_level
= level
= level
& 0xf;
3337 if (strlencmp(cmd
, "up") == 0) {
3341 new_level
= level
== 15 ? 15 : level
+ 1;
3342 } else if (strlencmp(cmd
, "down") == 0) {
3346 new_level
= level
== 0 ? 0 : level
- 1;
3347 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3348 new_level
>= 0 && new_level
<= 15) {
3350 } else if (strlencmp(cmd
, "mute") == 0) {
3355 if (new_level
!= level
) { /* mute doesn't change */
3356 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3357 inc
= new_level
> level
? 1 : -1;
3359 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3360 !acpi_ec_write(volume_offset
, level
)))
3363 for (i
= level
; i
!= new_level
; i
+= inc
)
3364 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3365 !acpi_ec_write(volume_offset
, i
+ inc
))
3368 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3369 !acpi_ec_write(volume_offset
,
3374 if (new_mute
!= mute
) { /* level doesn't change */
3375 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3377 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3378 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3386 static struct ibm_struct volume_driver_data
= {
3388 .read
= volume_read
,
3389 .write
= volume_write
,
3392 /*************************************************************************
3399 * TPACPI_FAN_RD_ACPI_GFAN:
3400 * ACPI GFAN method: returns fan level
3402 * see TPACPI_FAN_WR_ACPI_SFAN
3403 * EC 0x2f (HFSP) not available if GFAN exists
3405 * TPACPI_FAN_WR_ACPI_SFAN:
3406 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3408 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3411 * TPACPI_FAN_WR_TPEC:
3412 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3413 * Supported on almost all ThinkPads
3415 * Fan speed changes of any sort (including those caused by the
3416 * disengaged mode) are usually done slowly by the firmware as the
3417 * maximum ammount of fan duty cycle change per second seems to be
3420 * Reading is not available if GFAN exists.
3421 * Writing is not available if SFAN exists.
3424 * 7 automatic mode engaged;
3425 * (default operation mode of the ThinkPad)
3426 * fan level is ignored in this mode.
3427 * 6 full speed mode (takes precedence over bit 7);
3428 * not available on all thinkpads. May disable
3429 * the tachometer while the fan controller ramps up
3430 * the speed (which can take up to a few *minutes*).
3431 * Speeds up fan to 100% duty-cycle, which is far above
3432 * the standard RPM levels. It is not impossible that
3433 * it could cause hardware damage.
3434 * 5-3 unused in some models. Extra bits for fan level
3435 * in others, but still useless as all values above
3436 * 7 map to the same speed as level 7 in these models.
3437 * 2-0 fan level (0..7 usually)
3439 * 0x07 = max (set when temperatures critical)
3440 * Some ThinkPads may have other levels, see
3441 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3443 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3444 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3445 * does so, its initial value is meaningless (0x07).
3447 * For firmware bugs, refer to:
3448 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3452 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3453 * Main fan tachometer reading (in RPM)
3455 * This register is present on all ThinkPads with a new-style EC, and
3456 * it is known not to be present on the A21m/e, and T22, as there is
3457 * something else in offset 0x84 according to the ACPI DSDT. Other
3458 * ThinkPads from this same time period (and earlier) probably lack the
3459 * tachometer as well.
3461 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3462 * was never fixed by IBM to report the EC firmware version string
3463 * probably support the tachometer (like the early X models), so
3464 * detecting it is quite hard. We need more data to know for sure.
3466 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3469 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3472 * For firmware bugs, refer to:
3473 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3475 * TPACPI_FAN_WR_ACPI_FANS:
3476 * ThinkPad X31, X40, X41. Not available in the X60.
3478 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3479 * high speed. ACPI DSDT seems to map these three speeds to levels
3480 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3481 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3483 * The speeds are stored on handles
3484 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3486 * There are three default speed sets, acessible as handles:
3487 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3489 * ACPI DSDT switches which set is in use depending on various
3492 * TPACPI_FAN_WR_TPEC is also available and should be used to
3493 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3494 * but the ACPI tables just mention level 7.
3497 static enum fan_status_access_mode fan_status_access_mode
;
3498 static enum fan_control_access_mode fan_control_access_mode
;
3499 static enum fan_control_commands fan_control_commands
;
3501 static u8 fan_control_initial_status
;
3502 static u8 fan_control_desired_level
;
3504 static void fan_watchdog_fire(struct work_struct
*ignored
);
3505 static int fan_watchdog_maxinterval
;
3506 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3508 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3509 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3510 "\\FSPD", /* 600e/x, 770e, 770x */
3512 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3513 "JFNS", /* 770x-JL */
3517 * SYSFS fan layout: hwmon compatible (device)
3520 * 0: "disengaged" mode
3522 * 2: native EC "auto" mode (recommended, hardware default)
3524 * pwm*: set speed in manual mode, ignored otherwise.
3525 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3528 * fan*_input: tachometer reading, RPM
3531 * SYSFS fan layout: extensions
3533 * fan_watchdog (driver):
3534 * fan watchdog interval in seconds, 0 disables (default), max 120
3537 /* sysfs fan pwm1_enable ----------------------------------------------- */
3538 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3539 struct device_attribute
*attr
,
3545 res
= fan_get_status_safe(&status
);
3549 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3550 if (status
!= fan_control_initial_status
) {
3551 tp_features
.fan_ctrl_status_undef
= 0;
3553 /* Return most likely status. In fact, it
3554 * might be the only possible status */
3555 status
= TP_EC_FAN_AUTO
;
3559 if (status
& TP_EC_FAN_FULLSPEED
) {
3561 } else if (status
& TP_EC_FAN_AUTO
) {
3566 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3569 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3570 struct device_attribute
*attr
,
3571 const char *buf
, size_t count
)
3576 if (parse_strtoul(buf
, 2, &t
))
3581 level
= TP_EC_FAN_FULLSPEED
;
3584 level
= TPACPI_FAN_LAST_LEVEL
;
3587 level
= TP_EC_FAN_AUTO
;
3590 /* reserved for software-controlled auto mode */
3596 res
= fan_set_level_safe(level
);
3602 fan_watchdog_reset();
3607 static struct device_attribute dev_attr_fan_pwm1_enable
=
3608 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3609 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3611 /* sysfs fan pwm1 ------------------------------------------------------ */
3612 static ssize_t
fan_pwm1_show(struct device
*dev
,
3613 struct device_attribute
*attr
,
3619 res
= fan_get_status_safe(&status
);
3623 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3624 if (status
!= fan_control_initial_status
) {
3625 tp_features
.fan_ctrl_status_undef
= 0;
3627 status
= TP_EC_FAN_AUTO
;
3632 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3633 status
= fan_control_desired_level
;
3638 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3641 static ssize_t
fan_pwm1_store(struct device
*dev
,
3642 struct device_attribute
*attr
,
3643 const char *buf
, size_t count
)
3647 u8 status
, newlevel
;
3649 if (parse_strtoul(buf
, 255, &s
))
3652 /* scale down from 0-255 to 0-7 */
3653 newlevel
= (s
>> 5) & 0x07;
3655 rc
= mutex_lock_interruptible(&fan_mutex
);
3659 rc
= fan_get_status(&status
);
3660 if (!rc
&& (status
&
3661 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3662 rc
= fan_set_level(newlevel
);
3666 fan_update_desired_level(newlevel
);
3667 fan_watchdog_reset();
3671 mutex_unlock(&fan_mutex
);
3672 return (rc
)? rc
: count
;
3675 static struct device_attribute dev_attr_fan_pwm1
=
3676 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3677 fan_pwm1_show
, fan_pwm1_store
);
3679 /* sysfs fan fan1_input ------------------------------------------------ */
3680 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3681 struct device_attribute
*attr
,
3687 res
= fan_get_speed(&speed
);
3691 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3694 static struct device_attribute dev_attr_fan_fan1_input
=
3695 __ATTR(fan1_input
, S_IRUGO
,
3696 fan_fan1_input_show
, NULL
);
3698 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
3699 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3702 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3705 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3706 const char *buf
, size_t count
)
3710 if (parse_strtoul(buf
, 120, &t
))
3713 if (!fan_control_allowed
)
3716 fan_watchdog_maxinterval
= t
;
3717 fan_watchdog_reset();
3722 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3723 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3725 /* --------------------------------------------------------------------- */
3726 static struct attribute
*fan_attributes
[] = {
3727 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3728 &dev_attr_fan_fan1_input
.attr
,
3732 static const struct attribute_group fan_attr_group
= {
3733 .attrs
= fan_attributes
,
3736 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3740 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3742 mutex_init(&fan_mutex
);
3743 fan_status_access_mode
= TPACPI_FAN_NONE
;
3744 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3745 fan_control_commands
= 0;
3746 fan_watchdog_maxinterval
= 0;
3747 tp_features
.fan_ctrl_status_undef
= 0;
3748 fan_control_desired_level
= 7;
3750 IBM_ACPIHANDLE_INIT(fans
);
3751 IBM_ACPIHANDLE_INIT(gfan
);
3752 IBM_ACPIHANDLE_INIT(sfan
);
3755 /* 570, 600e/x, 770e, 770x */
3756 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3758 /* all other ThinkPads: note that even old-style
3759 * ThinkPad ECs supports the fan control register */
3760 if (likely(acpi_ec_read(fan_status_offset
,
3761 &fan_control_initial_status
))) {
3762 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3764 /* In some ThinkPads, neither the EC nor the ACPI
3765 * DSDT initialize the fan status, and it ends up
3766 * being set to 0x07 when it *could* be either
3769 * Enable for TP-1Y (T43), TP-78 (R51e),
3770 * TP-76 (R52), TP-70 (T43, R52), which are known
3772 if (fan_control_initial_status
== 0x07) {
3773 switch (thinkpad_id
.ec_model
) {
3774 case 0x5931: /* TP-1Y */
3775 case 0x3837: /* TP-78 */
3776 case 0x3637: /* TP-76 */
3777 case 0x3037: /* TP-70 */
3779 "fan_init: initial fan status is "
3780 "unknown, assuming it is in auto "
3782 tp_features
.fan_ctrl_status_undef
= 1;
3788 "ThinkPad ACPI EC access misbehaving, "
3789 "fan status and control unavailable\n");
3796 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3797 fan_control_commands
|=
3798 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3801 /* gfan without sfan means no fan control */
3802 /* all other models implement TP EC 0x2f control */
3806 fan_control_access_mode
=
3807 TPACPI_FAN_WR_ACPI_FANS
;
3808 fan_control_commands
|=
3809 TPACPI_FAN_CMD_SPEED
|
3810 TPACPI_FAN_CMD_LEVEL
|
3811 TPACPI_FAN_CMD_ENABLE
;
3813 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3814 fan_control_commands
|=
3815 TPACPI_FAN_CMD_LEVEL
|
3816 TPACPI_FAN_CMD_ENABLE
;
3821 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3822 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3823 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3824 fan_status_access_mode
, fan_control_access_mode
);
3826 /* fan control master switch */
3827 if (!fan_control_allowed
) {
3828 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3829 fan_control_commands
= 0;
3830 dbg_printk(TPACPI_DBG_INIT
,
3831 "fan control features disabled by parameter\n");
3834 /* update fan_control_desired_level */
3835 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3836 fan_get_status_safe(NULL
);
3838 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3839 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3840 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3843 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
3844 &driver_attr_fan_watchdog
);
3853 * Call with fan_mutex held
3855 static void fan_update_desired_level(u8 status
)
3858 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3860 fan_control_desired_level
= 7;
3862 fan_control_desired_level
= status
;
3866 static int fan_get_status(u8
*status
)
3871 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3873 switch (fan_status_access_mode
) {
3874 case TPACPI_FAN_RD_ACPI_GFAN
:
3875 /* 570, 600e/x, 770e, 770x */
3877 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
3885 case TPACPI_FAN_RD_TPEC
:
3886 /* all except 570, 600e/x, 770e, 770x */
3887 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
3902 static int fan_get_status_safe(u8
*status
)
3907 rc
= mutex_lock_interruptible(&fan_mutex
);
3910 rc
= fan_get_status(&s
);
3912 fan_update_desired_level(s
);
3913 mutex_unlock(&fan_mutex
);
3921 static void fan_exit(void)
3923 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
3925 /* FIXME: can we really do this unconditionally? */
3926 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
3927 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
, &driver_attr_fan_watchdog
);
3929 cancel_delayed_work(&fan_watchdog_task
);
3930 flush_scheduled_work();
3933 static int fan_get_speed(unsigned int *speed
)
3937 switch (fan_status_access_mode
) {
3938 case TPACPI_FAN_RD_TPEC
:
3939 /* all except 570, 600e/x, 770e, 770x */
3940 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
3941 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
3945 *speed
= (hi
<< 8) | lo
;
3956 static void fan_watchdog_fire(struct work_struct
*ignored
)
3960 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
3963 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
3964 rc
= fan_set_enable();
3966 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
3967 "will try again later...\n", -rc
);
3968 /* reschedule for later */
3969 fan_watchdog_reset();
3973 static void fan_watchdog_reset(void)
3975 static int fan_watchdog_active
;
3977 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
3980 if (fan_watchdog_active
)
3981 cancel_delayed_work(&fan_watchdog_task
);
3983 if (fan_watchdog_maxinterval
> 0 &&
3984 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
3985 fan_watchdog_active
= 1;
3986 if (!schedule_delayed_work(&fan_watchdog_task
,
3987 msecs_to_jiffies(fan_watchdog_maxinterval
3989 printk(IBM_ERR
"failed to schedule the fan watchdog, "
3990 "watchdog will not trigger\n");
3993 fan_watchdog_active
= 0;
3996 static int fan_set_level(int level
)
3998 if (!fan_control_allowed
)
4001 switch (fan_control_access_mode
) {
4002 case TPACPI_FAN_WR_ACPI_SFAN
:
4003 if (level
>= 0 && level
<= 7) {
4004 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4010 case TPACPI_FAN_WR_ACPI_FANS
:
4011 case TPACPI_FAN_WR_TPEC
:
4012 if ((level
!= TP_EC_FAN_AUTO
) &&
4013 (level
!= TP_EC_FAN_FULLSPEED
) &&
4014 ((level
< 0) || (level
> 7)))
4017 /* safety net should the EC not support AUTO
4018 * or FULLSPEED mode bits and just ignore them */
4019 if (level
& TP_EC_FAN_FULLSPEED
)
4020 level
|= 7; /* safety min speed 7 */
4021 else if (level
& TP_EC_FAN_FULLSPEED
)
4022 level
|= 4; /* safety min speed 4 */
4024 if (!acpi_ec_write(fan_status_offset
, level
))
4027 tp_features
.fan_ctrl_status_undef
= 0;
4036 static int fan_set_level_safe(int level
)
4040 if (!fan_control_allowed
)
4043 rc
= mutex_lock_interruptible(&fan_mutex
);
4047 if (level
== TPACPI_FAN_LAST_LEVEL
)
4048 level
= fan_control_desired_level
;
4050 rc
= fan_set_level(level
);
4052 fan_update_desired_level(level
);
4054 mutex_unlock(&fan_mutex
);
4058 static int fan_set_enable(void)
4063 if (!fan_control_allowed
)
4066 rc
= mutex_lock_interruptible(&fan_mutex
);
4070 switch (fan_control_access_mode
) {
4071 case TPACPI_FAN_WR_ACPI_FANS
:
4072 case TPACPI_FAN_WR_TPEC
:
4073 rc
= fan_get_status(&s
);
4077 /* Don't go out of emergency fan mode */
4080 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4083 if (!acpi_ec_write(fan_status_offset
, s
))
4086 tp_features
.fan_ctrl_status_undef
= 0;
4091 case TPACPI_FAN_WR_ACPI_SFAN
:
4092 rc
= fan_get_status(&s
);
4098 /* Set fan to at least level 4 */
4101 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4111 mutex_unlock(&fan_mutex
);
4115 static int fan_set_disable(void)
4119 if (!fan_control_allowed
)
4122 rc
= mutex_lock_interruptible(&fan_mutex
);
4127 switch (fan_control_access_mode
) {
4128 case TPACPI_FAN_WR_ACPI_FANS
:
4129 case TPACPI_FAN_WR_TPEC
:
4130 if (!acpi_ec_write(fan_status_offset
, 0x00))
4133 fan_control_desired_level
= 0;
4134 tp_features
.fan_ctrl_status_undef
= 0;
4138 case TPACPI_FAN_WR_ACPI_SFAN
:
4139 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4142 fan_control_desired_level
= 0;
4150 mutex_unlock(&fan_mutex
);
4154 static int fan_set_speed(int speed
)
4158 if (!fan_control_allowed
)
4161 rc
= mutex_lock_interruptible(&fan_mutex
);
4166 switch (fan_control_access_mode
) {
4167 case TPACPI_FAN_WR_ACPI_FANS
:
4168 if (speed
>= 0 && speed
<= 65535) {
4169 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4170 speed
, speed
, speed
))
4180 mutex_unlock(&fan_mutex
);
4184 static int fan_read(char *p
)
4189 unsigned int speed
= 0;
4191 switch (fan_status_access_mode
) {
4192 case TPACPI_FAN_RD_ACPI_GFAN
:
4193 /* 570, 600e/x, 770e, 770x */
4194 if ((rc
= fan_get_status_safe(&status
)) < 0)
4197 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
4199 (status
!= 0) ? "enabled" : "disabled", status
);
4202 case TPACPI_FAN_RD_TPEC
:
4203 /* all except 570, 600e/x, 770e, 770x */
4204 if ((rc
= fan_get_status_safe(&status
)) < 0)
4207 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4208 if (status
!= fan_control_initial_status
)
4209 tp_features
.fan_ctrl_status_undef
= 0;
4211 /* Return most likely status. In fact, it
4212 * might be the only possible status */
4213 status
= TP_EC_FAN_AUTO
;
4216 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4217 (status
!= 0) ? "enabled" : "disabled");
4219 if ((rc
= fan_get_speed(&speed
)) < 0)
4222 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
4224 if (status
& TP_EC_FAN_FULLSPEED
)
4225 /* Disengaged mode takes precedence */
4226 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
4227 else if (status
& TP_EC_FAN_AUTO
)
4228 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
4230 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
4233 case TPACPI_FAN_NONE
:
4235 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4238 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
4239 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
4241 switch (fan_control_access_mode
) {
4242 case TPACPI_FAN_WR_ACPI_SFAN
:
4243 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4247 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4248 "auto, disengaged, full-speed)\n");
4253 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4254 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4255 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4256 "1-120 (seconds))\n");
4258 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4259 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4260 " (<speed> is 0-65535)\n");
4265 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4269 if (strlencmp(cmd
, "level auto") == 0)
4270 level
= TP_EC_FAN_AUTO
;
4271 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4272 (strlencmp(cmd
, "level full-speed") == 0))
4273 level
= TP_EC_FAN_FULLSPEED
;
4274 else if (sscanf(cmd
, "level %d", &level
) != 1)
4277 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4278 printk(IBM_ERR
"level command accepted for unsupported "
4279 "access mode %d", fan_control_access_mode
);
4284 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4286 if (strlencmp(cmd
, "enable") != 0)
4289 if ((*rc
= fan_set_enable()) == -ENXIO
)
4290 printk(IBM_ERR
"enable command accepted for unsupported "
4291 "access mode %d", fan_control_access_mode
);
4296 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4298 if (strlencmp(cmd
, "disable") != 0)
4301 if ((*rc
= fan_set_disable()) == -ENXIO
)
4302 printk(IBM_ERR
"disable command accepted for unsupported "
4303 "access mode %d", fan_control_access_mode
);
4308 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4313 * Support speed <low> <medium> <high> ? */
4315 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4318 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4319 printk(IBM_ERR
"speed command accepted for unsupported "
4320 "access mode %d", fan_control_access_mode
);
4325 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4329 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4332 if (interval
< 0 || interval
> 120)
4335 fan_watchdog_maxinterval
= interval
;
4340 static int fan_write(char *buf
)
4345 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4346 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4347 fan_write_cmd_level(cmd
, &rc
)) &&
4348 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4349 (fan_write_cmd_enable(cmd
, &rc
) ||
4350 fan_write_cmd_disable(cmd
, &rc
) ||
4351 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4352 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4353 fan_write_cmd_speed(cmd
, &rc
))
4357 fan_watchdog_reset();
4363 static struct ibm_struct fan_driver_data
= {
4370 /****************************************************************************
4371 ****************************************************************************
4375 ****************************************************************************
4376 ****************************************************************************/
4378 /* sysfs name ---------------------------------------------------------- */
4379 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
4380 struct device_attribute
*attr
,
4383 return snprintf(buf
, PAGE_SIZE
, "%s\n", IBM_NAME
);
4386 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
4387 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
4389 /* --------------------------------------------------------------------- */
4392 static struct proc_dir_entry
*proc_dir
;
4394 /* Subdriver registry */
4395 static LIST_HEAD(tpacpi_all_drivers
);
4399 * Module and infrastructure proble, init and exit handling
4402 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4403 static const char * __init
str_supported(int is_supported
)
4405 static char text_unsupported
[] __initdata
= "not supported";
4407 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4409 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4411 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4414 struct ibm_struct
*ibm
= iibm
->data
;
4415 struct proc_dir_entry
*entry
;
4417 BUG_ON(ibm
== NULL
);
4419 INIT_LIST_HEAD(&ibm
->all_drivers
);
4421 if (ibm
->flags
.experimental
&& !experimental
)
4424 dbg_printk(TPACPI_DBG_INIT
,
4425 "probing for %s\n", ibm
->name
);
4428 ret
= iibm
->init(iibm
);
4430 return 0; /* probe failed */
4434 ibm
->flags
.init_called
= 1;
4438 if (ibm
->acpi
->hid
) {
4439 ret
= register_tpacpi_subdriver(ibm
);
4444 if (ibm
->acpi
->notify
) {
4445 ret
= setup_acpi_notify(ibm
);
4446 if (ret
== -ENODEV
) {
4447 printk(IBM_NOTICE
"disabling subdriver %s\n",
4457 dbg_printk(TPACPI_DBG_INIT
,
4458 "%s installed\n", ibm
->name
);
4461 entry
= create_proc_entry(ibm
->name
,
4462 S_IFREG
| S_IRUGO
| S_IWUSR
,
4465 printk(IBM_ERR
"unable to create proc entry %s\n",
4470 entry
->owner
= THIS_MODULE
;
4472 entry
->read_proc
= &dispatch_procfs_read
;
4474 entry
->write_proc
= &dispatch_procfs_write
;
4475 ibm
->flags
.proc_created
= 1;
4478 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4483 dbg_printk(TPACPI_DBG_INIT
,
4484 "%s: at error exit path with result %d\n",
4488 return (ret
< 0)? ret
: 0;
4491 static void ibm_exit(struct ibm_struct
*ibm
)
4493 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4495 list_del_init(&ibm
->all_drivers
);
4497 if (ibm
->flags
.acpi_notify_installed
) {
4498 dbg_printk(TPACPI_DBG_EXIT
,
4499 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4501 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4503 dispatch_acpi_notify
);
4504 ibm
->flags
.acpi_notify_installed
= 0;
4505 ibm
->flags
.acpi_notify_installed
= 0;
4508 if (ibm
->flags
.proc_created
) {
4509 dbg_printk(TPACPI_DBG_EXIT
,
4510 "%s: remove_proc_entry\n", ibm
->name
);
4511 remove_proc_entry(ibm
->name
, proc_dir
);
4512 ibm
->flags
.proc_created
= 0;
4515 if (ibm
->flags
.acpi_driver_registered
) {
4516 dbg_printk(TPACPI_DBG_EXIT
,
4517 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4519 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4520 kfree(ibm
->acpi
->driver
);
4521 ibm
->acpi
->driver
= NULL
;
4522 ibm
->flags
.acpi_driver_registered
= 0;
4525 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4527 ibm
->flags
.init_called
= 0;
4530 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4535 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
4537 const struct dmi_device
*dev
= NULL
;
4538 char ec_fw_string
[18];
4543 memset(tp
, 0, sizeof(*tp
));
4545 if (dmi_name_in_vendors("IBM"))
4546 tp
->vendor
= PCI_VENDOR_ID_IBM
;
4547 else if (dmi_name_in_vendors("LENOVO"))
4548 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
4552 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
4554 if (!tp
->bios_version_str
)
4556 tp
->bios_model
= tp
->bios_version_str
[0]
4557 | (tp
->bios_version_str
[1] << 8);
4560 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4561 * X32 or newer, all Z series; Some models must have an
4562 * up-to-date BIOS or they will not be detected.
4564 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4566 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4567 if (sscanf(dev
->name
,
4568 "IBM ThinkPad Embedded Controller -[%17c",
4569 ec_fw_string
) == 1) {
4570 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4571 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4573 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
4574 tp
->ec_model
= ec_fw_string
[0]
4575 | (ec_fw_string
[1] << 8);
4580 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
4582 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
4583 kfree(tp
->model_str
);
4584 tp
->model_str
= NULL
;
4588 static int __init
probe_for_thinkpad(void)
4596 * Non-ancient models have better DMI tagging, but very old models
4599 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
4601 /* ec is required because many other handles are relative to it */
4602 IBM_ACPIHANDLE_INIT(ec
);
4606 "Not yet supported ThinkPad detected!\n");
4611 * Risks a regression on very old machines, but reduces potential
4612 * false positives a damn great deal
4615 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
4617 if (!is_thinkpad
&& !force_load
)
4624 /* Module init, exit, parameters */
4626 static struct ibm_init_struct ibms_init
[] __initdata
= {
4628 .init
= thinkpad_acpi_driver_init
,
4629 .data
= &thinkpad_acpi_driver_data
,
4632 .init
= hotkey_init
,
4633 .data
= &hotkey_driver_data
,
4636 .init
= bluetooth_init
,
4637 .data
= &bluetooth_driver_data
,
4641 .data
= &wan_driver_data
,
4645 .data
= &video_driver_data
,
4649 .data
= &light_driver_data
,
4651 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4654 .data
= &dock_driver_data
[0],
4658 .data
= &dock_driver_data
[1],
4661 #ifdef CONFIG_THINKPAD_ACPI_BAY
4664 .data
= &bay_driver_data
,
4669 .data
= &cmos_driver_data
,
4673 .data
= &led_driver_data
,
4677 .data
= &beep_driver_data
,
4680 .init
= thermal_init
,
4681 .data
= &thermal_driver_data
,
4684 .data
= &ecdump_driver_data
,
4687 .init
= brightness_init
,
4688 .data
= &brightness_driver_data
,
4691 .data
= &volume_driver_data
,
4695 .data
= &fan_driver_data
,
4699 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4702 struct ibm_struct
*ibm
;
4704 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4705 ibm
= ibms_init
[i
].data
;
4706 BUG_ON(ibm
== NULL
);
4708 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4709 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4711 strcpy(ibms_init
[i
].param
, val
);
4712 strcat(ibms_init
[i
].param
, ",");
4720 static int experimental
;
4721 module_param(experimental
, int, 0);
4723 static u32 dbg_level
;
4724 module_param_named(debug
, dbg_level
, uint
, 0);
4726 static int force_load
;
4727 module_param(force_load
, bool, 0);
4729 static int fan_control_allowed
;
4730 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
4732 static int brightness_mode
;
4733 module_param_named(brightness_mode
, brightness_mode
, int, 0);
4735 static unsigned int hotkey_report_mode
;
4736 module_param(hotkey_report_mode
, uint
, 0);
4738 #define IBM_PARAM(feature) \
4739 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4742 IBM_PARAM(bluetooth
);
4745 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4748 #ifdef CONFIG_THINKPAD_ACPI_BAY
4750 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4755 IBM_PARAM(brightness
);
4759 static int __init
thinkpad_acpi_module_init(void)
4763 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
4765 /* Parameter checking */
4766 if (hotkey_report_mode
> 2)
4769 /* Driver-level probe */
4771 get_thinkpad_model_data(&thinkpad_id
);
4772 ret
= probe_for_thinkpad();
4774 thinkpad_acpi_module_exit();
4778 /* Driver initialization */
4780 IBM_ACPIHANDLE_INIT(ecrd
);
4781 IBM_ACPIHANDLE_INIT(ecwr
);
4783 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4785 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4786 thinkpad_acpi_module_exit();
4789 proc_dir
->owner
= THIS_MODULE
;
4791 ret
= platform_driver_register(&tpacpi_pdriver
);
4793 printk(IBM_ERR
"unable to register main platform driver\n");
4794 thinkpad_acpi_module_exit();
4797 tp_features
.platform_drv_registered
= 1;
4799 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
4801 printk(IBM_ERR
"unable to register hwmon platform driver\n");
4802 thinkpad_acpi_module_exit();
4805 tp_features
.sensors_pdrv_registered
= 1;
4807 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4809 tp_features
.platform_drv_attrs_registered
= 1;
4810 ret
= tpacpi_create_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
4813 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4814 thinkpad_acpi_module_exit();
4817 tp_features
.sensors_pdrv_attrs_registered
= 1;
4820 /* Device initialization */
4821 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4823 if (IS_ERR(tpacpi_pdev
)) {
4824 ret
= PTR_ERR(tpacpi_pdev
);
4826 printk(IBM_ERR
"unable to register platform device\n");
4827 thinkpad_acpi_module_exit();
4830 tpacpi_sensors_pdev
= platform_device_register_simple(
4831 IBM_HWMON_DRVR_NAME
,
4833 if (IS_ERR(tpacpi_sensors_pdev
)) {
4834 ret
= PTR_ERR(tpacpi_sensors_pdev
);
4835 tpacpi_sensors_pdev
= NULL
;
4836 printk(IBM_ERR
"unable to register hwmon platform device\n");
4837 thinkpad_acpi_module_exit();
4840 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
4841 &dev_attr_thinkpad_acpi_pdev_name
);
4844 "unable to create sysfs hwmon device attributes\n");
4845 thinkpad_acpi_module_exit();
4848 tp_features
.sensors_pdev_attrs_registered
= 1;
4849 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
4850 if (IS_ERR(tpacpi_hwmon
)) {
4851 ret
= PTR_ERR(tpacpi_hwmon
);
4852 tpacpi_hwmon
= NULL
;
4853 printk(IBM_ERR
"unable to register hwmon device\n");
4854 thinkpad_acpi_module_exit();
4857 mutex_init(&tpacpi_inputdev_send_mutex
);
4858 tpacpi_inputdev
= input_allocate_device();
4859 if (!tpacpi_inputdev
) {
4860 printk(IBM_ERR
"unable to allocate input device\n");
4861 thinkpad_acpi_module_exit();
4864 /* Prepare input device, but don't register */
4865 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
4866 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
4867 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
4868 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
4869 thinkpad_id
.vendor
:
4871 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
4872 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
4874 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4875 ret
= ibm_init(&ibms_init
[i
]);
4876 if (ret
>= 0 && *ibms_init
[i
].param
)
4877 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
4879 thinkpad_acpi_module_exit();
4883 ret
= input_register_device(tpacpi_inputdev
);
4885 printk(IBM_ERR
"unable to register input device\n");
4886 thinkpad_acpi_module_exit();
4889 tp_features
.input_device_registered
= 1;
4892 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
4896 static void thinkpad_acpi_module_exit(void)
4898 struct ibm_struct
*ibm
, *itmp
;
4900 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
4902 list_for_each_entry_safe_reverse(ibm
, itmp
,
4903 &tpacpi_all_drivers
,
4908 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
4910 if (tpacpi_inputdev
) {
4911 if (tp_features
.input_device_registered
)
4912 input_unregister_device(tpacpi_inputdev
);
4914 input_free_device(tpacpi_inputdev
);
4918 hwmon_device_unregister(tpacpi_hwmon
);
4920 if (tp_features
.sensors_pdev_attrs_registered
)
4921 device_remove_file(&tpacpi_sensors_pdev
->dev
,
4922 &dev_attr_thinkpad_acpi_pdev_name
);
4923 if (tpacpi_sensors_pdev
)
4924 platform_device_unregister(tpacpi_sensors_pdev
);
4926 platform_device_unregister(tpacpi_pdev
);
4928 if (tp_features
.sensors_pdrv_attrs_registered
)
4929 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
4930 if (tp_features
.platform_drv_attrs_registered
)
4931 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
4933 if (tp_features
.sensors_pdrv_registered
)
4934 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
4936 if (tp_features
.platform_drv_registered
)
4937 platform_driver_unregister(&tpacpi_pdriver
);
4940 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
4942 kfree(thinkpad_id
.bios_version_str
);
4943 kfree(thinkpad_id
.ec_version_str
);
4944 kfree(thinkpad_id
.model_str
);
4947 module_init(thinkpad_acpi_module_init
);
4948 module_exit(thinkpad_acpi_module_exit
);