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_IBM_HKEY_HID "IBM0068"
126 #define TPACPI_ACPI_LENOVO_HKEY_HID "LEN0068"
127 #define TPACPI_ACPI_EC_HID "PNP0C09"
130 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
131 #define TPACPI_HKEY_INPUT_VERSION 0x4101
133 /* ACPI \WGSV commands */
135 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
136 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
137 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
138 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
141 /* TP_ACPI_WGSV_GET_STATE bits */
143 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
144 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
145 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
146 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
147 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
148 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
149 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
150 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
151 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
152 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
156 enum tpacpi_hkey_event_t
{
158 TP_HKEY_EV_HOTKEY_BASE
= 0x1001, /* first hotkey (FN+F1) */
159 TP_HKEY_EV_BRGHT_UP
= 0x1010, /* Brightness up */
160 TP_HKEY_EV_BRGHT_DOWN
= 0x1011, /* Brightness down */
161 TP_HKEY_EV_VOL_UP
= 0x1015, /* Volume up or unmute */
162 TP_HKEY_EV_VOL_DOWN
= 0x1016, /* Volume down or unmute */
163 TP_HKEY_EV_VOL_MUTE
= 0x1017, /* Mixer output mute */
165 /* Reasons for waking up from S3/S4 */
166 TP_HKEY_EV_WKUP_S3_UNDOCK
= 0x2304, /* undock requested, S3 */
167 TP_HKEY_EV_WKUP_S4_UNDOCK
= 0x2404, /* undock requested, S4 */
168 TP_HKEY_EV_WKUP_S3_BAYEJ
= 0x2305, /* bay ejection req, S3 */
169 TP_HKEY_EV_WKUP_S4_BAYEJ
= 0x2405, /* bay ejection req, S4 */
170 TP_HKEY_EV_WKUP_S3_BATLOW
= 0x2313, /* battery empty, S3 */
171 TP_HKEY_EV_WKUP_S4_BATLOW
= 0x2413, /* battery empty, S4 */
173 /* Auto-sleep after eject request */
174 TP_HKEY_EV_BAYEJ_ACK
= 0x3003, /* bay ejection complete */
175 TP_HKEY_EV_UNDOCK_ACK
= 0x4003, /* undock complete */
177 /* Misc bay events */
178 TP_HKEY_EV_OPTDRV_EJ
= 0x3006, /* opt. drive tray ejected */
180 /* User-interface events */
181 TP_HKEY_EV_LID_CLOSE
= 0x5001, /* laptop lid closed */
182 TP_HKEY_EV_LID_OPEN
= 0x5002, /* laptop lid opened */
183 TP_HKEY_EV_TABLET_TABLET
= 0x5009, /* tablet swivel up */
184 TP_HKEY_EV_TABLET_NOTEBOOK
= 0x500a, /* tablet swivel down */
185 TP_HKEY_EV_PEN_INSERTED
= 0x500b, /* tablet pen inserted */
186 TP_HKEY_EV_PEN_REMOVED
= 0x500c, /* tablet pen removed */
187 TP_HKEY_EV_BRGHT_CHANGED
= 0x5010, /* backlight control event */
190 TP_HKEY_EV_ALARM_BAT_HOT
= 0x6011, /* battery too hot */
191 TP_HKEY_EV_ALARM_BAT_XHOT
= 0x6012, /* battery critically hot */
192 TP_HKEY_EV_ALARM_SENSOR_HOT
= 0x6021, /* sensor too hot */
193 TP_HKEY_EV_ALARM_SENSOR_XHOT
= 0x6022, /* sensor critically hot */
194 TP_HKEY_EV_THM_TABLE_CHANGED
= 0x6030, /* thermal table changed */
197 TP_HKEY_EV_RFKILL_CHANGED
= 0x7000, /* rfkill switch changed */
200 /****************************************************************************
204 #define TPACPI_NAME "thinkpad"
205 #define TPACPI_DESC "ThinkPad ACPI Extras"
206 #define TPACPI_FILE TPACPI_NAME "_acpi"
207 #define TPACPI_URL "http://ibm-acpi.sf.net/"
208 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
210 #define TPACPI_PROC_DIR "ibm"
211 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
212 #define TPACPI_DRVR_NAME TPACPI_FILE
213 #define TPACPI_DRVR_SHORTNAME "tpacpi"
214 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
216 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
217 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
219 #define TPACPI_MAX_ACPI_ARGS 3
222 #define TPACPI_LOG TPACPI_FILE ": "
223 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
224 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
225 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
226 #define TPACPI_ERR KERN_ERR TPACPI_LOG
227 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
228 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
229 #define TPACPI_INFO KERN_INFO TPACPI_LOG
230 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
232 /* Debugging printk groups */
233 #define TPACPI_DBG_ALL 0xffff
234 #define TPACPI_DBG_DISCLOSETASK 0x8000
235 #define TPACPI_DBG_INIT 0x0001
236 #define TPACPI_DBG_EXIT 0x0002
237 #define TPACPI_DBG_RFKILL 0x0004
238 #define TPACPI_DBG_HKEY 0x0008
239 #define TPACPI_DBG_FAN 0x0010
240 #define TPACPI_DBG_BRGHT 0x0020
241 #define TPACPI_DBG_MIXER 0x0040
243 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
244 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
245 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
248 /****************************************************************************
249 * Driver-wide structs and misc. variables
254 struct tp_acpi_drv_struct
{
255 const struct acpi_device_id
*hid
;
256 struct acpi_driver
*driver
;
258 void (*notify
) (struct ibm_struct
*, u32
);
261 struct acpi_device
*device
;
267 int (*read
) (struct seq_file
*);
268 int (*write
) (char *);
270 void (*resume
) (void);
271 void (*suspend
) (pm_message_t state
);
272 void (*shutdown
) (void);
274 struct list_head all_drivers
;
276 struct tp_acpi_drv_struct
*acpi
;
279 u8 acpi_driver_registered
:1;
280 u8 acpi_notify_installed
:1;
287 struct ibm_init_struct
{
290 int (*init
) (struct ibm_init_struct
*);
291 mode_t base_procfs_mode
;
292 struct ibm_struct
*data
;
303 u32 bright_16levels
:1;
304 u32 bright_acpimode
:1;
307 u32 fan_ctrl_status_undef
:1;
309 u32 beep_needs_two_args
:1;
310 u32 mixer_no_level_control
:1;
311 u32 input_device_registered
:1;
312 u32 platform_drv_registered
:1;
313 u32 platform_drv_attrs_registered
:1;
314 u32 sensors_pdrv_registered
:1;
315 u32 sensors_pdrv_attrs_registered
:1;
316 u32 sensors_pdev_attrs_registered
:1;
317 u32 hotkey_poll_active
:1;
321 u16 hotkey_mask_ff
:1;
322 u16 volume_ctrl_forbidden
:1;
325 struct thinkpad_id_data
{
326 unsigned int vendor
; /* ThinkPad vendor:
327 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
329 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
330 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
332 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
334 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
337 char *model_str
; /* ThinkPad T43 */
338 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
340 static struct thinkpad_id_data thinkpad_id
;
343 TPACPI_LIFE_INIT
= 0,
348 static int experimental
;
349 static u32 dbg_level
;
351 static struct workqueue_struct
*tpacpi_wq
;
359 /* Special LED class that can defer work */
360 struct tpacpi_led_classdev
{
361 struct led_classdev led_classdev
;
362 struct work_struct work
;
363 enum led_status_t new_state
;
367 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
368 static int dbg_wlswemul
;
369 static int tpacpi_wlsw_emulstate
;
370 static int dbg_bluetoothemul
;
371 static int tpacpi_bluetooth_emulstate
;
372 static int dbg_wwanemul
;
373 static int tpacpi_wwan_emulstate
;
374 static int dbg_uwbemul
;
375 static int tpacpi_uwb_emulstate
;
379 /*************************************************************************
383 #define dbg_printk(a_dbg_level, format, arg...) \
384 do { if (dbg_level & (a_dbg_level)) \
385 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
388 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
389 #define vdbg_printk dbg_printk
390 static const char *str_supported(int is_supported
);
392 #define vdbg_printk(a_dbg_level, format, arg...) \
396 static void tpacpi_log_usertask(const char * const what
)
398 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
399 what
, task_tgid_vnr(current
));
402 #define tpacpi_disclose_usertask(what, format, arg...) \
405 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
406 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
407 printk(TPACPI_DEBUG "%s: PID %d: " format, \
408 what, task_tgid_vnr(current), ## arg); \
413 * Quirk handling helpers
415 * ThinkPad IDs and versions seen in the field so far
416 * are two-characters from the set [0-9A-Z], i.e. base 36.
418 * We use values well outside that range as specials.
421 #define TPACPI_MATCH_ANY 0xffffU
422 #define TPACPI_MATCH_UNKNOWN 0U
424 /* TPID('1', 'Y') == 0x5931 */
425 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
427 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
428 { .vendor = PCI_VENDOR_ID_IBM, \
429 .bios = TPID(__id1, __id2), \
430 .ec = TPACPI_MATCH_ANY, \
431 .quirks = (__quirk) }
433 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
434 { .vendor = PCI_VENDOR_ID_LENOVO, \
435 .bios = TPID(__id1, __id2), \
436 .ec = TPACPI_MATCH_ANY, \
437 .quirks = (__quirk) }
439 #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \
440 { .vendor = PCI_VENDOR_ID_LENOVO, \
441 .bios = TPACPI_MATCH_ANY, \
442 .ec = TPID(__id1, __id2), \
443 .quirks = (__quirk) }
445 struct tpacpi_quirk
{
449 unsigned long quirks
;
453 * tpacpi_check_quirks() - search BIOS/EC version on a list
454 * @qlist: array of &struct tpacpi_quirk
455 * @qlist_size: number of elements in @qlist
457 * Iterates over a quirks list until one is found that matches the
458 * ThinkPad's vendor, BIOS and EC model.
460 * Returns 0 if nothing matches, otherwise returns the quirks field of
461 * the matching &struct tpacpi_quirk entry.
463 * The match criteria is: vendor, ec and bios much match.
465 static unsigned long __init
tpacpi_check_quirks(
466 const struct tpacpi_quirk
*qlist
,
467 unsigned int qlist_size
)
470 if ((qlist
->vendor
== thinkpad_id
.vendor
||
471 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
472 (qlist
->bios
== thinkpad_id
.bios_model
||
473 qlist
->bios
== TPACPI_MATCH_ANY
) &&
474 (qlist
->ec
== thinkpad_id
.ec_model
||
475 qlist
->ec
== TPACPI_MATCH_ANY
))
476 return qlist
->quirks
;
485 /****************************************************************************
486 ****************************************************************************
488 * ACPI Helpers and device model
490 ****************************************************************************
491 ****************************************************************************/
493 /*************************************************************************
497 static acpi_handle root_handle
;
499 #define TPACPI_HANDLE(object, parent, paths...) \
500 static acpi_handle object##_handle; \
501 static acpi_handle *object##_parent = &parent##_handle; \
502 static char *object##_path; \
503 static char *object##_paths[] = { paths }
505 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
506 "\\_SB.PCI.ISA.EC", /* 570 */
507 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
508 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
509 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
510 "\\_SB.PCI0.ICH3.EC0", /* R31 */
511 "\\_SB.PCI0.LPC.EC", /* all others */
514 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
515 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
517 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
519 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
520 "\\CMS", /* R40, R40e */
523 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
524 "^HKEY", /* R30, R31 */
525 "HKEY", /* all others */
528 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
529 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
530 "\\_SB.PCI0.VID0", /* 770e */
531 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
532 "\\_SB.PCI0.AGP.VID", /* all others */
536 /*************************************************************************
540 static int acpi_evalf(acpi_handle handle
,
541 void *res
, char *method
, char *fmt
, ...)
544 struct acpi_object_list params
;
545 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
546 struct acpi_buffer result
, *resultp
;
547 union acpi_object out_obj
;
555 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
568 params
.pointer
= &in_objs
[0];
575 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
576 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
578 /* add more types as needed */
580 printk(TPACPI_ERR
"acpi_evalf() called "
581 "with invalid format character '%c'\n", c
);
587 if (res_type
!= 'v') {
588 result
.length
= sizeof(out_obj
);
589 result
.pointer
= &out_obj
;
594 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
599 *(int *)res
= out_obj
.integer
.value
;
600 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
603 success
= status
== AE_OK
;
605 /* add more types as needed */
607 printk(TPACPI_ERR
"acpi_evalf() called "
608 "with invalid format character '%c'\n", res_type
);
612 if (!success
&& !quiet
)
613 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
614 method
, fmt0
, status
);
619 static int acpi_ec_read(int i
, u8
*p
)
624 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
628 if (ec_read(i
, p
) < 0)
635 static int acpi_ec_write(int i
, u8 v
)
638 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
641 if (ec_write(i
, v
) < 0)
648 static int issue_thinkpad_cmos_command(int cmos_cmd
)
653 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
659 /*************************************************************************
663 #define TPACPI_ACPIHANDLE_INIT(object) \
664 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
665 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
667 static void drv_acpi_handle_init(char *name
,
668 acpi_handle
*handle
, acpi_handle parent
,
669 char **paths
, int num_paths
, char **path
)
674 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
677 for (i
= 0; i
< num_paths
; i
++) {
678 status
= acpi_get_handle(parent
, paths
[i
], handle
);
679 if (ACPI_SUCCESS(status
)) {
681 dbg_printk(TPACPI_DBG_INIT
,
682 "Found ACPI handle %s for %s\n",
688 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
693 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
695 struct ibm_struct
*ibm
= data
;
697 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
700 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
703 ibm
->acpi
->notify(ibm
, event
);
706 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
713 if (!*ibm
->acpi
->handle
)
716 vdbg_printk(TPACPI_DBG_INIT
,
717 "setting up ACPI notify for %s\n", ibm
->name
);
719 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
721 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
726 ibm
->acpi
->device
->driver_data
= ibm
;
727 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
728 TPACPI_ACPI_EVENT_PREFIX
,
731 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
732 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
733 if (ACPI_FAILURE(status
)) {
734 if (status
== AE_ALREADY_EXISTS
) {
736 "another device driver is already "
737 "handling %s events\n", ibm
->name
);
740 "acpi_install_notify_handler(%s) failed: %d\n",
745 ibm
->flags
.acpi_notify_installed
= 1;
749 static int __init
tpacpi_device_add(struct acpi_device
*device
)
754 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
758 dbg_printk(TPACPI_DBG_INIT
,
759 "registering %s as an ACPI driver\n", ibm
->name
);
763 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
764 if (!ibm
->acpi
->driver
) {
766 "failed to allocate memory for ibm->acpi->driver\n");
770 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
771 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
773 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
775 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
777 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
779 kfree(ibm
->acpi
->driver
);
780 ibm
->acpi
->driver
= NULL
;
782 ibm
->flags
.acpi_driver_registered
= 1;
788 /****************************************************************************
789 ****************************************************************************
793 ****************************************************************************
794 ****************************************************************************/
796 static int dispatch_proc_show(struct seq_file
*m
, void *v
)
798 struct ibm_struct
*ibm
= m
->private;
800 if (!ibm
|| !ibm
->read
)
805 static int dispatch_proc_open(struct inode
*inode
, struct file
*file
)
807 return single_open(file
, dispatch_proc_show
, PDE(inode
)->data
);
810 static ssize_t
dispatch_proc_write(struct file
*file
,
811 const char __user
*userbuf
,
812 size_t count
, loff_t
*pos
)
814 struct ibm_struct
*ibm
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
818 if (!ibm
|| !ibm
->write
)
820 if (count
> PAGE_SIZE
- 2)
823 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
827 if (copy_from_user(kernbuf
, userbuf
, count
)) {
833 strcat(kernbuf
, ",");
834 ret
= ibm
->write(kernbuf
);
843 static const struct file_operations dispatch_proc_fops
= {
844 .owner
= THIS_MODULE
,
845 .open
= dispatch_proc_open
,
848 .release
= single_release
,
849 .write
= dispatch_proc_write
,
852 static char *next_cmd(char **cmds
)
857 while ((end
= strchr(start
, ',')) && end
== start
)
869 /****************************************************************************
870 ****************************************************************************
872 * Device model: input, hwmon and platform
874 ****************************************************************************
875 ****************************************************************************/
877 static struct platform_device
*tpacpi_pdev
;
878 static struct platform_device
*tpacpi_sensors_pdev
;
879 static struct device
*tpacpi_hwmon
;
880 static struct input_dev
*tpacpi_inputdev
;
881 static struct mutex tpacpi_inputdev_send_mutex
;
882 static LIST_HEAD(tpacpi_all_drivers
);
884 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
887 struct ibm_struct
*ibm
, *itmp
;
889 list_for_each_entry_safe(ibm
, itmp
,
893 (ibm
->suspend
)(state
);
899 static int tpacpi_resume_handler(struct platform_device
*pdev
)
901 struct ibm_struct
*ibm
, *itmp
;
903 list_for_each_entry_safe(ibm
, itmp
,
913 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
915 struct ibm_struct
*ibm
, *itmp
;
917 list_for_each_entry_safe(ibm
, itmp
,
925 static struct platform_driver tpacpi_pdriver
= {
927 .name
= TPACPI_DRVR_NAME
,
928 .owner
= THIS_MODULE
,
930 .suspend
= tpacpi_suspend_handler
,
931 .resume
= tpacpi_resume_handler
,
932 .shutdown
= tpacpi_shutdown_handler
,
935 static struct platform_driver tpacpi_hwmon_pdriver
= {
937 .name
= TPACPI_HWMON_DRVR_NAME
,
938 .owner
= THIS_MODULE
,
942 /*************************************************************************
943 * sysfs support helpers
946 struct attribute_set
{
947 unsigned int members
, max_members
;
948 struct attribute_group group
;
951 struct attribute_set_obj
{
952 struct attribute_set s
;
954 } __attribute__((packed
));
956 static struct attribute_set
*create_attr_set(unsigned int max_members
,
959 struct attribute_set_obj
*sobj
;
961 if (max_members
== 0)
964 /* Allocates space for implicit NULL at the end too */
965 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
966 max_members
* sizeof(struct attribute
*),
970 sobj
->s
.max_members
= max_members
;
971 sobj
->s
.group
.attrs
= &sobj
->a
;
972 sobj
->s
.group
.name
= name
;
977 #define destroy_attr_set(_set) \
980 /* not multi-threaded safe, use it in a single thread per set */
981 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
986 if (s
->members
>= s
->max_members
)
989 s
->group
.attrs
[s
->members
] = attr
;
995 static int add_many_to_attr_set(struct attribute_set
*s
,
996 struct attribute
**attr
,
1001 for (i
= 0; i
< count
; i
++) {
1002 res
= add_to_attr_set(s
, attr
[i
]);
1010 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
1012 sysfs_remove_group(kobj
, &s
->group
);
1013 destroy_attr_set(s
);
1016 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
1017 sysfs_create_group(_kobj, &_attr_set->group)
1019 static int parse_strtoul(const char *buf
,
1020 unsigned long max
, unsigned long *value
)
1024 while (*buf
&& isspace(*buf
))
1026 *value
= simple_strtoul(buf
, &endp
, 0);
1027 while (*endp
&& isspace(*endp
))
1029 if (*endp
|| *value
> max
)
1035 static void tpacpi_disable_brightness_delay(void)
1037 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
1038 printk(TPACPI_NOTICE
1039 "ACPI backlight control delay disabled\n");
1042 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
1044 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1045 union acpi_object
*obj
;
1048 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
1049 obj
= (union acpi_object
*)buffer
.pointer
;
1050 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
1051 printk(TPACPI_ERR
"Unknown _BCL data, "
1052 "please report this to %s\n", TPACPI_MAIL
);
1055 rc
= obj
->package
.count
;
1061 kfree(buffer
.pointer
);
1065 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1066 u32 lvl
, void *context
, void **rv
)
1068 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1069 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1071 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1072 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1073 BUG_ON(!rv
|| !*rv
);
1074 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1075 return AE_CTRL_TERMINATE
;
1082 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1084 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1088 void *bcl_ptr
= &bcl_levels
;
1091 TPACPI_ACPIHANDLE_INIT(vid
);
1097 * Search for a _BCL method, and execute it. This is safe on all
1098 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1099 * BIOS in ACPI backlight control mode. We do NOT have to care
1100 * about calling the _BCL method in an enabled video device, any
1101 * will do for our purposes.
1104 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1105 tpacpi_acpi_walk_find_bcl
, NULL
,
1108 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1109 tp_features
.bright_acpimode
= 1;
1110 return (bcl_levels
- 2);
1116 static void printk_deprecated_attribute(const char * const what
,
1117 const char * const details
)
1119 tpacpi_log_usertask("deprecated sysfs attribute");
1120 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1121 "will be removed. %s\n",
1125 /*************************************************************************
1126 * rfkill and radio control support helpers
1130 * ThinkPad-ACPI firmware handling model:
1132 * WLSW (master wireless switch) is event-driven, and is common to all
1133 * firmware-controlled radios. It cannot be controlled, just monitored,
1134 * as expected. It overrides all radio state in firmware
1136 * The kernel, a masked-off hotkey, and WLSW can change the radio state
1137 * (TODO: verify how WLSW interacts with the returned radio state).
1139 * The only time there are shadow radio state changes, is when
1140 * masked-off hotkeys are used.
1144 * Internal driver API for radio state:
1146 * int: < 0 = error, otherwise enum tpacpi_rfkill_state
1147 * bool: true means radio blocked (off)
1149 enum tpacpi_rfkill_state
{
1150 TPACPI_RFK_RADIO_OFF
= 0,
1154 /* rfkill switches */
1155 enum tpacpi_rfk_id
{
1156 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
1157 TPACPI_RFK_WWAN_SW_ID
,
1158 TPACPI_RFK_UWB_SW_ID
,
1162 static const char *tpacpi_rfkill_names
[] = {
1163 [TPACPI_RFK_BLUETOOTH_SW_ID
] = "bluetooth",
1164 [TPACPI_RFK_WWAN_SW_ID
] = "wwan",
1165 [TPACPI_RFK_UWB_SW_ID
] = "uwb",
1166 [TPACPI_RFK_SW_MAX
] = NULL
1169 /* ThinkPad-ACPI rfkill subdriver */
1171 struct rfkill
*rfkill
;
1172 enum tpacpi_rfk_id id
;
1173 const struct tpacpi_rfk_ops
*ops
;
1176 struct tpacpi_rfk_ops
{
1177 /* firmware interface */
1178 int (*get_status
)(void);
1179 int (*set_status
)(const enum tpacpi_rfkill_state
);
1182 static struct tpacpi_rfk
*tpacpi_rfkill_switches
[TPACPI_RFK_SW_MAX
];
1184 /* Query FW and update rfkill sw state for a given rfkill switch */
1185 static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk
*tp_rfk
)
1192 status
= (tp_rfk
->ops
->get_status
)();
1196 rfkill_set_sw_state(tp_rfk
->rfkill
,
1197 (status
== TPACPI_RFK_RADIO_OFF
));
1202 /* Query FW and update rfkill sw state for all rfkill switches */
1203 static void tpacpi_rfk_update_swstate_all(void)
1207 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++)
1208 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[i
]);
1212 * Sync the HW-blocking state of all rfkill switches,
1213 * do notice it causes the rfkill core to schedule uevents
1215 static void tpacpi_rfk_update_hwblock_state(bool blocked
)
1218 struct tpacpi_rfk
*tp_rfk
;
1220 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++) {
1221 tp_rfk
= tpacpi_rfkill_switches
[i
];
1223 if (rfkill_set_hw_state(tp_rfk
->rfkill
,
1225 /* ignore -- we track sw block */
1231 /* Call to get the WLSW state from the firmware */
1232 static int hotkey_get_wlsw(void);
1234 /* Call to query WLSW state and update all rfkill switches */
1235 static bool tpacpi_rfk_check_hwblock_state(void)
1237 int res
= hotkey_get_wlsw();
1240 /* When unknown or unsupported, we have to assume it is unblocked */
1244 hw_blocked
= (res
== TPACPI_RFK_RADIO_OFF
);
1245 tpacpi_rfk_update_hwblock_state(hw_blocked
);
1250 static int tpacpi_rfk_hook_set_block(void *data
, bool blocked
)
1252 struct tpacpi_rfk
*tp_rfk
= data
;
1255 dbg_printk(TPACPI_DBG_RFKILL
,
1256 "request to change radio state to %s\n",
1257 blocked
? "blocked" : "unblocked");
1259 /* try to set radio state */
1260 res
= (tp_rfk
->ops
->set_status
)(blocked
?
1261 TPACPI_RFK_RADIO_OFF
: TPACPI_RFK_RADIO_ON
);
1263 /* and update the rfkill core with whatever the FW really did */
1264 tpacpi_rfk_update_swstate(tp_rfk
);
1266 return (res
< 0) ? res
: 0;
1269 static const struct rfkill_ops tpacpi_rfk_rfkill_ops
= {
1270 .set_block
= tpacpi_rfk_hook_set_block
,
1273 static int __init
tpacpi_new_rfkill(const enum tpacpi_rfk_id id
,
1274 const struct tpacpi_rfk_ops
*tp_rfkops
,
1275 const enum rfkill_type rfktype
,
1277 const bool set_default
)
1279 struct tpacpi_rfk
*atp_rfk
;
1281 bool sw_state
= false;
1285 BUG_ON(id
>= TPACPI_RFK_SW_MAX
|| tpacpi_rfkill_switches
[id
]);
1287 atp_rfk
= kzalloc(sizeof(struct tpacpi_rfk
), GFP_KERNEL
);
1289 atp_rfk
->rfkill
= rfkill_alloc(name
,
1292 &tpacpi_rfk_rfkill_ops
,
1294 if (!atp_rfk
|| !atp_rfk
->rfkill
) {
1296 "failed to allocate memory for rfkill class\n");
1302 atp_rfk
->ops
= tp_rfkops
;
1304 sw_status
= (tp_rfkops
->get_status
)();
1305 if (sw_status
< 0) {
1307 "failed to read initial state for %s, error %d\n",
1310 sw_state
= (sw_status
== TPACPI_RFK_RADIO_OFF
);
1312 /* try to keep the initial state, since we ask the
1313 * firmware to preserve it across S5 in NVRAM */
1314 rfkill_init_sw_state(atp_rfk
->rfkill
, sw_state
);
1317 hw_state
= tpacpi_rfk_check_hwblock_state();
1318 rfkill_set_hw_state(atp_rfk
->rfkill
, hw_state
);
1320 res
= rfkill_register(atp_rfk
->rfkill
);
1323 "failed to register %s rfkill switch: %d\n",
1325 rfkill_destroy(atp_rfk
->rfkill
);
1330 tpacpi_rfkill_switches
[id
] = atp_rfk
;
1332 printk(TPACPI_INFO
"rfkill switch %s: radio is %sblocked\n",
1333 name
, (sw_state
|| hw_state
) ? "" : "un");
1337 static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id
)
1339 struct tpacpi_rfk
*tp_rfk
;
1341 BUG_ON(id
>= TPACPI_RFK_SW_MAX
);
1343 tp_rfk
= tpacpi_rfkill_switches
[id
];
1345 rfkill_unregister(tp_rfk
->rfkill
);
1346 rfkill_destroy(tp_rfk
->rfkill
);
1347 tpacpi_rfkill_switches
[id
] = NULL
;
1352 static void printk_deprecated_rfkill_attribute(const char * const what
)
1354 printk_deprecated_attribute(what
,
1355 "Please switch to generic rfkill before year 2010");
1358 /* sysfs <radio> enable ------------------------------------------------ */
1359 static ssize_t
tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id
,
1360 struct device_attribute
*attr
,
1365 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1367 /* This is in the ABI... */
1368 if (tpacpi_rfk_check_hwblock_state()) {
1369 status
= TPACPI_RFK_RADIO_OFF
;
1371 status
= tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1376 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1377 (status
== TPACPI_RFK_RADIO_ON
) ? 1 : 0);
1380 static ssize_t
tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id
,
1381 struct device_attribute
*attr
,
1382 const char *buf
, size_t count
)
1387 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1389 if (parse_strtoul(buf
, 1, &t
))
1392 tpacpi_disclose_usertask(attr
->attr
.name
, "set to %ld\n", t
);
1394 /* This is in the ABI... */
1395 if (tpacpi_rfk_check_hwblock_state() && !!t
)
1398 res
= tpacpi_rfkill_switches
[id
]->ops
->set_status((!!t
) ?
1399 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
);
1400 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1402 return (res
< 0) ? res
: count
;
1405 /* procfs -------------------------------------------------------------- */
1406 static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id
,
1409 if (id
>= TPACPI_RFK_SW_MAX
)
1410 seq_printf(m
, "status:\t\tnot supported\n");
1414 /* This is in the ABI... */
1415 if (tpacpi_rfk_check_hwblock_state()) {
1416 status
= TPACPI_RFK_RADIO_OFF
;
1418 status
= tpacpi_rfk_update_swstate(
1419 tpacpi_rfkill_switches
[id
]);
1424 seq_printf(m
, "status:\t\t%s\n",
1425 (status
== TPACPI_RFK_RADIO_ON
) ?
1426 "enabled" : "disabled");
1427 seq_printf(m
, "commands:\tenable, disable\n");
1433 static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id
, char *buf
)
1439 if (id
>= TPACPI_RFK_SW_MAX
)
1442 while ((cmd
= next_cmd(&buf
))) {
1443 if (strlencmp(cmd
, "enable") == 0)
1444 status
= TPACPI_RFK_RADIO_ON
;
1445 else if (strlencmp(cmd
, "disable") == 0)
1446 status
= TPACPI_RFK_RADIO_OFF
;
1452 tpacpi_disclose_usertask("procfs", "attempt to %s %s\n",
1453 (status
== TPACPI_RFK_RADIO_ON
) ?
1454 "enable" : "disable",
1455 tpacpi_rfkill_names
[id
]);
1456 res
= (tpacpi_rfkill_switches
[id
]->ops
->set_status
)(status
);
1457 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1463 /*************************************************************************
1464 * thinkpad-acpi driver attributes
1467 /* interface_version --------------------------------------------------- */
1468 static ssize_t
tpacpi_driver_interface_version_show(
1469 struct device_driver
*drv
,
1472 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1475 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1476 tpacpi_driver_interface_version_show
, NULL
);
1478 /* debug_level --------------------------------------------------------- */
1479 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1482 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1485 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1486 const char *buf
, size_t count
)
1490 if (parse_strtoul(buf
, 0xffff, &t
))
1498 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1499 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1501 /* version ------------------------------------------------------------- */
1502 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1505 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1506 TPACPI_DESC
, TPACPI_VERSION
);
1509 static DRIVER_ATTR(version
, S_IRUGO
,
1510 tpacpi_driver_version_show
, NULL
);
1512 /* --------------------------------------------------------------------- */
1514 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1516 /* wlsw_emulstate ------------------------------------------------------ */
1517 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1520 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1523 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1524 const char *buf
, size_t count
)
1528 if (parse_strtoul(buf
, 1, &t
))
1531 if (tpacpi_wlsw_emulstate
!= !!t
) {
1532 tpacpi_wlsw_emulstate
= !!t
;
1533 tpacpi_rfk_update_hwblock_state(!t
); /* negative logic */
1539 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1540 tpacpi_driver_wlsw_emulstate_show
,
1541 tpacpi_driver_wlsw_emulstate_store
);
1543 /* bluetooth_emulstate ------------------------------------------------- */
1544 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1545 struct device_driver
*drv
,
1548 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1551 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1552 struct device_driver
*drv
,
1553 const char *buf
, size_t count
)
1557 if (parse_strtoul(buf
, 1, &t
))
1560 tpacpi_bluetooth_emulstate
= !!t
;
1565 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1566 tpacpi_driver_bluetooth_emulstate_show
,
1567 tpacpi_driver_bluetooth_emulstate_store
);
1569 /* wwan_emulstate ------------------------------------------------- */
1570 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1571 struct device_driver
*drv
,
1574 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1577 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1578 struct device_driver
*drv
,
1579 const char *buf
, size_t count
)
1583 if (parse_strtoul(buf
, 1, &t
))
1586 tpacpi_wwan_emulstate
= !!t
;
1591 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1592 tpacpi_driver_wwan_emulstate_show
,
1593 tpacpi_driver_wwan_emulstate_store
);
1595 /* uwb_emulstate ------------------------------------------------- */
1596 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1597 struct device_driver
*drv
,
1600 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1603 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1604 struct device_driver
*drv
,
1605 const char *buf
, size_t count
)
1609 if (parse_strtoul(buf
, 1, &t
))
1612 tpacpi_uwb_emulstate
= !!t
;
1617 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1618 tpacpi_driver_uwb_emulstate_show
,
1619 tpacpi_driver_uwb_emulstate_store
);
1622 /* --------------------------------------------------------------------- */
1624 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1625 &driver_attr_debug_level
, &driver_attr_version
,
1626 &driver_attr_interface_version
,
1629 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1635 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1636 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1640 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1641 if (!res
&& dbg_wlswemul
)
1642 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1643 if (!res
&& dbg_bluetoothemul
)
1644 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1645 if (!res
&& dbg_wwanemul
)
1646 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1647 if (!res
&& dbg_uwbemul
)
1648 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1654 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1658 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1659 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1661 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1662 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1663 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1664 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1665 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1669 /*************************************************************************
1674 * Table of recommended minimum BIOS versions
1676 * Reasons for listing:
1677 * 1. Stable BIOS, listed because the unknown ammount of
1678 * bugs and bad ACPI behaviour on older versions
1680 * 2. BIOS or EC fw with known bugs that trigger on Linux
1682 * 3. BIOS with known reduced functionality in older versions
1684 * We recommend the latest BIOS and EC version.
1685 * We only support the latest BIOS and EC fw version as a rule.
1687 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1688 * Information from users in ThinkWiki
1690 * WARNING: we use this table also to detect that the machine is
1691 * a ThinkPad in some cases, so don't remove entries lightly.
1694 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1695 { .vendor = (__v), \
1696 .bios = TPID(__id1, __id2), \
1697 .ec = TPACPI_MATCH_ANY, \
1698 .quirks = TPACPI_MATCH_ANY << 16 \
1699 | (__bv1) << 8 | (__bv2) }
1701 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1702 __eid, __ev1, __ev2) \
1703 { .vendor = (__v), \
1704 .bios = TPID(__bid1, __bid2), \
1706 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1707 | (__bv1) << 8 | (__bv2) }
1709 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1710 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1712 /* Outdated IBM BIOSes often lack the EC id string */
1713 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1714 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1715 __bv1, __bv2, TPID(__id1, __id2), \
1717 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1718 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1721 /* Outdated IBM BIOSes often lack the EC id string */
1722 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1723 __eid1, __eid2, __ev1, __ev2) \
1724 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1725 __bv1, __bv2, TPID(__eid1, __eid2), \
1727 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1728 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1731 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1732 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1734 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1735 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1736 __bv1, __bv2, TPID(__id1, __id2), \
1739 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1740 __eid1, __eid2, __ev1, __ev2) \
1741 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1742 __bv1, __bv2, TPID(__eid1, __eid2), \
1745 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1746 /* Numeric models ------------------ */
1747 /* FW MODEL BIOS VERS */
1748 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1749 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1750 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1751 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1752 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1753 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1754 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1755 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1756 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1758 /* A-series ------------------------- */
1759 /* FW MODEL BIOS VERS EC VERS */
1760 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1761 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1762 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1763 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1764 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1765 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1766 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1767 TPV_QI0('1', '3', '2', '0'), /* A22m */
1768 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1769 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1770 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1772 /* G-series ------------------------- */
1773 /* FW MODEL BIOS VERS */
1774 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1775 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1777 /* R-series, T-series --------------- */
1778 /* FW MODEL BIOS VERS EC VERS */
1779 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1780 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1781 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1782 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1783 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1784 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1785 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1786 T40/p, T41/p, T42/p (1) */
1787 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1788 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1789 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1790 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1792 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1793 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1794 TPV_QI0('1', '6', '3', '2'), /* T22 */
1795 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1796 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1797 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1799 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1800 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1801 TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */
1803 /* BIOS FW BIOS VERS EC FW EC VERS */
1804 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1805 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1807 /* X-series ------------------------- */
1808 /* FW MODEL BIOS VERS EC VERS */
1809 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1810 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1811 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1812 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1813 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1814 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1815 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1817 TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */
1818 TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */
1820 /* (0) - older versions lack DMI EC fw string and functionality */
1821 /* (1) - older versions known to lack functionality */
1832 static void __init
tpacpi_check_outdated_fw(void)
1834 unsigned long fwvers
;
1835 u16 ec_version
, bios_version
;
1837 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1838 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1843 bios_version
= fwvers
& 0xffffU
;
1844 ec_version
= (fwvers
>> 16) & 0xffffU
;
1846 /* note that unknown versions are set to 0x0000 and we use that */
1847 if ((bios_version
> thinkpad_id
.bios_release
) ||
1848 (ec_version
> thinkpad_id
.ec_release
&&
1849 ec_version
!= TPACPI_MATCH_ANY
)) {
1851 * The changelogs would let us track down the exact
1852 * reason, but it is just too much of a pain to track
1853 * it. We only list BIOSes that are either really
1854 * broken, or really stable to begin with, so it is
1855 * best if the user upgrades the firmware anyway.
1858 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1860 "WARNING: This firmware may be missing critical bug "
1861 "fixes and/or important features\n");
1865 static bool __init
tpacpi_is_fw_known(void)
1867 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1868 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1871 /****************************************************************************
1872 ****************************************************************************
1876 ****************************************************************************
1877 ****************************************************************************/
1879 /*************************************************************************
1880 * thinkpad-acpi init subdriver
1883 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1885 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1886 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1888 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1889 (thinkpad_id
.bios_version_str
) ?
1890 thinkpad_id
.bios_version_str
: "unknown",
1891 (thinkpad_id
.ec_version_str
) ?
1892 thinkpad_id
.ec_version_str
: "unknown");
1894 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1895 printk(TPACPI_INFO
"%s %s, model %s\n",
1896 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1897 "IBM" : ((thinkpad_id
.vendor
==
1898 PCI_VENDOR_ID_LENOVO
) ?
1899 "Lenovo" : "Unknown vendor"),
1900 thinkpad_id
.model_str
,
1901 (thinkpad_id
.nummodel_str
) ?
1902 thinkpad_id
.nummodel_str
: "unknown");
1904 tpacpi_check_outdated_fw();
1908 static int thinkpad_acpi_driver_read(struct seq_file
*m
)
1910 seq_printf(m
, "driver:\t\t%s\n", TPACPI_DESC
);
1911 seq_printf(m
, "version:\t%s\n", TPACPI_VERSION
);
1915 static struct ibm_struct thinkpad_acpi_driver_data
= {
1917 .read
= thinkpad_acpi_driver_read
,
1920 /*************************************************************************
1925 * ThinkPad firmware event model
1927 * The ThinkPad firmware has two main event interfaces: normal ACPI
1928 * notifications (which follow the ACPI standard), and a private event
1931 * The private event interface also issues events for the hotkeys. As
1932 * the driver gained features, the event handling code ended up being
1933 * built around the hotkey subdriver. This will need to be refactored
1934 * to a more formal event API eventually.
1936 * Some "hotkeys" are actually supposed to be used as event reports,
1937 * such as "brightness has changed", "volume has changed", depending on
1938 * the ThinkPad model and how the firmware is operating.
1940 * Unlike other classes, hotkey-class events have mask/unmask control on
1941 * non-ancient firmware. However, how it behaves changes a lot with the
1942 * firmware model and version.
1945 enum { /* hot key scan codes (derived from ACPI DSDT) */
1946 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1947 TP_ACPI_HOTKEYSCAN_FNF2
,
1948 TP_ACPI_HOTKEYSCAN_FNF3
,
1949 TP_ACPI_HOTKEYSCAN_FNF4
,
1950 TP_ACPI_HOTKEYSCAN_FNF5
,
1951 TP_ACPI_HOTKEYSCAN_FNF6
,
1952 TP_ACPI_HOTKEYSCAN_FNF7
,
1953 TP_ACPI_HOTKEYSCAN_FNF8
,
1954 TP_ACPI_HOTKEYSCAN_FNF9
,
1955 TP_ACPI_HOTKEYSCAN_FNF10
,
1956 TP_ACPI_HOTKEYSCAN_FNF11
,
1957 TP_ACPI_HOTKEYSCAN_FNF12
,
1958 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1959 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1960 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1961 TP_ACPI_HOTKEYSCAN_FNHOME
,
1962 TP_ACPI_HOTKEYSCAN_FNEND
,
1963 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1964 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1965 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1966 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1967 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1968 TP_ACPI_HOTKEYSCAN_MUTE
,
1969 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1972 enum { /* Keys/events available through NVRAM polling */
1973 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1974 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1977 enum { /* Positions of some of the keys in hotkey masks */
1978 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1979 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1980 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1981 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1982 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1983 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1984 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1985 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1986 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1987 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1988 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1991 enum { /* NVRAM to ACPI HKEY group map */
1992 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1993 TP_ACPI_HKEY_ZOOM_MASK
|
1994 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1995 TP_ACPI_HKEY_HIBERNATE_MASK
,
1996 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1997 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1998 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1999 TP_ACPI_HKEY_VOLDWN_MASK
|
2000 TP_ACPI_HKEY_MUTE_MASK
,
2003 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2004 struct tp_nvram_state
{
2005 u16 thinkpad_toggle
:1;
2007 u16 display_toggle
:1;
2008 u16 thinklight_toggle
:1;
2009 u16 hibernate_toggle
:1;
2010 u16 displayexp_toggle
:1;
2011 u16 display_state
:1;
2012 u16 brightness_toggle
:1;
2013 u16 volume_toggle
:1;
2016 u8 brightness_level
;
2020 /* kthread for the hotkey poller */
2021 static struct task_struct
*tpacpi_hotkey_task
;
2023 /* Acquired while the poller kthread is running, use to sync start/stop */
2024 static struct mutex hotkey_thread_mutex
;
2027 * Acquire mutex to write poller control variables as an
2030 * Increment hotkey_config_change when changing them if you
2031 * want the kthread to forget old state.
2033 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2035 static struct mutex hotkey_thread_data_mutex
;
2036 static unsigned int hotkey_config_change
;
2039 * hotkey poller control variables
2041 * Must be atomic or readers will also need to acquire mutex
2043 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2044 * should be used only when the changes need to be taken as
2045 * a block, OR when one needs to force the kthread to forget
2048 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
2049 static unsigned int hotkey_poll_freq
= 10; /* Hz */
2051 #define HOTKEY_CONFIG_CRITICAL_START \
2053 mutex_lock(&hotkey_thread_data_mutex); \
2054 hotkey_config_change++; \
2056 #define HOTKEY_CONFIG_CRITICAL_END \
2057 mutex_unlock(&hotkey_thread_data_mutex);
2059 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2061 #define hotkey_source_mask 0U
2062 #define HOTKEY_CONFIG_CRITICAL_START
2063 #define HOTKEY_CONFIG_CRITICAL_END
2065 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2067 static struct mutex hotkey_mutex
;
2069 static enum { /* Reasons for waking up */
2070 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
2071 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
2072 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
2073 } hotkey_wakeup_reason
;
2075 static int hotkey_autosleep_ack
;
2077 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
2078 static u32 hotkey_all_mask
; /* all events supported in fw */
2079 static u32 hotkey_reserved_mask
; /* events better left disabled */
2080 static u32 hotkey_driver_mask
; /* events needed by the driver */
2081 static u32 hotkey_user_mask
; /* events visible to userspace */
2082 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
2084 static unsigned int hotkey_report_mode
;
2086 static u16
*hotkey_keycode_map
;
2088 static struct attribute_set
*hotkey_dev_attributes
;
2090 static void tpacpi_driver_event(const unsigned int hkey_event
);
2091 static void hotkey_driver_event(const unsigned int scancode
);
2092 static void hotkey_poll_setup(const bool may_warn
);
2094 /* HKEY.MHKG() return bits */
2095 #define TP_HOTKEY_TABLET_MASK (1 << 3)
2097 static int hotkey_get_wlsw(void)
2101 if (!tp_features
.hotkey_wlsw
)
2104 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2106 return (tpacpi_wlsw_emulstate
) ?
2107 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2110 if (!acpi_evalf(hkey_handle
, &status
, "WLSW", "d"))
2113 return (status
) ? TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2116 static int hotkey_get_tablet_mode(int *status
)
2120 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
2123 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
2128 * Reads current event mask from firmware, and updates
2129 * hotkey_acpi_mask accordingly. Also resets any bits
2130 * from hotkey_user_mask that are unavailable to be
2131 * delivered (shadow requirement of the userspace ABI).
2133 * Call with hotkey_mutex held
2135 static int hotkey_mask_get(void)
2137 if (tp_features
.hotkey_mask
) {
2140 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
2143 hotkey_acpi_mask
= m
;
2145 /* no mask support doesn't mean no event support... */
2146 hotkey_acpi_mask
= hotkey_all_mask
;
2149 /* sync userspace-visible mask */
2150 hotkey_user_mask
&= (hotkey_acpi_mask
| hotkey_source_mask
);
2155 void static hotkey_mask_warn_incomplete_mask(void)
2157 /* log only what the user can fix... */
2158 const u32 wantedmask
= hotkey_driver_mask
&
2159 ~(hotkey_acpi_mask
| hotkey_source_mask
) &
2160 (hotkey_all_mask
| TPACPI_HKEY_NVRAM_KNOWN_MASK
);
2163 printk(TPACPI_NOTICE
2164 "required events 0x%08x not enabled!\n",
2169 * Set the firmware mask when supported
2171 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
2173 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
2175 * Call with hotkey_mutex held
2177 static int hotkey_mask_set(u32 mask
)
2182 const u32 fwmask
= mask
& ~hotkey_source_mask
;
2184 if (tp_features
.hotkey_mask
) {
2185 for (i
= 0; i
< 32; i
++) {
2186 if (!acpi_evalf(hkey_handle
,
2187 NULL
, "MHKM", "vdd", i
+ 1,
2188 !!(mask
& (1 << i
)))) {
2196 * We *must* make an inconditional call to hotkey_mask_get to
2197 * refresh hotkey_acpi_mask and update hotkey_user_mask
2199 * Take the opportunity to also log when we cannot _enable_
2202 if (!hotkey_mask_get() && !rc
&& (fwmask
& ~hotkey_acpi_mask
)) {
2203 printk(TPACPI_NOTICE
2204 "asked for hotkey mask 0x%08x, but "
2205 "firmware forced it to 0x%08x\n",
2206 fwmask
, hotkey_acpi_mask
);
2209 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
)
2210 hotkey_mask_warn_incomplete_mask();
2216 * Sets hotkey_user_mask and tries to set the firmware mask
2218 * Call with hotkey_mutex held
2220 static int hotkey_user_mask_set(const u32 mask
)
2224 /* Give people a chance to notice they are doing something that
2225 * is bound to go boom on their users sooner or later */
2226 if (!tp_warned
.hotkey_mask_ff
&&
2227 (mask
== 0xffff || mask
== 0xffffff ||
2228 mask
== 0xffffffff)) {
2229 tp_warned
.hotkey_mask_ff
= 1;
2230 printk(TPACPI_NOTICE
2231 "setting the hotkey mask to 0x%08x is likely "
2232 "not the best way to go about it\n", mask
);
2233 printk(TPACPI_NOTICE
2234 "please consider using the driver defaults, "
2235 "and refer to up-to-date thinkpad-acpi "
2239 /* Try to enable what the user asked for, plus whatever we need.
2240 * this syncs everything but won't enable bits in hotkey_user_mask */
2241 rc
= hotkey_mask_set((mask
| hotkey_driver_mask
) & ~hotkey_source_mask
);
2243 /* Enable the available bits in hotkey_user_mask */
2244 hotkey_user_mask
= mask
& (hotkey_acpi_mask
| hotkey_source_mask
);
2250 * Sets the driver hotkey mask.
2252 * Can be called even if the hotkey subdriver is inactive
2254 static int tpacpi_hotkey_driver_mask_set(const u32 mask
)
2258 /* Do the right thing if hotkey_init has not been called yet */
2259 if (!tp_features
.hotkey
) {
2260 hotkey_driver_mask
= mask
;
2264 mutex_lock(&hotkey_mutex
);
2266 HOTKEY_CONFIG_CRITICAL_START
2267 hotkey_driver_mask
= mask
;
2268 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2269 hotkey_source_mask
|= (mask
& ~hotkey_all_mask
);
2271 HOTKEY_CONFIG_CRITICAL_END
2273 rc
= hotkey_mask_set((hotkey_acpi_mask
| hotkey_driver_mask
) &
2274 ~hotkey_source_mask
);
2275 hotkey_poll_setup(true);
2277 mutex_unlock(&hotkey_mutex
);
2282 static int hotkey_status_get(int *status
)
2284 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
2290 static int hotkey_status_set(bool enable
)
2292 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
2298 static void tpacpi_input_send_tabletsw(void)
2302 if (tp_features
.hotkey_tablet
&&
2303 !hotkey_get_tablet_mode(&state
)) {
2304 mutex_lock(&tpacpi_inputdev_send_mutex
);
2306 input_report_switch(tpacpi_inputdev
,
2307 SW_TABLET_MODE
, !!state
);
2308 input_sync(tpacpi_inputdev
);
2310 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2314 /* Do NOT call without validating scancode first */
2315 static void tpacpi_input_send_key(const unsigned int scancode
)
2317 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
2319 if (keycode
!= KEY_RESERVED
) {
2320 mutex_lock(&tpacpi_inputdev_send_mutex
);
2322 input_report_key(tpacpi_inputdev
, keycode
, 1);
2323 if (keycode
== KEY_UNKNOWN
)
2324 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2326 input_sync(tpacpi_inputdev
);
2328 input_report_key(tpacpi_inputdev
, keycode
, 0);
2329 if (keycode
== KEY_UNKNOWN
)
2330 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2332 input_sync(tpacpi_inputdev
);
2334 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2338 /* Do NOT call without validating scancode first */
2339 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
2341 hotkey_driver_event(scancode
);
2342 if (hotkey_user_mask
& (1 << scancode
))
2343 tpacpi_input_send_key(scancode
);
2346 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2347 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2349 /* Do NOT call without validating scancode first */
2350 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2352 tpacpi_input_send_key_masked(scancode
);
2353 if (hotkey_report_mode
< 2) {
2354 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2355 0x80, TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
2359 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2363 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2364 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2365 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2366 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2367 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2368 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2370 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2371 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2372 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2374 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2375 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2376 n
->displayexp_toggle
=
2377 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2379 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2380 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2381 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2382 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2383 n
->brightness_toggle
=
2384 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2386 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2387 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2388 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2389 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2390 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2391 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2395 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2396 struct tp_nvram_state
*newn
,
2397 const u32 event_mask
)
2400 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2402 if ((event_mask & (1 << __scancode)) && \
2403 oldn->__member != newn->__member) \
2404 tpacpi_hotkey_send_key(__scancode); \
2407 #define TPACPI_MAY_SEND_KEY(__scancode) \
2409 if (event_mask & (1 << __scancode)) \
2410 tpacpi_hotkey_send_key(__scancode); \
2413 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2414 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2415 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2416 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2418 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2420 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2423 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2424 if (oldn
->mute
!= newn
->mute
) {
2425 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2427 if (oldn
->volume_level
> newn
->volume_level
) {
2428 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2429 } else if (oldn
->volume_level
< newn
->volume_level
) {
2430 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2431 } else if (oldn
->mute
== newn
->mute
) {
2432 /* repeated key presses that didn't change state */
2434 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2435 } else if (newn
->volume_level
!= 0) {
2436 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2438 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2443 /* handle brightness */
2444 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2445 if (oldn
->brightness_level
< newn
->brightness_level
) {
2446 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2447 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
2448 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2450 /* repeated key presses that didn't change state */
2451 if (newn
->brightness_level
!= 0) {
2452 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2454 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2459 #undef TPACPI_COMPARE_KEY
2460 #undef TPACPI_MAY_SEND_KEY
2466 * We track all events in hotkey_source_mask all the time, since
2467 * most of them are edge-based. We only issue those requested by
2468 * hotkey_user_mask or hotkey_driver_mask, though.
2470 static int hotkey_kthread(void *data
)
2472 struct tp_nvram_state s
[2];
2473 u32 poll_mask
, event_mask
;
2474 unsigned int si
, so
;
2476 unsigned int change_detector
, must_reset
;
2477 unsigned int poll_freq
;
2479 mutex_lock(&hotkey_thread_mutex
);
2481 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2490 /* Initial state for compares */
2491 mutex_lock(&hotkey_thread_data_mutex
);
2492 change_detector
= hotkey_config_change
;
2493 poll_mask
= hotkey_source_mask
;
2494 event_mask
= hotkey_source_mask
&
2495 (hotkey_driver_mask
| hotkey_user_mask
);
2496 poll_freq
= hotkey_poll_freq
;
2497 mutex_unlock(&hotkey_thread_data_mutex
);
2498 hotkey_read_nvram(&s
[so
], poll_mask
);
2500 while (!kthread_should_stop()) {
2502 if (likely(poll_freq
))
2505 t
= 100; /* should never happen... */
2507 t
= msleep_interruptible(t
);
2508 if (unlikely(kthread_should_stop()))
2510 must_reset
= try_to_freeze();
2511 if (t
> 0 && !must_reset
)
2514 mutex_lock(&hotkey_thread_data_mutex
);
2515 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2516 /* forget old state on thaw or config change */
2519 change_detector
= hotkey_config_change
;
2521 poll_mask
= hotkey_source_mask
;
2522 event_mask
= hotkey_source_mask
&
2523 (hotkey_driver_mask
| hotkey_user_mask
);
2524 poll_freq
= hotkey_poll_freq
;
2525 mutex_unlock(&hotkey_thread_data_mutex
);
2527 if (likely(poll_mask
)) {
2528 hotkey_read_nvram(&s
[si
], poll_mask
);
2529 if (likely(si
!= so
)) {
2530 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2540 mutex_unlock(&hotkey_thread_mutex
);
2544 /* call with hotkey_mutex held */
2545 static void hotkey_poll_stop_sync(void)
2547 if (tpacpi_hotkey_task
) {
2548 if (frozen(tpacpi_hotkey_task
) ||
2549 freezing(tpacpi_hotkey_task
))
2550 thaw_process(tpacpi_hotkey_task
);
2552 kthread_stop(tpacpi_hotkey_task
);
2553 tpacpi_hotkey_task
= NULL
;
2554 mutex_lock(&hotkey_thread_mutex
);
2555 /* at this point, the thread did exit */
2556 mutex_unlock(&hotkey_thread_mutex
);
2560 /* call with hotkey_mutex held */
2561 static void hotkey_poll_setup(const bool may_warn
)
2563 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2564 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2566 if (hotkey_poll_freq
> 0 &&
2567 (poll_driver_mask
||
2568 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2569 if (!tpacpi_hotkey_task
) {
2570 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2571 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2572 if (IS_ERR(tpacpi_hotkey_task
)) {
2573 tpacpi_hotkey_task
= NULL
;
2575 "could not create kernel thread "
2576 "for hotkey polling\n");
2580 hotkey_poll_stop_sync();
2581 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2582 hotkey_poll_freq
== 0) {
2583 printk(TPACPI_NOTICE
2584 "hot keys 0x%08x and/or events 0x%08x "
2585 "require polling, which is currently "
2587 poll_user_mask
, poll_driver_mask
);
2592 static void hotkey_poll_setup_safe(const bool may_warn
)
2594 mutex_lock(&hotkey_mutex
);
2595 hotkey_poll_setup(may_warn
);
2596 mutex_unlock(&hotkey_mutex
);
2599 /* call with hotkey_mutex held */
2600 static void hotkey_poll_set_freq(unsigned int freq
)
2603 hotkey_poll_stop_sync();
2605 hotkey_poll_freq
= freq
;
2608 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2610 static void hotkey_poll_setup(const bool __unused
)
2614 static void hotkey_poll_setup_safe(const bool __unused
)
2618 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2620 static int hotkey_inputdev_open(struct input_dev
*dev
)
2622 switch (tpacpi_lifecycle
) {
2623 case TPACPI_LIFE_INIT
:
2624 case TPACPI_LIFE_RUNNING
:
2625 hotkey_poll_setup_safe(false);
2627 case TPACPI_LIFE_EXITING
:
2631 /* Should only happen if tpacpi_lifecycle is corrupt */
2636 static void hotkey_inputdev_close(struct input_dev
*dev
)
2638 /* disable hotkey polling when possible */
2639 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
&&
2640 !(hotkey_source_mask
& hotkey_driver_mask
))
2641 hotkey_poll_setup_safe(false);
2644 /* sysfs hotkey enable ------------------------------------------------- */
2645 static ssize_t
hotkey_enable_show(struct device
*dev
,
2646 struct device_attribute
*attr
,
2651 printk_deprecated_attribute("hotkey_enable",
2652 "Hotkey reporting is always enabled");
2654 res
= hotkey_status_get(&status
);
2658 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2661 static ssize_t
hotkey_enable_store(struct device
*dev
,
2662 struct device_attribute
*attr
,
2663 const char *buf
, size_t count
)
2667 printk_deprecated_attribute("hotkey_enable",
2668 "Hotkeys can be disabled through hotkey_mask");
2670 if (parse_strtoul(buf
, 1, &t
))
2679 static struct device_attribute dev_attr_hotkey_enable
=
2680 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2681 hotkey_enable_show
, hotkey_enable_store
);
2683 /* sysfs hotkey mask --------------------------------------------------- */
2684 static ssize_t
hotkey_mask_show(struct device
*dev
,
2685 struct device_attribute
*attr
,
2688 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2691 static ssize_t
hotkey_mask_store(struct device
*dev
,
2692 struct device_attribute
*attr
,
2693 const char *buf
, size_t count
)
2698 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2701 if (mutex_lock_killable(&hotkey_mutex
))
2702 return -ERESTARTSYS
;
2704 res
= hotkey_user_mask_set(t
);
2706 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2707 hotkey_poll_setup(true);
2710 mutex_unlock(&hotkey_mutex
);
2712 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2714 return (res
) ? res
: count
;
2717 static struct device_attribute dev_attr_hotkey_mask
=
2718 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2719 hotkey_mask_show
, hotkey_mask_store
);
2721 /* sysfs hotkey bios_enabled ------------------------------------------- */
2722 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2723 struct device_attribute
*attr
,
2726 return sprintf(buf
, "0\n");
2729 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2730 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2732 /* sysfs hotkey bios_mask ---------------------------------------------- */
2733 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2734 struct device_attribute
*attr
,
2737 printk_deprecated_attribute("hotkey_bios_mask",
2738 "This attribute is useless.");
2739 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2742 static struct device_attribute dev_attr_hotkey_bios_mask
=
2743 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2745 /* sysfs hotkey all_mask ----------------------------------------------- */
2746 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2747 struct device_attribute
*attr
,
2750 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2751 hotkey_all_mask
| hotkey_source_mask
);
2754 static struct device_attribute dev_attr_hotkey_all_mask
=
2755 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2757 /* sysfs hotkey recommended_mask --------------------------------------- */
2758 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2759 struct device_attribute
*attr
,
2762 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2763 (hotkey_all_mask
| hotkey_source_mask
)
2764 & ~hotkey_reserved_mask
);
2767 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2768 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2769 hotkey_recommended_mask_show
, NULL
);
2771 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2773 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2774 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2775 struct device_attribute
*attr
,
2778 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2781 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2782 struct device_attribute
*attr
,
2783 const char *buf
, size_t count
)
2789 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2790 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2793 if (mutex_lock_killable(&hotkey_mutex
))
2794 return -ERESTARTSYS
;
2796 HOTKEY_CONFIG_CRITICAL_START
2797 hotkey_source_mask
= t
;
2798 HOTKEY_CONFIG_CRITICAL_END
2800 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2801 ~hotkey_source_mask
);
2802 hotkey_poll_setup(true);
2804 /* check if events needed by the driver got disabled */
2805 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2806 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2808 mutex_unlock(&hotkey_mutex
);
2811 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2812 "firmware event mask!\n");
2815 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2816 "some important events were disabled: "
2819 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2821 return (rc
< 0) ? rc
: count
;
2824 static struct device_attribute dev_attr_hotkey_source_mask
=
2825 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2826 hotkey_source_mask_show
, hotkey_source_mask_store
);
2828 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2829 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2830 struct device_attribute
*attr
,
2833 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2836 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2837 struct device_attribute
*attr
,
2838 const char *buf
, size_t count
)
2842 if (parse_strtoul(buf
, 25, &t
))
2845 if (mutex_lock_killable(&hotkey_mutex
))
2846 return -ERESTARTSYS
;
2848 hotkey_poll_set_freq(t
);
2849 hotkey_poll_setup(true);
2851 mutex_unlock(&hotkey_mutex
);
2853 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2858 static struct device_attribute dev_attr_hotkey_poll_freq
=
2859 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2860 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2862 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2864 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2865 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2866 struct device_attribute
*attr
,
2870 res
= hotkey_get_wlsw();
2874 /* Opportunistic update */
2875 tpacpi_rfk_update_hwblock_state((res
== TPACPI_RFK_RADIO_OFF
));
2877 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2878 (res
== TPACPI_RFK_RADIO_OFF
) ? 0 : 1);
2881 static struct device_attribute dev_attr_hotkey_radio_sw
=
2882 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2884 static void hotkey_radio_sw_notify_change(void)
2886 if (tp_features
.hotkey_wlsw
)
2887 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2891 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2892 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2893 struct device_attribute
*attr
,
2897 res
= hotkey_get_tablet_mode(&s
);
2901 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2904 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2905 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2907 static void hotkey_tablet_mode_notify_change(void)
2909 if (tp_features
.hotkey_tablet
)
2910 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2911 "hotkey_tablet_mode");
2914 /* sysfs hotkey report_mode -------------------------------------------- */
2915 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2916 struct device_attribute
*attr
,
2919 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2920 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2923 static struct device_attribute dev_attr_hotkey_report_mode
=
2924 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2926 /* sysfs wakeup reason (pollable) -------------------------------------- */
2927 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2928 struct device_attribute
*attr
,
2931 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2934 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2935 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2937 static void hotkey_wakeup_reason_notify_change(void)
2939 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2943 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2944 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2945 struct device_attribute
*attr
,
2948 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2951 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2952 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2953 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2955 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2957 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2958 "wakeup_hotunplug_complete");
2961 /* --------------------------------------------------------------------- */
2963 static struct attribute
*hotkey_attributes
[] __initdata
= {
2964 &dev_attr_hotkey_enable
.attr
,
2965 &dev_attr_hotkey_bios_enabled
.attr
,
2966 &dev_attr_hotkey_bios_mask
.attr
,
2967 &dev_attr_hotkey_report_mode
.attr
,
2968 &dev_attr_hotkey_wakeup_reason
.attr
,
2969 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2970 &dev_attr_hotkey_mask
.attr
,
2971 &dev_attr_hotkey_all_mask
.attr
,
2972 &dev_attr_hotkey_recommended_mask
.attr
,
2973 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2974 &dev_attr_hotkey_source_mask
.attr
,
2975 &dev_attr_hotkey_poll_freq
.attr
,
2980 * Sync both the hw and sw blocking state of all switches
2982 static void tpacpi_send_radiosw_update(void)
2987 * We must sync all rfkill controllers *before* issuing any
2988 * rfkill input events, or we will race the rfkill core input
2991 * tpacpi_inputdev_send_mutex works as a syncronization point
2994 * We optimize to avoid numerous calls to hotkey_get_wlsw.
2997 wlsw
= hotkey_get_wlsw();
2999 /* Sync hw blocking state first if it is hw-blocked */
3000 if (wlsw
== TPACPI_RFK_RADIO_OFF
)
3001 tpacpi_rfk_update_hwblock_state(true);
3003 /* Sync sw blocking state */
3004 tpacpi_rfk_update_swstate_all();
3006 /* Sync hw blocking state last if it is hw-unblocked */
3007 if (wlsw
== TPACPI_RFK_RADIO_ON
)
3008 tpacpi_rfk_update_hwblock_state(false);
3010 /* Issue rfkill input event for WLSW switch */
3012 mutex_lock(&tpacpi_inputdev_send_mutex
);
3014 input_report_switch(tpacpi_inputdev
,
3015 SW_RFKILL_ALL
, (wlsw
> 0));
3016 input_sync(tpacpi_inputdev
);
3018 mutex_unlock(&tpacpi_inputdev_send_mutex
);
3022 * this can be unconditional, as we will poll state again
3023 * if userspace uses the notify to read data
3025 hotkey_radio_sw_notify_change();
3028 static void hotkey_exit(void)
3030 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3031 mutex_lock(&hotkey_mutex
);
3032 hotkey_poll_stop_sync();
3033 mutex_unlock(&hotkey_mutex
);
3036 if (hotkey_dev_attributes
)
3037 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3039 kfree(hotkey_keycode_map
);
3041 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
3042 "restoring original HKEY status and mask\n");
3043 /* yes, there is a bitwise or below, we want the
3044 * functions to be called even if one of them fail */
3045 if (((tp_features
.hotkey_mask
&&
3046 hotkey_mask_set(hotkey_orig_mask
)) |
3047 hotkey_status_set(false)) != 0)
3049 "failed to restore hot key mask "
3050 "to BIOS defaults\n");
3053 static void __init
hotkey_unmap(const unsigned int scancode
)
3055 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
3056 clear_bit(hotkey_keycode_map
[scancode
],
3057 tpacpi_inputdev
->keybit
);
3058 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
3064 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
3067 #define TPACPI_HK_Q_INIMASK 0x0001
3069 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
3070 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
3071 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
3072 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
3073 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
3074 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
3075 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
3076 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
3077 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
3078 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
3079 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
3080 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
3081 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
3082 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
3083 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
3084 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
3085 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
3086 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
3087 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
3088 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
3091 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
3093 /* Requirements for changing the default keymaps:
3095 * 1. Many of the keys are mapped to KEY_RESERVED for very
3096 * good reasons. Do not change them unless you have deep
3097 * knowledge on the IBM and Lenovo ThinkPad firmware for
3098 * the various ThinkPad models. The driver behaves
3099 * differently for KEY_RESERVED: such keys have their
3100 * hot key mask *unset* in mask_recommended, and also
3101 * in the initial hot key mask programmed into the
3102 * firmware at driver load time, which means the firm-
3103 * ware may react very differently if you change them to
3106 * 2. You must be subscribed to the linux-thinkpad and
3107 * ibm-acpi-devel mailing lists, and you should read the
3108 * list archives since 2007 if you want to change the
3109 * keymaps. This requirement exists so that you will
3110 * know the past history of problems with the thinkpad-
3111 * acpi driver keymaps, and also that you will be
3112 * listening to any bug reports;
3114 * 3. Do not send thinkpad-acpi specific patches directly to
3115 * for merging, *ever*. Send them to the linux-acpi
3116 * mailinglist for comments. Merging is to be done only
3117 * through acpi-test and the ACPI maintainer.
3119 * If the above is too much to ask, don't change the keymap.
3120 * Ask the thinkpad-acpi maintainer to do it, instead.
3122 static u16 ibm_keycode_map
[] __initdata
= {
3123 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3124 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
3125 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3126 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3128 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3129 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3130 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3131 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3133 /* brightness: firmware always reacts to them */
3134 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
3135 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
3137 /* Thinklight: firmware always react to it */
3138 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3140 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3141 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3143 /* Volume: firmware always react to it and reprograms
3144 * the built-in *extra* mixer. Never map it to control
3145 * another mixer by default. */
3146 KEY_RESERVED
, /* 0x14: VOLUME UP */
3147 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3148 KEY_RESERVED
, /* 0x16: MUTE */
3150 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3152 /* (assignments unknown, please report if found) */
3153 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3154 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3156 static u16 lenovo_keycode_map
[] __initdata
= {
3157 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3158 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
3159 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3160 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3162 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3163 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3164 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3165 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3167 /* These should be enabled --only-- when ACPI video
3168 * is disabled (i.e. in "vendor" mode), and are handled
3169 * in a special way by the init code */
3170 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
3171 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
3173 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3175 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3176 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3178 /* Volume: z60/z61, T60 (BIOS version?): firmware always
3179 * react to it and reprograms the built-in *extra* mixer.
3180 * Never map it to control another mixer by default.
3182 * T60?, T61, R60?, R61: firmware and EC tries to send
3183 * these over the regular keyboard, so these are no-ops,
3184 * but there are still weird bugs re. MUTE, so do not
3185 * change unless you get test reports from all Lenovo
3186 * models. May cause the BIOS to interfere with the
3189 KEY_RESERVED
, /* 0x14: VOLUME UP */
3190 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3191 KEY_RESERVED
, /* 0x16: MUTE */
3193 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3195 /* (assignments unknown, please report if found) */
3196 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3197 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3200 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
3201 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
3202 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
3207 bool radiosw_state
= false;
3208 bool tabletsw_state
= false;
3210 unsigned long quirks
;
3212 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3213 "initializing hotkey subdriver\n");
3215 BUG_ON(!tpacpi_inputdev
);
3216 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
3217 tpacpi_inputdev
->close
!= NULL
);
3219 TPACPI_ACPIHANDLE_INIT(hkey
);
3220 mutex_init(&hotkey_mutex
);
3222 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3223 mutex_init(&hotkey_thread_mutex
);
3224 mutex_init(&hotkey_thread_data_mutex
);
3227 /* hotkey not supported on 570 */
3228 tp_features
.hotkey
= hkey_handle
!= NULL
;
3230 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3232 str_supported(tp_features
.hotkey
));
3234 if (!tp_features
.hotkey
)
3237 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
3238 ARRAY_SIZE(tpacpi_hotkey_qtable
));
3240 tpacpi_disable_brightness_delay();
3242 /* MUST have enough space for all attributes to be added to
3243 * hotkey_dev_attributes */
3244 hotkey_dev_attributes
= create_attr_set(
3245 ARRAY_SIZE(hotkey_attributes
) + 2,
3247 if (!hotkey_dev_attributes
)
3249 res
= add_many_to_attr_set(hotkey_dev_attributes
,
3251 ARRAY_SIZE(hotkey_attributes
));
3255 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
3256 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
3257 for HKEY interface version 0x100 */
3258 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
3259 if ((hkeyv
>> 8) != 1) {
3260 printk(TPACPI_ERR
"unknown version of the "
3261 "HKEY interface: 0x%x\n", hkeyv
);
3262 printk(TPACPI_ERR
"please report this to %s\n",
3266 * MHKV 0x100 in A31, R40, R40e,
3267 * T4x, X31, and later
3269 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3270 "firmware HKEY interface version: 0x%x\n",
3273 /* Paranoia check AND init hotkey_all_mask */
3274 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
3277 "missing MHKA handler, "
3278 "please report this to %s\n",
3280 /* Fallback: pre-init for FN+F3,F4,F12 */
3281 hotkey_all_mask
= 0x080cU
;
3283 tp_features
.hotkey_mask
= 1;
3288 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3289 "hotkey masks are %s\n",
3290 str_supported(tp_features
.hotkey_mask
));
3292 /* Init hotkey_all_mask if not initialized yet */
3293 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
3294 (quirks
& TPACPI_HK_Q_INIMASK
))
3295 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
3297 /* Init hotkey_acpi_mask and hotkey_orig_mask */
3298 if (tp_features
.hotkey_mask
) {
3299 /* hotkey_source_mask *must* be zero for
3300 * the first hotkey_mask_get to return hotkey_orig_mask */
3301 res
= hotkey_mask_get();
3305 hotkey_orig_mask
= hotkey_acpi_mask
;
3307 hotkey_orig_mask
= hotkey_all_mask
;
3308 hotkey_acpi_mask
= hotkey_all_mask
;
3311 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3313 tp_features
.hotkey_wlsw
= 1;
3314 radiosw_state
= !!tpacpi_wlsw_emulstate
;
3316 "radio switch emulation enabled\n");
3319 /* Not all thinkpads have a hardware radio switch */
3320 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3321 tp_features
.hotkey_wlsw
= 1;
3322 radiosw_state
= !!status
;
3324 "radio switch found; radios are %s\n",
3325 enabled(status
, 0));
3327 if (tp_features
.hotkey_wlsw
)
3328 res
= add_to_attr_set(hotkey_dev_attributes
,
3329 &dev_attr_hotkey_radio_sw
.attr
);
3331 /* For X41t, X60t, X61t Tablets... */
3332 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3333 tp_features
.hotkey_tablet
= 1;
3334 tabletsw_state
= !!(status
& TP_HOTKEY_TABLET_MASK
);
3336 "possible tablet mode switch found; "
3337 "ThinkPad in %s mode\n",
3338 (tabletsw_state
) ? "tablet" : "laptop");
3339 res
= add_to_attr_set(hotkey_dev_attributes
,
3340 &dev_attr_hotkey_tablet_mode
.attr
);
3344 res
= register_attr_set_with_sysfs(
3345 hotkey_dev_attributes
,
3346 &tpacpi_pdev
->dev
.kobj
);
3350 /* Set up key map */
3352 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3354 if (!hotkey_keycode_map
) {
3356 "failed to allocate memory for key map\n");
3361 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
3362 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3363 "using Lenovo default hot key map\n");
3364 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
3365 TPACPI_HOTKEY_MAP_SIZE
);
3367 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3368 "using IBM default hot key map\n");
3369 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
3370 TPACPI_HOTKEY_MAP_SIZE
);
3373 input_set_capability(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
);
3374 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3375 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3376 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3377 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3378 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3379 input_set_capability(tpacpi_inputdev
, EV_KEY
,
3380 hotkey_keycode_map
[i
]);
3382 if (i
< sizeof(hotkey_reserved_mask
)*8)
3383 hotkey_reserved_mask
|= 1 << i
;
3387 if (tp_features
.hotkey_wlsw
) {
3388 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_RFKILL_ALL
);
3389 input_report_switch(tpacpi_inputdev
,
3390 SW_RFKILL_ALL
, radiosw_state
);
3392 if (tp_features
.hotkey_tablet
) {
3393 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_TABLET_MODE
);
3394 input_report_switch(tpacpi_inputdev
,
3395 SW_TABLET_MODE
, tabletsw_state
);
3398 /* Do not issue duplicate brightness change events to
3400 if (!tp_features
.bright_acpimode
)
3401 /* update bright_acpimode... */
3402 tpacpi_check_std_acpi_brightness_support();
3404 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
3406 "This ThinkPad has standard ACPI backlight "
3407 "brightness control, supported by the ACPI "
3409 printk(TPACPI_NOTICE
3410 "Disabling thinkpad-acpi brightness events "
3413 /* Disable brightness up/down on Lenovo thinkpads when
3414 * ACPI is handling them, otherwise it is plain impossible
3415 * for userspace to do something even remotely sane */
3416 hotkey_reserved_mask
|=
3417 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3418 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3419 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3420 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3423 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3424 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3426 & ~hotkey_reserved_mask
;
3428 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3429 "hotkey source mask 0x%08x, polling freq %u\n",
3430 hotkey_source_mask
, hotkey_poll_freq
);
3433 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3434 "enabling firmware HKEY event interface...\n");
3435 res
= hotkey_status_set(true);
3440 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3441 | hotkey_driver_mask
)
3442 & ~hotkey_source_mask
);
3443 if (res
< 0 && res
!= -ENXIO
) {
3447 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3448 & ~hotkey_reserved_mask
;
3449 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3450 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3451 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3453 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3454 "legacy ibm/hotkey event reporting over procfs %s\n",
3455 (hotkey_report_mode
< 2) ?
3456 "enabled" : "disabled");
3458 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3459 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3461 hotkey_poll_setup_safe(true);
3466 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3467 hotkey_dev_attributes
= NULL
;
3469 return (res
< 0)? res
: 1;
3472 static bool hotkey_notify_hotkey(const u32 hkey
,
3474 bool *ignore_acpi_ev
)
3476 /* 0x1000-0x1FFF: key presses */
3477 unsigned int scancode
= hkey
& 0xfff;
3478 *send_acpi_ev
= true;
3479 *ignore_acpi_ev
= false;
3481 if (scancode
> 0 && scancode
< 0x21) {
3483 if (!(hotkey_source_mask
& (1 << scancode
))) {
3484 tpacpi_input_send_key_masked(scancode
);
3485 *send_acpi_ev
= false;
3487 *ignore_acpi_ev
= true;
3494 static bool hotkey_notify_wakeup(const u32 hkey
,
3496 bool *ignore_acpi_ev
)
3498 /* 0x2000-0x2FFF: Wakeup reason */
3499 *send_acpi_ev
= true;
3500 *ignore_acpi_ev
= false;
3503 case TP_HKEY_EV_WKUP_S3_UNDOCK
: /* suspend, undock */
3504 case TP_HKEY_EV_WKUP_S4_UNDOCK
: /* hibernation, undock */
3505 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3506 *ignore_acpi_ev
= true;
3509 case TP_HKEY_EV_WKUP_S3_BAYEJ
: /* suspend, bay eject */
3510 case TP_HKEY_EV_WKUP_S4_BAYEJ
: /* hibernation, bay eject */
3511 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3512 *ignore_acpi_ev
= true;
3515 case TP_HKEY_EV_WKUP_S3_BATLOW
: /* Battery on critical low level/S3 */
3516 case TP_HKEY_EV_WKUP_S4_BATLOW
: /* Battery on critical low level/S4 */
3518 "EMERGENCY WAKEUP: battery almost empty\n");
3519 /* how to auto-heal: */
3520 /* 2313: woke up from S3, go to S4/S5 */
3521 /* 2413: woke up from S4, go to S5 */
3528 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3530 "woke up due to a hot-unplug "
3532 hotkey_wakeup_reason_notify_change();
3537 static bool hotkey_notify_usrevent(const u32 hkey
,
3539 bool *ignore_acpi_ev
)
3541 /* 0x5000-0x5FFF: human interface helpers */
3542 *send_acpi_ev
= true;
3543 *ignore_acpi_ev
= false;
3546 case TP_HKEY_EV_PEN_INSERTED
: /* X61t: tablet pen inserted into bay */
3547 case TP_HKEY_EV_PEN_REMOVED
: /* X61t: tablet pen removed from bay */
3550 case TP_HKEY_EV_TABLET_TABLET
: /* X41t-X61t: tablet mode */
3551 case TP_HKEY_EV_TABLET_NOTEBOOK
: /* X41t-X61t: normal mode */
3552 tpacpi_input_send_tabletsw();
3553 hotkey_tablet_mode_notify_change();
3554 *send_acpi_ev
= false;
3557 case TP_HKEY_EV_LID_CLOSE
: /* Lid closed */
3558 case TP_HKEY_EV_LID_OPEN
: /* Lid opened */
3559 case TP_HKEY_EV_BRGHT_CHANGED
: /* brightness changed */
3560 /* do not propagate these events */
3561 *ignore_acpi_ev
= true;
3569 static void thermal_dump_all_sensors(void);
3571 static bool hotkey_notify_thermal(const u32 hkey
,
3573 bool *ignore_acpi_ev
)
3577 /* 0x6000-0x6FFF: thermal alarms */
3578 *send_acpi_ev
= true;
3579 *ignore_acpi_ev
= false;
3582 case TP_HKEY_EV_THM_TABLE_CHANGED
:
3584 "EC reports that Thermal Table has changed\n");
3585 /* recommended action: do nothing, we don't have
3586 * Lenovo ATM information */
3588 case TP_HKEY_EV_ALARM_BAT_HOT
:
3590 "THERMAL ALARM: battery is too hot!\n");
3591 /* recommended action: warn user through gui */
3593 case TP_HKEY_EV_ALARM_BAT_XHOT
:
3595 "THERMAL EMERGENCY: battery is extremely hot!\n");
3596 /* recommended action: immediate sleep/hibernate */
3598 case TP_HKEY_EV_ALARM_SENSOR_HOT
:
3601 "a sensor reports something is too hot!\n");
3602 /* recommended action: warn user through gui, that */
3603 /* some internal component is too hot */
3605 case TP_HKEY_EV_ALARM_SENSOR_XHOT
:
3607 "THERMAL EMERGENCY: "
3608 "a sensor reports something is extremely hot!\n");
3609 /* recommended action: immediate sleep/hibernate */
3613 "THERMAL ALERT: unknown thermal alarm received\n");
3617 thermal_dump_all_sensors();
3622 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3626 bool ignore_acpi_ev
;
3629 if (event
!= 0x80) {
3631 "unknown HKEY notification event %d\n", event
);
3632 /* forward it to userspace, maybe it knows how to handle it */
3633 acpi_bus_generate_netlink_event(
3634 ibm
->acpi
->device
->pnp
.device_class
,
3635 dev_name(&ibm
->acpi
->device
->dev
),
3641 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3642 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3651 send_acpi_ev
= true;
3652 ignore_acpi_ev
= false;
3654 switch (hkey
>> 12) {
3656 /* 0x1000-0x1FFF: key presses */
3657 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3661 /* 0x2000-0x2FFF: Wakeup reason */
3662 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3666 /* 0x3000-0x3FFF: bay-related wakeups */
3668 case TP_HKEY_EV_BAYEJ_ACK
:
3669 hotkey_autosleep_ack
= 1;
3672 hotkey_wakeup_hotunplug_complete_notify_change();
3675 case TP_HKEY_EV_OPTDRV_EJ
:
3676 /* FIXME: kick libata if SATA link offline */
3684 /* 0x4000-0x4FFF: dock-related wakeups */
3685 if (hkey
== TP_HKEY_EV_UNDOCK_ACK
) {
3686 hotkey_autosleep_ack
= 1;
3689 hotkey_wakeup_hotunplug_complete_notify_change();
3696 /* 0x5000-0x5FFF: human interface helpers */
3697 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3701 /* 0x6000-0x6FFF: thermal alarms */
3702 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3706 /* 0x7000-0x7FFF: misc */
3707 if (tp_features
.hotkey_wlsw
&&
3708 hkey
== TP_HKEY_EV_RFKILL_CHANGED
) {
3709 tpacpi_send_radiosw_update();
3714 /* fallthrough to default */
3719 printk(TPACPI_NOTICE
3720 "unhandled HKEY event 0x%04x\n", hkey
);
3721 printk(TPACPI_NOTICE
3722 "please report the conditions when this "
3723 "event happened to %s\n", TPACPI_MAIL
);
3727 if (!ignore_acpi_ev
&&
3728 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3729 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3733 /* netlink events */
3734 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3735 acpi_bus_generate_netlink_event(
3736 ibm
->acpi
->device
->pnp
.device_class
,
3737 dev_name(&ibm
->acpi
->device
->dev
),
3743 static void hotkey_suspend(pm_message_t state
)
3745 /* Do these on suspend, we get the events on early resume! */
3746 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3747 hotkey_autosleep_ack
= 0;
3750 static void hotkey_resume(void)
3752 tpacpi_disable_brightness_delay();
3754 if (hotkey_status_set(true) < 0 ||
3755 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3757 "error while attempting to reset the event "
3758 "firmware interface\n");
3760 tpacpi_send_radiosw_update();
3761 hotkey_tablet_mode_notify_change();
3762 hotkey_wakeup_reason_notify_change();
3763 hotkey_wakeup_hotunplug_complete_notify_change();
3764 hotkey_poll_setup_safe(false);
3767 /* procfs -------------------------------------------------------------- */
3768 static int hotkey_read(struct seq_file
*m
)
3772 if (!tp_features
.hotkey
) {
3773 seq_printf(m
, "status:\t\tnot supported\n");
3777 if (mutex_lock_killable(&hotkey_mutex
))
3778 return -ERESTARTSYS
;
3779 res
= hotkey_status_get(&status
);
3781 res
= hotkey_mask_get();
3782 mutex_unlock(&hotkey_mutex
);
3786 seq_printf(m
, "status:\t\t%s\n", enabled(status
, 0));
3787 if (hotkey_all_mask
) {
3788 seq_printf(m
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3789 seq_printf(m
, "commands:\tenable, disable, reset, <mask>\n");
3791 seq_printf(m
, "mask:\t\tnot supported\n");
3792 seq_printf(m
, "commands:\tenable, disable, reset\n");
3798 static void hotkey_enabledisable_warn(bool enable
)
3800 tpacpi_log_usertask("procfs hotkey enable/disable");
3801 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3803 "hotkey enable/disable functionality has been "
3804 "removed from the driver. Hotkeys are always "
3807 "Please remove the hotkey=enable module "
3808 "parameter, it is deprecated. Hotkeys are always "
3812 static int hotkey_write(char *buf
)
3818 if (!tp_features
.hotkey
)
3821 if (mutex_lock_killable(&hotkey_mutex
))
3822 return -ERESTARTSYS
;
3824 mask
= hotkey_user_mask
;
3827 while ((cmd
= next_cmd(&buf
))) {
3828 if (strlencmp(cmd
, "enable") == 0) {
3829 hotkey_enabledisable_warn(1);
3830 } else if (strlencmp(cmd
, "disable") == 0) {
3831 hotkey_enabledisable_warn(0);
3833 } else if (strlencmp(cmd
, "reset") == 0) {
3834 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3835 & ~hotkey_reserved_mask
;
3836 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3838 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3847 tpacpi_disclose_usertask("procfs hotkey",
3848 "set mask to 0x%08x\n", mask
);
3849 res
= hotkey_user_mask_set(mask
);
3853 mutex_unlock(&hotkey_mutex
);
3857 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3858 {TPACPI_ACPI_IBM_HKEY_HID
, 0},
3859 {TPACPI_ACPI_LENOVO_HKEY_HID
, 0},
3863 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3864 .hid
= ibm_htk_device_ids
,
3865 .notify
= hotkey_notify
,
3866 .handle
= &hkey_handle
,
3867 .type
= ACPI_DEVICE_NOTIFY
,
3870 static struct ibm_struct hotkey_driver_data
= {
3872 .read
= hotkey_read
,
3873 .write
= hotkey_write
,
3874 .exit
= hotkey_exit
,
3875 .resume
= hotkey_resume
,
3876 .suspend
= hotkey_suspend
,
3877 .acpi
= &ibm_hotkey_acpidriver
,
3880 /*************************************************************************
3881 * Bluetooth subdriver
3885 /* ACPI GBDC/SBDC bits */
3886 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3887 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3888 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3889 0 = disable, 1 = enable */
3893 /* ACPI \BLTH commands */
3894 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3895 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3896 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3897 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3898 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3901 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3903 static int bluetooth_get_status(void)
3907 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3908 if (dbg_bluetoothemul
)
3909 return (tpacpi_bluetooth_emulstate
) ?
3910 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3913 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3916 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3917 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3920 static int bluetooth_set_status(enum tpacpi_rfkill_state state
)
3924 vdbg_printk(TPACPI_DBG_RFKILL
,
3925 "will attempt to %s bluetooth\n",
3926 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
3928 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3929 if (dbg_bluetoothemul
) {
3930 tpacpi_bluetooth_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
3935 if (state
== TPACPI_RFK_RADIO_ON
)
3936 status
= TP_ACPI_BLUETOOTH_RADIOSSW
3937 | TP_ACPI_BLUETOOTH_RESUMECTRL
;
3941 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3947 /* sysfs bluetooth enable ---------------------------------------------- */
3948 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3949 struct device_attribute
*attr
,
3952 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID
,
3956 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3957 struct device_attribute
*attr
,
3958 const char *buf
, size_t count
)
3960 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID
,
3964 static struct device_attribute dev_attr_bluetooth_enable
=
3965 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3966 bluetooth_enable_show
, bluetooth_enable_store
);
3968 /* --------------------------------------------------------------------- */
3970 static struct attribute
*bluetooth_attributes
[] = {
3971 &dev_attr_bluetooth_enable
.attr
,
3975 static const struct attribute_group bluetooth_attr_group
= {
3976 .attrs
= bluetooth_attributes
,
3979 static const struct tpacpi_rfk_ops bluetooth_tprfk_ops
= {
3980 .get_status
= bluetooth_get_status
,
3981 .set_status
= bluetooth_set_status
,
3984 static void bluetooth_shutdown(void)
3986 /* Order firmware to save current state to NVRAM */
3987 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3988 TP_ACPI_BLTH_SAVE_STATE
))
3989 printk(TPACPI_NOTICE
3990 "failed to save bluetooth state to NVRAM\n");
3992 vdbg_printk(TPACPI_DBG_RFKILL
,
3993 "bluestooth state saved to NVRAM\n");
3996 static void bluetooth_exit(void)
3998 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3999 &bluetooth_attr_group
);
4001 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
4003 bluetooth_shutdown();
4006 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
4011 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4012 "initializing bluetooth subdriver\n");
4014 TPACPI_ACPIHANDLE_INIT(hkey
);
4016 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4017 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
4018 tp_features
.bluetooth
= hkey_handle
&&
4019 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
4021 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4022 "bluetooth is %s, status 0x%02x\n",
4023 str_supported(tp_features
.bluetooth
),
4026 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4027 if (dbg_bluetoothemul
) {
4028 tp_features
.bluetooth
= 1;
4030 "bluetooth switch emulation enabled\n");
4033 if (tp_features
.bluetooth
&&
4034 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
4035 /* no bluetooth hardware present in system */
4036 tp_features
.bluetooth
= 0;
4037 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4038 "bluetooth hardware not installed\n");
4041 if (!tp_features
.bluetooth
)
4044 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
4045 &bluetooth_tprfk_ops
,
4046 RFKILL_TYPE_BLUETOOTH
,
4047 TPACPI_RFK_BLUETOOTH_SW_NAME
,
4052 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4053 &bluetooth_attr_group
);
4055 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
4062 /* procfs -------------------------------------------------------------- */
4063 static int bluetooth_read(struct seq_file
*m
)
4065 return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID
, m
);
4068 static int bluetooth_write(char *buf
)
4070 return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID
, buf
);
4073 static struct ibm_struct bluetooth_driver_data
= {
4074 .name
= "bluetooth",
4075 .read
= bluetooth_read
,
4076 .write
= bluetooth_write
,
4077 .exit
= bluetooth_exit
,
4078 .shutdown
= bluetooth_shutdown
,
4081 /*************************************************************************
4086 /* ACPI GWAN/SWAN bits */
4087 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
4088 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
4089 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
4090 0 = disable, 1 = enable */
4093 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
4095 static int wan_get_status(void)
4099 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4101 return (tpacpi_wwan_emulstate
) ?
4102 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4105 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
4108 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
4109 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4112 static int wan_set_status(enum tpacpi_rfkill_state state
)
4116 vdbg_printk(TPACPI_DBG_RFKILL
,
4117 "will attempt to %s wwan\n",
4118 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4120 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4122 tpacpi_wwan_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4127 if (state
== TPACPI_RFK_RADIO_ON
)
4128 status
= TP_ACPI_WANCARD_RADIOSSW
4129 | TP_ACPI_WANCARD_RESUMECTRL
;
4133 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
4139 /* sysfs wan enable ---------------------------------------------------- */
4140 static ssize_t
wan_enable_show(struct device
*dev
,
4141 struct device_attribute
*attr
,
4144 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID
,
4148 static ssize_t
wan_enable_store(struct device
*dev
,
4149 struct device_attribute
*attr
,
4150 const char *buf
, size_t count
)
4152 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID
,
4156 static struct device_attribute dev_attr_wan_enable
=
4157 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4158 wan_enable_show
, wan_enable_store
);
4160 /* --------------------------------------------------------------------- */
4162 static struct attribute
*wan_attributes
[] = {
4163 &dev_attr_wan_enable
.attr
,
4167 static const struct attribute_group wan_attr_group
= {
4168 .attrs
= wan_attributes
,
4171 static const struct tpacpi_rfk_ops wan_tprfk_ops
= {
4172 .get_status
= wan_get_status
,
4173 .set_status
= wan_set_status
,
4176 static void wan_shutdown(void)
4178 /* Order firmware to save current state to NVRAM */
4179 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4180 TP_ACPI_WGSV_SAVE_STATE
))
4181 printk(TPACPI_NOTICE
4182 "failed to save WWAN state to NVRAM\n");
4184 vdbg_printk(TPACPI_DBG_RFKILL
,
4185 "WWAN state saved to NVRAM\n");
4188 static void wan_exit(void)
4190 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4193 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4198 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4203 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4204 "initializing wan subdriver\n");
4206 TPACPI_ACPIHANDLE_INIT(hkey
);
4208 tp_features
.wan
= hkey_handle
&&
4209 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4211 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4212 "wan is %s, status 0x%02x\n",
4213 str_supported(tp_features
.wan
),
4216 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4218 tp_features
.wan
= 1;
4220 "wwan switch emulation enabled\n");
4223 if (tp_features
.wan
&&
4224 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4225 /* no wan hardware present in system */
4226 tp_features
.wan
= 0;
4227 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4228 "wan hardware not installed\n");
4231 if (!tp_features
.wan
)
4234 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4237 TPACPI_RFK_WWAN_SW_NAME
,
4242 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4246 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4253 /* procfs -------------------------------------------------------------- */
4254 static int wan_read(struct seq_file
*m
)
4256 return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID
, m
);
4259 static int wan_write(char *buf
)
4261 return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID
, buf
);
4264 static struct ibm_struct wan_driver_data
= {
4269 .shutdown
= wan_shutdown
,
4272 /*************************************************************************
4277 /* ACPI GUWB/SUWB bits */
4278 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4279 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4282 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4284 static int uwb_get_status(void)
4288 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4290 return (tpacpi_uwb_emulstate
) ?
4291 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4294 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4297 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4298 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4301 static int uwb_set_status(enum tpacpi_rfkill_state state
)
4305 vdbg_printk(TPACPI_DBG_RFKILL
,
4306 "will attempt to %s UWB\n",
4307 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4309 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4311 tpacpi_uwb_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4316 if (state
== TPACPI_RFK_RADIO_ON
)
4317 status
= TP_ACPI_UWB_RADIOSSW
;
4321 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4327 /* --------------------------------------------------------------------- */
4329 static const struct tpacpi_rfk_ops uwb_tprfk_ops
= {
4330 .get_status
= uwb_get_status
,
4331 .set_status
= uwb_set_status
,
4334 static void uwb_exit(void)
4336 tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID
);
4339 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4344 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4345 "initializing uwb subdriver\n");
4347 TPACPI_ACPIHANDLE_INIT(hkey
);
4349 tp_features
.uwb
= hkey_handle
&&
4350 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4352 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4353 "uwb is %s, status 0x%02x\n",
4354 str_supported(tp_features
.uwb
),
4357 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4359 tp_features
.uwb
= 1;
4361 "uwb switch emulation enabled\n");
4364 if (tp_features
.uwb
&&
4365 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4366 /* no uwb hardware present in system */
4367 tp_features
.uwb
= 0;
4368 dbg_printk(TPACPI_DBG_INIT
,
4369 "uwb hardware not installed\n");
4372 if (!tp_features
.uwb
)
4375 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4378 TPACPI_RFK_UWB_SW_NAME
,
4383 static struct ibm_struct uwb_driver_data
= {
4386 .flags
.experimental
= 1,
4389 /*************************************************************************
4393 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4395 enum video_access_mode
{
4396 TPACPI_VIDEO_NONE
= 0,
4397 TPACPI_VIDEO_570
, /* 570 */
4398 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4399 TPACPI_VIDEO_NEW
, /* all others */
4402 enum { /* video status flags, based on VIDEO_570 */
4403 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4404 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4405 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4408 enum { /* TPACPI_VIDEO_570 constants */
4409 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4410 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4411 * video_status_flags */
4412 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4413 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4416 static enum video_access_mode video_supported
;
4417 static int video_orig_autosw
;
4419 static int video_autosw_get(void);
4420 static int video_autosw_set(int enable
);
4422 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4424 static int __init
video_init(struct ibm_init_struct
*iibm
)
4428 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4430 TPACPI_ACPIHANDLE_INIT(vid
);
4431 TPACPI_ACPIHANDLE_INIT(vid2
);
4433 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4434 /* G41, assume IVGA doesn't change */
4435 vid_handle
= vid2_handle
;
4438 /* video switching not supported on R30, R31 */
4439 video_supported
= TPACPI_VIDEO_NONE
;
4440 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4442 video_supported
= TPACPI_VIDEO_570
;
4443 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4444 /* 600e/x, 770e, 770x */
4445 video_supported
= TPACPI_VIDEO_770
;
4448 video_supported
= TPACPI_VIDEO_NEW
;
4450 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4451 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4454 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4457 static void video_exit(void)
4459 dbg_printk(TPACPI_DBG_EXIT
,
4460 "restoring original video autoswitch mode\n");
4461 if (video_autosw_set(video_orig_autosw
))
4462 printk(TPACPI_ERR
"error while trying to restore original "
4463 "video autoswitch mode\n");
4466 static int video_outputsw_get(void)
4471 switch (video_supported
) {
4472 case TPACPI_VIDEO_570
:
4473 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4474 TP_ACPI_VIDEO_570_PHSCMD
))
4476 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4478 case TPACPI_VIDEO_770
:
4479 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4482 status
|= TP_ACPI_VIDEO_S_LCD
;
4483 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4486 status
|= TP_ACPI_VIDEO_S_CRT
;
4488 case TPACPI_VIDEO_NEW
:
4489 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4490 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4493 status
|= TP_ACPI_VIDEO_S_CRT
;
4495 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4496 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4499 status
|= TP_ACPI_VIDEO_S_LCD
;
4500 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4503 status
|= TP_ACPI_VIDEO_S_DVI
;
4512 static int video_outputsw_set(int status
)
4517 switch (video_supported
) {
4518 case TPACPI_VIDEO_570
:
4519 res
= acpi_evalf(NULL
, NULL
,
4520 "\\_SB.PHS2", "vdd",
4521 TP_ACPI_VIDEO_570_PHS2CMD
,
4522 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4524 case TPACPI_VIDEO_770
:
4525 autosw
= video_autosw_get();
4529 res
= video_autosw_set(1);
4532 res
= acpi_evalf(vid_handle
, NULL
,
4533 "ASWT", "vdd", status
* 0x100, 0);
4534 if (!autosw
&& video_autosw_set(autosw
)) {
4536 "video auto-switch left enabled due to error\n");
4540 case TPACPI_VIDEO_NEW
:
4541 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4542 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4548 return (res
)? 0 : -EIO
;
4551 static int video_autosw_get(void)
4555 switch (video_supported
) {
4556 case TPACPI_VIDEO_570
:
4557 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4560 case TPACPI_VIDEO_770
:
4561 case TPACPI_VIDEO_NEW
:
4562 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4572 static int video_autosw_set(int enable
)
4574 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4579 static int video_outputsw_cycle(void)
4581 int autosw
= video_autosw_get();
4587 switch (video_supported
) {
4588 case TPACPI_VIDEO_570
:
4589 res
= video_autosw_set(1);
4592 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4594 case TPACPI_VIDEO_770
:
4595 case TPACPI_VIDEO_NEW
:
4596 res
= video_autosw_set(1);
4599 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4604 if (!autosw
&& video_autosw_set(autosw
)) {
4606 "video auto-switch left enabled due to error\n");
4610 return (res
)? 0 : -EIO
;
4613 static int video_expand_toggle(void)
4615 switch (video_supported
) {
4616 case TPACPI_VIDEO_570
:
4617 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4619 case TPACPI_VIDEO_770
:
4620 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4622 case TPACPI_VIDEO_NEW
:
4623 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4631 static int video_read(struct seq_file
*m
)
4635 if (video_supported
== TPACPI_VIDEO_NONE
) {
4636 seq_printf(m
, "status:\t\tnot supported\n");
4640 /* Even reads can crash X.org, so... */
4641 if (!capable(CAP_SYS_ADMIN
))
4644 status
= video_outputsw_get();
4648 autosw
= video_autosw_get();
4652 seq_printf(m
, "status:\t\tsupported\n");
4653 seq_printf(m
, "lcd:\t\t%s\n", enabled(status
, 0));
4654 seq_printf(m
, "crt:\t\t%s\n", enabled(status
, 1));
4655 if (video_supported
== TPACPI_VIDEO_NEW
)
4656 seq_printf(m
, "dvi:\t\t%s\n", enabled(status
, 3));
4657 seq_printf(m
, "auto:\t\t%s\n", enabled(autosw
, 0));
4658 seq_printf(m
, "commands:\tlcd_enable, lcd_disable\n");
4659 seq_printf(m
, "commands:\tcrt_enable, crt_disable\n");
4660 if (video_supported
== TPACPI_VIDEO_NEW
)
4661 seq_printf(m
, "commands:\tdvi_enable, dvi_disable\n");
4662 seq_printf(m
, "commands:\tauto_enable, auto_disable\n");
4663 seq_printf(m
, "commands:\tvideo_switch, expand_toggle\n");
4668 static int video_write(char *buf
)
4671 int enable
, disable
, status
;
4674 if (video_supported
== TPACPI_VIDEO_NONE
)
4677 /* Even reads can crash X.org, let alone writes... */
4678 if (!capable(CAP_SYS_ADMIN
))
4684 while ((cmd
= next_cmd(&buf
))) {
4685 if (strlencmp(cmd
, "lcd_enable") == 0) {
4686 enable
|= TP_ACPI_VIDEO_S_LCD
;
4687 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4688 disable
|= TP_ACPI_VIDEO_S_LCD
;
4689 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4690 enable
|= TP_ACPI_VIDEO_S_CRT
;
4691 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4692 disable
|= TP_ACPI_VIDEO_S_CRT
;
4693 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4694 strlencmp(cmd
, "dvi_enable") == 0) {
4695 enable
|= TP_ACPI_VIDEO_S_DVI
;
4696 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4697 strlencmp(cmd
, "dvi_disable") == 0) {
4698 disable
|= TP_ACPI_VIDEO_S_DVI
;
4699 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4700 res
= video_autosw_set(1);
4703 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4704 res
= video_autosw_set(0);
4707 } else if (strlencmp(cmd
, "video_switch") == 0) {
4708 res
= video_outputsw_cycle();
4711 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4712 res
= video_expand_toggle();
4719 if (enable
|| disable
) {
4720 status
= video_outputsw_get();
4723 res
= video_outputsw_set((status
& ~disable
) | enable
);
4731 static struct ibm_struct video_driver_data
= {
4734 .write
= video_write
,
4738 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4740 /*************************************************************************
4741 * Light (thinklight) subdriver
4744 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4745 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4747 static int light_get_status(void)
4751 if (tp_features
.light_status
) {
4752 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4760 static int light_set_status(int status
)
4764 if (tp_features
.light
) {
4766 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4768 TP_CMOS_THINKLIGHT_ON
:
4769 TP_CMOS_THINKLIGHT_OFF
);
4771 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4774 return (rc
)? 0 : -EIO
;
4780 static void light_set_status_worker(struct work_struct
*work
)
4782 struct tpacpi_led_classdev
*data
=
4783 container_of(work
, struct tpacpi_led_classdev
, work
);
4785 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4786 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4789 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4790 enum led_brightness brightness
)
4792 struct tpacpi_led_classdev
*data
=
4793 container_of(led_cdev
,
4794 struct tpacpi_led_classdev
,
4796 data
->new_state
= (brightness
!= LED_OFF
) ?
4797 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4798 queue_work(tpacpi_wq
, &data
->work
);
4801 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4803 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4806 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4808 .name
= "tpacpi::thinklight",
4809 .brightness_set
= &light_sysfs_set
,
4810 .brightness_get
= &light_sysfs_get
,
4814 static int __init
light_init(struct ibm_init_struct
*iibm
)
4818 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4820 TPACPI_ACPIHANDLE_INIT(ledb
);
4821 TPACPI_ACPIHANDLE_INIT(lght
);
4822 TPACPI_ACPIHANDLE_INIT(cmos
);
4823 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4825 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4826 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4828 if (tp_features
.light
)
4829 /* light status not supported on
4830 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4831 tp_features
.light_status
=
4832 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4834 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4835 str_supported(tp_features
.light
),
4836 str_supported(tp_features
.light_status
));
4838 if (!tp_features
.light
)
4841 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4842 &tpacpi_led_thinklight
.led_classdev
);
4845 tp_features
.light
= 0;
4846 tp_features
.light_status
= 0;
4854 static void light_exit(void)
4856 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4857 if (work_pending(&tpacpi_led_thinklight
.work
))
4858 flush_workqueue(tpacpi_wq
);
4861 static int light_read(struct seq_file
*m
)
4865 if (!tp_features
.light
) {
4866 seq_printf(m
, "status:\t\tnot supported\n");
4867 } else if (!tp_features
.light_status
) {
4868 seq_printf(m
, "status:\t\tunknown\n");
4869 seq_printf(m
, "commands:\ton, off\n");
4871 status
= light_get_status();
4874 seq_printf(m
, "status:\t\t%s\n", onoff(status
, 0));
4875 seq_printf(m
, "commands:\ton, off\n");
4881 static int light_write(char *buf
)
4886 if (!tp_features
.light
)
4889 while ((cmd
= next_cmd(&buf
))) {
4890 if (strlencmp(cmd
, "on") == 0) {
4892 } else if (strlencmp(cmd
, "off") == 0) {
4898 return light_set_status(newstatus
);
4901 static struct ibm_struct light_driver_data
= {
4904 .write
= light_write
,
4908 /*************************************************************************
4912 /* sysfs cmos_command -------------------------------------------------- */
4913 static ssize_t
cmos_command_store(struct device
*dev
,
4914 struct device_attribute
*attr
,
4915 const char *buf
, size_t count
)
4917 unsigned long cmos_cmd
;
4920 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4923 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4924 return (res
)? res
: count
;
4927 static struct device_attribute dev_attr_cmos_command
=
4928 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4930 /* --------------------------------------------------------------------- */
4932 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4936 vdbg_printk(TPACPI_DBG_INIT
,
4937 "initializing cmos commands subdriver\n");
4939 TPACPI_ACPIHANDLE_INIT(cmos
);
4941 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4942 str_supported(cmos_handle
!= NULL
));
4944 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4948 return (cmos_handle
)? 0 : 1;
4951 static void cmos_exit(void)
4953 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4956 static int cmos_read(struct seq_file
*m
)
4958 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4959 R30, R31, T20-22, X20-21 */
4961 seq_printf(m
, "status:\t\tnot supported\n");
4963 seq_printf(m
, "status:\t\tsupported\n");
4964 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4970 static int cmos_write(char *buf
)
4975 while ((cmd
= next_cmd(&buf
))) {
4976 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4977 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4982 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4990 static struct ibm_struct cmos_driver_data
= {
4993 .write
= cmos_write
,
4997 /*************************************************************************
5001 enum led_access_mode
{
5002 TPACPI_LED_NONE
= 0,
5003 TPACPI_LED_570
, /* 570 */
5004 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5005 TPACPI_LED_NEW
, /* all others */
5008 enum { /* For TPACPI_LED_OLD */
5009 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
5010 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
5011 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
5014 static enum led_access_mode led_supported
;
5016 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
5017 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
5018 /* T20-22, X20-21 */
5019 "LED", /* all others */
5022 #define TPACPI_LED_NUMLEDS 16
5023 static struct tpacpi_led_classdev
*tpacpi_leds
;
5024 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
5025 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
5026 /* there's a limit of 19 chars + NULL before 2.6.26 */
5028 "tpacpi:orange:batt",
5029 "tpacpi:green:batt",
5030 "tpacpi::dock_active",
5031 "tpacpi::bay_active",
5032 "tpacpi::dock_batt",
5033 "tpacpi::unknown_led",
5035 "tpacpi::dock_status1",
5036 "tpacpi::dock_status2",
5037 "tpacpi::unknown_led2",
5038 "tpacpi::unknown_led3",
5039 "tpacpi::thinkvantage",
5041 #define TPACPI_SAFE_LEDS 0x1081U
5043 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
5045 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5048 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
5052 static int led_get_status(const unsigned int led
)
5055 enum led_status_t led_s
;
5057 switch (led_supported
) {
5058 case TPACPI_LED_570
:
5059 if (!acpi_evalf(ec_handle
,
5060 &status
, "GLED", "dd", 1 << led
))
5062 led_s
= (status
== 0)?
5067 tpacpi_led_state_cache
[led
] = led_s
;
5076 static int led_set_status(const unsigned int led
,
5077 const enum led_status_t ledstatus
)
5079 /* off, on, blink. Index is led_status_t */
5080 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
5081 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
5085 switch (led_supported
) {
5086 case TPACPI_LED_570
:
5088 if (unlikely(led
> 7))
5090 if (unlikely(tpacpi_is_led_restricted(led
)))
5092 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5093 (1 << led
), led_sled_arg1
[ledstatus
]))
5096 case TPACPI_LED_OLD
:
5097 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
5098 if (unlikely(led
> 7))
5100 if (unlikely(tpacpi_is_led_restricted(led
)))
5102 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
5104 rc
= ec_write(TPACPI_LED_EC_HLBL
,
5105 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5107 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5108 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5110 case TPACPI_LED_NEW
:
5112 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5114 if (unlikely(tpacpi_is_led_restricted(led
)))
5116 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5117 led
, led_led_arg1
[ledstatus
]))
5125 tpacpi_led_state_cache
[led
] = ledstatus
;
5130 static void led_set_status_worker(struct work_struct
*work
)
5132 struct tpacpi_led_classdev
*data
=
5133 container_of(work
, struct tpacpi_led_classdev
, work
);
5135 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5136 led_set_status(data
->led
, data
->new_state
);
5139 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5140 enum led_brightness brightness
)
5142 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5143 struct tpacpi_led_classdev
, led_classdev
);
5145 if (brightness
== LED_OFF
)
5146 data
->new_state
= TPACPI_LED_OFF
;
5147 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5148 data
->new_state
= TPACPI_LED_ON
;
5150 data
->new_state
= TPACPI_LED_BLINK
;
5152 queue_work(tpacpi_wq
, &data
->work
);
5155 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5156 unsigned long *delay_on
, unsigned long *delay_off
)
5158 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5159 struct tpacpi_led_classdev
, led_classdev
);
5161 /* Can we choose the flash rate? */
5162 if (*delay_on
== 0 && *delay_off
== 0) {
5163 /* yes. set them to the hardware blink rate (1 Hz) */
5164 *delay_on
= 500; /* ms */
5165 *delay_off
= 500; /* ms */
5166 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5169 data
->new_state
= TPACPI_LED_BLINK
;
5170 queue_work(tpacpi_wq
, &data
->work
);
5175 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5179 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5180 struct tpacpi_led_classdev
, led_classdev
);
5182 rc
= led_get_status(data
->led
);
5184 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5185 rc
= LED_OFF
; /* no error handling in led class :( */
5192 static void led_exit(void)
5196 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5197 if (tpacpi_leds
[i
].led_classdev
.name
)
5198 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5204 static int __init
tpacpi_init_led(unsigned int led
)
5208 tpacpi_leds
[led
].led
= led
;
5210 /* LEDs with no name don't get registered */
5211 if (!tpacpi_led_names
[led
])
5214 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5215 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5216 if (led_supported
== TPACPI_LED_570
)
5217 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5220 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5222 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5224 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5225 &tpacpi_leds
[led
].led_classdev
);
5227 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5232 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5233 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5234 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5235 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5237 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5238 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5239 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5240 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5241 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5242 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5243 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5244 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5246 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5247 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5248 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5249 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5250 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5252 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5253 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5254 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5255 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5257 /* (1) - may have excess leds enabled on MSB */
5259 /* Defaults (order matters, keep last, don't reorder!) */
5261 .vendor
= PCI_VENDOR_ID_LENOVO
,
5262 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5265 { /* IBM ThinkPads with no EC version string */
5266 .vendor
= PCI_VENDOR_ID_IBM
,
5267 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5270 { /* IBM ThinkPads with EC version string */
5271 .vendor
= PCI_VENDOR_ID_IBM
,
5272 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5277 #undef TPACPI_LEDQ_IBM
5278 #undef TPACPI_LEDQ_LNV
5280 static int __init
led_init(struct ibm_init_struct
*iibm
)
5284 unsigned long useful_leds
;
5286 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5288 TPACPI_ACPIHANDLE_INIT(led
);
5291 /* led not supported on R30, R31 */
5292 led_supported
= TPACPI_LED_NONE
;
5293 else if (strlencmp(led_path
, "SLED") == 0)
5295 led_supported
= TPACPI_LED_570
;
5296 else if (strlencmp(led_path
, "SYSL") == 0)
5297 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5298 led_supported
= TPACPI_LED_OLD
;
5301 led_supported
= TPACPI_LED_NEW
;
5303 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5304 str_supported(led_supported
), led_supported
);
5306 if (led_supported
== TPACPI_LED_NONE
)
5309 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5312 printk(TPACPI_ERR
"Out of memory for LED data\n");
5316 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5317 ARRAY_SIZE(led_useful_qtable
));
5319 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5320 if (!tpacpi_is_led_restricted(i
) &&
5321 test_bit(i
, &useful_leds
)) {
5322 rc
= tpacpi_init_led(i
);
5330 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5331 printk(TPACPI_NOTICE
5332 "warning: userspace override of important "
5333 "firmware LEDs is enabled\n");
5338 #define str_led_status(s) \
5339 ((s) == TPACPI_LED_OFF ? "off" : \
5340 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5342 static int led_read(struct seq_file
*m
)
5344 if (!led_supported
) {
5345 seq_printf(m
, "status:\t\tnot supported\n");
5348 seq_printf(m
, "status:\t\tsupported\n");
5350 if (led_supported
== TPACPI_LED_570
) {
5353 for (i
= 0; i
< 8; i
++) {
5354 status
= led_get_status(i
);
5357 seq_printf(m
, "%d:\t\t%s\n",
5358 i
, str_led_status(status
));
5362 seq_printf(m
, "commands:\t"
5363 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5368 static int led_write(char *buf
)
5372 enum led_status_t s
;
5377 while ((cmd
= next_cmd(&buf
))) {
5378 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5381 if (strstr(cmd
, "off")) {
5383 } else if (strstr(cmd
, "on")) {
5385 } else if (strstr(cmd
, "blink")) {
5386 s
= TPACPI_LED_BLINK
;
5391 rc
= led_set_status(led
, s
);
5399 static struct ibm_struct led_driver_data
= {
5406 /*************************************************************************
5410 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5412 #define TPACPI_BEEP_Q1 0x0001
5414 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5415 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5416 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5419 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5421 unsigned long quirks
;
5423 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5425 TPACPI_ACPIHANDLE_INIT(beep
);
5427 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5428 str_supported(beep_handle
!= NULL
));
5430 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5431 ARRAY_SIZE(beep_quirk_table
));
5433 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5435 return (beep_handle
)? 0 : 1;
5438 static int beep_read(struct seq_file
*m
)
5441 seq_printf(m
, "status:\t\tnot supported\n");
5443 seq_printf(m
, "status:\t\tsupported\n");
5444 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5450 static int beep_write(char *buf
)
5458 while ((cmd
= next_cmd(&buf
))) {
5459 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5460 beep_cmd
>= 0 && beep_cmd
<= 17) {
5464 if (tp_features
.beep_needs_two_args
) {
5465 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5469 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5478 static struct ibm_struct beep_driver_data
= {
5481 .write
= beep_write
,
5484 /*************************************************************************
5488 enum thermal_access_mode
{
5489 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5490 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5491 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5492 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5493 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5496 enum { /* TPACPI_THERMAL_TPEC_* */
5497 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5498 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5499 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5501 TPACPI_THERMAL_SENSOR_NA
= -128000, /* Sensor not available */
5505 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5506 struct ibm_thermal_sensors_struct
{
5507 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5510 static enum thermal_access_mode thermal_read_mode
;
5512 /* idx is zero-based */
5513 static int thermal_get_sensor(int idx
, s32
*value
)
5519 t
= TP_EC_THERMAL_TMP0
;
5521 switch (thermal_read_mode
) {
5522 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5523 case TPACPI_THERMAL_TPEC_16
:
5524 if (idx
>= 8 && idx
<= 15) {
5525 t
= TP_EC_THERMAL_TMP8
;
5530 case TPACPI_THERMAL_TPEC_8
:
5532 if (!acpi_ec_read(t
+ idx
, &tmp
))
5534 *value
= tmp
* 1000;
5539 case TPACPI_THERMAL_ACPI_UPDT
:
5541 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5542 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5544 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5546 *value
= (t
- 2732) * 100;
5551 case TPACPI_THERMAL_ACPI_TMP07
:
5553 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5554 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5556 if (t
> 127 || t
< -127)
5557 t
= TP_EC_THERMAL_TMP_NA
;
5563 case TPACPI_THERMAL_NONE
:
5571 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5582 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5585 for (i
= 0 ; i
< n
; i
++) {
5586 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5594 static void thermal_dump_all_sensors(void)
5597 struct ibm_thermal_sensors_struct t
;
5599 n
= thermal_get_sensors(&t
);
5603 printk(TPACPI_NOTICE
5604 "temperatures (Celsius):");
5606 for (i
= 0; i
< n
; i
++) {
5607 if (t
.temp
[i
] != TPACPI_THERMAL_SENSOR_NA
)
5608 printk(KERN_CONT
" %d", (int)(t
.temp
[i
] / 1000));
5610 printk(KERN_CONT
" N/A");
5613 printk(KERN_CONT
"\n");
5616 /* sysfs temp##_input -------------------------------------------------- */
5618 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5619 struct device_attribute
*attr
,
5622 struct sensor_device_attribute
*sensor_attr
=
5623 to_sensor_dev_attr(attr
);
5624 int idx
= sensor_attr
->index
;
5628 res
= thermal_get_sensor(idx
, &value
);
5631 if (value
== TPACPI_THERMAL_SENSOR_NA
)
5634 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5637 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5638 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5639 thermal_temp_input_show, NULL, _idxB)
5641 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5642 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5643 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5644 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5645 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5646 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5647 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5648 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5649 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5650 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5651 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5652 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5653 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5654 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5655 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5656 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5657 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5660 #define THERMAL_ATTRS(X) \
5661 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5663 static struct attribute
*thermal_temp_input_attr
[] = {
5683 static const struct attribute_group thermal_temp_input16_group
= {
5684 .attrs
= thermal_temp_input_attr
5687 static const struct attribute_group thermal_temp_input8_group
= {
5688 .attrs
= &thermal_temp_input_attr
[8]
5691 #undef THERMAL_SENSOR_ATTR_TEMP
5692 #undef THERMAL_ATTRS
5694 /* --------------------------------------------------------------------- */
5696 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5703 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5705 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5707 if (thinkpad_id
.ec_model
) {
5709 * Direct EC access mode: sensors at registers
5710 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5711 * non-implemented, thermal sensors return 0x80 when
5716 for (i
= 0; i
< 8; i
++) {
5717 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5723 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5731 /* This is sheer paranoia, but we handle it anyway */
5734 "ThinkPad ACPI EC access misbehaving, "
5735 "falling back to ACPI TMPx access "
5737 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5740 "ThinkPad ACPI EC access misbehaving, "
5741 "disabling thermal sensors access\n");
5742 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5747 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5749 } else if (acpi_tmp7
) {
5750 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5751 /* 600e/x, 770e, 770x */
5752 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5754 /* Standard ACPI TMPx access, max 8 sensors */
5755 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5758 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5759 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5762 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5763 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5766 switch (thermal_read_mode
) {
5767 case TPACPI_THERMAL_TPEC_16
:
5768 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5769 &thermal_temp_input16_group
);
5773 case TPACPI_THERMAL_TPEC_8
:
5774 case TPACPI_THERMAL_ACPI_TMP07
:
5775 case TPACPI_THERMAL_ACPI_UPDT
:
5776 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5777 &thermal_temp_input8_group
);
5781 case TPACPI_THERMAL_NONE
:
5789 static void thermal_exit(void)
5791 switch (thermal_read_mode
) {
5792 case TPACPI_THERMAL_TPEC_16
:
5793 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5794 &thermal_temp_input16_group
);
5796 case TPACPI_THERMAL_TPEC_8
:
5797 case TPACPI_THERMAL_ACPI_TMP07
:
5798 case TPACPI_THERMAL_ACPI_UPDT
:
5799 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5800 &thermal_temp_input8_group
);
5802 case TPACPI_THERMAL_NONE
:
5808 static int thermal_read(struct seq_file
*m
)
5811 struct ibm_thermal_sensors_struct t
;
5813 n
= thermal_get_sensors(&t
);
5814 if (unlikely(n
< 0))
5817 seq_printf(m
, "temperatures:\t");
5820 for (i
= 0; i
< (n
- 1); i
++)
5821 seq_printf(m
, "%d ", t
.temp
[i
] / 1000);
5822 seq_printf(m
, "%d\n", t
.temp
[i
] / 1000);
5824 seq_printf(m
, "not supported\n");
5829 static struct ibm_struct thermal_driver_data
= {
5831 .read
= thermal_read
,
5832 .exit
= thermal_exit
,
5835 /*************************************************************************
5839 static u8 ecdump_regs
[256];
5841 static int ecdump_read(struct seq_file
*m
)
5847 " +00 +01 +02 +03 +04 +05 +06 +07"
5848 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5849 for (i
= 0; i
< 256; i
+= 16) {
5850 seq_printf(m
, "EC 0x%02x:", i
);
5851 for (j
= 0; j
< 16; j
++) {
5852 if (!acpi_ec_read(i
+ j
, &v
))
5854 if (v
!= ecdump_regs
[i
+ j
])
5855 seq_printf(m
, " *%02x", v
);
5857 seq_printf(m
, " %02x", v
);
5858 ecdump_regs
[i
+ j
] = v
;
5865 /* These are way too dangerous to advertise openly... */
5867 seq_printf(m
, "commands:\t0x<offset> 0x<value>"
5868 " (<offset> is 00-ff, <value> is 00-ff)\n");
5869 seq_printf(m
, "commands:\t0x<offset> <value> "
5870 " (<offset> is 00-ff, <value> is 0-255)\n");
5875 static int ecdump_write(char *buf
)
5880 while ((cmd
= next_cmd(&buf
))) {
5881 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5883 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5887 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5888 if (!acpi_ec_write(i
, v
))
5897 static struct ibm_struct ecdump_driver_data
= {
5899 .read
= ecdump_read
,
5900 .write
= ecdump_write
,
5901 .flags
.experimental
= 1,
5904 /*************************************************************************
5905 * Backlight/brightness subdriver
5908 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5911 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5912 * CMOS NVRAM byte 0x5E, bits 0-3.
5914 * EC HBRV (0x31) has the following layout
5915 * Bit 7: unknown function
5916 * Bit 6: unknown function
5917 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5918 * Bit 4: must be set to zero to avoid problems
5919 * Bit 3-0: backlight brightness level
5921 * brightness_get_raw returns status data in the HBRV layout
5923 * WARNING: The X61 has been verified to use HBRV for something else, so
5924 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5925 * testing on the very early *60 Lenovo models...
5929 TP_EC_BACKLIGHT
= 0x31,
5931 /* TP_EC_BACKLIGHT bitmasks */
5932 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5933 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5934 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5937 enum tpacpi_brightness_access_mode
{
5938 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5939 TPACPI_BRGHT_MODE_EC
, /* EC control */
5940 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5941 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5942 TPACPI_BRGHT_MODE_MAX
5945 static struct backlight_device
*ibm_backlight_device
;
5947 static enum tpacpi_brightness_access_mode brightness_mode
=
5948 TPACPI_BRGHT_MODE_MAX
;
5950 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5952 static struct mutex brightness_mutex
;
5954 /* NVRAM brightness access,
5955 * call with brightness_mutex held! */
5956 static unsigned int tpacpi_brightness_nvram_get(void)
5960 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5961 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5962 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5963 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5968 static void tpacpi_brightness_checkpoint_nvram(void)
5973 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5976 vdbg_printk(TPACPI_DBG_BRGHT
,
5977 "trying to checkpoint backlight level to NVRAM...\n");
5979 if (mutex_lock_killable(&brightness_mutex
) < 0)
5982 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5984 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5985 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5987 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5988 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5989 /* NVRAM needs update */
5990 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5991 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5993 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5994 dbg_printk(TPACPI_DBG_BRGHT
,
5995 "updated NVRAM backlight level to %u (0x%02x)\n",
5996 (unsigned int) lec
, (unsigned int) b_nvram
);
5998 vdbg_printk(TPACPI_DBG_BRGHT
,
5999 "NVRAM backlight level already is %u (0x%02x)\n",
6000 (unsigned int) lec
, (unsigned int) b_nvram
);
6003 mutex_unlock(&brightness_mutex
);
6007 /* call with brightness_mutex held! */
6008 static int tpacpi_brightness_get_raw(int *status
)
6012 switch (brightness_mode
) {
6013 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6014 *status
= tpacpi_brightness_nvram_get();
6016 case TPACPI_BRGHT_MODE_EC
:
6017 case TPACPI_BRGHT_MODE_ECNVRAM
:
6018 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6027 /* call with brightness_mutex held! */
6028 /* do NOT call with illegal backlight level value */
6029 static int tpacpi_brightness_set_ec(unsigned int value
)
6033 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6036 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
6037 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
6038 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
6044 /* call with brightness_mutex held! */
6045 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
6048 unsigned int current_value
, i
;
6050 current_value
= tpacpi_brightness_nvram_get();
6052 if (value
== current_value
)
6055 cmos_cmd
= (value
> current_value
) ?
6056 TP_CMOS_BRIGHTNESS_UP
:
6057 TP_CMOS_BRIGHTNESS_DOWN
;
6058 inc
= (value
> current_value
) ? 1 : -1;
6060 for (i
= current_value
; i
!= value
; i
+= inc
)
6061 if (issue_thinkpad_cmos_command(cmos_cmd
))
6067 /* May return EINTR which can always be mapped to ERESTARTSYS */
6068 static int brightness_set(unsigned int value
)
6072 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
6076 vdbg_printk(TPACPI_DBG_BRGHT
,
6077 "set backlight level to %d\n", value
);
6079 res
= mutex_lock_killable(&brightness_mutex
);
6083 switch (brightness_mode
) {
6084 case TPACPI_BRGHT_MODE_EC
:
6085 case TPACPI_BRGHT_MODE_ECNVRAM
:
6086 res
= tpacpi_brightness_set_ec(value
);
6088 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6089 res
= tpacpi_brightness_set_ucmsstep(value
);
6095 mutex_unlock(&brightness_mutex
);
6099 /* sysfs backlight class ----------------------------------------------- */
6101 static int brightness_update_status(struct backlight_device
*bd
)
6103 unsigned int level
=
6104 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
6105 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
6106 bd
->props
.brightness
: 0;
6108 dbg_printk(TPACPI_DBG_BRGHT
,
6109 "backlight: attempt to set level to %d\n",
6112 /* it is the backlight class's job (caller) to handle
6113 * EINTR and other errors properly */
6114 return brightness_set(level
);
6117 static int brightness_get(struct backlight_device
*bd
)
6121 res
= mutex_lock_killable(&brightness_mutex
);
6125 res
= tpacpi_brightness_get_raw(&status
);
6127 mutex_unlock(&brightness_mutex
);
6132 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6135 static void tpacpi_brightness_notify_change(void)
6137 backlight_force_update(ibm_backlight_device
,
6138 BACKLIGHT_UPDATE_HOTKEY
);
6141 static struct backlight_ops ibm_backlight_data
= {
6142 .get_brightness
= brightness_get
,
6143 .update_status
= brightness_update_status
,
6146 /* --------------------------------------------------------------------- */
6149 * These are only useful for models that have only one possibility
6150 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6153 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6154 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6155 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6157 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6158 /* Models with ATI GPUs known to require ECNVRAM mode */
6159 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6161 /* Models with ATI GPUs that can use ECNVRAM */
6162 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
), /* R50,51 T40-42 */
6163 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6164 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC
), /* R52 */
6165 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6167 /* Models with Intel Extreme Graphics 2 */
6168 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
), /* X40 */
6169 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6170 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6172 /* Models with Intel GMA900 */
6173 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6174 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6175 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6178 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6181 unsigned long quirks
;
6183 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6185 mutex_init(&brightness_mutex
);
6187 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6188 ARRAY_SIZE(brightness_quirk_table
));
6191 * We always attempt to detect acpi support, so as to switch
6192 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6193 * going to publish a backlight interface
6195 b
= tpacpi_check_std_acpi_brightness_support();
6198 if (acpi_video_backlight_support()) {
6199 if (brightness_enable
> 1) {
6200 printk(TPACPI_NOTICE
6201 "Standard ACPI backlight interface "
6202 "available, not loading native one.\n");
6204 } else if (brightness_enable
== 1) {
6205 printk(TPACPI_NOTICE
6206 "Backlight control force enabled, even if standard "
6207 "ACPI backlight interface is available\n");
6210 if (brightness_enable
> 1) {
6211 printk(TPACPI_NOTICE
6212 "Standard ACPI backlight interface not "
6213 "available, thinkpad_acpi native "
6214 "brightness control enabled\n");
6219 if (!brightness_enable
) {
6220 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6221 "brightness support disabled by "
6222 "module parameter\n");
6228 "Unsupported brightness interface, "
6229 "please contact %s\n", TPACPI_MAIL
);
6233 tp_features
.bright_16levels
= 1;
6236 * Check for module parameter bogosity, note that we
6237 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6238 * able to detect "unspecified"
6240 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6243 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6244 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6245 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6246 if (quirks
& TPACPI_BRGHT_Q_EC
)
6247 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6249 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6251 dbg_printk(TPACPI_DBG_BRGHT
,
6252 "driver auto-selected brightness_mode=%d\n",
6257 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6258 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6259 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6262 if (tpacpi_brightness_get_raw(&b
) < 0)
6265 if (tp_features
.bright_16levels
)
6267 "detected a 16-level brightness capable ThinkPad\n");
6269 ibm_backlight_device
= backlight_device_register(
6270 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6271 &ibm_backlight_data
);
6272 if (IS_ERR(ibm_backlight_device
)) {
6273 int rc
= PTR_ERR(ibm_backlight_device
);
6274 ibm_backlight_device
= NULL
;
6275 printk(TPACPI_ERR
"Could not register backlight device\n");
6278 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6279 "brightness is supported\n");
6281 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6282 printk(TPACPI_NOTICE
6283 "brightness: will use unverified default: "
6284 "brightness_mode=%d\n", brightness_mode
);
6285 printk(TPACPI_NOTICE
6286 "brightness: please report to %s whether it works well "
6287 "or not on your ThinkPad\n", TPACPI_MAIL
);
6290 ibm_backlight_device
->props
.max_brightness
=
6291 (tp_features
.bright_16levels
)? 15 : 7;
6292 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6293 backlight_update_status(ibm_backlight_device
);
6295 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6296 "brightness: registering brightness hotkeys "
6297 "as change notification\n");
6298 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6299 | TP_ACPI_HKEY_BRGHTUP_MASK
6300 | TP_ACPI_HKEY_BRGHTDWN_MASK
);;
6304 static void brightness_suspend(pm_message_t state
)
6306 tpacpi_brightness_checkpoint_nvram();
6309 static void brightness_shutdown(void)
6311 tpacpi_brightness_checkpoint_nvram();
6314 static void brightness_exit(void)
6316 if (ibm_backlight_device
) {
6317 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6318 "calling backlight_device_unregister()\n");
6319 backlight_device_unregister(ibm_backlight_device
);
6322 tpacpi_brightness_checkpoint_nvram();
6325 static int brightness_read(struct seq_file
*m
)
6329 level
= brightness_get(NULL
);
6331 seq_printf(m
, "level:\t\tunreadable\n");
6333 seq_printf(m
, "level:\t\t%d\n", level
);
6334 seq_printf(m
, "commands:\tup, down\n");
6335 seq_printf(m
, "commands:\tlevel <level>"
6336 " (<level> is 0-%d)\n",
6337 (tp_features
.bright_16levels
) ? 15 : 7);
6343 static int brightness_write(char *buf
)
6348 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6350 level
= brightness_get(NULL
);
6354 while ((cmd
= next_cmd(&buf
))) {
6355 if (strlencmp(cmd
, "up") == 0) {
6356 if (level
< max_level
)
6358 } else if (strlencmp(cmd
, "down") == 0) {
6361 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6362 level
>= 0 && level
<= max_level
) {
6368 tpacpi_disclose_usertask("procfs brightness",
6369 "set level to %d\n", level
);
6372 * Now we know what the final level should be, so we try to set it.
6373 * Doing it this way makes the syscall restartable in case of EINTR
6375 rc
= brightness_set(level
);
6376 if (!rc
&& ibm_backlight_device
)
6377 backlight_force_update(ibm_backlight_device
,
6378 BACKLIGHT_UPDATE_SYSFS
);
6379 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6382 static struct ibm_struct brightness_driver_data
= {
6383 .name
= "brightness",
6384 .read
= brightness_read
,
6385 .write
= brightness_write
,
6386 .exit
= brightness_exit
,
6387 .suspend
= brightness_suspend
,
6388 .shutdown
= brightness_shutdown
,
6391 /*************************************************************************
6396 * IBM ThinkPads have a simple volume controller with MUTE gating.
6397 * Very early Lenovo ThinkPads follow the IBM ThinkPad spec.
6399 * Since the *61 series (and probably also the later *60 series), Lenovo
6400 * ThinkPads only implement the MUTE gate.
6403 * Bit 6: MUTE (1 mutes sound)
6405 * Other bits should be zero as far as we know.
6407 * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and
6408 * bits 3-0 (volume). Other bits in NVRAM may have other functions,
6409 * such as bit 7 which is used to detect repeated presses of MUTE,
6410 * and we leave them unchanged.
6413 #define TPACPI_ALSA_DRVNAME "ThinkPad EC"
6414 #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control"
6415 #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME
6417 static int alsa_index
= ~((1 << (SNDRV_CARDS
- 3)) - 1); /* last three slots */
6418 static char *alsa_id
= "ThinkPadEC";
6419 static int alsa_enable
= SNDRV_DEFAULT_ENABLE1
;
6421 struct tpacpi_alsa_data
{
6422 struct snd_card
*card
;
6423 struct snd_ctl_elem_id
*ctl_mute_id
;
6424 struct snd_ctl_elem_id
*ctl_vol_id
;
6427 static struct snd_card
*alsa_card
;
6432 /* TP_EC_AUDIO bits */
6433 TP_EC_AUDIO_MUTESW
= 6,
6435 /* TP_EC_AUDIO bitmasks */
6436 TP_EC_AUDIO_LVL_MSK
= 0x0F,
6437 TP_EC_AUDIO_MUTESW_MSK
= (1 << TP_EC_AUDIO_MUTESW
),
6439 /* Maximum volume */
6440 TP_EC_VOLUME_MAX
= 14,
6443 enum tpacpi_volume_access_mode
{
6444 TPACPI_VOL_MODE_AUTO
= 0, /* Not implemented yet */
6445 TPACPI_VOL_MODE_EC
, /* Pure EC control */
6446 TPACPI_VOL_MODE_UCMS_STEP
, /* UCMS step-based control: N/A */
6447 TPACPI_VOL_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
6451 enum tpacpi_volume_capabilities
{
6452 TPACPI_VOL_CAP_AUTO
= 0, /* Use white/blacklist */
6453 TPACPI_VOL_CAP_VOLMUTE
, /* Output vol and mute */
6454 TPACPI_VOL_CAP_MUTEONLY
, /* Output mute only */
6458 static enum tpacpi_volume_access_mode volume_mode
=
6459 TPACPI_VOL_MODE_MAX
;
6461 static enum tpacpi_volume_capabilities volume_capabilities
;
6462 static int volume_control_allowed
;
6465 * Used to syncronize writers to TP_EC_AUDIO and
6466 * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write
6468 static struct mutex volume_mutex
;
6470 static void tpacpi_volume_checkpoint_nvram(void)
6476 if (volume_mode
!= TPACPI_VOL_MODE_ECNVRAM
)
6478 if (!volume_control_allowed
)
6481 vdbg_printk(TPACPI_DBG_MIXER
,
6482 "trying to checkpoint mixer state to NVRAM...\n");
6484 if (tp_features
.mixer_no_level_control
)
6485 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
;
6487 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
| TP_EC_AUDIO_LVL_MSK
;
6489 if (mutex_lock_killable(&volume_mutex
) < 0)
6492 if (unlikely(!acpi_ec_read(TP_EC_AUDIO
, &lec
)))
6495 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
6497 if (lec
!= (b_nvram
& ec_mask
)) {
6498 /* NVRAM needs update */
6499 b_nvram
&= ~ec_mask
;
6501 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_MIXER
);
6502 dbg_printk(TPACPI_DBG_MIXER
,
6503 "updated NVRAM mixer status to 0x%02x (0x%02x)\n",
6504 (unsigned int) lec
, (unsigned int) b_nvram
);
6506 vdbg_printk(TPACPI_DBG_MIXER
,
6507 "NVRAM mixer status already is 0x%02x (0x%02x)\n",
6508 (unsigned int) lec
, (unsigned int) b_nvram
);
6512 mutex_unlock(&volume_mutex
);
6515 static int volume_get_status_ec(u8
*status
)
6519 if (!acpi_ec_read(TP_EC_AUDIO
, &s
))
6524 dbg_printk(TPACPI_DBG_MIXER
, "status 0x%02x\n", s
);
6529 static int volume_get_status(u8
*status
)
6531 return volume_get_status_ec(status
);
6534 static int volume_set_status_ec(const u8 status
)
6536 if (!acpi_ec_write(TP_EC_AUDIO
, status
))
6539 dbg_printk(TPACPI_DBG_MIXER
, "set EC mixer to 0x%02x\n", status
);
6544 static int volume_set_status(const u8 status
)
6546 return volume_set_status_ec(status
);
6549 static int volume_set_mute_ec(const bool mute
)
6554 if (mutex_lock_killable(&volume_mutex
) < 0)
6557 rc
= volume_get_status_ec(&s
);
6561 n
= (mute
) ? s
| TP_EC_AUDIO_MUTESW_MSK
:
6562 s
& ~TP_EC_AUDIO_MUTESW_MSK
;
6565 rc
= volume_set_status_ec(n
);
6568 mutex_unlock(&volume_mutex
);
6572 static int volume_set_mute(const bool mute
)
6574 dbg_printk(TPACPI_DBG_MIXER
, "trying to %smute\n",
6575 (mute
) ? "" : "un");
6576 return volume_set_mute_ec(mute
);
6579 static int volume_set_volume_ec(const u8 vol
)
6584 if (vol
> TP_EC_VOLUME_MAX
)
6587 if (mutex_lock_killable(&volume_mutex
) < 0)
6590 rc
= volume_get_status_ec(&s
);
6594 n
= (s
& ~TP_EC_AUDIO_LVL_MSK
) | vol
;
6597 rc
= volume_set_status_ec(n
);
6600 mutex_unlock(&volume_mutex
);
6604 static int volume_set_volume(const u8 vol
)
6606 dbg_printk(TPACPI_DBG_MIXER
,
6607 "trying to set volume level to %hu\n", vol
);
6608 return volume_set_volume_ec(vol
);
6611 static void volume_alsa_notify_change(void)
6613 struct tpacpi_alsa_data
*d
;
6615 if (alsa_card
&& alsa_card
->private_data
) {
6616 d
= alsa_card
->private_data
;
6618 snd_ctl_notify(alsa_card
,
6619 SNDRV_CTL_EVENT_MASK_VALUE
,
6622 snd_ctl_notify(alsa_card
,
6623 SNDRV_CTL_EVENT_MASK_VALUE
,
6628 static int volume_alsa_vol_info(struct snd_kcontrol
*kcontrol
,
6629 struct snd_ctl_elem_info
*uinfo
)
6631 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
6633 uinfo
->value
.integer
.min
= 0;
6634 uinfo
->value
.integer
.max
= TP_EC_VOLUME_MAX
;
6638 static int volume_alsa_vol_get(struct snd_kcontrol
*kcontrol
,
6639 struct snd_ctl_elem_value
*ucontrol
)
6644 rc
= volume_get_status(&s
);
6648 ucontrol
->value
.integer
.value
[0] = s
& TP_EC_AUDIO_LVL_MSK
;
6652 static int volume_alsa_vol_put(struct snd_kcontrol
*kcontrol
,
6653 struct snd_ctl_elem_value
*ucontrol
)
6655 return volume_set_volume(ucontrol
->value
.integer
.value
[0]);
6658 #define volume_alsa_mute_info snd_ctl_boolean_mono_info
6660 static int volume_alsa_mute_get(struct snd_kcontrol
*kcontrol
,
6661 struct snd_ctl_elem_value
*ucontrol
)
6666 rc
= volume_get_status(&s
);
6670 ucontrol
->value
.integer
.value
[0] =
6671 (s
& TP_EC_AUDIO_MUTESW_MSK
) ? 0 : 1;
6675 static int volume_alsa_mute_put(struct snd_kcontrol
*kcontrol
,
6676 struct snd_ctl_elem_value
*ucontrol
)
6678 return volume_set_mute(!ucontrol
->value
.integer
.value
[0]);
6681 static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata
= {
6682 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6683 .name
= "Console Playback Volume",
6685 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6686 .info
= volume_alsa_vol_info
,
6687 .get
= volume_alsa_vol_get
,
6690 static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata
= {
6691 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6692 .name
= "Console Playback Switch",
6694 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6695 .info
= volume_alsa_mute_info
,
6696 .get
= volume_alsa_mute_get
,
6699 static void volume_suspend(pm_message_t state
)
6701 tpacpi_volume_checkpoint_nvram();
6704 static void volume_resume(void)
6706 volume_alsa_notify_change();
6709 static void volume_shutdown(void)
6711 tpacpi_volume_checkpoint_nvram();
6714 static void volume_exit(void)
6717 snd_card_free(alsa_card
);
6721 tpacpi_volume_checkpoint_nvram();
6724 static int __init
volume_create_alsa_mixer(void)
6726 struct snd_card
*card
;
6727 struct tpacpi_alsa_data
*data
;
6728 struct snd_kcontrol
*ctl_vol
;
6729 struct snd_kcontrol
*ctl_mute
;
6732 rc
= snd_card_create(alsa_index
, alsa_id
, THIS_MODULE
,
6733 sizeof(struct tpacpi_alsa_data
), &card
);
6734 if (rc
< 0 || !card
) {
6736 "Failed to create ALSA card structures: %d\n", rc
);
6740 BUG_ON(!card
->private_data
);
6741 data
= card
->private_data
;
6744 strlcpy(card
->driver
, TPACPI_ALSA_DRVNAME
,
6745 sizeof(card
->driver
));
6746 strlcpy(card
->shortname
, TPACPI_ALSA_SHRTNAME
,
6747 sizeof(card
->shortname
));
6748 snprintf(card
->mixername
, sizeof(card
->mixername
), "ThinkPad EC %s",
6749 (thinkpad_id
.ec_version_str
) ?
6750 thinkpad_id
.ec_version_str
: "(unknown)");
6751 snprintf(card
->longname
, sizeof(card
->longname
),
6752 "%s at EC reg 0x%02x, fw %s", card
->shortname
, TP_EC_AUDIO
,
6753 (thinkpad_id
.ec_version_str
) ?
6754 thinkpad_id
.ec_version_str
: "unknown");
6756 if (volume_control_allowed
) {
6757 volume_alsa_control_vol
.put
= volume_alsa_vol_put
;
6758 volume_alsa_control_vol
.access
=
6759 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6761 volume_alsa_control_mute
.put
= volume_alsa_mute_put
;
6762 volume_alsa_control_mute
.access
=
6763 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6766 if (!tp_features
.mixer_no_level_control
) {
6767 ctl_vol
= snd_ctl_new1(&volume_alsa_control_vol
, NULL
);
6768 rc
= snd_ctl_add(card
, ctl_vol
);
6771 "Failed to create ALSA volume control: %d\n",
6775 data
->ctl_vol_id
= &ctl_vol
->id
;
6778 ctl_mute
= snd_ctl_new1(&volume_alsa_control_mute
, NULL
);
6779 rc
= snd_ctl_add(card
, ctl_mute
);
6781 printk(TPACPI_ERR
"Failed to create ALSA mute control: %d\n",
6785 data
->ctl_mute_id
= &ctl_mute
->id
;
6787 snd_card_set_dev(card
, &tpacpi_pdev
->dev
);
6788 rc
= snd_card_register(card
);
6790 printk(TPACPI_ERR
"Failed to register ALSA card: %d\n", rc
);
6798 snd_card_free(card
);
6802 #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */
6803 #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */
6805 static const struct tpacpi_quirk volume_quirk_table
[] __initconst
= {
6806 /* Whitelist volume level on all IBM by default */
6807 { .vendor
= PCI_VENDOR_ID_IBM
,
6808 .bios
= TPACPI_MATCH_ANY
,
6809 .ec
= TPACPI_MATCH_ANY
,
6810 .quirks
= TPACPI_VOL_Q_LEVEL
},
6812 /* Lenovo models with volume control (needs confirmation) */
6813 TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL
), /* R60/i */
6814 TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL
), /* R60e/i */
6815 TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL
), /* T60/p */
6816 TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL
), /* X60/s */
6817 TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL
), /* X60t */
6818 TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL
), /* Z60 */
6819 TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL
), /* Z61 */
6821 /* Whitelist mute-only on all Lenovo by default */
6822 { .vendor
= PCI_VENDOR_ID_LENOVO
,
6823 .bios
= TPACPI_MATCH_ANY
,
6824 .ec
= TPACPI_MATCH_ANY
,
6825 .quirks
= TPACPI_VOL_Q_MUTEONLY
}
6828 static int __init
volume_init(struct ibm_init_struct
*iibm
)
6830 unsigned long quirks
;
6833 vdbg_printk(TPACPI_DBG_INIT
, "initializing volume subdriver\n");
6835 mutex_init(&volume_mutex
);
6838 * Check for module parameter bogosity, note that we
6839 * init volume_mode to TPACPI_VOL_MODE_MAX in order to be
6840 * able to detect "unspecified"
6842 if (volume_mode
> TPACPI_VOL_MODE_MAX
)
6845 if (volume_mode
== TPACPI_VOL_MODE_UCMS_STEP
) {
6847 "UCMS step volume mode not implemented, "
6848 "please contact %s\n", TPACPI_MAIL
);
6852 if (volume_capabilities
>= TPACPI_VOL_CAP_MAX
)
6856 * The ALSA mixer is our primary interface.
6857 * When disabled, don't install the subdriver at all
6860 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6861 "ALSA mixer disabled by parameter, "
6862 "not loading volume subdriver...\n");
6866 quirks
= tpacpi_check_quirks(volume_quirk_table
,
6867 ARRAY_SIZE(volume_quirk_table
));
6869 switch (volume_capabilities
) {
6870 case TPACPI_VOL_CAP_AUTO
:
6871 if (quirks
& TPACPI_VOL_Q_MUTEONLY
)
6872 tp_features
.mixer_no_level_control
= 1;
6873 else if (quirks
& TPACPI_VOL_Q_LEVEL
)
6874 tp_features
.mixer_no_level_control
= 0;
6876 return 1; /* no mixer */
6878 case TPACPI_VOL_CAP_VOLMUTE
:
6879 tp_features
.mixer_no_level_control
= 0;
6881 case TPACPI_VOL_CAP_MUTEONLY
:
6882 tp_features
.mixer_no_level_control
= 1;
6888 if (volume_capabilities
!= TPACPI_VOL_CAP_AUTO
)
6889 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6890 "using user-supplied volume_capabilities=%d\n",
6891 volume_capabilities
);
6893 if (volume_mode
== TPACPI_VOL_MODE_AUTO
||
6894 volume_mode
== TPACPI_VOL_MODE_MAX
) {
6895 volume_mode
= TPACPI_VOL_MODE_ECNVRAM
;
6897 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6898 "driver auto-selected volume_mode=%d\n",
6901 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6902 "using user-supplied volume_mode=%d\n",
6906 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6907 "mute is supported, volume control is %s\n",
6908 str_supported(!tp_features
.mixer_no_level_control
));
6910 rc
= volume_create_alsa_mixer();
6913 "Could not create the ALSA mixer interface\n");
6918 "Console audio control enabled, mode: %s\n",
6919 (volume_control_allowed
) ?
6920 "override (read/write)" :
6921 "monitor (read only)");
6923 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6924 "registering volume hotkeys as change notification\n");
6925 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6926 | TP_ACPI_HKEY_VOLUP_MASK
6927 | TP_ACPI_HKEY_VOLDWN_MASK
6928 | TP_ACPI_HKEY_MUTE_MASK
);
6933 static int volume_read(struct seq_file
*m
)
6937 if (volume_get_status(&status
) < 0) {
6938 seq_printf(m
, "level:\t\tunreadable\n");
6940 if (tp_features
.mixer_no_level_control
)
6941 seq_printf(m
, "level:\t\tunsupported\n");
6943 seq_printf(m
, "level:\t\t%d\n",
6944 status
& TP_EC_AUDIO_LVL_MSK
);
6946 seq_printf(m
, "mute:\t\t%s\n",
6947 onoff(status
, TP_EC_AUDIO_MUTESW
));
6949 if (volume_control_allowed
) {
6950 seq_printf(m
, "commands:\tunmute, mute\n");
6951 if (!tp_features
.mixer_no_level_control
) {
6953 "commands:\tup, down\n");
6955 "commands:\tlevel <level>"
6956 " (<level> is 0-%d)\n",
6965 static int volume_write(char *buf
)
6968 u8 new_level
, new_mute
;
6974 * We do allow volume control at driver startup, so that the
6975 * user can set initial state through the volume=... parameter hack.
6977 if (!volume_control_allowed
&& tpacpi_lifecycle
!= TPACPI_LIFE_INIT
) {
6978 if (unlikely(!tp_warned
.volume_ctrl_forbidden
)) {
6979 tp_warned
.volume_ctrl_forbidden
= 1;
6980 printk(TPACPI_NOTICE
6981 "Console audio control in monitor mode, "
6982 "changes are not allowed.\n");
6983 printk(TPACPI_NOTICE
6984 "Use the volume_control=1 module parameter "
6985 "to enable volume control\n");
6990 rc
= volume_get_status(&s
);
6994 new_level
= s
& TP_EC_AUDIO_LVL_MSK
;
6995 new_mute
= s
& TP_EC_AUDIO_MUTESW_MSK
;
6997 while ((cmd
= next_cmd(&buf
))) {
6998 if (!tp_features
.mixer_no_level_control
) {
6999 if (strlencmp(cmd
, "up") == 0) {
7002 else if (new_level
< TP_EC_VOLUME_MAX
)
7005 } else if (strlencmp(cmd
, "down") == 0) {
7008 else if (new_level
> 0)
7011 } else if (sscanf(cmd
, "level %u", &l
) == 1 &&
7012 l
>= 0 && l
<= TP_EC_VOLUME_MAX
) {
7017 if (strlencmp(cmd
, "mute") == 0)
7018 new_mute
= TP_EC_AUDIO_MUTESW_MSK
;
7019 else if (strlencmp(cmd
, "unmute") == 0)
7025 if (tp_features
.mixer_no_level_control
) {
7026 tpacpi_disclose_usertask("procfs volume", "%smute\n",
7027 new_mute
? "" : "un");
7028 rc
= volume_set_mute(!!new_mute
);
7030 tpacpi_disclose_usertask("procfs volume",
7031 "%smute and set level to %d\n",
7032 new_mute
? "" : "un", new_level
);
7033 rc
= volume_set_status(new_mute
| new_level
);
7035 volume_alsa_notify_change();
7037 return (rc
== -EINTR
) ? -ERESTARTSYS
: rc
;
7040 static struct ibm_struct volume_driver_data
= {
7042 .read
= volume_read
,
7043 .write
= volume_write
,
7044 .exit
= volume_exit
,
7045 .suspend
= volume_suspend
,
7046 .resume
= volume_resume
,
7047 .shutdown
= volume_shutdown
,
7050 /*************************************************************************
7057 * TPACPI_FAN_RD_ACPI_GFAN:
7058 * ACPI GFAN method: returns fan level
7060 * see TPACPI_FAN_WR_ACPI_SFAN
7061 * EC 0x2f (HFSP) not available if GFAN exists
7063 * TPACPI_FAN_WR_ACPI_SFAN:
7064 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
7066 * EC 0x2f (HFSP) might be available *for reading*, but do not use
7069 * TPACPI_FAN_WR_TPEC:
7070 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
7071 * Supported on almost all ThinkPads
7073 * Fan speed changes of any sort (including those caused by the
7074 * disengaged mode) are usually done slowly by the firmware as the
7075 * maximum ammount of fan duty cycle change per second seems to be
7078 * Reading is not available if GFAN exists.
7079 * Writing is not available if SFAN exists.
7082 * 7 automatic mode engaged;
7083 * (default operation mode of the ThinkPad)
7084 * fan level is ignored in this mode.
7085 * 6 full speed mode (takes precedence over bit 7);
7086 * not available on all thinkpads. May disable
7087 * the tachometer while the fan controller ramps up
7088 * the speed (which can take up to a few *minutes*).
7089 * Speeds up fan to 100% duty-cycle, which is far above
7090 * the standard RPM levels. It is not impossible that
7091 * it could cause hardware damage.
7092 * 5-3 unused in some models. Extra bits for fan level
7093 * in others, but still useless as all values above
7094 * 7 map to the same speed as level 7 in these models.
7095 * 2-0 fan level (0..7 usually)
7097 * 0x07 = max (set when temperatures critical)
7098 * Some ThinkPads may have other levels, see
7099 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
7101 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
7102 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
7103 * does so, its initial value is meaningless (0x07).
7105 * For firmware bugs, refer to:
7106 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7110 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
7111 * Main fan tachometer reading (in RPM)
7113 * This register is present on all ThinkPads with a new-style EC, and
7114 * it is known not to be present on the A21m/e, and T22, as there is
7115 * something else in offset 0x84 according to the ACPI DSDT. Other
7116 * ThinkPads from this same time period (and earlier) probably lack the
7117 * tachometer as well.
7119 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
7120 * was never fixed by IBM to report the EC firmware version string
7121 * probably support the tachometer (like the early X models), so
7122 * detecting it is quite hard. We need more data to know for sure.
7124 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
7127 * FIRMWARE BUG: may go stale while the EC is switching to full speed
7130 * For firmware bugs, refer to:
7131 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7135 * ThinkPad EC register 0x31 bit 0 (only on select models)
7137 * When bit 0 of EC register 0x31 is zero, the tachometer registers
7138 * show the speed of the main fan. When bit 0 of EC register 0x31
7139 * is one, the tachometer registers show the speed of the auxiliary
7142 * Fan control seems to affect both fans, regardless of the state
7145 * So far, only the firmware for the X60/X61 non-tablet versions
7146 * seem to support this (firmware TP-7M).
7148 * TPACPI_FAN_WR_ACPI_FANS:
7149 * ThinkPad X31, X40, X41. Not available in the X60.
7151 * FANS ACPI handle: takes three arguments: low speed, medium speed,
7152 * high speed. ACPI DSDT seems to map these three speeds to levels
7153 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
7154 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
7156 * The speeds are stored on handles
7157 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
7159 * There are three default speed sets, acessible as handles:
7160 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
7162 * ACPI DSDT switches which set is in use depending on various
7165 * TPACPI_FAN_WR_TPEC is also available and should be used to
7166 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
7167 * but the ACPI tables just mention level 7.
7170 enum { /* Fan control constants */
7171 fan_status_offset
= 0x2f, /* EC register 0x2f */
7172 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
7173 * 0x84 must be read before 0x85 */
7174 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
7175 bit 0 selects which fan is active */
7177 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
7178 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
7180 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
7183 enum fan_status_access_mode
{
7184 TPACPI_FAN_NONE
= 0, /* No fan status or control */
7185 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
7186 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
7189 enum fan_control_access_mode
{
7190 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
7191 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
7192 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
7193 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
7196 enum fan_control_commands
{
7197 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
7198 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
7199 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
7200 * and also watchdog cmd */
7203 static int fan_control_allowed
;
7205 static enum fan_status_access_mode fan_status_access_mode
;
7206 static enum fan_control_access_mode fan_control_access_mode
;
7207 static enum fan_control_commands fan_control_commands
;
7209 static u8 fan_control_initial_status
;
7210 static u8 fan_control_desired_level
;
7211 static u8 fan_control_resume_level
;
7212 static int fan_watchdog_maxinterval
;
7214 static struct mutex fan_mutex
;
7216 static void fan_watchdog_fire(struct work_struct
*ignored
);
7217 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
7219 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
7220 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
7221 "\\FSPD", /* 600e/x, 770e, 770x */
7223 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
7224 "JFNS", /* 770x-JL */
7228 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
7229 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
7230 * be in auto mode (0x80).
7232 * This is corrected by any write to HFSP either by the driver, or
7235 * We assume 0x07 really means auto mode while this quirk is active,
7236 * as this is far more likely than the ThinkPad being in level 7,
7237 * which is only used by the firmware during thermal emergencies.
7239 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
7240 * TP-70 (T43, R52), which are known to be buggy.
7243 static void fan_quirk1_setup(void)
7245 if (fan_control_initial_status
== 0x07) {
7246 printk(TPACPI_NOTICE
7247 "fan_init: initial fan status is unknown, "
7248 "assuming it is in auto mode\n");
7249 tp_features
.fan_ctrl_status_undef
= 1;
7253 static void fan_quirk1_handle(u8
*fan_status
)
7255 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
7256 if (*fan_status
!= fan_control_initial_status
) {
7257 /* something changed the HFSP regisnter since
7258 * driver init time, so it is not undefined
7260 tp_features
.fan_ctrl_status_undef
= 0;
7262 /* Return most likely status. In fact, it
7263 * might be the only possible status */
7264 *fan_status
= TP_EC_FAN_AUTO
;
7269 /* Select main fan on X60/X61, NOOP on others */
7270 static bool fan_select_fan1(void)
7272 if (tp_features
.second_fan
) {
7275 if (ec_read(fan_select_offset
, &val
) < 0)
7278 if (ec_write(fan_select_offset
, val
) < 0)
7284 /* Select secondary fan on X60/X61 */
7285 static bool fan_select_fan2(void)
7289 if (!tp_features
.second_fan
)
7292 if (ec_read(fan_select_offset
, &val
) < 0)
7295 if (ec_write(fan_select_offset
, val
) < 0)
7302 * Call with fan_mutex held
7304 static void fan_update_desired_level(u8 status
)
7307 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7309 fan_control_desired_level
= 7;
7311 fan_control_desired_level
= status
;
7315 static int fan_get_status(u8
*status
)
7320 * Add TPACPI_FAN_RD_ACPI_FANS ? */
7322 switch (fan_status_access_mode
) {
7323 case TPACPI_FAN_RD_ACPI_GFAN
:
7324 /* 570, 600e/x, 770e, 770x */
7326 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
7334 case TPACPI_FAN_RD_TPEC
:
7335 /* all except 570, 600e/x, 770e, 770x */
7336 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
7339 if (likely(status
)) {
7341 fan_quirk1_handle(status
);
7353 static int fan_get_status_safe(u8
*status
)
7358 if (mutex_lock_killable(&fan_mutex
))
7359 return -ERESTARTSYS
;
7360 rc
= fan_get_status(&s
);
7362 fan_update_desired_level(s
);
7363 mutex_unlock(&fan_mutex
);
7371 static int fan_get_speed(unsigned int *speed
)
7375 switch (fan_status_access_mode
) {
7376 case TPACPI_FAN_RD_TPEC
:
7377 /* all except 570, 600e/x, 770e, 770x */
7378 if (unlikely(!fan_select_fan1()))
7380 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
7381 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
7385 *speed
= (hi
<< 8) | lo
;
7396 static int fan2_get_speed(unsigned int *speed
)
7401 switch (fan_status_access_mode
) {
7402 case TPACPI_FAN_RD_TPEC
:
7403 /* all except 570, 600e/x, 770e, 770x */
7404 if (unlikely(!fan_select_fan2()))
7406 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
7407 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
7408 fan_select_fan1(); /* play it safe */
7413 *speed
= (hi
<< 8) | lo
;
7424 static int fan_set_level(int level
)
7426 if (!fan_control_allowed
)
7429 switch (fan_control_access_mode
) {
7430 case TPACPI_FAN_WR_ACPI_SFAN
:
7431 if (level
>= 0 && level
<= 7) {
7432 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
7438 case TPACPI_FAN_WR_ACPI_FANS
:
7439 case TPACPI_FAN_WR_TPEC
:
7440 if (!(level
& TP_EC_FAN_AUTO
) &&
7441 !(level
& TP_EC_FAN_FULLSPEED
) &&
7442 ((level
< 0) || (level
> 7)))
7445 /* safety net should the EC not support AUTO
7446 * or FULLSPEED mode bits and just ignore them */
7447 if (level
& TP_EC_FAN_FULLSPEED
)
7448 level
|= 7; /* safety min speed 7 */
7449 else if (level
& TP_EC_FAN_AUTO
)
7450 level
|= 4; /* safety min speed 4 */
7452 if (!acpi_ec_write(fan_status_offset
, level
))
7455 tp_features
.fan_ctrl_status_undef
= 0;
7462 vdbg_printk(TPACPI_DBG_FAN
,
7463 "fan control: set fan control register to 0x%02x\n", level
);
7467 static int fan_set_level_safe(int level
)
7471 if (!fan_control_allowed
)
7474 if (mutex_lock_killable(&fan_mutex
))
7475 return -ERESTARTSYS
;
7477 if (level
== TPACPI_FAN_LAST_LEVEL
)
7478 level
= fan_control_desired_level
;
7480 rc
= fan_set_level(level
);
7482 fan_update_desired_level(level
);
7484 mutex_unlock(&fan_mutex
);
7488 static int fan_set_enable(void)
7493 if (!fan_control_allowed
)
7496 if (mutex_lock_killable(&fan_mutex
))
7497 return -ERESTARTSYS
;
7499 switch (fan_control_access_mode
) {
7500 case TPACPI_FAN_WR_ACPI_FANS
:
7501 case TPACPI_FAN_WR_TPEC
:
7502 rc
= fan_get_status(&s
);
7506 /* Don't go out of emergency fan mode */
7509 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
7512 if (!acpi_ec_write(fan_status_offset
, s
))
7515 tp_features
.fan_ctrl_status_undef
= 0;
7520 case TPACPI_FAN_WR_ACPI_SFAN
:
7521 rc
= fan_get_status(&s
);
7527 /* Set fan to at least level 4 */
7530 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
7540 mutex_unlock(&fan_mutex
);
7543 vdbg_printk(TPACPI_DBG_FAN
,
7544 "fan control: set fan control register to 0x%02x\n",
7549 static int fan_set_disable(void)
7553 if (!fan_control_allowed
)
7556 if (mutex_lock_killable(&fan_mutex
))
7557 return -ERESTARTSYS
;
7560 switch (fan_control_access_mode
) {
7561 case TPACPI_FAN_WR_ACPI_FANS
:
7562 case TPACPI_FAN_WR_TPEC
:
7563 if (!acpi_ec_write(fan_status_offset
, 0x00))
7566 fan_control_desired_level
= 0;
7567 tp_features
.fan_ctrl_status_undef
= 0;
7571 case TPACPI_FAN_WR_ACPI_SFAN
:
7572 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
7575 fan_control_desired_level
= 0;
7583 vdbg_printk(TPACPI_DBG_FAN
,
7584 "fan control: set fan control register to 0\n");
7586 mutex_unlock(&fan_mutex
);
7590 static int fan_set_speed(int speed
)
7594 if (!fan_control_allowed
)
7597 if (mutex_lock_killable(&fan_mutex
))
7598 return -ERESTARTSYS
;
7601 switch (fan_control_access_mode
) {
7602 case TPACPI_FAN_WR_ACPI_FANS
:
7603 if (speed
>= 0 && speed
<= 65535) {
7604 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
7605 speed
, speed
, speed
))
7615 mutex_unlock(&fan_mutex
);
7619 static void fan_watchdog_reset(void)
7621 static int fan_watchdog_active
;
7623 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
7626 if (fan_watchdog_active
)
7627 cancel_delayed_work(&fan_watchdog_task
);
7629 if (fan_watchdog_maxinterval
> 0 &&
7630 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
7631 fan_watchdog_active
= 1;
7632 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
7633 msecs_to_jiffies(fan_watchdog_maxinterval
7636 "failed to queue the fan watchdog, "
7637 "watchdog will not trigger\n");
7640 fan_watchdog_active
= 0;
7643 static void fan_watchdog_fire(struct work_struct
*ignored
)
7647 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
7650 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
7651 rc
= fan_set_enable();
7653 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
7654 "will try again later...\n", -rc
);
7655 /* reschedule for later */
7656 fan_watchdog_reset();
7661 * SYSFS fan layout: hwmon compatible (device)
7664 * 0: "disengaged" mode
7666 * 2: native EC "auto" mode (recommended, hardware default)
7668 * pwm*: set speed in manual mode, ignored otherwise.
7669 * 0 is level 0; 255 is level 7. Intermediate points done with linear
7672 * fan*_input: tachometer reading, RPM
7675 * SYSFS fan layout: extensions
7677 * fan_watchdog (driver):
7678 * fan watchdog interval in seconds, 0 disables (default), max 120
7681 /* sysfs fan pwm1_enable ----------------------------------------------- */
7682 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
7683 struct device_attribute
*attr
,
7689 res
= fan_get_status_safe(&status
);
7693 if (status
& TP_EC_FAN_FULLSPEED
) {
7695 } else if (status
& TP_EC_FAN_AUTO
) {
7700 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
7703 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7704 struct device_attribute
*attr
,
7705 const char *buf
, size_t count
)
7710 if (parse_strtoul(buf
, 2, &t
))
7713 tpacpi_disclose_usertask("hwmon pwm1_enable",
7714 "set fan mode to %lu\n", t
);
7718 level
= TP_EC_FAN_FULLSPEED
;
7721 level
= TPACPI_FAN_LAST_LEVEL
;
7724 level
= TP_EC_FAN_AUTO
;
7727 /* reserved for software-controlled auto mode */
7733 res
= fan_set_level_safe(level
);
7739 fan_watchdog_reset();
7744 static struct device_attribute dev_attr_fan_pwm1_enable
=
7745 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7746 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7748 /* sysfs fan pwm1 ------------------------------------------------------ */
7749 static ssize_t
fan_pwm1_show(struct device
*dev
,
7750 struct device_attribute
*attr
,
7756 res
= fan_get_status_safe(&status
);
7761 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7762 status
= fan_control_desired_level
;
7767 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7770 static ssize_t
fan_pwm1_store(struct device
*dev
,
7771 struct device_attribute
*attr
,
7772 const char *buf
, size_t count
)
7776 u8 status
, newlevel
;
7778 if (parse_strtoul(buf
, 255, &s
))
7781 tpacpi_disclose_usertask("hwmon pwm1",
7782 "set fan speed to %lu\n", s
);
7784 /* scale down from 0-255 to 0-7 */
7785 newlevel
= (s
>> 5) & 0x07;
7787 if (mutex_lock_killable(&fan_mutex
))
7788 return -ERESTARTSYS
;
7790 rc
= fan_get_status(&status
);
7791 if (!rc
&& (status
&
7792 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7793 rc
= fan_set_level(newlevel
);
7797 fan_update_desired_level(newlevel
);
7798 fan_watchdog_reset();
7802 mutex_unlock(&fan_mutex
);
7803 return (rc
)? rc
: count
;
7806 static struct device_attribute dev_attr_fan_pwm1
=
7807 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7808 fan_pwm1_show
, fan_pwm1_store
);
7810 /* sysfs fan fan1_input ------------------------------------------------ */
7811 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7812 struct device_attribute
*attr
,
7818 res
= fan_get_speed(&speed
);
7822 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7825 static struct device_attribute dev_attr_fan_fan1_input
=
7826 __ATTR(fan1_input
, S_IRUGO
,
7827 fan_fan1_input_show
, NULL
);
7829 /* sysfs fan fan2_input ------------------------------------------------ */
7830 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7831 struct device_attribute
*attr
,
7837 res
= fan2_get_speed(&speed
);
7841 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7844 static struct device_attribute dev_attr_fan_fan2_input
=
7845 __ATTR(fan2_input
, S_IRUGO
,
7846 fan_fan2_input_show
, NULL
);
7848 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
7849 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
7852 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
7855 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
7856 const char *buf
, size_t count
)
7860 if (parse_strtoul(buf
, 120, &t
))
7863 if (!fan_control_allowed
)
7866 fan_watchdog_maxinterval
= t
;
7867 fan_watchdog_reset();
7869 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
7874 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
7875 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
7877 /* --------------------------------------------------------------------- */
7878 static struct attribute
*fan_attributes
[] = {
7879 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
7880 &dev_attr_fan_fan1_input
.attr
,
7881 NULL
, /* for fan2_input */
7885 static const struct attribute_group fan_attr_group
= {
7886 .attrs
= fan_attributes
,
7889 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
7890 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
7892 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7893 { .vendor = PCI_VENDOR_ID_IBM, \
7894 .bios = TPACPI_MATCH_ANY, \
7895 .ec = TPID(__id1, __id2), \
7896 .quirks = __quirks }
7898 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7899 { .vendor = PCI_VENDOR_ID_LENOVO, \
7900 .bios = TPACPI_MATCH_ANY, \
7901 .ec = TPID(__id1, __id2), \
7902 .quirks = __quirks }
7904 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
7905 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
7906 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
7907 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
7908 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
7909 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
7912 #undef TPACPI_FAN_QL
7913 #undef TPACPI_FAN_QI
7915 static int __init
fan_init(struct ibm_init_struct
*iibm
)
7918 unsigned long quirks
;
7920 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7921 "initializing fan subdriver\n");
7923 mutex_init(&fan_mutex
);
7924 fan_status_access_mode
= TPACPI_FAN_NONE
;
7925 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7926 fan_control_commands
= 0;
7927 fan_watchdog_maxinterval
= 0;
7928 tp_features
.fan_ctrl_status_undef
= 0;
7929 tp_features
.second_fan
= 0;
7930 fan_control_desired_level
= 7;
7932 TPACPI_ACPIHANDLE_INIT(fans
);
7933 TPACPI_ACPIHANDLE_INIT(gfan
);
7934 TPACPI_ACPIHANDLE_INIT(sfan
);
7936 quirks
= tpacpi_check_quirks(fan_quirk_table
,
7937 ARRAY_SIZE(fan_quirk_table
));
7940 /* 570, 600e/x, 770e, 770x */
7941 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7943 /* all other ThinkPads: note that even old-style
7944 * ThinkPad ECs supports the fan control register */
7945 if (likely(acpi_ec_read(fan_status_offset
,
7946 &fan_control_initial_status
))) {
7947 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7948 if (quirks
& TPACPI_FAN_Q1
)
7950 if (quirks
& TPACPI_FAN_2FAN
) {
7951 tp_features
.second_fan
= 1;
7952 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7953 "secondary fan support enabled\n");
7957 "ThinkPad ACPI EC access misbehaving, "
7958 "fan status and control unavailable\n");
7965 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
7966 fan_control_commands
|=
7967 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
7970 /* gfan without sfan means no fan control */
7971 /* all other models implement TP EC 0x2f control */
7975 fan_control_access_mode
=
7976 TPACPI_FAN_WR_ACPI_FANS
;
7977 fan_control_commands
|=
7978 TPACPI_FAN_CMD_SPEED
|
7979 TPACPI_FAN_CMD_LEVEL
|
7980 TPACPI_FAN_CMD_ENABLE
;
7982 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
7983 fan_control_commands
|=
7984 TPACPI_FAN_CMD_LEVEL
|
7985 TPACPI_FAN_CMD_ENABLE
;
7990 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7991 "fan is %s, modes %d, %d\n",
7992 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
7993 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
7994 fan_status_access_mode
, fan_control_access_mode
);
7996 /* fan control master switch */
7997 if (!fan_control_allowed
) {
7998 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7999 fan_control_commands
= 0;
8000 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8001 "fan control features disabled by parameter\n");
8004 /* update fan_control_desired_level */
8005 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
8006 fan_get_status_safe(NULL
);
8008 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
8009 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
8010 if (tp_features
.second_fan
) {
8011 /* attach second fan tachometer */
8012 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
8013 &dev_attr_fan_fan2_input
.attr
;
8015 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8020 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
8021 &driver_attr_fan_watchdog
);
8023 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8032 static void fan_exit(void)
8034 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
8035 "cancelling any pending fan watchdog tasks\n");
8037 /* FIXME: can we really do this unconditionally? */
8038 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
8039 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
8040 &driver_attr_fan_watchdog
);
8042 cancel_delayed_work(&fan_watchdog_task
);
8043 flush_workqueue(tpacpi_wq
);
8046 static void fan_suspend(pm_message_t state
)
8050 if (!fan_control_allowed
)
8053 /* Store fan status in cache */
8054 fan_control_resume_level
= 0;
8055 rc
= fan_get_status_safe(&fan_control_resume_level
);
8057 printk(TPACPI_NOTICE
8058 "failed to read fan level for later "
8059 "restore during resume: %d\n", rc
);
8061 /* if it is undefined, don't attempt to restore it.
8063 if (tp_features
.fan_ctrl_status_undef
)
8064 fan_control_resume_level
= 0;
8067 static void fan_resume(void)
8069 u8 current_level
= 7;
8070 bool do_set
= false;
8073 /* DSDT *always* updates status on resume */
8074 tp_features
.fan_ctrl_status_undef
= 0;
8076 if (!fan_control_allowed
||
8077 !fan_control_resume_level
||
8078 (fan_get_status_safe(¤t_level
) < 0))
8081 switch (fan_control_access_mode
) {
8082 case TPACPI_FAN_WR_ACPI_SFAN
:
8083 /* never decrease fan level */
8084 do_set
= (fan_control_resume_level
> current_level
);
8086 case TPACPI_FAN_WR_ACPI_FANS
:
8087 case TPACPI_FAN_WR_TPEC
:
8088 /* never decrease fan level, scale is:
8089 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
8091 * We expect the firmware to set either 7 or AUTO, but we
8092 * handle FULLSPEED out of paranoia.
8094 * So, we can safely only restore FULLSPEED or 7, anything
8095 * else could slow the fan. Restoring AUTO is useless, at
8096 * best that's exactly what the DSDT already set (it is the
8099 * Always keep in mind that the DSDT *will* have set the
8100 * fans to what the vendor supposes is the best level. We
8101 * muck with it only to speed the fan up.
8103 if (fan_control_resume_level
!= 7 &&
8104 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
8107 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
8108 (current_level
!= fan_control_resume_level
);
8114 printk(TPACPI_NOTICE
8115 "restoring fan level to 0x%02x\n",
8116 fan_control_resume_level
);
8117 rc
= fan_set_level_safe(fan_control_resume_level
);
8119 printk(TPACPI_NOTICE
8120 "failed to restore fan level: %d\n", rc
);
8124 static int fan_read(struct seq_file
*m
)
8128 unsigned int speed
= 0;
8130 switch (fan_status_access_mode
) {
8131 case TPACPI_FAN_RD_ACPI_GFAN
:
8132 /* 570, 600e/x, 770e, 770x */
8133 rc
= fan_get_status_safe(&status
);
8137 seq_printf(m
, "status:\t\t%s\n"
8139 (status
!= 0) ? "enabled" : "disabled", status
);
8142 case TPACPI_FAN_RD_TPEC
:
8143 /* all except 570, 600e/x, 770e, 770x */
8144 rc
= fan_get_status_safe(&status
);
8148 seq_printf(m
, "status:\t\t%s\n",
8149 (status
!= 0) ? "enabled" : "disabled");
8151 rc
= fan_get_speed(&speed
);
8155 seq_printf(m
, "speed:\t\t%d\n", speed
);
8157 if (status
& TP_EC_FAN_FULLSPEED
)
8158 /* Disengaged mode takes precedence */
8159 seq_printf(m
, "level:\t\tdisengaged\n");
8160 else if (status
& TP_EC_FAN_AUTO
)
8161 seq_printf(m
, "level:\t\tauto\n");
8163 seq_printf(m
, "level:\t\t%d\n", status
);
8166 case TPACPI_FAN_NONE
:
8168 seq_printf(m
, "status:\t\tnot supported\n");
8171 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
8172 seq_printf(m
, "commands:\tlevel <level>");
8174 switch (fan_control_access_mode
) {
8175 case TPACPI_FAN_WR_ACPI_SFAN
:
8176 seq_printf(m
, " (<level> is 0-7)\n");
8180 seq_printf(m
, " (<level> is 0-7, "
8181 "auto, disengaged, full-speed)\n");
8186 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
8187 seq_printf(m
, "commands:\tenable, disable\n"
8188 "commands:\twatchdog <timeout> (<timeout> "
8189 "is 0 (off), 1-120 (seconds))\n");
8191 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
8192 seq_printf(m
, "commands:\tspeed <speed>"
8193 " (<speed> is 0-65535)\n");
8198 static int fan_write_cmd_level(const char *cmd
, int *rc
)
8202 if (strlencmp(cmd
, "level auto") == 0)
8203 level
= TP_EC_FAN_AUTO
;
8204 else if ((strlencmp(cmd
, "level disengaged") == 0) |
8205 (strlencmp(cmd
, "level full-speed") == 0))
8206 level
= TP_EC_FAN_FULLSPEED
;
8207 else if (sscanf(cmd
, "level %d", &level
) != 1)
8210 *rc
= fan_set_level_safe(level
);
8212 printk(TPACPI_ERR
"level command accepted for unsupported "
8213 "access mode %d", fan_control_access_mode
);
8215 tpacpi_disclose_usertask("procfs fan",
8216 "set level to %d\n", level
);
8221 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
8223 if (strlencmp(cmd
, "enable") != 0)
8226 *rc
= fan_set_enable();
8228 printk(TPACPI_ERR
"enable command accepted for unsupported "
8229 "access mode %d", fan_control_access_mode
);
8231 tpacpi_disclose_usertask("procfs fan", "enable\n");
8236 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
8238 if (strlencmp(cmd
, "disable") != 0)
8241 *rc
= fan_set_disable();
8243 printk(TPACPI_ERR
"disable command accepted for unsupported "
8244 "access mode %d", fan_control_access_mode
);
8246 tpacpi_disclose_usertask("procfs fan", "disable\n");
8251 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
8256 * Support speed <low> <medium> <high> ? */
8258 if (sscanf(cmd
, "speed %d", &speed
) != 1)
8261 *rc
= fan_set_speed(speed
);
8263 printk(TPACPI_ERR
"speed command accepted for unsupported "
8264 "access mode %d", fan_control_access_mode
);
8266 tpacpi_disclose_usertask("procfs fan",
8267 "set speed to %d\n", speed
);
8272 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
8276 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
8279 if (interval
< 0 || interval
> 120)
8282 fan_watchdog_maxinterval
= interval
;
8283 tpacpi_disclose_usertask("procfs fan",
8284 "set watchdog timer to %d\n",
8291 static int fan_write(char *buf
)
8296 while (!rc
&& (cmd
= next_cmd(&buf
))) {
8297 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
8298 fan_write_cmd_level(cmd
, &rc
)) &&
8299 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
8300 (fan_write_cmd_enable(cmd
, &rc
) ||
8301 fan_write_cmd_disable(cmd
, &rc
) ||
8302 fan_write_cmd_watchdog(cmd
, &rc
))) &&
8303 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
8304 fan_write_cmd_speed(cmd
, &rc
))
8308 fan_watchdog_reset();
8314 static struct ibm_struct fan_driver_data
= {
8319 .suspend
= fan_suspend
,
8320 .resume
= fan_resume
,
8323 /****************************************************************************
8324 ****************************************************************************
8328 ****************************************************************************
8329 ****************************************************************************/
8332 * HKEY event callout for other subdrivers go here
8333 * (yes, it is ugly, but it is quick, safe, and gets the job done
8335 static void tpacpi_driver_event(const unsigned int hkey_event
)
8337 if (ibm_backlight_device
) {
8338 switch (hkey_event
) {
8339 case TP_HKEY_EV_BRGHT_UP
:
8340 case TP_HKEY_EV_BRGHT_DOWN
:
8341 tpacpi_brightness_notify_change();
8345 switch (hkey_event
) {
8346 case TP_HKEY_EV_VOL_UP
:
8347 case TP_HKEY_EV_VOL_DOWN
:
8348 case TP_HKEY_EV_VOL_MUTE
:
8349 volume_alsa_notify_change();
8354 static void hotkey_driver_event(const unsigned int scancode
)
8356 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
8359 /* sysfs name ---------------------------------------------------------- */
8360 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
8361 struct device_attribute
*attr
,
8364 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
8367 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
8368 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
8370 /* --------------------------------------------------------------------- */
8373 static struct proc_dir_entry
*proc_dir
;
8376 * Module and infrastructure proble, init and exit handling
8379 static int force_load
;
8381 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
8382 static const char * __init
str_supported(int is_supported
)
8384 static char text_unsupported
[] __initdata
= "not supported";
8386 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
8388 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
8390 static void ibm_exit(struct ibm_struct
*ibm
)
8392 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
8394 list_del_init(&ibm
->all_drivers
);
8396 if (ibm
->flags
.acpi_notify_installed
) {
8397 dbg_printk(TPACPI_DBG_EXIT
,
8398 "%s: acpi_remove_notify_handler\n", ibm
->name
);
8400 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
8402 dispatch_acpi_notify
);
8403 ibm
->flags
.acpi_notify_installed
= 0;
8404 ibm
->flags
.acpi_notify_installed
= 0;
8407 if (ibm
->flags
.proc_created
) {
8408 dbg_printk(TPACPI_DBG_EXIT
,
8409 "%s: remove_proc_entry\n", ibm
->name
);
8410 remove_proc_entry(ibm
->name
, proc_dir
);
8411 ibm
->flags
.proc_created
= 0;
8414 if (ibm
->flags
.acpi_driver_registered
) {
8415 dbg_printk(TPACPI_DBG_EXIT
,
8416 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
8418 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
8419 kfree(ibm
->acpi
->driver
);
8420 ibm
->acpi
->driver
= NULL
;
8421 ibm
->flags
.acpi_driver_registered
= 0;
8424 if (ibm
->flags
.init_called
&& ibm
->exit
) {
8426 ibm
->flags
.init_called
= 0;
8429 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
8432 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
8435 struct ibm_struct
*ibm
= iibm
->data
;
8436 struct proc_dir_entry
*entry
;
8438 BUG_ON(ibm
== NULL
);
8440 INIT_LIST_HEAD(&ibm
->all_drivers
);
8442 if (ibm
->flags
.experimental
&& !experimental
)
8445 dbg_printk(TPACPI_DBG_INIT
,
8446 "probing for %s\n", ibm
->name
);
8449 ret
= iibm
->init(iibm
);
8451 return 0; /* probe failed */
8455 ibm
->flags
.init_called
= 1;
8459 if (ibm
->acpi
->hid
) {
8460 ret
= register_tpacpi_subdriver(ibm
);
8465 if (ibm
->acpi
->notify
) {
8466 ret
= setup_acpi_notify(ibm
);
8467 if (ret
== -ENODEV
) {
8468 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
8478 dbg_printk(TPACPI_DBG_INIT
,
8479 "%s installed\n", ibm
->name
);
8482 mode_t mode
= iibm
->base_procfs_mode
;
8488 entry
= proc_create_data(ibm
->name
, mode
, proc_dir
,
8489 &dispatch_proc_fops
, ibm
);
8491 printk(TPACPI_ERR
"unable to create proc entry %s\n",
8496 ibm
->flags
.proc_created
= 1;
8499 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
8504 dbg_printk(TPACPI_DBG_INIT
,
8505 "%s: at error exit path with result %d\n",
8509 return (ret
< 0)? ret
: 0;
8514 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
8516 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
8519 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
8520 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
8523 return s
&& strlen(s
) >= 8 &&
8524 tpacpi_is_fw_digit(s
[0]) &&
8525 tpacpi_is_fw_digit(s
[1]) &&
8526 s
[2] == t
&& s
[3] == 'T' &&
8527 tpacpi_is_fw_digit(s
[4]) &&
8528 tpacpi_is_fw_digit(s
[5]) &&
8529 s
[6] == 'W' && s
[7] == 'W';
8532 /* returns 0 - probe ok, or < 0 - probe error.
8533 * Probe ok doesn't mean thinkpad found.
8534 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
8535 static int __must_check __init
get_thinkpad_model_data(
8536 struct thinkpad_id_data
*tp
)
8538 const struct dmi_device
*dev
= NULL
;
8539 char ec_fw_string
[18];
8545 memset(tp
, 0, sizeof(*tp
));
8547 if (dmi_name_in_vendors("IBM"))
8548 tp
->vendor
= PCI_VENDOR_ID_IBM
;
8549 else if (dmi_name_in_vendors("LENOVO"))
8550 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
8554 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
8555 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
8556 if (s
&& !tp
->bios_version_str
)
8559 /* Really ancient ThinkPad 240X will fail this, which is fine */
8560 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
8563 tp
->bios_model
= tp
->bios_version_str
[0]
8564 | (tp
->bios_version_str
[1] << 8);
8565 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
8566 | tp
->bios_version_str
[5];
8569 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
8570 * X32 or newer, all Z series; Some models must have an
8571 * up-to-date BIOS or they will not be detected.
8573 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8575 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
8576 if (sscanf(dev
->name
,
8577 "IBM ThinkPad Embedded Controller -[%17c",
8578 ec_fw_string
) == 1) {
8579 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
8580 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
8582 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
8583 if (!tp
->ec_version_str
)
8586 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
8587 tp
->ec_model
= ec_fw_string
[0]
8588 | (ec_fw_string
[1] << 8);
8589 tp
->ec_release
= (ec_fw_string
[4] << 8)
8592 printk(TPACPI_NOTICE
8593 "ThinkPad firmware release %s "
8594 "doesn't match the known patterns\n",
8596 printk(TPACPI_NOTICE
8597 "please report this to %s\n",
8604 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
8605 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
8606 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
8611 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
8612 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
8613 if (s
&& !tp
->nummodel_str
)
8619 static int __init
probe_for_thinkpad(void)
8627 * Non-ancient models have better DMI tagging, but very old models
8628 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
8630 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
8631 (thinkpad_id
.ec_model
!= 0) ||
8632 tpacpi_is_fw_known();
8634 /* ec is required because many other handles are relative to it */
8635 TPACPI_ACPIHANDLE_INIT(ec
);
8639 "Not yet supported ThinkPad detected!\n");
8643 if (!is_thinkpad
&& !force_load
)
8650 /* Module init, exit, parameters */
8652 static struct ibm_init_struct ibms_init
[] __initdata
= {
8654 .init
= thinkpad_acpi_driver_init
,
8655 .data
= &thinkpad_acpi_driver_data
,
8658 .init
= hotkey_init
,
8659 .data
= &hotkey_driver_data
,
8662 .init
= bluetooth_init
,
8663 .data
= &bluetooth_driver_data
,
8667 .data
= &wan_driver_data
,
8671 .data
= &uwb_driver_data
,
8673 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8676 .base_procfs_mode
= S_IRUSR
,
8677 .data
= &video_driver_data
,
8682 .data
= &light_driver_data
,
8686 .data
= &cmos_driver_data
,
8690 .data
= &led_driver_data
,
8694 .data
= &beep_driver_data
,
8697 .init
= thermal_init
,
8698 .data
= &thermal_driver_data
,
8701 .data
= &ecdump_driver_data
,
8704 .init
= brightness_init
,
8705 .data
= &brightness_driver_data
,
8708 .init
= volume_init
,
8709 .data
= &volume_driver_data
,
8713 .data
= &fan_driver_data
,
8717 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
8720 struct ibm_struct
*ibm
;
8722 if (!kp
|| !kp
->name
|| !val
)
8725 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8726 ibm
= ibms_init
[i
].data
;
8727 WARN_ON(ibm
== NULL
);
8729 if (!ibm
|| !ibm
->name
)
8732 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8733 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8735 strcpy(ibms_init
[i
].param
, val
);
8736 strcat(ibms_init
[i
].param
, ",");
8744 module_param(experimental
, int, 0444);
8745 MODULE_PARM_DESC(experimental
,
8746 "Enables experimental features when non-zero");
8748 module_param_named(debug
, dbg_level
, uint
, 0);
8749 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8751 module_param(force_load
, bool, 0444);
8752 MODULE_PARM_DESC(force_load
,
8753 "Attempts to load the driver even on a "
8754 "mis-identified ThinkPad when true");
8756 module_param_named(fan_control
, fan_control_allowed
, bool, 0444);
8757 MODULE_PARM_DESC(fan_control
,
8758 "Enables setting fan parameters features when true");
8760 module_param_named(brightness_mode
, brightness_mode
, uint
, 0444);
8761 MODULE_PARM_DESC(brightness_mode
,
8762 "Selects brightness control strategy: "
8763 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8765 module_param(brightness_enable
, uint
, 0444);
8766 MODULE_PARM_DESC(brightness_enable
,
8767 "Enables backlight control when 1, disables when 0");
8769 module_param(hotkey_report_mode
, uint
, 0444);
8770 MODULE_PARM_DESC(hotkey_report_mode
,
8771 "used for backwards compatibility with userspace, "
8772 "see documentation");
8774 module_param_named(volume_mode
, volume_mode
, uint
, 0444);
8775 MODULE_PARM_DESC(volume_mode
,
8776 "Selects volume control strategy: "
8777 "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM");
8779 module_param_named(volume_capabilities
, volume_capabilities
, uint
, 0444);
8780 MODULE_PARM_DESC(volume_capabilities
,
8781 "Selects the mixer capabilites: "
8782 "0=auto, 1=volume and mute, 2=mute only");
8784 module_param_named(volume_control
, volume_control_allowed
, bool, 0444);
8785 MODULE_PARM_DESC(volume_control
,
8786 "Enables software override for the console audio "
8787 "control when true");
8789 /* ALSA module API parameters */
8790 module_param_named(index
, alsa_index
, int, 0444);
8791 MODULE_PARM_DESC(index
, "ALSA index for the ACPI EC Mixer");
8792 module_param_named(id
, alsa_id
, charp
, 0444);
8793 MODULE_PARM_DESC(id
, "ALSA id for the ACPI EC Mixer");
8794 module_param_named(enable
, alsa_enable
, bool, 0444);
8795 MODULE_PARM_DESC(enable
, "Enable the ALSA interface for the ACPI EC Mixer");
8797 #define TPACPI_PARAM(feature) \
8798 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8799 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8800 "at module load, see documentation")
8802 TPACPI_PARAM(hotkey
);
8803 TPACPI_PARAM(bluetooth
);
8804 TPACPI_PARAM(video
);
8805 TPACPI_PARAM(light
);
8809 TPACPI_PARAM(ecdump
);
8810 TPACPI_PARAM(brightness
);
8811 TPACPI_PARAM(volume
);
8814 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8815 module_param(dbg_wlswemul
, uint
, 0444);
8816 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
8817 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
8818 MODULE_PARM_DESC(wlsw_state
,
8819 "Initial state of the emulated WLSW switch");
8821 module_param(dbg_bluetoothemul
, uint
, 0444);
8822 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
8823 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
8824 MODULE_PARM_DESC(bluetooth_state
,
8825 "Initial state of the emulated bluetooth switch");
8827 module_param(dbg_wwanemul
, uint
, 0444);
8828 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
8829 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
8830 MODULE_PARM_DESC(wwan_state
,
8831 "Initial state of the emulated WWAN switch");
8833 module_param(dbg_uwbemul
, uint
, 0444);
8834 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
8835 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
8836 MODULE_PARM_DESC(uwb_state
,
8837 "Initial state of the emulated UWB switch");
8840 static void thinkpad_acpi_module_exit(void)
8842 struct ibm_struct
*ibm
, *itmp
;
8844 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
8846 list_for_each_entry_safe_reverse(ibm
, itmp
,
8847 &tpacpi_all_drivers
,
8852 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
8854 if (tpacpi_inputdev
) {
8855 if (tp_features
.input_device_registered
)
8856 input_unregister_device(tpacpi_inputdev
);
8858 input_free_device(tpacpi_inputdev
);
8862 hwmon_device_unregister(tpacpi_hwmon
);
8864 if (tp_features
.sensors_pdev_attrs_registered
)
8865 device_remove_file(&tpacpi_sensors_pdev
->dev
,
8866 &dev_attr_thinkpad_acpi_pdev_name
);
8867 if (tpacpi_sensors_pdev
)
8868 platform_device_unregister(tpacpi_sensors_pdev
);
8870 platform_device_unregister(tpacpi_pdev
);
8872 if (tp_features
.sensors_pdrv_attrs_registered
)
8873 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
8874 if (tp_features
.platform_drv_attrs_registered
)
8875 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
8877 if (tp_features
.sensors_pdrv_registered
)
8878 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
8880 if (tp_features
.platform_drv_registered
)
8881 platform_driver_unregister(&tpacpi_pdriver
);
8884 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
8887 destroy_workqueue(tpacpi_wq
);
8889 kfree(thinkpad_id
.bios_version_str
);
8890 kfree(thinkpad_id
.ec_version_str
);
8891 kfree(thinkpad_id
.model_str
);
8895 static int __init
thinkpad_acpi_module_init(void)
8899 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
8901 /* Parameter checking */
8902 if (hotkey_report_mode
> 2)
8905 /* Driver-level probe */
8907 ret
= get_thinkpad_model_data(&thinkpad_id
);
8910 "unable to get DMI data: %d\n", ret
);
8911 thinkpad_acpi_module_exit();
8914 ret
= probe_for_thinkpad();
8916 thinkpad_acpi_module_exit();
8920 /* Driver initialization */
8922 TPACPI_ACPIHANDLE_INIT(ecrd
);
8923 TPACPI_ACPIHANDLE_INIT(ecwr
);
8925 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
8927 thinkpad_acpi_module_exit();
8931 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
8934 "unable to create proc dir " TPACPI_PROC_DIR
);
8935 thinkpad_acpi_module_exit();
8939 ret
= platform_driver_register(&tpacpi_pdriver
);
8942 "unable to register main platform driver\n");
8943 thinkpad_acpi_module_exit();
8946 tp_features
.platform_drv_registered
= 1;
8948 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
8951 "unable to register hwmon platform driver\n");
8952 thinkpad_acpi_module_exit();
8955 tp_features
.sensors_pdrv_registered
= 1;
8957 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
8959 tp_features
.platform_drv_attrs_registered
= 1;
8960 ret
= tpacpi_create_driver_attributes(
8961 &tpacpi_hwmon_pdriver
.driver
);
8965 "unable to create sysfs driver attributes\n");
8966 thinkpad_acpi_module_exit();
8969 tp_features
.sensors_pdrv_attrs_registered
= 1;
8972 /* Device initialization */
8973 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
8975 if (IS_ERR(tpacpi_pdev
)) {
8976 ret
= PTR_ERR(tpacpi_pdev
);
8978 printk(TPACPI_ERR
"unable to register platform device\n");
8979 thinkpad_acpi_module_exit();
8982 tpacpi_sensors_pdev
= platform_device_register_simple(
8983 TPACPI_HWMON_DRVR_NAME
,
8985 if (IS_ERR(tpacpi_sensors_pdev
)) {
8986 ret
= PTR_ERR(tpacpi_sensors_pdev
);
8987 tpacpi_sensors_pdev
= NULL
;
8989 "unable to register hwmon platform device\n");
8990 thinkpad_acpi_module_exit();
8993 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
8994 &dev_attr_thinkpad_acpi_pdev_name
);
8997 "unable to create sysfs hwmon device attributes\n");
8998 thinkpad_acpi_module_exit();
9001 tp_features
.sensors_pdev_attrs_registered
= 1;
9002 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
9003 if (IS_ERR(tpacpi_hwmon
)) {
9004 ret
= PTR_ERR(tpacpi_hwmon
);
9005 tpacpi_hwmon
= NULL
;
9006 printk(TPACPI_ERR
"unable to register hwmon device\n");
9007 thinkpad_acpi_module_exit();
9010 mutex_init(&tpacpi_inputdev_send_mutex
);
9011 tpacpi_inputdev
= input_allocate_device();
9012 if (!tpacpi_inputdev
) {
9013 printk(TPACPI_ERR
"unable to allocate input device\n");
9014 thinkpad_acpi_module_exit();
9017 /* Prepare input device, but don't register */
9018 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
9019 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
9020 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
9021 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
9022 thinkpad_id
.vendor
:
9024 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
9025 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
9026 tpacpi_inputdev
->dev
.parent
= &tpacpi_pdev
->dev
;
9028 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
9029 ret
= ibm_init(&ibms_init
[i
]);
9030 if (ret
>= 0 && *ibms_init
[i
].param
)
9031 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
9033 thinkpad_acpi_module_exit();
9038 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
9040 ret
= input_register_device(tpacpi_inputdev
);
9042 printk(TPACPI_ERR
"unable to register input device\n");
9043 thinkpad_acpi_module_exit();
9046 tp_features
.input_device_registered
= 1;
9052 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
9055 * This will autoload the driver in almost every ThinkPad
9056 * in widespread use.
9058 * Only _VERY_ old models, like the 240, 240x and 570 lack
9059 * the HKEY event interface.
9061 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
9064 * DMI matching for module autoloading
9066 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
9067 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
9069 * Only models listed in thinkwiki will be supported, so add yours
9070 * if it is not there yet.
9072 #define IBM_BIOS_MODULE_ALIAS(__type) \
9073 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
9075 /* Ancient thinkpad BIOSes have to be identified by
9076 * BIOS type or model number, and there are far less
9077 * BIOS types than model numbers... */
9078 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
9080 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
9081 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
9082 MODULE_DESCRIPTION(TPACPI_DESC
);
9083 MODULE_VERSION(TPACPI_VERSION
);
9084 MODULE_LICENSE("GPL");
9086 module_init(thinkpad_acpi_module_init
);
9087 module_exit(thinkpad_acpi_module_exit
);