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.24"
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
:
2344 case TPACPI_LIFE_RUNNING
:
2345 hotkey_poll_setup_safe(false);
2347 case TPACPI_LIFE_EXITING
:
2351 /* Should only happen if tpacpi_lifecycle is corrupt */
2356 static void hotkey_inputdev_close(struct input_dev
*dev
)
2358 /* disable hotkey polling when possible */
2359 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
&&
2360 !(hotkey_source_mask
& hotkey_driver_mask
))
2361 hotkey_poll_setup_safe(false);
2364 /* sysfs hotkey enable ------------------------------------------------- */
2365 static ssize_t
hotkey_enable_show(struct device
*dev
,
2366 struct device_attribute
*attr
,
2371 printk_deprecated_attribute("hotkey_enable",
2372 "Hotkey reporting is always enabled");
2374 res
= hotkey_status_get(&status
);
2378 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2381 static ssize_t
hotkey_enable_store(struct device
*dev
,
2382 struct device_attribute
*attr
,
2383 const char *buf
, size_t count
)
2387 printk_deprecated_attribute("hotkey_enable",
2388 "Hotkeys can be disabled through hotkey_mask");
2390 if (parse_strtoul(buf
, 1, &t
))
2399 static struct device_attribute dev_attr_hotkey_enable
=
2400 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2401 hotkey_enable_show
, hotkey_enable_store
);
2403 /* sysfs hotkey mask --------------------------------------------------- */
2404 static ssize_t
hotkey_mask_show(struct device
*dev
,
2405 struct device_attribute
*attr
,
2408 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2411 static ssize_t
hotkey_mask_store(struct device
*dev
,
2412 struct device_attribute
*attr
,
2413 const char *buf
, size_t count
)
2418 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2421 if (mutex_lock_killable(&hotkey_mutex
))
2422 return -ERESTARTSYS
;
2424 res
= hotkey_user_mask_set(t
);
2426 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2427 hotkey_poll_setup(true);
2430 mutex_unlock(&hotkey_mutex
);
2432 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2434 return (res
) ? res
: count
;
2437 static struct device_attribute dev_attr_hotkey_mask
=
2438 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2439 hotkey_mask_show
, hotkey_mask_store
);
2441 /* sysfs hotkey bios_enabled ------------------------------------------- */
2442 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2443 struct device_attribute
*attr
,
2446 return sprintf(buf
, "0\n");
2449 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2450 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2452 /* sysfs hotkey bios_mask ---------------------------------------------- */
2453 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2454 struct device_attribute
*attr
,
2457 printk_deprecated_attribute("hotkey_bios_mask",
2458 "This attribute is useless.");
2459 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2462 static struct device_attribute dev_attr_hotkey_bios_mask
=
2463 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2465 /* sysfs hotkey all_mask ----------------------------------------------- */
2466 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2467 struct device_attribute
*attr
,
2470 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2471 hotkey_all_mask
| hotkey_source_mask
);
2474 static struct device_attribute dev_attr_hotkey_all_mask
=
2475 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2477 /* sysfs hotkey recommended_mask --------------------------------------- */
2478 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2479 struct device_attribute
*attr
,
2482 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2483 (hotkey_all_mask
| hotkey_source_mask
)
2484 & ~hotkey_reserved_mask
);
2487 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2488 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2489 hotkey_recommended_mask_show
, NULL
);
2491 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2493 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2494 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2495 struct device_attribute
*attr
,
2498 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2501 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2502 struct device_attribute
*attr
,
2503 const char *buf
, size_t count
)
2509 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2510 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2513 if (mutex_lock_killable(&hotkey_mutex
))
2514 return -ERESTARTSYS
;
2516 HOTKEY_CONFIG_CRITICAL_START
2517 hotkey_source_mask
= t
;
2518 HOTKEY_CONFIG_CRITICAL_END
2520 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2521 ~hotkey_source_mask
);
2522 hotkey_poll_setup(true);
2524 /* check if events needed by the driver got disabled */
2525 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2526 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2528 mutex_unlock(&hotkey_mutex
);
2531 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2532 "firmware event mask!\n");
2535 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2536 "some important events were disabled: "
2539 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2541 return (rc
< 0) ? rc
: count
;
2544 static struct device_attribute dev_attr_hotkey_source_mask
=
2545 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2546 hotkey_source_mask_show
, hotkey_source_mask_store
);
2548 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2549 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2550 struct device_attribute
*attr
,
2553 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2556 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2557 struct device_attribute
*attr
,
2558 const char *buf
, size_t count
)
2562 if (parse_strtoul(buf
, 25, &t
))
2565 if (mutex_lock_killable(&hotkey_mutex
))
2566 return -ERESTARTSYS
;
2568 hotkey_poll_set_freq(t
);
2569 hotkey_poll_setup(true);
2571 mutex_unlock(&hotkey_mutex
);
2573 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2578 static struct device_attribute dev_attr_hotkey_poll_freq
=
2579 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2580 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2582 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2584 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2585 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2586 struct device_attribute
*attr
,
2590 res
= hotkey_get_wlsw(&s
);
2594 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2597 static struct device_attribute dev_attr_hotkey_radio_sw
=
2598 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2600 static void hotkey_radio_sw_notify_change(void)
2602 if (tp_features
.hotkey_wlsw
)
2603 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2607 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2608 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2609 struct device_attribute
*attr
,
2613 res
= hotkey_get_tablet_mode(&s
);
2617 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2620 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2621 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2623 static void hotkey_tablet_mode_notify_change(void)
2625 if (tp_features
.hotkey_tablet
)
2626 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2627 "hotkey_tablet_mode");
2630 /* sysfs hotkey report_mode -------------------------------------------- */
2631 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2632 struct device_attribute
*attr
,
2635 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2636 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2639 static struct device_attribute dev_attr_hotkey_report_mode
=
2640 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2642 /* sysfs wakeup reason (pollable) -------------------------------------- */
2643 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2644 struct device_attribute
*attr
,
2647 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2650 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2651 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2653 static void hotkey_wakeup_reason_notify_change(void)
2655 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2659 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2660 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2661 struct device_attribute
*attr
,
2664 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2667 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2668 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2669 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2671 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2673 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2674 "wakeup_hotunplug_complete");
2677 /* --------------------------------------------------------------------- */
2679 static struct attribute
*hotkey_attributes
[] __initdata
= {
2680 &dev_attr_hotkey_enable
.attr
,
2681 &dev_attr_hotkey_bios_enabled
.attr
,
2682 &dev_attr_hotkey_bios_mask
.attr
,
2683 &dev_attr_hotkey_report_mode
.attr
,
2684 &dev_attr_hotkey_wakeup_reason
.attr
,
2685 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2686 &dev_attr_hotkey_mask
.attr
,
2687 &dev_attr_hotkey_all_mask
.attr
,
2688 &dev_attr_hotkey_recommended_mask
.attr
,
2689 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2690 &dev_attr_hotkey_source_mask
.attr
,
2691 &dev_attr_hotkey_poll_freq
.attr
,
2695 static void bluetooth_update_rfk(void);
2696 static void wan_update_rfk(void);
2697 static void uwb_update_rfk(void);
2698 static void tpacpi_send_radiosw_update(void)
2702 /* Sync these BEFORE sending any rfkill events */
2703 if (tp_features
.bluetooth
)
2704 bluetooth_update_rfk();
2705 if (tp_features
.wan
)
2707 if (tp_features
.uwb
)
2710 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2711 mutex_lock(&tpacpi_inputdev_send_mutex
);
2713 input_report_switch(tpacpi_inputdev
,
2714 SW_RFKILL_ALL
, !!wlsw
);
2715 input_sync(tpacpi_inputdev
);
2717 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2719 hotkey_radio_sw_notify_change();
2722 static void hotkey_exit(void)
2724 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2725 mutex_lock(&hotkey_mutex
);
2726 hotkey_poll_stop_sync();
2727 mutex_unlock(&hotkey_mutex
);
2730 if (hotkey_dev_attributes
)
2731 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2733 kfree(hotkey_keycode_map
);
2735 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
2736 "restoring original HKEY status and mask\n");
2737 /* yes, there is a bitwise or below, we want the
2738 * functions to be called even if one of them fail */
2739 if (((tp_features
.hotkey_mask
&&
2740 hotkey_mask_set(hotkey_orig_mask
)) |
2741 hotkey_status_set(false)) != 0)
2743 "failed to restore hot key mask "
2744 "to BIOS defaults\n");
2747 static void __init
hotkey_unmap(const unsigned int scancode
)
2749 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
2750 clear_bit(hotkey_keycode_map
[scancode
],
2751 tpacpi_inputdev
->keybit
);
2752 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
2758 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
2761 #define TPACPI_HK_Q_INIMASK 0x0001
2763 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
2764 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
2765 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
2766 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
2767 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
2768 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
2769 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
2770 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
2771 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
2772 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
2773 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
2774 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
2775 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
2776 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
2777 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
2778 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
2779 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
2780 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
2781 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
2782 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
2785 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2787 /* Requirements for changing the default keymaps:
2789 * 1. Many of the keys are mapped to KEY_RESERVED for very
2790 * good reasons. Do not change them unless you have deep
2791 * knowledge on the IBM and Lenovo ThinkPad firmware for
2792 * the various ThinkPad models. The driver behaves
2793 * differently for KEY_RESERVED: such keys have their
2794 * hot key mask *unset* in mask_recommended, and also
2795 * in the initial hot key mask programmed into the
2796 * firmware at driver load time, which means the firm-
2797 * ware may react very differently if you change them to
2800 * 2. You must be subscribed to the linux-thinkpad and
2801 * ibm-acpi-devel mailing lists, and you should read the
2802 * list archives since 2007 if you want to change the
2803 * keymaps. This requirement exists so that you will
2804 * know the past history of problems with the thinkpad-
2805 * acpi driver keymaps, and also that you will be
2806 * listening to any bug reports;
2808 * 3. Do not send thinkpad-acpi specific patches directly to
2809 * for merging, *ever*. Send them to the linux-acpi
2810 * mailinglist for comments. Merging is to be done only
2811 * through acpi-test and the ACPI maintainer.
2813 * If the above is too much to ask, don't change the keymap.
2814 * Ask the thinkpad-acpi maintainer to do it, instead.
2816 static u16 ibm_keycode_map
[] __initdata
= {
2817 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2818 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2819 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2820 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2822 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2823 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2824 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2825 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2827 /* brightness: firmware always reacts to them */
2828 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2829 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2831 /* Thinklight: firmware always react to it */
2832 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2834 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2835 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2837 /* Volume: firmware always react to it and reprograms
2838 * the built-in *extra* mixer. Never map it to control
2839 * another mixer by default. */
2840 KEY_RESERVED
, /* 0x14: VOLUME UP */
2841 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2842 KEY_RESERVED
, /* 0x16: MUTE */
2844 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2846 /* (assignments unknown, please report if found) */
2847 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2848 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2850 static u16 lenovo_keycode_map
[] __initdata
= {
2851 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2852 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2853 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2854 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2856 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2857 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2858 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2859 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2861 /* These should be enabled --only-- when ACPI video
2862 * is disabled (i.e. in "vendor" mode), and are handled
2863 * in a special way by the init code */
2864 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
2865 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
2867 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2869 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2870 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2872 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2873 * react to it and reprograms the built-in *extra* mixer.
2874 * Never map it to control another mixer by default.
2876 * T60?, T61, R60?, R61: firmware and EC tries to send
2877 * these over the regular keyboard, so these are no-ops,
2878 * but there are still weird bugs re. MUTE, so do not
2879 * change unless you get test reports from all Lenovo
2880 * models. May cause the BIOS to interfere with the
2883 KEY_RESERVED
, /* 0x14: VOLUME UP */
2884 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2885 KEY_RESERVED
, /* 0x16: MUTE */
2887 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2889 /* (assignments unknown, please report if found) */
2890 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2891 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2894 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2895 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2896 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2901 bool radiosw_state
= false;
2902 bool tabletsw_state
= false;
2904 unsigned long quirks
;
2906 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2907 "initializing hotkey subdriver\n");
2909 BUG_ON(!tpacpi_inputdev
);
2910 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2911 tpacpi_inputdev
->close
!= NULL
);
2913 TPACPI_ACPIHANDLE_INIT(hkey
);
2914 mutex_init(&hotkey_mutex
);
2916 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2917 mutex_init(&hotkey_thread_mutex
);
2918 mutex_init(&hotkey_thread_data_mutex
);
2921 /* hotkey not supported on 570 */
2922 tp_features
.hotkey
= hkey_handle
!= NULL
;
2924 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2926 str_supported(tp_features
.hotkey
));
2928 if (!tp_features
.hotkey
)
2931 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
2932 ARRAY_SIZE(tpacpi_hotkey_qtable
));
2934 tpacpi_disable_brightness_delay();
2936 /* MUST have enough space for all attributes to be added to
2937 * hotkey_dev_attributes */
2938 hotkey_dev_attributes
= create_attr_set(
2939 ARRAY_SIZE(hotkey_attributes
) + 2,
2941 if (!hotkey_dev_attributes
)
2943 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2945 ARRAY_SIZE(hotkey_attributes
));
2949 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
2950 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2951 for HKEY interface version 0x100 */
2952 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2953 if ((hkeyv
>> 8) != 1) {
2954 printk(TPACPI_ERR
"unknown version of the "
2955 "HKEY interface: 0x%x\n", hkeyv
);
2956 printk(TPACPI_ERR
"please report this to %s\n",
2960 * MHKV 0x100 in A31, R40, R40e,
2961 * T4x, X31, and later
2963 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2964 "firmware HKEY interface version: 0x%x\n",
2967 /* Paranoia check AND init hotkey_all_mask */
2968 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2971 "missing MHKA handler, "
2972 "please report this to %s\n",
2974 /* Fallback: pre-init for FN+F3,F4,F12 */
2975 hotkey_all_mask
= 0x080cU
;
2977 tp_features
.hotkey_mask
= 1;
2982 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2983 "hotkey masks are %s\n",
2984 str_supported(tp_features
.hotkey_mask
));
2986 /* Init hotkey_all_mask if not initialized yet */
2987 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
2988 (quirks
& TPACPI_HK_Q_INIMASK
))
2989 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
2991 /* Init hotkey_acpi_mask and hotkey_orig_mask */
2992 if (tp_features
.hotkey_mask
) {
2993 /* hotkey_source_mask *must* be zero for
2994 * the first hotkey_mask_get to return hotkey_orig_mask */
2995 res
= hotkey_mask_get();
2999 hotkey_orig_mask
= hotkey_acpi_mask
;
3001 hotkey_orig_mask
= hotkey_all_mask
;
3002 hotkey_acpi_mask
= hotkey_all_mask
;
3005 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3007 tp_features
.hotkey_wlsw
= 1;
3008 radiosw_state
= !!tpacpi_wlsw_emulstate
;
3010 "radio switch emulation enabled\n");
3013 /* Not all thinkpads have a hardware radio switch */
3014 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3015 tp_features
.hotkey_wlsw
= 1;
3016 radiosw_state
= !!status
;
3018 "radio switch found; radios are %s\n",
3019 enabled(status
, 0));
3021 if (tp_features
.hotkey_wlsw
)
3022 res
= add_to_attr_set(hotkey_dev_attributes
,
3023 &dev_attr_hotkey_radio_sw
.attr
);
3025 /* For X41t, X60t, X61t Tablets... */
3026 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3027 tp_features
.hotkey_tablet
= 1;
3028 tabletsw_state
= !!(status
& TP_HOTKEY_TABLET_MASK
);
3030 "possible tablet mode switch found; "
3031 "ThinkPad in %s mode\n",
3032 (tabletsw_state
) ? "tablet" : "laptop");
3033 res
= add_to_attr_set(hotkey_dev_attributes
,
3034 &dev_attr_hotkey_tablet_mode
.attr
);
3038 res
= register_attr_set_with_sysfs(
3039 hotkey_dev_attributes
,
3040 &tpacpi_pdev
->dev
.kobj
);
3044 /* Set up key map */
3046 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3048 if (!hotkey_keycode_map
) {
3050 "failed to allocate memory for key map\n");
3055 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
3056 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3057 "using Lenovo default hot key map\n");
3058 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
3059 TPACPI_HOTKEY_MAP_SIZE
);
3061 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3062 "using IBM default hot key map\n");
3063 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
3064 TPACPI_HOTKEY_MAP_SIZE
);
3067 input_set_capability(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
);
3068 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3069 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3070 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3071 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3072 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3073 input_set_capability(tpacpi_inputdev
, EV_KEY
,
3074 hotkey_keycode_map
[i
]);
3076 if (i
< sizeof(hotkey_reserved_mask
)*8)
3077 hotkey_reserved_mask
|= 1 << i
;
3081 if (tp_features
.hotkey_wlsw
) {
3082 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_RFKILL_ALL
);
3083 input_report_switch(tpacpi_inputdev
,
3084 SW_RFKILL_ALL
, radiosw_state
);
3086 if (tp_features
.hotkey_tablet
) {
3087 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_TABLET_MODE
);
3088 input_report_switch(tpacpi_inputdev
,
3089 SW_TABLET_MODE
, tabletsw_state
);
3092 /* Do not issue duplicate brightness change events to
3094 if (!tp_features
.bright_acpimode
)
3095 /* update bright_acpimode... */
3096 tpacpi_check_std_acpi_brightness_support();
3098 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
3100 "This ThinkPad has standard ACPI backlight "
3101 "brightness control, supported by the ACPI "
3103 printk(TPACPI_NOTICE
3104 "Disabling thinkpad-acpi brightness events "
3107 /* Disable brightness up/down on Lenovo thinkpads when
3108 * ACPI is handling them, otherwise it is plain impossible
3109 * for userspace to do something even remotely sane */
3110 hotkey_reserved_mask
|=
3111 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3112 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3113 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3114 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3117 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3118 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3120 & ~hotkey_reserved_mask
;
3122 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3123 "hotkey source mask 0x%08x, polling freq %u\n",
3124 hotkey_source_mask
, hotkey_poll_freq
);
3127 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3128 "enabling firmware HKEY event interface...\n");
3129 res
= hotkey_status_set(true);
3134 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3135 | hotkey_driver_mask
)
3136 & ~hotkey_source_mask
);
3137 if (res
< 0 && res
!= -ENXIO
) {
3141 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3142 & ~hotkey_reserved_mask
;
3143 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3144 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3145 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3147 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3148 "legacy ibm/hotkey event reporting over procfs %s\n",
3149 (hotkey_report_mode
< 2) ?
3150 "enabled" : "disabled");
3152 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3153 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3155 hotkey_poll_setup_safe(true);
3160 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3161 hotkey_dev_attributes
= NULL
;
3163 return (res
< 0)? res
: 1;
3166 static bool hotkey_notify_hotkey(const u32 hkey
,
3168 bool *ignore_acpi_ev
)
3170 /* 0x1000-0x1FFF: key presses */
3171 unsigned int scancode
= hkey
& 0xfff;
3172 *send_acpi_ev
= true;
3173 *ignore_acpi_ev
= false;
3175 if (scancode
> 0 && scancode
< 0x21) {
3177 if (!(hotkey_source_mask
& (1 << scancode
))) {
3178 tpacpi_input_send_key_masked(scancode
);
3179 *send_acpi_ev
= false;
3181 *ignore_acpi_ev
= true;
3188 static bool hotkey_notify_wakeup(const u32 hkey
,
3190 bool *ignore_acpi_ev
)
3192 /* 0x2000-0x2FFF: Wakeup reason */
3193 *send_acpi_ev
= true;
3194 *ignore_acpi_ev
= false;
3197 case TP_HKEY_EV_WKUP_S3_UNDOCK
: /* suspend, undock */
3198 case TP_HKEY_EV_WKUP_S4_UNDOCK
: /* hibernation, undock */
3199 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3200 *ignore_acpi_ev
= true;
3203 case TP_HKEY_EV_WKUP_S3_BAYEJ
: /* suspend, bay eject */
3204 case TP_HKEY_EV_WKUP_S4_BAYEJ
: /* hibernation, bay eject */
3205 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3206 *ignore_acpi_ev
= true;
3209 case TP_HKEY_EV_WKUP_S3_BATLOW
: /* Battery on critical low level/S3 */
3210 case TP_HKEY_EV_WKUP_S4_BATLOW
: /* Battery on critical low level/S4 */
3212 "EMERGENCY WAKEUP: battery almost empty\n");
3213 /* how to auto-heal: */
3214 /* 2313: woke up from S3, go to S4/S5 */
3215 /* 2413: woke up from S4, go to S5 */
3222 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3224 "woke up due to a hot-unplug "
3226 hotkey_wakeup_reason_notify_change();
3231 static bool hotkey_notify_usrevent(const u32 hkey
,
3233 bool *ignore_acpi_ev
)
3235 /* 0x5000-0x5FFF: human interface helpers */
3236 *send_acpi_ev
= true;
3237 *ignore_acpi_ev
= false;
3240 case TP_HKEY_EV_PEN_INSERTED
: /* X61t: tablet pen inserted into bay */
3241 case TP_HKEY_EV_PEN_REMOVED
: /* X61t: tablet pen removed from bay */
3244 case TP_HKEY_EV_TABLET_TABLET
: /* X41t-X61t: tablet mode */
3245 case TP_HKEY_EV_TABLET_NOTEBOOK
: /* X41t-X61t: normal mode */
3246 tpacpi_input_send_tabletsw();
3247 hotkey_tablet_mode_notify_change();
3248 *send_acpi_ev
= false;
3251 case TP_HKEY_EV_LID_CLOSE
: /* Lid closed */
3252 case TP_HKEY_EV_LID_OPEN
: /* Lid opened */
3253 case TP_HKEY_EV_BRGHT_CHANGED
: /* brightness changed */
3254 /* do not propagate these events */
3255 *ignore_acpi_ev
= true;
3263 static void thermal_dump_all_sensors(void);
3265 static bool hotkey_notify_thermal(const u32 hkey
,
3267 bool *ignore_acpi_ev
)
3271 /* 0x6000-0x6FFF: thermal alarms */
3272 *send_acpi_ev
= true;
3273 *ignore_acpi_ev
= false;
3276 case TP_HKEY_EV_THM_TABLE_CHANGED
:
3278 "EC reports that Thermal Table has changed\n");
3279 /* recommended action: do nothing, we don't have
3280 * Lenovo ATM information */
3282 case TP_HKEY_EV_ALARM_BAT_HOT
:
3284 "THERMAL ALARM: battery is too hot!\n");
3285 /* recommended action: warn user through gui */
3287 case TP_HKEY_EV_ALARM_BAT_XHOT
:
3289 "THERMAL EMERGENCY: battery is extremely hot!\n");
3290 /* recommended action: immediate sleep/hibernate */
3292 case TP_HKEY_EV_ALARM_SENSOR_HOT
:
3295 "a sensor reports something is too hot!\n");
3296 /* recommended action: warn user through gui, that */
3297 /* some internal component is too hot */
3299 case TP_HKEY_EV_ALARM_SENSOR_XHOT
:
3301 "THERMAL EMERGENCY: "
3302 "a sensor reports something is extremely hot!\n");
3303 /* recommended action: immediate sleep/hibernate */
3307 "THERMAL ALERT: unknown thermal alarm received\n");
3311 thermal_dump_all_sensors();
3316 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3320 bool ignore_acpi_ev
;
3323 if (event
!= 0x80) {
3325 "unknown HKEY notification event %d\n", event
);
3326 /* forward it to userspace, maybe it knows how to handle it */
3327 acpi_bus_generate_netlink_event(
3328 ibm
->acpi
->device
->pnp
.device_class
,
3329 dev_name(&ibm
->acpi
->device
->dev
),
3335 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3336 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3345 send_acpi_ev
= true;
3346 ignore_acpi_ev
= false;
3348 switch (hkey
>> 12) {
3350 /* 0x1000-0x1FFF: key presses */
3351 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3355 /* 0x2000-0x2FFF: Wakeup reason */
3356 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3360 /* 0x3000-0x3FFF: bay-related wakeups */
3362 case TP_HKEY_EV_BAYEJ_ACK
:
3363 hotkey_autosleep_ack
= 1;
3366 hotkey_wakeup_hotunplug_complete_notify_change();
3369 case TP_HKEY_EV_OPTDRV_EJ
:
3370 /* FIXME: kick libata if SATA link offline */
3378 /* 0x4000-0x4FFF: dock-related wakeups */
3379 if (hkey
== TP_HKEY_EV_UNDOCK_ACK
) {
3380 hotkey_autosleep_ack
= 1;
3383 hotkey_wakeup_hotunplug_complete_notify_change();
3390 /* 0x5000-0x5FFF: human interface helpers */
3391 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3395 /* 0x6000-0x6FFF: thermal alarms */
3396 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3400 /* 0x7000-0x7FFF: misc */
3401 if (tp_features
.hotkey_wlsw
&&
3402 hkey
== TP_HKEY_EV_RFKILL_CHANGED
) {
3403 tpacpi_send_radiosw_update();
3408 /* fallthrough to default */
3413 printk(TPACPI_NOTICE
3414 "unhandled HKEY event 0x%04x\n", hkey
);
3415 printk(TPACPI_NOTICE
3416 "please report the conditions when this "
3417 "event happened to %s\n", TPACPI_MAIL
);
3421 if (!ignore_acpi_ev
&&
3422 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3423 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3427 /* netlink events */
3428 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3429 acpi_bus_generate_netlink_event(
3430 ibm
->acpi
->device
->pnp
.device_class
,
3431 dev_name(&ibm
->acpi
->device
->dev
),
3437 static void hotkey_suspend(pm_message_t state
)
3439 /* Do these on suspend, we get the events on early resume! */
3440 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3441 hotkey_autosleep_ack
= 0;
3444 static void hotkey_resume(void)
3446 tpacpi_disable_brightness_delay();
3448 if (hotkey_status_set(true) < 0 ||
3449 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3451 "error while attempting to reset the event "
3452 "firmware interface\n");
3454 tpacpi_send_radiosw_update();
3455 hotkey_tablet_mode_notify_change();
3456 hotkey_wakeup_reason_notify_change();
3457 hotkey_wakeup_hotunplug_complete_notify_change();
3458 hotkey_poll_setup_safe(false);
3461 /* procfs -------------------------------------------------------------- */
3462 static int hotkey_read(struct seq_file
*m
)
3466 if (!tp_features
.hotkey
) {
3467 seq_printf(m
, "status:\t\tnot supported\n");
3471 if (mutex_lock_killable(&hotkey_mutex
))
3472 return -ERESTARTSYS
;
3473 res
= hotkey_status_get(&status
);
3475 res
= hotkey_mask_get();
3476 mutex_unlock(&hotkey_mutex
);
3480 seq_printf(m
, "status:\t\t%s\n", enabled(status
, 0));
3481 if (hotkey_all_mask
) {
3482 seq_printf(m
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3483 seq_printf(m
, "commands:\tenable, disable, reset, <mask>\n");
3485 seq_printf(m
, "mask:\t\tnot supported\n");
3486 seq_printf(m
, "commands:\tenable, disable, reset\n");
3492 static void hotkey_enabledisable_warn(bool enable
)
3494 tpacpi_log_usertask("procfs hotkey enable/disable");
3495 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3497 "hotkey enable/disable functionality has been "
3498 "removed from the driver. Hotkeys are always "
3501 "Please remove the hotkey=enable module "
3502 "parameter, it is deprecated. Hotkeys are always "
3506 static int hotkey_write(char *buf
)
3512 if (!tp_features
.hotkey
)
3515 if (mutex_lock_killable(&hotkey_mutex
))
3516 return -ERESTARTSYS
;
3518 mask
= hotkey_user_mask
;
3521 while ((cmd
= next_cmd(&buf
))) {
3522 if (strlencmp(cmd
, "enable") == 0) {
3523 hotkey_enabledisable_warn(1);
3524 } else if (strlencmp(cmd
, "disable") == 0) {
3525 hotkey_enabledisable_warn(0);
3527 } else if (strlencmp(cmd
, "reset") == 0) {
3528 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3529 & ~hotkey_reserved_mask
;
3530 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3532 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3541 tpacpi_disclose_usertask("procfs hotkey",
3542 "set mask to 0x%08x\n", mask
);
3543 res
= hotkey_user_mask_set(mask
);
3547 mutex_unlock(&hotkey_mutex
);
3551 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3552 {TPACPI_ACPI_HKEY_HID
, 0},
3556 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3557 .hid
= ibm_htk_device_ids
,
3558 .notify
= hotkey_notify
,
3559 .handle
= &hkey_handle
,
3560 .type
= ACPI_DEVICE_NOTIFY
,
3563 static struct ibm_struct hotkey_driver_data
= {
3565 .read
= hotkey_read
,
3566 .write
= hotkey_write
,
3567 .exit
= hotkey_exit
,
3568 .resume
= hotkey_resume
,
3569 .suspend
= hotkey_suspend
,
3570 .acpi
= &ibm_hotkey_acpidriver
,
3573 /*************************************************************************
3574 * Bluetooth subdriver
3578 /* ACPI GBDC/SBDC bits */
3579 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3580 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3581 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3586 /* ACPI \BLTH commands */
3587 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3588 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3589 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3590 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3591 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3594 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3596 static struct rfkill
*tpacpi_bluetooth_rfkill
;
3598 static void bluetooth_suspend(pm_message_t state
)
3600 /* Try to make sure radio will resume powered off */
3601 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3602 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
))
3603 vdbg_printk(TPACPI_DBG_RFKILL
,
3604 "bluetooth power down on resume request failed\n");
3607 static int bluetooth_get_radiosw(void)
3611 if (!tp_features
.bluetooth
)
3614 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
3615 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3616 return RFKILL_STATE_HARD_BLOCKED
;
3618 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3619 if (dbg_bluetoothemul
)
3620 return (tpacpi_bluetooth_emulstate
) ?
3621 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3624 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3627 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3628 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3631 static void bluetooth_update_rfk(void)
3635 if (!tpacpi_bluetooth_rfkill
)
3638 status
= bluetooth_get_radiosw();
3641 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
3643 vdbg_printk(TPACPI_DBG_RFKILL
,
3644 "forced rfkill state to %d\n",
3648 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
3652 if (!tp_features
.bluetooth
)
3655 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3656 * reason to risk weird behaviour. */
3657 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3661 vdbg_printk(TPACPI_DBG_RFKILL
,
3662 "will %s bluetooth\n", radio_on
? "enable" : "disable");
3664 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3665 if (dbg_bluetoothemul
) {
3666 tpacpi_bluetooth_emulstate
= !!radio_on
;
3668 bluetooth_update_rfk();
3673 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3675 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
3678 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3682 bluetooth_update_rfk();
3687 /* sysfs bluetooth enable ---------------------------------------------- */
3688 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3689 struct device_attribute
*attr
,
3694 printk_deprecated_rfkill_attribute("bluetooth_enable");
3696 status
= bluetooth_get_radiosw();
3700 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3701 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3704 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3705 struct device_attribute
*attr
,
3706 const char *buf
, size_t count
)
3711 printk_deprecated_rfkill_attribute("bluetooth_enable");
3713 if (parse_strtoul(buf
, 1, &t
))
3716 tpacpi_disclose_usertask("bluetooth_enable", "set to %ld\n", t
);
3718 res
= bluetooth_set_radiosw(t
, 1);
3720 return (res
) ? res
: count
;
3723 static struct device_attribute dev_attr_bluetooth_enable
=
3724 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3725 bluetooth_enable_show
, bluetooth_enable_store
);
3727 /* --------------------------------------------------------------------- */
3729 static struct attribute
*bluetooth_attributes
[] = {
3730 &dev_attr_bluetooth_enable
.attr
,
3734 static const struct attribute_group bluetooth_attr_group
= {
3735 .attrs
= bluetooth_attributes
,
3738 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
3740 int bts
= bluetooth_get_radiosw();
3749 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
3751 dbg_printk(TPACPI_DBG_RFKILL
,
3752 "request to change radio state to %d\n", state
);
3753 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3756 static void bluetooth_shutdown(void)
3758 /* Order firmware to save current state to NVRAM */
3759 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3760 TP_ACPI_BLTH_SAVE_STATE
))
3761 printk(TPACPI_NOTICE
3762 "failed to save bluetooth state to NVRAM\n");
3764 vdbg_printk(TPACPI_DBG_RFKILL
,
3765 "bluestooth state saved to NVRAM\n");
3768 static void bluetooth_exit(void)
3770 bluetooth_shutdown();
3772 if (tpacpi_bluetooth_rfkill
)
3773 rfkill_unregister(tpacpi_bluetooth_rfkill
);
3775 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3776 &bluetooth_attr_group
);
3779 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3784 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3785 "initializing bluetooth subdriver\n");
3787 TPACPI_ACPIHANDLE_INIT(hkey
);
3789 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3790 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3791 tp_features
.bluetooth
= hkey_handle
&&
3792 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3794 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3795 "bluetooth is %s, status 0x%02x\n",
3796 str_supported(tp_features
.bluetooth
),
3799 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3800 if (dbg_bluetoothemul
) {
3801 tp_features
.bluetooth
= 1;
3803 "bluetooth switch emulation enabled\n");
3806 if (tp_features
.bluetooth
&&
3807 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
3808 /* no bluetooth hardware present in system */
3809 tp_features
.bluetooth
= 0;
3810 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3811 "bluetooth hardware not installed\n");
3814 if (!tp_features
.bluetooth
)
3817 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3818 &bluetooth_attr_group
);
3822 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3823 &tpacpi_bluetooth_rfkill
,
3824 RFKILL_TYPE_BLUETOOTH
,
3825 TPACPI_RFK_BLUETOOTH_SW_NAME
,
3827 tpacpi_bluetooth_rfk_set
,
3828 tpacpi_bluetooth_rfk_get
);
3837 /* procfs -------------------------------------------------------------- */
3838 static int bluetooth_read(struct seq_file
*m
)
3840 int status
= bluetooth_get_radiosw();
3842 if (!tp_features
.bluetooth
)
3843 seq_printf(m
, "status:\t\tnot supported\n");
3845 seq_printf(m
, "status:\t\t%s\n",
3846 (status
== RFKILL_STATE_UNBLOCKED
) ?
3847 "enabled" : "disabled");
3848 seq_printf(m
, "commands:\tenable, disable\n");
3854 static int bluetooth_write(char *buf
)
3859 if (!tp_features
.bluetooth
)
3862 while ((cmd
= next_cmd(&buf
))) {
3863 if (strlencmp(cmd
, "enable") == 0) {
3865 } else if (strlencmp(cmd
, "disable") == 0) {
3872 tpacpi_disclose_usertask("procfs bluetooth",
3874 state
? "enable" : "disable");
3875 bluetooth_set_radiosw(state
, 1);
3881 static struct ibm_struct bluetooth_driver_data
= {
3882 .name
= "bluetooth",
3883 .read
= bluetooth_read
,
3884 .write
= bluetooth_write
,
3885 .exit
= bluetooth_exit
,
3886 .suspend
= bluetooth_suspend
,
3887 .shutdown
= bluetooth_shutdown
,
3890 /*************************************************************************
3895 /* ACPI GWAN/SWAN bits */
3896 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3897 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3898 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3902 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
3904 static struct rfkill
*tpacpi_wan_rfkill
;
3906 static void wan_suspend(pm_message_t state
)
3908 /* Try to make sure radio will resume powered off */
3909 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3910 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
))
3911 vdbg_printk(TPACPI_DBG_RFKILL
,
3912 "WWAN power down on resume request failed\n");
3915 static int wan_get_radiosw(void)
3919 if (!tp_features
.wan
)
3922 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3923 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3924 return RFKILL_STATE_HARD_BLOCKED
;
3926 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3928 return (tpacpi_wwan_emulstate
) ?
3929 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3932 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3935 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3936 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3939 static void wan_update_rfk(void)
3943 if (!tpacpi_wan_rfkill
)
3946 status
= wan_get_radiosw();
3949 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3951 vdbg_printk(TPACPI_DBG_RFKILL
,
3952 "forced rfkill state to %d\n",
3956 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3960 if (!tp_features
.wan
)
3963 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3964 * reason to risk weird behaviour. */
3965 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3969 vdbg_printk(TPACPI_DBG_RFKILL
,
3970 "will %s WWAN\n", radio_on
? "enable" : "disable");
3972 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3974 tpacpi_wwan_emulstate
= !!radio_on
;
3981 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3983 status
= TP_ACPI_WANCARD_RADIOSSW
;
3986 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3995 /* sysfs wan enable ---------------------------------------------------- */
3996 static ssize_t
wan_enable_show(struct device
*dev
,
3997 struct device_attribute
*attr
,
4002 printk_deprecated_rfkill_attribute("wwan_enable");
4004 status
= wan_get_radiosw();
4008 return snprintf(buf
, PAGE_SIZE
, "%d\n",
4009 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
4012 static ssize_t
wan_enable_store(struct device
*dev
,
4013 struct device_attribute
*attr
,
4014 const char *buf
, size_t count
)
4019 printk_deprecated_rfkill_attribute("wwan_enable");
4021 if (parse_strtoul(buf
, 1, &t
))
4024 tpacpi_disclose_usertask("wwan_enable", "set to %ld\n", t
);
4026 res
= wan_set_radiosw(t
, 1);
4028 return (res
) ? res
: count
;
4031 static struct device_attribute dev_attr_wan_enable
=
4032 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4033 wan_enable_show
, wan_enable_store
);
4035 /* --------------------------------------------------------------------- */
4037 static struct attribute
*wan_attributes
[] = {
4038 &dev_attr_wan_enable
.attr
,
4042 static const struct attribute_group wan_attr_group
= {
4043 .attrs
= wan_attributes
,
4046 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
4048 int wans
= wan_get_radiosw();
4057 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
4059 dbg_printk(TPACPI_DBG_RFKILL
,
4060 "request to change radio state to %d\n", state
);
4061 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
4064 static void wan_shutdown(void)
4066 /* Order firmware to save current state to NVRAM */
4067 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4068 TP_ACPI_WGSV_SAVE_STATE
))
4069 printk(TPACPI_NOTICE
4070 "failed to save WWAN state to NVRAM\n");
4072 vdbg_printk(TPACPI_DBG_RFKILL
,
4073 "WWAN state saved to NVRAM\n");
4076 static void wan_exit(void)
4080 if (tpacpi_wan_rfkill
)
4081 rfkill_unregister(tpacpi_wan_rfkill
);
4083 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4087 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4092 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4093 "initializing wan subdriver\n");
4095 TPACPI_ACPIHANDLE_INIT(hkey
);
4097 tp_features
.wan
= hkey_handle
&&
4098 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4100 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4101 "wan is %s, status 0x%02x\n",
4102 str_supported(tp_features
.wan
),
4105 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4107 tp_features
.wan
= 1;
4109 "wwan switch emulation enabled\n");
4112 if (tp_features
.wan
&&
4113 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4114 /* no wan hardware present in system */
4115 tp_features
.wan
= 0;
4116 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4117 "wan hardware not installed\n");
4120 if (!tp_features
.wan
)
4123 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4128 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4131 TPACPI_RFK_WWAN_SW_NAME
,
4134 tpacpi_wan_rfk_get
);
4143 /* procfs -------------------------------------------------------------- */
4144 static int wan_read(struct seq_file
*m
)
4146 int status
= wan_get_radiosw();
4148 tpacpi_disclose_usertask("procfs wan", "read");
4150 if (!tp_features
.wan
)
4151 seq_printf(m
, "status:\t\tnot supported\n");
4153 seq_printf(m
, "status:\t\t%s\n",
4154 (status
== RFKILL_STATE_UNBLOCKED
) ?
4155 "enabled" : "disabled");
4156 seq_printf(m
, "commands:\tenable, disable\n");
4162 static int wan_write(char *buf
)
4167 if (!tp_features
.wan
)
4170 while ((cmd
= next_cmd(&buf
))) {
4171 if (strlencmp(cmd
, "enable") == 0) {
4173 } else if (strlencmp(cmd
, "disable") == 0) {
4180 tpacpi_disclose_usertask("procfs wan",
4182 state
? "enable" : "disable");
4183 wan_set_radiosw(state
, 1);
4189 static struct ibm_struct wan_driver_data
= {
4194 .suspend
= wan_suspend
,
4195 .shutdown
= wan_shutdown
,
4198 /*************************************************************************
4203 /* ACPI GUWB/SUWB bits */
4204 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4205 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4208 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4210 static struct rfkill
*tpacpi_uwb_rfkill
;
4212 static int uwb_get_radiosw(void)
4216 if (!tp_features
.uwb
)
4219 /* WLSW overrides UWB in firmware/hardware, reflect that */
4220 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
4221 return RFKILL_STATE_HARD_BLOCKED
;
4223 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4225 return (tpacpi_uwb_emulstate
) ?
4226 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
4229 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4232 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4233 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
4236 static void uwb_update_rfk(void)
4240 if (!tpacpi_uwb_rfkill
)
4243 status
= uwb_get_radiosw();
4246 rfkill_force_state(tpacpi_uwb_rfkill
, status
);
4248 vdbg_printk(TPACPI_DBG_RFKILL
,
4249 "forced rfkill state to %d\n",
4253 static int uwb_set_radiosw(int radio_on
, int update_rfk
)
4257 if (!tp_features
.uwb
)
4260 /* WLSW overrides UWB in firmware/hardware, but there is no
4261 * reason to risk weird behaviour. */
4262 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
4266 vdbg_printk(TPACPI_DBG_RFKILL
,
4267 "will %s UWB\n", radio_on
? "enable" : "disable");
4269 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4271 tpacpi_uwb_emulstate
= !!radio_on
;
4278 status
= (radio_on
) ? TP_ACPI_UWB_RADIOSSW
: 0;
4279 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4288 /* --------------------------------------------------------------------- */
4290 static int tpacpi_uwb_rfk_get(void *data
, enum rfkill_state
*state
)
4292 int uwbs
= uwb_get_radiosw();
4301 static int tpacpi_uwb_rfk_set(void *data
, enum rfkill_state state
)
4303 dbg_printk(TPACPI_DBG_RFKILL
,
4304 "request to change radio state to %d\n", state
);
4305 return uwb_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
4308 static void uwb_exit(void)
4310 if (tpacpi_uwb_rfkill
)
4311 rfkill_unregister(tpacpi_uwb_rfkill
);
4314 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4319 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4320 "initializing uwb subdriver\n");
4322 TPACPI_ACPIHANDLE_INIT(hkey
);
4324 tp_features
.uwb
= hkey_handle
&&
4325 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4327 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4328 "uwb is %s, status 0x%02x\n",
4329 str_supported(tp_features
.uwb
),
4332 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4334 tp_features
.uwb
= 1;
4336 "uwb switch emulation enabled\n");
4339 if (tp_features
.uwb
&&
4340 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4341 /* no uwb hardware present in system */
4342 tp_features
.uwb
= 0;
4343 dbg_printk(TPACPI_DBG_INIT
,
4344 "uwb hardware not installed\n");
4347 if (!tp_features
.uwb
)
4350 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4353 TPACPI_RFK_UWB_SW_NAME
,
4356 tpacpi_uwb_rfk_get
);
4361 static struct ibm_struct uwb_driver_data
= {
4364 .flags
.experimental
= 1,
4367 /*************************************************************************
4371 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4373 enum video_access_mode
{
4374 TPACPI_VIDEO_NONE
= 0,
4375 TPACPI_VIDEO_570
, /* 570 */
4376 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4377 TPACPI_VIDEO_NEW
, /* all others */
4380 enum { /* video status flags, based on VIDEO_570 */
4381 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4382 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4383 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4386 enum { /* TPACPI_VIDEO_570 constants */
4387 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4388 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4389 * video_status_flags */
4390 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4391 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4394 static enum video_access_mode video_supported
;
4395 static int video_orig_autosw
;
4397 static int video_autosw_get(void);
4398 static int video_autosw_set(int enable
);
4400 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4402 static int __init
video_init(struct ibm_init_struct
*iibm
)
4406 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4408 TPACPI_ACPIHANDLE_INIT(vid
);
4409 TPACPI_ACPIHANDLE_INIT(vid2
);
4411 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4412 /* G41, assume IVGA doesn't change */
4413 vid_handle
= vid2_handle
;
4416 /* video switching not supported on R30, R31 */
4417 video_supported
= TPACPI_VIDEO_NONE
;
4418 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4420 video_supported
= TPACPI_VIDEO_570
;
4421 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4422 /* 600e/x, 770e, 770x */
4423 video_supported
= TPACPI_VIDEO_770
;
4426 video_supported
= TPACPI_VIDEO_NEW
;
4428 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4429 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4432 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4435 static void video_exit(void)
4437 dbg_printk(TPACPI_DBG_EXIT
,
4438 "restoring original video autoswitch mode\n");
4439 if (video_autosw_set(video_orig_autosw
))
4440 printk(TPACPI_ERR
"error while trying to restore original "
4441 "video autoswitch mode\n");
4444 static int video_outputsw_get(void)
4449 switch (video_supported
) {
4450 case TPACPI_VIDEO_570
:
4451 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4452 TP_ACPI_VIDEO_570_PHSCMD
))
4454 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4456 case TPACPI_VIDEO_770
:
4457 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4460 status
|= TP_ACPI_VIDEO_S_LCD
;
4461 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4464 status
|= TP_ACPI_VIDEO_S_CRT
;
4466 case TPACPI_VIDEO_NEW
:
4467 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4468 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4471 status
|= TP_ACPI_VIDEO_S_CRT
;
4473 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4474 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4477 status
|= TP_ACPI_VIDEO_S_LCD
;
4478 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4481 status
|= TP_ACPI_VIDEO_S_DVI
;
4490 static int video_outputsw_set(int status
)
4495 switch (video_supported
) {
4496 case TPACPI_VIDEO_570
:
4497 res
= acpi_evalf(NULL
, NULL
,
4498 "\\_SB.PHS2", "vdd",
4499 TP_ACPI_VIDEO_570_PHS2CMD
,
4500 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4502 case TPACPI_VIDEO_770
:
4503 autosw
= video_autosw_get();
4507 res
= video_autosw_set(1);
4510 res
= acpi_evalf(vid_handle
, NULL
,
4511 "ASWT", "vdd", status
* 0x100, 0);
4512 if (!autosw
&& video_autosw_set(autosw
)) {
4514 "video auto-switch left enabled due to error\n");
4518 case TPACPI_VIDEO_NEW
:
4519 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4520 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4526 return (res
)? 0 : -EIO
;
4529 static int video_autosw_get(void)
4533 switch (video_supported
) {
4534 case TPACPI_VIDEO_570
:
4535 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4538 case TPACPI_VIDEO_770
:
4539 case TPACPI_VIDEO_NEW
:
4540 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4550 static int video_autosw_set(int enable
)
4552 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4557 static int video_outputsw_cycle(void)
4559 int autosw
= video_autosw_get();
4565 switch (video_supported
) {
4566 case TPACPI_VIDEO_570
:
4567 res
= video_autosw_set(1);
4570 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4572 case TPACPI_VIDEO_770
:
4573 case TPACPI_VIDEO_NEW
:
4574 res
= video_autosw_set(1);
4577 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4582 if (!autosw
&& video_autosw_set(autosw
)) {
4584 "video auto-switch left enabled due to error\n");
4588 return (res
)? 0 : -EIO
;
4591 static int video_expand_toggle(void)
4593 switch (video_supported
) {
4594 case TPACPI_VIDEO_570
:
4595 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4597 case TPACPI_VIDEO_770
:
4598 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4600 case TPACPI_VIDEO_NEW
:
4601 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4609 static int video_read(struct seq_file
*m
)
4613 if (video_supported
== TPACPI_VIDEO_NONE
) {
4614 seq_printf(m
, "status:\t\tnot supported\n");
4618 status
= video_outputsw_get();
4622 autosw
= video_autosw_get();
4626 seq_printf(m
, "status:\t\tsupported\n");
4627 seq_printf(m
, "lcd:\t\t%s\n", enabled(status
, 0));
4628 seq_printf(m
, "crt:\t\t%s\n", enabled(status
, 1));
4629 if (video_supported
== TPACPI_VIDEO_NEW
)
4630 seq_printf(m
, "dvi:\t\t%s\n", enabled(status
, 3));
4631 seq_printf(m
, "auto:\t\t%s\n", enabled(autosw
, 0));
4632 seq_printf(m
, "commands:\tlcd_enable, lcd_disable\n");
4633 seq_printf(m
, "commands:\tcrt_enable, crt_disable\n");
4634 if (video_supported
== TPACPI_VIDEO_NEW
)
4635 seq_printf(m
, "commands:\tdvi_enable, dvi_disable\n");
4636 seq_printf(m
, "commands:\tauto_enable, auto_disable\n");
4637 seq_printf(m
, "commands:\tvideo_switch, expand_toggle\n");
4642 static int video_write(char *buf
)
4645 int enable
, disable
, status
;
4648 if (video_supported
== TPACPI_VIDEO_NONE
)
4654 while ((cmd
= next_cmd(&buf
))) {
4655 if (strlencmp(cmd
, "lcd_enable") == 0) {
4656 enable
|= TP_ACPI_VIDEO_S_LCD
;
4657 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4658 disable
|= TP_ACPI_VIDEO_S_LCD
;
4659 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4660 enable
|= TP_ACPI_VIDEO_S_CRT
;
4661 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4662 disable
|= TP_ACPI_VIDEO_S_CRT
;
4663 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4664 strlencmp(cmd
, "dvi_enable") == 0) {
4665 enable
|= TP_ACPI_VIDEO_S_DVI
;
4666 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4667 strlencmp(cmd
, "dvi_disable") == 0) {
4668 disable
|= TP_ACPI_VIDEO_S_DVI
;
4669 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4670 res
= video_autosw_set(1);
4673 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4674 res
= video_autosw_set(0);
4677 } else if (strlencmp(cmd
, "video_switch") == 0) {
4678 res
= video_outputsw_cycle();
4681 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4682 res
= video_expand_toggle();
4689 if (enable
|| disable
) {
4690 status
= video_outputsw_get();
4693 res
= video_outputsw_set((status
& ~disable
) | enable
);
4701 static struct ibm_struct video_driver_data
= {
4704 .write
= video_write
,
4708 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4710 /*************************************************************************
4711 * Light (thinklight) subdriver
4714 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4715 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4717 static int light_get_status(void)
4721 if (tp_features
.light_status
) {
4722 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4730 static int light_set_status(int status
)
4734 if (tp_features
.light
) {
4736 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4738 TP_CMOS_THINKLIGHT_ON
:
4739 TP_CMOS_THINKLIGHT_OFF
);
4741 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4744 return (rc
)? 0 : -EIO
;
4750 static void light_set_status_worker(struct work_struct
*work
)
4752 struct tpacpi_led_classdev
*data
=
4753 container_of(work
, struct tpacpi_led_classdev
, work
);
4755 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4756 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4759 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4760 enum led_brightness brightness
)
4762 struct tpacpi_led_classdev
*data
=
4763 container_of(led_cdev
,
4764 struct tpacpi_led_classdev
,
4766 data
->new_state
= (brightness
!= LED_OFF
) ?
4767 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4768 queue_work(tpacpi_wq
, &data
->work
);
4771 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4773 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4776 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4778 .name
= "tpacpi::thinklight",
4779 .brightness_set
= &light_sysfs_set
,
4780 .brightness_get
= &light_sysfs_get
,
4784 static int __init
light_init(struct ibm_init_struct
*iibm
)
4788 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4790 TPACPI_ACPIHANDLE_INIT(ledb
);
4791 TPACPI_ACPIHANDLE_INIT(lght
);
4792 TPACPI_ACPIHANDLE_INIT(cmos
);
4793 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4795 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4796 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4798 if (tp_features
.light
)
4799 /* light status not supported on
4800 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4801 tp_features
.light_status
=
4802 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4804 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4805 str_supported(tp_features
.light
),
4806 str_supported(tp_features
.light_status
));
4808 if (!tp_features
.light
)
4811 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4812 &tpacpi_led_thinklight
.led_classdev
);
4815 tp_features
.light
= 0;
4816 tp_features
.light_status
= 0;
4824 static void light_exit(void)
4826 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4827 if (work_pending(&tpacpi_led_thinklight
.work
))
4828 flush_workqueue(tpacpi_wq
);
4831 static int light_read(struct seq_file
*m
)
4835 if (!tp_features
.light
) {
4836 seq_printf(m
, "status:\t\tnot supported\n");
4837 } else if (!tp_features
.light_status
) {
4838 seq_printf(m
, "status:\t\tunknown\n");
4839 seq_printf(m
, "commands:\ton, off\n");
4841 status
= light_get_status();
4844 seq_printf(m
, "status:\t\t%s\n", onoff(status
, 0));
4845 seq_printf(m
, "commands:\ton, off\n");
4851 static int light_write(char *buf
)
4856 if (!tp_features
.light
)
4859 while ((cmd
= next_cmd(&buf
))) {
4860 if (strlencmp(cmd
, "on") == 0) {
4862 } else if (strlencmp(cmd
, "off") == 0) {
4868 return light_set_status(newstatus
);
4871 static struct ibm_struct light_driver_data
= {
4874 .write
= light_write
,
4878 /*************************************************************************
4882 /* sysfs cmos_command -------------------------------------------------- */
4883 static ssize_t
cmos_command_store(struct device
*dev
,
4884 struct device_attribute
*attr
,
4885 const char *buf
, size_t count
)
4887 unsigned long cmos_cmd
;
4890 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4893 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4894 return (res
)? res
: count
;
4897 static struct device_attribute dev_attr_cmos_command
=
4898 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4900 /* --------------------------------------------------------------------- */
4902 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4906 vdbg_printk(TPACPI_DBG_INIT
,
4907 "initializing cmos commands subdriver\n");
4909 TPACPI_ACPIHANDLE_INIT(cmos
);
4911 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4912 str_supported(cmos_handle
!= NULL
));
4914 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4918 return (cmos_handle
)? 0 : 1;
4921 static void cmos_exit(void)
4923 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4926 static int cmos_read(struct seq_file
*m
)
4928 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4929 R30, R31, T20-22, X20-21 */
4931 seq_printf(m
, "status:\t\tnot supported\n");
4933 seq_printf(m
, "status:\t\tsupported\n");
4934 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4940 static int cmos_write(char *buf
)
4945 while ((cmd
= next_cmd(&buf
))) {
4946 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4947 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4952 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4960 static struct ibm_struct cmos_driver_data
= {
4963 .write
= cmos_write
,
4967 /*************************************************************************
4971 enum led_access_mode
{
4972 TPACPI_LED_NONE
= 0,
4973 TPACPI_LED_570
, /* 570 */
4974 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4975 TPACPI_LED_NEW
, /* all others */
4978 enum { /* For TPACPI_LED_OLD */
4979 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4980 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4981 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4984 static enum led_access_mode led_supported
;
4986 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4987 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4988 /* T20-22, X20-21 */
4989 "LED", /* all others */
4992 #define TPACPI_LED_NUMLEDS 16
4993 static struct tpacpi_led_classdev
*tpacpi_leds
;
4994 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4995 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4996 /* there's a limit of 19 chars + NULL before 2.6.26 */
4998 "tpacpi:orange:batt",
4999 "tpacpi:green:batt",
5000 "tpacpi::dock_active",
5001 "tpacpi::bay_active",
5002 "tpacpi::dock_batt",
5003 "tpacpi::unknown_led",
5005 "tpacpi::dock_status1",
5006 "tpacpi::dock_status2",
5007 "tpacpi::unknown_led2",
5008 "tpacpi::unknown_led3",
5009 "tpacpi::thinkvantage",
5011 #define TPACPI_SAFE_LEDS 0x1081U
5013 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
5015 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5018 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
5022 static int led_get_status(const unsigned int led
)
5025 enum led_status_t led_s
;
5027 switch (led_supported
) {
5028 case TPACPI_LED_570
:
5029 if (!acpi_evalf(ec_handle
,
5030 &status
, "GLED", "dd", 1 << led
))
5032 led_s
= (status
== 0)?
5037 tpacpi_led_state_cache
[led
] = led_s
;
5046 static int led_set_status(const unsigned int led
,
5047 const enum led_status_t ledstatus
)
5049 /* off, on, blink. Index is led_status_t */
5050 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
5051 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
5055 switch (led_supported
) {
5056 case TPACPI_LED_570
:
5058 if (unlikely(led
> 7))
5060 if (unlikely(tpacpi_is_led_restricted(led
)))
5062 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5063 (1 << led
), led_sled_arg1
[ledstatus
]))
5066 case TPACPI_LED_OLD
:
5067 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
5068 if (unlikely(led
> 7))
5070 if (unlikely(tpacpi_is_led_restricted(led
)))
5072 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
5074 rc
= ec_write(TPACPI_LED_EC_HLBL
,
5075 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5077 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5078 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5080 case TPACPI_LED_NEW
:
5082 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5084 if (unlikely(tpacpi_is_led_restricted(led
)))
5086 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5087 led
, led_led_arg1
[ledstatus
]))
5095 tpacpi_led_state_cache
[led
] = ledstatus
;
5100 static void led_set_status_worker(struct work_struct
*work
)
5102 struct tpacpi_led_classdev
*data
=
5103 container_of(work
, struct tpacpi_led_classdev
, work
);
5105 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5106 led_set_status(data
->led
, data
->new_state
);
5109 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5110 enum led_brightness brightness
)
5112 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5113 struct tpacpi_led_classdev
, led_classdev
);
5115 if (brightness
== LED_OFF
)
5116 data
->new_state
= TPACPI_LED_OFF
;
5117 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5118 data
->new_state
= TPACPI_LED_ON
;
5120 data
->new_state
= TPACPI_LED_BLINK
;
5122 queue_work(tpacpi_wq
, &data
->work
);
5125 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5126 unsigned long *delay_on
, unsigned long *delay_off
)
5128 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5129 struct tpacpi_led_classdev
, led_classdev
);
5131 /* Can we choose the flash rate? */
5132 if (*delay_on
== 0 && *delay_off
== 0) {
5133 /* yes. set them to the hardware blink rate (1 Hz) */
5134 *delay_on
= 500; /* ms */
5135 *delay_off
= 500; /* ms */
5136 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5139 data
->new_state
= TPACPI_LED_BLINK
;
5140 queue_work(tpacpi_wq
, &data
->work
);
5145 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5149 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5150 struct tpacpi_led_classdev
, led_classdev
);
5152 rc
= led_get_status(data
->led
);
5154 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5155 rc
= LED_OFF
; /* no error handling in led class :( */
5162 static void led_exit(void)
5166 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5167 if (tpacpi_leds
[i
].led_classdev
.name
)
5168 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5174 static int __init
tpacpi_init_led(unsigned int led
)
5178 tpacpi_leds
[led
].led
= led
;
5180 /* LEDs with no name don't get registered */
5181 if (!tpacpi_led_names
[led
])
5184 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5185 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5186 if (led_supported
== TPACPI_LED_570
)
5187 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5190 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5192 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5194 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5195 &tpacpi_leds
[led
].led_classdev
);
5197 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5202 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5203 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5204 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5205 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5207 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5208 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5209 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5210 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5211 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5212 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5213 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5214 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5216 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5217 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5218 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5219 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5220 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5222 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5223 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5224 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5225 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5227 /* (1) - may have excess leds enabled on MSB */
5229 /* Defaults (order matters, keep last, don't reorder!) */
5231 .vendor
= PCI_VENDOR_ID_LENOVO
,
5232 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5235 { /* IBM ThinkPads with no EC version string */
5236 .vendor
= PCI_VENDOR_ID_IBM
,
5237 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5240 { /* IBM ThinkPads with EC version string */
5241 .vendor
= PCI_VENDOR_ID_IBM
,
5242 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5247 #undef TPACPI_LEDQ_IBM
5248 #undef TPACPI_LEDQ_LNV
5250 static int __init
led_init(struct ibm_init_struct
*iibm
)
5254 unsigned long useful_leds
;
5256 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5258 TPACPI_ACPIHANDLE_INIT(led
);
5261 /* led not supported on R30, R31 */
5262 led_supported
= TPACPI_LED_NONE
;
5263 else if (strlencmp(led_path
, "SLED") == 0)
5265 led_supported
= TPACPI_LED_570
;
5266 else if (strlencmp(led_path
, "SYSL") == 0)
5267 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5268 led_supported
= TPACPI_LED_OLD
;
5271 led_supported
= TPACPI_LED_NEW
;
5273 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5274 str_supported(led_supported
), led_supported
);
5276 if (led_supported
== TPACPI_LED_NONE
)
5279 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5282 printk(TPACPI_ERR
"Out of memory for LED data\n");
5286 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5287 ARRAY_SIZE(led_useful_qtable
));
5289 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5290 if (!tpacpi_is_led_restricted(i
) &&
5291 test_bit(i
, &useful_leds
)) {
5292 rc
= tpacpi_init_led(i
);
5300 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5301 printk(TPACPI_NOTICE
5302 "warning: userspace override of important "
5303 "firmware LEDs is enabled\n");
5308 #define str_led_status(s) \
5309 ((s) == TPACPI_LED_OFF ? "off" : \
5310 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5312 static int led_read(struct seq_file
*m
)
5314 if (!led_supported
) {
5315 seq_printf(m
, "status:\t\tnot supported\n");
5318 seq_printf(m
, "status:\t\tsupported\n");
5320 if (led_supported
== TPACPI_LED_570
) {
5323 for (i
= 0; i
< 8; i
++) {
5324 status
= led_get_status(i
);
5327 seq_printf(m
, "%d:\t\t%s\n",
5328 i
, str_led_status(status
));
5332 seq_printf(m
, "commands:\t"
5333 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5338 static int led_write(char *buf
)
5342 enum led_status_t s
;
5347 while ((cmd
= next_cmd(&buf
))) {
5348 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5351 if (strstr(cmd
, "off")) {
5353 } else if (strstr(cmd
, "on")) {
5355 } else if (strstr(cmd
, "blink")) {
5356 s
= TPACPI_LED_BLINK
;
5361 rc
= led_set_status(led
, s
);
5369 static struct ibm_struct led_driver_data
= {
5376 /*************************************************************************
5380 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5382 #define TPACPI_BEEP_Q1 0x0001
5384 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5385 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5386 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5389 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5391 unsigned long quirks
;
5393 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5395 TPACPI_ACPIHANDLE_INIT(beep
);
5397 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5398 str_supported(beep_handle
!= NULL
));
5400 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5401 ARRAY_SIZE(beep_quirk_table
));
5403 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5405 return (beep_handle
)? 0 : 1;
5408 static int beep_read(struct seq_file
*m
)
5411 seq_printf(m
, "status:\t\tnot supported\n");
5413 seq_printf(m
, "status:\t\tsupported\n");
5414 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5420 static int beep_write(char *buf
)
5428 while ((cmd
= next_cmd(&buf
))) {
5429 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5430 beep_cmd
>= 0 && beep_cmd
<= 17) {
5434 if (tp_features
.beep_needs_two_args
) {
5435 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5439 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5448 static struct ibm_struct beep_driver_data
= {
5451 .write
= beep_write
,
5454 /*************************************************************************
5458 enum thermal_access_mode
{
5459 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5460 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5461 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5462 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5463 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5466 enum { /* TPACPI_THERMAL_TPEC_* */
5467 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5468 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5469 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5471 TPACPI_THERMAL_SENSOR_NA
= -128000, /* Sensor not available */
5475 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5476 struct ibm_thermal_sensors_struct
{
5477 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5480 static enum thermal_access_mode thermal_read_mode
;
5482 /* idx is zero-based */
5483 static int thermal_get_sensor(int idx
, s32
*value
)
5489 t
= TP_EC_THERMAL_TMP0
;
5491 switch (thermal_read_mode
) {
5492 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5493 case TPACPI_THERMAL_TPEC_16
:
5494 if (idx
>= 8 && idx
<= 15) {
5495 t
= TP_EC_THERMAL_TMP8
;
5500 case TPACPI_THERMAL_TPEC_8
:
5502 if (!acpi_ec_read(t
+ idx
, &tmp
))
5504 *value
= tmp
* 1000;
5509 case TPACPI_THERMAL_ACPI_UPDT
:
5511 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5512 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5514 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5516 *value
= (t
- 2732) * 100;
5521 case TPACPI_THERMAL_ACPI_TMP07
:
5523 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5524 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5526 if (t
> 127 || t
< -127)
5527 t
= TP_EC_THERMAL_TMP_NA
;
5533 case TPACPI_THERMAL_NONE
:
5541 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5552 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5555 for (i
= 0 ; i
< n
; i
++) {
5556 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5564 static void thermal_dump_all_sensors(void)
5567 struct ibm_thermal_sensors_struct t
;
5569 n
= thermal_get_sensors(&t
);
5573 printk(TPACPI_NOTICE
5574 "temperatures (Celsius):");
5576 for (i
= 0; i
< n
; i
++) {
5577 if (t
.temp
[i
] != TPACPI_THERMAL_SENSOR_NA
)
5578 printk(KERN_CONT
" %d", (int)(t
.temp
[i
] / 1000));
5580 printk(KERN_CONT
" N/A");
5583 printk(KERN_CONT
"\n");
5586 /* sysfs temp##_input -------------------------------------------------- */
5588 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5589 struct device_attribute
*attr
,
5592 struct sensor_device_attribute
*sensor_attr
=
5593 to_sensor_dev_attr(attr
);
5594 int idx
= sensor_attr
->index
;
5598 res
= thermal_get_sensor(idx
, &value
);
5601 if (value
== TPACPI_THERMAL_SENSOR_NA
)
5604 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5607 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5608 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5609 thermal_temp_input_show, NULL, _idxB)
5611 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5612 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5613 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5614 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5615 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5616 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5617 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5618 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5619 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5620 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5621 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5622 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5623 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5624 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5625 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5626 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5627 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5630 #define THERMAL_ATTRS(X) \
5631 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5633 static struct attribute
*thermal_temp_input_attr
[] = {
5653 static const struct attribute_group thermal_temp_input16_group
= {
5654 .attrs
= thermal_temp_input_attr
5657 static const struct attribute_group thermal_temp_input8_group
= {
5658 .attrs
= &thermal_temp_input_attr
[8]
5661 #undef THERMAL_SENSOR_ATTR_TEMP
5662 #undef THERMAL_ATTRS
5664 /* --------------------------------------------------------------------- */
5666 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5673 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5675 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5677 if (thinkpad_id
.ec_model
) {
5679 * Direct EC access mode: sensors at registers
5680 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5681 * non-implemented, thermal sensors return 0x80 when
5686 for (i
= 0; i
< 8; i
++) {
5687 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5693 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5701 /* This is sheer paranoia, but we handle it anyway */
5704 "ThinkPad ACPI EC access misbehaving, "
5705 "falling back to ACPI TMPx access "
5707 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5710 "ThinkPad ACPI EC access misbehaving, "
5711 "disabling thermal sensors access\n");
5712 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5717 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5719 } else if (acpi_tmp7
) {
5720 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5721 /* 600e/x, 770e, 770x */
5722 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5724 /* Standard ACPI TMPx access, max 8 sensors */
5725 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5728 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5729 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5732 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5733 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5736 switch (thermal_read_mode
) {
5737 case TPACPI_THERMAL_TPEC_16
:
5738 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5739 &thermal_temp_input16_group
);
5743 case TPACPI_THERMAL_TPEC_8
:
5744 case TPACPI_THERMAL_ACPI_TMP07
:
5745 case TPACPI_THERMAL_ACPI_UPDT
:
5746 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5747 &thermal_temp_input8_group
);
5751 case TPACPI_THERMAL_NONE
:
5759 static void thermal_exit(void)
5761 switch (thermal_read_mode
) {
5762 case TPACPI_THERMAL_TPEC_16
:
5763 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5764 &thermal_temp_input16_group
);
5766 case TPACPI_THERMAL_TPEC_8
:
5767 case TPACPI_THERMAL_ACPI_TMP07
:
5768 case TPACPI_THERMAL_ACPI_UPDT
:
5769 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5770 &thermal_temp_input8_group
);
5772 case TPACPI_THERMAL_NONE
:
5778 static int thermal_read(struct seq_file
*m
)
5781 struct ibm_thermal_sensors_struct t
;
5783 n
= thermal_get_sensors(&t
);
5784 if (unlikely(n
< 0))
5787 seq_printf(m
, "temperatures:\t");
5790 for (i
= 0; i
< (n
- 1); i
++)
5791 seq_printf(m
, "%d ", t
.temp
[i
] / 1000);
5792 seq_printf(m
, "%d\n", t
.temp
[i
] / 1000);
5794 seq_printf(m
, "not supported\n");
5799 static struct ibm_struct thermal_driver_data
= {
5801 .read
= thermal_read
,
5802 .exit
= thermal_exit
,
5805 /*************************************************************************
5809 static u8 ecdump_regs
[256];
5811 static int ecdump_read(struct seq_file
*m
)
5817 " +00 +01 +02 +03 +04 +05 +06 +07"
5818 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5819 for (i
= 0; i
< 256; i
+= 16) {
5820 seq_printf(m
, "EC 0x%02x:", i
);
5821 for (j
= 0; j
< 16; j
++) {
5822 if (!acpi_ec_read(i
+ j
, &v
))
5824 if (v
!= ecdump_regs
[i
+ j
])
5825 seq_printf(m
, " *%02x", v
);
5827 seq_printf(m
, " %02x", v
);
5828 ecdump_regs
[i
+ j
] = v
;
5835 /* These are way too dangerous to advertise openly... */
5837 seq_printf(m
, "commands:\t0x<offset> 0x<value>"
5838 " (<offset> is 00-ff, <value> is 00-ff)\n");
5839 seq_printf(m
, "commands:\t0x<offset> <value> "
5840 " (<offset> is 00-ff, <value> is 0-255)\n");
5845 static int ecdump_write(char *buf
)
5850 while ((cmd
= next_cmd(&buf
))) {
5851 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5853 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5857 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5858 if (!acpi_ec_write(i
, v
))
5867 static struct ibm_struct ecdump_driver_data
= {
5869 .read
= ecdump_read
,
5870 .write
= ecdump_write
,
5871 .flags
.experimental
= 1,
5874 /*************************************************************************
5875 * Backlight/brightness subdriver
5878 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5881 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5882 * CMOS NVRAM byte 0x5E, bits 0-3.
5884 * EC HBRV (0x31) has the following layout
5885 * Bit 7: unknown function
5886 * Bit 6: unknown function
5887 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5888 * Bit 4: must be set to zero to avoid problems
5889 * Bit 3-0: backlight brightness level
5891 * brightness_get_raw returns status data in the HBRV layout
5893 * WARNING: The X61 has been verified to use HBRV for something else, so
5894 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5895 * testing on the very early *60 Lenovo models...
5899 TP_EC_BACKLIGHT
= 0x31,
5901 /* TP_EC_BACKLIGHT bitmasks */
5902 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5903 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5904 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5907 enum tpacpi_brightness_access_mode
{
5908 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5909 TPACPI_BRGHT_MODE_EC
, /* EC control */
5910 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5911 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5912 TPACPI_BRGHT_MODE_MAX
5915 static struct backlight_device
*ibm_backlight_device
;
5917 static enum tpacpi_brightness_access_mode brightness_mode
=
5918 TPACPI_BRGHT_MODE_MAX
;
5920 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5922 static struct mutex brightness_mutex
;
5924 /* NVRAM brightness access,
5925 * call with brightness_mutex held! */
5926 static unsigned int tpacpi_brightness_nvram_get(void)
5930 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5931 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5932 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5933 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5938 static void tpacpi_brightness_checkpoint_nvram(void)
5943 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5946 vdbg_printk(TPACPI_DBG_BRGHT
,
5947 "trying to checkpoint backlight level to NVRAM...\n");
5949 if (mutex_lock_killable(&brightness_mutex
) < 0)
5952 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5954 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5955 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5957 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5958 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5959 /* NVRAM needs update */
5960 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5961 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5963 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5964 dbg_printk(TPACPI_DBG_BRGHT
,
5965 "updated NVRAM backlight level to %u (0x%02x)\n",
5966 (unsigned int) lec
, (unsigned int) b_nvram
);
5968 vdbg_printk(TPACPI_DBG_BRGHT
,
5969 "NVRAM backlight level already is %u (0x%02x)\n",
5970 (unsigned int) lec
, (unsigned int) b_nvram
);
5973 mutex_unlock(&brightness_mutex
);
5977 /* call with brightness_mutex held! */
5978 static int tpacpi_brightness_get_raw(int *status
)
5982 switch (brightness_mode
) {
5983 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5984 *status
= tpacpi_brightness_nvram_get();
5986 case TPACPI_BRGHT_MODE_EC
:
5987 case TPACPI_BRGHT_MODE_ECNVRAM
:
5988 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5997 /* call with brightness_mutex held! */
5998 /* do NOT call with illegal backlight level value */
5999 static int tpacpi_brightness_set_ec(unsigned int value
)
6003 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6006 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
6007 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
6008 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
6014 /* call with brightness_mutex held! */
6015 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
6018 unsigned int current_value
, i
;
6020 current_value
= tpacpi_brightness_nvram_get();
6022 if (value
== current_value
)
6025 cmos_cmd
= (value
> current_value
) ?
6026 TP_CMOS_BRIGHTNESS_UP
:
6027 TP_CMOS_BRIGHTNESS_DOWN
;
6028 inc
= (value
> current_value
) ? 1 : -1;
6030 for (i
= current_value
; i
!= value
; i
+= inc
)
6031 if (issue_thinkpad_cmos_command(cmos_cmd
))
6037 /* May return EINTR which can always be mapped to ERESTARTSYS */
6038 static int brightness_set(unsigned int value
)
6042 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
6046 vdbg_printk(TPACPI_DBG_BRGHT
,
6047 "set backlight level to %d\n", value
);
6049 res
= mutex_lock_killable(&brightness_mutex
);
6053 switch (brightness_mode
) {
6054 case TPACPI_BRGHT_MODE_EC
:
6055 case TPACPI_BRGHT_MODE_ECNVRAM
:
6056 res
= tpacpi_brightness_set_ec(value
);
6058 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6059 res
= tpacpi_brightness_set_ucmsstep(value
);
6065 mutex_unlock(&brightness_mutex
);
6069 /* sysfs backlight class ----------------------------------------------- */
6071 static int brightness_update_status(struct backlight_device
*bd
)
6073 unsigned int level
=
6074 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
6075 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
6076 bd
->props
.brightness
: 0;
6078 dbg_printk(TPACPI_DBG_BRGHT
,
6079 "backlight: attempt to set level to %d\n",
6082 /* it is the backlight class's job (caller) to handle
6083 * EINTR and other errors properly */
6084 return brightness_set(level
);
6087 static int brightness_get(struct backlight_device
*bd
)
6091 res
= mutex_lock_killable(&brightness_mutex
);
6095 res
= tpacpi_brightness_get_raw(&status
);
6097 mutex_unlock(&brightness_mutex
);
6102 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6105 static void tpacpi_brightness_notify_change(void)
6107 backlight_force_update(ibm_backlight_device
,
6108 BACKLIGHT_UPDATE_HOTKEY
);
6111 static struct backlight_ops ibm_backlight_data
= {
6112 .get_brightness
= brightness_get
,
6113 .update_status
= brightness_update_status
,
6116 /* --------------------------------------------------------------------- */
6119 * These are only useful for models that have only one possibility
6120 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6123 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6124 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6125 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6127 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6128 /* Models with ATI GPUs known to require ECNVRAM mode */
6129 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6131 /* Models with ATI GPUs that can use ECNVRAM */
6132 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
), /* R50,51 T40-42 */
6133 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6134 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC
), /* R52 */
6135 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6137 /* Models with Intel Extreme Graphics 2 */
6138 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
), /* X40 */
6139 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6140 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6142 /* Models with Intel GMA900 */
6143 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6144 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6145 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6148 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6151 unsigned long quirks
;
6153 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6155 mutex_init(&brightness_mutex
);
6157 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6158 ARRAY_SIZE(brightness_quirk_table
));
6161 * We always attempt to detect acpi support, so as to switch
6162 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6163 * going to publish a backlight interface
6165 b
= tpacpi_check_std_acpi_brightness_support();
6168 if (acpi_video_backlight_support()) {
6169 if (brightness_enable
> 1) {
6170 printk(TPACPI_NOTICE
6171 "Standard ACPI backlight interface "
6172 "available, not loading native one.\n");
6174 } else if (brightness_enable
== 1) {
6175 printk(TPACPI_NOTICE
6176 "Backlight control force enabled, even if standard "
6177 "ACPI backlight interface is available\n");
6180 if (brightness_enable
> 1) {
6181 printk(TPACPI_NOTICE
6182 "Standard ACPI backlight interface not "
6183 "available, thinkpad_acpi native "
6184 "brightness control enabled\n");
6189 if (!brightness_enable
) {
6190 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6191 "brightness support disabled by "
6192 "module parameter\n");
6198 "Unsupported brightness interface, "
6199 "please contact %s\n", TPACPI_MAIL
);
6203 tp_features
.bright_16levels
= 1;
6206 * Check for module parameter bogosity, note that we
6207 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6208 * able to detect "unspecified"
6210 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6213 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6214 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6215 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6216 if (quirks
& TPACPI_BRGHT_Q_EC
)
6217 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6219 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6221 dbg_printk(TPACPI_DBG_BRGHT
,
6222 "driver auto-selected brightness_mode=%d\n",
6227 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6228 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6229 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6232 if (tpacpi_brightness_get_raw(&b
) < 0)
6235 if (tp_features
.bright_16levels
)
6237 "detected a 16-level brightness capable ThinkPad\n");
6239 ibm_backlight_device
= backlight_device_register(
6240 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6241 &ibm_backlight_data
);
6242 if (IS_ERR(ibm_backlight_device
)) {
6243 int rc
= PTR_ERR(ibm_backlight_device
);
6244 ibm_backlight_device
= NULL
;
6245 printk(TPACPI_ERR
"Could not register backlight device\n");
6248 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6249 "brightness is supported\n");
6251 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6252 printk(TPACPI_NOTICE
6253 "brightness: will use unverified default: "
6254 "brightness_mode=%d\n", brightness_mode
);
6255 printk(TPACPI_NOTICE
6256 "brightness: please report to %s whether it works well "
6257 "or not on your ThinkPad\n", TPACPI_MAIL
);
6260 ibm_backlight_device
->props
.max_brightness
=
6261 (tp_features
.bright_16levels
)? 15 : 7;
6262 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6263 backlight_update_status(ibm_backlight_device
);
6265 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6266 "brightness: registering brightness hotkeys "
6267 "as change notification\n");
6268 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6269 | TP_ACPI_HKEY_BRGHTUP_MASK
6270 | TP_ACPI_HKEY_BRGHTDWN_MASK
);;
6274 static void brightness_suspend(pm_message_t state
)
6276 tpacpi_brightness_checkpoint_nvram();
6279 static void brightness_shutdown(void)
6281 tpacpi_brightness_checkpoint_nvram();
6284 static void brightness_exit(void)
6286 if (ibm_backlight_device
) {
6287 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6288 "calling backlight_device_unregister()\n");
6289 backlight_device_unregister(ibm_backlight_device
);
6292 tpacpi_brightness_checkpoint_nvram();
6295 static int brightness_read(struct seq_file
*m
)
6299 level
= brightness_get(NULL
);
6301 seq_printf(m
, "level:\t\tunreadable\n");
6303 seq_printf(m
, "level:\t\t%d\n", level
);
6304 seq_printf(m
, "commands:\tup, down\n");
6305 seq_printf(m
, "commands:\tlevel <level>"
6306 " (<level> is 0-%d)\n",
6307 (tp_features
.bright_16levels
) ? 15 : 7);
6313 static int brightness_write(char *buf
)
6318 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6320 level
= brightness_get(NULL
);
6324 while ((cmd
= next_cmd(&buf
))) {
6325 if (strlencmp(cmd
, "up") == 0) {
6326 if (level
< max_level
)
6328 } else if (strlencmp(cmd
, "down") == 0) {
6331 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6332 level
>= 0 && level
<= max_level
) {
6338 tpacpi_disclose_usertask("procfs brightness",
6339 "set level to %d\n", level
);
6342 * Now we know what the final level should be, so we try to set it.
6343 * Doing it this way makes the syscall restartable in case of EINTR
6345 rc
= brightness_set(level
);
6346 if (!rc
&& ibm_backlight_device
)
6347 backlight_force_update(ibm_backlight_device
,
6348 BACKLIGHT_UPDATE_SYSFS
);
6349 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6352 static struct ibm_struct brightness_driver_data
= {
6353 .name
= "brightness",
6354 .read
= brightness_read
,
6355 .write
= brightness_write
,
6356 .exit
= brightness_exit
,
6357 .suspend
= brightness_suspend
,
6358 .shutdown
= brightness_shutdown
,
6361 /*************************************************************************
6366 * IBM ThinkPads have a simple volume controller with MUTE gating.
6367 * Very early Lenovo ThinkPads follow the IBM ThinkPad spec.
6369 * Since the *61 series (and probably also the later *60 series), Lenovo
6370 * ThinkPads only implement the MUTE gate.
6373 * Bit 6: MUTE (1 mutes sound)
6375 * Other bits should be zero as far as we know.
6377 * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and
6378 * bits 3-0 (volume). Other bits in NVRAM may have other functions,
6379 * such as bit 7 which is used to detect repeated presses of MUTE,
6380 * and we leave them unchanged.
6383 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
6385 #define TPACPI_ALSA_DRVNAME "ThinkPad EC"
6386 #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control"
6387 #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME
6389 static int alsa_index
= ~((1 << (SNDRV_CARDS
- 3)) - 1); /* last three slots */
6390 static char *alsa_id
= "ThinkPadEC";
6391 static int alsa_enable
= SNDRV_DEFAULT_ENABLE1
;
6393 struct tpacpi_alsa_data
{
6394 struct snd_card
*card
;
6395 struct snd_ctl_elem_id
*ctl_mute_id
;
6396 struct snd_ctl_elem_id
*ctl_vol_id
;
6399 static struct snd_card
*alsa_card
;
6404 /* TP_EC_AUDIO bits */
6405 TP_EC_AUDIO_MUTESW
= 6,
6407 /* TP_EC_AUDIO bitmasks */
6408 TP_EC_AUDIO_LVL_MSK
= 0x0F,
6409 TP_EC_AUDIO_MUTESW_MSK
= (1 << TP_EC_AUDIO_MUTESW
),
6411 /* Maximum volume */
6412 TP_EC_VOLUME_MAX
= 14,
6415 enum tpacpi_volume_access_mode
{
6416 TPACPI_VOL_MODE_AUTO
= 0, /* Not implemented yet */
6417 TPACPI_VOL_MODE_EC
, /* Pure EC control */
6418 TPACPI_VOL_MODE_UCMS_STEP
, /* UCMS step-based control: N/A */
6419 TPACPI_VOL_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
6423 enum tpacpi_volume_capabilities
{
6424 TPACPI_VOL_CAP_AUTO
= 0, /* Use white/blacklist */
6425 TPACPI_VOL_CAP_VOLMUTE
, /* Output vol and mute */
6426 TPACPI_VOL_CAP_MUTEONLY
, /* Output mute only */
6430 static enum tpacpi_volume_access_mode volume_mode
=
6431 TPACPI_VOL_MODE_MAX
;
6433 static enum tpacpi_volume_capabilities volume_capabilities
;
6434 static int volume_control_allowed
;
6437 * Used to syncronize writers to TP_EC_AUDIO and
6438 * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write
6440 static struct mutex volume_mutex
;
6442 static void tpacpi_volume_checkpoint_nvram(void)
6448 if (volume_mode
!= TPACPI_VOL_MODE_ECNVRAM
)
6450 if (!volume_control_allowed
)
6453 vdbg_printk(TPACPI_DBG_MIXER
,
6454 "trying to checkpoint mixer state to NVRAM...\n");
6456 if (tp_features
.mixer_no_level_control
)
6457 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
;
6459 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
| TP_EC_AUDIO_LVL_MSK
;
6461 if (mutex_lock_killable(&volume_mutex
) < 0)
6464 if (unlikely(!acpi_ec_read(TP_EC_AUDIO
, &lec
)))
6467 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
6469 if (lec
!= (b_nvram
& ec_mask
)) {
6470 /* NVRAM needs update */
6471 b_nvram
&= ~ec_mask
;
6473 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_MIXER
);
6474 dbg_printk(TPACPI_DBG_MIXER
,
6475 "updated NVRAM mixer status to 0x%02x (0x%02x)\n",
6476 (unsigned int) lec
, (unsigned int) b_nvram
);
6478 vdbg_printk(TPACPI_DBG_MIXER
,
6479 "NVRAM mixer status already is 0x%02x (0x%02x)\n",
6480 (unsigned int) lec
, (unsigned int) b_nvram
);
6484 mutex_unlock(&volume_mutex
);
6487 static int volume_get_status_ec(u8
*status
)
6491 if (!acpi_ec_read(TP_EC_AUDIO
, &s
))
6496 dbg_printk(TPACPI_DBG_MIXER
, "status 0x%02x\n", s
);
6501 static int volume_get_status(u8
*status
)
6503 return volume_get_status_ec(status
);
6506 static int volume_set_status_ec(const u8 status
)
6508 if (!acpi_ec_write(TP_EC_AUDIO
, status
))
6511 dbg_printk(TPACPI_DBG_MIXER
, "set EC mixer to 0x%02x\n", status
);
6516 static int volume_set_status(const u8 status
)
6518 return volume_set_status_ec(status
);
6521 static int volume_set_mute_ec(const bool mute
)
6526 if (mutex_lock_killable(&volume_mutex
) < 0)
6529 rc
= volume_get_status_ec(&s
);
6533 n
= (mute
) ? s
| TP_EC_AUDIO_MUTESW_MSK
:
6534 s
& ~TP_EC_AUDIO_MUTESW_MSK
;
6537 rc
= volume_set_status_ec(n
);
6540 mutex_unlock(&volume_mutex
);
6544 static int volume_set_mute(const bool mute
)
6546 dbg_printk(TPACPI_DBG_MIXER
, "trying to %smute\n",
6547 (mute
) ? "" : "un");
6548 return volume_set_mute_ec(mute
);
6551 static int volume_set_volume_ec(const u8 vol
)
6556 if (vol
> TP_EC_VOLUME_MAX
)
6559 if (mutex_lock_killable(&volume_mutex
) < 0)
6562 rc
= volume_get_status_ec(&s
);
6566 n
= (s
& ~TP_EC_AUDIO_LVL_MSK
) | vol
;
6569 rc
= volume_set_status_ec(n
);
6572 mutex_unlock(&volume_mutex
);
6576 static int volume_set_volume(const u8 vol
)
6578 dbg_printk(TPACPI_DBG_MIXER
,
6579 "trying to set volume level to %hu\n", vol
);
6580 return volume_set_volume_ec(vol
);
6583 static void volume_alsa_notify_change(void)
6585 struct tpacpi_alsa_data
*d
;
6587 if (alsa_card
&& alsa_card
->private_data
) {
6588 d
= alsa_card
->private_data
;
6590 snd_ctl_notify(alsa_card
,
6591 SNDRV_CTL_EVENT_MASK_VALUE
,
6594 snd_ctl_notify(alsa_card
,
6595 SNDRV_CTL_EVENT_MASK_VALUE
,
6600 static int volume_alsa_vol_info(struct snd_kcontrol
*kcontrol
,
6601 struct snd_ctl_elem_info
*uinfo
)
6603 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
6605 uinfo
->value
.integer
.min
= 0;
6606 uinfo
->value
.integer
.max
= TP_EC_VOLUME_MAX
;
6610 static int volume_alsa_vol_get(struct snd_kcontrol
*kcontrol
,
6611 struct snd_ctl_elem_value
*ucontrol
)
6616 rc
= volume_get_status(&s
);
6620 ucontrol
->value
.integer
.value
[0] = s
& TP_EC_AUDIO_LVL_MSK
;
6624 static int volume_alsa_vol_put(struct snd_kcontrol
*kcontrol
,
6625 struct snd_ctl_elem_value
*ucontrol
)
6627 return volume_set_volume(ucontrol
->value
.integer
.value
[0]);
6630 #define volume_alsa_mute_info snd_ctl_boolean_mono_info
6632 static int volume_alsa_mute_get(struct snd_kcontrol
*kcontrol
,
6633 struct snd_ctl_elem_value
*ucontrol
)
6638 rc
= volume_get_status(&s
);
6642 ucontrol
->value
.integer
.value
[0] =
6643 (s
& TP_EC_AUDIO_MUTESW_MSK
) ? 0 : 1;
6647 static int volume_alsa_mute_put(struct snd_kcontrol
*kcontrol
,
6648 struct snd_ctl_elem_value
*ucontrol
)
6650 return volume_set_mute(!ucontrol
->value
.integer
.value
[0]);
6653 static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata
= {
6654 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6655 .name
= "Console Playback Volume",
6657 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6658 .info
= volume_alsa_vol_info
,
6659 .get
= volume_alsa_vol_get
,
6662 static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata
= {
6663 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6664 .name
= "Console Playback Switch",
6666 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6667 .info
= volume_alsa_mute_info
,
6668 .get
= volume_alsa_mute_get
,
6671 static void volume_suspend(pm_message_t state
)
6673 tpacpi_volume_checkpoint_nvram();
6676 static void volume_resume(void)
6678 volume_alsa_notify_change();
6681 static void volume_shutdown(void)
6683 tpacpi_volume_checkpoint_nvram();
6686 static void volume_exit(void)
6689 snd_card_free(alsa_card
);
6693 tpacpi_volume_checkpoint_nvram();
6696 static int __init
volume_create_alsa_mixer(void)
6698 struct snd_card
*card
;
6699 struct tpacpi_alsa_data
*data
;
6700 struct snd_kcontrol
*ctl_vol
;
6701 struct snd_kcontrol
*ctl_mute
;
6704 card
= snd_card_new(alsa_index
, alsa_id
, THIS_MODULE
,
6705 sizeof(struct tpacpi_alsa_data
));
6708 "Failed to create ALSA card structures\n");
6712 BUG_ON(!card
->private_data
);
6713 data
= card
->private_data
;
6716 strlcpy(card
->driver
, TPACPI_ALSA_DRVNAME
,
6717 sizeof(card
->driver
));
6718 strlcpy(card
->shortname
, TPACPI_ALSA_SHRTNAME
,
6719 sizeof(card
->shortname
));
6720 snprintf(card
->mixername
, sizeof(card
->mixername
), "ThinkPad EC %s",
6721 (thinkpad_id
.ec_version_str
) ?
6722 thinkpad_id
.ec_version_str
: "(unknown)");
6723 snprintf(card
->longname
, sizeof(card
->longname
),
6724 "%s at EC reg 0x%02x, fw %s", card
->shortname
, TP_EC_AUDIO
,
6725 (thinkpad_id
.ec_version_str
) ?
6726 thinkpad_id
.ec_version_str
: "unknown");
6728 if (volume_control_allowed
) {
6729 volume_alsa_control_vol
.put
= volume_alsa_vol_put
;
6730 volume_alsa_control_vol
.access
=
6731 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6733 volume_alsa_control_mute
.put
= volume_alsa_mute_put
;
6734 volume_alsa_control_mute
.access
=
6735 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6738 if (!tp_features
.mixer_no_level_control
) {
6739 ctl_vol
= snd_ctl_new1(&volume_alsa_control_vol
, NULL
);
6740 rc
= snd_ctl_add(card
, ctl_vol
);
6743 "Failed to create ALSA volume control: %d\n",
6747 data
->ctl_vol_id
= &ctl_vol
->id
;
6750 ctl_mute
= snd_ctl_new1(&volume_alsa_control_mute
, NULL
);
6751 rc
= snd_ctl_add(card
, ctl_mute
);
6753 printk(TPACPI_ERR
"Failed to create ALSA mute control: %d\n",
6757 data
->ctl_mute_id
= &ctl_mute
->id
;
6759 snd_card_set_dev(card
, &tpacpi_pdev
->dev
);
6760 rc
= snd_card_register(card
);
6762 printk(TPACPI_ERR
"Failed to register ALSA card: %d\n", rc
);
6770 snd_card_free(card
);
6774 #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */
6775 #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */
6777 static const struct tpacpi_quirk volume_quirk_table
[] __initconst
= {
6778 /* Whitelist volume level on all IBM by default */
6779 { .vendor
= PCI_VENDOR_ID_IBM
,
6780 .bios
= TPACPI_MATCH_ANY
,
6781 .ec
= TPACPI_MATCH_ANY
,
6782 .quirks
= TPACPI_VOL_Q_LEVEL
},
6784 /* Lenovo models with volume control (needs confirmation) */
6785 TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL
), /* R60/i */
6786 TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL
), /* R60e/i */
6787 TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL
), /* T60/p */
6788 TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL
), /* X60/s */
6789 TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL
), /* X60t */
6790 TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL
), /* Z60 */
6791 TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL
), /* Z61 */
6793 /* Whitelist mute-only on all Lenovo by default */
6794 { .vendor
= PCI_VENDOR_ID_LENOVO
,
6795 .bios
= TPACPI_MATCH_ANY
,
6796 .ec
= TPACPI_MATCH_ANY
,
6797 .quirks
= TPACPI_VOL_Q_MUTEONLY
}
6800 static int __init
volume_init(struct ibm_init_struct
*iibm
)
6802 unsigned long quirks
;
6805 vdbg_printk(TPACPI_DBG_INIT
, "initializing volume subdriver\n");
6807 mutex_init(&volume_mutex
);
6810 * Check for module parameter bogosity, note that we
6811 * init volume_mode to TPACPI_VOL_MODE_MAX in order to be
6812 * able to detect "unspecified"
6814 if (volume_mode
> TPACPI_VOL_MODE_MAX
)
6817 if (volume_mode
== TPACPI_VOL_MODE_UCMS_STEP
) {
6819 "UCMS step volume mode not implemented, "
6820 "please contact %s\n", TPACPI_MAIL
);
6824 if (volume_capabilities
>= TPACPI_VOL_CAP_MAX
)
6828 * The ALSA mixer is our primary interface.
6829 * When disabled, don't install the subdriver at all
6832 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6833 "ALSA mixer disabled by parameter, "
6834 "not loading volume subdriver...\n");
6838 quirks
= tpacpi_check_quirks(volume_quirk_table
,
6839 ARRAY_SIZE(volume_quirk_table
));
6841 switch (volume_capabilities
) {
6842 case TPACPI_VOL_CAP_AUTO
:
6843 if (quirks
& TPACPI_VOL_Q_MUTEONLY
)
6844 tp_features
.mixer_no_level_control
= 1;
6845 else if (quirks
& TPACPI_VOL_Q_LEVEL
)
6846 tp_features
.mixer_no_level_control
= 0;
6848 return 1; /* no mixer */
6850 case TPACPI_VOL_CAP_VOLMUTE
:
6851 tp_features
.mixer_no_level_control
= 0;
6853 case TPACPI_VOL_CAP_MUTEONLY
:
6854 tp_features
.mixer_no_level_control
= 1;
6860 if (volume_capabilities
!= TPACPI_VOL_CAP_AUTO
)
6861 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6862 "using user-supplied volume_capabilities=%d\n",
6863 volume_capabilities
);
6865 if (volume_mode
== TPACPI_VOL_MODE_AUTO
||
6866 volume_mode
== TPACPI_VOL_MODE_MAX
) {
6867 volume_mode
= TPACPI_VOL_MODE_ECNVRAM
;
6869 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6870 "driver auto-selected volume_mode=%d\n",
6873 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6874 "using user-supplied volume_mode=%d\n",
6878 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6879 "mute is supported, volume control is %s\n",
6880 str_supported(!tp_features
.mixer_no_level_control
));
6882 rc
= volume_create_alsa_mixer();
6885 "Could not create the ALSA mixer interface\n");
6890 "Console audio control enabled, mode: %s\n",
6891 (volume_control_allowed
) ?
6892 "override (read/write)" :
6893 "monitor (read only)");
6895 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6896 "registering volume hotkeys as change notification\n");
6897 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6898 | TP_ACPI_HKEY_VOLUP_MASK
6899 | TP_ACPI_HKEY_VOLDWN_MASK
6900 | TP_ACPI_HKEY_MUTE_MASK
);
6905 static int volume_read(struct seq_file
*m
)
6909 if (volume_get_status(&status
) < 0) {
6910 seq_printf(m
, "level:\t\tunreadable\n");
6912 if (tp_features
.mixer_no_level_control
)
6913 seq_printf(m
, "level:\t\tunsupported\n");
6915 seq_printf(m
, "level:\t\t%d\n",
6916 status
& TP_EC_AUDIO_LVL_MSK
);
6918 seq_printf(m
, "mute:\t\t%s\n",
6919 onoff(status
, TP_EC_AUDIO_MUTESW
));
6921 if (volume_control_allowed
) {
6922 seq_printf(m
, "commands:\tunmute, mute\n");
6923 if (!tp_features
.mixer_no_level_control
) {
6925 "commands:\tup, down\n");
6927 "commands:\tlevel <level>"
6928 " (<level> is 0-%d)\n",
6937 static int volume_write(char *buf
)
6940 u8 new_level
, new_mute
;
6946 * We do allow volume control at driver startup, so that the
6947 * user can set initial state through the volume=... parameter hack.
6949 if (!volume_control_allowed
&& tpacpi_lifecycle
!= TPACPI_LIFE_INIT
) {
6950 if (unlikely(!tp_warned
.volume_ctrl_forbidden
)) {
6951 tp_warned
.volume_ctrl_forbidden
= 1;
6952 printk(TPACPI_NOTICE
6953 "Console audio control in monitor mode, "
6954 "changes are not allowed.\n");
6955 printk(TPACPI_NOTICE
6956 "Use the volume_control=1 module parameter "
6957 "to enable volume control\n");
6962 rc
= volume_get_status(&s
);
6966 new_level
= s
& TP_EC_AUDIO_LVL_MSK
;
6967 new_mute
= s
& TP_EC_AUDIO_MUTESW_MSK
;
6969 while ((cmd
= next_cmd(&buf
))) {
6970 if (!tp_features
.mixer_no_level_control
) {
6971 if (strlencmp(cmd
, "up") == 0) {
6974 else if (new_level
< TP_EC_VOLUME_MAX
)
6977 } else if (strlencmp(cmd
, "down") == 0) {
6980 else if (new_level
> 0)
6983 } else if (sscanf(cmd
, "level %u", &l
) == 1 &&
6984 l
>= 0 && l
<= TP_EC_VOLUME_MAX
) {
6989 if (strlencmp(cmd
, "mute") == 0)
6990 new_mute
= TP_EC_AUDIO_MUTESW_MSK
;
6991 else if (strlencmp(cmd
, "unmute") == 0)
6997 if (tp_features
.mixer_no_level_control
) {
6998 tpacpi_disclose_usertask("procfs volume", "%smute\n",
6999 new_mute
? "" : "un");
7000 rc
= volume_set_mute(!!new_mute
);
7002 tpacpi_disclose_usertask("procfs volume",
7003 "%smute and set level to %d\n",
7004 new_mute
? "" : "un", new_level
);
7005 rc
= volume_set_status(new_mute
| new_level
);
7007 volume_alsa_notify_change();
7009 return (rc
== -EINTR
) ? -ERESTARTSYS
: rc
;
7012 static struct ibm_struct volume_driver_data
= {
7014 .read
= volume_read
,
7015 .write
= volume_write
,
7016 .exit
= volume_exit
,
7017 .suspend
= volume_suspend
,
7018 .resume
= volume_resume
,
7019 .shutdown
= volume_shutdown
,
7022 #else /* !CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
7024 #define alsa_card NULL
7026 static void inline volume_alsa_notify_change(void)
7030 static int __init
volume_init(struct ibm_init_struct
*iibm
)
7033 "volume: disabled as there is no ALSA support in this kernel\n");
7038 static struct ibm_struct volume_driver_data
= {
7042 #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
7044 /*************************************************************************
7051 * TPACPI_FAN_RD_ACPI_GFAN:
7052 * ACPI GFAN method: returns fan level
7054 * see TPACPI_FAN_WR_ACPI_SFAN
7055 * EC 0x2f (HFSP) not available if GFAN exists
7057 * TPACPI_FAN_WR_ACPI_SFAN:
7058 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
7060 * EC 0x2f (HFSP) might be available *for reading*, but do not use
7063 * TPACPI_FAN_WR_TPEC:
7064 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
7065 * Supported on almost all ThinkPads
7067 * Fan speed changes of any sort (including those caused by the
7068 * disengaged mode) are usually done slowly by the firmware as the
7069 * maximum ammount of fan duty cycle change per second seems to be
7072 * Reading is not available if GFAN exists.
7073 * Writing is not available if SFAN exists.
7076 * 7 automatic mode engaged;
7077 * (default operation mode of the ThinkPad)
7078 * fan level is ignored in this mode.
7079 * 6 full speed mode (takes precedence over bit 7);
7080 * not available on all thinkpads. May disable
7081 * the tachometer while the fan controller ramps up
7082 * the speed (which can take up to a few *minutes*).
7083 * Speeds up fan to 100% duty-cycle, which is far above
7084 * the standard RPM levels. It is not impossible that
7085 * it could cause hardware damage.
7086 * 5-3 unused in some models. Extra bits for fan level
7087 * in others, but still useless as all values above
7088 * 7 map to the same speed as level 7 in these models.
7089 * 2-0 fan level (0..7 usually)
7091 * 0x07 = max (set when temperatures critical)
7092 * Some ThinkPads may have other levels, see
7093 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
7095 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
7096 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
7097 * does so, its initial value is meaningless (0x07).
7099 * For firmware bugs, refer to:
7100 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7104 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
7105 * Main fan tachometer reading (in RPM)
7107 * This register is present on all ThinkPads with a new-style EC, and
7108 * it is known not to be present on the A21m/e, and T22, as there is
7109 * something else in offset 0x84 according to the ACPI DSDT. Other
7110 * ThinkPads from this same time period (and earlier) probably lack the
7111 * tachometer as well.
7113 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
7114 * was never fixed by IBM to report the EC firmware version string
7115 * probably support the tachometer (like the early X models), so
7116 * detecting it is quite hard. We need more data to know for sure.
7118 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
7121 * FIRMWARE BUG: may go stale while the EC is switching to full speed
7124 * For firmware bugs, refer to:
7125 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7129 * ThinkPad EC register 0x31 bit 0 (only on select models)
7131 * When bit 0 of EC register 0x31 is zero, the tachometer registers
7132 * show the speed of the main fan. When bit 0 of EC register 0x31
7133 * is one, the tachometer registers show the speed of the auxiliary
7136 * Fan control seems to affect both fans, regardless of the state
7139 * So far, only the firmware for the X60/X61 non-tablet versions
7140 * seem to support this (firmware TP-7M).
7142 * TPACPI_FAN_WR_ACPI_FANS:
7143 * ThinkPad X31, X40, X41. Not available in the X60.
7145 * FANS ACPI handle: takes three arguments: low speed, medium speed,
7146 * high speed. ACPI DSDT seems to map these three speeds to levels
7147 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
7148 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
7150 * The speeds are stored on handles
7151 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
7153 * There are three default speed sets, acessible as handles:
7154 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
7156 * ACPI DSDT switches which set is in use depending on various
7159 * TPACPI_FAN_WR_TPEC is also available and should be used to
7160 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
7161 * but the ACPI tables just mention level 7.
7164 enum { /* Fan control constants */
7165 fan_status_offset
= 0x2f, /* EC register 0x2f */
7166 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
7167 * 0x84 must be read before 0x85 */
7168 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
7169 bit 0 selects which fan is active */
7171 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
7172 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
7174 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
7177 enum fan_status_access_mode
{
7178 TPACPI_FAN_NONE
= 0, /* No fan status or control */
7179 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
7180 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
7183 enum fan_control_access_mode
{
7184 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
7185 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
7186 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
7187 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
7190 enum fan_control_commands
{
7191 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
7192 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
7193 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
7194 * and also watchdog cmd */
7197 static int fan_control_allowed
;
7199 static enum fan_status_access_mode fan_status_access_mode
;
7200 static enum fan_control_access_mode fan_control_access_mode
;
7201 static enum fan_control_commands fan_control_commands
;
7203 static u8 fan_control_initial_status
;
7204 static u8 fan_control_desired_level
;
7205 static u8 fan_control_resume_level
;
7206 static int fan_watchdog_maxinterval
;
7208 static struct mutex fan_mutex
;
7210 static void fan_watchdog_fire(struct work_struct
*ignored
);
7211 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
7213 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
7214 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
7215 "\\FSPD", /* 600e/x, 770e, 770x */
7217 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
7218 "JFNS", /* 770x-JL */
7222 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
7223 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
7224 * be in auto mode (0x80).
7226 * This is corrected by any write to HFSP either by the driver, or
7229 * We assume 0x07 really means auto mode while this quirk is active,
7230 * as this is far more likely than the ThinkPad being in level 7,
7231 * which is only used by the firmware during thermal emergencies.
7233 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
7234 * TP-70 (T43, R52), which are known to be buggy.
7237 static void fan_quirk1_setup(void)
7239 if (fan_control_initial_status
== 0x07) {
7240 printk(TPACPI_NOTICE
7241 "fan_init: initial fan status is unknown, "
7242 "assuming it is in auto mode\n");
7243 tp_features
.fan_ctrl_status_undef
= 1;
7247 static void fan_quirk1_handle(u8
*fan_status
)
7249 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
7250 if (*fan_status
!= fan_control_initial_status
) {
7251 /* something changed the HFSP regisnter since
7252 * driver init time, so it is not undefined
7254 tp_features
.fan_ctrl_status_undef
= 0;
7256 /* Return most likely status. In fact, it
7257 * might be the only possible status */
7258 *fan_status
= TP_EC_FAN_AUTO
;
7263 /* Select main fan on X60/X61, NOOP on others */
7264 static bool fan_select_fan1(void)
7266 if (tp_features
.second_fan
) {
7269 if (ec_read(fan_select_offset
, &val
) < 0)
7272 if (ec_write(fan_select_offset
, val
) < 0)
7278 /* Select secondary fan on X60/X61 */
7279 static bool fan_select_fan2(void)
7283 if (!tp_features
.second_fan
)
7286 if (ec_read(fan_select_offset
, &val
) < 0)
7289 if (ec_write(fan_select_offset
, val
) < 0)
7296 * Call with fan_mutex held
7298 static void fan_update_desired_level(u8 status
)
7301 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7303 fan_control_desired_level
= 7;
7305 fan_control_desired_level
= status
;
7309 static int fan_get_status(u8
*status
)
7314 * Add TPACPI_FAN_RD_ACPI_FANS ? */
7316 switch (fan_status_access_mode
) {
7317 case TPACPI_FAN_RD_ACPI_GFAN
:
7318 /* 570, 600e/x, 770e, 770x */
7320 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
7328 case TPACPI_FAN_RD_TPEC
:
7329 /* all except 570, 600e/x, 770e, 770x */
7330 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
7333 if (likely(status
)) {
7335 fan_quirk1_handle(status
);
7347 static int fan_get_status_safe(u8
*status
)
7352 if (mutex_lock_killable(&fan_mutex
))
7353 return -ERESTARTSYS
;
7354 rc
= fan_get_status(&s
);
7356 fan_update_desired_level(s
);
7357 mutex_unlock(&fan_mutex
);
7365 static int fan_get_speed(unsigned int *speed
)
7369 switch (fan_status_access_mode
) {
7370 case TPACPI_FAN_RD_TPEC
:
7371 /* all except 570, 600e/x, 770e, 770x */
7372 if (unlikely(!fan_select_fan1()))
7374 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
7375 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
7379 *speed
= (hi
<< 8) | lo
;
7390 static int fan2_get_speed(unsigned int *speed
)
7395 switch (fan_status_access_mode
) {
7396 case TPACPI_FAN_RD_TPEC
:
7397 /* all except 570, 600e/x, 770e, 770x */
7398 if (unlikely(!fan_select_fan2()))
7400 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
7401 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
7402 fan_select_fan1(); /* play it safe */
7407 *speed
= (hi
<< 8) | lo
;
7418 static int fan_set_level(int level
)
7420 if (!fan_control_allowed
)
7423 switch (fan_control_access_mode
) {
7424 case TPACPI_FAN_WR_ACPI_SFAN
:
7425 if (level
>= 0 && level
<= 7) {
7426 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
7432 case TPACPI_FAN_WR_ACPI_FANS
:
7433 case TPACPI_FAN_WR_TPEC
:
7434 if (!(level
& TP_EC_FAN_AUTO
) &&
7435 !(level
& TP_EC_FAN_FULLSPEED
) &&
7436 ((level
< 0) || (level
> 7)))
7439 /* safety net should the EC not support AUTO
7440 * or FULLSPEED mode bits and just ignore them */
7441 if (level
& TP_EC_FAN_FULLSPEED
)
7442 level
|= 7; /* safety min speed 7 */
7443 else if (level
& TP_EC_FAN_AUTO
)
7444 level
|= 4; /* safety min speed 4 */
7446 if (!acpi_ec_write(fan_status_offset
, level
))
7449 tp_features
.fan_ctrl_status_undef
= 0;
7456 vdbg_printk(TPACPI_DBG_FAN
,
7457 "fan control: set fan control register to 0x%02x\n", level
);
7461 static int fan_set_level_safe(int level
)
7465 if (!fan_control_allowed
)
7468 if (mutex_lock_killable(&fan_mutex
))
7469 return -ERESTARTSYS
;
7471 if (level
== TPACPI_FAN_LAST_LEVEL
)
7472 level
= fan_control_desired_level
;
7474 rc
= fan_set_level(level
);
7476 fan_update_desired_level(level
);
7478 mutex_unlock(&fan_mutex
);
7482 static int fan_set_enable(void)
7487 if (!fan_control_allowed
)
7490 if (mutex_lock_killable(&fan_mutex
))
7491 return -ERESTARTSYS
;
7493 switch (fan_control_access_mode
) {
7494 case TPACPI_FAN_WR_ACPI_FANS
:
7495 case TPACPI_FAN_WR_TPEC
:
7496 rc
= fan_get_status(&s
);
7500 /* Don't go out of emergency fan mode */
7503 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
7506 if (!acpi_ec_write(fan_status_offset
, s
))
7509 tp_features
.fan_ctrl_status_undef
= 0;
7514 case TPACPI_FAN_WR_ACPI_SFAN
:
7515 rc
= fan_get_status(&s
);
7521 /* Set fan to at least level 4 */
7524 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
7534 mutex_unlock(&fan_mutex
);
7537 vdbg_printk(TPACPI_DBG_FAN
,
7538 "fan control: set fan control register to 0x%02x\n",
7543 static int fan_set_disable(void)
7547 if (!fan_control_allowed
)
7550 if (mutex_lock_killable(&fan_mutex
))
7551 return -ERESTARTSYS
;
7554 switch (fan_control_access_mode
) {
7555 case TPACPI_FAN_WR_ACPI_FANS
:
7556 case TPACPI_FAN_WR_TPEC
:
7557 if (!acpi_ec_write(fan_status_offset
, 0x00))
7560 fan_control_desired_level
= 0;
7561 tp_features
.fan_ctrl_status_undef
= 0;
7565 case TPACPI_FAN_WR_ACPI_SFAN
:
7566 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
7569 fan_control_desired_level
= 0;
7577 vdbg_printk(TPACPI_DBG_FAN
,
7578 "fan control: set fan control register to 0\n");
7580 mutex_unlock(&fan_mutex
);
7584 static int fan_set_speed(int speed
)
7588 if (!fan_control_allowed
)
7591 if (mutex_lock_killable(&fan_mutex
))
7592 return -ERESTARTSYS
;
7595 switch (fan_control_access_mode
) {
7596 case TPACPI_FAN_WR_ACPI_FANS
:
7597 if (speed
>= 0 && speed
<= 65535) {
7598 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
7599 speed
, speed
, speed
))
7609 mutex_unlock(&fan_mutex
);
7613 static void fan_watchdog_reset(void)
7615 static int fan_watchdog_active
;
7617 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
7620 if (fan_watchdog_active
)
7621 cancel_delayed_work(&fan_watchdog_task
);
7623 if (fan_watchdog_maxinterval
> 0 &&
7624 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
7625 fan_watchdog_active
= 1;
7626 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
7627 msecs_to_jiffies(fan_watchdog_maxinterval
7630 "failed to queue the fan watchdog, "
7631 "watchdog will not trigger\n");
7634 fan_watchdog_active
= 0;
7637 static void fan_watchdog_fire(struct work_struct
*ignored
)
7641 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
7644 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
7645 rc
= fan_set_enable();
7647 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
7648 "will try again later...\n", -rc
);
7649 /* reschedule for later */
7650 fan_watchdog_reset();
7655 * SYSFS fan layout: hwmon compatible (device)
7658 * 0: "disengaged" mode
7660 * 2: native EC "auto" mode (recommended, hardware default)
7662 * pwm*: set speed in manual mode, ignored otherwise.
7663 * 0 is level 0; 255 is level 7. Intermediate points done with linear
7666 * fan*_input: tachometer reading, RPM
7669 * SYSFS fan layout: extensions
7671 * fan_watchdog (driver):
7672 * fan watchdog interval in seconds, 0 disables (default), max 120
7675 /* sysfs fan pwm1_enable ----------------------------------------------- */
7676 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
7677 struct device_attribute
*attr
,
7683 res
= fan_get_status_safe(&status
);
7687 if (status
& TP_EC_FAN_FULLSPEED
) {
7689 } else if (status
& TP_EC_FAN_AUTO
) {
7694 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
7697 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7698 struct device_attribute
*attr
,
7699 const char *buf
, size_t count
)
7704 if (parse_strtoul(buf
, 2, &t
))
7707 tpacpi_disclose_usertask("hwmon pwm1_enable",
7708 "set fan mode to %lu\n", t
);
7712 level
= TP_EC_FAN_FULLSPEED
;
7715 level
= TPACPI_FAN_LAST_LEVEL
;
7718 level
= TP_EC_FAN_AUTO
;
7721 /* reserved for software-controlled auto mode */
7727 res
= fan_set_level_safe(level
);
7733 fan_watchdog_reset();
7738 static struct device_attribute dev_attr_fan_pwm1_enable
=
7739 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7740 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7742 /* sysfs fan pwm1 ------------------------------------------------------ */
7743 static ssize_t
fan_pwm1_show(struct device
*dev
,
7744 struct device_attribute
*attr
,
7750 res
= fan_get_status_safe(&status
);
7755 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7756 status
= fan_control_desired_level
;
7761 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7764 static ssize_t
fan_pwm1_store(struct device
*dev
,
7765 struct device_attribute
*attr
,
7766 const char *buf
, size_t count
)
7770 u8 status
, newlevel
;
7772 if (parse_strtoul(buf
, 255, &s
))
7775 tpacpi_disclose_usertask("hwmon pwm1",
7776 "set fan speed to %lu\n", s
);
7778 /* scale down from 0-255 to 0-7 */
7779 newlevel
= (s
>> 5) & 0x07;
7781 if (mutex_lock_killable(&fan_mutex
))
7782 return -ERESTARTSYS
;
7784 rc
= fan_get_status(&status
);
7785 if (!rc
&& (status
&
7786 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7787 rc
= fan_set_level(newlevel
);
7791 fan_update_desired_level(newlevel
);
7792 fan_watchdog_reset();
7796 mutex_unlock(&fan_mutex
);
7797 return (rc
)? rc
: count
;
7800 static struct device_attribute dev_attr_fan_pwm1
=
7801 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7802 fan_pwm1_show
, fan_pwm1_store
);
7804 /* sysfs fan fan1_input ------------------------------------------------ */
7805 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7806 struct device_attribute
*attr
,
7812 res
= fan_get_speed(&speed
);
7816 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7819 static struct device_attribute dev_attr_fan_fan1_input
=
7820 __ATTR(fan1_input
, S_IRUGO
,
7821 fan_fan1_input_show
, NULL
);
7823 /* sysfs fan fan2_input ------------------------------------------------ */
7824 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7825 struct device_attribute
*attr
,
7831 res
= fan2_get_speed(&speed
);
7835 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7838 static struct device_attribute dev_attr_fan_fan2_input
=
7839 __ATTR(fan2_input
, S_IRUGO
,
7840 fan_fan2_input_show
, NULL
);
7842 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
7843 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
7846 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
7849 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
7850 const char *buf
, size_t count
)
7854 if (parse_strtoul(buf
, 120, &t
))
7857 if (!fan_control_allowed
)
7860 fan_watchdog_maxinterval
= t
;
7861 fan_watchdog_reset();
7863 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
7868 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
7869 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
7871 /* --------------------------------------------------------------------- */
7872 static struct attribute
*fan_attributes
[] = {
7873 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
7874 &dev_attr_fan_fan1_input
.attr
,
7875 NULL
, /* for fan2_input */
7879 static const struct attribute_group fan_attr_group
= {
7880 .attrs
= fan_attributes
,
7883 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
7884 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
7886 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7887 { .vendor = PCI_VENDOR_ID_IBM, \
7888 .bios = TPACPI_MATCH_ANY, \
7889 .ec = TPID(__id1, __id2), \
7890 .quirks = __quirks }
7892 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7893 { .vendor = PCI_VENDOR_ID_LENOVO, \
7894 .bios = TPACPI_MATCH_ANY, \
7895 .ec = TPID(__id1, __id2), \
7896 .quirks = __quirks }
7898 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
7899 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
7900 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
7901 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
7902 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
7903 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
7906 #undef TPACPI_FAN_QL
7907 #undef TPACPI_FAN_QI
7909 static int __init
fan_init(struct ibm_init_struct
*iibm
)
7912 unsigned long quirks
;
7914 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7915 "initializing fan subdriver\n");
7917 mutex_init(&fan_mutex
);
7918 fan_status_access_mode
= TPACPI_FAN_NONE
;
7919 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7920 fan_control_commands
= 0;
7921 fan_watchdog_maxinterval
= 0;
7922 tp_features
.fan_ctrl_status_undef
= 0;
7923 tp_features
.second_fan
= 0;
7924 fan_control_desired_level
= 7;
7926 TPACPI_ACPIHANDLE_INIT(fans
);
7927 TPACPI_ACPIHANDLE_INIT(gfan
);
7928 TPACPI_ACPIHANDLE_INIT(sfan
);
7930 quirks
= tpacpi_check_quirks(fan_quirk_table
,
7931 ARRAY_SIZE(fan_quirk_table
));
7934 /* 570, 600e/x, 770e, 770x */
7935 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7937 /* all other ThinkPads: note that even old-style
7938 * ThinkPad ECs supports the fan control register */
7939 if (likely(acpi_ec_read(fan_status_offset
,
7940 &fan_control_initial_status
))) {
7941 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7942 if (quirks
& TPACPI_FAN_Q1
)
7944 if (quirks
& TPACPI_FAN_2FAN
) {
7945 tp_features
.second_fan
= 1;
7946 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7947 "secondary fan support enabled\n");
7951 "ThinkPad ACPI EC access misbehaving, "
7952 "fan status and control unavailable\n");
7959 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
7960 fan_control_commands
|=
7961 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
7964 /* gfan without sfan means no fan control */
7965 /* all other models implement TP EC 0x2f control */
7969 fan_control_access_mode
=
7970 TPACPI_FAN_WR_ACPI_FANS
;
7971 fan_control_commands
|=
7972 TPACPI_FAN_CMD_SPEED
|
7973 TPACPI_FAN_CMD_LEVEL
|
7974 TPACPI_FAN_CMD_ENABLE
;
7976 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
7977 fan_control_commands
|=
7978 TPACPI_FAN_CMD_LEVEL
|
7979 TPACPI_FAN_CMD_ENABLE
;
7984 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7985 "fan is %s, modes %d, %d\n",
7986 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
7987 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
7988 fan_status_access_mode
, fan_control_access_mode
);
7990 /* fan control master switch */
7991 if (!fan_control_allowed
) {
7992 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7993 fan_control_commands
= 0;
7994 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7995 "fan control features disabled by parameter\n");
7998 /* update fan_control_desired_level */
7999 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
8000 fan_get_status_safe(NULL
);
8002 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
8003 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
8004 if (tp_features
.second_fan
) {
8005 /* attach second fan tachometer */
8006 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
8007 &dev_attr_fan_fan2_input
.attr
;
8009 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8014 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
8015 &driver_attr_fan_watchdog
);
8017 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8026 static void fan_exit(void)
8028 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
8029 "cancelling any pending fan watchdog tasks\n");
8031 /* FIXME: can we really do this unconditionally? */
8032 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
8033 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
8034 &driver_attr_fan_watchdog
);
8036 cancel_delayed_work(&fan_watchdog_task
);
8037 flush_workqueue(tpacpi_wq
);
8040 static void fan_suspend(pm_message_t state
)
8044 if (!fan_control_allowed
)
8047 /* Store fan status in cache */
8048 fan_control_resume_level
= 0;
8049 rc
= fan_get_status_safe(&fan_control_resume_level
);
8051 printk(TPACPI_NOTICE
8052 "failed to read fan level for later "
8053 "restore during resume: %d\n", rc
);
8055 /* if it is undefined, don't attempt to restore it.
8057 if (tp_features
.fan_ctrl_status_undef
)
8058 fan_control_resume_level
= 0;
8061 static void fan_resume(void)
8063 u8 current_level
= 7;
8064 bool do_set
= false;
8067 /* DSDT *always* updates status on resume */
8068 tp_features
.fan_ctrl_status_undef
= 0;
8070 if (!fan_control_allowed
||
8071 !fan_control_resume_level
||
8072 (fan_get_status_safe(¤t_level
) < 0))
8075 switch (fan_control_access_mode
) {
8076 case TPACPI_FAN_WR_ACPI_SFAN
:
8077 /* never decrease fan level */
8078 do_set
= (fan_control_resume_level
> current_level
);
8080 case TPACPI_FAN_WR_ACPI_FANS
:
8081 case TPACPI_FAN_WR_TPEC
:
8082 /* never decrease fan level, scale is:
8083 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
8085 * We expect the firmware to set either 7 or AUTO, but we
8086 * handle FULLSPEED out of paranoia.
8088 * So, we can safely only restore FULLSPEED or 7, anything
8089 * else could slow the fan. Restoring AUTO is useless, at
8090 * best that's exactly what the DSDT already set (it is the
8093 * Always keep in mind that the DSDT *will* have set the
8094 * fans to what the vendor supposes is the best level. We
8095 * muck with it only to speed the fan up.
8097 if (fan_control_resume_level
!= 7 &&
8098 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
8101 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
8102 (current_level
!= fan_control_resume_level
);
8108 printk(TPACPI_NOTICE
8109 "restoring fan level to 0x%02x\n",
8110 fan_control_resume_level
);
8111 rc
= fan_set_level_safe(fan_control_resume_level
);
8113 printk(TPACPI_NOTICE
8114 "failed to restore fan level: %d\n", rc
);
8118 static int fan_read(struct seq_file
*m
)
8122 unsigned int speed
= 0;
8124 switch (fan_status_access_mode
) {
8125 case TPACPI_FAN_RD_ACPI_GFAN
:
8126 /* 570, 600e/x, 770e, 770x */
8127 rc
= fan_get_status_safe(&status
);
8131 seq_printf(m
, "status:\t\t%s\n"
8133 (status
!= 0) ? "enabled" : "disabled", status
);
8136 case TPACPI_FAN_RD_TPEC
:
8137 /* all except 570, 600e/x, 770e, 770x */
8138 rc
= fan_get_status_safe(&status
);
8142 seq_printf(m
, "status:\t\t%s\n",
8143 (status
!= 0) ? "enabled" : "disabled");
8145 rc
= fan_get_speed(&speed
);
8149 seq_printf(m
, "speed:\t\t%d\n", speed
);
8151 if (status
& TP_EC_FAN_FULLSPEED
)
8152 /* Disengaged mode takes precedence */
8153 seq_printf(m
, "level:\t\tdisengaged\n");
8154 else if (status
& TP_EC_FAN_AUTO
)
8155 seq_printf(m
, "level:\t\tauto\n");
8157 seq_printf(m
, "level:\t\t%d\n", status
);
8160 case TPACPI_FAN_NONE
:
8162 seq_printf(m
, "status:\t\tnot supported\n");
8165 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
8166 seq_printf(m
, "commands:\tlevel <level>");
8168 switch (fan_control_access_mode
) {
8169 case TPACPI_FAN_WR_ACPI_SFAN
:
8170 seq_printf(m
, " (<level> is 0-7)\n");
8174 seq_printf(m
, " (<level> is 0-7, "
8175 "auto, disengaged, full-speed)\n");
8180 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
8181 seq_printf(m
, "commands:\tenable, disable\n"
8182 "commands:\twatchdog <timeout> (<timeout> "
8183 "is 0 (off), 1-120 (seconds))\n");
8185 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
8186 seq_printf(m
, "commands:\tspeed <speed>"
8187 " (<speed> is 0-65535)\n");
8192 static int fan_write_cmd_level(const char *cmd
, int *rc
)
8196 if (strlencmp(cmd
, "level auto") == 0)
8197 level
= TP_EC_FAN_AUTO
;
8198 else if ((strlencmp(cmd
, "level disengaged") == 0) |
8199 (strlencmp(cmd
, "level full-speed") == 0))
8200 level
= TP_EC_FAN_FULLSPEED
;
8201 else if (sscanf(cmd
, "level %d", &level
) != 1)
8204 *rc
= fan_set_level_safe(level
);
8206 printk(TPACPI_ERR
"level command accepted for unsupported "
8207 "access mode %d", fan_control_access_mode
);
8209 tpacpi_disclose_usertask("procfs fan",
8210 "set level to %d\n", level
);
8215 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
8217 if (strlencmp(cmd
, "enable") != 0)
8220 *rc
= fan_set_enable();
8222 printk(TPACPI_ERR
"enable command accepted for unsupported "
8223 "access mode %d", fan_control_access_mode
);
8225 tpacpi_disclose_usertask("procfs fan", "enable\n");
8230 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
8232 if (strlencmp(cmd
, "disable") != 0)
8235 *rc
= fan_set_disable();
8237 printk(TPACPI_ERR
"disable command accepted for unsupported "
8238 "access mode %d", fan_control_access_mode
);
8240 tpacpi_disclose_usertask("procfs fan", "disable\n");
8245 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
8250 * Support speed <low> <medium> <high> ? */
8252 if (sscanf(cmd
, "speed %d", &speed
) != 1)
8255 *rc
= fan_set_speed(speed
);
8257 printk(TPACPI_ERR
"speed command accepted for unsupported "
8258 "access mode %d", fan_control_access_mode
);
8260 tpacpi_disclose_usertask("procfs fan",
8261 "set speed to %d\n", speed
);
8266 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
8270 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
8273 if (interval
< 0 || interval
> 120)
8276 fan_watchdog_maxinterval
= interval
;
8277 tpacpi_disclose_usertask("procfs fan",
8278 "set watchdog timer to %d\n",
8285 static int fan_write(char *buf
)
8290 while (!rc
&& (cmd
= next_cmd(&buf
))) {
8291 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
8292 fan_write_cmd_level(cmd
, &rc
)) &&
8293 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
8294 (fan_write_cmd_enable(cmd
, &rc
) ||
8295 fan_write_cmd_disable(cmd
, &rc
) ||
8296 fan_write_cmd_watchdog(cmd
, &rc
))) &&
8297 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
8298 fan_write_cmd_speed(cmd
, &rc
))
8302 fan_watchdog_reset();
8308 static struct ibm_struct fan_driver_data
= {
8313 .suspend
= fan_suspend
,
8314 .resume
= fan_resume
,
8317 /****************************************************************************
8318 ****************************************************************************
8322 ****************************************************************************
8323 ****************************************************************************/
8326 * HKEY event callout for other subdrivers go here
8327 * (yes, it is ugly, but it is quick, safe, and gets the job done
8329 static void tpacpi_driver_event(const unsigned int hkey_event
)
8331 if (ibm_backlight_device
) {
8332 switch (hkey_event
) {
8333 case TP_HKEY_EV_BRGHT_UP
:
8334 case TP_HKEY_EV_BRGHT_DOWN
:
8335 tpacpi_brightness_notify_change();
8339 switch (hkey_event
) {
8340 case TP_HKEY_EV_VOL_UP
:
8341 case TP_HKEY_EV_VOL_DOWN
:
8342 case TP_HKEY_EV_VOL_MUTE
:
8343 volume_alsa_notify_change();
8348 static void hotkey_driver_event(const unsigned int scancode
)
8350 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
8353 /* sysfs name ---------------------------------------------------------- */
8354 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
8355 struct device_attribute
*attr
,
8358 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
8361 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
8362 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
8364 /* --------------------------------------------------------------------- */
8367 static struct proc_dir_entry
*proc_dir
;
8370 * Module and infrastructure proble, init and exit handling
8373 static int force_load
;
8375 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
8376 static const char * __init
str_supported(int is_supported
)
8378 static char text_unsupported
[] __initdata
= "not supported";
8380 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
8382 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
8384 static void ibm_exit(struct ibm_struct
*ibm
)
8386 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
8388 list_del_init(&ibm
->all_drivers
);
8390 if (ibm
->flags
.acpi_notify_installed
) {
8391 dbg_printk(TPACPI_DBG_EXIT
,
8392 "%s: acpi_remove_notify_handler\n", ibm
->name
);
8394 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
8396 dispatch_acpi_notify
);
8397 ibm
->flags
.acpi_notify_installed
= 0;
8398 ibm
->flags
.acpi_notify_installed
= 0;
8401 if (ibm
->flags
.proc_created
) {
8402 dbg_printk(TPACPI_DBG_EXIT
,
8403 "%s: remove_proc_entry\n", ibm
->name
);
8404 remove_proc_entry(ibm
->name
, proc_dir
);
8405 ibm
->flags
.proc_created
= 0;
8408 if (ibm
->flags
.acpi_driver_registered
) {
8409 dbg_printk(TPACPI_DBG_EXIT
,
8410 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
8412 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
8413 kfree(ibm
->acpi
->driver
);
8414 ibm
->acpi
->driver
= NULL
;
8415 ibm
->flags
.acpi_driver_registered
= 0;
8418 if (ibm
->flags
.init_called
&& ibm
->exit
) {
8420 ibm
->flags
.init_called
= 0;
8423 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
8426 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
8429 struct ibm_struct
*ibm
= iibm
->data
;
8430 struct proc_dir_entry
*entry
;
8432 BUG_ON(ibm
== NULL
);
8434 INIT_LIST_HEAD(&ibm
->all_drivers
);
8436 if (ibm
->flags
.experimental
&& !experimental
)
8439 dbg_printk(TPACPI_DBG_INIT
,
8440 "probing for %s\n", ibm
->name
);
8443 ret
= iibm
->init(iibm
);
8445 return 0; /* probe failed */
8449 ibm
->flags
.init_called
= 1;
8453 if (ibm
->acpi
->hid
) {
8454 ret
= register_tpacpi_subdriver(ibm
);
8459 if (ibm
->acpi
->notify
) {
8460 ret
= setup_acpi_notify(ibm
);
8461 if (ret
== -ENODEV
) {
8462 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
8472 dbg_printk(TPACPI_DBG_INIT
,
8473 "%s installed\n", ibm
->name
);
8481 entry
= proc_create_data(ibm
->name
, mode
, proc_dir
,
8482 &dispatch_proc_fops
, ibm
);
8484 printk(TPACPI_ERR
"unable to create proc entry %s\n",
8489 ibm
->flags
.proc_created
= 1;
8492 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
8497 dbg_printk(TPACPI_DBG_INIT
,
8498 "%s: at error exit path with result %d\n",
8502 return (ret
< 0)? ret
: 0;
8507 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
8509 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
8512 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
8513 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
8516 return s
&& strlen(s
) >= 8 &&
8517 tpacpi_is_fw_digit(s
[0]) &&
8518 tpacpi_is_fw_digit(s
[1]) &&
8519 s
[2] == t
&& s
[3] == 'T' &&
8520 tpacpi_is_fw_digit(s
[4]) &&
8521 tpacpi_is_fw_digit(s
[5]) &&
8522 s
[6] == 'W' && s
[7] == 'W';
8525 /* returns 0 - probe ok, or < 0 - probe error.
8526 * Probe ok doesn't mean thinkpad found.
8527 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
8528 static int __must_check __init
get_thinkpad_model_data(
8529 struct thinkpad_id_data
*tp
)
8531 const struct dmi_device
*dev
= NULL
;
8532 char ec_fw_string
[18];
8538 memset(tp
, 0, sizeof(*tp
));
8540 if (dmi_name_in_vendors("IBM"))
8541 tp
->vendor
= PCI_VENDOR_ID_IBM
;
8542 else if (dmi_name_in_vendors("LENOVO"))
8543 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
8547 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
8548 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
8549 if (s
&& !tp
->bios_version_str
)
8552 /* Really ancient ThinkPad 240X will fail this, which is fine */
8553 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
8556 tp
->bios_model
= tp
->bios_version_str
[0]
8557 | (tp
->bios_version_str
[1] << 8);
8558 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
8559 | tp
->bios_version_str
[5];
8562 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
8563 * X32 or newer, all Z series; Some models must have an
8564 * up-to-date BIOS or they will not be detected.
8566 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8568 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
8569 if (sscanf(dev
->name
,
8570 "IBM ThinkPad Embedded Controller -[%17c",
8571 ec_fw_string
) == 1) {
8572 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
8573 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
8575 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
8576 if (!tp
->ec_version_str
)
8579 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
8580 tp
->ec_model
= ec_fw_string
[0]
8581 | (ec_fw_string
[1] << 8);
8582 tp
->ec_release
= (ec_fw_string
[4] << 8)
8585 printk(TPACPI_NOTICE
8586 "ThinkPad firmware release %s "
8587 "doesn't match the known patterns\n",
8589 printk(TPACPI_NOTICE
8590 "please report this to %s\n",
8597 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
8598 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
8599 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
8604 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
8605 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
8606 if (s
&& !tp
->nummodel_str
)
8612 static int __init
probe_for_thinkpad(void)
8620 * Non-ancient models have better DMI tagging, but very old models
8621 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
8623 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
8624 (thinkpad_id
.ec_model
!= 0) ||
8625 tpacpi_is_fw_known();
8627 /* ec is required because many other handles are relative to it */
8628 TPACPI_ACPIHANDLE_INIT(ec
);
8632 "Not yet supported ThinkPad detected!\n");
8636 if (!is_thinkpad
&& !force_load
)
8643 /* Module init, exit, parameters */
8645 static struct ibm_init_struct ibms_init
[] __initdata
= {
8647 .init
= thinkpad_acpi_driver_init
,
8648 .data
= &thinkpad_acpi_driver_data
,
8651 .init
= hotkey_init
,
8652 .data
= &hotkey_driver_data
,
8655 .init
= bluetooth_init
,
8656 .data
= &bluetooth_driver_data
,
8660 .data
= &wan_driver_data
,
8664 .data
= &uwb_driver_data
,
8666 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8669 .data
= &video_driver_data
,
8674 .data
= &light_driver_data
,
8678 .data
= &cmos_driver_data
,
8682 .data
= &led_driver_data
,
8686 .data
= &beep_driver_data
,
8689 .init
= thermal_init
,
8690 .data
= &thermal_driver_data
,
8693 .data
= &ecdump_driver_data
,
8696 .init
= brightness_init
,
8697 .data
= &brightness_driver_data
,
8700 .init
= volume_init
,
8701 .data
= &volume_driver_data
,
8705 .data
= &fan_driver_data
,
8709 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
8712 struct ibm_struct
*ibm
;
8714 if (!kp
|| !kp
->name
|| !val
)
8717 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8718 ibm
= ibms_init
[i
].data
;
8719 WARN_ON(ibm
== NULL
);
8721 if (!ibm
|| !ibm
->name
)
8724 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8725 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8727 strcpy(ibms_init
[i
].param
, val
);
8728 strcat(ibms_init
[i
].param
, ",");
8736 module_param(experimental
, int, 0444);
8737 MODULE_PARM_DESC(experimental
,
8738 "Enables experimental features when non-zero");
8740 module_param_named(debug
, dbg_level
, uint
, 0);
8741 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8743 module_param(force_load
, bool, 0444);
8744 MODULE_PARM_DESC(force_load
,
8745 "Attempts to load the driver even on a "
8746 "mis-identified ThinkPad when true");
8748 module_param_named(fan_control
, fan_control_allowed
, bool, 0444);
8749 MODULE_PARM_DESC(fan_control
,
8750 "Enables setting fan parameters features when true");
8752 module_param_named(brightness_mode
, brightness_mode
, uint
, 0444);
8753 MODULE_PARM_DESC(brightness_mode
,
8754 "Selects brightness control strategy: "
8755 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8757 module_param(brightness_enable
, uint
, 0444);
8758 MODULE_PARM_DESC(brightness_enable
,
8759 "Enables backlight control when 1, disables when 0");
8761 module_param(hotkey_report_mode
, uint
, 0444);
8762 MODULE_PARM_DESC(hotkey_report_mode
,
8763 "used for backwards compatibility with userspace, "
8764 "see documentation");
8766 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
8767 module_param_named(volume_mode
, volume_mode
, uint
, 0444);
8768 MODULE_PARM_DESC(volume_mode
,
8769 "Selects volume control strategy: "
8770 "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM");
8772 module_param_named(volume_capabilities
, volume_capabilities
, uint
, 0444);
8773 MODULE_PARM_DESC(volume_capabilities
,
8774 "Selects the mixer capabilites: "
8775 "0=auto, 1=volume and mute, 2=mute only");
8777 module_param_named(volume_control
, volume_control_allowed
, bool, 0444);
8778 MODULE_PARM_DESC(volume_control
,
8779 "Enables software override for the console audio "
8780 "control when true");
8782 /* ALSA module API parameters */
8783 module_param_named(index
, alsa_index
, int, 0444);
8784 MODULE_PARM_DESC(index
, "ALSA index for the ACPI EC Mixer");
8785 module_param_named(id
, alsa_id
, charp
, 0444);
8786 MODULE_PARM_DESC(id
, "ALSA id for the ACPI EC Mixer");
8787 module_param_named(enable
, alsa_enable
, bool, 0444);
8788 MODULE_PARM_DESC(enable
, "Enable the ALSA interface for the ACPI EC Mixer");
8789 #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
8791 #define TPACPI_PARAM(feature) \
8792 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8793 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8794 "at module load, see documentation")
8796 TPACPI_PARAM(hotkey
);
8797 TPACPI_PARAM(bluetooth
);
8798 TPACPI_PARAM(video
);
8799 TPACPI_PARAM(light
);
8803 TPACPI_PARAM(ecdump
);
8804 TPACPI_PARAM(brightness
);
8805 TPACPI_PARAM(volume
);
8808 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8809 module_param(dbg_wlswemul
, uint
, 0444);
8810 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
8811 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
8812 MODULE_PARM_DESC(wlsw_state
,
8813 "Initial state of the emulated WLSW switch");
8815 module_param(dbg_bluetoothemul
, uint
, 0444);
8816 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
8817 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
8818 MODULE_PARM_DESC(bluetooth_state
,
8819 "Initial state of the emulated bluetooth switch");
8821 module_param(dbg_wwanemul
, uint
, 0444);
8822 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
8823 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
8824 MODULE_PARM_DESC(wwan_state
,
8825 "Initial state of the emulated WWAN switch");
8827 module_param(dbg_uwbemul
, uint
, 0444);
8828 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
8829 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
8830 MODULE_PARM_DESC(uwb_state
,
8831 "Initial state of the emulated UWB switch");
8834 static void thinkpad_acpi_module_exit(void)
8836 struct ibm_struct
*ibm
, *itmp
;
8838 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
8840 list_for_each_entry_safe_reverse(ibm
, itmp
,
8841 &tpacpi_all_drivers
,
8846 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
8848 if (tpacpi_inputdev
) {
8849 if (tp_features
.input_device_registered
)
8850 input_unregister_device(tpacpi_inputdev
);
8852 input_free_device(tpacpi_inputdev
);
8856 hwmon_device_unregister(tpacpi_hwmon
);
8858 if (tp_features
.sensors_pdev_attrs_registered
)
8859 device_remove_file(&tpacpi_sensors_pdev
->dev
,
8860 &dev_attr_thinkpad_acpi_pdev_name
);
8861 if (tpacpi_sensors_pdev
)
8862 platform_device_unregister(tpacpi_sensors_pdev
);
8864 platform_device_unregister(tpacpi_pdev
);
8866 if (tp_features
.sensors_pdrv_attrs_registered
)
8867 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
8868 if (tp_features
.platform_drv_attrs_registered
)
8869 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
8871 if (tp_features
.sensors_pdrv_registered
)
8872 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
8874 if (tp_features
.platform_drv_registered
)
8875 platform_driver_unregister(&tpacpi_pdriver
);
8878 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
8881 destroy_workqueue(tpacpi_wq
);
8883 kfree(thinkpad_id
.bios_version_str
);
8884 kfree(thinkpad_id
.ec_version_str
);
8885 kfree(thinkpad_id
.model_str
);
8889 static int __init
thinkpad_acpi_module_init(void)
8893 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
8895 /* Parameter checking */
8896 if (hotkey_report_mode
> 2)
8899 /* Driver-level probe */
8901 ret
= get_thinkpad_model_data(&thinkpad_id
);
8904 "unable to get DMI data: %d\n", ret
);
8905 thinkpad_acpi_module_exit();
8908 ret
= probe_for_thinkpad();
8910 thinkpad_acpi_module_exit();
8914 /* Driver initialization */
8916 TPACPI_ACPIHANDLE_INIT(ecrd
);
8917 TPACPI_ACPIHANDLE_INIT(ecwr
);
8919 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
8921 thinkpad_acpi_module_exit();
8925 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
8928 "unable to create proc dir " TPACPI_PROC_DIR
);
8929 thinkpad_acpi_module_exit();
8932 proc_dir
->owner
= THIS_MODULE
;
8934 ret
= platform_driver_register(&tpacpi_pdriver
);
8937 "unable to register main platform driver\n");
8938 thinkpad_acpi_module_exit();
8941 tp_features
.platform_drv_registered
= 1;
8943 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
8946 "unable to register hwmon platform driver\n");
8947 thinkpad_acpi_module_exit();
8950 tp_features
.sensors_pdrv_registered
= 1;
8952 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
8954 tp_features
.platform_drv_attrs_registered
= 1;
8955 ret
= tpacpi_create_driver_attributes(
8956 &tpacpi_hwmon_pdriver
.driver
);
8960 "unable to create sysfs driver attributes\n");
8961 thinkpad_acpi_module_exit();
8964 tp_features
.sensors_pdrv_attrs_registered
= 1;
8967 /* Device initialization */
8968 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
8970 if (IS_ERR(tpacpi_pdev
)) {
8971 ret
= PTR_ERR(tpacpi_pdev
);
8973 printk(TPACPI_ERR
"unable to register platform device\n");
8974 thinkpad_acpi_module_exit();
8977 tpacpi_sensors_pdev
= platform_device_register_simple(
8978 TPACPI_HWMON_DRVR_NAME
,
8980 if (IS_ERR(tpacpi_sensors_pdev
)) {
8981 ret
= PTR_ERR(tpacpi_sensors_pdev
);
8982 tpacpi_sensors_pdev
= NULL
;
8984 "unable to register hwmon platform device\n");
8985 thinkpad_acpi_module_exit();
8988 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
8989 &dev_attr_thinkpad_acpi_pdev_name
);
8992 "unable to create sysfs hwmon device attributes\n");
8993 thinkpad_acpi_module_exit();
8996 tp_features
.sensors_pdev_attrs_registered
= 1;
8997 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
8998 if (IS_ERR(tpacpi_hwmon
)) {
8999 ret
= PTR_ERR(tpacpi_hwmon
);
9000 tpacpi_hwmon
= NULL
;
9001 printk(TPACPI_ERR
"unable to register hwmon device\n");
9002 thinkpad_acpi_module_exit();
9005 mutex_init(&tpacpi_inputdev_send_mutex
);
9006 tpacpi_inputdev
= input_allocate_device();
9007 if (!tpacpi_inputdev
) {
9008 printk(TPACPI_ERR
"unable to allocate input device\n");
9009 thinkpad_acpi_module_exit();
9012 /* Prepare input device, but don't register */
9013 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
9014 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
9015 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
9016 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
9017 thinkpad_id
.vendor
:
9019 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
9020 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
9021 tpacpi_inputdev
->dev
.parent
= &tpacpi_pdev
->dev
;
9023 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
9024 ret
= ibm_init(&ibms_init
[i
]);
9025 if (ret
>= 0 && *ibms_init
[i
].param
)
9026 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
9028 thinkpad_acpi_module_exit();
9033 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
9035 ret
= input_register_device(tpacpi_inputdev
);
9037 printk(TPACPI_ERR
"unable to register input device\n");
9038 thinkpad_acpi_module_exit();
9041 tp_features
.input_device_registered
= 1;
9047 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
9050 * This will autoload the driver in almost every ThinkPad
9051 * in widespread use.
9053 * Only _VERY_ old models, like the 240, 240x and 570 lack
9054 * the HKEY event interface.
9056 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
9059 * DMI matching for module autoloading
9061 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
9062 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
9064 * Only models listed in thinkwiki will be supported, so add yours
9065 * if it is not there yet.
9067 #define IBM_BIOS_MODULE_ALIAS(__type) \
9068 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
9070 /* Ancient thinkpad BIOSes have to be identified by
9071 * BIOS type or model number, and there are far less
9072 * BIOS types than model numbers... */
9073 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
9075 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
9076 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
9077 MODULE_DESCRIPTION(TPACPI_DESC
);
9078 MODULE_VERSION(TPACPI_VERSION
);
9079 MODULE_LICENSE("GPL");
9081 module_init(thinkpad_acpi_module_init
);
9082 module_exit(thinkpad_acpi_module_exit
);