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-20100220"
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 mode_t base_procfs_mode
;
297 struct ibm_struct
*data
;
308 u32 bright_16levels
:1;
309 u32 bright_acpimode
:1;
312 u32 fan_ctrl_status_undef
:1;
314 u32 beep_needs_two_args
:1;
315 u32 mixer_no_level_control
:1;
316 u32 input_device_registered
:1;
317 u32 platform_drv_registered
:1;
318 u32 platform_drv_attrs_registered
:1;
319 u32 sensors_pdrv_registered
:1;
320 u32 sensors_pdrv_attrs_registered
:1;
321 u32 sensors_pdev_attrs_registered
:1;
322 u32 hotkey_poll_active
:1;
326 u16 hotkey_mask_ff
:1;
327 u16 volume_ctrl_forbidden
:1;
330 struct thinkpad_id_data
{
331 unsigned int vendor
; /* ThinkPad vendor:
332 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
334 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
335 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
337 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
339 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
342 char *model_str
; /* ThinkPad T43 */
343 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
345 static struct thinkpad_id_data thinkpad_id
;
348 TPACPI_LIFE_INIT
= 0,
353 static int experimental
;
354 static u32 dbg_level
;
356 static struct workqueue_struct
*tpacpi_wq
;
364 /* Special LED class that can defer work */
365 struct tpacpi_led_classdev
{
366 struct led_classdev led_classdev
;
367 struct work_struct work
;
368 enum led_status_t new_state
;
372 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
373 static int dbg_wlswemul
;
374 static int tpacpi_wlsw_emulstate
;
375 static int dbg_bluetoothemul
;
376 static int tpacpi_bluetooth_emulstate
;
377 static int dbg_wwanemul
;
378 static int tpacpi_wwan_emulstate
;
379 static int dbg_uwbemul
;
380 static int tpacpi_uwb_emulstate
;
384 /*************************************************************************
388 #define dbg_printk(a_dbg_level, format, arg...) \
389 do { if (dbg_level & (a_dbg_level)) \
390 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
393 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
394 #define vdbg_printk dbg_printk
395 static const char *str_supported(int is_supported
);
397 #define vdbg_printk(a_dbg_level, format, arg...) \
401 static void tpacpi_log_usertask(const char * const what
)
403 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
404 what
, task_tgid_vnr(current
));
407 #define tpacpi_disclose_usertask(what, format, arg...) \
410 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
411 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
412 printk(TPACPI_DEBUG "%s: PID %d: " format, \
413 what, task_tgid_vnr(current), ## arg); \
418 * Quirk handling helpers
420 * ThinkPad IDs and versions seen in the field so far
421 * are two-characters from the set [0-9A-Z], i.e. base 36.
423 * We use values well outside that range as specials.
426 #define TPACPI_MATCH_ANY 0xffffU
427 #define TPACPI_MATCH_UNKNOWN 0U
429 /* TPID('1', 'Y') == 0x5931 */
430 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
432 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
433 { .vendor = PCI_VENDOR_ID_IBM, \
434 .bios = TPID(__id1, __id2), \
435 .ec = TPACPI_MATCH_ANY, \
436 .quirks = (__quirk) }
438 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
439 { .vendor = PCI_VENDOR_ID_LENOVO, \
440 .bios = TPID(__id1, __id2), \
441 .ec = TPACPI_MATCH_ANY, \
442 .quirks = (__quirk) }
444 #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \
445 { .vendor = PCI_VENDOR_ID_LENOVO, \
446 .bios = TPACPI_MATCH_ANY, \
447 .ec = TPID(__id1, __id2), \
448 .quirks = (__quirk) }
450 struct tpacpi_quirk
{
454 unsigned long quirks
;
458 * tpacpi_check_quirks() - search BIOS/EC version on a list
459 * @qlist: array of &struct tpacpi_quirk
460 * @qlist_size: number of elements in @qlist
462 * Iterates over a quirks list until one is found that matches the
463 * ThinkPad's vendor, BIOS and EC model.
465 * Returns 0 if nothing matches, otherwise returns the quirks field of
466 * the matching &struct tpacpi_quirk entry.
468 * The match criteria is: vendor, ec and bios much match.
470 static unsigned long __init
tpacpi_check_quirks(
471 const struct tpacpi_quirk
*qlist
,
472 unsigned int qlist_size
)
475 if ((qlist
->vendor
== thinkpad_id
.vendor
||
476 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
477 (qlist
->bios
== thinkpad_id
.bios_model
||
478 qlist
->bios
== TPACPI_MATCH_ANY
) &&
479 (qlist
->ec
== thinkpad_id
.ec_model
||
480 qlist
->ec
== TPACPI_MATCH_ANY
))
481 return qlist
->quirks
;
490 /****************************************************************************
491 ****************************************************************************
493 * ACPI Helpers and device model
495 ****************************************************************************
496 ****************************************************************************/
498 /*************************************************************************
502 static acpi_handle root_handle
;
504 #define TPACPI_HANDLE(object, parent, paths...) \
505 static acpi_handle object##_handle; \
506 static acpi_handle *object##_parent = &parent##_handle; \
507 static char *object##_path; \
508 static char *object##_paths[] = { paths }
510 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
511 "\\_SB.PCI.ISA.EC", /* 570 */
512 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
513 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
514 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
515 "\\_SB.PCI0.ICH3.EC0", /* R31 */
516 "\\_SB.PCI0.LPC.EC", /* all others */
519 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
520 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
522 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
524 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
525 "\\CMS", /* R40, R40e */
528 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
529 "^HKEY", /* R30, R31 */
530 "HKEY", /* all others */
533 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
534 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
535 "\\_SB.PCI0.VID0", /* 770e */
536 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
537 "\\_SB.PCI0.AGP.VID", /* all others */
541 /*************************************************************************
545 static int acpi_evalf(acpi_handle handle
,
546 void *res
, char *method
, char *fmt
, ...)
549 struct acpi_object_list params
;
550 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
551 struct acpi_buffer result
, *resultp
;
552 union acpi_object out_obj
;
560 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
573 params
.pointer
= &in_objs
[0];
580 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
581 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
583 /* add more types as needed */
585 printk(TPACPI_ERR
"acpi_evalf() called "
586 "with invalid format character '%c'\n", c
);
592 if (res_type
!= 'v') {
593 result
.length
= sizeof(out_obj
);
594 result
.pointer
= &out_obj
;
599 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
604 *(int *)res
= out_obj
.integer
.value
;
605 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
608 success
= status
== AE_OK
;
610 /* add more types as needed */
612 printk(TPACPI_ERR
"acpi_evalf() called "
613 "with invalid format character '%c'\n", res_type
);
617 if (!success
&& !quiet
)
618 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
619 method
, fmt0
, status
);
624 static int acpi_ec_read(int i
, u8
*p
)
629 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
633 if (ec_read(i
, p
) < 0)
640 static int acpi_ec_write(int i
, u8 v
)
643 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
646 if (ec_write(i
, v
) < 0)
653 static int issue_thinkpad_cmos_command(int cmos_cmd
)
658 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
664 /*************************************************************************
668 #define TPACPI_ACPIHANDLE_INIT(object) \
669 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
670 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
672 static void drv_acpi_handle_init(char *name
,
673 acpi_handle
*handle
, acpi_handle parent
,
674 char **paths
, int num_paths
, char **path
)
679 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
682 for (i
= 0; i
< num_paths
; i
++) {
683 status
= acpi_get_handle(parent
, paths
[i
], handle
);
684 if (ACPI_SUCCESS(status
)) {
686 dbg_printk(TPACPI_DBG_INIT
,
687 "Found ACPI handle %s for %s\n",
693 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
698 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
700 struct ibm_struct
*ibm
= data
;
702 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
705 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
708 ibm
->acpi
->notify(ibm
, event
);
711 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
718 if (!*ibm
->acpi
->handle
)
721 vdbg_printk(TPACPI_DBG_INIT
,
722 "setting up ACPI notify for %s\n", ibm
->name
);
724 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
726 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
731 ibm
->acpi
->device
->driver_data
= ibm
;
732 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
733 TPACPI_ACPI_EVENT_PREFIX
,
736 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
737 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
738 if (ACPI_FAILURE(status
)) {
739 if (status
== AE_ALREADY_EXISTS
) {
741 "another device driver is already "
742 "handling %s events\n", ibm
->name
);
745 "acpi_install_notify_handler(%s) failed: %d\n",
750 ibm
->flags
.acpi_notify_installed
= 1;
754 static int __init
tpacpi_device_add(struct acpi_device
*device
)
759 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
763 dbg_printk(TPACPI_DBG_INIT
,
764 "registering %s as an ACPI driver\n", ibm
->name
);
768 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
769 if (!ibm
->acpi
->driver
) {
771 "failed to allocate memory for ibm->acpi->driver\n");
775 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
776 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
778 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
780 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
782 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
784 kfree(ibm
->acpi
->driver
);
785 ibm
->acpi
->driver
= NULL
;
787 ibm
->flags
.acpi_driver_registered
= 1;
793 /****************************************************************************
794 ****************************************************************************
798 ****************************************************************************
799 ****************************************************************************/
801 static int dispatch_proc_show(struct seq_file
*m
, void *v
)
803 struct ibm_struct
*ibm
= m
->private;
805 if (!ibm
|| !ibm
->read
)
810 static int dispatch_proc_open(struct inode
*inode
, struct file
*file
)
812 return single_open(file
, dispatch_proc_show
, PDE(inode
)->data
);
815 static ssize_t
dispatch_proc_write(struct file
*file
,
816 const char __user
*userbuf
,
817 size_t count
, loff_t
*pos
)
819 struct ibm_struct
*ibm
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
823 if (!ibm
|| !ibm
->write
)
825 if (count
> PAGE_SIZE
- 2)
828 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
832 if (copy_from_user(kernbuf
, userbuf
, count
)) {
838 strcat(kernbuf
, ",");
839 ret
= ibm
->write(kernbuf
);
848 static const struct file_operations dispatch_proc_fops
= {
849 .owner
= THIS_MODULE
,
850 .open
= dispatch_proc_open
,
853 .release
= single_release
,
854 .write
= dispatch_proc_write
,
857 static char *next_cmd(char **cmds
)
862 while ((end
= strchr(start
, ',')) && end
== start
)
874 /****************************************************************************
875 ****************************************************************************
877 * Device model: input, hwmon and platform
879 ****************************************************************************
880 ****************************************************************************/
882 static struct platform_device
*tpacpi_pdev
;
883 static struct platform_device
*tpacpi_sensors_pdev
;
884 static struct device
*tpacpi_hwmon
;
885 static struct input_dev
*tpacpi_inputdev
;
886 static struct mutex tpacpi_inputdev_send_mutex
;
887 static LIST_HEAD(tpacpi_all_drivers
);
889 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
892 struct ibm_struct
*ibm
, *itmp
;
894 list_for_each_entry_safe(ibm
, itmp
,
898 (ibm
->suspend
)(state
);
904 static int tpacpi_resume_handler(struct platform_device
*pdev
)
906 struct ibm_struct
*ibm
, *itmp
;
908 list_for_each_entry_safe(ibm
, itmp
,
918 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
920 struct ibm_struct
*ibm
, *itmp
;
922 list_for_each_entry_safe(ibm
, itmp
,
930 static struct platform_driver tpacpi_pdriver
= {
932 .name
= TPACPI_DRVR_NAME
,
933 .owner
= THIS_MODULE
,
935 .suspend
= tpacpi_suspend_handler
,
936 .resume
= tpacpi_resume_handler
,
937 .shutdown
= tpacpi_shutdown_handler
,
940 static struct platform_driver tpacpi_hwmon_pdriver
= {
942 .name
= TPACPI_HWMON_DRVR_NAME
,
943 .owner
= THIS_MODULE
,
947 /*************************************************************************
948 * sysfs support helpers
951 struct attribute_set
{
952 unsigned int members
, max_members
;
953 struct attribute_group group
;
956 struct attribute_set_obj
{
957 struct attribute_set s
;
959 } __attribute__((packed
));
961 static struct attribute_set
*create_attr_set(unsigned int max_members
,
964 struct attribute_set_obj
*sobj
;
966 if (max_members
== 0)
969 /* Allocates space for implicit NULL at the end too */
970 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
971 max_members
* sizeof(struct attribute
*),
975 sobj
->s
.max_members
= max_members
;
976 sobj
->s
.group
.attrs
= &sobj
->a
;
977 sobj
->s
.group
.name
= name
;
982 #define destroy_attr_set(_set) \
985 /* not multi-threaded safe, use it in a single thread per set */
986 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
991 if (s
->members
>= s
->max_members
)
994 s
->group
.attrs
[s
->members
] = attr
;
1000 static int add_many_to_attr_set(struct attribute_set
*s
,
1001 struct attribute
**attr
,
1006 for (i
= 0; i
< count
; i
++) {
1007 res
= add_to_attr_set(s
, attr
[i
]);
1015 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
1017 sysfs_remove_group(kobj
, &s
->group
);
1018 destroy_attr_set(s
);
1021 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
1022 sysfs_create_group(_kobj, &_attr_set->group)
1024 static int parse_strtoul(const char *buf
,
1025 unsigned long max
, unsigned long *value
)
1029 while (*buf
&& isspace(*buf
))
1031 *value
= simple_strtoul(buf
, &endp
, 0);
1032 while (*endp
&& isspace(*endp
))
1034 if (*endp
|| *value
> max
)
1040 static void tpacpi_disable_brightness_delay(void)
1042 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
1043 printk(TPACPI_NOTICE
1044 "ACPI backlight control delay disabled\n");
1047 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
1049 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1050 union acpi_object
*obj
;
1053 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
1054 obj
= (union acpi_object
*)buffer
.pointer
;
1055 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
1056 printk(TPACPI_ERR
"Unknown _BCL data, "
1057 "please report this to %s\n", TPACPI_MAIL
);
1060 rc
= obj
->package
.count
;
1066 kfree(buffer
.pointer
);
1070 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1071 u32 lvl
, void *context
, void **rv
)
1073 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1074 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1076 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1077 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1078 BUG_ON(!rv
|| !*rv
);
1079 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1080 return AE_CTRL_TERMINATE
;
1087 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1089 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1093 void *bcl_ptr
= &bcl_levels
;
1096 TPACPI_ACPIHANDLE_INIT(vid
);
1102 * Search for a _BCL method, and execute it. This is safe on all
1103 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1104 * BIOS in ACPI backlight control mode. We do NOT have to care
1105 * about calling the _BCL method in an enabled video device, any
1106 * will do for our purposes.
1109 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1110 tpacpi_acpi_walk_find_bcl
, NULL
,
1113 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1114 tp_features
.bright_acpimode
= 1;
1115 return (bcl_levels
- 2);
1121 static int __init
tpacpi_new_rfkill(const unsigned int id
,
1122 struct rfkill
**rfk
,
1123 const enum rfkill_type rfktype
,
1125 const bool set_default
,
1126 int (*toggle_radio
)(void *, enum rfkill_state
),
1127 int (*get_state
)(void *, enum rfkill_state
*))
1130 enum rfkill_state initial_state
= RFKILL_STATE_SOFT_BLOCKED
;
1132 res
= get_state(NULL
, &initial_state
);
1135 "failed to read initial state for %s, error %d; "
1136 "will turn radio off\n", name
, res
);
1137 } else if (set_default
) {
1138 /* try to set the initial state as the default for the rfkill
1139 * type, since we ask the firmware to preserve it across S5 in
1141 if (rfkill_set_default(rfktype
,
1142 (initial_state
== RFKILL_STATE_UNBLOCKED
) ?
1143 RFKILL_STATE_UNBLOCKED
:
1144 RFKILL_STATE_SOFT_BLOCKED
) == -EPERM
)
1145 vdbg_printk(TPACPI_DBG_RFKILL
,
1146 "Default state for %s cannot be changed\n",
1150 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
1153 "failed to allocate memory for rfkill class\n");
1157 (*rfk
)->name
= name
;
1158 (*rfk
)->get_state
= get_state
;
1159 (*rfk
)->toggle_radio
= toggle_radio
;
1160 (*rfk
)->state
= initial_state
;
1162 res
= rfkill_register(*rfk
);
1165 "failed to register %s rfkill switch: %d\n",
1172 printk(TPACPI_INFO
"rfkill switch %s: radio is %sblocked\n",
1173 name
, (initial_state
== RFKILL_STATE_UNBLOCKED
) ?
1174 "un" : (initial_state
== RFKILL_STATE_SOFT_BLOCKED
) ?
1179 static void printk_deprecated_attribute(const char * const what
,
1180 const char * const details
)
1182 tpacpi_log_usertask("deprecated sysfs attribute");
1183 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1184 "will be removed. %s\n",
1188 static void printk_deprecated_rfkill_attribute(const char * const what
)
1190 printk_deprecated_attribute(what
,
1191 "Please switch to generic rfkill before year 2010");
1194 /*************************************************************************
1195 * thinkpad-acpi driver attributes
1198 /* interface_version --------------------------------------------------- */
1199 static ssize_t
tpacpi_driver_interface_version_show(
1200 struct device_driver
*drv
,
1203 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1206 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1207 tpacpi_driver_interface_version_show
, NULL
);
1209 /* debug_level --------------------------------------------------------- */
1210 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1213 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1216 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1217 const char *buf
, size_t count
)
1221 if (parse_strtoul(buf
, 0xffff, &t
))
1229 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1230 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1232 /* version ------------------------------------------------------------- */
1233 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1236 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1237 TPACPI_DESC
, TPACPI_VERSION
);
1240 static DRIVER_ATTR(version
, S_IRUGO
,
1241 tpacpi_driver_version_show
, NULL
);
1243 /* --------------------------------------------------------------------- */
1245 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1247 static void tpacpi_send_radiosw_update(void);
1249 /* wlsw_emulstate ------------------------------------------------------ */
1250 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1253 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1256 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1257 const char *buf
, size_t count
)
1261 if (parse_strtoul(buf
, 1, &t
))
1264 if (tpacpi_wlsw_emulstate
!= t
) {
1265 tpacpi_wlsw_emulstate
= !!t
;
1266 tpacpi_send_radiosw_update();
1268 tpacpi_wlsw_emulstate
= !!t
;
1273 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1274 tpacpi_driver_wlsw_emulstate_show
,
1275 tpacpi_driver_wlsw_emulstate_store
);
1277 /* bluetooth_emulstate ------------------------------------------------- */
1278 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1279 struct device_driver
*drv
,
1282 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1285 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1286 struct device_driver
*drv
,
1287 const char *buf
, size_t count
)
1291 if (parse_strtoul(buf
, 1, &t
))
1294 tpacpi_bluetooth_emulstate
= !!t
;
1299 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1300 tpacpi_driver_bluetooth_emulstate_show
,
1301 tpacpi_driver_bluetooth_emulstate_store
);
1303 /* wwan_emulstate ------------------------------------------------- */
1304 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1305 struct device_driver
*drv
,
1308 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1311 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1312 struct device_driver
*drv
,
1313 const char *buf
, size_t count
)
1317 if (parse_strtoul(buf
, 1, &t
))
1320 tpacpi_wwan_emulstate
= !!t
;
1325 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1326 tpacpi_driver_wwan_emulstate_show
,
1327 tpacpi_driver_wwan_emulstate_store
);
1329 /* uwb_emulstate ------------------------------------------------- */
1330 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1331 struct device_driver
*drv
,
1334 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1337 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1338 struct device_driver
*drv
,
1339 const char *buf
, size_t count
)
1343 if (parse_strtoul(buf
, 1, &t
))
1346 tpacpi_uwb_emulstate
= !!t
;
1351 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1352 tpacpi_driver_uwb_emulstate_show
,
1353 tpacpi_driver_uwb_emulstate_store
);
1356 /* --------------------------------------------------------------------- */
1358 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1359 &driver_attr_debug_level
, &driver_attr_version
,
1360 &driver_attr_interface_version
,
1363 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1369 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1370 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1374 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1375 if (!res
&& dbg_wlswemul
)
1376 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1377 if (!res
&& dbg_bluetoothemul
)
1378 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1379 if (!res
&& dbg_wwanemul
)
1380 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1381 if (!res
&& dbg_uwbemul
)
1382 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1388 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1392 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1393 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1395 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1396 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1397 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1398 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1399 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1403 /*************************************************************************
1408 * Table of recommended minimum BIOS versions
1410 * Reasons for listing:
1411 * 1. Stable BIOS, listed because the unknown ammount of
1412 * bugs and bad ACPI behaviour on older versions
1414 * 2. BIOS or EC fw with known bugs that trigger on Linux
1416 * 3. BIOS with known reduced functionality in older versions
1418 * We recommend the latest BIOS and EC version.
1419 * We only support the latest BIOS and EC fw version as a rule.
1421 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1422 * Information from users in ThinkWiki
1424 * WARNING: we use this table also to detect that the machine is
1425 * a ThinkPad in some cases, so don't remove entries lightly.
1428 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1429 { .vendor = (__v), \
1430 .bios = TPID(__id1, __id2), \
1431 .ec = TPACPI_MATCH_ANY, \
1432 .quirks = TPACPI_MATCH_ANY << 16 \
1433 | (__bv1) << 8 | (__bv2) }
1435 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1436 __eid, __ev1, __ev2) \
1437 { .vendor = (__v), \
1438 .bios = TPID(__bid1, __bid2), \
1440 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1441 | (__bv1) << 8 | (__bv2) }
1443 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1444 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1446 /* Outdated IBM BIOSes often lack the EC id string */
1447 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1448 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1449 __bv1, __bv2, TPID(__id1, __id2), \
1451 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1452 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1455 /* Outdated IBM BIOSes often lack the EC id string */
1456 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1457 __eid1, __eid2, __ev1, __ev2) \
1458 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1459 __bv1, __bv2, TPID(__eid1, __eid2), \
1461 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1462 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1465 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1466 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1468 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1469 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1470 __bv1, __bv2, TPID(__id1, __id2), \
1473 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1474 __eid1, __eid2, __ev1, __ev2) \
1475 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1476 __bv1, __bv2, TPID(__eid1, __eid2), \
1479 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1480 /* Numeric models ------------------ */
1481 /* FW MODEL BIOS VERS */
1482 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1483 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1484 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1485 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1486 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1487 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1488 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1489 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1490 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1492 /* A-series ------------------------- */
1493 /* FW MODEL BIOS VERS EC VERS */
1494 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1495 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1496 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1497 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1498 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1499 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1500 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1501 TPV_QI0('1', '3', '2', '0'), /* A22m */
1502 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1503 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1504 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1506 /* G-series ------------------------- */
1507 /* FW MODEL BIOS VERS */
1508 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1509 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1511 /* R-series, T-series --------------- */
1512 /* FW MODEL BIOS VERS EC VERS */
1513 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1514 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1515 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1516 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1517 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1518 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1519 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1520 T40/p, T41/p, T42/p (1) */
1521 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1522 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1523 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1524 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1526 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1527 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1528 TPV_QI0('1', '6', '3', '2'), /* T22 */
1529 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1530 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1531 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1533 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1534 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1535 TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */
1537 /* BIOS FW BIOS VERS EC FW EC VERS */
1538 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1539 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1541 /* X-series ------------------------- */
1542 /* FW MODEL BIOS VERS EC VERS */
1543 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1544 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1545 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1546 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1547 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1548 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1549 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1551 TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */
1552 TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */
1554 /* (0) - older versions lack DMI EC fw string and functionality */
1555 /* (1) - older versions known to lack functionality */
1566 static void __init
tpacpi_check_outdated_fw(void)
1568 unsigned long fwvers
;
1569 u16 ec_version
, bios_version
;
1571 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1572 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1577 bios_version
= fwvers
& 0xffffU
;
1578 ec_version
= (fwvers
>> 16) & 0xffffU
;
1580 /* note that unknown versions are set to 0x0000 and we use that */
1581 if ((bios_version
> thinkpad_id
.bios_release
) ||
1582 (ec_version
> thinkpad_id
.ec_release
&&
1583 ec_version
!= TPACPI_MATCH_ANY
)) {
1585 * The changelogs would let us track down the exact
1586 * reason, but it is just too much of a pain to track
1587 * it. We only list BIOSes that are either really
1588 * broken, or really stable to begin with, so it is
1589 * best if the user upgrades the firmware anyway.
1592 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1594 "WARNING: This firmware may be missing critical bug "
1595 "fixes and/or important features\n");
1599 static bool __init
tpacpi_is_fw_known(void)
1601 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1602 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1605 /****************************************************************************
1606 ****************************************************************************
1610 ****************************************************************************
1611 ****************************************************************************/
1613 /*************************************************************************
1614 * thinkpad-acpi init subdriver
1617 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1619 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1620 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1622 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1623 (thinkpad_id
.bios_version_str
) ?
1624 thinkpad_id
.bios_version_str
: "unknown",
1625 (thinkpad_id
.ec_version_str
) ?
1626 thinkpad_id
.ec_version_str
: "unknown");
1628 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1629 printk(TPACPI_INFO
"%s %s, model %s\n",
1630 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1631 "IBM" : ((thinkpad_id
.vendor
==
1632 PCI_VENDOR_ID_LENOVO
) ?
1633 "Lenovo" : "Unknown vendor"),
1634 thinkpad_id
.model_str
,
1635 (thinkpad_id
.nummodel_str
) ?
1636 thinkpad_id
.nummodel_str
: "unknown");
1638 tpacpi_check_outdated_fw();
1642 static int thinkpad_acpi_driver_read(struct seq_file
*m
)
1644 seq_printf(m
, "driver:\t\t%s\n", TPACPI_DESC
);
1645 seq_printf(m
, "version:\t%s\n", TPACPI_VERSION
);
1649 static struct ibm_struct thinkpad_acpi_driver_data
= {
1651 .read
= thinkpad_acpi_driver_read
,
1654 /*************************************************************************
1659 * ThinkPad firmware event model
1661 * The ThinkPad firmware has two main event interfaces: normal ACPI
1662 * notifications (which follow the ACPI standard), and a private event
1665 * The private event interface also issues events for the hotkeys. As
1666 * the driver gained features, the event handling code ended up being
1667 * built around the hotkey subdriver. This will need to be refactored
1668 * to a more formal event API eventually.
1670 * Some "hotkeys" are actually supposed to be used as event reports,
1671 * such as "brightness has changed", "volume has changed", depending on
1672 * the ThinkPad model and how the firmware is operating.
1674 * Unlike other classes, hotkey-class events have mask/unmask control on
1675 * non-ancient firmware. However, how it behaves changes a lot with the
1676 * firmware model and version.
1679 enum { /* hot key scan codes (derived from ACPI DSDT) */
1680 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1681 TP_ACPI_HOTKEYSCAN_FNF2
,
1682 TP_ACPI_HOTKEYSCAN_FNF3
,
1683 TP_ACPI_HOTKEYSCAN_FNF4
,
1684 TP_ACPI_HOTKEYSCAN_FNF5
,
1685 TP_ACPI_HOTKEYSCAN_FNF6
,
1686 TP_ACPI_HOTKEYSCAN_FNF7
,
1687 TP_ACPI_HOTKEYSCAN_FNF8
,
1688 TP_ACPI_HOTKEYSCAN_FNF9
,
1689 TP_ACPI_HOTKEYSCAN_FNF10
,
1690 TP_ACPI_HOTKEYSCAN_FNF11
,
1691 TP_ACPI_HOTKEYSCAN_FNF12
,
1692 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1693 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1694 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1695 TP_ACPI_HOTKEYSCAN_FNHOME
,
1696 TP_ACPI_HOTKEYSCAN_FNEND
,
1697 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1698 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1699 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1700 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1701 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1702 TP_ACPI_HOTKEYSCAN_MUTE
,
1703 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1706 enum { /* Keys/events available through NVRAM polling */
1707 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1708 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1711 enum { /* Positions of some of the keys in hotkey masks */
1712 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1713 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1714 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1715 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1716 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1717 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1718 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1719 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1720 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1721 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1722 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1725 enum { /* NVRAM to ACPI HKEY group map */
1726 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1727 TP_ACPI_HKEY_ZOOM_MASK
|
1728 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1729 TP_ACPI_HKEY_HIBERNATE_MASK
,
1730 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1731 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1732 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1733 TP_ACPI_HKEY_VOLDWN_MASK
|
1734 TP_ACPI_HKEY_MUTE_MASK
,
1737 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1738 struct tp_nvram_state
{
1739 u16 thinkpad_toggle
:1;
1741 u16 display_toggle
:1;
1742 u16 thinklight_toggle
:1;
1743 u16 hibernate_toggle
:1;
1744 u16 displayexp_toggle
:1;
1745 u16 display_state
:1;
1746 u16 brightness_toggle
:1;
1747 u16 volume_toggle
:1;
1750 u8 brightness_level
;
1754 /* kthread for the hotkey poller */
1755 static struct task_struct
*tpacpi_hotkey_task
;
1757 /* Acquired while the poller kthread is running, use to sync start/stop */
1758 static struct mutex hotkey_thread_mutex
;
1761 * Acquire mutex to write poller control variables as an
1764 * Increment hotkey_config_change when changing them if you
1765 * want the kthread to forget old state.
1767 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1769 static struct mutex hotkey_thread_data_mutex
;
1770 static unsigned int hotkey_config_change
;
1773 * hotkey poller control variables
1775 * Must be atomic or readers will also need to acquire mutex
1777 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1778 * should be used only when the changes need to be taken as
1779 * a block, OR when one needs to force the kthread to forget
1782 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1783 static unsigned int hotkey_poll_freq
= 10; /* Hz */
1785 #define HOTKEY_CONFIG_CRITICAL_START \
1787 mutex_lock(&hotkey_thread_data_mutex); \
1788 hotkey_config_change++; \
1790 #define HOTKEY_CONFIG_CRITICAL_END \
1791 mutex_unlock(&hotkey_thread_data_mutex);
1793 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1795 #define hotkey_source_mask 0U
1796 #define HOTKEY_CONFIG_CRITICAL_START
1797 #define HOTKEY_CONFIG_CRITICAL_END
1799 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1801 static struct mutex hotkey_mutex
;
1803 static enum { /* Reasons for waking up */
1804 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1805 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1806 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1807 } hotkey_wakeup_reason
;
1809 static int hotkey_autosleep_ack
;
1811 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
1812 static u32 hotkey_all_mask
; /* all events supported in fw */
1813 static u32 hotkey_reserved_mask
; /* events better left disabled */
1814 static u32 hotkey_driver_mask
; /* events needed by the driver */
1815 static u32 hotkey_user_mask
; /* events visible to userspace */
1816 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
1818 static unsigned int hotkey_report_mode
;
1820 static u16
*hotkey_keycode_map
;
1822 static struct attribute_set
*hotkey_dev_attributes
;
1824 static void tpacpi_driver_event(const unsigned int hkey_event
);
1825 static void hotkey_driver_event(const unsigned int scancode
);
1826 static void hotkey_poll_setup(const bool may_warn
);
1828 /* HKEY.MHKG() return bits */
1829 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1831 static int hotkey_get_wlsw(int *status
)
1833 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1835 *status
= !!tpacpi_wlsw_emulstate
;
1839 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1844 static int hotkey_get_tablet_mode(int *status
)
1848 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1851 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1856 * Reads current event mask from firmware, and updates
1857 * hotkey_acpi_mask accordingly. Also resets any bits
1858 * from hotkey_user_mask that are unavailable to be
1859 * delivered (shadow requirement of the userspace ABI).
1861 * Call with hotkey_mutex held
1863 static int hotkey_mask_get(void)
1865 if (tp_features
.hotkey_mask
) {
1868 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1871 hotkey_acpi_mask
= m
;
1873 /* no mask support doesn't mean no event support... */
1874 hotkey_acpi_mask
= hotkey_all_mask
;
1877 /* sync userspace-visible mask */
1878 hotkey_user_mask
&= (hotkey_acpi_mask
| hotkey_source_mask
);
1883 void static hotkey_mask_warn_incomplete_mask(void)
1885 /* log only what the user can fix... */
1886 const u32 wantedmask
= hotkey_driver_mask
&
1887 ~(hotkey_acpi_mask
| hotkey_source_mask
) &
1888 (hotkey_all_mask
| TPACPI_HKEY_NVRAM_KNOWN_MASK
);
1891 printk(TPACPI_NOTICE
1892 "required events 0x%08x not enabled!\n",
1897 * Set the firmware mask when supported
1899 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
1901 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
1903 * Call with hotkey_mutex held
1905 static int hotkey_mask_set(u32 mask
)
1910 const u32 fwmask
= mask
& ~hotkey_source_mask
;
1912 if (tp_features
.hotkey_mask
) {
1913 for (i
= 0; i
< 32; i
++) {
1914 if (!acpi_evalf(hkey_handle
,
1915 NULL
, "MHKM", "vdd", i
+ 1,
1916 !!(mask
& (1 << i
)))) {
1924 * We *must* make an inconditional call to hotkey_mask_get to
1925 * refresh hotkey_acpi_mask and update hotkey_user_mask
1927 * Take the opportunity to also log when we cannot _enable_
1930 if (!hotkey_mask_get() && !rc
&& (fwmask
& ~hotkey_acpi_mask
)) {
1931 printk(TPACPI_NOTICE
1932 "asked for hotkey mask 0x%08x, but "
1933 "firmware forced it to 0x%08x\n",
1934 fwmask
, hotkey_acpi_mask
);
1937 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
)
1938 hotkey_mask_warn_incomplete_mask();
1944 * Sets hotkey_user_mask and tries to set the firmware mask
1946 * Call with hotkey_mutex held
1948 static int hotkey_user_mask_set(const u32 mask
)
1952 /* Give people a chance to notice they are doing something that
1953 * is bound to go boom on their users sooner or later */
1954 if (!tp_warned
.hotkey_mask_ff
&&
1955 (mask
== 0xffff || mask
== 0xffffff ||
1956 mask
== 0xffffffff)) {
1957 tp_warned
.hotkey_mask_ff
= 1;
1958 printk(TPACPI_NOTICE
1959 "setting the hotkey mask to 0x%08x is likely "
1960 "not the best way to go about it\n", mask
);
1961 printk(TPACPI_NOTICE
1962 "please consider using the driver defaults, "
1963 "and refer to up-to-date thinkpad-acpi "
1967 /* Try to enable what the user asked for, plus whatever we need.
1968 * this syncs everything but won't enable bits in hotkey_user_mask */
1969 rc
= hotkey_mask_set((mask
| hotkey_driver_mask
) & ~hotkey_source_mask
);
1971 /* Enable the available bits in hotkey_user_mask */
1972 hotkey_user_mask
= mask
& (hotkey_acpi_mask
| hotkey_source_mask
);
1978 * Sets the driver hotkey mask.
1980 * Can be called even if the hotkey subdriver is inactive
1982 static int tpacpi_hotkey_driver_mask_set(const u32 mask
)
1986 /* Do the right thing if hotkey_init has not been called yet */
1987 if (!tp_features
.hotkey
) {
1988 hotkey_driver_mask
= mask
;
1992 mutex_lock(&hotkey_mutex
);
1994 HOTKEY_CONFIG_CRITICAL_START
1995 hotkey_driver_mask
= mask
;
1996 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1997 hotkey_source_mask
|= (mask
& ~hotkey_all_mask
);
1999 HOTKEY_CONFIG_CRITICAL_END
2001 rc
= hotkey_mask_set((hotkey_acpi_mask
| hotkey_driver_mask
) &
2002 ~hotkey_source_mask
);
2003 hotkey_poll_setup(true);
2005 mutex_unlock(&hotkey_mutex
);
2010 static int hotkey_status_get(int *status
)
2012 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
2018 static int hotkey_status_set(bool enable
)
2020 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
2026 static void tpacpi_input_send_tabletsw(void)
2030 if (tp_features
.hotkey_tablet
&&
2031 !hotkey_get_tablet_mode(&state
)) {
2032 mutex_lock(&tpacpi_inputdev_send_mutex
);
2034 input_report_switch(tpacpi_inputdev
,
2035 SW_TABLET_MODE
, !!state
);
2036 input_sync(tpacpi_inputdev
);
2038 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2042 /* Do NOT call without validating scancode first */
2043 static void tpacpi_input_send_key(const unsigned int scancode
)
2045 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
2047 if (keycode
!= KEY_RESERVED
) {
2048 mutex_lock(&tpacpi_inputdev_send_mutex
);
2050 input_report_key(tpacpi_inputdev
, keycode
, 1);
2051 if (keycode
== KEY_UNKNOWN
)
2052 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2054 input_sync(tpacpi_inputdev
);
2056 input_report_key(tpacpi_inputdev
, keycode
, 0);
2057 if (keycode
== KEY_UNKNOWN
)
2058 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2060 input_sync(tpacpi_inputdev
);
2062 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2066 /* Do NOT call without validating scancode first */
2067 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
2069 hotkey_driver_event(scancode
);
2070 if (hotkey_user_mask
& (1 << scancode
))
2071 tpacpi_input_send_key(scancode
);
2074 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2075 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2077 /* Do NOT call without validating scancode first */
2078 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2080 tpacpi_input_send_key_masked(scancode
);
2081 if (hotkey_report_mode
< 2) {
2082 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2083 0x80, TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
2087 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2091 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2092 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2093 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2094 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2095 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2096 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2098 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2099 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2100 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2102 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2103 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2104 n
->displayexp_toggle
=
2105 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2107 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2108 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2109 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2110 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2111 n
->brightness_toggle
=
2112 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2114 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2115 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2116 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2117 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2118 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2119 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2123 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2124 struct tp_nvram_state
*newn
,
2125 const u32 event_mask
)
2128 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2130 if ((event_mask & (1 << __scancode)) && \
2131 oldn->__member != newn->__member) \
2132 tpacpi_hotkey_send_key(__scancode); \
2135 #define TPACPI_MAY_SEND_KEY(__scancode) \
2137 if (event_mask & (1 << __scancode)) \
2138 tpacpi_hotkey_send_key(__scancode); \
2141 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2142 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2143 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2144 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2146 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2148 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2151 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2152 if (oldn
->mute
!= newn
->mute
) {
2153 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2155 if (oldn
->volume_level
> newn
->volume_level
) {
2156 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2157 } else if (oldn
->volume_level
< newn
->volume_level
) {
2158 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2159 } else if (oldn
->mute
== newn
->mute
) {
2160 /* repeated key presses that didn't change state */
2162 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2163 } else if (newn
->volume_level
!= 0) {
2164 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2166 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2171 /* handle brightness */
2172 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2173 if (oldn
->brightness_level
< newn
->brightness_level
) {
2174 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2175 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
2176 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2178 /* repeated key presses that didn't change state */
2179 if (newn
->brightness_level
!= 0) {
2180 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2182 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2187 #undef TPACPI_COMPARE_KEY
2188 #undef TPACPI_MAY_SEND_KEY
2194 * We track all events in hotkey_source_mask all the time, since
2195 * most of them are edge-based. We only issue those requested by
2196 * hotkey_user_mask or hotkey_driver_mask, though.
2198 static int hotkey_kthread(void *data
)
2200 struct tp_nvram_state s
[2];
2201 u32 poll_mask
, event_mask
;
2202 unsigned int si
, so
;
2204 unsigned int change_detector
, must_reset
;
2205 unsigned int poll_freq
;
2207 mutex_lock(&hotkey_thread_mutex
);
2209 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2218 /* Initial state for compares */
2219 mutex_lock(&hotkey_thread_data_mutex
);
2220 change_detector
= hotkey_config_change
;
2221 poll_mask
= hotkey_source_mask
;
2222 event_mask
= hotkey_source_mask
&
2223 (hotkey_driver_mask
| hotkey_user_mask
);
2224 poll_freq
= hotkey_poll_freq
;
2225 mutex_unlock(&hotkey_thread_data_mutex
);
2226 hotkey_read_nvram(&s
[so
], poll_mask
);
2228 while (!kthread_should_stop()) {
2230 if (likely(poll_freq
))
2233 t
= 100; /* should never happen... */
2235 t
= msleep_interruptible(t
);
2236 if (unlikely(kthread_should_stop()))
2238 must_reset
= try_to_freeze();
2239 if (t
> 0 && !must_reset
)
2242 mutex_lock(&hotkey_thread_data_mutex
);
2243 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2244 /* forget old state on thaw or config change */
2247 change_detector
= hotkey_config_change
;
2249 poll_mask
= hotkey_source_mask
;
2250 event_mask
= hotkey_source_mask
&
2251 (hotkey_driver_mask
| hotkey_user_mask
);
2252 poll_freq
= hotkey_poll_freq
;
2253 mutex_unlock(&hotkey_thread_data_mutex
);
2255 if (likely(poll_mask
)) {
2256 hotkey_read_nvram(&s
[si
], poll_mask
);
2257 if (likely(si
!= so
)) {
2258 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2268 mutex_unlock(&hotkey_thread_mutex
);
2272 /* call with hotkey_mutex held */
2273 static void hotkey_poll_stop_sync(void)
2275 if (tpacpi_hotkey_task
) {
2276 if (frozen(tpacpi_hotkey_task
) ||
2277 freezing(tpacpi_hotkey_task
))
2278 thaw_process(tpacpi_hotkey_task
);
2280 kthread_stop(tpacpi_hotkey_task
);
2281 tpacpi_hotkey_task
= NULL
;
2282 mutex_lock(&hotkey_thread_mutex
);
2283 /* at this point, the thread did exit */
2284 mutex_unlock(&hotkey_thread_mutex
);
2288 /* call with hotkey_mutex held */
2289 static void hotkey_poll_setup(const bool may_warn
)
2291 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2292 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2294 if (hotkey_poll_freq
> 0 &&
2295 (poll_driver_mask
||
2296 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2297 if (!tpacpi_hotkey_task
) {
2298 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2299 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2300 if (IS_ERR(tpacpi_hotkey_task
)) {
2301 tpacpi_hotkey_task
= NULL
;
2303 "could not create kernel thread "
2304 "for hotkey polling\n");
2308 hotkey_poll_stop_sync();
2309 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2310 hotkey_poll_freq
== 0) {
2311 printk(TPACPI_NOTICE
2312 "hot keys 0x%08x and/or events 0x%08x "
2313 "require polling, which is currently "
2315 poll_user_mask
, poll_driver_mask
);
2320 static void hotkey_poll_setup_safe(const bool may_warn
)
2322 mutex_lock(&hotkey_mutex
);
2323 hotkey_poll_setup(may_warn
);
2324 mutex_unlock(&hotkey_mutex
);
2327 /* call with hotkey_mutex held */
2328 static void hotkey_poll_set_freq(unsigned int freq
)
2331 hotkey_poll_stop_sync();
2333 hotkey_poll_freq
= freq
;
2336 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2338 static void hotkey_poll_setup(const bool __unused
)
2342 static void hotkey_poll_setup_safe(const bool __unused
)
2346 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2348 static int hotkey_inputdev_open(struct input_dev
*dev
)
2350 switch (tpacpi_lifecycle
) {
2351 case TPACPI_LIFE_INIT
:
2352 case TPACPI_LIFE_RUNNING
:
2353 hotkey_poll_setup_safe(false);
2355 case TPACPI_LIFE_EXITING
:
2359 /* Should only happen if tpacpi_lifecycle is corrupt */
2364 static void hotkey_inputdev_close(struct input_dev
*dev
)
2366 /* disable hotkey polling when possible */
2367 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
&&
2368 !(hotkey_source_mask
& hotkey_driver_mask
))
2369 hotkey_poll_setup_safe(false);
2372 /* sysfs hotkey enable ------------------------------------------------- */
2373 static ssize_t
hotkey_enable_show(struct device
*dev
,
2374 struct device_attribute
*attr
,
2379 printk_deprecated_attribute("hotkey_enable",
2380 "Hotkey reporting is always enabled");
2382 res
= hotkey_status_get(&status
);
2386 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2389 static ssize_t
hotkey_enable_store(struct device
*dev
,
2390 struct device_attribute
*attr
,
2391 const char *buf
, size_t count
)
2395 printk_deprecated_attribute("hotkey_enable",
2396 "Hotkeys can be disabled through hotkey_mask");
2398 if (parse_strtoul(buf
, 1, &t
))
2407 static struct device_attribute dev_attr_hotkey_enable
=
2408 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2409 hotkey_enable_show
, hotkey_enable_store
);
2411 /* sysfs hotkey mask --------------------------------------------------- */
2412 static ssize_t
hotkey_mask_show(struct device
*dev
,
2413 struct device_attribute
*attr
,
2416 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2419 static ssize_t
hotkey_mask_store(struct device
*dev
,
2420 struct device_attribute
*attr
,
2421 const char *buf
, size_t count
)
2426 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2429 if (mutex_lock_killable(&hotkey_mutex
))
2430 return -ERESTARTSYS
;
2432 res
= hotkey_user_mask_set(t
);
2434 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2435 hotkey_poll_setup(true);
2438 mutex_unlock(&hotkey_mutex
);
2440 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2442 return (res
) ? res
: count
;
2445 static struct device_attribute dev_attr_hotkey_mask
=
2446 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2447 hotkey_mask_show
, hotkey_mask_store
);
2449 /* sysfs hotkey bios_enabled ------------------------------------------- */
2450 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2451 struct device_attribute
*attr
,
2454 return sprintf(buf
, "0\n");
2457 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2458 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2460 /* sysfs hotkey bios_mask ---------------------------------------------- */
2461 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2462 struct device_attribute
*attr
,
2465 printk_deprecated_attribute("hotkey_bios_mask",
2466 "This attribute is useless.");
2467 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2470 static struct device_attribute dev_attr_hotkey_bios_mask
=
2471 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2473 /* sysfs hotkey all_mask ----------------------------------------------- */
2474 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2475 struct device_attribute
*attr
,
2478 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2479 hotkey_all_mask
| hotkey_source_mask
);
2482 static struct device_attribute dev_attr_hotkey_all_mask
=
2483 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2485 /* sysfs hotkey recommended_mask --------------------------------------- */
2486 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2487 struct device_attribute
*attr
,
2490 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2491 (hotkey_all_mask
| hotkey_source_mask
)
2492 & ~hotkey_reserved_mask
);
2495 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2496 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2497 hotkey_recommended_mask_show
, NULL
);
2499 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2501 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2502 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2503 struct device_attribute
*attr
,
2506 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2509 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2510 struct device_attribute
*attr
,
2511 const char *buf
, size_t count
)
2517 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2518 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2521 if (mutex_lock_killable(&hotkey_mutex
))
2522 return -ERESTARTSYS
;
2524 HOTKEY_CONFIG_CRITICAL_START
2525 hotkey_source_mask
= t
;
2526 HOTKEY_CONFIG_CRITICAL_END
2528 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2529 ~hotkey_source_mask
);
2530 hotkey_poll_setup(true);
2532 /* check if events needed by the driver got disabled */
2533 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2534 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2536 mutex_unlock(&hotkey_mutex
);
2539 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2540 "firmware event mask!\n");
2543 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2544 "some important events were disabled: "
2547 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2549 return (rc
< 0) ? rc
: count
;
2552 static struct device_attribute dev_attr_hotkey_source_mask
=
2553 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2554 hotkey_source_mask_show
, hotkey_source_mask_store
);
2556 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2557 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2558 struct device_attribute
*attr
,
2561 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2564 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2565 struct device_attribute
*attr
,
2566 const char *buf
, size_t count
)
2570 if (parse_strtoul(buf
, 25, &t
))
2573 if (mutex_lock_killable(&hotkey_mutex
))
2574 return -ERESTARTSYS
;
2576 hotkey_poll_set_freq(t
);
2577 hotkey_poll_setup(true);
2579 mutex_unlock(&hotkey_mutex
);
2581 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2586 static struct device_attribute dev_attr_hotkey_poll_freq
=
2587 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2588 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2590 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2592 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2593 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2594 struct device_attribute
*attr
,
2598 res
= hotkey_get_wlsw(&s
);
2602 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2605 static struct device_attribute dev_attr_hotkey_radio_sw
=
2606 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2608 static void hotkey_radio_sw_notify_change(void)
2610 if (tp_features
.hotkey_wlsw
)
2611 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2615 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2616 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2617 struct device_attribute
*attr
,
2621 res
= hotkey_get_tablet_mode(&s
);
2625 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2628 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2629 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2631 static void hotkey_tablet_mode_notify_change(void)
2633 if (tp_features
.hotkey_tablet
)
2634 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2635 "hotkey_tablet_mode");
2638 /* sysfs hotkey report_mode -------------------------------------------- */
2639 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2640 struct device_attribute
*attr
,
2643 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2644 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2647 static struct device_attribute dev_attr_hotkey_report_mode
=
2648 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2650 /* sysfs wakeup reason (pollable) -------------------------------------- */
2651 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2652 struct device_attribute
*attr
,
2655 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2658 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2659 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2661 static void hotkey_wakeup_reason_notify_change(void)
2663 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2667 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2668 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2669 struct device_attribute
*attr
,
2672 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2675 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2676 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2677 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2679 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2681 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2682 "wakeup_hotunplug_complete");
2685 /* --------------------------------------------------------------------- */
2687 static struct attribute
*hotkey_attributes
[] __initdata
= {
2688 &dev_attr_hotkey_enable
.attr
,
2689 &dev_attr_hotkey_bios_enabled
.attr
,
2690 &dev_attr_hotkey_bios_mask
.attr
,
2691 &dev_attr_hotkey_report_mode
.attr
,
2692 &dev_attr_hotkey_wakeup_reason
.attr
,
2693 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2694 &dev_attr_hotkey_mask
.attr
,
2695 &dev_attr_hotkey_all_mask
.attr
,
2696 &dev_attr_hotkey_recommended_mask
.attr
,
2697 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2698 &dev_attr_hotkey_source_mask
.attr
,
2699 &dev_attr_hotkey_poll_freq
.attr
,
2703 static void bluetooth_update_rfk(void);
2704 static void wan_update_rfk(void);
2705 static void uwb_update_rfk(void);
2706 static void tpacpi_send_radiosw_update(void)
2710 /* Sync these BEFORE sending any rfkill events */
2711 if (tp_features
.bluetooth
)
2712 bluetooth_update_rfk();
2713 if (tp_features
.wan
)
2715 if (tp_features
.uwb
)
2718 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2719 mutex_lock(&tpacpi_inputdev_send_mutex
);
2721 input_report_switch(tpacpi_inputdev
,
2722 SW_RFKILL_ALL
, !!wlsw
);
2723 input_sync(tpacpi_inputdev
);
2725 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2727 hotkey_radio_sw_notify_change();
2730 static void hotkey_exit(void)
2732 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2733 mutex_lock(&hotkey_mutex
);
2734 hotkey_poll_stop_sync();
2735 mutex_unlock(&hotkey_mutex
);
2738 if (hotkey_dev_attributes
)
2739 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2741 kfree(hotkey_keycode_map
);
2743 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
2744 "restoring original HKEY status and mask\n");
2745 /* yes, there is a bitwise or below, we want the
2746 * functions to be called even if one of them fail */
2747 if (((tp_features
.hotkey_mask
&&
2748 hotkey_mask_set(hotkey_orig_mask
)) |
2749 hotkey_status_set(false)) != 0)
2751 "failed to restore hot key mask "
2752 "to BIOS defaults\n");
2755 static void __init
hotkey_unmap(const unsigned int scancode
)
2757 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
2758 clear_bit(hotkey_keycode_map
[scancode
],
2759 tpacpi_inputdev
->keybit
);
2760 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
2766 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
2769 #define TPACPI_HK_Q_INIMASK 0x0001
2771 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
2772 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
2773 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
2774 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
2775 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
2776 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
2777 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
2778 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
2779 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
2780 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
2781 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
2782 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
2783 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
2784 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
2785 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
2786 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
2787 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
2788 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
2789 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
2790 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
2793 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2795 /* Requirements for changing the default keymaps:
2797 * 1. Many of the keys are mapped to KEY_RESERVED for very
2798 * good reasons. Do not change them unless you have deep
2799 * knowledge on the IBM and Lenovo ThinkPad firmware for
2800 * the various ThinkPad models. The driver behaves
2801 * differently for KEY_RESERVED: such keys have their
2802 * hot key mask *unset* in mask_recommended, and also
2803 * in the initial hot key mask programmed into the
2804 * firmware at driver load time, which means the firm-
2805 * ware may react very differently if you change them to
2808 * 2. You must be subscribed to the linux-thinkpad and
2809 * ibm-acpi-devel mailing lists, and you should read the
2810 * list archives since 2007 if you want to change the
2811 * keymaps. This requirement exists so that you will
2812 * know the past history of problems with the thinkpad-
2813 * acpi driver keymaps, and also that you will be
2814 * listening to any bug reports;
2816 * 3. Do not send thinkpad-acpi specific patches directly to
2817 * for merging, *ever*. Send them to the linux-acpi
2818 * mailinglist for comments. Merging is to be done only
2819 * through acpi-test and the ACPI maintainer.
2821 * If the above is too much to ask, don't change the keymap.
2822 * Ask the thinkpad-acpi maintainer to do it, instead.
2824 static u16 ibm_keycode_map
[] __initdata
= {
2825 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2826 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2827 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2828 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2830 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2831 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2832 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2833 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2835 /* brightness: firmware always reacts to them */
2836 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2837 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2839 /* Thinklight: firmware always react to it */
2840 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2842 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2843 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2845 /* Volume: firmware always react to it and reprograms
2846 * the built-in *extra* mixer. Never map it to control
2847 * another mixer by default. */
2848 KEY_RESERVED
, /* 0x14: VOLUME UP */
2849 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2850 KEY_RESERVED
, /* 0x16: MUTE */
2852 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2854 /* (assignments unknown, please report if found) */
2855 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2856 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2858 static u16 lenovo_keycode_map
[] __initdata
= {
2859 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2860 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2861 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2862 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2864 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2865 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2866 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2867 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2869 /* These should be enabled --only-- when ACPI video
2870 * is disabled (i.e. in "vendor" mode), and are handled
2871 * in a special way by the init code */
2872 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
2873 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
2875 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2877 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2878 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2880 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2881 * react to it and reprograms the built-in *extra* mixer.
2882 * Never map it to control another mixer by default.
2884 * T60?, T61, R60?, R61: firmware and EC tries to send
2885 * these over the regular keyboard, so these are no-ops,
2886 * but there are still weird bugs re. MUTE, so do not
2887 * change unless you get test reports from all Lenovo
2888 * models. May cause the BIOS to interfere with the
2891 KEY_RESERVED
, /* 0x14: VOLUME UP */
2892 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2893 KEY_RESERVED
, /* 0x16: MUTE */
2895 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2897 /* (assignments unknown, please report if found) */
2898 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2899 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2902 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2903 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2904 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2909 bool radiosw_state
= false;
2910 bool tabletsw_state
= false;
2912 unsigned long quirks
;
2914 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2915 "initializing hotkey subdriver\n");
2917 BUG_ON(!tpacpi_inputdev
);
2918 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2919 tpacpi_inputdev
->close
!= NULL
);
2921 TPACPI_ACPIHANDLE_INIT(hkey
);
2922 mutex_init(&hotkey_mutex
);
2924 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2925 mutex_init(&hotkey_thread_mutex
);
2926 mutex_init(&hotkey_thread_data_mutex
);
2929 /* hotkey not supported on 570 */
2930 tp_features
.hotkey
= hkey_handle
!= NULL
;
2932 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2934 str_supported(tp_features
.hotkey
));
2936 if (!tp_features
.hotkey
)
2939 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
2940 ARRAY_SIZE(tpacpi_hotkey_qtable
));
2942 tpacpi_disable_brightness_delay();
2944 /* MUST have enough space for all attributes to be added to
2945 * hotkey_dev_attributes */
2946 hotkey_dev_attributes
= create_attr_set(
2947 ARRAY_SIZE(hotkey_attributes
) + 2,
2949 if (!hotkey_dev_attributes
)
2951 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2953 ARRAY_SIZE(hotkey_attributes
));
2957 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
2958 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2959 for HKEY interface version 0x100 */
2960 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2961 if ((hkeyv
>> 8) != 1) {
2962 printk(TPACPI_ERR
"unknown version of the "
2963 "HKEY interface: 0x%x\n", hkeyv
);
2964 printk(TPACPI_ERR
"please report this to %s\n",
2968 * MHKV 0x100 in A31, R40, R40e,
2969 * T4x, X31, and later
2971 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2972 "firmware HKEY interface version: 0x%x\n",
2975 /* Paranoia check AND init hotkey_all_mask */
2976 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2979 "missing MHKA handler, "
2980 "please report this to %s\n",
2982 /* Fallback: pre-init for FN+F3,F4,F12 */
2983 hotkey_all_mask
= 0x080cU
;
2985 tp_features
.hotkey_mask
= 1;
2990 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2991 "hotkey masks are %s\n",
2992 str_supported(tp_features
.hotkey_mask
));
2994 /* Init hotkey_all_mask if not initialized yet */
2995 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
2996 (quirks
& TPACPI_HK_Q_INIMASK
))
2997 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
2999 /* Init hotkey_acpi_mask and hotkey_orig_mask */
3000 if (tp_features
.hotkey_mask
) {
3001 /* hotkey_source_mask *must* be zero for
3002 * the first hotkey_mask_get to return hotkey_orig_mask */
3003 res
= hotkey_mask_get();
3007 hotkey_orig_mask
= hotkey_acpi_mask
;
3009 hotkey_orig_mask
= hotkey_all_mask
;
3010 hotkey_acpi_mask
= hotkey_all_mask
;
3013 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3015 tp_features
.hotkey_wlsw
= 1;
3016 radiosw_state
= !!tpacpi_wlsw_emulstate
;
3018 "radio switch emulation enabled\n");
3021 /* Not all thinkpads have a hardware radio switch */
3022 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3023 tp_features
.hotkey_wlsw
= 1;
3024 radiosw_state
= !!status
;
3026 "radio switch found; radios are %s\n",
3027 enabled(status
, 0));
3029 if (tp_features
.hotkey_wlsw
)
3030 res
= add_to_attr_set(hotkey_dev_attributes
,
3031 &dev_attr_hotkey_radio_sw
.attr
);
3033 /* For X41t, X60t, X61t Tablets... */
3034 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3035 tp_features
.hotkey_tablet
= 1;
3036 tabletsw_state
= !!(status
& TP_HOTKEY_TABLET_MASK
);
3038 "possible tablet mode switch found; "
3039 "ThinkPad in %s mode\n",
3040 (tabletsw_state
) ? "tablet" : "laptop");
3041 res
= add_to_attr_set(hotkey_dev_attributes
,
3042 &dev_attr_hotkey_tablet_mode
.attr
);
3046 res
= register_attr_set_with_sysfs(
3047 hotkey_dev_attributes
,
3048 &tpacpi_pdev
->dev
.kobj
);
3052 /* Set up key map */
3054 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3056 if (!hotkey_keycode_map
) {
3058 "failed to allocate memory for key map\n");
3063 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
3064 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3065 "using Lenovo default hot key map\n");
3066 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
3067 TPACPI_HOTKEY_MAP_SIZE
);
3069 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3070 "using IBM default hot key map\n");
3071 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
3072 TPACPI_HOTKEY_MAP_SIZE
);
3075 input_set_capability(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
);
3076 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3077 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3078 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3079 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3080 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3081 input_set_capability(tpacpi_inputdev
, EV_KEY
,
3082 hotkey_keycode_map
[i
]);
3084 if (i
< sizeof(hotkey_reserved_mask
)*8)
3085 hotkey_reserved_mask
|= 1 << i
;
3089 if (tp_features
.hotkey_wlsw
) {
3090 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_RFKILL_ALL
);
3091 input_report_switch(tpacpi_inputdev
,
3092 SW_RFKILL_ALL
, radiosw_state
);
3094 if (tp_features
.hotkey_tablet
) {
3095 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_TABLET_MODE
);
3096 input_report_switch(tpacpi_inputdev
,
3097 SW_TABLET_MODE
, tabletsw_state
);
3100 /* Do not issue duplicate brightness change events to
3102 if (!tp_features
.bright_acpimode
)
3103 /* update bright_acpimode... */
3104 tpacpi_check_std_acpi_brightness_support();
3106 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
3108 "This ThinkPad has standard ACPI backlight "
3109 "brightness control, supported by the ACPI "
3111 printk(TPACPI_NOTICE
3112 "Disabling thinkpad-acpi brightness events "
3115 /* Disable brightness up/down on Lenovo thinkpads when
3116 * ACPI is handling them, otherwise it is plain impossible
3117 * for userspace to do something even remotely sane */
3118 hotkey_reserved_mask
|=
3119 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3120 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3121 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3122 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3125 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3126 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3128 & ~hotkey_reserved_mask
;
3130 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3131 "hotkey source mask 0x%08x, polling freq %u\n",
3132 hotkey_source_mask
, hotkey_poll_freq
);
3135 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3136 "enabling firmware HKEY event interface...\n");
3137 res
= hotkey_status_set(true);
3142 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3143 | hotkey_driver_mask
)
3144 & ~hotkey_source_mask
);
3145 if (res
< 0 && res
!= -ENXIO
) {
3149 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3150 & ~hotkey_reserved_mask
;
3151 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3152 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3153 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3155 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3156 "legacy ibm/hotkey event reporting over procfs %s\n",
3157 (hotkey_report_mode
< 2) ?
3158 "enabled" : "disabled");
3160 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3161 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3163 hotkey_poll_setup_safe(true);
3168 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3169 hotkey_dev_attributes
= NULL
;
3171 return (res
< 0)? res
: 1;
3174 static bool hotkey_notify_hotkey(const u32 hkey
,
3176 bool *ignore_acpi_ev
)
3178 /* 0x1000-0x1FFF: key presses */
3179 unsigned int scancode
= hkey
& 0xfff;
3180 *send_acpi_ev
= true;
3181 *ignore_acpi_ev
= false;
3183 if (scancode
> 0 && scancode
< 0x21) {
3185 if (!(hotkey_source_mask
& (1 << scancode
))) {
3186 tpacpi_input_send_key_masked(scancode
);
3187 *send_acpi_ev
= false;
3189 *ignore_acpi_ev
= true;
3196 static bool hotkey_notify_wakeup(const u32 hkey
,
3198 bool *ignore_acpi_ev
)
3200 /* 0x2000-0x2FFF: Wakeup reason */
3201 *send_acpi_ev
= true;
3202 *ignore_acpi_ev
= false;
3205 case TP_HKEY_EV_WKUP_S3_UNDOCK
: /* suspend, undock */
3206 case TP_HKEY_EV_WKUP_S4_UNDOCK
: /* hibernation, undock */
3207 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3208 *ignore_acpi_ev
= true;
3211 case TP_HKEY_EV_WKUP_S3_BAYEJ
: /* suspend, bay eject */
3212 case TP_HKEY_EV_WKUP_S4_BAYEJ
: /* hibernation, bay eject */
3213 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3214 *ignore_acpi_ev
= true;
3217 case TP_HKEY_EV_WKUP_S3_BATLOW
: /* Battery on critical low level/S3 */
3218 case TP_HKEY_EV_WKUP_S4_BATLOW
: /* Battery on critical low level/S4 */
3220 "EMERGENCY WAKEUP: battery almost empty\n");
3221 /* how to auto-heal: */
3222 /* 2313: woke up from S3, go to S4/S5 */
3223 /* 2413: woke up from S4, go to S5 */
3230 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3232 "woke up due to a hot-unplug "
3234 hotkey_wakeup_reason_notify_change();
3239 static bool hotkey_notify_usrevent(const u32 hkey
,
3241 bool *ignore_acpi_ev
)
3243 /* 0x5000-0x5FFF: human interface helpers */
3244 *send_acpi_ev
= true;
3245 *ignore_acpi_ev
= false;
3248 case TP_HKEY_EV_PEN_INSERTED
: /* X61t: tablet pen inserted into bay */
3249 case TP_HKEY_EV_PEN_REMOVED
: /* X61t: tablet pen removed from bay */
3252 case TP_HKEY_EV_TABLET_TABLET
: /* X41t-X61t: tablet mode */
3253 case TP_HKEY_EV_TABLET_NOTEBOOK
: /* X41t-X61t: normal mode */
3254 tpacpi_input_send_tabletsw();
3255 hotkey_tablet_mode_notify_change();
3256 *send_acpi_ev
= false;
3259 case TP_HKEY_EV_LID_CLOSE
: /* Lid closed */
3260 case TP_HKEY_EV_LID_OPEN
: /* Lid opened */
3261 case TP_HKEY_EV_BRGHT_CHANGED
: /* brightness changed */
3262 /* do not propagate these events */
3263 *ignore_acpi_ev
= true;
3271 static void thermal_dump_all_sensors(void);
3273 static bool hotkey_notify_thermal(const u32 hkey
,
3275 bool *ignore_acpi_ev
)
3279 /* 0x6000-0x6FFF: thermal alarms */
3280 *send_acpi_ev
= true;
3281 *ignore_acpi_ev
= false;
3284 case TP_HKEY_EV_THM_TABLE_CHANGED
:
3286 "EC reports that Thermal Table has changed\n");
3287 /* recommended action: do nothing, we don't have
3288 * Lenovo ATM information */
3290 case TP_HKEY_EV_ALARM_BAT_HOT
:
3292 "THERMAL ALARM: battery is too hot!\n");
3293 /* recommended action: warn user through gui */
3295 case TP_HKEY_EV_ALARM_BAT_XHOT
:
3297 "THERMAL EMERGENCY: battery is extremely hot!\n");
3298 /* recommended action: immediate sleep/hibernate */
3300 case TP_HKEY_EV_ALARM_SENSOR_HOT
:
3303 "a sensor reports something is too hot!\n");
3304 /* recommended action: warn user through gui, that */
3305 /* some internal component is too hot */
3307 case TP_HKEY_EV_ALARM_SENSOR_XHOT
:
3309 "THERMAL EMERGENCY: "
3310 "a sensor reports something is extremely hot!\n");
3311 /* recommended action: immediate sleep/hibernate */
3315 "THERMAL ALERT: unknown thermal alarm received\n");
3319 thermal_dump_all_sensors();
3324 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3328 bool ignore_acpi_ev
;
3331 if (event
!= 0x80) {
3333 "unknown HKEY notification event %d\n", event
);
3334 /* forward it to userspace, maybe it knows how to handle it */
3335 acpi_bus_generate_netlink_event(
3336 ibm
->acpi
->device
->pnp
.device_class
,
3337 dev_name(&ibm
->acpi
->device
->dev
),
3343 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3344 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3353 send_acpi_ev
= true;
3354 ignore_acpi_ev
= false;
3356 switch (hkey
>> 12) {
3358 /* 0x1000-0x1FFF: key presses */
3359 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3363 /* 0x2000-0x2FFF: Wakeup reason */
3364 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3368 /* 0x3000-0x3FFF: bay-related wakeups */
3370 case TP_HKEY_EV_BAYEJ_ACK
:
3371 hotkey_autosleep_ack
= 1;
3374 hotkey_wakeup_hotunplug_complete_notify_change();
3377 case TP_HKEY_EV_OPTDRV_EJ
:
3378 /* FIXME: kick libata if SATA link offline */
3386 /* 0x4000-0x4FFF: dock-related wakeups */
3387 if (hkey
== TP_HKEY_EV_UNDOCK_ACK
) {
3388 hotkey_autosleep_ack
= 1;
3391 hotkey_wakeup_hotunplug_complete_notify_change();
3398 /* 0x5000-0x5FFF: human interface helpers */
3399 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3403 /* 0x6000-0x6FFF: thermal alarms */
3404 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3408 /* 0x7000-0x7FFF: misc */
3409 if (tp_features
.hotkey_wlsw
&&
3410 hkey
== TP_HKEY_EV_RFKILL_CHANGED
) {
3411 tpacpi_send_radiosw_update();
3416 /* fallthrough to default */
3421 printk(TPACPI_NOTICE
3422 "unhandled HKEY event 0x%04x\n", hkey
);
3423 printk(TPACPI_NOTICE
3424 "please report the conditions when this "
3425 "event happened to %s\n", TPACPI_MAIL
);
3429 if (!ignore_acpi_ev
&&
3430 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3431 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3435 /* netlink events */
3436 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3437 acpi_bus_generate_netlink_event(
3438 ibm
->acpi
->device
->pnp
.device_class
,
3439 dev_name(&ibm
->acpi
->device
->dev
),
3445 static void hotkey_suspend(pm_message_t state
)
3447 /* Do these on suspend, we get the events on early resume! */
3448 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3449 hotkey_autosleep_ack
= 0;
3452 static void hotkey_resume(void)
3454 tpacpi_disable_brightness_delay();
3456 if (hotkey_status_set(true) < 0 ||
3457 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3459 "error while attempting to reset the event "
3460 "firmware interface\n");
3462 tpacpi_send_radiosw_update();
3463 hotkey_tablet_mode_notify_change();
3464 hotkey_wakeup_reason_notify_change();
3465 hotkey_wakeup_hotunplug_complete_notify_change();
3466 hotkey_poll_setup_safe(false);
3469 /* procfs -------------------------------------------------------------- */
3470 static int hotkey_read(struct seq_file
*m
)
3474 if (!tp_features
.hotkey
) {
3475 seq_printf(m
, "status:\t\tnot supported\n");
3479 if (mutex_lock_killable(&hotkey_mutex
))
3480 return -ERESTARTSYS
;
3481 res
= hotkey_status_get(&status
);
3483 res
= hotkey_mask_get();
3484 mutex_unlock(&hotkey_mutex
);
3488 seq_printf(m
, "status:\t\t%s\n", enabled(status
, 0));
3489 if (hotkey_all_mask
) {
3490 seq_printf(m
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3491 seq_printf(m
, "commands:\tenable, disable, reset, <mask>\n");
3493 seq_printf(m
, "mask:\t\tnot supported\n");
3494 seq_printf(m
, "commands:\tenable, disable, reset\n");
3500 static void hotkey_enabledisable_warn(bool enable
)
3502 tpacpi_log_usertask("procfs hotkey enable/disable");
3503 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3505 "hotkey enable/disable functionality has been "
3506 "removed from the driver. Hotkeys are always "
3509 "Please remove the hotkey=enable module "
3510 "parameter, it is deprecated. Hotkeys are always "
3514 static int hotkey_write(char *buf
)
3520 if (!tp_features
.hotkey
)
3523 if (mutex_lock_killable(&hotkey_mutex
))
3524 return -ERESTARTSYS
;
3526 mask
= hotkey_user_mask
;
3529 while ((cmd
= next_cmd(&buf
))) {
3530 if (strlencmp(cmd
, "enable") == 0) {
3531 hotkey_enabledisable_warn(1);
3532 } else if (strlencmp(cmd
, "disable") == 0) {
3533 hotkey_enabledisable_warn(0);
3535 } else if (strlencmp(cmd
, "reset") == 0) {
3536 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3537 & ~hotkey_reserved_mask
;
3538 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3540 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3549 tpacpi_disclose_usertask("procfs hotkey",
3550 "set mask to 0x%08x\n", mask
);
3551 res
= hotkey_user_mask_set(mask
);
3555 mutex_unlock(&hotkey_mutex
);
3559 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3560 {TPACPI_ACPI_HKEY_HID
, 0},
3564 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3565 .hid
= ibm_htk_device_ids
,
3566 .notify
= hotkey_notify
,
3567 .handle
= &hkey_handle
,
3568 .type
= ACPI_DEVICE_NOTIFY
,
3571 static struct ibm_struct hotkey_driver_data
= {
3573 .read
= hotkey_read
,
3574 .write
= hotkey_write
,
3575 .exit
= hotkey_exit
,
3576 .resume
= hotkey_resume
,
3577 .suspend
= hotkey_suspend
,
3578 .acpi
= &ibm_hotkey_acpidriver
,
3581 /*************************************************************************
3582 * Bluetooth subdriver
3586 /* ACPI GBDC/SBDC bits */
3587 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3588 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3589 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3590 0 = disable, 1 = enable */
3594 /* ACPI \BLTH commands */
3595 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3596 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3597 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3598 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3599 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3602 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3604 static struct rfkill
*tpacpi_bluetooth_rfkill
;
3606 static void bluetooth_suspend(pm_message_t state
)
3608 /* Try to make sure radio will resume powered off */
3609 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3610 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
))
3611 vdbg_printk(TPACPI_DBG_RFKILL
,
3612 "bluetooth power down on resume request failed\n");
3615 static int bluetooth_get_radiosw(void)
3619 if (!tp_features
.bluetooth
)
3622 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
3623 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3624 return RFKILL_STATE_HARD_BLOCKED
;
3626 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3627 if (dbg_bluetoothemul
)
3628 return (tpacpi_bluetooth_emulstate
) ?
3629 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3632 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3635 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3636 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3639 static void bluetooth_update_rfk(void)
3643 if (!tpacpi_bluetooth_rfkill
)
3646 status
= bluetooth_get_radiosw();
3649 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
3651 vdbg_printk(TPACPI_DBG_RFKILL
,
3652 "forced rfkill state to %d\n",
3656 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
3660 if (!tp_features
.bluetooth
)
3663 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3664 * reason to risk weird behaviour. */
3665 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3669 vdbg_printk(TPACPI_DBG_RFKILL
,
3670 "will %s bluetooth\n", radio_on
? "enable" : "disable");
3672 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3673 if (dbg_bluetoothemul
) {
3674 tpacpi_bluetooth_emulstate
= !!radio_on
;
3676 bluetooth_update_rfk();
3682 status
= TP_ACPI_BLUETOOTH_RADIOSSW
3683 | TP_ACPI_BLUETOOTH_RESUMECTRL
;
3687 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3691 bluetooth_update_rfk();
3696 /* sysfs bluetooth enable ---------------------------------------------- */
3697 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3698 struct device_attribute
*attr
,
3703 printk_deprecated_rfkill_attribute("bluetooth_enable");
3705 status
= bluetooth_get_radiosw();
3709 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3710 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3713 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3714 struct device_attribute
*attr
,
3715 const char *buf
, size_t count
)
3720 printk_deprecated_rfkill_attribute("bluetooth_enable");
3722 if (parse_strtoul(buf
, 1, &t
))
3725 tpacpi_disclose_usertask("bluetooth_enable", "set to %ld\n", t
);
3727 res
= bluetooth_set_radiosw(t
, 1);
3729 return (res
) ? res
: count
;
3732 static struct device_attribute dev_attr_bluetooth_enable
=
3733 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3734 bluetooth_enable_show
, bluetooth_enable_store
);
3736 /* --------------------------------------------------------------------- */
3738 static struct attribute
*bluetooth_attributes
[] = {
3739 &dev_attr_bluetooth_enable
.attr
,
3743 static const struct attribute_group bluetooth_attr_group
= {
3744 .attrs
= bluetooth_attributes
,
3747 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
3749 int bts
= bluetooth_get_radiosw();
3758 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
3760 dbg_printk(TPACPI_DBG_RFKILL
,
3761 "request to change radio state to %d\n", state
);
3762 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3765 static void bluetooth_shutdown(void)
3767 /* Order firmware to save current state to NVRAM */
3768 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3769 TP_ACPI_BLTH_SAVE_STATE
))
3770 printk(TPACPI_NOTICE
3771 "failed to save bluetooth state to NVRAM\n");
3773 vdbg_printk(TPACPI_DBG_RFKILL
,
3774 "bluestooth state saved to NVRAM\n");
3777 static void bluetooth_exit(void)
3779 bluetooth_shutdown();
3781 if (tpacpi_bluetooth_rfkill
)
3782 rfkill_unregister(tpacpi_bluetooth_rfkill
);
3784 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3785 &bluetooth_attr_group
);
3788 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3793 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3794 "initializing bluetooth subdriver\n");
3796 TPACPI_ACPIHANDLE_INIT(hkey
);
3798 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3799 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3800 tp_features
.bluetooth
= hkey_handle
&&
3801 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3803 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3804 "bluetooth is %s, status 0x%02x\n",
3805 str_supported(tp_features
.bluetooth
),
3808 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3809 if (dbg_bluetoothemul
) {
3810 tp_features
.bluetooth
= 1;
3812 "bluetooth switch emulation enabled\n");
3815 if (tp_features
.bluetooth
&&
3816 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
3817 /* no bluetooth hardware present in system */
3818 tp_features
.bluetooth
= 0;
3819 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3820 "bluetooth hardware not installed\n");
3823 if (!tp_features
.bluetooth
)
3826 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3827 &bluetooth_attr_group
);
3831 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3832 &tpacpi_bluetooth_rfkill
,
3833 RFKILL_TYPE_BLUETOOTH
,
3834 TPACPI_RFK_BLUETOOTH_SW_NAME
,
3836 tpacpi_bluetooth_rfk_set
,
3837 tpacpi_bluetooth_rfk_get
);
3846 /* procfs -------------------------------------------------------------- */
3847 static int bluetooth_read(struct seq_file
*m
)
3849 int status
= bluetooth_get_radiosw();
3851 if (!tp_features
.bluetooth
)
3852 seq_printf(m
, "status:\t\tnot supported\n");
3854 seq_printf(m
, "status:\t\t%s\n",
3855 (status
== RFKILL_STATE_UNBLOCKED
) ?
3856 "enabled" : "disabled");
3857 seq_printf(m
, "commands:\tenable, disable\n");
3863 static int bluetooth_write(char *buf
)
3868 if (!tp_features
.bluetooth
)
3871 while ((cmd
= next_cmd(&buf
))) {
3872 if (strlencmp(cmd
, "enable") == 0) {
3874 } else if (strlencmp(cmd
, "disable") == 0) {
3881 tpacpi_disclose_usertask("procfs bluetooth",
3883 state
? "enable" : "disable");
3884 bluetooth_set_radiosw(state
, 1);
3890 static struct ibm_struct bluetooth_driver_data
= {
3891 .name
= "bluetooth",
3892 .read
= bluetooth_read
,
3893 .write
= bluetooth_write
,
3894 .exit
= bluetooth_exit
,
3895 .suspend
= bluetooth_suspend
,
3896 .shutdown
= bluetooth_shutdown
,
3899 /*************************************************************************
3904 /* ACPI GWAN/SWAN bits */
3905 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3906 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3907 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3908 0 = disable, 1 = enable */
3911 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
3913 static struct rfkill
*tpacpi_wan_rfkill
;
3915 static void wan_suspend(pm_message_t state
)
3917 /* Try to make sure radio will resume powered off */
3918 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3919 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
))
3920 vdbg_printk(TPACPI_DBG_RFKILL
,
3921 "WWAN power down on resume request failed\n");
3924 static int wan_get_radiosw(void)
3928 if (!tp_features
.wan
)
3931 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3932 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3933 return RFKILL_STATE_HARD_BLOCKED
;
3935 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3937 return (tpacpi_wwan_emulstate
) ?
3938 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3941 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3944 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3945 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3948 static void wan_update_rfk(void)
3952 if (!tpacpi_wan_rfkill
)
3955 status
= wan_get_radiosw();
3958 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3960 vdbg_printk(TPACPI_DBG_RFKILL
,
3961 "forced rfkill state to %d\n",
3965 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3969 if (!tp_features
.wan
)
3972 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3973 * reason to risk weird behaviour. */
3974 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3978 vdbg_printk(TPACPI_DBG_RFKILL
,
3979 "will %s WWAN\n", radio_on
? "enable" : "disable");
3981 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3983 tpacpi_wwan_emulstate
= !!radio_on
;
3991 status
= TP_ACPI_WANCARD_RADIOSSW
3992 | TP_ACPI_WANCARD_RESUMECTRL
;
3996 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
4005 /* sysfs wan enable ---------------------------------------------------- */
4006 static ssize_t
wan_enable_show(struct device
*dev
,
4007 struct device_attribute
*attr
,
4012 printk_deprecated_rfkill_attribute("wwan_enable");
4014 status
= wan_get_radiosw();
4018 return snprintf(buf
, PAGE_SIZE
, "%d\n",
4019 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
4022 static ssize_t
wan_enable_store(struct device
*dev
,
4023 struct device_attribute
*attr
,
4024 const char *buf
, size_t count
)
4029 printk_deprecated_rfkill_attribute("wwan_enable");
4031 if (parse_strtoul(buf
, 1, &t
))
4034 tpacpi_disclose_usertask("wwan_enable", "set to %ld\n", t
);
4036 res
= wan_set_radiosw(t
, 1);
4038 return (res
) ? res
: count
;
4041 static struct device_attribute dev_attr_wan_enable
=
4042 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4043 wan_enable_show
, wan_enable_store
);
4045 /* --------------------------------------------------------------------- */
4047 static struct attribute
*wan_attributes
[] = {
4048 &dev_attr_wan_enable
.attr
,
4052 static const struct attribute_group wan_attr_group
= {
4053 .attrs
= wan_attributes
,
4056 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
4058 int wans
= wan_get_radiosw();
4067 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
4069 dbg_printk(TPACPI_DBG_RFKILL
,
4070 "request to change radio state to %d\n", state
);
4071 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
4074 static void wan_shutdown(void)
4076 /* Order firmware to save current state to NVRAM */
4077 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4078 TP_ACPI_WGSV_SAVE_STATE
))
4079 printk(TPACPI_NOTICE
4080 "failed to save WWAN state to NVRAM\n");
4082 vdbg_printk(TPACPI_DBG_RFKILL
,
4083 "WWAN state saved to NVRAM\n");
4086 static void wan_exit(void)
4090 if (tpacpi_wan_rfkill
)
4091 rfkill_unregister(tpacpi_wan_rfkill
);
4093 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4097 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4102 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4103 "initializing wan subdriver\n");
4105 TPACPI_ACPIHANDLE_INIT(hkey
);
4107 tp_features
.wan
= hkey_handle
&&
4108 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4110 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4111 "wan is %s, status 0x%02x\n",
4112 str_supported(tp_features
.wan
),
4115 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4117 tp_features
.wan
= 1;
4119 "wwan switch emulation enabled\n");
4122 if (tp_features
.wan
&&
4123 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4124 /* no wan hardware present in system */
4125 tp_features
.wan
= 0;
4126 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4127 "wan hardware not installed\n");
4130 if (!tp_features
.wan
)
4133 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4138 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4141 TPACPI_RFK_WWAN_SW_NAME
,
4144 tpacpi_wan_rfk_get
);
4153 /* procfs -------------------------------------------------------------- */
4154 static int wan_read(struct seq_file
*m
)
4156 int status
= wan_get_radiosw();
4158 tpacpi_disclose_usertask("procfs wan", "read");
4160 if (!tp_features
.wan
)
4161 seq_printf(m
, "status:\t\tnot supported\n");
4163 seq_printf(m
, "status:\t\t%s\n",
4164 (status
== RFKILL_STATE_UNBLOCKED
) ?
4165 "enabled" : "disabled");
4166 seq_printf(m
, "commands:\tenable, disable\n");
4172 static int wan_write(char *buf
)
4177 if (!tp_features
.wan
)
4180 while ((cmd
= next_cmd(&buf
))) {
4181 if (strlencmp(cmd
, "enable") == 0) {
4183 } else if (strlencmp(cmd
, "disable") == 0) {
4190 tpacpi_disclose_usertask("procfs wan",
4192 state
? "enable" : "disable");
4193 wan_set_radiosw(state
, 1);
4199 static struct ibm_struct wan_driver_data
= {
4204 .suspend
= wan_suspend
,
4205 .shutdown
= wan_shutdown
,
4208 /*************************************************************************
4213 /* ACPI GUWB/SUWB bits */
4214 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4215 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4218 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4220 static struct rfkill
*tpacpi_uwb_rfkill
;
4222 static int uwb_get_radiosw(void)
4226 if (!tp_features
.uwb
)
4229 /* WLSW overrides UWB in firmware/hardware, reflect that */
4230 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
4231 return RFKILL_STATE_HARD_BLOCKED
;
4233 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4235 return (tpacpi_uwb_emulstate
) ?
4236 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
4239 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4242 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4243 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
4246 static void uwb_update_rfk(void)
4250 if (!tpacpi_uwb_rfkill
)
4253 status
= uwb_get_radiosw();
4256 rfkill_force_state(tpacpi_uwb_rfkill
, status
);
4258 vdbg_printk(TPACPI_DBG_RFKILL
,
4259 "forced rfkill state to %d\n",
4263 static int uwb_set_radiosw(int radio_on
, int update_rfk
)
4267 if (!tp_features
.uwb
)
4270 /* WLSW overrides UWB in firmware/hardware, but there is no
4271 * reason to risk weird behaviour. */
4272 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
4276 vdbg_printk(TPACPI_DBG_RFKILL
,
4277 "will %s UWB\n", radio_on
? "enable" : "disable");
4279 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4281 tpacpi_uwb_emulstate
= !!radio_on
;
4288 status
= (radio_on
) ? TP_ACPI_UWB_RADIOSSW
: 0;
4289 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4298 /* --------------------------------------------------------------------- */
4300 static int tpacpi_uwb_rfk_get(void *data
, enum rfkill_state
*state
)
4302 int uwbs
= uwb_get_radiosw();
4311 static int tpacpi_uwb_rfk_set(void *data
, enum rfkill_state state
)
4313 dbg_printk(TPACPI_DBG_RFKILL
,
4314 "request to change radio state to %d\n", state
);
4315 return uwb_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
4318 static void uwb_exit(void)
4320 if (tpacpi_uwb_rfkill
)
4321 rfkill_unregister(tpacpi_uwb_rfkill
);
4324 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4329 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4330 "initializing uwb subdriver\n");
4332 TPACPI_ACPIHANDLE_INIT(hkey
);
4334 tp_features
.uwb
= hkey_handle
&&
4335 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4337 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4338 "uwb is %s, status 0x%02x\n",
4339 str_supported(tp_features
.uwb
),
4342 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4344 tp_features
.uwb
= 1;
4346 "uwb switch emulation enabled\n");
4349 if (tp_features
.uwb
&&
4350 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4351 /* no uwb hardware present in system */
4352 tp_features
.uwb
= 0;
4353 dbg_printk(TPACPI_DBG_INIT
,
4354 "uwb hardware not installed\n");
4357 if (!tp_features
.uwb
)
4360 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4363 TPACPI_RFK_UWB_SW_NAME
,
4366 tpacpi_uwb_rfk_get
);
4371 static struct ibm_struct uwb_driver_data
= {
4374 .flags
.experimental
= 1,
4377 /*************************************************************************
4381 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4383 enum video_access_mode
{
4384 TPACPI_VIDEO_NONE
= 0,
4385 TPACPI_VIDEO_570
, /* 570 */
4386 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4387 TPACPI_VIDEO_NEW
, /* all others */
4390 enum { /* video status flags, based on VIDEO_570 */
4391 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4392 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4393 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4396 enum { /* TPACPI_VIDEO_570 constants */
4397 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4398 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4399 * video_status_flags */
4400 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4401 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4404 static enum video_access_mode video_supported
;
4405 static int video_orig_autosw
;
4407 static int video_autosw_get(void);
4408 static int video_autosw_set(int enable
);
4410 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4412 static int __init
video_init(struct ibm_init_struct
*iibm
)
4416 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4418 TPACPI_ACPIHANDLE_INIT(vid
);
4419 TPACPI_ACPIHANDLE_INIT(vid2
);
4421 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4422 /* G41, assume IVGA doesn't change */
4423 vid_handle
= vid2_handle
;
4426 /* video switching not supported on R30, R31 */
4427 video_supported
= TPACPI_VIDEO_NONE
;
4428 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4430 video_supported
= TPACPI_VIDEO_570
;
4431 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4432 /* 600e/x, 770e, 770x */
4433 video_supported
= TPACPI_VIDEO_770
;
4436 video_supported
= TPACPI_VIDEO_NEW
;
4438 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4439 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4442 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4445 static void video_exit(void)
4447 dbg_printk(TPACPI_DBG_EXIT
,
4448 "restoring original video autoswitch mode\n");
4449 if (video_autosw_set(video_orig_autosw
))
4450 printk(TPACPI_ERR
"error while trying to restore original "
4451 "video autoswitch mode\n");
4454 static int video_outputsw_get(void)
4459 switch (video_supported
) {
4460 case TPACPI_VIDEO_570
:
4461 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4462 TP_ACPI_VIDEO_570_PHSCMD
))
4464 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4466 case TPACPI_VIDEO_770
:
4467 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4470 status
|= TP_ACPI_VIDEO_S_LCD
;
4471 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4474 status
|= TP_ACPI_VIDEO_S_CRT
;
4476 case TPACPI_VIDEO_NEW
:
4477 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4478 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4481 status
|= TP_ACPI_VIDEO_S_CRT
;
4483 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4484 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4487 status
|= TP_ACPI_VIDEO_S_LCD
;
4488 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4491 status
|= TP_ACPI_VIDEO_S_DVI
;
4500 static int video_outputsw_set(int status
)
4505 switch (video_supported
) {
4506 case TPACPI_VIDEO_570
:
4507 res
= acpi_evalf(NULL
, NULL
,
4508 "\\_SB.PHS2", "vdd",
4509 TP_ACPI_VIDEO_570_PHS2CMD
,
4510 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4512 case TPACPI_VIDEO_770
:
4513 autosw
= video_autosw_get();
4517 res
= video_autosw_set(1);
4520 res
= acpi_evalf(vid_handle
, NULL
,
4521 "ASWT", "vdd", status
* 0x100, 0);
4522 if (!autosw
&& video_autosw_set(autosw
)) {
4524 "video auto-switch left enabled due to error\n");
4528 case TPACPI_VIDEO_NEW
:
4529 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4530 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4536 return (res
)? 0 : -EIO
;
4539 static int video_autosw_get(void)
4543 switch (video_supported
) {
4544 case TPACPI_VIDEO_570
:
4545 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4548 case TPACPI_VIDEO_770
:
4549 case TPACPI_VIDEO_NEW
:
4550 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4560 static int video_autosw_set(int enable
)
4562 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4567 static int video_outputsw_cycle(void)
4569 int autosw
= video_autosw_get();
4575 switch (video_supported
) {
4576 case TPACPI_VIDEO_570
:
4577 res
= video_autosw_set(1);
4580 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4582 case TPACPI_VIDEO_770
:
4583 case TPACPI_VIDEO_NEW
:
4584 res
= video_autosw_set(1);
4587 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4592 if (!autosw
&& video_autosw_set(autosw
)) {
4594 "video auto-switch left enabled due to error\n");
4598 return (res
)? 0 : -EIO
;
4601 static int video_expand_toggle(void)
4603 switch (video_supported
) {
4604 case TPACPI_VIDEO_570
:
4605 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4607 case TPACPI_VIDEO_770
:
4608 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4610 case TPACPI_VIDEO_NEW
:
4611 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4619 static int video_read(struct seq_file
*m
)
4623 if (video_supported
== TPACPI_VIDEO_NONE
) {
4624 seq_printf(m
, "status:\t\tnot supported\n");
4628 /* Even reads can crash X.org, so... */
4629 if (!capable(CAP_SYS_ADMIN
))
4632 status
= video_outputsw_get();
4636 autosw
= video_autosw_get();
4640 seq_printf(m
, "status:\t\tsupported\n");
4641 seq_printf(m
, "lcd:\t\t%s\n", enabled(status
, 0));
4642 seq_printf(m
, "crt:\t\t%s\n", enabled(status
, 1));
4643 if (video_supported
== TPACPI_VIDEO_NEW
)
4644 seq_printf(m
, "dvi:\t\t%s\n", enabled(status
, 3));
4645 seq_printf(m
, "auto:\t\t%s\n", enabled(autosw
, 0));
4646 seq_printf(m
, "commands:\tlcd_enable, lcd_disable\n");
4647 seq_printf(m
, "commands:\tcrt_enable, crt_disable\n");
4648 if (video_supported
== TPACPI_VIDEO_NEW
)
4649 seq_printf(m
, "commands:\tdvi_enable, dvi_disable\n");
4650 seq_printf(m
, "commands:\tauto_enable, auto_disable\n");
4651 seq_printf(m
, "commands:\tvideo_switch, expand_toggle\n");
4656 static int video_write(char *buf
)
4659 int enable
, disable
, status
;
4662 if (video_supported
== TPACPI_VIDEO_NONE
)
4665 /* Even reads can crash X.org, let alone writes... */
4666 if (!capable(CAP_SYS_ADMIN
))
4672 while ((cmd
= next_cmd(&buf
))) {
4673 if (strlencmp(cmd
, "lcd_enable") == 0) {
4674 enable
|= TP_ACPI_VIDEO_S_LCD
;
4675 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4676 disable
|= TP_ACPI_VIDEO_S_LCD
;
4677 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4678 enable
|= TP_ACPI_VIDEO_S_CRT
;
4679 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4680 disable
|= TP_ACPI_VIDEO_S_CRT
;
4681 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4682 strlencmp(cmd
, "dvi_enable") == 0) {
4683 enable
|= TP_ACPI_VIDEO_S_DVI
;
4684 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4685 strlencmp(cmd
, "dvi_disable") == 0) {
4686 disable
|= TP_ACPI_VIDEO_S_DVI
;
4687 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4688 res
= video_autosw_set(1);
4691 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4692 res
= video_autosw_set(0);
4695 } else if (strlencmp(cmd
, "video_switch") == 0) {
4696 res
= video_outputsw_cycle();
4699 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4700 res
= video_expand_toggle();
4707 if (enable
|| disable
) {
4708 status
= video_outputsw_get();
4711 res
= video_outputsw_set((status
& ~disable
) | enable
);
4719 static struct ibm_struct video_driver_data
= {
4722 .write
= video_write
,
4726 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4728 /*************************************************************************
4729 * Light (thinklight) subdriver
4732 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4733 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4735 static int light_get_status(void)
4739 if (tp_features
.light_status
) {
4740 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4748 static int light_set_status(int status
)
4752 if (tp_features
.light
) {
4754 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4756 TP_CMOS_THINKLIGHT_ON
:
4757 TP_CMOS_THINKLIGHT_OFF
);
4759 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4762 return (rc
)? 0 : -EIO
;
4768 static void light_set_status_worker(struct work_struct
*work
)
4770 struct tpacpi_led_classdev
*data
=
4771 container_of(work
, struct tpacpi_led_classdev
, work
);
4773 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4774 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4777 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4778 enum led_brightness brightness
)
4780 struct tpacpi_led_classdev
*data
=
4781 container_of(led_cdev
,
4782 struct tpacpi_led_classdev
,
4784 data
->new_state
= (brightness
!= LED_OFF
) ?
4785 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4786 queue_work(tpacpi_wq
, &data
->work
);
4789 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4791 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4794 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4796 .name
= "tpacpi::thinklight",
4797 .brightness_set
= &light_sysfs_set
,
4798 .brightness_get
= &light_sysfs_get
,
4802 static int __init
light_init(struct ibm_init_struct
*iibm
)
4806 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4808 TPACPI_ACPIHANDLE_INIT(ledb
);
4809 TPACPI_ACPIHANDLE_INIT(lght
);
4810 TPACPI_ACPIHANDLE_INIT(cmos
);
4811 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4813 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4814 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4816 if (tp_features
.light
)
4817 /* light status not supported on
4818 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4819 tp_features
.light_status
=
4820 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4822 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4823 str_supported(tp_features
.light
),
4824 str_supported(tp_features
.light_status
));
4826 if (!tp_features
.light
)
4829 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4830 &tpacpi_led_thinklight
.led_classdev
);
4833 tp_features
.light
= 0;
4834 tp_features
.light_status
= 0;
4842 static void light_exit(void)
4844 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4845 if (work_pending(&tpacpi_led_thinklight
.work
))
4846 flush_workqueue(tpacpi_wq
);
4849 static int light_read(struct seq_file
*m
)
4853 if (!tp_features
.light
) {
4854 seq_printf(m
, "status:\t\tnot supported\n");
4855 } else if (!tp_features
.light_status
) {
4856 seq_printf(m
, "status:\t\tunknown\n");
4857 seq_printf(m
, "commands:\ton, off\n");
4859 status
= light_get_status();
4862 seq_printf(m
, "status:\t\t%s\n", onoff(status
, 0));
4863 seq_printf(m
, "commands:\ton, off\n");
4869 static int light_write(char *buf
)
4874 if (!tp_features
.light
)
4877 while ((cmd
= next_cmd(&buf
))) {
4878 if (strlencmp(cmd
, "on") == 0) {
4880 } else if (strlencmp(cmd
, "off") == 0) {
4886 return light_set_status(newstatus
);
4889 static struct ibm_struct light_driver_data
= {
4892 .write
= light_write
,
4896 /*************************************************************************
4900 /* sysfs cmos_command -------------------------------------------------- */
4901 static ssize_t
cmos_command_store(struct device
*dev
,
4902 struct device_attribute
*attr
,
4903 const char *buf
, size_t count
)
4905 unsigned long cmos_cmd
;
4908 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4911 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4912 return (res
)? res
: count
;
4915 static struct device_attribute dev_attr_cmos_command
=
4916 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4918 /* --------------------------------------------------------------------- */
4920 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4924 vdbg_printk(TPACPI_DBG_INIT
,
4925 "initializing cmos commands subdriver\n");
4927 TPACPI_ACPIHANDLE_INIT(cmos
);
4929 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4930 str_supported(cmos_handle
!= NULL
));
4932 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4936 return (cmos_handle
)? 0 : 1;
4939 static void cmos_exit(void)
4941 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4944 static int cmos_read(struct seq_file
*m
)
4946 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4947 R30, R31, T20-22, X20-21 */
4949 seq_printf(m
, "status:\t\tnot supported\n");
4951 seq_printf(m
, "status:\t\tsupported\n");
4952 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4958 static int cmos_write(char *buf
)
4963 while ((cmd
= next_cmd(&buf
))) {
4964 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4965 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4970 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4978 static struct ibm_struct cmos_driver_data
= {
4981 .write
= cmos_write
,
4985 /*************************************************************************
4989 enum led_access_mode
{
4990 TPACPI_LED_NONE
= 0,
4991 TPACPI_LED_570
, /* 570 */
4992 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4993 TPACPI_LED_NEW
, /* all others */
4996 enum { /* For TPACPI_LED_OLD */
4997 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4998 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4999 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
5002 static enum led_access_mode led_supported
;
5004 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
5005 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
5006 /* T20-22, X20-21 */
5007 "LED", /* all others */
5010 #define TPACPI_LED_NUMLEDS 16
5011 static struct tpacpi_led_classdev
*tpacpi_leds
;
5012 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
5013 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
5014 /* there's a limit of 19 chars + NULL before 2.6.26 */
5016 "tpacpi:orange:batt",
5017 "tpacpi:green:batt",
5018 "tpacpi::dock_active",
5019 "tpacpi::bay_active",
5020 "tpacpi::dock_batt",
5021 "tpacpi::unknown_led",
5023 "tpacpi::dock_status1",
5024 "tpacpi::dock_status2",
5025 "tpacpi::unknown_led2",
5026 "tpacpi::unknown_led3",
5027 "tpacpi::thinkvantage",
5029 #define TPACPI_SAFE_LEDS 0x1081U
5031 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
5033 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5036 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
5040 static int led_get_status(const unsigned int led
)
5043 enum led_status_t led_s
;
5045 switch (led_supported
) {
5046 case TPACPI_LED_570
:
5047 if (!acpi_evalf(ec_handle
,
5048 &status
, "GLED", "dd", 1 << led
))
5050 led_s
= (status
== 0)?
5055 tpacpi_led_state_cache
[led
] = led_s
;
5064 static int led_set_status(const unsigned int led
,
5065 const enum led_status_t ledstatus
)
5067 /* off, on, blink. Index is led_status_t */
5068 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
5069 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
5073 switch (led_supported
) {
5074 case TPACPI_LED_570
:
5076 if (unlikely(led
> 7))
5078 if (unlikely(tpacpi_is_led_restricted(led
)))
5080 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5081 (1 << led
), led_sled_arg1
[ledstatus
]))
5084 case TPACPI_LED_OLD
:
5085 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
5086 if (unlikely(led
> 7))
5088 if (unlikely(tpacpi_is_led_restricted(led
)))
5090 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
5092 rc
= ec_write(TPACPI_LED_EC_HLBL
,
5093 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5095 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5096 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5098 case TPACPI_LED_NEW
:
5100 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5102 if (unlikely(tpacpi_is_led_restricted(led
)))
5104 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5105 led
, led_led_arg1
[ledstatus
]))
5113 tpacpi_led_state_cache
[led
] = ledstatus
;
5118 static void led_set_status_worker(struct work_struct
*work
)
5120 struct tpacpi_led_classdev
*data
=
5121 container_of(work
, struct tpacpi_led_classdev
, work
);
5123 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5124 led_set_status(data
->led
, data
->new_state
);
5127 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5128 enum led_brightness brightness
)
5130 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5131 struct tpacpi_led_classdev
, led_classdev
);
5133 if (brightness
== LED_OFF
)
5134 data
->new_state
= TPACPI_LED_OFF
;
5135 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5136 data
->new_state
= TPACPI_LED_ON
;
5138 data
->new_state
= TPACPI_LED_BLINK
;
5140 queue_work(tpacpi_wq
, &data
->work
);
5143 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5144 unsigned long *delay_on
, unsigned long *delay_off
)
5146 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5147 struct tpacpi_led_classdev
, led_classdev
);
5149 /* Can we choose the flash rate? */
5150 if (*delay_on
== 0 && *delay_off
== 0) {
5151 /* yes. set them to the hardware blink rate (1 Hz) */
5152 *delay_on
= 500; /* ms */
5153 *delay_off
= 500; /* ms */
5154 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5157 data
->new_state
= TPACPI_LED_BLINK
;
5158 queue_work(tpacpi_wq
, &data
->work
);
5163 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5167 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5168 struct tpacpi_led_classdev
, led_classdev
);
5170 rc
= led_get_status(data
->led
);
5172 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5173 rc
= LED_OFF
; /* no error handling in led class :( */
5180 static void led_exit(void)
5184 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5185 if (tpacpi_leds
[i
].led_classdev
.name
)
5186 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5192 static int __init
tpacpi_init_led(unsigned int led
)
5196 tpacpi_leds
[led
].led
= led
;
5198 /* LEDs with no name don't get registered */
5199 if (!tpacpi_led_names
[led
])
5202 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5203 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5204 if (led_supported
== TPACPI_LED_570
)
5205 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5208 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5210 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5212 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5213 &tpacpi_leds
[led
].led_classdev
);
5215 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5220 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5221 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5222 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5223 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5225 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5226 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5227 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5228 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5229 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5230 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5231 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5232 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5234 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5235 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5236 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5237 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5238 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5240 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5241 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5242 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5243 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5245 /* (1) - may have excess leds enabled on MSB */
5247 /* Defaults (order matters, keep last, don't reorder!) */
5249 .vendor
= PCI_VENDOR_ID_LENOVO
,
5250 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5253 { /* IBM ThinkPads with no EC version string */
5254 .vendor
= PCI_VENDOR_ID_IBM
,
5255 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5258 { /* IBM ThinkPads with EC version string */
5259 .vendor
= PCI_VENDOR_ID_IBM
,
5260 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5265 #undef TPACPI_LEDQ_IBM
5266 #undef TPACPI_LEDQ_LNV
5268 static int __init
led_init(struct ibm_init_struct
*iibm
)
5272 unsigned long useful_leds
;
5274 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5276 TPACPI_ACPIHANDLE_INIT(led
);
5279 /* led not supported on R30, R31 */
5280 led_supported
= TPACPI_LED_NONE
;
5281 else if (strlencmp(led_path
, "SLED") == 0)
5283 led_supported
= TPACPI_LED_570
;
5284 else if (strlencmp(led_path
, "SYSL") == 0)
5285 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5286 led_supported
= TPACPI_LED_OLD
;
5289 led_supported
= TPACPI_LED_NEW
;
5291 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5292 str_supported(led_supported
), led_supported
);
5294 if (led_supported
== TPACPI_LED_NONE
)
5297 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5300 printk(TPACPI_ERR
"Out of memory for LED data\n");
5304 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5305 ARRAY_SIZE(led_useful_qtable
));
5307 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5308 if (!tpacpi_is_led_restricted(i
) &&
5309 test_bit(i
, &useful_leds
)) {
5310 rc
= tpacpi_init_led(i
);
5318 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5319 printk(TPACPI_NOTICE
5320 "warning: userspace override of important "
5321 "firmware LEDs is enabled\n");
5326 #define str_led_status(s) \
5327 ((s) == TPACPI_LED_OFF ? "off" : \
5328 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5330 static int led_read(struct seq_file
*m
)
5332 if (!led_supported
) {
5333 seq_printf(m
, "status:\t\tnot supported\n");
5336 seq_printf(m
, "status:\t\tsupported\n");
5338 if (led_supported
== TPACPI_LED_570
) {
5341 for (i
= 0; i
< 8; i
++) {
5342 status
= led_get_status(i
);
5345 seq_printf(m
, "%d:\t\t%s\n",
5346 i
, str_led_status(status
));
5350 seq_printf(m
, "commands:\t"
5351 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5356 static int led_write(char *buf
)
5360 enum led_status_t s
;
5365 while ((cmd
= next_cmd(&buf
))) {
5366 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5369 if (strstr(cmd
, "off")) {
5371 } else if (strstr(cmd
, "on")) {
5373 } else if (strstr(cmd
, "blink")) {
5374 s
= TPACPI_LED_BLINK
;
5379 rc
= led_set_status(led
, s
);
5387 static struct ibm_struct led_driver_data
= {
5394 /*************************************************************************
5398 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5400 #define TPACPI_BEEP_Q1 0x0001
5402 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5403 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5404 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5407 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5409 unsigned long quirks
;
5411 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5413 TPACPI_ACPIHANDLE_INIT(beep
);
5415 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5416 str_supported(beep_handle
!= NULL
));
5418 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5419 ARRAY_SIZE(beep_quirk_table
));
5421 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5423 return (beep_handle
)? 0 : 1;
5426 static int beep_read(struct seq_file
*m
)
5429 seq_printf(m
, "status:\t\tnot supported\n");
5431 seq_printf(m
, "status:\t\tsupported\n");
5432 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5438 static int beep_write(char *buf
)
5446 while ((cmd
= next_cmd(&buf
))) {
5447 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5448 beep_cmd
>= 0 && beep_cmd
<= 17) {
5452 if (tp_features
.beep_needs_two_args
) {
5453 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5457 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5466 static struct ibm_struct beep_driver_data
= {
5469 .write
= beep_write
,
5472 /*************************************************************************
5476 enum thermal_access_mode
{
5477 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5478 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5479 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5480 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5481 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5484 enum { /* TPACPI_THERMAL_TPEC_* */
5485 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5486 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5487 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5489 TPACPI_THERMAL_SENSOR_NA
= -128000, /* Sensor not available */
5493 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5494 struct ibm_thermal_sensors_struct
{
5495 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5498 static enum thermal_access_mode thermal_read_mode
;
5500 /* idx is zero-based */
5501 static int thermal_get_sensor(int idx
, s32
*value
)
5507 t
= TP_EC_THERMAL_TMP0
;
5509 switch (thermal_read_mode
) {
5510 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5511 case TPACPI_THERMAL_TPEC_16
:
5512 if (idx
>= 8 && idx
<= 15) {
5513 t
= TP_EC_THERMAL_TMP8
;
5518 case TPACPI_THERMAL_TPEC_8
:
5520 if (!acpi_ec_read(t
+ idx
, &tmp
))
5522 *value
= tmp
* 1000;
5527 case TPACPI_THERMAL_ACPI_UPDT
:
5529 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5530 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5532 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5534 *value
= (t
- 2732) * 100;
5539 case TPACPI_THERMAL_ACPI_TMP07
:
5541 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5542 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5544 if (t
> 127 || t
< -127)
5545 t
= TP_EC_THERMAL_TMP_NA
;
5551 case TPACPI_THERMAL_NONE
:
5559 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5570 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5573 for (i
= 0 ; i
< n
; i
++) {
5574 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5582 static void thermal_dump_all_sensors(void)
5585 struct ibm_thermal_sensors_struct t
;
5587 n
= thermal_get_sensors(&t
);
5591 printk(TPACPI_NOTICE
5592 "temperatures (Celsius):");
5594 for (i
= 0; i
< n
; i
++) {
5595 if (t
.temp
[i
] != TPACPI_THERMAL_SENSOR_NA
)
5596 printk(KERN_CONT
" %d", (int)(t
.temp
[i
] / 1000));
5598 printk(KERN_CONT
" N/A");
5601 printk(KERN_CONT
"\n");
5604 /* sysfs temp##_input -------------------------------------------------- */
5606 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5607 struct device_attribute
*attr
,
5610 struct sensor_device_attribute
*sensor_attr
=
5611 to_sensor_dev_attr(attr
);
5612 int idx
= sensor_attr
->index
;
5616 res
= thermal_get_sensor(idx
, &value
);
5619 if (value
== TPACPI_THERMAL_SENSOR_NA
)
5622 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5625 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5626 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5627 thermal_temp_input_show, NULL, _idxB)
5629 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5630 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5631 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5632 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5633 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5634 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5635 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5636 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5637 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5638 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5639 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5640 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5641 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5642 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5643 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5644 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5645 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5648 #define THERMAL_ATTRS(X) \
5649 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5651 static struct attribute
*thermal_temp_input_attr
[] = {
5671 static const struct attribute_group thermal_temp_input16_group
= {
5672 .attrs
= thermal_temp_input_attr
5675 static const struct attribute_group thermal_temp_input8_group
= {
5676 .attrs
= &thermal_temp_input_attr
[8]
5679 #undef THERMAL_SENSOR_ATTR_TEMP
5680 #undef THERMAL_ATTRS
5682 /* --------------------------------------------------------------------- */
5684 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5691 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5693 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5695 if (thinkpad_id
.ec_model
) {
5697 * Direct EC access mode: sensors at registers
5698 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5699 * non-implemented, thermal sensors return 0x80 when
5704 for (i
= 0; i
< 8; i
++) {
5705 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5711 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5719 /* This is sheer paranoia, but we handle it anyway */
5722 "ThinkPad ACPI EC access misbehaving, "
5723 "falling back to ACPI TMPx access "
5725 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5728 "ThinkPad ACPI EC access misbehaving, "
5729 "disabling thermal sensors access\n");
5730 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5735 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5737 } else if (acpi_tmp7
) {
5738 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5739 /* 600e/x, 770e, 770x */
5740 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5742 /* Standard ACPI TMPx access, max 8 sensors */
5743 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5746 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5747 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5750 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5751 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5754 switch (thermal_read_mode
) {
5755 case TPACPI_THERMAL_TPEC_16
:
5756 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5757 &thermal_temp_input16_group
);
5761 case TPACPI_THERMAL_TPEC_8
:
5762 case TPACPI_THERMAL_ACPI_TMP07
:
5763 case TPACPI_THERMAL_ACPI_UPDT
:
5764 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5765 &thermal_temp_input8_group
);
5769 case TPACPI_THERMAL_NONE
:
5777 static void thermal_exit(void)
5779 switch (thermal_read_mode
) {
5780 case TPACPI_THERMAL_TPEC_16
:
5781 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5782 &thermal_temp_input16_group
);
5784 case TPACPI_THERMAL_TPEC_8
:
5785 case TPACPI_THERMAL_ACPI_TMP07
:
5786 case TPACPI_THERMAL_ACPI_UPDT
:
5787 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5788 &thermal_temp_input8_group
);
5790 case TPACPI_THERMAL_NONE
:
5796 static int thermal_read(struct seq_file
*m
)
5799 struct ibm_thermal_sensors_struct t
;
5801 n
= thermal_get_sensors(&t
);
5802 if (unlikely(n
< 0))
5805 seq_printf(m
, "temperatures:\t");
5808 for (i
= 0; i
< (n
- 1); i
++)
5809 seq_printf(m
, "%d ", t
.temp
[i
] / 1000);
5810 seq_printf(m
, "%d\n", t
.temp
[i
] / 1000);
5812 seq_printf(m
, "not supported\n");
5817 static struct ibm_struct thermal_driver_data
= {
5819 .read
= thermal_read
,
5820 .exit
= thermal_exit
,
5823 /*************************************************************************
5827 static u8 ecdump_regs
[256];
5829 static int ecdump_read(struct seq_file
*m
)
5835 " +00 +01 +02 +03 +04 +05 +06 +07"
5836 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5837 for (i
= 0; i
< 256; i
+= 16) {
5838 seq_printf(m
, "EC 0x%02x:", i
);
5839 for (j
= 0; j
< 16; j
++) {
5840 if (!acpi_ec_read(i
+ j
, &v
))
5842 if (v
!= ecdump_regs
[i
+ j
])
5843 seq_printf(m
, " *%02x", v
);
5845 seq_printf(m
, " %02x", v
);
5846 ecdump_regs
[i
+ j
] = v
;
5853 /* These are way too dangerous to advertise openly... */
5855 seq_printf(m
, "commands:\t0x<offset> 0x<value>"
5856 " (<offset> is 00-ff, <value> is 00-ff)\n");
5857 seq_printf(m
, "commands:\t0x<offset> <value> "
5858 " (<offset> is 00-ff, <value> is 0-255)\n");
5863 static int ecdump_write(char *buf
)
5868 while ((cmd
= next_cmd(&buf
))) {
5869 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5871 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5875 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5876 if (!acpi_ec_write(i
, v
))
5885 static struct ibm_struct ecdump_driver_data
= {
5887 .read
= ecdump_read
,
5888 .write
= ecdump_write
,
5889 .flags
.experimental
= 1,
5892 /*************************************************************************
5893 * Backlight/brightness subdriver
5896 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5899 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5900 * CMOS NVRAM byte 0x5E, bits 0-3.
5902 * EC HBRV (0x31) has the following layout
5903 * Bit 7: unknown function
5904 * Bit 6: unknown function
5905 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5906 * Bit 4: must be set to zero to avoid problems
5907 * Bit 3-0: backlight brightness level
5909 * brightness_get_raw returns status data in the HBRV layout
5911 * WARNING: The X61 has been verified to use HBRV for something else, so
5912 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5913 * testing on the very early *60 Lenovo models...
5917 TP_EC_BACKLIGHT
= 0x31,
5919 /* TP_EC_BACKLIGHT bitmasks */
5920 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5921 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5922 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5925 enum tpacpi_brightness_access_mode
{
5926 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5927 TPACPI_BRGHT_MODE_EC
, /* EC control */
5928 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5929 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5930 TPACPI_BRGHT_MODE_MAX
5933 static struct backlight_device
*ibm_backlight_device
;
5935 static enum tpacpi_brightness_access_mode brightness_mode
=
5936 TPACPI_BRGHT_MODE_MAX
;
5938 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5940 static struct mutex brightness_mutex
;
5942 /* NVRAM brightness access,
5943 * call with brightness_mutex held! */
5944 static unsigned int tpacpi_brightness_nvram_get(void)
5948 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5949 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5950 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5951 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5956 static void tpacpi_brightness_checkpoint_nvram(void)
5961 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5964 vdbg_printk(TPACPI_DBG_BRGHT
,
5965 "trying to checkpoint backlight level to NVRAM...\n");
5967 if (mutex_lock_killable(&brightness_mutex
) < 0)
5970 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5972 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5973 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5975 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5976 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5977 /* NVRAM needs update */
5978 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5979 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5981 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5982 dbg_printk(TPACPI_DBG_BRGHT
,
5983 "updated NVRAM backlight level to %u (0x%02x)\n",
5984 (unsigned int) lec
, (unsigned int) b_nvram
);
5986 vdbg_printk(TPACPI_DBG_BRGHT
,
5987 "NVRAM backlight level already is %u (0x%02x)\n",
5988 (unsigned int) lec
, (unsigned int) b_nvram
);
5991 mutex_unlock(&brightness_mutex
);
5995 /* call with brightness_mutex held! */
5996 static int tpacpi_brightness_get_raw(int *status
)
6000 switch (brightness_mode
) {
6001 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6002 *status
= tpacpi_brightness_nvram_get();
6004 case TPACPI_BRGHT_MODE_EC
:
6005 case TPACPI_BRGHT_MODE_ECNVRAM
:
6006 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6015 /* call with brightness_mutex held! */
6016 /* do NOT call with illegal backlight level value */
6017 static int tpacpi_brightness_set_ec(unsigned int value
)
6021 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6024 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
6025 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
6026 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
6032 /* call with brightness_mutex held! */
6033 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
6036 unsigned int current_value
, i
;
6038 current_value
= tpacpi_brightness_nvram_get();
6040 if (value
== current_value
)
6043 cmos_cmd
= (value
> current_value
) ?
6044 TP_CMOS_BRIGHTNESS_UP
:
6045 TP_CMOS_BRIGHTNESS_DOWN
;
6046 inc
= (value
> current_value
) ? 1 : -1;
6048 for (i
= current_value
; i
!= value
; i
+= inc
)
6049 if (issue_thinkpad_cmos_command(cmos_cmd
))
6055 /* May return EINTR which can always be mapped to ERESTARTSYS */
6056 static int brightness_set(unsigned int value
)
6060 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
6064 vdbg_printk(TPACPI_DBG_BRGHT
,
6065 "set backlight level to %d\n", value
);
6067 res
= mutex_lock_killable(&brightness_mutex
);
6071 switch (brightness_mode
) {
6072 case TPACPI_BRGHT_MODE_EC
:
6073 case TPACPI_BRGHT_MODE_ECNVRAM
:
6074 res
= tpacpi_brightness_set_ec(value
);
6076 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6077 res
= tpacpi_brightness_set_ucmsstep(value
);
6083 mutex_unlock(&brightness_mutex
);
6087 /* sysfs backlight class ----------------------------------------------- */
6089 static int brightness_update_status(struct backlight_device
*bd
)
6091 unsigned int level
=
6092 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
6093 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
6094 bd
->props
.brightness
: 0;
6096 dbg_printk(TPACPI_DBG_BRGHT
,
6097 "backlight: attempt to set level to %d\n",
6100 /* it is the backlight class's job (caller) to handle
6101 * EINTR and other errors properly */
6102 return brightness_set(level
);
6105 static int brightness_get(struct backlight_device
*bd
)
6109 res
= mutex_lock_killable(&brightness_mutex
);
6113 res
= tpacpi_brightness_get_raw(&status
);
6115 mutex_unlock(&brightness_mutex
);
6120 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6123 static void tpacpi_brightness_notify_change(void)
6125 backlight_force_update(ibm_backlight_device
,
6126 BACKLIGHT_UPDATE_HOTKEY
);
6129 static struct backlight_ops ibm_backlight_data
= {
6130 .get_brightness
= brightness_get
,
6131 .update_status
= brightness_update_status
,
6134 /* --------------------------------------------------------------------- */
6137 * These are only useful for models that have only one possibility
6138 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6141 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6142 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6143 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6145 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6146 /* Models with ATI GPUs known to require ECNVRAM mode */
6147 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6149 /* Models with ATI GPUs that can use ECNVRAM */
6150 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
), /* R50,51 T40-42 */
6151 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6152 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC
), /* R52 */
6153 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6155 /* Models with Intel Extreme Graphics 2 */
6156 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
), /* X40 */
6157 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6158 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6160 /* Models with Intel GMA900 */
6161 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6162 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6163 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6166 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6169 unsigned long quirks
;
6171 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6173 mutex_init(&brightness_mutex
);
6175 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6176 ARRAY_SIZE(brightness_quirk_table
));
6179 * We always attempt to detect acpi support, so as to switch
6180 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6181 * going to publish a backlight interface
6183 b
= tpacpi_check_std_acpi_brightness_support();
6186 if (acpi_video_backlight_support()) {
6187 if (brightness_enable
> 1) {
6188 printk(TPACPI_NOTICE
6189 "Standard ACPI backlight interface "
6190 "available, not loading native one.\n");
6192 } else if (brightness_enable
== 1) {
6193 printk(TPACPI_NOTICE
6194 "Backlight control force enabled, even if standard "
6195 "ACPI backlight interface is available\n");
6198 if (brightness_enable
> 1) {
6199 printk(TPACPI_NOTICE
6200 "Standard ACPI backlight interface not "
6201 "available, thinkpad_acpi native "
6202 "brightness control enabled\n");
6207 if (!brightness_enable
) {
6208 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6209 "brightness support disabled by "
6210 "module parameter\n");
6216 "Unsupported brightness interface, "
6217 "please contact %s\n", TPACPI_MAIL
);
6221 tp_features
.bright_16levels
= 1;
6224 * Check for module parameter bogosity, note that we
6225 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6226 * able to detect "unspecified"
6228 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6231 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6232 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6233 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6234 if (quirks
& TPACPI_BRGHT_Q_EC
)
6235 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6237 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6239 dbg_printk(TPACPI_DBG_BRGHT
,
6240 "driver auto-selected brightness_mode=%d\n",
6245 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6246 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6247 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6250 if (tpacpi_brightness_get_raw(&b
) < 0)
6253 if (tp_features
.bright_16levels
)
6255 "detected a 16-level brightness capable ThinkPad\n");
6257 ibm_backlight_device
= backlight_device_register(
6258 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6259 &ibm_backlight_data
);
6260 if (IS_ERR(ibm_backlight_device
)) {
6261 int rc
= PTR_ERR(ibm_backlight_device
);
6262 ibm_backlight_device
= NULL
;
6263 printk(TPACPI_ERR
"Could not register backlight device\n");
6266 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6267 "brightness is supported\n");
6269 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6270 printk(TPACPI_NOTICE
6271 "brightness: will use unverified default: "
6272 "brightness_mode=%d\n", brightness_mode
);
6273 printk(TPACPI_NOTICE
6274 "brightness: please report to %s whether it works well "
6275 "or not on your ThinkPad\n", TPACPI_MAIL
);
6278 ibm_backlight_device
->props
.max_brightness
=
6279 (tp_features
.bright_16levels
)? 15 : 7;
6280 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6281 backlight_update_status(ibm_backlight_device
);
6283 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6284 "brightness: registering brightness hotkeys "
6285 "as change notification\n");
6286 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6287 | TP_ACPI_HKEY_BRGHTUP_MASK
6288 | TP_ACPI_HKEY_BRGHTDWN_MASK
);;
6292 static void brightness_suspend(pm_message_t state
)
6294 tpacpi_brightness_checkpoint_nvram();
6297 static void brightness_shutdown(void)
6299 tpacpi_brightness_checkpoint_nvram();
6302 static void brightness_exit(void)
6304 if (ibm_backlight_device
) {
6305 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6306 "calling backlight_device_unregister()\n");
6307 backlight_device_unregister(ibm_backlight_device
);
6310 tpacpi_brightness_checkpoint_nvram();
6313 static int brightness_read(struct seq_file
*m
)
6317 level
= brightness_get(NULL
);
6319 seq_printf(m
, "level:\t\tunreadable\n");
6321 seq_printf(m
, "level:\t\t%d\n", level
);
6322 seq_printf(m
, "commands:\tup, down\n");
6323 seq_printf(m
, "commands:\tlevel <level>"
6324 " (<level> is 0-%d)\n",
6325 (tp_features
.bright_16levels
) ? 15 : 7);
6331 static int brightness_write(char *buf
)
6336 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6338 level
= brightness_get(NULL
);
6342 while ((cmd
= next_cmd(&buf
))) {
6343 if (strlencmp(cmd
, "up") == 0) {
6344 if (level
< max_level
)
6346 } else if (strlencmp(cmd
, "down") == 0) {
6349 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6350 level
>= 0 && level
<= max_level
) {
6356 tpacpi_disclose_usertask("procfs brightness",
6357 "set level to %d\n", level
);
6360 * Now we know what the final level should be, so we try to set it.
6361 * Doing it this way makes the syscall restartable in case of EINTR
6363 rc
= brightness_set(level
);
6364 if (!rc
&& ibm_backlight_device
)
6365 backlight_force_update(ibm_backlight_device
,
6366 BACKLIGHT_UPDATE_SYSFS
);
6367 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6370 static struct ibm_struct brightness_driver_data
= {
6371 .name
= "brightness",
6372 .read
= brightness_read
,
6373 .write
= brightness_write
,
6374 .exit
= brightness_exit
,
6375 .suspend
= brightness_suspend
,
6376 .shutdown
= brightness_shutdown
,
6379 /*************************************************************************
6384 * IBM ThinkPads have a simple volume controller with MUTE gating.
6385 * Very early Lenovo ThinkPads follow the IBM ThinkPad spec.
6387 * Since the *61 series (and probably also the later *60 series), Lenovo
6388 * ThinkPads only implement the MUTE gate.
6391 * Bit 6: MUTE (1 mutes sound)
6393 * Other bits should be zero as far as we know.
6395 * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and
6396 * bits 3-0 (volume). Other bits in NVRAM may have other functions,
6397 * such as bit 7 which is used to detect repeated presses of MUTE,
6398 * and we leave them unchanged.
6401 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
6403 #define TPACPI_ALSA_DRVNAME "ThinkPad EC"
6404 #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control"
6405 #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME
6407 static int alsa_index
= ~((1 << (SNDRV_CARDS
- 3)) - 1); /* last three slots */
6408 static char *alsa_id
= "ThinkPadEC";
6409 static int alsa_enable
= SNDRV_DEFAULT_ENABLE1
;
6411 struct tpacpi_alsa_data
{
6412 struct snd_card
*card
;
6413 struct snd_ctl_elem_id
*ctl_mute_id
;
6414 struct snd_ctl_elem_id
*ctl_vol_id
;
6417 static struct snd_card
*alsa_card
;
6422 /* TP_EC_AUDIO bits */
6423 TP_EC_AUDIO_MUTESW
= 6,
6425 /* TP_EC_AUDIO bitmasks */
6426 TP_EC_AUDIO_LVL_MSK
= 0x0F,
6427 TP_EC_AUDIO_MUTESW_MSK
= (1 << TP_EC_AUDIO_MUTESW
),
6429 /* Maximum volume */
6430 TP_EC_VOLUME_MAX
= 14,
6433 enum tpacpi_volume_access_mode
{
6434 TPACPI_VOL_MODE_AUTO
= 0, /* Not implemented yet */
6435 TPACPI_VOL_MODE_EC
, /* Pure EC control */
6436 TPACPI_VOL_MODE_UCMS_STEP
, /* UCMS step-based control: N/A */
6437 TPACPI_VOL_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
6441 enum tpacpi_volume_capabilities
{
6442 TPACPI_VOL_CAP_AUTO
= 0, /* Use white/blacklist */
6443 TPACPI_VOL_CAP_VOLMUTE
, /* Output vol and mute */
6444 TPACPI_VOL_CAP_MUTEONLY
, /* Output mute only */
6448 static enum tpacpi_volume_access_mode volume_mode
=
6449 TPACPI_VOL_MODE_MAX
;
6451 static enum tpacpi_volume_capabilities volume_capabilities
;
6452 static int volume_control_allowed
;
6455 * Used to syncronize writers to TP_EC_AUDIO and
6456 * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write
6458 static struct mutex volume_mutex
;
6460 static void tpacpi_volume_checkpoint_nvram(void)
6466 if (volume_mode
!= TPACPI_VOL_MODE_ECNVRAM
)
6468 if (!volume_control_allowed
)
6471 vdbg_printk(TPACPI_DBG_MIXER
,
6472 "trying to checkpoint mixer state to NVRAM...\n");
6474 if (tp_features
.mixer_no_level_control
)
6475 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
;
6477 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
| TP_EC_AUDIO_LVL_MSK
;
6479 if (mutex_lock_killable(&volume_mutex
) < 0)
6482 if (unlikely(!acpi_ec_read(TP_EC_AUDIO
, &lec
)))
6485 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
6487 if (lec
!= (b_nvram
& ec_mask
)) {
6488 /* NVRAM needs update */
6489 b_nvram
&= ~ec_mask
;
6491 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_MIXER
);
6492 dbg_printk(TPACPI_DBG_MIXER
,
6493 "updated NVRAM mixer status to 0x%02x (0x%02x)\n",
6494 (unsigned int) lec
, (unsigned int) b_nvram
);
6496 vdbg_printk(TPACPI_DBG_MIXER
,
6497 "NVRAM mixer status already is 0x%02x (0x%02x)\n",
6498 (unsigned int) lec
, (unsigned int) b_nvram
);
6502 mutex_unlock(&volume_mutex
);
6505 static int volume_get_status_ec(u8
*status
)
6509 if (!acpi_ec_read(TP_EC_AUDIO
, &s
))
6514 dbg_printk(TPACPI_DBG_MIXER
, "status 0x%02x\n", s
);
6519 static int volume_get_status(u8
*status
)
6521 return volume_get_status_ec(status
);
6524 static int volume_set_status_ec(const u8 status
)
6526 if (!acpi_ec_write(TP_EC_AUDIO
, status
))
6529 dbg_printk(TPACPI_DBG_MIXER
, "set EC mixer to 0x%02x\n", status
);
6534 static int volume_set_status(const u8 status
)
6536 return volume_set_status_ec(status
);
6539 static int volume_set_mute_ec(const bool mute
)
6544 if (mutex_lock_killable(&volume_mutex
) < 0)
6547 rc
= volume_get_status_ec(&s
);
6551 n
= (mute
) ? s
| TP_EC_AUDIO_MUTESW_MSK
:
6552 s
& ~TP_EC_AUDIO_MUTESW_MSK
;
6555 rc
= volume_set_status_ec(n
);
6558 mutex_unlock(&volume_mutex
);
6562 static int volume_set_mute(const bool mute
)
6564 dbg_printk(TPACPI_DBG_MIXER
, "trying to %smute\n",
6565 (mute
) ? "" : "un");
6566 return volume_set_mute_ec(mute
);
6569 static int volume_set_volume_ec(const u8 vol
)
6574 if (vol
> TP_EC_VOLUME_MAX
)
6577 if (mutex_lock_killable(&volume_mutex
) < 0)
6580 rc
= volume_get_status_ec(&s
);
6584 n
= (s
& ~TP_EC_AUDIO_LVL_MSK
) | vol
;
6587 rc
= volume_set_status_ec(n
);
6590 mutex_unlock(&volume_mutex
);
6594 static int volume_set_volume(const u8 vol
)
6596 dbg_printk(TPACPI_DBG_MIXER
,
6597 "trying to set volume level to %hu\n", vol
);
6598 return volume_set_volume_ec(vol
);
6601 static void volume_alsa_notify_change(void)
6603 struct tpacpi_alsa_data
*d
;
6605 if (alsa_card
&& alsa_card
->private_data
) {
6606 d
= alsa_card
->private_data
;
6608 snd_ctl_notify(alsa_card
,
6609 SNDRV_CTL_EVENT_MASK_VALUE
,
6612 snd_ctl_notify(alsa_card
,
6613 SNDRV_CTL_EVENT_MASK_VALUE
,
6618 static int volume_alsa_vol_info(struct snd_kcontrol
*kcontrol
,
6619 struct snd_ctl_elem_info
*uinfo
)
6621 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
6623 uinfo
->value
.integer
.min
= 0;
6624 uinfo
->value
.integer
.max
= TP_EC_VOLUME_MAX
;
6628 static int volume_alsa_vol_get(struct snd_kcontrol
*kcontrol
,
6629 struct snd_ctl_elem_value
*ucontrol
)
6634 rc
= volume_get_status(&s
);
6638 ucontrol
->value
.integer
.value
[0] = s
& TP_EC_AUDIO_LVL_MSK
;
6642 static int volume_alsa_vol_put(struct snd_kcontrol
*kcontrol
,
6643 struct snd_ctl_elem_value
*ucontrol
)
6645 return volume_set_volume(ucontrol
->value
.integer
.value
[0]);
6648 #define volume_alsa_mute_info snd_ctl_boolean_mono_info
6650 static int volume_alsa_mute_get(struct snd_kcontrol
*kcontrol
,
6651 struct snd_ctl_elem_value
*ucontrol
)
6656 rc
= volume_get_status(&s
);
6660 ucontrol
->value
.integer
.value
[0] =
6661 (s
& TP_EC_AUDIO_MUTESW_MSK
) ? 0 : 1;
6665 static int volume_alsa_mute_put(struct snd_kcontrol
*kcontrol
,
6666 struct snd_ctl_elem_value
*ucontrol
)
6668 return volume_set_mute(!ucontrol
->value
.integer
.value
[0]);
6671 static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata
= {
6672 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6673 .name
= "Console Playback Volume",
6675 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6676 .info
= volume_alsa_vol_info
,
6677 .get
= volume_alsa_vol_get
,
6680 static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata
= {
6681 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6682 .name
= "Console Playback Switch",
6684 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6685 .info
= volume_alsa_mute_info
,
6686 .get
= volume_alsa_mute_get
,
6689 static void volume_suspend(pm_message_t state
)
6691 tpacpi_volume_checkpoint_nvram();
6694 static void volume_resume(void)
6696 volume_alsa_notify_change();
6699 static void volume_shutdown(void)
6701 tpacpi_volume_checkpoint_nvram();
6704 static void volume_exit(void)
6707 snd_card_free(alsa_card
);
6711 tpacpi_volume_checkpoint_nvram();
6714 static int __init
volume_create_alsa_mixer(void)
6716 struct snd_card
*card
;
6717 struct tpacpi_alsa_data
*data
;
6718 struct snd_kcontrol
*ctl_vol
;
6719 struct snd_kcontrol
*ctl_mute
;
6722 card
= snd_card_new(alsa_index
, alsa_id
, THIS_MODULE
,
6723 sizeof(struct tpacpi_alsa_data
));
6726 "Failed to create ALSA card structures\n");
6730 BUG_ON(!card
->private_data
);
6731 data
= card
->private_data
;
6734 strlcpy(card
->driver
, TPACPI_ALSA_DRVNAME
,
6735 sizeof(card
->driver
));
6736 strlcpy(card
->shortname
, TPACPI_ALSA_SHRTNAME
,
6737 sizeof(card
->shortname
));
6738 snprintf(card
->mixername
, sizeof(card
->mixername
), "ThinkPad EC %s",
6739 (thinkpad_id
.ec_version_str
) ?
6740 thinkpad_id
.ec_version_str
: "(unknown)");
6741 snprintf(card
->longname
, sizeof(card
->longname
),
6742 "%s at EC reg 0x%02x, fw %s", card
->shortname
, TP_EC_AUDIO
,
6743 (thinkpad_id
.ec_version_str
) ?
6744 thinkpad_id
.ec_version_str
: "unknown");
6746 if (volume_control_allowed
) {
6747 volume_alsa_control_vol
.put
= volume_alsa_vol_put
;
6748 volume_alsa_control_vol
.access
=
6749 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6751 volume_alsa_control_mute
.put
= volume_alsa_mute_put
;
6752 volume_alsa_control_mute
.access
=
6753 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6756 if (!tp_features
.mixer_no_level_control
) {
6757 ctl_vol
= snd_ctl_new1(&volume_alsa_control_vol
, NULL
);
6758 rc
= snd_ctl_add(card
, ctl_vol
);
6761 "Failed to create ALSA volume control: %d\n",
6765 data
->ctl_vol_id
= &ctl_vol
->id
;
6768 ctl_mute
= snd_ctl_new1(&volume_alsa_control_mute
, NULL
);
6769 rc
= snd_ctl_add(card
, ctl_mute
);
6771 printk(TPACPI_ERR
"Failed to create ALSA mute control: %d\n",
6775 data
->ctl_mute_id
= &ctl_mute
->id
;
6777 snd_card_set_dev(card
, &tpacpi_pdev
->dev
);
6778 rc
= snd_card_register(card
);
6780 printk(TPACPI_ERR
"Failed to register ALSA card: %d\n", rc
);
6788 snd_card_free(card
);
6792 #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */
6793 #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */
6795 static const struct tpacpi_quirk volume_quirk_table
[] __initconst
= {
6796 /* Whitelist volume level on all IBM by default */
6797 { .vendor
= PCI_VENDOR_ID_IBM
,
6798 .bios
= TPACPI_MATCH_ANY
,
6799 .ec
= TPACPI_MATCH_ANY
,
6800 .quirks
= TPACPI_VOL_Q_LEVEL
},
6802 /* Lenovo models with volume control (needs confirmation) */
6803 TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL
), /* R60/i */
6804 TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL
), /* R60e/i */
6805 TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL
), /* T60/p */
6806 TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL
), /* X60/s */
6807 TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL
), /* X60t */
6808 TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL
), /* Z60 */
6809 TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL
), /* Z61 */
6811 /* Whitelist mute-only on all Lenovo by default */
6812 { .vendor
= PCI_VENDOR_ID_LENOVO
,
6813 .bios
= TPACPI_MATCH_ANY
,
6814 .ec
= TPACPI_MATCH_ANY
,
6815 .quirks
= TPACPI_VOL_Q_MUTEONLY
}
6818 static int __init
volume_init(struct ibm_init_struct
*iibm
)
6820 unsigned long quirks
;
6823 vdbg_printk(TPACPI_DBG_INIT
, "initializing volume subdriver\n");
6825 mutex_init(&volume_mutex
);
6828 * Check for module parameter bogosity, note that we
6829 * init volume_mode to TPACPI_VOL_MODE_MAX in order to be
6830 * able to detect "unspecified"
6832 if (volume_mode
> TPACPI_VOL_MODE_MAX
)
6835 if (volume_mode
== TPACPI_VOL_MODE_UCMS_STEP
) {
6837 "UCMS step volume mode not implemented, "
6838 "please contact %s\n", TPACPI_MAIL
);
6842 if (volume_capabilities
>= TPACPI_VOL_CAP_MAX
)
6846 * The ALSA mixer is our primary interface.
6847 * When disabled, don't install the subdriver at all
6850 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6851 "ALSA mixer disabled by parameter, "
6852 "not loading volume subdriver...\n");
6856 quirks
= tpacpi_check_quirks(volume_quirk_table
,
6857 ARRAY_SIZE(volume_quirk_table
));
6859 switch (volume_capabilities
) {
6860 case TPACPI_VOL_CAP_AUTO
:
6861 if (quirks
& TPACPI_VOL_Q_MUTEONLY
)
6862 tp_features
.mixer_no_level_control
= 1;
6863 else if (quirks
& TPACPI_VOL_Q_LEVEL
)
6864 tp_features
.mixer_no_level_control
= 0;
6866 return 1; /* no mixer */
6868 case TPACPI_VOL_CAP_VOLMUTE
:
6869 tp_features
.mixer_no_level_control
= 0;
6871 case TPACPI_VOL_CAP_MUTEONLY
:
6872 tp_features
.mixer_no_level_control
= 1;
6878 if (volume_capabilities
!= TPACPI_VOL_CAP_AUTO
)
6879 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6880 "using user-supplied volume_capabilities=%d\n",
6881 volume_capabilities
);
6883 if (volume_mode
== TPACPI_VOL_MODE_AUTO
||
6884 volume_mode
== TPACPI_VOL_MODE_MAX
) {
6885 volume_mode
= TPACPI_VOL_MODE_ECNVRAM
;
6887 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6888 "driver auto-selected volume_mode=%d\n",
6891 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6892 "using user-supplied volume_mode=%d\n",
6896 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6897 "mute is supported, volume control is %s\n",
6898 str_supported(!tp_features
.mixer_no_level_control
));
6900 rc
= volume_create_alsa_mixer();
6903 "Could not create the ALSA mixer interface\n");
6908 "Console audio control enabled, mode: %s\n",
6909 (volume_control_allowed
) ?
6910 "override (read/write)" :
6911 "monitor (read only)");
6913 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6914 "registering volume hotkeys as change notification\n");
6915 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6916 | TP_ACPI_HKEY_VOLUP_MASK
6917 | TP_ACPI_HKEY_VOLDWN_MASK
6918 | TP_ACPI_HKEY_MUTE_MASK
);
6923 static int volume_read(struct seq_file
*m
)
6927 if (volume_get_status(&status
) < 0) {
6928 seq_printf(m
, "level:\t\tunreadable\n");
6930 if (tp_features
.mixer_no_level_control
)
6931 seq_printf(m
, "level:\t\tunsupported\n");
6933 seq_printf(m
, "level:\t\t%d\n",
6934 status
& TP_EC_AUDIO_LVL_MSK
);
6936 seq_printf(m
, "mute:\t\t%s\n",
6937 onoff(status
, TP_EC_AUDIO_MUTESW
));
6939 if (volume_control_allowed
) {
6940 seq_printf(m
, "commands:\tunmute, mute\n");
6941 if (!tp_features
.mixer_no_level_control
) {
6943 "commands:\tup, down\n");
6945 "commands:\tlevel <level>"
6946 " (<level> is 0-%d)\n",
6955 static int volume_write(char *buf
)
6958 u8 new_level
, new_mute
;
6964 * We do allow volume control at driver startup, so that the
6965 * user can set initial state through the volume=... parameter hack.
6967 if (!volume_control_allowed
&& tpacpi_lifecycle
!= TPACPI_LIFE_INIT
) {
6968 if (unlikely(!tp_warned
.volume_ctrl_forbidden
)) {
6969 tp_warned
.volume_ctrl_forbidden
= 1;
6970 printk(TPACPI_NOTICE
6971 "Console audio control in monitor mode, "
6972 "changes are not allowed.\n");
6973 printk(TPACPI_NOTICE
6974 "Use the volume_control=1 module parameter "
6975 "to enable volume control\n");
6980 rc
= volume_get_status(&s
);
6984 new_level
= s
& TP_EC_AUDIO_LVL_MSK
;
6985 new_mute
= s
& TP_EC_AUDIO_MUTESW_MSK
;
6987 while ((cmd
= next_cmd(&buf
))) {
6988 if (!tp_features
.mixer_no_level_control
) {
6989 if (strlencmp(cmd
, "up") == 0) {
6992 else if (new_level
< TP_EC_VOLUME_MAX
)
6995 } else if (strlencmp(cmd
, "down") == 0) {
6998 else if (new_level
> 0)
7001 } else if (sscanf(cmd
, "level %u", &l
) == 1 &&
7002 l
>= 0 && l
<= TP_EC_VOLUME_MAX
) {
7007 if (strlencmp(cmd
, "mute") == 0)
7008 new_mute
= TP_EC_AUDIO_MUTESW_MSK
;
7009 else if (strlencmp(cmd
, "unmute") == 0)
7015 if (tp_features
.mixer_no_level_control
) {
7016 tpacpi_disclose_usertask("procfs volume", "%smute\n",
7017 new_mute
? "" : "un");
7018 rc
= volume_set_mute(!!new_mute
);
7020 tpacpi_disclose_usertask("procfs volume",
7021 "%smute and set level to %d\n",
7022 new_mute
? "" : "un", new_level
);
7023 rc
= volume_set_status(new_mute
| new_level
);
7025 volume_alsa_notify_change();
7027 return (rc
== -EINTR
) ? -ERESTARTSYS
: rc
;
7030 static struct ibm_struct volume_driver_data
= {
7032 .read
= volume_read
,
7033 .write
= volume_write
,
7034 .exit
= volume_exit
,
7035 .suspend
= volume_suspend
,
7036 .resume
= volume_resume
,
7037 .shutdown
= volume_shutdown
,
7040 #else /* !CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
7042 #define alsa_card NULL
7044 static void inline volume_alsa_notify_change(void)
7048 static int __init
volume_init(struct ibm_init_struct
*iibm
)
7051 "volume: disabled as there is no ALSA support in this kernel\n");
7056 static struct ibm_struct volume_driver_data
= {
7060 #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
7062 /*************************************************************************
7069 * TPACPI_FAN_RD_ACPI_GFAN:
7070 * ACPI GFAN method: returns fan level
7072 * see TPACPI_FAN_WR_ACPI_SFAN
7073 * EC 0x2f (HFSP) not available if GFAN exists
7075 * TPACPI_FAN_WR_ACPI_SFAN:
7076 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
7078 * EC 0x2f (HFSP) might be available *for reading*, but do not use
7081 * TPACPI_FAN_WR_TPEC:
7082 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
7083 * Supported on almost all ThinkPads
7085 * Fan speed changes of any sort (including those caused by the
7086 * disengaged mode) are usually done slowly by the firmware as the
7087 * maximum ammount of fan duty cycle change per second seems to be
7090 * Reading is not available if GFAN exists.
7091 * Writing is not available if SFAN exists.
7094 * 7 automatic mode engaged;
7095 * (default operation mode of the ThinkPad)
7096 * fan level is ignored in this mode.
7097 * 6 full speed mode (takes precedence over bit 7);
7098 * not available on all thinkpads. May disable
7099 * the tachometer while the fan controller ramps up
7100 * the speed (which can take up to a few *minutes*).
7101 * Speeds up fan to 100% duty-cycle, which is far above
7102 * the standard RPM levels. It is not impossible that
7103 * it could cause hardware damage.
7104 * 5-3 unused in some models. Extra bits for fan level
7105 * in others, but still useless as all values above
7106 * 7 map to the same speed as level 7 in these models.
7107 * 2-0 fan level (0..7 usually)
7109 * 0x07 = max (set when temperatures critical)
7110 * Some ThinkPads may have other levels, see
7111 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
7113 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
7114 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
7115 * does so, its initial value is meaningless (0x07).
7117 * For firmware bugs, refer to:
7118 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7122 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
7123 * Main fan tachometer reading (in RPM)
7125 * This register is present on all ThinkPads with a new-style EC, and
7126 * it is known not to be present on the A21m/e, and T22, as there is
7127 * something else in offset 0x84 according to the ACPI DSDT. Other
7128 * ThinkPads from this same time period (and earlier) probably lack the
7129 * tachometer as well.
7131 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
7132 * was never fixed by IBM to report the EC firmware version string
7133 * probably support the tachometer (like the early X models), so
7134 * detecting it is quite hard. We need more data to know for sure.
7136 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
7139 * FIRMWARE BUG: may go stale while the EC is switching to full speed
7142 * For firmware bugs, refer to:
7143 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7147 * ThinkPad EC register 0x31 bit 0 (only on select models)
7149 * When bit 0 of EC register 0x31 is zero, the tachometer registers
7150 * show the speed of the main fan. When bit 0 of EC register 0x31
7151 * is one, the tachometer registers show the speed of the auxiliary
7154 * Fan control seems to affect both fans, regardless of the state
7157 * So far, only the firmware for the X60/X61 non-tablet versions
7158 * seem to support this (firmware TP-7M).
7160 * TPACPI_FAN_WR_ACPI_FANS:
7161 * ThinkPad X31, X40, X41. Not available in the X60.
7163 * FANS ACPI handle: takes three arguments: low speed, medium speed,
7164 * high speed. ACPI DSDT seems to map these three speeds to levels
7165 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
7166 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
7168 * The speeds are stored on handles
7169 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
7171 * There are three default speed sets, acessible as handles:
7172 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
7174 * ACPI DSDT switches which set is in use depending on various
7177 * TPACPI_FAN_WR_TPEC is also available and should be used to
7178 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
7179 * but the ACPI tables just mention level 7.
7182 enum { /* Fan control constants */
7183 fan_status_offset
= 0x2f, /* EC register 0x2f */
7184 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
7185 * 0x84 must be read before 0x85 */
7186 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
7187 bit 0 selects which fan is active */
7189 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
7190 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
7192 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
7195 enum fan_status_access_mode
{
7196 TPACPI_FAN_NONE
= 0, /* No fan status or control */
7197 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
7198 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
7201 enum fan_control_access_mode
{
7202 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
7203 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
7204 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
7205 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
7208 enum fan_control_commands
{
7209 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
7210 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
7211 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
7212 * and also watchdog cmd */
7215 static int fan_control_allowed
;
7217 static enum fan_status_access_mode fan_status_access_mode
;
7218 static enum fan_control_access_mode fan_control_access_mode
;
7219 static enum fan_control_commands fan_control_commands
;
7221 static u8 fan_control_initial_status
;
7222 static u8 fan_control_desired_level
;
7223 static u8 fan_control_resume_level
;
7224 static int fan_watchdog_maxinterval
;
7226 static struct mutex fan_mutex
;
7228 static void fan_watchdog_fire(struct work_struct
*ignored
);
7229 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
7231 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
7232 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
7233 "\\FSPD", /* 600e/x, 770e, 770x */
7235 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
7236 "JFNS", /* 770x-JL */
7240 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
7241 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
7242 * be in auto mode (0x80).
7244 * This is corrected by any write to HFSP either by the driver, or
7247 * We assume 0x07 really means auto mode while this quirk is active,
7248 * as this is far more likely than the ThinkPad being in level 7,
7249 * which is only used by the firmware during thermal emergencies.
7251 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
7252 * TP-70 (T43, R52), which are known to be buggy.
7255 static void fan_quirk1_setup(void)
7257 if (fan_control_initial_status
== 0x07) {
7258 printk(TPACPI_NOTICE
7259 "fan_init: initial fan status is unknown, "
7260 "assuming it is in auto mode\n");
7261 tp_features
.fan_ctrl_status_undef
= 1;
7265 static void fan_quirk1_handle(u8
*fan_status
)
7267 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
7268 if (*fan_status
!= fan_control_initial_status
) {
7269 /* something changed the HFSP regisnter since
7270 * driver init time, so it is not undefined
7272 tp_features
.fan_ctrl_status_undef
= 0;
7274 /* Return most likely status. In fact, it
7275 * might be the only possible status */
7276 *fan_status
= TP_EC_FAN_AUTO
;
7281 /* Select main fan on X60/X61, NOOP on others */
7282 static bool fan_select_fan1(void)
7284 if (tp_features
.second_fan
) {
7287 if (ec_read(fan_select_offset
, &val
) < 0)
7290 if (ec_write(fan_select_offset
, val
) < 0)
7296 /* Select secondary fan on X60/X61 */
7297 static bool fan_select_fan2(void)
7301 if (!tp_features
.second_fan
)
7304 if (ec_read(fan_select_offset
, &val
) < 0)
7307 if (ec_write(fan_select_offset
, val
) < 0)
7314 * Call with fan_mutex held
7316 static void fan_update_desired_level(u8 status
)
7319 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7321 fan_control_desired_level
= 7;
7323 fan_control_desired_level
= status
;
7327 static int fan_get_status(u8
*status
)
7332 * Add TPACPI_FAN_RD_ACPI_FANS ? */
7334 switch (fan_status_access_mode
) {
7335 case TPACPI_FAN_RD_ACPI_GFAN
:
7336 /* 570, 600e/x, 770e, 770x */
7338 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
7346 case TPACPI_FAN_RD_TPEC
:
7347 /* all except 570, 600e/x, 770e, 770x */
7348 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
7351 if (likely(status
)) {
7353 fan_quirk1_handle(status
);
7365 static int fan_get_status_safe(u8
*status
)
7370 if (mutex_lock_killable(&fan_mutex
))
7371 return -ERESTARTSYS
;
7372 rc
= fan_get_status(&s
);
7374 fan_update_desired_level(s
);
7375 mutex_unlock(&fan_mutex
);
7383 static int fan_get_speed(unsigned int *speed
)
7387 switch (fan_status_access_mode
) {
7388 case TPACPI_FAN_RD_TPEC
:
7389 /* all except 570, 600e/x, 770e, 770x */
7390 if (unlikely(!fan_select_fan1()))
7392 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
7393 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
7397 *speed
= (hi
<< 8) | lo
;
7408 static int fan2_get_speed(unsigned int *speed
)
7413 switch (fan_status_access_mode
) {
7414 case TPACPI_FAN_RD_TPEC
:
7415 /* all except 570, 600e/x, 770e, 770x */
7416 if (unlikely(!fan_select_fan2()))
7418 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
7419 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
7420 fan_select_fan1(); /* play it safe */
7425 *speed
= (hi
<< 8) | lo
;
7436 static int fan_set_level(int level
)
7438 if (!fan_control_allowed
)
7441 switch (fan_control_access_mode
) {
7442 case TPACPI_FAN_WR_ACPI_SFAN
:
7443 if (level
>= 0 && level
<= 7) {
7444 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
7450 case TPACPI_FAN_WR_ACPI_FANS
:
7451 case TPACPI_FAN_WR_TPEC
:
7452 if (!(level
& TP_EC_FAN_AUTO
) &&
7453 !(level
& TP_EC_FAN_FULLSPEED
) &&
7454 ((level
< 0) || (level
> 7)))
7457 /* safety net should the EC not support AUTO
7458 * or FULLSPEED mode bits and just ignore them */
7459 if (level
& TP_EC_FAN_FULLSPEED
)
7460 level
|= 7; /* safety min speed 7 */
7461 else if (level
& TP_EC_FAN_AUTO
)
7462 level
|= 4; /* safety min speed 4 */
7464 if (!acpi_ec_write(fan_status_offset
, level
))
7467 tp_features
.fan_ctrl_status_undef
= 0;
7474 vdbg_printk(TPACPI_DBG_FAN
,
7475 "fan control: set fan control register to 0x%02x\n", level
);
7479 static int fan_set_level_safe(int level
)
7483 if (!fan_control_allowed
)
7486 if (mutex_lock_killable(&fan_mutex
))
7487 return -ERESTARTSYS
;
7489 if (level
== TPACPI_FAN_LAST_LEVEL
)
7490 level
= fan_control_desired_level
;
7492 rc
= fan_set_level(level
);
7494 fan_update_desired_level(level
);
7496 mutex_unlock(&fan_mutex
);
7500 static int fan_set_enable(void)
7505 if (!fan_control_allowed
)
7508 if (mutex_lock_killable(&fan_mutex
))
7509 return -ERESTARTSYS
;
7511 switch (fan_control_access_mode
) {
7512 case TPACPI_FAN_WR_ACPI_FANS
:
7513 case TPACPI_FAN_WR_TPEC
:
7514 rc
= fan_get_status(&s
);
7518 /* Don't go out of emergency fan mode */
7521 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
7524 if (!acpi_ec_write(fan_status_offset
, s
))
7527 tp_features
.fan_ctrl_status_undef
= 0;
7532 case TPACPI_FAN_WR_ACPI_SFAN
:
7533 rc
= fan_get_status(&s
);
7539 /* Set fan to at least level 4 */
7542 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
7552 mutex_unlock(&fan_mutex
);
7555 vdbg_printk(TPACPI_DBG_FAN
,
7556 "fan control: set fan control register to 0x%02x\n",
7561 static int fan_set_disable(void)
7565 if (!fan_control_allowed
)
7568 if (mutex_lock_killable(&fan_mutex
))
7569 return -ERESTARTSYS
;
7572 switch (fan_control_access_mode
) {
7573 case TPACPI_FAN_WR_ACPI_FANS
:
7574 case TPACPI_FAN_WR_TPEC
:
7575 if (!acpi_ec_write(fan_status_offset
, 0x00))
7578 fan_control_desired_level
= 0;
7579 tp_features
.fan_ctrl_status_undef
= 0;
7583 case TPACPI_FAN_WR_ACPI_SFAN
:
7584 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
7587 fan_control_desired_level
= 0;
7595 vdbg_printk(TPACPI_DBG_FAN
,
7596 "fan control: set fan control register to 0\n");
7598 mutex_unlock(&fan_mutex
);
7602 static int fan_set_speed(int speed
)
7606 if (!fan_control_allowed
)
7609 if (mutex_lock_killable(&fan_mutex
))
7610 return -ERESTARTSYS
;
7613 switch (fan_control_access_mode
) {
7614 case TPACPI_FAN_WR_ACPI_FANS
:
7615 if (speed
>= 0 && speed
<= 65535) {
7616 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
7617 speed
, speed
, speed
))
7627 mutex_unlock(&fan_mutex
);
7631 static void fan_watchdog_reset(void)
7633 static int fan_watchdog_active
;
7635 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
7638 if (fan_watchdog_active
)
7639 cancel_delayed_work(&fan_watchdog_task
);
7641 if (fan_watchdog_maxinterval
> 0 &&
7642 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
7643 fan_watchdog_active
= 1;
7644 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
7645 msecs_to_jiffies(fan_watchdog_maxinterval
7648 "failed to queue the fan watchdog, "
7649 "watchdog will not trigger\n");
7652 fan_watchdog_active
= 0;
7655 static void fan_watchdog_fire(struct work_struct
*ignored
)
7659 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
7662 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
7663 rc
= fan_set_enable();
7665 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
7666 "will try again later...\n", -rc
);
7667 /* reschedule for later */
7668 fan_watchdog_reset();
7673 * SYSFS fan layout: hwmon compatible (device)
7676 * 0: "disengaged" mode
7678 * 2: native EC "auto" mode (recommended, hardware default)
7680 * pwm*: set speed in manual mode, ignored otherwise.
7681 * 0 is level 0; 255 is level 7. Intermediate points done with linear
7684 * fan*_input: tachometer reading, RPM
7687 * SYSFS fan layout: extensions
7689 * fan_watchdog (driver):
7690 * fan watchdog interval in seconds, 0 disables (default), max 120
7693 /* sysfs fan pwm1_enable ----------------------------------------------- */
7694 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
7695 struct device_attribute
*attr
,
7701 res
= fan_get_status_safe(&status
);
7705 if (status
& TP_EC_FAN_FULLSPEED
) {
7707 } else if (status
& TP_EC_FAN_AUTO
) {
7712 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
7715 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7716 struct device_attribute
*attr
,
7717 const char *buf
, size_t count
)
7722 if (parse_strtoul(buf
, 2, &t
))
7725 tpacpi_disclose_usertask("hwmon pwm1_enable",
7726 "set fan mode to %lu\n", t
);
7730 level
= TP_EC_FAN_FULLSPEED
;
7733 level
= TPACPI_FAN_LAST_LEVEL
;
7736 level
= TP_EC_FAN_AUTO
;
7739 /* reserved for software-controlled auto mode */
7745 res
= fan_set_level_safe(level
);
7751 fan_watchdog_reset();
7756 static struct device_attribute dev_attr_fan_pwm1_enable
=
7757 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7758 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7760 /* sysfs fan pwm1 ------------------------------------------------------ */
7761 static ssize_t
fan_pwm1_show(struct device
*dev
,
7762 struct device_attribute
*attr
,
7768 res
= fan_get_status_safe(&status
);
7773 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7774 status
= fan_control_desired_level
;
7779 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7782 static ssize_t
fan_pwm1_store(struct device
*dev
,
7783 struct device_attribute
*attr
,
7784 const char *buf
, size_t count
)
7788 u8 status
, newlevel
;
7790 if (parse_strtoul(buf
, 255, &s
))
7793 tpacpi_disclose_usertask("hwmon pwm1",
7794 "set fan speed to %lu\n", s
);
7796 /* scale down from 0-255 to 0-7 */
7797 newlevel
= (s
>> 5) & 0x07;
7799 if (mutex_lock_killable(&fan_mutex
))
7800 return -ERESTARTSYS
;
7802 rc
= fan_get_status(&status
);
7803 if (!rc
&& (status
&
7804 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7805 rc
= fan_set_level(newlevel
);
7809 fan_update_desired_level(newlevel
);
7810 fan_watchdog_reset();
7814 mutex_unlock(&fan_mutex
);
7815 return (rc
)? rc
: count
;
7818 static struct device_attribute dev_attr_fan_pwm1
=
7819 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7820 fan_pwm1_show
, fan_pwm1_store
);
7822 /* sysfs fan fan1_input ------------------------------------------------ */
7823 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7824 struct device_attribute
*attr
,
7830 res
= fan_get_speed(&speed
);
7834 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7837 static struct device_attribute dev_attr_fan_fan1_input
=
7838 __ATTR(fan1_input
, S_IRUGO
,
7839 fan_fan1_input_show
, NULL
);
7841 /* sysfs fan fan2_input ------------------------------------------------ */
7842 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7843 struct device_attribute
*attr
,
7849 res
= fan2_get_speed(&speed
);
7853 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7856 static struct device_attribute dev_attr_fan_fan2_input
=
7857 __ATTR(fan2_input
, S_IRUGO
,
7858 fan_fan2_input_show
, NULL
);
7860 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
7861 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
7864 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
7867 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
7868 const char *buf
, size_t count
)
7872 if (parse_strtoul(buf
, 120, &t
))
7875 if (!fan_control_allowed
)
7878 fan_watchdog_maxinterval
= t
;
7879 fan_watchdog_reset();
7881 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
7886 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
7887 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
7889 /* --------------------------------------------------------------------- */
7890 static struct attribute
*fan_attributes
[] = {
7891 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
7892 &dev_attr_fan_fan1_input
.attr
,
7893 NULL
, /* for fan2_input */
7897 static const struct attribute_group fan_attr_group
= {
7898 .attrs
= fan_attributes
,
7901 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
7902 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
7904 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7905 { .vendor = PCI_VENDOR_ID_IBM, \
7906 .bios = TPACPI_MATCH_ANY, \
7907 .ec = TPID(__id1, __id2), \
7908 .quirks = __quirks }
7910 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7911 { .vendor = PCI_VENDOR_ID_LENOVO, \
7912 .bios = TPACPI_MATCH_ANY, \
7913 .ec = TPID(__id1, __id2), \
7914 .quirks = __quirks }
7916 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
7917 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
7918 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
7919 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
7920 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
7921 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
7924 #undef TPACPI_FAN_QL
7925 #undef TPACPI_FAN_QI
7927 static int __init
fan_init(struct ibm_init_struct
*iibm
)
7930 unsigned long quirks
;
7932 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7933 "initializing fan subdriver\n");
7935 mutex_init(&fan_mutex
);
7936 fan_status_access_mode
= TPACPI_FAN_NONE
;
7937 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7938 fan_control_commands
= 0;
7939 fan_watchdog_maxinterval
= 0;
7940 tp_features
.fan_ctrl_status_undef
= 0;
7941 tp_features
.second_fan
= 0;
7942 fan_control_desired_level
= 7;
7944 TPACPI_ACPIHANDLE_INIT(fans
);
7945 TPACPI_ACPIHANDLE_INIT(gfan
);
7946 TPACPI_ACPIHANDLE_INIT(sfan
);
7948 quirks
= tpacpi_check_quirks(fan_quirk_table
,
7949 ARRAY_SIZE(fan_quirk_table
));
7952 /* 570, 600e/x, 770e, 770x */
7953 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7955 /* all other ThinkPads: note that even old-style
7956 * ThinkPad ECs supports the fan control register */
7957 if (likely(acpi_ec_read(fan_status_offset
,
7958 &fan_control_initial_status
))) {
7959 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7960 if (quirks
& TPACPI_FAN_Q1
)
7962 if (quirks
& TPACPI_FAN_2FAN
) {
7963 tp_features
.second_fan
= 1;
7964 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7965 "secondary fan support enabled\n");
7969 "ThinkPad ACPI EC access misbehaving, "
7970 "fan status and control unavailable\n");
7977 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
7978 fan_control_commands
|=
7979 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
7982 /* gfan without sfan means no fan control */
7983 /* all other models implement TP EC 0x2f control */
7987 fan_control_access_mode
=
7988 TPACPI_FAN_WR_ACPI_FANS
;
7989 fan_control_commands
|=
7990 TPACPI_FAN_CMD_SPEED
|
7991 TPACPI_FAN_CMD_LEVEL
|
7992 TPACPI_FAN_CMD_ENABLE
;
7994 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
7995 fan_control_commands
|=
7996 TPACPI_FAN_CMD_LEVEL
|
7997 TPACPI_FAN_CMD_ENABLE
;
8002 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8003 "fan is %s, modes %d, %d\n",
8004 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
8005 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
8006 fan_status_access_mode
, fan_control_access_mode
);
8008 /* fan control master switch */
8009 if (!fan_control_allowed
) {
8010 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
8011 fan_control_commands
= 0;
8012 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8013 "fan control features disabled by parameter\n");
8016 /* update fan_control_desired_level */
8017 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
8018 fan_get_status_safe(NULL
);
8020 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
8021 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
8022 if (tp_features
.second_fan
) {
8023 /* attach second fan tachometer */
8024 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
8025 &dev_attr_fan_fan2_input
.attr
;
8027 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8032 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
8033 &driver_attr_fan_watchdog
);
8035 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8044 static void fan_exit(void)
8046 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
8047 "cancelling any pending fan watchdog tasks\n");
8049 /* FIXME: can we really do this unconditionally? */
8050 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
8051 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
8052 &driver_attr_fan_watchdog
);
8054 cancel_delayed_work(&fan_watchdog_task
);
8055 flush_workqueue(tpacpi_wq
);
8058 static void fan_suspend(pm_message_t state
)
8062 if (!fan_control_allowed
)
8065 /* Store fan status in cache */
8066 fan_control_resume_level
= 0;
8067 rc
= fan_get_status_safe(&fan_control_resume_level
);
8069 printk(TPACPI_NOTICE
8070 "failed to read fan level for later "
8071 "restore during resume: %d\n", rc
);
8073 /* if it is undefined, don't attempt to restore it.
8075 if (tp_features
.fan_ctrl_status_undef
)
8076 fan_control_resume_level
= 0;
8079 static void fan_resume(void)
8081 u8 current_level
= 7;
8082 bool do_set
= false;
8085 /* DSDT *always* updates status on resume */
8086 tp_features
.fan_ctrl_status_undef
= 0;
8088 if (!fan_control_allowed
||
8089 !fan_control_resume_level
||
8090 (fan_get_status_safe(¤t_level
) < 0))
8093 switch (fan_control_access_mode
) {
8094 case TPACPI_FAN_WR_ACPI_SFAN
:
8095 /* never decrease fan level */
8096 do_set
= (fan_control_resume_level
> current_level
);
8098 case TPACPI_FAN_WR_ACPI_FANS
:
8099 case TPACPI_FAN_WR_TPEC
:
8100 /* never decrease fan level, scale is:
8101 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
8103 * We expect the firmware to set either 7 or AUTO, but we
8104 * handle FULLSPEED out of paranoia.
8106 * So, we can safely only restore FULLSPEED or 7, anything
8107 * else could slow the fan. Restoring AUTO is useless, at
8108 * best that's exactly what the DSDT already set (it is the
8111 * Always keep in mind that the DSDT *will* have set the
8112 * fans to what the vendor supposes is the best level. We
8113 * muck with it only to speed the fan up.
8115 if (fan_control_resume_level
!= 7 &&
8116 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
8119 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
8120 (current_level
!= fan_control_resume_level
);
8126 printk(TPACPI_NOTICE
8127 "restoring fan level to 0x%02x\n",
8128 fan_control_resume_level
);
8129 rc
= fan_set_level_safe(fan_control_resume_level
);
8131 printk(TPACPI_NOTICE
8132 "failed to restore fan level: %d\n", rc
);
8136 static int fan_read(struct seq_file
*m
)
8140 unsigned int speed
= 0;
8142 switch (fan_status_access_mode
) {
8143 case TPACPI_FAN_RD_ACPI_GFAN
:
8144 /* 570, 600e/x, 770e, 770x */
8145 rc
= fan_get_status_safe(&status
);
8149 seq_printf(m
, "status:\t\t%s\n"
8151 (status
!= 0) ? "enabled" : "disabled", status
);
8154 case TPACPI_FAN_RD_TPEC
:
8155 /* all except 570, 600e/x, 770e, 770x */
8156 rc
= fan_get_status_safe(&status
);
8160 seq_printf(m
, "status:\t\t%s\n",
8161 (status
!= 0) ? "enabled" : "disabled");
8163 rc
= fan_get_speed(&speed
);
8167 seq_printf(m
, "speed:\t\t%d\n", speed
);
8169 if (status
& TP_EC_FAN_FULLSPEED
)
8170 /* Disengaged mode takes precedence */
8171 seq_printf(m
, "level:\t\tdisengaged\n");
8172 else if (status
& TP_EC_FAN_AUTO
)
8173 seq_printf(m
, "level:\t\tauto\n");
8175 seq_printf(m
, "level:\t\t%d\n", status
);
8178 case TPACPI_FAN_NONE
:
8180 seq_printf(m
, "status:\t\tnot supported\n");
8183 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
8184 seq_printf(m
, "commands:\tlevel <level>");
8186 switch (fan_control_access_mode
) {
8187 case TPACPI_FAN_WR_ACPI_SFAN
:
8188 seq_printf(m
, " (<level> is 0-7)\n");
8192 seq_printf(m
, " (<level> is 0-7, "
8193 "auto, disengaged, full-speed)\n");
8198 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
8199 seq_printf(m
, "commands:\tenable, disable\n"
8200 "commands:\twatchdog <timeout> (<timeout> "
8201 "is 0 (off), 1-120 (seconds))\n");
8203 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
8204 seq_printf(m
, "commands:\tspeed <speed>"
8205 " (<speed> is 0-65535)\n");
8210 static int fan_write_cmd_level(const char *cmd
, int *rc
)
8214 if (strlencmp(cmd
, "level auto") == 0)
8215 level
= TP_EC_FAN_AUTO
;
8216 else if ((strlencmp(cmd
, "level disengaged") == 0) |
8217 (strlencmp(cmd
, "level full-speed") == 0))
8218 level
= TP_EC_FAN_FULLSPEED
;
8219 else if (sscanf(cmd
, "level %d", &level
) != 1)
8222 *rc
= fan_set_level_safe(level
);
8224 printk(TPACPI_ERR
"level command accepted for unsupported "
8225 "access mode %d", fan_control_access_mode
);
8227 tpacpi_disclose_usertask("procfs fan",
8228 "set level to %d\n", level
);
8233 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
8235 if (strlencmp(cmd
, "enable") != 0)
8238 *rc
= fan_set_enable();
8240 printk(TPACPI_ERR
"enable command accepted for unsupported "
8241 "access mode %d", fan_control_access_mode
);
8243 tpacpi_disclose_usertask("procfs fan", "enable\n");
8248 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
8250 if (strlencmp(cmd
, "disable") != 0)
8253 *rc
= fan_set_disable();
8255 printk(TPACPI_ERR
"disable command accepted for unsupported "
8256 "access mode %d", fan_control_access_mode
);
8258 tpacpi_disclose_usertask("procfs fan", "disable\n");
8263 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
8268 * Support speed <low> <medium> <high> ? */
8270 if (sscanf(cmd
, "speed %d", &speed
) != 1)
8273 *rc
= fan_set_speed(speed
);
8275 printk(TPACPI_ERR
"speed command accepted for unsupported "
8276 "access mode %d", fan_control_access_mode
);
8278 tpacpi_disclose_usertask("procfs fan",
8279 "set speed to %d\n", speed
);
8284 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
8288 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
8291 if (interval
< 0 || interval
> 120)
8294 fan_watchdog_maxinterval
= interval
;
8295 tpacpi_disclose_usertask("procfs fan",
8296 "set watchdog timer to %d\n",
8303 static int fan_write(char *buf
)
8308 while (!rc
&& (cmd
= next_cmd(&buf
))) {
8309 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
8310 fan_write_cmd_level(cmd
, &rc
)) &&
8311 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
8312 (fan_write_cmd_enable(cmd
, &rc
) ||
8313 fan_write_cmd_disable(cmd
, &rc
) ||
8314 fan_write_cmd_watchdog(cmd
, &rc
))) &&
8315 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
8316 fan_write_cmd_speed(cmd
, &rc
))
8320 fan_watchdog_reset();
8326 static struct ibm_struct fan_driver_data
= {
8331 .suspend
= fan_suspend
,
8332 .resume
= fan_resume
,
8335 /****************************************************************************
8336 ****************************************************************************
8340 ****************************************************************************
8341 ****************************************************************************/
8344 * HKEY event callout for other subdrivers go here
8345 * (yes, it is ugly, but it is quick, safe, and gets the job done
8347 static void tpacpi_driver_event(const unsigned int hkey_event
)
8349 if (ibm_backlight_device
) {
8350 switch (hkey_event
) {
8351 case TP_HKEY_EV_BRGHT_UP
:
8352 case TP_HKEY_EV_BRGHT_DOWN
:
8353 tpacpi_brightness_notify_change();
8357 switch (hkey_event
) {
8358 case TP_HKEY_EV_VOL_UP
:
8359 case TP_HKEY_EV_VOL_DOWN
:
8360 case TP_HKEY_EV_VOL_MUTE
:
8361 volume_alsa_notify_change();
8366 static void hotkey_driver_event(const unsigned int scancode
)
8368 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
8371 /* sysfs name ---------------------------------------------------------- */
8372 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
8373 struct device_attribute
*attr
,
8376 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
8379 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
8380 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
8382 /* --------------------------------------------------------------------- */
8385 static struct proc_dir_entry
*proc_dir
;
8388 * Module and infrastructure proble, init and exit handling
8391 static int force_load
;
8393 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
8394 static const char * __init
str_supported(int is_supported
)
8396 static char text_unsupported
[] __initdata
= "not supported";
8398 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
8400 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
8402 static void ibm_exit(struct ibm_struct
*ibm
)
8404 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
8406 list_del_init(&ibm
->all_drivers
);
8408 if (ibm
->flags
.acpi_notify_installed
) {
8409 dbg_printk(TPACPI_DBG_EXIT
,
8410 "%s: acpi_remove_notify_handler\n", ibm
->name
);
8412 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
8414 dispatch_acpi_notify
);
8415 ibm
->flags
.acpi_notify_installed
= 0;
8416 ibm
->flags
.acpi_notify_installed
= 0;
8419 if (ibm
->flags
.proc_created
) {
8420 dbg_printk(TPACPI_DBG_EXIT
,
8421 "%s: remove_proc_entry\n", ibm
->name
);
8422 remove_proc_entry(ibm
->name
, proc_dir
);
8423 ibm
->flags
.proc_created
= 0;
8426 if (ibm
->flags
.acpi_driver_registered
) {
8427 dbg_printk(TPACPI_DBG_EXIT
,
8428 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
8430 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
8431 kfree(ibm
->acpi
->driver
);
8432 ibm
->acpi
->driver
= NULL
;
8433 ibm
->flags
.acpi_driver_registered
= 0;
8436 if (ibm
->flags
.init_called
&& ibm
->exit
) {
8438 ibm
->flags
.init_called
= 0;
8441 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
8444 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
8447 struct ibm_struct
*ibm
= iibm
->data
;
8448 struct proc_dir_entry
*entry
;
8450 BUG_ON(ibm
== NULL
);
8452 INIT_LIST_HEAD(&ibm
->all_drivers
);
8454 if (ibm
->flags
.experimental
&& !experimental
)
8457 dbg_printk(TPACPI_DBG_INIT
,
8458 "probing for %s\n", ibm
->name
);
8461 ret
= iibm
->init(iibm
);
8463 return 0; /* probe failed */
8467 ibm
->flags
.init_called
= 1;
8471 if (ibm
->acpi
->hid
) {
8472 ret
= register_tpacpi_subdriver(ibm
);
8477 if (ibm
->acpi
->notify
) {
8478 ret
= setup_acpi_notify(ibm
);
8479 if (ret
== -ENODEV
) {
8480 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
8490 dbg_printk(TPACPI_DBG_INIT
,
8491 "%s installed\n", ibm
->name
);
8494 mode_t mode
= iibm
->base_procfs_mode
;
8500 entry
= proc_create_data(ibm
->name
, mode
, proc_dir
,
8501 &dispatch_proc_fops
, ibm
);
8503 printk(TPACPI_ERR
"unable to create proc entry %s\n",
8508 ibm
->flags
.proc_created
= 1;
8511 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
8516 dbg_printk(TPACPI_DBG_INIT
,
8517 "%s: at error exit path with result %d\n",
8521 return (ret
< 0)? ret
: 0;
8526 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
8528 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
8531 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
8532 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
8535 return s
&& strlen(s
) >= 8 &&
8536 tpacpi_is_fw_digit(s
[0]) &&
8537 tpacpi_is_fw_digit(s
[1]) &&
8538 s
[2] == t
&& s
[3] == 'T' &&
8539 tpacpi_is_fw_digit(s
[4]) &&
8540 tpacpi_is_fw_digit(s
[5]) &&
8541 s
[6] == 'W' && s
[7] == 'W';
8544 /* returns 0 - probe ok, or < 0 - probe error.
8545 * Probe ok doesn't mean thinkpad found.
8546 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
8547 static int __must_check __init
get_thinkpad_model_data(
8548 struct thinkpad_id_data
*tp
)
8550 const struct dmi_device
*dev
= NULL
;
8551 char ec_fw_string
[18];
8557 memset(tp
, 0, sizeof(*tp
));
8559 if (dmi_name_in_vendors("IBM"))
8560 tp
->vendor
= PCI_VENDOR_ID_IBM
;
8561 else if (dmi_name_in_vendors("LENOVO"))
8562 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
8566 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
8567 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
8568 if (s
&& !tp
->bios_version_str
)
8571 /* Really ancient ThinkPad 240X will fail this, which is fine */
8572 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
8575 tp
->bios_model
= tp
->bios_version_str
[0]
8576 | (tp
->bios_version_str
[1] << 8);
8577 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
8578 | tp
->bios_version_str
[5];
8581 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
8582 * X32 or newer, all Z series; Some models must have an
8583 * up-to-date BIOS or they will not be detected.
8585 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8587 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
8588 if (sscanf(dev
->name
,
8589 "IBM ThinkPad Embedded Controller -[%17c",
8590 ec_fw_string
) == 1) {
8591 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
8592 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
8594 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
8595 if (!tp
->ec_version_str
)
8598 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
8599 tp
->ec_model
= ec_fw_string
[0]
8600 | (ec_fw_string
[1] << 8);
8601 tp
->ec_release
= (ec_fw_string
[4] << 8)
8604 printk(TPACPI_NOTICE
8605 "ThinkPad firmware release %s "
8606 "doesn't match the known patterns\n",
8608 printk(TPACPI_NOTICE
8609 "please report this to %s\n",
8616 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
8617 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
8618 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
8623 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
8624 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
8625 if (s
&& !tp
->nummodel_str
)
8631 static int __init
probe_for_thinkpad(void)
8639 * Non-ancient models have better DMI tagging, but very old models
8640 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
8642 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
8643 (thinkpad_id
.ec_model
!= 0) ||
8644 tpacpi_is_fw_known();
8646 /* ec is required because many other handles are relative to it */
8647 TPACPI_ACPIHANDLE_INIT(ec
);
8651 "Not yet supported ThinkPad detected!\n");
8655 if (!is_thinkpad
&& !force_load
)
8662 /* Module init, exit, parameters */
8664 static struct ibm_init_struct ibms_init
[] __initdata
= {
8666 .init
= thinkpad_acpi_driver_init
,
8667 .data
= &thinkpad_acpi_driver_data
,
8670 .init
= hotkey_init
,
8671 .data
= &hotkey_driver_data
,
8674 .init
= bluetooth_init
,
8675 .data
= &bluetooth_driver_data
,
8679 .data
= &wan_driver_data
,
8683 .data
= &uwb_driver_data
,
8685 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8688 .base_procfs_mode
= S_IRUSR
,
8689 .data
= &video_driver_data
,
8694 .data
= &light_driver_data
,
8698 .data
= &cmos_driver_data
,
8702 .data
= &led_driver_data
,
8706 .data
= &beep_driver_data
,
8709 .init
= thermal_init
,
8710 .data
= &thermal_driver_data
,
8713 .data
= &ecdump_driver_data
,
8716 .init
= brightness_init
,
8717 .data
= &brightness_driver_data
,
8720 .init
= volume_init
,
8721 .data
= &volume_driver_data
,
8725 .data
= &fan_driver_data
,
8729 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
8732 struct ibm_struct
*ibm
;
8734 if (!kp
|| !kp
->name
|| !val
)
8737 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8738 ibm
= ibms_init
[i
].data
;
8739 WARN_ON(ibm
== NULL
);
8741 if (!ibm
|| !ibm
->name
)
8744 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8745 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8747 strcpy(ibms_init
[i
].param
, val
);
8748 strcat(ibms_init
[i
].param
, ",");
8756 module_param(experimental
, int, 0444);
8757 MODULE_PARM_DESC(experimental
,
8758 "Enables experimental features when non-zero");
8760 module_param_named(debug
, dbg_level
, uint
, 0);
8761 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8763 module_param(force_load
, bool, 0444);
8764 MODULE_PARM_DESC(force_load
,
8765 "Attempts to load the driver even on a "
8766 "mis-identified ThinkPad when true");
8768 module_param_named(fan_control
, fan_control_allowed
, bool, 0444);
8769 MODULE_PARM_DESC(fan_control
,
8770 "Enables setting fan parameters features when true");
8772 module_param_named(brightness_mode
, brightness_mode
, uint
, 0444);
8773 MODULE_PARM_DESC(brightness_mode
,
8774 "Selects brightness control strategy: "
8775 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8777 module_param(brightness_enable
, uint
, 0444);
8778 MODULE_PARM_DESC(brightness_enable
,
8779 "Enables backlight control when 1, disables when 0");
8781 module_param(hotkey_report_mode
, uint
, 0444);
8782 MODULE_PARM_DESC(hotkey_report_mode
,
8783 "used for backwards compatibility with userspace, "
8784 "see documentation");
8786 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
8787 module_param_named(volume_mode
, volume_mode
, uint
, 0444);
8788 MODULE_PARM_DESC(volume_mode
,
8789 "Selects volume control strategy: "
8790 "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM");
8792 module_param_named(volume_capabilities
, volume_capabilities
, uint
, 0444);
8793 MODULE_PARM_DESC(volume_capabilities
,
8794 "Selects the mixer capabilites: "
8795 "0=auto, 1=volume and mute, 2=mute only");
8797 module_param_named(volume_control
, volume_control_allowed
, bool, 0444);
8798 MODULE_PARM_DESC(volume_control
,
8799 "Enables software override for the console audio "
8800 "control when true");
8802 /* ALSA module API parameters */
8803 module_param_named(index
, alsa_index
, int, 0444);
8804 MODULE_PARM_DESC(index
, "ALSA index for the ACPI EC Mixer");
8805 module_param_named(id
, alsa_id
, charp
, 0444);
8806 MODULE_PARM_DESC(id
, "ALSA id for the ACPI EC Mixer");
8807 module_param_named(enable
, alsa_enable
, bool, 0444);
8808 MODULE_PARM_DESC(enable
, "Enable the ALSA interface for the ACPI EC Mixer");
8809 #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
8811 #define TPACPI_PARAM(feature) \
8812 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8813 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8814 "at module load, see documentation")
8816 TPACPI_PARAM(hotkey
);
8817 TPACPI_PARAM(bluetooth
);
8818 TPACPI_PARAM(video
);
8819 TPACPI_PARAM(light
);
8823 TPACPI_PARAM(ecdump
);
8824 TPACPI_PARAM(brightness
);
8825 TPACPI_PARAM(volume
);
8828 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8829 module_param(dbg_wlswemul
, uint
, 0444);
8830 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
8831 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
8832 MODULE_PARM_DESC(wlsw_state
,
8833 "Initial state of the emulated WLSW switch");
8835 module_param(dbg_bluetoothemul
, uint
, 0444);
8836 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
8837 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
8838 MODULE_PARM_DESC(bluetooth_state
,
8839 "Initial state of the emulated bluetooth switch");
8841 module_param(dbg_wwanemul
, uint
, 0444);
8842 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
8843 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
8844 MODULE_PARM_DESC(wwan_state
,
8845 "Initial state of the emulated WWAN switch");
8847 module_param(dbg_uwbemul
, uint
, 0444);
8848 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
8849 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
8850 MODULE_PARM_DESC(uwb_state
,
8851 "Initial state of the emulated UWB switch");
8854 static void thinkpad_acpi_module_exit(void)
8856 struct ibm_struct
*ibm
, *itmp
;
8858 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
8860 list_for_each_entry_safe_reverse(ibm
, itmp
,
8861 &tpacpi_all_drivers
,
8866 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
8868 if (tpacpi_inputdev
) {
8869 if (tp_features
.input_device_registered
)
8870 input_unregister_device(tpacpi_inputdev
);
8872 input_free_device(tpacpi_inputdev
);
8876 hwmon_device_unregister(tpacpi_hwmon
);
8878 if (tp_features
.sensors_pdev_attrs_registered
)
8879 device_remove_file(&tpacpi_sensors_pdev
->dev
,
8880 &dev_attr_thinkpad_acpi_pdev_name
);
8881 if (tpacpi_sensors_pdev
)
8882 platform_device_unregister(tpacpi_sensors_pdev
);
8884 platform_device_unregister(tpacpi_pdev
);
8886 if (tp_features
.sensors_pdrv_attrs_registered
)
8887 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
8888 if (tp_features
.platform_drv_attrs_registered
)
8889 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
8891 if (tp_features
.sensors_pdrv_registered
)
8892 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
8894 if (tp_features
.platform_drv_registered
)
8895 platform_driver_unregister(&tpacpi_pdriver
);
8898 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
8901 destroy_workqueue(tpacpi_wq
);
8903 kfree(thinkpad_id
.bios_version_str
);
8904 kfree(thinkpad_id
.ec_version_str
);
8905 kfree(thinkpad_id
.model_str
);
8909 static int __init
thinkpad_acpi_module_init(void)
8913 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
8915 /* Parameter checking */
8916 if (hotkey_report_mode
> 2)
8919 /* Driver-level probe */
8921 ret
= get_thinkpad_model_data(&thinkpad_id
);
8924 "unable to get DMI data: %d\n", ret
);
8925 thinkpad_acpi_module_exit();
8928 ret
= probe_for_thinkpad();
8930 thinkpad_acpi_module_exit();
8934 /* Driver initialization */
8936 TPACPI_ACPIHANDLE_INIT(ecrd
);
8937 TPACPI_ACPIHANDLE_INIT(ecwr
);
8939 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
8941 thinkpad_acpi_module_exit();
8945 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
8948 "unable to create proc dir " TPACPI_PROC_DIR
);
8949 thinkpad_acpi_module_exit();
8952 proc_dir
->owner
= THIS_MODULE
;
8954 ret
= platform_driver_register(&tpacpi_pdriver
);
8957 "unable to register main platform driver\n");
8958 thinkpad_acpi_module_exit();
8961 tp_features
.platform_drv_registered
= 1;
8963 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
8966 "unable to register hwmon platform driver\n");
8967 thinkpad_acpi_module_exit();
8970 tp_features
.sensors_pdrv_registered
= 1;
8972 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
8974 tp_features
.platform_drv_attrs_registered
= 1;
8975 ret
= tpacpi_create_driver_attributes(
8976 &tpacpi_hwmon_pdriver
.driver
);
8980 "unable to create sysfs driver attributes\n");
8981 thinkpad_acpi_module_exit();
8984 tp_features
.sensors_pdrv_attrs_registered
= 1;
8987 /* Device initialization */
8988 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
8990 if (IS_ERR(tpacpi_pdev
)) {
8991 ret
= PTR_ERR(tpacpi_pdev
);
8993 printk(TPACPI_ERR
"unable to register platform device\n");
8994 thinkpad_acpi_module_exit();
8997 tpacpi_sensors_pdev
= platform_device_register_simple(
8998 TPACPI_HWMON_DRVR_NAME
,
9000 if (IS_ERR(tpacpi_sensors_pdev
)) {
9001 ret
= PTR_ERR(tpacpi_sensors_pdev
);
9002 tpacpi_sensors_pdev
= NULL
;
9004 "unable to register hwmon platform device\n");
9005 thinkpad_acpi_module_exit();
9008 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
9009 &dev_attr_thinkpad_acpi_pdev_name
);
9012 "unable to create sysfs hwmon device attributes\n");
9013 thinkpad_acpi_module_exit();
9016 tp_features
.sensors_pdev_attrs_registered
= 1;
9017 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
9018 if (IS_ERR(tpacpi_hwmon
)) {
9019 ret
= PTR_ERR(tpacpi_hwmon
);
9020 tpacpi_hwmon
= NULL
;
9021 printk(TPACPI_ERR
"unable to register hwmon device\n");
9022 thinkpad_acpi_module_exit();
9025 mutex_init(&tpacpi_inputdev_send_mutex
);
9026 tpacpi_inputdev
= input_allocate_device();
9027 if (!tpacpi_inputdev
) {
9028 printk(TPACPI_ERR
"unable to allocate input device\n");
9029 thinkpad_acpi_module_exit();
9032 /* Prepare input device, but don't register */
9033 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
9034 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
9035 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
9036 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
9037 thinkpad_id
.vendor
:
9039 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
9040 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
9041 tpacpi_inputdev
->dev
.parent
= &tpacpi_pdev
->dev
;
9043 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
9044 ret
= ibm_init(&ibms_init
[i
]);
9045 if (ret
>= 0 && *ibms_init
[i
].param
)
9046 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
9048 thinkpad_acpi_module_exit();
9053 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
9055 ret
= input_register_device(tpacpi_inputdev
);
9057 printk(TPACPI_ERR
"unable to register input device\n");
9058 thinkpad_acpi_module_exit();
9061 tp_features
.input_device_registered
= 1;
9067 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
9070 * This will autoload the driver in almost every ThinkPad
9071 * in widespread use.
9073 * Only _VERY_ old models, like the 240, 240x and 570 lack
9074 * the HKEY event interface.
9076 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
9079 * DMI matching for module autoloading
9081 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
9082 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
9084 * Only models listed in thinkwiki will be supported, so add yours
9085 * if it is not there yet.
9087 #define IBM_BIOS_MODULE_ALIAS(__type) \
9088 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
9090 /* Ancient thinkpad BIOSes have to be identified by
9091 * BIOS type or model number, and there are far less
9092 * BIOS types than model numbers... */
9093 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
9095 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
9096 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
9097 MODULE_DESCRIPTION(TPACPI_DESC
);
9098 MODULE_VERSION(TPACPI_VERSION
);
9099 MODULE_LICENSE("GPL");
9101 module_init(thinkpad_acpi_module_init
);
9102 module_exit(thinkpad_acpi_module_exit
);