2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2008 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 TPACPI_VERSION "0.19"
25 #define TPACPI_SYSFS_VERSION 0x020200
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/kthread.h>
58 #include <linux/freezer.h>
59 #include <linux/delay.h>
61 #include <linux/nvram.h>
62 #include <linux/proc_fs.h>
63 #include <linux/sysfs.h>
64 #include <linux/backlight.h>
66 #include <linux/platform_device.h>
67 #include <linux/hwmon.h>
68 #include <linux/hwmon-sysfs.h>
69 #include <linux/input.h>
70 #include <asm/uaccess.h>
72 #include <linux/dmi.h>
73 #include <linux/jiffies.h>
74 #include <linux/workqueue.h>
76 #include <acpi/acpi_drivers.h>
77 #include <acpi/acnamesp.h>
79 #include <linux/pci_ids.h>
82 /* ThinkPad CMOS commands */
83 #define TP_CMOS_VOLUME_DOWN 0
84 #define TP_CMOS_VOLUME_UP 1
85 #define TP_CMOS_VOLUME_MUTE 2
86 #define TP_CMOS_BRIGHTNESS_UP 4
87 #define TP_CMOS_BRIGHTNESS_DOWN 5
91 TP_NVRAM_ADDR_HK2
= 0x57,
92 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
93 TP_NVRAM_ADDR_VIDEO
= 0x59,
94 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
95 TP_NVRAM_ADDR_MIXER
= 0x60,
100 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
101 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
102 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
103 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
104 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
105 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
106 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
107 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
108 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
109 TP_NVRAM_MASK_MUTE
= 0x40,
110 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
111 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
112 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
116 #define TPACPI_ACPI_HKEY_HID "IBM0068"
119 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
120 #define TPACPI_HKEY_INPUT_VERSION 0x4101
123 /****************************************************************************
127 #define TPACPI_NAME "thinkpad"
128 #define TPACPI_DESC "ThinkPad ACPI Extras"
129 #define TPACPI_FILE TPACPI_NAME "_acpi"
130 #define TPACPI_URL "http://ibm-acpi.sf.net/"
131 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
133 #define TPACPI_PROC_DIR "ibm"
134 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
135 #define TPACPI_DRVR_NAME TPACPI_FILE
136 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
138 #define TPACPI_MAX_ACPI_ARGS 3
141 #define TPACPI_LOG TPACPI_FILE ": "
142 #define TPACPI_ERR KERN_ERR TPACPI_LOG
143 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
144 #define TPACPI_INFO KERN_INFO TPACPI_LOG
145 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
147 #define TPACPI_DBG_ALL 0xffff
148 #define TPACPI_DBG_ALL 0xffff
149 #define TPACPI_DBG_INIT 0x0001
150 #define TPACPI_DBG_EXIT 0x0002
151 #define dbg_printk(a_dbg_level, format, arg...) \
152 do { if (dbg_level & a_dbg_level) \
153 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
155 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
156 #define vdbg_printk(a_dbg_level, format, arg...) \
157 dbg_printk(a_dbg_level, format, ## arg)
158 static const char *str_supported(int is_supported
);
160 #define vdbg_printk(a_dbg_level, format, arg...)
163 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
164 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
165 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
168 /****************************************************************************
169 * Driver-wide structs and misc. variables
174 struct tp_acpi_drv_struct
{
175 const struct acpi_device_id
*hid
;
176 struct acpi_driver
*driver
;
178 void (*notify
) (struct ibm_struct
*, u32
);
181 struct acpi_device
*device
;
187 int (*read
) (char *);
188 int (*write
) (char *);
190 void (*resume
) (void);
191 void (*suspend
) (pm_message_t state
);
193 struct list_head all_drivers
;
195 struct tp_acpi_drv_struct
*acpi
;
198 u8 acpi_driver_registered
:1;
199 u8 acpi_notify_installed
:1;
206 struct ibm_init_struct
{
209 int (*init
) (struct ibm_init_struct
*);
210 struct ibm_struct
*data
;
214 #ifdef CONFIG_THINKPAD_ACPI_BAY
224 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
227 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
230 u32 bright_16levels
:1;
232 u32 fan_ctrl_status_undef
:1;
233 u32 input_device_registered
:1;
234 u32 platform_drv_registered
:1;
235 u32 platform_drv_attrs_registered
:1;
236 u32 sensors_pdrv_registered
:1;
237 u32 sensors_pdrv_attrs_registered
:1;
238 u32 sensors_pdev_attrs_registered
:1;
239 u32 hotkey_poll_active
:1;
242 struct thinkpad_id_data
{
243 unsigned int vendor
; /* ThinkPad vendor:
244 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
246 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
247 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
249 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
254 static struct thinkpad_id_data thinkpad_id
;
257 TPACPI_LIFE_INIT
= 0,
262 static int experimental
;
263 static u32 dbg_level
;
265 /****************************************************************************
266 ****************************************************************************
268 * ACPI Helpers and device model
270 ****************************************************************************
271 ****************************************************************************/
273 /*************************************************************************
277 static acpi_handle root_handle
;
279 #define TPACPI_HANDLE(object, parent, paths...) \
280 static acpi_handle object##_handle; \
281 static acpi_handle *object##_parent = &parent##_handle; \
282 static char *object##_path; \
283 static char *object##_paths[] = { paths }
285 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
286 "\\_SB.PCI.ISA.EC", /* 570 */
287 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
288 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
289 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
290 "\\_SB.PCI0.ICH3.EC0", /* R31 */
291 "\\_SB.PCI0.LPC.EC", /* all others */
294 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
295 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
297 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
299 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
300 "\\CMS", /* R40, R40e */
303 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
304 "^HKEY", /* R30, R31 */
305 "HKEY", /* all others */
308 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
310 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
311 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
312 "\\_SB.PCI0.VID0", /* 770e */
313 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
314 "\\_SB.PCI0.AGP.VID", /* all others */
317 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
319 /*************************************************************************
323 static int acpi_evalf(acpi_handle handle
,
324 void *res
, char *method
, char *fmt
, ...)
327 struct acpi_object_list params
;
328 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
329 struct acpi_buffer result
, *resultp
;
330 union acpi_object out_obj
;
338 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
351 params
.pointer
= &in_objs
[0];
358 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
359 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
361 /* add more types as needed */
363 printk(TPACPI_ERR
"acpi_evalf() called "
364 "with invalid format character '%c'\n", c
);
370 if (res_type
!= 'v') {
371 result
.length
= sizeof(out_obj
);
372 result
.pointer
= &out_obj
;
377 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
382 *(int *)res
= out_obj
.integer
.value
;
383 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
386 success
= status
== AE_OK
;
388 /* add more types as needed */
390 printk(TPACPI_ERR
"acpi_evalf() called "
391 "with invalid format character '%c'\n", res_type
);
395 if (!success
&& !quiet
)
396 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
397 method
, fmt0
, status
);
402 static int acpi_ec_read(int i
, u8
*p
)
407 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
411 if (ec_read(i
, p
) < 0)
418 static int acpi_ec_write(int i
, u8 v
)
421 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
424 if (ec_write(i
, v
) < 0)
431 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
432 static int _sta(acpi_handle handle
)
436 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
443 static int issue_thinkpad_cmos_command(int cmos_cmd
)
448 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
454 /*************************************************************************
458 #define TPACPI_ACPIHANDLE_INIT(object) \
459 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
460 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
462 static void drv_acpi_handle_init(char *name
,
463 acpi_handle
*handle
, acpi_handle parent
,
464 char **paths
, int num_paths
, char **path
)
469 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
472 for (i
= 0; i
< num_paths
; i
++) {
473 status
= acpi_get_handle(parent
, paths
[i
], handle
);
474 if (ACPI_SUCCESS(status
)) {
476 dbg_printk(TPACPI_DBG_INIT
,
477 "Found ACPI handle %s for %s\n",
483 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
488 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
490 struct ibm_struct
*ibm
= data
;
492 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
495 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
498 ibm
->acpi
->notify(ibm
, event
);
501 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
508 if (!*ibm
->acpi
->handle
)
511 vdbg_printk(TPACPI_DBG_INIT
,
512 "setting up ACPI notify for %s\n", ibm
->name
);
514 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
516 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
521 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
522 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
523 TPACPI_ACPI_EVENT_PREFIX
,
526 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
527 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
528 if (ACPI_FAILURE(status
)) {
529 if (status
== AE_ALREADY_EXISTS
) {
531 "another device driver is already "
532 "handling %s events\n", ibm
->name
);
535 "acpi_install_notify_handler(%s) failed: %d\n",
540 ibm
->flags
.acpi_notify_installed
= 1;
544 static int __init
tpacpi_device_add(struct acpi_device
*device
)
549 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
553 dbg_printk(TPACPI_DBG_INIT
,
554 "registering %s as an ACPI driver\n", ibm
->name
);
558 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
559 if (!ibm
->acpi
->driver
) {
560 printk(TPACPI_ERR
"kzalloc(ibm->driver) failed\n");
564 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
565 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
567 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
569 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
571 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
573 kfree(ibm
->acpi
->driver
);
574 ibm
->acpi
->driver
= NULL
;
576 ibm
->flags
.acpi_driver_registered
= 1;
582 /****************************************************************************
583 ****************************************************************************
587 ****************************************************************************
588 ****************************************************************************/
590 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
591 int count
, int *eof
, void *data
)
593 struct ibm_struct
*ibm
= data
;
596 if (!ibm
|| !ibm
->read
)
599 len
= ibm
->read(page
);
603 if (len
<= off
+ count
)
615 static int dispatch_procfs_write(struct file
*file
,
616 const char __user
*userbuf
,
617 unsigned long count
, void *data
)
619 struct ibm_struct
*ibm
= data
;
623 if (!ibm
|| !ibm
->write
)
626 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
630 if (copy_from_user(kernbuf
, userbuf
, count
)) {
636 strcat(kernbuf
, ",");
637 ret
= ibm
->write(kernbuf
);
646 static char *next_cmd(char **cmds
)
651 while ((end
= strchr(start
, ',')) && end
== start
)
663 /****************************************************************************
664 ****************************************************************************
666 * Device model: input, hwmon and platform
668 ****************************************************************************
669 ****************************************************************************/
671 static struct platform_device
*tpacpi_pdev
;
672 static struct platform_device
*tpacpi_sensors_pdev
;
673 static struct device
*tpacpi_hwmon
;
674 static struct input_dev
*tpacpi_inputdev
;
675 static struct mutex tpacpi_inputdev_send_mutex
;
676 static LIST_HEAD(tpacpi_all_drivers
);
678 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
681 struct ibm_struct
*ibm
, *itmp
;
683 list_for_each_entry_safe(ibm
, itmp
,
687 (ibm
->suspend
)(state
);
693 static int tpacpi_resume_handler(struct platform_device
*pdev
)
695 struct ibm_struct
*ibm
, *itmp
;
697 list_for_each_entry_safe(ibm
, itmp
,
707 static struct platform_driver tpacpi_pdriver
= {
709 .name
= TPACPI_DRVR_NAME
,
710 .owner
= THIS_MODULE
,
712 .suspend
= tpacpi_suspend_handler
,
713 .resume
= tpacpi_resume_handler
,
716 static struct platform_driver tpacpi_hwmon_pdriver
= {
718 .name
= TPACPI_HWMON_DRVR_NAME
,
719 .owner
= THIS_MODULE
,
723 /*************************************************************************
724 * sysfs support helpers
727 struct attribute_set
{
728 unsigned int members
, max_members
;
729 struct attribute_group group
;
732 struct attribute_set_obj
{
733 struct attribute_set s
;
735 } __attribute__((packed
));
737 static struct attribute_set
*create_attr_set(unsigned int max_members
,
740 struct attribute_set_obj
*sobj
;
742 if (max_members
== 0)
745 /* Allocates space for implicit NULL at the end too */
746 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
747 max_members
* sizeof(struct attribute
*),
751 sobj
->s
.max_members
= max_members
;
752 sobj
->s
.group
.attrs
= &sobj
->a
;
753 sobj
->s
.group
.name
= name
;
758 #define destroy_attr_set(_set) \
761 /* not multi-threaded safe, use it in a single thread per set */
762 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
767 if (s
->members
>= s
->max_members
)
770 s
->group
.attrs
[s
->members
] = attr
;
776 static int add_many_to_attr_set(struct attribute_set
*s
,
777 struct attribute
**attr
,
782 for (i
= 0; i
< count
; i
++) {
783 res
= add_to_attr_set(s
, attr
[i
]);
791 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
793 sysfs_remove_group(kobj
, &s
->group
);
797 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
798 sysfs_create_group(_kobj, &_attr_set->group)
800 static int parse_strtoul(const char *buf
,
801 unsigned long max
, unsigned long *value
)
805 while (*buf
&& isspace(*buf
))
807 *value
= simple_strtoul(buf
, &endp
, 0);
808 while (*endp
&& isspace(*endp
))
810 if (*endp
|| *value
> max
)
816 /*************************************************************************
817 * thinkpad-acpi driver attributes
820 /* interface_version --------------------------------------------------- */
821 static ssize_t
tpacpi_driver_interface_version_show(
822 struct device_driver
*drv
,
825 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
828 static DRIVER_ATTR(interface_version
, S_IRUGO
,
829 tpacpi_driver_interface_version_show
, NULL
);
831 /* debug_level --------------------------------------------------------- */
832 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
835 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
838 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
839 const char *buf
, size_t count
)
843 if (parse_strtoul(buf
, 0xffff, &t
))
851 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
852 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
854 /* version ------------------------------------------------------------- */
855 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
858 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
859 TPACPI_DESC
, TPACPI_VERSION
);
862 static DRIVER_ATTR(version
, S_IRUGO
,
863 tpacpi_driver_version_show
, NULL
);
865 /* --------------------------------------------------------------------- */
867 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
868 &driver_attr_debug_level
, &driver_attr_version
,
869 &driver_attr_interface_version
,
872 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
878 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
879 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
886 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
890 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
891 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
894 /****************************************************************************
895 ****************************************************************************
899 ****************************************************************************
900 ****************************************************************************/
902 /*************************************************************************
903 * thinkpad-acpi init subdriver
906 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
908 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
909 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
911 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
912 (thinkpad_id
.bios_version_str
) ?
913 thinkpad_id
.bios_version_str
: "unknown",
914 (thinkpad_id
.ec_version_str
) ?
915 thinkpad_id
.ec_version_str
: "unknown");
917 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
918 printk(TPACPI_INFO
"%s %s\n",
919 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
920 "IBM" : ((thinkpad_id
.vendor
==
921 PCI_VENDOR_ID_LENOVO
) ?
922 "Lenovo" : "Unknown vendor"),
923 thinkpad_id
.model_str
);
928 static int thinkpad_acpi_driver_read(char *p
)
932 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
933 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
938 static struct ibm_struct thinkpad_acpi_driver_data
= {
940 .read
= thinkpad_acpi_driver_read
,
943 /*************************************************************************
947 enum { /* hot key scan codes (derived from ACPI DSDT) */
948 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
949 TP_ACPI_HOTKEYSCAN_FNF2
,
950 TP_ACPI_HOTKEYSCAN_FNF3
,
951 TP_ACPI_HOTKEYSCAN_FNF4
,
952 TP_ACPI_HOTKEYSCAN_FNF5
,
953 TP_ACPI_HOTKEYSCAN_FNF6
,
954 TP_ACPI_HOTKEYSCAN_FNF7
,
955 TP_ACPI_HOTKEYSCAN_FNF8
,
956 TP_ACPI_HOTKEYSCAN_FNF9
,
957 TP_ACPI_HOTKEYSCAN_FNF10
,
958 TP_ACPI_HOTKEYSCAN_FNF11
,
959 TP_ACPI_HOTKEYSCAN_FNF12
,
960 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
961 TP_ACPI_HOTKEYSCAN_FNINSERT
,
962 TP_ACPI_HOTKEYSCAN_FNDELETE
,
963 TP_ACPI_HOTKEYSCAN_FNHOME
,
964 TP_ACPI_HOTKEYSCAN_FNEND
,
965 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
966 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
967 TP_ACPI_HOTKEYSCAN_FNSPACE
,
968 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
969 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
970 TP_ACPI_HOTKEYSCAN_MUTE
,
971 TP_ACPI_HOTKEYSCAN_THINKPAD
,
974 enum { /* Keys available through NVRAM polling */
975 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
976 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
979 enum { /* Positions of some of the keys in hotkey masks */
980 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
981 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
982 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
983 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
984 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
985 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
986 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
987 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
988 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
989 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
990 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
993 enum { /* NVRAM to ACPI HKEY group map */
994 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
995 TP_ACPI_HKEY_ZOOM_MASK
|
996 TP_ACPI_HKEY_DISPSWTCH_MASK
|
997 TP_ACPI_HKEY_HIBERNATE_MASK
,
998 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
999 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1000 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1001 TP_ACPI_HKEY_VOLDWN_MASK
|
1002 TP_ACPI_HKEY_MUTE_MASK
,
1005 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1006 struct tp_nvram_state
{
1007 u16 thinkpad_toggle
:1;
1009 u16 display_toggle
:1;
1010 u16 thinklight_toggle
:1;
1011 u16 hibernate_toggle
:1;
1012 u16 displayexp_toggle
:1;
1013 u16 display_state
:1;
1014 u16 brightness_toggle
:1;
1015 u16 volume_toggle
:1;
1018 u8 brightness_level
;
1022 static struct task_struct
*tpacpi_hotkey_task
;
1023 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1024 static int hotkey_poll_freq
= 10; /* Hz */
1025 static struct mutex hotkey_thread_mutex
;
1026 static struct mutex hotkey_thread_data_mutex
;
1027 static unsigned int hotkey_config_change
;
1029 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1031 #define hotkey_source_mask 0U
1033 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1035 static struct mutex hotkey_mutex
;
1037 static enum { /* Reasons for waking up */
1038 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1039 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1040 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1041 } hotkey_wakeup_reason
;
1043 static int hotkey_autosleep_ack
;
1045 static int hotkey_orig_status
;
1046 static u32 hotkey_orig_mask
;
1047 static u32 hotkey_all_mask
;
1048 static u32 hotkey_reserved_mask
;
1049 static u32 hotkey_mask
;
1051 static unsigned int hotkey_report_mode
;
1053 static u16
*hotkey_keycode_map
;
1055 static struct attribute_set
*hotkey_dev_attributes
;
1057 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1058 #define HOTKEY_CONFIG_CRITICAL_START \
1060 mutex_lock(&hotkey_thread_data_mutex); \
1061 hotkey_config_change++; \
1063 #define HOTKEY_CONFIG_CRITICAL_END \
1064 mutex_unlock(&hotkey_thread_data_mutex);
1066 #define HOTKEY_CONFIG_CRITICAL_START
1067 #define HOTKEY_CONFIG_CRITICAL_END
1068 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1070 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
1072 /* HKEY.MHKG() return bits */
1073 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1075 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
1076 static int hotkey_get_wlsw(int *status
)
1078 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1083 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
1085 static int hotkey_get_tablet_mode(int *status
)
1089 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1092 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1096 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
1098 * Call with hotkey_mutex held
1100 static int hotkey_mask_get(void)
1104 if (tp_features
.hotkey_mask
) {
1105 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1108 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1114 * Call with hotkey_mutex held
1116 static int hotkey_mask_set(u32 mask
)
1121 if (tp_features
.hotkey_mask
) {
1122 HOTKEY_CONFIG_CRITICAL_START
1123 for (i
= 0; i
< 32; i
++) {
1125 /* enable in firmware mask only keys not in NVRAM
1126 * mode, but enable the key in the cached hotkey_mask
1127 * regardless of mode, or the key will end up
1128 * disabled by hotkey_mask_get() */
1129 if (!acpi_evalf(hkey_handle
,
1130 NULL
, "MHKM", "vdd", i
+ 1,
1131 !!((mask
& ~hotkey_source_mask
) & m
))) {
1135 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1138 HOTKEY_CONFIG_CRITICAL_END
1140 /* hotkey_mask_get must be called unconditionally below */
1141 if (!hotkey_mask_get() && !rc
&&
1142 (hotkey_mask
& ~hotkey_source_mask
) !=
1143 (mask
& ~hotkey_source_mask
)) {
1144 printk(TPACPI_NOTICE
1145 "requested hot key mask 0x%08x, but "
1146 "firmware forced it to 0x%08x\n",
1150 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1151 HOTKEY_CONFIG_CRITICAL_START
1152 hotkey_mask
= mask
& hotkey_source_mask
;
1153 HOTKEY_CONFIG_CRITICAL_END
1155 if (hotkey_mask
!= mask
) {
1156 printk(TPACPI_NOTICE
1157 "requested hot key mask 0x%08x, "
1158 "forced to 0x%08x (NVRAM poll mask is "
1159 "0x%08x): no firmware mask support\n",
1160 mask
, hotkey_mask
, hotkey_source_mask
);
1165 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1171 static int hotkey_status_get(int *status
)
1173 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1179 static int hotkey_status_set(int status
)
1181 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1187 static void tpacpi_input_send_radiosw(void)
1191 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
1192 mutex_lock(&tpacpi_inputdev_send_mutex
);
1195 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
1196 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1197 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
1199 mutex_lock(&tpacpi_inputdev_send_mutex
);
1201 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
1202 input_report_switch(tpacpi_inputdev
,
1204 input_sync(tpacpi_inputdev
);
1205 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
1208 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1209 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
1211 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
1215 static void tpacpi_input_send_tabletsw(void)
1219 if (tp_features
.hotkey_tablet
&&
1220 !hotkey_get_tablet_mode(&state
)) {
1221 mutex_lock(&tpacpi_inputdev_send_mutex
);
1222 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
1224 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
1225 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1227 input_report_switch(tpacpi_inputdev
,
1228 SW_TABLET_MODE
, !!state
);
1229 input_sync(tpacpi_inputdev
);
1231 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1233 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
1236 static void tpacpi_input_send_key(unsigned int scancode
)
1238 unsigned int keycode
;
1240 keycode
= hotkey_keycode_map
[scancode
];
1242 if (keycode
!= KEY_RESERVED
) {
1243 mutex_lock(&tpacpi_inputdev_send_mutex
);
1245 input_report_key(tpacpi_inputdev
, keycode
, 1);
1246 if (keycode
== KEY_UNKNOWN
)
1247 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1249 input_sync(tpacpi_inputdev
);
1251 input_report_key(tpacpi_inputdev
, keycode
, 0);
1252 if (keycode
== KEY_UNKNOWN
)
1253 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1255 input_sync(tpacpi_inputdev
);
1257 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1261 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1262 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1264 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1266 tpacpi_input_send_key(scancode
);
1267 if (hotkey_report_mode
< 2) {
1268 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1269 0x80, 0x1001 + scancode
);
1273 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1277 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1278 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1279 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1280 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1281 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1282 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1284 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1285 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1286 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1288 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1289 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1290 n
->displayexp_toggle
=
1291 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1293 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1294 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1295 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1296 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1297 n
->brightness_toggle
=
1298 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1300 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1301 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1302 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1303 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1304 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1305 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1309 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1311 if ((mask & (1 << __scancode)) && \
1312 oldn->__member != newn->__member) \
1313 tpacpi_hotkey_send_key(__scancode); \
1316 #define TPACPI_MAY_SEND_KEY(__scancode) \
1317 do { if (mask & (1 << __scancode)) \
1318 tpacpi_hotkey_send_key(__scancode); } while (0)
1320 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1321 struct tp_nvram_state
*newn
,
1324 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1325 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1326 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1327 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1329 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1331 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1334 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1335 if (oldn
->mute
!= newn
->mute
) {
1336 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1338 if (oldn
->volume_level
> newn
->volume_level
) {
1339 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1340 } else if (oldn
->volume_level
< newn
->volume_level
) {
1341 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1342 } else if (oldn
->mute
== newn
->mute
) {
1343 /* repeated key presses that didn't change state */
1345 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1346 } else if (newn
->volume_level
!= 0) {
1347 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1349 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1354 /* handle brightness */
1355 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1356 if (oldn
->brightness_level
< newn
->brightness_level
) {
1357 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1358 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1359 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1361 /* repeated key presses that didn't change state */
1362 if (newn
->brightness_level
!= 0) {
1363 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1365 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1371 #undef TPACPI_COMPARE_KEY
1372 #undef TPACPI_MAY_SEND_KEY
1374 static int hotkey_kthread(void *data
)
1376 struct tp_nvram_state s
[2];
1378 unsigned int si
, so
;
1380 unsigned int change_detector
, must_reset
;
1382 mutex_lock(&hotkey_thread_mutex
);
1384 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1393 /* Initial state for compares */
1394 mutex_lock(&hotkey_thread_data_mutex
);
1395 change_detector
= hotkey_config_change
;
1396 mask
= hotkey_source_mask
& hotkey_mask
;
1397 mutex_unlock(&hotkey_thread_data_mutex
);
1398 hotkey_read_nvram(&s
[so
], mask
);
1400 while (!kthread_should_stop() && hotkey_poll_freq
) {
1402 t
= 1000/hotkey_poll_freq
;
1403 t
= msleep_interruptible(t
);
1404 if (unlikely(kthread_should_stop()))
1406 must_reset
= try_to_freeze();
1407 if (t
> 0 && !must_reset
)
1410 mutex_lock(&hotkey_thread_data_mutex
);
1411 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1412 /* forget old state on thaw or config change */
1415 change_detector
= hotkey_config_change
;
1417 mask
= hotkey_source_mask
& hotkey_mask
;
1418 mutex_unlock(&hotkey_thread_data_mutex
);
1421 hotkey_read_nvram(&s
[si
], mask
);
1422 if (likely(si
!= so
)) {
1423 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1433 mutex_unlock(&hotkey_thread_mutex
);
1437 static void hotkey_poll_stop_sync(void)
1439 if (tpacpi_hotkey_task
) {
1440 if (frozen(tpacpi_hotkey_task
) ||
1441 freezing(tpacpi_hotkey_task
))
1442 thaw_process(tpacpi_hotkey_task
);
1444 kthread_stop(tpacpi_hotkey_task
);
1445 tpacpi_hotkey_task
= NULL
;
1446 mutex_lock(&hotkey_thread_mutex
);
1447 /* at this point, the thread did exit */
1448 mutex_unlock(&hotkey_thread_mutex
);
1452 /* call with hotkey_mutex held */
1453 static void hotkey_poll_setup(int may_warn
)
1455 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1456 hotkey_poll_freq
> 0 &&
1457 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1458 if (!tpacpi_hotkey_task
) {
1459 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1462 if (IS_ERR(tpacpi_hotkey_task
)) {
1463 tpacpi_hotkey_task
= NULL
;
1465 "could not create kernel thread "
1466 "for hotkey polling\n");
1470 hotkey_poll_stop_sync();
1472 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1473 printk(TPACPI_NOTICE
1474 "hot keys 0x%08x require polling, "
1475 "which is currently disabled\n",
1476 hotkey_source_mask
);
1481 static void hotkey_poll_setup_safe(int may_warn
)
1483 mutex_lock(&hotkey_mutex
);
1484 hotkey_poll_setup(may_warn
);
1485 mutex_unlock(&hotkey_mutex
);
1488 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
1490 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1492 static void hotkey_poll_setup_safe(int __unused
)
1496 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1498 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
1499 static int hotkey_inputdev_open(struct input_dev
*dev
)
1501 switch (tpacpi_lifecycle
) {
1502 case TPACPI_LIFE_INIT
:
1504 * hotkey_init will call hotkey_poll_setup_safe
1505 * at the appropriate moment
1508 case TPACPI_LIFE_EXITING
:
1510 case TPACPI_LIFE_RUNNING
:
1511 hotkey_poll_setup_safe(0);
1515 /* Should only happen if tpacpi_lifecycle is corrupt */
1520 static void hotkey_inputdev_close(struct input_dev
*dev
)
1522 /* disable hotkey polling when possible */
1523 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1524 hotkey_poll_setup_safe(0);
1526 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
1527 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1529 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
1531 /* sysfs hotkey enable ------------------------------------------------- */
1532 static ssize_t
hotkey_enable_show(struct device
*dev
,
1533 struct device_attribute
*attr
,
1538 res
= hotkey_status_get(&status
);
1542 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1545 static ssize_t
hotkey_enable_store(struct device
*dev
,
1546 struct device_attribute
*attr
,
1547 const char *buf
, size_t count
)
1552 if (parse_strtoul(buf
, 1, &t
))
1555 res
= hotkey_status_set(t
);
1557 return (res
) ? res
: count
;
1560 static struct device_attribute dev_attr_hotkey_enable
=
1561 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1562 hotkey_enable_show
, hotkey_enable_store
);
1564 /* sysfs hotkey mask --------------------------------------------------- */
1565 static ssize_t
hotkey_mask_show(struct device
*dev
,
1566 struct device_attribute
*attr
,
1571 if (mutex_lock_interruptible(&hotkey_mutex
))
1572 return -ERESTARTSYS
;
1573 res
= hotkey_mask_get();
1574 mutex_unlock(&hotkey_mutex
);
1577 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1580 static ssize_t
hotkey_mask_store(struct device
*dev
,
1581 struct device_attribute
*attr
,
1582 const char *buf
, size_t count
)
1587 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1590 if (mutex_lock_interruptible(&hotkey_mutex
))
1591 return -ERESTARTSYS
;
1593 res
= hotkey_mask_set(t
);
1595 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1596 hotkey_poll_setup(1);
1599 mutex_unlock(&hotkey_mutex
);
1601 return (res
) ? res
: count
;
1604 static struct device_attribute dev_attr_hotkey_mask
=
1605 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1606 hotkey_mask_show
, hotkey_mask_store
);
1608 /* sysfs hotkey bios_enabled ------------------------------------------- */
1609 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1610 struct device_attribute
*attr
,
1613 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1616 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1617 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1619 /* sysfs hotkey bios_mask ---------------------------------------------- */
1620 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1621 struct device_attribute
*attr
,
1624 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1627 static struct device_attribute dev_attr_hotkey_bios_mask
=
1628 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1630 /* sysfs hotkey all_mask ----------------------------------------------- */
1631 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1632 struct device_attribute
*attr
,
1635 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1636 hotkey_all_mask
| hotkey_source_mask
);
1639 static struct device_attribute dev_attr_hotkey_all_mask
=
1640 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1642 /* sysfs hotkey recommended_mask --------------------------------------- */
1643 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1644 struct device_attribute
*attr
,
1647 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1648 (hotkey_all_mask
| hotkey_source_mask
)
1649 & ~hotkey_reserved_mask
);
1652 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1653 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1654 hotkey_recommended_mask_show
, NULL
);
1656 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1658 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1659 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1660 struct device_attribute
*attr
,
1663 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1666 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1667 struct device_attribute
*attr
,
1668 const char *buf
, size_t count
)
1672 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1673 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1676 if (mutex_lock_interruptible(&hotkey_mutex
))
1677 return -ERESTARTSYS
;
1679 HOTKEY_CONFIG_CRITICAL_START
1680 hotkey_source_mask
= t
;
1681 HOTKEY_CONFIG_CRITICAL_END
1683 hotkey_poll_setup(1);
1685 mutex_unlock(&hotkey_mutex
);
1690 static struct device_attribute dev_attr_hotkey_source_mask
=
1691 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1692 hotkey_source_mask_show
, hotkey_source_mask_store
);
1694 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1695 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1696 struct device_attribute
*attr
,
1699 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1702 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1703 struct device_attribute
*attr
,
1704 const char *buf
, size_t count
)
1708 if (parse_strtoul(buf
, 25, &t
))
1711 if (mutex_lock_interruptible(&hotkey_mutex
))
1712 return -ERESTARTSYS
;
1714 hotkey_poll_freq
= t
;
1716 hotkey_poll_setup(1);
1717 mutex_unlock(&hotkey_mutex
);
1722 static struct device_attribute dev_attr_hotkey_poll_freq
=
1723 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1724 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1726 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1728 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
1729 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1730 struct device_attribute
*attr
,
1734 res
= hotkey_get_wlsw(&s
);
1738 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1741 static struct device_attribute dev_attr_hotkey_radio_sw
=
1742 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1744 static void hotkey_radio_sw_notify_change(void)
1746 if (tp_features
.hotkey_wlsw
)
1747 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1751 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
1753 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
1754 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
1755 struct device_attribute
*attr
,
1759 res
= hotkey_get_tablet_mode(&s
);
1763 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1766 static struct device_attribute dev_attr_hotkey_tablet_mode
=
1767 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
1769 static void hotkey_tablet_mode_notify_change(void)
1771 if (tp_features
.hotkey_tablet
)
1772 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1773 "hotkey_tablet_mode");
1776 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
1777 /* sysfs hotkey report_mode -------------------------------------------- */
1778 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
1779 struct device_attribute
*attr
,
1782 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1783 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
1786 static struct device_attribute dev_attr_hotkey_report_mode
=
1787 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
1789 /* sysfs wakeup reason (pollable) -------------------------------------- */
1790 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
1791 struct device_attribute
*attr
,
1794 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
1797 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
1798 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
1800 static void hotkey_wakeup_reason_notify_change(void)
1802 if (tp_features
.hotkey_mask
)
1803 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1807 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
1808 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
1809 struct device_attribute
*attr
,
1812 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
1815 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
1816 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
1817 hotkey_wakeup_hotunplug_complete_show
, NULL
);
1819 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
1821 if (tp_features
.hotkey_mask
)
1822 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1823 "wakeup_hotunplug_complete");
1826 /* --------------------------------------------------------------------- */
1828 static struct attribute
*hotkey_attributes
[] __initdata
= {
1829 &dev_attr_hotkey_enable
.attr
,
1830 &dev_attr_hotkey_bios_enabled
.attr
,
1831 &dev_attr_hotkey_report_mode
.attr
,
1832 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1833 &dev_attr_hotkey_mask
.attr
,
1834 &dev_attr_hotkey_all_mask
.attr
,
1835 &dev_attr_hotkey_recommended_mask
.attr
,
1836 &dev_attr_hotkey_source_mask
.attr
,
1837 &dev_attr_hotkey_poll_freq
.attr
,
1841 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
1842 &dev_attr_hotkey_bios_mask
.attr
,
1843 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1844 &dev_attr_hotkey_mask
.attr
,
1845 &dev_attr_hotkey_all_mask
.attr
,
1846 &dev_attr_hotkey_recommended_mask
.attr
,
1848 &dev_attr_hotkey_wakeup_reason
.attr
,
1849 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
1852 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
1854 /* Requirements for changing the default keymaps:
1856 * 1. Many of the keys are mapped to KEY_RESERVED for very
1857 * good reasons. Do not change them unless you have deep
1858 * knowledge on the IBM and Lenovo ThinkPad firmware for
1859 * the various ThinkPad models. The driver behaves
1860 * differently for KEY_RESERVED: such keys have their
1861 * hot key mask *unset* in mask_recommended, and also
1862 * in the initial hot key mask programmed into the
1863 * firmware at driver load time, which means the firm-
1864 * ware may react very differently if you change them to
1867 * 2. You must be subscribed to the linux-thinkpad and
1868 * ibm-acpi-devel mailing lists, and you should read the
1869 * list archives since 2007 if you want to change the
1870 * keymaps. This requirement exists so that you will
1871 * know the past history of problems with the thinkpad-
1872 * acpi driver keymaps, and also that you will be
1873 * listening to any bug reports;
1875 * 3. Do not send thinkpad-acpi specific patches directly to
1876 * for merging, *ever*. Send them to the linux-acpi
1877 * mailinglist for comments. Merging is to be done only
1878 * through acpi-test and the ACPI maintainer.
1880 * If the above is too much to ask, don't change the keymap.
1881 * Ask the thinkpad-acpi maintainer to do it, instead.
1883 static u16 ibm_keycode_map
[] __initdata
= {
1884 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1885 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
1886 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1887 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1889 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1890 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1891 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1892 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1894 /* brightness: firmware always reacts to them, unless
1895 * X.org did some tricks in the radeon BIOS scratch
1896 * registers of *some* models */
1897 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1898 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1900 /* Thinklight: firmware always react to it */
1901 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1903 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1904 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1906 /* Volume: firmware always react to it and reprograms
1907 * the built-in *extra* mixer. Never map it to control
1908 * another mixer by default. */
1909 KEY_RESERVED
, /* 0x14: VOLUME UP */
1910 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1911 KEY_RESERVED
, /* 0x16: MUTE */
1913 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1915 /* (assignments unknown, please report if found) */
1916 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1917 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1919 static u16 lenovo_keycode_map
[] __initdata
= {
1920 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1921 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1922 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1923 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1925 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1926 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1927 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1928 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1930 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1931 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1933 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1935 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1936 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1938 /* Volume: z60/z61, T60 (BIOS version?): firmware always
1939 * react to it and reprograms the built-in *extra* mixer.
1940 * Never map it to control another mixer by default.
1942 * T60?, T61, R60?, R61: firmware and EC tries to send
1943 * these over the regular keyboard, so these are no-ops,
1944 * but there are still weird bugs re. MUTE, so do not
1945 * change unless you get test reports from all Lenovo
1946 * models. May cause the BIOS to interfere with the
1949 KEY_RESERVED
, /* 0x14: VOLUME UP */
1950 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1951 KEY_RESERVED
, /* 0x16: MUTE */
1953 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1955 /* (assignments unknown, please report if found) */
1956 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1957 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1960 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1961 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1962 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1968 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1970 BUG_ON(!tpacpi_inputdev
);
1971 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
1972 tpacpi_inputdev
->close
!= NULL
);
1974 TPACPI_ACPIHANDLE_INIT(hkey
);
1975 mutex_init(&hotkey_mutex
);
1977 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1978 mutex_init(&hotkey_thread_mutex
);
1979 mutex_init(&hotkey_thread_data_mutex
);
1982 /* hotkey not supported on 570 */
1983 tp_features
.hotkey
= hkey_handle
!= NULL
;
1985 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1986 str_supported(tp_features
.hotkey
));
1988 if (tp_features
.hotkey
) {
1989 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
1990 hotkey_dev_attributes
= create_attr_set(12, NULL
);
1992 hotkey_dev_attributes
= create_attr_set(13, NULL
);
1993 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
1994 if (!hotkey_dev_attributes
)
1996 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1998 ARRAY_SIZE(hotkey_attributes
));
2002 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2003 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2004 for HKEY interface version 0x100 */
2005 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2006 if ((hkeyv
>> 8) != 1) {
2007 printk(TPACPI_ERR
"unknown version of the "
2008 "HKEY interface: 0x%x\n", hkeyv
);
2009 printk(TPACPI_ERR
"please report this to %s\n",
2013 * MHKV 0x100 in A31, R40, R40e,
2014 * T4x, X31, and later
2016 tp_features
.hotkey_mask
= 1;
2020 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
2021 str_supported(tp_features
.hotkey_mask
));
2023 if (tp_features
.hotkey_mask
) {
2024 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2027 "missing MHKA handler, "
2028 "please report this to %s\n",
2030 /* FN+F12, FN+F4, FN+F3 */
2031 hotkey_all_mask
= 0x080cU
;
2035 /* hotkey_source_mask *must* be zero for
2036 * the first hotkey_mask_get */
2037 res
= hotkey_status_get(&hotkey_orig_status
);
2038 if (!res
&& tp_features
.hotkey_mask
) {
2039 res
= hotkey_mask_get();
2040 hotkey_orig_mask
= hotkey_mask
;
2042 res
= add_many_to_attr_set(
2043 hotkey_dev_attributes
,
2044 hotkey_mask_attributes
,
2045 ARRAY_SIZE(hotkey_mask_attributes
));
2049 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2050 if (tp_features
.hotkey_mask
) {
2051 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2054 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2057 vdbg_printk(TPACPI_DBG_INIT
,
2058 "hotkey source mask 0x%08x, polling freq %d\n",
2059 hotkey_source_mask
, hotkey_poll_freq
);
2062 /* Not all thinkpads have a hardware radio switch */
2063 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2064 tp_features
.hotkey_wlsw
= 1;
2066 "radio switch found; radios are %s\n",
2067 enabled(status
, 0));
2068 res
= add_to_attr_set(hotkey_dev_attributes
,
2069 &dev_attr_hotkey_radio_sw
.attr
);
2072 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
2074 /* For X41t, X60t, X61t Tablets... */
2075 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2076 tp_features
.hotkey_tablet
= 1;
2078 "possible tablet mode switch found; "
2079 "ThinkPad in %s mode\n",
2080 (status
& TP_HOTKEY_TABLET_MASK
)?
2081 "tablet" : "laptop");
2082 res
= add_to_attr_set(hotkey_dev_attributes
,
2083 &dev_attr_hotkey_tablet_mode
.attr
);
2086 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
2088 res
= register_attr_set_with_sysfs(
2089 hotkey_dev_attributes
,
2090 &tpacpi_pdev
->dev
.kobj
);
2094 /* Set up key map */
2096 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2098 if (!hotkey_keycode_map
) {
2100 "failed to allocate memory for key map\n");
2104 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2105 dbg_printk(TPACPI_DBG_INIT
,
2106 "using Lenovo default hot key map\n");
2107 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2108 TPACPI_HOTKEY_MAP_SIZE
);
2110 dbg_printk(TPACPI_DBG_INIT
,
2111 "using IBM default hot key map\n");
2112 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2113 TPACPI_HOTKEY_MAP_SIZE
);
2116 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2117 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2118 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2119 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2120 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2121 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2122 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2123 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2124 set_bit(hotkey_keycode_map
[i
],
2125 tpacpi_inputdev
->keybit
);
2127 if (i
< sizeof(hotkey_reserved_mask
)*8)
2128 hotkey_reserved_mask
|= 1 << i
;
2132 if (tp_features
.hotkey_wlsw
) {
2133 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2134 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
2136 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
2138 if (tp_features
.hotkey_tablet
) {
2139 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2140 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2142 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
2144 dbg_printk(TPACPI_DBG_INIT
,
2145 "enabling hot key handling\n");
2146 res
= hotkey_status_set(1);
2149 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2150 & ~hotkey_reserved_mask
)
2151 | hotkey_orig_mask
);
2152 if (res
< 0 && res
!= -ENXIO
)
2155 dbg_printk(TPACPI_DBG_INIT
,
2156 "legacy hot key reporting over procfs %s\n",
2157 (hotkey_report_mode
< 2) ?
2158 "enabled" : "disabled");
2160 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
2161 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2163 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
2164 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2165 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2167 hotkey_poll_setup_safe(1);
2168 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
2171 tpacpi_input_send_radiosw();
2172 tpacpi_input_send_tabletsw();
2173 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
2176 return (tp_features
.hotkey
)? 0 : 1;
2179 static void hotkey_exit(void)
2181 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2182 hotkey_poll_stop_sync();
2185 if (tp_features
.hotkey
) {
2186 dbg_printk(TPACPI_DBG_EXIT
,
2187 "restoring original hot key mask\n");
2188 /* no short-circuit boolean operator below! */
2189 if ((hotkey_mask_set(hotkey_orig_mask
) |
2190 hotkey_status_set(hotkey_orig_status
)) != 0)
2192 "failed to restore hot key mask "
2193 "to BIOS defaults\n");
2196 if (hotkey_dev_attributes
) {
2197 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2198 hotkey_dev_attributes
= NULL
;
2202 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2205 unsigned int scancode
;
2210 if (event
!= 0x80) {
2212 "unknown HKEY notification event %d\n", event
);
2213 /* forward it to userspace, maybe it knows how to handle it */
2214 acpi_bus_generate_netlink_event(
2215 ibm
->acpi
->device
->pnp
.device_class
,
2216 ibm
->acpi
->device
->dev
.bus_id
,
2222 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2223 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2236 switch (hkey
>> 12) {
2238 /* 0x1000-0x1FFF: key presses */
2239 scancode
= hkey
& 0xfff;
2240 if (scancode
> 0 && scancode
< 0x21) {
2242 if (!(hotkey_source_mask
& (1 << scancode
))) {
2243 tpacpi_input_send_key(scancode
);
2255 case 0x2304: /* suspend, undock */
2256 case 0x2404: /* hibernation, undock */
2257 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2260 case 0x2305: /* suspend, bay eject */
2261 case 0x2405: /* hibernation, bay eject */
2262 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2268 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2270 "woke up due to a hot-unplug "
2272 hotkey_wakeup_reason_notify_change();
2276 /* bay-related wakeups */
2277 if (hkey
== 0x3003) {
2278 hotkey_autosleep_ack
= 1;
2281 hotkey_wakeup_hotunplug_complete_notify_change();
2287 /* dock-related wakeups */
2288 if (hkey
== 0x4003) {
2289 hotkey_autosleep_ack
= 1;
2292 hotkey_wakeup_hotunplug_complete_notify_change();
2298 /* 0x5000-0x5FFF: human interface helpers */
2300 case 0x5010: /* Lenovo new BIOS: brightness changed */
2301 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
2302 case 0x5009: /* X61t: swivel up (tablet mode) */
2303 case 0x500a: /* X61t: swivel down (normal mode) */
2305 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
2306 case 0x500b: /* X61t: tablet pen inserted into bay */
2307 case 0x500c: /* X61t: tablet pen removed from bay */
2309 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
2311 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2312 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2313 tpacpi_input_send_tabletsw();
2314 hotkey_tablet_mode_notify_change();
2317 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
2320 /* LID switch events. Do not propagate */
2328 /* 0x7000-0x7FFF: misc */
2329 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2330 tpacpi_input_send_radiosw();
2331 hotkey_radio_sw_notify_change();
2335 /* fallthrough to default */
2340 printk(TPACPI_NOTICE
2341 "unhandled HKEY event 0x%04x\n", hkey
);
2345 if (!ignore_acpi_ev
&&
2346 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2347 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2351 /* netlink events */
2352 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2353 acpi_bus_generate_netlink_event(
2354 ibm
->acpi
->device
->pnp
.device_class
,
2355 ibm
->acpi
->device
->dev
.bus_id
,
2361 static void hotkey_suspend(pm_message_t state
)
2363 /* Do these on suspend, we get the events on early resume! */
2364 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2365 hotkey_autosleep_ack
= 0;
2368 static void hotkey_resume(void)
2370 if (hotkey_mask_get())
2372 "error while trying to read hot key mask "
2374 tpacpi_input_send_radiosw();
2375 hotkey_radio_sw_notify_change();
2376 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
2378 hotkey_tablet_mode_notify_change();
2379 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
2380 hotkey_wakeup_reason_notify_change();
2381 hotkey_wakeup_hotunplug_complete_notify_change();
2382 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
2383 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2385 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
2386 hotkey_poll_setup_safe(0);
2387 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
2390 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
2393 /* procfs -------------------------------------------------------------- */
2394 static int hotkey_read(char *p
)
2399 if (!tp_features
.hotkey
) {
2400 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2404 if (mutex_lock_interruptible(&hotkey_mutex
))
2405 return -ERESTARTSYS
;
2406 res
= hotkey_status_get(&status
);
2408 res
= hotkey_mask_get();
2409 mutex_unlock(&hotkey_mutex
);
2413 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2414 if (tp_features
.hotkey_mask
) {
2415 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2416 len
+= sprintf(p
+ len
,
2417 "commands:\tenable, disable, reset, <mask>\n");
2419 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2420 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2426 static int hotkey_write(char *buf
)
2432 if (!tp_features
.hotkey
)
2435 if (mutex_lock_interruptible(&hotkey_mutex
))
2436 return -ERESTARTSYS
;
2442 while ((cmd
= next_cmd(&buf
))) {
2443 if (strlencmp(cmd
, "enable") == 0) {
2445 } else if (strlencmp(cmd
, "disable") == 0) {
2447 } else if (strlencmp(cmd
, "reset") == 0) {
2448 status
= hotkey_orig_status
;
2449 mask
= hotkey_orig_mask
;
2450 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2452 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2460 res
= hotkey_status_set(status
);
2462 if (!res
&& mask
!= hotkey_mask
)
2463 res
= hotkey_mask_set(mask
);
2466 mutex_unlock(&hotkey_mutex
);
2470 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2471 {TPACPI_ACPI_HKEY_HID
, 0},
2475 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2476 .hid
= ibm_htk_device_ids
,
2477 .notify
= hotkey_notify
,
2478 .handle
= &hkey_handle
,
2479 .type
= ACPI_DEVICE_NOTIFY
,
2482 static struct ibm_struct hotkey_driver_data
= {
2484 .read
= hotkey_read
,
2485 .write
= hotkey_write
,
2486 .exit
= hotkey_exit
,
2487 .resume
= hotkey_resume
,
2488 .suspend
= hotkey_suspend
,
2489 .acpi
= &ibm_hotkey_acpidriver
,
2492 /*************************************************************************
2493 * Bluetooth subdriver
2497 /* ACPI GBDC/SBDC bits */
2498 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2499 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2500 TP_ACPI_BLUETOOTH_UNK
= 0x04, /* unknown function */
2503 static int bluetooth_get_radiosw(void);
2504 static int bluetooth_set_radiosw(int radio_on
);
2506 /* sysfs bluetooth enable ---------------------------------------------- */
2507 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2508 struct device_attribute
*attr
,
2513 status
= bluetooth_get_radiosw();
2517 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2520 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2521 struct device_attribute
*attr
,
2522 const char *buf
, size_t count
)
2527 if (parse_strtoul(buf
, 1, &t
))
2530 res
= bluetooth_set_radiosw(t
);
2532 return (res
) ? res
: count
;
2535 static struct device_attribute dev_attr_bluetooth_enable
=
2536 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2537 bluetooth_enable_show
, bluetooth_enable_store
);
2539 /* --------------------------------------------------------------------- */
2541 static struct attribute
*bluetooth_attributes
[] = {
2542 &dev_attr_bluetooth_enable
.attr
,
2546 static const struct attribute_group bluetooth_attr_group
= {
2547 .attrs
= bluetooth_attributes
,
2550 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
2555 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
2557 TPACPI_ACPIHANDLE_INIT(hkey
);
2559 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2560 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
2561 tp_features
.bluetooth
= hkey_handle
&&
2562 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
2564 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
2565 str_supported(tp_features
.bluetooth
),
2568 if (tp_features
.bluetooth
) {
2569 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
2570 /* no bluetooth hardware present in system */
2571 tp_features
.bluetooth
= 0;
2572 dbg_printk(TPACPI_DBG_INIT
,
2573 "bluetooth hardware not installed\n");
2575 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2576 &bluetooth_attr_group
);
2582 return (tp_features
.bluetooth
)? 0 : 1;
2585 static void bluetooth_exit(void)
2587 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2588 &bluetooth_attr_group
);
2591 static int bluetooth_get_radiosw(void)
2595 if (!tp_features
.bluetooth
)
2598 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2601 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
2604 static int bluetooth_set_radiosw(int radio_on
)
2608 if (!tp_features
.bluetooth
)
2611 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2614 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
2616 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
2617 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2623 /* procfs -------------------------------------------------------------- */
2624 static int bluetooth_read(char *p
)
2627 int status
= bluetooth_get_radiosw();
2629 if (!tp_features
.bluetooth
)
2630 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2632 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2633 (status
)? "enabled" : "disabled");
2634 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2640 static int bluetooth_write(char *buf
)
2644 if (!tp_features
.bluetooth
)
2647 while ((cmd
= next_cmd(&buf
))) {
2648 if (strlencmp(cmd
, "enable") == 0) {
2649 bluetooth_set_radiosw(1);
2650 } else if (strlencmp(cmd
, "disable") == 0) {
2651 bluetooth_set_radiosw(0);
2659 static struct ibm_struct bluetooth_driver_data
= {
2660 .name
= "bluetooth",
2661 .read
= bluetooth_read
,
2662 .write
= bluetooth_write
,
2663 .exit
= bluetooth_exit
,
2666 /*************************************************************************
2671 /* ACPI GWAN/SWAN bits */
2672 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
2673 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
2674 TP_ACPI_WANCARD_UNK
= 0x04, /* unknown function */
2677 static int wan_get_radiosw(void);
2678 static int wan_set_radiosw(int radio_on
);
2680 /* sysfs wan enable ---------------------------------------------------- */
2681 static ssize_t
wan_enable_show(struct device
*dev
,
2682 struct device_attribute
*attr
,
2687 status
= wan_get_radiosw();
2691 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2694 static ssize_t
wan_enable_store(struct device
*dev
,
2695 struct device_attribute
*attr
,
2696 const char *buf
, size_t count
)
2701 if (parse_strtoul(buf
, 1, &t
))
2704 res
= wan_set_radiosw(t
);
2706 return (res
) ? res
: count
;
2709 static struct device_attribute dev_attr_wan_enable
=
2710 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
2711 wan_enable_show
, wan_enable_store
);
2713 /* --------------------------------------------------------------------- */
2715 static struct attribute
*wan_attributes
[] = {
2716 &dev_attr_wan_enable
.attr
,
2720 static const struct attribute_group wan_attr_group
= {
2721 .attrs
= wan_attributes
,
2724 static int __init
wan_init(struct ibm_init_struct
*iibm
)
2729 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
2731 TPACPI_ACPIHANDLE_INIT(hkey
);
2733 tp_features
.wan
= hkey_handle
&&
2734 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
2736 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
2737 str_supported(tp_features
.wan
),
2740 if (tp_features
.wan
) {
2741 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
2742 /* no wan hardware present in system */
2743 tp_features
.wan
= 0;
2744 dbg_printk(TPACPI_DBG_INIT
,
2745 "wan hardware not installed\n");
2747 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2754 return (tp_features
.wan
)? 0 : 1;
2757 static void wan_exit(void)
2759 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2763 static int wan_get_radiosw(void)
2767 if (!tp_features
.wan
)
2770 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2773 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
2776 static int wan_set_radiosw(int radio_on
)
2780 if (!tp_features
.wan
)
2783 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2786 status
|= TP_ACPI_WANCARD_RADIOSSW
;
2788 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
2789 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
2795 /* procfs -------------------------------------------------------------- */
2796 static int wan_read(char *p
)
2799 int status
= wan_get_radiosw();
2801 if (!tp_features
.wan
)
2802 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2804 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2805 (status
)? "enabled" : "disabled");
2806 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2812 static int wan_write(char *buf
)
2816 if (!tp_features
.wan
)
2819 while ((cmd
= next_cmd(&buf
))) {
2820 if (strlencmp(cmd
, "enable") == 0) {
2822 } else if (strlencmp(cmd
, "disable") == 0) {
2831 static struct ibm_struct wan_driver_data
= {
2836 .flags
.experimental
= 1,
2839 /*************************************************************************
2843 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
2845 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
2847 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
2848 enum video_access_mode
{
2849 TPACPI_VIDEO_NONE
= 0,
2850 TPACPI_VIDEO_570
, /* 570 */
2851 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
2852 TPACPI_VIDEO_NEW
, /* all others */
2855 enum { /* video status flags, based on VIDEO_570 */
2856 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
2857 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
2858 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
2861 enum { /* TPACPI_VIDEO_570 constants */
2862 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
2863 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
2864 * video_status_flags */
2865 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
2866 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
2869 static enum video_access_mode video_supported
;
2870 static int video_orig_autosw
;
2872 static int video_autosw_get(void);
2873 static int video_autosw_set(int enable
);
2875 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
2876 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
2877 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
2878 "\\_SB.PCI0.VID0", /* 770e */
2879 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
2880 "\\_SB.PCI0.AGP.VID", /* all others */
2884 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
2885 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
2887 static int __init
video_init(struct ibm_init_struct
*iibm
)
2891 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
2893 TPACPI_ACPIHANDLE_INIT(vid
);
2894 TPACPI_ACPIHANDLE_INIT(vid2
);
2896 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
2897 /* G41, assume IVGA doesn't change */
2898 vid_handle
= vid2_handle
;
2901 /* video switching not supported on R30, R31 */
2902 video_supported
= TPACPI_VIDEO_NONE
;
2903 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
2905 video_supported
= TPACPI_VIDEO_570
;
2906 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
2907 /* 600e/x, 770e, 770x */
2908 video_supported
= TPACPI_VIDEO_770
;
2911 video_supported
= TPACPI_VIDEO_NEW
;
2913 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
2914 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
2917 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
2920 static void video_exit(void)
2922 dbg_printk(TPACPI_DBG_EXIT
,
2923 "restoring original video autoswitch mode\n");
2924 if (video_autosw_set(video_orig_autosw
))
2925 printk(TPACPI_ERR
"error while trying to restore original "
2926 "video autoswitch mode\n");
2929 static int video_outputsw_get(void)
2934 switch (video_supported
) {
2935 case TPACPI_VIDEO_570
:
2936 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
2937 TP_ACPI_VIDEO_570_PHSCMD
))
2939 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
2941 case TPACPI_VIDEO_770
:
2942 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2945 status
|= TP_ACPI_VIDEO_S_LCD
;
2946 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2949 status
|= TP_ACPI_VIDEO_S_CRT
;
2951 case TPACPI_VIDEO_NEW
:
2952 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
2953 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2956 status
|= TP_ACPI_VIDEO_S_CRT
;
2958 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
2959 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2962 status
|= TP_ACPI_VIDEO_S_LCD
;
2963 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
2966 status
|= TP_ACPI_VIDEO_S_DVI
;
2975 static int video_outputsw_set(int status
)
2980 switch (video_supported
) {
2981 case TPACPI_VIDEO_570
:
2982 res
= acpi_evalf(NULL
, NULL
,
2983 "\\_SB.PHS2", "vdd",
2984 TP_ACPI_VIDEO_570_PHS2CMD
,
2985 status
| TP_ACPI_VIDEO_570_PHS2SET
);
2987 case TPACPI_VIDEO_770
:
2988 autosw
= video_autosw_get();
2992 res
= video_autosw_set(1);
2995 res
= acpi_evalf(vid_handle
, NULL
,
2996 "ASWT", "vdd", status
* 0x100, 0);
2997 if (!autosw
&& video_autosw_set(autosw
)) {
2999 "video auto-switch left enabled due to error\n");
3003 case TPACPI_VIDEO_NEW
:
3004 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
3005 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
3011 return (res
)? 0 : -EIO
;
3014 static int video_autosw_get(void)
3018 switch (video_supported
) {
3019 case TPACPI_VIDEO_570
:
3020 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
3023 case TPACPI_VIDEO_770
:
3024 case TPACPI_VIDEO_NEW
:
3025 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
3035 static int video_autosw_set(int enable
)
3037 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
3042 static int video_outputsw_cycle(void)
3044 int autosw
= video_autosw_get();
3050 switch (video_supported
) {
3051 case TPACPI_VIDEO_570
:
3052 res
= video_autosw_set(1);
3055 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
3057 case TPACPI_VIDEO_770
:
3058 case TPACPI_VIDEO_NEW
:
3059 res
= video_autosw_set(1);
3062 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
3067 if (!autosw
&& video_autosw_set(autosw
)) {
3069 "video auto-switch left enabled due to error\n");
3073 return (res
)? 0 : -EIO
;
3076 static int video_expand_toggle(void)
3078 switch (video_supported
) {
3079 case TPACPI_VIDEO_570
:
3080 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
3082 case TPACPI_VIDEO_770
:
3083 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
3085 case TPACPI_VIDEO_NEW
:
3086 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
3094 static int video_read(char *p
)
3099 if (video_supported
== TPACPI_VIDEO_NONE
) {
3100 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3104 status
= video_outputsw_get();
3108 autosw
= video_autosw_get();
3112 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3113 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
3114 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
3115 if (video_supported
== TPACPI_VIDEO_NEW
)
3116 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
3117 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
3118 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
3119 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
3120 if (video_supported
== TPACPI_VIDEO_NEW
)
3121 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
3122 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
3123 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
3128 static int video_write(char *buf
)
3131 int enable
, disable
, status
;
3134 if (video_supported
== TPACPI_VIDEO_NONE
)
3140 while ((cmd
= next_cmd(&buf
))) {
3141 if (strlencmp(cmd
, "lcd_enable") == 0) {
3142 enable
|= TP_ACPI_VIDEO_S_LCD
;
3143 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
3144 disable
|= TP_ACPI_VIDEO_S_LCD
;
3145 } else if (strlencmp(cmd
, "crt_enable") == 0) {
3146 enable
|= TP_ACPI_VIDEO_S_CRT
;
3147 } else if (strlencmp(cmd
, "crt_disable") == 0) {
3148 disable
|= TP_ACPI_VIDEO_S_CRT
;
3149 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3150 strlencmp(cmd
, "dvi_enable") == 0) {
3151 enable
|= TP_ACPI_VIDEO_S_DVI
;
3152 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3153 strlencmp(cmd
, "dvi_disable") == 0) {
3154 disable
|= TP_ACPI_VIDEO_S_DVI
;
3155 } else if (strlencmp(cmd
, "auto_enable") == 0) {
3156 res
= video_autosw_set(1);
3159 } else if (strlencmp(cmd
, "auto_disable") == 0) {
3160 res
= video_autosw_set(0);
3163 } else if (strlencmp(cmd
, "video_switch") == 0) {
3164 res
= video_outputsw_cycle();
3167 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
3168 res
= video_expand_toggle();
3175 if (enable
|| disable
) {
3176 status
= video_outputsw_get();
3179 res
= video_outputsw_set((status
& ~disable
) | enable
);
3187 static struct ibm_struct video_driver_data
= {
3190 .write
= video_write
,
3194 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
3196 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
3198 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
3199 /*************************************************************************
3200 * Light (thinklight) subdriver
3203 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
3204 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
3206 static int __init
light_init(struct ibm_init_struct
*iibm
)
3208 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
3210 TPACPI_ACPIHANDLE_INIT(ledb
);
3211 TPACPI_ACPIHANDLE_INIT(lght
);
3212 TPACPI_ACPIHANDLE_INIT(cmos
);
3214 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
3215 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
3217 if (tp_features
.light
)
3218 /* light status not supported on
3219 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
3220 tp_features
.light_status
=
3221 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
3223 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
3224 str_supported(tp_features
.light
));
3226 return (tp_features
.light
)? 0 : 1;
3229 static int light_read(char *p
)
3234 if (!tp_features
.light
) {
3235 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3236 } else if (!tp_features
.light_status
) {
3237 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
3238 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3240 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
3242 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
3243 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3249 static int light_write(char *buf
)
3251 int cmos_cmd
, lght_cmd
;
3255 if (!tp_features
.light
)
3258 while ((cmd
= next_cmd(&buf
))) {
3259 if (strlencmp(cmd
, "on") == 0) {
3262 } else if (strlencmp(cmd
, "off") == 0) {
3268 success
= cmos_handle
?
3269 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
3270 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
3278 static struct ibm_struct light_driver_data
= {
3281 .write
= light_write
,
3284 /*************************************************************************
3288 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3290 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
3291 static int dock_read(char *p
);
3292 static int dock_write(char *buf
);
3294 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
3295 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
3296 "\\_SB.PCI0.PCI1.DOCK", /* all others */
3297 "\\_SB.PCI.ISA.SLCE", /* 570 */
3298 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
3300 /* don't list other alternatives as we install a notify handler on the 570 */
3301 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
3303 static const struct acpi_device_id ibm_pci_device_ids
[] = {
3304 {PCI_ROOT_HID_STRING
, 0},
3308 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
3310 .notify
= dock_notify
,
3311 .handle
= &dock_handle
,
3312 .type
= ACPI_SYSTEM_NOTIFY
,
3315 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
3316 * We just use it to get notifications of dock hotplug
3317 * in very old thinkpads */
3318 .hid
= ibm_pci_device_ids
,
3319 .notify
= dock_notify
,
3320 .handle
= &pci_handle
,
3321 .type
= ACPI_SYSTEM_NOTIFY
,
3325 static struct ibm_struct dock_driver_data
[2] = {
3329 .write
= dock_write
,
3330 .acpi
= &ibm_dock_acpidriver
[0],
3334 .acpi
= &ibm_dock_acpidriver
[1],
3338 #define dock_docked() (_sta(dock_handle) & 1)
3340 static int __init
dock_init(struct ibm_init_struct
*iibm
)
3342 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
3344 TPACPI_ACPIHANDLE_INIT(dock
);
3346 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
3347 str_supported(dock_handle
!= NULL
));
3349 return (dock_handle
)? 0 : 1;
3352 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
3356 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
3358 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
3359 dock_driver_data
[0].flags
.acpi_notify_installed
) {
3360 TPACPI_ACPIHANDLE_INIT(pci
);
3361 dock2_needed
= (pci_handle
!= NULL
);
3362 vdbg_printk(TPACPI_DBG_INIT
,
3363 "dock PCI handler for the TP 570 is %s\n",
3364 str_supported(dock2_needed
));
3366 vdbg_printk(TPACPI_DBG_INIT
,
3367 "dock subdriver part 2 not required\n");
3371 return (dock2_needed
)? 0 : 1;
3374 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
3376 int docked
= dock_docked();
3377 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
3378 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
3381 if (event
== 1 && !pci
) /* 570 */
3382 data
= 1; /* button */
3383 else if (event
== 1 && pci
) /* 570 */
3384 data
= 3; /* dock */
3385 else if (event
== 3 && docked
)
3386 data
= 1; /* button */
3387 else if (event
== 3 && !docked
)
3388 data
= 2; /* undock */
3389 else if (event
== 0 && docked
)
3390 data
= 3; /* dock */
3392 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
3393 event
, _sta(dock_handle
));
3394 data
= 0; /* unknown */
3396 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
3397 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3398 ibm
->acpi
->device
->dev
.bus_id
,
3402 static int dock_read(char *p
)
3405 int docked
= dock_docked();
3408 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3410 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
3412 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
3413 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
3419 static int dock_write(char *buf
)
3426 while ((cmd
= next_cmd(&buf
))) {
3427 if (strlencmp(cmd
, "undock") == 0) {
3428 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
3429 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
3431 } else if (strlencmp(cmd
, "dock") == 0) {
3432 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
3441 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
3443 /*************************************************************************
3447 #ifdef CONFIG_THINKPAD_ACPI_BAY
3449 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
3450 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
3451 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
3452 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
3453 ); /* A21e, R30, R31 */
3454 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
3455 "_EJ0", /* all others */
3456 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
3457 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
3458 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
3460 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
3464 static int __init
bay_init(struct ibm_init_struct
*iibm
)
3466 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
3468 TPACPI_ACPIHANDLE_INIT(bay
);
3470 TPACPI_ACPIHANDLE_INIT(bay_ej
);
3471 TPACPI_ACPIHANDLE_INIT(bay2
);
3473 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
3475 tp_features
.bay_status
= bay_handle
&&
3476 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
3477 tp_features
.bay_status2
= bay2_handle
&&
3478 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
3480 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
3481 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
3482 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
3483 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
3485 vdbg_printk(TPACPI_DBG_INIT
,
3486 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
3487 str_supported(tp_features
.bay_status
),
3488 str_supported(tp_features
.bay_eject
),
3489 str_supported(tp_features
.bay_status2
),
3490 str_supported(tp_features
.bay_eject2
));
3492 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
3493 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
3496 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
3498 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
3499 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3500 ibm
->acpi
->device
->dev
.bus_id
,
3504 #define bay_occupied(b) (_sta(b##_handle) & 1)
3506 static int bay_read(char *p
)
3509 int occupied
= bay_occupied(bay
);
3510 int occupied2
= bay_occupied(bay2
);
3513 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3514 tp_features
.bay_status
?
3515 (occupied
? "occupied" : "unoccupied") :
3517 if (tp_features
.bay_status2
)
3518 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
3519 "occupied" : "unoccupied");
3521 eject
= tp_features
.bay_eject
&& occupied
;
3522 eject2
= tp_features
.bay_eject2
&& occupied2
;
3524 if (eject
&& eject2
)
3525 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
3527 len
+= sprintf(p
+ len
, "commands:\teject\n");
3529 len
+= sprintf(p
+ len
, "commands:\teject2\n");
3534 static int bay_write(char *buf
)
3538 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
3541 while ((cmd
= next_cmd(&buf
))) {
3542 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
3543 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
3545 } else if (tp_features
.bay_eject2
&&
3546 strlencmp(cmd
, "eject2") == 0) {
3547 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
3556 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
3557 .notify
= bay_notify
,
3558 .handle
= &bay_handle
,
3559 .type
= ACPI_SYSTEM_NOTIFY
,
3562 static struct ibm_struct bay_driver_data
= {
3566 .acpi
= &ibm_bay_acpidriver
,
3569 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3571 /*************************************************************************
3575 /* sysfs cmos_command -------------------------------------------------- */
3576 static ssize_t
cmos_command_store(struct device
*dev
,
3577 struct device_attribute
*attr
,
3578 const char *buf
, size_t count
)
3580 unsigned long cmos_cmd
;
3583 if (parse_strtoul(buf
, 21, &cmos_cmd
))
3586 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3587 return (res
)? res
: count
;
3590 static struct device_attribute dev_attr_cmos_command
=
3591 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
3593 /* --------------------------------------------------------------------- */
3595 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
3599 vdbg_printk(TPACPI_DBG_INIT
,
3600 "initializing cmos commands subdriver\n");
3602 TPACPI_ACPIHANDLE_INIT(cmos
);
3604 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
3605 str_supported(cmos_handle
!= NULL
));
3607 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3611 return (cmos_handle
)? 0 : 1;
3614 static void cmos_exit(void)
3616 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3619 static int cmos_read(char *p
)
3623 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3624 R30, R31, T20-22, X20-21 */
3626 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3628 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3629 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
3635 static int cmos_write(char *buf
)
3640 while ((cmd
= next_cmd(&buf
))) {
3641 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
3642 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
3647 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3655 static struct ibm_struct cmos_driver_data
= {
3658 .write
= cmos_write
,
3662 /*************************************************************************
3666 enum led_access_mode
{
3667 TPACPI_LED_NONE
= 0,
3668 TPACPI_LED_570
, /* 570 */
3669 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3670 TPACPI_LED_NEW
, /* all others */
3673 enum { /* For TPACPI_LED_OLD */
3674 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
3675 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
3676 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
3679 static enum led_access_mode led_supported
;
3681 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
3682 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
3683 /* T20-22, X20-21 */
3684 "LED", /* all others */
3687 static int __init
led_init(struct ibm_init_struct
*iibm
)
3689 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
3691 TPACPI_ACPIHANDLE_INIT(led
);
3694 /* led not supported on R30, R31 */
3695 led_supported
= TPACPI_LED_NONE
;
3696 else if (strlencmp(led_path
, "SLED") == 0)
3698 led_supported
= TPACPI_LED_570
;
3699 else if (strlencmp(led_path
, "SYSL") == 0)
3700 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3701 led_supported
= TPACPI_LED_OLD
;
3704 led_supported
= TPACPI_LED_NEW
;
3706 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
3707 str_supported(led_supported
), led_supported
);
3709 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
3712 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
3714 static int led_read(char *p
)
3718 if (!led_supported
) {
3719 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3722 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3724 if (led_supported
== TPACPI_LED_570
) {
3727 for (i
= 0; i
< 8; i
++) {
3728 if (!acpi_evalf(ec_handle
,
3729 &status
, "GLED", "dd", 1 << i
))
3731 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
3732 i
, led_status(status
));
3736 len
+= sprintf(p
+ len
, "commands:\t"
3737 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
3742 /* off, on, blink */
3743 static const int led_sled_arg1
[] = { 0, 1, 3 };
3744 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
3745 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
3746 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
3748 static int led_write(char *buf
)
3756 while ((cmd
= next_cmd(&buf
))) {
3757 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
3760 if (strstr(cmd
, "off")) {
3762 } else if (strstr(cmd
, "on")) {
3764 } else if (strstr(cmd
, "blink")) {
3769 if (led_supported
== TPACPI_LED_570
) {
3772 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3773 led
, led_sled_arg1
[ind
]))
3775 } else if (led_supported
== TPACPI_LED_OLD
) {
3776 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
3778 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
3780 ret
= ec_write(TPACPI_LED_EC_HLBL
,
3781 led
* led_exp_hlbl
[ind
]);
3783 ret
= ec_write(TPACPI_LED_EC_HLCL
,
3784 led
* led_exp_hlcl
[ind
]);
3789 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3790 led
, led_led_arg1
[ind
]))
3798 static struct ibm_struct led_driver_data
= {
3804 /*************************************************************************
3808 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
3810 static int __init
beep_init(struct ibm_init_struct
*iibm
)
3812 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
3814 TPACPI_ACPIHANDLE_INIT(beep
);
3816 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
3817 str_supported(beep_handle
!= NULL
));
3819 return (beep_handle
)? 0 : 1;
3822 static int beep_read(char *p
)
3827 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3829 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3830 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
3836 static int beep_write(char *buf
)
3844 while ((cmd
= next_cmd(&buf
))) {
3845 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
3846 beep_cmd
>= 0 && beep_cmd
<= 17) {
3850 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
3857 static struct ibm_struct beep_driver_data
= {
3860 .write
= beep_write
,
3863 /*************************************************************************
3867 enum thermal_access_mode
{
3868 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
3869 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
3870 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
3871 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
3872 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
3875 enum { /* TPACPI_THERMAL_TPEC_* */
3876 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
3877 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
3878 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
3881 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
3882 struct ibm_thermal_sensors_struct
{
3883 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
3886 static enum thermal_access_mode thermal_read_mode
;
3888 /* idx is zero-based */
3889 static int thermal_get_sensor(int idx
, s32
*value
)
3895 t
= TP_EC_THERMAL_TMP0
;
3897 switch (thermal_read_mode
) {
3898 #if TPACPI_MAX_THERMAL_SENSORS >= 16
3899 case TPACPI_THERMAL_TPEC_16
:
3900 if (idx
>= 8 && idx
<= 15) {
3901 t
= TP_EC_THERMAL_TMP8
;
3906 case TPACPI_THERMAL_TPEC_8
:
3908 if (!acpi_ec_read(t
+ idx
, &tmp
))
3910 *value
= tmp
* 1000;
3915 case TPACPI_THERMAL_ACPI_UPDT
:
3917 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3918 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
3920 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3922 *value
= (t
- 2732) * 100;
3927 case TPACPI_THERMAL_ACPI_TMP07
:
3929 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3930 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3932 if (t
> 127 || t
< -127)
3933 t
= TP_EC_THERMAL_TMP_NA
;
3939 case TPACPI_THERMAL_NONE
:
3947 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
3958 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
3961 for (i
= 0 ; i
< n
; i
++) {
3962 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3970 /* sysfs temp##_input -------------------------------------------------- */
3972 static ssize_t
thermal_temp_input_show(struct device
*dev
,
3973 struct device_attribute
*attr
,
3976 struct sensor_device_attribute
*sensor_attr
=
3977 to_sensor_dev_attr(attr
);
3978 int idx
= sensor_attr
->index
;
3982 res
= thermal_get_sensor(idx
, &value
);
3985 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
3988 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
3991 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
3992 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
3993 thermal_temp_input_show, NULL, _idxB)
3995 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
3996 THERMAL_SENSOR_ATTR_TEMP(1, 0),
3997 THERMAL_SENSOR_ATTR_TEMP(2, 1),
3998 THERMAL_SENSOR_ATTR_TEMP(3, 2),
3999 THERMAL_SENSOR_ATTR_TEMP(4, 3),
4000 THERMAL_SENSOR_ATTR_TEMP(5, 4),
4001 THERMAL_SENSOR_ATTR_TEMP(6, 5),
4002 THERMAL_SENSOR_ATTR_TEMP(7, 6),
4003 THERMAL_SENSOR_ATTR_TEMP(8, 7),
4004 THERMAL_SENSOR_ATTR_TEMP(9, 8),
4005 THERMAL_SENSOR_ATTR_TEMP(10, 9),
4006 THERMAL_SENSOR_ATTR_TEMP(11, 10),
4007 THERMAL_SENSOR_ATTR_TEMP(12, 11),
4008 THERMAL_SENSOR_ATTR_TEMP(13, 12),
4009 THERMAL_SENSOR_ATTR_TEMP(14, 13),
4010 THERMAL_SENSOR_ATTR_TEMP(15, 14),
4011 THERMAL_SENSOR_ATTR_TEMP(16, 15),
4014 #define THERMAL_ATTRS(X) \
4015 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
4017 static struct attribute
*thermal_temp_input_attr
[] = {
4037 static const struct attribute_group thermal_temp_input16_group
= {
4038 .attrs
= thermal_temp_input_attr
4041 static const struct attribute_group thermal_temp_input8_group
= {
4042 .attrs
= &thermal_temp_input_attr
[8]
4045 #undef THERMAL_SENSOR_ATTR_TEMP
4046 #undef THERMAL_ATTRS
4048 /* --------------------------------------------------------------------- */
4050 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
4057 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
4059 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
4061 if (thinkpad_id
.ec_model
) {
4063 * Direct EC access mode: sensors at registers
4064 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
4065 * non-implemented, thermal sensors return 0x80 when
4070 for (i
= 0; i
< 8; i
++) {
4071 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
4077 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
4085 /* This is sheer paranoia, but we handle it anyway */
4088 "ThinkPad ACPI EC access misbehaving, "
4089 "falling back to ACPI TMPx access "
4091 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4094 "ThinkPad ACPI EC access misbehaving, "
4095 "disabling thermal sensors access\n");
4096 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4101 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
4103 } else if (acpi_tmp7
) {
4104 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
4105 /* 600e/x, 770e, 770x */
4106 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
4108 /* Standard ACPI TMPx access, max 8 sensors */
4109 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4112 /* temperatures not supported on 570, G4x, R30, R31, R32 */
4113 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4116 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
4117 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
4120 switch (thermal_read_mode
) {
4121 case TPACPI_THERMAL_TPEC_16
:
4122 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4123 &thermal_temp_input16_group
);
4127 case TPACPI_THERMAL_TPEC_8
:
4128 case TPACPI_THERMAL_ACPI_TMP07
:
4129 case TPACPI_THERMAL_ACPI_UPDT
:
4130 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4131 &thermal_temp_input8_group
);
4135 case TPACPI_THERMAL_NONE
:
4143 static void thermal_exit(void)
4145 switch (thermal_read_mode
) {
4146 case TPACPI_THERMAL_TPEC_16
:
4147 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4148 &thermal_temp_input16_group
);
4150 case TPACPI_THERMAL_TPEC_8
:
4151 case TPACPI_THERMAL_ACPI_TMP07
:
4152 case TPACPI_THERMAL_ACPI_UPDT
:
4153 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4154 &thermal_temp_input16_group
);
4156 case TPACPI_THERMAL_NONE
:
4162 static int thermal_read(char *p
)
4166 struct ibm_thermal_sensors_struct t
;
4168 n
= thermal_get_sensors(&t
);
4169 if (unlikely(n
< 0))
4172 len
+= sprintf(p
+ len
, "temperatures:\t");
4175 for (i
= 0; i
< (n
- 1); i
++)
4176 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
4177 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
4179 len
+= sprintf(p
+ len
, "not supported\n");
4184 static struct ibm_struct thermal_driver_data
= {
4186 .read
= thermal_read
,
4187 .exit
= thermal_exit
,
4190 /*************************************************************************
4194 static u8 ecdump_regs
[256];
4196 static int ecdump_read(char *p
)
4202 len
+= sprintf(p
+ len
, "EC "
4203 " +00 +01 +02 +03 +04 +05 +06 +07"
4204 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
4205 for (i
= 0; i
< 256; i
+= 16) {
4206 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
4207 for (j
= 0; j
< 16; j
++) {
4208 if (!acpi_ec_read(i
+ j
, &v
))
4210 if (v
!= ecdump_regs
[i
+ j
])
4211 len
+= sprintf(p
+ len
, " *%02x", v
);
4213 len
+= sprintf(p
+ len
, " %02x", v
);
4214 ecdump_regs
[i
+ j
] = v
;
4216 len
+= sprintf(p
+ len
, "\n");
4221 /* These are way too dangerous to advertise openly... */
4223 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
4224 " (<offset> is 00-ff, <value> is 00-ff)\n");
4225 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
4226 " (<offset> is 00-ff, <value> is 0-255)\n");
4231 static int ecdump_write(char *buf
)
4236 while ((cmd
= next_cmd(&buf
))) {
4237 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
4239 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
4243 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
4244 if (!acpi_ec_write(i
, v
))
4253 static struct ibm_struct ecdump_driver_data
= {
4255 .read
= ecdump_read
,
4256 .write
= ecdump_write
,
4257 .flags
.experimental
= 1,
4260 /*************************************************************************
4261 * Backlight/brightness subdriver
4264 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
4266 static struct backlight_device
*ibm_backlight_device
;
4267 static int brightness_offset
= 0x31;
4268 static int brightness_mode
;
4269 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
4271 static struct mutex brightness_mutex
;
4274 * ThinkPads can read brightness from two places: EC 0x31, or
4275 * CMOS NVRAM byte 0x5E, bits 0-3.
4277 static int brightness_get(struct backlight_device
*bd
)
4279 u8 lec
= 0, lcmos
= 0, level
= 0;
4281 if (brightness_mode
& 1) {
4282 if (!acpi_ec_read(brightness_offset
, &lec
))
4284 lec
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
4287 if (brightness_mode
& 2) {
4288 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
4289 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
4290 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
4291 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
4295 if (brightness_mode
== 3 && lec
!= lcmos
) {
4297 "CMOS NVRAM (%u) and EC (%u) do not agree "
4298 "on display brightness level\n",
4299 (unsigned int) lcmos
,
4300 (unsigned int) lec
);
4307 /* May return EINTR which can always be mapped to ERESTARTSYS */
4308 static int brightness_set(int value
)
4310 int cmos_cmd
, inc
, i
, res
;
4313 if (value
> ((tp_features
.bright_16levels
)? 15 : 7))
4316 res
= mutex_lock_interruptible(&brightness_mutex
);
4320 current_value
= brightness_get(NULL
);
4321 if (current_value
< 0) {
4322 res
= current_value
;
4326 cmos_cmd
= value
> current_value
?
4327 TP_CMOS_BRIGHTNESS_UP
:
4328 TP_CMOS_BRIGHTNESS_DOWN
;
4329 inc
= (value
> current_value
)? 1 : -1;
4332 for (i
= current_value
; i
!= value
; i
+= inc
) {
4333 if ((brightness_mode
& 2) &&
4334 issue_thinkpad_cmos_command(cmos_cmd
)) {
4338 if ((brightness_mode
& 1) &&
4339 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
4346 mutex_unlock(&brightness_mutex
);
4350 /* sysfs backlight class ----------------------------------------------- */
4352 static int brightness_update_status(struct backlight_device
*bd
)
4354 /* it is the backlight class's job (caller) to handle
4355 * EINTR and other errors properly */
4356 return brightness_set(
4357 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
4358 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
4359 bd
->props
.brightness
: 0);
4362 static struct backlight_ops ibm_backlight_data
= {
4363 .get_brightness
= brightness_get
,
4364 .update_status
= brightness_update_status
,
4367 /* --------------------------------------------------------------------- */
4369 static int __init
tpacpi_query_bcll_levels(acpi_handle handle
)
4371 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
4372 union acpi_object
*obj
;
4375 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
4376 obj
= (union acpi_object
*)buffer
.pointer
;
4377 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
4378 printk(TPACPI_ERR
"Unknown BCLL data, "
4379 "please report this to %s\n", TPACPI_MAIL
);
4382 rc
= obj
->package
.count
;
4388 kfree(buffer
.pointer
);
4392 static acpi_status __init
brightness_find_bcll(acpi_handle handle
, u32 lvl
,
4393 void *context
, void **rv
)
4395 char name
[ACPI_PATH_SEGMENT_LENGTH
];
4396 struct acpi_buffer buffer
= { sizeof(name
), &name
};
4398 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
4399 !strncmp("BCLL", name
, sizeof(name
) - 1)) {
4400 if (tpacpi_query_bcll_levels(handle
) == 16) {
4402 return AE_CTRL_TERMINATE
;
4411 static int __init
brightness_check_levels(void)
4414 void *found_node
= NULL
;
4417 TPACPI_ACPIHANDLE_INIT(vid
);
4422 /* Search for a BCLL package with 16 levels */
4423 status
= acpi_walk_namespace(ACPI_TYPE_PACKAGE
, vid_handle
, 3,
4424 brightness_find_bcll
, NULL
,
4427 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
4430 static acpi_status __init
brightness_find_bcl(acpi_handle handle
, u32 lvl
,
4431 void *context
, void **rv
)
4433 char name
[ACPI_PATH_SEGMENT_LENGTH
];
4434 struct acpi_buffer buffer
= { sizeof(name
), &name
};
4436 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
4437 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
4439 return AE_CTRL_TERMINATE
;
4445 static int __init
brightness_check_std_acpi_support(void)
4448 void *found_node
= NULL
;
4451 TPACPI_ACPIHANDLE_INIT(vid
);
4456 /* Search for a _BCL method, but don't execute it */
4457 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
4458 brightness_find_bcl
, NULL
, &found_node
);
4460 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
4463 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
4467 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
4469 mutex_init(&brightness_mutex
);
4471 if (!brightness_enable
) {
4472 dbg_printk(TPACPI_DBG_INIT
,
4473 "brightness support disabled by "
4474 "module parameter\n");
4476 } else if (brightness_enable
> 1) {
4477 if (brightness_check_std_acpi_support()) {
4478 printk(TPACPI_NOTICE
4479 "standard ACPI backlight interface "
4480 "available, not loading native one...\n");
4485 if (!brightness_mode
) {
4486 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
4487 brightness_mode
= 2;
4489 brightness_mode
= 3;
4491 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
4495 if (brightness_mode
> 3)
4498 tp_features
.bright_16levels
=
4499 thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
&&
4500 brightness_check_levels();
4502 b
= brightness_get(NULL
);
4506 if (tp_features
.bright_16levels
)
4508 "detected a 16-level brightness capable ThinkPad\n");
4510 ibm_backlight_device
= backlight_device_register(
4511 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
4512 &ibm_backlight_data
);
4513 if (IS_ERR(ibm_backlight_device
)) {
4514 printk(TPACPI_ERR
"Could not register backlight device\n");
4515 return PTR_ERR(ibm_backlight_device
);
4517 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
4519 ibm_backlight_device
->props
.max_brightness
=
4520 (tp_features
.bright_16levels
)? 15 : 7;
4521 ibm_backlight_device
->props
.brightness
= b
;
4522 backlight_update_status(ibm_backlight_device
);
4527 static void brightness_exit(void)
4529 if (ibm_backlight_device
) {
4530 vdbg_printk(TPACPI_DBG_EXIT
,
4531 "calling backlight_device_unregister()\n");
4532 backlight_device_unregister(ibm_backlight_device
);
4533 ibm_backlight_device
= NULL
;
4537 static int brightness_read(char *p
)
4542 level
= brightness_get(NULL
);
4544 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4546 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
4547 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
4548 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4549 " (<level> is 0-%d)\n",
4550 (tp_features
.bright_16levels
) ? 15 : 7);
4556 static int brightness_write(char *buf
)
4561 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
4563 level
= brightness_get(NULL
);
4567 while ((cmd
= next_cmd(&buf
))) {
4568 if (strlencmp(cmd
, "up") == 0) {
4569 if (level
< max_level
)
4571 } else if (strlencmp(cmd
, "down") == 0) {
4574 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
4575 level
>= 0 && level
<= max_level
) {
4582 * Now we know what the final level should be, so we try to set it.
4583 * Doing it this way makes the syscall restartable in case of EINTR
4585 rc
= brightness_set(level
);
4586 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
4589 static struct ibm_struct brightness_driver_data
= {
4590 .name
= "brightness",
4591 .read
= brightness_read
,
4592 .write
= brightness_write
,
4593 .exit
= brightness_exit
,
4596 /*************************************************************************
4600 static int volume_offset
= 0x30;
4602 static int volume_read(char *p
)
4607 if (!acpi_ec_read(volume_offset
, &level
)) {
4608 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4610 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
4611 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
4612 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
4613 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4614 " (<level> is 0-15)\n");
4620 static int volume_write(char *buf
)
4622 int cmos_cmd
, inc
, i
;
4624 int new_level
, new_mute
;
4627 while ((cmd
= next_cmd(&buf
))) {
4628 if (!acpi_ec_read(volume_offset
, &level
))
4630 new_mute
= mute
= level
& 0x40;
4631 new_level
= level
= level
& 0xf;
4633 if (strlencmp(cmd
, "up") == 0) {
4637 new_level
= level
== 15 ? 15 : level
+ 1;
4638 } else if (strlencmp(cmd
, "down") == 0) {
4642 new_level
= level
== 0 ? 0 : level
- 1;
4643 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
4644 new_level
>= 0 && new_level
<= 15) {
4646 } else if (strlencmp(cmd
, "mute") == 0) {
4651 if (new_level
!= level
) {
4652 /* mute doesn't change */
4654 cmos_cmd
= (new_level
> level
) ?
4655 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
4656 inc
= new_level
> level
? 1 : -1;
4658 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
4659 !acpi_ec_write(volume_offset
, level
)))
4662 for (i
= level
; i
!= new_level
; i
+= inc
)
4663 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4664 !acpi_ec_write(volume_offset
, i
+ inc
))
4668 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
4669 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
4674 if (new_mute
!= mute
) {
4675 /* level doesn't change */
4677 cmos_cmd
= (new_mute
) ?
4678 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
4680 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4681 !acpi_ec_write(volume_offset
, level
+ new_mute
))
4689 static struct ibm_struct volume_driver_data
= {
4691 .read
= volume_read
,
4692 .write
= volume_write
,
4695 /*************************************************************************
4702 * TPACPI_FAN_RD_ACPI_GFAN:
4703 * ACPI GFAN method: returns fan level
4705 * see TPACPI_FAN_WR_ACPI_SFAN
4706 * EC 0x2f (HFSP) not available if GFAN exists
4708 * TPACPI_FAN_WR_ACPI_SFAN:
4709 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
4711 * EC 0x2f (HFSP) might be available *for reading*, but do not use
4714 * TPACPI_FAN_WR_TPEC:
4715 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
4716 * Supported on almost all ThinkPads
4718 * Fan speed changes of any sort (including those caused by the
4719 * disengaged mode) are usually done slowly by the firmware as the
4720 * maximum ammount of fan duty cycle change per second seems to be
4723 * Reading is not available if GFAN exists.
4724 * Writing is not available if SFAN exists.
4727 * 7 automatic mode engaged;
4728 * (default operation mode of the ThinkPad)
4729 * fan level is ignored in this mode.
4730 * 6 full speed mode (takes precedence over bit 7);
4731 * not available on all thinkpads. May disable
4732 * the tachometer while the fan controller ramps up
4733 * the speed (which can take up to a few *minutes*).
4734 * Speeds up fan to 100% duty-cycle, which is far above
4735 * the standard RPM levels. It is not impossible that
4736 * it could cause hardware damage.
4737 * 5-3 unused in some models. Extra bits for fan level
4738 * in others, but still useless as all values above
4739 * 7 map to the same speed as level 7 in these models.
4740 * 2-0 fan level (0..7 usually)
4742 * 0x07 = max (set when temperatures critical)
4743 * Some ThinkPads may have other levels, see
4744 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
4746 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
4747 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
4748 * does so, its initial value is meaningless (0x07).
4750 * For firmware bugs, refer to:
4751 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4755 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
4756 * Main fan tachometer reading (in RPM)
4758 * This register is present on all ThinkPads with a new-style EC, and
4759 * it is known not to be present on the A21m/e, and T22, as there is
4760 * something else in offset 0x84 according to the ACPI DSDT. Other
4761 * ThinkPads from this same time period (and earlier) probably lack the
4762 * tachometer as well.
4764 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
4765 * was never fixed by IBM to report the EC firmware version string
4766 * probably support the tachometer (like the early X models), so
4767 * detecting it is quite hard. We need more data to know for sure.
4769 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
4772 * FIRMWARE BUG: may go stale while the EC is switching to full speed
4775 * For firmware bugs, refer to:
4776 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4778 * TPACPI_FAN_WR_ACPI_FANS:
4779 * ThinkPad X31, X40, X41. Not available in the X60.
4781 * FANS ACPI handle: takes three arguments: low speed, medium speed,
4782 * high speed. ACPI DSDT seems to map these three speeds to levels
4783 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
4784 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
4786 * The speeds are stored on handles
4787 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
4789 * There are three default speed sets, acessible as handles:
4790 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
4792 * ACPI DSDT switches which set is in use depending on various
4795 * TPACPI_FAN_WR_TPEC is also available and should be used to
4796 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
4797 * but the ACPI tables just mention level 7.
4800 enum { /* Fan control constants */
4801 fan_status_offset
= 0x2f, /* EC register 0x2f */
4802 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
4803 * 0x84 must be read before 0x85 */
4805 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
4806 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
4808 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
4811 enum fan_status_access_mode
{
4812 TPACPI_FAN_NONE
= 0, /* No fan status or control */
4813 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
4814 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
4817 enum fan_control_access_mode
{
4818 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
4819 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
4820 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
4821 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
4824 enum fan_control_commands
{
4825 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
4826 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
4827 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
4828 * and also watchdog cmd */
4831 static int fan_control_allowed
;
4833 static enum fan_status_access_mode fan_status_access_mode
;
4834 static enum fan_control_access_mode fan_control_access_mode
;
4835 static enum fan_control_commands fan_control_commands
;
4837 static u8 fan_control_initial_status
;
4838 static u8 fan_control_desired_level
;
4839 static int fan_watchdog_maxinterval
;
4841 static struct mutex fan_mutex
;
4843 static void fan_watchdog_fire(struct work_struct
*ignored
);
4844 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
4846 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
4847 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
4848 "\\FSPD", /* 600e/x, 770e, 770x */
4850 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
4851 "JFNS", /* 770x-JL */
4855 * Call with fan_mutex held
4857 static void fan_update_desired_level(u8 status
)
4860 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4862 fan_control_desired_level
= 7;
4864 fan_control_desired_level
= status
;
4868 static int fan_get_status(u8
*status
)
4873 * Add TPACPI_FAN_RD_ACPI_FANS ? */
4875 switch (fan_status_access_mode
) {
4876 case TPACPI_FAN_RD_ACPI_GFAN
:
4877 /* 570, 600e/x, 770e, 770x */
4879 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
4887 case TPACPI_FAN_RD_TPEC
:
4888 /* all except 570, 600e/x, 770e, 770x */
4889 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
4904 static int fan_get_status_safe(u8
*status
)
4909 if (mutex_lock_interruptible(&fan_mutex
))
4910 return -ERESTARTSYS
;
4911 rc
= fan_get_status(&s
);
4913 fan_update_desired_level(s
);
4914 mutex_unlock(&fan_mutex
);
4922 static int fan_get_speed(unsigned int *speed
)
4926 switch (fan_status_access_mode
) {
4927 case TPACPI_FAN_RD_TPEC
:
4928 /* all except 570, 600e/x, 770e, 770x */
4929 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4930 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4934 *speed
= (hi
<< 8) | lo
;
4945 static int fan_set_level(int level
)
4947 if (!fan_control_allowed
)
4950 switch (fan_control_access_mode
) {
4951 case TPACPI_FAN_WR_ACPI_SFAN
:
4952 if (level
>= 0 && level
<= 7) {
4953 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4959 case TPACPI_FAN_WR_ACPI_FANS
:
4960 case TPACPI_FAN_WR_TPEC
:
4961 if ((level
!= TP_EC_FAN_AUTO
) &&
4962 (level
!= TP_EC_FAN_FULLSPEED
) &&
4963 ((level
< 0) || (level
> 7)))
4966 /* safety net should the EC not support AUTO
4967 * or FULLSPEED mode bits and just ignore them */
4968 if (level
& TP_EC_FAN_FULLSPEED
)
4969 level
|= 7; /* safety min speed 7 */
4970 else if (level
& TP_EC_FAN_AUTO
)
4971 level
|= 4; /* safety min speed 4 */
4973 if (!acpi_ec_write(fan_status_offset
, level
))
4976 tp_features
.fan_ctrl_status_undef
= 0;
4985 static int fan_set_level_safe(int level
)
4989 if (!fan_control_allowed
)
4992 if (mutex_lock_interruptible(&fan_mutex
))
4993 return -ERESTARTSYS
;
4995 if (level
== TPACPI_FAN_LAST_LEVEL
)
4996 level
= fan_control_desired_level
;
4998 rc
= fan_set_level(level
);
5000 fan_update_desired_level(level
);
5002 mutex_unlock(&fan_mutex
);
5006 static int fan_set_enable(void)
5011 if (!fan_control_allowed
)
5014 if (mutex_lock_interruptible(&fan_mutex
))
5015 return -ERESTARTSYS
;
5017 switch (fan_control_access_mode
) {
5018 case TPACPI_FAN_WR_ACPI_FANS
:
5019 case TPACPI_FAN_WR_TPEC
:
5020 rc
= fan_get_status(&s
);
5024 /* Don't go out of emergency fan mode */
5027 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
5030 if (!acpi_ec_write(fan_status_offset
, s
))
5033 tp_features
.fan_ctrl_status_undef
= 0;
5038 case TPACPI_FAN_WR_ACPI_SFAN
:
5039 rc
= fan_get_status(&s
);
5045 /* Set fan to at least level 4 */
5048 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
5058 mutex_unlock(&fan_mutex
);
5062 static int fan_set_disable(void)
5066 if (!fan_control_allowed
)
5069 if (mutex_lock_interruptible(&fan_mutex
))
5070 return -ERESTARTSYS
;
5073 switch (fan_control_access_mode
) {
5074 case TPACPI_FAN_WR_ACPI_FANS
:
5075 case TPACPI_FAN_WR_TPEC
:
5076 if (!acpi_ec_write(fan_status_offset
, 0x00))
5079 fan_control_desired_level
= 0;
5080 tp_features
.fan_ctrl_status_undef
= 0;
5084 case TPACPI_FAN_WR_ACPI_SFAN
:
5085 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
5088 fan_control_desired_level
= 0;
5096 mutex_unlock(&fan_mutex
);
5100 static int fan_set_speed(int speed
)
5104 if (!fan_control_allowed
)
5107 if (mutex_lock_interruptible(&fan_mutex
))
5108 return -ERESTARTSYS
;
5111 switch (fan_control_access_mode
) {
5112 case TPACPI_FAN_WR_ACPI_FANS
:
5113 if (speed
>= 0 && speed
<= 65535) {
5114 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
5115 speed
, speed
, speed
))
5125 mutex_unlock(&fan_mutex
);
5129 static void fan_watchdog_reset(void)
5131 static int fan_watchdog_active
;
5133 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
5136 if (fan_watchdog_active
)
5137 cancel_delayed_work(&fan_watchdog_task
);
5139 if (fan_watchdog_maxinterval
> 0 &&
5140 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
5141 fan_watchdog_active
= 1;
5142 if (!schedule_delayed_work(&fan_watchdog_task
,
5143 msecs_to_jiffies(fan_watchdog_maxinterval
5146 "failed to schedule the fan watchdog, "
5147 "watchdog will not trigger\n");
5150 fan_watchdog_active
= 0;
5153 static void fan_watchdog_fire(struct work_struct
*ignored
)
5157 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
5160 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
5161 rc
= fan_set_enable();
5163 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
5164 "will try again later...\n", -rc
);
5165 /* reschedule for later */
5166 fan_watchdog_reset();
5171 * SYSFS fan layout: hwmon compatible (device)
5174 * 0: "disengaged" mode
5176 * 2: native EC "auto" mode (recommended, hardware default)
5178 * pwm*: set speed in manual mode, ignored otherwise.
5179 * 0 is level 0; 255 is level 7. Intermediate points done with linear
5182 * fan*_input: tachometer reading, RPM
5185 * SYSFS fan layout: extensions
5187 * fan_watchdog (driver):
5188 * fan watchdog interval in seconds, 0 disables (default), max 120
5191 /* sysfs fan pwm1_enable ----------------------------------------------- */
5192 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
5193 struct device_attribute
*attr
,
5199 res
= fan_get_status_safe(&status
);
5203 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5204 if (status
!= fan_control_initial_status
) {
5205 tp_features
.fan_ctrl_status_undef
= 0;
5207 /* Return most likely status. In fact, it
5208 * might be the only possible status */
5209 status
= TP_EC_FAN_AUTO
;
5213 if (status
& TP_EC_FAN_FULLSPEED
) {
5215 } else if (status
& TP_EC_FAN_AUTO
) {
5220 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
5223 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
5224 struct device_attribute
*attr
,
5225 const char *buf
, size_t count
)
5230 if (parse_strtoul(buf
, 2, &t
))
5235 level
= TP_EC_FAN_FULLSPEED
;
5238 level
= TPACPI_FAN_LAST_LEVEL
;
5241 level
= TP_EC_FAN_AUTO
;
5244 /* reserved for software-controlled auto mode */
5250 res
= fan_set_level_safe(level
);
5256 fan_watchdog_reset();
5261 static struct device_attribute dev_attr_fan_pwm1_enable
=
5262 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
5263 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
5265 /* sysfs fan pwm1 ------------------------------------------------------ */
5266 static ssize_t
fan_pwm1_show(struct device
*dev
,
5267 struct device_attribute
*attr
,
5273 res
= fan_get_status_safe(&status
);
5277 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5278 if (status
!= fan_control_initial_status
) {
5279 tp_features
.fan_ctrl_status_undef
= 0;
5281 status
= TP_EC_FAN_AUTO
;
5286 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
5287 status
= fan_control_desired_level
;
5292 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
5295 static ssize_t
fan_pwm1_store(struct device
*dev
,
5296 struct device_attribute
*attr
,
5297 const char *buf
, size_t count
)
5301 u8 status
, newlevel
;
5303 if (parse_strtoul(buf
, 255, &s
))
5306 /* scale down from 0-255 to 0-7 */
5307 newlevel
= (s
>> 5) & 0x07;
5309 if (mutex_lock_interruptible(&fan_mutex
))
5310 return -ERESTARTSYS
;
5312 rc
= fan_get_status(&status
);
5313 if (!rc
&& (status
&
5314 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5315 rc
= fan_set_level(newlevel
);
5319 fan_update_desired_level(newlevel
);
5320 fan_watchdog_reset();
5324 mutex_unlock(&fan_mutex
);
5325 return (rc
)? rc
: count
;
5328 static struct device_attribute dev_attr_fan_pwm1
=
5329 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
5330 fan_pwm1_show
, fan_pwm1_store
);
5332 /* sysfs fan fan1_input ------------------------------------------------ */
5333 static ssize_t
fan_fan1_input_show(struct device
*dev
,
5334 struct device_attribute
*attr
,
5340 res
= fan_get_speed(&speed
);
5344 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
5347 static struct device_attribute dev_attr_fan_fan1_input
=
5348 __ATTR(fan1_input
, S_IRUGO
,
5349 fan_fan1_input_show
, NULL
);
5351 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
5352 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
5355 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
5358 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
5359 const char *buf
, size_t count
)
5363 if (parse_strtoul(buf
, 120, &t
))
5366 if (!fan_control_allowed
)
5369 fan_watchdog_maxinterval
= t
;
5370 fan_watchdog_reset();
5375 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
5376 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
5378 /* --------------------------------------------------------------------- */
5379 static struct attribute
*fan_attributes
[] = {
5380 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
5381 &dev_attr_fan_fan1_input
.attr
,
5385 static const struct attribute_group fan_attr_group
= {
5386 .attrs
= fan_attributes
,
5389 static int __init
fan_init(struct ibm_init_struct
*iibm
)
5393 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
5395 mutex_init(&fan_mutex
);
5396 fan_status_access_mode
= TPACPI_FAN_NONE
;
5397 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5398 fan_control_commands
= 0;
5399 fan_watchdog_maxinterval
= 0;
5400 tp_features
.fan_ctrl_status_undef
= 0;
5401 fan_control_desired_level
= 7;
5403 TPACPI_ACPIHANDLE_INIT(fans
);
5404 TPACPI_ACPIHANDLE_INIT(gfan
);
5405 TPACPI_ACPIHANDLE_INIT(sfan
);
5408 /* 570, 600e/x, 770e, 770x */
5409 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
5411 /* all other ThinkPads: note that even old-style
5412 * ThinkPad ECs supports the fan control register */
5413 if (likely(acpi_ec_read(fan_status_offset
,
5414 &fan_control_initial_status
))) {
5415 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
5417 /* In some ThinkPads, neither the EC nor the ACPI
5418 * DSDT initialize the fan status, and it ends up
5419 * being set to 0x07 when it *could* be either
5422 * Enable for TP-1Y (T43), TP-78 (R51e),
5423 * TP-76 (R52), TP-70 (T43, R52), which are known
5425 if (fan_control_initial_status
== 0x07) {
5426 switch (thinkpad_id
.ec_model
) {
5427 case 0x5931: /* TP-1Y */
5428 case 0x3837: /* TP-78 */
5429 case 0x3637: /* TP-76 */
5430 case 0x3037: /* TP-70 */
5431 printk(TPACPI_NOTICE
5432 "fan_init: initial fan status "
5433 "is unknown, assuming it is "
5435 tp_features
.fan_ctrl_status_undef
= 1;
5441 "ThinkPad ACPI EC access misbehaving, "
5442 "fan status and control unavailable\n");
5449 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
5450 fan_control_commands
|=
5451 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
5454 /* gfan without sfan means no fan control */
5455 /* all other models implement TP EC 0x2f control */
5459 fan_control_access_mode
=
5460 TPACPI_FAN_WR_ACPI_FANS
;
5461 fan_control_commands
|=
5462 TPACPI_FAN_CMD_SPEED
|
5463 TPACPI_FAN_CMD_LEVEL
|
5464 TPACPI_FAN_CMD_ENABLE
;
5466 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
5467 fan_control_commands
|=
5468 TPACPI_FAN_CMD_LEVEL
|
5469 TPACPI_FAN_CMD_ENABLE
;
5474 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
5475 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
5476 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
5477 fan_status_access_mode
, fan_control_access_mode
);
5479 /* fan control master switch */
5480 if (!fan_control_allowed
) {
5481 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5482 fan_control_commands
= 0;
5483 dbg_printk(TPACPI_DBG_INIT
,
5484 "fan control features disabled by parameter\n");
5487 /* update fan_control_desired_level */
5488 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
5489 fan_get_status_safe(NULL
);
5491 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
5492 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
5493 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5496 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
5497 &driver_attr_fan_watchdog
);
5505 static void fan_exit(void)
5507 vdbg_printk(TPACPI_DBG_EXIT
,
5508 "cancelling any pending fan watchdog tasks\n");
5510 /* FIXME: can we really do this unconditionally? */
5511 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
5512 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
5513 &driver_attr_fan_watchdog
);
5515 cancel_delayed_work(&fan_watchdog_task
);
5516 flush_scheduled_work();
5519 static int fan_read(char *p
)
5524 unsigned int speed
= 0;
5526 switch (fan_status_access_mode
) {
5527 case TPACPI_FAN_RD_ACPI_GFAN
:
5528 /* 570, 600e/x, 770e, 770x */
5529 rc
= fan_get_status_safe(&status
);
5533 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
5535 (status
!= 0) ? "enabled" : "disabled", status
);
5538 case TPACPI_FAN_RD_TPEC
:
5539 /* all except 570, 600e/x, 770e, 770x */
5540 rc
= fan_get_status_safe(&status
);
5544 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5545 if (status
!= fan_control_initial_status
)
5546 tp_features
.fan_ctrl_status_undef
= 0;
5548 /* Return most likely status. In fact, it
5549 * might be the only possible status */
5550 status
= TP_EC_FAN_AUTO
;
5553 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
5554 (status
!= 0) ? "enabled" : "disabled");
5556 rc
= fan_get_speed(&speed
);
5560 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
5562 if (status
& TP_EC_FAN_FULLSPEED
)
5563 /* Disengaged mode takes precedence */
5564 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
5565 else if (status
& TP_EC_FAN_AUTO
)
5566 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
5568 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
5571 case TPACPI_FAN_NONE
:
5573 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5576 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
5577 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
5579 switch (fan_control_access_mode
) {
5580 case TPACPI_FAN_WR_ACPI_SFAN
:
5581 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
5585 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
5586 "auto, disengaged, full-speed)\n");
5591 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
5592 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
5593 "commands:\twatchdog <timeout> (<timeout> "
5594 "is 0 (off), 1-120 (seconds))\n");
5596 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
5597 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
5598 " (<speed> is 0-65535)\n");
5603 static int fan_write_cmd_level(const char *cmd
, int *rc
)
5607 if (strlencmp(cmd
, "level auto") == 0)
5608 level
= TP_EC_FAN_AUTO
;
5609 else if ((strlencmp(cmd
, "level disengaged") == 0) |
5610 (strlencmp(cmd
, "level full-speed") == 0))
5611 level
= TP_EC_FAN_FULLSPEED
;
5612 else if (sscanf(cmd
, "level %d", &level
) != 1)
5615 *rc
= fan_set_level_safe(level
);
5617 printk(TPACPI_ERR
"level command accepted for unsupported "
5618 "access mode %d", fan_control_access_mode
);
5623 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
5625 if (strlencmp(cmd
, "enable") != 0)
5628 *rc
= fan_set_enable();
5630 printk(TPACPI_ERR
"enable command accepted for unsupported "
5631 "access mode %d", fan_control_access_mode
);
5636 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
5638 if (strlencmp(cmd
, "disable") != 0)
5641 *rc
= fan_set_disable();
5643 printk(TPACPI_ERR
"disable command accepted for unsupported "
5644 "access mode %d", fan_control_access_mode
);
5649 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
5654 * Support speed <low> <medium> <high> ? */
5656 if (sscanf(cmd
, "speed %d", &speed
) != 1)
5659 *rc
= fan_set_speed(speed
);
5661 printk(TPACPI_ERR
"speed command accepted for unsupported "
5662 "access mode %d", fan_control_access_mode
);
5667 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
5671 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
5674 if (interval
< 0 || interval
> 120)
5677 fan_watchdog_maxinterval
= interval
;
5682 static int fan_write(char *buf
)
5687 while (!rc
&& (cmd
= next_cmd(&buf
))) {
5688 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
5689 fan_write_cmd_level(cmd
, &rc
)) &&
5690 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
5691 (fan_write_cmd_enable(cmd
, &rc
) ||
5692 fan_write_cmd_disable(cmd
, &rc
) ||
5693 fan_write_cmd_watchdog(cmd
, &rc
))) &&
5694 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
5695 fan_write_cmd_speed(cmd
, &rc
))
5699 fan_watchdog_reset();
5705 static struct ibm_struct fan_driver_data
= {
5712 /****************************************************************************
5713 ****************************************************************************
5717 ****************************************************************************
5718 ****************************************************************************/
5720 /* sysfs name ---------------------------------------------------------- */
5721 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
5722 struct device_attribute
*attr
,
5725 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
5728 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
5729 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
5731 /* --------------------------------------------------------------------- */
5734 static struct proc_dir_entry
*proc_dir
;
5737 * Module and infrastructure proble, init and exit handling
5740 static int force_load
;
5742 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
5743 static const char * __init
str_supported(int is_supported
)
5745 static char text_unsupported
[] __initdata
= "not supported";
5747 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
5749 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
5751 static void ibm_exit(struct ibm_struct
*ibm
)
5753 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
5755 list_del_init(&ibm
->all_drivers
);
5757 if (ibm
->flags
.acpi_notify_installed
) {
5758 dbg_printk(TPACPI_DBG_EXIT
,
5759 "%s: acpi_remove_notify_handler\n", ibm
->name
);
5761 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
5763 dispatch_acpi_notify
);
5764 ibm
->flags
.acpi_notify_installed
= 0;
5765 ibm
->flags
.acpi_notify_installed
= 0;
5768 if (ibm
->flags
.proc_created
) {
5769 dbg_printk(TPACPI_DBG_EXIT
,
5770 "%s: remove_proc_entry\n", ibm
->name
);
5771 remove_proc_entry(ibm
->name
, proc_dir
);
5772 ibm
->flags
.proc_created
= 0;
5775 if (ibm
->flags
.acpi_driver_registered
) {
5776 dbg_printk(TPACPI_DBG_EXIT
,
5777 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
5779 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
5780 kfree(ibm
->acpi
->driver
);
5781 ibm
->acpi
->driver
= NULL
;
5782 ibm
->flags
.acpi_driver_registered
= 0;
5785 if (ibm
->flags
.init_called
&& ibm
->exit
) {
5787 ibm
->flags
.init_called
= 0;
5790 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
5793 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
5796 struct ibm_struct
*ibm
= iibm
->data
;
5797 struct proc_dir_entry
*entry
;
5799 BUG_ON(ibm
== NULL
);
5801 INIT_LIST_HEAD(&ibm
->all_drivers
);
5803 if (ibm
->flags
.experimental
&& !experimental
)
5806 dbg_printk(TPACPI_DBG_INIT
,
5807 "probing for %s\n", ibm
->name
);
5810 ret
= iibm
->init(iibm
);
5812 return 0; /* probe failed */
5816 ibm
->flags
.init_called
= 1;
5820 if (ibm
->acpi
->hid
) {
5821 ret
= register_tpacpi_subdriver(ibm
);
5826 if (ibm
->acpi
->notify
) {
5827 ret
= setup_acpi_notify(ibm
);
5828 if (ret
== -ENODEV
) {
5829 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
5839 dbg_printk(TPACPI_DBG_INIT
,
5840 "%s installed\n", ibm
->name
);
5843 entry
= create_proc_entry(ibm
->name
,
5844 S_IFREG
| S_IRUGO
| S_IWUSR
,
5847 printk(TPACPI_ERR
"unable to create proc entry %s\n",
5852 entry
->owner
= THIS_MODULE
;
5854 entry
->read_proc
= &dispatch_procfs_read
;
5856 entry
->write_proc
= &dispatch_procfs_write
;
5857 ibm
->flags
.proc_created
= 1;
5860 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
5865 dbg_printk(TPACPI_DBG_INIT
,
5866 "%s: at error exit path with result %d\n",
5870 return (ret
< 0)? ret
: 0;
5875 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
5877 const struct dmi_device
*dev
= NULL
;
5878 char ec_fw_string
[18];
5883 memset(tp
, 0, sizeof(*tp
));
5885 if (dmi_name_in_vendors("IBM"))
5886 tp
->vendor
= PCI_VENDOR_ID_IBM
;
5887 else if (dmi_name_in_vendors("LENOVO"))
5888 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
5892 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
5894 if (!tp
->bios_version_str
)
5896 tp
->bios_model
= tp
->bios_version_str
[0]
5897 | (tp
->bios_version_str
[1] << 8);
5900 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
5901 * X32 or newer, all Z series; Some models must have an
5902 * up-to-date BIOS or they will not be detected.
5904 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
5906 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
5907 if (sscanf(dev
->name
,
5908 "IBM ThinkPad Embedded Controller -[%17c",
5909 ec_fw_string
) == 1) {
5910 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
5911 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
5913 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
5914 tp
->ec_model
= ec_fw_string
[0]
5915 | (ec_fw_string
[1] << 8);
5920 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
5922 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
5923 kfree(tp
->model_str
);
5924 tp
->model_str
= NULL
;
5928 static int __init
probe_for_thinkpad(void)
5936 * Non-ancient models have better DMI tagging, but very old models
5939 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
5941 /* ec is required because many other handles are relative to it */
5942 TPACPI_ACPIHANDLE_INIT(ec
);
5946 "Not yet supported ThinkPad detected!\n");
5951 * Risks a regression on very old machines, but reduces potential
5952 * false positives a damn great deal
5955 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
5957 if (!is_thinkpad
&& !force_load
)
5964 /* Module init, exit, parameters */
5966 static struct ibm_init_struct ibms_init
[] __initdata
= {
5968 .init
= thinkpad_acpi_driver_init
,
5969 .data
= &thinkpad_acpi_driver_data
,
5972 .init
= hotkey_init
,
5973 .data
= &hotkey_driver_data
,
5976 .init
= bluetooth_init
,
5977 .data
= &bluetooth_driver_data
,
5981 .data
= &wan_driver_data
,
5983 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
5985 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
5986 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
5989 .data
= &video_driver_data
,
5991 <<<<<<< HEAD
:drivers
/misc
/thinkpad_acpi
.c
5994 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
5997 .data
= &light_driver_data
,
5999 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6002 .data
= &dock_driver_data
[0],
6006 .data
= &dock_driver_data
[1],
6009 #ifdef CONFIG_THINKPAD_ACPI_BAY
6012 .data
= &bay_driver_data
,
6017 .data
= &cmos_driver_data
,
6021 .data
= &led_driver_data
,
6025 .data
= &beep_driver_data
,
6028 .init
= thermal_init
,
6029 .data
= &thermal_driver_data
,
6032 .data
= &ecdump_driver_data
,
6035 .init
= brightness_init
,
6036 .data
= &brightness_driver_data
,
6039 .data
= &volume_driver_data
,
6043 .data
= &fan_driver_data
,
6047 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
6050 struct ibm_struct
*ibm
;
6052 if (!kp
|| !kp
->name
|| !val
)
6055 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6056 ibm
= ibms_init
[i
].data
;
6057 WARN_ON(ibm
== NULL
);
6059 if (!ibm
|| !ibm
->name
)
6062 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
6063 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
6065 strcpy(ibms_init
[i
].param
, val
);
6066 strcat(ibms_init
[i
].param
, ",");
6074 module_param(experimental
, int, 0);
6075 MODULE_PARM_DESC(experimental
,
6076 "Enables experimental features when non-zero");
6078 module_param_named(debug
, dbg_level
, uint
, 0);
6079 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
6081 module_param(force_load
, bool, 0);
6082 MODULE_PARM_DESC(force_load
,
6083 "Attempts to load the driver even on a "
6084 "mis-identified ThinkPad when true");
6086 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
6087 MODULE_PARM_DESC(fan_control
,
6088 "Enables setting fan parameters features when true");
6090 module_param_named(brightness_mode
, brightness_mode
, int, 0);
6091 MODULE_PARM_DESC(brightness_mode
,
6092 "Selects brightness control strategy: "
6093 "0=auto, 1=EC, 2=CMOS, 3=both");
6095 module_param(brightness_enable
, uint
, 0);
6096 MODULE_PARM_DESC(brightness_enable
,
6097 "Enables backlight control when 1, disables when 0");
6099 module_param(hotkey_report_mode
, uint
, 0);
6100 MODULE_PARM_DESC(hotkey_report_mode
,
6101 "used for backwards compatibility with userspace, "
6102 "see documentation");
6104 #define TPACPI_PARAM(feature) \
6105 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
6106 <<<<<<< HEAD:drivers/misc/thinkpad_acpi.c
6107 MODULE_PARM_DESC(feature
, "Simulates thinkpad-aci procfs command " \
6109 MODULE_PARM_DESC(feature
, "Simulates thinkpad-acpi procfs command " \
6110 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/misc
/thinkpad_acpi
.c
6111 "at module load, see documentation")
6113 TPACPI_PARAM(hotkey
);
6114 TPACPI_PARAM(bluetooth
);
6115 TPACPI_PARAM(video
);
6116 TPACPI_PARAM(light
);
6117 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6120 #ifdef CONFIG_THINKPAD_ACPI_BAY
6122 #endif /* CONFIG_THINKPAD_ACPI_BAY */
6126 TPACPI_PARAM(ecdump
);
6127 TPACPI_PARAM(brightness
);
6128 TPACPI_PARAM(volume
);
6131 static void thinkpad_acpi_module_exit(void)
6133 struct ibm_struct
*ibm
, *itmp
;
6135 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
6137 list_for_each_entry_safe_reverse(ibm
, itmp
,
6138 &tpacpi_all_drivers
,
6143 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
6145 if (tpacpi_inputdev
) {
6146 if (tp_features
.input_device_registered
)
6147 input_unregister_device(tpacpi_inputdev
);
6149 input_free_device(tpacpi_inputdev
);
6153 hwmon_device_unregister(tpacpi_hwmon
);
6155 if (tp_features
.sensors_pdev_attrs_registered
)
6156 device_remove_file(&tpacpi_sensors_pdev
->dev
,
6157 &dev_attr_thinkpad_acpi_pdev_name
);
6158 if (tpacpi_sensors_pdev
)
6159 platform_device_unregister(tpacpi_sensors_pdev
);
6161 platform_device_unregister(tpacpi_pdev
);
6163 if (tp_features
.sensors_pdrv_attrs_registered
)
6164 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
6165 if (tp_features
.platform_drv_attrs_registered
)
6166 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
6168 if (tp_features
.sensors_pdrv_registered
)
6169 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
6171 if (tp_features
.platform_drv_registered
)
6172 platform_driver_unregister(&tpacpi_pdriver
);
6175 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
6177 kfree(thinkpad_id
.bios_version_str
);
6178 kfree(thinkpad_id
.ec_version_str
);
6179 kfree(thinkpad_id
.model_str
);
6183 static int __init
thinkpad_acpi_module_init(void)
6187 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
6189 /* Parameter checking */
6190 if (hotkey_report_mode
> 2)
6193 /* Driver-level probe */
6195 get_thinkpad_model_data(&thinkpad_id
);
6196 ret
= probe_for_thinkpad();
6198 thinkpad_acpi_module_exit();
6202 /* Driver initialization */
6204 TPACPI_ACPIHANDLE_INIT(ecrd
);
6205 TPACPI_ACPIHANDLE_INIT(ecwr
);
6207 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
6210 "unable to create proc dir " TPACPI_PROC_DIR
);
6211 thinkpad_acpi_module_exit();
6214 proc_dir
->owner
= THIS_MODULE
;
6216 ret
= platform_driver_register(&tpacpi_pdriver
);
6219 "unable to register main platform driver\n");
6220 thinkpad_acpi_module_exit();
6223 tp_features
.platform_drv_registered
= 1;
6225 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
6228 "unable to register hwmon platform driver\n");
6229 thinkpad_acpi_module_exit();
6232 tp_features
.sensors_pdrv_registered
= 1;
6234 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
6236 tp_features
.platform_drv_attrs_registered
= 1;
6237 ret
= tpacpi_create_driver_attributes(
6238 &tpacpi_hwmon_pdriver
.driver
);
6242 "unable to create sysfs driver attributes\n");
6243 thinkpad_acpi_module_exit();
6246 tp_features
.sensors_pdrv_attrs_registered
= 1;
6249 /* Device initialization */
6250 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
6252 if (IS_ERR(tpacpi_pdev
)) {
6253 ret
= PTR_ERR(tpacpi_pdev
);
6255 printk(TPACPI_ERR
"unable to register platform device\n");
6256 thinkpad_acpi_module_exit();
6259 tpacpi_sensors_pdev
= platform_device_register_simple(
6260 TPACPI_HWMON_DRVR_NAME
,
6262 if (IS_ERR(tpacpi_sensors_pdev
)) {
6263 ret
= PTR_ERR(tpacpi_sensors_pdev
);
6264 tpacpi_sensors_pdev
= NULL
;
6266 "unable to register hwmon platform device\n");
6267 thinkpad_acpi_module_exit();
6270 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
6271 &dev_attr_thinkpad_acpi_pdev_name
);
6274 "unable to create sysfs hwmon device attributes\n");
6275 thinkpad_acpi_module_exit();
6278 tp_features
.sensors_pdev_attrs_registered
= 1;
6279 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
6280 if (IS_ERR(tpacpi_hwmon
)) {
6281 ret
= PTR_ERR(tpacpi_hwmon
);
6282 tpacpi_hwmon
= NULL
;
6283 printk(TPACPI_ERR
"unable to register hwmon device\n");
6284 thinkpad_acpi_module_exit();
6287 mutex_init(&tpacpi_inputdev_send_mutex
);
6288 tpacpi_inputdev
= input_allocate_device();
6289 if (!tpacpi_inputdev
) {
6290 printk(TPACPI_ERR
"unable to allocate input device\n");
6291 thinkpad_acpi_module_exit();
6294 /* Prepare input device, but don't register */
6295 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
6296 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
6297 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
6298 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
6299 thinkpad_id
.vendor
:
6301 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
6302 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
6304 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6305 ret
= ibm_init(&ibms_init
[i
]);
6306 if (ret
>= 0 && *ibms_init
[i
].param
)
6307 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
6309 thinkpad_acpi_module_exit();
6313 ret
= input_register_device(tpacpi_inputdev
);
6315 printk(TPACPI_ERR
"unable to register input device\n");
6316 thinkpad_acpi_module_exit();
6319 tp_features
.input_device_registered
= 1;
6322 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
6326 /* Please remove this in year 2009 */
6327 MODULE_ALIAS("ibm_acpi");
6330 * DMI matching for module autoloading
6332 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6333 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
6335 * Only models listed in thinkwiki will be supported, so add yours
6336 * if it is not there yet.
6338 #define IBM_BIOS_MODULE_ALIAS(__type) \
6339 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
6341 /* Non-ancient thinkpads */
6342 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
6343 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
6345 /* Ancient thinkpad BIOSes have to be identified by
6346 * BIOS type or model number, and there are far less
6347 * BIOS types than model numbers... */
6348 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
6349 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
6350 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
6352 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
6353 MODULE_DESCRIPTION(TPACPI_DESC
);
6354 MODULE_VERSION(TPACPI_VERSION
);
6355 MODULE_LICENSE("GPL");
6357 module_init(thinkpad_acpi_module_init
);
6358 module_exit(thinkpad_acpi_module_exit
);