2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define TPACPI_VERSION "0.24"
25 #define TPACPI_SYSFS_VERSION 0x020700
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/sched.h>
58 #include <linux/kthread.h>
59 #include <linux/freezer.h>
60 #include <linux/delay.h>
61 #include <linux/slab.h>
63 #include <linux/nvram.h>
64 #include <linux/proc_fs.h>
65 #include <linux/seq_file.h>
66 #include <linux/sysfs.h>
67 #include <linux/backlight.h>
69 #include <linux/platform_device.h>
70 #include <linux/hwmon.h>
71 #include <linux/hwmon-sysfs.h>
72 #include <linux/input.h>
73 #include <linux/leds.h>
74 #include <linux/rfkill.h>
75 #include <asm/uaccess.h>
77 #include <linux/dmi.h>
78 #include <linux/jiffies.h>
79 #include <linux/workqueue.h>
81 #include <sound/core.h>
82 #include <sound/control.h>
83 #include <sound/initval.h>
85 #include <acpi/acpi_drivers.h>
87 #include <linux/pci_ids.h>
90 /* ThinkPad CMOS commands */
91 #define TP_CMOS_VOLUME_DOWN 0
92 #define TP_CMOS_VOLUME_UP 1
93 #define TP_CMOS_VOLUME_MUTE 2
94 #define TP_CMOS_BRIGHTNESS_UP 4
95 #define TP_CMOS_BRIGHTNESS_DOWN 5
96 #define TP_CMOS_THINKLIGHT_ON 12
97 #define TP_CMOS_THINKLIGHT_OFF 13
101 TP_NVRAM_ADDR_HK2
= 0x57,
102 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
103 TP_NVRAM_ADDR_VIDEO
= 0x59,
104 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
105 TP_NVRAM_ADDR_MIXER
= 0x60,
108 /* NVRAM bit masks */
110 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
111 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
112 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
113 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
114 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
115 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
116 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
117 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
118 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
119 TP_NVRAM_MASK_MUTE
= 0x40,
120 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
121 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
122 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
126 #define TPACPI_ACPI_HKEY_HID "IBM0068"
129 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
130 #define TPACPI_HKEY_INPUT_VERSION 0x4101
132 /* ACPI \WGSV commands */
134 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
135 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
136 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
137 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
140 /* TP_ACPI_WGSV_GET_STATE bits */
142 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
143 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
144 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
145 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
146 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
147 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
148 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
149 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
150 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
151 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
155 enum tpacpi_hkey_event_t
{
157 TP_HKEY_EV_HOTKEY_BASE
= 0x1001, /* first hotkey (FN+F1) */
158 TP_HKEY_EV_BRGHT_UP
= 0x1010, /* Brightness up */
159 TP_HKEY_EV_BRGHT_DOWN
= 0x1011, /* Brightness down */
160 TP_HKEY_EV_VOL_UP
= 0x1015, /* Volume up or unmute */
161 TP_HKEY_EV_VOL_DOWN
= 0x1016, /* Volume down or unmute */
162 TP_HKEY_EV_VOL_MUTE
= 0x1017, /* Mixer output mute */
164 /* Reasons for waking up from S3/S4 */
165 TP_HKEY_EV_WKUP_S3_UNDOCK
= 0x2304, /* undock requested, S3 */
166 TP_HKEY_EV_WKUP_S4_UNDOCK
= 0x2404, /* undock requested, S4 */
167 TP_HKEY_EV_WKUP_S3_BAYEJ
= 0x2305, /* bay ejection req, S3 */
168 TP_HKEY_EV_WKUP_S4_BAYEJ
= 0x2405, /* bay ejection req, S4 */
169 TP_HKEY_EV_WKUP_S3_BATLOW
= 0x2313, /* battery empty, S3 */
170 TP_HKEY_EV_WKUP_S4_BATLOW
= 0x2413, /* battery empty, S4 */
172 /* Auto-sleep after eject request */
173 TP_HKEY_EV_BAYEJ_ACK
= 0x3003, /* bay ejection complete */
174 TP_HKEY_EV_UNDOCK_ACK
= 0x4003, /* undock complete */
176 /* Misc bay events */
177 TP_HKEY_EV_OPTDRV_EJ
= 0x3006, /* opt. drive tray ejected */
179 /* User-interface events */
180 TP_HKEY_EV_LID_CLOSE
= 0x5001, /* laptop lid closed */
181 TP_HKEY_EV_LID_OPEN
= 0x5002, /* laptop lid opened */
182 TP_HKEY_EV_TABLET_TABLET
= 0x5009, /* tablet swivel up */
183 TP_HKEY_EV_TABLET_NOTEBOOK
= 0x500a, /* tablet swivel down */
184 TP_HKEY_EV_PEN_INSERTED
= 0x500b, /* tablet pen inserted */
185 TP_HKEY_EV_PEN_REMOVED
= 0x500c, /* tablet pen removed */
186 TP_HKEY_EV_BRGHT_CHANGED
= 0x5010, /* backlight control event */
189 TP_HKEY_EV_ALARM_BAT_HOT
= 0x6011, /* battery too hot */
190 TP_HKEY_EV_ALARM_BAT_XHOT
= 0x6012, /* battery critically hot */
191 TP_HKEY_EV_ALARM_SENSOR_HOT
= 0x6021, /* sensor too hot */
192 TP_HKEY_EV_ALARM_SENSOR_XHOT
= 0x6022, /* sensor critically hot */
193 TP_HKEY_EV_THM_TABLE_CHANGED
= 0x6030, /* thermal table changed */
196 TP_HKEY_EV_RFKILL_CHANGED
= 0x7000, /* rfkill switch changed */
199 /****************************************************************************
203 #define TPACPI_NAME "thinkpad"
204 #define TPACPI_DESC "ThinkPad ACPI Extras"
205 #define TPACPI_FILE TPACPI_NAME "_acpi"
206 #define TPACPI_URL "http://ibm-acpi.sf.net/"
207 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
209 #define TPACPI_PROC_DIR "ibm"
210 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
211 #define TPACPI_DRVR_NAME TPACPI_FILE
212 #define TPACPI_DRVR_SHORTNAME "tpacpi"
213 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
215 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
216 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
218 #define TPACPI_MAX_ACPI_ARGS 3
221 #define TPACPI_LOG TPACPI_FILE ": "
222 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
223 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
224 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
225 #define TPACPI_ERR KERN_ERR TPACPI_LOG
226 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
227 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
228 #define TPACPI_INFO KERN_INFO TPACPI_LOG
229 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
231 /* Debugging printk groups */
232 #define TPACPI_DBG_ALL 0xffff
233 #define TPACPI_DBG_DISCLOSETASK 0x8000
234 #define TPACPI_DBG_INIT 0x0001
235 #define TPACPI_DBG_EXIT 0x0002
236 #define TPACPI_DBG_RFKILL 0x0004
237 #define TPACPI_DBG_HKEY 0x0008
238 #define TPACPI_DBG_FAN 0x0010
239 #define TPACPI_DBG_BRGHT 0x0020
240 #define TPACPI_DBG_MIXER 0x0040
242 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
243 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
244 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
247 /****************************************************************************
248 * Driver-wide structs and misc. variables
253 struct tp_acpi_drv_struct
{
254 const struct acpi_device_id
*hid
;
255 struct acpi_driver
*driver
;
257 void (*notify
) (struct ibm_struct
*, u32
);
260 struct acpi_device
*device
;
266 int (*read
) (struct seq_file
*);
267 int (*write
) (char *);
269 void (*resume
) (void);
270 void (*suspend
) (pm_message_t state
);
271 void (*shutdown
) (void);
273 struct list_head all_drivers
;
275 struct tp_acpi_drv_struct
*acpi
;
278 u8 acpi_driver_registered
:1;
279 u8 acpi_notify_installed
:1;
286 struct ibm_init_struct
{
289 int (*init
) (struct ibm_init_struct
*);
290 mode_t base_procfs_mode
;
291 struct ibm_struct
*data
;
302 u32 bright_16levels
:1;
303 u32 bright_acpimode
:1;
306 u32 fan_ctrl_status_undef
:1;
308 u32 beep_needs_two_args
:1;
309 u32 mixer_no_level_control
:1;
310 u32 input_device_registered
:1;
311 u32 platform_drv_registered
:1;
312 u32 platform_drv_attrs_registered
:1;
313 u32 sensors_pdrv_registered
:1;
314 u32 sensors_pdrv_attrs_registered
:1;
315 u32 sensors_pdev_attrs_registered
:1;
316 u32 hotkey_poll_active
:1;
320 u16 hotkey_mask_ff
:1;
321 u16 volume_ctrl_forbidden
:1;
324 struct thinkpad_id_data
{
325 unsigned int vendor
; /* ThinkPad vendor:
326 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
328 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
329 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
331 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
333 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
336 char *model_str
; /* ThinkPad T43 */
337 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
339 static struct thinkpad_id_data thinkpad_id
;
342 TPACPI_LIFE_INIT
= 0,
347 static int experimental
;
348 static u32 dbg_level
;
350 static struct workqueue_struct
*tpacpi_wq
;
358 /* Special LED class that can defer work */
359 struct tpacpi_led_classdev
{
360 struct led_classdev led_classdev
;
361 struct work_struct work
;
362 enum led_status_t new_state
;
366 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
367 static int dbg_wlswemul
;
368 static int tpacpi_wlsw_emulstate
;
369 static int dbg_bluetoothemul
;
370 static int tpacpi_bluetooth_emulstate
;
371 static int dbg_wwanemul
;
372 static int tpacpi_wwan_emulstate
;
373 static int dbg_uwbemul
;
374 static int tpacpi_uwb_emulstate
;
378 /*************************************************************************
382 #define dbg_printk(a_dbg_level, format, arg...) \
383 do { if (dbg_level & (a_dbg_level)) \
384 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
387 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
388 #define vdbg_printk dbg_printk
389 static const char *str_supported(int is_supported
);
391 #define vdbg_printk(a_dbg_level, format, arg...) \
395 static void tpacpi_log_usertask(const char * const what
)
397 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
398 what
, task_tgid_vnr(current
));
401 #define tpacpi_disclose_usertask(what, format, arg...) \
404 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
405 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
406 printk(TPACPI_DEBUG "%s: PID %d: " format, \
407 what, task_tgid_vnr(current), ## arg); \
412 * Quirk handling helpers
414 * ThinkPad IDs and versions seen in the field so far
415 * are two-characters from the set [0-9A-Z], i.e. base 36.
417 * We use values well outside that range as specials.
420 #define TPACPI_MATCH_ANY 0xffffU
421 #define TPACPI_MATCH_UNKNOWN 0U
423 /* TPID('1', 'Y') == 0x5931 */
424 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
426 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
427 { .vendor = PCI_VENDOR_ID_IBM, \
428 .bios = TPID(__id1, __id2), \
429 .ec = TPACPI_MATCH_ANY, \
430 .quirks = (__quirk) }
432 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
433 { .vendor = PCI_VENDOR_ID_LENOVO, \
434 .bios = TPID(__id1, __id2), \
435 .ec = TPACPI_MATCH_ANY, \
436 .quirks = (__quirk) }
438 #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \
439 { .vendor = PCI_VENDOR_ID_LENOVO, \
440 .bios = TPACPI_MATCH_ANY, \
441 .ec = TPID(__id1, __id2), \
442 .quirks = (__quirk) }
444 struct tpacpi_quirk
{
448 unsigned long quirks
;
452 * tpacpi_check_quirks() - search BIOS/EC version on a list
453 * @qlist: array of &struct tpacpi_quirk
454 * @qlist_size: number of elements in @qlist
456 * Iterates over a quirks list until one is found that matches the
457 * ThinkPad's vendor, BIOS and EC model.
459 * Returns 0 if nothing matches, otherwise returns the quirks field of
460 * the matching &struct tpacpi_quirk entry.
462 * The match criteria is: vendor, ec and bios much match.
464 static unsigned long __init
tpacpi_check_quirks(
465 const struct tpacpi_quirk
*qlist
,
466 unsigned int qlist_size
)
469 if ((qlist
->vendor
== thinkpad_id
.vendor
||
470 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
471 (qlist
->bios
== thinkpad_id
.bios_model
||
472 qlist
->bios
== TPACPI_MATCH_ANY
) &&
473 (qlist
->ec
== thinkpad_id
.ec_model
||
474 qlist
->ec
== TPACPI_MATCH_ANY
))
475 return qlist
->quirks
;
484 /****************************************************************************
485 ****************************************************************************
487 * ACPI Helpers and device model
489 ****************************************************************************
490 ****************************************************************************/
492 /*************************************************************************
496 static acpi_handle root_handle
;
498 #define TPACPI_HANDLE(object, parent, paths...) \
499 static acpi_handle object##_handle; \
500 static acpi_handle *object##_parent = &parent##_handle; \
501 static char *object##_path; \
502 static char *object##_paths[] = { paths }
504 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
505 "\\_SB.PCI.ISA.EC", /* 570 */
506 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
507 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
508 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
509 "\\_SB.PCI0.ICH3.EC0", /* R31 */
510 "\\_SB.PCI0.LPC.EC", /* all others */
513 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
514 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
516 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
518 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
519 "\\CMS", /* R40, R40e */
522 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
523 "^HKEY", /* R30, R31 */
524 "HKEY", /* all others */
527 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
528 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
529 "\\_SB.PCI0.VID0", /* 770e */
530 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
531 "\\_SB.PCI0.AGP.VID", /* all others */
535 /*************************************************************************
539 static int acpi_evalf(acpi_handle handle
,
540 void *res
, char *method
, char *fmt
, ...)
543 struct acpi_object_list params
;
544 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
545 struct acpi_buffer result
, *resultp
;
546 union acpi_object out_obj
;
554 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
567 params
.pointer
= &in_objs
[0];
574 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
575 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
577 /* add more types as needed */
579 printk(TPACPI_ERR
"acpi_evalf() called "
580 "with invalid format character '%c'\n", c
);
586 if (res_type
!= 'v') {
587 result
.length
= sizeof(out_obj
);
588 result
.pointer
= &out_obj
;
593 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
598 *(int *)res
= out_obj
.integer
.value
;
599 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
602 success
= status
== AE_OK
;
604 /* add more types as needed */
606 printk(TPACPI_ERR
"acpi_evalf() called "
607 "with invalid format character '%c'\n", res_type
);
611 if (!success
&& !quiet
)
612 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
613 method
, fmt0
, status
);
618 static int acpi_ec_read(int i
, u8
*p
)
623 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
627 if (ec_read(i
, p
) < 0)
634 static int acpi_ec_write(int i
, u8 v
)
637 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
640 if (ec_write(i
, v
) < 0)
647 static int issue_thinkpad_cmos_command(int cmos_cmd
)
652 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
658 /*************************************************************************
662 #define TPACPI_ACPIHANDLE_INIT(object) \
663 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
664 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
666 static void drv_acpi_handle_init(char *name
,
667 acpi_handle
*handle
, acpi_handle parent
,
668 char **paths
, int num_paths
, char **path
)
673 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
676 for (i
= 0; i
< num_paths
; i
++) {
677 status
= acpi_get_handle(parent
, paths
[i
], handle
);
678 if (ACPI_SUCCESS(status
)) {
680 dbg_printk(TPACPI_DBG_INIT
,
681 "Found ACPI handle %s for %s\n",
687 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
692 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
694 struct ibm_struct
*ibm
= data
;
696 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
699 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
702 ibm
->acpi
->notify(ibm
, event
);
705 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
712 if (!*ibm
->acpi
->handle
)
715 vdbg_printk(TPACPI_DBG_INIT
,
716 "setting up ACPI notify for %s\n", ibm
->name
);
718 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
720 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
725 ibm
->acpi
->device
->driver_data
= ibm
;
726 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
727 TPACPI_ACPI_EVENT_PREFIX
,
730 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
731 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
732 if (ACPI_FAILURE(status
)) {
733 if (status
== AE_ALREADY_EXISTS
) {
735 "another device driver is already "
736 "handling %s events\n", ibm
->name
);
739 "acpi_install_notify_handler(%s) failed: %d\n",
744 ibm
->flags
.acpi_notify_installed
= 1;
748 static int __init
tpacpi_device_add(struct acpi_device
*device
)
753 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
757 dbg_printk(TPACPI_DBG_INIT
,
758 "registering %s as an ACPI driver\n", ibm
->name
);
762 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
763 if (!ibm
->acpi
->driver
) {
765 "failed to allocate memory for ibm->acpi->driver\n");
769 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
770 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
772 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
774 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
776 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
778 kfree(ibm
->acpi
->driver
);
779 ibm
->acpi
->driver
= NULL
;
781 ibm
->flags
.acpi_driver_registered
= 1;
787 /****************************************************************************
788 ****************************************************************************
792 ****************************************************************************
793 ****************************************************************************/
795 static int dispatch_proc_show(struct seq_file
*m
, void *v
)
797 struct ibm_struct
*ibm
= m
->private;
799 if (!ibm
|| !ibm
->read
)
804 static int dispatch_proc_open(struct inode
*inode
, struct file
*file
)
806 return single_open(file
, dispatch_proc_show
, PDE(inode
)->data
);
809 static ssize_t
dispatch_proc_write(struct file
*file
,
810 const char __user
*userbuf
,
811 size_t count
, loff_t
*pos
)
813 struct ibm_struct
*ibm
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
817 if (!ibm
|| !ibm
->write
)
819 if (count
> PAGE_SIZE
- 2)
822 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
826 if (copy_from_user(kernbuf
, userbuf
, count
)) {
832 strcat(kernbuf
, ",");
833 ret
= ibm
->write(kernbuf
);
842 static const struct file_operations dispatch_proc_fops
= {
843 .owner
= THIS_MODULE
,
844 .open
= dispatch_proc_open
,
847 .release
= single_release
,
848 .write
= dispatch_proc_write
,
851 static char *next_cmd(char **cmds
)
856 while ((end
= strchr(start
, ',')) && end
== start
)
868 /****************************************************************************
869 ****************************************************************************
871 * Device model: input, hwmon and platform
873 ****************************************************************************
874 ****************************************************************************/
876 static struct platform_device
*tpacpi_pdev
;
877 static struct platform_device
*tpacpi_sensors_pdev
;
878 static struct device
*tpacpi_hwmon
;
879 static struct input_dev
*tpacpi_inputdev
;
880 static struct mutex tpacpi_inputdev_send_mutex
;
881 static LIST_HEAD(tpacpi_all_drivers
);
883 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
886 struct ibm_struct
*ibm
, *itmp
;
888 list_for_each_entry_safe(ibm
, itmp
,
892 (ibm
->suspend
)(state
);
898 static int tpacpi_resume_handler(struct platform_device
*pdev
)
900 struct ibm_struct
*ibm
, *itmp
;
902 list_for_each_entry_safe(ibm
, itmp
,
912 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
914 struct ibm_struct
*ibm
, *itmp
;
916 list_for_each_entry_safe(ibm
, itmp
,
924 static struct platform_driver tpacpi_pdriver
= {
926 .name
= TPACPI_DRVR_NAME
,
927 .owner
= THIS_MODULE
,
929 .suspend
= tpacpi_suspend_handler
,
930 .resume
= tpacpi_resume_handler
,
931 .shutdown
= tpacpi_shutdown_handler
,
934 static struct platform_driver tpacpi_hwmon_pdriver
= {
936 .name
= TPACPI_HWMON_DRVR_NAME
,
937 .owner
= THIS_MODULE
,
941 /*************************************************************************
942 * sysfs support helpers
945 struct attribute_set
{
946 unsigned int members
, max_members
;
947 struct attribute_group group
;
950 struct attribute_set_obj
{
951 struct attribute_set s
;
953 } __attribute__((packed
));
955 static struct attribute_set
*create_attr_set(unsigned int max_members
,
958 struct attribute_set_obj
*sobj
;
960 if (max_members
== 0)
963 /* Allocates space for implicit NULL at the end too */
964 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
965 max_members
* sizeof(struct attribute
*),
969 sobj
->s
.max_members
= max_members
;
970 sobj
->s
.group
.attrs
= &sobj
->a
;
971 sobj
->s
.group
.name
= name
;
976 #define destroy_attr_set(_set) \
979 /* not multi-threaded safe, use it in a single thread per set */
980 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
985 if (s
->members
>= s
->max_members
)
988 s
->group
.attrs
[s
->members
] = attr
;
994 static int add_many_to_attr_set(struct attribute_set
*s
,
995 struct attribute
**attr
,
1000 for (i
= 0; i
< count
; i
++) {
1001 res
= add_to_attr_set(s
, attr
[i
]);
1009 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
1011 sysfs_remove_group(kobj
, &s
->group
);
1012 destroy_attr_set(s
);
1015 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
1016 sysfs_create_group(_kobj, &_attr_set->group)
1018 static int parse_strtoul(const char *buf
,
1019 unsigned long max
, unsigned long *value
)
1023 *value
= simple_strtoul(skip_spaces(buf
), &endp
, 0);
1024 endp
= skip_spaces(endp
);
1025 if (*endp
|| *value
> max
)
1031 static void tpacpi_disable_brightness_delay(void)
1033 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
1034 printk(TPACPI_NOTICE
1035 "ACPI backlight control delay disabled\n");
1038 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
1040 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1041 union acpi_object
*obj
;
1044 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
1045 obj
= (union acpi_object
*)buffer
.pointer
;
1046 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
1047 printk(TPACPI_ERR
"Unknown _BCL data, "
1048 "please report this to %s\n", TPACPI_MAIL
);
1051 rc
= obj
->package
.count
;
1057 kfree(buffer
.pointer
);
1061 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1062 u32 lvl
, void *context
, void **rv
)
1064 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1065 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1067 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1068 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1069 BUG_ON(!rv
|| !*rv
);
1070 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1071 return AE_CTRL_TERMINATE
;
1078 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1080 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1084 void *bcl_ptr
= &bcl_levels
;
1087 TPACPI_ACPIHANDLE_INIT(vid
);
1093 * Search for a _BCL method, and execute it. This is safe on all
1094 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1095 * BIOS in ACPI backlight control mode. We do NOT have to care
1096 * about calling the _BCL method in an enabled video device, any
1097 * will do for our purposes.
1100 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1101 tpacpi_acpi_walk_find_bcl
, NULL
, NULL
,
1104 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1105 tp_features
.bright_acpimode
= 1;
1106 return (bcl_levels
- 2);
1112 static void printk_deprecated_attribute(const char * const what
,
1113 const char * const details
)
1115 tpacpi_log_usertask("deprecated sysfs attribute");
1116 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1117 "will be removed. %s\n",
1121 /*************************************************************************
1122 * rfkill and radio control support helpers
1126 * ThinkPad-ACPI firmware handling model:
1128 * WLSW (master wireless switch) is event-driven, and is common to all
1129 * firmware-controlled radios. It cannot be controlled, just monitored,
1130 * as expected. It overrides all radio state in firmware
1132 * The kernel, a masked-off hotkey, and WLSW can change the radio state
1133 * (TODO: verify how WLSW interacts with the returned radio state).
1135 * The only time there are shadow radio state changes, is when
1136 * masked-off hotkeys are used.
1140 * Internal driver API for radio state:
1142 * int: < 0 = error, otherwise enum tpacpi_rfkill_state
1143 * bool: true means radio blocked (off)
1145 enum tpacpi_rfkill_state
{
1146 TPACPI_RFK_RADIO_OFF
= 0,
1150 /* rfkill switches */
1151 enum tpacpi_rfk_id
{
1152 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
1153 TPACPI_RFK_WWAN_SW_ID
,
1154 TPACPI_RFK_UWB_SW_ID
,
1158 static const char *tpacpi_rfkill_names
[] = {
1159 [TPACPI_RFK_BLUETOOTH_SW_ID
] = "bluetooth",
1160 [TPACPI_RFK_WWAN_SW_ID
] = "wwan",
1161 [TPACPI_RFK_UWB_SW_ID
] = "uwb",
1162 [TPACPI_RFK_SW_MAX
] = NULL
1165 /* ThinkPad-ACPI rfkill subdriver */
1167 struct rfkill
*rfkill
;
1168 enum tpacpi_rfk_id id
;
1169 const struct tpacpi_rfk_ops
*ops
;
1172 struct tpacpi_rfk_ops
{
1173 /* firmware interface */
1174 int (*get_status
)(void);
1175 int (*set_status
)(const enum tpacpi_rfkill_state
);
1178 static struct tpacpi_rfk
*tpacpi_rfkill_switches
[TPACPI_RFK_SW_MAX
];
1180 /* Query FW and update rfkill sw state for a given rfkill switch */
1181 static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk
*tp_rfk
)
1188 status
= (tp_rfk
->ops
->get_status
)();
1192 rfkill_set_sw_state(tp_rfk
->rfkill
,
1193 (status
== TPACPI_RFK_RADIO_OFF
));
1198 /* Query FW and update rfkill sw state for all rfkill switches */
1199 static void tpacpi_rfk_update_swstate_all(void)
1203 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++)
1204 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[i
]);
1208 * Sync the HW-blocking state of all rfkill switches,
1209 * do notice it causes the rfkill core to schedule uevents
1211 static void tpacpi_rfk_update_hwblock_state(bool blocked
)
1214 struct tpacpi_rfk
*tp_rfk
;
1216 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++) {
1217 tp_rfk
= tpacpi_rfkill_switches
[i
];
1219 if (rfkill_set_hw_state(tp_rfk
->rfkill
,
1221 /* ignore -- we track sw block */
1227 /* Call to get the WLSW state from the firmware */
1228 static int hotkey_get_wlsw(void);
1230 /* Call to query WLSW state and update all rfkill switches */
1231 static bool tpacpi_rfk_check_hwblock_state(void)
1233 int res
= hotkey_get_wlsw();
1236 /* When unknown or unsupported, we have to assume it is unblocked */
1240 hw_blocked
= (res
== TPACPI_RFK_RADIO_OFF
);
1241 tpacpi_rfk_update_hwblock_state(hw_blocked
);
1246 static int tpacpi_rfk_hook_set_block(void *data
, bool blocked
)
1248 struct tpacpi_rfk
*tp_rfk
= data
;
1251 dbg_printk(TPACPI_DBG_RFKILL
,
1252 "request to change radio state to %s\n",
1253 blocked
? "blocked" : "unblocked");
1255 /* try to set radio state */
1256 res
= (tp_rfk
->ops
->set_status
)(blocked
?
1257 TPACPI_RFK_RADIO_OFF
: TPACPI_RFK_RADIO_ON
);
1259 /* and update the rfkill core with whatever the FW really did */
1260 tpacpi_rfk_update_swstate(tp_rfk
);
1262 return (res
< 0) ? res
: 0;
1265 static const struct rfkill_ops tpacpi_rfk_rfkill_ops
= {
1266 .set_block
= tpacpi_rfk_hook_set_block
,
1269 static int __init
tpacpi_new_rfkill(const enum tpacpi_rfk_id id
,
1270 const struct tpacpi_rfk_ops
*tp_rfkops
,
1271 const enum rfkill_type rfktype
,
1273 const bool set_default
)
1275 struct tpacpi_rfk
*atp_rfk
;
1277 bool sw_state
= false;
1281 BUG_ON(id
>= TPACPI_RFK_SW_MAX
|| tpacpi_rfkill_switches
[id
]);
1283 atp_rfk
= kzalloc(sizeof(struct tpacpi_rfk
), GFP_KERNEL
);
1285 atp_rfk
->rfkill
= rfkill_alloc(name
,
1288 &tpacpi_rfk_rfkill_ops
,
1290 if (!atp_rfk
|| !atp_rfk
->rfkill
) {
1292 "failed to allocate memory for rfkill class\n");
1298 atp_rfk
->ops
= tp_rfkops
;
1300 sw_status
= (tp_rfkops
->get_status
)();
1301 if (sw_status
< 0) {
1303 "failed to read initial state for %s, error %d\n",
1306 sw_state
= (sw_status
== TPACPI_RFK_RADIO_OFF
);
1308 /* try to keep the initial state, since we ask the
1309 * firmware to preserve it across S5 in NVRAM */
1310 rfkill_init_sw_state(atp_rfk
->rfkill
, sw_state
);
1313 hw_state
= tpacpi_rfk_check_hwblock_state();
1314 rfkill_set_hw_state(atp_rfk
->rfkill
, hw_state
);
1316 res
= rfkill_register(atp_rfk
->rfkill
);
1319 "failed to register %s rfkill switch: %d\n",
1321 rfkill_destroy(atp_rfk
->rfkill
);
1326 tpacpi_rfkill_switches
[id
] = atp_rfk
;
1328 printk(TPACPI_INFO
"rfkill switch %s: radio is %sblocked\n",
1329 name
, (sw_state
|| hw_state
) ? "" : "un");
1333 static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id
)
1335 struct tpacpi_rfk
*tp_rfk
;
1337 BUG_ON(id
>= TPACPI_RFK_SW_MAX
);
1339 tp_rfk
= tpacpi_rfkill_switches
[id
];
1341 rfkill_unregister(tp_rfk
->rfkill
);
1342 rfkill_destroy(tp_rfk
->rfkill
);
1343 tpacpi_rfkill_switches
[id
] = NULL
;
1348 static void printk_deprecated_rfkill_attribute(const char * const what
)
1350 printk_deprecated_attribute(what
,
1351 "Please switch to generic rfkill before year 2010");
1354 /* sysfs <radio> enable ------------------------------------------------ */
1355 static ssize_t
tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id
,
1356 struct device_attribute
*attr
,
1361 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1363 /* This is in the ABI... */
1364 if (tpacpi_rfk_check_hwblock_state()) {
1365 status
= TPACPI_RFK_RADIO_OFF
;
1367 status
= tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1372 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1373 (status
== TPACPI_RFK_RADIO_ON
) ? 1 : 0);
1376 static ssize_t
tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id
,
1377 struct device_attribute
*attr
,
1378 const char *buf
, size_t count
)
1383 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1385 if (parse_strtoul(buf
, 1, &t
))
1388 tpacpi_disclose_usertask(attr
->attr
.name
, "set to %ld\n", t
);
1390 /* This is in the ABI... */
1391 if (tpacpi_rfk_check_hwblock_state() && !!t
)
1394 res
= tpacpi_rfkill_switches
[id
]->ops
->set_status((!!t
) ?
1395 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
);
1396 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1398 return (res
< 0) ? res
: count
;
1401 /* procfs -------------------------------------------------------------- */
1402 static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id
, struct seq_file
*m
)
1404 if (id
>= TPACPI_RFK_SW_MAX
)
1405 seq_printf(m
, "status:\t\tnot supported\n");
1409 /* This is in the ABI... */
1410 if (tpacpi_rfk_check_hwblock_state()) {
1411 status
= TPACPI_RFK_RADIO_OFF
;
1413 status
= tpacpi_rfk_update_swstate(
1414 tpacpi_rfkill_switches
[id
]);
1419 seq_printf(m
, "status:\t\t%s\n",
1420 (status
== TPACPI_RFK_RADIO_ON
) ?
1421 "enabled" : "disabled");
1422 seq_printf(m
, "commands:\tenable, disable\n");
1428 static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id
, char *buf
)
1434 if (id
>= TPACPI_RFK_SW_MAX
)
1437 while ((cmd
= next_cmd(&buf
))) {
1438 if (strlencmp(cmd
, "enable") == 0)
1439 status
= TPACPI_RFK_RADIO_ON
;
1440 else if (strlencmp(cmd
, "disable") == 0)
1441 status
= TPACPI_RFK_RADIO_OFF
;
1447 tpacpi_disclose_usertask("procfs", "attempt to %s %s\n",
1448 (status
== TPACPI_RFK_RADIO_ON
) ?
1449 "enable" : "disable",
1450 tpacpi_rfkill_names
[id
]);
1451 res
= (tpacpi_rfkill_switches
[id
]->ops
->set_status
)(status
);
1452 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1458 /*************************************************************************
1459 * thinkpad-acpi driver attributes
1462 /* interface_version --------------------------------------------------- */
1463 static ssize_t
tpacpi_driver_interface_version_show(
1464 struct device_driver
*drv
,
1467 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1470 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1471 tpacpi_driver_interface_version_show
, NULL
);
1473 /* debug_level --------------------------------------------------------- */
1474 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1477 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1480 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1481 const char *buf
, size_t count
)
1485 if (parse_strtoul(buf
, 0xffff, &t
))
1493 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1494 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1496 /* version ------------------------------------------------------------- */
1497 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1500 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1501 TPACPI_DESC
, TPACPI_VERSION
);
1504 static DRIVER_ATTR(version
, S_IRUGO
,
1505 tpacpi_driver_version_show
, NULL
);
1507 /* --------------------------------------------------------------------- */
1509 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1511 /* wlsw_emulstate ------------------------------------------------------ */
1512 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1515 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1518 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1519 const char *buf
, size_t count
)
1523 if (parse_strtoul(buf
, 1, &t
))
1526 if (tpacpi_wlsw_emulstate
!= !!t
) {
1527 tpacpi_wlsw_emulstate
= !!t
;
1528 tpacpi_rfk_update_hwblock_state(!t
); /* negative logic */
1534 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1535 tpacpi_driver_wlsw_emulstate_show
,
1536 tpacpi_driver_wlsw_emulstate_store
);
1538 /* bluetooth_emulstate ------------------------------------------------- */
1539 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1540 struct device_driver
*drv
,
1543 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1546 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1547 struct device_driver
*drv
,
1548 const char *buf
, size_t count
)
1552 if (parse_strtoul(buf
, 1, &t
))
1555 tpacpi_bluetooth_emulstate
= !!t
;
1560 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1561 tpacpi_driver_bluetooth_emulstate_show
,
1562 tpacpi_driver_bluetooth_emulstate_store
);
1564 /* wwan_emulstate ------------------------------------------------- */
1565 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1566 struct device_driver
*drv
,
1569 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1572 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1573 struct device_driver
*drv
,
1574 const char *buf
, size_t count
)
1578 if (parse_strtoul(buf
, 1, &t
))
1581 tpacpi_wwan_emulstate
= !!t
;
1586 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1587 tpacpi_driver_wwan_emulstate_show
,
1588 tpacpi_driver_wwan_emulstate_store
);
1590 /* uwb_emulstate ------------------------------------------------- */
1591 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1592 struct device_driver
*drv
,
1595 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1598 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1599 struct device_driver
*drv
,
1600 const char *buf
, size_t count
)
1604 if (parse_strtoul(buf
, 1, &t
))
1607 tpacpi_uwb_emulstate
= !!t
;
1612 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1613 tpacpi_driver_uwb_emulstate_show
,
1614 tpacpi_driver_uwb_emulstate_store
);
1617 /* --------------------------------------------------------------------- */
1619 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1620 &driver_attr_debug_level
, &driver_attr_version
,
1621 &driver_attr_interface_version
,
1624 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1630 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1631 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1635 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1636 if (!res
&& dbg_wlswemul
)
1637 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1638 if (!res
&& dbg_bluetoothemul
)
1639 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1640 if (!res
&& dbg_wwanemul
)
1641 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1642 if (!res
&& dbg_uwbemul
)
1643 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1649 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1653 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1654 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1656 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1657 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1658 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1659 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1660 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1664 /*************************************************************************
1669 * Table of recommended minimum BIOS versions
1671 * Reasons for listing:
1672 * 1. Stable BIOS, listed because the unknown amount of
1673 * bugs and bad ACPI behaviour on older versions
1675 * 2. BIOS or EC fw with known bugs that trigger on Linux
1677 * 3. BIOS with known reduced functionality in older versions
1679 * We recommend the latest BIOS and EC version.
1680 * We only support the latest BIOS and EC fw version as a rule.
1682 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1683 * Information from users in ThinkWiki
1685 * WARNING: we use this table also to detect that the machine is
1686 * a ThinkPad in some cases, so don't remove entries lightly.
1689 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1690 { .vendor = (__v), \
1691 .bios = TPID(__id1, __id2), \
1692 .ec = TPACPI_MATCH_ANY, \
1693 .quirks = TPACPI_MATCH_ANY << 16 \
1694 | (__bv1) << 8 | (__bv2) }
1696 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1697 __eid, __ev1, __ev2) \
1698 { .vendor = (__v), \
1699 .bios = TPID(__bid1, __bid2), \
1701 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1702 | (__bv1) << 8 | (__bv2) }
1704 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1705 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1707 /* Outdated IBM BIOSes often lack the EC id string */
1708 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1709 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1710 __bv1, __bv2, TPID(__id1, __id2), \
1712 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1713 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1716 /* Outdated IBM BIOSes often lack the EC id string */
1717 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1718 __eid1, __eid2, __ev1, __ev2) \
1719 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1720 __bv1, __bv2, TPID(__eid1, __eid2), \
1722 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1723 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1726 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1727 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1729 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1730 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1731 __bv1, __bv2, TPID(__id1, __id2), \
1734 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1735 __eid1, __eid2, __ev1, __ev2) \
1736 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1737 __bv1, __bv2, TPID(__eid1, __eid2), \
1740 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1741 /* Numeric models ------------------ */
1742 /* FW MODEL BIOS VERS */
1743 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1744 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1745 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1746 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1747 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1748 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1749 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1750 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1751 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1753 /* A-series ------------------------- */
1754 /* FW MODEL BIOS VERS EC VERS */
1755 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1756 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1757 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1758 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1759 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1760 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1761 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1762 TPV_QI0('1', '3', '2', '0'), /* A22m */
1763 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1764 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1765 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1767 /* G-series ------------------------- */
1768 /* FW MODEL BIOS VERS */
1769 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1770 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1772 /* R-series, T-series --------------- */
1773 /* FW MODEL BIOS VERS EC VERS */
1774 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1775 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1776 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1777 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1778 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1779 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1780 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1781 T40/p, T41/p, T42/p (1) */
1782 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1783 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1784 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1785 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1787 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1788 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1789 TPV_QI0('1', '6', '3', '2'), /* T22 */
1790 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1791 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1792 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1794 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1795 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1796 TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */
1798 /* BIOS FW BIOS VERS EC FW EC VERS */
1799 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1800 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1802 /* X-series ------------------------- */
1803 /* FW MODEL BIOS VERS EC VERS */
1804 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1805 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1806 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1807 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1808 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1809 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1810 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1812 TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */
1813 TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */
1815 /* (0) - older versions lack DMI EC fw string and functionality */
1816 /* (1) - older versions known to lack functionality */
1827 static void __init
tpacpi_check_outdated_fw(void)
1829 unsigned long fwvers
;
1830 u16 ec_version
, bios_version
;
1832 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1833 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1838 bios_version
= fwvers
& 0xffffU
;
1839 ec_version
= (fwvers
>> 16) & 0xffffU
;
1841 /* note that unknown versions are set to 0x0000 and we use that */
1842 if ((bios_version
> thinkpad_id
.bios_release
) ||
1843 (ec_version
> thinkpad_id
.ec_release
&&
1844 ec_version
!= TPACPI_MATCH_ANY
)) {
1846 * The changelogs would let us track down the exact
1847 * reason, but it is just too much of a pain to track
1848 * it. We only list BIOSes that are either really
1849 * broken, or really stable to begin with, so it is
1850 * best if the user upgrades the firmware anyway.
1853 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1855 "WARNING: This firmware may be missing critical bug "
1856 "fixes and/or important features\n");
1860 static bool __init
tpacpi_is_fw_known(void)
1862 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1863 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1866 /****************************************************************************
1867 ****************************************************************************
1871 ****************************************************************************
1872 ****************************************************************************/
1874 /*************************************************************************
1875 * thinkpad-acpi init subdriver
1878 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1880 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1881 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1883 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1884 (thinkpad_id
.bios_version_str
) ?
1885 thinkpad_id
.bios_version_str
: "unknown",
1886 (thinkpad_id
.ec_version_str
) ?
1887 thinkpad_id
.ec_version_str
: "unknown");
1889 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1890 printk(TPACPI_INFO
"%s %s, model %s\n",
1891 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1892 "IBM" : ((thinkpad_id
.vendor
==
1893 PCI_VENDOR_ID_LENOVO
) ?
1894 "Lenovo" : "Unknown vendor"),
1895 thinkpad_id
.model_str
,
1896 (thinkpad_id
.nummodel_str
) ?
1897 thinkpad_id
.nummodel_str
: "unknown");
1899 tpacpi_check_outdated_fw();
1903 static int thinkpad_acpi_driver_read(struct seq_file
*m
)
1905 seq_printf(m
, "driver:\t\t%s\n", TPACPI_DESC
);
1906 seq_printf(m
, "version:\t%s\n", TPACPI_VERSION
);
1910 static struct ibm_struct thinkpad_acpi_driver_data
= {
1912 .read
= thinkpad_acpi_driver_read
,
1915 /*************************************************************************
1920 * ThinkPad firmware event model
1922 * The ThinkPad firmware has two main event interfaces: normal ACPI
1923 * notifications (which follow the ACPI standard), and a private event
1926 * The private event interface also issues events for the hotkeys. As
1927 * the driver gained features, the event handling code ended up being
1928 * built around the hotkey subdriver. This will need to be refactored
1929 * to a more formal event API eventually.
1931 * Some "hotkeys" are actually supposed to be used as event reports,
1932 * such as "brightness has changed", "volume has changed", depending on
1933 * the ThinkPad model and how the firmware is operating.
1935 * Unlike other classes, hotkey-class events have mask/unmask control on
1936 * non-ancient firmware. However, how it behaves changes a lot with the
1937 * firmware model and version.
1940 enum { /* hot key scan codes (derived from ACPI DSDT) */
1941 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1942 TP_ACPI_HOTKEYSCAN_FNF2
,
1943 TP_ACPI_HOTKEYSCAN_FNF3
,
1944 TP_ACPI_HOTKEYSCAN_FNF4
,
1945 TP_ACPI_HOTKEYSCAN_FNF5
,
1946 TP_ACPI_HOTKEYSCAN_FNF6
,
1947 TP_ACPI_HOTKEYSCAN_FNF7
,
1948 TP_ACPI_HOTKEYSCAN_FNF8
,
1949 TP_ACPI_HOTKEYSCAN_FNF9
,
1950 TP_ACPI_HOTKEYSCAN_FNF10
,
1951 TP_ACPI_HOTKEYSCAN_FNF11
,
1952 TP_ACPI_HOTKEYSCAN_FNF12
,
1953 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1954 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1955 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1956 TP_ACPI_HOTKEYSCAN_FNHOME
,
1957 TP_ACPI_HOTKEYSCAN_FNEND
,
1958 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1959 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1960 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1961 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1962 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1963 TP_ACPI_HOTKEYSCAN_MUTE
,
1964 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1967 enum { /* Keys/events available through NVRAM polling */
1968 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1969 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1972 enum { /* Positions of some of the keys in hotkey masks */
1973 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1974 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1975 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1976 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1977 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1978 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1979 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1980 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1981 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1982 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1983 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1986 enum { /* NVRAM to ACPI HKEY group map */
1987 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1988 TP_ACPI_HKEY_ZOOM_MASK
|
1989 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1990 TP_ACPI_HKEY_HIBERNATE_MASK
,
1991 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1992 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1993 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1994 TP_ACPI_HKEY_VOLDWN_MASK
|
1995 TP_ACPI_HKEY_MUTE_MASK
,
1998 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1999 struct tp_nvram_state
{
2000 u16 thinkpad_toggle
:1;
2002 u16 display_toggle
:1;
2003 u16 thinklight_toggle
:1;
2004 u16 hibernate_toggle
:1;
2005 u16 displayexp_toggle
:1;
2006 u16 display_state
:1;
2007 u16 brightness_toggle
:1;
2008 u16 volume_toggle
:1;
2011 u8 brightness_level
;
2015 /* kthread for the hotkey poller */
2016 static struct task_struct
*tpacpi_hotkey_task
;
2018 /* Acquired while the poller kthread is running, use to sync start/stop */
2019 static struct mutex hotkey_thread_mutex
;
2022 * Acquire mutex to write poller control variables as an
2025 * Increment hotkey_config_change when changing them if you
2026 * want the kthread to forget old state.
2028 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2030 static struct mutex hotkey_thread_data_mutex
;
2031 static unsigned int hotkey_config_change
;
2034 * hotkey poller control variables
2036 * Must be atomic or readers will also need to acquire mutex
2038 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2039 * should be used only when the changes need to be taken as
2040 * a block, OR when one needs to force the kthread to forget
2043 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
2044 static unsigned int hotkey_poll_freq
= 10; /* Hz */
2046 #define HOTKEY_CONFIG_CRITICAL_START \
2048 mutex_lock(&hotkey_thread_data_mutex); \
2049 hotkey_config_change++; \
2051 #define HOTKEY_CONFIG_CRITICAL_END \
2052 mutex_unlock(&hotkey_thread_data_mutex);
2054 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2056 #define hotkey_source_mask 0U
2057 #define HOTKEY_CONFIG_CRITICAL_START
2058 #define HOTKEY_CONFIG_CRITICAL_END
2060 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2062 static struct mutex hotkey_mutex
;
2064 static enum { /* Reasons for waking up */
2065 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
2066 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
2067 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
2068 } hotkey_wakeup_reason
;
2070 static int hotkey_autosleep_ack
;
2072 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
2073 static u32 hotkey_all_mask
; /* all events supported in fw */
2074 static u32 hotkey_reserved_mask
; /* events better left disabled */
2075 static u32 hotkey_driver_mask
; /* events needed by the driver */
2076 static u32 hotkey_user_mask
; /* events visible to userspace */
2077 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
2079 static unsigned int hotkey_report_mode
;
2081 static u16
*hotkey_keycode_map
;
2083 static struct attribute_set
*hotkey_dev_attributes
;
2085 static void tpacpi_driver_event(const unsigned int hkey_event
);
2086 static void hotkey_driver_event(const unsigned int scancode
);
2087 static void hotkey_poll_setup(const bool may_warn
);
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 hotkey_poll_setup(true);
2272 mutex_unlock(&hotkey_mutex
);
2277 static int hotkey_status_get(int *status
)
2279 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
2285 static int hotkey_status_set(bool enable
)
2287 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
2293 static void tpacpi_input_send_tabletsw(void)
2297 if (tp_features
.hotkey_tablet
&&
2298 !hotkey_get_tablet_mode(&state
)) {
2299 mutex_lock(&tpacpi_inputdev_send_mutex
);
2301 input_report_switch(tpacpi_inputdev
,
2302 SW_TABLET_MODE
, !!state
);
2303 input_sync(tpacpi_inputdev
);
2305 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2309 /* Do NOT call without validating scancode first */
2310 static void tpacpi_input_send_key(const unsigned int scancode
)
2312 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
2314 if (keycode
!= KEY_RESERVED
) {
2315 mutex_lock(&tpacpi_inputdev_send_mutex
);
2317 input_report_key(tpacpi_inputdev
, keycode
, 1);
2318 if (keycode
== KEY_UNKNOWN
)
2319 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2321 input_sync(tpacpi_inputdev
);
2323 input_report_key(tpacpi_inputdev
, keycode
, 0);
2324 if (keycode
== KEY_UNKNOWN
)
2325 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2327 input_sync(tpacpi_inputdev
);
2329 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2333 /* Do NOT call without validating scancode first */
2334 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
2336 hotkey_driver_event(scancode
);
2337 if (hotkey_user_mask
& (1 << scancode
))
2338 tpacpi_input_send_key(scancode
);
2341 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2342 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2344 /* Do NOT call without validating scancode first */
2345 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2347 tpacpi_input_send_key_masked(scancode
);
2348 if (hotkey_report_mode
< 2) {
2349 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2350 0x80, TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
2354 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2358 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2359 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2360 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2361 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2362 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2363 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2365 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2366 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2367 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2369 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2370 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2371 n
->displayexp_toggle
=
2372 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2374 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2375 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2376 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2377 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2378 n
->brightness_toggle
=
2379 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2381 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2382 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2383 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2384 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2385 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2386 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2390 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2391 struct tp_nvram_state
*newn
,
2392 const u32 event_mask
)
2395 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2397 if ((event_mask & (1 << __scancode)) && \
2398 oldn->__member != newn->__member) \
2399 tpacpi_hotkey_send_key(__scancode); \
2402 #define TPACPI_MAY_SEND_KEY(__scancode) \
2404 if (event_mask & (1 << __scancode)) \
2405 tpacpi_hotkey_send_key(__scancode); \
2408 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2409 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2410 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2411 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2413 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2415 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2418 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2419 if (oldn
->mute
!= newn
->mute
) {
2420 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2422 if (oldn
->volume_level
> newn
->volume_level
) {
2423 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2424 } else if (oldn
->volume_level
< newn
->volume_level
) {
2425 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2426 } else if (oldn
->mute
== newn
->mute
) {
2427 /* repeated key presses that didn't change state */
2429 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2430 } else if (newn
->volume_level
!= 0) {
2431 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2433 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2438 /* handle brightness */
2439 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2440 if (oldn
->brightness_level
< newn
->brightness_level
) {
2441 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2442 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
2443 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2445 /* repeated key presses that didn't change state */
2446 if (newn
->brightness_level
!= 0) {
2447 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2449 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2454 #undef TPACPI_COMPARE_KEY
2455 #undef TPACPI_MAY_SEND_KEY
2461 * We track all events in hotkey_source_mask all the time, since
2462 * most of them are edge-based. We only issue those requested by
2463 * hotkey_user_mask or hotkey_driver_mask, though.
2465 static int hotkey_kthread(void *data
)
2467 struct tp_nvram_state s
[2];
2468 u32 poll_mask
, event_mask
;
2469 unsigned int si
, so
;
2471 unsigned int change_detector
, must_reset
;
2472 unsigned int poll_freq
;
2474 mutex_lock(&hotkey_thread_mutex
);
2476 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2485 /* Initial state for compares */
2486 mutex_lock(&hotkey_thread_data_mutex
);
2487 change_detector
= hotkey_config_change
;
2488 poll_mask
= hotkey_source_mask
;
2489 event_mask
= hotkey_source_mask
&
2490 (hotkey_driver_mask
| hotkey_user_mask
);
2491 poll_freq
= hotkey_poll_freq
;
2492 mutex_unlock(&hotkey_thread_data_mutex
);
2493 hotkey_read_nvram(&s
[so
], poll_mask
);
2495 while (!kthread_should_stop()) {
2497 if (likely(poll_freq
))
2500 t
= 100; /* should never happen... */
2502 t
= msleep_interruptible(t
);
2503 if (unlikely(kthread_should_stop()))
2505 must_reset
= try_to_freeze();
2506 if (t
> 0 && !must_reset
)
2509 mutex_lock(&hotkey_thread_data_mutex
);
2510 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2511 /* forget old state on thaw or config change */
2514 change_detector
= hotkey_config_change
;
2516 poll_mask
= hotkey_source_mask
;
2517 event_mask
= hotkey_source_mask
&
2518 (hotkey_driver_mask
| hotkey_user_mask
);
2519 poll_freq
= hotkey_poll_freq
;
2520 mutex_unlock(&hotkey_thread_data_mutex
);
2522 if (likely(poll_mask
)) {
2523 hotkey_read_nvram(&s
[si
], poll_mask
);
2524 if (likely(si
!= so
)) {
2525 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2535 mutex_unlock(&hotkey_thread_mutex
);
2539 /* call with hotkey_mutex held */
2540 static void hotkey_poll_stop_sync(void)
2542 if (tpacpi_hotkey_task
) {
2543 if (frozen(tpacpi_hotkey_task
) ||
2544 freezing(tpacpi_hotkey_task
))
2545 thaw_process(tpacpi_hotkey_task
);
2547 kthread_stop(tpacpi_hotkey_task
);
2548 tpacpi_hotkey_task
= NULL
;
2549 mutex_lock(&hotkey_thread_mutex
);
2550 /* at this point, the thread did exit */
2551 mutex_unlock(&hotkey_thread_mutex
);
2555 /* call with hotkey_mutex held */
2556 static void hotkey_poll_setup(const bool may_warn
)
2558 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2559 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2561 if (hotkey_poll_freq
> 0 &&
2562 (poll_driver_mask
||
2563 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2564 if (!tpacpi_hotkey_task
) {
2565 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2566 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2567 if (IS_ERR(tpacpi_hotkey_task
)) {
2568 tpacpi_hotkey_task
= NULL
;
2570 "could not create kernel thread "
2571 "for hotkey polling\n");
2575 hotkey_poll_stop_sync();
2576 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2577 hotkey_poll_freq
== 0) {
2578 printk(TPACPI_NOTICE
2579 "hot keys 0x%08x and/or events 0x%08x "
2580 "require polling, which is currently "
2582 poll_user_mask
, poll_driver_mask
);
2587 static void hotkey_poll_setup_safe(const bool may_warn
)
2589 mutex_lock(&hotkey_mutex
);
2590 hotkey_poll_setup(may_warn
);
2591 mutex_unlock(&hotkey_mutex
);
2594 /* call with hotkey_mutex held */
2595 static void hotkey_poll_set_freq(unsigned int freq
)
2598 hotkey_poll_stop_sync();
2600 hotkey_poll_freq
= freq
;
2603 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2605 static void hotkey_poll_setup(const bool __unused
)
2609 static void hotkey_poll_setup_safe(const bool __unused
)
2613 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2615 static int hotkey_inputdev_open(struct input_dev
*dev
)
2617 switch (tpacpi_lifecycle
) {
2618 case TPACPI_LIFE_INIT
:
2619 case TPACPI_LIFE_RUNNING
:
2620 hotkey_poll_setup_safe(false);
2622 case TPACPI_LIFE_EXITING
:
2626 /* Should only happen if tpacpi_lifecycle is corrupt */
2631 static void hotkey_inputdev_close(struct input_dev
*dev
)
2633 /* disable hotkey polling when possible */
2634 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
&&
2635 !(hotkey_source_mask
& hotkey_driver_mask
))
2636 hotkey_poll_setup_safe(false);
2639 /* sysfs hotkey enable ------------------------------------------------- */
2640 static ssize_t
hotkey_enable_show(struct device
*dev
,
2641 struct device_attribute
*attr
,
2646 printk_deprecated_attribute("hotkey_enable",
2647 "Hotkey reporting is always enabled");
2649 res
= hotkey_status_get(&status
);
2653 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2656 static ssize_t
hotkey_enable_store(struct device
*dev
,
2657 struct device_attribute
*attr
,
2658 const char *buf
, size_t count
)
2662 printk_deprecated_attribute("hotkey_enable",
2663 "Hotkeys can be disabled through hotkey_mask");
2665 if (parse_strtoul(buf
, 1, &t
))
2674 static struct device_attribute dev_attr_hotkey_enable
=
2675 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2676 hotkey_enable_show
, hotkey_enable_store
);
2678 /* sysfs hotkey mask --------------------------------------------------- */
2679 static ssize_t
hotkey_mask_show(struct device
*dev
,
2680 struct device_attribute
*attr
,
2683 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2686 static ssize_t
hotkey_mask_store(struct device
*dev
,
2687 struct device_attribute
*attr
,
2688 const char *buf
, size_t count
)
2693 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2696 if (mutex_lock_killable(&hotkey_mutex
))
2697 return -ERESTARTSYS
;
2699 res
= hotkey_user_mask_set(t
);
2701 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2702 hotkey_poll_setup(true);
2705 mutex_unlock(&hotkey_mutex
);
2707 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2709 return (res
) ? res
: count
;
2712 static struct device_attribute dev_attr_hotkey_mask
=
2713 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2714 hotkey_mask_show
, hotkey_mask_store
);
2716 /* sysfs hotkey bios_enabled ------------------------------------------- */
2717 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2718 struct device_attribute
*attr
,
2721 return sprintf(buf
, "0\n");
2724 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2725 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2727 /* sysfs hotkey bios_mask ---------------------------------------------- */
2728 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2729 struct device_attribute
*attr
,
2732 printk_deprecated_attribute("hotkey_bios_mask",
2733 "This attribute is useless.");
2734 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2737 static struct device_attribute dev_attr_hotkey_bios_mask
=
2738 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2740 /* sysfs hotkey all_mask ----------------------------------------------- */
2741 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2742 struct device_attribute
*attr
,
2745 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2746 hotkey_all_mask
| hotkey_source_mask
);
2749 static struct device_attribute dev_attr_hotkey_all_mask
=
2750 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2752 /* sysfs hotkey recommended_mask --------------------------------------- */
2753 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2754 struct device_attribute
*attr
,
2757 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2758 (hotkey_all_mask
| hotkey_source_mask
)
2759 & ~hotkey_reserved_mask
);
2762 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2763 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2764 hotkey_recommended_mask_show
, NULL
);
2766 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2768 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2769 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2770 struct device_attribute
*attr
,
2773 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2776 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2777 struct device_attribute
*attr
,
2778 const char *buf
, size_t count
)
2784 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2785 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2788 if (mutex_lock_killable(&hotkey_mutex
))
2789 return -ERESTARTSYS
;
2791 HOTKEY_CONFIG_CRITICAL_START
2792 hotkey_source_mask
= t
;
2793 HOTKEY_CONFIG_CRITICAL_END
2795 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2796 ~hotkey_source_mask
);
2797 hotkey_poll_setup(true);
2799 /* check if events needed by the driver got disabled */
2800 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2801 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2803 mutex_unlock(&hotkey_mutex
);
2806 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2807 "firmware event mask!\n");
2810 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2811 "some important events were disabled: "
2814 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2816 return (rc
< 0) ? rc
: count
;
2819 static struct device_attribute dev_attr_hotkey_source_mask
=
2820 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2821 hotkey_source_mask_show
, hotkey_source_mask_store
);
2823 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2824 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2825 struct device_attribute
*attr
,
2828 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2831 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2832 struct device_attribute
*attr
,
2833 const char *buf
, size_t count
)
2837 if (parse_strtoul(buf
, 25, &t
))
2840 if (mutex_lock_killable(&hotkey_mutex
))
2841 return -ERESTARTSYS
;
2843 hotkey_poll_set_freq(t
);
2844 hotkey_poll_setup(true);
2846 mutex_unlock(&hotkey_mutex
);
2848 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2853 static struct device_attribute dev_attr_hotkey_poll_freq
=
2854 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2855 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2857 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2859 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2860 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2861 struct device_attribute
*attr
,
2865 res
= hotkey_get_wlsw();
2869 /* Opportunistic update */
2870 tpacpi_rfk_update_hwblock_state((res
== TPACPI_RFK_RADIO_OFF
));
2872 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2873 (res
== TPACPI_RFK_RADIO_OFF
) ? 0 : 1);
2876 static struct device_attribute dev_attr_hotkey_radio_sw
=
2877 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2879 static void hotkey_radio_sw_notify_change(void)
2881 if (tp_features
.hotkey_wlsw
)
2882 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2886 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2887 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2888 struct device_attribute
*attr
,
2892 res
= hotkey_get_tablet_mode(&s
);
2896 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2899 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2900 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2902 static void hotkey_tablet_mode_notify_change(void)
2904 if (tp_features
.hotkey_tablet
)
2905 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2906 "hotkey_tablet_mode");
2909 /* sysfs hotkey report_mode -------------------------------------------- */
2910 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2911 struct device_attribute
*attr
,
2914 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2915 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2918 static struct device_attribute dev_attr_hotkey_report_mode
=
2919 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2921 /* sysfs wakeup reason (pollable) -------------------------------------- */
2922 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2923 struct device_attribute
*attr
,
2926 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2929 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2930 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2932 static void hotkey_wakeup_reason_notify_change(void)
2934 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2938 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2939 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2940 struct device_attribute
*attr
,
2943 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2946 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2947 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2948 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2950 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2952 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2953 "wakeup_hotunplug_complete");
2956 /* --------------------------------------------------------------------- */
2958 static struct attribute
*hotkey_attributes
[] __initdata
= {
2959 &dev_attr_hotkey_enable
.attr
,
2960 &dev_attr_hotkey_bios_enabled
.attr
,
2961 &dev_attr_hotkey_bios_mask
.attr
,
2962 &dev_attr_hotkey_report_mode
.attr
,
2963 &dev_attr_hotkey_wakeup_reason
.attr
,
2964 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2965 &dev_attr_hotkey_mask
.attr
,
2966 &dev_attr_hotkey_all_mask
.attr
,
2967 &dev_attr_hotkey_recommended_mask
.attr
,
2968 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2969 &dev_attr_hotkey_source_mask
.attr
,
2970 &dev_attr_hotkey_poll_freq
.attr
,
2975 * Sync both the hw and sw blocking state of all switches
2977 static void tpacpi_send_radiosw_update(void)
2982 * We must sync all rfkill controllers *before* issuing any
2983 * rfkill input events, or we will race the rfkill core input
2986 * tpacpi_inputdev_send_mutex works as a syncronization point
2989 * We optimize to avoid numerous calls to hotkey_get_wlsw.
2992 wlsw
= hotkey_get_wlsw();
2994 /* Sync hw blocking state first if it is hw-blocked */
2995 if (wlsw
== TPACPI_RFK_RADIO_OFF
)
2996 tpacpi_rfk_update_hwblock_state(true);
2998 /* Sync sw blocking state */
2999 tpacpi_rfk_update_swstate_all();
3001 /* Sync hw blocking state last if it is hw-unblocked */
3002 if (wlsw
== TPACPI_RFK_RADIO_ON
)
3003 tpacpi_rfk_update_hwblock_state(false);
3005 /* Issue rfkill input event for WLSW switch */
3007 mutex_lock(&tpacpi_inputdev_send_mutex
);
3009 input_report_switch(tpacpi_inputdev
,
3010 SW_RFKILL_ALL
, (wlsw
> 0));
3011 input_sync(tpacpi_inputdev
);
3013 mutex_unlock(&tpacpi_inputdev_send_mutex
);
3017 * this can be unconditional, as we will poll state again
3018 * if userspace uses the notify to read data
3020 hotkey_radio_sw_notify_change();
3023 static void hotkey_exit(void)
3025 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3026 mutex_lock(&hotkey_mutex
);
3027 hotkey_poll_stop_sync();
3028 mutex_unlock(&hotkey_mutex
);
3031 if (hotkey_dev_attributes
)
3032 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3034 kfree(hotkey_keycode_map
);
3036 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
3037 "restoring original HKEY status and mask\n");
3038 /* yes, there is a bitwise or below, we want the
3039 * functions to be called even if one of them fail */
3040 if (((tp_features
.hotkey_mask
&&
3041 hotkey_mask_set(hotkey_orig_mask
)) |
3042 hotkey_status_set(false)) != 0)
3044 "failed to restore hot key mask "
3045 "to BIOS defaults\n");
3048 static void __init
hotkey_unmap(const unsigned int scancode
)
3050 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
3051 clear_bit(hotkey_keycode_map
[scancode
],
3052 tpacpi_inputdev
->keybit
);
3053 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
3059 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
3062 #define TPACPI_HK_Q_INIMASK 0x0001
3064 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
3065 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
3066 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
3067 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
3068 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
3069 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
3070 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
3071 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
3072 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
3073 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
3074 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
3075 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
3076 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
3077 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
3078 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
3079 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
3080 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
3081 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
3082 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
3083 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
3086 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
3088 /* Requirements for changing the default keymaps:
3090 * 1. Many of the keys are mapped to KEY_RESERVED for very
3091 * good reasons. Do not change them unless you have deep
3092 * knowledge on the IBM and Lenovo ThinkPad firmware for
3093 * the various ThinkPad models. The driver behaves
3094 * differently for KEY_RESERVED: such keys have their
3095 * hot key mask *unset* in mask_recommended, and also
3096 * in the initial hot key mask programmed into the
3097 * firmware at driver load time, which means the firm-
3098 * ware may react very differently if you change them to
3101 * 2. You must be subscribed to the linux-thinkpad and
3102 * ibm-acpi-devel mailing lists, and you should read the
3103 * list archives since 2007 if you want to change the
3104 * keymaps. This requirement exists so that you will
3105 * know the past history of problems with the thinkpad-
3106 * acpi driver keymaps, and also that you will be
3107 * listening to any bug reports;
3109 * 3. Do not send thinkpad-acpi specific patches directly to
3110 * for merging, *ever*. Send them to the linux-acpi
3111 * mailinglist for comments. Merging is to be done only
3112 * through acpi-test and the ACPI maintainer.
3114 * If the above is too much to ask, don't change the keymap.
3115 * Ask the thinkpad-acpi maintainer to do it, instead.
3117 static u16 ibm_keycode_map
[] __initdata
= {
3118 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3119 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
3120 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3121 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3123 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3124 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3125 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3126 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3128 /* brightness: firmware always reacts to them */
3129 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
3130 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
3132 /* Thinklight: firmware always react to it */
3133 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3135 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3136 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3138 /* Volume: firmware always react to it and reprograms
3139 * the built-in *extra* mixer. Never map it to control
3140 * another mixer by default. */
3141 KEY_RESERVED
, /* 0x14: VOLUME UP */
3142 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3143 KEY_RESERVED
, /* 0x16: MUTE */
3145 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3147 /* (assignments unknown, please report if found) */
3148 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3149 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3151 static u16 lenovo_keycode_map
[] __initdata
= {
3152 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3153 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
3154 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3155 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3157 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3158 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3159 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3160 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3162 /* These should be enabled --only-- when ACPI video
3163 * is disabled (i.e. in "vendor" mode), and are handled
3164 * in a special way by the init code */
3165 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
3166 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
3168 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3170 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3171 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3173 /* Volume: z60/z61, T60 (BIOS version?): firmware always
3174 * react to it and reprograms the built-in *extra* mixer.
3175 * Never map it to control another mixer by default.
3177 * T60?, T61, R60?, R61: firmware and EC tries to send
3178 * these over the regular keyboard, so these are no-ops,
3179 * but there are still weird bugs re. MUTE, so do not
3180 * change unless you get test reports from all Lenovo
3181 * models. May cause the BIOS to interfere with the
3184 KEY_RESERVED
, /* 0x14: VOLUME UP */
3185 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3186 KEY_RESERVED
, /* 0x16: MUTE */
3188 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3190 /* (assignments unknown, please report if found) */
3191 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3192 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3195 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
3196 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
3197 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
3202 bool radiosw_state
= false;
3203 bool tabletsw_state
= false;
3205 unsigned long quirks
;
3207 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3208 "initializing hotkey subdriver\n");
3210 BUG_ON(!tpacpi_inputdev
);
3211 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
3212 tpacpi_inputdev
->close
!= NULL
);
3214 TPACPI_ACPIHANDLE_INIT(hkey
);
3215 mutex_init(&hotkey_mutex
);
3217 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3218 mutex_init(&hotkey_thread_mutex
);
3219 mutex_init(&hotkey_thread_data_mutex
);
3222 /* hotkey not supported on 570 */
3223 tp_features
.hotkey
= hkey_handle
!= NULL
;
3225 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3227 str_supported(tp_features
.hotkey
));
3229 if (!tp_features
.hotkey
)
3232 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
3233 ARRAY_SIZE(tpacpi_hotkey_qtable
));
3235 tpacpi_disable_brightness_delay();
3237 /* MUST have enough space for all attributes to be added to
3238 * hotkey_dev_attributes */
3239 hotkey_dev_attributes
= create_attr_set(
3240 ARRAY_SIZE(hotkey_attributes
) + 2,
3242 if (!hotkey_dev_attributes
)
3244 res
= add_many_to_attr_set(hotkey_dev_attributes
,
3246 ARRAY_SIZE(hotkey_attributes
));
3250 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
3251 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
3252 for HKEY interface version 0x100 */
3253 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
3254 if ((hkeyv
>> 8) != 1) {
3255 printk(TPACPI_ERR
"unknown version of the "
3256 "HKEY interface: 0x%x\n", hkeyv
);
3257 printk(TPACPI_ERR
"please report this to %s\n",
3261 * MHKV 0x100 in A31, R40, R40e,
3262 * T4x, X31, and later
3264 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3265 "firmware HKEY interface version: 0x%x\n",
3268 /* Paranoia check AND init hotkey_all_mask */
3269 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
3272 "missing MHKA handler, "
3273 "please report this to %s\n",
3275 /* Fallback: pre-init for FN+F3,F4,F12 */
3276 hotkey_all_mask
= 0x080cU
;
3278 tp_features
.hotkey_mask
= 1;
3283 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3284 "hotkey masks are %s\n",
3285 str_supported(tp_features
.hotkey_mask
));
3287 /* Init hotkey_all_mask if not initialized yet */
3288 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
3289 (quirks
& TPACPI_HK_Q_INIMASK
))
3290 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
3292 /* Init hotkey_acpi_mask and hotkey_orig_mask */
3293 if (tp_features
.hotkey_mask
) {
3294 /* hotkey_source_mask *must* be zero for
3295 * the first hotkey_mask_get to return hotkey_orig_mask */
3296 res
= hotkey_mask_get();
3300 hotkey_orig_mask
= hotkey_acpi_mask
;
3302 hotkey_orig_mask
= hotkey_all_mask
;
3303 hotkey_acpi_mask
= hotkey_all_mask
;
3306 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3308 tp_features
.hotkey_wlsw
= 1;
3309 radiosw_state
= !!tpacpi_wlsw_emulstate
;
3311 "radio switch emulation enabled\n");
3314 /* Not all thinkpads have a hardware radio switch */
3315 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3316 tp_features
.hotkey_wlsw
= 1;
3317 radiosw_state
= !!status
;
3319 "radio switch found; radios are %s\n",
3320 enabled(status
, 0));
3322 if (tp_features
.hotkey_wlsw
)
3323 res
= add_to_attr_set(hotkey_dev_attributes
,
3324 &dev_attr_hotkey_radio_sw
.attr
);
3326 /* For X41t, X60t, X61t Tablets... */
3327 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3328 tp_features
.hotkey_tablet
= 1;
3329 tabletsw_state
= !!(status
& TP_HOTKEY_TABLET_MASK
);
3331 "possible tablet mode switch found; "
3332 "ThinkPad in %s mode\n",
3333 (tabletsw_state
) ? "tablet" : "laptop");
3334 res
= add_to_attr_set(hotkey_dev_attributes
,
3335 &dev_attr_hotkey_tablet_mode
.attr
);
3339 res
= register_attr_set_with_sysfs(
3340 hotkey_dev_attributes
,
3341 &tpacpi_pdev
->dev
.kobj
);
3345 /* Set up key map */
3347 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3349 if (!hotkey_keycode_map
) {
3351 "failed to allocate memory for key map\n");
3356 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
3357 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3358 "using Lenovo default hot key map\n");
3359 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
3360 TPACPI_HOTKEY_MAP_SIZE
);
3362 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3363 "using IBM default hot key map\n");
3364 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
3365 TPACPI_HOTKEY_MAP_SIZE
);
3368 input_set_capability(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
);
3369 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3370 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3371 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3372 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3373 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3374 input_set_capability(tpacpi_inputdev
, EV_KEY
,
3375 hotkey_keycode_map
[i
]);
3377 if (i
< sizeof(hotkey_reserved_mask
)*8)
3378 hotkey_reserved_mask
|= 1 << i
;
3382 if (tp_features
.hotkey_wlsw
) {
3383 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_RFKILL_ALL
);
3384 input_report_switch(tpacpi_inputdev
,
3385 SW_RFKILL_ALL
, radiosw_state
);
3387 if (tp_features
.hotkey_tablet
) {
3388 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_TABLET_MODE
);
3389 input_report_switch(tpacpi_inputdev
,
3390 SW_TABLET_MODE
, tabletsw_state
);
3393 /* Do not issue duplicate brightness change events to
3395 if (!tp_features
.bright_acpimode
)
3396 /* update bright_acpimode... */
3397 tpacpi_check_std_acpi_brightness_support();
3399 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
3401 "This ThinkPad has standard ACPI backlight "
3402 "brightness control, supported by the ACPI "
3404 printk(TPACPI_NOTICE
3405 "Disabling thinkpad-acpi brightness events "
3408 /* Disable brightness up/down on Lenovo thinkpads when
3409 * ACPI is handling them, otherwise it is plain impossible
3410 * for userspace to do something even remotely sane */
3411 hotkey_reserved_mask
|=
3412 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3413 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3414 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3415 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3418 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3419 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3421 & ~hotkey_reserved_mask
;
3423 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3424 "hotkey source mask 0x%08x, polling freq %u\n",
3425 hotkey_source_mask
, hotkey_poll_freq
);
3428 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3429 "enabling firmware HKEY event interface...\n");
3430 res
= hotkey_status_set(true);
3435 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3436 | hotkey_driver_mask
)
3437 & ~hotkey_source_mask
);
3438 if (res
< 0 && res
!= -ENXIO
) {
3442 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3443 & ~hotkey_reserved_mask
;
3444 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3445 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3446 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3448 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3449 "legacy ibm/hotkey event reporting over procfs %s\n",
3450 (hotkey_report_mode
< 2) ?
3451 "enabled" : "disabled");
3453 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3454 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3456 hotkey_poll_setup_safe(true);
3461 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3462 hotkey_dev_attributes
= NULL
;
3464 return (res
< 0)? res
: 1;
3467 static bool hotkey_notify_hotkey(const u32 hkey
,
3469 bool *ignore_acpi_ev
)
3471 /* 0x1000-0x1FFF: key presses */
3472 unsigned int scancode
= hkey
& 0xfff;
3473 *send_acpi_ev
= true;
3474 *ignore_acpi_ev
= false;
3476 if (scancode
> 0 && scancode
< 0x21) {
3478 if (!(hotkey_source_mask
& (1 << scancode
))) {
3479 tpacpi_input_send_key_masked(scancode
);
3480 *send_acpi_ev
= false;
3482 *ignore_acpi_ev
= true;
3489 static bool hotkey_notify_wakeup(const u32 hkey
,
3491 bool *ignore_acpi_ev
)
3493 /* 0x2000-0x2FFF: Wakeup reason */
3494 *send_acpi_ev
= true;
3495 *ignore_acpi_ev
= false;
3498 case TP_HKEY_EV_WKUP_S3_UNDOCK
: /* suspend, undock */
3499 case TP_HKEY_EV_WKUP_S4_UNDOCK
: /* hibernation, undock */
3500 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3501 *ignore_acpi_ev
= true;
3504 case TP_HKEY_EV_WKUP_S3_BAYEJ
: /* suspend, bay eject */
3505 case TP_HKEY_EV_WKUP_S4_BAYEJ
: /* hibernation, bay eject */
3506 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3507 *ignore_acpi_ev
= true;
3510 case TP_HKEY_EV_WKUP_S3_BATLOW
: /* Battery on critical low level/S3 */
3511 case TP_HKEY_EV_WKUP_S4_BATLOW
: /* Battery on critical low level/S4 */
3513 "EMERGENCY WAKEUP: battery almost empty\n");
3514 /* how to auto-heal: */
3515 /* 2313: woke up from S3, go to S4/S5 */
3516 /* 2413: woke up from S4, go to S5 */
3523 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3525 "woke up due to a hot-unplug "
3527 hotkey_wakeup_reason_notify_change();
3532 static bool hotkey_notify_usrevent(const u32 hkey
,
3534 bool *ignore_acpi_ev
)
3536 /* 0x5000-0x5FFF: human interface helpers */
3537 *send_acpi_ev
= true;
3538 *ignore_acpi_ev
= false;
3541 case TP_HKEY_EV_PEN_INSERTED
: /* X61t: tablet pen inserted into bay */
3542 case TP_HKEY_EV_PEN_REMOVED
: /* X61t: tablet pen removed from bay */
3545 case TP_HKEY_EV_TABLET_TABLET
: /* X41t-X61t: tablet mode */
3546 case TP_HKEY_EV_TABLET_NOTEBOOK
: /* X41t-X61t: normal mode */
3547 tpacpi_input_send_tabletsw();
3548 hotkey_tablet_mode_notify_change();
3549 *send_acpi_ev
= false;
3552 case TP_HKEY_EV_LID_CLOSE
: /* Lid closed */
3553 case TP_HKEY_EV_LID_OPEN
: /* Lid opened */
3554 case TP_HKEY_EV_BRGHT_CHANGED
: /* brightness changed */
3555 /* do not propagate these events */
3556 *ignore_acpi_ev
= true;
3564 static void thermal_dump_all_sensors(void);
3566 static bool hotkey_notify_thermal(const u32 hkey
,
3568 bool *ignore_acpi_ev
)
3572 /* 0x6000-0x6FFF: thermal alarms */
3573 *send_acpi_ev
= true;
3574 *ignore_acpi_ev
= false;
3577 case TP_HKEY_EV_THM_TABLE_CHANGED
:
3579 "EC reports that Thermal Table has changed\n");
3580 /* recommended action: do nothing, we don't have
3581 * Lenovo ATM information */
3583 case TP_HKEY_EV_ALARM_BAT_HOT
:
3585 "THERMAL ALARM: battery is too hot!\n");
3586 /* recommended action: warn user through gui */
3588 case TP_HKEY_EV_ALARM_BAT_XHOT
:
3590 "THERMAL EMERGENCY: battery is extremely hot!\n");
3591 /* recommended action: immediate sleep/hibernate */
3593 case TP_HKEY_EV_ALARM_SENSOR_HOT
:
3596 "a sensor reports something is too hot!\n");
3597 /* recommended action: warn user through gui, that */
3598 /* some internal component is too hot */
3600 case TP_HKEY_EV_ALARM_SENSOR_XHOT
:
3602 "THERMAL EMERGENCY: "
3603 "a sensor reports something is extremely hot!\n");
3604 /* recommended action: immediate sleep/hibernate */
3608 "THERMAL ALERT: unknown thermal alarm received\n");
3612 thermal_dump_all_sensors();
3617 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3621 bool ignore_acpi_ev
;
3624 if (event
!= 0x80) {
3626 "unknown HKEY notification event %d\n", event
);
3627 /* forward it to userspace, maybe it knows how to handle it */
3628 acpi_bus_generate_netlink_event(
3629 ibm
->acpi
->device
->pnp
.device_class
,
3630 dev_name(&ibm
->acpi
->device
->dev
),
3636 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3637 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3646 send_acpi_ev
= true;
3647 ignore_acpi_ev
= false;
3649 switch (hkey
>> 12) {
3651 /* 0x1000-0x1FFF: key presses */
3652 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3656 /* 0x2000-0x2FFF: Wakeup reason */
3657 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3661 /* 0x3000-0x3FFF: bay-related wakeups */
3663 case TP_HKEY_EV_BAYEJ_ACK
:
3664 hotkey_autosleep_ack
= 1;
3667 hotkey_wakeup_hotunplug_complete_notify_change();
3670 case TP_HKEY_EV_OPTDRV_EJ
:
3671 /* FIXME: kick libata if SATA link offline */
3679 /* 0x4000-0x4FFF: dock-related wakeups */
3680 if (hkey
== TP_HKEY_EV_UNDOCK_ACK
) {
3681 hotkey_autosleep_ack
= 1;
3684 hotkey_wakeup_hotunplug_complete_notify_change();
3691 /* 0x5000-0x5FFF: human interface helpers */
3692 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3696 /* 0x6000-0x6FFF: thermal alarms */
3697 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3701 /* 0x7000-0x7FFF: misc */
3702 if (tp_features
.hotkey_wlsw
&&
3703 hkey
== TP_HKEY_EV_RFKILL_CHANGED
) {
3704 tpacpi_send_radiosw_update();
3709 /* fallthrough to default */
3714 printk(TPACPI_NOTICE
3715 "unhandled HKEY event 0x%04x\n", hkey
);
3716 printk(TPACPI_NOTICE
3717 "please report the conditions when this "
3718 "event happened to %s\n", TPACPI_MAIL
);
3722 if (!ignore_acpi_ev
&&
3723 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3724 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3728 /* netlink events */
3729 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3730 acpi_bus_generate_netlink_event(
3731 ibm
->acpi
->device
->pnp
.device_class
,
3732 dev_name(&ibm
->acpi
->device
->dev
),
3738 static void hotkey_suspend(pm_message_t state
)
3740 /* Do these on suspend, we get the events on early resume! */
3741 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3742 hotkey_autosleep_ack
= 0;
3745 static void hotkey_resume(void)
3747 tpacpi_disable_brightness_delay();
3749 if (hotkey_status_set(true) < 0 ||
3750 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3752 "error while attempting to reset the event "
3753 "firmware interface\n");
3755 tpacpi_send_radiosw_update();
3756 hotkey_tablet_mode_notify_change();
3757 hotkey_wakeup_reason_notify_change();
3758 hotkey_wakeup_hotunplug_complete_notify_change();
3759 hotkey_poll_setup_safe(false);
3762 /* procfs -------------------------------------------------------------- */
3763 static int hotkey_read(struct seq_file
*m
)
3767 if (!tp_features
.hotkey
) {
3768 seq_printf(m
, "status:\t\tnot supported\n");
3772 if (mutex_lock_killable(&hotkey_mutex
))
3773 return -ERESTARTSYS
;
3774 res
= hotkey_status_get(&status
);
3776 res
= hotkey_mask_get();
3777 mutex_unlock(&hotkey_mutex
);
3781 seq_printf(m
, "status:\t\t%s\n", enabled(status
, 0));
3782 if (hotkey_all_mask
) {
3783 seq_printf(m
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3784 seq_printf(m
, "commands:\tenable, disable, reset, <mask>\n");
3786 seq_printf(m
, "mask:\t\tnot supported\n");
3787 seq_printf(m
, "commands:\tenable, disable, reset\n");
3793 static void hotkey_enabledisable_warn(bool enable
)
3795 tpacpi_log_usertask("procfs hotkey enable/disable");
3796 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3798 "hotkey enable/disable functionality has been "
3799 "removed from the driver. Hotkeys are always "
3802 "Please remove the hotkey=enable module "
3803 "parameter, it is deprecated. Hotkeys are always "
3807 static int hotkey_write(char *buf
)
3813 if (!tp_features
.hotkey
)
3816 if (mutex_lock_killable(&hotkey_mutex
))
3817 return -ERESTARTSYS
;
3819 mask
= hotkey_user_mask
;
3822 while ((cmd
= next_cmd(&buf
))) {
3823 if (strlencmp(cmd
, "enable") == 0) {
3824 hotkey_enabledisable_warn(1);
3825 } else if (strlencmp(cmd
, "disable") == 0) {
3826 hotkey_enabledisable_warn(0);
3828 } else if (strlencmp(cmd
, "reset") == 0) {
3829 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3830 & ~hotkey_reserved_mask
;
3831 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3833 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3842 tpacpi_disclose_usertask("procfs hotkey",
3843 "set mask to 0x%08x\n", mask
);
3844 res
= hotkey_user_mask_set(mask
);
3848 mutex_unlock(&hotkey_mutex
);
3852 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3853 {TPACPI_ACPI_HKEY_HID
, 0},
3857 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3858 .hid
= ibm_htk_device_ids
,
3859 .notify
= hotkey_notify
,
3860 .handle
= &hkey_handle
,
3861 .type
= ACPI_DEVICE_NOTIFY
,
3864 static struct ibm_struct hotkey_driver_data
= {
3866 .read
= hotkey_read
,
3867 .write
= hotkey_write
,
3868 .exit
= hotkey_exit
,
3869 .resume
= hotkey_resume
,
3870 .suspend
= hotkey_suspend
,
3871 .acpi
= &ibm_hotkey_acpidriver
,
3874 /*************************************************************************
3875 * Bluetooth subdriver
3879 /* ACPI GBDC/SBDC bits */
3880 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3881 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3882 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3883 0 = disable, 1 = enable */
3887 /* ACPI \BLTH commands */
3888 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3889 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3890 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3891 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3892 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3895 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3897 static int bluetooth_get_status(void)
3901 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3902 if (dbg_bluetoothemul
)
3903 return (tpacpi_bluetooth_emulstate
) ?
3904 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3907 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3910 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3911 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3914 static int bluetooth_set_status(enum tpacpi_rfkill_state state
)
3918 vdbg_printk(TPACPI_DBG_RFKILL
,
3919 "will attempt to %s bluetooth\n",
3920 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
3922 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3923 if (dbg_bluetoothemul
) {
3924 tpacpi_bluetooth_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
3929 if (state
== TPACPI_RFK_RADIO_ON
)
3930 status
= TP_ACPI_BLUETOOTH_RADIOSSW
3931 | TP_ACPI_BLUETOOTH_RESUMECTRL
;
3935 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3941 /* sysfs bluetooth enable ---------------------------------------------- */
3942 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3943 struct device_attribute
*attr
,
3946 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID
,
3950 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3951 struct device_attribute
*attr
,
3952 const char *buf
, size_t count
)
3954 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID
,
3958 static struct device_attribute dev_attr_bluetooth_enable
=
3959 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3960 bluetooth_enable_show
, bluetooth_enable_store
);
3962 /* --------------------------------------------------------------------- */
3964 static struct attribute
*bluetooth_attributes
[] = {
3965 &dev_attr_bluetooth_enable
.attr
,
3969 static const struct attribute_group bluetooth_attr_group
= {
3970 .attrs
= bluetooth_attributes
,
3973 static const struct tpacpi_rfk_ops bluetooth_tprfk_ops
= {
3974 .get_status
= bluetooth_get_status
,
3975 .set_status
= bluetooth_set_status
,
3978 static void bluetooth_shutdown(void)
3980 /* Order firmware to save current state to NVRAM */
3981 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3982 TP_ACPI_BLTH_SAVE_STATE
))
3983 printk(TPACPI_NOTICE
3984 "failed to save bluetooth state to NVRAM\n");
3986 vdbg_printk(TPACPI_DBG_RFKILL
,
3987 "bluestooth state saved to NVRAM\n");
3990 static void bluetooth_exit(void)
3992 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3993 &bluetooth_attr_group
);
3995 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
3997 bluetooth_shutdown();
4000 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
4005 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4006 "initializing bluetooth subdriver\n");
4008 TPACPI_ACPIHANDLE_INIT(hkey
);
4010 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4011 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
4012 tp_features
.bluetooth
= hkey_handle
&&
4013 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
4015 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4016 "bluetooth is %s, status 0x%02x\n",
4017 str_supported(tp_features
.bluetooth
),
4020 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4021 if (dbg_bluetoothemul
) {
4022 tp_features
.bluetooth
= 1;
4024 "bluetooth switch emulation enabled\n");
4027 if (tp_features
.bluetooth
&&
4028 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
4029 /* no bluetooth hardware present in system */
4030 tp_features
.bluetooth
= 0;
4031 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4032 "bluetooth hardware not installed\n");
4035 if (!tp_features
.bluetooth
)
4038 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
4039 &bluetooth_tprfk_ops
,
4040 RFKILL_TYPE_BLUETOOTH
,
4041 TPACPI_RFK_BLUETOOTH_SW_NAME
,
4046 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4047 &bluetooth_attr_group
);
4049 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
4056 /* procfs -------------------------------------------------------------- */
4057 static int bluetooth_read(struct seq_file
*m
)
4059 return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID
, m
);
4062 static int bluetooth_write(char *buf
)
4064 return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID
, buf
);
4067 static struct ibm_struct bluetooth_driver_data
= {
4068 .name
= "bluetooth",
4069 .read
= bluetooth_read
,
4070 .write
= bluetooth_write
,
4071 .exit
= bluetooth_exit
,
4072 .shutdown
= bluetooth_shutdown
,
4075 /*************************************************************************
4080 /* ACPI GWAN/SWAN bits */
4081 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
4082 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
4083 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
4084 0 = disable, 1 = enable */
4087 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
4089 static int wan_get_status(void)
4093 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4095 return (tpacpi_wwan_emulstate
) ?
4096 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4099 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
4102 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
4103 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4106 static int wan_set_status(enum tpacpi_rfkill_state state
)
4110 vdbg_printk(TPACPI_DBG_RFKILL
,
4111 "will attempt to %s wwan\n",
4112 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4114 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4116 tpacpi_wwan_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4121 if (state
== TPACPI_RFK_RADIO_ON
)
4122 status
= TP_ACPI_WANCARD_RADIOSSW
4123 | TP_ACPI_WANCARD_RESUMECTRL
;
4127 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
4133 /* sysfs wan enable ---------------------------------------------------- */
4134 static ssize_t
wan_enable_show(struct device
*dev
,
4135 struct device_attribute
*attr
,
4138 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID
,
4142 static ssize_t
wan_enable_store(struct device
*dev
,
4143 struct device_attribute
*attr
,
4144 const char *buf
, size_t count
)
4146 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID
,
4150 static struct device_attribute dev_attr_wan_enable
=
4151 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4152 wan_enable_show
, wan_enable_store
);
4154 /* --------------------------------------------------------------------- */
4156 static struct attribute
*wan_attributes
[] = {
4157 &dev_attr_wan_enable
.attr
,
4161 static const struct attribute_group wan_attr_group
= {
4162 .attrs
= wan_attributes
,
4165 static const struct tpacpi_rfk_ops wan_tprfk_ops
= {
4166 .get_status
= wan_get_status
,
4167 .set_status
= wan_set_status
,
4170 static void wan_shutdown(void)
4172 /* Order firmware to save current state to NVRAM */
4173 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4174 TP_ACPI_WGSV_SAVE_STATE
))
4175 printk(TPACPI_NOTICE
4176 "failed to save WWAN state to NVRAM\n");
4178 vdbg_printk(TPACPI_DBG_RFKILL
,
4179 "WWAN state saved to NVRAM\n");
4182 static void wan_exit(void)
4184 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4187 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4192 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4197 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4198 "initializing wan subdriver\n");
4200 TPACPI_ACPIHANDLE_INIT(hkey
);
4202 tp_features
.wan
= hkey_handle
&&
4203 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4205 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4206 "wan is %s, status 0x%02x\n",
4207 str_supported(tp_features
.wan
),
4210 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4212 tp_features
.wan
= 1;
4214 "wwan switch emulation enabled\n");
4217 if (tp_features
.wan
&&
4218 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4219 /* no wan hardware present in system */
4220 tp_features
.wan
= 0;
4221 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4222 "wan hardware not installed\n");
4225 if (!tp_features
.wan
)
4228 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4231 TPACPI_RFK_WWAN_SW_NAME
,
4236 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4240 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4247 /* procfs -------------------------------------------------------------- */
4248 static int wan_read(struct seq_file
*m
)
4250 return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID
, m
);
4253 static int wan_write(char *buf
)
4255 return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID
, buf
);
4258 static struct ibm_struct wan_driver_data
= {
4263 .shutdown
= wan_shutdown
,
4266 /*************************************************************************
4271 /* ACPI GUWB/SUWB bits */
4272 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4273 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4276 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4278 static int uwb_get_status(void)
4282 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4284 return (tpacpi_uwb_emulstate
) ?
4285 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4288 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4291 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4292 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4295 static int uwb_set_status(enum tpacpi_rfkill_state state
)
4299 vdbg_printk(TPACPI_DBG_RFKILL
,
4300 "will attempt to %s UWB\n",
4301 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4303 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4305 tpacpi_uwb_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4310 if (state
== TPACPI_RFK_RADIO_ON
)
4311 status
= TP_ACPI_UWB_RADIOSSW
;
4315 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4321 /* --------------------------------------------------------------------- */
4323 static const struct tpacpi_rfk_ops uwb_tprfk_ops
= {
4324 .get_status
= uwb_get_status
,
4325 .set_status
= uwb_set_status
,
4328 static void uwb_exit(void)
4330 tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID
);
4333 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4338 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4339 "initializing uwb subdriver\n");
4341 TPACPI_ACPIHANDLE_INIT(hkey
);
4343 tp_features
.uwb
= hkey_handle
&&
4344 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4346 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4347 "uwb is %s, status 0x%02x\n",
4348 str_supported(tp_features
.uwb
),
4351 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4353 tp_features
.uwb
= 1;
4355 "uwb switch emulation enabled\n");
4358 if (tp_features
.uwb
&&
4359 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4360 /* no uwb hardware present in system */
4361 tp_features
.uwb
= 0;
4362 dbg_printk(TPACPI_DBG_INIT
,
4363 "uwb hardware not installed\n");
4366 if (!tp_features
.uwb
)
4369 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4372 TPACPI_RFK_UWB_SW_NAME
,
4377 static struct ibm_struct uwb_driver_data
= {
4380 .flags
.experimental
= 1,
4383 /*************************************************************************
4387 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4389 enum video_access_mode
{
4390 TPACPI_VIDEO_NONE
= 0,
4391 TPACPI_VIDEO_570
, /* 570 */
4392 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4393 TPACPI_VIDEO_NEW
, /* all others */
4396 enum { /* video status flags, based on VIDEO_570 */
4397 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4398 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4399 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4402 enum { /* TPACPI_VIDEO_570 constants */
4403 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4404 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4405 * video_status_flags */
4406 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4407 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4410 static enum video_access_mode video_supported
;
4411 static int video_orig_autosw
;
4413 static int video_autosw_get(void);
4414 static int video_autosw_set(int enable
);
4416 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4418 static int __init
video_init(struct ibm_init_struct
*iibm
)
4422 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4424 TPACPI_ACPIHANDLE_INIT(vid
);
4425 TPACPI_ACPIHANDLE_INIT(vid2
);
4427 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4428 /* G41, assume IVGA doesn't change */
4429 vid_handle
= vid2_handle
;
4432 /* video switching not supported on R30, R31 */
4433 video_supported
= TPACPI_VIDEO_NONE
;
4434 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4436 video_supported
= TPACPI_VIDEO_570
;
4437 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4438 /* 600e/x, 770e, 770x */
4439 video_supported
= TPACPI_VIDEO_770
;
4442 video_supported
= TPACPI_VIDEO_NEW
;
4444 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4445 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4448 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4451 static void video_exit(void)
4453 dbg_printk(TPACPI_DBG_EXIT
,
4454 "restoring original video autoswitch mode\n");
4455 if (video_autosw_set(video_orig_autosw
))
4456 printk(TPACPI_ERR
"error while trying to restore original "
4457 "video autoswitch mode\n");
4460 static int video_outputsw_get(void)
4465 switch (video_supported
) {
4466 case TPACPI_VIDEO_570
:
4467 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4468 TP_ACPI_VIDEO_570_PHSCMD
))
4470 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4472 case TPACPI_VIDEO_770
:
4473 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4476 status
|= TP_ACPI_VIDEO_S_LCD
;
4477 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4480 status
|= TP_ACPI_VIDEO_S_CRT
;
4482 case TPACPI_VIDEO_NEW
:
4483 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4484 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4487 status
|= TP_ACPI_VIDEO_S_CRT
;
4489 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4490 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4493 status
|= TP_ACPI_VIDEO_S_LCD
;
4494 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4497 status
|= TP_ACPI_VIDEO_S_DVI
;
4506 static int video_outputsw_set(int status
)
4511 switch (video_supported
) {
4512 case TPACPI_VIDEO_570
:
4513 res
= acpi_evalf(NULL
, NULL
,
4514 "\\_SB.PHS2", "vdd",
4515 TP_ACPI_VIDEO_570_PHS2CMD
,
4516 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4518 case TPACPI_VIDEO_770
:
4519 autosw
= video_autosw_get();
4523 res
= video_autosw_set(1);
4526 res
= acpi_evalf(vid_handle
, NULL
,
4527 "ASWT", "vdd", status
* 0x100, 0);
4528 if (!autosw
&& video_autosw_set(autosw
)) {
4530 "video auto-switch left enabled due to error\n");
4534 case TPACPI_VIDEO_NEW
:
4535 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4536 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4542 return (res
)? 0 : -EIO
;
4545 static int video_autosw_get(void)
4549 switch (video_supported
) {
4550 case TPACPI_VIDEO_570
:
4551 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4554 case TPACPI_VIDEO_770
:
4555 case TPACPI_VIDEO_NEW
:
4556 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4566 static int video_autosw_set(int enable
)
4568 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4573 static int video_outputsw_cycle(void)
4575 int autosw
= video_autosw_get();
4581 switch (video_supported
) {
4582 case TPACPI_VIDEO_570
:
4583 res
= video_autosw_set(1);
4586 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4588 case TPACPI_VIDEO_770
:
4589 case TPACPI_VIDEO_NEW
:
4590 res
= video_autosw_set(1);
4593 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4598 if (!autosw
&& video_autosw_set(autosw
)) {
4600 "video auto-switch left enabled due to error\n");
4604 return (res
)? 0 : -EIO
;
4607 static int video_expand_toggle(void)
4609 switch (video_supported
) {
4610 case TPACPI_VIDEO_570
:
4611 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4613 case TPACPI_VIDEO_770
:
4614 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4616 case TPACPI_VIDEO_NEW
:
4617 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4625 static int video_read(struct seq_file
*m
)
4629 if (video_supported
== TPACPI_VIDEO_NONE
) {
4630 seq_printf(m
, "status:\t\tnot supported\n");
4634 /* Even reads can crash X.org, so... */
4635 if (!capable(CAP_SYS_ADMIN
))
4638 status
= video_outputsw_get();
4642 autosw
= video_autosw_get();
4646 seq_printf(m
, "status:\t\tsupported\n");
4647 seq_printf(m
, "lcd:\t\t%s\n", enabled(status
, 0));
4648 seq_printf(m
, "crt:\t\t%s\n", enabled(status
, 1));
4649 if (video_supported
== TPACPI_VIDEO_NEW
)
4650 seq_printf(m
, "dvi:\t\t%s\n", enabled(status
, 3));
4651 seq_printf(m
, "auto:\t\t%s\n", enabled(autosw
, 0));
4652 seq_printf(m
, "commands:\tlcd_enable, lcd_disable\n");
4653 seq_printf(m
, "commands:\tcrt_enable, crt_disable\n");
4654 if (video_supported
== TPACPI_VIDEO_NEW
)
4655 seq_printf(m
, "commands:\tdvi_enable, dvi_disable\n");
4656 seq_printf(m
, "commands:\tauto_enable, auto_disable\n");
4657 seq_printf(m
, "commands:\tvideo_switch, expand_toggle\n");
4662 static int video_write(char *buf
)
4665 int enable
, disable
, status
;
4668 if (video_supported
== TPACPI_VIDEO_NONE
)
4671 /* Even reads can crash X.org, let alone writes... */
4672 if (!capable(CAP_SYS_ADMIN
))
4678 while ((cmd
= next_cmd(&buf
))) {
4679 if (strlencmp(cmd
, "lcd_enable") == 0) {
4680 enable
|= TP_ACPI_VIDEO_S_LCD
;
4681 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4682 disable
|= TP_ACPI_VIDEO_S_LCD
;
4683 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4684 enable
|= TP_ACPI_VIDEO_S_CRT
;
4685 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4686 disable
|= TP_ACPI_VIDEO_S_CRT
;
4687 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4688 strlencmp(cmd
, "dvi_enable") == 0) {
4689 enable
|= TP_ACPI_VIDEO_S_DVI
;
4690 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4691 strlencmp(cmd
, "dvi_disable") == 0) {
4692 disable
|= TP_ACPI_VIDEO_S_DVI
;
4693 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4694 res
= video_autosw_set(1);
4697 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4698 res
= video_autosw_set(0);
4701 } else if (strlencmp(cmd
, "video_switch") == 0) {
4702 res
= video_outputsw_cycle();
4705 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4706 res
= video_expand_toggle();
4713 if (enable
|| disable
) {
4714 status
= video_outputsw_get();
4717 res
= video_outputsw_set((status
& ~disable
) | enable
);
4725 static struct ibm_struct video_driver_data
= {
4728 .write
= video_write
,
4732 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4734 /*************************************************************************
4735 * Light (thinklight) subdriver
4738 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4739 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4741 static int light_get_status(void)
4745 if (tp_features
.light_status
) {
4746 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4754 static int light_set_status(int status
)
4758 if (tp_features
.light
) {
4760 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4762 TP_CMOS_THINKLIGHT_ON
:
4763 TP_CMOS_THINKLIGHT_OFF
);
4765 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4768 return (rc
)? 0 : -EIO
;
4774 static void light_set_status_worker(struct work_struct
*work
)
4776 struct tpacpi_led_classdev
*data
=
4777 container_of(work
, struct tpacpi_led_classdev
, work
);
4779 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4780 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4783 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4784 enum led_brightness brightness
)
4786 struct tpacpi_led_classdev
*data
=
4787 container_of(led_cdev
,
4788 struct tpacpi_led_classdev
,
4790 data
->new_state
= (brightness
!= LED_OFF
) ?
4791 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4792 queue_work(tpacpi_wq
, &data
->work
);
4795 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4797 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4800 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4802 .name
= "tpacpi::thinklight",
4803 .brightness_set
= &light_sysfs_set
,
4804 .brightness_get
= &light_sysfs_get
,
4808 static int __init
light_init(struct ibm_init_struct
*iibm
)
4812 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4814 TPACPI_ACPIHANDLE_INIT(ledb
);
4815 TPACPI_ACPIHANDLE_INIT(lght
);
4816 TPACPI_ACPIHANDLE_INIT(cmos
);
4817 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4819 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4820 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4822 if (tp_features
.light
)
4823 /* light status not supported on
4824 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4825 tp_features
.light_status
=
4826 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4828 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4829 str_supported(tp_features
.light
),
4830 str_supported(tp_features
.light_status
));
4832 if (!tp_features
.light
)
4835 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4836 &tpacpi_led_thinklight
.led_classdev
);
4839 tp_features
.light
= 0;
4840 tp_features
.light_status
= 0;
4848 static void light_exit(void)
4850 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4851 if (work_pending(&tpacpi_led_thinklight
.work
))
4852 flush_workqueue(tpacpi_wq
);
4855 static int light_read(struct seq_file
*m
)
4859 if (!tp_features
.light
) {
4860 seq_printf(m
, "status:\t\tnot supported\n");
4861 } else if (!tp_features
.light_status
) {
4862 seq_printf(m
, "status:\t\tunknown\n");
4863 seq_printf(m
, "commands:\ton, off\n");
4865 status
= light_get_status();
4868 seq_printf(m
, "status:\t\t%s\n", onoff(status
, 0));
4869 seq_printf(m
, "commands:\ton, off\n");
4875 static int light_write(char *buf
)
4880 if (!tp_features
.light
)
4883 while ((cmd
= next_cmd(&buf
))) {
4884 if (strlencmp(cmd
, "on") == 0) {
4886 } else if (strlencmp(cmd
, "off") == 0) {
4892 return light_set_status(newstatus
);
4895 static struct ibm_struct light_driver_data
= {
4898 .write
= light_write
,
4902 /*************************************************************************
4906 /* sysfs cmos_command -------------------------------------------------- */
4907 static ssize_t
cmos_command_store(struct device
*dev
,
4908 struct device_attribute
*attr
,
4909 const char *buf
, size_t count
)
4911 unsigned long cmos_cmd
;
4914 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4917 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4918 return (res
)? res
: count
;
4921 static struct device_attribute dev_attr_cmos_command
=
4922 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4924 /* --------------------------------------------------------------------- */
4926 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4930 vdbg_printk(TPACPI_DBG_INIT
,
4931 "initializing cmos commands subdriver\n");
4933 TPACPI_ACPIHANDLE_INIT(cmos
);
4935 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4936 str_supported(cmos_handle
!= NULL
));
4938 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4942 return (cmos_handle
)? 0 : 1;
4945 static void cmos_exit(void)
4947 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4950 static int cmos_read(struct seq_file
*m
)
4952 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4953 R30, R31, T20-22, X20-21 */
4955 seq_printf(m
, "status:\t\tnot supported\n");
4957 seq_printf(m
, "status:\t\tsupported\n");
4958 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4964 static int cmos_write(char *buf
)
4969 while ((cmd
= next_cmd(&buf
))) {
4970 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4971 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4976 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4984 static struct ibm_struct cmos_driver_data
= {
4987 .write
= cmos_write
,
4991 /*************************************************************************
4995 enum led_access_mode
{
4996 TPACPI_LED_NONE
= 0,
4997 TPACPI_LED_570
, /* 570 */
4998 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4999 TPACPI_LED_NEW
, /* all others */
5002 enum { /* For TPACPI_LED_OLD */
5003 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
5004 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
5005 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
5008 static enum led_access_mode led_supported
;
5010 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
5011 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
5012 /* T20-22, X20-21 */
5013 "LED", /* all others */
5016 #define TPACPI_LED_NUMLEDS 16
5017 static struct tpacpi_led_classdev
*tpacpi_leds
;
5018 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
5019 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
5020 /* there's a limit of 19 chars + NULL before 2.6.26 */
5022 "tpacpi:orange:batt",
5023 "tpacpi:green:batt",
5024 "tpacpi::dock_active",
5025 "tpacpi::bay_active",
5026 "tpacpi::dock_batt",
5027 "tpacpi::unknown_led",
5029 "tpacpi::dock_status1",
5030 "tpacpi::dock_status2",
5031 "tpacpi::unknown_led2",
5032 "tpacpi::unknown_led3",
5033 "tpacpi::thinkvantage",
5035 #define TPACPI_SAFE_LEDS 0x1081U
5037 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
5039 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5042 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
5046 static int led_get_status(const unsigned int led
)
5049 enum led_status_t led_s
;
5051 switch (led_supported
) {
5052 case TPACPI_LED_570
:
5053 if (!acpi_evalf(ec_handle
,
5054 &status
, "GLED", "dd", 1 << led
))
5056 led_s
= (status
== 0)?
5061 tpacpi_led_state_cache
[led
] = led_s
;
5070 static int led_set_status(const unsigned int led
,
5071 const enum led_status_t ledstatus
)
5073 /* off, on, blink. Index is led_status_t */
5074 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
5075 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
5079 switch (led_supported
) {
5080 case TPACPI_LED_570
:
5082 if (unlikely(led
> 7))
5084 if (unlikely(tpacpi_is_led_restricted(led
)))
5086 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5087 (1 << led
), led_sled_arg1
[ledstatus
]))
5090 case TPACPI_LED_OLD
:
5091 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
5092 if (unlikely(led
> 7))
5094 if (unlikely(tpacpi_is_led_restricted(led
)))
5096 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
5098 rc
= ec_write(TPACPI_LED_EC_HLBL
,
5099 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5101 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5102 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5104 case TPACPI_LED_NEW
:
5106 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5108 if (unlikely(tpacpi_is_led_restricted(led
)))
5110 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5111 led
, led_led_arg1
[ledstatus
]))
5119 tpacpi_led_state_cache
[led
] = ledstatus
;
5124 static void led_set_status_worker(struct work_struct
*work
)
5126 struct tpacpi_led_classdev
*data
=
5127 container_of(work
, struct tpacpi_led_classdev
, work
);
5129 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5130 led_set_status(data
->led
, data
->new_state
);
5133 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5134 enum led_brightness brightness
)
5136 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5137 struct tpacpi_led_classdev
, led_classdev
);
5139 if (brightness
== LED_OFF
)
5140 data
->new_state
= TPACPI_LED_OFF
;
5141 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5142 data
->new_state
= TPACPI_LED_ON
;
5144 data
->new_state
= TPACPI_LED_BLINK
;
5146 queue_work(tpacpi_wq
, &data
->work
);
5149 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5150 unsigned long *delay_on
, unsigned long *delay_off
)
5152 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5153 struct tpacpi_led_classdev
, led_classdev
);
5155 /* Can we choose the flash rate? */
5156 if (*delay_on
== 0 && *delay_off
== 0) {
5157 /* yes. set them to the hardware blink rate (1 Hz) */
5158 *delay_on
= 500; /* ms */
5159 *delay_off
= 500; /* ms */
5160 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5163 data
->new_state
= TPACPI_LED_BLINK
;
5164 queue_work(tpacpi_wq
, &data
->work
);
5169 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5173 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5174 struct tpacpi_led_classdev
, led_classdev
);
5176 rc
= led_get_status(data
->led
);
5178 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5179 rc
= LED_OFF
; /* no error handling in led class :( */
5186 static void led_exit(void)
5190 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5191 if (tpacpi_leds
[i
].led_classdev
.name
)
5192 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5198 static int __init
tpacpi_init_led(unsigned int led
)
5202 tpacpi_leds
[led
].led
= led
;
5204 /* LEDs with no name don't get registered */
5205 if (!tpacpi_led_names
[led
])
5208 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5209 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5210 if (led_supported
== TPACPI_LED_570
)
5211 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5214 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5216 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5218 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5219 &tpacpi_leds
[led
].led_classdev
);
5221 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5226 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5227 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5228 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5229 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5231 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5232 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5233 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5234 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5235 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5236 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5237 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5238 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5240 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5241 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5242 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5243 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5244 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5246 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5247 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5248 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5249 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5251 /* (1) - may have excess leds enabled on MSB */
5253 /* Defaults (order matters, keep last, don't reorder!) */
5255 .vendor
= PCI_VENDOR_ID_LENOVO
,
5256 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5259 { /* IBM ThinkPads with no EC version string */
5260 .vendor
= PCI_VENDOR_ID_IBM
,
5261 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5264 { /* IBM ThinkPads with EC version string */
5265 .vendor
= PCI_VENDOR_ID_IBM
,
5266 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5271 #undef TPACPI_LEDQ_IBM
5272 #undef TPACPI_LEDQ_LNV
5274 static int __init
led_init(struct ibm_init_struct
*iibm
)
5278 unsigned long useful_leds
;
5280 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5282 TPACPI_ACPIHANDLE_INIT(led
);
5285 /* led not supported on R30, R31 */
5286 led_supported
= TPACPI_LED_NONE
;
5287 else if (strlencmp(led_path
, "SLED") == 0)
5289 led_supported
= TPACPI_LED_570
;
5290 else if (strlencmp(led_path
, "SYSL") == 0)
5291 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5292 led_supported
= TPACPI_LED_OLD
;
5295 led_supported
= TPACPI_LED_NEW
;
5297 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5298 str_supported(led_supported
), led_supported
);
5300 if (led_supported
== TPACPI_LED_NONE
)
5303 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5306 printk(TPACPI_ERR
"Out of memory for LED data\n");
5310 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5311 ARRAY_SIZE(led_useful_qtable
));
5313 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5314 if (!tpacpi_is_led_restricted(i
) &&
5315 test_bit(i
, &useful_leds
)) {
5316 rc
= tpacpi_init_led(i
);
5324 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5325 printk(TPACPI_NOTICE
5326 "warning: userspace override of important "
5327 "firmware LEDs is enabled\n");
5332 #define str_led_status(s) \
5333 ((s) == TPACPI_LED_OFF ? "off" : \
5334 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5336 static int led_read(struct seq_file
*m
)
5338 if (!led_supported
) {
5339 seq_printf(m
, "status:\t\tnot supported\n");
5342 seq_printf(m
, "status:\t\tsupported\n");
5344 if (led_supported
== TPACPI_LED_570
) {
5347 for (i
= 0; i
< 8; i
++) {
5348 status
= led_get_status(i
);
5351 seq_printf(m
, "%d:\t\t%s\n",
5352 i
, str_led_status(status
));
5356 seq_printf(m
, "commands:\t"
5357 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5362 static int led_write(char *buf
)
5366 enum led_status_t s
;
5371 while ((cmd
= next_cmd(&buf
))) {
5372 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5375 if (strstr(cmd
, "off")) {
5377 } else if (strstr(cmd
, "on")) {
5379 } else if (strstr(cmd
, "blink")) {
5380 s
= TPACPI_LED_BLINK
;
5385 rc
= led_set_status(led
, s
);
5393 static struct ibm_struct led_driver_data
= {
5400 /*************************************************************************
5404 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5406 #define TPACPI_BEEP_Q1 0x0001
5408 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5409 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5410 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5413 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5415 unsigned long quirks
;
5417 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5419 TPACPI_ACPIHANDLE_INIT(beep
);
5421 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5422 str_supported(beep_handle
!= NULL
));
5424 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5425 ARRAY_SIZE(beep_quirk_table
));
5427 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5429 return (beep_handle
)? 0 : 1;
5432 static int beep_read(struct seq_file
*m
)
5435 seq_printf(m
, "status:\t\tnot supported\n");
5437 seq_printf(m
, "status:\t\tsupported\n");
5438 seq_printf(m
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5444 static int beep_write(char *buf
)
5452 while ((cmd
= next_cmd(&buf
))) {
5453 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5454 beep_cmd
>= 0 && beep_cmd
<= 17) {
5458 if (tp_features
.beep_needs_two_args
) {
5459 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5463 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5472 static struct ibm_struct beep_driver_data
= {
5475 .write
= beep_write
,
5478 /*************************************************************************
5482 enum thermal_access_mode
{
5483 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5484 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5485 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5486 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5487 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5490 enum { /* TPACPI_THERMAL_TPEC_* */
5491 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5492 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5493 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5495 TPACPI_THERMAL_SENSOR_NA
= -128000, /* Sensor not available */
5499 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5500 struct ibm_thermal_sensors_struct
{
5501 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5504 static enum thermal_access_mode thermal_read_mode
;
5506 /* idx is zero-based */
5507 static int thermal_get_sensor(int idx
, s32
*value
)
5513 t
= TP_EC_THERMAL_TMP0
;
5515 switch (thermal_read_mode
) {
5516 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5517 case TPACPI_THERMAL_TPEC_16
:
5518 if (idx
>= 8 && idx
<= 15) {
5519 t
= TP_EC_THERMAL_TMP8
;
5524 case TPACPI_THERMAL_TPEC_8
:
5526 if (!acpi_ec_read(t
+ idx
, &tmp
))
5528 *value
= tmp
* 1000;
5533 case TPACPI_THERMAL_ACPI_UPDT
:
5535 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5536 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5538 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5540 *value
= (t
- 2732) * 100;
5545 case TPACPI_THERMAL_ACPI_TMP07
:
5547 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5548 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5550 if (t
> 127 || t
< -127)
5551 t
= TP_EC_THERMAL_TMP_NA
;
5557 case TPACPI_THERMAL_NONE
:
5565 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5576 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5579 for (i
= 0 ; i
< n
; i
++) {
5580 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5588 static void thermal_dump_all_sensors(void)
5591 struct ibm_thermal_sensors_struct t
;
5593 n
= thermal_get_sensors(&t
);
5597 printk(TPACPI_NOTICE
5598 "temperatures (Celsius):");
5600 for (i
= 0; i
< n
; i
++) {
5601 if (t
.temp
[i
] != TPACPI_THERMAL_SENSOR_NA
)
5602 printk(KERN_CONT
" %d", (int)(t
.temp
[i
] / 1000));
5604 printk(KERN_CONT
" N/A");
5607 printk(KERN_CONT
"\n");
5610 /* sysfs temp##_input -------------------------------------------------- */
5612 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5613 struct device_attribute
*attr
,
5616 struct sensor_device_attribute
*sensor_attr
=
5617 to_sensor_dev_attr(attr
);
5618 int idx
= sensor_attr
->index
;
5622 res
= thermal_get_sensor(idx
, &value
);
5625 if (value
== TPACPI_THERMAL_SENSOR_NA
)
5628 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5631 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5632 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5633 thermal_temp_input_show, NULL, _idxB)
5635 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5636 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5637 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5638 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5639 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5640 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5641 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5642 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5643 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5644 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5645 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5646 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5647 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5648 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5649 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5650 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5651 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5654 #define THERMAL_ATTRS(X) \
5655 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5657 static struct attribute
*thermal_temp_input_attr
[] = {
5677 static const struct attribute_group thermal_temp_input16_group
= {
5678 .attrs
= thermal_temp_input_attr
5681 static const struct attribute_group thermal_temp_input8_group
= {
5682 .attrs
= &thermal_temp_input_attr
[8]
5685 #undef THERMAL_SENSOR_ATTR_TEMP
5686 #undef THERMAL_ATTRS
5688 /* --------------------------------------------------------------------- */
5690 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5697 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5699 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5701 if (thinkpad_id
.ec_model
) {
5703 * Direct EC access mode: sensors at registers
5704 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5705 * non-implemented, thermal sensors return 0x80 when
5710 for (i
= 0; i
< 8; i
++) {
5711 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5717 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5725 /* This is sheer paranoia, but we handle it anyway */
5728 "ThinkPad ACPI EC access misbehaving, "
5729 "falling back to ACPI TMPx access "
5731 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5734 "ThinkPad ACPI EC access misbehaving, "
5735 "disabling thermal sensors access\n");
5736 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5741 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5743 } else if (acpi_tmp7
) {
5744 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5745 /* 600e/x, 770e, 770x */
5746 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5748 /* Standard ACPI TMPx access, max 8 sensors */
5749 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5752 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5753 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5756 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5757 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5760 switch (thermal_read_mode
) {
5761 case TPACPI_THERMAL_TPEC_16
:
5762 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5763 &thermal_temp_input16_group
);
5767 case TPACPI_THERMAL_TPEC_8
:
5768 case TPACPI_THERMAL_ACPI_TMP07
:
5769 case TPACPI_THERMAL_ACPI_UPDT
:
5770 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5771 &thermal_temp_input8_group
);
5775 case TPACPI_THERMAL_NONE
:
5783 static void thermal_exit(void)
5785 switch (thermal_read_mode
) {
5786 case TPACPI_THERMAL_TPEC_16
:
5787 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5788 &thermal_temp_input16_group
);
5790 case TPACPI_THERMAL_TPEC_8
:
5791 case TPACPI_THERMAL_ACPI_TMP07
:
5792 case TPACPI_THERMAL_ACPI_UPDT
:
5793 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5794 &thermal_temp_input8_group
);
5796 case TPACPI_THERMAL_NONE
:
5802 static int thermal_read(struct seq_file
*m
)
5805 struct ibm_thermal_sensors_struct t
;
5807 n
= thermal_get_sensors(&t
);
5808 if (unlikely(n
< 0))
5811 seq_printf(m
, "temperatures:\t");
5814 for (i
= 0; i
< (n
- 1); i
++)
5815 seq_printf(m
, "%d ", t
.temp
[i
] / 1000);
5816 seq_printf(m
, "%d\n", t
.temp
[i
] / 1000);
5818 seq_printf(m
, "not supported\n");
5823 static struct ibm_struct thermal_driver_data
= {
5825 .read
= thermal_read
,
5826 .exit
= thermal_exit
,
5829 /*************************************************************************
5833 static u8 ecdump_regs
[256];
5835 static int ecdump_read(struct seq_file
*m
)
5841 " +00 +01 +02 +03 +04 +05 +06 +07"
5842 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5843 for (i
= 0; i
< 256; i
+= 16) {
5844 seq_printf(m
, "EC 0x%02x:", i
);
5845 for (j
= 0; j
< 16; j
++) {
5846 if (!acpi_ec_read(i
+ j
, &v
))
5848 if (v
!= ecdump_regs
[i
+ j
])
5849 seq_printf(m
, " *%02x", v
);
5851 seq_printf(m
, " %02x", v
);
5852 ecdump_regs
[i
+ j
] = v
;
5859 /* These are way too dangerous to advertise openly... */
5861 seq_printf(m
, "commands:\t0x<offset> 0x<value>"
5862 " (<offset> is 00-ff, <value> is 00-ff)\n");
5863 seq_printf(m
, "commands:\t0x<offset> <value> "
5864 " (<offset> is 00-ff, <value> is 0-255)\n");
5869 static int ecdump_write(char *buf
)
5874 while ((cmd
= next_cmd(&buf
))) {
5875 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5877 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5881 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5882 if (!acpi_ec_write(i
, v
))
5891 static struct ibm_struct ecdump_driver_data
= {
5893 .read
= ecdump_read
,
5894 .write
= ecdump_write
,
5895 .flags
.experimental
= 1,
5898 /*************************************************************************
5899 * Backlight/brightness subdriver
5902 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5905 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5906 * CMOS NVRAM byte 0x5E, bits 0-3.
5908 * EC HBRV (0x31) has the following layout
5909 * Bit 7: unknown function
5910 * Bit 6: unknown function
5911 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5912 * Bit 4: must be set to zero to avoid problems
5913 * Bit 3-0: backlight brightness level
5915 * brightness_get_raw returns status data in the HBRV layout
5917 * WARNING: The X61 has been verified to use HBRV for something else, so
5918 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5919 * testing on the very early *60 Lenovo models...
5923 TP_EC_BACKLIGHT
= 0x31,
5925 /* TP_EC_BACKLIGHT bitmasks */
5926 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5927 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5928 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5931 enum tpacpi_brightness_access_mode
{
5932 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5933 TPACPI_BRGHT_MODE_EC
, /* EC control */
5934 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5935 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5936 TPACPI_BRGHT_MODE_MAX
5939 static struct backlight_device
*ibm_backlight_device
;
5941 static enum tpacpi_brightness_access_mode brightness_mode
=
5942 TPACPI_BRGHT_MODE_MAX
;
5944 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5946 static struct mutex brightness_mutex
;
5948 /* NVRAM brightness access,
5949 * call with brightness_mutex held! */
5950 static unsigned int tpacpi_brightness_nvram_get(void)
5954 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5955 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5956 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5957 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5962 static void tpacpi_brightness_checkpoint_nvram(void)
5967 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5970 vdbg_printk(TPACPI_DBG_BRGHT
,
5971 "trying to checkpoint backlight level to NVRAM...\n");
5973 if (mutex_lock_killable(&brightness_mutex
) < 0)
5976 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5978 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5979 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5981 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5982 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5983 /* NVRAM needs update */
5984 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5985 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5987 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5988 dbg_printk(TPACPI_DBG_BRGHT
,
5989 "updated NVRAM backlight level to %u (0x%02x)\n",
5990 (unsigned int) lec
, (unsigned int) b_nvram
);
5992 vdbg_printk(TPACPI_DBG_BRGHT
,
5993 "NVRAM backlight level already is %u (0x%02x)\n",
5994 (unsigned int) lec
, (unsigned int) b_nvram
);
5997 mutex_unlock(&brightness_mutex
);
6001 /* call with brightness_mutex held! */
6002 static int tpacpi_brightness_get_raw(int *status
)
6006 switch (brightness_mode
) {
6007 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6008 *status
= tpacpi_brightness_nvram_get();
6010 case TPACPI_BRGHT_MODE_EC
:
6011 case TPACPI_BRGHT_MODE_ECNVRAM
:
6012 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6021 /* call with brightness_mutex held! */
6022 /* do NOT call with illegal backlight level value */
6023 static int tpacpi_brightness_set_ec(unsigned int value
)
6027 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6030 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
6031 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
6032 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
6038 /* call with brightness_mutex held! */
6039 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
6042 unsigned int current_value
, i
;
6044 current_value
= tpacpi_brightness_nvram_get();
6046 if (value
== current_value
)
6049 cmos_cmd
= (value
> current_value
) ?
6050 TP_CMOS_BRIGHTNESS_UP
:
6051 TP_CMOS_BRIGHTNESS_DOWN
;
6052 inc
= (value
> current_value
) ? 1 : -1;
6054 for (i
= current_value
; i
!= value
; i
+= inc
)
6055 if (issue_thinkpad_cmos_command(cmos_cmd
))
6061 /* May return EINTR which can always be mapped to ERESTARTSYS */
6062 static int brightness_set(unsigned int value
)
6066 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
6070 vdbg_printk(TPACPI_DBG_BRGHT
,
6071 "set backlight level to %d\n", value
);
6073 res
= mutex_lock_killable(&brightness_mutex
);
6077 switch (brightness_mode
) {
6078 case TPACPI_BRGHT_MODE_EC
:
6079 case TPACPI_BRGHT_MODE_ECNVRAM
:
6080 res
= tpacpi_brightness_set_ec(value
);
6082 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6083 res
= tpacpi_brightness_set_ucmsstep(value
);
6089 mutex_unlock(&brightness_mutex
);
6093 /* sysfs backlight class ----------------------------------------------- */
6095 static int brightness_update_status(struct backlight_device
*bd
)
6097 unsigned int level
=
6098 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
6099 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
6100 bd
->props
.brightness
: 0;
6102 dbg_printk(TPACPI_DBG_BRGHT
,
6103 "backlight: attempt to set level to %d\n",
6106 /* it is the backlight class's job (caller) to handle
6107 * EINTR and other errors properly */
6108 return brightness_set(level
);
6111 static int brightness_get(struct backlight_device
*bd
)
6115 res
= mutex_lock_killable(&brightness_mutex
);
6119 res
= tpacpi_brightness_get_raw(&status
);
6121 mutex_unlock(&brightness_mutex
);
6126 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6129 static void tpacpi_brightness_notify_change(void)
6131 backlight_force_update(ibm_backlight_device
,
6132 BACKLIGHT_UPDATE_HOTKEY
);
6135 static struct backlight_ops ibm_backlight_data
= {
6136 .get_brightness
= brightness_get
,
6137 .update_status
= brightness_update_status
,
6140 /* --------------------------------------------------------------------- */
6143 * These are only useful for models that have only one possibility
6144 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6147 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6148 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6149 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6151 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6152 /* Models with ATI GPUs known to require ECNVRAM mode */
6153 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6155 /* Models with ATI GPUs that can use ECNVRAM */
6156 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
), /* R50,51 T40-42 */
6157 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6158 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC
), /* R52 */
6159 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6161 /* Models with Intel Extreme Graphics 2 */
6162 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
), /* X40 */
6163 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6164 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6166 /* Models with Intel GMA900 */
6167 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6168 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6169 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6172 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6174 struct backlight_properties props
;
6176 unsigned long quirks
;
6178 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6180 mutex_init(&brightness_mutex
);
6182 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6183 ARRAY_SIZE(brightness_quirk_table
));
6186 * We always attempt to detect acpi support, so as to switch
6187 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6188 * going to publish a backlight interface
6190 b
= tpacpi_check_std_acpi_brightness_support();
6193 if (acpi_video_backlight_support()) {
6194 if (brightness_enable
> 1) {
6195 printk(TPACPI_NOTICE
6196 "Standard ACPI backlight interface "
6197 "available, not loading native one.\n");
6199 } else if (brightness_enable
== 1) {
6200 printk(TPACPI_NOTICE
6201 "Backlight control force enabled, even if standard "
6202 "ACPI backlight interface is available\n");
6205 if (brightness_enable
> 1) {
6206 printk(TPACPI_NOTICE
6207 "Standard ACPI backlight interface not "
6208 "available, thinkpad_acpi native "
6209 "brightness control enabled\n");
6214 if (!brightness_enable
) {
6215 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6216 "brightness support disabled by "
6217 "module parameter\n");
6223 "Unsupported brightness interface, "
6224 "please contact %s\n", TPACPI_MAIL
);
6228 tp_features
.bright_16levels
= 1;
6231 * Check for module parameter bogosity, note that we
6232 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6233 * able to detect "unspecified"
6235 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6238 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6239 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6240 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6241 if (quirks
& TPACPI_BRGHT_Q_EC
)
6242 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6244 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6246 dbg_printk(TPACPI_DBG_BRGHT
,
6247 "driver auto-selected brightness_mode=%d\n",
6252 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6253 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6254 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6257 if (tpacpi_brightness_get_raw(&b
) < 0)
6260 if (tp_features
.bright_16levels
)
6262 "detected a 16-level brightness capable ThinkPad\n");
6264 memset(&props
, 0, sizeof(struct backlight_properties
));
6265 props
.max_brightness
= (tp_features
.bright_16levels
) ? 15 : 7;
6266 ibm_backlight_device
= backlight_device_register(TPACPI_BACKLIGHT_DEV_NAME
,
6268 &ibm_backlight_data
,
6270 if (IS_ERR(ibm_backlight_device
)) {
6271 int rc
= PTR_ERR(ibm_backlight_device
);
6272 ibm_backlight_device
= NULL
;
6273 printk(TPACPI_ERR
"Could not register backlight device\n");
6276 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6277 "brightness is supported\n");
6279 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6280 printk(TPACPI_NOTICE
6281 "brightness: will use unverified default: "
6282 "brightness_mode=%d\n", brightness_mode
);
6283 printk(TPACPI_NOTICE
6284 "brightness: please report to %s whether it works well "
6285 "or not on your ThinkPad\n", TPACPI_MAIL
);
6288 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6289 backlight_update_status(ibm_backlight_device
);
6291 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6292 "brightness: registering brightness hotkeys "
6293 "as change notification\n");
6294 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6295 | TP_ACPI_HKEY_BRGHTUP_MASK
6296 | TP_ACPI_HKEY_BRGHTDWN_MASK
);;
6300 static void brightness_suspend(pm_message_t state
)
6302 tpacpi_brightness_checkpoint_nvram();
6305 static void brightness_shutdown(void)
6307 tpacpi_brightness_checkpoint_nvram();
6310 static void brightness_exit(void)
6312 if (ibm_backlight_device
) {
6313 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6314 "calling backlight_device_unregister()\n");
6315 backlight_device_unregister(ibm_backlight_device
);
6318 tpacpi_brightness_checkpoint_nvram();
6321 static int brightness_read(struct seq_file
*m
)
6325 level
= brightness_get(NULL
);
6327 seq_printf(m
, "level:\t\tunreadable\n");
6329 seq_printf(m
, "level:\t\t%d\n", level
);
6330 seq_printf(m
, "commands:\tup, down\n");
6331 seq_printf(m
, "commands:\tlevel <level>"
6332 " (<level> is 0-%d)\n",
6333 (tp_features
.bright_16levels
) ? 15 : 7);
6339 static int brightness_write(char *buf
)
6344 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6346 level
= brightness_get(NULL
);
6350 while ((cmd
= next_cmd(&buf
))) {
6351 if (strlencmp(cmd
, "up") == 0) {
6352 if (level
< max_level
)
6354 } else if (strlencmp(cmd
, "down") == 0) {
6357 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6358 level
>= 0 && level
<= max_level
) {
6364 tpacpi_disclose_usertask("procfs brightness",
6365 "set level to %d\n", level
);
6368 * Now we know what the final level should be, so we try to set it.
6369 * Doing it this way makes the syscall restartable in case of EINTR
6371 rc
= brightness_set(level
);
6372 if (!rc
&& ibm_backlight_device
)
6373 backlight_force_update(ibm_backlight_device
,
6374 BACKLIGHT_UPDATE_SYSFS
);
6375 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6378 static struct ibm_struct brightness_driver_data
= {
6379 .name
= "brightness",
6380 .read
= brightness_read
,
6381 .write
= brightness_write
,
6382 .exit
= brightness_exit
,
6383 .suspend
= brightness_suspend
,
6384 .shutdown
= brightness_shutdown
,
6387 /*************************************************************************
6392 * IBM ThinkPads have a simple volume controller with MUTE gating.
6393 * Very early Lenovo ThinkPads follow the IBM ThinkPad spec.
6395 * Since the *61 series (and probably also the later *60 series), Lenovo
6396 * ThinkPads only implement the MUTE gate.
6399 * Bit 6: MUTE (1 mutes sound)
6401 * Other bits should be zero as far as we know.
6403 * This is also stored in CMOS NVRAM, byte 0x60, bit 6 (MUTE), and
6404 * bits 3-0 (volume). Other bits in NVRAM may have other functions,
6405 * such as bit 7 which is used to detect repeated presses of MUTE,
6406 * and we leave them unchanged.
6409 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
6411 #define TPACPI_ALSA_DRVNAME "ThinkPad EC"
6412 #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control"
6413 #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME
6415 static int alsa_index
= ~((1 << (SNDRV_CARDS
- 3)) - 1); /* last three slots */
6416 static char *alsa_id
= "ThinkPadEC";
6417 static int alsa_enable
= SNDRV_DEFAULT_ENABLE1
;
6419 struct tpacpi_alsa_data
{
6420 struct snd_card
*card
;
6421 struct snd_ctl_elem_id
*ctl_mute_id
;
6422 struct snd_ctl_elem_id
*ctl_vol_id
;
6425 static struct snd_card
*alsa_card
;
6430 /* TP_EC_AUDIO bits */
6431 TP_EC_AUDIO_MUTESW
= 6,
6433 /* TP_EC_AUDIO bitmasks */
6434 TP_EC_AUDIO_LVL_MSK
= 0x0F,
6435 TP_EC_AUDIO_MUTESW_MSK
= (1 << TP_EC_AUDIO_MUTESW
),
6437 /* Maximum volume */
6438 TP_EC_VOLUME_MAX
= 14,
6441 enum tpacpi_volume_access_mode
{
6442 TPACPI_VOL_MODE_AUTO
= 0, /* Not implemented yet */
6443 TPACPI_VOL_MODE_EC
, /* Pure EC control */
6444 TPACPI_VOL_MODE_UCMS_STEP
, /* UCMS step-based control: N/A */
6445 TPACPI_VOL_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
6449 enum tpacpi_volume_capabilities
{
6450 TPACPI_VOL_CAP_AUTO
= 0, /* Use white/blacklist */
6451 TPACPI_VOL_CAP_VOLMUTE
, /* Output vol and mute */
6452 TPACPI_VOL_CAP_MUTEONLY
, /* Output mute only */
6456 static enum tpacpi_volume_access_mode volume_mode
=
6457 TPACPI_VOL_MODE_MAX
;
6459 static enum tpacpi_volume_capabilities volume_capabilities
;
6460 static int volume_control_allowed
;
6463 * Used to syncronize writers to TP_EC_AUDIO and
6464 * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write
6466 static struct mutex volume_mutex
;
6468 static void tpacpi_volume_checkpoint_nvram(void)
6474 if (volume_mode
!= TPACPI_VOL_MODE_ECNVRAM
)
6476 if (!volume_control_allowed
)
6479 vdbg_printk(TPACPI_DBG_MIXER
,
6480 "trying to checkpoint mixer state to NVRAM...\n");
6482 if (tp_features
.mixer_no_level_control
)
6483 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
;
6485 ec_mask
= TP_EC_AUDIO_MUTESW_MSK
| TP_EC_AUDIO_LVL_MSK
;
6487 if (mutex_lock_killable(&volume_mutex
) < 0)
6490 if (unlikely(!acpi_ec_read(TP_EC_AUDIO
, &lec
)))
6493 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
6495 if (lec
!= (b_nvram
& ec_mask
)) {
6496 /* NVRAM needs update */
6497 b_nvram
&= ~ec_mask
;
6499 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_MIXER
);
6500 dbg_printk(TPACPI_DBG_MIXER
,
6501 "updated NVRAM mixer status to 0x%02x (0x%02x)\n",
6502 (unsigned int) lec
, (unsigned int) b_nvram
);
6504 vdbg_printk(TPACPI_DBG_MIXER
,
6505 "NVRAM mixer status already is 0x%02x (0x%02x)\n",
6506 (unsigned int) lec
, (unsigned int) b_nvram
);
6510 mutex_unlock(&volume_mutex
);
6513 static int volume_get_status_ec(u8
*status
)
6517 if (!acpi_ec_read(TP_EC_AUDIO
, &s
))
6522 dbg_printk(TPACPI_DBG_MIXER
, "status 0x%02x\n", s
);
6527 static int volume_get_status(u8
*status
)
6529 return volume_get_status_ec(status
);
6532 static int volume_set_status_ec(const u8 status
)
6534 if (!acpi_ec_write(TP_EC_AUDIO
, status
))
6537 dbg_printk(TPACPI_DBG_MIXER
, "set EC mixer to 0x%02x\n", status
);
6542 static int volume_set_status(const u8 status
)
6544 return volume_set_status_ec(status
);
6547 /* returns < 0 on error, 0 on no change, 1 on change */
6548 static int __volume_set_mute_ec(const bool mute
)
6553 if (mutex_lock_killable(&volume_mutex
) < 0)
6556 rc
= volume_get_status_ec(&s
);
6560 n
= (mute
) ? s
| TP_EC_AUDIO_MUTESW_MSK
:
6561 s
& ~TP_EC_AUDIO_MUTESW_MSK
;
6564 rc
= volume_set_status_ec(n
);
6570 mutex_unlock(&volume_mutex
);
6574 static int volume_alsa_set_mute(const bool mute
)
6576 dbg_printk(TPACPI_DBG_MIXER
, "ALSA: trying to %smute\n",
6577 (mute
) ? "" : "un");
6578 return __volume_set_mute_ec(mute
);
6581 static int volume_set_mute(const bool mute
)
6585 dbg_printk(TPACPI_DBG_MIXER
, "trying to %smute\n",
6586 (mute
) ? "" : "un");
6588 rc
= __volume_set_mute_ec(mute
);
6589 return (rc
< 0) ? rc
: 0;
6592 /* returns < 0 on error, 0 on no change, 1 on change */
6593 static int __volume_set_volume_ec(const u8 vol
)
6598 if (vol
> TP_EC_VOLUME_MAX
)
6601 if (mutex_lock_killable(&volume_mutex
) < 0)
6604 rc
= volume_get_status_ec(&s
);
6608 n
= (s
& ~TP_EC_AUDIO_LVL_MSK
) | vol
;
6611 rc
= volume_set_status_ec(n
);
6617 mutex_unlock(&volume_mutex
);
6621 static int volume_alsa_set_volume(const u8 vol
)
6623 dbg_printk(TPACPI_DBG_MIXER
,
6624 "ALSA: trying to set volume level to %hu\n", vol
);
6625 return __volume_set_volume_ec(vol
);
6628 static void volume_alsa_notify_change(void)
6630 struct tpacpi_alsa_data
*d
;
6632 if (alsa_card
&& alsa_card
->private_data
) {
6633 d
= alsa_card
->private_data
;
6635 snd_ctl_notify(alsa_card
,
6636 SNDRV_CTL_EVENT_MASK_VALUE
,
6639 snd_ctl_notify(alsa_card
,
6640 SNDRV_CTL_EVENT_MASK_VALUE
,
6645 static int volume_alsa_vol_info(struct snd_kcontrol
*kcontrol
,
6646 struct snd_ctl_elem_info
*uinfo
)
6648 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
6650 uinfo
->value
.integer
.min
= 0;
6651 uinfo
->value
.integer
.max
= TP_EC_VOLUME_MAX
;
6655 static int volume_alsa_vol_get(struct snd_kcontrol
*kcontrol
,
6656 struct snd_ctl_elem_value
*ucontrol
)
6661 rc
= volume_get_status(&s
);
6665 ucontrol
->value
.integer
.value
[0] = s
& TP_EC_AUDIO_LVL_MSK
;
6669 static int volume_alsa_vol_put(struct snd_kcontrol
*kcontrol
,
6670 struct snd_ctl_elem_value
*ucontrol
)
6672 return volume_alsa_set_volume(ucontrol
->value
.integer
.value
[0]);
6675 #define volume_alsa_mute_info snd_ctl_boolean_mono_info
6677 static int volume_alsa_mute_get(struct snd_kcontrol
*kcontrol
,
6678 struct snd_ctl_elem_value
*ucontrol
)
6683 rc
= volume_get_status(&s
);
6687 ucontrol
->value
.integer
.value
[0] =
6688 (s
& TP_EC_AUDIO_MUTESW_MSK
) ? 0 : 1;
6692 static int volume_alsa_mute_put(struct snd_kcontrol
*kcontrol
,
6693 struct snd_ctl_elem_value
*ucontrol
)
6695 return volume_alsa_set_mute(!ucontrol
->value
.integer
.value
[0]);
6698 static struct snd_kcontrol_new volume_alsa_control_vol __devinitdata
= {
6699 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6700 .name
= "Console Playback Volume",
6702 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6703 .info
= volume_alsa_vol_info
,
6704 .get
= volume_alsa_vol_get
,
6707 static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata
= {
6708 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
6709 .name
= "Console Playback Switch",
6711 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
6712 .info
= volume_alsa_mute_info
,
6713 .get
= volume_alsa_mute_get
,
6716 static void volume_suspend(pm_message_t state
)
6718 tpacpi_volume_checkpoint_nvram();
6721 static void volume_resume(void)
6723 volume_alsa_notify_change();
6726 static void volume_shutdown(void)
6728 tpacpi_volume_checkpoint_nvram();
6731 static void volume_exit(void)
6734 snd_card_free(alsa_card
);
6738 tpacpi_volume_checkpoint_nvram();
6741 static int __init
volume_create_alsa_mixer(void)
6743 struct snd_card
*card
;
6744 struct tpacpi_alsa_data
*data
;
6745 struct snd_kcontrol
*ctl_vol
;
6746 struct snd_kcontrol
*ctl_mute
;
6749 rc
= snd_card_create(alsa_index
, alsa_id
, THIS_MODULE
,
6750 sizeof(struct tpacpi_alsa_data
), &card
);
6751 if (rc
< 0 || !card
) {
6753 "Failed to create ALSA card structures: %d\n", rc
);
6757 BUG_ON(!card
->private_data
);
6758 data
= card
->private_data
;
6761 strlcpy(card
->driver
, TPACPI_ALSA_DRVNAME
,
6762 sizeof(card
->driver
));
6763 strlcpy(card
->shortname
, TPACPI_ALSA_SHRTNAME
,
6764 sizeof(card
->shortname
));
6765 snprintf(card
->mixername
, sizeof(card
->mixername
), "ThinkPad EC %s",
6766 (thinkpad_id
.ec_version_str
) ?
6767 thinkpad_id
.ec_version_str
: "(unknown)");
6768 snprintf(card
->longname
, sizeof(card
->longname
),
6769 "%s at EC reg 0x%02x, fw %s", card
->shortname
, TP_EC_AUDIO
,
6770 (thinkpad_id
.ec_version_str
) ?
6771 thinkpad_id
.ec_version_str
: "unknown");
6773 if (volume_control_allowed
) {
6774 volume_alsa_control_vol
.put
= volume_alsa_vol_put
;
6775 volume_alsa_control_vol
.access
=
6776 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6778 volume_alsa_control_mute
.put
= volume_alsa_mute_put
;
6779 volume_alsa_control_mute
.access
=
6780 SNDRV_CTL_ELEM_ACCESS_READWRITE
;
6783 if (!tp_features
.mixer_no_level_control
) {
6784 ctl_vol
= snd_ctl_new1(&volume_alsa_control_vol
, NULL
);
6785 rc
= snd_ctl_add(card
, ctl_vol
);
6788 "Failed to create ALSA volume control: %d\n",
6792 data
->ctl_vol_id
= &ctl_vol
->id
;
6795 ctl_mute
= snd_ctl_new1(&volume_alsa_control_mute
, NULL
);
6796 rc
= snd_ctl_add(card
, ctl_mute
);
6798 printk(TPACPI_ERR
"Failed to create ALSA mute control: %d\n",
6802 data
->ctl_mute_id
= &ctl_mute
->id
;
6804 snd_card_set_dev(card
, &tpacpi_pdev
->dev
);
6805 rc
= snd_card_register(card
);
6807 printk(TPACPI_ERR
"Failed to register ALSA card: %d\n", rc
);
6815 snd_card_free(card
);
6819 #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */
6820 #define TPACPI_VOL_Q_LEVEL 0x0002 /* Volume control available */
6822 static const struct tpacpi_quirk volume_quirk_table
[] __initconst
= {
6823 /* Whitelist volume level on all IBM by default */
6824 { .vendor
= PCI_VENDOR_ID_IBM
,
6825 .bios
= TPACPI_MATCH_ANY
,
6826 .ec
= TPACPI_MATCH_ANY
,
6827 .quirks
= TPACPI_VOL_Q_LEVEL
},
6829 /* Lenovo models with volume control (needs confirmation) */
6830 TPACPI_QEC_LNV('7', 'C', TPACPI_VOL_Q_LEVEL
), /* R60/i */
6831 TPACPI_QEC_LNV('7', 'E', TPACPI_VOL_Q_LEVEL
), /* R60e/i */
6832 TPACPI_QEC_LNV('7', '9', TPACPI_VOL_Q_LEVEL
), /* T60/p */
6833 TPACPI_QEC_LNV('7', 'B', TPACPI_VOL_Q_LEVEL
), /* X60/s */
6834 TPACPI_QEC_LNV('7', 'J', TPACPI_VOL_Q_LEVEL
), /* X60t */
6835 TPACPI_QEC_LNV('7', '7', TPACPI_VOL_Q_LEVEL
), /* Z60 */
6836 TPACPI_QEC_LNV('7', 'F', TPACPI_VOL_Q_LEVEL
), /* Z61 */
6838 /* Whitelist mute-only on all Lenovo by default */
6839 { .vendor
= PCI_VENDOR_ID_LENOVO
,
6840 .bios
= TPACPI_MATCH_ANY
,
6841 .ec
= TPACPI_MATCH_ANY
,
6842 .quirks
= TPACPI_VOL_Q_MUTEONLY
}
6845 static int __init
volume_init(struct ibm_init_struct
*iibm
)
6847 unsigned long quirks
;
6850 vdbg_printk(TPACPI_DBG_INIT
, "initializing volume subdriver\n");
6852 mutex_init(&volume_mutex
);
6855 * Check for module parameter bogosity, note that we
6856 * init volume_mode to TPACPI_VOL_MODE_MAX in order to be
6857 * able to detect "unspecified"
6859 if (volume_mode
> TPACPI_VOL_MODE_MAX
)
6862 if (volume_mode
== TPACPI_VOL_MODE_UCMS_STEP
) {
6864 "UCMS step volume mode not implemented, "
6865 "please contact %s\n", TPACPI_MAIL
);
6869 if (volume_capabilities
>= TPACPI_VOL_CAP_MAX
)
6873 * The ALSA mixer is our primary interface.
6874 * When disabled, don't install the subdriver at all
6877 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6878 "ALSA mixer disabled by parameter, "
6879 "not loading volume subdriver...\n");
6883 quirks
= tpacpi_check_quirks(volume_quirk_table
,
6884 ARRAY_SIZE(volume_quirk_table
));
6886 switch (volume_capabilities
) {
6887 case TPACPI_VOL_CAP_AUTO
:
6888 if (quirks
& TPACPI_VOL_Q_MUTEONLY
)
6889 tp_features
.mixer_no_level_control
= 1;
6890 else if (quirks
& TPACPI_VOL_Q_LEVEL
)
6891 tp_features
.mixer_no_level_control
= 0;
6893 return 1; /* no mixer */
6895 case TPACPI_VOL_CAP_VOLMUTE
:
6896 tp_features
.mixer_no_level_control
= 0;
6898 case TPACPI_VOL_CAP_MUTEONLY
:
6899 tp_features
.mixer_no_level_control
= 1;
6905 if (volume_capabilities
!= TPACPI_VOL_CAP_AUTO
)
6906 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6907 "using user-supplied volume_capabilities=%d\n",
6908 volume_capabilities
);
6910 if (volume_mode
== TPACPI_VOL_MODE_AUTO
||
6911 volume_mode
== TPACPI_VOL_MODE_MAX
) {
6912 volume_mode
= TPACPI_VOL_MODE_ECNVRAM
;
6914 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6915 "driver auto-selected volume_mode=%d\n",
6918 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6919 "using user-supplied volume_mode=%d\n",
6923 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6924 "mute is supported, volume control is %s\n",
6925 str_supported(!tp_features
.mixer_no_level_control
));
6927 rc
= volume_create_alsa_mixer();
6930 "Could not create the ALSA mixer interface\n");
6935 "Console audio control enabled, mode: %s\n",
6936 (volume_control_allowed
) ?
6937 "override (read/write)" :
6938 "monitor (read only)");
6940 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_MIXER
,
6941 "registering volume hotkeys as change notification\n");
6942 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6943 | TP_ACPI_HKEY_VOLUP_MASK
6944 | TP_ACPI_HKEY_VOLDWN_MASK
6945 | TP_ACPI_HKEY_MUTE_MASK
);
6950 static int volume_read(struct seq_file
*m
)
6954 if (volume_get_status(&status
) < 0) {
6955 seq_printf(m
, "level:\t\tunreadable\n");
6957 if (tp_features
.mixer_no_level_control
)
6958 seq_printf(m
, "level:\t\tunsupported\n");
6960 seq_printf(m
, "level:\t\t%d\n",
6961 status
& TP_EC_AUDIO_LVL_MSK
);
6963 seq_printf(m
, "mute:\t\t%s\n",
6964 onoff(status
, TP_EC_AUDIO_MUTESW
));
6966 if (volume_control_allowed
) {
6967 seq_printf(m
, "commands:\tunmute, mute\n");
6968 if (!tp_features
.mixer_no_level_control
) {
6970 "commands:\tup, down\n");
6972 "commands:\tlevel <level>"
6973 " (<level> is 0-%d)\n",
6982 static int volume_write(char *buf
)
6985 u8 new_level
, new_mute
;
6991 * We do allow volume control at driver startup, so that the
6992 * user can set initial state through the volume=... parameter hack.
6994 if (!volume_control_allowed
&& tpacpi_lifecycle
!= TPACPI_LIFE_INIT
) {
6995 if (unlikely(!tp_warned
.volume_ctrl_forbidden
)) {
6996 tp_warned
.volume_ctrl_forbidden
= 1;
6997 printk(TPACPI_NOTICE
6998 "Console audio control in monitor mode, "
6999 "changes are not allowed.\n");
7000 printk(TPACPI_NOTICE
7001 "Use the volume_control=1 module parameter "
7002 "to enable volume control\n");
7007 rc
= volume_get_status(&s
);
7011 new_level
= s
& TP_EC_AUDIO_LVL_MSK
;
7012 new_mute
= s
& TP_EC_AUDIO_MUTESW_MSK
;
7014 while ((cmd
= next_cmd(&buf
))) {
7015 if (!tp_features
.mixer_no_level_control
) {
7016 if (strlencmp(cmd
, "up") == 0) {
7019 else if (new_level
< TP_EC_VOLUME_MAX
)
7022 } else if (strlencmp(cmd
, "down") == 0) {
7025 else if (new_level
> 0)
7028 } else if (sscanf(cmd
, "level %u", &l
) == 1 &&
7029 l
>= 0 && l
<= TP_EC_VOLUME_MAX
) {
7034 if (strlencmp(cmd
, "mute") == 0)
7035 new_mute
= TP_EC_AUDIO_MUTESW_MSK
;
7036 else if (strlencmp(cmd
, "unmute") == 0)
7042 if (tp_features
.mixer_no_level_control
) {
7043 tpacpi_disclose_usertask("procfs volume", "%smute\n",
7044 new_mute
? "" : "un");
7045 rc
= volume_set_mute(!!new_mute
);
7047 tpacpi_disclose_usertask("procfs volume",
7048 "%smute and set level to %d\n",
7049 new_mute
? "" : "un", new_level
);
7050 rc
= volume_set_status(new_mute
| new_level
);
7052 volume_alsa_notify_change();
7054 return (rc
== -EINTR
) ? -ERESTARTSYS
: rc
;
7057 static struct ibm_struct volume_driver_data
= {
7059 .read
= volume_read
,
7060 .write
= volume_write
,
7061 .exit
= volume_exit
,
7062 .suspend
= volume_suspend
,
7063 .resume
= volume_resume
,
7064 .shutdown
= volume_shutdown
,
7067 #else /* !CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
7069 #define alsa_card NULL
7071 static void inline volume_alsa_notify_change(void)
7075 static int __init
volume_init(struct ibm_init_struct
*iibm
)
7078 "volume: disabled as there is no ALSA support in this kernel\n");
7083 static struct ibm_struct volume_driver_data
= {
7087 #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
7089 /*************************************************************************
7096 * TPACPI_FAN_RD_ACPI_GFAN:
7097 * ACPI GFAN method: returns fan level
7099 * see TPACPI_FAN_WR_ACPI_SFAN
7100 * EC 0x2f (HFSP) not available if GFAN exists
7102 * TPACPI_FAN_WR_ACPI_SFAN:
7103 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
7105 * EC 0x2f (HFSP) might be available *for reading*, but do not use
7108 * TPACPI_FAN_WR_TPEC:
7109 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
7110 * Supported on almost all ThinkPads
7112 * Fan speed changes of any sort (including those caused by the
7113 * disengaged mode) are usually done slowly by the firmware as the
7114 * maximum amount of fan duty cycle change per second seems to be
7117 * Reading is not available if GFAN exists.
7118 * Writing is not available if SFAN exists.
7121 * 7 automatic mode engaged;
7122 * (default operation mode of the ThinkPad)
7123 * fan level is ignored in this mode.
7124 * 6 full speed mode (takes precedence over bit 7);
7125 * not available on all thinkpads. May disable
7126 * the tachometer while the fan controller ramps up
7127 * the speed (which can take up to a few *minutes*).
7128 * Speeds up fan to 100% duty-cycle, which is far above
7129 * the standard RPM levels. It is not impossible that
7130 * it could cause hardware damage.
7131 * 5-3 unused in some models. Extra bits for fan level
7132 * in others, but still useless as all values above
7133 * 7 map to the same speed as level 7 in these models.
7134 * 2-0 fan level (0..7 usually)
7136 * 0x07 = max (set when temperatures critical)
7137 * Some ThinkPads may have other levels, see
7138 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
7140 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
7141 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
7142 * does so, its initial value is meaningless (0x07).
7144 * For firmware bugs, refer to:
7145 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7149 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
7150 * Main fan tachometer reading (in RPM)
7152 * This register is present on all ThinkPads with a new-style EC, and
7153 * it is known not to be present on the A21m/e, and T22, as there is
7154 * something else in offset 0x84 according to the ACPI DSDT. Other
7155 * ThinkPads from this same time period (and earlier) probably lack the
7156 * tachometer as well.
7158 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
7159 * was never fixed by IBM to report the EC firmware version string
7160 * probably support the tachometer (like the early X models), so
7161 * detecting it is quite hard. We need more data to know for sure.
7163 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
7166 * FIRMWARE BUG: may go stale while the EC is switching to full speed
7169 * For firmware bugs, refer to:
7170 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
7174 * ThinkPad EC register 0x31 bit 0 (only on select models)
7176 * When bit 0 of EC register 0x31 is zero, the tachometer registers
7177 * show the speed of the main fan. When bit 0 of EC register 0x31
7178 * is one, the tachometer registers show the speed of the auxiliary
7181 * Fan control seems to affect both fans, regardless of the state
7184 * So far, only the firmware for the X60/X61 non-tablet versions
7185 * seem to support this (firmware TP-7M).
7187 * TPACPI_FAN_WR_ACPI_FANS:
7188 * ThinkPad X31, X40, X41. Not available in the X60.
7190 * FANS ACPI handle: takes three arguments: low speed, medium speed,
7191 * high speed. ACPI DSDT seems to map these three speeds to levels
7192 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
7193 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
7195 * The speeds are stored on handles
7196 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
7198 * There are three default speed sets, accessible as handles:
7199 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
7201 * ACPI DSDT switches which set is in use depending on various
7204 * TPACPI_FAN_WR_TPEC is also available and should be used to
7205 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
7206 * but the ACPI tables just mention level 7.
7209 enum { /* Fan control constants */
7210 fan_status_offset
= 0x2f, /* EC register 0x2f */
7211 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
7212 * 0x84 must be read before 0x85 */
7213 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
7214 bit 0 selects which fan is active */
7216 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
7217 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
7219 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
7222 enum fan_status_access_mode
{
7223 TPACPI_FAN_NONE
= 0, /* No fan status or control */
7224 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
7225 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
7228 enum fan_control_access_mode
{
7229 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
7230 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
7231 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
7232 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
7235 enum fan_control_commands
{
7236 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
7237 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
7238 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
7239 * and also watchdog cmd */
7242 static int fan_control_allowed
;
7244 static enum fan_status_access_mode fan_status_access_mode
;
7245 static enum fan_control_access_mode fan_control_access_mode
;
7246 static enum fan_control_commands fan_control_commands
;
7248 static u8 fan_control_initial_status
;
7249 static u8 fan_control_desired_level
;
7250 static u8 fan_control_resume_level
;
7251 static int fan_watchdog_maxinterval
;
7253 static struct mutex fan_mutex
;
7255 static void fan_watchdog_fire(struct work_struct
*ignored
);
7256 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
7258 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
7259 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
7260 "\\FSPD", /* 600e/x, 770e, 770x */
7262 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
7263 "JFNS", /* 770x-JL */
7267 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
7268 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
7269 * be in auto mode (0x80).
7271 * This is corrected by any write to HFSP either by the driver, or
7274 * We assume 0x07 really means auto mode while this quirk is active,
7275 * as this is far more likely than the ThinkPad being in level 7,
7276 * which is only used by the firmware during thermal emergencies.
7278 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
7279 * TP-70 (T43, R52), which are known to be buggy.
7282 static void fan_quirk1_setup(void)
7284 if (fan_control_initial_status
== 0x07) {
7285 printk(TPACPI_NOTICE
7286 "fan_init: initial fan status is unknown, "
7287 "assuming it is in auto mode\n");
7288 tp_features
.fan_ctrl_status_undef
= 1;
7292 static void fan_quirk1_handle(u8
*fan_status
)
7294 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
7295 if (*fan_status
!= fan_control_initial_status
) {
7296 /* something changed the HFSP regisnter since
7297 * driver init time, so it is not undefined
7299 tp_features
.fan_ctrl_status_undef
= 0;
7301 /* Return most likely status. In fact, it
7302 * might be the only possible status */
7303 *fan_status
= TP_EC_FAN_AUTO
;
7308 /* Select main fan on X60/X61, NOOP on others */
7309 static bool fan_select_fan1(void)
7311 if (tp_features
.second_fan
) {
7314 if (ec_read(fan_select_offset
, &val
) < 0)
7317 if (ec_write(fan_select_offset
, val
) < 0)
7323 /* Select secondary fan on X60/X61 */
7324 static bool fan_select_fan2(void)
7328 if (!tp_features
.second_fan
)
7331 if (ec_read(fan_select_offset
, &val
) < 0)
7334 if (ec_write(fan_select_offset
, val
) < 0)
7341 * Call with fan_mutex held
7343 static void fan_update_desired_level(u8 status
)
7346 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7348 fan_control_desired_level
= 7;
7350 fan_control_desired_level
= status
;
7354 static int fan_get_status(u8
*status
)
7359 * Add TPACPI_FAN_RD_ACPI_FANS ? */
7361 switch (fan_status_access_mode
) {
7362 case TPACPI_FAN_RD_ACPI_GFAN
:
7363 /* 570, 600e/x, 770e, 770x */
7365 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
7373 case TPACPI_FAN_RD_TPEC
:
7374 /* all except 570, 600e/x, 770e, 770x */
7375 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
7378 if (likely(status
)) {
7380 fan_quirk1_handle(status
);
7392 static int fan_get_status_safe(u8
*status
)
7397 if (mutex_lock_killable(&fan_mutex
))
7398 return -ERESTARTSYS
;
7399 rc
= fan_get_status(&s
);
7401 fan_update_desired_level(s
);
7402 mutex_unlock(&fan_mutex
);
7410 static int fan_get_speed(unsigned int *speed
)
7414 switch (fan_status_access_mode
) {
7415 case TPACPI_FAN_RD_TPEC
:
7416 /* all except 570, 600e/x, 770e, 770x */
7417 if (unlikely(!fan_select_fan1()))
7419 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
7420 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
7424 *speed
= (hi
<< 8) | lo
;
7435 static int fan2_get_speed(unsigned int *speed
)
7440 switch (fan_status_access_mode
) {
7441 case TPACPI_FAN_RD_TPEC
:
7442 /* all except 570, 600e/x, 770e, 770x */
7443 if (unlikely(!fan_select_fan2()))
7445 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
7446 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
7447 fan_select_fan1(); /* play it safe */
7452 *speed
= (hi
<< 8) | lo
;
7463 static int fan_set_level(int level
)
7465 if (!fan_control_allowed
)
7468 switch (fan_control_access_mode
) {
7469 case TPACPI_FAN_WR_ACPI_SFAN
:
7470 if (level
>= 0 && level
<= 7) {
7471 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
7477 case TPACPI_FAN_WR_ACPI_FANS
:
7478 case TPACPI_FAN_WR_TPEC
:
7479 if (!(level
& TP_EC_FAN_AUTO
) &&
7480 !(level
& TP_EC_FAN_FULLSPEED
) &&
7481 ((level
< 0) || (level
> 7)))
7484 /* safety net should the EC not support AUTO
7485 * or FULLSPEED mode bits and just ignore them */
7486 if (level
& TP_EC_FAN_FULLSPEED
)
7487 level
|= 7; /* safety min speed 7 */
7488 else if (level
& TP_EC_FAN_AUTO
)
7489 level
|= 4; /* safety min speed 4 */
7491 if (!acpi_ec_write(fan_status_offset
, level
))
7494 tp_features
.fan_ctrl_status_undef
= 0;
7501 vdbg_printk(TPACPI_DBG_FAN
,
7502 "fan control: set fan control register to 0x%02x\n", level
);
7506 static int fan_set_level_safe(int level
)
7510 if (!fan_control_allowed
)
7513 if (mutex_lock_killable(&fan_mutex
))
7514 return -ERESTARTSYS
;
7516 if (level
== TPACPI_FAN_LAST_LEVEL
)
7517 level
= fan_control_desired_level
;
7519 rc
= fan_set_level(level
);
7521 fan_update_desired_level(level
);
7523 mutex_unlock(&fan_mutex
);
7527 static int fan_set_enable(void)
7532 if (!fan_control_allowed
)
7535 if (mutex_lock_killable(&fan_mutex
))
7536 return -ERESTARTSYS
;
7538 switch (fan_control_access_mode
) {
7539 case TPACPI_FAN_WR_ACPI_FANS
:
7540 case TPACPI_FAN_WR_TPEC
:
7541 rc
= fan_get_status(&s
);
7545 /* Don't go out of emergency fan mode */
7548 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
7551 if (!acpi_ec_write(fan_status_offset
, s
))
7554 tp_features
.fan_ctrl_status_undef
= 0;
7559 case TPACPI_FAN_WR_ACPI_SFAN
:
7560 rc
= fan_get_status(&s
);
7566 /* Set fan to at least level 4 */
7569 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
7579 mutex_unlock(&fan_mutex
);
7582 vdbg_printk(TPACPI_DBG_FAN
,
7583 "fan control: set fan control register to 0x%02x\n",
7588 static int fan_set_disable(void)
7592 if (!fan_control_allowed
)
7595 if (mutex_lock_killable(&fan_mutex
))
7596 return -ERESTARTSYS
;
7599 switch (fan_control_access_mode
) {
7600 case TPACPI_FAN_WR_ACPI_FANS
:
7601 case TPACPI_FAN_WR_TPEC
:
7602 if (!acpi_ec_write(fan_status_offset
, 0x00))
7605 fan_control_desired_level
= 0;
7606 tp_features
.fan_ctrl_status_undef
= 0;
7610 case TPACPI_FAN_WR_ACPI_SFAN
:
7611 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
7614 fan_control_desired_level
= 0;
7622 vdbg_printk(TPACPI_DBG_FAN
,
7623 "fan control: set fan control register to 0\n");
7625 mutex_unlock(&fan_mutex
);
7629 static int fan_set_speed(int speed
)
7633 if (!fan_control_allowed
)
7636 if (mutex_lock_killable(&fan_mutex
))
7637 return -ERESTARTSYS
;
7640 switch (fan_control_access_mode
) {
7641 case TPACPI_FAN_WR_ACPI_FANS
:
7642 if (speed
>= 0 && speed
<= 65535) {
7643 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
7644 speed
, speed
, speed
))
7654 mutex_unlock(&fan_mutex
);
7658 static void fan_watchdog_reset(void)
7660 static int fan_watchdog_active
;
7662 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
7665 if (fan_watchdog_active
)
7666 cancel_delayed_work(&fan_watchdog_task
);
7668 if (fan_watchdog_maxinterval
> 0 &&
7669 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
7670 fan_watchdog_active
= 1;
7671 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
7672 msecs_to_jiffies(fan_watchdog_maxinterval
7675 "failed to queue the fan watchdog, "
7676 "watchdog will not trigger\n");
7679 fan_watchdog_active
= 0;
7682 static void fan_watchdog_fire(struct work_struct
*ignored
)
7686 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
7689 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
7690 rc
= fan_set_enable();
7692 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
7693 "will try again later...\n", -rc
);
7694 /* reschedule for later */
7695 fan_watchdog_reset();
7700 * SYSFS fan layout: hwmon compatible (device)
7703 * 0: "disengaged" mode
7705 * 2: native EC "auto" mode (recommended, hardware default)
7707 * pwm*: set speed in manual mode, ignored otherwise.
7708 * 0 is level 0; 255 is level 7. Intermediate points done with linear
7711 * fan*_input: tachometer reading, RPM
7714 * SYSFS fan layout: extensions
7716 * fan_watchdog (driver):
7717 * fan watchdog interval in seconds, 0 disables (default), max 120
7720 /* sysfs fan pwm1_enable ----------------------------------------------- */
7721 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
7722 struct device_attribute
*attr
,
7728 res
= fan_get_status_safe(&status
);
7732 if (status
& TP_EC_FAN_FULLSPEED
) {
7734 } else if (status
& TP_EC_FAN_AUTO
) {
7739 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
7742 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7743 struct device_attribute
*attr
,
7744 const char *buf
, size_t count
)
7749 if (parse_strtoul(buf
, 2, &t
))
7752 tpacpi_disclose_usertask("hwmon pwm1_enable",
7753 "set fan mode to %lu\n", t
);
7757 level
= TP_EC_FAN_FULLSPEED
;
7760 level
= TPACPI_FAN_LAST_LEVEL
;
7763 level
= TP_EC_FAN_AUTO
;
7766 /* reserved for software-controlled auto mode */
7772 res
= fan_set_level_safe(level
);
7778 fan_watchdog_reset();
7783 static struct device_attribute dev_attr_fan_pwm1_enable
=
7784 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7785 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7787 /* sysfs fan pwm1 ------------------------------------------------------ */
7788 static ssize_t
fan_pwm1_show(struct device
*dev
,
7789 struct device_attribute
*attr
,
7795 res
= fan_get_status_safe(&status
);
7800 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7801 status
= fan_control_desired_level
;
7806 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7809 static ssize_t
fan_pwm1_store(struct device
*dev
,
7810 struct device_attribute
*attr
,
7811 const char *buf
, size_t count
)
7815 u8 status
, newlevel
;
7817 if (parse_strtoul(buf
, 255, &s
))
7820 tpacpi_disclose_usertask("hwmon pwm1",
7821 "set fan speed to %lu\n", s
);
7823 /* scale down from 0-255 to 0-7 */
7824 newlevel
= (s
>> 5) & 0x07;
7826 if (mutex_lock_killable(&fan_mutex
))
7827 return -ERESTARTSYS
;
7829 rc
= fan_get_status(&status
);
7830 if (!rc
&& (status
&
7831 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7832 rc
= fan_set_level(newlevel
);
7836 fan_update_desired_level(newlevel
);
7837 fan_watchdog_reset();
7841 mutex_unlock(&fan_mutex
);
7842 return (rc
)? rc
: count
;
7845 static struct device_attribute dev_attr_fan_pwm1
=
7846 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7847 fan_pwm1_show
, fan_pwm1_store
);
7849 /* sysfs fan fan1_input ------------------------------------------------ */
7850 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7851 struct device_attribute
*attr
,
7857 res
= fan_get_speed(&speed
);
7861 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7864 static struct device_attribute dev_attr_fan_fan1_input
=
7865 __ATTR(fan1_input
, S_IRUGO
,
7866 fan_fan1_input_show
, NULL
);
7868 /* sysfs fan fan2_input ------------------------------------------------ */
7869 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7870 struct device_attribute
*attr
,
7876 res
= fan2_get_speed(&speed
);
7880 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7883 static struct device_attribute dev_attr_fan_fan2_input
=
7884 __ATTR(fan2_input
, S_IRUGO
,
7885 fan_fan2_input_show
, NULL
);
7887 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
7888 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
7891 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
7894 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
7895 const char *buf
, size_t count
)
7899 if (parse_strtoul(buf
, 120, &t
))
7902 if (!fan_control_allowed
)
7905 fan_watchdog_maxinterval
= t
;
7906 fan_watchdog_reset();
7908 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
7913 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
7914 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
7916 /* --------------------------------------------------------------------- */
7917 static struct attribute
*fan_attributes
[] = {
7918 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
7919 &dev_attr_fan_fan1_input
.attr
,
7920 NULL
, /* for fan2_input */
7924 static const struct attribute_group fan_attr_group
= {
7925 .attrs
= fan_attributes
,
7928 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
7929 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
7931 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7932 { .vendor = PCI_VENDOR_ID_IBM, \
7933 .bios = TPACPI_MATCH_ANY, \
7934 .ec = TPID(__id1, __id2), \
7935 .quirks = __quirks }
7937 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7938 { .vendor = PCI_VENDOR_ID_LENOVO, \
7939 .bios = TPACPI_MATCH_ANY, \
7940 .ec = TPID(__id1, __id2), \
7941 .quirks = __quirks }
7943 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
7944 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
7945 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
7946 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
7947 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
7948 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
7951 #undef TPACPI_FAN_QL
7952 #undef TPACPI_FAN_QI
7954 static int __init
fan_init(struct ibm_init_struct
*iibm
)
7957 unsigned long quirks
;
7959 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7960 "initializing fan subdriver\n");
7962 mutex_init(&fan_mutex
);
7963 fan_status_access_mode
= TPACPI_FAN_NONE
;
7964 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7965 fan_control_commands
= 0;
7966 fan_watchdog_maxinterval
= 0;
7967 tp_features
.fan_ctrl_status_undef
= 0;
7968 tp_features
.second_fan
= 0;
7969 fan_control_desired_level
= 7;
7971 TPACPI_ACPIHANDLE_INIT(fans
);
7972 TPACPI_ACPIHANDLE_INIT(gfan
);
7973 TPACPI_ACPIHANDLE_INIT(sfan
);
7975 quirks
= tpacpi_check_quirks(fan_quirk_table
,
7976 ARRAY_SIZE(fan_quirk_table
));
7979 /* 570, 600e/x, 770e, 770x */
7980 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7982 /* all other ThinkPads: note that even old-style
7983 * ThinkPad ECs supports the fan control register */
7984 if (likely(acpi_ec_read(fan_status_offset
,
7985 &fan_control_initial_status
))) {
7986 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7987 if (quirks
& TPACPI_FAN_Q1
)
7989 if (quirks
& TPACPI_FAN_2FAN
) {
7990 tp_features
.second_fan
= 1;
7991 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7992 "secondary fan support enabled\n");
7996 "ThinkPad ACPI EC access misbehaving, "
7997 "fan status and control unavailable\n");
8004 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
8005 fan_control_commands
|=
8006 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
8009 /* gfan without sfan means no fan control */
8010 /* all other models implement TP EC 0x2f control */
8014 fan_control_access_mode
=
8015 TPACPI_FAN_WR_ACPI_FANS
;
8016 fan_control_commands
|=
8017 TPACPI_FAN_CMD_SPEED
|
8018 TPACPI_FAN_CMD_LEVEL
|
8019 TPACPI_FAN_CMD_ENABLE
;
8021 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
8022 fan_control_commands
|=
8023 TPACPI_FAN_CMD_LEVEL
|
8024 TPACPI_FAN_CMD_ENABLE
;
8029 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8030 "fan is %s, modes %d, %d\n",
8031 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
8032 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
8033 fan_status_access_mode
, fan_control_access_mode
);
8035 /* fan control master switch */
8036 if (!fan_control_allowed
) {
8037 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
8038 fan_control_commands
= 0;
8039 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
8040 "fan control features disabled by parameter\n");
8043 /* update fan_control_desired_level */
8044 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
8045 fan_get_status_safe(NULL
);
8047 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
8048 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
8049 if (tp_features
.second_fan
) {
8050 /* attach second fan tachometer */
8051 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
8052 &dev_attr_fan_fan2_input
.attr
;
8054 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8059 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
8060 &driver_attr_fan_watchdog
);
8062 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
8071 static void fan_exit(void)
8073 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
8074 "cancelling any pending fan watchdog tasks\n");
8076 /* FIXME: can we really do this unconditionally? */
8077 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
8078 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
8079 &driver_attr_fan_watchdog
);
8081 cancel_delayed_work(&fan_watchdog_task
);
8082 flush_workqueue(tpacpi_wq
);
8085 static void fan_suspend(pm_message_t state
)
8089 if (!fan_control_allowed
)
8092 /* Store fan status in cache */
8093 fan_control_resume_level
= 0;
8094 rc
= fan_get_status_safe(&fan_control_resume_level
);
8096 printk(TPACPI_NOTICE
8097 "failed to read fan level for later "
8098 "restore during resume: %d\n", rc
);
8100 /* if it is undefined, don't attempt to restore it.
8102 if (tp_features
.fan_ctrl_status_undef
)
8103 fan_control_resume_level
= 0;
8106 static void fan_resume(void)
8108 u8 current_level
= 7;
8109 bool do_set
= false;
8112 /* DSDT *always* updates status on resume */
8113 tp_features
.fan_ctrl_status_undef
= 0;
8115 if (!fan_control_allowed
||
8116 !fan_control_resume_level
||
8117 (fan_get_status_safe(¤t_level
) < 0))
8120 switch (fan_control_access_mode
) {
8121 case TPACPI_FAN_WR_ACPI_SFAN
:
8122 /* never decrease fan level */
8123 do_set
= (fan_control_resume_level
> current_level
);
8125 case TPACPI_FAN_WR_ACPI_FANS
:
8126 case TPACPI_FAN_WR_TPEC
:
8127 /* never decrease fan level, scale is:
8128 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
8130 * We expect the firmware to set either 7 or AUTO, but we
8131 * handle FULLSPEED out of paranoia.
8133 * So, we can safely only restore FULLSPEED or 7, anything
8134 * else could slow the fan. Restoring AUTO is useless, at
8135 * best that's exactly what the DSDT already set (it is the
8138 * Always keep in mind that the DSDT *will* have set the
8139 * fans to what the vendor supposes is the best level. We
8140 * muck with it only to speed the fan up.
8142 if (fan_control_resume_level
!= 7 &&
8143 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
8146 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
8147 (current_level
!= fan_control_resume_level
);
8153 printk(TPACPI_NOTICE
8154 "restoring fan level to 0x%02x\n",
8155 fan_control_resume_level
);
8156 rc
= fan_set_level_safe(fan_control_resume_level
);
8158 printk(TPACPI_NOTICE
8159 "failed to restore fan level: %d\n", rc
);
8163 static int fan_read(struct seq_file
*m
)
8167 unsigned int speed
= 0;
8169 switch (fan_status_access_mode
) {
8170 case TPACPI_FAN_RD_ACPI_GFAN
:
8171 /* 570, 600e/x, 770e, 770x */
8172 rc
= fan_get_status_safe(&status
);
8176 seq_printf(m
, "status:\t\t%s\n"
8178 (status
!= 0) ? "enabled" : "disabled", status
);
8181 case TPACPI_FAN_RD_TPEC
:
8182 /* all except 570, 600e/x, 770e, 770x */
8183 rc
= fan_get_status_safe(&status
);
8187 seq_printf(m
, "status:\t\t%s\n",
8188 (status
!= 0) ? "enabled" : "disabled");
8190 rc
= fan_get_speed(&speed
);
8194 seq_printf(m
, "speed:\t\t%d\n", speed
);
8196 if (status
& TP_EC_FAN_FULLSPEED
)
8197 /* Disengaged mode takes precedence */
8198 seq_printf(m
, "level:\t\tdisengaged\n");
8199 else if (status
& TP_EC_FAN_AUTO
)
8200 seq_printf(m
, "level:\t\tauto\n");
8202 seq_printf(m
, "level:\t\t%d\n", status
);
8205 case TPACPI_FAN_NONE
:
8207 seq_printf(m
, "status:\t\tnot supported\n");
8210 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
8211 seq_printf(m
, "commands:\tlevel <level>");
8213 switch (fan_control_access_mode
) {
8214 case TPACPI_FAN_WR_ACPI_SFAN
:
8215 seq_printf(m
, " (<level> is 0-7)\n");
8219 seq_printf(m
, " (<level> is 0-7, "
8220 "auto, disengaged, full-speed)\n");
8225 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
8226 seq_printf(m
, "commands:\tenable, disable\n"
8227 "commands:\twatchdog <timeout> (<timeout> "
8228 "is 0 (off), 1-120 (seconds))\n");
8230 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
8231 seq_printf(m
, "commands:\tspeed <speed>"
8232 " (<speed> is 0-65535)\n");
8237 static int fan_write_cmd_level(const char *cmd
, int *rc
)
8241 if (strlencmp(cmd
, "level auto") == 0)
8242 level
= TP_EC_FAN_AUTO
;
8243 else if ((strlencmp(cmd
, "level disengaged") == 0) |
8244 (strlencmp(cmd
, "level full-speed") == 0))
8245 level
= TP_EC_FAN_FULLSPEED
;
8246 else if (sscanf(cmd
, "level %d", &level
) != 1)
8249 *rc
= fan_set_level_safe(level
);
8251 printk(TPACPI_ERR
"level command accepted for unsupported "
8252 "access mode %d", fan_control_access_mode
);
8254 tpacpi_disclose_usertask("procfs fan",
8255 "set level to %d\n", level
);
8260 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
8262 if (strlencmp(cmd
, "enable") != 0)
8265 *rc
= fan_set_enable();
8267 printk(TPACPI_ERR
"enable command accepted for unsupported "
8268 "access mode %d", fan_control_access_mode
);
8270 tpacpi_disclose_usertask("procfs fan", "enable\n");
8275 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
8277 if (strlencmp(cmd
, "disable") != 0)
8280 *rc
= fan_set_disable();
8282 printk(TPACPI_ERR
"disable command accepted for unsupported "
8283 "access mode %d", fan_control_access_mode
);
8285 tpacpi_disclose_usertask("procfs fan", "disable\n");
8290 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
8295 * Support speed <low> <medium> <high> ? */
8297 if (sscanf(cmd
, "speed %d", &speed
) != 1)
8300 *rc
= fan_set_speed(speed
);
8302 printk(TPACPI_ERR
"speed command accepted for unsupported "
8303 "access mode %d", fan_control_access_mode
);
8305 tpacpi_disclose_usertask("procfs fan",
8306 "set speed to %d\n", speed
);
8311 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
8315 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
8318 if (interval
< 0 || interval
> 120)
8321 fan_watchdog_maxinterval
= interval
;
8322 tpacpi_disclose_usertask("procfs fan",
8323 "set watchdog timer to %d\n",
8330 static int fan_write(char *buf
)
8335 while (!rc
&& (cmd
= next_cmd(&buf
))) {
8336 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
8337 fan_write_cmd_level(cmd
, &rc
)) &&
8338 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
8339 (fan_write_cmd_enable(cmd
, &rc
) ||
8340 fan_write_cmd_disable(cmd
, &rc
) ||
8341 fan_write_cmd_watchdog(cmd
, &rc
))) &&
8342 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
8343 fan_write_cmd_speed(cmd
, &rc
))
8347 fan_watchdog_reset();
8353 static struct ibm_struct fan_driver_data
= {
8358 .suspend
= fan_suspend
,
8359 .resume
= fan_resume
,
8362 /****************************************************************************
8363 ****************************************************************************
8367 ****************************************************************************
8368 ****************************************************************************/
8371 * HKEY event callout for other subdrivers go here
8372 * (yes, it is ugly, but it is quick, safe, and gets the job done
8374 static void tpacpi_driver_event(const unsigned int hkey_event
)
8376 if (ibm_backlight_device
) {
8377 switch (hkey_event
) {
8378 case TP_HKEY_EV_BRGHT_UP
:
8379 case TP_HKEY_EV_BRGHT_DOWN
:
8380 tpacpi_brightness_notify_change();
8384 switch (hkey_event
) {
8385 case TP_HKEY_EV_VOL_UP
:
8386 case TP_HKEY_EV_VOL_DOWN
:
8387 case TP_HKEY_EV_VOL_MUTE
:
8388 volume_alsa_notify_change();
8393 static void hotkey_driver_event(const unsigned int scancode
)
8395 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
8398 /* sysfs name ---------------------------------------------------------- */
8399 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
8400 struct device_attribute
*attr
,
8403 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
8406 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
8407 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
8409 /* --------------------------------------------------------------------- */
8412 static struct proc_dir_entry
*proc_dir
;
8415 * Module and infrastructure proble, init and exit handling
8418 static int force_load
;
8420 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
8421 static const char * __init
str_supported(int is_supported
)
8423 static char text_unsupported
[] __initdata
= "not supported";
8425 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
8427 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
8429 static void ibm_exit(struct ibm_struct
*ibm
)
8431 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
8433 list_del_init(&ibm
->all_drivers
);
8435 if (ibm
->flags
.acpi_notify_installed
) {
8436 dbg_printk(TPACPI_DBG_EXIT
,
8437 "%s: acpi_remove_notify_handler\n", ibm
->name
);
8439 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
8441 dispatch_acpi_notify
);
8442 ibm
->flags
.acpi_notify_installed
= 0;
8443 ibm
->flags
.acpi_notify_installed
= 0;
8446 if (ibm
->flags
.proc_created
) {
8447 dbg_printk(TPACPI_DBG_EXIT
,
8448 "%s: remove_proc_entry\n", ibm
->name
);
8449 remove_proc_entry(ibm
->name
, proc_dir
);
8450 ibm
->flags
.proc_created
= 0;
8453 if (ibm
->flags
.acpi_driver_registered
) {
8454 dbg_printk(TPACPI_DBG_EXIT
,
8455 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
8457 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
8458 kfree(ibm
->acpi
->driver
);
8459 ibm
->acpi
->driver
= NULL
;
8460 ibm
->flags
.acpi_driver_registered
= 0;
8463 if (ibm
->flags
.init_called
&& ibm
->exit
) {
8465 ibm
->flags
.init_called
= 0;
8468 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
8471 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
8474 struct ibm_struct
*ibm
= iibm
->data
;
8475 struct proc_dir_entry
*entry
;
8477 BUG_ON(ibm
== NULL
);
8479 INIT_LIST_HEAD(&ibm
->all_drivers
);
8481 if (ibm
->flags
.experimental
&& !experimental
)
8484 dbg_printk(TPACPI_DBG_INIT
,
8485 "probing for %s\n", ibm
->name
);
8488 ret
= iibm
->init(iibm
);
8490 return 0; /* probe failed */
8494 ibm
->flags
.init_called
= 1;
8498 if (ibm
->acpi
->hid
) {
8499 ret
= register_tpacpi_subdriver(ibm
);
8504 if (ibm
->acpi
->notify
) {
8505 ret
= setup_acpi_notify(ibm
);
8506 if (ret
== -ENODEV
) {
8507 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
8517 dbg_printk(TPACPI_DBG_INIT
,
8518 "%s installed\n", ibm
->name
);
8521 mode_t mode
= iibm
->base_procfs_mode
;
8527 entry
= proc_create_data(ibm
->name
, mode
, proc_dir
,
8528 &dispatch_proc_fops
, ibm
);
8530 printk(TPACPI_ERR
"unable to create proc entry %s\n",
8535 ibm
->flags
.proc_created
= 1;
8538 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
8543 dbg_printk(TPACPI_DBG_INIT
,
8544 "%s: at error exit path with result %d\n",
8548 return (ret
< 0)? ret
: 0;
8553 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
8555 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
8558 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
8559 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
8562 return s
&& strlen(s
) >= 8 &&
8563 tpacpi_is_fw_digit(s
[0]) &&
8564 tpacpi_is_fw_digit(s
[1]) &&
8565 s
[2] == t
&& s
[3] == 'T' &&
8566 tpacpi_is_fw_digit(s
[4]) &&
8567 tpacpi_is_fw_digit(s
[5]) &&
8568 s
[6] == 'W' && s
[7] == 'W';
8571 /* returns 0 - probe ok, or < 0 - probe error.
8572 * Probe ok doesn't mean thinkpad found.
8573 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
8574 static int __must_check __init
get_thinkpad_model_data(
8575 struct thinkpad_id_data
*tp
)
8577 const struct dmi_device
*dev
= NULL
;
8578 char ec_fw_string
[18];
8584 memset(tp
, 0, sizeof(*tp
));
8586 if (dmi_name_in_vendors("IBM"))
8587 tp
->vendor
= PCI_VENDOR_ID_IBM
;
8588 else if (dmi_name_in_vendors("LENOVO"))
8589 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
8593 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
8594 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
8595 if (s
&& !tp
->bios_version_str
)
8598 /* Really ancient ThinkPad 240X will fail this, which is fine */
8599 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
8602 tp
->bios_model
= tp
->bios_version_str
[0]
8603 | (tp
->bios_version_str
[1] << 8);
8604 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
8605 | tp
->bios_version_str
[5];
8608 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
8609 * X32 or newer, all Z series; Some models must have an
8610 * up-to-date BIOS or they will not be detected.
8612 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8614 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
8615 if (sscanf(dev
->name
,
8616 "IBM ThinkPad Embedded Controller -[%17c",
8617 ec_fw_string
) == 1) {
8618 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
8619 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
8621 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
8622 if (!tp
->ec_version_str
)
8625 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
8626 tp
->ec_model
= ec_fw_string
[0]
8627 | (ec_fw_string
[1] << 8);
8628 tp
->ec_release
= (ec_fw_string
[4] << 8)
8631 printk(TPACPI_NOTICE
8632 "ThinkPad firmware release %s "
8633 "doesn't match the known patterns\n",
8635 printk(TPACPI_NOTICE
8636 "please report this to %s\n",
8643 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
8644 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
8645 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
8650 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
8651 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
8652 if (s
&& !tp
->nummodel_str
)
8658 static int __init
probe_for_thinkpad(void)
8666 * Non-ancient models have better DMI tagging, but very old models
8667 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
8669 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
8670 (thinkpad_id
.ec_model
!= 0) ||
8671 tpacpi_is_fw_known();
8673 /* ec is required because many other handles are relative to it */
8674 TPACPI_ACPIHANDLE_INIT(ec
);
8678 "Not yet supported ThinkPad detected!\n");
8682 if (!is_thinkpad
&& !force_load
)
8689 /* Module init, exit, parameters */
8691 static struct ibm_init_struct ibms_init
[] __initdata
= {
8693 .init
= thinkpad_acpi_driver_init
,
8694 .data
= &thinkpad_acpi_driver_data
,
8697 .init
= hotkey_init
,
8698 .data
= &hotkey_driver_data
,
8701 .init
= bluetooth_init
,
8702 .data
= &bluetooth_driver_data
,
8706 .data
= &wan_driver_data
,
8710 .data
= &uwb_driver_data
,
8712 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8715 .base_procfs_mode
= S_IRUSR
,
8716 .data
= &video_driver_data
,
8721 .data
= &light_driver_data
,
8725 .data
= &cmos_driver_data
,
8729 .data
= &led_driver_data
,
8733 .data
= &beep_driver_data
,
8736 .init
= thermal_init
,
8737 .data
= &thermal_driver_data
,
8740 .data
= &ecdump_driver_data
,
8743 .init
= brightness_init
,
8744 .data
= &brightness_driver_data
,
8747 .init
= volume_init
,
8748 .data
= &volume_driver_data
,
8752 .data
= &fan_driver_data
,
8756 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
8759 struct ibm_struct
*ibm
;
8761 if (!kp
|| !kp
->name
|| !val
)
8764 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8765 ibm
= ibms_init
[i
].data
;
8766 WARN_ON(ibm
== NULL
);
8768 if (!ibm
|| !ibm
->name
)
8771 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8772 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8774 strcpy(ibms_init
[i
].param
, val
);
8775 strcat(ibms_init
[i
].param
, ",");
8783 module_param(experimental
, int, 0444);
8784 MODULE_PARM_DESC(experimental
,
8785 "Enables experimental features when non-zero");
8787 module_param_named(debug
, dbg_level
, uint
, 0);
8788 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8790 module_param(force_load
, bool, 0444);
8791 MODULE_PARM_DESC(force_load
,
8792 "Attempts to load the driver even on a "
8793 "mis-identified ThinkPad when true");
8795 module_param_named(fan_control
, fan_control_allowed
, bool, 0444);
8796 MODULE_PARM_DESC(fan_control
,
8797 "Enables setting fan parameters features when true");
8799 module_param_named(brightness_mode
, brightness_mode
, uint
, 0444);
8800 MODULE_PARM_DESC(brightness_mode
,
8801 "Selects brightness control strategy: "
8802 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8804 module_param(brightness_enable
, uint
, 0444);
8805 MODULE_PARM_DESC(brightness_enable
,
8806 "Enables backlight control when 1, disables when 0");
8808 module_param(hotkey_report_mode
, uint
, 0444);
8809 MODULE_PARM_DESC(hotkey_report_mode
,
8810 "used for backwards compatibility with userspace, "
8811 "see documentation");
8813 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
8814 module_param_named(volume_mode
, volume_mode
, uint
, 0444);
8815 MODULE_PARM_DESC(volume_mode
,
8816 "Selects volume control strategy: "
8817 "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM");
8819 module_param_named(volume_capabilities
, volume_capabilities
, uint
, 0444);
8820 MODULE_PARM_DESC(volume_capabilities
,
8821 "Selects the mixer capabilites: "
8822 "0=auto, 1=volume and mute, 2=mute only");
8824 module_param_named(volume_control
, volume_control_allowed
, bool, 0444);
8825 MODULE_PARM_DESC(volume_control
,
8826 "Enables software override for the console audio "
8827 "control when true");
8829 /* ALSA module API parameters */
8830 module_param_named(index
, alsa_index
, int, 0444);
8831 MODULE_PARM_DESC(index
, "ALSA index for the ACPI EC Mixer");
8832 module_param_named(id
, alsa_id
, charp
, 0444);
8833 MODULE_PARM_DESC(id
, "ALSA id for the ACPI EC Mixer");
8834 module_param_named(enable
, alsa_enable
, bool, 0444);
8835 MODULE_PARM_DESC(enable
, "Enable the ALSA interface for the ACPI EC Mixer");
8836 #endif /* CONFIG_THINKPAD_ACPI_ALSA_SUPPORT */
8838 #define TPACPI_PARAM(feature) \
8839 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8840 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8841 "at module load, see documentation")
8843 TPACPI_PARAM(hotkey
);
8844 TPACPI_PARAM(bluetooth
);
8845 TPACPI_PARAM(video
);
8846 TPACPI_PARAM(light
);
8850 TPACPI_PARAM(ecdump
);
8851 TPACPI_PARAM(brightness
);
8852 TPACPI_PARAM(volume
);
8855 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8856 module_param(dbg_wlswemul
, uint
, 0444);
8857 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
8858 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
8859 MODULE_PARM_DESC(wlsw_state
,
8860 "Initial state of the emulated WLSW switch");
8862 module_param(dbg_bluetoothemul
, uint
, 0444);
8863 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
8864 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
8865 MODULE_PARM_DESC(bluetooth_state
,
8866 "Initial state of the emulated bluetooth switch");
8868 module_param(dbg_wwanemul
, uint
, 0444);
8869 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
8870 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
8871 MODULE_PARM_DESC(wwan_state
,
8872 "Initial state of the emulated WWAN switch");
8874 module_param(dbg_uwbemul
, uint
, 0444);
8875 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
8876 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
8877 MODULE_PARM_DESC(uwb_state
,
8878 "Initial state of the emulated UWB switch");
8881 static void thinkpad_acpi_module_exit(void)
8883 struct ibm_struct
*ibm
, *itmp
;
8885 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
8887 list_for_each_entry_safe_reverse(ibm
, itmp
,
8888 &tpacpi_all_drivers
,
8893 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
8895 if (tpacpi_inputdev
) {
8896 if (tp_features
.input_device_registered
)
8897 input_unregister_device(tpacpi_inputdev
);
8899 input_free_device(tpacpi_inputdev
);
8903 hwmon_device_unregister(tpacpi_hwmon
);
8905 if (tp_features
.sensors_pdev_attrs_registered
)
8906 device_remove_file(&tpacpi_sensors_pdev
->dev
,
8907 &dev_attr_thinkpad_acpi_pdev_name
);
8908 if (tpacpi_sensors_pdev
)
8909 platform_device_unregister(tpacpi_sensors_pdev
);
8911 platform_device_unregister(tpacpi_pdev
);
8913 if (tp_features
.sensors_pdrv_attrs_registered
)
8914 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
8915 if (tp_features
.platform_drv_attrs_registered
)
8916 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
8918 if (tp_features
.sensors_pdrv_registered
)
8919 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
8921 if (tp_features
.platform_drv_registered
)
8922 platform_driver_unregister(&tpacpi_pdriver
);
8925 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
8928 destroy_workqueue(tpacpi_wq
);
8930 kfree(thinkpad_id
.bios_version_str
);
8931 kfree(thinkpad_id
.ec_version_str
);
8932 kfree(thinkpad_id
.model_str
);
8936 static int __init
thinkpad_acpi_module_init(void)
8940 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
8942 /* Parameter checking */
8943 if (hotkey_report_mode
> 2)
8946 /* Driver-level probe */
8948 ret
= get_thinkpad_model_data(&thinkpad_id
);
8951 "unable to get DMI data: %d\n", ret
);
8952 thinkpad_acpi_module_exit();
8955 ret
= probe_for_thinkpad();
8957 thinkpad_acpi_module_exit();
8961 /* Driver initialization */
8963 TPACPI_ACPIHANDLE_INIT(ecrd
);
8964 TPACPI_ACPIHANDLE_INIT(ecwr
);
8966 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
8968 thinkpad_acpi_module_exit();
8972 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
8975 "unable to create proc dir " TPACPI_PROC_DIR
);
8976 thinkpad_acpi_module_exit();
8980 ret
= platform_driver_register(&tpacpi_pdriver
);
8983 "unable to register main platform driver\n");
8984 thinkpad_acpi_module_exit();
8987 tp_features
.platform_drv_registered
= 1;
8989 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
8992 "unable to register hwmon platform driver\n");
8993 thinkpad_acpi_module_exit();
8996 tp_features
.sensors_pdrv_registered
= 1;
8998 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
9000 tp_features
.platform_drv_attrs_registered
= 1;
9001 ret
= tpacpi_create_driver_attributes(
9002 &tpacpi_hwmon_pdriver
.driver
);
9006 "unable to create sysfs driver attributes\n");
9007 thinkpad_acpi_module_exit();
9010 tp_features
.sensors_pdrv_attrs_registered
= 1;
9013 /* Device initialization */
9014 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
9016 if (IS_ERR(tpacpi_pdev
)) {
9017 ret
= PTR_ERR(tpacpi_pdev
);
9019 printk(TPACPI_ERR
"unable to register platform device\n");
9020 thinkpad_acpi_module_exit();
9023 tpacpi_sensors_pdev
= platform_device_register_simple(
9024 TPACPI_HWMON_DRVR_NAME
,
9026 if (IS_ERR(tpacpi_sensors_pdev
)) {
9027 ret
= PTR_ERR(tpacpi_sensors_pdev
);
9028 tpacpi_sensors_pdev
= NULL
;
9030 "unable to register hwmon platform device\n");
9031 thinkpad_acpi_module_exit();
9034 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
9035 &dev_attr_thinkpad_acpi_pdev_name
);
9038 "unable to create sysfs hwmon device attributes\n");
9039 thinkpad_acpi_module_exit();
9042 tp_features
.sensors_pdev_attrs_registered
= 1;
9043 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
9044 if (IS_ERR(tpacpi_hwmon
)) {
9045 ret
= PTR_ERR(tpacpi_hwmon
);
9046 tpacpi_hwmon
= NULL
;
9047 printk(TPACPI_ERR
"unable to register hwmon device\n");
9048 thinkpad_acpi_module_exit();
9051 mutex_init(&tpacpi_inputdev_send_mutex
);
9052 tpacpi_inputdev
= input_allocate_device();
9053 if (!tpacpi_inputdev
) {
9054 printk(TPACPI_ERR
"unable to allocate input device\n");
9055 thinkpad_acpi_module_exit();
9058 /* Prepare input device, but don't register */
9059 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
9060 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
9061 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
9062 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
9063 thinkpad_id
.vendor
:
9065 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
9066 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
9067 tpacpi_inputdev
->dev
.parent
= &tpacpi_pdev
->dev
;
9069 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
9070 ret
= ibm_init(&ibms_init
[i
]);
9071 if (ret
>= 0 && *ibms_init
[i
].param
)
9072 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
9074 thinkpad_acpi_module_exit();
9079 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
9081 ret
= input_register_device(tpacpi_inputdev
);
9083 printk(TPACPI_ERR
"unable to register input device\n");
9084 thinkpad_acpi_module_exit();
9087 tp_features
.input_device_registered
= 1;
9093 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
9096 * This will autoload the driver in almost every ThinkPad
9097 * in widespread use.
9099 * Only _VERY_ old models, like the 240, 240x and 570 lack
9100 * the HKEY event interface.
9102 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
9105 * DMI matching for module autoloading
9107 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
9108 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
9110 * Only models listed in thinkwiki will be supported, so add yours
9111 * if it is not there yet.
9113 #define IBM_BIOS_MODULE_ALIAS(__type) \
9114 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
9116 /* Ancient thinkpad BIOSes have to be identified by
9117 * BIOS type or model number, and there are far less
9118 * BIOS types than model numbers... */
9119 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
9121 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
9122 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
9123 MODULE_DESCRIPTION(TPACPI_DESC
);
9124 MODULE_VERSION(TPACPI_VERSION
);
9125 MODULE_LICENSE("GPL");
9127 module_init(thinkpad_acpi_module_init
);
9128 module_exit(thinkpad_acpi_module_exit
);