2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2009 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.23"
25 #define TPACPI_SYSFS_VERSION 0x020500
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/sched.h>
58 #include <linux/kthread.h>
59 #include <linux/freezer.h>
60 #include <linux/delay.h>
62 #include <linux/nvram.h>
63 #include <linux/proc_fs.h>
64 #include <linux/sysfs.h>
65 #include <linux/backlight.h>
67 #include <linux/platform_device.h>
68 #include <linux/hwmon.h>
69 #include <linux/hwmon-sysfs.h>
70 #include <linux/input.h>
71 #include <linux/leds.h>
72 #include <linux/rfkill.h>
73 #include <asm/uaccess.h>
75 #include <linux/dmi.h>
76 #include <linux/jiffies.h>
77 #include <linux/workqueue.h>
79 #include <acpi/acpi_drivers.h>
81 #include <linux/pci_ids.h>
84 /* ThinkPad CMOS commands */
85 #define TP_CMOS_VOLUME_DOWN 0
86 #define TP_CMOS_VOLUME_UP 1
87 #define TP_CMOS_VOLUME_MUTE 2
88 #define TP_CMOS_BRIGHTNESS_UP 4
89 #define TP_CMOS_BRIGHTNESS_DOWN 5
90 #define TP_CMOS_THINKLIGHT_ON 12
91 #define TP_CMOS_THINKLIGHT_OFF 13
95 TP_NVRAM_ADDR_HK2
= 0x57,
96 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
97 TP_NVRAM_ADDR_VIDEO
= 0x59,
98 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
99 TP_NVRAM_ADDR_MIXER
= 0x60,
102 /* NVRAM bit masks */
104 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
105 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
106 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
107 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
108 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
109 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
110 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
111 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
112 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
113 TP_NVRAM_MASK_MUTE
= 0x40,
114 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
115 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
116 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
120 #define TPACPI_ACPI_HKEY_HID "IBM0068"
123 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
124 #define TPACPI_HKEY_INPUT_VERSION 0x4101
126 /* ACPI \WGSV commands */
128 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
129 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
130 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
131 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
134 /* TP_ACPI_WGSV_GET_STATE bits */
136 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
137 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
138 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
139 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
140 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
141 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
142 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
143 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
144 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
145 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
148 /****************************************************************************
152 #define TPACPI_NAME "thinkpad"
153 #define TPACPI_DESC "ThinkPad ACPI Extras"
154 #define TPACPI_FILE TPACPI_NAME "_acpi"
155 #define TPACPI_URL "http://ibm-acpi.sf.net/"
156 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
158 #define TPACPI_PROC_DIR "ibm"
159 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
160 #define TPACPI_DRVR_NAME TPACPI_FILE
161 #define TPACPI_DRVR_SHORTNAME "tpacpi"
162 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
164 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
165 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
167 #define TPACPI_MAX_ACPI_ARGS 3
169 /* rfkill switches */
171 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
172 TPACPI_RFK_WWAN_SW_ID
,
173 TPACPI_RFK_UWB_SW_ID
,
177 #define TPACPI_LOG TPACPI_FILE ": "
178 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
179 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
180 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
181 #define TPACPI_ERR KERN_ERR TPACPI_LOG
182 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
183 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
184 #define TPACPI_INFO KERN_INFO TPACPI_LOG
185 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
187 /* Debugging printk groups */
188 #define TPACPI_DBG_ALL 0xffff
189 #define TPACPI_DBG_DISCLOSETASK 0x8000
190 #define TPACPI_DBG_INIT 0x0001
191 #define TPACPI_DBG_EXIT 0x0002
192 #define TPACPI_DBG_RFKILL 0x0004
193 #define TPACPI_DBG_HKEY 0x0008
194 #define TPACPI_DBG_FAN 0x0010
195 #define TPACPI_DBG_BRGHT 0x0020
197 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
198 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
199 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
202 /****************************************************************************
203 * Driver-wide structs and misc. variables
208 struct tp_acpi_drv_struct
{
209 const struct acpi_device_id
*hid
;
210 struct acpi_driver
*driver
;
212 void (*notify
) (struct ibm_struct
*, u32
);
215 struct acpi_device
*device
;
221 int (*read
) (char *);
222 int (*write
) (char *);
224 void (*resume
) (void);
225 void (*suspend
) (pm_message_t state
);
226 void (*shutdown
) (void);
228 struct list_head all_drivers
;
230 struct tp_acpi_drv_struct
*acpi
;
233 u8 acpi_driver_registered
:1;
234 u8 acpi_notify_installed
:1;
241 struct ibm_init_struct
{
244 int (*init
) (struct ibm_init_struct
*);
245 struct ibm_struct
*data
;
256 u32 bright_16levels
:1;
257 u32 bright_acpimode
:1;
260 u32 fan_ctrl_status_undef
:1;
262 u32 beep_needs_two_args
:1;
263 u32 input_device_registered
:1;
264 u32 platform_drv_registered
:1;
265 u32 platform_drv_attrs_registered
:1;
266 u32 sensors_pdrv_registered
:1;
267 u32 sensors_pdrv_attrs_registered
:1;
268 u32 sensors_pdev_attrs_registered
:1;
269 u32 hotkey_poll_active
:1;
273 u16 hotkey_mask_ff
:1;
276 struct thinkpad_id_data
{
277 unsigned int vendor
; /* ThinkPad vendor:
278 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
280 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
281 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
283 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
285 u16 bios_release
; /* 1ZETK1WW = 0x314b, 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
;
310 /* Special LED class that can defer work */
311 struct tpacpi_led_classdev
{
312 struct led_classdev led_classdev
;
313 struct work_struct work
;
314 enum led_status_t new_state
;
318 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
319 static int dbg_wlswemul
;
320 static int tpacpi_wlsw_emulstate
;
321 static int dbg_bluetoothemul
;
322 static int tpacpi_bluetooth_emulstate
;
323 static int dbg_wwanemul
;
324 static int tpacpi_wwan_emulstate
;
325 static int dbg_uwbemul
;
326 static int tpacpi_uwb_emulstate
;
330 /*************************************************************************
334 #define dbg_printk(a_dbg_level, format, arg...) \
335 do { if (dbg_level & (a_dbg_level)) \
336 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
339 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
340 #define vdbg_printk dbg_printk
341 static const char *str_supported(int is_supported
);
343 #define vdbg_printk(a_dbg_level, format, arg...) \
347 static void tpacpi_log_usertask(const char * const what
)
349 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
350 what
, task_tgid_vnr(current
));
353 #define tpacpi_disclose_usertask(what, format, arg...) \
356 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
357 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
358 printk(TPACPI_DEBUG "%s: PID %d: " format, \
359 what, task_tgid_vnr(current), ## arg); \
364 * Quirk handling helpers
366 * ThinkPad IDs and versions seen in the field so far
367 * are two-characters from the set [0-9A-Z], i.e. base 36.
369 * We use values well outside that range as specials.
372 #define TPACPI_MATCH_ANY 0xffffU
373 #define TPACPI_MATCH_UNKNOWN 0U
375 /* TPID('1', 'Y') == 0x5931 */
376 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
378 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
379 { .vendor = PCI_VENDOR_ID_IBM, \
380 .bios = TPID(__id1, __id2), \
381 .ec = TPACPI_MATCH_ANY, \
382 .quirks = (__quirk) }
384 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
385 { .vendor = PCI_VENDOR_ID_LENOVO, \
386 .bios = TPID(__id1, __id2), \
387 .ec = TPACPI_MATCH_ANY, \
388 .quirks = (__quirk) }
390 struct tpacpi_quirk
{
394 unsigned long quirks
;
398 * tpacpi_check_quirks() - search BIOS/EC version on a list
399 * @qlist: array of &struct tpacpi_quirk
400 * @qlist_size: number of elements in @qlist
402 * Iterates over a quirks list until one is found that matches the
403 * ThinkPad's vendor, BIOS and EC model.
405 * Returns 0 if nothing matches, otherwise returns the quirks field of
406 * the matching &struct tpacpi_quirk entry.
408 * The match criteria is: vendor, ec and bios much match.
410 static unsigned long __init
tpacpi_check_quirks(
411 const struct tpacpi_quirk
*qlist
,
412 unsigned int qlist_size
)
415 if ((qlist
->vendor
== thinkpad_id
.vendor
||
416 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
417 (qlist
->bios
== thinkpad_id
.bios_model
||
418 qlist
->bios
== TPACPI_MATCH_ANY
) &&
419 (qlist
->ec
== thinkpad_id
.ec_model
||
420 qlist
->ec
== TPACPI_MATCH_ANY
))
421 return qlist
->quirks
;
430 /****************************************************************************
431 ****************************************************************************
433 * ACPI Helpers and device model
435 ****************************************************************************
436 ****************************************************************************/
438 /*************************************************************************
442 static acpi_handle root_handle
;
444 #define TPACPI_HANDLE(object, parent, paths...) \
445 static acpi_handle object##_handle; \
446 static acpi_handle *object##_parent = &parent##_handle; \
447 static char *object##_path; \
448 static char *object##_paths[] = { paths }
450 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
451 "\\_SB.PCI.ISA.EC", /* 570 */
452 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
453 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
454 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
455 "\\_SB.PCI0.ICH3.EC0", /* R31 */
456 "\\_SB.PCI0.LPC.EC", /* all others */
459 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
460 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
462 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
464 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
465 "\\CMS", /* R40, R40e */
468 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
469 "^HKEY", /* R30, R31 */
470 "HKEY", /* all others */
473 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
474 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
475 "\\_SB.PCI0.VID0", /* 770e */
476 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
477 "\\_SB.PCI0.AGP.VID", /* all others */
481 /*************************************************************************
485 static int acpi_evalf(acpi_handle handle
,
486 void *res
, char *method
, char *fmt
, ...)
489 struct acpi_object_list params
;
490 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
491 struct acpi_buffer result
, *resultp
;
492 union acpi_object out_obj
;
500 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
513 params
.pointer
= &in_objs
[0];
520 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
521 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
523 /* add more types as needed */
525 printk(TPACPI_ERR
"acpi_evalf() called "
526 "with invalid format character '%c'\n", c
);
532 if (res_type
!= 'v') {
533 result
.length
= sizeof(out_obj
);
534 result
.pointer
= &out_obj
;
539 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
544 *(int *)res
= out_obj
.integer
.value
;
545 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
548 success
= status
== AE_OK
;
550 /* add more types as needed */
552 printk(TPACPI_ERR
"acpi_evalf() called "
553 "with invalid format character '%c'\n", res_type
);
557 if (!success
&& !quiet
)
558 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
559 method
, fmt0
, status
);
564 static int acpi_ec_read(int i
, u8
*p
)
569 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
573 if (ec_read(i
, p
) < 0)
580 static int acpi_ec_write(int i
, u8 v
)
583 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
586 if (ec_write(i
, v
) < 0)
593 static int issue_thinkpad_cmos_command(int cmos_cmd
)
598 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
604 /*************************************************************************
608 #define TPACPI_ACPIHANDLE_INIT(object) \
609 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
610 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
612 static void drv_acpi_handle_init(char *name
,
613 acpi_handle
*handle
, acpi_handle parent
,
614 char **paths
, int num_paths
, char **path
)
619 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
622 for (i
= 0; i
< num_paths
; i
++) {
623 status
= acpi_get_handle(parent
, paths
[i
], handle
);
624 if (ACPI_SUCCESS(status
)) {
626 dbg_printk(TPACPI_DBG_INIT
,
627 "Found ACPI handle %s for %s\n",
633 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
638 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
640 struct ibm_struct
*ibm
= data
;
642 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
645 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
648 ibm
->acpi
->notify(ibm
, event
);
651 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
658 if (!*ibm
->acpi
->handle
)
661 vdbg_printk(TPACPI_DBG_INIT
,
662 "setting up ACPI notify for %s\n", ibm
->name
);
664 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
666 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
671 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
672 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
673 TPACPI_ACPI_EVENT_PREFIX
,
676 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
677 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
678 if (ACPI_FAILURE(status
)) {
679 if (status
== AE_ALREADY_EXISTS
) {
681 "another device driver is already "
682 "handling %s events\n", ibm
->name
);
685 "acpi_install_notify_handler(%s) failed: %d\n",
690 ibm
->flags
.acpi_notify_installed
= 1;
694 static int __init
tpacpi_device_add(struct acpi_device
*device
)
699 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
703 dbg_printk(TPACPI_DBG_INIT
,
704 "registering %s as an ACPI driver\n", ibm
->name
);
708 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
709 if (!ibm
->acpi
->driver
) {
711 "failed to allocate memory for ibm->acpi->driver\n");
715 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
716 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
718 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
720 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
722 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
724 kfree(ibm
->acpi
->driver
);
725 ibm
->acpi
->driver
= NULL
;
727 ibm
->flags
.acpi_driver_registered
= 1;
733 /****************************************************************************
734 ****************************************************************************
738 ****************************************************************************
739 ****************************************************************************/
741 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
742 int count
, int *eof
, void *data
)
744 struct ibm_struct
*ibm
= data
;
747 if (!ibm
|| !ibm
->read
)
750 len
= ibm
->read(page
);
754 if (len
<= off
+ count
)
766 static int dispatch_procfs_write(struct file
*file
,
767 const char __user
*userbuf
,
768 unsigned long count
, void *data
)
770 struct ibm_struct
*ibm
= data
;
774 if (!ibm
|| !ibm
->write
)
776 if (count
> PAGE_SIZE
- 2)
779 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
783 if (copy_from_user(kernbuf
, userbuf
, count
)) {
789 strcat(kernbuf
, ",");
790 ret
= ibm
->write(kernbuf
);
799 static char *next_cmd(char **cmds
)
804 while ((end
= strchr(start
, ',')) && end
== start
)
816 /****************************************************************************
817 ****************************************************************************
819 * Device model: input, hwmon and platform
821 ****************************************************************************
822 ****************************************************************************/
824 static struct platform_device
*tpacpi_pdev
;
825 static struct platform_device
*tpacpi_sensors_pdev
;
826 static struct device
*tpacpi_hwmon
;
827 static struct input_dev
*tpacpi_inputdev
;
828 static struct mutex tpacpi_inputdev_send_mutex
;
829 static LIST_HEAD(tpacpi_all_drivers
);
831 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
834 struct ibm_struct
*ibm
, *itmp
;
836 list_for_each_entry_safe(ibm
, itmp
,
840 (ibm
->suspend
)(state
);
846 static int tpacpi_resume_handler(struct platform_device
*pdev
)
848 struct ibm_struct
*ibm
, *itmp
;
850 list_for_each_entry_safe(ibm
, itmp
,
860 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
862 struct ibm_struct
*ibm
, *itmp
;
864 list_for_each_entry_safe(ibm
, itmp
,
872 static struct platform_driver tpacpi_pdriver
= {
874 .name
= TPACPI_DRVR_NAME
,
875 .owner
= THIS_MODULE
,
877 .suspend
= tpacpi_suspend_handler
,
878 .resume
= tpacpi_resume_handler
,
879 .shutdown
= tpacpi_shutdown_handler
,
882 static struct platform_driver tpacpi_hwmon_pdriver
= {
884 .name
= TPACPI_HWMON_DRVR_NAME
,
885 .owner
= THIS_MODULE
,
889 /*************************************************************************
890 * sysfs support helpers
893 struct attribute_set
{
894 unsigned int members
, max_members
;
895 struct attribute_group group
;
898 struct attribute_set_obj
{
899 struct attribute_set s
;
901 } __attribute__((packed
));
903 static struct attribute_set
*create_attr_set(unsigned int max_members
,
906 struct attribute_set_obj
*sobj
;
908 if (max_members
== 0)
911 /* Allocates space for implicit NULL at the end too */
912 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
913 max_members
* sizeof(struct attribute
*),
917 sobj
->s
.max_members
= max_members
;
918 sobj
->s
.group
.attrs
= &sobj
->a
;
919 sobj
->s
.group
.name
= name
;
924 #define destroy_attr_set(_set) \
927 /* not multi-threaded safe, use it in a single thread per set */
928 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
933 if (s
->members
>= s
->max_members
)
936 s
->group
.attrs
[s
->members
] = attr
;
942 static int add_many_to_attr_set(struct attribute_set
*s
,
943 struct attribute
**attr
,
948 for (i
= 0; i
< count
; i
++) {
949 res
= add_to_attr_set(s
, attr
[i
]);
957 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
959 sysfs_remove_group(kobj
, &s
->group
);
963 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
964 sysfs_create_group(_kobj, &_attr_set->group)
966 static int parse_strtoul(const char *buf
,
967 unsigned long max
, unsigned long *value
)
971 while (*buf
&& isspace(*buf
))
973 *value
= simple_strtoul(buf
, &endp
, 0);
974 while (*endp
&& isspace(*endp
))
976 if (*endp
|| *value
> max
)
982 static void tpacpi_disable_brightness_delay(void)
984 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
986 "ACPI backlight control delay disabled\n");
989 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
991 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
992 union acpi_object
*obj
;
995 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
996 obj
= (union acpi_object
*)buffer
.pointer
;
997 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
998 printk(TPACPI_ERR
"Unknown _BCL data, "
999 "please report this to %s\n", TPACPI_MAIL
);
1002 rc
= obj
->package
.count
;
1008 kfree(buffer
.pointer
);
1012 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1013 u32 lvl
, void *context
, void **rv
)
1015 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1016 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1018 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1019 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1020 BUG_ON(!rv
|| !*rv
);
1021 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1022 return AE_CTRL_TERMINATE
;
1029 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1031 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1035 void *bcl_ptr
= &bcl_levels
;
1038 TPACPI_ACPIHANDLE_INIT(vid
);
1044 * Search for a _BCL method, and execute it. This is safe on all
1045 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1046 * BIOS in ACPI backlight control mode. We do NOT have to care
1047 * about calling the _BCL method in an enabled video device, any
1048 * will do for our purposes.
1051 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1052 tpacpi_acpi_walk_find_bcl
, NULL
,
1055 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1056 tp_features
.bright_acpimode
= 1;
1057 return (bcl_levels
- 2);
1063 static int __init
tpacpi_new_rfkill(const unsigned int id
,
1064 struct rfkill
**rfk
,
1065 const enum rfkill_type rfktype
,
1067 const bool set_default
,
1068 int (*toggle_radio
)(void *, enum rfkill_state
),
1069 int (*get_state
)(void *, enum rfkill_state
*))
1072 enum rfkill_state initial_state
= RFKILL_STATE_SOFT_BLOCKED
;
1074 res
= get_state(NULL
, &initial_state
);
1077 "failed to read initial state for %s, error %d; "
1078 "will turn radio off\n", name
, res
);
1079 } else if (set_default
) {
1080 /* try to set the initial state as the default for the rfkill
1081 * type, since we ask the firmware to preserve it across S5 in
1083 if (rfkill_set_default(rfktype
,
1084 (initial_state
== RFKILL_STATE_UNBLOCKED
) ?
1085 RFKILL_STATE_UNBLOCKED
:
1086 RFKILL_STATE_SOFT_BLOCKED
) == -EPERM
)
1087 vdbg_printk(TPACPI_DBG_RFKILL
,
1088 "Default state for %s cannot be changed\n",
1092 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
1095 "failed to allocate memory for rfkill class\n");
1099 (*rfk
)->name
= name
;
1100 (*rfk
)->get_state
= get_state
;
1101 (*rfk
)->toggle_radio
= toggle_radio
;
1102 (*rfk
)->state
= initial_state
;
1104 res
= rfkill_register(*rfk
);
1107 "failed to register %s rfkill switch: %d\n",
1117 static void printk_deprecated_attribute(const char * const what
,
1118 const char * const details
)
1120 tpacpi_log_usertask("deprecated sysfs attribute");
1121 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1122 "will be removed. %s\n",
1126 static void printk_deprecated_rfkill_attribute(const char * const what
)
1128 printk_deprecated_attribute(what
,
1129 "Please switch to generic rfkill before year 2010");
1132 /*************************************************************************
1133 * thinkpad-acpi driver attributes
1136 /* interface_version --------------------------------------------------- */
1137 static ssize_t
tpacpi_driver_interface_version_show(
1138 struct device_driver
*drv
,
1141 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1144 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1145 tpacpi_driver_interface_version_show
, NULL
);
1147 /* debug_level --------------------------------------------------------- */
1148 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1151 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1154 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1155 const char *buf
, size_t count
)
1159 if (parse_strtoul(buf
, 0xffff, &t
))
1167 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1168 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1170 /* version ------------------------------------------------------------- */
1171 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1174 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1175 TPACPI_DESC
, TPACPI_VERSION
);
1178 static DRIVER_ATTR(version
, S_IRUGO
,
1179 tpacpi_driver_version_show
, NULL
);
1181 /* --------------------------------------------------------------------- */
1183 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1185 static void tpacpi_send_radiosw_update(void);
1187 /* wlsw_emulstate ------------------------------------------------------ */
1188 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1191 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1194 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1195 const char *buf
, size_t count
)
1199 if (parse_strtoul(buf
, 1, &t
))
1202 if (tpacpi_wlsw_emulstate
!= t
) {
1203 tpacpi_wlsw_emulstate
= !!t
;
1204 tpacpi_send_radiosw_update();
1206 tpacpi_wlsw_emulstate
= !!t
;
1211 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1212 tpacpi_driver_wlsw_emulstate_show
,
1213 tpacpi_driver_wlsw_emulstate_store
);
1215 /* bluetooth_emulstate ------------------------------------------------- */
1216 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1217 struct device_driver
*drv
,
1220 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1223 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1224 struct device_driver
*drv
,
1225 const char *buf
, size_t count
)
1229 if (parse_strtoul(buf
, 1, &t
))
1232 tpacpi_bluetooth_emulstate
= !!t
;
1237 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1238 tpacpi_driver_bluetooth_emulstate_show
,
1239 tpacpi_driver_bluetooth_emulstate_store
);
1241 /* wwan_emulstate ------------------------------------------------- */
1242 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1243 struct device_driver
*drv
,
1246 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1249 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1250 struct device_driver
*drv
,
1251 const char *buf
, size_t count
)
1255 if (parse_strtoul(buf
, 1, &t
))
1258 tpacpi_wwan_emulstate
= !!t
;
1263 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1264 tpacpi_driver_wwan_emulstate_show
,
1265 tpacpi_driver_wwan_emulstate_store
);
1267 /* uwb_emulstate ------------------------------------------------- */
1268 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1269 struct device_driver
*drv
,
1272 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1275 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1276 struct device_driver
*drv
,
1277 const char *buf
, size_t count
)
1281 if (parse_strtoul(buf
, 1, &t
))
1284 tpacpi_uwb_emulstate
= !!t
;
1289 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1290 tpacpi_driver_uwb_emulstate_show
,
1291 tpacpi_driver_uwb_emulstate_store
);
1294 /* --------------------------------------------------------------------- */
1296 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1297 &driver_attr_debug_level
, &driver_attr_version
,
1298 &driver_attr_interface_version
,
1301 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1307 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1308 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1312 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1313 if (!res
&& dbg_wlswemul
)
1314 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1315 if (!res
&& dbg_bluetoothemul
)
1316 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1317 if (!res
&& dbg_wwanemul
)
1318 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1319 if (!res
&& dbg_uwbemul
)
1320 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1326 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1330 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1331 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1333 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1334 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1335 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1336 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1337 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1341 /*************************************************************************
1346 * Table of recommended minimum BIOS versions
1348 * Reasons for listing:
1349 * 1. Stable BIOS, listed because the unknown ammount of
1350 * bugs and bad ACPI behaviour on older versions
1352 * 2. BIOS or EC fw with known bugs that trigger on Linux
1354 * 3. BIOS with known reduced functionality in older versions
1356 * We recommend the latest BIOS and EC version.
1357 * We only support the latest BIOS and EC fw version as a rule.
1359 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1360 * Information from users in ThinkWiki
1362 * WARNING: we use this table also to detect that the machine is
1363 * a ThinkPad in some cases, so don't remove entries lightly.
1366 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1367 { .vendor = (__v), \
1368 .bios = TPID(__id1, __id2), \
1369 .ec = TPACPI_MATCH_ANY, \
1370 .quirks = TPACPI_MATCH_ANY << 16 \
1371 | (__bv1) << 8 | (__bv2) }
1373 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1374 __eid1, __eid2, __ev1, __ev2) \
1375 { .vendor = (__v), \
1376 .bios = TPID(__bid1, __bid2), \
1377 .ec = TPID(__eid1, __eid2), \
1378 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1379 | (__bv1) << 8 | (__bv2) }
1381 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1382 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1384 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1385 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1386 __bv1, __bv2, __id1, __id2, __ev1, __ev2)
1388 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1389 __eid1, __eid2, __ev1, __ev2) \
1390 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1391 __bv1, __bv2, __eid1, __eid2, __ev1, __ev2)
1393 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1394 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1396 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1397 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1398 __bv1, __bv2, __id1, __id2, __ev1, __ev2)
1400 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1401 __eid1, __eid2, __ev1, __ev2) \
1402 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1403 __bv1, __bv2, __eid1, __eid2, __ev1, __ev2)
1405 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1406 /* Numeric models ------------------ */
1407 /* FW MODEL BIOS VERS */
1408 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1409 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1410 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1411 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1412 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1413 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1414 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1415 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1416 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1418 /* A-series ------------------------- */
1419 /* FW MODEL BIOS VERS EC VERS */
1420 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1421 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1422 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1423 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1424 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1425 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1426 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1427 TPV_QI0('1', '3', '2', '0'), /* A22m */
1428 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1429 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1430 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1432 /* G-series ------------------------- */
1433 /* FW MODEL BIOS VERS */
1434 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1435 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1437 /* R-series, T-series --------------- */
1438 /* FW MODEL BIOS VERS EC VERS */
1439 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1440 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1441 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1442 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1443 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1444 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1445 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1446 T40/p, T41/p, T42/p (1) */
1447 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1448 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1449 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1450 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1452 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1453 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1454 TPV_QI0('1', '6', '3', '2'), /* T22 */
1455 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1456 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1457 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1459 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1460 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1461 TPV_QL0('7', 'E', 'D', '0'), /* R60e, R60i */
1463 /* BIOS FW BIOS VERS EC FW EC VERS */
1464 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1465 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1467 /* X-series ------------------------- */
1468 /* FW MODEL BIOS VERS EC VERS */
1469 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1470 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1471 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1472 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1473 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1474 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1475 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1477 TPV_QL0('7', 'B', 'D', '7'), /* X60/s */
1478 TPV_QL0('7', 'J', '3', '0'), /* X60t */
1480 /* (0) - older versions lack DMI EC fw string and functionality */
1481 /* (1) - older versions known to lack functionality */
1492 static void __init
tpacpi_check_outdated_fw(void)
1494 unsigned long fwvers
;
1495 u16 ec_version
, bios_version
;
1497 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1498 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1503 bios_version
= fwvers
& 0xffffU
;
1504 ec_version
= (fwvers
>> 16) & 0xffffU
;
1506 /* note that unknown versions are set to 0x0000 and we use that */
1507 if ((bios_version
> thinkpad_id
.bios_release
) ||
1508 (ec_version
> thinkpad_id
.ec_release
&&
1509 ec_version
!= TPACPI_MATCH_ANY
)) {
1511 * The changelogs would let us track down the exact
1512 * reason, but it is just too much of a pain to track
1513 * it. We only list BIOSes that are either really
1514 * broken, or really stable to begin with, so it is
1515 * best if the user upgrades the firmware anyway.
1518 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1520 "WARNING: This firmware may be missing critical bug "
1521 "fixes and/or important features\n");
1525 static bool __init
tpacpi_is_fw_known(void)
1527 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1528 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1531 /****************************************************************************
1532 ****************************************************************************
1536 ****************************************************************************
1537 ****************************************************************************/
1539 /*************************************************************************
1540 * thinkpad-acpi init subdriver
1543 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1545 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1546 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1548 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1549 (thinkpad_id
.bios_version_str
) ?
1550 thinkpad_id
.bios_version_str
: "unknown",
1551 (thinkpad_id
.ec_version_str
) ?
1552 thinkpad_id
.ec_version_str
: "unknown");
1554 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1555 printk(TPACPI_INFO
"%s %s, model %s\n",
1556 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1557 "IBM" : ((thinkpad_id
.vendor
==
1558 PCI_VENDOR_ID_LENOVO
) ?
1559 "Lenovo" : "Unknown vendor"),
1560 thinkpad_id
.model_str
,
1561 (thinkpad_id
.nummodel_str
) ?
1562 thinkpad_id
.nummodel_str
: "unknown");
1564 tpacpi_check_outdated_fw();
1568 static int thinkpad_acpi_driver_read(char *p
)
1572 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1573 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1578 static struct ibm_struct thinkpad_acpi_driver_data
= {
1580 .read
= thinkpad_acpi_driver_read
,
1583 /*************************************************************************
1588 * ThinkPad firmware event model
1590 * The ThinkPad firmware has two main event interfaces: normal ACPI
1591 * notifications (which follow the ACPI standard), and a private event
1594 * The private event interface also issues events for the hotkeys. As
1595 * the driver gained features, the event handling code ended up being
1596 * built around the hotkey subdriver. This will need to be refactored
1597 * to a more formal event API eventually.
1599 * Some "hotkeys" are actually supposed to be used as event reports,
1600 * such as "brightness has changed", "volume has changed", depending on
1601 * the ThinkPad model and how the firmware is operating.
1603 * Unlike other classes, hotkey-class events have mask/unmask control on
1604 * non-ancient firmware. However, how it behaves changes a lot with the
1605 * firmware model and version.
1608 enum { /* hot key scan codes (derived from ACPI DSDT) */
1609 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1610 TP_ACPI_HOTKEYSCAN_FNF2
,
1611 TP_ACPI_HOTKEYSCAN_FNF3
,
1612 TP_ACPI_HOTKEYSCAN_FNF4
,
1613 TP_ACPI_HOTKEYSCAN_FNF5
,
1614 TP_ACPI_HOTKEYSCAN_FNF6
,
1615 TP_ACPI_HOTKEYSCAN_FNF7
,
1616 TP_ACPI_HOTKEYSCAN_FNF8
,
1617 TP_ACPI_HOTKEYSCAN_FNF9
,
1618 TP_ACPI_HOTKEYSCAN_FNF10
,
1619 TP_ACPI_HOTKEYSCAN_FNF11
,
1620 TP_ACPI_HOTKEYSCAN_FNF12
,
1621 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1622 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1623 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1624 TP_ACPI_HOTKEYSCAN_FNHOME
,
1625 TP_ACPI_HOTKEYSCAN_FNEND
,
1626 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1627 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1628 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1629 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1630 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1631 TP_ACPI_HOTKEYSCAN_MUTE
,
1632 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1635 enum { /* Keys/events available through NVRAM polling */
1636 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1637 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1640 enum { /* Positions of some of the keys in hotkey masks */
1641 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1642 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1643 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1644 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1645 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1646 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1647 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1648 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1649 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1650 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1651 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1654 enum { /* NVRAM to ACPI HKEY group map */
1655 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1656 TP_ACPI_HKEY_ZOOM_MASK
|
1657 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1658 TP_ACPI_HKEY_HIBERNATE_MASK
,
1659 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1660 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1661 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1662 TP_ACPI_HKEY_VOLDWN_MASK
|
1663 TP_ACPI_HKEY_MUTE_MASK
,
1666 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1667 struct tp_nvram_state
{
1668 u16 thinkpad_toggle
:1;
1670 u16 display_toggle
:1;
1671 u16 thinklight_toggle
:1;
1672 u16 hibernate_toggle
:1;
1673 u16 displayexp_toggle
:1;
1674 u16 display_state
:1;
1675 u16 brightness_toggle
:1;
1676 u16 volume_toggle
:1;
1679 u8 brightness_level
;
1683 /* kthread for the hotkey poller */
1684 static struct task_struct
*tpacpi_hotkey_task
;
1686 /* Acquired while the poller kthread is running, use to sync start/stop */
1687 static struct mutex hotkey_thread_mutex
;
1690 * Acquire mutex to write poller control variables as an
1693 * Increment hotkey_config_change when changing them if you
1694 * want the kthread to forget old state.
1696 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1698 static struct mutex hotkey_thread_data_mutex
;
1699 static unsigned int hotkey_config_change
;
1702 * hotkey poller control variables
1704 * Must be atomic or readers will also need to acquire mutex
1706 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1707 * should be used only when the changes need to be taken as
1708 * a block, OR when one needs to force the kthread to forget
1711 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1712 static unsigned int hotkey_poll_freq
= 10; /* Hz */
1714 #define HOTKEY_CONFIG_CRITICAL_START \
1716 mutex_lock(&hotkey_thread_data_mutex); \
1717 hotkey_config_change++; \
1719 #define HOTKEY_CONFIG_CRITICAL_END \
1720 mutex_unlock(&hotkey_thread_data_mutex);
1722 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1724 #define hotkey_source_mask 0U
1725 #define HOTKEY_CONFIG_CRITICAL_START
1726 #define HOTKEY_CONFIG_CRITICAL_END
1728 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1730 static struct mutex hotkey_mutex
;
1732 static enum { /* Reasons for waking up */
1733 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1734 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1735 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1736 } hotkey_wakeup_reason
;
1738 static int hotkey_autosleep_ack
;
1740 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
1741 static u32 hotkey_all_mask
; /* all events supported in fw */
1742 static u32 hotkey_reserved_mask
; /* events better left disabled */
1743 static u32 hotkey_driver_mask
; /* events needed by the driver */
1744 static u32 hotkey_user_mask
; /* events visible to userspace */
1745 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
1747 static unsigned int hotkey_report_mode
;
1749 static u16
*hotkey_keycode_map
;
1751 static struct attribute_set
*hotkey_dev_attributes
;
1753 static void tpacpi_driver_event(const unsigned int hkey_event
);
1754 static void hotkey_driver_event(const unsigned int scancode
);
1756 /* HKEY.MHKG() return bits */
1757 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1759 static int hotkey_get_wlsw(int *status
)
1761 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1763 *status
= !!tpacpi_wlsw_emulstate
;
1767 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1772 static int hotkey_get_tablet_mode(int *status
)
1776 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1779 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1784 * Reads current event mask from firmware, and updates
1785 * hotkey_acpi_mask accordingly. Also resets any bits
1786 * from hotkey_user_mask that are unavailable to be
1787 * delivered (shadow requirement of the userspace ABI).
1789 * Call with hotkey_mutex held
1791 static int hotkey_mask_get(void)
1793 if (tp_features
.hotkey_mask
) {
1796 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1799 hotkey_acpi_mask
= m
;
1801 /* no mask support doesn't mean no event support... */
1802 hotkey_acpi_mask
= hotkey_all_mask
;
1805 /* sync userspace-visible mask */
1806 hotkey_user_mask
&= (hotkey_acpi_mask
| hotkey_source_mask
);
1811 void static hotkey_mask_warn_incomplete_mask(void)
1813 /* log only what the user can fix... */
1814 const u32 wantedmask
= hotkey_driver_mask
&
1815 ~(hotkey_acpi_mask
| hotkey_source_mask
) &
1816 (hotkey_all_mask
| TPACPI_HKEY_NVRAM_KNOWN_MASK
);
1819 printk(TPACPI_NOTICE
1820 "required events 0x%08x not enabled!\n",
1825 * Set the firmware mask when supported
1827 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
1829 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
1831 * Call with hotkey_mutex held
1833 static int hotkey_mask_set(u32 mask
)
1838 const u32 fwmask
= mask
& ~hotkey_source_mask
;
1840 if (tp_features
.hotkey_mask
) {
1841 for (i
= 0; i
< 32; i
++) {
1842 if (!acpi_evalf(hkey_handle
,
1843 NULL
, "MHKM", "vdd", i
+ 1,
1844 !!(mask
& (1 << i
)))) {
1852 * We *must* make an inconditional call to hotkey_mask_get to
1853 * refresh hotkey_acpi_mask and update hotkey_user_mask
1855 * Take the opportunity to also log when we cannot _enable_
1858 if (!hotkey_mask_get() && !rc
&& (fwmask
& ~hotkey_acpi_mask
)) {
1859 printk(TPACPI_NOTICE
1860 "asked for hotkey mask 0x%08x, but "
1861 "firmware forced it to 0x%08x\n",
1862 fwmask
, hotkey_acpi_mask
);
1865 hotkey_mask_warn_incomplete_mask();
1871 * Sets hotkey_user_mask and tries to set the firmware mask
1873 * Call with hotkey_mutex held
1875 static int hotkey_user_mask_set(const u32 mask
)
1879 /* Give people a chance to notice they are doing something that
1880 * is bound to go boom on their users sooner or later */
1881 if (!tp_warned
.hotkey_mask_ff
&&
1882 (mask
== 0xffff || mask
== 0xffffff ||
1883 mask
== 0xffffffff)) {
1884 tp_warned
.hotkey_mask_ff
= 1;
1885 printk(TPACPI_NOTICE
1886 "setting the hotkey mask to 0x%08x is likely "
1887 "not the best way to go about it\n", mask
);
1888 printk(TPACPI_NOTICE
1889 "please consider using the driver defaults, "
1890 "and refer to up-to-date thinkpad-acpi "
1894 /* Try to enable what the user asked for, plus whatever we need.
1895 * this syncs everything but won't enable bits in hotkey_user_mask */
1896 rc
= hotkey_mask_set((mask
| hotkey_driver_mask
) & ~hotkey_source_mask
);
1898 /* Enable the available bits in hotkey_user_mask */
1899 hotkey_user_mask
= mask
& (hotkey_acpi_mask
| hotkey_source_mask
);
1905 * Sets the driver hotkey mask.
1907 * Can be called even if the hotkey subdriver is inactive
1909 static int tpacpi_hotkey_driver_mask_set(const u32 mask
)
1913 /* Do the right thing if hotkey_init has not been called yet */
1914 if (!tp_features
.hotkey
) {
1915 hotkey_driver_mask
= mask
;
1919 mutex_lock(&hotkey_mutex
);
1921 HOTKEY_CONFIG_CRITICAL_START
1922 hotkey_driver_mask
= mask
;
1923 hotkey_source_mask
|= (mask
& ~hotkey_all_mask
);
1924 HOTKEY_CONFIG_CRITICAL_END
1926 rc
= hotkey_mask_set((hotkey_acpi_mask
| hotkey_driver_mask
) &
1927 ~hotkey_source_mask
);
1928 mutex_unlock(&hotkey_mutex
);
1933 static int hotkey_status_get(int *status
)
1935 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1941 static int hotkey_status_set(bool enable
)
1943 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
1949 static void tpacpi_input_send_tabletsw(void)
1953 if (tp_features
.hotkey_tablet
&&
1954 !hotkey_get_tablet_mode(&state
)) {
1955 mutex_lock(&tpacpi_inputdev_send_mutex
);
1957 input_report_switch(tpacpi_inputdev
,
1958 SW_TABLET_MODE
, !!state
);
1959 input_sync(tpacpi_inputdev
);
1961 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1965 /* Do NOT call without validating scancode first */
1966 static void tpacpi_input_send_key(const unsigned int scancode
)
1968 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
1970 if (keycode
!= KEY_RESERVED
) {
1971 mutex_lock(&tpacpi_inputdev_send_mutex
);
1973 input_report_key(tpacpi_inputdev
, keycode
, 1);
1974 if (keycode
== KEY_UNKNOWN
)
1975 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1977 input_sync(tpacpi_inputdev
);
1979 input_report_key(tpacpi_inputdev
, keycode
, 0);
1980 if (keycode
== KEY_UNKNOWN
)
1981 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1983 input_sync(tpacpi_inputdev
);
1985 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1989 /* Do NOT call without validating scancode first */
1990 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
1992 hotkey_driver_event(scancode
);
1993 if (hotkey_user_mask
& (1 << scancode
))
1994 tpacpi_input_send_key(scancode
);
1997 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1998 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2000 /* Do NOT call without validating scancode first */
2001 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2003 tpacpi_input_send_key_masked(scancode
);
2004 if (hotkey_report_mode
< 2) {
2005 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2006 0x80, 0x1001 + scancode
);
2010 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2014 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2015 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2016 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2017 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2018 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2019 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2021 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2022 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2023 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2025 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2026 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2027 n
->displayexp_toggle
=
2028 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2030 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2031 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2032 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2033 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2034 n
->brightness_toggle
=
2035 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2037 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2038 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2039 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2040 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2041 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2042 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2046 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2047 struct tp_nvram_state
*newn
,
2048 const u32 event_mask
)
2051 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2053 if ((event_mask & (1 << __scancode)) && \
2054 oldn->__member != newn->__member) \
2055 tpacpi_hotkey_send_key(__scancode); \
2058 #define TPACPI_MAY_SEND_KEY(__scancode) \
2060 if (event_mask & (1 << __scancode)) \
2061 tpacpi_hotkey_send_key(__scancode); \
2064 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2065 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2066 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2067 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2069 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2071 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2074 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2075 if (oldn
->mute
!= newn
->mute
) {
2076 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2078 if (oldn
->volume_level
> newn
->volume_level
) {
2079 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2080 } else if (oldn
->volume_level
< newn
->volume_level
) {
2081 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2082 } else if (oldn
->mute
== newn
->mute
) {
2083 /* repeated key presses that didn't change state */
2085 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2086 } else if (newn
->volume_level
!= 0) {
2087 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2089 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2094 /* handle brightness */
2095 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2096 if (oldn
->brightness_level
< newn
->brightness_level
) {
2097 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2098 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
2099 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2101 /* repeated key presses that didn't change state */
2102 if (newn
->brightness_level
!= 0) {
2103 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2105 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2110 #undef TPACPI_COMPARE_KEY
2111 #undef TPACPI_MAY_SEND_KEY
2117 * We track all events in hotkey_source_mask all the time, since
2118 * most of them are edge-based. We only issue those requested by
2119 * hotkey_user_mask or hotkey_driver_mask, though.
2121 static int hotkey_kthread(void *data
)
2123 struct tp_nvram_state s
[2];
2124 u32 poll_mask
, event_mask
;
2125 unsigned int si
, so
;
2127 unsigned int change_detector
, must_reset
;
2128 unsigned int poll_freq
;
2130 mutex_lock(&hotkey_thread_mutex
);
2132 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2141 /* Initial state for compares */
2142 mutex_lock(&hotkey_thread_data_mutex
);
2143 change_detector
= hotkey_config_change
;
2144 poll_mask
= hotkey_source_mask
;
2145 event_mask
= hotkey_source_mask
&
2146 (hotkey_driver_mask
| hotkey_user_mask
);
2147 poll_freq
= hotkey_poll_freq
;
2148 mutex_unlock(&hotkey_thread_data_mutex
);
2149 hotkey_read_nvram(&s
[so
], poll_mask
);
2151 while (!kthread_should_stop()) {
2153 if (likely(poll_freq
))
2156 t
= 100; /* should never happen... */
2158 t
= msleep_interruptible(t
);
2159 if (unlikely(kthread_should_stop()))
2161 must_reset
= try_to_freeze();
2162 if (t
> 0 && !must_reset
)
2165 mutex_lock(&hotkey_thread_data_mutex
);
2166 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2167 /* forget old state on thaw or config change */
2170 change_detector
= hotkey_config_change
;
2172 poll_mask
= hotkey_source_mask
;
2173 event_mask
= hotkey_source_mask
&
2174 (hotkey_driver_mask
| hotkey_user_mask
);
2175 poll_freq
= hotkey_poll_freq
;
2176 mutex_unlock(&hotkey_thread_data_mutex
);
2178 if (likely(poll_mask
)) {
2179 hotkey_read_nvram(&s
[si
], poll_mask
);
2180 if (likely(si
!= so
)) {
2181 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2191 mutex_unlock(&hotkey_thread_mutex
);
2195 /* call with hotkey_mutex held */
2196 static void hotkey_poll_stop_sync(void)
2198 if (tpacpi_hotkey_task
) {
2199 if (frozen(tpacpi_hotkey_task
) ||
2200 freezing(tpacpi_hotkey_task
))
2201 thaw_process(tpacpi_hotkey_task
);
2203 kthread_stop(tpacpi_hotkey_task
);
2204 tpacpi_hotkey_task
= NULL
;
2205 mutex_lock(&hotkey_thread_mutex
);
2206 /* at this point, the thread did exit */
2207 mutex_unlock(&hotkey_thread_mutex
);
2211 /* call with hotkey_mutex held */
2212 static void hotkey_poll_setup(bool may_warn
)
2214 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2215 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2217 if (hotkey_poll_freq
> 0 &&
2218 (poll_driver_mask
||
2219 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2220 if (!tpacpi_hotkey_task
) {
2221 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2222 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2223 if (IS_ERR(tpacpi_hotkey_task
)) {
2224 tpacpi_hotkey_task
= NULL
;
2226 "could not create kernel thread "
2227 "for hotkey polling\n");
2231 hotkey_poll_stop_sync();
2232 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2233 hotkey_poll_freq
== 0) {
2234 printk(TPACPI_NOTICE
2235 "hot keys 0x%08x and/or events 0x%08x "
2236 "require polling, which is currently "
2238 poll_user_mask
, poll_driver_mask
);
2243 static void hotkey_poll_setup_safe(bool may_warn
)
2245 mutex_lock(&hotkey_mutex
);
2246 hotkey_poll_setup(may_warn
);
2247 mutex_unlock(&hotkey_mutex
);
2250 /* call with hotkey_mutex held */
2251 static void hotkey_poll_set_freq(unsigned int freq
)
2254 hotkey_poll_stop_sync();
2256 hotkey_poll_freq
= freq
;
2259 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2261 static void hotkey_poll_setup_safe(bool __unused
)
2265 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2267 static int hotkey_inputdev_open(struct input_dev
*dev
)
2269 switch (tpacpi_lifecycle
) {
2270 case TPACPI_LIFE_INIT
:
2272 * hotkey_init will call hotkey_poll_setup_safe
2273 * at the appropriate moment
2276 case TPACPI_LIFE_EXITING
:
2278 case TPACPI_LIFE_RUNNING
:
2279 hotkey_poll_setup_safe(false);
2283 /* Should only happen if tpacpi_lifecycle is corrupt */
2288 static void hotkey_inputdev_close(struct input_dev
*dev
)
2290 /* disable hotkey polling when possible */
2291 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
&&
2292 !(hotkey_source_mask
& hotkey_driver_mask
))
2293 hotkey_poll_setup_safe(false);
2296 /* sysfs hotkey enable ------------------------------------------------- */
2297 static ssize_t
hotkey_enable_show(struct device
*dev
,
2298 struct device_attribute
*attr
,
2303 printk_deprecated_attribute("hotkey_enable",
2304 "Hotkey reporting is always enabled");
2306 res
= hotkey_status_get(&status
);
2310 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2313 static ssize_t
hotkey_enable_store(struct device
*dev
,
2314 struct device_attribute
*attr
,
2315 const char *buf
, size_t count
)
2319 printk_deprecated_attribute("hotkey_enable",
2320 "Hotkeys can be disabled through hotkey_mask");
2322 if (parse_strtoul(buf
, 1, &t
))
2331 static struct device_attribute dev_attr_hotkey_enable
=
2332 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2333 hotkey_enable_show
, hotkey_enable_store
);
2335 /* sysfs hotkey mask --------------------------------------------------- */
2336 static ssize_t
hotkey_mask_show(struct device
*dev
,
2337 struct device_attribute
*attr
,
2340 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2343 static ssize_t
hotkey_mask_store(struct device
*dev
,
2344 struct device_attribute
*attr
,
2345 const char *buf
, size_t count
)
2350 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2353 if (mutex_lock_killable(&hotkey_mutex
))
2354 return -ERESTARTSYS
;
2356 res
= hotkey_user_mask_set(t
);
2358 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2359 hotkey_poll_setup(true);
2362 mutex_unlock(&hotkey_mutex
);
2364 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2366 return (res
) ? res
: count
;
2369 static struct device_attribute dev_attr_hotkey_mask
=
2370 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2371 hotkey_mask_show
, hotkey_mask_store
);
2373 /* sysfs hotkey bios_enabled ------------------------------------------- */
2374 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2375 struct device_attribute
*attr
,
2378 return sprintf(buf
, "0\n");
2381 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2382 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2384 /* sysfs hotkey bios_mask ---------------------------------------------- */
2385 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2386 struct device_attribute
*attr
,
2389 printk_deprecated_attribute("hotkey_bios_mask",
2390 "This attribute is useless.");
2391 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2394 static struct device_attribute dev_attr_hotkey_bios_mask
=
2395 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2397 /* sysfs hotkey all_mask ----------------------------------------------- */
2398 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2399 struct device_attribute
*attr
,
2402 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2403 hotkey_all_mask
| hotkey_source_mask
);
2406 static struct device_attribute dev_attr_hotkey_all_mask
=
2407 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2409 /* sysfs hotkey recommended_mask --------------------------------------- */
2410 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2411 struct device_attribute
*attr
,
2414 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2415 (hotkey_all_mask
| hotkey_source_mask
)
2416 & ~hotkey_reserved_mask
);
2419 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2420 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2421 hotkey_recommended_mask_show
, NULL
);
2423 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2425 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2426 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2427 struct device_attribute
*attr
,
2430 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2433 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2434 struct device_attribute
*attr
,
2435 const char *buf
, size_t count
)
2441 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2442 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2445 if (mutex_lock_killable(&hotkey_mutex
))
2446 return -ERESTARTSYS
;
2448 HOTKEY_CONFIG_CRITICAL_START
2449 hotkey_source_mask
= t
;
2450 HOTKEY_CONFIG_CRITICAL_END
2452 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2453 ~hotkey_source_mask
);
2454 hotkey_poll_setup(true);
2456 /* check if events needed by the driver got disabled */
2457 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2458 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2460 mutex_unlock(&hotkey_mutex
);
2463 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2464 "firmware event mask!\n");
2467 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2468 "some important events were disabled: "
2471 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2473 return (rc
< 0) ? rc
: count
;
2476 static struct device_attribute dev_attr_hotkey_source_mask
=
2477 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2478 hotkey_source_mask_show
, hotkey_source_mask_store
);
2480 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2481 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2482 struct device_attribute
*attr
,
2485 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2488 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2489 struct device_attribute
*attr
,
2490 const char *buf
, size_t count
)
2494 if (parse_strtoul(buf
, 25, &t
))
2497 if (mutex_lock_killable(&hotkey_mutex
))
2498 return -ERESTARTSYS
;
2500 hotkey_poll_set_freq(t
);
2501 hotkey_poll_setup(true);
2503 mutex_unlock(&hotkey_mutex
);
2505 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2510 static struct device_attribute dev_attr_hotkey_poll_freq
=
2511 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2512 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2514 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2516 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2517 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2518 struct device_attribute
*attr
,
2522 res
= hotkey_get_wlsw(&s
);
2526 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2529 static struct device_attribute dev_attr_hotkey_radio_sw
=
2530 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2532 static void hotkey_radio_sw_notify_change(void)
2534 if (tp_features
.hotkey_wlsw
)
2535 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2539 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2540 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2541 struct device_attribute
*attr
,
2545 res
= hotkey_get_tablet_mode(&s
);
2549 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2552 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2553 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2555 static void hotkey_tablet_mode_notify_change(void)
2557 if (tp_features
.hotkey_tablet
)
2558 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2559 "hotkey_tablet_mode");
2562 /* sysfs hotkey report_mode -------------------------------------------- */
2563 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2564 struct device_attribute
*attr
,
2567 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2568 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2571 static struct device_attribute dev_attr_hotkey_report_mode
=
2572 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2574 /* sysfs wakeup reason (pollable) -------------------------------------- */
2575 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2576 struct device_attribute
*attr
,
2579 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2582 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2583 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2585 static void hotkey_wakeup_reason_notify_change(void)
2587 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2591 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2592 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2593 struct device_attribute
*attr
,
2596 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2599 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2600 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2601 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2603 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2605 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2606 "wakeup_hotunplug_complete");
2609 /* --------------------------------------------------------------------- */
2611 static struct attribute
*hotkey_attributes
[] __initdata
= {
2612 &dev_attr_hotkey_enable
.attr
,
2613 &dev_attr_hotkey_bios_enabled
.attr
,
2614 &dev_attr_hotkey_bios_mask
.attr
,
2615 &dev_attr_hotkey_report_mode
.attr
,
2616 &dev_attr_hotkey_wakeup_reason
.attr
,
2617 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2618 &dev_attr_hotkey_mask
.attr
,
2619 &dev_attr_hotkey_all_mask
.attr
,
2620 &dev_attr_hotkey_recommended_mask
.attr
,
2621 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2622 &dev_attr_hotkey_source_mask
.attr
,
2623 &dev_attr_hotkey_poll_freq
.attr
,
2627 static void bluetooth_update_rfk(void);
2628 static void wan_update_rfk(void);
2629 static void uwb_update_rfk(void);
2630 static void tpacpi_send_radiosw_update(void)
2634 /* Sync these BEFORE sending any rfkill events */
2635 if (tp_features
.bluetooth
)
2636 bluetooth_update_rfk();
2637 if (tp_features
.wan
)
2639 if (tp_features
.uwb
)
2642 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2643 mutex_lock(&tpacpi_inputdev_send_mutex
);
2645 input_report_switch(tpacpi_inputdev
,
2646 SW_RFKILL_ALL
, !!wlsw
);
2647 input_sync(tpacpi_inputdev
);
2649 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2651 hotkey_radio_sw_notify_change();
2654 static void hotkey_exit(void)
2656 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2657 mutex_lock(&hotkey_mutex
);
2658 hotkey_poll_stop_sync();
2659 mutex_unlock(&hotkey_mutex
);
2662 if (hotkey_dev_attributes
)
2663 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2665 kfree(hotkey_keycode_map
);
2667 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
2668 "restoring original HKEY status and mask\n");
2669 /* yes, there is a bitwise or below, we want the
2670 * functions to be called even if one of them fail */
2671 if (((tp_features
.hotkey_mask
&&
2672 hotkey_mask_set(hotkey_orig_mask
)) |
2673 hotkey_status_set(false)) != 0)
2675 "failed to restore hot key mask "
2676 "to BIOS defaults\n");
2679 static void __init
hotkey_unmap(const unsigned int scancode
)
2681 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
2682 clear_bit(hotkey_keycode_map
[scancode
],
2683 tpacpi_inputdev
->keybit
);
2684 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
2690 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
2693 #define TPACPI_HK_Q_INIMASK 0x0001
2695 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
2696 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
2697 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
2698 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
2699 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
2700 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
2701 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
2702 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
2703 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
2704 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
2705 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
2706 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
2707 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
2708 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
2709 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
2710 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
2711 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
2712 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
2713 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
2714 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
2717 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2719 /* Requirements for changing the default keymaps:
2721 * 1. Many of the keys are mapped to KEY_RESERVED for very
2722 * good reasons. Do not change them unless you have deep
2723 * knowledge on the IBM and Lenovo ThinkPad firmware for
2724 * the various ThinkPad models. The driver behaves
2725 * differently for KEY_RESERVED: such keys have their
2726 * hot key mask *unset* in mask_recommended, and also
2727 * in the initial hot key mask programmed into the
2728 * firmware at driver load time, which means the firm-
2729 * ware may react very differently if you change them to
2732 * 2. You must be subscribed to the linux-thinkpad and
2733 * ibm-acpi-devel mailing lists, and you should read the
2734 * list archives since 2007 if you want to change the
2735 * keymaps. This requirement exists so that you will
2736 * know the past history of problems with the thinkpad-
2737 * acpi driver keymaps, and also that you will be
2738 * listening to any bug reports;
2740 * 3. Do not send thinkpad-acpi specific patches directly to
2741 * for merging, *ever*. Send them to the linux-acpi
2742 * mailinglist for comments. Merging is to be done only
2743 * through acpi-test and the ACPI maintainer.
2745 * If the above is too much to ask, don't change the keymap.
2746 * Ask the thinkpad-acpi maintainer to do it, instead.
2748 static u16 ibm_keycode_map
[] __initdata
= {
2749 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2750 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2751 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2752 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2754 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2755 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2756 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2757 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2759 /* brightness: firmware always reacts to them */
2760 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2761 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2763 /* Thinklight: firmware always react to it */
2764 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2766 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2767 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2769 /* Volume: firmware always react to it and reprograms
2770 * the built-in *extra* mixer. Never map it to control
2771 * another mixer by default. */
2772 KEY_RESERVED
, /* 0x14: VOLUME UP */
2773 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2774 KEY_RESERVED
, /* 0x16: MUTE */
2776 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2778 /* (assignments unknown, please report if found) */
2779 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2780 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2782 static u16 lenovo_keycode_map
[] __initdata
= {
2783 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2784 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2785 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2786 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2788 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2789 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2790 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2791 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2793 /* These should be enabled --only-- when ACPI video
2794 * is disabled (i.e. in "vendor" mode), and are handled
2795 * in a special way by the init code */
2796 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
2797 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
2799 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2801 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2802 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2804 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2805 * react to it and reprograms the built-in *extra* mixer.
2806 * Never map it to control another mixer by default.
2808 * T60?, T61, R60?, R61: firmware and EC tries to send
2809 * these over the regular keyboard, so these are no-ops,
2810 * but there are still weird bugs re. MUTE, so do not
2811 * change unless you get test reports from all Lenovo
2812 * models. May cause the BIOS to interfere with the
2815 KEY_RESERVED
, /* 0x14: VOLUME UP */
2816 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2817 KEY_RESERVED
, /* 0x16: MUTE */
2819 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2821 /* (assignments unknown, please report if found) */
2822 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2823 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2826 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2827 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2828 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2834 unsigned long quirks
;
2836 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2837 "initializing hotkey subdriver\n");
2839 BUG_ON(!tpacpi_inputdev
);
2840 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2841 tpacpi_inputdev
->close
!= NULL
);
2843 TPACPI_ACPIHANDLE_INIT(hkey
);
2844 mutex_init(&hotkey_mutex
);
2846 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2847 mutex_init(&hotkey_thread_mutex
);
2848 mutex_init(&hotkey_thread_data_mutex
);
2851 /* hotkey not supported on 570 */
2852 tp_features
.hotkey
= hkey_handle
!= NULL
;
2854 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2856 str_supported(tp_features
.hotkey
));
2858 if (!tp_features
.hotkey
)
2861 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
2862 ARRAY_SIZE(tpacpi_hotkey_qtable
));
2864 tpacpi_disable_brightness_delay();
2866 /* MUST have enough space for all attributes to be added to
2867 * hotkey_dev_attributes */
2868 hotkey_dev_attributes
= create_attr_set(
2869 ARRAY_SIZE(hotkey_attributes
) + 2,
2871 if (!hotkey_dev_attributes
)
2873 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2875 ARRAY_SIZE(hotkey_attributes
));
2879 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
2880 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2881 for HKEY interface version 0x100 */
2882 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2883 if ((hkeyv
>> 8) != 1) {
2884 printk(TPACPI_ERR
"unknown version of the "
2885 "HKEY interface: 0x%x\n", hkeyv
);
2886 printk(TPACPI_ERR
"please report this to %s\n",
2890 * MHKV 0x100 in A31, R40, R40e,
2891 * T4x, X31, and later
2893 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2894 "firmware HKEY interface version: 0x%x\n",
2897 /* Paranoia check AND init hotkey_all_mask */
2898 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2901 "missing MHKA handler, "
2902 "please report this to %s\n",
2904 /* Fallback: pre-init for FN+F3,F4,F12 */
2905 hotkey_all_mask
= 0x080cU
;
2907 tp_features
.hotkey_mask
= 1;
2912 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2913 "hotkey masks are %s\n",
2914 str_supported(tp_features
.hotkey_mask
));
2916 /* Init hotkey_all_mask if not initialized yet */
2917 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
2918 (quirks
& TPACPI_HK_Q_INIMASK
))
2919 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
2921 /* Init hotkey_acpi_mask and hotkey_orig_mask */
2922 if (tp_features
.hotkey_mask
) {
2923 /* hotkey_source_mask *must* be zero for
2924 * the first hotkey_mask_get to return hotkey_orig_mask */
2925 res
= hotkey_mask_get();
2929 hotkey_orig_mask
= hotkey_acpi_mask
;
2931 hotkey_orig_mask
= hotkey_all_mask
;
2932 hotkey_acpi_mask
= hotkey_all_mask
;
2935 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2937 tp_features
.hotkey_wlsw
= 1;
2939 "radio switch emulation enabled\n");
2942 /* Not all thinkpads have a hardware radio switch */
2943 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2944 tp_features
.hotkey_wlsw
= 1;
2946 "radio switch found; radios are %s\n",
2947 enabled(status
, 0));
2949 if (tp_features
.hotkey_wlsw
)
2950 res
= add_to_attr_set(hotkey_dev_attributes
,
2951 &dev_attr_hotkey_radio_sw
.attr
);
2953 /* For X41t, X60t, X61t Tablets... */
2954 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2955 tp_features
.hotkey_tablet
= 1;
2957 "possible tablet mode switch found; "
2958 "ThinkPad in %s mode\n",
2959 (status
& TP_HOTKEY_TABLET_MASK
)?
2960 "tablet" : "laptop");
2961 res
= add_to_attr_set(hotkey_dev_attributes
,
2962 &dev_attr_hotkey_tablet_mode
.attr
);
2966 res
= register_attr_set_with_sysfs(
2967 hotkey_dev_attributes
,
2968 &tpacpi_pdev
->dev
.kobj
);
2972 /* Set up key map */
2974 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2976 if (!hotkey_keycode_map
) {
2978 "failed to allocate memory for key map\n");
2983 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2984 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2985 "using Lenovo default hot key map\n");
2986 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2987 TPACPI_HOTKEY_MAP_SIZE
);
2989 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2990 "using IBM default hot key map\n");
2991 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2992 TPACPI_HOTKEY_MAP_SIZE
);
2995 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2996 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2997 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2998 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2999 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3000 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3001 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3002 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3003 set_bit(hotkey_keycode_map
[i
],
3004 tpacpi_inputdev
->keybit
);
3006 if (i
< sizeof(hotkey_reserved_mask
)*8)
3007 hotkey_reserved_mask
|= 1 << i
;
3011 if (tp_features
.hotkey_wlsw
) {
3012 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
3013 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
3015 if (tp_features
.hotkey_tablet
) {
3016 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
3017 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
3020 /* Do not issue duplicate brightness change events to
3022 if (!tp_features
.bright_acpimode
)
3023 /* update bright_acpimode... */
3024 tpacpi_check_std_acpi_brightness_support();
3026 if (tp_features
.bright_acpimode
) {
3028 "This ThinkPad has standard ACPI backlight "
3029 "brightness control, supported by the ACPI "
3031 printk(TPACPI_NOTICE
3032 "Disabling thinkpad-acpi brightness events "
3035 /* Disable brightness up/down on Lenovo thinkpads when
3036 * ACPI is handling them, otherwise it is plain impossible
3037 * for userspace to do something even remotely sane */
3038 hotkey_reserved_mask
|=
3039 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3040 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3041 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3042 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3045 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3046 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3048 & ~hotkey_reserved_mask
;
3050 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3051 "hotkey source mask 0x%08x, polling freq %u\n",
3052 hotkey_source_mask
, hotkey_poll_freq
);
3055 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3056 "enabling firmware HKEY event interface...\n");
3057 res
= hotkey_status_set(true);
3062 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3063 | hotkey_driver_mask
)
3064 & ~hotkey_source_mask
);
3065 if (res
< 0 && res
!= -ENXIO
) {
3069 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3070 & ~hotkey_reserved_mask
;
3071 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3072 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3073 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3075 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3076 "legacy ibm/hotkey event reporting over procfs %s\n",
3077 (hotkey_report_mode
< 2) ?
3078 "enabled" : "disabled");
3080 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3081 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3083 hotkey_poll_setup_safe(true);
3084 tpacpi_send_radiosw_update();
3085 tpacpi_input_send_tabletsw();
3090 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3091 hotkey_dev_attributes
= NULL
;
3093 return (res
< 0)? res
: 1;
3096 static bool hotkey_notify_hotkey(const u32 hkey
,
3098 bool *ignore_acpi_ev
)
3100 /* 0x1000-0x1FFF: key presses */
3101 unsigned int scancode
= hkey
& 0xfff;
3102 *send_acpi_ev
= true;
3103 *ignore_acpi_ev
= false;
3105 if (scancode
> 0 && scancode
< 0x21) {
3107 if (!(hotkey_source_mask
& (1 << scancode
))) {
3108 tpacpi_input_send_key_masked(scancode
);
3109 *send_acpi_ev
= false;
3111 *ignore_acpi_ev
= true;
3118 static bool hotkey_notify_wakeup(const u32 hkey
,
3120 bool *ignore_acpi_ev
)
3122 /* 0x2000-0x2FFF: Wakeup reason */
3123 *send_acpi_ev
= true;
3124 *ignore_acpi_ev
= false;
3127 case 0x2304: /* suspend, undock */
3128 case 0x2404: /* hibernation, undock */
3129 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3130 *ignore_acpi_ev
= true;
3133 case 0x2305: /* suspend, bay eject */
3134 case 0x2405: /* hibernation, bay eject */
3135 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3136 *ignore_acpi_ev
= true;
3139 case 0x2313: /* Battery on critical low level (S3) */
3140 case 0x2413: /* Battery on critical low level (S4) */
3142 "EMERGENCY WAKEUP: battery almost empty\n");
3143 /* how to auto-heal: */
3144 /* 2313: woke up from S3, go to S4/S5 */
3145 /* 2413: woke up from S4, go to S5 */
3152 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3154 "woke up due to a hot-unplug "
3156 hotkey_wakeup_reason_notify_change();
3161 static bool hotkey_notify_usrevent(const u32 hkey
,
3163 bool *ignore_acpi_ev
)
3165 /* 0x5000-0x5FFF: human interface helpers */
3166 *send_acpi_ev
= true;
3167 *ignore_acpi_ev
= false;
3170 case 0x500b: /* X61t: tablet pen inserted into bay */
3171 case 0x500c: /* X61t: tablet pen removed from bay */
3174 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
3175 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
3176 tpacpi_input_send_tabletsw();
3177 hotkey_tablet_mode_notify_change();
3178 *send_acpi_ev
= false;
3181 case 0x5001: /* Lid close */
3182 case 0x5002: /* Lid open */
3183 case 0x5010: /* brightness control */
3184 /* do not propagate these events */
3185 *ignore_acpi_ev
= true;
3193 static bool hotkey_notify_thermal(const u32 hkey
,
3195 bool *ignore_acpi_ev
)
3197 /* 0x6000-0x6FFF: thermal alarms */
3198 *send_acpi_ev
= true;
3199 *ignore_acpi_ev
= false;
3204 "THERMAL ALARM: battery is too hot!\n");
3205 /* recommended action: warn user through gui */
3209 "THERMAL EMERGENCY: battery is extremely hot!\n");
3210 /* recommended action: immediate sleep/hibernate */
3215 "a sensor reports something is too hot!\n");
3216 /* recommended action: warn user through gui, that */
3217 /* some internal component is too hot */
3221 "THERMAL EMERGENCY: "
3222 "a sensor reports something is extremely hot!\n");
3223 /* recommended action: immediate sleep/hibernate */
3227 "EC reports that Thermal Table has changed\n");
3228 /* recommended action: do nothing, we don't have
3229 * Lenovo ATM information */
3233 "THERMAL ALERT: unknown thermal alarm received\n");
3238 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3242 bool ignore_acpi_ev
;
3245 if (event
!= 0x80) {
3247 "unknown HKEY notification event %d\n", event
);
3248 /* forward it to userspace, maybe it knows how to handle it */
3249 acpi_bus_generate_netlink_event(
3250 ibm
->acpi
->device
->pnp
.device_class
,
3251 dev_name(&ibm
->acpi
->device
->dev
),
3257 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3258 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3267 send_acpi_ev
= true;
3268 ignore_acpi_ev
= false;
3270 switch (hkey
>> 12) {
3272 /* 0x1000-0x1FFF: key presses */
3273 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3277 /* 0x2000-0x2FFF: Wakeup reason */
3278 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3282 /* 0x3000-0x3FFF: bay-related wakeups */
3283 if (hkey
== 0x3003) {
3284 hotkey_autosleep_ack
= 1;
3287 hotkey_wakeup_hotunplug_complete_notify_change();
3294 /* 0x4000-0x4FFF: dock-related wakeups */
3295 if (hkey
== 0x4003) {
3296 hotkey_autosleep_ack
= 1;
3299 hotkey_wakeup_hotunplug_complete_notify_change();
3306 /* 0x5000-0x5FFF: human interface helpers */
3307 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3311 /* 0x6000-0x6FFF: thermal alarms */
3312 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3316 /* 0x7000-0x7FFF: misc */
3317 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
3318 tpacpi_send_radiosw_update();
3323 /* fallthrough to default */
3328 printk(TPACPI_NOTICE
3329 "unhandled HKEY event 0x%04x\n", hkey
);
3330 printk(TPACPI_NOTICE
3331 "please report the conditions when this "
3332 "event happened to %s\n", TPACPI_MAIL
);
3336 if (!ignore_acpi_ev
&&
3337 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3338 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3342 /* netlink events */
3343 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3344 acpi_bus_generate_netlink_event(
3345 ibm
->acpi
->device
->pnp
.device_class
,
3346 dev_name(&ibm
->acpi
->device
->dev
),
3352 static void hotkey_suspend(pm_message_t state
)
3354 /* Do these on suspend, we get the events on early resume! */
3355 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3356 hotkey_autosleep_ack
= 0;
3359 static void hotkey_resume(void)
3361 tpacpi_disable_brightness_delay();
3363 if (hotkey_status_set(true) < 0 ||
3364 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3366 "error while attempting to reset the event "
3367 "firmware interface\n");
3369 tpacpi_send_radiosw_update();
3370 hotkey_tablet_mode_notify_change();
3371 hotkey_wakeup_reason_notify_change();
3372 hotkey_wakeup_hotunplug_complete_notify_change();
3373 hotkey_poll_setup_safe(false);
3376 /* procfs -------------------------------------------------------------- */
3377 static int hotkey_read(char *p
)
3382 if (!tp_features
.hotkey
) {
3383 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3387 if (mutex_lock_killable(&hotkey_mutex
))
3388 return -ERESTARTSYS
;
3389 res
= hotkey_status_get(&status
);
3391 res
= hotkey_mask_get();
3392 mutex_unlock(&hotkey_mutex
);
3396 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
3397 if (hotkey_all_mask
) {
3398 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3399 len
+= sprintf(p
+ len
,
3400 "commands:\tenable, disable, reset, <mask>\n");
3402 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
3403 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
3409 static void hotkey_enabledisable_warn(bool enable
)
3411 tpacpi_log_usertask("procfs hotkey enable/disable");
3412 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3414 "hotkey enable/disable functionality has been "
3415 "removed from the driver. Hotkeys are always "
3418 "Please remove the hotkey=enable module "
3419 "parameter, it is deprecated. Hotkeys are always "
3423 static int hotkey_write(char *buf
)
3429 if (!tp_features
.hotkey
)
3432 if (mutex_lock_killable(&hotkey_mutex
))
3433 return -ERESTARTSYS
;
3435 mask
= hotkey_user_mask
;
3438 while ((cmd
= next_cmd(&buf
))) {
3439 if (strlencmp(cmd
, "enable") == 0) {
3440 hotkey_enabledisable_warn(1);
3441 } else if (strlencmp(cmd
, "disable") == 0) {
3442 hotkey_enabledisable_warn(0);
3444 } else if (strlencmp(cmd
, "reset") == 0) {
3445 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3446 & ~hotkey_reserved_mask
;
3447 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3449 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3458 tpacpi_disclose_usertask("procfs hotkey",
3459 "set mask to 0x%08x\n", mask
);
3460 res
= hotkey_user_mask_set(mask
);
3464 mutex_unlock(&hotkey_mutex
);
3468 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3469 {TPACPI_ACPI_HKEY_HID
, 0},
3473 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3474 .hid
= ibm_htk_device_ids
,
3475 .notify
= hotkey_notify
,
3476 .handle
= &hkey_handle
,
3477 .type
= ACPI_DEVICE_NOTIFY
,
3480 static struct ibm_struct hotkey_driver_data
= {
3482 .read
= hotkey_read
,
3483 .write
= hotkey_write
,
3484 .exit
= hotkey_exit
,
3485 .resume
= hotkey_resume
,
3486 .suspend
= hotkey_suspend
,
3487 .acpi
= &ibm_hotkey_acpidriver
,
3490 /*************************************************************************
3491 * Bluetooth subdriver
3495 /* ACPI GBDC/SBDC bits */
3496 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3497 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3498 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3503 /* ACPI \BLTH commands */
3504 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3505 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3506 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3507 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3508 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3511 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3513 static struct rfkill
*tpacpi_bluetooth_rfkill
;
3515 static void bluetooth_suspend(pm_message_t state
)
3517 /* Try to make sure radio will resume powered off */
3518 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3519 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
))
3520 vdbg_printk(TPACPI_DBG_RFKILL
,
3521 "bluetooth power down on resume request failed\n");
3524 static int bluetooth_get_radiosw(void)
3528 if (!tp_features
.bluetooth
)
3531 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
3532 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3533 return RFKILL_STATE_HARD_BLOCKED
;
3535 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3536 if (dbg_bluetoothemul
)
3537 return (tpacpi_bluetooth_emulstate
) ?
3538 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3541 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3544 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3545 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3548 static void bluetooth_update_rfk(void)
3552 if (!tpacpi_bluetooth_rfkill
)
3555 status
= bluetooth_get_radiosw();
3558 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
3560 vdbg_printk(TPACPI_DBG_RFKILL
,
3561 "forced rfkill state to %d\n",
3565 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
3569 if (!tp_features
.bluetooth
)
3572 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3573 * reason to risk weird behaviour. */
3574 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3578 vdbg_printk(TPACPI_DBG_RFKILL
,
3579 "will %s bluetooth\n", radio_on
? "enable" : "disable");
3581 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3582 if (dbg_bluetoothemul
) {
3583 tpacpi_bluetooth_emulstate
= !!radio_on
;
3585 bluetooth_update_rfk();
3590 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3592 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
3595 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3599 bluetooth_update_rfk();
3604 /* sysfs bluetooth enable ---------------------------------------------- */
3605 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3606 struct device_attribute
*attr
,
3611 printk_deprecated_rfkill_attribute("bluetooth_enable");
3613 status
= bluetooth_get_radiosw();
3617 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3618 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3621 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3622 struct device_attribute
*attr
,
3623 const char *buf
, size_t count
)
3628 printk_deprecated_rfkill_attribute("bluetooth_enable");
3630 if (parse_strtoul(buf
, 1, &t
))
3633 tpacpi_disclose_usertask("bluetooth_enable", "set to %ld\n", t
);
3635 res
= bluetooth_set_radiosw(t
, 1);
3637 return (res
) ? res
: count
;
3640 static struct device_attribute dev_attr_bluetooth_enable
=
3641 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3642 bluetooth_enable_show
, bluetooth_enable_store
);
3644 /* --------------------------------------------------------------------- */
3646 static struct attribute
*bluetooth_attributes
[] = {
3647 &dev_attr_bluetooth_enable
.attr
,
3651 static const struct attribute_group bluetooth_attr_group
= {
3652 .attrs
= bluetooth_attributes
,
3655 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
3657 int bts
= bluetooth_get_radiosw();
3666 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
3668 dbg_printk(TPACPI_DBG_RFKILL
,
3669 "request to change radio state to %d\n", state
);
3670 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3673 static void bluetooth_shutdown(void)
3675 /* Order firmware to save current state to NVRAM */
3676 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3677 TP_ACPI_BLTH_SAVE_STATE
))
3678 printk(TPACPI_NOTICE
3679 "failed to save bluetooth state to NVRAM\n");
3681 vdbg_printk(TPACPI_DBG_RFKILL
,
3682 "bluestooth state saved to NVRAM\n");
3685 static void bluetooth_exit(void)
3687 bluetooth_shutdown();
3689 if (tpacpi_bluetooth_rfkill
)
3690 rfkill_unregister(tpacpi_bluetooth_rfkill
);
3692 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3693 &bluetooth_attr_group
);
3696 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3701 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3702 "initializing bluetooth subdriver\n");
3704 TPACPI_ACPIHANDLE_INIT(hkey
);
3706 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3707 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3708 tp_features
.bluetooth
= hkey_handle
&&
3709 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3711 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3712 "bluetooth is %s, status 0x%02x\n",
3713 str_supported(tp_features
.bluetooth
),
3716 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3717 if (dbg_bluetoothemul
) {
3718 tp_features
.bluetooth
= 1;
3720 "bluetooth switch emulation enabled\n");
3723 if (tp_features
.bluetooth
&&
3724 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
3725 /* no bluetooth hardware present in system */
3726 tp_features
.bluetooth
= 0;
3727 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3728 "bluetooth hardware not installed\n");
3731 if (!tp_features
.bluetooth
)
3734 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3735 &bluetooth_attr_group
);
3739 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3740 &tpacpi_bluetooth_rfkill
,
3741 RFKILL_TYPE_BLUETOOTH
,
3742 TPACPI_RFK_BLUETOOTH_SW_NAME
,
3744 tpacpi_bluetooth_rfk_set
,
3745 tpacpi_bluetooth_rfk_get
);
3754 /* procfs -------------------------------------------------------------- */
3755 static int bluetooth_read(char *p
)
3758 int status
= bluetooth_get_radiosw();
3760 if (!tp_features
.bluetooth
)
3761 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3763 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3764 (status
== RFKILL_STATE_UNBLOCKED
) ?
3765 "enabled" : "disabled");
3766 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3772 static int bluetooth_write(char *buf
)
3777 if (!tp_features
.bluetooth
)
3780 while ((cmd
= next_cmd(&buf
))) {
3781 if (strlencmp(cmd
, "enable") == 0) {
3783 } else if (strlencmp(cmd
, "disable") == 0) {
3790 tpacpi_disclose_usertask("procfs bluetooth",
3792 state
? "enable" : "disable");
3793 bluetooth_set_radiosw(state
, 1);
3799 static struct ibm_struct bluetooth_driver_data
= {
3800 .name
= "bluetooth",
3801 .read
= bluetooth_read
,
3802 .write
= bluetooth_write
,
3803 .exit
= bluetooth_exit
,
3804 .suspend
= bluetooth_suspend
,
3805 .shutdown
= bluetooth_shutdown
,
3808 /*************************************************************************
3813 /* ACPI GWAN/SWAN bits */
3814 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3815 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3816 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3820 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
3822 static struct rfkill
*tpacpi_wan_rfkill
;
3824 static void wan_suspend(pm_message_t state
)
3826 /* Try to make sure radio will resume powered off */
3827 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3828 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
))
3829 vdbg_printk(TPACPI_DBG_RFKILL
,
3830 "WWAN power down on resume request failed\n");
3833 static int wan_get_radiosw(void)
3837 if (!tp_features
.wan
)
3840 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3841 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3842 return RFKILL_STATE_HARD_BLOCKED
;
3844 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3846 return (tpacpi_wwan_emulstate
) ?
3847 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3850 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3853 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3854 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3857 static void wan_update_rfk(void)
3861 if (!tpacpi_wan_rfkill
)
3864 status
= wan_get_radiosw();
3867 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3869 vdbg_printk(TPACPI_DBG_RFKILL
,
3870 "forced rfkill state to %d\n",
3874 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3878 if (!tp_features
.wan
)
3881 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3882 * reason to risk weird behaviour. */
3883 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3887 vdbg_printk(TPACPI_DBG_RFKILL
,
3888 "will %s WWAN\n", radio_on
? "enable" : "disable");
3890 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3892 tpacpi_wwan_emulstate
= !!radio_on
;
3899 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3901 status
= TP_ACPI_WANCARD_RADIOSSW
;
3904 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3913 /* sysfs wan enable ---------------------------------------------------- */
3914 static ssize_t
wan_enable_show(struct device
*dev
,
3915 struct device_attribute
*attr
,
3920 printk_deprecated_rfkill_attribute("wwan_enable");
3922 status
= wan_get_radiosw();
3926 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3927 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3930 static ssize_t
wan_enable_store(struct device
*dev
,
3931 struct device_attribute
*attr
,
3932 const char *buf
, size_t count
)
3937 printk_deprecated_rfkill_attribute("wwan_enable");
3939 if (parse_strtoul(buf
, 1, &t
))
3942 tpacpi_disclose_usertask("wwan_enable", "set to %ld\n", t
);
3944 res
= wan_set_radiosw(t
, 1);
3946 return (res
) ? res
: count
;
3949 static struct device_attribute dev_attr_wan_enable
=
3950 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
3951 wan_enable_show
, wan_enable_store
);
3953 /* --------------------------------------------------------------------- */
3955 static struct attribute
*wan_attributes
[] = {
3956 &dev_attr_wan_enable
.attr
,
3960 static const struct attribute_group wan_attr_group
= {
3961 .attrs
= wan_attributes
,
3964 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
3966 int wans
= wan_get_radiosw();
3975 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
3977 dbg_printk(TPACPI_DBG_RFKILL
,
3978 "request to change radio state to %d\n", state
);
3979 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3982 static void wan_shutdown(void)
3984 /* Order firmware to save current state to NVRAM */
3985 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
3986 TP_ACPI_WGSV_SAVE_STATE
))
3987 printk(TPACPI_NOTICE
3988 "failed to save WWAN state to NVRAM\n");
3990 vdbg_printk(TPACPI_DBG_RFKILL
,
3991 "WWAN state saved to NVRAM\n");
3994 static void wan_exit(void)
3998 if (tpacpi_wan_rfkill
)
3999 rfkill_unregister(tpacpi_wan_rfkill
);
4001 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4005 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4010 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4011 "initializing wan subdriver\n");
4013 TPACPI_ACPIHANDLE_INIT(hkey
);
4015 tp_features
.wan
= hkey_handle
&&
4016 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4018 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4019 "wan is %s, status 0x%02x\n",
4020 str_supported(tp_features
.wan
),
4023 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4025 tp_features
.wan
= 1;
4027 "wwan switch emulation enabled\n");
4030 if (tp_features
.wan
&&
4031 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4032 /* no wan hardware present in system */
4033 tp_features
.wan
= 0;
4034 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4035 "wan hardware not installed\n");
4038 if (!tp_features
.wan
)
4041 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4046 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4049 TPACPI_RFK_WWAN_SW_NAME
,
4052 tpacpi_wan_rfk_get
);
4061 /* procfs -------------------------------------------------------------- */
4062 static int wan_read(char *p
)
4065 int status
= wan_get_radiosw();
4067 tpacpi_disclose_usertask("procfs wan", "read");
4069 if (!tp_features
.wan
)
4070 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4072 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4073 (status
== RFKILL_STATE_UNBLOCKED
) ?
4074 "enabled" : "disabled");
4075 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
4081 static int wan_write(char *buf
)
4086 if (!tp_features
.wan
)
4089 while ((cmd
= next_cmd(&buf
))) {
4090 if (strlencmp(cmd
, "enable") == 0) {
4092 } else if (strlencmp(cmd
, "disable") == 0) {
4099 tpacpi_disclose_usertask("procfs wan",
4101 state
? "enable" : "disable");
4102 wan_set_radiosw(state
, 1);
4108 static struct ibm_struct wan_driver_data
= {
4113 .suspend
= wan_suspend
,
4114 .shutdown
= wan_shutdown
,
4117 /*************************************************************************
4122 /* ACPI GUWB/SUWB bits */
4123 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4124 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4127 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4129 static struct rfkill
*tpacpi_uwb_rfkill
;
4131 static int uwb_get_radiosw(void)
4135 if (!tp_features
.uwb
)
4138 /* WLSW overrides UWB in firmware/hardware, reflect that */
4139 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
4140 return RFKILL_STATE_HARD_BLOCKED
;
4142 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4144 return (tpacpi_uwb_emulstate
) ?
4145 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
4148 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4151 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4152 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
4155 static void uwb_update_rfk(void)
4159 if (!tpacpi_uwb_rfkill
)
4162 status
= uwb_get_radiosw();
4165 rfkill_force_state(tpacpi_uwb_rfkill
, status
);
4167 vdbg_printk(TPACPI_DBG_RFKILL
,
4168 "forced rfkill state to %d\n",
4172 static int uwb_set_radiosw(int radio_on
, int update_rfk
)
4176 if (!tp_features
.uwb
)
4179 /* WLSW overrides UWB in firmware/hardware, but there is no
4180 * reason to risk weird behaviour. */
4181 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
4185 vdbg_printk(TPACPI_DBG_RFKILL
,
4186 "will %s UWB\n", radio_on
? "enable" : "disable");
4188 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4190 tpacpi_uwb_emulstate
= !!radio_on
;
4197 status
= (radio_on
) ? TP_ACPI_UWB_RADIOSSW
: 0;
4198 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4207 /* --------------------------------------------------------------------- */
4209 static int tpacpi_uwb_rfk_get(void *data
, enum rfkill_state
*state
)
4211 int uwbs
= uwb_get_radiosw();
4220 static int tpacpi_uwb_rfk_set(void *data
, enum rfkill_state state
)
4222 dbg_printk(TPACPI_DBG_RFKILL
,
4223 "request to change radio state to %d\n", state
);
4224 return uwb_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
4227 static void uwb_exit(void)
4229 if (tpacpi_uwb_rfkill
)
4230 rfkill_unregister(tpacpi_uwb_rfkill
);
4233 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4238 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4239 "initializing uwb subdriver\n");
4241 TPACPI_ACPIHANDLE_INIT(hkey
);
4243 tp_features
.uwb
= hkey_handle
&&
4244 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4246 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4247 "uwb is %s, status 0x%02x\n",
4248 str_supported(tp_features
.uwb
),
4251 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4253 tp_features
.uwb
= 1;
4255 "uwb switch emulation enabled\n");
4258 if (tp_features
.uwb
&&
4259 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4260 /* no uwb hardware present in system */
4261 tp_features
.uwb
= 0;
4262 dbg_printk(TPACPI_DBG_INIT
,
4263 "uwb hardware not installed\n");
4266 if (!tp_features
.uwb
)
4269 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4272 TPACPI_RFK_UWB_SW_NAME
,
4275 tpacpi_uwb_rfk_get
);
4280 static struct ibm_struct uwb_driver_data
= {
4283 .flags
.experimental
= 1,
4286 /*************************************************************************
4290 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4292 enum video_access_mode
{
4293 TPACPI_VIDEO_NONE
= 0,
4294 TPACPI_VIDEO_570
, /* 570 */
4295 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4296 TPACPI_VIDEO_NEW
, /* all others */
4299 enum { /* video status flags, based on VIDEO_570 */
4300 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4301 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4302 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4305 enum { /* TPACPI_VIDEO_570 constants */
4306 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4307 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4308 * video_status_flags */
4309 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4310 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4313 static enum video_access_mode video_supported
;
4314 static int video_orig_autosw
;
4316 static int video_autosw_get(void);
4317 static int video_autosw_set(int enable
);
4319 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4321 static int __init
video_init(struct ibm_init_struct
*iibm
)
4325 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4327 TPACPI_ACPIHANDLE_INIT(vid
);
4328 TPACPI_ACPIHANDLE_INIT(vid2
);
4330 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4331 /* G41, assume IVGA doesn't change */
4332 vid_handle
= vid2_handle
;
4335 /* video switching not supported on R30, R31 */
4336 video_supported
= TPACPI_VIDEO_NONE
;
4337 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4339 video_supported
= TPACPI_VIDEO_570
;
4340 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4341 /* 600e/x, 770e, 770x */
4342 video_supported
= TPACPI_VIDEO_770
;
4345 video_supported
= TPACPI_VIDEO_NEW
;
4347 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4348 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4351 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4354 static void video_exit(void)
4356 dbg_printk(TPACPI_DBG_EXIT
,
4357 "restoring original video autoswitch mode\n");
4358 if (video_autosw_set(video_orig_autosw
))
4359 printk(TPACPI_ERR
"error while trying to restore original "
4360 "video autoswitch mode\n");
4363 static int video_outputsw_get(void)
4368 switch (video_supported
) {
4369 case TPACPI_VIDEO_570
:
4370 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4371 TP_ACPI_VIDEO_570_PHSCMD
))
4373 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4375 case TPACPI_VIDEO_770
:
4376 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4379 status
|= TP_ACPI_VIDEO_S_LCD
;
4380 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4383 status
|= TP_ACPI_VIDEO_S_CRT
;
4385 case TPACPI_VIDEO_NEW
:
4386 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4387 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4390 status
|= TP_ACPI_VIDEO_S_CRT
;
4392 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4393 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4396 status
|= TP_ACPI_VIDEO_S_LCD
;
4397 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4400 status
|= TP_ACPI_VIDEO_S_DVI
;
4409 static int video_outputsw_set(int status
)
4414 switch (video_supported
) {
4415 case TPACPI_VIDEO_570
:
4416 res
= acpi_evalf(NULL
, NULL
,
4417 "\\_SB.PHS2", "vdd",
4418 TP_ACPI_VIDEO_570_PHS2CMD
,
4419 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4421 case TPACPI_VIDEO_770
:
4422 autosw
= video_autosw_get();
4426 res
= video_autosw_set(1);
4429 res
= acpi_evalf(vid_handle
, NULL
,
4430 "ASWT", "vdd", status
* 0x100, 0);
4431 if (!autosw
&& video_autosw_set(autosw
)) {
4433 "video auto-switch left enabled due to error\n");
4437 case TPACPI_VIDEO_NEW
:
4438 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4439 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4445 return (res
)? 0 : -EIO
;
4448 static int video_autosw_get(void)
4452 switch (video_supported
) {
4453 case TPACPI_VIDEO_570
:
4454 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4457 case TPACPI_VIDEO_770
:
4458 case TPACPI_VIDEO_NEW
:
4459 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4469 static int video_autosw_set(int enable
)
4471 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4476 static int video_outputsw_cycle(void)
4478 int autosw
= video_autosw_get();
4484 switch (video_supported
) {
4485 case TPACPI_VIDEO_570
:
4486 res
= video_autosw_set(1);
4489 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4491 case TPACPI_VIDEO_770
:
4492 case TPACPI_VIDEO_NEW
:
4493 res
= video_autosw_set(1);
4496 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4501 if (!autosw
&& video_autosw_set(autosw
)) {
4503 "video auto-switch left enabled due to error\n");
4507 return (res
)? 0 : -EIO
;
4510 static int video_expand_toggle(void)
4512 switch (video_supported
) {
4513 case TPACPI_VIDEO_570
:
4514 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4516 case TPACPI_VIDEO_770
:
4517 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4519 case TPACPI_VIDEO_NEW
:
4520 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4528 static int video_read(char *p
)
4533 if (video_supported
== TPACPI_VIDEO_NONE
) {
4534 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4538 status
= video_outputsw_get();
4542 autosw
= video_autosw_get();
4546 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4547 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
4548 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
4549 if (video_supported
== TPACPI_VIDEO_NEW
)
4550 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
4551 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
4552 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
4553 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
4554 if (video_supported
== TPACPI_VIDEO_NEW
)
4555 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
4556 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
4557 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
4562 static int video_write(char *buf
)
4565 int enable
, disable
, status
;
4568 if (video_supported
== TPACPI_VIDEO_NONE
)
4574 while ((cmd
= next_cmd(&buf
))) {
4575 if (strlencmp(cmd
, "lcd_enable") == 0) {
4576 enable
|= TP_ACPI_VIDEO_S_LCD
;
4577 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4578 disable
|= TP_ACPI_VIDEO_S_LCD
;
4579 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4580 enable
|= TP_ACPI_VIDEO_S_CRT
;
4581 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4582 disable
|= TP_ACPI_VIDEO_S_CRT
;
4583 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4584 strlencmp(cmd
, "dvi_enable") == 0) {
4585 enable
|= TP_ACPI_VIDEO_S_DVI
;
4586 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4587 strlencmp(cmd
, "dvi_disable") == 0) {
4588 disable
|= TP_ACPI_VIDEO_S_DVI
;
4589 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4590 res
= video_autosw_set(1);
4593 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4594 res
= video_autosw_set(0);
4597 } else if (strlencmp(cmd
, "video_switch") == 0) {
4598 res
= video_outputsw_cycle();
4601 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4602 res
= video_expand_toggle();
4609 if (enable
|| disable
) {
4610 status
= video_outputsw_get();
4613 res
= video_outputsw_set((status
& ~disable
) | enable
);
4621 static struct ibm_struct video_driver_data
= {
4624 .write
= video_write
,
4628 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4630 /*************************************************************************
4631 * Light (thinklight) subdriver
4634 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4635 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4637 static int light_get_status(void)
4641 if (tp_features
.light_status
) {
4642 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4650 static int light_set_status(int status
)
4654 if (tp_features
.light
) {
4656 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4658 TP_CMOS_THINKLIGHT_ON
:
4659 TP_CMOS_THINKLIGHT_OFF
);
4661 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4664 return (rc
)? 0 : -EIO
;
4670 static void light_set_status_worker(struct work_struct
*work
)
4672 struct tpacpi_led_classdev
*data
=
4673 container_of(work
, struct tpacpi_led_classdev
, work
);
4675 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4676 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4679 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4680 enum led_brightness brightness
)
4682 struct tpacpi_led_classdev
*data
=
4683 container_of(led_cdev
,
4684 struct tpacpi_led_classdev
,
4686 data
->new_state
= (brightness
!= LED_OFF
) ?
4687 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4688 queue_work(tpacpi_wq
, &data
->work
);
4691 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4693 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4696 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4698 .name
= "tpacpi::thinklight",
4699 .brightness_set
= &light_sysfs_set
,
4700 .brightness_get
= &light_sysfs_get
,
4704 static int __init
light_init(struct ibm_init_struct
*iibm
)
4708 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4710 TPACPI_ACPIHANDLE_INIT(ledb
);
4711 TPACPI_ACPIHANDLE_INIT(lght
);
4712 TPACPI_ACPIHANDLE_INIT(cmos
);
4713 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4715 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4716 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4718 if (tp_features
.light
)
4719 /* light status not supported on
4720 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4721 tp_features
.light_status
=
4722 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4724 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4725 str_supported(tp_features
.light
),
4726 str_supported(tp_features
.light_status
));
4728 if (!tp_features
.light
)
4731 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4732 &tpacpi_led_thinklight
.led_classdev
);
4735 tp_features
.light
= 0;
4736 tp_features
.light_status
= 0;
4744 static void light_exit(void)
4746 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4747 if (work_pending(&tpacpi_led_thinklight
.work
))
4748 flush_workqueue(tpacpi_wq
);
4751 static int light_read(char *p
)
4756 if (!tp_features
.light
) {
4757 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4758 } else if (!tp_features
.light_status
) {
4759 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
4760 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4762 status
= light_get_status();
4765 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
4766 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4772 static int light_write(char *buf
)
4777 if (!tp_features
.light
)
4780 while ((cmd
= next_cmd(&buf
))) {
4781 if (strlencmp(cmd
, "on") == 0) {
4783 } else if (strlencmp(cmd
, "off") == 0) {
4789 return light_set_status(newstatus
);
4792 static struct ibm_struct light_driver_data
= {
4795 .write
= light_write
,
4799 /*************************************************************************
4803 /* sysfs cmos_command -------------------------------------------------- */
4804 static ssize_t
cmos_command_store(struct device
*dev
,
4805 struct device_attribute
*attr
,
4806 const char *buf
, size_t count
)
4808 unsigned long cmos_cmd
;
4811 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4814 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4815 return (res
)? res
: count
;
4818 static struct device_attribute dev_attr_cmos_command
=
4819 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4821 /* --------------------------------------------------------------------- */
4823 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4827 vdbg_printk(TPACPI_DBG_INIT
,
4828 "initializing cmos commands subdriver\n");
4830 TPACPI_ACPIHANDLE_INIT(cmos
);
4832 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4833 str_supported(cmos_handle
!= NULL
));
4835 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4839 return (cmos_handle
)? 0 : 1;
4842 static void cmos_exit(void)
4844 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4847 static int cmos_read(char *p
)
4851 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4852 R30, R31, T20-22, X20-21 */
4854 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4856 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4857 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4863 static int cmos_write(char *buf
)
4868 while ((cmd
= next_cmd(&buf
))) {
4869 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4870 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4875 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4883 static struct ibm_struct cmos_driver_data
= {
4886 .write
= cmos_write
,
4890 /*************************************************************************
4894 enum led_access_mode
{
4895 TPACPI_LED_NONE
= 0,
4896 TPACPI_LED_570
, /* 570 */
4897 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4898 TPACPI_LED_NEW
, /* all others */
4901 enum { /* For TPACPI_LED_OLD */
4902 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4903 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4904 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4907 static enum led_access_mode led_supported
;
4909 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4910 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4911 /* T20-22, X20-21 */
4912 "LED", /* all others */
4915 #define TPACPI_LED_NUMLEDS 16
4916 static struct tpacpi_led_classdev
*tpacpi_leds
;
4917 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4918 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4919 /* there's a limit of 19 chars + NULL before 2.6.26 */
4921 "tpacpi:orange:batt",
4922 "tpacpi:green:batt",
4923 "tpacpi::dock_active",
4924 "tpacpi::bay_active",
4925 "tpacpi::dock_batt",
4926 "tpacpi::unknown_led",
4928 "tpacpi::dock_status1",
4929 "tpacpi::dock_status2",
4930 "tpacpi::unknown_led2",
4931 "tpacpi::unknown_led3",
4932 "tpacpi::thinkvantage",
4934 #define TPACPI_SAFE_LEDS 0x1081U
4936 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
4938 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
4941 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
4945 static int led_get_status(const unsigned int led
)
4948 enum led_status_t led_s
;
4950 switch (led_supported
) {
4951 case TPACPI_LED_570
:
4952 if (!acpi_evalf(ec_handle
,
4953 &status
, "GLED", "dd", 1 << led
))
4955 led_s
= (status
== 0)?
4960 tpacpi_led_state_cache
[led
] = led_s
;
4969 static int led_set_status(const unsigned int led
,
4970 const enum led_status_t ledstatus
)
4972 /* off, on, blink. Index is led_status_t */
4973 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
4974 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
4978 switch (led_supported
) {
4979 case TPACPI_LED_570
:
4981 if (unlikely(led
> 7))
4983 if (unlikely(tpacpi_is_led_restricted(led
)))
4985 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4986 (1 << led
), led_sled_arg1
[ledstatus
]))
4989 case TPACPI_LED_OLD
:
4990 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4991 if (unlikely(led
> 7))
4993 if (unlikely(tpacpi_is_led_restricted(led
)))
4995 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
4997 rc
= ec_write(TPACPI_LED_EC_HLBL
,
4998 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5000 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5001 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5003 case TPACPI_LED_NEW
:
5005 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5007 if (unlikely(tpacpi_is_led_restricted(led
)))
5009 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5010 led
, led_led_arg1
[ledstatus
]))
5018 tpacpi_led_state_cache
[led
] = ledstatus
;
5023 static void led_set_status_worker(struct work_struct
*work
)
5025 struct tpacpi_led_classdev
*data
=
5026 container_of(work
, struct tpacpi_led_classdev
, work
);
5028 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5029 led_set_status(data
->led
, data
->new_state
);
5032 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5033 enum led_brightness brightness
)
5035 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5036 struct tpacpi_led_classdev
, led_classdev
);
5038 if (brightness
== LED_OFF
)
5039 data
->new_state
= TPACPI_LED_OFF
;
5040 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5041 data
->new_state
= TPACPI_LED_ON
;
5043 data
->new_state
= TPACPI_LED_BLINK
;
5045 queue_work(tpacpi_wq
, &data
->work
);
5048 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5049 unsigned long *delay_on
, unsigned long *delay_off
)
5051 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5052 struct tpacpi_led_classdev
, led_classdev
);
5054 /* Can we choose the flash rate? */
5055 if (*delay_on
== 0 && *delay_off
== 0) {
5056 /* yes. set them to the hardware blink rate (1 Hz) */
5057 *delay_on
= 500; /* ms */
5058 *delay_off
= 500; /* ms */
5059 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5062 data
->new_state
= TPACPI_LED_BLINK
;
5063 queue_work(tpacpi_wq
, &data
->work
);
5068 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5072 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5073 struct tpacpi_led_classdev
, led_classdev
);
5075 rc
= led_get_status(data
->led
);
5077 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5078 rc
= LED_OFF
; /* no error handling in led class :( */
5085 static void led_exit(void)
5089 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5090 if (tpacpi_leds
[i
].led_classdev
.name
)
5091 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5097 static int __init
tpacpi_init_led(unsigned int led
)
5101 tpacpi_leds
[led
].led
= led
;
5103 /* LEDs with no name don't get registered */
5104 if (!tpacpi_led_names
[led
])
5107 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5108 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5109 if (led_supported
== TPACPI_LED_570
)
5110 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5113 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5115 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5117 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5118 &tpacpi_leds
[led
].led_classdev
);
5120 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5125 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5126 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5127 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5128 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5130 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5131 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5132 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5133 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5134 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5135 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5136 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5137 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5139 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5140 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5141 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5142 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5143 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5145 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5146 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5147 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5148 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5150 /* (1) - may have excess leds enabled on MSB */
5152 /* Defaults (order matters, keep last, don't reorder!) */
5154 .vendor
= PCI_VENDOR_ID_LENOVO
,
5155 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5158 { /* IBM ThinkPads with no EC version string */
5159 .vendor
= PCI_VENDOR_ID_IBM
,
5160 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5163 { /* IBM ThinkPads with EC version string */
5164 .vendor
= PCI_VENDOR_ID_IBM
,
5165 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5170 #undef TPACPI_LEDQ_IBM
5171 #undef TPACPI_LEDQ_LNV
5173 static int __init
led_init(struct ibm_init_struct
*iibm
)
5177 unsigned long useful_leds
;
5179 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5181 TPACPI_ACPIHANDLE_INIT(led
);
5184 /* led not supported on R30, R31 */
5185 led_supported
= TPACPI_LED_NONE
;
5186 else if (strlencmp(led_path
, "SLED") == 0)
5188 led_supported
= TPACPI_LED_570
;
5189 else if (strlencmp(led_path
, "SYSL") == 0)
5190 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5191 led_supported
= TPACPI_LED_OLD
;
5194 led_supported
= TPACPI_LED_NEW
;
5196 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5197 str_supported(led_supported
), led_supported
);
5199 if (led_supported
== TPACPI_LED_NONE
)
5202 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5205 printk(TPACPI_ERR
"Out of memory for LED data\n");
5209 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5210 ARRAY_SIZE(led_useful_qtable
));
5212 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5213 if (!tpacpi_is_led_restricted(i
) &&
5214 test_bit(i
, &useful_leds
)) {
5215 rc
= tpacpi_init_led(i
);
5223 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5224 printk(TPACPI_NOTICE
5225 "warning: userspace override of important "
5226 "firmware LEDs is enabled\n");
5231 #define str_led_status(s) \
5232 ((s) == TPACPI_LED_OFF ? "off" : \
5233 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5235 static int led_read(char *p
)
5239 if (!led_supported
) {
5240 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5243 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
5245 if (led_supported
== TPACPI_LED_570
) {
5248 for (i
= 0; i
< 8; i
++) {
5249 status
= led_get_status(i
);
5252 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
5253 i
, str_led_status(status
));
5257 len
+= sprintf(p
+ len
, "commands:\t"
5258 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5263 static int led_write(char *buf
)
5267 enum led_status_t s
;
5272 while ((cmd
= next_cmd(&buf
))) {
5273 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5276 if (strstr(cmd
, "off")) {
5278 } else if (strstr(cmd
, "on")) {
5280 } else if (strstr(cmd
, "blink")) {
5281 s
= TPACPI_LED_BLINK
;
5286 rc
= led_set_status(led
, s
);
5294 static struct ibm_struct led_driver_data
= {
5301 /*************************************************************************
5305 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5307 #define TPACPI_BEEP_Q1 0x0001
5309 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5310 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5311 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5314 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5316 unsigned long quirks
;
5318 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5320 TPACPI_ACPIHANDLE_INIT(beep
);
5322 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5323 str_supported(beep_handle
!= NULL
));
5325 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5326 ARRAY_SIZE(beep_quirk_table
));
5328 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5330 return (beep_handle
)? 0 : 1;
5333 static int beep_read(char *p
)
5338 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5340 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
5341 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5347 static int beep_write(char *buf
)
5355 while ((cmd
= next_cmd(&buf
))) {
5356 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5357 beep_cmd
>= 0 && beep_cmd
<= 17) {
5361 if (tp_features
.beep_needs_two_args
) {
5362 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5366 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5375 static struct ibm_struct beep_driver_data
= {
5378 .write
= beep_write
,
5381 /*************************************************************************
5385 enum thermal_access_mode
{
5386 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5387 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5388 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5389 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5390 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5393 enum { /* TPACPI_THERMAL_TPEC_* */
5394 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5395 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5396 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5399 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5400 struct ibm_thermal_sensors_struct
{
5401 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5404 static enum thermal_access_mode thermal_read_mode
;
5406 /* idx is zero-based */
5407 static int thermal_get_sensor(int idx
, s32
*value
)
5413 t
= TP_EC_THERMAL_TMP0
;
5415 switch (thermal_read_mode
) {
5416 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5417 case TPACPI_THERMAL_TPEC_16
:
5418 if (idx
>= 8 && idx
<= 15) {
5419 t
= TP_EC_THERMAL_TMP8
;
5424 case TPACPI_THERMAL_TPEC_8
:
5426 if (!acpi_ec_read(t
+ idx
, &tmp
))
5428 *value
= tmp
* 1000;
5433 case TPACPI_THERMAL_ACPI_UPDT
:
5435 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5436 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5438 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5440 *value
= (t
- 2732) * 100;
5445 case TPACPI_THERMAL_ACPI_TMP07
:
5447 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5448 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5450 if (t
> 127 || t
< -127)
5451 t
= TP_EC_THERMAL_TMP_NA
;
5457 case TPACPI_THERMAL_NONE
:
5465 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5476 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5479 for (i
= 0 ; i
< n
; i
++) {
5480 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5488 /* sysfs temp##_input -------------------------------------------------- */
5490 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5491 struct device_attribute
*attr
,
5494 struct sensor_device_attribute
*sensor_attr
=
5495 to_sensor_dev_attr(attr
);
5496 int idx
= sensor_attr
->index
;
5500 res
= thermal_get_sensor(idx
, &value
);
5503 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
5506 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5509 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5510 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5511 thermal_temp_input_show, NULL, _idxB)
5513 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5514 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5515 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5516 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5517 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5518 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5519 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5520 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5521 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5522 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5523 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5524 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5525 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5526 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5527 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5528 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5529 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5532 #define THERMAL_ATTRS(X) \
5533 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5535 static struct attribute
*thermal_temp_input_attr
[] = {
5555 static const struct attribute_group thermal_temp_input16_group
= {
5556 .attrs
= thermal_temp_input_attr
5559 static const struct attribute_group thermal_temp_input8_group
= {
5560 .attrs
= &thermal_temp_input_attr
[8]
5563 #undef THERMAL_SENSOR_ATTR_TEMP
5564 #undef THERMAL_ATTRS
5566 /* --------------------------------------------------------------------- */
5568 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5575 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5577 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5579 if (thinkpad_id
.ec_model
) {
5581 * Direct EC access mode: sensors at registers
5582 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5583 * non-implemented, thermal sensors return 0x80 when
5588 for (i
= 0; i
< 8; i
++) {
5589 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5595 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5603 /* This is sheer paranoia, but we handle it anyway */
5606 "ThinkPad ACPI EC access misbehaving, "
5607 "falling back to ACPI TMPx access "
5609 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5612 "ThinkPad ACPI EC access misbehaving, "
5613 "disabling thermal sensors access\n");
5614 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5619 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5621 } else if (acpi_tmp7
) {
5622 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5623 /* 600e/x, 770e, 770x */
5624 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5626 /* Standard ACPI TMPx access, max 8 sensors */
5627 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5630 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5631 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5634 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5635 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5638 switch (thermal_read_mode
) {
5639 case TPACPI_THERMAL_TPEC_16
:
5640 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5641 &thermal_temp_input16_group
);
5645 case TPACPI_THERMAL_TPEC_8
:
5646 case TPACPI_THERMAL_ACPI_TMP07
:
5647 case TPACPI_THERMAL_ACPI_UPDT
:
5648 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5649 &thermal_temp_input8_group
);
5653 case TPACPI_THERMAL_NONE
:
5661 static void thermal_exit(void)
5663 switch (thermal_read_mode
) {
5664 case TPACPI_THERMAL_TPEC_16
:
5665 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5666 &thermal_temp_input16_group
);
5668 case TPACPI_THERMAL_TPEC_8
:
5669 case TPACPI_THERMAL_ACPI_TMP07
:
5670 case TPACPI_THERMAL_ACPI_UPDT
:
5671 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5672 &thermal_temp_input16_group
);
5674 case TPACPI_THERMAL_NONE
:
5680 static int thermal_read(char *p
)
5684 struct ibm_thermal_sensors_struct t
;
5686 n
= thermal_get_sensors(&t
);
5687 if (unlikely(n
< 0))
5690 len
+= sprintf(p
+ len
, "temperatures:\t");
5693 for (i
= 0; i
< (n
- 1); i
++)
5694 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
5695 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
5697 len
+= sprintf(p
+ len
, "not supported\n");
5702 static struct ibm_struct thermal_driver_data
= {
5704 .read
= thermal_read
,
5705 .exit
= thermal_exit
,
5708 /*************************************************************************
5712 static u8 ecdump_regs
[256];
5714 static int ecdump_read(char *p
)
5720 len
+= sprintf(p
+ len
, "EC "
5721 " +00 +01 +02 +03 +04 +05 +06 +07"
5722 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5723 for (i
= 0; i
< 256; i
+= 16) {
5724 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
5725 for (j
= 0; j
< 16; j
++) {
5726 if (!acpi_ec_read(i
+ j
, &v
))
5728 if (v
!= ecdump_regs
[i
+ j
])
5729 len
+= sprintf(p
+ len
, " *%02x", v
);
5731 len
+= sprintf(p
+ len
, " %02x", v
);
5732 ecdump_regs
[i
+ j
] = v
;
5734 len
+= sprintf(p
+ len
, "\n");
5739 /* These are way too dangerous to advertise openly... */
5741 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
5742 " (<offset> is 00-ff, <value> is 00-ff)\n");
5743 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
5744 " (<offset> is 00-ff, <value> is 0-255)\n");
5749 static int ecdump_write(char *buf
)
5754 while ((cmd
= next_cmd(&buf
))) {
5755 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5757 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5761 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5762 if (!acpi_ec_write(i
, v
))
5771 static struct ibm_struct ecdump_driver_data
= {
5773 .read
= ecdump_read
,
5774 .write
= ecdump_write
,
5775 .flags
.experimental
= 1,
5778 /*************************************************************************
5779 * Backlight/brightness subdriver
5782 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5785 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5786 * CMOS NVRAM byte 0x5E, bits 0-3.
5788 * EC HBRV (0x31) has the following layout
5789 * Bit 7: unknown function
5790 * Bit 6: unknown function
5791 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5792 * Bit 4: must be set to zero to avoid problems
5793 * Bit 3-0: backlight brightness level
5795 * brightness_get_raw returns status data in the HBRV layout
5797 * WARNING: The X61 has been verified to use HBRV for something else, so
5798 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5799 * testing on the very early *60 Lenovo models...
5803 TP_EC_BACKLIGHT
= 0x31,
5805 /* TP_EC_BACKLIGHT bitmasks */
5806 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5807 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5808 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5811 enum tpacpi_brightness_access_mode
{
5812 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5813 TPACPI_BRGHT_MODE_EC
, /* EC control */
5814 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5815 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5816 TPACPI_BRGHT_MODE_MAX
5819 static struct backlight_device
*ibm_backlight_device
;
5821 static enum tpacpi_brightness_access_mode brightness_mode
=
5822 TPACPI_BRGHT_MODE_MAX
;
5824 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5826 static struct mutex brightness_mutex
;
5828 /* NVRAM brightness access,
5829 * call with brightness_mutex held! */
5830 static unsigned int tpacpi_brightness_nvram_get(void)
5834 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5835 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5836 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5837 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5842 static void tpacpi_brightness_checkpoint_nvram(void)
5847 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5850 vdbg_printk(TPACPI_DBG_BRGHT
,
5851 "trying to checkpoint backlight level to NVRAM...\n");
5853 if (mutex_lock_killable(&brightness_mutex
) < 0)
5856 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5858 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5859 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5861 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5862 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5863 /* NVRAM needs update */
5864 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5865 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5867 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5868 dbg_printk(TPACPI_DBG_BRGHT
,
5869 "updated NVRAM backlight level to %u (0x%02x)\n",
5870 (unsigned int) lec
, (unsigned int) b_nvram
);
5872 vdbg_printk(TPACPI_DBG_BRGHT
,
5873 "NVRAM backlight level already is %u (0x%02x)\n",
5874 (unsigned int) lec
, (unsigned int) b_nvram
);
5877 mutex_unlock(&brightness_mutex
);
5881 /* call with brightness_mutex held! */
5882 static int tpacpi_brightness_get_raw(int *status
)
5886 switch (brightness_mode
) {
5887 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5888 *status
= tpacpi_brightness_nvram_get();
5890 case TPACPI_BRGHT_MODE_EC
:
5891 case TPACPI_BRGHT_MODE_ECNVRAM
:
5892 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5901 /* call with brightness_mutex held! */
5902 /* do NOT call with illegal backlight level value */
5903 static int tpacpi_brightness_set_ec(unsigned int value
)
5907 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5910 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
5911 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
5912 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
5918 /* call with brightness_mutex held! */
5919 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
5922 unsigned int current_value
, i
;
5924 current_value
= tpacpi_brightness_nvram_get();
5926 if (value
== current_value
)
5929 cmos_cmd
= (value
> current_value
) ?
5930 TP_CMOS_BRIGHTNESS_UP
:
5931 TP_CMOS_BRIGHTNESS_DOWN
;
5932 inc
= (value
> current_value
) ? 1 : -1;
5934 for (i
= current_value
; i
!= value
; i
+= inc
)
5935 if (issue_thinkpad_cmos_command(cmos_cmd
))
5941 /* May return EINTR which can always be mapped to ERESTARTSYS */
5942 static int brightness_set(unsigned int value
)
5946 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
5950 vdbg_printk(TPACPI_DBG_BRGHT
,
5951 "set backlight level to %d\n", value
);
5953 res
= mutex_lock_killable(&brightness_mutex
);
5957 switch (brightness_mode
) {
5958 case TPACPI_BRGHT_MODE_EC
:
5959 case TPACPI_BRGHT_MODE_ECNVRAM
:
5960 res
= tpacpi_brightness_set_ec(value
);
5962 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5963 res
= tpacpi_brightness_set_ucmsstep(value
);
5969 mutex_unlock(&brightness_mutex
);
5973 /* sysfs backlight class ----------------------------------------------- */
5975 static int brightness_update_status(struct backlight_device
*bd
)
5977 unsigned int level
=
5978 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
5979 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
5980 bd
->props
.brightness
: 0;
5982 dbg_printk(TPACPI_DBG_BRGHT
,
5983 "backlight: attempt to set level to %d\n",
5986 /* it is the backlight class's job (caller) to handle
5987 * EINTR and other errors properly */
5988 return brightness_set(level
);
5991 static int brightness_get(struct backlight_device
*bd
)
5995 res
= mutex_lock_killable(&brightness_mutex
);
5999 res
= tpacpi_brightness_get_raw(&status
);
6001 mutex_unlock(&brightness_mutex
);
6006 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6009 static struct backlight_ops ibm_backlight_data
= {
6010 .get_brightness
= brightness_get
,
6011 .update_status
= brightness_update_status
,
6014 /* --------------------------------------------------------------------- */
6017 * These are only useful for models that have only one possibility
6018 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6021 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6022 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6023 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6025 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6026 /* Models with ATI GPUs known to require ECNVRAM mode */
6027 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6029 /* Models with ATI GPUs that can use ECNVRAM */
6030 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
),
6031 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6032 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6033 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6035 /* Models with Intel Extreme Graphics 2 */
6036 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
),
6037 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_NOEC
),
6038 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_NOEC
),
6040 /* Models with Intel GMA900 */
6041 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6042 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6043 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6046 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6049 unsigned long quirks
;
6051 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6053 mutex_init(&brightness_mutex
);
6055 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6056 ARRAY_SIZE(brightness_quirk_table
));
6059 * We always attempt to detect acpi support, so as to switch
6060 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6061 * going to publish a backlight interface
6063 b
= tpacpi_check_std_acpi_brightness_support();
6065 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
6066 printk(TPACPI_NOTICE
6067 "Lenovo BIOS switched to ACPI backlight "
6070 if (brightness_enable
> 1) {
6071 printk(TPACPI_NOTICE
6072 "standard ACPI backlight interface "
6073 "available, not loading native one...\n");
6078 if (!brightness_enable
) {
6079 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6080 "brightness support disabled by "
6081 "module parameter\n");
6087 "Unsupported brightness interface, "
6088 "please contact %s\n", TPACPI_MAIL
);
6092 tp_features
.bright_16levels
= 1;
6095 * Check for module parameter bogosity, note that we
6096 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6097 * able to detect "unspecified"
6099 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6102 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6103 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6104 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6105 if (quirks
& TPACPI_BRGHT_Q_EC
)
6106 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6108 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6110 dbg_printk(TPACPI_DBG_BRGHT
,
6111 "driver auto-selected brightness_mode=%d\n",
6116 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6117 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6118 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6121 if (tpacpi_brightness_get_raw(&b
) < 0)
6124 if (tp_features
.bright_16levels
)
6126 "detected a 16-level brightness capable ThinkPad\n");
6128 ibm_backlight_device
= backlight_device_register(
6129 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6130 &ibm_backlight_data
);
6131 if (IS_ERR(ibm_backlight_device
)) {
6132 int rc
= PTR_ERR(ibm_backlight_device
);
6133 ibm_backlight_device
= NULL
;
6134 printk(TPACPI_ERR
"Could not register backlight device\n");
6137 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6138 "brightness is supported\n");
6140 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6141 printk(TPACPI_NOTICE
6142 "brightness: will use unverified default: "
6143 "brightness_mode=%d\n", brightness_mode
);
6144 printk(TPACPI_NOTICE
6145 "brightness: please report to %s whether it works well "
6146 "or not on your ThinkPad\n", TPACPI_MAIL
);
6149 ibm_backlight_device
->props
.max_brightness
=
6150 (tp_features
.bright_16levels
)? 15 : 7;
6151 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6152 backlight_update_status(ibm_backlight_device
);
6157 static void brightness_suspend(pm_message_t state
)
6159 tpacpi_brightness_checkpoint_nvram();
6162 static void brightness_shutdown(void)
6164 tpacpi_brightness_checkpoint_nvram();
6167 static void brightness_exit(void)
6169 if (ibm_backlight_device
) {
6170 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6171 "calling backlight_device_unregister()\n");
6172 backlight_device_unregister(ibm_backlight_device
);
6175 tpacpi_brightness_checkpoint_nvram();
6178 static int brightness_read(char *p
)
6183 level
= brightness_get(NULL
);
6185 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
6187 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
6188 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
6189 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
6190 " (<level> is 0-%d)\n",
6191 (tp_features
.bright_16levels
) ? 15 : 7);
6197 static int brightness_write(char *buf
)
6202 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6204 level
= brightness_get(NULL
);
6208 while ((cmd
= next_cmd(&buf
))) {
6209 if (strlencmp(cmd
, "up") == 0) {
6210 if (level
< max_level
)
6212 } else if (strlencmp(cmd
, "down") == 0) {
6215 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6216 level
>= 0 && level
<= max_level
) {
6222 tpacpi_disclose_usertask("procfs brightness",
6223 "set level to %d\n", level
);
6226 * Now we know what the final level should be, so we try to set it.
6227 * Doing it this way makes the syscall restartable in case of EINTR
6229 rc
= brightness_set(level
);
6230 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6233 static struct ibm_struct brightness_driver_data
= {
6234 .name
= "brightness",
6235 .read
= brightness_read
,
6236 .write
= brightness_write
,
6237 .exit
= brightness_exit
,
6238 .suspend
= brightness_suspend
,
6239 .shutdown
= brightness_shutdown
,
6242 /*************************************************************************
6246 static int volume_offset
= 0x30;
6248 static int volume_read(char *p
)
6253 if (!acpi_ec_read(volume_offset
, &level
)) {
6254 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
6256 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
6257 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
6258 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
6259 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
6260 " (<level> is 0-15)\n");
6266 static int volume_write(char *buf
)
6268 int cmos_cmd
, inc
, i
;
6270 int new_level
, new_mute
;
6273 while ((cmd
= next_cmd(&buf
))) {
6274 if (!acpi_ec_read(volume_offset
, &level
))
6276 new_mute
= mute
= level
& 0x40;
6277 new_level
= level
= level
& 0xf;
6279 if (strlencmp(cmd
, "up") == 0) {
6283 new_level
= level
== 15 ? 15 : level
+ 1;
6284 } else if (strlencmp(cmd
, "down") == 0) {
6288 new_level
= level
== 0 ? 0 : level
- 1;
6289 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
6290 new_level
>= 0 && new_level
<= 15) {
6292 } else if (strlencmp(cmd
, "mute") == 0) {
6297 if (new_level
!= level
) {
6298 /* mute doesn't change */
6300 cmos_cmd
= (new_level
> level
) ?
6301 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
6302 inc
= new_level
> level
? 1 : -1;
6304 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
6305 !acpi_ec_write(volume_offset
, level
)))
6308 for (i
= level
; i
!= new_level
; i
+= inc
)
6309 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
6310 !acpi_ec_write(volume_offset
, i
+ inc
))
6314 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
6315 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
6320 if (new_mute
!= mute
) {
6321 /* level doesn't change */
6323 cmos_cmd
= (new_mute
) ?
6324 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
6326 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
6327 !acpi_ec_write(volume_offset
, level
+ new_mute
))
6335 static struct ibm_struct volume_driver_data
= {
6337 .read
= volume_read
,
6338 .write
= volume_write
,
6341 /*************************************************************************
6348 * TPACPI_FAN_RD_ACPI_GFAN:
6349 * ACPI GFAN method: returns fan level
6351 * see TPACPI_FAN_WR_ACPI_SFAN
6352 * EC 0x2f (HFSP) not available if GFAN exists
6354 * TPACPI_FAN_WR_ACPI_SFAN:
6355 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
6357 * EC 0x2f (HFSP) might be available *for reading*, but do not use
6360 * TPACPI_FAN_WR_TPEC:
6361 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
6362 * Supported on almost all ThinkPads
6364 * Fan speed changes of any sort (including those caused by the
6365 * disengaged mode) are usually done slowly by the firmware as the
6366 * maximum ammount of fan duty cycle change per second seems to be
6369 * Reading is not available if GFAN exists.
6370 * Writing is not available if SFAN exists.
6373 * 7 automatic mode engaged;
6374 * (default operation mode of the ThinkPad)
6375 * fan level is ignored in this mode.
6376 * 6 full speed mode (takes precedence over bit 7);
6377 * not available on all thinkpads. May disable
6378 * the tachometer while the fan controller ramps up
6379 * the speed (which can take up to a few *minutes*).
6380 * Speeds up fan to 100% duty-cycle, which is far above
6381 * the standard RPM levels. It is not impossible that
6382 * it could cause hardware damage.
6383 * 5-3 unused in some models. Extra bits for fan level
6384 * in others, but still useless as all values above
6385 * 7 map to the same speed as level 7 in these models.
6386 * 2-0 fan level (0..7 usually)
6388 * 0x07 = max (set when temperatures critical)
6389 * Some ThinkPads may have other levels, see
6390 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
6392 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
6393 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
6394 * does so, its initial value is meaningless (0x07).
6396 * For firmware bugs, refer to:
6397 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6401 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
6402 * Main fan tachometer reading (in RPM)
6404 * This register is present on all ThinkPads with a new-style EC, and
6405 * it is known not to be present on the A21m/e, and T22, as there is
6406 * something else in offset 0x84 according to the ACPI DSDT. Other
6407 * ThinkPads from this same time period (and earlier) probably lack the
6408 * tachometer as well.
6410 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
6411 * was never fixed by IBM to report the EC firmware version string
6412 * probably support the tachometer (like the early X models), so
6413 * detecting it is quite hard. We need more data to know for sure.
6415 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
6418 * FIRMWARE BUG: may go stale while the EC is switching to full speed
6421 * For firmware bugs, refer to:
6422 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6426 * ThinkPad EC register 0x31 bit 0 (only on select models)
6428 * When bit 0 of EC register 0x31 is zero, the tachometer registers
6429 * show the speed of the main fan. When bit 0 of EC register 0x31
6430 * is one, the tachometer registers show the speed of the auxiliary
6433 * Fan control seems to affect both fans, regardless of the state
6436 * So far, only the firmware for the X60/X61 non-tablet versions
6437 * seem to support this (firmware TP-7M).
6439 * TPACPI_FAN_WR_ACPI_FANS:
6440 * ThinkPad X31, X40, X41. Not available in the X60.
6442 * FANS ACPI handle: takes three arguments: low speed, medium speed,
6443 * high speed. ACPI DSDT seems to map these three speeds to levels
6444 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
6445 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
6447 * The speeds are stored on handles
6448 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
6450 * There are three default speed sets, acessible as handles:
6451 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
6453 * ACPI DSDT switches which set is in use depending on various
6456 * TPACPI_FAN_WR_TPEC is also available and should be used to
6457 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
6458 * but the ACPI tables just mention level 7.
6461 enum { /* Fan control constants */
6462 fan_status_offset
= 0x2f, /* EC register 0x2f */
6463 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
6464 * 0x84 must be read before 0x85 */
6465 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
6466 bit 0 selects which fan is active */
6468 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
6469 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
6471 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
6474 enum fan_status_access_mode
{
6475 TPACPI_FAN_NONE
= 0, /* No fan status or control */
6476 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
6477 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
6480 enum fan_control_access_mode
{
6481 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
6482 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
6483 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
6484 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
6487 enum fan_control_commands
{
6488 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
6489 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
6490 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
6491 * and also watchdog cmd */
6494 static int fan_control_allowed
;
6496 static enum fan_status_access_mode fan_status_access_mode
;
6497 static enum fan_control_access_mode fan_control_access_mode
;
6498 static enum fan_control_commands fan_control_commands
;
6500 static u8 fan_control_initial_status
;
6501 static u8 fan_control_desired_level
;
6502 static u8 fan_control_resume_level
;
6503 static int fan_watchdog_maxinterval
;
6505 static struct mutex fan_mutex
;
6507 static void fan_watchdog_fire(struct work_struct
*ignored
);
6508 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
6510 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
6511 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
6512 "\\FSPD", /* 600e/x, 770e, 770x */
6514 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
6515 "JFNS", /* 770x-JL */
6519 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
6520 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
6521 * be in auto mode (0x80).
6523 * This is corrected by any write to HFSP either by the driver, or
6526 * We assume 0x07 really means auto mode while this quirk is active,
6527 * as this is far more likely than the ThinkPad being in level 7,
6528 * which is only used by the firmware during thermal emergencies.
6530 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
6531 * TP-70 (T43, R52), which are known to be buggy.
6534 static void fan_quirk1_setup(void)
6536 if (fan_control_initial_status
== 0x07) {
6537 printk(TPACPI_NOTICE
6538 "fan_init: initial fan status is unknown, "
6539 "assuming it is in auto mode\n");
6540 tp_features
.fan_ctrl_status_undef
= 1;
6544 static void fan_quirk1_handle(u8
*fan_status
)
6546 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6547 if (*fan_status
!= fan_control_initial_status
) {
6548 /* something changed the HFSP regisnter since
6549 * driver init time, so it is not undefined
6551 tp_features
.fan_ctrl_status_undef
= 0;
6553 /* Return most likely status. In fact, it
6554 * might be the only possible status */
6555 *fan_status
= TP_EC_FAN_AUTO
;
6560 /* Select main fan on X60/X61, NOOP on others */
6561 static bool fan_select_fan1(void)
6563 if (tp_features
.second_fan
) {
6566 if (ec_read(fan_select_offset
, &val
) < 0)
6569 if (ec_write(fan_select_offset
, val
) < 0)
6575 /* Select secondary fan on X60/X61 */
6576 static bool fan_select_fan2(void)
6580 if (!tp_features
.second_fan
)
6583 if (ec_read(fan_select_offset
, &val
) < 0)
6586 if (ec_write(fan_select_offset
, val
) < 0)
6593 * Call with fan_mutex held
6595 static void fan_update_desired_level(u8 status
)
6598 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6600 fan_control_desired_level
= 7;
6602 fan_control_desired_level
= status
;
6606 static int fan_get_status(u8
*status
)
6611 * Add TPACPI_FAN_RD_ACPI_FANS ? */
6613 switch (fan_status_access_mode
) {
6614 case TPACPI_FAN_RD_ACPI_GFAN
:
6615 /* 570, 600e/x, 770e, 770x */
6617 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
6625 case TPACPI_FAN_RD_TPEC
:
6626 /* all except 570, 600e/x, 770e, 770x */
6627 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
6630 if (likely(status
)) {
6632 fan_quirk1_handle(status
);
6644 static int fan_get_status_safe(u8
*status
)
6649 if (mutex_lock_killable(&fan_mutex
))
6650 return -ERESTARTSYS
;
6651 rc
= fan_get_status(&s
);
6653 fan_update_desired_level(s
);
6654 mutex_unlock(&fan_mutex
);
6662 static int fan_get_speed(unsigned int *speed
)
6666 switch (fan_status_access_mode
) {
6667 case TPACPI_FAN_RD_TPEC
:
6668 /* all except 570, 600e/x, 770e, 770x */
6669 if (unlikely(!fan_select_fan1()))
6671 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
6672 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
6676 *speed
= (hi
<< 8) | lo
;
6687 static int fan2_get_speed(unsigned int *speed
)
6692 switch (fan_status_access_mode
) {
6693 case TPACPI_FAN_RD_TPEC
:
6694 /* all except 570, 600e/x, 770e, 770x */
6695 if (unlikely(!fan_select_fan2()))
6697 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
6698 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
6699 fan_select_fan1(); /* play it safe */
6704 *speed
= (hi
<< 8) | lo
;
6715 static int fan_set_level(int level
)
6717 if (!fan_control_allowed
)
6720 switch (fan_control_access_mode
) {
6721 case TPACPI_FAN_WR_ACPI_SFAN
:
6722 if (level
>= 0 && level
<= 7) {
6723 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
6729 case TPACPI_FAN_WR_ACPI_FANS
:
6730 case TPACPI_FAN_WR_TPEC
:
6731 if (!(level
& TP_EC_FAN_AUTO
) &&
6732 !(level
& TP_EC_FAN_FULLSPEED
) &&
6733 ((level
< 0) || (level
> 7)))
6736 /* safety net should the EC not support AUTO
6737 * or FULLSPEED mode bits and just ignore them */
6738 if (level
& TP_EC_FAN_FULLSPEED
)
6739 level
|= 7; /* safety min speed 7 */
6740 else if (level
& TP_EC_FAN_AUTO
)
6741 level
|= 4; /* safety min speed 4 */
6743 if (!acpi_ec_write(fan_status_offset
, level
))
6746 tp_features
.fan_ctrl_status_undef
= 0;
6753 vdbg_printk(TPACPI_DBG_FAN
,
6754 "fan control: set fan control register to 0x%02x\n", level
);
6758 static int fan_set_level_safe(int level
)
6762 if (!fan_control_allowed
)
6765 if (mutex_lock_killable(&fan_mutex
))
6766 return -ERESTARTSYS
;
6768 if (level
== TPACPI_FAN_LAST_LEVEL
)
6769 level
= fan_control_desired_level
;
6771 rc
= fan_set_level(level
);
6773 fan_update_desired_level(level
);
6775 mutex_unlock(&fan_mutex
);
6779 static int fan_set_enable(void)
6784 if (!fan_control_allowed
)
6787 if (mutex_lock_killable(&fan_mutex
))
6788 return -ERESTARTSYS
;
6790 switch (fan_control_access_mode
) {
6791 case TPACPI_FAN_WR_ACPI_FANS
:
6792 case TPACPI_FAN_WR_TPEC
:
6793 rc
= fan_get_status(&s
);
6797 /* Don't go out of emergency fan mode */
6800 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
6803 if (!acpi_ec_write(fan_status_offset
, s
))
6806 tp_features
.fan_ctrl_status_undef
= 0;
6811 case TPACPI_FAN_WR_ACPI_SFAN
:
6812 rc
= fan_get_status(&s
);
6818 /* Set fan to at least level 4 */
6821 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
6831 mutex_unlock(&fan_mutex
);
6834 vdbg_printk(TPACPI_DBG_FAN
,
6835 "fan control: set fan control register to 0x%02x\n",
6840 static int fan_set_disable(void)
6844 if (!fan_control_allowed
)
6847 if (mutex_lock_killable(&fan_mutex
))
6848 return -ERESTARTSYS
;
6851 switch (fan_control_access_mode
) {
6852 case TPACPI_FAN_WR_ACPI_FANS
:
6853 case TPACPI_FAN_WR_TPEC
:
6854 if (!acpi_ec_write(fan_status_offset
, 0x00))
6857 fan_control_desired_level
= 0;
6858 tp_features
.fan_ctrl_status_undef
= 0;
6862 case TPACPI_FAN_WR_ACPI_SFAN
:
6863 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
6866 fan_control_desired_level
= 0;
6874 vdbg_printk(TPACPI_DBG_FAN
,
6875 "fan control: set fan control register to 0\n");
6877 mutex_unlock(&fan_mutex
);
6881 static int fan_set_speed(int speed
)
6885 if (!fan_control_allowed
)
6888 if (mutex_lock_killable(&fan_mutex
))
6889 return -ERESTARTSYS
;
6892 switch (fan_control_access_mode
) {
6893 case TPACPI_FAN_WR_ACPI_FANS
:
6894 if (speed
>= 0 && speed
<= 65535) {
6895 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
6896 speed
, speed
, speed
))
6906 mutex_unlock(&fan_mutex
);
6910 static void fan_watchdog_reset(void)
6912 static int fan_watchdog_active
;
6914 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
6917 if (fan_watchdog_active
)
6918 cancel_delayed_work(&fan_watchdog_task
);
6920 if (fan_watchdog_maxinterval
> 0 &&
6921 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
6922 fan_watchdog_active
= 1;
6923 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
6924 msecs_to_jiffies(fan_watchdog_maxinterval
6927 "failed to queue the fan watchdog, "
6928 "watchdog will not trigger\n");
6931 fan_watchdog_active
= 0;
6934 static void fan_watchdog_fire(struct work_struct
*ignored
)
6938 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
6941 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
6942 rc
= fan_set_enable();
6944 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
6945 "will try again later...\n", -rc
);
6946 /* reschedule for later */
6947 fan_watchdog_reset();
6952 * SYSFS fan layout: hwmon compatible (device)
6955 * 0: "disengaged" mode
6957 * 2: native EC "auto" mode (recommended, hardware default)
6959 * pwm*: set speed in manual mode, ignored otherwise.
6960 * 0 is level 0; 255 is level 7. Intermediate points done with linear
6963 * fan*_input: tachometer reading, RPM
6966 * SYSFS fan layout: extensions
6968 * fan_watchdog (driver):
6969 * fan watchdog interval in seconds, 0 disables (default), max 120
6972 /* sysfs fan pwm1_enable ----------------------------------------------- */
6973 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
6974 struct device_attribute
*attr
,
6980 res
= fan_get_status_safe(&status
);
6984 if (status
& TP_EC_FAN_FULLSPEED
) {
6986 } else if (status
& TP_EC_FAN_AUTO
) {
6991 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
6994 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
6995 struct device_attribute
*attr
,
6996 const char *buf
, size_t count
)
7001 if (parse_strtoul(buf
, 2, &t
))
7004 tpacpi_disclose_usertask("hwmon pwm1_enable",
7005 "set fan mode to %lu\n", t
);
7009 level
= TP_EC_FAN_FULLSPEED
;
7012 level
= TPACPI_FAN_LAST_LEVEL
;
7015 level
= TP_EC_FAN_AUTO
;
7018 /* reserved for software-controlled auto mode */
7024 res
= fan_set_level_safe(level
);
7030 fan_watchdog_reset();
7035 static struct device_attribute dev_attr_fan_pwm1_enable
=
7036 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7037 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7039 /* sysfs fan pwm1 ------------------------------------------------------ */
7040 static ssize_t
fan_pwm1_show(struct device
*dev
,
7041 struct device_attribute
*attr
,
7047 res
= fan_get_status_safe(&status
);
7052 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7053 status
= fan_control_desired_level
;
7058 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7061 static ssize_t
fan_pwm1_store(struct device
*dev
,
7062 struct device_attribute
*attr
,
7063 const char *buf
, size_t count
)
7067 u8 status
, newlevel
;
7069 if (parse_strtoul(buf
, 255, &s
))
7072 tpacpi_disclose_usertask("hwmon pwm1",
7073 "set fan speed to %lu\n", s
);
7075 /* scale down from 0-255 to 0-7 */
7076 newlevel
= (s
>> 5) & 0x07;
7078 if (mutex_lock_killable(&fan_mutex
))
7079 return -ERESTARTSYS
;
7081 rc
= fan_get_status(&status
);
7082 if (!rc
&& (status
&
7083 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7084 rc
= fan_set_level(newlevel
);
7088 fan_update_desired_level(newlevel
);
7089 fan_watchdog_reset();
7093 mutex_unlock(&fan_mutex
);
7094 return (rc
)? rc
: count
;
7097 static struct device_attribute dev_attr_fan_pwm1
=
7098 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7099 fan_pwm1_show
, fan_pwm1_store
);
7101 /* sysfs fan fan1_input ------------------------------------------------ */
7102 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7103 struct device_attribute
*attr
,
7109 res
= fan_get_speed(&speed
);
7113 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7116 static struct device_attribute dev_attr_fan_fan1_input
=
7117 __ATTR(fan1_input
, S_IRUGO
,
7118 fan_fan1_input_show
, NULL
);
7120 /* sysfs fan fan2_input ------------------------------------------------ */
7121 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7122 struct device_attribute
*attr
,
7128 res
= fan2_get_speed(&speed
);
7132 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7135 static struct device_attribute dev_attr_fan_fan2_input
=
7136 __ATTR(fan2_input
, S_IRUGO
,
7137 fan_fan2_input_show
, NULL
);
7139 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
7140 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
7143 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
7146 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
7147 const char *buf
, size_t count
)
7151 if (parse_strtoul(buf
, 120, &t
))
7154 if (!fan_control_allowed
)
7157 fan_watchdog_maxinterval
= t
;
7158 fan_watchdog_reset();
7160 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
7165 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
7166 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
7168 /* --------------------------------------------------------------------- */
7169 static struct attribute
*fan_attributes
[] = {
7170 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
7171 &dev_attr_fan_fan1_input
.attr
,
7172 NULL
, /* for fan2_input */
7176 static const struct attribute_group fan_attr_group
= {
7177 .attrs
= fan_attributes
,
7180 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
7181 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
7183 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7184 { .vendor = PCI_VENDOR_ID_IBM, \
7185 .bios = TPACPI_MATCH_ANY, \
7186 .ec = TPID(__id1, __id2), \
7187 .quirks = __quirks }
7189 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7190 { .vendor = PCI_VENDOR_ID_LENOVO, \
7191 .bios = TPACPI_MATCH_ANY, \
7192 .ec = TPID(__id1, __id2), \
7193 .quirks = __quirks }
7195 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
7196 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
7197 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
7198 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
7199 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
7200 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
7203 #undef TPACPI_FAN_QL
7204 #undef TPACPI_FAN_QI
7206 static int __init
fan_init(struct ibm_init_struct
*iibm
)
7209 unsigned long quirks
;
7211 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7212 "initializing fan subdriver\n");
7214 mutex_init(&fan_mutex
);
7215 fan_status_access_mode
= TPACPI_FAN_NONE
;
7216 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7217 fan_control_commands
= 0;
7218 fan_watchdog_maxinterval
= 0;
7219 tp_features
.fan_ctrl_status_undef
= 0;
7220 tp_features
.second_fan
= 0;
7221 fan_control_desired_level
= 7;
7223 TPACPI_ACPIHANDLE_INIT(fans
);
7224 TPACPI_ACPIHANDLE_INIT(gfan
);
7225 TPACPI_ACPIHANDLE_INIT(sfan
);
7227 quirks
= tpacpi_check_quirks(fan_quirk_table
,
7228 ARRAY_SIZE(fan_quirk_table
));
7231 /* 570, 600e/x, 770e, 770x */
7232 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7234 /* all other ThinkPads: note that even old-style
7235 * ThinkPad ECs supports the fan control register */
7236 if (likely(acpi_ec_read(fan_status_offset
,
7237 &fan_control_initial_status
))) {
7238 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7239 if (quirks
& TPACPI_FAN_Q1
)
7241 if (quirks
& TPACPI_FAN_2FAN
) {
7242 tp_features
.second_fan
= 1;
7243 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7244 "secondary fan support enabled\n");
7248 "ThinkPad ACPI EC access misbehaving, "
7249 "fan status and control unavailable\n");
7256 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
7257 fan_control_commands
|=
7258 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
7261 /* gfan without sfan means no fan control */
7262 /* all other models implement TP EC 0x2f control */
7266 fan_control_access_mode
=
7267 TPACPI_FAN_WR_ACPI_FANS
;
7268 fan_control_commands
|=
7269 TPACPI_FAN_CMD_SPEED
|
7270 TPACPI_FAN_CMD_LEVEL
|
7271 TPACPI_FAN_CMD_ENABLE
;
7273 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
7274 fan_control_commands
|=
7275 TPACPI_FAN_CMD_LEVEL
|
7276 TPACPI_FAN_CMD_ENABLE
;
7281 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7282 "fan is %s, modes %d, %d\n",
7283 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
7284 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
7285 fan_status_access_mode
, fan_control_access_mode
);
7287 /* fan control master switch */
7288 if (!fan_control_allowed
) {
7289 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7290 fan_control_commands
= 0;
7291 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7292 "fan control features disabled by parameter\n");
7295 /* update fan_control_desired_level */
7296 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
7297 fan_get_status_safe(NULL
);
7299 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
7300 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
7301 if (tp_features
.second_fan
) {
7302 /* attach second fan tachometer */
7303 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
7304 &dev_attr_fan_fan2_input
.attr
;
7306 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7311 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
7312 &driver_attr_fan_watchdog
);
7314 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7323 static void fan_exit(void)
7325 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
7326 "cancelling any pending fan watchdog tasks\n");
7328 /* FIXME: can we really do this unconditionally? */
7329 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
7330 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
7331 &driver_attr_fan_watchdog
);
7333 cancel_delayed_work(&fan_watchdog_task
);
7334 flush_workqueue(tpacpi_wq
);
7337 static void fan_suspend(pm_message_t state
)
7341 if (!fan_control_allowed
)
7344 /* Store fan status in cache */
7345 fan_control_resume_level
= 0;
7346 rc
= fan_get_status_safe(&fan_control_resume_level
);
7348 printk(TPACPI_NOTICE
7349 "failed to read fan level for later "
7350 "restore during resume: %d\n", rc
);
7352 /* if it is undefined, don't attempt to restore it.
7354 if (tp_features
.fan_ctrl_status_undef
)
7355 fan_control_resume_level
= 0;
7358 static void fan_resume(void)
7360 u8 current_level
= 7;
7361 bool do_set
= false;
7364 /* DSDT *always* updates status on resume */
7365 tp_features
.fan_ctrl_status_undef
= 0;
7367 if (!fan_control_allowed
||
7368 !fan_control_resume_level
||
7369 (fan_get_status_safe(¤t_level
) < 0))
7372 switch (fan_control_access_mode
) {
7373 case TPACPI_FAN_WR_ACPI_SFAN
:
7374 /* never decrease fan level */
7375 do_set
= (fan_control_resume_level
> current_level
);
7377 case TPACPI_FAN_WR_ACPI_FANS
:
7378 case TPACPI_FAN_WR_TPEC
:
7379 /* never decrease fan level, scale is:
7380 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
7382 * We expect the firmware to set either 7 or AUTO, but we
7383 * handle FULLSPEED out of paranoia.
7385 * So, we can safely only restore FULLSPEED or 7, anything
7386 * else could slow the fan. Restoring AUTO is useless, at
7387 * best that's exactly what the DSDT already set (it is the
7390 * Always keep in mind that the DSDT *will* have set the
7391 * fans to what the vendor supposes is the best level. We
7392 * muck with it only to speed the fan up.
7394 if (fan_control_resume_level
!= 7 &&
7395 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
7398 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
7399 (current_level
!= fan_control_resume_level
);
7405 printk(TPACPI_NOTICE
7406 "restoring fan level to 0x%02x\n",
7407 fan_control_resume_level
);
7408 rc
= fan_set_level_safe(fan_control_resume_level
);
7410 printk(TPACPI_NOTICE
7411 "failed to restore fan level: %d\n", rc
);
7415 static int fan_read(char *p
)
7420 unsigned int speed
= 0;
7422 switch (fan_status_access_mode
) {
7423 case TPACPI_FAN_RD_ACPI_GFAN
:
7424 /* 570, 600e/x, 770e, 770x */
7425 rc
= fan_get_status_safe(&status
);
7429 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
7431 (status
!= 0) ? "enabled" : "disabled", status
);
7434 case TPACPI_FAN_RD_TPEC
:
7435 /* all except 570, 600e/x, 770e, 770x */
7436 rc
= fan_get_status_safe(&status
);
7440 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
7441 (status
!= 0) ? "enabled" : "disabled");
7443 rc
= fan_get_speed(&speed
);
7447 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
7449 if (status
& TP_EC_FAN_FULLSPEED
)
7450 /* Disengaged mode takes precedence */
7451 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
7452 else if (status
& TP_EC_FAN_AUTO
)
7453 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
7455 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
7458 case TPACPI_FAN_NONE
:
7460 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
7463 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
7464 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
7466 switch (fan_control_access_mode
) {
7467 case TPACPI_FAN_WR_ACPI_SFAN
:
7468 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
7472 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
7473 "auto, disengaged, full-speed)\n");
7478 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
7479 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
7480 "commands:\twatchdog <timeout> (<timeout> "
7481 "is 0 (off), 1-120 (seconds))\n");
7483 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
7484 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
7485 " (<speed> is 0-65535)\n");
7490 static int fan_write_cmd_level(const char *cmd
, int *rc
)
7494 if (strlencmp(cmd
, "level auto") == 0)
7495 level
= TP_EC_FAN_AUTO
;
7496 else if ((strlencmp(cmd
, "level disengaged") == 0) |
7497 (strlencmp(cmd
, "level full-speed") == 0))
7498 level
= TP_EC_FAN_FULLSPEED
;
7499 else if (sscanf(cmd
, "level %d", &level
) != 1)
7502 *rc
= fan_set_level_safe(level
);
7504 printk(TPACPI_ERR
"level command accepted for unsupported "
7505 "access mode %d", fan_control_access_mode
);
7507 tpacpi_disclose_usertask("procfs fan",
7508 "set level to %d\n", level
);
7513 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
7515 if (strlencmp(cmd
, "enable") != 0)
7518 *rc
= fan_set_enable();
7520 printk(TPACPI_ERR
"enable command accepted for unsupported "
7521 "access mode %d", fan_control_access_mode
);
7523 tpacpi_disclose_usertask("procfs fan", "enable\n");
7528 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
7530 if (strlencmp(cmd
, "disable") != 0)
7533 *rc
= fan_set_disable();
7535 printk(TPACPI_ERR
"disable command accepted for unsupported "
7536 "access mode %d", fan_control_access_mode
);
7538 tpacpi_disclose_usertask("procfs fan", "disable\n");
7543 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
7548 * Support speed <low> <medium> <high> ? */
7550 if (sscanf(cmd
, "speed %d", &speed
) != 1)
7553 *rc
= fan_set_speed(speed
);
7555 printk(TPACPI_ERR
"speed command accepted for unsupported "
7556 "access mode %d", fan_control_access_mode
);
7558 tpacpi_disclose_usertask("procfs fan",
7559 "set speed to %d\n", speed
);
7564 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
7568 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
7571 if (interval
< 0 || interval
> 120)
7574 fan_watchdog_maxinterval
= interval
;
7575 tpacpi_disclose_usertask("procfs fan",
7576 "set watchdog timer to %d\n",
7583 static int fan_write(char *buf
)
7588 while (!rc
&& (cmd
= next_cmd(&buf
))) {
7589 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
7590 fan_write_cmd_level(cmd
, &rc
)) &&
7591 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
7592 (fan_write_cmd_enable(cmd
, &rc
) ||
7593 fan_write_cmd_disable(cmd
, &rc
) ||
7594 fan_write_cmd_watchdog(cmd
, &rc
))) &&
7595 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
7596 fan_write_cmd_speed(cmd
, &rc
))
7600 fan_watchdog_reset();
7606 static struct ibm_struct fan_driver_data
= {
7611 .suspend
= fan_suspend
,
7612 .resume
= fan_resume
,
7615 /****************************************************************************
7616 ****************************************************************************
7620 ****************************************************************************
7621 ****************************************************************************/
7624 * HKEY event callout for other subdrivers go here
7625 * (yes, it is ugly, but it is quick, safe, and gets the job done
7627 static void tpacpi_driver_event(const unsigned int hkey_event
)
7633 static void hotkey_driver_event(const unsigned int scancode
)
7635 tpacpi_driver_event(0x1001 + scancode
);
7638 /* sysfs name ---------------------------------------------------------- */
7639 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
7640 struct device_attribute
*attr
,
7643 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
7646 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
7647 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
7649 /* --------------------------------------------------------------------- */
7652 static struct proc_dir_entry
*proc_dir
;
7655 * Module and infrastructure proble, init and exit handling
7658 static int force_load
;
7660 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
7661 static const char * __init
str_supported(int is_supported
)
7663 static char text_unsupported
[] __initdata
= "not supported";
7665 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
7667 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
7669 static void ibm_exit(struct ibm_struct
*ibm
)
7671 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
7673 list_del_init(&ibm
->all_drivers
);
7675 if (ibm
->flags
.acpi_notify_installed
) {
7676 dbg_printk(TPACPI_DBG_EXIT
,
7677 "%s: acpi_remove_notify_handler\n", ibm
->name
);
7679 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
7681 dispatch_acpi_notify
);
7682 ibm
->flags
.acpi_notify_installed
= 0;
7683 ibm
->flags
.acpi_notify_installed
= 0;
7686 if (ibm
->flags
.proc_created
) {
7687 dbg_printk(TPACPI_DBG_EXIT
,
7688 "%s: remove_proc_entry\n", ibm
->name
);
7689 remove_proc_entry(ibm
->name
, proc_dir
);
7690 ibm
->flags
.proc_created
= 0;
7693 if (ibm
->flags
.acpi_driver_registered
) {
7694 dbg_printk(TPACPI_DBG_EXIT
,
7695 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
7697 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
7698 kfree(ibm
->acpi
->driver
);
7699 ibm
->acpi
->driver
= NULL
;
7700 ibm
->flags
.acpi_driver_registered
= 0;
7703 if (ibm
->flags
.init_called
&& ibm
->exit
) {
7705 ibm
->flags
.init_called
= 0;
7708 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
7711 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
7714 struct ibm_struct
*ibm
= iibm
->data
;
7715 struct proc_dir_entry
*entry
;
7717 BUG_ON(ibm
== NULL
);
7719 INIT_LIST_HEAD(&ibm
->all_drivers
);
7721 if (ibm
->flags
.experimental
&& !experimental
)
7724 dbg_printk(TPACPI_DBG_INIT
,
7725 "probing for %s\n", ibm
->name
);
7728 ret
= iibm
->init(iibm
);
7730 return 0; /* probe failed */
7734 ibm
->flags
.init_called
= 1;
7738 if (ibm
->acpi
->hid
) {
7739 ret
= register_tpacpi_subdriver(ibm
);
7744 if (ibm
->acpi
->notify
) {
7745 ret
= setup_acpi_notify(ibm
);
7746 if (ret
== -ENODEV
) {
7747 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
7757 dbg_printk(TPACPI_DBG_INIT
,
7758 "%s installed\n", ibm
->name
);
7761 entry
= create_proc_entry(ibm
->name
,
7762 S_IFREG
| S_IRUGO
| S_IWUSR
,
7765 printk(TPACPI_ERR
"unable to create proc entry %s\n",
7770 entry
->owner
= THIS_MODULE
;
7772 entry
->read_proc
= &dispatch_procfs_read
;
7774 entry
->write_proc
= &dispatch_procfs_write
;
7775 ibm
->flags
.proc_created
= 1;
7778 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
7783 dbg_printk(TPACPI_DBG_INIT
,
7784 "%s: at error exit path with result %d\n",
7788 return (ret
< 0)? ret
: 0;
7793 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
7795 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
7798 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
7799 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
7802 return s
&& strlen(s
) >= 8 &&
7803 tpacpi_is_fw_digit(s
[0]) &&
7804 tpacpi_is_fw_digit(s
[1]) &&
7805 s
[2] == t
&& s
[3] == 'T' &&
7806 tpacpi_is_fw_digit(s
[4]) &&
7807 tpacpi_is_fw_digit(s
[5]) &&
7808 s
[6] == 'W' && s
[7] == 'W';
7811 /* returns 0 - probe ok, or < 0 - probe error.
7812 * Probe ok doesn't mean thinkpad found.
7813 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
7814 static int __must_check __init
get_thinkpad_model_data(
7815 struct thinkpad_id_data
*tp
)
7817 const struct dmi_device
*dev
= NULL
;
7818 char ec_fw_string
[18];
7824 memset(tp
, 0, sizeof(*tp
));
7826 if (dmi_name_in_vendors("IBM"))
7827 tp
->vendor
= PCI_VENDOR_ID_IBM
;
7828 else if (dmi_name_in_vendors("LENOVO"))
7829 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
7833 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
7834 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
7835 if (s
&& !tp
->bios_version_str
)
7838 /* Really ancient ThinkPad 240X will fail this, which is fine */
7839 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
7842 tp
->bios_model
= tp
->bios_version_str
[0]
7843 | (tp
->bios_version_str
[1] << 8);
7844 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
7845 | tp
->bios_version_str
[5];
7848 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
7849 * X32 or newer, all Z series; Some models must have an
7850 * up-to-date BIOS or they will not be detected.
7852 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7854 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
7855 if (sscanf(dev
->name
,
7856 "IBM ThinkPad Embedded Controller -[%17c",
7857 ec_fw_string
) == 1) {
7858 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
7859 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
7861 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
7862 if (!tp
->ec_version_str
)
7865 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
7866 tp
->ec_model
= ec_fw_string
[0]
7867 | (ec_fw_string
[1] << 8);
7868 tp
->ec_release
= (ec_fw_string
[4] << 8)
7871 printk(TPACPI_NOTICE
7872 "ThinkPad firmware release %s "
7873 "doesn't match the known patterns\n",
7875 printk(TPACPI_NOTICE
7876 "please report this to %s\n",
7883 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
7884 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
7885 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
7890 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
7891 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
7892 if (s
&& !tp
->nummodel_str
)
7898 static int __init
probe_for_thinkpad(void)
7906 * Non-ancient models have better DMI tagging, but very old models
7907 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
7909 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
7910 (thinkpad_id
.ec_model
!= 0) ||
7911 tpacpi_is_fw_known();
7913 /* ec is required because many other handles are relative to it */
7914 TPACPI_ACPIHANDLE_INIT(ec
);
7918 "Not yet supported ThinkPad detected!\n");
7922 if (!is_thinkpad
&& !force_load
)
7929 /* Module init, exit, parameters */
7931 static struct ibm_init_struct ibms_init
[] __initdata
= {
7933 .init
= thinkpad_acpi_driver_init
,
7934 .data
= &thinkpad_acpi_driver_data
,
7937 .init
= hotkey_init
,
7938 .data
= &hotkey_driver_data
,
7941 .init
= bluetooth_init
,
7942 .data
= &bluetooth_driver_data
,
7946 .data
= &wan_driver_data
,
7950 .data
= &uwb_driver_data
,
7952 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
7955 .data
= &video_driver_data
,
7960 .data
= &light_driver_data
,
7964 .data
= &cmos_driver_data
,
7968 .data
= &led_driver_data
,
7972 .data
= &beep_driver_data
,
7975 .init
= thermal_init
,
7976 .data
= &thermal_driver_data
,
7979 .data
= &ecdump_driver_data
,
7982 .init
= brightness_init
,
7983 .data
= &brightness_driver_data
,
7986 .data
= &volume_driver_data
,
7990 .data
= &fan_driver_data
,
7994 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
7997 struct ibm_struct
*ibm
;
7999 if (!kp
|| !kp
->name
|| !val
)
8002 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8003 ibm
= ibms_init
[i
].data
;
8004 WARN_ON(ibm
== NULL
);
8006 if (!ibm
|| !ibm
->name
)
8009 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8010 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8012 strcpy(ibms_init
[i
].param
, val
);
8013 strcat(ibms_init
[i
].param
, ",");
8021 module_param(experimental
, int, 0);
8022 MODULE_PARM_DESC(experimental
,
8023 "Enables experimental features when non-zero");
8025 module_param_named(debug
, dbg_level
, uint
, 0);
8026 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8028 module_param(force_load
, bool, 0);
8029 MODULE_PARM_DESC(force_load
,
8030 "Attempts to load the driver even on a "
8031 "mis-identified ThinkPad when true");
8033 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
8034 MODULE_PARM_DESC(fan_control
,
8035 "Enables setting fan parameters features when true");
8037 module_param_named(brightness_mode
, brightness_mode
, uint
, 0);
8038 MODULE_PARM_DESC(brightness_mode
,
8039 "Selects brightness control strategy: "
8040 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8042 module_param(brightness_enable
, uint
, 0);
8043 MODULE_PARM_DESC(brightness_enable
,
8044 "Enables backlight control when 1, disables when 0");
8046 module_param(hotkey_report_mode
, uint
, 0);
8047 MODULE_PARM_DESC(hotkey_report_mode
,
8048 "used for backwards compatibility with userspace, "
8049 "see documentation");
8051 #define TPACPI_PARAM(feature) \
8052 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8053 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8054 "at module load, see documentation")
8056 TPACPI_PARAM(hotkey
);
8057 TPACPI_PARAM(bluetooth
);
8058 TPACPI_PARAM(video
);
8059 TPACPI_PARAM(light
);
8063 TPACPI_PARAM(ecdump
);
8064 TPACPI_PARAM(brightness
);
8065 TPACPI_PARAM(volume
);
8068 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8069 module_param(dbg_wlswemul
, uint
, 0);
8070 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
8071 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
8072 MODULE_PARM_DESC(wlsw_state
,
8073 "Initial state of the emulated WLSW switch");
8075 module_param(dbg_bluetoothemul
, uint
, 0);
8076 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
8077 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
8078 MODULE_PARM_DESC(bluetooth_state
,
8079 "Initial state of the emulated bluetooth switch");
8081 module_param(dbg_wwanemul
, uint
, 0);
8082 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
8083 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
8084 MODULE_PARM_DESC(wwan_state
,
8085 "Initial state of the emulated WWAN switch");
8087 module_param(dbg_uwbemul
, uint
, 0);
8088 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
8089 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
8090 MODULE_PARM_DESC(uwb_state
,
8091 "Initial state of the emulated UWB switch");
8094 static void thinkpad_acpi_module_exit(void)
8096 struct ibm_struct
*ibm
, *itmp
;
8098 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
8100 list_for_each_entry_safe_reverse(ibm
, itmp
,
8101 &tpacpi_all_drivers
,
8106 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
8108 if (tpacpi_inputdev
) {
8109 if (tp_features
.input_device_registered
)
8110 input_unregister_device(tpacpi_inputdev
);
8112 input_free_device(tpacpi_inputdev
);
8116 hwmon_device_unregister(tpacpi_hwmon
);
8118 if (tp_features
.sensors_pdev_attrs_registered
)
8119 device_remove_file(&tpacpi_sensors_pdev
->dev
,
8120 &dev_attr_thinkpad_acpi_pdev_name
);
8121 if (tpacpi_sensors_pdev
)
8122 platform_device_unregister(tpacpi_sensors_pdev
);
8124 platform_device_unregister(tpacpi_pdev
);
8126 if (tp_features
.sensors_pdrv_attrs_registered
)
8127 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
8128 if (tp_features
.platform_drv_attrs_registered
)
8129 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
8131 if (tp_features
.sensors_pdrv_registered
)
8132 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
8134 if (tp_features
.platform_drv_registered
)
8135 platform_driver_unregister(&tpacpi_pdriver
);
8138 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
8141 destroy_workqueue(tpacpi_wq
);
8143 kfree(thinkpad_id
.bios_version_str
);
8144 kfree(thinkpad_id
.ec_version_str
);
8145 kfree(thinkpad_id
.model_str
);
8149 static int __init
thinkpad_acpi_module_init(void)
8153 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
8155 /* Parameter checking */
8156 if (hotkey_report_mode
> 2)
8159 /* Driver-level probe */
8161 ret
= get_thinkpad_model_data(&thinkpad_id
);
8164 "unable to get DMI data: %d\n", ret
);
8165 thinkpad_acpi_module_exit();
8168 ret
= probe_for_thinkpad();
8170 thinkpad_acpi_module_exit();
8174 /* Driver initialization */
8176 TPACPI_ACPIHANDLE_INIT(ecrd
);
8177 TPACPI_ACPIHANDLE_INIT(ecwr
);
8179 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
8181 thinkpad_acpi_module_exit();
8185 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
8188 "unable to create proc dir " TPACPI_PROC_DIR
);
8189 thinkpad_acpi_module_exit();
8192 proc_dir
->owner
= THIS_MODULE
;
8194 ret
= platform_driver_register(&tpacpi_pdriver
);
8197 "unable to register main platform driver\n");
8198 thinkpad_acpi_module_exit();
8201 tp_features
.platform_drv_registered
= 1;
8203 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
8206 "unable to register hwmon platform driver\n");
8207 thinkpad_acpi_module_exit();
8210 tp_features
.sensors_pdrv_registered
= 1;
8212 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
8214 tp_features
.platform_drv_attrs_registered
= 1;
8215 ret
= tpacpi_create_driver_attributes(
8216 &tpacpi_hwmon_pdriver
.driver
);
8220 "unable to create sysfs driver attributes\n");
8221 thinkpad_acpi_module_exit();
8224 tp_features
.sensors_pdrv_attrs_registered
= 1;
8227 /* Device initialization */
8228 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
8230 if (IS_ERR(tpacpi_pdev
)) {
8231 ret
= PTR_ERR(tpacpi_pdev
);
8233 printk(TPACPI_ERR
"unable to register platform device\n");
8234 thinkpad_acpi_module_exit();
8237 tpacpi_sensors_pdev
= platform_device_register_simple(
8238 TPACPI_HWMON_DRVR_NAME
,
8240 if (IS_ERR(tpacpi_sensors_pdev
)) {
8241 ret
= PTR_ERR(tpacpi_sensors_pdev
);
8242 tpacpi_sensors_pdev
= NULL
;
8244 "unable to register hwmon platform device\n");
8245 thinkpad_acpi_module_exit();
8248 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
8249 &dev_attr_thinkpad_acpi_pdev_name
);
8252 "unable to create sysfs hwmon device attributes\n");
8253 thinkpad_acpi_module_exit();
8256 tp_features
.sensors_pdev_attrs_registered
= 1;
8257 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
8258 if (IS_ERR(tpacpi_hwmon
)) {
8259 ret
= PTR_ERR(tpacpi_hwmon
);
8260 tpacpi_hwmon
= NULL
;
8261 printk(TPACPI_ERR
"unable to register hwmon device\n");
8262 thinkpad_acpi_module_exit();
8265 mutex_init(&tpacpi_inputdev_send_mutex
);
8266 tpacpi_inputdev
= input_allocate_device();
8267 if (!tpacpi_inputdev
) {
8268 printk(TPACPI_ERR
"unable to allocate input device\n");
8269 thinkpad_acpi_module_exit();
8272 /* Prepare input device, but don't register */
8273 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
8274 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
8275 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
8276 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
8277 thinkpad_id
.vendor
:
8279 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
8280 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
8282 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8283 ret
= ibm_init(&ibms_init
[i
]);
8284 if (ret
>= 0 && *ibms_init
[i
].param
)
8285 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
8287 thinkpad_acpi_module_exit();
8291 ret
= input_register_device(tpacpi_inputdev
);
8293 printk(TPACPI_ERR
"unable to register input device\n");
8294 thinkpad_acpi_module_exit();
8297 tp_features
.input_device_registered
= 1;
8300 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
8304 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
8307 * This will autoload the driver in almost every ThinkPad
8308 * in widespread use.
8310 * Only _VERY_ old models, like the 240, 240x and 570 lack
8311 * the HKEY event interface.
8313 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
8316 * DMI matching for module autoloading
8318 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8319 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
8321 * Only models listed in thinkwiki will be supported, so add yours
8322 * if it is not there yet.
8324 #define IBM_BIOS_MODULE_ALIAS(__type) \
8325 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
8327 /* Ancient thinkpad BIOSes have to be identified by
8328 * BIOS type or model number, and there are far less
8329 * BIOS types than model numbers... */
8330 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
8332 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
8333 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
8334 MODULE_DESCRIPTION(TPACPI_DESC
);
8335 MODULE_VERSION(TPACPI_VERSION
);
8336 MODULE_LICENSE("GPL");
8338 module_init(thinkpad_acpi_module_init
);
8339 module_exit(thinkpad_acpi_module_exit
);