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.23"
25 #define TPACPI_SYSFS_VERSION 0x020700
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/sched.h>
58 #include <linux/kthread.h>
59 #include <linux/freezer.h>
60 #include <linux/delay.h>
62 #include <linux/nvram.h>
63 #include <linux/proc_fs.h>
64 #include <linux/seq_file.h>
65 #include <linux/sysfs.h>
66 #include <linux/backlight.h>
68 #include <linux/platform_device.h>
69 #include <linux/hwmon.h>
70 #include <linux/hwmon-sysfs.h>
71 #include <linux/input.h>
72 #include <linux/leds.h>
73 #include <linux/rfkill.h>
74 #include <asm/uaccess.h>
76 #include <linux/dmi.h>
77 #include <linux/jiffies.h>
78 #include <linux/workqueue.h>
80 #include <sound/core.h>
81 #include <sound/control.h>
82 #include <sound/initval.h>
84 #include <acpi/acpi_drivers.h>
86 #include <linux/pci_ids.h>
89 /* ThinkPad CMOS commands */
90 #define TP_CMOS_VOLUME_DOWN 0
91 #define TP_CMOS_VOLUME_UP 1
92 #define TP_CMOS_VOLUME_MUTE 2
93 #define TP_CMOS_BRIGHTNESS_UP 4
94 #define TP_CMOS_BRIGHTNESS_DOWN 5
95 #define TP_CMOS_THINKLIGHT_ON 12
96 #define TP_CMOS_THINKLIGHT_OFF 13
100 TP_NVRAM_ADDR_HK2
= 0x57,
101 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
102 TP_NVRAM_ADDR_VIDEO
= 0x59,
103 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
104 TP_NVRAM_ADDR_MIXER
= 0x60,
107 /* NVRAM bit masks */
109 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
110 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
111 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
112 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
113 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
114 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
115 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
116 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
117 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
118 TP_NVRAM_MASK_MUTE
= 0x40,
119 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
120 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
121 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
125 #define TPACPI_ACPI_HKEY_HID "IBM0068"
128 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
129 #define TPACPI_HKEY_INPUT_VERSION 0x4101
131 /* ACPI \WGSV commands */
133 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
134 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
135 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
136 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
139 /* TP_ACPI_WGSV_GET_STATE bits */
141 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
142 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
143 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
144 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
145 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
146 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
147 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
148 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
149 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
150 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
154 enum tpacpi_hkey_event_t
{
156 TP_HKEY_EV_HOTKEY_BASE
= 0x1001, /* first hotkey (FN+F1) */
157 TP_HKEY_EV_BRGHT_UP
= 0x1010, /* Brightness up */
158 TP_HKEY_EV_BRGHT_DOWN
= 0x1011, /* Brightness down */
159 TP_HKEY_EV_VOL_UP
= 0x1015, /* Volume up or unmute */
160 TP_HKEY_EV_VOL_DOWN
= 0x1016, /* Volume down or unmute */
161 TP_HKEY_EV_VOL_MUTE
= 0x1017, /* Mixer output mute */
163 /* Reasons for waking up from S3/S4 */
164 TP_HKEY_EV_WKUP_S3_UNDOCK
= 0x2304, /* undock requested, S3 */
165 TP_HKEY_EV_WKUP_S4_UNDOCK
= 0x2404, /* undock requested, S4 */
166 TP_HKEY_EV_WKUP_S3_BAYEJ
= 0x2305, /* bay ejection req, S3 */
167 TP_HKEY_EV_WKUP_S4_BAYEJ
= 0x2405, /* bay ejection req, S4 */
168 TP_HKEY_EV_WKUP_S3_BATLOW
= 0x2313, /* battery empty, S3 */
169 TP_HKEY_EV_WKUP_S4_BATLOW
= 0x2413, /* battery empty, S4 */
171 /* Auto-sleep after eject request */
172 TP_HKEY_EV_BAYEJ_ACK
= 0x3003, /* bay ejection complete */
173 TP_HKEY_EV_UNDOCK_ACK
= 0x4003, /* undock complete */
175 /* Misc bay events */
176 TP_HKEY_EV_OPTDRV_EJ
= 0x3006, /* opt. drive tray ejected */
178 /* User-interface events */
179 TP_HKEY_EV_LID_CLOSE
= 0x5001, /* laptop lid closed */
180 TP_HKEY_EV_LID_OPEN
= 0x5002, /* laptop lid opened */
181 TP_HKEY_EV_TABLET_TABLET
= 0x5009, /* tablet swivel up */
182 TP_HKEY_EV_TABLET_NOTEBOOK
= 0x500a, /* tablet swivel down */
183 TP_HKEY_EV_PEN_INSERTED
= 0x500b, /* tablet pen inserted */
184 TP_HKEY_EV_PEN_REMOVED
= 0x500c, /* tablet pen removed */
185 TP_HKEY_EV_BRGHT_CHANGED
= 0x5010, /* backlight control event */
188 TP_HKEY_EV_ALARM_BAT_HOT
= 0x6011, /* battery too hot */
189 TP_HKEY_EV_ALARM_BAT_XHOT
= 0x6012, /* battery critically hot */
190 TP_HKEY_EV_ALARM_SENSOR_HOT
= 0x6021, /* sensor too hot */
191 TP_HKEY_EV_ALARM_SENSOR_XHOT
= 0x6022, /* sensor critically hot */
192 TP_HKEY_EV_THM_TABLE_CHANGED
= 0x6030, /* thermal table changed */
195 TP_HKEY_EV_RFKILL_CHANGED
= 0x7000, /* rfkill switch changed */
198 /****************************************************************************
202 #define TPACPI_NAME "thinkpad"
203 #define TPACPI_DESC "ThinkPad ACPI Extras"
204 #define TPACPI_FILE TPACPI_NAME "_acpi"
205 #define TPACPI_URL "http://ibm-acpi.sf.net/"
206 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
208 #define TPACPI_PROC_DIR "ibm"
209 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
210 #define TPACPI_DRVR_NAME TPACPI_FILE
211 #define TPACPI_DRVR_SHORTNAME "tpacpi"
212 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
214 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
215 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
217 #define TPACPI_MAX_ACPI_ARGS 3
220 #define TPACPI_LOG TPACPI_FILE ": "
221 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
222 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
223 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
224 #define TPACPI_ERR KERN_ERR TPACPI_LOG
225 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
226 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
227 #define TPACPI_INFO KERN_INFO TPACPI_LOG
228 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
230 /* Debugging printk groups */
231 #define TPACPI_DBG_ALL 0xffff
232 #define TPACPI_DBG_DISCLOSETASK 0x8000
233 #define TPACPI_DBG_INIT 0x0001
234 #define TPACPI_DBG_EXIT 0x0002
235 #define TPACPI_DBG_RFKILL 0x0004
236 #define TPACPI_DBG_HKEY 0x0008
237 #define TPACPI_DBG_FAN 0x0010
238 #define TPACPI_DBG_BRGHT 0x0020
239 #define TPACPI_DBG_MIXER 0x0040
241 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
242 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
243 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
246 /****************************************************************************
247 * Driver-wide structs and misc. variables
252 struct tp_acpi_drv_struct
{
253 const struct acpi_device_id
*hid
;
254 struct acpi_driver
*driver
;
256 void (*notify
) (struct ibm_struct
*, u32
);
259 struct acpi_device
*device
;
265 int (*read
) (struct seq_file
*);
266 int (*write
) (char *);
268 void (*resume
) (void);
269 void (*suspend
) (pm_message_t state
);
270 void (*shutdown
) (void);
272 struct list_head all_drivers
;
274 struct tp_acpi_drv_struct
*acpi
;
277 u8 acpi_driver_registered
:1;
278 u8 acpi_notify_installed
:1;
285 struct ibm_init_struct
{
288 int (*init
) (struct ibm_init_struct
*);
289 struct ibm_struct
*data
;
300 u32 bright_16levels
:1;
301 u32 bright_acpimode
:1;
304 u32 fan_ctrl_status_undef
:1;
306 u32 beep_needs_two_args
:1;
307 u32 mixer_no_level_control
:1;
308 u32 input_device_registered
:1;
309 u32 platform_drv_registered
:1;
310 u32 platform_drv_attrs_registered
:1;
311 u32 sensors_pdrv_registered
:1;
312 u32 sensors_pdrv_attrs_registered
:1;
313 u32 sensors_pdev_attrs_registered
:1;
314 u32 hotkey_poll_active
:1;
318 u16 hotkey_mask_ff
:1;
319 u16 volume_ctrl_forbidden
:1;
322 struct thinkpad_id_data
{
323 unsigned int vendor
; /* ThinkPad vendor:
324 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
326 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
327 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
329 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
331 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
334 char *model_str
; /* ThinkPad T43 */
335 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
337 static struct thinkpad_id_data thinkpad_id
;
340 TPACPI_LIFE_INIT
= 0,
345 static int experimental
;
346 static u32 dbg_level
;
348 static struct workqueue_struct
*tpacpi_wq
;
356 /* Special LED class that can defer work */
357 struct tpacpi_led_classdev
{
358 struct led_classdev led_classdev
;
359 struct work_struct work
;
360 enum led_status_t new_state
;
364 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
365 static int dbg_wlswemul
;
366 static int tpacpi_wlsw_emulstate
;
367 static int dbg_bluetoothemul
;
368 static int tpacpi_bluetooth_emulstate
;
369 static int dbg_wwanemul
;
370 static int tpacpi_wwan_emulstate
;
371 static int dbg_uwbemul
;
372 static int tpacpi_uwb_emulstate
;
376 /*************************************************************************
380 #define dbg_printk(a_dbg_level, format, arg...) \
381 do { if (dbg_level & (a_dbg_level)) \
382 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
385 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
386 #define vdbg_printk dbg_printk
387 static const char *str_supported(int is_supported
);
389 #define vdbg_printk(a_dbg_level, format, arg...) \
393 static void tpacpi_log_usertask(const char * const what
)
395 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
396 what
, task_tgid_vnr(current
));
399 #define tpacpi_disclose_usertask(what, format, arg...) \
402 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
403 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
404 printk(TPACPI_DEBUG "%s: PID %d: " format, \
405 what, task_tgid_vnr(current), ## arg); \
410 * Quirk handling helpers
412 * ThinkPad IDs and versions seen in the field so far
413 * are two-characters from the set [0-9A-Z], i.e. base 36.
415 * We use values well outside that range as specials.
418 #define TPACPI_MATCH_ANY 0xffffU
419 #define TPACPI_MATCH_UNKNOWN 0U
421 /* TPID('1', 'Y') == 0x5931 */
422 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
424 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
425 { .vendor = PCI_VENDOR_ID_IBM, \
426 .bios = TPID(__id1, __id2), \
427 .ec = TPACPI_MATCH_ANY, \
428 .quirks = (__quirk) }
430 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
431 { .vendor = PCI_VENDOR_ID_LENOVO, \
432 .bios = TPID(__id1, __id2), \
433 .ec = TPACPI_MATCH_ANY, \
434 .quirks = (__quirk) }
436 #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \
437 { .vendor = PCI_VENDOR_ID_LENOVO, \
438 .bios = TPACPI_MATCH_ANY, \
439 .ec = TPID(__id1, __id2), \
440 .quirks = (__quirk) }
442 struct tpacpi_quirk
{
446 unsigned long quirks
;
450 * tpacpi_check_quirks() - search BIOS/EC version on a list
451 * @qlist: array of &struct tpacpi_quirk
452 * @qlist_size: number of elements in @qlist
454 * Iterates over a quirks list until one is found that matches the
455 * ThinkPad's vendor, BIOS and EC model.
457 * Returns 0 if nothing matches, otherwise returns the quirks field of
458 * the matching &struct tpacpi_quirk entry.
460 * The match criteria is: vendor, ec and bios much match.
462 static unsigned long __init
tpacpi_check_quirks(
463 const struct tpacpi_quirk
*qlist
,
464 unsigned int qlist_size
)
467 if ((qlist
->vendor
== thinkpad_id
.vendor
||
468 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
469 (qlist
->bios
== thinkpad_id
.bios_model
||
470 qlist
->bios
== TPACPI_MATCH_ANY
) &&
471 (qlist
->ec
== thinkpad_id
.ec_model
||
472 qlist
->ec
== TPACPI_MATCH_ANY
))
473 return qlist
->quirks
;
482 /****************************************************************************
483 ****************************************************************************
485 * ACPI Helpers and device model
487 ****************************************************************************
488 ****************************************************************************/
490 /*************************************************************************
494 static acpi_handle root_handle
;
496 #define TPACPI_HANDLE(object, parent, paths...) \
497 static acpi_handle object##_handle; \
498 static acpi_handle *object##_parent = &parent##_handle; \
499 static char *object##_path; \
500 static char *object##_paths[] = { paths }
502 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
503 "\\_SB.PCI.ISA.EC", /* 570 */
504 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
505 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
506 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
507 "\\_SB.PCI0.ICH3.EC0", /* R31 */
508 "\\_SB.PCI0.LPC.EC", /* all others */
511 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
512 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
514 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
516 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
517 "\\CMS", /* R40, R40e */
520 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
521 "^HKEY", /* R30, R31 */
522 "HKEY", /* all others */
525 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
526 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
527 "\\_SB.PCI0.VID0", /* 770e */
528 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
529 "\\_SB.PCI0.AGP.VID", /* all others */
533 /*************************************************************************
537 static int acpi_evalf(acpi_handle handle
,
538 void *res
, char *method
, char *fmt
, ...)
541 struct acpi_object_list params
;
542 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
543 struct acpi_buffer result
, *resultp
;
544 union acpi_object out_obj
;
552 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
565 params
.pointer
= &in_objs
[0];
572 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
573 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
575 /* add more types as needed */
577 printk(TPACPI_ERR
"acpi_evalf() called "
578 "with invalid format character '%c'\n", c
);
584 if (res_type
!= 'v') {
585 result
.length
= sizeof(out_obj
);
586 result
.pointer
= &out_obj
;
591 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
596 *(int *)res
= out_obj
.integer
.value
;
597 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
600 success
= status
== AE_OK
;
602 /* add more types as needed */
604 printk(TPACPI_ERR
"acpi_evalf() called "
605 "with invalid format character '%c'\n", res_type
);
609 if (!success
&& !quiet
)
610 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
611 method
, fmt0
, status
);
616 static int acpi_ec_read(int i
, u8
*p
)
621 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
625 if (ec_read(i
, p
) < 0)
632 static int acpi_ec_write(int i
, u8 v
)
635 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
638 if (ec_write(i
, v
) < 0)
645 static int issue_thinkpad_cmos_command(int cmos_cmd
)
650 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
656 /*************************************************************************
660 #define TPACPI_ACPIHANDLE_INIT(object) \
661 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
662 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
664 static void drv_acpi_handle_init(char *name
,
665 acpi_handle
*handle
, acpi_handle parent
,
666 char **paths
, int num_paths
, char **path
)
671 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
674 for (i
= 0; i
< num_paths
; i
++) {
675 status
= acpi_get_handle(parent
, paths
[i
], handle
);
676 if (ACPI_SUCCESS(status
)) {
678 dbg_printk(TPACPI_DBG_INIT
,
679 "Found ACPI handle %s for %s\n",
685 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
690 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
692 struct ibm_struct
*ibm
= data
;
694 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
697 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
700 ibm
->acpi
->notify(ibm
, event
);
703 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
710 if (!*ibm
->acpi
->handle
)
713 vdbg_printk(TPACPI_DBG_INIT
,
714 "setting up ACPI notify for %s\n", ibm
->name
);
716 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
718 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
723 ibm
->acpi
->device
->driver_data
= ibm
;
724 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
725 TPACPI_ACPI_EVENT_PREFIX
,
728 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
729 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
730 if (ACPI_FAILURE(status
)) {
731 if (status
== AE_ALREADY_EXISTS
) {
733 "another device driver is already "
734 "handling %s events\n", ibm
->name
);
737 "acpi_install_notify_handler(%s) failed: %d\n",
742 ibm
->flags
.acpi_notify_installed
= 1;
746 static int __init
tpacpi_device_add(struct acpi_device
*device
)
751 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
755 dbg_printk(TPACPI_DBG_INIT
,
756 "registering %s as an ACPI driver\n", ibm
->name
);
760 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
761 if (!ibm
->acpi
->driver
) {
763 "failed to allocate memory for ibm->acpi->driver\n");
767 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
768 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
770 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
772 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
774 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
776 kfree(ibm
->acpi
->driver
);
777 ibm
->acpi
->driver
= NULL
;
779 ibm
->flags
.acpi_driver_registered
= 1;
785 /****************************************************************************
786 ****************************************************************************
790 ****************************************************************************
791 ****************************************************************************/
793 static int dispatch_proc_show(struct seq_file
*m
, void *v
)
795 struct ibm_struct
*ibm
= m
->private;
797 if (!ibm
|| !ibm
->read
)
802 static int dispatch_proc_open(struct inode
*inode
, struct file
*file
)
804 return single_open(file
, dispatch_proc_show
, PDE(inode
)->data
);
807 static ssize_t
dispatch_proc_write(struct file
*file
,
808 const char __user
*userbuf
,
809 size_t count
, loff_t
*pos
)
811 struct ibm_struct
*ibm
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
815 if (!ibm
|| !ibm
->write
)
817 if (count
> PAGE_SIZE
- 2)
820 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
824 if (copy_from_user(kernbuf
, userbuf
, count
)) {
830 strcat(kernbuf
, ",");
831 ret
= ibm
->write(kernbuf
);
840 static const struct file_operations dispatch_proc_fops
= {
841 .owner
= THIS_MODULE
,
842 .open
= dispatch_proc_open
,
845 .release
= single_release
,
846 .write
= dispatch_proc_write
,
849 static char *next_cmd(char **cmds
)
854 while ((end
= strchr(start
, ',')) && end
== start
)
866 /****************************************************************************
867 ****************************************************************************
869 * Device model: input, hwmon and platform
871 ****************************************************************************
872 ****************************************************************************/
874 static struct platform_device
*tpacpi_pdev
;
875 static struct platform_device
*tpacpi_sensors_pdev
;
876 static struct device
*tpacpi_hwmon
;
877 static struct input_dev
*tpacpi_inputdev
;
878 static struct mutex tpacpi_inputdev_send_mutex
;
879 static LIST_HEAD(tpacpi_all_drivers
);
881 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
884 struct ibm_struct
*ibm
, *itmp
;
886 list_for_each_entry_safe(ibm
, itmp
,
890 (ibm
->suspend
)(state
);
896 static int tpacpi_resume_handler(struct platform_device
*pdev
)
898 struct ibm_struct
*ibm
, *itmp
;
900 list_for_each_entry_safe(ibm
, itmp
,
910 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
912 struct ibm_struct
*ibm
, *itmp
;
914 list_for_each_entry_safe(ibm
, itmp
,
922 static struct platform_driver tpacpi_pdriver
= {
924 .name
= TPACPI_DRVR_NAME
,
925 .owner
= THIS_MODULE
,
927 .suspend
= tpacpi_suspend_handler
,
928 .resume
= tpacpi_resume_handler
,
929 .shutdown
= tpacpi_shutdown_handler
,
932 static struct platform_driver tpacpi_hwmon_pdriver
= {
934 .name
= TPACPI_HWMON_DRVR_NAME
,
935 .owner
= THIS_MODULE
,
939 /*************************************************************************
940 * sysfs support helpers
943 struct attribute_set
{
944 unsigned int members
, max_members
;
945 struct attribute_group group
;
948 struct attribute_set_obj
{
949 struct attribute_set s
;
951 } __attribute__((packed
));
953 static struct attribute_set
*create_attr_set(unsigned int max_members
,
956 struct attribute_set_obj
*sobj
;
958 if (max_members
== 0)
961 /* Allocates space for implicit NULL at the end too */
962 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
963 max_members
* sizeof(struct attribute
*),
967 sobj
->s
.max_members
= max_members
;
968 sobj
->s
.group
.attrs
= &sobj
->a
;
969 sobj
->s
.group
.name
= name
;
974 #define destroy_attr_set(_set) \
977 /* not multi-threaded safe, use it in a single thread per set */
978 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
983 if (s
->members
>= s
->max_members
)
986 s
->group
.attrs
[s
->members
] = attr
;
992 static int add_many_to_attr_set(struct attribute_set
*s
,
993 struct attribute
**attr
,
998 for (i
= 0; i
< count
; i
++) {
999 res
= add_to_attr_set(s
, attr
[i
]);
1007 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
1009 sysfs_remove_group(kobj
, &s
->group
);
1010 destroy_attr_set(s
);
1013 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
1014 sysfs_create_group(_kobj, &_attr_set->group)
1016 static int parse_strtoul(const char *buf
,
1017 unsigned long max
, unsigned long *value
)
1021 while (*buf
&& isspace(*buf
))
1023 *value
= simple_strtoul(buf
, &endp
, 0);
1024 while (*endp
&& isspace(*endp
))
1026 if (*endp
|| *value
> max
)
1032 static void tpacpi_disable_brightness_delay(void)
1034 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
1035 printk(TPACPI_NOTICE
1036 "ACPI backlight control delay disabled\n");
1039 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
1041 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1042 union acpi_object
*obj
;
1045 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
1046 obj
= (union acpi_object
*)buffer
.pointer
;
1047 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
1048 printk(TPACPI_ERR
"Unknown _BCL data, "
1049 "please report this to %s\n", TPACPI_MAIL
);
1052 rc
= obj
->package
.count
;
1058 kfree(buffer
.pointer
);
1062 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1063 u32 lvl
, void *context
, void **rv
)
1065 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1066 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1068 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1069 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1070 BUG_ON(!rv
|| !*rv
);
1071 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1072 return AE_CTRL_TERMINATE
;
1079 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1081 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1085 void *bcl_ptr
= &bcl_levels
;
1088 TPACPI_ACPIHANDLE_INIT(vid
);
1094 * Search for a _BCL method, and execute it. This is safe on all
1095 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1096 * BIOS in ACPI backlight control mode. We do NOT have to care
1097 * about calling the _BCL method in an enabled video device, any
1098 * will do for our purposes.
1101 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1102 tpacpi_acpi_walk_find_bcl
, NULL
,
1105 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1106 tp_features
.bright_acpimode
= 1;
1107 return (bcl_levels
- 2);
1113 static void printk_deprecated_attribute(const char * const what
,
1114 const char * const details
)
1116 tpacpi_log_usertask("deprecated sysfs attribute");
1117 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1118 "will be removed. %s\n",
1122 /*************************************************************************
1123 * rfkill and radio control support helpers
1127 * ThinkPad-ACPI firmware handling model:
1129 * WLSW (master wireless switch) is event-driven, and is common to all
1130 * firmware-controlled radios. It cannot be controlled, just monitored,
1131 * as expected. It overrides all radio state in firmware
1133 * The kernel, a masked-off hotkey, and WLSW can change the radio state
1134 * (TODO: verify how WLSW interacts with the returned radio state).
1136 * The only time there are shadow radio state changes, is when
1137 * masked-off hotkeys are used.
1141 * Internal driver API for radio state:
1143 * int: < 0 = error, otherwise enum tpacpi_rfkill_state
1144 * bool: true means radio blocked (off)
1146 enum tpacpi_rfkill_state
{
1147 TPACPI_RFK_RADIO_OFF
= 0,
1151 /* rfkill switches */
1152 enum tpacpi_rfk_id
{
1153 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
1154 TPACPI_RFK_WWAN_SW_ID
,
1155 TPACPI_RFK_UWB_SW_ID
,
1159 static const char *tpacpi_rfkill_names
[] = {
1160 [TPACPI_RFK_BLUETOOTH_SW_ID
] = "bluetooth",
1161 [TPACPI_RFK_WWAN_SW_ID
] = "wwan",
1162 [TPACPI_RFK_UWB_SW_ID
] = "uwb",
1163 [TPACPI_RFK_SW_MAX
] = NULL
1166 /* ThinkPad-ACPI rfkill subdriver */
1168 struct rfkill
*rfkill
;
1169 enum tpacpi_rfk_id id
;
1170 const struct tpacpi_rfk_ops
*ops
;
1173 struct tpacpi_rfk_ops
{
1174 /* firmware interface */
1175 int (*get_status
)(void);
1176 int (*set_status
)(const enum tpacpi_rfkill_state
);
1179 static struct tpacpi_rfk
*tpacpi_rfkill_switches
[TPACPI_RFK_SW_MAX
];
1181 /* Query FW and update rfkill sw state for a given rfkill switch */
1182 static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk
*tp_rfk
)
1189 status
= (tp_rfk
->ops
->get_status
)();
1193 rfkill_set_sw_state(tp_rfk
->rfkill
,
1194 (status
== TPACPI_RFK_RADIO_OFF
));
1199 /* Query FW and update rfkill sw state for all rfkill switches */
1200 static void tpacpi_rfk_update_swstate_all(void)
1204 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++)
1205 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[i
]);
1209 * Sync the HW-blocking state of all rfkill switches,
1210 * do notice it causes the rfkill core to schedule uevents
1212 static void tpacpi_rfk_update_hwblock_state(bool blocked
)
1215 struct tpacpi_rfk
*tp_rfk
;
1217 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++) {
1218 tp_rfk
= tpacpi_rfkill_switches
[i
];
1220 if (rfkill_set_hw_state(tp_rfk
->rfkill
,
1222 /* ignore -- we track sw block */
1228 /* Call to get the WLSW state from the firmware */
1229 static int hotkey_get_wlsw(void);
1231 /* Call to query WLSW state and update all rfkill switches */
1232 static bool tpacpi_rfk_check_hwblock_state(void)
1234 int res
= hotkey_get_wlsw();
1237 /* When unknown or unsupported, we have to assume it is unblocked */
1241 hw_blocked
= (res
== TPACPI_RFK_RADIO_OFF
);
1242 tpacpi_rfk_update_hwblock_state(hw_blocked
);
1247 static int tpacpi_rfk_hook_set_block(void *data
, bool blocked
)
1249 struct tpacpi_rfk
*tp_rfk
= data
;
1252 dbg_printk(TPACPI_DBG_RFKILL
,
1253 "request to change radio state to %s\n",
1254 blocked
? "blocked" : "unblocked");
1256 /* try to set radio state */
1257 res
= (tp_rfk
->ops
->set_status
)(blocked
?
1258 TPACPI_RFK_RADIO_OFF
: TPACPI_RFK_RADIO_ON
);
1260 /* and update the rfkill core with whatever the FW really did */
1261 tpacpi_rfk_update_swstate(tp_rfk
);
1263 return (res
< 0) ? res
: 0;
1266 static const struct rfkill_ops tpacpi_rfk_rfkill_ops
= {
1267 .set_block
= tpacpi_rfk_hook_set_block
,
1270 static int __init
tpacpi_new_rfkill(const enum tpacpi_rfk_id id
,
1271 const struct tpacpi_rfk_ops
*tp_rfkops
,
1272 const enum rfkill_type rfktype
,
1274 const bool set_default
)
1276 struct tpacpi_rfk
*atp_rfk
;
1278 bool sw_state
= false;
1282 BUG_ON(id
>= TPACPI_RFK_SW_MAX
|| tpacpi_rfkill_switches
[id
]);
1284 atp_rfk
= kzalloc(sizeof(struct tpacpi_rfk
), GFP_KERNEL
);
1286 atp_rfk
->rfkill
= rfkill_alloc(name
,
1289 &tpacpi_rfk_rfkill_ops
,
1291 if (!atp_rfk
|| !atp_rfk
->rfkill
) {
1293 "failed to allocate memory for rfkill class\n");
1299 atp_rfk
->ops
= tp_rfkops
;
1301 sw_status
= (tp_rfkops
->get_status
)();
1302 if (sw_status
< 0) {
1304 "failed to read initial state for %s, error %d\n",
1307 sw_state
= (sw_status
== TPACPI_RFK_RADIO_OFF
);
1309 /* try to keep the initial state, since we ask the
1310 * firmware to preserve it across S5 in NVRAM */
1311 rfkill_init_sw_state(atp_rfk
->rfkill
, sw_state
);
1314 hw_state
= tpacpi_rfk_check_hwblock_state();
1315 rfkill_set_hw_state(atp_rfk
->rfkill
, hw_state
);
1317 res
= rfkill_register(atp_rfk
->rfkill
);
1320 "failed to register %s rfkill switch: %d\n",
1322 rfkill_destroy(atp_rfk
->rfkill
);
1327 tpacpi_rfkill_switches
[id
] = atp_rfk
;
1329 printk(TPACPI_INFO
"rfkill switch %s: radio is %sblocked\n",
1330 name
, (sw_state
|| hw_state
) ? "" : "un");
1334 static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id
)
1336 struct tpacpi_rfk
*tp_rfk
;
1338 BUG_ON(id
>= TPACPI_RFK_SW_MAX
);
1340 tp_rfk
= tpacpi_rfkill_switches
[id
];
1342 rfkill_unregister(tp_rfk
->rfkill
);
1343 rfkill_destroy(tp_rfk
->rfkill
);
1344 tpacpi_rfkill_switches
[id
] = NULL
;
1349 static void printk_deprecated_rfkill_attribute(const char * const what
)
1351 printk_deprecated_attribute(what
,
1352 "Please switch to generic rfkill before year 2010");
1355 /* sysfs <radio> enable ------------------------------------------------ */
1356 static ssize_t
tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id
,
1357 struct device_attribute
*attr
,
1362 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1364 /* This is in the ABI... */
1365 if (tpacpi_rfk_check_hwblock_state()) {
1366 status
= TPACPI_RFK_RADIO_OFF
;
1368 status
= tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1373 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1374 (status
== TPACPI_RFK_RADIO_ON
) ? 1 : 0);
1377 static ssize_t
tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id
,
1378 struct device_attribute
*attr
,
1379 const char *buf
, size_t count
)
1384 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1386 if (parse_strtoul(buf
, 1, &t
))
1389 tpacpi_disclose_usertask(attr
->attr
.name
, "set to %ld\n", t
);
1391 /* This is in the ABI... */
1392 if (tpacpi_rfk_check_hwblock_state() && !!t
)
1395 res
= tpacpi_rfkill_switches
[id
]->ops
->set_status((!!t
) ?
1396 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
);
1397 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1399 return (res
< 0) ? res
: count
;
1402 /* procfs -------------------------------------------------------------- */
1403 static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id
, struct seq_file
*m
)
1405 if (id
>= TPACPI_RFK_SW_MAX
)
1406 seq_printf(m
, "status:\t\tnot supported\n");
1410 /* This is in the ABI... */
1411 if (tpacpi_rfk_check_hwblock_state()) {
1412 status
= TPACPI_RFK_RADIO_OFF
;
1414 status
= tpacpi_rfk_update_swstate(
1415 tpacpi_rfkill_switches
[id
]);
1420 seq_printf(m
, "status:\t\t%s\n",
1421 (status
== TPACPI_RFK_RADIO_ON
) ?
1422 "enabled" : "disabled");
1423 seq_printf(m
, "commands:\tenable, disable\n");
1429 static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id
, char *buf
)
1435 if (id
>= TPACPI_RFK_SW_MAX
)
1438 while ((cmd
= next_cmd(&buf
))) {
1439 if (strlencmp(cmd
, "enable") == 0)
1440 status
= TPACPI_RFK_RADIO_ON
;
1441 else if (strlencmp(cmd
, "disable") == 0)
1442 status
= TPACPI_RFK_RADIO_OFF
;
1448 tpacpi_disclose_usertask("procfs", "attempt to %s %s\n",
1449 (status
== TPACPI_RFK_RADIO_ON
) ?
1450 "enable" : "disable",
1451 tpacpi_rfkill_names
[id
]);
1452 res
= (tpacpi_rfkill_switches
[id
]->ops
->set_status
)(status
);
1453 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1459 /*************************************************************************
1460 * thinkpad-acpi driver attributes
1463 /* interface_version --------------------------------------------------- */
1464 static ssize_t
tpacpi_driver_interface_version_show(
1465 struct device_driver
*drv
,
1468 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1471 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1472 tpacpi_driver_interface_version_show
, NULL
);
1474 /* debug_level --------------------------------------------------------- */
1475 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1478 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1481 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1482 const char *buf
, size_t count
)
1486 if (parse_strtoul(buf
, 0xffff, &t
))
1494 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1495 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1497 /* version ------------------------------------------------------------- */
1498 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1501 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1502 TPACPI_DESC
, TPACPI_VERSION
);
1505 static DRIVER_ATTR(version
, S_IRUGO
,
1506 tpacpi_driver_version_show
, NULL
);
1508 /* --------------------------------------------------------------------- */
1510 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1512 /* wlsw_emulstate ------------------------------------------------------ */
1513 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1516 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1519 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1520 const char *buf
, size_t count
)
1524 if (parse_strtoul(buf
, 1, &t
))
1527 if (tpacpi_wlsw_emulstate
!= !!t
) {
1528 tpacpi_wlsw_emulstate
= !!t
;
1529 tpacpi_rfk_update_hwblock_state(!t
); /* negative logic */
1535 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1536 tpacpi_driver_wlsw_emulstate_show
,
1537 tpacpi_driver_wlsw_emulstate_store
);
1539 /* bluetooth_emulstate ------------------------------------------------- */
1540 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1541 struct device_driver
*drv
,
1544 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1547 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1548 struct device_driver
*drv
,
1549 const char *buf
, size_t count
)
1553 if (parse_strtoul(buf
, 1, &t
))
1556 tpacpi_bluetooth_emulstate
= !!t
;
1561 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1562 tpacpi_driver_bluetooth_emulstate_show
,
1563 tpacpi_driver_bluetooth_emulstate_store
);
1565 /* wwan_emulstate ------------------------------------------------- */
1566 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1567 struct device_driver
*drv
,
1570 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1573 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1574 struct device_driver
*drv
,
1575 const char *buf
, size_t count
)
1579 if (parse_strtoul(buf
, 1, &t
))
1582 tpacpi_wwan_emulstate
= !!t
;
1587 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1588 tpacpi_driver_wwan_emulstate_show
,
1589 tpacpi_driver_wwan_emulstate_store
);
1591 /* uwb_emulstate ------------------------------------------------- */
1592 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1593 struct device_driver
*drv
,
1596 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1599 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1600 struct device_driver
*drv
,
1601 const char *buf
, size_t count
)
1605 if (parse_strtoul(buf
, 1, &t
))
1608 tpacpi_uwb_emulstate
= !!t
;
1613 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1614 tpacpi_driver_uwb_emulstate_show
,
1615 tpacpi_driver_uwb_emulstate_store
);
1618 /* --------------------------------------------------------------------- */
1620 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1621 &driver_attr_debug_level
, &driver_attr_version
,
1622 &driver_attr_interface_version
,
1625 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1631 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1632 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1636 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1637 if (!res
&& dbg_wlswemul
)
1638 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1639 if (!res
&& dbg_bluetoothemul
)
1640 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1641 if (!res
&& dbg_wwanemul
)
1642 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1643 if (!res
&& dbg_uwbemul
)
1644 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1650 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1654 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1655 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1657 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1658 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1659 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1660 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1661 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1665 /*************************************************************************
1670 * Table of recommended minimum BIOS versions
1672 * Reasons for listing:
1673 * 1. Stable BIOS, listed because the unknown ammount of
1674 * bugs and bad ACPI behaviour on older versions
1676 * 2. BIOS or EC fw with known bugs that trigger on Linux
1678 * 3. BIOS with known reduced functionality in older versions
1680 * We recommend the latest BIOS and EC version.
1681 * We only support the latest BIOS and EC fw version as a rule.
1683 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1684 * Information from users in ThinkWiki
1686 * WARNING: we use this table also to detect that the machine is
1687 * a ThinkPad in some cases, so don't remove entries lightly.
1690 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1691 { .vendor = (__v), \
1692 .bios = TPID(__id1, __id2), \
1693 .ec = TPACPI_MATCH_ANY, \
1694 .quirks = TPACPI_MATCH_ANY << 16 \
1695 | (__bv1) << 8 | (__bv2) }
1697 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1698 __eid, __ev1, __ev2) \
1699 { .vendor = (__v), \
1700 .bios = TPID(__bid1, __bid2), \
1702 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1703 | (__bv1) << 8 | (__bv2) }
1705 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1706 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1708 /* Outdated IBM BIOSes often lack the EC id string */
1709 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1710 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1711 __bv1, __bv2, TPID(__id1, __id2), \
1713 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1714 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1717 /* Outdated IBM BIOSes often lack the EC id string */
1718 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1719 __eid1, __eid2, __ev1, __ev2) \
1720 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1721 __bv1, __bv2, TPID(__eid1, __eid2), \
1723 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1724 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1727 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1728 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1730 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1731 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1732 __bv1, __bv2, TPID(__id1, __id2), \
1735 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1736 __eid1, __eid2, __ev1, __ev2) \
1737 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1738 __bv1, __bv2, TPID(__eid1, __eid2), \
1741 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1742 /* Numeric models ------------------ */
1743 /* FW MODEL BIOS VERS */
1744 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1745 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1746 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1747 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1748 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1749 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1750 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1751 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1752 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1754 /* A-series ------------------------- */
1755 /* FW MODEL BIOS VERS EC VERS */
1756 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1757 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1758 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1759 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1760 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1761 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1762 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1763 TPV_QI0('1', '3', '2', '0'), /* A22m */
1764 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1765 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1766 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1768 /* G-series ------------------------- */
1769 /* FW MODEL BIOS VERS */
1770 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1771 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1773 /* R-series, T-series --------------- */
1774 /* FW MODEL BIOS VERS EC VERS */
1775 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1776 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1777 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1778 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1779 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1780 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1781 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1782 T40/p, T41/p, T42/p (1) */
1783 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1784 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1785 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1786 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1788 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1789 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1790 TPV_QI0('1', '6', '3', '2'), /* T22 */
1791 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1792 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1793 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1795 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1796 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1797 TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */
1799 /* BIOS FW BIOS VERS EC FW EC VERS */
1800 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1801 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1803 /* X-series ------------------------- */
1804 /* FW MODEL BIOS VERS EC VERS */
1805 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1806 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1807 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1808 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1809 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1810 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1811 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1813 TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */
1814 TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */
1816 /* (0) - older versions lack DMI EC fw string and functionality */
1817 /* (1) - older versions known to lack functionality */
1828 static void __init
tpacpi_check_outdated_fw(void)
1830 unsigned long fwvers
;
1831 u16 ec_version
, bios_version
;
1833 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1834 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1839 bios_version
= fwvers
& 0xffffU
;
1840 ec_version
= (fwvers
>> 16) & 0xffffU
;
1842 /* note that unknown versions are set to 0x0000 and we use that */
1843 if ((bios_version
> thinkpad_id
.bios_release
) ||
1844 (ec_version
> thinkpad_id
.ec_release
&&
1845 ec_version
!= TPACPI_MATCH_ANY
)) {
1847 * The changelogs would let us track down the exact
1848 * reason, but it is just too much of a pain to track
1849 * it. We only list BIOSes that are either really
1850 * broken, or really stable to begin with, so it is
1851 * best if the user upgrades the firmware anyway.
1854 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1856 "WARNING: This firmware may be missing critical bug "
1857 "fixes and/or important features\n");
1861 static bool __init
tpacpi_is_fw_known(void)
1863 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1864 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1867 /****************************************************************************
1868 ****************************************************************************
1872 ****************************************************************************
1873 ****************************************************************************/
1875 /*************************************************************************
1876 * thinkpad-acpi init subdriver
1879 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1881 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1882 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1884 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1885 (thinkpad_id
.bios_version_str
) ?
1886 thinkpad_id
.bios_version_str
: "unknown",
1887 (thinkpad_id
.ec_version_str
) ?
1888 thinkpad_id
.ec_version_str
: "unknown");
1890 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1891 printk(TPACPI_INFO
"%s %s, model %s\n",
1892 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1893 "IBM" : ((thinkpad_id
.vendor
==
1894 PCI_VENDOR_ID_LENOVO
) ?
1895 "Lenovo" : "Unknown vendor"),
1896 thinkpad_id
.model_str
,
1897 (thinkpad_id
.nummodel_str
) ?
1898 thinkpad_id
.nummodel_str
: "unknown");
1900 tpacpi_check_outdated_fw();
1904 static int thinkpad_acpi_driver_read(struct seq_file
*m
)
1906 seq_printf(m
, "driver:\t\t%s\n", TPACPI_DESC
);
1907 seq_printf(m
, "version:\t%s\n", TPACPI_VERSION
);
1911 static struct ibm_struct thinkpad_acpi_driver_data
= {
1913 .read
= thinkpad_acpi_driver_read
,
1916 /*************************************************************************
1921 * ThinkPad firmware event model
1923 * The ThinkPad firmware has two main event interfaces: normal ACPI
1924 * notifications (which follow the ACPI standard), and a private event
1927 * The private event interface also issues events for the hotkeys. As
1928 * the driver gained features, the event handling code ended up being
1929 * built around the hotkey subdriver. This will need to be refactored
1930 * to a more formal event API eventually.
1932 * Some "hotkeys" are actually supposed to be used as event reports,
1933 * such as "brightness has changed", "volume has changed", depending on
1934 * the ThinkPad model and how the firmware is operating.
1936 * Unlike other classes, hotkey-class events have mask/unmask control on
1937 * non-ancient firmware. However, how it behaves changes a lot with the
1938 * firmware model and version.
1941 enum { /* hot key scan codes (derived from ACPI DSDT) */
1942 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1943 TP_ACPI_HOTKEYSCAN_FNF2
,
1944 TP_ACPI_HOTKEYSCAN_FNF3
,
1945 TP_ACPI_HOTKEYSCAN_FNF4
,
1946 TP_ACPI_HOTKEYSCAN_FNF5
,
1947 TP_ACPI_HOTKEYSCAN_FNF6
,
1948 TP_ACPI_HOTKEYSCAN_FNF7
,
1949 TP_ACPI_HOTKEYSCAN_FNF8
,
1950 TP_ACPI_HOTKEYSCAN_FNF9
,
1951 TP_ACPI_HOTKEYSCAN_FNF10
,
1952 TP_ACPI_HOTKEYSCAN_FNF11
,
1953 TP_ACPI_HOTKEYSCAN_FNF12
,
1954 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1955 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1956 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1957 TP_ACPI_HOTKEYSCAN_FNHOME
,
1958 TP_ACPI_HOTKEYSCAN_FNEND
,
1959 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1960 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1961 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1962 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1963 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1964 TP_ACPI_HOTKEYSCAN_MUTE
,
1965 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1968 enum { /* Keys/events available through NVRAM polling */
1969 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1970 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1973 enum { /* Positions of some of the keys in hotkey masks */
1974 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1975 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1976 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1977 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1978 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1979 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1980 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1981 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1982 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1983 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1984 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1987 enum { /* NVRAM to ACPI HKEY group map */
1988 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1989 TP_ACPI_HKEY_ZOOM_MASK
|
1990 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1991 TP_ACPI_HKEY_HIBERNATE_MASK
,
1992 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1993 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1994 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1995 TP_ACPI_HKEY_VOLDWN_MASK
|
1996 TP_ACPI_HKEY_MUTE_MASK
,
1999 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2000 struct tp_nvram_state
{
2001 u16 thinkpad_toggle
:1;
2003 u16 display_toggle
:1;
2004 u16 thinklight_toggle
:1;
2005 u16 hibernate_toggle
:1;
2006 u16 displayexp_toggle
:1;
2007 u16 display_state
:1;
2008 u16 brightness_toggle
:1;
2009 u16 volume_toggle
:1;
2012 u8 brightness_level
;
2016 /* kthread for the hotkey poller */
2017 static struct task_struct
*tpacpi_hotkey_task
;
2019 /* Acquired while the poller kthread is running, use to sync start/stop */
2020 static struct mutex hotkey_thread_mutex
;
2023 * Acquire mutex to write poller control variables as an
2026 * Increment hotkey_config_change when changing them if you
2027 * want the kthread to forget old state.
2029 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2031 static struct mutex hotkey_thread_data_mutex
;
2032 static unsigned int hotkey_config_change
;
2035 * hotkey poller control variables
2037 * Must be atomic or readers will also need to acquire mutex
2039 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2040 * should be used only when the changes need to be taken as
2041 * a block, OR when one needs to force the kthread to forget
2044 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
2045 static unsigned int hotkey_poll_freq
= 10; /* Hz */
2047 #define HOTKEY_CONFIG_CRITICAL_START \
2049 mutex_lock(&hotkey_thread_data_mutex); \
2050 hotkey_config_change++; \
2052 #define HOTKEY_CONFIG_CRITICAL_END \
2053 mutex_unlock(&hotkey_thread_data_mutex);
2055 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2057 #define hotkey_source_mask 0U
2058 #define HOTKEY_CONFIG_CRITICAL_START
2059 #define HOTKEY_CONFIG_CRITICAL_END
2061 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2063 static struct mutex hotkey_mutex
;
2065 static enum { /* Reasons for waking up */
2066 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
2067 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
2068 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
2069 } hotkey_wakeup_reason
;
2071 static int hotkey_autosleep_ack
;
2073 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
2074 static u32 hotkey_all_mask
; /* all events supported in fw */
2075 static u32 hotkey_reserved_mask
; /* events better left disabled */
2076 static u32 hotkey_driver_mask
; /* events needed by the driver */
2077 static u32 hotkey_user_mask
; /* events visible to userspace */
2078 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
2080 static unsigned int hotkey_report_mode
;
2082 static u16
*hotkey_keycode_map
;
2084 static struct attribute_set
*hotkey_dev_attributes
;
2086 static void tpacpi_driver_event(const unsigned int hkey_event
);
2087 static void hotkey_driver_event(const unsigned int scancode
);
2089 /* HKEY.MHKG() return bits */
2090 #define TP_HOTKEY_TABLET_MASK (1 << 3)
2092 static int hotkey_get_wlsw(void)
2096 if (!tp_features
.hotkey_wlsw
)
2099 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2101 return (tpacpi_wlsw_emulstate
) ?
2102 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2105 if (!acpi_evalf(hkey_handle
, &status
, "WLSW", "d"))
2108 return (status
) ? TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2111 static int hotkey_get_tablet_mode(int *status
)
2115 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
2118 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
2123 * Reads current event mask from firmware, and updates
2124 * hotkey_acpi_mask accordingly. Also resets any bits
2125 * from hotkey_user_mask that are unavailable to be
2126 * delivered (shadow requirement of the userspace ABI).
2128 * Call with hotkey_mutex held
2130 static int hotkey_mask_get(void)
2132 if (tp_features
.hotkey_mask
) {
2135 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
2138 hotkey_acpi_mask
= m
;
2140 /* no mask support doesn't mean no event support... */
2141 hotkey_acpi_mask
= hotkey_all_mask
;
2144 /* sync userspace-visible mask */
2145 hotkey_user_mask
&= (hotkey_acpi_mask
| hotkey_source_mask
);
2150 void static hotkey_mask_warn_incomplete_mask(void)
2152 /* log only what the user can fix... */
2153 const u32 wantedmask
= hotkey_driver_mask
&
2154 ~(hotkey_acpi_mask
| hotkey_source_mask
) &
2155 (hotkey_all_mask
| TPACPI_HKEY_NVRAM_KNOWN_MASK
);
2158 printk(TPACPI_NOTICE
2159 "required events 0x%08x not enabled!\n",
2164 * Set the firmware mask when supported
2166 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
2168 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
2170 * Call with hotkey_mutex held
2172 static int hotkey_mask_set(u32 mask
)
2177 const u32 fwmask
= mask
& ~hotkey_source_mask
;
2179 if (tp_features
.hotkey_mask
) {
2180 for (i
= 0; i
< 32; i
++) {
2181 if (!acpi_evalf(hkey_handle
,
2182 NULL
, "MHKM", "vdd", i
+ 1,
2183 !!(mask
& (1 << i
)))) {
2191 * We *must* make an inconditional call to hotkey_mask_get to
2192 * refresh hotkey_acpi_mask and update hotkey_user_mask
2194 * Take the opportunity to also log when we cannot _enable_
2197 if (!hotkey_mask_get() && !rc
&& (fwmask
& ~hotkey_acpi_mask
)) {
2198 printk(TPACPI_NOTICE
2199 "asked for hotkey mask 0x%08x, but "
2200 "firmware forced it to 0x%08x\n",
2201 fwmask
, hotkey_acpi_mask
);
2204 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
)
2205 hotkey_mask_warn_incomplete_mask();
2211 * Sets hotkey_user_mask and tries to set the firmware mask
2213 * Call with hotkey_mutex held
2215 static int hotkey_user_mask_set(const u32 mask
)
2219 /* Give people a chance to notice they are doing something that
2220 * is bound to go boom on their users sooner or later */
2221 if (!tp_warned
.hotkey_mask_ff
&&
2222 (mask
== 0xffff || mask
== 0xffffff ||
2223 mask
== 0xffffffff)) {
2224 tp_warned
.hotkey_mask_ff
= 1;
2225 printk(TPACPI_NOTICE
2226 "setting the hotkey mask to 0x%08x is likely "
2227 "not the best way to go about it\n", mask
);
2228 printk(TPACPI_NOTICE
2229 "please consider using the driver defaults, "
2230 "and refer to up-to-date thinkpad-acpi "
2234 /* Try to enable what the user asked for, plus whatever we need.
2235 * this syncs everything but won't enable bits in hotkey_user_mask */
2236 rc
= hotkey_mask_set((mask
| hotkey_driver_mask
) & ~hotkey_source_mask
);
2238 /* Enable the available bits in hotkey_user_mask */
2239 hotkey_user_mask
= mask
& (hotkey_acpi_mask
| hotkey_source_mask
);
2245 * Sets the driver hotkey mask.
2247 * Can be called even if the hotkey subdriver is inactive
2249 static int tpacpi_hotkey_driver_mask_set(const u32 mask
)
2253 /* Do the right thing if hotkey_init has not been called yet */
2254 if (!tp_features
.hotkey
) {
2255 hotkey_driver_mask
= mask
;
2259 mutex_lock(&hotkey_mutex
);
2261 HOTKEY_CONFIG_CRITICAL_START
2262 hotkey_driver_mask
= mask
;
2263 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2264 hotkey_source_mask
|= (mask
& ~hotkey_all_mask
);
2266 HOTKEY_CONFIG_CRITICAL_END
2268 rc
= hotkey_mask_set((hotkey_acpi_mask
| hotkey_driver_mask
) &
2269 ~hotkey_source_mask
);
2270 mutex_unlock(&hotkey_mutex
);
2275 static int hotkey_status_get(int *status
)
2277 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
2283 static int hotkey_status_set(bool enable
)
2285 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
2291 static void tpacpi_input_send_tabletsw(void)
2295 if (tp_features
.hotkey_tablet
&&
2296 !hotkey_get_tablet_mode(&state
)) {
2297 mutex_lock(&tpacpi_inputdev_send_mutex
);
2299 input_report_switch(tpacpi_inputdev
,
2300 SW_TABLET_MODE
, !!state
);
2301 input_sync(tpacpi_inputdev
);
2303 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2307 /* Do NOT call without validating scancode first */
2308 static void tpacpi_input_send_key(const unsigned int scancode
)
2310 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
2312 if (keycode
!= KEY_RESERVED
) {
2313 mutex_lock(&tpacpi_inputdev_send_mutex
);
2315 input_report_key(tpacpi_inputdev
, keycode
, 1);
2316 if (keycode
== KEY_UNKNOWN
)
2317 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2319 input_sync(tpacpi_inputdev
);
2321 input_report_key(tpacpi_inputdev
, keycode
, 0);
2322 if (keycode
== KEY_UNKNOWN
)
2323 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2325 input_sync(tpacpi_inputdev
);
2327 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2331 /* Do NOT call without validating scancode first */
2332 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
2334 hotkey_driver_event(scancode
);
2335 if (hotkey_user_mask
& (1 << scancode
))
2336 tpacpi_input_send_key(scancode
);
2339 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2340 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2342 /* Do NOT call without validating scancode first */
2343 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2345 tpacpi_input_send_key_masked(scancode
);
2346 if (hotkey_report_mode
< 2) {
2347 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2348 0x80, TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
2352 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2356 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2357 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2358 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2359 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2360 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2361 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2363 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2364 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2365 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2367 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2368 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2369 n
->displayexp_toggle
=
2370 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2372 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2373 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2374 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2375 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2376 n
->brightness_toggle
=
2377 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2379 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2380 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2381 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2382 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2383 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2384 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2388 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2389 struct tp_nvram_state
*newn
,
2390 const u32 event_mask
)
2393 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2395 if ((event_mask & (1 << __scancode)) && \
2396 oldn->__member != newn->__member) \
2397 tpacpi_hotkey_send_key(__scancode); \
2400 #define TPACPI_MAY_SEND_KEY(__scancode) \
2402 if (event_mask & (1 << __scancode)) \
2403 tpacpi_hotkey_send_key(__scancode); \
2406 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2407 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2408 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2409 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2411 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2413 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2416 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2417 if (oldn
->mute
!= newn
->mute
) {
2418 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2420 if (oldn
->volume_level
> newn
->volume_level
) {
2421 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2422 } else if (oldn
->volume_level
< newn
->volume_level
) {
2423 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2424 } else if (oldn
->mute
== newn
->mute
) {
2425 /* repeated key presses that didn't change state */
2427 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2428 } else if (newn
->volume_level
!= 0) {
2429 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2431 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2436 /* handle brightness */
2437 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2438 if (oldn
->brightness_level
< newn
->brightness_level
) {
2439 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2440 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
2441 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2443 /* repeated key presses that didn't change state */
2444 if (newn
->brightness_level
!= 0) {
2445 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2447 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2452 #undef TPACPI_COMPARE_KEY
2453 #undef TPACPI_MAY_SEND_KEY
2459 * We track all events in hotkey_source_mask all the time, since
2460 * most of them are edge-based. We only issue those requested by
2461 * hotkey_user_mask or hotkey_driver_mask, though.
2463 static int hotkey_kthread(void *data
)
2465 struct tp_nvram_state s
[2];
2466 u32 poll_mask
, event_mask
;
2467 unsigned int si
, so
;
2469 unsigned int change_detector
, must_reset
;
2470 unsigned int poll_freq
;
2472 mutex_lock(&hotkey_thread_mutex
);
2474 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2483 /* Initial state for compares */
2484 mutex_lock(&hotkey_thread_data_mutex
);
2485 change_detector
= hotkey_config_change
;
2486 poll_mask
= hotkey_source_mask
;
2487 event_mask
= hotkey_source_mask
&
2488 (hotkey_driver_mask
| hotkey_user_mask
);
2489 poll_freq
= hotkey_poll_freq
;
2490 mutex_unlock(&hotkey_thread_data_mutex
);
2491 hotkey_read_nvram(&s
[so
], poll_mask
);
2493 while (!kthread_should_stop()) {
2495 if (likely(poll_freq
))
2498 t
= 100; /* should never happen... */
2500 t
= msleep_interruptible(t
);
2501 if (unlikely(kthread_should_stop()))
2503 must_reset
= try_to_freeze();
2504 if (t
> 0 && !must_reset
)
2507 mutex_lock(&hotkey_thread_data_mutex
);
2508 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2509 /* forget old state on thaw or config change */
2512 change_detector
= hotkey_config_change
;
2514 poll_mask
= hotkey_source_mask
;
2515 event_mask
= hotkey_source_mask
&
2516 (hotkey_driver_mask
| hotkey_user_mask
);
2517 poll_freq
= hotkey_poll_freq
;
2518 mutex_unlock(&hotkey_thread_data_mutex
);
2520 if (likely(poll_mask
)) {
2521 hotkey_read_nvram(&s
[si
], poll_mask
);
2522 if (likely(si
!= so
)) {
2523 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2533 mutex_unlock(&hotkey_thread_mutex
);
2537 /* call with hotkey_mutex held */
2538 static void hotkey_poll_stop_sync(void)
2540 if (tpacpi_hotkey_task
) {
2541 if (frozen(tpacpi_hotkey_task
) ||
2542 freezing(tpacpi_hotkey_task
))
2543 thaw_process(tpacpi_hotkey_task
);
2545 kthread_stop(tpacpi_hotkey_task
);
2546 tpacpi_hotkey_task
= NULL
;
2547 mutex_lock(&hotkey_thread_mutex
);
2548 /* at this point, the thread did exit */
2549 mutex_unlock(&hotkey_thread_mutex
);
2553 /* call with hotkey_mutex held */
2554 static void hotkey_poll_setup(bool may_warn
)
2556 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2557 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2559 if (hotkey_poll_freq
> 0 &&
2560 (poll_driver_mask
||
2561 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2562 if (!tpacpi_hotkey_task
) {
2563 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2564 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2565 if (IS_ERR(tpacpi_hotkey_task
)) {
2566 tpacpi_hotkey_task
= NULL
;
2568 "could not create kernel thread "
2569 "for hotkey polling\n");
2573 hotkey_poll_stop_sync();
2574 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2575 hotkey_poll_freq
== 0) {
2576 printk(TPACPI_NOTICE
2577 "hot keys 0x%08x and/or events 0x%08x "
2578 "require polling, which is currently "
2580 poll_user_mask
, poll_driver_mask
);
2585 static void hotkey_poll_setup_safe(bool may_warn
)
2587 mutex_lock(&hotkey_mutex
);
2588 hotkey_poll_setup(may_warn
);
2589 mutex_unlock(&hotkey_mutex
);
2592 /* call with hotkey_mutex held */
2593 static void hotkey_poll_set_freq(unsigned int freq
)
2596 hotkey_poll_stop_sync();
2598 hotkey_poll_freq
= freq
;
2601 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2603 static void hotkey_poll_setup_safe(bool __unused
)
2607 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2609 static int hotkey_inputdev_open(struct input_dev
*dev
)
2611 switch (tpacpi_lifecycle
) {
2612 case TPACPI_LIFE_INIT
:
2614 * hotkey_init will call hotkey_poll_setup_safe
2615 * at the appropriate moment
2618 case TPACPI_LIFE_EXITING
:
2620 case TPACPI_LIFE_RUNNING
:
2621 hotkey_poll_setup_safe(false);
2625 /* Should only happen if tpacpi_lifecycle is corrupt */
2630 static void hotkey_inputdev_close(struct input_dev
*dev
)
2632 /* disable hotkey polling when possible */
2633 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
&&
2634 !(hotkey_source_mask
& hotkey_driver_mask
))
2635 hotkey_poll_setup_safe(false);
2638 /* sysfs hotkey enable ------------------------------------------------- */
2639 static ssize_t
hotkey_enable_show(struct device
*dev
,
2640 struct device_attribute
*attr
,
2645 printk_deprecated_attribute("hotkey_enable",
2646 "Hotkey reporting is always enabled");
2648 res
= hotkey_status_get(&status
);
2652 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2655 static ssize_t
hotkey_enable_store(struct device
*dev
,
2656 struct device_attribute
*attr
,
2657 const char *buf
, size_t count
)
2661 printk_deprecated_attribute("hotkey_enable",
2662 "Hotkeys can be disabled through hotkey_mask");
2664 if (parse_strtoul(buf
, 1, &t
))
2673 static struct device_attribute dev_attr_hotkey_enable
=
2674 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2675 hotkey_enable_show
, hotkey_enable_store
);
2677 /* sysfs hotkey mask --------------------------------------------------- */
2678 static ssize_t
hotkey_mask_show(struct device
*dev
,
2679 struct device_attribute
*attr
,
2682 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2685 static ssize_t
hotkey_mask_store(struct device
*dev
,
2686 struct device_attribute
*attr
,
2687 const char *buf
, size_t count
)
2692 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2695 if (mutex_lock_killable(&hotkey_mutex
))
2696 return -ERESTARTSYS
;
2698 res
= hotkey_user_mask_set(t
);
2700 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2701 hotkey_poll_setup(true);
2704 mutex_unlock(&hotkey_mutex
);
2706 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2708 return (res
) ? res
: count
;
2711 static struct device_attribute dev_attr_hotkey_mask
=
2712 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2713 hotkey_mask_show
, hotkey_mask_store
);
2715 /* sysfs hotkey bios_enabled ------------------------------------------- */
2716 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2717 struct device_attribute
*attr
,
2720 return sprintf(buf
, "0\n");
2723 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2724 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2726 /* sysfs hotkey bios_mask ---------------------------------------------- */
2727 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2728 struct device_attribute
*attr
,
2731 printk_deprecated_attribute("hotkey_bios_mask",
2732 "This attribute is useless.");
2733 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2736 static struct device_attribute dev_attr_hotkey_bios_mask
=
2737 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2739 /* sysfs hotkey all_mask ----------------------------------------------- */
2740 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2741 struct device_attribute
*attr
,
2744 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2745 hotkey_all_mask
| hotkey_source_mask
);
2748 static struct device_attribute dev_attr_hotkey_all_mask
=
2749 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2751 /* sysfs hotkey recommended_mask --------------------------------------- */
2752 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2753 struct device_attribute
*attr
,
2756 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2757 (hotkey_all_mask
| hotkey_source_mask
)
2758 & ~hotkey_reserved_mask
);
2761 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2762 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2763 hotkey_recommended_mask_show
, NULL
);
2765 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2767 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2768 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2769 struct device_attribute
*attr
,
2772 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2775 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2776 struct device_attribute
*attr
,
2777 const char *buf
, size_t count
)
2783 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2784 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2787 if (mutex_lock_killable(&hotkey_mutex
))
2788 return -ERESTARTSYS
;
2790 HOTKEY_CONFIG_CRITICAL_START
2791 hotkey_source_mask
= t
;
2792 HOTKEY_CONFIG_CRITICAL_END
2794 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2795 ~hotkey_source_mask
);
2796 hotkey_poll_setup(true);
2798 /* check if events needed by the driver got disabled */
2799 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2800 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2802 mutex_unlock(&hotkey_mutex
);
2805 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2806 "firmware event mask!\n");
2809 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2810 "some important events were disabled: "
2813 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2815 return (rc
< 0) ? rc
: count
;
2818 static struct device_attribute dev_attr_hotkey_source_mask
=
2819 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2820 hotkey_source_mask_show
, hotkey_source_mask_store
);
2822 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2823 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2824 struct device_attribute
*attr
,
2827 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2830 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2831 struct device_attribute
*attr
,
2832 const char *buf
, size_t count
)
2836 if (parse_strtoul(buf
, 25, &t
))
2839 if (mutex_lock_killable(&hotkey_mutex
))
2840 return -ERESTARTSYS
;
2842 hotkey_poll_set_freq(t
);
2843 hotkey_poll_setup(true);
2845 mutex_unlock(&hotkey_mutex
);
2847 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2852 static struct device_attribute dev_attr_hotkey_poll_freq
=
2853 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2854 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2856 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2858 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2859 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2860 struct device_attribute
*attr
,
2864 res
= hotkey_get_wlsw();
2868 /* Opportunistic update */
2869 tpacpi_rfk_update_hwblock_state((res
== TPACPI_RFK_RADIO_OFF
));
2871 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2872 (res
== TPACPI_RFK_RADIO_OFF
) ? 0 : 1);
2875 static struct device_attribute dev_attr_hotkey_radio_sw
=
2876 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2878 static void hotkey_radio_sw_notify_change(void)
2880 if (tp_features
.hotkey_wlsw
)
2881 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2885 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2886 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2887 struct device_attribute
*attr
,
2891 res
= hotkey_get_tablet_mode(&s
);
2895 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2898 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2899 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2901 static void hotkey_tablet_mode_notify_change(void)
2903 if (tp_features
.hotkey_tablet
)
2904 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2905 "hotkey_tablet_mode");
2908 /* sysfs hotkey report_mode -------------------------------------------- */
2909 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2910 struct device_attribute
*attr
,
2913 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2914 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2917 static struct device_attribute dev_attr_hotkey_report_mode
=
2918 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2920 /* sysfs wakeup reason (pollable) -------------------------------------- */
2921 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2922 struct device_attribute
*attr
,
2925 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2928 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2929 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2931 static void hotkey_wakeup_reason_notify_change(void)
2933 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2937 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2938 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2939 struct device_attribute
*attr
,
2942 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2945 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2946 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2947 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2949 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2951 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2952 "wakeup_hotunplug_complete");
2955 /* --------------------------------------------------------------------- */
2957 static struct attribute
*hotkey_attributes
[] __initdata
= {
2958 &dev_attr_hotkey_enable
.attr
,
2959 &dev_attr_hotkey_bios_enabled
.attr
,
2960 &dev_attr_hotkey_bios_mask
.attr
,
2961 &dev_attr_hotkey_report_mode
.attr
,
2962 &dev_attr_hotkey_wakeup_reason
.attr
,
2963 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2964 &dev_attr_hotkey_mask
.attr
,
2965 &dev_attr_hotkey_all_mask
.attr
,
2966 &dev_attr_hotkey_recommended_mask
.attr
,
2967 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2968 &dev_attr_hotkey_source_mask
.attr
,
2969 &dev_attr_hotkey_poll_freq
.attr
,
2974 * Sync both the hw and sw blocking state of all switches
2976 static void tpacpi_send_radiosw_update(void)
2981 * We must sync all rfkill controllers *before* issuing any
2982 * rfkill input events, or we will race the rfkill core input
2985 * tpacpi_inputdev_send_mutex works as a syncronization point
2988 * We optimize to avoid numerous calls to hotkey_get_wlsw.
2991 wlsw
= hotkey_get_wlsw();
2993 /* Sync hw blocking state first if it is hw-blocked */
2994 if (wlsw
== TPACPI_RFK_RADIO_OFF
)
2995 tpacpi_rfk_update_hwblock_state(true);
2997 /* Sync sw blocking state */
2998 tpacpi_rfk_update_swstate_all();
3000 /* Sync hw blocking state last if it is hw-unblocked */
3001 if (wlsw
== TPACPI_RFK_RADIO_ON
)
3002 tpacpi_rfk_update_hwblock_state(false);
3004 /* Issue rfkill input event for WLSW switch */
3006 mutex_lock(&tpacpi_inputdev_send_mutex
);
3008 input_report_switch(tpacpi_inputdev
,
3009 SW_RFKILL_ALL
, (wlsw
> 0));
3010 input_sync(tpacpi_inputdev
);
3012 mutex_unlock(&tpacpi_inputdev_send_mutex
);
3016 * this can be unconditional, as we will poll state again
3017 * if userspace uses the notify to read data
3019 hotkey_radio_sw_notify_change();
3022 static void hotkey_exit(void)
3024 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3025 mutex_lock(&hotkey_mutex
);
3026 hotkey_poll_stop_sync();
3027 mutex_unlock(&hotkey_mutex
);
3030 if (hotkey_dev_attributes
)
3031 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3033 kfree(hotkey_keycode_map
);
3035 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
3036 "restoring original HKEY status and mask\n");
3037 /* yes, there is a bitwise or below, we want the
3038 * functions to be called even if one of them fail */
3039 if (((tp_features
.hotkey_mask
&&
3040 hotkey_mask_set(hotkey_orig_mask
)) |
3041 hotkey_status_set(false)) != 0)
3043 "failed to restore hot key mask "
3044 "to BIOS defaults\n");
3047 static void __init
hotkey_unmap(const unsigned int scancode
)
3049 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
3050 clear_bit(hotkey_keycode_map
[scancode
],
3051 tpacpi_inputdev
->keybit
);
3052 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
3058 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
3061 #define TPACPI_HK_Q_INIMASK 0x0001
3063 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
3064 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
3065 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
3066 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
3067 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
3068 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
3069 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
3070 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
3071 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
3072 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
3073 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
3074 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
3075 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
3076 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
3077 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
3078 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
3079 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
3080 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
3081 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
3082 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
3085 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
3087 /* Requirements for changing the default keymaps:
3089 * 1. Many of the keys are mapped to KEY_RESERVED for very
3090 * good reasons. Do not change them unless you have deep
3091 * knowledge on the IBM and Lenovo ThinkPad firmware for
3092 * the various ThinkPad models. The driver behaves
3093 * differently for KEY_RESERVED: such keys have their
3094 * hot key mask *unset* in mask_recommended, and also
3095 * in the initial hot key mask programmed into the
3096 * firmware at driver load time, which means the firm-
3097 * ware may react very differently if you change them to
3100 * 2. You must be subscribed to the linux-thinkpad and
3101 * ibm-acpi-devel mailing lists, and you should read the
3102 * list archives since 2007 if you want to change the
3103 * keymaps. This requirement exists so that you will
3104 * know the past history of problems with the thinkpad-
3105 * acpi driver keymaps, and also that you will be
3106 * listening to any bug reports;
3108 * 3. Do not send thinkpad-acpi specific patches directly to
3109 * for merging, *ever*. Send them to the linux-acpi
3110 * mailinglist for comments. Merging is to be done only
3111 * through acpi-test and the ACPI maintainer.
3113 * If the above is too much to ask, don't change the keymap.
3114 * Ask the thinkpad-acpi maintainer to do it, instead.
3116 static u16 ibm_keycode_map
[] __initdata
= {
3117 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3118 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
3119 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3120 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3122 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3123 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3124 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3125 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3127 /* brightness: firmware always reacts to them */
3128 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
3129 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
3131 /* Thinklight: firmware always react to it */
3132 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3134 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3135 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3137 /* Volume: firmware always react to it and reprograms
3138 * the built-in *extra* mixer. Never map it to control
3139 * another mixer by default. */
3140 KEY_RESERVED
, /* 0x14: VOLUME UP */
3141 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3142 KEY_RESERVED
, /* 0x16: MUTE */
3144 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3146 /* (assignments unknown, please report if found) */
3147 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3148 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3150 static u16 lenovo_keycode_map
[] __initdata
= {
3151 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3152 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
3153 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3154 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3156 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3157 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3158 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3159 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3161 /* These should be enabled --only-- when ACPI video
3162 * is disabled (i.e. in "vendor" mode), and are handled
3163 * in a special way by the init code */
3164 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
3165 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
3167 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3169 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3170 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3172 /* Volume: z60/z61, T60 (BIOS version?): firmware always
3173 * react to it and reprograms the built-in *extra* mixer.
3174 * Never map it to control another mixer by default.
3176 * T60?, T61, R60?, R61: firmware and EC tries to send
3177 * these over the regular keyboard, so these are no-ops,
3178 * but there are still weird bugs re. MUTE, so do not
3179 * change unless you get test reports from all Lenovo
3180 * models. May cause the BIOS to interfere with the
3183 KEY_RESERVED
, /* 0x14: VOLUME UP */
3184 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3185 KEY_RESERVED
, /* 0x16: MUTE */
3187 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3189 /* (assignments unknown, please report if found) */
3190 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3191 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3194 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
3195 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
3196 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
3201 bool radiosw_state
= false;
3202 bool tabletsw_state
= false;
3204 unsigned long quirks
;
3206 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3207 "initializing hotkey subdriver\n");
3209 BUG_ON(!tpacpi_inputdev
);
3210 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
3211 tpacpi_inputdev
->close
!= NULL
);
3213 TPACPI_ACPIHANDLE_INIT(hkey
);
3214 mutex_init(&hotkey_mutex
);
3216 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3217 mutex_init(&hotkey_thread_mutex
);
3218 mutex_init(&hotkey_thread_data_mutex
);
3221 /* hotkey not supported on 570 */
3222 tp_features
.hotkey
= hkey_handle
!= NULL
;
3224 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3226 str_supported(tp_features
.hotkey
));
3228 if (!tp_features
.hotkey
)
3231 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
3232 ARRAY_SIZE(tpacpi_hotkey_qtable
));
3234 tpacpi_disable_brightness_delay();
3236 /* MUST have enough space for all attributes to be added to
3237 * hotkey_dev_attributes */
3238 hotkey_dev_attributes
= create_attr_set(
3239 ARRAY_SIZE(hotkey_attributes
) + 2,
3241 if (!hotkey_dev_attributes
)
3243 res
= add_many_to_attr_set(hotkey_dev_attributes
,
3245 ARRAY_SIZE(hotkey_attributes
));
3249 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
3250 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
3251 for HKEY interface version 0x100 */
3252 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
3253 if ((hkeyv
>> 8) != 1) {
3254 printk(TPACPI_ERR
"unknown version of the "
3255 "HKEY interface: 0x%x\n", hkeyv
);
3256 printk(TPACPI_ERR
"please report this to %s\n",
3260 * MHKV 0x100 in A31, R40, R40e,
3261 * T4x, X31, and later
3263 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3264 "firmware HKEY interface version: 0x%x\n",
3267 /* Paranoia check AND init hotkey_all_mask */
3268 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
3271 "missing MHKA handler, "
3272 "please report this to %s\n",
3274 /* Fallback: pre-init for FN+F3,F4,F12 */
3275 hotkey_all_mask
= 0x080cU
;
3277 tp_features
.hotkey_mask
= 1;
3282 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3283 "hotkey masks are %s\n",
3284 str_supported(tp_features
.hotkey_mask
));
3286 /* Init hotkey_all_mask if not initialized yet */
3287 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
3288 (quirks
& TPACPI_HK_Q_INIMASK
))
3289 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
3291 /* Init hotkey_acpi_mask and hotkey_orig_mask */
3292 if (tp_features
.hotkey_mask
) {
3293 /* hotkey_source_mask *must* be zero for
3294 * the first hotkey_mask_get to return hotkey_orig_mask */
3295 res
= hotkey_mask_get();
3299 hotkey_orig_mask
= hotkey_acpi_mask
;
3301 hotkey_orig_mask
= hotkey_all_mask
;
3302 hotkey_acpi_mask
= hotkey_all_mask
;
3305 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3307 tp_features
.hotkey_wlsw
= 1;
3308 radiosw_state
= !!tpacpi_wlsw_emulstate
;
3310 "radio switch emulation enabled\n");
3313 /* Not all thinkpads have a hardware radio switch */
3314 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3315 tp_features
.hotkey_wlsw
= 1;
3316 radiosw_state
= !!status
;
3318 "radio switch found; radios are %s\n",
3319 enabled(status
, 0));
3321 if (tp_features
.hotkey_wlsw
)
3322 res
= add_to_attr_set(hotkey_dev_attributes
,
3323 &dev_attr_hotkey_radio_sw
.attr
);
3325 /* For X41t, X60t, X61t Tablets... */
3326 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3327 tp_features
.hotkey_tablet
= 1;
3328 tabletsw_state
= !!(status
& TP_HOTKEY_TABLET_MASK
);
3330 "possible tablet mode switch found; "
3331 "ThinkPad in %s mode\n",
3332 (tabletsw_state
) ? "tablet" : "laptop");
3333 res
= add_to_attr_set(hotkey_dev_attributes
,
3334 &dev_attr_hotkey_tablet_mode
.attr
);
3338 res
= register_attr_set_with_sysfs(
3339 hotkey_dev_attributes
,
3340 &tpacpi_pdev
->dev
.kobj
);
3344 /* Set up key map */
3346 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3348 if (!hotkey_keycode_map
) {
3350 "failed to allocate memory for key map\n");
3355 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
3356 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3357 "using Lenovo default hot key map\n");
3358 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
3359 TPACPI_HOTKEY_MAP_SIZE
);
3361 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3362 "using IBM default hot key map\n");
3363 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
3364 TPACPI_HOTKEY_MAP_SIZE
);
3367 input_set_capability(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
);
3368 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3369 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3370 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3371 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3372 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3373 input_set_capability(tpacpi_inputdev
, EV_KEY
,
3374 hotkey_keycode_map
[i
]);
3376 if (i
< sizeof(hotkey_reserved_mask
)*8)
3377 hotkey_reserved_mask
|= 1 << i
;
3381 if (tp_features
.hotkey_wlsw
) {
3382 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_RFKILL_ALL
);
3383 input_report_switch(tpacpi_inputdev
,
3384 SW_RFKILL_ALL
, radiosw_state
);
3386 if (tp_features
.hotkey_tablet
) {
3387 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_TABLET_MODE
);
3388 input_report_switch(tpacpi_inputdev
,
3389 SW_TABLET_MODE
, tabletsw_state
);
3392 /* Do not issue duplicate brightness change events to
3394 if (!tp_features
.bright_acpimode
)
3395 /* update bright_acpimode... */
3396 tpacpi_check_std_acpi_brightness_support();
3398 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
3400 "This ThinkPad has standard ACPI backlight "
3401 "brightness control, supported by the ACPI "
3403 printk(TPACPI_NOTICE
3404 "Disabling thinkpad-acpi brightness events "
3407 /* Disable brightness up/down on Lenovo thinkpads when
3408 * ACPI is handling them, otherwise it is plain impossible
3409 * for userspace to do something even remotely sane */
3410 hotkey_reserved_mask
|=
3411 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3412 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3413 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3414 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3417 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3418 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3420 & ~hotkey_reserved_mask
;
3422 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3423 "hotkey source mask 0x%08x, polling freq %u\n",
3424 hotkey_source_mask
, hotkey_poll_freq
);
3427 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3428 "enabling firmware HKEY event interface...\n");
3429 res
= hotkey_status_set(true);
3434 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3435 | hotkey_driver_mask
)
3436 & ~hotkey_source_mask
);
3437 if (res
< 0 && res
!= -ENXIO
) {
3441 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3442 & ~hotkey_reserved_mask
;
3443 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3444 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3445 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3447 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3448 "legacy ibm/hotkey event reporting over procfs %s\n",
3449 (hotkey_report_mode
< 2) ?
3450 "enabled" : "disabled");
3452 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3453 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3455 hotkey_poll_setup_safe(true);
3460 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3461 hotkey_dev_attributes
= NULL
;
3463 return (res
< 0)? res
: 1;
3466 static bool hotkey_notify_hotkey(const u32 hkey
,
3468 bool *ignore_acpi_ev
)
3470 /* 0x1000-0x1FFF: key presses */
3471 unsigned int scancode
= hkey
& 0xfff;
3472 *send_acpi_ev
= true;
3473 *ignore_acpi_ev
= false;
3475 if (scancode
> 0 && scancode
< 0x21) {
3477 if (!(hotkey_source_mask
& (1 << scancode
))) {
3478 tpacpi_input_send_key_masked(scancode
);
3479 *send_acpi_ev
= false;
3481 *ignore_acpi_ev
= true;
3488 static bool hotkey_notify_wakeup(const u32 hkey
,
3490 bool *ignore_acpi_ev
)
3492 /* 0x2000-0x2FFF: Wakeup reason */
3493 *send_acpi_ev
= true;
3494 *ignore_acpi_ev
= false;
3497 case TP_HKEY_EV_WKUP_S3_UNDOCK
: /* suspend, undock */
3498 case TP_HKEY_EV_WKUP_S4_UNDOCK
: /* hibernation, undock */
3499 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3500 *ignore_acpi_ev
= true;
3503 case TP_HKEY_EV_WKUP_S3_BAYEJ
: /* suspend, bay eject */
3504 case TP_HKEY_EV_WKUP_S4_BAYEJ
: /* hibernation, bay eject */
3505 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3506 *ignore_acpi_ev
= true;
3509 case TP_HKEY_EV_WKUP_S3_BATLOW
: /* Battery on critical low level/S3 */
3510 case TP_HKEY_EV_WKUP_S4_BATLOW
: /* Battery on critical low level/S4 */
3512 "EMERGENCY WAKEUP: battery almost empty\n");
3513 /* how to auto-heal: */
3514 /* 2313: woke up from S3, go to S4/S5 */
3515 /* 2413: woke up from S4, go to S5 */
3522 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3524 "woke up due to a hot-unplug "
3526 hotkey_wakeup_reason_notify_change();
3531 static bool hotkey_notify_usrevent(const u32 hkey
,
3533 bool *ignore_acpi_ev
)
3535 /* 0x5000-0x5FFF: human interface helpers */
3536 *send_acpi_ev
= true;
3537 *ignore_acpi_ev
= false;
3540 case TP_HKEY_EV_PEN_INSERTED
: /* X61t: tablet pen inserted into bay */
3541 case TP_HKEY_EV_PEN_REMOVED
: /* X61t: tablet pen removed from bay */
3544 case TP_HKEY_EV_TABLET_TABLET
: /* X41t-X61t: tablet mode */
3545 case TP_HKEY_EV_TABLET_NOTEBOOK
: /* X41t-X61t: normal mode */
3546 tpacpi_input_send_tabletsw();
3547 hotkey_tablet_mode_notify_change();
3548 *send_acpi_ev
= false;
3551 case TP_HKEY_EV_LID_CLOSE
: /* Lid closed */
3552 case TP_HKEY_EV_LID_OPEN
: /* Lid opened */
3553 case TP_HKEY_EV_BRGHT_CHANGED
: /* brightness changed */
3554 /* do not propagate these events */
3555 *ignore_acpi_ev
= true;
3563 static void thermal_dump_all_sensors(void);
3565 static bool hotkey_notify_thermal(const u32 hkey
,
3567 bool *ignore_acpi_ev
)
3571 /* 0x6000-0x6FFF: thermal alarms */
3572 *send_acpi_ev
= true;
3573 *ignore_acpi_ev
= false;
3576 case TP_HKEY_EV_THM_TABLE_CHANGED
:
3578 "EC reports that Thermal Table has changed\n");
3579 /* recommended action: do nothing, we don't have
3580 * Lenovo ATM information */
3582 case TP_HKEY_EV_ALARM_BAT_HOT
:
3584 "THERMAL ALARM: battery is too hot!\n");
3585 /* recommended action: warn user through gui */
3587 case TP_HKEY_EV_ALARM_BAT_XHOT
:
3589 "THERMAL EMERGENCY: battery is extremely hot!\n");
3590 /* recommended action: immediate sleep/hibernate */
3592 case TP_HKEY_EV_ALARM_SENSOR_HOT
:
3595 "a sensor reports something is too hot!\n");
3596 /* recommended action: warn user through gui, that */
3597 /* some internal component is too hot */
3599 case TP_HKEY_EV_ALARM_SENSOR_XHOT
:
3601 "THERMAL EMERGENCY: "
3602 "a sensor reports something is extremely hot!\n");
3603 /* recommended action: immediate sleep/hibernate */
3607 "THERMAL ALERT: unknown thermal alarm received\n");
3611 thermal_dump_all_sensors();
3616 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3620 bool ignore_acpi_ev
;
3623 if (event
!= 0x80) {
3625 "unknown HKEY notification event %d\n", event
);
3626 /* forward it to userspace, maybe it knows how to handle it */
3627 acpi_bus_generate_netlink_event(
3628 ibm
->acpi
->device
->pnp
.device_class
,
3629 dev_name(&ibm
->acpi
->device
->dev
),
3635 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3636 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3645 send_acpi_ev
= true;
3646 ignore_acpi_ev
= false;
3648 switch (hkey
>> 12) {
3650 /* 0x1000-0x1FFF: key presses */
3651 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3655 /* 0x2000-0x2FFF: Wakeup reason */
3656 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3660 /* 0x3000-0x3FFF: bay-related wakeups */
3661 if (hkey
== TP_HKEY_EV_BAYEJ_ACK
) {
3662 hotkey_autosleep_ack
= 1;
3665 hotkey_wakeup_hotunplug_complete_notify_change();
3672 /* 0x4000-0x4FFF: dock-related wakeups */
3673 if (hkey
== TP_HKEY_EV_UNDOCK_ACK
) {
3674 hotkey_autosleep_ack
= 1;
3677 hotkey_wakeup_hotunplug_complete_notify_change();
3684 /* 0x5000-0x5FFF: human interface helpers */
3685 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3689 /* 0x6000-0x6FFF: thermal alarms */
3690 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3694 /* 0x7000-0x7FFF: misc */
3695 if (tp_features
.hotkey_wlsw
&&
3696 hkey
== TP_HKEY_EV_RFKILL_CHANGED
) {
3697 tpacpi_send_radiosw_update();
3702 /* fallthrough to default */
3707 printk(TPACPI_NOTICE
3708 "unhandled HKEY event 0x%04x\n", hkey
);
3709 printk(TPACPI_NOTICE
3710 "please report the conditions when this "
3711 "event happened to %s\n", TPACPI_MAIL
);
3715 if (!ignore_acpi_ev
&&
3716 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3717 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3721 /* netlink events */
3722 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3723 acpi_bus_generate_netlink_event(
3724 ibm
->acpi
->device
->pnp
.device_class
,
3725 dev_name(&ibm
->acpi
->device
->dev
),
3731 static void hotkey_suspend(pm_message_t state
)
3733 /* Do these on suspend, we get the events on early resume! */
3734 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3735 hotkey_autosleep_ack
= 0;
3738 static void hotkey_resume(void)
3740 tpacpi_disable_brightness_delay();
3742 if (hotkey_status_set(true) < 0 ||
3743 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3745 "error while attempting to reset the event "
3746 "firmware interface\n");
3748 tpacpi_send_radiosw_update();
3749 hotkey_tablet_mode_notify_change();
3750 hotkey_wakeup_reason_notify_change();
3751 hotkey_wakeup_hotunplug_complete_notify_change();
3752 hotkey_poll_setup_safe(false);
3755 /* procfs -------------------------------------------------------------- */
3756 static int hotkey_read(struct seq_file
*m
)
3760 if (!tp_features
.hotkey
) {
3761 seq_printf(m
, "status:\t\tnot supported\n");
3765 if (mutex_lock_killable(&hotkey_mutex
))
3766 return -ERESTARTSYS
;
3767 res
= hotkey_status_get(&status
);
3769 res
= hotkey_mask_get();
3770 mutex_unlock(&hotkey_mutex
);
3774 seq_printf(m
, "status:\t\t%s\n", enabled(status
, 0));
3775 if (hotkey_all_mask
) {
3776 seq_printf(m
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3777 seq_printf(m
, "commands:\tenable, disable, reset, <mask>\n");
3779 seq_printf(m
, "mask:\t\tnot supported\n");
3780 seq_printf(m
, "commands:\tenable, disable, reset\n");
3786 static void hotkey_enabledisable_warn(bool enable
)
3788 tpacpi_log_usertask("procfs hotkey enable/disable");
3789 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3791 "hotkey enable/disable functionality has been "
3792 "removed from the driver. Hotkeys are always "
3795 "Please remove the hotkey=enable module "
3796 "parameter, it is deprecated. Hotkeys are always "
3800 static int hotkey_write(char *buf
)
3806 if (!tp_features
.hotkey
)
3809 if (mutex_lock_killable(&hotkey_mutex
))
3810 return -ERESTARTSYS
;
3812 mask
= hotkey_user_mask
;
3815 while ((cmd
= next_cmd(&buf
))) {
3816 if (strlencmp(cmd
, "enable") == 0) {
3817 hotkey_enabledisable_warn(1);
3818 } else if (strlencmp(cmd
, "disable") == 0) {
3819 hotkey_enabledisable_warn(0);
3821 } else if (strlencmp(cmd
, "reset") == 0) {
3822 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3823 & ~hotkey_reserved_mask
;
3824 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3826 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3835 tpacpi_disclose_usertask("procfs hotkey",
3836 "set mask to 0x%08x\n", mask
);
3837 res
= hotkey_user_mask_set(mask
);
3841 mutex_unlock(&hotkey_mutex
);
3845 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3846 {TPACPI_ACPI_HKEY_HID
, 0},
3850 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3851 .hid
= ibm_htk_device_ids
,
3852 .notify
= hotkey_notify
,
3853 .handle
= &hkey_handle
,
3854 .type
= ACPI_DEVICE_NOTIFY
,
3857 static struct ibm_struct hotkey_driver_data
= {
3859 .read
= hotkey_read
,
3860 .write
= hotkey_write
,
3861 .exit
= hotkey_exit
,
3862 .resume
= hotkey_resume
,
3863 .suspend
= hotkey_suspend
,
3864 .acpi
= &ibm_hotkey_acpidriver
,
3867 /*************************************************************************
3868 * Bluetooth subdriver
3872 /* ACPI GBDC/SBDC bits */
3873 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3874 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3875 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3880 /* ACPI \BLTH commands */
3881 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3882 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3883 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3884 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3885 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3888 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3890 static int bluetooth_get_status(void)
3894 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3895 if (dbg_bluetoothemul
)
3896 return (tpacpi_bluetooth_emulstate
) ?
3897 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3900 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3903 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3904 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3907 static int bluetooth_set_status(enum tpacpi_rfkill_state state
)
3911 vdbg_printk(TPACPI_DBG_RFKILL
,
3912 "will attempt to %s bluetooth\n",
3913 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
3915 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3916 if (dbg_bluetoothemul
) {
3917 tpacpi_bluetooth_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
3922 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3923 status
= TP_ACPI_BLUETOOTH_RESUMECTRL
;
3924 if (state
== TPACPI_RFK_RADIO_ON
)
3925 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
3927 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3933 /* sysfs bluetooth enable ---------------------------------------------- */
3934 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3935 struct device_attribute
*attr
,
3938 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID
,
3942 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3943 struct device_attribute
*attr
,
3944 const char *buf
, size_t count
)
3946 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID
,
3950 static struct device_attribute dev_attr_bluetooth_enable
=
3951 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3952 bluetooth_enable_show
, bluetooth_enable_store
);
3954 /* --------------------------------------------------------------------- */
3956 static struct attribute
*bluetooth_attributes
[] = {
3957 &dev_attr_bluetooth_enable
.attr
,
3961 static const struct attribute_group bluetooth_attr_group
= {
3962 .attrs
= bluetooth_attributes
,
3965 static const struct tpacpi_rfk_ops bluetooth_tprfk_ops
= {
3966 .get_status
= bluetooth_get_status
,
3967 .set_status
= bluetooth_set_status
,
3970 static void bluetooth_shutdown(void)
3972 /* Order firmware to save current state to NVRAM */
3973 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3974 TP_ACPI_BLTH_SAVE_STATE
))
3975 printk(TPACPI_NOTICE
3976 "failed to save bluetooth state to NVRAM\n");
3978 vdbg_printk(TPACPI_DBG_RFKILL
,
3979 "bluestooth state saved to NVRAM\n");
3982 static void bluetooth_exit(void)
3984 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3985 &bluetooth_attr_group
);
3987 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
3989 bluetooth_shutdown();
3992 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3997 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3998 "initializing bluetooth subdriver\n");
4000 TPACPI_ACPIHANDLE_INIT(hkey
);
4002 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4003 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
4004 tp_features
.bluetooth
= hkey_handle
&&
4005 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
4007 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4008 "bluetooth is %s, status 0x%02x\n",
4009 str_supported(tp_features
.bluetooth
),
4012 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4013 if (dbg_bluetoothemul
) {
4014 tp_features
.bluetooth
= 1;
4016 "bluetooth switch emulation enabled\n");
4019 if (tp_features
.bluetooth
&&
4020 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
4021 /* no bluetooth hardware present in system */
4022 tp_features
.bluetooth
= 0;
4023 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4024 "bluetooth hardware not installed\n");
4027 if (!tp_features
.bluetooth
)
4030 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
4031 &bluetooth_tprfk_ops
,
4032 RFKILL_TYPE_BLUETOOTH
,
4033 TPACPI_RFK_BLUETOOTH_SW_NAME
,
4038 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4039 &bluetooth_attr_group
);
4041 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
4048 /* procfs -------------------------------------------------------------- */
4049 static int bluetooth_read(struct seq_file
*m
)
4051 return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID
, m
);
4054 static int bluetooth_write(char *buf
)
4056 return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID
, buf
);
4059 static struct ibm_struct bluetooth_driver_data
= {
4060 .name
= "bluetooth",
4061 .read
= bluetooth_read
,
4062 .write
= bluetooth_write
,
4063 .exit
= bluetooth_exit
,
4064 .shutdown
= bluetooth_shutdown
,
4067 /*************************************************************************
4072 /* ACPI GWAN/SWAN bits */
4073 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
4074 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
4075 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
4079 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
4081 static int wan_get_status(void)
4085 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4087 return (tpacpi_wwan_emulstate
) ?
4088 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4091 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
4094 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
4095 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4098 static int wan_set_status(enum tpacpi_rfkill_state state
)
4102 vdbg_printk(TPACPI_DBG_RFKILL
,
4103 "will attempt to %s wwan\n",
4104 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4106 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4108 tpacpi_wwan_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4113 /* We make sure to set TP_ACPI_WANCARD_RESUMECTRL */
4114 status
= TP_ACPI_WANCARD_RESUMECTRL
;
4115 if (state
== TPACPI_RFK_RADIO_ON
)
4116 status
|= TP_ACPI_WANCARD_RADIOSSW
;
4118 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
4124 /* sysfs wan enable ---------------------------------------------------- */
4125 static ssize_t
wan_enable_show(struct device
*dev
,
4126 struct device_attribute
*attr
,
4129 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID
,
4133 static ssize_t
wan_enable_store(struct device
*dev
,
4134 struct device_attribute
*attr
,
4135 const char *buf
, size_t count
)
4137 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID
,
4141 static struct device_attribute dev_attr_wan_enable
=
4142 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4143 wan_enable_show
, wan_enable_store
);
4145 /* --------------------------------------------------------------------- */
4147 static struct attribute
*wan_attributes
[] = {
4148 &dev_attr_wan_enable
.attr
,
4152 static const struct attribute_group wan_attr_group
= {
4153 .attrs
= wan_attributes
,
4156 static const struct tpacpi_rfk_ops wan_tprfk_ops
= {
4157 .get_status
= wan_get_status
,
4158 .set_status
= wan_set_status
,
4161 static void wan_shutdown(void)
4163 /* Order firmware to save current state to NVRAM */
4164 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4165 TP_ACPI_WGSV_SAVE_STATE
))
4166 printk(TPACPI_NOTICE
4167 "failed to save WWAN state to NVRAM\n");
4169 vdbg_printk(TPACPI_DBG_RFKILL
,
4170 "WWAN state saved to NVRAM\n");
4173 static void wan_exit(void)
4175 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4178 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4183 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4188 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4189 "initializing wan subdriver\n");
4191 TPACPI_ACPIHANDLE_INIT(hkey
);
4193 tp_features
.wan
= hkey_handle
&&
4194 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4196 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4197 "wan is %s, status 0x%02x\n",
4198 str_supported(tp_features
.wan
),
4201 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4203 tp_features
.wan
= 1;
4205 "wwan switch emulation enabled\n");
4208 if (tp_features
.wan
&&
4209 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4210 /* no wan hardware present in system */
4211 tp_features
.wan
= 0;
4212 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4213 "wan hardware not installed\n");
4216 if (!tp_features
.wan
)
4219 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4222 TPACPI_RFK_WWAN_SW_NAME
,
4227 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4231 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4238 /* procfs -------------------------------------------------------------- */
4239 static int wan_read(struct seq_file
*m
)
4241 return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID
, m
);
4244 static int wan_write(char *buf
)
4246 return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID
, buf
);
4249 static struct ibm_struct wan_driver_data
= {
4254 .shutdown
= wan_shutdown
,
4257 /*************************************************************************
4262 /* ACPI GUWB/SUWB bits */
4263 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4264 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4267 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4269 static int uwb_get_status(void)
4273 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4275 return (tpacpi_uwb_emulstate
) ?
4276 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4279 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4282 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4283 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4286 static int uwb_set_status(enum tpacpi_rfkill_state state
)
4290 vdbg_printk(TPACPI_DBG_RFKILL
,
4291 "will attempt to %s UWB\n",
4292 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4294 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4296 tpacpi_uwb_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4301 if (state
== TPACPI_RFK_RADIO_ON
)
4302 status
= TP_ACPI_UWB_RADIOSSW
;
4306 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4312 /* --------------------------------------------------------------------- */
4314 static const struct tpacpi_rfk_ops uwb_tprfk_ops
= {
4315 .get_status
= uwb_get_status
,
4316 .set_status
= uwb_set_status
,
4319 static void uwb_exit(void)
4321 tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID
);
4324 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4329 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4330 "initializing uwb subdriver\n");
4332 TPACPI_ACPIHANDLE_INIT(hkey
);
4334 tp_features
.uwb
= hkey_handle
&&
4335 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4337 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4338 "uwb is %s, status 0x%02x\n",
4339 str_supported(tp_features
.uwb
),
4342 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4344 tp_features
.uwb
= 1;
4346 "uwb switch emulation enabled\n");
4349 if (tp_features
.uwb
&&
4350 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4351 /* no uwb hardware present in system */
4352 tp_features
.uwb
= 0;
4353 dbg_printk(TPACPI_DBG_INIT
,
4354 "uwb hardware not installed\n");
4357 if (!tp_features
.uwb
)
4360 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4363 TPACPI_RFK_UWB_SW_NAME
,
4368 static struct ibm_struct uwb_driver_data
= {
4371 .flags
.experimental
= 1,
4374 /*************************************************************************
4378 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4380 enum video_access_mode
{
4381 TPACPI_VIDEO_NONE
= 0,
4382 TPACPI_VIDEO_570
, /* 570 */
4383 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4384 TPACPI_VIDEO_NEW
, /* all others */
4387 enum { /* video status flags, based on VIDEO_570 */
4388 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4389 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4390 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4393 enum { /* TPACPI_VIDEO_570 constants */
4394 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4395 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4396 * video_status_flags */
4397 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4398 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4401 static enum video_access_mode video_supported
;
4402 static int video_orig_autosw
;
4404 static int video_autosw_get(void);
4405 static int video_autosw_set(int enable
);
4407 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4409 static int __init
video_init(struct ibm_init_struct
*iibm
)
4413 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4415 TPACPI_ACPIHANDLE_INIT(vid
);
4416 TPACPI_ACPIHANDLE_INIT(vid2
);
4418 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4419 /* G41, assume IVGA doesn't change */
4420 vid_handle
= vid2_handle
;
4423 /* video switching not supported on R30, R31 */
4424 video_supported
= TPACPI_VIDEO_NONE
;
4425 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4427 video_supported
= TPACPI_VIDEO_570
;
4428 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4429 /* 600e/x, 770e, 770x */
4430 video_supported
= TPACPI_VIDEO_770
;
4433 video_supported
= TPACPI_VIDEO_NEW
;
4435 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4436 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4439 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4442 static void video_exit(void)
4444 dbg_printk(TPACPI_DBG_EXIT
,
4445 "restoring original video autoswitch mode\n");
4446 if (video_autosw_set(video_orig_autosw
))
4447 printk(TPACPI_ERR
"error while trying to restore original "
4448 "video autoswitch mode\n");
4451 static int video_outputsw_get(void)
4456 switch (video_supported
) {
4457 case TPACPI_VIDEO_570
:
4458 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4459 TP_ACPI_VIDEO_570_PHSCMD
))
4461 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4463 case TPACPI_VIDEO_770
:
4464 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4467 status
|= TP_ACPI_VIDEO_S_LCD
;
4468 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4471 status
|= TP_ACPI_VIDEO_S_CRT
;
4473 case TPACPI_VIDEO_NEW
:
4474 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4475 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4478 status
|= TP_ACPI_VIDEO_S_CRT
;
4480 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4481 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4484 status
|= TP_ACPI_VIDEO_S_LCD
;
4485 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4488 status
|= TP_ACPI_VIDEO_S_DVI
;
4497 static int video_outputsw_set(int status
)
4502 switch (video_supported
) {
4503 case TPACPI_VIDEO_570
:
4504 res
= acpi_evalf(NULL
, NULL
,
4505 "\\_SB.PHS2", "vdd",
4506 TP_ACPI_VIDEO_570_PHS2CMD
,
4507 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4509 case TPACPI_VIDEO_770
:
4510 autosw
= video_autosw_get();
4514 res
= video_autosw_set(1);
4517 res
= acpi_evalf(vid_handle
, NULL
,
4518 "ASWT", "vdd", status
* 0x100, 0);
4519 if (!autosw
&& video_autosw_set(autosw
)) {
4521 "video auto-switch left enabled due to error\n");
4525 case TPACPI_VIDEO_NEW
:
4526 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4527 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4533 return (res
)? 0 : -EIO
;
4536 static int video_autosw_get(void)
4540 switch (video_supported
) {
4541 case TPACPI_VIDEO_570
:
4542 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4545 case TPACPI_VIDEO_770
:
4546 case TPACPI_VIDEO_NEW
:
4547 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4557 static int video_autosw_set(int enable
)
4559 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4564 static int video_outputsw_cycle(void)
4566 int autosw
= video_autosw_get();
4572 switch (video_supported
) {
4573 case TPACPI_VIDEO_570
:
4574 res
= video_autosw_set(1);
4577 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4579 case TPACPI_VIDEO_770
:
4580 case TPACPI_VIDEO_NEW
:
4581 res
= video_autosw_set(1);
4584 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4589 if (!autosw
&& video_autosw_set(autosw
)) {
4591 "video auto-switch left enabled due to error\n");
4595 return (res
)? 0 : -EIO
;
4598 static int video_expand_toggle(void)
4600 switch (video_supported
) {
4601 case TPACPI_VIDEO_570
:
4602 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4604 case TPACPI_VIDEO_770
:
4605 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4607 case TPACPI_VIDEO_NEW
:
4608 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4616 static int video_read(struct seq_file
*m
)
4620 if (video_supported
== TPACPI_VIDEO_NONE
) {
4621 seq_printf(m
, "status:\t\tnot supported\n");
4625 status
= video_outputsw_get();
4629 autosw
= video_autosw_get();
4633 seq_printf(m
, "status:\t\tsupported\n");
4634 seq_printf(m
, "lcd:\t\t%s\n", enabled(status
, 0));
4635 seq_printf(m
, "crt:\t\t%s\n", enabled(status
, 1));
4636 if (video_supported
== TPACPI_VIDEO_NEW
)
4637 seq_printf(m
, "dvi:\t\t%s\n", enabled(status
, 3));
4638 seq_printf(m
, "auto:\t\t%s\n", enabled(autosw
, 0));
4639 seq_printf(m
, "commands:\tlcd_enable, lcd_disable\n");
4640 seq_printf(m
, "commands:\tcrt_enable, crt_disable\n");
4641 if (video_supported
== TPACPI_VIDEO_NEW
)
4642 seq_printf(m
, "commands:\tdvi_enable, dvi_disable\n");
4643 seq_printf(m
, "commands:\tauto_enable, auto_disable\n");
4644 seq_printf(m
, "commands:\tvideo_switch, expand_toggle\n");
4649 static int video_write(char *buf
)
4652 int enable
, disable
, status
;
4655 if (video_supported
== TPACPI_VIDEO_NONE
)
4661 while ((cmd
= next_cmd(&buf
))) {
4662 if (strlencmp(cmd
, "lcd_enable") == 0) {
4663 enable
|= TP_ACPI_VIDEO_S_LCD
;
4664 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4665 disable
|= TP_ACPI_VIDEO_S_LCD
;
4666 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4667 enable
|= TP_ACPI_VIDEO_S_CRT
;
4668 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4669 disable
|= TP_ACPI_VIDEO_S_CRT
;
4670 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4671 strlencmp(cmd
, "dvi_enable") == 0) {
4672 enable
|= TP_ACPI_VIDEO_S_DVI
;
4673 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4674 strlencmp(cmd
, "dvi_disable") == 0) {
4675 disable
|= TP_ACPI_VIDEO_S_DVI
;
4676 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4677 res
= video_autosw_set(1);
4680 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4681 res
= video_autosw_set(0);
4684 } else if (strlencmp(cmd
, "video_switch") == 0) {
4685 res
= video_outputsw_cycle();
4688 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4689 res
= video_expand_toggle();
4696 if (enable
|| disable
) {
4697 status
= video_outputsw_get();
4700 res
= video_outputsw_set((status
& ~disable
) | enable
);
4708 static struct ibm_struct video_driver_data
= {
4711 .write
= video_write
,
4715 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4717 /*************************************************************************
4718 * Light (thinklight) subdriver
4721 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4722 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4724 static int light_get_status(void)
4728 if (tp_features
.light_status
) {
4729 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4737 static int light_set_status(int status
)
4741 if (tp_features
.light
) {
4743 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4745 TP_CMOS_THINKLIGHT_ON
:
4746 TP_CMOS_THINKLIGHT_OFF
);
4748 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4751 return (rc
)? 0 : -EIO
;
4757 static void light_set_status_worker(struct work_struct
*work
)
4759 struct tpacpi_led_classdev
*data
=
4760 container_of(work
, struct tpacpi_led_classdev
, work
);
4762 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4763 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4766 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4767 enum led_brightness brightness
)
4769 struct tpacpi_led_classdev
*data
=
4770 container_of(led_cdev
,
4771 struct tpacpi_led_classdev
,
4773 data
->new_state
= (brightness
!= LED_OFF
) ?
4774 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4775 queue_work(tpacpi_wq
, &data
->work
);
4778 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4780 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4783 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4785 .name
= "tpacpi::thinklight",
4786 .brightness_set
= &light_sysfs_set
,
4787 .brightness_get
= &light_sysfs_get
,
4791 static int __init
light_init(struct ibm_init_struct
*iibm
)
4795 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4797 TPACPI_ACPIHANDLE_INIT(ledb
);
4798 TPACPI_ACPIHANDLE_INIT(lght
);
4799 TPACPI_ACPIHANDLE_INIT(cmos
);
4800 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4802 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4803 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4805 if (tp_features
.light
)
4806 /* light status not supported on
4807 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4808 tp_features
.light_status
=
4809 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4811 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4812 str_supported(tp_features
.light
),
4813 str_supported(tp_features
.light_status
));
4815 if (!tp_features
.light
)
4818 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4819 &tpacpi_led_thinklight
.led_classdev
);
4822 tp_features
.light
= 0;
4823 tp_features
.light_status
= 0;
4831 static void light_exit(void)
4833 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4834 if (work_pending(&tpacpi_led_thinklight
.work
))
4835 flush_workqueue(tpacpi_wq
);
4838 static int light_read(struct seq_file
*m
)
4842 if (!tp_features
.light
) {
4843 seq_printf(m
, "status:\t\tnot supported\n");
4844 } else if (!tp_features
.light_status
) {
4845 seq_printf(m
, "status:\t\tunknown\n");
4846 seq_printf(m
, "commands:\ton, off\n");
4848 status
= light_get_status();
4851 seq_printf(m
, "status:\t\t%s\n", onoff(status
, 0));
4852 seq_printf(m
, "commands:\ton, off\n");
4858 static int light_write(char *buf
)
4863 if (!tp_features
.light
)
4866 while ((cmd
= next_cmd(&buf
))) {
4867 if (strlencmp(cmd
, "on") == 0) {
4869 } else if (strlencmp(cmd
, "off") == 0) {
4875 return light_set_status(newstatus
);
4878 static struct ibm_struct light_driver_data
= {
4881 .write
= light_write
,
4885 /*************************************************************************
4889 /* sysfs cmos_command -------------------------------------------------- */
4890 static ssize_t
cmos_command_store(struct device
*dev
,
4891 struct device_attribute
*attr
,
4892 const char *buf
, size_t count
)
4894 unsigned long cmos_cmd
;
4897 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4900 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4901 return (res
)? res
: count
;
4904 static struct device_attribute dev_attr_cmos_command
=
4905 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4907 /* --------------------------------------------------------------------- */
4909 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4913 vdbg_printk(TPACPI_DBG_INIT
,
4914 "initializing cmos commands subdriver\n");
4916 TPACPI_ACPIHANDLE_INIT(cmos
);
4918 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4919 str_supported(cmos_handle
!= NULL
));
4921 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4925 return (cmos_handle
)? 0 : 1;
4928 static void cmos_exit(void)
4930 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4933 static int cmos_read(struct seq_file
*m
)
4935 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4936 R30, R31, T20-22, X20-21 */
4938 seq_printf(m
, "status:\t\tnot supported\n");
4940 seq_printf(m
, "status:\t\tsupported\n");
4941 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4947 static int cmos_write(char *buf
)
4952 while ((cmd
= next_cmd(&buf
))) {
4953 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4954 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4959 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4967 static struct ibm_struct cmos_driver_data
= {
4970 .write
= cmos_write
,
4974 /*************************************************************************
4978 enum led_access_mode
{
4979 TPACPI_LED_NONE
= 0,
4980 TPACPI_LED_570
, /* 570 */
4981 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4982 TPACPI_LED_NEW
, /* all others */
4985 enum { /* For TPACPI_LED_OLD */
4986 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4987 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4988 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4991 static enum led_access_mode led_supported
;
4993 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4994 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4995 /* T20-22, X20-21 */
4996 "LED", /* all others */
4999 #define TPACPI_LED_NUMLEDS 16
5000 static struct tpacpi_led_classdev
*tpacpi_leds
;
5001 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
5002 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
5003 /* there's a limit of 19 chars + NULL before 2.6.26 */
5005 "tpacpi:orange:batt",
5006 "tpacpi:green:batt",
5007 "tpacpi::dock_active",
5008 "tpacpi::bay_active",
5009 "tpacpi::dock_batt",
5010 "tpacpi::unknown_led",
5012 "tpacpi::dock_status1",
5013 "tpacpi::dock_status2",
5014 "tpacpi::unknown_led2",
5015 "tpacpi::unknown_led3",
5016 "tpacpi::thinkvantage",
5018 #define TPACPI_SAFE_LEDS 0x1081U
5020 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
5022 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5025 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
5029 static int led_get_status(const unsigned int led
)
5032 enum led_status_t led_s
;
5034 switch (led_supported
) {
5035 case TPACPI_LED_570
:
5036 if (!acpi_evalf(ec_handle
,
5037 &status
, "GLED", "dd", 1 << led
))
5039 led_s
= (status
== 0)?
5044 tpacpi_led_state_cache
[led
] = led_s
;
5053 static int led_set_status(const unsigned int led
,
5054 const enum led_status_t ledstatus
)
5056 /* off, on, blink. Index is led_status_t */
5057 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
5058 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
5062 switch (led_supported
) {
5063 case TPACPI_LED_570
:
5065 if (unlikely(led
> 7))
5067 if (unlikely(tpacpi_is_led_restricted(led
)))
5069 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5070 (1 << led
), led_sled_arg1
[ledstatus
]))
5073 case TPACPI_LED_OLD
:
5074 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
5075 if (unlikely(led
> 7))
5077 if (unlikely(tpacpi_is_led_restricted(led
)))
5079 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
5081 rc
= ec_write(TPACPI_LED_EC_HLBL
,
5082 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5084 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5085 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5087 case TPACPI_LED_NEW
:
5089 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5091 if (unlikely(tpacpi_is_led_restricted(led
)))
5093 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5094 led
, led_led_arg1
[ledstatus
]))
5102 tpacpi_led_state_cache
[led
] = ledstatus
;
5107 static void led_set_status_worker(struct work_struct
*work
)
5109 struct tpacpi_led_classdev
*data
=
5110 container_of(work
, struct tpacpi_led_classdev
, work
);
5112 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5113 led_set_status(data
->led
, data
->new_state
);
5116 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5117 enum led_brightness brightness
)
5119 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5120 struct tpacpi_led_classdev
, led_classdev
);
5122 if (brightness
== LED_OFF
)
5123 data
->new_state
= TPACPI_LED_OFF
;
5124 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5125 data
->new_state
= TPACPI_LED_ON
;
5127 data
->new_state
= TPACPI_LED_BLINK
;
5129 queue_work(tpacpi_wq
, &data
->work
);
5132 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5133 unsigned long *delay_on
, unsigned long *delay_off
)
5135 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5136 struct tpacpi_led_classdev
, led_classdev
);
5138 /* Can we choose the flash rate? */
5139 if (*delay_on
== 0 && *delay_off
== 0) {
5140 /* yes. set them to the hardware blink rate (1 Hz) */
5141 *delay_on
= 500; /* ms */
5142 *delay_off
= 500; /* ms */
5143 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5146 data
->new_state
= TPACPI_LED_BLINK
;
5147 queue_work(tpacpi_wq
, &data
->work
);
5152 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5156 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5157 struct tpacpi_led_classdev
, led_classdev
);
5159 rc
= led_get_status(data
->led
);
5161 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5162 rc
= LED_OFF
; /* no error handling in led class :( */
5169 static void led_exit(void)
5173 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5174 if (tpacpi_leds
[i
].led_classdev
.name
)
5175 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5181 static int __init
tpacpi_init_led(unsigned int led
)
5185 tpacpi_leds
[led
].led
= led
;
5187 /* LEDs with no name don't get registered */
5188 if (!tpacpi_led_names
[led
])
5191 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5192 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5193 if (led_supported
== TPACPI_LED_570
)
5194 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5197 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5199 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5201 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5202 &tpacpi_leds
[led
].led_classdev
);
5204 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5209 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5210 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5211 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5212 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5214 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5215 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5216 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5217 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5218 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5219 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5220 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5221 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5223 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5224 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5225 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5226 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5227 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5229 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5230 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5231 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5232 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5234 /* (1) - may have excess leds enabled on MSB */
5236 /* Defaults (order matters, keep last, don't reorder!) */
5238 .vendor
= PCI_VENDOR_ID_LENOVO
,
5239 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5242 { /* IBM ThinkPads with no EC version string */
5243 .vendor
= PCI_VENDOR_ID_IBM
,
5244 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5247 { /* IBM ThinkPads with EC version string */
5248 .vendor
= PCI_VENDOR_ID_IBM
,
5249 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5254 #undef TPACPI_LEDQ_IBM
5255 #undef TPACPI_LEDQ_LNV
5257 static int __init
led_init(struct ibm_init_struct
*iibm
)
5261 unsigned long useful_leds
;
5263 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5265 TPACPI_ACPIHANDLE_INIT(led
);
5268 /* led not supported on R30, R31 */
5269 led_supported
= TPACPI_LED_NONE
;
5270 else if (strlencmp(led_path
, "SLED") == 0)
5272 led_supported
= TPACPI_LED_570
;
5273 else if (strlencmp(led_path
, "SYSL") == 0)
5274 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5275 led_supported
= TPACPI_LED_OLD
;
5278 led_supported
= TPACPI_LED_NEW
;
5280 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5281 str_supported(led_supported
), led_supported
);
5283 if (led_supported
== TPACPI_LED_NONE
)
5286 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5289 printk(TPACPI_ERR
"Out of memory for LED data\n");
5293 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5294 ARRAY_SIZE(led_useful_qtable
));
5296 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5297 if (!tpacpi_is_led_restricted(i
) &&
5298 test_bit(i
, &useful_leds
)) {
5299 rc
= tpacpi_init_led(i
);
5307 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5308 printk(TPACPI_NOTICE
5309 "warning: userspace override of important "
5310 "firmware LEDs is enabled\n");
5315 #define str_led_status(s) \
5316 ((s) == TPACPI_LED_OFF ? "off" : \
5317 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5319 static int led_read(struct seq_file
*m
)
5321 if (!led_supported
) {
5322 seq_printf(m
, "status:\t\tnot supported\n");
5325 seq_printf(m
, "status:\t\tsupported\n");
5327 if (led_supported
== TPACPI_LED_570
) {
5330 for (i
= 0; i
< 8; i
++) {
5331 status
= led_get_status(i
);
5334 seq_printf(m
, "%d:\t\t%s\n",
5335 i
, str_led_status(status
));
5339 seq_printf(m
, "commands:\t"
5340 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5345 static int led_write(char *buf
)
5349 enum led_status_t s
;
5354 while ((cmd
= next_cmd(&buf
))) {
5355 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5358 if (strstr(cmd
, "off")) {
5360 } else if (strstr(cmd
, "on")) {
5362 } else if (strstr(cmd
, "blink")) {
5363 s
= TPACPI_LED_BLINK
;
5368 rc
= led_set_status(led
, s
);
5376 static struct ibm_struct led_driver_data
= {
5383 /*************************************************************************
5387 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5389 #define TPACPI_BEEP_Q1 0x0001
5391 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5392 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5393 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5396 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5398 unsigned long quirks
;
5400 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5402 TPACPI_ACPIHANDLE_INIT(beep
);
5404 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5405 str_supported(beep_handle
!= NULL
));
5407 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5408 ARRAY_SIZE(beep_quirk_table
));
5410 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5412 return (beep_handle
)? 0 : 1;
5415 static int beep_read(struct seq_file
*m
)
5418 seq_printf(m
, "status:\t\tnot supported\n");
5420 seq_printf(m
, "status:\t\tsupported\n");
5421 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5427 static int beep_write(char *buf
)
5435 while ((cmd
= next_cmd(&buf
))) {
5436 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5437 beep_cmd
>= 0 && beep_cmd
<= 17) {
5441 if (tp_features
.beep_needs_two_args
) {
5442 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5446 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5455 static struct ibm_struct beep_driver_data
= {
5458 .write
= beep_write
,
5461 /*************************************************************************
5465 enum thermal_access_mode
{
5466 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5467 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5468 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5469 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5470 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5473 enum { /* TPACPI_THERMAL_TPEC_* */
5474 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5475 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5476 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5478 TPACPI_THERMAL_SENSOR_NA
= -128000, /* Sensor not available */
5482 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5483 struct ibm_thermal_sensors_struct
{
5484 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5487 static enum thermal_access_mode thermal_read_mode
;
5489 /* idx is zero-based */
5490 static int thermal_get_sensor(int idx
, s32
*value
)
5496 t
= TP_EC_THERMAL_TMP0
;
5498 switch (thermal_read_mode
) {
5499 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5500 case TPACPI_THERMAL_TPEC_16
:
5501 if (idx
>= 8 && idx
<= 15) {
5502 t
= TP_EC_THERMAL_TMP8
;
5507 case TPACPI_THERMAL_TPEC_8
:
5509 if (!acpi_ec_read(t
+ idx
, &tmp
))
5511 *value
= tmp
* 1000;
5516 case TPACPI_THERMAL_ACPI_UPDT
:
5518 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5519 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5521 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5523 *value
= (t
- 2732) * 100;
5528 case TPACPI_THERMAL_ACPI_TMP07
:
5530 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5531 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5533 if (t
> 127 || t
< -127)
5534 t
= TP_EC_THERMAL_TMP_NA
;
5540 case TPACPI_THERMAL_NONE
:
5548 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5559 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5562 for (i
= 0 ; i
< n
; i
++) {
5563 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5571 static void thermal_dump_all_sensors(void)
5574 struct ibm_thermal_sensors_struct t
;
5576 n
= thermal_get_sensors(&t
);
5580 printk(TPACPI_NOTICE
5581 "temperatures (Celsius):");
5583 for (i
= 0; i
< n
; i
++) {
5584 if (t
.temp
[i
] != TPACPI_THERMAL_SENSOR_NA
)
5585 printk(KERN_CONT
" %d", (int)(t
.temp
[i
] / 1000));
5587 printk(KERN_CONT
" N/A");
5590 printk(KERN_CONT
"\n");
5593 /* sysfs temp##_input -------------------------------------------------- */
5595 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5596 struct device_attribute
*attr
,
5599 struct sensor_device_attribute
*sensor_attr
=
5600 to_sensor_dev_attr(attr
);
5601 int idx
= sensor_attr
->index
;
5605 res
= thermal_get_sensor(idx
, &value
);
5608 if (value
== TPACPI_THERMAL_SENSOR_NA
)
5611 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5614 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5615 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5616 thermal_temp_input_show, NULL, _idxB)
5618 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5619 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5620 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5621 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5622 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5623 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5624 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5625 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5626 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5627 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5628 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5629 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5630 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5631 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5632 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5633 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5634 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5637 #define THERMAL_ATTRS(X) \
5638 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5640 static struct attribute
*thermal_temp_input_attr
[] = {
5660 static const struct attribute_group thermal_temp_input16_group
= {
5661 .attrs
= thermal_temp_input_attr
5664 static const struct attribute_group thermal_temp_input8_group
= {
5665 .attrs
= &thermal_temp_input_attr
[8]
5668 #undef THERMAL_SENSOR_ATTR_TEMP
5669 #undef THERMAL_ATTRS
5671 /* --------------------------------------------------------------------- */
5673 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5680 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5682 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5684 if (thinkpad_id
.ec_model
) {
5686 * Direct EC access mode: sensors at registers
5687 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5688 * non-implemented, thermal sensors return 0x80 when
5693 for (i
= 0; i
< 8; i
++) {
5694 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5700 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5708 /* This is sheer paranoia, but we handle it anyway */
5711 "ThinkPad ACPI EC access misbehaving, "
5712 "falling back to ACPI TMPx access "
5714 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5717 "ThinkPad ACPI EC access misbehaving, "
5718 "disabling thermal sensors access\n");
5719 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5724 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5726 } else if (acpi_tmp7
) {
5727 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5728 /* 600e/x, 770e, 770x */
5729 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5731 /* Standard ACPI TMPx access, max 8 sensors */
5732 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5735 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5736 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5739 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5740 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5743 switch (thermal_read_mode
) {
5744 case TPACPI_THERMAL_TPEC_16
:
5745 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5746 &thermal_temp_input16_group
);
5750 case TPACPI_THERMAL_TPEC_8
:
5751 case TPACPI_THERMAL_ACPI_TMP07
:
5752 case TPACPI_THERMAL_ACPI_UPDT
:
5753 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5754 &thermal_temp_input8_group
);
5758 case TPACPI_THERMAL_NONE
:
5766 static void thermal_exit(void)
5768 switch (thermal_read_mode
) {
5769 case TPACPI_THERMAL_TPEC_16
:
5770 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5771 &thermal_temp_input16_group
);
5773 case TPACPI_THERMAL_TPEC_8
:
5774 case TPACPI_THERMAL_ACPI_TMP07
:
5775 case TPACPI_THERMAL_ACPI_UPDT
:
5776 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5777 &thermal_temp_input16_group
);
5779 case TPACPI_THERMAL_NONE
:
5785 static int thermal_read(struct seq_file
*m
)
5788 struct ibm_thermal_sensors_struct t
;
5790 n
= thermal_get_sensors(&t
);
5791 if (unlikely(n
< 0))
5794 seq_printf(m
, "temperatures:\t");
5797 for (i
= 0; i
< (n
- 1); i
++)
5798 seq_printf(m
, "%d ", t
.temp
[i
] / 1000);
5799 seq_printf(m
, "%d\n", t
.temp
[i
] / 1000);
5801 seq_printf(m
, "not supported\n");
5806 static struct ibm_struct thermal_driver_data
= {
5808 .read
= thermal_read
,
5809 .exit
= thermal_exit
,
5812 /*************************************************************************
5816 static u8 ecdump_regs
[256];
5818 static int ecdump_read(struct seq_file
*m
)
5824 " +00 +01 +02 +03 +04 +05 +06 +07"
5825 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5826 for (i
= 0; i
< 256; i
+= 16) {
5827 seq_printf(m
, "EC 0x%02x:", i
);
5828 for (j
= 0; j
< 16; j
++) {
5829 if (!acpi_ec_read(i
+ j
, &v
))
5831 if (v
!= ecdump_regs
[i
+ j
])
5832 seq_printf(m
, " *%02x", v
);
5834 seq_printf(m
, " %02x", v
);
5835 ecdump_regs
[i
+ j
] = v
;
5842 /* These are way too dangerous to advertise openly... */
5844 seq_printf(m
, "commands:\t0x<offset> 0x<value>"
5845 " (<offset> is 00-ff, <value> is 00-ff)\n");
5846 seq_printf(m
, "commands:\t0x<offset> <value> "
5847 " (<offset> is 00-ff, <value> is 0-255)\n");
5852 static int ecdump_write(char *buf
)
5857 while ((cmd
= next_cmd(&buf
))) {
5858 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5860 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5864 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5865 if (!acpi_ec_write(i
, v
))
5874 static struct ibm_struct ecdump_driver_data
= {
5876 .read
= ecdump_read
,
5877 .write
= ecdump_write
,
5878 .flags
.experimental
= 1,
5881 /*************************************************************************
5882 * Backlight/brightness subdriver
5885 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5888 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5889 * CMOS NVRAM byte 0x5E, bits 0-3.
5891 * EC HBRV (0x31) has the following layout
5892 * Bit 7: unknown function
5893 * Bit 6: unknown function
5894 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5895 * Bit 4: must be set to zero to avoid problems
5896 * Bit 3-0: backlight brightness level
5898 * brightness_get_raw returns status data in the HBRV layout
5900 * WARNING: The X61 has been verified to use HBRV for something else, so
5901 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5902 * testing on the very early *60 Lenovo models...
5906 TP_EC_BACKLIGHT
= 0x31,
5908 /* TP_EC_BACKLIGHT bitmasks */
5909 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5910 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5911 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5914 enum tpacpi_brightness_access_mode
{
5915 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5916 TPACPI_BRGHT_MODE_EC
, /* EC control */
5917 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5918 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5919 TPACPI_BRGHT_MODE_MAX
5922 static struct backlight_device
*ibm_backlight_device
;
5924 static enum tpacpi_brightness_access_mode brightness_mode
=
5925 TPACPI_BRGHT_MODE_MAX
;
5927 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5929 static struct mutex brightness_mutex
;
5931 /* NVRAM brightness access,
5932 * call with brightness_mutex held! */
5933 static unsigned int tpacpi_brightness_nvram_get(void)
5937 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5938 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5939 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5940 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5945 static void tpacpi_brightness_checkpoint_nvram(void)
5950 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5953 vdbg_printk(TPACPI_DBG_BRGHT
,
5954 "trying to checkpoint backlight level to NVRAM...\n");
5956 if (mutex_lock_killable(&brightness_mutex
) < 0)
5959 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5961 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5962 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5964 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5965 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5966 /* NVRAM needs update */
5967 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5968 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5970 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5971 dbg_printk(TPACPI_DBG_BRGHT
,
5972 "updated NVRAM backlight level to %u (0x%02x)\n",
5973 (unsigned int) lec
, (unsigned int) b_nvram
);
5975 vdbg_printk(TPACPI_DBG_BRGHT
,
5976 "NVRAM backlight level already is %u (0x%02x)\n",
5977 (unsigned int) lec
, (unsigned int) b_nvram
);
5980 mutex_unlock(&brightness_mutex
);
5984 /* call with brightness_mutex held! */
5985 static int tpacpi_brightness_get_raw(int *status
)
5989 switch (brightness_mode
) {
5990 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5991 *status
= tpacpi_brightness_nvram_get();
5993 case TPACPI_BRGHT_MODE_EC
:
5994 case TPACPI_BRGHT_MODE_ECNVRAM
:
5995 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6004 /* call with brightness_mutex held! */
6005 /* do NOT call with illegal backlight level value */
6006 static int tpacpi_brightness_set_ec(unsigned int value
)
6010 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6013 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
6014 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
6015 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
6021 /* call with brightness_mutex held! */
6022 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
6025 unsigned int current_value
, i
;
6027 current_value
= tpacpi_brightness_nvram_get();
6029 if (value
== current_value
)
6032 cmos_cmd
= (value
> current_value
) ?
6033 TP_CMOS_BRIGHTNESS_UP
:
6034 TP_CMOS_BRIGHTNESS_DOWN
;
6035 inc
= (value
> current_value
) ? 1 : -1;
6037 for (i
= current_value
; i
!= value
; i
+= inc
)
6038 if (issue_thinkpad_cmos_command(cmos_cmd
))
6044 /* May return EINTR which can always be mapped to ERESTARTSYS */
6045 static int brightness_set(unsigned int value
)
6049 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
6053 vdbg_printk(TPACPI_DBG_BRGHT
,
6054 "set backlight level to %d\n", value
);
6056 res
= mutex_lock_killable(&brightness_mutex
);
6060 switch (brightness_mode
) {
6061 case TPACPI_BRGHT_MODE_EC
:
6062 case TPACPI_BRGHT_MODE_ECNVRAM
:
6063 res
= tpacpi_brightness_set_ec(value
);
6065 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6066 res
= tpacpi_brightness_set_ucmsstep(value
);
6072 mutex_unlock(&brightness_mutex
);
6076 /* sysfs backlight class ----------------------------------------------- */
6078 static int brightness_update_status(struct backlight_device
*bd
)
6080 unsigned int level
=
6081 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
6082 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
6083 bd
->props
.brightness
: 0;
6085 dbg_printk(TPACPI_DBG_BRGHT
,
6086 "backlight: attempt to set level to %d\n",
6089 /* it is the backlight class's job (caller) to handle
6090 * EINTR and other errors properly */
6091 return brightness_set(level
);
6094 static int brightness_get(struct backlight_device
*bd
)
6098 res
= mutex_lock_killable(&brightness_mutex
);
6102 res
= tpacpi_brightness_get_raw(&status
);
6104 mutex_unlock(&brightness_mutex
);
6109 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6112 static void tpacpi_brightness_notify_change(void)
6114 backlight_force_update(ibm_backlight_device
,
6115 BACKLIGHT_UPDATE_HOTKEY
);
6118 static struct backlight_ops ibm_backlight_data
= {
6119 .get_brightness
= brightness_get
,
6120 .update_status
= brightness_update_status
,
6123 /* --------------------------------------------------------------------- */
6126 * These are only useful for models that have only one possibility
6127 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6130 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6131 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6132 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6134 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6135 /* Models with ATI GPUs known to require ECNVRAM mode */
6136 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6138 /* Models with ATI GPUs that can use ECNVRAM */
6139 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
),
6140 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6141 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6142 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6144 /* Models with Intel Extreme Graphics 2 */
6145 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
),
6146 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6147 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6149 /* Models with Intel GMA900 */
6150 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6151 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6152 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6155 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6158 unsigned long quirks
;
6160 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6162 mutex_init(&brightness_mutex
);
6164 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6165 ARRAY_SIZE(brightness_quirk_table
));
6168 * We always attempt to detect acpi support, so as to switch
6169 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6170 * going to publish a backlight interface
6172 b
= tpacpi_check_std_acpi_brightness_support();
6175 if (acpi_video_backlight_support()) {
6176 if (brightness_enable
> 1) {
6177 printk(TPACPI_NOTICE
6178 "Standard ACPI backlight interface "
6179 "available, not loading native one.\n");
6181 } else if (brightness_enable
== 1) {
6182 printk(TPACPI_NOTICE
6183 "Backlight control force enabled, even if standard "
6184 "ACPI backlight interface is available\n");
6187 if (brightness_enable
> 1) {
6188 printk(TPACPI_NOTICE
6189 "Standard ACPI backlight interface not "
6190 "available, thinkpad_acpi native "
6191 "brightness control enabled\n");
6196 if (!brightness_enable
) {
6197 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6198 "brightness support disabled by "
6199 "module parameter\n");
6205 "Unsupported brightness interface, "
6206 "please contact %s\n", TPACPI_MAIL
);
6210 tp_features
.bright_16levels
= 1;
6213 * Check for module parameter bogosity, note that we
6214 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6215 * able to detect "unspecified"
6217 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6220 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6221 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6222 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6223 if (quirks
& TPACPI_BRGHT_Q_EC
)
6224 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6226 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6228 dbg_printk(TPACPI_DBG_BRGHT
,
6229 "driver auto-selected brightness_mode=%d\n",
6234 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6235 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6236 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6239 if (tpacpi_brightness_get_raw(&b
) < 0)
6242 if (tp_features
.bright_16levels
)
6244 "detected a 16-level brightness capable ThinkPad\n");
6246 ibm_backlight_device
= backlight_device_register(
6247 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6248 &ibm_backlight_data
);
6249 if (IS_ERR(ibm_backlight_device
)) {
6250 int rc
= PTR_ERR(ibm_backlight_device
);
6251 ibm_backlight_device
= NULL
;
6252 printk(TPACPI_ERR
"Could not register backlight device\n");
6255 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6256 "brightness is supported\n");
6258 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6259 printk(TPACPI_NOTICE
6260 "brightness: will use unverified default: "
6261 "brightness_mode=%d\n", brightness_mode
);
6262 printk(TPACPI_NOTICE
6263 "brightness: please report to %s whether it works well "
6264 "or not on your ThinkPad\n", TPACPI_MAIL
);
6267 ibm_backlight_device
->props
.max_brightness
=
6268 (tp_features
.bright_16levels
)? 15 : 7;
6269 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6270 backlight_update_status(ibm_backlight_device
);
6272 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6273 "brightness: registering brightness hotkeys "
6274 "as change notification\n");
6275 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6276 | TP_ACPI_HKEY_BRGHTUP_MASK
6277 | TP_ACPI_HKEY_BRGHTDWN_MASK
);;
6281 static void brightness_suspend(pm_message_t state
)
6283 tpacpi_brightness_checkpoint_nvram();
6286 static void brightness_shutdown(void)
6288 tpacpi_brightness_checkpoint_nvram();
6291 static void brightness_exit(void)
6293 if (ibm_backlight_device
) {
6294 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6295 "calling backlight_device_unregister()\n");
6296 backlight_device_unregister(ibm_backlight_device
);
6299 tpacpi_brightness_checkpoint_nvram();
6302 static int brightness_read(struct seq_file
*m
)
6306 level
= brightness_get(NULL
);
6308 seq_printf(m
, "level:\t\tunreadable\n");
6310 seq_printf(m
, "level:\t\t%d\n", level
);
6311 seq_printf(m
, "commands:\tup, down\n");
6312 seq_printf(m
, "commands:\tlevel <level>"
6313 " (<level> is 0-%d)\n",
6314 (tp_features
.bright_16levels
) ? 15 : 7);
6320 static int brightness_write(char *buf
)
6325 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6327 level
= brightness_get(NULL
);
6331 while ((cmd
= next_cmd(&buf
))) {
6332 if (strlencmp(cmd
, "up") == 0) {
6333 if (level
< max_level
)
6335 } else if (strlencmp(cmd
, "down") == 0) {
6338 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6339 level
>= 0 && level
<= max_level
) {
6345 tpacpi_disclose_usertask("procfs brightness",
6346 "set level to %d\n", level
);
6349 * Now we know what the final level should be, so we try to set it.
6350 * Doing it this way makes the syscall restartable in case of EINTR
6352 rc
= brightness_set(level
);
6353 if (!rc
&& ibm_backlight_device
)
6354 backlight_force_update(ibm_backlight_device
,
6355 BACKLIGHT_UPDATE_SYSFS
);
6356 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6359 static struct ibm_struct brightness_driver_data
= {
6360 .name
= "brightness",
6361 .read
= brightness_read
,
6362 .write
= brightness_write
,
6363 .exit
= brightness_exit
,
6364 .suspend
= brightness_suspend
,
6365 .shutdown
= brightness_shutdown
,
6368 /*************************************************************************
6373 * IBM ThinkPads have a simple volume controller with MUTE gating.
6374 * Very early Lenovo ThinkPads follow the IBM ThinkPad spec.
6376 * Since the *61 series (and probably also the later *60 series), Lenovo
6377 * ThinkPads only implement the MUTE gate.
6380 * Bit 6: MUTE (1 mutes sound)
6382 * Other bits should be zero as far as we know.
6384 * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and
6385 * bits 3-0 (volume). Other bits in NVRAM may have other functions,
6386 * such as bit 7 which is used to detect repeated presses of MUTE,
6387 * and we leave them unchanged.
6390 #define TPACPI_ALSA_DRVNAME "ThinkPad EC"
6391 #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control"
6392 #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME
6394 static int alsa_index
= SNDRV_DEFAULT_IDX1
;
6395 static char *alsa_id
= "ThinkPadEC";
6396 static int alsa_enable
= SNDRV_DEFAULT_ENABLE1
;
6398 struct tpacpi_alsa_data
{
6399 struct snd_card
*card
;
6400 struct snd_ctl_elem_id
*ctl_mute_id
;
6401 struct snd_ctl_elem_id
*ctl_vol_id
;
6404 static struct snd_card
*alsa_card
;
6409 /* TP_EC_AUDIO bits */
6410 TP_EC_AUDIO_MUTESW
= 6,
6412 /* TP_EC_AUDIO bitmasks */
6413 TP_EC_AUDIO_LVL_MSK
= 0x0F,
6414 TP_EC_AUDIO_MUTESW_MSK
= (1 << TP_EC_AUDIO_MUTESW
),
6416 /* Maximum volume */
6417 TP_EC_VOLUME_MAX
= 14,
6420 enum tpacpi_volume_access_mode
{
6421 TPACPI_VOL_MODE_AUTO
= 0, /* Not implemented yet */
6422 TPACPI_VOL_MODE_EC
, /* Pure EC control */
6423 TPACPI_VOL_MODE_UCMS_STEP
, /* UCMS step-based control: N/A */
6424 TPACPI_VOL_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
6428 enum tpacpi_volume_capabilities
{
6429 TPACPI_VOL_CAP_AUTO
= 0, /* Use white/blacklist */
6430 TPACPI_VOL_CAP_VOLMUTE
, /* Output vol and mute */
6431 TPACPI_VOL_CAP_MUTEONLY
, /* Output mute only */
6435 static enum tpacpi_volume_access_mode volume_mode
=
6436 TPACPI_VOL_MODE_MAX
;
6438 static enum tpacpi_volume_capabilities volume_capabilities
;
6439 static int volume_control_allowed
;
6442 * Used to syncronize writers to TP_EC_AUDIO and
6443 * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write
6445 static struct mutex volume_mutex
;
6447 static void tpacpi_volume_checkpoint_nvram(void)
6453 if (volume_mode
!= TPACPI_VOL_MODE_ECNVRAM
)
6455 if (!volume_control_allowed
)
6458 vdbg_printk(TPACPI_DBG_MIXER
,
6459 "trying to checkpoint mixer state to NVRAM...\n");
6461 if (tp_features
.mixer_no_level_control
)
6462 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
;
6464 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
| TP_EC_AUDIO_LVL_MSK
;
6466 if (mutex_lock_killable(&volume_mutex
) < 0)
6469 if (unlikely(!acpi_ec_read(TP_EC_AUDIO
, &lec
)))
6472 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
6474 if (lec
!= (b_nvram
& ec_mask
)) {
6475 /* NVRAM needs update */
6476 b_nvram
&= ~ec_mask
;
6478 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_MIXER
);
6479 dbg_printk(TPACPI_DBG_MIXER
,
6480 "updated NVRAM mixer status to 0x%02x (0x%02x)\n",
6481 (unsigned int) lec
, (unsigned int) b_nvram
);
6483 vdbg_printk(TPACPI_DBG_MIXER
,
6484 "NVRAM mixer status already is 0x%02x (0x%02x)\n",
6485 (unsigned int) lec
, (unsigned int) b_nvram
);
6489 mutex_unlock(&volume_mutex
);
6492 static int volume_get_status_ec(u8
*status
)
6496 if (!acpi_ec_read(TP_EC_AUDIO
, &s
))
6501 dbg_printk(TPACPI_DBG_MIXER
, "status 0x%02x\n", s
);
6506 static int volume_get_status(u8
*status
)
6508 return volume_get_status_ec(status
);
6511 static int volume_set_status_ec(const u8 status
)
6513 if (!acpi_ec_write(TP_EC_AUDIO
, status
))
6516 dbg_printk(TPACPI_DBG_MIXER
, "set EC mixer to 0x%02x\n", status
);
6521 static int volume_set_status(const u8 status
)
6523 return volume_set_status_ec(status
);
6526 static int volume_set_mute_ec(const bool mute
)
6531 if (mutex_lock_killable(&volume_mutex
) < 0)
6534 rc
= volume_get_status_ec(&s
);
6538 n
= (mute
) ? s
| TP_EC_AUDIO_MUTESW_MSK
:
6539 s
& ~TP_EC_AUDIO_MUTESW_MSK
;
6542 rc
= volume_set_status_ec(n
);
6545 mutex_unlock(&volume_mutex
);
6549 static int volume_set_mute(const bool mute
)
6551 dbg_printk(TPACPI_DBG_MIXER
, "trying to %smute\n",
6552 (mute
) ? "" : "un");
6553 return volume_set_mute_ec(mute
);
6556 static int volume_set_volume_ec(const u8 vol
)
6561 if (vol
> TP_EC_VOLUME_MAX
)
6564 if (mutex_lock_killable(&volume_mutex
) < 0)
6567 rc
= volume_get_status_ec(&s
);
6571 n
= (s
& ~TP_EC_AUDIO_LVL_MSK
) | vol
;
6574 rc
= volume_set_status_ec(n
);
6577 mutex_unlock(&volume_mutex
);
6581 static int volume_set_volume(const u8 vol
)
6583 dbg_printk(TPACPI_DBG_MIXER
,
6584 "trying to set volume level to %hu\n", vol
);
6585 return volume_set_volume_ec(vol
);
6588 static void volume_alsa_notify_change(void)
6590 struct tpacpi_alsa_data
*d
;
6592 if (alsa_card
&& alsa_card
->private_data
) {
6593 d
= alsa_card
->private_data
;
6595 snd_ctl_notify(alsa_card
,
6596 SNDRV_CTL_EVENT_MASK_VALUE
,
6599 snd_ctl_notify(alsa_card
,
6600 SNDRV_CTL_EVENT_MASK_VALUE
,
6605 static int volume_alsa_vol_info(struct snd_kcontrol
*kcontrol
,
6606 struct snd_ctl_elem_info
*uinfo
)
6608 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
6610 uinfo
->value
.integer
.min
= 0;
6611 uinfo
->value
.integer
.max
= TP_EC_VOLUME_MAX
;
6615 static int volume_alsa_vol_get(struct snd_kcontrol
*kcontrol
,
6616 struct snd_ctl_elem_value
*ucontrol
)
6621 rc
= volume_get_status(&s
);
6625 ucontrol
->value
.integer
.value
[0] = s
& TP_EC_AUDIO_LVL_MSK
;
6629 static int volume_alsa_vol_put(struct snd_kcontrol
*kcontrol
,
6630 struct snd_ctl_elem_value
*ucontrol
)
6632 return volume_set_volume(ucontrol
->value
.integer
.value
[0]);
6635 #define volume_alsa_mute_info snd_ctl_boolean_mono_info
6637 static int volume_alsa_mute_get(struct snd_kcontrol
*kcontrol
,
6638 struct snd_ctl_elem_value
*ucontrol
)
6643 rc
= volume_get_status(&s
);
6647 ucontrol
->value
.integer
.value
[0] =
6648 (s
& TP_EC_AUDIO_MUTESW_MSK
) ? 0 : 1;
6652 static int volume_alsa_mute_put(struct snd_kcontrol
*kcontrol
,
6653 struct snd_ctl_elem_value
*ucontrol
)
6655 return volume_set_mute(!ucontrol
->value
.integer
.value
[0]);
6658 static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata
= {
6659 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6660 .name
= "Console Playback Volume",
6662 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6663 .info
= volume_alsa_vol_info
,
6664 .get
= volume_alsa_vol_get
,
6667 static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata
= {
6668 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6669 .name
= "Console Playback Switch",
6671 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6672 .info
= volume_alsa_mute_info
,
6673 .get
= volume_alsa_mute_get
,
6676 static void volume_suspend(pm_message_t state
)
6678 tpacpi_volume_checkpoint_nvram();
6681 static void volume_resume(void)
6683 volume_alsa_notify_change();
6686 static void volume_shutdown(void)
6688 tpacpi_volume_checkpoint_nvram();
6691 static void volume_exit(void)
6694 snd_card_free(alsa_card
);
6698 tpacpi_volume_checkpoint_nvram();
6701 static int __init
volume_create_alsa_mixer(void)
6703 struct snd_card
*card
;
6704 struct tpacpi_alsa_data
*data
;
6705 struct snd_kcontrol
*ctl_vol
;
6706 struct snd_kcontrol
*ctl_mute
;
6709 rc
= snd_card_create(alsa_index
, alsa_id
, THIS_MODULE
,
6710 sizeof(struct tpacpi_alsa_data
), &card
);
6716 BUG_ON(!card
->private_data
);
6717 data
= card
->private_data
;
6720 strlcpy(card
->driver
, TPACPI_ALSA_DRVNAME
,
6721 sizeof(card
->driver
));
6722 strlcpy(card
->shortname
, TPACPI_ALSA_SHRTNAME
,
6723 sizeof(card
->shortname
));
6724 snprintf(card
->mixername
, sizeof(card
->mixername
), "ThinkPad EC %s",
6725 (thinkpad_id
.ec_version_str
) ?
6726 thinkpad_id
.ec_version_str
: "(unknown)");
6727 snprintf(card
->longname
, sizeof(card
->longname
),
6728 "%s at EC reg 0x%02x, fw %s", card
->shortname
, TP_EC_AUDIO
,
6729 (thinkpad_id
.ec_version_str
) ?
6730 thinkpad_id
.ec_version_str
: "unknown");
6732 if (volume_control_allowed
) {
6733 volume_alsa_control_vol
.put
= volume_alsa_vol_put
;
6734 volume_alsa_control_vol
.access
=
6735 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6737 volume_alsa_control_mute
.put
= volume_alsa_mute_put
;
6738 volume_alsa_control_mute
.access
=
6739 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6742 if (!tp_features
.mixer_no_level_control
) {
6743 ctl_vol
= snd_ctl_new1(&volume_alsa_control_vol
, NULL
);
6744 rc
= snd_ctl_add(card
, ctl_vol
);
6747 "Failed to create ALSA volume control\n");
6750 data
->ctl_vol_id
= &ctl_vol
->id
;
6753 ctl_mute
= snd_ctl_new1(&volume_alsa_control_mute
, NULL
);
6754 rc
= snd_ctl_add(card
, ctl_mute
);
6756 printk(TPACPI_ERR
"Failed to create ALSA mute control\n");
6759 data
->ctl_mute_id
= &ctl_mute
->id
;
6761 snd_card_set_dev(card
, &tpacpi_pdev
->dev
);
6762 rc
= snd_card_register(card
);
6766 snd_card_free(card
);
6774 #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */
6775 #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */
6777 static const struct tpacpi_quirk volume_quirk_table
[] __initconst
= {
6778 /* Whitelist volume level on all IBM by default */
6779 { .vendor
= PCI_VENDOR_ID_IBM
,
6780 .bios
= TPACPI_MATCH_ANY
,
6781 .ec
= TPACPI_MATCH_ANY
,
6782 .quirks
= TPACPI_VOL_Q_LEVEL
},
6784 /* Lenovo models with volume control (needs confirmation) */
6785 TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL
), /* R60/i */
6786 TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL
), /* R60e/i */
6787 TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL
), /* T60/p */
6788 TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL
), /* X60/s */
6789 TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL
), /* X60t */
6790 TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL
), /* Z60 */
6791 TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL
), /* Z61 */
6793 /* Whitelist mute-only on all Lenovo by default */
6794 { .vendor
= PCI_VENDOR_ID_LENOVO
,
6795 .bios
= TPACPI_MATCH_ANY
,
6796 .ec
= TPACPI_MATCH_ANY
,
6797 .quirks
= TPACPI_VOL_Q_MUTEONLY
}
6800 static int __init
volume_init(struct ibm_init_struct
*iibm
)
6802 unsigned long quirks
;
6805 vdbg_printk(TPACPI_DBG_INIT
, "initializing volume subdriver\n");
6807 mutex_init(&volume_mutex
);
6810 * Check for module parameter bogosity, note that we
6811 * init volume_mode to TPACPI_VOL_MODE_MAX in order to be
6812 * able to detect "unspecified"
6814 if (volume_mode
> TPACPI_VOL_MODE_MAX
)
6817 if (volume_mode
== TPACPI_VOL_MODE_UCMS_STEP
) {
6819 "UCMS step volume mode not implemented, "
6820 "please contact %s\n", TPACPI_MAIL
);
6824 if (volume_capabilities
>= TPACPI_VOL_CAP_MAX
)
6828 * The ALSA mixer is our primary interface.
6829 * When disabled, don't install the subdriver at all
6832 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6833 "ALSA mixer disabled by parameter, "
6834 "not loading volume subdriver...\n");
6838 quirks
= tpacpi_check_quirks(volume_quirk_table
,
6839 ARRAY_SIZE(volume_quirk_table
));
6841 switch (volume_capabilities
) {
6842 case TPACPI_VOL_CAP_AUTO
:
6843 if (quirks
& TPACPI_VOL_Q_MUTEONLY
)
6844 tp_features
.mixer_no_level_control
= 1;
6845 else if (quirks
& TPACPI_VOL_Q_LEVEL
)
6846 tp_features
.mixer_no_level_control
= 0;
6848 return 1; /* no mixer */
6850 case TPACPI_VOL_CAP_VOLMUTE
:
6851 tp_features
.mixer_no_level_control
= 0;
6853 case TPACPI_VOL_CAP_MUTEONLY
:
6854 tp_features
.mixer_no_level_control
= 1;
6860 if (volume_capabilities
!= TPACPI_VOL_CAP_AUTO
)
6861 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6862 "using user-supplied volume_capabilities=%d\n",
6863 volume_capabilities
);
6865 if (volume_mode
== TPACPI_VOL_MODE_AUTO
||
6866 volume_mode
== TPACPI_VOL_MODE_MAX
) {
6867 volume_mode
= TPACPI_VOL_MODE_ECNVRAM
;
6869 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6870 "driver auto-selected volume_mode=%d\n",
6873 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6874 "using user-supplied volume_mode=%d\n",
6878 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6879 "mute is supported, volume control is %s\n",
6880 str_supported(!tp_features
.mixer_no_level_control
));
6882 rc
= volume_create_alsa_mixer();
6885 "Could not create the ALSA mixer interface\n");
6890 "Console audio control enabled, mode: %s\n",
6891 (volume_control_allowed
) ?
6892 "override (read/write)" :
6893 "monitor (read only)");
6895 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6896 "registering volume hotkeys as change notification\n");
6897 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6898 | TP_ACPI_HKEY_VOLUP_MASK
6899 | TP_ACPI_HKEY_VOLDWN_MASK
6900 | TP_ACPI_HKEY_MUTE_MASK
);
6905 static int volume_read(struct seq_file
*m
)
6909 if (volume_get_status(&status
) < 0) {
6910 seq_printf(m
, "level:\t\tunreadable\n");
6912 if (tp_features
.mixer_no_level_control
)
6913 seq_printf(m
, "level:\t\tunsupported\n");
6915 seq_printf(m
, "level:\t\t%d\n",
6916 status
& TP_EC_AUDIO_LVL_MSK
);
6918 seq_printf(m
, "mute:\t\t%s\n",
6919 onoff(status
, TP_EC_AUDIO_MUTESW
));
6921 if (volume_control_allowed
) {
6922 seq_printf(m
, "commands:\tunmute, mute\n");
6923 if (!tp_features
.mixer_no_level_control
) {
6925 "commands:\tup, down\n");
6927 "commands:\tlevel <level>"
6928 " (<level> is 0-%d)\n",
6937 static int volume_write(char *buf
)
6940 u8 new_level
, new_mute
;
6946 * We do allow volume control at driver startup, so that the
6947 * user can set initial state through the volume=... parameter hack.
6949 if (!volume_control_allowed
&& tpacpi_lifecycle
!= TPACPI_LIFE_INIT
) {
6950 if (unlikely(!tp_warned
.volume_ctrl_forbidden
)) {
6951 tp_warned
.volume_ctrl_forbidden
= 1;
6952 printk(TPACPI_NOTICE
6953 "Console audio control in monitor mode, "
6954 "changes are not allowed.\n");
6955 printk(TPACPI_NOTICE
6956 "Use the volume_control=1 module parameter "
6957 "to enable volume control\n");
6962 rc
= volume_get_status(&s
);
6966 new_level
= s
& TP_EC_AUDIO_LVL_MSK
;
6967 new_mute
= s
& TP_EC_AUDIO_MUTESW_MSK
;
6969 while ((cmd
= next_cmd(&buf
))) {
6970 if (!tp_features
.mixer_no_level_control
) {
6971 if (strlencmp(cmd
, "up") == 0) {
6974 else if (new_level
< TP_EC_VOLUME_MAX
)
6977 } else if (strlencmp(cmd
, "down") == 0) {
6980 else if (new_level
> 0)
6983 } else if (sscanf(cmd
, "level %u", &l
) == 1 &&
6984 l
>= 0 && l
<= TP_EC_VOLUME_MAX
) {
6989 if (strlencmp(cmd
, "mute") == 0)
6990 new_mute
= TP_EC_AUDIO_MUTESW_MSK
;
6991 else if (strlencmp(cmd
, "unmute") == 0)
6997 if (tp_features
.mixer_no_level_control
) {
6998 tpacpi_disclose_usertask("procfs volume", "%smute\n",
6999 new_mute
? "" : "un");
7000 rc
= volume_set_mute(!!new_mute
);
7002 tpacpi_disclose_usertask("procfs volume",
7003 "%smute and set level to %d\n",
7004 new_mute
? "" : "un", new_level
);
7005 rc
= volume_set_status(new_mute
| new_level
);
7007 volume_alsa_notify_change();
7009 return (rc
== -EINTR
) ? -ERESTARTSYS
: rc
;
7012 static struct ibm_struct volume_driver_data
= {
7014 .read
= volume_read
,
7015 .write
= volume_write
,
7016 .exit
= volume_exit
,
7017 .suspend
= volume_suspend
,
7018 .resume
= volume_resume
,
7019 .shutdown
= volume_shutdown
,
7022 /*************************************************************************
7029 * TPACPI_FAN_RD_ACPI_GFAN:
7030 * ACPI GFAN method: returns fan level
7032 * see TPACPI_FAN_WR_ACPI_SFAN
7033 * EC 0x2f (HFSP) not available if GFAN exists
7035 * TPACPI_FAN_WR_ACPI_SFAN:
7036 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
7038 * EC 0x2f (HFSP) might be available *for reading*, but do not use
7041 * TPACPI_FAN_WR_TPEC:
7042 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
7043 * Supported on almost all ThinkPads
7045 * Fan speed changes of any sort (including those caused by the
7046 * disengaged mode) are usually done slowly by the firmware as the
7047 * maximum ammount of fan duty cycle change per second seems to be
7050 * Reading is not available if GFAN exists.
7051 * Writing is not available if SFAN exists.
7054 * 7 automatic mode engaged;
7055 * (default operation mode of the ThinkPad)
7056 * fan level is ignored in this mode.
7057 * 6 full speed mode (takes precedence over bit 7);
7058 * not available on all thinkpads. May disable
7059 * the tachometer while the fan controller ramps up
7060 * the speed (which can take up to a few *minutes*).
7061 * Speeds up fan to 100% duty-cycle, which is far above
7062 * the standard RPM levels. It is not impossible that
7063 * it could cause hardware damage.
7064 * 5-3 unused in some models. Extra bits for fan level
7065 * in others, but still useless as all values above
7066 * 7 map to the same speed as level 7 in these models.
7067 * 2-0 fan level (0..7 usually)
7069 * 0x07 = max (set when temperatures critical)
7070 * Some ThinkPads may have other levels, see
7071 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
7073 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
7074 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
7075 * does so, its initial value is meaningless (0x07).
7077 * For firmware bugs, refer to:
7078 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7082 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
7083 * Main fan tachometer reading (in RPM)
7085 * This register is present on all ThinkPads with a new-style EC, and
7086 * it is known not to be present on the A21m/e, and T22, as there is
7087 * something else in offset 0x84 according to the ACPI DSDT. Other
7088 * ThinkPads from this same time period (and earlier) probably lack the
7089 * tachometer as well.
7091 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
7092 * was never fixed by IBM to report the EC firmware version string
7093 * probably support the tachometer (like the early X models), so
7094 * detecting it is quite hard. We need more data to know for sure.
7096 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
7099 * FIRMWARE BUG: may go stale while the EC is switching to full speed
7102 * For firmware bugs, refer to:
7103 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7107 * ThinkPad EC register 0x31 bit 0 (only on select models)
7109 * When bit 0 of EC register 0x31 is zero, the tachometer registers
7110 * show the speed of the main fan. When bit 0 of EC register 0x31
7111 * is one, the tachometer registers show the speed of the auxiliary
7114 * Fan control seems to affect both fans, regardless of the state
7117 * So far, only the firmware for the X60/X61 non-tablet versions
7118 * seem to support this (firmware TP-7M).
7120 * TPACPI_FAN_WR_ACPI_FANS:
7121 * ThinkPad X31, X40, X41. Not available in the X60.
7123 * FANS ACPI handle: takes three arguments: low speed, medium speed,
7124 * high speed. ACPI DSDT seems to map these three speeds to levels
7125 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
7126 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
7128 * The speeds are stored on handles
7129 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
7131 * There are three default speed sets, acessible as handles:
7132 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
7134 * ACPI DSDT switches which set is in use depending on various
7137 * TPACPI_FAN_WR_TPEC is also available and should be used to
7138 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
7139 * but the ACPI tables just mention level 7.
7142 enum { /* Fan control constants */
7143 fan_status_offset
= 0x2f, /* EC register 0x2f */
7144 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
7145 * 0x84 must be read before 0x85 */
7146 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
7147 bit 0 selects which fan is active */
7149 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
7150 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
7152 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
7155 enum fan_status_access_mode
{
7156 TPACPI_FAN_NONE
= 0, /* No fan status or control */
7157 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
7158 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
7161 enum fan_control_access_mode
{
7162 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
7163 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
7164 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
7165 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
7168 enum fan_control_commands
{
7169 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
7170 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
7171 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
7172 * and also watchdog cmd */
7175 static int fan_control_allowed
;
7177 static enum fan_status_access_mode fan_status_access_mode
;
7178 static enum fan_control_access_mode fan_control_access_mode
;
7179 static enum fan_control_commands fan_control_commands
;
7181 static u8 fan_control_initial_status
;
7182 static u8 fan_control_desired_level
;
7183 static u8 fan_control_resume_level
;
7184 static int fan_watchdog_maxinterval
;
7186 static struct mutex fan_mutex
;
7188 static void fan_watchdog_fire(struct work_struct
*ignored
);
7189 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
7191 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
7192 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
7193 "\\FSPD", /* 600e/x, 770e, 770x */
7195 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
7196 "JFNS", /* 770x-JL */
7200 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
7201 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
7202 * be in auto mode (0x80).
7204 * This is corrected by any write to HFSP either by the driver, or
7207 * We assume 0x07 really means auto mode while this quirk is active,
7208 * as this is far more likely than the ThinkPad being in level 7,
7209 * which is only used by the firmware during thermal emergencies.
7211 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
7212 * TP-70 (T43, R52), which are known to be buggy.
7215 static void fan_quirk1_setup(void)
7217 if (fan_control_initial_status
== 0x07) {
7218 printk(TPACPI_NOTICE
7219 "fan_init: initial fan status is unknown, "
7220 "assuming it is in auto mode\n");
7221 tp_features
.fan_ctrl_status_undef
= 1;
7225 static void fan_quirk1_handle(u8
*fan_status
)
7227 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
7228 if (*fan_status
!= fan_control_initial_status
) {
7229 /* something changed the HFSP regisnter since
7230 * driver init time, so it is not undefined
7232 tp_features
.fan_ctrl_status_undef
= 0;
7234 /* Return most likely status. In fact, it
7235 * might be the only possible status */
7236 *fan_status
= TP_EC_FAN_AUTO
;
7241 /* Select main fan on X60/X61, NOOP on others */
7242 static bool fan_select_fan1(void)
7244 if (tp_features
.second_fan
) {
7247 if (ec_read(fan_select_offset
, &val
) < 0)
7250 if (ec_write(fan_select_offset
, val
) < 0)
7256 /* Select secondary fan on X60/X61 */
7257 static bool fan_select_fan2(void)
7261 if (!tp_features
.second_fan
)
7264 if (ec_read(fan_select_offset
, &val
) < 0)
7267 if (ec_write(fan_select_offset
, val
) < 0)
7274 * Call with fan_mutex held
7276 static void fan_update_desired_level(u8 status
)
7279 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7281 fan_control_desired_level
= 7;
7283 fan_control_desired_level
= status
;
7287 static int fan_get_status(u8
*status
)
7292 * Add TPACPI_FAN_RD_ACPI_FANS ? */
7294 switch (fan_status_access_mode
) {
7295 case TPACPI_FAN_RD_ACPI_GFAN
:
7296 /* 570, 600e/x, 770e, 770x */
7298 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
7306 case TPACPI_FAN_RD_TPEC
:
7307 /* all except 570, 600e/x, 770e, 770x */
7308 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
7311 if (likely(status
)) {
7313 fan_quirk1_handle(status
);
7325 static int fan_get_status_safe(u8
*status
)
7330 if (mutex_lock_killable(&fan_mutex
))
7331 return -ERESTARTSYS
;
7332 rc
= fan_get_status(&s
);
7334 fan_update_desired_level(s
);
7335 mutex_unlock(&fan_mutex
);
7343 static int fan_get_speed(unsigned int *speed
)
7347 switch (fan_status_access_mode
) {
7348 case TPACPI_FAN_RD_TPEC
:
7349 /* all except 570, 600e/x, 770e, 770x */
7350 if (unlikely(!fan_select_fan1()))
7352 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
7353 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
7357 *speed
= (hi
<< 8) | lo
;
7368 static int fan2_get_speed(unsigned int *speed
)
7373 switch (fan_status_access_mode
) {
7374 case TPACPI_FAN_RD_TPEC
:
7375 /* all except 570, 600e/x, 770e, 770x */
7376 if (unlikely(!fan_select_fan2()))
7378 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
7379 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
7380 fan_select_fan1(); /* play it safe */
7385 *speed
= (hi
<< 8) | lo
;
7396 static int fan_set_level(int level
)
7398 if (!fan_control_allowed
)
7401 switch (fan_control_access_mode
) {
7402 case TPACPI_FAN_WR_ACPI_SFAN
:
7403 if (level
>= 0 && level
<= 7) {
7404 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
7410 case TPACPI_FAN_WR_ACPI_FANS
:
7411 case TPACPI_FAN_WR_TPEC
:
7412 if (!(level
& TP_EC_FAN_AUTO
) &&
7413 !(level
& TP_EC_FAN_FULLSPEED
) &&
7414 ((level
< 0) || (level
> 7)))
7417 /* safety net should the EC not support AUTO
7418 * or FULLSPEED mode bits and just ignore them */
7419 if (level
& TP_EC_FAN_FULLSPEED
)
7420 level
|= 7; /* safety min speed 7 */
7421 else if (level
& TP_EC_FAN_AUTO
)
7422 level
|= 4; /* safety min speed 4 */
7424 if (!acpi_ec_write(fan_status_offset
, level
))
7427 tp_features
.fan_ctrl_status_undef
= 0;
7434 vdbg_printk(TPACPI_DBG_FAN
,
7435 "fan control: set fan control register to 0x%02x\n", level
);
7439 static int fan_set_level_safe(int level
)
7443 if (!fan_control_allowed
)
7446 if (mutex_lock_killable(&fan_mutex
))
7447 return -ERESTARTSYS
;
7449 if (level
== TPACPI_FAN_LAST_LEVEL
)
7450 level
= fan_control_desired_level
;
7452 rc
= fan_set_level(level
);
7454 fan_update_desired_level(level
);
7456 mutex_unlock(&fan_mutex
);
7460 static int fan_set_enable(void)
7465 if (!fan_control_allowed
)
7468 if (mutex_lock_killable(&fan_mutex
))
7469 return -ERESTARTSYS
;
7471 switch (fan_control_access_mode
) {
7472 case TPACPI_FAN_WR_ACPI_FANS
:
7473 case TPACPI_FAN_WR_TPEC
:
7474 rc
= fan_get_status(&s
);
7478 /* Don't go out of emergency fan mode */
7481 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
7484 if (!acpi_ec_write(fan_status_offset
, s
))
7487 tp_features
.fan_ctrl_status_undef
= 0;
7492 case TPACPI_FAN_WR_ACPI_SFAN
:
7493 rc
= fan_get_status(&s
);
7499 /* Set fan to at least level 4 */
7502 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
7512 mutex_unlock(&fan_mutex
);
7515 vdbg_printk(TPACPI_DBG_FAN
,
7516 "fan control: set fan control register to 0x%02x\n",
7521 static int fan_set_disable(void)
7525 if (!fan_control_allowed
)
7528 if (mutex_lock_killable(&fan_mutex
))
7529 return -ERESTARTSYS
;
7532 switch (fan_control_access_mode
) {
7533 case TPACPI_FAN_WR_ACPI_FANS
:
7534 case TPACPI_FAN_WR_TPEC
:
7535 if (!acpi_ec_write(fan_status_offset
, 0x00))
7538 fan_control_desired_level
= 0;
7539 tp_features
.fan_ctrl_status_undef
= 0;
7543 case TPACPI_FAN_WR_ACPI_SFAN
:
7544 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
7547 fan_control_desired_level
= 0;
7555 vdbg_printk(TPACPI_DBG_FAN
,
7556 "fan control: set fan control register to 0\n");
7558 mutex_unlock(&fan_mutex
);
7562 static int fan_set_speed(int speed
)
7566 if (!fan_control_allowed
)
7569 if (mutex_lock_killable(&fan_mutex
))
7570 return -ERESTARTSYS
;
7573 switch (fan_control_access_mode
) {
7574 case TPACPI_FAN_WR_ACPI_FANS
:
7575 if (speed
>= 0 && speed
<= 65535) {
7576 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
7577 speed
, speed
, speed
))
7587 mutex_unlock(&fan_mutex
);
7591 static void fan_watchdog_reset(void)
7593 static int fan_watchdog_active
;
7595 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
7598 if (fan_watchdog_active
)
7599 cancel_delayed_work(&fan_watchdog_task
);
7601 if (fan_watchdog_maxinterval
> 0 &&
7602 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
7603 fan_watchdog_active
= 1;
7604 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
7605 msecs_to_jiffies(fan_watchdog_maxinterval
7608 "failed to queue the fan watchdog, "
7609 "watchdog will not trigger\n");
7612 fan_watchdog_active
= 0;
7615 static void fan_watchdog_fire(struct work_struct
*ignored
)
7619 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
7622 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
7623 rc
= fan_set_enable();
7625 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
7626 "will try again later...\n", -rc
);
7627 /* reschedule for later */
7628 fan_watchdog_reset();
7633 * SYSFS fan layout: hwmon compatible (device)
7636 * 0: "disengaged" mode
7638 * 2: native EC "auto" mode (recommended, hardware default)
7640 * pwm*: set speed in manual mode, ignored otherwise.
7641 * 0 is level 0; 255 is level 7. Intermediate points done with linear
7644 * fan*_input: tachometer reading, RPM
7647 * SYSFS fan layout: extensions
7649 * fan_watchdog (driver):
7650 * fan watchdog interval in seconds, 0 disables (default), max 120
7653 /* sysfs fan pwm1_enable ----------------------------------------------- */
7654 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
7655 struct device_attribute
*attr
,
7661 res
= fan_get_status_safe(&status
);
7665 if (status
& TP_EC_FAN_FULLSPEED
) {
7667 } else if (status
& TP_EC_FAN_AUTO
) {
7672 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
7675 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7676 struct device_attribute
*attr
,
7677 const char *buf
, size_t count
)
7682 if (parse_strtoul(buf
, 2, &t
))
7685 tpacpi_disclose_usertask("hwmon pwm1_enable",
7686 "set fan mode to %lu\n", t
);
7690 level
= TP_EC_FAN_FULLSPEED
;
7693 level
= TPACPI_FAN_LAST_LEVEL
;
7696 level
= TP_EC_FAN_AUTO
;
7699 /* reserved for software-controlled auto mode */
7705 res
= fan_set_level_safe(level
);
7711 fan_watchdog_reset();
7716 static struct device_attribute dev_attr_fan_pwm1_enable
=
7717 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7718 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7720 /* sysfs fan pwm1 ------------------------------------------------------ */
7721 static ssize_t
fan_pwm1_show(struct device
*dev
,
7722 struct device_attribute
*attr
,
7728 res
= fan_get_status_safe(&status
);
7733 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7734 status
= fan_control_desired_level
;
7739 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7742 static ssize_t
fan_pwm1_store(struct device
*dev
,
7743 struct device_attribute
*attr
,
7744 const char *buf
, size_t count
)
7748 u8 status
, newlevel
;
7750 if (parse_strtoul(buf
, 255, &s
))
7753 tpacpi_disclose_usertask("hwmon pwm1",
7754 "set fan speed to %lu\n", s
);
7756 /* scale down from 0-255 to 0-7 */
7757 newlevel
= (s
>> 5) & 0x07;
7759 if (mutex_lock_killable(&fan_mutex
))
7760 return -ERESTARTSYS
;
7762 rc
= fan_get_status(&status
);
7763 if (!rc
&& (status
&
7764 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7765 rc
= fan_set_level(newlevel
);
7769 fan_update_desired_level(newlevel
);
7770 fan_watchdog_reset();
7774 mutex_unlock(&fan_mutex
);
7775 return (rc
)? rc
: count
;
7778 static struct device_attribute dev_attr_fan_pwm1
=
7779 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7780 fan_pwm1_show
, fan_pwm1_store
);
7782 /* sysfs fan fan1_input ------------------------------------------------ */
7783 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7784 struct device_attribute
*attr
,
7790 res
= fan_get_speed(&speed
);
7794 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7797 static struct device_attribute dev_attr_fan_fan1_input
=
7798 __ATTR(fan1_input
, S_IRUGO
,
7799 fan_fan1_input_show
, NULL
);
7801 /* sysfs fan fan2_input ------------------------------------------------ */
7802 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7803 struct device_attribute
*attr
,
7809 res
= fan2_get_speed(&speed
);
7813 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7816 static struct device_attribute dev_attr_fan_fan2_input
=
7817 __ATTR(fan2_input
, S_IRUGO
,
7818 fan_fan2_input_show
, NULL
);
7820 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
7821 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
7824 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
7827 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
7828 const char *buf
, size_t count
)
7832 if (parse_strtoul(buf
, 120, &t
))
7835 if (!fan_control_allowed
)
7838 fan_watchdog_maxinterval
= t
;
7839 fan_watchdog_reset();
7841 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
7846 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
7847 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
7849 /* --------------------------------------------------------------------- */
7850 static struct attribute
*fan_attributes
[] = {
7851 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
7852 &dev_attr_fan_fan1_input
.attr
,
7853 NULL
, /* for fan2_input */
7857 static const struct attribute_group fan_attr_group
= {
7858 .attrs
= fan_attributes
,
7861 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
7862 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
7864 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7865 { .vendor = PCI_VENDOR_ID_IBM, \
7866 .bios = TPACPI_MATCH_ANY, \
7867 .ec = TPID(__id1, __id2), \
7868 .quirks = __quirks }
7870 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7871 { .vendor = PCI_VENDOR_ID_LENOVO, \
7872 .bios = TPACPI_MATCH_ANY, \
7873 .ec = TPID(__id1, __id2), \
7874 .quirks = __quirks }
7876 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
7877 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
7878 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
7879 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
7880 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
7881 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
7884 #undef TPACPI_FAN_QL
7885 #undef TPACPI_FAN_QI
7887 static int __init
fan_init(struct ibm_init_struct
*iibm
)
7890 unsigned long quirks
;
7892 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7893 "initializing fan subdriver\n");
7895 mutex_init(&fan_mutex
);
7896 fan_status_access_mode
= TPACPI_FAN_NONE
;
7897 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7898 fan_control_commands
= 0;
7899 fan_watchdog_maxinterval
= 0;
7900 tp_features
.fan_ctrl_status_undef
= 0;
7901 tp_features
.second_fan
= 0;
7902 fan_control_desired_level
= 7;
7904 TPACPI_ACPIHANDLE_INIT(fans
);
7905 TPACPI_ACPIHANDLE_INIT(gfan
);
7906 TPACPI_ACPIHANDLE_INIT(sfan
);
7908 quirks
= tpacpi_check_quirks(fan_quirk_table
,
7909 ARRAY_SIZE(fan_quirk_table
));
7912 /* 570, 600e/x, 770e, 770x */
7913 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7915 /* all other ThinkPads: note that even old-style
7916 * ThinkPad ECs supports the fan control register */
7917 if (likely(acpi_ec_read(fan_status_offset
,
7918 &fan_control_initial_status
))) {
7919 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7920 if (quirks
& TPACPI_FAN_Q1
)
7922 if (quirks
& TPACPI_FAN_2FAN
) {
7923 tp_features
.second_fan
= 1;
7924 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7925 "secondary fan support enabled\n");
7929 "ThinkPad ACPI EC access misbehaving, "
7930 "fan status and control unavailable\n");
7937 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
7938 fan_control_commands
|=
7939 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
7942 /* gfan without sfan means no fan control */
7943 /* all other models implement TP EC 0x2f control */
7947 fan_control_access_mode
=
7948 TPACPI_FAN_WR_ACPI_FANS
;
7949 fan_control_commands
|=
7950 TPACPI_FAN_CMD_SPEED
|
7951 TPACPI_FAN_CMD_LEVEL
|
7952 TPACPI_FAN_CMD_ENABLE
;
7954 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
7955 fan_control_commands
|=
7956 TPACPI_FAN_CMD_LEVEL
|
7957 TPACPI_FAN_CMD_ENABLE
;
7962 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7963 "fan is %s, modes %d, %d\n",
7964 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
7965 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
7966 fan_status_access_mode
, fan_control_access_mode
);
7968 /* fan control master switch */
7969 if (!fan_control_allowed
) {
7970 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7971 fan_control_commands
= 0;
7972 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7973 "fan control features disabled by parameter\n");
7976 /* update fan_control_desired_level */
7977 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
7978 fan_get_status_safe(NULL
);
7980 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
7981 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
7982 if (tp_features
.second_fan
) {
7983 /* attach second fan tachometer */
7984 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
7985 &dev_attr_fan_fan2_input
.attr
;
7987 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7992 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
7993 &driver_attr_fan_watchdog
);
7995 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8004 static void fan_exit(void)
8006 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
8007 "cancelling any pending fan watchdog tasks\n");
8009 /* FIXME: can we really do this unconditionally? */
8010 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
8011 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
8012 &driver_attr_fan_watchdog
);
8014 cancel_delayed_work(&fan_watchdog_task
);
8015 flush_workqueue(tpacpi_wq
);
8018 static void fan_suspend(pm_message_t state
)
8022 if (!fan_control_allowed
)
8025 /* Store fan status in cache */
8026 fan_control_resume_level
= 0;
8027 rc
= fan_get_status_safe(&fan_control_resume_level
);
8029 printk(TPACPI_NOTICE
8030 "failed to read fan level for later "
8031 "restore during resume: %d\n", rc
);
8033 /* if it is undefined, don't attempt to restore it.
8035 if (tp_features
.fan_ctrl_status_undef
)
8036 fan_control_resume_level
= 0;
8039 static void fan_resume(void)
8041 u8 current_level
= 7;
8042 bool do_set
= false;
8045 /* DSDT *always* updates status on resume */
8046 tp_features
.fan_ctrl_status_undef
= 0;
8048 if (!fan_control_allowed
||
8049 !fan_control_resume_level
||
8050 (fan_get_status_safe(¤t_level
) < 0))
8053 switch (fan_control_access_mode
) {
8054 case TPACPI_FAN_WR_ACPI_SFAN
:
8055 /* never decrease fan level */
8056 do_set
= (fan_control_resume_level
> current_level
);
8058 case TPACPI_FAN_WR_ACPI_FANS
:
8059 case TPACPI_FAN_WR_TPEC
:
8060 /* never decrease fan level, scale is:
8061 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
8063 * We expect the firmware to set either 7 or AUTO, but we
8064 * handle FULLSPEED out of paranoia.
8066 * So, we can safely only restore FULLSPEED or 7, anything
8067 * else could slow the fan. Restoring AUTO is useless, at
8068 * best that's exactly what the DSDT already set (it is the
8071 * Always keep in mind that the DSDT *will* have set the
8072 * fans to what the vendor supposes is the best level. We
8073 * muck with it only to speed the fan up.
8075 if (fan_control_resume_level
!= 7 &&
8076 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
8079 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
8080 (current_level
!= fan_control_resume_level
);
8086 printk(TPACPI_NOTICE
8087 "restoring fan level to 0x%02x\n",
8088 fan_control_resume_level
);
8089 rc
= fan_set_level_safe(fan_control_resume_level
);
8091 printk(TPACPI_NOTICE
8092 "failed to restore fan level: %d\n", rc
);
8096 static int fan_read(struct seq_file
*m
)
8100 unsigned int speed
= 0;
8102 switch (fan_status_access_mode
) {
8103 case TPACPI_FAN_RD_ACPI_GFAN
:
8104 /* 570, 600e/x, 770e, 770x */
8105 rc
= fan_get_status_safe(&status
);
8109 seq_printf(m
, "status:\t\t%s\n"
8111 (status
!= 0) ? "enabled" : "disabled", status
);
8114 case TPACPI_FAN_RD_TPEC
:
8115 /* all except 570, 600e/x, 770e, 770x */
8116 rc
= fan_get_status_safe(&status
);
8120 seq_printf(m
, "status:\t\t%s\n",
8121 (status
!= 0) ? "enabled" : "disabled");
8123 rc
= fan_get_speed(&speed
);
8127 seq_printf(m
, "speed:\t\t%d\n", speed
);
8129 if (status
& TP_EC_FAN_FULLSPEED
)
8130 /* Disengaged mode takes precedence */
8131 seq_printf(m
, "level:\t\tdisengaged\n");
8132 else if (status
& TP_EC_FAN_AUTO
)
8133 seq_printf(m
, "level:\t\tauto\n");
8135 seq_printf(m
, "level:\t\t%d\n", status
);
8138 case TPACPI_FAN_NONE
:
8140 seq_printf(m
, "status:\t\tnot supported\n");
8143 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
8144 seq_printf(m
, "commands:\tlevel <level>");
8146 switch (fan_control_access_mode
) {
8147 case TPACPI_FAN_WR_ACPI_SFAN
:
8148 seq_printf(m
, " (<level> is 0-7)\n");
8152 seq_printf(m
, " (<level> is 0-7, "
8153 "auto, disengaged, full-speed)\n");
8158 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
8159 seq_printf(m
, "commands:\tenable, disable\n"
8160 "commands:\twatchdog <timeout> (<timeout> "
8161 "is 0 (off), 1-120 (seconds))\n");
8163 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
8164 seq_printf(m
, "commands:\tspeed <speed>"
8165 " (<speed> is 0-65535)\n");
8170 static int fan_write_cmd_level(const char *cmd
, int *rc
)
8174 if (strlencmp(cmd
, "level auto") == 0)
8175 level
= TP_EC_FAN_AUTO
;
8176 else if ((strlencmp(cmd
, "level disengaged") == 0) |
8177 (strlencmp(cmd
, "level full-speed") == 0))
8178 level
= TP_EC_FAN_FULLSPEED
;
8179 else if (sscanf(cmd
, "level %d", &level
) != 1)
8182 *rc
= fan_set_level_safe(level
);
8184 printk(TPACPI_ERR
"level command accepted for unsupported "
8185 "access mode %d", fan_control_access_mode
);
8187 tpacpi_disclose_usertask("procfs fan",
8188 "set level to %d\n", level
);
8193 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
8195 if (strlencmp(cmd
, "enable") != 0)
8198 *rc
= fan_set_enable();
8200 printk(TPACPI_ERR
"enable command accepted for unsupported "
8201 "access mode %d", fan_control_access_mode
);
8203 tpacpi_disclose_usertask("procfs fan", "enable\n");
8208 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
8210 if (strlencmp(cmd
, "disable") != 0)
8213 *rc
= fan_set_disable();
8215 printk(TPACPI_ERR
"disable command accepted for unsupported "
8216 "access mode %d", fan_control_access_mode
);
8218 tpacpi_disclose_usertask("procfs fan", "disable\n");
8223 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
8228 * Support speed <low> <medium> <high> ? */
8230 if (sscanf(cmd
, "speed %d", &speed
) != 1)
8233 *rc
= fan_set_speed(speed
);
8235 printk(TPACPI_ERR
"speed command accepted for unsupported "
8236 "access mode %d", fan_control_access_mode
);
8238 tpacpi_disclose_usertask("procfs fan",
8239 "set speed to %d\n", speed
);
8244 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
8248 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
8251 if (interval
< 0 || interval
> 120)
8254 fan_watchdog_maxinterval
= interval
;
8255 tpacpi_disclose_usertask("procfs fan",
8256 "set watchdog timer to %d\n",
8263 static int fan_write(char *buf
)
8268 while (!rc
&& (cmd
= next_cmd(&buf
))) {
8269 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
8270 fan_write_cmd_level(cmd
, &rc
)) &&
8271 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
8272 (fan_write_cmd_enable(cmd
, &rc
) ||
8273 fan_write_cmd_disable(cmd
, &rc
) ||
8274 fan_write_cmd_watchdog(cmd
, &rc
))) &&
8275 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
8276 fan_write_cmd_speed(cmd
, &rc
))
8280 fan_watchdog_reset();
8286 static struct ibm_struct fan_driver_data
= {
8291 .suspend
= fan_suspend
,
8292 .resume
= fan_resume
,
8295 /****************************************************************************
8296 ****************************************************************************
8300 ****************************************************************************
8301 ****************************************************************************/
8304 * HKEY event callout for other subdrivers go here
8305 * (yes, it is ugly, but it is quick, safe, and gets the job done
8307 static void tpacpi_driver_event(const unsigned int hkey_event
)
8309 if (ibm_backlight_device
) {
8310 switch (hkey_event
) {
8311 case TP_HKEY_EV_BRGHT_UP
:
8312 case TP_HKEY_EV_BRGHT_DOWN
:
8313 tpacpi_brightness_notify_change();
8317 switch (hkey_event
) {
8318 case TP_HKEY_EV_VOL_UP
:
8319 case TP_HKEY_EV_VOL_DOWN
:
8320 case TP_HKEY_EV_VOL_MUTE
:
8321 volume_alsa_notify_change();
8326 static void hotkey_driver_event(const unsigned int scancode
)
8328 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
8331 /* sysfs name ---------------------------------------------------------- */
8332 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
8333 struct device_attribute
*attr
,
8336 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
8339 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
8340 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
8342 /* --------------------------------------------------------------------- */
8345 static struct proc_dir_entry
*proc_dir
;
8348 * Module and infrastructure proble, init and exit handling
8351 static int force_load
;
8353 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
8354 static const char * __init
str_supported(int is_supported
)
8356 static char text_unsupported
[] __initdata
= "not supported";
8358 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
8360 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
8362 static void ibm_exit(struct ibm_struct
*ibm
)
8364 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
8366 list_del_init(&ibm
->all_drivers
);
8368 if (ibm
->flags
.acpi_notify_installed
) {
8369 dbg_printk(TPACPI_DBG_EXIT
,
8370 "%s: acpi_remove_notify_handler\n", ibm
->name
);
8372 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
8374 dispatch_acpi_notify
);
8375 ibm
->flags
.acpi_notify_installed
= 0;
8376 ibm
->flags
.acpi_notify_installed
= 0;
8379 if (ibm
->flags
.proc_created
) {
8380 dbg_printk(TPACPI_DBG_EXIT
,
8381 "%s: remove_proc_entry\n", ibm
->name
);
8382 remove_proc_entry(ibm
->name
, proc_dir
);
8383 ibm
->flags
.proc_created
= 0;
8386 if (ibm
->flags
.acpi_driver_registered
) {
8387 dbg_printk(TPACPI_DBG_EXIT
,
8388 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
8390 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
8391 kfree(ibm
->acpi
->driver
);
8392 ibm
->acpi
->driver
= NULL
;
8393 ibm
->flags
.acpi_driver_registered
= 0;
8396 if (ibm
->flags
.init_called
&& ibm
->exit
) {
8398 ibm
->flags
.init_called
= 0;
8401 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
8404 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
8407 struct ibm_struct
*ibm
= iibm
->data
;
8408 struct proc_dir_entry
*entry
;
8410 BUG_ON(ibm
== NULL
);
8412 INIT_LIST_HEAD(&ibm
->all_drivers
);
8414 if (ibm
->flags
.experimental
&& !experimental
)
8417 dbg_printk(TPACPI_DBG_INIT
,
8418 "probing for %s\n", ibm
->name
);
8421 ret
= iibm
->init(iibm
);
8423 return 0; /* probe failed */
8427 ibm
->flags
.init_called
= 1;
8431 if (ibm
->acpi
->hid
) {
8432 ret
= register_tpacpi_subdriver(ibm
);
8437 if (ibm
->acpi
->notify
) {
8438 ret
= setup_acpi_notify(ibm
);
8439 if (ret
== -ENODEV
) {
8440 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
8450 dbg_printk(TPACPI_DBG_INIT
,
8451 "%s installed\n", ibm
->name
);
8459 entry
= proc_create_data(ibm
->name
, mode
, proc_dir
,
8460 &dispatch_proc_fops
, ibm
);
8462 printk(TPACPI_ERR
"unable to create proc entry %s\n",
8467 ibm
->flags
.proc_created
= 1;
8470 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
8475 dbg_printk(TPACPI_DBG_INIT
,
8476 "%s: at error exit path with result %d\n",
8480 return (ret
< 0)? ret
: 0;
8485 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
8487 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
8490 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
8491 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
8494 return s
&& strlen(s
) >= 8 &&
8495 tpacpi_is_fw_digit(s
[0]) &&
8496 tpacpi_is_fw_digit(s
[1]) &&
8497 s
[2] == t
&& s
[3] == 'T' &&
8498 tpacpi_is_fw_digit(s
[4]) &&
8499 tpacpi_is_fw_digit(s
[5]) &&
8500 s
[6] == 'W' && s
[7] == 'W';
8503 /* returns 0 - probe ok, or < 0 - probe error.
8504 * Probe ok doesn't mean thinkpad found.
8505 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
8506 static int __must_check __init
get_thinkpad_model_data(
8507 struct thinkpad_id_data
*tp
)
8509 const struct dmi_device
*dev
= NULL
;
8510 char ec_fw_string
[18];
8516 memset(tp
, 0, sizeof(*tp
));
8518 if (dmi_name_in_vendors("IBM"))
8519 tp
->vendor
= PCI_VENDOR_ID_IBM
;
8520 else if (dmi_name_in_vendors("LENOVO"))
8521 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
8525 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
8526 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
8527 if (s
&& !tp
->bios_version_str
)
8530 /* Really ancient ThinkPad 240X will fail this, which is fine */
8531 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
8534 tp
->bios_model
= tp
->bios_version_str
[0]
8535 | (tp
->bios_version_str
[1] << 8);
8536 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
8537 | tp
->bios_version_str
[5];
8540 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
8541 * X32 or newer, all Z series; Some models must have an
8542 * up-to-date BIOS or they will not be detected.
8544 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8546 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
8547 if (sscanf(dev
->name
,
8548 "IBM ThinkPad Embedded Controller -[%17c",
8549 ec_fw_string
) == 1) {
8550 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
8551 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
8553 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
8554 if (!tp
->ec_version_str
)
8557 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
8558 tp
->ec_model
= ec_fw_string
[0]
8559 | (ec_fw_string
[1] << 8);
8560 tp
->ec_release
= (ec_fw_string
[4] << 8)
8563 printk(TPACPI_NOTICE
8564 "ThinkPad firmware release %s "
8565 "doesn't match the known patterns\n",
8567 printk(TPACPI_NOTICE
8568 "please report this to %s\n",
8575 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
8576 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
8577 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
8582 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
8583 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
8584 if (s
&& !tp
->nummodel_str
)
8590 static int __init
probe_for_thinkpad(void)
8598 * Non-ancient models have better DMI tagging, but very old models
8599 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
8601 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
8602 (thinkpad_id
.ec_model
!= 0) ||
8603 tpacpi_is_fw_known();
8605 /* ec is required because many other handles are relative to it */
8606 TPACPI_ACPIHANDLE_INIT(ec
);
8610 "Not yet supported ThinkPad detected!\n");
8614 if (!is_thinkpad
&& !force_load
)
8621 /* Module init, exit, parameters */
8623 static struct ibm_init_struct ibms_init
[] __initdata
= {
8625 .init
= thinkpad_acpi_driver_init
,
8626 .data
= &thinkpad_acpi_driver_data
,
8629 .init
= hotkey_init
,
8630 .data
= &hotkey_driver_data
,
8633 .init
= bluetooth_init
,
8634 .data
= &bluetooth_driver_data
,
8638 .data
= &wan_driver_data
,
8642 .data
= &uwb_driver_data
,
8644 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8647 .data
= &video_driver_data
,
8652 .data
= &light_driver_data
,
8656 .data
= &cmos_driver_data
,
8660 .data
= &led_driver_data
,
8664 .data
= &beep_driver_data
,
8667 .init
= thermal_init
,
8668 .data
= &thermal_driver_data
,
8671 .data
= &ecdump_driver_data
,
8674 .init
= brightness_init
,
8675 .data
= &brightness_driver_data
,
8678 .init
= volume_init
,
8679 .data
= &volume_driver_data
,
8683 .data
= &fan_driver_data
,
8687 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
8690 struct ibm_struct
*ibm
;
8692 if (!kp
|| !kp
->name
|| !val
)
8695 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8696 ibm
= ibms_init
[i
].data
;
8697 WARN_ON(ibm
== NULL
);
8699 if (!ibm
|| !ibm
->name
)
8702 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8703 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8705 strcpy(ibms_init
[i
].param
, val
);
8706 strcat(ibms_init
[i
].param
, ",");
8714 module_param(experimental
, int, 0444);
8715 MODULE_PARM_DESC(experimental
,
8716 "Enables experimental features when non-zero");
8718 module_param_named(debug
, dbg_level
, uint
, 0);
8719 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8721 module_param(force_load
, bool, 0444);
8722 MODULE_PARM_DESC(force_load
,
8723 "Attempts to load the driver even on a "
8724 "mis-identified ThinkPad when true");
8726 module_param_named(fan_control
, fan_control_allowed
, bool, 0444);
8727 MODULE_PARM_DESC(fan_control
,
8728 "Enables setting fan parameters features when true");
8730 module_param_named(brightness_mode
, brightness_mode
, uint
, 0444);
8731 MODULE_PARM_DESC(brightness_mode
,
8732 "Selects brightness control strategy: "
8733 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8735 module_param(brightness_enable
, uint
, 0444);
8736 MODULE_PARM_DESC(brightness_enable
,
8737 "Enables backlight control when 1, disables when 0");
8739 module_param(hotkey_report_mode
, uint
, 0444);
8740 MODULE_PARM_DESC(hotkey_report_mode
,
8741 "used for backwards compatibility with userspace, "
8742 "see documentation");
8744 module_param_named(volume_mode
, volume_mode
, uint
, 0444);
8745 MODULE_PARM_DESC(volume_mode
,
8746 "Selects volume control strategy: "
8747 "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM");
8749 module_param_named(volume_capabilities
, volume_capabilities
, uint
, 0444);
8750 MODULE_PARM_DESC(volume_capabilities
,
8751 "Selects the mixer capabilites: "
8752 "0=auto, 1=volume and mute, 2=mute only");
8754 module_param_named(volume_control
, volume_control_allowed
, bool, 0444);
8755 MODULE_PARM_DESC(volume_control
,
8756 "Enables software override for the console audio "
8757 "control when true");
8759 /* ALSA module API parameters */
8760 module_param_named(index
, alsa_index
, int, 0444);
8761 MODULE_PARM_DESC(index
, "ALSA index for the ACPI EC Mixer");
8762 module_param_named(id
, alsa_id
, charp
, 0444);
8763 MODULE_PARM_DESC(id
, "ALSA id for the ACPI EC Mixer");
8764 module_param_named(enable
, alsa_enable
, bool, 0444);
8765 MODULE_PARM_DESC(enable
, "Enable the ALSA interface for the ACPI EC Mixer");
8767 #define TPACPI_PARAM(feature) \
8768 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8769 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8770 "at module load, see documentation")
8772 TPACPI_PARAM(hotkey
);
8773 TPACPI_PARAM(bluetooth
);
8774 TPACPI_PARAM(video
);
8775 TPACPI_PARAM(light
);
8779 TPACPI_PARAM(ecdump
);
8780 TPACPI_PARAM(brightness
);
8781 TPACPI_PARAM(volume
);
8784 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8785 module_param(dbg_wlswemul
, uint
, 0444);
8786 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
8787 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
8788 MODULE_PARM_DESC(wlsw_state
,
8789 "Initial state of the emulated WLSW switch");
8791 module_param(dbg_bluetoothemul
, uint
, 0444);
8792 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
8793 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
8794 MODULE_PARM_DESC(bluetooth_state
,
8795 "Initial state of the emulated bluetooth switch");
8797 module_param(dbg_wwanemul
, uint
, 0444);
8798 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
8799 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
8800 MODULE_PARM_DESC(wwan_state
,
8801 "Initial state of the emulated WWAN switch");
8803 module_param(dbg_uwbemul
, uint
, 0444);
8804 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
8805 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
8806 MODULE_PARM_DESC(uwb_state
,
8807 "Initial state of the emulated UWB switch");
8810 static void thinkpad_acpi_module_exit(void)
8812 struct ibm_struct
*ibm
, *itmp
;
8814 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
8816 list_for_each_entry_safe_reverse(ibm
, itmp
,
8817 &tpacpi_all_drivers
,
8822 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
8824 if (tpacpi_inputdev
) {
8825 if (tp_features
.input_device_registered
)
8826 input_unregister_device(tpacpi_inputdev
);
8828 input_free_device(tpacpi_inputdev
);
8832 hwmon_device_unregister(tpacpi_hwmon
);
8834 if (tp_features
.sensors_pdev_attrs_registered
)
8835 device_remove_file(&tpacpi_sensors_pdev
->dev
,
8836 &dev_attr_thinkpad_acpi_pdev_name
);
8837 if (tpacpi_sensors_pdev
)
8838 platform_device_unregister(tpacpi_sensors_pdev
);
8840 platform_device_unregister(tpacpi_pdev
);
8842 if (tp_features
.sensors_pdrv_attrs_registered
)
8843 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
8844 if (tp_features
.platform_drv_attrs_registered
)
8845 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
8847 if (tp_features
.sensors_pdrv_registered
)
8848 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
8850 if (tp_features
.platform_drv_registered
)
8851 platform_driver_unregister(&tpacpi_pdriver
);
8854 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
8857 destroy_workqueue(tpacpi_wq
);
8859 kfree(thinkpad_id
.bios_version_str
);
8860 kfree(thinkpad_id
.ec_version_str
);
8861 kfree(thinkpad_id
.model_str
);
8865 static int __init
thinkpad_acpi_module_init(void)
8869 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
8871 /* Parameter checking */
8872 if (hotkey_report_mode
> 2)
8875 /* Driver-level probe */
8877 ret
= get_thinkpad_model_data(&thinkpad_id
);
8880 "unable to get DMI data: %d\n", ret
);
8881 thinkpad_acpi_module_exit();
8884 ret
= probe_for_thinkpad();
8886 thinkpad_acpi_module_exit();
8890 /* Driver initialization */
8892 TPACPI_ACPIHANDLE_INIT(ecrd
);
8893 TPACPI_ACPIHANDLE_INIT(ecwr
);
8895 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
8897 thinkpad_acpi_module_exit();
8901 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
8904 "unable to create proc dir " TPACPI_PROC_DIR
);
8905 thinkpad_acpi_module_exit();
8909 ret
= platform_driver_register(&tpacpi_pdriver
);
8912 "unable to register main platform driver\n");
8913 thinkpad_acpi_module_exit();
8916 tp_features
.platform_drv_registered
= 1;
8918 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
8921 "unable to register hwmon platform driver\n");
8922 thinkpad_acpi_module_exit();
8925 tp_features
.sensors_pdrv_registered
= 1;
8927 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
8929 tp_features
.platform_drv_attrs_registered
= 1;
8930 ret
= tpacpi_create_driver_attributes(
8931 &tpacpi_hwmon_pdriver
.driver
);
8935 "unable to create sysfs driver attributes\n");
8936 thinkpad_acpi_module_exit();
8939 tp_features
.sensors_pdrv_attrs_registered
= 1;
8942 /* Device initialization */
8943 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
8945 if (IS_ERR(tpacpi_pdev
)) {
8946 ret
= PTR_ERR(tpacpi_pdev
);
8948 printk(TPACPI_ERR
"unable to register platform device\n");
8949 thinkpad_acpi_module_exit();
8952 tpacpi_sensors_pdev
= platform_device_register_simple(
8953 TPACPI_HWMON_DRVR_NAME
,
8955 if (IS_ERR(tpacpi_sensors_pdev
)) {
8956 ret
= PTR_ERR(tpacpi_sensors_pdev
);
8957 tpacpi_sensors_pdev
= NULL
;
8959 "unable to register hwmon platform device\n");
8960 thinkpad_acpi_module_exit();
8963 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
8964 &dev_attr_thinkpad_acpi_pdev_name
);
8967 "unable to create sysfs hwmon device attributes\n");
8968 thinkpad_acpi_module_exit();
8971 tp_features
.sensors_pdev_attrs_registered
= 1;
8972 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
8973 if (IS_ERR(tpacpi_hwmon
)) {
8974 ret
= PTR_ERR(tpacpi_hwmon
);
8975 tpacpi_hwmon
= NULL
;
8976 printk(TPACPI_ERR
"unable to register hwmon device\n");
8977 thinkpad_acpi_module_exit();
8980 mutex_init(&tpacpi_inputdev_send_mutex
);
8981 tpacpi_inputdev
= input_allocate_device();
8982 if (!tpacpi_inputdev
) {
8983 printk(TPACPI_ERR
"unable to allocate input device\n");
8984 thinkpad_acpi_module_exit();
8987 /* Prepare input device, but don't register */
8988 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
8989 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
8990 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
8991 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
8992 thinkpad_id
.vendor
:
8994 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
8995 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
8996 tpacpi_inputdev
->dev
.parent
= &tpacpi_pdev
->dev
;
8998 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8999 ret
= ibm_init(&ibms_init
[i
]);
9000 if (ret
>= 0 && *ibms_init
[i
].param
)
9001 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
9003 thinkpad_acpi_module_exit();
9007 ret
= input_register_device(tpacpi_inputdev
);
9009 printk(TPACPI_ERR
"unable to register input device\n");
9010 thinkpad_acpi_module_exit();
9013 tp_features
.input_device_registered
= 1;
9016 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
9020 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
9023 * This will autoload the driver in almost every ThinkPad
9024 * in widespread use.
9026 * Only _VERY_ old models, like the 240, 240x and 570 lack
9027 * the HKEY event interface.
9029 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
9032 * DMI matching for module autoloading
9034 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
9035 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
9037 * Only models listed in thinkwiki will be supported, so add yours
9038 * if it is not there yet.
9040 #define IBM_BIOS_MODULE_ALIAS(__type) \
9041 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
9043 /* Ancient thinkpad BIOSes have to be identified by
9044 * BIOS type or model number, and there are far less
9045 * BIOS types than model numbers... */
9046 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
9048 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
9049 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
9050 MODULE_DESCRIPTION(TPACPI_DESC
);
9051 MODULE_VERSION(TPACPI_VERSION
);
9052 MODULE_LICENSE("GPL");
9054 module_init(thinkpad_acpi_module_init
);
9055 module_exit(thinkpad_acpi_module_exit
);