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 0x010000
29 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
32 * 2006-11-22 0.13 new maintainer
33 * changelog now lives in git commit history, and will
34 * not be updated further in-file.
36 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
37 * 2005-03-17 0.11 support for 600e, 770x
38 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
39 * support for 770e, G41
40 * G40 and G41 don't have a thinklight
41 * temperatures no longer experimental
42 * experimental brightness control
43 * experimental volume control
44 * experimental fan enable/disable
45 * 2005-01-16 0.10 fix module loading on R30, R31
46 * 2005-01-16 0.9 support for 570, R30, R31
47 * ultrabay support on A22p, A3x
48 * limit arg for cmos, led, beep, drop experimental status
49 * more capable led control on A21e, A22p, T20-22, X20
50 * experimental temperatures and fan speed
51 * experimental embedded controller register dump
52 * mark more functions as __init, drop incorrect __exit
54 * thanks to Henrik Brix Andersen <brix@gentoo.org>
55 * fix parameter passing on module loading
56 * thanks to Rusty Russell <rusty@rustcorp.com.au>
57 * thanks to Jim Radford <radford@blackbean.org>
58 * 2004-11-08 0.8 fix init error case, don't return from a macro
59 * thanks to Chris Wright <chrisw@osdl.org>
60 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
61 * fix led control on A21e
62 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
63 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
64 * proc file format changed
65 * video_switch command
66 * experimental cmos control
67 * experimental led control
68 * experimental acpi sounds
69 * 2004-09-16 0.4 support for module parameters
70 * hotkey mask can be prefixed by 0x
71 * video output switching
72 * video expansion control
73 * ultrabay eject support
74 * removed lcd brightness/on/off control, didn't work
75 * 2004-08-17 0.3 support for R40
76 * lcd off, brightness control
78 * 2004-08-14 0.2 support for T series, X20
79 * bluetooth enable/disable
80 * hotkey events disabled by default
81 * removed fan control, currently useless
82 * 2004-08-09 0.1 initial release, support for X series
85 #include "thinkpad_acpi.h"
87 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
88 MODULE_DESCRIPTION(IBM_DESC
);
89 MODULE_VERSION(IBM_VERSION
);
90 MODULE_LICENSE("GPL");
92 /* Please remove this in year 2009 */
93 MODULE_ALIAS("ibm_acpi");
96 * DMI matching for module autoloading
98 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
99 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
101 * Only models listed in thinkwiki will be supported, so add yours
102 * if it is not there yet.
104 #define IBM_BIOS_MODULE_ALIAS(__type) \
105 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
107 /* Non-ancient thinkpads */
108 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
109 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
111 /* Ancient thinkpad BIOSes have to be identified by
112 * BIOS type or model number, and there are far less
113 * BIOS types than model numbers... */
114 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
115 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
116 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
118 #define __unused __attribute__ ((unused))
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
;
423 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
425 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
427 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
429 kfree(ibm
->acpi
->driver
);
430 ibm
->acpi
->driver
= NULL
;
432 ibm
->flags
.acpi_driver_registered
= 1;
438 /****************************************************************************
439 ****************************************************************************
443 ****************************************************************************
444 ****************************************************************************/
446 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
447 int count
, int *eof
, void *data
)
449 struct ibm_struct
*ibm
= data
;
452 if (!ibm
|| !ibm
->read
)
455 len
= ibm
->read(page
);
459 if (len
<= off
+ count
)
471 static int dispatch_procfs_write(struct file
*file
,
472 const char __user
* userbuf
,
473 unsigned long count
, void *data
)
475 struct ibm_struct
*ibm
= data
;
479 if (!ibm
|| !ibm
->write
)
482 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
486 if (copy_from_user(kernbuf
, userbuf
, count
)) {
492 strcat(kernbuf
, ",");
493 ret
= ibm
->write(kernbuf
);
502 static char *next_cmd(char **cmds
)
507 while ((end
= strchr(start
, ',')) && end
== start
)
519 /****************************************************************************
520 ****************************************************************************
522 * Device model: input, hwmon and platform
524 ****************************************************************************
525 ****************************************************************************/
527 static struct platform_device
*tpacpi_pdev
;
528 static struct class_device
*tpacpi_hwmon
;
529 static struct input_dev
*tpacpi_inputdev
;
530 static struct mutex tpacpi_inputdev_send_mutex
;
533 static int tpacpi_resume_handler(struct platform_device
*pdev
)
535 struct ibm_struct
*ibm
, *itmp
;
537 list_for_each_entry_safe(ibm
, itmp
,
547 static struct platform_driver tpacpi_pdriver
= {
549 .name
= IBM_DRVR_NAME
,
550 .owner
= THIS_MODULE
,
552 .resume
= tpacpi_resume_handler
,
556 /*************************************************************************
557 * thinkpad-acpi driver attributes
560 /* interface_version --------------------------------------------------- */
561 static ssize_t
tpacpi_driver_interface_version_show(
562 struct device_driver
*drv
,
565 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
568 static DRIVER_ATTR(interface_version
, S_IRUGO
,
569 tpacpi_driver_interface_version_show
, NULL
);
571 /* debug_level --------------------------------------------------------- */
572 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
575 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
578 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
579 const char *buf
, size_t count
)
583 if (parse_strtoul(buf
, 0xffff, &t
))
591 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
592 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
594 /* version ------------------------------------------------------------- */
595 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
598 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
601 static DRIVER_ATTR(version
, S_IRUGO
,
602 tpacpi_driver_version_show
, NULL
);
604 /* --------------------------------------------------------------------- */
606 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
607 &driver_attr_debug_level
, &driver_attr_version
,
608 &driver_attr_interface_version
,
611 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
617 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
618 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
625 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
629 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
630 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
633 /*************************************************************************
634 * sysfs support helpers
637 struct attribute_set_obj
{
638 struct attribute_set s
;
640 } __attribute__((packed
));
642 static struct attribute_set
*create_attr_set(unsigned int max_members
,
645 struct attribute_set_obj
*sobj
;
647 if (max_members
== 0)
650 /* Allocates space for implicit NULL at the end too */
651 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
652 max_members
* sizeof(struct attribute
*),
656 sobj
->s
.max_members
= max_members
;
657 sobj
->s
.group
.attrs
= &sobj
->a
;
658 sobj
->s
.group
.name
= name
;
663 /* not multi-threaded safe, use it in a single thread per set */
664 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
669 if (s
->members
>= s
->max_members
)
672 s
->group
.attrs
[s
->members
] = attr
;
678 static int add_many_to_attr_set(struct attribute_set
* s
,
679 struct attribute
**attr
,
684 for (i
= 0; i
< count
; i
++) {
685 res
= add_to_attr_set(s
, attr
[i
]);
693 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
695 sysfs_remove_group(kobj
, &s
->group
);
699 static int parse_strtoul(const char *buf
,
700 unsigned long max
, unsigned long *value
)
704 *value
= simple_strtoul(buf
, &endp
, 0);
705 while (*endp
&& isspace(*endp
))
707 if (*endp
|| *value
> max
)
713 /****************************************************************************
714 ****************************************************************************
718 ****************************************************************************
719 ****************************************************************************/
721 /*************************************************************************
722 * thinkpad-acpi init subdriver
725 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
727 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
728 printk(IBM_INFO
"%s\n", IBM_URL
);
730 printk(IBM_INFO
"ThinkPad BIOS %s, EC %s\n",
731 (thinkpad_id
.bios_version_str
) ?
732 thinkpad_id
.bios_version_str
: "unknown",
733 (thinkpad_id
.ec_version_str
) ?
734 thinkpad_id
.ec_version_str
: "unknown");
736 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
737 printk(IBM_INFO
"%s %s\n",
738 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
739 "IBM" : ((thinkpad_id
.vendor
==
740 PCI_VENDOR_ID_LENOVO
) ?
741 "Lenovo" : "Unknown vendor"),
742 thinkpad_id
.model_str
);
747 static int thinkpad_acpi_driver_read(char *p
)
751 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
752 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
757 static struct ibm_struct thinkpad_acpi_driver_data
= {
759 .read
= thinkpad_acpi_driver_read
,
762 /*************************************************************************
766 static int hotkey_orig_status
;
767 static u32 hotkey_orig_mask
;
768 static u32 hotkey_all_mask
;
769 static u32 hotkey_reserved_mask
;
771 static u16
*hotkey_keycode_map
;
773 static struct attribute_set
*hotkey_dev_attributes
;
775 static int hotkey_get_wlsw(int *status
)
777 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
782 /* sysfs hotkey enable ------------------------------------------------- */
783 static ssize_t
hotkey_enable_show(struct device
*dev
,
784 struct device_attribute
*attr
,
790 res
= hotkey_get(&status
, &mask
);
794 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
797 static ssize_t
hotkey_enable_store(struct device
*dev
,
798 struct device_attribute
*attr
,
799 const char *buf
, size_t count
)
805 if (parse_strtoul(buf
, 1, &t
))
808 res
= hotkey_get(&status
, &mask
);
810 res
= hotkey_set(t
, mask
);
812 return (res
) ? res
: count
;
815 static struct device_attribute dev_attr_hotkey_enable
=
816 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
817 hotkey_enable_show
, hotkey_enable_store
);
819 /* sysfs hotkey mask --------------------------------------------------- */
820 static ssize_t
hotkey_mask_show(struct device
*dev
,
821 struct device_attribute
*attr
,
827 res
= hotkey_get(&status
, &mask
);
831 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
834 static ssize_t
hotkey_mask_store(struct device
*dev
,
835 struct device_attribute
*attr
,
836 const char *buf
, size_t count
)
842 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
845 res
= hotkey_get(&status
, &mask
);
847 hotkey_set(status
, t
);
849 return (res
) ? res
: count
;
852 static struct device_attribute dev_attr_hotkey_mask
=
853 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
854 hotkey_mask_show
, hotkey_mask_store
);
856 /* sysfs hotkey bios_enabled ------------------------------------------- */
857 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
858 struct device_attribute
*attr
,
861 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
864 static struct device_attribute dev_attr_hotkey_bios_enabled
=
865 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
867 /* sysfs hotkey bios_mask ---------------------------------------------- */
868 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
869 struct device_attribute
*attr
,
872 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
875 static struct device_attribute dev_attr_hotkey_bios_mask
=
876 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
878 /* sysfs hotkey all_mask ----------------------------------------------- */
879 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
880 struct device_attribute
*attr
,
883 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_all_mask
);
886 static struct device_attribute dev_attr_hotkey_all_mask
=
887 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
889 /* sysfs hotkey recommended_mask --------------------------------------- */
890 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
891 struct device_attribute
*attr
,
894 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
895 hotkey_all_mask
& ~hotkey_reserved_mask
);
898 static struct device_attribute dev_attr_hotkey_recommended_mask
=
899 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
900 hotkey_recommended_mask_show
, NULL
);
902 /* sysfs hotkey radio_sw ----------------------------------------------- */
903 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
904 struct device_attribute
*attr
,
908 res
= hotkey_get_wlsw(&s
);
912 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
915 static struct device_attribute dev_attr_hotkey_radio_sw
=
916 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
918 /* sysfs hotkey report_mode -------------------------------------------- */
919 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
920 struct device_attribute
*attr
,
923 return snprintf(buf
, PAGE_SIZE
, "%d\n",
924 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
927 static ssize_t
hotkey_report_mode_store(struct device
*dev
,
928 struct device_attribute
*attr
,
929 const char *buf
, size_t count
)
934 if (parse_strtoul(buf
, 2, &t
) || (t
< 1))
937 if (t
!= hotkey_report_mode
) {
938 if (tp_features
.hotkey_report_mode_locked
)
940 hotkey_report_mode
= t
;
941 printk(IBM_NOTICE
"hot key report mode set to %d\n",
945 return (res
) ? res
: count
;
948 static struct device_attribute dev_attr_hotkey_report_mode
=
949 __ATTR(hotkey_report_mode
, S_IWUSR
| S_IRUGO
,
950 hotkey_report_mode_show
, hotkey_report_mode_store
);
952 /* --------------------------------------------------------------------- */
954 static struct attribute
*hotkey_attributes
[] __initdata
= {
955 &dev_attr_hotkey_enable
.attr
,
956 &dev_attr_hotkey_report_mode
.attr
,
959 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
960 &dev_attr_hotkey_mask
.attr
,
961 &dev_attr_hotkey_bios_enabled
.attr
,
962 &dev_attr_hotkey_bios_mask
.attr
,
963 &dev_attr_hotkey_all_mask
.attr
,
964 &dev_attr_hotkey_recommended_mask
.attr
,
967 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
970 static u16 ibm_keycode_map
[] __initdata
= {
971 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
972 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
973 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
974 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
975 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
976 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
977 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
978 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
979 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
980 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
981 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
982 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
983 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
984 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
985 KEY_RESERVED
, /* 0x14: VOLUME UP */
986 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
987 KEY_RESERVED
, /* 0x16: MUTE */
988 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
989 /* (assignments unknown, please report if found) */
990 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
991 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
993 static u16 lenovo_keycode_map
[] __initdata
= {
994 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
995 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
996 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
997 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
998 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
999 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1000 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1001 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1002 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
1003 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1004 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
1005 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1006 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1007 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1008 KEY_RESERVED
, /* 0x14: VOLUME UP */
1009 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1010 KEY_RESERVED
, /* 0x16: MUTE */
1011 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1012 /* (assignments unknown, please report if found) */
1013 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1014 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1017 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1018 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1019 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1025 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1027 BUG_ON(!tpacpi_inputdev
);
1029 IBM_ACPIHANDLE_INIT(hkey
);
1030 mutex_init(&hotkey_mutex
);
1032 /* hotkey not supported on 570 */
1033 tp_features
.hotkey
= hkey_handle
!= NULL
;
1035 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1036 str_supported(tp_features
.hotkey
));
1038 if (tp_features
.hotkey
) {
1039 hotkey_dev_attributes
= create_attr_set(8, NULL
);
1040 if (!hotkey_dev_attributes
)
1042 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1044 ARRAY_SIZE(hotkey_attributes
));
1048 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1049 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1050 for HKEY interface version 0x100 */
1051 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1052 if ((hkeyv
>> 8) != 1) {
1053 printk(IBM_ERR
"unknown version of the "
1054 "HKEY interface: 0x%x\n", hkeyv
);
1055 printk(IBM_ERR
"please report this to %s\n",
1059 * MHKV 0x100 in A31, R40, R40e,
1060 * T4x, X31, and later
1062 tp_features
.hotkey_mask
= 1;
1066 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1067 str_supported(tp_features
.hotkey_mask
));
1069 if (tp_features
.hotkey_mask
) {
1070 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1073 "missing MHKA handler, "
1074 "please report this to %s\n",
1076 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
1080 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
1081 if (!res
&& tp_features
.hotkey_mask
) {
1082 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1083 hotkey_mask_attributes
,
1084 ARRAY_SIZE(hotkey_mask_attributes
));
1087 /* Not all thinkpads have a hardware radio switch */
1088 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1089 tp_features
.hotkey_wlsw
= 1;
1091 "radio switch found; radios are %s\n",
1092 enabled(status
, 0));
1093 res
= add_to_attr_set(hotkey_dev_attributes
,
1094 &dev_attr_hotkey_radio_sw
.attr
);
1098 res
= register_attr_set_with_sysfs(
1099 hotkey_dev_attributes
,
1100 &tpacpi_pdev
->dev
.kobj
);
1104 /* Set up key map */
1106 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1108 if (!hotkey_keycode_map
) {
1109 printk(IBM_ERR
"failed to allocate memory for key map\n");
1113 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1114 dbg_printk(TPACPI_DBG_INIT
,
1115 "using Lenovo default hot key map\n");
1116 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1117 TPACPI_HOTKEY_MAP_SIZE
);
1119 dbg_printk(TPACPI_DBG_INIT
,
1120 "using IBM default hot key map\n");
1121 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1122 TPACPI_HOTKEY_MAP_SIZE
);
1125 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1126 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1127 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1128 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1129 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1130 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1131 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1132 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1133 set_bit(hotkey_keycode_map
[i
],
1134 tpacpi_inputdev
->keybit
);
1136 if (i
< sizeof(hotkey_reserved_mask
)*8)
1137 hotkey_reserved_mask
|= 1 << i
;
1141 if (tp_features
.hotkey_wlsw
) {
1142 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1143 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1146 dbg_printk(TPACPI_DBG_INIT
,
1147 "enabling hot key handling\n");
1148 res
= hotkey_set(1, (hotkey_all_mask
& ~hotkey_reserved_mask
)
1149 | hotkey_orig_mask
);
1153 if (hotkey_report_mode
> 0) {
1154 tp_features
.hotkey_report_mode_locked
= 1;
1156 hotkey_report_mode
= 1;
1157 vdbg_printk(TPACPI_DBG_INIT
,
1158 "hot key reporting mode can be "
1159 "changed at runtime\n");
1162 dbg_printk(TPACPI_DBG_INIT
,
1163 "legacy hot key reporting over procfs %s\n",
1164 (hotkey_report_mode
< 2) ?
1165 "enabled" : "disabled");
1168 return (tp_features
.hotkey
)? 0 : 1;
1171 static void hotkey_exit(void)
1175 if (tp_features
.hotkey
) {
1176 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
1177 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
1179 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
1182 if (hotkey_dev_attributes
) {
1183 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1184 hotkey_dev_attributes
= NULL
;
1188 static void tpacpi_input_send_key(unsigned int scancode
,
1189 unsigned int keycode
)
1191 if (keycode
!= KEY_RESERVED
) {
1192 mutex_lock(&tpacpi_inputdev_send_mutex
);
1194 input_report_key(tpacpi_inputdev
, keycode
, 1);
1195 if (keycode
== KEY_UNKNOWN
)
1196 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1198 input_sync(tpacpi_inputdev
);
1200 input_report_key(tpacpi_inputdev
, keycode
, 0);
1201 if (keycode
== KEY_UNKNOWN
)
1202 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1204 input_sync(tpacpi_inputdev
);
1206 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1210 static void tpacpi_input_send_radiosw(void)
1214 mutex_lock(&tpacpi_inputdev_send_mutex
);
1216 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1217 input_report_switch(tpacpi_inputdev
,
1219 input_sync(tpacpi_inputdev
);
1222 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1225 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1228 unsigned int keycode
, scancode
;
1231 if (event
!= 0x80) {
1232 printk(IBM_ERR
"unknown HKEY notification event %d\n", event
);
1233 /* forward it to userspace, maybe it knows how to handle it */
1234 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1240 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1241 printk(IBM_ERR
"failed to retrieve HKEY event\n");
1252 switch (hkey
>> 12) {
1254 /* 0x1000-0x1FFF: key presses */
1255 scancode
= hkey
& 0xfff;
1256 if (scancode
> 0 && scancode
< 0x21) {
1258 keycode
= hotkey_keycode_map
[scancode
];
1259 tpacpi_input_send_key(scancode
, keycode
);
1262 "hotkey 0x%04x out of range for keyboard map\n",
1268 /* 0x5000-0x5FFF: LID */
1269 /* we don't handle it through this path, just
1270 * eat up known LID events */
1271 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1273 "unknown LID-related HKEY event: 0x%04x\n",
1279 /* 0x7000-0x7FFF: misc */
1280 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1281 tpacpi_input_send_radiosw();
1284 /* fallthrough to default */
1286 /* case 2: dock-related */
1287 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1288 /* case 3: ultra-bay related. maybe bay in dock? */
1289 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1290 printk(IBM_NOTICE
"unhandled HKEY event 0x%04x\n", hkey
);
1294 if (send_acpi_ev
|| hotkey_report_mode
< 2) {
1295 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
1300 static void hotkey_resume(void)
1302 tpacpi_input_send_radiosw();
1306 * Call with hotkey_mutex held
1308 static int hotkey_get(int *status
, u32
*mask
)
1310 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1313 if (tp_features
.hotkey_mask
)
1314 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1321 * Call with hotkey_mutex held
1323 static int hotkey_set(int status
, u32 mask
)
1327 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1330 if (tp_features
.hotkey_mask
)
1331 for (i
= 0; i
< 32; i
++) {
1332 int bit
= ((1 << i
) & mask
) != 0;
1333 if (!acpi_evalf(hkey_handle
,
1334 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1341 /* procfs -------------------------------------------------------------- */
1342 static int hotkey_read(char *p
)
1348 if (!tp_features
.hotkey
) {
1349 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1353 res
= mutex_lock_interruptible(&hotkey_mutex
);
1356 res
= hotkey_get(&status
, &mask
);
1357 mutex_unlock(&hotkey_mutex
);
1361 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1362 if (tp_features
.hotkey_mask
) {
1363 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1364 len
+= sprintf(p
+ len
,
1365 "commands:\tenable, disable, reset, <mask>\n");
1367 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1368 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1374 static int hotkey_write(char *buf
)
1381 if (!tp_features
.hotkey
)
1384 res
= mutex_lock_interruptible(&hotkey_mutex
);
1388 res
= hotkey_get(&status
, &mask
);
1393 while ((cmd
= next_cmd(&buf
))) {
1394 if (strlencmp(cmd
, "enable") == 0) {
1396 } else if (strlencmp(cmd
, "disable") == 0) {
1398 } else if (strlencmp(cmd
, "reset") == 0) {
1399 status
= hotkey_orig_status
;
1400 mask
= hotkey_orig_mask
;
1401 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1403 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1413 res
= hotkey_set(status
, mask
);
1416 mutex_unlock(&hotkey_mutex
);
1420 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1421 .hid
= IBM_HKEY_HID
,
1422 .notify
= hotkey_notify
,
1423 .handle
= &hkey_handle
,
1424 .type
= ACPI_DEVICE_NOTIFY
,
1427 static struct ibm_struct hotkey_driver_data
= {
1429 .read
= hotkey_read
,
1430 .write
= hotkey_write
,
1431 .exit
= hotkey_exit
,
1432 .resume
= hotkey_resume
,
1433 .acpi
= &ibm_hotkey_acpidriver
,
1436 /*************************************************************************
1437 * Bluetooth subdriver
1440 /* sysfs bluetooth enable ---------------------------------------------- */
1441 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1442 struct device_attribute
*attr
,
1447 status
= bluetooth_get_radiosw();
1451 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1454 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1455 struct device_attribute
*attr
,
1456 const char *buf
, size_t count
)
1461 if (parse_strtoul(buf
, 1, &t
))
1464 res
= bluetooth_set_radiosw(t
);
1466 return (res
) ? res
: count
;
1469 static struct device_attribute dev_attr_bluetooth_enable
=
1470 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1471 bluetooth_enable_show
, bluetooth_enable_store
);
1473 /* --------------------------------------------------------------------- */
1475 static struct attribute
*bluetooth_attributes
[] = {
1476 &dev_attr_bluetooth_enable
.attr
,
1480 static const struct attribute_group bluetooth_attr_group
= {
1481 .attrs
= bluetooth_attributes
,
1484 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1489 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1491 IBM_ACPIHANDLE_INIT(hkey
);
1493 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1494 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1495 tp_features
.bluetooth
= hkey_handle
&&
1496 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1498 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1499 str_supported(tp_features
.bluetooth
),
1502 if (tp_features
.bluetooth
) {
1503 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1504 /* no bluetooth hardware present in system */
1505 tp_features
.bluetooth
= 0;
1506 dbg_printk(TPACPI_DBG_INIT
,
1507 "bluetooth hardware not installed\n");
1509 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1510 &bluetooth_attr_group
);
1516 return (tp_features
.bluetooth
)? 0 : 1;
1519 static void bluetooth_exit(void)
1521 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1522 &bluetooth_attr_group
);
1525 static int bluetooth_get_radiosw(void)
1529 if (!tp_features
.bluetooth
)
1532 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1535 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1538 static int bluetooth_set_radiosw(int radio_on
)
1542 if (!tp_features
.bluetooth
)
1545 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1548 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1550 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1551 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1557 /* procfs -------------------------------------------------------------- */
1558 static int bluetooth_read(char *p
)
1561 int status
= bluetooth_get_radiosw();
1563 if (!tp_features
.bluetooth
)
1564 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1566 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1567 (status
)? "enabled" : "disabled");
1568 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1574 static int bluetooth_write(char *buf
)
1578 if (!tp_features
.bluetooth
)
1581 while ((cmd
= next_cmd(&buf
))) {
1582 if (strlencmp(cmd
, "enable") == 0) {
1583 bluetooth_set_radiosw(1);
1584 } else if (strlencmp(cmd
, "disable") == 0) {
1585 bluetooth_set_radiosw(0);
1593 static struct ibm_struct bluetooth_driver_data
= {
1594 .name
= "bluetooth",
1595 .read
= bluetooth_read
,
1596 .write
= bluetooth_write
,
1597 .exit
= bluetooth_exit
,
1600 /*************************************************************************
1604 /* sysfs wan enable ---------------------------------------------------- */
1605 static ssize_t
wan_enable_show(struct device
*dev
,
1606 struct device_attribute
*attr
,
1611 status
= wan_get_radiosw();
1615 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1618 static ssize_t
wan_enable_store(struct device
*dev
,
1619 struct device_attribute
*attr
,
1620 const char *buf
, size_t count
)
1625 if (parse_strtoul(buf
, 1, &t
))
1628 res
= wan_set_radiosw(t
);
1630 return (res
) ? res
: count
;
1633 static struct device_attribute dev_attr_wan_enable
=
1634 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1635 wan_enable_show
, wan_enable_store
);
1637 /* --------------------------------------------------------------------- */
1639 static struct attribute
*wan_attributes
[] = {
1640 &dev_attr_wan_enable
.attr
,
1644 static const struct attribute_group wan_attr_group
= {
1645 .attrs
= wan_attributes
,
1648 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1653 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1655 IBM_ACPIHANDLE_INIT(hkey
);
1657 tp_features
.wan
= hkey_handle
&&
1658 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1660 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1661 str_supported(tp_features
.wan
),
1664 if (tp_features
.wan
) {
1665 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1666 /* no wan hardware present in system */
1667 tp_features
.wan
= 0;
1668 dbg_printk(TPACPI_DBG_INIT
,
1669 "wan hardware not installed\n");
1671 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1678 return (tp_features
.wan
)? 0 : 1;
1681 static void wan_exit(void)
1683 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1687 static int wan_get_radiosw(void)
1691 if (!tp_features
.wan
)
1694 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1697 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1700 static int wan_set_radiosw(int radio_on
)
1704 if (!tp_features
.wan
)
1707 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1710 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1712 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1713 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1719 /* procfs -------------------------------------------------------------- */
1720 static int wan_read(char *p
)
1723 int status
= wan_get_radiosw();
1725 if (!tp_features
.wan
)
1726 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1728 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1729 (status
)? "enabled" : "disabled");
1730 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1736 static int wan_write(char *buf
)
1740 if (!tp_features
.wan
)
1743 while ((cmd
= next_cmd(&buf
))) {
1744 if (strlencmp(cmd
, "enable") == 0) {
1746 } else if (strlencmp(cmd
, "disable") == 0) {
1755 static struct ibm_struct wan_driver_data
= {
1760 .flags
.experimental
= 1,
1763 /*************************************************************************
1767 static enum video_access_mode video_supported
;
1768 static int video_orig_autosw
;
1770 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1771 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1772 "\\_SB.PCI0.VID0", /* 770e */
1773 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1774 "\\_SB.PCI0.AGP.VID", /* all others */
1777 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1779 static int __init
video_init(struct ibm_init_struct
*iibm
)
1783 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1785 IBM_ACPIHANDLE_INIT(vid
);
1786 IBM_ACPIHANDLE_INIT(vid2
);
1788 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1789 /* G41, assume IVGA doesn't change */
1790 vid_handle
= vid2_handle
;
1793 /* video switching not supported on R30, R31 */
1794 video_supported
= TPACPI_VIDEO_NONE
;
1795 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1797 video_supported
= TPACPI_VIDEO_570
;
1798 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1799 /* 600e/x, 770e, 770x */
1800 video_supported
= TPACPI_VIDEO_770
;
1803 video_supported
= TPACPI_VIDEO_NEW
;
1805 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1806 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1809 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1812 static void video_exit(void)
1814 dbg_printk(TPACPI_DBG_EXIT
,
1815 "restoring original video autoswitch mode\n");
1816 if (video_autosw_set(video_orig_autosw
))
1817 printk(IBM_ERR
"error while trying to restore original "
1818 "video autoswitch mode\n");
1821 static int video_outputsw_get(void)
1826 switch (video_supported
) {
1827 case TPACPI_VIDEO_570
:
1828 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1829 TP_ACPI_VIDEO_570_PHSCMD
))
1831 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1833 case TPACPI_VIDEO_770
:
1834 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1837 status
|= TP_ACPI_VIDEO_S_LCD
;
1838 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1841 status
|= TP_ACPI_VIDEO_S_CRT
;
1843 case TPACPI_VIDEO_NEW
:
1844 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1845 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1848 status
|= TP_ACPI_VIDEO_S_CRT
;
1850 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1851 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1854 status
|= TP_ACPI_VIDEO_S_LCD
;
1855 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1858 status
|= TP_ACPI_VIDEO_S_DVI
;
1867 static int video_outputsw_set(int status
)
1872 switch (video_supported
) {
1873 case TPACPI_VIDEO_570
:
1874 res
= acpi_evalf(NULL
, NULL
,
1875 "\\_SB.PHS2", "vdd",
1876 TP_ACPI_VIDEO_570_PHS2CMD
,
1877 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1879 case TPACPI_VIDEO_770
:
1880 autosw
= video_autosw_get();
1884 res
= video_autosw_set(1);
1887 res
= acpi_evalf(vid_handle
, NULL
,
1888 "ASWT", "vdd", status
* 0x100, 0);
1889 if (!autosw
&& video_autosw_set(autosw
)) {
1890 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1894 case TPACPI_VIDEO_NEW
:
1895 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1896 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1902 return (res
)? 0 : -EIO
;
1905 static int video_autosw_get(void)
1909 switch (video_supported
) {
1910 case TPACPI_VIDEO_570
:
1911 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1914 case TPACPI_VIDEO_770
:
1915 case TPACPI_VIDEO_NEW
:
1916 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1926 static int video_autosw_set(int enable
)
1928 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1933 static int video_outputsw_cycle(void)
1935 int autosw
= video_autosw_get();
1941 switch (video_supported
) {
1942 case TPACPI_VIDEO_570
:
1943 res
= video_autosw_set(1);
1946 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1948 case TPACPI_VIDEO_770
:
1949 case TPACPI_VIDEO_NEW
:
1950 res
= video_autosw_set(1);
1953 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1958 if (!autosw
&& video_autosw_set(autosw
)) {
1959 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1963 return (res
)? 0 : -EIO
;
1966 static int video_expand_toggle(void)
1968 switch (video_supported
) {
1969 case TPACPI_VIDEO_570
:
1970 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1972 case TPACPI_VIDEO_770
:
1973 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1975 case TPACPI_VIDEO_NEW
:
1976 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1984 static int video_read(char *p
)
1989 if (video_supported
== TPACPI_VIDEO_NONE
) {
1990 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1994 status
= video_outputsw_get();
1998 autosw
= video_autosw_get();
2002 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2003 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2004 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2005 if (video_supported
== TPACPI_VIDEO_NEW
)
2006 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2007 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2008 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2009 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2010 if (video_supported
== TPACPI_VIDEO_NEW
)
2011 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2012 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2013 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2018 static int video_write(char *buf
)
2021 int enable
, disable
, status
;
2024 if (video_supported
== TPACPI_VIDEO_NONE
)
2030 while ((cmd
= next_cmd(&buf
))) {
2031 if (strlencmp(cmd
, "lcd_enable") == 0) {
2032 enable
|= TP_ACPI_VIDEO_S_LCD
;
2033 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2034 disable
|= TP_ACPI_VIDEO_S_LCD
;
2035 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2036 enable
|= TP_ACPI_VIDEO_S_CRT
;
2037 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2038 disable
|= TP_ACPI_VIDEO_S_CRT
;
2039 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2040 strlencmp(cmd
, "dvi_enable") == 0) {
2041 enable
|= TP_ACPI_VIDEO_S_DVI
;
2042 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2043 strlencmp(cmd
, "dvi_disable") == 0) {
2044 disable
|= TP_ACPI_VIDEO_S_DVI
;
2045 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2046 res
= video_autosw_set(1);
2049 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2050 res
= video_autosw_set(0);
2053 } else if (strlencmp(cmd
, "video_switch") == 0) {
2054 res
= video_outputsw_cycle();
2057 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2058 res
= video_expand_toggle();
2065 if (enable
|| disable
) {
2066 status
= video_outputsw_get();
2069 res
= video_outputsw_set((status
& ~disable
) | enable
);
2077 static struct ibm_struct video_driver_data
= {
2080 .write
= video_write
,
2084 /*************************************************************************
2085 * Light (thinklight) subdriver
2088 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2089 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2091 static int __init
light_init(struct ibm_init_struct
*iibm
)
2093 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2095 IBM_ACPIHANDLE_INIT(ledb
);
2096 IBM_ACPIHANDLE_INIT(lght
);
2097 IBM_ACPIHANDLE_INIT(cmos
);
2099 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2100 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2102 if (tp_features
.light
)
2103 /* light status not supported on
2104 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2105 tp_features
.light_status
=
2106 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2108 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2109 str_supported(tp_features
.light
));
2111 return (tp_features
.light
)? 0 : 1;
2114 static int light_read(char *p
)
2119 if (!tp_features
.light
) {
2120 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2121 } else if (!tp_features
.light_status
) {
2122 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2123 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2125 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2127 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2128 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2134 static int light_write(char *buf
)
2136 int cmos_cmd
, lght_cmd
;
2140 if (!tp_features
.light
)
2143 while ((cmd
= next_cmd(&buf
))) {
2144 if (strlencmp(cmd
, "on") == 0) {
2147 } else if (strlencmp(cmd
, "off") == 0) {
2153 success
= cmos_handle
?
2154 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2155 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2163 static struct ibm_struct light_driver_data
= {
2166 .write
= light_write
,
2169 /*************************************************************************
2173 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2175 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2176 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2177 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2178 "\\_SB.PCI.ISA.SLCE", /* 570 */
2179 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2181 /* don't list other alternatives as we install a notify handler on the 570 */
2182 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2184 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2186 .notify
= dock_notify
,
2187 .handle
= &dock_handle
,
2188 .type
= ACPI_SYSTEM_NOTIFY
,
2191 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2192 * We just use it to get notifications of dock hotplug
2193 * in very old thinkpads */
2194 .hid
= PCI_ROOT_HID_STRING
,
2195 .notify
= dock_notify
,
2196 .handle
= &pci_handle
,
2197 .type
= ACPI_SYSTEM_NOTIFY
,
2201 static struct ibm_struct dock_driver_data
[2] = {
2205 .write
= dock_write
,
2206 .acpi
= &ibm_dock_acpidriver
[0],
2210 .acpi
= &ibm_dock_acpidriver
[1],
2214 #define dock_docked() (_sta(dock_handle) & 1)
2216 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2218 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2220 IBM_ACPIHANDLE_INIT(dock
);
2222 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2223 str_supported(dock_handle
!= NULL
));
2225 return (dock_handle
)? 0 : 1;
2228 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2232 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2234 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2235 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2236 IBM_ACPIHANDLE_INIT(pci
);
2237 dock2_needed
= (pci_handle
!= NULL
);
2238 vdbg_printk(TPACPI_DBG_INIT
,
2239 "dock PCI handler for the TP 570 is %s\n",
2240 str_supported(dock2_needed
));
2242 vdbg_printk(TPACPI_DBG_INIT
,
2243 "dock subdriver part 2 not required\n");
2247 return (dock2_needed
)? 0 : 1;
2250 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2252 int docked
= dock_docked();
2253 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, PCI_ROOT_HID_STRING
);
2255 if (event
== 1 && !pci
) /* 570 */
2256 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2257 else if (event
== 1 && pci
) /* 570 */
2258 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2259 else if (event
== 3 && docked
)
2260 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2261 else if (event
== 3 && !docked
)
2262 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
2263 else if (event
== 0 && docked
)
2264 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2266 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2267 event
, _sta(dock_handle
));
2268 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
2272 static int dock_read(char *p
)
2275 int docked
= dock_docked();
2278 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2280 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2282 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2283 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2289 static int dock_write(char *buf
)
2296 while ((cmd
= next_cmd(&buf
))) {
2297 if (strlencmp(cmd
, "undock") == 0) {
2298 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2299 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2301 } else if (strlencmp(cmd
, "dock") == 0) {
2302 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2311 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2313 /*************************************************************************
2317 #ifdef CONFIG_THINKPAD_ACPI_BAY
2318 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2319 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2320 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2321 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2322 ); /* A21e, R30, R31 */
2323 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2324 "_EJ0", /* all others */
2325 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2326 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2327 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2329 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2333 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2335 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2337 IBM_ACPIHANDLE_INIT(bay
);
2339 IBM_ACPIHANDLE_INIT(bay_ej
);
2340 IBM_ACPIHANDLE_INIT(bay2
);
2342 IBM_ACPIHANDLE_INIT(bay2_ej
);
2344 tp_features
.bay_status
= bay_handle
&&
2345 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2346 tp_features
.bay_status2
= bay2_handle
&&
2347 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2349 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2350 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2351 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2352 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2354 vdbg_printk(TPACPI_DBG_INIT
,
2355 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2356 str_supported(tp_features
.bay_status
),
2357 str_supported(tp_features
.bay_eject
),
2358 str_supported(tp_features
.bay_status2
),
2359 str_supported(tp_features
.bay_eject2
));
2361 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2362 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2365 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2367 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
2370 #define bay_occupied(b) (_sta(b##_handle) & 1)
2372 static int bay_read(char *p
)
2375 int occupied
= bay_occupied(bay
);
2376 int occupied2
= bay_occupied(bay2
);
2379 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2380 tp_features
.bay_status
?
2381 (occupied
? "occupied" : "unoccupied") :
2383 if (tp_features
.bay_status2
)
2384 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2385 "occupied" : "unoccupied");
2387 eject
= tp_features
.bay_eject
&& occupied
;
2388 eject2
= tp_features
.bay_eject2
&& occupied2
;
2390 if (eject
&& eject2
)
2391 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2393 len
+= sprintf(p
+ len
, "commands:\teject\n");
2395 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2400 static int bay_write(char *buf
)
2404 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2407 while ((cmd
= next_cmd(&buf
))) {
2408 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2409 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2411 } else if (tp_features
.bay_eject2
&&
2412 strlencmp(cmd
, "eject2") == 0) {
2413 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2422 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2423 .notify
= bay_notify
,
2424 .handle
= &bay_handle
,
2425 .type
= ACPI_SYSTEM_NOTIFY
,
2428 static struct ibm_struct bay_driver_data
= {
2432 .acpi
= &ibm_bay_acpidriver
,
2435 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2437 /*************************************************************************
2441 /* sysfs cmos_command -------------------------------------------------- */
2442 static ssize_t
cmos_command_store(struct device
*dev
,
2443 struct device_attribute
*attr
,
2444 const char *buf
, size_t count
)
2446 unsigned long cmos_cmd
;
2449 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2452 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2453 return (res
)? res
: count
;
2456 static struct device_attribute dev_attr_cmos_command
=
2457 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2459 /* --------------------------------------------------------------------- */
2461 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2465 vdbg_printk(TPACPI_DBG_INIT
,
2466 "initializing cmos commands subdriver\n");
2468 IBM_ACPIHANDLE_INIT(cmos
);
2470 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2471 str_supported(cmos_handle
!= NULL
));
2473 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2477 return (cmos_handle
)? 0 : 1;
2480 static void cmos_exit(void)
2482 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2485 static int cmos_read(char *p
)
2489 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2490 R30, R31, T20-22, X20-21 */
2492 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2494 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2495 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2501 static int cmos_write(char *buf
)
2506 while ((cmd
= next_cmd(&buf
))) {
2507 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2508 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2513 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2521 static struct ibm_struct cmos_driver_data
= {
2524 .write
= cmos_write
,
2528 /*************************************************************************
2532 static enum led_access_mode led_supported
;
2534 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2535 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2536 "LED", /* all others */
2539 static int __init
led_init(struct ibm_init_struct
*iibm
)
2541 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2543 IBM_ACPIHANDLE_INIT(led
);
2546 /* led not supported on R30, R31 */
2547 led_supported
= TPACPI_LED_NONE
;
2548 else if (strlencmp(led_path
, "SLED") == 0)
2550 led_supported
= TPACPI_LED_570
;
2551 else if (strlencmp(led_path
, "SYSL") == 0)
2552 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2553 led_supported
= TPACPI_LED_OLD
;
2556 led_supported
= TPACPI_LED_NEW
;
2558 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2559 str_supported(led_supported
), led_supported
);
2561 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2564 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2566 static int led_read(char *p
)
2570 if (!led_supported
) {
2571 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2574 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2576 if (led_supported
== TPACPI_LED_570
) {
2579 for (i
= 0; i
< 8; i
++) {
2580 if (!acpi_evalf(ec_handle
,
2581 &status
, "GLED", "dd", 1 << i
))
2583 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2584 i
, led_status(status
));
2588 len
+= sprintf(p
+ len
, "commands:\t"
2589 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2594 /* off, on, blink */
2595 static const int led_sled_arg1
[] = { 0, 1, 3 };
2596 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2597 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2598 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2600 static int led_write(char *buf
)
2608 while ((cmd
= next_cmd(&buf
))) {
2609 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2612 if (strstr(cmd
, "off")) {
2614 } else if (strstr(cmd
, "on")) {
2616 } else if (strstr(cmd
, "blink")) {
2621 if (led_supported
== TPACPI_LED_570
) {
2624 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2625 led
, led_sled_arg1
[ind
]))
2627 } else if (led_supported
== TPACPI_LED_OLD
) {
2628 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2630 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2633 ec_write(TPACPI_LED_EC_HLBL
,
2634 led
* led_exp_hlbl
[ind
]);
2637 ec_write(TPACPI_LED_EC_HLCL
,
2638 led
* led_exp_hlcl
[ind
]);
2643 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2644 led
, led_led_arg1
[ind
]))
2652 static struct ibm_struct led_driver_data
= {
2658 /*************************************************************************
2662 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2664 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2666 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2668 IBM_ACPIHANDLE_INIT(beep
);
2670 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2671 str_supported(beep_handle
!= NULL
));
2673 return (beep_handle
)? 0 : 1;
2676 static int beep_read(char *p
)
2681 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2683 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2684 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2690 static int beep_write(char *buf
)
2698 while ((cmd
= next_cmd(&buf
))) {
2699 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2700 beep_cmd
>= 0 && beep_cmd
<= 17) {
2704 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2711 static struct ibm_struct beep_driver_data
= {
2714 .write
= beep_write
,
2717 /*************************************************************************
2721 static enum thermal_access_mode thermal_read_mode
;
2723 /* sysfs temp##_input -------------------------------------------------- */
2725 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2726 struct device_attribute
*attr
,
2729 struct sensor_device_attribute
*sensor_attr
=
2730 to_sensor_dev_attr(attr
);
2731 int idx
= sensor_attr
->index
;
2735 res
= thermal_get_sensor(idx
, &value
);
2738 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2741 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2744 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2745 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2747 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2748 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2749 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2750 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2751 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2752 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2753 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2754 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2755 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2756 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2757 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2758 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2759 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2760 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2761 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2762 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2763 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2766 #define THERMAL_ATTRS(X) \
2767 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2769 static struct attribute
*thermal_temp_input_attr
[] = {
2789 static const struct attribute_group thermal_temp_input16_group
= {
2790 .attrs
= thermal_temp_input_attr
2793 static const struct attribute_group thermal_temp_input8_group
= {
2794 .attrs
= &thermal_temp_input_attr
[8]
2797 #undef THERMAL_SENSOR_ATTR_TEMP
2798 #undef THERMAL_ATTRS
2800 /* --------------------------------------------------------------------- */
2802 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2809 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2811 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2813 if (thinkpad_id
.ec_model
) {
2815 * Direct EC access mode: sensors at registers
2816 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2817 * non-implemented, thermal sensors return 0x80 when
2822 for (i
= 0; i
< 8; i
++) {
2823 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2829 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2837 /* This is sheer paranoia, but we handle it anyway */
2840 "ThinkPad ACPI EC access misbehaving, "
2841 "falling back to ACPI TMPx access mode\n");
2842 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2845 "ThinkPad ACPI EC access misbehaving, "
2846 "disabling thermal sensors access\n");
2847 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2852 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2854 } else if (acpi_tmp7
) {
2855 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2856 /* 600e/x, 770e, 770x */
2857 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2859 /* Standard ACPI TMPx access, max 8 sensors */
2860 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2863 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2864 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2867 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2868 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2871 switch(thermal_read_mode
) {
2872 case TPACPI_THERMAL_TPEC_16
:
2873 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2874 &thermal_temp_input16_group
);
2878 case TPACPI_THERMAL_TPEC_8
:
2879 case TPACPI_THERMAL_ACPI_TMP07
:
2880 case TPACPI_THERMAL_ACPI_UPDT
:
2881 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2882 &thermal_temp_input8_group
);
2886 case TPACPI_THERMAL_NONE
:
2894 static void thermal_exit(void)
2896 switch(thermal_read_mode
) {
2897 case TPACPI_THERMAL_TPEC_16
:
2898 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2899 &thermal_temp_input16_group
);
2901 case TPACPI_THERMAL_TPEC_8
:
2902 case TPACPI_THERMAL_ACPI_TMP07
:
2903 case TPACPI_THERMAL_ACPI_UPDT
:
2904 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2905 &thermal_temp_input16_group
);
2907 case TPACPI_THERMAL_NONE
:
2913 /* idx is zero-based */
2914 static int thermal_get_sensor(int idx
, s32
*value
)
2920 t
= TP_EC_THERMAL_TMP0
;
2922 switch (thermal_read_mode
) {
2923 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2924 case TPACPI_THERMAL_TPEC_16
:
2925 if (idx
>= 8 && idx
<= 15) {
2926 t
= TP_EC_THERMAL_TMP8
;
2931 case TPACPI_THERMAL_TPEC_8
:
2933 if (!acpi_ec_read(t
+ idx
, &tmp
))
2935 *value
= tmp
* 1000;
2940 case TPACPI_THERMAL_ACPI_UPDT
:
2942 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2943 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2945 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2947 *value
= (t
- 2732) * 100;
2952 case TPACPI_THERMAL_ACPI_TMP07
:
2954 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2955 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2957 if (t
> 127 || t
< -127)
2958 t
= TP_EC_THERMAL_TMP_NA
;
2964 case TPACPI_THERMAL_NONE
:
2972 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2983 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2986 for(i
= 0 ; i
< n
; i
++) {
2987 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
2995 static int thermal_read(char *p
)
2999 struct ibm_thermal_sensors_struct t
;
3001 n
= thermal_get_sensors(&t
);
3002 if (unlikely(n
< 0))
3005 len
+= sprintf(p
+ len
, "temperatures:\t");
3008 for (i
= 0; i
< (n
- 1); i
++)
3009 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3010 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3012 len
+= sprintf(p
+ len
, "not supported\n");
3017 static struct ibm_struct thermal_driver_data
= {
3019 .read
= thermal_read
,
3020 .exit
= thermal_exit
,
3023 /*************************************************************************
3027 static u8 ecdump_regs
[256];
3029 static int ecdump_read(char *p
)
3035 len
+= sprintf(p
+ len
, "EC "
3036 " +00 +01 +02 +03 +04 +05 +06 +07"
3037 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
3038 for (i
= 0; i
< 256; i
+= 16) {
3039 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
3040 for (j
= 0; j
< 16; j
++) {
3041 if (!acpi_ec_read(i
+ j
, &v
))
3043 if (v
!= ecdump_regs
[i
+ j
])
3044 len
+= sprintf(p
+ len
, " *%02x", v
);
3046 len
+= sprintf(p
+ len
, " %02x", v
);
3047 ecdump_regs
[i
+ j
] = v
;
3049 len
+= sprintf(p
+ len
, "\n");
3054 /* These are way too dangerous to advertise openly... */
3056 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3057 " (<offset> is 00-ff, <value> is 00-ff)\n");
3058 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3059 " (<offset> is 00-ff, <value> is 0-255)\n");
3064 static int ecdump_write(char *buf
)
3069 while ((cmd
= next_cmd(&buf
))) {
3070 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3072 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3076 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3077 if (!acpi_ec_write(i
, v
))
3086 static struct ibm_struct ecdump_driver_data
= {
3088 .read
= ecdump_read
,
3089 .write
= ecdump_write
,
3090 .flags
.experimental
= 1,
3093 /*************************************************************************
3094 * Backlight/brightness subdriver
3097 static struct backlight_device
*ibm_backlight_device
;
3099 static struct backlight_ops ibm_backlight_data
= {
3100 .get_brightness
= brightness_get
,
3101 .update_status
= brightness_update_status
,
3104 static struct mutex brightness_mutex
;
3106 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
3110 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
3112 mutex_init(&brightness_mutex
);
3114 if (!brightness_mode
) {
3115 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
3116 brightness_mode
= 2;
3118 brightness_mode
= 3;
3120 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
3124 if (brightness_mode
> 3)
3127 b
= brightness_get(NULL
);
3131 ibm_backlight_device
= backlight_device_register(
3132 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
3133 &ibm_backlight_data
);
3134 if (IS_ERR(ibm_backlight_device
)) {
3135 printk(IBM_ERR
"Could not register backlight device\n");
3136 return PTR_ERR(ibm_backlight_device
);
3138 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
3140 ibm_backlight_device
->props
.max_brightness
= 7;
3141 ibm_backlight_device
->props
.brightness
= b
;
3142 backlight_update_status(ibm_backlight_device
);
3147 static void brightness_exit(void)
3149 if (ibm_backlight_device
) {
3150 vdbg_printk(TPACPI_DBG_EXIT
,
3151 "calling backlight_device_unregister()\n");
3152 backlight_device_unregister(ibm_backlight_device
);
3153 ibm_backlight_device
= NULL
;
3157 static int brightness_update_status(struct backlight_device
*bd
)
3159 return brightness_set(
3160 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
3161 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
3162 bd
->props
.brightness
: 0);
3166 * ThinkPads can read brightness from two places: EC 0x31, or
3167 * CMOS NVRAM byte 0x5E, bits 0-3.
3169 static int brightness_get(struct backlight_device
*bd
)
3171 u8 lec
= 0, lcmos
= 0, level
= 0;
3173 if (brightness_mode
& 1) {
3174 if (!acpi_ec_read(brightness_offset
, &lec
))
3179 if (brightness_mode
& 2) {
3180 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3181 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3182 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3186 if (brightness_mode
== 3 && lec
!= lcmos
) {
3188 "CMOS NVRAM (%u) and EC (%u) do not agree "
3189 "on display brightness level\n",
3190 (unsigned int) lcmos
,
3191 (unsigned int) lec
);
3198 static int brightness_set(int value
)
3200 int cmos_cmd
, inc
, i
, res
;
3206 res
= mutex_lock_interruptible(&brightness_mutex
);
3210 current_value
= brightness_get(NULL
);
3211 if (current_value
< 0) {
3212 res
= current_value
;
3216 cmos_cmd
= value
> current_value
?
3217 TP_CMOS_BRIGHTNESS_UP
:
3218 TP_CMOS_BRIGHTNESS_DOWN
;
3219 inc
= value
> current_value
? 1 : -1;
3222 for (i
= current_value
; i
!= value
; i
+= inc
) {
3223 if ((brightness_mode
& 2) &&
3224 issue_thinkpad_cmos_command(cmos_cmd
)) {
3228 if ((brightness_mode
& 1) &&
3229 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
3236 mutex_unlock(&brightness_mutex
);
3240 static int brightness_read(char *p
)
3245 if ((level
= brightness_get(NULL
)) < 0) {
3246 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3248 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
3249 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3250 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3251 " (<level> is 0-7)\n");
3257 static int brightness_write(char *buf
)
3263 while ((cmd
= next_cmd(&buf
))) {
3264 if ((level
= brightness_get(NULL
)) < 0)
3268 if (strlencmp(cmd
, "up") == 0) {
3269 new_level
= level
== 7 ? 7 : level
+ 1;
3270 } else if (strlencmp(cmd
, "down") == 0) {
3271 new_level
= level
== 0 ? 0 : level
- 1;
3272 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3273 new_level
>= 0 && new_level
<= 7) {
3278 brightness_set(new_level
);
3284 static struct ibm_struct brightness_driver_data
= {
3285 .name
= "brightness",
3286 .read
= brightness_read
,
3287 .write
= brightness_write
,
3288 .exit
= brightness_exit
,
3291 /*************************************************************************
3295 static int volume_read(char *p
)
3300 if (!acpi_ec_read(volume_offset
, &level
)) {
3301 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3303 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3304 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3305 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3306 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3307 " (<level> is 0-15)\n");
3313 static int volume_write(char *buf
)
3315 int cmos_cmd
, inc
, i
;
3317 int new_level
, new_mute
;
3320 while ((cmd
= next_cmd(&buf
))) {
3321 if (!acpi_ec_read(volume_offset
, &level
))
3323 new_mute
= mute
= level
& 0x40;
3324 new_level
= level
= level
& 0xf;
3326 if (strlencmp(cmd
, "up") == 0) {
3330 new_level
= level
== 15 ? 15 : level
+ 1;
3331 } else if (strlencmp(cmd
, "down") == 0) {
3335 new_level
= level
== 0 ? 0 : level
- 1;
3336 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3337 new_level
>= 0 && new_level
<= 15) {
3339 } else if (strlencmp(cmd
, "mute") == 0) {
3344 if (new_level
!= level
) { /* mute doesn't change */
3345 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3346 inc
= new_level
> level
? 1 : -1;
3348 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3349 !acpi_ec_write(volume_offset
, level
)))
3352 for (i
= level
; i
!= new_level
; i
+= inc
)
3353 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3354 !acpi_ec_write(volume_offset
, i
+ inc
))
3357 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3358 !acpi_ec_write(volume_offset
,
3363 if (new_mute
!= mute
) { /* level doesn't change */
3364 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3366 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3367 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3375 static struct ibm_struct volume_driver_data
= {
3377 .read
= volume_read
,
3378 .write
= volume_write
,
3381 /*************************************************************************
3388 * TPACPI_FAN_RD_ACPI_GFAN:
3389 * ACPI GFAN method: returns fan level
3391 * see TPACPI_FAN_WR_ACPI_SFAN
3392 * EC 0x2f (HFSP) not available if GFAN exists
3394 * TPACPI_FAN_WR_ACPI_SFAN:
3395 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3397 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3400 * TPACPI_FAN_WR_TPEC:
3401 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3402 * Supported on almost all ThinkPads
3404 * Fan speed changes of any sort (including those caused by the
3405 * disengaged mode) are usually done slowly by the firmware as the
3406 * maximum ammount of fan duty cycle change per second seems to be
3409 * Reading is not available if GFAN exists.
3410 * Writing is not available if SFAN exists.
3413 * 7 automatic mode engaged;
3414 * (default operation mode of the ThinkPad)
3415 * fan level is ignored in this mode.
3416 * 6 full speed mode (takes precedence over bit 7);
3417 * not available on all thinkpads. May disable
3418 * the tachometer while the fan controller ramps up
3419 * the speed (which can take up to a few *minutes*).
3420 * Speeds up fan to 100% duty-cycle, which is far above
3421 * the standard RPM levels. It is not impossible that
3422 * it could cause hardware damage.
3423 * 5-3 unused in some models. Extra bits for fan level
3424 * in others, but still useless as all values above
3425 * 7 map to the same speed as level 7 in these models.
3426 * 2-0 fan level (0..7 usually)
3428 * 0x07 = max (set when temperatures critical)
3429 * Some ThinkPads may have other levels, see
3430 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3432 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3433 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3434 * does so, its initial value is meaningless (0x07).
3436 * For firmware bugs, refer to:
3437 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3441 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3442 * Main fan tachometer reading (in RPM)
3444 * This register is present on all ThinkPads with a new-style EC, and
3445 * it is known not to be present on the A21m/e, and T22, as there is
3446 * something else in offset 0x84 according to the ACPI DSDT. Other
3447 * ThinkPads from this same time period (and earlier) probably lack the
3448 * tachometer as well.
3450 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3451 * was never fixed by IBM to report the EC firmware version string
3452 * probably support the tachometer (like the early X models), so
3453 * detecting it is quite hard. We need more data to know for sure.
3455 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3458 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3461 * For firmware bugs, refer to:
3462 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3464 * TPACPI_FAN_WR_ACPI_FANS:
3465 * ThinkPad X31, X40, X41. Not available in the X60.
3467 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3468 * high speed. ACPI DSDT seems to map these three speeds to levels
3469 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3470 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3472 * The speeds are stored on handles
3473 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3475 * There are three default speed sets, acessible as handles:
3476 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3478 * ACPI DSDT switches which set is in use depending on various
3481 * TPACPI_FAN_WR_TPEC is also available and should be used to
3482 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3483 * but the ACPI tables just mention level 7.
3486 static enum fan_status_access_mode fan_status_access_mode
;
3487 static enum fan_control_access_mode fan_control_access_mode
;
3488 static enum fan_control_commands fan_control_commands
;
3490 static u8 fan_control_initial_status
;
3491 static u8 fan_control_desired_level
;
3493 static void fan_watchdog_fire(struct work_struct
*ignored
);
3494 static int fan_watchdog_maxinterval
;
3495 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3497 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3498 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3499 "\\FSPD", /* 600e/x, 770e, 770x */
3501 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3502 "JFNS", /* 770x-JL */
3506 * SYSFS fan layout: hwmon compatible (device)
3509 * 0: "disengaged" mode
3511 * 2: native EC "auto" mode (recommended, hardware default)
3513 * pwm*: set speed in manual mode, ignored otherwise.
3514 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3517 * fan*_input: tachometer reading, RPM
3520 * SYSFS fan layout: extensions
3522 * fan_watchdog (driver):
3523 * fan watchdog interval in seconds, 0 disables (default), max 120
3526 /* sysfs fan pwm1_enable ----------------------------------------------- */
3527 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3528 struct device_attribute
*attr
,
3534 res
= fan_get_status_safe(&status
);
3538 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3539 if (status
!= fan_control_initial_status
) {
3540 tp_features
.fan_ctrl_status_undef
= 0;
3542 /* Return most likely status. In fact, it
3543 * might be the only possible status */
3544 status
= TP_EC_FAN_AUTO
;
3548 if (status
& TP_EC_FAN_FULLSPEED
) {
3550 } else if (status
& TP_EC_FAN_AUTO
) {
3555 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3558 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3559 struct device_attribute
*attr
,
3560 const char *buf
, size_t count
)
3565 if (parse_strtoul(buf
, 2, &t
))
3570 level
= TP_EC_FAN_FULLSPEED
;
3573 level
= TPACPI_FAN_LAST_LEVEL
;
3576 level
= TP_EC_FAN_AUTO
;
3579 /* reserved for software-controlled auto mode */
3585 res
= fan_set_level_safe(level
);
3591 fan_watchdog_reset();
3596 static struct device_attribute dev_attr_fan_pwm1_enable
=
3597 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3598 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3600 /* sysfs fan pwm1 ------------------------------------------------------ */
3601 static ssize_t
fan_pwm1_show(struct device
*dev
,
3602 struct device_attribute
*attr
,
3608 res
= fan_get_status_safe(&status
);
3612 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3613 if (status
!= fan_control_initial_status
) {
3614 tp_features
.fan_ctrl_status_undef
= 0;
3616 status
= TP_EC_FAN_AUTO
;
3621 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3622 status
= fan_control_desired_level
;
3627 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3630 static ssize_t
fan_pwm1_store(struct device
*dev
,
3631 struct device_attribute
*attr
,
3632 const char *buf
, size_t count
)
3636 u8 status
, newlevel
;
3638 if (parse_strtoul(buf
, 255, &s
))
3641 /* scale down from 0-255 to 0-7 */
3642 newlevel
= (s
>> 5) & 0x07;
3644 rc
= mutex_lock_interruptible(&fan_mutex
);
3648 rc
= fan_get_status(&status
);
3649 if (!rc
&& (status
&
3650 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3651 rc
= fan_set_level(newlevel
);
3655 fan_update_desired_level(newlevel
);
3656 fan_watchdog_reset();
3660 mutex_unlock(&fan_mutex
);
3661 return (rc
)? rc
: count
;
3664 static struct device_attribute dev_attr_fan_pwm1
=
3665 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3666 fan_pwm1_show
, fan_pwm1_store
);
3668 /* sysfs fan fan1_input ------------------------------------------------ */
3669 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3670 struct device_attribute
*attr
,
3676 res
= fan_get_speed(&speed
);
3680 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3683 static struct device_attribute dev_attr_fan_fan1_input
=
3684 __ATTR(fan1_input
, S_IRUGO
,
3685 fan_fan1_input_show
, NULL
);
3687 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
3688 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3691 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3694 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3695 const char *buf
, size_t count
)
3699 if (parse_strtoul(buf
, 120, &t
))
3702 if (!fan_control_allowed
)
3705 fan_watchdog_maxinterval
= t
;
3706 fan_watchdog_reset();
3711 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3712 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3714 /* --------------------------------------------------------------------- */
3715 static struct attribute
*fan_attributes
[] = {
3716 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3717 &dev_attr_fan_fan1_input
.attr
,
3721 static const struct attribute_group fan_attr_group
= {
3722 .attrs
= fan_attributes
,
3725 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3729 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3731 mutex_init(&fan_mutex
);
3732 fan_status_access_mode
= TPACPI_FAN_NONE
;
3733 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3734 fan_control_commands
= 0;
3735 fan_watchdog_maxinterval
= 0;
3736 tp_features
.fan_ctrl_status_undef
= 0;
3737 fan_control_desired_level
= 7;
3739 IBM_ACPIHANDLE_INIT(fans
);
3740 IBM_ACPIHANDLE_INIT(gfan
);
3741 IBM_ACPIHANDLE_INIT(sfan
);
3744 /* 570, 600e/x, 770e, 770x */
3745 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3747 /* all other ThinkPads: note that even old-style
3748 * ThinkPad ECs supports the fan control register */
3749 if (likely(acpi_ec_read(fan_status_offset
,
3750 &fan_control_initial_status
))) {
3751 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3753 /* In some ThinkPads, neither the EC nor the ACPI
3754 * DSDT initialize the fan status, and it ends up
3755 * being set to 0x07 when it *could* be either
3758 * Enable for TP-1Y (T43), TP-78 (R51e),
3759 * TP-76 (R52), TP-70 (T43, R52), which are known
3761 if (fan_control_initial_status
== 0x07) {
3762 switch (thinkpad_id
.ec_model
) {
3763 case 0x5931: /* TP-1Y */
3764 case 0x3837: /* TP-78 */
3765 case 0x3637: /* TP-76 */
3766 case 0x3037: /* TP-70 */
3768 "fan_init: initial fan status is "
3769 "unknown, assuming it is in auto "
3771 tp_features
.fan_ctrl_status_undef
= 1;
3777 "ThinkPad ACPI EC access misbehaving, "
3778 "fan status and control unavailable\n");
3785 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3786 fan_control_commands
|=
3787 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3790 /* gfan without sfan means no fan control */
3791 /* all other models implement TP EC 0x2f control */
3795 fan_control_access_mode
=
3796 TPACPI_FAN_WR_ACPI_FANS
;
3797 fan_control_commands
|=
3798 TPACPI_FAN_CMD_SPEED
|
3799 TPACPI_FAN_CMD_LEVEL
|
3800 TPACPI_FAN_CMD_ENABLE
;
3802 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3803 fan_control_commands
|=
3804 TPACPI_FAN_CMD_LEVEL
|
3805 TPACPI_FAN_CMD_ENABLE
;
3810 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3811 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3812 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3813 fan_status_access_mode
, fan_control_access_mode
);
3815 /* fan control master switch */
3816 if (!fan_control_allowed
) {
3817 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3818 fan_control_commands
= 0;
3819 dbg_printk(TPACPI_DBG_INIT
,
3820 "fan control features disabled by parameter\n");
3823 /* update fan_control_desired_level */
3824 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3825 fan_get_status_safe(NULL
);
3827 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3828 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3829 rc
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3832 rc
= driver_create_file(&tpacpi_pdriver
.driver
,
3833 &driver_attr_fan_watchdog
);
3842 * Call with fan_mutex held
3844 static void fan_update_desired_level(u8 status
)
3847 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3849 fan_control_desired_level
= 7;
3851 fan_control_desired_level
= status
;
3855 static int fan_get_status(u8
*status
)
3860 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3862 switch (fan_status_access_mode
) {
3863 case TPACPI_FAN_RD_ACPI_GFAN
:
3864 /* 570, 600e/x, 770e, 770x */
3866 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
3874 case TPACPI_FAN_RD_TPEC
:
3875 /* all except 570, 600e/x, 770e, 770x */
3876 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
3891 static int fan_get_status_safe(u8
*status
)
3896 rc
= mutex_lock_interruptible(&fan_mutex
);
3899 rc
= fan_get_status(&s
);
3901 fan_update_desired_level(s
);
3902 mutex_unlock(&fan_mutex
);
3910 static void fan_exit(void)
3912 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
3914 /* FIXME: can we really do this unconditionally? */
3915 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
, &fan_attr_group
);
3916 driver_remove_file(&tpacpi_pdriver
.driver
, &driver_attr_fan_watchdog
);
3918 cancel_delayed_work(&fan_watchdog_task
);
3919 flush_scheduled_work();
3922 static int fan_get_speed(unsigned int *speed
)
3926 switch (fan_status_access_mode
) {
3927 case TPACPI_FAN_RD_TPEC
:
3928 /* all except 570, 600e/x, 770e, 770x */
3929 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
3930 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
3934 *speed
= (hi
<< 8) | lo
;
3945 static void fan_watchdog_fire(struct work_struct
*ignored
)
3949 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
3952 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
3953 rc
= fan_set_enable();
3955 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
3956 "will try again later...\n", -rc
);
3957 /* reschedule for later */
3958 fan_watchdog_reset();
3962 static void fan_watchdog_reset(void)
3964 static int fan_watchdog_active
;
3966 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
3969 if (fan_watchdog_active
)
3970 cancel_delayed_work(&fan_watchdog_task
);
3972 if (fan_watchdog_maxinterval
> 0 &&
3973 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
3974 fan_watchdog_active
= 1;
3975 if (!schedule_delayed_work(&fan_watchdog_task
,
3976 msecs_to_jiffies(fan_watchdog_maxinterval
3978 printk(IBM_ERR
"failed to schedule the fan watchdog, "
3979 "watchdog will not trigger\n");
3982 fan_watchdog_active
= 0;
3985 static int fan_set_level(int level
)
3987 if (!fan_control_allowed
)
3990 switch (fan_control_access_mode
) {
3991 case TPACPI_FAN_WR_ACPI_SFAN
:
3992 if (level
>= 0 && level
<= 7) {
3993 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
3999 case TPACPI_FAN_WR_ACPI_FANS
:
4000 case TPACPI_FAN_WR_TPEC
:
4001 if ((level
!= TP_EC_FAN_AUTO
) &&
4002 (level
!= TP_EC_FAN_FULLSPEED
) &&
4003 ((level
< 0) || (level
> 7)))
4006 /* safety net should the EC not support AUTO
4007 * or FULLSPEED mode bits and just ignore them */
4008 if (level
& TP_EC_FAN_FULLSPEED
)
4009 level
|= 7; /* safety min speed 7 */
4010 else if (level
& TP_EC_FAN_FULLSPEED
)
4011 level
|= 4; /* safety min speed 4 */
4013 if (!acpi_ec_write(fan_status_offset
, level
))
4016 tp_features
.fan_ctrl_status_undef
= 0;
4025 static int fan_set_level_safe(int level
)
4029 if (!fan_control_allowed
)
4032 rc
= mutex_lock_interruptible(&fan_mutex
);
4036 if (level
== TPACPI_FAN_LAST_LEVEL
)
4037 level
= fan_control_desired_level
;
4039 rc
= fan_set_level(level
);
4041 fan_update_desired_level(level
);
4043 mutex_unlock(&fan_mutex
);
4047 static int fan_set_enable(void)
4052 if (!fan_control_allowed
)
4055 rc
= mutex_lock_interruptible(&fan_mutex
);
4059 switch (fan_control_access_mode
) {
4060 case TPACPI_FAN_WR_ACPI_FANS
:
4061 case TPACPI_FAN_WR_TPEC
:
4062 rc
= fan_get_status(&s
);
4066 /* Don't go out of emergency fan mode */
4069 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4072 if (!acpi_ec_write(fan_status_offset
, s
))
4075 tp_features
.fan_ctrl_status_undef
= 0;
4080 case TPACPI_FAN_WR_ACPI_SFAN
:
4081 rc
= fan_get_status(&s
);
4087 /* Set fan to at least level 4 */
4090 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4100 mutex_unlock(&fan_mutex
);
4104 static int fan_set_disable(void)
4108 if (!fan_control_allowed
)
4111 rc
= mutex_lock_interruptible(&fan_mutex
);
4116 switch (fan_control_access_mode
) {
4117 case TPACPI_FAN_WR_ACPI_FANS
:
4118 case TPACPI_FAN_WR_TPEC
:
4119 if (!acpi_ec_write(fan_status_offset
, 0x00))
4122 fan_control_desired_level
= 0;
4123 tp_features
.fan_ctrl_status_undef
= 0;
4127 case TPACPI_FAN_WR_ACPI_SFAN
:
4128 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4131 fan_control_desired_level
= 0;
4139 mutex_unlock(&fan_mutex
);
4143 static int fan_set_speed(int speed
)
4147 if (!fan_control_allowed
)
4150 rc
= mutex_lock_interruptible(&fan_mutex
);
4155 switch (fan_control_access_mode
) {
4156 case TPACPI_FAN_WR_ACPI_FANS
:
4157 if (speed
>= 0 && speed
<= 65535) {
4158 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4159 speed
, speed
, speed
))
4169 mutex_unlock(&fan_mutex
);
4173 static int fan_read(char *p
)
4178 unsigned int speed
= 0;
4180 switch (fan_status_access_mode
) {
4181 case TPACPI_FAN_RD_ACPI_GFAN
:
4182 /* 570, 600e/x, 770e, 770x */
4183 if ((rc
= fan_get_status_safe(&status
)) < 0)
4186 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
4188 (status
!= 0) ? "enabled" : "disabled", status
);
4191 case TPACPI_FAN_RD_TPEC
:
4192 /* all except 570, 600e/x, 770e, 770x */
4193 if ((rc
= fan_get_status_safe(&status
)) < 0)
4196 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4197 if (status
!= fan_control_initial_status
)
4198 tp_features
.fan_ctrl_status_undef
= 0;
4200 /* Return most likely status. In fact, it
4201 * might be the only possible status */
4202 status
= TP_EC_FAN_AUTO
;
4205 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4206 (status
!= 0) ? "enabled" : "disabled");
4208 if ((rc
= fan_get_speed(&speed
)) < 0)
4211 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
4213 if (status
& TP_EC_FAN_FULLSPEED
)
4214 /* Disengaged mode takes precedence */
4215 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
4216 else if (status
& TP_EC_FAN_AUTO
)
4217 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
4219 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
4222 case TPACPI_FAN_NONE
:
4224 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4227 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
4228 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
4230 switch (fan_control_access_mode
) {
4231 case TPACPI_FAN_WR_ACPI_SFAN
:
4232 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4236 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4237 "auto, disengaged, full-speed)\n");
4242 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4243 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4244 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4245 "1-120 (seconds))\n");
4247 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4248 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4249 " (<speed> is 0-65535)\n");
4254 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4258 if (strlencmp(cmd
, "level auto") == 0)
4259 level
= TP_EC_FAN_AUTO
;
4260 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4261 (strlencmp(cmd
, "level full-speed") == 0))
4262 level
= TP_EC_FAN_FULLSPEED
;
4263 else if (sscanf(cmd
, "level %d", &level
) != 1)
4266 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4267 printk(IBM_ERR
"level command accepted for unsupported "
4268 "access mode %d", fan_control_access_mode
);
4273 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4275 if (strlencmp(cmd
, "enable") != 0)
4278 if ((*rc
= fan_set_enable()) == -ENXIO
)
4279 printk(IBM_ERR
"enable command accepted for unsupported "
4280 "access mode %d", fan_control_access_mode
);
4285 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4287 if (strlencmp(cmd
, "disable") != 0)
4290 if ((*rc
= fan_set_disable()) == -ENXIO
)
4291 printk(IBM_ERR
"disable command accepted for unsupported "
4292 "access mode %d", fan_control_access_mode
);
4297 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4302 * Support speed <low> <medium> <high> ? */
4304 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4307 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4308 printk(IBM_ERR
"speed command accepted for unsupported "
4309 "access mode %d", fan_control_access_mode
);
4314 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4318 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4321 if (interval
< 0 || interval
> 120)
4324 fan_watchdog_maxinterval
= interval
;
4329 static int fan_write(char *buf
)
4334 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4335 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4336 fan_write_cmd_level(cmd
, &rc
)) &&
4337 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4338 (fan_write_cmd_enable(cmd
, &rc
) ||
4339 fan_write_cmd_disable(cmd
, &rc
) ||
4340 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4341 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4342 fan_write_cmd_speed(cmd
, &rc
))
4346 fan_watchdog_reset();
4352 static struct ibm_struct fan_driver_data
= {
4359 /****************************************************************************
4360 ****************************************************************************
4364 ****************************************************************************
4365 ****************************************************************************/
4368 static struct proc_dir_entry
*proc_dir
;
4370 /* Subdriver registry */
4371 static LIST_HEAD(tpacpi_all_drivers
);
4375 * Module and infrastructure proble, init and exit handling
4378 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4379 static const char * __init
str_supported(int is_supported
)
4381 static char text_unsupported
[] __initdata
= "not supported";
4383 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4385 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4387 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4390 struct ibm_struct
*ibm
= iibm
->data
;
4391 struct proc_dir_entry
*entry
;
4393 BUG_ON(ibm
== NULL
);
4395 INIT_LIST_HEAD(&ibm
->all_drivers
);
4397 if (ibm
->flags
.experimental
&& !experimental
)
4400 dbg_printk(TPACPI_DBG_INIT
,
4401 "probing for %s\n", ibm
->name
);
4404 ret
= iibm
->init(iibm
);
4406 return 0; /* probe failed */
4410 ibm
->flags
.init_called
= 1;
4414 if (ibm
->acpi
->hid
) {
4415 ret
= register_tpacpi_subdriver(ibm
);
4420 if (ibm
->acpi
->notify
) {
4421 ret
= setup_acpi_notify(ibm
);
4422 if (ret
== -ENODEV
) {
4423 printk(IBM_NOTICE
"disabling subdriver %s\n",
4433 dbg_printk(TPACPI_DBG_INIT
,
4434 "%s installed\n", ibm
->name
);
4437 entry
= create_proc_entry(ibm
->name
,
4438 S_IFREG
| S_IRUGO
| S_IWUSR
,
4441 printk(IBM_ERR
"unable to create proc entry %s\n",
4446 entry
->owner
= THIS_MODULE
;
4448 entry
->read_proc
= &dispatch_procfs_read
;
4450 entry
->write_proc
= &dispatch_procfs_write
;
4451 ibm
->flags
.proc_created
= 1;
4454 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4459 dbg_printk(TPACPI_DBG_INIT
,
4460 "%s: at error exit path with result %d\n",
4464 return (ret
< 0)? ret
: 0;
4467 static void ibm_exit(struct ibm_struct
*ibm
)
4469 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4471 list_del_init(&ibm
->all_drivers
);
4473 if (ibm
->flags
.acpi_notify_installed
) {
4474 dbg_printk(TPACPI_DBG_EXIT
,
4475 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4477 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4479 dispatch_acpi_notify
);
4480 ibm
->flags
.acpi_notify_installed
= 0;
4481 ibm
->flags
.acpi_notify_installed
= 0;
4484 if (ibm
->flags
.proc_created
) {
4485 dbg_printk(TPACPI_DBG_EXIT
,
4486 "%s: remove_proc_entry\n", ibm
->name
);
4487 remove_proc_entry(ibm
->name
, proc_dir
);
4488 ibm
->flags
.proc_created
= 0;
4491 if (ibm
->flags
.acpi_driver_registered
) {
4492 dbg_printk(TPACPI_DBG_EXIT
,
4493 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4495 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4496 kfree(ibm
->acpi
->driver
);
4497 ibm
->acpi
->driver
= NULL
;
4498 ibm
->flags
.acpi_driver_registered
= 0;
4501 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4503 ibm
->flags
.init_called
= 0;
4506 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4511 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
4513 struct dmi_device
*dev
= NULL
;
4514 char ec_fw_string
[18];
4519 memset(tp
, 0, sizeof(*tp
));
4521 if (dmi_name_in_vendors("IBM"))
4522 tp
->vendor
= PCI_VENDOR_ID_IBM
;
4523 else if (dmi_name_in_vendors("LENOVO"))
4524 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
4528 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
4530 if (!tp
->bios_version_str
)
4532 tp
->bios_model
= tp
->bios_version_str
[0]
4533 | (tp
->bios_version_str
[1] << 8);
4536 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4537 * X32 or newer, all Z series; Some models must have an
4538 * up-to-date BIOS or they will not be detected.
4540 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4542 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4543 if (sscanf(dev
->name
,
4544 "IBM ThinkPad Embedded Controller -[%17c",
4545 ec_fw_string
) == 1) {
4546 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4547 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4549 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
4550 tp
->ec_model
= ec_fw_string
[0]
4551 | (ec_fw_string
[1] << 8);
4556 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
4558 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
4559 kfree(tp
->model_str
);
4560 tp
->model_str
= NULL
;
4564 static int __init
probe_for_thinkpad(void)
4572 * Non-ancient models have better DMI tagging, but very old models
4575 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
4577 /* ec is required because many other handles are relative to it */
4578 IBM_ACPIHANDLE_INIT(ec
);
4582 "Not yet supported ThinkPad detected!\n");
4587 * Risks a regression on very old machines, but reduces potential
4588 * false positives a damn great deal
4591 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
4593 if (!is_thinkpad
&& !force_load
)
4600 /* Module init, exit, parameters */
4602 static struct ibm_init_struct ibms_init
[] __initdata
= {
4604 .init
= thinkpad_acpi_driver_init
,
4605 .data
= &thinkpad_acpi_driver_data
,
4608 .init
= hotkey_init
,
4609 .data
= &hotkey_driver_data
,
4612 .init
= bluetooth_init
,
4613 .data
= &bluetooth_driver_data
,
4617 .data
= &wan_driver_data
,
4621 .data
= &video_driver_data
,
4625 .data
= &light_driver_data
,
4627 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4630 .data
= &dock_driver_data
[0],
4634 .data
= &dock_driver_data
[1],
4637 #ifdef CONFIG_THINKPAD_ACPI_BAY
4640 .data
= &bay_driver_data
,
4645 .data
= &cmos_driver_data
,
4649 .data
= &led_driver_data
,
4653 .data
= &beep_driver_data
,
4656 .init
= thermal_init
,
4657 .data
= &thermal_driver_data
,
4660 .data
= &ecdump_driver_data
,
4663 .init
= brightness_init
,
4664 .data
= &brightness_driver_data
,
4667 .data
= &volume_driver_data
,
4671 .data
= &fan_driver_data
,
4675 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4678 struct ibm_struct
*ibm
;
4680 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4681 ibm
= ibms_init
[i
].data
;
4682 BUG_ON(ibm
== NULL
);
4684 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4685 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4687 strcpy(ibms_init
[i
].param
, val
);
4688 strcat(ibms_init
[i
].param
, ",");
4696 static int experimental
;
4697 module_param(experimental
, int, 0);
4699 static u32 dbg_level
;
4700 module_param_named(debug
, dbg_level
, uint
, 0);
4702 static int force_load
;
4703 module_param(force_load
, bool, 0);
4705 static int fan_control_allowed
;
4706 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
4708 static int brightness_mode
;
4709 module_param_named(brightness_mode
, brightness_mode
, int, 0);
4711 static unsigned int hotkey_report_mode
;
4712 module_param(hotkey_report_mode
, uint
, 0);
4714 #define IBM_PARAM(feature) \
4715 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4718 IBM_PARAM(bluetooth
);
4721 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4724 #ifdef CONFIG_THINKPAD_ACPI_BAY
4726 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4731 IBM_PARAM(brightness
);
4735 static int __init
thinkpad_acpi_module_init(void)
4739 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
4741 /* Parameter checking */
4742 if (hotkey_report_mode
> 2)
4745 /* Driver-level probe */
4747 get_thinkpad_model_data(&thinkpad_id
);
4748 ret
= probe_for_thinkpad();
4750 thinkpad_acpi_module_exit();
4754 /* Driver initialization */
4756 IBM_ACPIHANDLE_INIT(ecrd
);
4757 IBM_ACPIHANDLE_INIT(ecwr
);
4759 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4761 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4762 thinkpad_acpi_module_exit();
4765 proc_dir
->owner
= THIS_MODULE
;
4767 ret
= platform_driver_register(&tpacpi_pdriver
);
4769 printk(IBM_ERR
"unable to register platform driver\n");
4770 thinkpad_acpi_module_exit();
4773 tp_features
.platform_drv_registered
= 1;
4775 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4777 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4778 thinkpad_acpi_module_exit();
4781 tp_features
.platform_drv_attrs_registered
= 1;
4784 /* Device initialization */
4785 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4787 if (IS_ERR(tpacpi_pdev
)) {
4788 ret
= PTR_ERR(tpacpi_pdev
);
4790 printk(IBM_ERR
"unable to register platform device\n");
4791 thinkpad_acpi_module_exit();
4794 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
4795 if (IS_ERR(tpacpi_hwmon
)) {
4796 ret
= PTR_ERR(tpacpi_hwmon
);
4797 tpacpi_hwmon
= NULL
;
4798 printk(IBM_ERR
"unable to register hwmon device\n");
4799 thinkpad_acpi_module_exit();
4802 mutex_init(&tpacpi_inputdev_send_mutex
);
4803 tpacpi_inputdev
= input_allocate_device();
4804 if (!tpacpi_inputdev
) {
4805 printk(IBM_ERR
"unable to allocate input device\n");
4806 thinkpad_acpi_module_exit();
4809 /* Prepare input device, but don't register */
4810 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
4811 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
4812 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
4813 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
4814 thinkpad_id
.vendor
:
4816 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
4817 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
4819 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4820 ret
= ibm_init(&ibms_init
[i
]);
4821 if (ret
>= 0 && *ibms_init
[i
].param
)
4822 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
4824 thinkpad_acpi_module_exit();
4828 ret
= input_register_device(tpacpi_inputdev
);
4830 printk(IBM_ERR
"unable to register input device\n");
4831 thinkpad_acpi_module_exit();
4834 tp_features
.input_device_registered
= 1;
4837 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
4841 static void thinkpad_acpi_module_exit(void)
4843 struct ibm_struct
*ibm
, *itmp
;
4845 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
4847 list_for_each_entry_safe_reverse(ibm
, itmp
,
4848 &tpacpi_all_drivers
,
4853 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
4855 if (tpacpi_inputdev
) {
4856 if (tp_features
.input_device_registered
)
4857 input_unregister_device(tpacpi_inputdev
);
4859 input_free_device(tpacpi_inputdev
);
4863 hwmon_device_unregister(tpacpi_hwmon
);
4866 platform_device_unregister(tpacpi_pdev
);
4868 if (tp_features
.platform_drv_attrs_registered
)
4869 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
4871 if (tp_features
.platform_drv_registered
)
4872 platform_driver_unregister(&tpacpi_pdriver
);
4875 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
4877 kfree(thinkpad_id
.bios_version_str
);
4878 kfree(thinkpad_id
.ec_version_str
);
4879 kfree(thinkpad_id
.model_str
);
4882 module_init(thinkpad_acpi_module_init
);
4883 module_exit(thinkpad_acpi_module_exit
);