2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define TPACPI_VERSION "0.23"
25 #define TPACPI_SYSFS_VERSION 0x020600
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/sched.h>
58 #include <linux/kthread.h>
59 #include <linux/freezer.h>
60 #include <linux/delay.h>
62 #include <linux/nvram.h>
63 #include <linux/proc_fs.h>
64 #include <linux/sysfs.h>
65 #include <linux/backlight.h>
67 #include <linux/platform_device.h>
68 #include <linux/hwmon.h>
69 #include <linux/hwmon-sysfs.h>
70 #include <linux/input.h>
71 #include <linux/leds.h>
72 #include <linux/rfkill.h>
73 #include <asm/uaccess.h>
75 #include <linux/dmi.h>
76 #include <linux/jiffies.h>
77 #include <linux/workqueue.h>
79 #include <acpi/acpi_drivers.h>
81 #include <linux/pci_ids.h>
84 /* ThinkPad CMOS commands */
85 #define TP_CMOS_VOLUME_DOWN 0
86 #define TP_CMOS_VOLUME_UP 1
87 #define TP_CMOS_VOLUME_MUTE 2
88 #define TP_CMOS_BRIGHTNESS_UP 4
89 #define TP_CMOS_BRIGHTNESS_DOWN 5
90 #define TP_CMOS_THINKLIGHT_ON 12
91 #define TP_CMOS_THINKLIGHT_OFF 13
95 TP_NVRAM_ADDR_HK2
= 0x57,
96 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
97 TP_NVRAM_ADDR_VIDEO
= 0x59,
98 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
99 TP_NVRAM_ADDR_MIXER
= 0x60,
102 /* NVRAM bit masks */
104 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
105 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
106 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
107 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
108 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
109 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
110 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
111 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
112 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
113 TP_NVRAM_MASK_MUTE
= 0x40,
114 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
115 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
116 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
120 #define TPACPI_ACPI_HKEY_HID "IBM0068"
123 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
124 #define TPACPI_HKEY_INPUT_VERSION 0x4101
126 /* ACPI \WGSV commands */
128 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
129 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
130 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
131 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
134 /* TP_ACPI_WGSV_GET_STATE bits */
136 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
137 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
138 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
139 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
140 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
141 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
142 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
143 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
144 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
145 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
149 enum tpacpi_hkey_event_t
{
151 TP_HKEY_EV_HOTKEY_BASE
= 0x1001, /* first hotkey (FN+F1) */
152 TP_HKEY_EV_BRGHT_UP
= 0x1010, /* Brightness up */
153 TP_HKEY_EV_BRGHT_DOWN
= 0x1011, /* Brightness down */
154 TP_HKEY_EV_VOL_UP
= 0x1015, /* Volume up or unmute */
155 TP_HKEY_EV_VOL_DOWN
= 0x1016, /* Volume down or unmute */
156 TP_HKEY_EV_VOL_MUTE
= 0x1017, /* Mixer output mute */
158 /* Reasons for waking up from S3/S4 */
159 TP_HKEY_EV_WKUP_S3_UNDOCK
= 0x2304, /* undock requested, S3 */
160 TP_HKEY_EV_WKUP_S4_UNDOCK
= 0x2404, /* undock requested, S4 */
161 TP_HKEY_EV_WKUP_S3_BAYEJ
= 0x2305, /* bay ejection req, S3 */
162 TP_HKEY_EV_WKUP_S4_BAYEJ
= 0x2405, /* bay ejection req, S4 */
163 TP_HKEY_EV_WKUP_S3_BATLOW
= 0x2313, /* battery empty, S3 */
164 TP_HKEY_EV_WKUP_S4_BATLOW
= 0x2413, /* battery empty, S4 */
166 /* Auto-sleep after eject request */
167 TP_HKEY_EV_BAYEJ_ACK
= 0x3003, /* bay ejection complete */
168 TP_HKEY_EV_UNDOCK_ACK
= 0x4003, /* undock complete */
170 /* Misc bay events */
171 TP_HKEY_EV_OPTDRV_EJ
= 0x3006, /* opt. drive tray ejected */
173 /* User-interface events */
174 TP_HKEY_EV_LID_CLOSE
= 0x5001, /* laptop lid closed */
175 TP_HKEY_EV_LID_OPEN
= 0x5002, /* laptop lid opened */
176 TP_HKEY_EV_TABLET_TABLET
= 0x5009, /* tablet swivel up */
177 TP_HKEY_EV_TABLET_NOTEBOOK
= 0x500a, /* tablet swivel down */
178 TP_HKEY_EV_PEN_INSERTED
= 0x500b, /* tablet pen inserted */
179 TP_HKEY_EV_PEN_REMOVED
= 0x500c, /* tablet pen removed */
180 TP_HKEY_EV_BRGHT_CHANGED
= 0x5010, /* backlight control event */
183 TP_HKEY_EV_ALARM_BAT_HOT
= 0x6011, /* battery too hot */
184 TP_HKEY_EV_ALARM_BAT_XHOT
= 0x6012, /* battery critically hot */
185 TP_HKEY_EV_ALARM_SENSOR_HOT
= 0x6021, /* sensor too hot */
186 TP_HKEY_EV_ALARM_SENSOR_XHOT
= 0x6022, /* sensor critically hot */
187 TP_HKEY_EV_THM_TABLE_CHANGED
= 0x6030, /* thermal table changed */
190 TP_HKEY_EV_RFKILL_CHANGED
= 0x7000, /* rfkill switch changed */
193 /****************************************************************************
197 #define TPACPI_NAME "thinkpad"
198 #define TPACPI_DESC "ThinkPad ACPI Extras"
199 #define TPACPI_FILE TPACPI_NAME "_acpi"
200 #define TPACPI_URL "http://ibm-acpi.sf.net/"
201 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
203 #define TPACPI_PROC_DIR "ibm"
204 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
205 #define TPACPI_DRVR_NAME TPACPI_FILE
206 #define TPACPI_DRVR_SHORTNAME "tpacpi"
207 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
209 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
210 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
212 #define TPACPI_MAX_ACPI_ARGS 3
214 /* rfkill switches */
216 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
217 TPACPI_RFK_WWAN_SW_ID
,
218 TPACPI_RFK_UWB_SW_ID
,
222 #define TPACPI_LOG TPACPI_FILE ": "
223 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
224 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
225 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
226 #define TPACPI_ERR KERN_ERR TPACPI_LOG
227 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
228 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
229 #define TPACPI_INFO KERN_INFO TPACPI_LOG
230 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
232 /* Debugging printk groups */
233 #define TPACPI_DBG_ALL 0xffff
234 #define TPACPI_DBG_DISCLOSETASK 0x8000
235 #define TPACPI_DBG_INIT 0x0001
236 #define TPACPI_DBG_EXIT 0x0002
237 #define TPACPI_DBG_RFKILL 0x0004
238 #define TPACPI_DBG_HKEY 0x0008
239 #define TPACPI_DBG_FAN 0x0010
240 #define TPACPI_DBG_BRGHT 0x0020
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
) (char *);
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 struct ibm_struct
*data
;
301 u32 bright_16levels
:1;
302 u32 bright_acpimode
:1;
305 u32 fan_ctrl_status_undef
:1;
307 u32 beep_needs_two_args
:1;
308 u32 input_device_registered
:1;
309 u32 platform_drv_registered
:1;
310 u32 platform_drv_attrs_registered
:1;
311 u32 sensors_pdrv_registered
:1;
312 u32 sensors_pdrv_attrs_registered
:1;
313 u32 sensors_pdev_attrs_registered
:1;
314 u32 hotkey_poll_active
:1;
318 u16 hotkey_mask_ff
:1;
321 struct thinkpad_id_data
{
322 unsigned int vendor
; /* ThinkPad vendor:
323 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
325 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
326 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
328 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
330 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
333 char *model_str
; /* ThinkPad T43 */
334 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
336 static struct thinkpad_id_data thinkpad_id
;
339 TPACPI_LIFE_INIT
= 0,
344 static int experimental
;
345 static u32 dbg_level
;
347 static struct workqueue_struct
*tpacpi_wq
;
355 /* Special LED class that can defer work */
356 struct tpacpi_led_classdev
{
357 struct led_classdev led_classdev
;
358 struct work_struct work
;
359 enum led_status_t new_state
;
363 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
364 static int dbg_wlswemul
;
365 static int tpacpi_wlsw_emulstate
;
366 static int dbg_bluetoothemul
;
367 static int tpacpi_bluetooth_emulstate
;
368 static int dbg_wwanemul
;
369 static int tpacpi_wwan_emulstate
;
370 static int dbg_uwbemul
;
371 static int tpacpi_uwb_emulstate
;
375 /*************************************************************************
379 #define dbg_printk(a_dbg_level, format, arg...) \
380 do { if (dbg_level & (a_dbg_level)) \
381 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
384 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
385 #define vdbg_printk dbg_printk
386 static const char *str_supported(int is_supported
);
388 #define vdbg_printk(a_dbg_level, format, arg...) \
392 static void tpacpi_log_usertask(const char * const what
)
394 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
395 what
, task_tgid_vnr(current
));
398 #define tpacpi_disclose_usertask(what, format, arg...) \
401 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
402 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
403 printk(TPACPI_DEBUG "%s: PID %d: " format, \
404 what, task_tgid_vnr(current), ## arg); \
409 * Quirk handling helpers
411 * ThinkPad IDs and versions seen in the field so far
412 * are two-characters from the set [0-9A-Z], i.e. base 36.
414 * We use values well outside that range as specials.
417 #define TPACPI_MATCH_ANY 0xffffU
418 #define TPACPI_MATCH_UNKNOWN 0U
420 /* TPID('1', 'Y') == 0x5931 */
421 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
423 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
424 { .vendor = PCI_VENDOR_ID_IBM, \
425 .bios = TPID(__id1, __id2), \
426 .ec = TPACPI_MATCH_ANY, \
427 .quirks = (__quirk) }
429 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
430 { .vendor = PCI_VENDOR_ID_LENOVO, \
431 .bios = TPID(__id1, __id2), \
432 .ec = TPACPI_MATCH_ANY, \
433 .quirks = (__quirk) }
435 struct tpacpi_quirk
{
439 unsigned long quirks
;
443 * tpacpi_check_quirks() - search BIOS/EC version on a list
444 * @qlist: array of &struct tpacpi_quirk
445 * @qlist_size: number of elements in @qlist
447 * Iterates over a quirks list until one is found that matches the
448 * ThinkPad's vendor, BIOS and EC model.
450 * Returns 0 if nothing matches, otherwise returns the quirks field of
451 * the matching &struct tpacpi_quirk entry.
453 * The match criteria is: vendor, ec and bios much match.
455 static unsigned long __init
tpacpi_check_quirks(
456 const struct tpacpi_quirk
*qlist
,
457 unsigned int qlist_size
)
460 if ((qlist
->vendor
== thinkpad_id
.vendor
||
461 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
462 (qlist
->bios
== thinkpad_id
.bios_model
||
463 qlist
->bios
== TPACPI_MATCH_ANY
) &&
464 (qlist
->ec
== thinkpad_id
.ec_model
||
465 qlist
->ec
== TPACPI_MATCH_ANY
))
466 return qlist
->quirks
;
475 /****************************************************************************
476 ****************************************************************************
478 * ACPI Helpers and device model
480 ****************************************************************************
481 ****************************************************************************/
483 /*************************************************************************
487 static acpi_handle root_handle
;
489 #define TPACPI_HANDLE(object, parent, paths...) \
490 static acpi_handle object##_handle; \
491 static acpi_handle *object##_parent = &parent##_handle; \
492 static char *object##_path; \
493 static char *object##_paths[] = { paths }
495 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
496 "\\_SB.PCI.ISA.EC", /* 570 */
497 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
498 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
499 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
500 "\\_SB.PCI0.ICH3.EC0", /* R31 */
501 "\\_SB.PCI0.LPC.EC", /* all others */
504 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
505 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
507 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
509 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
510 "\\CMS", /* R40, R40e */
513 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
514 "^HKEY", /* R30, R31 */
515 "HKEY", /* all others */
518 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
519 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
520 "\\_SB.PCI0.VID0", /* 770e */
521 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
522 "\\_SB.PCI0.AGP.VID", /* all others */
526 /*************************************************************************
530 static int acpi_evalf(acpi_handle handle
,
531 void *res
, char *method
, char *fmt
, ...)
534 struct acpi_object_list params
;
535 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
536 struct acpi_buffer result
, *resultp
;
537 union acpi_object out_obj
;
545 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
558 params
.pointer
= &in_objs
[0];
565 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
566 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
568 /* add more types as needed */
570 printk(TPACPI_ERR
"acpi_evalf() called "
571 "with invalid format character '%c'\n", c
);
577 if (res_type
!= 'v') {
578 result
.length
= sizeof(out_obj
);
579 result
.pointer
= &out_obj
;
584 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
589 *(int *)res
= out_obj
.integer
.value
;
590 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
593 success
= status
== AE_OK
;
595 /* add more types as needed */
597 printk(TPACPI_ERR
"acpi_evalf() called "
598 "with invalid format character '%c'\n", res_type
);
602 if (!success
&& !quiet
)
603 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
604 method
, fmt0
, status
);
609 static int acpi_ec_read(int i
, u8
*p
)
614 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
618 if (ec_read(i
, p
) < 0)
625 static int acpi_ec_write(int i
, u8 v
)
628 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
631 if (ec_write(i
, v
) < 0)
638 static int issue_thinkpad_cmos_command(int cmos_cmd
)
643 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
649 /*************************************************************************
653 #define TPACPI_ACPIHANDLE_INIT(object) \
654 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
655 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
657 static void drv_acpi_handle_init(char *name
,
658 acpi_handle
*handle
, acpi_handle parent
,
659 char **paths
, int num_paths
, char **path
)
664 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
667 for (i
= 0; i
< num_paths
; i
++) {
668 status
= acpi_get_handle(parent
, paths
[i
], handle
);
669 if (ACPI_SUCCESS(status
)) {
671 dbg_printk(TPACPI_DBG_INIT
,
672 "Found ACPI handle %s for %s\n",
678 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
683 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
685 struct ibm_struct
*ibm
= data
;
687 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
690 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
693 ibm
->acpi
->notify(ibm
, event
);
696 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
703 if (!*ibm
->acpi
->handle
)
706 vdbg_printk(TPACPI_DBG_INIT
,
707 "setting up ACPI notify for %s\n", ibm
->name
);
709 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
711 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
716 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
717 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
718 TPACPI_ACPI_EVENT_PREFIX
,
721 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
722 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
723 if (ACPI_FAILURE(status
)) {
724 if (status
== AE_ALREADY_EXISTS
) {
726 "another device driver is already "
727 "handling %s events\n", ibm
->name
);
730 "acpi_install_notify_handler(%s) failed: %d\n",
735 ibm
->flags
.acpi_notify_installed
= 1;
739 static int __init
tpacpi_device_add(struct acpi_device
*device
)
744 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
748 dbg_printk(TPACPI_DBG_INIT
,
749 "registering %s as an ACPI driver\n", ibm
->name
);
753 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
754 if (!ibm
->acpi
->driver
) {
756 "failed to allocate memory for ibm->acpi->driver\n");
760 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
761 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
763 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
765 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
767 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
769 kfree(ibm
->acpi
->driver
);
770 ibm
->acpi
->driver
= NULL
;
772 ibm
->flags
.acpi_driver_registered
= 1;
778 /****************************************************************************
779 ****************************************************************************
783 ****************************************************************************
784 ****************************************************************************/
786 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
787 int count
, int *eof
, void *data
)
789 struct ibm_struct
*ibm
= data
;
792 if (!ibm
|| !ibm
->read
)
795 len
= ibm
->read(page
);
799 if (len
<= off
+ count
)
811 static int dispatch_procfs_write(struct file
*file
,
812 const char __user
*userbuf
,
813 unsigned long count
, void *data
)
815 struct ibm_struct
*ibm
= data
;
819 if (!ibm
|| !ibm
->write
)
821 if (count
> PAGE_SIZE
- 2)
824 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
828 if (copy_from_user(kernbuf
, userbuf
, count
)) {
834 strcat(kernbuf
, ",");
835 ret
= ibm
->write(kernbuf
);
844 static char *next_cmd(char **cmds
)
849 while ((end
= strchr(start
, ',')) && end
== start
)
861 /****************************************************************************
862 ****************************************************************************
864 * Device model: input, hwmon and platform
866 ****************************************************************************
867 ****************************************************************************/
869 static struct platform_device
*tpacpi_pdev
;
870 static struct platform_device
*tpacpi_sensors_pdev
;
871 static struct device
*tpacpi_hwmon
;
872 static struct input_dev
*tpacpi_inputdev
;
873 static struct mutex tpacpi_inputdev_send_mutex
;
874 static LIST_HEAD(tpacpi_all_drivers
);
876 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
879 struct ibm_struct
*ibm
, *itmp
;
881 list_for_each_entry_safe(ibm
, itmp
,
885 (ibm
->suspend
)(state
);
891 static int tpacpi_resume_handler(struct platform_device
*pdev
)
893 struct ibm_struct
*ibm
, *itmp
;
895 list_for_each_entry_safe(ibm
, itmp
,
905 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
907 struct ibm_struct
*ibm
, *itmp
;
909 list_for_each_entry_safe(ibm
, itmp
,
917 static struct platform_driver tpacpi_pdriver
= {
919 .name
= TPACPI_DRVR_NAME
,
920 .owner
= THIS_MODULE
,
922 .suspend
= tpacpi_suspend_handler
,
923 .resume
= tpacpi_resume_handler
,
924 .shutdown
= tpacpi_shutdown_handler
,
927 static struct platform_driver tpacpi_hwmon_pdriver
= {
929 .name
= TPACPI_HWMON_DRVR_NAME
,
930 .owner
= THIS_MODULE
,
934 /*************************************************************************
935 * sysfs support helpers
938 struct attribute_set
{
939 unsigned int members
, max_members
;
940 struct attribute_group group
;
943 struct attribute_set_obj
{
944 struct attribute_set s
;
946 } __attribute__((packed
));
948 static struct attribute_set
*create_attr_set(unsigned int max_members
,
951 struct attribute_set_obj
*sobj
;
953 if (max_members
== 0)
956 /* Allocates space for implicit NULL at the end too */
957 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
958 max_members
* sizeof(struct attribute
*),
962 sobj
->s
.max_members
= max_members
;
963 sobj
->s
.group
.attrs
= &sobj
->a
;
964 sobj
->s
.group
.name
= name
;
969 #define destroy_attr_set(_set) \
972 /* not multi-threaded safe, use it in a single thread per set */
973 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
978 if (s
->members
>= s
->max_members
)
981 s
->group
.attrs
[s
->members
] = attr
;
987 static int add_many_to_attr_set(struct attribute_set
*s
,
988 struct attribute
**attr
,
993 for (i
= 0; i
< count
; i
++) {
994 res
= add_to_attr_set(s
, attr
[i
]);
1002 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
1004 sysfs_remove_group(kobj
, &s
->group
);
1005 destroy_attr_set(s
);
1008 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
1009 sysfs_create_group(_kobj, &_attr_set->group)
1011 static int parse_strtoul(const char *buf
,
1012 unsigned long max
, unsigned long *value
)
1016 while (*buf
&& isspace(*buf
))
1018 *value
= simple_strtoul(buf
, &endp
, 0);
1019 while (*endp
&& isspace(*endp
))
1021 if (*endp
|| *value
> max
)
1027 static void tpacpi_disable_brightness_delay(void)
1029 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
1030 printk(TPACPI_NOTICE
1031 "ACPI backlight control delay disabled\n");
1034 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
1036 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1037 union acpi_object
*obj
;
1040 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
1041 obj
= (union acpi_object
*)buffer
.pointer
;
1042 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
1043 printk(TPACPI_ERR
"Unknown _BCL data, "
1044 "please report this to %s\n", TPACPI_MAIL
);
1047 rc
= obj
->package
.count
;
1053 kfree(buffer
.pointer
);
1057 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1058 u32 lvl
, void *context
, void **rv
)
1060 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1061 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1063 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1064 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1065 BUG_ON(!rv
|| !*rv
);
1066 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1067 return AE_CTRL_TERMINATE
;
1074 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1076 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1080 void *bcl_ptr
= &bcl_levels
;
1083 TPACPI_ACPIHANDLE_INIT(vid
);
1089 * Search for a _BCL method, and execute it. This is safe on all
1090 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1091 * BIOS in ACPI backlight control mode. We do NOT have to care
1092 * about calling the _BCL method in an enabled video device, any
1093 * will do for our purposes.
1096 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1097 tpacpi_acpi_walk_find_bcl
, NULL
,
1100 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1101 tp_features
.bright_acpimode
= 1;
1102 return (bcl_levels
- 2);
1108 static int __init
tpacpi_new_rfkill(const unsigned int id
,
1109 struct rfkill
**rfk
,
1110 const enum rfkill_type rfktype
,
1112 const bool set_default
,
1113 int (*toggle_radio
)(void *, enum rfkill_state
),
1114 int (*get_state
)(void *, enum rfkill_state
*))
1117 enum rfkill_state initial_state
= RFKILL_STATE_SOFT_BLOCKED
;
1119 res
= get_state(NULL
, &initial_state
);
1122 "failed to read initial state for %s, error %d; "
1123 "will turn radio off\n", name
, res
);
1124 } else if (set_default
) {
1125 /* try to set the initial state as the default for the rfkill
1126 * type, since we ask the firmware to preserve it across S5 in
1128 if (rfkill_set_default(rfktype
,
1129 (initial_state
== RFKILL_STATE_UNBLOCKED
) ?
1130 RFKILL_STATE_UNBLOCKED
:
1131 RFKILL_STATE_SOFT_BLOCKED
) == -EPERM
)
1132 vdbg_printk(TPACPI_DBG_RFKILL
,
1133 "Default state for %s cannot be changed\n",
1137 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
1140 "failed to allocate memory for rfkill class\n");
1144 (*rfk
)->name
= name
;
1145 (*rfk
)->get_state
= get_state
;
1146 (*rfk
)->toggle_radio
= toggle_radio
;
1147 (*rfk
)->state
= initial_state
;
1149 res
= rfkill_register(*rfk
);
1152 "failed to register %s rfkill switch: %d\n",
1162 static void printk_deprecated_attribute(const char * const what
,
1163 const char * const details
)
1165 tpacpi_log_usertask("deprecated sysfs attribute");
1166 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1167 "will be removed. %s\n",
1171 static void printk_deprecated_rfkill_attribute(const char * const what
)
1173 printk_deprecated_attribute(what
,
1174 "Please switch to generic rfkill before year 2010");
1177 /*************************************************************************
1178 * thinkpad-acpi driver attributes
1181 /* interface_version --------------------------------------------------- */
1182 static ssize_t
tpacpi_driver_interface_version_show(
1183 struct device_driver
*drv
,
1186 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1189 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1190 tpacpi_driver_interface_version_show
, NULL
);
1192 /* debug_level --------------------------------------------------------- */
1193 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1196 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1199 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1200 const char *buf
, size_t count
)
1204 if (parse_strtoul(buf
, 0xffff, &t
))
1212 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1213 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1215 /* version ------------------------------------------------------------- */
1216 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1219 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1220 TPACPI_DESC
, TPACPI_VERSION
);
1223 static DRIVER_ATTR(version
, S_IRUGO
,
1224 tpacpi_driver_version_show
, NULL
);
1226 /* --------------------------------------------------------------------- */
1228 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1230 static void tpacpi_send_radiosw_update(void);
1232 /* wlsw_emulstate ------------------------------------------------------ */
1233 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1236 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1239 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1240 const char *buf
, size_t count
)
1244 if (parse_strtoul(buf
, 1, &t
))
1247 if (tpacpi_wlsw_emulstate
!= t
) {
1248 tpacpi_wlsw_emulstate
= !!t
;
1249 tpacpi_send_radiosw_update();
1251 tpacpi_wlsw_emulstate
= !!t
;
1256 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1257 tpacpi_driver_wlsw_emulstate_show
,
1258 tpacpi_driver_wlsw_emulstate_store
);
1260 /* bluetooth_emulstate ------------------------------------------------- */
1261 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1262 struct device_driver
*drv
,
1265 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1268 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1269 struct device_driver
*drv
,
1270 const char *buf
, size_t count
)
1274 if (parse_strtoul(buf
, 1, &t
))
1277 tpacpi_bluetooth_emulstate
= !!t
;
1282 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1283 tpacpi_driver_bluetooth_emulstate_show
,
1284 tpacpi_driver_bluetooth_emulstate_store
);
1286 /* wwan_emulstate ------------------------------------------------- */
1287 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1288 struct device_driver
*drv
,
1291 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1294 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1295 struct device_driver
*drv
,
1296 const char *buf
, size_t count
)
1300 if (parse_strtoul(buf
, 1, &t
))
1303 tpacpi_wwan_emulstate
= !!t
;
1308 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1309 tpacpi_driver_wwan_emulstate_show
,
1310 tpacpi_driver_wwan_emulstate_store
);
1312 /* uwb_emulstate ------------------------------------------------- */
1313 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1314 struct device_driver
*drv
,
1317 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1320 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1321 struct device_driver
*drv
,
1322 const char *buf
, size_t count
)
1326 if (parse_strtoul(buf
, 1, &t
))
1329 tpacpi_uwb_emulstate
= !!t
;
1334 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1335 tpacpi_driver_uwb_emulstate_show
,
1336 tpacpi_driver_uwb_emulstate_store
);
1339 /* --------------------------------------------------------------------- */
1341 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1342 &driver_attr_debug_level
, &driver_attr_version
,
1343 &driver_attr_interface_version
,
1346 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1352 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1353 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1357 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1358 if (!res
&& dbg_wlswemul
)
1359 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1360 if (!res
&& dbg_bluetoothemul
)
1361 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1362 if (!res
&& dbg_wwanemul
)
1363 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1364 if (!res
&& dbg_uwbemul
)
1365 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1371 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1375 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1376 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1378 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1379 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1380 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1381 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1382 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1386 /*************************************************************************
1391 * Table of recommended minimum BIOS versions
1393 * Reasons for listing:
1394 * 1. Stable BIOS, listed because the unknown ammount of
1395 * bugs and bad ACPI behaviour on older versions
1397 * 2. BIOS or EC fw with known bugs that trigger on Linux
1399 * 3. BIOS with known reduced functionality in older versions
1401 * We recommend the latest BIOS and EC version.
1402 * We only support the latest BIOS and EC fw version as a rule.
1404 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1405 * Information from users in ThinkWiki
1407 * WARNING: we use this table also to detect that the machine is
1408 * a ThinkPad in some cases, so don't remove entries lightly.
1411 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1412 { .vendor = (__v), \
1413 .bios = TPID(__id1, __id2), \
1414 .ec = TPACPI_MATCH_ANY, \
1415 .quirks = TPACPI_MATCH_ANY << 16 \
1416 | (__bv1) << 8 | (__bv2) }
1418 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1419 __eid, __ev1, __ev2) \
1420 { .vendor = (__v), \
1421 .bios = TPID(__bid1, __bid2), \
1423 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1424 | (__bv1) << 8 | (__bv2) }
1426 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1427 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1429 /* Outdated IBM BIOSes often lack the EC id string */
1430 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1431 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1432 __bv1, __bv2, TPID(__id1, __id2), \
1434 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1435 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1438 /* Outdated IBM BIOSes often lack the EC id string */
1439 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1440 __eid1, __eid2, __ev1, __ev2) \
1441 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1442 __bv1, __bv2, TPID(__eid1, __eid2), \
1444 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1445 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1448 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1449 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1451 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1452 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1453 __bv1, __bv2, TPID(__id1, __id2), \
1456 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1457 __eid1, __eid2, __ev1, __ev2) \
1458 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1459 __bv1, __bv2, TPID(__eid1, __eid2), \
1462 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1463 /* Numeric models ------------------ */
1464 /* FW MODEL BIOS VERS */
1465 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1466 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1467 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1468 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1469 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1470 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1471 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1472 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1473 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1475 /* A-series ------------------------- */
1476 /* FW MODEL BIOS VERS EC VERS */
1477 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1478 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1479 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1480 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1481 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1482 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1483 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1484 TPV_QI0('1', '3', '2', '0'), /* A22m */
1485 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1486 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1487 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1489 /* G-series ------------------------- */
1490 /* FW MODEL BIOS VERS */
1491 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1492 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1494 /* R-series, T-series --------------- */
1495 /* FW MODEL BIOS VERS EC VERS */
1496 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1497 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1498 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1499 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1500 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1501 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1502 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1503 T40/p, T41/p, T42/p (1) */
1504 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1505 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1506 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1507 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1509 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1510 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1511 TPV_QI0('1', '6', '3', '2'), /* T22 */
1512 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1513 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1514 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1516 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1517 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1518 TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */
1520 /* BIOS FW BIOS VERS EC FW EC VERS */
1521 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1522 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1524 /* X-series ------------------------- */
1525 /* FW MODEL BIOS VERS EC VERS */
1526 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1527 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1528 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1529 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1530 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1531 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1532 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1534 TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */
1535 TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */
1537 /* (0) - older versions lack DMI EC fw string and functionality */
1538 /* (1) - older versions known to lack functionality */
1549 static void __init
tpacpi_check_outdated_fw(void)
1551 unsigned long fwvers
;
1552 u16 ec_version
, bios_version
;
1554 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1555 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1560 bios_version
= fwvers
& 0xffffU
;
1561 ec_version
= (fwvers
>> 16) & 0xffffU
;
1563 /* note that unknown versions are set to 0x0000 and we use that */
1564 if ((bios_version
> thinkpad_id
.bios_release
) ||
1565 (ec_version
> thinkpad_id
.ec_release
&&
1566 ec_version
!= TPACPI_MATCH_ANY
)) {
1568 * The changelogs would let us track down the exact
1569 * reason, but it is just too much of a pain to track
1570 * it. We only list BIOSes that are either really
1571 * broken, or really stable to begin with, so it is
1572 * best if the user upgrades the firmware anyway.
1575 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1577 "WARNING: This firmware may be missing critical bug "
1578 "fixes and/or important features\n");
1582 static bool __init
tpacpi_is_fw_known(void)
1584 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1585 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1588 /****************************************************************************
1589 ****************************************************************************
1593 ****************************************************************************
1594 ****************************************************************************/
1596 /*************************************************************************
1597 * thinkpad-acpi init subdriver
1600 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1602 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1603 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1605 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1606 (thinkpad_id
.bios_version_str
) ?
1607 thinkpad_id
.bios_version_str
: "unknown",
1608 (thinkpad_id
.ec_version_str
) ?
1609 thinkpad_id
.ec_version_str
: "unknown");
1611 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1612 printk(TPACPI_INFO
"%s %s, model %s\n",
1613 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1614 "IBM" : ((thinkpad_id
.vendor
==
1615 PCI_VENDOR_ID_LENOVO
) ?
1616 "Lenovo" : "Unknown vendor"),
1617 thinkpad_id
.model_str
,
1618 (thinkpad_id
.nummodel_str
) ?
1619 thinkpad_id
.nummodel_str
: "unknown");
1621 tpacpi_check_outdated_fw();
1625 static int thinkpad_acpi_driver_read(char *p
)
1629 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1630 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1635 static struct ibm_struct thinkpad_acpi_driver_data
= {
1637 .read
= thinkpad_acpi_driver_read
,
1640 /*************************************************************************
1645 * ThinkPad firmware event model
1647 * The ThinkPad firmware has two main event interfaces: normal ACPI
1648 * notifications (which follow the ACPI standard), and a private event
1651 * The private event interface also issues events for the hotkeys. As
1652 * the driver gained features, the event handling code ended up being
1653 * built around the hotkey subdriver. This will need to be refactored
1654 * to a more formal event API eventually.
1656 * Some "hotkeys" are actually supposed to be used as event reports,
1657 * such as "brightness has changed", "volume has changed", depending on
1658 * the ThinkPad model and how the firmware is operating.
1660 * Unlike other classes, hotkey-class events have mask/unmask control on
1661 * non-ancient firmware. However, how it behaves changes a lot with the
1662 * firmware model and version.
1665 enum { /* hot key scan codes (derived from ACPI DSDT) */
1666 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1667 TP_ACPI_HOTKEYSCAN_FNF2
,
1668 TP_ACPI_HOTKEYSCAN_FNF3
,
1669 TP_ACPI_HOTKEYSCAN_FNF4
,
1670 TP_ACPI_HOTKEYSCAN_FNF5
,
1671 TP_ACPI_HOTKEYSCAN_FNF6
,
1672 TP_ACPI_HOTKEYSCAN_FNF7
,
1673 TP_ACPI_HOTKEYSCAN_FNF8
,
1674 TP_ACPI_HOTKEYSCAN_FNF9
,
1675 TP_ACPI_HOTKEYSCAN_FNF10
,
1676 TP_ACPI_HOTKEYSCAN_FNF11
,
1677 TP_ACPI_HOTKEYSCAN_FNF12
,
1678 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1679 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1680 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1681 TP_ACPI_HOTKEYSCAN_FNHOME
,
1682 TP_ACPI_HOTKEYSCAN_FNEND
,
1683 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1684 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1685 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1686 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1687 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1688 TP_ACPI_HOTKEYSCAN_MUTE
,
1689 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1692 enum { /* Keys/events available through NVRAM polling */
1693 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1694 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1697 enum { /* Positions of some of the keys in hotkey masks */
1698 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1699 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1700 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1701 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1702 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1703 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1704 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1705 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1706 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1707 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1708 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1711 enum { /* NVRAM to ACPI HKEY group map */
1712 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1713 TP_ACPI_HKEY_ZOOM_MASK
|
1714 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1715 TP_ACPI_HKEY_HIBERNATE_MASK
,
1716 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1717 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1718 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1719 TP_ACPI_HKEY_VOLDWN_MASK
|
1720 TP_ACPI_HKEY_MUTE_MASK
,
1723 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1724 struct tp_nvram_state
{
1725 u16 thinkpad_toggle
:1;
1727 u16 display_toggle
:1;
1728 u16 thinklight_toggle
:1;
1729 u16 hibernate_toggle
:1;
1730 u16 displayexp_toggle
:1;
1731 u16 display_state
:1;
1732 u16 brightness_toggle
:1;
1733 u16 volume_toggle
:1;
1736 u8 brightness_level
;
1740 /* kthread for the hotkey poller */
1741 static struct task_struct
*tpacpi_hotkey_task
;
1743 /* Acquired while the poller kthread is running, use to sync start/stop */
1744 static struct mutex hotkey_thread_mutex
;
1747 * Acquire mutex to write poller control variables as an
1750 * Increment hotkey_config_change when changing them if you
1751 * want the kthread to forget old state.
1753 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1755 static struct mutex hotkey_thread_data_mutex
;
1756 static unsigned int hotkey_config_change
;
1759 * hotkey poller control variables
1761 * Must be atomic or readers will also need to acquire mutex
1763 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1764 * should be used only when the changes need to be taken as
1765 * a block, OR when one needs to force the kthread to forget
1768 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1769 static unsigned int hotkey_poll_freq
= 10; /* Hz */
1771 #define HOTKEY_CONFIG_CRITICAL_START \
1773 mutex_lock(&hotkey_thread_data_mutex); \
1774 hotkey_config_change++; \
1776 #define HOTKEY_CONFIG_CRITICAL_END \
1777 mutex_unlock(&hotkey_thread_data_mutex);
1779 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1781 #define hotkey_source_mask 0U
1782 #define HOTKEY_CONFIG_CRITICAL_START
1783 #define HOTKEY_CONFIG_CRITICAL_END
1785 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1787 static struct mutex hotkey_mutex
;
1789 static enum { /* Reasons for waking up */
1790 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1791 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1792 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1793 } hotkey_wakeup_reason
;
1795 static int hotkey_autosleep_ack
;
1797 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
1798 static u32 hotkey_all_mask
; /* all events supported in fw */
1799 static u32 hotkey_reserved_mask
; /* events better left disabled */
1800 static u32 hotkey_driver_mask
; /* events needed by the driver */
1801 static u32 hotkey_user_mask
; /* events visible to userspace */
1802 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
1804 static unsigned int hotkey_report_mode
;
1806 static u16
*hotkey_keycode_map
;
1808 static struct attribute_set
*hotkey_dev_attributes
;
1810 static void tpacpi_driver_event(const unsigned int hkey_event
);
1811 static void hotkey_driver_event(const unsigned int scancode
);
1813 /* HKEY.MHKG() return bits */
1814 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1816 static int hotkey_get_wlsw(int *status
)
1818 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1820 *status
= !!tpacpi_wlsw_emulstate
;
1824 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1829 static int hotkey_get_tablet_mode(int *status
)
1833 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1836 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1841 * Reads current event mask from firmware, and updates
1842 * hotkey_acpi_mask accordingly. Also resets any bits
1843 * from hotkey_user_mask that are unavailable to be
1844 * delivered (shadow requirement of the userspace ABI).
1846 * Call with hotkey_mutex held
1848 static int hotkey_mask_get(void)
1850 if (tp_features
.hotkey_mask
) {
1853 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1856 hotkey_acpi_mask
= m
;
1858 /* no mask support doesn't mean no event support... */
1859 hotkey_acpi_mask
= hotkey_all_mask
;
1862 /* sync userspace-visible mask */
1863 hotkey_user_mask
&= (hotkey_acpi_mask
| hotkey_source_mask
);
1868 void static hotkey_mask_warn_incomplete_mask(void)
1870 /* log only what the user can fix... */
1871 const u32 wantedmask
= hotkey_driver_mask
&
1872 ~(hotkey_acpi_mask
| hotkey_source_mask
) &
1873 (hotkey_all_mask
| TPACPI_HKEY_NVRAM_KNOWN_MASK
);
1876 printk(TPACPI_NOTICE
1877 "required events 0x%08x not enabled!\n",
1882 * Set the firmware mask when supported
1884 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
1886 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
1888 * Call with hotkey_mutex held
1890 static int hotkey_mask_set(u32 mask
)
1895 const u32 fwmask
= mask
& ~hotkey_source_mask
;
1897 if (tp_features
.hotkey_mask
) {
1898 for (i
= 0; i
< 32; i
++) {
1899 if (!acpi_evalf(hkey_handle
,
1900 NULL
, "MHKM", "vdd", i
+ 1,
1901 !!(mask
& (1 << i
)))) {
1909 * We *must* make an inconditional call to hotkey_mask_get to
1910 * refresh hotkey_acpi_mask and update hotkey_user_mask
1912 * Take the opportunity to also log when we cannot _enable_
1915 if (!hotkey_mask_get() && !rc
&& (fwmask
& ~hotkey_acpi_mask
)) {
1916 printk(TPACPI_NOTICE
1917 "asked for hotkey mask 0x%08x, but "
1918 "firmware forced it to 0x%08x\n",
1919 fwmask
, hotkey_acpi_mask
);
1922 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
)
1923 hotkey_mask_warn_incomplete_mask();
1929 * Sets hotkey_user_mask and tries to set the firmware mask
1931 * Call with hotkey_mutex held
1933 static int hotkey_user_mask_set(const u32 mask
)
1937 /* Give people a chance to notice they are doing something that
1938 * is bound to go boom on their users sooner or later */
1939 if (!tp_warned
.hotkey_mask_ff
&&
1940 (mask
== 0xffff || mask
== 0xffffff ||
1941 mask
== 0xffffffff)) {
1942 tp_warned
.hotkey_mask_ff
= 1;
1943 printk(TPACPI_NOTICE
1944 "setting the hotkey mask to 0x%08x is likely "
1945 "not the best way to go about it\n", mask
);
1946 printk(TPACPI_NOTICE
1947 "please consider using the driver defaults, "
1948 "and refer to up-to-date thinkpad-acpi "
1952 /* Try to enable what the user asked for, plus whatever we need.
1953 * this syncs everything but won't enable bits in hotkey_user_mask */
1954 rc
= hotkey_mask_set((mask
| hotkey_driver_mask
) & ~hotkey_source_mask
);
1956 /* Enable the available bits in hotkey_user_mask */
1957 hotkey_user_mask
= mask
& (hotkey_acpi_mask
| hotkey_source_mask
);
1963 * Sets the driver hotkey mask.
1965 * Can be called even if the hotkey subdriver is inactive
1967 static int tpacpi_hotkey_driver_mask_set(const u32 mask
)
1971 /* Do the right thing if hotkey_init has not been called yet */
1972 if (!tp_features
.hotkey
) {
1973 hotkey_driver_mask
= mask
;
1977 mutex_lock(&hotkey_mutex
);
1979 HOTKEY_CONFIG_CRITICAL_START
1980 hotkey_driver_mask
= mask
;
1981 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1982 hotkey_source_mask
|= (mask
& ~hotkey_all_mask
);
1984 HOTKEY_CONFIG_CRITICAL_END
1986 rc
= hotkey_mask_set((hotkey_acpi_mask
| hotkey_driver_mask
) &
1987 ~hotkey_source_mask
);
1988 mutex_unlock(&hotkey_mutex
);
1993 static int hotkey_status_get(int *status
)
1995 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
2001 static int hotkey_status_set(bool enable
)
2003 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
2009 static void tpacpi_input_send_tabletsw(void)
2013 if (tp_features
.hotkey_tablet
&&
2014 !hotkey_get_tablet_mode(&state
)) {
2015 mutex_lock(&tpacpi_inputdev_send_mutex
);
2017 input_report_switch(tpacpi_inputdev
,
2018 SW_TABLET_MODE
, !!state
);
2019 input_sync(tpacpi_inputdev
);
2021 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2025 /* Do NOT call without validating scancode first */
2026 static void tpacpi_input_send_key(const unsigned int scancode
)
2028 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
2030 if (keycode
!= KEY_RESERVED
) {
2031 mutex_lock(&tpacpi_inputdev_send_mutex
);
2033 input_report_key(tpacpi_inputdev
, keycode
, 1);
2034 if (keycode
== KEY_UNKNOWN
)
2035 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2037 input_sync(tpacpi_inputdev
);
2039 input_report_key(tpacpi_inputdev
, keycode
, 0);
2040 if (keycode
== KEY_UNKNOWN
)
2041 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2043 input_sync(tpacpi_inputdev
);
2045 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2049 /* Do NOT call without validating scancode first */
2050 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
2052 hotkey_driver_event(scancode
);
2053 if (hotkey_user_mask
& (1 << scancode
))
2054 tpacpi_input_send_key(scancode
);
2057 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2058 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2060 /* Do NOT call without validating scancode first */
2061 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2063 tpacpi_input_send_key_masked(scancode
);
2064 if (hotkey_report_mode
< 2) {
2065 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2066 0x80, TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
2070 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2074 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2075 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2076 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2077 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2078 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2079 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2081 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2082 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2083 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2085 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2086 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2087 n
->displayexp_toggle
=
2088 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2090 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2091 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2092 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2093 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2094 n
->brightness_toggle
=
2095 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2097 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2098 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2099 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2100 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2101 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2102 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2106 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2107 struct tp_nvram_state
*newn
,
2108 const u32 event_mask
)
2111 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2113 if ((event_mask & (1 << __scancode)) && \
2114 oldn->__member != newn->__member) \
2115 tpacpi_hotkey_send_key(__scancode); \
2118 #define TPACPI_MAY_SEND_KEY(__scancode) \
2120 if (event_mask & (1 << __scancode)) \
2121 tpacpi_hotkey_send_key(__scancode); \
2124 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2125 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2126 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2127 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2129 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2131 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2134 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2135 if (oldn
->mute
!= newn
->mute
) {
2136 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2138 if (oldn
->volume_level
> newn
->volume_level
) {
2139 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2140 } else if (oldn
->volume_level
< newn
->volume_level
) {
2141 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2142 } else if (oldn
->mute
== newn
->mute
) {
2143 /* repeated key presses that didn't change state */
2145 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2146 } else if (newn
->volume_level
!= 0) {
2147 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2149 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2154 /* handle brightness */
2155 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2156 if (oldn
->brightness_level
< newn
->brightness_level
) {
2157 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2158 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
2159 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2161 /* repeated key presses that didn't change state */
2162 if (newn
->brightness_level
!= 0) {
2163 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2165 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2170 #undef TPACPI_COMPARE_KEY
2171 #undef TPACPI_MAY_SEND_KEY
2177 * We track all events in hotkey_source_mask all the time, since
2178 * most of them are edge-based. We only issue those requested by
2179 * hotkey_user_mask or hotkey_driver_mask, though.
2181 static int hotkey_kthread(void *data
)
2183 struct tp_nvram_state s
[2];
2184 u32 poll_mask
, event_mask
;
2185 unsigned int si
, so
;
2187 unsigned int change_detector
, must_reset
;
2188 unsigned int poll_freq
;
2190 mutex_lock(&hotkey_thread_mutex
);
2192 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2201 /* Initial state for compares */
2202 mutex_lock(&hotkey_thread_data_mutex
);
2203 change_detector
= hotkey_config_change
;
2204 poll_mask
= hotkey_source_mask
;
2205 event_mask
= hotkey_source_mask
&
2206 (hotkey_driver_mask
| hotkey_user_mask
);
2207 poll_freq
= hotkey_poll_freq
;
2208 mutex_unlock(&hotkey_thread_data_mutex
);
2209 hotkey_read_nvram(&s
[so
], poll_mask
);
2211 while (!kthread_should_stop()) {
2213 if (likely(poll_freq
))
2216 t
= 100; /* should never happen... */
2218 t
= msleep_interruptible(t
);
2219 if (unlikely(kthread_should_stop()))
2221 must_reset
= try_to_freeze();
2222 if (t
> 0 && !must_reset
)
2225 mutex_lock(&hotkey_thread_data_mutex
);
2226 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2227 /* forget old state on thaw or config change */
2230 change_detector
= hotkey_config_change
;
2232 poll_mask
= hotkey_source_mask
;
2233 event_mask
= hotkey_source_mask
&
2234 (hotkey_driver_mask
| hotkey_user_mask
);
2235 poll_freq
= hotkey_poll_freq
;
2236 mutex_unlock(&hotkey_thread_data_mutex
);
2238 if (likely(poll_mask
)) {
2239 hotkey_read_nvram(&s
[si
], poll_mask
);
2240 if (likely(si
!= so
)) {
2241 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2251 mutex_unlock(&hotkey_thread_mutex
);
2255 /* call with hotkey_mutex held */
2256 static void hotkey_poll_stop_sync(void)
2258 if (tpacpi_hotkey_task
) {
2259 if (frozen(tpacpi_hotkey_task
) ||
2260 freezing(tpacpi_hotkey_task
))
2261 thaw_process(tpacpi_hotkey_task
);
2263 kthread_stop(tpacpi_hotkey_task
);
2264 tpacpi_hotkey_task
= NULL
;
2265 mutex_lock(&hotkey_thread_mutex
);
2266 /* at this point, the thread did exit */
2267 mutex_unlock(&hotkey_thread_mutex
);
2271 /* call with hotkey_mutex held */
2272 static void hotkey_poll_setup(bool may_warn
)
2274 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2275 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2277 if (hotkey_poll_freq
> 0 &&
2278 (poll_driver_mask
||
2279 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2280 if (!tpacpi_hotkey_task
) {
2281 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2282 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2283 if (IS_ERR(tpacpi_hotkey_task
)) {
2284 tpacpi_hotkey_task
= NULL
;
2286 "could not create kernel thread "
2287 "for hotkey polling\n");
2291 hotkey_poll_stop_sync();
2292 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2293 hotkey_poll_freq
== 0) {
2294 printk(TPACPI_NOTICE
2295 "hot keys 0x%08x and/or events 0x%08x "
2296 "require polling, which is currently "
2298 poll_user_mask
, poll_driver_mask
);
2303 static void hotkey_poll_setup_safe(bool may_warn
)
2305 mutex_lock(&hotkey_mutex
);
2306 hotkey_poll_setup(may_warn
);
2307 mutex_unlock(&hotkey_mutex
);
2310 /* call with hotkey_mutex held */
2311 static void hotkey_poll_set_freq(unsigned int freq
)
2314 hotkey_poll_stop_sync();
2316 hotkey_poll_freq
= freq
;
2319 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2321 static void hotkey_poll_setup_safe(bool __unused
)
2325 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2327 static int hotkey_inputdev_open(struct input_dev
*dev
)
2329 switch (tpacpi_lifecycle
) {
2330 case TPACPI_LIFE_INIT
:
2332 * hotkey_init will call hotkey_poll_setup_safe
2333 * at the appropriate moment
2336 case TPACPI_LIFE_EXITING
:
2338 case TPACPI_LIFE_RUNNING
:
2339 hotkey_poll_setup_safe(false);
2343 /* Should only happen if tpacpi_lifecycle is corrupt */
2348 static void hotkey_inputdev_close(struct input_dev
*dev
)
2350 /* disable hotkey polling when possible */
2351 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
&&
2352 !(hotkey_source_mask
& hotkey_driver_mask
))
2353 hotkey_poll_setup_safe(false);
2356 /* sysfs hotkey enable ------------------------------------------------- */
2357 static ssize_t
hotkey_enable_show(struct device
*dev
,
2358 struct device_attribute
*attr
,
2363 printk_deprecated_attribute("hotkey_enable",
2364 "Hotkey reporting is always enabled");
2366 res
= hotkey_status_get(&status
);
2370 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2373 static ssize_t
hotkey_enable_store(struct device
*dev
,
2374 struct device_attribute
*attr
,
2375 const char *buf
, size_t count
)
2379 printk_deprecated_attribute("hotkey_enable",
2380 "Hotkeys can be disabled through hotkey_mask");
2382 if (parse_strtoul(buf
, 1, &t
))
2391 static struct device_attribute dev_attr_hotkey_enable
=
2392 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2393 hotkey_enable_show
, hotkey_enable_store
);
2395 /* sysfs hotkey mask --------------------------------------------------- */
2396 static ssize_t
hotkey_mask_show(struct device
*dev
,
2397 struct device_attribute
*attr
,
2400 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2403 static ssize_t
hotkey_mask_store(struct device
*dev
,
2404 struct device_attribute
*attr
,
2405 const char *buf
, size_t count
)
2410 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2413 if (mutex_lock_killable(&hotkey_mutex
))
2414 return -ERESTARTSYS
;
2416 res
= hotkey_user_mask_set(t
);
2418 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2419 hotkey_poll_setup(true);
2422 mutex_unlock(&hotkey_mutex
);
2424 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2426 return (res
) ? res
: count
;
2429 static struct device_attribute dev_attr_hotkey_mask
=
2430 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2431 hotkey_mask_show
, hotkey_mask_store
);
2433 /* sysfs hotkey bios_enabled ------------------------------------------- */
2434 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2435 struct device_attribute
*attr
,
2438 return sprintf(buf
, "0\n");
2441 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2442 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2444 /* sysfs hotkey bios_mask ---------------------------------------------- */
2445 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2446 struct device_attribute
*attr
,
2449 printk_deprecated_attribute("hotkey_bios_mask",
2450 "This attribute is useless.");
2451 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2454 static struct device_attribute dev_attr_hotkey_bios_mask
=
2455 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2457 /* sysfs hotkey all_mask ----------------------------------------------- */
2458 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2459 struct device_attribute
*attr
,
2462 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2463 hotkey_all_mask
| hotkey_source_mask
);
2466 static struct device_attribute dev_attr_hotkey_all_mask
=
2467 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2469 /* sysfs hotkey recommended_mask --------------------------------------- */
2470 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2471 struct device_attribute
*attr
,
2474 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2475 (hotkey_all_mask
| hotkey_source_mask
)
2476 & ~hotkey_reserved_mask
);
2479 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2480 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2481 hotkey_recommended_mask_show
, NULL
);
2483 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2485 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2486 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2487 struct device_attribute
*attr
,
2490 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2493 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2494 struct device_attribute
*attr
,
2495 const char *buf
, size_t count
)
2501 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2502 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2505 if (mutex_lock_killable(&hotkey_mutex
))
2506 return -ERESTARTSYS
;
2508 HOTKEY_CONFIG_CRITICAL_START
2509 hotkey_source_mask
= t
;
2510 HOTKEY_CONFIG_CRITICAL_END
2512 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2513 ~hotkey_source_mask
);
2514 hotkey_poll_setup(true);
2516 /* check if events needed by the driver got disabled */
2517 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2518 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2520 mutex_unlock(&hotkey_mutex
);
2523 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2524 "firmware event mask!\n");
2527 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2528 "some important events were disabled: "
2531 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2533 return (rc
< 0) ? rc
: count
;
2536 static struct device_attribute dev_attr_hotkey_source_mask
=
2537 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2538 hotkey_source_mask_show
, hotkey_source_mask_store
);
2540 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2541 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2542 struct device_attribute
*attr
,
2545 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2548 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2549 struct device_attribute
*attr
,
2550 const char *buf
, size_t count
)
2554 if (parse_strtoul(buf
, 25, &t
))
2557 if (mutex_lock_killable(&hotkey_mutex
))
2558 return -ERESTARTSYS
;
2560 hotkey_poll_set_freq(t
);
2561 hotkey_poll_setup(true);
2563 mutex_unlock(&hotkey_mutex
);
2565 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2570 static struct device_attribute dev_attr_hotkey_poll_freq
=
2571 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2572 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2574 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2576 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2577 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2578 struct device_attribute
*attr
,
2582 res
= hotkey_get_wlsw(&s
);
2586 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2589 static struct device_attribute dev_attr_hotkey_radio_sw
=
2590 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2592 static void hotkey_radio_sw_notify_change(void)
2594 if (tp_features
.hotkey_wlsw
)
2595 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2599 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2600 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2601 struct device_attribute
*attr
,
2605 res
= hotkey_get_tablet_mode(&s
);
2609 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2612 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2613 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2615 static void hotkey_tablet_mode_notify_change(void)
2617 if (tp_features
.hotkey_tablet
)
2618 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2619 "hotkey_tablet_mode");
2622 /* sysfs hotkey report_mode -------------------------------------------- */
2623 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2624 struct device_attribute
*attr
,
2627 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2628 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2631 static struct device_attribute dev_attr_hotkey_report_mode
=
2632 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2634 /* sysfs wakeup reason (pollable) -------------------------------------- */
2635 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2636 struct device_attribute
*attr
,
2639 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2642 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2643 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2645 static void hotkey_wakeup_reason_notify_change(void)
2647 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2651 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2652 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2653 struct device_attribute
*attr
,
2656 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2659 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2660 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2661 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2663 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2665 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2666 "wakeup_hotunplug_complete");
2669 /* --------------------------------------------------------------------- */
2671 static struct attribute
*hotkey_attributes
[] __initdata
= {
2672 &dev_attr_hotkey_enable
.attr
,
2673 &dev_attr_hotkey_bios_enabled
.attr
,
2674 &dev_attr_hotkey_bios_mask
.attr
,
2675 &dev_attr_hotkey_report_mode
.attr
,
2676 &dev_attr_hotkey_wakeup_reason
.attr
,
2677 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2678 &dev_attr_hotkey_mask
.attr
,
2679 &dev_attr_hotkey_all_mask
.attr
,
2680 &dev_attr_hotkey_recommended_mask
.attr
,
2681 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2682 &dev_attr_hotkey_source_mask
.attr
,
2683 &dev_attr_hotkey_poll_freq
.attr
,
2687 static void bluetooth_update_rfk(void);
2688 static void wan_update_rfk(void);
2689 static void uwb_update_rfk(void);
2690 static void tpacpi_send_radiosw_update(void)
2694 /* Sync these BEFORE sending any rfkill events */
2695 if (tp_features
.bluetooth
)
2696 bluetooth_update_rfk();
2697 if (tp_features
.wan
)
2699 if (tp_features
.uwb
)
2702 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2703 mutex_lock(&tpacpi_inputdev_send_mutex
);
2705 input_report_switch(tpacpi_inputdev
,
2706 SW_RFKILL_ALL
, !!wlsw
);
2707 input_sync(tpacpi_inputdev
);
2709 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2711 hotkey_radio_sw_notify_change();
2714 static void hotkey_exit(void)
2716 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2717 mutex_lock(&hotkey_mutex
);
2718 hotkey_poll_stop_sync();
2719 mutex_unlock(&hotkey_mutex
);
2722 if (hotkey_dev_attributes
)
2723 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2725 kfree(hotkey_keycode_map
);
2727 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
2728 "restoring original HKEY status and mask\n");
2729 /* yes, there is a bitwise or below, we want the
2730 * functions to be called even if one of them fail */
2731 if (((tp_features
.hotkey_mask
&&
2732 hotkey_mask_set(hotkey_orig_mask
)) |
2733 hotkey_status_set(false)) != 0)
2735 "failed to restore hot key mask "
2736 "to BIOS defaults\n");
2739 static void __init
hotkey_unmap(const unsigned int scancode
)
2741 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
2742 clear_bit(hotkey_keycode_map
[scancode
],
2743 tpacpi_inputdev
->keybit
);
2744 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
2750 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
2753 #define TPACPI_HK_Q_INIMASK 0x0001
2755 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
2756 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
2757 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
2758 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
2759 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
2760 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
2761 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
2762 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
2763 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
2764 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
2765 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
2766 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
2767 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
2768 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
2769 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
2770 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
2771 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
2772 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
2773 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
2774 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
2777 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2779 /* Requirements for changing the default keymaps:
2781 * 1. Many of the keys are mapped to KEY_RESERVED for very
2782 * good reasons. Do not change them unless you have deep
2783 * knowledge on the IBM and Lenovo ThinkPad firmware for
2784 * the various ThinkPad models. The driver behaves
2785 * differently for KEY_RESERVED: such keys have their
2786 * hot key mask *unset* in mask_recommended, and also
2787 * in the initial hot key mask programmed into the
2788 * firmware at driver load time, which means the firm-
2789 * ware may react very differently if you change them to
2792 * 2. You must be subscribed to the linux-thinkpad and
2793 * ibm-acpi-devel mailing lists, and you should read the
2794 * list archives since 2007 if you want to change the
2795 * keymaps. This requirement exists so that you will
2796 * know the past history of problems with the thinkpad-
2797 * acpi driver keymaps, and also that you will be
2798 * listening to any bug reports;
2800 * 3. Do not send thinkpad-acpi specific patches directly to
2801 * for merging, *ever*. Send them to the linux-acpi
2802 * mailinglist for comments. Merging is to be done only
2803 * through acpi-test and the ACPI maintainer.
2805 * If the above is too much to ask, don't change the keymap.
2806 * Ask the thinkpad-acpi maintainer to do it, instead.
2808 static u16 ibm_keycode_map
[] __initdata
= {
2809 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2810 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2811 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2812 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2814 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2815 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2816 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2817 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2819 /* brightness: firmware always reacts to them */
2820 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2821 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2823 /* Thinklight: firmware always react to it */
2824 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2826 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2827 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2829 /* Volume: firmware always react to it and reprograms
2830 * the built-in *extra* mixer. Never map it to control
2831 * another mixer by default. */
2832 KEY_RESERVED
, /* 0x14: VOLUME UP */
2833 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2834 KEY_RESERVED
, /* 0x16: MUTE */
2836 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2838 /* (assignments unknown, please report if found) */
2839 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2840 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2842 static u16 lenovo_keycode_map
[] __initdata
= {
2843 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2844 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2845 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2846 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2848 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2849 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2850 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2851 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2853 /* These should be enabled --only-- when ACPI video
2854 * is disabled (i.e. in "vendor" mode), and are handled
2855 * in a special way by the init code */
2856 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
2857 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
2859 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2861 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2862 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2864 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2865 * react to it and reprograms the built-in *extra* mixer.
2866 * Never map it to control another mixer by default.
2868 * T60?, T61, R60?, R61: firmware and EC tries to send
2869 * these over the regular keyboard, so these are no-ops,
2870 * but there are still weird bugs re. MUTE, so do not
2871 * change unless you get test reports from all Lenovo
2872 * models. May cause the BIOS to interfere with the
2875 KEY_RESERVED
, /* 0x14: VOLUME UP */
2876 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2877 KEY_RESERVED
, /* 0x16: MUTE */
2879 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2881 /* (assignments unknown, please report if found) */
2882 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2883 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2886 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2887 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2888 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2894 unsigned long quirks
;
2896 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2897 "initializing hotkey subdriver\n");
2899 BUG_ON(!tpacpi_inputdev
);
2900 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2901 tpacpi_inputdev
->close
!= NULL
);
2903 TPACPI_ACPIHANDLE_INIT(hkey
);
2904 mutex_init(&hotkey_mutex
);
2906 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2907 mutex_init(&hotkey_thread_mutex
);
2908 mutex_init(&hotkey_thread_data_mutex
);
2911 /* hotkey not supported on 570 */
2912 tp_features
.hotkey
= hkey_handle
!= NULL
;
2914 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2916 str_supported(tp_features
.hotkey
));
2918 if (!tp_features
.hotkey
)
2921 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
2922 ARRAY_SIZE(tpacpi_hotkey_qtable
));
2924 tpacpi_disable_brightness_delay();
2926 /* MUST have enough space for all attributes to be added to
2927 * hotkey_dev_attributes */
2928 hotkey_dev_attributes
= create_attr_set(
2929 ARRAY_SIZE(hotkey_attributes
) + 2,
2931 if (!hotkey_dev_attributes
)
2933 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2935 ARRAY_SIZE(hotkey_attributes
));
2939 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
2940 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2941 for HKEY interface version 0x100 */
2942 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2943 if ((hkeyv
>> 8) != 1) {
2944 printk(TPACPI_ERR
"unknown version of the "
2945 "HKEY interface: 0x%x\n", hkeyv
);
2946 printk(TPACPI_ERR
"please report this to %s\n",
2950 * MHKV 0x100 in A31, R40, R40e,
2951 * T4x, X31, and later
2953 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2954 "firmware HKEY interface version: 0x%x\n",
2957 /* Paranoia check AND init hotkey_all_mask */
2958 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2961 "missing MHKA handler, "
2962 "please report this to %s\n",
2964 /* Fallback: pre-init for FN+F3,F4,F12 */
2965 hotkey_all_mask
= 0x080cU
;
2967 tp_features
.hotkey_mask
= 1;
2972 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2973 "hotkey masks are %s\n",
2974 str_supported(tp_features
.hotkey_mask
));
2976 /* Init hotkey_all_mask if not initialized yet */
2977 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
2978 (quirks
& TPACPI_HK_Q_INIMASK
))
2979 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
2981 /* Init hotkey_acpi_mask and hotkey_orig_mask */
2982 if (tp_features
.hotkey_mask
) {
2983 /* hotkey_source_mask *must* be zero for
2984 * the first hotkey_mask_get to return hotkey_orig_mask */
2985 res
= hotkey_mask_get();
2989 hotkey_orig_mask
= hotkey_acpi_mask
;
2991 hotkey_orig_mask
= hotkey_all_mask
;
2992 hotkey_acpi_mask
= hotkey_all_mask
;
2995 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2997 tp_features
.hotkey_wlsw
= 1;
2999 "radio switch emulation enabled\n");
3002 /* Not all thinkpads have a hardware radio switch */
3003 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3004 tp_features
.hotkey_wlsw
= 1;
3006 "radio switch found; radios are %s\n",
3007 enabled(status
, 0));
3009 if (tp_features
.hotkey_wlsw
)
3010 res
= add_to_attr_set(hotkey_dev_attributes
,
3011 &dev_attr_hotkey_radio_sw
.attr
);
3013 /* For X41t, X60t, X61t Tablets... */
3014 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3015 tp_features
.hotkey_tablet
= 1;
3017 "possible tablet mode switch found; "
3018 "ThinkPad in %s mode\n",
3019 (status
& TP_HOTKEY_TABLET_MASK
)?
3020 "tablet" : "laptop");
3021 res
= add_to_attr_set(hotkey_dev_attributes
,
3022 &dev_attr_hotkey_tablet_mode
.attr
);
3026 res
= register_attr_set_with_sysfs(
3027 hotkey_dev_attributes
,
3028 &tpacpi_pdev
->dev
.kobj
);
3032 /* Set up key map */
3034 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3036 if (!hotkey_keycode_map
) {
3038 "failed to allocate memory for key map\n");
3043 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
3044 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3045 "using Lenovo default hot key map\n");
3046 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
3047 TPACPI_HOTKEY_MAP_SIZE
);
3049 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3050 "using IBM default hot key map\n");
3051 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
3052 TPACPI_HOTKEY_MAP_SIZE
);
3055 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
3056 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
3057 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
3058 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3059 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3060 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3061 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3062 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3063 set_bit(hotkey_keycode_map
[i
],
3064 tpacpi_inputdev
->keybit
);
3066 if (i
< sizeof(hotkey_reserved_mask
)*8)
3067 hotkey_reserved_mask
|= 1 << i
;
3071 if (tp_features
.hotkey_wlsw
) {
3072 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
3073 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
3075 if (tp_features
.hotkey_tablet
) {
3076 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
3077 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
3080 /* Do not issue duplicate brightness change events to
3082 if (!tp_features
.bright_acpimode
)
3083 /* update bright_acpimode... */
3084 tpacpi_check_std_acpi_brightness_support();
3086 if (tp_features
.bright_acpimode
) {
3088 "This ThinkPad has standard ACPI backlight "
3089 "brightness control, supported by the ACPI "
3091 printk(TPACPI_NOTICE
3092 "Disabling thinkpad-acpi brightness events "
3095 /* Disable brightness up/down on Lenovo thinkpads when
3096 * ACPI is handling them, otherwise it is plain impossible
3097 * for userspace to do something even remotely sane */
3098 hotkey_reserved_mask
|=
3099 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3100 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3101 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3102 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3105 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3106 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3108 & ~hotkey_reserved_mask
;
3110 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3111 "hotkey source mask 0x%08x, polling freq %u\n",
3112 hotkey_source_mask
, hotkey_poll_freq
);
3115 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3116 "enabling firmware HKEY event interface...\n");
3117 res
= hotkey_status_set(true);
3122 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3123 | hotkey_driver_mask
)
3124 & ~hotkey_source_mask
);
3125 if (res
< 0 && res
!= -ENXIO
) {
3129 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3130 & ~hotkey_reserved_mask
;
3131 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3132 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3133 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3135 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3136 "legacy ibm/hotkey event reporting over procfs %s\n",
3137 (hotkey_report_mode
< 2) ?
3138 "enabled" : "disabled");
3140 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3141 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3143 hotkey_poll_setup_safe(true);
3144 tpacpi_send_radiosw_update();
3145 tpacpi_input_send_tabletsw();
3150 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3151 hotkey_dev_attributes
= NULL
;
3153 return (res
< 0)? res
: 1;
3156 static bool hotkey_notify_hotkey(const u32 hkey
,
3158 bool *ignore_acpi_ev
)
3160 /* 0x1000-0x1FFF: key presses */
3161 unsigned int scancode
= hkey
& 0xfff;
3162 *send_acpi_ev
= true;
3163 *ignore_acpi_ev
= false;
3165 if (scancode
> 0 && scancode
< 0x21) {
3167 if (!(hotkey_source_mask
& (1 << scancode
))) {
3168 tpacpi_input_send_key_masked(scancode
);
3169 *send_acpi_ev
= false;
3171 *ignore_acpi_ev
= true;
3178 static bool hotkey_notify_wakeup(const u32 hkey
,
3180 bool *ignore_acpi_ev
)
3182 /* 0x2000-0x2FFF: Wakeup reason */
3183 *send_acpi_ev
= true;
3184 *ignore_acpi_ev
= false;
3187 case TP_HKEY_EV_WKUP_S3_UNDOCK
: /* suspend, undock */
3188 case TP_HKEY_EV_WKUP_S4_UNDOCK
: /* hibernation, undock */
3189 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3190 *ignore_acpi_ev
= true;
3193 case TP_HKEY_EV_WKUP_S3_BAYEJ
: /* suspend, bay eject */
3194 case TP_HKEY_EV_WKUP_S4_BAYEJ
: /* hibernation, bay eject */
3195 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3196 *ignore_acpi_ev
= true;
3199 case TP_HKEY_EV_WKUP_S3_BATLOW
: /* Battery on critical low level/S3 */
3200 case TP_HKEY_EV_WKUP_S4_BATLOW
: /* Battery on critical low level/S4 */
3202 "EMERGENCY WAKEUP: battery almost empty\n");
3203 /* how to auto-heal: */
3204 /* 2313: woke up from S3, go to S4/S5 */
3205 /* 2413: woke up from S4, go to S5 */
3212 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3214 "woke up due to a hot-unplug "
3216 hotkey_wakeup_reason_notify_change();
3221 static bool hotkey_notify_usrevent(const u32 hkey
,
3223 bool *ignore_acpi_ev
)
3225 /* 0x5000-0x5FFF: human interface helpers */
3226 *send_acpi_ev
= true;
3227 *ignore_acpi_ev
= false;
3230 case TP_HKEY_EV_PEN_INSERTED
: /* X61t: tablet pen inserted into bay */
3231 case TP_HKEY_EV_PEN_REMOVED
: /* X61t: tablet pen removed from bay */
3234 case TP_HKEY_EV_TABLET_TABLET
: /* X41t-X61t: tablet mode */
3235 case TP_HKEY_EV_TABLET_NOTEBOOK
: /* X41t-X61t: normal mode */
3236 tpacpi_input_send_tabletsw();
3237 hotkey_tablet_mode_notify_change();
3238 *send_acpi_ev
= false;
3241 case TP_HKEY_EV_LID_CLOSE
: /* Lid closed */
3242 case TP_HKEY_EV_LID_OPEN
: /* Lid opened */
3243 case TP_HKEY_EV_BRGHT_CHANGED
: /* brightness changed */
3244 /* do not propagate these events */
3245 *ignore_acpi_ev
= true;
3253 static void thermal_dump_all_sensors(void);
3255 static bool hotkey_notify_thermal(const u32 hkey
,
3257 bool *ignore_acpi_ev
)
3261 /* 0x6000-0x6FFF: thermal alarms */
3262 *send_acpi_ev
= true;
3263 *ignore_acpi_ev
= false;
3266 case TP_HKEY_EV_THM_TABLE_CHANGED
:
3268 "EC reports that Thermal Table has changed\n");
3269 /* recommended action: do nothing, we don't have
3270 * Lenovo ATM information */
3272 case TP_HKEY_EV_ALARM_BAT_HOT
:
3274 "THERMAL ALARM: battery is too hot!\n");
3275 /* recommended action: warn user through gui */
3277 case TP_HKEY_EV_ALARM_BAT_XHOT
:
3279 "THERMAL EMERGENCY: battery is extremely hot!\n");
3280 /* recommended action: immediate sleep/hibernate */
3282 case TP_HKEY_EV_ALARM_SENSOR_HOT
:
3285 "a sensor reports something is too hot!\n");
3286 /* recommended action: warn user through gui, that */
3287 /* some internal component is too hot */
3289 case TP_HKEY_EV_ALARM_SENSOR_XHOT
:
3291 "THERMAL EMERGENCY: "
3292 "a sensor reports something is extremely hot!\n");
3293 /* recommended action: immediate sleep/hibernate */
3297 "THERMAL ALERT: unknown thermal alarm received\n");
3301 thermal_dump_all_sensors();
3306 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3310 bool ignore_acpi_ev
;
3313 if (event
!= 0x80) {
3315 "unknown HKEY notification event %d\n", event
);
3316 /* forward it to userspace, maybe it knows how to handle it */
3317 acpi_bus_generate_netlink_event(
3318 ibm
->acpi
->device
->pnp
.device_class
,
3319 dev_name(&ibm
->acpi
->device
->dev
),
3325 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3326 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3335 send_acpi_ev
= true;
3336 ignore_acpi_ev
= false;
3338 switch (hkey
>> 12) {
3340 /* 0x1000-0x1FFF: key presses */
3341 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3345 /* 0x2000-0x2FFF: Wakeup reason */
3346 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3350 /* 0x3000-0x3FFF: bay-related wakeups */
3351 if (hkey
== TP_HKEY_EV_BAYEJ_ACK
) {
3352 hotkey_autosleep_ack
= 1;
3355 hotkey_wakeup_hotunplug_complete_notify_change();
3362 /* 0x4000-0x4FFF: dock-related wakeups */
3363 if (hkey
== TP_HKEY_EV_UNDOCK_ACK
) {
3364 hotkey_autosleep_ack
= 1;
3367 hotkey_wakeup_hotunplug_complete_notify_change();
3374 /* 0x5000-0x5FFF: human interface helpers */
3375 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3379 /* 0x6000-0x6FFF: thermal alarms */
3380 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3384 /* 0x7000-0x7FFF: misc */
3385 if (tp_features
.hotkey_wlsw
&&
3386 hkey
== TP_HKEY_EV_RFKILL_CHANGED
) {
3387 tpacpi_send_radiosw_update();
3392 /* fallthrough to default */
3397 printk(TPACPI_NOTICE
3398 "unhandled HKEY event 0x%04x\n", hkey
);
3399 printk(TPACPI_NOTICE
3400 "please report the conditions when this "
3401 "event happened to %s\n", TPACPI_MAIL
);
3405 if (!ignore_acpi_ev
&&
3406 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3407 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3411 /* netlink events */
3412 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3413 acpi_bus_generate_netlink_event(
3414 ibm
->acpi
->device
->pnp
.device_class
,
3415 dev_name(&ibm
->acpi
->device
->dev
),
3421 static void hotkey_suspend(pm_message_t state
)
3423 /* Do these on suspend, we get the events on early resume! */
3424 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3425 hotkey_autosleep_ack
= 0;
3428 static void hotkey_resume(void)
3430 tpacpi_disable_brightness_delay();
3432 if (hotkey_status_set(true) < 0 ||
3433 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3435 "error while attempting to reset the event "
3436 "firmware interface\n");
3438 tpacpi_send_radiosw_update();
3439 hotkey_tablet_mode_notify_change();
3440 hotkey_wakeup_reason_notify_change();
3441 hotkey_wakeup_hotunplug_complete_notify_change();
3442 hotkey_poll_setup_safe(false);
3445 /* procfs -------------------------------------------------------------- */
3446 static int hotkey_read(char *p
)
3451 if (!tp_features
.hotkey
) {
3452 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3456 if (mutex_lock_killable(&hotkey_mutex
))
3457 return -ERESTARTSYS
;
3458 res
= hotkey_status_get(&status
);
3460 res
= hotkey_mask_get();
3461 mutex_unlock(&hotkey_mutex
);
3465 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
3466 if (hotkey_all_mask
) {
3467 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3468 len
+= sprintf(p
+ len
,
3469 "commands:\tenable, disable, reset, <mask>\n");
3471 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
3472 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
3478 static void hotkey_enabledisable_warn(bool enable
)
3480 tpacpi_log_usertask("procfs hotkey enable/disable");
3481 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3483 "hotkey enable/disable functionality has been "
3484 "removed from the driver. Hotkeys are always "
3487 "Please remove the hotkey=enable module "
3488 "parameter, it is deprecated. Hotkeys are always "
3492 static int hotkey_write(char *buf
)
3498 if (!tp_features
.hotkey
)
3501 if (mutex_lock_killable(&hotkey_mutex
))
3502 return -ERESTARTSYS
;
3504 mask
= hotkey_user_mask
;
3507 while ((cmd
= next_cmd(&buf
))) {
3508 if (strlencmp(cmd
, "enable") == 0) {
3509 hotkey_enabledisable_warn(1);
3510 } else if (strlencmp(cmd
, "disable") == 0) {
3511 hotkey_enabledisable_warn(0);
3513 } else if (strlencmp(cmd
, "reset") == 0) {
3514 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3515 & ~hotkey_reserved_mask
;
3516 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3518 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3527 tpacpi_disclose_usertask("procfs hotkey",
3528 "set mask to 0x%08x\n", mask
);
3529 res
= hotkey_user_mask_set(mask
);
3533 mutex_unlock(&hotkey_mutex
);
3537 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3538 {TPACPI_ACPI_HKEY_HID
, 0},
3542 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3543 .hid
= ibm_htk_device_ids
,
3544 .notify
= hotkey_notify
,
3545 .handle
= &hkey_handle
,
3546 .type
= ACPI_DEVICE_NOTIFY
,
3549 static struct ibm_struct hotkey_driver_data
= {
3551 .read
= hotkey_read
,
3552 .write
= hotkey_write
,
3553 .exit
= hotkey_exit
,
3554 .resume
= hotkey_resume
,
3555 .suspend
= hotkey_suspend
,
3556 .acpi
= &ibm_hotkey_acpidriver
,
3559 /*************************************************************************
3560 * Bluetooth subdriver
3564 /* ACPI GBDC/SBDC bits */
3565 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3566 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3567 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3572 /* ACPI \BLTH commands */
3573 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3574 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3575 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3576 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3577 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3580 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3582 static struct rfkill
*tpacpi_bluetooth_rfkill
;
3584 static void bluetooth_suspend(pm_message_t state
)
3586 /* Try to make sure radio will resume powered off */
3587 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3588 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
))
3589 vdbg_printk(TPACPI_DBG_RFKILL
,
3590 "bluetooth power down on resume request failed\n");
3593 static int bluetooth_get_radiosw(void)
3597 if (!tp_features
.bluetooth
)
3600 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
3601 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3602 return RFKILL_STATE_HARD_BLOCKED
;
3604 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3605 if (dbg_bluetoothemul
)
3606 return (tpacpi_bluetooth_emulstate
) ?
3607 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3610 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3613 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3614 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3617 static void bluetooth_update_rfk(void)
3621 if (!tpacpi_bluetooth_rfkill
)
3624 status
= bluetooth_get_radiosw();
3627 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
3629 vdbg_printk(TPACPI_DBG_RFKILL
,
3630 "forced rfkill state to %d\n",
3634 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
3638 if (!tp_features
.bluetooth
)
3641 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3642 * reason to risk weird behaviour. */
3643 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3647 vdbg_printk(TPACPI_DBG_RFKILL
,
3648 "will %s bluetooth\n", radio_on
? "enable" : "disable");
3650 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3651 if (dbg_bluetoothemul
) {
3652 tpacpi_bluetooth_emulstate
= !!radio_on
;
3654 bluetooth_update_rfk();
3659 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3661 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
3664 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3668 bluetooth_update_rfk();
3673 /* sysfs bluetooth enable ---------------------------------------------- */
3674 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3675 struct device_attribute
*attr
,
3680 printk_deprecated_rfkill_attribute("bluetooth_enable");
3682 status
= bluetooth_get_radiosw();
3686 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3687 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3690 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3691 struct device_attribute
*attr
,
3692 const char *buf
, size_t count
)
3697 printk_deprecated_rfkill_attribute("bluetooth_enable");
3699 if (parse_strtoul(buf
, 1, &t
))
3702 tpacpi_disclose_usertask("bluetooth_enable", "set to %ld\n", t
);
3704 res
= bluetooth_set_radiosw(t
, 1);
3706 return (res
) ? res
: count
;
3709 static struct device_attribute dev_attr_bluetooth_enable
=
3710 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3711 bluetooth_enable_show
, bluetooth_enable_store
);
3713 /* --------------------------------------------------------------------- */
3715 static struct attribute
*bluetooth_attributes
[] = {
3716 &dev_attr_bluetooth_enable
.attr
,
3720 static const struct attribute_group bluetooth_attr_group
= {
3721 .attrs
= bluetooth_attributes
,
3724 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
3726 int bts
= bluetooth_get_radiosw();
3735 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
3737 dbg_printk(TPACPI_DBG_RFKILL
,
3738 "request to change radio state to %d\n", state
);
3739 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3742 static void bluetooth_shutdown(void)
3744 /* Order firmware to save current state to NVRAM */
3745 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3746 TP_ACPI_BLTH_SAVE_STATE
))
3747 printk(TPACPI_NOTICE
3748 "failed to save bluetooth state to NVRAM\n");
3750 vdbg_printk(TPACPI_DBG_RFKILL
,
3751 "bluestooth state saved to NVRAM\n");
3754 static void bluetooth_exit(void)
3756 bluetooth_shutdown();
3758 if (tpacpi_bluetooth_rfkill
)
3759 rfkill_unregister(tpacpi_bluetooth_rfkill
);
3761 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3762 &bluetooth_attr_group
);
3765 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3770 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3771 "initializing bluetooth subdriver\n");
3773 TPACPI_ACPIHANDLE_INIT(hkey
);
3775 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3776 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3777 tp_features
.bluetooth
= hkey_handle
&&
3778 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3780 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3781 "bluetooth is %s, status 0x%02x\n",
3782 str_supported(tp_features
.bluetooth
),
3785 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3786 if (dbg_bluetoothemul
) {
3787 tp_features
.bluetooth
= 1;
3789 "bluetooth switch emulation enabled\n");
3792 if (tp_features
.bluetooth
&&
3793 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
3794 /* no bluetooth hardware present in system */
3795 tp_features
.bluetooth
= 0;
3796 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3797 "bluetooth hardware not installed\n");
3800 if (!tp_features
.bluetooth
)
3803 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3804 &bluetooth_attr_group
);
3808 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3809 &tpacpi_bluetooth_rfkill
,
3810 RFKILL_TYPE_BLUETOOTH
,
3811 TPACPI_RFK_BLUETOOTH_SW_NAME
,
3813 tpacpi_bluetooth_rfk_set
,
3814 tpacpi_bluetooth_rfk_get
);
3823 /* procfs -------------------------------------------------------------- */
3824 static int bluetooth_read(char *p
)
3827 int status
= bluetooth_get_radiosw();
3829 if (!tp_features
.bluetooth
)
3830 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3832 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3833 (status
== RFKILL_STATE_UNBLOCKED
) ?
3834 "enabled" : "disabled");
3835 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3841 static int bluetooth_write(char *buf
)
3846 if (!tp_features
.bluetooth
)
3849 while ((cmd
= next_cmd(&buf
))) {
3850 if (strlencmp(cmd
, "enable") == 0) {
3852 } else if (strlencmp(cmd
, "disable") == 0) {
3859 tpacpi_disclose_usertask("procfs bluetooth",
3861 state
? "enable" : "disable");
3862 bluetooth_set_radiosw(state
, 1);
3868 static struct ibm_struct bluetooth_driver_data
= {
3869 .name
= "bluetooth",
3870 .read
= bluetooth_read
,
3871 .write
= bluetooth_write
,
3872 .exit
= bluetooth_exit
,
3873 .suspend
= bluetooth_suspend
,
3874 .shutdown
= bluetooth_shutdown
,
3877 /*************************************************************************
3882 /* ACPI GWAN/SWAN bits */
3883 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3884 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3885 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3889 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
3891 static struct rfkill
*tpacpi_wan_rfkill
;
3893 static void wan_suspend(pm_message_t state
)
3895 /* Try to make sure radio will resume powered off */
3896 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3897 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
))
3898 vdbg_printk(TPACPI_DBG_RFKILL
,
3899 "WWAN power down on resume request failed\n");
3902 static int wan_get_radiosw(void)
3906 if (!tp_features
.wan
)
3909 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3910 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3911 return RFKILL_STATE_HARD_BLOCKED
;
3913 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3915 return (tpacpi_wwan_emulstate
) ?
3916 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3919 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3922 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3923 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3926 static void wan_update_rfk(void)
3930 if (!tpacpi_wan_rfkill
)
3933 status
= wan_get_radiosw();
3936 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3938 vdbg_printk(TPACPI_DBG_RFKILL
,
3939 "forced rfkill state to %d\n",
3943 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3947 if (!tp_features
.wan
)
3950 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3951 * reason to risk weird behaviour. */
3952 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3956 vdbg_printk(TPACPI_DBG_RFKILL
,
3957 "will %s WWAN\n", radio_on
? "enable" : "disable");
3959 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3961 tpacpi_wwan_emulstate
= !!radio_on
;
3968 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3970 status
= TP_ACPI_WANCARD_RADIOSSW
;
3973 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3982 /* sysfs wan enable ---------------------------------------------------- */
3983 static ssize_t
wan_enable_show(struct device
*dev
,
3984 struct device_attribute
*attr
,
3989 printk_deprecated_rfkill_attribute("wwan_enable");
3991 status
= wan_get_radiosw();
3995 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3996 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3999 static ssize_t
wan_enable_store(struct device
*dev
,
4000 struct device_attribute
*attr
,
4001 const char *buf
, size_t count
)
4006 printk_deprecated_rfkill_attribute("wwan_enable");
4008 if (parse_strtoul(buf
, 1, &t
))
4011 tpacpi_disclose_usertask("wwan_enable", "set to %ld\n", t
);
4013 res
= wan_set_radiosw(t
, 1);
4015 return (res
) ? res
: count
;
4018 static struct device_attribute dev_attr_wan_enable
=
4019 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4020 wan_enable_show
, wan_enable_store
);
4022 /* --------------------------------------------------------------------- */
4024 static struct attribute
*wan_attributes
[] = {
4025 &dev_attr_wan_enable
.attr
,
4029 static const struct attribute_group wan_attr_group
= {
4030 .attrs
= wan_attributes
,
4033 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
4035 int wans
= wan_get_radiosw();
4044 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
4046 dbg_printk(TPACPI_DBG_RFKILL
,
4047 "request to change radio state to %d\n", state
);
4048 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
4051 static void wan_shutdown(void)
4053 /* Order firmware to save current state to NVRAM */
4054 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4055 TP_ACPI_WGSV_SAVE_STATE
))
4056 printk(TPACPI_NOTICE
4057 "failed to save WWAN state to NVRAM\n");
4059 vdbg_printk(TPACPI_DBG_RFKILL
,
4060 "WWAN state saved to NVRAM\n");
4063 static void wan_exit(void)
4067 if (tpacpi_wan_rfkill
)
4068 rfkill_unregister(tpacpi_wan_rfkill
);
4070 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4074 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4079 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4080 "initializing wan subdriver\n");
4082 TPACPI_ACPIHANDLE_INIT(hkey
);
4084 tp_features
.wan
= hkey_handle
&&
4085 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4087 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4088 "wan is %s, status 0x%02x\n",
4089 str_supported(tp_features
.wan
),
4092 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4094 tp_features
.wan
= 1;
4096 "wwan switch emulation enabled\n");
4099 if (tp_features
.wan
&&
4100 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4101 /* no wan hardware present in system */
4102 tp_features
.wan
= 0;
4103 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4104 "wan hardware not installed\n");
4107 if (!tp_features
.wan
)
4110 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4115 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4118 TPACPI_RFK_WWAN_SW_NAME
,
4121 tpacpi_wan_rfk_get
);
4130 /* procfs -------------------------------------------------------------- */
4131 static int wan_read(char *p
)
4134 int status
= wan_get_radiosw();
4136 tpacpi_disclose_usertask("procfs wan", "read");
4138 if (!tp_features
.wan
)
4139 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4141 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4142 (status
== RFKILL_STATE_UNBLOCKED
) ?
4143 "enabled" : "disabled");
4144 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
4150 static int wan_write(char *buf
)
4155 if (!tp_features
.wan
)
4158 while ((cmd
= next_cmd(&buf
))) {
4159 if (strlencmp(cmd
, "enable") == 0) {
4161 } else if (strlencmp(cmd
, "disable") == 0) {
4168 tpacpi_disclose_usertask("procfs wan",
4170 state
? "enable" : "disable");
4171 wan_set_radiosw(state
, 1);
4177 static struct ibm_struct wan_driver_data
= {
4182 .suspend
= wan_suspend
,
4183 .shutdown
= wan_shutdown
,
4186 /*************************************************************************
4191 /* ACPI GUWB/SUWB bits */
4192 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4193 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4196 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4198 static struct rfkill
*tpacpi_uwb_rfkill
;
4200 static int uwb_get_radiosw(void)
4204 if (!tp_features
.uwb
)
4207 /* WLSW overrides UWB in firmware/hardware, reflect that */
4208 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
4209 return RFKILL_STATE_HARD_BLOCKED
;
4211 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4213 return (tpacpi_uwb_emulstate
) ?
4214 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
4217 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4220 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4221 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
4224 static void uwb_update_rfk(void)
4228 if (!tpacpi_uwb_rfkill
)
4231 status
= uwb_get_radiosw();
4234 rfkill_force_state(tpacpi_uwb_rfkill
, status
);
4236 vdbg_printk(TPACPI_DBG_RFKILL
,
4237 "forced rfkill state to %d\n",
4241 static int uwb_set_radiosw(int radio_on
, int update_rfk
)
4245 if (!tp_features
.uwb
)
4248 /* WLSW overrides UWB in firmware/hardware, but there is no
4249 * reason to risk weird behaviour. */
4250 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
4254 vdbg_printk(TPACPI_DBG_RFKILL
,
4255 "will %s UWB\n", radio_on
? "enable" : "disable");
4257 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4259 tpacpi_uwb_emulstate
= !!radio_on
;
4266 status
= (radio_on
) ? TP_ACPI_UWB_RADIOSSW
: 0;
4267 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4276 /* --------------------------------------------------------------------- */
4278 static int tpacpi_uwb_rfk_get(void *data
, enum rfkill_state
*state
)
4280 int uwbs
= uwb_get_radiosw();
4289 static int tpacpi_uwb_rfk_set(void *data
, enum rfkill_state state
)
4291 dbg_printk(TPACPI_DBG_RFKILL
,
4292 "request to change radio state to %d\n", state
);
4293 return uwb_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
4296 static void uwb_exit(void)
4298 if (tpacpi_uwb_rfkill
)
4299 rfkill_unregister(tpacpi_uwb_rfkill
);
4302 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4307 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4308 "initializing uwb subdriver\n");
4310 TPACPI_ACPIHANDLE_INIT(hkey
);
4312 tp_features
.uwb
= hkey_handle
&&
4313 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4315 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4316 "uwb is %s, status 0x%02x\n",
4317 str_supported(tp_features
.uwb
),
4320 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4322 tp_features
.uwb
= 1;
4324 "uwb switch emulation enabled\n");
4327 if (tp_features
.uwb
&&
4328 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4329 /* no uwb hardware present in system */
4330 tp_features
.uwb
= 0;
4331 dbg_printk(TPACPI_DBG_INIT
,
4332 "uwb hardware not installed\n");
4335 if (!tp_features
.uwb
)
4338 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4341 TPACPI_RFK_UWB_SW_NAME
,
4344 tpacpi_uwb_rfk_get
);
4349 static struct ibm_struct uwb_driver_data
= {
4352 .flags
.experimental
= 1,
4355 /*************************************************************************
4359 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4361 enum video_access_mode
{
4362 TPACPI_VIDEO_NONE
= 0,
4363 TPACPI_VIDEO_570
, /* 570 */
4364 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4365 TPACPI_VIDEO_NEW
, /* all others */
4368 enum { /* video status flags, based on VIDEO_570 */
4369 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4370 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4371 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4374 enum { /* TPACPI_VIDEO_570 constants */
4375 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4376 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4377 * video_status_flags */
4378 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4379 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4382 static enum video_access_mode video_supported
;
4383 static int video_orig_autosw
;
4385 static int video_autosw_get(void);
4386 static int video_autosw_set(int enable
);
4388 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4390 static int __init
video_init(struct ibm_init_struct
*iibm
)
4394 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4396 TPACPI_ACPIHANDLE_INIT(vid
);
4397 TPACPI_ACPIHANDLE_INIT(vid2
);
4399 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4400 /* G41, assume IVGA doesn't change */
4401 vid_handle
= vid2_handle
;
4404 /* video switching not supported on R30, R31 */
4405 video_supported
= TPACPI_VIDEO_NONE
;
4406 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4408 video_supported
= TPACPI_VIDEO_570
;
4409 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4410 /* 600e/x, 770e, 770x */
4411 video_supported
= TPACPI_VIDEO_770
;
4414 video_supported
= TPACPI_VIDEO_NEW
;
4416 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4417 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4420 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4423 static void video_exit(void)
4425 dbg_printk(TPACPI_DBG_EXIT
,
4426 "restoring original video autoswitch mode\n");
4427 if (video_autosw_set(video_orig_autosw
))
4428 printk(TPACPI_ERR
"error while trying to restore original "
4429 "video autoswitch mode\n");
4432 static int video_outputsw_get(void)
4437 switch (video_supported
) {
4438 case TPACPI_VIDEO_570
:
4439 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4440 TP_ACPI_VIDEO_570_PHSCMD
))
4442 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4444 case TPACPI_VIDEO_770
:
4445 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4448 status
|= TP_ACPI_VIDEO_S_LCD
;
4449 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4452 status
|= TP_ACPI_VIDEO_S_CRT
;
4454 case TPACPI_VIDEO_NEW
:
4455 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4456 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4459 status
|= TP_ACPI_VIDEO_S_CRT
;
4461 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4462 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4465 status
|= TP_ACPI_VIDEO_S_LCD
;
4466 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4469 status
|= TP_ACPI_VIDEO_S_DVI
;
4478 static int video_outputsw_set(int status
)
4483 switch (video_supported
) {
4484 case TPACPI_VIDEO_570
:
4485 res
= acpi_evalf(NULL
, NULL
,
4486 "\\_SB.PHS2", "vdd",
4487 TP_ACPI_VIDEO_570_PHS2CMD
,
4488 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4490 case TPACPI_VIDEO_770
:
4491 autosw
= video_autosw_get();
4495 res
= video_autosw_set(1);
4498 res
= acpi_evalf(vid_handle
, NULL
,
4499 "ASWT", "vdd", status
* 0x100, 0);
4500 if (!autosw
&& video_autosw_set(autosw
)) {
4502 "video auto-switch left enabled due to error\n");
4506 case TPACPI_VIDEO_NEW
:
4507 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4508 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4514 return (res
)? 0 : -EIO
;
4517 static int video_autosw_get(void)
4521 switch (video_supported
) {
4522 case TPACPI_VIDEO_570
:
4523 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4526 case TPACPI_VIDEO_770
:
4527 case TPACPI_VIDEO_NEW
:
4528 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4538 static int video_autosw_set(int enable
)
4540 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4545 static int video_outputsw_cycle(void)
4547 int autosw
= video_autosw_get();
4553 switch (video_supported
) {
4554 case TPACPI_VIDEO_570
:
4555 res
= video_autosw_set(1);
4558 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4560 case TPACPI_VIDEO_770
:
4561 case TPACPI_VIDEO_NEW
:
4562 res
= video_autosw_set(1);
4565 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4570 if (!autosw
&& video_autosw_set(autosw
)) {
4572 "video auto-switch left enabled due to error\n");
4576 return (res
)? 0 : -EIO
;
4579 static int video_expand_toggle(void)
4581 switch (video_supported
) {
4582 case TPACPI_VIDEO_570
:
4583 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4585 case TPACPI_VIDEO_770
:
4586 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4588 case TPACPI_VIDEO_NEW
:
4589 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4597 static int video_read(char *p
)
4602 if (video_supported
== TPACPI_VIDEO_NONE
) {
4603 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4607 status
= video_outputsw_get();
4611 autosw
= video_autosw_get();
4615 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4616 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
4617 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
4618 if (video_supported
== TPACPI_VIDEO_NEW
)
4619 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
4620 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
4621 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
4622 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
4623 if (video_supported
== TPACPI_VIDEO_NEW
)
4624 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
4625 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
4626 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
4631 static int video_write(char *buf
)
4634 int enable
, disable
, status
;
4637 if (video_supported
== TPACPI_VIDEO_NONE
)
4643 while ((cmd
= next_cmd(&buf
))) {
4644 if (strlencmp(cmd
, "lcd_enable") == 0) {
4645 enable
|= TP_ACPI_VIDEO_S_LCD
;
4646 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4647 disable
|= TP_ACPI_VIDEO_S_LCD
;
4648 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4649 enable
|= TP_ACPI_VIDEO_S_CRT
;
4650 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4651 disable
|= TP_ACPI_VIDEO_S_CRT
;
4652 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4653 strlencmp(cmd
, "dvi_enable") == 0) {
4654 enable
|= TP_ACPI_VIDEO_S_DVI
;
4655 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4656 strlencmp(cmd
, "dvi_disable") == 0) {
4657 disable
|= TP_ACPI_VIDEO_S_DVI
;
4658 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4659 res
= video_autosw_set(1);
4662 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4663 res
= video_autosw_set(0);
4666 } else if (strlencmp(cmd
, "video_switch") == 0) {
4667 res
= video_outputsw_cycle();
4670 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4671 res
= video_expand_toggle();
4678 if (enable
|| disable
) {
4679 status
= video_outputsw_get();
4682 res
= video_outputsw_set((status
& ~disable
) | enable
);
4690 static struct ibm_struct video_driver_data
= {
4693 .write
= video_write
,
4697 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4699 /*************************************************************************
4700 * Light (thinklight) subdriver
4703 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4704 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4706 static int light_get_status(void)
4710 if (tp_features
.light_status
) {
4711 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4719 static int light_set_status(int status
)
4723 if (tp_features
.light
) {
4725 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4727 TP_CMOS_THINKLIGHT_ON
:
4728 TP_CMOS_THINKLIGHT_OFF
);
4730 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4733 return (rc
)? 0 : -EIO
;
4739 static void light_set_status_worker(struct work_struct
*work
)
4741 struct tpacpi_led_classdev
*data
=
4742 container_of(work
, struct tpacpi_led_classdev
, work
);
4744 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4745 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4748 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4749 enum led_brightness brightness
)
4751 struct tpacpi_led_classdev
*data
=
4752 container_of(led_cdev
,
4753 struct tpacpi_led_classdev
,
4755 data
->new_state
= (brightness
!= LED_OFF
) ?
4756 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4757 queue_work(tpacpi_wq
, &data
->work
);
4760 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4762 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4765 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4767 .name
= "tpacpi::thinklight",
4768 .brightness_set
= &light_sysfs_set
,
4769 .brightness_get
= &light_sysfs_get
,
4773 static int __init
light_init(struct ibm_init_struct
*iibm
)
4777 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4779 TPACPI_ACPIHANDLE_INIT(ledb
);
4780 TPACPI_ACPIHANDLE_INIT(lght
);
4781 TPACPI_ACPIHANDLE_INIT(cmos
);
4782 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4784 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4785 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4787 if (tp_features
.light
)
4788 /* light status not supported on
4789 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4790 tp_features
.light_status
=
4791 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4793 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4794 str_supported(tp_features
.light
),
4795 str_supported(tp_features
.light_status
));
4797 if (!tp_features
.light
)
4800 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4801 &tpacpi_led_thinklight
.led_classdev
);
4804 tp_features
.light
= 0;
4805 tp_features
.light_status
= 0;
4813 static void light_exit(void)
4815 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4816 if (work_pending(&tpacpi_led_thinklight
.work
))
4817 flush_workqueue(tpacpi_wq
);
4820 static int light_read(char *p
)
4825 if (!tp_features
.light
) {
4826 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4827 } else if (!tp_features
.light_status
) {
4828 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
4829 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4831 status
= light_get_status();
4834 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
4835 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4841 static int light_write(char *buf
)
4846 if (!tp_features
.light
)
4849 while ((cmd
= next_cmd(&buf
))) {
4850 if (strlencmp(cmd
, "on") == 0) {
4852 } else if (strlencmp(cmd
, "off") == 0) {
4858 return light_set_status(newstatus
);
4861 static struct ibm_struct light_driver_data
= {
4864 .write
= light_write
,
4868 /*************************************************************************
4872 /* sysfs cmos_command -------------------------------------------------- */
4873 static ssize_t
cmos_command_store(struct device
*dev
,
4874 struct device_attribute
*attr
,
4875 const char *buf
, size_t count
)
4877 unsigned long cmos_cmd
;
4880 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4883 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4884 return (res
)? res
: count
;
4887 static struct device_attribute dev_attr_cmos_command
=
4888 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4890 /* --------------------------------------------------------------------- */
4892 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4896 vdbg_printk(TPACPI_DBG_INIT
,
4897 "initializing cmos commands subdriver\n");
4899 TPACPI_ACPIHANDLE_INIT(cmos
);
4901 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4902 str_supported(cmos_handle
!= NULL
));
4904 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4908 return (cmos_handle
)? 0 : 1;
4911 static void cmos_exit(void)
4913 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4916 static int cmos_read(char *p
)
4920 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4921 R30, R31, T20-22, X20-21 */
4923 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4925 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4926 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4932 static int cmos_write(char *buf
)
4937 while ((cmd
= next_cmd(&buf
))) {
4938 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4939 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4944 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4952 static struct ibm_struct cmos_driver_data
= {
4955 .write
= cmos_write
,
4959 /*************************************************************************
4963 enum led_access_mode
{
4964 TPACPI_LED_NONE
= 0,
4965 TPACPI_LED_570
, /* 570 */
4966 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4967 TPACPI_LED_NEW
, /* all others */
4970 enum { /* For TPACPI_LED_OLD */
4971 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4972 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4973 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4976 static enum led_access_mode led_supported
;
4978 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4979 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4980 /* T20-22, X20-21 */
4981 "LED", /* all others */
4984 #define TPACPI_LED_NUMLEDS 16
4985 static struct tpacpi_led_classdev
*tpacpi_leds
;
4986 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4987 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4988 /* there's a limit of 19 chars + NULL before 2.6.26 */
4990 "tpacpi:orange:batt",
4991 "tpacpi:green:batt",
4992 "tpacpi::dock_active",
4993 "tpacpi::bay_active",
4994 "tpacpi::dock_batt",
4995 "tpacpi::unknown_led",
4997 "tpacpi::dock_status1",
4998 "tpacpi::dock_status2",
4999 "tpacpi::unknown_led2",
5000 "tpacpi::unknown_led3",
5001 "tpacpi::thinkvantage",
5003 #define TPACPI_SAFE_LEDS 0x1081U
5005 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
5007 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5010 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
5014 static int led_get_status(const unsigned int led
)
5017 enum led_status_t led_s
;
5019 switch (led_supported
) {
5020 case TPACPI_LED_570
:
5021 if (!acpi_evalf(ec_handle
,
5022 &status
, "GLED", "dd", 1 << led
))
5024 led_s
= (status
== 0)?
5029 tpacpi_led_state_cache
[led
] = led_s
;
5038 static int led_set_status(const unsigned int led
,
5039 const enum led_status_t ledstatus
)
5041 /* off, on, blink. Index is led_status_t */
5042 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
5043 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
5047 switch (led_supported
) {
5048 case TPACPI_LED_570
:
5050 if (unlikely(led
> 7))
5052 if (unlikely(tpacpi_is_led_restricted(led
)))
5054 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5055 (1 << led
), led_sled_arg1
[ledstatus
]))
5058 case TPACPI_LED_OLD
:
5059 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
5060 if (unlikely(led
> 7))
5062 if (unlikely(tpacpi_is_led_restricted(led
)))
5064 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
5066 rc
= ec_write(TPACPI_LED_EC_HLBL
,
5067 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5069 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5070 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5072 case TPACPI_LED_NEW
:
5074 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5076 if (unlikely(tpacpi_is_led_restricted(led
)))
5078 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5079 led
, led_led_arg1
[ledstatus
]))
5087 tpacpi_led_state_cache
[led
] = ledstatus
;
5092 static void led_set_status_worker(struct work_struct
*work
)
5094 struct tpacpi_led_classdev
*data
=
5095 container_of(work
, struct tpacpi_led_classdev
, work
);
5097 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5098 led_set_status(data
->led
, data
->new_state
);
5101 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5102 enum led_brightness brightness
)
5104 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5105 struct tpacpi_led_classdev
, led_classdev
);
5107 if (brightness
== LED_OFF
)
5108 data
->new_state
= TPACPI_LED_OFF
;
5109 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5110 data
->new_state
= TPACPI_LED_ON
;
5112 data
->new_state
= TPACPI_LED_BLINK
;
5114 queue_work(tpacpi_wq
, &data
->work
);
5117 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5118 unsigned long *delay_on
, unsigned long *delay_off
)
5120 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5121 struct tpacpi_led_classdev
, led_classdev
);
5123 /* Can we choose the flash rate? */
5124 if (*delay_on
== 0 && *delay_off
== 0) {
5125 /* yes. set them to the hardware blink rate (1 Hz) */
5126 *delay_on
= 500; /* ms */
5127 *delay_off
= 500; /* ms */
5128 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5131 data
->new_state
= TPACPI_LED_BLINK
;
5132 queue_work(tpacpi_wq
, &data
->work
);
5137 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5141 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5142 struct tpacpi_led_classdev
, led_classdev
);
5144 rc
= led_get_status(data
->led
);
5146 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5147 rc
= LED_OFF
; /* no error handling in led class :( */
5154 static void led_exit(void)
5158 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5159 if (tpacpi_leds
[i
].led_classdev
.name
)
5160 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5166 static int __init
tpacpi_init_led(unsigned int led
)
5170 tpacpi_leds
[led
].led
= led
;
5172 /* LEDs with no name don't get registered */
5173 if (!tpacpi_led_names
[led
])
5176 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5177 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5178 if (led_supported
== TPACPI_LED_570
)
5179 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5182 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5184 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5186 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5187 &tpacpi_leds
[led
].led_classdev
);
5189 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5194 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5195 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5196 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5197 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5199 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5200 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5201 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5202 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5203 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5204 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5205 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5206 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5208 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5209 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5210 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5211 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5212 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5214 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5215 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5216 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5217 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5219 /* (1) - may have excess leds enabled on MSB */
5221 /* Defaults (order matters, keep last, don't reorder!) */
5223 .vendor
= PCI_VENDOR_ID_LENOVO
,
5224 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5227 { /* IBM ThinkPads with no EC version string */
5228 .vendor
= PCI_VENDOR_ID_IBM
,
5229 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5232 { /* IBM ThinkPads with EC version string */
5233 .vendor
= PCI_VENDOR_ID_IBM
,
5234 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5239 #undef TPACPI_LEDQ_IBM
5240 #undef TPACPI_LEDQ_LNV
5242 static int __init
led_init(struct ibm_init_struct
*iibm
)
5246 unsigned long useful_leds
;
5248 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5250 TPACPI_ACPIHANDLE_INIT(led
);
5253 /* led not supported on R30, R31 */
5254 led_supported
= TPACPI_LED_NONE
;
5255 else if (strlencmp(led_path
, "SLED") == 0)
5257 led_supported
= TPACPI_LED_570
;
5258 else if (strlencmp(led_path
, "SYSL") == 0)
5259 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5260 led_supported
= TPACPI_LED_OLD
;
5263 led_supported
= TPACPI_LED_NEW
;
5265 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5266 str_supported(led_supported
), led_supported
);
5268 if (led_supported
== TPACPI_LED_NONE
)
5271 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5274 printk(TPACPI_ERR
"Out of memory for LED data\n");
5278 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5279 ARRAY_SIZE(led_useful_qtable
));
5281 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5282 if (!tpacpi_is_led_restricted(i
) &&
5283 test_bit(i
, &useful_leds
)) {
5284 rc
= tpacpi_init_led(i
);
5292 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5293 printk(TPACPI_NOTICE
5294 "warning: userspace override of important "
5295 "firmware LEDs is enabled\n");
5300 #define str_led_status(s) \
5301 ((s) == TPACPI_LED_OFF ? "off" : \
5302 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5304 static int led_read(char *p
)
5308 if (!led_supported
) {
5309 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5312 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
5314 if (led_supported
== TPACPI_LED_570
) {
5317 for (i
= 0; i
< 8; i
++) {
5318 status
= led_get_status(i
);
5321 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
5322 i
, str_led_status(status
));
5326 len
+= sprintf(p
+ len
, "commands:\t"
5327 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5332 static int led_write(char *buf
)
5336 enum led_status_t s
;
5341 while ((cmd
= next_cmd(&buf
))) {
5342 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5345 if (strstr(cmd
, "off")) {
5347 } else if (strstr(cmd
, "on")) {
5349 } else if (strstr(cmd
, "blink")) {
5350 s
= TPACPI_LED_BLINK
;
5355 rc
= led_set_status(led
, s
);
5363 static struct ibm_struct led_driver_data
= {
5370 /*************************************************************************
5374 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5376 #define TPACPI_BEEP_Q1 0x0001
5378 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5379 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5380 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5383 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5385 unsigned long quirks
;
5387 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5389 TPACPI_ACPIHANDLE_INIT(beep
);
5391 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5392 str_supported(beep_handle
!= NULL
));
5394 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5395 ARRAY_SIZE(beep_quirk_table
));
5397 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5399 return (beep_handle
)? 0 : 1;
5402 static int beep_read(char *p
)
5407 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5409 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
5410 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5416 static int beep_write(char *buf
)
5424 while ((cmd
= next_cmd(&buf
))) {
5425 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5426 beep_cmd
>= 0 && beep_cmd
<= 17) {
5430 if (tp_features
.beep_needs_two_args
) {
5431 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5435 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5444 static struct ibm_struct beep_driver_data
= {
5447 .write
= beep_write
,
5450 /*************************************************************************
5454 enum thermal_access_mode
{
5455 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5456 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5457 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5458 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5459 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5462 enum { /* TPACPI_THERMAL_TPEC_* */
5463 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5464 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5465 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5467 TPACPI_THERMAL_SENSOR_NA
= -128000, /* Sensor not available */
5471 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5472 struct ibm_thermal_sensors_struct
{
5473 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5476 static enum thermal_access_mode thermal_read_mode
;
5478 /* idx is zero-based */
5479 static int thermal_get_sensor(int idx
, s32
*value
)
5485 t
= TP_EC_THERMAL_TMP0
;
5487 switch (thermal_read_mode
) {
5488 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5489 case TPACPI_THERMAL_TPEC_16
:
5490 if (idx
>= 8 && idx
<= 15) {
5491 t
= TP_EC_THERMAL_TMP8
;
5496 case TPACPI_THERMAL_TPEC_8
:
5498 if (!acpi_ec_read(t
+ idx
, &tmp
))
5500 *value
= tmp
* 1000;
5505 case TPACPI_THERMAL_ACPI_UPDT
:
5507 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5508 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5510 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5512 *value
= (t
- 2732) * 100;
5517 case TPACPI_THERMAL_ACPI_TMP07
:
5519 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5520 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5522 if (t
> 127 || t
< -127)
5523 t
= TP_EC_THERMAL_TMP_NA
;
5529 case TPACPI_THERMAL_NONE
:
5537 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5548 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5551 for (i
= 0 ; i
< n
; i
++) {
5552 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5560 static void thermal_dump_all_sensors(void)
5563 struct ibm_thermal_sensors_struct t
;
5565 n
= thermal_get_sensors(&t
);
5569 printk(TPACPI_NOTICE
5570 "temperatures (Celsius):");
5572 for (i
= 0; i
< n
; i
++) {
5573 if (t
.temp
[i
] != TPACPI_THERMAL_SENSOR_NA
)
5574 printk(KERN_CONT
" %d", (int)(t
.temp
[i
] / 1000));
5576 printk(KERN_CONT
" N/A");
5579 printk(KERN_CONT
"\n");
5582 /* sysfs temp##_input -------------------------------------------------- */
5584 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5585 struct device_attribute
*attr
,
5588 struct sensor_device_attribute
*sensor_attr
=
5589 to_sensor_dev_attr(attr
);
5590 int idx
= sensor_attr
->index
;
5594 res
= thermal_get_sensor(idx
, &value
);
5597 if (value
== TPACPI_THERMAL_SENSOR_NA
)
5600 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5603 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5604 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5605 thermal_temp_input_show, NULL, _idxB)
5607 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5608 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5609 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5610 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5611 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5612 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5613 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5614 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5615 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5616 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5617 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5618 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5619 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5620 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5621 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5622 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5623 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5626 #define THERMAL_ATTRS(X) \
5627 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5629 static struct attribute
*thermal_temp_input_attr
[] = {
5649 static const struct attribute_group thermal_temp_input16_group
= {
5650 .attrs
= thermal_temp_input_attr
5653 static const struct attribute_group thermal_temp_input8_group
= {
5654 .attrs
= &thermal_temp_input_attr
[8]
5657 #undef THERMAL_SENSOR_ATTR_TEMP
5658 #undef THERMAL_ATTRS
5660 /* --------------------------------------------------------------------- */
5662 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5669 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5671 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5673 if (thinkpad_id
.ec_model
) {
5675 * Direct EC access mode: sensors at registers
5676 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5677 * non-implemented, thermal sensors return 0x80 when
5682 for (i
= 0; i
< 8; i
++) {
5683 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5689 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5697 /* This is sheer paranoia, but we handle it anyway */
5700 "ThinkPad ACPI EC access misbehaving, "
5701 "falling back to ACPI TMPx access "
5703 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5706 "ThinkPad ACPI EC access misbehaving, "
5707 "disabling thermal sensors access\n");
5708 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5713 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5715 } else if (acpi_tmp7
) {
5716 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5717 /* 600e/x, 770e, 770x */
5718 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5720 /* Standard ACPI TMPx access, max 8 sensors */
5721 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5724 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5725 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5728 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5729 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5732 switch (thermal_read_mode
) {
5733 case TPACPI_THERMAL_TPEC_16
:
5734 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5735 &thermal_temp_input16_group
);
5739 case TPACPI_THERMAL_TPEC_8
:
5740 case TPACPI_THERMAL_ACPI_TMP07
:
5741 case TPACPI_THERMAL_ACPI_UPDT
:
5742 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5743 &thermal_temp_input8_group
);
5747 case TPACPI_THERMAL_NONE
:
5755 static void thermal_exit(void)
5757 switch (thermal_read_mode
) {
5758 case TPACPI_THERMAL_TPEC_16
:
5759 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5760 &thermal_temp_input16_group
);
5762 case TPACPI_THERMAL_TPEC_8
:
5763 case TPACPI_THERMAL_ACPI_TMP07
:
5764 case TPACPI_THERMAL_ACPI_UPDT
:
5765 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5766 &thermal_temp_input16_group
);
5768 case TPACPI_THERMAL_NONE
:
5774 static int thermal_read(char *p
)
5778 struct ibm_thermal_sensors_struct t
;
5780 n
= thermal_get_sensors(&t
);
5781 if (unlikely(n
< 0))
5784 len
+= sprintf(p
+ len
, "temperatures:\t");
5787 for (i
= 0; i
< (n
- 1); i
++)
5788 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
5789 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
5791 len
+= sprintf(p
+ len
, "not supported\n");
5796 static struct ibm_struct thermal_driver_data
= {
5798 .read
= thermal_read
,
5799 .exit
= thermal_exit
,
5802 /*************************************************************************
5806 static u8 ecdump_regs
[256];
5808 static int ecdump_read(char *p
)
5814 len
+= sprintf(p
+ len
, "EC "
5815 " +00 +01 +02 +03 +04 +05 +06 +07"
5816 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5817 for (i
= 0; i
< 256; i
+= 16) {
5818 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
5819 for (j
= 0; j
< 16; j
++) {
5820 if (!acpi_ec_read(i
+ j
, &v
))
5822 if (v
!= ecdump_regs
[i
+ j
])
5823 len
+= sprintf(p
+ len
, " *%02x", v
);
5825 len
+= sprintf(p
+ len
, " %02x", v
);
5826 ecdump_regs
[i
+ j
] = v
;
5828 len
+= sprintf(p
+ len
, "\n");
5833 /* These are way too dangerous to advertise openly... */
5835 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
5836 " (<offset> is 00-ff, <value> is 00-ff)\n");
5837 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
5838 " (<offset> is 00-ff, <value> is 0-255)\n");
5843 static int ecdump_write(char *buf
)
5848 while ((cmd
= next_cmd(&buf
))) {
5849 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5851 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5855 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5856 if (!acpi_ec_write(i
, v
))
5865 static struct ibm_struct ecdump_driver_data
= {
5867 .read
= ecdump_read
,
5868 .write
= ecdump_write
,
5869 .flags
.experimental
= 1,
5872 /*************************************************************************
5873 * Backlight/brightness subdriver
5876 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5879 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5880 * CMOS NVRAM byte 0x5E, bits 0-3.
5882 * EC HBRV (0x31) has the following layout
5883 * Bit 7: unknown function
5884 * Bit 6: unknown function
5885 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5886 * Bit 4: must be set to zero to avoid problems
5887 * Bit 3-0: backlight brightness level
5889 * brightness_get_raw returns status data in the HBRV layout
5891 * WARNING: The X61 has been verified to use HBRV for something else, so
5892 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5893 * testing on the very early *60 Lenovo models...
5897 TP_EC_BACKLIGHT
= 0x31,
5899 /* TP_EC_BACKLIGHT bitmasks */
5900 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5901 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5902 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5905 enum tpacpi_brightness_access_mode
{
5906 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5907 TPACPI_BRGHT_MODE_EC
, /* EC control */
5908 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5909 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5910 TPACPI_BRGHT_MODE_MAX
5913 static struct backlight_device
*ibm_backlight_device
;
5915 static enum tpacpi_brightness_access_mode brightness_mode
=
5916 TPACPI_BRGHT_MODE_MAX
;
5918 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5920 static struct mutex brightness_mutex
;
5922 /* NVRAM brightness access,
5923 * call with brightness_mutex held! */
5924 static unsigned int tpacpi_brightness_nvram_get(void)
5928 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5929 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5930 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5931 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5936 static void tpacpi_brightness_checkpoint_nvram(void)
5941 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5944 vdbg_printk(TPACPI_DBG_BRGHT
,
5945 "trying to checkpoint backlight level to NVRAM...\n");
5947 if (mutex_lock_killable(&brightness_mutex
) < 0)
5950 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5952 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5953 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5955 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5956 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5957 /* NVRAM needs update */
5958 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5959 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5961 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5962 dbg_printk(TPACPI_DBG_BRGHT
,
5963 "updated NVRAM backlight level to %u (0x%02x)\n",
5964 (unsigned int) lec
, (unsigned int) b_nvram
);
5966 vdbg_printk(TPACPI_DBG_BRGHT
,
5967 "NVRAM backlight level already is %u (0x%02x)\n",
5968 (unsigned int) lec
, (unsigned int) b_nvram
);
5971 mutex_unlock(&brightness_mutex
);
5975 /* call with brightness_mutex held! */
5976 static int tpacpi_brightness_get_raw(int *status
)
5980 switch (brightness_mode
) {
5981 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5982 *status
= tpacpi_brightness_nvram_get();
5984 case TPACPI_BRGHT_MODE_EC
:
5985 case TPACPI_BRGHT_MODE_ECNVRAM
:
5986 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5995 /* call with brightness_mutex held! */
5996 /* do NOT call with illegal backlight level value */
5997 static int tpacpi_brightness_set_ec(unsigned int value
)
6001 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6004 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
6005 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
6006 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
6012 /* call with brightness_mutex held! */
6013 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
6016 unsigned int current_value
, i
;
6018 current_value
= tpacpi_brightness_nvram_get();
6020 if (value
== current_value
)
6023 cmos_cmd
= (value
> current_value
) ?
6024 TP_CMOS_BRIGHTNESS_UP
:
6025 TP_CMOS_BRIGHTNESS_DOWN
;
6026 inc
= (value
> current_value
) ? 1 : -1;
6028 for (i
= current_value
; i
!= value
; i
+= inc
)
6029 if (issue_thinkpad_cmos_command(cmos_cmd
))
6035 /* May return EINTR which can always be mapped to ERESTARTSYS */
6036 static int brightness_set(unsigned int value
)
6040 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
6044 vdbg_printk(TPACPI_DBG_BRGHT
,
6045 "set backlight level to %d\n", value
);
6047 res
= mutex_lock_killable(&brightness_mutex
);
6051 switch (brightness_mode
) {
6052 case TPACPI_BRGHT_MODE_EC
:
6053 case TPACPI_BRGHT_MODE_ECNVRAM
:
6054 res
= tpacpi_brightness_set_ec(value
);
6056 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6057 res
= tpacpi_brightness_set_ucmsstep(value
);
6063 mutex_unlock(&brightness_mutex
);
6067 /* sysfs backlight class ----------------------------------------------- */
6069 static int brightness_update_status(struct backlight_device
*bd
)
6071 unsigned int level
=
6072 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
6073 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
6074 bd
->props
.brightness
: 0;
6076 dbg_printk(TPACPI_DBG_BRGHT
,
6077 "backlight: attempt to set level to %d\n",
6080 /* it is the backlight class's job (caller) to handle
6081 * EINTR and other errors properly */
6082 return brightness_set(level
);
6085 static int brightness_get(struct backlight_device
*bd
)
6089 res
= mutex_lock_killable(&brightness_mutex
);
6093 res
= tpacpi_brightness_get_raw(&status
);
6095 mutex_unlock(&brightness_mutex
);
6100 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6103 static void tpacpi_brightness_notify_change(void)
6105 backlight_force_update(ibm_backlight_device
,
6106 BACKLIGHT_UPDATE_HOTKEY
);
6109 static struct backlight_ops ibm_backlight_data
= {
6110 .get_brightness
= brightness_get
,
6111 .update_status
= brightness_update_status
,
6114 /* --------------------------------------------------------------------- */
6117 * These are only useful for models that have only one possibility
6118 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6121 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6122 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6123 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6125 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6126 /* Models with ATI GPUs known to require ECNVRAM mode */
6127 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6129 /* Models with ATI GPUs that can use ECNVRAM */
6130 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
),
6131 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6132 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6133 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6135 /* Models with Intel Extreme Graphics 2 */
6136 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
),
6137 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6138 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6140 /* Models with Intel GMA900 */
6141 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6142 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6143 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6146 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6149 unsigned long quirks
;
6151 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6153 mutex_init(&brightness_mutex
);
6155 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6156 ARRAY_SIZE(brightness_quirk_table
));
6159 * We always attempt to detect acpi support, so as to switch
6160 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6161 * going to publish a backlight interface
6163 b
= tpacpi_check_std_acpi_brightness_support();
6165 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
6166 printk(TPACPI_NOTICE
6167 "Lenovo BIOS switched to ACPI backlight "
6170 if (brightness_enable
> 1) {
6171 printk(TPACPI_NOTICE
6172 "standard ACPI backlight interface "
6173 "available, not loading native one...\n");
6178 if (!brightness_enable
) {
6179 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6180 "brightness support disabled by "
6181 "module parameter\n");
6187 "Unsupported brightness interface, "
6188 "please contact %s\n", TPACPI_MAIL
);
6192 tp_features
.bright_16levels
= 1;
6195 * Check for module parameter bogosity, note that we
6196 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6197 * able to detect "unspecified"
6199 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6202 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6203 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6204 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6205 if (quirks
& TPACPI_BRGHT_Q_EC
)
6206 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6208 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6210 dbg_printk(TPACPI_DBG_BRGHT
,
6211 "driver auto-selected brightness_mode=%d\n",
6216 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6217 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6218 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6221 if (tpacpi_brightness_get_raw(&b
) < 0)
6224 if (tp_features
.bright_16levels
)
6226 "detected a 16-level brightness capable ThinkPad\n");
6228 ibm_backlight_device
= backlight_device_register(
6229 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6230 &ibm_backlight_data
);
6231 if (IS_ERR(ibm_backlight_device
)) {
6232 int rc
= PTR_ERR(ibm_backlight_device
);
6233 ibm_backlight_device
= NULL
;
6234 printk(TPACPI_ERR
"Could not register backlight device\n");
6237 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6238 "brightness is supported\n");
6240 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6241 printk(TPACPI_NOTICE
6242 "brightness: will use unverified default: "
6243 "brightness_mode=%d\n", brightness_mode
);
6244 printk(TPACPI_NOTICE
6245 "brightness: please report to %s whether it works well "
6246 "or not on your ThinkPad\n", TPACPI_MAIL
);
6249 ibm_backlight_device
->props
.max_brightness
=
6250 (tp_features
.bright_16levels
)? 15 : 7;
6251 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6252 backlight_update_status(ibm_backlight_device
);
6254 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6255 "brightness: registering brightness hotkeys "
6256 "as change notification\n");
6257 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6258 | TP_ACPI_HKEY_BRGHTUP_MASK
6259 | TP_ACPI_HKEY_BRGHTDWN_MASK
);;
6263 static void brightness_suspend(pm_message_t state
)
6265 tpacpi_brightness_checkpoint_nvram();
6268 static void brightness_shutdown(void)
6270 tpacpi_brightness_checkpoint_nvram();
6273 static void brightness_exit(void)
6275 if (ibm_backlight_device
) {
6276 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6277 "calling backlight_device_unregister()\n");
6278 backlight_device_unregister(ibm_backlight_device
);
6281 tpacpi_brightness_checkpoint_nvram();
6284 static int brightness_read(char *p
)
6289 level
= brightness_get(NULL
);
6291 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
6293 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
6294 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
6295 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
6296 " (<level> is 0-%d)\n",
6297 (tp_features
.bright_16levels
) ? 15 : 7);
6303 static int brightness_write(char *buf
)
6308 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6310 level
= brightness_get(NULL
);
6314 while ((cmd
= next_cmd(&buf
))) {
6315 if (strlencmp(cmd
, "up") == 0) {
6316 if (level
< max_level
)
6318 } else if (strlencmp(cmd
, "down") == 0) {
6321 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6322 level
>= 0 && level
<= max_level
) {
6328 tpacpi_disclose_usertask("procfs brightness",
6329 "set level to %d\n", level
);
6332 * Now we know what the final level should be, so we try to set it.
6333 * Doing it this way makes the syscall restartable in case of EINTR
6335 rc
= brightness_set(level
);
6336 if (!rc
&& ibm_backlight_device
)
6337 backlight_force_update(ibm_backlight_device
,
6338 BACKLIGHT_UPDATE_SYSFS
);
6339 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6342 static struct ibm_struct brightness_driver_data
= {
6343 .name
= "brightness",
6344 .read
= brightness_read
,
6345 .write
= brightness_write
,
6346 .exit
= brightness_exit
,
6347 .suspend
= brightness_suspend
,
6348 .shutdown
= brightness_shutdown
,
6351 /*************************************************************************
6355 static int volume_offset
= 0x30;
6357 static int volume_read(char *p
)
6362 if (!acpi_ec_read(volume_offset
, &level
)) {
6363 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
6365 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
6366 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
6367 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
6368 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
6369 " (<level> is 0-15)\n");
6375 static int volume_write(char *buf
)
6377 int cmos_cmd
, inc
, i
;
6379 int new_level
, new_mute
;
6382 while ((cmd
= next_cmd(&buf
))) {
6383 if (!acpi_ec_read(volume_offset
, &level
))
6385 new_mute
= mute
= level
& 0x40;
6386 new_level
= level
= level
& 0xf;
6388 if (strlencmp(cmd
, "up") == 0) {
6392 new_level
= level
== 15 ? 15 : level
+ 1;
6393 } else if (strlencmp(cmd
, "down") == 0) {
6397 new_level
= level
== 0 ? 0 : level
- 1;
6398 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
6399 new_level
>= 0 && new_level
<= 15) {
6401 } else if (strlencmp(cmd
, "mute") == 0) {
6406 if (new_level
!= level
) {
6407 /* mute doesn't change */
6409 cmos_cmd
= (new_level
> level
) ?
6410 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
6411 inc
= new_level
> level
? 1 : -1;
6413 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
6414 !acpi_ec_write(volume_offset
, level
)))
6417 for (i
= level
; i
!= new_level
; i
+= inc
)
6418 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
6419 !acpi_ec_write(volume_offset
, i
+ inc
))
6423 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
6424 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
6429 if (new_mute
!= mute
) {
6430 /* level doesn't change */
6432 cmos_cmd
= (new_mute
) ?
6433 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
6435 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
6436 !acpi_ec_write(volume_offset
, level
+ new_mute
))
6444 static struct ibm_struct volume_driver_data
= {
6446 .read
= volume_read
,
6447 .write
= volume_write
,
6450 /*************************************************************************
6457 * TPACPI_FAN_RD_ACPI_GFAN:
6458 * ACPI GFAN method: returns fan level
6460 * see TPACPI_FAN_WR_ACPI_SFAN
6461 * EC 0x2f (HFSP) not available if GFAN exists
6463 * TPACPI_FAN_WR_ACPI_SFAN:
6464 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
6466 * EC 0x2f (HFSP) might be available *for reading*, but do not use
6469 * TPACPI_FAN_WR_TPEC:
6470 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
6471 * Supported on almost all ThinkPads
6473 * Fan speed changes of any sort (including those caused by the
6474 * disengaged mode) are usually done slowly by the firmware as the
6475 * maximum ammount of fan duty cycle change per second seems to be
6478 * Reading is not available if GFAN exists.
6479 * Writing is not available if SFAN exists.
6482 * 7 automatic mode engaged;
6483 * (default operation mode of the ThinkPad)
6484 * fan level is ignored in this mode.
6485 * 6 full speed mode (takes precedence over bit 7);
6486 * not available on all thinkpads. May disable
6487 * the tachometer while the fan controller ramps up
6488 * the speed (which can take up to a few *minutes*).
6489 * Speeds up fan to 100% duty-cycle, which is far above
6490 * the standard RPM levels. It is not impossible that
6491 * it could cause hardware damage.
6492 * 5-3 unused in some models. Extra bits for fan level
6493 * in others, but still useless as all values above
6494 * 7 map to the same speed as level 7 in these models.
6495 * 2-0 fan level (0..7 usually)
6497 * 0x07 = max (set when temperatures critical)
6498 * Some ThinkPads may have other levels, see
6499 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
6501 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
6502 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
6503 * does so, its initial value is meaningless (0x07).
6505 * For firmware bugs, refer to:
6506 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6510 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
6511 * Main fan tachometer reading (in RPM)
6513 * This register is present on all ThinkPads with a new-style EC, and
6514 * it is known not to be present on the A21m/e, and T22, as there is
6515 * something else in offset 0x84 according to the ACPI DSDT. Other
6516 * ThinkPads from this same time period (and earlier) probably lack the
6517 * tachometer as well.
6519 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
6520 * was never fixed by IBM to report the EC firmware version string
6521 * probably support the tachometer (like the early X models), so
6522 * detecting it is quite hard. We need more data to know for sure.
6524 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
6527 * FIRMWARE BUG: may go stale while the EC is switching to full speed
6530 * For firmware bugs, refer to:
6531 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6535 * ThinkPad EC register 0x31 bit 0 (only on select models)
6537 * When bit 0 of EC register 0x31 is zero, the tachometer registers
6538 * show the speed of the main fan. When bit 0 of EC register 0x31
6539 * is one, the tachometer registers show the speed of the auxiliary
6542 * Fan control seems to affect both fans, regardless of the state
6545 * So far, only the firmware for the X60/X61 non-tablet versions
6546 * seem to support this (firmware TP-7M).
6548 * TPACPI_FAN_WR_ACPI_FANS:
6549 * ThinkPad X31, X40, X41. Not available in the X60.
6551 * FANS ACPI handle: takes three arguments: low speed, medium speed,
6552 * high speed. ACPI DSDT seems to map these three speeds to levels
6553 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
6554 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
6556 * The speeds are stored on handles
6557 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
6559 * There are three default speed sets, acessible as handles:
6560 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
6562 * ACPI DSDT switches which set is in use depending on various
6565 * TPACPI_FAN_WR_TPEC is also available and should be used to
6566 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
6567 * but the ACPI tables just mention level 7.
6570 enum { /* Fan control constants */
6571 fan_status_offset
= 0x2f, /* EC register 0x2f */
6572 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
6573 * 0x84 must be read before 0x85 */
6574 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
6575 bit 0 selects which fan is active */
6577 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
6578 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
6580 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
6583 enum fan_status_access_mode
{
6584 TPACPI_FAN_NONE
= 0, /* No fan status or control */
6585 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
6586 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
6589 enum fan_control_access_mode
{
6590 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
6591 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
6592 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
6593 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
6596 enum fan_control_commands
{
6597 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
6598 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
6599 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
6600 * and also watchdog cmd */
6603 static int fan_control_allowed
;
6605 static enum fan_status_access_mode fan_status_access_mode
;
6606 static enum fan_control_access_mode fan_control_access_mode
;
6607 static enum fan_control_commands fan_control_commands
;
6609 static u8 fan_control_initial_status
;
6610 static u8 fan_control_desired_level
;
6611 static u8 fan_control_resume_level
;
6612 static int fan_watchdog_maxinterval
;
6614 static struct mutex fan_mutex
;
6616 static void fan_watchdog_fire(struct work_struct
*ignored
);
6617 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
6619 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
6620 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
6621 "\\FSPD", /* 600e/x, 770e, 770x */
6623 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
6624 "JFNS", /* 770x-JL */
6628 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
6629 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
6630 * be in auto mode (0x80).
6632 * This is corrected by any write to HFSP either by the driver, or
6635 * We assume 0x07 really means auto mode while this quirk is active,
6636 * as this is far more likely than the ThinkPad being in level 7,
6637 * which is only used by the firmware during thermal emergencies.
6639 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
6640 * TP-70 (T43, R52), which are known to be buggy.
6643 static void fan_quirk1_setup(void)
6645 if (fan_control_initial_status
== 0x07) {
6646 printk(TPACPI_NOTICE
6647 "fan_init: initial fan status is unknown, "
6648 "assuming it is in auto mode\n");
6649 tp_features
.fan_ctrl_status_undef
= 1;
6653 static void fan_quirk1_handle(u8
*fan_status
)
6655 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6656 if (*fan_status
!= fan_control_initial_status
) {
6657 /* something changed the HFSP regisnter since
6658 * driver init time, so it is not undefined
6660 tp_features
.fan_ctrl_status_undef
= 0;
6662 /* Return most likely status. In fact, it
6663 * might be the only possible status */
6664 *fan_status
= TP_EC_FAN_AUTO
;
6669 /* Select main fan on X60/X61, NOOP on others */
6670 static bool fan_select_fan1(void)
6672 if (tp_features
.second_fan
) {
6675 if (ec_read(fan_select_offset
, &val
) < 0)
6678 if (ec_write(fan_select_offset
, val
) < 0)
6684 /* Select secondary fan on X60/X61 */
6685 static bool fan_select_fan2(void)
6689 if (!tp_features
.second_fan
)
6692 if (ec_read(fan_select_offset
, &val
) < 0)
6695 if (ec_write(fan_select_offset
, val
) < 0)
6702 * Call with fan_mutex held
6704 static void fan_update_desired_level(u8 status
)
6707 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6709 fan_control_desired_level
= 7;
6711 fan_control_desired_level
= status
;
6715 static int fan_get_status(u8
*status
)
6720 * Add TPACPI_FAN_RD_ACPI_FANS ? */
6722 switch (fan_status_access_mode
) {
6723 case TPACPI_FAN_RD_ACPI_GFAN
:
6724 /* 570, 600e/x, 770e, 770x */
6726 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
6734 case TPACPI_FAN_RD_TPEC
:
6735 /* all except 570, 600e/x, 770e, 770x */
6736 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
6739 if (likely(status
)) {
6741 fan_quirk1_handle(status
);
6753 static int fan_get_status_safe(u8
*status
)
6758 if (mutex_lock_killable(&fan_mutex
))
6759 return -ERESTARTSYS
;
6760 rc
= fan_get_status(&s
);
6762 fan_update_desired_level(s
);
6763 mutex_unlock(&fan_mutex
);
6771 static int fan_get_speed(unsigned int *speed
)
6775 switch (fan_status_access_mode
) {
6776 case TPACPI_FAN_RD_TPEC
:
6777 /* all except 570, 600e/x, 770e, 770x */
6778 if (unlikely(!fan_select_fan1()))
6780 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
6781 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
6785 *speed
= (hi
<< 8) | lo
;
6796 static int fan2_get_speed(unsigned int *speed
)
6801 switch (fan_status_access_mode
) {
6802 case TPACPI_FAN_RD_TPEC
:
6803 /* all except 570, 600e/x, 770e, 770x */
6804 if (unlikely(!fan_select_fan2()))
6806 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
6807 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
6808 fan_select_fan1(); /* play it safe */
6813 *speed
= (hi
<< 8) | lo
;
6824 static int fan_set_level(int level
)
6826 if (!fan_control_allowed
)
6829 switch (fan_control_access_mode
) {
6830 case TPACPI_FAN_WR_ACPI_SFAN
:
6831 if (level
>= 0 && level
<= 7) {
6832 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
6838 case TPACPI_FAN_WR_ACPI_FANS
:
6839 case TPACPI_FAN_WR_TPEC
:
6840 if (!(level
& TP_EC_FAN_AUTO
) &&
6841 !(level
& TP_EC_FAN_FULLSPEED
) &&
6842 ((level
< 0) || (level
> 7)))
6845 /* safety net should the EC not support AUTO
6846 * or FULLSPEED mode bits and just ignore them */
6847 if (level
& TP_EC_FAN_FULLSPEED
)
6848 level
|= 7; /* safety min speed 7 */
6849 else if (level
& TP_EC_FAN_AUTO
)
6850 level
|= 4; /* safety min speed 4 */
6852 if (!acpi_ec_write(fan_status_offset
, level
))
6855 tp_features
.fan_ctrl_status_undef
= 0;
6862 vdbg_printk(TPACPI_DBG_FAN
,
6863 "fan control: set fan control register to 0x%02x\n", level
);
6867 static int fan_set_level_safe(int level
)
6871 if (!fan_control_allowed
)
6874 if (mutex_lock_killable(&fan_mutex
))
6875 return -ERESTARTSYS
;
6877 if (level
== TPACPI_FAN_LAST_LEVEL
)
6878 level
= fan_control_desired_level
;
6880 rc
= fan_set_level(level
);
6882 fan_update_desired_level(level
);
6884 mutex_unlock(&fan_mutex
);
6888 static int fan_set_enable(void)
6893 if (!fan_control_allowed
)
6896 if (mutex_lock_killable(&fan_mutex
))
6897 return -ERESTARTSYS
;
6899 switch (fan_control_access_mode
) {
6900 case TPACPI_FAN_WR_ACPI_FANS
:
6901 case TPACPI_FAN_WR_TPEC
:
6902 rc
= fan_get_status(&s
);
6906 /* Don't go out of emergency fan mode */
6909 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
6912 if (!acpi_ec_write(fan_status_offset
, s
))
6915 tp_features
.fan_ctrl_status_undef
= 0;
6920 case TPACPI_FAN_WR_ACPI_SFAN
:
6921 rc
= fan_get_status(&s
);
6927 /* Set fan to at least level 4 */
6930 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
6940 mutex_unlock(&fan_mutex
);
6943 vdbg_printk(TPACPI_DBG_FAN
,
6944 "fan control: set fan control register to 0x%02x\n",
6949 static int fan_set_disable(void)
6953 if (!fan_control_allowed
)
6956 if (mutex_lock_killable(&fan_mutex
))
6957 return -ERESTARTSYS
;
6960 switch (fan_control_access_mode
) {
6961 case TPACPI_FAN_WR_ACPI_FANS
:
6962 case TPACPI_FAN_WR_TPEC
:
6963 if (!acpi_ec_write(fan_status_offset
, 0x00))
6966 fan_control_desired_level
= 0;
6967 tp_features
.fan_ctrl_status_undef
= 0;
6971 case TPACPI_FAN_WR_ACPI_SFAN
:
6972 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
6975 fan_control_desired_level
= 0;
6983 vdbg_printk(TPACPI_DBG_FAN
,
6984 "fan control: set fan control register to 0\n");
6986 mutex_unlock(&fan_mutex
);
6990 static int fan_set_speed(int speed
)
6994 if (!fan_control_allowed
)
6997 if (mutex_lock_killable(&fan_mutex
))
6998 return -ERESTARTSYS
;
7001 switch (fan_control_access_mode
) {
7002 case TPACPI_FAN_WR_ACPI_FANS
:
7003 if (speed
>= 0 && speed
<= 65535) {
7004 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
7005 speed
, speed
, speed
))
7015 mutex_unlock(&fan_mutex
);
7019 static void fan_watchdog_reset(void)
7021 static int fan_watchdog_active
;
7023 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
7026 if (fan_watchdog_active
)
7027 cancel_delayed_work(&fan_watchdog_task
);
7029 if (fan_watchdog_maxinterval
> 0 &&
7030 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
7031 fan_watchdog_active
= 1;
7032 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
7033 msecs_to_jiffies(fan_watchdog_maxinterval
7036 "failed to queue the fan watchdog, "
7037 "watchdog will not trigger\n");
7040 fan_watchdog_active
= 0;
7043 static void fan_watchdog_fire(struct work_struct
*ignored
)
7047 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
7050 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
7051 rc
= fan_set_enable();
7053 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
7054 "will try again later...\n", -rc
);
7055 /* reschedule for later */
7056 fan_watchdog_reset();
7061 * SYSFS fan layout: hwmon compatible (device)
7064 * 0: "disengaged" mode
7066 * 2: native EC "auto" mode (recommended, hardware default)
7068 * pwm*: set speed in manual mode, ignored otherwise.
7069 * 0 is level 0; 255 is level 7. Intermediate points done with linear
7072 * fan*_input: tachometer reading, RPM
7075 * SYSFS fan layout: extensions
7077 * fan_watchdog (driver):
7078 * fan watchdog interval in seconds, 0 disables (default), max 120
7081 /* sysfs fan pwm1_enable ----------------------------------------------- */
7082 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
7083 struct device_attribute
*attr
,
7089 res
= fan_get_status_safe(&status
);
7093 if (status
& TP_EC_FAN_FULLSPEED
) {
7095 } else if (status
& TP_EC_FAN_AUTO
) {
7100 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
7103 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7104 struct device_attribute
*attr
,
7105 const char *buf
, size_t count
)
7110 if (parse_strtoul(buf
, 2, &t
))
7113 tpacpi_disclose_usertask("hwmon pwm1_enable",
7114 "set fan mode to %lu\n", t
);
7118 level
= TP_EC_FAN_FULLSPEED
;
7121 level
= TPACPI_FAN_LAST_LEVEL
;
7124 level
= TP_EC_FAN_AUTO
;
7127 /* reserved for software-controlled auto mode */
7133 res
= fan_set_level_safe(level
);
7139 fan_watchdog_reset();
7144 static struct device_attribute dev_attr_fan_pwm1_enable
=
7145 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7146 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7148 /* sysfs fan pwm1 ------------------------------------------------------ */
7149 static ssize_t
fan_pwm1_show(struct device
*dev
,
7150 struct device_attribute
*attr
,
7156 res
= fan_get_status_safe(&status
);
7161 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7162 status
= fan_control_desired_level
;
7167 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7170 static ssize_t
fan_pwm1_store(struct device
*dev
,
7171 struct device_attribute
*attr
,
7172 const char *buf
, size_t count
)
7176 u8 status
, newlevel
;
7178 if (parse_strtoul(buf
, 255, &s
))
7181 tpacpi_disclose_usertask("hwmon pwm1",
7182 "set fan speed to %lu\n", s
);
7184 /* scale down from 0-255 to 0-7 */
7185 newlevel
= (s
>> 5) & 0x07;
7187 if (mutex_lock_killable(&fan_mutex
))
7188 return -ERESTARTSYS
;
7190 rc
= fan_get_status(&status
);
7191 if (!rc
&& (status
&
7192 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7193 rc
= fan_set_level(newlevel
);
7197 fan_update_desired_level(newlevel
);
7198 fan_watchdog_reset();
7202 mutex_unlock(&fan_mutex
);
7203 return (rc
)? rc
: count
;
7206 static struct device_attribute dev_attr_fan_pwm1
=
7207 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7208 fan_pwm1_show
, fan_pwm1_store
);
7210 /* sysfs fan fan1_input ------------------------------------------------ */
7211 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7212 struct device_attribute
*attr
,
7218 res
= fan_get_speed(&speed
);
7222 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7225 static struct device_attribute dev_attr_fan_fan1_input
=
7226 __ATTR(fan1_input
, S_IRUGO
,
7227 fan_fan1_input_show
, NULL
);
7229 /* sysfs fan fan2_input ------------------------------------------------ */
7230 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7231 struct device_attribute
*attr
,
7237 res
= fan2_get_speed(&speed
);
7241 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7244 static struct device_attribute dev_attr_fan_fan2_input
=
7245 __ATTR(fan2_input
, S_IRUGO
,
7246 fan_fan2_input_show
, NULL
);
7248 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
7249 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
7252 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
7255 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
7256 const char *buf
, size_t count
)
7260 if (parse_strtoul(buf
, 120, &t
))
7263 if (!fan_control_allowed
)
7266 fan_watchdog_maxinterval
= t
;
7267 fan_watchdog_reset();
7269 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
7274 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
7275 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
7277 /* --------------------------------------------------------------------- */
7278 static struct attribute
*fan_attributes
[] = {
7279 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
7280 &dev_attr_fan_fan1_input
.attr
,
7281 NULL
, /* for fan2_input */
7285 static const struct attribute_group fan_attr_group
= {
7286 .attrs
= fan_attributes
,
7289 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
7290 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
7292 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7293 { .vendor = PCI_VENDOR_ID_IBM, \
7294 .bios = TPACPI_MATCH_ANY, \
7295 .ec = TPID(__id1, __id2), \
7296 .quirks = __quirks }
7298 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7299 { .vendor = PCI_VENDOR_ID_LENOVO, \
7300 .bios = TPACPI_MATCH_ANY, \
7301 .ec = TPID(__id1, __id2), \
7302 .quirks = __quirks }
7304 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
7305 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
7306 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
7307 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
7308 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
7309 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
7312 #undef TPACPI_FAN_QL
7313 #undef TPACPI_FAN_QI
7315 static int __init
fan_init(struct ibm_init_struct
*iibm
)
7318 unsigned long quirks
;
7320 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7321 "initializing fan subdriver\n");
7323 mutex_init(&fan_mutex
);
7324 fan_status_access_mode
= TPACPI_FAN_NONE
;
7325 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7326 fan_control_commands
= 0;
7327 fan_watchdog_maxinterval
= 0;
7328 tp_features
.fan_ctrl_status_undef
= 0;
7329 tp_features
.second_fan
= 0;
7330 fan_control_desired_level
= 7;
7332 TPACPI_ACPIHANDLE_INIT(fans
);
7333 TPACPI_ACPIHANDLE_INIT(gfan
);
7334 TPACPI_ACPIHANDLE_INIT(sfan
);
7336 quirks
= tpacpi_check_quirks(fan_quirk_table
,
7337 ARRAY_SIZE(fan_quirk_table
));
7340 /* 570, 600e/x, 770e, 770x */
7341 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7343 /* all other ThinkPads: note that even old-style
7344 * ThinkPad ECs supports the fan control register */
7345 if (likely(acpi_ec_read(fan_status_offset
,
7346 &fan_control_initial_status
))) {
7347 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7348 if (quirks
& TPACPI_FAN_Q1
)
7350 if (quirks
& TPACPI_FAN_2FAN
) {
7351 tp_features
.second_fan
= 1;
7352 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7353 "secondary fan support enabled\n");
7357 "ThinkPad ACPI EC access misbehaving, "
7358 "fan status and control unavailable\n");
7365 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
7366 fan_control_commands
|=
7367 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
7370 /* gfan without sfan means no fan control */
7371 /* all other models implement TP EC 0x2f control */
7375 fan_control_access_mode
=
7376 TPACPI_FAN_WR_ACPI_FANS
;
7377 fan_control_commands
|=
7378 TPACPI_FAN_CMD_SPEED
|
7379 TPACPI_FAN_CMD_LEVEL
|
7380 TPACPI_FAN_CMD_ENABLE
;
7382 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
7383 fan_control_commands
|=
7384 TPACPI_FAN_CMD_LEVEL
|
7385 TPACPI_FAN_CMD_ENABLE
;
7390 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7391 "fan is %s, modes %d, %d\n",
7392 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
7393 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
7394 fan_status_access_mode
, fan_control_access_mode
);
7396 /* fan control master switch */
7397 if (!fan_control_allowed
) {
7398 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7399 fan_control_commands
= 0;
7400 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7401 "fan control features disabled by parameter\n");
7404 /* update fan_control_desired_level */
7405 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
7406 fan_get_status_safe(NULL
);
7408 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
7409 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
7410 if (tp_features
.second_fan
) {
7411 /* attach second fan tachometer */
7412 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
7413 &dev_attr_fan_fan2_input
.attr
;
7415 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7420 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
7421 &driver_attr_fan_watchdog
);
7423 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7432 static void fan_exit(void)
7434 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
7435 "cancelling any pending fan watchdog tasks\n");
7437 /* FIXME: can we really do this unconditionally? */
7438 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
7439 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
7440 &driver_attr_fan_watchdog
);
7442 cancel_delayed_work(&fan_watchdog_task
);
7443 flush_workqueue(tpacpi_wq
);
7446 static void fan_suspend(pm_message_t state
)
7450 if (!fan_control_allowed
)
7453 /* Store fan status in cache */
7454 fan_control_resume_level
= 0;
7455 rc
= fan_get_status_safe(&fan_control_resume_level
);
7457 printk(TPACPI_NOTICE
7458 "failed to read fan level for later "
7459 "restore during resume: %d\n", rc
);
7461 /* if it is undefined, don't attempt to restore it.
7463 if (tp_features
.fan_ctrl_status_undef
)
7464 fan_control_resume_level
= 0;
7467 static void fan_resume(void)
7469 u8 current_level
= 7;
7470 bool do_set
= false;
7473 /* DSDT *always* updates status on resume */
7474 tp_features
.fan_ctrl_status_undef
= 0;
7476 if (!fan_control_allowed
||
7477 !fan_control_resume_level
||
7478 (fan_get_status_safe(¤t_level
) < 0))
7481 switch (fan_control_access_mode
) {
7482 case TPACPI_FAN_WR_ACPI_SFAN
:
7483 /* never decrease fan level */
7484 do_set
= (fan_control_resume_level
> current_level
);
7486 case TPACPI_FAN_WR_ACPI_FANS
:
7487 case TPACPI_FAN_WR_TPEC
:
7488 /* never decrease fan level, scale is:
7489 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
7491 * We expect the firmware to set either 7 or AUTO, but we
7492 * handle FULLSPEED out of paranoia.
7494 * So, we can safely only restore FULLSPEED or 7, anything
7495 * else could slow the fan. Restoring AUTO is useless, at
7496 * best that's exactly what the DSDT already set (it is the
7499 * Always keep in mind that the DSDT *will* have set the
7500 * fans to what the vendor supposes is the best level. We
7501 * muck with it only to speed the fan up.
7503 if (fan_control_resume_level
!= 7 &&
7504 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
7507 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
7508 (current_level
!= fan_control_resume_level
);
7514 printk(TPACPI_NOTICE
7515 "restoring fan level to 0x%02x\n",
7516 fan_control_resume_level
);
7517 rc
= fan_set_level_safe(fan_control_resume_level
);
7519 printk(TPACPI_NOTICE
7520 "failed to restore fan level: %d\n", rc
);
7524 static int fan_read(char *p
)
7529 unsigned int speed
= 0;
7531 switch (fan_status_access_mode
) {
7532 case TPACPI_FAN_RD_ACPI_GFAN
:
7533 /* 570, 600e/x, 770e, 770x */
7534 rc
= fan_get_status_safe(&status
);
7538 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
7540 (status
!= 0) ? "enabled" : "disabled", status
);
7543 case TPACPI_FAN_RD_TPEC
:
7544 /* all except 570, 600e/x, 770e, 770x */
7545 rc
= fan_get_status_safe(&status
);
7549 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
7550 (status
!= 0) ? "enabled" : "disabled");
7552 rc
= fan_get_speed(&speed
);
7556 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
7558 if (status
& TP_EC_FAN_FULLSPEED
)
7559 /* Disengaged mode takes precedence */
7560 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
7561 else if (status
& TP_EC_FAN_AUTO
)
7562 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
7564 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
7567 case TPACPI_FAN_NONE
:
7569 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
7572 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
7573 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
7575 switch (fan_control_access_mode
) {
7576 case TPACPI_FAN_WR_ACPI_SFAN
:
7577 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
7581 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
7582 "auto, disengaged, full-speed)\n");
7587 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
7588 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
7589 "commands:\twatchdog <timeout> (<timeout> "
7590 "is 0 (off), 1-120 (seconds))\n");
7592 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
7593 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
7594 " (<speed> is 0-65535)\n");
7599 static int fan_write_cmd_level(const char *cmd
, int *rc
)
7603 if (strlencmp(cmd
, "level auto") == 0)
7604 level
= TP_EC_FAN_AUTO
;
7605 else if ((strlencmp(cmd
, "level disengaged") == 0) |
7606 (strlencmp(cmd
, "level full-speed") == 0))
7607 level
= TP_EC_FAN_FULLSPEED
;
7608 else if (sscanf(cmd
, "level %d", &level
) != 1)
7611 *rc
= fan_set_level_safe(level
);
7613 printk(TPACPI_ERR
"level command accepted for unsupported "
7614 "access mode %d", fan_control_access_mode
);
7616 tpacpi_disclose_usertask("procfs fan",
7617 "set level to %d\n", level
);
7622 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
7624 if (strlencmp(cmd
, "enable") != 0)
7627 *rc
= fan_set_enable();
7629 printk(TPACPI_ERR
"enable command accepted for unsupported "
7630 "access mode %d", fan_control_access_mode
);
7632 tpacpi_disclose_usertask("procfs fan", "enable\n");
7637 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
7639 if (strlencmp(cmd
, "disable") != 0)
7642 *rc
= fan_set_disable();
7644 printk(TPACPI_ERR
"disable command accepted for unsupported "
7645 "access mode %d", fan_control_access_mode
);
7647 tpacpi_disclose_usertask("procfs fan", "disable\n");
7652 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
7657 * Support speed <low> <medium> <high> ? */
7659 if (sscanf(cmd
, "speed %d", &speed
) != 1)
7662 *rc
= fan_set_speed(speed
);
7664 printk(TPACPI_ERR
"speed command accepted for unsupported "
7665 "access mode %d", fan_control_access_mode
);
7667 tpacpi_disclose_usertask("procfs fan",
7668 "set speed to %d\n", speed
);
7673 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
7677 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
7680 if (interval
< 0 || interval
> 120)
7683 fan_watchdog_maxinterval
= interval
;
7684 tpacpi_disclose_usertask("procfs fan",
7685 "set watchdog timer to %d\n",
7692 static int fan_write(char *buf
)
7697 while (!rc
&& (cmd
= next_cmd(&buf
))) {
7698 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
7699 fan_write_cmd_level(cmd
, &rc
)) &&
7700 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
7701 (fan_write_cmd_enable(cmd
, &rc
) ||
7702 fan_write_cmd_disable(cmd
, &rc
) ||
7703 fan_write_cmd_watchdog(cmd
, &rc
))) &&
7704 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
7705 fan_write_cmd_speed(cmd
, &rc
))
7709 fan_watchdog_reset();
7715 static struct ibm_struct fan_driver_data
= {
7720 .suspend
= fan_suspend
,
7721 .resume
= fan_resume
,
7724 /****************************************************************************
7725 ****************************************************************************
7729 ****************************************************************************
7730 ****************************************************************************/
7733 * HKEY event callout for other subdrivers go here
7734 * (yes, it is ugly, but it is quick, safe, and gets the job done
7736 static void tpacpi_driver_event(const unsigned int hkey_event
)
7738 if (ibm_backlight_device
) {
7739 switch (hkey_event
) {
7740 case TP_HKEY_EV_BRGHT_UP
:
7741 case TP_HKEY_EV_BRGHT_DOWN
:
7742 tpacpi_brightness_notify_change();
7749 static void hotkey_driver_event(const unsigned int scancode
)
7751 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
7754 /* sysfs name ---------------------------------------------------------- */
7755 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
7756 struct device_attribute
*attr
,
7759 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
7762 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
7763 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
7765 /* --------------------------------------------------------------------- */
7768 static struct proc_dir_entry
*proc_dir
;
7771 * Module and infrastructure proble, init and exit handling
7774 static int force_load
;
7776 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
7777 static const char * __init
str_supported(int is_supported
)
7779 static char text_unsupported
[] __initdata
= "not supported";
7781 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
7783 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
7785 static void ibm_exit(struct ibm_struct
*ibm
)
7787 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
7789 list_del_init(&ibm
->all_drivers
);
7791 if (ibm
->flags
.acpi_notify_installed
) {
7792 dbg_printk(TPACPI_DBG_EXIT
,
7793 "%s: acpi_remove_notify_handler\n", ibm
->name
);
7795 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
7797 dispatch_acpi_notify
);
7798 ibm
->flags
.acpi_notify_installed
= 0;
7799 ibm
->flags
.acpi_notify_installed
= 0;
7802 if (ibm
->flags
.proc_created
) {
7803 dbg_printk(TPACPI_DBG_EXIT
,
7804 "%s: remove_proc_entry\n", ibm
->name
);
7805 remove_proc_entry(ibm
->name
, proc_dir
);
7806 ibm
->flags
.proc_created
= 0;
7809 if (ibm
->flags
.acpi_driver_registered
) {
7810 dbg_printk(TPACPI_DBG_EXIT
,
7811 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
7813 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
7814 kfree(ibm
->acpi
->driver
);
7815 ibm
->acpi
->driver
= NULL
;
7816 ibm
->flags
.acpi_driver_registered
= 0;
7819 if (ibm
->flags
.init_called
&& ibm
->exit
) {
7821 ibm
->flags
.init_called
= 0;
7824 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
7827 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
7830 struct ibm_struct
*ibm
= iibm
->data
;
7831 struct proc_dir_entry
*entry
;
7833 BUG_ON(ibm
== NULL
);
7835 INIT_LIST_HEAD(&ibm
->all_drivers
);
7837 if (ibm
->flags
.experimental
&& !experimental
)
7840 dbg_printk(TPACPI_DBG_INIT
,
7841 "probing for %s\n", ibm
->name
);
7844 ret
= iibm
->init(iibm
);
7846 return 0; /* probe failed */
7850 ibm
->flags
.init_called
= 1;
7854 if (ibm
->acpi
->hid
) {
7855 ret
= register_tpacpi_subdriver(ibm
);
7860 if (ibm
->acpi
->notify
) {
7861 ret
= setup_acpi_notify(ibm
);
7862 if (ret
== -ENODEV
) {
7863 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
7873 dbg_printk(TPACPI_DBG_INIT
,
7874 "%s installed\n", ibm
->name
);
7877 entry
= create_proc_entry(ibm
->name
,
7878 S_IFREG
| S_IRUGO
| S_IWUSR
,
7881 printk(TPACPI_ERR
"unable to create proc entry %s\n",
7886 entry
->owner
= THIS_MODULE
;
7888 entry
->read_proc
= &dispatch_procfs_read
;
7890 entry
->write_proc
= &dispatch_procfs_write
;
7891 ibm
->flags
.proc_created
= 1;
7894 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
7899 dbg_printk(TPACPI_DBG_INIT
,
7900 "%s: at error exit path with result %d\n",
7904 return (ret
< 0)? ret
: 0;
7909 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
7911 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
7914 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
7915 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
7918 return s
&& strlen(s
) >= 8 &&
7919 tpacpi_is_fw_digit(s
[0]) &&
7920 tpacpi_is_fw_digit(s
[1]) &&
7921 s
[2] == t
&& s
[3] == 'T' &&
7922 tpacpi_is_fw_digit(s
[4]) &&
7923 tpacpi_is_fw_digit(s
[5]) &&
7924 s
[6] == 'W' && s
[7] == 'W';
7927 /* returns 0 - probe ok, or < 0 - probe error.
7928 * Probe ok doesn't mean thinkpad found.
7929 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
7930 static int __must_check __init
get_thinkpad_model_data(
7931 struct thinkpad_id_data
*tp
)
7933 const struct dmi_device
*dev
= NULL
;
7934 char ec_fw_string
[18];
7940 memset(tp
, 0, sizeof(*tp
));
7942 if (dmi_name_in_vendors("IBM"))
7943 tp
->vendor
= PCI_VENDOR_ID_IBM
;
7944 else if (dmi_name_in_vendors("LENOVO"))
7945 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
7949 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
7950 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
7951 if (s
&& !tp
->bios_version_str
)
7954 /* Really ancient ThinkPad 240X will fail this, which is fine */
7955 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
7958 tp
->bios_model
= tp
->bios_version_str
[0]
7959 | (tp
->bios_version_str
[1] << 8);
7960 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
7961 | tp
->bios_version_str
[5];
7964 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
7965 * X32 or newer, all Z series; Some models must have an
7966 * up-to-date BIOS or they will not be detected.
7968 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7970 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
7971 if (sscanf(dev
->name
,
7972 "IBM ThinkPad Embedded Controller -[%17c",
7973 ec_fw_string
) == 1) {
7974 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
7975 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
7977 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
7978 if (!tp
->ec_version_str
)
7981 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
7982 tp
->ec_model
= ec_fw_string
[0]
7983 | (ec_fw_string
[1] << 8);
7984 tp
->ec_release
= (ec_fw_string
[4] << 8)
7987 printk(TPACPI_NOTICE
7988 "ThinkPad firmware release %s "
7989 "doesn't match the known patterns\n",
7991 printk(TPACPI_NOTICE
7992 "please report this to %s\n",
7999 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
8000 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
8001 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
8006 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
8007 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
8008 if (s
&& !tp
->nummodel_str
)
8014 static int __init
probe_for_thinkpad(void)
8022 * Non-ancient models have better DMI tagging, but very old models
8023 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
8025 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
8026 (thinkpad_id
.ec_model
!= 0) ||
8027 tpacpi_is_fw_known();
8029 /* ec is required because many other handles are relative to it */
8030 TPACPI_ACPIHANDLE_INIT(ec
);
8034 "Not yet supported ThinkPad detected!\n");
8038 if (!is_thinkpad
&& !force_load
)
8045 /* Module init, exit, parameters */
8047 static struct ibm_init_struct ibms_init
[] __initdata
= {
8049 .init
= thinkpad_acpi_driver_init
,
8050 .data
= &thinkpad_acpi_driver_data
,
8053 .init
= hotkey_init
,
8054 .data
= &hotkey_driver_data
,
8057 .init
= bluetooth_init
,
8058 .data
= &bluetooth_driver_data
,
8062 .data
= &wan_driver_data
,
8066 .data
= &uwb_driver_data
,
8068 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8071 .data
= &video_driver_data
,
8076 .data
= &light_driver_data
,
8080 .data
= &cmos_driver_data
,
8084 .data
= &led_driver_data
,
8088 .data
= &beep_driver_data
,
8091 .init
= thermal_init
,
8092 .data
= &thermal_driver_data
,
8095 .data
= &ecdump_driver_data
,
8098 .init
= brightness_init
,
8099 .data
= &brightness_driver_data
,
8102 .data
= &volume_driver_data
,
8106 .data
= &fan_driver_data
,
8110 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
8113 struct ibm_struct
*ibm
;
8115 if (!kp
|| !kp
->name
|| !val
)
8118 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8119 ibm
= ibms_init
[i
].data
;
8120 WARN_ON(ibm
== NULL
);
8122 if (!ibm
|| !ibm
->name
)
8125 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8126 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8128 strcpy(ibms_init
[i
].param
, val
);
8129 strcat(ibms_init
[i
].param
, ",");
8137 module_param(experimental
, int, 0444);
8138 MODULE_PARM_DESC(experimental
,
8139 "Enables experimental features when non-zero");
8141 module_param_named(debug
, dbg_level
, uint
, 0);
8142 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8144 module_param(force_load
, bool, 0444);
8145 MODULE_PARM_DESC(force_load
,
8146 "Attempts to load the driver even on a "
8147 "mis-identified ThinkPad when true");
8149 module_param_named(fan_control
, fan_control_allowed
, bool, 0444);
8150 MODULE_PARM_DESC(fan_control
,
8151 "Enables setting fan parameters features when true");
8153 module_param_named(brightness_mode
, brightness_mode
, uint
, 0444);
8154 MODULE_PARM_DESC(brightness_mode
,
8155 "Selects brightness control strategy: "
8156 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8158 module_param(brightness_enable
, uint
, 0444);
8159 MODULE_PARM_DESC(brightness_enable
,
8160 "Enables backlight control when 1, disables when 0");
8162 module_param(hotkey_report_mode
, uint
, 0444);
8163 MODULE_PARM_DESC(hotkey_report_mode
,
8164 "used for backwards compatibility with userspace, "
8165 "see documentation");
8167 #define TPACPI_PARAM(feature) \
8168 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8169 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8170 "at module load, see documentation")
8172 TPACPI_PARAM(hotkey
);
8173 TPACPI_PARAM(bluetooth
);
8174 TPACPI_PARAM(video
);
8175 TPACPI_PARAM(light
);
8179 TPACPI_PARAM(ecdump
);
8180 TPACPI_PARAM(brightness
);
8181 TPACPI_PARAM(volume
);
8184 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8185 module_param(dbg_wlswemul
, uint
, 0444);
8186 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
8187 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
8188 MODULE_PARM_DESC(wlsw_state
,
8189 "Initial state of the emulated WLSW switch");
8191 module_param(dbg_bluetoothemul
, uint
, 0444);
8192 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
8193 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
8194 MODULE_PARM_DESC(bluetooth_state
,
8195 "Initial state of the emulated bluetooth switch");
8197 module_param(dbg_wwanemul
, uint
, 0444);
8198 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
8199 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
8200 MODULE_PARM_DESC(wwan_state
,
8201 "Initial state of the emulated WWAN switch");
8203 module_param(dbg_uwbemul
, uint
, 0444);
8204 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
8205 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
8206 MODULE_PARM_DESC(uwb_state
,
8207 "Initial state of the emulated UWB switch");
8210 static void thinkpad_acpi_module_exit(void)
8212 struct ibm_struct
*ibm
, *itmp
;
8214 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
8216 list_for_each_entry_safe_reverse(ibm
, itmp
,
8217 &tpacpi_all_drivers
,
8222 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
8224 if (tpacpi_inputdev
) {
8225 if (tp_features
.input_device_registered
)
8226 input_unregister_device(tpacpi_inputdev
);
8228 input_free_device(tpacpi_inputdev
);
8232 hwmon_device_unregister(tpacpi_hwmon
);
8234 if (tp_features
.sensors_pdev_attrs_registered
)
8235 device_remove_file(&tpacpi_sensors_pdev
->dev
,
8236 &dev_attr_thinkpad_acpi_pdev_name
);
8237 if (tpacpi_sensors_pdev
)
8238 platform_device_unregister(tpacpi_sensors_pdev
);
8240 platform_device_unregister(tpacpi_pdev
);
8242 if (tp_features
.sensors_pdrv_attrs_registered
)
8243 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
8244 if (tp_features
.platform_drv_attrs_registered
)
8245 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
8247 if (tp_features
.sensors_pdrv_registered
)
8248 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
8250 if (tp_features
.platform_drv_registered
)
8251 platform_driver_unregister(&tpacpi_pdriver
);
8254 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
8257 destroy_workqueue(tpacpi_wq
);
8259 kfree(thinkpad_id
.bios_version_str
);
8260 kfree(thinkpad_id
.ec_version_str
);
8261 kfree(thinkpad_id
.model_str
);
8265 static int __init
thinkpad_acpi_module_init(void)
8269 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
8271 /* Parameter checking */
8272 if (hotkey_report_mode
> 2)
8275 /* Driver-level probe */
8277 ret
= get_thinkpad_model_data(&thinkpad_id
);
8280 "unable to get DMI data: %d\n", ret
);
8281 thinkpad_acpi_module_exit();
8284 ret
= probe_for_thinkpad();
8286 thinkpad_acpi_module_exit();
8290 /* Driver initialization */
8292 TPACPI_ACPIHANDLE_INIT(ecrd
);
8293 TPACPI_ACPIHANDLE_INIT(ecwr
);
8295 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
8297 thinkpad_acpi_module_exit();
8301 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
8304 "unable to create proc dir " TPACPI_PROC_DIR
);
8305 thinkpad_acpi_module_exit();
8308 proc_dir
->owner
= THIS_MODULE
;
8310 ret
= platform_driver_register(&tpacpi_pdriver
);
8313 "unable to register main platform driver\n");
8314 thinkpad_acpi_module_exit();
8317 tp_features
.platform_drv_registered
= 1;
8319 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
8322 "unable to register hwmon platform driver\n");
8323 thinkpad_acpi_module_exit();
8326 tp_features
.sensors_pdrv_registered
= 1;
8328 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
8330 tp_features
.platform_drv_attrs_registered
= 1;
8331 ret
= tpacpi_create_driver_attributes(
8332 &tpacpi_hwmon_pdriver
.driver
);
8336 "unable to create sysfs driver attributes\n");
8337 thinkpad_acpi_module_exit();
8340 tp_features
.sensors_pdrv_attrs_registered
= 1;
8343 /* Device initialization */
8344 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
8346 if (IS_ERR(tpacpi_pdev
)) {
8347 ret
= PTR_ERR(tpacpi_pdev
);
8349 printk(TPACPI_ERR
"unable to register platform device\n");
8350 thinkpad_acpi_module_exit();
8353 tpacpi_sensors_pdev
= platform_device_register_simple(
8354 TPACPI_HWMON_DRVR_NAME
,
8356 if (IS_ERR(tpacpi_sensors_pdev
)) {
8357 ret
= PTR_ERR(tpacpi_sensors_pdev
);
8358 tpacpi_sensors_pdev
= NULL
;
8360 "unable to register hwmon platform device\n");
8361 thinkpad_acpi_module_exit();
8364 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
8365 &dev_attr_thinkpad_acpi_pdev_name
);
8368 "unable to create sysfs hwmon device attributes\n");
8369 thinkpad_acpi_module_exit();
8372 tp_features
.sensors_pdev_attrs_registered
= 1;
8373 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
8374 if (IS_ERR(tpacpi_hwmon
)) {
8375 ret
= PTR_ERR(tpacpi_hwmon
);
8376 tpacpi_hwmon
= NULL
;
8377 printk(TPACPI_ERR
"unable to register hwmon device\n");
8378 thinkpad_acpi_module_exit();
8381 mutex_init(&tpacpi_inputdev_send_mutex
);
8382 tpacpi_inputdev
= input_allocate_device();
8383 if (!tpacpi_inputdev
) {
8384 printk(TPACPI_ERR
"unable to allocate input device\n");
8385 thinkpad_acpi_module_exit();
8388 /* Prepare input device, but don't register */
8389 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
8390 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
8391 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
8392 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
8393 thinkpad_id
.vendor
:
8395 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
8396 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
8397 tpacpi_inputdev
->dev
.parent
= &tpacpi_pdev
->dev
;
8399 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8400 ret
= ibm_init(&ibms_init
[i
]);
8401 if (ret
>= 0 && *ibms_init
[i
].param
)
8402 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
8404 thinkpad_acpi_module_exit();
8408 ret
= input_register_device(tpacpi_inputdev
);
8410 printk(TPACPI_ERR
"unable to register input device\n");
8411 thinkpad_acpi_module_exit();
8414 tp_features
.input_device_registered
= 1;
8417 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
8421 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
8424 * This will autoload the driver in almost every ThinkPad
8425 * in widespread use.
8427 * Only _VERY_ old models, like the 240, 240x and 570 lack
8428 * the HKEY event interface.
8430 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
8433 * DMI matching for module autoloading
8435 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8436 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
8438 * Only models listed in thinkwiki will be supported, so add yours
8439 * if it is not there yet.
8441 #define IBM_BIOS_MODULE_ALIAS(__type) \
8442 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
8444 /* Ancient thinkpad BIOSes have to be identified by
8445 * BIOS type or model number, and there are far less
8446 * BIOS types than model numbers... */
8447 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
8449 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
8450 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
8451 MODULE_DESCRIPTION(TPACPI_DESC
);
8452 MODULE_VERSION(TPACPI_VERSION
);
8453 MODULE_LICENSE("GPL");
8455 module_init(thinkpad_acpi_module_init
);
8456 module_exit(thinkpad_acpi_module_exit
);