2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define TPACPI_VERSION "0.24"
25 #define TPACPI_SYSFS_VERSION 0x020700
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/sched.h>
58 #include <linux/kthread.h>
59 #include <linux/freezer.h>
60 #include <linux/delay.h>
62 #include <linux/nvram.h>
63 #include <linux/proc_fs.h>
64 #include <linux/seq_file.h>
65 #include <linux/sysfs.h>
66 #include <linux/backlight.h>
68 #include <linux/platform_device.h>
69 #include <linux/hwmon.h>
70 #include <linux/hwmon-sysfs.h>
71 #include <linux/input.h>
72 #include <linux/leds.h>
73 #include <linux/rfkill.h>
74 #include <asm/uaccess.h>
76 #include <linux/dmi.h>
77 #include <linux/jiffies.h>
78 #include <linux/workqueue.h>
80 #include <sound/core.h>
81 #include <sound/control.h>
82 #include <sound/initval.h>
84 #include <acpi/acpi_drivers.h>
86 #include <linux/pci_ids.h>
89 /* ThinkPad CMOS commands */
90 #define TP_CMOS_VOLUME_DOWN 0
91 #define TP_CMOS_VOLUME_UP 1
92 #define TP_CMOS_VOLUME_MUTE 2
93 #define TP_CMOS_BRIGHTNESS_UP 4
94 #define TP_CMOS_BRIGHTNESS_DOWN 5
95 #define TP_CMOS_THINKLIGHT_ON 12
96 #define TP_CMOS_THINKLIGHT_OFF 13
100 TP_NVRAM_ADDR_HK2
= 0x57,
101 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
102 TP_NVRAM_ADDR_VIDEO
= 0x59,
103 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
104 TP_NVRAM_ADDR_MIXER
= 0x60,
107 /* NVRAM bit masks */
109 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
110 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
111 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
112 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
113 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
114 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
115 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
116 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
117 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
118 TP_NVRAM_MASK_MUTE
= 0x40,
119 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
120 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
121 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
125 #define TPACPI_ACPI_HKEY_HID "IBM0068"
128 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
129 #define TPACPI_HKEY_INPUT_VERSION 0x4101
131 /* ACPI \WGSV commands */
133 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
134 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
135 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
136 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
139 /* TP_ACPI_WGSV_GET_STATE bits */
141 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
142 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
143 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
144 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
145 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
146 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
147 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
148 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
149 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
150 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
154 enum tpacpi_hkey_event_t
{
156 TP_HKEY_EV_HOTKEY_BASE
= 0x1001, /* first hotkey (FN+F1) */
157 TP_HKEY_EV_BRGHT_UP
= 0x1010, /* Brightness up */
158 TP_HKEY_EV_BRGHT_DOWN
= 0x1011, /* Brightness down */
159 TP_HKEY_EV_VOL_UP
= 0x1015, /* Volume up or unmute */
160 TP_HKEY_EV_VOL_DOWN
= 0x1016, /* Volume down or unmute */
161 TP_HKEY_EV_VOL_MUTE
= 0x1017, /* Mixer output mute */
163 /* Reasons for waking up from S3/S4 */
164 TP_HKEY_EV_WKUP_S3_UNDOCK
= 0x2304, /* undock requested, S3 */
165 TP_HKEY_EV_WKUP_S4_UNDOCK
= 0x2404, /* undock requested, S4 */
166 TP_HKEY_EV_WKUP_S3_BAYEJ
= 0x2305, /* bay ejection req, S3 */
167 TP_HKEY_EV_WKUP_S4_BAYEJ
= 0x2405, /* bay ejection req, S4 */
168 TP_HKEY_EV_WKUP_S3_BATLOW
= 0x2313, /* battery empty, S3 */
169 TP_HKEY_EV_WKUP_S4_BATLOW
= 0x2413, /* battery empty, S4 */
171 /* Auto-sleep after eject request */
172 TP_HKEY_EV_BAYEJ_ACK
= 0x3003, /* bay ejection complete */
173 TP_HKEY_EV_UNDOCK_ACK
= 0x4003, /* undock complete */
175 /* Misc bay events */
176 TP_HKEY_EV_OPTDRV_EJ
= 0x3006, /* opt. drive tray ejected */
178 /* User-interface events */
179 TP_HKEY_EV_LID_CLOSE
= 0x5001, /* laptop lid closed */
180 TP_HKEY_EV_LID_OPEN
= 0x5002, /* laptop lid opened */
181 TP_HKEY_EV_TABLET_TABLET
= 0x5009, /* tablet swivel up */
182 TP_HKEY_EV_TABLET_NOTEBOOK
= 0x500a, /* tablet swivel down */
183 TP_HKEY_EV_PEN_INSERTED
= 0x500b, /* tablet pen inserted */
184 TP_HKEY_EV_PEN_REMOVED
= 0x500c, /* tablet pen removed */
185 TP_HKEY_EV_BRGHT_CHANGED
= 0x5010, /* backlight control event */
188 TP_HKEY_EV_ALARM_BAT_HOT
= 0x6011, /* battery too hot */
189 TP_HKEY_EV_ALARM_BAT_XHOT
= 0x6012, /* battery critically hot */
190 TP_HKEY_EV_ALARM_SENSOR_HOT
= 0x6021, /* sensor too hot */
191 TP_HKEY_EV_ALARM_SENSOR_XHOT
= 0x6022, /* sensor critically hot */
192 TP_HKEY_EV_THM_TABLE_CHANGED
= 0x6030, /* thermal table changed */
195 TP_HKEY_EV_RFKILL_CHANGED
= 0x7000, /* rfkill switch changed */
198 /****************************************************************************
202 #define TPACPI_NAME "thinkpad"
203 #define TPACPI_DESC "ThinkPad ACPI Extras"
204 #define TPACPI_FILE TPACPI_NAME "_acpi"
205 #define TPACPI_URL "http://ibm-acpi.sf.net/"
206 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
208 #define TPACPI_PROC_DIR "ibm"
209 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
210 #define TPACPI_DRVR_NAME TPACPI_FILE
211 #define TPACPI_DRVR_SHORTNAME "tpacpi"
212 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
214 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
215 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
217 #define TPACPI_MAX_ACPI_ARGS 3
220 #define TPACPI_LOG TPACPI_FILE ": "
221 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
222 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
223 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
224 #define TPACPI_ERR KERN_ERR TPACPI_LOG
225 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
226 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
227 #define TPACPI_INFO KERN_INFO TPACPI_LOG
228 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
230 /* Debugging printk groups */
231 #define TPACPI_DBG_ALL 0xffff
232 #define TPACPI_DBG_DISCLOSETASK 0x8000
233 #define TPACPI_DBG_INIT 0x0001
234 #define TPACPI_DBG_EXIT 0x0002
235 #define TPACPI_DBG_RFKILL 0x0004
236 #define TPACPI_DBG_HKEY 0x0008
237 #define TPACPI_DBG_FAN 0x0010
238 #define TPACPI_DBG_BRGHT 0x0020
239 #define TPACPI_DBG_MIXER 0x0040
241 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
242 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
243 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
246 /****************************************************************************
247 * Driver-wide structs and misc. variables
252 struct tp_acpi_drv_struct
{
253 const struct acpi_device_id
*hid
;
254 struct acpi_driver
*driver
;
256 void (*notify
) (struct ibm_struct
*, u32
);
259 struct acpi_device
*device
;
265 int (*read
) (struct seq_file
*);
266 int (*write
) (char *);
268 void (*resume
) (void);
269 void (*suspend
) (pm_message_t state
);
270 void (*shutdown
) (void);
272 struct list_head all_drivers
;
274 struct tp_acpi_drv_struct
*acpi
;
277 u8 acpi_driver_registered
:1;
278 u8 acpi_notify_installed
:1;
285 struct ibm_init_struct
{
288 int (*init
) (struct ibm_init_struct
*);
289 mode_t base_procfs_mode
;
290 struct ibm_struct
*data
;
301 u32 bright_16levels
:1;
302 u32 bright_acpimode
:1;
305 u32 fan_ctrl_status_undef
:1;
307 u32 beep_needs_two_args
:1;
308 u32 mixer_no_level_control
:1;
309 u32 input_device_registered
:1;
310 u32 platform_drv_registered
:1;
311 u32 platform_drv_attrs_registered
:1;
312 u32 sensors_pdrv_registered
:1;
313 u32 sensors_pdrv_attrs_registered
:1;
314 u32 sensors_pdev_attrs_registered
:1;
315 u32 hotkey_poll_active
:1;
319 u16 hotkey_mask_ff
:1;
320 u16 volume_ctrl_forbidden
:1;
323 struct thinkpad_id_data
{
324 unsigned int vendor
; /* ThinkPad vendor:
325 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
327 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
328 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
330 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
332 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
335 char *model_str
; /* ThinkPad T43 */
336 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
338 static struct thinkpad_id_data thinkpad_id
;
341 TPACPI_LIFE_INIT
= 0,
346 static int experimental
;
347 static u32 dbg_level
;
349 static struct workqueue_struct
*tpacpi_wq
;
357 /* Special LED class that can defer work */
358 struct tpacpi_led_classdev
{
359 struct led_classdev led_classdev
;
360 struct work_struct work
;
361 enum led_status_t new_state
;
365 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
366 static int dbg_wlswemul
;
367 static int tpacpi_wlsw_emulstate
;
368 static int dbg_bluetoothemul
;
369 static int tpacpi_bluetooth_emulstate
;
370 static int dbg_wwanemul
;
371 static int tpacpi_wwan_emulstate
;
372 static int dbg_uwbemul
;
373 static int tpacpi_uwb_emulstate
;
377 /*************************************************************************
381 #define dbg_printk(a_dbg_level, format, arg...) \
382 do { if (dbg_level & (a_dbg_level)) \
383 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
386 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
387 #define vdbg_printk dbg_printk
388 static const char *str_supported(int is_supported
);
390 #define vdbg_printk(a_dbg_level, format, arg...) \
394 static void tpacpi_log_usertask(const char * const what
)
396 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
397 what
, task_tgid_vnr(current
));
400 #define tpacpi_disclose_usertask(what, format, arg...) \
403 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
404 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
405 printk(TPACPI_DEBUG "%s: PID %d: " format, \
406 what, task_tgid_vnr(current), ## arg); \
411 * Quirk handling helpers
413 * ThinkPad IDs and versions seen in the field so far
414 * are two-characters from the set [0-9A-Z], i.e. base 36.
416 * We use values well outside that range as specials.
419 #define TPACPI_MATCH_ANY 0xffffU
420 #define TPACPI_MATCH_UNKNOWN 0U
422 /* TPID('1', 'Y') == 0x5931 */
423 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
425 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
426 { .vendor = PCI_VENDOR_ID_IBM, \
427 .bios = TPID(__id1, __id2), \
428 .ec = TPACPI_MATCH_ANY, \
429 .quirks = (__quirk) }
431 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
432 { .vendor = PCI_VENDOR_ID_LENOVO, \
433 .bios = TPID(__id1, __id2), \
434 .ec = TPACPI_MATCH_ANY, \
435 .quirks = (__quirk) }
437 #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \
438 { .vendor = PCI_VENDOR_ID_LENOVO, \
439 .bios = TPACPI_MATCH_ANY, \
440 .ec = TPID(__id1, __id2), \
441 .quirks = (__quirk) }
443 struct tpacpi_quirk
{
447 unsigned long quirks
;
451 * tpacpi_check_quirks() - search BIOS/EC version on a list
452 * @qlist: array of &struct tpacpi_quirk
453 * @qlist_size: number of elements in @qlist
455 * Iterates over a quirks list until one is found that matches the
456 * ThinkPad's vendor, BIOS and EC model.
458 * Returns 0 if nothing matches, otherwise returns the quirks field of
459 * the matching &struct tpacpi_quirk entry.
461 * The match criteria is: vendor, ec and bios much match.
463 static unsigned long __init
tpacpi_check_quirks(
464 const struct tpacpi_quirk
*qlist
,
465 unsigned int qlist_size
)
468 if ((qlist
->vendor
== thinkpad_id
.vendor
||
469 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
470 (qlist
->bios
== thinkpad_id
.bios_model
||
471 qlist
->bios
== TPACPI_MATCH_ANY
) &&
472 (qlist
->ec
== thinkpad_id
.ec_model
||
473 qlist
->ec
== TPACPI_MATCH_ANY
))
474 return qlist
->quirks
;
483 /****************************************************************************
484 ****************************************************************************
486 * ACPI Helpers and device model
488 ****************************************************************************
489 ****************************************************************************/
491 /*************************************************************************
495 static acpi_handle root_handle
;
497 #define TPACPI_HANDLE(object, parent, paths...) \
498 static acpi_handle object##_handle; \
499 static acpi_handle *object##_parent = &parent##_handle; \
500 static char *object##_path; \
501 static char *object##_paths[] = { paths }
503 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
504 "\\_SB.PCI.ISA.EC", /* 570 */
505 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
506 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
507 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
508 "\\_SB.PCI0.ICH3.EC0", /* R31 */
509 "\\_SB.PCI0.LPC.EC", /* all others */
512 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
513 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
515 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
517 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
518 "\\CMS", /* R40, R40e */
521 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
522 "^HKEY", /* R30, R31 */
523 "HKEY", /* all others */
526 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
527 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
528 "\\_SB.PCI0.VID0", /* 770e */
529 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
530 "\\_SB.PCI0.AGP.VID", /* all others */
534 /*************************************************************************
538 static int acpi_evalf(acpi_handle handle
,
539 void *res
, char *method
, char *fmt
, ...)
542 struct acpi_object_list params
;
543 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
544 struct acpi_buffer result
, *resultp
;
545 union acpi_object out_obj
;
553 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
566 params
.pointer
= &in_objs
[0];
573 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
574 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
576 /* add more types as needed */
578 printk(TPACPI_ERR
"acpi_evalf() called "
579 "with invalid format character '%c'\n", c
);
585 if (res_type
!= 'v') {
586 result
.length
= sizeof(out_obj
);
587 result
.pointer
= &out_obj
;
592 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
597 *(int *)res
= out_obj
.integer
.value
;
598 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
601 success
= status
== AE_OK
;
603 /* add more types as needed */
605 printk(TPACPI_ERR
"acpi_evalf() called "
606 "with invalid format character '%c'\n", res_type
);
610 if (!success
&& !quiet
)
611 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
612 method
, fmt0
, status
);
617 static int acpi_ec_read(int i
, u8
*p
)
622 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
626 if (ec_read(i
, p
) < 0)
633 static int acpi_ec_write(int i
, u8 v
)
636 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
639 if (ec_write(i
, v
) < 0)
646 static int issue_thinkpad_cmos_command(int cmos_cmd
)
651 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
657 /*************************************************************************
661 #define TPACPI_ACPIHANDLE_INIT(object) \
662 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
663 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
665 static void drv_acpi_handle_init(char *name
,
666 acpi_handle
*handle
, acpi_handle parent
,
667 char **paths
, int num_paths
, char **path
)
672 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
675 for (i
= 0; i
< num_paths
; i
++) {
676 status
= acpi_get_handle(parent
, paths
[i
], handle
);
677 if (ACPI_SUCCESS(status
)) {
679 dbg_printk(TPACPI_DBG_INIT
,
680 "Found ACPI handle %s for %s\n",
686 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
691 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
693 struct ibm_struct
*ibm
= data
;
695 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
698 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
701 ibm
->acpi
->notify(ibm
, event
);
704 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
711 if (!*ibm
->acpi
->handle
)
714 vdbg_printk(TPACPI_DBG_INIT
,
715 "setting up ACPI notify for %s\n", ibm
->name
);
717 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
719 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
724 ibm
->acpi
->device
->driver_data
= ibm
;
725 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
726 TPACPI_ACPI_EVENT_PREFIX
,
729 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
730 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
731 if (ACPI_FAILURE(status
)) {
732 if (status
== AE_ALREADY_EXISTS
) {
734 "another device driver is already "
735 "handling %s events\n", ibm
->name
);
738 "acpi_install_notify_handler(%s) failed: %d\n",
743 ibm
->flags
.acpi_notify_installed
= 1;
747 static int __init
tpacpi_device_add(struct acpi_device
*device
)
752 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
756 dbg_printk(TPACPI_DBG_INIT
,
757 "registering %s as an ACPI driver\n", ibm
->name
);
761 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
762 if (!ibm
->acpi
->driver
) {
764 "failed to allocate memory for ibm->acpi->driver\n");
768 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
769 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
771 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
773 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
775 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
777 kfree(ibm
->acpi
->driver
);
778 ibm
->acpi
->driver
= NULL
;
780 ibm
->flags
.acpi_driver_registered
= 1;
786 /****************************************************************************
787 ****************************************************************************
791 ****************************************************************************
792 ****************************************************************************/
794 static int dispatch_proc_show(struct seq_file
*m
, void *v
)
796 struct ibm_struct
*ibm
= m
->private;
798 if (!ibm
|| !ibm
->read
)
803 static int dispatch_proc_open(struct inode
*inode
, struct file
*file
)
805 return single_open(file
, dispatch_proc_show
, PDE(inode
)->data
);
808 static ssize_t
dispatch_proc_write(struct file
*file
,
809 const char __user
*userbuf
,
810 size_t count
, loff_t
*pos
)
812 struct ibm_struct
*ibm
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
816 if (!ibm
|| !ibm
->write
)
818 if (count
> PAGE_SIZE
- 2)
821 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
825 if (copy_from_user(kernbuf
, userbuf
, count
)) {
831 strcat(kernbuf
, ",");
832 ret
= ibm
->write(kernbuf
);
841 static const struct file_operations dispatch_proc_fops
= {
842 .owner
= THIS_MODULE
,
843 .open
= dispatch_proc_open
,
846 .release
= single_release
,
847 .write
= dispatch_proc_write
,
850 static char *next_cmd(char **cmds
)
855 while ((end
= strchr(start
, ',')) && end
== start
)
867 /****************************************************************************
868 ****************************************************************************
870 * Device model: input, hwmon and platform
872 ****************************************************************************
873 ****************************************************************************/
875 static struct platform_device
*tpacpi_pdev
;
876 static struct platform_device
*tpacpi_sensors_pdev
;
877 static struct device
*tpacpi_hwmon
;
878 static struct input_dev
*tpacpi_inputdev
;
879 static struct mutex tpacpi_inputdev_send_mutex
;
880 static LIST_HEAD(tpacpi_all_drivers
);
882 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
885 struct ibm_struct
*ibm
, *itmp
;
887 list_for_each_entry_safe(ibm
, itmp
,
891 (ibm
->suspend
)(state
);
897 static int tpacpi_resume_handler(struct platform_device
*pdev
)
899 struct ibm_struct
*ibm
, *itmp
;
901 list_for_each_entry_safe(ibm
, itmp
,
911 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
913 struct ibm_struct
*ibm
, *itmp
;
915 list_for_each_entry_safe(ibm
, itmp
,
923 static struct platform_driver tpacpi_pdriver
= {
925 .name
= TPACPI_DRVR_NAME
,
926 .owner
= THIS_MODULE
,
928 .suspend
= tpacpi_suspend_handler
,
929 .resume
= tpacpi_resume_handler
,
930 .shutdown
= tpacpi_shutdown_handler
,
933 static struct platform_driver tpacpi_hwmon_pdriver
= {
935 .name
= TPACPI_HWMON_DRVR_NAME
,
936 .owner
= THIS_MODULE
,
940 /*************************************************************************
941 * sysfs support helpers
944 struct attribute_set
{
945 unsigned int members
, max_members
;
946 struct attribute_group group
;
949 struct attribute_set_obj
{
950 struct attribute_set s
;
952 } __attribute__((packed
));
954 static struct attribute_set
*create_attr_set(unsigned int max_members
,
957 struct attribute_set_obj
*sobj
;
959 if (max_members
== 0)
962 /* Allocates space for implicit NULL at the end too */
963 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
964 max_members
* sizeof(struct attribute
*),
968 sobj
->s
.max_members
= max_members
;
969 sobj
->s
.group
.attrs
= &sobj
->a
;
970 sobj
->s
.group
.name
= name
;
975 #define destroy_attr_set(_set) \
978 /* not multi-threaded safe, use it in a single thread per set */
979 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
984 if (s
->members
>= s
->max_members
)
987 s
->group
.attrs
[s
->members
] = attr
;
993 static int add_many_to_attr_set(struct attribute_set
*s
,
994 struct attribute
**attr
,
999 for (i
= 0; i
< count
; i
++) {
1000 res
= add_to_attr_set(s
, attr
[i
]);
1008 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
1010 sysfs_remove_group(kobj
, &s
->group
);
1011 destroy_attr_set(s
);
1014 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
1015 sysfs_create_group(_kobj, &_attr_set->group)
1017 static int parse_strtoul(const char *buf
,
1018 unsigned long max
, unsigned long *value
)
1022 *value
= simple_strtoul(skip_spaces(buf
), &endp
, 0);
1023 endp
= skip_spaces(endp
);
1024 if (*endp
|| *value
> max
)
1030 static void tpacpi_disable_brightness_delay(void)
1032 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
1033 printk(TPACPI_NOTICE
1034 "ACPI backlight control delay disabled\n");
1037 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
1039 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1040 union acpi_object
*obj
;
1043 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
1044 obj
= (union acpi_object
*)buffer
.pointer
;
1045 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
1046 printk(TPACPI_ERR
"Unknown _BCL data, "
1047 "please report this to %s\n", TPACPI_MAIL
);
1050 rc
= obj
->package
.count
;
1056 kfree(buffer
.pointer
);
1060 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1061 u32 lvl
, void *context
, void **rv
)
1063 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1064 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1066 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1067 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1068 BUG_ON(!rv
|| !*rv
);
1069 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1070 return AE_CTRL_TERMINATE
;
1077 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1079 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1083 void *bcl_ptr
= &bcl_levels
;
1086 TPACPI_ACPIHANDLE_INIT(vid
);
1092 * Search for a _BCL method, and execute it. This is safe on all
1093 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1094 * BIOS in ACPI backlight control mode. We do NOT have to care
1095 * about calling the _BCL method in an enabled video device, any
1096 * will do for our purposes.
1099 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1100 tpacpi_acpi_walk_find_bcl
, NULL
, NULL
,
1103 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1104 tp_features
.bright_acpimode
= 1;
1105 return (bcl_levels
- 2);
1111 static void printk_deprecated_attribute(const char * const what
,
1112 const char * const details
)
1114 tpacpi_log_usertask("deprecated sysfs attribute");
1115 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1116 "will be removed. %s\n",
1120 /*************************************************************************
1121 * rfkill and radio control support helpers
1125 * ThinkPad-ACPI firmware handling model:
1127 * WLSW (master wireless switch) is event-driven, and is common to all
1128 * firmware-controlled radios. It cannot be controlled, just monitored,
1129 * as expected. It overrides all radio state in firmware
1131 * The kernel, a masked-off hotkey, and WLSW can change the radio state
1132 * (TODO: verify how WLSW interacts with the returned radio state).
1134 * The only time there are shadow radio state changes, is when
1135 * masked-off hotkeys are used.
1139 * Internal driver API for radio state:
1141 * int: < 0 = error, otherwise enum tpacpi_rfkill_state
1142 * bool: true means radio blocked (off)
1144 enum tpacpi_rfkill_state
{
1145 TPACPI_RFK_RADIO_OFF
= 0,
1149 /* rfkill switches */
1150 enum tpacpi_rfk_id
{
1151 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
1152 TPACPI_RFK_WWAN_SW_ID
,
1153 TPACPI_RFK_UWB_SW_ID
,
1157 static const char *tpacpi_rfkill_names
[] = {
1158 [TPACPI_RFK_BLUETOOTH_SW_ID
] = "bluetooth",
1159 [TPACPI_RFK_WWAN_SW_ID
] = "wwan",
1160 [TPACPI_RFK_UWB_SW_ID
] = "uwb",
1161 [TPACPI_RFK_SW_MAX
] = NULL
1164 /* ThinkPad-ACPI rfkill subdriver */
1166 struct rfkill
*rfkill
;
1167 enum tpacpi_rfk_id id
;
1168 const struct tpacpi_rfk_ops
*ops
;
1171 struct tpacpi_rfk_ops
{
1172 /* firmware interface */
1173 int (*get_status
)(void);
1174 int (*set_status
)(const enum tpacpi_rfkill_state
);
1177 static struct tpacpi_rfk
*tpacpi_rfkill_switches
[TPACPI_RFK_SW_MAX
];
1179 /* Query FW and update rfkill sw state for a given rfkill switch */
1180 static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk
*tp_rfk
)
1187 status
= (tp_rfk
->ops
->get_status
)();
1191 rfkill_set_sw_state(tp_rfk
->rfkill
,
1192 (status
== TPACPI_RFK_RADIO_OFF
));
1197 /* Query FW and update rfkill sw state for all rfkill switches */
1198 static void tpacpi_rfk_update_swstate_all(void)
1202 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++)
1203 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[i
]);
1207 * Sync the HW-blocking state of all rfkill switches,
1208 * do notice it causes the rfkill core to schedule uevents
1210 static void tpacpi_rfk_update_hwblock_state(bool blocked
)
1213 struct tpacpi_rfk
*tp_rfk
;
1215 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++) {
1216 tp_rfk
= tpacpi_rfkill_switches
[i
];
1218 if (rfkill_set_hw_state(tp_rfk
->rfkill
,
1220 /* ignore -- we track sw block */
1226 /* Call to get the WLSW state from the firmware */
1227 static int hotkey_get_wlsw(void);
1229 /* Call to query WLSW state and update all rfkill switches */
1230 static bool tpacpi_rfk_check_hwblock_state(void)
1232 int res
= hotkey_get_wlsw();
1235 /* When unknown or unsupported, we have to assume it is unblocked */
1239 hw_blocked
= (res
== TPACPI_RFK_RADIO_OFF
);
1240 tpacpi_rfk_update_hwblock_state(hw_blocked
);
1245 static int tpacpi_rfk_hook_set_block(void *data
, bool blocked
)
1247 struct tpacpi_rfk
*tp_rfk
= data
;
1250 dbg_printk(TPACPI_DBG_RFKILL
,
1251 "request to change radio state to %s\n",
1252 blocked
? "blocked" : "unblocked");
1254 /* try to set radio state */
1255 res
= (tp_rfk
->ops
->set_status
)(blocked
?
1256 TPACPI_RFK_RADIO_OFF
: TPACPI_RFK_RADIO_ON
);
1258 /* and update the rfkill core with whatever the FW really did */
1259 tpacpi_rfk_update_swstate(tp_rfk
);
1261 return (res
< 0) ? res
: 0;
1264 static const struct rfkill_ops tpacpi_rfk_rfkill_ops
= {
1265 .set_block
= tpacpi_rfk_hook_set_block
,
1268 static int __init
tpacpi_new_rfkill(const enum tpacpi_rfk_id id
,
1269 const struct tpacpi_rfk_ops
*tp_rfkops
,
1270 const enum rfkill_type rfktype
,
1272 const bool set_default
)
1274 struct tpacpi_rfk
*atp_rfk
;
1276 bool sw_state
= false;
1280 BUG_ON(id
>= TPACPI_RFK_SW_MAX
|| tpacpi_rfkill_switches
[id
]);
1282 atp_rfk
= kzalloc(sizeof(struct tpacpi_rfk
), GFP_KERNEL
);
1284 atp_rfk
->rfkill
= rfkill_alloc(name
,
1287 &tpacpi_rfk_rfkill_ops
,
1289 if (!atp_rfk
|| !atp_rfk
->rfkill
) {
1291 "failed to allocate memory for rfkill class\n");
1297 atp_rfk
->ops
= tp_rfkops
;
1299 sw_status
= (tp_rfkops
->get_status
)();
1300 if (sw_status
< 0) {
1302 "failed to read initial state for %s, error %d\n",
1305 sw_state
= (sw_status
== TPACPI_RFK_RADIO_OFF
);
1307 /* try to keep the initial state, since we ask the
1308 * firmware to preserve it across S5 in NVRAM */
1309 rfkill_init_sw_state(atp_rfk
->rfkill
, sw_state
);
1312 hw_state
= tpacpi_rfk_check_hwblock_state();
1313 rfkill_set_hw_state(atp_rfk
->rfkill
, hw_state
);
1315 res
= rfkill_register(atp_rfk
->rfkill
);
1318 "failed to register %s rfkill switch: %d\n",
1320 rfkill_destroy(atp_rfk
->rfkill
);
1325 tpacpi_rfkill_switches
[id
] = atp_rfk
;
1327 printk(TPACPI_INFO
"rfkill switch %s: radio is %sblocked\n",
1328 name
, (sw_state
|| hw_state
) ? "" : "un");
1332 static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id
)
1334 struct tpacpi_rfk
*tp_rfk
;
1336 BUG_ON(id
>= TPACPI_RFK_SW_MAX
);
1338 tp_rfk
= tpacpi_rfkill_switches
[id
];
1340 rfkill_unregister(tp_rfk
->rfkill
);
1341 rfkill_destroy(tp_rfk
->rfkill
);
1342 tpacpi_rfkill_switches
[id
] = NULL
;
1347 static void printk_deprecated_rfkill_attribute(const char * const what
)
1349 printk_deprecated_attribute(what
,
1350 "Please switch to generic rfkill before year 2010");
1353 /* sysfs <radio> enable ------------------------------------------------ */
1354 static ssize_t
tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id
,
1355 struct device_attribute
*attr
,
1360 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1362 /* This is in the ABI... */
1363 if (tpacpi_rfk_check_hwblock_state()) {
1364 status
= TPACPI_RFK_RADIO_OFF
;
1366 status
= tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1371 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1372 (status
== TPACPI_RFK_RADIO_ON
) ? 1 : 0);
1375 static ssize_t
tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id
,
1376 struct device_attribute
*attr
,
1377 const char *buf
, size_t count
)
1382 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1384 if (parse_strtoul(buf
, 1, &t
))
1387 tpacpi_disclose_usertask(attr
->attr
.name
, "set to %ld\n", t
);
1389 /* This is in the ABI... */
1390 if (tpacpi_rfk_check_hwblock_state() && !!t
)
1393 res
= tpacpi_rfkill_switches
[id
]->ops
->set_status((!!t
) ?
1394 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
);
1395 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1397 return (res
< 0) ? res
: count
;
1400 /* procfs -------------------------------------------------------------- */
1401 static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id
, struct seq_file
*m
)
1403 if (id
>= TPACPI_RFK_SW_MAX
)
1404 seq_printf(m
, "status:\t\tnot supported\n");
1408 /* This is in the ABI... */
1409 if (tpacpi_rfk_check_hwblock_state()) {
1410 status
= TPACPI_RFK_RADIO_OFF
;
1412 status
= tpacpi_rfk_update_swstate(
1413 tpacpi_rfkill_switches
[id
]);
1418 seq_printf(m
, "status:\t\t%s\n",
1419 (status
== TPACPI_RFK_RADIO_ON
) ?
1420 "enabled" : "disabled");
1421 seq_printf(m
, "commands:\tenable, disable\n");
1427 static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id
, char *buf
)
1433 if (id
>= TPACPI_RFK_SW_MAX
)
1436 while ((cmd
= next_cmd(&buf
))) {
1437 if (strlencmp(cmd
, "enable") == 0)
1438 status
= TPACPI_RFK_RADIO_ON
;
1439 else if (strlencmp(cmd
, "disable") == 0)
1440 status
= TPACPI_RFK_RADIO_OFF
;
1446 tpacpi_disclose_usertask("procfs", "attempt to %s %s\n",
1447 (status
== TPACPI_RFK_RADIO_ON
) ?
1448 "enable" : "disable",
1449 tpacpi_rfkill_names
[id
]);
1450 res
= (tpacpi_rfkill_switches
[id
]->ops
->set_status
)(status
);
1451 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1457 /*************************************************************************
1458 * thinkpad-acpi driver attributes
1461 /* interface_version --------------------------------------------------- */
1462 static ssize_t
tpacpi_driver_interface_version_show(
1463 struct device_driver
*drv
,
1466 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1469 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1470 tpacpi_driver_interface_version_show
, NULL
);
1472 /* debug_level --------------------------------------------------------- */
1473 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1476 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1479 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1480 const char *buf
, size_t count
)
1484 if (parse_strtoul(buf
, 0xffff, &t
))
1492 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1493 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1495 /* version ------------------------------------------------------------- */
1496 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1499 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1500 TPACPI_DESC
, TPACPI_VERSION
);
1503 static DRIVER_ATTR(version
, S_IRUGO
,
1504 tpacpi_driver_version_show
, NULL
);
1506 /* --------------------------------------------------------------------- */
1508 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1510 /* wlsw_emulstate ------------------------------------------------------ */
1511 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1514 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1517 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1518 const char *buf
, size_t count
)
1522 if (parse_strtoul(buf
, 1, &t
))
1525 if (tpacpi_wlsw_emulstate
!= !!t
) {
1526 tpacpi_wlsw_emulstate
= !!t
;
1527 tpacpi_rfk_update_hwblock_state(!t
); /* negative logic */
1533 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1534 tpacpi_driver_wlsw_emulstate_show
,
1535 tpacpi_driver_wlsw_emulstate_store
);
1537 /* bluetooth_emulstate ------------------------------------------------- */
1538 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1539 struct device_driver
*drv
,
1542 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1545 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1546 struct device_driver
*drv
,
1547 const char *buf
, size_t count
)
1551 if (parse_strtoul(buf
, 1, &t
))
1554 tpacpi_bluetooth_emulstate
= !!t
;
1559 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1560 tpacpi_driver_bluetooth_emulstate_show
,
1561 tpacpi_driver_bluetooth_emulstate_store
);
1563 /* wwan_emulstate ------------------------------------------------- */
1564 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1565 struct device_driver
*drv
,
1568 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1571 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1572 struct device_driver
*drv
,
1573 const char *buf
, size_t count
)
1577 if (parse_strtoul(buf
, 1, &t
))
1580 tpacpi_wwan_emulstate
= !!t
;
1585 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1586 tpacpi_driver_wwan_emulstate_show
,
1587 tpacpi_driver_wwan_emulstate_store
);
1589 /* uwb_emulstate ------------------------------------------------- */
1590 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1591 struct device_driver
*drv
,
1594 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1597 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1598 struct device_driver
*drv
,
1599 const char *buf
, size_t count
)
1603 if (parse_strtoul(buf
, 1, &t
))
1606 tpacpi_uwb_emulstate
= !!t
;
1611 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1612 tpacpi_driver_uwb_emulstate_show
,
1613 tpacpi_driver_uwb_emulstate_store
);
1616 /* --------------------------------------------------------------------- */
1618 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1619 &driver_attr_debug_level
, &driver_attr_version
,
1620 &driver_attr_interface_version
,
1623 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1629 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1630 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1634 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1635 if (!res
&& dbg_wlswemul
)
1636 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1637 if (!res
&& dbg_bluetoothemul
)
1638 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1639 if (!res
&& dbg_wwanemul
)
1640 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1641 if (!res
&& dbg_uwbemul
)
1642 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1648 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1652 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1653 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1655 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1656 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1657 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1658 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1659 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1663 /*************************************************************************
1668 * Table of recommended minimum BIOS versions
1670 * Reasons for listing:
1671 * 1. Stable BIOS, listed because the unknown ammount of
1672 * bugs and bad ACPI behaviour on older versions
1674 * 2. BIOS or EC fw with known bugs that trigger on Linux
1676 * 3. BIOS with known reduced functionality in older versions
1678 * We recommend the latest BIOS and EC version.
1679 * We only support the latest BIOS and EC fw version as a rule.
1681 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1682 * Information from users in ThinkWiki
1684 * WARNING: we use this table also to detect that the machine is
1685 * a ThinkPad in some cases, so don't remove entries lightly.
1688 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1689 { .vendor = (__v), \
1690 .bios = TPID(__id1, __id2), \
1691 .ec = TPACPI_MATCH_ANY, \
1692 .quirks = TPACPI_MATCH_ANY << 16 \
1693 | (__bv1) << 8 | (__bv2) }
1695 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1696 __eid, __ev1, __ev2) \
1697 { .vendor = (__v), \
1698 .bios = TPID(__bid1, __bid2), \
1700 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1701 | (__bv1) << 8 | (__bv2) }
1703 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1704 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1706 /* Outdated IBM BIOSes often lack the EC id string */
1707 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1708 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1709 __bv1, __bv2, TPID(__id1, __id2), \
1711 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1712 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1715 /* Outdated IBM BIOSes often lack the EC id string */
1716 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1717 __eid1, __eid2, __ev1, __ev2) \
1718 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1719 __bv1, __bv2, TPID(__eid1, __eid2), \
1721 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1722 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1725 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1726 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1728 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1729 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1730 __bv1, __bv2, TPID(__id1, __id2), \
1733 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1734 __eid1, __eid2, __ev1, __ev2) \
1735 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1736 __bv1, __bv2, TPID(__eid1, __eid2), \
1739 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1740 /* Numeric models ------------------ */
1741 /* FW MODEL BIOS VERS */
1742 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1743 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1744 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1745 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1746 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1747 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1748 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1749 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1750 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1752 /* A-series ------------------------- */
1753 /* FW MODEL BIOS VERS EC VERS */
1754 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1755 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1756 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1757 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1758 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1759 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1760 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1761 TPV_QI0('1', '3', '2', '0'), /* A22m */
1762 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1763 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1764 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1766 /* G-series ------------------------- */
1767 /* FW MODEL BIOS VERS */
1768 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1769 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1771 /* R-series, T-series --------------- */
1772 /* FW MODEL BIOS VERS EC VERS */
1773 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1774 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1775 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1776 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1777 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1778 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1779 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1780 T40/p, T41/p, T42/p (1) */
1781 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1782 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1783 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1784 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1786 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1787 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1788 TPV_QI0('1', '6', '3', '2'), /* T22 */
1789 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1790 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1791 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1793 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1794 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1795 TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */
1797 /* BIOS FW BIOS VERS EC FW EC VERS */
1798 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1799 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1801 /* X-series ------------------------- */
1802 /* FW MODEL BIOS VERS EC VERS */
1803 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1804 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1805 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1806 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1807 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1808 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1809 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1811 TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */
1812 TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */
1814 /* (0) - older versions lack DMI EC fw string and functionality */
1815 /* (1) - older versions known to lack functionality */
1826 static void __init
tpacpi_check_outdated_fw(void)
1828 unsigned long fwvers
;
1829 u16 ec_version
, bios_version
;
1831 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1832 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1837 bios_version
= fwvers
& 0xffffU
;
1838 ec_version
= (fwvers
>> 16) & 0xffffU
;
1840 /* note that unknown versions are set to 0x0000 and we use that */
1841 if ((bios_version
> thinkpad_id
.bios_release
) ||
1842 (ec_version
> thinkpad_id
.ec_release
&&
1843 ec_version
!= TPACPI_MATCH_ANY
)) {
1845 * The changelogs would let us track down the exact
1846 * reason, but it is just too much of a pain to track
1847 * it. We only list BIOSes that are either really
1848 * broken, or really stable to begin with, so it is
1849 * best if the user upgrades the firmware anyway.
1852 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1854 "WARNING: This firmware may be missing critical bug "
1855 "fixes and/or important features\n");
1859 static bool __init
tpacpi_is_fw_known(void)
1861 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1862 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1865 /****************************************************************************
1866 ****************************************************************************
1870 ****************************************************************************
1871 ****************************************************************************/
1873 /*************************************************************************
1874 * thinkpad-acpi init subdriver
1877 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1879 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1880 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1882 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1883 (thinkpad_id
.bios_version_str
) ?
1884 thinkpad_id
.bios_version_str
: "unknown",
1885 (thinkpad_id
.ec_version_str
) ?
1886 thinkpad_id
.ec_version_str
: "unknown");
1888 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1889 printk(TPACPI_INFO
"%s %s, model %s\n",
1890 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1891 "IBM" : ((thinkpad_id
.vendor
==
1892 PCI_VENDOR_ID_LENOVO
) ?
1893 "Lenovo" : "Unknown vendor"),
1894 thinkpad_id
.model_str
,
1895 (thinkpad_id
.nummodel_str
) ?
1896 thinkpad_id
.nummodel_str
: "unknown");
1898 tpacpi_check_outdated_fw();
1902 static int thinkpad_acpi_driver_read(struct seq_file
*m
)
1904 seq_printf(m
, "driver:\t\t%s\n", TPACPI_DESC
);
1905 seq_printf(m
, "version:\t%s\n", TPACPI_VERSION
);
1909 static struct ibm_struct thinkpad_acpi_driver_data
= {
1911 .read
= thinkpad_acpi_driver_read
,
1914 /*************************************************************************
1919 * ThinkPad firmware event model
1921 * The ThinkPad firmware has two main event interfaces: normal ACPI
1922 * notifications (which follow the ACPI standard), and a private event
1925 * The private event interface also issues events for the hotkeys. As
1926 * the driver gained features, the event handling code ended up being
1927 * built around the hotkey subdriver. This will need to be refactored
1928 * to a more formal event API eventually.
1930 * Some "hotkeys" are actually supposed to be used as event reports,
1931 * such as "brightness has changed", "volume has changed", depending on
1932 * the ThinkPad model and how the firmware is operating.
1934 * Unlike other classes, hotkey-class events have mask/unmask control on
1935 * non-ancient firmware. However, how it behaves changes a lot with the
1936 * firmware model and version.
1939 enum { /* hot key scan codes (derived from ACPI DSDT) */
1940 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1941 TP_ACPI_HOTKEYSCAN_FNF2
,
1942 TP_ACPI_HOTKEYSCAN_FNF3
,
1943 TP_ACPI_HOTKEYSCAN_FNF4
,
1944 TP_ACPI_HOTKEYSCAN_FNF5
,
1945 TP_ACPI_HOTKEYSCAN_FNF6
,
1946 TP_ACPI_HOTKEYSCAN_FNF7
,
1947 TP_ACPI_HOTKEYSCAN_FNF8
,
1948 TP_ACPI_HOTKEYSCAN_FNF9
,
1949 TP_ACPI_HOTKEYSCAN_FNF10
,
1950 TP_ACPI_HOTKEYSCAN_FNF11
,
1951 TP_ACPI_HOTKEYSCAN_FNF12
,
1952 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1953 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1954 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1955 TP_ACPI_HOTKEYSCAN_FNHOME
,
1956 TP_ACPI_HOTKEYSCAN_FNEND
,
1957 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1958 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1959 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1960 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1961 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1962 TP_ACPI_HOTKEYSCAN_MUTE
,
1963 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1966 enum { /* Keys/events available through NVRAM polling */
1967 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1968 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1971 enum { /* Positions of some of the keys in hotkey masks */
1972 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1973 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1974 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1975 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1976 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1977 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1978 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1979 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1980 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1981 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1982 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1985 enum { /* NVRAM to ACPI HKEY group map */
1986 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1987 TP_ACPI_HKEY_ZOOM_MASK
|
1988 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1989 TP_ACPI_HKEY_HIBERNATE_MASK
,
1990 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1991 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1992 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1993 TP_ACPI_HKEY_VOLDWN_MASK
|
1994 TP_ACPI_HKEY_MUTE_MASK
,
1997 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1998 struct tp_nvram_state
{
1999 u16 thinkpad_toggle
:1;
2001 u16 display_toggle
:1;
2002 u16 thinklight_toggle
:1;
2003 u16 hibernate_toggle
:1;
2004 u16 displayexp_toggle
:1;
2005 u16 display_state
:1;
2006 u16 brightness_toggle
:1;
2007 u16 volume_toggle
:1;
2010 u8 brightness_level
;
2014 /* kthread for the hotkey poller */
2015 static struct task_struct
*tpacpi_hotkey_task
;
2017 /* Acquired while the poller kthread is running, use to sync start/stop */
2018 static struct mutex hotkey_thread_mutex
;
2021 * Acquire mutex to write poller control variables as an
2024 * Increment hotkey_config_change when changing them if you
2025 * want the kthread to forget old state.
2027 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2029 static struct mutex hotkey_thread_data_mutex
;
2030 static unsigned int hotkey_config_change
;
2033 * hotkey poller control variables
2035 * Must be atomic or readers will also need to acquire mutex
2037 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2038 * should be used only when the changes need to be taken as
2039 * a block, OR when one needs to force the kthread to forget
2042 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
2043 static unsigned int hotkey_poll_freq
= 10; /* Hz */
2045 #define HOTKEY_CONFIG_CRITICAL_START \
2047 mutex_lock(&hotkey_thread_data_mutex); \
2048 hotkey_config_change++; \
2050 #define HOTKEY_CONFIG_CRITICAL_END \
2051 mutex_unlock(&hotkey_thread_data_mutex);
2053 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2055 #define hotkey_source_mask 0U
2056 #define HOTKEY_CONFIG_CRITICAL_START
2057 #define HOTKEY_CONFIG_CRITICAL_END
2059 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2061 static struct mutex hotkey_mutex
;
2063 static enum { /* Reasons for waking up */
2064 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
2065 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
2066 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
2067 } hotkey_wakeup_reason
;
2069 static int hotkey_autosleep_ack
;
2071 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
2072 static u32 hotkey_all_mask
; /* all events supported in fw */
2073 static u32 hotkey_reserved_mask
; /* events better left disabled */
2074 static u32 hotkey_driver_mask
; /* events needed by the driver */
2075 static u32 hotkey_user_mask
; /* events visible to userspace */
2076 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
2078 static unsigned int hotkey_report_mode
;
2080 static u16
*hotkey_keycode_map
;
2082 static struct attribute_set
*hotkey_dev_attributes
;
2084 static void tpacpi_driver_event(const unsigned int hkey_event
);
2085 static void hotkey_driver_event(const unsigned int scancode
);
2086 static void hotkey_poll_setup(const bool may_warn
);
2088 /* HKEY.MHKG() return bits */
2089 #define TP_HOTKEY_TABLET_MASK (1 << 3)
2091 static int hotkey_get_wlsw(void)
2095 if (!tp_features
.hotkey_wlsw
)
2098 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2100 return (tpacpi_wlsw_emulstate
) ?
2101 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2104 if (!acpi_evalf(hkey_handle
, &status
, "WLSW", "d"))
2107 return (status
) ? TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2110 static int hotkey_get_tablet_mode(int *status
)
2114 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
2117 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
2122 * Reads current event mask from firmware, and updates
2123 * hotkey_acpi_mask accordingly. Also resets any bits
2124 * from hotkey_user_mask that are unavailable to be
2125 * delivered (shadow requirement of the userspace ABI).
2127 * Call with hotkey_mutex held
2129 static int hotkey_mask_get(void)
2131 if (tp_features
.hotkey_mask
) {
2134 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
2137 hotkey_acpi_mask
= m
;
2139 /* no mask support doesn't mean no event support... */
2140 hotkey_acpi_mask
= hotkey_all_mask
;
2143 /* sync userspace-visible mask */
2144 hotkey_user_mask
&= (hotkey_acpi_mask
| hotkey_source_mask
);
2149 void static hotkey_mask_warn_incomplete_mask(void)
2151 /* log only what the user can fix... */
2152 const u32 wantedmask
= hotkey_driver_mask
&
2153 ~(hotkey_acpi_mask
| hotkey_source_mask
) &
2154 (hotkey_all_mask
| TPACPI_HKEY_NVRAM_KNOWN_MASK
);
2157 printk(TPACPI_NOTICE
2158 "required events 0x%08x not enabled!\n",
2163 * Set the firmware mask when supported
2165 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
2167 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
2169 * Call with hotkey_mutex held
2171 static int hotkey_mask_set(u32 mask
)
2176 const u32 fwmask
= mask
& ~hotkey_source_mask
;
2178 if (tp_features
.hotkey_mask
) {
2179 for (i
= 0; i
< 32; i
++) {
2180 if (!acpi_evalf(hkey_handle
,
2181 NULL
, "MHKM", "vdd", i
+ 1,
2182 !!(mask
& (1 << i
)))) {
2190 * We *must* make an inconditional call to hotkey_mask_get to
2191 * refresh hotkey_acpi_mask and update hotkey_user_mask
2193 * Take the opportunity to also log when we cannot _enable_
2196 if (!hotkey_mask_get() && !rc
&& (fwmask
& ~hotkey_acpi_mask
)) {
2197 printk(TPACPI_NOTICE
2198 "asked for hotkey mask 0x%08x, but "
2199 "firmware forced it to 0x%08x\n",
2200 fwmask
, hotkey_acpi_mask
);
2203 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
)
2204 hotkey_mask_warn_incomplete_mask();
2210 * Sets hotkey_user_mask and tries to set the firmware mask
2212 * Call with hotkey_mutex held
2214 static int hotkey_user_mask_set(const u32 mask
)
2218 /* Give people a chance to notice they are doing something that
2219 * is bound to go boom on their users sooner or later */
2220 if (!tp_warned
.hotkey_mask_ff
&&
2221 (mask
== 0xffff || mask
== 0xffffff ||
2222 mask
== 0xffffffff)) {
2223 tp_warned
.hotkey_mask_ff
= 1;
2224 printk(TPACPI_NOTICE
2225 "setting the hotkey mask to 0x%08x is likely "
2226 "not the best way to go about it\n", mask
);
2227 printk(TPACPI_NOTICE
2228 "please consider using the driver defaults, "
2229 "and refer to up-to-date thinkpad-acpi "
2233 /* Try to enable what the user asked for, plus whatever we need.
2234 * this syncs everything but won't enable bits in hotkey_user_mask */
2235 rc
= hotkey_mask_set((mask
| hotkey_driver_mask
) & ~hotkey_source_mask
);
2237 /* Enable the available bits in hotkey_user_mask */
2238 hotkey_user_mask
= mask
& (hotkey_acpi_mask
| hotkey_source_mask
);
2244 * Sets the driver hotkey mask.
2246 * Can be called even if the hotkey subdriver is inactive
2248 static int tpacpi_hotkey_driver_mask_set(const u32 mask
)
2252 /* Do the right thing if hotkey_init has not been called yet */
2253 if (!tp_features
.hotkey
) {
2254 hotkey_driver_mask
= mask
;
2258 mutex_lock(&hotkey_mutex
);
2260 HOTKEY_CONFIG_CRITICAL_START
2261 hotkey_driver_mask
= mask
;
2262 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2263 hotkey_source_mask
|= (mask
& ~hotkey_all_mask
);
2265 HOTKEY_CONFIG_CRITICAL_END
2267 rc
= hotkey_mask_set((hotkey_acpi_mask
| hotkey_driver_mask
) &
2268 ~hotkey_source_mask
);
2269 hotkey_poll_setup(true);
2271 mutex_unlock(&hotkey_mutex
);
2276 static int hotkey_status_get(int *status
)
2278 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
2284 static int hotkey_status_set(bool enable
)
2286 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
2292 static void tpacpi_input_send_tabletsw(void)
2296 if (tp_features
.hotkey_tablet
&&
2297 !hotkey_get_tablet_mode(&state
)) {
2298 mutex_lock(&tpacpi_inputdev_send_mutex
);
2300 input_report_switch(tpacpi_inputdev
,
2301 SW_TABLET_MODE
, !!state
);
2302 input_sync(tpacpi_inputdev
);
2304 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2308 /* Do NOT call without validating scancode first */
2309 static void tpacpi_input_send_key(const unsigned int scancode
)
2311 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
2313 if (keycode
!= KEY_RESERVED
) {
2314 mutex_lock(&tpacpi_inputdev_send_mutex
);
2316 input_report_key(tpacpi_inputdev
, keycode
, 1);
2317 if (keycode
== KEY_UNKNOWN
)
2318 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2320 input_sync(tpacpi_inputdev
);
2322 input_report_key(tpacpi_inputdev
, keycode
, 0);
2323 if (keycode
== KEY_UNKNOWN
)
2324 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2326 input_sync(tpacpi_inputdev
);
2328 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2332 /* Do NOT call without validating scancode first */
2333 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
2335 hotkey_driver_event(scancode
);
2336 if (hotkey_user_mask
& (1 << scancode
))
2337 tpacpi_input_send_key(scancode
);
2340 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2341 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2343 /* Do NOT call without validating scancode first */
2344 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2346 tpacpi_input_send_key_masked(scancode
);
2347 if (hotkey_report_mode
< 2) {
2348 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2349 0x80, TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
2353 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2357 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2358 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2359 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2360 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2361 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2362 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2364 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2365 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2366 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2368 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2369 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2370 n
->displayexp_toggle
=
2371 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2373 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2374 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2375 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2376 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2377 n
->brightness_toggle
=
2378 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2380 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2381 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2382 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2383 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2384 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2385 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2389 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2390 struct tp_nvram_state
*newn
,
2391 const u32 event_mask
)
2394 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2396 if ((event_mask & (1 << __scancode)) && \
2397 oldn->__member != newn->__member) \
2398 tpacpi_hotkey_send_key(__scancode); \
2401 #define TPACPI_MAY_SEND_KEY(__scancode) \
2403 if (event_mask & (1 << __scancode)) \
2404 tpacpi_hotkey_send_key(__scancode); \
2407 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2408 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2409 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2410 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2412 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2414 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2417 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2418 if (oldn
->mute
!= newn
->mute
) {
2419 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2421 if (oldn
->volume_level
> newn
->volume_level
) {
2422 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2423 } else if (oldn
->volume_level
< newn
->volume_level
) {
2424 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2425 } else if (oldn
->mute
== newn
->mute
) {
2426 /* repeated key presses that didn't change state */
2428 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2429 } else if (newn
->volume_level
!= 0) {
2430 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2432 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2437 /* handle brightness */
2438 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2439 if (oldn
->brightness_level
< newn
->brightness_level
) {
2440 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2441 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
2442 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2444 /* repeated key presses that didn't change state */
2445 if (newn
->brightness_level
!= 0) {
2446 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2448 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2453 #undef TPACPI_COMPARE_KEY
2454 #undef TPACPI_MAY_SEND_KEY
2460 * We track all events in hotkey_source_mask all the time, since
2461 * most of them are edge-based. We only issue those requested by
2462 * hotkey_user_mask or hotkey_driver_mask, though.
2464 static int hotkey_kthread(void *data
)
2466 struct tp_nvram_state s
[2];
2467 u32 poll_mask
, event_mask
;
2468 unsigned int si
, so
;
2470 unsigned int change_detector
, must_reset
;
2471 unsigned int poll_freq
;
2473 mutex_lock(&hotkey_thread_mutex
);
2475 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2484 /* Initial state for compares */
2485 mutex_lock(&hotkey_thread_data_mutex
);
2486 change_detector
= hotkey_config_change
;
2487 poll_mask
= hotkey_source_mask
;
2488 event_mask
= hotkey_source_mask
&
2489 (hotkey_driver_mask
| hotkey_user_mask
);
2490 poll_freq
= hotkey_poll_freq
;
2491 mutex_unlock(&hotkey_thread_data_mutex
);
2492 hotkey_read_nvram(&s
[so
], poll_mask
);
2494 while (!kthread_should_stop()) {
2496 if (likely(poll_freq
))
2499 t
= 100; /* should never happen... */
2501 t
= msleep_interruptible(t
);
2502 if (unlikely(kthread_should_stop()))
2504 must_reset
= try_to_freeze();
2505 if (t
> 0 && !must_reset
)
2508 mutex_lock(&hotkey_thread_data_mutex
);
2509 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2510 /* forget old state on thaw or config change */
2513 change_detector
= hotkey_config_change
;
2515 poll_mask
= hotkey_source_mask
;
2516 event_mask
= hotkey_source_mask
&
2517 (hotkey_driver_mask
| hotkey_user_mask
);
2518 poll_freq
= hotkey_poll_freq
;
2519 mutex_unlock(&hotkey_thread_data_mutex
);
2521 if (likely(poll_mask
)) {
2522 hotkey_read_nvram(&s
[si
], poll_mask
);
2523 if (likely(si
!= so
)) {
2524 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2534 mutex_unlock(&hotkey_thread_mutex
);
2538 /* call with hotkey_mutex held */
2539 static void hotkey_poll_stop_sync(void)
2541 if (tpacpi_hotkey_task
) {
2542 if (frozen(tpacpi_hotkey_task
) ||
2543 freezing(tpacpi_hotkey_task
))
2544 thaw_process(tpacpi_hotkey_task
);
2546 kthread_stop(tpacpi_hotkey_task
);
2547 tpacpi_hotkey_task
= NULL
;
2548 mutex_lock(&hotkey_thread_mutex
);
2549 /* at this point, the thread did exit */
2550 mutex_unlock(&hotkey_thread_mutex
);
2554 /* call with hotkey_mutex held */
2555 static void hotkey_poll_setup(const bool may_warn
)
2557 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2558 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2560 if (hotkey_poll_freq
> 0 &&
2561 (poll_driver_mask
||
2562 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2563 if (!tpacpi_hotkey_task
) {
2564 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2565 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2566 if (IS_ERR(tpacpi_hotkey_task
)) {
2567 tpacpi_hotkey_task
= NULL
;
2569 "could not create kernel thread "
2570 "for hotkey polling\n");
2574 hotkey_poll_stop_sync();
2575 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2576 hotkey_poll_freq
== 0) {
2577 printk(TPACPI_NOTICE
2578 "hot keys 0x%08x and/or events 0x%08x "
2579 "require polling, which is currently "
2581 poll_user_mask
, poll_driver_mask
);
2586 static void hotkey_poll_setup_safe(const bool may_warn
)
2588 mutex_lock(&hotkey_mutex
);
2589 hotkey_poll_setup(may_warn
);
2590 mutex_unlock(&hotkey_mutex
);
2593 /* call with hotkey_mutex held */
2594 static void hotkey_poll_set_freq(unsigned int freq
)
2597 hotkey_poll_stop_sync();
2599 hotkey_poll_freq
= freq
;
2602 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2604 static void hotkey_poll_setup(const bool __unused
)
2608 static void hotkey_poll_setup_safe(const bool __unused
)
2612 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2614 static int hotkey_inputdev_open(struct input_dev
*dev
)
2616 switch (tpacpi_lifecycle
) {
2617 case TPACPI_LIFE_INIT
:
2618 case TPACPI_LIFE_RUNNING
:
2619 hotkey_poll_setup_safe(false);
2621 case TPACPI_LIFE_EXITING
:
2625 /* Should only happen if tpacpi_lifecycle is corrupt */
2630 static void hotkey_inputdev_close(struct input_dev
*dev
)
2632 /* disable hotkey polling when possible */
2633 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
&&
2634 !(hotkey_source_mask
& hotkey_driver_mask
))
2635 hotkey_poll_setup_safe(false);
2638 /* sysfs hotkey enable ------------------------------------------------- */
2639 static ssize_t
hotkey_enable_show(struct device
*dev
,
2640 struct device_attribute
*attr
,
2645 printk_deprecated_attribute("hotkey_enable",
2646 "Hotkey reporting is always enabled");
2648 res
= hotkey_status_get(&status
);
2652 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2655 static ssize_t
hotkey_enable_store(struct device
*dev
,
2656 struct device_attribute
*attr
,
2657 const char *buf
, size_t count
)
2661 printk_deprecated_attribute("hotkey_enable",
2662 "Hotkeys can be disabled through hotkey_mask");
2664 if (parse_strtoul(buf
, 1, &t
))
2673 static struct device_attribute dev_attr_hotkey_enable
=
2674 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2675 hotkey_enable_show
, hotkey_enable_store
);
2677 /* sysfs hotkey mask --------------------------------------------------- */
2678 static ssize_t
hotkey_mask_show(struct device
*dev
,
2679 struct device_attribute
*attr
,
2682 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2685 static ssize_t
hotkey_mask_store(struct device
*dev
,
2686 struct device_attribute
*attr
,
2687 const char *buf
, size_t count
)
2692 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2695 if (mutex_lock_killable(&hotkey_mutex
))
2696 return -ERESTARTSYS
;
2698 res
= hotkey_user_mask_set(t
);
2700 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2701 hotkey_poll_setup(true);
2704 mutex_unlock(&hotkey_mutex
);
2706 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2708 return (res
) ? res
: count
;
2711 static struct device_attribute dev_attr_hotkey_mask
=
2712 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2713 hotkey_mask_show
, hotkey_mask_store
);
2715 /* sysfs hotkey bios_enabled ------------------------------------------- */
2716 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2717 struct device_attribute
*attr
,
2720 return sprintf(buf
, "0\n");
2723 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2724 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2726 /* sysfs hotkey bios_mask ---------------------------------------------- */
2727 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2728 struct device_attribute
*attr
,
2731 printk_deprecated_attribute("hotkey_bios_mask",
2732 "This attribute is useless.");
2733 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2736 static struct device_attribute dev_attr_hotkey_bios_mask
=
2737 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2739 /* sysfs hotkey all_mask ----------------------------------------------- */
2740 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2741 struct device_attribute
*attr
,
2744 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2745 hotkey_all_mask
| hotkey_source_mask
);
2748 static struct device_attribute dev_attr_hotkey_all_mask
=
2749 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2751 /* sysfs hotkey recommended_mask --------------------------------------- */
2752 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2753 struct device_attribute
*attr
,
2756 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2757 (hotkey_all_mask
| hotkey_source_mask
)
2758 & ~hotkey_reserved_mask
);
2761 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2762 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2763 hotkey_recommended_mask_show
, NULL
);
2765 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2767 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2768 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2769 struct device_attribute
*attr
,
2772 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2775 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2776 struct device_attribute
*attr
,
2777 const char *buf
, size_t count
)
2783 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2784 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2787 if (mutex_lock_killable(&hotkey_mutex
))
2788 return -ERESTARTSYS
;
2790 HOTKEY_CONFIG_CRITICAL_START
2791 hotkey_source_mask
= t
;
2792 HOTKEY_CONFIG_CRITICAL_END
2794 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2795 ~hotkey_source_mask
);
2796 hotkey_poll_setup(true);
2798 /* check if events needed by the driver got disabled */
2799 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2800 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2802 mutex_unlock(&hotkey_mutex
);
2805 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2806 "firmware event mask!\n");
2809 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2810 "some important events were disabled: "
2813 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2815 return (rc
< 0) ? rc
: count
;
2818 static struct device_attribute dev_attr_hotkey_source_mask
=
2819 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2820 hotkey_source_mask_show
, hotkey_source_mask_store
);
2822 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2823 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2824 struct device_attribute
*attr
,
2827 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2830 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2831 struct device_attribute
*attr
,
2832 const char *buf
, size_t count
)
2836 if (parse_strtoul(buf
, 25, &t
))
2839 if (mutex_lock_killable(&hotkey_mutex
))
2840 return -ERESTARTSYS
;
2842 hotkey_poll_set_freq(t
);
2843 hotkey_poll_setup(true);
2845 mutex_unlock(&hotkey_mutex
);
2847 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2852 static struct device_attribute dev_attr_hotkey_poll_freq
=
2853 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2854 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2856 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2858 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2859 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2860 struct device_attribute
*attr
,
2864 res
= hotkey_get_wlsw();
2868 /* Opportunistic update */
2869 tpacpi_rfk_update_hwblock_state((res
== TPACPI_RFK_RADIO_OFF
));
2871 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2872 (res
== TPACPI_RFK_RADIO_OFF
) ? 0 : 1);
2875 static struct device_attribute dev_attr_hotkey_radio_sw
=
2876 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2878 static void hotkey_radio_sw_notify_change(void)
2880 if (tp_features
.hotkey_wlsw
)
2881 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2885 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2886 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2887 struct device_attribute
*attr
,
2891 res
= hotkey_get_tablet_mode(&s
);
2895 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2898 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2899 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2901 static void hotkey_tablet_mode_notify_change(void)
2903 if (tp_features
.hotkey_tablet
)
2904 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2905 "hotkey_tablet_mode");
2908 /* sysfs hotkey report_mode -------------------------------------------- */
2909 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2910 struct device_attribute
*attr
,
2913 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2914 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2917 static struct device_attribute dev_attr_hotkey_report_mode
=
2918 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2920 /* sysfs wakeup reason (pollable) -------------------------------------- */
2921 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2922 struct device_attribute
*attr
,
2925 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2928 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2929 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2931 static void hotkey_wakeup_reason_notify_change(void)
2933 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2937 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2938 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2939 struct device_attribute
*attr
,
2942 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2945 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2946 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2947 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2949 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2951 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2952 "wakeup_hotunplug_complete");
2955 /* --------------------------------------------------------------------- */
2957 static struct attribute
*hotkey_attributes
[] __initdata
= {
2958 &dev_attr_hotkey_enable
.attr
,
2959 &dev_attr_hotkey_bios_enabled
.attr
,
2960 &dev_attr_hotkey_bios_mask
.attr
,
2961 &dev_attr_hotkey_report_mode
.attr
,
2962 &dev_attr_hotkey_wakeup_reason
.attr
,
2963 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2964 &dev_attr_hotkey_mask
.attr
,
2965 &dev_attr_hotkey_all_mask
.attr
,
2966 &dev_attr_hotkey_recommended_mask
.attr
,
2967 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2968 &dev_attr_hotkey_source_mask
.attr
,
2969 &dev_attr_hotkey_poll_freq
.attr
,
2974 * Sync both the hw and sw blocking state of all switches
2976 static void tpacpi_send_radiosw_update(void)
2981 * We must sync all rfkill controllers *before* issuing any
2982 * rfkill input events, or we will race the rfkill core input
2985 * tpacpi_inputdev_send_mutex works as a syncronization point
2988 * We optimize to avoid numerous calls to hotkey_get_wlsw.
2991 wlsw
= hotkey_get_wlsw();
2993 /* Sync hw blocking state first if it is hw-blocked */
2994 if (wlsw
== TPACPI_RFK_RADIO_OFF
)
2995 tpacpi_rfk_update_hwblock_state(true);
2997 /* Sync sw blocking state */
2998 tpacpi_rfk_update_swstate_all();
3000 /* Sync hw blocking state last if it is hw-unblocked */
3001 if (wlsw
== TPACPI_RFK_RADIO_ON
)
3002 tpacpi_rfk_update_hwblock_state(false);
3004 /* Issue rfkill input event for WLSW switch */
3006 mutex_lock(&tpacpi_inputdev_send_mutex
);
3008 input_report_switch(tpacpi_inputdev
,
3009 SW_RFKILL_ALL
, (wlsw
> 0));
3010 input_sync(tpacpi_inputdev
);
3012 mutex_unlock(&tpacpi_inputdev_send_mutex
);
3016 * this can be unconditional, as we will poll state again
3017 * if userspace uses the notify to read data
3019 hotkey_radio_sw_notify_change();
3022 static void hotkey_exit(void)
3024 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3025 mutex_lock(&hotkey_mutex
);
3026 hotkey_poll_stop_sync();
3027 mutex_unlock(&hotkey_mutex
);
3030 if (hotkey_dev_attributes
)
3031 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3033 kfree(hotkey_keycode_map
);
3035 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
3036 "restoring original HKEY status and mask\n");
3037 /* yes, there is a bitwise or below, we want the
3038 * functions to be called even if one of them fail */
3039 if (((tp_features
.hotkey_mask
&&
3040 hotkey_mask_set(hotkey_orig_mask
)) |
3041 hotkey_status_set(false)) != 0)
3043 "failed to restore hot key mask "
3044 "to BIOS defaults\n");
3047 static void __init
hotkey_unmap(const unsigned int scancode
)
3049 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
3050 clear_bit(hotkey_keycode_map
[scancode
],
3051 tpacpi_inputdev
->keybit
);
3052 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
3058 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
3061 #define TPACPI_HK_Q_INIMASK 0x0001
3063 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
3064 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
3065 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
3066 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
3067 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
3068 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
3069 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
3070 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
3071 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
3072 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
3073 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
3074 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
3075 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
3076 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
3077 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
3078 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
3079 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
3080 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
3081 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
3082 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
3085 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
3087 /* Requirements for changing the default keymaps:
3089 * 1. Many of the keys are mapped to KEY_RESERVED for very
3090 * good reasons. Do not change them unless you have deep
3091 * knowledge on the IBM and Lenovo ThinkPad firmware for
3092 * the various ThinkPad models. The driver behaves
3093 * differently for KEY_RESERVED: such keys have their
3094 * hot key mask *unset* in mask_recommended, and also
3095 * in the initial hot key mask programmed into the
3096 * firmware at driver load time, which means the firm-
3097 * ware may react very differently if you change them to
3100 * 2. You must be subscribed to the linux-thinkpad and
3101 * ibm-acpi-devel mailing lists, and you should read the
3102 * list archives since 2007 if you want to change the
3103 * keymaps. This requirement exists so that you will
3104 * know the past history of problems with the thinkpad-
3105 * acpi driver keymaps, and also that you will be
3106 * listening to any bug reports;
3108 * 3. Do not send thinkpad-acpi specific patches directly to
3109 * for merging, *ever*. Send them to the linux-acpi
3110 * mailinglist for comments. Merging is to be done only
3111 * through acpi-test and the ACPI maintainer.
3113 * If the above is too much to ask, don't change the keymap.
3114 * Ask the thinkpad-acpi maintainer to do it, instead.
3116 static u16 ibm_keycode_map
[] __initdata
= {
3117 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3118 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
3119 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3120 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3122 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3123 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3124 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3125 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3127 /* brightness: firmware always reacts to them */
3128 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
3129 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
3131 /* Thinklight: firmware always react to it */
3132 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3134 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3135 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3137 /* Volume: firmware always react to it and reprograms
3138 * the built-in *extra* mixer. Never map it to control
3139 * another mixer by default. */
3140 KEY_RESERVED
, /* 0x14: VOLUME UP */
3141 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3142 KEY_RESERVED
, /* 0x16: MUTE */
3144 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3146 /* (assignments unknown, please report if found) */
3147 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3148 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3150 static u16 lenovo_keycode_map
[] __initdata
= {
3151 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3152 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
3153 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3154 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3156 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3157 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3158 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3159 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3161 /* These should be enabled --only-- when ACPI video
3162 * is disabled (i.e. in "vendor" mode), and are handled
3163 * in a special way by the init code */
3164 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
3165 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
3167 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3169 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3170 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3172 /* Volume: z60/z61, T60 (BIOS version?): firmware always
3173 * react to it and reprograms the built-in *extra* mixer.
3174 * Never map it to control another mixer by default.
3176 * T60?, T61, R60?, R61: firmware and EC tries to send
3177 * these over the regular keyboard, so these are no-ops,
3178 * but there are still weird bugs re. MUTE, so do not
3179 * change unless you get test reports from all Lenovo
3180 * models. May cause the BIOS to interfere with the
3183 KEY_RESERVED
, /* 0x14: VOLUME UP */
3184 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3185 KEY_RESERVED
, /* 0x16: MUTE */
3187 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3189 /* (assignments unknown, please report if found) */
3190 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3191 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3194 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
3195 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
3196 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
3201 bool radiosw_state
= false;
3202 bool tabletsw_state
= false;
3204 unsigned long quirks
;
3206 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3207 "initializing hotkey subdriver\n");
3209 BUG_ON(!tpacpi_inputdev
);
3210 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
3211 tpacpi_inputdev
->close
!= NULL
);
3213 TPACPI_ACPIHANDLE_INIT(hkey
);
3214 mutex_init(&hotkey_mutex
);
3216 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3217 mutex_init(&hotkey_thread_mutex
);
3218 mutex_init(&hotkey_thread_data_mutex
);
3221 /* hotkey not supported on 570 */
3222 tp_features
.hotkey
= hkey_handle
!= NULL
;
3224 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3226 str_supported(tp_features
.hotkey
));
3228 if (!tp_features
.hotkey
)
3231 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
3232 ARRAY_SIZE(tpacpi_hotkey_qtable
));
3234 tpacpi_disable_brightness_delay();
3236 /* MUST have enough space for all attributes to be added to
3237 * hotkey_dev_attributes */
3238 hotkey_dev_attributes
= create_attr_set(
3239 ARRAY_SIZE(hotkey_attributes
) + 2,
3241 if (!hotkey_dev_attributes
)
3243 res
= add_many_to_attr_set(hotkey_dev_attributes
,
3245 ARRAY_SIZE(hotkey_attributes
));
3249 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
3250 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
3251 for HKEY interface version 0x100 */
3252 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
3253 if ((hkeyv
>> 8) != 1) {
3254 printk(TPACPI_ERR
"unknown version of the "
3255 "HKEY interface: 0x%x\n", hkeyv
);
3256 printk(TPACPI_ERR
"please report this to %s\n",
3260 * MHKV 0x100 in A31, R40, R40e,
3261 * T4x, X31, and later
3263 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3264 "firmware HKEY interface version: 0x%x\n",
3267 /* Paranoia check AND init hotkey_all_mask */
3268 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
3271 "missing MHKA handler, "
3272 "please report this to %s\n",
3274 /* Fallback: pre-init for FN+F3,F4,F12 */
3275 hotkey_all_mask
= 0x080cU
;
3277 tp_features
.hotkey_mask
= 1;
3282 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3283 "hotkey masks are %s\n",
3284 str_supported(tp_features
.hotkey_mask
));
3286 /* Init hotkey_all_mask if not initialized yet */
3287 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
3288 (quirks
& TPACPI_HK_Q_INIMASK
))
3289 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
3291 /* Init hotkey_acpi_mask and hotkey_orig_mask */
3292 if (tp_features
.hotkey_mask
) {
3293 /* hotkey_source_mask *must* be zero for
3294 * the first hotkey_mask_get to return hotkey_orig_mask */
3295 res
= hotkey_mask_get();
3299 hotkey_orig_mask
= hotkey_acpi_mask
;
3301 hotkey_orig_mask
= hotkey_all_mask
;
3302 hotkey_acpi_mask
= hotkey_all_mask
;
3305 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3307 tp_features
.hotkey_wlsw
= 1;
3308 radiosw_state
= !!tpacpi_wlsw_emulstate
;
3310 "radio switch emulation enabled\n");
3313 /* Not all thinkpads have a hardware radio switch */
3314 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3315 tp_features
.hotkey_wlsw
= 1;
3316 radiosw_state
= !!status
;
3318 "radio switch found; radios are %s\n",
3319 enabled(status
, 0));
3321 if (tp_features
.hotkey_wlsw
)
3322 res
= add_to_attr_set(hotkey_dev_attributes
,
3323 &dev_attr_hotkey_radio_sw
.attr
);
3325 /* For X41t, X60t, X61t Tablets... */
3326 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3327 tp_features
.hotkey_tablet
= 1;
3328 tabletsw_state
= !!(status
& TP_HOTKEY_TABLET_MASK
);
3330 "possible tablet mode switch found; "
3331 "ThinkPad in %s mode\n",
3332 (tabletsw_state
) ? "tablet" : "laptop");
3333 res
= add_to_attr_set(hotkey_dev_attributes
,
3334 &dev_attr_hotkey_tablet_mode
.attr
);
3338 res
= register_attr_set_with_sysfs(
3339 hotkey_dev_attributes
,
3340 &tpacpi_pdev
->dev
.kobj
);
3344 /* Set up key map */
3346 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3348 if (!hotkey_keycode_map
) {
3350 "failed to allocate memory for key map\n");
3355 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
3356 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3357 "using Lenovo default hot key map\n");
3358 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
3359 TPACPI_HOTKEY_MAP_SIZE
);
3361 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3362 "using IBM default hot key map\n");
3363 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
3364 TPACPI_HOTKEY_MAP_SIZE
);
3367 input_set_capability(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
);
3368 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3369 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3370 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3371 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3372 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3373 input_set_capability(tpacpi_inputdev
, EV_KEY
,
3374 hotkey_keycode_map
[i
]);
3376 if (i
< sizeof(hotkey_reserved_mask
)*8)
3377 hotkey_reserved_mask
|= 1 << i
;
3381 if (tp_features
.hotkey_wlsw
) {
3382 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_RFKILL_ALL
);
3383 input_report_switch(tpacpi_inputdev
,
3384 SW_RFKILL_ALL
, radiosw_state
);
3386 if (tp_features
.hotkey_tablet
) {
3387 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_TABLET_MODE
);
3388 input_report_switch(tpacpi_inputdev
,
3389 SW_TABLET_MODE
, tabletsw_state
);
3392 /* Do not issue duplicate brightness change events to
3394 if (!tp_features
.bright_acpimode
)
3395 /* update bright_acpimode... */
3396 tpacpi_check_std_acpi_brightness_support();
3398 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
3400 "This ThinkPad has standard ACPI backlight "
3401 "brightness control, supported by the ACPI "
3403 printk(TPACPI_NOTICE
3404 "Disabling thinkpad-acpi brightness events "
3407 /* Disable brightness up/down on Lenovo thinkpads when
3408 * ACPI is handling them, otherwise it is plain impossible
3409 * for userspace to do something even remotely sane */
3410 hotkey_reserved_mask
|=
3411 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3412 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3413 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3414 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3417 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3418 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3420 & ~hotkey_reserved_mask
;
3422 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3423 "hotkey source mask 0x%08x, polling freq %u\n",
3424 hotkey_source_mask
, hotkey_poll_freq
);
3427 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3428 "enabling firmware HKEY event interface...\n");
3429 res
= hotkey_status_set(true);
3434 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3435 | hotkey_driver_mask
)
3436 & ~hotkey_source_mask
);
3437 if (res
< 0 && res
!= -ENXIO
) {
3441 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3442 & ~hotkey_reserved_mask
;
3443 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3444 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3445 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3447 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3448 "legacy ibm/hotkey event reporting over procfs %s\n",
3449 (hotkey_report_mode
< 2) ?
3450 "enabled" : "disabled");
3452 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3453 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3455 hotkey_poll_setup_safe(true);
3460 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3461 hotkey_dev_attributes
= NULL
;
3463 return (res
< 0)? res
: 1;
3466 static bool hotkey_notify_hotkey(const u32 hkey
,
3468 bool *ignore_acpi_ev
)
3470 /* 0x1000-0x1FFF: key presses */
3471 unsigned int scancode
= hkey
& 0xfff;
3472 *send_acpi_ev
= true;
3473 *ignore_acpi_ev
= false;
3475 if (scancode
> 0 && scancode
< 0x21) {
3477 if (!(hotkey_source_mask
& (1 << scancode
))) {
3478 tpacpi_input_send_key_masked(scancode
);
3479 *send_acpi_ev
= false;
3481 *ignore_acpi_ev
= true;
3488 static bool hotkey_notify_wakeup(const u32 hkey
,
3490 bool *ignore_acpi_ev
)
3492 /* 0x2000-0x2FFF: Wakeup reason */
3493 *send_acpi_ev
= true;
3494 *ignore_acpi_ev
= false;
3497 case TP_HKEY_EV_WKUP_S3_UNDOCK
: /* suspend, undock */
3498 case TP_HKEY_EV_WKUP_S4_UNDOCK
: /* hibernation, undock */
3499 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3500 *ignore_acpi_ev
= true;
3503 case TP_HKEY_EV_WKUP_S3_BAYEJ
: /* suspend, bay eject */
3504 case TP_HKEY_EV_WKUP_S4_BAYEJ
: /* hibernation, bay eject */
3505 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3506 *ignore_acpi_ev
= true;
3509 case TP_HKEY_EV_WKUP_S3_BATLOW
: /* Battery on critical low level/S3 */
3510 case TP_HKEY_EV_WKUP_S4_BATLOW
: /* Battery on critical low level/S4 */
3512 "EMERGENCY WAKEUP: battery almost empty\n");
3513 /* how to auto-heal: */
3514 /* 2313: woke up from S3, go to S4/S5 */
3515 /* 2413: woke up from S4, go to S5 */
3522 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3524 "woke up due to a hot-unplug "
3526 hotkey_wakeup_reason_notify_change();
3531 static bool hotkey_notify_usrevent(const u32 hkey
,
3533 bool *ignore_acpi_ev
)
3535 /* 0x5000-0x5FFF: human interface helpers */
3536 *send_acpi_ev
= true;
3537 *ignore_acpi_ev
= false;
3540 case TP_HKEY_EV_PEN_INSERTED
: /* X61t: tablet pen inserted into bay */
3541 case TP_HKEY_EV_PEN_REMOVED
: /* X61t: tablet pen removed from bay */
3544 case TP_HKEY_EV_TABLET_TABLET
: /* X41t-X61t: tablet mode */
3545 case TP_HKEY_EV_TABLET_NOTEBOOK
: /* X41t-X61t: normal mode */
3546 tpacpi_input_send_tabletsw();
3547 hotkey_tablet_mode_notify_change();
3548 *send_acpi_ev
= false;
3551 case TP_HKEY_EV_LID_CLOSE
: /* Lid closed */
3552 case TP_HKEY_EV_LID_OPEN
: /* Lid opened */
3553 case TP_HKEY_EV_BRGHT_CHANGED
: /* brightness changed */
3554 /* do not propagate these events */
3555 *ignore_acpi_ev
= true;
3563 static void thermal_dump_all_sensors(void);
3565 static bool hotkey_notify_thermal(const u32 hkey
,
3567 bool *ignore_acpi_ev
)
3571 /* 0x6000-0x6FFF: thermal alarms */
3572 *send_acpi_ev
= true;
3573 *ignore_acpi_ev
= false;
3576 case TP_HKEY_EV_THM_TABLE_CHANGED
:
3578 "EC reports that Thermal Table has changed\n");
3579 /* recommended action: do nothing, we don't have
3580 * Lenovo ATM information */
3582 case TP_HKEY_EV_ALARM_BAT_HOT
:
3584 "THERMAL ALARM: battery is too hot!\n");
3585 /* recommended action: warn user through gui */
3587 case TP_HKEY_EV_ALARM_BAT_XHOT
:
3589 "THERMAL EMERGENCY: battery is extremely hot!\n");
3590 /* recommended action: immediate sleep/hibernate */
3592 case TP_HKEY_EV_ALARM_SENSOR_HOT
:
3595 "a sensor reports something is too hot!\n");
3596 /* recommended action: warn user through gui, that */
3597 /* some internal component is too hot */
3599 case TP_HKEY_EV_ALARM_SENSOR_XHOT
:
3601 "THERMAL EMERGENCY: "
3602 "a sensor reports something is extremely hot!\n");
3603 /* recommended action: immediate sleep/hibernate */
3607 "THERMAL ALERT: unknown thermal alarm received\n");
3611 thermal_dump_all_sensors();
3616 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3620 bool ignore_acpi_ev
;
3623 if (event
!= 0x80) {
3625 "unknown HKEY notification event %d\n", event
);
3626 /* forward it to userspace, maybe it knows how to handle it */
3627 acpi_bus_generate_netlink_event(
3628 ibm
->acpi
->device
->pnp
.device_class
,
3629 dev_name(&ibm
->acpi
->device
->dev
),
3635 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3636 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3645 send_acpi_ev
= true;
3646 ignore_acpi_ev
= false;
3648 switch (hkey
>> 12) {
3650 /* 0x1000-0x1FFF: key presses */
3651 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3655 /* 0x2000-0x2FFF: Wakeup reason */
3656 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3660 /* 0x3000-0x3FFF: bay-related wakeups */
3662 case TP_HKEY_EV_BAYEJ_ACK
:
3663 hotkey_autosleep_ack
= 1;
3666 hotkey_wakeup_hotunplug_complete_notify_change();
3669 case TP_HKEY_EV_OPTDRV_EJ
:
3670 /* FIXME: kick libata if SATA link offline */
3678 /* 0x4000-0x4FFF: dock-related wakeups */
3679 if (hkey
== TP_HKEY_EV_UNDOCK_ACK
) {
3680 hotkey_autosleep_ack
= 1;
3683 hotkey_wakeup_hotunplug_complete_notify_change();
3690 /* 0x5000-0x5FFF: human interface helpers */
3691 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3695 /* 0x6000-0x6FFF: thermal alarms */
3696 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3700 /* 0x7000-0x7FFF: misc */
3701 if (tp_features
.hotkey_wlsw
&&
3702 hkey
== TP_HKEY_EV_RFKILL_CHANGED
) {
3703 tpacpi_send_radiosw_update();
3708 /* fallthrough to default */
3713 printk(TPACPI_NOTICE
3714 "unhandled HKEY event 0x%04x\n", hkey
);
3715 printk(TPACPI_NOTICE
3716 "please report the conditions when this "
3717 "event happened to %s\n", TPACPI_MAIL
);
3721 if (!ignore_acpi_ev
&&
3722 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3723 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3727 /* netlink events */
3728 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3729 acpi_bus_generate_netlink_event(
3730 ibm
->acpi
->device
->pnp
.device_class
,
3731 dev_name(&ibm
->acpi
->device
->dev
),
3737 static void hotkey_suspend(pm_message_t state
)
3739 /* Do these on suspend, we get the events on early resume! */
3740 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3741 hotkey_autosleep_ack
= 0;
3744 static void hotkey_resume(void)
3746 tpacpi_disable_brightness_delay();
3748 if (hotkey_status_set(true) < 0 ||
3749 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3751 "error while attempting to reset the event "
3752 "firmware interface\n");
3754 tpacpi_send_radiosw_update();
3755 hotkey_tablet_mode_notify_change();
3756 hotkey_wakeup_reason_notify_change();
3757 hotkey_wakeup_hotunplug_complete_notify_change();
3758 hotkey_poll_setup_safe(false);
3761 /* procfs -------------------------------------------------------------- */
3762 static int hotkey_read(struct seq_file
*m
)
3766 if (!tp_features
.hotkey
) {
3767 seq_printf(m
, "status:\t\tnot supported\n");
3771 if (mutex_lock_killable(&hotkey_mutex
))
3772 return -ERESTARTSYS
;
3773 res
= hotkey_status_get(&status
);
3775 res
= hotkey_mask_get();
3776 mutex_unlock(&hotkey_mutex
);
3780 seq_printf(m
, "status:\t\t%s\n", enabled(status
, 0));
3781 if (hotkey_all_mask
) {
3782 seq_printf(m
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3783 seq_printf(m
, "commands:\tenable, disable, reset, <mask>\n");
3785 seq_printf(m
, "mask:\t\tnot supported\n");
3786 seq_printf(m
, "commands:\tenable, disable, reset\n");
3792 static void hotkey_enabledisable_warn(bool enable
)
3794 tpacpi_log_usertask("procfs hotkey enable/disable");
3795 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3797 "hotkey enable/disable functionality has been "
3798 "removed from the driver. Hotkeys are always "
3801 "Please remove the hotkey=enable module "
3802 "parameter, it is deprecated. Hotkeys are always "
3806 static int hotkey_write(char *buf
)
3812 if (!tp_features
.hotkey
)
3815 if (mutex_lock_killable(&hotkey_mutex
))
3816 return -ERESTARTSYS
;
3818 mask
= hotkey_user_mask
;
3821 while ((cmd
= next_cmd(&buf
))) {
3822 if (strlencmp(cmd
, "enable") == 0) {
3823 hotkey_enabledisable_warn(1);
3824 } else if (strlencmp(cmd
, "disable") == 0) {
3825 hotkey_enabledisable_warn(0);
3827 } else if (strlencmp(cmd
, "reset") == 0) {
3828 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3829 & ~hotkey_reserved_mask
;
3830 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3832 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3841 tpacpi_disclose_usertask("procfs hotkey",
3842 "set mask to 0x%08x\n", mask
);
3843 res
= hotkey_user_mask_set(mask
);
3847 mutex_unlock(&hotkey_mutex
);
3851 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3852 {TPACPI_ACPI_HKEY_HID
, 0},
3856 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3857 .hid
= ibm_htk_device_ids
,
3858 .notify
= hotkey_notify
,
3859 .handle
= &hkey_handle
,
3860 .type
= ACPI_DEVICE_NOTIFY
,
3863 static struct ibm_struct hotkey_driver_data
= {
3865 .read
= hotkey_read
,
3866 .write
= hotkey_write
,
3867 .exit
= hotkey_exit
,
3868 .resume
= hotkey_resume
,
3869 .suspend
= hotkey_suspend
,
3870 .acpi
= &ibm_hotkey_acpidriver
,
3873 /*************************************************************************
3874 * Bluetooth subdriver
3878 /* ACPI GBDC/SBDC bits */
3879 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3880 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3881 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3882 0 = disable, 1 = enable */
3886 /* ACPI \BLTH commands */
3887 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3888 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3889 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3890 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3891 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3894 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3896 static int bluetooth_get_status(void)
3900 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3901 if (dbg_bluetoothemul
)
3902 return (tpacpi_bluetooth_emulstate
) ?
3903 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3906 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3909 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3910 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3913 static int bluetooth_set_status(enum tpacpi_rfkill_state state
)
3917 vdbg_printk(TPACPI_DBG_RFKILL
,
3918 "will attempt to %s bluetooth\n",
3919 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
3921 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3922 if (dbg_bluetoothemul
) {
3923 tpacpi_bluetooth_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
3928 if (state
== TPACPI_RFK_RADIO_ON
)
3929 status
= TP_ACPI_BLUETOOTH_RADIOSSW
3930 | TP_ACPI_BLUETOOTH_RESUMECTRL
;
3934 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3940 /* sysfs bluetooth enable ---------------------------------------------- */
3941 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3942 struct device_attribute
*attr
,
3945 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID
,
3949 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3950 struct device_attribute
*attr
,
3951 const char *buf
, size_t count
)
3953 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID
,
3957 static struct device_attribute dev_attr_bluetooth_enable
=
3958 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3959 bluetooth_enable_show
, bluetooth_enable_store
);
3961 /* --------------------------------------------------------------------- */
3963 static struct attribute
*bluetooth_attributes
[] = {
3964 &dev_attr_bluetooth_enable
.attr
,
3968 static const struct attribute_group bluetooth_attr_group
= {
3969 .attrs
= bluetooth_attributes
,
3972 static const struct tpacpi_rfk_ops bluetooth_tprfk_ops
= {
3973 .get_status
= bluetooth_get_status
,
3974 .set_status
= bluetooth_set_status
,
3977 static void bluetooth_shutdown(void)
3979 /* Order firmware to save current state to NVRAM */
3980 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3981 TP_ACPI_BLTH_SAVE_STATE
))
3982 printk(TPACPI_NOTICE
3983 "failed to save bluetooth state to NVRAM\n");
3985 vdbg_printk(TPACPI_DBG_RFKILL
,
3986 "bluestooth state saved to NVRAM\n");
3989 static void bluetooth_exit(void)
3991 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3992 &bluetooth_attr_group
);
3994 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
3996 bluetooth_shutdown();
3999 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
4004 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4005 "initializing bluetooth subdriver\n");
4007 TPACPI_ACPIHANDLE_INIT(hkey
);
4009 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4010 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
4011 tp_features
.bluetooth
= hkey_handle
&&
4012 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
4014 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4015 "bluetooth is %s, status 0x%02x\n",
4016 str_supported(tp_features
.bluetooth
),
4019 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4020 if (dbg_bluetoothemul
) {
4021 tp_features
.bluetooth
= 1;
4023 "bluetooth switch emulation enabled\n");
4026 if (tp_features
.bluetooth
&&
4027 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
4028 /* no bluetooth hardware present in system */
4029 tp_features
.bluetooth
= 0;
4030 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4031 "bluetooth hardware not installed\n");
4034 if (!tp_features
.bluetooth
)
4037 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
4038 &bluetooth_tprfk_ops
,
4039 RFKILL_TYPE_BLUETOOTH
,
4040 TPACPI_RFK_BLUETOOTH_SW_NAME
,
4045 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4046 &bluetooth_attr_group
);
4048 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
4055 /* procfs -------------------------------------------------------------- */
4056 static int bluetooth_read(struct seq_file
*m
)
4058 return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID
, m
);
4061 static int bluetooth_write(char *buf
)
4063 return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID
, buf
);
4066 static struct ibm_struct bluetooth_driver_data
= {
4067 .name
= "bluetooth",
4068 .read
= bluetooth_read
,
4069 .write
= bluetooth_write
,
4070 .exit
= bluetooth_exit
,
4071 .shutdown
= bluetooth_shutdown
,
4074 /*************************************************************************
4079 /* ACPI GWAN/SWAN bits */
4080 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
4081 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
4082 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
4083 0 = disable, 1 = enable */
4086 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
4088 static int wan_get_status(void)
4092 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4094 return (tpacpi_wwan_emulstate
) ?
4095 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4098 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
4101 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
4102 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4105 static int wan_set_status(enum tpacpi_rfkill_state state
)
4109 vdbg_printk(TPACPI_DBG_RFKILL
,
4110 "will attempt to %s wwan\n",
4111 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4113 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4115 tpacpi_wwan_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4120 if (state
== TPACPI_RFK_RADIO_ON
)
4121 status
= TP_ACPI_WANCARD_RADIOSSW
4122 | TP_ACPI_WANCARD_RESUMECTRL
;
4126 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
4132 /* sysfs wan enable ---------------------------------------------------- */
4133 static ssize_t
wan_enable_show(struct device
*dev
,
4134 struct device_attribute
*attr
,
4137 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID
,
4141 static ssize_t
wan_enable_store(struct device
*dev
,
4142 struct device_attribute
*attr
,
4143 const char *buf
, size_t count
)
4145 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID
,
4149 static struct device_attribute dev_attr_wan_enable
=
4150 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4151 wan_enable_show
, wan_enable_store
);
4153 /* --------------------------------------------------------------------- */
4155 static struct attribute
*wan_attributes
[] = {
4156 &dev_attr_wan_enable
.attr
,
4160 static const struct attribute_group wan_attr_group
= {
4161 .attrs
= wan_attributes
,
4164 static const struct tpacpi_rfk_ops wan_tprfk_ops
= {
4165 .get_status
= wan_get_status
,
4166 .set_status
= wan_set_status
,
4169 static void wan_shutdown(void)
4171 /* Order firmware to save current state to NVRAM */
4172 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4173 TP_ACPI_WGSV_SAVE_STATE
))
4174 printk(TPACPI_NOTICE
4175 "failed to save WWAN state to NVRAM\n");
4177 vdbg_printk(TPACPI_DBG_RFKILL
,
4178 "WWAN state saved to NVRAM\n");
4181 static void wan_exit(void)
4183 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4186 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4191 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4196 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4197 "initializing wan subdriver\n");
4199 TPACPI_ACPIHANDLE_INIT(hkey
);
4201 tp_features
.wan
= hkey_handle
&&
4202 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4204 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4205 "wan is %s, status 0x%02x\n",
4206 str_supported(tp_features
.wan
),
4209 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4211 tp_features
.wan
= 1;
4213 "wwan switch emulation enabled\n");
4216 if (tp_features
.wan
&&
4217 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4218 /* no wan hardware present in system */
4219 tp_features
.wan
= 0;
4220 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4221 "wan hardware not installed\n");
4224 if (!tp_features
.wan
)
4227 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4230 TPACPI_RFK_WWAN_SW_NAME
,
4235 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4239 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4246 /* procfs -------------------------------------------------------------- */
4247 static int wan_read(struct seq_file
*m
)
4249 return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID
, m
);
4252 static int wan_write(char *buf
)
4254 return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID
, buf
);
4257 static struct ibm_struct wan_driver_data
= {
4262 .shutdown
= wan_shutdown
,
4265 /*************************************************************************
4270 /* ACPI GUWB/SUWB bits */
4271 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4272 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4275 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4277 static int uwb_get_status(void)
4281 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4283 return (tpacpi_uwb_emulstate
) ?
4284 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4287 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4290 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4291 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4294 static int uwb_set_status(enum tpacpi_rfkill_state state
)
4298 vdbg_printk(TPACPI_DBG_RFKILL
,
4299 "will attempt to %s UWB\n",
4300 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4302 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4304 tpacpi_uwb_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4309 if (state
== TPACPI_RFK_RADIO_ON
)
4310 status
= TP_ACPI_UWB_RADIOSSW
;
4314 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4320 /* --------------------------------------------------------------------- */
4322 static const struct tpacpi_rfk_ops uwb_tprfk_ops
= {
4323 .get_status
= uwb_get_status
,
4324 .set_status
= uwb_set_status
,
4327 static void uwb_exit(void)
4329 tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID
);
4332 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4337 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4338 "initializing uwb subdriver\n");
4340 TPACPI_ACPIHANDLE_INIT(hkey
);
4342 tp_features
.uwb
= hkey_handle
&&
4343 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4345 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4346 "uwb is %s, status 0x%02x\n",
4347 str_supported(tp_features
.uwb
),
4350 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4352 tp_features
.uwb
= 1;
4354 "uwb switch emulation enabled\n");
4357 if (tp_features
.uwb
&&
4358 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4359 /* no uwb hardware present in system */
4360 tp_features
.uwb
= 0;
4361 dbg_printk(TPACPI_DBG_INIT
,
4362 "uwb hardware not installed\n");
4365 if (!tp_features
.uwb
)
4368 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4371 TPACPI_RFK_UWB_SW_NAME
,
4376 static struct ibm_struct uwb_driver_data
= {
4379 .flags
.experimental
= 1,
4382 /*************************************************************************
4386 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4388 enum video_access_mode
{
4389 TPACPI_VIDEO_NONE
= 0,
4390 TPACPI_VIDEO_570
, /* 570 */
4391 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4392 TPACPI_VIDEO_NEW
, /* all others */
4395 enum { /* video status flags, based on VIDEO_570 */
4396 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4397 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4398 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4401 enum { /* TPACPI_VIDEO_570 constants */
4402 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4403 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4404 * video_status_flags */
4405 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4406 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4409 static enum video_access_mode video_supported
;
4410 static int video_orig_autosw
;
4412 static int video_autosw_get(void);
4413 static int video_autosw_set(int enable
);
4415 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4417 static int __init
video_init(struct ibm_init_struct
*iibm
)
4421 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4423 TPACPI_ACPIHANDLE_INIT(vid
);
4424 TPACPI_ACPIHANDLE_INIT(vid2
);
4426 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4427 /* G41, assume IVGA doesn't change */
4428 vid_handle
= vid2_handle
;
4431 /* video switching not supported on R30, R31 */
4432 video_supported
= TPACPI_VIDEO_NONE
;
4433 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4435 video_supported
= TPACPI_VIDEO_570
;
4436 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4437 /* 600e/x, 770e, 770x */
4438 video_supported
= TPACPI_VIDEO_770
;
4441 video_supported
= TPACPI_VIDEO_NEW
;
4443 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4444 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4447 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4450 static void video_exit(void)
4452 dbg_printk(TPACPI_DBG_EXIT
,
4453 "restoring original video autoswitch mode\n");
4454 if (video_autosw_set(video_orig_autosw
))
4455 printk(TPACPI_ERR
"error while trying to restore original "
4456 "video autoswitch mode\n");
4459 static int video_outputsw_get(void)
4464 switch (video_supported
) {
4465 case TPACPI_VIDEO_570
:
4466 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4467 TP_ACPI_VIDEO_570_PHSCMD
))
4469 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4471 case TPACPI_VIDEO_770
:
4472 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4475 status
|= TP_ACPI_VIDEO_S_LCD
;
4476 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4479 status
|= TP_ACPI_VIDEO_S_CRT
;
4481 case TPACPI_VIDEO_NEW
:
4482 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4483 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4486 status
|= TP_ACPI_VIDEO_S_CRT
;
4488 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4489 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4492 status
|= TP_ACPI_VIDEO_S_LCD
;
4493 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4496 status
|= TP_ACPI_VIDEO_S_DVI
;
4505 static int video_outputsw_set(int status
)
4510 switch (video_supported
) {
4511 case TPACPI_VIDEO_570
:
4512 res
= acpi_evalf(NULL
, NULL
,
4513 "\\_SB.PHS2", "vdd",
4514 TP_ACPI_VIDEO_570_PHS2CMD
,
4515 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4517 case TPACPI_VIDEO_770
:
4518 autosw
= video_autosw_get();
4522 res
= video_autosw_set(1);
4525 res
= acpi_evalf(vid_handle
, NULL
,
4526 "ASWT", "vdd", status
* 0x100, 0);
4527 if (!autosw
&& video_autosw_set(autosw
)) {
4529 "video auto-switch left enabled due to error\n");
4533 case TPACPI_VIDEO_NEW
:
4534 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4535 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4541 return (res
)? 0 : -EIO
;
4544 static int video_autosw_get(void)
4548 switch (video_supported
) {
4549 case TPACPI_VIDEO_570
:
4550 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4553 case TPACPI_VIDEO_770
:
4554 case TPACPI_VIDEO_NEW
:
4555 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4565 static int video_autosw_set(int enable
)
4567 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4572 static int video_outputsw_cycle(void)
4574 int autosw
= video_autosw_get();
4580 switch (video_supported
) {
4581 case TPACPI_VIDEO_570
:
4582 res
= video_autosw_set(1);
4585 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4587 case TPACPI_VIDEO_770
:
4588 case TPACPI_VIDEO_NEW
:
4589 res
= video_autosw_set(1);
4592 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4597 if (!autosw
&& video_autosw_set(autosw
)) {
4599 "video auto-switch left enabled due to error\n");
4603 return (res
)? 0 : -EIO
;
4606 static int video_expand_toggle(void)
4608 switch (video_supported
) {
4609 case TPACPI_VIDEO_570
:
4610 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4612 case TPACPI_VIDEO_770
:
4613 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4615 case TPACPI_VIDEO_NEW
:
4616 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4624 static int video_read(struct seq_file
*m
)
4628 if (video_supported
== TPACPI_VIDEO_NONE
) {
4629 seq_printf(m
, "status:\t\tnot supported\n");
4633 /* Even reads can crash X.org, so... */
4634 if (!capable(CAP_SYS_ADMIN
))
4637 status
= video_outputsw_get();
4641 autosw
= video_autosw_get();
4645 seq_printf(m
, "status:\t\tsupported\n");
4646 seq_printf(m
, "lcd:\t\t%s\n", enabled(status
, 0));
4647 seq_printf(m
, "crt:\t\t%s\n", enabled(status
, 1));
4648 if (video_supported
== TPACPI_VIDEO_NEW
)
4649 seq_printf(m
, "dvi:\t\t%s\n", enabled(status
, 3));
4650 seq_printf(m
, "auto:\t\t%s\n", enabled(autosw
, 0));
4651 seq_printf(m
, "commands:\tlcd_enable, lcd_disable\n");
4652 seq_printf(m
, "commands:\tcrt_enable, crt_disable\n");
4653 if (video_supported
== TPACPI_VIDEO_NEW
)
4654 seq_printf(m
, "commands:\tdvi_enable, dvi_disable\n");
4655 seq_printf(m
, "commands:\tauto_enable, auto_disable\n");
4656 seq_printf(m
, "commands:\tvideo_switch, expand_toggle\n");
4661 static int video_write(char *buf
)
4664 int enable
, disable
, status
;
4667 if (video_supported
== TPACPI_VIDEO_NONE
)
4670 /* Even reads can crash X.org, let alone writes... */
4671 if (!capable(CAP_SYS_ADMIN
))
4677 while ((cmd
= next_cmd(&buf
))) {
4678 if (strlencmp(cmd
, "lcd_enable") == 0) {
4679 enable
|= TP_ACPI_VIDEO_S_LCD
;
4680 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4681 disable
|= TP_ACPI_VIDEO_S_LCD
;
4682 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4683 enable
|= TP_ACPI_VIDEO_S_CRT
;
4684 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4685 disable
|= TP_ACPI_VIDEO_S_CRT
;
4686 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4687 strlencmp(cmd
, "dvi_enable") == 0) {
4688 enable
|= TP_ACPI_VIDEO_S_DVI
;
4689 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4690 strlencmp(cmd
, "dvi_disable") == 0) {
4691 disable
|= TP_ACPI_VIDEO_S_DVI
;
4692 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4693 res
= video_autosw_set(1);
4696 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4697 res
= video_autosw_set(0);
4700 } else if (strlencmp(cmd
, "video_switch") == 0) {
4701 res
= video_outputsw_cycle();
4704 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4705 res
= video_expand_toggle();
4712 if (enable
|| disable
) {
4713 status
= video_outputsw_get();
4716 res
= video_outputsw_set((status
& ~disable
) | enable
);
4724 static struct ibm_struct video_driver_data
= {
4727 .write
= video_write
,
4731 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4733 /*************************************************************************
4734 * Light (thinklight) subdriver
4737 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4738 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4740 static int light_get_status(void)
4744 if (tp_features
.light_status
) {
4745 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4753 static int light_set_status(int status
)
4757 if (tp_features
.light
) {
4759 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4761 TP_CMOS_THINKLIGHT_ON
:
4762 TP_CMOS_THINKLIGHT_OFF
);
4764 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4767 return (rc
)? 0 : -EIO
;
4773 static void light_set_status_worker(struct work_struct
*work
)
4775 struct tpacpi_led_classdev
*data
=
4776 container_of(work
, struct tpacpi_led_classdev
, work
);
4778 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4779 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4782 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4783 enum led_brightness brightness
)
4785 struct tpacpi_led_classdev
*data
=
4786 container_of(led_cdev
,
4787 struct tpacpi_led_classdev
,
4789 data
->new_state
= (brightness
!= LED_OFF
) ?
4790 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4791 queue_work(tpacpi_wq
, &data
->work
);
4794 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4796 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4799 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4801 .name
= "tpacpi::thinklight",
4802 .brightness_set
= &light_sysfs_set
,
4803 .brightness_get
= &light_sysfs_get
,
4807 static int __init
light_init(struct ibm_init_struct
*iibm
)
4811 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4813 TPACPI_ACPIHANDLE_INIT(ledb
);
4814 TPACPI_ACPIHANDLE_INIT(lght
);
4815 TPACPI_ACPIHANDLE_INIT(cmos
);
4816 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4818 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4819 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4821 if (tp_features
.light
)
4822 /* light status not supported on
4823 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4824 tp_features
.light_status
=
4825 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4827 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4828 str_supported(tp_features
.light
),
4829 str_supported(tp_features
.light_status
));
4831 if (!tp_features
.light
)
4834 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4835 &tpacpi_led_thinklight
.led_classdev
);
4838 tp_features
.light
= 0;
4839 tp_features
.light_status
= 0;
4847 static void light_exit(void)
4849 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4850 if (work_pending(&tpacpi_led_thinklight
.work
))
4851 flush_workqueue(tpacpi_wq
);
4854 static int light_read(struct seq_file
*m
)
4858 if (!tp_features
.light
) {
4859 seq_printf(m
, "status:\t\tnot supported\n");
4860 } else if (!tp_features
.light_status
) {
4861 seq_printf(m
, "status:\t\tunknown\n");
4862 seq_printf(m
, "commands:\ton, off\n");
4864 status
= light_get_status();
4867 seq_printf(m
, "status:\t\t%s\n", onoff(status
, 0));
4868 seq_printf(m
, "commands:\ton, off\n");
4874 static int light_write(char *buf
)
4879 if (!tp_features
.light
)
4882 while ((cmd
= next_cmd(&buf
))) {
4883 if (strlencmp(cmd
, "on") == 0) {
4885 } else if (strlencmp(cmd
, "off") == 0) {
4891 return light_set_status(newstatus
);
4894 static struct ibm_struct light_driver_data
= {
4897 .write
= light_write
,
4901 /*************************************************************************
4905 /* sysfs cmos_command -------------------------------------------------- */
4906 static ssize_t
cmos_command_store(struct device
*dev
,
4907 struct device_attribute
*attr
,
4908 const char *buf
, size_t count
)
4910 unsigned long cmos_cmd
;
4913 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4916 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4917 return (res
)? res
: count
;
4920 static struct device_attribute dev_attr_cmos_command
=
4921 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4923 /* --------------------------------------------------------------------- */
4925 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4929 vdbg_printk(TPACPI_DBG_INIT
,
4930 "initializing cmos commands subdriver\n");
4932 TPACPI_ACPIHANDLE_INIT(cmos
);
4934 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4935 str_supported(cmos_handle
!= NULL
));
4937 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4941 return (cmos_handle
)? 0 : 1;
4944 static void cmos_exit(void)
4946 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4949 static int cmos_read(struct seq_file
*m
)
4951 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4952 R30, R31, T20-22, X20-21 */
4954 seq_printf(m
, "status:\t\tnot supported\n");
4956 seq_printf(m
, "status:\t\tsupported\n");
4957 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4963 static int cmos_write(char *buf
)
4968 while ((cmd
= next_cmd(&buf
))) {
4969 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4970 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4975 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4983 static struct ibm_struct cmos_driver_data
= {
4986 .write
= cmos_write
,
4990 /*************************************************************************
4994 enum led_access_mode
{
4995 TPACPI_LED_NONE
= 0,
4996 TPACPI_LED_570
, /* 570 */
4997 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4998 TPACPI_LED_NEW
, /* all others */
5001 enum { /* For TPACPI_LED_OLD */
5002 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
5003 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
5004 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
5007 static enum led_access_mode led_supported
;
5009 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
5010 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
5011 /* T20-22, X20-21 */
5012 "LED", /* all others */
5015 #define TPACPI_LED_NUMLEDS 16
5016 static struct tpacpi_led_classdev
*tpacpi_leds
;
5017 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
5018 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
5019 /* there's a limit of 19 chars + NULL before 2.6.26 */
5021 "tpacpi:orange:batt",
5022 "tpacpi:green:batt",
5023 "tpacpi::dock_active",
5024 "tpacpi::bay_active",
5025 "tpacpi::dock_batt",
5026 "tpacpi::unknown_led",
5028 "tpacpi::dock_status1",
5029 "tpacpi::dock_status2",
5030 "tpacpi::unknown_led2",
5031 "tpacpi::unknown_led3",
5032 "tpacpi::thinkvantage",
5034 #define TPACPI_SAFE_LEDS 0x1081U
5036 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
5038 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5041 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
5045 static int led_get_status(const unsigned int led
)
5048 enum led_status_t led_s
;
5050 switch (led_supported
) {
5051 case TPACPI_LED_570
:
5052 if (!acpi_evalf(ec_handle
,
5053 &status
, "GLED", "dd", 1 << led
))
5055 led_s
= (status
== 0)?
5060 tpacpi_led_state_cache
[led
] = led_s
;
5069 static int led_set_status(const unsigned int led
,
5070 const enum led_status_t ledstatus
)
5072 /* off, on, blink. Index is led_status_t */
5073 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
5074 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
5078 switch (led_supported
) {
5079 case TPACPI_LED_570
:
5081 if (unlikely(led
> 7))
5083 if (unlikely(tpacpi_is_led_restricted(led
)))
5085 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5086 (1 << led
), led_sled_arg1
[ledstatus
]))
5089 case TPACPI_LED_OLD
:
5090 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
5091 if (unlikely(led
> 7))
5093 if (unlikely(tpacpi_is_led_restricted(led
)))
5095 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
5097 rc
= ec_write(TPACPI_LED_EC_HLBL
,
5098 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5100 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5101 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5103 case TPACPI_LED_NEW
:
5105 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5107 if (unlikely(tpacpi_is_led_restricted(led
)))
5109 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5110 led
, led_led_arg1
[ledstatus
]))
5118 tpacpi_led_state_cache
[led
] = ledstatus
;
5123 static void led_set_status_worker(struct work_struct
*work
)
5125 struct tpacpi_led_classdev
*data
=
5126 container_of(work
, struct tpacpi_led_classdev
, work
);
5128 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5129 led_set_status(data
->led
, data
->new_state
);
5132 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5133 enum led_brightness brightness
)
5135 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5136 struct tpacpi_led_classdev
, led_classdev
);
5138 if (brightness
== LED_OFF
)
5139 data
->new_state
= TPACPI_LED_OFF
;
5140 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5141 data
->new_state
= TPACPI_LED_ON
;
5143 data
->new_state
= TPACPI_LED_BLINK
;
5145 queue_work(tpacpi_wq
, &data
->work
);
5148 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5149 unsigned long *delay_on
, unsigned long *delay_off
)
5151 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5152 struct tpacpi_led_classdev
, led_classdev
);
5154 /* Can we choose the flash rate? */
5155 if (*delay_on
== 0 && *delay_off
== 0) {
5156 /* yes. set them to the hardware blink rate (1 Hz) */
5157 *delay_on
= 500; /* ms */
5158 *delay_off
= 500; /* ms */
5159 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5162 data
->new_state
= TPACPI_LED_BLINK
;
5163 queue_work(tpacpi_wq
, &data
->work
);
5168 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5172 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5173 struct tpacpi_led_classdev
, led_classdev
);
5175 rc
= led_get_status(data
->led
);
5177 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5178 rc
= LED_OFF
; /* no error handling in led class :( */
5185 static void led_exit(void)
5189 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5190 if (tpacpi_leds
[i
].led_classdev
.name
)
5191 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5197 static int __init
tpacpi_init_led(unsigned int led
)
5201 tpacpi_leds
[led
].led
= led
;
5203 /* LEDs with no name don't get registered */
5204 if (!tpacpi_led_names
[led
])
5207 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5208 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5209 if (led_supported
== TPACPI_LED_570
)
5210 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5213 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5215 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5217 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5218 &tpacpi_leds
[led
].led_classdev
);
5220 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5225 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5226 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5227 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5228 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5230 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5231 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5232 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5233 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5234 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5235 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5236 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5237 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5239 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5240 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5241 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5242 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5243 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5245 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5246 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5247 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5248 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5250 /* (1) - may have excess leds enabled on MSB */
5252 /* Defaults (order matters, keep last, don't reorder!) */
5254 .vendor
= PCI_VENDOR_ID_LENOVO
,
5255 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5258 { /* IBM ThinkPads with no EC version string */
5259 .vendor
= PCI_VENDOR_ID_IBM
,
5260 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5263 { /* IBM ThinkPads with EC version string */
5264 .vendor
= PCI_VENDOR_ID_IBM
,
5265 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5270 #undef TPACPI_LEDQ_IBM
5271 #undef TPACPI_LEDQ_LNV
5273 static int __init
led_init(struct ibm_init_struct
*iibm
)
5277 unsigned long useful_leds
;
5279 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5281 TPACPI_ACPIHANDLE_INIT(led
);
5284 /* led not supported on R30, R31 */
5285 led_supported
= TPACPI_LED_NONE
;
5286 else if (strlencmp(led_path
, "SLED") == 0)
5288 led_supported
= TPACPI_LED_570
;
5289 else if (strlencmp(led_path
, "SYSL") == 0)
5290 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5291 led_supported
= TPACPI_LED_OLD
;
5294 led_supported
= TPACPI_LED_NEW
;
5296 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5297 str_supported(led_supported
), led_supported
);
5299 if (led_supported
== TPACPI_LED_NONE
)
5302 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5305 printk(TPACPI_ERR
"Out of memory for LED data\n");
5309 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5310 ARRAY_SIZE(led_useful_qtable
));
5312 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5313 if (!tpacpi_is_led_restricted(i
) &&
5314 test_bit(i
, &useful_leds
)) {
5315 rc
= tpacpi_init_led(i
);
5323 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5324 printk(TPACPI_NOTICE
5325 "warning: userspace override of important "
5326 "firmware LEDs is enabled\n");
5331 #define str_led_status(s) \
5332 ((s) == TPACPI_LED_OFF ? "off" : \
5333 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5335 static int led_read(struct seq_file
*m
)
5337 if (!led_supported
) {
5338 seq_printf(m
, "status:\t\tnot supported\n");
5341 seq_printf(m
, "status:\t\tsupported\n");
5343 if (led_supported
== TPACPI_LED_570
) {
5346 for (i
= 0; i
< 8; i
++) {
5347 status
= led_get_status(i
);
5350 seq_printf(m
, "%d:\t\t%s\n",
5351 i
, str_led_status(status
));
5355 seq_printf(m
, "commands:\t"
5356 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5361 static int led_write(char *buf
)
5365 enum led_status_t s
;
5370 while ((cmd
= next_cmd(&buf
))) {
5371 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5374 if (strstr(cmd
, "off")) {
5376 } else if (strstr(cmd
, "on")) {
5378 } else if (strstr(cmd
, "blink")) {
5379 s
= TPACPI_LED_BLINK
;
5384 rc
= led_set_status(led
, s
);
5392 static struct ibm_struct led_driver_data
= {
5399 /*************************************************************************
5403 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5405 #define TPACPI_BEEP_Q1 0x0001
5407 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5408 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5409 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5412 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5414 unsigned long quirks
;
5416 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5418 TPACPI_ACPIHANDLE_INIT(beep
);
5420 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5421 str_supported(beep_handle
!= NULL
));
5423 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5424 ARRAY_SIZE(beep_quirk_table
));
5426 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5428 return (beep_handle
)? 0 : 1;
5431 static int beep_read(struct seq_file
*m
)
5434 seq_printf(m
, "status:\t\tnot supported\n");
5436 seq_printf(m
, "status:\t\tsupported\n");
5437 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5443 static int beep_write(char *buf
)
5451 while ((cmd
= next_cmd(&buf
))) {
5452 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5453 beep_cmd
>= 0 && beep_cmd
<= 17) {
5457 if (tp_features
.beep_needs_two_args
) {
5458 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5462 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5471 static struct ibm_struct beep_driver_data
= {
5474 .write
= beep_write
,
5477 /*************************************************************************
5481 enum thermal_access_mode
{
5482 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5483 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5484 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5485 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5486 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5489 enum { /* TPACPI_THERMAL_TPEC_* */
5490 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5491 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5492 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5494 TPACPI_THERMAL_SENSOR_NA
= -128000, /* Sensor not available */
5498 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5499 struct ibm_thermal_sensors_struct
{
5500 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5503 static enum thermal_access_mode thermal_read_mode
;
5505 /* idx is zero-based */
5506 static int thermal_get_sensor(int idx
, s32
*value
)
5512 t
= TP_EC_THERMAL_TMP0
;
5514 switch (thermal_read_mode
) {
5515 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5516 case TPACPI_THERMAL_TPEC_16
:
5517 if (idx
>= 8 && idx
<= 15) {
5518 t
= TP_EC_THERMAL_TMP8
;
5523 case TPACPI_THERMAL_TPEC_8
:
5525 if (!acpi_ec_read(t
+ idx
, &tmp
))
5527 *value
= tmp
* 1000;
5532 case TPACPI_THERMAL_ACPI_UPDT
:
5534 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5535 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5537 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5539 *value
= (t
- 2732) * 100;
5544 case TPACPI_THERMAL_ACPI_TMP07
:
5546 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5547 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5549 if (t
> 127 || t
< -127)
5550 t
= TP_EC_THERMAL_TMP_NA
;
5556 case TPACPI_THERMAL_NONE
:
5564 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5575 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5578 for (i
= 0 ; i
< n
; i
++) {
5579 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5587 static void thermal_dump_all_sensors(void)
5590 struct ibm_thermal_sensors_struct t
;
5592 n
= thermal_get_sensors(&t
);
5596 printk(TPACPI_NOTICE
5597 "temperatures (Celsius):");
5599 for (i
= 0; i
< n
; i
++) {
5600 if (t
.temp
[i
] != TPACPI_THERMAL_SENSOR_NA
)
5601 printk(KERN_CONT
" %d", (int)(t
.temp
[i
] / 1000));
5603 printk(KERN_CONT
" N/A");
5606 printk(KERN_CONT
"\n");
5609 /* sysfs temp##_input -------------------------------------------------- */
5611 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5612 struct device_attribute
*attr
,
5615 struct sensor_device_attribute
*sensor_attr
=
5616 to_sensor_dev_attr(attr
);
5617 int idx
= sensor_attr
->index
;
5621 res
= thermal_get_sensor(idx
, &value
);
5624 if (value
== TPACPI_THERMAL_SENSOR_NA
)
5627 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5630 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5631 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5632 thermal_temp_input_show, NULL, _idxB)
5634 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5635 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5636 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5637 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5638 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5639 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5640 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5641 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5642 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5643 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5644 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5645 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5646 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5647 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5648 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5649 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5650 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5653 #define THERMAL_ATTRS(X) \
5654 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5656 static struct attribute
*thermal_temp_input_attr
[] = {
5676 static const struct attribute_group thermal_temp_input16_group
= {
5677 .attrs
= thermal_temp_input_attr
5680 static const struct attribute_group thermal_temp_input8_group
= {
5681 .attrs
= &thermal_temp_input_attr
[8]
5684 #undef THERMAL_SENSOR_ATTR_TEMP
5685 #undef THERMAL_ATTRS
5687 /* --------------------------------------------------------------------- */
5689 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5696 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5698 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5700 if (thinkpad_id
.ec_model
) {
5702 * Direct EC access mode: sensors at registers
5703 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5704 * non-implemented, thermal sensors return 0x80 when
5709 for (i
= 0; i
< 8; i
++) {
5710 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5716 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5724 /* This is sheer paranoia, but we handle it anyway */
5727 "ThinkPad ACPI EC access misbehaving, "
5728 "falling back to ACPI TMPx access "
5730 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5733 "ThinkPad ACPI EC access misbehaving, "
5734 "disabling thermal sensors access\n");
5735 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5740 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5742 } else if (acpi_tmp7
) {
5743 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5744 /* 600e/x, 770e, 770x */
5745 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5747 /* Standard ACPI TMPx access, max 8 sensors */
5748 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5751 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5752 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5755 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5756 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5759 switch (thermal_read_mode
) {
5760 case TPACPI_THERMAL_TPEC_16
:
5761 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5762 &thermal_temp_input16_group
);
5766 case TPACPI_THERMAL_TPEC_8
:
5767 case TPACPI_THERMAL_ACPI_TMP07
:
5768 case TPACPI_THERMAL_ACPI_UPDT
:
5769 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5770 &thermal_temp_input8_group
);
5774 case TPACPI_THERMAL_NONE
:
5782 static void thermal_exit(void)
5784 switch (thermal_read_mode
) {
5785 case TPACPI_THERMAL_TPEC_16
:
5786 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5787 &thermal_temp_input16_group
);
5789 case TPACPI_THERMAL_TPEC_8
:
5790 case TPACPI_THERMAL_ACPI_TMP07
:
5791 case TPACPI_THERMAL_ACPI_UPDT
:
5792 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5793 &thermal_temp_input8_group
);
5795 case TPACPI_THERMAL_NONE
:
5801 static int thermal_read(struct seq_file
*m
)
5804 struct ibm_thermal_sensors_struct t
;
5806 n
= thermal_get_sensors(&t
);
5807 if (unlikely(n
< 0))
5810 seq_printf(m
, "temperatures:\t");
5813 for (i
= 0; i
< (n
- 1); i
++)
5814 seq_printf(m
, "%d ", t
.temp
[i
] / 1000);
5815 seq_printf(m
, "%d\n", t
.temp
[i
] / 1000);
5817 seq_printf(m
, "not supported\n");
5822 static struct ibm_struct thermal_driver_data
= {
5824 .read
= thermal_read
,
5825 .exit
= thermal_exit
,
5828 /*************************************************************************
5832 static u8 ecdump_regs
[256];
5834 static int ecdump_read(struct seq_file
*m
)
5840 " +00 +01 +02 +03 +04 +05 +06 +07"
5841 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5842 for (i
= 0; i
< 256; i
+= 16) {
5843 seq_printf(m
, "EC 0x%02x:", i
);
5844 for (j
= 0; j
< 16; j
++) {
5845 if (!acpi_ec_read(i
+ j
, &v
))
5847 if (v
!= ecdump_regs
[i
+ j
])
5848 seq_printf(m
, " *%02x", v
);
5850 seq_printf(m
, " %02x", v
);
5851 ecdump_regs
[i
+ j
] = v
;
5858 /* These are way too dangerous to advertise openly... */
5860 seq_printf(m
, "commands:\t0x<offset> 0x<value>"
5861 " (<offset> is 00-ff, <value> is 00-ff)\n");
5862 seq_printf(m
, "commands:\t0x<offset> <value> "
5863 " (<offset> is 00-ff, <value> is 0-255)\n");
5868 static int ecdump_write(char *buf
)
5873 while ((cmd
= next_cmd(&buf
))) {
5874 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5876 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5880 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5881 if (!acpi_ec_write(i
, v
))
5890 static struct ibm_struct ecdump_driver_data
= {
5892 .read
= ecdump_read
,
5893 .write
= ecdump_write
,
5894 .flags
.experimental
= 1,
5897 /*************************************************************************
5898 * Backlight/brightness subdriver
5901 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5904 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5905 * CMOS NVRAM byte 0x5E, bits 0-3.
5907 * EC HBRV (0x31) has the following layout
5908 * Bit 7: unknown function
5909 * Bit 6: unknown function
5910 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5911 * Bit 4: must be set to zero to avoid problems
5912 * Bit 3-0: backlight brightness level
5914 * brightness_get_raw returns status data in the HBRV layout
5916 * WARNING: The X61 has been verified to use HBRV for something else, so
5917 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5918 * testing on the very early *60 Lenovo models...
5922 TP_EC_BACKLIGHT
= 0x31,
5924 /* TP_EC_BACKLIGHT bitmasks */
5925 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5926 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5927 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5930 enum tpacpi_brightness_access_mode
{
5931 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5932 TPACPI_BRGHT_MODE_EC
, /* EC control */
5933 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5934 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5935 TPACPI_BRGHT_MODE_MAX
5938 static struct backlight_device
*ibm_backlight_device
;
5940 static enum tpacpi_brightness_access_mode brightness_mode
=
5941 TPACPI_BRGHT_MODE_MAX
;
5943 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5945 static struct mutex brightness_mutex
;
5947 /* NVRAM brightness access,
5948 * call with brightness_mutex held! */
5949 static unsigned int tpacpi_brightness_nvram_get(void)
5953 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5954 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5955 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5956 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5961 static void tpacpi_brightness_checkpoint_nvram(void)
5966 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5969 vdbg_printk(TPACPI_DBG_BRGHT
,
5970 "trying to checkpoint backlight level to NVRAM...\n");
5972 if (mutex_lock_killable(&brightness_mutex
) < 0)
5975 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5977 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5978 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5980 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5981 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5982 /* NVRAM needs update */
5983 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5984 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5986 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5987 dbg_printk(TPACPI_DBG_BRGHT
,
5988 "updated NVRAM backlight level to %u (0x%02x)\n",
5989 (unsigned int) lec
, (unsigned int) b_nvram
);
5991 vdbg_printk(TPACPI_DBG_BRGHT
,
5992 "NVRAM backlight level already is %u (0x%02x)\n",
5993 (unsigned int) lec
, (unsigned int) b_nvram
);
5996 mutex_unlock(&brightness_mutex
);
6000 /* call with brightness_mutex held! */
6001 static int tpacpi_brightness_get_raw(int *status
)
6005 switch (brightness_mode
) {
6006 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6007 *status
= tpacpi_brightness_nvram_get();
6009 case TPACPI_BRGHT_MODE_EC
:
6010 case TPACPI_BRGHT_MODE_ECNVRAM
:
6011 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6020 /* call with brightness_mutex held! */
6021 /* do NOT call with illegal backlight level value */
6022 static int tpacpi_brightness_set_ec(unsigned int value
)
6026 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6029 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
6030 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
6031 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
6037 /* call with brightness_mutex held! */
6038 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
6041 unsigned int current_value
, i
;
6043 current_value
= tpacpi_brightness_nvram_get();
6045 if (value
== current_value
)
6048 cmos_cmd
= (value
> current_value
) ?
6049 TP_CMOS_BRIGHTNESS_UP
:
6050 TP_CMOS_BRIGHTNESS_DOWN
;
6051 inc
= (value
> current_value
) ? 1 : -1;
6053 for (i
= current_value
; i
!= value
; i
+= inc
)
6054 if (issue_thinkpad_cmos_command(cmos_cmd
))
6060 /* May return EINTR which can always be mapped to ERESTARTSYS */
6061 static int brightness_set(unsigned int value
)
6065 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
6069 vdbg_printk(TPACPI_DBG_BRGHT
,
6070 "set backlight level to %d\n", value
);
6072 res
= mutex_lock_killable(&brightness_mutex
);
6076 switch (brightness_mode
) {
6077 case TPACPI_BRGHT_MODE_EC
:
6078 case TPACPI_BRGHT_MODE_ECNVRAM
:
6079 res
= tpacpi_brightness_set_ec(value
);
6081 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6082 res
= tpacpi_brightness_set_ucmsstep(value
);
6088 mutex_unlock(&brightness_mutex
);
6092 /* sysfs backlight class ----------------------------------------------- */
6094 static int brightness_update_status(struct backlight_device
*bd
)
6096 unsigned int level
=
6097 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
6098 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
6099 bd
->props
.brightness
: 0;
6101 dbg_printk(TPACPI_DBG_BRGHT
,
6102 "backlight: attempt to set level to %d\n",
6105 /* it is the backlight class's job (caller) to handle
6106 * EINTR and other errors properly */
6107 return brightness_set(level
);
6110 static int brightness_get(struct backlight_device
*bd
)
6114 res
= mutex_lock_killable(&brightness_mutex
);
6118 res
= tpacpi_brightness_get_raw(&status
);
6120 mutex_unlock(&brightness_mutex
);
6125 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6128 static void tpacpi_brightness_notify_change(void)
6130 backlight_force_update(ibm_backlight_device
,
6131 BACKLIGHT_UPDATE_HOTKEY
);
6134 static struct backlight_ops ibm_backlight_data
= {
6135 .get_brightness
= brightness_get
,
6136 .update_status
= brightness_update_status
,
6139 /* --------------------------------------------------------------------- */
6142 * These are only useful for models that have only one possibility
6143 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6146 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6147 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6148 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6150 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6151 /* Models with ATI GPUs known to require ECNVRAM mode */
6152 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6154 /* Models with ATI GPUs that can use ECNVRAM */
6155 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
), /* R50,51 T40-42 */
6156 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6157 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC
), /* R52 */
6158 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6160 /* Models with Intel Extreme Graphics 2 */
6161 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
), /* X40 */
6162 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6163 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6165 /* Models with Intel GMA900 */
6166 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6167 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6168 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6171 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6174 unsigned long quirks
;
6176 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6178 mutex_init(&brightness_mutex
);
6180 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6181 ARRAY_SIZE(brightness_quirk_table
));
6184 * We always attempt to detect acpi support, so as to switch
6185 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6186 * going to publish a backlight interface
6188 b
= tpacpi_check_std_acpi_brightness_support();
6191 if (acpi_video_backlight_support()) {
6192 if (brightness_enable
> 1) {
6193 printk(TPACPI_NOTICE
6194 "Standard ACPI backlight interface "
6195 "available, not loading native one.\n");
6197 } else if (brightness_enable
== 1) {
6198 printk(TPACPI_NOTICE
6199 "Backlight control force enabled, even if standard "
6200 "ACPI backlight interface is available\n");
6203 if (brightness_enable
> 1) {
6204 printk(TPACPI_NOTICE
6205 "Standard ACPI backlight interface not "
6206 "available, thinkpad_acpi native "
6207 "brightness control enabled\n");
6212 if (!brightness_enable
) {
6213 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6214 "brightness support disabled by "
6215 "module parameter\n");
6221 "Unsupported brightness interface, "
6222 "please contact %s\n", TPACPI_MAIL
);
6226 tp_features
.bright_16levels
= 1;
6229 * Check for module parameter bogosity, note that we
6230 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6231 * able to detect "unspecified"
6233 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6236 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6237 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6238 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6239 if (quirks
& TPACPI_BRGHT_Q_EC
)
6240 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6242 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6244 dbg_printk(TPACPI_DBG_BRGHT
,
6245 "driver auto-selected brightness_mode=%d\n",
6250 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6251 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6252 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6255 if (tpacpi_brightness_get_raw(&b
) < 0)
6258 if (tp_features
.bright_16levels
)
6260 "detected a 16-level brightness capable ThinkPad\n");
6262 ibm_backlight_device
= backlight_device_register(
6263 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6264 &ibm_backlight_data
);
6265 if (IS_ERR(ibm_backlight_device
)) {
6266 int rc
= PTR_ERR(ibm_backlight_device
);
6267 ibm_backlight_device
= NULL
;
6268 printk(TPACPI_ERR
"Could not register backlight device\n");
6271 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6272 "brightness is supported\n");
6274 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6275 printk(TPACPI_NOTICE
6276 "brightness: will use unverified default: "
6277 "brightness_mode=%d\n", brightness_mode
);
6278 printk(TPACPI_NOTICE
6279 "brightness: please report to %s whether it works well "
6280 "or not on your ThinkPad\n", TPACPI_MAIL
);
6283 ibm_backlight_device
->props
.max_brightness
=
6284 (tp_features
.bright_16levels
)? 15 : 7;
6285 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6286 backlight_update_status(ibm_backlight_device
);
6288 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6289 "brightness: registering brightness hotkeys "
6290 "as change notification\n");
6291 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6292 | TP_ACPI_HKEY_BRGHTUP_MASK
6293 | TP_ACPI_HKEY_BRGHTDWN_MASK
);;
6297 static void brightness_suspend(pm_message_t state
)
6299 tpacpi_brightness_checkpoint_nvram();
6302 static void brightness_shutdown(void)
6304 tpacpi_brightness_checkpoint_nvram();
6307 static void brightness_exit(void)
6309 if (ibm_backlight_device
) {
6310 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6311 "calling backlight_device_unregister()\n");
6312 backlight_device_unregister(ibm_backlight_device
);
6315 tpacpi_brightness_checkpoint_nvram();
6318 static int brightness_read(struct seq_file
*m
)
6322 level
= brightness_get(NULL
);
6324 seq_printf(m
, "level:\t\tunreadable\n");
6326 seq_printf(m
, "level:\t\t%d\n", level
);
6327 seq_printf(m
, "commands:\tup, down\n");
6328 seq_printf(m
, "commands:\tlevel <level>"
6329 " (<level> is 0-%d)\n",
6330 (tp_features
.bright_16levels
) ? 15 : 7);
6336 static int brightness_write(char *buf
)
6341 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6343 level
= brightness_get(NULL
);
6347 while ((cmd
= next_cmd(&buf
))) {
6348 if (strlencmp(cmd
, "up") == 0) {
6349 if (level
< max_level
)
6351 } else if (strlencmp(cmd
, "down") == 0) {
6354 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6355 level
>= 0 && level
<= max_level
) {
6361 tpacpi_disclose_usertask("procfs brightness",
6362 "set level to %d\n", level
);
6365 * Now we know what the final level should be, so we try to set it.
6366 * Doing it this way makes the syscall restartable in case of EINTR
6368 rc
= brightness_set(level
);
6369 if (!rc
&& ibm_backlight_device
)
6370 backlight_force_update(ibm_backlight_device
,
6371 BACKLIGHT_UPDATE_SYSFS
);
6372 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6375 static struct ibm_struct brightness_driver_data
= {
6376 .name
= "brightness",
6377 .read
= brightness_read
,
6378 .write
= brightness_write
,
6379 .exit
= brightness_exit
,
6380 .suspend
= brightness_suspend
,
6381 .shutdown
= brightness_shutdown
,
6384 /*************************************************************************
6389 * IBM ThinkPads have a simple volume controller with MUTE gating.
6390 * Very early Lenovo ThinkPads follow the IBM ThinkPad spec.
6392 * Since the *61 series (and probably also the later *60 series), Lenovo
6393 * ThinkPads only implement the MUTE gate.
6396 * Bit 6: MUTE (1 mutes sound)
6398 * Other bits should be zero as far as we know.
6400 * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and
6401 * bits 3-0 (volume). Other bits in NVRAM may have other functions,
6402 * such as bit 7 which is used to detect repeated presses of MUTE,
6403 * and we leave them unchanged.
6406 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
6408 #define TPACPI_ALSA_DRVNAME "ThinkPad EC"
6409 #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control"
6410 #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME
6412 static int alsa_index
= ~((1 << (SNDRV_CARDS
- 3)) - 1); /* last three slots */
6413 static char *alsa_id
= "ThinkPadEC";
6414 static int alsa_enable
= SNDRV_DEFAULT_ENABLE1
;
6416 struct tpacpi_alsa_data
{
6417 struct snd_card
*card
;
6418 struct snd_ctl_elem_id
*ctl_mute_id
;
6419 struct snd_ctl_elem_id
*ctl_vol_id
;
6422 static struct snd_card
*alsa_card
;
6427 /* TP_EC_AUDIO bits */
6428 TP_EC_AUDIO_MUTESW
= 6,
6430 /* TP_EC_AUDIO bitmasks */
6431 TP_EC_AUDIO_LVL_MSK
= 0x0F,
6432 TP_EC_AUDIO_MUTESW_MSK
= (1 << TP_EC_AUDIO_MUTESW
),
6434 /* Maximum volume */
6435 TP_EC_VOLUME_MAX
= 14,
6438 enum tpacpi_volume_access_mode
{
6439 TPACPI_VOL_MODE_AUTO
= 0, /* Not implemented yet */
6440 TPACPI_VOL_MODE_EC
, /* Pure EC control */
6441 TPACPI_VOL_MODE_UCMS_STEP
, /* UCMS step-based control: N/A */
6442 TPACPI_VOL_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
6446 enum tpacpi_volume_capabilities
{
6447 TPACPI_VOL_CAP_AUTO
= 0, /* Use white/blacklist */
6448 TPACPI_VOL_CAP_VOLMUTE
, /* Output vol and mute */
6449 TPACPI_VOL_CAP_MUTEONLY
, /* Output mute only */
6453 static enum tpacpi_volume_access_mode volume_mode
=
6454 TPACPI_VOL_MODE_MAX
;
6456 static enum tpacpi_volume_capabilities volume_capabilities
;
6457 static int volume_control_allowed
;
6460 * Used to syncronize writers to TP_EC_AUDIO and
6461 * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write
6463 static struct mutex volume_mutex
;
6465 static void tpacpi_volume_checkpoint_nvram(void)
6471 if (volume_mode
!= TPACPI_VOL_MODE_ECNVRAM
)
6473 if (!volume_control_allowed
)
6476 vdbg_printk(TPACPI_DBG_MIXER
,
6477 "trying to checkpoint mixer state to NVRAM...\n");
6479 if (tp_features
.mixer_no_level_control
)
6480 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
;
6482 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
| TP_EC_AUDIO_LVL_MSK
;
6484 if (mutex_lock_killable(&volume_mutex
) < 0)
6487 if (unlikely(!acpi_ec_read(TP_EC_AUDIO
, &lec
)))
6490 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
6492 if (lec
!= (b_nvram
& ec_mask
)) {
6493 /* NVRAM needs update */
6494 b_nvram
&= ~ec_mask
;
6496 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_MIXER
);
6497 dbg_printk(TPACPI_DBG_MIXER
,
6498 "updated NVRAM mixer status to 0x%02x (0x%02x)\n",
6499 (unsigned int) lec
, (unsigned int) b_nvram
);
6501 vdbg_printk(TPACPI_DBG_MIXER
,
6502 "NVRAM mixer status already is 0x%02x (0x%02x)\n",
6503 (unsigned int) lec
, (unsigned int) b_nvram
);
6507 mutex_unlock(&volume_mutex
);
6510 static int volume_get_status_ec(u8
*status
)
6514 if (!acpi_ec_read(TP_EC_AUDIO
, &s
))
6519 dbg_printk(TPACPI_DBG_MIXER
, "status 0x%02x\n", s
);
6524 static int volume_get_status(u8
*status
)
6526 return volume_get_status_ec(status
);
6529 static int volume_set_status_ec(const u8 status
)
6531 if (!acpi_ec_write(TP_EC_AUDIO
, status
))
6534 dbg_printk(TPACPI_DBG_MIXER
, "set EC mixer to 0x%02x\n", status
);
6539 static int volume_set_status(const u8 status
)
6541 return volume_set_status_ec(status
);
6544 /* returns < 0 on error, 0 on no change, 1 on change */
6545 static int __volume_set_mute_ec(const bool mute
)
6550 if (mutex_lock_killable(&volume_mutex
) < 0)
6553 rc
= volume_get_status_ec(&s
);
6557 n
= (mute
) ? s
| TP_EC_AUDIO_MUTESW_MSK
:
6558 s
& ~TP_EC_AUDIO_MUTESW_MSK
;
6561 rc
= volume_set_status_ec(n
);
6567 mutex_unlock(&volume_mutex
);
6571 static int volume_alsa_set_mute(const bool mute
)
6573 dbg_printk(TPACPI_DBG_MIXER
, "ALSA: trying to %smute\n",
6574 (mute
) ? "" : "un");
6575 return __volume_set_mute_ec(mute
);
6578 static int volume_set_mute(const bool mute
)
6582 dbg_printk(TPACPI_DBG_MIXER
, "trying to %smute\n",
6583 (mute
) ? "" : "un");
6585 rc
= __volume_set_mute_ec(mute
);
6586 return (rc
< 0) ? rc
: 0;
6589 /* returns < 0 on error, 0 on no change, 1 on change */
6590 static int __volume_set_volume_ec(const u8 vol
)
6595 if (vol
> TP_EC_VOLUME_MAX
)
6598 if (mutex_lock_killable(&volume_mutex
) < 0)
6601 rc
= volume_get_status_ec(&s
);
6605 n
= (s
& ~TP_EC_AUDIO_LVL_MSK
) | vol
;
6608 rc
= volume_set_status_ec(n
);
6614 mutex_unlock(&volume_mutex
);
6618 static int volume_alsa_set_volume(const u8 vol
)
6620 dbg_printk(TPACPI_DBG_MIXER
,
6621 "ALSA: trying to set volume level to %hu\n", vol
);
6622 return __volume_set_volume_ec(vol
);
6625 static void volume_alsa_notify_change(void)
6627 struct tpacpi_alsa_data
*d
;
6629 if (alsa_card
&& alsa_card
->private_data
) {
6630 d
= alsa_card
->private_data
;
6632 snd_ctl_notify(alsa_card
,
6633 SNDRV_CTL_EVENT_MASK_VALUE
,
6636 snd_ctl_notify(alsa_card
,
6637 SNDRV_CTL_EVENT_MASK_VALUE
,
6642 static int volume_alsa_vol_info(struct snd_kcontrol
*kcontrol
,
6643 struct snd_ctl_elem_info
*uinfo
)
6645 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
6647 uinfo
->value
.integer
.min
= 0;
6648 uinfo
->value
.integer
.max
= TP_EC_VOLUME_MAX
;
6652 static int volume_alsa_vol_get(struct snd_kcontrol
*kcontrol
,
6653 struct snd_ctl_elem_value
*ucontrol
)
6658 rc
= volume_get_status(&s
);
6662 ucontrol
->value
.integer
.value
[0] = s
& TP_EC_AUDIO_LVL_MSK
;
6666 static int volume_alsa_vol_put(struct snd_kcontrol
*kcontrol
,
6667 struct snd_ctl_elem_value
*ucontrol
)
6669 return volume_alsa_set_volume(ucontrol
->value
.integer
.value
[0]);
6672 #define volume_alsa_mute_info snd_ctl_boolean_mono_info
6674 static int volume_alsa_mute_get(struct snd_kcontrol
*kcontrol
,
6675 struct snd_ctl_elem_value
*ucontrol
)
6680 rc
= volume_get_status(&s
);
6684 ucontrol
->value
.integer
.value
[0] =
6685 (s
& TP_EC_AUDIO_MUTESW_MSK
) ? 0 : 1;
6689 static int volume_alsa_mute_put(struct snd_kcontrol
*kcontrol
,
6690 struct snd_ctl_elem_value
*ucontrol
)
6692 return volume_alsa_set_mute(!ucontrol
->value
.integer
.value
[0]);
6695 static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata
= {
6696 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6697 .name
= "Console Playback Volume",
6699 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6700 .info
= volume_alsa_vol_info
,
6701 .get
= volume_alsa_vol_get
,
6704 static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata
= {
6705 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6706 .name
= "Console Playback Switch",
6708 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6709 .info
= volume_alsa_mute_info
,
6710 .get
= volume_alsa_mute_get
,
6713 static void volume_suspend(pm_message_t state
)
6715 tpacpi_volume_checkpoint_nvram();
6718 static void volume_resume(void)
6720 volume_alsa_notify_change();
6723 static void volume_shutdown(void)
6725 tpacpi_volume_checkpoint_nvram();
6728 static void volume_exit(void)
6731 snd_card_free(alsa_card
);
6735 tpacpi_volume_checkpoint_nvram();
6738 static int __init
volume_create_alsa_mixer(void)
6740 struct snd_card
*card
;
6741 struct tpacpi_alsa_data
*data
;
6742 struct snd_kcontrol
*ctl_vol
;
6743 struct snd_kcontrol
*ctl_mute
;
6746 rc
= snd_card_create(alsa_index
, alsa_id
, THIS_MODULE
,
6747 sizeof(struct tpacpi_alsa_data
), &card
);
6748 if (rc
< 0 || !card
) {
6750 "Failed to create ALSA card structures: %d\n", rc
);
6754 BUG_ON(!card
->private_data
);
6755 data
= card
->private_data
;
6758 strlcpy(card
->driver
, TPACPI_ALSA_DRVNAME
,
6759 sizeof(card
->driver
));
6760 strlcpy(card
->shortname
, TPACPI_ALSA_SHRTNAME
,
6761 sizeof(card
->shortname
));
6762 snprintf(card
->mixername
, sizeof(card
->mixername
), "ThinkPad EC %s",
6763 (thinkpad_id
.ec_version_str
) ?
6764 thinkpad_id
.ec_version_str
: "(unknown)");
6765 snprintf(card
->longname
, sizeof(card
->longname
),
6766 "%s at EC reg 0x%02x, fw %s", card
->shortname
, TP_EC_AUDIO
,
6767 (thinkpad_id
.ec_version_str
) ?
6768 thinkpad_id
.ec_version_str
: "unknown");
6770 if (volume_control_allowed
) {
6771 volume_alsa_control_vol
.put
= volume_alsa_vol_put
;
6772 volume_alsa_control_vol
.access
=
6773 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6775 volume_alsa_control_mute
.put
= volume_alsa_mute_put
;
6776 volume_alsa_control_mute
.access
=
6777 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6780 if (!tp_features
.mixer_no_level_control
) {
6781 ctl_vol
= snd_ctl_new1(&volume_alsa_control_vol
, NULL
);
6782 rc
= snd_ctl_add(card
, ctl_vol
);
6785 "Failed to create ALSA volume control: %d\n",
6789 data
->ctl_vol_id
= &ctl_vol
->id
;
6792 ctl_mute
= snd_ctl_new1(&volume_alsa_control_mute
, NULL
);
6793 rc
= snd_ctl_add(card
, ctl_mute
);
6795 printk(TPACPI_ERR
"Failed to create ALSA mute control: %d\n",
6799 data
->ctl_mute_id
= &ctl_mute
->id
;
6801 snd_card_set_dev(card
, &tpacpi_pdev
->dev
);
6802 rc
= snd_card_register(card
);
6804 printk(TPACPI_ERR
"Failed to register ALSA card: %d\n", rc
);
6812 snd_card_free(card
);
6816 #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */
6817 #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */
6819 static const struct tpacpi_quirk volume_quirk_table
[] __initconst
= {
6820 /* Whitelist volume level on all IBM by default */
6821 { .vendor
= PCI_VENDOR_ID_IBM
,
6822 .bios
= TPACPI_MATCH_ANY
,
6823 .ec
= TPACPI_MATCH_ANY
,
6824 .quirks
= TPACPI_VOL_Q_LEVEL
},
6826 /* Lenovo models with volume control (needs confirmation) */
6827 TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL
), /* R60/i */
6828 TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL
), /* R60e/i */
6829 TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL
), /* T60/p */
6830 TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL
), /* X60/s */
6831 TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL
), /* X60t */
6832 TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL
), /* Z60 */
6833 TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL
), /* Z61 */
6835 /* Whitelist mute-only on all Lenovo by default */
6836 { .vendor
= PCI_VENDOR_ID_LENOVO
,
6837 .bios
= TPACPI_MATCH_ANY
,
6838 .ec
= TPACPI_MATCH_ANY
,
6839 .quirks
= TPACPI_VOL_Q_MUTEONLY
}
6842 static int __init
volume_init(struct ibm_init_struct
*iibm
)
6844 unsigned long quirks
;
6847 vdbg_printk(TPACPI_DBG_INIT
, "initializing volume subdriver\n");
6849 mutex_init(&volume_mutex
);
6852 * Check for module parameter bogosity, note that we
6853 * init volume_mode to TPACPI_VOL_MODE_MAX in order to be
6854 * able to detect "unspecified"
6856 if (volume_mode
> TPACPI_VOL_MODE_MAX
)
6859 if (volume_mode
== TPACPI_VOL_MODE_UCMS_STEP
) {
6861 "UCMS step volume mode not implemented, "
6862 "please contact %s\n", TPACPI_MAIL
);
6866 if (volume_capabilities
>= TPACPI_VOL_CAP_MAX
)
6870 * The ALSA mixer is our primary interface.
6871 * When disabled, don't install the subdriver at all
6874 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6875 "ALSA mixer disabled by parameter, "
6876 "not loading volume subdriver...\n");
6880 quirks
= tpacpi_check_quirks(volume_quirk_table
,
6881 ARRAY_SIZE(volume_quirk_table
));
6883 switch (volume_capabilities
) {
6884 case TPACPI_VOL_CAP_AUTO
:
6885 if (quirks
& TPACPI_VOL_Q_MUTEONLY
)
6886 tp_features
.mixer_no_level_control
= 1;
6887 else if (quirks
& TPACPI_VOL_Q_LEVEL
)
6888 tp_features
.mixer_no_level_control
= 0;
6890 return 1; /* no mixer */
6892 case TPACPI_VOL_CAP_VOLMUTE
:
6893 tp_features
.mixer_no_level_control
= 0;
6895 case TPACPI_VOL_CAP_MUTEONLY
:
6896 tp_features
.mixer_no_level_control
= 1;
6902 if (volume_capabilities
!= TPACPI_VOL_CAP_AUTO
)
6903 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6904 "using user-supplied volume_capabilities=%d\n",
6905 volume_capabilities
);
6907 if (volume_mode
== TPACPI_VOL_MODE_AUTO
||
6908 volume_mode
== TPACPI_VOL_MODE_MAX
) {
6909 volume_mode
= TPACPI_VOL_MODE_ECNVRAM
;
6911 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6912 "driver auto-selected volume_mode=%d\n",
6915 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6916 "using user-supplied volume_mode=%d\n",
6920 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6921 "mute is supported, volume control is %s\n",
6922 str_supported(!tp_features
.mixer_no_level_control
));
6924 rc
= volume_create_alsa_mixer();
6927 "Could not create the ALSA mixer interface\n");
6932 "Console audio control enabled, mode: %s\n",
6933 (volume_control_allowed
) ?
6934 "override (read/write)" :
6935 "monitor (read only)");
6937 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6938 "registering volume hotkeys as change notification\n");
6939 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6940 | TP_ACPI_HKEY_VOLUP_MASK
6941 | TP_ACPI_HKEY_VOLDWN_MASK
6942 | TP_ACPI_HKEY_MUTE_MASK
);
6947 static int volume_read(struct seq_file
*m
)
6951 if (volume_get_status(&status
) < 0) {
6952 seq_printf(m
, "level:\t\tunreadable\n");
6954 if (tp_features
.mixer_no_level_control
)
6955 seq_printf(m
, "level:\t\tunsupported\n");
6957 seq_printf(m
, "level:\t\t%d\n",
6958 status
& TP_EC_AUDIO_LVL_MSK
);
6960 seq_printf(m
, "mute:\t\t%s\n",
6961 onoff(status
, TP_EC_AUDIO_MUTESW
));
6963 if (volume_control_allowed
) {
6964 seq_printf(m
, "commands:\tunmute, mute\n");
6965 if (!tp_features
.mixer_no_level_control
) {
6967 "commands:\tup, down\n");
6969 "commands:\tlevel <level>"
6970 " (<level> is 0-%d)\n",
6979 static int volume_write(char *buf
)
6982 u8 new_level
, new_mute
;
6988 * We do allow volume control at driver startup, so that the
6989 * user can set initial state through the volume=... parameter hack.
6991 if (!volume_control_allowed
&& tpacpi_lifecycle
!= TPACPI_LIFE_INIT
) {
6992 if (unlikely(!tp_warned
.volume_ctrl_forbidden
)) {
6993 tp_warned
.volume_ctrl_forbidden
= 1;
6994 printk(TPACPI_NOTICE
6995 "Console audio control in monitor mode, "
6996 "changes are not allowed.\n");
6997 printk(TPACPI_NOTICE
6998 "Use the volume_control=1 module parameter "
6999 "to enable volume control\n");
7004 rc
= volume_get_status(&s
);
7008 new_level
= s
& TP_EC_AUDIO_LVL_MSK
;
7009 new_mute
= s
& TP_EC_AUDIO_MUTESW_MSK
;
7011 while ((cmd
= next_cmd(&buf
))) {
7012 if (!tp_features
.mixer_no_level_control
) {
7013 if (strlencmp(cmd
, "up") == 0) {
7016 else if (new_level
< TP_EC_VOLUME_MAX
)
7019 } else if (strlencmp(cmd
, "down") == 0) {
7022 else if (new_level
> 0)
7025 } else if (sscanf(cmd
, "level %u", &l
) == 1 &&
7026 l
>= 0 && l
<= TP_EC_VOLUME_MAX
) {
7031 if (strlencmp(cmd
, "mute") == 0)
7032 new_mute
= TP_EC_AUDIO_MUTESW_MSK
;
7033 else if (strlencmp(cmd
, "unmute") == 0)
7039 if (tp_features
.mixer_no_level_control
) {
7040 tpacpi_disclose_usertask("procfs volume", "%smute\n",
7041 new_mute
? "" : "un");
7042 rc
= volume_set_mute(!!new_mute
);
7044 tpacpi_disclose_usertask("procfs volume",
7045 "%smute and set level to %d\n",
7046 new_mute
? "" : "un", new_level
);
7047 rc
= volume_set_status(new_mute
| new_level
);
7049 volume_alsa_notify_change();
7051 return (rc
== -EINTR
) ? -ERESTARTSYS
: rc
;
7054 static struct ibm_struct volume_driver_data
= {
7056 .read
= volume_read
,
7057 .write
= volume_write
,
7058 .exit
= volume_exit
,
7059 .suspend
= volume_suspend
,
7060 .resume
= volume_resume
,
7061 .shutdown
= volume_shutdown
,
7064 #else /* !CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
7066 #define alsa_card NULL
7068 static void inline volume_alsa_notify_change(void)
7072 static int __init
volume_init(struct ibm_init_struct
*iibm
)
7075 "volume: disabled as there is no ALSA support in this kernel\n");
7080 static struct ibm_struct volume_driver_data
= {
7084 #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
7086 /*************************************************************************
7093 * TPACPI_FAN_RD_ACPI_GFAN:
7094 * ACPI GFAN method: returns fan level
7096 * see TPACPI_FAN_WR_ACPI_SFAN
7097 * EC 0x2f (HFSP) not available if GFAN exists
7099 * TPACPI_FAN_WR_ACPI_SFAN:
7100 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
7102 * EC 0x2f (HFSP) might be available *for reading*, but do not use
7105 * TPACPI_FAN_WR_TPEC:
7106 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
7107 * Supported on almost all ThinkPads
7109 * Fan speed changes of any sort (including those caused by the
7110 * disengaged mode) are usually done slowly by the firmware as the
7111 * maximum ammount of fan duty cycle change per second seems to be
7114 * Reading is not available if GFAN exists.
7115 * Writing is not available if SFAN exists.
7118 * 7 automatic mode engaged;
7119 * (default operation mode of the ThinkPad)
7120 * fan level is ignored in this mode.
7121 * 6 full speed mode (takes precedence over bit 7);
7122 * not available on all thinkpads. May disable
7123 * the tachometer while the fan controller ramps up
7124 * the speed (which can take up to a few *minutes*).
7125 * Speeds up fan to 100% duty-cycle, which is far above
7126 * the standard RPM levels. It is not impossible that
7127 * it could cause hardware damage.
7128 * 5-3 unused in some models. Extra bits for fan level
7129 * in others, but still useless as all values above
7130 * 7 map to the same speed as level 7 in these models.
7131 * 2-0 fan level (0..7 usually)
7133 * 0x07 = max (set when temperatures critical)
7134 * Some ThinkPads may have other levels, see
7135 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
7137 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
7138 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
7139 * does so, its initial value is meaningless (0x07).
7141 * For firmware bugs, refer to:
7142 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7146 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
7147 * Main fan tachometer reading (in RPM)
7149 * This register is present on all ThinkPads with a new-style EC, and
7150 * it is known not to be present on the A21m/e, and T22, as there is
7151 * something else in offset 0x84 according to the ACPI DSDT. Other
7152 * ThinkPads from this same time period (and earlier) probably lack the
7153 * tachometer as well.
7155 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
7156 * was never fixed by IBM to report the EC firmware version string
7157 * probably support the tachometer (like the early X models), so
7158 * detecting it is quite hard. We need more data to know for sure.
7160 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
7163 * FIRMWARE BUG: may go stale while the EC is switching to full speed
7166 * For firmware bugs, refer to:
7167 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7171 * ThinkPad EC register 0x31 bit 0 (only on select models)
7173 * When bit 0 of EC register 0x31 is zero, the tachometer registers
7174 * show the speed of the main fan. When bit 0 of EC register 0x31
7175 * is one, the tachometer registers show the speed of the auxiliary
7178 * Fan control seems to affect both fans, regardless of the state
7181 * So far, only the firmware for the X60/X61 non-tablet versions
7182 * seem to support this (firmware TP-7M).
7184 * TPACPI_FAN_WR_ACPI_FANS:
7185 * ThinkPad X31, X40, X41. Not available in the X60.
7187 * FANS ACPI handle: takes three arguments: low speed, medium speed,
7188 * high speed. ACPI DSDT seems to map these three speeds to levels
7189 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
7190 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
7192 * The speeds are stored on handles
7193 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
7195 * There are three default speed sets, accessible as handles:
7196 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
7198 * ACPI DSDT switches which set is in use depending on various
7201 * TPACPI_FAN_WR_TPEC is also available and should be used to
7202 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
7203 * but the ACPI tables just mention level 7.
7206 enum { /* Fan control constants */
7207 fan_status_offset
= 0x2f, /* EC register 0x2f */
7208 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
7209 * 0x84 must be read before 0x85 */
7210 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
7211 bit 0 selects which fan is active */
7213 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
7214 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
7216 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
7219 enum fan_status_access_mode
{
7220 TPACPI_FAN_NONE
= 0, /* No fan status or control */
7221 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
7222 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
7225 enum fan_control_access_mode
{
7226 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
7227 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
7228 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
7229 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
7232 enum fan_control_commands
{
7233 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
7234 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
7235 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
7236 * and also watchdog cmd */
7239 static int fan_control_allowed
;
7241 static enum fan_status_access_mode fan_status_access_mode
;
7242 static enum fan_control_access_mode fan_control_access_mode
;
7243 static enum fan_control_commands fan_control_commands
;
7245 static u8 fan_control_initial_status
;
7246 static u8 fan_control_desired_level
;
7247 static u8 fan_control_resume_level
;
7248 static int fan_watchdog_maxinterval
;
7250 static struct mutex fan_mutex
;
7252 static void fan_watchdog_fire(struct work_struct
*ignored
);
7253 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
7255 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
7256 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
7257 "\\FSPD", /* 600e/x, 770e, 770x */
7259 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
7260 "JFNS", /* 770x-JL */
7264 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
7265 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
7266 * be in auto mode (0x80).
7268 * This is corrected by any write to HFSP either by the driver, or
7271 * We assume 0x07 really means auto mode while this quirk is active,
7272 * as this is far more likely than the ThinkPad being in level 7,
7273 * which is only used by the firmware during thermal emergencies.
7275 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
7276 * TP-70 (T43, R52), which are known to be buggy.
7279 static void fan_quirk1_setup(void)
7281 if (fan_control_initial_status
== 0x07) {
7282 printk(TPACPI_NOTICE
7283 "fan_init: initial fan status is unknown, "
7284 "assuming it is in auto mode\n");
7285 tp_features
.fan_ctrl_status_undef
= 1;
7289 static void fan_quirk1_handle(u8
*fan_status
)
7291 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
7292 if (*fan_status
!= fan_control_initial_status
) {
7293 /* something changed the HFSP regisnter since
7294 * driver init time, so it is not undefined
7296 tp_features
.fan_ctrl_status_undef
= 0;
7298 /* Return most likely status. In fact, it
7299 * might be the only possible status */
7300 *fan_status
= TP_EC_FAN_AUTO
;
7305 /* Select main fan on X60/X61, NOOP on others */
7306 static bool fan_select_fan1(void)
7308 if (tp_features
.second_fan
) {
7311 if (ec_read(fan_select_offset
, &val
) < 0)
7314 if (ec_write(fan_select_offset
, val
) < 0)
7320 /* Select secondary fan on X60/X61 */
7321 static bool fan_select_fan2(void)
7325 if (!tp_features
.second_fan
)
7328 if (ec_read(fan_select_offset
, &val
) < 0)
7331 if (ec_write(fan_select_offset
, val
) < 0)
7338 * Call with fan_mutex held
7340 static void fan_update_desired_level(u8 status
)
7343 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7345 fan_control_desired_level
= 7;
7347 fan_control_desired_level
= status
;
7351 static int fan_get_status(u8
*status
)
7356 * Add TPACPI_FAN_RD_ACPI_FANS ? */
7358 switch (fan_status_access_mode
) {
7359 case TPACPI_FAN_RD_ACPI_GFAN
:
7360 /* 570, 600e/x, 770e, 770x */
7362 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
7370 case TPACPI_FAN_RD_TPEC
:
7371 /* all except 570, 600e/x, 770e, 770x */
7372 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
7375 if (likely(status
)) {
7377 fan_quirk1_handle(status
);
7389 static int fan_get_status_safe(u8
*status
)
7394 if (mutex_lock_killable(&fan_mutex
))
7395 return -ERESTARTSYS
;
7396 rc
= fan_get_status(&s
);
7398 fan_update_desired_level(s
);
7399 mutex_unlock(&fan_mutex
);
7407 static int fan_get_speed(unsigned int *speed
)
7411 switch (fan_status_access_mode
) {
7412 case TPACPI_FAN_RD_TPEC
:
7413 /* all except 570, 600e/x, 770e, 770x */
7414 if (unlikely(!fan_select_fan1()))
7416 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
7417 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
7421 *speed
= (hi
<< 8) | lo
;
7432 static int fan2_get_speed(unsigned int *speed
)
7437 switch (fan_status_access_mode
) {
7438 case TPACPI_FAN_RD_TPEC
:
7439 /* all except 570, 600e/x, 770e, 770x */
7440 if (unlikely(!fan_select_fan2()))
7442 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
7443 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
7444 fan_select_fan1(); /* play it safe */
7449 *speed
= (hi
<< 8) | lo
;
7460 static int fan_set_level(int level
)
7462 if (!fan_control_allowed
)
7465 switch (fan_control_access_mode
) {
7466 case TPACPI_FAN_WR_ACPI_SFAN
:
7467 if (level
>= 0 && level
<= 7) {
7468 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
7474 case TPACPI_FAN_WR_ACPI_FANS
:
7475 case TPACPI_FAN_WR_TPEC
:
7476 if (!(level
& TP_EC_FAN_AUTO
) &&
7477 !(level
& TP_EC_FAN_FULLSPEED
) &&
7478 ((level
< 0) || (level
> 7)))
7481 /* safety net should the EC not support AUTO
7482 * or FULLSPEED mode bits and just ignore them */
7483 if (level
& TP_EC_FAN_FULLSPEED
)
7484 level
|= 7; /* safety min speed 7 */
7485 else if (level
& TP_EC_FAN_AUTO
)
7486 level
|= 4; /* safety min speed 4 */
7488 if (!acpi_ec_write(fan_status_offset
, level
))
7491 tp_features
.fan_ctrl_status_undef
= 0;
7498 vdbg_printk(TPACPI_DBG_FAN
,
7499 "fan control: set fan control register to 0x%02x\n", level
);
7503 static int fan_set_level_safe(int level
)
7507 if (!fan_control_allowed
)
7510 if (mutex_lock_killable(&fan_mutex
))
7511 return -ERESTARTSYS
;
7513 if (level
== TPACPI_FAN_LAST_LEVEL
)
7514 level
= fan_control_desired_level
;
7516 rc
= fan_set_level(level
);
7518 fan_update_desired_level(level
);
7520 mutex_unlock(&fan_mutex
);
7524 static int fan_set_enable(void)
7529 if (!fan_control_allowed
)
7532 if (mutex_lock_killable(&fan_mutex
))
7533 return -ERESTARTSYS
;
7535 switch (fan_control_access_mode
) {
7536 case TPACPI_FAN_WR_ACPI_FANS
:
7537 case TPACPI_FAN_WR_TPEC
:
7538 rc
= fan_get_status(&s
);
7542 /* Don't go out of emergency fan mode */
7545 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
7548 if (!acpi_ec_write(fan_status_offset
, s
))
7551 tp_features
.fan_ctrl_status_undef
= 0;
7556 case TPACPI_FAN_WR_ACPI_SFAN
:
7557 rc
= fan_get_status(&s
);
7563 /* Set fan to at least level 4 */
7566 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
7576 mutex_unlock(&fan_mutex
);
7579 vdbg_printk(TPACPI_DBG_FAN
,
7580 "fan control: set fan control register to 0x%02x\n",
7585 static int fan_set_disable(void)
7589 if (!fan_control_allowed
)
7592 if (mutex_lock_killable(&fan_mutex
))
7593 return -ERESTARTSYS
;
7596 switch (fan_control_access_mode
) {
7597 case TPACPI_FAN_WR_ACPI_FANS
:
7598 case TPACPI_FAN_WR_TPEC
:
7599 if (!acpi_ec_write(fan_status_offset
, 0x00))
7602 fan_control_desired_level
= 0;
7603 tp_features
.fan_ctrl_status_undef
= 0;
7607 case TPACPI_FAN_WR_ACPI_SFAN
:
7608 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
7611 fan_control_desired_level
= 0;
7619 vdbg_printk(TPACPI_DBG_FAN
,
7620 "fan control: set fan control register to 0\n");
7622 mutex_unlock(&fan_mutex
);
7626 static int fan_set_speed(int speed
)
7630 if (!fan_control_allowed
)
7633 if (mutex_lock_killable(&fan_mutex
))
7634 return -ERESTARTSYS
;
7637 switch (fan_control_access_mode
) {
7638 case TPACPI_FAN_WR_ACPI_FANS
:
7639 if (speed
>= 0 && speed
<= 65535) {
7640 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
7641 speed
, speed
, speed
))
7651 mutex_unlock(&fan_mutex
);
7655 static void fan_watchdog_reset(void)
7657 static int fan_watchdog_active
;
7659 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
7662 if (fan_watchdog_active
)
7663 cancel_delayed_work(&fan_watchdog_task
);
7665 if (fan_watchdog_maxinterval
> 0 &&
7666 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
7667 fan_watchdog_active
= 1;
7668 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
7669 msecs_to_jiffies(fan_watchdog_maxinterval
7672 "failed to queue the fan watchdog, "
7673 "watchdog will not trigger\n");
7676 fan_watchdog_active
= 0;
7679 static void fan_watchdog_fire(struct work_struct
*ignored
)
7683 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
7686 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
7687 rc
= fan_set_enable();
7689 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
7690 "will try again later...\n", -rc
);
7691 /* reschedule for later */
7692 fan_watchdog_reset();
7697 * SYSFS fan layout: hwmon compatible (device)
7700 * 0: "disengaged" mode
7702 * 2: native EC "auto" mode (recommended, hardware default)
7704 * pwm*: set speed in manual mode, ignored otherwise.
7705 * 0 is level 0; 255 is level 7. Intermediate points done with linear
7708 * fan*_input: tachometer reading, RPM
7711 * SYSFS fan layout: extensions
7713 * fan_watchdog (driver):
7714 * fan watchdog interval in seconds, 0 disables (default), max 120
7717 /* sysfs fan pwm1_enable ----------------------------------------------- */
7718 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
7719 struct device_attribute
*attr
,
7725 res
= fan_get_status_safe(&status
);
7729 if (status
& TP_EC_FAN_FULLSPEED
) {
7731 } else if (status
& TP_EC_FAN_AUTO
) {
7736 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
7739 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7740 struct device_attribute
*attr
,
7741 const char *buf
, size_t count
)
7746 if (parse_strtoul(buf
, 2, &t
))
7749 tpacpi_disclose_usertask("hwmon pwm1_enable",
7750 "set fan mode to %lu\n", t
);
7754 level
= TP_EC_FAN_FULLSPEED
;
7757 level
= TPACPI_FAN_LAST_LEVEL
;
7760 level
= TP_EC_FAN_AUTO
;
7763 /* reserved for software-controlled auto mode */
7769 res
= fan_set_level_safe(level
);
7775 fan_watchdog_reset();
7780 static struct device_attribute dev_attr_fan_pwm1_enable
=
7781 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7782 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7784 /* sysfs fan pwm1 ------------------------------------------------------ */
7785 static ssize_t
fan_pwm1_show(struct device
*dev
,
7786 struct device_attribute
*attr
,
7792 res
= fan_get_status_safe(&status
);
7797 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7798 status
= fan_control_desired_level
;
7803 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7806 static ssize_t
fan_pwm1_store(struct device
*dev
,
7807 struct device_attribute
*attr
,
7808 const char *buf
, size_t count
)
7812 u8 status
, newlevel
;
7814 if (parse_strtoul(buf
, 255, &s
))
7817 tpacpi_disclose_usertask("hwmon pwm1",
7818 "set fan speed to %lu\n", s
);
7820 /* scale down from 0-255 to 0-7 */
7821 newlevel
= (s
>> 5) & 0x07;
7823 if (mutex_lock_killable(&fan_mutex
))
7824 return -ERESTARTSYS
;
7826 rc
= fan_get_status(&status
);
7827 if (!rc
&& (status
&
7828 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7829 rc
= fan_set_level(newlevel
);
7833 fan_update_desired_level(newlevel
);
7834 fan_watchdog_reset();
7838 mutex_unlock(&fan_mutex
);
7839 return (rc
)? rc
: count
;
7842 static struct device_attribute dev_attr_fan_pwm1
=
7843 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7844 fan_pwm1_show
, fan_pwm1_store
);
7846 /* sysfs fan fan1_input ------------------------------------------------ */
7847 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7848 struct device_attribute
*attr
,
7854 res
= fan_get_speed(&speed
);
7858 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7861 static struct device_attribute dev_attr_fan_fan1_input
=
7862 __ATTR(fan1_input
, S_IRUGO
,
7863 fan_fan1_input_show
, NULL
);
7865 /* sysfs fan fan2_input ------------------------------------------------ */
7866 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7867 struct device_attribute
*attr
,
7873 res
= fan2_get_speed(&speed
);
7877 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7880 static struct device_attribute dev_attr_fan_fan2_input
=
7881 __ATTR(fan2_input
, S_IRUGO
,
7882 fan_fan2_input_show
, NULL
);
7884 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
7885 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
7888 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
7891 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
7892 const char *buf
, size_t count
)
7896 if (parse_strtoul(buf
, 120, &t
))
7899 if (!fan_control_allowed
)
7902 fan_watchdog_maxinterval
= t
;
7903 fan_watchdog_reset();
7905 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
7910 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
7911 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
7913 /* --------------------------------------------------------------------- */
7914 static struct attribute
*fan_attributes
[] = {
7915 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
7916 &dev_attr_fan_fan1_input
.attr
,
7917 NULL
, /* for fan2_input */
7921 static const struct attribute_group fan_attr_group
= {
7922 .attrs
= fan_attributes
,
7925 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
7926 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
7928 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7929 { .vendor = PCI_VENDOR_ID_IBM, \
7930 .bios = TPACPI_MATCH_ANY, \
7931 .ec = TPID(__id1, __id2), \
7932 .quirks = __quirks }
7934 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7935 { .vendor = PCI_VENDOR_ID_LENOVO, \
7936 .bios = TPACPI_MATCH_ANY, \
7937 .ec = TPID(__id1, __id2), \
7938 .quirks = __quirks }
7940 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
7941 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
7942 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
7943 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
7944 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
7945 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
7948 #undef TPACPI_FAN_QL
7949 #undef TPACPI_FAN_QI
7951 static int __init
fan_init(struct ibm_init_struct
*iibm
)
7954 unsigned long quirks
;
7956 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7957 "initializing fan subdriver\n");
7959 mutex_init(&fan_mutex
);
7960 fan_status_access_mode
= TPACPI_FAN_NONE
;
7961 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7962 fan_control_commands
= 0;
7963 fan_watchdog_maxinterval
= 0;
7964 tp_features
.fan_ctrl_status_undef
= 0;
7965 tp_features
.second_fan
= 0;
7966 fan_control_desired_level
= 7;
7968 TPACPI_ACPIHANDLE_INIT(fans
);
7969 TPACPI_ACPIHANDLE_INIT(gfan
);
7970 TPACPI_ACPIHANDLE_INIT(sfan
);
7972 quirks
= tpacpi_check_quirks(fan_quirk_table
,
7973 ARRAY_SIZE(fan_quirk_table
));
7976 /* 570, 600e/x, 770e, 770x */
7977 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7979 /* all other ThinkPads: note that even old-style
7980 * ThinkPad ECs supports the fan control register */
7981 if (likely(acpi_ec_read(fan_status_offset
,
7982 &fan_control_initial_status
))) {
7983 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7984 if (quirks
& TPACPI_FAN_Q1
)
7986 if (quirks
& TPACPI_FAN_2FAN
) {
7987 tp_features
.second_fan
= 1;
7988 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7989 "secondary fan support enabled\n");
7993 "ThinkPad ACPI EC access misbehaving, "
7994 "fan status and control unavailable\n");
8001 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
8002 fan_control_commands
|=
8003 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
8006 /* gfan without sfan means no fan control */
8007 /* all other models implement TP EC 0x2f control */
8011 fan_control_access_mode
=
8012 TPACPI_FAN_WR_ACPI_FANS
;
8013 fan_control_commands
|=
8014 TPACPI_FAN_CMD_SPEED
|
8015 TPACPI_FAN_CMD_LEVEL
|
8016 TPACPI_FAN_CMD_ENABLE
;
8018 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
8019 fan_control_commands
|=
8020 TPACPI_FAN_CMD_LEVEL
|
8021 TPACPI_FAN_CMD_ENABLE
;
8026 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8027 "fan is %s, modes %d, %d\n",
8028 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
8029 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
8030 fan_status_access_mode
, fan_control_access_mode
);
8032 /* fan control master switch */
8033 if (!fan_control_allowed
) {
8034 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
8035 fan_control_commands
= 0;
8036 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8037 "fan control features disabled by parameter\n");
8040 /* update fan_control_desired_level */
8041 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
8042 fan_get_status_safe(NULL
);
8044 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
8045 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
8046 if (tp_features
.second_fan
) {
8047 /* attach second fan tachometer */
8048 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
8049 &dev_attr_fan_fan2_input
.attr
;
8051 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8056 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
8057 &driver_attr_fan_watchdog
);
8059 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8068 static void fan_exit(void)
8070 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
8071 "cancelling any pending fan watchdog tasks\n");
8073 /* FIXME: can we really do this unconditionally? */
8074 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
8075 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
8076 &driver_attr_fan_watchdog
);
8078 cancel_delayed_work(&fan_watchdog_task
);
8079 flush_workqueue(tpacpi_wq
);
8082 static void fan_suspend(pm_message_t state
)
8086 if (!fan_control_allowed
)
8089 /* Store fan status in cache */
8090 fan_control_resume_level
= 0;
8091 rc
= fan_get_status_safe(&fan_control_resume_level
);
8093 printk(TPACPI_NOTICE
8094 "failed to read fan level for later "
8095 "restore during resume: %d\n", rc
);
8097 /* if it is undefined, don't attempt to restore it.
8099 if (tp_features
.fan_ctrl_status_undef
)
8100 fan_control_resume_level
= 0;
8103 static void fan_resume(void)
8105 u8 current_level
= 7;
8106 bool do_set
= false;
8109 /* DSDT *always* updates status on resume */
8110 tp_features
.fan_ctrl_status_undef
= 0;
8112 if (!fan_control_allowed
||
8113 !fan_control_resume_level
||
8114 (fan_get_status_safe(¤t_level
) < 0))
8117 switch (fan_control_access_mode
) {
8118 case TPACPI_FAN_WR_ACPI_SFAN
:
8119 /* never decrease fan level */
8120 do_set
= (fan_control_resume_level
> current_level
);
8122 case TPACPI_FAN_WR_ACPI_FANS
:
8123 case TPACPI_FAN_WR_TPEC
:
8124 /* never decrease fan level, scale is:
8125 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
8127 * We expect the firmware to set either 7 or AUTO, but we
8128 * handle FULLSPEED out of paranoia.
8130 * So, we can safely only restore FULLSPEED or 7, anything
8131 * else could slow the fan. Restoring AUTO is useless, at
8132 * best that's exactly what the DSDT already set (it is the
8135 * Always keep in mind that the DSDT *will* have set the
8136 * fans to what the vendor supposes is the best level. We
8137 * muck with it only to speed the fan up.
8139 if (fan_control_resume_level
!= 7 &&
8140 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
8143 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
8144 (current_level
!= fan_control_resume_level
);
8150 printk(TPACPI_NOTICE
8151 "restoring fan level to 0x%02x\n",
8152 fan_control_resume_level
);
8153 rc
= fan_set_level_safe(fan_control_resume_level
);
8155 printk(TPACPI_NOTICE
8156 "failed to restore fan level: %d\n", rc
);
8160 static int fan_read(struct seq_file
*m
)
8164 unsigned int speed
= 0;
8166 switch (fan_status_access_mode
) {
8167 case TPACPI_FAN_RD_ACPI_GFAN
:
8168 /* 570, 600e/x, 770e, 770x */
8169 rc
= fan_get_status_safe(&status
);
8173 seq_printf(m
, "status:\t\t%s\n"
8175 (status
!= 0) ? "enabled" : "disabled", status
);
8178 case TPACPI_FAN_RD_TPEC
:
8179 /* all except 570, 600e/x, 770e, 770x */
8180 rc
= fan_get_status_safe(&status
);
8184 seq_printf(m
, "status:\t\t%s\n",
8185 (status
!= 0) ? "enabled" : "disabled");
8187 rc
= fan_get_speed(&speed
);
8191 seq_printf(m
, "speed:\t\t%d\n", speed
);
8193 if (status
& TP_EC_FAN_FULLSPEED
)
8194 /* Disengaged mode takes precedence */
8195 seq_printf(m
, "level:\t\tdisengaged\n");
8196 else if (status
& TP_EC_FAN_AUTO
)
8197 seq_printf(m
, "level:\t\tauto\n");
8199 seq_printf(m
, "level:\t\t%d\n", status
);
8202 case TPACPI_FAN_NONE
:
8204 seq_printf(m
, "status:\t\tnot supported\n");
8207 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
8208 seq_printf(m
, "commands:\tlevel <level>");
8210 switch (fan_control_access_mode
) {
8211 case TPACPI_FAN_WR_ACPI_SFAN
:
8212 seq_printf(m
, " (<level> is 0-7)\n");
8216 seq_printf(m
, " (<level> is 0-7, "
8217 "auto, disengaged, full-speed)\n");
8222 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
8223 seq_printf(m
, "commands:\tenable, disable\n"
8224 "commands:\twatchdog <timeout> (<timeout> "
8225 "is 0 (off), 1-120 (seconds))\n");
8227 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
8228 seq_printf(m
, "commands:\tspeed <speed>"
8229 " (<speed> is 0-65535)\n");
8234 static int fan_write_cmd_level(const char *cmd
, int *rc
)
8238 if (strlencmp(cmd
, "level auto") == 0)
8239 level
= TP_EC_FAN_AUTO
;
8240 else if ((strlencmp(cmd
, "level disengaged") == 0) |
8241 (strlencmp(cmd
, "level full-speed") == 0))
8242 level
= TP_EC_FAN_FULLSPEED
;
8243 else if (sscanf(cmd
, "level %d", &level
) != 1)
8246 *rc
= fan_set_level_safe(level
);
8248 printk(TPACPI_ERR
"level command accepted for unsupported "
8249 "access mode %d", fan_control_access_mode
);
8251 tpacpi_disclose_usertask("procfs fan",
8252 "set level to %d\n", level
);
8257 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
8259 if (strlencmp(cmd
, "enable") != 0)
8262 *rc
= fan_set_enable();
8264 printk(TPACPI_ERR
"enable command accepted for unsupported "
8265 "access mode %d", fan_control_access_mode
);
8267 tpacpi_disclose_usertask("procfs fan", "enable\n");
8272 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
8274 if (strlencmp(cmd
, "disable") != 0)
8277 *rc
= fan_set_disable();
8279 printk(TPACPI_ERR
"disable command accepted for unsupported "
8280 "access mode %d", fan_control_access_mode
);
8282 tpacpi_disclose_usertask("procfs fan", "disable\n");
8287 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
8292 * Support speed <low> <medium> <high> ? */
8294 if (sscanf(cmd
, "speed %d", &speed
) != 1)
8297 *rc
= fan_set_speed(speed
);
8299 printk(TPACPI_ERR
"speed command accepted for unsupported "
8300 "access mode %d", fan_control_access_mode
);
8302 tpacpi_disclose_usertask("procfs fan",
8303 "set speed to %d\n", speed
);
8308 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
8312 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
8315 if (interval
< 0 || interval
> 120)
8318 fan_watchdog_maxinterval
= interval
;
8319 tpacpi_disclose_usertask("procfs fan",
8320 "set watchdog timer to %d\n",
8327 static int fan_write(char *buf
)
8332 while (!rc
&& (cmd
= next_cmd(&buf
))) {
8333 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
8334 fan_write_cmd_level(cmd
, &rc
)) &&
8335 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
8336 (fan_write_cmd_enable(cmd
, &rc
) ||
8337 fan_write_cmd_disable(cmd
, &rc
) ||
8338 fan_write_cmd_watchdog(cmd
, &rc
))) &&
8339 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
8340 fan_write_cmd_speed(cmd
, &rc
))
8344 fan_watchdog_reset();
8350 static struct ibm_struct fan_driver_data
= {
8355 .suspend
= fan_suspend
,
8356 .resume
= fan_resume
,
8359 /****************************************************************************
8360 ****************************************************************************
8364 ****************************************************************************
8365 ****************************************************************************/
8368 * HKEY event callout for other subdrivers go here
8369 * (yes, it is ugly, but it is quick, safe, and gets the job done
8371 static void tpacpi_driver_event(const unsigned int hkey_event
)
8373 if (ibm_backlight_device
) {
8374 switch (hkey_event
) {
8375 case TP_HKEY_EV_BRGHT_UP
:
8376 case TP_HKEY_EV_BRGHT_DOWN
:
8377 tpacpi_brightness_notify_change();
8381 switch (hkey_event
) {
8382 case TP_HKEY_EV_VOL_UP
:
8383 case TP_HKEY_EV_VOL_DOWN
:
8384 case TP_HKEY_EV_VOL_MUTE
:
8385 volume_alsa_notify_change();
8390 static void hotkey_driver_event(const unsigned int scancode
)
8392 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
8395 /* sysfs name ---------------------------------------------------------- */
8396 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
8397 struct device_attribute
*attr
,
8400 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
8403 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
8404 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
8406 /* --------------------------------------------------------------------- */
8409 static struct proc_dir_entry
*proc_dir
;
8412 * Module and infrastructure proble, init and exit handling
8415 static int force_load
;
8417 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
8418 static const char * __init
str_supported(int is_supported
)
8420 static char text_unsupported
[] __initdata
= "not supported";
8422 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
8424 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
8426 static void ibm_exit(struct ibm_struct
*ibm
)
8428 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
8430 list_del_init(&ibm
->all_drivers
);
8432 if (ibm
->flags
.acpi_notify_installed
) {
8433 dbg_printk(TPACPI_DBG_EXIT
,
8434 "%s: acpi_remove_notify_handler\n", ibm
->name
);
8436 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
8438 dispatch_acpi_notify
);
8439 ibm
->flags
.acpi_notify_installed
= 0;
8440 ibm
->flags
.acpi_notify_installed
= 0;
8443 if (ibm
->flags
.proc_created
) {
8444 dbg_printk(TPACPI_DBG_EXIT
,
8445 "%s: remove_proc_entry\n", ibm
->name
);
8446 remove_proc_entry(ibm
->name
, proc_dir
);
8447 ibm
->flags
.proc_created
= 0;
8450 if (ibm
->flags
.acpi_driver_registered
) {
8451 dbg_printk(TPACPI_DBG_EXIT
,
8452 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
8454 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
8455 kfree(ibm
->acpi
->driver
);
8456 ibm
->acpi
->driver
= NULL
;
8457 ibm
->flags
.acpi_driver_registered
= 0;
8460 if (ibm
->flags
.init_called
&& ibm
->exit
) {
8462 ibm
->flags
.init_called
= 0;
8465 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
8468 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
8471 struct ibm_struct
*ibm
= iibm
->data
;
8472 struct proc_dir_entry
*entry
;
8474 BUG_ON(ibm
== NULL
);
8476 INIT_LIST_HEAD(&ibm
->all_drivers
);
8478 if (ibm
->flags
.experimental
&& !experimental
)
8481 dbg_printk(TPACPI_DBG_INIT
,
8482 "probing for %s\n", ibm
->name
);
8485 ret
= iibm
->init(iibm
);
8487 return 0; /* probe failed */
8491 ibm
->flags
.init_called
= 1;
8495 if (ibm
->acpi
->hid
) {
8496 ret
= register_tpacpi_subdriver(ibm
);
8501 if (ibm
->acpi
->notify
) {
8502 ret
= setup_acpi_notify(ibm
);
8503 if (ret
== -ENODEV
) {
8504 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
8514 dbg_printk(TPACPI_DBG_INIT
,
8515 "%s installed\n", ibm
->name
);
8518 mode_t mode
= iibm
->base_procfs_mode
;
8524 entry
= proc_create_data(ibm
->name
, mode
, proc_dir
,
8525 &dispatch_proc_fops
, ibm
);
8527 printk(TPACPI_ERR
"unable to create proc entry %s\n",
8532 ibm
->flags
.proc_created
= 1;
8535 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
8540 dbg_printk(TPACPI_DBG_INIT
,
8541 "%s: at error exit path with result %d\n",
8545 return (ret
< 0)? ret
: 0;
8550 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
8552 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
8555 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
8556 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
8559 return s
&& strlen(s
) >= 8 &&
8560 tpacpi_is_fw_digit(s
[0]) &&
8561 tpacpi_is_fw_digit(s
[1]) &&
8562 s
[2] == t
&& s
[3] == 'T' &&
8563 tpacpi_is_fw_digit(s
[4]) &&
8564 tpacpi_is_fw_digit(s
[5]) &&
8565 s
[6] == 'W' && s
[7] == 'W';
8568 /* returns 0 - probe ok, or < 0 - probe error.
8569 * Probe ok doesn't mean thinkpad found.
8570 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
8571 static int __must_check __init
get_thinkpad_model_data(
8572 struct thinkpad_id_data
*tp
)
8574 const struct dmi_device
*dev
= NULL
;
8575 char ec_fw_string
[18];
8581 memset(tp
, 0, sizeof(*tp
));
8583 if (dmi_name_in_vendors("IBM"))
8584 tp
->vendor
= PCI_VENDOR_ID_IBM
;
8585 else if (dmi_name_in_vendors("LENOVO"))
8586 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
8590 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
8591 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
8592 if (s
&& !tp
->bios_version_str
)
8595 /* Really ancient ThinkPad 240X will fail this, which is fine */
8596 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
8599 tp
->bios_model
= tp
->bios_version_str
[0]
8600 | (tp
->bios_version_str
[1] << 8);
8601 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
8602 | tp
->bios_version_str
[5];
8605 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
8606 * X32 or newer, all Z series; Some models must have an
8607 * up-to-date BIOS or they will not be detected.
8609 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8611 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
8612 if (sscanf(dev
->name
,
8613 "IBM ThinkPad Embedded Controller -[%17c",
8614 ec_fw_string
) == 1) {
8615 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
8616 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
8618 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
8619 if (!tp
->ec_version_str
)
8622 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
8623 tp
->ec_model
= ec_fw_string
[0]
8624 | (ec_fw_string
[1] << 8);
8625 tp
->ec_release
= (ec_fw_string
[4] << 8)
8628 printk(TPACPI_NOTICE
8629 "ThinkPad firmware release %s "
8630 "doesn't match the known patterns\n",
8632 printk(TPACPI_NOTICE
8633 "please report this to %s\n",
8640 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
8641 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
8642 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
8647 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
8648 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
8649 if (s
&& !tp
->nummodel_str
)
8655 static int __init
probe_for_thinkpad(void)
8663 * Non-ancient models have better DMI tagging, but very old models
8664 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
8666 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
8667 (thinkpad_id
.ec_model
!= 0) ||
8668 tpacpi_is_fw_known();
8670 /* ec is required because many other handles are relative to it */
8671 TPACPI_ACPIHANDLE_INIT(ec
);
8675 "Not yet supported ThinkPad detected!\n");
8679 if (!is_thinkpad
&& !force_load
)
8686 /* Module init, exit, parameters */
8688 static struct ibm_init_struct ibms_init
[] __initdata
= {
8690 .init
= thinkpad_acpi_driver_init
,
8691 .data
= &thinkpad_acpi_driver_data
,
8694 .init
= hotkey_init
,
8695 .data
= &hotkey_driver_data
,
8698 .init
= bluetooth_init
,
8699 .data
= &bluetooth_driver_data
,
8703 .data
= &wan_driver_data
,
8707 .data
= &uwb_driver_data
,
8709 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8712 .base_procfs_mode
= S_IRUSR
,
8713 .data
= &video_driver_data
,
8718 .data
= &light_driver_data
,
8722 .data
= &cmos_driver_data
,
8726 .data
= &led_driver_data
,
8730 .data
= &beep_driver_data
,
8733 .init
= thermal_init
,
8734 .data
= &thermal_driver_data
,
8737 .data
= &ecdump_driver_data
,
8740 .init
= brightness_init
,
8741 .data
= &brightness_driver_data
,
8744 .init
= volume_init
,
8745 .data
= &volume_driver_data
,
8749 .data
= &fan_driver_data
,
8753 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
8756 struct ibm_struct
*ibm
;
8758 if (!kp
|| !kp
->name
|| !val
)
8761 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8762 ibm
= ibms_init
[i
].data
;
8763 WARN_ON(ibm
== NULL
);
8765 if (!ibm
|| !ibm
->name
)
8768 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8769 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8771 strcpy(ibms_init
[i
].param
, val
);
8772 strcat(ibms_init
[i
].param
, ",");
8780 module_param(experimental
, int, 0444);
8781 MODULE_PARM_DESC(experimental
,
8782 "Enables experimental features when non-zero");
8784 module_param_named(debug
, dbg_level
, uint
, 0);
8785 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8787 module_param(force_load
, bool, 0444);
8788 MODULE_PARM_DESC(force_load
,
8789 "Attempts to load the driver even on a "
8790 "mis-identified ThinkPad when true");
8792 module_param_named(fan_control
, fan_control_allowed
, bool, 0444);
8793 MODULE_PARM_DESC(fan_control
,
8794 "Enables setting fan parameters features when true");
8796 module_param_named(brightness_mode
, brightness_mode
, uint
, 0444);
8797 MODULE_PARM_DESC(brightness_mode
,
8798 "Selects brightness control strategy: "
8799 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8801 module_param(brightness_enable
, uint
, 0444);
8802 MODULE_PARM_DESC(brightness_enable
,
8803 "Enables backlight control when 1, disables when 0");
8805 module_param(hotkey_report_mode
, uint
, 0444);
8806 MODULE_PARM_DESC(hotkey_report_mode
,
8807 "used for backwards compatibility with userspace, "
8808 "see documentation");
8810 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
8811 module_param_named(volume_mode
, volume_mode
, uint
, 0444);
8812 MODULE_PARM_DESC(volume_mode
,
8813 "Selects volume control strategy: "
8814 "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM");
8816 module_param_named(volume_capabilities
, volume_capabilities
, uint
, 0444);
8817 MODULE_PARM_DESC(volume_capabilities
,
8818 "Selects the mixer capabilites: "
8819 "0=auto, 1=volume and mute, 2=mute only");
8821 module_param_named(volume_control
, volume_control_allowed
, bool, 0444);
8822 MODULE_PARM_DESC(volume_control
,
8823 "Enables software override for the console audio "
8824 "control when true");
8826 /* ALSA module API parameters */
8827 module_param_named(index
, alsa_index
, int, 0444);
8828 MODULE_PARM_DESC(index
, "ALSA index for the ACPI EC Mixer");
8829 module_param_named(id
, alsa_id
, charp
, 0444);
8830 MODULE_PARM_DESC(id
, "ALSA id for the ACPI EC Mixer");
8831 module_param_named(enable
, alsa_enable
, bool, 0444);
8832 MODULE_PARM_DESC(enable
, "Enable the ALSA interface for the ACPI EC Mixer");
8833 #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
8835 #define TPACPI_PARAM(feature) \
8836 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8837 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8838 "at module load, see documentation")
8840 TPACPI_PARAM(hotkey
);
8841 TPACPI_PARAM(bluetooth
);
8842 TPACPI_PARAM(video
);
8843 TPACPI_PARAM(light
);
8847 TPACPI_PARAM(ecdump
);
8848 TPACPI_PARAM(brightness
);
8849 TPACPI_PARAM(volume
);
8852 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8853 module_param(dbg_wlswemul
, uint
, 0444);
8854 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
8855 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
8856 MODULE_PARM_DESC(wlsw_state
,
8857 "Initial state of the emulated WLSW switch");
8859 module_param(dbg_bluetoothemul
, uint
, 0444);
8860 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
8861 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
8862 MODULE_PARM_DESC(bluetooth_state
,
8863 "Initial state of the emulated bluetooth switch");
8865 module_param(dbg_wwanemul
, uint
, 0444);
8866 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
8867 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
8868 MODULE_PARM_DESC(wwan_state
,
8869 "Initial state of the emulated WWAN switch");
8871 module_param(dbg_uwbemul
, uint
, 0444);
8872 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
8873 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
8874 MODULE_PARM_DESC(uwb_state
,
8875 "Initial state of the emulated UWB switch");
8878 static void thinkpad_acpi_module_exit(void)
8880 struct ibm_struct
*ibm
, *itmp
;
8882 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
8884 list_for_each_entry_safe_reverse(ibm
, itmp
,
8885 &tpacpi_all_drivers
,
8890 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
8892 if (tpacpi_inputdev
) {
8893 if (tp_features
.input_device_registered
)
8894 input_unregister_device(tpacpi_inputdev
);
8896 input_free_device(tpacpi_inputdev
);
8900 hwmon_device_unregister(tpacpi_hwmon
);
8902 if (tp_features
.sensors_pdev_attrs_registered
)
8903 device_remove_file(&tpacpi_sensors_pdev
->dev
,
8904 &dev_attr_thinkpad_acpi_pdev_name
);
8905 if (tpacpi_sensors_pdev
)
8906 platform_device_unregister(tpacpi_sensors_pdev
);
8908 platform_device_unregister(tpacpi_pdev
);
8910 if (tp_features
.sensors_pdrv_attrs_registered
)
8911 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
8912 if (tp_features
.platform_drv_attrs_registered
)
8913 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
8915 if (tp_features
.sensors_pdrv_registered
)
8916 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
8918 if (tp_features
.platform_drv_registered
)
8919 platform_driver_unregister(&tpacpi_pdriver
);
8922 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
8925 destroy_workqueue(tpacpi_wq
);
8927 kfree(thinkpad_id
.bios_version_str
);
8928 kfree(thinkpad_id
.ec_version_str
);
8929 kfree(thinkpad_id
.model_str
);
8933 static int __init
thinkpad_acpi_module_init(void)
8937 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
8939 /* Parameter checking */
8940 if (hotkey_report_mode
> 2)
8943 /* Driver-level probe */
8945 ret
= get_thinkpad_model_data(&thinkpad_id
);
8948 "unable to get DMI data: %d\n", ret
);
8949 thinkpad_acpi_module_exit();
8952 ret
= probe_for_thinkpad();
8954 thinkpad_acpi_module_exit();
8958 /* Driver initialization */
8960 TPACPI_ACPIHANDLE_INIT(ecrd
);
8961 TPACPI_ACPIHANDLE_INIT(ecwr
);
8963 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
8965 thinkpad_acpi_module_exit();
8969 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
8972 "unable to create proc dir " TPACPI_PROC_DIR
);
8973 thinkpad_acpi_module_exit();
8977 ret
= platform_driver_register(&tpacpi_pdriver
);
8980 "unable to register main platform driver\n");
8981 thinkpad_acpi_module_exit();
8984 tp_features
.platform_drv_registered
= 1;
8986 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
8989 "unable to register hwmon platform driver\n");
8990 thinkpad_acpi_module_exit();
8993 tp_features
.sensors_pdrv_registered
= 1;
8995 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
8997 tp_features
.platform_drv_attrs_registered
= 1;
8998 ret
= tpacpi_create_driver_attributes(
8999 &tpacpi_hwmon_pdriver
.driver
);
9003 "unable to create sysfs driver attributes\n");
9004 thinkpad_acpi_module_exit();
9007 tp_features
.sensors_pdrv_attrs_registered
= 1;
9010 /* Device initialization */
9011 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
9013 if (IS_ERR(tpacpi_pdev
)) {
9014 ret
= PTR_ERR(tpacpi_pdev
);
9016 printk(TPACPI_ERR
"unable to register platform device\n");
9017 thinkpad_acpi_module_exit();
9020 tpacpi_sensors_pdev
= platform_device_register_simple(
9021 TPACPI_HWMON_DRVR_NAME
,
9023 if (IS_ERR(tpacpi_sensors_pdev
)) {
9024 ret
= PTR_ERR(tpacpi_sensors_pdev
);
9025 tpacpi_sensors_pdev
= NULL
;
9027 "unable to register hwmon platform device\n");
9028 thinkpad_acpi_module_exit();
9031 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
9032 &dev_attr_thinkpad_acpi_pdev_name
);
9035 "unable to create sysfs hwmon device attributes\n");
9036 thinkpad_acpi_module_exit();
9039 tp_features
.sensors_pdev_attrs_registered
= 1;
9040 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
9041 if (IS_ERR(tpacpi_hwmon
)) {
9042 ret
= PTR_ERR(tpacpi_hwmon
);
9043 tpacpi_hwmon
= NULL
;
9044 printk(TPACPI_ERR
"unable to register hwmon device\n");
9045 thinkpad_acpi_module_exit();
9048 mutex_init(&tpacpi_inputdev_send_mutex
);
9049 tpacpi_inputdev
= input_allocate_device();
9050 if (!tpacpi_inputdev
) {
9051 printk(TPACPI_ERR
"unable to allocate input device\n");
9052 thinkpad_acpi_module_exit();
9055 /* Prepare input device, but don't register */
9056 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
9057 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
9058 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
9059 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
9060 thinkpad_id
.vendor
:
9062 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
9063 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
9064 tpacpi_inputdev
->dev
.parent
= &tpacpi_pdev
->dev
;
9066 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
9067 ret
= ibm_init(&ibms_init
[i
]);
9068 if (ret
>= 0 && *ibms_init
[i
].param
)
9069 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
9071 thinkpad_acpi_module_exit();
9076 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
9078 ret
= input_register_device(tpacpi_inputdev
);
9080 printk(TPACPI_ERR
"unable to register input device\n");
9081 thinkpad_acpi_module_exit();
9084 tp_features
.input_device_registered
= 1;
9090 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
9093 * This will autoload the driver in almost every ThinkPad
9094 * in widespread use.
9096 * Only _VERY_ old models, like the 240, 240x and 570 lack
9097 * the HKEY event interface.
9099 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
9102 * DMI matching for module autoloading
9104 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
9105 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
9107 * Only models listed in thinkwiki will be supported, so add yours
9108 * if it is not there yet.
9110 #define IBM_BIOS_MODULE_ALIAS(__type) \
9111 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
9113 /* Ancient thinkpad BIOSes have to be identified by
9114 * BIOS type or model number, and there are far less
9115 * BIOS types than model numbers... */
9116 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
9118 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
9119 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
9120 MODULE_DESCRIPTION(TPACPI_DESC
);
9121 MODULE_VERSION(TPACPI_VERSION
);
9122 MODULE_LICENSE("GPL");
9124 module_init(thinkpad_acpi_module_init
);
9125 module_exit(thinkpad_acpi_module_exit
);