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 0x020400
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 */
148 /****************************************************************************
152 #define TPACPI_NAME "thinkpad"
153 #define TPACPI_DESC "ThinkPad ACPI Extras"
154 #define TPACPI_FILE TPACPI_NAME "_acpi"
155 #define TPACPI_URL "http://ibm-acpi.sf.net/"
156 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
158 #define TPACPI_PROC_DIR "ibm"
159 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
160 #define TPACPI_DRVR_NAME TPACPI_FILE
161 #define TPACPI_DRVR_SHORTNAME "tpacpi"
162 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
164 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
165 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
167 #define TPACPI_MAX_ACPI_ARGS 3
169 /* rfkill switches */
171 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
172 TPACPI_RFK_WWAN_SW_ID
,
173 TPACPI_RFK_UWB_SW_ID
,
177 #define TPACPI_LOG TPACPI_FILE ": "
178 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
179 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
180 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
181 #define TPACPI_ERR KERN_ERR TPACPI_LOG
182 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
183 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
184 #define TPACPI_INFO KERN_INFO TPACPI_LOG
185 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
187 /* Debugging printk groups */
188 #define TPACPI_DBG_ALL 0xffff
189 #define TPACPI_DBG_DISCLOSETASK 0x8000
190 #define TPACPI_DBG_INIT 0x0001
191 #define TPACPI_DBG_EXIT 0x0002
192 #define TPACPI_DBG_RFKILL 0x0004
193 #define TPACPI_DBG_HKEY 0x0008
194 #define TPACPI_DBG_FAN 0x0010
195 #define TPACPI_DBG_BRGHT 0x0020
197 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
198 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
199 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
202 /****************************************************************************
203 * Driver-wide structs and misc. variables
208 struct tp_acpi_drv_struct
{
209 const struct acpi_device_id
*hid
;
210 struct acpi_driver
*driver
;
212 void (*notify
) (struct ibm_struct
*, u32
);
215 struct acpi_device
*device
;
221 int (*read
) (char *);
222 int (*write
) (char *);
224 void (*resume
) (void);
225 void (*suspend
) (pm_message_t state
);
226 void (*shutdown
) (void);
228 struct list_head all_drivers
;
230 struct tp_acpi_drv_struct
*acpi
;
233 u8 acpi_driver_registered
:1;
234 u8 acpi_notify_installed
:1;
241 struct ibm_init_struct
{
244 int (*init
) (struct ibm_init_struct
*);
245 struct ibm_struct
*data
;
256 u32 bright_16levels
:1;
257 u32 bright_acpimode
:1;
260 u32 fan_ctrl_status_undef
:1;
262 u32 beep_needs_two_args
:1;
263 u32 input_device_registered
:1;
264 u32 platform_drv_registered
:1;
265 u32 platform_drv_attrs_registered
:1;
266 u32 sensors_pdrv_registered
:1;
267 u32 sensors_pdrv_attrs_registered
:1;
268 u32 sensors_pdev_attrs_registered
:1;
269 u32 hotkey_poll_active
:1;
273 u16 hotkey_mask_ff
:1;
276 struct thinkpad_id_data
{
277 unsigned int vendor
; /* ThinkPad vendor:
278 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
280 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
281 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
283 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
285 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
288 char *model_str
; /* ThinkPad T43 */
289 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
291 static struct thinkpad_id_data thinkpad_id
;
294 TPACPI_LIFE_INIT
= 0,
299 static int experimental
;
300 static u32 dbg_level
;
302 static struct workqueue_struct
*tpacpi_wq
;
310 /* Special LED class that can defer work */
311 struct tpacpi_led_classdev
{
312 struct led_classdev led_classdev
;
313 struct work_struct work
;
314 enum led_status_t new_state
;
318 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
319 static int dbg_wlswemul
;
320 static int tpacpi_wlsw_emulstate
;
321 static int dbg_bluetoothemul
;
322 static int tpacpi_bluetooth_emulstate
;
323 static int dbg_wwanemul
;
324 static int tpacpi_wwan_emulstate
;
325 static int dbg_uwbemul
;
326 static int tpacpi_uwb_emulstate
;
330 /*************************************************************************
334 #define dbg_printk(a_dbg_level, format, arg...) \
335 do { if (dbg_level & (a_dbg_level)) \
336 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
339 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
340 #define vdbg_printk dbg_printk
341 static const char *str_supported(int is_supported
);
343 #define vdbg_printk(a_dbg_level, format, arg...) \
347 static void tpacpi_log_usertask(const char * const what
)
349 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
350 what
, task_tgid_vnr(current
));
353 #define tpacpi_disclose_usertask(what, format, arg...) \
356 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
357 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
358 printk(TPACPI_DEBUG "%s: PID %d: " format, \
359 what, task_tgid_vnr(current), ## arg); \
364 * Quirk handling helpers
366 * ThinkPad IDs and versions seen in the field so far
367 * are two-characters from the set [0-9A-Z], i.e. base 36.
369 * We use values well outside that range as specials.
372 #define TPACPI_MATCH_ANY 0xffffU
373 #define TPACPI_MATCH_UNKNOWN 0U
375 /* TPID('1', 'Y') == 0x5931 */
376 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
378 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
379 { .vendor = PCI_VENDOR_ID_IBM, \
380 .bios = TPID(__id1, __id2), \
381 .ec = TPACPI_MATCH_ANY, \
382 .quirks = (__quirk) }
384 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
385 { .vendor = PCI_VENDOR_ID_LENOVO, \
386 .bios = TPID(__id1, __id2), \
387 .ec = TPACPI_MATCH_ANY, \
388 .quirks = (__quirk) }
390 struct tpacpi_quirk
{
394 unsigned long quirks
;
398 * tpacpi_check_quirks() - search BIOS/EC version on a list
399 * @qlist: array of &struct tpacpi_quirk
400 * @qlist_size: number of elements in @qlist
402 * Iterates over a quirks list until one is found that matches the
403 * ThinkPad's vendor, BIOS and EC model.
405 * Returns 0 if nothing matches, otherwise returns the quirks field of
406 * the matching &struct tpacpi_quirk entry.
408 * The match criteria is: vendor, ec and bios much match.
410 static unsigned long __init
tpacpi_check_quirks(
411 const struct tpacpi_quirk
*qlist
,
412 unsigned int qlist_size
)
415 if ((qlist
->vendor
== thinkpad_id
.vendor
||
416 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
417 (qlist
->bios
== thinkpad_id
.bios_model
||
418 qlist
->bios
== TPACPI_MATCH_ANY
) &&
419 (qlist
->ec
== thinkpad_id
.ec_model
||
420 qlist
->ec
== TPACPI_MATCH_ANY
))
421 return qlist
->quirks
;
430 /****************************************************************************
431 ****************************************************************************
433 * ACPI Helpers and device model
435 ****************************************************************************
436 ****************************************************************************/
438 /*************************************************************************
442 static acpi_handle root_handle
;
444 #define TPACPI_HANDLE(object, parent, paths...) \
445 static acpi_handle object##_handle; \
446 static acpi_handle *object##_parent = &parent##_handle; \
447 static char *object##_path; \
448 static char *object##_paths[] = { paths }
450 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
451 "\\_SB.PCI.ISA.EC", /* 570 */
452 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
453 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
454 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
455 "\\_SB.PCI0.ICH3.EC0", /* R31 */
456 "\\_SB.PCI0.LPC.EC", /* all others */
459 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
460 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
462 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
464 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
465 "\\CMS", /* R40, R40e */
468 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
469 "^HKEY", /* R30, R31 */
470 "HKEY", /* all others */
473 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
474 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
475 "\\_SB.PCI0.VID0", /* 770e */
476 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
477 "\\_SB.PCI0.AGP.VID", /* all others */
481 /*************************************************************************
485 static int acpi_evalf(acpi_handle handle
,
486 void *res
, char *method
, char *fmt
, ...)
489 struct acpi_object_list params
;
490 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
491 struct acpi_buffer result
, *resultp
;
492 union acpi_object out_obj
;
500 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
513 params
.pointer
= &in_objs
[0];
520 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
521 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
523 /* add more types as needed */
525 printk(TPACPI_ERR
"acpi_evalf() called "
526 "with invalid format character '%c'\n", c
);
532 if (res_type
!= 'v') {
533 result
.length
= sizeof(out_obj
);
534 result
.pointer
= &out_obj
;
539 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
544 *(int *)res
= out_obj
.integer
.value
;
545 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
548 success
= status
== AE_OK
;
550 /* add more types as needed */
552 printk(TPACPI_ERR
"acpi_evalf() called "
553 "with invalid format character '%c'\n", res_type
);
557 if (!success
&& !quiet
)
558 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
559 method
, fmt0
, status
);
564 static int acpi_ec_read(int i
, u8
*p
)
569 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
573 if (ec_read(i
, p
) < 0)
580 static int acpi_ec_write(int i
, u8 v
)
583 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
586 if (ec_write(i
, v
) < 0)
593 static int issue_thinkpad_cmos_command(int cmos_cmd
)
598 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
604 /*************************************************************************
608 #define TPACPI_ACPIHANDLE_INIT(object) \
609 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
610 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
612 static void drv_acpi_handle_init(char *name
,
613 acpi_handle
*handle
, acpi_handle parent
,
614 char **paths
, int num_paths
, char **path
)
619 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
622 for (i
= 0; i
< num_paths
; i
++) {
623 status
= acpi_get_handle(parent
, paths
[i
], handle
);
624 if (ACPI_SUCCESS(status
)) {
626 dbg_printk(TPACPI_DBG_INIT
,
627 "Found ACPI handle %s for %s\n",
633 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
638 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
640 struct ibm_struct
*ibm
= data
;
642 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
645 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
648 ibm
->acpi
->notify(ibm
, event
);
651 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
658 if (!*ibm
->acpi
->handle
)
661 vdbg_printk(TPACPI_DBG_INIT
,
662 "setting up ACPI notify for %s\n", ibm
->name
);
664 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
666 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
671 ibm
->acpi
->device
->driver_data
= ibm
;
672 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
673 TPACPI_ACPI_EVENT_PREFIX
,
676 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
677 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
678 if (ACPI_FAILURE(status
)) {
679 if (status
== AE_ALREADY_EXISTS
) {
681 "another device driver is already "
682 "handling %s events\n", ibm
->name
);
685 "acpi_install_notify_handler(%s) failed: %d\n",
690 ibm
->flags
.acpi_notify_installed
= 1;
694 static int __init
tpacpi_device_add(struct acpi_device
*device
)
699 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
703 dbg_printk(TPACPI_DBG_INIT
,
704 "registering %s as an ACPI driver\n", ibm
->name
);
708 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
709 if (!ibm
->acpi
->driver
) {
711 "failed to allocate memory for ibm->acpi->driver\n");
715 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
716 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
718 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
720 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
722 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
724 kfree(ibm
->acpi
->driver
);
725 ibm
->acpi
->driver
= NULL
;
727 ibm
->flags
.acpi_driver_registered
= 1;
733 /****************************************************************************
734 ****************************************************************************
738 ****************************************************************************
739 ****************************************************************************/
741 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
742 int count
, int *eof
, void *data
)
744 struct ibm_struct
*ibm
= data
;
747 if (!ibm
|| !ibm
->read
)
750 len
= ibm
->read(page
);
754 if (len
<= off
+ count
)
766 static int dispatch_procfs_write(struct file
*file
,
767 const char __user
*userbuf
,
768 unsigned long count
, void *data
)
770 struct ibm_struct
*ibm
= data
;
774 if (!ibm
|| !ibm
->write
)
776 if (count
> PAGE_SIZE
- 2)
779 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
783 if (copy_from_user(kernbuf
, userbuf
, count
)) {
789 strcat(kernbuf
, ",");
790 ret
= ibm
->write(kernbuf
);
799 static char *next_cmd(char **cmds
)
804 while ((end
= strchr(start
, ',')) && end
== start
)
816 /****************************************************************************
817 ****************************************************************************
819 * Device model: input, hwmon and platform
821 ****************************************************************************
822 ****************************************************************************/
824 static struct platform_device
*tpacpi_pdev
;
825 static struct platform_device
*tpacpi_sensors_pdev
;
826 static struct device
*tpacpi_hwmon
;
827 static struct input_dev
*tpacpi_inputdev
;
828 static struct mutex tpacpi_inputdev_send_mutex
;
829 static LIST_HEAD(tpacpi_all_drivers
);
831 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
834 struct ibm_struct
*ibm
, *itmp
;
836 list_for_each_entry_safe(ibm
, itmp
,
840 (ibm
->suspend
)(state
);
846 static int tpacpi_resume_handler(struct platform_device
*pdev
)
848 struct ibm_struct
*ibm
, *itmp
;
850 list_for_each_entry_safe(ibm
, itmp
,
860 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
862 struct ibm_struct
*ibm
, *itmp
;
864 list_for_each_entry_safe(ibm
, itmp
,
872 static struct platform_driver tpacpi_pdriver
= {
874 .name
= TPACPI_DRVR_NAME
,
875 .owner
= THIS_MODULE
,
877 .suspend
= tpacpi_suspend_handler
,
878 .resume
= tpacpi_resume_handler
,
879 .shutdown
= tpacpi_shutdown_handler
,
882 static struct platform_driver tpacpi_hwmon_pdriver
= {
884 .name
= TPACPI_HWMON_DRVR_NAME
,
885 .owner
= THIS_MODULE
,
889 /*************************************************************************
890 * sysfs support helpers
893 struct attribute_set
{
894 unsigned int members
, max_members
;
895 struct attribute_group group
;
898 struct attribute_set_obj
{
899 struct attribute_set s
;
901 } __attribute__((packed
));
903 static struct attribute_set
*create_attr_set(unsigned int max_members
,
906 struct attribute_set_obj
*sobj
;
908 if (max_members
== 0)
911 /* Allocates space for implicit NULL at the end too */
912 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
913 max_members
* sizeof(struct attribute
*),
917 sobj
->s
.max_members
= max_members
;
918 sobj
->s
.group
.attrs
= &sobj
->a
;
919 sobj
->s
.group
.name
= name
;
924 #define destroy_attr_set(_set) \
927 /* not multi-threaded safe, use it in a single thread per set */
928 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
933 if (s
->members
>= s
->max_members
)
936 s
->group
.attrs
[s
->members
] = attr
;
942 static int add_many_to_attr_set(struct attribute_set
*s
,
943 struct attribute
**attr
,
948 for (i
= 0; i
< count
; i
++) {
949 res
= add_to_attr_set(s
, attr
[i
]);
957 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
959 sysfs_remove_group(kobj
, &s
->group
);
963 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
964 sysfs_create_group(_kobj, &_attr_set->group)
966 static int parse_strtoul(const char *buf
,
967 unsigned long max
, unsigned long *value
)
971 while (*buf
&& isspace(*buf
))
973 *value
= simple_strtoul(buf
, &endp
, 0);
974 while (*endp
&& isspace(*endp
))
976 if (*endp
|| *value
> max
)
982 static void tpacpi_disable_brightness_delay(void)
984 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
986 "ACPI backlight control delay disabled\n");
989 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
991 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
992 union acpi_object
*obj
;
995 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
996 obj
= (union acpi_object
*)buffer
.pointer
;
997 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
998 printk(TPACPI_ERR
"Unknown _BCL data, "
999 "please report this to %s\n", TPACPI_MAIL
);
1002 rc
= obj
->package
.count
;
1008 kfree(buffer
.pointer
);
1012 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1013 u32 lvl
, void *context
, void **rv
)
1015 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1016 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1018 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1019 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1020 BUG_ON(!rv
|| !*rv
);
1021 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1022 return AE_CTRL_TERMINATE
;
1029 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1031 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1035 void *bcl_ptr
= &bcl_levels
;
1038 TPACPI_ACPIHANDLE_INIT(vid
);
1044 * Search for a _BCL method, and execute it. This is safe on all
1045 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1046 * BIOS in ACPI backlight control mode. We do NOT have to care
1047 * about calling the _BCL method in an enabled video device, any
1048 * will do for our purposes.
1051 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1052 tpacpi_acpi_walk_find_bcl
, NULL
,
1055 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1056 tp_features
.bright_acpimode
= 1;
1057 return (bcl_levels
- 2);
1063 static int __init
tpacpi_new_rfkill(const unsigned int id
,
1064 struct rfkill
**rfk
,
1065 const enum rfkill_type rfktype
,
1067 const bool set_default
,
1068 int (*toggle_radio
)(void *, enum rfkill_state
),
1069 int (*get_state
)(void *, enum rfkill_state
*))
1072 enum rfkill_state initial_state
= RFKILL_STATE_SOFT_BLOCKED
;
1074 res
= get_state(NULL
, &initial_state
);
1077 "failed to read initial state for %s, error %d; "
1078 "will turn radio off\n", name
, res
);
1079 } else if (set_default
) {
1080 /* try to set the initial state as the default for the rfkill
1081 * type, since we ask the firmware to preserve it across S5 in
1083 if (rfkill_set_default(rfktype
,
1084 (initial_state
== RFKILL_STATE_UNBLOCKED
) ?
1085 RFKILL_STATE_UNBLOCKED
:
1086 RFKILL_STATE_SOFT_BLOCKED
) == -EPERM
)
1087 vdbg_printk(TPACPI_DBG_RFKILL
,
1088 "Default state for %s cannot be changed\n",
1092 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
1095 "failed to allocate memory for rfkill class\n");
1099 (*rfk
)->name
= name
;
1100 (*rfk
)->get_state
= get_state
;
1101 (*rfk
)->toggle_radio
= toggle_radio
;
1102 (*rfk
)->state
= initial_state
;
1104 res
= rfkill_register(*rfk
);
1107 "failed to register %s rfkill switch: %d\n",
1117 static void printk_deprecated_attribute(const char * const what
,
1118 const char * const details
)
1120 tpacpi_log_usertask("deprecated sysfs attribute");
1121 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1122 "will be removed. %s\n",
1126 static void printk_deprecated_rfkill_attribute(const char * const what
)
1128 printk_deprecated_attribute(what
,
1129 "Please switch to generic rfkill before year 2010");
1132 /*************************************************************************
1133 * thinkpad-acpi driver attributes
1136 /* interface_version --------------------------------------------------- */
1137 static ssize_t
tpacpi_driver_interface_version_show(
1138 struct device_driver
*drv
,
1141 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1144 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1145 tpacpi_driver_interface_version_show
, NULL
);
1147 /* debug_level --------------------------------------------------------- */
1148 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1151 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1154 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1155 const char *buf
, size_t count
)
1159 if (parse_strtoul(buf
, 0xffff, &t
))
1167 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1168 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1170 /* version ------------------------------------------------------------- */
1171 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1174 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1175 TPACPI_DESC
, TPACPI_VERSION
);
1178 static DRIVER_ATTR(version
, S_IRUGO
,
1179 tpacpi_driver_version_show
, NULL
);
1181 /* --------------------------------------------------------------------- */
1183 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1185 static void tpacpi_send_radiosw_update(void);
1187 /* wlsw_emulstate ------------------------------------------------------ */
1188 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1191 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1194 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1195 const char *buf
, size_t count
)
1199 if (parse_strtoul(buf
, 1, &t
))
1202 if (tpacpi_wlsw_emulstate
!= t
) {
1203 tpacpi_wlsw_emulstate
= !!t
;
1204 tpacpi_send_radiosw_update();
1206 tpacpi_wlsw_emulstate
= !!t
;
1211 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1212 tpacpi_driver_wlsw_emulstate_show
,
1213 tpacpi_driver_wlsw_emulstate_store
);
1215 /* bluetooth_emulstate ------------------------------------------------- */
1216 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1217 struct device_driver
*drv
,
1220 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1223 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1224 struct device_driver
*drv
,
1225 const char *buf
, size_t count
)
1229 if (parse_strtoul(buf
, 1, &t
))
1232 tpacpi_bluetooth_emulstate
= !!t
;
1237 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1238 tpacpi_driver_bluetooth_emulstate_show
,
1239 tpacpi_driver_bluetooth_emulstate_store
);
1241 /* wwan_emulstate ------------------------------------------------- */
1242 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1243 struct device_driver
*drv
,
1246 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1249 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1250 struct device_driver
*drv
,
1251 const char *buf
, size_t count
)
1255 if (parse_strtoul(buf
, 1, &t
))
1258 tpacpi_wwan_emulstate
= !!t
;
1263 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1264 tpacpi_driver_wwan_emulstate_show
,
1265 tpacpi_driver_wwan_emulstate_store
);
1267 /* uwb_emulstate ------------------------------------------------- */
1268 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1269 struct device_driver
*drv
,
1272 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1275 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1276 struct device_driver
*drv
,
1277 const char *buf
, size_t count
)
1281 if (parse_strtoul(buf
, 1, &t
))
1284 tpacpi_uwb_emulstate
= !!t
;
1289 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1290 tpacpi_driver_uwb_emulstate_show
,
1291 tpacpi_driver_uwb_emulstate_store
);
1294 /* --------------------------------------------------------------------- */
1296 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1297 &driver_attr_debug_level
, &driver_attr_version
,
1298 &driver_attr_interface_version
,
1301 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1307 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1308 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1312 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1313 if (!res
&& dbg_wlswemul
)
1314 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1315 if (!res
&& dbg_bluetoothemul
)
1316 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1317 if (!res
&& dbg_wwanemul
)
1318 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1319 if (!res
&& dbg_uwbemul
)
1320 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1326 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1330 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1331 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1333 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1334 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1335 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1336 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1337 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1341 /****************************************************************************
1342 ****************************************************************************
1346 ****************************************************************************
1347 ****************************************************************************/
1349 /*************************************************************************
1350 * thinkpad-acpi init subdriver
1353 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1355 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1356 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1358 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1359 (thinkpad_id
.bios_version_str
) ?
1360 thinkpad_id
.bios_version_str
: "unknown",
1361 (thinkpad_id
.ec_version_str
) ?
1362 thinkpad_id
.ec_version_str
: "unknown");
1364 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1365 printk(TPACPI_INFO
"%s %s, model %s\n",
1366 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1367 "IBM" : ((thinkpad_id
.vendor
==
1368 PCI_VENDOR_ID_LENOVO
) ?
1369 "Lenovo" : "Unknown vendor"),
1370 thinkpad_id
.model_str
,
1371 (thinkpad_id
.nummodel_str
) ?
1372 thinkpad_id
.nummodel_str
: "unknown");
1377 static int thinkpad_acpi_driver_read(char *p
)
1381 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1382 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1387 static struct ibm_struct thinkpad_acpi_driver_data
= {
1389 .read
= thinkpad_acpi_driver_read
,
1392 /*************************************************************************
1396 enum { /* hot key scan codes (derived from ACPI DSDT) */
1397 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1398 TP_ACPI_HOTKEYSCAN_FNF2
,
1399 TP_ACPI_HOTKEYSCAN_FNF3
,
1400 TP_ACPI_HOTKEYSCAN_FNF4
,
1401 TP_ACPI_HOTKEYSCAN_FNF5
,
1402 TP_ACPI_HOTKEYSCAN_FNF6
,
1403 TP_ACPI_HOTKEYSCAN_FNF7
,
1404 TP_ACPI_HOTKEYSCAN_FNF8
,
1405 TP_ACPI_HOTKEYSCAN_FNF9
,
1406 TP_ACPI_HOTKEYSCAN_FNF10
,
1407 TP_ACPI_HOTKEYSCAN_FNF11
,
1408 TP_ACPI_HOTKEYSCAN_FNF12
,
1409 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1410 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1411 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1412 TP_ACPI_HOTKEYSCAN_FNHOME
,
1413 TP_ACPI_HOTKEYSCAN_FNEND
,
1414 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1415 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1416 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1417 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1418 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1419 TP_ACPI_HOTKEYSCAN_MUTE
,
1420 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1423 enum { /* Keys available through NVRAM polling */
1424 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1425 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1428 enum { /* Positions of some of the keys in hotkey masks */
1429 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1430 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1431 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1432 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1433 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1434 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1435 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1436 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1437 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1438 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1439 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1442 enum { /* NVRAM to ACPI HKEY group map */
1443 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1444 TP_ACPI_HKEY_ZOOM_MASK
|
1445 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1446 TP_ACPI_HKEY_HIBERNATE_MASK
,
1447 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1448 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1449 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1450 TP_ACPI_HKEY_VOLDWN_MASK
|
1451 TP_ACPI_HKEY_MUTE_MASK
,
1454 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1455 struct tp_nvram_state
{
1456 u16 thinkpad_toggle
:1;
1458 u16 display_toggle
:1;
1459 u16 thinklight_toggle
:1;
1460 u16 hibernate_toggle
:1;
1461 u16 displayexp_toggle
:1;
1462 u16 display_state
:1;
1463 u16 brightness_toggle
:1;
1464 u16 volume_toggle
:1;
1467 u8 brightness_level
;
1471 static struct task_struct
*tpacpi_hotkey_task
;
1472 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1473 static int hotkey_poll_freq
= 10; /* Hz */
1474 static struct mutex hotkey_thread_mutex
;
1475 static struct mutex hotkey_thread_data_mutex
;
1476 static unsigned int hotkey_config_change
;
1478 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1480 #define hotkey_source_mask 0U
1482 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1484 static struct mutex hotkey_mutex
;
1486 static enum { /* Reasons for waking up */
1487 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1488 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1489 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1490 } hotkey_wakeup_reason
;
1492 static int hotkey_autosleep_ack
;
1494 static u32 hotkey_orig_mask
;
1495 static u32 hotkey_all_mask
;
1496 static u32 hotkey_reserved_mask
;
1497 static u32 hotkey_mask
;
1499 static unsigned int hotkey_report_mode
;
1501 static u16
*hotkey_keycode_map
;
1503 static struct attribute_set
*hotkey_dev_attributes
;
1505 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1506 #define HOTKEY_CONFIG_CRITICAL_START \
1508 mutex_lock(&hotkey_thread_data_mutex); \
1509 hotkey_config_change++; \
1511 #define HOTKEY_CONFIG_CRITICAL_END \
1512 mutex_unlock(&hotkey_thread_data_mutex);
1514 #define HOTKEY_CONFIG_CRITICAL_START
1515 #define HOTKEY_CONFIG_CRITICAL_END
1516 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1518 /* HKEY.MHKG() return bits */
1519 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1521 static int hotkey_get_wlsw(int *status
)
1523 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1525 *status
= !!tpacpi_wlsw_emulstate
;
1529 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1534 static int hotkey_get_tablet_mode(int *status
)
1538 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1541 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1546 * Call with hotkey_mutex held
1548 static int hotkey_mask_get(void)
1552 if (tp_features
.hotkey_mask
) {
1553 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1556 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1562 * Call with hotkey_mutex held
1564 static int hotkey_mask_set(u32 mask
)
1569 if (tp_features
.hotkey_mask
) {
1570 if (!tp_warned
.hotkey_mask_ff
&&
1571 (mask
== 0xffff || mask
== 0xffffff ||
1572 mask
== 0xffffffff)) {
1573 tp_warned
.hotkey_mask_ff
= 1;
1574 printk(TPACPI_NOTICE
1575 "setting the hotkey mask to 0x%08x is likely "
1576 "not the best way to go about it\n", mask
);
1577 printk(TPACPI_NOTICE
1578 "please consider using the driver defaults, "
1579 "and refer to up-to-date thinkpad-acpi "
1583 HOTKEY_CONFIG_CRITICAL_START
1584 for (i
= 0; i
< 32; i
++) {
1586 /* enable in firmware mask only keys not in NVRAM
1587 * mode, but enable the key in the cached hotkey_mask
1588 * regardless of mode, or the key will end up
1589 * disabled by hotkey_mask_get() */
1590 if (!acpi_evalf(hkey_handle
,
1591 NULL
, "MHKM", "vdd", i
+ 1,
1592 !!((mask
& ~hotkey_source_mask
) & m
))) {
1596 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1599 HOTKEY_CONFIG_CRITICAL_END
1601 /* hotkey_mask_get must be called unconditionally below */
1602 if (!hotkey_mask_get() && !rc
&&
1603 (hotkey_mask
& ~hotkey_source_mask
) !=
1604 (mask
& ~hotkey_source_mask
)) {
1605 printk(TPACPI_NOTICE
1606 "requested hot key mask 0x%08x, but "
1607 "firmware forced it to 0x%08x\n",
1611 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1612 HOTKEY_CONFIG_CRITICAL_START
1613 hotkey_mask
= mask
& hotkey_source_mask
;
1614 HOTKEY_CONFIG_CRITICAL_END
1616 if (hotkey_mask
!= mask
) {
1617 printk(TPACPI_NOTICE
1618 "requested hot key mask 0x%08x, "
1619 "forced to 0x%08x (NVRAM poll mask is "
1620 "0x%08x): no firmware mask support\n",
1621 mask
, hotkey_mask
, hotkey_source_mask
);
1626 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1632 static int hotkey_status_get(int *status
)
1634 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1640 static int hotkey_status_set(bool enable
)
1642 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
1648 static void tpacpi_input_send_tabletsw(void)
1652 if (tp_features
.hotkey_tablet
&&
1653 !hotkey_get_tablet_mode(&state
)) {
1654 mutex_lock(&tpacpi_inputdev_send_mutex
);
1656 input_report_switch(tpacpi_inputdev
,
1657 SW_TABLET_MODE
, !!state
);
1658 input_sync(tpacpi_inputdev
);
1660 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1664 static void tpacpi_input_send_key(unsigned int scancode
)
1666 unsigned int keycode
;
1668 keycode
= hotkey_keycode_map
[scancode
];
1670 if (keycode
!= KEY_RESERVED
) {
1671 mutex_lock(&tpacpi_inputdev_send_mutex
);
1673 input_report_key(tpacpi_inputdev
, keycode
, 1);
1674 if (keycode
== KEY_UNKNOWN
)
1675 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1677 input_sync(tpacpi_inputdev
);
1679 input_report_key(tpacpi_inputdev
, keycode
, 0);
1680 if (keycode
== KEY_UNKNOWN
)
1681 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1683 input_sync(tpacpi_inputdev
);
1685 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1689 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1690 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1692 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1694 tpacpi_input_send_key(scancode
);
1695 if (hotkey_report_mode
< 2) {
1696 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1697 0x80, 0x1001 + scancode
);
1701 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1705 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1706 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1707 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1708 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1709 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1710 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1712 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1713 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1714 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1716 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1717 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1718 n
->displayexp_toggle
=
1719 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1721 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1722 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1723 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1724 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1725 n
->brightness_toggle
=
1726 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1728 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1729 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1730 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1731 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1732 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1733 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1737 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1739 if ((mask & (1 << __scancode)) && \
1740 oldn->__member != newn->__member) \
1741 tpacpi_hotkey_send_key(__scancode); \
1744 #define TPACPI_MAY_SEND_KEY(__scancode) \
1745 do { if (mask & (1 << __scancode)) \
1746 tpacpi_hotkey_send_key(__scancode); } while (0)
1748 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1749 struct tp_nvram_state
*newn
,
1752 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1753 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1754 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1755 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1757 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1759 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1762 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1763 if (oldn
->mute
!= newn
->mute
) {
1764 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1766 if (oldn
->volume_level
> newn
->volume_level
) {
1767 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1768 } else if (oldn
->volume_level
< newn
->volume_level
) {
1769 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1770 } else if (oldn
->mute
== newn
->mute
) {
1771 /* repeated key presses that didn't change state */
1773 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1774 } else if (newn
->volume_level
!= 0) {
1775 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1777 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1782 /* handle brightness */
1783 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1784 if (oldn
->brightness_level
< newn
->brightness_level
) {
1785 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1786 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1787 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1789 /* repeated key presses that didn't change state */
1790 if (newn
->brightness_level
!= 0) {
1791 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1793 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1799 #undef TPACPI_COMPARE_KEY
1800 #undef TPACPI_MAY_SEND_KEY
1802 static int hotkey_kthread(void *data
)
1804 struct tp_nvram_state s
[2];
1806 unsigned int si
, so
;
1808 unsigned int change_detector
, must_reset
;
1810 mutex_lock(&hotkey_thread_mutex
);
1812 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1821 /* Initial state for compares */
1822 mutex_lock(&hotkey_thread_data_mutex
);
1823 change_detector
= hotkey_config_change
;
1824 mask
= hotkey_source_mask
& hotkey_mask
;
1825 mutex_unlock(&hotkey_thread_data_mutex
);
1826 hotkey_read_nvram(&s
[so
], mask
);
1828 while (!kthread_should_stop() && hotkey_poll_freq
) {
1830 t
= 1000/hotkey_poll_freq
;
1831 t
= msleep_interruptible(t
);
1832 if (unlikely(kthread_should_stop()))
1834 must_reset
= try_to_freeze();
1835 if (t
> 0 && !must_reset
)
1838 mutex_lock(&hotkey_thread_data_mutex
);
1839 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1840 /* forget old state on thaw or config change */
1843 change_detector
= hotkey_config_change
;
1845 mask
= hotkey_source_mask
& hotkey_mask
;
1846 mutex_unlock(&hotkey_thread_data_mutex
);
1849 hotkey_read_nvram(&s
[si
], mask
);
1850 if (likely(si
!= so
)) {
1851 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1861 mutex_unlock(&hotkey_thread_mutex
);
1865 static void hotkey_poll_stop_sync(void)
1867 if (tpacpi_hotkey_task
) {
1868 if (frozen(tpacpi_hotkey_task
) ||
1869 freezing(tpacpi_hotkey_task
))
1870 thaw_process(tpacpi_hotkey_task
);
1872 kthread_stop(tpacpi_hotkey_task
);
1873 tpacpi_hotkey_task
= NULL
;
1874 mutex_lock(&hotkey_thread_mutex
);
1875 /* at this point, the thread did exit */
1876 mutex_unlock(&hotkey_thread_mutex
);
1880 /* call with hotkey_mutex held */
1881 static void hotkey_poll_setup(int may_warn
)
1883 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1884 hotkey_poll_freq
> 0 &&
1885 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1886 if (!tpacpi_hotkey_task
) {
1887 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1888 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
1889 if (IS_ERR(tpacpi_hotkey_task
)) {
1890 tpacpi_hotkey_task
= NULL
;
1892 "could not create kernel thread "
1893 "for hotkey polling\n");
1897 hotkey_poll_stop_sync();
1899 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1900 printk(TPACPI_NOTICE
1901 "hot keys 0x%08x require polling, "
1902 "which is currently disabled\n",
1903 hotkey_source_mask
);
1908 static void hotkey_poll_setup_safe(int may_warn
)
1910 mutex_lock(&hotkey_mutex
);
1911 hotkey_poll_setup(may_warn
);
1912 mutex_unlock(&hotkey_mutex
);
1915 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1917 static void hotkey_poll_setup_safe(int __unused
)
1921 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1923 static int hotkey_inputdev_open(struct input_dev
*dev
)
1925 switch (tpacpi_lifecycle
) {
1926 case TPACPI_LIFE_INIT
:
1928 * hotkey_init will call hotkey_poll_setup_safe
1929 * at the appropriate moment
1932 case TPACPI_LIFE_EXITING
:
1934 case TPACPI_LIFE_RUNNING
:
1935 hotkey_poll_setup_safe(0);
1939 /* Should only happen if tpacpi_lifecycle is corrupt */
1944 static void hotkey_inputdev_close(struct input_dev
*dev
)
1946 /* disable hotkey polling when possible */
1947 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1948 hotkey_poll_setup_safe(0);
1951 /* sysfs hotkey enable ------------------------------------------------- */
1952 static ssize_t
hotkey_enable_show(struct device
*dev
,
1953 struct device_attribute
*attr
,
1958 printk_deprecated_attribute("hotkey_enable",
1959 "Hotkey reporting is always enabled");
1961 res
= hotkey_status_get(&status
);
1965 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1968 static ssize_t
hotkey_enable_store(struct device
*dev
,
1969 struct device_attribute
*attr
,
1970 const char *buf
, size_t count
)
1974 printk_deprecated_attribute("hotkey_enable",
1975 "Hotkeys can be disabled through hotkey_mask");
1977 if (parse_strtoul(buf
, 1, &t
))
1986 static struct device_attribute dev_attr_hotkey_enable
=
1987 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1988 hotkey_enable_show
, hotkey_enable_store
);
1990 /* sysfs hotkey mask --------------------------------------------------- */
1991 static ssize_t
hotkey_mask_show(struct device
*dev
,
1992 struct device_attribute
*attr
,
1997 if (mutex_lock_killable(&hotkey_mutex
))
1998 return -ERESTARTSYS
;
1999 res
= hotkey_mask_get();
2000 mutex_unlock(&hotkey_mutex
);
2003 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
2006 static ssize_t
hotkey_mask_store(struct device
*dev
,
2007 struct device_attribute
*attr
,
2008 const char *buf
, size_t count
)
2013 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2016 if (mutex_lock_killable(&hotkey_mutex
))
2017 return -ERESTARTSYS
;
2019 res
= hotkey_mask_set(t
);
2021 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2022 hotkey_poll_setup(1);
2025 mutex_unlock(&hotkey_mutex
);
2027 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2029 return (res
) ? res
: count
;
2032 static struct device_attribute dev_attr_hotkey_mask
=
2033 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2034 hotkey_mask_show
, hotkey_mask_store
);
2036 /* sysfs hotkey bios_enabled ------------------------------------------- */
2037 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2038 struct device_attribute
*attr
,
2041 return sprintf(buf
, "0\n");
2044 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2045 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2047 /* sysfs hotkey bios_mask ---------------------------------------------- */
2048 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2049 struct device_attribute
*attr
,
2052 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2055 static struct device_attribute dev_attr_hotkey_bios_mask
=
2056 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2058 /* sysfs hotkey all_mask ----------------------------------------------- */
2059 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2060 struct device_attribute
*attr
,
2063 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2064 hotkey_all_mask
| hotkey_source_mask
);
2067 static struct device_attribute dev_attr_hotkey_all_mask
=
2068 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2070 /* sysfs hotkey recommended_mask --------------------------------------- */
2071 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2072 struct device_attribute
*attr
,
2075 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2076 (hotkey_all_mask
| hotkey_source_mask
)
2077 & ~hotkey_reserved_mask
);
2080 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2081 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2082 hotkey_recommended_mask_show
, NULL
);
2084 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2086 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2087 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2088 struct device_attribute
*attr
,
2091 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2094 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2095 struct device_attribute
*attr
,
2096 const char *buf
, size_t count
)
2100 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2101 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2104 if (mutex_lock_killable(&hotkey_mutex
))
2105 return -ERESTARTSYS
;
2107 HOTKEY_CONFIG_CRITICAL_START
2108 hotkey_source_mask
= t
;
2109 HOTKEY_CONFIG_CRITICAL_END
2111 hotkey_poll_setup(1);
2113 mutex_unlock(&hotkey_mutex
);
2115 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2120 static struct device_attribute dev_attr_hotkey_source_mask
=
2121 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2122 hotkey_source_mask_show
, hotkey_source_mask_store
);
2124 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2125 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2126 struct device_attribute
*attr
,
2129 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2132 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2133 struct device_attribute
*attr
,
2134 const char *buf
, size_t count
)
2138 if (parse_strtoul(buf
, 25, &t
))
2141 if (mutex_lock_killable(&hotkey_mutex
))
2142 return -ERESTARTSYS
;
2144 hotkey_poll_freq
= t
;
2146 hotkey_poll_setup(1);
2147 mutex_unlock(&hotkey_mutex
);
2149 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2154 static struct device_attribute dev_attr_hotkey_poll_freq
=
2155 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2156 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2158 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2160 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2161 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2162 struct device_attribute
*attr
,
2166 res
= hotkey_get_wlsw(&s
);
2170 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2173 static struct device_attribute dev_attr_hotkey_radio_sw
=
2174 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2176 static void hotkey_radio_sw_notify_change(void)
2178 if (tp_features
.hotkey_wlsw
)
2179 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2183 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2184 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2185 struct device_attribute
*attr
,
2189 res
= hotkey_get_tablet_mode(&s
);
2193 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2196 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2197 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2199 static void hotkey_tablet_mode_notify_change(void)
2201 if (tp_features
.hotkey_tablet
)
2202 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2203 "hotkey_tablet_mode");
2206 /* sysfs hotkey report_mode -------------------------------------------- */
2207 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2208 struct device_attribute
*attr
,
2211 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2212 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2215 static struct device_attribute dev_attr_hotkey_report_mode
=
2216 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2218 /* sysfs wakeup reason (pollable) -------------------------------------- */
2219 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2220 struct device_attribute
*attr
,
2223 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2226 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2227 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2229 static void hotkey_wakeup_reason_notify_change(void)
2231 if (tp_features
.hotkey_mask
)
2232 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2236 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2237 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2238 struct device_attribute
*attr
,
2241 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2244 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2245 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2246 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2248 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2250 if (tp_features
.hotkey_mask
)
2251 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2252 "wakeup_hotunplug_complete");
2255 /* --------------------------------------------------------------------- */
2257 static struct attribute
*hotkey_attributes
[] __initdata
= {
2258 &dev_attr_hotkey_enable
.attr
,
2259 &dev_attr_hotkey_bios_enabled
.attr
,
2260 &dev_attr_hotkey_report_mode
.attr
,
2261 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2262 &dev_attr_hotkey_mask
.attr
,
2263 &dev_attr_hotkey_all_mask
.attr
,
2264 &dev_attr_hotkey_recommended_mask
.attr
,
2265 &dev_attr_hotkey_source_mask
.attr
,
2266 &dev_attr_hotkey_poll_freq
.attr
,
2270 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
2271 &dev_attr_hotkey_bios_mask
.attr
,
2272 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2273 &dev_attr_hotkey_mask
.attr
,
2274 &dev_attr_hotkey_all_mask
.attr
,
2275 &dev_attr_hotkey_recommended_mask
.attr
,
2277 &dev_attr_hotkey_wakeup_reason
.attr
,
2278 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2281 static void bluetooth_update_rfk(void);
2282 static void wan_update_rfk(void);
2283 static void uwb_update_rfk(void);
2284 static void tpacpi_send_radiosw_update(void)
2288 /* Sync these BEFORE sending any rfkill events */
2289 if (tp_features
.bluetooth
)
2290 bluetooth_update_rfk();
2291 if (tp_features
.wan
)
2293 if (tp_features
.uwb
)
2296 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2297 mutex_lock(&tpacpi_inputdev_send_mutex
);
2299 input_report_switch(tpacpi_inputdev
,
2300 SW_RFKILL_ALL
, !!wlsw
);
2301 input_sync(tpacpi_inputdev
);
2303 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2305 hotkey_radio_sw_notify_change();
2308 static void hotkey_exit(void)
2310 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2311 hotkey_poll_stop_sync();
2314 if (hotkey_dev_attributes
)
2315 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2317 kfree(hotkey_keycode_map
);
2319 if (tp_features
.hotkey
) {
2320 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
2321 "restoring original hot key mask\n");
2322 /* no short-circuit boolean operator below! */
2323 if ((hotkey_mask_set(hotkey_orig_mask
) |
2324 hotkey_status_set(false)) != 0)
2326 "failed to restore hot key mask "
2327 "to BIOS defaults\n");
2331 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2333 /* Requirements for changing the default keymaps:
2335 * 1. Many of the keys are mapped to KEY_RESERVED for very
2336 * good reasons. Do not change them unless you have deep
2337 * knowledge on the IBM and Lenovo ThinkPad firmware for
2338 * the various ThinkPad models. The driver behaves
2339 * differently for KEY_RESERVED: such keys have their
2340 * hot key mask *unset* in mask_recommended, and also
2341 * in the initial hot key mask programmed into the
2342 * firmware at driver load time, which means the firm-
2343 * ware may react very differently if you change them to
2346 * 2. You must be subscribed to the linux-thinkpad and
2347 * ibm-acpi-devel mailing lists, and you should read the
2348 * list archives since 2007 if you want to change the
2349 * keymaps. This requirement exists so that you will
2350 * know the past history of problems with the thinkpad-
2351 * acpi driver keymaps, and also that you will be
2352 * listening to any bug reports;
2354 * 3. Do not send thinkpad-acpi specific patches directly to
2355 * for merging, *ever*. Send them to the linux-acpi
2356 * mailinglist for comments. Merging is to be done only
2357 * through acpi-test and the ACPI maintainer.
2359 * If the above is too much to ask, don't change the keymap.
2360 * Ask the thinkpad-acpi maintainer to do it, instead.
2362 static u16 ibm_keycode_map
[] __initdata
= {
2363 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2364 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2365 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2366 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2368 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2369 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2370 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2371 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2373 /* brightness: firmware always reacts to them, unless
2374 * X.org did some tricks in the radeon BIOS scratch
2375 * registers of *some* models */
2376 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2377 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2379 /* Thinklight: firmware always react to it */
2380 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2382 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2383 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2385 /* Volume: firmware always react to it and reprograms
2386 * the built-in *extra* mixer. Never map it to control
2387 * another mixer by default. */
2388 KEY_RESERVED
, /* 0x14: VOLUME UP */
2389 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2390 KEY_RESERVED
, /* 0x16: MUTE */
2392 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2394 /* (assignments unknown, please report if found) */
2395 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2396 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2398 static u16 lenovo_keycode_map
[] __initdata
= {
2399 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2400 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2401 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2402 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2404 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2405 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2406 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2407 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2409 /* These either have to go through ACPI video, or
2410 * act like in the IBM ThinkPads, so don't ever
2411 * enable them by default */
2412 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2413 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2415 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2417 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2418 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2420 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2421 * react to it and reprograms the built-in *extra* mixer.
2422 * Never map it to control another mixer by default.
2424 * T60?, T61, R60?, R61: firmware and EC tries to send
2425 * these over the regular keyboard, so these are no-ops,
2426 * but there are still weird bugs re. MUTE, so do not
2427 * change unless you get test reports from all Lenovo
2428 * models. May cause the BIOS to interfere with the
2431 KEY_RESERVED
, /* 0x14: VOLUME UP */
2432 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2433 KEY_RESERVED
, /* 0x16: MUTE */
2435 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2437 /* (assignments unknown, please report if found) */
2438 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2439 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2442 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2443 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2444 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2450 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2451 "initializing hotkey subdriver\n");
2453 BUG_ON(!tpacpi_inputdev
);
2454 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2455 tpacpi_inputdev
->close
!= NULL
);
2457 TPACPI_ACPIHANDLE_INIT(hkey
);
2458 mutex_init(&hotkey_mutex
);
2460 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2461 mutex_init(&hotkey_thread_mutex
);
2462 mutex_init(&hotkey_thread_data_mutex
);
2465 /* hotkey not supported on 570 */
2466 tp_features
.hotkey
= hkey_handle
!= NULL
;
2468 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2470 str_supported(tp_features
.hotkey
));
2472 if (!tp_features
.hotkey
)
2475 tpacpi_disable_brightness_delay();
2477 hotkey_dev_attributes
= create_attr_set(13, NULL
);
2478 if (!hotkey_dev_attributes
)
2480 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2482 ARRAY_SIZE(hotkey_attributes
));
2486 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2487 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2488 for HKEY interface version 0x100 */
2489 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2490 if ((hkeyv
>> 8) != 1) {
2491 printk(TPACPI_ERR
"unknown version of the "
2492 "HKEY interface: 0x%x\n", hkeyv
);
2493 printk(TPACPI_ERR
"please report this to %s\n",
2497 * MHKV 0x100 in A31, R40, R40e,
2498 * T4x, X31, and later
2500 tp_features
.hotkey_mask
= 1;
2501 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2502 "firmware HKEY interface version: 0x%x\n",
2507 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2508 "hotkey masks are %s\n",
2509 str_supported(tp_features
.hotkey_mask
));
2511 if (tp_features
.hotkey_mask
) {
2512 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2515 "missing MHKA handler, "
2516 "please report this to %s\n",
2518 /* FN+F12, FN+F4, FN+F3 */
2519 hotkey_all_mask
= 0x080cU
;
2523 /* hotkey_source_mask *must* be zero for
2524 * the first hotkey_mask_get */
2525 if (tp_features
.hotkey_mask
) {
2526 res
= hotkey_mask_get();
2530 hotkey_orig_mask
= hotkey_mask
;
2531 res
= add_many_to_attr_set(
2532 hotkey_dev_attributes
,
2533 hotkey_mask_attributes
,
2534 ARRAY_SIZE(hotkey_mask_attributes
));
2539 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2540 if (tp_features
.hotkey_mask
) {
2541 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2544 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2547 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2548 "hotkey source mask 0x%08x, polling freq %d\n",
2549 hotkey_source_mask
, hotkey_poll_freq
);
2552 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2554 tp_features
.hotkey_wlsw
= 1;
2556 "radio switch emulation enabled\n");
2559 /* Not all thinkpads have a hardware radio switch */
2560 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2561 tp_features
.hotkey_wlsw
= 1;
2563 "radio switch found; radios are %s\n",
2564 enabled(status
, 0));
2566 if (tp_features
.hotkey_wlsw
)
2567 res
= add_to_attr_set(hotkey_dev_attributes
,
2568 &dev_attr_hotkey_radio_sw
.attr
);
2570 /* For X41t, X60t, X61t Tablets... */
2571 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2572 tp_features
.hotkey_tablet
= 1;
2574 "possible tablet mode switch found; "
2575 "ThinkPad in %s mode\n",
2576 (status
& TP_HOTKEY_TABLET_MASK
)?
2577 "tablet" : "laptop");
2578 res
= add_to_attr_set(hotkey_dev_attributes
,
2579 &dev_attr_hotkey_tablet_mode
.attr
);
2583 res
= register_attr_set_with_sysfs(
2584 hotkey_dev_attributes
,
2585 &tpacpi_pdev
->dev
.kobj
);
2589 /* Set up key map */
2591 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2593 if (!hotkey_keycode_map
) {
2595 "failed to allocate memory for key map\n");
2600 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2601 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2602 "using Lenovo default hot key map\n");
2603 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2604 TPACPI_HOTKEY_MAP_SIZE
);
2606 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2607 "using IBM default hot key map\n");
2608 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2609 TPACPI_HOTKEY_MAP_SIZE
);
2612 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2613 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2614 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2615 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2616 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2617 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2618 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2619 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2620 set_bit(hotkey_keycode_map
[i
],
2621 tpacpi_inputdev
->keybit
);
2623 if (i
< sizeof(hotkey_reserved_mask
)*8)
2624 hotkey_reserved_mask
|= 1 << i
;
2628 if (tp_features
.hotkey_wlsw
) {
2629 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2630 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
2632 if (tp_features
.hotkey_tablet
) {
2633 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2634 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2637 /* Do not issue duplicate brightness change events to
2639 if (!tp_features
.bright_acpimode
)
2640 /* update bright_acpimode... */
2641 tpacpi_check_std_acpi_brightness_support();
2643 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
2645 "This ThinkPad has standard ACPI backlight "
2646 "brightness control, supported by the ACPI "
2648 printk(TPACPI_NOTICE
2649 "Disabling thinkpad-acpi brightness events "
2652 /* The hotkey_reserved_mask change below is not
2653 * necessary while the keys are at KEY_RESERVED in the
2654 * default map, but better safe than sorry, leave it
2655 * here as a marker of what we have to do, especially
2656 * when we finally become able to set this at runtime
2657 * on response to X.org requests */
2658 hotkey_reserved_mask
|=
2659 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
2660 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
2663 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2664 "enabling firmware HKEY event interface...\n");
2665 res
= hotkey_status_set(true);
2670 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2671 & ~hotkey_reserved_mask
)
2672 | hotkey_orig_mask
);
2673 if (res
< 0 && res
!= -ENXIO
) {
2678 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2679 "legacy ibm/hotkey event reporting over procfs %s\n",
2680 (hotkey_report_mode
< 2) ?
2681 "enabled" : "disabled");
2683 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2684 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2686 hotkey_poll_setup_safe(1);
2687 tpacpi_send_radiosw_update();
2688 tpacpi_input_send_tabletsw();
2693 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2694 hotkey_dev_attributes
= NULL
;
2696 return (res
< 0)? res
: 1;
2699 static bool hotkey_notify_hotkey(const u32 hkey
,
2701 bool *ignore_acpi_ev
)
2703 /* 0x1000-0x1FFF: key presses */
2704 unsigned int scancode
= hkey
& 0xfff;
2705 *send_acpi_ev
= true;
2706 *ignore_acpi_ev
= false;
2708 if (scancode
> 0 && scancode
< 0x21) {
2710 if (!(hotkey_source_mask
& (1 << scancode
))) {
2711 tpacpi_input_send_key(scancode
);
2712 *send_acpi_ev
= false;
2714 *ignore_acpi_ev
= true;
2721 static bool hotkey_notify_wakeup(const u32 hkey
,
2723 bool *ignore_acpi_ev
)
2725 /* 0x2000-0x2FFF: Wakeup reason */
2726 *send_acpi_ev
= true;
2727 *ignore_acpi_ev
= false;
2730 case 0x2304: /* suspend, undock */
2731 case 0x2404: /* hibernation, undock */
2732 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2733 *ignore_acpi_ev
= true;
2736 case 0x2305: /* suspend, bay eject */
2737 case 0x2405: /* hibernation, bay eject */
2738 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2739 *ignore_acpi_ev
= true;
2742 case 0x2313: /* Battery on critical low level (S3) */
2743 case 0x2413: /* Battery on critical low level (S4) */
2745 "EMERGENCY WAKEUP: battery almost empty\n");
2746 /* how to auto-heal: */
2747 /* 2313: woke up from S3, go to S4/S5 */
2748 /* 2413: woke up from S4, go to S5 */
2755 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2757 "woke up due to a hot-unplug "
2759 hotkey_wakeup_reason_notify_change();
2764 static bool hotkey_notify_usrevent(const u32 hkey
,
2766 bool *ignore_acpi_ev
)
2768 /* 0x5000-0x5FFF: human interface helpers */
2769 *send_acpi_ev
= true;
2770 *ignore_acpi_ev
= false;
2773 case 0x5010: /* Lenovo new BIOS: brightness changed */
2774 case 0x500b: /* X61t: tablet pen inserted into bay */
2775 case 0x500c: /* X61t: tablet pen removed from bay */
2778 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2779 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2780 tpacpi_input_send_tabletsw();
2781 hotkey_tablet_mode_notify_change();
2782 *send_acpi_ev
= false;
2787 /* LID switch events. Do not propagate */
2788 *ignore_acpi_ev
= true;
2796 static bool hotkey_notify_thermal(const u32 hkey
,
2798 bool *ignore_acpi_ev
)
2800 /* 0x6000-0x6FFF: thermal alarms */
2801 *send_acpi_ev
= true;
2802 *ignore_acpi_ev
= false;
2807 "THERMAL ALARM: battery is too hot!\n");
2808 /* recommended action: warn user through gui */
2812 "THERMAL EMERGENCY: battery is extremely hot!\n");
2813 /* recommended action: immediate sleep/hibernate */
2818 "a sensor reports something is too hot!\n");
2819 /* recommended action: warn user through gui, that */
2820 /* some internal component is too hot */
2824 "THERMAL EMERGENCY: "
2825 "a sensor reports something is extremely hot!\n");
2826 /* recommended action: immediate sleep/hibernate */
2830 "EC reports that Thermal Table has changed\n");
2831 /* recommended action: do nothing, we don't have
2832 * Lenovo ATM information */
2836 "THERMAL ALERT: unknown thermal alarm received\n");
2841 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2845 bool ignore_acpi_ev
;
2848 if (event
!= 0x80) {
2850 "unknown HKEY notification event %d\n", event
);
2851 /* forward it to userspace, maybe it knows how to handle it */
2852 acpi_bus_generate_netlink_event(
2853 ibm
->acpi
->device
->pnp
.device_class
,
2854 dev_name(&ibm
->acpi
->device
->dev
),
2860 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2861 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2870 send_acpi_ev
= true;
2871 ignore_acpi_ev
= false;
2873 switch (hkey
>> 12) {
2875 /* 0x1000-0x1FFF: key presses */
2876 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
2880 /* 0x2000-0x2FFF: Wakeup reason */
2881 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
2885 /* 0x3000-0x3FFF: bay-related wakeups */
2886 if (hkey
== 0x3003) {
2887 hotkey_autosleep_ack
= 1;
2890 hotkey_wakeup_hotunplug_complete_notify_change();
2897 /* 0x4000-0x4FFF: dock-related wakeups */
2898 if (hkey
== 0x4003) {
2899 hotkey_autosleep_ack
= 1;
2902 hotkey_wakeup_hotunplug_complete_notify_change();
2909 /* 0x5000-0x5FFF: human interface helpers */
2910 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
2914 /* 0x6000-0x6FFF: thermal alarms */
2915 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
2919 /* 0x7000-0x7FFF: misc */
2920 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2921 tpacpi_send_radiosw_update();
2926 /* fallthrough to default */
2931 printk(TPACPI_NOTICE
2932 "unhandled HKEY event 0x%04x\n", hkey
);
2933 printk(TPACPI_NOTICE
2934 "please report the conditions when this "
2935 "event happened to %s\n", TPACPI_MAIL
);
2939 if (!ignore_acpi_ev
&&
2940 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2941 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2945 /* netlink events */
2946 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2947 acpi_bus_generate_netlink_event(
2948 ibm
->acpi
->device
->pnp
.device_class
,
2949 dev_name(&ibm
->acpi
->device
->dev
),
2955 static void hotkey_suspend(pm_message_t state
)
2957 /* Do these on suspend, we get the events on early resume! */
2958 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2959 hotkey_autosleep_ack
= 0;
2962 static void hotkey_resume(void)
2964 tpacpi_disable_brightness_delay();
2966 if (hotkey_mask_get())
2968 "error while trying to read hot key mask "
2970 tpacpi_send_radiosw_update();
2971 hotkey_tablet_mode_notify_change();
2972 hotkey_wakeup_reason_notify_change();
2973 hotkey_wakeup_hotunplug_complete_notify_change();
2974 hotkey_poll_setup_safe(0);
2977 /* procfs -------------------------------------------------------------- */
2978 static int hotkey_read(char *p
)
2983 if (!tp_features
.hotkey
) {
2984 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2988 if (mutex_lock_killable(&hotkey_mutex
))
2989 return -ERESTARTSYS
;
2990 res
= hotkey_status_get(&status
);
2992 res
= hotkey_mask_get();
2993 mutex_unlock(&hotkey_mutex
);
2997 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2998 if (tp_features
.hotkey_mask
) {
2999 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
3000 len
+= sprintf(p
+ len
,
3001 "commands:\tenable, disable, reset, <mask>\n");
3003 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
3004 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
3010 static void hotkey_enabledisable_warn(bool enable
)
3012 tpacpi_log_usertask("procfs hotkey enable/disable");
3013 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3015 "hotkey enable/disable functionality has been "
3016 "removed from the driver. Hotkeys are always "
3019 "Please remove the hotkey=enable module "
3020 "parameter, it is deprecated. Hotkeys are always "
3024 static int hotkey_write(char *buf
)
3030 if (!tp_features
.hotkey
)
3033 if (mutex_lock_killable(&hotkey_mutex
))
3034 return -ERESTARTSYS
;
3039 while ((cmd
= next_cmd(&buf
))) {
3040 if (strlencmp(cmd
, "enable") == 0) {
3041 hotkey_enabledisable_warn(1);
3042 } else if (strlencmp(cmd
, "disable") == 0) {
3043 hotkey_enabledisable_warn(0);
3045 } else if (strlencmp(cmd
, "reset") == 0) {
3046 mask
= hotkey_orig_mask
;
3047 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3049 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3058 tpacpi_disclose_usertask("procfs hotkey",
3059 "set mask to 0x%08x\n", mask
);
3061 if (!res
&& mask
!= hotkey_mask
)
3062 res
= hotkey_mask_set(mask
);
3065 mutex_unlock(&hotkey_mutex
);
3069 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3070 {TPACPI_ACPI_HKEY_HID
, 0},
3074 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3075 .hid
= ibm_htk_device_ids
,
3076 .notify
= hotkey_notify
,
3077 .handle
= &hkey_handle
,
3078 .type
= ACPI_DEVICE_NOTIFY
,
3081 static struct ibm_struct hotkey_driver_data
= {
3083 .read
= hotkey_read
,
3084 .write
= hotkey_write
,
3085 .exit
= hotkey_exit
,
3086 .resume
= hotkey_resume
,
3087 .suspend
= hotkey_suspend
,
3088 .acpi
= &ibm_hotkey_acpidriver
,
3091 /*************************************************************************
3092 * Bluetooth subdriver
3096 /* ACPI GBDC/SBDC bits */
3097 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3098 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3099 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3104 /* ACPI \BLTH commands */
3105 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3106 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3107 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3108 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3109 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3112 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3114 static struct rfkill
*tpacpi_bluetooth_rfkill
;
3116 static void bluetooth_suspend(pm_message_t state
)
3118 /* Try to make sure radio will resume powered off */
3119 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3120 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
))
3121 vdbg_printk(TPACPI_DBG_RFKILL
,
3122 "bluetooth power down on resume request failed\n");
3125 static int bluetooth_get_radiosw(void)
3129 if (!tp_features
.bluetooth
)
3132 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
3133 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3134 return RFKILL_STATE_HARD_BLOCKED
;
3136 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3137 if (dbg_bluetoothemul
)
3138 return (tpacpi_bluetooth_emulstate
) ?
3139 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3142 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3145 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3146 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3149 static void bluetooth_update_rfk(void)
3153 if (!tpacpi_bluetooth_rfkill
)
3156 status
= bluetooth_get_radiosw();
3159 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
3161 vdbg_printk(TPACPI_DBG_RFKILL
,
3162 "forced rfkill state to %d\n",
3166 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
3170 if (!tp_features
.bluetooth
)
3173 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3174 * reason to risk weird behaviour. */
3175 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3179 vdbg_printk(TPACPI_DBG_RFKILL
,
3180 "will %s bluetooth\n", radio_on
? "enable" : "disable");
3182 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3183 if (dbg_bluetoothemul
) {
3184 tpacpi_bluetooth_emulstate
= !!radio_on
;
3186 bluetooth_update_rfk();
3191 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3193 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
3196 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3200 bluetooth_update_rfk();
3205 /* sysfs bluetooth enable ---------------------------------------------- */
3206 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3207 struct device_attribute
*attr
,
3212 printk_deprecated_rfkill_attribute("bluetooth_enable");
3214 status
= bluetooth_get_radiosw();
3218 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3219 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3222 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3223 struct device_attribute
*attr
,
3224 const char *buf
, size_t count
)
3229 printk_deprecated_rfkill_attribute("bluetooth_enable");
3231 if (parse_strtoul(buf
, 1, &t
))
3234 tpacpi_disclose_usertask("bluetooth_enable", "set to %ld\n", t
);
3236 res
= bluetooth_set_radiosw(t
, 1);
3238 return (res
) ? res
: count
;
3241 static struct device_attribute dev_attr_bluetooth_enable
=
3242 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3243 bluetooth_enable_show
, bluetooth_enable_store
);
3245 /* --------------------------------------------------------------------- */
3247 static struct attribute
*bluetooth_attributes
[] = {
3248 &dev_attr_bluetooth_enable
.attr
,
3252 static const struct attribute_group bluetooth_attr_group
= {
3253 .attrs
= bluetooth_attributes
,
3256 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
3258 int bts
= bluetooth_get_radiosw();
3267 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
3269 dbg_printk(TPACPI_DBG_RFKILL
,
3270 "request to change radio state to %d\n", state
);
3271 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3274 static void bluetooth_shutdown(void)
3276 /* Order firmware to save current state to NVRAM */
3277 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3278 TP_ACPI_BLTH_SAVE_STATE
))
3279 printk(TPACPI_NOTICE
3280 "failed to save bluetooth state to NVRAM\n");
3282 vdbg_printk(TPACPI_DBG_RFKILL
,
3283 "bluestooth state saved to NVRAM\n");
3286 static void bluetooth_exit(void)
3288 bluetooth_shutdown();
3290 if (tpacpi_bluetooth_rfkill
)
3291 rfkill_unregister(tpacpi_bluetooth_rfkill
);
3293 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3294 &bluetooth_attr_group
);
3297 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3302 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3303 "initializing bluetooth subdriver\n");
3305 TPACPI_ACPIHANDLE_INIT(hkey
);
3307 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3308 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3309 tp_features
.bluetooth
= hkey_handle
&&
3310 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3312 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3313 "bluetooth is %s, status 0x%02x\n",
3314 str_supported(tp_features
.bluetooth
),
3317 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3318 if (dbg_bluetoothemul
) {
3319 tp_features
.bluetooth
= 1;
3321 "bluetooth switch emulation enabled\n");
3324 if (tp_features
.bluetooth
&&
3325 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
3326 /* no bluetooth hardware present in system */
3327 tp_features
.bluetooth
= 0;
3328 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3329 "bluetooth hardware not installed\n");
3332 if (!tp_features
.bluetooth
)
3335 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3336 &bluetooth_attr_group
);
3340 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3341 &tpacpi_bluetooth_rfkill
,
3342 RFKILL_TYPE_BLUETOOTH
,
3343 TPACPI_RFK_BLUETOOTH_SW_NAME
,
3345 tpacpi_bluetooth_rfk_set
,
3346 tpacpi_bluetooth_rfk_get
);
3355 /* procfs -------------------------------------------------------------- */
3356 static int bluetooth_read(char *p
)
3359 int status
= bluetooth_get_radiosw();
3361 if (!tp_features
.bluetooth
)
3362 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3364 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3365 (status
== RFKILL_STATE_UNBLOCKED
) ?
3366 "enabled" : "disabled");
3367 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3373 static int bluetooth_write(char *buf
)
3378 if (!tp_features
.bluetooth
)
3381 while ((cmd
= next_cmd(&buf
))) {
3382 if (strlencmp(cmd
, "enable") == 0) {
3384 } else if (strlencmp(cmd
, "disable") == 0) {
3391 tpacpi_disclose_usertask("procfs bluetooth",
3393 state
? "enable" : "disable");
3394 bluetooth_set_radiosw(state
, 1);
3400 static struct ibm_struct bluetooth_driver_data
= {
3401 .name
= "bluetooth",
3402 .read
= bluetooth_read
,
3403 .write
= bluetooth_write
,
3404 .exit
= bluetooth_exit
,
3405 .suspend
= bluetooth_suspend
,
3406 .shutdown
= bluetooth_shutdown
,
3409 /*************************************************************************
3414 /* ACPI GWAN/SWAN bits */
3415 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3416 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3417 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3421 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
3423 static struct rfkill
*tpacpi_wan_rfkill
;
3425 static void wan_suspend(pm_message_t state
)
3427 /* Try to make sure radio will resume powered off */
3428 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3429 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
))
3430 vdbg_printk(TPACPI_DBG_RFKILL
,
3431 "WWAN power down on resume request failed\n");
3434 static int wan_get_radiosw(void)
3438 if (!tp_features
.wan
)
3441 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3442 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3443 return RFKILL_STATE_HARD_BLOCKED
;
3445 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3447 return (tpacpi_wwan_emulstate
) ?
3448 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3451 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3454 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3455 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3458 static void wan_update_rfk(void)
3462 if (!tpacpi_wan_rfkill
)
3465 status
= wan_get_radiosw();
3468 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3470 vdbg_printk(TPACPI_DBG_RFKILL
,
3471 "forced rfkill state to %d\n",
3475 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3479 if (!tp_features
.wan
)
3482 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3483 * reason to risk weird behaviour. */
3484 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3488 vdbg_printk(TPACPI_DBG_RFKILL
,
3489 "will %s WWAN\n", radio_on
? "enable" : "disable");
3491 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3493 tpacpi_wwan_emulstate
= !!radio_on
;
3500 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3502 status
= TP_ACPI_WANCARD_RADIOSSW
;
3505 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3514 /* sysfs wan enable ---------------------------------------------------- */
3515 static ssize_t
wan_enable_show(struct device
*dev
,
3516 struct device_attribute
*attr
,
3521 printk_deprecated_rfkill_attribute("wwan_enable");
3523 status
= wan_get_radiosw();
3527 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3528 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3531 static ssize_t
wan_enable_store(struct device
*dev
,
3532 struct device_attribute
*attr
,
3533 const char *buf
, size_t count
)
3538 printk_deprecated_rfkill_attribute("wwan_enable");
3540 if (parse_strtoul(buf
, 1, &t
))
3543 tpacpi_disclose_usertask("wwan_enable", "set to %ld\n", t
);
3545 res
= wan_set_radiosw(t
, 1);
3547 return (res
) ? res
: count
;
3550 static struct device_attribute dev_attr_wan_enable
=
3551 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
3552 wan_enable_show
, wan_enable_store
);
3554 /* --------------------------------------------------------------------- */
3556 static struct attribute
*wan_attributes
[] = {
3557 &dev_attr_wan_enable
.attr
,
3561 static const struct attribute_group wan_attr_group
= {
3562 .attrs
= wan_attributes
,
3565 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
3567 int wans
= wan_get_radiosw();
3576 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
3578 dbg_printk(TPACPI_DBG_RFKILL
,
3579 "request to change radio state to %d\n", state
);
3580 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3583 static void wan_shutdown(void)
3585 /* Order firmware to save current state to NVRAM */
3586 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
3587 TP_ACPI_WGSV_SAVE_STATE
))
3588 printk(TPACPI_NOTICE
3589 "failed to save WWAN state to NVRAM\n");
3591 vdbg_printk(TPACPI_DBG_RFKILL
,
3592 "WWAN state saved to NVRAM\n");
3595 static void wan_exit(void)
3599 if (tpacpi_wan_rfkill
)
3600 rfkill_unregister(tpacpi_wan_rfkill
);
3602 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3606 static int __init
wan_init(struct ibm_init_struct
*iibm
)
3611 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3612 "initializing wan subdriver\n");
3614 TPACPI_ACPIHANDLE_INIT(hkey
);
3616 tp_features
.wan
= hkey_handle
&&
3617 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
3619 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3620 "wan is %s, status 0x%02x\n",
3621 str_supported(tp_features
.wan
),
3624 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3626 tp_features
.wan
= 1;
3628 "wwan switch emulation enabled\n");
3631 if (tp_features
.wan
&&
3632 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
3633 /* no wan hardware present in system */
3634 tp_features
.wan
= 0;
3635 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3636 "wan hardware not installed\n");
3639 if (!tp_features
.wan
)
3642 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3647 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
3650 TPACPI_RFK_WWAN_SW_NAME
,
3653 tpacpi_wan_rfk_get
);
3662 /* procfs -------------------------------------------------------------- */
3663 static int wan_read(char *p
)
3666 int status
= wan_get_radiosw();
3668 tpacpi_disclose_usertask("procfs wan", "read");
3670 if (!tp_features
.wan
)
3671 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3673 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3674 (status
== RFKILL_STATE_UNBLOCKED
) ?
3675 "enabled" : "disabled");
3676 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3682 static int wan_write(char *buf
)
3687 if (!tp_features
.wan
)
3690 while ((cmd
= next_cmd(&buf
))) {
3691 if (strlencmp(cmd
, "enable") == 0) {
3693 } else if (strlencmp(cmd
, "disable") == 0) {
3700 tpacpi_disclose_usertask("procfs wan",
3702 state
? "enable" : "disable");
3703 wan_set_radiosw(state
, 1);
3709 static struct ibm_struct wan_driver_data
= {
3714 .suspend
= wan_suspend
,
3715 .shutdown
= wan_shutdown
,
3718 /*************************************************************************
3723 /* ACPI GUWB/SUWB bits */
3724 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
3725 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
3728 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
3730 static struct rfkill
*tpacpi_uwb_rfkill
;
3732 static int uwb_get_radiosw(void)
3736 if (!tp_features
.uwb
)
3739 /* WLSW overrides UWB in firmware/hardware, reflect that */
3740 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3741 return RFKILL_STATE_HARD_BLOCKED
;
3743 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3745 return (tpacpi_uwb_emulstate
) ?
3746 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3749 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
3752 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
3753 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3756 static void uwb_update_rfk(void)
3760 if (!tpacpi_uwb_rfkill
)
3763 status
= uwb_get_radiosw();
3766 rfkill_force_state(tpacpi_uwb_rfkill
, status
);
3768 vdbg_printk(TPACPI_DBG_RFKILL
,
3769 "forced rfkill state to %d\n",
3773 static int uwb_set_radiosw(int radio_on
, int update_rfk
)
3777 if (!tp_features
.uwb
)
3780 /* WLSW overrides UWB in firmware/hardware, but there is no
3781 * reason to risk weird behaviour. */
3782 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3786 vdbg_printk(TPACPI_DBG_RFKILL
,
3787 "will %s UWB\n", radio_on
? "enable" : "disable");
3789 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3791 tpacpi_uwb_emulstate
= !!radio_on
;
3798 status
= (radio_on
) ? TP_ACPI_UWB_RADIOSSW
: 0;
3799 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
3808 /* --------------------------------------------------------------------- */
3810 static int tpacpi_uwb_rfk_get(void *data
, enum rfkill_state
*state
)
3812 int uwbs
= uwb_get_radiosw();
3821 static int tpacpi_uwb_rfk_set(void *data
, enum rfkill_state state
)
3823 dbg_printk(TPACPI_DBG_RFKILL
,
3824 "request to change radio state to %d\n", state
);
3825 return uwb_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3828 static void uwb_exit(void)
3830 if (tpacpi_uwb_rfkill
)
3831 rfkill_unregister(tpacpi_uwb_rfkill
);
3834 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
3839 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3840 "initializing uwb subdriver\n");
3842 TPACPI_ACPIHANDLE_INIT(hkey
);
3844 tp_features
.uwb
= hkey_handle
&&
3845 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
3847 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3848 "uwb is %s, status 0x%02x\n",
3849 str_supported(tp_features
.uwb
),
3852 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3854 tp_features
.uwb
= 1;
3856 "uwb switch emulation enabled\n");
3859 if (tp_features
.uwb
&&
3860 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
3861 /* no uwb hardware present in system */
3862 tp_features
.uwb
= 0;
3863 dbg_printk(TPACPI_DBG_INIT
,
3864 "uwb hardware not installed\n");
3867 if (!tp_features
.uwb
)
3870 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
3873 TPACPI_RFK_UWB_SW_NAME
,
3876 tpacpi_uwb_rfk_get
);
3881 static struct ibm_struct uwb_driver_data
= {
3884 .flags
.experimental
= 1,
3887 /*************************************************************************
3891 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
3893 enum video_access_mode
{
3894 TPACPI_VIDEO_NONE
= 0,
3895 TPACPI_VIDEO_570
, /* 570 */
3896 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
3897 TPACPI_VIDEO_NEW
, /* all others */
3900 enum { /* video status flags, based on VIDEO_570 */
3901 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
3902 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
3903 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
3906 enum { /* TPACPI_VIDEO_570 constants */
3907 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
3908 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
3909 * video_status_flags */
3910 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
3911 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
3914 static enum video_access_mode video_supported
;
3915 static int video_orig_autosw
;
3917 static int video_autosw_get(void);
3918 static int video_autosw_set(int enable
);
3920 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
3922 static int __init
video_init(struct ibm_init_struct
*iibm
)
3926 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
3928 TPACPI_ACPIHANDLE_INIT(vid
);
3929 TPACPI_ACPIHANDLE_INIT(vid2
);
3931 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
3932 /* G41, assume IVGA doesn't change */
3933 vid_handle
= vid2_handle
;
3936 /* video switching not supported on R30, R31 */
3937 video_supported
= TPACPI_VIDEO_NONE
;
3938 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
3940 video_supported
= TPACPI_VIDEO_570
;
3941 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
3942 /* 600e/x, 770e, 770x */
3943 video_supported
= TPACPI_VIDEO_770
;
3946 video_supported
= TPACPI_VIDEO_NEW
;
3948 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
3949 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
3952 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
3955 static void video_exit(void)
3957 dbg_printk(TPACPI_DBG_EXIT
,
3958 "restoring original video autoswitch mode\n");
3959 if (video_autosw_set(video_orig_autosw
))
3960 printk(TPACPI_ERR
"error while trying to restore original "
3961 "video autoswitch mode\n");
3964 static int video_outputsw_get(void)
3969 switch (video_supported
) {
3970 case TPACPI_VIDEO_570
:
3971 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
3972 TP_ACPI_VIDEO_570_PHSCMD
))
3974 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
3976 case TPACPI_VIDEO_770
:
3977 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3980 status
|= TP_ACPI_VIDEO_S_LCD
;
3981 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3984 status
|= TP_ACPI_VIDEO_S_CRT
;
3986 case TPACPI_VIDEO_NEW
:
3987 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
3988 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3991 status
|= TP_ACPI_VIDEO_S_CRT
;
3993 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
3994 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3997 status
|= TP_ACPI_VIDEO_S_LCD
;
3998 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4001 status
|= TP_ACPI_VIDEO_S_DVI
;
4010 static int video_outputsw_set(int status
)
4015 switch (video_supported
) {
4016 case TPACPI_VIDEO_570
:
4017 res
= acpi_evalf(NULL
, NULL
,
4018 "\\_SB.PHS2", "vdd",
4019 TP_ACPI_VIDEO_570_PHS2CMD
,
4020 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4022 case TPACPI_VIDEO_770
:
4023 autosw
= video_autosw_get();
4027 res
= video_autosw_set(1);
4030 res
= acpi_evalf(vid_handle
, NULL
,
4031 "ASWT", "vdd", status
* 0x100, 0);
4032 if (!autosw
&& video_autosw_set(autosw
)) {
4034 "video auto-switch left enabled due to error\n");
4038 case TPACPI_VIDEO_NEW
:
4039 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4040 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4046 return (res
)? 0 : -EIO
;
4049 static int video_autosw_get(void)
4053 switch (video_supported
) {
4054 case TPACPI_VIDEO_570
:
4055 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4058 case TPACPI_VIDEO_770
:
4059 case TPACPI_VIDEO_NEW
:
4060 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4070 static int video_autosw_set(int enable
)
4072 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4077 static int video_outputsw_cycle(void)
4079 int autosw
= video_autosw_get();
4085 switch (video_supported
) {
4086 case TPACPI_VIDEO_570
:
4087 res
= video_autosw_set(1);
4090 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4092 case TPACPI_VIDEO_770
:
4093 case TPACPI_VIDEO_NEW
:
4094 res
= video_autosw_set(1);
4097 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4102 if (!autosw
&& video_autosw_set(autosw
)) {
4104 "video auto-switch left enabled due to error\n");
4108 return (res
)? 0 : -EIO
;
4111 static int video_expand_toggle(void)
4113 switch (video_supported
) {
4114 case TPACPI_VIDEO_570
:
4115 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4117 case TPACPI_VIDEO_770
:
4118 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4120 case TPACPI_VIDEO_NEW
:
4121 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4129 static int video_read(char *p
)
4134 if (video_supported
== TPACPI_VIDEO_NONE
) {
4135 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4139 status
= video_outputsw_get();
4143 autosw
= video_autosw_get();
4147 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4148 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
4149 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
4150 if (video_supported
== TPACPI_VIDEO_NEW
)
4151 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
4152 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
4153 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
4154 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
4155 if (video_supported
== TPACPI_VIDEO_NEW
)
4156 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
4157 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
4158 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
4163 static int video_write(char *buf
)
4166 int enable
, disable
, status
;
4169 if (video_supported
== TPACPI_VIDEO_NONE
)
4175 while ((cmd
= next_cmd(&buf
))) {
4176 if (strlencmp(cmd
, "lcd_enable") == 0) {
4177 enable
|= TP_ACPI_VIDEO_S_LCD
;
4178 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4179 disable
|= TP_ACPI_VIDEO_S_LCD
;
4180 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4181 enable
|= TP_ACPI_VIDEO_S_CRT
;
4182 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4183 disable
|= TP_ACPI_VIDEO_S_CRT
;
4184 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4185 strlencmp(cmd
, "dvi_enable") == 0) {
4186 enable
|= TP_ACPI_VIDEO_S_DVI
;
4187 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4188 strlencmp(cmd
, "dvi_disable") == 0) {
4189 disable
|= TP_ACPI_VIDEO_S_DVI
;
4190 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4191 res
= video_autosw_set(1);
4194 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4195 res
= video_autosw_set(0);
4198 } else if (strlencmp(cmd
, "video_switch") == 0) {
4199 res
= video_outputsw_cycle();
4202 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4203 res
= video_expand_toggle();
4210 if (enable
|| disable
) {
4211 status
= video_outputsw_get();
4214 res
= video_outputsw_set((status
& ~disable
) | enable
);
4222 static struct ibm_struct video_driver_data
= {
4225 .write
= video_write
,
4229 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4231 /*************************************************************************
4232 * Light (thinklight) subdriver
4235 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4236 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4238 static int light_get_status(void)
4242 if (tp_features
.light_status
) {
4243 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4251 static int light_set_status(int status
)
4255 if (tp_features
.light
) {
4257 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4259 TP_CMOS_THINKLIGHT_ON
:
4260 TP_CMOS_THINKLIGHT_OFF
);
4262 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4265 return (rc
)? 0 : -EIO
;
4271 static void light_set_status_worker(struct work_struct
*work
)
4273 struct tpacpi_led_classdev
*data
=
4274 container_of(work
, struct tpacpi_led_classdev
, work
);
4276 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4277 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4280 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4281 enum led_brightness brightness
)
4283 struct tpacpi_led_classdev
*data
=
4284 container_of(led_cdev
,
4285 struct tpacpi_led_classdev
,
4287 data
->new_state
= (brightness
!= LED_OFF
) ?
4288 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4289 queue_work(tpacpi_wq
, &data
->work
);
4292 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4294 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4297 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4299 .name
= "tpacpi::thinklight",
4300 .brightness_set
= &light_sysfs_set
,
4301 .brightness_get
= &light_sysfs_get
,
4305 static int __init
light_init(struct ibm_init_struct
*iibm
)
4309 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4311 TPACPI_ACPIHANDLE_INIT(ledb
);
4312 TPACPI_ACPIHANDLE_INIT(lght
);
4313 TPACPI_ACPIHANDLE_INIT(cmos
);
4314 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4316 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4317 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4319 if (tp_features
.light
)
4320 /* light status not supported on
4321 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4322 tp_features
.light_status
=
4323 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4325 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4326 str_supported(tp_features
.light
),
4327 str_supported(tp_features
.light_status
));
4329 if (!tp_features
.light
)
4332 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4333 &tpacpi_led_thinklight
.led_classdev
);
4336 tp_features
.light
= 0;
4337 tp_features
.light_status
= 0;
4345 static void light_exit(void)
4347 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4348 if (work_pending(&tpacpi_led_thinklight
.work
))
4349 flush_workqueue(tpacpi_wq
);
4352 static int light_read(char *p
)
4357 if (!tp_features
.light
) {
4358 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4359 } else if (!tp_features
.light_status
) {
4360 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
4361 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4363 status
= light_get_status();
4366 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
4367 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4373 static int light_write(char *buf
)
4378 if (!tp_features
.light
)
4381 while ((cmd
= next_cmd(&buf
))) {
4382 if (strlencmp(cmd
, "on") == 0) {
4384 } else if (strlencmp(cmd
, "off") == 0) {
4390 return light_set_status(newstatus
);
4393 static struct ibm_struct light_driver_data
= {
4396 .write
= light_write
,
4400 /*************************************************************************
4404 /* sysfs cmos_command -------------------------------------------------- */
4405 static ssize_t
cmos_command_store(struct device
*dev
,
4406 struct device_attribute
*attr
,
4407 const char *buf
, size_t count
)
4409 unsigned long cmos_cmd
;
4412 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4415 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4416 return (res
)? res
: count
;
4419 static struct device_attribute dev_attr_cmos_command
=
4420 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4422 /* --------------------------------------------------------------------- */
4424 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4428 vdbg_printk(TPACPI_DBG_INIT
,
4429 "initializing cmos commands subdriver\n");
4431 TPACPI_ACPIHANDLE_INIT(cmos
);
4433 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4434 str_supported(cmos_handle
!= NULL
));
4436 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4440 return (cmos_handle
)? 0 : 1;
4443 static void cmos_exit(void)
4445 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4448 static int cmos_read(char *p
)
4452 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4453 R30, R31, T20-22, X20-21 */
4455 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4457 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4458 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4464 static int cmos_write(char *buf
)
4469 while ((cmd
= next_cmd(&buf
))) {
4470 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4471 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4476 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4484 static struct ibm_struct cmos_driver_data
= {
4487 .write
= cmos_write
,
4491 /*************************************************************************
4495 enum led_access_mode
{
4496 TPACPI_LED_NONE
= 0,
4497 TPACPI_LED_570
, /* 570 */
4498 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4499 TPACPI_LED_NEW
, /* all others */
4502 enum { /* For TPACPI_LED_OLD */
4503 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4504 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4505 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4508 static enum led_access_mode led_supported
;
4510 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4511 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4512 /* T20-22, X20-21 */
4513 "LED", /* all others */
4516 #define TPACPI_LED_NUMLEDS 16
4517 static struct tpacpi_led_classdev
*tpacpi_leds
;
4518 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4519 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4520 /* there's a limit of 19 chars + NULL before 2.6.26 */
4522 "tpacpi:orange:batt",
4523 "tpacpi:green:batt",
4524 "tpacpi::dock_active",
4525 "tpacpi::bay_active",
4526 "tpacpi::dock_batt",
4527 "tpacpi::unknown_led",
4529 "tpacpi::dock_status1",
4530 "tpacpi::dock_status2",
4531 "tpacpi::unknown_led2",
4532 "tpacpi::unknown_led3",
4533 "tpacpi::thinkvantage",
4535 #define TPACPI_SAFE_LEDS 0x1081U
4537 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
4539 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
4542 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
4546 static int led_get_status(const unsigned int led
)
4549 enum led_status_t led_s
;
4551 switch (led_supported
) {
4552 case TPACPI_LED_570
:
4553 if (!acpi_evalf(ec_handle
,
4554 &status
, "GLED", "dd", 1 << led
))
4556 led_s
= (status
== 0)?
4561 tpacpi_led_state_cache
[led
] = led_s
;
4570 static int led_set_status(const unsigned int led
,
4571 const enum led_status_t ledstatus
)
4573 /* off, on, blink. Index is led_status_t */
4574 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
4575 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
4579 switch (led_supported
) {
4580 case TPACPI_LED_570
:
4582 if (unlikely(led
> 7))
4584 if (unlikely(tpacpi_is_led_restricted(led
)))
4586 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4587 (1 << led
), led_sled_arg1
[ledstatus
]))
4590 case TPACPI_LED_OLD
:
4591 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4592 if (unlikely(led
> 7))
4594 if (unlikely(tpacpi_is_led_restricted(led
)))
4596 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
4598 rc
= ec_write(TPACPI_LED_EC_HLBL
,
4599 (ledstatus
== TPACPI_LED_BLINK
) << led
);
4601 rc
= ec_write(TPACPI_LED_EC_HLCL
,
4602 (ledstatus
!= TPACPI_LED_OFF
) << led
);
4604 case TPACPI_LED_NEW
:
4606 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
4608 if (unlikely(tpacpi_is_led_restricted(led
)))
4610 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4611 led
, led_led_arg1
[ledstatus
]))
4619 tpacpi_led_state_cache
[led
] = ledstatus
;
4624 static void led_set_status_worker(struct work_struct
*work
)
4626 struct tpacpi_led_classdev
*data
=
4627 container_of(work
, struct tpacpi_led_classdev
, work
);
4629 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4630 led_set_status(data
->led
, data
->new_state
);
4633 static void led_sysfs_set(struct led_classdev
*led_cdev
,
4634 enum led_brightness brightness
)
4636 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4637 struct tpacpi_led_classdev
, led_classdev
);
4639 if (brightness
== LED_OFF
)
4640 data
->new_state
= TPACPI_LED_OFF
;
4641 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
4642 data
->new_state
= TPACPI_LED_ON
;
4644 data
->new_state
= TPACPI_LED_BLINK
;
4646 queue_work(tpacpi_wq
, &data
->work
);
4649 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
4650 unsigned long *delay_on
, unsigned long *delay_off
)
4652 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4653 struct tpacpi_led_classdev
, led_classdev
);
4655 /* Can we choose the flash rate? */
4656 if (*delay_on
== 0 && *delay_off
== 0) {
4657 /* yes. set them to the hardware blink rate (1 Hz) */
4658 *delay_on
= 500; /* ms */
4659 *delay_off
= 500; /* ms */
4660 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
4663 data
->new_state
= TPACPI_LED_BLINK
;
4664 queue_work(tpacpi_wq
, &data
->work
);
4669 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
4673 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4674 struct tpacpi_led_classdev
, led_classdev
);
4676 rc
= led_get_status(data
->led
);
4678 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
4679 rc
= LED_OFF
; /* no error handling in led class :( */
4686 static void led_exit(void)
4690 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4691 if (tpacpi_leds
[i
].led_classdev
.name
)
4692 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
4698 static int __init
tpacpi_init_led(unsigned int led
)
4702 tpacpi_leds
[led
].led
= led
;
4704 /* LEDs with no name don't get registered */
4705 if (!tpacpi_led_names
[led
])
4708 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
4709 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
4710 if (led_supported
== TPACPI_LED_570
)
4711 tpacpi_leds
[led
].led_classdev
.brightness_get
=
4714 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
4716 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
4718 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4719 &tpacpi_leds
[led
].led_classdev
);
4721 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
4726 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
4727 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
4728 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
4729 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
4731 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
4732 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
4733 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
4734 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
4735 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
4736 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
4737 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
4738 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
4740 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
4741 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
4742 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
4743 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
4744 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
4746 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
4747 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
4748 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
4749 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
4751 /* (1) - may have excess leds enabled on MSB */
4753 /* Defaults (order matters, keep last, don't reorder!) */
4755 .vendor
= PCI_VENDOR_ID_LENOVO
,
4756 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
4759 { /* IBM ThinkPads with no EC version string */
4760 .vendor
= PCI_VENDOR_ID_IBM
,
4761 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
4764 { /* IBM ThinkPads with EC version string */
4765 .vendor
= PCI_VENDOR_ID_IBM
,
4766 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
4771 #undef TPACPI_LEDQ_IBM
4772 #undef TPACPI_LEDQ_LNV
4774 static int __init
led_init(struct ibm_init_struct
*iibm
)
4778 unsigned long useful_leds
;
4780 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
4782 TPACPI_ACPIHANDLE_INIT(led
);
4785 /* led not supported on R30, R31 */
4786 led_supported
= TPACPI_LED_NONE
;
4787 else if (strlencmp(led_path
, "SLED") == 0)
4789 led_supported
= TPACPI_LED_570
;
4790 else if (strlencmp(led_path
, "SYSL") == 0)
4791 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4792 led_supported
= TPACPI_LED_OLD
;
4795 led_supported
= TPACPI_LED_NEW
;
4797 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
4798 str_supported(led_supported
), led_supported
);
4800 if (led_supported
== TPACPI_LED_NONE
)
4803 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
4806 printk(TPACPI_ERR
"Out of memory for LED data\n");
4810 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
4811 ARRAY_SIZE(led_useful_qtable
));
4813 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4814 if (!tpacpi_is_led_restricted(i
) &&
4815 test_bit(i
, &useful_leds
)) {
4816 rc
= tpacpi_init_led(i
);
4824 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
4825 printk(TPACPI_NOTICE
4826 "warning: userspace override of important "
4827 "firmware LEDs is enabled\n");
4832 #define str_led_status(s) \
4833 ((s) == TPACPI_LED_OFF ? "off" : \
4834 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
4836 static int led_read(char *p
)
4840 if (!led_supported
) {
4841 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4844 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4846 if (led_supported
== TPACPI_LED_570
) {
4849 for (i
= 0; i
< 8; i
++) {
4850 status
= led_get_status(i
);
4853 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
4854 i
, str_led_status(status
));
4858 len
+= sprintf(p
+ len
, "commands:\t"
4859 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
4864 static int led_write(char *buf
)
4868 enum led_status_t s
;
4873 while ((cmd
= next_cmd(&buf
))) {
4874 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
4877 if (strstr(cmd
, "off")) {
4879 } else if (strstr(cmd
, "on")) {
4881 } else if (strstr(cmd
, "blink")) {
4882 s
= TPACPI_LED_BLINK
;
4887 rc
= led_set_status(led
, s
);
4895 static struct ibm_struct led_driver_data
= {
4902 /*************************************************************************
4906 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
4908 #define TPACPI_BEEP_Q1 0x0001
4910 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
4911 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
4912 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
4915 static int __init
beep_init(struct ibm_init_struct
*iibm
)
4917 unsigned long quirks
;
4919 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
4921 TPACPI_ACPIHANDLE_INIT(beep
);
4923 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
4924 str_supported(beep_handle
!= NULL
));
4926 quirks
= tpacpi_check_quirks(beep_quirk_table
,
4927 ARRAY_SIZE(beep_quirk_table
));
4929 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
4931 return (beep_handle
)? 0 : 1;
4934 static int beep_read(char *p
)
4939 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4941 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4942 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
4948 static int beep_write(char *buf
)
4956 while ((cmd
= next_cmd(&buf
))) {
4957 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
4958 beep_cmd
>= 0 && beep_cmd
<= 17) {
4962 if (tp_features
.beep_needs_two_args
) {
4963 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
4967 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
4976 static struct ibm_struct beep_driver_data
= {
4979 .write
= beep_write
,
4982 /*************************************************************************
4986 enum thermal_access_mode
{
4987 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
4988 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
4989 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
4990 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
4991 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
4994 enum { /* TPACPI_THERMAL_TPEC_* */
4995 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
4996 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
4997 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5000 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5001 struct ibm_thermal_sensors_struct
{
5002 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5005 static enum thermal_access_mode thermal_read_mode
;
5007 /* idx is zero-based */
5008 static int thermal_get_sensor(int idx
, s32
*value
)
5014 t
= TP_EC_THERMAL_TMP0
;
5016 switch (thermal_read_mode
) {
5017 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5018 case TPACPI_THERMAL_TPEC_16
:
5019 if (idx
>= 8 && idx
<= 15) {
5020 t
= TP_EC_THERMAL_TMP8
;
5025 case TPACPI_THERMAL_TPEC_8
:
5027 if (!acpi_ec_read(t
+ idx
, &tmp
))
5029 *value
= tmp
* 1000;
5034 case TPACPI_THERMAL_ACPI_UPDT
:
5036 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5037 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5039 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5041 *value
= (t
- 2732) * 100;
5046 case TPACPI_THERMAL_ACPI_TMP07
:
5048 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5049 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5051 if (t
> 127 || t
< -127)
5052 t
= TP_EC_THERMAL_TMP_NA
;
5058 case TPACPI_THERMAL_NONE
:
5066 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5077 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5080 for (i
= 0 ; i
< n
; i
++) {
5081 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5089 /* sysfs temp##_input -------------------------------------------------- */
5091 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5092 struct device_attribute
*attr
,
5095 struct sensor_device_attribute
*sensor_attr
=
5096 to_sensor_dev_attr(attr
);
5097 int idx
= sensor_attr
->index
;
5101 res
= thermal_get_sensor(idx
, &value
);
5104 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
5107 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5110 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5111 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5112 thermal_temp_input_show, NULL, _idxB)
5114 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5115 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5116 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5117 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5118 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5119 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5120 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5121 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5122 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5123 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5124 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5125 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5126 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5127 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5128 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5129 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5130 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5133 #define THERMAL_ATTRS(X) \
5134 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5136 static struct attribute
*thermal_temp_input_attr
[] = {
5156 static const struct attribute_group thermal_temp_input16_group
= {
5157 .attrs
= thermal_temp_input_attr
5160 static const struct attribute_group thermal_temp_input8_group
= {
5161 .attrs
= &thermal_temp_input_attr
[8]
5164 #undef THERMAL_SENSOR_ATTR_TEMP
5165 #undef THERMAL_ATTRS
5167 /* --------------------------------------------------------------------- */
5169 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5176 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5178 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5180 if (thinkpad_id
.ec_model
) {
5182 * Direct EC access mode: sensors at registers
5183 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5184 * non-implemented, thermal sensors return 0x80 when
5189 for (i
= 0; i
< 8; i
++) {
5190 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5196 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5204 /* This is sheer paranoia, but we handle it anyway */
5207 "ThinkPad ACPI EC access misbehaving, "
5208 "falling back to ACPI TMPx access "
5210 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5213 "ThinkPad ACPI EC access misbehaving, "
5214 "disabling thermal sensors access\n");
5215 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5220 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5222 } else if (acpi_tmp7
) {
5223 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5224 /* 600e/x, 770e, 770x */
5225 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5227 /* Standard ACPI TMPx access, max 8 sensors */
5228 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5231 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5232 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5235 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5236 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5239 switch (thermal_read_mode
) {
5240 case TPACPI_THERMAL_TPEC_16
:
5241 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5242 &thermal_temp_input16_group
);
5246 case TPACPI_THERMAL_TPEC_8
:
5247 case TPACPI_THERMAL_ACPI_TMP07
:
5248 case TPACPI_THERMAL_ACPI_UPDT
:
5249 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5250 &thermal_temp_input8_group
);
5254 case TPACPI_THERMAL_NONE
:
5262 static void thermal_exit(void)
5264 switch (thermal_read_mode
) {
5265 case TPACPI_THERMAL_TPEC_16
:
5266 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5267 &thermal_temp_input16_group
);
5269 case TPACPI_THERMAL_TPEC_8
:
5270 case TPACPI_THERMAL_ACPI_TMP07
:
5271 case TPACPI_THERMAL_ACPI_UPDT
:
5272 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5273 &thermal_temp_input16_group
);
5275 case TPACPI_THERMAL_NONE
:
5281 static int thermal_read(char *p
)
5285 struct ibm_thermal_sensors_struct t
;
5287 n
= thermal_get_sensors(&t
);
5288 if (unlikely(n
< 0))
5291 len
+= sprintf(p
+ len
, "temperatures:\t");
5294 for (i
= 0; i
< (n
- 1); i
++)
5295 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
5296 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
5298 len
+= sprintf(p
+ len
, "not supported\n");
5303 static struct ibm_struct thermal_driver_data
= {
5305 .read
= thermal_read
,
5306 .exit
= thermal_exit
,
5309 /*************************************************************************
5313 static u8 ecdump_regs
[256];
5315 static int ecdump_read(char *p
)
5321 len
+= sprintf(p
+ len
, "EC "
5322 " +00 +01 +02 +03 +04 +05 +06 +07"
5323 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5324 for (i
= 0; i
< 256; i
+= 16) {
5325 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
5326 for (j
= 0; j
< 16; j
++) {
5327 if (!acpi_ec_read(i
+ j
, &v
))
5329 if (v
!= ecdump_regs
[i
+ j
])
5330 len
+= sprintf(p
+ len
, " *%02x", v
);
5332 len
+= sprintf(p
+ len
, " %02x", v
);
5333 ecdump_regs
[i
+ j
] = v
;
5335 len
+= sprintf(p
+ len
, "\n");
5340 /* These are way too dangerous to advertise openly... */
5342 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
5343 " (<offset> is 00-ff, <value> is 00-ff)\n");
5344 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
5345 " (<offset> is 00-ff, <value> is 0-255)\n");
5350 static int ecdump_write(char *buf
)
5355 while ((cmd
= next_cmd(&buf
))) {
5356 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5358 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5362 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5363 if (!acpi_ec_write(i
, v
))
5372 static struct ibm_struct ecdump_driver_data
= {
5374 .read
= ecdump_read
,
5375 .write
= ecdump_write
,
5376 .flags
.experimental
= 1,
5379 /*************************************************************************
5380 * Backlight/brightness subdriver
5383 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5386 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5387 * CMOS NVRAM byte 0x5E, bits 0-3.
5389 * EC HBRV (0x31) has the following layout
5390 * Bit 7: unknown function
5391 * Bit 6: unknown function
5392 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5393 * Bit 4: must be set to zero to avoid problems
5394 * Bit 3-0: backlight brightness level
5396 * brightness_get_raw returns status data in the HBRV layout
5398 * WARNING: The X61 has been verified to use HBRV for something else, so
5399 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5400 * testing on the very early *60 Lenovo models...
5404 TP_EC_BACKLIGHT
= 0x31,
5406 /* TP_EC_BACKLIGHT bitmasks */
5407 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5408 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5409 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5412 enum tpacpi_brightness_access_mode
{
5413 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5414 TPACPI_BRGHT_MODE_EC
, /* EC control */
5415 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5416 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5417 TPACPI_BRGHT_MODE_MAX
5420 static struct backlight_device
*ibm_backlight_device
;
5422 static enum tpacpi_brightness_access_mode brightness_mode
=
5423 TPACPI_BRGHT_MODE_MAX
;
5425 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5427 static struct mutex brightness_mutex
;
5429 /* NVRAM brightness access,
5430 * call with brightness_mutex held! */
5431 static unsigned int tpacpi_brightness_nvram_get(void)
5435 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5436 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5437 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5438 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5443 static void tpacpi_brightness_checkpoint_nvram(void)
5448 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5451 vdbg_printk(TPACPI_DBG_BRGHT
,
5452 "trying to checkpoint backlight level to NVRAM...\n");
5454 if (mutex_lock_killable(&brightness_mutex
) < 0)
5457 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5459 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5460 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5462 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5463 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5464 /* NVRAM needs update */
5465 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5466 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5468 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5469 dbg_printk(TPACPI_DBG_BRGHT
,
5470 "updated NVRAM backlight level to %u (0x%02x)\n",
5471 (unsigned int) lec
, (unsigned int) b_nvram
);
5473 vdbg_printk(TPACPI_DBG_BRGHT
,
5474 "NVRAM backlight level already is %u (0x%02x)\n",
5475 (unsigned int) lec
, (unsigned int) b_nvram
);
5478 mutex_unlock(&brightness_mutex
);
5482 /* call with brightness_mutex held! */
5483 static int tpacpi_brightness_get_raw(int *status
)
5487 switch (brightness_mode
) {
5488 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5489 *status
= tpacpi_brightness_nvram_get();
5491 case TPACPI_BRGHT_MODE_EC
:
5492 case TPACPI_BRGHT_MODE_ECNVRAM
:
5493 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5502 /* call with brightness_mutex held! */
5503 /* do NOT call with illegal backlight level value */
5504 static int tpacpi_brightness_set_ec(unsigned int value
)
5508 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5511 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
5512 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
5513 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
5519 /* call with brightness_mutex held! */
5520 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
5523 unsigned int current_value
, i
;
5525 current_value
= tpacpi_brightness_nvram_get();
5527 if (value
== current_value
)
5530 cmos_cmd
= (value
> current_value
) ?
5531 TP_CMOS_BRIGHTNESS_UP
:
5532 TP_CMOS_BRIGHTNESS_DOWN
;
5533 inc
= (value
> current_value
) ? 1 : -1;
5535 for (i
= current_value
; i
!= value
; i
+= inc
)
5536 if (issue_thinkpad_cmos_command(cmos_cmd
))
5542 /* May return EINTR which can always be mapped to ERESTARTSYS */
5543 static int brightness_set(unsigned int value
)
5547 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
5551 vdbg_printk(TPACPI_DBG_BRGHT
,
5552 "set backlight level to %d\n", value
);
5554 res
= mutex_lock_killable(&brightness_mutex
);
5558 switch (brightness_mode
) {
5559 case TPACPI_BRGHT_MODE_EC
:
5560 case TPACPI_BRGHT_MODE_ECNVRAM
:
5561 res
= tpacpi_brightness_set_ec(value
);
5563 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5564 res
= tpacpi_brightness_set_ucmsstep(value
);
5570 mutex_unlock(&brightness_mutex
);
5574 /* sysfs backlight class ----------------------------------------------- */
5576 static int brightness_update_status(struct backlight_device
*bd
)
5578 unsigned int level
=
5579 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
5580 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
5581 bd
->props
.brightness
: 0;
5583 dbg_printk(TPACPI_DBG_BRGHT
,
5584 "backlight: attempt to set level to %d\n",
5587 /* it is the backlight class's job (caller) to handle
5588 * EINTR and other errors properly */
5589 return brightness_set(level
);
5592 static int brightness_get(struct backlight_device
*bd
)
5596 res
= mutex_lock_killable(&brightness_mutex
);
5600 res
= tpacpi_brightness_get_raw(&status
);
5602 mutex_unlock(&brightness_mutex
);
5607 return status
& TP_EC_BACKLIGHT_LVLMSK
;
5610 static struct backlight_ops ibm_backlight_data
= {
5611 .get_brightness
= brightness_get
,
5612 .update_status
= brightness_update_status
,
5615 /* --------------------------------------------------------------------- */
5618 * These are only useful for models that have only one possibility
5619 * of GPU. If the BIOS model handles both ATI and Intel, don't use
5622 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
5623 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
5624 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
5626 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
5627 /* Models with ATI GPUs known to require ECNVRAM mode */
5628 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
5630 /* Models with ATI GPUs (waiting confirmation) */
5631 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
5632 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
5633 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
5634 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
5636 /* Models with Intel Extreme Graphics 2 (waiting confirmation) */
5637 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_NOEC
),
5638 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_NOEC
),
5639 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_NOEC
),
5641 /* Models with Intel GMA900 */
5642 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
5643 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
5644 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
5647 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
5650 unsigned long quirks
;
5652 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
5654 mutex_init(&brightness_mutex
);
5656 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
5657 ARRAY_SIZE(brightness_quirk_table
));
5660 * We always attempt to detect acpi support, so as to switch
5661 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
5662 * going to publish a backlight interface
5664 b
= tpacpi_check_std_acpi_brightness_support();
5667 if (acpi_video_backlight_support()) {
5668 if (brightness_enable
> 1) {
5669 printk(TPACPI_NOTICE
5670 "Standard ACPI backlight interface "
5671 "available, not loading native one.\n");
5673 } else if (brightness_enable
== 1) {
5674 printk(TPACPI_NOTICE
5675 "Backlight control force enabled, even if standard "
5676 "ACPI backlight interface is available\n");
5679 if (brightness_enable
> 1) {
5680 printk(TPACPI_NOTICE
5681 "Standard ACPI backlight interface not "
5682 "available, thinkpad_acpi native "
5683 "brightness control enabled\n");
5688 if (!brightness_enable
) {
5689 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
5690 "brightness support disabled by "
5691 "module parameter\n");
5697 "Unsupported brightness interface, "
5698 "please contact %s\n", TPACPI_MAIL
);
5702 tp_features
.bright_16levels
= 1;
5705 * Check for module parameter bogosity, note that we
5706 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
5707 * able to detect "unspecified"
5709 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
5712 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
5713 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
5714 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
5715 if (quirks
& TPACPI_BRGHT_Q_EC
)
5716 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
5718 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
5720 dbg_printk(TPACPI_DBG_BRGHT
,
5721 "driver auto-selected brightness_mode=%d\n",
5726 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
5727 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
5728 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
5731 if (tpacpi_brightness_get_raw(&b
) < 0)
5734 if (tp_features
.bright_16levels
)
5736 "detected a 16-level brightness capable ThinkPad\n");
5738 ibm_backlight_device
= backlight_device_register(
5739 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
5740 &ibm_backlight_data
);
5741 if (IS_ERR(ibm_backlight_device
)) {
5742 printk(TPACPI_ERR
"Could not register backlight device\n");
5743 return PTR_ERR(ibm_backlight_device
);
5745 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
5746 "brightness is supported\n");
5748 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
5749 printk(TPACPI_NOTICE
5750 "brightness: will use unverified default: "
5751 "brightness_mode=%d\n", brightness_mode
);
5752 printk(TPACPI_NOTICE
5753 "brightness: please report to %s whether it works well "
5754 "or not on your ThinkPad\n", TPACPI_MAIL
);
5757 ibm_backlight_device
->props
.max_brightness
=
5758 (tp_features
.bright_16levels
)? 15 : 7;
5759 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
5760 backlight_update_status(ibm_backlight_device
);
5765 static void brightness_suspend(pm_message_t state
)
5767 tpacpi_brightness_checkpoint_nvram();
5770 static void brightness_shutdown(void)
5772 tpacpi_brightness_checkpoint_nvram();
5775 static void brightness_exit(void)
5777 if (ibm_backlight_device
) {
5778 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
5779 "calling backlight_device_unregister()\n");
5780 backlight_device_unregister(ibm_backlight_device
);
5783 tpacpi_brightness_checkpoint_nvram();
5786 static int brightness_read(char *p
)
5791 level
= brightness_get(NULL
);
5793 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5795 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
5796 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
5797 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5798 " (<level> is 0-%d)\n",
5799 (tp_features
.bright_16levels
) ? 15 : 7);
5805 static int brightness_write(char *buf
)
5810 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
5812 level
= brightness_get(NULL
);
5816 while ((cmd
= next_cmd(&buf
))) {
5817 if (strlencmp(cmd
, "up") == 0) {
5818 if (level
< max_level
)
5820 } else if (strlencmp(cmd
, "down") == 0) {
5823 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
5824 level
>= 0 && level
<= max_level
) {
5830 tpacpi_disclose_usertask("procfs brightness",
5831 "set level to %d\n", level
);
5834 * Now we know what the final level should be, so we try to set it.
5835 * Doing it this way makes the syscall restartable in case of EINTR
5837 rc
= brightness_set(level
);
5838 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
5841 static struct ibm_struct brightness_driver_data
= {
5842 .name
= "brightness",
5843 .read
= brightness_read
,
5844 .write
= brightness_write
,
5845 .exit
= brightness_exit
,
5846 .suspend
= brightness_suspend
,
5847 .shutdown
= brightness_shutdown
,
5850 /*************************************************************************
5854 static int volume_offset
= 0x30;
5856 static int volume_read(char *p
)
5861 if (!acpi_ec_read(volume_offset
, &level
)) {
5862 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5864 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
5865 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
5866 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
5867 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5868 " (<level> is 0-15)\n");
5874 static int volume_write(char *buf
)
5876 int cmos_cmd
, inc
, i
;
5878 int new_level
, new_mute
;
5881 while ((cmd
= next_cmd(&buf
))) {
5882 if (!acpi_ec_read(volume_offset
, &level
))
5884 new_mute
= mute
= level
& 0x40;
5885 new_level
= level
= level
& 0xf;
5887 if (strlencmp(cmd
, "up") == 0) {
5891 new_level
= level
== 15 ? 15 : level
+ 1;
5892 } else if (strlencmp(cmd
, "down") == 0) {
5896 new_level
= level
== 0 ? 0 : level
- 1;
5897 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
5898 new_level
>= 0 && new_level
<= 15) {
5900 } else if (strlencmp(cmd
, "mute") == 0) {
5905 if (new_level
!= level
) {
5906 /* mute doesn't change */
5908 cmos_cmd
= (new_level
> level
) ?
5909 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
5910 inc
= new_level
> level
? 1 : -1;
5912 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
5913 !acpi_ec_write(volume_offset
, level
)))
5916 for (i
= level
; i
!= new_level
; i
+= inc
)
5917 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5918 !acpi_ec_write(volume_offset
, i
+ inc
))
5922 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
5923 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
5928 if (new_mute
!= mute
) {
5929 /* level doesn't change */
5931 cmos_cmd
= (new_mute
) ?
5932 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
5934 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5935 !acpi_ec_write(volume_offset
, level
+ new_mute
))
5943 static struct ibm_struct volume_driver_data
= {
5945 .read
= volume_read
,
5946 .write
= volume_write
,
5949 /*************************************************************************
5956 * TPACPI_FAN_RD_ACPI_GFAN:
5957 * ACPI GFAN method: returns fan level
5959 * see TPACPI_FAN_WR_ACPI_SFAN
5960 * EC 0x2f (HFSP) not available if GFAN exists
5962 * TPACPI_FAN_WR_ACPI_SFAN:
5963 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
5965 * EC 0x2f (HFSP) might be available *for reading*, but do not use
5968 * TPACPI_FAN_WR_TPEC:
5969 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
5970 * Supported on almost all ThinkPads
5972 * Fan speed changes of any sort (including those caused by the
5973 * disengaged mode) are usually done slowly by the firmware as the
5974 * maximum ammount of fan duty cycle change per second seems to be
5977 * Reading is not available if GFAN exists.
5978 * Writing is not available if SFAN exists.
5981 * 7 automatic mode engaged;
5982 * (default operation mode of the ThinkPad)
5983 * fan level is ignored in this mode.
5984 * 6 full speed mode (takes precedence over bit 7);
5985 * not available on all thinkpads. May disable
5986 * the tachometer while the fan controller ramps up
5987 * the speed (which can take up to a few *minutes*).
5988 * Speeds up fan to 100% duty-cycle, which is far above
5989 * the standard RPM levels. It is not impossible that
5990 * it could cause hardware damage.
5991 * 5-3 unused in some models. Extra bits for fan level
5992 * in others, but still useless as all values above
5993 * 7 map to the same speed as level 7 in these models.
5994 * 2-0 fan level (0..7 usually)
5996 * 0x07 = max (set when temperatures critical)
5997 * Some ThinkPads may have other levels, see
5998 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
6000 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
6001 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
6002 * does so, its initial value is meaningless (0x07).
6004 * For firmware bugs, refer to:
6005 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6009 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
6010 * Main fan tachometer reading (in RPM)
6012 * This register is present on all ThinkPads with a new-style EC, and
6013 * it is known not to be present on the A21m/e, and T22, as there is
6014 * something else in offset 0x84 according to the ACPI DSDT. Other
6015 * ThinkPads from this same time period (and earlier) probably lack the
6016 * tachometer as well.
6018 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
6019 * was never fixed by IBM to report the EC firmware version string
6020 * probably support the tachometer (like the early X models), so
6021 * detecting it is quite hard. We need more data to know for sure.
6023 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
6026 * FIRMWARE BUG: may go stale while the EC is switching to full speed
6029 * For firmware bugs, refer to:
6030 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6034 * ThinkPad EC register 0x31 bit 0 (only on select models)
6036 * When bit 0 of EC register 0x31 is zero, the tachometer registers
6037 * show the speed of the main fan. When bit 0 of EC register 0x31
6038 * is one, the tachometer registers show the speed of the auxiliary
6041 * Fan control seems to affect both fans, regardless of the state
6044 * So far, only the firmware for the X60/X61 non-tablet versions
6045 * seem to support this (firmware TP-7M).
6047 * TPACPI_FAN_WR_ACPI_FANS:
6048 * ThinkPad X31, X40, X41. Not available in the X60.
6050 * FANS ACPI handle: takes three arguments: low speed, medium speed,
6051 * high speed. ACPI DSDT seems to map these three speeds to levels
6052 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
6053 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
6055 * The speeds are stored on handles
6056 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
6058 * There are three default speed sets, acessible as handles:
6059 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
6061 * ACPI DSDT switches which set is in use depending on various
6064 * TPACPI_FAN_WR_TPEC is also available and should be used to
6065 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
6066 * but the ACPI tables just mention level 7.
6069 enum { /* Fan control constants */
6070 fan_status_offset
= 0x2f, /* EC register 0x2f */
6071 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
6072 * 0x84 must be read before 0x85 */
6073 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
6074 bit 0 selects which fan is active */
6076 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
6077 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
6079 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
6082 enum fan_status_access_mode
{
6083 TPACPI_FAN_NONE
= 0, /* No fan status or control */
6084 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
6085 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
6088 enum fan_control_access_mode
{
6089 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
6090 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
6091 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
6092 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
6095 enum fan_control_commands
{
6096 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
6097 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
6098 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
6099 * and also watchdog cmd */
6102 static int fan_control_allowed
;
6104 static enum fan_status_access_mode fan_status_access_mode
;
6105 static enum fan_control_access_mode fan_control_access_mode
;
6106 static enum fan_control_commands fan_control_commands
;
6108 static u8 fan_control_initial_status
;
6109 static u8 fan_control_desired_level
;
6110 static u8 fan_control_resume_level
;
6111 static int fan_watchdog_maxinterval
;
6113 static struct mutex fan_mutex
;
6115 static void fan_watchdog_fire(struct work_struct
*ignored
);
6116 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
6118 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
6119 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
6120 "\\FSPD", /* 600e/x, 770e, 770x */
6122 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
6123 "JFNS", /* 770x-JL */
6127 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
6128 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
6129 * be in auto mode (0x80).
6131 * This is corrected by any write to HFSP either by the driver, or
6134 * We assume 0x07 really means auto mode while this quirk is active,
6135 * as this is far more likely than the ThinkPad being in level 7,
6136 * which is only used by the firmware during thermal emergencies.
6138 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
6139 * TP-70 (T43, R52), which are known to be buggy.
6142 static void fan_quirk1_setup(void)
6144 if (fan_control_initial_status
== 0x07) {
6145 printk(TPACPI_NOTICE
6146 "fan_init: initial fan status is unknown, "
6147 "assuming it is in auto mode\n");
6148 tp_features
.fan_ctrl_status_undef
= 1;
6152 static void fan_quirk1_handle(u8
*fan_status
)
6154 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6155 if (*fan_status
!= fan_control_initial_status
) {
6156 /* something changed the HFSP regisnter since
6157 * driver init time, so it is not undefined
6159 tp_features
.fan_ctrl_status_undef
= 0;
6161 /* Return most likely status. In fact, it
6162 * might be the only possible status */
6163 *fan_status
= TP_EC_FAN_AUTO
;
6168 /* Select main fan on X60/X61, NOOP on others */
6169 static bool fan_select_fan1(void)
6171 if (tp_features
.second_fan
) {
6174 if (ec_read(fan_select_offset
, &val
) < 0)
6177 if (ec_write(fan_select_offset
, val
) < 0)
6183 /* Select secondary fan on X60/X61 */
6184 static bool fan_select_fan2(void)
6188 if (!tp_features
.second_fan
)
6191 if (ec_read(fan_select_offset
, &val
) < 0)
6194 if (ec_write(fan_select_offset
, val
) < 0)
6201 * Call with fan_mutex held
6203 static void fan_update_desired_level(u8 status
)
6206 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6208 fan_control_desired_level
= 7;
6210 fan_control_desired_level
= status
;
6214 static int fan_get_status(u8
*status
)
6219 * Add TPACPI_FAN_RD_ACPI_FANS ? */
6221 switch (fan_status_access_mode
) {
6222 case TPACPI_FAN_RD_ACPI_GFAN
:
6223 /* 570, 600e/x, 770e, 770x */
6225 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
6233 case TPACPI_FAN_RD_TPEC
:
6234 /* all except 570, 600e/x, 770e, 770x */
6235 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
6238 if (likely(status
)) {
6240 fan_quirk1_handle(status
);
6252 static int fan_get_status_safe(u8
*status
)
6257 if (mutex_lock_killable(&fan_mutex
))
6258 return -ERESTARTSYS
;
6259 rc
= fan_get_status(&s
);
6261 fan_update_desired_level(s
);
6262 mutex_unlock(&fan_mutex
);
6270 static int fan_get_speed(unsigned int *speed
)
6274 switch (fan_status_access_mode
) {
6275 case TPACPI_FAN_RD_TPEC
:
6276 /* all except 570, 600e/x, 770e, 770x */
6277 if (unlikely(!fan_select_fan1()))
6279 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
6280 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
6284 *speed
= (hi
<< 8) | lo
;
6295 static int fan2_get_speed(unsigned int *speed
)
6300 switch (fan_status_access_mode
) {
6301 case TPACPI_FAN_RD_TPEC
:
6302 /* all except 570, 600e/x, 770e, 770x */
6303 if (unlikely(!fan_select_fan2()))
6305 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
6306 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
6307 fan_select_fan1(); /* play it safe */
6312 *speed
= (hi
<< 8) | lo
;
6323 static int fan_set_level(int level
)
6325 if (!fan_control_allowed
)
6328 switch (fan_control_access_mode
) {
6329 case TPACPI_FAN_WR_ACPI_SFAN
:
6330 if (level
>= 0 && level
<= 7) {
6331 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
6337 case TPACPI_FAN_WR_ACPI_FANS
:
6338 case TPACPI_FAN_WR_TPEC
:
6339 if (!(level
& TP_EC_FAN_AUTO
) &&
6340 !(level
& TP_EC_FAN_FULLSPEED
) &&
6341 ((level
< 0) || (level
> 7)))
6344 /* safety net should the EC not support AUTO
6345 * or FULLSPEED mode bits and just ignore them */
6346 if (level
& TP_EC_FAN_FULLSPEED
)
6347 level
|= 7; /* safety min speed 7 */
6348 else if (level
& TP_EC_FAN_AUTO
)
6349 level
|= 4; /* safety min speed 4 */
6351 if (!acpi_ec_write(fan_status_offset
, level
))
6354 tp_features
.fan_ctrl_status_undef
= 0;
6361 vdbg_printk(TPACPI_DBG_FAN
,
6362 "fan control: set fan control register to 0x%02x\n", level
);
6366 static int fan_set_level_safe(int level
)
6370 if (!fan_control_allowed
)
6373 if (mutex_lock_killable(&fan_mutex
))
6374 return -ERESTARTSYS
;
6376 if (level
== TPACPI_FAN_LAST_LEVEL
)
6377 level
= fan_control_desired_level
;
6379 rc
= fan_set_level(level
);
6381 fan_update_desired_level(level
);
6383 mutex_unlock(&fan_mutex
);
6387 static int fan_set_enable(void)
6392 if (!fan_control_allowed
)
6395 if (mutex_lock_killable(&fan_mutex
))
6396 return -ERESTARTSYS
;
6398 switch (fan_control_access_mode
) {
6399 case TPACPI_FAN_WR_ACPI_FANS
:
6400 case TPACPI_FAN_WR_TPEC
:
6401 rc
= fan_get_status(&s
);
6405 /* Don't go out of emergency fan mode */
6408 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
6411 if (!acpi_ec_write(fan_status_offset
, s
))
6414 tp_features
.fan_ctrl_status_undef
= 0;
6419 case TPACPI_FAN_WR_ACPI_SFAN
:
6420 rc
= fan_get_status(&s
);
6426 /* Set fan to at least level 4 */
6429 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
6439 mutex_unlock(&fan_mutex
);
6442 vdbg_printk(TPACPI_DBG_FAN
,
6443 "fan control: set fan control register to 0x%02x\n",
6448 static int fan_set_disable(void)
6452 if (!fan_control_allowed
)
6455 if (mutex_lock_killable(&fan_mutex
))
6456 return -ERESTARTSYS
;
6459 switch (fan_control_access_mode
) {
6460 case TPACPI_FAN_WR_ACPI_FANS
:
6461 case TPACPI_FAN_WR_TPEC
:
6462 if (!acpi_ec_write(fan_status_offset
, 0x00))
6465 fan_control_desired_level
= 0;
6466 tp_features
.fan_ctrl_status_undef
= 0;
6470 case TPACPI_FAN_WR_ACPI_SFAN
:
6471 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
6474 fan_control_desired_level
= 0;
6482 vdbg_printk(TPACPI_DBG_FAN
,
6483 "fan control: set fan control register to 0\n");
6485 mutex_unlock(&fan_mutex
);
6489 static int fan_set_speed(int speed
)
6493 if (!fan_control_allowed
)
6496 if (mutex_lock_killable(&fan_mutex
))
6497 return -ERESTARTSYS
;
6500 switch (fan_control_access_mode
) {
6501 case TPACPI_FAN_WR_ACPI_FANS
:
6502 if (speed
>= 0 && speed
<= 65535) {
6503 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
6504 speed
, speed
, speed
))
6514 mutex_unlock(&fan_mutex
);
6518 static void fan_watchdog_reset(void)
6520 static int fan_watchdog_active
;
6522 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
6525 if (fan_watchdog_active
)
6526 cancel_delayed_work(&fan_watchdog_task
);
6528 if (fan_watchdog_maxinterval
> 0 &&
6529 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
6530 fan_watchdog_active
= 1;
6531 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
6532 msecs_to_jiffies(fan_watchdog_maxinterval
6535 "failed to queue the fan watchdog, "
6536 "watchdog will not trigger\n");
6539 fan_watchdog_active
= 0;
6542 static void fan_watchdog_fire(struct work_struct
*ignored
)
6546 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
6549 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
6550 rc
= fan_set_enable();
6552 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
6553 "will try again later...\n", -rc
);
6554 /* reschedule for later */
6555 fan_watchdog_reset();
6560 * SYSFS fan layout: hwmon compatible (device)
6563 * 0: "disengaged" mode
6565 * 2: native EC "auto" mode (recommended, hardware default)
6567 * pwm*: set speed in manual mode, ignored otherwise.
6568 * 0 is level 0; 255 is level 7. Intermediate points done with linear
6571 * fan*_input: tachometer reading, RPM
6574 * SYSFS fan layout: extensions
6576 * fan_watchdog (driver):
6577 * fan watchdog interval in seconds, 0 disables (default), max 120
6580 /* sysfs fan pwm1_enable ----------------------------------------------- */
6581 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
6582 struct device_attribute
*attr
,
6588 res
= fan_get_status_safe(&status
);
6592 if (status
& TP_EC_FAN_FULLSPEED
) {
6594 } else if (status
& TP_EC_FAN_AUTO
) {
6599 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
6602 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
6603 struct device_attribute
*attr
,
6604 const char *buf
, size_t count
)
6609 if (parse_strtoul(buf
, 2, &t
))
6612 tpacpi_disclose_usertask("hwmon pwm1_enable",
6613 "set fan mode to %lu\n", t
);
6617 level
= TP_EC_FAN_FULLSPEED
;
6620 level
= TPACPI_FAN_LAST_LEVEL
;
6623 level
= TP_EC_FAN_AUTO
;
6626 /* reserved for software-controlled auto mode */
6632 res
= fan_set_level_safe(level
);
6638 fan_watchdog_reset();
6643 static struct device_attribute dev_attr_fan_pwm1_enable
=
6644 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
6645 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
6647 /* sysfs fan pwm1 ------------------------------------------------------ */
6648 static ssize_t
fan_pwm1_show(struct device
*dev
,
6649 struct device_attribute
*attr
,
6655 res
= fan_get_status_safe(&status
);
6660 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
6661 status
= fan_control_desired_level
;
6666 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
6669 static ssize_t
fan_pwm1_store(struct device
*dev
,
6670 struct device_attribute
*attr
,
6671 const char *buf
, size_t count
)
6675 u8 status
, newlevel
;
6677 if (parse_strtoul(buf
, 255, &s
))
6680 tpacpi_disclose_usertask("hwmon pwm1",
6681 "set fan speed to %lu\n", s
);
6683 /* scale down from 0-255 to 0-7 */
6684 newlevel
= (s
>> 5) & 0x07;
6686 if (mutex_lock_killable(&fan_mutex
))
6687 return -ERESTARTSYS
;
6689 rc
= fan_get_status(&status
);
6690 if (!rc
&& (status
&
6691 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6692 rc
= fan_set_level(newlevel
);
6696 fan_update_desired_level(newlevel
);
6697 fan_watchdog_reset();
6701 mutex_unlock(&fan_mutex
);
6702 return (rc
)? rc
: count
;
6705 static struct device_attribute dev_attr_fan_pwm1
=
6706 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
6707 fan_pwm1_show
, fan_pwm1_store
);
6709 /* sysfs fan fan1_input ------------------------------------------------ */
6710 static ssize_t
fan_fan1_input_show(struct device
*dev
,
6711 struct device_attribute
*attr
,
6717 res
= fan_get_speed(&speed
);
6721 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
6724 static struct device_attribute dev_attr_fan_fan1_input
=
6725 __ATTR(fan1_input
, S_IRUGO
,
6726 fan_fan1_input_show
, NULL
);
6728 /* sysfs fan fan2_input ------------------------------------------------ */
6729 static ssize_t
fan_fan2_input_show(struct device
*dev
,
6730 struct device_attribute
*attr
,
6736 res
= fan2_get_speed(&speed
);
6740 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
6743 static struct device_attribute dev_attr_fan_fan2_input
=
6744 __ATTR(fan2_input
, S_IRUGO
,
6745 fan_fan2_input_show
, NULL
);
6747 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
6748 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
6751 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
6754 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
6755 const char *buf
, size_t count
)
6759 if (parse_strtoul(buf
, 120, &t
))
6762 if (!fan_control_allowed
)
6765 fan_watchdog_maxinterval
= t
;
6766 fan_watchdog_reset();
6768 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
6773 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
6774 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
6776 /* --------------------------------------------------------------------- */
6777 static struct attribute
*fan_attributes
[] = {
6778 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
6779 &dev_attr_fan_fan1_input
.attr
,
6780 NULL
, /* for fan2_input */
6784 static const struct attribute_group fan_attr_group
= {
6785 .attrs
= fan_attributes
,
6788 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
6789 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
6791 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
6792 { .vendor = PCI_VENDOR_ID_IBM, \
6793 .bios = TPACPI_MATCH_ANY, \
6794 .ec = TPID(__id1, __id2), \
6795 .quirks = __quirks }
6797 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
6798 { .vendor = PCI_VENDOR_ID_LENOVO, \
6799 .bios = TPACPI_MATCH_ANY, \
6800 .ec = TPID(__id1, __id2), \
6801 .quirks = __quirks }
6803 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
6804 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
6805 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
6806 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
6807 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
6808 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
6811 #undef TPACPI_FAN_QL
6812 #undef TPACPI_FAN_QI
6814 static int __init
fan_init(struct ibm_init_struct
*iibm
)
6817 unsigned long quirks
;
6819 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
6820 "initializing fan subdriver\n");
6822 mutex_init(&fan_mutex
);
6823 fan_status_access_mode
= TPACPI_FAN_NONE
;
6824 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6825 fan_control_commands
= 0;
6826 fan_watchdog_maxinterval
= 0;
6827 tp_features
.fan_ctrl_status_undef
= 0;
6828 tp_features
.second_fan
= 0;
6829 fan_control_desired_level
= 7;
6831 TPACPI_ACPIHANDLE_INIT(fans
);
6832 TPACPI_ACPIHANDLE_INIT(gfan
);
6833 TPACPI_ACPIHANDLE_INIT(sfan
);
6835 quirks
= tpacpi_check_quirks(fan_quirk_table
,
6836 ARRAY_SIZE(fan_quirk_table
));
6839 /* 570, 600e/x, 770e, 770x */
6840 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
6842 /* all other ThinkPads: note that even old-style
6843 * ThinkPad ECs supports the fan control register */
6844 if (likely(acpi_ec_read(fan_status_offset
,
6845 &fan_control_initial_status
))) {
6846 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
6847 if (quirks
& TPACPI_FAN_Q1
)
6849 if (quirks
& TPACPI_FAN_2FAN
) {
6850 tp_features
.second_fan
= 1;
6851 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
6852 "secondary fan support enabled\n");
6856 "ThinkPad ACPI EC access misbehaving, "
6857 "fan status and control unavailable\n");
6864 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
6865 fan_control_commands
|=
6866 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
6869 /* gfan without sfan means no fan control */
6870 /* all other models implement TP EC 0x2f control */
6874 fan_control_access_mode
=
6875 TPACPI_FAN_WR_ACPI_FANS
;
6876 fan_control_commands
|=
6877 TPACPI_FAN_CMD_SPEED
|
6878 TPACPI_FAN_CMD_LEVEL
|
6879 TPACPI_FAN_CMD_ENABLE
;
6881 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
6882 fan_control_commands
|=
6883 TPACPI_FAN_CMD_LEVEL
|
6884 TPACPI_FAN_CMD_ENABLE
;
6889 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
6890 "fan is %s, modes %d, %d\n",
6891 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
6892 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
6893 fan_status_access_mode
, fan_control_access_mode
);
6895 /* fan control master switch */
6896 if (!fan_control_allowed
) {
6897 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6898 fan_control_commands
= 0;
6899 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
6900 "fan control features disabled by parameter\n");
6903 /* update fan_control_desired_level */
6904 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
6905 fan_get_status_safe(NULL
);
6907 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
6908 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
6909 if (tp_features
.second_fan
) {
6910 /* attach second fan tachometer */
6911 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
6912 &dev_attr_fan_fan2_input
.attr
;
6914 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6919 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
6920 &driver_attr_fan_watchdog
);
6922 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6931 static void fan_exit(void)
6933 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
6934 "cancelling any pending fan watchdog tasks\n");
6936 /* FIXME: can we really do this unconditionally? */
6937 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
6938 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
6939 &driver_attr_fan_watchdog
);
6941 cancel_delayed_work(&fan_watchdog_task
);
6942 flush_workqueue(tpacpi_wq
);
6945 static void fan_suspend(pm_message_t state
)
6949 if (!fan_control_allowed
)
6952 /* Store fan status in cache */
6953 fan_control_resume_level
= 0;
6954 rc
= fan_get_status_safe(&fan_control_resume_level
);
6956 printk(TPACPI_NOTICE
6957 "failed to read fan level for later "
6958 "restore during resume: %d\n", rc
);
6960 /* if it is undefined, don't attempt to restore it.
6962 if (tp_features
.fan_ctrl_status_undef
)
6963 fan_control_resume_level
= 0;
6966 static void fan_resume(void)
6968 u8 current_level
= 7;
6969 bool do_set
= false;
6972 /* DSDT *always* updates status on resume */
6973 tp_features
.fan_ctrl_status_undef
= 0;
6975 if (!fan_control_allowed
||
6976 !fan_control_resume_level
||
6977 (fan_get_status_safe(¤t_level
) < 0))
6980 switch (fan_control_access_mode
) {
6981 case TPACPI_FAN_WR_ACPI_SFAN
:
6982 /* never decrease fan level */
6983 do_set
= (fan_control_resume_level
> current_level
);
6985 case TPACPI_FAN_WR_ACPI_FANS
:
6986 case TPACPI_FAN_WR_TPEC
:
6987 /* never decrease fan level, scale is:
6988 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
6990 * We expect the firmware to set either 7 or AUTO, but we
6991 * handle FULLSPEED out of paranoia.
6993 * So, we can safely only restore FULLSPEED or 7, anything
6994 * else could slow the fan. Restoring AUTO is useless, at
6995 * best that's exactly what the DSDT already set (it is the
6998 * Always keep in mind that the DSDT *will* have set the
6999 * fans to what the vendor supposes is the best level. We
7000 * muck with it only to speed the fan up.
7002 if (fan_control_resume_level
!= 7 &&
7003 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
7006 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
7007 (current_level
!= fan_control_resume_level
);
7013 printk(TPACPI_NOTICE
7014 "restoring fan level to 0x%02x\n",
7015 fan_control_resume_level
);
7016 rc
= fan_set_level_safe(fan_control_resume_level
);
7018 printk(TPACPI_NOTICE
7019 "failed to restore fan level: %d\n", rc
);
7023 static int fan_read(char *p
)
7028 unsigned int speed
= 0;
7030 switch (fan_status_access_mode
) {
7031 case TPACPI_FAN_RD_ACPI_GFAN
:
7032 /* 570, 600e/x, 770e, 770x */
7033 rc
= fan_get_status_safe(&status
);
7037 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
7039 (status
!= 0) ? "enabled" : "disabled", status
);
7042 case TPACPI_FAN_RD_TPEC
:
7043 /* all except 570, 600e/x, 770e, 770x */
7044 rc
= fan_get_status_safe(&status
);
7048 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
7049 (status
!= 0) ? "enabled" : "disabled");
7051 rc
= fan_get_speed(&speed
);
7055 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
7057 if (status
& TP_EC_FAN_FULLSPEED
)
7058 /* Disengaged mode takes precedence */
7059 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
7060 else if (status
& TP_EC_FAN_AUTO
)
7061 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
7063 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
7066 case TPACPI_FAN_NONE
:
7068 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
7071 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
7072 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
7074 switch (fan_control_access_mode
) {
7075 case TPACPI_FAN_WR_ACPI_SFAN
:
7076 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
7080 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
7081 "auto, disengaged, full-speed)\n");
7086 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
7087 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
7088 "commands:\twatchdog <timeout> (<timeout> "
7089 "is 0 (off), 1-120 (seconds))\n");
7091 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
7092 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
7093 " (<speed> is 0-65535)\n");
7098 static int fan_write_cmd_level(const char *cmd
, int *rc
)
7102 if (strlencmp(cmd
, "level auto") == 0)
7103 level
= TP_EC_FAN_AUTO
;
7104 else if ((strlencmp(cmd
, "level disengaged") == 0) |
7105 (strlencmp(cmd
, "level full-speed") == 0))
7106 level
= TP_EC_FAN_FULLSPEED
;
7107 else if (sscanf(cmd
, "level %d", &level
) != 1)
7110 *rc
= fan_set_level_safe(level
);
7112 printk(TPACPI_ERR
"level command accepted for unsupported "
7113 "access mode %d", fan_control_access_mode
);
7115 tpacpi_disclose_usertask("procfs fan",
7116 "set level to %d\n", level
);
7121 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
7123 if (strlencmp(cmd
, "enable") != 0)
7126 *rc
= fan_set_enable();
7128 printk(TPACPI_ERR
"enable command accepted for unsupported "
7129 "access mode %d", fan_control_access_mode
);
7131 tpacpi_disclose_usertask("procfs fan", "enable\n");
7136 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
7138 if (strlencmp(cmd
, "disable") != 0)
7141 *rc
= fan_set_disable();
7143 printk(TPACPI_ERR
"disable command accepted for unsupported "
7144 "access mode %d", fan_control_access_mode
);
7146 tpacpi_disclose_usertask("procfs fan", "disable\n");
7151 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
7156 * Support speed <low> <medium> <high> ? */
7158 if (sscanf(cmd
, "speed %d", &speed
) != 1)
7161 *rc
= fan_set_speed(speed
);
7163 printk(TPACPI_ERR
"speed command accepted for unsupported "
7164 "access mode %d", fan_control_access_mode
);
7166 tpacpi_disclose_usertask("procfs fan",
7167 "set speed to %d\n", speed
);
7172 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
7176 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
7179 if (interval
< 0 || interval
> 120)
7182 fan_watchdog_maxinterval
= interval
;
7183 tpacpi_disclose_usertask("procfs fan",
7184 "set watchdog timer to %d\n",
7191 static int fan_write(char *buf
)
7196 while (!rc
&& (cmd
= next_cmd(&buf
))) {
7197 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
7198 fan_write_cmd_level(cmd
, &rc
)) &&
7199 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
7200 (fan_write_cmd_enable(cmd
, &rc
) ||
7201 fan_write_cmd_disable(cmd
, &rc
) ||
7202 fan_write_cmd_watchdog(cmd
, &rc
))) &&
7203 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
7204 fan_write_cmd_speed(cmd
, &rc
))
7208 fan_watchdog_reset();
7214 static struct ibm_struct fan_driver_data
= {
7219 .suspend
= fan_suspend
,
7220 .resume
= fan_resume
,
7223 /****************************************************************************
7224 ****************************************************************************
7228 ****************************************************************************
7229 ****************************************************************************/
7231 /* sysfs name ---------------------------------------------------------- */
7232 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
7233 struct device_attribute
*attr
,
7236 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
7239 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
7240 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
7242 /* --------------------------------------------------------------------- */
7245 static struct proc_dir_entry
*proc_dir
;
7248 * Module and infrastructure proble, init and exit handling
7251 static int force_load
;
7253 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
7254 static const char * __init
str_supported(int is_supported
)
7256 static char text_unsupported
[] __initdata
= "not supported";
7258 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
7260 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
7262 static void ibm_exit(struct ibm_struct
*ibm
)
7264 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
7266 list_del_init(&ibm
->all_drivers
);
7268 if (ibm
->flags
.acpi_notify_installed
) {
7269 dbg_printk(TPACPI_DBG_EXIT
,
7270 "%s: acpi_remove_notify_handler\n", ibm
->name
);
7272 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
7274 dispatch_acpi_notify
);
7275 ibm
->flags
.acpi_notify_installed
= 0;
7276 ibm
->flags
.acpi_notify_installed
= 0;
7279 if (ibm
->flags
.proc_created
) {
7280 dbg_printk(TPACPI_DBG_EXIT
,
7281 "%s: remove_proc_entry\n", ibm
->name
);
7282 remove_proc_entry(ibm
->name
, proc_dir
);
7283 ibm
->flags
.proc_created
= 0;
7286 if (ibm
->flags
.acpi_driver_registered
) {
7287 dbg_printk(TPACPI_DBG_EXIT
,
7288 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
7290 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
7291 kfree(ibm
->acpi
->driver
);
7292 ibm
->acpi
->driver
= NULL
;
7293 ibm
->flags
.acpi_driver_registered
= 0;
7296 if (ibm
->flags
.init_called
&& ibm
->exit
) {
7298 ibm
->flags
.init_called
= 0;
7301 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
7304 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
7307 struct ibm_struct
*ibm
= iibm
->data
;
7308 struct proc_dir_entry
*entry
;
7310 BUG_ON(ibm
== NULL
);
7312 INIT_LIST_HEAD(&ibm
->all_drivers
);
7314 if (ibm
->flags
.experimental
&& !experimental
)
7317 dbg_printk(TPACPI_DBG_INIT
,
7318 "probing for %s\n", ibm
->name
);
7321 ret
= iibm
->init(iibm
);
7323 return 0; /* probe failed */
7327 ibm
->flags
.init_called
= 1;
7331 if (ibm
->acpi
->hid
) {
7332 ret
= register_tpacpi_subdriver(ibm
);
7337 if (ibm
->acpi
->notify
) {
7338 ret
= setup_acpi_notify(ibm
);
7339 if (ret
== -ENODEV
) {
7340 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
7350 dbg_printk(TPACPI_DBG_INIT
,
7351 "%s installed\n", ibm
->name
);
7354 entry
= create_proc_entry(ibm
->name
,
7355 S_IFREG
| S_IRUGO
| S_IWUSR
,
7358 printk(TPACPI_ERR
"unable to create proc entry %s\n",
7364 entry
->read_proc
= &dispatch_procfs_read
;
7366 entry
->write_proc
= &dispatch_procfs_write
;
7367 ibm
->flags
.proc_created
= 1;
7370 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
7375 dbg_printk(TPACPI_DBG_INIT
,
7376 "%s: at error exit path with result %d\n",
7380 return (ret
< 0)? ret
: 0;
7385 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
7387 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
7390 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
7391 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
7394 return s
&& strlen(s
) >= 8 &&
7395 tpacpi_is_fw_digit(s
[0]) &&
7396 tpacpi_is_fw_digit(s
[1]) &&
7397 s
[2] == t
&& s
[3] == 'T' &&
7398 tpacpi_is_fw_digit(s
[4]) &&
7399 tpacpi_is_fw_digit(s
[5]) &&
7400 s
[6] == 'W' && s
[7] == 'W';
7403 /* returns 0 - probe ok, or < 0 - probe error.
7404 * Probe ok doesn't mean thinkpad found.
7405 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
7406 static int __must_check __init
get_thinkpad_model_data(
7407 struct thinkpad_id_data
*tp
)
7409 const struct dmi_device
*dev
= NULL
;
7410 char ec_fw_string
[18];
7416 memset(tp
, 0, sizeof(*tp
));
7418 if (dmi_name_in_vendors("IBM"))
7419 tp
->vendor
= PCI_VENDOR_ID_IBM
;
7420 else if (dmi_name_in_vendors("LENOVO"))
7421 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
7425 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
7426 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
7427 if (s
&& !tp
->bios_version_str
)
7430 /* Really ancient ThinkPad 240X will fail this, which is fine */
7431 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
7434 tp
->bios_model
= tp
->bios_version_str
[0]
7435 | (tp
->bios_version_str
[1] << 8);
7436 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
7437 | tp
->bios_version_str
[5];
7440 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
7441 * X32 or newer, all Z series; Some models must have an
7442 * up-to-date BIOS or they will not be detected.
7444 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7446 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
7447 if (sscanf(dev
->name
,
7448 "IBM ThinkPad Embedded Controller -[%17c",
7449 ec_fw_string
) == 1) {
7450 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
7451 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
7453 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
7454 if (!tp
->ec_version_str
)
7457 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
7458 tp
->ec_model
= ec_fw_string
[0]
7459 | (ec_fw_string
[1] << 8);
7460 tp
->ec_release
= (ec_fw_string
[4] << 8)
7463 printk(TPACPI_NOTICE
7464 "ThinkPad firmware release %s "
7465 "doesn't match the known patterns\n",
7467 printk(TPACPI_NOTICE
7468 "please report this to %s\n",
7475 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
7476 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
7477 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
7482 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
7483 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
7484 if (s
&& !tp
->nummodel_str
)
7490 static int __init
probe_for_thinkpad(void)
7498 * Non-ancient models have better DMI tagging, but very old models
7501 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
7503 /* ec is required because many other handles are relative to it */
7504 TPACPI_ACPIHANDLE_INIT(ec
);
7508 "Not yet supported ThinkPad detected!\n");
7513 * Risks a regression on very old machines, but reduces potential
7514 * false positives a damn great deal
7517 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
7519 if (!is_thinkpad
&& !force_load
)
7526 /* Module init, exit, parameters */
7528 static struct ibm_init_struct ibms_init
[] __initdata
= {
7530 .init
= thinkpad_acpi_driver_init
,
7531 .data
= &thinkpad_acpi_driver_data
,
7534 .init
= hotkey_init
,
7535 .data
= &hotkey_driver_data
,
7538 .init
= bluetooth_init
,
7539 .data
= &bluetooth_driver_data
,
7543 .data
= &wan_driver_data
,
7547 .data
= &uwb_driver_data
,
7549 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
7552 .data
= &video_driver_data
,
7557 .data
= &light_driver_data
,
7561 .data
= &cmos_driver_data
,
7565 .data
= &led_driver_data
,
7569 .data
= &beep_driver_data
,
7572 .init
= thermal_init
,
7573 .data
= &thermal_driver_data
,
7576 .data
= &ecdump_driver_data
,
7579 .init
= brightness_init
,
7580 .data
= &brightness_driver_data
,
7583 .data
= &volume_driver_data
,
7587 .data
= &fan_driver_data
,
7591 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
7594 struct ibm_struct
*ibm
;
7596 if (!kp
|| !kp
->name
|| !val
)
7599 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7600 ibm
= ibms_init
[i
].data
;
7601 WARN_ON(ibm
== NULL
);
7603 if (!ibm
|| !ibm
->name
)
7606 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
7607 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
7609 strcpy(ibms_init
[i
].param
, val
);
7610 strcat(ibms_init
[i
].param
, ",");
7618 module_param(experimental
, int, 0);
7619 MODULE_PARM_DESC(experimental
,
7620 "Enables experimental features when non-zero");
7622 module_param_named(debug
, dbg_level
, uint
, 0);
7623 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
7625 module_param(force_load
, bool, 0);
7626 MODULE_PARM_DESC(force_load
,
7627 "Attempts to load the driver even on a "
7628 "mis-identified ThinkPad when true");
7630 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
7631 MODULE_PARM_DESC(fan_control
,
7632 "Enables setting fan parameters features when true");
7634 module_param_named(brightness_mode
, brightness_mode
, uint
, 0);
7635 MODULE_PARM_DESC(brightness_mode
,
7636 "Selects brightness control strategy: "
7637 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
7639 module_param(brightness_enable
, uint
, 0);
7640 MODULE_PARM_DESC(brightness_enable
,
7641 "Enables backlight control when 1, disables when 0");
7643 module_param(hotkey_report_mode
, uint
, 0);
7644 MODULE_PARM_DESC(hotkey_report_mode
,
7645 "used for backwards compatibility with userspace, "
7646 "see documentation");
7648 #define TPACPI_PARAM(feature) \
7649 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
7650 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
7651 "at module load, see documentation")
7653 TPACPI_PARAM(hotkey
);
7654 TPACPI_PARAM(bluetooth
);
7655 TPACPI_PARAM(video
);
7656 TPACPI_PARAM(light
);
7660 TPACPI_PARAM(ecdump
);
7661 TPACPI_PARAM(brightness
);
7662 TPACPI_PARAM(volume
);
7665 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
7666 module_param(dbg_wlswemul
, uint
, 0);
7667 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
7668 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
7669 MODULE_PARM_DESC(wlsw_state
,
7670 "Initial state of the emulated WLSW switch");
7672 module_param(dbg_bluetoothemul
, uint
, 0);
7673 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
7674 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
7675 MODULE_PARM_DESC(bluetooth_state
,
7676 "Initial state of the emulated bluetooth switch");
7678 module_param(dbg_wwanemul
, uint
, 0);
7679 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
7680 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
7681 MODULE_PARM_DESC(wwan_state
,
7682 "Initial state of the emulated WWAN switch");
7684 module_param(dbg_uwbemul
, uint
, 0);
7685 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
7686 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
7687 MODULE_PARM_DESC(uwb_state
,
7688 "Initial state of the emulated UWB switch");
7691 static void thinkpad_acpi_module_exit(void)
7693 struct ibm_struct
*ibm
, *itmp
;
7695 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
7697 list_for_each_entry_safe_reverse(ibm
, itmp
,
7698 &tpacpi_all_drivers
,
7703 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
7705 if (tpacpi_inputdev
) {
7706 if (tp_features
.input_device_registered
)
7707 input_unregister_device(tpacpi_inputdev
);
7709 input_free_device(tpacpi_inputdev
);
7713 hwmon_device_unregister(tpacpi_hwmon
);
7715 if (tp_features
.sensors_pdev_attrs_registered
)
7716 device_remove_file(&tpacpi_sensors_pdev
->dev
,
7717 &dev_attr_thinkpad_acpi_pdev_name
);
7718 if (tpacpi_sensors_pdev
)
7719 platform_device_unregister(tpacpi_sensors_pdev
);
7721 platform_device_unregister(tpacpi_pdev
);
7723 if (tp_features
.sensors_pdrv_attrs_registered
)
7724 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
7725 if (tp_features
.platform_drv_attrs_registered
)
7726 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
7728 if (tp_features
.sensors_pdrv_registered
)
7729 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
7731 if (tp_features
.platform_drv_registered
)
7732 platform_driver_unregister(&tpacpi_pdriver
);
7735 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
7738 destroy_workqueue(tpacpi_wq
);
7740 kfree(thinkpad_id
.bios_version_str
);
7741 kfree(thinkpad_id
.ec_version_str
);
7742 kfree(thinkpad_id
.model_str
);
7746 static int __init
thinkpad_acpi_module_init(void)
7750 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
7752 /* Parameter checking */
7753 if (hotkey_report_mode
> 2)
7756 /* Driver-level probe */
7758 ret
= get_thinkpad_model_data(&thinkpad_id
);
7761 "unable to get DMI data: %d\n", ret
);
7762 thinkpad_acpi_module_exit();
7765 ret
= probe_for_thinkpad();
7767 thinkpad_acpi_module_exit();
7771 /* Driver initialization */
7773 TPACPI_ACPIHANDLE_INIT(ecrd
);
7774 TPACPI_ACPIHANDLE_INIT(ecwr
);
7776 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
7778 thinkpad_acpi_module_exit();
7782 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
7785 "unable to create proc dir " TPACPI_PROC_DIR
);
7786 thinkpad_acpi_module_exit();
7790 ret
= platform_driver_register(&tpacpi_pdriver
);
7793 "unable to register main platform driver\n");
7794 thinkpad_acpi_module_exit();
7797 tp_features
.platform_drv_registered
= 1;
7799 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
7802 "unable to register hwmon platform driver\n");
7803 thinkpad_acpi_module_exit();
7806 tp_features
.sensors_pdrv_registered
= 1;
7808 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
7810 tp_features
.platform_drv_attrs_registered
= 1;
7811 ret
= tpacpi_create_driver_attributes(
7812 &tpacpi_hwmon_pdriver
.driver
);
7816 "unable to create sysfs driver attributes\n");
7817 thinkpad_acpi_module_exit();
7820 tp_features
.sensors_pdrv_attrs_registered
= 1;
7823 /* Device initialization */
7824 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
7826 if (IS_ERR(tpacpi_pdev
)) {
7827 ret
= PTR_ERR(tpacpi_pdev
);
7829 printk(TPACPI_ERR
"unable to register platform device\n");
7830 thinkpad_acpi_module_exit();
7833 tpacpi_sensors_pdev
= platform_device_register_simple(
7834 TPACPI_HWMON_DRVR_NAME
,
7836 if (IS_ERR(tpacpi_sensors_pdev
)) {
7837 ret
= PTR_ERR(tpacpi_sensors_pdev
);
7838 tpacpi_sensors_pdev
= NULL
;
7840 "unable to register hwmon platform device\n");
7841 thinkpad_acpi_module_exit();
7844 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
7845 &dev_attr_thinkpad_acpi_pdev_name
);
7848 "unable to create sysfs hwmon device attributes\n");
7849 thinkpad_acpi_module_exit();
7852 tp_features
.sensors_pdev_attrs_registered
= 1;
7853 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
7854 if (IS_ERR(tpacpi_hwmon
)) {
7855 ret
= PTR_ERR(tpacpi_hwmon
);
7856 tpacpi_hwmon
= NULL
;
7857 printk(TPACPI_ERR
"unable to register hwmon device\n");
7858 thinkpad_acpi_module_exit();
7861 mutex_init(&tpacpi_inputdev_send_mutex
);
7862 tpacpi_inputdev
= input_allocate_device();
7863 if (!tpacpi_inputdev
) {
7864 printk(TPACPI_ERR
"unable to allocate input device\n");
7865 thinkpad_acpi_module_exit();
7868 /* Prepare input device, but don't register */
7869 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
7870 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
7871 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
7872 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
7873 thinkpad_id
.vendor
:
7875 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
7876 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
7878 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7879 ret
= ibm_init(&ibms_init
[i
]);
7880 if (ret
>= 0 && *ibms_init
[i
].param
)
7881 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
7883 thinkpad_acpi_module_exit();
7887 ret
= input_register_device(tpacpi_inputdev
);
7889 printk(TPACPI_ERR
"unable to register input device\n");
7890 thinkpad_acpi_module_exit();
7893 tp_features
.input_device_registered
= 1;
7896 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
7900 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
7903 * This will autoload the driver in almost every ThinkPad
7904 * in widespread use.
7906 * Only _VERY_ old models, like the 240, 240x and 570 lack
7907 * the HKEY event interface.
7909 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
7912 * DMI matching for module autoloading
7914 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7915 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
7917 * Only models listed in thinkwiki will be supported, so add yours
7918 * if it is not there yet.
7920 #define IBM_BIOS_MODULE_ALIAS(__type) \
7921 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
7923 /* Ancient thinkpad BIOSes have to be identified by
7924 * BIOS type or model number, and there are far less
7925 * BIOS types than model numbers... */
7926 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
7928 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
7929 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
7930 MODULE_DESCRIPTION(TPACPI_DESC
);
7931 MODULE_VERSION(TPACPI_VERSION
);
7932 MODULE_LICENSE("GPL");
7934 module_init(thinkpad_acpi_module_init
);
7935 module_exit(thinkpad_acpi_module_exit
);