2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define TPACPI_VERSION "0.24"
25 #define TPACPI_SYSFS_VERSION 0x020700
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/sched.h>
58 #include <linux/kthread.h>
59 #include <linux/freezer.h>
60 #include <linux/delay.h>
61 #include <linux/slab.h>
63 #include <linux/nvram.h>
64 #include <linux/proc_fs.h>
65 #include <linux/seq_file.h>
66 #include <linux/sysfs.h>
67 #include <linux/backlight.h>
69 #include <linux/platform_device.h>
70 #include <linux/hwmon.h>
71 #include <linux/hwmon-sysfs.h>
72 #include <linux/input.h>
73 #include <linux/leds.h>
74 #include <linux/rfkill.h>
75 #include <asm/uaccess.h>
77 #include <linux/dmi.h>
78 #include <linux/jiffies.h>
79 #include <linux/workqueue.h>
81 #include <sound/core.h>
82 #include <sound/control.h>
83 #include <sound/initval.h>
85 #include <acpi/acpi_drivers.h>
87 #include <linux/pci_ids.h>
90 /* ThinkPad CMOS commands */
91 #define TP_CMOS_VOLUME_DOWN 0
92 #define TP_CMOS_VOLUME_UP 1
93 #define TP_CMOS_VOLUME_MUTE 2
94 #define TP_CMOS_BRIGHTNESS_UP 4
95 #define TP_CMOS_BRIGHTNESS_DOWN 5
96 #define TP_CMOS_THINKLIGHT_ON 12
97 #define TP_CMOS_THINKLIGHT_OFF 13
101 TP_NVRAM_ADDR_HK2
= 0x57,
102 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
103 TP_NVRAM_ADDR_VIDEO
= 0x59,
104 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
105 TP_NVRAM_ADDR_MIXER
= 0x60,
108 /* NVRAM bit masks */
110 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
111 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
112 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
113 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
114 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
115 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
116 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
117 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
118 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
119 TP_NVRAM_MASK_MUTE
= 0x40,
120 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
121 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
122 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
125 /* Misc NVRAM-related */
127 TP_NVRAM_LEVEL_VOLUME_MAX
= 14,
131 #define TPACPI_ACPI_IBM_HKEY_HID "IBM0068"
132 #define TPACPI_ACPI_LENOVO_HKEY_HID "LEN0068"
133 #define TPACPI_ACPI_EC_HID "PNP0C09"
136 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
137 #define TPACPI_HKEY_INPUT_VERSION 0x4101
139 /* ACPI \WGSV commands */
141 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
142 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
143 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
144 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
147 /* TP_ACPI_WGSV_GET_STATE bits */
149 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
150 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
151 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
152 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
153 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
154 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
155 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
156 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
157 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
158 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
162 enum tpacpi_hkey_event_t
{
164 TP_HKEY_EV_HOTKEY_BASE
= 0x1001, /* first hotkey (FN+F1) */
165 TP_HKEY_EV_BRGHT_UP
= 0x1010, /* Brightness up */
166 TP_HKEY_EV_BRGHT_DOWN
= 0x1011, /* Brightness down */
167 TP_HKEY_EV_VOL_UP
= 0x1015, /* Volume up or unmute */
168 TP_HKEY_EV_VOL_DOWN
= 0x1016, /* Volume down or unmute */
169 TP_HKEY_EV_VOL_MUTE
= 0x1017, /* Mixer output mute */
171 /* Reasons for waking up from S3/S4 */
172 TP_HKEY_EV_WKUP_S3_UNDOCK
= 0x2304, /* undock requested, S3 */
173 TP_HKEY_EV_WKUP_S4_UNDOCK
= 0x2404, /* undock requested, S4 */
174 TP_HKEY_EV_WKUP_S3_BAYEJ
= 0x2305, /* bay ejection req, S3 */
175 TP_HKEY_EV_WKUP_S4_BAYEJ
= 0x2405, /* bay ejection req, S4 */
176 TP_HKEY_EV_WKUP_S3_BATLOW
= 0x2313, /* battery empty, S3 */
177 TP_HKEY_EV_WKUP_S4_BATLOW
= 0x2413, /* battery empty, S4 */
179 /* Auto-sleep after eject request */
180 TP_HKEY_EV_BAYEJ_ACK
= 0x3003, /* bay ejection complete */
181 TP_HKEY_EV_UNDOCK_ACK
= 0x4003, /* undock complete */
183 /* Misc bay events */
184 TP_HKEY_EV_OPTDRV_EJ
= 0x3006, /* opt. drive tray ejected */
186 /* User-interface events */
187 TP_HKEY_EV_LID_CLOSE
= 0x5001, /* laptop lid closed */
188 TP_HKEY_EV_LID_OPEN
= 0x5002, /* laptop lid opened */
189 TP_HKEY_EV_TABLET_TABLET
= 0x5009, /* tablet swivel up */
190 TP_HKEY_EV_TABLET_NOTEBOOK
= 0x500a, /* tablet swivel down */
191 TP_HKEY_EV_PEN_INSERTED
= 0x500b, /* tablet pen inserted */
192 TP_HKEY_EV_PEN_REMOVED
= 0x500c, /* tablet pen removed */
193 TP_HKEY_EV_BRGHT_CHANGED
= 0x5010, /* backlight control event */
196 TP_HKEY_EV_ALARM_BAT_HOT
= 0x6011, /* battery too hot */
197 TP_HKEY_EV_ALARM_BAT_XHOT
= 0x6012, /* battery critically hot */
198 TP_HKEY_EV_ALARM_SENSOR_HOT
= 0x6021, /* sensor too hot */
199 TP_HKEY_EV_ALARM_SENSOR_XHOT
= 0x6022, /* sensor critically hot */
200 TP_HKEY_EV_THM_TABLE_CHANGED
= 0x6030, /* thermal table changed */
203 TP_HKEY_EV_RFKILL_CHANGED
= 0x7000, /* rfkill switch changed */
206 /****************************************************************************
210 #define TPACPI_NAME "thinkpad"
211 #define TPACPI_DESC "ThinkPad ACPI Extras"
212 #define TPACPI_FILE TPACPI_NAME "_acpi"
213 #define TPACPI_URL "http://ibm-acpi.sf.net/"
214 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
216 #define TPACPI_PROC_DIR "ibm"
217 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
218 #define TPACPI_DRVR_NAME TPACPI_FILE
219 #define TPACPI_DRVR_SHORTNAME "tpacpi"
220 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
222 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
223 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
225 #define TPACPI_MAX_ACPI_ARGS 3
228 #define TPACPI_LOG TPACPI_FILE ": "
229 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
230 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
231 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
232 #define TPACPI_ERR KERN_ERR TPACPI_LOG
233 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
234 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
235 #define TPACPI_INFO KERN_INFO TPACPI_LOG
236 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
238 /* Debugging printk groups */
239 #define TPACPI_DBG_ALL 0xffff
240 #define TPACPI_DBG_DISCLOSETASK 0x8000
241 #define TPACPI_DBG_INIT 0x0001
242 #define TPACPI_DBG_EXIT 0x0002
243 #define TPACPI_DBG_RFKILL 0x0004
244 #define TPACPI_DBG_HKEY 0x0008
245 #define TPACPI_DBG_FAN 0x0010
246 #define TPACPI_DBG_BRGHT 0x0020
247 #define TPACPI_DBG_MIXER 0x0040
249 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
250 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
251 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
254 /****************************************************************************
255 * Driver-wide structs and misc. variables
260 struct tp_acpi_drv_struct
{
261 const struct acpi_device_id
*hid
;
262 struct acpi_driver
*driver
;
264 void (*notify
) (struct ibm_struct
*, u32
);
267 struct acpi_device
*device
;
273 int (*read
) (struct seq_file
*);
274 int (*write
) (char *);
276 void (*resume
) (void);
277 void (*suspend
) (pm_message_t state
);
278 void (*shutdown
) (void);
280 struct list_head all_drivers
;
282 struct tp_acpi_drv_struct
*acpi
;
285 u8 acpi_driver_registered
:1;
286 u8 acpi_notify_installed
:1;
293 struct ibm_init_struct
{
296 int (*init
) (struct ibm_init_struct
*);
297 mode_t base_procfs_mode
;
298 struct ibm_struct
*data
;
309 u32 bright_acpimode
:1;
313 u32 fan_ctrl_status_undef
:1;
315 u32 beep_needs_two_args
:1;
316 u32 mixer_no_level_control
:1;
317 u32 input_device_registered
:1;
318 u32 platform_drv_registered
:1;
319 u32 platform_drv_attrs_registered
:1;
320 u32 sensors_pdrv_registered
:1;
321 u32 sensors_pdrv_attrs_registered
:1;
322 u32 sensors_pdev_attrs_registered
:1;
323 u32 hotkey_poll_active
:1;
327 u16 hotkey_mask_ff
:1;
328 u16 volume_ctrl_forbidden
:1;
331 struct thinkpad_id_data
{
332 unsigned int vendor
; /* ThinkPad vendor:
333 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
335 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
336 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
338 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
340 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
343 char *model_str
; /* ThinkPad T43 */
344 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
346 static struct thinkpad_id_data thinkpad_id
;
349 TPACPI_LIFE_INIT
= 0,
354 static int experimental
;
355 static u32 dbg_level
;
357 static struct workqueue_struct
*tpacpi_wq
;
365 /* Special LED class that can defer work */
366 struct tpacpi_led_classdev
{
367 struct led_classdev led_classdev
;
368 struct work_struct work
;
369 enum led_status_t new_state
;
373 /* brightness level capabilities */
374 static unsigned int bright_maxlvl
; /* 0 = unknown */
376 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
377 static int dbg_wlswemul
;
378 static int tpacpi_wlsw_emulstate
;
379 static int dbg_bluetoothemul
;
380 static int tpacpi_bluetooth_emulstate
;
381 static int dbg_wwanemul
;
382 static int tpacpi_wwan_emulstate
;
383 static int dbg_uwbemul
;
384 static int tpacpi_uwb_emulstate
;
388 /*************************************************************************
392 #define dbg_printk(a_dbg_level, format, arg...) \
393 do { if (dbg_level & (a_dbg_level)) \
394 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
397 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
398 #define vdbg_printk dbg_printk
399 static const char *str_supported(int is_supported
);
401 #define vdbg_printk(a_dbg_level, format, arg...) \
405 static void tpacpi_log_usertask(const char * const what
)
407 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
408 what
, task_tgid_vnr(current
));
411 #define tpacpi_disclose_usertask(what, format, arg...) \
414 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
415 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
416 printk(TPACPI_DEBUG "%s: PID %d: " format, \
417 what, task_tgid_vnr(current), ## arg); \
422 * Quirk handling helpers
424 * ThinkPad IDs and versions seen in the field so far
425 * are two-characters from the set [0-9A-Z], i.e. base 36.
427 * We use values well outside that range as specials.
430 #define TPACPI_MATCH_ANY 0xffffU
431 #define TPACPI_MATCH_UNKNOWN 0U
433 /* TPID('1', 'Y') == 0x5931 */
434 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
436 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
437 { .vendor = PCI_VENDOR_ID_IBM, \
438 .bios = TPID(__id1, __id2), \
439 .ec = TPACPI_MATCH_ANY, \
440 .quirks = (__quirk) }
442 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
443 { .vendor = PCI_VENDOR_ID_LENOVO, \
444 .bios = TPID(__id1, __id2), \
445 .ec = TPACPI_MATCH_ANY, \
446 .quirks = (__quirk) }
448 #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \
449 { .vendor = PCI_VENDOR_ID_LENOVO, \
450 .bios = TPACPI_MATCH_ANY, \
451 .ec = TPID(__id1, __id2), \
452 .quirks = (__quirk) }
454 struct tpacpi_quirk
{
458 unsigned long quirks
;
462 * tpacpi_check_quirks() - search BIOS/EC version on a list
463 * @qlist: array of &struct tpacpi_quirk
464 * @qlist_size: number of elements in @qlist
466 * Iterates over a quirks list until one is found that matches the
467 * ThinkPad's vendor, BIOS and EC model.
469 * Returns 0 if nothing matches, otherwise returns the quirks field of
470 * the matching &struct tpacpi_quirk entry.
472 * The match criteria is: vendor, ec and bios much match.
474 static unsigned long __init
tpacpi_check_quirks(
475 const struct tpacpi_quirk
*qlist
,
476 unsigned int qlist_size
)
479 if ((qlist
->vendor
== thinkpad_id
.vendor
||
480 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
481 (qlist
->bios
== thinkpad_id
.bios_model
||
482 qlist
->bios
== TPACPI_MATCH_ANY
) &&
483 (qlist
->ec
== thinkpad_id
.ec_model
||
484 qlist
->ec
== TPACPI_MATCH_ANY
))
485 return qlist
->quirks
;
493 static inline bool __pure __init
tpacpi_is_lenovo(void)
495 return thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
;
498 static inline bool __pure __init
tpacpi_is_ibm(void)
500 return thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
;
503 /****************************************************************************
504 ****************************************************************************
506 * ACPI Helpers and device model
508 ****************************************************************************
509 ****************************************************************************/
511 /*************************************************************************
515 static acpi_handle root_handle
;
516 static acpi_handle ec_handle
;
518 #define TPACPI_HANDLE(object, parent, paths...) \
519 static acpi_handle object##_handle; \
520 static const acpi_handle *object##_parent __initdata = \
522 static char *object##_paths[] __initdata = { paths }
524 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
525 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
527 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
529 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
530 "\\CMS", /* R40, R40e */
533 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
534 "^HKEY", /* R30, R31 */
535 "HKEY", /* all others */
538 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
539 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
540 "\\_SB.PCI0.VID0", /* 770e */
541 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
542 "\\_SB.PCI0.AGP.VGA", /* X100e and a few others */
543 "\\_SB.PCI0.AGP.VID", /* all others */
547 /*************************************************************************
551 static int acpi_evalf(acpi_handle handle
,
552 void *res
, char *method
, char *fmt
, ...)
555 struct acpi_object_list params
;
556 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
557 struct acpi_buffer result
, *resultp
;
558 union acpi_object out_obj
;
566 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
579 params
.pointer
= &in_objs
[0];
586 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
587 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
589 /* add more types as needed */
591 printk(TPACPI_ERR
"acpi_evalf() called "
592 "with invalid format character '%c'\n", c
);
599 if (res_type
!= 'v') {
600 result
.length
= sizeof(out_obj
);
601 result
.pointer
= &out_obj
;
606 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
610 success
= (status
== AE_OK
&&
611 out_obj
.type
== ACPI_TYPE_INTEGER
);
613 *(int *)res
= out_obj
.integer
.value
;
616 success
= status
== AE_OK
;
618 /* add more types as needed */
620 printk(TPACPI_ERR
"acpi_evalf() called "
621 "with invalid format character '%c'\n", res_type
);
625 if (!success
&& !quiet
)
626 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %s\n",
627 method
, fmt0
, acpi_format_exception(status
));
632 static int acpi_ec_read(int i
, u8
*p
)
637 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
641 if (ec_read(i
, p
) < 0)
648 static int acpi_ec_write(int i
, u8 v
)
651 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
654 if (ec_write(i
, v
) < 0)
661 static int issue_thinkpad_cmos_command(int cmos_cmd
)
666 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
672 /*************************************************************************
676 #define TPACPI_ACPIHANDLE_INIT(object) \
677 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
678 object##_paths, ARRAY_SIZE(object##_paths))
680 static void __init
drv_acpi_handle_init(const char *name
,
681 acpi_handle
*handle
, const acpi_handle parent
,
682 char **paths
, const int num_paths
)
687 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
690 for (i
= 0; i
< num_paths
; i
++) {
691 status
= acpi_get_handle(parent
, paths
[i
], handle
);
692 if (ACPI_SUCCESS(status
)) {
693 dbg_printk(TPACPI_DBG_INIT
,
694 "Found ACPI handle %s for %s\n",
700 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
705 static acpi_status __init
tpacpi_acpi_handle_locate_callback(acpi_handle handle
,
706 u32 level
, void *context
, void **return_value
)
708 *(acpi_handle
*)return_value
= handle
;
710 return AE_CTRL_TERMINATE
;
713 static void __init
tpacpi_acpi_handle_locate(const char *name
,
718 acpi_handle device_found
;
720 BUG_ON(!name
|| !hid
|| !handle
);
721 vdbg_printk(TPACPI_DBG_INIT
,
722 "trying to locate ACPI handle for %s, using HID %s\n",
725 memset(&device_found
, 0, sizeof(device_found
));
726 status
= acpi_get_devices(hid
, tpacpi_acpi_handle_locate_callback
,
727 (void *)name
, &device_found
);
731 if (ACPI_SUCCESS(status
)) {
732 *handle
= device_found
;
733 dbg_printk(TPACPI_DBG_INIT
,
734 "Found ACPI handle for %s\n", name
);
736 vdbg_printk(TPACPI_DBG_INIT
,
737 "Could not locate an ACPI handle for %s: %s\n",
738 name
, acpi_format_exception(status
));
742 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
744 struct ibm_struct
*ibm
= data
;
746 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
749 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
752 ibm
->acpi
->notify(ibm
, event
);
755 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
762 if (!*ibm
->acpi
->handle
)
765 vdbg_printk(TPACPI_DBG_INIT
,
766 "setting up ACPI notify for %s\n", ibm
->name
);
768 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
770 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
775 ibm
->acpi
->device
->driver_data
= ibm
;
776 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
777 TPACPI_ACPI_EVENT_PREFIX
,
780 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
781 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
782 if (ACPI_FAILURE(status
)) {
783 if (status
== AE_ALREADY_EXISTS
) {
785 "another device driver is already "
786 "handling %s events\n", ibm
->name
);
789 "acpi_install_notify_handler(%s) failed: %s\n",
790 ibm
->name
, acpi_format_exception(status
));
794 ibm
->flags
.acpi_notify_installed
= 1;
798 static int __init
tpacpi_device_add(struct acpi_device
*device
)
803 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
807 dbg_printk(TPACPI_DBG_INIT
,
808 "registering %s as an ACPI driver\n", ibm
->name
);
812 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
813 if (!ibm
->acpi
->driver
) {
815 "failed to allocate memory for ibm->acpi->driver\n");
819 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
820 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
822 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
824 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
826 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
828 kfree(ibm
->acpi
->driver
);
829 ibm
->acpi
->driver
= NULL
;
831 ibm
->flags
.acpi_driver_registered
= 1;
837 /****************************************************************************
838 ****************************************************************************
842 ****************************************************************************
843 ****************************************************************************/
845 static int dispatch_proc_show(struct seq_file
*m
, void *v
)
847 struct ibm_struct
*ibm
= m
->private;
849 if (!ibm
|| !ibm
->read
)
854 static int dispatch_proc_open(struct inode
*inode
, struct file
*file
)
856 return single_open(file
, dispatch_proc_show
, PDE(inode
)->data
);
859 static ssize_t
dispatch_proc_write(struct file
*file
,
860 const char __user
*userbuf
,
861 size_t count
, loff_t
*pos
)
863 struct ibm_struct
*ibm
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
867 if (!ibm
|| !ibm
->write
)
869 if (count
> PAGE_SIZE
- 2)
872 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
876 if (copy_from_user(kernbuf
, userbuf
, count
)) {
882 strcat(kernbuf
, ",");
883 ret
= ibm
->write(kernbuf
);
892 static const struct file_operations dispatch_proc_fops
= {
893 .owner
= THIS_MODULE
,
894 .open
= dispatch_proc_open
,
897 .release
= single_release
,
898 .write
= dispatch_proc_write
,
901 static char *next_cmd(char **cmds
)
906 while ((end
= strchr(start
, ',')) && end
== start
)
918 /****************************************************************************
919 ****************************************************************************
921 * Device model: input, hwmon and platform
923 ****************************************************************************
924 ****************************************************************************/
926 static struct platform_device
*tpacpi_pdev
;
927 static struct platform_device
*tpacpi_sensors_pdev
;
928 static struct device
*tpacpi_hwmon
;
929 static struct input_dev
*tpacpi_inputdev
;
930 static struct mutex tpacpi_inputdev_send_mutex
;
931 static LIST_HEAD(tpacpi_all_drivers
);
933 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
936 struct ibm_struct
*ibm
, *itmp
;
938 list_for_each_entry_safe(ibm
, itmp
,
942 (ibm
->suspend
)(state
);
948 static int tpacpi_resume_handler(struct platform_device
*pdev
)
950 struct ibm_struct
*ibm
, *itmp
;
952 list_for_each_entry_safe(ibm
, itmp
,
962 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
964 struct ibm_struct
*ibm
, *itmp
;
966 list_for_each_entry_safe(ibm
, itmp
,
974 static struct platform_driver tpacpi_pdriver
= {
976 .name
= TPACPI_DRVR_NAME
,
977 .owner
= THIS_MODULE
,
979 .suspend
= tpacpi_suspend_handler
,
980 .resume
= tpacpi_resume_handler
,
981 .shutdown
= tpacpi_shutdown_handler
,
984 static struct platform_driver tpacpi_hwmon_pdriver
= {
986 .name
= TPACPI_HWMON_DRVR_NAME
,
987 .owner
= THIS_MODULE
,
991 /*************************************************************************
992 * sysfs support helpers
995 struct attribute_set
{
996 unsigned int members
, max_members
;
997 struct attribute_group group
;
1000 struct attribute_set_obj
{
1001 struct attribute_set s
;
1002 struct attribute
*a
;
1003 } __attribute__((packed
));
1005 static struct attribute_set
*create_attr_set(unsigned int max_members
,
1008 struct attribute_set_obj
*sobj
;
1010 if (max_members
== 0)
1013 /* Allocates space for implicit NULL at the end too */
1014 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
1015 max_members
* sizeof(struct attribute
*),
1019 sobj
->s
.max_members
= max_members
;
1020 sobj
->s
.group
.attrs
= &sobj
->a
;
1021 sobj
->s
.group
.name
= name
;
1026 #define destroy_attr_set(_set) \
1029 /* not multi-threaded safe, use it in a single thread per set */
1030 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
1035 if (s
->members
>= s
->max_members
)
1038 s
->group
.attrs
[s
->members
] = attr
;
1044 static int add_many_to_attr_set(struct attribute_set
*s
,
1045 struct attribute
**attr
,
1050 for (i
= 0; i
< count
; i
++) {
1051 res
= add_to_attr_set(s
, attr
[i
]);
1059 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
1061 sysfs_remove_group(kobj
, &s
->group
);
1062 destroy_attr_set(s
);
1065 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
1066 sysfs_create_group(_kobj, &_attr_set->group)
1068 static int parse_strtoul(const char *buf
,
1069 unsigned long max
, unsigned long *value
)
1073 *value
= simple_strtoul(skip_spaces(buf
), &endp
, 0);
1074 endp
= skip_spaces(endp
);
1075 if (*endp
|| *value
> max
)
1081 static void tpacpi_disable_brightness_delay(void)
1083 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
1084 printk(TPACPI_NOTICE
1085 "ACPI backlight control delay disabled\n");
1088 static void printk_deprecated_attribute(const char * const what
,
1089 const char * const details
)
1091 tpacpi_log_usertask("deprecated sysfs attribute");
1092 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1093 "will be removed. %s\n",
1097 /*************************************************************************
1098 * rfkill and radio control support helpers
1102 * ThinkPad-ACPI firmware handling model:
1104 * WLSW (master wireless switch) is event-driven, and is common to all
1105 * firmware-controlled radios. It cannot be controlled, just monitored,
1106 * as expected. It overrides all radio state in firmware
1108 * The kernel, a masked-off hotkey, and WLSW can change the radio state
1109 * (TODO: verify how WLSW interacts with the returned radio state).
1111 * The only time there are shadow radio state changes, is when
1112 * masked-off hotkeys are used.
1116 * Internal driver API for radio state:
1118 * int: < 0 = error, otherwise enum tpacpi_rfkill_state
1119 * bool: true means radio blocked (off)
1121 enum tpacpi_rfkill_state
{
1122 TPACPI_RFK_RADIO_OFF
= 0,
1126 /* rfkill switches */
1127 enum tpacpi_rfk_id
{
1128 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
1129 TPACPI_RFK_WWAN_SW_ID
,
1130 TPACPI_RFK_UWB_SW_ID
,
1134 static const char *tpacpi_rfkill_names
[] = {
1135 [TPACPI_RFK_BLUETOOTH_SW_ID
] = "bluetooth",
1136 [TPACPI_RFK_WWAN_SW_ID
] = "wwan",
1137 [TPACPI_RFK_UWB_SW_ID
] = "uwb",
1138 [TPACPI_RFK_SW_MAX
] = NULL
1141 /* ThinkPad-ACPI rfkill subdriver */
1143 struct rfkill
*rfkill
;
1144 enum tpacpi_rfk_id id
;
1145 const struct tpacpi_rfk_ops
*ops
;
1148 struct tpacpi_rfk_ops
{
1149 /* firmware interface */
1150 int (*get_status
)(void);
1151 int (*set_status
)(const enum tpacpi_rfkill_state
);
1154 static struct tpacpi_rfk
*tpacpi_rfkill_switches
[TPACPI_RFK_SW_MAX
];
1156 /* Query FW and update rfkill sw state for a given rfkill switch */
1157 static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk
*tp_rfk
)
1164 status
= (tp_rfk
->ops
->get_status
)();
1168 rfkill_set_sw_state(tp_rfk
->rfkill
,
1169 (status
== TPACPI_RFK_RADIO_OFF
));
1174 /* Query FW and update rfkill sw state for all rfkill switches */
1175 static void tpacpi_rfk_update_swstate_all(void)
1179 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++)
1180 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[i
]);
1184 * Sync the HW-blocking state of all rfkill switches,
1185 * do notice it causes the rfkill core to schedule uevents
1187 static void tpacpi_rfk_update_hwblock_state(bool blocked
)
1190 struct tpacpi_rfk
*tp_rfk
;
1192 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++) {
1193 tp_rfk
= tpacpi_rfkill_switches
[i
];
1195 if (rfkill_set_hw_state(tp_rfk
->rfkill
,
1197 /* ignore -- we track sw block */
1203 /* Call to get the WLSW state from the firmware */
1204 static int hotkey_get_wlsw(void);
1206 /* Call to query WLSW state and update all rfkill switches */
1207 static bool tpacpi_rfk_check_hwblock_state(void)
1209 int res
= hotkey_get_wlsw();
1212 /* When unknown or unsupported, we have to assume it is unblocked */
1216 hw_blocked
= (res
== TPACPI_RFK_RADIO_OFF
);
1217 tpacpi_rfk_update_hwblock_state(hw_blocked
);
1222 static int tpacpi_rfk_hook_set_block(void *data
, bool blocked
)
1224 struct tpacpi_rfk
*tp_rfk
= data
;
1227 dbg_printk(TPACPI_DBG_RFKILL
,
1228 "request to change radio state to %s\n",
1229 blocked
? "blocked" : "unblocked");
1231 /* try to set radio state */
1232 res
= (tp_rfk
->ops
->set_status
)(blocked
?
1233 TPACPI_RFK_RADIO_OFF
: TPACPI_RFK_RADIO_ON
);
1235 /* and update the rfkill core with whatever the FW really did */
1236 tpacpi_rfk_update_swstate(tp_rfk
);
1238 return (res
< 0) ? res
: 0;
1241 static const struct rfkill_ops tpacpi_rfk_rfkill_ops
= {
1242 .set_block
= tpacpi_rfk_hook_set_block
,
1245 static int __init
tpacpi_new_rfkill(const enum tpacpi_rfk_id id
,
1246 const struct tpacpi_rfk_ops
*tp_rfkops
,
1247 const enum rfkill_type rfktype
,
1249 const bool set_default
)
1251 struct tpacpi_rfk
*atp_rfk
;
1253 bool sw_state
= false;
1257 BUG_ON(id
>= TPACPI_RFK_SW_MAX
|| tpacpi_rfkill_switches
[id
]);
1259 atp_rfk
= kzalloc(sizeof(struct tpacpi_rfk
), GFP_KERNEL
);
1261 atp_rfk
->rfkill
= rfkill_alloc(name
,
1264 &tpacpi_rfk_rfkill_ops
,
1266 if (!atp_rfk
|| !atp_rfk
->rfkill
) {
1268 "failed to allocate memory for rfkill class\n");
1274 atp_rfk
->ops
= tp_rfkops
;
1276 sw_status
= (tp_rfkops
->get_status
)();
1277 if (sw_status
< 0) {
1279 "failed to read initial state for %s, error %d\n",
1282 sw_state
= (sw_status
== TPACPI_RFK_RADIO_OFF
);
1284 /* try to keep the initial state, since we ask the
1285 * firmware to preserve it across S5 in NVRAM */
1286 rfkill_init_sw_state(atp_rfk
->rfkill
, sw_state
);
1289 hw_state
= tpacpi_rfk_check_hwblock_state();
1290 rfkill_set_hw_state(atp_rfk
->rfkill
, hw_state
);
1292 res
= rfkill_register(atp_rfk
->rfkill
);
1295 "failed to register %s rfkill switch: %d\n",
1297 rfkill_destroy(atp_rfk
->rfkill
);
1302 tpacpi_rfkill_switches
[id
] = atp_rfk
;
1304 printk(TPACPI_INFO
"rfkill switch %s: radio is %sblocked\n",
1305 name
, (sw_state
|| hw_state
) ? "" : "un");
1309 static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id
)
1311 struct tpacpi_rfk
*tp_rfk
;
1313 BUG_ON(id
>= TPACPI_RFK_SW_MAX
);
1315 tp_rfk
= tpacpi_rfkill_switches
[id
];
1317 rfkill_unregister(tp_rfk
->rfkill
);
1318 rfkill_destroy(tp_rfk
->rfkill
);
1319 tpacpi_rfkill_switches
[id
] = NULL
;
1324 static void printk_deprecated_rfkill_attribute(const char * const what
)
1326 printk_deprecated_attribute(what
,
1327 "Please switch to generic rfkill before year 2010");
1330 /* sysfs <radio> enable ------------------------------------------------ */
1331 static ssize_t
tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id
,
1332 struct device_attribute
*attr
,
1337 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1339 /* This is in the ABI... */
1340 if (tpacpi_rfk_check_hwblock_state()) {
1341 status
= TPACPI_RFK_RADIO_OFF
;
1343 status
= tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1348 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1349 (status
== TPACPI_RFK_RADIO_ON
) ? 1 : 0);
1352 static ssize_t
tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id
,
1353 struct device_attribute
*attr
,
1354 const char *buf
, size_t count
)
1359 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1361 if (parse_strtoul(buf
, 1, &t
))
1364 tpacpi_disclose_usertask(attr
->attr
.name
, "set to %ld\n", t
);
1366 /* This is in the ABI... */
1367 if (tpacpi_rfk_check_hwblock_state() && !!t
)
1370 res
= tpacpi_rfkill_switches
[id
]->ops
->set_status((!!t
) ?
1371 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
);
1372 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1374 return (res
< 0) ? res
: count
;
1377 /* procfs -------------------------------------------------------------- */
1378 static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id
, struct seq_file
*m
)
1380 if (id
>= TPACPI_RFK_SW_MAX
)
1381 seq_printf(m
, "status:\t\tnot supported\n");
1385 /* This is in the ABI... */
1386 if (tpacpi_rfk_check_hwblock_state()) {
1387 status
= TPACPI_RFK_RADIO_OFF
;
1389 status
= tpacpi_rfk_update_swstate(
1390 tpacpi_rfkill_switches
[id
]);
1395 seq_printf(m
, "status:\t\t%s\n",
1396 (status
== TPACPI_RFK_RADIO_ON
) ?
1397 "enabled" : "disabled");
1398 seq_printf(m
, "commands:\tenable, disable\n");
1404 static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id
, char *buf
)
1410 if (id
>= TPACPI_RFK_SW_MAX
)
1413 while ((cmd
= next_cmd(&buf
))) {
1414 if (strlencmp(cmd
, "enable") == 0)
1415 status
= TPACPI_RFK_RADIO_ON
;
1416 else if (strlencmp(cmd
, "disable") == 0)
1417 status
= TPACPI_RFK_RADIO_OFF
;
1423 tpacpi_disclose_usertask("procfs", "attempt to %s %s\n",
1424 (status
== TPACPI_RFK_RADIO_ON
) ?
1425 "enable" : "disable",
1426 tpacpi_rfkill_names
[id
]);
1427 res
= (tpacpi_rfkill_switches
[id
]->ops
->set_status
)(status
);
1428 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1434 /*************************************************************************
1435 * thinkpad-acpi driver attributes
1438 /* interface_version --------------------------------------------------- */
1439 static ssize_t
tpacpi_driver_interface_version_show(
1440 struct device_driver
*drv
,
1443 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1446 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1447 tpacpi_driver_interface_version_show
, NULL
);
1449 /* debug_level --------------------------------------------------------- */
1450 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1453 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1456 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1457 const char *buf
, size_t count
)
1461 if (parse_strtoul(buf
, 0xffff, &t
))
1469 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1470 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1472 /* version ------------------------------------------------------------- */
1473 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1476 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1477 TPACPI_DESC
, TPACPI_VERSION
);
1480 static DRIVER_ATTR(version
, S_IRUGO
,
1481 tpacpi_driver_version_show
, NULL
);
1483 /* --------------------------------------------------------------------- */
1485 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1487 /* wlsw_emulstate ------------------------------------------------------ */
1488 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1491 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1494 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1495 const char *buf
, size_t count
)
1499 if (parse_strtoul(buf
, 1, &t
))
1502 if (tpacpi_wlsw_emulstate
!= !!t
) {
1503 tpacpi_wlsw_emulstate
= !!t
;
1504 tpacpi_rfk_update_hwblock_state(!t
); /* negative logic */
1510 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1511 tpacpi_driver_wlsw_emulstate_show
,
1512 tpacpi_driver_wlsw_emulstate_store
);
1514 /* bluetooth_emulstate ------------------------------------------------- */
1515 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1516 struct device_driver
*drv
,
1519 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1522 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1523 struct device_driver
*drv
,
1524 const char *buf
, size_t count
)
1528 if (parse_strtoul(buf
, 1, &t
))
1531 tpacpi_bluetooth_emulstate
= !!t
;
1536 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1537 tpacpi_driver_bluetooth_emulstate_show
,
1538 tpacpi_driver_bluetooth_emulstate_store
);
1540 /* wwan_emulstate ------------------------------------------------- */
1541 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1542 struct device_driver
*drv
,
1545 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1548 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1549 struct device_driver
*drv
,
1550 const char *buf
, size_t count
)
1554 if (parse_strtoul(buf
, 1, &t
))
1557 tpacpi_wwan_emulstate
= !!t
;
1562 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1563 tpacpi_driver_wwan_emulstate_show
,
1564 tpacpi_driver_wwan_emulstate_store
);
1566 /* uwb_emulstate ------------------------------------------------- */
1567 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1568 struct device_driver
*drv
,
1571 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1574 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1575 struct device_driver
*drv
,
1576 const char *buf
, size_t count
)
1580 if (parse_strtoul(buf
, 1, &t
))
1583 tpacpi_uwb_emulstate
= !!t
;
1588 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1589 tpacpi_driver_uwb_emulstate_show
,
1590 tpacpi_driver_uwb_emulstate_store
);
1593 /* --------------------------------------------------------------------- */
1595 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1596 &driver_attr_debug_level
, &driver_attr_version
,
1597 &driver_attr_interface_version
,
1600 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1606 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1607 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1611 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1612 if (!res
&& dbg_wlswemul
)
1613 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1614 if (!res
&& dbg_bluetoothemul
)
1615 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1616 if (!res
&& dbg_wwanemul
)
1617 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1618 if (!res
&& dbg_uwbemul
)
1619 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1625 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1629 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1630 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1632 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1633 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1634 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1635 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1636 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1640 /*************************************************************************
1645 * Table of recommended minimum BIOS versions
1647 * Reasons for listing:
1648 * 1. Stable BIOS, listed because the unknown amount of
1649 * bugs and bad ACPI behaviour on older versions
1651 * 2. BIOS or EC fw with known bugs that trigger on Linux
1653 * 3. BIOS with known reduced functionality in older versions
1655 * We recommend the latest BIOS and EC version.
1656 * We only support the latest BIOS and EC fw version as a rule.
1658 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1659 * Information from users in ThinkWiki
1661 * WARNING: we use this table also to detect that the machine is
1662 * a ThinkPad in some cases, so don't remove entries lightly.
1665 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1666 { .vendor = (__v), \
1667 .bios = TPID(__id1, __id2), \
1668 .ec = TPACPI_MATCH_ANY, \
1669 .quirks = TPACPI_MATCH_ANY << 16 \
1670 | (__bv1) << 8 | (__bv2) }
1672 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1673 __eid, __ev1, __ev2) \
1674 { .vendor = (__v), \
1675 .bios = TPID(__bid1, __bid2), \
1677 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1678 | (__bv1) << 8 | (__bv2) }
1680 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1681 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1683 /* Outdated IBM BIOSes often lack the EC id string */
1684 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1685 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1686 __bv1, __bv2, TPID(__id1, __id2), \
1688 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1689 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1692 /* Outdated IBM BIOSes often lack the EC id string */
1693 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1694 __eid1, __eid2, __ev1, __ev2) \
1695 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1696 __bv1, __bv2, TPID(__eid1, __eid2), \
1698 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1699 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1702 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1703 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1705 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1706 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1707 __bv1, __bv2, TPID(__id1, __id2), \
1710 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1711 __eid1, __eid2, __ev1, __ev2) \
1712 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1713 __bv1, __bv2, TPID(__eid1, __eid2), \
1716 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1717 /* Numeric models ------------------ */
1718 /* FW MODEL BIOS VERS */
1719 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1720 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1721 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1722 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1723 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1724 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1725 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1726 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1727 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1729 /* A-series ------------------------- */
1730 /* FW MODEL BIOS VERS EC VERS */
1731 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1732 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1733 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1734 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1735 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1736 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1737 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1738 TPV_QI0('1', '3', '2', '0'), /* A22m */
1739 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1740 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1741 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1743 /* G-series ------------------------- */
1744 /* FW MODEL BIOS VERS */
1745 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1746 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1748 /* R-series, T-series --------------- */
1749 /* FW MODEL BIOS VERS EC VERS */
1750 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1751 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1752 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1753 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1754 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1755 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1756 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1757 T40/p, T41/p, T42/p (1) */
1758 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1759 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1760 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1761 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1763 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1764 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1765 TPV_QI0('1', '6', '3', '2'), /* T22 */
1766 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1767 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1768 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1770 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1771 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1772 TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */
1774 /* BIOS FW BIOS VERS EC FW EC VERS */
1775 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1776 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1778 /* X-series ------------------------- */
1779 /* FW MODEL BIOS VERS EC VERS */
1780 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1781 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1782 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1783 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1784 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1785 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1786 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1788 TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */
1789 TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */
1791 /* (0) - older versions lack DMI EC fw string and functionality */
1792 /* (1) - older versions known to lack functionality */
1803 static void __init
tpacpi_check_outdated_fw(void)
1805 unsigned long fwvers
;
1806 u16 ec_version
, bios_version
;
1808 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1809 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1814 bios_version
= fwvers
& 0xffffU
;
1815 ec_version
= (fwvers
>> 16) & 0xffffU
;
1817 /* note that unknown versions are set to 0x0000 and we use that */
1818 if ((bios_version
> thinkpad_id
.bios_release
) ||
1819 (ec_version
> thinkpad_id
.ec_release
&&
1820 ec_version
!= TPACPI_MATCH_ANY
)) {
1822 * The changelogs would let us track down the exact
1823 * reason, but it is just too much of a pain to track
1824 * it. We only list BIOSes that are either really
1825 * broken, or really stable to begin with, so it is
1826 * best if the user upgrades the firmware anyway.
1829 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1831 "WARNING: This firmware may be missing critical bug "
1832 "fixes and/or important features\n");
1836 static bool __init
tpacpi_is_fw_known(void)
1838 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1839 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1842 /****************************************************************************
1843 ****************************************************************************
1847 ****************************************************************************
1848 ****************************************************************************/
1850 /*************************************************************************
1851 * thinkpad-acpi metadata subdriver
1854 static int thinkpad_acpi_driver_read(struct seq_file
*m
)
1856 seq_printf(m
, "driver:\t\t%s\n", TPACPI_DESC
);
1857 seq_printf(m
, "version:\t%s\n", TPACPI_VERSION
);
1861 static struct ibm_struct thinkpad_acpi_driver_data
= {
1863 .read
= thinkpad_acpi_driver_read
,
1866 /*************************************************************************
1871 * ThinkPad firmware event model
1873 * The ThinkPad firmware has two main event interfaces: normal ACPI
1874 * notifications (which follow the ACPI standard), and a private event
1877 * The private event interface also issues events for the hotkeys. As
1878 * the driver gained features, the event handling code ended up being
1879 * built around the hotkey subdriver. This will need to be refactored
1880 * to a more formal event API eventually.
1882 * Some "hotkeys" are actually supposed to be used as event reports,
1883 * such as "brightness has changed", "volume has changed", depending on
1884 * the ThinkPad model and how the firmware is operating.
1886 * Unlike other classes, hotkey-class events have mask/unmask control on
1887 * non-ancient firmware. However, how it behaves changes a lot with the
1888 * firmware model and version.
1891 enum { /* hot key scan codes (derived from ACPI DSDT) */
1892 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1893 TP_ACPI_HOTKEYSCAN_FNF2
,
1894 TP_ACPI_HOTKEYSCAN_FNF3
,
1895 TP_ACPI_HOTKEYSCAN_FNF4
,
1896 TP_ACPI_HOTKEYSCAN_FNF5
,
1897 TP_ACPI_HOTKEYSCAN_FNF6
,
1898 TP_ACPI_HOTKEYSCAN_FNF7
,
1899 TP_ACPI_HOTKEYSCAN_FNF8
,
1900 TP_ACPI_HOTKEYSCAN_FNF9
,
1901 TP_ACPI_HOTKEYSCAN_FNF10
,
1902 TP_ACPI_HOTKEYSCAN_FNF11
,
1903 TP_ACPI_HOTKEYSCAN_FNF12
,
1904 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1905 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1906 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1907 TP_ACPI_HOTKEYSCAN_FNHOME
,
1908 TP_ACPI_HOTKEYSCAN_FNEND
,
1909 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1910 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1911 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1912 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1913 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1914 TP_ACPI_HOTKEYSCAN_MUTE
,
1915 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1916 TP_ACPI_HOTKEYSCAN_UNK1
,
1917 TP_ACPI_HOTKEYSCAN_UNK2
,
1918 TP_ACPI_HOTKEYSCAN_UNK3
,
1919 TP_ACPI_HOTKEYSCAN_UNK4
,
1920 TP_ACPI_HOTKEYSCAN_UNK5
,
1921 TP_ACPI_HOTKEYSCAN_UNK6
,
1922 TP_ACPI_HOTKEYSCAN_UNK7
,
1923 TP_ACPI_HOTKEYSCAN_UNK8
,
1925 /* Hotkey keymap size */
1926 TPACPI_HOTKEY_MAP_LEN
1929 enum { /* Keys/events available through NVRAM polling */
1930 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1931 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1934 enum { /* Positions of some of the keys in hotkey masks */
1935 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1936 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1937 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1938 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1939 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1940 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1941 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1942 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1943 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1944 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1945 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1948 enum { /* NVRAM to ACPI HKEY group map */
1949 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1950 TP_ACPI_HKEY_ZOOM_MASK
|
1951 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1952 TP_ACPI_HKEY_HIBERNATE_MASK
,
1953 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1954 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1955 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1956 TP_ACPI_HKEY_VOLDWN_MASK
|
1957 TP_ACPI_HKEY_MUTE_MASK
,
1960 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1961 struct tp_nvram_state
{
1962 u16 thinkpad_toggle
:1;
1964 u16 display_toggle
:1;
1965 u16 thinklight_toggle
:1;
1966 u16 hibernate_toggle
:1;
1967 u16 displayexp_toggle
:1;
1968 u16 display_state
:1;
1969 u16 brightness_toggle
:1;
1970 u16 volume_toggle
:1;
1973 u8 brightness_level
;
1977 /* kthread for the hotkey poller */
1978 static struct task_struct
*tpacpi_hotkey_task
;
1980 /* Acquired while the poller kthread is running, use to sync start/stop */
1981 static struct mutex hotkey_thread_mutex
;
1984 * Acquire mutex to write poller control variables as an
1987 * Increment hotkey_config_change when changing them if you
1988 * want the kthread to forget old state.
1990 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1992 static struct mutex hotkey_thread_data_mutex
;
1993 static unsigned int hotkey_config_change
;
1996 * hotkey poller control variables
1998 * Must be atomic or readers will also need to acquire mutex
2000 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2001 * should be used only when the changes need to be taken as
2002 * a block, OR when one needs to force the kthread to forget
2005 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
2006 static unsigned int hotkey_poll_freq
= 10; /* Hz */
2008 #define HOTKEY_CONFIG_CRITICAL_START \
2010 mutex_lock(&hotkey_thread_data_mutex); \
2011 hotkey_config_change++; \
2013 #define HOTKEY_CONFIG_CRITICAL_END \
2014 mutex_unlock(&hotkey_thread_data_mutex);
2016 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2018 #define hotkey_source_mask 0U
2019 #define HOTKEY_CONFIG_CRITICAL_START
2020 #define HOTKEY_CONFIG_CRITICAL_END
2022 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2024 static struct mutex hotkey_mutex
;
2026 static enum { /* Reasons for waking up */
2027 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
2028 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
2029 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
2030 } hotkey_wakeup_reason
;
2032 static int hotkey_autosleep_ack
;
2034 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
2035 static u32 hotkey_all_mask
; /* all events supported in fw */
2036 static u32 hotkey_reserved_mask
; /* events better left disabled */
2037 static u32 hotkey_driver_mask
; /* events needed by the driver */
2038 static u32 hotkey_user_mask
; /* events visible to userspace */
2039 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
2041 static unsigned int hotkey_report_mode
;
2043 static u16
*hotkey_keycode_map
;
2045 static struct attribute_set
*hotkey_dev_attributes
;
2047 static void tpacpi_driver_event(const unsigned int hkey_event
);
2048 static void hotkey_driver_event(const unsigned int scancode
);
2049 static void hotkey_poll_setup(const bool may_warn
);
2051 /* HKEY.MHKG() return bits */
2052 #define TP_HOTKEY_TABLET_MASK (1 << 3)
2054 static int hotkey_get_wlsw(void)
2058 if (!tp_features
.hotkey_wlsw
)
2061 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2063 return (tpacpi_wlsw_emulstate
) ?
2064 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2067 if (!acpi_evalf(hkey_handle
, &status
, "WLSW", "d"))
2070 return (status
) ? TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2073 static int hotkey_get_tablet_mode(int *status
)
2077 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
2080 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
2085 * Reads current event mask from firmware, and updates
2086 * hotkey_acpi_mask accordingly. Also resets any bits
2087 * from hotkey_user_mask that are unavailable to be
2088 * delivered (shadow requirement of the userspace ABI).
2090 * Call with hotkey_mutex held
2092 static int hotkey_mask_get(void)
2094 if (tp_features
.hotkey_mask
) {
2097 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
2100 hotkey_acpi_mask
= m
;
2102 /* no mask support doesn't mean no event support... */
2103 hotkey_acpi_mask
= hotkey_all_mask
;
2106 /* sync userspace-visible mask */
2107 hotkey_user_mask
&= (hotkey_acpi_mask
| hotkey_source_mask
);
2112 void static hotkey_mask_warn_incomplete_mask(void)
2114 /* log only what the user can fix... */
2115 const u32 wantedmask
= hotkey_driver_mask
&
2116 ~(hotkey_acpi_mask
| hotkey_source_mask
) &
2117 (hotkey_all_mask
| TPACPI_HKEY_NVRAM_KNOWN_MASK
);
2120 printk(TPACPI_NOTICE
2121 "required events 0x%08x not enabled!\n",
2126 * Set the firmware mask when supported
2128 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
2130 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
2132 * Call with hotkey_mutex held
2134 static int hotkey_mask_set(u32 mask
)
2139 const u32 fwmask
= mask
& ~hotkey_source_mask
;
2141 if (tp_features
.hotkey_mask
) {
2142 for (i
= 0; i
< 32; i
++) {
2143 if (!acpi_evalf(hkey_handle
,
2144 NULL
, "MHKM", "vdd", i
+ 1,
2145 !!(mask
& (1 << i
)))) {
2153 * We *must* make an inconditional call to hotkey_mask_get to
2154 * refresh hotkey_acpi_mask and update hotkey_user_mask
2156 * Take the opportunity to also log when we cannot _enable_
2159 if (!hotkey_mask_get() && !rc
&& (fwmask
& ~hotkey_acpi_mask
)) {
2160 printk(TPACPI_NOTICE
2161 "asked for hotkey mask 0x%08x, but "
2162 "firmware forced it to 0x%08x\n",
2163 fwmask
, hotkey_acpi_mask
);
2166 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
)
2167 hotkey_mask_warn_incomplete_mask();
2173 * Sets hotkey_user_mask and tries to set the firmware mask
2175 * Call with hotkey_mutex held
2177 static int hotkey_user_mask_set(const u32 mask
)
2181 /* Give people a chance to notice they are doing something that
2182 * is bound to go boom on their users sooner or later */
2183 if (!tp_warned
.hotkey_mask_ff
&&
2184 (mask
== 0xffff || mask
== 0xffffff ||
2185 mask
== 0xffffffff)) {
2186 tp_warned
.hotkey_mask_ff
= 1;
2187 printk(TPACPI_NOTICE
2188 "setting the hotkey mask to 0x%08x is likely "
2189 "not the best way to go about it\n", mask
);
2190 printk(TPACPI_NOTICE
2191 "please consider using the driver defaults, "
2192 "and refer to up-to-date thinkpad-acpi "
2196 /* Try to enable what the user asked for, plus whatever we need.
2197 * this syncs everything but won't enable bits in hotkey_user_mask */
2198 rc
= hotkey_mask_set((mask
| hotkey_driver_mask
) & ~hotkey_source_mask
);
2200 /* Enable the available bits in hotkey_user_mask */
2201 hotkey_user_mask
= mask
& (hotkey_acpi_mask
| hotkey_source_mask
);
2207 * Sets the driver hotkey mask.
2209 * Can be called even if the hotkey subdriver is inactive
2211 static int tpacpi_hotkey_driver_mask_set(const u32 mask
)
2215 /* Do the right thing if hotkey_init has not been called yet */
2216 if (!tp_features
.hotkey
) {
2217 hotkey_driver_mask
= mask
;
2221 mutex_lock(&hotkey_mutex
);
2223 HOTKEY_CONFIG_CRITICAL_START
2224 hotkey_driver_mask
= mask
;
2225 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2226 hotkey_source_mask
|= (mask
& ~hotkey_all_mask
);
2228 HOTKEY_CONFIG_CRITICAL_END
2230 rc
= hotkey_mask_set((hotkey_acpi_mask
| hotkey_driver_mask
) &
2231 ~hotkey_source_mask
);
2232 hotkey_poll_setup(true);
2234 mutex_unlock(&hotkey_mutex
);
2239 static int hotkey_status_get(int *status
)
2241 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
2247 static int hotkey_status_set(bool enable
)
2249 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
2255 static void tpacpi_input_send_tabletsw(void)
2259 if (tp_features
.hotkey_tablet
&&
2260 !hotkey_get_tablet_mode(&state
)) {
2261 mutex_lock(&tpacpi_inputdev_send_mutex
);
2263 input_report_switch(tpacpi_inputdev
,
2264 SW_TABLET_MODE
, !!state
);
2265 input_sync(tpacpi_inputdev
);
2267 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2271 /* Do NOT call without validating scancode first */
2272 static void tpacpi_input_send_key(const unsigned int scancode
)
2274 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
2276 if (keycode
!= KEY_RESERVED
) {
2277 mutex_lock(&tpacpi_inputdev_send_mutex
);
2279 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
, scancode
);
2280 input_report_key(tpacpi_inputdev
, keycode
, 1);
2281 input_sync(tpacpi_inputdev
);
2283 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
, scancode
);
2284 input_report_key(tpacpi_inputdev
, keycode
, 0);
2285 input_sync(tpacpi_inputdev
);
2287 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2291 /* Do NOT call without validating scancode first */
2292 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
2294 hotkey_driver_event(scancode
);
2295 if (hotkey_user_mask
& (1 << scancode
))
2296 tpacpi_input_send_key(scancode
);
2299 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2300 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2302 /* Do NOT call without validating scancode first */
2303 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2305 tpacpi_input_send_key_masked(scancode
);
2306 if (hotkey_report_mode
< 2) {
2307 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2308 0x80, TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
2312 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2316 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2317 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2318 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2319 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2320 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2321 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2323 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2324 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2325 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2327 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2328 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2329 n
->displayexp_toggle
=
2330 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2332 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2333 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2334 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2335 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2336 n
->brightness_toggle
=
2337 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2339 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2340 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2341 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2342 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2343 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2344 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2348 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2349 struct tp_nvram_state
*newn
,
2350 const u32 event_mask
)
2353 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2355 if ((event_mask & (1 << __scancode)) && \
2356 oldn->__member != newn->__member) \
2357 tpacpi_hotkey_send_key(__scancode); \
2360 #define TPACPI_MAY_SEND_KEY(__scancode) \
2362 if (event_mask & (1 << __scancode)) \
2363 tpacpi_hotkey_send_key(__scancode); \
2366 void issue_volchange(const unsigned int oldvol
,
2367 const unsigned int newvol
)
2369 unsigned int i
= oldvol
;
2371 while (i
> newvol
) {
2372 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2375 while (i
< newvol
) {
2376 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2381 void issue_brightnesschange(const unsigned int oldbrt
,
2382 const unsigned int newbrt
)
2384 unsigned int i
= oldbrt
;
2386 while (i
> newbrt
) {
2387 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2390 while (i
< newbrt
) {
2391 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2396 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2397 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2398 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2399 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2401 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2403 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2408 * This code is supposed to duplicate the IBM firmware behaviour:
2409 * - Pressing MUTE issues mute hotkey message, even when already mute
2410 * - Pressing Volume up/down issues volume up/down hotkey messages,
2411 * even when already at maximum or minimum volume
2412 * - The act of unmuting issues volume up/down notification,
2413 * depending which key was used to unmute
2415 * We are constrained to what the NVRAM can tell us, which is not much
2416 * and certainly not enough if more than one volume hotkey was pressed
2417 * since the last poll cycle.
2419 * Just to make our life interesting, some newer Lenovo ThinkPads have
2420 * bugs in the BIOS and may fail to update volume_toggle properly.
2425 oldn
->volume_toggle
!= newn
->volume_toggle
||
2426 oldn
->volume_level
!= newn
->volume_level
) {
2427 /* recently muted, or repeated mute keypress, or
2428 * multiple presses ending in mute */
2429 issue_volchange(oldn
->volume_level
, newn
->volume_level
);
2430 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2435 /* recently unmuted, issue 'unmute' keypress */
2436 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2438 if (oldn
->volume_level
!= newn
->volume_level
) {
2439 issue_volchange(oldn
->volume_level
, newn
->volume_level
);
2440 } else if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2441 /* repeated vol up/down keypress at end of scale ? */
2442 if (newn
->volume_level
== 0)
2443 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2444 else if (newn
->volume_level
>= TP_NVRAM_LEVEL_VOLUME_MAX
)
2445 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2449 /* handle brightness */
2450 if (oldn
->brightness_level
!= newn
->brightness_level
) {
2451 issue_brightnesschange(oldn
->brightness_level
,
2452 newn
->brightness_level
);
2453 } else if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2454 /* repeated key presses that didn't change state */
2455 if (newn
->brightness_level
== 0)
2456 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2457 else if (newn
->brightness_level
>= bright_maxlvl
2458 && !tp_features
.bright_unkfw
)
2459 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2462 #undef TPACPI_COMPARE_KEY
2463 #undef TPACPI_MAY_SEND_KEY
2469 * We track all events in hotkey_source_mask all the time, since
2470 * most of them are edge-based. We only issue those requested by
2471 * hotkey_user_mask or hotkey_driver_mask, though.
2473 static int hotkey_kthread(void *data
)
2475 struct tp_nvram_state s
[2];
2476 u32 poll_mask
, event_mask
;
2477 unsigned int si
, so
;
2479 unsigned int change_detector
, must_reset
;
2480 unsigned int poll_freq
;
2482 mutex_lock(&hotkey_thread_mutex
);
2484 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2493 /* Initial state for compares */
2494 mutex_lock(&hotkey_thread_data_mutex
);
2495 change_detector
= hotkey_config_change
;
2496 poll_mask
= hotkey_source_mask
;
2497 event_mask
= hotkey_source_mask
&
2498 (hotkey_driver_mask
| hotkey_user_mask
);
2499 poll_freq
= hotkey_poll_freq
;
2500 mutex_unlock(&hotkey_thread_data_mutex
);
2501 hotkey_read_nvram(&s
[so
], poll_mask
);
2503 while (!kthread_should_stop()) {
2505 if (likely(poll_freq
))
2508 t
= 100; /* should never happen... */
2510 t
= msleep_interruptible(t
);
2511 if (unlikely(kthread_should_stop()))
2513 must_reset
= try_to_freeze();
2514 if (t
> 0 && !must_reset
)
2517 mutex_lock(&hotkey_thread_data_mutex
);
2518 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2519 /* forget old state on thaw or config change */
2522 change_detector
= hotkey_config_change
;
2524 poll_mask
= hotkey_source_mask
;
2525 event_mask
= hotkey_source_mask
&
2526 (hotkey_driver_mask
| hotkey_user_mask
);
2527 poll_freq
= hotkey_poll_freq
;
2528 mutex_unlock(&hotkey_thread_data_mutex
);
2530 if (likely(poll_mask
)) {
2531 hotkey_read_nvram(&s
[si
], poll_mask
);
2532 if (likely(si
!= so
)) {
2533 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2543 mutex_unlock(&hotkey_thread_mutex
);
2547 /* call with hotkey_mutex held */
2548 static void hotkey_poll_stop_sync(void)
2550 if (tpacpi_hotkey_task
) {
2551 if (frozen(tpacpi_hotkey_task
) ||
2552 freezing(tpacpi_hotkey_task
))
2553 thaw_process(tpacpi_hotkey_task
);
2555 kthread_stop(tpacpi_hotkey_task
);
2556 tpacpi_hotkey_task
= NULL
;
2557 mutex_lock(&hotkey_thread_mutex
);
2558 /* at this point, the thread did exit */
2559 mutex_unlock(&hotkey_thread_mutex
);
2563 /* call with hotkey_mutex held */
2564 static void hotkey_poll_setup(const bool may_warn
)
2566 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2567 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2569 if (hotkey_poll_freq
> 0 &&
2570 (poll_driver_mask
||
2571 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2572 if (!tpacpi_hotkey_task
) {
2573 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2574 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2575 if (IS_ERR(tpacpi_hotkey_task
)) {
2576 tpacpi_hotkey_task
= NULL
;
2578 "could not create kernel thread "
2579 "for hotkey polling\n");
2583 hotkey_poll_stop_sync();
2584 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2585 hotkey_poll_freq
== 0) {
2586 printk(TPACPI_NOTICE
2587 "hot keys 0x%08x and/or events 0x%08x "
2588 "require polling, which is currently "
2590 poll_user_mask
, poll_driver_mask
);
2595 static void hotkey_poll_setup_safe(const bool may_warn
)
2597 mutex_lock(&hotkey_mutex
);
2598 hotkey_poll_setup(may_warn
);
2599 mutex_unlock(&hotkey_mutex
);
2602 /* call with hotkey_mutex held */
2603 static void hotkey_poll_set_freq(unsigned int freq
)
2606 hotkey_poll_stop_sync();
2608 hotkey_poll_freq
= freq
;
2611 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2613 static void hotkey_poll_setup(const bool __unused
)
2617 static void hotkey_poll_setup_safe(const bool __unused
)
2621 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2623 static int hotkey_inputdev_open(struct input_dev
*dev
)
2625 switch (tpacpi_lifecycle
) {
2626 case TPACPI_LIFE_INIT
:
2627 case TPACPI_LIFE_RUNNING
:
2628 hotkey_poll_setup_safe(false);
2630 case TPACPI_LIFE_EXITING
:
2634 /* Should only happen if tpacpi_lifecycle is corrupt */
2639 static void hotkey_inputdev_close(struct input_dev
*dev
)
2641 /* disable hotkey polling when possible */
2642 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
&&
2643 !(hotkey_source_mask
& hotkey_driver_mask
))
2644 hotkey_poll_setup_safe(false);
2647 /* sysfs hotkey enable ------------------------------------------------- */
2648 static ssize_t
hotkey_enable_show(struct device
*dev
,
2649 struct device_attribute
*attr
,
2654 printk_deprecated_attribute("hotkey_enable",
2655 "Hotkey reporting is always enabled");
2657 res
= hotkey_status_get(&status
);
2661 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2664 static ssize_t
hotkey_enable_store(struct device
*dev
,
2665 struct device_attribute
*attr
,
2666 const char *buf
, size_t count
)
2670 printk_deprecated_attribute("hotkey_enable",
2671 "Hotkeys can be disabled through hotkey_mask");
2673 if (parse_strtoul(buf
, 1, &t
))
2682 static struct device_attribute dev_attr_hotkey_enable
=
2683 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2684 hotkey_enable_show
, hotkey_enable_store
);
2686 /* sysfs hotkey mask --------------------------------------------------- */
2687 static ssize_t
hotkey_mask_show(struct device
*dev
,
2688 struct device_attribute
*attr
,
2691 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2694 static ssize_t
hotkey_mask_store(struct device
*dev
,
2695 struct device_attribute
*attr
,
2696 const char *buf
, size_t count
)
2701 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2704 if (mutex_lock_killable(&hotkey_mutex
))
2705 return -ERESTARTSYS
;
2707 res
= hotkey_user_mask_set(t
);
2709 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2710 hotkey_poll_setup(true);
2713 mutex_unlock(&hotkey_mutex
);
2715 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2717 return (res
) ? res
: count
;
2720 static struct device_attribute dev_attr_hotkey_mask
=
2721 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2722 hotkey_mask_show
, hotkey_mask_store
);
2724 /* sysfs hotkey bios_enabled ------------------------------------------- */
2725 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2726 struct device_attribute
*attr
,
2729 return sprintf(buf
, "0\n");
2732 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2733 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2735 /* sysfs hotkey bios_mask ---------------------------------------------- */
2736 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2737 struct device_attribute
*attr
,
2740 printk_deprecated_attribute("hotkey_bios_mask",
2741 "This attribute is useless.");
2742 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2745 static struct device_attribute dev_attr_hotkey_bios_mask
=
2746 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2748 /* sysfs hotkey all_mask ----------------------------------------------- */
2749 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2750 struct device_attribute
*attr
,
2753 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2754 hotkey_all_mask
| hotkey_source_mask
);
2757 static struct device_attribute dev_attr_hotkey_all_mask
=
2758 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2760 /* sysfs hotkey recommended_mask --------------------------------------- */
2761 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2762 struct device_attribute
*attr
,
2765 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2766 (hotkey_all_mask
| hotkey_source_mask
)
2767 & ~hotkey_reserved_mask
);
2770 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2771 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2772 hotkey_recommended_mask_show
, NULL
);
2774 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2776 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2777 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2778 struct device_attribute
*attr
,
2781 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2784 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2785 struct device_attribute
*attr
,
2786 const char *buf
, size_t count
)
2792 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2793 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2796 if (mutex_lock_killable(&hotkey_mutex
))
2797 return -ERESTARTSYS
;
2799 HOTKEY_CONFIG_CRITICAL_START
2800 hotkey_source_mask
= t
;
2801 HOTKEY_CONFIG_CRITICAL_END
2803 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2804 ~hotkey_source_mask
);
2805 hotkey_poll_setup(true);
2807 /* check if events needed by the driver got disabled */
2808 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2809 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2811 mutex_unlock(&hotkey_mutex
);
2814 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2815 "firmware event mask!\n");
2818 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2819 "some important events were disabled: "
2822 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2824 return (rc
< 0) ? rc
: count
;
2827 static struct device_attribute dev_attr_hotkey_source_mask
=
2828 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2829 hotkey_source_mask_show
, hotkey_source_mask_store
);
2831 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2832 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2833 struct device_attribute
*attr
,
2836 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2839 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2840 struct device_attribute
*attr
,
2841 const char *buf
, size_t count
)
2845 if (parse_strtoul(buf
, 25, &t
))
2848 if (mutex_lock_killable(&hotkey_mutex
))
2849 return -ERESTARTSYS
;
2851 hotkey_poll_set_freq(t
);
2852 hotkey_poll_setup(true);
2854 mutex_unlock(&hotkey_mutex
);
2856 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2861 static struct device_attribute dev_attr_hotkey_poll_freq
=
2862 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2863 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2865 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2867 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2868 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2869 struct device_attribute
*attr
,
2873 res
= hotkey_get_wlsw();
2877 /* Opportunistic update */
2878 tpacpi_rfk_update_hwblock_state((res
== TPACPI_RFK_RADIO_OFF
));
2880 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2881 (res
== TPACPI_RFK_RADIO_OFF
) ? 0 : 1);
2884 static struct device_attribute dev_attr_hotkey_radio_sw
=
2885 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2887 static void hotkey_radio_sw_notify_change(void)
2889 if (tp_features
.hotkey_wlsw
)
2890 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2894 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2895 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2896 struct device_attribute
*attr
,
2900 res
= hotkey_get_tablet_mode(&s
);
2904 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2907 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2908 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2910 static void hotkey_tablet_mode_notify_change(void)
2912 if (tp_features
.hotkey_tablet
)
2913 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2914 "hotkey_tablet_mode");
2917 /* sysfs hotkey report_mode -------------------------------------------- */
2918 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2919 struct device_attribute
*attr
,
2922 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2923 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2926 static struct device_attribute dev_attr_hotkey_report_mode
=
2927 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2929 /* sysfs wakeup reason (pollable) -------------------------------------- */
2930 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2931 struct device_attribute
*attr
,
2934 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2937 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2938 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2940 static void hotkey_wakeup_reason_notify_change(void)
2942 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2946 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2947 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2948 struct device_attribute
*attr
,
2951 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2954 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2955 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2956 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2958 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2960 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2961 "wakeup_hotunplug_complete");
2964 /* --------------------------------------------------------------------- */
2966 static struct attribute
*hotkey_attributes
[] __initdata
= {
2967 &dev_attr_hotkey_enable
.attr
,
2968 &dev_attr_hotkey_bios_enabled
.attr
,
2969 &dev_attr_hotkey_bios_mask
.attr
,
2970 &dev_attr_hotkey_report_mode
.attr
,
2971 &dev_attr_hotkey_wakeup_reason
.attr
,
2972 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2973 &dev_attr_hotkey_mask
.attr
,
2974 &dev_attr_hotkey_all_mask
.attr
,
2975 &dev_attr_hotkey_recommended_mask
.attr
,
2976 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2977 &dev_attr_hotkey_source_mask
.attr
,
2978 &dev_attr_hotkey_poll_freq
.attr
,
2983 * Sync both the hw and sw blocking state of all switches
2985 static void tpacpi_send_radiosw_update(void)
2990 * We must sync all rfkill controllers *before* issuing any
2991 * rfkill input events, or we will race the rfkill core input
2994 * tpacpi_inputdev_send_mutex works as a synchronization point
2997 * We optimize to avoid numerous calls to hotkey_get_wlsw.
3000 wlsw
= hotkey_get_wlsw();
3002 /* Sync hw blocking state first if it is hw-blocked */
3003 if (wlsw
== TPACPI_RFK_RADIO_OFF
)
3004 tpacpi_rfk_update_hwblock_state(true);
3006 /* Sync sw blocking state */
3007 tpacpi_rfk_update_swstate_all();
3009 /* Sync hw blocking state last if it is hw-unblocked */
3010 if (wlsw
== TPACPI_RFK_RADIO_ON
)
3011 tpacpi_rfk_update_hwblock_state(false);
3013 /* Issue rfkill input event for WLSW switch */
3015 mutex_lock(&tpacpi_inputdev_send_mutex
);
3017 input_report_switch(tpacpi_inputdev
,
3018 SW_RFKILL_ALL
, (wlsw
> 0));
3019 input_sync(tpacpi_inputdev
);
3021 mutex_unlock(&tpacpi_inputdev_send_mutex
);
3025 * this can be unconditional, as we will poll state again
3026 * if userspace uses the notify to read data
3028 hotkey_radio_sw_notify_change();
3031 static void hotkey_exit(void)
3033 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3034 mutex_lock(&hotkey_mutex
);
3035 hotkey_poll_stop_sync();
3036 mutex_unlock(&hotkey_mutex
);
3039 if (hotkey_dev_attributes
)
3040 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3042 kfree(hotkey_keycode_map
);
3044 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
3045 "restoring original HKEY status and mask\n");
3046 /* yes, there is a bitwise or below, we want the
3047 * functions to be called even if one of them fail */
3048 if (((tp_features
.hotkey_mask
&&
3049 hotkey_mask_set(hotkey_orig_mask
)) |
3050 hotkey_status_set(false)) != 0)
3052 "failed to restore hot key mask "
3053 "to BIOS defaults\n");
3056 static void __init
hotkey_unmap(const unsigned int scancode
)
3058 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
3059 clear_bit(hotkey_keycode_map
[scancode
],
3060 tpacpi_inputdev
->keybit
);
3061 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
3067 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
3070 #define TPACPI_HK_Q_INIMASK 0x0001
3072 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
3073 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
3074 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
3075 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
3076 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
3077 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
3078 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
3079 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
3080 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
3081 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
3082 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
3083 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
3084 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
3085 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
3086 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
3087 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
3088 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
3089 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
3090 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
3091 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
3094 typedef u16 tpacpi_keymap_entry_t
;
3095 typedef tpacpi_keymap_entry_t tpacpi_keymap_t
[TPACPI_HOTKEY_MAP_LEN
];
3097 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
3099 /* Requirements for changing the default keymaps:
3101 * 1. Many of the keys are mapped to KEY_RESERVED for very
3102 * good reasons. Do not change them unless you have deep
3103 * knowledge on the IBM and Lenovo ThinkPad firmware for
3104 * the various ThinkPad models. The driver behaves
3105 * differently for KEY_RESERVED: such keys have their
3106 * hot key mask *unset* in mask_recommended, and also
3107 * in the initial hot key mask programmed into the
3108 * firmware at driver load time, which means the firm-
3109 * ware may react very differently if you change them to
3112 * 2. You must be subscribed to the linux-thinkpad and
3113 * ibm-acpi-devel mailing lists, and you should read the
3114 * list archives since 2007 if you want to change the
3115 * keymaps. This requirement exists so that you will
3116 * know the past history of problems with the thinkpad-
3117 * acpi driver keymaps, and also that you will be
3118 * listening to any bug reports;
3120 * 3. Do not send thinkpad-acpi specific patches directly to
3121 * for merging, *ever*. Send them to the linux-acpi
3122 * mailinglist for comments. Merging is to be done only
3123 * through acpi-test and the ACPI maintainer.
3125 * If the above is too much to ask, don't change the keymap.
3126 * Ask the thinkpad-acpi maintainer to do it, instead.
3130 TPACPI_KEYMAP_IBM_GENERIC
= 0,
3131 TPACPI_KEYMAP_LENOVO_GENERIC
,
3134 static const tpacpi_keymap_t tpacpi_keymaps
[] __initconst
= {
3135 /* Generic keymap for IBM ThinkPads */
3136 [TPACPI_KEYMAP_IBM_GENERIC
] = {
3137 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3138 KEY_FN_F1
, KEY_BATTERY
, KEY_COFFEE
, KEY_SLEEP
,
3139 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3140 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3142 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3143 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3144 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3145 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3147 /* brightness: firmware always reacts to them */
3148 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
3149 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
3151 /* Thinklight: firmware always react to it */
3152 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3154 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3155 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3157 /* Volume: firmware always react to it and reprograms
3158 * the built-in *extra* mixer. Never map it to control
3159 * another mixer by default. */
3160 KEY_RESERVED
, /* 0x14: VOLUME UP */
3161 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3162 KEY_RESERVED
, /* 0x16: MUTE */
3164 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3166 /* (assignments unknown, please report if found) */
3167 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3168 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3171 /* Generic keymap for Lenovo ThinkPads */
3172 [TPACPI_KEYMAP_LENOVO_GENERIC
] = {
3173 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3174 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
3175 KEY_WLAN
, KEY_CAMERA
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3176 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3178 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3179 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3180 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3181 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3183 /* These should be enabled --only-- when ACPI video
3184 * is disabled (i.e. in "vendor" mode), and are handled
3185 * in a special way by the init code */
3186 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
3187 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
3189 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3191 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3192 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3194 /* Volume: z60/z61, T60 (BIOS version?): firmware always
3195 * react to it and reprograms the built-in *extra* mixer.
3196 * Never map it to control another mixer by default.
3198 * T60?, T61, R60?, R61: firmware and EC tries to send
3199 * these over the regular keyboard, so these are no-ops,
3200 * but there are still weird bugs re. MUTE, so do not
3201 * change unless you get test reports from all Lenovo
3202 * models. May cause the BIOS to interfere with the
3205 KEY_RESERVED
, /* 0x14: VOLUME UP */
3206 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3207 KEY_RESERVED
, /* 0x16: MUTE */
3209 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3211 /* (assignments unknown, please report if found) */
3212 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3213 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3217 static const struct tpacpi_quirk tpacpi_keymap_qtable
[] __initconst
= {
3218 /* Generic maps (fallback) */
3220 .vendor
= PCI_VENDOR_ID_IBM
,
3221 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
3222 .quirks
= TPACPI_KEYMAP_IBM_GENERIC
,
3225 .vendor
= PCI_VENDOR_ID_LENOVO
,
3226 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
3227 .quirks
= TPACPI_KEYMAP_LENOVO_GENERIC
,
3231 #define TPACPI_HOTKEY_MAP_SIZE sizeof(tpacpi_keymap_t)
3232 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(tpacpi_keymap_entry_t)
3237 bool radiosw_state
= false;
3238 bool tabletsw_state
= false;
3240 unsigned long quirks
;
3241 unsigned long keymap_id
;
3243 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3244 "initializing hotkey subdriver\n");
3246 BUG_ON(!tpacpi_inputdev
);
3247 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
3248 tpacpi_inputdev
->close
!= NULL
);
3250 TPACPI_ACPIHANDLE_INIT(hkey
);
3251 mutex_init(&hotkey_mutex
);
3253 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3254 mutex_init(&hotkey_thread_mutex
);
3255 mutex_init(&hotkey_thread_data_mutex
);
3258 /* hotkey not supported on 570 */
3259 tp_features
.hotkey
= hkey_handle
!= NULL
;
3261 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3263 str_supported(tp_features
.hotkey
));
3265 if (!tp_features
.hotkey
)
3268 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
3269 ARRAY_SIZE(tpacpi_hotkey_qtable
));
3271 tpacpi_disable_brightness_delay();
3273 /* MUST have enough space for all attributes to be added to
3274 * hotkey_dev_attributes */
3275 hotkey_dev_attributes
= create_attr_set(
3276 ARRAY_SIZE(hotkey_attributes
) + 2,
3278 if (!hotkey_dev_attributes
)
3280 res
= add_many_to_attr_set(hotkey_dev_attributes
,
3282 ARRAY_SIZE(hotkey_attributes
));
3286 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
3287 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
3288 for HKEY interface version 0x100 */
3289 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
3290 if ((hkeyv
>> 8) != 1) {
3291 printk(TPACPI_ERR
"unknown version of the "
3292 "HKEY interface: 0x%x\n", hkeyv
);
3293 printk(TPACPI_ERR
"please report this to %s\n",
3297 * MHKV 0x100 in A31, R40, R40e,
3298 * T4x, X31, and later
3300 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3301 "firmware HKEY interface version: 0x%x\n",
3304 /* Paranoia check AND init hotkey_all_mask */
3305 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
3308 "missing MHKA handler, "
3309 "please report this to %s\n",
3311 /* Fallback: pre-init for FN+F3,F4,F12 */
3312 hotkey_all_mask
= 0x080cU
;
3314 tp_features
.hotkey_mask
= 1;
3319 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3320 "hotkey masks are %s\n",
3321 str_supported(tp_features
.hotkey_mask
));
3323 /* Init hotkey_all_mask if not initialized yet */
3324 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
3325 (quirks
& TPACPI_HK_Q_INIMASK
))
3326 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
3328 /* Init hotkey_acpi_mask and hotkey_orig_mask */
3329 if (tp_features
.hotkey_mask
) {
3330 /* hotkey_source_mask *must* be zero for
3331 * the first hotkey_mask_get to return hotkey_orig_mask */
3332 res
= hotkey_mask_get();
3336 hotkey_orig_mask
= hotkey_acpi_mask
;
3338 hotkey_orig_mask
= hotkey_all_mask
;
3339 hotkey_acpi_mask
= hotkey_all_mask
;
3342 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3344 tp_features
.hotkey_wlsw
= 1;
3345 radiosw_state
= !!tpacpi_wlsw_emulstate
;
3347 "radio switch emulation enabled\n");
3350 /* Not all thinkpads have a hardware radio switch */
3351 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3352 tp_features
.hotkey_wlsw
= 1;
3353 radiosw_state
= !!status
;
3355 "radio switch found; radios are %s\n",
3356 enabled(status
, 0));
3358 if (tp_features
.hotkey_wlsw
)
3359 res
= add_to_attr_set(hotkey_dev_attributes
,
3360 &dev_attr_hotkey_radio_sw
.attr
);
3362 /* For X41t, X60t, X61t Tablets... */
3363 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3364 tp_features
.hotkey_tablet
= 1;
3365 tabletsw_state
= !!(status
& TP_HOTKEY_TABLET_MASK
);
3367 "possible tablet mode switch found; "
3368 "ThinkPad in %s mode\n",
3369 (tabletsw_state
) ? "tablet" : "laptop");
3370 res
= add_to_attr_set(hotkey_dev_attributes
,
3371 &dev_attr_hotkey_tablet_mode
.attr
);
3375 res
= register_attr_set_with_sysfs(
3376 hotkey_dev_attributes
,
3377 &tpacpi_pdev
->dev
.kobj
);
3381 /* Set up key map */
3382 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3384 if (!hotkey_keycode_map
) {
3386 "failed to allocate memory for key map\n");
3391 keymap_id
= tpacpi_check_quirks(tpacpi_keymap_qtable
,
3392 ARRAY_SIZE(tpacpi_keymap_qtable
));
3393 BUG_ON(keymap_id
>= ARRAY_SIZE(tpacpi_keymaps
));
3394 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3395 "using keymap number %lu\n", keymap_id
);
3397 memcpy(hotkey_keycode_map
, &tpacpi_keymaps
[keymap_id
],
3398 TPACPI_HOTKEY_MAP_SIZE
);
3400 input_set_capability(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
);
3401 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3402 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3403 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3404 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3405 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3406 input_set_capability(tpacpi_inputdev
, EV_KEY
,
3407 hotkey_keycode_map
[i
]);
3409 if (i
< sizeof(hotkey_reserved_mask
)*8)
3410 hotkey_reserved_mask
|= 1 << i
;
3414 if (tp_features
.hotkey_wlsw
) {
3415 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_RFKILL_ALL
);
3416 input_report_switch(tpacpi_inputdev
,
3417 SW_RFKILL_ALL
, radiosw_state
);
3419 if (tp_features
.hotkey_tablet
) {
3420 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_TABLET_MODE
);
3421 input_report_switch(tpacpi_inputdev
,
3422 SW_TABLET_MODE
, tabletsw_state
);
3425 /* Do not issue duplicate brightness change events to
3426 * userspace. tpacpi_detect_brightness_capabilities() must have
3427 * been called before this point */
3428 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
3430 "This ThinkPad has standard ACPI backlight "
3431 "brightness control, supported by the ACPI "
3433 printk(TPACPI_NOTICE
3434 "Disabling thinkpad-acpi brightness events "
3437 /* Disable brightness up/down on Lenovo thinkpads when
3438 * ACPI is handling them, otherwise it is plain impossible
3439 * for userspace to do something even remotely sane */
3440 hotkey_reserved_mask
|=
3441 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3442 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3443 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3444 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3447 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3448 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3450 & ~hotkey_reserved_mask
;
3452 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3453 "hotkey source mask 0x%08x, polling freq %u\n",
3454 hotkey_source_mask
, hotkey_poll_freq
);
3457 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3458 "enabling firmware HKEY event interface...\n");
3459 res
= hotkey_status_set(true);
3464 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3465 | hotkey_driver_mask
)
3466 & ~hotkey_source_mask
);
3467 if (res
< 0 && res
!= -ENXIO
) {
3471 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3472 & ~hotkey_reserved_mask
;
3473 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3474 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3475 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3477 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3478 "legacy ibm/hotkey event reporting over procfs %s\n",
3479 (hotkey_report_mode
< 2) ?
3480 "enabled" : "disabled");
3482 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3483 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3485 hotkey_poll_setup_safe(true);
3490 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3491 hotkey_dev_attributes
= NULL
;
3493 return (res
< 0)? res
: 1;
3496 static bool hotkey_notify_hotkey(const u32 hkey
,
3498 bool *ignore_acpi_ev
)
3500 /* 0x1000-0x1FFF: key presses */
3501 unsigned int scancode
= hkey
& 0xfff;
3502 *send_acpi_ev
= true;
3503 *ignore_acpi_ev
= false;
3505 /* HKEY event 0x1001 is scancode 0x00 */
3506 if (scancode
> 0 && scancode
<= TPACPI_HOTKEY_MAP_LEN
) {
3508 if (!(hotkey_source_mask
& (1 << scancode
))) {
3509 tpacpi_input_send_key_masked(scancode
);
3510 *send_acpi_ev
= false;
3512 *ignore_acpi_ev
= true;
3519 static bool hotkey_notify_wakeup(const u32 hkey
,
3521 bool *ignore_acpi_ev
)
3523 /* 0x2000-0x2FFF: Wakeup reason */
3524 *send_acpi_ev
= true;
3525 *ignore_acpi_ev
= false;
3528 case TP_HKEY_EV_WKUP_S3_UNDOCK
: /* suspend, undock */
3529 case TP_HKEY_EV_WKUP_S4_UNDOCK
: /* hibernation, undock */
3530 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3531 *ignore_acpi_ev
= true;
3534 case TP_HKEY_EV_WKUP_S3_BAYEJ
: /* suspend, bay eject */
3535 case TP_HKEY_EV_WKUP_S4_BAYEJ
: /* hibernation, bay eject */
3536 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3537 *ignore_acpi_ev
= true;
3540 case TP_HKEY_EV_WKUP_S3_BATLOW
: /* Battery on critical low level/S3 */
3541 case TP_HKEY_EV_WKUP_S4_BATLOW
: /* Battery on critical low level/S4 */
3543 "EMERGENCY WAKEUP: battery almost empty\n");
3544 /* how to auto-heal: */
3545 /* 2313: woke up from S3, go to S4/S5 */
3546 /* 2413: woke up from S4, go to S5 */
3553 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3555 "woke up due to a hot-unplug "
3557 hotkey_wakeup_reason_notify_change();
3562 static bool hotkey_notify_usrevent(const u32 hkey
,
3564 bool *ignore_acpi_ev
)
3566 /* 0x5000-0x5FFF: human interface helpers */
3567 *send_acpi_ev
= true;
3568 *ignore_acpi_ev
= false;
3571 case TP_HKEY_EV_PEN_INSERTED
: /* X61t: tablet pen inserted into bay */
3572 case TP_HKEY_EV_PEN_REMOVED
: /* X61t: tablet pen removed from bay */
3575 case TP_HKEY_EV_TABLET_TABLET
: /* X41t-X61t: tablet mode */
3576 case TP_HKEY_EV_TABLET_NOTEBOOK
: /* X41t-X61t: normal mode */
3577 tpacpi_input_send_tabletsw();
3578 hotkey_tablet_mode_notify_change();
3579 *send_acpi_ev
= false;
3582 case TP_HKEY_EV_LID_CLOSE
: /* Lid closed */
3583 case TP_HKEY_EV_LID_OPEN
: /* Lid opened */
3584 case TP_HKEY_EV_BRGHT_CHANGED
: /* brightness changed */
3585 /* do not propagate these events */
3586 *ignore_acpi_ev
= true;
3594 static void thermal_dump_all_sensors(void);
3596 static bool hotkey_notify_thermal(const u32 hkey
,
3598 bool *ignore_acpi_ev
)
3602 /* 0x6000-0x6FFF: thermal alarms */
3603 *send_acpi_ev
= true;
3604 *ignore_acpi_ev
= false;
3607 case TP_HKEY_EV_THM_TABLE_CHANGED
:
3609 "EC reports that Thermal Table has changed\n");
3610 /* recommended action: do nothing, we don't have
3611 * Lenovo ATM information */
3613 case TP_HKEY_EV_ALARM_BAT_HOT
:
3615 "THERMAL ALARM: battery is too hot!\n");
3616 /* recommended action: warn user through gui */
3618 case TP_HKEY_EV_ALARM_BAT_XHOT
:
3620 "THERMAL EMERGENCY: battery is extremely hot!\n");
3621 /* recommended action: immediate sleep/hibernate */
3623 case TP_HKEY_EV_ALARM_SENSOR_HOT
:
3626 "a sensor reports something is too hot!\n");
3627 /* recommended action: warn user through gui, that */
3628 /* some internal component is too hot */
3630 case TP_HKEY_EV_ALARM_SENSOR_XHOT
:
3632 "THERMAL EMERGENCY: "
3633 "a sensor reports something is extremely hot!\n");
3634 /* recommended action: immediate sleep/hibernate */
3638 "THERMAL ALERT: unknown thermal alarm received\n");
3642 thermal_dump_all_sensors();
3647 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3651 bool ignore_acpi_ev
;
3654 if (event
!= 0x80) {
3656 "unknown HKEY notification event %d\n", event
);
3657 /* forward it to userspace, maybe it knows how to handle it */
3658 acpi_bus_generate_netlink_event(
3659 ibm
->acpi
->device
->pnp
.device_class
,
3660 dev_name(&ibm
->acpi
->device
->dev
),
3666 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3667 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3676 send_acpi_ev
= true;
3677 ignore_acpi_ev
= false;
3679 switch (hkey
>> 12) {
3681 /* 0x1000-0x1FFF: key presses */
3682 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3686 /* 0x2000-0x2FFF: Wakeup reason */
3687 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3691 /* 0x3000-0x3FFF: bay-related wakeups */
3693 case TP_HKEY_EV_BAYEJ_ACK
:
3694 hotkey_autosleep_ack
= 1;
3697 hotkey_wakeup_hotunplug_complete_notify_change();
3700 case TP_HKEY_EV_OPTDRV_EJ
:
3701 /* FIXME: kick libata if SATA link offline */
3709 /* 0x4000-0x4FFF: dock-related wakeups */
3710 if (hkey
== TP_HKEY_EV_UNDOCK_ACK
) {
3711 hotkey_autosleep_ack
= 1;
3714 hotkey_wakeup_hotunplug_complete_notify_change();
3721 /* 0x5000-0x5FFF: human interface helpers */
3722 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3726 /* 0x6000-0x6FFF: thermal alarms */
3727 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3731 /* 0x7000-0x7FFF: misc */
3732 if (tp_features
.hotkey_wlsw
&&
3733 hkey
== TP_HKEY_EV_RFKILL_CHANGED
) {
3734 tpacpi_send_radiosw_update();
3739 /* fallthrough to default */
3744 printk(TPACPI_NOTICE
3745 "unhandled HKEY event 0x%04x\n", hkey
);
3746 printk(TPACPI_NOTICE
3747 "please report the conditions when this "
3748 "event happened to %s\n", TPACPI_MAIL
);
3752 if (!ignore_acpi_ev
&&
3753 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3754 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3758 /* netlink events */
3759 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3760 acpi_bus_generate_netlink_event(
3761 ibm
->acpi
->device
->pnp
.device_class
,
3762 dev_name(&ibm
->acpi
->device
->dev
),
3768 static void hotkey_suspend(pm_message_t state
)
3770 /* Do these on suspend, we get the events on early resume! */
3771 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3772 hotkey_autosleep_ack
= 0;
3775 static void hotkey_resume(void)
3777 tpacpi_disable_brightness_delay();
3779 if (hotkey_status_set(true) < 0 ||
3780 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3782 "error while attempting to reset the event "
3783 "firmware interface\n");
3785 tpacpi_send_radiosw_update();
3786 hotkey_tablet_mode_notify_change();
3787 hotkey_wakeup_reason_notify_change();
3788 hotkey_wakeup_hotunplug_complete_notify_change();
3789 hotkey_poll_setup_safe(false);
3792 /* procfs -------------------------------------------------------------- */
3793 static int hotkey_read(struct seq_file
*m
)
3797 if (!tp_features
.hotkey
) {
3798 seq_printf(m
, "status:\t\tnot supported\n");
3802 if (mutex_lock_killable(&hotkey_mutex
))
3803 return -ERESTARTSYS
;
3804 res
= hotkey_status_get(&status
);
3806 res
= hotkey_mask_get();
3807 mutex_unlock(&hotkey_mutex
);
3811 seq_printf(m
, "status:\t\t%s\n", enabled(status
, 0));
3812 if (hotkey_all_mask
) {
3813 seq_printf(m
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3814 seq_printf(m
, "commands:\tenable, disable, reset, <mask>\n");
3816 seq_printf(m
, "mask:\t\tnot supported\n");
3817 seq_printf(m
, "commands:\tenable, disable, reset\n");
3823 static void hotkey_enabledisable_warn(bool enable
)
3825 tpacpi_log_usertask("procfs hotkey enable/disable");
3826 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3828 "hotkey enable/disable functionality has been "
3829 "removed from the driver. Hotkeys are always "
3832 "Please remove the hotkey=enable module "
3833 "parameter, it is deprecated. Hotkeys are always "
3837 static int hotkey_write(char *buf
)
3843 if (!tp_features
.hotkey
)
3846 if (mutex_lock_killable(&hotkey_mutex
))
3847 return -ERESTARTSYS
;
3849 mask
= hotkey_user_mask
;
3852 while ((cmd
= next_cmd(&buf
))) {
3853 if (strlencmp(cmd
, "enable") == 0) {
3854 hotkey_enabledisable_warn(1);
3855 } else if (strlencmp(cmd
, "disable") == 0) {
3856 hotkey_enabledisable_warn(0);
3858 } else if (strlencmp(cmd
, "reset") == 0) {
3859 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3860 & ~hotkey_reserved_mask
;
3861 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3863 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3872 tpacpi_disclose_usertask("procfs hotkey",
3873 "set mask to 0x%08x\n", mask
);
3874 res
= hotkey_user_mask_set(mask
);
3878 mutex_unlock(&hotkey_mutex
);
3882 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3883 {TPACPI_ACPI_IBM_HKEY_HID
, 0},
3884 {TPACPI_ACPI_LENOVO_HKEY_HID
, 0},
3888 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3889 .hid
= ibm_htk_device_ids
,
3890 .notify
= hotkey_notify
,
3891 .handle
= &hkey_handle
,
3892 .type
= ACPI_DEVICE_NOTIFY
,
3895 static struct ibm_struct hotkey_driver_data
= {
3897 .read
= hotkey_read
,
3898 .write
= hotkey_write
,
3899 .exit
= hotkey_exit
,
3900 .resume
= hotkey_resume
,
3901 .suspend
= hotkey_suspend
,
3902 .acpi
= &ibm_hotkey_acpidriver
,
3905 /*************************************************************************
3906 * Bluetooth subdriver
3910 /* ACPI GBDC/SBDC bits */
3911 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3912 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3913 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3914 0 = disable, 1 = enable */
3918 /* ACPI \BLTH commands */
3919 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3920 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3921 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3922 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3923 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3926 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3928 static int bluetooth_get_status(void)
3932 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3933 if (dbg_bluetoothemul
)
3934 return (tpacpi_bluetooth_emulstate
) ?
3935 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3938 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3941 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3942 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3945 static int bluetooth_set_status(enum tpacpi_rfkill_state state
)
3949 vdbg_printk(TPACPI_DBG_RFKILL
,
3950 "will attempt to %s bluetooth\n",
3951 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
3953 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3954 if (dbg_bluetoothemul
) {
3955 tpacpi_bluetooth_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
3960 if (state
== TPACPI_RFK_RADIO_ON
)
3961 status
= TP_ACPI_BLUETOOTH_RADIOSSW
3962 | TP_ACPI_BLUETOOTH_RESUMECTRL
;
3966 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3972 /* sysfs bluetooth enable ---------------------------------------------- */
3973 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3974 struct device_attribute
*attr
,
3977 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID
,
3981 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3982 struct device_attribute
*attr
,
3983 const char *buf
, size_t count
)
3985 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID
,
3989 static struct device_attribute dev_attr_bluetooth_enable
=
3990 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3991 bluetooth_enable_show
, bluetooth_enable_store
);
3993 /* --------------------------------------------------------------------- */
3995 static struct attribute
*bluetooth_attributes
[] = {
3996 &dev_attr_bluetooth_enable
.attr
,
4000 static const struct attribute_group bluetooth_attr_group
= {
4001 .attrs
= bluetooth_attributes
,
4004 static const struct tpacpi_rfk_ops bluetooth_tprfk_ops
= {
4005 .get_status
= bluetooth_get_status
,
4006 .set_status
= bluetooth_set_status
,
4009 static void bluetooth_shutdown(void)
4011 /* Order firmware to save current state to NVRAM */
4012 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
4013 TP_ACPI_BLTH_SAVE_STATE
))
4014 printk(TPACPI_NOTICE
4015 "failed to save bluetooth state to NVRAM\n");
4017 vdbg_printk(TPACPI_DBG_RFKILL
,
4018 "bluestooth state saved to NVRAM\n");
4021 static void bluetooth_exit(void)
4023 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4024 &bluetooth_attr_group
);
4026 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
4028 bluetooth_shutdown();
4031 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
4036 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4037 "initializing bluetooth subdriver\n");
4039 TPACPI_ACPIHANDLE_INIT(hkey
);
4041 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4042 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
4043 tp_features
.bluetooth
= hkey_handle
&&
4044 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
4046 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4047 "bluetooth is %s, status 0x%02x\n",
4048 str_supported(tp_features
.bluetooth
),
4051 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4052 if (dbg_bluetoothemul
) {
4053 tp_features
.bluetooth
= 1;
4055 "bluetooth switch emulation enabled\n");
4058 if (tp_features
.bluetooth
&&
4059 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
4060 /* no bluetooth hardware present in system */
4061 tp_features
.bluetooth
= 0;
4062 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4063 "bluetooth hardware not installed\n");
4066 if (!tp_features
.bluetooth
)
4069 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
4070 &bluetooth_tprfk_ops
,
4071 RFKILL_TYPE_BLUETOOTH
,
4072 TPACPI_RFK_BLUETOOTH_SW_NAME
,
4077 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4078 &bluetooth_attr_group
);
4080 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
4087 /* procfs -------------------------------------------------------------- */
4088 static int bluetooth_read(struct seq_file
*m
)
4090 return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID
, m
);
4093 static int bluetooth_write(char *buf
)
4095 return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID
, buf
);
4098 static struct ibm_struct bluetooth_driver_data
= {
4099 .name
= "bluetooth",
4100 .read
= bluetooth_read
,
4101 .write
= bluetooth_write
,
4102 .exit
= bluetooth_exit
,
4103 .shutdown
= bluetooth_shutdown
,
4106 /*************************************************************************
4111 /* ACPI GWAN/SWAN bits */
4112 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
4113 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
4114 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
4115 0 = disable, 1 = enable */
4118 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
4120 static int wan_get_status(void)
4124 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4126 return (tpacpi_wwan_emulstate
) ?
4127 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4130 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
4133 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
4134 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4137 static int wan_set_status(enum tpacpi_rfkill_state state
)
4141 vdbg_printk(TPACPI_DBG_RFKILL
,
4142 "will attempt to %s wwan\n",
4143 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4145 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4147 tpacpi_wwan_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4152 if (state
== TPACPI_RFK_RADIO_ON
)
4153 status
= TP_ACPI_WANCARD_RADIOSSW
4154 | TP_ACPI_WANCARD_RESUMECTRL
;
4158 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
4164 /* sysfs wan enable ---------------------------------------------------- */
4165 static ssize_t
wan_enable_show(struct device
*dev
,
4166 struct device_attribute
*attr
,
4169 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID
,
4173 static ssize_t
wan_enable_store(struct device
*dev
,
4174 struct device_attribute
*attr
,
4175 const char *buf
, size_t count
)
4177 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID
,
4181 static struct device_attribute dev_attr_wan_enable
=
4182 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4183 wan_enable_show
, wan_enable_store
);
4185 /* --------------------------------------------------------------------- */
4187 static struct attribute
*wan_attributes
[] = {
4188 &dev_attr_wan_enable
.attr
,
4192 static const struct attribute_group wan_attr_group
= {
4193 .attrs
= wan_attributes
,
4196 static const struct tpacpi_rfk_ops wan_tprfk_ops
= {
4197 .get_status
= wan_get_status
,
4198 .set_status
= wan_set_status
,
4201 static void wan_shutdown(void)
4203 /* Order firmware to save current state to NVRAM */
4204 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4205 TP_ACPI_WGSV_SAVE_STATE
))
4206 printk(TPACPI_NOTICE
4207 "failed to save WWAN state to NVRAM\n");
4209 vdbg_printk(TPACPI_DBG_RFKILL
,
4210 "WWAN state saved to NVRAM\n");
4213 static void wan_exit(void)
4215 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4218 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4223 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4228 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4229 "initializing wan subdriver\n");
4231 TPACPI_ACPIHANDLE_INIT(hkey
);
4233 tp_features
.wan
= hkey_handle
&&
4234 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4236 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4237 "wan is %s, status 0x%02x\n",
4238 str_supported(tp_features
.wan
),
4241 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4243 tp_features
.wan
= 1;
4245 "wwan switch emulation enabled\n");
4248 if (tp_features
.wan
&&
4249 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4250 /* no wan hardware present in system */
4251 tp_features
.wan
= 0;
4252 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4253 "wan hardware not installed\n");
4256 if (!tp_features
.wan
)
4259 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4262 TPACPI_RFK_WWAN_SW_NAME
,
4267 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4271 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4278 /* procfs -------------------------------------------------------------- */
4279 static int wan_read(struct seq_file
*m
)
4281 return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID
, m
);
4284 static int wan_write(char *buf
)
4286 return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID
, buf
);
4289 static struct ibm_struct wan_driver_data
= {
4294 .shutdown
= wan_shutdown
,
4297 /*************************************************************************
4302 /* ACPI GUWB/SUWB bits */
4303 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4304 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4307 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4309 static int uwb_get_status(void)
4313 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4315 return (tpacpi_uwb_emulstate
) ?
4316 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4319 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4322 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4323 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4326 static int uwb_set_status(enum tpacpi_rfkill_state state
)
4330 vdbg_printk(TPACPI_DBG_RFKILL
,
4331 "will attempt to %s UWB\n",
4332 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4334 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4336 tpacpi_uwb_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4341 if (state
== TPACPI_RFK_RADIO_ON
)
4342 status
= TP_ACPI_UWB_RADIOSSW
;
4346 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4352 /* --------------------------------------------------------------------- */
4354 static const struct tpacpi_rfk_ops uwb_tprfk_ops
= {
4355 .get_status
= uwb_get_status
,
4356 .set_status
= uwb_set_status
,
4359 static void uwb_exit(void)
4361 tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID
);
4364 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4369 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4370 "initializing uwb subdriver\n");
4372 TPACPI_ACPIHANDLE_INIT(hkey
);
4374 tp_features
.uwb
= hkey_handle
&&
4375 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4377 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4378 "uwb is %s, status 0x%02x\n",
4379 str_supported(tp_features
.uwb
),
4382 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4384 tp_features
.uwb
= 1;
4386 "uwb switch emulation enabled\n");
4389 if (tp_features
.uwb
&&
4390 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4391 /* no uwb hardware present in system */
4392 tp_features
.uwb
= 0;
4393 dbg_printk(TPACPI_DBG_INIT
,
4394 "uwb hardware not installed\n");
4397 if (!tp_features
.uwb
)
4400 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4403 TPACPI_RFK_UWB_SW_NAME
,
4408 static struct ibm_struct uwb_driver_data
= {
4411 .flags
.experimental
= 1,
4414 /*************************************************************************
4418 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4420 enum video_access_mode
{
4421 TPACPI_VIDEO_NONE
= 0,
4422 TPACPI_VIDEO_570
, /* 570 */
4423 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4424 TPACPI_VIDEO_NEW
, /* all others */
4427 enum { /* video status flags, based on VIDEO_570 */
4428 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4429 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4430 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4433 enum { /* TPACPI_VIDEO_570 constants */
4434 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4435 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4436 * video_status_flags */
4437 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4438 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4441 static enum video_access_mode video_supported
;
4442 static int video_orig_autosw
;
4444 static int video_autosw_get(void);
4445 static int video_autosw_set(int enable
);
4447 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4449 static int __init
video_init(struct ibm_init_struct
*iibm
)
4453 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4455 TPACPI_ACPIHANDLE_INIT(vid
);
4456 if (tpacpi_is_ibm())
4457 TPACPI_ACPIHANDLE_INIT(vid2
);
4459 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4460 /* G41, assume IVGA doesn't change */
4461 vid_handle
= vid2_handle
;
4464 /* video switching not supported on R30, R31 */
4465 video_supported
= TPACPI_VIDEO_NONE
;
4466 else if (tpacpi_is_ibm() &&
4467 acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4469 video_supported
= TPACPI_VIDEO_570
;
4470 else if (tpacpi_is_ibm() &&
4471 acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4472 /* 600e/x, 770e, 770x */
4473 video_supported
= TPACPI_VIDEO_770
;
4476 video_supported
= TPACPI_VIDEO_NEW
;
4478 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4479 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4482 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4485 static void video_exit(void)
4487 dbg_printk(TPACPI_DBG_EXIT
,
4488 "restoring original video autoswitch mode\n");
4489 if (video_autosw_set(video_orig_autosw
))
4490 printk(TPACPI_ERR
"error while trying to restore original "
4491 "video autoswitch mode\n");
4494 static int video_outputsw_get(void)
4499 switch (video_supported
) {
4500 case TPACPI_VIDEO_570
:
4501 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4502 TP_ACPI_VIDEO_570_PHSCMD
))
4504 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4506 case TPACPI_VIDEO_770
:
4507 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4510 status
|= TP_ACPI_VIDEO_S_LCD
;
4511 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4514 status
|= TP_ACPI_VIDEO_S_CRT
;
4516 case TPACPI_VIDEO_NEW
:
4517 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4518 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4521 status
|= TP_ACPI_VIDEO_S_CRT
;
4523 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4524 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4527 status
|= TP_ACPI_VIDEO_S_LCD
;
4528 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4531 status
|= TP_ACPI_VIDEO_S_DVI
;
4540 static int video_outputsw_set(int status
)
4545 switch (video_supported
) {
4546 case TPACPI_VIDEO_570
:
4547 res
= acpi_evalf(NULL
, NULL
,
4548 "\\_SB.PHS2", "vdd",
4549 TP_ACPI_VIDEO_570_PHS2CMD
,
4550 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4552 case TPACPI_VIDEO_770
:
4553 autosw
= video_autosw_get();
4557 res
= video_autosw_set(1);
4560 res
= acpi_evalf(vid_handle
, NULL
,
4561 "ASWT", "vdd", status
* 0x100, 0);
4562 if (!autosw
&& video_autosw_set(autosw
)) {
4564 "video auto-switch left enabled due to error\n");
4568 case TPACPI_VIDEO_NEW
:
4569 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4570 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4576 return (res
)? 0 : -EIO
;
4579 static int video_autosw_get(void)
4583 switch (video_supported
) {
4584 case TPACPI_VIDEO_570
:
4585 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4588 case TPACPI_VIDEO_770
:
4589 case TPACPI_VIDEO_NEW
:
4590 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4600 static int video_autosw_set(int enable
)
4602 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4607 static int video_outputsw_cycle(void)
4609 int autosw
= video_autosw_get();
4615 switch (video_supported
) {
4616 case TPACPI_VIDEO_570
:
4617 res
= video_autosw_set(1);
4620 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4622 case TPACPI_VIDEO_770
:
4623 case TPACPI_VIDEO_NEW
:
4624 res
= video_autosw_set(1);
4627 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4632 if (!autosw
&& video_autosw_set(autosw
)) {
4634 "video auto-switch left enabled due to error\n");
4638 return (res
)? 0 : -EIO
;
4641 static int video_expand_toggle(void)
4643 switch (video_supported
) {
4644 case TPACPI_VIDEO_570
:
4645 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4647 case TPACPI_VIDEO_770
:
4648 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4650 case TPACPI_VIDEO_NEW
:
4651 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4659 static int video_read(struct seq_file
*m
)
4663 if (video_supported
== TPACPI_VIDEO_NONE
) {
4664 seq_printf(m
, "status:\t\tnot supported\n");
4668 /* Even reads can crash X.org, so... */
4669 if (!capable(CAP_SYS_ADMIN
))
4672 status
= video_outputsw_get();
4676 autosw
= video_autosw_get();
4680 seq_printf(m
, "status:\t\tsupported\n");
4681 seq_printf(m
, "lcd:\t\t%s\n", enabled(status
, 0));
4682 seq_printf(m
, "crt:\t\t%s\n", enabled(status
, 1));
4683 if (video_supported
== TPACPI_VIDEO_NEW
)
4684 seq_printf(m
, "dvi:\t\t%s\n", enabled(status
, 3));
4685 seq_printf(m
, "auto:\t\t%s\n", enabled(autosw
, 0));
4686 seq_printf(m
, "commands:\tlcd_enable, lcd_disable\n");
4687 seq_printf(m
, "commands:\tcrt_enable, crt_disable\n");
4688 if (video_supported
== TPACPI_VIDEO_NEW
)
4689 seq_printf(m
, "commands:\tdvi_enable, dvi_disable\n");
4690 seq_printf(m
, "commands:\tauto_enable, auto_disable\n");
4691 seq_printf(m
, "commands:\tvideo_switch, expand_toggle\n");
4696 static int video_write(char *buf
)
4699 int enable
, disable
, status
;
4702 if (video_supported
== TPACPI_VIDEO_NONE
)
4705 /* Even reads can crash X.org, let alone writes... */
4706 if (!capable(CAP_SYS_ADMIN
))
4712 while ((cmd
= next_cmd(&buf
))) {
4713 if (strlencmp(cmd
, "lcd_enable") == 0) {
4714 enable
|= TP_ACPI_VIDEO_S_LCD
;
4715 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4716 disable
|= TP_ACPI_VIDEO_S_LCD
;
4717 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4718 enable
|= TP_ACPI_VIDEO_S_CRT
;
4719 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4720 disable
|= TP_ACPI_VIDEO_S_CRT
;
4721 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4722 strlencmp(cmd
, "dvi_enable") == 0) {
4723 enable
|= TP_ACPI_VIDEO_S_DVI
;
4724 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4725 strlencmp(cmd
, "dvi_disable") == 0) {
4726 disable
|= TP_ACPI_VIDEO_S_DVI
;
4727 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4728 res
= video_autosw_set(1);
4731 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4732 res
= video_autosw_set(0);
4735 } else if (strlencmp(cmd
, "video_switch") == 0) {
4736 res
= video_outputsw_cycle();
4739 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4740 res
= video_expand_toggle();
4747 if (enable
|| disable
) {
4748 status
= video_outputsw_get();
4751 res
= video_outputsw_set((status
& ~disable
) | enable
);
4759 static struct ibm_struct video_driver_data
= {
4762 .write
= video_write
,
4766 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4768 /*************************************************************************
4769 * Light (thinklight) subdriver
4772 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4773 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4775 static int light_get_status(void)
4779 if (tp_features
.light_status
) {
4780 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4788 static int light_set_status(int status
)
4792 if (tp_features
.light
) {
4794 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4796 TP_CMOS_THINKLIGHT_ON
:
4797 TP_CMOS_THINKLIGHT_OFF
);
4799 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4802 return (rc
)? 0 : -EIO
;
4808 static void light_set_status_worker(struct work_struct
*work
)
4810 struct tpacpi_led_classdev
*data
=
4811 container_of(work
, struct tpacpi_led_classdev
, work
);
4813 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4814 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4817 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4818 enum led_brightness brightness
)
4820 struct tpacpi_led_classdev
*data
=
4821 container_of(led_cdev
,
4822 struct tpacpi_led_classdev
,
4824 data
->new_state
= (brightness
!= LED_OFF
) ?
4825 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4826 queue_work(tpacpi_wq
, &data
->work
);
4829 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4831 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4834 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4836 .name
= "tpacpi::thinklight",
4837 .brightness_set
= &light_sysfs_set
,
4838 .brightness_get
= &light_sysfs_get
,
4842 static int __init
light_init(struct ibm_init_struct
*iibm
)
4846 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4848 if (tpacpi_is_ibm()) {
4849 TPACPI_ACPIHANDLE_INIT(ledb
);
4850 TPACPI_ACPIHANDLE_INIT(lght
);
4852 TPACPI_ACPIHANDLE_INIT(cmos
);
4853 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4855 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4856 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4858 if (tp_features
.light
)
4859 /* light status not supported on
4860 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4861 tp_features
.light_status
=
4862 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4864 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4865 str_supported(tp_features
.light
),
4866 str_supported(tp_features
.light_status
));
4868 if (!tp_features
.light
)
4871 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4872 &tpacpi_led_thinklight
.led_classdev
);
4875 tp_features
.light
= 0;
4876 tp_features
.light_status
= 0;
4884 static void light_exit(void)
4886 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4887 if (work_pending(&tpacpi_led_thinklight
.work
))
4888 flush_workqueue(tpacpi_wq
);
4891 static int light_read(struct seq_file
*m
)
4895 if (!tp_features
.light
) {
4896 seq_printf(m
, "status:\t\tnot supported\n");
4897 } else if (!tp_features
.light_status
) {
4898 seq_printf(m
, "status:\t\tunknown\n");
4899 seq_printf(m
, "commands:\ton, off\n");
4901 status
= light_get_status();
4904 seq_printf(m
, "status:\t\t%s\n", onoff(status
, 0));
4905 seq_printf(m
, "commands:\ton, off\n");
4911 static int light_write(char *buf
)
4916 if (!tp_features
.light
)
4919 while ((cmd
= next_cmd(&buf
))) {
4920 if (strlencmp(cmd
, "on") == 0) {
4922 } else if (strlencmp(cmd
, "off") == 0) {
4928 return light_set_status(newstatus
);
4931 static struct ibm_struct light_driver_data
= {
4934 .write
= light_write
,
4938 /*************************************************************************
4942 /* sysfs cmos_command -------------------------------------------------- */
4943 static ssize_t
cmos_command_store(struct device
*dev
,
4944 struct device_attribute
*attr
,
4945 const char *buf
, size_t count
)
4947 unsigned long cmos_cmd
;
4950 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4953 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4954 return (res
)? res
: count
;
4957 static struct device_attribute dev_attr_cmos_command
=
4958 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4960 /* --------------------------------------------------------------------- */
4962 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4966 vdbg_printk(TPACPI_DBG_INIT
,
4967 "initializing cmos commands subdriver\n");
4969 TPACPI_ACPIHANDLE_INIT(cmos
);
4971 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4972 str_supported(cmos_handle
!= NULL
));
4974 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4978 return (cmos_handle
)? 0 : 1;
4981 static void cmos_exit(void)
4983 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4986 static int cmos_read(struct seq_file
*m
)
4988 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4989 R30, R31, T20-22, X20-21 */
4991 seq_printf(m
, "status:\t\tnot supported\n");
4993 seq_printf(m
, "status:\t\tsupported\n");
4994 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-21)\n");
5000 static int cmos_write(char *buf
)
5005 while ((cmd
= next_cmd(&buf
))) {
5006 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
5007 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
5012 res
= issue_thinkpad_cmos_command(cmos_cmd
);
5020 static struct ibm_struct cmos_driver_data
= {
5023 .write
= cmos_write
,
5027 /*************************************************************************
5031 enum led_access_mode
{
5032 TPACPI_LED_NONE
= 0,
5033 TPACPI_LED_570
, /* 570 */
5034 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5035 TPACPI_LED_NEW
, /* all others */
5038 enum { /* For TPACPI_LED_OLD */
5039 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
5040 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
5041 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
5044 static enum led_access_mode led_supported
;
5046 static acpi_handle led_handle
;
5048 #define TPACPI_LED_NUMLEDS 16
5049 static struct tpacpi_led_classdev
*tpacpi_leds
;
5050 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
5051 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
5052 /* there's a limit of 19 chars + NULL before 2.6.26 */
5054 "tpacpi:orange:batt",
5055 "tpacpi:green:batt",
5056 "tpacpi::dock_active",
5057 "tpacpi::bay_active",
5058 "tpacpi::dock_batt",
5059 "tpacpi::unknown_led",
5061 "tpacpi::dock_status1",
5062 "tpacpi::dock_status2",
5063 "tpacpi::unknown_led2",
5064 "tpacpi::unknown_led3",
5065 "tpacpi::thinkvantage",
5067 #define TPACPI_SAFE_LEDS 0x1081U
5069 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
5071 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5074 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
5078 static int led_get_status(const unsigned int led
)
5081 enum led_status_t led_s
;
5083 switch (led_supported
) {
5084 case TPACPI_LED_570
:
5085 if (!acpi_evalf(ec_handle
,
5086 &status
, "GLED", "dd", 1 << led
))
5088 led_s
= (status
== 0)?
5093 tpacpi_led_state_cache
[led
] = led_s
;
5102 static int led_set_status(const unsigned int led
,
5103 const enum led_status_t ledstatus
)
5105 /* off, on, blink. Index is led_status_t */
5106 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
5107 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
5111 switch (led_supported
) {
5112 case TPACPI_LED_570
:
5114 if (unlikely(led
> 7))
5116 if (unlikely(tpacpi_is_led_restricted(led
)))
5118 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5119 (1 << led
), led_sled_arg1
[ledstatus
]))
5122 case TPACPI_LED_OLD
:
5123 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
5124 if (unlikely(led
> 7))
5126 if (unlikely(tpacpi_is_led_restricted(led
)))
5128 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
5130 rc
= ec_write(TPACPI_LED_EC_HLBL
,
5131 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5133 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5134 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5136 case TPACPI_LED_NEW
:
5138 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5140 if (unlikely(tpacpi_is_led_restricted(led
)))
5142 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5143 led
, led_led_arg1
[ledstatus
]))
5151 tpacpi_led_state_cache
[led
] = ledstatus
;
5156 static void led_set_status_worker(struct work_struct
*work
)
5158 struct tpacpi_led_classdev
*data
=
5159 container_of(work
, struct tpacpi_led_classdev
, work
);
5161 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5162 led_set_status(data
->led
, data
->new_state
);
5165 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5166 enum led_brightness brightness
)
5168 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5169 struct tpacpi_led_classdev
, led_classdev
);
5171 if (brightness
== LED_OFF
)
5172 data
->new_state
= TPACPI_LED_OFF
;
5173 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5174 data
->new_state
= TPACPI_LED_ON
;
5176 data
->new_state
= TPACPI_LED_BLINK
;
5178 queue_work(tpacpi_wq
, &data
->work
);
5181 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5182 unsigned long *delay_on
, unsigned long *delay_off
)
5184 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5185 struct tpacpi_led_classdev
, led_classdev
);
5187 /* Can we choose the flash rate? */
5188 if (*delay_on
== 0 && *delay_off
== 0) {
5189 /* yes. set them to the hardware blink rate (1 Hz) */
5190 *delay_on
= 500; /* ms */
5191 *delay_off
= 500; /* ms */
5192 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5195 data
->new_state
= TPACPI_LED_BLINK
;
5196 queue_work(tpacpi_wq
, &data
->work
);
5201 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5205 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5206 struct tpacpi_led_classdev
, led_classdev
);
5208 rc
= led_get_status(data
->led
);
5210 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5211 rc
= LED_OFF
; /* no error handling in led class :( */
5218 static void led_exit(void)
5222 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5223 if (tpacpi_leds
[i
].led_classdev
.name
)
5224 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5230 static int __init
tpacpi_init_led(unsigned int led
)
5234 tpacpi_leds
[led
].led
= led
;
5236 /* LEDs with no name don't get registered */
5237 if (!tpacpi_led_names
[led
])
5240 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5241 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5242 if (led_supported
== TPACPI_LED_570
)
5243 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5246 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5248 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5250 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5251 &tpacpi_leds
[led
].led_classdev
);
5253 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5258 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5259 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5260 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5261 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5263 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5264 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5265 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5266 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5267 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5268 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5269 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5270 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5272 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5273 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5274 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5275 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5276 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5278 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5279 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5280 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5281 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5283 /* (1) - may have excess leds enabled on MSB */
5285 /* Defaults (order matters, keep last, don't reorder!) */
5287 .vendor
= PCI_VENDOR_ID_LENOVO
,
5288 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5291 { /* IBM ThinkPads with no EC version string */
5292 .vendor
= PCI_VENDOR_ID_IBM
,
5293 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5296 { /* IBM ThinkPads with EC version string */
5297 .vendor
= PCI_VENDOR_ID_IBM
,
5298 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5303 #undef TPACPI_LEDQ_IBM
5304 #undef TPACPI_LEDQ_LNV
5306 static enum led_access_mode __init
led_init_detect_mode(void)
5310 if (tpacpi_is_ibm()) {
5312 status
= acpi_get_handle(ec_handle
, "SLED", &led_handle
);
5313 if (ACPI_SUCCESS(status
))
5314 return TPACPI_LED_570
;
5316 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5317 status
= acpi_get_handle(ec_handle
, "SYSL", &led_handle
);
5318 if (ACPI_SUCCESS(status
))
5319 return TPACPI_LED_OLD
;
5323 status
= acpi_get_handle(ec_handle
, "LED", &led_handle
);
5324 if (ACPI_SUCCESS(status
))
5325 return TPACPI_LED_NEW
;
5327 /* R30, R31, and unknown firmwares */
5329 return TPACPI_LED_NONE
;
5332 static int __init
led_init(struct ibm_init_struct
*iibm
)
5336 unsigned long useful_leds
;
5338 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5340 led_supported
= led_init_detect_mode();
5342 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5343 str_supported(led_supported
), led_supported
);
5345 if (led_supported
== TPACPI_LED_NONE
)
5348 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5351 printk(TPACPI_ERR
"Out of memory for LED data\n");
5355 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5356 ARRAY_SIZE(led_useful_qtable
));
5358 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5359 if (!tpacpi_is_led_restricted(i
) &&
5360 test_bit(i
, &useful_leds
)) {
5361 rc
= tpacpi_init_led(i
);
5369 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5370 printk(TPACPI_NOTICE
5371 "warning: userspace override of important "
5372 "firmware LEDs is enabled\n");
5377 #define str_led_status(s) \
5378 ((s) == TPACPI_LED_OFF ? "off" : \
5379 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5381 static int led_read(struct seq_file
*m
)
5383 if (!led_supported
) {
5384 seq_printf(m
, "status:\t\tnot supported\n");
5387 seq_printf(m
, "status:\t\tsupported\n");
5389 if (led_supported
== TPACPI_LED_570
) {
5392 for (i
= 0; i
< 8; i
++) {
5393 status
= led_get_status(i
);
5396 seq_printf(m
, "%d:\t\t%s\n",
5397 i
, str_led_status(status
));
5401 seq_printf(m
, "commands:\t"
5402 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5407 static int led_write(char *buf
)
5411 enum led_status_t s
;
5416 while ((cmd
= next_cmd(&buf
))) {
5417 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5420 if (strstr(cmd
, "off")) {
5422 } else if (strstr(cmd
, "on")) {
5424 } else if (strstr(cmd
, "blink")) {
5425 s
= TPACPI_LED_BLINK
;
5430 rc
= led_set_status(led
, s
);
5438 static struct ibm_struct led_driver_data
= {
5445 /*************************************************************************
5449 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5451 #define TPACPI_BEEP_Q1 0x0001
5453 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5454 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5455 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5458 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5460 unsigned long quirks
;
5462 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5464 TPACPI_ACPIHANDLE_INIT(beep
);
5466 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5467 str_supported(beep_handle
!= NULL
));
5469 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5470 ARRAY_SIZE(beep_quirk_table
));
5472 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5474 return (beep_handle
)? 0 : 1;
5477 static int beep_read(struct seq_file
*m
)
5480 seq_printf(m
, "status:\t\tnot supported\n");
5482 seq_printf(m
, "status:\t\tsupported\n");
5483 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5489 static int beep_write(char *buf
)
5497 while ((cmd
= next_cmd(&buf
))) {
5498 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5499 beep_cmd
>= 0 && beep_cmd
<= 17) {
5503 if (tp_features
.beep_needs_two_args
) {
5504 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5508 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5517 static struct ibm_struct beep_driver_data
= {
5520 .write
= beep_write
,
5523 /*************************************************************************
5527 enum thermal_access_mode
{
5528 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5529 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5530 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5531 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5532 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5535 enum { /* TPACPI_THERMAL_TPEC_* */
5536 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5537 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5538 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5540 TPACPI_THERMAL_SENSOR_NA
= -128000, /* Sensor not available */
5544 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5545 struct ibm_thermal_sensors_struct
{
5546 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5549 static enum thermal_access_mode thermal_read_mode
;
5551 /* idx is zero-based */
5552 static int thermal_get_sensor(int idx
, s32
*value
)
5558 t
= TP_EC_THERMAL_TMP0
;
5560 switch (thermal_read_mode
) {
5561 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5562 case TPACPI_THERMAL_TPEC_16
:
5563 if (idx
>= 8 && idx
<= 15) {
5564 t
= TP_EC_THERMAL_TMP8
;
5569 case TPACPI_THERMAL_TPEC_8
:
5571 if (!acpi_ec_read(t
+ idx
, &tmp
))
5573 *value
= tmp
* 1000;
5578 case TPACPI_THERMAL_ACPI_UPDT
:
5580 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5581 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5583 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5585 *value
= (t
- 2732) * 100;
5590 case TPACPI_THERMAL_ACPI_TMP07
:
5592 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5593 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5595 if (t
> 127 || t
< -127)
5596 t
= TP_EC_THERMAL_TMP_NA
;
5602 case TPACPI_THERMAL_NONE
:
5610 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5621 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5624 for (i
= 0 ; i
< n
; i
++) {
5625 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5633 static void thermal_dump_all_sensors(void)
5636 struct ibm_thermal_sensors_struct t
;
5638 n
= thermal_get_sensors(&t
);
5642 printk(TPACPI_NOTICE
5643 "temperatures (Celsius):");
5645 for (i
= 0; i
< n
; i
++) {
5646 if (t
.temp
[i
] != TPACPI_THERMAL_SENSOR_NA
)
5647 printk(KERN_CONT
" %d", (int)(t
.temp
[i
] / 1000));
5649 printk(KERN_CONT
" N/A");
5652 printk(KERN_CONT
"\n");
5655 /* sysfs temp##_input -------------------------------------------------- */
5657 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5658 struct device_attribute
*attr
,
5661 struct sensor_device_attribute
*sensor_attr
=
5662 to_sensor_dev_attr(attr
);
5663 int idx
= sensor_attr
->index
;
5667 res
= thermal_get_sensor(idx
, &value
);
5670 if (value
== TPACPI_THERMAL_SENSOR_NA
)
5673 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5676 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5677 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5678 thermal_temp_input_show, NULL, _idxB)
5680 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5681 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5682 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5683 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5684 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5685 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5686 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5687 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5688 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5689 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5690 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5691 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5692 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5693 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5694 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5695 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5696 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5699 #define THERMAL_ATTRS(X) \
5700 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5702 static struct attribute
*thermal_temp_input_attr
[] = {
5722 static const struct attribute_group thermal_temp_input16_group
= {
5723 .attrs
= thermal_temp_input_attr
5726 static const struct attribute_group thermal_temp_input8_group
= {
5727 .attrs
= &thermal_temp_input_attr
[8]
5730 #undef THERMAL_SENSOR_ATTR_TEMP
5731 #undef THERMAL_ATTRS
5733 /* --------------------------------------------------------------------- */
5735 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5742 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5744 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5746 if (thinkpad_id
.ec_model
) {
5748 * Direct EC access mode: sensors at registers
5749 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5750 * non-implemented, thermal sensors return 0x80 when
5755 for (i
= 0; i
< 8; i
++) {
5756 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5762 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5770 /* This is sheer paranoia, but we handle it anyway */
5773 "ThinkPad ACPI EC access misbehaving, "
5774 "falling back to ACPI TMPx access "
5776 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5779 "ThinkPad ACPI EC access misbehaving, "
5780 "disabling thermal sensors access\n");
5781 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5786 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5788 } else if (acpi_tmp7
) {
5789 if (tpacpi_is_ibm() &&
5790 acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5791 /* 600e/x, 770e, 770x */
5792 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5794 /* IBM/LENOVO DSDT EC.TMPx access, max 8 sensors */
5795 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5798 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5799 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5802 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5803 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5806 switch (thermal_read_mode
) {
5807 case TPACPI_THERMAL_TPEC_16
:
5808 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5809 &thermal_temp_input16_group
);
5813 case TPACPI_THERMAL_TPEC_8
:
5814 case TPACPI_THERMAL_ACPI_TMP07
:
5815 case TPACPI_THERMAL_ACPI_UPDT
:
5816 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5817 &thermal_temp_input8_group
);
5821 case TPACPI_THERMAL_NONE
:
5829 static void thermal_exit(void)
5831 switch (thermal_read_mode
) {
5832 case TPACPI_THERMAL_TPEC_16
:
5833 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5834 &thermal_temp_input16_group
);
5836 case TPACPI_THERMAL_TPEC_8
:
5837 case TPACPI_THERMAL_ACPI_TMP07
:
5838 case TPACPI_THERMAL_ACPI_UPDT
:
5839 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5840 &thermal_temp_input8_group
);
5842 case TPACPI_THERMAL_NONE
:
5848 static int thermal_read(struct seq_file
*m
)
5851 struct ibm_thermal_sensors_struct t
;
5853 n
= thermal_get_sensors(&t
);
5854 if (unlikely(n
< 0))
5857 seq_printf(m
, "temperatures:\t");
5860 for (i
= 0; i
< (n
- 1); i
++)
5861 seq_printf(m
, "%d ", t
.temp
[i
] / 1000);
5862 seq_printf(m
, "%d\n", t
.temp
[i
] / 1000);
5864 seq_printf(m
, "not supported\n");
5869 static struct ibm_struct thermal_driver_data
= {
5871 .read
= thermal_read
,
5872 .exit
= thermal_exit
,
5875 /*************************************************************************
5879 static u8 ecdump_regs
[256];
5881 static int ecdump_read(struct seq_file
*m
)
5887 " +00 +01 +02 +03 +04 +05 +06 +07"
5888 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5889 for (i
= 0; i
< 256; i
+= 16) {
5890 seq_printf(m
, "EC 0x%02x:", i
);
5891 for (j
= 0; j
< 16; j
++) {
5892 if (!acpi_ec_read(i
+ j
, &v
))
5894 if (v
!= ecdump_regs
[i
+ j
])
5895 seq_printf(m
, " *%02x", v
);
5897 seq_printf(m
, " %02x", v
);
5898 ecdump_regs
[i
+ j
] = v
;
5905 /* These are way too dangerous to advertise openly... */
5907 seq_printf(m
, "commands:\t0x<offset> 0x<value>"
5908 " (<offset> is 00-ff, <value> is 00-ff)\n");
5909 seq_printf(m
, "commands:\t0x<offset> <value> "
5910 " (<offset> is 00-ff, <value> is 0-255)\n");
5915 static int ecdump_write(char *buf
)
5920 while ((cmd
= next_cmd(&buf
))) {
5921 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5923 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5927 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5928 if (!acpi_ec_write(i
, v
))
5937 static struct ibm_struct ecdump_driver_data
= {
5939 .read
= ecdump_read
,
5940 .write
= ecdump_write
,
5941 .flags
.experimental
= 1,
5944 /*************************************************************************
5945 * Backlight/brightness subdriver
5948 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5951 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5952 * CMOS NVRAM byte 0x5E, bits 0-3.
5954 * EC HBRV (0x31) has the following layout
5955 * Bit 7: unknown function
5956 * Bit 6: unknown function
5957 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5958 * Bit 4: must be set to zero to avoid problems
5959 * Bit 3-0: backlight brightness level
5961 * brightness_get_raw returns status data in the HBRV layout
5963 * WARNING: The X61 has been verified to use HBRV for something else, so
5964 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5965 * testing on the very early *60 Lenovo models...
5969 TP_EC_BACKLIGHT
= 0x31,
5971 /* TP_EC_BACKLIGHT bitmasks */
5972 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5973 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5974 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5977 enum tpacpi_brightness_access_mode
{
5978 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5979 TPACPI_BRGHT_MODE_EC
, /* EC control */
5980 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5981 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5982 TPACPI_BRGHT_MODE_MAX
5985 static struct backlight_device
*ibm_backlight_device
;
5987 static enum tpacpi_brightness_access_mode brightness_mode
=
5988 TPACPI_BRGHT_MODE_MAX
;
5990 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5992 static struct mutex brightness_mutex
;
5994 /* NVRAM brightness access,
5995 * call with brightness_mutex held! */
5996 static unsigned int tpacpi_brightness_nvram_get(void)
6000 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
6001 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
6002 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
6003 lnvram
&= bright_maxlvl
;
6008 static void tpacpi_brightness_checkpoint_nvram(void)
6013 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
6016 vdbg_printk(TPACPI_DBG_BRGHT
,
6017 "trying to checkpoint backlight level to NVRAM...\n");
6019 if (mutex_lock_killable(&brightness_mutex
) < 0)
6022 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6024 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
6025 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
6027 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
6028 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
6029 /* NVRAM needs update */
6030 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
6031 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
6033 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
6034 dbg_printk(TPACPI_DBG_BRGHT
,
6035 "updated NVRAM backlight level to %u (0x%02x)\n",
6036 (unsigned int) lec
, (unsigned int) b_nvram
);
6038 vdbg_printk(TPACPI_DBG_BRGHT
,
6039 "NVRAM backlight level already is %u (0x%02x)\n",
6040 (unsigned int) lec
, (unsigned int) b_nvram
);
6043 mutex_unlock(&brightness_mutex
);
6047 /* call with brightness_mutex held! */
6048 static int tpacpi_brightness_get_raw(int *status
)
6052 switch (brightness_mode
) {
6053 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6054 *status
= tpacpi_brightness_nvram_get();
6056 case TPACPI_BRGHT_MODE_EC
:
6057 case TPACPI_BRGHT_MODE_ECNVRAM
:
6058 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6067 /* call with brightness_mutex held! */
6068 /* do NOT call with illegal backlight level value */
6069 static int tpacpi_brightness_set_ec(unsigned int value
)
6073 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6076 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
6077 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
6078 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
6084 /* call with brightness_mutex held! */
6085 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
6088 unsigned int current_value
, i
;
6090 current_value
= tpacpi_brightness_nvram_get();
6092 if (value
== current_value
)
6095 cmos_cmd
= (value
> current_value
) ?
6096 TP_CMOS_BRIGHTNESS_UP
:
6097 TP_CMOS_BRIGHTNESS_DOWN
;
6098 inc
= (value
> current_value
) ? 1 : -1;
6100 for (i
= current_value
; i
!= value
; i
+= inc
)
6101 if (issue_thinkpad_cmos_command(cmos_cmd
))
6107 /* May return EINTR which can always be mapped to ERESTARTSYS */
6108 static int brightness_set(unsigned int value
)
6112 if (value
> bright_maxlvl
|| value
< 0)
6115 vdbg_printk(TPACPI_DBG_BRGHT
,
6116 "set backlight level to %d\n", value
);
6118 res
= mutex_lock_killable(&brightness_mutex
);
6122 switch (brightness_mode
) {
6123 case TPACPI_BRGHT_MODE_EC
:
6124 case TPACPI_BRGHT_MODE_ECNVRAM
:
6125 res
= tpacpi_brightness_set_ec(value
);
6127 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6128 res
= tpacpi_brightness_set_ucmsstep(value
);
6134 mutex_unlock(&brightness_mutex
);
6138 /* sysfs backlight class ----------------------------------------------- */
6140 static int brightness_update_status(struct backlight_device
*bd
)
6142 unsigned int level
=
6143 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
6144 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
6145 bd
->props
.brightness
: 0;
6147 dbg_printk(TPACPI_DBG_BRGHT
,
6148 "backlight: attempt to set level to %d\n",
6151 /* it is the backlight class's job (caller) to handle
6152 * EINTR and other errors properly */
6153 return brightness_set(level
);
6156 static int brightness_get(struct backlight_device
*bd
)
6160 res
= mutex_lock_killable(&brightness_mutex
);
6164 res
= tpacpi_brightness_get_raw(&status
);
6166 mutex_unlock(&brightness_mutex
);
6171 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6174 static void tpacpi_brightness_notify_change(void)
6176 backlight_force_update(ibm_backlight_device
,
6177 BACKLIGHT_UPDATE_HOTKEY
);
6180 static const struct backlight_ops ibm_backlight_data
= {
6181 .get_brightness
= brightness_get
,
6182 .update_status
= brightness_update_status
,
6185 /* --------------------------------------------------------------------- */
6188 * Call _BCL method of video device. On some ThinkPads this will
6189 * switch the firmware to the ACPI brightness control mode.
6192 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
6194 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
6195 union acpi_object
*obj
;
6198 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, "_BCL", NULL
, &buffer
))) {
6199 obj
= (union acpi_object
*)buffer
.pointer
;
6200 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
6201 printk(TPACPI_ERR
"Unknown _BCL data, "
6202 "please report this to %s\n", TPACPI_MAIL
);
6205 rc
= obj
->package
.count
;
6211 kfree(buffer
.pointer
);
6217 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
6219 static unsigned int __init
tpacpi_check_std_acpi_brightness_support(void)
6221 acpi_handle video_device
;
6224 tpacpi_acpi_handle_locate("video", ACPI_VIDEO_HID
, &video_device
);
6226 bcl_levels
= tpacpi_query_bcl_levels(video_device
);
6228 tp_features
.bright_acpimode
= (bcl_levels
> 0);
6230 return (bcl_levels
> 2) ? (bcl_levels
- 2) : 0;
6234 * These are only useful for models that have only one possibility
6235 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6238 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6239 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6240 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6242 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6243 /* Models with ATI GPUs known to require ECNVRAM mode */
6244 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6246 /* Models with ATI GPUs that can use ECNVRAM */
6247 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
), /* R50,51 T40-42 */
6248 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6249 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC
), /* R52 */
6250 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6252 /* Models with Intel Extreme Graphics 2 */
6253 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
), /* X40 */
6254 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6255 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6257 /* Models with Intel GMA900 */
6258 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6259 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6260 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6264 * Returns < 0 for error, otherwise sets tp_features.bright_*
6265 * and bright_maxlvl.
6267 static void __init
tpacpi_detect_brightness_capabilities(void)
6271 vdbg_printk(TPACPI_DBG_INIT
,
6272 "detecting firmware brightness interface capabilities\n");
6274 /* we could run a quirks check here (same table used by
6275 * brightness_init) if needed */
6278 * We always attempt to detect acpi support, so as to switch
6279 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6280 * going to publish a backlight interface
6282 b
= tpacpi_check_std_acpi_brightness_support();
6287 "detected a 16-level brightness capable ThinkPad\n");
6293 "detected a 8-level brightness capable ThinkPad\n");
6297 "Unsupported brightness interface, "
6298 "please contact %s\n", TPACPI_MAIL
);
6299 tp_features
.bright_unkfw
= 1;
6300 bright_maxlvl
= b
- 1;
6304 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6306 struct backlight_properties props
;
6308 unsigned long quirks
;
6310 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6312 mutex_init(&brightness_mutex
);
6314 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6315 ARRAY_SIZE(brightness_quirk_table
));
6317 /* tpacpi_detect_brightness_capabilities() must have run already */
6319 /* if it is unknown, we don't handle it: it wouldn't be safe */
6320 if (tp_features
.bright_unkfw
)
6323 if (!brightness_enable
) {
6324 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6325 "brightness support disabled by "
6326 "module parameter\n");
6330 if (acpi_video_backlight_support()) {
6331 if (brightness_enable
> 1) {
6333 "Standard ACPI backlight interface "
6334 "available, not loading native one.\n");
6336 } else if (brightness_enable
== 1) {
6338 "Cannot enable backlight brightness support, "
6339 "ACPI is already handling it. Refer to the "
6340 "acpi_backlight kernel parameter\n");
6343 } else if (tp_features
.bright_acpimode
&& brightness_enable
> 1) {
6344 printk(TPACPI_NOTICE
6345 "Standard ACPI backlight interface not "
6346 "available, thinkpad_acpi native "
6347 "brightness control enabled\n");
6351 * Check for module parameter bogosity, note that we
6352 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6353 * able to detect "unspecified"
6355 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6358 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6359 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6360 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6361 if (quirks
& TPACPI_BRGHT_Q_EC
)
6362 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6364 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6366 dbg_printk(TPACPI_DBG_BRGHT
,
6367 "driver auto-selected brightness_mode=%d\n",
6372 if (!tpacpi_is_ibm() &&
6373 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6374 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6377 if (tpacpi_brightness_get_raw(&b
) < 0)
6380 memset(&props
, 0, sizeof(struct backlight_properties
));
6381 props
.max_brightness
= bright_maxlvl
;
6382 props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6383 ibm_backlight_device
= backlight_device_register(TPACPI_BACKLIGHT_DEV_NAME
,
6385 &ibm_backlight_data
,
6387 if (IS_ERR(ibm_backlight_device
)) {
6388 int rc
= PTR_ERR(ibm_backlight_device
);
6389 ibm_backlight_device
= NULL
;
6390 printk(TPACPI_ERR
"Could not register backlight device\n");
6393 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6394 "brightness is supported\n");
6396 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6397 printk(TPACPI_NOTICE
6398 "brightness: will use unverified default: "
6399 "brightness_mode=%d\n", brightness_mode
);
6400 printk(TPACPI_NOTICE
6401 "brightness: please report to %s whether it works well "
6402 "or not on your ThinkPad\n", TPACPI_MAIL
);
6405 /* Added by mistake in early 2007. Probably useless, but it could
6406 * be working around some unknown firmware problem where the value
6407 * read at startup doesn't match the real hardware state... so leave
6408 * it in place just in case */
6409 backlight_update_status(ibm_backlight_device
);
6411 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6412 "brightness: registering brightness hotkeys "
6413 "as change notification\n");
6414 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6415 | TP_ACPI_HKEY_BRGHTUP_MASK
6416 | TP_ACPI_HKEY_BRGHTDWN_MASK
);
6420 static void brightness_suspend(pm_message_t state
)
6422 tpacpi_brightness_checkpoint_nvram();
6425 static void brightness_shutdown(void)
6427 tpacpi_brightness_checkpoint_nvram();
6430 static void brightness_exit(void)
6432 if (ibm_backlight_device
) {
6433 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6434 "calling backlight_device_unregister()\n");
6435 backlight_device_unregister(ibm_backlight_device
);
6438 tpacpi_brightness_checkpoint_nvram();
6441 static int brightness_read(struct seq_file
*m
)
6445 level
= brightness_get(NULL
);
6447 seq_printf(m
, "level:\t\tunreadable\n");
6449 seq_printf(m
, "level:\t\t%d\n", level
);
6450 seq_printf(m
, "commands:\tup, down\n");
6451 seq_printf(m
, "commands:\tlevel <level> (<level> is 0-%d)\n",
6458 static int brightness_write(char *buf
)
6464 level
= brightness_get(NULL
);
6468 while ((cmd
= next_cmd(&buf
))) {
6469 if (strlencmp(cmd
, "up") == 0) {
6470 if (level
< bright_maxlvl
)
6472 } else if (strlencmp(cmd
, "down") == 0) {
6475 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6476 level
>= 0 && level
<= bright_maxlvl
) {
6482 tpacpi_disclose_usertask("procfs brightness",
6483 "set level to %d\n", level
);
6486 * Now we know what the final level should be, so we try to set it.
6487 * Doing it this way makes the syscall restartable in case of EINTR
6489 rc
= brightness_set(level
);
6490 if (!rc
&& ibm_backlight_device
)
6491 backlight_force_update(ibm_backlight_device
,
6492 BACKLIGHT_UPDATE_SYSFS
);
6493 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6496 static struct ibm_struct brightness_driver_data
= {
6497 .name
= "brightness",
6498 .read
= brightness_read
,
6499 .write
= brightness_write
,
6500 .exit
= brightness_exit
,
6501 .suspend
= brightness_suspend
,
6502 .shutdown
= brightness_shutdown
,
6505 /*************************************************************************
6510 * IBM ThinkPads have a simple volume controller with MUTE gating.
6511 * Very early Lenovo ThinkPads follow the IBM ThinkPad spec.
6513 * Since the *61 series (and probably also the later *60 series), Lenovo
6514 * ThinkPads only implement the MUTE gate.
6517 * Bit 6: MUTE (1 mutes sound)
6519 * Other bits should be zero as far as we know.
6521 * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and
6522 * bits 3-0 (volume). Other bits in NVRAM may have other functions,
6523 * such as bit 7 which is used to detect repeated presses of MUTE,
6524 * and we leave them unchanged.
6527 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
6529 #define TPACPI_ALSA_DRVNAME "ThinkPad EC"
6530 #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control"
6531 #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME
6533 static int alsa_index
= ~((1 << (SNDRV_CARDS
- 3)) - 1); /* last three slots */
6534 static char *alsa_id
= "ThinkPadEC";
6535 static int alsa_enable
= SNDRV_DEFAULT_ENABLE1
;
6537 struct tpacpi_alsa_data
{
6538 struct snd_card
*card
;
6539 struct snd_ctl_elem_id
*ctl_mute_id
;
6540 struct snd_ctl_elem_id
*ctl_vol_id
;
6543 static struct snd_card
*alsa_card
;
6548 /* TP_EC_AUDIO bits */
6549 TP_EC_AUDIO_MUTESW
= 6,
6551 /* TP_EC_AUDIO bitmasks */
6552 TP_EC_AUDIO_LVL_MSK
= 0x0F,
6553 TP_EC_AUDIO_MUTESW_MSK
= (1 << TP_EC_AUDIO_MUTESW
),
6555 /* Maximum volume */
6556 TP_EC_VOLUME_MAX
= 14,
6559 enum tpacpi_volume_access_mode
{
6560 TPACPI_VOL_MODE_AUTO
= 0, /* Not implemented yet */
6561 TPACPI_VOL_MODE_EC
, /* Pure EC control */
6562 TPACPI_VOL_MODE_UCMS_STEP
, /* UCMS step-based control: N/A */
6563 TPACPI_VOL_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
6567 enum tpacpi_volume_capabilities
{
6568 TPACPI_VOL_CAP_AUTO
= 0, /* Use white/blacklist */
6569 TPACPI_VOL_CAP_VOLMUTE
, /* Output vol and mute */
6570 TPACPI_VOL_CAP_MUTEONLY
, /* Output mute only */
6574 static enum tpacpi_volume_access_mode volume_mode
=
6575 TPACPI_VOL_MODE_MAX
;
6577 static enum tpacpi_volume_capabilities volume_capabilities
;
6578 static int volume_control_allowed
;
6581 * Used to syncronize writers to TP_EC_AUDIO and
6582 * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write
6584 static struct mutex volume_mutex
;
6586 static void tpacpi_volume_checkpoint_nvram(void)
6592 if (volume_mode
!= TPACPI_VOL_MODE_ECNVRAM
)
6594 if (!volume_control_allowed
)
6597 vdbg_printk(TPACPI_DBG_MIXER
,
6598 "trying to checkpoint mixer state to NVRAM...\n");
6600 if (tp_features
.mixer_no_level_control
)
6601 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
;
6603 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
| TP_EC_AUDIO_LVL_MSK
;
6605 if (mutex_lock_killable(&volume_mutex
) < 0)
6608 if (unlikely(!acpi_ec_read(TP_EC_AUDIO
, &lec
)))
6611 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
6613 if (lec
!= (b_nvram
& ec_mask
)) {
6614 /* NVRAM needs update */
6615 b_nvram
&= ~ec_mask
;
6617 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_MIXER
);
6618 dbg_printk(TPACPI_DBG_MIXER
,
6619 "updated NVRAM mixer status to 0x%02x (0x%02x)\n",
6620 (unsigned int) lec
, (unsigned int) b_nvram
);
6622 vdbg_printk(TPACPI_DBG_MIXER
,
6623 "NVRAM mixer status already is 0x%02x (0x%02x)\n",
6624 (unsigned int) lec
, (unsigned int) b_nvram
);
6628 mutex_unlock(&volume_mutex
);
6631 static int volume_get_status_ec(u8
*status
)
6635 if (!acpi_ec_read(TP_EC_AUDIO
, &s
))
6640 dbg_printk(TPACPI_DBG_MIXER
, "status 0x%02x\n", s
);
6645 static int volume_get_status(u8
*status
)
6647 return volume_get_status_ec(status
);
6650 static int volume_set_status_ec(const u8 status
)
6652 if (!acpi_ec_write(TP_EC_AUDIO
, status
))
6655 dbg_printk(TPACPI_DBG_MIXER
, "set EC mixer to 0x%02x\n", status
);
6660 static int volume_set_status(const u8 status
)
6662 return volume_set_status_ec(status
);
6665 /* returns < 0 on error, 0 on no change, 1 on change */
6666 static int __volume_set_mute_ec(const bool mute
)
6671 if (mutex_lock_killable(&volume_mutex
) < 0)
6674 rc
= volume_get_status_ec(&s
);
6678 n
= (mute
) ? s
| TP_EC_AUDIO_MUTESW_MSK
:
6679 s
& ~TP_EC_AUDIO_MUTESW_MSK
;
6682 rc
= volume_set_status_ec(n
);
6688 mutex_unlock(&volume_mutex
);
6692 static int volume_alsa_set_mute(const bool mute
)
6694 dbg_printk(TPACPI_DBG_MIXER
, "ALSA: trying to %smute\n",
6695 (mute
) ? "" : "un");
6696 return __volume_set_mute_ec(mute
);
6699 static int volume_set_mute(const bool mute
)
6703 dbg_printk(TPACPI_DBG_MIXER
, "trying to %smute\n",
6704 (mute
) ? "" : "un");
6706 rc
= __volume_set_mute_ec(mute
);
6707 return (rc
< 0) ? rc
: 0;
6710 /* returns < 0 on error, 0 on no change, 1 on change */
6711 static int __volume_set_volume_ec(const u8 vol
)
6716 if (vol
> TP_EC_VOLUME_MAX
)
6719 if (mutex_lock_killable(&volume_mutex
) < 0)
6722 rc
= volume_get_status_ec(&s
);
6726 n
= (s
& ~TP_EC_AUDIO_LVL_MSK
) | vol
;
6729 rc
= volume_set_status_ec(n
);
6735 mutex_unlock(&volume_mutex
);
6739 static int volume_alsa_set_volume(const u8 vol
)
6741 dbg_printk(TPACPI_DBG_MIXER
,
6742 "ALSA: trying to set volume level to %hu\n", vol
);
6743 return __volume_set_volume_ec(vol
);
6746 static void volume_alsa_notify_change(void)
6748 struct tpacpi_alsa_data
*d
;
6750 if (alsa_card
&& alsa_card
->private_data
) {
6751 d
= alsa_card
->private_data
;
6753 snd_ctl_notify(alsa_card
,
6754 SNDRV_CTL_EVENT_MASK_VALUE
,
6757 snd_ctl_notify(alsa_card
,
6758 SNDRV_CTL_EVENT_MASK_VALUE
,
6763 static int volume_alsa_vol_info(struct snd_kcontrol
*kcontrol
,
6764 struct snd_ctl_elem_info
*uinfo
)
6766 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
6768 uinfo
->value
.integer
.min
= 0;
6769 uinfo
->value
.integer
.max
= TP_EC_VOLUME_MAX
;
6773 static int volume_alsa_vol_get(struct snd_kcontrol
*kcontrol
,
6774 struct snd_ctl_elem_value
*ucontrol
)
6779 rc
= volume_get_status(&s
);
6783 ucontrol
->value
.integer
.value
[0] = s
& TP_EC_AUDIO_LVL_MSK
;
6787 static int volume_alsa_vol_put(struct snd_kcontrol
*kcontrol
,
6788 struct snd_ctl_elem_value
*ucontrol
)
6790 tpacpi_disclose_usertask("ALSA", "set volume to %ld\n",
6791 ucontrol
->value
.integer
.value
[0]);
6792 return volume_alsa_set_volume(ucontrol
->value
.integer
.value
[0]);
6795 #define volume_alsa_mute_info snd_ctl_boolean_mono_info
6797 static int volume_alsa_mute_get(struct snd_kcontrol
*kcontrol
,
6798 struct snd_ctl_elem_value
*ucontrol
)
6803 rc
= volume_get_status(&s
);
6807 ucontrol
->value
.integer
.value
[0] =
6808 (s
& TP_EC_AUDIO_MUTESW_MSK
) ? 0 : 1;
6812 static int volume_alsa_mute_put(struct snd_kcontrol
*kcontrol
,
6813 struct snd_ctl_elem_value
*ucontrol
)
6815 tpacpi_disclose_usertask("ALSA", "%smute\n",
6816 ucontrol
->value
.integer
.value
[0] ?
6818 return volume_alsa_set_mute(!ucontrol
->value
.integer
.value
[0]);
6821 static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata
= {
6822 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6823 .name
= "Console Playback Volume",
6825 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6826 .info
= volume_alsa_vol_info
,
6827 .get
= volume_alsa_vol_get
,
6830 static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata
= {
6831 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6832 .name
= "Console Playback Switch",
6834 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6835 .info
= volume_alsa_mute_info
,
6836 .get
= volume_alsa_mute_get
,
6839 static void volume_suspend(pm_message_t state
)
6841 tpacpi_volume_checkpoint_nvram();
6844 static void volume_resume(void)
6846 volume_alsa_notify_change();
6849 static void volume_shutdown(void)
6851 tpacpi_volume_checkpoint_nvram();
6854 static void volume_exit(void)
6857 snd_card_free(alsa_card
);
6861 tpacpi_volume_checkpoint_nvram();
6864 static int __init
volume_create_alsa_mixer(void)
6866 struct snd_card
*card
;
6867 struct tpacpi_alsa_data
*data
;
6868 struct snd_kcontrol
*ctl_vol
;
6869 struct snd_kcontrol
*ctl_mute
;
6872 rc
= snd_card_create(alsa_index
, alsa_id
, THIS_MODULE
,
6873 sizeof(struct tpacpi_alsa_data
), &card
);
6874 if (rc
< 0 || !card
) {
6876 "Failed to create ALSA card structures: %d\n", rc
);
6880 BUG_ON(!card
->private_data
);
6881 data
= card
->private_data
;
6884 strlcpy(card
->driver
, TPACPI_ALSA_DRVNAME
,
6885 sizeof(card
->driver
));
6886 strlcpy(card
->shortname
, TPACPI_ALSA_SHRTNAME
,
6887 sizeof(card
->shortname
));
6888 snprintf(card
->mixername
, sizeof(card
->mixername
), "ThinkPad EC %s",
6889 (thinkpad_id
.ec_version_str
) ?
6890 thinkpad_id
.ec_version_str
: "(unknown)");
6891 snprintf(card
->longname
, sizeof(card
->longname
),
6892 "%s at EC reg 0x%02x, fw %s", card
->shortname
, TP_EC_AUDIO
,
6893 (thinkpad_id
.ec_version_str
) ?
6894 thinkpad_id
.ec_version_str
: "unknown");
6896 if (volume_control_allowed
) {
6897 volume_alsa_control_vol
.put
= volume_alsa_vol_put
;
6898 volume_alsa_control_vol
.access
=
6899 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6901 volume_alsa_control_mute
.put
= volume_alsa_mute_put
;
6902 volume_alsa_control_mute
.access
=
6903 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6906 if (!tp_features
.mixer_no_level_control
) {
6907 ctl_vol
= snd_ctl_new1(&volume_alsa_control_vol
, NULL
);
6908 rc
= snd_ctl_add(card
, ctl_vol
);
6911 "Failed to create ALSA volume control: %d\n",
6915 data
->ctl_vol_id
= &ctl_vol
->id
;
6918 ctl_mute
= snd_ctl_new1(&volume_alsa_control_mute
, NULL
);
6919 rc
= snd_ctl_add(card
, ctl_mute
);
6921 printk(TPACPI_ERR
"Failed to create ALSA mute control: %d\n",
6925 data
->ctl_mute_id
= &ctl_mute
->id
;
6927 snd_card_set_dev(card
, &tpacpi_pdev
->dev
);
6928 rc
= snd_card_register(card
);
6930 printk(TPACPI_ERR
"Failed to register ALSA card: %d\n", rc
);
6938 snd_card_free(card
);
6942 #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */
6943 #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */
6945 static const struct tpacpi_quirk volume_quirk_table
[] __initconst
= {
6946 /* Whitelist volume level on all IBM by default */
6947 { .vendor
= PCI_VENDOR_ID_IBM
,
6948 .bios
= TPACPI_MATCH_ANY
,
6949 .ec
= TPACPI_MATCH_ANY
,
6950 .quirks
= TPACPI_VOL_Q_LEVEL
},
6952 /* Lenovo models with volume control (needs confirmation) */
6953 TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL
), /* R60/i */
6954 TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL
), /* R60e/i */
6955 TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL
), /* T60/p */
6956 TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL
), /* X60/s */
6957 TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL
), /* X60t */
6958 TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL
), /* Z60 */
6959 TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL
), /* Z61 */
6961 /* Whitelist mute-only on all Lenovo by default */
6962 { .vendor
= PCI_VENDOR_ID_LENOVO
,
6963 .bios
= TPACPI_MATCH_ANY
,
6964 .ec
= TPACPI_MATCH_ANY
,
6965 .quirks
= TPACPI_VOL_Q_MUTEONLY
}
6968 static int __init
volume_init(struct ibm_init_struct
*iibm
)
6970 unsigned long quirks
;
6973 vdbg_printk(TPACPI_DBG_INIT
, "initializing volume subdriver\n");
6975 mutex_init(&volume_mutex
);
6978 * Check for module parameter bogosity, note that we
6979 * init volume_mode to TPACPI_VOL_MODE_MAX in order to be
6980 * able to detect "unspecified"
6982 if (volume_mode
> TPACPI_VOL_MODE_MAX
)
6985 if (volume_mode
== TPACPI_VOL_MODE_UCMS_STEP
) {
6987 "UCMS step volume mode not implemented, "
6988 "please contact %s\n", TPACPI_MAIL
);
6992 if (volume_capabilities
>= TPACPI_VOL_CAP_MAX
)
6996 * The ALSA mixer is our primary interface.
6997 * When disabled, don't install the subdriver at all
7000 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
7001 "ALSA mixer disabled by parameter, "
7002 "not loading volume subdriver...\n");
7006 quirks
= tpacpi_check_quirks(volume_quirk_table
,
7007 ARRAY_SIZE(volume_quirk_table
));
7009 switch (volume_capabilities
) {
7010 case TPACPI_VOL_CAP_AUTO
:
7011 if (quirks
& TPACPI_VOL_Q_MUTEONLY
)
7012 tp_features
.mixer_no_level_control
= 1;
7013 else if (quirks
& TPACPI_VOL_Q_LEVEL
)
7014 tp_features
.mixer_no_level_control
= 0;
7016 return 1; /* no mixer */
7018 case TPACPI_VOL_CAP_VOLMUTE
:
7019 tp_features
.mixer_no_level_control
= 0;
7021 case TPACPI_VOL_CAP_MUTEONLY
:
7022 tp_features
.mixer_no_level_control
= 1;
7028 if (volume_capabilities
!= TPACPI_VOL_CAP_AUTO
)
7029 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
7030 "using user-supplied volume_capabilities=%d\n",
7031 volume_capabilities
);
7033 if (volume_mode
== TPACPI_VOL_MODE_AUTO
||
7034 volume_mode
== TPACPI_VOL_MODE_MAX
) {
7035 volume_mode
= TPACPI_VOL_MODE_ECNVRAM
;
7037 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
7038 "driver auto-selected volume_mode=%d\n",
7041 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
7042 "using user-supplied volume_mode=%d\n",
7046 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
7047 "mute is supported, volume control is %s\n",
7048 str_supported(!tp_features
.mixer_no_level_control
));
7050 rc
= volume_create_alsa_mixer();
7053 "Could not create the ALSA mixer interface\n");
7058 "Console audio control enabled, mode: %s\n",
7059 (volume_control_allowed
) ?
7060 "override (read/write)" :
7061 "monitor (read only)");
7063 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
7064 "registering volume hotkeys as change notification\n");
7065 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
7066 | TP_ACPI_HKEY_VOLUP_MASK
7067 | TP_ACPI_HKEY_VOLDWN_MASK
7068 | TP_ACPI_HKEY_MUTE_MASK
);
7073 static int volume_read(struct seq_file
*m
)
7077 if (volume_get_status(&status
) < 0) {
7078 seq_printf(m
, "level:\t\tunreadable\n");
7080 if (tp_features
.mixer_no_level_control
)
7081 seq_printf(m
, "level:\t\tunsupported\n");
7083 seq_printf(m
, "level:\t\t%d\n",
7084 status
& TP_EC_AUDIO_LVL_MSK
);
7086 seq_printf(m
, "mute:\t\t%s\n",
7087 onoff(status
, TP_EC_AUDIO_MUTESW
));
7089 if (volume_control_allowed
) {
7090 seq_printf(m
, "commands:\tunmute, mute\n");
7091 if (!tp_features
.mixer_no_level_control
) {
7093 "commands:\tup, down\n");
7095 "commands:\tlevel <level>"
7096 " (<level> is 0-%d)\n",
7105 static int volume_write(char *buf
)
7108 u8 new_level
, new_mute
;
7114 * We do allow volume control at driver startup, so that the
7115 * user can set initial state through the volume=... parameter hack.
7117 if (!volume_control_allowed
&& tpacpi_lifecycle
!= TPACPI_LIFE_INIT
) {
7118 if (unlikely(!tp_warned
.volume_ctrl_forbidden
)) {
7119 tp_warned
.volume_ctrl_forbidden
= 1;
7120 printk(TPACPI_NOTICE
7121 "Console audio control in monitor mode, "
7122 "changes are not allowed.\n");
7123 printk(TPACPI_NOTICE
7124 "Use the volume_control=1 module parameter "
7125 "to enable volume control\n");
7130 rc
= volume_get_status(&s
);
7134 new_level
= s
& TP_EC_AUDIO_LVL_MSK
;
7135 new_mute
= s
& TP_EC_AUDIO_MUTESW_MSK
;
7137 while ((cmd
= next_cmd(&buf
))) {
7138 if (!tp_features
.mixer_no_level_control
) {
7139 if (strlencmp(cmd
, "up") == 0) {
7142 else if (new_level
< TP_EC_VOLUME_MAX
)
7145 } else if (strlencmp(cmd
, "down") == 0) {
7148 else if (new_level
> 0)
7151 } else if (sscanf(cmd
, "level %u", &l
) == 1 &&
7152 l
>= 0 && l
<= TP_EC_VOLUME_MAX
) {
7157 if (strlencmp(cmd
, "mute") == 0)
7158 new_mute
= TP_EC_AUDIO_MUTESW_MSK
;
7159 else if (strlencmp(cmd
, "unmute") == 0)
7165 if (tp_features
.mixer_no_level_control
) {
7166 tpacpi_disclose_usertask("procfs volume", "%smute\n",
7167 new_mute
? "" : "un");
7168 rc
= volume_set_mute(!!new_mute
);
7170 tpacpi_disclose_usertask("procfs volume",
7171 "%smute and set level to %d\n",
7172 new_mute
? "" : "un", new_level
);
7173 rc
= volume_set_status(new_mute
| new_level
);
7175 volume_alsa_notify_change();
7177 return (rc
== -EINTR
) ? -ERESTARTSYS
: rc
;
7180 static struct ibm_struct volume_driver_data
= {
7182 .read
= volume_read
,
7183 .write
= volume_write
,
7184 .exit
= volume_exit
,
7185 .suspend
= volume_suspend
,
7186 .resume
= volume_resume
,
7187 .shutdown
= volume_shutdown
,
7190 #else /* !CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
7192 #define alsa_card NULL
7194 static void inline volume_alsa_notify_change(void)
7198 static int __init
volume_init(struct ibm_init_struct
*iibm
)
7201 "volume: disabled as there is no ALSA support in this kernel\n");
7206 static struct ibm_struct volume_driver_data
= {
7210 #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
7212 /*************************************************************************
7219 * TPACPI_FAN_RD_ACPI_GFAN:
7220 * ACPI GFAN method: returns fan level
7222 * see TPACPI_FAN_WR_ACPI_SFAN
7223 * EC 0x2f (HFSP) not available if GFAN exists
7225 * TPACPI_FAN_WR_ACPI_SFAN:
7226 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
7228 * EC 0x2f (HFSP) might be available *for reading*, but do not use
7231 * TPACPI_FAN_WR_TPEC:
7232 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
7233 * Supported on almost all ThinkPads
7235 * Fan speed changes of any sort (including those caused by the
7236 * disengaged mode) are usually done slowly by the firmware as the
7237 * maximum amount of fan duty cycle change per second seems to be
7240 * Reading is not available if GFAN exists.
7241 * Writing is not available if SFAN exists.
7244 * 7 automatic mode engaged;
7245 * (default operation mode of the ThinkPad)
7246 * fan level is ignored in this mode.
7247 * 6 full speed mode (takes precedence over bit 7);
7248 * not available on all thinkpads. May disable
7249 * the tachometer while the fan controller ramps up
7250 * the speed (which can take up to a few *minutes*).
7251 * Speeds up fan to 100% duty-cycle, which is far above
7252 * the standard RPM levels. It is not impossible that
7253 * it could cause hardware damage.
7254 * 5-3 unused in some models. Extra bits for fan level
7255 * in others, but still useless as all values above
7256 * 7 map to the same speed as level 7 in these models.
7257 * 2-0 fan level (0..7 usually)
7259 * 0x07 = max (set when temperatures critical)
7260 * Some ThinkPads may have other levels, see
7261 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
7263 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
7264 * boot. Apparently the EC does not initialize it, so unless ACPI DSDT
7265 * does so, its initial value is meaningless (0x07).
7267 * For firmware bugs, refer to:
7268 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7272 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
7273 * Main fan tachometer reading (in RPM)
7275 * This register is present on all ThinkPads with a new-style EC, and
7276 * it is known not to be present on the A21m/e, and T22, as there is
7277 * something else in offset 0x84 according to the ACPI DSDT. Other
7278 * ThinkPads from this same time period (and earlier) probably lack the
7279 * tachometer as well.
7281 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
7282 * was never fixed by IBM to report the EC firmware version string
7283 * probably support the tachometer (like the early X models), so
7284 * detecting it is quite hard. We need more data to know for sure.
7286 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
7289 * FIRMWARE BUG: may go stale while the EC is switching to full speed
7292 * For firmware bugs, refer to:
7293 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7297 * ThinkPad EC register 0x31 bit 0 (only on select models)
7299 * When bit 0 of EC register 0x31 is zero, the tachometer registers
7300 * show the speed of the main fan. When bit 0 of EC register 0x31
7301 * is one, the tachometer registers show the speed of the auxiliary
7304 * Fan control seems to affect both fans, regardless of the state
7307 * So far, only the firmware for the X60/X61 non-tablet versions
7308 * seem to support this (firmware TP-7M).
7310 * TPACPI_FAN_WR_ACPI_FANS:
7311 * ThinkPad X31, X40, X41. Not available in the X60.
7313 * FANS ACPI handle: takes three arguments: low speed, medium speed,
7314 * high speed. ACPI DSDT seems to map these three speeds to levels
7315 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
7316 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
7318 * The speeds are stored on handles
7319 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
7321 * There are three default speed sets, accessible as handles:
7322 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
7324 * ACPI DSDT switches which set is in use depending on various
7327 * TPACPI_FAN_WR_TPEC is also available and should be used to
7328 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
7329 * but the ACPI tables just mention level 7.
7332 enum { /* Fan control constants */
7333 fan_status_offset
= 0x2f, /* EC register 0x2f */
7334 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
7335 * 0x84 must be read before 0x85 */
7336 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
7337 bit 0 selects which fan is active */
7339 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
7340 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
7342 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
7345 enum fan_status_access_mode
{
7346 TPACPI_FAN_NONE
= 0, /* No fan status or control */
7347 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
7348 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
7351 enum fan_control_access_mode
{
7352 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
7353 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
7354 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
7355 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
7358 enum fan_control_commands
{
7359 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
7360 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
7361 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
7362 * and also watchdog cmd */
7365 static int fan_control_allowed
;
7367 static enum fan_status_access_mode fan_status_access_mode
;
7368 static enum fan_control_access_mode fan_control_access_mode
;
7369 static enum fan_control_commands fan_control_commands
;
7371 static u8 fan_control_initial_status
;
7372 static u8 fan_control_desired_level
;
7373 static u8 fan_control_resume_level
;
7374 static int fan_watchdog_maxinterval
;
7376 static struct mutex fan_mutex
;
7378 static void fan_watchdog_fire(struct work_struct
*ignored
);
7379 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
7381 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
7382 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
7383 "\\FSPD", /* 600e/x, 770e, 770x */
7385 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
7386 "JFNS", /* 770x-JL */
7390 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
7391 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
7392 * be in auto mode (0x80).
7394 * This is corrected by any write to HFSP either by the driver, or
7397 * We assume 0x07 really means auto mode while this quirk is active,
7398 * as this is far more likely than the ThinkPad being in level 7,
7399 * which is only used by the firmware during thermal emergencies.
7401 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
7402 * TP-70 (T43, R52), which are known to be buggy.
7405 static void fan_quirk1_setup(void)
7407 if (fan_control_initial_status
== 0x07) {
7408 printk(TPACPI_NOTICE
7409 "fan_init: initial fan status is unknown, "
7410 "assuming it is in auto mode\n");
7411 tp_features
.fan_ctrl_status_undef
= 1;
7415 static void fan_quirk1_handle(u8
*fan_status
)
7417 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
7418 if (*fan_status
!= fan_control_initial_status
) {
7419 /* something changed the HFSP regisnter since
7420 * driver init time, so it is not undefined
7422 tp_features
.fan_ctrl_status_undef
= 0;
7424 /* Return most likely status. In fact, it
7425 * might be the only possible status */
7426 *fan_status
= TP_EC_FAN_AUTO
;
7431 /* Select main fan on X60/X61, NOOP on others */
7432 static bool fan_select_fan1(void)
7434 if (tp_features
.second_fan
) {
7437 if (ec_read(fan_select_offset
, &val
) < 0)
7440 if (ec_write(fan_select_offset
, val
) < 0)
7446 /* Select secondary fan on X60/X61 */
7447 static bool fan_select_fan2(void)
7451 if (!tp_features
.second_fan
)
7454 if (ec_read(fan_select_offset
, &val
) < 0)
7457 if (ec_write(fan_select_offset
, val
) < 0)
7464 * Call with fan_mutex held
7466 static void fan_update_desired_level(u8 status
)
7469 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7471 fan_control_desired_level
= 7;
7473 fan_control_desired_level
= status
;
7477 static int fan_get_status(u8
*status
)
7482 * Add TPACPI_FAN_RD_ACPI_FANS ? */
7484 switch (fan_status_access_mode
) {
7485 case TPACPI_FAN_RD_ACPI_GFAN
:
7486 /* 570, 600e/x, 770e, 770x */
7488 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
7496 case TPACPI_FAN_RD_TPEC
:
7497 /* all except 570, 600e/x, 770e, 770x */
7498 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
7501 if (likely(status
)) {
7503 fan_quirk1_handle(status
);
7515 static int fan_get_status_safe(u8
*status
)
7520 if (mutex_lock_killable(&fan_mutex
))
7521 return -ERESTARTSYS
;
7522 rc
= fan_get_status(&s
);
7524 fan_update_desired_level(s
);
7525 mutex_unlock(&fan_mutex
);
7533 static int fan_get_speed(unsigned int *speed
)
7537 switch (fan_status_access_mode
) {
7538 case TPACPI_FAN_RD_TPEC
:
7539 /* all except 570, 600e/x, 770e, 770x */
7540 if (unlikely(!fan_select_fan1()))
7542 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
7543 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
7547 *speed
= (hi
<< 8) | lo
;
7558 static int fan2_get_speed(unsigned int *speed
)
7563 switch (fan_status_access_mode
) {
7564 case TPACPI_FAN_RD_TPEC
:
7565 /* all except 570, 600e/x, 770e, 770x */
7566 if (unlikely(!fan_select_fan2()))
7568 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
7569 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
7570 fan_select_fan1(); /* play it safe */
7575 *speed
= (hi
<< 8) | lo
;
7586 static int fan_set_level(int level
)
7588 if (!fan_control_allowed
)
7591 switch (fan_control_access_mode
) {
7592 case TPACPI_FAN_WR_ACPI_SFAN
:
7593 if (level
>= 0 && level
<= 7) {
7594 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
7600 case TPACPI_FAN_WR_ACPI_FANS
:
7601 case TPACPI_FAN_WR_TPEC
:
7602 if (!(level
& TP_EC_FAN_AUTO
) &&
7603 !(level
& TP_EC_FAN_FULLSPEED
) &&
7604 ((level
< 0) || (level
> 7)))
7607 /* safety net should the EC not support AUTO
7608 * or FULLSPEED mode bits and just ignore them */
7609 if (level
& TP_EC_FAN_FULLSPEED
)
7610 level
|= 7; /* safety min speed 7 */
7611 else if (level
& TP_EC_FAN_AUTO
)
7612 level
|= 4; /* safety min speed 4 */
7614 if (!acpi_ec_write(fan_status_offset
, level
))
7617 tp_features
.fan_ctrl_status_undef
= 0;
7624 vdbg_printk(TPACPI_DBG_FAN
,
7625 "fan control: set fan control register to 0x%02x\n", level
);
7629 static int fan_set_level_safe(int level
)
7633 if (!fan_control_allowed
)
7636 if (mutex_lock_killable(&fan_mutex
))
7637 return -ERESTARTSYS
;
7639 if (level
== TPACPI_FAN_LAST_LEVEL
)
7640 level
= fan_control_desired_level
;
7642 rc
= fan_set_level(level
);
7644 fan_update_desired_level(level
);
7646 mutex_unlock(&fan_mutex
);
7650 static int fan_set_enable(void)
7655 if (!fan_control_allowed
)
7658 if (mutex_lock_killable(&fan_mutex
))
7659 return -ERESTARTSYS
;
7661 switch (fan_control_access_mode
) {
7662 case TPACPI_FAN_WR_ACPI_FANS
:
7663 case TPACPI_FAN_WR_TPEC
:
7664 rc
= fan_get_status(&s
);
7668 /* Don't go out of emergency fan mode */
7671 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
7674 if (!acpi_ec_write(fan_status_offset
, s
))
7677 tp_features
.fan_ctrl_status_undef
= 0;
7682 case TPACPI_FAN_WR_ACPI_SFAN
:
7683 rc
= fan_get_status(&s
);
7689 /* Set fan to at least level 4 */
7692 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
7702 mutex_unlock(&fan_mutex
);
7705 vdbg_printk(TPACPI_DBG_FAN
,
7706 "fan control: set fan control register to 0x%02x\n",
7711 static int fan_set_disable(void)
7715 if (!fan_control_allowed
)
7718 if (mutex_lock_killable(&fan_mutex
))
7719 return -ERESTARTSYS
;
7722 switch (fan_control_access_mode
) {
7723 case TPACPI_FAN_WR_ACPI_FANS
:
7724 case TPACPI_FAN_WR_TPEC
:
7725 if (!acpi_ec_write(fan_status_offset
, 0x00))
7728 fan_control_desired_level
= 0;
7729 tp_features
.fan_ctrl_status_undef
= 0;
7733 case TPACPI_FAN_WR_ACPI_SFAN
:
7734 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
7737 fan_control_desired_level
= 0;
7745 vdbg_printk(TPACPI_DBG_FAN
,
7746 "fan control: set fan control register to 0\n");
7748 mutex_unlock(&fan_mutex
);
7752 static int fan_set_speed(int speed
)
7756 if (!fan_control_allowed
)
7759 if (mutex_lock_killable(&fan_mutex
))
7760 return -ERESTARTSYS
;
7763 switch (fan_control_access_mode
) {
7764 case TPACPI_FAN_WR_ACPI_FANS
:
7765 if (speed
>= 0 && speed
<= 65535) {
7766 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
7767 speed
, speed
, speed
))
7777 mutex_unlock(&fan_mutex
);
7781 static void fan_watchdog_reset(void)
7783 static int fan_watchdog_active
;
7785 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
7788 if (fan_watchdog_active
)
7789 cancel_delayed_work(&fan_watchdog_task
);
7791 if (fan_watchdog_maxinterval
> 0 &&
7792 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
7793 fan_watchdog_active
= 1;
7794 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
7795 msecs_to_jiffies(fan_watchdog_maxinterval
7798 "failed to queue the fan watchdog, "
7799 "watchdog will not trigger\n");
7802 fan_watchdog_active
= 0;
7805 static void fan_watchdog_fire(struct work_struct
*ignored
)
7809 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
7812 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
7813 rc
= fan_set_enable();
7815 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
7816 "will try again later...\n", -rc
);
7817 /* reschedule for later */
7818 fan_watchdog_reset();
7823 * SYSFS fan layout: hwmon compatible (device)
7826 * 0: "disengaged" mode
7828 * 2: native EC "auto" mode (recommended, hardware default)
7830 * pwm*: set speed in manual mode, ignored otherwise.
7831 * 0 is level 0; 255 is level 7. Intermediate points done with linear
7834 * fan*_input: tachometer reading, RPM
7837 * SYSFS fan layout: extensions
7839 * fan_watchdog (driver):
7840 * fan watchdog interval in seconds, 0 disables (default), max 120
7843 /* sysfs fan pwm1_enable ----------------------------------------------- */
7844 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
7845 struct device_attribute
*attr
,
7851 res
= fan_get_status_safe(&status
);
7855 if (status
& TP_EC_FAN_FULLSPEED
) {
7857 } else if (status
& TP_EC_FAN_AUTO
) {
7862 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
7865 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7866 struct device_attribute
*attr
,
7867 const char *buf
, size_t count
)
7872 if (parse_strtoul(buf
, 2, &t
))
7875 tpacpi_disclose_usertask("hwmon pwm1_enable",
7876 "set fan mode to %lu\n", t
);
7880 level
= TP_EC_FAN_FULLSPEED
;
7883 level
= TPACPI_FAN_LAST_LEVEL
;
7886 level
= TP_EC_FAN_AUTO
;
7889 /* reserved for software-controlled auto mode */
7895 res
= fan_set_level_safe(level
);
7901 fan_watchdog_reset();
7906 static struct device_attribute dev_attr_fan_pwm1_enable
=
7907 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7908 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7910 /* sysfs fan pwm1 ------------------------------------------------------ */
7911 static ssize_t
fan_pwm1_show(struct device
*dev
,
7912 struct device_attribute
*attr
,
7918 res
= fan_get_status_safe(&status
);
7923 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7924 status
= fan_control_desired_level
;
7929 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7932 static ssize_t
fan_pwm1_store(struct device
*dev
,
7933 struct device_attribute
*attr
,
7934 const char *buf
, size_t count
)
7938 u8 status
, newlevel
;
7940 if (parse_strtoul(buf
, 255, &s
))
7943 tpacpi_disclose_usertask("hwmon pwm1",
7944 "set fan speed to %lu\n", s
);
7946 /* scale down from 0-255 to 0-7 */
7947 newlevel
= (s
>> 5) & 0x07;
7949 if (mutex_lock_killable(&fan_mutex
))
7950 return -ERESTARTSYS
;
7952 rc
= fan_get_status(&status
);
7953 if (!rc
&& (status
&
7954 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7955 rc
= fan_set_level(newlevel
);
7959 fan_update_desired_level(newlevel
);
7960 fan_watchdog_reset();
7964 mutex_unlock(&fan_mutex
);
7965 return (rc
)? rc
: count
;
7968 static struct device_attribute dev_attr_fan_pwm1
=
7969 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7970 fan_pwm1_show
, fan_pwm1_store
);
7972 /* sysfs fan fan1_input ------------------------------------------------ */
7973 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7974 struct device_attribute
*attr
,
7980 res
= fan_get_speed(&speed
);
7984 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7987 static struct device_attribute dev_attr_fan_fan1_input
=
7988 __ATTR(fan1_input
, S_IRUGO
,
7989 fan_fan1_input_show
, NULL
);
7991 /* sysfs fan fan2_input ------------------------------------------------ */
7992 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7993 struct device_attribute
*attr
,
7999 res
= fan2_get_speed(&speed
);
8003 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
8006 static struct device_attribute dev_attr_fan_fan2_input
=
8007 __ATTR(fan2_input
, S_IRUGO
,
8008 fan_fan2_input_show
, NULL
);
8010 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
8011 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
8014 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
8017 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
8018 const char *buf
, size_t count
)
8022 if (parse_strtoul(buf
, 120, &t
))
8025 if (!fan_control_allowed
)
8028 fan_watchdog_maxinterval
= t
;
8029 fan_watchdog_reset();
8031 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
8036 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
8037 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
8039 /* --------------------------------------------------------------------- */
8040 static struct attribute
*fan_attributes
[] = {
8041 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
8042 &dev_attr_fan_fan1_input
.attr
,
8043 NULL
, /* for fan2_input */
8047 static const struct attribute_group fan_attr_group
= {
8048 .attrs
= fan_attributes
,
8051 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
8052 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
8054 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
8055 { .vendor = PCI_VENDOR_ID_IBM, \
8056 .bios = TPACPI_MATCH_ANY, \
8057 .ec = TPID(__id1, __id2), \
8058 .quirks = __quirks }
8060 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
8061 { .vendor = PCI_VENDOR_ID_LENOVO, \
8062 .bios = TPACPI_MATCH_ANY, \
8063 .ec = TPID(__id1, __id2), \
8064 .quirks = __quirks }
8066 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
8067 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
8068 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
8069 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
8070 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
8071 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
8074 #undef TPACPI_FAN_QL
8075 #undef TPACPI_FAN_QI
8077 static int __init
fan_init(struct ibm_init_struct
*iibm
)
8080 unsigned long quirks
;
8082 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8083 "initializing fan subdriver\n");
8085 mutex_init(&fan_mutex
);
8086 fan_status_access_mode
= TPACPI_FAN_NONE
;
8087 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
8088 fan_control_commands
= 0;
8089 fan_watchdog_maxinterval
= 0;
8090 tp_features
.fan_ctrl_status_undef
= 0;
8091 tp_features
.second_fan
= 0;
8092 fan_control_desired_level
= 7;
8094 if (tpacpi_is_ibm()) {
8095 TPACPI_ACPIHANDLE_INIT(fans
);
8096 TPACPI_ACPIHANDLE_INIT(gfan
);
8097 TPACPI_ACPIHANDLE_INIT(sfan
);
8100 quirks
= tpacpi_check_quirks(fan_quirk_table
,
8101 ARRAY_SIZE(fan_quirk_table
));
8104 /* 570, 600e/x, 770e, 770x */
8105 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
8107 /* all other ThinkPads: note that even old-style
8108 * ThinkPad ECs supports the fan control register */
8109 if (likely(acpi_ec_read(fan_status_offset
,
8110 &fan_control_initial_status
))) {
8111 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
8112 if (quirks
& TPACPI_FAN_Q1
)
8114 if (quirks
& TPACPI_FAN_2FAN
) {
8115 tp_features
.second_fan
= 1;
8116 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8117 "secondary fan support enabled\n");
8121 "ThinkPad ACPI EC access misbehaving, "
8122 "fan status and control unavailable\n");
8129 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
8130 fan_control_commands
|=
8131 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
8134 /* gfan without sfan means no fan control */
8135 /* all other models implement TP EC 0x2f control */
8139 fan_control_access_mode
=
8140 TPACPI_FAN_WR_ACPI_FANS
;
8141 fan_control_commands
|=
8142 TPACPI_FAN_CMD_SPEED
|
8143 TPACPI_FAN_CMD_LEVEL
|
8144 TPACPI_FAN_CMD_ENABLE
;
8146 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
8147 fan_control_commands
|=
8148 TPACPI_FAN_CMD_LEVEL
|
8149 TPACPI_FAN_CMD_ENABLE
;
8154 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8155 "fan is %s, modes %d, %d\n",
8156 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
8157 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
8158 fan_status_access_mode
, fan_control_access_mode
);
8160 /* fan control master switch */
8161 if (!fan_control_allowed
) {
8162 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
8163 fan_control_commands
= 0;
8164 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8165 "fan control features disabled by parameter\n");
8168 /* update fan_control_desired_level */
8169 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
8170 fan_get_status_safe(NULL
);
8172 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
8173 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
8174 if (tp_features
.second_fan
) {
8175 /* attach second fan tachometer */
8176 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
8177 &dev_attr_fan_fan2_input
.attr
;
8179 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8184 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
8185 &driver_attr_fan_watchdog
);
8187 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8196 static void fan_exit(void)
8198 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
8199 "cancelling any pending fan watchdog tasks\n");
8201 /* FIXME: can we really do this unconditionally? */
8202 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
8203 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
8204 &driver_attr_fan_watchdog
);
8206 cancel_delayed_work(&fan_watchdog_task
);
8207 flush_workqueue(tpacpi_wq
);
8210 static void fan_suspend(pm_message_t state
)
8214 if (!fan_control_allowed
)
8217 /* Store fan status in cache */
8218 fan_control_resume_level
= 0;
8219 rc
= fan_get_status_safe(&fan_control_resume_level
);
8221 printk(TPACPI_NOTICE
8222 "failed to read fan level for later "
8223 "restore during resume: %d\n", rc
);
8225 /* if it is undefined, don't attempt to restore it.
8227 if (tp_features
.fan_ctrl_status_undef
)
8228 fan_control_resume_level
= 0;
8231 static void fan_resume(void)
8233 u8 current_level
= 7;
8234 bool do_set
= false;
8237 /* DSDT *always* updates status on resume */
8238 tp_features
.fan_ctrl_status_undef
= 0;
8240 if (!fan_control_allowed
||
8241 !fan_control_resume_level
||
8242 (fan_get_status_safe(¤t_level
) < 0))
8245 switch (fan_control_access_mode
) {
8246 case TPACPI_FAN_WR_ACPI_SFAN
:
8247 /* never decrease fan level */
8248 do_set
= (fan_control_resume_level
> current_level
);
8250 case TPACPI_FAN_WR_ACPI_FANS
:
8251 case TPACPI_FAN_WR_TPEC
:
8252 /* never decrease fan level, scale is:
8253 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
8255 * We expect the firmware to set either 7 or AUTO, but we
8256 * handle FULLSPEED out of paranoia.
8258 * So, we can safely only restore FULLSPEED or 7, anything
8259 * else could slow the fan. Restoring AUTO is useless, at
8260 * best that's exactly what the DSDT already set (it is the
8263 * Always keep in mind that the DSDT *will* have set the
8264 * fans to what the vendor supposes is the best level. We
8265 * muck with it only to speed the fan up.
8267 if (fan_control_resume_level
!= 7 &&
8268 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
8271 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
8272 (current_level
!= fan_control_resume_level
);
8278 printk(TPACPI_NOTICE
8279 "restoring fan level to 0x%02x\n",
8280 fan_control_resume_level
);
8281 rc
= fan_set_level_safe(fan_control_resume_level
);
8283 printk(TPACPI_NOTICE
8284 "failed to restore fan level: %d\n", rc
);
8288 static int fan_read(struct seq_file
*m
)
8292 unsigned int speed
= 0;
8294 switch (fan_status_access_mode
) {
8295 case TPACPI_FAN_RD_ACPI_GFAN
:
8296 /* 570, 600e/x, 770e, 770x */
8297 rc
= fan_get_status_safe(&status
);
8301 seq_printf(m
, "status:\t\t%s\n"
8303 (status
!= 0) ? "enabled" : "disabled", status
);
8306 case TPACPI_FAN_RD_TPEC
:
8307 /* all except 570, 600e/x, 770e, 770x */
8308 rc
= fan_get_status_safe(&status
);
8312 seq_printf(m
, "status:\t\t%s\n",
8313 (status
!= 0) ? "enabled" : "disabled");
8315 rc
= fan_get_speed(&speed
);
8319 seq_printf(m
, "speed:\t\t%d\n", speed
);
8321 if (status
& TP_EC_FAN_FULLSPEED
)
8322 /* Disengaged mode takes precedence */
8323 seq_printf(m
, "level:\t\tdisengaged\n");
8324 else if (status
& TP_EC_FAN_AUTO
)
8325 seq_printf(m
, "level:\t\tauto\n");
8327 seq_printf(m
, "level:\t\t%d\n", status
);
8330 case TPACPI_FAN_NONE
:
8332 seq_printf(m
, "status:\t\tnot supported\n");
8335 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
8336 seq_printf(m
, "commands:\tlevel <level>");
8338 switch (fan_control_access_mode
) {
8339 case TPACPI_FAN_WR_ACPI_SFAN
:
8340 seq_printf(m
, " (<level> is 0-7)\n");
8344 seq_printf(m
, " (<level> is 0-7, "
8345 "auto, disengaged, full-speed)\n");
8350 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
8351 seq_printf(m
, "commands:\tenable, disable\n"
8352 "commands:\twatchdog <timeout> (<timeout> "
8353 "is 0 (off), 1-120 (seconds))\n");
8355 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
8356 seq_printf(m
, "commands:\tspeed <speed>"
8357 " (<speed> is 0-65535)\n");
8362 static int fan_write_cmd_level(const char *cmd
, int *rc
)
8366 if (strlencmp(cmd
, "level auto") == 0)
8367 level
= TP_EC_FAN_AUTO
;
8368 else if ((strlencmp(cmd
, "level disengaged") == 0) |
8369 (strlencmp(cmd
, "level full-speed") == 0))
8370 level
= TP_EC_FAN_FULLSPEED
;
8371 else if (sscanf(cmd
, "level %d", &level
) != 1)
8374 *rc
= fan_set_level_safe(level
);
8376 printk(TPACPI_ERR
"level command accepted for unsupported "
8377 "access mode %d", fan_control_access_mode
);
8379 tpacpi_disclose_usertask("procfs fan",
8380 "set level to %d\n", level
);
8385 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
8387 if (strlencmp(cmd
, "enable") != 0)
8390 *rc
= fan_set_enable();
8392 printk(TPACPI_ERR
"enable command accepted for unsupported "
8393 "access mode %d", fan_control_access_mode
);
8395 tpacpi_disclose_usertask("procfs fan", "enable\n");
8400 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
8402 if (strlencmp(cmd
, "disable") != 0)
8405 *rc
= fan_set_disable();
8407 printk(TPACPI_ERR
"disable command accepted for unsupported "
8408 "access mode %d", fan_control_access_mode
);
8410 tpacpi_disclose_usertask("procfs fan", "disable\n");
8415 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
8420 * Support speed <low> <medium> <high> ? */
8422 if (sscanf(cmd
, "speed %d", &speed
) != 1)
8425 *rc
= fan_set_speed(speed
);
8427 printk(TPACPI_ERR
"speed command accepted for unsupported "
8428 "access mode %d", fan_control_access_mode
);
8430 tpacpi_disclose_usertask("procfs fan",
8431 "set speed to %d\n", speed
);
8436 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
8440 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
8443 if (interval
< 0 || interval
> 120)
8446 fan_watchdog_maxinterval
= interval
;
8447 tpacpi_disclose_usertask("procfs fan",
8448 "set watchdog timer to %d\n",
8455 static int fan_write(char *buf
)
8460 while (!rc
&& (cmd
= next_cmd(&buf
))) {
8461 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
8462 fan_write_cmd_level(cmd
, &rc
)) &&
8463 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
8464 (fan_write_cmd_enable(cmd
, &rc
) ||
8465 fan_write_cmd_disable(cmd
, &rc
) ||
8466 fan_write_cmd_watchdog(cmd
, &rc
))) &&
8467 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
8468 fan_write_cmd_speed(cmd
, &rc
))
8472 fan_watchdog_reset();
8478 static struct ibm_struct fan_driver_data
= {
8483 .suspend
= fan_suspend
,
8484 .resume
= fan_resume
,
8487 /****************************************************************************
8488 ****************************************************************************
8492 ****************************************************************************
8493 ****************************************************************************/
8496 * HKEY event callout for other subdrivers go here
8497 * (yes, it is ugly, but it is quick, safe, and gets the job done
8499 static void tpacpi_driver_event(const unsigned int hkey_event
)
8501 if (ibm_backlight_device
) {
8502 switch (hkey_event
) {
8503 case TP_HKEY_EV_BRGHT_UP
:
8504 case TP_HKEY_EV_BRGHT_DOWN
:
8505 tpacpi_brightness_notify_change();
8509 switch (hkey_event
) {
8510 case TP_HKEY_EV_VOL_UP
:
8511 case TP_HKEY_EV_VOL_DOWN
:
8512 case TP_HKEY_EV_VOL_MUTE
:
8513 volume_alsa_notify_change();
8518 static void hotkey_driver_event(const unsigned int scancode
)
8520 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
8523 /* sysfs name ---------------------------------------------------------- */
8524 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
8525 struct device_attribute
*attr
,
8528 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
8531 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
8532 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
8534 /* --------------------------------------------------------------------- */
8537 static struct proc_dir_entry
*proc_dir
;
8540 * Module and infrastructure proble, init and exit handling
8543 static int force_load
;
8545 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
8546 static const char * __init
str_supported(int is_supported
)
8548 static char text_unsupported
[] __initdata
= "not supported";
8550 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
8552 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
8554 static void ibm_exit(struct ibm_struct
*ibm
)
8556 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
8558 list_del_init(&ibm
->all_drivers
);
8560 if (ibm
->flags
.acpi_notify_installed
) {
8561 dbg_printk(TPACPI_DBG_EXIT
,
8562 "%s: acpi_remove_notify_handler\n", ibm
->name
);
8564 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
8566 dispatch_acpi_notify
);
8567 ibm
->flags
.acpi_notify_installed
= 0;
8570 if (ibm
->flags
.proc_created
) {
8571 dbg_printk(TPACPI_DBG_EXIT
,
8572 "%s: remove_proc_entry\n", ibm
->name
);
8573 remove_proc_entry(ibm
->name
, proc_dir
);
8574 ibm
->flags
.proc_created
= 0;
8577 if (ibm
->flags
.acpi_driver_registered
) {
8578 dbg_printk(TPACPI_DBG_EXIT
,
8579 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
8581 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
8582 kfree(ibm
->acpi
->driver
);
8583 ibm
->acpi
->driver
= NULL
;
8584 ibm
->flags
.acpi_driver_registered
= 0;
8587 if (ibm
->flags
.init_called
&& ibm
->exit
) {
8589 ibm
->flags
.init_called
= 0;
8592 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
8595 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
8598 struct ibm_struct
*ibm
= iibm
->data
;
8599 struct proc_dir_entry
*entry
;
8601 BUG_ON(ibm
== NULL
);
8603 INIT_LIST_HEAD(&ibm
->all_drivers
);
8605 if (ibm
->flags
.experimental
&& !experimental
)
8608 dbg_printk(TPACPI_DBG_INIT
,
8609 "probing for %s\n", ibm
->name
);
8612 ret
= iibm
->init(iibm
);
8614 return 0; /* probe failed */
8618 ibm
->flags
.init_called
= 1;
8622 if (ibm
->acpi
->hid
) {
8623 ret
= register_tpacpi_subdriver(ibm
);
8628 if (ibm
->acpi
->notify
) {
8629 ret
= setup_acpi_notify(ibm
);
8630 if (ret
== -ENODEV
) {
8631 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
8641 dbg_printk(TPACPI_DBG_INIT
,
8642 "%s installed\n", ibm
->name
);
8645 mode_t mode
= iibm
->base_procfs_mode
;
8651 entry
= proc_create_data(ibm
->name
, mode
, proc_dir
,
8652 &dispatch_proc_fops
, ibm
);
8654 printk(TPACPI_ERR
"unable to create proc entry %s\n",
8659 ibm
->flags
.proc_created
= 1;
8662 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
8667 dbg_printk(TPACPI_DBG_INIT
,
8668 "%s: at error exit path with result %d\n",
8672 return (ret
< 0)? ret
: 0;
8677 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
8679 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
8682 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
8683 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
8686 return s
&& strlen(s
) >= 8 &&
8687 tpacpi_is_fw_digit(s
[0]) &&
8688 tpacpi_is_fw_digit(s
[1]) &&
8689 s
[2] == t
&& s
[3] == 'T' &&
8690 tpacpi_is_fw_digit(s
[4]) &&
8691 tpacpi_is_fw_digit(s
[5]);
8694 /* returns 0 - probe ok, or < 0 - probe error.
8695 * Probe ok doesn't mean thinkpad found.
8696 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
8697 static int __must_check __init
get_thinkpad_model_data(
8698 struct thinkpad_id_data
*tp
)
8700 const struct dmi_device
*dev
= NULL
;
8701 char ec_fw_string
[18];
8707 memset(tp
, 0, sizeof(*tp
));
8709 if (dmi_name_in_vendors("IBM"))
8710 tp
->vendor
= PCI_VENDOR_ID_IBM
;
8711 else if (dmi_name_in_vendors("LENOVO"))
8712 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
8716 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
8717 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
8718 if (s
&& !tp
->bios_version_str
)
8721 /* Really ancient ThinkPad 240X will fail this, which is fine */
8722 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
8725 tp
->bios_model
= tp
->bios_version_str
[0]
8726 | (tp
->bios_version_str
[1] << 8);
8727 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
8728 | tp
->bios_version_str
[5];
8731 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
8732 * X32 or newer, all Z series; Some models must have an
8733 * up-to-date BIOS or they will not be detected.
8735 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8737 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
8738 if (sscanf(dev
->name
,
8739 "IBM ThinkPad Embedded Controller -[%17c",
8740 ec_fw_string
) == 1) {
8741 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
8742 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
8744 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
8745 if (!tp
->ec_version_str
)
8748 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
8749 tp
->ec_model
= ec_fw_string
[0]
8750 | (ec_fw_string
[1] << 8);
8751 tp
->ec_release
= (ec_fw_string
[4] << 8)
8754 printk(TPACPI_NOTICE
8755 "ThinkPad firmware release %s "
8756 "doesn't match the known patterns\n",
8758 printk(TPACPI_NOTICE
8759 "please report this to %s\n",
8766 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
8767 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
8768 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
8773 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
8774 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
8775 if (s
&& !tp
->nummodel_str
)
8781 static int __init
probe_for_thinkpad(void)
8788 /* It would be dangerous to run the driver in this case */
8789 if (!tpacpi_is_ibm() && !tpacpi_is_lenovo())
8793 * Non-ancient models have better DMI tagging, but very old models
8794 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
8796 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
8797 (thinkpad_id
.ec_model
!= 0) ||
8798 tpacpi_is_fw_known();
8800 /* The EC handler is required */
8801 tpacpi_acpi_handle_locate("ec", TPACPI_ACPI_EC_HID
, &ec_handle
);
8805 "Not yet supported ThinkPad detected!\n");
8809 if (!is_thinkpad
&& !force_load
)
8815 static void __init
thinkpad_acpi_init_banner(void)
8817 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
8818 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
8820 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
8821 (thinkpad_id
.bios_version_str
) ?
8822 thinkpad_id
.bios_version_str
: "unknown",
8823 (thinkpad_id
.ec_version_str
) ?
8824 thinkpad_id
.ec_version_str
: "unknown");
8826 BUG_ON(!thinkpad_id
.vendor
);
8828 if (thinkpad_id
.model_str
)
8829 printk(TPACPI_INFO
"%s %s, model %s\n",
8830 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
8831 "IBM" : ((thinkpad_id
.vendor
==
8832 PCI_VENDOR_ID_LENOVO
) ?
8833 "Lenovo" : "Unknown vendor"),
8834 thinkpad_id
.model_str
,
8835 (thinkpad_id
.nummodel_str
) ?
8836 thinkpad_id
.nummodel_str
: "unknown");
8839 /* Module init, exit, parameters */
8841 static struct ibm_init_struct ibms_init
[] __initdata
= {
8843 .data
= &thinkpad_acpi_driver_data
,
8846 .init
= hotkey_init
,
8847 .data
= &hotkey_driver_data
,
8850 .init
= bluetooth_init
,
8851 .data
= &bluetooth_driver_data
,
8855 .data
= &wan_driver_data
,
8859 .data
= &uwb_driver_data
,
8861 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8864 .base_procfs_mode
= S_IRUSR
,
8865 .data
= &video_driver_data
,
8870 .data
= &light_driver_data
,
8874 .data
= &cmos_driver_data
,
8878 .data
= &led_driver_data
,
8882 .data
= &beep_driver_data
,
8885 .init
= thermal_init
,
8886 .data
= &thermal_driver_data
,
8889 .data
= &ecdump_driver_data
,
8892 .init
= brightness_init
,
8893 .data
= &brightness_driver_data
,
8896 .init
= volume_init
,
8897 .data
= &volume_driver_data
,
8901 .data
= &fan_driver_data
,
8905 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
8908 struct ibm_struct
*ibm
;
8910 if (!kp
|| !kp
->name
|| !val
)
8913 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8914 ibm
= ibms_init
[i
].data
;
8915 WARN_ON(ibm
== NULL
);
8917 if (!ibm
|| !ibm
->name
)
8920 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8921 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8923 strcpy(ibms_init
[i
].param
, val
);
8924 strcat(ibms_init
[i
].param
, ",");
8932 module_param(experimental
, int, 0444);
8933 MODULE_PARM_DESC(experimental
,
8934 "Enables experimental features when non-zero");
8936 module_param_named(debug
, dbg_level
, uint
, 0);
8937 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8939 module_param(force_load
, bool, 0444);
8940 MODULE_PARM_DESC(force_load
,
8941 "Attempts to load the driver even on a "
8942 "mis-identified ThinkPad when true");
8944 module_param_named(fan_control
, fan_control_allowed
, bool, 0444);
8945 MODULE_PARM_DESC(fan_control
,
8946 "Enables setting fan parameters features when true");
8948 module_param_named(brightness_mode
, brightness_mode
, uint
, 0444);
8949 MODULE_PARM_DESC(brightness_mode
,
8950 "Selects brightness control strategy: "
8951 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8953 module_param(brightness_enable
, uint
, 0444);
8954 MODULE_PARM_DESC(brightness_enable
,
8955 "Enables backlight control when 1, disables when 0");
8957 module_param(hotkey_report_mode
, uint
, 0444);
8958 MODULE_PARM_DESC(hotkey_report_mode
,
8959 "used for backwards compatibility with userspace, "
8960 "see documentation");
8962 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
8963 module_param_named(volume_mode
, volume_mode
, uint
, 0444);
8964 MODULE_PARM_DESC(volume_mode
,
8965 "Selects volume control strategy: "
8966 "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM");
8968 module_param_named(volume_capabilities
, volume_capabilities
, uint
, 0444);
8969 MODULE_PARM_DESC(volume_capabilities
,
8970 "Selects the mixer capabilites: "
8971 "0=auto, 1=volume and mute, 2=mute only");
8973 module_param_named(volume_control
, volume_control_allowed
, bool, 0444);
8974 MODULE_PARM_DESC(volume_control
,
8975 "Enables software override for the console audio "
8976 "control when true");
8978 /* ALSA module API parameters */
8979 module_param_named(index
, alsa_index
, int, 0444);
8980 MODULE_PARM_DESC(index
, "ALSA index for the ACPI EC Mixer");
8981 module_param_named(id
, alsa_id
, charp
, 0444);
8982 MODULE_PARM_DESC(id
, "ALSA id for the ACPI EC Mixer");
8983 module_param_named(enable
, alsa_enable
, bool, 0444);
8984 MODULE_PARM_DESC(enable
, "Enable the ALSA interface for the ACPI EC Mixer");
8985 #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
8987 #define TPACPI_PARAM(feature) \
8988 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8989 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8990 "at module load, see documentation")
8992 TPACPI_PARAM(hotkey
);
8993 TPACPI_PARAM(bluetooth
);
8994 TPACPI_PARAM(video
);
8995 TPACPI_PARAM(light
);
8999 TPACPI_PARAM(ecdump
);
9000 TPACPI_PARAM(brightness
);
9001 TPACPI_PARAM(volume
);
9004 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
9005 module_param(dbg_wlswemul
, uint
, 0444);
9006 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
9007 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
9008 MODULE_PARM_DESC(wlsw_state
,
9009 "Initial state of the emulated WLSW switch");
9011 module_param(dbg_bluetoothemul
, uint
, 0444);
9012 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
9013 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
9014 MODULE_PARM_DESC(bluetooth_state
,
9015 "Initial state of the emulated bluetooth switch");
9017 module_param(dbg_wwanemul
, uint
, 0444);
9018 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
9019 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
9020 MODULE_PARM_DESC(wwan_state
,
9021 "Initial state of the emulated WWAN switch");
9023 module_param(dbg_uwbemul
, uint
, 0444);
9024 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
9025 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
9026 MODULE_PARM_DESC(uwb_state
,
9027 "Initial state of the emulated UWB switch");
9030 static void thinkpad_acpi_module_exit(void)
9032 struct ibm_struct
*ibm
, *itmp
;
9034 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
9036 list_for_each_entry_safe_reverse(ibm
, itmp
,
9037 &tpacpi_all_drivers
,
9042 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
9044 if (tpacpi_inputdev
) {
9045 if (tp_features
.input_device_registered
)
9046 input_unregister_device(tpacpi_inputdev
);
9048 input_free_device(tpacpi_inputdev
);
9052 hwmon_device_unregister(tpacpi_hwmon
);
9054 if (tp_features
.sensors_pdev_attrs_registered
)
9055 device_remove_file(&tpacpi_sensors_pdev
->dev
,
9056 &dev_attr_thinkpad_acpi_pdev_name
);
9057 if (tpacpi_sensors_pdev
)
9058 platform_device_unregister(tpacpi_sensors_pdev
);
9060 platform_device_unregister(tpacpi_pdev
);
9062 if (tp_features
.sensors_pdrv_attrs_registered
)
9063 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
9064 if (tp_features
.platform_drv_attrs_registered
)
9065 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
9067 if (tp_features
.sensors_pdrv_registered
)
9068 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
9070 if (tp_features
.platform_drv_registered
)
9071 platform_driver_unregister(&tpacpi_pdriver
);
9074 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
9077 destroy_workqueue(tpacpi_wq
);
9079 kfree(thinkpad_id
.bios_version_str
);
9080 kfree(thinkpad_id
.ec_version_str
);
9081 kfree(thinkpad_id
.model_str
);
9085 static int __init
thinkpad_acpi_module_init(void)
9089 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
9091 /* Parameter checking */
9092 if (hotkey_report_mode
> 2)
9095 /* Driver-level probe */
9097 ret
= get_thinkpad_model_data(&thinkpad_id
);
9100 "unable to get DMI data: %d\n", ret
);
9101 thinkpad_acpi_module_exit();
9104 ret
= probe_for_thinkpad();
9106 thinkpad_acpi_module_exit();
9110 /* Driver initialization */
9112 thinkpad_acpi_init_banner();
9113 tpacpi_check_outdated_fw();
9115 TPACPI_ACPIHANDLE_INIT(ecrd
);
9116 TPACPI_ACPIHANDLE_INIT(ecwr
);
9118 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
9120 thinkpad_acpi_module_exit();
9124 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
9127 "unable to create proc dir " TPACPI_PROC_DIR
);
9128 thinkpad_acpi_module_exit();
9132 ret
= platform_driver_register(&tpacpi_pdriver
);
9135 "unable to register main platform driver\n");
9136 thinkpad_acpi_module_exit();
9139 tp_features
.platform_drv_registered
= 1;
9141 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
9144 "unable to register hwmon platform driver\n");
9145 thinkpad_acpi_module_exit();
9148 tp_features
.sensors_pdrv_registered
= 1;
9150 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
9152 tp_features
.platform_drv_attrs_registered
= 1;
9153 ret
= tpacpi_create_driver_attributes(
9154 &tpacpi_hwmon_pdriver
.driver
);
9158 "unable to create sysfs driver attributes\n");
9159 thinkpad_acpi_module_exit();
9162 tp_features
.sensors_pdrv_attrs_registered
= 1;
9165 /* Device initialization */
9166 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
9168 if (IS_ERR(tpacpi_pdev
)) {
9169 ret
= PTR_ERR(tpacpi_pdev
);
9171 printk(TPACPI_ERR
"unable to register platform device\n");
9172 thinkpad_acpi_module_exit();
9175 tpacpi_sensors_pdev
= platform_device_register_simple(
9176 TPACPI_HWMON_DRVR_NAME
,
9178 if (IS_ERR(tpacpi_sensors_pdev
)) {
9179 ret
= PTR_ERR(tpacpi_sensors_pdev
);
9180 tpacpi_sensors_pdev
= NULL
;
9182 "unable to register hwmon platform device\n");
9183 thinkpad_acpi_module_exit();
9186 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
9187 &dev_attr_thinkpad_acpi_pdev_name
);
9190 "unable to create sysfs hwmon device attributes\n");
9191 thinkpad_acpi_module_exit();
9194 tp_features
.sensors_pdev_attrs_registered
= 1;
9195 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
9196 if (IS_ERR(tpacpi_hwmon
)) {
9197 ret
= PTR_ERR(tpacpi_hwmon
);
9198 tpacpi_hwmon
= NULL
;
9199 printk(TPACPI_ERR
"unable to register hwmon device\n");
9200 thinkpad_acpi_module_exit();
9203 mutex_init(&tpacpi_inputdev_send_mutex
);
9204 tpacpi_inputdev
= input_allocate_device();
9205 if (!tpacpi_inputdev
) {
9206 printk(TPACPI_ERR
"unable to allocate input device\n");
9207 thinkpad_acpi_module_exit();
9210 /* Prepare input device, but don't register */
9211 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
9212 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
9213 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
9214 tpacpi_inputdev
->id
.vendor
= thinkpad_id
.vendor
;
9215 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
9216 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
9217 tpacpi_inputdev
->dev
.parent
= &tpacpi_pdev
->dev
;
9220 /* Init subdriver dependencies */
9221 tpacpi_detect_brightness_capabilities();
9223 /* Init subdrivers */
9224 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
9225 ret
= ibm_init(&ibms_init
[i
]);
9226 if (ret
>= 0 && *ibms_init
[i
].param
)
9227 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
9229 thinkpad_acpi_module_exit();
9234 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
9236 ret
= input_register_device(tpacpi_inputdev
);
9238 printk(TPACPI_ERR
"unable to register input device\n");
9239 thinkpad_acpi_module_exit();
9242 tp_features
.input_device_registered
= 1;
9248 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
9251 * This will autoload the driver in almost every ThinkPad
9252 * in widespread use.
9254 * Only _VERY_ old models, like the 240, 240x and 570 lack
9255 * the HKEY event interface.
9257 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
9260 * DMI matching for module autoloading
9262 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
9263 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
9265 * Only models listed in thinkwiki will be supported, so add yours
9266 * if it is not there yet.
9268 #define IBM_BIOS_MODULE_ALIAS(__type) \
9269 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
9271 /* Ancient thinkpad BIOSes have to be identified by
9272 * BIOS type or model number, and there are far less
9273 * BIOS types than model numbers... */
9274 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
9276 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
9277 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
9278 MODULE_DESCRIPTION(TPACPI_DESC
);
9279 MODULE_VERSION(TPACPI_VERSION
);
9280 MODULE_LICENSE("GPL");
9282 module_init(thinkpad_acpi_module_init
);
9283 module_exit(thinkpad_acpi_module_exit
);