2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define TPACPI_VERSION "0.24"
25 #define TPACPI_SYSFS_VERSION 0x020700
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/sched.h>
58 #include <linux/kthread.h>
59 #include <linux/freezer.h>
60 #include <linux/delay.h>
62 #include <linux/nvram.h>
63 #include <linux/proc_fs.h>
64 #include <linux/seq_file.h>
65 #include <linux/sysfs.h>
66 #include <linux/backlight.h>
68 #include <linux/platform_device.h>
69 #include <linux/hwmon.h>
70 #include <linux/hwmon-sysfs.h>
71 #include <linux/input.h>
72 #include <linux/leds.h>
73 #include <linux/rfkill.h>
74 #include <asm/uaccess.h>
76 #include <linux/dmi.h>
77 #include <linux/jiffies.h>
78 #include <linux/workqueue.h>
80 #include <sound/core.h>
81 #include <sound/control.h>
82 #include <sound/initval.h>
84 #include <acpi/acpi_drivers.h>
86 #include <linux/pci_ids.h>
89 /* ThinkPad CMOS commands */
90 #define TP_CMOS_VOLUME_DOWN 0
91 #define TP_CMOS_VOLUME_UP 1
92 #define TP_CMOS_VOLUME_MUTE 2
93 #define TP_CMOS_BRIGHTNESS_UP 4
94 #define TP_CMOS_BRIGHTNESS_DOWN 5
95 #define TP_CMOS_THINKLIGHT_ON 12
96 #define TP_CMOS_THINKLIGHT_OFF 13
100 TP_NVRAM_ADDR_HK2
= 0x57,
101 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
102 TP_NVRAM_ADDR_VIDEO
= 0x59,
103 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
104 TP_NVRAM_ADDR_MIXER
= 0x60,
107 /* NVRAM bit masks */
109 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
110 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
111 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
112 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
113 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
114 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
115 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
116 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
117 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
118 TP_NVRAM_MASK_MUTE
= 0x40,
119 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
120 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
121 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
124 /* Misc NVRAM-related */
126 TP_NVRAM_LEVEL_VOLUME_MAX
= 14,
130 #define TPACPI_ACPI_HKEY_HID "IBM0068"
131 #define TPACPI_ACPI_EC_HID "PNP0C09"
134 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
135 #define TPACPI_HKEY_INPUT_VERSION 0x4101
137 /* ACPI \WGSV commands */
139 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
140 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
141 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
142 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
145 /* TP_ACPI_WGSV_GET_STATE bits */
147 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
148 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
149 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
150 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
151 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
152 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
153 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
154 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
155 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
156 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
160 enum tpacpi_hkey_event_t
{
162 TP_HKEY_EV_HOTKEY_BASE
= 0x1001, /* first hotkey (FN+F1) */
163 TP_HKEY_EV_BRGHT_UP
= 0x1010, /* Brightness up */
164 TP_HKEY_EV_BRGHT_DOWN
= 0x1011, /* Brightness down */
165 TP_HKEY_EV_VOL_UP
= 0x1015, /* Volume up or unmute */
166 TP_HKEY_EV_VOL_DOWN
= 0x1016, /* Volume down or unmute */
167 TP_HKEY_EV_VOL_MUTE
= 0x1017, /* Mixer output mute */
169 /* Reasons for waking up from S3/S4 */
170 TP_HKEY_EV_WKUP_S3_UNDOCK
= 0x2304, /* undock requested, S3 */
171 TP_HKEY_EV_WKUP_S4_UNDOCK
= 0x2404, /* undock requested, S4 */
172 TP_HKEY_EV_WKUP_S3_BAYEJ
= 0x2305, /* bay ejection req, S3 */
173 TP_HKEY_EV_WKUP_S4_BAYEJ
= 0x2405, /* bay ejection req, S4 */
174 TP_HKEY_EV_WKUP_S3_BATLOW
= 0x2313, /* battery empty, S3 */
175 TP_HKEY_EV_WKUP_S4_BATLOW
= 0x2413, /* battery empty, S4 */
177 /* Auto-sleep after eject request */
178 TP_HKEY_EV_BAYEJ_ACK
= 0x3003, /* bay ejection complete */
179 TP_HKEY_EV_UNDOCK_ACK
= 0x4003, /* undock complete */
181 /* Misc bay events */
182 TP_HKEY_EV_OPTDRV_EJ
= 0x3006, /* opt. drive tray ejected */
184 /* User-interface events */
185 TP_HKEY_EV_LID_CLOSE
= 0x5001, /* laptop lid closed */
186 TP_HKEY_EV_LID_OPEN
= 0x5002, /* laptop lid opened */
187 TP_HKEY_EV_TABLET_TABLET
= 0x5009, /* tablet swivel up */
188 TP_HKEY_EV_TABLET_NOTEBOOK
= 0x500a, /* tablet swivel down */
189 TP_HKEY_EV_PEN_INSERTED
= 0x500b, /* tablet pen inserted */
190 TP_HKEY_EV_PEN_REMOVED
= 0x500c, /* tablet pen removed */
191 TP_HKEY_EV_BRGHT_CHANGED
= 0x5010, /* backlight control event */
194 TP_HKEY_EV_ALARM_BAT_HOT
= 0x6011, /* battery too hot */
195 TP_HKEY_EV_ALARM_BAT_XHOT
= 0x6012, /* battery critically hot */
196 TP_HKEY_EV_ALARM_SENSOR_HOT
= 0x6021, /* sensor too hot */
197 TP_HKEY_EV_ALARM_SENSOR_XHOT
= 0x6022, /* sensor critically hot */
198 TP_HKEY_EV_THM_TABLE_CHANGED
= 0x6030, /* thermal table changed */
201 TP_HKEY_EV_RFKILL_CHANGED
= 0x7000, /* rfkill switch changed */
204 /****************************************************************************
208 #define TPACPI_NAME "thinkpad"
209 #define TPACPI_DESC "ThinkPad ACPI Extras"
210 #define TPACPI_FILE TPACPI_NAME "_acpi"
211 #define TPACPI_URL "http://ibm-acpi.sf.net/"
212 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
214 #define TPACPI_PROC_DIR "ibm"
215 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
216 #define TPACPI_DRVR_NAME TPACPI_FILE
217 #define TPACPI_DRVR_SHORTNAME "tpacpi"
218 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
220 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
221 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
223 #define TPACPI_MAX_ACPI_ARGS 3
226 #define TPACPI_LOG TPACPI_FILE ": "
227 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
228 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
229 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
230 #define TPACPI_ERR KERN_ERR TPACPI_LOG
231 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
232 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
233 #define TPACPI_INFO KERN_INFO TPACPI_LOG
234 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
236 /* Debugging printk groups */
237 #define TPACPI_DBG_ALL 0xffff
238 #define TPACPI_DBG_DISCLOSETASK 0x8000
239 #define TPACPI_DBG_INIT 0x0001
240 #define TPACPI_DBG_EXIT 0x0002
241 #define TPACPI_DBG_RFKILL 0x0004
242 #define TPACPI_DBG_HKEY 0x0008
243 #define TPACPI_DBG_FAN 0x0010
244 #define TPACPI_DBG_BRGHT 0x0020
245 #define TPACPI_DBG_MIXER 0x0040
247 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
248 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
249 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
252 /****************************************************************************
253 * Driver-wide structs and misc. variables
258 struct tp_acpi_drv_struct
{
259 const struct acpi_device_id
*hid
;
260 struct acpi_driver
*driver
;
262 void (*notify
) (struct ibm_struct
*, u32
);
265 struct acpi_device
*device
;
271 int (*read
) (struct seq_file
*);
272 int (*write
) (char *);
274 void (*resume
) (void);
275 void (*suspend
) (pm_message_t state
);
276 void (*shutdown
) (void);
278 struct list_head all_drivers
;
280 struct tp_acpi_drv_struct
*acpi
;
283 u8 acpi_driver_registered
:1;
284 u8 acpi_notify_installed
:1;
291 struct ibm_init_struct
{
294 int (*init
) (struct ibm_init_struct
*);
295 mode_t base_procfs_mode
;
296 struct ibm_struct
*data
;
307 u32 bright_acpimode
:1;
311 u32 fan_ctrl_status_undef
:1;
313 u32 beep_needs_two_args
:1;
314 u32 mixer_no_level_control
:1;
315 u32 input_device_registered
:1;
316 u32 platform_drv_registered
:1;
317 u32 platform_drv_attrs_registered
:1;
318 u32 sensors_pdrv_registered
:1;
319 u32 sensors_pdrv_attrs_registered
:1;
320 u32 sensors_pdev_attrs_registered
:1;
321 u32 hotkey_poll_active
:1;
325 u16 hotkey_mask_ff
:1;
326 u16 volume_ctrl_forbidden
:1;
329 struct thinkpad_id_data
{
330 unsigned int vendor
; /* ThinkPad vendor:
331 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
333 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
334 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
336 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
338 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
341 char *model_str
; /* ThinkPad T43 */
342 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
344 static struct thinkpad_id_data thinkpad_id
;
347 TPACPI_LIFE_INIT
= 0,
352 static int experimental
;
353 static u32 dbg_level
;
355 static struct workqueue_struct
*tpacpi_wq
;
363 /* Special LED class that can defer work */
364 struct tpacpi_led_classdev
{
365 struct led_classdev led_classdev
;
366 struct work_struct work
;
367 enum led_status_t new_state
;
371 /* brightness level capabilities */
372 static unsigned int bright_maxlvl
; /* 0 = unknown */
374 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
375 static int dbg_wlswemul
;
376 static int tpacpi_wlsw_emulstate
;
377 static int dbg_bluetoothemul
;
378 static int tpacpi_bluetooth_emulstate
;
379 static int dbg_wwanemul
;
380 static int tpacpi_wwan_emulstate
;
381 static int dbg_uwbemul
;
382 static int tpacpi_uwb_emulstate
;
386 /*************************************************************************
390 #define dbg_printk(a_dbg_level, format, arg...) \
391 do { if (dbg_level & (a_dbg_level)) \
392 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
395 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
396 #define vdbg_printk dbg_printk
397 static const char *str_supported(int is_supported
);
399 #define vdbg_printk(a_dbg_level, format, arg...) \
403 static void tpacpi_log_usertask(const char * const what
)
405 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
406 what
, task_tgid_vnr(current
));
409 #define tpacpi_disclose_usertask(what, format, arg...) \
412 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
413 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
414 printk(TPACPI_DEBUG "%s: PID %d: " format, \
415 what, task_tgid_vnr(current), ## arg); \
420 * Quirk handling helpers
422 * ThinkPad IDs and versions seen in the field so far
423 * are two-characters from the set [0-9A-Z], i.e. base 36.
425 * We use values well outside that range as specials.
428 #define TPACPI_MATCH_ANY 0xffffU
429 #define TPACPI_MATCH_UNKNOWN 0U
431 /* TPID('1', 'Y') == 0x5931 */
432 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
434 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
435 { .vendor = PCI_VENDOR_ID_IBM, \
436 .bios = TPID(__id1, __id2), \
437 .ec = TPACPI_MATCH_ANY, \
438 .quirks = (__quirk) }
440 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
441 { .vendor = PCI_VENDOR_ID_LENOVO, \
442 .bios = TPID(__id1, __id2), \
443 .ec = TPACPI_MATCH_ANY, \
444 .quirks = (__quirk) }
446 #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \
447 { .vendor = PCI_VENDOR_ID_LENOVO, \
448 .bios = TPACPI_MATCH_ANY, \
449 .ec = TPID(__id1, __id2), \
450 .quirks = (__quirk) }
452 struct tpacpi_quirk
{
456 unsigned long quirks
;
460 * tpacpi_check_quirks() - search BIOS/EC version on a list
461 * @qlist: array of &struct tpacpi_quirk
462 * @qlist_size: number of elements in @qlist
464 * Iterates over a quirks list until one is found that matches the
465 * ThinkPad's vendor, BIOS and EC model.
467 * Returns 0 if nothing matches, otherwise returns the quirks field of
468 * the matching &struct tpacpi_quirk entry.
470 * The match criteria is: vendor, ec and bios much match.
472 static unsigned long __init
tpacpi_check_quirks(
473 const struct tpacpi_quirk
*qlist
,
474 unsigned int qlist_size
)
477 if ((qlist
->vendor
== thinkpad_id
.vendor
||
478 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
479 (qlist
->bios
== thinkpad_id
.bios_model
||
480 qlist
->bios
== TPACPI_MATCH_ANY
) &&
481 (qlist
->ec
== thinkpad_id
.ec_model
||
482 qlist
->ec
== TPACPI_MATCH_ANY
))
483 return qlist
->quirks
;
491 static inline bool __pure __init
tpacpi_is_lenovo(void)
493 return thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
;
496 static inline bool __pure __init
tpacpi_is_ibm(void)
498 return thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
;
501 /****************************************************************************
502 ****************************************************************************
504 * ACPI Helpers and device model
506 ****************************************************************************
507 ****************************************************************************/
509 /*************************************************************************
513 static acpi_handle root_handle
;
514 static acpi_handle ec_handle
;
516 #define TPACPI_HANDLE(object, parent, paths...) \
517 static acpi_handle object##_handle; \
518 static const acpi_handle *object##_parent __initdata = \
520 static char *object##_paths[] __initdata = { paths }
522 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
523 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
525 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
527 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
528 "\\CMS", /* R40, R40e */
531 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
532 "^HKEY", /* R30, R31 */
533 "HKEY", /* all others */
536 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
537 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
538 "\\_SB.PCI0.VID0", /* 770e */
539 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
540 "\\_SB.PCI0.AGP.VGA", /* X100e and a few others */
541 "\\_SB.PCI0.AGP.VID", /* all others */
545 /*************************************************************************
549 static int acpi_evalf(acpi_handle handle
,
550 void *res
, char *method
, char *fmt
, ...)
553 struct acpi_object_list params
;
554 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
555 struct acpi_buffer result
, *resultp
;
556 union acpi_object out_obj
;
564 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
577 params
.pointer
= &in_objs
[0];
584 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
585 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
587 /* add more types as needed */
589 printk(TPACPI_ERR
"acpi_evalf() called "
590 "with invalid format character '%c'\n", c
);
596 if (res_type
!= 'v') {
597 result
.length
= sizeof(out_obj
);
598 result
.pointer
= &out_obj
;
603 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
607 success
= (status
== AE_OK
&&
608 out_obj
.type
== ACPI_TYPE_INTEGER
);
610 *(int *)res
= out_obj
.integer
.value
;
613 success
= status
== AE_OK
;
615 /* add more types as needed */
617 printk(TPACPI_ERR
"acpi_evalf() called "
618 "with invalid format character '%c'\n", res_type
);
622 if (!success
&& !quiet
)
623 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %s\n",
624 method
, fmt0
, acpi_format_exception(status
));
629 static int acpi_ec_read(int i
, u8
*p
)
634 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
638 if (ec_read(i
, p
) < 0)
645 static int acpi_ec_write(int i
, u8 v
)
648 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
651 if (ec_write(i
, v
) < 0)
658 static int issue_thinkpad_cmos_command(int cmos_cmd
)
663 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
669 /*************************************************************************
673 #define TPACPI_ACPIHANDLE_INIT(object) \
674 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
675 object##_paths, ARRAY_SIZE(object##_paths))
677 static void __init
drv_acpi_handle_init(const char *name
,
678 acpi_handle
*handle
, const acpi_handle parent
,
679 char **paths
, const int num_paths
)
684 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
687 for (i
= 0; i
< num_paths
; i
++) {
688 status
= acpi_get_handle(parent
, paths
[i
], handle
);
689 if (ACPI_SUCCESS(status
)) {
690 dbg_printk(TPACPI_DBG_INIT
,
691 "Found ACPI handle %s for %s\n",
697 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
702 static acpi_status __init
tpacpi_acpi_handle_locate_callback(acpi_handle handle
,
703 u32 level
, void *context
, void **return_value
)
705 *(acpi_handle
*)return_value
= handle
;
707 return AE_CTRL_TERMINATE
;
710 static void __init
tpacpi_acpi_handle_locate(const char *name
,
715 acpi_handle device_found
;
717 BUG_ON(!name
|| !hid
|| !handle
);
718 vdbg_printk(TPACPI_DBG_INIT
,
719 "trying to locate ACPI handle for %s, using HID %s\n",
722 memset(&device_found
, 0, sizeof(device_found
));
723 status
= acpi_get_devices(hid
, tpacpi_acpi_handle_locate_callback
,
724 (void *)name
, &device_found
);
728 if (ACPI_SUCCESS(status
)) {
729 *handle
= device_found
;
730 dbg_printk(TPACPI_DBG_INIT
,
731 "Found ACPI handle for %s\n", name
);
733 vdbg_printk(TPACPI_DBG_INIT
,
734 "Could not locate an ACPI handle for %s: %s\n",
735 name
, acpi_format_exception(status
));
739 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
741 struct ibm_struct
*ibm
= data
;
743 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
746 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
749 ibm
->acpi
->notify(ibm
, event
);
752 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
759 if (!*ibm
->acpi
->handle
)
762 vdbg_printk(TPACPI_DBG_INIT
,
763 "setting up ACPI notify for %s\n", ibm
->name
);
765 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
767 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
772 ibm
->acpi
->device
->driver_data
= ibm
;
773 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
774 TPACPI_ACPI_EVENT_PREFIX
,
777 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
778 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
779 if (ACPI_FAILURE(status
)) {
780 if (status
== AE_ALREADY_EXISTS
) {
782 "another device driver is already "
783 "handling %s events\n", ibm
->name
);
786 "acpi_install_notify_handler(%s) failed: %s\n",
787 ibm
->name
, acpi_format_exception(status
));
791 ibm
->flags
.acpi_notify_installed
= 1;
795 static int __init
tpacpi_device_add(struct acpi_device
*device
)
800 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
804 dbg_printk(TPACPI_DBG_INIT
,
805 "registering %s as an ACPI driver\n", ibm
->name
);
809 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
810 if (!ibm
->acpi
->driver
) {
812 "failed to allocate memory for ibm->acpi->driver\n");
816 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
817 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
819 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
821 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
823 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
825 kfree(ibm
->acpi
->driver
);
826 ibm
->acpi
->driver
= NULL
;
828 ibm
->flags
.acpi_driver_registered
= 1;
834 /****************************************************************************
835 ****************************************************************************
839 ****************************************************************************
840 ****************************************************************************/
842 static int dispatch_proc_show(struct seq_file
*m
, void *v
)
844 struct ibm_struct
*ibm
= m
->private;
846 if (!ibm
|| !ibm
->read
)
851 static int dispatch_proc_open(struct inode
*inode
, struct file
*file
)
853 return single_open(file
, dispatch_proc_show
, PDE(inode
)->data
);
856 static ssize_t
dispatch_proc_write(struct file
*file
,
857 const char __user
*userbuf
,
858 size_t count
, loff_t
*pos
)
860 struct ibm_struct
*ibm
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
864 if (!ibm
|| !ibm
->write
)
866 if (count
> PAGE_SIZE
- 2)
869 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
873 if (copy_from_user(kernbuf
, userbuf
, count
)) {
879 strcat(kernbuf
, ",");
880 ret
= ibm
->write(kernbuf
);
889 static const struct file_operations dispatch_proc_fops
= {
890 .owner
= THIS_MODULE
,
891 .open
= dispatch_proc_open
,
894 .release
= single_release
,
895 .write
= dispatch_proc_write
,
898 static char *next_cmd(char **cmds
)
903 while ((end
= strchr(start
, ',')) && end
== start
)
915 /****************************************************************************
916 ****************************************************************************
918 * Device model: input, hwmon and platform
920 ****************************************************************************
921 ****************************************************************************/
923 static struct platform_device
*tpacpi_pdev
;
924 static struct platform_device
*tpacpi_sensors_pdev
;
925 static struct device
*tpacpi_hwmon
;
926 static struct input_dev
*tpacpi_inputdev
;
927 static struct mutex tpacpi_inputdev_send_mutex
;
928 static LIST_HEAD(tpacpi_all_drivers
);
930 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
933 struct ibm_struct
*ibm
, *itmp
;
935 list_for_each_entry_safe(ibm
, itmp
,
939 (ibm
->suspend
)(state
);
945 static int tpacpi_resume_handler(struct platform_device
*pdev
)
947 struct ibm_struct
*ibm
, *itmp
;
949 list_for_each_entry_safe(ibm
, itmp
,
959 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
961 struct ibm_struct
*ibm
, *itmp
;
963 list_for_each_entry_safe(ibm
, itmp
,
971 static struct platform_driver tpacpi_pdriver
= {
973 .name
= TPACPI_DRVR_NAME
,
974 .owner
= THIS_MODULE
,
976 .suspend
= tpacpi_suspend_handler
,
977 .resume
= tpacpi_resume_handler
,
978 .shutdown
= tpacpi_shutdown_handler
,
981 static struct platform_driver tpacpi_hwmon_pdriver
= {
983 .name
= TPACPI_HWMON_DRVR_NAME
,
984 .owner
= THIS_MODULE
,
988 /*************************************************************************
989 * sysfs support helpers
992 struct attribute_set
{
993 unsigned int members
, max_members
;
994 struct attribute_group group
;
997 struct attribute_set_obj
{
998 struct attribute_set s
;
1000 } __attribute__((packed
));
1002 static struct attribute_set
*create_attr_set(unsigned int max_members
,
1005 struct attribute_set_obj
*sobj
;
1007 if (max_members
== 0)
1010 /* Allocates space for implicit NULL at the end too */
1011 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
1012 max_members
* sizeof(struct attribute
*),
1016 sobj
->s
.max_members
= max_members
;
1017 sobj
->s
.group
.attrs
= &sobj
->a
;
1018 sobj
->s
.group
.name
= name
;
1023 #define destroy_attr_set(_set) \
1026 /* not multi-threaded safe, use it in a single thread per set */
1027 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
1032 if (s
->members
>= s
->max_members
)
1035 s
->group
.attrs
[s
->members
] = attr
;
1041 static int add_many_to_attr_set(struct attribute_set
*s
,
1042 struct attribute
**attr
,
1047 for (i
= 0; i
< count
; i
++) {
1048 res
= add_to_attr_set(s
, attr
[i
]);
1056 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
1058 sysfs_remove_group(kobj
, &s
->group
);
1059 destroy_attr_set(s
);
1062 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
1063 sysfs_create_group(_kobj, &_attr_set->group)
1065 static int parse_strtoul(const char *buf
,
1066 unsigned long max
, unsigned long *value
)
1070 *value
= simple_strtoul(skip_spaces(buf
), &endp
, 0);
1071 endp
= skip_spaces(endp
);
1072 if (*endp
|| *value
> max
)
1078 static void tpacpi_disable_brightness_delay(void)
1080 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
1081 printk(TPACPI_NOTICE
1082 "ACPI backlight control delay disabled\n");
1085 static void printk_deprecated_attribute(const char * const what
,
1086 const char * const details
)
1088 tpacpi_log_usertask("deprecated sysfs attribute");
1089 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1090 "will be removed. %s\n",
1094 /*************************************************************************
1095 * rfkill and radio control support helpers
1099 * ThinkPad-ACPI firmware handling model:
1101 * WLSW (master wireless switch) is event-driven, and is common to all
1102 * firmware-controlled radios. It cannot be controlled, just monitored,
1103 * as expected. It overrides all radio state in firmware
1105 * The kernel, a masked-off hotkey, and WLSW can change the radio state
1106 * (TODO: verify how WLSW interacts with the returned radio state).
1108 * The only time there are shadow radio state changes, is when
1109 * masked-off hotkeys are used.
1113 * Internal driver API for radio state:
1115 * int: < 0 = error, otherwise enum tpacpi_rfkill_state
1116 * bool: true means radio blocked (off)
1118 enum tpacpi_rfkill_state
{
1119 TPACPI_RFK_RADIO_OFF
= 0,
1123 /* rfkill switches */
1124 enum tpacpi_rfk_id
{
1125 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
1126 TPACPI_RFK_WWAN_SW_ID
,
1127 TPACPI_RFK_UWB_SW_ID
,
1131 static const char *tpacpi_rfkill_names
[] = {
1132 [TPACPI_RFK_BLUETOOTH_SW_ID
] = "bluetooth",
1133 [TPACPI_RFK_WWAN_SW_ID
] = "wwan",
1134 [TPACPI_RFK_UWB_SW_ID
] = "uwb",
1135 [TPACPI_RFK_SW_MAX
] = NULL
1138 /* ThinkPad-ACPI rfkill subdriver */
1140 struct rfkill
*rfkill
;
1141 enum tpacpi_rfk_id id
;
1142 const struct tpacpi_rfk_ops
*ops
;
1145 struct tpacpi_rfk_ops
{
1146 /* firmware interface */
1147 int (*get_status
)(void);
1148 int (*set_status
)(const enum tpacpi_rfkill_state
);
1151 static struct tpacpi_rfk
*tpacpi_rfkill_switches
[TPACPI_RFK_SW_MAX
];
1153 /* Query FW and update rfkill sw state for a given rfkill switch */
1154 static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk
*tp_rfk
)
1161 status
= (tp_rfk
->ops
->get_status
)();
1165 rfkill_set_sw_state(tp_rfk
->rfkill
,
1166 (status
== TPACPI_RFK_RADIO_OFF
));
1171 /* Query FW and update rfkill sw state for all rfkill switches */
1172 static void tpacpi_rfk_update_swstate_all(void)
1176 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++)
1177 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[i
]);
1181 * Sync the HW-blocking state of all rfkill switches,
1182 * do notice it causes the rfkill core to schedule uevents
1184 static void tpacpi_rfk_update_hwblock_state(bool blocked
)
1187 struct tpacpi_rfk
*tp_rfk
;
1189 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++) {
1190 tp_rfk
= tpacpi_rfkill_switches
[i
];
1192 if (rfkill_set_hw_state(tp_rfk
->rfkill
,
1194 /* ignore -- we track sw block */
1200 /* Call to get the WLSW state from the firmware */
1201 static int hotkey_get_wlsw(void);
1203 /* Call to query WLSW state and update all rfkill switches */
1204 static bool tpacpi_rfk_check_hwblock_state(void)
1206 int res
= hotkey_get_wlsw();
1209 /* When unknown or unsupported, we have to assume it is unblocked */
1213 hw_blocked
= (res
== TPACPI_RFK_RADIO_OFF
);
1214 tpacpi_rfk_update_hwblock_state(hw_blocked
);
1219 static int tpacpi_rfk_hook_set_block(void *data
, bool blocked
)
1221 struct tpacpi_rfk
*tp_rfk
= data
;
1224 dbg_printk(TPACPI_DBG_RFKILL
,
1225 "request to change radio state to %s\n",
1226 blocked
? "blocked" : "unblocked");
1228 /* try to set radio state */
1229 res
= (tp_rfk
->ops
->set_status
)(blocked
?
1230 TPACPI_RFK_RADIO_OFF
: TPACPI_RFK_RADIO_ON
);
1232 /* and update the rfkill core with whatever the FW really did */
1233 tpacpi_rfk_update_swstate(tp_rfk
);
1235 return (res
< 0) ? res
: 0;
1238 static const struct rfkill_ops tpacpi_rfk_rfkill_ops
= {
1239 .set_block
= tpacpi_rfk_hook_set_block
,
1242 static int __init
tpacpi_new_rfkill(const enum tpacpi_rfk_id id
,
1243 const struct tpacpi_rfk_ops
*tp_rfkops
,
1244 const enum rfkill_type rfktype
,
1246 const bool set_default
)
1248 struct tpacpi_rfk
*atp_rfk
;
1250 bool sw_state
= false;
1254 BUG_ON(id
>= TPACPI_RFK_SW_MAX
|| tpacpi_rfkill_switches
[id
]);
1256 atp_rfk
= kzalloc(sizeof(struct tpacpi_rfk
), GFP_KERNEL
);
1258 atp_rfk
->rfkill
= rfkill_alloc(name
,
1261 &tpacpi_rfk_rfkill_ops
,
1263 if (!atp_rfk
|| !atp_rfk
->rfkill
) {
1265 "failed to allocate memory for rfkill class\n");
1271 atp_rfk
->ops
= tp_rfkops
;
1273 sw_status
= (tp_rfkops
->get_status
)();
1274 if (sw_status
< 0) {
1276 "failed to read initial state for %s, error %d\n",
1279 sw_state
= (sw_status
== TPACPI_RFK_RADIO_OFF
);
1281 /* try to keep the initial state, since we ask the
1282 * firmware to preserve it across S5 in NVRAM */
1283 rfkill_init_sw_state(atp_rfk
->rfkill
, sw_state
);
1286 hw_state
= tpacpi_rfk_check_hwblock_state();
1287 rfkill_set_hw_state(atp_rfk
->rfkill
, hw_state
);
1289 res
= rfkill_register(atp_rfk
->rfkill
);
1292 "failed to register %s rfkill switch: %d\n",
1294 rfkill_destroy(atp_rfk
->rfkill
);
1299 tpacpi_rfkill_switches
[id
] = atp_rfk
;
1301 printk(TPACPI_INFO
"rfkill switch %s: radio is %sblocked\n",
1302 name
, (sw_state
|| hw_state
) ? "" : "un");
1306 static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id
)
1308 struct tpacpi_rfk
*tp_rfk
;
1310 BUG_ON(id
>= TPACPI_RFK_SW_MAX
);
1312 tp_rfk
= tpacpi_rfkill_switches
[id
];
1314 rfkill_unregister(tp_rfk
->rfkill
);
1315 rfkill_destroy(tp_rfk
->rfkill
);
1316 tpacpi_rfkill_switches
[id
] = NULL
;
1321 static void printk_deprecated_rfkill_attribute(const char * const what
)
1323 printk_deprecated_attribute(what
,
1324 "Please switch to generic rfkill before year 2010");
1327 /* sysfs <radio> enable ------------------------------------------------ */
1328 static ssize_t
tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id
,
1329 struct device_attribute
*attr
,
1334 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1336 /* This is in the ABI... */
1337 if (tpacpi_rfk_check_hwblock_state()) {
1338 status
= TPACPI_RFK_RADIO_OFF
;
1340 status
= tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1345 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1346 (status
== TPACPI_RFK_RADIO_ON
) ? 1 : 0);
1349 static ssize_t
tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id
,
1350 struct device_attribute
*attr
,
1351 const char *buf
, size_t count
)
1356 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1358 if (parse_strtoul(buf
, 1, &t
))
1361 tpacpi_disclose_usertask(attr
->attr
.name
, "set to %ld\n", t
);
1363 /* This is in the ABI... */
1364 if (tpacpi_rfk_check_hwblock_state() && !!t
)
1367 res
= tpacpi_rfkill_switches
[id
]->ops
->set_status((!!t
) ?
1368 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
);
1369 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1371 return (res
< 0) ? res
: count
;
1374 /* procfs -------------------------------------------------------------- */
1375 static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id
, struct seq_file
*m
)
1377 if (id
>= TPACPI_RFK_SW_MAX
)
1378 seq_printf(m
, "status:\t\tnot supported\n");
1382 /* This is in the ABI... */
1383 if (tpacpi_rfk_check_hwblock_state()) {
1384 status
= TPACPI_RFK_RADIO_OFF
;
1386 status
= tpacpi_rfk_update_swstate(
1387 tpacpi_rfkill_switches
[id
]);
1392 seq_printf(m
, "status:\t\t%s\n",
1393 (status
== TPACPI_RFK_RADIO_ON
) ?
1394 "enabled" : "disabled");
1395 seq_printf(m
, "commands:\tenable, disable\n");
1401 static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id
, char *buf
)
1407 if (id
>= TPACPI_RFK_SW_MAX
)
1410 while ((cmd
= next_cmd(&buf
))) {
1411 if (strlencmp(cmd
, "enable") == 0)
1412 status
= TPACPI_RFK_RADIO_ON
;
1413 else if (strlencmp(cmd
, "disable") == 0)
1414 status
= TPACPI_RFK_RADIO_OFF
;
1420 tpacpi_disclose_usertask("procfs", "attempt to %s %s\n",
1421 (status
== TPACPI_RFK_RADIO_ON
) ?
1422 "enable" : "disable",
1423 tpacpi_rfkill_names
[id
]);
1424 res
= (tpacpi_rfkill_switches
[id
]->ops
->set_status
)(status
);
1425 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1431 /*************************************************************************
1432 * thinkpad-acpi driver attributes
1435 /* interface_version --------------------------------------------------- */
1436 static ssize_t
tpacpi_driver_interface_version_show(
1437 struct device_driver
*drv
,
1440 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1443 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1444 tpacpi_driver_interface_version_show
, NULL
);
1446 /* debug_level --------------------------------------------------------- */
1447 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1450 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1453 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1454 const char *buf
, size_t count
)
1458 if (parse_strtoul(buf
, 0xffff, &t
))
1466 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1467 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1469 /* version ------------------------------------------------------------- */
1470 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1473 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1474 TPACPI_DESC
, TPACPI_VERSION
);
1477 static DRIVER_ATTR(version
, S_IRUGO
,
1478 tpacpi_driver_version_show
, NULL
);
1480 /* --------------------------------------------------------------------- */
1482 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1484 /* wlsw_emulstate ------------------------------------------------------ */
1485 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1488 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1491 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1492 const char *buf
, size_t count
)
1496 if (parse_strtoul(buf
, 1, &t
))
1499 if (tpacpi_wlsw_emulstate
!= !!t
) {
1500 tpacpi_wlsw_emulstate
= !!t
;
1501 tpacpi_rfk_update_hwblock_state(!t
); /* negative logic */
1507 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1508 tpacpi_driver_wlsw_emulstate_show
,
1509 tpacpi_driver_wlsw_emulstate_store
);
1511 /* bluetooth_emulstate ------------------------------------------------- */
1512 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1513 struct device_driver
*drv
,
1516 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1519 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1520 struct device_driver
*drv
,
1521 const char *buf
, size_t count
)
1525 if (parse_strtoul(buf
, 1, &t
))
1528 tpacpi_bluetooth_emulstate
= !!t
;
1533 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1534 tpacpi_driver_bluetooth_emulstate_show
,
1535 tpacpi_driver_bluetooth_emulstate_store
);
1537 /* wwan_emulstate ------------------------------------------------- */
1538 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1539 struct device_driver
*drv
,
1542 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1545 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1546 struct device_driver
*drv
,
1547 const char *buf
, size_t count
)
1551 if (parse_strtoul(buf
, 1, &t
))
1554 tpacpi_wwan_emulstate
= !!t
;
1559 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1560 tpacpi_driver_wwan_emulstate_show
,
1561 tpacpi_driver_wwan_emulstate_store
);
1563 /* uwb_emulstate ------------------------------------------------- */
1564 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1565 struct device_driver
*drv
,
1568 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1571 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1572 struct device_driver
*drv
,
1573 const char *buf
, size_t count
)
1577 if (parse_strtoul(buf
, 1, &t
))
1580 tpacpi_uwb_emulstate
= !!t
;
1585 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1586 tpacpi_driver_uwb_emulstate_show
,
1587 tpacpi_driver_uwb_emulstate_store
);
1590 /* --------------------------------------------------------------------- */
1592 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1593 &driver_attr_debug_level
, &driver_attr_version
,
1594 &driver_attr_interface_version
,
1597 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1603 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1604 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1608 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1609 if (!res
&& dbg_wlswemul
)
1610 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1611 if (!res
&& dbg_bluetoothemul
)
1612 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1613 if (!res
&& dbg_wwanemul
)
1614 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1615 if (!res
&& dbg_uwbemul
)
1616 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1622 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1626 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1627 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1629 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1630 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1631 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1632 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1633 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1637 /*************************************************************************
1642 * Table of recommended minimum BIOS versions
1644 * Reasons for listing:
1645 * 1. Stable BIOS, listed because the unknown amount of
1646 * bugs and bad ACPI behaviour on older versions
1648 * 2. BIOS or EC fw with known bugs that trigger on Linux
1650 * 3. BIOS with known reduced functionality in older versions
1652 * We recommend the latest BIOS and EC version.
1653 * We only support the latest BIOS and EC fw version as a rule.
1655 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1656 * Information from users in ThinkWiki
1658 * WARNING: we use this table also to detect that the machine is
1659 * a ThinkPad in some cases, so don't remove entries lightly.
1662 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1663 { .vendor = (__v), \
1664 .bios = TPID(__id1, __id2), \
1665 .ec = TPACPI_MATCH_ANY, \
1666 .quirks = TPACPI_MATCH_ANY << 16 \
1667 | (__bv1) << 8 | (__bv2) }
1669 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1670 __eid, __ev1, __ev2) \
1671 { .vendor = (__v), \
1672 .bios = TPID(__bid1, __bid2), \
1674 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1675 | (__bv1) << 8 | (__bv2) }
1677 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1678 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1680 /* Outdated IBM BIOSes often lack the EC id string */
1681 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1682 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1683 __bv1, __bv2, TPID(__id1, __id2), \
1685 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1686 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1689 /* Outdated IBM BIOSes often lack the EC id string */
1690 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1691 __eid1, __eid2, __ev1, __ev2) \
1692 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1693 __bv1, __bv2, TPID(__eid1, __eid2), \
1695 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1696 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1699 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1700 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1702 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1703 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1704 __bv1, __bv2, TPID(__id1, __id2), \
1707 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1708 __eid1, __eid2, __ev1, __ev2) \
1709 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1710 __bv1, __bv2, TPID(__eid1, __eid2), \
1713 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1714 /* Numeric models ------------------ */
1715 /* FW MODEL BIOS VERS */
1716 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1717 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1718 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1719 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1720 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1721 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1722 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1723 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1724 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1726 /* A-series ------------------------- */
1727 /* FW MODEL BIOS VERS EC VERS */
1728 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1729 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1730 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1731 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1732 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1733 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1734 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1735 TPV_QI0('1', '3', '2', '0'), /* A22m */
1736 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1737 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1738 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1740 /* G-series ------------------------- */
1741 /* FW MODEL BIOS VERS */
1742 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1743 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1745 /* R-series, T-series --------------- */
1746 /* FW MODEL BIOS VERS EC VERS */
1747 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1748 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1749 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1750 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1751 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1752 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1753 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1754 T40/p, T41/p, T42/p (1) */
1755 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1756 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1757 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1758 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1760 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1761 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1762 TPV_QI0('1', '6', '3', '2'), /* T22 */
1763 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1764 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1765 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1767 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1768 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1769 TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */
1771 /* BIOS FW BIOS VERS EC FW EC VERS */
1772 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1773 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1775 /* X-series ------------------------- */
1776 /* FW MODEL BIOS VERS EC VERS */
1777 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1778 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1779 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1780 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1781 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1782 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1783 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1785 TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */
1786 TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */
1788 /* (0) - older versions lack DMI EC fw string and functionality */
1789 /* (1) - older versions known to lack functionality */
1800 static void __init
tpacpi_check_outdated_fw(void)
1802 unsigned long fwvers
;
1803 u16 ec_version
, bios_version
;
1805 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1806 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1811 bios_version
= fwvers
& 0xffffU
;
1812 ec_version
= (fwvers
>> 16) & 0xffffU
;
1814 /* note that unknown versions are set to 0x0000 and we use that */
1815 if ((bios_version
> thinkpad_id
.bios_release
) ||
1816 (ec_version
> thinkpad_id
.ec_release
&&
1817 ec_version
!= TPACPI_MATCH_ANY
)) {
1819 * The changelogs would let us track down the exact
1820 * reason, but it is just too much of a pain to track
1821 * it. We only list BIOSes that are either really
1822 * broken, or really stable to begin with, so it is
1823 * best if the user upgrades the firmware anyway.
1826 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1828 "WARNING: This firmware may be missing critical bug "
1829 "fixes and/or important features\n");
1833 static bool __init
tpacpi_is_fw_known(void)
1835 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1836 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1839 /****************************************************************************
1840 ****************************************************************************
1844 ****************************************************************************
1845 ****************************************************************************/
1847 /*************************************************************************
1848 * thinkpad-acpi metadata subdriver
1851 static int thinkpad_acpi_driver_read(struct seq_file
*m
)
1853 seq_printf(m
, "driver:\t\t%s\n", TPACPI_DESC
);
1854 seq_printf(m
, "version:\t%s\n", TPACPI_VERSION
);
1858 static struct ibm_struct thinkpad_acpi_driver_data
= {
1860 .read
= thinkpad_acpi_driver_read
,
1863 /*************************************************************************
1868 * ThinkPad firmware event model
1870 * The ThinkPad firmware has two main event interfaces: normal ACPI
1871 * notifications (which follow the ACPI standard), and a private event
1874 * The private event interface also issues events for the hotkeys. As
1875 * the driver gained features, the event handling code ended up being
1876 * built around the hotkey subdriver. This will need to be refactored
1877 * to a more formal event API eventually.
1879 * Some "hotkeys" are actually supposed to be used as event reports,
1880 * such as "brightness has changed", "volume has changed", depending on
1881 * the ThinkPad model and how the firmware is operating.
1883 * Unlike other classes, hotkey-class events have mask/unmask control on
1884 * non-ancient firmware. However, how it behaves changes a lot with the
1885 * firmware model and version.
1888 enum { /* hot key scan codes (derived from ACPI DSDT) */
1889 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1890 TP_ACPI_HOTKEYSCAN_FNF2
,
1891 TP_ACPI_HOTKEYSCAN_FNF3
,
1892 TP_ACPI_HOTKEYSCAN_FNF4
,
1893 TP_ACPI_HOTKEYSCAN_FNF5
,
1894 TP_ACPI_HOTKEYSCAN_FNF6
,
1895 TP_ACPI_HOTKEYSCAN_FNF7
,
1896 TP_ACPI_HOTKEYSCAN_FNF8
,
1897 TP_ACPI_HOTKEYSCAN_FNF9
,
1898 TP_ACPI_HOTKEYSCAN_FNF10
,
1899 TP_ACPI_HOTKEYSCAN_FNF11
,
1900 TP_ACPI_HOTKEYSCAN_FNF12
,
1901 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1902 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1903 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1904 TP_ACPI_HOTKEYSCAN_FNHOME
,
1905 TP_ACPI_HOTKEYSCAN_FNEND
,
1906 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1907 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1908 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1909 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1910 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1911 TP_ACPI_HOTKEYSCAN_MUTE
,
1912 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1915 enum { /* Keys/events available through NVRAM polling */
1916 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1917 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1920 enum { /* Positions of some of the keys in hotkey masks */
1921 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1922 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1923 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1924 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1925 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1926 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1927 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1928 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1929 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1930 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1931 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1934 enum { /* NVRAM to ACPI HKEY group map */
1935 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1936 TP_ACPI_HKEY_ZOOM_MASK
|
1937 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1938 TP_ACPI_HKEY_HIBERNATE_MASK
,
1939 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1940 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1941 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1942 TP_ACPI_HKEY_VOLDWN_MASK
|
1943 TP_ACPI_HKEY_MUTE_MASK
,
1946 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1947 struct tp_nvram_state
{
1948 u16 thinkpad_toggle
:1;
1950 u16 display_toggle
:1;
1951 u16 thinklight_toggle
:1;
1952 u16 hibernate_toggle
:1;
1953 u16 displayexp_toggle
:1;
1954 u16 display_state
:1;
1955 u16 brightness_toggle
:1;
1956 u16 volume_toggle
:1;
1959 u8 brightness_level
;
1963 /* kthread for the hotkey poller */
1964 static struct task_struct
*tpacpi_hotkey_task
;
1966 /* Acquired while the poller kthread is running, use to sync start/stop */
1967 static struct mutex hotkey_thread_mutex
;
1970 * Acquire mutex to write poller control variables as an
1973 * Increment hotkey_config_change when changing them if you
1974 * want the kthread to forget old state.
1976 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1978 static struct mutex hotkey_thread_data_mutex
;
1979 static unsigned int hotkey_config_change
;
1982 * hotkey poller control variables
1984 * Must be atomic or readers will also need to acquire mutex
1986 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1987 * should be used only when the changes need to be taken as
1988 * a block, OR when one needs to force the kthread to forget
1991 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1992 static unsigned int hotkey_poll_freq
= 10; /* Hz */
1994 #define HOTKEY_CONFIG_CRITICAL_START \
1996 mutex_lock(&hotkey_thread_data_mutex); \
1997 hotkey_config_change++; \
1999 #define HOTKEY_CONFIG_CRITICAL_END \
2000 mutex_unlock(&hotkey_thread_data_mutex);
2002 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2004 #define hotkey_source_mask 0U
2005 #define HOTKEY_CONFIG_CRITICAL_START
2006 #define HOTKEY_CONFIG_CRITICAL_END
2008 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2010 static struct mutex hotkey_mutex
;
2012 static enum { /* Reasons for waking up */
2013 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
2014 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
2015 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
2016 } hotkey_wakeup_reason
;
2018 static int hotkey_autosleep_ack
;
2020 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
2021 static u32 hotkey_all_mask
; /* all events supported in fw */
2022 static u32 hotkey_reserved_mask
; /* events better left disabled */
2023 static u32 hotkey_driver_mask
; /* events needed by the driver */
2024 static u32 hotkey_user_mask
; /* events visible to userspace */
2025 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
2027 static unsigned int hotkey_report_mode
;
2029 static u16
*hotkey_keycode_map
;
2031 static struct attribute_set
*hotkey_dev_attributes
;
2033 static void tpacpi_driver_event(const unsigned int hkey_event
);
2034 static void hotkey_driver_event(const unsigned int scancode
);
2035 static void hotkey_poll_setup(const bool may_warn
);
2037 /* HKEY.MHKG() return bits */
2038 #define TP_HOTKEY_TABLET_MASK (1 << 3)
2040 static int hotkey_get_wlsw(void)
2044 if (!tp_features
.hotkey_wlsw
)
2047 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2049 return (tpacpi_wlsw_emulstate
) ?
2050 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2053 if (!acpi_evalf(hkey_handle
, &status
, "WLSW", "d"))
2056 return (status
) ? TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2059 static int hotkey_get_tablet_mode(int *status
)
2063 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
2066 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
2071 * Reads current event mask from firmware, and updates
2072 * hotkey_acpi_mask accordingly. Also resets any bits
2073 * from hotkey_user_mask that are unavailable to be
2074 * delivered (shadow requirement of the userspace ABI).
2076 * Call with hotkey_mutex held
2078 static int hotkey_mask_get(void)
2080 if (tp_features
.hotkey_mask
) {
2083 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
2086 hotkey_acpi_mask
= m
;
2088 /* no mask support doesn't mean no event support... */
2089 hotkey_acpi_mask
= hotkey_all_mask
;
2092 /* sync userspace-visible mask */
2093 hotkey_user_mask
&= (hotkey_acpi_mask
| hotkey_source_mask
);
2098 void static hotkey_mask_warn_incomplete_mask(void)
2100 /* log only what the user can fix... */
2101 const u32 wantedmask
= hotkey_driver_mask
&
2102 ~(hotkey_acpi_mask
| hotkey_source_mask
) &
2103 (hotkey_all_mask
| TPACPI_HKEY_NVRAM_KNOWN_MASK
);
2106 printk(TPACPI_NOTICE
2107 "required events 0x%08x not enabled!\n",
2112 * Set the firmware mask when supported
2114 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
2116 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
2118 * Call with hotkey_mutex held
2120 static int hotkey_mask_set(u32 mask
)
2125 const u32 fwmask
= mask
& ~hotkey_source_mask
;
2127 if (tp_features
.hotkey_mask
) {
2128 for (i
= 0; i
< 32; i
++) {
2129 if (!acpi_evalf(hkey_handle
,
2130 NULL
, "MHKM", "vdd", i
+ 1,
2131 !!(mask
& (1 << i
)))) {
2139 * We *must* make an inconditional call to hotkey_mask_get to
2140 * refresh hotkey_acpi_mask and update hotkey_user_mask
2142 * Take the opportunity to also log when we cannot _enable_
2145 if (!hotkey_mask_get() && !rc
&& (fwmask
& ~hotkey_acpi_mask
)) {
2146 printk(TPACPI_NOTICE
2147 "asked for hotkey mask 0x%08x, but "
2148 "firmware forced it to 0x%08x\n",
2149 fwmask
, hotkey_acpi_mask
);
2152 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
)
2153 hotkey_mask_warn_incomplete_mask();
2159 * Sets hotkey_user_mask and tries to set the firmware mask
2161 * Call with hotkey_mutex held
2163 static int hotkey_user_mask_set(const u32 mask
)
2167 /* Give people a chance to notice they are doing something that
2168 * is bound to go boom on their users sooner or later */
2169 if (!tp_warned
.hotkey_mask_ff
&&
2170 (mask
== 0xffff || mask
== 0xffffff ||
2171 mask
== 0xffffffff)) {
2172 tp_warned
.hotkey_mask_ff
= 1;
2173 printk(TPACPI_NOTICE
2174 "setting the hotkey mask to 0x%08x is likely "
2175 "not the best way to go about it\n", mask
);
2176 printk(TPACPI_NOTICE
2177 "please consider using the driver defaults, "
2178 "and refer to up-to-date thinkpad-acpi "
2182 /* Try to enable what the user asked for, plus whatever we need.
2183 * this syncs everything but won't enable bits in hotkey_user_mask */
2184 rc
= hotkey_mask_set((mask
| hotkey_driver_mask
) & ~hotkey_source_mask
);
2186 /* Enable the available bits in hotkey_user_mask */
2187 hotkey_user_mask
= mask
& (hotkey_acpi_mask
| hotkey_source_mask
);
2193 * Sets the driver hotkey mask.
2195 * Can be called even if the hotkey subdriver is inactive
2197 static int tpacpi_hotkey_driver_mask_set(const u32 mask
)
2201 /* Do the right thing if hotkey_init has not been called yet */
2202 if (!tp_features
.hotkey
) {
2203 hotkey_driver_mask
= mask
;
2207 mutex_lock(&hotkey_mutex
);
2209 HOTKEY_CONFIG_CRITICAL_START
2210 hotkey_driver_mask
= mask
;
2211 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2212 hotkey_source_mask
|= (mask
& ~hotkey_all_mask
);
2214 HOTKEY_CONFIG_CRITICAL_END
2216 rc
= hotkey_mask_set((hotkey_acpi_mask
| hotkey_driver_mask
) &
2217 ~hotkey_source_mask
);
2218 hotkey_poll_setup(true);
2220 mutex_unlock(&hotkey_mutex
);
2225 static int hotkey_status_get(int *status
)
2227 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
2233 static int hotkey_status_set(bool enable
)
2235 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
2241 static void tpacpi_input_send_tabletsw(void)
2245 if (tp_features
.hotkey_tablet
&&
2246 !hotkey_get_tablet_mode(&state
)) {
2247 mutex_lock(&tpacpi_inputdev_send_mutex
);
2249 input_report_switch(tpacpi_inputdev
,
2250 SW_TABLET_MODE
, !!state
);
2251 input_sync(tpacpi_inputdev
);
2253 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2257 /* Do NOT call without validating scancode first */
2258 static void tpacpi_input_send_key(const unsigned int scancode
)
2260 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
2262 if (keycode
!= KEY_RESERVED
) {
2263 mutex_lock(&tpacpi_inputdev_send_mutex
);
2265 input_report_key(tpacpi_inputdev
, keycode
, 1);
2266 if (keycode
== KEY_UNKNOWN
)
2267 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2269 input_sync(tpacpi_inputdev
);
2271 input_report_key(tpacpi_inputdev
, keycode
, 0);
2272 if (keycode
== KEY_UNKNOWN
)
2273 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2275 input_sync(tpacpi_inputdev
);
2277 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2281 /* Do NOT call without validating scancode first */
2282 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
2284 hotkey_driver_event(scancode
);
2285 if (hotkey_user_mask
& (1 << scancode
))
2286 tpacpi_input_send_key(scancode
);
2289 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2290 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2292 /* Do NOT call without validating scancode first */
2293 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2295 tpacpi_input_send_key_masked(scancode
);
2296 if (hotkey_report_mode
< 2) {
2297 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2298 0x80, TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
2302 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2306 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2307 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2308 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2309 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2310 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2311 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2313 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2314 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2315 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2317 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2318 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2319 n
->displayexp_toggle
=
2320 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2322 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2323 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2324 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2325 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2326 n
->brightness_toggle
=
2327 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2329 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2330 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2331 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2332 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2333 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2334 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2338 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2339 struct tp_nvram_state
*newn
,
2340 const u32 event_mask
)
2343 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2345 if ((event_mask & (1 << __scancode)) && \
2346 oldn->__member != newn->__member) \
2347 tpacpi_hotkey_send_key(__scancode); \
2350 #define TPACPI_MAY_SEND_KEY(__scancode) \
2352 if (event_mask & (1 << __scancode)) \
2353 tpacpi_hotkey_send_key(__scancode); \
2356 void issue_volchange(const unsigned int oldvol
,
2357 const unsigned int newvol
)
2359 unsigned int i
= oldvol
;
2361 while (i
> newvol
) {
2362 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2365 while (i
< newvol
) {
2366 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2371 void issue_brightnesschange(const unsigned int oldbrt
,
2372 const unsigned int newbrt
)
2374 unsigned int i
= oldbrt
;
2376 while (i
> newbrt
) {
2377 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2380 while (i
< newbrt
) {
2381 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2386 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2387 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2388 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2389 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2391 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2393 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2398 * This code is supposed to duplicate the IBM firmware behaviour:
2399 * - Pressing MUTE issues mute hotkey message, even when already mute
2400 * - Pressing Volume up/down issues volume up/down hotkey messages,
2401 * even when already at maximum or minumum volume
2402 * - The act of unmuting issues volume up/down notification,
2403 * depending which key was used to unmute
2405 * We are constrained to what the NVRAM can tell us, which is not much
2406 * and certainly not enough if more than one volume hotkey was pressed
2407 * since the last poll cycle.
2409 * Just to make our life interesting, some newer Lenovo ThinkPads have
2410 * bugs in the BIOS and may fail to update volume_toggle properly.
2415 oldn
->volume_toggle
!= newn
->volume_toggle
||
2416 oldn
->volume_level
!= newn
->volume_level
) {
2417 /* recently muted, or repeated mute keypress, or
2418 * multiple presses ending in mute */
2419 issue_volchange(oldn
->volume_level
, newn
->volume_level
);
2420 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2425 /* recently unmuted, issue 'unmute' keypress */
2426 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2428 if (oldn
->volume_level
!= newn
->volume_level
) {
2429 issue_volchange(oldn
->volume_level
, newn
->volume_level
);
2430 } else if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2431 /* repeated vol up/down keypress at end of scale ? */
2432 if (newn
->volume_level
== 0)
2433 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2434 else if (newn
->volume_level
>= TP_NVRAM_LEVEL_VOLUME_MAX
)
2435 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2439 /* handle brightness */
2440 if (oldn
->brightness_level
!= newn
->brightness_level
) {
2441 issue_brightnesschange(oldn
->brightness_level
,
2442 newn
->brightness_level
);
2443 } else if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2444 /* repeated key presses that didn't change state */
2445 if (newn
->brightness_level
== 0)
2446 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2447 else if (newn
->brightness_level
>= bright_maxlvl
2448 && !tp_features
.bright_unkfw
)
2449 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2452 #undef TPACPI_COMPARE_KEY
2453 #undef TPACPI_MAY_SEND_KEY
2459 * We track all events in hotkey_source_mask all the time, since
2460 * most of them are edge-based. We only issue those requested by
2461 * hotkey_user_mask or hotkey_driver_mask, though.
2463 static int hotkey_kthread(void *data
)
2465 struct tp_nvram_state s
[2];
2466 u32 poll_mask
, event_mask
;
2467 unsigned int si
, so
;
2469 unsigned int change_detector
, must_reset
;
2470 unsigned int poll_freq
;
2472 mutex_lock(&hotkey_thread_mutex
);
2474 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2483 /* Initial state for compares */
2484 mutex_lock(&hotkey_thread_data_mutex
);
2485 change_detector
= hotkey_config_change
;
2486 poll_mask
= hotkey_source_mask
;
2487 event_mask
= hotkey_source_mask
&
2488 (hotkey_driver_mask
| hotkey_user_mask
);
2489 poll_freq
= hotkey_poll_freq
;
2490 mutex_unlock(&hotkey_thread_data_mutex
);
2491 hotkey_read_nvram(&s
[so
], poll_mask
);
2493 while (!kthread_should_stop()) {
2495 if (likely(poll_freq
))
2498 t
= 100; /* should never happen... */
2500 t
= msleep_interruptible(t
);
2501 if (unlikely(kthread_should_stop()))
2503 must_reset
= try_to_freeze();
2504 if (t
> 0 && !must_reset
)
2507 mutex_lock(&hotkey_thread_data_mutex
);
2508 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2509 /* forget old state on thaw or config change */
2512 change_detector
= hotkey_config_change
;
2514 poll_mask
= hotkey_source_mask
;
2515 event_mask
= hotkey_source_mask
&
2516 (hotkey_driver_mask
| hotkey_user_mask
);
2517 poll_freq
= hotkey_poll_freq
;
2518 mutex_unlock(&hotkey_thread_data_mutex
);
2520 if (likely(poll_mask
)) {
2521 hotkey_read_nvram(&s
[si
], poll_mask
);
2522 if (likely(si
!= so
)) {
2523 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2533 mutex_unlock(&hotkey_thread_mutex
);
2537 /* call with hotkey_mutex held */
2538 static void hotkey_poll_stop_sync(void)
2540 if (tpacpi_hotkey_task
) {
2541 if (frozen(tpacpi_hotkey_task
) ||
2542 freezing(tpacpi_hotkey_task
))
2543 thaw_process(tpacpi_hotkey_task
);
2545 kthread_stop(tpacpi_hotkey_task
);
2546 tpacpi_hotkey_task
= NULL
;
2547 mutex_lock(&hotkey_thread_mutex
);
2548 /* at this point, the thread did exit */
2549 mutex_unlock(&hotkey_thread_mutex
);
2553 /* call with hotkey_mutex held */
2554 static void hotkey_poll_setup(const bool may_warn
)
2556 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2557 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2559 if (hotkey_poll_freq
> 0 &&
2560 (poll_driver_mask
||
2561 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2562 if (!tpacpi_hotkey_task
) {
2563 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2564 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2565 if (IS_ERR(tpacpi_hotkey_task
)) {
2566 tpacpi_hotkey_task
= NULL
;
2568 "could not create kernel thread "
2569 "for hotkey polling\n");
2573 hotkey_poll_stop_sync();
2574 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2575 hotkey_poll_freq
== 0) {
2576 printk(TPACPI_NOTICE
2577 "hot keys 0x%08x and/or events 0x%08x "
2578 "require polling, which is currently "
2580 poll_user_mask
, poll_driver_mask
);
2585 static void hotkey_poll_setup_safe(const bool may_warn
)
2587 mutex_lock(&hotkey_mutex
);
2588 hotkey_poll_setup(may_warn
);
2589 mutex_unlock(&hotkey_mutex
);
2592 /* call with hotkey_mutex held */
2593 static void hotkey_poll_set_freq(unsigned int freq
)
2596 hotkey_poll_stop_sync();
2598 hotkey_poll_freq
= freq
;
2601 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2603 static void hotkey_poll_setup(const bool __unused
)
2607 static void hotkey_poll_setup_safe(const bool __unused
)
2611 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2613 static int hotkey_inputdev_open(struct input_dev
*dev
)
2615 switch (tpacpi_lifecycle
) {
2616 case TPACPI_LIFE_INIT
:
2617 case TPACPI_LIFE_RUNNING
:
2618 hotkey_poll_setup_safe(false);
2620 case TPACPI_LIFE_EXITING
:
2624 /* Should only happen if tpacpi_lifecycle is corrupt */
2629 static void hotkey_inputdev_close(struct input_dev
*dev
)
2631 /* disable hotkey polling when possible */
2632 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
&&
2633 !(hotkey_source_mask
& hotkey_driver_mask
))
2634 hotkey_poll_setup_safe(false);
2637 /* sysfs hotkey enable ------------------------------------------------- */
2638 static ssize_t
hotkey_enable_show(struct device
*dev
,
2639 struct device_attribute
*attr
,
2644 printk_deprecated_attribute("hotkey_enable",
2645 "Hotkey reporting is always enabled");
2647 res
= hotkey_status_get(&status
);
2651 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2654 static ssize_t
hotkey_enable_store(struct device
*dev
,
2655 struct device_attribute
*attr
,
2656 const char *buf
, size_t count
)
2660 printk_deprecated_attribute("hotkey_enable",
2661 "Hotkeys can be disabled through hotkey_mask");
2663 if (parse_strtoul(buf
, 1, &t
))
2672 static struct device_attribute dev_attr_hotkey_enable
=
2673 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2674 hotkey_enable_show
, hotkey_enable_store
);
2676 /* sysfs hotkey mask --------------------------------------------------- */
2677 static ssize_t
hotkey_mask_show(struct device
*dev
,
2678 struct device_attribute
*attr
,
2681 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2684 static ssize_t
hotkey_mask_store(struct device
*dev
,
2685 struct device_attribute
*attr
,
2686 const char *buf
, size_t count
)
2691 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2694 if (mutex_lock_killable(&hotkey_mutex
))
2695 return -ERESTARTSYS
;
2697 res
= hotkey_user_mask_set(t
);
2699 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2700 hotkey_poll_setup(true);
2703 mutex_unlock(&hotkey_mutex
);
2705 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2707 return (res
) ? res
: count
;
2710 static struct device_attribute dev_attr_hotkey_mask
=
2711 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2712 hotkey_mask_show
, hotkey_mask_store
);
2714 /* sysfs hotkey bios_enabled ------------------------------------------- */
2715 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2716 struct device_attribute
*attr
,
2719 return sprintf(buf
, "0\n");
2722 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2723 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2725 /* sysfs hotkey bios_mask ---------------------------------------------- */
2726 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2727 struct device_attribute
*attr
,
2730 printk_deprecated_attribute("hotkey_bios_mask",
2731 "This attribute is useless.");
2732 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2735 static struct device_attribute dev_attr_hotkey_bios_mask
=
2736 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2738 /* sysfs hotkey all_mask ----------------------------------------------- */
2739 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2740 struct device_attribute
*attr
,
2743 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2744 hotkey_all_mask
| hotkey_source_mask
);
2747 static struct device_attribute dev_attr_hotkey_all_mask
=
2748 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2750 /* sysfs hotkey recommended_mask --------------------------------------- */
2751 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2752 struct device_attribute
*attr
,
2755 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2756 (hotkey_all_mask
| hotkey_source_mask
)
2757 & ~hotkey_reserved_mask
);
2760 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2761 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2762 hotkey_recommended_mask_show
, NULL
);
2764 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2766 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2767 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2768 struct device_attribute
*attr
,
2771 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2774 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2775 struct device_attribute
*attr
,
2776 const char *buf
, size_t count
)
2782 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2783 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2786 if (mutex_lock_killable(&hotkey_mutex
))
2787 return -ERESTARTSYS
;
2789 HOTKEY_CONFIG_CRITICAL_START
2790 hotkey_source_mask
= t
;
2791 HOTKEY_CONFIG_CRITICAL_END
2793 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2794 ~hotkey_source_mask
);
2795 hotkey_poll_setup(true);
2797 /* check if events needed by the driver got disabled */
2798 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2799 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2801 mutex_unlock(&hotkey_mutex
);
2804 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2805 "firmware event mask!\n");
2808 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2809 "some important events were disabled: "
2812 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2814 return (rc
< 0) ? rc
: count
;
2817 static struct device_attribute dev_attr_hotkey_source_mask
=
2818 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2819 hotkey_source_mask_show
, hotkey_source_mask_store
);
2821 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2822 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2823 struct device_attribute
*attr
,
2826 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2829 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2830 struct device_attribute
*attr
,
2831 const char *buf
, size_t count
)
2835 if (parse_strtoul(buf
, 25, &t
))
2838 if (mutex_lock_killable(&hotkey_mutex
))
2839 return -ERESTARTSYS
;
2841 hotkey_poll_set_freq(t
);
2842 hotkey_poll_setup(true);
2844 mutex_unlock(&hotkey_mutex
);
2846 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2851 static struct device_attribute dev_attr_hotkey_poll_freq
=
2852 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2853 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2855 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2857 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2858 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2859 struct device_attribute
*attr
,
2863 res
= hotkey_get_wlsw();
2867 /* Opportunistic update */
2868 tpacpi_rfk_update_hwblock_state((res
== TPACPI_RFK_RADIO_OFF
));
2870 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2871 (res
== TPACPI_RFK_RADIO_OFF
) ? 0 : 1);
2874 static struct device_attribute dev_attr_hotkey_radio_sw
=
2875 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2877 static void hotkey_radio_sw_notify_change(void)
2879 if (tp_features
.hotkey_wlsw
)
2880 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2884 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2885 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2886 struct device_attribute
*attr
,
2890 res
= hotkey_get_tablet_mode(&s
);
2894 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2897 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2898 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2900 static void hotkey_tablet_mode_notify_change(void)
2902 if (tp_features
.hotkey_tablet
)
2903 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2904 "hotkey_tablet_mode");
2907 /* sysfs hotkey report_mode -------------------------------------------- */
2908 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2909 struct device_attribute
*attr
,
2912 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2913 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2916 static struct device_attribute dev_attr_hotkey_report_mode
=
2917 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2919 /* sysfs wakeup reason (pollable) -------------------------------------- */
2920 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2921 struct device_attribute
*attr
,
2924 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2927 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2928 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2930 static void hotkey_wakeup_reason_notify_change(void)
2932 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2936 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2937 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2938 struct device_attribute
*attr
,
2941 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2944 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2945 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2946 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2948 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2950 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2951 "wakeup_hotunplug_complete");
2954 /* --------------------------------------------------------------------- */
2956 static struct attribute
*hotkey_attributes
[] __initdata
= {
2957 &dev_attr_hotkey_enable
.attr
,
2958 &dev_attr_hotkey_bios_enabled
.attr
,
2959 &dev_attr_hotkey_bios_mask
.attr
,
2960 &dev_attr_hotkey_report_mode
.attr
,
2961 &dev_attr_hotkey_wakeup_reason
.attr
,
2962 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2963 &dev_attr_hotkey_mask
.attr
,
2964 &dev_attr_hotkey_all_mask
.attr
,
2965 &dev_attr_hotkey_recommended_mask
.attr
,
2966 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2967 &dev_attr_hotkey_source_mask
.attr
,
2968 &dev_attr_hotkey_poll_freq
.attr
,
2973 * Sync both the hw and sw blocking state of all switches
2975 static void tpacpi_send_radiosw_update(void)
2980 * We must sync all rfkill controllers *before* issuing any
2981 * rfkill input events, or we will race the rfkill core input
2984 * tpacpi_inputdev_send_mutex works as a syncronization point
2987 * We optimize to avoid numerous calls to hotkey_get_wlsw.
2990 wlsw
= hotkey_get_wlsw();
2992 /* Sync hw blocking state first if it is hw-blocked */
2993 if (wlsw
== TPACPI_RFK_RADIO_OFF
)
2994 tpacpi_rfk_update_hwblock_state(true);
2996 /* Sync sw blocking state */
2997 tpacpi_rfk_update_swstate_all();
2999 /* Sync hw blocking state last if it is hw-unblocked */
3000 if (wlsw
== TPACPI_RFK_RADIO_ON
)
3001 tpacpi_rfk_update_hwblock_state(false);
3003 /* Issue rfkill input event for WLSW switch */
3005 mutex_lock(&tpacpi_inputdev_send_mutex
);
3007 input_report_switch(tpacpi_inputdev
,
3008 SW_RFKILL_ALL
, (wlsw
> 0));
3009 input_sync(tpacpi_inputdev
);
3011 mutex_unlock(&tpacpi_inputdev_send_mutex
);
3015 * this can be unconditional, as we will poll state again
3016 * if userspace uses the notify to read data
3018 hotkey_radio_sw_notify_change();
3021 static void hotkey_exit(void)
3023 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3024 mutex_lock(&hotkey_mutex
);
3025 hotkey_poll_stop_sync();
3026 mutex_unlock(&hotkey_mutex
);
3029 if (hotkey_dev_attributes
)
3030 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3032 kfree(hotkey_keycode_map
);
3034 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
3035 "restoring original HKEY status and mask\n");
3036 /* yes, there is a bitwise or below, we want the
3037 * functions to be called even if one of them fail */
3038 if (((tp_features
.hotkey_mask
&&
3039 hotkey_mask_set(hotkey_orig_mask
)) |
3040 hotkey_status_set(false)) != 0)
3042 "failed to restore hot key mask "
3043 "to BIOS defaults\n");
3046 static void __init
hotkey_unmap(const unsigned int scancode
)
3048 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
3049 clear_bit(hotkey_keycode_map
[scancode
],
3050 tpacpi_inputdev
->keybit
);
3051 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
3057 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
3060 #define TPACPI_HK_Q_INIMASK 0x0001
3062 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
3063 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
3064 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
3065 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
3066 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
3067 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
3068 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
3069 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
3070 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
3071 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
3072 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
3073 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
3074 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
3075 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
3076 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
3077 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
3078 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
3079 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
3080 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
3081 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
3084 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
3086 /* Requirements for changing the default keymaps:
3088 * 1. Many of the keys are mapped to KEY_RESERVED for very
3089 * good reasons. Do not change them unless you have deep
3090 * knowledge on the IBM and Lenovo ThinkPad firmware for
3091 * the various ThinkPad models. The driver behaves
3092 * differently for KEY_RESERVED: such keys have their
3093 * hot key mask *unset* in mask_recommended, and also
3094 * in the initial hot key mask programmed into the
3095 * firmware at driver load time, which means the firm-
3096 * ware may react very differently if you change them to
3099 * 2. You must be subscribed to the linux-thinkpad and
3100 * ibm-acpi-devel mailing lists, and you should read the
3101 * list archives since 2007 if you want to change the
3102 * keymaps. This requirement exists so that you will
3103 * know the past history of problems with the thinkpad-
3104 * acpi driver keymaps, and also that you will be
3105 * listening to any bug reports;
3107 * 3. Do not send thinkpad-acpi specific patches directly to
3108 * for merging, *ever*. Send them to the linux-acpi
3109 * mailinglist for comments. Merging is to be done only
3110 * through acpi-test and the ACPI maintainer.
3112 * If the above is too much to ask, don't change the keymap.
3113 * Ask the thinkpad-acpi maintainer to do it, instead.
3115 static u16 ibm_keycode_map
[] __initdata
= {
3116 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3117 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
3118 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3119 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3121 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3122 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3123 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3124 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3126 /* brightness: firmware always reacts to them */
3127 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
3128 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
3130 /* Thinklight: firmware always react to it */
3131 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3133 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3134 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3136 /* Volume: firmware always react to it and reprograms
3137 * the built-in *extra* mixer. Never map it to control
3138 * another mixer by default. */
3139 KEY_RESERVED
, /* 0x14: VOLUME UP */
3140 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3141 KEY_RESERVED
, /* 0x16: MUTE */
3143 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3145 /* (assignments unknown, please report if found) */
3146 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3147 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3149 static u16 lenovo_keycode_map
[] __initdata
= {
3150 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3151 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
3152 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3153 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3155 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3156 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3157 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3158 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3160 /* These should be enabled --only-- when ACPI video
3161 * is disabled (i.e. in "vendor" mode), and are handled
3162 * in a special way by the init code */
3163 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
3164 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
3166 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3168 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3169 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3171 /* Volume: z60/z61, T60 (BIOS version?): firmware always
3172 * react to it and reprograms the built-in *extra* mixer.
3173 * Never map it to control another mixer by default.
3175 * T60?, T61, R60?, R61: firmware and EC tries to send
3176 * these over the regular keyboard, so these are no-ops,
3177 * but there are still weird bugs re. MUTE, so do not
3178 * change unless you get test reports from all Lenovo
3179 * models. May cause the BIOS to interfere with the
3182 KEY_RESERVED
, /* 0x14: VOLUME UP */
3183 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3184 KEY_RESERVED
, /* 0x16: MUTE */
3186 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3188 /* (assignments unknown, please report if found) */
3189 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3190 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3193 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
3194 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
3195 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
3200 bool radiosw_state
= false;
3201 bool tabletsw_state
= false;
3203 unsigned long quirks
;
3205 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3206 "initializing hotkey subdriver\n");
3208 BUG_ON(!tpacpi_inputdev
);
3209 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
3210 tpacpi_inputdev
->close
!= NULL
);
3212 TPACPI_ACPIHANDLE_INIT(hkey
);
3213 mutex_init(&hotkey_mutex
);
3215 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3216 mutex_init(&hotkey_thread_mutex
);
3217 mutex_init(&hotkey_thread_data_mutex
);
3220 /* hotkey not supported on 570 */
3221 tp_features
.hotkey
= hkey_handle
!= NULL
;
3223 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3225 str_supported(tp_features
.hotkey
));
3227 if (!tp_features
.hotkey
)
3230 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
3231 ARRAY_SIZE(tpacpi_hotkey_qtable
));
3233 tpacpi_disable_brightness_delay();
3235 /* MUST have enough space for all attributes to be added to
3236 * hotkey_dev_attributes */
3237 hotkey_dev_attributes
= create_attr_set(
3238 ARRAY_SIZE(hotkey_attributes
) + 2,
3240 if (!hotkey_dev_attributes
)
3242 res
= add_many_to_attr_set(hotkey_dev_attributes
,
3244 ARRAY_SIZE(hotkey_attributes
));
3248 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
3249 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
3250 for HKEY interface version 0x100 */
3251 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
3252 if ((hkeyv
>> 8) != 1) {
3253 printk(TPACPI_ERR
"unknown version of the "
3254 "HKEY interface: 0x%x\n", hkeyv
);
3255 printk(TPACPI_ERR
"please report this to %s\n",
3259 * MHKV 0x100 in A31, R40, R40e,
3260 * T4x, X31, and later
3262 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3263 "firmware HKEY interface version: 0x%x\n",
3266 /* Paranoia check AND init hotkey_all_mask */
3267 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
3270 "missing MHKA handler, "
3271 "please report this to %s\n",
3273 /* Fallback: pre-init for FN+F3,F4,F12 */
3274 hotkey_all_mask
= 0x080cU
;
3276 tp_features
.hotkey_mask
= 1;
3281 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3282 "hotkey masks are %s\n",
3283 str_supported(tp_features
.hotkey_mask
));
3285 /* Init hotkey_all_mask if not initialized yet */
3286 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
3287 (quirks
& TPACPI_HK_Q_INIMASK
))
3288 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
3290 /* Init hotkey_acpi_mask and hotkey_orig_mask */
3291 if (tp_features
.hotkey_mask
) {
3292 /* hotkey_source_mask *must* be zero for
3293 * the first hotkey_mask_get to return hotkey_orig_mask */
3294 res
= hotkey_mask_get();
3298 hotkey_orig_mask
= hotkey_acpi_mask
;
3300 hotkey_orig_mask
= hotkey_all_mask
;
3301 hotkey_acpi_mask
= hotkey_all_mask
;
3304 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3306 tp_features
.hotkey_wlsw
= 1;
3307 radiosw_state
= !!tpacpi_wlsw_emulstate
;
3309 "radio switch emulation enabled\n");
3312 /* Not all thinkpads have a hardware radio switch */
3313 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3314 tp_features
.hotkey_wlsw
= 1;
3315 radiosw_state
= !!status
;
3317 "radio switch found; radios are %s\n",
3318 enabled(status
, 0));
3320 if (tp_features
.hotkey_wlsw
)
3321 res
= add_to_attr_set(hotkey_dev_attributes
,
3322 &dev_attr_hotkey_radio_sw
.attr
);
3324 /* For X41t, X60t, X61t Tablets... */
3325 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3326 tp_features
.hotkey_tablet
= 1;
3327 tabletsw_state
= !!(status
& TP_HOTKEY_TABLET_MASK
);
3329 "possible tablet mode switch found; "
3330 "ThinkPad in %s mode\n",
3331 (tabletsw_state
) ? "tablet" : "laptop");
3332 res
= add_to_attr_set(hotkey_dev_attributes
,
3333 &dev_attr_hotkey_tablet_mode
.attr
);
3337 res
= register_attr_set_with_sysfs(
3338 hotkey_dev_attributes
,
3339 &tpacpi_pdev
->dev
.kobj
);
3343 /* Set up key map */
3345 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3347 if (!hotkey_keycode_map
) {
3349 "failed to allocate memory for key map\n");
3354 if (tpacpi_is_lenovo()) {
3355 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3356 "using Lenovo default hot key map\n");
3357 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
3358 TPACPI_HOTKEY_MAP_SIZE
);
3360 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3361 "using IBM default hot key map\n");
3362 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
3363 TPACPI_HOTKEY_MAP_SIZE
);
3366 input_set_capability(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
);
3367 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3368 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3369 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3370 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3371 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3372 input_set_capability(tpacpi_inputdev
, EV_KEY
,
3373 hotkey_keycode_map
[i
]);
3375 if (i
< sizeof(hotkey_reserved_mask
)*8)
3376 hotkey_reserved_mask
|= 1 << i
;
3380 if (tp_features
.hotkey_wlsw
) {
3381 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_RFKILL_ALL
);
3382 input_report_switch(tpacpi_inputdev
,
3383 SW_RFKILL_ALL
, radiosw_state
);
3385 if (tp_features
.hotkey_tablet
) {
3386 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_TABLET_MODE
);
3387 input_report_switch(tpacpi_inputdev
,
3388 SW_TABLET_MODE
, tabletsw_state
);
3391 /* Do not issue duplicate brightness change events to
3392 * userspace. tpacpi_detect_brightness_capabilities() must have
3393 * been called before this point */
3394 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
3396 "This ThinkPad has standard ACPI backlight "
3397 "brightness control, supported by the ACPI "
3399 printk(TPACPI_NOTICE
3400 "Disabling thinkpad-acpi brightness events "
3403 /* Disable brightness up/down on Lenovo thinkpads when
3404 * ACPI is handling them, otherwise it is plain impossible
3405 * for userspace to do something even remotely sane */
3406 hotkey_reserved_mask
|=
3407 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3408 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3409 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3410 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3413 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3414 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3416 & ~hotkey_reserved_mask
;
3418 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3419 "hotkey source mask 0x%08x, polling freq %u\n",
3420 hotkey_source_mask
, hotkey_poll_freq
);
3423 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3424 "enabling firmware HKEY event interface...\n");
3425 res
= hotkey_status_set(true);
3430 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3431 | hotkey_driver_mask
)
3432 & ~hotkey_source_mask
);
3433 if (res
< 0 && res
!= -ENXIO
) {
3437 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3438 & ~hotkey_reserved_mask
;
3439 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3440 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3441 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3443 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3444 "legacy ibm/hotkey event reporting over procfs %s\n",
3445 (hotkey_report_mode
< 2) ?
3446 "enabled" : "disabled");
3448 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3449 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3451 hotkey_poll_setup_safe(true);
3456 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3457 hotkey_dev_attributes
= NULL
;
3459 return (res
< 0)? res
: 1;
3462 static bool hotkey_notify_hotkey(const u32 hkey
,
3464 bool *ignore_acpi_ev
)
3466 /* 0x1000-0x1FFF: key presses */
3467 unsigned int scancode
= hkey
& 0xfff;
3468 *send_acpi_ev
= true;
3469 *ignore_acpi_ev
= false;
3471 if (scancode
> 0 && scancode
< 0x21) {
3473 if (!(hotkey_source_mask
& (1 << scancode
))) {
3474 tpacpi_input_send_key_masked(scancode
);
3475 *send_acpi_ev
= false;
3477 *ignore_acpi_ev
= true;
3484 static bool hotkey_notify_wakeup(const u32 hkey
,
3486 bool *ignore_acpi_ev
)
3488 /* 0x2000-0x2FFF: Wakeup reason */
3489 *send_acpi_ev
= true;
3490 *ignore_acpi_ev
= false;
3493 case TP_HKEY_EV_WKUP_S3_UNDOCK
: /* suspend, undock */
3494 case TP_HKEY_EV_WKUP_S4_UNDOCK
: /* hibernation, undock */
3495 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3496 *ignore_acpi_ev
= true;
3499 case TP_HKEY_EV_WKUP_S3_BAYEJ
: /* suspend, bay eject */
3500 case TP_HKEY_EV_WKUP_S4_BAYEJ
: /* hibernation, bay eject */
3501 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3502 *ignore_acpi_ev
= true;
3505 case TP_HKEY_EV_WKUP_S3_BATLOW
: /* Battery on critical low level/S3 */
3506 case TP_HKEY_EV_WKUP_S4_BATLOW
: /* Battery on critical low level/S4 */
3508 "EMERGENCY WAKEUP: battery almost empty\n");
3509 /* how to auto-heal: */
3510 /* 2313: woke up from S3, go to S4/S5 */
3511 /* 2413: woke up from S4, go to S5 */
3518 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3520 "woke up due to a hot-unplug "
3522 hotkey_wakeup_reason_notify_change();
3527 static bool hotkey_notify_usrevent(const u32 hkey
,
3529 bool *ignore_acpi_ev
)
3531 /* 0x5000-0x5FFF: human interface helpers */
3532 *send_acpi_ev
= true;
3533 *ignore_acpi_ev
= false;
3536 case TP_HKEY_EV_PEN_INSERTED
: /* X61t: tablet pen inserted into bay */
3537 case TP_HKEY_EV_PEN_REMOVED
: /* X61t: tablet pen removed from bay */
3540 case TP_HKEY_EV_TABLET_TABLET
: /* X41t-X61t: tablet mode */
3541 case TP_HKEY_EV_TABLET_NOTEBOOK
: /* X41t-X61t: normal mode */
3542 tpacpi_input_send_tabletsw();
3543 hotkey_tablet_mode_notify_change();
3544 *send_acpi_ev
= false;
3547 case TP_HKEY_EV_LID_CLOSE
: /* Lid closed */
3548 case TP_HKEY_EV_LID_OPEN
: /* Lid opened */
3549 case TP_HKEY_EV_BRGHT_CHANGED
: /* brightness changed */
3550 /* do not propagate these events */
3551 *ignore_acpi_ev
= true;
3559 static void thermal_dump_all_sensors(void);
3561 static bool hotkey_notify_thermal(const u32 hkey
,
3563 bool *ignore_acpi_ev
)
3567 /* 0x6000-0x6FFF: thermal alarms */
3568 *send_acpi_ev
= true;
3569 *ignore_acpi_ev
= false;
3572 case TP_HKEY_EV_THM_TABLE_CHANGED
:
3574 "EC reports that Thermal Table has changed\n");
3575 /* recommended action: do nothing, we don't have
3576 * Lenovo ATM information */
3578 case TP_HKEY_EV_ALARM_BAT_HOT
:
3580 "THERMAL ALARM: battery is too hot!\n");
3581 /* recommended action: warn user through gui */
3583 case TP_HKEY_EV_ALARM_BAT_XHOT
:
3585 "THERMAL EMERGENCY: battery is extremely hot!\n");
3586 /* recommended action: immediate sleep/hibernate */
3588 case TP_HKEY_EV_ALARM_SENSOR_HOT
:
3591 "a sensor reports something is too hot!\n");
3592 /* recommended action: warn user through gui, that */
3593 /* some internal component is too hot */
3595 case TP_HKEY_EV_ALARM_SENSOR_XHOT
:
3597 "THERMAL EMERGENCY: "
3598 "a sensor reports something is extremely hot!\n");
3599 /* recommended action: immediate sleep/hibernate */
3603 "THERMAL ALERT: unknown thermal alarm received\n");
3607 thermal_dump_all_sensors();
3612 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3616 bool ignore_acpi_ev
;
3619 if (event
!= 0x80) {
3621 "unknown HKEY notification event %d\n", event
);
3622 /* forward it to userspace, maybe it knows how to handle it */
3623 acpi_bus_generate_netlink_event(
3624 ibm
->acpi
->device
->pnp
.device_class
,
3625 dev_name(&ibm
->acpi
->device
->dev
),
3631 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3632 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3641 send_acpi_ev
= true;
3642 ignore_acpi_ev
= false;
3644 switch (hkey
>> 12) {
3646 /* 0x1000-0x1FFF: key presses */
3647 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3651 /* 0x2000-0x2FFF: Wakeup reason */
3652 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3656 /* 0x3000-0x3FFF: bay-related wakeups */
3658 case TP_HKEY_EV_BAYEJ_ACK
:
3659 hotkey_autosleep_ack
= 1;
3662 hotkey_wakeup_hotunplug_complete_notify_change();
3665 case TP_HKEY_EV_OPTDRV_EJ
:
3666 /* FIXME: kick libata if SATA link offline */
3674 /* 0x4000-0x4FFF: dock-related wakeups */
3675 if (hkey
== TP_HKEY_EV_UNDOCK_ACK
) {
3676 hotkey_autosleep_ack
= 1;
3679 hotkey_wakeup_hotunplug_complete_notify_change();
3686 /* 0x5000-0x5FFF: human interface helpers */
3687 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3691 /* 0x6000-0x6FFF: thermal alarms */
3692 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3696 /* 0x7000-0x7FFF: misc */
3697 if (tp_features
.hotkey_wlsw
&&
3698 hkey
== TP_HKEY_EV_RFKILL_CHANGED
) {
3699 tpacpi_send_radiosw_update();
3704 /* fallthrough to default */
3709 printk(TPACPI_NOTICE
3710 "unhandled HKEY event 0x%04x\n", hkey
);
3711 printk(TPACPI_NOTICE
3712 "please report the conditions when this "
3713 "event happened to %s\n", TPACPI_MAIL
);
3717 if (!ignore_acpi_ev
&&
3718 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3719 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3723 /* netlink events */
3724 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3725 acpi_bus_generate_netlink_event(
3726 ibm
->acpi
->device
->pnp
.device_class
,
3727 dev_name(&ibm
->acpi
->device
->dev
),
3733 static void hotkey_suspend(pm_message_t state
)
3735 /* Do these on suspend, we get the events on early resume! */
3736 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3737 hotkey_autosleep_ack
= 0;
3740 static void hotkey_resume(void)
3742 tpacpi_disable_brightness_delay();
3744 if (hotkey_status_set(true) < 0 ||
3745 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3747 "error while attempting to reset the event "
3748 "firmware interface\n");
3750 tpacpi_send_radiosw_update();
3751 hotkey_tablet_mode_notify_change();
3752 hotkey_wakeup_reason_notify_change();
3753 hotkey_wakeup_hotunplug_complete_notify_change();
3754 hotkey_poll_setup_safe(false);
3757 /* procfs -------------------------------------------------------------- */
3758 static int hotkey_read(struct seq_file
*m
)
3762 if (!tp_features
.hotkey
) {
3763 seq_printf(m
, "status:\t\tnot supported\n");
3767 if (mutex_lock_killable(&hotkey_mutex
))
3768 return -ERESTARTSYS
;
3769 res
= hotkey_status_get(&status
);
3771 res
= hotkey_mask_get();
3772 mutex_unlock(&hotkey_mutex
);
3776 seq_printf(m
, "status:\t\t%s\n", enabled(status
, 0));
3777 if (hotkey_all_mask
) {
3778 seq_printf(m
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3779 seq_printf(m
, "commands:\tenable, disable, reset, <mask>\n");
3781 seq_printf(m
, "mask:\t\tnot supported\n");
3782 seq_printf(m
, "commands:\tenable, disable, reset\n");
3788 static void hotkey_enabledisable_warn(bool enable
)
3790 tpacpi_log_usertask("procfs hotkey enable/disable");
3791 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3793 "hotkey enable/disable functionality has been "
3794 "removed from the driver. Hotkeys are always "
3797 "Please remove the hotkey=enable module "
3798 "parameter, it is deprecated. Hotkeys are always "
3802 static int hotkey_write(char *buf
)
3808 if (!tp_features
.hotkey
)
3811 if (mutex_lock_killable(&hotkey_mutex
))
3812 return -ERESTARTSYS
;
3814 mask
= hotkey_user_mask
;
3817 while ((cmd
= next_cmd(&buf
))) {
3818 if (strlencmp(cmd
, "enable") == 0) {
3819 hotkey_enabledisable_warn(1);
3820 } else if (strlencmp(cmd
, "disable") == 0) {
3821 hotkey_enabledisable_warn(0);
3823 } else if (strlencmp(cmd
, "reset") == 0) {
3824 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3825 & ~hotkey_reserved_mask
;
3826 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3828 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3837 tpacpi_disclose_usertask("procfs hotkey",
3838 "set mask to 0x%08x\n", mask
);
3839 res
= hotkey_user_mask_set(mask
);
3843 mutex_unlock(&hotkey_mutex
);
3847 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3848 {TPACPI_ACPI_HKEY_HID
, 0},
3852 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3853 .hid
= ibm_htk_device_ids
,
3854 .notify
= hotkey_notify
,
3855 .handle
= &hkey_handle
,
3856 .type
= ACPI_DEVICE_NOTIFY
,
3859 static struct ibm_struct hotkey_driver_data
= {
3861 .read
= hotkey_read
,
3862 .write
= hotkey_write
,
3863 .exit
= hotkey_exit
,
3864 .resume
= hotkey_resume
,
3865 .suspend
= hotkey_suspend
,
3866 .acpi
= &ibm_hotkey_acpidriver
,
3869 /*************************************************************************
3870 * Bluetooth subdriver
3874 /* ACPI GBDC/SBDC bits */
3875 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3876 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3877 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3878 0 = disable, 1 = enable */
3882 /* ACPI \BLTH commands */
3883 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3884 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3885 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3886 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3887 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3890 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3892 static int bluetooth_get_status(void)
3896 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3897 if (dbg_bluetoothemul
)
3898 return (tpacpi_bluetooth_emulstate
) ?
3899 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3902 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3905 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3906 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3909 static int bluetooth_set_status(enum tpacpi_rfkill_state state
)
3913 vdbg_printk(TPACPI_DBG_RFKILL
,
3914 "will attempt to %s bluetooth\n",
3915 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
3917 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3918 if (dbg_bluetoothemul
) {
3919 tpacpi_bluetooth_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
3924 if (state
== TPACPI_RFK_RADIO_ON
)
3925 status
= TP_ACPI_BLUETOOTH_RADIOSSW
3926 | TP_ACPI_BLUETOOTH_RESUMECTRL
;
3930 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3936 /* sysfs bluetooth enable ---------------------------------------------- */
3937 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3938 struct device_attribute
*attr
,
3941 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID
,
3945 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3946 struct device_attribute
*attr
,
3947 const char *buf
, size_t count
)
3949 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID
,
3953 static struct device_attribute dev_attr_bluetooth_enable
=
3954 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3955 bluetooth_enable_show
, bluetooth_enable_store
);
3957 /* --------------------------------------------------------------------- */
3959 static struct attribute
*bluetooth_attributes
[] = {
3960 &dev_attr_bluetooth_enable
.attr
,
3964 static const struct attribute_group bluetooth_attr_group
= {
3965 .attrs
= bluetooth_attributes
,
3968 static const struct tpacpi_rfk_ops bluetooth_tprfk_ops
= {
3969 .get_status
= bluetooth_get_status
,
3970 .set_status
= bluetooth_set_status
,
3973 static void bluetooth_shutdown(void)
3975 /* Order firmware to save current state to NVRAM */
3976 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3977 TP_ACPI_BLTH_SAVE_STATE
))
3978 printk(TPACPI_NOTICE
3979 "failed to save bluetooth state to NVRAM\n");
3981 vdbg_printk(TPACPI_DBG_RFKILL
,
3982 "bluestooth state saved to NVRAM\n");
3985 static void bluetooth_exit(void)
3987 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3988 &bluetooth_attr_group
);
3990 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
3992 bluetooth_shutdown();
3995 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
4000 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4001 "initializing bluetooth subdriver\n");
4003 TPACPI_ACPIHANDLE_INIT(hkey
);
4005 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4006 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
4007 tp_features
.bluetooth
= hkey_handle
&&
4008 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
4010 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4011 "bluetooth is %s, status 0x%02x\n",
4012 str_supported(tp_features
.bluetooth
),
4015 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4016 if (dbg_bluetoothemul
) {
4017 tp_features
.bluetooth
= 1;
4019 "bluetooth switch emulation enabled\n");
4022 if (tp_features
.bluetooth
&&
4023 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
4024 /* no bluetooth hardware present in system */
4025 tp_features
.bluetooth
= 0;
4026 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4027 "bluetooth hardware not installed\n");
4030 if (!tp_features
.bluetooth
)
4033 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
4034 &bluetooth_tprfk_ops
,
4035 RFKILL_TYPE_BLUETOOTH
,
4036 TPACPI_RFK_BLUETOOTH_SW_NAME
,
4041 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4042 &bluetooth_attr_group
);
4044 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
4051 /* procfs -------------------------------------------------------------- */
4052 static int bluetooth_read(struct seq_file
*m
)
4054 return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID
, m
);
4057 static int bluetooth_write(char *buf
)
4059 return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID
, buf
);
4062 static struct ibm_struct bluetooth_driver_data
= {
4063 .name
= "bluetooth",
4064 .read
= bluetooth_read
,
4065 .write
= bluetooth_write
,
4066 .exit
= bluetooth_exit
,
4067 .shutdown
= bluetooth_shutdown
,
4070 /*************************************************************************
4075 /* ACPI GWAN/SWAN bits */
4076 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
4077 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
4078 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
4079 0 = disable, 1 = enable */
4082 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
4084 static int wan_get_status(void)
4088 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4090 return (tpacpi_wwan_emulstate
) ?
4091 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4094 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
4097 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
4098 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4101 static int wan_set_status(enum tpacpi_rfkill_state state
)
4105 vdbg_printk(TPACPI_DBG_RFKILL
,
4106 "will attempt to %s wwan\n",
4107 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4109 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4111 tpacpi_wwan_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4116 if (state
== TPACPI_RFK_RADIO_ON
)
4117 status
= TP_ACPI_WANCARD_RADIOSSW
4118 | TP_ACPI_WANCARD_RESUMECTRL
;
4122 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
4128 /* sysfs wan enable ---------------------------------------------------- */
4129 static ssize_t
wan_enable_show(struct device
*dev
,
4130 struct device_attribute
*attr
,
4133 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID
,
4137 static ssize_t
wan_enable_store(struct device
*dev
,
4138 struct device_attribute
*attr
,
4139 const char *buf
, size_t count
)
4141 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID
,
4145 static struct device_attribute dev_attr_wan_enable
=
4146 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4147 wan_enable_show
, wan_enable_store
);
4149 /* --------------------------------------------------------------------- */
4151 static struct attribute
*wan_attributes
[] = {
4152 &dev_attr_wan_enable
.attr
,
4156 static const struct attribute_group wan_attr_group
= {
4157 .attrs
= wan_attributes
,
4160 static const struct tpacpi_rfk_ops wan_tprfk_ops
= {
4161 .get_status
= wan_get_status
,
4162 .set_status
= wan_set_status
,
4165 static void wan_shutdown(void)
4167 /* Order firmware to save current state to NVRAM */
4168 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4169 TP_ACPI_WGSV_SAVE_STATE
))
4170 printk(TPACPI_NOTICE
4171 "failed to save WWAN state to NVRAM\n");
4173 vdbg_printk(TPACPI_DBG_RFKILL
,
4174 "WWAN state saved to NVRAM\n");
4177 static void wan_exit(void)
4179 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4182 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4187 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4192 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4193 "initializing wan subdriver\n");
4195 TPACPI_ACPIHANDLE_INIT(hkey
);
4197 tp_features
.wan
= hkey_handle
&&
4198 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4200 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4201 "wan is %s, status 0x%02x\n",
4202 str_supported(tp_features
.wan
),
4205 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4207 tp_features
.wan
= 1;
4209 "wwan switch emulation enabled\n");
4212 if (tp_features
.wan
&&
4213 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4214 /* no wan hardware present in system */
4215 tp_features
.wan
= 0;
4216 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4217 "wan hardware not installed\n");
4220 if (!tp_features
.wan
)
4223 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4226 TPACPI_RFK_WWAN_SW_NAME
,
4231 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4235 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4242 /* procfs -------------------------------------------------------------- */
4243 static int wan_read(struct seq_file
*m
)
4245 return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID
, m
);
4248 static int wan_write(char *buf
)
4250 return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID
, buf
);
4253 static struct ibm_struct wan_driver_data
= {
4258 .shutdown
= wan_shutdown
,
4261 /*************************************************************************
4266 /* ACPI GUWB/SUWB bits */
4267 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4268 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4271 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4273 static int uwb_get_status(void)
4277 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4279 return (tpacpi_uwb_emulstate
) ?
4280 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4283 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4286 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4287 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4290 static int uwb_set_status(enum tpacpi_rfkill_state state
)
4294 vdbg_printk(TPACPI_DBG_RFKILL
,
4295 "will attempt to %s UWB\n",
4296 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4298 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4300 tpacpi_uwb_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4305 if (state
== TPACPI_RFK_RADIO_ON
)
4306 status
= TP_ACPI_UWB_RADIOSSW
;
4310 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4316 /* --------------------------------------------------------------------- */
4318 static const struct tpacpi_rfk_ops uwb_tprfk_ops
= {
4319 .get_status
= uwb_get_status
,
4320 .set_status
= uwb_set_status
,
4323 static void uwb_exit(void)
4325 tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID
);
4328 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4333 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4334 "initializing uwb subdriver\n");
4336 TPACPI_ACPIHANDLE_INIT(hkey
);
4338 tp_features
.uwb
= hkey_handle
&&
4339 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4341 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4342 "uwb is %s, status 0x%02x\n",
4343 str_supported(tp_features
.uwb
),
4346 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4348 tp_features
.uwb
= 1;
4350 "uwb switch emulation enabled\n");
4353 if (tp_features
.uwb
&&
4354 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4355 /* no uwb hardware present in system */
4356 tp_features
.uwb
= 0;
4357 dbg_printk(TPACPI_DBG_INIT
,
4358 "uwb hardware not installed\n");
4361 if (!tp_features
.uwb
)
4364 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4367 TPACPI_RFK_UWB_SW_NAME
,
4372 static struct ibm_struct uwb_driver_data
= {
4375 .flags
.experimental
= 1,
4378 /*************************************************************************
4382 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4384 enum video_access_mode
{
4385 TPACPI_VIDEO_NONE
= 0,
4386 TPACPI_VIDEO_570
, /* 570 */
4387 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4388 TPACPI_VIDEO_NEW
, /* all others */
4391 enum { /* video status flags, based on VIDEO_570 */
4392 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4393 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4394 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4397 enum { /* TPACPI_VIDEO_570 constants */
4398 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4399 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4400 * video_status_flags */
4401 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4402 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4405 static enum video_access_mode video_supported
;
4406 static int video_orig_autosw
;
4408 static int video_autosw_get(void);
4409 static int video_autosw_set(int enable
);
4411 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4413 static int __init
video_init(struct ibm_init_struct
*iibm
)
4417 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4419 TPACPI_ACPIHANDLE_INIT(vid
);
4420 if (tpacpi_is_ibm())
4421 TPACPI_ACPIHANDLE_INIT(vid2
);
4423 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4424 /* G41, assume IVGA doesn't change */
4425 vid_handle
= vid2_handle
;
4428 /* video switching not supported on R30, R31 */
4429 video_supported
= TPACPI_VIDEO_NONE
;
4430 else if (tpacpi_is_ibm() &&
4431 acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4433 video_supported
= TPACPI_VIDEO_570
;
4434 else if (tpacpi_is_ibm() &&
4435 acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4436 /* 600e/x, 770e, 770x */
4437 video_supported
= TPACPI_VIDEO_770
;
4440 video_supported
= TPACPI_VIDEO_NEW
;
4442 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4443 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4446 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4449 static void video_exit(void)
4451 dbg_printk(TPACPI_DBG_EXIT
,
4452 "restoring original video autoswitch mode\n");
4453 if (video_autosw_set(video_orig_autosw
))
4454 printk(TPACPI_ERR
"error while trying to restore original "
4455 "video autoswitch mode\n");
4458 static int video_outputsw_get(void)
4463 switch (video_supported
) {
4464 case TPACPI_VIDEO_570
:
4465 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4466 TP_ACPI_VIDEO_570_PHSCMD
))
4468 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4470 case TPACPI_VIDEO_770
:
4471 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4474 status
|= TP_ACPI_VIDEO_S_LCD
;
4475 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4478 status
|= TP_ACPI_VIDEO_S_CRT
;
4480 case TPACPI_VIDEO_NEW
:
4481 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4482 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4485 status
|= TP_ACPI_VIDEO_S_CRT
;
4487 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4488 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4491 status
|= TP_ACPI_VIDEO_S_LCD
;
4492 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4495 status
|= TP_ACPI_VIDEO_S_DVI
;
4504 static int video_outputsw_set(int status
)
4509 switch (video_supported
) {
4510 case TPACPI_VIDEO_570
:
4511 res
= acpi_evalf(NULL
, NULL
,
4512 "\\_SB.PHS2", "vdd",
4513 TP_ACPI_VIDEO_570_PHS2CMD
,
4514 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4516 case TPACPI_VIDEO_770
:
4517 autosw
= video_autosw_get();
4521 res
= video_autosw_set(1);
4524 res
= acpi_evalf(vid_handle
, NULL
,
4525 "ASWT", "vdd", status
* 0x100, 0);
4526 if (!autosw
&& video_autosw_set(autosw
)) {
4528 "video auto-switch left enabled due to error\n");
4532 case TPACPI_VIDEO_NEW
:
4533 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4534 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4540 return (res
)? 0 : -EIO
;
4543 static int video_autosw_get(void)
4547 switch (video_supported
) {
4548 case TPACPI_VIDEO_570
:
4549 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4552 case TPACPI_VIDEO_770
:
4553 case TPACPI_VIDEO_NEW
:
4554 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4564 static int video_autosw_set(int enable
)
4566 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4571 static int video_outputsw_cycle(void)
4573 int autosw
= video_autosw_get();
4579 switch (video_supported
) {
4580 case TPACPI_VIDEO_570
:
4581 res
= video_autosw_set(1);
4584 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4586 case TPACPI_VIDEO_770
:
4587 case TPACPI_VIDEO_NEW
:
4588 res
= video_autosw_set(1);
4591 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4596 if (!autosw
&& video_autosw_set(autosw
)) {
4598 "video auto-switch left enabled due to error\n");
4602 return (res
)? 0 : -EIO
;
4605 static int video_expand_toggle(void)
4607 switch (video_supported
) {
4608 case TPACPI_VIDEO_570
:
4609 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4611 case TPACPI_VIDEO_770
:
4612 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4614 case TPACPI_VIDEO_NEW
:
4615 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4623 static int video_read(struct seq_file
*m
)
4627 if (video_supported
== TPACPI_VIDEO_NONE
) {
4628 seq_printf(m
, "status:\t\tnot supported\n");
4632 /* Even reads can crash X.org, so... */
4633 if (!capable(CAP_SYS_ADMIN
))
4636 status
= video_outputsw_get();
4640 autosw
= video_autosw_get();
4644 seq_printf(m
, "status:\t\tsupported\n");
4645 seq_printf(m
, "lcd:\t\t%s\n", enabled(status
, 0));
4646 seq_printf(m
, "crt:\t\t%s\n", enabled(status
, 1));
4647 if (video_supported
== TPACPI_VIDEO_NEW
)
4648 seq_printf(m
, "dvi:\t\t%s\n", enabled(status
, 3));
4649 seq_printf(m
, "auto:\t\t%s\n", enabled(autosw
, 0));
4650 seq_printf(m
, "commands:\tlcd_enable, lcd_disable\n");
4651 seq_printf(m
, "commands:\tcrt_enable, crt_disable\n");
4652 if (video_supported
== TPACPI_VIDEO_NEW
)
4653 seq_printf(m
, "commands:\tdvi_enable, dvi_disable\n");
4654 seq_printf(m
, "commands:\tauto_enable, auto_disable\n");
4655 seq_printf(m
, "commands:\tvideo_switch, expand_toggle\n");
4660 static int video_write(char *buf
)
4663 int enable
, disable
, status
;
4666 if (video_supported
== TPACPI_VIDEO_NONE
)
4669 /* Even reads can crash X.org, let alone writes... */
4670 if (!capable(CAP_SYS_ADMIN
))
4676 while ((cmd
= next_cmd(&buf
))) {
4677 if (strlencmp(cmd
, "lcd_enable") == 0) {
4678 enable
|= TP_ACPI_VIDEO_S_LCD
;
4679 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4680 disable
|= TP_ACPI_VIDEO_S_LCD
;
4681 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4682 enable
|= TP_ACPI_VIDEO_S_CRT
;
4683 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4684 disable
|= TP_ACPI_VIDEO_S_CRT
;
4685 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4686 strlencmp(cmd
, "dvi_enable") == 0) {
4687 enable
|= TP_ACPI_VIDEO_S_DVI
;
4688 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4689 strlencmp(cmd
, "dvi_disable") == 0) {
4690 disable
|= TP_ACPI_VIDEO_S_DVI
;
4691 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4692 res
= video_autosw_set(1);
4695 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4696 res
= video_autosw_set(0);
4699 } else if (strlencmp(cmd
, "video_switch") == 0) {
4700 res
= video_outputsw_cycle();
4703 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4704 res
= video_expand_toggle();
4711 if (enable
|| disable
) {
4712 status
= video_outputsw_get();
4715 res
= video_outputsw_set((status
& ~disable
) | enable
);
4723 static struct ibm_struct video_driver_data
= {
4726 .write
= video_write
,
4730 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4732 /*************************************************************************
4733 * Light (thinklight) subdriver
4736 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4737 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4739 static int light_get_status(void)
4743 if (tp_features
.light_status
) {
4744 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4752 static int light_set_status(int status
)
4756 if (tp_features
.light
) {
4758 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4760 TP_CMOS_THINKLIGHT_ON
:
4761 TP_CMOS_THINKLIGHT_OFF
);
4763 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4766 return (rc
)? 0 : -EIO
;
4772 static void light_set_status_worker(struct work_struct
*work
)
4774 struct tpacpi_led_classdev
*data
=
4775 container_of(work
, struct tpacpi_led_classdev
, work
);
4777 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4778 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4781 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4782 enum led_brightness brightness
)
4784 struct tpacpi_led_classdev
*data
=
4785 container_of(led_cdev
,
4786 struct tpacpi_led_classdev
,
4788 data
->new_state
= (brightness
!= LED_OFF
) ?
4789 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4790 queue_work(tpacpi_wq
, &data
->work
);
4793 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4795 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4798 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4800 .name
= "tpacpi::thinklight",
4801 .brightness_set
= &light_sysfs_set
,
4802 .brightness_get
= &light_sysfs_get
,
4806 static int __init
light_init(struct ibm_init_struct
*iibm
)
4810 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4812 if (tpacpi_is_ibm()) {
4813 TPACPI_ACPIHANDLE_INIT(ledb
);
4814 TPACPI_ACPIHANDLE_INIT(lght
);
4816 TPACPI_ACPIHANDLE_INIT(cmos
);
4817 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4819 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4820 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4822 if (tp_features
.light
)
4823 /* light status not supported on
4824 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4825 tp_features
.light_status
=
4826 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4828 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4829 str_supported(tp_features
.light
),
4830 str_supported(tp_features
.light_status
));
4832 if (!tp_features
.light
)
4835 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4836 &tpacpi_led_thinklight
.led_classdev
);
4839 tp_features
.light
= 0;
4840 tp_features
.light_status
= 0;
4848 static void light_exit(void)
4850 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4851 if (work_pending(&tpacpi_led_thinklight
.work
))
4852 flush_workqueue(tpacpi_wq
);
4855 static int light_read(struct seq_file
*m
)
4859 if (!tp_features
.light
) {
4860 seq_printf(m
, "status:\t\tnot supported\n");
4861 } else if (!tp_features
.light_status
) {
4862 seq_printf(m
, "status:\t\tunknown\n");
4863 seq_printf(m
, "commands:\ton, off\n");
4865 status
= light_get_status();
4868 seq_printf(m
, "status:\t\t%s\n", onoff(status
, 0));
4869 seq_printf(m
, "commands:\ton, off\n");
4875 static int light_write(char *buf
)
4880 if (!tp_features
.light
)
4883 while ((cmd
= next_cmd(&buf
))) {
4884 if (strlencmp(cmd
, "on") == 0) {
4886 } else if (strlencmp(cmd
, "off") == 0) {
4892 return light_set_status(newstatus
);
4895 static struct ibm_struct light_driver_data
= {
4898 .write
= light_write
,
4902 /*************************************************************************
4906 /* sysfs cmos_command -------------------------------------------------- */
4907 static ssize_t
cmos_command_store(struct device
*dev
,
4908 struct device_attribute
*attr
,
4909 const char *buf
, size_t count
)
4911 unsigned long cmos_cmd
;
4914 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4917 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4918 return (res
)? res
: count
;
4921 static struct device_attribute dev_attr_cmos_command
=
4922 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4924 /* --------------------------------------------------------------------- */
4926 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4930 vdbg_printk(TPACPI_DBG_INIT
,
4931 "initializing cmos commands subdriver\n");
4933 TPACPI_ACPIHANDLE_INIT(cmos
);
4935 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4936 str_supported(cmos_handle
!= NULL
));
4938 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4942 return (cmos_handle
)? 0 : 1;
4945 static void cmos_exit(void)
4947 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4950 static int cmos_read(struct seq_file
*m
)
4952 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4953 R30, R31, T20-22, X20-21 */
4955 seq_printf(m
, "status:\t\tnot supported\n");
4957 seq_printf(m
, "status:\t\tsupported\n");
4958 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4964 static int cmos_write(char *buf
)
4969 while ((cmd
= next_cmd(&buf
))) {
4970 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4971 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4976 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4984 static struct ibm_struct cmos_driver_data
= {
4987 .write
= cmos_write
,
4991 /*************************************************************************
4995 enum led_access_mode
{
4996 TPACPI_LED_NONE
= 0,
4997 TPACPI_LED_570
, /* 570 */
4998 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4999 TPACPI_LED_NEW
, /* all others */
5002 enum { /* For TPACPI_LED_OLD */
5003 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
5004 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
5005 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
5008 static enum led_access_mode led_supported
;
5010 static acpi_handle led_handle
;
5012 #define TPACPI_LED_NUMLEDS 16
5013 static struct tpacpi_led_classdev
*tpacpi_leds
;
5014 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
5015 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
5016 /* there's a limit of 19 chars + NULL before 2.6.26 */
5018 "tpacpi:orange:batt",
5019 "tpacpi:green:batt",
5020 "tpacpi::dock_active",
5021 "tpacpi::bay_active",
5022 "tpacpi::dock_batt",
5023 "tpacpi::unknown_led",
5025 "tpacpi::dock_status1",
5026 "tpacpi::dock_status2",
5027 "tpacpi::unknown_led2",
5028 "tpacpi::unknown_led3",
5029 "tpacpi::thinkvantage",
5031 #define TPACPI_SAFE_LEDS 0x1081U
5033 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
5035 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5038 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
5042 static int led_get_status(const unsigned int led
)
5045 enum led_status_t led_s
;
5047 switch (led_supported
) {
5048 case TPACPI_LED_570
:
5049 if (!acpi_evalf(ec_handle
,
5050 &status
, "GLED", "dd", 1 << led
))
5052 led_s
= (status
== 0)?
5057 tpacpi_led_state_cache
[led
] = led_s
;
5066 static int led_set_status(const unsigned int led
,
5067 const enum led_status_t ledstatus
)
5069 /* off, on, blink. Index is led_status_t */
5070 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
5071 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
5075 switch (led_supported
) {
5076 case TPACPI_LED_570
:
5078 if (unlikely(led
> 7))
5080 if (unlikely(tpacpi_is_led_restricted(led
)))
5082 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5083 (1 << led
), led_sled_arg1
[ledstatus
]))
5086 case TPACPI_LED_OLD
:
5087 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
5088 if (unlikely(led
> 7))
5090 if (unlikely(tpacpi_is_led_restricted(led
)))
5092 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
5094 rc
= ec_write(TPACPI_LED_EC_HLBL
,
5095 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5097 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5098 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5100 case TPACPI_LED_NEW
:
5102 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5104 if (unlikely(tpacpi_is_led_restricted(led
)))
5106 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5107 led
, led_led_arg1
[ledstatus
]))
5115 tpacpi_led_state_cache
[led
] = ledstatus
;
5120 static void led_set_status_worker(struct work_struct
*work
)
5122 struct tpacpi_led_classdev
*data
=
5123 container_of(work
, struct tpacpi_led_classdev
, work
);
5125 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5126 led_set_status(data
->led
, data
->new_state
);
5129 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5130 enum led_brightness brightness
)
5132 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5133 struct tpacpi_led_classdev
, led_classdev
);
5135 if (brightness
== LED_OFF
)
5136 data
->new_state
= TPACPI_LED_OFF
;
5137 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5138 data
->new_state
= TPACPI_LED_ON
;
5140 data
->new_state
= TPACPI_LED_BLINK
;
5142 queue_work(tpacpi_wq
, &data
->work
);
5145 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5146 unsigned long *delay_on
, unsigned long *delay_off
)
5148 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5149 struct tpacpi_led_classdev
, led_classdev
);
5151 /* Can we choose the flash rate? */
5152 if (*delay_on
== 0 && *delay_off
== 0) {
5153 /* yes. set them to the hardware blink rate (1 Hz) */
5154 *delay_on
= 500; /* ms */
5155 *delay_off
= 500; /* ms */
5156 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5159 data
->new_state
= TPACPI_LED_BLINK
;
5160 queue_work(tpacpi_wq
, &data
->work
);
5165 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5169 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5170 struct tpacpi_led_classdev
, led_classdev
);
5172 rc
= led_get_status(data
->led
);
5174 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5175 rc
= LED_OFF
; /* no error handling in led class :( */
5182 static void led_exit(void)
5186 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5187 if (tpacpi_leds
[i
].led_classdev
.name
)
5188 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5194 static int __init
tpacpi_init_led(unsigned int led
)
5198 tpacpi_leds
[led
].led
= led
;
5200 /* LEDs with no name don't get registered */
5201 if (!tpacpi_led_names
[led
])
5204 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5205 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5206 if (led_supported
== TPACPI_LED_570
)
5207 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5210 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5212 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5214 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5215 &tpacpi_leds
[led
].led_classdev
);
5217 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5222 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5223 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5224 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5225 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5227 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5228 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5229 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5230 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5231 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5232 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5233 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5234 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5236 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5237 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5238 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5239 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5240 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5242 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5243 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5244 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5245 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5247 /* (1) - may have excess leds enabled on MSB */
5249 /* Defaults (order matters, keep last, don't reorder!) */
5251 .vendor
= PCI_VENDOR_ID_LENOVO
,
5252 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5255 { /* IBM ThinkPads with no EC version string */
5256 .vendor
= PCI_VENDOR_ID_IBM
,
5257 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5260 { /* IBM ThinkPads with EC version string */
5261 .vendor
= PCI_VENDOR_ID_IBM
,
5262 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5267 #undef TPACPI_LEDQ_IBM
5268 #undef TPACPI_LEDQ_LNV
5270 static enum led_access_mode __init
led_init_detect_mode(void)
5274 if (tpacpi_is_ibm()) {
5276 status
= acpi_get_handle(ec_handle
, "SLED", &led_handle
);
5277 if (ACPI_SUCCESS(status
))
5278 return TPACPI_LED_570
;
5280 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5281 status
= acpi_get_handle(ec_handle
, "SYSL", &led_handle
);
5282 if (ACPI_SUCCESS(status
))
5283 return TPACPI_LED_OLD
;
5287 status
= acpi_get_handle(ec_handle
, "LED", &led_handle
);
5288 if (ACPI_SUCCESS(status
))
5289 return TPACPI_LED_NEW
;
5291 /* R30, R31, and unknown firmwares */
5293 return TPACPI_LED_NONE
;
5296 static int __init
led_init(struct ibm_init_struct
*iibm
)
5300 unsigned long useful_leds
;
5302 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5304 led_supported
= led_init_detect_mode();
5306 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5307 str_supported(led_supported
), led_supported
);
5309 if (led_supported
== TPACPI_LED_NONE
)
5312 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5315 printk(TPACPI_ERR
"Out of memory for LED data\n");
5319 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5320 ARRAY_SIZE(led_useful_qtable
));
5322 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5323 if (!tpacpi_is_led_restricted(i
) &&
5324 test_bit(i
, &useful_leds
)) {
5325 rc
= tpacpi_init_led(i
);
5333 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5334 printk(TPACPI_NOTICE
5335 "warning: userspace override of important "
5336 "firmware LEDs is enabled\n");
5341 #define str_led_status(s) \
5342 ((s) == TPACPI_LED_OFF ? "off" : \
5343 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5345 static int led_read(struct seq_file
*m
)
5347 if (!led_supported
) {
5348 seq_printf(m
, "status:\t\tnot supported\n");
5351 seq_printf(m
, "status:\t\tsupported\n");
5353 if (led_supported
== TPACPI_LED_570
) {
5356 for (i
= 0; i
< 8; i
++) {
5357 status
= led_get_status(i
);
5360 seq_printf(m
, "%d:\t\t%s\n",
5361 i
, str_led_status(status
));
5365 seq_printf(m
, "commands:\t"
5366 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5371 static int led_write(char *buf
)
5375 enum led_status_t s
;
5380 while ((cmd
= next_cmd(&buf
))) {
5381 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5384 if (strstr(cmd
, "off")) {
5386 } else if (strstr(cmd
, "on")) {
5388 } else if (strstr(cmd
, "blink")) {
5389 s
= TPACPI_LED_BLINK
;
5394 rc
= led_set_status(led
, s
);
5402 static struct ibm_struct led_driver_data
= {
5409 /*************************************************************************
5413 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5415 #define TPACPI_BEEP_Q1 0x0001
5417 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5418 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5419 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5422 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5424 unsigned long quirks
;
5426 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5428 TPACPI_ACPIHANDLE_INIT(beep
);
5430 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5431 str_supported(beep_handle
!= NULL
));
5433 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5434 ARRAY_SIZE(beep_quirk_table
));
5436 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5438 return (beep_handle
)? 0 : 1;
5441 static int beep_read(struct seq_file
*m
)
5444 seq_printf(m
, "status:\t\tnot supported\n");
5446 seq_printf(m
, "status:\t\tsupported\n");
5447 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5453 static int beep_write(char *buf
)
5461 while ((cmd
= next_cmd(&buf
))) {
5462 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5463 beep_cmd
>= 0 && beep_cmd
<= 17) {
5467 if (tp_features
.beep_needs_two_args
) {
5468 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5472 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5481 static struct ibm_struct beep_driver_data
= {
5484 .write
= beep_write
,
5487 /*************************************************************************
5491 enum thermal_access_mode
{
5492 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5493 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5494 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5495 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5496 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5499 enum { /* TPACPI_THERMAL_TPEC_* */
5500 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5501 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5502 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5504 TPACPI_THERMAL_SENSOR_NA
= -128000, /* Sensor not available */
5508 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5509 struct ibm_thermal_sensors_struct
{
5510 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5513 static enum thermal_access_mode thermal_read_mode
;
5515 /* idx is zero-based */
5516 static int thermal_get_sensor(int idx
, s32
*value
)
5522 t
= TP_EC_THERMAL_TMP0
;
5524 switch (thermal_read_mode
) {
5525 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5526 case TPACPI_THERMAL_TPEC_16
:
5527 if (idx
>= 8 && idx
<= 15) {
5528 t
= TP_EC_THERMAL_TMP8
;
5533 case TPACPI_THERMAL_TPEC_8
:
5535 if (!acpi_ec_read(t
+ idx
, &tmp
))
5537 *value
= tmp
* 1000;
5542 case TPACPI_THERMAL_ACPI_UPDT
:
5544 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5545 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5547 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5549 *value
= (t
- 2732) * 100;
5554 case TPACPI_THERMAL_ACPI_TMP07
:
5556 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5557 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5559 if (t
> 127 || t
< -127)
5560 t
= TP_EC_THERMAL_TMP_NA
;
5566 case TPACPI_THERMAL_NONE
:
5574 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5585 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5588 for (i
= 0 ; i
< n
; i
++) {
5589 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5597 static void thermal_dump_all_sensors(void)
5600 struct ibm_thermal_sensors_struct t
;
5602 n
= thermal_get_sensors(&t
);
5606 printk(TPACPI_NOTICE
5607 "temperatures (Celsius):");
5609 for (i
= 0; i
< n
; i
++) {
5610 if (t
.temp
[i
] != TPACPI_THERMAL_SENSOR_NA
)
5611 printk(KERN_CONT
" %d", (int)(t
.temp
[i
] / 1000));
5613 printk(KERN_CONT
" N/A");
5616 printk(KERN_CONT
"\n");
5619 /* sysfs temp##_input -------------------------------------------------- */
5621 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5622 struct device_attribute
*attr
,
5625 struct sensor_device_attribute
*sensor_attr
=
5626 to_sensor_dev_attr(attr
);
5627 int idx
= sensor_attr
->index
;
5631 res
= thermal_get_sensor(idx
, &value
);
5634 if (value
== TPACPI_THERMAL_SENSOR_NA
)
5637 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5640 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5641 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5642 thermal_temp_input_show, NULL, _idxB)
5644 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5645 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5646 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5647 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5648 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5649 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5650 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5651 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5652 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5653 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5654 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5655 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5656 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5657 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5658 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5659 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5660 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5663 #define THERMAL_ATTRS(X) \
5664 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5666 static struct attribute
*thermal_temp_input_attr
[] = {
5686 static const struct attribute_group thermal_temp_input16_group
= {
5687 .attrs
= thermal_temp_input_attr
5690 static const struct attribute_group thermal_temp_input8_group
= {
5691 .attrs
= &thermal_temp_input_attr
[8]
5694 #undef THERMAL_SENSOR_ATTR_TEMP
5695 #undef THERMAL_ATTRS
5697 /* --------------------------------------------------------------------- */
5699 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5706 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5708 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5710 if (thinkpad_id
.ec_model
) {
5712 * Direct EC access mode: sensors at registers
5713 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5714 * non-implemented, thermal sensors return 0x80 when
5719 for (i
= 0; i
< 8; i
++) {
5720 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5726 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5734 /* This is sheer paranoia, but we handle it anyway */
5737 "ThinkPad ACPI EC access misbehaving, "
5738 "falling back to ACPI TMPx access "
5740 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5743 "ThinkPad ACPI EC access misbehaving, "
5744 "disabling thermal sensors access\n");
5745 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5750 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5752 } else if (acpi_tmp7
) {
5753 if (tpacpi_is_ibm() &&
5754 acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5755 /* 600e/x, 770e, 770x */
5756 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5758 /* IBM/LENOVO DSDT EC.TMPx access, max 8 sensors */
5759 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5762 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5763 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5766 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5767 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5770 switch (thermal_read_mode
) {
5771 case TPACPI_THERMAL_TPEC_16
:
5772 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5773 &thermal_temp_input16_group
);
5777 case TPACPI_THERMAL_TPEC_8
:
5778 case TPACPI_THERMAL_ACPI_TMP07
:
5779 case TPACPI_THERMAL_ACPI_UPDT
:
5780 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5781 &thermal_temp_input8_group
);
5785 case TPACPI_THERMAL_NONE
:
5793 static void thermal_exit(void)
5795 switch (thermal_read_mode
) {
5796 case TPACPI_THERMAL_TPEC_16
:
5797 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5798 &thermal_temp_input16_group
);
5800 case TPACPI_THERMAL_TPEC_8
:
5801 case TPACPI_THERMAL_ACPI_TMP07
:
5802 case TPACPI_THERMAL_ACPI_UPDT
:
5803 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5804 &thermal_temp_input8_group
);
5806 case TPACPI_THERMAL_NONE
:
5812 static int thermal_read(struct seq_file
*m
)
5815 struct ibm_thermal_sensors_struct t
;
5817 n
= thermal_get_sensors(&t
);
5818 if (unlikely(n
< 0))
5821 seq_printf(m
, "temperatures:\t");
5824 for (i
= 0; i
< (n
- 1); i
++)
5825 seq_printf(m
, "%d ", t
.temp
[i
] / 1000);
5826 seq_printf(m
, "%d\n", t
.temp
[i
] / 1000);
5828 seq_printf(m
, "not supported\n");
5833 static struct ibm_struct thermal_driver_data
= {
5835 .read
= thermal_read
,
5836 .exit
= thermal_exit
,
5839 /*************************************************************************
5843 static u8 ecdump_regs
[256];
5845 static int ecdump_read(struct seq_file
*m
)
5851 " +00 +01 +02 +03 +04 +05 +06 +07"
5852 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5853 for (i
= 0; i
< 256; i
+= 16) {
5854 seq_printf(m
, "EC 0x%02x:", i
);
5855 for (j
= 0; j
< 16; j
++) {
5856 if (!acpi_ec_read(i
+ j
, &v
))
5858 if (v
!= ecdump_regs
[i
+ j
])
5859 seq_printf(m
, " *%02x", v
);
5861 seq_printf(m
, " %02x", v
);
5862 ecdump_regs
[i
+ j
] = v
;
5869 /* These are way too dangerous to advertise openly... */
5871 seq_printf(m
, "commands:\t0x<offset> 0x<value>"
5872 " (<offset> is 00-ff, <value> is 00-ff)\n");
5873 seq_printf(m
, "commands:\t0x<offset> <value> "
5874 " (<offset> is 00-ff, <value> is 0-255)\n");
5879 static int ecdump_write(char *buf
)
5884 while ((cmd
= next_cmd(&buf
))) {
5885 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5887 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5891 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5892 if (!acpi_ec_write(i
, v
))
5901 static struct ibm_struct ecdump_driver_data
= {
5903 .read
= ecdump_read
,
5904 .write
= ecdump_write
,
5905 .flags
.experimental
= 1,
5908 /*************************************************************************
5909 * Backlight/brightness subdriver
5912 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5915 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5916 * CMOS NVRAM byte 0x5E, bits 0-3.
5918 * EC HBRV (0x31) has the following layout
5919 * Bit 7: unknown function
5920 * Bit 6: unknown function
5921 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5922 * Bit 4: must be set to zero to avoid problems
5923 * Bit 3-0: backlight brightness level
5925 * brightness_get_raw returns status data in the HBRV layout
5927 * WARNING: The X61 has been verified to use HBRV for something else, so
5928 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5929 * testing on the very early *60 Lenovo models...
5933 TP_EC_BACKLIGHT
= 0x31,
5935 /* TP_EC_BACKLIGHT bitmasks */
5936 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5937 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5938 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5941 enum tpacpi_brightness_access_mode
{
5942 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5943 TPACPI_BRGHT_MODE_EC
, /* EC control */
5944 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5945 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5946 TPACPI_BRGHT_MODE_MAX
5949 static struct backlight_device
*ibm_backlight_device
;
5951 static enum tpacpi_brightness_access_mode brightness_mode
=
5952 TPACPI_BRGHT_MODE_MAX
;
5954 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5956 static struct mutex brightness_mutex
;
5958 /* NVRAM brightness access,
5959 * call with brightness_mutex held! */
5960 static unsigned int tpacpi_brightness_nvram_get(void)
5964 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5965 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5966 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5967 lnvram
&= bright_maxlvl
;
5972 static void tpacpi_brightness_checkpoint_nvram(void)
5977 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5980 vdbg_printk(TPACPI_DBG_BRGHT
,
5981 "trying to checkpoint backlight level to NVRAM...\n");
5983 if (mutex_lock_killable(&brightness_mutex
) < 0)
5986 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5988 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5989 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5991 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5992 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5993 /* NVRAM needs update */
5994 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5995 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5997 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5998 dbg_printk(TPACPI_DBG_BRGHT
,
5999 "updated NVRAM backlight level to %u (0x%02x)\n",
6000 (unsigned int) lec
, (unsigned int) b_nvram
);
6002 vdbg_printk(TPACPI_DBG_BRGHT
,
6003 "NVRAM backlight level already is %u (0x%02x)\n",
6004 (unsigned int) lec
, (unsigned int) b_nvram
);
6007 mutex_unlock(&brightness_mutex
);
6011 /* call with brightness_mutex held! */
6012 static int tpacpi_brightness_get_raw(int *status
)
6016 switch (brightness_mode
) {
6017 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6018 *status
= tpacpi_brightness_nvram_get();
6020 case TPACPI_BRGHT_MODE_EC
:
6021 case TPACPI_BRGHT_MODE_ECNVRAM
:
6022 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6031 /* call with brightness_mutex held! */
6032 /* do NOT call with illegal backlight level value */
6033 static int tpacpi_brightness_set_ec(unsigned int value
)
6037 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6040 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
6041 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
6042 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
6048 /* call with brightness_mutex held! */
6049 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
6052 unsigned int current_value
, i
;
6054 current_value
= tpacpi_brightness_nvram_get();
6056 if (value
== current_value
)
6059 cmos_cmd
= (value
> current_value
) ?
6060 TP_CMOS_BRIGHTNESS_UP
:
6061 TP_CMOS_BRIGHTNESS_DOWN
;
6062 inc
= (value
> current_value
) ? 1 : -1;
6064 for (i
= current_value
; i
!= value
; i
+= inc
)
6065 if (issue_thinkpad_cmos_command(cmos_cmd
))
6071 /* May return EINTR which can always be mapped to ERESTARTSYS */
6072 static int brightness_set(unsigned int value
)
6076 if (value
> bright_maxlvl
|| value
< 0)
6079 vdbg_printk(TPACPI_DBG_BRGHT
,
6080 "set backlight level to %d\n", value
);
6082 res
= mutex_lock_killable(&brightness_mutex
);
6086 switch (brightness_mode
) {
6087 case TPACPI_BRGHT_MODE_EC
:
6088 case TPACPI_BRGHT_MODE_ECNVRAM
:
6089 res
= tpacpi_brightness_set_ec(value
);
6091 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6092 res
= tpacpi_brightness_set_ucmsstep(value
);
6098 mutex_unlock(&brightness_mutex
);
6102 /* sysfs backlight class ----------------------------------------------- */
6104 static int brightness_update_status(struct backlight_device
*bd
)
6106 unsigned int level
=
6107 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
6108 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
6109 bd
->props
.brightness
: 0;
6111 dbg_printk(TPACPI_DBG_BRGHT
,
6112 "backlight: attempt to set level to %d\n",
6115 /* it is the backlight class's job (caller) to handle
6116 * EINTR and other errors properly */
6117 return brightness_set(level
);
6120 static int brightness_get(struct backlight_device
*bd
)
6124 res
= mutex_lock_killable(&brightness_mutex
);
6128 res
= tpacpi_brightness_get_raw(&status
);
6130 mutex_unlock(&brightness_mutex
);
6135 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6138 static void tpacpi_brightness_notify_change(void)
6140 backlight_force_update(ibm_backlight_device
,
6141 BACKLIGHT_UPDATE_HOTKEY
);
6144 static struct backlight_ops ibm_backlight_data
= {
6145 .get_brightness
= brightness_get
,
6146 .update_status
= brightness_update_status
,
6149 /* --------------------------------------------------------------------- */
6151 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
6153 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
6154 union acpi_object
*obj
;
6157 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
6158 obj
= (union acpi_object
*)buffer
.pointer
;
6159 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
6160 printk(TPACPI_ERR
"Unknown _BCL data, "
6161 "please report this to %s\n", TPACPI_MAIL
);
6164 rc
= obj
->package
.count
;
6170 kfree(buffer
.pointer
);
6174 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
6175 u32 lvl
, void *context
, void **rv
)
6177 char name
[ACPI_PATH_SEGMENT_LENGTH
];
6178 struct acpi_buffer buffer
= { sizeof(name
), &name
};
6180 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
6181 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
6182 BUG_ON(!rv
|| !*rv
);
6183 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
6184 return AE_CTRL_TERMINATE
;
6191 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
6193 static unsigned int __init
tpacpi_check_std_acpi_brightness_support(void)
6197 void *bcl_ptr
= &bcl_levels
;
6200 TPACPI_ACPIHANDLE_INIT(vid
);
6206 * Search for a _BCL method, and execute it. This is safe on all
6207 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
6208 * BIOS in ACPI backlight control mode. We do NOT have to care
6209 * about calling the _BCL method in an enabled video device, any
6210 * will do for our purposes.
6213 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
6214 tpacpi_acpi_walk_find_bcl
, NULL
, NULL
,
6217 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
6218 tp_features
.bright_acpimode
= 1;
6219 return bcl_levels
- 2;
6226 * These are only useful for models that have only one possibility
6227 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6230 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6231 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6232 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6234 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6235 /* Models with ATI GPUs known to require ECNVRAM mode */
6236 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6238 /* Models with ATI GPUs that can use ECNVRAM */
6239 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
), /* R50,51 T40-42 */
6240 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6241 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC
), /* R52 */
6242 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6244 /* Models with Intel Extreme Graphics 2 */
6245 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
), /* X40 */
6246 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6247 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6249 /* Models with Intel GMA900 */
6250 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6251 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6252 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6256 * Returns < 0 for error, otherwise sets tp_features.bright_*
6257 * and bright_maxlvl.
6259 static void __init
tpacpi_detect_brightness_capabilities(void)
6263 vdbg_printk(TPACPI_DBG_INIT
,
6264 "detecting firmware brightness interface capabilities\n");
6266 /* we could run a quirks check here (same table used by
6267 * brightness_init) if needed */
6270 * We always attempt to detect acpi support, so as to switch
6271 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6272 * going to publish a backlight interface
6274 b
= tpacpi_check_std_acpi_brightness_support();
6279 "detected a 16-level brightness capable ThinkPad\n");
6285 "detected a 8-level brightness capable ThinkPad\n");
6289 "Unsupported brightness interface, "
6290 "please contact %s\n", TPACPI_MAIL
);
6291 tp_features
.bright_unkfw
= 1;
6292 bright_maxlvl
= b
- 1;
6296 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6299 unsigned long quirks
;
6301 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6303 mutex_init(&brightness_mutex
);
6305 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6306 ARRAY_SIZE(brightness_quirk_table
));
6308 /* tpacpi_detect_brightness_capabilities() must have run already */
6310 /* if it is unknown, we don't handle it: it wouldn't be safe */
6311 if (tp_features
.bright_unkfw
)
6314 if (tp_features
.bright_acpimode
) {
6315 if (acpi_video_backlight_support()) {
6316 if (brightness_enable
> 1) {
6317 printk(TPACPI_NOTICE
6318 "Standard ACPI backlight interface "
6319 "available, not loading native one.\n");
6321 } else if (brightness_enable
== 1) {
6322 printk(TPACPI_NOTICE
6323 "Backlight control force enabled, even if standard "
6324 "ACPI backlight interface is available\n");
6327 if (brightness_enable
> 1) {
6328 printk(TPACPI_NOTICE
6329 "Standard ACPI backlight interface not "
6330 "available, thinkpad_acpi native "
6331 "brightness control enabled\n");
6336 if (!brightness_enable
) {
6337 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6338 "brightness support disabled by "
6339 "module parameter\n");
6344 * Check for module parameter bogosity, note that we
6345 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6346 * able to detect "unspecified"
6348 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6351 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6352 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6353 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6354 if (quirks
& TPACPI_BRGHT_Q_EC
)
6355 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6357 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6359 dbg_printk(TPACPI_DBG_BRGHT
,
6360 "driver auto-selected brightness_mode=%d\n",
6365 if (!tpacpi_is_ibm() &&
6366 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6367 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6370 if (tpacpi_brightness_get_raw(&b
) < 0)
6373 ibm_backlight_device
= backlight_device_register(
6374 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6375 &ibm_backlight_data
);
6376 if (IS_ERR(ibm_backlight_device
)) {
6377 int rc
= PTR_ERR(ibm_backlight_device
);
6378 ibm_backlight_device
= NULL
;
6379 printk(TPACPI_ERR
"Could not register backlight device\n");
6382 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6383 "brightness is supported\n");
6385 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6386 printk(TPACPI_NOTICE
6387 "brightness: will use unverified default: "
6388 "brightness_mode=%d\n", brightness_mode
);
6389 printk(TPACPI_NOTICE
6390 "brightness: please report to %s whether it works well "
6391 "or not on your ThinkPad\n", TPACPI_MAIL
);
6394 ibm_backlight_device
->props
.max_brightness
= bright_maxlvl
;
6395 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6397 /* Added by mistake in early 2007. Probably useless, but it could
6398 * be working around some unknown firmware problem where the value
6399 * read at startup doesn't match the real hardware state... so leave
6400 * it in place just in case */
6401 backlight_update_status(ibm_backlight_device
);
6403 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6404 "brightness: registering brightness hotkeys "
6405 "as change notification\n");
6406 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6407 | TP_ACPI_HKEY_BRGHTUP_MASK
6408 | TP_ACPI_HKEY_BRGHTDWN_MASK
);;
6412 static void brightness_suspend(pm_message_t state
)
6414 tpacpi_brightness_checkpoint_nvram();
6417 static void brightness_shutdown(void)
6419 tpacpi_brightness_checkpoint_nvram();
6422 static void brightness_exit(void)
6424 if (ibm_backlight_device
) {
6425 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6426 "calling backlight_device_unregister()\n");
6427 backlight_device_unregister(ibm_backlight_device
);
6430 tpacpi_brightness_checkpoint_nvram();
6433 static int brightness_read(struct seq_file
*m
)
6437 level
= brightness_get(NULL
);
6439 seq_printf(m
, "level:\t\tunreadable\n");
6441 seq_printf(m
, "level:\t\t%d\n", level
);
6442 seq_printf(m
, "commands:\tup, down\n");
6443 seq_printf(m
, "commands:\tlevel <level> (<level> is 0-%d)\n",
6450 static int brightness_write(char *buf
)
6456 level
= brightness_get(NULL
);
6460 while ((cmd
= next_cmd(&buf
))) {
6461 if (strlencmp(cmd
, "up") == 0) {
6462 if (level
< bright_maxlvl
)
6464 } else if (strlencmp(cmd
, "down") == 0) {
6467 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6468 level
>= 0 && level
<= bright_maxlvl
) {
6474 tpacpi_disclose_usertask("procfs brightness",
6475 "set level to %d\n", level
);
6478 * Now we know what the final level should be, so we try to set it.
6479 * Doing it this way makes the syscall restartable in case of EINTR
6481 rc
= brightness_set(level
);
6482 if (!rc
&& ibm_backlight_device
)
6483 backlight_force_update(ibm_backlight_device
,
6484 BACKLIGHT_UPDATE_SYSFS
);
6485 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6488 static struct ibm_struct brightness_driver_data
= {
6489 .name
= "brightness",
6490 .read
= brightness_read
,
6491 .write
= brightness_write
,
6492 .exit
= brightness_exit
,
6493 .suspend
= brightness_suspend
,
6494 .shutdown
= brightness_shutdown
,
6497 /*************************************************************************
6502 * IBM ThinkPads have a simple volume controller with MUTE gating.
6503 * Very early Lenovo ThinkPads follow the IBM ThinkPad spec.
6505 * Since the *61 series (and probably also the later *60 series), Lenovo
6506 * ThinkPads only implement the MUTE gate.
6509 * Bit 6: MUTE (1 mutes sound)
6511 * Other bits should be zero as far as we know.
6513 * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and
6514 * bits 3-0 (volume). Other bits in NVRAM may have other functions,
6515 * such as bit 7 which is used to detect repeated presses of MUTE,
6516 * and we leave them unchanged.
6519 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
6521 #define TPACPI_ALSA_DRVNAME "ThinkPad EC"
6522 #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control"
6523 #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME
6525 static int alsa_index
= ~((1 << (SNDRV_CARDS
- 3)) - 1); /* last three slots */
6526 static char *alsa_id
= "ThinkPadEC";
6527 static int alsa_enable
= SNDRV_DEFAULT_ENABLE1
;
6529 struct tpacpi_alsa_data
{
6530 struct snd_card
*card
;
6531 struct snd_ctl_elem_id
*ctl_mute_id
;
6532 struct snd_ctl_elem_id
*ctl_vol_id
;
6535 static struct snd_card
*alsa_card
;
6540 /* TP_EC_AUDIO bits */
6541 TP_EC_AUDIO_MUTESW
= 6,
6543 /* TP_EC_AUDIO bitmasks */
6544 TP_EC_AUDIO_LVL_MSK
= 0x0F,
6545 TP_EC_AUDIO_MUTESW_MSK
= (1 << TP_EC_AUDIO_MUTESW
),
6547 /* Maximum volume */
6548 TP_EC_VOLUME_MAX
= 14,
6551 enum tpacpi_volume_access_mode
{
6552 TPACPI_VOL_MODE_AUTO
= 0, /* Not implemented yet */
6553 TPACPI_VOL_MODE_EC
, /* Pure EC control */
6554 TPACPI_VOL_MODE_UCMS_STEP
, /* UCMS step-based control: N/A */
6555 TPACPI_VOL_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
6559 enum tpacpi_volume_capabilities
{
6560 TPACPI_VOL_CAP_AUTO
= 0, /* Use white/blacklist */
6561 TPACPI_VOL_CAP_VOLMUTE
, /* Output vol and mute */
6562 TPACPI_VOL_CAP_MUTEONLY
, /* Output mute only */
6566 static enum tpacpi_volume_access_mode volume_mode
=
6567 TPACPI_VOL_MODE_MAX
;
6569 static enum tpacpi_volume_capabilities volume_capabilities
;
6570 static int volume_control_allowed
;
6573 * Used to syncronize writers to TP_EC_AUDIO and
6574 * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write
6576 static struct mutex volume_mutex
;
6578 static void tpacpi_volume_checkpoint_nvram(void)
6584 if (volume_mode
!= TPACPI_VOL_MODE_ECNVRAM
)
6586 if (!volume_control_allowed
)
6589 vdbg_printk(TPACPI_DBG_MIXER
,
6590 "trying to checkpoint mixer state to NVRAM...\n");
6592 if (tp_features
.mixer_no_level_control
)
6593 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
;
6595 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
| TP_EC_AUDIO_LVL_MSK
;
6597 if (mutex_lock_killable(&volume_mutex
) < 0)
6600 if (unlikely(!acpi_ec_read(TP_EC_AUDIO
, &lec
)))
6603 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
6605 if (lec
!= (b_nvram
& ec_mask
)) {
6606 /* NVRAM needs update */
6607 b_nvram
&= ~ec_mask
;
6609 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_MIXER
);
6610 dbg_printk(TPACPI_DBG_MIXER
,
6611 "updated NVRAM mixer status to 0x%02x (0x%02x)\n",
6612 (unsigned int) lec
, (unsigned int) b_nvram
);
6614 vdbg_printk(TPACPI_DBG_MIXER
,
6615 "NVRAM mixer status already is 0x%02x (0x%02x)\n",
6616 (unsigned int) lec
, (unsigned int) b_nvram
);
6620 mutex_unlock(&volume_mutex
);
6623 static int volume_get_status_ec(u8
*status
)
6627 if (!acpi_ec_read(TP_EC_AUDIO
, &s
))
6632 dbg_printk(TPACPI_DBG_MIXER
, "status 0x%02x\n", s
);
6637 static int volume_get_status(u8
*status
)
6639 return volume_get_status_ec(status
);
6642 static int volume_set_status_ec(const u8 status
)
6644 if (!acpi_ec_write(TP_EC_AUDIO
, status
))
6647 dbg_printk(TPACPI_DBG_MIXER
, "set EC mixer to 0x%02x\n", status
);
6652 static int volume_set_status(const u8 status
)
6654 return volume_set_status_ec(status
);
6657 /* returns < 0 on error, 0 on no change, 1 on change */
6658 static int __volume_set_mute_ec(const bool mute
)
6663 if (mutex_lock_killable(&volume_mutex
) < 0)
6666 rc
= volume_get_status_ec(&s
);
6670 n
= (mute
) ? s
| TP_EC_AUDIO_MUTESW_MSK
:
6671 s
& ~TP_EC_AUDIO_MUTESW_MSK
;
6674 rc
= volume_set_status_ec(n
);
6680 mutex_unlock(&volume_mutex
);
6684 static int volume_alsa_set_mute(const bool mute
)
6686 dbg_printk(TPACPI_DBG_MIXER
, "ALSA: trying to %smute\n",
6687 (mute
) ? "" : "un");
6688 return __volume_set_mute_ec(mute
);
6691 static int volume_set_mute(const bool mute
)
6695 dbg_printk(TPACPI_DBG_MIXER
, "trying to %smute\n",
6696 (mute
) ? "" : "un");
6698 rc
= __volume_set_mute_ec(mute
);
6699 return (rc
< 0) ? rc
: 0;
6702 /* returns < 0 on error, 0 on no change, 1 on change */
6703 static int __volume_set_volume_ec(const u8 vol
)
6708 if (vol
> TP_EC_VOLUME_MAX
)
6711 if (mutex_lock_killable(&volume_mutex
) < 0)
6714 rc
= volume_get_status_ec(&s
);
6718 n
= (s
& ~TP_EC_AUDIO_LVL_MSK
) | vol
;
6721 rc
= volume_set_status_ec(n
);
6727 mutex_unlock(&volume_mutex
);
6731 static int volume_alsa_set_volume(const u8 vol
)
6733 dbg_printk(TPACPI_DBG_MIXER
,
6734 "ALSA: trying to set volume level to %hu\n", vol
);
6735 return __volume_set_volume_ec(vol
);
6738 static void volume_alsa_notify_change(void)
6740 struct tpacpi_alsa_data
*d
;
6742 if (alsa_card
&& alsa_card
->private_data
) {
6743 d
= alsa_card
->private_data
;
6745 snd_ctl_notify(alsa_card
,
6746 SNDRV_CTL_EVENT_MASK_VALUE
,
6749 snd_ctl_notify(alsa_card
,
6750 SNDRV_CTL_EVENT_MASK_VALUE
,
6755 static int volume_alsa_vol_info(struct snd_kcontrol
*kcontrol
,
6756 struct snd_ctl_elem_info
*uinfo
)
6758 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
6760 uinfo
->value
.integer
.min
= 0;
6761 uinfo
->value
.integer
.max
= TP_EC_VOLUME_MAX
;
6765 static int volume_alsa_vol_get(struct snd_kcontrol
*kcontrol
,
6766 struct snd_ctl_elem_value
*ucontrol
)
6771 rc
= volume_get_status(&s
);
6775 ucontrol
->value
.integer
.value
[0] = s
& TP_EC_AUDIO_LVL_MSK
;
6779 static int volume_alsa_vol_put(struct snd_kcontrol
*kcontrol
,
6780 struct snd_ctl_elem_value
*ucontrol
)
6782 tpacpi_disclose_usertask("ALSA", "set volume to %ld\n",
6783 ucontrol
->value
.integer
.value
[0]);
6784 return volume_alsa_set_volume(ucontrol
->value
.integer
.value
[0]);
6787 #define volume_alsa_mute_info snd_ctl_boolean_mono_info
6789 static int volume_alsa_mute_get(struct snd_kcontrol
*kcontrol
,
6790 struct snd_ctl_elem_value
*ucontrol
)
6795 rc
= volume_get_status(&s
);
6799 ucontrol
->value
.integer
.value
[0] =
6800 (s
& TP_EC_AUDIO_MUTESW_MSK
) ? 0 : 1;
6804 static int volume_alsa_mute_put(struct snd_kcontrol
*kcontrol
,
6805 struct snd_ctl_elem_value
*ucontrol
)
6807 tpacpi_disclose_usertask("ALSA", "%smute\n",
6808 ucontrol
->value
.integer
.value
[0] ?
6810 return volume_alsa_set_mute(!ucontrol
->value
.integer
.value
[0]);
6813 static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata
= {
6814 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6815 .name
= "Console Playback Volume",
6817 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6818 .info
= volume_alsa_vol_info
,
6819 .get
= volume_alsa_vol_get
,
6822 static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata
= {
6823 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6824 .name
= "Console Playback Switch",
6826 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6827 .info
= volume_alsa_mute_info
,
6828 .get
= volume_alsa_mute_get
,
6831 static void volume_suspend(pm_message_t state
)
6833 tpacpi_volume_checkpoint_nvram();
6836 static void volume_resume(void)
6838 volume_alsa_notify_change();
6841 static void volume_shutdown(void)
6843 tpacpi_volume_checkpoint_nvram();
6846 static void volume_exit(void)
6849 snd_card_free(alsa_card
);
6853 tpacpi_volume_checkpoint_nvram();
6856 static int __init
volume_create_alsa_mixer(void)
6858 struct snd_card
*card
;
6859 struct tpacpi_alsa_data
*data
;
6860 struct snd_kcontrol
*ctl_vol
;
6861 struct snd_kcontrol
*ctl_mute
;
6864 rc
= snd_card_create(alsa_index
, alsa_id
, THIS_MODULE
,
6865 sizeof(struct tpacpi_alsa_data
), &card
);
6866 if (rc
< 0 || !card
) {
6868 "Failed to create ALSA card structures: %d\n", rc
);
6872 BUG_ON(!card
->private_data
);
6873 data
= card
->private_data
;
6876 strlcpy(card
->driver
, TPACPI_ALSA_DRVNAME
,
6877 sizeof(card
->driver
));
6878 strlcpy(card
->shortname
, TPACPI_ALSA_SHRTNAME
,
6879 sizeof(card
->shortname
));
6880 snprintf(card
->mixername
, sizeof(card
->mixername
), "ThinkPad EC %s",
6881 (thinkpad_id
.ec_version_str
) ?
6882 thinkpad_id
.ec_version_str
: "(unknown)");
6883 snprintf(card
->longname
, sizeof(card
->longname
),
6884 "%s at EC reg 0x%02x, fw %s", card
->shortname
, TP_EC_AUDIO
,
6885 (thinkpad_id
.ec_version_str
) ?
6886 thinkpad_id
.ec_version_str
: "unknown");
6888 if (volume_control_allowed
) {
6889 volume_alsa_control_vol
.put
= volume_alsa_vol_put
;
6890 volume_alsa_control_vol
.access
=
6891 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6893 volume_alsa_control_mute
.put
= volume_alsa_mute_put
;
6894 volume_alsa_control_mute
.access
=
6895 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6898 if (!tp_features
.mixer_no_level_control
) {
6899 ctl_vol
= snd_ctl_new1(&volume_alsa_control_vol
, NULL
);
6900 rc
= snd_ctl_add(card
, ctl_vol
);
6903 "Failed to create ALSA volume control: %d\n",
6907 data
->ctl_vol_id
= &ctl_vol
->id
;
6910 ctl_mute
= snd_ctl_new1(&volume_alsa_control_mute
, NULL
);
6911 rc
= snd_ctl_add(card
, ctl_mute
);
6913 printk(TPACPI_ERR
"Failed to create ALSA mute control: %d\n",
6917 data
->ctl_mute_id
= &ctl_mute
->id
;
6919 snd_card_set_dev(card
, &tpacpi_pdev
->dev
);
6920 rc
= snd_card_register(card
);
6922 printk(TPACPI_ERR
"Failed to register ALSA card: %d\n", rc
);
6930 snd_card_free(card
);
6934 #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */
6935 #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */
6937 static const struct tpacpi_quirk volume_quirk_table
[] __initconst
= {
6938 /* Whitelist volume level on all IBM by default */
6939 { .vendor
= PCI_VENDOR_ID_IBM
,
6940 .bios
= TPACPI_MATCH_ANY
,
6941 .ec
= TPACPI_MATCH_ANY
,
6942 .quirks
= TPACPI_VOL_Q_LEVEL
},
6944 /* Lenovo models with volume control (needs confirmation) */
6945 TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL
), /* R60/i */
6946 TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL
), /* R60e/i */
6947 TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL
), /* T60/p */
6948 TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL
), /* X60/s */
6949 TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL
), /* X60t */
6950 TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL
), /* Z60 */
6951 TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL
), /* Z61 */
6953 /* Whitelist mute-only on all Lenovo by default */
6954 { .vendor
= PCI_VENDOR_ID_LENOVO
,
6955 .bios
= TPACPI_MATCH_ANY
,
6956 .ec
= TPACPI_MATCH_ANY
,
6957 .quirks
= TPACPI_VOL_Q_MUTEONLY
}
6960 static int __init
volume_init(struct ibm_init_struct
*iibm
)
6962 unsigned long quirks
;
6965 vdbg_printk(TPACPI_DBG_INIT
, "initializing volume subdriver\n");
6967 mutex_init(&volume_mutex
);
6970 * Check for module parameter bogosity, note that we
6971 * init volume_mode to TPACPI_VOL_MODE_MAX in order to be
6972 * able to detect "unspecified"
6974 if (volume_mode
> TPACPI_VOL_MODE_MAX
)
6977 if (volume_mode
== TPACPI_VOL_MODE_UCMS_STEP
) {
6979 "UCMS step volume mode not implemented, "
6980 "please contact %s\n", TPACPI_MAIL
);
6984 if (volume_capabilities
>= TPACPI_VOL_CAP_MAX
)
6988 * The ALSA mixer is our primary interface.
6989 * When disabled, don't install the subdriver at all
6992 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6993 "ALSA mixer disabled by parameter, "
6994 "not loading volume subdriver...\n");
6998 quirks
= tpacpi_check_quirks(volume_quirk_table
,
6999 ARRAY_SIZE(volume_quirk_table
));
7001 switch (volume_capabilities
) {
7002 case TPACPI_VOL_CAP_AUTO
:
7003 if (quirks
& TPACPI_VOL_Q_MUTEONLY
)
7004 tp_features
.mixer_no_level_control
= 1;
7005 else if (quirks
& TPACPI_VOL_Q_LEVEL
)
7006 tp_features
.mixer_no_level_control
= 0;
7008 return 1; /* no mixer */
7010 case TPACPI_VOL_CAP_VOLMUTE
:
7011 tp_features
.mixer_no_level_control
= 0;
7013 case TPACPI_VOL_CAP_MUTEONLY
:
7014 tp_features
.mixer_no_level_control
= 1;
7020 if (volume_capabilities
!= TPACPI_VOL_CAP_AUTO
)
7021 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
7022 "using user-supplied volume_capabilities=%d\n",
7023 volume_capabilities
);
7025 if (volume_mode
== TPACPI_VOL_MODE_AUTO
||
7026 volume_mode
== TPACPI_VOL_MODE_MAX
) {
7027 volume_mode
= TPACPI_VOL_MODE_ECNVRAM
;
7029 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
7030 "driver auto-selected volume_mode=%d\n",
7033 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
7034 "using user-supplied volume_mode=%d\n",
7038 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
7039 "mute is supported, volume control is %s\n",
7040 str_supported(!tp_features
.mixer_no_level_control
));
7042 rc
= volume_create_alsa_mixer();
7045 "Could not create the ALSA mixer interface\n");
7050 "Console audio control enabled, mode: %s\n",
7051 (volume_control_allowed
) ?
7052 "override (read/write)" :
7053 "monitor (read only)");
7055 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
7056 "registering volume hotkeys as change notification\n");
7057 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
7058 | TP_ACPI_HKEY_VOLUP_MASK
7059 | TP_ACPI_HKEY_VOLDWN_MASK
7060 | TP_ACPI_HKEY_MUTE_MASK
);
7065 static int volume_read(struct seq_file
*m
)
7069 if (volume_get_status(&status
) < 0) {
7070 seq_printf(m
, "level:\t\tunreadable\n");
7072 if (tp_features
.mixer_no_level_control
)
7073 seq_printf(m
, "level:\t\tunsupported\n");
7075 seq_printf(m
, "level:\t\t%d\n",
7076 status
& TP_EC_AUDIO_LVL_MSK
);
7078 seq_printf(m
, "mute:\t\t%s\n",
7079 onoff(status
, TP_EC_AUDIO_MUTESW
));
7081 if (volume_control_allowed
) {
7082 seq_printf(m
, "commands:\tunmute, mute\n");
7083 if (!tp_features
.mixer_no_level_control
) {
7085 "commands:\tup, down\n");
7087 "commands:\tlevel <level>"
7088 " (<level> is 0-%d)\n",
7097 static int volume_write(char *buf
)
7100 u8 new_level
, new_mute
;
7106 * We do allow volume control at driver startup, so that the
7107 * user can set initial state through the volume=... parameter hack.
7109 if (!volume_control_allowed
&& tpacpi_lifecycle
!= TPACPI_LIFE_INIT
) {
7110 if (unlikely(!tp_warned
.volume_ctrl_forbidden
)) {
7111 tp_warned
.volume_ctrl_forbidden
= 1;
7112 printk(TPACPI_NOTICE
7113 "Console audio control in monitor mode, "
7114 "changes are not allowed.\n");
7115 printk(TPACPI_NOTICE
7116 "Use the volume_control=1 module parameter "
7117 "to enable volume control\n");
7122 rc
= volume_get_status(&s
);
7126 new_level
= s
& TP_EC_AUDIO_LVL_MSK
;
7127 new_mute
= s
& TP_EC_AUDIO_MUTESW_MSK
;
7129 while ((cmd
= next_cmd(&buf
))) {
7130 if (!tp_features
.mixer_no_level_control
) {
7131 if (strlencmp(cmd
, "up") == 0) {
7134 else if (new_level
< TP_EC_VOLUME_MAX
)
7137 } else if (strlencmp(cmd
, "down") == 0) {
7140 else if (new_level
> 0)
7143 } else if (sscanf(cmd
, "level %u", &l
) == 1 &&
7144 l
>= 0 && l
<= TP_EC_VOLUME_MAX
) {
7149 if (strlencmp(cmd
, "mute") == 0)
7150 new_mute
= TP_EC_AUDIO_MUTESW_MSK
;
7151 else if (strlencmp(cmd
, "unmute") == 0)
7157 if (tp_features
.mixer_no_level_control
) {
7158 tpacpi_disclose_usertask("procfs volume", "%smute\n",
7159 new_mute
? "" : "un");
7160 rc
= volume_set_mute(!!new_mute
);
7162 tpacpi_disclose_usertask("procfs volume",
7163 "%smute and set level to %d\n",
7164 new_mute
? "" : "un", new_level
);
7165 rc
= volume_set_status(new_mute
| new_level
);
7167 volume_alsa_notify_change();
7169 return (rc
== -EINTR
) ? -ERESTARTSYS
: rc
;
7172 static struct ibm_struct volume_driver_data
= {
7174 .read
= volume_read
,
7175 .write
= volume_write
,
7176 .exit
= volume_exit
,
7177 .suspend
= volume_suspend
,
7178 .resume
= volume_resume
,
7179 .shutdown
= volume_shutdown
,
7182 #else /* !CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
7184 #define alsa_card NULL
7186 static void inline volume_alsa_notify_change(void)
7190 static int __init
volume_init(struct ibm_init_struct
*iibm
)
7193 "volume: disabled as there is no ALSA support in this kernel\n");
7198 static struct ibm_struct volume_driver_data
= {
7202 #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
7204 /*************************************************************************
7211 * TPACPI_FAN_RD_ACPI_GFAN:
7212 * ACPI GFAN method: returns fan level
7214 * see TPACPI_FAN_WR_ACPI_SFAN
7215 * EC 0x2f (HFSP) not available if GFAN exists
7217 * TPACPI_FAN_WR_ACPI_SFAN:
7218 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
7220 * EC 0x2f (HFSP) might be available *for reading*, but do not use
7223 * TPACPI_FAN_WR_TPEC:
7224 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
7225 * Supported on almost all ThinkPads
7227 * Fan speed changes of any sort (including those caused by the
7228 * disengaged mode) are usually done slowly by the firmware as the
7229 * maximum amount of fan duty cycle change per second seems to be
7232 * Reading is not available if GFAN exists.
7233 * Writing is not available if SFAN exists.
7236 * 7 automatic mode engaged;
7237 * (default operation mode of the ThinkPad)
7238 * fan level is ignored in this mode.
7239 * 6 full speed mode (takes precedence over bit 7);
7240 * not available on all thinkpads. May disable
7241 * the tachometer while the fan controller ramps up
7242 * the speed (which can take up to a few *minutes*).
7243 * Speeds up fan to 100% duty-cycle, which is far above
7244 * the standard RPM levels. It is not impossible that
7245 * it could cause hardware damage.
7246 * 5-3 unused in some models. Extra bits for fan level
7247 * in others, but still useless as all values above
7248 * 7 map to the same speed as level 7 in these models.
7249 * 2-0 fan level (0..7 usually)
7251 * 0x07 = max (set when temperatures critical)
7252 * Some ThinkPads may have other levels, see
7253 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
7255 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
7256 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
7257 * does so, its initial value is meaningless (0x07).
7259 * For firmware bugs, refer to:
7260 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7264 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
7265 * Main fan tachometer reading (in RPM)
7267 * This register is present on all ThinkPads with a new-style EC, and
7268 * it is known not to be present on the A21m/e, and T22, as there is
7269 * something else in offset 0x84 according to the ACPI DSDT. Other
7270 * ThinkPads from this same time period (and earlier) probably lack the
7271 * tachometer as well.
7273 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
7274 * was never fixed by IBM to report the EC firmware version string
7275 * probably support the tachometer (like the early X models), so
7276 * detecting it is quite hard. We need more data to know for sure.
7278 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
7281 * FIRMWARE BUG: may go stale while the EC is switching to full speed
7284 * For firmware bugs, refer to:
7285 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7289 * ThinkPad EC register 0x31 bit 0 (only on select models)
7291 * When bit 0 of EC register 0x31 is zero, the tachometer registers
7292 * show the speed of the main fan. When bit 0 of EC register 0x31
7293 * is one, the tachometer registers show the speed of the auxiliary
7296 * Fan control seems to affect both fans, regardless of the state
7299 * So far, only the firmware for the X60/X61 non-tablet versions
7300 * seem to support this (firmware TP-7M).
7302 * TPACPI_FAN_WR_ACPI_FANS:
7303 * ThinkPad X31, X40, X41. Not available in the X60.
7305 * FANS ACPI handle: takes three arguments: low speed, medium speed,
7306 * high speed. ACPI DSDT seems to map these three speeds to levels
7307 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
7308 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
7310 * The speeds are stored on handles
7311 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
7313 * There are three default speed sets, accessible as handles:
7314 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
7316 * ACPI DSDT switches which set is in use depending on various
7319 * TPACPI_FAN_WR_TPEC is also available and should be used to
7320 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
7321 * but the ACPI tables just mention level 7.
7324 enum { /* Fan control constants */
7325 fan_status_offset
= 0x2f, /* EC register 0x2f */
7326 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
7327 * 0x84 must be read before 0x85 */
7328 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
7329 bit 0 selects which fan is active */
7331 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
7332 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
7334 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
7337 enum fan_status_access_mode
{
7338 TPACPI_FAN_NONE
= 0, /* No fan status or control */
7339 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
7340 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
7343 enum fan_control_access_mode
{
7344 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
7345 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
7346 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
7347 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
7350 enum fan_control_commands
{
7351 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
7352 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
7353 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
7354 * and also watchdog cmd */
7357 static int fan_control_allowed
;
7359 static enum fan_status_access_mode fan_status_access_mode
;
7360 static enum fan_control_access_mode fan_control_access_mode
;
7361 static enum fan_control_commands fan_control_commands
;
7363 static u8 fan_control_initial_status
;
7364 static u8 fan_control_desired_level
;
7365 static u8 fan_control_resume_level
;
7366 static int fan_watchdog_maxinterval
;
7368 static struct mutex fan_mutex
;
7370 static void fan_watchdog_fire(struct work_struct
*ignored
);
7371 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
7373 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
7374 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
7375 "\\FSPD", /* 600e/x, 770e, 770x */
7377 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
7378 "JFNS", /* 770x-JL */
7382 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
7383 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
7384 * be in auto mode (0x80).
7386 * This is corrected by any write to HFSP either by the driver, or
7389 * We assume 0x07 really means auto mode while this quirk is active,
7390 * as this is far more likely than the ThinkPad being in level 7,
7391 * which is only used by the firmware during thermal emergencies.
7393 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
7394 * TP-70 (T43, R52), which are known to be buggy.
7397 static void fan_quirk1_setup(void)
7399 if (fan_control_initial_status
== 0x07) {
7400 printk(TPACPI_NOTICE
7401 "fan_init: initial fan status is unknown, "
7402 "assuming it is in auto mode\n");
7403 tp_features
.fan_ctrl_status_undef
= 1;
7407 static void fan_quirk1_handle(u8
*fan_status
)
7409 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
7410 if (*fan_status
!= fan_control_initial_status
) {
7411 /* something changed the HFSP regisnter since
7412 * driver init time, so it is not undefined
7414 tp_features
.fan_ctrl_status_undef
= 0;
7416 /* Return most likely status. In fact, it
7417 * might be the only possible status */
7418 *fan_status
= TP_EC_FAN_AUTO
;
7423 /* Select main fan on X60/X61, NOOP on others */
7424 static bool fan_select_fan1(void)
7426 if (tp_features
.second_fan
) {
7429 if (ec_read(fan_select_offset
, &val
) < 0)
7432 if (ec_write(fan_select_offset
, val
) < 0)
7438 /* Select secondary fan on X60/X61 */
7439 static bool fan_select_fan2(void)
7443 if (!tp_features
.second_fan
)
7446 if (ec_read(fan_select_offset
, &val
) < 0)
7449 if (ec_write(fan_select_offset
, val
) < 0)
7456 * Call with fan_mutex held
7458 static void fan_update_desired_level(u8 status
)
7461 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7463 fan_control_desired_level
= 7;
7465 fan_control_desired_level
= status
;
7469 static int fan_get_status(u8
*status
)
7474 * Add TPACPI_FAN_RD_ACPI_FANS ? */
7476 switch (fan_status_access_mode
) {
7477 case TPACPI_FAN_RD_ACPI_GFAN
:
7478 /* 570, 600e/x, 770e, 770x */
7480 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
7488 case TPACPI_FAN_RD_TPEC
:
7489 /* all except 570, 600e/x, 770e, 770x */
7490 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
7493 if (likely(status
)) {
7495 fan_quirk1_handle(status
);
7507 static int fan_get_status_safe(u8
*status
)
7512 if (mutex_lock_killable(&fan_mutex
))
7513 return -ERESTARTSYS
;
7514 rc
= fan_get_status(&s
);
7516 fan_update_desired_level(s
);
7517 mutex_unlock(&fan_mutex
);
7525 static int fan_get_speed(unsigned int *speed
)
7529 switch (fan_status_access_mode
) {
7530 case TPACPI_FAN_RD_TPEC
:
7531 /* all except 570, 600e/x, 770e, 770x */
7532 if (unlikely(!fan_select_fan1()))
7534 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
7535 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
7539 *speed
= (hi
<< 8) | lo
;
7550 static int fan2_get_speed(unsigned int *speed
)
7555 switch (fan_status_access_mode
) {
7556 case TPACPI_FAN_RD_TPEC
:
7557 /* all except 570, 600e/x, 770e, 770x */
7558 if (unlikely(!fan_select_fan2()))
7560 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
7561 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
7562 fan_select_fan1(); /* play it safe */
7567 *speed
= (hi
<< 8) | lo
;
7578 static int fan_set_level(int level
)
7580 if (!fan_control_allowed
)
7583 switch (fan_control_access_mode
) {
7584 case TPACPI_FAN_WR_ACPI_SFAN
:
7585 if (level
>= 0 && level
<= 7) {
7586 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
7592 case TPACPI_FAN_WR_ACPI_FANS
:
7593 case TPACPI_FAN_WR_TPEC
:
7594 if (!(level
& TP_EC_FAN_AUTO
) &&
7595 !(level
& TP_EC_FAN_FULLSPEED
) &&
7596 ((level
< 0) || (level
> 7)))
7599 /* safety net should the EC not support AUTO
7600 * or FULLSPEED mode bits and just ignore them */
7601 if (level
& TP_EC_FAN_FULLSPEED
)
7602 level
|= 7; /* safety min speed 7 */
7603 else if (level
& TP_EC_FAN_AUTO
)
7604 level
|= 4; /* safety min speed 4 */
7606 if (!acpi_ec_write(fan_status_offset
, level
))
7609 tp_features
.fan_ctrl_status_undef
= 0;
7616 vdbg_printk(TPACPI_DBG_FAN
,
7617 "fan control: set fan control register to 0x%02x\n", level
);
7621 static int fan_set_level_safe(int level
)
7625 if (!fan_control_allowed
)
7628 if (mutex_lock_killable(&fan_mutex
))
7629 return -ERESTARTSYS
;
7631 if (level
== TPACPI_FAN_LAST_LEVEL
)
7632 level
= fan_control_desired_level
;
7634 rc
= fan_set_level(level
);
7636 fan_update_desired_level(level
);
7638 mutex_unlock(&fan_mutex
);
7642 static int fan_set_enable(void)
7647 if (!fan_control_allowed
)
7650 if (mutex_lock_killable(&fan_mutex
))
7651 return -ERESTARTSYS
;
7653 switch (fan_control_access_mode
) {
7654 case TPACPI_FAN_WR_ACPI_FANS
:
7655 case TPACPI_FAN_WR_TPEC
:
7656 rc
= fan_get_status(&s
);
7660 /* Don't go out of emergency fan mode */
7663 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
7666 if (!acpi_ec_write(fan_status_offset
, s
))
7669 tp_features
.fan_ctrl_status_undef
= 0;
7674 case TPACPI_FAN_WR_ACPI_SFAN
:
7675 rc
= fan_get_status(&s
);
7681 /* Set fan to at least level 4 */
7684 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
7694 mutex_unlock(&fan_mutex
);
7697 vdbg_printk(TPACPI_DBG_FAN
,
7698 "fan control: set fan control register to 0x%02x\n",
7703 static int fan_set_disable(void)
7707 if (!fan_control_allowed
)
7710 if (mutex_lock_killable(&fan_mutex
))
7711 return -ERESTARTSYS
;
7714 switch (fan_control_access_mode
) {
7715 case TPACPI_FAN_WR_ACPI_FANS
:
7716 case TPACPI_FAN_WR_TPEC
:
7717 if (!acpi_ec_write(fan_status_offset
, 0x00))
7720 fan_control_desired_level
= 0;
7721 tp_features
.fan_ctrl_status_undef
= 0;
7725 case TPACPI_FAN_WR_ACPI_SFAN
:
7726 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
7729 fan_control_desired_level
= 0;
7737 vdbg_printk(TPACPI_DBG_FAN
,
7738 "fan control: set fan control register to 0\n");
7740 mutex_unlock(&fan_mutex
);
7744 static int fan_set_speed(int speed
)
7748 if (!fan_control_allowed
)
7751 if (mutex_lock_killable(&fan_mutex
))
7752 return -ERESTARTSYS
;
7755 switch (fan_control_access_mode
) {
7756 case TPACPI_FAN_WR_ACPI_FANS
:
7757 if (speed
>= 0 && speed
<= 65535) {
7758 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
7759 speed
, speed
, speed
))
7769 mutex_unlock(&fan_mutex
);
7773 static void fan_watchdog_reset(void)
7775 static int fan_watchdog_active
;
7777 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
7780 if (fan_watchdog_active
)
7781 cancel_delayed_work(&fan_watchdog_task
);
7783 if (fan_watchdog_maxinterval
> 0 &&
7784 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
7785 fan_watchdog_active
= 1;
7786 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
7787 msecs_to_jiffies(fan_watchdog_maxinterval
7790 "failed to queue the fan watchdog, "
7791 "watchdog will not trigger\n");
7794 fan_watchdog_active
= 0;
7797 static void fan_watchdog_fire(struct work_struct
*ignored
)
7801 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
7804 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
7805 rc
= fan_set_enable();
7807 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
7808 "will try again later...\n", -rc
);
7809 /* reschedule for later */
7810 fan_watchdog_reset();
7815 * SYSFS fan layout: hwmon compatible (device)
7818 * 0: "disengaged" mode
7820 * 2: native EC "auto" mode (recommended, hardware default)
7822 * pwm*: set speed in manual mode, ignored otherwise.
7823 * 0 is level 0; 255 is level 7. Intermediate points done with linear
7826 * fan*_input: tachometer reading, RPM
7829 * SYSFS fan layout: extensions
7831 * fan_watchdog (driver):
7832 * fan watchdog interval in seconds, 0 disables (default), max 120
7835 /* sysfs fan pwm1_enable ----------------------------------------------- */
7836 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
7837 struct device_attribute
*attr
,
7843 res
= fan_get_status_safe(&status
);
7847 if (status
& TP_EC_FAN_FULLSPEED
) {
7849 } else if (status
& TP_EC_FAN_AUTO
) {
7854 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
7857 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7858 struct device_attribute
*attr
,
7859 const char *buf
, size_t count
)
7864 if (parse_strtoul(buf
, 2, &t
))
7867 tpacpi_disclose_usertask("hwmon pwm1_enable",
7868 "set fan mode to %lu\n", t
);
7872 level
= TP_EC_FAN_FULLSPEED
;
7875 level
= TPACPI_FAN_LAST_LEVEL
;
7878 level
= TP_EC_FAN_AUTO
;
7881 /* reserved for software-controlled auto mode */
7887 res
= fan_set_level_safe(level
);
7893 fan_watchdog_reset();
7898 static struct device_attribute dev_attr_fan_pwm1_enable
=
7899 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7900 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7902 /* sysfs fan pwm1 ------------------------------------------------------ */
7903 static ssize_t
fan_pwm1_show(struct device
*dev
,
7904 struct device_attribute
*attr
,
7910 res
= fan_get_status_safe(&status
);
7915 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7916 status
= fan_control_desired_level
;
7921 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7924 static ssize_t
fan_pwm1_store(struct device
*dev
,
7925 struct device_attribute
*attr
,
7926 const char *buf
, size_t count
)
7930 u8 status
, newlevel
;
7932 if (parse_strtoul(buf
, 255, &s
))
7935 tpacpi_disclose_usertask("hwmon pwm1",
7936 "set fan speed to %lu\n", s
);
7938 /* scale down from 0-255 to 0-7 */
7939 newlevel
= (s
>> 5) & 0x07;
7941 if (mutex_lock_killable(&fan_mutex
))
7942 return -ERESTARTSYS
;
7944 rc
= fan_get_status(&status
);
7945 if (!rc
&& (status
&
7946 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7947 rc
= fan_set_level(newlevel
);
7951 fan_update_desired_level(newlevel
);
7952 fan_watchdog_reset();
7956 mutex_unlock(&fan_mutex
);
7957 return (rc
)? rc
: count
;
7960 static struct device_attribute dev_attr_fan_pwm1
=
7961 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7962 fan_pwm1_show
, fan_pwm1_store
);
7964 /* sysfs fan fan1_input ------------------------------------------------ */
7965 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7966 struct device_attribute
*attr
,
7972 res
= fan_get_speed(&speed
);
7976 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7979 static struct device_attribute dev_attr_fan_fan1_input
=
7980 __ATTR(fan1_input
, S_IRUGO
,
7981 fan_fan1_input_show
, NULL
);
7983 /* sysfs fan fan2_input ------------------------------------------------ */
7984 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7985 struct device_attribute
*attr
,
7991 res
= fan2_get_speed(&speed
);
7995 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7998 static struct device_attribute dev_attr_fan_fan2_input
=
7999 __ATTR(fan2_input
, S_IRUGO
,
8000 fan_fan2_input_show
, NULL
);
8002 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
8003 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
8006 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
8009 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
8010 const char *buf
, size_t count
)
8014 if (parse_strtoul(buf
, 120, &t
))
8017 if (!fan_control_allowed
)
8020 fan_watchdog_maxinterval
= t
;
8021 fan_watchdog_reset();
8023 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
8028 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
8029 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
8031 /* --------------------------------------------------------------------- */
8032 static struct attribute
*fan_attributes
[] = {
8033 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
8034 &dev_attr_fan_fan1_input
.attr
,
8035 NULL
, /* for fan2_input */
8039 static const struct attribute_group fan_attr_group
= {
8040 .attrs
= fan_attributes
,
8043 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
8044 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
8046 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
8047 { .vendor = PCI_VENDOR_ID_IBM, \
8048 .bios = TPACPI_MATCH_ANY, \
8049 .ec = TPID(__id1, __id2), \
8050 .quirks = __quirks }
8052 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
8053 { .vendor = PCI_VENDOR_ID_LENOVO, \
8054 .bios = TPACPI_MATCH_ANY, \
8055 .ec = TPID(__id1, __id2), \
8056 .quirks = __quirks }
8058 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
8059 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
8060 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
8061 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
8062 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
8063 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
8066 #undef TPACPI_FAN_QL
8067 #undef TPACPI_FAN_QI
8069 static int __init
fan_init(struct ibm_init_struct
*iibm
)
8072 unsigned long quirks
;
8074 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8075 "initializing fan subdriver\n");
8077 mutex_init(&fan_mutex
);
8078 fan_status_access_mode
= TPACPI_FAN_NONE
;
8079 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
8080 fan_control_commands
= 0;
8081 fan_watchdog_maxinterval
= 0;
8082 tp_features
.fan_ctrl_status_undef
= 0;
8083 tp_features
.second_fan
= 0;
8084 fan_control_desired_level
= 7;
8086 if (tpacpi_is_ibm()) {
8087 TPACPI_ACPIHANDLE_INIT(fans
);
8088 TPACPI_ACPIHANDLE_INIT(gfan
);
8089 TPACPI_ACPIHANDLE_INIT(sfan
);
8092 quirks
= tpacpi_check_quirks(fan_quirk_table
,
8093 ARRAY_SIZE(fan_quirk_table
));
8096 /* 570, 600e/x, 770e, 770x */
8097 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
8099 /* all other ThinkPads: note that even old-style
8100 * ThinkPad ECs supports the fan control register */
8101 if (likely(acpi_ec_read(fan_status_offset
,
8102 &fan_control_initial_status
))) {
8103 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
8104 if (quirks
& TPACPI_FAN_Q1
)
8106 if (quirks
& TPACPI_FAN_2FAN
) {
8107 tp_features
.second_fan
= 1;
8108 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8109 "secondary fan support enabled\n");
8113 "ThinkPad ACPI EC access misbehaving, "
8114 "fan status and control unavailable\n");
8121 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
8122 fan_control_commands
|=
8123 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
8126 /* gfan without sfan means no fan control */
8127 /* all other models implement TP EC 0x2f control */
8131 fan_control_access_mode
=
8132 TPACPI_FAN_WR_ACPI_FANS
;
8133 fan_control_commands
|=
8134 TPACPI_FAN_CMD_SPEED
|
8135 TPACPI_FAN_CMD_LEVEL
|
8136 TPACPI_FAN_CMD_ENABLE
;
8138 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
8139 fan_control_commands
|=
8140 TPACPI_FAN_CMD_LEVEL
|
8141 TPACPI_FAN_CMD_ENABLE
;
8146 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8147 "fan is %s, modes %d, %d\n",
8148 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
8149 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
8150 fan_status_access_mode
, fan_control_access_mode
);
8152 /* fan control master switch */
8153 if (!fan_control_allowed
) {
8154 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
8155 fan_control_commands
= 0;
8156 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8157 "fan control features disabled by parameter\n");
8160 /* update fan_control_desired_level */
8161 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
8162 fan_get_status_safe(NULL
);
8164 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
8165 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
8166 if (tp_features
.second_fan
) {
8167 /* attach second fan tachometer */
8168 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
8169 &dev_attr_fan_fan2_input
.attr
;
8171 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8176 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
8177 &driver_attr_fan_watchdog
);
8179 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8188 static void fan_exit(void)
8190 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
8191 "cancelling any pending fan watchdog tasks\n");
8193 /* FIXME: can we really do this unconditionally? */
8194 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
8195 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
8196 &driver_attr_fan_watchdog
);
8198 cancel_delayed_work(&fan_watchdog_task
);
8199 flush_workqueue(tpacpi_wq
);
8202 static void fan_suspend(pm_message_t state
)
8206 if (!fan_control_allowed
)
8209 /* Store fan status in cache */
8210 fan_control_resume_level
= 0;
8211 rc
= fan_get_status_safe(&fan_control_resume_level
);
8213 printk(TPACPI_NOTICE
8214 "failed to read fan level for later "
8215 "restore during resume: %d\n", rc
);
8217 /* if it is undefined, don't attempt to restore it.
8219 if (tp_features
.fan_ctrl_status_undef
)
8220 fan_control_resume_level
= 0;
8223 static void fan_resume(void)
8225 u8 current_level
= 7;
8226 bool do_set
= false;
8229 /* DSDT *always* updates status on resume */
8230 tp_features
.fan_ctrl_status_undef
= 0;
8232 if (!fan_control_allowed
||
8233 !fan_control_resume_level
||
8234 (fan_get_status_safe(¤t_level
) < 0))
8237 switch (fan_control_access_mode
) {
8238 case TPACPI_FAN_WR_ACPI_SFAN
:
8239 /* never decrease fan level */
8240 do_set
= (fan_control_resume_level
> current_level
);
8242 case TPACPI_FAN_WR_ACPI_FANS
:
8243 case TPACPI_FAN_WR_TPEC
:
8244 /* never decrease fan level, scale is:
8245 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
8247 * We expect the firmware to set either 7 or AUTO, but we
8248 * handle FULLSPEED out of paranoia.
8250 * So, we can safely only restore FULLSPEED or 7, anything
8251 * else could slow the fan. Restoring AUTO is useless, at
8252 * best that's exactly what the DSDT already set (it is the
8255 * Always keep in mind that the DSDT *will* have set the
8256 * fans to what the vendor supposes is the best level. We
8257 * muck with it only to speed the fan up.
8259 if (fan_control_resume_level
!= 7 &&
8260 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
8263 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
8264 (current_level
!= fan_control_resume_level
);
8270 printk(TPACPI_NOTICE
8271 "restoring fan level to 0x%02x\n",
8272 fan_control_resume_level
);
8273 rc
= fan_set_level_safe(fan_control_resume_level
);
8275 printk(TPACPI_NOTICE
8276 "failed to restore fan level: %d\n", rc
);
8280 static int fan_read(struct seq_file
*m
)
8284 unsigned int speed
= 0;
8286 switch (fan_status_access_mode
) {
8287 case TPACPI_FAN_RD_ACPI_GFAN
:
8288 /* 570, 600e/x, 770e, 770x */
8289 rc
= fan_get_status_safe(&status
);
8293 seq_printf(m
, "status:\t\t%s\n"
8295 (status
!= 0) ? "enabled" : "disabled", status
);
8298 case TPACPI_FAN_RD_TPEC
:
8299 /* all except 570, 600e/x, 770e, 770x */
8300 rc
= fan_get_status_safe(&status
);
8304 seq_printf(m
, "status:\t\t%s\n",
8305 (status
!= 0) ? "enabled" : "disabled");
8307 rc
= fan_get_speed(&speed
);
8311 seq_printf(m
, "speed:\t\t%d\n", speed
);
8313 if (status
& TP_EC_FAN_FULLSPEED
)
8314 /* Disengaged mode takes precedence */
8315 seq_printf(m
, "level:\t\tdisengaged\n");
8316 else if (status
& TP_EC_FAN_AUTO
)
8317 seq_printf(m
, "level:\t\tauto\n");
8319 seq_printf(m
, "level:\t\t%d\n", status
);
8322 case TPACPI_FAN_NONE
:
8324 seq_printf(m
, "status:\t\tnot supported\n");
8327 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
8328 seq_printf(m
, "commands:\tlevel <level>");
8330 switch (fan_control_access_mode
) {
8331 case TPACPI_FAN_WR_ACPI_SFAN
:
8332 seq_printf(m
, " (<level> is 0-7)\n");
8336 seq_printf(m
, " (<level> is 0-7, "
8337 "auto, disengaged, full-speed)\n");
8342 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
8343 seq_printf(m
, "commands:\tenable, disable\n"
8344 "commands:\twatchdog <timeout> (<timeout> "
8345 "is 0 (off), 1-120 (seconds))\n");
8347 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
8348 seq_printf(m
, "commands:\tspeed <speed>"
8349 " (<speed> is 0-65535)\n");
8354 static int fan_write_cmd_level(const char *cmd
, int *rc
)
8358 if (strlencmp(cmd
, "level auto") == 0)
8359 level
= TP_EC_FAN_AUTO
;
8360 else if ((strlencmp(cmd
, "level disengaged") == 0) |
8361 (strlencmp(cmd
, "level full-speed") == 0))
8362 level
= TP_EC_FAN_FULLSPEED
;
8363 else if (sscanf(cmd
, "level %d", &level
) != 1)
8366 *rc
= fan_set_level_safe(level
);
8368 printk(TPACPI_ERR
"level command accepted for unsupported "
8369 "access mode %d", fan_control_access_mode
);
8371 tpacpi_disclose_usertask("procfs fan",
8372 "set level to %d\n", level
);
8377 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
8379 if (strlencmp(cmd
, "enable") != 0)
8382 *rc
= fan_set_enable();
8384 printk(TPACPI_ERR
"enable command accepted for unsupported "
8385 "access mode %d", fan_control_access_mode
);
8387 tpacpi_disclose_usertask("procfs fan", "enable\n");
8392 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
8394 if (strlencmp(cmd
, "disable") != 0)
8397 *rc
= fan_set_disable();
8399 printk(TPACPI_ERR
"disable command accepted for unsupported "
8400 "access mode %d", fan_control_access_mode
);
8402 tpacpi_disclose_usertask("procfs fan", "disable\n");
8407 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
8412 * Support speed <low> <medium> <high> ? */
8414 if (sscanf(cmd
, "speed %d", &speed
) != 1)
8417 *rc
= fan_set_speed(speed
);
8419 printk(TPACPI_ERR
"speed command accepted for unsupported "
8420 "access mode %d", fan_control_access_mode
);
8422 tpacpi_disclose_usertask("procfs fan",
8423 "set speed to %d\n", speed
);
8428 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
8432 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
8435 if (interval
< 0 || interval
> 120)
8438 fan_watchdog_maxinterval
= interval
;
8439 tpacpi_disclose_usertask("procfs fan",
8440 "set watchdog timer to %d\n",
8447 static int fan_write(char *buf
)
8452 while (!rc
&& (cmd
= next_cmd(&buf
))) {
8453 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
8454 fan_write_cmd_level(cmd
, &rc
)) &&
8455 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
8456 (fan_write_cmd_enable(cmd
, &rc
) ||
8457 fan_write_cmd_disable(cmd
, &rc
) ||
8458 fan_write_cmd_watchdog(cmd
, &rc
))) &&
8459 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
8460 fan_write_cmd_speed(cmd
, &rc
))
8464 fan_watchdog_reset();
8470 static struct ibm_struct fan_driver_data
= {
8475 .suspend
= fan_suspend
,
8476 .resume
= fan_resume
,
8479 /****************************************************************************
8480 ****************************************************************************
8484 ****************************************************************************
8485 ****************************************************************************/
8488 * HKEY event callout for other subdrivers go here
8489 * (yes, it is ugly, but it is quick, safe, and gets the job done
8491 static void tpacpi_driver_event(const unsigned int hkey_event
)
8493 if (ibm_backlight_device
) {
8494 switch (hkey_event
) {
8495 case TP_HKEY_EV_BRGHT_UP
:
8496 case TP_HKEY_EV_BRGHT_DOWN
:
8497 tpacpi_brightness_notify_change();
8501 switch (hkey_event
) {
8502 case TP_HKEY_EV_VOL_UP
:
8503 case TP_HKEY_EV_VOL_DOWN
:
8504 case TP_HKEY_EV_VOL_MUTE
:
8505 volume_alsa_notify_change();
8510 static void hotkey_driver_event(const unsigned int scancode
)
8512 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
8515 /* sysfs name ---------------------------------------------------------- */
8516 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
8517 struct device_attribute
*attr
,
8520 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
8523 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
8524 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
8526 /* --------------------------------------------------------------------- */
8529 static struct proc_dir_entry
*proc_dir
;
8532 * Module and infrastructure proble, init and exit handling
8535 static int force_load
;
8537 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
8538 static const char * __init
str_supported(int is_supported
)
8540 static char text_unsupported
[] __initdata
= "not supported";
8542 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
8544 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
8546 static void ibm_exit(struct ibm_struct
*ibm
)
8548 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
8550 list_del_init(&ibm
->all_drivers
);
8552 if (ibm
->flags
.acpi_notify_installed
) {
8553 dbg_printk(TPACPI_DBG_EXIT
,
8554 "%s: acpi_remove_notify_handler\n", ibm
->name
);
8556 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
8558 dispatch_acpi_notify
);
8559 ibm
->flags
.acpi_notify_installed
= 0;
8560 ibm
->flags
.acpi_notify_installed
= 0;
8563 if (ibm
->flags
.proc_created
) {
8564 dbg_printk(TPACPI_DBG_EXIT
,
8565 "%s: remove_proc_entry\n", ibm
->name
);
8566 remove_proc_entry(ibm
->name
, proc_dir
);
8567 ibm
->flags
.proc_created
= 0;
8570 if (ibm
->flags
.acpi_driver_registered
) {
8571 dbg_printk(TPACPI_DBG_EXIT
,
8572 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
8574 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
8575 kfree(ibm
->acpi
->driver
);
8576 ibm
->acpi
->driver
= NULL
;
8577 ibm
->flags
.acpi_driver_registered
= 0;
8580 if (ibm
->flags
.init_called
&& ibm
->exit
) {
8582 ibm
->flags
.init_called
= 0;
8585 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
8588 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
8591 struct ibm_struct
*ibm
= iibm
->data
;
8592 struct proc_dir_entry
*entry
;
8594 BUG_ON(ibm
== NULL
);
8596 INIT_LIST_HEAD(&ibm
->all_drivers
);
8598 if (ibm
->flags
.experimental
&& !experimental
)
8601 dbg_printk(TPACPI_DBG_INIT
,
8602 "probing for %s\n", ibm
->name
);
8605 ret
= iibm
->init(iibm
);
8607 return 0; /* probe failed */
8611 ibm
->flags
.init_called
= 1;
8615 if (ibm
->acpi
->hid
) {
8616 ret
= register_tpacpi_subdriver(ibm
);
8621 if (ibm
->acpi
->notify
) {
8622 ret
= setup_acpi_notify(ibm
);
8623 if (ret
== -ENODEV
) {
8624 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
8634 dbg_printk(TPACPI_DBG_INIT
,
8635 "%s installed\n", ibm
->name
);
8638 mode_t mode
= iibm
->base_procfs_mode
;
8644 entry
= proc_create_data(ibm
->name
, mode
, proc_dir
,
8645 &dispatch_proc_fops
, ibm
);
8647 printk(TPACPI_ERR
"unable to create proc entry %s\n",
8652 ibm
->flags
.proc_created
= 1;
8655 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
8660 dbg_printk(TPACPI_DBG_INIT
,
8661 "%s: at error exit path with result %d\n",
8665 return (ret
< 0)? ret
: 0;
8670 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
8672 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
8675 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
8676 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
8679 return s
&& strlen(s
) >= 8 &&
8680 tpacpi_is_fw_digit(s
[0]) &&
8681 tpacpi_is_fw_digit(s
[1]) &&
8682 s
[2] == t
&& s
[3] == 'T' &&
8683 tpacpi_is_fw_digit(s
[4]) &&
8684 tpacpi_is_fw_digit(s
[5]) &&
8685 s
[6] == 'W' && s
[7] == 'W';
8688 /* returns 0 - probe ok, or < 0 - probe error.
8689 * Probe ok doesn't mean thinkpad found.
8690 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
8691 static int __must_check __init
get_thinkpad_model_data(
8692 struct thinkpad_id_data
*tp
)
8694 const struct dmi_device
*dev
= NULL
;
8695 char ec_fw_string
[18];
8701 memset(tp
, 0, sizeof(*tp
));
8703 if (dmi_name_in_vendors("IBM"))
8704 tp
->vendor
= PCI_VENDOR_ID_IBM
;
8705 else if (dmi_name_in_vendors("LENOVO"))
8706 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
8710 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
8711 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
8712 if (s
&& !tp
->bios_version_str
)
8715 /* Really ancient ThinkPad 240X will fail this, which is fine */
8716 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
8719 tp
->bios_model
= tp
->bios_version_str
[0]
8720 | (tp
->bios_version_str
[1] << 8);
8721 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
8722 | tp
->bios_version_str
[5];
8725 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
8726 * X32 or newer, all Z series; Some models must have an
8727 * up-to-date BIOS or they will not be detected.
8729 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8731 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
8732 if (sscanf(dev
->name
,
8733 "IBM ThinkPad Embedded Controller -[%17c",
8734 ec_fw_string
) == 1) {
8735 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
8736 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
8738 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
8739 if (!tp
->ec_version_str
)
8742 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
8743 tp
->ec_model
= ec_fw_string
[0]
8744 | (ec_fw_string
[1] << 8);
8745 tp
->ec_release
= (ec_fw_string
[4] << 8)
8748 printk(TPACPI_NOTICE
8749 "ThinkPad firmware release %s "
8750 "doesn't match the known patterns\n",
8752 printk(TPACPI_NOTICE
8753 "please report this to %s\n",
8760 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
8761 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
8762 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
8767 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
8768 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
8769 if (s
&& !tp
->nummodel_str
)
8775 static int __init
probe_for_thinkpad(void)
8782 /* It would be dangerous to run the driver in this case */
8783 if (!tpacpi_is_ibm() && !tpacpi_is_lenovo())
8787 * Non-ancient models have better DMI tagging, but very old models
8788 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
8790 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
8791 (thinkpad_id
.ec_model
!= 0) ||
8792 tpacpi_is_fw_known();
8794 /* The EC handler is required */
8795 tpacpi_acpi_handle_locate("ec", TPACPI_ACPI_EC_HID
, &ec_handle
);
8799 "Not yet supported ThinkPad detected!\n");
8803 if (!is_thinkpad
&& !force_load
)
8809 static void __init
thinkpad_acpi_init_banner(void)
8811 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
8812 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
8814 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
8815 (thinkpad_id
.bios_version_str
) ?
8816 thinkpad_id
.bios_version_str
: "unknown",
8817 (thinkpad_id
.ec_version_str
) ?
8818 thinkpad_id
.ec_version_str
: "unknown");
8820 BUG_ON(!thinkpad_id
.vendor
);
8822 if (thinkpad_id
.model_str
)
8823 printk(TPACPI_INFO
"%s %s, model %s\n",
8824 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
8825 "IBM" : ((thinkpad_id
.vendor
==
8826 PCI_VENDOR_ID_LENOVO
) ?
8827 "Lenovo" : "Unknown vendor"),
8828 thinkpad_id
.model_str
,
8829 (thinkpad_id
.nummodel_str
) ?
8830 thinkpad_id
.nummodel_str
: "unknown");
8833 /* Module init, exit, parameters */
8835 static struct ibm_init_struct ibms_init
[] __initdata
= {
8837 .data
= &thinkpad_acpi_driver_data
,
8840 .init
= hotkey_init
,
8841 .data
= &hotkey_driver_data
,
8844 .init
= bluetooth_init
,
8845 .data
= &bluetooth_driver_data
,
8849 .data
= &wan_driver_data
,
8853 .data
= &uwb_driver_data
,
8855 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8858 .base_procfs_mode
= S_IRUSR
,
8859 .data
= &video_driver_data
,
8864 .data
= &light_driver_data
,
8868 .data
= &cmos_driver_data
,
8872 .data
= &led_driver_data
,
8876 .data
= &beep_driver_data
,
8879 .init
= thermal_init
,
8880 .data
= &thermal_driver_data
,
8883 .data
= &ecdump_driver_data
,
8886 .init
= brightness_init
,
8887 .data
= &brightness_driver_data
,
8890 .init
= volume_init
,
8891 .data
= &volume_driver_data
,
8895 .data
= &fan_driver_data
,
8899 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
8902 struct ibm_struct
*ibm
;
8904 if (!kp
|| !kp
->name
|| !val
)
8907 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8908 ibm
= ibms_init
[i
].data
;
8909 WARN_ON(ibm
== NULL
);
8911 if (!ibm
|| !ibm
->name
)
8914 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8915 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8917 strcpy(ibms_init
[i
].param
, val
);
8918 strcat(ibms_init
[i
].param
, ",");
8926 module_param(experimental
, int, 0444);
8927 MODULE_PARM_DESC(experimental
,
8928 "Enables experimental features when non-zero");
8930 module_param_named(debug
, dbg_level
, uint
, 0);
8931 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8933 module_param(force_load
, bool, 0444);
8934 MODULE_PARM_DESC(force_load
,
8935 "Attempts to load the driver even on a "
8936 "mis-identified ThinkPad when true");
8938 module_param_named(fan_control
, fan_control_allowed
, bool, 0444);
8939 MODULE_PARM_DESC(fan_control
,
8940 "Enables setting fan parameters features when true");
8942 module_param_named(brightness_mode
, brightness_mode
, uint
, 0444);
8943 MODULE_PARM_DESC(brightness_mode
,
8944 "Selects brightness control strategy: "
8945 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8947 module_param(brightness_enable
, uint
, 0444);
8948 MODULE_PARM_DESC(brightness_enable
,
8949 "Enables backlight control when 1, disables when 0");
8951 module_param(hotkey_report_mode
, uint
, 0444);
8952 MODULE_PARM_DESC(hotkey_report_mode
,
8953 "used for backwards compatibility with userspace, "
8954 "see documentation");
8956 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
8957 module_param_named(volume_mode
, volume_mode
, uint
, 0444);
8958 MODULE_PARM_DESC(volume_mode
,
8959 "Selects volume control strategy: "
8960 "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM");
8962 module_param_named(volume_capabilities
, volume_capabilities
, uint
, 0444);
8963 MODULE_PARM_DESC(volume_capabilities
,
8964 "Selects the mixer capabilites: "
8965 "0=auto, 1=volume and mute, 2=mute only");
8967 module_param_named(volume_control
, volume_control_allowed
, bool, 0444);
8968 MODULE_PARM_DESC(volume_control
,
8969 "Enables software override for the console audio "
8970 "control when true");
8972 /* ALSA module API parameters */
8973 module_param_named(index
, alsa_index
, int, 0444);
8974 MODULE_PARM_DESC(index
, "ALSA index for the ACPI EC Mixer");
8975 module_param_named(id
, alsa_id
, charp
, 0444);
8976 MODULE_PARM_DESC(id
, "ALSA id for the ACPI EC Mixer");
8977 module_param_named(enable
, alsa_enable
, bool, 0444);
8978 MODULE_PARM_DESC(enable
, "Enable the ALSA interface for the ACPI EC Mixer");
8979 #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
8981 #define TPACPI_PARAM(feature) \
8982 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8983 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8984 "at module load, see documentation")
8986 TPACPI_PARAM(hotkey
);
8987 TPACPI_PARAM(bluetooth
);
8988 TPACPI_PARAM(video
);
8989 TPACPI_PARAM(light
);
8993 TPACPI_PARAM(ecdump
);
8994 TPACPI_PARAM(brightness
);
8995 TPACPI_PARAM(volume
);
8998 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8999 module_param(dbg_wlswemul
, uint
, 0444);
9000 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
9001 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
9002 MODULE_PARM_DESC(wlsw_state
,
9003 "Initial state of the emulated WLSW switch");
9005 module_param(dbg_bluetoothemul
, uint
, 0444);
9006 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
9007 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
9008 MODULE_PARM_DESC(bluetooth_state
,
9009 "Initial state of the emulated bluetooth switch");
9011 module_param(dbg_wwanemul
, uint
, 0444);
9012 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
9013 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
9014 MODULE_PARM_DESC(wwan_state
,
9015 "Initial state of the emulated WWAN switch");
9017 module_param(dbg_uwbemul
, uint
, 0444);
9018 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
9019 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
9020 MODULE_PARM_DESC(uwb_state
,
9021 "Initial state of the emulated UWB switch");
9024 static void thinkpad_acpi_module_exit(void)
9026 struct ibm_struct
*ibm
, *itmp
;
9028 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
9030 list_for_each_entry_safe_reverse(ibm
, itmp
,
9031 &tpacpi_all_drivers
,
9036 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
9038 if (tpacpi_inputdev
) {
9039 if (tp_features
.input_device_registered
)
9040 input_unregister_device(tpacpi_inputdev
);
9042 input_free_device(tpacpi_inputdev
);
9046 hwmon_device_unregister(tpacpi_hwmon
);
9048 if (tp_features
.sensors_pdev_attrs_registered
)
9049 device_remove_file(&tpacpi_sensors_pdev
->dev
,
9050 &dev_attr_thinkpad_acpi_pdev_name
);
9051 if (tpacpi_sensors_pdev
)
9052 platform_device_unregister(tpacpi_sensors_pdev
);
9054 platform_device_unregister(tpacpi_pdev
);
9056 if (tp_features
.sensors_pdrv_attrs_registered
)
9057 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
9058 if (tp_features
.platform_drv_attrs_registered
)
9059 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
9061 if (tp_features
.sensors_pdrv_registered
)
9062 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
9064 if (tp_features
.platform_drv_registered
)
9065 platform_driver_unregister(&tpacpi_pdriver
);
9068 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
9071 destroy_workqueue(tpacpi_wq
);
9073 kfree(thinkpad_id
.bios_version_str
);
9074 kfree(thinkpad_id
.ec_version_str
);
9075 kfree(thinkpad_id
.model_str
);
9079 static int __init
thinkpad_acpi_module_init(void)
9083 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
9085 /* Parameter checking */
9086 if (hotkey_report_mode
> 2)
9089 /* Driver-level probe */
9091 ret
= get_thinkpad_model_data(&thinkpad_id
);
9094 "unable to get DMI data: %d\n", ret
);
9095 thinkpad_acpi_module_exit();
9098 ret
= probe_for_thinkpad();
9100 thinkpad_acpi_module_exit();
9104 /* Driver initialization */
9106 thinkpad_acpi_init_banner();
9107 tpacpi_check_outdated_fw();
9109 TPACPI_ACPIHANDLE_INIT(ecrd
);
9110 TPACPI_ACPIHANDLE_INIT(ecwr
);
9112 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
9114 thinkpad_acpi_module_exit();
9118 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
9121 "unable to create proc dir " TPACPI_PROC_DIR
);
9122 thinkpad_acpi_module_exit();
9126 ret
= platform_driver_register(&tpacpi_pdriver
);
9129 "unable to register main platform driver\n");
9130 thinkpad_acpi_module_exit();
9133 tp_features
.platform_drv_registered
= 1;
9135 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
9138 "unable to register hwmon platform driver\n");
9139 thinkpad_acpi_module_exit();
9142 tp_features
.sensors_pdrv_registered
= 1;
9144 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
9146 tp_features
.platform_drv_attrs_registered
= 1;
9147 ret
= tpacpi_create_driver_attributes(
9148 &tpacpi_hwmon_pdriver
.driver
);
9152 "unable to create sysfs driver attributes\n");
9153 thinkpad_acpi_module_exit();
9156 tp_features
.sensors_pdrv_attrs_registered
= 1;
9159 /* Device initialization */
9160 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
9162 if (IS_ERR(tpacpi_pdev
)) {
9163 ret
= PTR_ERR(tpacpi_pdev
);
9165 printk(TPACPI_ERR
"unable to register platform device\n");
9166 thinkpad_acpi_module_exit();
9169 tpacpi_sensors_pdev
= platform_device_register_simple(
9170 TPACPI_HWMON_DRVR_NAME
,
9172 if (IS_ERR(tpacpi_sensors_pdev
)) {
9173 ret
= PTR_ERR(tpacpi_sensors_pdev
);
9174 tpacpi_sensors_pdev
= NULL
;
9176 "unable to register hwmon platform device\n");
9177 thinkpad_acpi_module_exit();
9180 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
9181 &dev_attr_thinkpad_acpi_pdev_name
);
9184 "unable to create sysfs hwmon device attributes\n");
9185 thinkpad_acpi_module_exit();
9188 tp_features
.sensors_pdev_attrs_registered
= 1;
9189 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
9190 if (IS_ERR(tpacpi_hwmon
)) {
9191 ret
= PTR_ERR(tpacpi_hwmon
);
9192 tpacpi_hwmon
= NULL
;
9193 printk(TPACPI_ERR
"unable to register hwmon device\n");
9194 thinkpad_acpi_module_exit();
9197 mutex_init(&tpacpi_inputdev_send_mutex
);
9198 tpacpi_inputdev
= input_allocate_device();
9199 if (!tpacpi_inputdev
) {
9200 printk(TPACPI_ERR
"unable to allocate input device\n");
9201 thinkpad_acpi_module_exit();
9204 /* Prepare input device, but don't register */
9205 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
9206 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
9207 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
9208 tpacpi_inputdev
->id
.vendor
= thinkpad_id
.vendor
;
9209 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
9210 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
9211 tpacpi_inputdev
->dev
.parent
= &tpacpi_pdev
->dev
;
9214 /* Init subdriver dependencies */
9215 tpacpi_detect_brightness_capabilities();
9217 /* Init subdrivers */
9218 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
9219 ret
= ibm_init(&ibms_init
[i
]);
9220 if (ret
>= 0 && *ibms_init
[i
].param
)
9221 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
9223 thinkpad_acpi_module_exit();
9228 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
9230 ret
= input_register_device(tpacpi_inputdev
);
9232 printk(TPACPI_ERR
"unable to register input device\n");
9233 thinkpad_acpi_module_exit();
9236 tp_features
.input_device_registered
= 1;
9242 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
9245 * This will autoload the driver in almost every ThinkPad
9246 * in widespread use.
9248 * Only _VERY_ old models, like the 240, 240x and 570 lack
9249 * the HKEY event interface.
9251 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
9254 * DMI matching for module autoloading
9256 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
9257 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
9259 * Only models listed in thinkwiki will be supported, so add yours
9260 * if it is not there yet.
9262 #define IBM_BIOS_MODULE_ALIAS(__type) \
9263 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
9265 /* Ancient thinkpad BIOSes have to be identified by
9266 * BIOS type or model number, and there are far less
9267 * BIOS types than model numbers... */
9268 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
9270 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
9271 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
9272 MODULE_DESCRIPTION(TPACPI_DESC
);
9273 MODULE_VERSION(TPACPI_VERSION
);
9274 MODULE_LICENSE("GPL");
9276 module_init(thinkpad_acpi_module_init
);
9277 module_exit(thinkpad_acpi_module_exit
);