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.21"
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 <linux/leds.h>
71 #include <linux/rfkill.h>
72 #include <asm/uaccess.h>
74 #include <linux/dmi.h>
75 #include <linux/jiffies.h>
76 #include <linux/workqueue.h>
78 #include <acpi/acpi_drivers.h>
80 #include <linux/pci_ids.h>
83 /* ThinkPad CMOS commands */
84 #define TP_CMOS_VOLUME_DOWN 0
85 #define TP_CMOS_VOLUME_UP 1
86 #define TP_CMOS_VOLUME_MUTE 2
87 #define TP_CMOS_BRIGHTNESS_UP 4
88 #define TP_CMOS_BRIGHTNESS_DOWN 5
89 #define TP_CMOS_THINKLIGHT_ON 12
90 #define TP_CMOS_THINKLIGHT_OFF 13
94 TP_NVRAM_ADDR_HK2
= 0x57,
95 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
96 TP_NVRAM_ADDR_VIDEO
= 0x59,
97 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
98 TP_NVRAM_ADDR_MIXER
= 0x60,
101 /* NVRAM bit masks */
103 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
104 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
105 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
106 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
107 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
108 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
109 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
110 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
111 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
112 TP_NVRAM_MASK_MUTE
= 0x40,
113 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
114 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
115 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
119 #define TPACPI_ACPI_HKEY_HID "IBM0068"
122 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
123 #define TPACPI_HKEY_INPUT_VERSION 0x4101
125 /* ACPI \WGSV commands */
127 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
128 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
129 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
130 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
133 /* TP_ACPI_WGSV_GET_STATE bits */
135 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
136 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
137 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
138 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
139 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
140 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
141 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
142 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
143 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
144 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
147 /****************************************************************************
151 #define TPACPI_NAME "thinkpad"
152 #define TPACPI_DESC "ThinkPad ACPI Extras"
153 #define TPACPI_FILE TPACPI_NAME "_acpi"
154 #define TPACPI_URL "http://ibm-acpi.sf.net/"
155 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
157 #define TPACPI_PROC_DIR "ibm"
158 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
159 #define TPACPI_DRVR_NAME TPACPI_FILE
160 #define TPACPI_DRVR_SHORTNAME "tpacpi"
161 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
163 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
164 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
166 #define TPACPI_MAX_ACPI_ARGS 3
168 /* rfkill switches */
170 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
171 TPACPI_RFK_WWAN_SW_ID
,
175 #define TPACPI_LOG TPACPI_FILE ": "
176 #define TPACPI_ERR KERN_ERR TPACPI_LOG
177 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
178 #define TPACPI_INFO KERN_INFO TPACPI_LOG
179 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
181 #define TPACPI_DBG_ALL 0xffff
182 #define TPACPI_DBG_INIT 0x0001
183 #define TPACPI_DBG_EXIT 0x0002
184 #define dbg_printk(a_dbg_level, format, arg...) \
185 do { if (dbg_level & a_dbg_level) \
186 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
188 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
189 #define vdbg_printk(a_dbg_level, format, arg...) \
190 dbg_printk(a_dbg_level, format, ## arg)
191 static const char *str_supported(int is_supported
);
193 #define vdbg_printk(a_dbg_level, format, arg...)
196 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
197 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
198 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
201 /****************************************************************************
202 * Driver-wide structs and misc. variables
207 struct tp_acpi_drv_struct
{
208 const struct acpi_device_id
*hid
;
209 struct acpi_driver
*driver
;
211 void (*notify
) (struct ibm_struct
*, u32
);
214 struct acpi_device
*device
;
220 int (*read
) (char *);
221 int (*write
) (char *);
223 void (*resume
) (void);
224 void (*suspend
) (pm_message_t state
);
226 struct list_head all_drivers
;
228 struct tp_acpi_drv_struct
*acpi
;
231 u8 acpi_driver_registered
:1;
232 u8 acpi_notify_installed
:1;
239 struct ibm_init_struct
{
242 int (*init
) (struct ibm_init_struct
*);
243 struct ibm_struct
*data
;
247 #ifdef CONFIG_THINKPAD_ACPI_BAY
260 u32 bright_16levels
:1;
261 u32 bright_acpimode
:1;
263 u32 fan_ctrl_status_undef
:1;
264 u32 input_device_registered
:1;
265 u32 platform_drv_registered
:1;
266 u32 platform_drv_attrs_registered
:1;
267 u32 sensors_pdrv_registered
:1;
268 u32 sensors_pdrv_attrs_registered
:1;
269 u32 sensors_pdev_attrs_registered
:1;
270 u32 hotkey_poll_active
:1;
274 u16 hotkey_mask_ff
:1;
275 u16 bright_cmos_ec_unsync
:1;
278 struct thinkpad_id_data
{
279 unsigned int vendor
; /* ThinkPad vendor:
280 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
282 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
283 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
285 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
288 char *model_str
; /* ThinkPad T43 */
289 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
291 static struct thinkpad_id_data thinkpad_id
;
294 TPACPI_LIFE_INIT
= 0,
299 static int experimental
;
300 static u32 dbg_level
;
302 static struct workqueue_struct
*tpacpi_wq
;
304 /* Special LED class that can defer work */
305 struct tpacpi_led_classdev
{
306 struct led_classdev led_classdev
;
307 struct work_struct work
;
308 enum led_brightness new_brightness
;
312 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
313 static int dbg_wlswemul
;
314 static int tpacpi_wlsw_emulstate
;
315 static int dbg_bluetoothemul
;
316 static int tpacpi_bluetooth_emulstate
;
317 static int dbg_wwanemul
;
318 static int tpacpi_wwan_emulstate
;
322 /****************************************************************************
323 ****************************************************************************
325 * ACPI Helpers and device model
327 ****************************************************************************
328 ****************************************************************************/
330 /*************************************************************************
334 static acpi_handle root_handle
;
336 #define TPACPI_HANDLE(object, parent, paths...) \
337 static acpi_handle object##_handle; \
338 static acpi_handle *object##_parent = &parent##_handle; \
339 static char *object##_path; \
340 static char *object##_paths[] = { paths }
342 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
343 "\\_SB.PCI.ISA.EC", /* 570 */
344 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
345 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
346 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
347 "\\_SB.PCI0.ICH3.EC0", /* R31 */
348 "\\_SB.PCI0.LPC.EC", /* all others */
351 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
352 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
354 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
356 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
357 "\\CMS", /* R40, R40e */
360 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
361 "^HKEY", /* R30, R31 */
362 "HKEY", /* all others */
365 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
366 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
367 "\\_SB.PCI0.VID0", /* 770e */
368 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
369 "\\_SB.PCI0.AGP.VID", /* all others */
373 /*************************************************************************
377 static int acpi_evalf(acpi_handle handle
,
378 void *res
, char *method
, char *fmt
, ...)
381 struct acpi_object_list params
;
382 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
383 struct acpi_buffer result
, *resultp
;
384 union acpi_object out_obj
;
392 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
405 params
.pointer
= &in_objs
[0];
412 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
413 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
415 /* add more types as needed */
417 printk(TPACPI_ERR
"acpi_evalf() called "
418 "with invalid format character '%c'\n", c
);
424 if (res_type
!= 'v') {
425 result
.length
= sizeof(out_obj
);
426 result
.pointer
= &out_obj
;
431 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
436 *(int *)res
= out_obj
.integer
.value
;
437 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
440 success
= status
== AE_OK
;
442 /* add more types as needed */
444 printk(TPACPI_ERR
"acpi_evalf() called "
445 "with invalid format character '%c'\n", res_type
);
449 if (!success
&& !quiet
)
450 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
451 method
, fmt0
, status
);
456 static int acpi_ec_read(int i
, u8
*p
)
461 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
465 if (ec_read(i
, p
) < 0)
472 static int acpi_ec_write(int i
, u8 v
)
475 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
478 if (ec_write(i
, v
) < 0)
485 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
486 static int _sta(acpi_handle handle
)
490 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
497 static int issue_thinkpad_cmos_command(int cmos_cmd
)
502 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
508 /*************************************************************************
512 #define TPACPI_ACPIHANDLE_INIT(object) \
513 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
514 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
516 static void drv_acpi_handle_init(char *name
,
517 acpi_handle
*handle
, acpi_handle parent
,
518 char **paths
, int num_paths
, char **path
)
523 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
526 for (i
= 0; i
< num_paths
; i
++) {
527 status
= acpi_get_handle(parent
, paths
[i
], handle
);
528 if (ACPI_SUCCESS(status
)) {
530 dbg_printk(TPACPI_DBG_INIT
,
531 "Found ACPI handle %s for %s\n",
537 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
542 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
544 struct ibm_struct
*ibm
= data
;
546 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
549 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
552 ibm
->acpi
->notify(ibm
, event
);
555 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
562 if (!*ibm
->acpi
->handle
)
565 vdbg_printk(TPACPI_DBG_INIT
,
566 "setting up ACPI notify for %s\n", ibm
->name
);
568 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
570 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
575 ibm
->acpi
->device
->driver_data
= ibm
;
576 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
577 TPACPI_ACPI_EVENT_PREFIX
,
580 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
581 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
582 if (ACPI_FAILURE(status
)) {
583 if (status
== AE_ALREADY_EXISTS
) {
585 "another device driver is already "
586 "handling %s events\n", ibm
->name
);
589 "acpi_install_notify_handler(%s) failed: %d\n",
594 ibm
->flags
.acpi_notify_installed
= 1;
598 static int __init
tpacpi_device_add(struct acpi_device
*device
)
603 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
607 dbg_printk(TPACPI_DBG_INIT
,
608 "registering %s as an ACPI driver\n", ibm
->name
);
612 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
613 if (!ibm
->acpi
->driver
) {
615 "failed to allocate memory for ibm->acpi->driver\n");
619 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
620 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
622 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
624 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
626 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
628 kfree(ibm
->acpi
->driver
);
629 ibm
->acpi
->driver
= NULL
;
631 ibm
->flags
.acpi_driver_registered
= 1;
637 /****************************************************************************
638 ****************************************************************************
642 ****************************************************************************
643 ****************************************************************************/
645 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
646 int count
, int *eof
, void *data
)
648 struct ibm_struct
*ibm
= data
;
651 if (!ibm
|| !ibm
->read
)
654 len
= ibm
->read(page
);
658 if (len
<= off
+ count
)
670 static int dispatch_procfs_write(struct file
*file
,
671 const char __user
*userbuf
,
672 unsigned long count
, void *data
)
674 struct ibm_struct
*ibm
= data
;
678 if (!ibm
|| !ibm
->write
)
681 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
685 if (copy_from_user(kernbuf
, userbuf
, count
)) {
691 strcat(kernbuf
, ",");
692 ret
= ibm
->write(kernbuf
);
701 static char *next_cmd(char **cmds
)
706 while ((end
= strchr(start
, ',')) && end
== start
)
718 /****************************************************************************
719 ****************************************************************************
721 * Device model: input, hwmon and platform
723 ****************************************************************************
724 ****************************************************************************/
726 static struct platform_device
*tpacpi_pdev
;
727 static struct platform_device
*tpacpi_sensors_pdev
;
728 static struct device
*tpacpi_hwmon
;
729 static struct input_dev
*tpacpi_inputdev
;
730 static struct mutex tpacpi_inputdev_send_mutex
;
731 static LIST_HEAD(tpacpi_all_drivers
);
733 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
736 struct ibm_struct
*ibm
, *itmp
;
738 list_for_each_entry_safe(ibm
, itmp
,
742 (ibm
->suspend
)(state
);
748 static int tpacpi_resume_handler(struct platform_device
*pdev
)
750 struct ibm_struct
*ibm
, *itmp
;
752 list_for_each_entry_safe(ibm
, itmp
,
762 static struct platform_driver tpacpi_pdriver
= {
764 .name
= TPACPI_DRVR_NAME
,
765 .owner
= THIS_MODULE
,
767 .suspend
= tpacpi_suspend_handler
,
768 .resume
= tpacpi_resume_handler
,
771 static struct platform_driver tpacpi_hwmon_pdriver
= {
773 .name
= TPACPI_HWMON_DRVR_NAME
,
774 .owner
= THIS_MODULE
,
778 /*************************************************************************
779 * sysfs support helpers
782 struct attribute_set
{
783 unsigned int members
, max_members
;
784 struct attribute_group group
;
787 struct attribute_set_obj
{
788 struct attribute_set s
;
790 } __attribute__((packed
));
792 static struct attribute_set
*create_attr_set(unsigned int max_members
,
795 struct attribute_set_obj
*sobj
;
797 if (max_members
== 0)
800 /* Allocates space for implicit NULL at the end too */
801 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
802 max_members
* sizeof(struct attribute
*),
806 sobj
->s
.max_members
= max_members
;
807 sobj
->s
.group
.attrs
= &sobj
->a
;
808 sobj
->s
.group
.name
= name
;
813 #define destroy_attr_set(_set) \
816 /* not multi-threaded safe, use it in a single thread per set */
817 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
822 if (s
->members
>= s
->max_members
)
825 s
->group
.attrs
[s
->members
] = attr
;
831 static int add_many_to_attr_set(struct attribute_set
*s
,
832 struct attribute
**attr
,
837 for (i
= 0; i
< count
; i
++) {
838 res
= add_to_attr_set(s
, attr
[i
]);
846 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
848 sysfs_remove_group(kobj
, &s
->group
);
852 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
853 sysfs_create_group(_kobj, &_attr_set->group)
855 static int parse_strtoul(const char *buf
,
856 unsigned long max
, unsigned long *value
)
860 while (*buf
&& isspace(*buf
))
862 *value
= simple_strtoul(buf
, &endp
, 0);
863 while (*endp
&& isspace(*endp
))
865 if (*endp
|| *value
> max
)
871 static void tpacpi_disable_brightness_delay(void)
873 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
875 "ACPI backlight control delay disabled\n");
878 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
880 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
881 union acpi_object
*obj
;
884 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
885 obj
= (union acpi_object
*)buffer
.pointer
;
886 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
887 printk(TPACPI_ERR
"Unknown _BCL data, "
888 "please report this to %s\n", TPACPI_MAIL
);
891 rc
= obj
->package
.count
;
897 kfree(buffer
.pointer
);
901 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
902 u32 lvl
, void *context
, void **rv
)
904 char name
[ACPI_PATH_SEGMENT_LENGTH
];
905 struct acpi_buffer buffer
= { sizeof(name
), &name
};
907 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
908 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
910 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
911 return AE_CTRL_TERMINATE
;
918 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
920 static int __init
tpacpi_check_std_acpi_brightness_support(void)
924 void *bcl_ptr
= &bcl_levels
;
927 TPACPI_ACPIHANDLE_INIT(vid
);
933 * Search for a _BCL method, and execute it. This is safe on all
934 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
935 * BIOS in ACPI backlight control mode. We do NOT have to care
936 * about calling the _BCL method in an enabled video device, any
937 * will do for our purposes.
940 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
941 tpacpi_acpi_walk_find_bcl
, NULL
,
944 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
945 tp_features
.bright_acpimode
= 1;
946 return (bcl_levels
- 2);
952 static int __init
tpacpi_new_rfkill(const unsigned int id
,
954 const enum rfkill_type rfktype
,
956 int (*toggle_radio
)(void *, enum rfkill_state
),
957 int (*get_state
)(void *, enum rfkill_state
*))
960 enum rfkill_state initial_state
;
962 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
965 "failed to allocate memory for rfkill class\n");
970 (*rfk
)->get_state
= get_state
;
971 (*rfk
)->toggle_radio
= toggle_radio
;
973 if (!get_state(NULL
, &initial_state
))
974 (*rfk
)->state
= initial_state
;
976 res
= rfkill_register(*rfk
);
979 "failed to register %s rfkill switch: %d\n",
989 /*************************************************************************
990 * thinkpad-acpi driver attributes
993 /* interface_version --------------------------------------------------- */
994 static ssize_t
tpacpi_driver_interface_version_show(
995 struct device_driver
*drv
,
998 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1001 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1002 tpacpi_driver_interface_version_show
, NULL
);
1004 /* debug_level --------------------------------------------------------- */
1005 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1008 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1011 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1012 const char *buf
, size_t count
)
1016 if (parse_strtoul(buf
, 0xffff, &t
))
1024 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1025 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1027 /* version ------------------------------------------------------------- */
1028 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1031 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1032 TPACPI_DESC
, TPACPI_VERSION
);
1035 static DRIVER_ATTR(version
, S_IRUGO
,
1036 tpacpi_driver_version_show
, NULL
);
1038 /* --------------------------------------------------------------------- */
1040 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1042 static void tpacpi_send_radiosw_update(void);
1044 /* wlsw_emulstate ------------------------------------------------------ */
1045 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1048 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1051 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1052 const char *buf
, size_t count
)
1056 if (parse_strtoul(buf
, 1, &t
))
1059 if (tpacpi_wlsw_emulstate
!= t
) {
1060 tpacpi_wlsw_emulstate
= !!t
;
1061 tpacpi_send_radiosw_update();
1063 tpacpi_wlsw_emulstate
= !!t
;
1068 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1069 tpacpi_driver_wlsw_emulstate_show
,
1070 tpacpi_driver_wlsw_emulstate_store
);
1072 /* bluetooth_emulstate ------------------------------------------------- */
1073 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1074 struct device_driver
*drv
,
1077 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1080 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1081 struct device_driver
*drv
,
1082 const char *buf
, size_t count
)
1086 if (parse_strtoul(buf
, 1, &t
))
1089 tpacpi_bluetooth_emulstate
= !!t
;
1094 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1095 tpacpi_driver_bluetooth_emulstate_show
,
1096 tpacpi_driver_bluetooth_emulstate_store
);
1098 /* wwan_emulstate ------------------------------------------------- */
1099 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1100 struct device_driver
*drv
,
1103 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1106 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1107 struct device_driver
*drv
,
1108 const char *buf
, size_t count
)
1112 if (parse_strtoul(buf
, 1, &t
))
1115 tpacpi_wwan_emulstate
= !!t
;
1120 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1121 tpacpi_driver_wwan_emulstate_show
,
1122 tpacpi_driver_wwan_emulstate_store
);
1126 /* --------------------------------------------------------------------- */
1128 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1129 &driver_attr_debug_level
, &driver_attr_version
,
1130 &driver_attr_interface_version
,
1133 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1139 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1140 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1144 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1145 if (!res
&& dbg_wlswemul
)
1146 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1147 if (!res
&& dbg_bluetoothemul
)
1148 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1149 if (!res
&& dbg_wwanemul
)
1150 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1156 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1160 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1161 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1163 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1164 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1165 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1166 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1170 /****************************************************************************
1171 ****************************************************************************
1175 ****************************************************************************
1176 ****************************************************************************/
1178 /*************************************************************************
1179 * thinkpad-acpi init subdriver
1182 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1184 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1185 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1187 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1188 (thinkpad_id
.bios_version_str
) ?
1189 thinkpad_id
.bios_version_str
: "unknown",
1190 (thinkpad_id
.ec_version_str
) ?
1191 thinkpad_id
.ec_version_str
: "unknown");
1193 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1194 printk(TPACPI_INFO
"%s %s, model %s\n",
1195 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1196 "IBM" : ((thinkpad_id
.vendor
==
1197 PCI_VENDOR_ID_LENOVO
) ?
1198 "Lenovo" : "Unknown vendor"),
1199 thinkpad_id
.model_str
,
1200 (thinkpad_id
.nummodel_str
) ?
1201 thinkpad_id
.nummodel_str
: "unknown");
1206 static int thinkpad_acpi_driver_read(char *p
)
1210 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1211 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1216 static struct ibm_struct thinkpad_acpi_driver_data
= {
1218 .read
= thinkpad_acpi_driver_read
,
1221 /*************************************************************************
1225 enum { /* hot key scan codes (derived from ACPI DSDT) */
1226 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1227 TP_ACPI_HOTKEYSCAN_FNF2
,
1228 TP_ACPI_HOTKEYSCAN_FNF3
,
1229 TP_ACPI_HOTKEYSCAN_FNF4
,
1230 TP_ACPI_HOTKEYSCAN_FNF5
,
1231 TP_ACPI_HOTKEYSCAN_FNF6
,
1232 TP_ACPI_HOTKEYSCAN_FNF7
,
1233 TP_ACPI_HOTKEYSCAN_FNF8
,
1234 TP_ACPI_HOTKEYSCAN_FNF9
,
1235 TP_ACPI_HOTKEYSCAN_FNF10
,
1236 TP_ACPI_HOTKEYSCAN_FNF11
,
1237 TP_ACPI_HOTKEYSCAN_FNF12
,
1238 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1239 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1240 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1241 TP_ACPI_HOTKEYSCAN_FNHOME
,
1242 TP_ACPI_HOTKEYSCAN_FNEND
,
1243 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1244 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1245 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1246 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1247 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1248 TP_ACPI_HOTKEYSCAN_MUTE
,
1249 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1252 enum { /* Keys available through NVRAM polling */
1253 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1254 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1257 enum { /* Positions of some of the keys in hotkey masks */
1258 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1259 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1260 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1261 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1262 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1263 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1264 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1265 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1266 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1267 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1268 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1271 enum { /* NVRAM to ACPI HKEY group map */
1272 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1273 TP_ACPI_HKEY_ZOOM_MASK
|
1274 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1275 TP_ACPI_HKEY_HIBERNATE_MASK
,
1276 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1277 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1278 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1279 TP_ACPI_HKEY_VOLDWN_MASK
|
1280 TP_ACPI_HKEY_MUTE_MASK
,
1283 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1284 struct tp_nvram_state
{
1285 u16 thinkpad_toggle
:1;
1287 u16 display_toggle
:1;
1288 u16 thinklight_toggle
:1;
1289 u16 hibernate_toggle
:1;
1290 u16 displayexp_toggle
:1;
1291 u16 display_state
:1;
1292 u16 brightness_toggle
:1;
1293 u16 volume_toggle
:1;
1296 u8 brightness_level
;
1300 static struct task_struct
*tpacpi_hotkey_task
;
1301 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1302 static int hotkey_poll_freq
= 10; /* Hz */
1303 static struct mutex hotkey_thread_mutex
;
1304 static struct mutex hotkey_thread_data_mutex
;
1305 static unsigned int hotkey_config_change
;
1307 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1309 #define hotkey_source_mask 0U
1311 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1313 static struct mutex hotkey_mutex
;
1315 static enum { /* Reasons for waking up */
1316 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1317 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1318 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1319 } hotkey_wakeup_reason
;
1321 static int hotkey_autosleep_ack
;
1323 static int hotkey_orig_status
;
1324 static u32 hotkey_orig_mask
;
1325 static u32 hotkey_all_mask
;
1326 static u32 hotkey_reserved_mask
;
1327 static u32 hotkey_mask
;
1329 static unsigned int hotkey_report_mode
;
1331 static u16
*hotkey_keycode_map
;
1333 static struct attribute_set
*hotkey_dev_attributes
;
1335 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1336 #define HOTKEY_CONFIG_CRITICAL_START \
1338 mutex_lock(&hotkey_thread_data_mutex); \
1339 hotkey_config_change++; \
1341 #define HOTKEY_CONFIG_CRITICAL_END \
1342 mutex_unlock(&hotkey_thread_data_mutex);
1344 #define HOTKEY_CONFIG_CRITICAL_START
1345 #define HOTKEY_CONFIG_CRITICAL_END
1346 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1348 /* HKEY.MHKG() return bits */
1349 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1351 static int hotkey_get_wlsw(int *status
)
1353 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1355 *status
= !!tpacpi_wlsw_emulstate
;
1359 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1364 static int hotkey_get_tablet_mode(int *status
)
1368 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1371 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1376 * Call with hotkey_mutex held
1378 static int hotkey_mask_get(void)
1382 if (tp_features
.hotkey_mask
) {
1383 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1386 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1392 * Call with hotkey_mutex held
1394 static int hotkey_mask_set(u32 mask
)
1399 if (tp_features
.hotkey_mask
) {
1400 if (!tp_warned
.hotkey_mask_ff
&&
1401 (mask
== 0xffff || mask
== 0xffffff ||
1402 mask
== 0xffffffff)) {
1403 tp_warned
.hotkey_mask_ff
= 1;
1404 printk(TPACPI_NOTICE
1405 "setting the hotkey mask to 0x%08x is likely "
1406 "not the best way to go about it\n", mask
);
1407 printk(TPACPI_NOTICE
1408 "please consider using the driver defaults, "
1409 "and refer to up-to-date thinkpad-acpi "
1413 HOTKEY_CONFIG_CRITICAL_START
1414 for (i
= 0; i
< 32; i
++) {
1416 /* enable in firmware mask only keys not in NVRAM
1417 * mode, but enable the key in the cached hotkey_mask
1418 * regardless of mode, or the key will end up
1419 * disabled by hotkey_mask_get() */
1420 if (!acpi_evalf(hkey_handle
,
1421 NULL
, "MHKM", "vdd", i
+ 1,
1422 !!((mask
& ~hotkey_source_mask
) & m
))) {
1426 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1429 HOTKEY_CONFIG_CRITICAL_END
1431 /* hotkey_mask_get must be called unconditionally below */
1432 if (!hotkey_mask_get() && !rc
&&
1433 (hotkey_mask
& ~hotkey_source_mask
) !=
1434 (mask
& ~hotkey_source_mask
)) {
1435 printk(TPACPI_NOTICE
1436 "requested hot key mask 0x%08x, but "
1437 "firmware forced it to 0x%08x\n",
1441 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1442 HOTKEY_CONFIG_CRITICAL_START
1443 hotkey_mask
= mask
& hotkey_source_mask
;
1444 HOTKEY_CONFIG_CRITICAL_END
1446 if (hotkey_mask
!= mask
) {
1447 printk(TPACPI_NOTICE
1448 "requested hot key mask 0x%08x, "
1449 "forced to 0x%08x (NVRAM poll mask is "
1450 "0x%08x): no firmware mask support\n",
1451 mask
, hotkey_mask
, hotkey_source_mask
);
1456 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1462 static int hotkey_status_get(int *status
)
1464 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1470 static int hotkey_status_set(int status
)
1472 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1478 static void tpacpi_input_send_tabletsw(void)
1482 if (tp_features
.hotkey_tablet
&&
1483 !hotkey_get_tablet_mode(&state
)) {
1484 mutex_lock(&tpacpi_inputdev_send_mutex
);
1486 input_report_switch(tpacpi_inputdev
,
1487 SW_TABLET_MODE
, !!state
);
1488 input_sync(tpacpi_inputdev
);
1490 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1494 static void tpacpi_input_send_key(unsigned int scancode
)
1496 unsigned int keycode
;
1498 keycode
= hotkey_keycode_map
[scancode
];
1500 if (keycode
!= KEY_RESERVED
) {
1501 mutex_lock(&tpacpi_inputdev_send_mutex
);
1503 input_report_key(tpacpi_inputdev
, keycode
, 1);
1504 if (keycode
== KEY_UNKNOWN
)
1505 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1507 input_sync(tpacpi_inputdev
);
1509 input_report_key(tpacpi_inputdev
, keycode
, 0);
1510 if (keycode
== KEY_UNKNOWN
)
1511 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1513 input_sync(tpacpi_inputdev
);
1515 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1519 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1520 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1522 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1524 tpacpi_input_send_key(scancode
);
1525 if (hotkey_report_mode
< 2) {
1526 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1527 0x80, 0x1001 + scancode
);
1531 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1535 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1536 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1537 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1538 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1539 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1540 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1542 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1543 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1544 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1546 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1547 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1548 n
->displayexp_toggle
=
1549 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1551 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1552 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1553 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1554 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1555 n
->brightness_toggle
=
1556 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1558 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1559 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1560 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1561 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1562 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1563 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1567 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1569 if ((mask & (1 << __scancode)) && \
1570 oldn->__member != newn->__member) \
1571 tpacpi_hotkey_send_key(__scancode); \
1574 #define TPACPI_MAY_SEND_KEY(__scancode) \
1575 do { if (mask & (1 << __scancode)) \
1576 tpacpi_hotkey_send_key(__scancode); } while (0)
1578 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1579 struct tp_nvram_state
*newn
,
1582 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1583 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1584 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1585 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1587 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1589 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1592 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1593 if (oldn
->mute
!= newn
->mute
) {
1594 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1596 if (oldn
->volume_level
> newn
->volume_level
) {
1597 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1598 } else if (oldn
->volume_level
< newn
->volume_level
) {
1599 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1600 } else if (oldn
->mute
== newn
->mute
) {
1601 /* repeated key presses that didn't change state */
1603 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1604 } else if (newn
->volume_level
!= 0) {
1605 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1607 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1612 /* handle brightness */
1613 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1614 if (oldn
->brightness_level
< newn
->brightness_level
) {
1615 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1616 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1617 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1619 /* repeated key presses that didn't change state */
1620 if (newn
->brightness_level
!= 0) {
1621 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1623 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1629 #undef TPACPI_COMPARE_KEY
1630 #undef TPACPI_MAY_SEND_KEY
1632 static int hotkey_kthread(void *data
)
1634 struct tp_nvram_state s
[2];
1636 unsigned int si
, so
;
1638 unsigned int change_detector
, must_reset
;
1640 mutex_lock(&hotkey_thread_mutex
);
1642 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1651 /* Initial state for compares */
1652 mutex_lock(&hotkey_thread_data_mutex
);
1653 change_detector
= hotkey_config_change
;
1654 mask
= hotkey_source_mask
& hotkey_mask
;
1655 mutex_unlock(&hotkey_thread_data_mutex
);
1656 hotkey_read_nvram(&s
[so
], mask
);
1658 while (!kthread_should_stop() && hotkey_poll_freq
) {
1660 t
= 1000/hotkey_poll_freq
;
1661 t
= msleep_interruptible(t
);
1662 if (unlikely(kthread_should_stop()))
1664 must_reset
= try_to_freeze();
1665 if (t
> 0 && !must_reset
)
1668 mutex_lock(&hotkey_thread_data_mutex
);
1669 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1670 /* forget old state on thaw or config change */
1673 change_detector
= hotkey_config_change
;
1675 mask
= hotkey_source_mask
& hotkey_mask
;
1676 mutex_unlock(&hotkey_thread_data_mutex
);
1679 hotkey_read_nvram(&s
[si
], mask
);
1680 if (likely(si
!= so
)) {
1681 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1691 mutex_unlock(&hotkey_thread_mutex
);
1695 static void hotkey_poll_stop_sync(void)
1697 if (tpacpi_hotkey_task
) {
1698 if (frozen(tpacpi_hotkey_task
) ||
1699 freezing(tpacpi_hotkey_task
))
1700 thaw_process(tpacpi_hotkey_task
);
1702 kthread_stop(tpacpi_hotkey_task
);
1703 tpacpi_hotkey_task
= NULL
;
1704 mutex_lock(&hotkey_thread_mutex
);
1705 /* at this point, the thread did exit */
1706 mutex_unlock(&hotkey_thread_mutex
);
1710 /* call with hotkey_mutex held */
1711 static void hotkey_poll_setup(int may_warn
)
1713 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1714 hotkey_poll_freq
> 0 &&
1715 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1716 if (!tpacpi_hotkey_task
) {
1717 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1718 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
1719 if (IS_ERR(tpacpi_hotkey_task
)) {
1720 tpacpi_hotkey_task
= NULL
;
1722 "could not create kernel thread "
1723 "for hotkey polling\n");
1727 hotkey_poll_stop_sync();
1729 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1730 printk(TPACPI_NOTICE
1731 "hot keys 0x%08x require polling, "
1732 "which is currently disabled\n",
1733 hotkey_source_mask
);
1738 static void hotkey_poll_setup_safe(int may_warn
)
1740 mutex_lock(&hotkey_mutex
);
1741 hotkey_poll_setup(may_warn
);
1742 mutex_unlock(&hotkey_mutex
);
1745 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1747 static void hotkey_poll_setup_safe(int __unused
)
1751 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1753 static int hotkey_inputdev_open(struct input_dev
*dev
)
1755 switch (tpacpi_lifecycle
) {
1756 case TPACPI_LIFE_INIT
:
1758 * hotkey_init will call hotkey_poll_setup_safe
1759 * at the appropriate moment
1762 case TPACPI_LIFE_EXITING
:
1764 case TPACPI_LIFE_RUNNING
:
1765 hotkey_poll_setup_safe(0);
1769 /* Should only happen if tpacpi_lifecycle is corrupt */
1774 static void hotkey_inputdev_close(struct input_dev
*dev
)
1776 /* disable hotkey polling when possible */
1777 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1778 hotkey_poll_setup_safe(0);
1781 /* sysfs hotkey enable ------------------------------------------------- */
1782 static ssize_t
hotkey_enable_show(struct device
*dev
,
1783 struct device_attribute
*attr
,
1788 res
= hotkey_status_get(&status
);
1792 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1795 static ssize_t
hotkey_enable_store(struct device
*dev
,
1796 struct device_attribute
*attr
,
1797 const char *buf
, size_t count
)
1802 if (parse_strtoul(buf
, 1, &t
))
1805 res
= hotkey_status_set(t
);
1807 return (res
) ? res
: count
;
1810 static struct device_attribute dev_attr_hotkey_enable
=
1811 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1812 hotkey_enable_show
, hotkey_enable_store
);
1814 /* sysfs hotkey mask --------------------------------------------------- */
1815 static ssize_t
hotkey_mask_show(struct device
*dev
,
1816 struct device_attribute
*attr
,
1821 if (mutex_lock_interruptible(&hotkey_mutex
))
1822 return -ERESTARTSYS
;
1823 res
= hotkey_mask_get();
1824 mutex_unlock(&hotkey_mutex
);
1827 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1830 static ssize_t
hotkey_mask_store(struct device
*dev
,
1831 struct device_attribute
*attr
,
1832 const char *buf
, size_t count
)
1837 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1840 if (mutex_lock_interruptible(&hotkey_mutex
))
1841 return -ERESTARTSYS
;
1843 res
= hotkey_mask_set(t
);
1845 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1846 hotkey_poll_setup(1);
1849 mutex_unlock(&hotkey_mutex
);
1851 return (res
) ? res
: count
;
1854 static struct device_attribute dev_attr_hotkey_mask
=
1855 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1856 hotkey_mask_show
, hotkey_mask_store
);
1858 /* sysfs hotkey bios_enabled ------------------------------------------- */
1859 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1860 struct device_attribute
*attr
,
1863 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1866 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1867 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1869 /* sysfs hotkey bios_mask ---------------------------------------------- */
1870 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1871 struct device_attribute
*attr
,
1874 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1877 static struct device_attribute dev_attr_hotkey_bios_mask
=
1878 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1880 /* sysfs hotkey all_mask ----------------------------------------------- */
1881 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1882 struct device_attribute
*attr
,
1885 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1886 hotkey_all_mask
| hotkey_source_mask
);
1889 static struct device_attribute dev_attr_hotkey_all_mask
=
1890 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1892 /* sysfs hotkey recommended_mask --------------------------------------- */
1893 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1894 struct device_attribute
*attr
,
1897 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1898 (hotkey_all_mask
| hotkey_source_mask
)
1899 & ~hotkey_reserved_mask
);
1902 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1903 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1904 hotkey_recommended_mask_show
, NULL
);
1906 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1908 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1909 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1910 struct device_attribute
*attr
,
1913 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1916 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1917 struct device_attribute
*attr
,
1918 const char *buf
, size_t count
)
1922 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1923 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1926 if (mutex_lock_interruptible(&hotkey_mutex
))
1927 return -ERESTARTSYS
;
1929 HOTKEY_CONFIG_CRITICAL_START
1930 hotkey_source_mask
= t
;
1931 HOTKEY_CONFIG_CRITICAL_END
1933 hotkey_poll_setup(1);
1935 mutex_unlock(&hotkey_mutex
);
1940 static struct device_attribute dev_attr_hotkey_source_mask
=
1941 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1942 hotkey_source_mask_show
, hotkey_source_mask_store
);
1944 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1945 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1946 struct device_attribute
*attr
,
1949 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1952 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1953 struct device_attribute
*attr
,
1954 const char *buf
, size_t count
)
1958 if (parse_strtoul(buf
, 25, &t
))
1961 if (mutex_lock_interruptible(&hotkey_mutex
))
1962 return -ERESTARTSYS
;
1964 hotkey_poll_freq
= t
;
1966 hotkey_poll_setup(1);
1967 mutex_unlock(&hotkey_mutex
);
1972 static struct device_attribute dev_attr_hotkey_poll_freq
=
1973 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1974 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1976 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1978 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
1979 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1980 struct device_attribute
*attr
,
1984 res
= hotkey_get_wlsw(&s
);
1988 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1991 static struct device_attribute dev_attr_hotkey_radio_sw
=
1992 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1994 static void hotkey_radio_sw_notify_change(void)
1996 if (tp_features
.hotkey_wlsw
)
1997 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2001 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2002 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2003 struct device_attribute
*attr
,
2007 res
= hotkey_get_tablet_mode(&s
);
2011 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2014 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2015 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2017 static void hotkey_tablet_mode_notify_change(void)
2019 if (tp_features
.hotkey_tablet
)
2020 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2021 "hotkey_tablet_mode");
2024 /* sysfs hotkey report_mode -------------------------------------------- */
2025 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2026 struct device_attribute
*attr
,
2029 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2030 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2033 static struct device_attribute dev_attr_hotkey_report_mode
=
2034 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2036 /* sysfs wakeup reason (pollable) -------------------------------------- */
2037 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2038 struct device_attribute
*attr
,
2041 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2044 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2045 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2047 static void hotkey_wakeup_reason_notify_change(void)
2049 if (tp_features
.hotkey_mask
)
2050 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2054 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2055 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2056 struct device_attribute
*attr
,
2059 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2062 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2063 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2064 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2066 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2068 if (tp_features
.hotkey_mask
)
2069 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2070 "wakeup_hotunplug_complete");
2073 /* --------------------------------------------------------------------- */
2075 static struct attribute
*hotkey_attributes
[] __initdata
= {
2076 &dev_attr_hotkey_enable
.attr
,
2077 &dev_attr_hotkey_bios_enabled
.attr
,
2078 &dev_attr_hotkey_report_mode
.attr
,
2079 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2080 &dev_attr_hotkey_mask
.attr
,
2081 &dev_attr_hotkey_all_mask
.attr
,
2082 &dev_attr_hotkey_recommended_mask
.attr
,
2083 &dev_attr_hotkey_source_mask
.attr
,
2084 &dev_attr_hotkey_poll_freq
.attr
,
2088 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
2089 &dev_attr_hotkey_bios_mask
.attr
,
2090 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2091 &dev_attr_hotkey_mask
.attr
,
2092 &dev_attr_hotkey_all_mask
.attr
,
2093 &dev_attr_hotkey_recommended_mask
.attr
,
2095 &dev_attr_hotkey_wakeup_reason
.attr
,
2096 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2099 static void bluetooth_update_rfk(void);
2100 static void wan_update_rfk(void);
2101 static void tpacpi_send_radiosw_update(void)
2105 /* Sync these BEFORE sending any rfkill events */
2106 if (tp_features
.bluetooth
)
2107 bluetooth_update_rfk();
2108 if (tp_features
.wan
)
2111 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2112 mutex_lock(&tpacpi_inputdev_send_mutex
);
2114 input_report_switch(tpacpi_inputdev
,
2115 SW_RFKILL_ALL
, !!wlsw
);
2116 input_sync(tpacpi_inputdev
);
2118 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2120 hotkey_radio_sw_notify_change();
2123 static void hotkey_exit(void)
2125 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2126 hotkey_poll_stop_sync();
2129 if (hotkey_dev_attributes
)
2130 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2132 kfree(hotkey_keycode_map
);
2134 if (tp_features
.hotkey
) {
2135 dbg_printk(TPACPI_DBG_EXIT
,
2136 "restoring original hot key mask\n");
2137 /* no short-circuit boolean operator below! */
2138 if ((hotkey_mask_set(hotkey_orig_mask
) |
2139 hotkey_status_set(hotkey_orig_status
)) != 0)
2141 "failed to restore hot key mask "
2142 "to BIOS defaults\n");
2146 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2148 /* Requirements for changing the default keymaps:
2150 * 1. Many of the keys are mapped to KEY_RESERVED for very
2151 * good reasons. Do not change them unless you have deep
2152 * knowledge on the IBM and Lenovo ThinkPad firmware for
2153 * the various ThinkPad models. The driver behaves
2154 * differently for KEY_RESERVED: such keys have their
2155 * hot key mask *unset* in mask_recommended, and also
2156 * in the initial hot key mask programmed into the
2157 * firmware at driver load time, which means the firm-
2158 * ware may react very differently if you change them to
2161 * 2. You must be subscribed to the linux-thinkpad and
2162 * ibm-acpi-devel mailing lists, and you should read the
2163 * list archives since 2007 if you want to change the
2164 * keymaps. This requirement exists so that you will
2165 * know the past history of problems with the thinkpad-
2166 * acpi driver keymaps, and also that you will be
2167 * listening to any bug reports;
2169 * 3. Do not send thinkpad-acpi specific patches directly to
2170 * for merging, *ever*. Send them to the linux-acpi
2171 * mailinglist for comments. Merging is to be done only
2172 * through acpi-test and the ACPI maintainer.
2174 * If the above is too much to ask, don't change the keymap.
2175 * Ask the thinkpad-acpi maintainer to do it, instead.
2177 static u16 ibm_keycode_map
[] __initdata
= {
2178 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2179 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2180 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2181 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2183 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2184 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2185 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2186 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2188 /* brightness: firmware always reacts to them, unless
2189 * X.org did some tricks in the radeon BIOS scratch
2190 * registers of *some* models */
2191 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2192 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2194 /* Thinklight: firmware always react to it */
2195 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2197 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2198 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2200 /* Volume: firmware always react to it and reprograms
2201 * the built-in *extra* mixer. Never map it to control
2202 * another mixer by default. */
2203 KEY_RESERVED
, /* 0x14: VOLUME UP */
2204 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2205 KEY_RESERVED
, /* 0x16: MUTE */
2207 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2209 /* (assignments unknown, please report if found) */
2210 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2211 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2213 static u16 lenovo_keycode_map
[] __initdata
= {
2214 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2215 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2216 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2217 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2219 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2220 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2221 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2222 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2224 /* These either have to go through ACPI video, or
2225 * act like in the IBM ThinkPads, so don't ever
2226 * enable them by default */
2227 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2228 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2230 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2232 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2233 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2235 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2236 * react to it and reprograms the built-in *extra* mixer.
2237 * Never map it to control another mixer by default.
2239 * T60?, T61, R60?, R61: firmware and EC tries to send
2240 * these over the regular keyboard, so these are no-ops,
2241 * but there are still weird bugs re. MUTE, so do not
2242 * change unless you get test reports from all Lenovo
2243 * models. May cause the BIOS to interfere with the
2246 KEY_RESERVED
, /* 0x14: VOLUME UP */
2247 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2248 KEY_RESERVED
, /* 0x16: MUTE */
2250 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2252 /* (assignments unknown, please report if found) */
2253 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2254 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2257 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2258 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2259 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2265 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
2267 BUG_ON(!tpacpi_inputdev
);
2268 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2269 tpacpi_inputdev
->close
!= NULL
);
2271 TPACPI_ACPIHANDLE_INIT(hkey
);
2272 mutex_init(&hotkey_mutex
);
2274 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2275 mutex_init(&hotkey_thread_mutex
);
2276 mutex_init(&hotkey_thread_data_mutex
);
2279 /* hotkey not supported on 570 */
2280 tp_features
.hotkey
= hkey_handle
!= NULL
;
2282 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
2283 str_supported(tp_features
.hotkey
));
2285 if (!tp_features
.hotkey
)
2288 tpacpi_disable_brightness_delay();
2290 hotkey_dev_attributes
= create_attr_set(13, NULL
);
2291 if (!hotkey_dev_attributes
)
2293 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2295 ARRAY_SIZE(hotkey_attributes
));
2299 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2300 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2301 for HKEY interface version 0x100 */
2302 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2303 if ((hkeyv
>> 8) != 1) {
2304 printk(TPACPI_ERR
"unknown version of the "
2305 "HKEY interface: 0x%x\n", hkeyv
);
2306 printk(TPACPI_ERR
"please report this to %s\n",
2310 * MHKV 0x100 in A31, R40, R40e,
2311 * T4x, X31, and later
2313 tp_features
.hotkey_mask
= 1;
2317 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
2318 str_supported(tp_features
.hotkey_mask
));
2320 if (tp_features
.hotkey_mask
) {
2321 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2324 "missing MHKA handler, "
2325 "please report this to %s\n",
2327 /* FN+F12, FN+F4, FN+F3 */
2328 hotkey_all_mask
= 0x080cU
;
2332 /* hotkey_source_mask *must* be zero for
2333 * the first hotkey_mask_get */
2334 res
= hotkey_status_get(&hotkey_orig_status
);
2338 if (tp_features
.hotkey_mask
) {
2339 res
= hotkey_mask_get();
2343 hotkey_orig_mask
= hotkey_mask
;
2344 res
= add_many_to_attr_set(
2345 hotkey_dev_attributes
,
2346 hotkey_mask_attributes
,
2347 ARRAY_SIZE(hotkey_mask_attributes
));
2352 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2353 if (tp_features
.hotkey_mask
) {
2354 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2357 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2360 vdbg_printk(TPACPI_DBG_INIT
,
2361 "hotkey source mask 0x%08x, polling freq %d\n",
2362 hotkey_source_mask
, hotkey_poll_freq
);
2365 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2367 tp_features
.hotkey_wlsw
= 1;
2369 "radio switch emulation enabled\n");
2372 /* Not all thinkpads have a hardware radio switch */
2373 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2374 tp_features
.hotkey_wlsw
= 1;
2376 "radio switch found; radios are %s\n",
2377 enabled(status
, 0));
2379 if (tp_features
.hotkey_wlsw
)
2380 res
= add_to_attr_set(hotkey_dev_attributes
,
2381 &dev_attr_hotkey_radio_sw
.attr
);
2383 /* For X41t, X60t, X61t Tablets... */
2384 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2385 tp_features
.hotkey_tablet
= 1;
2387 "possible tablet mode switch found; "
2388 "ThinkPad in %s mode\n",
2389 (status
& TP_HOTKEY_TABLET_MASK
)?
2390 "tablet" : "laptop");
2391 res
= add_to_attr_set(hotkey_dev_attributes
,
2392 &dev_attr_hotkey_tablet_mode
.attr
);
2396 res
= register_attr_set_with_sysfs(
2397 hotkey_dev_attributes
,
2398 &tpacpi_pdev
->dev
.kobj
);
2402 /* Set up key map */
2404 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2406 if (!hotkey_keycode_map
) {
2408 "failed to allocate memory for key map\n");
2413 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2414 dbg_printk(TPACPI_DBG_INIT
,
2415 "using Lenovo default hot key map\n");
2416 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2417 TPACPI_HOTKEY_MAP_SIZE
);
2419 dbg_printk(TPACPI_DBG_INIT
,
2420 "using IBM default hot key map\n");
2421 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2422 TPACPI_HOTKEY_MAP_SIZE
);
2425 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2426 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2427 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2428 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2429 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2430 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2431 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2432 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2433 set_bit(hotkey_keycode_map
[i
],
2434 tpacpi_inputdev
->keybit
);
2436 if (i
< sizeof(hotkey_reserved_mask
)*8)
2437 hotkey_reserved_mask
|= 1 << i
;
2441 if (tp_features
.hotkey_wlsw
) {
2442 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2443 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
2445 if (tp_features
.hotkey_tablet
) {
2446 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2447 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2450 /* Do not issue duplicate brightness change events to
2452 if (!tp_features
.bright_acpimode
)
2453 /* update bright_acpimode... */
2454 tpacpi_check_std_acpi_brightness_support();
2456 if (tp_features
.bright_acpimode
) {
2458 "This ThinkPad has standard ACPI backlight "
2459 "brightness control, supported by the ACPI "
2461 printk(TPACPI_NOTICE
2462 "Disabling thinkpad-acpi brightness events "
2465 /* The hotkey_reserved_mask change below is not
2466 * necessary while the keys are at KEY_RESERVED in the
2467 * default map, but better safe than sorry, leave it
2468 * here as a marker of what we have to do, especially
2469 * when we finally become able to set this at runtime
2470 * on response to X.org requests */
2471 hotkey_reserved_mask
|=
2472 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
2473 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
2476 dbg_printk(TPACPI_DBG_INIT
, "enabling hot key handling\n");
2477 res
= hotkey_status_set(1);
2482 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2483 & ~hotkey_reserved_mask
)
2484 | hotkey_orig_mask
);
2485 if (res
< 0 && res
!= -ENXIO
) {
2490 dbg_printk(TPACPI_DBG_INIT
,
2491 "legacy hot key reporting over procfs %s\n",
2492 (hotkey_report_mode
< 2) ?
2493 "enabled" : "disabled");
2495 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2496 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2498 hotkey_poll_setup_safe(1);
2499 tpacpi_send_radiosw_update();
2500 tpacpi_input_send_tabletsw();
2505 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2506 hotkey_dev_attributes
= NULL
;
2508 return (res
< 0)? res
: 1;
2511 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2514 unsigned int scancode
;
2519 if (event
!= 0x80) {
2521 "unknown HKEY notification event %d\n", event
);
2522 /* forward it to userspace, maybe it knows how to handle it */
2523 acpi_bus_generate_netlink_event(
2524 ibm
->acpi
->device
->pnp
.device_class
,
2525 dev_name(&ibm
->acpi
->device
->dev
),
2531 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2532 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2545 switch (hkey
>> 12) {
2547 /* 0x1000-0x1FFF: key presses */
2548 scancode
= hkey
& 0xfff;
2549 if (scancode
> 0 && scancode
< 0x21) {
2551 if (!(hotkey_source_mask
& (1 << scancode
))) {
2552 tpacpi_input_send_key(scancode
);
2564 case 0x2304: /* suspend, undock */
2565 case 0x2404: /* hibernation, undock */
2566 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2569 case 0x2305: /* suspend, bay eject */
2570 case 0x2405: /* hibernation, bay eject */
2571 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2577 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2579 "woke up due to a hot-unplug "
2581 hotkey_wakeup_reason_notify_change();
2585 /* bay-related wakeups */
2586 if (hkey
== 0x3003) {
2587 hotkey_autosleep_ack
= 1;
2590 hotkey_wakeup_hotunplug_complete_notify_change();
2596 /* dock-related wakeups */
2597 if (hkey
== 0x4003) {
2598 hotkey_autosleep_ack
= 1;
2601 hotkey_wakeup_hotunplug_complete_notify_change();
2607 /* 0x5000-0x5FFF: human interface helpers */
2609 case 0x5010: /* Lenovo new BIOS: brightness changed */
2610 case 0x500b: /* X61t: tablet pen inserted into bay */
2611 case 0x500c: /* X61t: tablet pen removed from bay */
2613 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2614 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2615 tpacpi_input_send_tabletsw();
2616 hotkey_tablet_mode_notify_change();
2621 /* LID switch events. Do not propagate */
2629 /* 0x7000-0x7FFF: misc */
2630 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2631 tpacpi_send_radiosw_update();
2635 /* fallthrough to default */
2640 printk(TPACPI_NOTICE
2641 "unhandled HKEY event 0x%04x\n", hkey
);
2645 if (!ignore_acpi_ev
&&
2646 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2647 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2651 /* netlink events */
2652 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2653 acpi_bus_generate_netlink_event(
2654 ibm
->acpi
->device
->pnp
.device_class
,
2655 dev_name(&ibm
->acpi
->device
->dev
),
2661 static void hotkey_suspend(pm_message_t state
)
2663 /* Do these on suspend, we get the events on early resume! */
2664 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2665 hotkey_autosleep_ack
= 0;
2668 static void hotkey_resume(void)
2670 tpacpi_disable_brightness_delay();
2672 if (hotkey_mask_get())
2674 "error while trying to read hot key mask "
2676 tpacpi_send_radiosw_update();
2677 hotkey_tablet_mode_notify_change();
2678 hotkey_wakeup_reason_notify_change();
2679 hotkey_wakeup_hotunplug_complete_notify_change();
2680 hotkey_poll_setup_safe(0);
2683 /* procfs -------------------------------------------------------------- */
2684 static int hotkey_read(char *p
)
2689 if (!tp_features
.hotkey
) {
2690 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2694 if (mutex_lock_interruptible(&hotkey_mutex
))
2695 return -ERESTARTSYS
;
2696 res
= hotkey_status_get(&status
);
2698 res
= hotkey_mask_get();
2699 mutex_unlock(&hotkey_mutex
);
2703 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2704 if (tp_features
.hotkey_mask
) {
2705 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2706 len
+= sprintf(p
+ len
,
2707 "commands:\tenable, disable, reset, <mask>\n");
2709 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2710 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2716 static int hotkey_write(char *buf
)
2722 if (!tp_features
.hotkey
)
2725 if (mutex_lock_interruptible(&hotkey_mutex
))
2726 return -ERESTARTSYS
;
2732 while ((cmd
= next_cmd(&buf
))) {
2733 if (strlencmp(cmd
, "enable") == 0) {
2735 } else if (strlencmp(cmd
, "disable") == 0) {
2737 } else if (strlencmp(cmd
, "reset") == 0) {
2738 status
= hotkey_orig_status
;
2739 mask
= hotkey_orig_mask
;
2740 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2742 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2750 res
= hotkey_status_set(status
);
2752 if (!res
&& mask
!= hotkey_mask
)
2753 res
= hotkey_mask_set(mask
);
2756 mutex_unlock(&hotkey_mutex
);
2760 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2761 {TPACPI_ACPI_HKEY_HID
, 0},
2765 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2766 .hid
= ibm_htk_device_ids
,
2767 .notify
= hotkey_notify
,
2768 .handle
= &hkey_handle
,
2769 .type
= ACPI_DEVICE_NOTIFY
,
2772 static struct ibm_struct hotkey_driver_data
= {
2774 .read
= hotkey_read
,
2775 .write
= hotkey_write
,
2776 .exit
= hotkey_exit
,
2777 .resume
= hotkey_resume
,
2778 .suspend
= hotkey_suspend
,
2779 .acpi
= &ibm_hotkey_acpidriver
,
2782 /*************************************************************************
2783 * Bluetooth subdriver
2787 /* ACPI GBDC/SBDC bits */
2788 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2789 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2790 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
2795 /* ACPI \BLTH commands */
2796 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
2797 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
2798 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
2799 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
2800 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
2803 static struct rfkill
*tpacpi_bluetooth_rfkill
;
2805 static void bluetooth_suspend(pm_message_t state
)
2807 /* Try to make sure radio will resume powered off */
2808 acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
2809 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
);
2812 static int bluetooth_get_radiosw(void)
2816 if (!tp_features
.bluetooth
)
2819 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
2820 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
2821 return RFKILL_STATE_HARD_BLOCKED
;
2823 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2824 if (dbg_bluetoothemul
)
2825 return (tpacpi_bluetooth_emulstate
) ?
2826 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
2829 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2832 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
2833 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
2836 static void bluetooth_update_rfk(void)
2840 if (!tpacpi_bluetooth_rfkill
)
2843 status
= bluetooth_get_radiosw();
2846 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
2849 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
2853 if (!tp_features
.bluetooth
)
2856 /* WLSW overrides bluetooth in firmware/hardware, but there is no
2857 * reason to risk weird behaviour. */
2858 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
2862 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2863 if (dbg_bluetoothemul
) {
2864 tpacpi_bluetooth_emulstate
= !!radio_on
;
2866 bluetooth_update_rfk();
2871 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
2873 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
2876 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2880 bluetooth_update_rfk();
2885 /* sysfs bluetooth enable ---------------------------------------------- */
2886 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2887 struct device_attribute
*attr
,
2892 status
= bluetooth_get_radiosw();
2896 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2897 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
2900 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2901 struct device_attribute
*attr
,
2902 const char *buf
, size_t count
)
2907 if (parse_strtoul(buf
, 1, &t
))
2910 res
= bluetooth_set_radiosw(t
, 1);
2912 return (res
) ? res
: count
;
2915 static struct device_attribute dev_attr_bluetooth_enable
=
2916 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2917 bluetooth_enable_show
, bluetooth_enable_store
);
2919 /* --------------------------------------------------------------------- */
2921 static struct attribute
*bluetooth_attributes
[] = {
2922 &dev_attr_bluetooth_enable
.attr
,
2926 static const struct attribute_group bluetooth_attr_group
= {
2927 .attrs
= bluetooth_attributes
,
2930 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
2932 int bts
= bluetooth_get_radiosw();
2941 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
2943 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
2946 static void bluetooth_exit(void)
2948 if (tpacpi_bluetooth_rfkill
)
2949 rfkill_unregister(tpacpi_bluetooth_rfkill
);
2951 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2952 &bluetooth_attr_group
);
2955 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
2960 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
2962 TPACPI_ACPIHANDLE_INIT(hkey
);
2964 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2965 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
2966 tp_features
.bluetooth
= hkey_handle
&&
2967 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
2969 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
2970 str_supported(tp_features
.bluetooth
),
2973 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2974 if (dbg_bluetoothemul
) {
2975 tp_features
.bluetooth
= 1;
2977 "bluetooth switch emulation enabled\n");
2980 if (tp_features
.bluetooth
&&
2981 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
2982 /* no bluetooth hardware present in system */
2983 tp_features
.bluetooth
= 0;
2984 dbg_printk(TPACPI_DBG_INIT
,
2985 "bluetooth hardware not installed\n");
2988 if (!tp_features
.bluetooth
)
2991 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2992 &bluetooth_attr_group
);
2996 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
2997 &tpacpi_bluetooth_rfkill
,
2998 RFKILL_TYPE_BLUETOOTH
,
2999 "tpacpi_bluetooth_sw",
3000 tpacpi_bluetooth_rfk_set
,
3001 tpacpi_bluetooth_rfk_get
);
3010 /* procfs -------------------------------------------------------------- */
3011 static int bluetooth_read(char *p
)
3014 int status
= bluetooth_get_radiosw();
3016 if (!tp_features
.bluetooth
)
3017 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3019 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3020 (status
== RFKILL_STATE_UNBLOCKED
) ?
3021 "enabled" : "disabled");
3022 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3028 static int bluetooth_write(char *buf
)
3032 if (!tp_features
.bluetooth
)
3035 while ((cmd
= next_cmd(&buf
))) {
3036 if (strlencmp(cmd
, "enable") == 0) {
3037 bluetooth_set_radiosw(1, 1);
3038 } else if (strlencmp(cmd
, "disable") == 0) {
3039 bluetooth_set_radiosw(0, 1);
3047 static struct ibm_struct bluetooth_driver_data
= {
3048 .name
= "bluetooth",
3049 .read
= bluetooth_read
,
3050 .write
= bluetooth_write
,
3051 .exit
= bluetooth_exit
,
3052 .suspend
= bluetooth_suspend
,
3055 /*************************************************************************
3060 /* ACPI GWAN/SWAN bits */
3061 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3062 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3063 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3067 static struct rfkill
*tpacpi_wan_rfkill
;
3069 static void wan_suspend(pm_message_t state
)
3071 /* Try to make sure radio will resume powered off */
3072 acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3073 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
);
3076 static int wan_get_radiosw(void)
3080 if (!tp_features
.wan
)
3083 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3084 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3085 return RFKILL_STATE_HARD_BLOCKED
;
3087 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3089 return (tpacpi_wwan_emulstate
) ?
3090 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3093 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3096 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3097 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3100 static void wan_update_rfk(void)
3104 if (!tpacpi_wan_rfkill
)
3107 status
= wan_get_radiosw();
3110 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3113 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3117 if (!tp_features
.wan
)
3120 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3121 * reason to risk weird behaviour. */
3122 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3126 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3128 tpacpi_wwan_emulstate
= !!radio_on
;
3135 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3137 status
= TP_ACPI_WANCARD_RADIOSSW
;
3140 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3149 /* sysfs wan enable ---------------------------------------------------- */
3150 static ssize_t
wan_enable_show(struct device
*dev
,
3151 struct device_attribute
*attr
,
3156 status
= wan_get_radiosw();
3160 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3161 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3164 static ssize_t
wan_enable_store(struct device
*dev
,
3165 struct device_attribute
*attr
,
3166 const char *buf
, size_t count
)
3171 if (parse_strtoul(buf
, 1, &t
))
3174 res
= wan_set_radiosw(t
, 1);
3176 return (res
) ? res
: count
;
3179 static struct device_attribute dev_attr_wan_enable
=
3180 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
3181 wan_enable_show
, wan_enable_store
);
3183 /* --------------------------------------------------------------------- */
3185 static struct attribute
*wan_attributes
[] = {
3186 &dev_attr_wan_enable
.attr
,
3190 static const struct attribute_group wan_attr_group
= {
3191 .attrs
= wan_attributes
,
3194 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
3196 int wans
= wan_get_radiosw();
3205 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
3207 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3210 static void wan_exit(void)
3212 if (tpacpi_wan_rfkill
)
3213 rfkill_unregister(tpacpi_wan_rfkill
);
3215 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3219 static int __init
wan_init(struct ibm_init_struct
*iibm
)
3224 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
3226 TPACPI_ACPIHANDLE_INIT(hkey
);
3228 tp_features
.wan
= hkey_handle
&&
3229 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
3231 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
3232 str_supported(tp_features
.wan
),
3235 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3237 tp_features
.wan
= 1;
3239 "wwan switch emulation enabled\n");
3242 if (tp_features
.wan
&&
3243 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
3244 /* no wan hardware present in system */
3245 tp_features
.wan
= 0;
3246 dbg_printk(TPACPI_DBG_INIT
,
3247 "wan hardware not installed\n");
3250 if (!tp_features
.wan
)
3253 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3258 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
3263 tpacpi_wan_rfk_get
);
3272 /* procfs -------------------------------------------------------------- */
3273 static int wan_read(char *p
)
3276 int status
= wan_get_radiosw();
3278 if (!tp_features
.wan
)
3279 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3281 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3282 (status
== RFKILL_STATE_UNBLOCKED
) ?
3283 "enabled" : "disabled");
3284 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3290 static int wan_write(char *buf
)
3294 if (!tp_features
.wan
)
3297 while ((cmd
= next_cmd(&buf
))) {
3298 if (strlencmp(cmd
, "enable") == 0) {
3299 wan_set_radiosw(1, 1);
3300 } else if (strlencmp(cmd
, "disable") == 0) {
3301 wan_set_radiosw(0, 1);
3309 static struct ibm_struct wan_driver_data
= {
3314 .suspend
= wan_suspend
,
3317 /*************************************************************************
3321 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
3323 enum video_access_mode
{
3324 TPACPI_VIDEO_NONE
= 0,
3325 TPACPI_VIDEO_570
, /* 570 */
3326 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
3327 TPACPI_VIDEO_NEW
, /* all others */
3330 enum { /* video status flags, based on VIDEO_570 */
3331 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
3332 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
3333 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
3336 enum { /* TPACPI_VIDEO_570 constants */
3337 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
3338 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
3339 * video_status_flags */
3340 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
3341 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
3344 static enum video_access_mode video_supported
;
3345 static int video_orig_autosw
;
3347 static int video_autosw_get(void);
3348 static int video_autosw_set(int enable
);
3350 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
3352 static int __init
video_init(struct ibm_init_struct
*iibm
)
3356 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
3358 TPACPI_ACPIHANDLE_INIT(vid
);
3359 TPACPI_ACPIHANDLE_INIT(vid2
);
3361 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
3362 /* G41, assume IVGA doesn't change */
3363 vid_handle
= vid2_handle
;
3366 /* video switching not supported on R30, R31 */
3367 video_supported
= TPACPI_VIDEO_NONE
;
3368 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
3370 video_supported
= TPACPI_VIDEO_570
;
3371 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
3372 /* 600e/x, 770e, 770x */
3373 video_supported
= TPACPI_VIDEO_770
;
3376 video_supported
= TPACPI_VIDEO_NEW
;
3378 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
3379 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
3382 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
3385 static void video_exit(void)
3387 dbg_printk(TPACPI_DBG_EXIT
,
3388 "restoring original video autoswitch mode\n");
3389 if (video_autosw_set(video_orig_autosw
))
3390 printk(TPACPI_ERR
"error while trying to restore original "
3391 "video autoswitch mode\n");
3394 static int video_outputsw_get(void)
3399 switch (video_supported
) {
3400 case TPACPI_VIDEO_570
:
3401 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
3402 TP_ACPI_VIDEO_570_PHSCMD
))
3404 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
3406 case TPACPI_VIDEO_770
:
3407 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3410 status
|= TP_ACPI_VIDEO_S_LCD
;
3411 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3414 status
|= TP_ACPI_VIDEO_S_CRT
;
3416 case TPACPI_VIDEO_NEW
:
3417 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
3418 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3421 status
|= TP_ACPI_VIDEO_S_CRT
;
3423 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
3424 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3427 status
|= TP_ACPI_VIDEO_S_LCD
;
3428 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
3431 status
|= TP_ACPI_VIDEO_S_DVI
;
3440 static int video_outputsw_set(int status
)
3445 switch (video_supported
) {
3446 case TPACPI_VIDEO_570
:
3447 res
= acpi_evalf(NULL
, NULL
,
3448 "\\_SB.PHS2", "vdd",
3449 TP_ACPI_VIDEO_570_PHS2CMD
,
3450 status
| TP_ACPI_VIDEO_570_PHS2SET
);
3452 case TPACPI_VIDEO_770
:
3453 autosw
= video_autosw_get();
3457 res
= video_autosw_set(1);
3460 res
= acpi_evalf(vid_handle
, NULL
,
3461 "ASWT", "vdd", status
* 0x100, 0);
3462 if (!autosw
&& video_autosw_set(autosw
)) {
3464 "video auto-switch left enabled due to error\n");
3468 case TPACPI_VIDEO_NEW
:
3469 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
3470 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
3476 return (res
)? 0 : -EIO
;
3479 static int video_autosw_get(void)
3483 switch (video_supported
) {
3484 case TPACPI_VIDEO_570
:
3485 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
3488 case TPACPI_VIDEO_770
:
3489 case TPACPI_VIDEO_NEW
:
3490 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
3500 static int video_autosw_set(int enable
)
3502 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
3507 static int video_outputsw_cycle(void)
3509 int autosw
= video_autosw_get();
3515 switch (video_supported
) {
3516 case TPACPI_VIDEO_570
:
3517 res
= video_autosw_set(1);
3520 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
3522 case TPACPI_VIDEO_770
:
3523 case TPACPI_VIDEO_NEW
:
3524 res
= video_autosw_set(1);
3527 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
3532 if (!autosw
&& video_autosw_set(autosw
)) {
3534 "video auto-switch left enabled due to error\n");
3538 return (res
)? 0 : -EIO
;
3541 static int video_expand_toggle(void)
3543 switch (video_supported
) {
3544 case TPACPI_VIDEO_570
:
3545 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
3547 case TPACPI_VIDEO_770
:
3548 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
3550 case TPACPI_VIDEO_NEW
:
3551 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
3559 static int video_read(char *p
)
3564 if (video_supported
== TPACPI_VIDEO_NONE
) {
3565 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3569 status
= video_outputsw_get();
3573 autosw
= video_autosw_get();
3577 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3578 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
3579 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
3580 if (video_supported
== TPACPI_VIDEO_NEW
)
3581 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
3582 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
3583 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
3584 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
3585 if (video_supported
== TPACPI_VIDEO_NEW
)
3586 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
3587 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
3588 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
3593 static int video_write(char *buf
)
3596 int enable
, disable
, status
;
3599 if (video_supported
== TPACPI_VIDEO_NONE
)
3605 while ((cmd
= next_cmd(&buf
))) {
3606 if (strlencmp(cmd
, "lcd_enable") == 0) {
3607 enable
|= TP_ACPI_VIDEO_S_LCD
;
3608 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
3609 disable
|= TP_ACPI_VIDEO_S_LCD
;
3610 } else if (strlencmp(cmd
, "crt_enable") == 0) {
3611 enable
|= TP_ACPI_VIDEO_S_CRT
;
3612 } else if (strlencmp(cmd
, "crt_disable") == 0) {
3613 disable
|= TP_ACPI_VIDEO_S_CRT
;
3614 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3615 strlencmp(cmd
, "dvi_enable") == 0) {
3616 enable
|= TP_ACPI_VIDEO_S_DVI
;
3617 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3618 strlencmp(cmd
, "dvi_disable") == 0) {
3619 disable
|= TP_ACPI_VIDEO_S_DVI
;
3620 } else if (strlencmp(cmd
, "auto_enable") == 0) {
3621 res
= video_autosw_set(1);
3624 } else if (strlencmp(cmd
, "auto_disable") == 0) {
3625 res
= video_autosw_set(0);
3628 } else if (strlencmp(cmd
, "video_switch") == 0) {
3629 res
= video_outputsw_cycle();
3632 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
3633 res
= video_expand_toggle();
3640 if (enable
|| disable
) {
3641 status
= video_outputsw_get();
3644 res
= video_outputsw_set((status
& ~disable
) | enable
);
3652 static struct ibm_struct video_driver_data
= {
3655 .write
= video_write
,
3659 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
3661 /*************************************************************************
3662 * Light (thinklight) subdriver
3665 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
3666 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
3668 static int light_get_status(void)
3672 if (tp_features
.light_status
) {
3673 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
3681 static int light_set_status(int status
)
3685 if (tp_features
.light
) {
3687 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
3689 TP_CMOS_THINKLIGHT_ON
:
3690 TP_CMOS_THINKLIGHT_OFF
);
3692 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
3695 return (rc
)? 0 : -EIO
;
3701 static void light_set_status_worker(struct work_struct
*work
)
3703 struct tpacpi_led_classdev
*data
=
3704 container_of(work
, struct tpacpi_led_classdev
, work
);
3706 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
3707 light_set_status((data
->new_brightness
!= LED_OFF
));
3710 static void light_sysfs_set(struct led_classdev
*led_cdev
,
3711 enum led_brightness brightness
)
3713 struct tpacpi_led_classdev
*data
=
3714 container_of(led_cdev
,
3715 struct tpacpi_led_classdev
,
3717 data
->new_brightness
= brightness
;
3718 queue_work(tpacpi_wq
, &data
->work
);
3721 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
3723 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
3726 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
3728 .name
= "tpacpi::thinklight",
3729 .brightness_set
= &light_sysfs_set
,
3730 .brightness_get
= &light_sysfs_get
,
3734 static int __init
light_init(struct ibm_init_struct
*iibm
)
3738 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
3740 TPACPI_ACPIHANDLE_INIT(ledb
);
3741 TPACPI_ACPIHANDLE_INIT(lght
);
3742 TPACPI_ACPIHANDLE_INIT(cmos
);
3743 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
3745 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
3746 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
3748 if (tp_features
.light
)
3749 /* light status not supported on
3750 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
3751 tp_features
.light_status
=
3752 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
3754 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
3755 str_supported(tp_features
.light
),
3756 str_supported(tp_features
.light_status
));
3758 if (!tp_features
.light
)
3761 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
3762 &tpacpi_led_thinklight
.led_classdev
);
3765 tp_features
.light
= 0;
3766 tp_features
.light_status
= 0;
3774 static void light_exit(void)
3776 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
3777 if (work_pending(&tpacpi_led_thinklight
.work
))
3778 flush_workqueue(tpacpi_wq
);
3781 static int light_read(char *p
)
3786 if (!tp_features
.light
) {
3787 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3788 } else if (!tp_features
.light_status
) {
3789 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
3790 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3792 status
= light_get_status();
3795 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
3796 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3802 static int light_write(char *buf
)
3807 if (!tp_features
.light
)
3810 while ((cmd
= next_cmd(&buf
))) {
3811 if (strlencmp(cmd
, "on") == 0) {
3813 } else if (strlencmp(cmd
, "off") == 0) {
3819 return light_set_status(newstatus
);
3822 static struct ibm_struct light_driver_data
= {
3825 .write
= light_write
,
3829 /*************************************************************************
3833 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3835 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
3836 static int dock_read(char *p
);
3837 static int dock_write(char *buf
);
3839 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
3840 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
3841 "\\_SB.PCI0.PCI1.DOCK", /* all others */
3842 "\\_SB.PCI.ISA.SLCE", /* 570 */
3843 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
3845 /* don't list other alternatives as we install a notify handler on the 570 */
3846 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
3848 static const struct acpi_device_id ibm_pci_device_ids
[] = {
3849 {PCI_ROOT_HID_STRING
, 0},
3853 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
3855 .notify
= dock_notify
,
3856 .handle
= &dock_handle
,
3857 .type
= ACPI_SYSTEM_NOTIFY
,
3860 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
3861 * We just use it to get notifications of dock hotplug
3862 * in very old thinkpads */
3863 .hid
= ibm_pci_device_ids
,
3864 .notify
= dock_notify
,
3865 .handle
= &pci_handle
,
3866 .type
= ACPI_SYSTEM_NOTIFY
,
3870 static struct ibm_struct dock_driver_data
[2] = {
3874 .write
= dock_write
,
3875 .acpi
= &ibm_dock_acpidriver
[0],
3879 .acpi
= &ibm_dock_acpidriver
[1],
3883 #define dock_docked() (_sta(dock_handle) & 1)
3885 static int __init
dock_init(struct ibm_init_struct
*iibm
)
3887 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
3889 TPACPI_ACPIHANDLE_INIT(dock
);
3891 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
3892 str_supported(dock_handle
!= NULL
));
3894 return (dock_handle
)? 0 : 1;
3897 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
3901 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
3903 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
3904 dock_driver_data
[0].flags
.acpi_notify_installed
) {
3905 TPACPI_ACPIHANDLE_INIT(pci
);
3906 dock2_needed
= (pci_handle
!= NULL
);
3907 vdbg_printk(TPACPI_DBG_INIT
,
3908 "dock PCI handler for the TP 570 is %s\n",
3909 str_supported(dock2_needed
));
3911 vdbg_printk(TPACPI_DBG_INIT
,
3912 "dock subdriver part 2 not required\n");
3916 return (dock2_needed
)? 0 : 1;
3919 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
3921 int docked
= dock_docked();
3922 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
3923 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
3926 if (event
== 1 && !pci
) /* 570 */
3927 data
= 1; /* button */
3928 else if (event
== 1 && pci
) /* 570 */
3929 data
= 3; /* dock */
3930 else if (event
== 3 && docked
)
3931 data
= 1; /* button */
3932 else if (event
== 3 && !docked
)
3933 data
= 2; /* undock */
3934 else if (event
== 0 && docked
)
3935 data
= 3; /* dock */
3937 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
3938 event
, _sta(dock_handle
));
3939 data
= 0; /* unknown */
3941 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
3942 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3943 dev_name(&ibm
->acpi
->device
->dev
),
3947 static int dock_read(char *p
)
3950 int docked
= dock_docked();
3953 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3955 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
3957 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
3958 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
3964 static int dock_write(char *buf
)
3971 while ((cmd
= next_cmd(&buf
))) {
3972 if (strlencmp(cmd
, "undock") == 0) {
3973 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
3974 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
3976 } else if (strlencmp(cmd
, "dock") == 0) {
3977 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
3986 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
3988 /*************************************************************************
3992 #ifdef CONFIG_THINKPAD_ACPI_BAY
3994 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
3995 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
3996 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
3997 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
3998 ); /* A21e, R30, R31 */
3999 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
4000 "_EJ0", /* all others */
4001 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
4002 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
4003 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
4005 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
4009 static int __init
bay_init(struct ibm_init_struct
*iibm
)
4011 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
4013 TPACPI_ACPIHANDLE_INIT(bay
);
4015 TPACPI_ACPIHANDLE_INIT(bay_ej
);
4016 TPACPI_ACPIHANDLE_INIT(bay2
);
4018 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
4020 tp_features
.bay_status
= bay_handle
&&
4021 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
4022 tp_features
.bay_status2
= bay2_handle
&&
4023 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
4025 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
4026 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
4027 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
4028 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
4030 vdbg_printk(TPACPI_DBG_INIT
,
4031 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
4032 str_supported(tp_features
.bay_status
),
4033 str_supported(tp_features
.bay_eject
),
4034 str_supported(tp_features
.bay_status2
),
4035 str_supported(tp_features
.bay_eject2
));
4037 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
4038 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
4041 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
4043 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
4044 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
4045 dev_name(&ibm
->acpi
->device
->dev
),
4049 #define bay_occupied(b) (_sta(b##_handle) & 1)
4051 static int bay_read(char *p
)
4054 int occupied
= bay_occupied(bay
);
4055 int occupied2
= bay_occupied(bay2
);
4058 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4059 tp_features
.bay_status
?
4060 (occupied
? "occupied" : "unoccupied") :
4062 if (tp_features
.bay_status2
)
4063 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
4064 "occupied" : "unoccupied");
4066 eject
= tp_features
.bay_eject
&& occupied
;
4067 eject2
= tp_features
.bay_eject2
&& occupied2
;
4069 if (eject
&& eject2
)
4070 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
4072 len
+= sprintf(p
+ len
, "commands:\teject\n");
4074 len
+= sprintf(p
+ len
, "commands:\teject2\n");
4079 static int bay_write(char *buf
)
4083 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
4086 while ((cmd
= next_cmd(&buf
))) {
4087 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
4088 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
4090 } else if (tp_features
.bay_eject2
&&
4091 strlencmp(cmd
, "eject2") == 0) {
4092 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
4101 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
4102 .notify
= bay_notify
,
4103 .handle
= &bay_handle
,
4104 .type
= ACPI_SYSTEM_NOTIFY
,
4107 static struct ibm_struct bay_driver_data
= {
4111 .acpi
= &ibm_bay_acpidriver
,
4114 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4116 /*************************************************************************
4120 /* sysfs cmos_command -------------------------------------------------- */
4121 static ssize_t
cmos_command_store(struct device
*dev
,
4122 struct device_attribute
*attr
,
4123 const char *buf
, size_t count
)
4125 unsigned long cmos_cmd
;
4128 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4131 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4132 return (res
)? res
: count
;
4135 static struct device_attribute dev_attr_cmos_command
=
4136 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4138 /* --------------------------------------------------------------------- */
4140 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4144 vdbg_printk(TPACPI_DBG_INIT
,
4145 "initializing cmos commands subdriver\n");
4147 TPACPI_ACPIHANDLE_INIT(cmos
);
4149 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4150 str_supported(cmos_handle
!= NULL
));
4152 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4156 return (cmos_handle
)? 0 : 1;
4159 static void cmos_exit(void)
4161 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4164 static int cmos_read(char *p
)
4168 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4169 R30, R31, T20-22, X20-21 */
4171 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4173 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4174 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4180 static int cmos_write(char *buf
)
4185 while ((cmd
= next_cmd(&buf
))) {
4186 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4187 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4192 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4200 static struct ibm_struct cmos_driver_data
= {
4203 .write
= cmos_write
,
4207 /*************************************************************************
4211 enum led_access_mode
{
4212 TPACPI_LED_NONE
= 0,
4213 TPACPI_LED_570
, /* 570 */
4214 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4215 TPACPI_LED_NEW
, /* all others */
4218 enum { /* For TPACPI_LED_OLD */
4219 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4220 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4221 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4230 static enum led_access_mode led_supported
;
4232 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4233 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4234 /* T20-22, X20-21 */
4235 "LED", /* all others */
4238 #define TPACPI_LED_NUMLEDS 8
4239 static struct tpacpi_led_classdev
*tpacpi_leds
;
4240 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4241 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4242 /* there's a limit of 19 chars + NULL before 2.6.26 */
4244 "tpacpi:orange:batt",
4245 "tpacpi:green:batt",
4246 "tpacpi::dock_active",
4247 "tpacpi::bay_active",
4248 "tpacpi::dock_batt",
4249 "tpacpi::unknown_led",
4253 static int led_get_status(const unsigned int led
)
4256 enum led_status_t led_s
;
4258 switch (led_supported
) {
4259 case TPACPI_LED_570
:
4260 if (!acpi_evalf(ec_handle
,
4261 &status
, "GLED", "dd", 1 << led
))
4263 led_s
= (status
== 0)?
4268 tpacpi_led_state_cache
[led
] = led_s
;
4277 static int led_set_status(const unsigned int led
,
4278 const enum led_status_t ledstatus
)
4280 /* off, on, blink. Index is led_status_t */
4281 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
4282 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
4286 switch (led_supported
) {
4287 case TPACPI_LED_570
:
4291 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4292 (1 << led
), led_sled_arg1
[ledstatus
]))
4295 case TPACPI_LED_OLD
:
4296 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4299 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
4301 rc
= ec_write(TPACPI_LED_EC_HLBL
,
4302 (ledstatus
== TPACPI_LED_BLINK
) << led
);
4304 rc
= ec_write(TPACPI_LED_EC_HLCL
,
4305 (ledstatus
!= TPACPI_LED_OFF
) << led
);
4307 case TPACPI_LED_NEW
:
4309 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4310 led
, led_led_arg1
[ledstatus
]))
4318 tpacpi_led_state_cache
[led
] = ledstatus
;
4323 static void led_sysfs_set_status(unsigned int led
,
4324 enum led_brightness brightness
)
4327 (brightness
== LED_OFF
) ?
4329 (tpacpi_led_state_cache
[led
] == TPACPI_LED_BLINK
) ?
4330 TPACPI_LED_BLINK
: TPACPI_LED_ON
);
4333 static void led_set_status_worker(struct work_struct
*work
)
4335 struct tpacpi_led_classdev
*data
=
4336 container_of(work
, struct tpacpi_led_classdev
, work
);
4338 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4339 led_sysfs_set_status(data
->led
, data
->new_brightness
);
4342 static void led_sysfs_set(struct led_classdev
*led_cdev
,
4343 enum led_brightness brightness
)
4345 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4346 struct tpacpi_led_classdev
, led_classdev
);
4348 data
->new_brightness
= brightness
;
4349 queue_work(tpacpi_wq
, &data
->work
);
4352 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
4353 unsigned long *delay_on
, unsigned long *delay_off
)
4355 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4356 struct tpacpi_led_classdev
, led_classdev
);
4358 /* Can we choose the flash rate? */
4359 if (*delay_on
== 0 && *delay_off
== 0) {
4360 /* yes. set them to the hardware blink rate (1 Hz) */
4361 *delay_on
= 500; /* ms */
4362 *delay_off
= 500; /* ms */
4363 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
4366 data
->new_brightness
= TPACPI_LED_BLINK
;
4367 queue_work(tpacpi_wq
, &data
->work
);
4372 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
4376 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4377 struct tpacpi_led_classdev
, led_classdev
);
4379 rc
= led_get_status(data
->led
);
4381 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
4382 rc
= LED_OFF
; /* no error handling in led class :( */
4389 static void led_exit(void)
4393 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4394 if (tpacpi_leds
[i
].led_classdev
.name
)
4395 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
4401 static int __init
led_init(struct ibm_init_struct
*iibm
)
4406 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
4408 TPACPI_ACPIHANDLE_INIT(led
);
4411 /* led not supported on R30, R31 */
4412 led_supported
= TPACPI_LED_NONE
;
4413 else if (strlencmp(led_path
, "SLED") == 0)
4415 led_supported
= TPACPI_LED_570
;
4416 else if (strlencmp(led_path
, "SYSL") == 0)
4417 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4418 led_supported
= TPACPI_LED_OLD
;
4421 led_supported
= TPACPI_LED_NEW
;
4423 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
4424 str_supported(led_supported
), led_supported
);
4426 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
4429 printk(TPACPI_ERR
"Out of memory for LED data\n");
4433 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4434 tpacpi_leds
[i
].led
= i
;
4436 tpacpi_leds
[i
].led_classdev
.brightness_set
= &led_sysfs_set
;
4437 tpacpi_leds
[i
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
4438 if (led_supported
== TPACPI_LED_570
)
4439 tpacpi_leds
[i
].led_classdev
.brightness_get
=
4442 tpacpi_leds
[i
].led_classdev
.name
= tpacpi_led_names
[i
];
4444 INIT_WORK(&tpacpi_leds
[i
].work
, led_set_status_worker
);
4446 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4447 &tpacpi_leds
[i
].led_classdev
);
4449 tpacpi_leds
[i
].led_classdev
.name
= NULL
;
4455 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
4458 #define str_led_status(s) \
4459 ((s) == TPACPI_LED_OFF ? "off" : \
4460 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
4462 static int led_read(char *p
)
4466 if (!led_supported
) {
4467 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4470 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4472 if (led_supported
== TPACPI_LED_570
) {
4475 for (i
= 0; i
< 8; i
++) {
4476 status
= led_get_status(i
);
4479 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
4480 i
, str_led_status(status
));
4484 len
+= sprintf(p
+ len
, "commands:\t"
4485 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
4490 static int led_write(char *buf
)
4494 enum led_status_t s
;
4499 while ((cmd
= next_cmd(&buf
))) {
4500 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
4503 if (strstr(cmd
, "off")) {
4505 } else if (strstr(cmd
, "on")) {
4507 } else if (strstr(cmd
, "blink")) {
4508 s
= TPACPI_LED_BLINK
;
4513 rc
= led_set_status(led
, s
);
4521 static struct ibm_struct led_driver_data
= {
4528 /*************************************************************************
4532 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
4534 static int __init
beep_init(struct ibm_init_struct
*iibm
)
4536 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
4538 TPACPI_ACPIHANDLE_INIT(beep
);
4540 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
4541 str_supported(beep_handle
!= NULL
));
4543 return (beep_handle
)? 0 : 1;
4546 static int beep_read(char *p
)
4551 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4553 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4554 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
4560 static int beep_write(char *buf
)
4568 while ((cmd
= next_cmd(&buf
))) {
4569 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
4570 beep_cmd
>= 0 && beep_cmd
<= 17) {
4574 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
4581 static struct ibm_struct beep_driver_data
= {
4584 .write
= beep_write
,
4587 /*************************************************************************
4591 enum thermal_access_mode
{
4592 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
4593 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
4594 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
4595 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
4596 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
4599 enum { /* TPACPI_THERMAL_TPEC_* */
4600 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
4601 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
4602 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
4605 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
4606 struct ibm_thermal_sensors_struct
{
4607 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
4610 static enum thermal_access_mode thermal_read_mode
;
4612 /* idx is zero-based */
4613 static int thermal_get_sensor(int idx
, s32
*value
)
4619 t
= TP_EC_THERMAL_TMP0
;
4621 switch (thermal_read_mode
) {
4622 #if TPACPI_MAX_THERMAL_SENSORS >= 16
4623 case TPACPI_THERMAL_TPEC_16
:
4624 if (idx
>= 8 && idx
<= 15) {
4625 t
= TP_EC_THERMAL_TMP8
;
4630 case TPACPI_THERMAL_TPEC_8
:
4632 if (!acpi_ec_read(t
+ idx
, &tmp
))
4634 *value
= tmp
* 1000;
4639 case TPACPI_THERMAL_ACPI_UPDT
:
4641 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4642 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
4644 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
4646 *value
= (t
- 2732) * 100;
4651 case TPACPI_THERMAL_ACPI_TMP07
:
4653 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4654 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
4656 if (t
> 127 || t
< -127)
4657 t
= TP_EC_THERMAL_TMP_NA
;
4663 case TPACPI_THERMAL_NONE
:
4671 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
4682 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
4685 for (i
= 0 ; i
< n
; i
++) {
4686 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
4694 /* sysfs temp##_input -------------------------------------------------- */
4696 static ssize_t
thermal_temp_input_show(struct device
*dev
,
4697 struct device_attribute
*attr
,
4700 struct sensor_device_attribute
*sensor_attr
=
4701 to_sensor_dev_attr(attr
);
4702 int idx
= sensor_attr
->index
;
4706 res
= thermal_get_sensor(idx
, &value
);
4709 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
4712 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
4715 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
4716 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
4717 thermal_temp_input_show, NULL, _idxB)
4719 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
4720 THERMAL_SENSOR_ATTR_TEMP(1, 0),
4721 THERMAL_SENSOR_ATTR_TEMP(2, 1),
4722 THERMAL_SENSOR_ATTR_TEMP(3, 2),
4723 THERMAL_SENSOR_ATTR_TEMP(4, 3),
4724 THERMAL_SENSOR_ATTR_TEMP(5, 4),
4725 THERMAL_SENSOR_ATTR_TEMP(6, 5),
4726 THERMAL_SENSOR_ATTR_TEMP(7, 6),
4727 THERMAL_SENSOR_ATTR_TEMP(8, 7),
4728 THERMAL_SENSOR_ATTR_TEMP(9, 8),
4729 THERMAL_SENSOR_ATTR_TEMP(10, 9),
4730 THERMAL_SENSOR_ATTR_TEMP(11, 10),
4731 THERMAL_SENSOR_ATTR_TEMP(12, 11),
4732 THERMAL_SENSOR_ATTR_TEMP(13, 12),
4733 THERMAL_SENSOR_ATTR_TEMP(14, 13),
4734 THERMAL_SENSOR_ATTR_TEMP(15, 14),
4735 THERMAL_SENSOR_ATTR_TEMP(16, 15),
4738 #define THERMAL_ATTRS(X) \
4739 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
4741 static struct attribute
*thermal_temp_input_attr
[] = {
4761 static const struct attribute_group thermal_temp_input16_group
= {
4762 .attrs
= thermal_temp_input_attr
4765 static const struct attribute_group thermal_temp_input8_group
= {
4766 .attrs
= &thermal_temp_input_attr
[8]
4769 #undef THERMAL_SENSOR_ATTR_TEMP
4770 #undef THERMAL_ATTRS
4772 /* --------------------------------------------------------------------- */
4774 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
4781 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
4783 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
4785 if (thinkpad_id
.ec_model
) {
4787 * Direct EC access mode: sensors at registers
4788 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
4789 * non-implemented, thermal sensors return 0x80 when
4794 for (i
= 0; i
< 8; i
++) {
4795 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
4801 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
4809 /* This is sheer paranoia, but we handle it anyway */
4812 "ThinkPad ACPI EC access misbehaving, "
4813 "falling back to ACPI TMPx access "
4815 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4818 "ThinkPad ACPI EC access misbehaving, "
4819 "disabling thermal sensors access\n");
4820 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4825 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
4827 } else if (acpi_tmp7
) {
4828 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
4829 /* 600e/x, 770e, 770x */
4830 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
4832 /* Standard ACPI TMPx access, max 8 sensors */
4833 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4836 /* temperatures not supported on 570, G4x, R30, R31, R32 */
4837 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4840 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
4841 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
4844 switch (thermal_read_mode
) {
4845 case TPACPI_THERMAL_TPEC_16
:
4846 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4847 &thermal_temp_input16_group
);
4851 case TPACPI_THERMAL_TPEC_8
:
4852 case TPACPI_THERMAL_ACPI_TMP07
:
4853 case TPACPI_THERMAL_ACPI_UPDT
:
4854 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4855 &thermal_temp_input8_group
);
4859 case TPACPI_THERMAL_NONE
:
4867 static void thermal_exit(void)
4869 switch (thermal_read_mode
) {
4870 case TPACPI_THERMAL_TPEC_16
:
4871 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4872 &thermal_temp_input16_group
);
4874 case TPACPI_THERMAL_TPEC_8
:
4875 case TPACPI_THERMAL_ACPI_TMP07
:
4876 case TPACPI_THERMAL_ACPI_UPDT
:
4877 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4878 &thermal_temp_input16_group
);
4880 case TPACPI_THERMAL_NONE
:
4886 static int thermal_read(char *p
)
4890 struct ibm_thermal_sensors_struct t
;
4892 n
= thermal_get_sensors(&t
);
4893 if (unlikely(n
< 0))
4896 len
+= sprintf(p
+ len
, "temperatures:\t");
4899 for (i
= 0; i
< (n
- 1); i
++)
4900 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
4901 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
4903 len
+= sprintf(p
+ len
, "not supported\n");
4908 static struct ibm_struct thermal_driver_data
= {
4910 .read
= thermal_read
,
4911 .exit
= thermal_exit
,
4914 /*************************************************************************
4918 static u8 ecdump_regs
[256];
4920 static int ecdump_read(char *p
)
4926 len
+= sprintf(p
+ len
, "EC "
4927 " +00 +01 +02 +03 +04 +05 +06 +07"
4928 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
4929 for (i
= 0; i
< 256; i
+= 16) {
4930 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
4931 for (j
= 0; j
< 16; j
++) {
4932 if (!acpi_ec_read(i
+ j
, &v
))
4934 if (v
!= ecdump_regs
[i
+ j
])
4935 len
+= sprintf(p
+ len
, " *%02x", v
);
4937 len
+= sprintf(p
+ len
, " %02x", v
);
4938 ecdump_regs
[i
+ j
] = v
;
4940 len
+= sprintf(p
+ len
, "\n");
4945 /* These are way too dangerous to advertise openly... */
4947 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
4948 " (<offset> is 00-ff, <value> is 00-ff)\n");
4949 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
4950 " (<offset> is 00-ff, <value> is 0-255)\n");
4955 static int ecdump_write(char *buf
)
4960 while ((cmd
= next_cmd(&buf
))) {
4961 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
4963 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
4967 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
4968 if (!acpi_ec_write(i
, v
))
4977 static struct ibm_struct ecdump_driver_data
= {
4979 .read
= ecdump_read
,
4980 .write
= ecdump_write
,
4981 .flags
.experimental
= 1,
4984 /*************************************************************************
4985 * Backlight/brightness subdriver
4988 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
4991 TP_EC_BACKLIGHT
= 0x31,
4993 /* TP_EC_BACKLIGHT bitmasks */
4994 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
4995 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
4996 TP_EC_BACKLIGHT_MAPSW
= 0x20,
4999 static struct backlight_device
*ibm_backlight_device
;
5000 static int brightness_mode
;
5001 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5003 static struct mutex brightness_mutex
;
5006 * ThinkPads can read brightness from two places: EC 0x31, or
5007 * CMOS NVRAM byte 0x5E, bits 0-3.
5009 * EC 0x31 has the following layout
5010 * Bit 7: unknown function
5011 * Bit 6: unknown function
5012 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5013 * Bit 4: must be set to zero to avoid problems
5014 * Bit 3-0: backlight brightness level
5016 * brightness_get_raw returns status data in the EC 0x31 layout
5018 static int brightness_get_raw(int *status
)
5020 u8 lec
= 0, lcmos
= 0, level
= 0;
5022 if (brightness_mode
& 1) {
5023 if (!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
))
5025 level
= lec
& TP_EC_BACKLIGHT_LVLMSK
;
5027 if (brightness_mode
& 2) {
5028 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5029 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5030 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5031 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
5035 if (brightness_mode
== 3) {
5036 *status
= lec
; /* Prefer EC, CMOS is just a backing store */
5037 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5039 tp_warned
.bright_cmos_ec_unsync
= 0;
5041 if (!tp_warned
.bright_cmos_ec_unsync
) {
5043 "CMOS NVRAM (%u) and EC (%u) do not "
5044 "agree on display brightness level\n",
5045 (unsigned int) lcmos
,
5046 (unsigned int) lec
);
5047 tp_warned
.bright_cmos_ec_unsync
= 1;
5058 /* May return EINTR which can always be mapped to ERESTARTSYS */
5059 static int brightness_set(int value
)
5061 int cmos_cmd
, inc
, i
, res
;
5065 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
5069 res
= mutex_lock_interruptible(&brightness_mutex
);
5073 res
= brightness_get_raw(¤t_value
);
5077 command_bits
= current_value
& TP_EC_BACKLIGHT_CMDMSK
;
5078 current_value
&= TP_EC_BACKLIGHT_LVLMSK
;
5080 cmos_cmd
= value
> current_value
?
5081 TP_CMOS_BRIGHTNESS_UP
:
5082 TP_CMOS_BRIGHTNESS_DOWN
;
5083 inc
= (value
> current_value
)? 1 : -1;
5086 for (i
= current_value
; i
!= value
; i
+= inc
) {
5087 if ((brightness_mode
& 2) &&
5088 issue_thinkpad_cmos_command(cmos_cmd
)) {
5092 if ((brightness_mode
& 1) &&
5093 !acpi_ec_write(TP_EC_BACKLIGHT
,
5094 (i
+ inc
) | command_bits
)) {
5101 mutex_unlock(&brightness_mutex
);
5105 /* sysfs backlight class ----------------------------------------------- */
5107 static int brightness_update_status(struct backlight_device
*bd
)
5109 /* it is the backlight class's job (caller) to handle
5110 * EINTR and other errors properly */
5111 return brightness_set(
5112 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
5113 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
5114 bd
->props
.brightness
: 0);
5117 static int brightness_get(struct backlight_device
*bd
)
5121 res
= brightness_get_raw(&status
);
5123 return 0; /* FIXME: teach backlight about error handling */
5125 return status
& TP_EC_BACKLIGHT_LVLMSK
;
5128 static struct backlight_ops ibm_backlight_data
= {
5129 .get_brightness
= brightness_get
,
5130 .update_status
= brightness_update_status
,
5133 /* --------------------------------------------------------------------- */
5135 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
5139 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
5141 mutex_init(&brightness_mutex
);
5144 * We always attempt to detect acpi support, so as to switch
5145 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
5146 * going to publish a backlight interface
5148 b
= tpacpi_check_std_acpi_brightness_support();
5151 if (acpi_video_backlight_support()) {
5152 if (brightness_enable
> 1) {
5153 printk(TPACPI_NOTICE
5154 "Standard ACPI backlight interface "
5155 "available, not loading native one.\n");
5157 } else if (brightness_enable
== 1) {
5158 printk(TPACPI_NOTICE
5159 "Backlight control force enabled, even if standard "
5160 "ACPI backlight interface is available\n");
5163 if (brightness_enable
> 1) {
5164 printk(TPACPI_NOTICE
5165 "Standard ACPI backlight interface not "
5166 "available, thinkpad_acpi native "
5167 "brightness control enabled\n");
5172 if (!brightness_enable
) {
5173 dbg_printk(TPACPI_DBG_INIT
,
5174 "brightness support disabled by "
5175 "module parameter\n");
5181 "Unsupported brightness interface, "
5182 "please contact %s\n", TPACPI_MAIL
);
5186 tp_features
.bright_16levels
= 1;
5188 if (!brightness_mode
) {
5189 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
5190 brightness_mode
= 2;
5192 brightness_mode
= 3;
5194 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
5198 if (brightness_mode
> 3)
5201 if (brightness_get_raw(&b
) < 0)
5204 if (tp_features
.bright_16levels
)
5206 "detected a 16-level brightness capable ThinkPad\n");
5208 ibm_backlight_device
= backlight_device_register(
5209 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
5210 &ibm_backlight_data
);
5211 if (IS_ERR(ibm_backlight_device
)) {
5212 printk(TPACPI_ERR
"Could not register backlight device\n");
5213 return PTR_ERR(ibm_backlight_device
);
5215 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
5217 ibm_backlight_device
->props
.max_brightness
=
5218 (tp_features
.bright_16levels
)? 15 : 7;
5219 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
5220 backlight_update_status(ibm_backlight_device
);
5225 static void brightness_exit(void)
5227 if (ibm_backlight_device
) {
5228 vdbg_printk(TPACPI_DBG_EXIT
,
5229 "calling backlight_device_unregister()\n");
5230 backlight_device_unregister(ibm_backlight_device
);
5234 static int brightness_read(char *p
)
5239 level
= brightness_get(NULL
);
5241 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5243 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
5244 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
5245 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5246 " (<level> is 0-%d)\n",
5247 (tp_features
.bright_16levels
) ? 15 : 7);
5253 static int brightness_write(char *buf
)
5258 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
5260 level
= brightness_get(NULL
);
5264 while ((cmd
= next_cmd(&buf
))) {
5265 if (strlencmp(cmd
, "up") == 0) {
5266 if (level
< max_level
)
5268 } else if (strlencmp(cmd
, "down") == 0) {
5271 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
5272 level
>= 0 && level
<= max_level
) {
5279 * Now we know what the final level should be, so we try to set it.
5280 * Doing it this way makes the syscall restartable in case of EINTR
5282 rc
= brightness_set(level
);
5283 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
5286 static struct ibm_struct brightness_driver_data
= {
5287 .name
= "brightness",
5288 .read
= brightness_read
,
5289 .write
= brightness_write
,
5290 .exit
= brightness_exit
,
5293 /*************************************************************************
5297 static int volume_offset
= 0x30;
5299 static int volume_read(char *p
)
5304 if (!acpi_ec_read(volume_offset
, &level
)) {
5305 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5307 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
5308 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
5309 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
5310 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5311 " (<level> is 0-15)\n");
5317 static int volume_write(char *buf
)
5319 int cmos_cmd
, inc
, i
;
5321 int new_level
, new_mute
;
5324 while ((cmd
= next_cmd(&buf
))) {
5325 if (!acpi_ec_read(volume_offset
, &level
))
5327 new_mute
= mute
= level
& 0x40;
5328 new_level
= level
= level
& 0xf;
5330 if (strlencmp(cmd
, "up") == 0) {
5334 new_level
= level
== 15 ? 15 : level
+ 1;
5335 } else if (strlencmp(cmd
, "down") == 0) {
5339 new_level
= level
== 0 ? 0 : level
- 1;
5340 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
5341 new_level
>= 0 && new_level
<= 15) {
5343 } else if (strlencmp(cmd
, "mute") == 0) {
5348 if (new_level
!= level
) {
5349 /* mute doesn't change */
5351 cmos_cmd
= (new_level
> level
) ?
5352 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
5353 inc
= new_level
> level
? 1 : -1;
5355 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
5356 !acpi_ec_write(volume_offset
, level
)))
5359 for (i
= level
; i
!= new_level
; i
+= inc
)
5360 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5361 !acpi_ec_write(volume_offset
, i
+ inc
))
5365 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
5366 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
5371 if (new_mute
!= mute
) {
5372 /* level doesn't change */
5374 cmos_cmd
= (new_mute
) ?
5375 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
5377 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5378 !acpi_ec_write(volume_offset
, level
+ new_mute
))
5386 static struct ibm_struct volume_driver_data
= {
5388 .read
= volume_read
,
5389 .write
= volume_write
,
5392 /*************************************************************************
5399 * TPACPI_FAN_RD_ACPI_GFAN:
5400 * ACPI GFAN method: returns fan level
5402 * see TPACPI_FAN_WR_ACPI_SFAN
5403 * EC 0x2f (HFSP) not available if GFAN exists
5405 * TPACPI_FAN_WR_ACPI_SFAN:
5406 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
5408 * EC 0x2f (HFSP) might be available *for reading*, but do not use
5411 * TPACPI_FAN_WR_TPEC:
5412 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
5413 * Supported on almost all ThinkPads
5415 * Fan speed changes of any sort (including those caused by the
5416 * disengaged mode) are usually done slowly by the firmware as the
5417 * maximum ammount of fan duty cycle change per second seems to be
5420 * Reading is not available if GFAN exists.
5421 * Writing is not available if SFAN exists.
5424 * 7 automatic mode engaged;
5425 * (default operation mode of the ThinkPad)
5426 * fan level is ignored in this mode.
5427 * 6 full speed mode (takes precedence over bit 7);
5428 * not available on all thinkpads. May disable
5429 * the tachometer while the fan controller ramps up
5430 * the speed (which can take up to a few *minutes*).
5431 * Speeds up fan to 100% duty-cycle, which is far above
5432 * the standard RPM levels. It is not impossible that
5433 * it could cause hardware damage.
5434 * 5-3 unused in some models. Extra bits for fan level
5435 * in others, but still useless as all values above
5436 * 7 map to the same speed as level 7 in these models.
5437 * 2-0 fan level (0..7 usually)
5439 * 0x07 = max (set when temperatures critical)
5440 * Some ThinkPads may have other levels, see
5441 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
5443 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
5444 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
5445 * does so, its initial value is meaningless (0x07).
5447 * For firmware bugs, refer to:
5448 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5452 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
5453 * Main fan tachometer reading (in RPM)
5455 * This register is present on all ThinkPads with a new-style EC, and
5456 * it is known not to be present on the A21m/e, and T22, as there is
5457 * something else in offset 0x84 according to the ACPI DSDT. Other
5458 * ThinkPads from this same time period (and earlier) probably lack the
5459 * tachometer as well.
5461 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
5462 * was never fixed by IBM to report the EC firmware version string
5463 * probably support the tachometer (like the early X models), so
5464 * detecting it is quite hard. We need more data to know for sure.
5466 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
5469 * FIRMWARE BUG: may go stale while the EC is switching to full speed
5472 * For firmware bugs, refer to:
5473 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5475 * TPACPI_FAN_WR_ACPI_FANS:
5476 * ThinkPad X31, X40, X41. Not available in the X60.
5478 * FANS ACPI handle: takes three arguments: low speed, medium speed,
5479 * high speed. ACPI DSDT seems to map these three speeds to levels
5480 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
5481 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
5483 * The speeds are stored on handles
5484 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
5486 * There are three default speed sets, acessible as handles:
5487 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
5489 * ACPI DSDT switches which set is in use depending on various
5492 * TPACPI_FAN_WR_TPEC is also available and should be used to
5493 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
5494 * but the ACPI tables just mention level 7.
5497 enum { /* Fan control constants */
5498 fan_status_offset
= 0x2f, /* EC register 0x2f */
5499 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
5500 * 0x84 must be read before 0x85 */
5502 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
5503 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
5505 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
5508 enum fan_status_access_mode
{
5509 TPACPI_FAN_NONE
= 0, /* No fan status or control */
5510 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
5511 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
5514 enum fan_control_access_mode
{
5515 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
5516 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
5517 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
5518 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
5521 enum fan_control_commands
{
5522 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
5523 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
5524 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
5525 * and also watchdog cmd */
5528 static int fan_control_allowed
;
5530 static enum fan_status_access_mode fan_status_access_mode
;
5531 static enum fan_control_access_mode fan_control_access_mode
;
5532 static enum fan_control_commands fan_control_commands
;
5534 static u8 fan_control_initial_status
;
5535 static u8 fan_control_desired_level
;
5536 static u8 fan_control_resume_level
;
5537 static int fan_watchdog_maxinterval
;
5539 static struct mutex fan_mutex
;
5541 static void fan_watchdog_fire(struct work_struct
*ignored
);
5542 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
5544 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
5545 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
5546 "\\FSPD", /* 600e/x, 770e, 770x */
5548 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
5549 "JFNS", /* 770x-JL */
5553 * Call with fan_mutex held
5555 static void fan_update_desired_level(u8 status
)
5558 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5560 fan_control_desired_level
= 7;
5562 fan_control_desired_level
= status
;
5566 static int fan_get_status(u8
*status
)
5571 * Add TPACPI_FAN_RD_ACPI_FANS ? */
5573 switch (fan_status_access_mode
) {
5574 case TPACPI_FAN_RD_ACPI_GFAN
:
5575 /* 570, 600e/x, 770e, 770x */
5577 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
5585 case TPACPI_FAN_RD_TPEC
:
5586 /* all except 570, 600e/x, 770e, 770x */
5587 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
5602 static int fan_get_status_safe(u8
*status
)
5607 if (mutex_lock_interruptible(&fan_mutex
))
5608 return -ERESTARTSYS
;
5609 rc
= fan_get_status(&s
);
5611 fan_update_desired_level(s
);
5612 mutex_unlock(&fan_mutex
);
5620 static int fan_get_speed(unsigned int *speed
)
5624 switch (fan_status_access_mode
) {
5625 case TPACPI_FAN_RD_TPEC
:
5626 /* all except 570, 600e/x, 770e, 770x */
5627 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
5628 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
5632 *speed
= (hi
<< 8) | lo
;
5643 static int fan_set_level(int level
)
5645 if (!fan_control_allowed
)
5648 switch (fan_control_access_mode
) {
5649 case TPACPI_FAN_WR_ACPI_SFAN
:
5650 if (level
>= 0 && level
<= 7) {
5651 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
5657 case TPACPI_FAN_WR_ACPI_FANS
:
5658 case TPACPI_FAN_WR_TPEC
:
5659 if (!(level
& TP_EC_FAN_AUTO
) &&
5660 !(level
& TP_EC_FAN_FULLSPEED
) &&
5661 ((level
< 0) || (level
> 7)))
5664 /* safety net should the EC not support AUTO
5665 * or FULLSPEED mode bits and just ignore them */
5666 if (level
& TP_EC_FAN_FULLSPEED
)
5667 level
|= 7; /* safety min speed 7 */
5668 else if (level
& TP_EC_FAN_AUTO
)
5669 level
|= 4; /* safety min speed 4 */
5671 if (!acpi_ec_write(fan_status_offset
, level
))
5674 tp_features
.fan_ctrl_status_undef
= 0;
5683 static int fan_set_level_safe(int level
)
5687 if (!fan_control_allowed
)
5690 if (mutex_lock_interruptible(&fan_mutex
))
5691 return -ERESTARTSYS
;
5693 if (level
== TPACPI_FAN_LAST_LEVEL
)
5694 level
= fan_control_desired_level
;
5696 rc
= fan_set_level(level
);
5698 fan_update_desired_level(level
);
5700 mutex_unlock(&fan_mutex
);
5704 static int fan_set_enable(void)
5709 if (!fan_control_allowed
)
5712 if (mutex_lock_interruptible(&fan_mutex
))
5713 return -ERESTARTSYS
;
5715 switch (fan_control_access_mode
) {
5716 case TPACPI_FAN_WR_ACPI_FANS
:
5717 case TPACPI_FAN_WR_TPEC
:
5718 rc
= fan_get_status(&s
);
5722 /* Don't go out of emergency fan mode */
5725 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
5728 if (!acpi_ec_write(fan_status_offset
, s
))
5731 tp_features
.fan_ctrl_status_undef
= 0;
5736 case TPACPI_FAN_WR_ACPI_SFAN
:
5737 rc
= fan_get_status(&s
);
5743 /* Set fan to at least level 4 */
5746 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
5756 mutex_unlock(&fan_mutex
);
5760 static int fan_set_disable(void)
5764 if (!fan_control_allowed
)
5767 if (mutex_lock_interruptible(&fan_mutex
))
5768 return -ERESTARTSYS
;
5771 switch (fan_control_access_mode
) {
5772 case TPACPI_FAN_WR_ACPI_FANS
:
5773 case TPACPI_FAN_WR_TPEC
:
5774 if (!acpi_ec_write(fan_status_offset
, 0x00))
5777 fan_control_desired_level
= 0;
5778 tp_features
.fan_ctrl_status_undef
= 0;
5782 case TPACPI_FAN_WR_ACPI_SFAN
:
5783 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
5786 fan_control_desired_level
= 0;
5794 mutex_unlock(&fan_mutex
);
5798 static int fan_set_speed(int speed
)
5802 if (!fan_control_allowed
)
5805 if (mutex_lock_interruptible(&fan_mutex
))
5806 return -ERESTARTSYS
;
5809 switch (fan_control_access_mode
) {
5810 case TPACPI_FAN_WR_ACPI_FANS
:
5811 if (speed
>= 0 && speed
<= 65535) {
5812 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
5813 speed
, speed
, speed
))
5823 mutex_unlock(&fan_mutex
);
5827 static void fan_watchdog_reset(void)
5829 static int fan_watchdog_active
;
5831 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
5834 if (fan_watchdog_active
)
5835 cancel_delayed_work(&fan_watchdog_task
);
5837 if (fan_watchdog_maxinterval
> 0 &&
5838 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
5839 fan_watchdog_active
= 1;
5840 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
5841 msecs_to_jiffies(fan_watchdog_maxinterval
5844 "failed to queue the fan watchdog, "
5845 "watchdog will not trigger\n");
5848 fan_watchdog_active
= 0;
5851 static void fan_watchdog_fire(struct work_struct
*ignored
)
5855 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
5858 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
5859 rc
= fan_set_enable();
5861 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
5862 "will try again later...\n", -rc
);
5863 /* reschedule for later */
5864 fan_watchdog_reset();
5869 * SYSFS fan layout: hwmon compatible (device)
5872 * 0: "disengaged" mode
5874 * 2: native EC "auto" mode (recommended, hardware default)
5876 * pwm*: set speed in manual mode, ignored otherwise.
5877 * 0 is level 0; 255 is level 7. Intermediate points done with linear
5880 * fan*_input: tachometer reading, RPM
5883 * SYSFS fan layout: extensions
5885 * fan_watchdog (driver):
5886 * fan watchdog interval in seconds, 0 disables (default), max 120
5889 /* sysfs fan pwm1_enable ----------------------------------------------- */
5890 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
5891 struct device_attribute
*attr
,
5897 res
= fan_get_status_safe(&status
);
5901 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5902 if (status
!= fan_control_initial_status
) {
5903 tp_features
.fan_ctrl_status_undef
= 0;
5905 /* Return most likely status. In fact, it
5906 * might be the only possible status */
5907 status
= TP_EC_FAN_AUTO
;
5911 if (status
& TP_EC_FAN_FULLSPEED
) {
5913 } else if (status
& TP_EC_FAN_AUTO
) {
5918 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
5921 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
5922 struct device_attribute
*attr
,
5923 const char *buf
, size_t count
)
5928 if (parse_strtoul(buf
, 2, &t
))
5933 level
= TP_EC_FAN_FULLSPEED
;
5936 level
= TPACPI_FAN_LAST_LEVEL
;
5939 level
= TP_EC_FAN_AUTO
;
5942 /* reserved for software-controlled auto mode */
5948 res
= fan_set_level_safe(level
);
5954 fan_watchdog_reset();
5959 static struct device_attribute dev_attr_fan_pwm1_enable
=
5960 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
5961 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
5963 /* sysfs fan pwm1 ------------------------------------------------------ */
5964 static ssize_t
fan_pwm1_show(struct device
*dev
,
5965 struct device_attribute
*attr
,
5971 res
= fan_get_status_safe(&status
);
5975 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5976 if (status
!= fan_control_initial_status
) {
5977 tp_features
.fan_ctrl_status_undef
= 0;
5979 status
= TP_EC_FAN_AUTO
;
5984 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
5985 status
= fan_control_desired_level
;
5990 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
5993 static ssize_t
fan_pwm1_store(struct device
*dev
,
5994 struct device_attribute
*attr
,
5995 const char *buf
, size_t count
)
5999 u8 status
, newlevel
;
6001 if (parse_strtoul(buf
, 255, &s
))
6004 /* scale down from 0-255 to 0-7 */
6005 newlevel
= (s
>> 5) & 0x07;
6007 if (mutex_lock_interruptible(&fan_mutex
))
6008 return -ERESTARTSYS
;
6010 rc
= fan_get_status(&status
);
6011 if (!rc
&& (status
&
6012 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6013 rc
= fan_set_level(newlevel
);
6017 fan_update_desired_level(newlevel
);
6018 fan_watchdog_reset();
6022 mutex_unlock(&fan_mutex
);
6023 return (rc
)? rc
: count
;
6026 static struct device_attribute dev_attr_fan_pwm1
=
6027 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
6028 fan_pwm1_show
, fan_pwm1_store
);
6030 /* sysfs fan fan1_input ------------------------------------------------ */
6031 static ssize_t
fan_fan1_input_show(struct device
*dev
,
6032 struct device_attribute
*attr
,
6038 res
= fan_get_speed(&speed
);
6042 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
6045 static struct device_attribute dev_attr_fan_fan1_input
=
6046 __ATTR(fan1_input
, S_IRUGO
,
6047 fan_fan1_input_show
, NULL
);
6049 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
6050 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
6053 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
6056 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
6057 const char *buf
, size_t count
)
6061 if (parse_strtoul(buf
, 120, &t
))
6064 if (!fan_control_allowed
)
6067 fan_watchdog_maxinterval
= t
;
6068 fan_watchdog_reset();
6073 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
6074 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
6076 /* --------------------------------------------------------------------- */
6077 static struct attribute
*fan_attributes
[] = {
6078 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
6079 &dev_attr_fan_fan1_input
.attr
,
6083 static const struct attribute_group fan_attr_group
= {
6084 .attrs
= fan_attributes
,
6087 static int __init
fan_init(struct ibm_init_struct
*iibm
)
6091 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
6093 mutex_init(&fan_mutex
);
6094 fan_status_access_mode
= TPACPI_FAN_NONE
;
6095 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6096 fan_control_commands
= 0;
6097 fan_watchdog_maxinterval
= 0;
6098 tp_features
.fan_ctrl_status_undef
= 0;
6099 fan_control_desired_level
= 7;
6101 TPACPI_ACPIHANDLE_INIT(fans
);
6102 TPACPI_ACPIHANDLE_INIT(gfan
);
6103 TPACPI_ACPIHANDLE_INIT(sfan
);
6106 /* 570, 600e/x, 770e, 770x */
6107 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
6109 /* all other ThinkPads: note that even old-style
6110 * ThinkPad ECs supports the fan control register */
6111 if (likely(acpi_ec_read(fan_status_offset
,
6112 &fan_control_initial_status
))) {
6113 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
6115 /* In some ThinkPads, neither the EC nor the ACPI
6116 * DSDT initialize the fan status, and it ends up
6117 * being set to 0x07 when it *could* be either
6120 * Enable for TP-1Y (T43), TP-78 (R51e),
6121 * TP-76 (R52), TP-70 (T43, R52), which are known
6123 if (fan_control_initial_status
== 0x07) {
6124 switch (thinkpad_id
.ec_model
) {
6125 case 0x5931: /* TP-1Y */
6126 case 0x3837: /* TP-78 */
6127 case 0x3637: /* TP-76 */
6128 case 0x3037: /* TP-70 */
6129 printk(TPACPI_NOTICE
6130 "fan_init: initial fan status "
6131 "is unknown, assuming it is "
6133 tp_features
.fan_ctrl_status_undef
= 1;
6139 "ThinkPad ACPI EC access misbehaving, "
6140 "fan status and control unavailable\n");
6147 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
6148 fan_control_commands
|=
6149 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
6152 /* gfan without sfan means no fan control */
6153 /* all other models implement TP EC 0x2f control */
6157 fan_control_access_mode
=
6158 TPACPI_FAN_WR_ACPI_FANS
;
6159 fan_control_commands
|=
6160 TPACPI_FAN_CMD_SPEED
|
6161 TPACPI_FAN_CMD_LEVEL
|
6162 TPACPI_FAN_CMD_ENABLE
;
6164 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
6165 fan_control_commands
|=
6166 TPACPI_FAN_CMD_LEVEL
|
6167 TPACPI_FAN_CMD_ENABLE
;
6172 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
6173 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
6174 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
6175 fan_status_access_mode
, fan_control_access_mode
);
6177 /* fan control master switch */
6178 if (!fan_control_allowed
) {
6179 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6180 fan_control_commands
= 0;
6181 dbg_printk(TPACPI_DBG_INIT
,
6182 "fan control features disabled by parameter\n");
6185 /* update fan_control_desired_level */
6186 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
6187 fan_get_status_safe(NULL
);
6189 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
6190 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
6191 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6196 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
6197 &driver_attr_fan_watchdog
);
6199 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6208 static void fan_exit(void)
6210 vdbg_printk(TPACPI_DBG_EXIT
,
6211 "cancelling any pending fan watchdog tasks\n");
6213 /* FIXME: can we really do this unconditionally? */
6214 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
6215 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
6216 &driver_attr_fan_watchdog
);
6218 cancel_delayed_work(&fan_watchdog_task
);
6219 flush_workqueue(tpacpi_wq
);
6222 static void fan_suspend(pm_message_t state
)
6226 if (!fan_control_allowed
)
6229 /* Store fan status in cache */
6230 fan_control_resume_level
= 0;
6231 rc
= fan_get_status_safe(&fan_control_resume_level
);
6233 printk(TPACPI_NOTICE
6234 "failed to read fan level for later "
6235 "restore during resume: %d\n", rc
);
6237 /* if it is undefined, don't attempt to restore it.
6239 if (tp_features
.fan_ctrl_status_undef
)
6240 fan_control_resume_level
= 0;
6243 static void fan_resume(void)
6245 u8 current_level
= 7;
6246 bool do_set
= false;
6249 /* DSDT *always* updates status on resume */
6250 tp_features
.fan_ctrl_status_undef
= 0;
6252 if (!fan_control_allowed
||
6253 !fan_control_resume_level
||
6254 (fan_get_status_safe(¤t_level
) < 0))
6257 switch (fan_control_access_mode
) {
6258 case TPACPI_FAN_WR_ACPI_SFAN
:
6259 /* never decrease fan level */
6260 do_set
= (fan_control_resume_level
> current_level
);
6262 case TPACPI_FAN_WR_ACPI_FANS
:
6263 case TPACPI_FAN_WR_TPEC
:
6264 /* never decrease fan level, scale is:
6265 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
6267 * We expect the firmware to set either 7 or AUTO, but we
6268 * handle FULLSPEED out of paranoia.
6270 * So, we can safely only restore FULLSPEED or 7, anything
6271 * else could slow the fan. Restoring AUTO is useless, at
6272 * best that's exactly what the DSDT already set (it is the
6275 * Always keep in mind that the DSDT *will* have set the
6276 * fans to what the vendor supposes is the best level. We
6277 * muck with it only to speed the fan up.
6279 if (fan_control_resume_level
!= 7 &&
6280 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
6283 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
6284 (current_level
!= fan_control_resume_level
);
6290 printk(TPACPI_NOTICE
6291 "restoring fan level to 0x%02x\n",
6292 fan_control_resume_level
);
6293 rc
= fan_set_level_safe(fan_control_resume_level
);
6295 printk(TPACPI_NOTICE
6296 "failed to restore fan level: %d\n", rc
);
6300 static int fan_read(char *p
)
6305 unsigned int speed
= 0;
6307 switch (fan_status_access_mode
) {
6308 case TPACPI_FAN_RD_ACPI_GFAN
:
6309 /* 570, 600e/x, 770e, 770x */
6310 rc
= fan_get_status_safe(&status
);
6314 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
6316 (status
!= 0) ? "enabled" : "disabled", status
);
6319 case TPACPI_FAN_RD_TPEC
:
6320 /* all except 570, 600e/x, 770e, 770x */
6321 rc
= fan_get_status_safe(&status
);
6325 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6326 if (status
!= fan_control_initial_status
)
6327 tp_features
.fan_ctrl_status_undef
= 0;
6329 /* Return most likely status. In fact, it
6330 * might be the only possible status */
6331 status
= TP_EC_FAN_AUTO
;
6334 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
6335 (status
!= 0) ? "enabled" : "disabled");
6337 rc
= fan_get_speed(&speed
);
6341 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
6343 if (status
& TP_EC_FAN_FULLSPEED
)
6344 /* Disengaged mode takes precedence */
6345 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
6346 else if (status
& TP_EC_FAN_AUTO
)
6347 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
6349 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
6352 case TPACPI_FAN_NONE
:
6354 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
6357 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
6358 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
6360 switch (fan_control_access_mode
) {
6361 case TPACPI_FAN_WR_ACPI_SFAN
:
6362 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
6366 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
6367 "auto, disengaged, full-speed)\n");
6372 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
6373 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
6374 "commands:\twatchdog <timeout> (<timeout> "
6375 "is 0 (off), 1-120 (seconds))\n");
6377 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
6378 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
6379 " (<speed> is 0-65535)\n");
6384 static int fan_write_cmd_level(const char *cmd
, int *rc
)
6388 if (strlencmp(cmd
, "level auto") == 0)
6389 level
= TP_EC_FAN_AUTO
;
6390 else if ((strlencmp(cmd
, "level disengaged") == 0) |
6391 (strlencmp(cmd
, "level full-speed") == 0))
6392 level
= TP_EC_FAN_FULLSPEED
;
6393 else if (sscanf(cmd
, "level %d", &level
) != 1)
6396 *rc
= fan_set_level_safe(level
);
6398 printk(TPACPI_ERR
"level command accepted for unsupported "
6399 "access mode %d", fan_control_access_mode
);
6404 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
6406 if (strlencmp(cmd
, "enable") != 0)
6409 *rc
= fan_set_enable();
6411 printk(TPACPI_ERR
"enable command accepted for unsupported "
6412 "access mode %d", fan_control_access_mode
);
6417 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
6419 if (strlencmp(cmd
, "disable") != 0)
6422 *rc
= fan_set_disable();
6424 printk(TPACPI_ERR
"disable command accepted for unsupported "
6425 "access mode %d", fan_control_access_mode
);
6430 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
6435 * Support speed <low> <medium> <high> ? */
6437 if (sscanf(cmd
, "speed %d", &speed
) != 1)
6440 *rc
= fan_set_speed(speed
);
6442 printk(TPACPI_ERR
"speed command accepted for unsupported "
6443 "access mode %d", fan_control_access_mode
);
6448 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
6452 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
6455 if (interval
< 0 || interval
> 120)
6458 fan_watchdog_maxinterval
= interval
;
6463 static int fan_write(char *buf
)
6468 while (!rc
&& (cmd
= next_cmd(&buf
))) {
6469 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
6470 fan_write_cmd_level(cmd
, &rc
)) &&
6471 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
6472 (fan_write_cmd_enable(cmd
, &rc
) ||
6473 fan_write_cmd_disable(cmd
, &rc
) ||
6474 fan_write_cmd_watchdog(cmd
, &rc
))) &&
6475 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
6476 fan_write_cmd_speed(cmd
, &rc
))
6480 fan_watchdog_reset();
6486 static struct ibm_struct fan_driver_data
= {
6491 .suspend
= fan_suspend
,
6492 .resume
= fan_resume
,
6495 /****************************************************************************
6496 ****************************************************************************
6500 ****************************************************************************
6501 ****************************************************************************/
6503 /* sysfs name ---------------------------------------------------------- */
6504 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
6505 struct device_attribute
*attr
,
6508 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
6511 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
6512 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
6514 /* --------------------------------------------------------------------- */
6517 static struct proc_dir_entry
*proc_dir
;
6520 * Module and infrastructure proble, init and exit handling
6523 static int force_load
;
6525 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
6526 static const char * __init
str_supported(int is_supported
)
6528 static char text_unsupported
[] __initdata
= "not supported";
6530 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
6532 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
6534 static void ibm_exit(struct ibm_struct
*ibm
)
6536 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
6538 list_del_init(&ibm
->all_drivers
);
6540 if (ibm
->flags
.acpi_notify_installed
) {
6541 dbg_printk(TPACPI_DBG_EXIT
,
6542 "%s: acpi_remove_notify_handler\n", ibm
->name
);
6544 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
6546 dispatch_acpi_notify
);
6547 ibm
->flags
.acpi_notify_installed
= 0;
6548 ibm
->flags
.acpi_notify_installed
= 0;
6551 if (ibm
->flags
.proc_created
) {
6552 dbg_printk(TPACPI_DBG_EXIT
,
6553 "%s: remove_proc_entry\n", ibm
->name
);
6554 remove_proc_entry(ibm
->name
, proc_dir
);
6555 ibm
->flags
.proc_created
= 0;
6558 if (ibm
->flags
.acpi_driver_registered
) {
6559 dbg_printk(TPACPI_DBG_EXIT
,
6560 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
6562 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
6563 kfree(ibm
->acpi
->driver
);
6564 ibm
->acpi
->driver
= NULL
;
6565 ibm
->flags
.acpi_driver_registered
= 0;
6568 if (ibm
->flags
.init_called
&& ibm
->exit
) {
6570 ibm
->flags
.init_called
= 0;
6573 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
6576 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
6579 struct ibm_struct
*ibm
= iibm
->data
;
6580 struct proc_dir_entry
*entry
;
6582 BUG_ON(ibm
== NULL
);
6584 INIT_LIST_HEAD(&ibm
->all_drivers
);
6586 if (ibm
->flags
.experimental
&& !experimental
)
6589 dbg_printk(TPACPI_DBG_INIT
,
6590 "probing for %s\n", ibm
->name
);
6593 ret
= iibm
->init(iibm
);
6595 return 0; /* probe failed */
6599 ibm
->flags
.init_called
= 1;
6603 if (ibm
->acpi
->hid
) {
6604 ret
= register_tpacpi_subdriver(ibm
);
6609 if (ibm
->acpi
->notify
) {
6610 ret
= setup_acpi_notify(ibm
);
6611 if (ret
== -ENODEV
) {
6612 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
6622 dbg_printk(TPACPI_DBG_INIT
,
6623 "%s installed\n", ibm
->name
);
6626 entry
= create_proc_entry(ibm
->name
,
6627 S_IFREG
| S_IRUGO
| S_IWUSR
,
6630 printk(TPACPI_ERR
"unable to create proc entry %s\n",
6635 entry
->owner
= THIS_MODULE
;
6637 entry
->read_proc
= &dispatch_procfs_read
;
6639 entry
->write_proc
= &dispatch_procfs_write
;
6640 ibm
->flags
.proc_created
= 1;
6643 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
6648 dbg_printk(TPACPI_DBG_INIT
,
6649 "%s: at error exit path with result %d\n",
6653 return (ret
< 0)? ret
: 0;
6658 /* returns 0 - probe ok, or < 0 - probe error.
6659 * Probe ok doesn't mean thinkpad found.
6660 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
6661 static int __must_check __init
get_thinkpad_model_data(
6662 struct thinkpad_id_data
*tp
)
6664 const struct dmi_device
*dev
= NULL
;
6665 char ec_fw_string
[18];
6671 memset(tp
, 0, sizeof(*tp
));
6673 if (dmi_name_in_vendors("IBM"))
6674 tp
->vendor
= PCI_VENDOR_ID_IBM
;
6675 else if (dmi_name_in_vendors("LENOVO"))
6676 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
6680 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
6681 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
6682 if (s
&& !tp
->bios_version_str
)
6684 if (!tp
->bios_version_str
)
6686 tp
->bios_model
= tp
->bios_version_str
[0]
6687 | (tp
->bios_version_str
[1] << 8);
6690 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
6691 * X32 or newer, all Z series; Some models must have an
6692 * up-to-date BIOS or they will not be detected.
6694 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6696 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
6697 if (sscanf(dev
->name
,
6698 "IBM ThinkPad Embedded Controller -[%17c",
6699 ec_fw_string
) == 1) {
6700 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
6701 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
6703 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
6704 if (!tp
->ec_version_str
)
6706 tp
->ec_model
= ec_fw_string
[0]
6707 | (ec_fw_string
[1] << 8);
6712 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
6713 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
6714 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
6719 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
6720 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
6721 if (s
&& !tp
->nummodel_str
)
6727 static int __init
probe_for_thinkpad(void)
6735 * Non-ancient models have better DMI tagging, but very old models
6738 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
6740 /* ec is required because many other handles are relative to it */
6741 TPACPI_ACPIHANDLE_INIT(ec
);
6745 "Not yet supported ThinkPad detected!\n");
6750 * Risks a regression on very old machines, but reduces potential
6751 * false positives a damn great deal
6754 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
6756 if (!is_thinkpad
&& !force_load
)
6763 /* Module init, exit, parameters */
6765 static struct ibm_init_struct ibms_init
[] __initdata
= {
6767 .init
= thinkpad_acpi_driver_init
,
6768 .data
= &thinkpad_acpi_driver_data
,
6771 .init
= hotkey_init
,
6772 .data
= &hotkey_driver_data
,
6775 .init
= bluetooth_init
,
6776 .data
= &bluetooth_driver_data
,
6780 .data
= &wan_driver_data
,
6782 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
6785 .data
= &video_driver_data
,
6790 .data
= &light_driver_data
,
6792 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6795 .data
= &dock_driver_data
[0],
6799 .data
= &dock_driver_data
[1],
6802 #ifdef CONFIG_THINKPAD_ACPI_BAY
6805 .data
= &bay_driver_data
,
6810 .data
= &cmos_driver_data
,
6814 .data
= &led_driver_data
,
6818 .data
= &beep_driver_data
,
6821 .init
= thermal_init
,
6822 .data
= &thermal_driver_data
,
6825 .data
= &ecdump_driver_data
,
6828 .init
= brightness_init
,
6829 .data
= &brightness_driver_data
,
6832 .data
= &volume_driver_data
,
6836 .data
= &fan_driver_data
,
6840 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
6843 struct ibm_struct
*ibm
;
6845 if (!kp
|| !kp
->name
|| !val
)
6848 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6849 ibm
= ibms_init
[i
].data
;
6850 WARN_ON(ibm
== NULL
);
6852 if (!ibm
|| !ibm
->name
)
6855 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
6856 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
6858 strcpy(ibms_init
[i
].param
, val
);
6859 strcat(ibms_init
[i
].param
, ",");
6867 module_param(experimental
, int, 0);
6868 MODULE_PARM_DESC(experimental
,
6869 "Enables experimental features when non-zero");
6871 module_param_named(debug
, dbg_level
, uint
, 0);
6872 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
6874 module_param(force_load
, bool, 0);
6875 MODULE_PARM_DESC(force_load
,
6876 "Attempts to load the driver even on a "
6877 "mis-identified ThinkPad when true");
6879 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
6880 MODULE_PARM_DESC(fan_control
,
6881 "Enables setting fan parameters features when true");
6883 module_param_named(brightness_mode
, brightness_mode
, int, 0);
6884 MODULE_PARM_DESC(brightness_mode
,
6885 "Selects brightness control strategy: "
6886 "0=auto, 1=EC, 2=CMOS, 3=both");
6888 module_param(brightness_enable
, uint
, 0);
6889 MODULE_PARM_DESC(brightness_enable
,
6890 "Enables backlight control when 1, disables when 0");
6892 module_param(hotkey_report_mode
, uint
, 0);
6893 MODULE_PARM_DESC(hotkey_report_mode
,
6894 "used for backwards compatibility with userspace, "
6895 "see documentation");
6897 #define TPACPI_PARAM(feature) \
6898 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
6899 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
6900 "at module load, see documentation")
6902 TPACPI_PARAM(hotkey
);
6903 TPACPI_PARAM(bluetooth
);
6904 TPACPI_PARAM(video
);
6905 TPACPI_PARAM(light
);
6906 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6909 #ifdef CONFIG_THINKPAD_ACPI_BAY
6911 #endif /* CONFIG_THINKPAD_ACPI_BAY */
6915 TPACPI_PARAM(ecdump
);
6916 TPACPI_PARAM(brightness
);
6917 TPACPI_PARAM(volume
);
6920 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
6921 module_param(dbg_wlswemul
, uint
, 0);
6922 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
6923 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
6924 MODULE_PARM_DESC(wlsw_state
,
6925 "Initial state of the emulated WLSW switch");
6927 module_param(dbg_bluetoothemul
, uint
, 0);
6928 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
6929 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
6930 MODULE_PARM_DESC(bluetooth_state
,
6931 "Initial state of the emulated bluetooth switch");
6933 module_param(dbg_wwanemul
, uint
, 0);
6934 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
6935 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
6936 MODULE_PARM_DESC(wwan_state
,
6937 "Initial state of the emulated WWAN switch");
6940 static void thinkpad_acpi_module_exit(void)
6942 struct ibm_struct
*ibm
, *itmp
;
6944 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
6946 list_for_each_entry_safe_reverse(ibm
, itmp
,
6947 &tpacpi_all_drivers
,
6952 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
6954 if (tpacpi_inputdev
) {
6955 if (tp_features
.input_device_registered
)
6956 input_unregister_device(tpacpi_inputdev
);
6958 input_free_device(tpacpi_inputdev
);
6962 hwmon_device_unregister(tpacpi_hwmon
);
6964 if (tp_features
.sensors_pdev_attrs_registered
)
6965 device_remove_file(&tpacpi_sensors_pdev
->dev
,
6966 &dev_attr_thinkpad_acpi_pdev_name
);
6967 if (tpacpi_sensors_pdev
)
6968 platform_device_unregister(tpacpi_sensors_pdev
);
6970 platform_device_unregister(tpacpi_pdev
);
6972 if (tp_features
.sensors_pdrv_attrs_registered
)
6973 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
6974 if (tp_features
.platform_drv_attrs_registered
)
6975 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
6977 if (tp_features
.sensors_pdrv_registered
)
6978 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
6980 if (tp_features
.platform_drv_registered
)
6981 platform_driver_unregister(&tpacpi_pdriver
);
6984 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
6987 destroy_workqueue(tpacpi_wq
);
6989 kfree(thinkpad_id
.bios_version_str
);
6990 kfree(thinkpad_id
.ec_version_str
);
6991 kfree(thinkpad_id
.model_str
);
6995 static int __init
thinkpad_acpi_module_init(void)
6999 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
7001 /* Parameter checking */
7002 if (hotkey_report_mode
> 2)
7005 /* Driver-level probe */
7007 ret
= get_thinkpad_model_data(&thinkpad_id
);
7010 "unable to get DMI data: %d\n", ret
);
7011 thinkpad_acpi_module_exit();
7014 ret
= probe_for_thinkpad();
7016 thinkpad_acpi_module_exit();
7020 /* Driver initialization */
7022 TPACPI_ACPIHANDLE_INIT(ecrd
);
7023 TPACPI_ACPIHANDLE_INIT(ecwr
);
7025 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
7027 thinkpad_acpi_module_exit();
7031 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
7034 "unable to create proc dir " TPACPI_PROC_DIR
);
7035 thinkpad_acpi_module_exit();
7038 proc_dir
->owner
= THIS_MODULE
;
7040 ret
= platform_driver_register(&tpacpi_pdriver
);
7043 "unable to register main platform driver\n");
7044 thinkpad_acpi_module_exit();
7047 tp_features
.platform_drv_registered
= 1;
7049 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
7052 "unable to register hwmon platform driver\n");
7053 thinkpad_acpi_module_exit();
7056 tp_features
.sensors_pdrv_registered
= 1;
7058 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
7060 tp_features
.platform_drv_attrs_registered
= 1;
7061 ret
= tpacpi_create_driver_attributes(
7062 &tpacpi_hwmon_pdriver
.driver
);
7066 "unable to create sysfs driver attributes\n");
7067 thinkpad_acpi_module_exit();
7070 tp_features
.sensors_pdrv_attrs_registered
= 1;
7073 /* Device initialization */
7074 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
7076 if (IS_ERR(tpacpi_pdev
)) {
7077 ret
= PTR_ERR(tpacpi_pdev
);
7079 printk(TPACPI_ERR
"unable to register platform device\n");
7080 thinkpad_acpi_module_exit();
7083 tpacpi_sensors_pdev
= platform_device_register_simple(
7084 TPACPI_HWMON_DRVR_NAME
,
7086 if (IS_ERR(tpacpi_sensors_pdev
)) {
7087 ret
= PTR_ERR(tpacpi_sensors_pdev
);
7088 tpacpi_sensors_pdev
= NULL
;
7090 "unable to register hwmon platform device\n");
7091 thinkpad_acpi_module_exit();
7094 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
7095 &dev_attr_thinkpad_acpi_pdev_name
);
7098 "unable to create sysfs hwmon device attributes\n");
7099 thinkpad_acpi_module_exit();
7102 tp_features
.sensors_pdev_attrs_registered
= 1;
7103 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
7104 if (IS_ERR(tpacpi_hwmon
)) {
7105 ret
= PTR_ERR(tpacpi_hwmon
);
7106 tpacpi_hwmon
= NULL
;
7107 printk(TPACPI_ERR
"unable to register hwmon device\n");
7108 thinkpad_acpi_module_exit();
7111 mutex_init(&tpacpi_inputdev_send_mutex
);
7112 tpacpi_inputdev
= input_allocate_device();
7113 if (!tpacpi_inputdev
) {
7114 printk(TPACPI_ERR
"unable to allocate input device\n");
7115 thinkpad_acpi_module_exit();
7118 /* Prepare input device, but don't register */
7119 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
7120 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
7121 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
7122 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
7123 thinkpad_id
.vendor
:
7125 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
7126 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
7128 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7129 ret
= ibm_init(&ibms_init
[i
]);
7130 if (ret
>= 0 && *ibms_init
[i
].param
)
7131 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
7133 thinkpad_acpi_module_exit();
7137 ret
= input_register_device(tpacpi_inputdev
);
7139 printk(TPACPI_ERR
"unable to register input device\n");
7140 thinkpad_acpi_module_exit();
7143 tp_features
.input_device_registered
= 1;
7146 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
7150 /* Please remove this in year 2009 */
7151 MODULE_ALIAS("ibm_acpi");
7153 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
7156 * DMI matching for module autoloading
7158 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7159 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
7161 * Only models listed in thinkwiki will be supported, so add yours
7162 * if it is not there yet.
7164 #define IBM_BIOS_MODULE_ALIAS(__type) \
7165 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
7167 /* Non-ancient thinkpads */
7168 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
7169 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
7171 /* Ancient thinkpad BIOSes have to be identified by
7172 * BIOS type or model number, and there are far less
7173 * BIOS types than model numbers... */
7174 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
7175 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
7176 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
7178 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
7179 MODULE_DESCRIPTION(TPACPI_DESC
);
7180 MODULE_VERSION(TPACPI_VERSION
);
7181 MODULE_LICENSE("GPL");
7183 module_init(thinkpad_acpi_module_init
);
7184 module_exit(thinkpad_acpi_module_exit
);