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 0x020700
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/seq_file.h>
65 #include <linux/sysfs.h>
66 #include <linux/backlight.h>
68 #include <linux/platform_device.h>
69 #include <linux/hwmon.h>
70 #include <linux/hwmon-sysfs.h>
71 #include <linux/input.h>
72 #include <linux/leds.h>
73 #include <linux/rfkill.h>
74 #include <asm/uaccess.h>
76 #include <linux/dmi.h>
77 #include <linux/jiffies.h>
78 #include <linux/workqueue.h>
80 #include <sound/core.h>
81 #include <sound/control.h>
82 #include <sound/initval.h>
84 #include <acpi/acpi_drivers.h>
86 #include <linux/pci_ids.h>
89 /* ThinkPad CMOS commands */
90 #define TP_CMOS_VOLUME_DOWN 0
91 #define TP_CMOS_VOLUME_UP 1
92 #define TP_CMOS_VOLUME_MUTE 2
93 #define TP_CMOS_BRIGHTNESS_UP 4
94 #define TP_CMOS_BRIGHTNESS_DOWN 5
95 #define TP_CMOS_THINKLIGHT_ON 12
96 #define TP_CMOS_THINKLIGHT_OFF 13
100 TP_NVRAM_ADDR_HK2
= 0x57,
101 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
102 TP_NVRAM_ADDR_VIDEO
= 0x59,
103 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
104 TP_NVRAM_ADDR_MIXER
= 0x60,
107 /* NVRAM bit masks */
109 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
110 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
111 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
112 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
113 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
114 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
115 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
116 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
117 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
118 TP_NVRAM_MASK_MUTE
= 0x40,
119 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
120 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
121 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
125 #define TPACPI_ACPI_HKEY_HID "IBM0068"
128 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
129 #define TPACPI_HKEY_INPUT_VERSION 0x4101
131 /* ACPI \WGSV commands */
133 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
134 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
135 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
136 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
139 /* TP_ACPI_WGSV_GET_STATE bits */
141 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
142 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
143 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
144 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
145 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
146 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
147 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
148 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
149 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
150 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
154 enum tpacpi_hkey_event_t
{
156 TP_HKEY_EV_HOTKEY_BASE
= 0x1001, /* first hotkey (FN+F1) */
157 TP_HKEY_EV_BRGHT_UP
= 0x1010, /* Brightness up */
158 TP_HKEY_EV_BRGHT_DOWN
= 0x1011, /* Brightness down */
159 TP_HKEY_EV_VOL_UP
= 0x1015, /* Volume up or unmute */
160 TP_HKEY_EV_VOL_DOWN
= 0x1016, /* Volume down or unmute */
161 TP_HKEY_EV_VOL_MUTE
= 0x1017, /* Mixer output mute */
163 /* Reasons for waking up from S3/S4 */
164 TP_HKEY_EV_WKUP_S3_UNDOCK
= 0x2304, /* undock requested, S3 */
165 TP_HKEY_EV_WKUP_S4_UNDOCK
= 0x2404, /* undock requested, S4 */
166 TP_HKEY_EV_WKUP_S3_BAYEJ
= 0x2305, /* bay ejection req, S3 */
167 TP_HKEY_EV_WKUP_S4_BAYEJ
= 0x2405, /* bay ejection req, S4 */
168 TP_HKEY_EV_WKUP_S3_BATLOW
= 0x2313, /* battery empty, S3 */
169 TP_HKEY_EV_WKUP_S4_BATLOW
= 0x2413, /* battery empty, S4 */
171 /* Auto-sleep after eject request */
172 TP_HKEY_EV_BAYEJ_ACK
= 0x3003, /* bay ejection complete */
173 TP_HKEY_EV_UNDOCK_ACK
= 0x4003, /* undock complete */
175 /* Misc bay events */
176 TP_HKEY_EV_OPTDRV_EJ
= 0x3006, /* opt. drive tray ejected */
178 /* User-interface events */
179 TP_HKEY_EV_LID_CLOSE
= 0x5001, /* laptop lid closed */
180 TP_HKEY_EV_LID_OPEN
= 0x5002, /* laptop lid opened */
181 TP_HKEY_EV_TABLET_TABLET
= 0x5009, /* tablet swivel up */
182 TP_HKEY_EV_TABLET_NOTEBOOK
= 0x500a, /* tablet swivel down */
183 TP_HKEY_EV_PEN_INSERTED
= 0x500b, /* tablet pen inserted */
184 TP_HKEY_EV_PEN_REMOVED
= 0x500c, /* tablet pen removed */
185 TP_HKEY_EV_BRGHT_CHANGED
= 0x5010, /* backlight control event */
188 TP_HKEY_EV_ALARM_BAT_HOT
= 0x6011, /* battery too hot */
189 TP_HKEY_EV_ALARM_BAT_XHOT
= 0x6012, /* battery critically hot */
190 TP_HKEY_EV_ALARM_SENSOR_HOT
= 0x6021, /* sensor too hot */
191 TP_HKEY_EV_ALARM_SENSOR_XHOT
= 0x6022, /* sensor critically hot */
192 TP_HKEY_EV_THM_TABLE_CHANGED
= 0x6030, /* thermal table changed */
195 TP_HKEY_EV_RFKILL_CHANGED
= 0x7000, /* rfkill switch changed */
198 /****************************************************************************
202 #define TPACPI_NAME "thinkpad"
203 #define TPACPI_DESC "ThinkPad ACPI Extras"
204 #define TPACPI_FILE TPACPI_NAME "_acpi"
205 #define TPACPI_URL "http://ibm-acpi.sf.net/"
206 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
208 #define TPACPI_PROC_DIR "ibm"
209 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
210 #define TPACPI_DRVR_NAME TPACPI_FILE
211 #define TPACPI_DRVR_SHORTNAME "tpacpi"
212 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
214 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
215 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
217 #define TPACPI_MAX_ACPI_ARGS 3
219 /* rfkill switches */
221 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
222 TPACPI_RFK_WWAN_SW_ID
,
223 TPACPI_RFK_UWB_SW_ID
,
227 #define TPACPI_LOG TPACPI_FILE ": "
228 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
229 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
230 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
231 #define TPACPI_ERR KERN_ERR TPACPI_LOG
232 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
233 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
234 #define TPACPI_INFO KERN_INFO TPACPI_LOG
235 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
237 /* Debugging printk groups */
238 #define TPACPI_DBG_ALL 0xffff
239 #define TPACPI_DBG_DISCLOSETASK 0x8000
240 #define TPACPI_DBG_INIT 0x0001
241 #define TPACPI_DBG_EXIT 0x0002
242 #define TPACPI_DBG_RFKILL 0x0004
243 #define TPACPI_DBG_HKEY 0x0008
244 #define TPACPI_DBG_FAN 0x0010
245 #define TPACPI_DBG_BRGHT 0x0020
246 #define TPACPI_DBG_MIXER 0x0040
248 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
249 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
250 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
253 /****************************************************************************
254 * Driver-wide structs and misc. variables
259 struct tp_acpi_drv_struct
{
260 const struct acpi_device_id
*hid
;
261 struct acpi_driver
*driver
;
263 void (*notify
) (struct ibm_struct
*, u32
);
266 struct acpi_device
*device
;
272 int (*read
) (struct seq_file
*);
273 int (*write
) (char *);
275 void (*resume
) (void);
276 void (*suspend
) (pm_message_t state
);
277 void (*shutdown
) (void);
279 struct list_head all_drivers
;
281 struct tp_acpi_drv_struct
*acpi
;
284 u8 acpi_driver_registered
:1;
285 u8 acpi_notify_installed
:1;
292 struct ibm_init_struct
{
295 int (*init
) (struct ibm_init_struct
*);
296 struct ibm_struct
*data
;
307 u32 bright_16levels
:1;
308 u32 bright_acpimode
:1;
311 u32 fan_ctrl_status_undef
:1;
313 u32 beep_needs_two_args
:1;
314 u32 mixer_no_level_control
:1;
315 u32 input_device_registered
:1;
316 u32 platform_drv_registered
:1;
317 u32 platform_drv_attrs_registered
:1;
318 u32 sensors_pdrv_registered
:1;
319 u32 sensors_pdrv_attrs_registered
:1;
320 u32 sensors_pdev_attrs_registered
:1;
321 u32 hotkey_poll_active
:1;
325 u16 hotkey_mask_ff
:1;
326 u16 volume_ctrl_forbidden
:1;
329 struct thinkpad_id_data
{
330 unsigned int vendor
; /* ThinkPad vendor:
331 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
333 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
334 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
336 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
338 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
341 char *model_str
; /* ThinkPad T43 */
342 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
344 static struct thinkpad_id_data thinkpad_id
;
347 TPACPI_LIFE_INIT
= 0,
352 static int experimental
;
353 static u32 dbg_level
;
355 static struct workqueue_struct
*tpacpi_wq
;
363 /* Special LED class that can defer work */
364 struct tpacpi_led_classdev
{
365 struct led_classdev led_classdev
;
366 struct work_struct work
;
367 enum led_status_t new_state
;
371 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
372 static int dbg_wlswemul
;
373 static int tpacpi_wlsw_emulstate
;
374 static int dbg_bluetoothemul
;
375 static int tpacpi_bluetooth_emulstate
;
376 static int dbg_wwanemul
;
377 static int tpacpi_wwan_emulstate
;
378 static int dbg_uwbemul
;
379 static int tpacpi_uwb_emulstate
;
383 /*************************************************************************
387 #define dbg_printk(a_dbg_level, format, arg...) \
388 do { if (dbg_level & (a_dbg_level)) \
389 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
392 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
393 #define vdbg_printk dbg_printk
394 static const char *str_supported(int is_supported
);
396 #define vdbg_printk(a_dbg_level, format, arg...) \
400 static void tpacpi_log_usertask(const char * const what
)
402 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
403 what
, task_tgid_vnr(current
));
406 #define tpacpi_disclose_usertask(what, format, arg...) \
409 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
410 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
411 printk(TPACPI_DEBUG "%s: PID %d: " format, \
412 what, task_tgid_vnr(current), ## arg); \
417 * Quirk handling helpers
419 * ThinkPad IDs and versions seen in the field so far
420 * are two-characters from the set [0-9A-Z], i.e. base 36.
422 * We use values well outside that range as specials.
425 #define TPACPI_MATCH_ANY 0xffffU
426 #define TPACPI_MATCH_UNKNOWN 0U
428 /* TPID('1', 'Y') == 0x5931 */
429 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
431 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
432 { .vendor = PCI_VENDOR_ID_IBM, \
433 .bios = TPID(__id1, __id2), \
434 .ec = TPACPI_MATCH_ANY, \
435 .quirks = (__quirk) }
437 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
438 { .vendor = PCI_VENDOR_ID_LENOVO, \
439 .bios = TPID(__id1, __id2), \
440 .ec = TPACPI_MATCH_ANY, \
441 .quirks = (__quirk) }
443 #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \
444 { .vendor = PCI_VENDOR_ID_LENOVO, \
445 .bios = TPACPI_MATCH_ANY, \
446 .ec = TPID(__id1, __id2), \
447 .quirks = (__quirk) }
449 struct tpacpi_quirk
{
453 unsigned long quirks
;
457 * tpacpi_check_quirks() - search BIOS/EC version on a list
458 * @qlist: array of &struct tpacpi_quirk
459 * @qlist_size: number of elements in @qlist
461 * Iterates over a quirks list until one is found that matches the
462 * ThinkPad's vendor, BIOS and EC model.
464 * Returns 0 if nothing matches, otherwise returns the quirks field of
465 * the matching &struct tpacpi_quirk entry.
467 * The match criteria is: vendor, ec and bios much match.
469 static unsigned long __init
tpacpi_check_quirks(
470 const struct tpacpi_quirk
*qlist
,
471 unsigned int qlist_size
)
474 if ((qlist
->vendor
== thinkpad_id
.vendor
||
475 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
476 (qlist
->bios
== thinkpad_id
.bios_model
||
477 qlist
->bios
== TPACPI_MATCH_ANY
) &&
478 (qlist
->ec
== thinkpad_id
.ec_model
||
479 qlist
->ec
== TPACPI_MATCH_ANY
))
480 return qlist
->quirks
;
489 /****************************************************************************
490 ****************************************************************************
492 * ACPI Helpers and device model
494 ****************************************************************************
495 ****************************************************************************/
497 /*************************************************************************
501 static acpi_handle root_handle
;
503 #define TPACPI_HANDLE(object, parent, paths...) \
504 static acpi_handle object##_handle; \
505 static acpi_handle *object##_parent = &parent##_handle; \
506 static char *object##_path; \
507 static char *object##_paths[] = { paths }
509 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
510 "\\_SB.PCI.ISA.EC", /* 570 */
511 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
512 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
513 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
514 "\\_SB.PCI0.ICH3.EC0", /* R31 */
515 "\\_SB.PCI0.LPC.EC", /* all others */
518 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
519 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
521 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
523 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
524 "\\CMS", /* R40, R40e */
527 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
528 "^HKEY", /* R30, R31 */
529 "HKEY", /* all others */
532 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
533 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
534 "\\_SB.PCI0.VID0", /* 770e */
535 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
536 "\\_SB.PCI0.AGP.VID", /* all others */
540 /*************************************************************************
544 static int acpi_evalf(acpi_handle handle
,
545 void *res
, char *method
, char *fmt
, ...)
548 struct acpi_object_list params
;
549 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
550 struct acpi_buffer result
, *resultp
;
551 union acpi_object out_obj
;
559 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
572 params
.pointer
= &in_objs
[0];
579 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
580 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
582 /* add more types as needed */
584 printk(TPACPI_ERR
"acpi_evalf() called "
585 "with invalid format character '%c'\n", c
);
591 if (res_type
!= 'v') {
592 result
.length
= sizeof(out_obj
);
593 result
.pointer
= &out_obj
;
598 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
603 *(int *)res
= out_obj
.integer
.value
;
604 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
607 success
= status
== AE_OK
;
609 /* add more types as needed */
611 printk(TPACPI_ERR
"acpi_evalf() called "
612 "with invalid format character '%c'\n", res_type
);
616 if (!success
&& !quiet
)
617 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
618 method
, fmt0
, status
);
623 static int acpi_ec_read(int i
, u8
*p
)
628 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
632 if (ec_read(i
, p
) < 0)
639 static int acpi_ec_write(int i
, u8 v
)
642 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
645 if (ec_write(i
, v
) < 0)
652 static int issue_thinkpad_cmos_command(int cmos_cmd
)
657 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
663 /*************************************************************************
667 #define TPACPI_ACPIHANDLE_INIT(object) \
668 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
669 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
671 static void drv_acpi_handle_init(char *name
,
672 acpi_handle
*handle
, acpi_handle parent
,
673 char **paths
, int num_paths
, char **path
)
678 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
681 for (i
= 0; i
< num_paths
; i
++) {
682 status
= acpi_get_handle(parent
, paths
[i
], handle
);
683 if (ACPI_SUCCESS(status
)) {
685 dbg_printk(TPACPI_DBG_INIT
,
686 "Found ACPI handle %s for %s\n",
692 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
697 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
699 struct ibm_struct
*ibm
= data
;
701 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
704 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
707 ibm
->acpi
->notify(ibm
, event
);
710 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
717 if (!*ibm
->acpi
->handle
)
720 vdbg_printk(TPACPI_DBG_INIT
,
721 "setting up ACPI notify for %s\n", ibm
->name
);
723 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
725 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
730 ibm
->acpi
->device
->driver_data
= ibm
;
731 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
732 TPACPI_ACPI_EVENT_PREFIX
,
735 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
736 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
737 if (ACPI_FAILURE(status
)) {
738 if (status
== AE_ALREADY_EXISTS
) {
740 "another device driver is already "
741 "handling %s events\n", ibm
->name
);
744 "acpi_install_notify_handler(%s) failed: %d\n",
749 ibm
->flags
.acpi_notify_installed
= 1;
753 static int __init
tpacpi_device_add(struct acpi_device
*device
)
758 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
762 dbg_printk(TPACPI_DBG_INIT
,
763 "registering %s as an ACPI driver\n", ibm
->name
);
767 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
768 if (!ibm
->acpi
->driver
) {
770 "failed to allocate memory for ibm->acpi->driver\n");
774 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
775 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
777 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
779 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
781 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
783 kfree(ibm
->acpi
->driver
);
784 ibm
->acpi
->driver
= NULL
;
786 ibm
->flags
.acpi_driver_registered
= 1;
792 /****************************************************************************
793 ****************************************************************************
797 ****************************************************************************
798 ****************************************************************************/
800 static int dispatch_proc_show(struct seq_file
*m
, void *v
)
802 struct ibm_struct
*ibm
= m
->private;
804 if (!ibm
|| !ibm
->read
)
809 static int dispatch_proc_open(struct inode
*inode
, struct file
*file
)
811 return single_open(file
, dispatch_proc_show
, PDE(inode
)->data
);
814 static ssize_t
dispatch_proc_write(struct file
*file
,
815 const char __user
*userbuf
,
816 size_t count
, loff_t
*pos
)
818 struct ibm_struct
*ibm
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
822 if (!ibm
|| !ibm
->write
)
824 if (count
> PAGE_SIZE
- 2)
827 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
831 if (copy_from_user(kernbuf
, userbuf
, count
)) {
837 strcat(kernbuf
, ",");
838 ret
= ibm
->write(kernbuf
);
847 static const struct file_operations dispatch_proc_fops
= {
848 .owner
= THIS_MODULE
,
849 .open
= dispatch_proc_open
,
852 .release
= single_release
,
853 .write
= dispatch_proc_write
,
856 static char *next_cmd(char **cmds
)
861 while ((end
= strchr(start
, ',')) && end
== start
)
873 /****************************************************************************
874 ****************************************************************************
876 * Device model: input, hwmon and platform
878 ****************************************************************************
879 ****************************************************************************/
881 static struct platform_device
*tpacpi_pdev
;
882 static struct platform_device
*tpacpi_sensors_pdev
;
883 static struct device
*tpacpi_hwmon
;
884 static struct input_dev
*tpacpi_inputdev
;
885 static struct mutex tpacpi_inputdev_send_mutex
;
886 static LIST_HEAD(tpacpi_all_drivers
);
888 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
891 struct ibm_struct
*ibm
, *itmp
;
893 list_for_each_entry_safe(ibm
, itmp
,
897 (ibm
->suspend
)(state
);
903 static int tpacpi_resume_handler(struct platform_device
*pdev
)
905 struct ibm_struct
*ibm
, *itmp
;
907 list_for_each_entry_safe(ibm
, itmp
,
917 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
919 struct ibm_struct
*ibm
, *itmp
;
921 list_for_each_entry_safe(ibm
, itmp
,
929 static struct platform_driver tpacpi_pdriver
= {
931 .name
= TPACPI_DRVR_NAME
,
932 .owner
= THIS_MODULE
,
934 .suspend
= tpacpi_suspend_handler
,
935 .resume
= tpacpi_resume_handler
,
936 .shutdown
= tpacpi_shutdown_handler
,
939 static struct platform_driver tpacpi_hwmon_pdriver
= {
941 .name
= TPACPI_HWMON_DRVR_NAME
,
942 .owner
= THIS_MODULE
,
946 /*************************************************************************
947 * sysfs support helpers
950 struct attribute_set
{
951 unsigned int members
, max_members
;
952 struct attribute_group group
;
955 struct attribute_set_obj
{
956 struct attribute_set s
;
958 } __attribute__((packed
));
960 static struct attribute_set
*create_attr_set(unsigned int max_members
,
963 struct attribute_set_obj
*sobj
;
965 if (max_members
== 0)
968 /* Allocates space for implicit NULL at the end too */
969 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
970 max_members
* sizeof(struct attribute
*),
974 sobj
->s
.max_members
= max_members
;
975 sobj
->s
.group
.attrs
= &sobj
->a
;
976 sobj
->s
.group
.name
= name
;
981 #define destroy_attr_set(_set) \
984 /* not multi-threaded safe, use it in a single thread per set */
985 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
990 if (s
->members
>= s
->max_members
)
993 s
->group
.attrs
[s
->members
] = attr
;
999 static int add_many_to_attr_set(struct attribute_set
*s
,
1000 struct attribute
**attr
,
1005 for (i
= 0; i
< count
; i
++) {
1006 res
= add_to_attr_set(s
, attr
[i
]);
1014 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
1016 sysfs_remove_group(kobj
, &s
->group
);
1017 destroy_attr_set(s
);
1020 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
1021 sysfs_create_group(_kobj, &_attr_set->group)
1023 static int parse_strtoul(const char *buf
,
1024 unsigned long max
, unsigned long *value
)
1028 while (*buf
&& isspace(*buf
))
1030 *value
= simple_strtoul(buf
, &endp
, 0);
1031 while (*endp
&& isspace(*endp
))
1033 if (*endp
|| *value
> max
)
1039 static void tpacpi_disable_brightness_delay(void)
1041 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
1042 printk(TPACPI_NOTICE
1043 "ACPI backlight control delay disabled\n");
1046 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
1048 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1049 union acpi_object
*obj
;
1052 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
1053 obj
= (union acpi_object
*)buffer
.pointer
;
1054 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
1055 printk(TPACPI_ERR
"Unknown _BCL data, "
1056 "please report this to %s\n", TPACPI_MAIL
);
1059 rc
= obj
->package
.count
;
1065 kfree(buffer
.pointer
);
1069 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1070 u32 lvl
, void *context
, void **rv
)
1072 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1073 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1075 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1076 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1077 BUG_ON(!rv
|| !*rv
);
1078 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1079 return AE_CTRL_TERMINATE
;
1086 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1088 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1092 void *bcl_ptr
= &bcl_levels
;
1095 TPACPI_ACPIHANDLE_INIT(vid
);
1101 * Search for a _BCL method, and execute it. This is safe on all
1102 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1103 * BIOS in ACPI backlight control mode. We do NOT have to care
1104 * about calling the _BCL method in an enabled video device, any
1105 * will do for our purposes.
1108 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1109 tpacpi_acpi_walk_find_bcl
, NULL
,
1112 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1113 tp_features
.bright_acpimode
= 1;
1114 return (bcl_levels
- 2);
1120 static int __init
tpacpi_new_rfkill(const unsigned int id
,
1121 struct rfkill
**rfk
,
1122 const enum rfkill_type rfktype
,
1124 const bool set_default
,
1125 int (*toggle_radio
)(void *, enum rfkill_state
),
1126 int (*get_state
)(void *, enum rfkill_state
*))
1129 enum rfkill_state initial_state
= RFKILL_STATE_SOFT_BLOCKED
;
1131 res
= get_state(NULL
, &initial_state
);
1134 "failed to read initial state for %s, error %d; "
1135 "will turn radio off\n", name
, res
);
1136 } else if (set_default
) {
1137 /* try to set the initial state as the default for the rfkill
1138 * type, since we ask the firmware to preserve it across S5 in
1140 if (rfkill_set_default(rfktype
,
1141 (initial_state
== RFKILL_STATE_UNBLOCKED
) ?
1142 RFKILL_STATE_UNBLOCKED
:
1143 RFKILL_STATE_SOFT_BLOCKED
) == -EPERM
)
1144 vdbg_printk(TPACPI_DBG_RFKILL
,
1145 "Default state for %s cannot be changed\n",
1149 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
1152 "failed to allocate memory for rfkill class\n");
1156 (*rfk
)->name
= name
;
1157 (*rfk
)->get_state
= get_state
;
1158 (*rfk
)->toggle_radio
= toggle_radio
;
1159 (*rfk
)->state
= initial_state
;
1161 res
= rfkill_register(*rfk
);
1164 "failed to register %s rfkill switch: %d\n",
1171 printk(TPACPI_INFO
"rfkill switch %s: radio is %sblocked\n",
1172 name
, (initial_state
== RFKILL_STATE_UNBLOCKED
) ?
1173 "un" : (initial_state
== RFKILL_STATE_SOFT_BLOCKED
) ?
1178 static void printk_deprecated_attribute(const char * const what
,
1179 const char * const details
)
1181 tpacpi_log_usertask("deprecated sysfs attribute");
1182 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1183 "will be removed. %s\n",
1187 static void printk_deprecated_rfkill_attribute(const char * const what
)
1189 printk_deprecated_attribute(what
,
1190 "Please switch to generic rfkill before year 2010");
1193 /*************************************************************************
1194 * thinkpad-acpi driver attributes
1197 /* interface_version --------------------------------------------------- */
1198 static ssize_t
tpacpi_driver_interface_version_show(
1199 struct device_driver
*drv
,
1202 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1205 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1206 tpacpi_driver_interface_version_show
, NULL
);
1208 /* debug_level --------------------------------------------------------- */
1209 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1212 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1215 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1216 const char *buf
, size_t count
)
1220 if (parse_strtoul(buf
, 0xffff, &t
))
1228 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1229 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1231 /* version ------------------------------------------------------------- */
1232 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1235 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1236 TPACPI_DESC
, TPACPI_VERSION
);
1239 static DRIVER_ATTR(version
, S_IRUGO
,
1240 tpacpi_driver_version_show
, NULL
);
1242 /* --------------------------------------------------------------------- */
1244 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1246 static void tpacpi_send_radiosw_update(void);
1248 /* wlsw_emulstate ------------------------------------------------------ */
1249 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1252 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1255 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1256 const char *buf
, size_t count
)
1260 if (parse_strtoul(buf
, 1, &t
))
1263 if (tpacpi_wlsw_emulstate
!= t
) {
1264 tpacpi_wlsw_emulstate
= !!t
;
1265 tpacpi_send_radiosw_update();
1267 tpacpi_wlsw_emulstate
= !!t
;
1272 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1273 tpacpi_driver_wlsw_emulstate_show
,
1274 tpacpi_driver_wlsw_emulstate_store
);
1276 /* bluetooth_emulstate ------------------------------------------------- */
1277 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1278 struct device_driver
*drv
,
1281 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1284 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1285 struct device_driver
*drv
,
1286 const char *buf
, size_t count
)
1290 if (parse_strtoul(buf
, 1, &t
))
1293 tpacpi_bluetooth_emulstate
= !!t
;
1298 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1299 tpacpi_driver_bluetooth_emulstate_show
,
1300 tpacpi_driver_bluetooth_emulstate_store
);
1302 /* wwan_emulstate ------------------------------------------------- */
1303 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1304 struct device_driver
*drv
,
1307 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1310 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1311 struct device_driver
*drv
,
1312 const char *buf
, size_t count
)
1316 if (parse_strtoul(buf
, 1, &t
))
1319 tpacpi_wwan_emulstate
= !!t
;
1324 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1325 tpacpi_driver_wwan_emulstate_show
,
1326 tpacpi_driver_wwan_emulstate_store
);
1328 /* uwb_emulstate ------------------------------------------------- */
1329 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1330 struct device_driver
*drv
,
1333 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1336 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1337 struct device_driver
*drv
,
1338 const char *buf
, size_t count
)
1342 if (parse_strtoul(buf
, 1, &t
))
1345 tpacpi_uwb_emulstate
= !!t
;
1350 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1351 tpacpi_driver_uwb_emulstate_show
,
1352 tpacpi_driver_uwb_emulstate_store
);
1355 /* --------------------------------------------------------------------- */
1357 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1358 &driver_attr_debug_level
, &driver_attr_version
,
1359 &driver_attr_interface_version
,
1362 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1368 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1369 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1373 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1374 if (!res
&& dbg_wlswemul
)
1375 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1376 if (!res
&& dbg_bluetoothemul
)
1377 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1378 if (!res
&& dbg_wwanemul
)
1379 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1380 if (!res
&& dbg_uwbemul
)
1381 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1387 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1391 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1392 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1394 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1395 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1396 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1397 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1398 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1402 /*************************************************************************
1407 * Table of recommended minimum BIOS versions
1409 * Reasons for listing:
1410 * 1. Stable BIOS, listed because the unknown ammount of
1411 * bugs and bad ACPI behaviour on older versions
1413 * 2. BIOS or EC fw with known bugs that trigger on Linux
1415 * 3. BIOS with known reduced functionality in older versions
1417 * We recommend the latest BIOS and EC version.
1418 * We only support the latest BIOS and EC fw version as a rule.
1420 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1421 * Information from users in ThinkWiki
1423 * WARNING: we use this table also to detect that the machine is
1424 * a ThinkPad in some cases, so don't remove entries lightly.
1427 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1428 { .vendor = (__v), \
1429 .bios = TPID(__id1, __id2), \
1430 .ec = TPACPI_MATCH_ANY, \
1431 .quirks = TPACPI_MATCH_ANY << 16 \
1432 | (__bv1) << 8 | (__bv2) }
1434 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1435 __eid, __ev1, __ev2) \
1436 { .vendor = (__v), \
1437 .bios = TPID(__bid1, __bid2), \
1439 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1440 | (__bv1) << 8 | (__bv2) }
1442 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1443 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1445 /* Outdated IBM BIOSes often lack the EC id string */
1446 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1447 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1448 __bv1, __bv2, TPID(__id1, __id2), \
1450 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1451 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1454 /* Outdated IBM BIOSes often lack the EC id string */
1455 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1456 __eid1, __eid2, __ev1, __ev2) \
1457 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1458 __bv1, __bv2, TPID(__eid1, __eid2), \
1460 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1461 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1464 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1465 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1467 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1468 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1469 __bv1, __bv2, TPID(__id1, __id2), \
1472 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1473 __eid1, __eid2, __ev1, __ev2) \
1474 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1475 __bv1, __bv2, TPID(__eid1, __eid2), \
1478 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1479 /* Numeric models ------------------ */
1480 /* FW MODEL BIOS VERS */
1481 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1482 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1483 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1484 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1485 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1486 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1487 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1488 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1489 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1491 /* A-series ------------------------- */
1492 /* FW MODEL BIOS VERS EC VERS */
1493 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1494 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1495 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1496 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1497 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1498 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1499 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1500 TPV_QI0('1', '3', '2', '0'), /* A22m */
1501 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1502 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1503 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1505 /* G-series ------------------------- */
1506 /* FW MODEL BIOS VERS */
1507 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1508 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1510 /* R-series, T-series --------------- */
1511 /* FW MODEL BIOS VERS EC VERS */
1512 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1513 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1514 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1515 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1516 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1517 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1518 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1519 T40/p, T41/p, T42/p (1) */
1520 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1521 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1522 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1523 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1525 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1526 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1527 TPV_QI0('1', '6', '3', '2'), /* T22 */
1528 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1529 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1530 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1532 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1533 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1534 TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */
1536 /* BIOS FW BIOS VERS EC FW EC VERS */
1537 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1538 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1540 /* X-series ------------------------- */
1541 /* FW MODEL BIOS VERS EC VERS */
1542 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1543 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1544 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1545 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1546 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1547 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1548 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1550 TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */
1551 TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */
1553 /* (0) - older versions lack DMI EC fw string and functionality */
1554 /* (1) - older versions known to lack functionality */
1565 static void __init
tpacpi_check_outdated_fw(void)
1567 unsigned long fwvers
;
1568 u16 ec_version
, bios_version
;
1570 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1571 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1576 bios_version
= fwvers
& 0xffffU
;
1577 ec_version
= (fwvers
>> 16) & 0xffffU
;
1579 /* note that unknown versions are set to 0x0000 and we use that */
1580 if ((bios_version
> thinkpad_id
.bios_release
) ||
1581 (ec_version
> thinkpad_id
.ec_release
&&
1582 ec_version
!= TPACPI_MATCH_ANY
)) {
1584 * The changelogs would let us track down the exact
1585 * reason, but it is just too much of a pain to track
1586 * it. We only list BIOSes that are either really
1587 * broken, or really stable to begin with, so it is
1588 * best if the user upgrades the firmware anyway.
1591 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1593 "WARNING: This firmware may be missing critical bug "
1594 "fixes and/or important features\n");
1598 static bool __init
tpacpi_is_fw_known(void)
1600 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1601 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1604 /****************************************************************************
1605 ****************************************************************************
1609 ****************************************************************************
1610 ****************************************************************************/
1612 /*************************************************************************
1613 * thinkpad-acpi init subdriver
1616 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1618 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1619 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1621 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1622 (thinkpad_id
.bios_version_str
) ?
1623 thinkpad_id
.bios_version_str
: "unknown",
1624 (thinkpad_id
.ec_version_str
) ?
1625 thinkpad_id
.ec_version_str
: "unknown");
1627 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1628 printk(TPACPI_INFO
"%s %s, model %s\n",
1629 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1630 "IBM" : ((thinkpad_id
.vendor
==
1631 PCI_VENDOR_ID_LENOVO
) ?
1632 "Lenovo" : "Unknown vendor"),
1633 thinkpad_id
.model_str
,
1634 (thinkpad_id
.nummodel_str
) ?
1635 thinkpad_id
.nummodel_str
: "unknown");
1637 tpacpi_check_outdated_fw();
1641 static int thinkpad_acpi_driver_read(struct seq_file
*m
)
1643 seq_printf(m
, "driver:\t\t%s\n", TPACPI_DESC
);
1644 seq_printf(m
, "version:\t%s\n", TPACPI_VERSION
);
1648 static struct ibm_struct thinkpad_acpi_driver_data
= {
1650 .read
= thinkpad_acpi_driver_read
,
1653 /*************************************************************************
1658 * ThinkPad firmware event model
1660 * The ThinkPad firmware has two main event interfaces: normal ACPI
1661 * notifications (which follow the ACPI standard), and a private event
1664 * The private event interface also issues events for the hotkeys. As
1665 * the driver gained features, the event handling code ended up being
1666 * built around the hotkey subdriver. This will need to be refactored
1667 * to a more formal event API eventually.
1669 * Some "hotkeys" are actually supposed to be used as event reports,
1670 * such as "brightness has changed", "volume has changed", depending on
1671 * the ThinkPad model and how the firmware is operating.
1673 * Unlike other classes, hotkey-class events have mask/unmask control on
1674 * non-ancient firmware. However, how it behaves changes a lot with the
1675 * firmware model and version.
1678 enum { /* hot key scan codes (derived from ACPI DSDT) */
1679 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1680 TP_ACPI_HOTKEYSCAN_FNF2
,
1681 TP_ACPI_HOTKEYSCAN_FNF3
,
1682 TP_ACPI_HOTKEYSCAN_FNF4
,
1683 TP_ACPI_HOTKEYSCAN_FNF5
,
1684 TP_ACPI_HOTKEYSCAN_FNF6
,
1685 TP_ACPI_HOTKEYSCAN_FNF7
,
1686 TP_ACPI_HOTKEYSCAN_FNF8
,
1687 TP_ACPI_HOTKEYSCAN_FNF9
,
1688 TP_ACPI_HOTKEYSCAN_FNF10
,
1689 TP_ACPI_HOTKEYSCAN_FNF11
,
1690 TP_ACPI_HOTKEYSCAN_FNF12
,
1691 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1692 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1693 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1694 TP_ACPI_HOTKEYSCAN_FNHOME
,
1695 TP_ACPI_HOTKEYSCAN_FNEND
,
1696 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1697 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1698 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1699 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1700 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1701 TP_ACPI_HOTKEYSCAN_MUTE
,
1702 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1705 enum { /* Keys/events available through NVRAM polling */
1706 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1707 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1710 enum { /* Positions of some of the keys in hotkey masks */
1711 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1712 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1713 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1714 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1715 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1716 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1717 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1718 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1719 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1720 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1721 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1724 enum { /* NVRAM to ACPI HKEY group map */
1725 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1726 TP_ACPI_HKEY_ZOOM_MASK
|
1727 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1728 TP_ACPI_HKEY_HIBERNATE_MASK
,
1729 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1730 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1731 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1732 TP_ACPI_HKEY_VOLDWN_MASK
|
1733 TP_ACPI_HKEY_MUTE_MASK
,
1736 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1737 struct tp_nvram_state
{
1738 u16 thinkpad_toggle
:1;
1740 u16 display_toggle
:1;
1741 u16 thinklight_toggle
:1;
1742 u16 hibernate_toggle
:1;
1743 u16 displayexp_toggle
:1;
1744 u16 display_state
:1;
1745 u16 brightness_toggle
:1;
1746 u16 volume_toggle
:1;
1749 u8 brightness_level
;
1753 /* kthread for the hotkey poller */
1754 static struct task_struct
*tpacpi_hotkey_task
;
1756 /* Acquired while the poller kthread is running, use to sync start/stop */
1757 static struct mutex hotkey_thread_mutex
;
1760 * Acquire mutex to write poller control variables as an
1763 * Increment hotkey_config_change when changing them if you
1764 * want the kthread to forget old state.
1766 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1768 static struct mutex hotkey_thread_data_mutex
;
1769 static unsigned int hotkey_config_change
;
1772 * hotkey poller control variables
1774 * Must be atomic or readers will also need to acquire mutex
1776 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1777 * should be used only when the changes need to be taken as
1778 * a block, OR when one needs to force the kthread to forget
1781 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1782 static unsigned int hotkey_poll_freq
= 10; /* Hz */
1784 #define HOTKEY_CONFIG_CRITICAL_START \
1786 mutex_lock(&hotkey_thread_data_mutex); \
1787 hotkey_config_change++; \
1789 #define HOTKEY_CONFIG_CRITICAL_END \
1790 mutex_unlock(&hotkey_thread_data_mutex);
1792 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1794 #define hotkey_source_mask 0U
1795 #define HOTKEY_CONFIG_CRITICAL_START
1796 #define HOTKEY_CONFIG_CRITICAL_END
1798 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1800 static struct mutex hotkey_mutex
;
1802 static enum { /* Reasons for waking up */
1803 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1804 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1805 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1806 } hotkey_wakeup_reason
;
1808 static int hotkey_autosleep_ack
;
1810 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
1811 static u32 hotkey_all_mask
; /* all events supported in fw */
1812 static u32 hotkey_reserved_mask
; /* events better left disabled */
1813 static u32 hotkey_driver_mask
; /* events needed by the driver */
1814 static u32 hotkey_user_mask
; /* events visible to userspace */
1815 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
1817 static unsigned int hotkey_report_mode
;
1819 static u16
*hotkey_keycode_map
;
1821 static struct attribute_set
*hotkey_dev_attributes
;
1823 static void tpacpi_driver_event(const unsigned int hkey_event
);
1824 static void hotkey_driver_event(const unsigned int scancode
);
1826 /* HKEY.MHKG() return bits */
1827 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1829 static int hotkey_get_wlsw(int *status
)
1831 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1833 *status
= !!tpacpi_wlsw_emulstate
;
1837 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1842 static int hotkey_get_tablet_mode(int *status
)
1846 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1849 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1854 * Reads current event mask from firmware, and updates
1855 * hotkey_acpi_mask accordingly. Also resets any bits
1856 * from hotkey_user_mask that are unavailable to be
1857 * delivered (shadow requirement of the userspace ABI).
1859 * Call with hotkey_mutex held
1861 static int hotkey_mask_get(void)
1863 if (tp_features
.hotkey_mask
) {
1866 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1869 hotkey_acpi_mask
= m
;
1871 /* no mask support doesn't mean no event support... */
1872 hotkey_acpi_mask
= hotkey_all_mask
;
1875 /* sync userspace-visible mask */
1876 hotkey_user_mask
&= (hotkey_acpi_mask
| hotkey_source_mask
);
1881 void static hotkey_mask_warn_incomplete_mask(void)
1883 /* log only what the user can fix... */
1884 const u32 wantedmask
= hotkey_driver_mask
&
1885 ~(hotkey_acpi_mask
| hotkey_source_mask
) &
1886 (hotkey_all_mask
| TPACPI_HKEY_NVRAM_KNOWN_MASK
);
1889 printk(TPACPI_NOTICE
1890 "required events 0x%08x not enabled!\n",
1895 * Set the firmware mask when supported
1897 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
1899 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
1901 * Call with hotkey_mutex held
1903 static int hotkey_mask_set(u32 mask
)
1908 const u32 fwmask
= mask
& ~hotkey_source_mask
;
1910 if (tp_features
.hotkey_mask
) {
1911 for (i
= 0; i
< 32; i
++) {
1912 if (!acpi_evalf(hkey_handle
,
1913 NULL
, "MHKM", "vdd", i
+ 1,
1914 !!(mask
& (1 << i
)))) {
1922 * We *must* make an inconditional call to hotkey_mask_get to
1923 * refresh hotkey_acpi_mask and update hotkey_user_mask
1925 * Take the opportunity to also log when we cannot _enable_
1928 if (!hotkey_mask_get() && !rc
&& (fwmask
& ~hotkey_acpi_mask
)) {
1929 printk(TPACPI_NOTICE
1930 "asked for hotkey mask 0x%08x, but "
1931 "firmware forced it to 0x%08x\n",
1932 fwmask
, hotkey_acpi_mask
);
1935 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
)
1936 hotkey_mask_warn_incomplete_mask();
1942 * Sets hotkey_user_mask and tries to set the firmware mask
1944 * Call with hotkey_mutex held
1946 static int hotkey_user_mask_set(const u32 mask
)
1950 /* Give people a chance to notice they are doing something that
1951 * is bound to go boom on their users sooner or later */
1952 if (!tp_warned
.hotkey_mask_ff
&&
1953 (mask
== 0xffff || mask
== 0xffffff ||
1954 mask
== 0xffffffff)) {
1955 tp_warned
.hotkey_mask_ff
= 1;
1956 printk(TPACPI_NOTICE
1957 "setting the hotkey mask to 0x%08x is likely "
1958 "not the best way to go about it\n", mask
);
1959 printk(TPACPI_NOTICE
1960 "please consider using the driver defaults, "
1961 "and refer to up-to-date thinkpad-acpi "
1965 /* Try to enable what the user asked for, plus whatever we need.
1966 * this syncs everything but won't enable bits in hotkey_user_mask */
1967 rc
= hotkey_mask_set((mask
| hotkey_driver_mask
) & ~hotkey_source_mask
);
1969 /* Enable the available bits in hotkey_user_mask */
1970 hotkey_user_mask
= mask
& (hotkey_acpi_mask
| hotkey_source_mask
);
1976 * Sets the driver hotkey mask.
1978 * Can be called even if the hotkey subdriver is inactive
1980 static int tpacpi_hotkey_driver_mask_set(const u32 mask
)
1984 /* Do the right thing if hotkey_init has not been called yet */
1985 if (!tp_features
.hotkey
) {
1986 hotkey_driver_mask
= mask
;
1990 mutex_lock(&hotkey_mutex
);
1992 HOTKEY_CONFIG_CRITICAL_START
1993 hotkey_driver_mask
= mask
;
1994 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1995 hotkey_source_mask
|= (mask
& ~hotkey_all_mask
);
1997 HOTKEY_CONFIG_CRITICAL_END
1999 rc
= hotkey_mask_set((hotkey_acpi_mask
| hotkey_driver_mask
) &
2000 ~hotkey_source_mask
);
2001 mutex_unlock(&hotkey_mutex
);
2006 static int hotkey_status_get(int *status
)
2008 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
2014 static int hotkey_status_set(bool enable
)
2016 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
2022 static void tpacpi_input_send_tabletsw(void)
2026 if (tp_features
.hotkey_tablet
&&
2027 !hotkey_get_tablet_mode(&state
)) {
2028 mutex_lock(&tpacpi_inputdev_send_mutex
);
2030 input_report_switch(tpacpi_inputdev
,
2031 SW_TABLET_MODE
, !!state
);
2032 input_sync(tpacpi_inputdev
);
2034 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2038 /* Do NOT call without validating scancode first */
2039 static void tpacpi_input_send_key(const unsigned int scancode
)
2041 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
2043 if (keycode
!= KEY_RESERVED
) {
2044 mutex_lock(&tpacpi_inputdev_send_mutex
);
2046 input_report_key(tpacpi_inputdev
, keycode
, 1);
2047 if (keycode
== KEY_UNKNOWN
)
2048 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2050 input_sync(tpacpi_inputdev
);
2052 input_report_key(tpacpi_inputdev
, keycode
, 0);
2053 if (keycode
== KEY_UNKNOWN
)
2054 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2056 input_sync(tpacpi_inputdev
);
2058 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2062 /* Do NOT call without validating scancode first */
2063 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
2065 hotkey_driver_event(scancode
);
2066 if (hotkey_user_mask
& (1 << scancode
))
2067 tpacpi_input_send_key(scancode
);
2070 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2071 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2073 /* Do NOT call without validating scancode first */
2074 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2076 tpacpi_input_send_key_masked(scancode
);
2077 if (hotkey_report_mode
< 2) {
2078 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2079 0x80, TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
2083 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2087 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2088 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2089 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2090 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2091 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2092 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2094 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2095 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2096 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2098 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2099 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2100 n
->displayexp_toggle
=
2101 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2103 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2104 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2105 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2106 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2107 n
->brightness_toggle
=
2108 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2110 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2111 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2112 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2113 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2114 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2115 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2119 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2120 struct tp_nvram_state
*newn
,
2121 const u32 event_mask
)
2124 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2126 if ((event_mask & (1 << __scancode)) && \
2127 oldn->__member != newn->__member) \
2128 tpacpi_hotkey_send_key(__scancode); \
2131 #define TPACPI_MAY_SEND_KEY(__scancode) \
2133 if (event_mask & (1 << __scancode)) \
2134 tpacpi_hotkey_send_key(__scancode); \
2137 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2138 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2139 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2140 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2142 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2144 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2147 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2148 if (oldn
->mute
!= newn
->mute
) {
2149 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2151 if (oldn
->volume_level
> newn
->volume_level
) {
2152 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2153 } else if (oldn
->volume_level
< newn
->volume_level
) {
2154 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2155 } else if (oldn
->mute
== newn
->mute
) {
2156 /* repeated key presses that didn't change state */
2158 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2159 } else if (newn
->volume_level
!= 0) {
2160 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2162 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2167 /* handle brightness */
2168 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2169 if (oldn
->brightness_level
< newn
->brightness_level
) {
2170 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2171 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
2172 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2174 /* repeated key presses that didn't change state */
2175 if (newn
->brightness_level
!= 0) {
2176 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2178 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2183 #undef TPACPI_COMPARE_KEY
2184 #undef TPACPI_MAY_SEND_KEY
2190 * We track all events in hotkey_source_mask all the time, since
2191 * most of them are edge-based. We only issue those requested by
2192 * hotkey_user_mask or hotkey_driver_mask, though.
2194 static int hotkey_kthread(void *data
)
2196 struct tp_nvram_state s
[2];
2197 u32 poll_mask
, event_mask
;
2198 unsigned int si
, so
;
2200 unsigned int change_detector
, must_reset
;
2201 unsigned int poll_freq
;
2203 mutex_lock(&hotkey_thread_mutex
);
2205 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2214 /* Initial state for compares */
2215 mutex_lock(&hotkey_thread_data_mutex
);
2216 change_detector
= hotkey_config_change
;
2217 poll_mask
= hotkey_source_mask
;
2218 event_mask
= hotkey_source_mask
&
2219 (hotkey_driver_mask
| hotkey_user_mask
);
2220 poll_freq
= hotkey_poll_freq
;
2221 mutex_unlock(&hotkey_thread_data_mutex
);
2222 hotkey_read_nvram(&s
[so
], poll_mask
);
2224 while (!kthread_should_stop()) {
2226 if (likely(poll_freq
))
2229 t
= 100; /* should never happen... */
2231 t
= msleep_interruptible(t
);
2232 if (unlikely(kthread_should_stop()))
2234 must_reset
= try_to_freeze();
2235 if (t
> 0 && !must_reset
)
2238 mutex_lock(&hotkey_thread_data_mutex
);
2239 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2240 /* forget old state on thaw or config change */
2243 change_detector
= hotkey_config_change
;
2245 poll_mask
= hotkey_source_mask
;
2246 event_mask
= hotkey_source_mask
&
2247 (hotkey_driver_mask
| hotkey_user_mask
);
2248 poll_freq
= hotkey_poll_freq
;
2249 mutex_unlock(&hotkey_thread_data_mutex
);
2251 if (likely(poll_mask
)) {
2252 hotkey_read_nvram(&s
[si
], poll_mask
);
2253 if (likely(si
!= so
)) {
2254 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2264 mutex_unlock(&hotkey_thread_mutex
);
2268 /* call with hotkey_mutex held */
2269 static void hotkey_poll_stop_sync(void)
2271 if (tpacpi_hotkey_task
) {
2272 if (frozen(tpacpi_hotkey_task
) ||
2273 freezing(tpacpi_hotkey_task
))
2274 thaw_process(tpacpi_hotkey_task
);
2276 kthread_stop(tpacpi_hotkey_task
);
2277 tpacpi_hotkey_task
= NULL
;
2278 mutex_lock(&hotkey_thread_mutex
);
2279 /* at this point, the thread did exit */
2280 mutex_unlock(&hotkey_thread_mutex
);
2284 /* call with hotkey_mutex held */
2285 static void hotkey_poll_setup(bool may_warn
)
2287 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2288 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2290 if (hotkey_poll_freq
> 0 &&
2291 (poll_driver_mask
||
2292 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2293 if (!tpacpi_hotkey_task
) {
2294 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2295 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2296 if (IS_ERR(tpacpi_hotkey_task
)) {
2297 tpacpi_hotkey_task
= NULL
;
2299 "could not create kernel thread "
2300 "for hotkey polling\n");
2304 hotkey_poll_stop_sync();
2305 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2306 hotkey_poll_freq
== 0) {
2307 printk(TPACPI_NOTICE
2308 "hot keys 0x%08x and/or events 0x%08x "
2309 "require polling, which is currently "
2311 poll_user_mask
, poll_driver_mask
);
2316 static void hotkey_poll_setup_safe(bool may_warn
)
2318 mutex_lock(&hotkey_mutex
);
2319 hotkey_poll_setup(may_warn
);
2320 mutex_unlock(&hotkey_mutex
);
2323 /* call with hotkey_mutex held */
2324 static void hotkey_poll_set_freq(unsigned int freq
)
2327 hotkey_poll_stop_sync();
2329 hotkey_poll_freq
= freq
;
2332 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2334 static void hotkey_poll_setup_safe(bool __unused
)
2338 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2340 static int hotkey_inputdev_open(struct input_dev
*dev
)
2342 switch (tpacpi_lifecycle
) {
2343 case TPACPI_LIFE_INIT
:
2345 * hotkey_init will call hotkey_poll_setup_safe
2346 * at the appropriate moment
2349 case TPACPI_LIFE_EXITING
:
2351 case TPACPI_LIFE_RUNNING
:
2352 hotkey_poll_setup_safe(false);
2356 /* Should only happen if tpacpi_lifecycle is corrupt */
2361 static void hotkey_inputdev_close(struct input_dev
*dev
)
2363 /* disable hotkey polling when possible */
2364 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
&&
2365 !(hotkey_source_mask
& hotkey_driver_mask
))
2366 hotkey_poll_setup_safe(false);
2369 /* sysfs hotkey enable ------------------------------------------------- */
2370 static ssize_t
hotkey_enable_show(struct device
*dev
,
2371 struct device_attribute
*attr
,
2376 printk_deprecated_attribute("hotkey_enable",
2377 "Hotkey reporting is always enabled");
2379 res
= hotkey_status_get(&status
);
2383 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2386 static ssize_t
hotkey_enable_store(struct device
*dev
,
2387 struct device_attribute
*attr
,
2388 const char *buf
, size_t count
)
2392 printk_deprecated_attribute("hotkey_enable",
2393 "Hotkeys can be disabled through hotkey_mask");
2395 if (parse_strtoul(buf
, 1, &t
))
2404 static struct device_attribute dev_attr_hotkey_enable
=
2405 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2406 hotkey_enable_show
, hotkey_enable_store
);
2408 /* sysfs hotkey mask --------------------------------------------------- */
2409 static ssize_t
hotkey_mask_show(struct device
*dev
,
2410 struct device_attribute
*attr
,
2413 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2416 static ssize_t
hotkey_mask_store(struct device
*dev
,
2417 struct device_attribute
*attr
,
2418 const char *buf
, size_t count
)
2423 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2426 if (mutex_lock_killable(&hotkey_mutex
))
2427 return -ERESTARTSYS
;
2429 res
= hotkey_user_mask_set(t
);
2431 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2432 hotkey_poll_setup(true);
2435 mutex_unlock(&hotkey_mutex
);
2437 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2439 return (res
) ? res
: count
;
2442 static struct device_attribute dev_attr_hotkey_mask
=
2443 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2444 hotkey_mask_show
, hotkey_mask_store
);
2446 /* sysfs hotkey bios_enabled ------------------------------------------- */
2447 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2448 struct device_attribute
*attr
,
2451 return sprintf(buf
, "0\n");
2454 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2455 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2457 /* sysfs hotkey bios_mask ---------------------------------------------- */
2458 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2459 struct device_attribute
*attr
,
2462 printk_deprecated_attribute("hotkey_bios_mask",
2463 "This attribute is useless.");
2464 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2467 static struct device_attribute dev_attr_hotkey_bios_mask
=
2468 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2470 /* sysfs hotkey all_mask ----------------------------------------------- */
2471 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2472 struct device_attribute
*attr
,
2475 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2476 hotkey_all_mask
| hotkey_source_mask
);
2479 static struct device_attribute dev_attr_hotkey_all_mask
=
2480 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2482 /* sysfs hotkey recommended_mask --------------------------------------- */
2483 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2484 struct device_attribute
*attr
,
2487 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2488 (hotkey_all_mask
| hotkey_source_mask
)
2489 & ~hotkey_reserved_mask
);
2492 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2493 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2494 hotkey_recommended_mask_show
, NULL
);
2496 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2498 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2499 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2500 struct device_attribute
*attr
,
2503 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2506 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2507 struct device_attribute
*attr
,
2508 const char *buf
, size_t count
)
2514 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2515 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2518 if (mutex_lock_killable(&hotkey_mutex
))
2519 return -ERESTARTSYS
;
2521 HOTKEY_CONFIG_CRITICAL_START
2522 hotkey_source_mask
= t
;
2523 HOTKEY_CONFIG_CRITICAL_END
2525 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2526 ~hotkey_source_mask
);
2527 hotkey_poll_setup(true);
2529 /* check if events needed by the driver got disabled */
2530 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2531 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2533 mutex_unlock(&hotkey_mutex
);
2536 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2537 "firmware event mask!\n");
2540 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2541 "some important events were disabled: "
2544 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2546 return (rc
< 0) ? rc
: count
;
2549 static struct device_attribute dev_attr_hotkey_source_mask
=
2550 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2551 hotkey_source_mask_show
, hotkey_source_mask_store
);
2553 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2554 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2555 struct device_attribute
*attr
,
2558 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2561 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2562 struct device_attribute
*attr
,
2563 const char *buf
, size_t count
)
2567 if (parse_strtoul(buf
, 25, &t
))
2570 if (mutex_lock_killable(&hotkey_mutex
))
2571 return -ERESTARTSYS
;
2573 hotkey_poll_set_freq(t
);
2574 hotkey_poll_setup(true);
2576 mutex_unlock(&hotkey_mutex
);
2578 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2583 static struct device_attribute dev_attr_hotkey_poll_freq
=
2584 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2585 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2587 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2589 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2590 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2591 struct device_attribute
*attr
,
2595 res
= hotkey_get_wlsw(&s
);
2599 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2602 static struct device_attribute dev_attr_hotkey_radio_sw
=
2603 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2605 static void hotkey_radio_sw_notify_change(void)
2607 if (tp_features
.hotkey_wlsw
)
2608 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2612 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2613 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2614 struct device_attribute
*attr
,
2618 res
= hotkey_get_tablet_mode(&s
);
2622 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2625 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2626 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2628 static void hotkey_tablet_mode_notify_change(void)
2630 if (tp_features
.hotkey_tablet
)
2631 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2632 "hotkey_tablet_mode");
2635 /* sysfs hotkey report_mode -------------------------------------------- */
2636 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2637 struct device_attribute
*attr
,
2640 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2641 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2644 static struct device_attribute dev_attr_hotkey_report_mode
=
2645 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2647 /* sysfs wakeup reason (pollable) -------------------------------------- */
2648 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2649 struct device_attribute
*attr
,
2652 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2655 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2656 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2658 static void hotkey_wakeup_reason_notify_change(void)
2660 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2664 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2665 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2666 struct device_attribute
*attr
,
2669 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2672 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2673 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2674 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2676 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2678 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2679 "wakeup_hotunplug_complete");
2682 /* --------------------------------------------------------------------- */
2684 static struct attribute
*hotkey_attributes
[] __initdata
= {
2685 &dev_attr_hotkey_enable
.attr
,
2686 &dev_attr_hotkey_bios_enabled
.attr
,
2687 &dev_attr_hotkey_bios_mask
.attr
,
2688 &dev_attr_hotkey_report_mode
.attr
,
2689 &dev_attr_hotkey_wakeup_reason
.attr
,
2690 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2691 &dev_attr_hotkey_mask
.attr
,
2692 &dev_attr_hotkey_all_mask
.attr
,
2693 &dev_attr_hotkey_recommended_mask
.attr
,
2694 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2695 &dev_attr_hotkey_source_mask
.attr
,
2696 &dev_attr_hotkey_poll_freq
.attr
,
2700 static void bluetooth_update_rfk(void);
2701 static void wan_update_rfk(void);
2702 static void uwb_update_rfk(void);
2703 static void tpacpi_send_radiosw_update(void)
2707 /* Sync these BEFORE sending any rfkill events */
2708 if (tp_features
.bluetooth
)
2709 bluetooth_update_rfk();
2710 if (tp_features
.wan
)
2712 if (tp_features
.uwb
)
2715 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2716 mutex_lock(&tpacpi_inputdev_send_mutex
);
2718 input_report_switch(tpacpi_inputdev
,
2719 SW_RFKILL_ALL
, !!wlsw
);
2720 input_sync(tpacpi_inputdev
);
2722 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2724 hotkey_radio_sw_notify_change();
2727 static void hotkey_exit(void)
2729 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2730 mutex_lock(&hotkey_mutex
);
2731 hotkey_poll_stop_sync();
2732 mutex_unlock(&hotkey_mutex
);
2735 if (hotkey_dev_attributes
)
2736 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2738 kfree(hotkey_keycode_map
);
2740 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
2741 "restoring original HKEY status and mask\n");
2742 /* yes, there is a bitwise or below, we want the
2743 * functions to be called even if one of them fail */
2744 if (((tp_features
.hotkey_mask
&&
2745 hotkey_mask_set(hotkey_orig_mask
)) |
2746 hotkey_status_set(false)) != 0)
2748 "failed to restore hot key mask "
2749 "to BIOS defaults\n");
2752 static void __init
hotkey_unmap(const unsigned int scancode
)
2754 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
2755 clear_bit(hotkey_keycode_map
[scancode
],
2756 tpacpi_inputdev
->keybit
);
2757 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
2763 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
2766 #define TPACPI_HK_Q_INIMASK 0x0001
2768 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
2769 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
2770 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
2771 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
2772 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
2773 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
2774 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
2775 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
2776 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
2777 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
2778 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
2779 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
2780 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
2781 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
2782 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
2783 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
2784 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
2785 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
2786 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
2787 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
2790 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2792 /* Requirements for changing the default keymaps:
2794 * 1. Many of the keys are mapped to KEY_RESERVED for very
2795 * good reasons. Do not change them unless you have deep
2796 * knowledge on the IBM and Lenovo ThinkPad firmware for
2797 * the various ThinkPad models. The driver behaves
2798 * differently for KEY_RESERVED: such keys have their
2799 * hot key mask *unset* in mask_recommended, and also
2800 * in the initial hot key mask programmed into the
2801 * firmware at driver load time, which means the firm-
2802 * ware may react very differently if you change them to
2805 * 2. You must be subscribed to the linux-thinkpad and
2806 * ibm-acpi-devel mailing lists, and you should read the
2807 * list archives since 2007 if you want to change the
2808 * keymaps. This requirement exists so that you will
2809 * know the past history of problems with the thinkpad-
2810 * acpi driver keymaps, and also that you will be
2811 * listening to any bug reports;
2813 * 3. Do not send thinkpad-acpi specific patches directly to
2814 * for merging, *ever*. Send them to the linux-acpi
2815 * mailinglist for comments. Merging is to be done only
2816 * through acpi-test and the ACPI maintainer.
2818 * If the above is too much to ask, don't change the keymap.
2819 * Ask the thinkpad-acpi maintainer to do it, instead.
2821 static u16 ibm_keycode_map
[] __initdata
= {
2822 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2823 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2824 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2825 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2827 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2828 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2829 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2830 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2832 /* brightness: firmware always reacts to them */
2833 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2834 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2836 /* Thinklight: firmware always react to it */
2837 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2839 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2840 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2842 /* Volume: firmware always react to it and reprograms
2843 * the built-in *extra* mixer. Never map it to control
2844 * another mixer by default. */
2845 KEY_RESERVED
, /* 0x14: VOLUME UP */
2846 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2847 KEY_RESERVED
, /* 0x16: MUTE */
2849 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2851 /* (assignments unknown, please report if found) */
2852 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2853 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2855 static u16 lenovo_keycode_map
[] __initdata
= {
2856 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2857 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2858 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2859 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2861 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2862 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2863 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2864 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2866 /* These should be enabled --only-- when ACPI video
2867 * is disabled (i.e. in "vendor" mode), and are handled
2868 * in a special way by the init code */
2869 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
2870 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
2872 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2874 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2875 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2877 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2878 * react to it and reprograms the built-in *extra* mixer.
2879 * Never map it to control another mixer by default.
2881 * T60?, T61, R60?, R61: firmware and EC tries to send
2882 * these over the regular keyboard, so these are no-ops,
2883 * but there are still weird bugs re. MUTE, so do not
2884 * change unless you get test reports from all Lenovo
2885 * models. May cause the BIOS to interfere with the
2888 KEY_RESERVED
, /* 0x14: VOLUME UP */
2889 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2890 KEY_RESERVED
, /* 0x16: MUTE */
2892 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2894 /* (assignments unknown, please report if found) */
2895 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2896 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2899 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2900 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2901 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2906 bool radiosw_state
= false;
2907 bool tabletsw_state
= false;
2909 unsigned long quirks
;
2911 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2912 "initializing hotkey subdriver\n");
2914 BUG_ON(!tpacpi_inputdev
);
2915 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2916 tpacpi_inputdev
->close
!= NULL
);
2918 TPACPI_ACPIHANDLE_INIT(hkey
);
2919 mutex_init(&hotkey_mutex
);
2921 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2922 mutex_init(&hotkey_thread_mutex
);
2923 mutex_init(&hotkey_thread_data_mutex
);
2926 /* hotkey not supported on 570 */
2927 tp_features
.hotkey
= hkey_handle
!= NULL
;
2929 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2931 str_supported(tp_features
.hotkey
));
2933 if (!tp_features
.hotkey
)
2936 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
2937 ARRAY_SIZE(tpacpi_hotkey_qtable
));
2939 tpacpi_disable_brightness_delay();
2941 /* MUST have enough space for all attributes to be added to
2942 * hotkey_dev_attributes */
2943 hotkey_dev_attributes
= create_attr_set(
2944 ARRAY_SIZE(hotkey_attributes
) + 2,
2946 if (!hotkey_dev_attributes
)
2948 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2950 ARRAY_SIZE(hotkey_attributes
));
2954 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
2955 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2956 for HKEY interface version 0x100 */
2957 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2958 if ((hkeyv
>> 8) != 1) {
2959 printk(TPACPI_ERR
"unknown version of the "
2960 "HKEY interface: 0x%x\n", hkeyv
);
2961 printk(TPACPI_ERR
"please report this to %s\n",
2965 * MHKV 0x100 in A31, R40, R40e,
2966 * T4x, X31, and later
2968 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2969 "firmware HKEY interface version: 0x%x\n",
2972 /* Paranoia check AND init hotkey_all_mask */
2973 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2976 "missing MHKA handler, "
2977 "please report this to %s\n",
2979 /* Fallback: pre-init for FN+F3,F4,F12 */
2980 hotkey_all_mask
= 0x080cU
;
2982 tp_features
.hotkey_mask
= 1;
2987 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2988 "hotkey masks are %s\n",
2989 str_supported(tp_features
.hotkey_mask
));
2991 /* Init hotkey_all_mask if not initialized yet */
2992 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
2993 (quirks
& TPACPI_HK_Q_INIMASK
))
2994 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
2996 /* Init hotkey_acpi_mask and hotkey_orig_mask */
2997 if (tp_features
.hotkey_mask
) {
2998 /* hotkey_source_mask *must* be zero for
2999 * the first hotkey_mask_get to return hotkey_orig_mask */
3000 res
= hotkey_mask_get();
3004 hotkey_orig_mask
= hotkey_acpi_mask
;
3006 hotkey_orig_mask
= hotkey_all_mask
;
3007 hotkey_acpi_mask
= hotkey_all_mask
;
3010 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3012 tp_features
.hotkey_wlsw
= 1;
3013 radiosw_state
= !!tpacpi_wlsw_emulstate
;
3015 "radio switch emulation enabled\n");
3018 /* Not all thinkpads have a hardware radio switch */
3019 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3020 tp_features
.hotkey_wlsw
= 1;
3021 radiosw_state
= !!status
;
3023 "radio switch found; radios are %s\n",
3024 enabled(status
, 0));
3026 if (tp_features
.hotkey_wlsw
)
3027 res
= add_to_attr_set(hotkey_dev_attributes
,
3028 &dev_attr_hotkey_radio_sw
.attr
);
3030 /* For X41t, X60t, X61t Tablets... */
3031 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3032 tp_features
.hotkey_tablet
= 1;
3033 tabletsw_state
= !!(status
& TP_HOTKEY_TABLET_MASK
);
3035 "possible tablet mode switch found; "
3036 "ThinkPad in %s mode\n",
3037 (tabletsw_state
) ? "tablet" : "laptop");
3038 res
= add_to_attr_set(hotkey_dev_attributes
,
3039 &dev_attr_hotkey_tablet_mode
.attr
);
3043 res
= register_attr_set_with_sysfs(
3044 hotkey_dev_attributes
,
3045 &tpacpi_pdev
->dev
.kobj
);
3049 /* Set up key map */
3051 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3053 if (!hotkey_keycode_map
) {
3055 "failed to allocate memory for key map\n");
3060 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
3061 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3062 "using Lenovo default hot key map\n");
3063 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
3064 TPACPI_HOTKEY_MAP_SIZE
);
3066 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3067 "using IBM default hot key map\n");
3068 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
3069 TPACPI_HOTKEY_MAP_SIZE
);
3072 input_set_capability(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
);
3073 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3074 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3075 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3076 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3077 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3078 input_set_capability(tpacpi_inputdev
, EV_KEY
,
3079 hotkey_keycode_map
[i
]);
3081 if (i
< sizeof(hotkey_reserved_mask
)*8)
3082 hotkey_reserved_mask
|= 1 << i
;
3086 if (tp_features
.hotkey_wlsw
) {
3087 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_RFKILL_ALL
);
3088 input_report_switch(tpacpi_inputdev
,
3089 SW_RFKILL_ALL
, radiosw_state
);
3091 if (tp_features
.hotkey_tablet
) {
3092 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_TABLET_MODE
);
3093 input_report_switch(tpacpi_inputdev
,
3094 SW_TABLET_MODE
, tabletsw_state
);
3097 /* Do not issue duplicate brightness change events to
3099 if (!tp_features
.bright_acpimode
)
3100 /* update bright_acpimode... */
3101 tpacpi_check_std_acpi_brightness_support();
3103 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
3105 "This ThinkPad has standard ACPI backlight "
3106 "brightness control, supported by the ACPI "
3108 printk(TPACPI_NOTICE
3109 "Disabling thinkpad-acpi brightness events "
3112 /* Disable brightness up/down on Lenovo thinkpads when
3113 * ACPI is handling them, otherwise it is plain impossible
3114 * for userspace to do something even remotely sane */
3115 hotkey_reserved_mask
|=
3116 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3117 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3118 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3119 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3122 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3123 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3125 & ~hotkey_reserved_mask
;
3127 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3128 "hotkey source mask 0x%08x, polling freq %u\n",
3129 hotkey_source_mask
, hotkey_poll_freq
);
3132 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3133 "enabling firmware HKEY event interface...\n");
3134 res
= hotkey_status_set(true);
3139 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3140 | hotkey_driver_mask
)
3141 & ~hotkey_source_mask
);
3142 if (res
< 0 && res
!= -ENXIO
) {
3146 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3147 & ~hotkey_reserved_mask
;
3148 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3149 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3150 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3152 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3153 "legacy ibm/hotkey event reporting over procfs %s\n",
3154 (hotkey_report_mode
< 2) ?
3155 "enabled" : "disabled");
3157 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3158 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3160 hotkey_poll_setup_safe(true);
3165 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3166 hotkey_dev_attributes
= NULL
;
3168 return (res
< 0)? res
: 1;
3171 static bool hotkey_notify_hotkey(const u32 hkey
,
3173 bool *ignore_acpi_ev
)
3175 /* 0x1000-0x1FFF: key presses */
3176 unsigned int scancode
= hkey
& 0xfff;
3177 *send_acpi_ev
= true;
3178 *ignore_acpi_ev
= false;
3180 if (scancode
> 0 && scancode
< 0x21) {
3182 if (!(hotkey_source_mask
& (1 << scancode
))) {
3183 tpacpi_input_send_key_masked(scancode
);
3184 *send_acpi_ev
= false;
3186 *ignore_acpi_ev
= true;
3193 static bool hotkey_notify_wakeup(const u32 hkey
,
3195 bool *ignore_acpi_ev
)
3197 /* 0x2000-0x2FFF: Wakeup reason */
3198 *send_acpi_ev
= true;
3199 *ignore_acpi_ev
= false;
3202 case TP_HKEY_EV_WKUP_S3_UNDOCK
: /* suspend, undock */
3203 case TP_HKEY_EV_WKUP_S4_UNDOCK
: /* hibernation, undock */
3204 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3205 *ignore_acpi_ev
= true;
3208 case TP_HKEY_EV_WKUP_S3_BAYEJ
: /* suspend, bay eject */
3209 case TP_HKEY_EV_WKUP_S4_BAYEJ
: /* hibernation, bay eject */
3210 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3211 *ignore_acpi_ev
= true;
3214 case TP_HKEY_EV_WKUP_S3_BATLOW
: /* Battery on critical low level/S3 */
3215 case TP_HKEY_EV_WKUP_S4_BATLOW
: /* Battery on critical low level/S4 */
3217 "EMERGENCY WAKEUP: battery almost empty\n");
3218 /* how to auto-heal: */
3219 /* 2313: woke up from S3, go to S4/S5 */
3220 /* 2413: woke up from S4, go to S5 */
3227 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3229 "woke up due to a hot-unplug "
3231 hotkey_wakeup_reason_notify_change();
3236 static bool hotkey_notify_usrevent(const u32 hkey
,
3238 bool *ignore_acpi_ev
)
3240 /* 0x5000-0x5FFF: human interface helpers */
3241 *send_acpi_ev
= true;
3242 *ignore_acpi_ev
= false;
3245 case TP_HKEY_EV_PEN_INSERTED
: /* X61t: tablet pen inserted into bay */
3246 case TP_HKEY_EV_PEN_REMOVED
: /* X61t: tablet pen removed from bay */
3249 case TP_HKEY_EV_TABLET_TABLET
: /* X41t-X61t: tablet mode */
3250 case TP_HKEY_EV_TABLET_NOTEBOOK
: /* X41t-X61t: normal mode */
3251 tpacpi_input_send_tabletsw();
3252 hotkey_tablet_mode_notify_change();
3253 *send_acpi_ev
= false;
3256 case TP_HKEY_EV_LID_CLOSE
: /* Lid closed */
3257 case TP_HKEY_EV_LID_OPEN
: /* Lid opened */
3258 case TP_HKEY_EV_BRGHT_CHANGED
: /* brightness changed */
3259 /* do not propagate these events */
3260 *ignore_acpi_ev
= true;
3268 static void thermal_dump_all_sensors(void);
3270 static bool hotkey_notify_thermal(const u32 hkey
,
3272 bool *ignore_acpi_ev
)
3276 /* 0x6000-0x6FFF: thermal alarms */
3277 *send_acpi_ev
= true;
3278 *ignore_acpi_ev
= false;
3281 case TP_HKEY_EV_THM_TABLE_CHANGED
:
3283 "EC reports that Thermal Table has changed\n");
3284 /* recommended action: do nothing, we don't have
3285 * Lenovo ATM information */
3287 case TP_HKEY_EV_ALARM_BAT_HOT
:
3289 "THERMAL ALARM: battery is too hot!\n");
3290 /* recommended action: warn user through gui */
3292 case TP_HKEY_EV_ALARM_BAT_XHOT
:
3294 "THERMAL EMERGENCY: battery is extremely hot!\n");
3295 /* recommended action: immediate sleep/hibernate */
3297 case TP_HKEY_EV_ALARM_SENSOR_HOT
:
3300 "a sensor reports something is too hot!\n");
3301 /* recommended action: warn user through gui, that */
3302 /* some internal component is too hot */
3304 case TP_HKEY_EV_ALARM_SENSOR_XHOT
:
3306 "THERMAL EMERGENCY: "
3307 "a sensor reports something is extremely hot!\n");
3308 /* recommended action: immediate sleep/hibernate */
3312 "THERMAL ALERT: unknown thermal alarm received\n");
3316 thermal_dump_all_sensors();
3321 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3325 bool ignore_acpi_ev
;
3328 if (event
!= 0x80) {
3330 "unknown HKEY notification event %d\n", event
);
3331 /* forward it to userspace, maybe it knows how to handle it */
3332 acpi_bus_generate_netlink_event(
3333 ibm
->acpi
->device
->pnp
.device_class
,
3334 dev_name(&ibm
->acpi
->device
->dev
),
3340 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3341 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3350 send_acpi_ev
= true;
3351 ignore_acpi_ev
= false;
3353 switch (hkey
>> 12) {
3355 /* 0x1000-0x1FFF: key presses */
3356 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3360 /* 0x2000-0x2FFF: Wakeup reason */
3361 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3365 /* 0x3000-0x3FFF: bay-related wakeups */
3366 if (hkey
== TP_HKEY_EV_BAYEJ_ACK
) {
3367 hotkey_autosleep_ack
= 1;
3370 hotkey_wakeup_hotunplug_complete_notify_change();
3377 /* 0x4000-0x4FFF: dock-related wakeups */
3378 if (hkey
== TP_HKEY_EV_UNDOCK_ACK
) {
3379 hotkey_autosleep_ack
= 1;
3382 hotkey_wakeup_hotunplug_complete_notify_change();
3389 /* 0x5000-0x5FFF: human interface helpers */
3390 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3394 /* 0x6000-0x6FFF: thermal alarms */
3395 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3399 /* 0x7000-0x7FFF: misc */
3400 if (tp_features
.hotkey_wlsw
&&
3401 hkey
== TP_HKEY_EV_RFKILL_CHANGED
) {
3402 tpacpi_send_radiosw_update();
3407 /* fallthrough to default */
3412 printk(TPACPI_NOTICE
3413 "unhandled HKEY event 0x%04x\n", hkey
);
3414 printk(TPACPI_NOTICE
3415 "please report the conditions when this "
3416 "event happened to %s\n", TPACPI_MAIL
);
3420 if (!ignore_acpi_ev
&&
3421 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3422 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3426 /* netlink events */
3427 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3428 acpi_bus_generate_netlink_event(
3429 ibm
->acpi
->device
->pnp
.device_class
,
3430 dev_name(&ibm
->acpi
->device
->dev
),
3436 static void hotkey_suspend(pm_message_t state
)
3438 /* Do these on suspend, we get the events on early resume! */
3439 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3440 hotkey_autosleep_ack
= 0;
3443 static void hotkey_resume(void)
3445 tpacpi_disable_brightness_delay();
3447 if (hotkey_status_set(true) < 0 ||
3448 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3450 "error while attempting to reset the event "
3451 "firmware interface\n");
3453 tpacpi_send_radiosw_update();
3454 hotkey_tablet_mode_notify_change();
3455 hotkey_wakeup_reason_notify_change();
3456 hotkey_wakeup_hotunplug_complete_notify_change();
3457 hotkey_poll_setup_safe(false);
3460 /* procfs -------------------------------------------------------------- */
3461 static int hotkey_read(struct seq_file
*m
)
3465 if (!tp_features
.hotkey
) {
3466 seq_printf(m
, "status:\t\tnot supported\n");
3470 if (mutex_lock_killable(&hotkey_mutex
))
3471 return -ERESTARTSYS
;
3472 res
= hotkey_status_get(&status
);
3474 res
= hotkey_mask_get();
3475 mutex_unlock(&hotkey_mutex
);
3479 seq_printf(m
, "status:\t\t%s\n", enabled(status
, 0));
3480 if (hotkey_all_mask
) {
3481 seq_printf(m
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3482 seq_printf(m
, "commands:\tenable, disable, reset, <mask>\n");
3484 seq_printf(m
, "mask:\t\tnot supported\n");
3485 seq_printf(m
, "commands:\tenable, disable, reset\n");
3491 static void hotkey_enabledisable_warn(bool enable
)
3493 tpacpi_log_usertask("procfs hotkey enable/disable");
3494 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3496 "hotkey enable/disable functionality has been "
3497 "removed from the driver. Hotkeys are always "
3500 "Please remove the hotkey=enable module "
3501 "parameter, it is deprecated. Hotkeys are always "
3505 static int hotkey_write(char *buf
)
3511 if (!tp_features
.hotkey
)
3514 if (mutex_lock_killable(&hotkey_mutex
))
3515 return -ERESTARTSYS
;
3517 mask
= hotkey_user_mask
;
3520 while ((cmd
= next_cmd(&buf
))) {
3521 if (strlencmp(cmd
, "enable") == 0) {
3522 hotkey_enabledisable_warn(1);
3523 } else if (strlencmp(cmd
, "disable") == 0) {
3524 hotkey_enabledisable_warn(0);
3526 } else if (strlencmp(cmd
, "reset") == 0) {
3527 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3528 & ~hotkey_reserved_mask
;
3529 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3531 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3540 tpacpi_disclose_usertask("procfs hotkey",
3541 "set mask to 0x%08x\n", mask
);
3542 res
= hotkey_user_mask_set(mask
);
3546 mutex_unlock(&hotkey_mutex
);
3550 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3551 {TPACPI_ACPI_HKEY_HID
, 0},
3555 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3556 .hid
= ibm_htk_device_ids
,
3557 .notify
= hotkey_notify
,
3558 .handle
= &hkey_handle
,
3559 .type
= ACPI_DEVICE_NOTIFY
,
3562 static struct ibm_struct hotkey_driver_data
= {
3564 .read
= hotkey_read
,
3565 .write
= hotkey_write
,
3566 .exit
= hotkey_exit
,
3567 .resume
= hotkey_resume
,
3568 .suspend
= hotkey_suspend
,
3569 .acpi
= &ibm_hotkey_acpidriver
,
3572 /*************************************************************************
3573 * Bluetooth subdriver
3577 /* ACPI GBDC/SBDC bits */
3578 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3579 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3580 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3585 /* ACPI \BLTH commands */
3586 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3587 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3588 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3589 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3590 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3593 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3595 static struct rfkill
*tpacpi_bluetooth_rfkill
;
3597 static void bluetooth_suspend(pm_message_t state
)
3599 /* Try to make sure radio will resume powered off */
3600 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3601 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
))
3602 vdbg_printk(TPACPI_DBG_RFKILL
,
3603 "bluetooth power down on resume request failed\n");
3606 static int bluetooth_get_radiosw(void)
3610 if (!tp_features
.bluetooth
)
3613 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
3614 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3615 return RFKILL_STATE_HARD_BLOCKED
;
3617 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3618 if (dbg_bluetoothemul
)
3619 return (tpacpi_bluetooth_emulstate
) ?
3620 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3623 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3626 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3627 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3630 static void bluetooth_update_rfk(void)
3634 if (!tpacpi_bluetooth_rfkill
)
3637 status
= bluetooth_get_radiosw();
3640 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
3642 vdbg_printk(TPACPI_DBG_RFKILL
,
3643 "forced rfkill state to %d\n",
3647 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
3651 if (!tp_features
.bluetooth
)
3654 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3655 * reason to risk weird behaviour. */
3656 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3660 vdbg_printk(TPACPI_DBG_RFKILL
,
3661 "will %s bluetooth\n", radio_on
? "enable" : "disable");
3663 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3664 if (dbg_bluetoothemul
) {
3665 tpacpi_bluetooth_emulstate
= !!radio_on
;
3667 bluetooth_update_rfk();
3672 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3674 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
3677 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3681 bluetooth_update_rfk();
3686 /* sysfs bluetooth enable ---------------------------------------------- */
3687 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3688 struct device_attribute
*attr
,
3693 printk_deprecated_rfkill_attribute("bluetooth_enable");
3695 status
= bluetooth_get_radiosw();
3699 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3700 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3703 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3704 struct device_attribute
*attr
,
3705 const char *buf
, size_t count
)
3710 printk_deprecated_rfkill_attribute("bluetooth_enable");
3712 if (parse_strtoul(buf
, 1, &t
))
3715 tpacpi_disclose_usertask("bluetooth_enable", "set to %ld\n", t
);
3717 res
= bluetooth_set_radiosw(t
, 1);
3719 return (res
) ? res
: count
;
3722 static struct device_attribute dev_attr_bluetooth_enable
=
3723 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3724 bluetooth_enable_show
, bluetooth_enable_store
);
3726 /* --------------------------------------------------------------------- */
3728 static struct attribute
*bluetooth_attributes
[] = {
3729 &dev_attr_bluetooth_enable
.attr
,
3733 static const struct attribute_group bluetooth_attr_group
= {
3734 .attrs
= bluetooth_attributes
,
3737 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
3739 int bts
= bluetooth_get_radiosw();
3748 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
3750 dbg_printk(TPACPI_DBG_RFKILL
,
3751 "request to change radio state to %d\n", state
);
3752 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3755 static void bluetooth_shutdown(void)
3757 /* Order firmware to save current state to NVRAM */
3758 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3759 TP_ACPI_BLTH_SAVE_STATE
))
3760 printk(TPACPI_NOTICE
3761 "failed to save bluetooth state to NVRAM\n");
3763 vdbg_printk(TPACPI_DBG_RFKILL
,
3764 "bluestooth state saved to NVRAM\n");
3767 static void bluetooth_exit(void)
3769 bluetooth_shutdown();
3771 if (tpacpi_bluetooth_rfkill
)
3772 rfkill_unregister(tpacpi_bluetooth_rfkill
);
3774 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3775 &bluetooth_attr_group
);
3778 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3783 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3784 "initializing bluetooth subdriver\n");
3786 TPACPI_ACPIHANDLE_INIT(hkey
);
3788 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3789 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3790 tp_features
.bluetooth
= hkey_handle
&&
3791 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3793 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3794 "bluetooth is %s, status 0x%02x\n",
3795 str_supported(tp_features
.bluetooth
),
3798 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3799 if (dbg_bluetoothemul
) {
3800 tp_features
.bluetooth
= 1;
3802 "bluetooth switch emulation enabled\n");
3805 if (tp_features
.bluetooth
&&
3806 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
3807 /* no bluetooth hardware present in system */
3808 tp_features
.bluetooth
= 0;
3809 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3810 "bluetooth hardware not installed\n");
3813 if (!tp_features
.bluetooth
)
3816 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3817 &bluetooth_attr_group
);
3821 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3822 &tpacpi_bluetooth_rfkill
,
3823 RFKILL_TYPE_BLUETOOTH
,
3824 TPACPI_RFK_BLUETOOTH_SW_NAME
,
3826 tpacpi_bluetooth_rfk_set
,
3827 tpacpi_bluetooth_rfk_get
);
3836 /* procfs -------------------------------------------------------------- */
3837 static int bluetooth_read(struct seq_file
*m
)
3839 int status
= bluetooth_get_radiosw();
3841 if (!tp_features
.bluetooth
)
3842 seq_printf(m
, "status:\t\tnot supported\n");
3844 seq_printf(m
, "status:\t\t%s\n",
3845 (status
== RFKILL_STATE_UNBLOCKED
) ?
3846 "enabled" : "disabled");
3847 seq_printf(m
, "commands:\tenable, disable\n");
3853 static int bluetooth_write(char *buf
)
3858 if (!tp_features
.bluetooth
)
3861 while ((cmd
= next_cmd(&buf
))) {
3862 if (strlencmp(cmd
, "enable") == 0) {
3864 } else if (strlencmp(cmd
, "disable") == 0) {
3871 tpacpi_disclose_usertask("procfs bluetooth",
3873 state
? "enable" : "disable");
3874 bluetooth_set_radiosw(state
, 1);
3880 static struct ibm_struct bluetooth_driver_data
= {
3881 .name
= "bluetooth",
3882 .read
= bluetooth_read
,
3883 .write
= bluetooth_write
,
3884 .exit
= bluetooth_exit
,
3885 .suspend
= bluetooth_suspend
,
3886 .shutdown
= bluetooth_shutdown
,
3889 /*************************************************************************
3894 /* ACPI GWAN/SWAN bits */
3895 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3896 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3897 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3901 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
3903 static struct rfkill
*tpacpi_wan_rfkill
;
3905 static void wan_suspend(pm_message_t state
)
3907 /* Try to make sure radio will resume powered off */
3908 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3909 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
))
3910 vdbg_printk(TPACPI_DBG_RFKILL
,
3911 "WWAN power down on resume request failed\n");
3914 static int wan_get_radiosw(void)
3918 if (!tp_features
.wan
)
3921 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3922 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3923 return RFKILL_STATE_HARD_BLOCKED
;
3925 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3927 return (tpacpi_wwan_emulstate
) ?
3928 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3931 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3934 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3935 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3938 static void wan_update_rfk(void)
3942 if (!tpacpi_wan_rfkill
)
3945 status
= wan_get_radiosw();
3948 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3950 vdbg_printk(TPACPI_DBG_RFKILL
,
3951 "forced rfkill state to %d\n",
3955 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3959 if (!tp_features
.wan
)
3962 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3963 * reason to risk weird behaviour. */
3964 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3968 vdbg_printk(TPACPI_DBG_RFKILL
,
3969 "will %s WWAN\n", radio_on
? "enable" : "disable");
3971 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3973 tpacpi_wwan_emulstate
= !!radio_on
;
3980 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3982 status
= TP_ACPI_WANCARD_RADIOSSW
;
3985 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3994 /* sysfs wan enable ---------------------------------------------------- */
3995 static ssize_t
wan_enable_show(struct device
*dev
,
3996 struct device_attribute
*attr
,
4001 printk_deprecated_rfkill_attribute("wwan_enable");
4003 status
= wan_get_radiosw();
4007 return snprintf(buf
, PAGE_SIZE
, "%d\n",
4008 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
4011 static ssize_t
wan_enable_store(struct device
*dev
,
4012 struct device_attribute
*attr
,
4013 const char *buf
, size_t count
)
4018 printk_deprecated_rfkill_attribute("wwan_enable");
4020 if (parse_strtoul(buf
, 1, &t
))
4023 tpacpi_disclose_usertask("wwan_enable", "set to %ld\n", t
);
4025 res
= wan_set_radiosw(t
, 1);
4027 return (res
) ? res
: count
;
4030 static struct device_attribute dev_attr_wan_enable
=
4031 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4032 wan_enable_show
, wan_enable_store
);
4034 /* --------------------------------------------------------------------- */
4036 static struct attribute
*wan_attributes
[] = {
4037 &dev_attr_wan_enable
.attr
,
4041 static const struct attribute_group wan_attr_group
= {
4042 .attrs
= wan_attributes
,
4045 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
4047 int wans
= wan_get_radiosw();
4056 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
4058 dbg_printk(TPACPI_DBG_RFKILL
,
4059 "request to change radio state to %d\n", state
);
4060 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
4063 static void wan_shutdown(void)
4065 /* Order firmware to save current state to NVRAM */
4066 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4067 TP_ACPI_WGSV_SAVE_STATE
))
4068 printk(TPACPI_NOTICE
4069 "failed to save WWAN state to NVRAM\n");
4071 vdbg_printk(TPACPI_DBG_RFKILL
,
4072 "WWAN state saved to NVRAM\n");
4075 static void wan_exit(void)
4079 if (tpacpi_wan_rfkill
)
4080 rfkill_unregister(tpacpi_wan_rfkill
);
4082 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4086 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4091 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4092 "initializing wan subdriver\n");
4094 TPACPI_ACPIHANDLE_INIT(hkey
);
4096 tp_features
.wan
= hkey_handle
&&
4097 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4099 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4100 "wan is %s, status 0x%02x\n",
4101 str_supported(tp_features
.wan
),
4104 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4106 tp_features
.wan
= 1;
4108 "wwan switch emulation enabled\n");
4111 if (tp_features
.wan
&&
4112 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4113 /* no wan hardware present in system */
4114 tp_features
.wan
= 0;
4115 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4116 "wan hardware not installed\n");
4119 if (!tp_features
.wan
)
4122 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4127 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4130 TPACPI_RFK_WWAN_SW_NAME
,
4133 tpacpi_wan_rfk_get
);
4142 /* procfs -------------------------------------------------------------- */
4143 static int wan_read(struct seq_file
*m
)
4145 int status
= wan_get_radiosw();
4147 tpacpi_disclose_usertask("procfs wan", "read");
4149 if (!tp_features
.wan
)
4150 seq_printf(m
, "status:\t\tnot supported\n");
4152 seq_printf(m
, "status:\t\t%s\n",
4153 (status
== RFKILL_STATE_UNBLOCKED
) ?
4154 "enabled" : "disabled");
4155 seq_printf(m
, "commands:\tenable, disable\n");
4161 static int wan_write(char *buf
)
4166 if (!tp_features
.wan
)
4169 while ((cmd
= next_cmd(&buf
))) {
4170 if (strlencmp(cmd
, "enable") == 0) {
4172 } else if (strlencmp(cmd
, "disable") == 0) {
4179 tpacpi_disclose_usertask("procfs wan",
4181 state
? "enable" : "disable");
4182 wan_set_radiosw(state
, 1);
4188 static struct ibm_struct wan_driver_data
= {
4193 .suspend
= wan_suspend
,
4194 .shutdown
= wan_shutdown
,
4197 /*************************************************************************
4202 /* ACPI GUWB/SUWB bits */
4203 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4204 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4207 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4209 static struct rfkill
*tpacpi_uwb_rfkill
;
4211 static int uwb_get_radiosw(void)
4215 if (!tp_features
.uwb
)
4218 /* WLSW overrides UWB in firmware/hardware, reflect that */
4219 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
4220 return RFKILL_STATE_HARD_BLOCKED
;
4222 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4224 return (tpacpi_uwb_emulstate
) ?
4225 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
4228 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4231 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4232 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
4235 static void uwb_update_rfk(void)
4239 if (!tpacpi_uwb_rfkill
)
4242 status
= uwb_get_radiosw();
4245 rfkill_force_state(tpacpi_uwb_rfkill
, status
);
4247 vdbg_printk(TPACPI_DBG_RFKILL
,
4248 "forced rfkill state to %d\n",
4252 static int uwb_set_radiosw(int radio_on
, int update_rfk
)
4256 if (!tp_features
.uwb
)
4259 /* WLSW overrides UWB in firmware/hardware, but there is no
4260 * reason to risk weird behaviour. */
4261 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
4265 vdbg_printk(TPACPI_DBG_RFKILL
,
4266 "will %s UWB\n", radio_on
? "enable" : "disable");
4268 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4270 tpacpi_uwb_emulstate
= !!radio_on
;
4277 status
= (radio_on
) ? TP_ACPI_UWB_RADIOSSW
: 0;
4278 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4287 /* --------------------------------------------------------------------- */
4289 static int tpacpi_uwb_rfk_get(void *data
, enum rfkill_state
*state
)
4291 int uwbs
= uwb_get_radiosw();
4300 static int tpacpi_uwb_rfk_set(void *data
, enum rfkill_state state
)
4302 dbg_printk(TPACPI_DBG_RFKILL
,
4303 "request to change radio state to %d\n", state
);
4304 return uwb_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
4307 static void uwb_exit(void)
4309 if (tpacpi_uwb_rfkill
)
4310 rfkill_unregister(tpacpi_uwb_rfkill
);
4313 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4318 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4319 "initializing uwb subdriver\n");
4321 TPACPI_ACPIHANDLE_INIT(hkey
);
4323 tp_features
.uwb
= hkey_handle
&&
4324 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4326 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4327 "uwb is %s, status 0x%02x\n",
4328 str_supported(tp_features
.uwb
),
4331 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4333 tp_features
.uwb
= 1;
4335 "uwb switch emulation enabled\n");
4338 if (tp_features
.uwb
&&
4339 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4340 /* no uwb hardware present in system */
4341 tp_features
.uwb
= 0;
4342 dbg_printk(TPACPI_DBG_INIT
,
4343 "uwb hardware not installed\n");
4346 if (!tp_features
.uwb
)
4349 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4352 TPACPI_RFK_UWB_SW_NAME
,
4355 tpacpi_uwb_rfk_get
);
4360 static struct ibm_struct uwb_driver_data
= {
4363 .flags
.experimental
= 1,
4366 /*************************************************************************
4370 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4372 enum video_access_mode
{
4373 TPACPI_VIDEO_NONE
= 0,
4374 TPACPI_VIDEO_570
, /* 570 */
4375 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4376 TPACPI_VIDEO_NEW
, /* all others */
4379 enum { /* video status flags, based on VIDEO_570 */
4380 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4381 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4382 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4385 enum { /* TPACPI_VIDEO_570 constants */
4386 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4387 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4388 * video_status_flags */
4389 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4390 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4393 static enum video_access_mode video_supported
;
4394 static int video_orig_autosw
;
4396 static int video_autosw_get(void);
4397 static int video_autosw_set(int enable
);
4399 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4401 static int __init
video_init(struct ibm_init_struct
*iibm
)
4405 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4407 TPACPI_ACPIHANDLE_INIT(vid
);
4408 TPACPI_ACPIHANDLE_INIT(vid2
);
4410 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4411 /* G41, assume IVGA doesn't change */
4412 vid_handle
= vid2_handle
;
4415 /* video switching not supported on R30, R31 */
4416 video_supported
= TPACPI_VIDEO_NONE
;
4417 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4419 video_supported
= TPACPI_VIDEO_570
;
4420 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4421 /* 600e/x, 770e, 770x */
4422 video_supported
= TPACPI_VIDEO_770
;
4425 video_supported
= TPACPI_VIDEO_NEW
;
4427 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4428 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4431 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4434 static void video_exit(void)
4436 dbg_printk(TPACPI_DBG_EXIT
,
4437 "restoring original video autoswitch mode\n");
4438 if (video_autosw_set(video_orig_autosw
))
4439 printk(TPACPI_ERR
"error while trying to restore original "
4440 "video autoswitch mode\n");
4443 static int video_outputsw_get(void)
4448 switch (video_supported
) {
4449 case TPACPI_VIDEO_570
:
4450 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4451 TP_ACPI_VIDEO_570_PHSCMD
))
4453 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4455 case TPACPI_VIDEO_770
:
4456 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4459 status
|= TP_ACPI_VIDEO_S_LCD
;
4460 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4463 status
|= TP_ACPI_VIDEO_S_CRT
;
4465 case TPACPI_VIDEO_NEW
:
4466 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4467 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4470 status
|= TP_ACPI_VIDEO_S_CRT
;
4472 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4473 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4476 status
|= TP_ACPI_VIDEO_S_LCD
;
4477 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4480 status
|= TP_ACPI_VIDEO_S_DVI
;
4489 static int video_outputsw_set(int status
)
4494 switch (video_supported
) {
4495 case TPACPI_VIDEO_570
:
4496 res
= acpi_evalf(NULL
, NULL
,
4497 "\\_SB.PHS2", "vdd",
4498 TP_ACPI_VIDEO_570_PHS2CMD
,
4499 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4501 case TPACPI_VIDEO_770
:
4502 autosw
= video_autosw_get();
4506 res
= video_autosw_set(1);
4509 res
= acpi_evalf(vid_handle
, NULL
,
4510 "ASWT", "vdd", status
* 0x100, 0);
4511 if (!autosw
&& video_autosw_set(autosw
)) {
4513 "video auto-switch left enabled due to error\n");
4517 case TPACPI_VIDEO_NEW
:
4518 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4519 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4525 return (res
)? 0 : -EIO
;
4528 static int video_autosw_get(void)
4532 switch (video_supported
) {
4533 case TPACPI_VIDEO_570
:
4534 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4537 case TPACPI_VIDEO_770
:
4538 case TPACPI_VIDEO_NEW
:
4539 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4549 static int video_autosw_set(int enable
)
4551 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4556 static int video_outputsw_cycle(void)
4558 int autosw
= video_autosw_get();
4564 switch (video_supported
) {
4565 case TPACPI_VIDEO_570
:
4566 res
= video_autosw_set(1);
4569 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4571 case TPACPI_VIDEO_770
:
4572 case TPACPI_VIDEO_NEW
:
4573 res
= video_autosw_set(1);
4576 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4581 if (!autosw
&& video_autosw_set(autosw
)) {
4583 "video auto-switch left enabled due to error\n");
4587 return (res
)? 0 : -EIO
;
4590 static int video_expand_toggle(void)
4592 switch (video_supported
) {
4593 case TPACPI_VIDEO_570
:
4594 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4596 case TPACPI_VIDEO_770
:
4597 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4599 case TPACPI_VIDEO_NEW
:
4600 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4608 static int video_read(struct seq_file
*m
)
4612 if (video_supported
== TPACPI_VIDEO_NONE
) {
4613 seq_printf(m
, "status:\t\tnot supported\n");
4617 status
= video_outputsw_get();
4621 autosw
= video_autosw_get();
4625 seq_printf(m
, "status:\t\tsupported\n");
4626 seq_printf(m
, "lcd:\t\t%s\n", enabled(status
, 0));
4627 seq_printf(m
, "crt:\t\t%s\n", enabled(status
, 1));
4628 if (video_supported
== TPACPI_VIDEO_NEW
)
4629 seq_printf(m
, "dvi:\t\t%s\n", enabled(status
, 3));
4630 seq_printf(m
, "auto:\t\t%s\n", enabled(autosw
, 0));
4631 seq_printf(m
, "commands:\tlcd_enable, lcd_disable\n");
4632 seq_printf(m
, "commands:\tcrt_enable, crt_disable\n");
4633 if (video_supported
== TPACPI_VIDEO_NEW
)
4634 seq_printf(m
, "commands:\tdvi_enable, dvi_disable\n");
4635 seq_printf(m
, "commands:\tauto_enable, auto_disable\n");
4636 seq_printf(m
, "commands:\tvideo_switch, expand_toggle\n");
4641 static int video_write(char *buf
)
4644 int enable
, disable
, status
;
4647 if (video_supported
== TPACPI_VIDEO_NONE
)
4653 while ((cmd
= next_cmd(&buf
))) {
4654 if (strlencmp(cmd
, "lcd_enable") == 0) {
4655 enable
|= TP_ACPI_VIDEO_S_LCD
;
4656 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4657 disable
|= TP_ACPI_VIDEO_S_LCD
;
4658 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4659 enable
|= TP_ACPI_VIDEO_S_CRT
;
4660 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4661 disable
|= TP_ACPI_VIDEO_S_CRT
;
4662 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4663 strlencmp(cmd
, "dvi_enable") == 0) {
4664 enable
|= TP_ACPI_VIDEO_S_DVI
;
4665 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4666 strlencmp(cmd
, "dvi_disable") == 0) {
4667 disable
|= TP_ACPI_VIDEO_S_DVI
;
4668 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4669 res
= video_autosw_set(1);
4672 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4673 res
= video_autosw_set(0);
4676 } else if (strlencmp(cmd
, "video_switch") == 0) {
4677 res
= video_outputsw_cycle();
4680 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4681 res
= video_expand_toggle();
4688 if (enable
|| disable
) {
4689 status
= video_outputsw_get();
4692 res
= video_outputsw_set((status
& ~disable
) | enable
);
4700 static struct ibm_struct video_driver_data
= {
4703 .write
= video_write
,
4707 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4709 /*************************************************************************
4710 * Light (thinklight) subdriver
4713 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4714 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4716 static int light_get_status(void)
4720 if (tp_features
.light_status
) {
4721 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4729 static int light_set_status(int status
)
4733 if (tp_features
.light
) {
4735 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4737 TP_CMOS_THINKLIGHT_ON
:
4738 TP_CMOS_THINKLIGHT_OFF
);
4740 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4743 return (rc
)? 0 : -EIO
;
4749 static void light_set_status_worker(struct work_struct
*work
)
4751 struct tpacpi_led_classdev
*data
=
4752 container_of(work
, struct tpacpi_led_classdev
, work
);
4754 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4755 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4758 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4759 enum led_brightness brightness
)
4761 struct tpacpi_led_classdev
*data
=
4762 container_of(led_cdev
,
4763 struct tpacpi_led_classdev
,
4765 data
->new_state
= (brightness
!= LED_OFF
) ?
4766 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4767 queue_work(tpacpi_wq
, &data
->work
);
4770 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4772 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4775 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4777 .name
= "tpacpi::thinklight",
4778 .brightness_set
= &light_sysfs_set
,
4779 .brightness_get
= &light_sysfs_get
,
4783 static int __init
light_init(struct ibm_init_struct
*iibm
)
4787 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4789 TPACPI_ACPIHANDLE_INIT(ledb
);
4790 TPACPI_ACPIHANDLE_INIT(lght
);
4791 TPACPI_ACPIHANDLE_INIT(cmos
);
4792 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4794 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4795 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4797 if (tp_features
.light
)
4798 /* light status not supported on
4799 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4800 tp_features
.light_status
=
4801 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4803 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4804 str_supported(tp_features
.light
),
4805 str_supported(tp_features
.light_status
));
4807 if (!tp_features
.light
)
4810 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4811 &tpacpi_led_thinklight
.led_classdev
);
4814 tp_features
.light
= 0;
4815 tp_features
.light_status
= 0;
4823 static void light_exit(void)
4825 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4826 if (work_pending(&tpacpi_led_thinklight
.work
))
4827 flush_workqueue(tpacpi_wq
);
4830 static int light_read(struct seq_file
*m
)
4834 if (!tp_features
.light
) {
4835 seq_printf(m
, "status:\t\tnot supported\n");
4836 } else if (!tp_features
.light_status
) {
4837 seq_printf(m
, "status:\t\tunknown\n");
4838 seq_printf(m
, "commands:\ton, off\n");
4840 status
= light_get_status();
4843 seq_printf(m
, "status:\t\t%s\n", onoff(status
, 0));
4844 seq_printf(m
, "commands:\ton, off\n");
4850 static int light_write(char *buf
)
4855 if (!tp_features
.light
)
4858 while ((cmd
= next_cmd(&buf
))) {
4859 if (strlencmp(cmd
, "on") == 0) {
4861 } else if (strlencmp(cmd
, "off") == 0) {
4867 return light_set_status(newstatus
);
4870 static struct ibm_struct light_driver_data
= {
4873 .write
= light_write
,
4877 /*************************************************************************
4881 /* sysfs cmos_command -------------------------------------------------- */
4882 static ssize_t
cmos_command_store(struct device
*dev
,
4883 struct device_attribute
*attr
,
4884 const char *buf
, size_t count
)
4886 unsigned long cmos_cmd
;
4889 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4892 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4893 return (res
)? res
: count
;
4896 static struct device_attribute dev_attr_cmos_command
=
4897 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4899 /* --------------------------------------------------------------------- */
4901 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4905 vdbg_printk(TPACPI_DBG_INIT
,
4906 "initializing cmos commands subdriver\n");
4908 TPACPI_ACPIHANDLE_INIT(cmos
);
4910 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4911 str_supported(cmos_handle
!= NULL
));
4913 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4917 return (cmos_handle
)? 0 : 1;
4920 static void cmos_exit(void)
4922 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4925 static int cmos_read(struct seq_file
*m
)
4927 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4928 R30, R31, T20-22, X20-21 */
4930 seq_printf(m
, "status:\t\tnot supported\n");
4932 seq_printf(m
, "status:\t\tsupported\n");
4933 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4939 static int cmos_write(char *buf
)
4944 while ((cmd
= next_cmd(&buf
))) {
4945 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4946 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4951 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4959 static struct ibm_struct cmos_driver_data
= {
4962 .write
= cmos_write
,
4966 /*************************************************************************
4970 enum led_access_mode
{
4971 TPACPI_LED_NONE
= 0,
4972 TPACPI_LED_570
, /* 570 */
4973 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4974 TPACPI_LED_NEW
, /* all others */
4977 enum { /* For TPACPI_LED_OLD */
4978 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4979 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4980 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4983 static enum led_access_mode led_supported
;
4985 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4986 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4987 /* T20-22, X20-21 */
4988 "LED", /* all others */
4991 #define TPACPI_LED_NUMLEDS 16
4992 static struct tpacpi_led_classdev
*tpacpi_leds
;
4993 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4994 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4995 /* there's a limit of 19 chars + NULL before 2.6.26 */
4997 "tpacpi:orange:batt",
4998 "tpacpi:green:batt",
4999 "tpacpi::dock_active",
5000 "tpacpi::bay_active",
5001 "tpacpi::dock_batt",
5002 "tpacpi::unknown_led",
5004 "tpacpi::dock_status1",
5005 "tpacpi::dock_status2",
5006 "tpacpi::unknown_led2",
5007 "tpacpi::unknown_led3",
5008 "tpacpi::thinkvantage",
5010 #define TPACPI_SAFE_LEDS 0x1081U
5012 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
5014 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5017 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
5021 static int led_get_status(const unsigned int led
)
5024 enum led_status_t led_s
;
5026 switch (led_supported
) {
5027 case TPACPI_LED_570
:
5028 if (!acpi_evalf(ec_handle
,
5029 &status
, "GLED", "dd", 1 << led
))
5031 led_s
= (status
== 0)?
5036 tpacpi_led_state_cache
[led
] = led_s
;
5045 static int led_set_status(const unsigned int led
,
5046 const enum led_status_t ledstatus
)
5048 /* off, on, blink. Index is led_status_t */
5049 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
5050 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
5054 switch (led_supported
) {
5055 case TPACPI_LED_570
:
5057 if (unlikely(led
> 7))
5059 if (unlikely(tpacpi_is_led_restricted(led
)))
5061 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5062 (1 << led
), led_sled_arg1
[ledstatus
]))
5065 case TPACPI_LED_OLD
:
5066 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
5067 if (unlikely(led
> 7))
5069 if (unlikely(tpacpi_is_led_restricted(led
)))
5071 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
5073 rc
= ec_write(TPACPI_LED_EC_HLBL
,
5074 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5076 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5077 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5079 case TPACPI_LED_NEW
:
5081 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5083 if (unlikely(tpacpi_is_led_restricted(led
)))
5085 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5086 led
, led_led_arg1
[ledstatus
]))
5094 tpacpi_led_state_cache
[led
] = ledstatus
;
5099 static void led_set_status_worker(struct work_struct
*work
)
5101 struct tpacpi_led_classdev
*data
=
5102 container_of(work
, struct tpacpi_led_classdev
, work
);
5104 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5105 led_set_status(data
->led
, data
->new_state
);
5108 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5109 enum led_brightness brightness
)
5111 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5112 struct tpacpi_led_classdev
, led_classdev
);
5114 if (brightness
== LED_OFF
)
5115 data
->new_state
= TPACPI_LED_OFF
;
5116 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5117 data
->new_state
= TPACPI_LED_ON
;
5119 data
->new_state
= TPACPI_LED_BLINK
;
5121 queue_work(tpacpi_wq
, &data
->work
);
5124 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5125 unsigned long *delay_on
, unsigned long *delay_off
)
5127 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5128 struct tpacpi_led_classdev
, led_classdev
);
5130 /* Can we choose the flash rate? */
5131 if (*delay_on
== 0 && *delay_off
== 0) {
5132 /* yes. set them to the hardware blink rate (1 Hz) */
5133 *delay_on
= 500; /* ms */
5134 *delay_off
= 500; /* ms */
5135 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5138 data
->new_state
= TPACPI_LED_BLINK
;
5139 queue_work(tpacpi_wq
, &data
->work
);
5144 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5148 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5149 struct tpacpi_led_classdev
, led_classdev
);
5151 rc
= led_get_status(data
->led
);
5153 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5154 rc
= LED_OFF
; /* no error handling in led class :( */
5161 static void led_exit(void)
5165 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5166 if (tpacpi_leds
[i
].led_classdev
.name
)
5167 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5173 static int __init
tpacpi_init_led(unsigned int led
)
5177 tpacpi_leds
[led
].led
= led
;
5179 /* LEDs with no name don't get registered */
5180 if (!tpacpi_led_names
[led
])
5183 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5184 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5185 if (led_supported
== TPACPI_LED_570
)
5186 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5189 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5191 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5193 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5194 &tpacpi_leds
[led
].led_classdev
);
5196 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5201 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5202 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5203 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5204 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5206 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5207 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5208 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5209 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5210 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5211 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5212 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5213 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5215 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5216 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5217 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5218 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5219 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5221 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5222 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5223 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5224 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5226 /* (1) - may have excess leds enabled on MSB */
5228 /* Defaults (order matters, keep last, don't reorder!) */
5230 .vendor
= PCI_VENDOR_ID_LENOVO
,
5231 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5234 { /* IBM ThinkPads with no EC version string */
5235 .vendor
= PCI_VENDOR_ID_IBM
,
5236 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5239 { /* IBM ThinkPads with EC version string */
5240 .vendor
= PCI_VENDOR_ID_IBM
,
5241 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5246 #undef TPACPI_LEDQ_IBM
5247 #undef TPACPI_LEDQ_LNV
5249 static int __init
led_init(struct ibm_init_struct
*iibm
)
5253 unsigned long useful_leds
;
5255 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5257 TPACPI_ACPIHANDLE_INIT(led
);
5260 /* led not supported on R30, R31 */
5261 led_supported
= TPACPI_LED_NONE
;
5262 else if (strlencmp(led_path
, "SLED") == 0)
5264 led_supported
= TPACPI_LED_570
;
5265 else if (strlencmp(led_path
, "SYSL") == 0)
5266 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5267 led_supported
= TPACPI_LED_OLD
;
5270 led_supported
= TPACPI_LED_NEW
;
5272 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5273 str_supported(led_supported
), led_supported
);
5275 if (led_supported
== TPACPI_LED_NONE
)
5278 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5281 printk(TPACPI_ERR
"Out of memory for LED data\n");
5285 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5286 ARRAY_SIZE(led_useful_qtable
));
5288 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5289 if (!tpacpi_is_led_restricted(i
) &&
5290 test_bit(i
, &useful_leds
)) {
5291 rc
= tpacpi_init_led(i
);
5299 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5300 printk(TPACPI_NOTICE
5301 "warning: userspace override of important "
5302 "firmware LEDs is enabled\n");
5307 #define str_led_status(s) \
5308 ((s) == TPACPI_LED_OFF ? "off" : \
5309 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5311 static int led_read(struct seq_file
*m
)
5313 if (!led_supported
) {
5314 seq_printf(m
, "status:\t\tnot supported\n");
5317 seq_printf(m
, "status:\t\tsupported\n");
5319 if (led_supported
== TPACPI_LED_570
) {
5322 for (i
= 0; i
< 8; i
++) {
5323 status
= led_get_status(i
);
5326 seq_printf(m
, "%d:\t\t%s\n",
5327 i
, str_led_status(status
));
5331 seq_printf(m
, "commands:\t"
5332 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5337 static int led_write(char *buf
)
5341 enum led_status_t s
;
5346 while ((cmd
= next_cmd(&buf
))) {
5347 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5350 if (strstr(cmd
, "off")) {
5352 } else if (strstr(cmd
, "on")) {
5354 } else if (strstr(cmd
, "blink")) {
5355 s
= TPACPI_LED_BLINK
;
5360 rc
= led_set_status(led
, s
);
5368 static struct ibm_struct led_driver_data
= {
5375 /*************************************************************************
5379 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5381 #define TPACPI_BEEP_Q1 0x0001
5383 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5384 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5385 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5388 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5390 unsigned long quirks
;
5392 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5394 TPACPI_ACPIHANDLE_INIT(beep
);
5396 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5397 str_supported(beep_handle
!= NULL
));
5399 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5400 ARRAY_SIZE(beep_quirk_table
));
5402 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5404 return (beep_handle
)? 0 : 1;
5407 static int beep_read(struct seq_file
*m
)
5410 seq_printf(m
, "status:\t\tnot supported\n");
5412 seq_printf(m
, "status:\t\tsupported\n");
5413 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5419 static int beep_write(char *buf
)
5427 while ((cmd
= next_cmd(&buf
))) {
5428 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5429 beep_cmd
>= 0 && beep_cmd
<= 17) {
5433 if (tp_features
.beep_needs_two_args
) {
5434 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5438 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5447 static struct ibm_struct beep_driver_data
= {
5450 .write
= beep_write
,
5453 /*************************************************************************
5457 enum thermal_access_mode
{
5458 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5459 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5460 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5461 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5462 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5465 enum { /* TPACPI_THERMAL_TPEC_* */
5466 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5467 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5468 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5470 TPACPI_THERMAL_SENSOR_NA
= -128000, /* Sensor not available */
5474 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5475 struct ibm_thermal_sensors_struct
{
5476 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5479 static enum thermal_access_mode thermal_read_mode
;
5481 /* idx is zero-based */
5482 static int thermal_get_sensor(int idx
, s32
*value
)
5488 t
= TP_EC_THERMAL_TMP0
;
5490 switch (thermal_read_mode
) {
5491 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5492 case TPACPI_THERMAL_TPEC_16
:
5493 if (idx
>= 8 && idx
<= 15) {
5494 t
= TP_EC_THERMAL_TMP8
;
5499 case TPACPI_THERMAL_TPEC_8
:
5501 if (!acpi_ec_read(t
+ idx
, &tmp
))
5503 *value
= tmp
* 1000;
5508 case TPACPI_THERMAL_ACPI_UPDT
:
5510 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5511 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5513 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5515 *value
= (t
- 2732) * 100;
5520 case TPACPI_THERMAL_ACPI_TMP07
:
5522 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5523 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5525 if (t
> 127 || t
< -127)
5526 t
= TP_EC_THERMAL_TMP_NA
;
5532 case TPACPI_THERMAL_NONE
:
5540 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5551 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5554 for (i
= 0 ; i
< n
; i
++) {
5555 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5563 static void thermal_dump_all_sensors(void)
5566 struct ibm_thermal_sensors_struct t
;
5568 n
= thermal_get_sensors(&t
);
5572 printk(TPACPI_NOTICE
5573 "temperatures (Celsius):");
5575 for (i
= 0; i
< n
; i
++) {
5576 if (t
.temp
[i
] != TPACPI_THERMAL_SENSOR_NA
)
5577 printk(KERN_CONT
" %d", (int)(t
.temp
[i
] / 1000));
5579 printk(KERN_CONT
" N/A");
5582 printk(KERN_CONT
"\n");
5585 /* sysfs temp##_input -------------------------------------------------- */
5587 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5588 struct device_attribute
*attr
,
5591 struct sensor_device_attribute
*sensor_attr
=
5592 to_sensor_dev_attr(attr
);
5593 int idx
= sensor_attr
->index
;
5597 res
= thermal_get_sensor(idx
, &value
);
5600 if (value
== TPACPI_THERMAL_SENSOR_NA
)
5603 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5606 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5607 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5608 thermal_temp_input_show, NULL, _idxB)
5610 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5611 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5612 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5613 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5614 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5615 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5616 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5617 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5618 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5619 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5620 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5621 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5622 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5623 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5624 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5625 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5626 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5629 #define THERMAL_ATTRS(X) \
5630 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5632 static struct attribute
*thermal_temp_input_attr
[] = {
5652 static const struct attribute_group thermal_temp_input16_group
= {
5653 .attrs
= thermal_temp_input_attr
5656 static const struct attribute_group thermal_temp_input8_group
= {
5657 .attrs
= &thermal_temp_input_attr
[8]
5660 #undef THERMAL_SENSOR_ATTR_TEMP
5661 #undef THERMAL_ATTRS
5663 /* --------------------------------------------------------------------- */
5665 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5672 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5674 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5676 if (thinkpad_id
.ec_model
) {
5678 * Direct EC access mode: sensors at registers
5679 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5680 * non-implemented, thermal sensors return 0x80 when
5685 for (i
= 0; i
< 8; i
++) {
5686 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5692 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5700 /* This is sheer paranoia, but we handle it anyway */
5703 "ThinkPad ACPI EC access misbehaving, "
5704 "falling back to ACPI TMPx access "
5706 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5709 "ThinkPad ACPI EC access misbehaving, "
5710 "disabling thermal sensors access\n");
5711 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5716 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5718 } else if (acpi_tmp7
) {
5719 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5720 /* 600e/x, 770e, 770x */
5721 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5723 /* Standard ACPI TMPx access, max 8 sensors */
5724 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5727 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5728 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5731 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5732 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5735 switch (thermal_read_mode
) {
5736 case TPACPI_THERMAL_TPEC_16
:
5737 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5738 &thermal_temp_input16_group
);
5742 case TPACPI_THERMAL_TPEC_8
:
5743 case TPACPI_THERMAL_ACPI_TMP07
:
5744 case TPACPI_THERMAL_ACPI_UPDT
:
5745 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5746 &thermal_temp_input8_group
);
5750 case TPACPI_THERMAL_NONE
:
5758 static void thermal_exit(void)
5760 switch (thermal_read_mode
) {
5761 case TPACPI_THERMAL_TPEC_16
:
5762 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5763 &thermal_temp_input16_group
);
5765 case TPACPI_THERMAL_TPEC_8
:
5766 case TPACPI_THERMAL_ACPI_TMP07
:
5767 case TPACPI_THERMAL_ACPI_UPDT
:
5768 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5769 &thermal_temp_input16_group
);
5771 case TPACPI_THERMAL_NONE
:
5777 static int thermal_read(struct seq_file
*m
)
5780 struct ibm_thermal_sensors_struct t
;
5782 n
= thermal_get_sensors(&t
);
5783 if (unlikely(n
< 0))
5786 seq_printf(m
, "temperatures:\t");
5789 for (i
= 0; i
< (n
- 1); i
++)
5790 seq_printf(m
, "%d ", t
.temp
[i
] / 1000);
5791 seq_printf(m
, "%d\n", t
.temp
[i
] / 1000);
5793 seq_printf(m
, "not supported\n");
5798 static struct ibm_struct thermal_driver_data
= {
5800 .read
= thermal_read
,
5801 .exit
= thermal_exit
,
5804 /*************************************************************************
5808 static u8 ecdump_regs
[256];
5810 static int ecdump_read(struct seq_file
*m
)
5816 " +00 +01 +02 +03 +04 +05 +06 +07"
5817 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5818 for (i
= 0; i
< 256; i
+= 16) {
5819 seq_printf(m
, "EC 0x%02x:", i
);
5820 for (j
= 0; j
< 16; j
++) {
5821 if (!acpi_ec_read(i
+ j
, &v
))
5823 if (v
!= ecdump_regs
[i
+ j
])
5824 seq_printf(m
, " *%02x", v
);
5826 seq_printf(m
, " %02x", v
);
5827 ecdump_regs
[i
+ j
] = v
;
5834 /* These are way too dangerous to advertise openly... */
5836 seq_printf(m
, "commands:\t0x<offset> 0x<value>"
5837 " (<offset> is 00-ff, <value> is 00-ff)\n");
5838 seq_printf(m
, "commands:\t0x<offset> <value> "
5839 " (<offset> is 00-ff, <value> is 0-255)\n");
5844 static int ecdump_write(char *buf
)
5849 while ((cmd
= next_cmd(&buf
))) {
5850 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5852 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5856 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5857 if (!acpi_ec_write(i
, v
))
5866 static struct ibm_struct ecdump_driver_data
= {
5868 .read
= ecdump_read
,
5869 .write
= ecdump_write
,
5870 .flags
.experimental
= 1,
5873 /*************************************************************************
5874 * Backlight/brightness subdriver
5877 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5880 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5881 * CMOS NVRAM byte 0x5E, bits 0-3.
5883 * EC HBRV (0x31) has the following layout
5884 * Bit 7: unknown function
5885 * Bit 6: unknown function
5886 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5887 * Bit 4: must be set to zero to avoid problems
5888 * Bit 3-0: backlight brightness level
5890 * brightness_get_raw returns status data in the HBRV layout
5892 * WARNING: The X61 has been verified to use HBRV for something else, so
5893 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5894 * testing on the very early *60 Lenovo models...
5898 TP_EC_BACKLIGHT
= 0x31,
5900 /* TP_EC_BACKLIGHT bitmasks */
5901 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5902 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5903 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5906 enum tpacpi_brightness_access_mode
{
5907 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5908 TPACPI_BRGHT_MODE_EC
, /* EC control */
5909 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5910 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5911 TPACPI_BRGHT_MODE_MAX
5914 static struct backlight_device
*ibm_backlight_device
;
5916 static enum tpacpi_brightness_access_mode brightness_mode
=
5917 TPACPI_BRGHT_MODE_MAX
;
5919 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5921 static struct mutex brightness_mutex
;
5923 /* NVRAM brightness access,
5924 * call with brightness_mutex held! */
5925 static unsigned int tpacpi_brightness_nvram_get(void)
5929 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5930 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5931 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5932 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5937 static void tpacpi_brightness_checkpoint_nvram(void)
5942 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5945 vdbg_printk(TPACPI_DBG_BRGHT
,
5946 "trying to checkpoint backlight level to NVRAM...\n");
5948 if (mutex_lock_killable(&brightness_mutex
) < 0)
5951 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5953 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5954 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5956 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5957 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5958 /* NVRAM needs update */
5959 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5960 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5962 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5963 dbg_printk(TPACPI_DBG_BRGHT
,
5964 "updated NVRAM backlight level to %u (0x%02x)\n",
5965 (unsigned int) lec
, (unsigned int) b_nvram
);
5967 vdbg_printk(TPACPI_DBG_BRGHT
,
5968 "NVRAM backlight level already is %u (0x%02x)\n",
5969 (unsigned int) lec
, (unsigned int) b_nvram
);
5972 mutex_unlock(&brightness_mutex
);
5976 /* call with brightness_mutex held! */
5977 static int tpacpi_brightness_get_raw(int *status
)
5981 switch (brightness_mode
) {
5982 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5983 *status
= tpacpi_brightness_nvram_get();
5985 case TPACPI_BRGHT_MODE_EC
:
5986 case TPACPI_BRGHT_MODE_ECNVRAM
:
5987 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5996 /* call with brightness_mutex held! */
5997 /* do NOT call with illegal backlight level value */
5998 static int tpacpi_brightness_set_ec(unsigned int value
)
6002 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6005 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
6006 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
6007 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
6013 /* call with brightness_mutex held! */
6014 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
6017 unsigned int current_value
, i
;
6019 current_value
= tpacpi_brightness_nvram_get();
6021 if (value
== current_value
)
6024 cmos_cmd
= (value
> current_value
) ?
6025 TP_CMOS_BRIGHTNESS_UP
:
6026 TP_CMOS_BRIGHTNESS_DOWN
;
6027 inc
= (value
> current_value
) ? 1 : -1;
6029 for (i
= current_value
; i
!= value
; i
+= inc
)
6030 if (issue_thinkpad_cmos_command(cmos_cmd
))
6036 /* May return EINTR which can always be mapped to ERESTARTSYS */
6037 static int brightness_set(unsigned int value
)
6041 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
6045 vdbg_printk(TPACPI_DBG_BRGHT
,
6046 "set backlight level to %d\n", value
);
6048 res
= mutex_lock_killable(&brightness_mutex
);
6052 switch (brightness_mode
) {
6053 case TPACPI_BRGHT_MODE_EC
:
6054 case TPACPI_BRGHT_MODE_ECNVRAM
:
6055 res
= tpacpi_brightness_set_ec(value
);
6057 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6058 res
= tpacpi_brightness_set_ucmsstep(value
);
6064 mutex_unlock(&brightness_mutex
);
6068 /* sysfs backlight class ----------------------------------------------- */
6070 static int brightness_update_status(struct backlight_device
*bd
)
6072 unsigned int level
=
6073 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
6074 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
6075 bd
->props
.brightness
: 0;
6077 dbg_printk(TPACPI_DBG_BRGHT
,
6078 "backlight: attempt to set level to %d\n",
6081 /* it is the backlight class's job (caller) to handle
6082 * EINTR and other errors properly */
6083 return brightness_set(level
);
6086 static int brightness_get(struct backlight_device
*bd
)
6090 res
= mutex_lock_killable(&brightness_mutex
);
6094 res
= tpacpi_brightness_get_raw(&status
);
6096 mutex_unlock(&brightness_mutex
);
6101 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6104 static void tpacpi_brightness_notify_change(void)
6106 backlight_force_update(ibm_backlight_device
,
6107 BACKLIGHT_UPDATE_HOTKEY
);
6110 static struct backlight_ops ibm_backlight_data
= {
6111 .get_brightness
= brightness_get
,
6112 .update_status
= brightness_update_status
,
6115 /* --------------------------------------------------------------------- */
6118 * These are only useful for models that have only one possibility
6119 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6122 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6123 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6124 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6126 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6127 /* Models with ATI GPUs known to require ECNVRAM mode */
6128 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6130 /* Models with ATI GPUs that can use ECNVRAM */
6131 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
),
6132 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6133 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6134 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6136 /* Models with Intel Extreme Graphics 2 */
6137 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
),
6138 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6139 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6141 /* Models with Intel GMA900 */
6142 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6143 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6144 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6147 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6150 unsigned long quirks
;
6152 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6154 mutex_init(&brightness_mutex
);
6156 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6157 ARRAY_SIZE(brightness_quirk_table
));
6160 * We always attempt to detect acpi support, so as to switch
6161 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6162 * going to publish a backlight interface
6164 b
= tpacpi_check_std_acpi_brightness_support();
6167 if (acpi_video_backlight_support()) {
6168 if (brightness_enable
> 1) {
6169 printk(TPACPI_NOTICE
6170 "Standard ACPI backlight interface "
6171 "available, not loading native one.\n");
6173 } else if (brightness_enable
== 1) {
6174 printk(TPACPI_NOTICE
6175 "Backlight control force enabled, even if standard "
6176 "ACPI backlight interface is available\n");
6179 if (brightness_enable
> 1) {
6180 printk(TPACPI_NOTICE
6181 "Standard ACPI backlight interface not "
6182 "available, thinkpad_acpi native "
6183 "brightness control enabled\n");
6188 if (!brightness_enable
) {
6189 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6190 "brightness support disabled by "
6191 "module parameter\n");
6197 "Unsupported brightness interface, "
6198 "please contact %s\n", TPACPI_MAIL
);
6202 tp_features
.bright_16levels
= 1;
6205 * Check for module parameter bogosity, note that we
6206 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6207 * able to detect "unspecified"
6209 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6212 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6213 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6214 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6215 if (quirks
& TPACPI_BRGHT_Q_EC
)
6216 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6218 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6220 dbg_printk(TPACPI_DBG_BRGHT
,
6221 "driver auto-selected brightness_mode=%d\n",
6226 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6227 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6228 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6231 if (tpacpi_brightness_get_raw(&b
) < 0)
6234 if (tp_features
.bright_16levels
)
6236 "detected a 16-level brightness capable ThinkPad\n");
6238 ibm_backlight_device
= backlight_device_register(
6239 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6240 &ibm_backlight_data
);
6241 if (IS_ERR(ibm_backlight_device
)) {
6242 int rc
= PTR_ERR(ibm_backlight_device
);
6243 ibm_backlight_device
= NULL
;
6244 printk(TPACPI_ERR
"Could not register backlight device\n");
6247 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6248 "brightness is supported\n");
6250 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6251 printk(TPACPI_NOTICE
6252 "brightness: will use unverified default: "
6253 "brightness_mode=%d\n", brightness_mode
);
6254 printk(TPACPI_NOTICE
6255 "brightness: please report to %s whether it works well "
6256 "or not on your ThinkPad\n", TPACPI_MAIL
);
6259 ibm_backlight_device
->props
.max_brightness
=
6260 (tp_features
.bright_16levels
)? 15 : 7;
6261 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6262 backlight_update_status(ibm_backlight_device
);
6264 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6265 "brightness: registering brightness hotkeys "
6266 "as change notification\n");
6267 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6268 | TP_ACPI_HKEY_BRGHTUP_MASK
6269 | TP_ACPI_HKEY_BRGHTDWN_MASK
);;
6273 static void brightness_suspend(pm_message_t state
)
6275 tpacpi_brightness_checkpoint_nvram();
6278 static void brightness_shutdown(void)
6280 tpacpi_brightness_checkpoint_nvram();
6283 static void brightness_exit(void)
6285 if (ibm_backlight_device
) {
6286 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6287 "calling backlight_device_unregister()\n");
6288 backlight_device_unregister(ibm_backlight_device
);
6291 tpacpi_brightness_checkpoint_nvram();
6294 static int brightness_read(struct seq_file
*m
)
6298 level
= brightness_get(NULL
);
6300 seq_printf(m
, "level:\t\tunreadable\n");
6302 seq_printf(m
, "level:\t\t%d\n", level
);
6303 seq_printf(m
, "commands:\tup, down\n");
6304 seq_printf(m
, "commands:\tlevel <level>"
6305 " (<level> is 0-%d)\n",
6306 (tp_features
.bright_16levels
) ? 15 : 7);
6312 static int brightness_write(char *buf
)
6317 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6319 level
= brightness_get(NULL
);
6323 while ((cmd
= next_cmd(&buf
))) {
6324 if (strlencmp(cmd
, "up") == 0) {
6325 if (level
< max_level
)
6327 } else if (strlencmp(cmd
, "down") == 0) {
6330 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6331 level
>= 0 && level
<= max_level
) {
6337 tpacpi_disclose_usertask("procfs brightness",
6338 "set level to %d\n", level
);
6341 * Now we know what the final level should be, so we try to set it.
6342 * Doing it this way makes the syscall restartable in case of EINTR
6344 rc
= brightness_set(level
);
6345 if (!rc
&& ibm_backlight_device
)
6346 backlight_force_update(ibm_backlight_device
,
6347 BACKLIGHT_UPDATE_SYSFS
);
6348 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6351 static struct ibm_struct brightness_driver_data
= {
6352 .name
= "brightness",
6353 .read
= brightness_read
,
6354 .write
= brightness_write
,
6355 .exit
= brightness_exit
,
6356 .suspend
= brightness_suspend
,
6357 .shutdown
= brightness_shutdown
,
6360 /*************************************************************************
6365 * IBM ThinkPads have a simple volume controller with MUTE gating.
6366 * Very early Lenovo ThinkPads follow the IBM ThinkPad spec.
6368 * Since the *61 series (and probably also the later *60 series), Lenovo
6369 * ThinkPads only implement the MUTE gate.
6372 * Bit 6: MUTE (1 mutes sound)
6374 * Other bits should be zero as far as we know.
6376 * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and
6377 * bits 3-0 (volume). Other bits in NVRAM may have other functions,
6378 * such as bit 7 which is used to detect repeated presses of MUTE,
6379 * and we leave them unchanged.
6382 #define TPACPI_ALSA_DRVNAME "ThinkPad EC"
6383 #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control"
6384 #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME
6386 static int alsa_index
= SNDRV_DEFAULT_IDX1
;
6387 static char *alsa_id
= "ThinkPadEC";
6388 static int alsa_enable
= SNDRV_DEFAULT_ENABLE1
;
6390 struct tpacpi_alsa_data
{
6391 struct snd_card
*card
;
6392 struct snd_ctl_elem_id
*ctl_mute_id
;
6393 struct snd_ctl_elem_id
*ctl_vol_id
;
6396 static struct snd_card
*alsa_card
;
6401 /* TP_EC_AUDIO bits */
6402 TP_EC_AUDIO_MUTESW
= 6,
6404 /* TP_EC_AUDIO bitmasks */
6405 TP_EC_AUDIO_LVL_MSK
= 0x0F,
6406 TP_EC_AUDIO_MUTESW_MSK
= (1 << TP_EC_AUDIO_MUTESW
),
6408 /* Maximum volume */
6409 TP_EC_VOLUME_MAX
= 14,
6412 enum tpacpi_volume_access_mode
{
6413 TPACPI_VOL_MODE_AUTO
= 0, /* Not implemented yet */
6414 TPACPI_VOL_MODE_EC
, /* Pure EC control */
6415 TPACPI_VOL_MODE_UCMS_STEP
, /* UCMS step-based control: N/A */
6416 TPACPI_VOL_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
6420 enum tpacpi_volume_capabilities
{
6421 TPACPI_VOL_CAP_AUTO
= 0, /* Use white/blacklist */
6422 TPACPI_VOL_CAP_VOLMUTE
, /* Output vol and mute */
6423 TPACPI_VOL_CAP_MUTEONLY
, /* Output mute only */
6427 static enum tpacpi_volume_access_mode volume_mode
=
6428 TPACPI_VOL_MODE_MAX
;
6430 static enum tpacpi_volume_capabilities volume_capabilities
;
6431 static int volume_control_allowed
;
6434 * Used to syncronize writers to TP_EC_AUDIO and
6435 * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write
6437 static struct mutex volume_mutex
;
6439 static void tpacpi_volume_checkpoint_nvram(void)
6445 if (volume_mode
!= TPACPI_VOL_MODE_ECNVRAM
)
6447 if (!volume_control_allowed
)
6450 vdbg_printk(TPACPI_DBG_MIXER
,
6451 "trying to checkpoint mixer state to NVRAM...\n");
6453 if (tp_features
.mixer_no_level_control
)
6454 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
;
6456 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
| TP_EC_AUDIO_LVL_MSK
;
6458 if (mutex_lock_killable(&volume_mutex
) < 0)
6461 if (unlikely(!acpi_ec_read(TP_EC_AUDIO
, &lec
)))
6464 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
6466 if (lec
!= (b_nvram
& ec_mask
)) {
6467 /* NVRAM needs update */
6468 b_nvram
&= ~ec_mask
;
6470 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_MIXER
);
6471 dbg_printk(TPACPI_DBG_MIXER
,
6472 "updated NVRAM mixer status to 0x%02x (0x%02x)\n",
6473 (unsigned int) lec
, (unsigned int) b_nvram
);
6475 vdbg_printk(TPACPI_DBG_MIXER
,
6476 "NVRAM mixer status already is 0x%02x (0x%02x)\n",
6477 (unsigned int) lec
, (unsigned int) b_nvram
);
6481 mutex_unlock(&volume_mutex
);
6484 static int volume_get_status_ec(u8
*status
)
6488 if (!acpi_ec_read(TP_EC_AUDIO
, &s
))
6493 dbg_printk(TPACPI_DBG_MIXER
, "status 0x%02x\n", s
);
6498 static int volume_get_status(u8
*status
)
6500 return volume_get_status_ec(status
);
6503 static int volume_set_status_ec(const u8 status
)
6505 if (!acpi_ec_write(TP_EC_AUDIO
, status
))
6508 dbg_printk(TPACPI_DBG_MIXER
, "set EC mixer to 0x%02x\n", status
);
6513 static int volume_set_status(const u8 status
)
6515 return volume_set_status_ec(status
);
6518 static int volume_set_mute_ec(const bool mute
)
6523 if (mutex_lock_killable(&volume_mutex
) < 0)
6526 rc
= volume_get_status_ec(&s
);
6530 n
= (mute
) ? s
| TP_EC_AUDIO_MUTESW_MSK
:
6531 s
& ~TP_EC_AUDIO_MUTESW_MSK
;
6534 rc
= volume_set_status_ec(n
);
6537 mutex_unlock(&volume_mutex
);
6541 static int volume_set_mute(const bool mute
)
6543 dbg_printk(TPACPI_DBG_MIXER
, "trying to %smute\n",
6544 (mute
) ? "" : "un");
6545 return volume_set_mute_ec(mute
);
6548 static int volume_set_volume_ec(const u8 vol
)
6553 if (vol
> TP_EC_VOLUME_MAX
)
6556 if (mutex_lock_killable(&volume_mutex
) < 0)
6559 rc
= volume_get_status_ec(&s
);
6563 n
= (s
& ~TP_EC_AUDIO_LVL_MSK
) | vol
;
6566 rc
= volume_set_status_ec(n
);
6569 mutex_unlock(&volume_mutex
);
6573 static int volume_set_volume(const u8 vol
)
6575 dbg_printk(TPACPI_DBG_MIXER
,
6576 "trying to set volume level to %hu\n", vol
);
6577 return volume_set_volume_ec(vol
);
6580 static void volume_alsa_notify_change(void)
6582 struct tpacpi_alsa_data
*d
;
6584 if (alsa_card
&& alsa_card
->private_data
) {
6585 d
= alsa_card
->private_data
;
6587 snd_ctl_notify(alsa_card
,
6588 SNDRV_CTL_EVENT_MASK_VALUE
,
6591 snd_ctl_notify(alsa_card
,
6592 SNDRV_CTL_EVENT_MASK_VALUE
,
6597 static int volume_alsa_vol_info(struct snd_kcontrol
*kcontrol
,
6598 struct snd_ctl_elem_info
*uinfo
)
6600 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
6602 uinfo
->value
.integer
.min
= 0;
6603 uinfo
->value
.integer
.max
= TP_EC_VOLUME_MAX
;
6607 static int volume_alsa_vol_get(struct snd_kcontrol
*kcontrol
,
6608 struct snd_ctl_elem_value
*ucontrol
)
6613 rc
= volume_get_status(&s
);
6617 ucontrol
->value
.integer
.value
[0] = s
& TP_EC_AUDIO_LVL_MSK
;
6621 static int volume_alsa_vol_put(struct snd_kcontrol
*kcontrol
,
6622 struct snd_ctl_elem_value
*ucontrol
)
6624 return volume_set_volume(ucontrol
->value
.integer
.value
[0]);
6627 #define volume_alsa_mute_info snd_ctl_boolean_mono_info
6629 static int volume_alsa_mute_get(struct snd_kcontrol
*kcontrol
,
6630 struct snd_ctl_elem_value
*ucontrol
)
6635 rc
= volume_get_status(&s
);
6639 ucontrol
->value
.integer
.value
[0] =
6640 (s
& TP_EC_AUDIO_MUTESW_MSK
) ? 0 : 1;
6644 static int volume_alsa_mute_put(struct snd_kcontrol
*kcontrol
,
6645 struct snd_ctl_elem_value
*ucontrol
)
6647 return volume_set_mute(!ucontrol
->value
.integer
.value
[0]);
6650 static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata
= {
6651 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6652 .name
= "Console Playback Volume",
6654 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6655 .info
= volume_alsa_vol_info
,
6656 .get
= volume_alsa_vol_get
,
6659 static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata
= {
6660 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6661 .name
= "Console Playback Switch",
6663 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6664 .info
= volume_alsa_mute_info
,
6665 .get
= volume_alsa_mute_get
,
6668 static void volume_suspend(pm_message_t state
)
6670 tpacpi_volume_checkpoint_nvram();
6673 static void volume_resume(void)
6675 volume_alsa_notify_change();
6678 static void volume_shutdown(void)
6680 tpacpi_volume_checkpoint_nvram();
6683 static void volume_exit(void)
6686 snd_card_free(alsa_card
);
6690 tpacpi_volume_checkpoint_nvram();
6693 static int __init
volume_create_alsa_mixer(void)
6695 struct snd_card
*card
;
6696 struct tpacpi_alsa_data
*data
;
6697 struct snd_kcontrol
*ctl_vol
;
6698 struct snd_kcontrol
*ctl_mute
;
6701 card
= snd_card_new(alsa_index
, alsa_id
, THIS_MODULE
,
6702 sizeof(struct tpacpi_alsa_data
));
6706 BUG_ON(!card
->private_data
);
6707 data
= card
->private_data
;
6710 strlcpy(card
->driver
, TPACPI_ALSA_DRVNAME
,
6711 sizeof(card
->driver
));
6712 strlcpy(card
->shortname
, TPACPI_ALSA_SHRTNAME
,
6713 sizeof(card
->shortname
));
6714 snprintf(card
->mixername
, sizeof(card
->mixername
), "ThinkPad EC %s",
6715 (thinkpad_id
.ec_version_str
) ?
6716 thinkpad_id
.ec_version_str
: "(unknown)");
6717 snprintf(card
->longname
, sizeof(card
->longname
),
6718 "%s at EC reg 0x%02x, fw %s", card
->shortname
, TP_EC_AUDIO
,
6719 (thinkpad_id
.ec_version_str
) ?
6720 thinkpad_id
.ec_version_str
: "unknown");
6722 if (volume_control_allowed
) {
6723 volume_alsa_control_vol
.put
= volume_alsa_vol_put
;
6724 volume_alsa_control_vol
.access
=
6725 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6727 volume_alsa_control_mute
.put
= volume_alsa_mute_put
;
6728 volume_alsa_control_mute
.access
=
6729 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6732 if (!tp_features
.mixer_no_level_control
) {
6733 ctl_vol
= snd_ctl_new1(&volume_alsa_control_vol
, NULL
);
6734 rc
= snd_ctl_add(card
, ctl_vol
);
6737 "Failed to create ALSA volume control\n");
6740 data
->ctl_vol_id
= &ctl_vol
->id
;
6743 ctl_mute
= snd_ctl_new1(&volume_alsa_control_mute
, NULL
);
6744 rc
= snd_ctl_add(card
, ctl_mute
);
6746 printk(TPACPI_ERR
"Failed to create ALSA mute control\n");
6749 data
->ctl_mute_id
= &ctl_mute
->id
;
6751 snd_card_set_dev(card
, &tpacpi_pdev
->dev
);
6752 rc
= snd_card_register(card
);
6756 snd_card_free(card
);
6764 #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */
6765 #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */
6767 static const struct tpacpi_quirk volume_quirk_table
[] __initconst
= {
6768 /* Whitelist volume level on all IBM by default */
6769 { .vendor
= PCI_VENDOR_ID_IBM
,
6770 .bios
= TPACPI_MATCH_ANY
,
6771 .ec
= TPACPI_MATCH_ANY
,
6772 .quirks
= TPACPI_VOL_Q_LEVEL
},
6774 /* Lenovo models with volume control (needs confirmation) */
6775 TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL
), /* R60/i */
6776 TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL
), /* R60e/i */
6777 TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL
), /* T60/p */
6778 TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL
), /* X60/s */
6779 TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL
), /* X60t */
6780 TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL
), /* Z60 */
6781 TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL
), /* Z61 */
6783 /* Whitelist mute-only on all Lenovo by default */
6784 { .vendor
= PCI_VENDOR_ID_LENOVO
,
6785 .bios
= TPACPI_MATCH_ANY
,
6786 .ec
= TPACPI_MATCH_ANY
,
6787 .quirks
= TPACPI_VOL_Q_MUTEONLY
}
6790 static int __init
volume_init(struct ibm_init_struct
*iibm
)
6792 unsigned long quirks
;
6795 vdbg_printk(TPACPI_DBG_INIT
, "initializing volume subdriver\n");
6797 mutex_init(&volume_mutex
);
6800 * Check for module parameter bogosity, note that we
6801 * init volume_mode to TPACPI_VOL_MODE_MAX in order to be
6802 * able to detect "unspecified"
6804 if (volume_mode
> TPACPI_VOL_MODE_MAX
)
6807 if (volume_mode
== TPACPI_VOL_MODE_UCMS_STEP
) {
6809 "UCMS step volume mode not implemented, "
6810 "please contact %s\n", TPACPI_MAIL
);
6814 if (volume_capabilities
>= TPACPI_VOL_CAP_MAX
)
6818 * The ALSA mixer is our primary interface.
6819 * When disabled, don't install the subdriver at all
6822 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6823 "ALSA mixer disabled by parameter, "
6824 "not loading volume subdriver...\n");
6828 quirks
= tpacpi_check_quirks(volume_quirk_table
,
6829 ARRAY_SIZE(volume_quirk_table
));
6831 switch (volume_capabilities
) {
6832 case TPACPI_VOL_CAP_AUTO
:
6833 if (quirks
& TPACPI_VOL_Q_MUTEONLY
)
6834 tp_features
.mixer_no_level_control
= 1;
6835 else if (quirks
& TPACPI_VOL_Q_LEVEL
)
6836 tp_features
.mixer_no_level_control
= 0;
6838 return 1; /* no mixer */
6840 case TPACPI_VOL_CAP_VOLMUTE
:
6841 tp_features
.mixer_no_level_control
= 0;
6843 case TPACPI_VOL_CAP_MUTEONLY
:
6844 tp_features
.mixer_no_level_control
= 1;
6850 if (volume_capabilities
!= TPACPI_VOL_CAP_AUTO
)
6851 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6852 "using user-supplied volume_capabilities=%d\n",
6853 volume_capabilities
);
6855 if (volume_mode
== TPACPI_VOL_MODE_AUTO
||
6856 volume_mode
== TPACPI_VOL_MODE_MAX
) {
6857 volume_mode
= TPACPI_VOL_MODE_ECNVRAM
;
6859 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6860 "driver auto-selected volume_mode=%d\n",
6863 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6864 "using user-supplied volume_mode=%d\n",
6868 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6869 "mute is supported, volume control is %s\n",
6870 str_supported(!tp_features
.mixer_no_level_control
));
6872 rc
= volume_create_alsa_mixer();
6875 "Could not create the ALSA mixer interface\n");
6880 "Console audio control enabled, mode: %s\n",
6881 (volume_control_allowed
) ?
6882 "override (read/write)" :
6883 "monitor (read only)");
6885 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6886 "registering volume hotkeys as change notification\n");
6887 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6888 | TP_ACPI_HKEY_VOLUP_MASK
6889 | TP_ACPI_HKEY_VOLDWN_MASK
6890 | TP_ACPI_HKEY_MUTE_MASK
);
6895 static int volume_read(struct seq_file
*m
)
6899 if (volume_get_status(&status
) < 0) {
6900 seq_printf(m
, "level:\t\tunreadable\n");
6902 if (tp_features
.mixer_no_level_control
)
6903 seq_printf(m
, "level:\t\tunsupported\n");
6905 seq_printf(m
, "level:\t\t%d\n",
6906 status
& TP_EC_AUDIO_LVL_MSK
);
6908 seq_printf(m
, "mute:\t\t%s\n",
6909 onoff(status
, TP_EC_AUDIO_MUTESW
));
6911 if (volume_control_allowed
) {
6912 seq_printf(m
, "commands:\tunmute, mute\n");
6913 if (!tp_features
.mixer_no_level_control
) {
6915 "commands:\tup, down\n");
6917 "commands:\tlevel <level>"
6918 " (<level> is 0-%d)\n",
6927 static int volume_write(char *buf
)
6930 u8 new_level
, new_mute
;
6936 * We do allow volume control at driver startup, so that the
6937 * user can set initial state through the volume=... parameter hack.
6939 if (!volume_control_allowed
&& tpacpi_lifecycle
!= TPACPI_LIFE_INIT
) {
6940 if (unlikely(!tp_warned
.volume_ctrl_forbidden
)) {
6941 tp_warned
.volume_ctrl_forbidden
= 1;
6942 printk(TPACPI_NOTICE
6943 "Console audio control in monitor mode, "
6944 "changes are not allowed.\n");
6945 printk(TPACPI_NOTICE
6946 "Use the volume_control=1 module parameter "
6947 "to enable volume control\n");
6952 rc
= volume_get_status(&s
);
6956 new_level
= s
& TP_EC_AUDIO_LVL_MSK
;
6957 new_mute
= s
& TP_EC_AUDIO_MUTESW_MSK
;
6959 while ((cmd
= next_cmd(&buf
))) {
6960 if (!tp_features
.mixer_no_level_control
) {
6961 if (strlencmp(cmd
, "up") == 0) {
6964 else if (new_level
< TP_EC_VOLUME_MAX
)
6967 } else if (strlencmp(cmd
, "down") == 0) {
6970 else if (new_level
> 0)
6973 } else if (sscanf(cmd
, "level %u", &l
) == 1 &&
6974 l
>= 0 && l
<= TP_EC_VOLUME_MAX
) {
6979 if (strlencmp(cmd
, "mute") == 0)
6980 new_mute
= TP_EC_AUDIO_MUTESW_MSK
;
6981 else if (strlencmp(cmd
, "unmute") == 0)
6987 if (tp_features
.mixer_no_level_control
) {
6988 tpacpi_disclose_usertask("procfs volume", "%smute\n",
6989 new_mute
? "" : "un");
6990 rc
= volume_set_mute(!!new_mute
);
6992 tpacpi_disclose_usertask("procfs volume",
6993 "%smute and set level to %d\n",
6994 new_mute
? "" : "un", new_level
);
6995 rc
= volume_set_status(new_mute
| new_level
);
6997 volume_alsa_notify_change();
6999 return (rc
== -EINTR
) ? -ERESTARTSYS
: rc
;
7002 static struct ibm_struct volume_driver_data
= {
7004 .read
= volume_read
,
7005 .write
= volume_write
,
7006 .exit
= volume_exit
,
7007 .suspend
= volume_suspend
,
7008 .resume
= volume_resume
,
7009 .shutdown
= volume_shutdown
,
7012 /*************************************************************************
7019 * TPACPI_FAN_RD_ACPI_GFAN:
7020 * ACPI GFAN method: returns fan level
7022 * see TPACPI_FAN_WR_ACPI_SFAN
7023 * EC 0x2f (HFSP) not available if GFAN exists
7025 * TPACPI_FAN_WR_ACPI_SFAN:
7026 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
7028 * EC 0x2f (HFSP) might be available *for reading*, but do not use
7031 * TPACPI_FAN_WR_TPEC:
7032 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
7033 * Supported on almost all ThinkPads
7035 * Fan speed changes of any sort (including those caused by the
7036 * disengaged mode) are usually done slowly by the firmware as the
7037 * maximum ammount of fan duty cycle change per second seems to be
7040 * Reading is not available if GFAN exists.
7041 * Writing is not available if SFAN exists.
7044 * 7 automatic mode engaged;
7045 * (default operation mode of the ThinkPad)
7046 * fan level is ignored in this mode.
7047 * 6 full speed mode (takes precedence over bit 7);
7048 * not available on all thinkpads. May disable
7049 * the tachometer while the fan controller ramps up
7050 * the speed (which can take up to a few *minutes*).
7051 * Speeds up fan to 100% duty-cycle, which is far above
7052 * the standard RPM levels. It is not impossible that
7053 * it could cause hardware damage.
7054 * 5-3 unused in some models. Extra bits for fan level
7055 * in others, but still useless as all values above
7056 * 7 map to the same speed as level 7 in these models.
7057 * 2-0 fan level (0..7 usually)
7059 * 0x07 = max (set when temperatures critical)
7060 * Some ThinkPads may have other levels, see
7061 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
7063 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
7064 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
7065 * does so, its initial value is meaningless (0x07).
7067 * For firmware bugs, refer to:
7068 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7072 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
7073 * Main fan tachometer reading (in RPM)
7075 * This register is present on all ThinkPads with a new-style EC, and
7076 * it is known not to be present on the A21m/e, and T22, as there is
7077 * something else in offset 0x84 according to the ACPI DSDT. Other
7078 * ThinkPads from this same time period (and earlier) probably lack the
7079 * tachometer as well.
7081 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
7082 * was never fixed by IBM to report the EC firmware version string
7083 * probably support the tachometer (like the early X models), so
7084 * detecting it is quite hard. We need more data to know for sure.
7086 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
7089 * FIRMWARE BUG: may go stale while the EC is switching to full speed
7092 * For firmware bugs, refer to:
7093 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7097 * ThinkPad EC register 0x31 bit 0 (only on select models)
7099 * When bit 0 of EC register 0x31 is zero, the tachometer registers
7100 * show the speed of the main fan. When bit 0 of EC register 0x31
7101 * is one, the tachometer registers show the speed of the auxiliary
7104 * Fan control seems to affect both fans, regardless of the state
7107 * So far, only the firmware for the X60/X61 non-tablet versions
7108 * seem to support this (firmware TP-7M).
7110 * TPACPI_FAN_WR_ACPI_FANS:
7111 * ThinkPad X31, X40, X41. Not available in the X60.
7113 * FANS ACPI handle: takes three arguments: low speed, medium speed,
7114 * high speed. ACPI DSDT seems to map these three speeds to levels
7115 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
7116 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
7118 * The speeds are stored on handles
7119 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
7121 * There are three default speed sets, acessible as handles:
7122 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
7124 * ACPI DSDT switches which set is in use depending on various
7127 * TPACPI_FAN_WR_TPEC is also available and should be used to
7128 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
7129 * but the ACPI tables just mention level 7.
7132 enum { /* Fan control constants */
7133 fan_status_offset
= 0x2f, /* EC register 0x2f */
7134 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
7135 * 0x84 must be read before 0x85 */
7136 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
7137 bit 0 selects which fan is active */
7139 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
7140 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
7142 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
7145 enum fan_status_access_mode
{
7146 TPACPI_FAN_NONE
= 0, /* No fan status or control */
7147 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
7148 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
7151 enum fan_control_access_mode
{
7152 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
7153 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
7154 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
7155 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
7158 enum fan_control_commands
{
7159 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
7160 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
7161 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
7162 * and also watchdog cmd */
7165 static int fan_control_allowed
;
7167 static enum fan_status_access_mode fan_status_access_mode
;
7168 static enum fan_control_access_mode fan_control_access_mode
;
7169 static enum fan_control_commands fan_control_commands
;
7171 static u8 fan_control_initial_status
;
7172 static u8 fan_control_desired_level
;
7173 static u8 fan_control_resume_level
;
7174 static int fan_watchdog_maxinterval
;
7176 static struct mutex fan_mutex
;
7178 static void fan_watchdog_fire(struct work_struct
*ignored
);
7179 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
7181 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
7182 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
7183 "\\FSPD", /* 600e/x, 770e, 770x */
7185 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
7186 "JFNS", /* 770x-JL */
7190 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
7191 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
7192 * be in auto mode (0x80).
7194 * This is corrected by any write to HFSP either by the driver, or
7197 * We assume 0x07 really means auto mode while this quirk is active,
7198 * as this is far more likely than the ThinkPad being in level 7,
7199 * which is only used by the firmware during thermal emergencies.
7201 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
7202 * TP-70 (T43, R52), which are known to be buggy.
7205 static void fan_quirk1_setup(void)
7207 if (fan_control_initial_status
== 0x07) {
7208 printk(TPACPI_NOTICE
7209 "fan_init: initial fan status is unknown, "
7210 "assuming it is in auto mode\n");
7211 tp_features
.fan_ctrl_status_undef
= 1;
7215 static void fan_quirk1_handle(u8
*fan_status
)
7217 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
7218 if (*fan_status
!= fan_control_initial_status
) {
7219 /* something changed the HFSP regisnter since
7220 * driver init time, so it is not undefined
7222 tp_features
.fan_ctrl_status_undef
= 0;
7224 /* Return most likely status. In fact, it
7225 * might be the only possible status */
7226 *fan_status
= TP_EC_FAN_AUTO
;
7231 /* Select main fan on X60/X61, NOOP on others */
7232 static bool fan_select_fan1(void)
7234 if (tp_features
.second_fan
) {
7237 if (ec_read(fan_select_offset
, &val
) < 0)
7240 if (ec_write(fan_select_offset
, val
) < 0)
7246 /* Select secondary fan on X60/X61 */
7247 static bool fan_select_fan2(void)
7251 if (!tp_features
.second_fan
)
7254 if (ec_read(fan_select_offset
, &val
) < 0)
7257 if (ec_write(fan_select_offset
, val
) < 0)
7264 * Call with fan_mutex held
7266 static void fan_update_desired_level(u8 status
)
7269 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7271 fan_control_desired_level
= 7;
7273 fan_control_desired_level
= status
;
7277 static int fan_get_status(u8
*status
)
7282 * Add TPACPI_FAN_RD_ACPI_FANS ? */
7284 switch (fan_status_access_mode
) {
7285 case TPACPI_FAN_RD_ACPI_GFAN
:
7286 /* 570, 600e/x, 770e, 770x */
7288 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
7296 case TPACPI_FAN_RD_TPEC
:
7297 /* all except 570, 600e/x, 770e, 770x */
7298 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
7301 if (likely(status
)) {
7303 fan_quirk1_handle(status
);
7315 static int fan_get_status_safe(u8
*status
)
7320 if (mutex_lock_killable(&fan_mutex
))
7321 return -ERESTARTSYS
;
7322 rc
= fan_get_status(&s
);
7324 fan_update_desired_level(s
);
7325 mutex_unlock(&fan_mutex
);
7333 static int fan_get_speed(unsigned int *speed
)
7337 switch (fan_status_access_mode
) {
7338 case TPACPI_FAN_RD_TPEC
:
7339 /* all except 570, 600e/x, 770e, 770x */
7340 if (unlikely(!fan_select_fan1()))
7342 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
7343 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
7347 *speed
= (hi
<< 8) | lo
;
7358 static int fan2_get_speed(unsigned int *speed
)
7363 switch (fan_status_access_mode
) {
7364 case TPACPI_FAN_RD_TPEC
:
7365 /* all except 570, 600e/x, 770e, 770x */
7366 if (unlikely(!fan_select_fan2()))
7368 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
7369 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
7370 fan_select_fan1(); /* play it safe */
7375 *speed
= (hi
<< 8) | lo
;
7386 static int fan_set_level(int level
)
7388 if (!fan_control_allowed
)
7391 switch (fan_control_access_mode
) {
7392 case TPACPI_FAN_WR_ACPI_SFAN
:
7393 if (level
>= 0 && level
<= 7) {
7394 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
7400 case TPACPI_FAN_WR_ACPI_FANS
:
7401 case TPACPI_FAN_WR_TPEC
:
7402 if (!(level
& TP_EC_FAN_AUTO
) &&
7403 !(level
& TP_EC_FAN_FULLSPEED
) &&
7404 ((level
< 0) || (level
> 7)))
7407 /* safety net should the EC not support AUTO
7408 * or FULLSPEED mode bits and just ignore them */
7409 if (level
& TP_EC_FAN_FULLSPEED
)
7410 level
|= 7; /* safety min speed 7 */
7411 else if (level
& TP_EC_FAN_AUTO
)
7412 level
|= 4; /* safety min speed 4 */
7414 if (!acpi_ec_write(fan_status_offset
, level
))
7417 tp_features
.fan_ctrl_status_undef
= 0;
7424 vdbg_printk(TPACPI_DBG_FAN
,
7425 "fan control: set fan control register to 0x%02x\n", level
);
7429 static int fan_set_level_safe(int level
)
7433 if (!fan_control_allowed
)
7436 if (mutex_lock_killable(&fan_mutex
))
7437 return -ERESTARTSYS
;
7439 if (level
== TPACPI_FAN_LAST_LEVEL
)
7440 level
= fan_control_desired_level
;
7442 rc
= fan_set_level(level
);
7444 fan_update_desired_level(level
);
7446 mutex_unlock(&fan_mutex
);
7450 static int fan_set_enable(void)
7455 if (!fan_control_allowed
)
7458 if (mutex_lock_killable(&fan_mutex
))
7459 return -ERESTARTSYS
;
7461 switch (fan_control_access_mode
) {
7462 case TPACPI_FAN_WR_ACPI_FANS
:
7463 case TPACPI_FAN_WR_TPEC
:
7464 rc
= fan_get_status(&s
);
7468 /* Don't go out of emergency fan mode */
7471 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
7474 if (!acpi_ec_write(fan_status_offset
, s
))
7477 tp_features
.fan_ctrl_status_undef
= 0;
7482 case TPACPI_FAN_WR_ACPI_SFAN
:
7483 rc
= fan_get_status(&s
);
7489 /* Set fan to at least level 4 */
7492 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
7502 mutex_unlock(&fan_mutex
);
7505 vdbg_printk(TPACPI_DBG_FAN
,
7506 "fan control: set fan control register to 0x%02x\n",
7511 static int fan_set_disable(void)
7515 if (!fan_control_allowed
)
7518 if (mutex_lock_killable(&fan_mutex
))
7519 return -ERESTARTSYS
;
7522 switch (fan_control_access_mode
) {
7523 case TPACPI_FAN_WR_ACPI_FANS
:
7524 case TPACPI_FAN_WR_TPEC
:
7525 if (!acpi_ec_write(fan_status_offset
, 0x00))
7528 fan_control_desired_level
= 0;
7529 tp_features
.fan_ctrl_status_undef
= 0;
7533 case TPACPI_FAN_WR_ACPI_SFAN
:
7534 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
7537 fan_control_desired_level
= 0;
7545 vdbg_printk(TPACPI_DBG_FAN
,
7546 "fan control: set fan control register to 0\n");
7548 mutex_unlock(&fan_mutex
);
7552 static int fan_set_speed(int speed
)
7556 if (!fan_control_allowed
)
7559 if (mutex_lock_killable(&fan_mutex
))
7560 return -ERESTARTSYS
;
7563 switch (fan_control_access_mode
) {
7564 case TPACPI_FAN_WR_ACPI_FANS
:
7565 if (speed
>= 0 && speed
<= 65535) {
7566 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
7567 speed
, speed
, speed
))
7577 mutex_unlock(&fan_mutex
);
7581 static void fan_watchdog_reset(void)
7583 static int fan_watchdog_active
;
7585 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
7588 if (fan_watchdog_active
)
7589 cancel_delayed_work(&fan_watchdog_task
);
7591 if (fan_watchdog_maxinterval
> 0 &&
7592 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
7593 fan_watchdog_active
= 1;
7594 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
7595 msecs_to_jiffies(fan_watchdog_maxinterval
7598 "failed to queue the fan watchdog, "
7599 "watchdog will not trigger\n");
7602 fan_watchdog_active
= 0;
7605 static void fan_watchdog_fire(struct work_struct
*ignored
)
7609 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
7612 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
7613 rc
= fan_set_enable();
7615 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
7616 "will try again later...\n", -rc
);
7617 /* reschedule for later */
7618 fan_watchdog_reset();
7623 * SYSFS fan layout: hwmon compatible (device)
7626 * 0: "disengaged" mode
7628 * 2: native EC "auto" mode (recommended, hardware default)
7630 * pwm*: set speed in manual mode, ignored otherwise.
7631 * 0 is level 0; 255 is level 7. Intermediate points done with linear
7634 * fan*_input: tachometer reading, RPM
7637 * SYSFS fan layout: extensions
7639 * fan_watchdog (driver):
7640 * fan watchdog interval in seconds, 0 disables (default), max 120
7643 /* sysfs fan pwm1_enable ----------------------------------------------- */
7644 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
7645 struct device_attribute
*attr
,
7651 res
= fan_get_status_safe(&status
);
7655 if (status
& TP_EC_FAN_FULLSPEED
) {
7657 } else if (status
& TP_EC_FAN_AUTO
) {
7662 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
7665 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7666 struct device_attribute
*attr
,
7667 const char *buf
, size_t count
)
7672 if (parse_strtoul(buf
, 2, &t
))
7675 tpacpi_disclose_usertask("hwmon pwm1_enable",
7676 "set fan mode to %lu\n", t
);
7680 level
= TP_EC_FAN_FULLSPEED
;
7683 level
= TPACPI_FAN_LAST_LEVEL
;
7686 level
= TP_EC_FAN_AUTO
;
7689 /* reserved for software-controlled auto mode */
7695 res
= fan_set_level_safe(level
);
7701 fan_watchdog_reset();
7706 static struct device_attribute dev_attr_fan_pwm1_enable
=
7707 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7708 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7710 /* sysfs fan pwm1 ------------------------------------------------------ */
7711 static ssize_t
fan_pwm1_show(struct device
*dev
,
7712 struct device_attribute
*attr
,
7718 res
= fan_get_status_safe(&status
);
7723 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7724 status
= fan_control_desired_level
;
7729 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7732 static ssize_t
fan_pwm1_store(struct device
*dev
,
7733 struct device_attribute
*attr
,
7734 const char *buf
, size_t count
)
7738 u8 status
, newlevel
;
7740 if (parse_strtoul(buf
, 255, &s
))
7743 tpacpi_disclose_usertask("hwmon pwm1",
7744 "set fan speed to %lu\n", s
);
7746 /* scale down from 0-255 to 0-7 */
7747 newlevel
= (s
>> 5) & 0x07;
7749 if (mutex_lock_killable(&fan_mutex
))
7750 return -ERESTARTSYS
;
7752 rc
= fan_get_status(&status
);
7753 if (!rc
&& (status
&
7754 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7755 rc
= fan_set_level(newlevel
);
7759 fan_update_desired_level(newlevel
);
7760 fan_watchdog_reset();
7764 mutex_unlock(&fan_mutex
);
7765 return (rc
)? rc
: count
;
7768 static struct device_attribute dev_attr_fan_pwm1
=
7769 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7770 fan_pwm1_show
, fan_pwm1_store
);
7772 /* sysfs fan fan1_input ------------------------------------------------ */
7773 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7774 struct device_attribute
*attr
,
7780 res
= fan_get_speed(&speed
);
7784 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7787 static struct device_attribute dev_attr_fan_fan1_input
=
7788 __ATTR(fan1_input
, S_IRUGO
,
7789 fan_fan1_input_show
, NULL
);
7791 /* sysfs fan fan2_input ------------------------------------------------ */
7792 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7793 struct device_attribute
*attr
,
7799 res
= fan2_get_speed(&speed
);
7803 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7806 static struct device_attribute dev_attr_fan_fan2_input
=
7807 __ATTR(fan2_input
, S_IRUGO
,
7808 fan_fan2_input_show
, NULL
);
7810 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
7811 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
7814 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
7817 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
7818 const char *buf
, size_t count
)
7822 if (parse_strtoul(buf
, 120, &t
))
7825 if (!fan_control_allowed
)
7828 fan_watchdog_maxinterval
= t
;
7829 fan_watchdog_reset();
7831 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
7836 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
7837 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
7839 /* --------------------------------------------------------------------- */
7840 static struct attribute
*fan_attributes
[] = {
7841 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
7842 &dev_attr_fan_fan1_input
.attr
,
7843 NULL
, /* for fan2_input */
7847 static const struct attribute_group fan_attr_group
= {
7848 .attrs
= fan_attributes
,
7851 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
7852 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
7854 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7855 { .vendor = PCI_VENDOR_ID_IBM, \
7856 .bios = TPACPI_MATCH_ANY, \
7857 .ec = TPID(__id1, __id2), \
7858 .quirks = __quirks }
7860 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7861 { .vendor = PCI_VENDOR_ID_LENOVO, \
7862 .bios = TPACPI_MATCH_ANY, \
7863 .ec = TPID(__id1, __id2), \
7864 .quirks = __quirks }
7866 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
7867 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
7868 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
7869 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
7870 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
7871 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
7874 #undef TPACPI_FAN_QL
7875 #undef TPACPI_FAN_QI
7877 static int __init
fan_init(struct ibm_init_struct
*iibm
)
7880 unsigned long quirks
;
7882 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7883 "initializing fan subdriver\n");
7885 mutex_init(&fan_mutex
);
7886 fan_status_access_mode
= TPACPI_FAN_NONE
;
7887 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7888 fan_control_commands
= 0;
7889 fan_watchdog_maxinterval
= 0;
7890 tp_features
.fan_ctrl_status_undef
= 0;
7891 tp_features
.second_fan
= 0;
7892 fan_control_desired_level
= 7;
7894 TPACPI_ACPIHANDLE_INIT(fans
);
7895 TPACPI_ACPIHANDLE_INIT(gfan
);
7896 TPACPI_ACPIHANDLE_INIT(sfan
);
7898 quirks
= tpacpi_check_quirks(fan_quirk_table
,
7899 ARRAY_SIZE(fan_quirk_table
));
7902 /* 570, 600e/x, 770e, 770x */
7903 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7905 /* all other ThinkPads: note that even old-style
7906 * ThinkPad ECs supports the fan control register */
7907 if (likely(acpi_ec_read(fan_status_offset
,
7908 &fan_control_initial_status
))) {
7909 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7910 if (quirks
& TPACPI_FAN_Q1
)
7912 if (quirks
& TPACPI_FAN_2FAN
) {
7913 tp_features
.second_fan
= 1;
7914 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7915 "secondary fan support enabled\n");
7919 "ThinkPad ACPI EC access misbehaving, "
7920 "fan status and control unavailable\n");
7927 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
7928 fan_control_commands
|=
7929 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
7932 /* gfan without sfan means no fan control */
7933 /* all other models implement TP EC 0x2f control */
7937 fan_control_access_mode
=
7938 TPACPI_FAN_WR_ACPI_FANS
;
7939 fan_control_commands
|=
7940 TPACPI_FAN_CMD_SPEED
|
7941 TPACPI_FAN_CMD_LEVEL
|
7942 TPACPI_FAN_CMD_ENABLE
;
7944 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
7945 fan_control_commands
|=
7946 TPACPI_FAN_CMD_LEVEL
|
7947 TPACPI_FAN_CMD_ENABLE
;
7952 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7953 "fan is %s, modes %d, %d\n",
7954 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
7955 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
7956 fan_status_access_mode
, fan_control_access_mode
);
7958 /* fan control master switch */
7959 if (!fan_control_allowed
) {
7960 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7961 fan_control_commands
= 0;
7962 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7963 "fan control features disabled by parameter\n");
7966 /* update fan_control_desired_level */
7967 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
7968 fan_get_status_safe(NULL
);
7970 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
7971 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
7972 if (tp_features
.second_fan
) {
7973 /* attach second fan tachometer */
7974 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
7975 &dev_attr_fan_fan2_input
.attr
;
7977 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7982 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
7983 &driver_attr_fan_watchdog
);
7985 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7994 static void fan_exit(void)
7996 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
7997 "cancelling any pending fan watchdog tasks\n");
7999 /* FIXME: can we really do this unconditionally? */
8000 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
8001 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
8002 &driver_attr_fan_watchdog
);
8004 cancel_delayed_work(&fan_watchdog_task
);
8005 flush_workqueue(tpacpi_wq
);
8008 static void fan_suspend(pm_message_t state
)
8012 if (!fan_control_allowed
)
8015 /* Store fan status in cache */
8016 fan_control_resume_level
= 0;
8017 rc
= fan_get_status_safe(&fan_control_resume_level
);
8019 printk(TPACPI_NOTICE
8020 "failed to read fan level for later "
8021 "restore during resume: %d\n", rc
);
8023 /* if it is undefined, don't attempt to restore it.
8025 if (tp_features
.fan_ctrl_status_undef
)
8026 fan_control_resume_level
= 0;
8029 static void fan_resume(void)
8031 u8 current_level
= 7;
8032 bool do_set
= false;
8035 /* DSDT *always* updates status on resume */
8036 tp_features
.fan_ctrl_status_undef
= 0;
8038 if (!fan_control_allowed
||
8039 !fan_control_resume_level
||
8040 (fan_get_status_safe(¤t_level
) < 0))
8043 switch (fan_control_access_mode
) {
8044 case TPACPI_FAN_WR_ACPI_SFAN
:
8045 /* never decrease fan level */
8046 do_set
= (fan_control_resume_level
> current_level
);
8048 case TPACPI_FAN_WR_ACPI_FANS
:
8049 case TPACPI_FAN_WR_TPEC
:
8050 /* never decrease fan level, scale is:
8051 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
8053 * We expect the firmware to set either 7 or AUTO, but we
8054 * handle FULLSPEED out of paranoia.
8056 * So, we can safely only restore FULLSPEED or 7, anything
8057 * else could slow the fan. Restoring AUTO is useless, at
8058 * best that's exactly what the DSDT already set (it is the
8061 * Always keep in mind that the DSDT *will* have set the
8062 * fans to what the vendor supposes is the best level. We
8063 * muck with it only to speed the fan up.
8065 if (fan_control_resume_level
!= 7 &&
8066 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
8069 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
8070 (current_level
!= fan_control_resume_level
);
8076 printk(TPACPI_NOTICE
8077 "restoring fan level to 0x%02x\n",
8078 fan_control_resume_level
);
8079 rc
= fan_set_level_safe(fan_control_resume_level
);
8081 printk(TPACPI_NOTICE
8082 "failed to restore fan level: %d\n", rc
);
8086 static int fan_read(struct seq_file
*m
)
8090 unsigned int speed
= 0;
8092 switch (fan_status_access_mode
) {
8093 case TPACPI_FAN_RD_ACPI_GFAN
:
8094 /* 570, 600e/x, 770e, 770x */
8095 rc
= fan_get_status_safe(&status
);
8099 seq_printf(m
, "status:\t\t%s\n"
8101 (status
!= 0) ? "enabled" : "disabled", status
);
8104 case TPACPI_FAN_RD_TPEC
:
8105 /* all except 570, 600e/x, 770e, 770x */
8106 rc
= fan_get_status_safe(&status
);
8110 seq_printf(m
, "status:\t\t%s\n",
8111 (status
!= 0) ? "enabled" : "disabled");
8113 rc
= fan_get_speed(&speed
);
8117 seq_printf(m
, "speed:\t\t%d\n", speed
);
8119 if (status
& TP_EC_FAN_FULLSPEED
)
8120 /* Disengaged mode takes precedence */
8121 seq_printf(m
, "level:\t\tdisengaged\n");
8122 else if (status
& TP_EC_FAN_AUTO
)
8123 seq_printf(m
, "level:\t\tauto\n");
8125 seq_printf(m
, "level:\t\t%d\n", status
);
8128 case TPACPI_FAN_NONE
:
8130 seq_printf(m
, "status:\t\tnot supported\n");
8133 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
8134 seq_printf(m
, "commands:\tlevel <level>");
8136 switch (fan_control_access_mode
) {
8137 case TPACPI_FAN_WR_ACPI_SFAN
:
8138 seq_printf(m
, " (<level> is 0-7)\n");
8142 seq_printf(m
, " (<level> is 0-7, "
8143 "auto, disengaged, full-speed)\n");
8148 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
8149 seq_printf(m
, "commands:\tenable, disable\n"
8150 "commands:\twatchdog <timeout> (<timeout> "
8151 "is 0 (off), 1-120 (seconds))\n");
8153 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
8154 seq_printf(m
, "commands:\tspeed <speed>"
8155 " (<speed> is 0-65535)\n");
8160 static int fan_write_cmd_level(const char *cmd
, int *rc
)
8164 if (strlencmp(cmd
, "level auto") == 0)
8165 level
= TP_EC_FAN_AUTO
;
8166 else if ((strlencmp(cmd
, "level disengaged") == 0) |
8167 (strlencmp(cmd
, "level full-speed") == 0))
8168 level
= TP_EC_FAN_FULLSPEED
;
8169 else if (sscanf(cmd
, "level %d", &level
) != 1)
8172 *rc
= fan_set_level_safe(level
);
8174 printk(TPACPI_ERR
"level command accepted for unsupported "
8175 "access mode %d", fan_control_access_mode
);
8177 tpacpi_disclose_usertask("procfs fan",
8178 "set level to %d\n", level
);
8183 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
8185 if (strlencmp(cmd
, "enable") != 0)
8188 *rc
= fan_set_enable();
8190 printk(TPACPI_ERR
"enable command accepted for unsupported "
8191 "access mode %d", fan_control_access_mode
);
8193 tpacpi_disclose_usertask("procfs fan", "enable\n");
8198 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
8200 if (strlencmp(cmd
, "disable") != 0)
8203 *rc
= fan_set_disable();
8205 printk(TPACPI_ERR
"disable command accepted for unsupported "
8206 "access mode %d", fan_control_access_mode
);
8208 tpacpi_disclose_usertask("procfs fan", "disable\n");
8213 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
8218 * Support speed <low> <medium> <high> ? */
8220 if (sscanf(cmd
, "speed %d", &speed
) != 1)
8223 *rc
= fan_set_speed(speed
);
8225 printk(TPACPI_ERR
"speed command accepted for unsupported "
8226 "access mode %d", fan_control_access_mode
);
8228 tpacpi_disclose_usertask("procfs fan",
8229 "set speed to %d\n", speed
);
8234 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
8238 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
8241 if (interval
< 0 || interval
> 120)
8244 fan_watchdog_maxinterval
= interval
;
8245 tpacpi_disclose_usertask("procfs fan",
8246 "set watchdog timer to %d\n",
8253 static int fan_write(char *buf
)
8258 while (!rc
&& (cmd
= next_cmd(&buf
))) {
8259 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
8260 fan_write_cmd_level(cmd
, &rc
)) &&
8261 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
8262 (fan_write_cmd_enable(cmd
, &rc
) ||
8263 fan_write_cmd_disable(cmd
, &rc
) ||
8264 fan_write_cmd_watchdog(cmd
, &rc
))) &&
8265 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
8266 fan_write_cmd_speed(cmd
, &rc
))
8270 fan_watchdog_reset();
8276 static struct ibm_struct fan_driver_data
= {
8281 .suspend
= fan_suspend
,
8282 .resume
= fan_resume
,
8285 /****************************************************************************
8286 ****************************************************************************
8290 ****************************************************************************
8291 ****************************************************************************/
8294 * HKEY event callout for other subdrivers go here
8295 * (yes, it is ugly, but it is quick, safe, and gets the job done
8297 static void tpacpi_driver_event(const unsigned int hkey_event
)
8299 if (ibm_backlight_device
) {
8300 switch (hkey_event
) {
8301 case TP_HKEY_EV_BRGHT_UP
:
8302 case TP_HKEY_EV_BRGHT_DOWN
:
8303 tpacpi_brightness_notify_change();
8307 switch (hkey_event
) {
8308 case TP_HKEY_EV_VOL_UP
:
8309 case TP_HKEY_EV_VOL_DOWN
:
8310 case TP_HKEY_EV_VOL_MUTE
:
8311 volume_alsa_notify_change();
8316 static void hotkey_driver_event(const unsigned int scancode
)
8318 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
8321 /* sysfs name ---------------------------------------------------------- */
8322 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
8323 struct device_attribute
*attr
,
8326 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
8329 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
8330 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
8332 /* --------------------------------------------------------------------- */
8335 static struct proc_dir_entry
*proc_dir
;
8338 * Module and infrastructure proble, init and exit handling
8341 static int force_load
;
8343 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
8344 static const char * __init
str_supported(int is_supported
)
8346 static char text_unsupported
[] __initdata
= "not supported";
8348 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
8350 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
8352 static void ibm_exit(struct ibm_struct
*ibm
)
8354 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
8356 list_del_init(&ibm
->all_drivers
);
8358 if (ibm
->flags
.acpi_notify_installed
) {
8359 dbg_printk(TPACPI_DBG_EXIT
,
8360 "%s: acpi_remove_notify_handler\n", ibm
->name
);
8362 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
8364 dispatch_acpi_notify
);
8365 ibm
->flags
.acpi_notify_installed
= 0;
8366 ibm
->flags
.acpi_notify_installed
= 0;
8369 if (ibm
->flags
.proc_created
) {
8370 dbg_printk(TPACPI_DBG_EXIT
,
8371 "%s: remove_proc_entry\n", ibm
->name
);
8372 remove_proc_entry(ibm
->name
, proc_dir
);
8373 ibm
->flags
.proc_created
= 0;
8376 if (ibm
->flags
.acpi_driver_registered
) {
8377 dbg_printk(TPACPI_DBG_EXIT
,
8378 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
8380 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
8381 kfree(ibm
->acpi
->driver
);
8382 ibm
->acpi
->driver
= NULL
;
8383 ibm
->flags
.acpi_driver_registered
= 0;
8386 if (ibm
->flags
.init_called
&& ibm
->exit
) {
8388 ibm
->flags
.init_called
= 0;
8391 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
8394 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
8397 struct ibm_struct
*ibm
= iibm
->data
;
8398 struct proc_dir_entry
*entry
;
8400 BUG_ON(ibm
== NULL
);
8402 INIT_LIST_HEAD(&ibm
->all_drivers
);
8404 if (ibm
->flags
.experimental
&& !experimental
)
8407 dbg_printk(TPACPI_DBG_INIT
,
8408 "probing for %s\n", ibm
->name
);
8411 ret
= iibm
->init(iibm
);
8413 return 0; /* probe failed */
8417 ibm
->flags
.init_called
= 1;
8421 if (ibm
->acpi
->hid
) {
8422 ret
= register_tpacpi_subdriver(ibm
);
8427 if (ibm
->acpi
->notify
) {
8428 ret
= setup_acpi_notify(ibm
);
8429 if (ret
== -ENODEV
) {
8430 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
8440 dbg_printk(TPACPI_DBG_INIT
,
8441 "%s installed\n", ibm
->name
);
8449 entry
= proc_create_data(ibm
->name
, mode
, proc_dir
,
8450 &dispatch_proc_fops
, ibm
);
8452 printk(TPACPI_ERR
"unable to create proc entry %s\n",
8457 ibm
->flags
.proc_created
= 1;
8460 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
8465 dbg_printk(TPACPI_DBG_INIT
,
8466 "%s: at error exit path with result %d\n",
8470 return (ret
< 0)? ret
: 0;
8475 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
8477 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
8480 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
8481 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
8484 return s
&& strlen(s
) >= 8 &&
8485 tpacpi_is_fw_digit(s
[0]) &&
8486 tpacpi_is_fw_digit(s
[1]) &&
8487 s
[2] == t
&& s
[3] == 'T' &&
8488 tpacpi_is_fw_digit(s
[4]) &&
8489 tpacpi_is_fw_digit(s
[5]) &&
8490 s
[6] == 'W' && s
[7] == 'W';
8493 /* returns 0 - probe ok, or < 0 - probe error.
8494 * Probe ok doesn't mean thinkpad found.
8495 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
8496 static int __must_check __init
get_thinkpad_model_data(
8497 struct thinkpad_id_data
*tp
)
8499 const struct dmi_device
*dev
= NULL
;
8500 char ec_fw_string
[18];
8506 memset(tp
, 0, sizeof(*tp
));
8508 if (dmi_name_in_vendors("IBM"))
8509 tp
->vendor
= PCI_VENDOR_ID_IBM
;
8510 else if (dmi_name_in_vendors("LENOVO"))
8511 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
8515 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
8516 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
8517 if (s
&& !tp
->bios_version_str
)
8520 /* Really ancient ThinkPad 240X will fail this, which is fine */
8521 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
8524 tp
->bios_model
= tp
->bios_version_str
[0]
8525 | (tp
->bios_version_str
[1] << 8);
8526 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
8527 | tp
->bios_version_str
[5];
8530 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
8531 * X32 or newer, all Z series; Some models must have an
8532 * up-to-date BIOS or they will not be detected.
8534 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8536 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
8537 if (sscanf(dev
->name
,
8538 "IBM ThinkPad Embedded Controller -[%17c",
8539 ec_fw_string
) == 1) {
8540 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
8541 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
8543 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
8544 if (!tp
->ec_version_str
)
8547 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
8548 tp
->ec_model
= ec_fw_string
[0]
8549 | (ec_fw_string
[1] << 8);
8550 tp
->ec_release
= (ec_fw_string
[4] << 8)
8553 printk(TPACPI_NOTICE
8554 "ThinkPad firmware release %s "
8555 "doesn't match the known patterns\n",
8557 printk(TPACPI_NOTICE
8558 "please report this to %s\n",
8565 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
8566 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
8567 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
8572 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
8573 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
8574 if (s
&& !tp
->nummodel_str
)
8580 static int __init
probe_for_thinkpad(void)
8588 * Non-ancient models have better DMI tagging, but very old models
8589 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
8591 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
8592 (thinkpad_id
.ec_model
!= 0) ||
8593 tpacpi_is_fw_known();
8595 /* ec is required because many other handles are relative to it */
8596 TPACPI_ACPIHANDLE_INIT(ec
);
8600 "Not yet supported ThinkPad detected!\n");
8604 if (!is_thinkpad
&& !force_load
)
8611 /* Module init, exit, parameters */
8613 static struct ibm_init_struct ibms_init
[] __initdata
= {
8615 .init
= thinkpad_acpi_driver_init
,
8616 .data
= &thinkpad_acpi_driver_data
,
8619 .init
= hotkey_init
,
8620 .data
= &hotkey_driver_data
,
8623 .init
= bluetooth_init
,
8624 .data
= &bluetooth_driver_data
,
8628 .data
= &wan_driver_data
,
8632 .data
= &uwb_driver_data
,
8634 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8637 .data
= &video_driver_data
,
8642 .data
= &light_driver_data
,
8646 .data
= &cmos_driver_data
,
8650 .data
= &led_driver_data
,
8654 .data
= &beep_driver_data
,
8657 .init
= thermal_init
,
8658 .data
= &thermal_driver_data
,
8661 .data
= &ecdump_driver_data
,
8664 .init
= brightness_init
,
8665 .data
= &brightness_driver_data
,
8668 .init
= volume_init
,
8669 .data
= &volume_driver_data
,
8673 .data
= &fan_driver_data
,
8677 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
8680 struct ibm_struct
*ibm
;
8682 if (!kp
|| !kp
->name
|| !val
)
8685 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8686 ibm
= ibms_init
[i
].data
;
8687 WARN_ON(ibm
== NULL
);
8689 if (!ibm
|| !ibm
->name
)
8692 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8693 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8695 strcpy(ibms_init
[i
].param
, val
);
8696 strcat(ibms_init
[i
].param
, ",");
8704 module_param(experimental
, int, 0444);
8705 MODULE_PARM_DESC(experimental
,
8706 "Enables experimental features when non-zero");
8708 module_param_named(debug
, dbg_level
, uint
, 0);
8709 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8711 module_param(force_load
, bool, 0444);
8712 MODULE_PARM_DESC(force_load
,
8713 "Attempts to load the driver even on a "
8714 "mis-identified ThinkPad when true");
8716 module_param_named(fan_control
, fan_control_allowed
, bool, 0444);
8717 MODULE_PARM_DESC(fan_control
,
8718 "Enables setting fan parameters features when true");
8720 module_param_named(brightness_mode
, brightness_mode
, uint
, 0444);
8721 MODULE_PARM_DESC(brightness_mode
,
8722 "Selects brightness control strategy: "
8723 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8725 module_param(brightness_enable
, uint
, 0444);
8726 MODULE_PARM_DESC(brightness_enable
,
8727 "Enables backlight control when 1, disables when 0");
8729 module_param(hotkey_report_mode
, uint
, 0444);
8730 MODULE_PARM_DESC(hotkey_report_mode
,
8731 "used for backwards compatibility with userspace, "
8732 "see documentation");
8734 module_param_named(volume_mode
, volume_mode
, uint
, 0444);
8735 MODULE_PARM_DESC(volume_mode
,
8736 "Selects volume control strategy: "
8737 "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM");
8739 module_param_named(volume_capabilities
, volume_capabilities
, uint
, 0444);
8740 MODULE_PARM_DESC(volume_capabilities
,
8741 "Selects the mixer capabilites: "
8742 "0=auto, 1=volume and mute, 2=mute only");
8744 module_param_named(volume_control
, volume_control_allowed
, bool, 0444);
8745 MODULE_PARM_DESC(volume_control
,
8746 "Enables software override for the console audio "
8747 "control when true");
8749 /* ALSA module API parameters */
8750 module_param_named(index
, alsa_index
, int, 0444);
8751 MODULE_PARM_DESC(index
, "ALSA index for the ACPI EC Mixer");
8752 module_param_named(id
, alsa_id
, charp
, 0444);
8753 MODULE_PARM_DESC(id
, "ALSA id for the ACPI EC Mixer");
8754 module_param_named(enable
, alsa_enable
, bool, 0444);
8755 MODULE_PARM_DESC(enable
, "Enable the ALSA interface for the ACPI EC Mixer");
8757 #define TPACPI_PARAM(feature) \
8758 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8759 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8760 "at module load, see documentation")
8762 TPACPI_PARAM(hotkey
);
8763 TPACPI_PARAM(bluetooth
);
8764 TPACPI_PARAM(video
);
8765 TPACPI_PARAM(light
);
8769 TPACPI_PARAM(ecdump
);
8770 TPACPI_PARAM(brightness
);
8771 TPACPI_PARAM(volume
);
8774 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8775 module_param(dbg_wlswemul
, uint
, 0444);
8776 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
8777 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
8778 MODULE_PARM_DESC(wlsw_state
,
8779 "Initial state of the emulated WLSW switch");
8781 module_param(dbg_bluetoothemul
, uint
, 0444);
8782 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
8783 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
8784 MODULE_PARM_DESC(bluetooth_state
,
8785 "Initial state of the emulated bluetooth switch");
8787 module_param(dbg_wwanemul
, uint
, 0444);
8788 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
8789 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
8790 MODULE_PARM_DESC(wwan_state
,
8791 "Initial state of the emulated WWAN switch");
8793 module_param(dbg_uwbemul
, uint
, 0444);
8794 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
8795 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
8796 MODULE_PARM_DESC(uwb_state
,
8797 "Initial state of the emulated UWB switch");
8800 static void thinkpad_acpi_module_exit(void)
8802 struct ibm_struct
*ibm
, *itmp
;
8804 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
8806 list_for_each_entry_safe_reverse(ibm
, itmp
,
8807 &tpacpi_all_drivers
,
8812 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
8814 if (tpacpi_inputdev
) {
8815 if (tp_features
.input_device_registered
)
8816 input_unregister_device(tpacpi_inputdev
);
8818 input_free_device(tpacpi_inputdev
);
8822 hwmon_device_unregister(tpacpi_hwmon
);
8824 if (tp_features
.sensors_pdev_attrs_registered
)
8825 device_remove_file(&tpacpi_sensors_pdev
->dev
,
8826 &dev_attr_thinkpad_acpi_pdev_name
);
8827 if (tpacpi_sensors_pdev
)
8828 platform_device_unregister(tpacpi_sensors_pdev
);
8830 platform_device_unregister(tpacpi_pdev
);
8832 if (tp_features
.sensors_pdrv_attrs_registered
)
8833 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
8834 if (tp_features
.platform_drv_attrs_registered
)
8835 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
8837 if (tp_features
.sensors_pdrv_registered
)
8838 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
8840 if (tp_features
.platform_drv_registered
)
8841 platform_driver_unregister(&tpacpi_pdriver
);
8844 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
8847 destroy_workqueue(tpacpi_wq
);
8849 kfree(thinkpad_id
.bios_version_str
);
8850 kfree(thinkpad_id
.ec_version_str
);
8851 kfree(thinkpad_id
.model_str
);
8855 static int __init
thinkpad_acpi_module_init(void)
8859 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
8861 /* Parameter checking */
8862 if (hotkey_report_mode
> 2)
8865 /* Driver-level probe */
8867 ret
= get_thinkpad_model_data(&thinkpad_id
);
8870 "unable to get DMI data: %d\n", ret
);
8871 thinkpad_acpi_module_exit();
8874 ret
= probe_for_thinkpad();
8876 thinkpad_acpi_module_exit();
8880 /* Driver initialization */
8882 TPACPI_ACPIHANDLE_INIT(ecrd
);
8883 TPACPI_ACPIHANDLE_INIT(ecwr
);
8885 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
8887 thinkpad_acpi_module_exit();
8891 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
8894 "unable to create proc dir " TPACPI_PROC_DIR
);
8895 thinkpad_acpi_module_exit();
8898 proc_dir
->owner
= THIS_MODULE
;
8900 ret
= platform_driver_register(&tpacpi_pdriver
);
8903 "unable to register main platform driver\n");
8904 thinkpad_acpi_module_exit();
8907 tp_features
.platform_drv_registered
= 1;
8909 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
8912 "unable to register hwmon platform driver\n");
8913 thinkpad_acpi_module_exit();
8916 tp_features
.sensors_pdrv_registered
= 1;
8918 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
8920 tp_features
.platform_drv_attrs_registered
= 1;
8921 ret
= tpacpi_create_driver_attributes(
8922 &tpacpi_hwmon_pdriver
.driver
);
8926 "unable to create sysfs driver attributes\n");
8927 thinkpad_acpi_module_exit();
8930 tp_features
.sensors_pdrv_attrs_registered
= 1;
8933 /* Device initialization */
8934 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
8936 if (IS_ERR(tpacpi_pdev
)) {
8937 ret
= PTR_ERR(tpacpi_pdev
);
8939 printk(TPACPI_ERR
"unable to register platform device\n");
8940 thinkpad_acpi_module_exit();
8943 tpacpi_sensors_pdev
= platform_device_register_simple(
8944 TPACPI_HWMON_DRVR_NAME
,
8946 if (IS_ERR(tpacpi_sensors_pdev
)) {
8947 ret
= PTR_ERR(tpacpi_sensors_pdev
);
8948 tpacpi_sensors_pdev
= NULL
;
8950 "unable to register hwmon platform device\n");
8951 thinkpad_acpi_module_exit();
8954 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
8955 &dev_attr_thinkpad_acpi_pdev_name
);
8958 "unable to create sysfs hwmon device attributes\n");
8959 thinkpad_acpi_module_exit();
8962 tp_features
.sensors_pdev_attrs_registered
= 1;
8963 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
8964 if (IS_ERR(tpacpi_hwmon
)) {
8965 ret
= PTR_ERR(tpacpi_hwmon
);
8966 tpacpi_hwmon
= NULL
;
8967 printk(TPACPI_ERR
"unable to register hwmon device\n");
8968 thinkpad_acpi_module_exit();
8971 mutex_init(&tpacpi_inputdev_send_mutex
);
8972 tpacpi_inputdev
= input_allocate_device();
8973 if (!tpacpi_inputdev
) {
8974 printk(TPACPI_ERR
"unable to allocate input device\n");
8975 thinkpad_acpi_module_exit();
8978 /* Prepare input device, but don't register */
8979 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
8980 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
8981 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
8982 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
8983 thinkpad_id
.vendor
:
8985 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
8986 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
8987 tpacpi_inputdev
->dev
.parent
= &tpacpi_pdev
->dev
;
8989 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8990 ret
= ibm_init(&ibms_init
[i
]);
8991 if (ret
>= 0 && *ibms_init
[i
].param
)
8992 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
8994 thinkpad_acpi_module_exit();
8998 ret
= input_register_device(tpacpi_inputdev
);
9000 printk(TPACPI_ERR
"unable to register input device\n");
9001 thinkpad_acpi_module_exit();
9004 tp_features
.input_device_registered
= 1;
9007 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
9011 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
9014 * This will autoload the driver in almost every ThinkPad
9015 * in widespread use.
9017 * Only _VERY_ old models, like the 240, 240x and 570 lack
9018 * the HKEY event interface.
9020 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
9023 * DMI matching for module autoloading
9025 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
9026 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
9028 * Only models listed in thinkwiki will be supported, so add yours
9029 * if it is not there yet.
9031 #define IBM_BIOS_MODULE_ALIAS(__type) \
9032 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
9034 /* Ancient thinkpad BIOSes have to be identified by
9035 * BIOS type or model number, and there are far less
9036 * BIOS types than model numbers... */
9037 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
9039 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
9040 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
9041 MODULE_DESCRIPTION(TPACPI_DESC
);
9042 MODULE_VERSION(TPACPI_VERSION
);
9043 MODULE_LICENSE("GPL");
9045 module_init(thinkpad_acpi_module_init
);
9046 module_exit(thinkpad_acpi_module_exit
);