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 0x020500
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
170 #define TPACPI_LOG TPACPI_FILE ": "
171 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
172 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
173 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
174 #define TPACPI_ERR KERN_ERR TPACPI_LOG
175 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
176 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
177 #define TPACPI_INFO KERN_INFO TPACPI_LOG
178 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
180 /* Debugging printk groups */
181 #define TPACPI_DBG_ALL 0xffff
182 #define TPACPI_DBG_DISCLOSETASK 0x8000
183 #define TPACPI_DBG_INIT 0x0001
184 #define TPACPI_DBG_EXIT 0x0002
185 #define TPACPI_DBG_RFKILL 0x0004
186 #define TPACPI_DBG_HKEY 0x0008
187 #define TPACPI_DBG_FAN 0x0010
188 #define TPACPI_DBG_BRGHT 0x0020
190 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
191 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
192 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
195 /****************************************************************************
196 * Driver-wide structs and misc. variables
201 struct tp_acpi_drv_struct
{
202 const struct acpi_device_id
*hid
;
203 struct acpi_driver
*driver
;
205 void (*notify
) (struct ibm_struct
*, u32
);
208 struct acpi_device
*device
;
214 int (*read
) (char *);
215 int (*write
) (char *);
217 void (*resume
) (void);
218 void (*suspend
) (pm_message_t state
);
219 void (*shutdown
) (void);
221 struct list_head all_drivers
;
223 struct tp_acpi_drv_struct
*acpi
;
226 u8 acpi_driver_registered
:1;
227 u8 acpi_notify_installed
:1;
234 struct ibm_init_struct
{
237 int (*init
) (struct ibm_init_struct
*);
238 struct ibm_struct
*data
;
249 u32 bright_16levels
:1;
250 u32 bright_acpimode
:1;
253 u32 fan_ctrl_status_undef
:1;
255 u32 beep_needs_two_args
:1;
256 u32 input_device_registered
:1;
257 u32 platform_drv_registered
:1;
258 u32 platform_drv_attrs_registered
:1;
259 u32 sensors_pdrv_registered
:1;
260 u32 sensors_pdrv_attrs_registered
:1;
261 u32 sensors_pdev_attrs_registered
:1;
262 u32 hotkey_poll_active
:1;
266 u16 hotkey_mask_ff
:1;
269 struct thinkpad_id_data
{
270 unsigned int vendor
; /* ThinkPad vendor:
271 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
273 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
274 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
276 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
278 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
281 char *model_str
; /* ThinkPad T43 */
282 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
284 static struct thinkpad_id_data thinkpad_id
;
287 TPACPI_LIFE_INIT
= 0,
292 static int experimental
;
293 static u32 dbg_level
;
295 static struct workqueue_struct
*tpacpi_wq
;
303 /* Special LED class that can defer work */
304 struct tpacpi_led_classdev
{
305 struct led_classdev led_classdev
;
306 struct work_struct work
;
307 enum led_status_t new_state
;
311 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
312 static int dbg_wlswemul
;
313 static int tpacpi_wlsw_emulstate
;
314 static int dbg_bluetoothemul
;
315 static int tpacpi_bluetooth_emulstate
;
316 static int dbg_wwanemul
;
317 static int tpacpi_wwan_emulstate
;
318 static int dbg_uwbemul
;
319 static int tpacpi_uwb_emulstate
;
323 /*************************************************************************
327 #define dbg_printk(a_dbg_level, format, arg...) \
328 do { if (dbg_level & (a_dbg_level)) \
329 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
332 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
333 #define vdbg_printk dbg_printk
334 static const char *str_supported(int is_supported
);
336 #define vdbg_printk(a_dbg_level, format, arg...) \
340 static void tpacpi_log_usertask(const char * const what
)
342 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
343 what
, task_tgid_vnr(current
));
346 #define tpacpi_disclose_usertask(what, format, arg...) \
349 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
350 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
351 printk(TPACPI_DEBUG "%s: PID %d: " format, \
352 what, task_tgid_vnr(current), ## arg); \
357 * Quirk handling helpers
359 * ThinkPad IDs and versions seen in the field so far
360 * are two-characters from the set [0-9A-Z], i.e. base 36.
362 * We use values well outside that range as specials.
365 #define TPACPI_MATCH_ANY 0xffffU
366 #define TPACPI_MATCH_UNKNOWN 0U
368 /* TPID('1', 'Y') == 0x5931 */
369 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
371 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
372 { .vendor = PCI_VENDOR_ID_IBM, \
373 .bios = TPID(__id1, __id2), \
374 .ec = TPACPI_MATCH_ANY, \
375 .quirks = (__quirk) }
377 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
378 { .vendor = PCI_VENDOR_ID_LENOVO, \
379 .bios = TPID(__id1, __id2), \
380 .ec = TPACPI_MATCH_ANY, \
381 .quirks = (__quirk) }
383 struct tpacpi_quirk
{
387 unsigned long quirks
;
391 * tpacpi_check_quirks() - search BIOS/EC version on a list
392 * @qlist: array of &struct tpacpi_quirk
393 * @qlist_size: number of elements in @qlist
395 * Iterates over a quirks list until one is found that matches the
396 * ThinkPad's vendor, BIOS and EC model.
398 * Returns 0 if nothing matches, otherwise returns the quirks field of
399 * the matching &struct tpacpi_quirk entry.
401 * The match criteria is: vendor, ec and bios much match.
403 static unsigned long __init
tpacpi_check_quirks(
404 const struct tpacpi_quirk
*qlist
,
405 unsigned int qlist_size
)
408 if ((qlist
->vendor
== thinkpad_id
.vendor
||
409 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
410 (qlist
->bios
== thinkpad_id
.bios_model
||
411 qlist
->bios
== TPACPI_MATCH_ANY
) &&
412 (qlist
->ec
== thinkpad_id
.ec_model
||
413 qlist
->ec
== TPACPI_MATCH_ANY
))
414 return qlist
->quirks
;
423 /****************************************************************************
424 ****************************************************************************
426 * ACPI Helpers and device model
428 ****************************************************************************
429 ****************************************************************************/
431 /*************************************************************************
435 static acpi_handle root_handle
;
437 #define TPACPI_HANDLE(object, parent, paths...) \
438 static acpi_handle object##_handle; \
439 static acpi_handle *object##_parent = &parent##_handle; \
440 static char *object##_path; \
441 static char *object##_paths[] = { paths }
443 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
444 "\\_SB.PCI.ISA.EC", /* 570 */
445 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
446 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
447 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
448 "\\_SB.PCI0.ICH3.EC0", /* R31 */
449 "\\_SB.PCI0.LPC.EC", /* all others */
452 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
453 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
455 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
457 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
458 "\\CMS", /* R40, R40e */
461 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
462 "^HKEY", /* R30, R31 */
463 "HKEY", /* all others */
466 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
467 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
468 "\\_SB.PCI0.VID0", /* 770e */
469 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
470 "\\_SB.PCI0.AGP.VID", /* all others */
474 /*************************************************************************
478 static int acpi_evalf(acpi_handle handle
,
479 void *res
, char *method
, char *fmt
, ...)
482 struct acpi_object_list params
;
483 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
484 struct acpi_buffer result
, *resultp
;
485 union acpi_object out_obj
;
493 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
506 params
.pointer
= &in_objs
[0];
513 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
514 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
516 /* add more types as needed */
518 printk(TPACPI_ERR
"acpi_evalf() called "
519 "with invalid format character '%c'\n", c
);
525 if (res_type
!= 'v') {
526 result
.length
= sizeof(out_obj
);
527 result
.pointer
= &out_obj
;
532 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
537 *(int *)res
= out_obj
.integer
.value
;
538 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
541 success
= status
== AE_OK
;
543 /* add more types as needed */
545 printk(TPACPI_ERR
"acpi_evalf() called "
546 "with invalid format character '%c'\n", res_type
);
550 if (!success
&& !quiet
)
551 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
552 method
, fmt0
, status
);
557 static int acpi_ec_read(int i
, u8
*p
)
562 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
566 if (ec_read(i
, p
) < 0)
573 static int acpi_ec_write(int i
, u8 v
)
576 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
579 if (ec_write(i
, v
) < 0)
586 static int issue_thinkpad_cmos_command(int cmos_cmd
)
591 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
597 /*************************************************************************
601 #define TPACPI_ACPIHANDLE_INIT(object) \
602 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
603 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
605 static void drv_acpi_handle_init(char *name
,
606 acpi_handle
*handle
, acpi_handle parent
,
607 char **paths
, int num_paths
, char **path
)
612 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
615 for (i
= 0; i
< num_paths
; i
++) {
616 status
= acpi_get_handle(parent
, paths
[i
], handle
);
617 if (ACPI_SUCCESS(status
)) {
619 dbg_printk(TPACPI_DBG_INIT
,
620 "Found ACPI handle %s for %s\n",
626 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
631 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
633 struct ibm_struct
*ibm
= data
;
635 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
638 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
641 ibm
->acpi
->notify(ibm
, event
);
644 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
651 if (!*ibm
->acpi
->handle
)
654 vdbg_printk(TPACPI_DBG_INIT
,
655 "setting up ACPI notify for %s\n", ibm
->name
);
657 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
659 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
664 ibm
->acpi
->device
->driver_data
= ibm
;
665 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
666 TPACPI_ACPI_EVENT_PREFIX
,
669 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
670 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
671 if (ACPI_FAILURE(status
)) {
672 if (status
== AE_ALREADY_EXISTS
) {
674 "another device driver is already "
675 "handling %s events\n", ibm
->name
);
678 "acpi_install_notify_handler(%s) failed: %d\n",
683 ibm
->flags
.acpi_notify_installed
= 1;
687 static int __init
tpacpi_device_add(struct acpi_device
*device
)
692 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
696 dbg_printk(TPACPI_DBG_INIT
,
697 "registering %s as an ACPI driver\n", ibm
->name
);
701 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
702 if (!ibm
->acpi
->driver
) {
704 "failed to allocate memory for ibm->acpi->driver\n");
708 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
709 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
711 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
713 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
715 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
717 kfree(ibm
->acpi
->driver
);
718 ibm
->acpi
->driver
= NULL
;
720 ibm
->flags
.acpi_driver_registered
= 1;
726 /****************************************************************************
727 ****************************************************************************
731 ****************************************************************************
732 ****************************************************************************/
734 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
735 int count
, int *eof
, void *data
)
737 struct ibm_struct
*ibm
= data
;
740 if (!ibm
|| !ibm
->read
)
743 len
= ibm
->read(page
);
747 if (len
<= off
+ count
)
759 static int dispatch_procfs_write(struct file
*file
,
760 const char __user
*userbuf
,
761 unsigned long count
, void *data
)
763 struct ibm_struct
*ibm
= data
;
767 if (!ibm
|| !ibm
->write
)
769 if (count
> PAGE_SIZE
- 2)
772 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
776 if (copy_from_user(kernbuf
, userbuf
, count
)) {
782 strcat(kernbuf
, ",");
783 ret
= ibm
->write(kernbuf
);
792 static char *next_cmd(char **cmds
)
797 while ((end
= strchr(start
, ',')) && end
== start
)
809 /****************************************************************************
810 ****************************************************************************
812 * Device model: input, hwmon and platform
814 ****************************************************************************
815 ****************************************************************************/
817 static struct platform_device
*tpacpi_pdev
;
818 static struct platform_device
*tpacpi_sensors_pdev
;
819 static struct device
*tpacpi_hwmon
;
820 static struct input_dev
*tpacpi_inputdev
;
821 static struct mutex tpacpi_inputdev_send_mutex
;
822 static LIST_HEAD(tpacpi_all_drivers
);
824 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
827 struct ibm_struct
*ibm
, *itmp
;
829 list_for_each_entry_safe(ibm
, itmp
,
833 (ibm
->suspend
)(state
);
839 static int tpacpi_resume_handler(struct platform_device
*pdev
)
841 struct ibm_struct
*ibm
, *itmp
;
843 list_for_each_entry_safe(ibm
, itmp
,
853 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
855 struct ibm_struct
*ibm
, *itmp
;
857 list_for_each_entry_safe(ibm
, itmp
,
865 static struct platform_driver tpacpi_pdriver
= {
867 .name
= TPACPI_DRVR_NAME
,
868 .owner
= THIS_MODULE
,
870 .suspend
= tpacpi_suspend_handler
,
871 .resume
= tpacpi_resume_handler
,
872 .shutdown
= tpacpi_shutdown_handler
,
875 static struct platform_driver tpacpi_hwmon_pdriver
= {
877 .name
= TPACPI_HWMON_DRVR_NAME
,
878 .owner
= THIS_MODULE
,
882 /*************************************************************************
883 * sysfs support helpers
886 struct attribute_set
{
887 unsigned int members
, max_members
;
888 struct attribute_group group
;
891 struct attribute_set_obj
{
892 struct attribute_set s
;
894 } __attribute__((packed
));
896 static struct attribute_set
*create_attr_set(unsigned int max_members
,
899 struct attribute_set_obj
*sobj
;
901 if (max_members
== 0)
904 /* Allocates space for implicit NULL at the end too */
905 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
906 max_members
* sizeof(struct attribute
*),
910 sobj
->s
.max_members
= max_members
;
911 sobj
->s
.group
.attrs
= &sobj
->a
;
912 sobj
->s
.group
.name
= name
;
917 #define destroy_attr_set(_set) \
920 /* not multi-threaded safe, use it in a single thread per set */
921 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
926 if (s
->members
>= s
->max_members
)
929 s
->group
.attrs
[s
->members
] = attr
;
935 static int add_many_to_attr_set(struct attribute_set
*s
,
936 struct attribute
**attr
,
941 for (i
= 0; i
< count
; i
++) {
942 res
= add_to_attr_set(s
, attr
[i
]);
950 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
952 sysfs_remove_group(kobj
, &s
->group
);
956 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
957 sysfs_create_group(_kobj, &_attr_set->group)
959 static int parse_strtoul(const char *buf
,
960 unsigned long max
, unsigned long *value
)
964 while (*buf
&& isspace(*buf
))
966 *value
= simple_strtoul(buf
, &endp
, 0);
967 while (*endp
&& isspace(*endp
))
969 if (*endp
|| *value
> max
)
975 static void tpacpi_disable_brightness_delay(void)
977 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
979 "ACPI backlight control delay disabled\n");
982 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
984 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
985 union acpi_object
*obj
;
988 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
989 obj
= (union acpi_object
*)buffer
.pointer
;
990 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
991 printk(TPACPI_ERR
"Unknown _BCL data, "
992 "please report this to %s\n", TPACPI_MAIL
);
995 rc
= obj
->package
.count
;
1001 kfree(buffer
.pointer
);
1005 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1006 u32 lvl
, void *context
, void **rv
)
1008 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1009 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1011 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1012 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1013 BUG_ON(!rv
|| !*rv
);
1014 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1015 return AE_CTRL_TERMINATE
;
1022 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1024 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1028 void *bcl_ptr
= &bcl_levels
;
1031 TPACPI_ACPIHANDLE_INIT(vid
);
1037 * Search for a _BCL method, and execute it. This is safe on all
1038 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1039 * BIOS in ACPI backlight control mode. We do NOT have to care
1040 * about calling the _BCL method in an enabled video device, any
1041 * will do for our purposes.
1044 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1045 tpacpi_acpi_walk_find_bcl
, NULL
,
1048 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1049 tp_features
.bright_acpimode
= 1;
1050 return (bcl_levels
- 2);
1056 static void printk_deprecated_attribute(const char * const what
,
1057 const char * const details
)
1059 tpacpi_log_usertask("deprecated sysfs attribute");
1060 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1061 "will be removed. %s\n",
1065 /*************************************************************************
1066 * rfkill and radio control support helpers
1070 * ThinkPad-ACPI firmware handling model:
1072 * WLSW (master wireless switch) is event-driven, and is common to all
1073 * firmware-controlled radios. It cannot be controlled, just monitored,
1074 * as expected. It overrides all radio state in firmware
1076 * The kernel, a masked-off hotkey, and WLSW can change the radio state
1077 * (TODO: verify how WLSW interacts with the returned radio state).
1079 * The only time there are shadow radio state changes, is when
1080 * masked-off hotkeys are used.
1084 * Internal driver API for radio state:
1086 * int: < 0 = error, otherwise enum tpacpi_rfkill_state
1087 * bool: true means radio blocked (off)
1089 enum tpacpi_rfkill_state
{
1090 TPACPI_RFK_RADIO_OFF
= 0,
1094 /* rfkill switches */
1095 enum tpacpi_rfk_id
{
1096 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
1097 TPACPI_RFK_WWAN_SW_ID
,
1098 TPACPI_RFK_UWB_SW_ID
,
1102 static const char *tpacpi_rfkill_names
[] = {
1103 [TPACPI_RFK_BLUETOOTH_SW_ID
] = "bluetooth",
1104 [TPACPI_RFK_WWAN_SW_ID
] = "wwan",
1105 [TPACPI_RFK_UWB_SW_ID
] = "uwb",
1106 [TPACPI_RFK_SW_MAX
] = NULL
1109 /* ThinkPad-ACPI rfkill subdriver */
1111 struct rfkill
*rfkill
;
1112 enum tpacpi_rfk_id id
;
1113 const struct tpacpi_rfk_ops
*ops
;
1116 struct tpacpi_rfk_ops
{
1117 /* firmware interface */
1118 int (*get_status
)(void);
1119 int (*set_status
)(const enum tpacpi_rfkill_state
);
1122 static struct tpacpi_rfk
*tpacpi_rfkill_switches
[TPACPI_RFK_SW_MAX
];
1124 /* Query FW and update rfkill sw state for a given rfkill switch */
1125 static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk
*tp_rfk
)
1132 status
= (tp_rfk
->ops
->get_status
)();
1136 rfkill_set_sw_state(tp_rfk
->rfkill
,
1137 (status
== TPACPI_RFK_RADIO_OFF
));
1142 /* Query FW and update rfkill sw state for all rfkill switches */
1143 static void tpacpi_rfk_update_swstate_all(void)
1147 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++)
1148 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[i
]);
1152 * Sync the HW-blocking state of all rfkill switches,
1153 * do notice it causes the rfkill core to schedule uevents
1155 static void tpacpi_rfk_update_hwblock_state(bool blocked
)
1158 struct tpacpi_rfk
*tp_rfk
;
1160 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++) {
1161 tp_rfk
= tpacpi_rfkill_switches
[i
];
1163 if (rfkill_set_hw_state(tp_rfk
->rfkill
,
1165 /* ignore -- we track sw block */
1171 /* Call to get the WLSW state from the firmware */
1172 static int hotkey_get_wlsw(void);
1174 /* Call to query WLSW state and update all rfkill switches */
1175 static bool tpacpi_rfk_check_hwblock_state(void)
1177 int res
= hotkey_get_wlsw();
1180 /* When unknown or unsupported, we have to assume it is unblocked */
1184 hw_blocked
= (res
== TPACPI_RFK_RADIO_OFF
);
1185 tpacpi_rfk_update_hwblock_state(hw_blocked
);
1190 static int tpacpi_rfk_hook_set_block(void *data
, bool blocked
)
1192 struct tpacpi_rfk
*tp_rfk
= data
;
1195 dbg_printk(TPACPI_DBG_RFKILL
,
1196 "request to change radio state to %s\n",
1197 blocked
? "blocked" : "unblocked");
1199 /* try to set radio state */
1200 res
= (tp_rfk
->ops
->set_status
)(blocked
?
1201 TPACPI_RFK_RADIO_OFF
: TPACPI_RFK_RADIO_ON
);
1203 /* and update the rfkill core with whatever the FW really did */
1204 tpacpi_rfk_update_swstate(tp_rfk
);
1206 return (res
< 0) ? res
: 0;
1209 static const struct rfkill_ops tpacpi_rfk_rfkill_ops
= {
1210 .set_block
= tpacpi_rfk_hook_set_block
,
1213 static int __init
tpacpi_new_rfkill(const enum tpacpi_rfk_id id
,
1214 const struct tpacpi_rfk_ops
*tp_rfkops
,
1215 const enum rfkill_type rfktype
,
1217 const bool set_default
)
1219 struct tpacpi_rfk
*atp_rfk
;
1221 bool sw_state
= false;
1224 BUG_ON(id
>= TPACPI_RFK_SW_MAX
|| tpacpi_rfkill_switches
[id
]);
1226 atp_rfk
= kzalloc(sizeof(struct tpacpi_rfk
), GFP_KERNEL
);
1228 atp_rfk
->rfkill
= rfkill_alloc(name
,
1231 &tpacpi_rfk_rfkill_ops
,
1233 if (!atp_rfk
|| !atp_rfk
->rfkill
) {
1235 "failed to allocate memory for rfkill class\n");
1241 atp_rfk
->ops
= tp_rfkops
;
1243 sw_status
= (tp_rfkops
->get_status
)();
1244 if (sw_status
< 0) {
1246 "failed to read initial state for %s, error %d\n",
1249 sw_state
= (sw_status
== TPACPI_RFK_RADIO_OFF
);
1251 /* try to keep the initial state, since we ask the
1252 * firmware to preserve it across S5 in NVRAM */
1253 rfkill_init_sw_state(atp_rfk
->rfkill
, sw_state
);
1256 rfkill_set_hw_state(atp_rfk
->rfkill
, tpacpi_rfk_check_hwblock_state());
1258 res
= rfkill_register(atp_rfk
->rfkill
);
1261 "failed to register %s rfkill switch: %d\n",
1263 rfkill_destroy(atp_rfk
->rfkill
);
1268 tpacpi_rfkill_switches
[id
] = atp_rfk
;
1272 static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id
)
1274 struct tpacpi_rfk
*tp_rfk
;
1276 BUG_ON(id
>= TPACPI_RFK_SW_MAX
);
1278 tp_rfk
= tpacpi_rfkill_switches
[id
];
1280 rfkill_unregister(tp_rfk
->rfkill
);
1281 rfkill_destroy(tp_rfk
->rfkill
);
1282 tpacpi_rfkill_switches
[id
] = NULL
;
1287 static void printk_deprecated_rfkill_attribute(const char * const what
)
1289 printk_deprecated_attribute(what
,
1290 "Please switch to generic rfkill before year 2010");
1293 /* sysfs <radio> enable ------------------------------------------------ */
1294 static ssize_t
tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id
,
1295 struct device_attribute
*attr
,
1300 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1302 /* This is in the ABI... */
1303 if (tpacpi_rfk_check_hwblock_state()) {
1304 status
= TPACPI_RFK_RADIO_OFF
;
1306 status
= tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1311 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1312 (status
== TPACPI_RFK_RADIO_ON
) ? 1 : 0);
1315 static ssize_t
tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id
,
1316 struct device_attribute
*attr
,
1317 const char *buf
, size_t count
)
1322 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1324 if (parse_strtoul(buf
, 1, &t
))
1327 tpacpi_disclose_usertask(attr
->attr
.name
, "set to %ld\n", t
);
1329 /* This is in the ABI... */
1330 if (tpacpi_rfk_check_hwblock_state() && !!t
)
1333 res
= tpacpi_rfkill_switches
[id
]->ops
->set_status((!!t
) ?
1334 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
);
1335 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1337 return (res
< 0) ? res
: count
;
1340 /* procfs -------------------------------------------------------------- */
1341 static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id
, char *p
)
1345 if (id
>= TPACPI_RFK_SW_MAX
)
1346 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1350 /* This is in the ABI... */
1351 if (tpacpi_rfk_check_hwblock_state()) {
1352 status
= TPACPI_RFK_RADIO_OFF
;
1354 status
= tpacpi_rfk_update_swstate(
1355 tpacpi_rfkill_switches
[id
]);
1360 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1361 (status
== TPACPI_RFK_RADIO_ON
) ?
1362 "enabled" : "disabled");
1363 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1369 static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id
, char *buf
)
1375 if (id
>= TPACPI_RFK_SW_MAX
)
1378 while ((cmd
= next_cmd(&buf
))) {
1379 if (strlencmp(cmd
, "enable") == 0)
1380 status
= TPACPI_RFK_RADIO_ON
;
1381 else if (strlencmp(cmd
, "disable") == 0)
1382 status
= TPACPI_RFK_RADIO_OFF
;
1388 tpacpi_disclose_usertask("procfs", "attempt to %s %s\n",
1389 (status
== TPACPI_RFK_RADIO_ON
) ?
1390 "enable" : "disable",
1391 tpacpi_rfkill_names
[id
]);
1392 res
= (tpacpi_rfkill_switches
[id
]->ops
->set_status
)(status
);
1393 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1399 /*************************************************************************
1400 * thinkpad-acpi driver attributes
1403 /* interface_version --------------------------------------------------- */
1404 static ssize_t
tpacpi_driver_interface_version_show(
1405 struct device_driver
*drv
,
1408 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1411 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1412 tpacpi_driver_interface_version_show
, NULL
);
1414 /* debug_level --------------------------------------------------------- */
1415 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1418 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1421 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1422 const char *buf
, size_t count
)
1426 if (parse_strtoul(buf
, 0xffff, &t
))
1434 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1435 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1437 /* version ------------------------------------------------------------- */
1438 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1441 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1442 TPACPI_DESC
, TPACPI_VERSION
);
1445 static DRIVER_ATTR(version
, S_IRUGO
,
1446 tpacpi_driver_version_show
, NULL
);
1448 /* --------------------------------------------------------------------- */
1450 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1452 /* wlsw_emulstate ------------------------------------------------------ */
1453 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1456 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1459 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1460 const char *buf
, size_t count
)
1464 if (parse_strtoul(buf
, 1, &t
))
1467 if (tpacpi_wlsw_emulstate
!= !!t
) {
1468 tpacpi_wlsw_emulstate
= !!t
;
1469 tpacpi_rfk_update_hwblock_state(!t
); /* negative logic */
1475 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1476 tpacpi_driver_wlsw_emulstate_show
,
1477 tpacpi_driver_wlsw_emulstate_store
);
1479 /* bluetooth_emulstate ------------------------------------------------- */
1480 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1481 struct device_driver
*drv
,
1484 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1487 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1488 struct device_driver
*drv
,
1489 const char *buf
, size_t count
)
1493 if (parse_strtoul(buf
, 1, &t
))
1496 tpacpi_bluetooth_emulstate
= !!t
;
1501 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1502 tpacpi_driver_bluetooth_emulstate_show
,
1503 tpacpi_driver_bluetooth_emulstate_store
);
1505 /* wwan_emulstate ------------------------------------------------- */
1506 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1507 struct device_driver
*drv
,
1510 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1513 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1514 struct device_driver
*drv
,
1515 const char *buf
, size_t count
)
1519 if (parse_strtoul(buf
, 1, &t
))
1522 tpacpi_wwan_emulstate
= !!t
;
1527 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1528 tpacpi_driver_wwan_emulstate_show
,
1529 tpacpi_driver_wwan_emulstate_store
);
1531 /* uwb_emulstate ------------------------------------------------- */
1532 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1533 struct device_driver
*drv
,
1536 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1539 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1540 struct device_driver
*drv
,
1541 const char *buf
, size_t count
)
1545 if (parse_strtoul(buf
, 1, &t
))
1548 tpacpi_uwb_emulstate
= !!t
;
1553 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1554 tpacpi_driver_uwb_emulstate_show
,
1555 tpacpi_driver_uwb_emulstate_store
);
1558 /* --------------------------------------------------------------------- */
1560 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1561 &driver_attr_debug_level
, &driver_attr_version
,
1562 &driver_attr_interface_version
,
1565 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1571 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1572 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1576 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1577 if (!res
&& dbg_wlswemul
)
1578 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1579 if (!res
&& dbg_bluetoothemul
)
1580 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1581 if (!res
&& dbg_wwanemul
)
1582 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1583 if (!res
&& dbg_uwbemul
)
1584 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1590 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1594 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1595 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1597 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1598 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1599 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1600 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1601 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1605 /*************************************************************************
1610 * Table of recommended minimum BIOS versions
1612 * Reasons for listing:
1613 * 1. Stable BIOS, listed because the unknown ammount of
1614 * bugs and bad ACPI behaviour on older versions
1616 * 2. BIOS or EC fw with known bugs that trigger on Linux
1618 * 3. BIOS with known reduced functionality in older versions
1620 * We recommend the latest BIOS and EC version.
1621 * We only support the latest BIOS and EC fw version as a rule.
1623 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1624 * Information from users in ThinkWiki
1626 * WARNING: we use this table also to detect that the machine is
1627 * a ThinkPad in some cases, so don't remove entries lightly.
1630 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1631 { .vendor = (__v), \
1632 .bios = TPID(__id1, __id2), \
1633 .ec = TPACPI_MATCH_ANY, \
1634 .quirks = TPACPI_MATCH_ANY << 16 \
1635 | (__bv1) << 8 | (__bv2) }
1637 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1638 __eid1, __eid2, __ev1, __ev2) \
1639 { .vendor = (__v), \
1640 .bios = TPID(__bid1, __bid2), \
1641 .ec = TPID(__eid1, __eid2), \
1642 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1643 | (__bv1) << 8 | (__bv2) }
1645 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1646 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1648 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1649 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1650 __bv1, __bv2, __id1, __id2, __ev1, __ev2)
1652 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1653 __eid1, __eid2, __ev1, __ev2) \
1654 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1655 __bv1, __bv2, __eid1, __eid2, __ev1, __ev2)
1657 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1658 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1660 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1661 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1662 __bv1, __bv2, __id1, __id2, __ev1, __ev2)
1664 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1665 __eid1, __eid2, __ev1, __ev2) \
1666 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1667 __bv1, __bv2, __eid1, __eid2, __ev1, __ev2)
1669 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1670 /* Numeric models ------------------ */
1671 /* FW MODEL BIOS VERS */
1672 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1673 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1674 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1675 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1676 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1677 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1678 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1679 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1680 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1682 /* A-series ------------------------- */
1683 /* FW MODEL BIOS VERS EC VERS */
1684 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1685 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1686 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1687 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1688 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1689 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1690 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1691 TPV_QI0('1', '3', '2', '0'), /* A22m */
1692 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1693 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1694 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1696 /* G-series ------------------------- */
1697 /* FW MODEL BIOS VERS */
1698 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1699 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1701 /* R-series, T-series --------------- */
1702 /* FW MODEL BIOS VERS EC VERS */
1703 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1704 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1705 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1706 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1707 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1708 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1709 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1710 T40/p, T41/p, T42/p (1) */
1711 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1712 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1713 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1714 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1716 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1717 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1718 TPV_QI0('1', '6', '3', '2'), /* T22 */
1719 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1720 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1721 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1723 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1724 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1725 TPV_QL0('7', 'E', 'D', '0'), /* R60e, R60i */
1727 /* BIOS FW BIOS VERS EC FW EC VERS */
1728 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1729 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1731 /* X-series ------------------------- */
1732 /* FW MODEL BIOS VERS EC VERS */
1733 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1734 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1735 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1736 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1737 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1738 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1739 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1741 TPV_QL0('7', 'B', 'D', '7'), /* X60/s */
1742 TPV_QL0('7', 'J', '3', '0'), /* X60t */
1744 /* (0) - older versions lack DMI EC fw string and functionality */
1745 /* (1) - older versions known to lack functionality */
1756 static void __init
tpacpi_check_outdated_fw(void)
1758 unsigned long fwvers
;
1759 u16 ec_version
, bios_version
;
1761 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1762 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1767 bios_version
= fwvers
& 0xffffU
;
1768 ec_version
= (fwvers
>> 16) & 0xffffU
;
1770 /* note that unknown versions are set to 0x0000 and we use that */
1771 if ((bios_version
> thinkpad_id
.bios_release
) ||
1772 (ec_version
> thinkpad_id
.ec_release
&&
1773 ec_version
!= TPACPI_MATCH_ANY
)) {
1775 * The changelogs would let us track down the exact
1776 * reason, but it is just too much of a pain to track
1777 * it. We only list BIOSes that are either really
1778 * broken, or really stable to begin with, so it is
1779 * best if the user upgrades the firmware anyway.
1782 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1784 "WARNING: This firmware may be missing critical bug "
1785 "fixes and/or important features\n");
1789 static bool __init
tpacpi_is_fw_known(void)
1791 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1792 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1795 /****************************************************************************
1796 ****************************************************************************
1800 ****************************************************************************
1801 ****************************************************************************/
1803 /*************************************************************************
1804 * thinkpad-acpi init subdriver
1807 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1809 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1810 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1812 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1813 (thinkpad_id
.bios_version_str
) ?
1814 thinkpad_id
.bios_version_str
: "unknown",
1815 (thinkpad_id
.ec_version_str
) ?
1816 thinkpad_id
.ec_version_str
: "unknown");
1818 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1819 printk(TPACPI_INFO
"%s %s, model %s\n",
1820 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1821 "IBM" : ((thinkpad_id
.vendor
==
1822 PCI_VENDOR_ID_LENOVO
) ?
1823 "Lenovo" : "Unknown vendor"),
1824 thinkpad_id
.model_str
,
1825 (thinkpad_id
.nummodel_str
) ?
1826 thinkpad_id
.nummodel_str
: "unknown");
1828 tpacpi_check_outdated_fw();
1832 static int thinkpad_acpi_driver_read(char *p
)
1836 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1837 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1842 static struct ibm_struct thinkpad_acpi_driver_data
= {
1844 .read
= thinkpad_acpi_driver_read
,
1847 /*************************************************************************
1852 * ThinkPad firmware event model
1854 * The ThinkPad firmware has two main event interfaces: normal ACPI
1855 * notifications (which follow the ACPI standard), and a private event
1858 * The private event interface also issues events for the hotkeys. As
1859 * the driver gained features, the event handling code ended up being
1860 * built around the hotkey subdriver. This will need to be refactored
1861 * to a more formal event API eventually.
1863 * Some "hotkeys" are actually supposed to be used as event reports,
1864 * such as "brightness has changed", "volume has changed", depending on
1865 * the ThinkPad model and how the firmware is operating.
1867 * Unlike other classes, hotkey-class events have mask/unmask control on
1868 * non-ancient firmware. However, how it behaves changes a lot with the
1869 * firmware model and version.
1872 enum { /* hot key scan codes (derived from ACPI DSDT) */
1873 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1874 TP_ACPI_HOTKEYSCAN_FNF2
,
1875 TP_ACPI_HOTKEYSCAN_FNF3
,
1876 TP_ACPI_HOTKEYSCAN_FNF4
,
1877 TP_ACPI_HOTKEYSCAN_FNF5
,
1878 TP_ACPI_HOTKEYSCAN_FNF6
,
1879 TP_ACPI_HOTKEYSCAN_FNF7
,
1880 TP_ACPI_HOTKEYSCAN_FNF8
,
1881 TP_ACPI_HOTKEYSCAN_FNF9
,
1882 TP_ACPI_HOTKEYSCAN_FNF10
,
1883 TP_ACPI_HOTKEYSCAN_FNF11
,
1884 TP_ACPI_HOTKEYSCAN_FNF12
,
1885 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1886 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1887 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1888 TP_ACPI_HOTKEYSCAN_FNHOME
,
1889 TP_ACPI_HOTKEYSCAN_FNEND
,
1890 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1891 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1892 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1893 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1894 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1895 TP_ACPI_HOTKEYSCAN_MUTE
,
1896 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1899 enum { /* Keys/events available through NVRAM polling */
1900 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1901 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1904 enum { /* Positions of some of the keys in hotkey masks */
1905 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1906 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1907 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1908 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1909 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1910 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1911 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1912 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1913 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1914 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1915 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1918 enum { /* NVRAM to ACPI HKEY group map */
1919 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1920 TP_ACPI_HKEY_ZOOM_MASK
|
1921 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1922 TP_ACPI_HKEY_HIBERNATE_MASK
,
1923 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1924 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1925 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1926 TP_ACPI_HKEY_VOLDWN_MASK
|
1927 TP_ACPI_HKEY_MUTE_MASK
,
1930 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1931 struct tp_nvram_state
{
1932 u16 thinkpad_toggle
:1;
1934 u16 display_toggle
:1;
1935 u16 thinklight_toggle
:1;
1936 u16 hibernate_toggle
:1;
1937 u16 displayexp_toggle
:1;
1938 u16 display_state
:1;
1939 u16 brightness_toggle
:1;
1940 u16 volume_toggle
:1;
1943 u8 brightness_level
;
1947 /* kthread for the hotkey poller */
1948 static struct task_struct
*tpacpi_hotkey_task
;
1950 /* Acquired while the poller kthread is running, use to sync start/stop */
1951 static struct mutex hotkey_thread_mutex
;
1954 * Acquire mutex to write poller control variables as an
1957 * Increment hotkey_config_change when changing them if you
1958 * want the kthread to forget old state.
1960 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1962 static struct mutex hotkey_thread_data_mutex
;
1963 static unsigned int hotkey_config_change
;
1966 * hotkey poller control variables
1968 * Must be atomic or readers will also need to acquire mutex
1970 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
1971 * should be used only when the changes need to be taken as
1972 * a block, OR when one needs to force the kthread to forget
1975 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1976 static unsigned int hotkey_poll_freq
= 10; /* Hz */
1978 #define HOTKEY_CONFIG_CRITICAL_START \
1980 mutex_lock(&hotkey_thread_data_mutex); \
1981 hotkey_config_change++; \
1983 #define HOTKEY_CONFIG_CRITICAL_END \
1984 mutex_unlock(&hotkey_thread_data_mutex);
1986 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1988 #define hotkey_source_mask 0U
1989 #define HOTKEY_CONFIG_CRITICAL_START
1990 #define HOTKEY_CONFIG_CRITICAL_END
1992 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1994 static struct mutex hotkey_mutex
;
1996 static enum { /* Reasons for waking up */
1997 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1998 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1999 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
2000 } hotkey_wakeup_reason
;
2002 static int hotkey_autosleep_ack
;
2004 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
2005 static u32 hotkey_all_mask
; /* all events supported in fw */
2006 static u32 hotkey_reserved_mask
; /* events better left disabled */
2007 static u32 hotkey_driver_mask
; /* events needed by the driver */
2008 static u32 hotkey_user_mask
; /* events visible to userspace */
2009 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
2011 static unsigned int hotkey_report_mode
;
2013 static u16
*hotkey_keycode_map
;
2015 static struct attribute_set
*hotkey_dev_attributes
;
2017 /* HKEY.MHKG() return bits */
2018 #define TP_HOTKEY_TABLET_MASK (1 << 3)
2020 static int hotkey_get_wlsw(void)
2024 if (!tp_features
.hotkey_wlsw
)
2027 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2029 return (tpacpi_wlsw_emulstate
) ?
2030 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2033 if (!acpi_evalf(hkey_handle
, &status
, "WLSW", "d"))
2036 return (status
) ? TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2039 static int hotkey_get_tablet_mode(int *status
)
2043 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
2046 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
2051 * Reads current event mask from firmware, and updates
2052 * hotkey_acpi_mask accordingly. Also resets any bits
2053 * from hotkey_user_mask that are unavailable to be
2054 * delivered (shadow requirement of the userspace ABI).
2056 * Call with hotkey_mutex held
2058 static int hotkey_mask_get(void)
2060 if (tp_features
.hotkey_mask
) {
2063 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
2066 hotkey_acpi_mask
= m
;
2068 /* no mask support doesn't mean no event support... */
2069 hotkey_acpi_mask
= hotkey_all_mask
;
2072 /* sync userspace-visible mask */
2073 hotkey_user_mask
&= (hotkey_acpi_mask
| hotkey_source_mask
);
2078 void static hotkey_mask_warn_incomplete_mask(void)
2080 /* log only what the user can fix... */
2081 const u32 wantedmask
= hotkey_driver_mask
&
2082 ~(hotkey_acpi_mask
| hotkey_source_mask
) &
2083 (hotkey_all_mask
| TPACPI_HKEY_NVRAM_KNOWN_MASK
);
2086 printk(TPACPI_NOTICE
2087 "required events 0x%08x not enabled!\n",
2092 * Set the firmware mask when supported
2094 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
2096 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
2098 * Call with hotkey_mutex held
2100 static int hotkey_mask_set(u32 mask
)
2105 const u32 fwmask
= mask
& ~hotkey_source_mask
;
2107 if (tp_features
.hotkey_mask
) {
2108 for (i
= 0; i
< 32; i
++) {
2109 if (!acpi_evalf(hkey_handle
,
2110 NULL
, "MHKM", "vdd", i
+ 1,
2111 !!(mask
& (1 << i
)))) {
2119 * We *must* make an inconditional call to hotkey_mask_get to
2120 * refresh hotkey_acpi_mask and update hotkey_user_mask
2122 * Take the opportunity to also log when we cannot _enable_
2125 if (!hotkey_mask_get() && !rc
&& (fwmask
& ~hotkey_acpi_mask
)) {
2126 printk(TPACPI_NOTICE
2127 "asked for hotkey mask 0x%08x, but "
2128 "firmware forced it to 0x%08x\n",
2129 fwmask
, hotkey_acpi_mask
);
2132 hotkey_mask_warn_incomplete_mask();
2138 * Sets hotkey_user_mask and tries to set the firmware mask
2140 * Call with hotkey_mutex held
2142 static int hotkey_user_mask_set(const u32 mask
)
2146 /* Give people a chance to notice they are doing something that
2147 * is bound to go boom on their users sooner or later */
2148 if (!tp_warned
.hotkey_mask_ff
&&
2149 (mask
== 0xffff || mask
== 0xffffff ||
2150 mask
== 0xffffffff)) {
2151 tp_warned
.hotkey_mask_ff
= 1;
2152 printk(TPACPI_NOTICE
2153 "setting the hotkey mask to 0x%08x is likely "
2154 "not the best way to go about it\n", mask
);
2155 printk(TPACPI_NOTICE
2156 "please consider using the driver defaults, "
2157 "and refer to up-to-date thinkpad-acpi "
2161 /* Try to enable what the user asked for, plus whatever we need.
2162 * this syncs everything but won't enable bits in hotkey_user_mask */
2163 rc
= hotkey_mask_set((mask
| hotkey_driver_mask
) & ~hotkey_source_mask
);
2165 /* Enable the available bits in hotkey_user_mask */
2166 hotkey_user_mask
= mask
& (hotkey_acpi_mask
| hotkey_source_mask
);
2171 static int hotkey_status_get(int *status
)
2173 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
2179 static int hotkey_status_set(bool enable
)
2181 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
2187 static void tpacpi_input_send_tabletsw(void)
2191 if (tp_features
.hotkey_tablet
&&
2192 !hotkey_get_tablet_mode(&state
)) {
2193 mutex_lock(&tpacpi_inputdev_send_mutex
);
2195 input_report_switch(tpacpi_inputdev
,
2196 SW_TABLET_MODE
, !!state
);
2197 input_sync(tpacpi_inputdev
);
2199 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2203 /* Do NOT call without validating scancode first */
2204 static void tpacpi_input_send_key(const unsigned int scancode
)
2206 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
2208 if (keycode
!= KEY_RESERVED
) {
2209 mutex_lock(&tpacpi_inputdev_send_mutex
);
2211 input_report_key(tpacpi_inputdev
, keycode
, 1);
2212 if (keycode
== KEY_UNKNOWN
)
2213 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2215 input_sync(tpacpi_inputdev
);
2217 input_report_key(tpacpi_inputdev
, keycode
, 0);
2218 if (keycode
== KEY_UNKNOWN
)
2219 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2221 input_sync(tpacpi_inputdev
);
2223 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2227 /* Do NOT call without validating scancode first */
2228 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
2230 if (hotkey_user_mask
& (1 << scancode
))
2231 tpacpi_input_send_key(scancode
);
2234 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2235 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2237 /* Do NOT call without validating scancode first */
2238 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2240 tpacpi_input_send_key_masked(scancode
);
2241 if (hotkey_report_mode
< 2) {
2242 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2243 0x80, 0x1001 + scancode
);
2247 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2251 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2252 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2253 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2254 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2255 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2256 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2258 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2259 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2260 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2262 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2263 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2264 n
->displayexp_toggle
=
2265 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2267 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2268 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2269 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2270 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2271 n
->brightness_toggle
=
2272 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2274 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2275 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2276 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2277 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2278 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2279 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2283 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2284 struct tp_nvram_state
*newn
,
2285 const u32 event_mask
)
2288 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2290 if ((event_mask & (1 << __scancode)) && \
2291 oldn->__member != newn->__member) \
2292 tpacpi_hotkey_send_key(__scancode); \
2295 #define TPACPI_MAY_SEND_KEY(__scancode) \
2297 if (event_mask & (1 << __scancode)) \
2298 tpacpi_hotkey_send_key(__scancode); \
2301 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2302 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2303 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2304 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2306 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2308 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2311 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2312 if (oldn
->mute
!= newn
->mute
) {
2313 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2315 if (oldn
->volume_level
> newn
->volume_level
) {
2316 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2317 } else if (oldn
->volume_level
< newn
->volume_level
) {
2318 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2319 } else if (oldn
->mute
== newn
->mute
) {
2320 /* repeated key presses that didn't change state */
2322 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2323 } else if (newn
->volume_level
!= 0) {
2324 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2326 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2331 /* handle brightness */
2332 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2333 if (oldn
->brightness_level
< newn
->brightness_level
) {
2334 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2335 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
2336 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2338 /* repeated key presses that didn't change state */
2339 if (newn
->brightness_level
!= 0) {
2340 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2342 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2347 #undef TPACPI_COMPARE_KEY
2348 #undef TPACPI_MAY_SEND_KEY
2354 * We track all events in hotkey_source_mask all the time, since
2355 * most of them are edge-based. We only issue those requested by
2356 * hotkey_user_mask or hotkey_driver_mask, though.
2358 static int hotkey_kthread(void *data
)
2360 struct tp_nvram_state s
[2];
2361 u32 poll_mask
, event_mask
;
2362 unsigned int si
, so
;
2364 unsigned int change_detector
, must_reset
;
2365 unsigned int poll_freq
;
2367 mutex_lock(&hotkey_thread_mutex
);
2369 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2378 /* Initial state for compares */
2379 mutex_lock(&hotkey_thread_data_mutex
);
2380 change_detector
= hotkey_config_change
;
2381 poll_mask
= hotkey_source_mask
;
2382 event_mask
= hotkey_source_mask
&
2383 (hotkey_driver_mask
| hotkey_user_mask
);
2384 poll_freq
= hotkey_poll_freq
;
2385 mutex_unlock(&hotkey_thread_data_mutex
);
2386 hotkey_read_nvram(&s
[so
], poll_mask
);
2388 while (!kthread_should_stop()) {
2390 if (likely(poll_freq
))
2393 t
= 100; /* should never happen... */
2395 t
= msleep_interruptible(t
);
2396 if (unlikely(kthread_should_stop()))
2398 must_reset
= try_to_freeze();
2399 if (t
> 0 && !must_reset
)
2402 mutex_lock(&hotkey_thread_data_mutex
);
2403 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2404 /* forget old state on thaw or config change */
2407 change_detector
= hotkey_config_change
;
2409 poll_mask
= hotkey_source_mask
;
2410 event_mask
= hotkey_source_mask
&
2411 (hotkey_driver_mask
| hotkey_user_mask
);
2412 poll_freq
= hotkey_poll_freq
;
2413 mutex_unlock(&hotkey_thread_data_mutex
);
2415 if (likely(poll_mask
)) {
2416 hotkey_read_nvram(&s
[si
], poll_mask
);
2417 if (likely(si
!= so
)) {
2418 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2428 mutex_unlock(&hotkey_thread_mutex
);
2432 /* call with hotkey_mutex held */
2433 static void hotkey_poll_stop_sync(void)
2435 if (tpacpi_hotkey_task
) {
2436 if (frozen(tpacpi_hotkey_task
) ||
2437 freezing(tpacpi_hotkey_task
))
2438 thaw_process(tpacpi_hotkey_task
);
2440 kthread_stop(tpacpi_hotkey_task
);
2441 tpacpi_hotkey_task
= NULL
;
2442 mutex_lock(&hotkey_thread_mutex
);
2443 /* at this point, the thread did exit */
2444 mutex_unlock(&hotkey_thread_mutex
);
2448 /* call with hotkey_mutex held */
2449 static void hotkey_poll_setup(bool may_warn
)
2451 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2452 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2454 if (hotkey_poll_freq
> 0 &&
2455 (poll_driver_mask
||
2456 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2457 if (!tpacpi_hotkey_task
) {
2458 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2459 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2460 if (IS_ERR(tpacpi_hotkey_task
)) {
2461 tpacpi_hotkey_task
= NULL
;
2463 "could not create kernel thread "
2464 "for hotkey polling\n");
2468 hotkey_poll_stop_sync();
2469 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2470 hotkey_poll_freq
== 0) {
2471 printk(TPACPI_NOTICE
2472 "hot keys 0x%08x and/or events 0x%08x "
2473 "require polling, which is currently "
2475 poll_user_mask
, poll_driver_mask
);
2480 static void hotkey_poll_setup_safe(bool may_warn
)
2482 mutex_lock(&hotkey_mutex
);
2483 hotkey_poll_setup(may_warn
);
2484 mutex_unlock(&hotkey_mutex
);
2487 /* call with hotkey_mutex held */
2488 static void hotkey_poll_set_freq(unsigned int freq
)
2491 hotkey_poll_stop_sync();
2493 hotkey_poll_freq
= freq
;
2496 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2498 static void hotkey_poll_setup_safe(bool __unused
)
2502 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2504 static int hotkey_inputdev_open(struct input_dev
*dev
)
2506 switch (tpacpi_lifecycle
) {
2507 case TPACPI_LIFE_INIT
:
2509 * hotkey_init will call hotkey_poll_setup_safe
2510 * at the appropriate moment
2513 case TPACPI_LIFE_EXITING
:
2515 case TPACPI_LIFE_RUNNING
:
2516 hotkey_poll_setup_safe(false);
2520 /* Should only happen if tpacpi_lifecycle is corrupt */
2525 static void hotkey_inputdev_close(struct input_dev
*dev
)
2527 /* disable hotkey polling when possible */
2528 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
&&
2529 !(hotkey_source_mask
& hotkey_driver_mask
))
2530 hotkey_poll_setup_safe(false);
2533 /* sysfs hotkey enable ------------------------------------------------- */
2534 static ssize_t
hotkey_enable_show(struct device
*dev
,
2535 struct device_attribute
*attr
,
2540 printk_deprecated_attribute("hotkey_enable",
2541 "Hotkey reporting is always enabled");
2543 res
= hotkey_status_get(&status
);
2547 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2550 static ssize_t
hotkey_enable_store(struct device
*dev
,
2551 struct device_attribute
*attr
,
2552 const char *buf
, size_t count
)
2556 printk_deprecated_attribute("hotkey_enable",
2557 "Hotkeys can be disabled through hotkey_mask");
2559 if (parse_strtoul(buf
, 1, &t
))
2568 static struct device_attribute dev_attr_hotkey_enable
=
2569 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2570 hotkey_enable_show
, hotkey_enable_store
);
2572 /* sysfs hotkey mask --------------------------------------------------- */
2573 static ssize_t
hotkey_mask_show(struct device
*dev
,
2574 struct device_attribute
*attr
,
2577 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2580 static ssize_t
hotkey_mask_store(struct device
*dev
,
2581 struct device_attribute
*attr
,
2582 const char *buf
, size_t count
)
2587 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2590 if (mutex_lock_killable(&hotkey_mutex
))
2591 return -ERESTARTSYS
;
2593 res
= hotkey_user_mask_set(t
);
2595 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2596 hotkey_poll_setup(true);
2599 mutex_unlock(&hotkey_mutex
);
2601 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2603 return (res
) ? res
: count
;
2606 static struct device_attribute dev_attr_hotkey_mask
=
2607 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2608 hotkey_mask_show
, hotkey_mask_store
);
2610 /* sysfs hotkey bios_enabled ------------------------------------------- */
2611 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2612 struct device_attribute
*attr
,
2615 return sprintf(buf
, "0\n");
2618 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2619 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2621 /* sysfs hotkey bios_mask ---------------------------------------------- */
2622 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2623 struct device_attribute
*attr
,
2626 printk_deprecated_attribute("hotkey_bios_mask",
2627 "This attribute is useless.");
2628 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2631 static struct device_attribute dev_attr_hotkey_bios_mask
=
2632 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2634 /* sysfs hotkey all_mask ----------------------------------------------- */
2635 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2636 struct device_attribute
*attr
,
2639 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2640 hotkey_all_mask
| hotkey_source_mask
);
2643 static struct device_attribute dev_attr_hotkey_all_mask
=
2644 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2646 /* sysfs hotkey recommended_mask --------------------------------------- */
2647 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2648 struct device_attribute
*attr
,
2651 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2652 (hotkey_all_mask
| hotkey_source_mask
)
2653 & ~hotkey_reserved_mask
);
2656 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2657 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2658 hotkey_recommended_mask_show
, NULL
);
2660 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2662 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2663 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2664 struct device_attribute
*attr
,
2667 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2670 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2671 struct device_attribute
*attr
,
2672 const char *buf
, size_t count
)
2678 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2679 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2682 if (mutex_lock_killable(&hotkey_mutex
))
2683 return -ERESTARTSYS
;
2685 HOTKEY_CONFIG_CRITICAL_START
2686 hotkey_source_mask
= t
;
2687 HOTKEY_CONFIG_CRITICAL_END
2689 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2690 ~hotkey_source_mask
);
2691 hotkey_poll_setup(true);
2693 /* check if events needed by the driver got disabled */
2694 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2695 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2697 mutex_unlock(&hotkey_mutex
);
2700 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2701 "firmware event mask!\n");
2704 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2705 "some important events were disabled: "
2708 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2710 return (rc
< 0) ? rc
: count
;
2713 static struct device_attribute dev_attr_hotkey_source_mask
=
2714 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2715 hotkey_source_mask_show
, hotkey_source_mask_store
);
2717 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2718 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2719 struct device_attribute
*attr
,
2722 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2725 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2726 struct device_attribute
*attr
,
2727 const char *buf
, size_t count
)
2731 if (parse_strtoul(buf
, 25, &t
))
2734 if (mutex_lock_killable(&hotkey_mutex
))
2735 return -ERESTARTSYS
;
2737 hotkey_poll_set_freq(t
);
2738 hotkey_poll_setup(true);
2740 mutex_unlock(&hotkey_mutex
);
2742 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2747 static struct device_attribute dev_attr_hotkey_poll_freq
=
2748 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2749 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2751 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2753 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2754 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2755 struct device_attribute
*attr
,
2759 res
= hotkey_get_wlsw();
2763 /* Opportunistic update */
2764 tpacpi_rfk_update_hwblock_state((res
== TPACPI_RFK_RADIO_OFF
));
2766 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2767 (res
== TPACPI_RFK_RADIO_OFF
) ? 0 : 1);
2770 static struct device_attribute dev_attr_hotkey_radio_sw
=
2771 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2773 static void hotkey_radio_sw_notify_change(void)
2775 if (tp_features
.hotkey_wlsw
)
2776 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2780 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2781 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2782 struct device_attribute
*attr
,
2786 res
= hotkey_get_tablet_mode(&s
);
2790 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2793 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2794 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2796 static void hotkey_tablet_mode_notify_change(void)
2798 if (tp_features
.hotkey_tablet
)
2799 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2800 "hotkey_tablet_mode");
2803 /* sysfs hotkey report_mode -------------------------------------------- */
2804 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2805 struct device_attribute
*attr
,
2808 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2809 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2812 static struct device_attribute dev_attr_hotkey_report_mode
=
2813 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2815 /* sysfs wakeup reason (pollable) -------------------------------------- */
2816 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2817 struct device_attribute
*attr
,
2820 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2823 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2824 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2826 static void hotkey_wakeup_reason_notify_change(void)
2828 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2832 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2833 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2834 struct device_attribute
*attr
,
2837 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2840 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2841 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2842 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2844 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2846 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2847 "wakeup_hotunplug_complete");
2850 /* --------------------------------------------------------------------- */
2852 static struct attribute
*hotkey_attributes
[] __initdata
= {
2853 &dev_attr_hotkey_enable
.attr
,
2854 &dev_attr_hotkey_bios_enabled
.attr
,
2855 &dev_attr_hotkey_bios_mask
.attr
,
2856 &dev_attr_hotkey_report_mode
.attr
,
2857 &dev_attr_hotkey_wakeup_reason
.attr
,
2858 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2859 &dev_attr_hotkey_mask
.attr
,
2860 &dev_attr_hotkey_all_mask
.attr
,
2861 &dev_attr_hotkey_recommended_mask
.attr
,
2862 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2863 &dev_attr_hotkey_source_mask
.attr
,
2864 &dev_attr_hotkey_poll_freq
.attr
,
2869 * Sync both the hw and sw blocking state of all switches
2871 static void tpacpi_send_radiosw_update(void)
2876 * We must sync all rfkill controllers *before* issuing any
2877 * rfkill input events, or we will race the rfkill core input
2880 * tpacpi_inputdev_send_mutex works as a syncronization point
2883 * We optimize to avoid numerous calls to hotkey_get_wlsw.
2886 wlsw
= hotkey_get_wlsw();
2888 /* Sync hw blocking state first if it is hw-blocked */
2889 if (wlsw
== TPACPI_RFK_RADIO_OFF
)
2890 tpacpi_rfk_update_hwblock_state(true);
2892 /* Sync sw blocking state */
2893 tpacpi_rfk_update_swstate_all();
2895 /* Sync hw blocking state last if it is hw-unblocked */
2896 if (wlsw
== TPACPI_RFK_RADIO_ON
)
2897 tpacpi_rfk_update_hwblock_state(false);
2899 /* Issue rfkill input event for WLSW switch */
2901 mutex_lock(&tpacpi_inputdev_send_mutex
);
2903 input_report_switch(tpacpi_inputdev
,
2904 SW_RFKILL_ALL
, (wlsw
> 0));
2905 input_sync(tpacpi_inputdev
);
2907 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2911 * this can be unconditional, as we will poll state again
2912 * if userspace uses the notify to read data
2914 hotkey_radio_sw_notify_change();
2917 static void hotkey_exit(void)
2919 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2920 mutex_lock(&hotkey_mutex
);
2921 hotkey_poll_stop_sync();
2922 mutex_unlock(&hotkey_mutex
);
2925 if (hotkey_dev_attributes
)
2926 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2928 kfree(hotkey_keycode_map
);
2930 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
2931 "restoring original HKEY status and mask\n");
2932 /* yes, there is a bitwise or below, we want the
2933 * functions to be called even if one of them fail */
2934 if (((tp_features
.hotkey_mask
&&
2935 hotkey_mask_set(hotkey_orig_mask
)) |
2936 hotkey_status_set(false)) != 0)
2938 "failed to restore hot key mask "
2939 "to BIOS defaults\n");
2942 static void __init
hotkey_unmap(const unsigned int scancode
)
2944 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
2945 clear_bit(hotkey_keycode_map
[scancode
],
2946 tpacpi_inputdev
->keybit
);
2947 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
2953 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
2956 #define TPACPI_HK_Q_INIMASK 0x0001
2958 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
2959 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
2960 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
2961 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
2962 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
2963 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
2964 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
2965 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
2966 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
2967 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
2968 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
2969 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
2970 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
2971 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
2972 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
2973 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
2974 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
2975 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
2976 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
2977 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
2980 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2982 /* Requirements for changing the default keymaps:
2984 * 1. Many of the keys are mapped to KEY_RESERVED for very
2985 * good reasons. Do not change them unless you have deep
2986 * knowledge on the IBM and Lenovo ThinkPad firmware for
2987 * the various ThinkPad models. The driver behaves
2988 * differently for KEY_RESERVED: such keys have their
2989 * hot key mask *unset* in mask_recommended, and also
2990 * in the initial hot key mask programmed into the
2991 * firmware at driver load time, which means the firm-
2992 * ware may react very differently if you change them to
2995 * 2. You must be subscribed to the linux-thinkpad and
2996 * ibm-acpi-devel mailing lists, and you should read the
2997 * list archives since 2007 if you want to change the
2998 * keymaps. This requirement exists so that you will
2999 * know the past history of problems with the thinkpad-
3000 * acpi driver keymaps, and also that you will be
3001 * listening to any bug reports;
3003 * 3. Do not send thinkpad-acpi specific patches directly to
3004 * for merging, *ever*. Send them to the linux-acpi
3005 * mailinglist for comments. Merging is to be done only
3006 * through acpi-test and the ACPI maintainer.
3008 * If the above is too much to ask, don't change the keymap.
3009 * Ask the thinkpad-acpi maintainer to do it, instead.
3011 static u16 ibm_keycode_map
[] __initdata
= {
3012 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3013 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
3014 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3015 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3017 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3018 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3019 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3020 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3022 /* brightness: firmware always reacts to them */
3023 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
3024 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
3026 /* Thinklight: firmware always react to it */
3027 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3029 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3030 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3032 /* Volume: firmware always react to it and reprograms
3033 * the built-in *extra* mixer. Never map it to control
3034 * another mixer by default. */
3035 KEY_RESERVED
, /* 0x14: VOLUME UP */
3036 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3037 KEY_RESERVED
, /* 0x16: MUTE */
3039 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3041 /* (assignments unknown, please report if found) */
3042 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3043 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3045 static u16 lenovo_keycode_map
[] __initdata
= {
3046 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3047 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
3048 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3049 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3051 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3052 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3053 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3054 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3056 /* These should be enabled --only-- when ACPI video
3057 * is disabled (i.e. in "vendor" mode), and are handled
3058 * in a special way by the init code */
3059 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
3060 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
3062 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3064 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3065 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3067 /* Volume: z60/z61, T60 (BIOS version?): firmware always
3068 * react to it and reprograms the built-in *extra* mixer.
3069 * Never map it to control another mixer by default.
3071 * T60?, T61, R60?, R61: firmware and EC tries to send
3072 * these over the regular keyboard, so these are no-ops,
3073 * but there are still weird bugs re. MUTE, so do not
3074 * change unless you get test reports from all Lenovo
3075 * models. May cause the BIOS to interfere with the
3078 KEY_RESERVED
, /* 0x14: VOLUME UP */
3079 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3080 KEY_RESERVED
, /* 0x16: MUTE */
3082 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3084 /* (assignments unknown, please report if found) */
3085 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3086 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3089 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
3090 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
3091 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
3097 unsigned long quirks
;
3099 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3100 "initializing hotkey subdriver\n");
3102 BUG_ON(!tpacpi_inputdev
);
3103 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
3104 tpacpi_inputdev
->close
!= NULL
);
3106 TPACPI_ACPIHANDLE_INIT(hkey
);
3107 mutex_init(&hotkey_mutex
);
3109 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3110 mutex_init(&hotkey_thread_mutex
);
3111 mutex_init(&hotkey_thread_data_mutex
);
3114 /* hotkey not supported on 570 */
3115 tp_features
.hotkey
= hkey_handle
!= NULL
;
3117 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3119 str_supported(tp_features
.hotkey
));
3121 if (!tp_features
.hotkey
)
3124 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
3125 ARRAY_SIZE(tpacpi_hotkey_qtable
));
3127 tpacpi_disable_brightness_delay();
3129 /* MUST have enough space for all attributes to be added to
3130 * hotkey_dev_attributes */
3131 hotkey_dev_attributes
= create_attr_set(
3132 ARRAY_SIZE(hotkey_attributes
) + 2,
3134 if (!hotkey_dev_attributes
)
3136 res
= add_many_to_attr_set(hotkey_dev_attributes
,
3138 ARRAY_SIZE(hotkey_attributes
));
3142 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
3143 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
3144 for HKEY interface version 0x100 */
3145 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
3146 if ((hkeyv
>> 8) != 1) {
3147 printk(TPACPI_ERR
"unknown version of the "
3148 "HKEY interface: 0x%x\n", hkeyv
);
3149 printk(TPACPI_ERR
"please report this to %s\n",
3153 * MHKV 0x100 in A31, R40, R40e,
3154 * T4x, X31, and later
3156 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3157 "firmware HKEY interface version: 0x%x\n",
3160 /* Paranoia check AND init hotkey_all_mask */
3161 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
3164 "missing MHKA handler, "
3165 "please report this to %s\n",
3167 /* Fallback: pre-init for FN+F3,F4,F12 */
3168 hotkey_all_mask
= 0x080cU
;
3170 tp_features
.hotkey_mask
= 1;
3175 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3176 "hotkey masks are %s\n",
3177 str_supported(tp_features
.hotkey_mask
));
3179 /* Init hotkey_all_mask if not initialized yet */
3180 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
3181 (quirks
& TPACPI_HK_Q_INIMASK
))
3182 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
3184 /* Init hotkey_acpi_mask and hotkey_orig_mask */
3185 if (tp_features
.hotkey_mask
) {
3186 /* hotkey_source_mask *must* be zero for
3187 * the first hotkey_mask_get to return hotkey_orig_mask */
3188 res
= hotkey_mask_get();
3192 hotkey_orig_mask
= hotkey_acpi_mask
;
3194 hotkey_orig_mask
= hotkey_all_mask
;
3195 hotkey_acpi_mask
= hotkey_all_mask
;
3198 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3200 tp_features
.hotkey_wlsw
= 1;
3202 "radio switch emulation enabled\n");
3205 /* Not all thinkpads have a hardware radio switch */
3206 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3207 tp_features
.hotkey_wlsw
= 1;
3209 "radio switch found; radios are %s\n",
3210 enabled(status
, 0));
3212 if (tp_features
.hotkey_wlsw
)
3213 res
= add_to_attr_set(hotkey_dev_attributes
,
3214 &dev_attr_hotkey_radio_sw
.attr
);
3216 /* For X41t, X60t, X61t Tablets... */
3217 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3218 tp_features
.hotkey_tablet
= 1;
3220 "possible tablet mode switch found; "
3221 "ThinkPad in %s mode\n",
3222 (status
& TP_HOTKEY_TABLET_MASK
)?
3223 "tablet" : "laptop");
3224 res
= add_to_attr_set(hotkey_dev_attributes
,
3225 &dev_attr_hotkey_tablet_mode
.attr
);
3229 res
= register_attr_set_with_sysfs(
3230 hotkey_dev_attributes
,
3231 &tpacpi_pdev
->dev
.kobj
);
3235 /* Set up key map */
3237 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3239 if (!hotkey_keycode_map
) {
3241 "failed to allocate memory for key map\n");
3246 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
3247 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3248 "using Lenovo default hot key map\n");
3249 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
3250 TPACPI_HOTKEY_MAP_SIZE
);
3252 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3253 "using IBM default hot key map\n");
3254 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
3255 TPACPI_HOTKEY_MAP_SIZE
);
3258 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
3259 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
3260 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
3261 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3262 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3263 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3264 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3265 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3266 set_bit(hotkey_keycode_map
[i
],
3267 tpacpi_inputdev
->keybit
);
3269 if (i
< sizeof(hotkey_reserved_mask
)*8)
3270 hotkey_reserved_mask
|= 1 << i
;
3274 if (tp_features
.hotkey_wlsw
) {
3275 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
3276 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
3278 if (tp_features
.hotkey_tablet
) {
3279 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
3280 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
3283 /* Do not issue duplicate brightness change events to
3285 if (!tp_features
.bright_acpimode
)
3286 /* update bright_acpimode... */
3287 tpacpi_check_std_acpi_brightness_support();
3289 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
3291 "This ThinkPad has standard ACPI backlight "
3292 "brightness control, supported by the ACPI "
3294 printk(TPACPI_NOTICE
3295 "Disabling thinkpad-acpi brightness events "
3298 /* Disable brightness up/down on Lenovo thinkpads when
3299 * ACPI is handling them, otherwise it is plain impossible
3300 * for userspace to do something even remotely sane */
3301 hotkey_reserved_mask
|=
3302 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3303 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3304 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3305 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3308 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3309 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3311 & ~hotkey_reserved_mask
;
3313 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3314 "hotkey source mask 0x%08x, polling freq %u\n",
3315 hotkey_source_mask
, hotkey_poll_freq
);
3318 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3319 "enabling firmware HKEY event interface...\n");
3320 res
= hotkey_status_set(true);
3325 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3326 | hotkey_driver_mask
)
3327 & ~hotkey_source_mask
);
3328 if (res
< 0 && res
!= -ENXIO
) {
3332 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3333 & ~hotkey_reserved_mask
;
3334 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3335 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3336 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3338 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3339 "legacy ibm/hotkey event reporting over procfs %s\n",
3340 (hotkey_report_mode
< 2) ?
3341 "enabled" : "disabled");
3343 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3344 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3346 hotkey_poll_setup_safe(true);
3347 tpacpi_send_radiosw_update();
3348 tpacpi_input_send_tabletsw();
3353 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3354 hotkey_dev_attributes
= NULL
;
3356 return (res
< 0)? res
: 1;
3359 static bool hotkey_notify_hotkey(const u32 hkey
,
3361 bool *ignore_acpi_ev
)
3363 /* 0x1000-0x1FFF: key presses */
3364 unsigned int scancode
= hkey
& 0xfff;
3365 *send_acpi_ev
= true;
3366 *ignore_acpi_ev
= false;
3368 if (scancode
> 0 && scancode
< 0x21) {
3370 if (!(hotkey_source_mask
& (1 << scancode
))) {
3371 tpacpi_input_send_key_masked(scancode
);
3372 *send_acpi_ev
= false;
3374 *ignore_acpi_ev
= true;
3381 static bool hotkey_notify_wakeup(const u32 hkey
,
3383 bool *ignore_acpi_ev
)
3385 /* 0x2000-0x2FFF: Wakeup reason */
3386 *send_acpi_ev
= true;
3387 *ignore_acpi_ev
= false;
3390 case 0x2304: /* suspend, undock */
3391 case 0x2404: /* hibernation, undock */
3392 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3393 *ignore_acpi_ev
= true;
3396 case 0x2305: /* suspend, bay eject */
3397 case 0x2405: /* hibernation, bay eject */
3398 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3399 *ignore_acpi_ev
= true;
3402 case 0x2313: /* Battery on critical low level (S3) */
3403 case 0x2413: /* Battery on critical low level (S4) */
3405 "EMERGENCY WAKEUP: battery almost empty\n");
3406 /* how to auto-heal: */
3407 /* 2313: woke up from S3, go to S4/S5 */
3408 /* 2413: woke up from S4, go to S5 */
3415 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3417 "woke up due to a hot-unplug "
3419 hotkey_wakeup_reason_notify_change();
3424 static bool hotkey_notify_usrevent(const u32 hkey
,
3426 bool *ignore_acpi_ev
)
3428 /* 0x5000-0x5FFF: human interface helpers */
3429 *send_acpi_ev
= true;
3430 *ignore_acpi_ev
= false;
3433 case 0x500b: /* X61t: tablet pen inserted into bay */
3434 case 0x500c: /* X61t: tablet pen removed from bay */
3437 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
3438 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
3439 tpacpi_input_send_tabletsw();
3440 hotkey_tablet_mode_notify_change();
3441 *send_acpi_ev
= false;
3444 case 0x5001: /* Lid close */
3445 case 0x5002: /* Lid open */
3446 case 0x5010: /* brightness control */
3447 /* do not propagate these events */
3448 *ignore_acpi_ev
= true;
3456 static bool hotkey_notify_thermal(const u32 hkey
,
3458 bool *ignore_acpi_ev
)
3460 /* 0x6000-0x6FFF: thermal alarms */
3461 *send_acpi_ev
= true;
3462 *ignore_acpi_ev
= false;
3467 "THERMAL ALARM: battery is too hot!\n");
3468 /* recommended action: warn user through gui */
3472 "THERMAL EMERGENCY: battery is extremely hot!\n");
3473 /* recommended action: immediate sleep/hibernate */
3478 "a sensor reports something is too hot!\n");
3479 /* recommended action: warn user through gui, that */
3480 /* some internal component is too hot */
3484 "THERMAL EMERGENCY: "
3485 "a sensor reports something is extremely hot!\n");
3486 /* recommended action: immediate sleep/hibernate */
3490 "EC reports that Thermal Table has changed\n");
3491 /* recommended action: do nothing, we don't have
3492 * Lenovo ATM information */
3496 "THERMAL ALERT: unknown thermal alarm received\n");
3501 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3505 bool ignore_acpi_ev
;
3508 if (event
!= 0x80) {
3510 "unknown HKEY notification event %d\n", event
);
3511 /* forward it to userspace, maybe it knows how to handle it */
3512 acpi_bus_generate_netlink_event(
3513 ibm
->acpi
->device
->pnp
.device_class
,
3514 dev_name(&ibm
->acpi
->device
->dev
),
3520 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3521 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3530 send_acpi_ev
= true;
3531 ignore_acpi_ev
= false;
3533 switch (hkey
>> 12) {
3535 /* 0x1000-0x1FFF: key presses */
3536 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3540 /* 0x2000-0x2FFF: Wakeup reason */
3541 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3545 /* 0x3000-0x3FFF: bay-related wakeups */
3546 if (hkey
== 0x3003) {
3547 hotkey_autosleep_ack
= 1;
3550 hotkey_wakeup_hotunplug_complete_notify_change();
3557 /* 0x4000-0x4FFF: dock-related wakeups */
3558 if (hkey
== 0x4003) {
3559 hotkey_autosleep_ack
= 1;
3562 hotkey_wakeup_hotunplug_complete_notify_change();
3569 /* 0x5000-0x5FFF: human interface helpers */
3570 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3574 /* 0x6000-0x6FFF: thermal alarms */
3575 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3579 /* 0x7000-0x7FFF: misc */
3580 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
3581 tpacpi_send_radiosw_update();
3586 /* fallthrough to default */
3591 printk(TPACPI_NOTICE
3592 "unhandled HKEY event 0x%04x\n", hkey
);
3593 printk(TPACPI_NOTICE
3594 "please report the conditions when this "
3595 "event happened to %s\n", TPACPI_MAIL
);
3599 if (!ignore_acpi_ev
&&
3600 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3601 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3605 /* netlink events */
3606 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3607 acpi_bus_generate_netlink_event(
3608 ibm
->acpi
->device
->pnp
.device_class
,
3609 dev_name(&ibm
->acpi
->device
->dev
),
3615 static void hotkey_suspend(pm_message_t state
)
3617 /* Do these on suspend, we get the events on early resume! */
3618 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3619 hotkey_autosleep_ack
= 0;
3622 static void hotkey_resume(void)
3624 tpacpi_disable_brightness_delay();
3626 if (hotkey_status_set(true) < 0 ||
3627 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3629 "error while attempting to reset the event "
3630 "firmware interface\n");
3632 tpacpi_send_radiosw_update();
3633 hotkey_tablet_mode_notify_change();
3634 hotkey_wakeup_reason_notify_change();
3635 hotkey_wakeup_hotunplug_complete_notify_change();
3636 hotkey_poll_setup_safe(false);
3639 /* procfs -------------------------------------------------------------- */
3640 static int hotkey_read(char *p
)
3645 if (!tp_features
.hotkey
) {
3646 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3650 if (mutex_lock_killable(&hotkey_mutex
))
3651 return -ERESTARTSYS
;
3652 res
= hotkey_status_get(&status
);
3654 res
= hotkey_mask_get();
3655 mutex_unlock(&hotkey_mutex
);
3659 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
3660 if (hotkey_all_mask
) {
3661 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3662 len
+= sprintf(p
+ len
,
3663 "commands:\tenable, disable, reset, <mask>\n");
3665 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
3666 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
3672 static void hotkey_enabledisable_warn(bool enable
)
3674 tpacpi_log_usertask("procfs hotkey enable/disable");
3675 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3677 "hotkey enable/disable functionality has been "
3678 "removed from the driver. Hotkeys are always "
3681 "Please remove the hotkey=enable module "
3682 "parameter, it is deprecated. Hotkeys are always "
3686 static int hotkey_write(char *buf
)
3692 if (!tp_features
.hotkey
)
3695 if (mutex_lock_killable(&hotkey_mutex
))
3696 return -ERESTARTSYS
;
3698 mask
= hotkey_user_mask
;
3701 while ((cmd
= next_cmd(&buf
))) {
3702 if (strlencmp(cmd
, "enable") == 0) {
3703 hotkey_enabledisable_warn(1);
3704 } else if (strlencmp(cmd
, "disable") == 0) {
3705 hotkey_enabledisable_warn(0);
3707 } else if (strlencmp(cmd
, "reset") == 0) {
3708 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3709 & ~hotkey_reserved_mask
;
3710 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3712 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3721 tpacpi_disclose_usertask("procfs hotkey",
3722 "set mask to 0x%08x\n", mask
);
3723 res
= hotkey_user_mask_set(mask
);
3727 mutex_unlock(&hotkey_mutex
);
3731 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3732 {TPACPI_ACPI_HKEY_HID
, 0},
3736 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3737 .hid
= ibm_htk_device_ids
,
3738 .notify
= hotkey_notify
,
3739 .handle
= &hkey_handle
,
3740 .type
= ACPI_DEVICE_NOTIFY
,
3743 static struct ibm_struct hotkey_driver_data
= {
3745 .read
= hotkey_read
,
3746 .write
= hotkey_write
,
3747 .exit
= hotkey_exit
,
3748 .resume
= hotkey_resume
,
3749 .suspend
= hotkey_suspend
,
3750 .acpi
= &ibm_hotkey_acpidriver
,
3753 /*************************************************************************
3754 * Bluetooth subdriver
3758 /* ACPI GBDC/SBDC bits */
3759 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3760 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3761 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3766 /* ACPI \BLTH commands */
3767 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3768 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3769 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3770 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3771 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3774 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3776 static void bluetooth_suspend(pm_message_t state
)
3778 /* Try to make sure radio will resume powered off */
3779 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3780 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
))
3781 vdbg_printk(TPACPI_DBG_RFKILL
,
3782 "bluetooth power down on resume request failed\n");
3785 static int bluetooth_get_status(void)
3789 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3790 if (dbg_bluetoothemul
)
3791 return (tpacpi_bluetooth_emulstate
) ?
3792 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3795 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3798 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3799 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3802 static int bluetooth_set_status(enum tpacpi_rfkill_state state
)
3806 vdbg_printk(TPACPI_DBG_RFKILL
,
3807 "will attempt to %s bluetooth\n",
3808 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
3810 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3811 if (dbg_bluetoothemul
) {
3812 tpacpi_bluetooth_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
3817 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3818 if (state
== TPACPI_RFK_RADIO_ON
)
3819 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
3823 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3829 /* sysfs bluetooth enable ---------------------------------------------- */
3830 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3831 struct device_attribute
*attr
,
3834 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID
,
3838 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3839 struct device_attribute
*attr
,
3840 const char *buf
, size_t count
)
3842 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID
,
3846 static struct device_attribute dev_attr_bluetooth_enable
=
3847 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3848 bluetooth_enable_show
, bluetooth_enable_store
);
3850 /* --------------------------------------------------------------------- */
3852 static struct attribute
*bluetooth_attributes
[] = {
3853 &dev_attr_bluetooth_enable
.attr
,
3857 static const struct attribute_group bluetooth_attr_group
= {
3858 .attrs
= bluetooth_attributes
,
3861 static const struct tpacpi_rfk_ops bluetooth_tprfk_ops
= {
3862 .get_status
= bluetooth_get_status
,
3863 .set_status
= bluetooth_set_status
,
3866 static void bluetooth_shutdown(void)
3868 /* Order firmware to save current state to NVRAM */
3869 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3870 TP_ACPI_BLTH_SAVE_STATE
))
3871 printk(TPACPI_NOTICE
3872 "failed to save bluetooth state to NVRAM\n");
3874 vdbg_printk(TPACPI_DBG_RFKILL
,
3875 "bluestooth state saved to NVRAM\n");
3878 static void bluetooth_exit(void)
3880 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3881 &bluetooth_attr_group
);
3883 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
3885 bluetooth_shutdown();
3888 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3893 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3894 "initializing bluetooth subdriver\n");
3896 TPACPI_ACPIHANDLE_INIT(hkey
);
3898 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3899 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3900 tp_features
.bluetooth
= hkey_handle
&&
3901 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3903 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3904 "bluetooth is %s, status 0x%02x\n",
3905 str_supported(tp_features
.bluetooth
),
3908 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3909 if (dbg_bluetoothemul
) {
3910 tp_features
.bluetooth
= 1;
3912 "bluetooth switch emulation enabled\n");
3915 if (tp_features
.bluetooth
&&
3916 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
3917 /* no bluetooth hardware present in system */
3918 tp_features
.bluetooth
= 0;
3919 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3920 "bluetooth hardware not installed\n");
3923 if (!tp_features
.bluetooth
)
3926 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3927 &bluetooth_tprfk_ops
,
3928 RFKILL_TYPE_BLUETOOTH
,
3929 TPACPI_RFK_BLUETOOTH_SW_NAME
,
3934 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3935 &bluetooth_attr_group
);
3937 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
3944 /* procfs -------------------------------------------------------------- */
3945 static int bluetooth_read(char *p
)
3947 return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID
, p
);
3950 static int bluetooth_write(char *buf
)
3952 return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID
, buf
);
3955 static struct ibm_struct bluetooth_driver_data
= {
3956 .name
= "bluetooth",
3957 .read
= bluetooth_read
,
3958 .write
= bluetooth_write
,
3959 .exit
= bluetooth_exit
,
3960 .suspend
= bluetooth_suspend
,
3961 .shutdown
= bluetooth_shutdown
,
3964 /*************************************************************************
3969 /* ACPI GWAN/SWAN bits */
3970 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3971 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3972 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3976 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
3978 static void wan_suspend(pm_message_t state
)
3980 /* Try to make sure radio will resume powered off */
3981 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3982 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
))
3983 vdbg_printk(TPACPI_DBG_RFKILL
,
3984 "WWAN power down on resume request failed\n");
3987 static int wan_get_status(void)
3991 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3993 return (tpacpi_wwan_emulstate
) ?
3994 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3997 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
4000 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
4001 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4004 static int wan_set_status(enum tpacpi_rfkill_state state
)
4008 vdbg_printk(TPACPI_DBG_RFKILL
,
4009 "will attempt to %s wwan\n",
4010 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4012 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4014 tpacpi_wwan_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4019 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
4020 if (state
== TPACPI_RFK_RADIO_ON
)
4021 status
= TP_ACPI_WANCARD_RADIOSSW
;
4025 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
4031 /* sysfs wan enable ---------------------------------------------------- */
4032 static ssize_t
wan_enable_show(struct device
*dev
,
4033 struct device_attribute
*attr
,
4036 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID
,
4040 static ssize_t
wan_enable_store(struct device
*dev
,
4041 struct device_attribute
*attr
,
4042 const char *buf
, size_t count
)
4044 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID
,
4048 static struct device_attribute dev_attr_wan_enable
=
4049 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4050 wan_enable_show
, wan_enable_store
);
4052 /* --------------------------------------------------------------------- */
4054 static struct attribute
*wan_attributes
[] = {
4055 &dev_attr_wan_enable
.attr
,
4059 static const struct attribute_group wan_attr_group
= {
4060 .attrs
= wan_attributes
,
4063 static const struct tpacpi_rfk_ops wan_tprfk_ops
= {
4064 .get_status
= wan_get_status
,
4065 .set_status
= wan_set_status
,
4068 static void wan_shutdown(void)
4070 /* Order firmware to save current state to NVRAM */
4071 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4072 TP_ACPI_WGSV_SAVE_STATE
))
4073 printk(TPACPI_NOTICE
4074 "failed to save WWAN state to NVRAM\n");
4076 vdbg_printk(TPACPI_DBG_RFKILL
,
4077 "WWAN state saved to NVRAM\n");
4080 static void wan_exit(void)
4082 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4085 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4090 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4095 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4096 "initializing wan subdriver\n");
4098 TPACPI_ACPIHANDLE_INIT(hkey
);
4100 tp_features
.wan
= hkey_handle
&&
4101 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4103 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4104 "wan is %s, status 0x%02x\n",
4105 str_supported(tp_features
.wan
),
4108 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4110 tp_features
.wan
= 1;
4112 "wwan switch emulation enabled\n");
4115 if (tp_features
.wan
&&
4116 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4117 /* no wan hardware present in system */
4118 tp_features
.wan
= 0;
4119 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4120 "wan hardware not installed\n");
4123 if (!tp_features
.wan
)
4126 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4129 TPACPI_RFK_WWAN_SW_NAME
,
4134 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4138 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4145 /* procfs -------------------------------------------------------------- */
4146 static int wan_read(char *p
)
4148 return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID
, p
);
4151 static int wan_write(char *buf
)
4153 return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID
, buf
);
4156 static struct ibm_struct wan_driver_data
= {
4161 .suspend
= wan_suspend
,
4162 .shutdown
= wan_shutdown
,
4165 /*************************************************************************
4170 /* ACPI GUWB/SUWB bits */
4171 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4172 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4175 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4177 static int uwb_get_status(void)
4181 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4183 return (tpacpi_uwb_emulstate
) ?
4184 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4187 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4190 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4191 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4194 static int uwb_set_status(enum tpacpi_rfkill_state state
)
4198 vdbg_printk(TPACPI_DBG_RFKILL
,
4199 "will attempt to %s UWB\n",
4200 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4202 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4204 tpacpi_uwb_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4209 if (state
== TPACPI_RFK_RADIO_ON
)
4210 status
= TP_ACPI_UWB_RADIOSSW
;
4214 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4220 /* --------------------------------------------------------------------- */
4222 static const struct tpacpi_rfk_ops uwb_tprfk_ops
= {
4223 .get_status
= uwb_get_status
,
4224 .set_status
= uwb_set_status
,
4227 static void uwb_exit(void)
4229 tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID
);
4232 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4237 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4238 "initializing uwb subdriver\n");
4240 TPACPI_ACPIHANDLE_INIT(hkey
);
4242 tp_features
.uwb
= hkey_handle
&&
4243 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4245 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4246 "uwb is %s, status 0x%02x\n",
4247 str_supported(tp_features
.uwb
),
4250 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4252 tp_features
.uwb
= 1;
4254 "uwb switch emulation enabled\n");
4257 if (tp_features
.uwb
&&
4258 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4259 /* no uwb hardware present in system */
4260 tp_features
.uwb
= 0;
4261 dbg_printk(TPACPI_DBG_INIT
,
4262 "uwb hardware not installed\n");
4265 if (!tp_features
.uwb
)
4268 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4271 TPACPI_RFK_UWB_SW_NAME
,
4276 static struct ibm_struct uwb_driver_data
= {
4279 .flags
.experimental
= 1,
4282 /*************************************************************************
4286 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4288 enum video_access_mode
{
4289 TPACPI_VIDEO_NONE
= 0,
4290 TPACPI_VIDEO_570
, /* 570 */
4291 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4292 TPACPI_VIDEO_NEW
, /* all others */
4295 enum { /* video status flags, based on VIDEO_570 */
4296 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4297 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4298 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4301 enum { /* TPACPI_VIDEO_570 constants */
4302 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4303 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4304 * video_status_flags */
4305 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4306 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4309 static enum video_access_mode video_supported
;
4310 static int video_orig_autosw
;
4312 static int video_autosw_get(void);
4313 static int video_autosw_set(int enable
);
4315 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4317 static int __init
video_init(struct ibm_init_struct
*iibm
)
4321 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4323 TPACPI_ACPIHANDLE_INIT(vid
);
4324 TPACPI_ACPIHANDLE_INIT(vid2
);
4326 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4327 /* G41, assume IVGA doesn't change */
4328 vid_handle
= vid2_handle
;
4331 /* video switching not supported on R30, R31 */
4332 video_supported
= TPACPI_VIDEO_NONE
;
4333 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4335 video_supported
= TPACPI_VIDEO_570
;
4336 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4337 /* 600e/x, 770e, 770x */
4338 video_supported
= TPACPI_VIDEO_770
;
4341 video_supported
= TPACPI_VIDEO_NEW
;
4343 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4344 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4347 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4350 static void video_exit(void)
4352 dbg_printk(TPACPI_DBG_EXIT
,
4353 "restoring original video autoswitch mode\n");
4354 if (video_autosw_set(video_orig_autosw
))
4355 printk(TPACPI_ERR
"error while trying to restore original "
4356 "video autoswitch mode\n");
4359 static int video_outputsw_get(void)
4364 switch (video_supported
) {
4365 case TPACPI_VIDEO_570
:
4366 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4367 TP_ACPI_VIDEO_570_PHSCMD
))
4369 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4371 case TPACPI_VIDEO_770
:
4372 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4375 status
|= TP_ACPI_VIDEO_S_LCD
;
4376 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4379 status
|= TP_ACPI_VIDEO_S_CRT
;
4381 case TPACPI_VIDEO_NEW
:
4382 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4383 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4386 status
|= TP_ACPI_VIDEO_S_CRT
;
4388 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4389 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4392 status
|= TP_ACPI_VIDEO_S_LCD
;
4393 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4396 status
|= TP_ACPI_VIDEO_S_DVI
;
4405 static int video_outputsw_set(int status
)
4410 switch (video_supported
) {
4411 case TPACPI_VIDEO_570
:
4412 res
= acpi_evalf(NULL
, NULL
,
4413 "\\_SB.PHS2", "vdd",
4414 TP_ACPI_VIDEO_570_PHS2CMD
,
4415 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4417 case TPACPI_VIDEO_770
:
4418 autosw
= video_autosw_get();
4422 res
= video_autosw_set(1);
4425 res
= acpi_evalf(vid_handle
, NULL
,
4426 "ASWT", "vdd", status
* 0x100, 0);
4427 if (!autosw
&& video_autosw_set(autosw
)) {
4429 "video auto-switch left enabled due to error\n");
4433 case TPACPI_VIDEO_NEW
:
4434 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4435 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4441 return (res
)? 0 : -EIO
;
4444 static int video_autosw_get(void)
4448 switch (video_supported
) {
4449 case TPACPI_VIDEO_570
:
4450 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4453 case TPACPI_VIDEO_770
:
4454 case TPACPI_VIDEO_NEW
:
4455 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4465 static int video_autosw_set(int enable
)
4467 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4472 static int video_outputsw_cycle(void)
4474 int autosw
= video_autosw_get();
4480 switch (video_supported
) {
4481 case TPACPI_VIDEO_570
:
4482 res
= video_autosw_set(1);
4485 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4487 case TPACPI_VIDEO_770
:
4488 case TPACPI_VIDEO_NEW
:
4489 res
= video_autosw_set(1);
4492 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4497 if (!autosw
&& video_autosw_set(autosw
)) {
4499 "video auto-switch left enabled due to error\n");
4503 return (res
)? 0 : -EIO
;
4506 static int video_expand_toggle(void)
4508 switch (video_supported
) {
4509 case TPACPI_VIDEO_570
:
4510 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4512 case TPACPI_VIDEO_770
:
4513 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4515 case TPACPI_VIDEO_NEW
:
4516 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4524 static int video_read(char *p
)
4529 if (video_supported
== TPACPI_VIDEO_NONE
) {
4530 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4534 status
= video_outputsw_get();
4538 autosw
= video_autosw_get();
4542 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4543 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
4544 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
4545 if (video_supported
== TPACPI_VIDEO_NEW
)
4546 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
4547 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
4548 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
4549 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
4550 if (video_supported
== TPACPI_VIDEO_NEW
)
4551 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
4552 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
4553 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
4558 static int video_write(char *buf
)
4561 int enable
, disable
, status
;
4564 if (video_supported
== TPACPI_VIDEO_NONE
)
4570 while ((cmd
= next_cmd(&buf
))) {
4571 if (strlencmp(cmd
, "lcd_enable") == 0) {
4572 enable
|= TP_ACPI_VIDEO_S_LCD
;
4573 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4574 disable
|= TP_ACPI_VIDEO_S_LCD
;
4575 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4576 enable
|= TP_ACPI_VIDEO_S_CRT
;
4577 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4578 disable
|= TP_ACPI_VIDEO_S_CRT
;
4579 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4580 strlencmp(cmd
, "dvi_enable") == 0) {
4581 enable
|= TP_ACPI_VIDEO_S_DVI
;
4582 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4583 strlencmp(cmd
, "dvi_disable") == 0) {
4584 disable
|= TP_ACPI_VIDEO_S_DVI
;
4585 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4586 res
= video_autosw_set(1);
4589 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4590 res
= video_autosw_set(0);
4593 } else if (strlencmp(cmd
, "video_switch") == 0) {
4594 res
= video_outputsw_cycle();
4597 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4598 res
= video_expand_toggle();
4605 if (enable
|| disable
) {
4606 status
= video_outputsw_get();
4609 res
= video_outputsw_set((status
& ~disable
) | enable
);
4617 static struct ibm_struct video_driver_data
= {
4620 .write
= video_write
,
4624 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4626 /*************************************************************************
4627 * Light (thinklight) subdriver
4630 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4631 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4633 static int light_get_status(void)
4637 if (tp_features
.light_status
) {
4638 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4646 static int light_set_status(int status
)
4650 if (tp_features
.light
) {
4652 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4654 TP_CMOS_THINKLIGHT_ON
:
4655 TP_CMOS_THINKLIGHT_OFF
);
4657 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4660 return (rc
)? 0 : -EIO
;
4666 static void light_set_status_worker(struct work_struct
*work
)
4668 struct tpacpi_led_classdev
*data
=
4669 container_of(work
, struct tpacpi_led_classdev
, work
);
4671 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4672 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4675 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4676 enum led_brightness brightness
)
4678 struct tpacpi_led_classdev
*data
=
4679 container_of(led_cdev
,
4680 struct tpacpi_led_classdev
,
4682 data
->new_state
= (brightness
!= LED_OFF
) ?
4683 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4684 queue_work(tpacpi_wq
, &data
->work
);
4687 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4689 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4692 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4694 .name
= "tpacpi::thinklight",
4695 .brightness_set
= &light_sysfs_set
,
4696 .brightness_get
= &light_sysfs_get
,
4700 static int __init
light_init(struct ibm_init_struct
*iibm
)
4704 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4706 TPACPI_ACPIHANDLE_INIT(ledb
);
4707 TPACPI_ACPIHANDLE_INIT(lght
);
4708 TPACPI_ACPIHANDLE_INIT(cmos
);
4709 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4711 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4712 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4714 if (tp_features
.light
)
4715 /* light status not supported on
4716 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4717 tp_features
.light_status
=
4718 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4720 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4721 str_supported(tp_features
.light
),
4722 str_supported(tp_features
.light_status
));
4724 if (!tp_features
.light
)
4727 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4728 &tpacpi_led_thinklight
.led_classdev
);
4731 tp_features
.light
= 0;
4732 tp_features
.light_status
= 0;
4740 static void light_exit(void)
4742 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4743 if (work_pending(&tpacpi_led_thinklight
.work
))
4744 flush_workqueue(tpacpi_wq
);
4747 static int light_read(char *p
)
4752 if (!tp_features
.light
) {
4753 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4754 } else if (!tp_features
.light_status
) {
4755 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
4756 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4758 status
= light_get_status();
4761 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
4762 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4768 static int light_write(char *buf
)
4773 if (!tp_features
.light
)
4776 while ((cmd
= next_cmd(&buf
))) {
4777 if (strlencmp(cmd
, "on") == 0) {
4779 } else if (strlencmp(cmd
, "off") == 0) {
4785 return light_set_status(newstatus
);
4788 static struct ibm_struct light_driver_data
= {
4791 .write
= light_write
,
4795 /*************************************************************************
4799 /* sysfs cmos_command -------------------------------------------------- */
4800 static ssize_t
cmos_command_store(struct device
*dev
,
4801 struct device_attribute
*attr
,
4802 const char *buf
, size_t count
)
4804 unsigned long cmos_cmd
;
4807 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4810 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4811 return (res
)? res
: count
;
4814 static struct device_attribute dev_attr_cmos_command
=
4815 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4817 /* --------------------------------------------------------------------- */
4819 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4823 vdbg_printk(TPACPI_DBG_INIT
,
4824 "initializing cmos commands subdriver\n");
4826 TPACPI_ACPIHANDLE_INIT(cmos
);
4828 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4829 str_supported(cmos_handle
!= NULL
));
4831 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4835 return (cmos_handle
)? 0 : 1;
4838 static void cmos_exit(void)
4840 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4843 static int cmos_read(char *p
)
4847 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4848 R30, R31, T20-22, X20-21 */
4850 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4852 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4853 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4859 static int cmos_write(char *buf
)
4864 while ((cmd
= next_cmd(&buf
))) {
4865 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4866 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4871 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4879 static struct ibm_struct cmos_driver_data
= {
4882 .write
= cmos_write
,
4886 /*************************************************************************
4890 enum led_access_mode
{
4891 TPACPI_LED_NONE
= 0,
4892 TPACPI_LED_570
, /* 570 */
4893 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4894 TPACPI_LED_NEW
, /* all others */
4897 enum { /* For TPACPI_LED_OLD */
4898 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4899 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4900 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4903 static enum led_access_mode led_supported
;
4905 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4906 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4907 /* T20-22, X20-21 */
4908 "LED", /* all others */
4911 #define TPACPI_LED_NUMLEDS 16
4912 static struct tpacpi_led_classdev
*tpacpi_leds
;
4913 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4914 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4915 /* there's a limit of 19 chars + NULL before 2.6.26 */
4917 "tpacpi:orange:batt",
4918 "tpacpi:green:batt",
4919 "tpacpi::dock_active",
4920 "tpacpi::bay_active",
4921 "tpacpi::dock_batt",
4922 "tpacpi::unknown_led",
4924 "tpacpi::dock_status1",
4925 "tpacpi::dock_status2",
4926 "tpacpi::unknown_led2",
4927 "tpacpi::unknown_led3",
4928 "tpacpi::thinkvantage",
4930 #define TPACPI_SAFE_LEDS 0x1081U
4932 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
4934 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
4937 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
4941 static int led_get_status(const unsigned int led
)
4944 enum led_status_t led_s
;
4946 switch (led_supported
) {
4947 case TPACPI_LED_570
:
4948 if (!acpi_evalf(ec_handle
,
4949 &status
, "GLED", "dd", 1 << led
))
4951 led_s
= (status
== 0)?
4956 tpacpi_led_state_cache
[led
] = led_s
;
4965 static int led_set_status(const unsigned int led
,
4966 const enum led_status_t ledstatus
)
4968 /* off, on, blink. Index is led_status_t */
4969 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
4970 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
4974 switch (led_supported
) {
4975 case TPACPI_LED_570
:
4977 if (unlikely(led
> 7))
4979 if (unlikely(tpacpi_is_led_restricted(led
)))
4981 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4982 (1 << led
), led_sled_arg1
[ledstatus
]))
4985 case TPACPI_LED_OLD
:
4986 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4987 if (unlikely(led
> 7))
4989 if (unlikely(tpacpi_is_led_restricted(led
)))
4991 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
4993 rc
= ec_write(TPACPI_LED_EC_HLBL
,
4994 (ledstatus
== TPACPI_LED_BLINK
) << led
);
4996 rc
= ec_write(TPACPI_LED_EC_HLCL
,
4997 (ledstatus
!= TPACPI_LED_OFF
) << led
);
4999 case TPACPI_LED_NEW
:
5001 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5003 if (unlikely(tpacpi_is_led_restricted(led
)))
5005 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5006 led
, led_led_arg1
[ledstatus
]))
5014 tpacpi_led_state_cache
[led
] = ledstatus
;
5019 static void led_set_status_worker(struct work_struct
*work
)
5021 struct tpacpi_led_classdev
*data
=
5022 container_of(work
, struct tpacpi_led_classdev
, work
);
5024 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5025 led_set_status(data
->led
, data
->new_state
);
5028 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5029 enum led_brightness brightness
)
5031 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5032 struct tpacpi_led_classdev
, led_classdev
);
5034 if (brightness
== LED_OFF
)
5035 data
->new_state
= TPACPI_LED_OFF
;
5036 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5037 data
->new_state
= TPACPI_LED_ON
;
5039 data
->new_state
= TPACPI_LED_BLINK
;
5041 queue_work(tpacpi_wq
, &data
->work
);
5044 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5045 unsigned long *delay_on
, unsigned long *delay_off
)
5047 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5048 struct tpacpi_led_classdev
, led_classdev
);
5050 /* Can we choose the flash rate? */
5051 if (*delay_on
== 0 && *delay_off
== 0) {
5052 /* yes. set them to the hardware blink rate (1 Hz) */
5053 *delay_on
= 500; /* ms */
5054 *delay_off
= 500; /* ms */
5055 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5058 data
->new_state
= TPACPI_LED_BLINK
;
5059 queue_work(tpacpi_wq
, &data
->work
);
5064 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5068 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5069 struct tpacpi_led_classdev
, led_classdev
);
5071 rc
= led_get_status(data
->led
);
5073 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5074 rc
= LED_OFF
; /* no error handling in led class :( */
5081 static void led_exit(void)
5085 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5086 if (tpacpi_leds
[i
].led_classdev
.name
)
5087 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5093 static int __init
tpacpi_init_led(unsigned int led
)
5097 tpacpi_leds
[led
].led
= led
;
5099 /* LEDs with no name don't get registered */
5100 if (!tpacpi_led_names
[led
])
5103 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5104 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5105 if (led_supported
== TPACPI_LED_570
)
5106 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5109 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5111 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5113 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5114 &tpacpi_leds
[led
].led_classdev
);
5116 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5121 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5122 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5123 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5124 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5126 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5127 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5128 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5129 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5130 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5131 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5132 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5133 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5135 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5136 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5137 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5138 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5139 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5141 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5142 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5143 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5144 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5146 /* (1) - may have excess leds enabled on MSB */
5148 /* Defaults (order matters, keep last, don't reorder!) */
5150 .vendor
= PCI_VENDOR_ID_LENOVO
,
5151 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5154 { /* IBM ThinkPads with no EC version string */
5155 .vendor
= PCI_VENDOR_ID_IBM
,
5156 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5159 { /* IBM ThinkPads with EC version string */
5160 .vendor
= PCI_VENDOR_ID_IBM
,
5161 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5166 #undef TPACPI_LEDQ_IBM
5167 #undef TPACPI_LEDQ_LNV
5169 static int __init
led_init(struct ibm_init_struct
*iibm
)
5173 unsigned long useful_leds
;
5175 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5177 TPACPI_ACPIHANDLE_INIT(led
);
5180 /* led not supported on R30, R31 */
5181 led_supported
= TPACPI_LED_NONE
;
5182 else if (strlencmp(led_path
, "SLED") == 0)
5184 led_supported
= TPACPI_LED_570
;
5185 else if (strlencmp(led_path
, "SYSL") == 0)
5186 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5187 led_supported
= TPACPI_LED_OLD
;
5190 led_supported
= TPACPI_LED_NEW
;
5192 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5193 str_supported(led_supported
), led_supported
);
5195 if (led_supported
== TPACPI_LED_NONE
)
5198 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5201 printk(TPACPI_ERR
"Out of memory for LED data\n");
5205 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5206 ARRAY_SIZE(led_useful_qtable
));
5208 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5209 if (!tpacpi_is_led_restricted(i
) &&
5210 test_bit(i
, &useful_leds
)) {
5211 rc
= tpacpi_init_led(i
);
5219 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5220 printk(TPACPI_NOTICE
5221 "warning: userspace override of important "
5222 "firmware LEDs is enabled\n");
5227 #define str_led_status(s) \
5228 ((s) == TPACPI_LED_OFF ? "off" : \
5229 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5231 static int led_read(char *p
)
5235 if (!led_supported
) {
5236 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5239 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
5241 if (led_supported
== TPACPI_LED_570
) {
5244 for (i
= 0; i
< 8; i
++) {
5245 status
= led_get_status(i
);
5248 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
5249 i
, str_led_status(status
));
5253 len
+= sprintf(p
+ len
, "commands:\t"
5254 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5259 static int led_write(char *buf
)
5263 enum led_status_t s
;
5268 while ((cmd
= next_cmd(&buf
))) {
5269 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5272 if (strstr(cmd
, "off")) {
5274 } else if (strstr(cmd
, "on")) {
5276 } else if (strstr(cmd
, "blink")) {
5277 s
= TPACPI_LED_BLINK
;
5282 rc
= led_set_status(led
, s
);
5290 static struct ibm_struct led_driver_data
= {
5297 /*************************************************************************
5301 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5303 #define TPACPI_BEEP_Q1 0x0001
5305 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5306 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5307 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5310 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5312 unsigned long quirks
;
5314 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5316 TPACPI_ACPIHANDLE_INIT(beep
);
5318 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5319 str_supported(beep_handle
!= NULL
));
5321 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5322 ARRAY_SIZE(beep_quirk_table
));
5324 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5326 return (beep_handle
)? 0 : 1;
5329 static int beep_read(char *p
)
5334 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5336 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
5337 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5343 static int beep_write(char *buf
)
5351 while ((cmd
= next_cmd(&buf
))) {
5352 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5353 beep_cmd
>= 0 && beep_cmd
<= 17) {
5357 if (tp_features
.beep_needs_two_args
) {
5358 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5362 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5371 static struct ibm_struct beep_driver_data
= {
5374 .write
= beep_write
,
5377 /*************************************************************************
5381 enum thermal_access_mode
{
5382 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5383 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5384 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5385 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5386 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5389 enum { /* TPACPI_THERMAL_TPEC_* */
5390 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5391 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5392 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5395 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5396 struct ibm_thermal_sensors_struct
{
5397 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5400 static enum thermal_access_mode thermal_read_mode
;
5402 /* idx is zero-based */
5403 static int thermal_get_sensor(int idx
, s32
*value
)
5409 t
= TP_EC_THERMAL_TMP0
;
5411 switch (thermal_read_mode
) {
5412 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5413 case TPACPI_THERMAL_TPEC_16
:
5414 if (idx
>= 8 && idx
<= 15) {
5415 t
= TP_EC_THERMAL_TMP8
;
5420 case TPACPI_THERMAL_TPEC_8
:
5422 if (!acpi_ec_read(t
+ idx
, &tmp
))
5424 *value
= tmp
* 1000;
5429 case TPACPI_THERMAL_ACPI_UPDT
:
5431 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5432 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5434 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5436 *value
= (t
- 2732) * 100;
5441 case TPACPI_THERMAL_ACPI_TMP07
:
5443 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5444 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5446 if (t
> 127 || t
< -127)
5447 t
= TP_EC_THERMAL_TMP_NA
;
5453 case TPACPI_THERMAL_NONE
:
5461 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5472 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5475 for (i
= 0 ; i
< n
; i
++) {
5476 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5484 /* sysfs temp##_input -------------------------------------------------- */
5486 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5487 struct device_attribute
*attr
,
5490 struct sensor_device_attribute
*sensor_attr
=
5491 to_sensor_dev_attr(attr
);
5492 int idx
= sensor_attr
->index
;
5496 res
= thermal_get_sensor(idx
, &value
);
5499 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
5502 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5505 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5506 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5507 thermal_temp_input_show, NULL, _idxB)
5509 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5510 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5511 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5512 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5513 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5514 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5515 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5516 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5517 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5518 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5519 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5520 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5521 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5522 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5523 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5524 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5525 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5528 #define THERMAL_ATTRS(X) \
5529 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5531 static struct attribute
*thermal_temp_input_attr
[] = {
5551 static const struct attribute_group thermal_temp_input16_group
= {
5552 .attrs
= thermal_temp_input_attr
5555 static const struct attribute_group thermal_temp_input8_group
= {
5556 .attrs
= &thermal_temp_input_attr
[8]
5559 #undef THERMAL_SENSOR_ATTR_TEMP
5560 #undef THERMAL_ATTRS
5562 /* --------------------------------------------------------------------- */
5564 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5571 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5573 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5575 if (thinkpad_id
.ec_model
) {
5577 * Direct EC access mode: sensors at registers
5578 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5579 * non-implemented, thermal sensors return 0x80 when
5584 for (i
= 0; i
< 8; i
++) {
5585 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5591 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5599 /* This is sheer paranoia, but we handle it anyway */
5602 "ThinkPad ACPI EC access misbehaving, "
5603 "falling back to ACPI TMPx access "
5605 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5608 "ThinkPad ACPI EC access misbehaving, "
5609 "disabling thermal sensors access\n");
5610 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5615 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5617 } else if (acpi_tmp7
) {
5618 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5619 /* 600e/x, 770e, 770x */
5620 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5622 /* Standard ACPI TMPx access, max 8 sensors */
5623 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5626 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5627 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5630 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5631 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5634 switch (thermal_read_mode
) {
5635 case TPACPI_THERMAL_TPEC_16
:
5636 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5637 &thermal_temp_input16_group
);
5641 case TPACPI_THERMAL_TPEC_8
:
5642 case TPACPI_THERMAL_ACPI_TMP07
:
5643 case TPACPI_THERMAL_ACPI_UPDT
:
5644 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5645 &thermal_temp_input8_group
);
5649 case TPACPI_THERMAL_NONE
:
5657 static void thermal_exit(void)
5659 switch (thermal_read_mode
) {
5660 case TPACPI_THERMAL_TPEC_16
:
5661 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5662 &thermal_temp_input16_group
);
5664 case TPACPI_THERMAL_TPEC_8
:
5665 case TPACPI_THERMAL_ACPI_TMP07
:
5666 case TPACPI_THERMAL_ACPI_UPDT
:
5667 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5668 &thermal_temp_input16_group
);
5670 case TPACPI_THERMAL_NONE
:
5676 static int thermal_read(char *p
)
5680 struct ibm_thermal_sensors_struct t
;
5682 n
= thermal_get_sensors(&t
);
5683 if (unlikely(n
< 0))
5686 len
+= sprintf(p
+ len
, "temperatures:\t");
5689 for (i
= 0; i
< (n
- 1); i
++)
5690 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
5691 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
5693 len
+= sprintf(p
+ len
, "not supported\n");
5698 static struct ibm_struct thermal_driver_data
= {
5700 .read
= thermal_read
,
5701 .exit
= thermal_exit
,
5704 /*************************************************************************
5708 static u8 ecdump_regs
[256];
5710 static int ecdump_read(char *p
)
5716 len
+= sprintf(p
+ len
, "EC "
5717 " +00 +01 +02 +03 +04 +05 +06 +07"
5718 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5719 for (i
= 0; i
< 256; i
+= 16) {
5720 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
5721 for (j
= 0; j
< 16; j
++) {
5722 if (!acpi_ec_read(i
+ j
, &v
))
5724 if (v
!= ecdump_regs
[i
+ j
])
5725 len
+= sprintf(p
+ len
, " *%02x", v
);
5727 len
+= sprintf(p
+ len
, " %02x", v
);
5728 ecdump_regs
[i
+ j
] = v
;
5730 len
+= sprintf(p
+ len
, "\n");
5735 /* These are way too dangerous to advertise openly... */
5737 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
5738 " (<offset> is 00-ff, <value> is 00-ff)\n");
5739 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
5740 " (<offset> is 00-ff, <value> is 0-255)\n");
5745 static int ecdump_write(char *buf
)
5750 while ((cmd
= next_cmd(&buf
))) {
5751 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5753 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5757 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5758 if (!acpi_ec_write(i
, v
))
5767 static struct ibm_struct ecdump_driver_data
= {
5769 .read
= ecdump_read
,
5770 .write
= ecdump_write
,
5771 .flags
.experimental
= 1,
5774 /*************************************************************************
5775 * Backlight/brightness subdriver
5778 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5781 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5782 * CMOS NVRAM byte 0x5E, bits 0-3.
5784 * EC HBRV (0x31) has the following layout
5785 * Bit 7: unknown function
5786 * Bit 6: unknown function
5787 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5788 * Bit 4: must be set to zero to avoid problems
5789 * Bit 3-0: backlight brightness level
5791 * brightness_get_raw returns status data in the HBRV layout
5793 * WARNING: The X61 has been verified to use HBRV for something else, so
5794 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5795 * testing on the very early *60 Lenovo models...
5799 TP_EC_BACKLIGHT
= 0x31,
5801 /* TP_EC_BACKLIGHT bitmasks */
5802 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5803 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5804 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5807 enum tpacpi_brightness_access_mode
{
5808 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5809 TPACPI_BRGHT_MODE_EC
, /* EC control */
5810 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5811 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5812 TPACPI_BRGHT_MODE_MAX
5815 static struct backlight_device
*ibm_backlight_device
;
5817 static enum tpacpi_brightness_access_mode brightness_mode
=
5818 TPACPI_BRGHT_MODE_MAX
;
5820 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5822 static struct mutex brightness_mutex
;
5824 /* NVRAM brightness access,
5825 * call with brightness_mutex held! */
5826 static unsigned int tpacpi_brightness_nvram_get(void)
5830 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5831 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5832 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5833 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5838 static void tpacpi_brightness_checkpoint_nvram(void)
5843 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5846 vdbg_printk(TPACPI_DBG_BRGHT
,
5847 "trying to checkpoint backlight level to NVRAM...\n");
5849 if (mutex_lock_killable(&brightness_mutex
) < 0)
5852 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5854 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5855 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5857 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5858 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5859 /* NVRAM needs update */
5860 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5861 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5863 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5864 dbg_printk(TPACPI_DBG_BRGHT
,
5865 "updated NVRAM backlight level to %u (0x%02x)\n",
5866 (unsigned int) lec
, (unsigned int) b_nvram
);
5868 vdbg_printk(TPACPI_DBG_BRGHT
,
5869 "NVRAM backlight level already is %u (0x%02x)\n",
5870 (unsigned int) lec
, (unsigned int) b_nvram
);
5873 mutex_unlock(&brightness_mutex
);
5877 /* call with brightness_mutex held! */
5878 static int tpacpi_brightness_get_raw(int *status
)
5882 switch (brightness_mode
) {
5883 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5884 *status
= tpacpi_brightness_nvram_get();
5886 case TPACPI_BRGHT_MODE_EC
:
5887 case TPACPI_BRGHT_MODE_ECNVRAM
:
5888 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5897 /* call with brightness_mutex held! */
5898 /* do NOT call with illegal backlight level value */
5899 static int tpacpi_brightness_set_ec(unsigned int value
)
5903 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5906 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
5907 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
5908 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
5914 /* call with brightness_mutex held! */
5915 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
5918 unsigned int current_value
, i
;
5920 current_value
= tpacpi_brightness_nvram_get();
5922 if (value
== current_value
)
5925 cmos_cmd
= (value
> current_value
) ?
5926 TP_CMOS_BRIGHTNESS_UP
:
5927 TP_CMOS_BRIGHTNESS_DOWN
;
5928 inc
= (value
> current_value
) ? 1 : -1;
5930 for (i
= current_value
; i
!= value
; i
+= inc
)
5931 if (issue_thinkpad_cmos_command(cmos_cmd
))
5937 /* May return EINTR which can always be mapped to ERESTARTSYS */
5938 static int brightness_set(unsigned int value
)
5942 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
5946 vdbg_printk(TPACPI_DBG_BRGHT
,
5947 "set backlight level to %d\n", value
);
5949 res
= mutex_lock_killable(&brightness_mutex
);
5953 switch (brightness_mode
) {
5954 case TPACPI_BRGHT_MODE_EC
:
5955 case TPACPI_BRGHT_MODE_ECNVRAM
:
5956 res
= tpacpi_brightness_set_ec(value
);
5958 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5959 res
= tpacpi_brightness_set_ucmsstep(value
);
5965 mutex_unlock(&brightness_mutex
);
5969 /* sysfs backlight class ----------------------------------------------- */
5971 static int brightness_update_status(struct backlight_device
*bd
)
5973 unsigned int level
=
5974 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
5975 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
5976 bd
->props
.brightness
: 0;
5978 dbg_printk(TPACPI_DBG_BRGHT
,
5979 "backlight: attempt to set level to %d\n",
5982 /* it is the backlight class's job (caller) to handle
5983 * EINTR and other errors properly */
5984 return brightness_set(level
);
5987 static int brightness_get(struct backlight_device
*bd
)
5991 res
= mutex_lock_killable(&brightness_mutex
);
5995 res
= tpacpi_brightness_get_raw(&status
);
5997 mutex_unlock(&brightness_mutex
);
6002 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6005 static struct backlight_ops ibm_backlight_data
= {
6006 .get_brightness
= brightness_get
,
6007 .update_status
= brightness_update_status
,
6010 /* --------------------------------------------------------------------- */
6013 * These are only useful for models that have only one possibility
6014 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6017 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6018 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6019 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6021 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6022 /* Models with ATI GPUs known to require ECNVRAM mode */
6023 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6025 /* Models with ATI GPUs that can use ECNVRAM */
6026 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
),
6027 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6028 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6029 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6031 /* Models with Intel Extreme Graphics 2 */
6032 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
),
6033 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_NOEC
),
6034 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_NOEC
),
6036 /* Models with Intel GMA900 */
6037 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6038 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6039 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6042 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6045 unsigned long quirks
;
6047 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6049 mutex_init(&brightness_mutex
);
6051 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6052 ARRAY_SIZE(brightness_quirk_table
));
6055 * We always attempt to detect acpi support, so as to switch
6056 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6057 * going to publish a backlight interface
6059 b
= tpacpi_check_std_acpi_brightness_support();
6062 if (acpi_video_backlight_support()) {
6063 if (brightness_enable
> 1) {
6064 printk(TPACPI_NOTICE
6065 "Standard ACPI backlight interface "
6066 "available, not loading native one.\n");
6068 } else if (brightness_enable
== 1) {
6069 printk(TPACPI_NOTICE
6070 "Backlight control force enabled, even if standard "
6071 "ACPI backlight interface is available\n");
6074 if (brightness_enable
> 1) {
6075 printk(TPACPI_NOTICE
6076 "Standard ACPI backlight interface not "
6077 "available, thinkpad_acpi native "
6078 "brightness control enabled\n");
6083 if (!brightness_enable
) {
6084 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6085 "brightness support disabled by "
6086 "module parameter\n");
6092 "Unsupported brightness interface, "
6093 "please contact %s\n", TPACPI_MAIL
);
6097 tp_features
.bright_16levels
= 1;
6100 * Check for module parameter bogosity, note that we
6101 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6102 * able to detect "unspecified"
6104 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6107 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6108 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6109 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6110 if (quirks
& TPACPI_BRGHT_Q_EC
)
6111 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6113 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6115 dbg_printk(TPACPI_DBG_BRGHT
,
6116 "driver auto-selected brightness_mode=%d\n",
6121 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6122 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6123 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6126 if (tpacpi_brightness_get_raw(&b
) < 0)
6129 if (tp_features
.bright_16levels
)
6131 "detected a 16-level brightness capable ThinkPad\n");
6133 ibm_backlight_device
= backlight_device_register(
6134 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6135 &ibm_backlight_data
);
6136 if (IS_ERR(ibm_backlight_device
)) {
6137 int rc
= PTR_ERR(ibm_backlight_device
);
6138 ibm_backlight_device
= NULL
;
6139 printk(TPACPI_ERR
"Could not register backlight device\n");
6142 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6143 "brightness is supported\n");
6145 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6146 printk(TPACPI_NOTICE
6147 "brightness: will use unverified default: "
6148 "brightness_mode=%d\n", brightness_mode
);
6149 printk(TPACPI_NOTICE
6150 "brightness: please report to %s whether it works well "
6151 "or not on your ThinkPad\n", TPACPI_MAIL
);
6154 ibm_backlight_device
->props
.max_brightness
=
6155 (tp_features
.bright_16levels
)? 15 : 7;
6156 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6157 backlight_update_status(ibm_backlight_device
);
6162 static void brightness_suspend(pm_message_t state
)
6164 tpacpi_brightness_checkpoint_nvram();
6167 static void brightness_shutdown(void)
6169 tpacpi_brightness_checkpoint_nvram();
6172 static void brightness_exit(void)
6174 if (ibm_backlight_device
) {
6175 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6176 "calling backlight_device_unregister()\n");
6177 backlight_device_unregister(ibm_backlight_device
);
6180 tpacpi_brightness_checkpoint_nvram();
6183 static int brightness_read(char *p
)
6188 level
= brightness_get(NULL
);
6190 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
6192 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
6193 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
6194 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
6195 " (<level> is 0-%d)\n",
6196 (tp_features
.bright_16levels
) ? 15 : 7);
6202 static int brightness_write(char *buf
)
6207 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6209 level
= brightness_get(NULL
);
6213 while ((cmd
= next_cmd(&buf
))) {
6214 if (strlencmp(cmd
, "up") == 0) {
6215 if (level
< max_level
)
6217 } else if (strlencmp(cmd
, "down") == 0) {
6220 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6221 level
>= 0 && level
<= max_level
) {
6227 tpacpi_disclose_usertask("procfs brightness",
6228 "set level to %d\n", level
);
6231 * Now we know what the final level should be, so we try to set it.
6232 * Doing it this way makes the syscall restartable in case of EINTR
6234 rc
= brightness_set(level
);
6235 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
6238 static struct ibm_struct brightness_driver_data
= {
6239 .name
= "brightness",
6240 .read
= brightness_read
,
6241 .write
= brightness_write
,
6242 .exit
= brightness_exit
,
6243 .suspend
= brightness_suspend
,
6244 .shutdown
= brightness_shutdown
,
6247 /*************************************************************************
6251 static int volume_offset
= 0x30;
6253 static int volume_read(char *p
)
6258 if (!acpi_ec_read(volume_offset
, &level
)) {
6259 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
6261 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
6262 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
6263 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
6264 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
6265 " (<level> is 0-15)\n");
6271 static int volume_write(char *buf
)
6273 int cmos_cmd
, inc
, i
;
6275 int new_level
, new_mute
;
6278 while ((cmd
= next_cmd(&buf
))) {
6279 if (!acpi_ec_read(volume_offset
, &level
))
6281 new_mute
= mute
= level
& 0x40;
6282 new_level
= level
= level
& 0xf;
6284 if (strlencmp(cmd
, "up") == 0) {
6288 new_level
= level
== 15 ? 15 : level
+ 1;
6289 } else if (strlencmp(cmd
, "down") == 0) {
6293 new_level
= level
== 0 ? 0 : level
- 1;
6294 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
6295 new_level
>= 0 && new_level
<= 15) {
6297 } else if (strlencmp(cmd
, "mute") == 0) {
6302 if (new_level
!= level
) {
6303 /* mute doesn't change */
6305 cmos_cmd
= (new_level
> level
) ?
6306 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
6307 inc
= new_level
> level
? 1 : -1;
6309 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
6310 !acpi_ec_write(volume_offset
, level
)))
6313 for (i
= level
; i
!= new_level
; i
+= inc
)
6314 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
6315 !acpi_ec_write(volume_offset
, i
+ inc
))
6319 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
6320 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
6325 if (new_mute
!= mute
) {
6326 /* level doesn't change */
6328 cmos_cmd
= (new_mute
) ?
6329 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
6331 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
6332 !acpi_ec_write(volume_offset
, level
+ new_mute
))
6340 static struct ibm_struct volume_driver_data
= {
6342 .read
= volume_read
,
6343 .write
= volume_write
,
6346 /*************************************************************************
6353 * TPACPI_FAN_RD_ACPI_GFAN:
6354 * ACPI GFAN method: returns fan level
6356 * see TPACPI_FAN_WR_ACPI_SFAN
6357 * EC 0x2f (HFSP) not available if GFAN exists
6359 * TPACPI_FAN_WR_ACPI_SFAN:
6360 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
6362 * EC 0x2f (HFSP) might be available *for reading*, but do not use
6365 * TPACPI_FAN_WR_TPEC:
6366 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
6367 * Supported on almost all ThinkPads
6369 * Fan speed changes of any sort (including those caused by the
6370 * disengaged mode) are usually done slowly by the firmware as the
6371 * maximum ammount of fan duty cycle change per second seems to be
6374 * Reading is not available if GFAN exists.
6375 * Writing is not available if SFAN exists.
6378 * 7 automatic mode engaged;
6379 * (default operation mode of the ThinkPad)
6380 * fan level is ignored in this mode.
6381 * 6 full speed mode (takes precedence over bit 7);
6382 * not available on all thinkpads. May disable
6383 * the tachometer while the fan controller ramps up
6384 * the speed (which can take up to a few *minutes*).
6385 * Speeds up fan to 100% duty-cycle, which is far above
6386 * the standard RPM levels. It is not impossible that
6387 * it could cause hardware damage.
6388 * 5-3 unused in some models. Extra bits for fan level
6389 * in others, but still useless as all values above
6390 * 7 map to the same speed as level 7 in these models.
6391 * 2-0 fan level (0..7 usually)
6393 * 0x07 = max (set when temperatures critical)
6394 * Some ThinkPads may have other levels, see
6395 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
6397 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
6398 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
6399 * does so, its initial value is meaningless (0x07).
6401 * For firmware bugs, refer to:
6402 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6406 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
6407 * Main fan tachometer reading (in RPM)
6409 * This register is present on all ThinkPads with a new-style EC, and
6410 * it is known not to be present on the A21m/e, and T22, as there is
6411 * something else in offset 0x84 according to the ACPI DSDT. Other
6412 * ThinkPads from this same time period (and earlier) probably lack the
6413 * tachometer as well.
6415 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
6416 * was never fixed by IBM to report the EC firmware version string
6417 * probably support the tachometer (like the early X models), so
6418 * detecting it is quite hard. We need more data to know for sure.
6420 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
6423 * FIRMWARE BUG: may go stale while the EC is switching to full speed
6426 * For firmware bugs, refer to:
6427 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6431 * ThinkPad EC register 0x31 bit 0 (only on select models)
6433 * When bit 0 of EC register 0x31 is zero, the tachometer registers
6434 * show the speed of the main fan. When bit 0 of EC register 0x31
6435 * is one, the tachometer registers show the speed of the auxiliary
6438 * Fan control seems to affect both fans, regardless of the state
6441 * So far, only the firmware for the X60/X61 non-tablet versions
6442 * seem to support this (firmware TP-7M).
6444 * TPACPI_FAN_WR_ACPI_FANS:
6445 * ThinkPad X31, X40, X41. Not available in the X60.
6447 * FANS ACPI handle: takes three arguments: low speed, medium speed,
6448 * high speed. ACPI DSDT seems to map these three speeds to levels
6449 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
6450 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
6452 * The speeds are stored on handles
6453 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
6455 * There are three default speed sets, acessible as handles:
6456 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
6458 * ACPI DSDT switches which set is in use depending on various
6461 * TPACPI_FAN_WR_TPEC is also available and should be used to
6462 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
6463 * but the ACPI tables just mention level 7.
6466 enum { /* Fan control constants */
6467 fan_status_offset
= 0x2f, /* EC register 0x2f */
6468 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
6469 * 0x84 must be read before 0x85 */
6470 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
6471 bit 0 selects which fan is active */
6473 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
6474 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
6476 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
6479 enum fan_status_access_mode
{
6480 TPACPI_FAN_NONE
= 0, /* No fan status or control */
6481 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
6482 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
6485 enum fan_control_access_mode
{
6486 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
6487 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
6488 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
6489 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
6492 enum fan_control_commands
{
6493 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
6494 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
6495 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
6496 * and also watchdog cmd */
6499 static int fan_control_allowed
;
6501 static enum fan_status_access_mode fan_status_access_mode
;
6502 static enum fan_control_access_mode fan_control_access_mode
;
6503 static enum fan_control_commands fan_control_commands
;
6505 static u8 fan_control_initial_status
;
6506 static u8 fan_control_desired_level
;
6507 static u8 fan_control_resume_level
;
6508 static int fan_watchdog_maxinterval
;
6510 static struct mutex fan_mutex
;
6512 static void fan_watchdog_fire(struct work_struct
*ignored
);
6513 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
6515 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
6516 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
6517 "\\FSPD", /* 600e/x, 770e, 770x */
6519 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
6520 "JFNS", /* 770x-JL */
6524 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
6525 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
6526 * be in auto mode (0x80).
6528 * This is corrected by any write to HFSP either by the driver, or
6531 * We assume 0x07 really means auto mode while this quirk is active,
6532 * as this is far more likely than the ThinkPad being in level 7,
6533 * which is only used by the firmware during thermal emergencies.
6535 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
6536 * TP-70 (T43, R52), which are known to be buggy.
6539 static void fan_quirk1_setup(void)
6541 if (fan_control_initial_status
== 0x07) {
6542 printk(TPACPI_NOTICE
6543 "fan_init: initial fan status is unknown, "
6544 "assuming it is in auto mode\n");
6545 tp_features
.fan_ctrl_status_undef
= 1;
6549 static void fan_quirk1_handle(u8
*fan_status
)
6551 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6552 if (*fan_status
!= fan_control_initial_status
) {
6553 /* something changed the HFSP regisnter since
6554 * driver init time, so it is not undefined
6556 tp_features
.fan_ctrl_status_undef
= 0;
6558 /* Return most likely status. In fact, it
6559 * might be the only possible status */
6560 *fan_status
= TP_EC_FAN_AUTO
;
6565 /* Select main fan on X60/X61, NOOP on others */
6566 static bool fan_select_fan1(void)
6568 if (tp_features
.second_fan
) {
6571 if (ec_read(fan_select_offset
, &val
) < 0)
6574 if (ec_write(fan_select_offset
, val
) < 0)
6580 /* Select secondary fan on X60/X61 */
6581 static bool fan_select_fan2(void)
6585 if (!tp_features
.second_fan
)
6588 if (ec_read(fan_select_offset
, &val
) < 0)
6591 if (ec_write(fan_select_offset
, val
) < 0)
6598 * Call with fan_mutex held
6600 static void fan_update_desired_level(u8 status
)
6603 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6605 fan_control_desired_level
= 7;
6607 fan_control_desired_level
= status
;
6611 static int fan_get_status(u8
*status
)
6616 * Add TPACPI_FAN_RD_ACPI_FANS ? */
6618 switch (fan_status_access_mode
) {
6619 case TPACPI_FAN_RD_ACPI_GFAN
:
6620 /* 570, 600e/x, 770e, 770x */
6622 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
6630 case TPACPI_FAN_RD_TPEC
:
6631 /* all except 570, 600e/x, 770e, 770x */
6632 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
6635 if (likely(status
)) {
6637 fan_quirk1_handle(status
);
6649 static int fan_get_status_safe(u8
*status
)
6654 if (mutex_lock_killable(&fan_mutex
))
6655 return -ERESTARTSYS
;
6656 rc
= fan_get_status(&s
);
6658 fan_update_desired_level(s
);
6659 mutex_unlock(&fan_mutex
);
6667 static int fan_get_speed(unsigned int *speed
)
6671 switch (fan_status_access_mode
) {
6672 case TPACPI_FAN_RD_TPEC
:
6673 /* all except 570, 600e/x, 770e, 770x */
6674 if (unlikely(!fan_select_fan1()))
6676 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
6677 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
6681 *speed
= (hi
<< 8) | lo
;
6692 static int fan2_get_speed(unsigned int *speed
)
6697 switch (fan_status_access_mode
) {
6698 case TPACPI_FAN_RD_TPEC
:
6699 /* all except 570, 600e/x, 770e, 770x */
6700 if (unlikely(!fan_select_fan2()))
6702 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
6703 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
6704 fan_select_fan1(); /* play it safe */
6709 *speed
= (hi
<< 8) | lo
;
6720 static int fan_set_level(int level
)
6722 if (!fan_control_allowed
)
6725 switch (fan_control_access_mode
) {
6726 case TPACPI_FAN_WR_ACPI_SFAN
:
6727 if (level
>= 0 && level
<= 7) {
6728 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
6734 case TPACPI_FAN_WR_ACPI_FANS
:
6735 case TPACPI_FAN_WR_TPEC
:
6736 if (!(level
& TP_EC_FAN_AUTO
) &&
6737 !(level
& TP_EC_FAN_FULLSPEED
) &&
6738 ((level
< 0) || (level
> 7)))
6741 /* safety net should the EC not support AUTO
6742 * or FULLSPEED mode bits and just ignore them */
6743 if (level
& TP_EC_FAN_FULLSPEED
)
6744 level
|= 7; /* safety min speed 7 */
6745 else if (level
& TP_EC_FAN_AUTO
)
6746 level
|= 4; /* safety min speed 4 */
6748 if (!acpi_ec_write(fan_status_offset
, level
))
6751 tp_features
.fan_ctrl_status_undef
= 0;
6758 vdbg_printk(TPACPI_DBG_FAN
,
6759 "fan control: set fan control register to 0x%02x\n", level
);
6763 static int fan_set_level_safe(int level
)
6767 if (!fan_control_allowed
)
6770 if (mutex_lock_killable(&fan_mutex
))
6771 return -ERESTARTSYS
;
6773 if (level
== TPACPI_FAN_LAST_LEVEL
)
6774 level
= fan_control_desired_level
;
6776 rc
= fan_set_level(level
);
6778 fan_update_desired_level(level
);
6780 mutex_unlock(&fan_mutex
);
6784 static int fan_set_enable(void)
6789 if (!fan_control_allowed
)
6792 if (mutex_lock_killable(&fan_mutex
))
6793 return -ERESTARTSYS
;
6795 switch (fan_control_access_mode
) {
6796 case TPACPI_FAN_WR_ACPI_FANS
:
6797 case TPACPI_FAN_WR_TPEC
:
6798 rc
= fan_get_status(&s
);
6802 /* Don't go out of emergency fan mode */
6805 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
6808 if (!acpi_ec_write(fan_status_offset
, s
))
6811 tp_features
.fan_ctrl_status_undef
= 0;
6816 case TPACPI_FAN_WR_ACPI_SFAN
:
6817 rc
= fan_get_status(&s
);
6823 /* Set fan to at least level 4 */
6826 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
6836 mutex_unlock(&fan_mutex
);
6839 vdbg_printk(TPACPI_DBG_FAN
,
6840 "fan control: set fan control register to 0x%02x\n",
6845 static int fan_set_disable(void)
6849 if (!fan_control_allowed
)
6852 if (mutex_lock_killable(&fan_mutex
))
6853 return -ERESTARTSYS
;
6856 switch (fan_control_access_mode
) {
6857 case TPACPI_FAN_WR_ACPI_FANS
:
6858 case TPACPI_FAN_WR_TPEC
:
6859 if (!acpi_ec_write(fan_status_offset
, 0x00))
6862 fan_control_desired_level
= 0;
6863 tp_features
.fan_ctrl_status_undef
= 0;
6867 case TPACPI_FAN_WR_ACPI_SFAN
:
6868 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
6871 fan_control_desired_level
= 0;
6879 vdbg_printk(TPACPI_DBG_FAN
,
6880 "fan control: set fan control register to 0\n");
6882 mutex_unlock(&fan_mutex
);
6886 static int fan_set_speed(int speed
)
6890 if (!fan_control_allowed
)
6893 if (mutex_lock_killable(&fan_mutex
))
6894 return -ERESTARTSYS
;
6897 switch (fan_control_access_mode
) {
6898 case TPACPI_FAN_WR_ACPI_FANS
:
6899 if (speed
>= 0 && speed
<= 65535) {
6900 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
6901 speed
, speed
, speed
))
6911 mutex_unlock(&fan_mutex
);
6915 static void fan_watchdog_reset(void)
6917 static int fan_watchdog_active
;
6919 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
6922 if (fan_watchdog_active
)
6923 cancel_delayed_work(&fan_watchdog_task
);
6925 if (fan_watchdog_maxinterval
> 0 &&
6926 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
6927 fan_watchdog_active
= 1;
6928 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
6929 msecs_to_jiffies(fan_watchdog_maxinterval
6932 "failed to queue the fan watchdog, "
6933 "watchdog will not trigger\n");
6936 fan_watchdog_active
= 0;
6939 static void fan_watchdog_fire(struct work_struct
*ignored
)
6943 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
6946 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
6947 rc
= fan_set_enable();
6949 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
6950 "will try again later...\n", -rc
);
6951 /* reschedule for later */
6952 fan_watchdog_reset();
6957 * SYSFS fan layout: hwmon compatible (device)
6960 * 0: "disengaged" mode
6962 * 2: native EC "auto" mode (recommended, hardware default)
6964 * pwm*: set speed in manual mode, ignored otherwise.
6965 * 0 is level 0; 255 is level 7. Intermediate points done with linear
6968 * fan*_input: tachometer reading, RPM
6971 * SYSFS fan layout: extensions
6973 * fan_watchdog (driver):
6974 * fan watchdog interval in seconds, 0 disables (default), max 120
6977 /* sysfs fan pwm1_enable ----------------------------------------------- */
6978 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
6979 struct device_attribute
*attr
,
6985 res
= fan_get_status_safe(&status
);
6989 if (status
& TP_EC_FAN_FULLSPEED
) {
6991 } else if (status
& TP_EC_FAN_AUTO
) {
6996 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
6999 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7000 struct device_attribute
*attr
,
7001 const char *buf
, size_t count
)
7006 if (parse_strtoul(buf
, 2, &t
))
7009 tpacpi_disclose_usertask("hwmon pwm1_enable",
7010 "set fan mode to %lu\n", t
);
7014 level
= TP_EC_FAN_FULLSPEED
;
7017 level
= TPACPI_FAN_LAST_LEVEL
;
7020 level
= TP_EC_FAN_AUTO
;
7023 /* reserved for software-controlled auto mode */
7029 res
= fan_set_level_safe(level
);
7035 fan_watchdog_reset();
7040 static struct device_attribute dev_attr_fan_pwm1_enable
=
7041 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7042 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7044 /* sysfs fan pwm1 ------------------------------------------------------ */
7045 static ssize_t
fan_pwm1_show(struct device
*dev
,
7046 struct device_attribute
*attr
,
7052 res
= fan_get_status_safe(&status
);
7057 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7058 status
= fan_control_desired_level
;
7063 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7066 static ssize_t
fan_pwm1_store(struct device
*dev
,
7067 struct device_attribute
*attr
,
7068 const char *buf
, size_t count
)
7072 u8 status
, newlevel
;
7074 if (parse_strtoul(buf
, 255, &s
))
7077 tpacpi_disclose_usertask("hwmon pwm1",
7078 "set fan speed to %lu\n", s
);
7080 /* scale down from 0-255 to 0-7 */
7081 newlevel
= (s
>> 5) & 0x07;
7083 if (mutex_lock_killable(&fan_mutex
))
7084 return -ERESTARTSYS
;
7086 rc
= fan_get_status(&status
);
7087 if (!rc
&& (status
&
7088 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7089 rc
= fan_set_level(newlevel
);
7093 fan_update_desired_level(newlevel
);
7094 fan_watchdog_reset();
7098 mutex_unlock(&fan_mutex
);
7099 return (rc
)? rc
: count
;
7102 static struct device_attribute dev_attr_fan_pwm1
=
7103 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7104 fan_pwm1_show
, fan_pwm1_store
);
7106 /* sysfs fan fan1_input ------------------------------------------------ */
7107 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7108 struct device_attribute
*attr
,
7114 res
= fan_get_speed(&speed
);
7118 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7121 static struct device_attribute dev_attr_fan_fan1_input
=
7122 __ATTR(fan1_input
, S_IRUGO
,
7123 fan_fan1_input_show
, NULL
);
7125 /* sysfs fan fan2_input ------------------------------------------------ */
7126 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7127 struct device_attribute
*attr
,
7133 res
= fan2_get_speed(&speed
);
7137 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7140 static struct device_attribute dev_attr_fan_fan2_input
=
7141 __ATTR(fan2_input
, S_IRUGO
,
7142 fan_fan2_input_show
, NULL
);
7144 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
7145 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
7148 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
7151 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
7152 const char *buf
, size_t count
)
7156 if (parse_strtoul(buf
, 120, &t
))
7159 if (!fan_control_allowed
)
7162 fan_watchdog_maxinterval
= t
;
7163 fan_watchdog_reset();
7165 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
7170 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
7171 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
7173 /* --------------------------------------------------------------------- */
7174 static struct attribute
*fan_attributes
[] = {
7175 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
7176 &dev_attr_fan_fan1_input
.attr
,
7177 NULL
, /* for fan2_input */
7181 static const struct attribute_group fan_attr_group
= {
7182 .attrs
= fan_attributes
,
7185 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
7186 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
7188 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7189 { .vendor = PCI_VENDOR_ID_IBM, \
7190 .bios = TPACPI_MATCH_ANY, \
7191 .ec = TPID(__id1, __id2), \
7192 .quirks = __quirks }
7194 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7195 { .vendor = PCI_VENDOR_ID_LENOVO, \
7196 .bios = TPACPI_MATCH_ANY, \
7197 .ec = TPID(__id1, __id2), \
7198 .quirks = __quirks }
7200 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
7201 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
7202 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
7203 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
7204 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
7205 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
7208 #undef TPACPI_FAN_QL
7209 #undef TPACPI_FAN_QI
7211 static int __init
fan_init(struct ibm_init_struct
*iibm
)
7214 unsigned long quirks
;
7216 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7217 "initializing fan subdriver\n");
7219 mutex_init(&fan_mutex
);
7220 fan_status_access_mode
= TPACPI_FAN_NONE
;
7221 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7222 fan_control_commands
= 0;
7223 fan_watchdog_maxinterval
= 0;
7224 tp_features
.fan_ctrl_status_undef
= 0;
7225 tp_features
.second_fan
= 0;
7226 fan_control_desired_level
= 7;
7228 TPACPI_ACPIHANDLE_INIT(fans
);
7229 TPACPI_ACPIHANDLE_INIT(gfan
);
7230 TPACPI_ACPIHANDLE_INIT(sfan
);
7232 quirks
= tpacpi_check_quirks(fan_quirk_table
,
7233 ARRAY_SIZE(fan_quirk_table
));
7236 /* 570, 600e/x, 770e, 770x */
7237 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7239 /* all other ThinkPads: note that even old-style
7240 * ThinkPad ECs supports the fan control register */
7241 if (likely(acpi_ec_read(fan_status_offset
,
7242 &fan_control_initial_status
))) {
7243 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7244 if (quirks
& TPACPI_FAN_Q1
)
7246 if (quirks
& TPACPI_FAN_2FAN
) {
7247 tp_features
.second_fan
= 1;
7248 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7249 "secondary fan support enabled\n");
7253 "ThinkPad ACPI EC access misbehaving, "
7254 "fan status and control unavailable\n");
7261 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
7262 fan_control_commands
|=
7263 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
7266 /* gfan without sfan means no fan control */
7267 /* all other models implement TP EC 0x2f control */
7271 fan_control_access_mode
=
7272 TPACPI_FAN_WR_ACPI_FANS
;
7273 fan_control_commands
|=
7274 TPACPI_FAN_CMD_SPEED
|
7275 TPACPI_FAN_CMD_LEVEL
|
7276 TPACPI_FAN_CMD_ENABLE
;
7278 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
7279 fan_control_commands
|=
7280 TPACPI_FAN_CMD_LEVEL
|
7281 TPACPI_FAN_CMD_ENABLE
;
7286 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7287 "fan is %s, modes %d, %d\n",
7288 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
7289 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
7290 fan_status_access_mode
, fan_control_access_mode
);
7292 /* fan control master switch */
7293 if (!fan_control_allowed
) {
7294 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7295 fan_control_commands
= 0;
7296 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7297 "fan control features disabled by parameter\n");
7300 /* update fan_control_desired_level */
7301 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
7302 fan_get_status_safe(NULL
);
7304 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
7305 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
7306 if (tp_features
.second_fan
) {
7307 /* attach second fan tachometer */
7308 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
7309 &dev_attr_fan_fan2_input
.attr
;
7311 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7316 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
7317 &driver_attr_fan_watchdog
);
7319 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7328 static void fan_exit(void)
7330 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
7331 "cancelling any pending fan watchdog tasks\n");
7333 /* FIXME: can we really do this unconditionally? */
7334 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
7335 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
7336 &driver_attr_fan_watchdog
);
7338 cancel_delayed_work(&fan_watchdog_task
);
7339 flush_workqueue(tpacpi_wq
);
7342 static void fan_suspend(pm_message_t state
)
7346 if (!fan_control_allowed
)
7349 /* Store fan status in cache */
7350 fan_control_resume_level
= 0;
7351 rc
= fan_get_status_safe(&fan_control_resume_level
);
7353 printk(TPACPI_NOTICE
7354 "failed to read fan level for later "
7355 "restore during resume: %d\n", rc
);
7357 /* if it is undefined, don't attempt to restore it.
7359 if (tp_features
.fan_ctrl_status_undef
)
7360 fan_control_resume_level
= 0;
7363 static void fan_resume(void)
7365 u8 current_level
= 7;
7366 bool do_set
= false;
7369 /* DSDT *always* updates status on resume */
7370 tp_features
.fan_ctrl_status_undef
= 0;
7372 if (!fan_control_allowed
||
7373 !fan_control_resume_level
||
7374 (fan_get_status_safe(¤t_level
) < 0))
7377 switch (fan_control_access_mode
) {
7378 case TPACPI_FAN_WR_ACPI_SFAN
:
7379 /* never decrease fan level */
7380 do_set
= (fan_control_resume_level
> current_level
);
7382 case TPACPI_FAN_WR_ACPI_FANS
:
7383 case TPACPI_FAN_WR_TPEC
:
7384 /* never decrease fan level, scale is:
7385 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
7387 * We expect the firmware to set either 7 or AUTO, but we
7388 * handle FULLSPEED out of paranoia.
7390 * So, we can safely only restore FULLSPEED or 7, anything
7391 * else could slow the fan. Restoring AUTO is useless, at
7392 * best that's exactly what the DSDT already set (it is the
7395 * Always keep in mind that the DSDT *will* have set the
7396 * fans to what the vendor supposes is the best level. We
7397 * muck with it only to speed the fan up.
7399 if (fan_control_resume_level
!= 7 &&
7400 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
7403 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
7404 (current_level
!= fan_control_resume_level
);
7410 printk(TPACPI_NOTICE
7411 "restoring fan level to 0x%02x\n",
7412 fan_control_resume_level
);
7413 rc
= fan_set_level_safe(fan_control_resume_level
);
7415 printk(TPACPI_NOTICE
7416 "failed to restore fan level: %d\n", rc
);
7420 static int fan_read(char *p
)
7425 unsigned int speed
= 0;
7427 switch (fan_status_access_mode
) {
7428 case TPACPI_FAN_RD_ACPI_GFAN
:
7429 /* 570, 600e/x, 770e, 770x */
7430 rc
= fan_get_status_safe(&status
);
7434 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
7436 (status
!= 0) ? "enabled" : "disabled", status
);
7439 case TPACPI_FAN_RD_TPEC
:
7440 /* all except 570, 600e/x, 770e, 770x */
7441 rc
= fan_get_status_safe(&status
);
7445 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
7446 (status
!= 0) ? "enabled" : "disabled");
7448 rc
= fan_get_speed(&speed
);
7452 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
7454 if (status
& TP_EC_FAN_FULLSPEED
)
7455 /* Disengaged mode takes precedence */
7456 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
7457 else if (status
& TP_EC_FAN_AUTO
)
7458 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
7460 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
7463 case TPACPI_FAN_NONE
:
7465 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
7468 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
7469 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
7471 switch (fan_control_access_mode
) {
7472 case TPACPI_FAN_WR_ACPI_SFAN
:
7473 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
7477 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
7478 "auto, disengaged, full-speed)\n");
7483 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
7484 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
7485 "commands:\twatchdog <timeout> (<timeout> "
7486 "is 0 (off), 1-120 (seconds))\n");
7488 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
7489 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
7490 " (<speed> is 0-65535)\n");
7495 static int fan_write_cmd_level(const char *cmd
, int *rc
)
7499 if (strlencmp(cmd
, "level auto") == 0)
7500 level
= TP_EC_FAN_AUTO
;
7501 else if ((strlencmp(cmd
, "level disengaged") == 0) |
7502 (strlencmp(cmd
, "level full-speed") == 0))
7503 level
= TP_EC_FAN_FULLSPEED
;
7504 else if (sscanf(cmd
, "level %d", &level
) != 1)
7507 *rc
= fan_set_level_safe(level
);
7509 printk(TPACPI_ERR
"level command accepted for unsupported "
7510 "access mode %d", fan_control_access_mode
);
7512 tpacpi_disclose_usertask("procfs fan",
7513 "set level to %d\n", level
);
7518 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
7520 if (strlencmp(cmd
, "enable") != 0)
7523 *rc
= fan_set_enable();
7525 printk(TPACPI_ERR
"enable command accepted for unsupported "
7526 "access mode %d", fan_control_access_mode
);
7528 tpacpi_disclose_usertask("procfs fan", "enable\n");
7533 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
7535 if (strlencmp(cmd
, "disable") != 0)
7538 *rc
= fan_set_disable();
7540 printk(TPACPI_ERR
"disable command accepted for unsupported "
7541 "access mode %d", fan_control_access_mode
);
7543 tpacpi_disclose_usertask("procfs fan", "disable\n");
7548 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
7553 * Support speed <low> <medium> <high> ? */
7555 if (sscanf(cmd
, "speed %d", &speed
) != 1)
7558 *rc
= fan_set_speed(speed
);
7560 printk(TPACPI_ERR
"speed command accepted for unsupported "
7561 "access mode %d", fan_control_access_mode
);
7563 tpacpi_disclose_usertask("procfs fan",
7564 "set speed to %d\n", speed
);
7569 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
7573 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
7576 if (interval
< 0 || interval
> 120)
7579 fan_watchdog_maxinterval
= interval
;
7580 tpacpi_disclose_usertask("procfs fan",
7581 "set watchdog timer to %d\n",
7588 static int fan_write(char *buf
)
7593 while (!rc
&& (cmd
= next_cmd(&buf
))) {
7594 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
7595 fan_write_cmd_level(cmd
, &rc
)) &&
7596 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
7597 (fan_write_cmd_enable(cmd
, &rc
) ||
7598 fan_write_cmd_disable(cmd
, &rc
) ||
7599 fan_write_cmd_watchdog(cmd
, &rc
))) &&
7600 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
7601 fan_write_cmd_speed(cmd
, &rc
))
7605 fan_watchdog_reset();
7611 static struct ibm_struct fan_driver_data
= {
7616 .suspend
= fan_suspend
,
7617 .resume
= fan_resume
,
7620 /****************************************************************************
7621 ****************************************************************************
7625 ****************************************************************************
7626 ****************************************************************************/
7628 /* sysfs name ---------------------------------------------------------- */
7629 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
7630 struct device_attribute
*attr
,
7633 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
7636 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
7637 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
7639 /* --------------------------------------------------------------------- */
7642 static struct proc_dir_entry
*proc_dir
;
7645 * Module and infrastructure proble, init and exit handling
7648 static int force_load
;
7650 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
7651 static const char * __init
str_supported(int is_supported
)
7653 static char text_unsupported
[] __initdata
= "not supported";
7655 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
7657 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
7659 static void ibm_exit(struct ibm_struct
*ibm
)
7661 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
7663 list_del_init(&ibm
->all_drivers
);
7665 if (ibm
->flags
.acpi_notify_installed
) {
7666 dbg_printk(TPACPI_DBG_EXIT
,
7667 "%s: acpi_remove_notify_handler\n", ibm
->name
);
7669 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
7671 dispatch_acpi_notify
);
7672 ibm
->flags
.acpi_notify_installed
= 0;
7673 ibm
->flags
.acpi_notify_installed
= 0;
7676 if (ibm
->flags
.proc_created
) {
7677 dbg_printk(TPACPI_DBG_EXIT
,
7678 "%s: remove_proc_entry\n", ibm
->name
);
7679 remove_proc_entry(ibm
->name
, proc_dir
);
7680 ibm
->flags
.proc_created
= 0;
7683 if (ibm
->flags
.acpi_driver_registered
) {
7684 dbg_printk(TPACPI_DBG_EXIT
,
7685 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
7687 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
7688 kfree(ibm
->acpi
->driver
);
7689 ibm
->acpi
->driver
= NULL
;
7690 ibm
->flags
.acpi_driver_registered
= 0;
7693 if (ibm
->flags
.init_called
&& ibm
->exit
) {
7695 ibm
->flags
.init_called
= 0;
7698 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
7701 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
7704 struct ibm_struct
*ibm
= iibm
->data
;
7705 struct proc_dir_entry
*entry
;
7707 BUG_ON(ibm
== NULL
);
7709 INIT_LIST_HEAD(&ibm
->all_drivers
);
7711 if (ibm
->flags
.experimental
&& !experimental
)
7714 dbg_printk(TPACPI_DBG_INIT
,
7715 "probing for %s\n", ibm
->name
);
7718 ret
= iibm
->init(iibm
);
7720 return 0; /* probe failed */
7724 ibm
->flags
.init_called
= 1;
7728 if (ibm
->acpi
->hid
) {
7729 ret
= register_tpacpi_subdriver(ibm
);
7734 if (ibm
->acpi
->notify
) {
7735 ret
= setup_acpi_notify(ibm
);
7736 if (ret
== -ENODEV
) {
7737 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
7747 dbg_printk(TPACPI_DBG_INIT
,
7748 "%s installed\n", ibm
->name
);
7751 entry
= create_proc_entry(ibm
->name
,
7752 S_IFREG
| S_IRUGO
| S_IWUSR
,
7755 printk(TPACPI_ERR
"unable to create proc entry %s\n",
7761 entry
->read_proc
= &dispatch_procfs_read
;
7763 entry
->write_proc
= &dispatch_procfs_write
;
7764 ibm
->flags
.proc_created
= 1;
7767 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
7772 dbg_printk(TPACPI_DBG_INIT
,
7773 "%s: at error exit path with result %d\n",
7777 return (ret
< 0)? ret
: 0;
7782 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
7784 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
7787 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
7788 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
7791 return s
&& strlen(s
) >= 8 &&
7792 tpacpi_is_fw_digit(s
[0]) &&
7793 tpacpi_is_fw_digit(s
[1]) &&
7794 s
[2] == t
&& s
[3] == 'T' &&
7795 tpacpi_is_fw_digit(s
[4]) &&
7796 tpacpi_is_fw_digit(s
[5]) &&
7797 s
[6] == 'W' && s
[7] == 'W';
7800 /* returns 0 - probe ok, or < 0 - probe error.
7801 * Probe ok doesn't mean thinkpad found.
7802 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
7803 static int __must_check __init
get_thinkpad_model_data(
7804 struct thinkpad_id_data
*tp
)
7806 const struct dmi_device
*dev
= NULL
;
7807 char ec_fw_string
[18];
7813 memset(tp
, 0, sizeof(*tp
));
7815 if (dmi_name_in_vendors("IBM"))
7816 tp
->vendor
= PCI_VENDOR_ID_IBM
;
7817 else if (dmi_name_in_vendors("LENOVO"))
7818 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
7822 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
7823 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
7824 if (s
&& !tp
->bios_version_str
)
7827 /* Really ancient ThinkPad 240X will fail this, which is fine */
7828 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
7831 tp
->bios_model
= tp
->bios_version_str
[0]
7832 | (tp
->bios_version_str
[1] << 8);
7833 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
7834 | tp
->bios_version_str
[5];
7837 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
7838 * X32 or newer, all Z series; Some models must have an
7839 * up-to-date BIOS or they will not be detected.
7841 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7843 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
7844 if (sscanf(dev
->name
,
7845 "IBM ThinkPad Embedded Controller -[%17c",
7846 ec_fw_string
) == 1) {
7847 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
7848 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
7850 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
7851 if (!tp
->ec_version_str
)
7854 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
7855 tp
->ec_model
= ec_fw_string
[0]
7856 | (ec_fw_string
[1] << 8);
7857 tp
->ec_release
= (ec_fw_string
[4] << 8)
7860 printk(TPACPI_NOTICE
7861 "ThinkPad firmware release %s "
7862 "doesn't match the known patterns\n",
7864 printk(TPACPI_NOTICE
7865 "please report this to %s\n",
7872 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
7873 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
7874 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
7879 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
7880 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
7881 if (s
&& !tp
->nummodel_str
)
7887 static int __init
probe_for_thinkpad(void)
7895 * Non-ancient models have better DMI tagging, but very old models
7896 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
7898 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
7899 (thinkpad_id
.ec_model
!= 0) ||
7900 tpacpi_is_fw_known();
7902 /* ec is required because many other handles are relative to it */
7903 TPACPI_ACPIHANDLE_INIT(ec
);
7907 "Not yet supported ThinkPad detected!\n");
7911 if (!is_thinkpad
&& !force_load
)
7918 /* Module init, exit, parameters */
7920 static struct ibm_init_struct ibms_init
[] __initdata
= {
7922 .init
= thinkpad_acpi_driver_init
,
7923 .data
= &thinkpad_acpi_driver_data
,
7926 .init
= hotkey_init
,
7927 .data
= &hotkey_driver_data
,
7930 .init
= bluetooth_init
,
7931 .data
= &bluetooth_driver_data
,
7935 .data
= &wan_driver_data
,
7939 .data
= &uwb_driver_data
,
7941 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
7944 .data
= &video_driver_data
,
7949 .data
= &light_driver_data
,
7953 .data
= &cmos_driver_data
,
7957 .data
= &led_driver_data
,
7961 .data
= &beep_driver_data
,
7964 .init
= thermal_init
,
7965 .data
= &thermal_driver_data
,
7968 .data
= &ecdump_driver_data
,
7971 .init
= brightness_init
,
7972 .data
= &brightness_driver_data
,
7975 .data
= &volume_driver_data
,
7979 .data
= &fan_driver_data
,
7983 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
7986 struct ibm_struct
*ibm
;
7988 if (!kp
|| !kp
->name
|| !val
)
7991 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7992 ibm
= ibms_init
[i
].data
;
7993 WARN_ON(ibm
== NULL
);
7995 if (!ibm
|| !ibm
->name
)
7998 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
7999 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8001 strcpy(ibms_init
[i
].param
, val
);
8002 strcat(ibms_init
[i
].param
, ",");
8010 module_param(experimental
, int, 0);
8011 MODULE_PARM_DESC(experimental
,
8012 "Enables experimental features when non-zero");
8014 module_param_named(debug
, dbg_level
, uint
, 0);
8015 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8017 module_param(force_load
, bool, 0);
8018 MODULE_PARM_DESC(force_load
,
8019 "Attempts to load the driver even on a "
8020 "mis-identified ThinkPad when true");
8022 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
8023 MODULE_PARM_DESC(fan_control
,
8024 "Enables setting fan parameters features when true");
8026 module_param_named(brightness_mode
, brightness_mode
, uint
, 0);
8027 MODULE_PARM_DESC(brightness_mode
,
8028 "Selects brightness control strategy: "
8029 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8031 module_param(brightness_enable
, uint
, 0);
8032 MODULE_PARM_DESC(brightness_enable
,
8033 "Enables backlight control when 1, disables when 0");
8035 module_param(hotkey_report_mode
, uint
, 0);
8036 MODULE_PARM_DESC(hotkey_report_mode
,
8037 "used for backwards compatibility with userspace, "
8038 "see documentation");
8040 #define TPACPI_PARAM(feature) \
8041 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8042 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8043 "at module load, see documentation")
8045 TPACPI_PARAM(hotkey
);
8046 TPACPI_PARAM(bluetooth
);
8047 TPACPI_PARAM(video
);
8048 TPACPI_PARAM(light
);
8052 TPACPI_PARAM(ecdump
);
8053 TPACPI_PARAM(brightness
);
8054 TPACPI_PARAM(volume
);
8057 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8058 module_param(dbg_wlswemul
, uint
, 0);
8059 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
8060 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
8061 MODULE_PARM_DESC(wlsw_state
,
8062 "Initial state of the emulated WLSW switch");
8064 module_param(dbg_bluetoothemul
, uint
, 0);
8065 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
8066 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
8067 MODULE_PARM_DESC(bluetooth_state
,
8068 "Initial state of the emulated bluetooth switch");
8070 module_param(dbg_wwanemul
, uint
, 0);
8071 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
8072 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
8073 MODULE_PARM_DESC(wwan_state
,
8074 "Initial state of the emulated WWAN switch");
8076 module_param(dbg_uwbemul
, uint
, 0);
8077 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
8078 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
8079 MODULE_PARM_DESC(uwb_state
,
8080 "Initial state of the emulated UWB switch");
8083 static void thinkpad_acpi_module_exit(void)
8085 struct ibm_struct
*ibm
, *itmp
;
8087 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
8089 list_for_each_entry_safe_reverse(ibm
, itmp
,
8090 &tpacpi_all_drivers
,
8095 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
8097 if (tpacpi_inputdev
) {
8098 if (tp_features
.input_device_registered
)
8099 input_unregister_device(tpacpi_inputdev
);
8101 input_free_device(tpacpi_inputdev
);
8105 hwmon_device_unregister(tpacpi_hwmon
);
8107 if (tp_features
.sensors_pdev_attrs_registered
)
8108 device_remove_file(&tpacpi_sensors_pdev
->dev
,
8109 &dev_attr_thinkpad_acpi_pdev_name
);
8110 if (tpacpi_sensors_pdev
)
8111 platform_device_unregister(tpacpi_sensors_pdev
);
8113 platform_device_unregister(tpacpi_pdev
);
8115 if (tp_features
.sensors_pdrv_attrs_registered
)
8116 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
8117 if (tp_features
.platform_drv_attrs_registered
)
8118 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
8120 if (tp_features
.sensors_pdrv_registered
)
8121 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
8123 if (tp_features
.platform_drv_registered
)
8124 platform_driver_unregister(&tpacpi_pdriver
);
8127 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
8130 destroy_workqueue(tpacpi_wq
);
8132 kfree(thinkpad_id
.bios_version_str
);
8133 kfree(thinkpad_id
.ec_version_str
);
8134 kfree(thinkpad_id
.model_str
);
8138 static int __init
thinkpad_acpi_module_init(void)
8142 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
8144 /* Parameter checking */
8145 if (hotkey_report_mode
> 2)
8148 /* Driver-level probe */
8150 ret
= get_thinkpad_model_data(&thinkpad_id
);
8153 "unable to get DMI data: %d\n", ret
);
8154 thinkpad_acpi_module_exit();
8157 ret
= probe_for_thinkpad();
8159 thinkpad_acpi_module_exit();
8163 /* Driver initialization */
8165 TPACPI_ACPIHANDLE_INIT(ecrd
);
8166 TPACPI_ACPIHANDLE_INIT(ecwr
);
8168 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
8170 thinkpad_acpi_module_exit();
8174 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
8177 "unable to create proc dir " TPACPI_PROC_DIR
);
8178 thinkpad_acpi_module_exit();
8182 ret
= platform_driver_register(&tpacpi_pdriver
);
8185 "unable to register main platform driver\n");
8186 thinkpad_acpi_module_exit();
8189 tp_features
.platform_drv_registered
= 1;
8191 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
8194 "unable to register hwmon platform driver\n");
8195 thinkpad_acpi_module_exit();
8198 tp_features
.sensors_pdrv_registered
= 1;
8200 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
8202 tp_features
.platform_drv_attrs_registered
= 1;
8203 ret
= tpacpi_create_driver_attributes(
8204 &tpacpi_hwmon_pdriver
.driver
);
8208 "unable to create sysfs driver attributes\n");
8209 thinkpad_acpi_module_exit();
8212 tp_features
.sensors_pdrv_attrs_registered
= 1;
8215 /* Device initialization */
8216 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
8218 if (IS_ERR(tpacpi_pdev
)) {
8219 ret
= PTR_ERR(tpacpi_pdev
);
8221 printk(TPACPI_ERR
"unable to register platform device\n");
8222 thinkpad_acpi_module_exit();
8225 tpacpi_sensors_pdev
= platform_device_register_simple(
8226 TPACPI_HWMON_DRVR_NAME
,
8228 if (IS_ERR(tpacpi_sensors_pdev
)) {
8229 ret
= PTR_ERR(tpacpi_sensors_pdev
);
8230 tpacpi_sensors_pdev
= NULL
;
8232 "unable to register hwmon platform device\n");
8233 thinkpad_acpi_module_exit();
8236 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
8237 &dev_attr_thinkpad_acpi_pdev_name
);
8240 "unable to create sysfs hwmon device attributes\n");
8241 thinkpad_acpi_module_exit();
8244 tp_features
.sensors_pdev_attrs_registered
= 1;
8245 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
8246 if (IS_ERR(tpacpi_hwmon
)) {
8247 ret
= PTR_ERR(tpacpi_hwmon
);
8248 tpacpi_hwmon
= NULL
;
8249 printk(TPACPI_ERR
"unable to register hwmon device\n");
8250 thinkpad_acpi_module_exit();
8253 mutex_init(&tpacpi_inputdev_send_mutex
);
8254 tpacpi_inputdev
= input_allocate_device();
8255 if (!tpacpi_inputdev
) {
8256 printk(TPACPI_ERR
"unable to allocate input device\n");
8257 thinkpad_acpi_module_exit();
8260 /* Prepare input device, but don't register */
8261 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
8262 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
8263 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
8264 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
8265 thinkpad_id
.vendor
:
8267 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
8268 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
8270 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8271 ret
= ibm_init(&ibms_init
[i
]);
8272 if (ret
>= 0 && *ibms_init
[i
].param
)
8273 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
8275 thinkpad_acpi_module_exit();
8279 ret
= input_register_device(tpacpi_inputdev
);
8281 printk(TPACPI_ERR
"unable to register input device\n");
8282 thinkpad_acpi_module_exit();
8285 tp_features
.input_device_registered
= 1;
8288 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
8292 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
8295 * This will autoload the driver in almost every ThinkPad
8296 * in widespread use.
8298 * Only _VERY_ old models, like the 240, 240x and 570 lack
8299 * the HKEY event interface.
8301 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
8304 * DMI matching for module autoloading
8306 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8307 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
8309 * Only models listed in thinkwiki will be supported, so add yours
8310 * if it is not there yet.
8312 #define IBM_BIOS_MODULE_ALIAS(__type) \
8313 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
8315 /* Ancient thinkpad BIOSes have to be identified by
8316 * BIOS type or model number, and there are far less
8317 * BIOS types than model numbers... */
8318 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
8320 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
8321 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
8322 MODULE_DESCRIPTION(TPACPI_DESC
);
8323 MODULE_VERSION(TPACPI_VERSION
);
8324 MODULE_LICENSE("GPL");
8326 module_init(thinkpad_acpi_module_init
);
8327 module_exit(thinkpad_acpi_module_exit
);