2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define TPACPI_VERSION "0.23"
25 #define TPACPI_SYSFS_VERSION 0x020400
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/sched.h>
58 #include <linux/kthread.h>
59 #include <linux/freezer.h>
60 #include <linux/delay.h>
62 #include <linux/nvram.h>
63 #include <linux/proc_fs.h>
64 #include <linux/sysfs.h>
65 #include <linux/backlight.h>
67 #include <linux/platform_device.h>
68 #include <linux/hwmon.h>
69 #include <linux/hwmon-sysfs.h>
70 #include <linux/input.h>
71 #include <linux/leds.h>
72 #include <linux/rfkill.h>
73 #include <asm/uaccess.h>
75 #include <linux/dmi.h>
76 #include <linux/jiffies.h>
77 #include <linux/workqueue.h>
79 #include <acpi/acpi_drivers.h>
81 #include <linux/pci_ids.h>
84 /* ThinkPad CMOS commands */
85 #define TP_CMOS_VOLUME_DOWN 0
86 #define TP_CMOS_VOLUME_UP 1
87 #define TP_CMOS_VOLUME_MUTE 2
88 #define TP_CMOS_BRIGHTNESS_UP 4
89 #define TP_CMOS_BRIGHTNESS_DOWN 5
90 #define TP_CMOS_THINKLIGHT_ON 12
91 #define TP_CMOS_THINKLIGHT_OFF 13
95 TP_NVRAM_ADDR_HK2
= 0x57,
96 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
97 TP_NVRAM_ADDR_VIDEO
= 0x59,
98 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
99 TP_NVRAM_ADDR_MIXER
= 0x60,
102 /* NVRAM bit masks */
104 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
105 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
106 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
107 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
108 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
109 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
110 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
111 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
112 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
113 TP_NVRAM_MASK_MUTE
= 0x40,
114 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
115 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
116 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
120 #define TPACPI_ACPI_HKEY_HID "IBM0068"
123 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
124 #define TPACPI_HKEY_INPUT_VERSION 0x4101
126 /* ACPI \WGSV commands */
128 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
129 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
130 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
131 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
134 /* TP_ACPI_WGSV_GET_STATE bits */
136 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
137 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
138 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
139 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
140 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
141 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
142 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
143 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
144 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
145 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
148 /****************************************************************************
152 #define TPACPI_NAME "thinkpad"
153 #define TPACPI_DESC "ThinkPad ACPI Extras"
154 #define TPACPI_FILE TPACPI_NAME "_acpi"
155 #define TPACPI_URL "http://ibm-acpi.sf.net/"
156 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
158 #define TPACPI_PROC_DIR "ibm"
159 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
160 #define TPACPI_DRVR_NAME TPACPI_FILE
161 #define TPACPI_DRVR_SHORTNAME "tpacpi"
162 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
164 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
165 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
167 #define TPACPI_MAX_ACPI_ARGS 3
169 /* rfkill switches */
171 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
172 TPACPI_RFK_WWAN_SW_ID
,
173 TPACPI_RFK_UWB_SW_ID
,
177 #define TPACPI_LOG TPACPI_FILE ": "
178 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
179 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
180 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
181 #define TPACPI_ERR KERN_ERR TPACPI_LOG
182 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
183 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
184 #define TPACPI_INFO KERN_INFO TPACPI_LOG
185 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
187 /* Debugging printk groups */
188 #define TPACPI_DBG_ALL 0xffff
189 #define TPACPI_DBG_DISCLOSETASK 0x8000
190 #define TPACPI_DBG_INIT 0x0001
191 #define TPACPI_DBG_EXIT 0x0002
192 #define TPACPI_DBG_RFKILL 0x0004
193 #define TPACPI_DBG_HKEY 0x0008
194 #define TPACPI_DBG_FAN 0x0010
195 #define TPACPI_DBG_BRGHT 0x0020
197 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
198 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
199 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
202 /****************************************************************************
203 * Driver-wide structs and misc. variables
208 struct tp_acpi_drv_struct
{
209 const struct acpi_device_id
*hid
;
210 struct acpi_driver
*driver
;
212 void (*notify
) (struct ibm_struct
*, u32
);
215 struct acpi_device
*device
;
221 int (*read
) (char *);
222 int (*write
) (char *);
224 void (*resume
) (void);
225 void (*suspend
) (pm_message_t state
);
226 void (*shutdown
) (void);
228 struct list_head all_drivers
;
230 struct tp_acpi_drv_struct
*acpi
;
233 u8 acpi_driver_registered
:1;
234 u8 acpi_notify_installed
:1;
241 struct ibm_init_struct
{
244 int (*init
) (struct ibm_init_struct
*);
245 struct ibm_struct
*data
;
249 #ifdef CONFIG_THINKPAD_ACPI_BAY
262 u32 bright_16levels
:1;
263 u32 bright_acpimode
:1;
266 u32 fan_ctrl_status_undef
:1;
267 u32 beep_needs_two_args
:1;
268 u32 input_device_registered
:1;
269 u32 platform_drv_registered
:1;
270 u32 platform_drv_attrs_registered
:1;
271 u32 sensors_pdrv_registered
:1;
272 u32 sensors_pdrv_attrs_registered
:1;
273 u32 sensors_pdev_attrs_registered
:1;
274 u32 hotkey_poll_active
:1;
278 u16 hotkey_mask_ff
:1;
281 struct thinkpad_id_data
{
282 unsigned int vendor
; /* ThinkPad vendor:
283 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
285 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
286 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
288 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
290 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
293 char *model_str
; /* ThinkPad T43 */
294 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
296 static struct thinkpad_id_data thinkpad_id
;
299 TPACPI_LIFE_INIT
= 0,
304 static int experimental
;
305 static u32 dbg_level
;
307 static struct workqueue_struct
*tpacpi_wq
;
315 /* Special LED class that can defer work */
316 struct tpacpi_led_classdev
{
317 struct led_classdev led_classdev
;
318 struct work_struct work
;
319 enum led_status_t new_state
;
323 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
324 static int dbg_wlswemul
;
325 static int tpacpi_wlsw_emulstate
;
326 static int dbg_bluetoothemul
;
327 static int tpacpi_bluetooth_emulstate
;
328 static int dbg_wwanemul
;
329 static int tpacpi_wwan_emulstate
;
330 static int dbg_uwbemul
;
331 static int tpacpi_uwb_emulstate
;
335 /*************************************************************************
339 #define dbg_printk(a_dbg_level, format, arg...) \
340 do { if (dbg_level & (a_dbg_level)) \
341 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
344 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
345 #define vdbg_printk dbg_printk
346 static const char *str_supported(int is_supported
);
348 #define vdbg_printk(a_dbg_level, format, arg...) \
352 static void tpacpi_log_usertask(const char * const what
)
354 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
355 what
, task_tgid_vnr(current
));
358 #define tpacpi_disclose_usertask(what, format, arg...) \
361 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
362 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
363 printk(TPACPI_DEBUG "%s: PID %d: " format, \
364 what, task_tgid_vnr(current), ## arg); \
369 * Quirk handling helpers
371 * ThinkPad IDs and versions seen in the field so far
372 * are two-characters from the set [0-9A-Z], i.e. base 36.
374 * We use values well outside that range as specials.
377 #define TPACPI_MATCH_ANY 0xffffU
378 #define TPACPI_MATCH_UNKNOWN 0U
380 /* TPID('1', 'Y') == 0x5931 */
381 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
383 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
384 { .vendor = PCI_VENDOR_ID_IBM, \
385 .bios = TPID(__id1, __id2), \
386 .ec = TPACPI_MATCH_ANY, \
387 .quirks = (__quirk) }
389 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
390 { .vendor = PCI_VENDOR_ID_LENOVO, \
391 .bios = TPID(__id1, __id2), \
392 .ec = TPACPI_MATCH_ANY, \
393 .quirks = (__quirk) }
395 struct tpacpi_quirk
{
399 unsigned long quirks
;
403 * tpacpi_check_quirks() - search BIOS/EC version on a list
404 * @qlist: array of &struct tpacpi_quirk
405 * @qlist_size: number of elements in @qlist
407 * Iterates over a quirks list until one is found that matches the
408 * ThinkPad's vendor, BIOS and EC model.
410 * Returns 0 if nothing matches, otherwise returns the quirks field of
411 * the matching &struct tpacpi_quirk entry.
413 * The match criteria is: vendor, ec and bios much match.
415 static unsigned long __init
tpacpi_check_quirks(
416 const struct tpacpi_quirk
*qlist
,
417 unsigned int qlist_size
)
420 if ((qlist
->vendor
== thinkpad_id
.vendor
||
421 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
422 (qlist
->bios
== thinkpad_id
.bios_model
||
423 qlist
->bios
== TPACPI_MATCH_ANY
) &&
424 (qlist
->ec
== thinkpad_id
.ec_model
||
425 qlist
->ec
== TPACPI_MATCH_ANY
))
426 return qlist
->quirks
;
435 /****************************************************************************
436 ****************************************************************************
438 * ACPI Helpers and device model
440 ****************************************************************************
441 ****************************************************************************/
443 /*************************************************************************
447 static acpi_handle root_handle
;
449 #define TPACPI_HANDLE(object, parent, paths...) \
450 static acpi_handle object##_handle; \
451 static acpi_handle *object##_parent = &parent##_handle; \
452 static char *object##_path; \
453 static char *object##_paths[] = { paths }
455 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
456 "\\_SB.PCI.ISA.EC", /* 570 */
457 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
458 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
459 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
460 "\\_SB.PCI0.ICH3.EC0", /* R31 */
461 "\\_SB.PCI0.LPC.EC", /* all others */
464 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
465 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
467 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
469 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
470 "\\CMS", /* R40, R40e */
473 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
474 "^HKEY", /* R30, R31 */
475 "HKEY", /* all others */
478 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
479 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
480 "\\_SB.PCI0.VID0", /* 770e */
481 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
482 "\\_SB.PCI0.AGP.VID", /* all others */
486 /*************************************************************************
490 static int acpi_evalf(acpi_handle handle
,
491 void *res
, char *method
, char *fmt
, ...)
494 struct acpi_object_list params
;
495 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
496 struct acpi_buffer result
, *resultp
;
497 union acpi_object out_obj
;
505 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
518 params
.pointer
= &in_objs
[0];
525 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
526 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
528 /* add more types as needed */
530 printk(TPACPI_ERR
"acpi_evalf() called "
531 "with invalid format character '%c'\n", c
);
537 if (res_type
!= 'v') {
538 result
.length
= sizeof(out_obj
);
539 result
.pointer
= &out_obj
;
544 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
549 *(int *)res
= out_obj
.integer
.value
;
550 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
553 success
= status
== AE_OK
;
555 /* add more types as needed */
557 printk(TPACPI_ERR
"acpi_evalf() called "
558 "with invalid format character '%c'\n", res_type
);
562 if (!success
&& !quiet
)
563 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
564 method
, fmt0
, status
);
569 static int acpi_ec_read(int i
, u8
*p
)
574 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
578 if (ec_read(i
, p
) < 0)
585 static int acpi_ec_write(int i
, u8 v
)
588 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
591 if (ec_write(i
, v
) < 0)
598 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
599 static int _sta(acpi_handle handle
)
603 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
610 static int issue_thinkpad_cmos_command(int cmos_cmd
)
615 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
621 /*************************************************************************
625 #define TPACPI_ACPIHANDLE_INIT(object) \
626 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
627 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
629 static void drv_acpi_handle_init(char *name
,
630 acpi_handle
*handle
, acpi_handle parent
,
631 char **paths
, int num_paths
, char **path
)
636 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
639 for (i
= 0; i
< num_paths
; i
++) {
640 status
= acpi_get_handle(parent
, paths
[i
], handle
);
641 if (ACPI_SUCCESS(status
)) {
643 dbg_printk(TPACPI_DBG_INIT
,
644 "Found ACPI handle %s for %s\n",
650 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
655 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
657 struct ibm_struct
*ibm
= data
;
659 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
662 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
665 ibm
->acpi
->notify(ibm
, event
);
668 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
675 if (!*ibm
->acpi
->handle
)
678 vdbg_printk(TPACPI_DBG_INIT
,
679 "setting up ACPI notify for %s\n", ibm
->name
);
681 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
683 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
688 ibm
->acpi
->device
->driver_data
= ibm
;
689 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
690 TPACPI_ACPI_EVENT_PREFIX
,
693 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
694 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
695 if (ACPI_FAILURE(status
)) {
696 if (status
== AE_ALREADY_EXISTS
) {
698 "another device driver is already "
699 "handling %s events\n", ibm
->name
);
702 "acpi_install_notify_handler(%s) failed: %d\n",
707 ibm
->flags
.acpi_notify_installed
= 1;
711 static int __init
tpacpi_device_add(struct acpi_device
*device
)
716 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
720 dbg_printk(TPACPI_DBG_INIT
,
721 "registering %s as an ACPI driver\n", ibm
->name
);
725 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
726 if (!ibm
->acpi
->driver
) {
728 "failed to allocate memory for ibm->acpi->driver\n");
732 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
733 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
735 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
737 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
739 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
741 kfree(ibm
->acpi
->driver
);
742 ibm
->acpi
->driver
= NULL
;
744 ibm
->flags
.acpi_driver_registered
= 1;
750 /****************************************************************************
751 ****************************************************************************
755 ****************************************************************************
756 ****************************************************************************/
758 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
759 int count
, int *eof
, void *data
)
761 struct ibm_struct
*ibm
= data
;
764 if (!ibm
|| !ibm
->read
)
767 len
= ibm
->read(page
);
771 if (len
<= off
+ count
)
783 static int dispatch_procfs_write(struct file
*file
,
784 const char __user
*userbuf
,
785 unsigned long count
, void *data
)
787 struct ibm_struct
*ibm
= data
;
791 if (!ibm
|| !ibm
->write
)
794 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
798 if (copy_from_user(kernbuf
, userbuf
, count
)) {
804 strcat(kernbuf
, ",");
805 ret
= ibm
->write(kernbuf
);
814 static char *next_cmd(char **cmds
)
819 while ((end
= strchr(start
, ',')) && end
== start
)
831 /****************************************************************************
832 ****************************************************************************
834 * Device model: input, hwmon and platform
836 ****************************************************************************
837 ****************************************************************************/
839 static struct platform_device
*tpacpi_pdev
;
840 static struct platform_device
*tpacpi_sensors_pdev
;
841 static struct device
*tpacpi_hwmon
;
842 static struct input_dev
*tpacpi_inputdev
;
843 static struct mutex tpacpi_inputdev_send_mutex
;
844 static LIST_HEAD(tpacpi_all_drivers
);
846 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
849 struct ibm_struct
*ibm
, *itmp
;
851 list_for_each_entry_safe(ibm
, itmp
,
855 (ibm
->suspend
)(state
);
861 static int tpacpi_resume_handler(struct platform_device
*pdev
)
863 struct ibm_struct
*ibm
, *itmp
;
865 list_for_each_entry_safe(ibm
, itmp
,
875 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
877 struct ibm_struct
*ibm
, *itmp
;
879 list_for_each_entry_safe(ibm
, itmp
,
887 static struct platform_driver tpacpi_pdriver
= {
889 .name
= TPACPI_DRVR_NAME
,
890 .owner
= THIS_MODULE
,
892 .suspend
= tpacpi_suspend_handler
,
893 .resume
= tpacpi_resume_handler
,
894 .shutdown
= tpacpi_shutdown_handler
,
897 static struct platform_driver tpacpi_hwmon_pdriver
= {
899 .name
= TPACPI_HWMON_DRVR_NAME
,
900 .owner
= THIS_MODULE
,
904 /*************************************************************************
905 * sysfs support helpers
908 struct attribute_set
{
909 unsigned int members
, max_members
;
910 struct attribute_group group
;
913 struct attribute_set_obj
{
914 struct attribute_set s
;
916 } __attribute__((packed
));
918 static struct attribute_set
*create_attr_set(unsigned int max_members
,
921 struct attribute_set_obj
*sobj
;
923 if (max_members
== 0)
926 /* Allocates space for implicit NULL at the end too */
927 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
928 max_members
* sizeof(struct attribute
*),
932 sobj
->s
.max_members
= max_members
;
933 sobj
->s
.group
.attrs
= &sobj
->a
;
934 sobj
->s
.group
.name
= name
;
939 #define destroy_attr_set(_set) \
942 /* not multi-threaded safe, use it in a single thread per set */
943 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
948 if (s
->members
>= s
->max_members
)
951 s
->group
.attrs
[s
->members
] = attr
;
957 static int add_many_to_attr_set(struct attribute_set
*s
,
958 struct attribute
**attr
,
963 for (i
= 0; i
< count
; i
++) {
964 res
= add_to_attr_set(s
, attr
[i
]);
972 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
974 sysfs_remove_group(kobj
, &s
->group
);
978 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
979 sysfs_create_group(_kobj, &_attr_set->group)
981 static int parse_strtoul(const char *buf
,
982 unsigned long max
, unsigned long *value
)
986 while (*buf
&& isspace(*buf
))
988 *value
= simple_strtoul(buf
, &endp
, 0);
989 while (*endp
&& isspace(*endp
))
991 if (*endp
|| *value
> max
)
997 static void tpacpi_disable_brightness_delay(void)
999 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
1000 printk(TPACPI_NOTICE
1001 "ACPI backlight control delay disabled\n");
1004 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
1006 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1007 union acpi_object
*obj
;
1010 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
1011 obj
= (union acpi_object
*)buffer
.pointer
;
1012 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
1013 printk(TPACPI_ERR
"Unknown _BCL data, "
1014 "please report this to %s\n", TPACPI_MAIL
);
1017 rc
= obj
->package
.count
;
1023 kfree(buffer
.pointer
);
1027 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1028 u32 lvl
, void *context
, void **rv
)
1030 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1031 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1033 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1034 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1035 BUG_ON(!rv
|| !*rv
);
1036 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1037 return AE_CTRL_TERMINATE
;
1044 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1046 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1050 void *bcl_ptr
= &bcl_levels
;
1053 TPACPI_ACPIHANDLE_INIT(vid
);
1059 * Search for a _BCL method, and execute it. This is safe on all
1060 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1061 * BIOS in ACPI backlight control mode. We do NOT have to care
1062 * about calling the _BCL method in an enabled video device, any
1063 * will do for our purposes.
1066 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1067 tpacpi_acpi_walk_find_bcl
, NULL
,
1070 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1071 tp_features
.bright_acpimode
= 1;
1072 return (bcl_levels
- 2);
1078 static int __init
tpacpi_new_rfkill(const unsigned int id
,
1079 struct rfkill
**rfk
,
1080 const enum rfkill_type rfktype
,
1082 const bool set_default
,
1083 int (*toggle_radio
)(void *, enum rfkill_state
),
1084 int (*get_state
)(void *, enum rfkill_state
*))
1087 enum rfkill_state initial_state
= RFKILL_STATE_SOFT_BLOCKED
;
1089 res
= get_state(NULL
, &initial_state
);
1092 "failed to read initial state for %s, error %d; "
1093 "will turn radio off\n", name
, res
);
1094 } else if (set_default
) {
1095 /* try to set the initial state as the default for the rfkill
1096 * type, since we ask the firmware to preserve it across S5 in
1098 if (rfkill_set_default(rfktype
,
1099 (initial_state
== RFKILL_STATE_UNBLOCKED
) ?
1100 RFKILL_STATE_UNBLOCKED
:
1101 RFKILL_STATE_SOFT_BLOCKED
) == -EPERM
)
1102 vdbg_printk(TPACPI_DBG_RFKILL
,
1103 "Default state for %s cannot be changed\n",
1107 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
1110 "failed to allocate memory for rfkill class\n");
1114 (*rfk
)->name
= name
;
1115 (*rfk
)->get_state
= get_state
;
1116 (*rfk
)->toggle_radio
= toggle_radio
;
1117 (*rfk
)->state
= initial_state
;
1119 res
= rfkill_register(*rfk
);
1122 "failed to register %s rfkill switch: %d\n",
1132 static void printk_deprecated_attribute(const char * const what
,
1133 const char * const details
)
1135 tpacpi_log_usertask("deprecated sysfs attribute");
1136 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1137 "will be removed. %s\n",
1141 static void printk_deprecated_rfkill_attribute(const char * const what
)
1143 printk_deprecated_attribute(what
,
1144 "Please switch to generic rfkill before year 2010");
1147 /*************************************************************************
1148 * thinkpad-acpi driver attributes
1151 /* interface_version --------------------------------------------------- */
1152 static ssize_t
tpacpi_driver_interface_version_show(
1153 struct device_driver
*drv
,
1156 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1159 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1160 tpacpi_driver_interface_version_show
, NULL
);
1162 /* debug_level --------------------------------------------------------- */
1163 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1166 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1169 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1170 const char *buf
, size_t count
)
1174 if (parse_strtoul(buf
, 0xffff, &t
))
1182 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1183 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1185 /* version ------------------------------------------------------------- */
1186 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1189 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1190 TPACPI_DESC
, TPACPI_VERSION
);
1193 static DRIVER_ATTR(version
, S_IRUGO
,
1194 tpacpi_driver_version_show
, NULL
);
1196 /* --------------------------------------------------------------------- */
1198 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1200 static void tpacpi_send_radiosw_update(void);
1202 /* wlsw_emulstate ------------------------------------------------------ */
1203 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1206 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1209 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1210 const char *buf
, size_t count
)
1214 if (parse_strtoul(buf
, 1, &t
))
1217 if (tpacpi_wlsw_emulstate
!= t
) {
1218 tpacpi_wlsw_emulstate
= !!t
;
1219 tpacpi_send_radiosw_update();
1221 tpacpi_wlsw_emulstate
= !!t
;
1226 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1227 tpacpi_driver_wlsw_emulstate_show
,
1228 tpacpi_driver_wlsw_emulstate_store
);
1230 /* bluetooth_emulstate ------------------------------------------------- */
1231 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1232 struct device_driver
*drv
,
1235 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1238 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1239 struct device_driver
*drv
,
1240 const char *buf
, size_t count
)
1244 if (parse_strtoul(buf
, 1, &t
))
1247 tpacpi_bluetooth_emulstate
= !!t
;
1252 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1253 tpacpi_driver_bluetooth_emulstate_show
,
1254 tpacpi_driver_bluetooth_emulstate_store
);
1256 /* wwan_emulstate ------------------------------------------------- */
1257 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1258 struct device_driver
*drv
,
1261 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1264 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1265 struct device_driver
*drv
,
1266 const char *buf
, size_t count
)
1270 if (parse_strtoul(buf
, 1, &t
))
1273 tpacpi_wwan_emulstate
= !!t
;
1278 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1279 tpacpi_driver_wwan_emulstate_show
,
1280 tpacpi_driver_wwan_emulstate_store
);
1282 /* uwb_emulstate ------------------------------------------------- */
1283 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1284 struct device_driver
*drv
,
1287 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1290 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1291 struct device_driver
*drv
,
1292 const char *buf
, size_t count
)
1296 if (parse_strtoul(buf
, 1, &t
))
1299 tpacpi_uwb_emulstate
= !!t
;
1304 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1305 tpacpi_driver_uwb_emulstate_show
,
1306 tpacpi_driver_uwb_emulstate_store
);
1309 /* --------------------------------------------------------------------- */
1311 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1312 &driver_attr_debug_level
, &driver_attr_version
,
1313 &driver_attr_interface_version
,
1316 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1322 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1323 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1327 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1328 if (!res
&& dbg_wlswemul
)
1329 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1330 if (!res
&& dbg_bluetoothemul
)
1331 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1332 if (!res
&& dbg_wwanemul
)
1333 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1334 if (!res
&& dbg_uwbemul
)
1335 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1341 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1345 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1346 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1348 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1349 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1350 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1351 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1352 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1356 /****************************************************************************
1357 ****************************************************************************
1361 ****************************************************************************
1362 ****************************************************************************/
1364 /*************************************************************************
1365 * thinkpad-acpi init subdriver
1368 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1370 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1371 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1373 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1374 (thinkpad_id
.bios_version_str
) ?
1375 thinkpad_id
.bios_version_str
: "unknown",
1376 (thinkpad_id
.ec_version_str
) ?
1377 thinkpad_id
.ec_version_str
: "unknown");
1379 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1380 printk(TPACPI_INFO
"%s %s, model %s\n",
1381 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1382 "IBM" : ((thinkpad_id
.vendor
==
1383 PCI_VENDOR_ID_LENOVO
) ?
1384 "Lenovo" : "Unknown vendor"),
1385 thinkpad_id
.model_str
,
1386 (thinkpad_id
.nummodel_str
) ?
1387 thinkpad_id
.nummodel_str
: "unknown");
1392 static int thinkpad_acpi_driver_read(char *p
)
1396 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1397 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1402 static struct ibm_struct thinkpad_acpi_driver_data
= {
1404 .read
= thinkpad_acpi_driver_read
,
1407 /*************************************************************************
1411 enum { /* hot key scan codes (derived from ACPI DSDT) */
1412 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1413 TP_ACPI_HOTKEYSCAN_FNF2
,
1414 TP_ACPI_HOTKEYSCAN_FNF3
,
1415 TP_ACPI_HOTKEYSCAN_FNF4
,
1416 TP_ACPI_HOTKEYSCAN_FNF5
,
1417 TP_ACPI_HOTKEYSCAN_FNF6
,
1418 TP_ACPI_HOTKEYSCAN_FNF7
,
1419 TP_ACPI_HOTKEYSCAN_FNF8
,
1420 TP_ACPI_HOTKEYSCAN_FNF9
,
1421 TP_ACPI_HOTKEYSCAN_FNF10
,
1422 TP_ACPI_HOTKEYSCAN_FNF11
,
1423 TP_ACPI_HOTKEYSCAN_FNF12
,
1424 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1425 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1426 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1427 TP_ACPI_HOTKEYSCAN_FNHOME
,
1428 TP_ACPI_HOTKEYSCAN_FNEND
,
1429 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1430 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1431 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1432 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1433 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1434 TP_ACPI_HOTKEYSCAN_MUTE
,
1435 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1438 enum { /* Keys available through NVRAM polling */
1439 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1440 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1443 enum { /* Positions of some of the keys in hotkey masks */
1444 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1445 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1446 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1447 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1448 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1449 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1450 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1451 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1452 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1453 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1454 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1457 enum { /* NVRAM to ACPI HKEY group map */
1458 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1459 TP_ACPI_HKEY_ZOOM_MASK
|
1460 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1461 TP_ACPI_HKEY_HIBERNATE_MASK
,
1462 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1463 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1464 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1465 TP_ACPI_HKEY_VOLDWN_MASK
|
1466 TP_ACPI_HKEY_MUTE_MASK
,
1469 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1470 struct tp_nvram_state
{
1471 u16 thinkpad_toggle
:1;
1473 u16 display_toggle
:1;
1474 u16 thinklight_toggle
:1;
1475 u16 hibernate_toggle
:1;
1476 u16 displayexp_toggle
:1;
1477 u16 display_state
:1;
1478 u16 brightness_toggle
:1;
1479 u16 volume_toggle
:1;
1482 u8 brightness_level
;
1486 static struct task_struct
*tpacpi_hotkey_task
;
1487 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1488 static int hotkey_poll_freq
= 10; /* Hz */
1489 static struct mutex hotkey_thread_mutex
;
1490 static struct mutex hotkey_thread_data_mutex
;
1491 static unsigned int hotkey_config_change
;
1493 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1495 #define hotkey_source_mask 0U
1497 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1499 static struct mutex hotkey_mutex
;
1501 static enum { /* Reasons for waking up */
1502 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1503 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1504 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1505 } hotkey_wakeup_reason
;
1507 static int hotkey_autosleep_ack
;
1509 static u32 hotkey_orig_mask
;
1510 static u32 hotkey_all_mask
;
1511 static u32 hotkey_reserved_mask
;
1512 static u32 hotkey_mask
;
1514 static unsigned int hotkey_report_mode
;
1516 static u16
*hotkey_keycode_map
;
1518 static struct attribute_set
*hotkey_dev_attributes
;
1520 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1521 #define HOTKEY_CONFIG_CRITICAL_START \
1523 mutex_lock(&hotkey_thread_data_mutex); \
1524 hotkey_config_change++; \
1526 #define HOTKEY_CONFIG_CRITICAL_END \
1527 mutex_unlock(&hotkey_thread_data_mutex);
1529 #define HOTKEY_CONFIG_CRITICAL_START
1530 #define HOTKEY_CONFIG_CRITICAL_END
1531 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1533 /* HKEY.MHKG() return bits */
1534 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1536 static int hotkey_get_wlsw(int *status
)
1538 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1540 *status
= !!tpacpi_wlsw_emulstate
;
1544 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1549 static int hotkey_get_tablet_mode(int *status
)
1553 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1556 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1561 * Call with hotkey_mutex held
1563 static int hotkey_mask_get(void)
1567 if (tp_features
.hotkey_mask
) {
1568 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1571 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1577 * Call with hotkey_mutex held
1579 static int hotkey_mask_set(u32 mask
)
1584 if (tp_features
.hotkey_mask
) {
1585 if (!tp_warned
.hotkey_mask_ff
&&
1586 (mask
== 0xffff || mask
== 0xffffff ||
1587 mask
== 0xffffffff)) {
1588 tp_warned
.hotkey_mask_ff
= 1;
1589 printk(TPACPI_NOTICE
1590 "setting the hotkey mask to 0x%08x is likely "
1591 "not the best way to go about it\n", mask
);
1592 printk(TPACPI_NOTICE
1593 "please consider using the driver defaults, "
1594 "and refer to up-to-date thinkpad-acpi "
1598 HOTKEY_CONFIG_CRITICAL_START
1599 for (i
= 0; i
< 32; i
++) {
1601 /* enable in firmware mask only keys not in NVRAM
1602 * mode, but enable the key in the cached hotkey_mask
1603 * regardless of mode, or the key will end up
1604 * disabled by hotkey_mask_get() */
1605 if (!acpi_evalf(hkey_handle
,
1606 NULL
, "MHKM", "vdd", i
+ 1,
1607 !!((mask
& ~hotkey_source_mask
) & m
))) {
1611 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1614 HOTKEY_CONFIG_CRITICAL_END
1616 /* hotkey_mask_get must be called unconditionally below */
1617 if (!hotkey_mask_get() && !rc
&&
1618 (hotkey_mask
& ~hotkey_source_mask
) !=
1619 (mask
& ~hotkey_source_mask
)) {
1620 printk(TPACPI_NOTICE
1621 "requested hot key mask 0x%08x, but "
1622 "firmware forced it to 0x%08x\n",
1626 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1627 HOTKEY_CONFIG_CRITICAL_START
1628 hotkey_mask
= mask
& hotkey_source_mask
;
1629 HOTKEY_CONFIG_CRITICAL_END
1631 if (hotkey_mask
!= mask
) {
1632 printk(TPACPI_NOTICE
1633 "requested hot key mask 0x%08x, "
1634 "forced to 0x%08x (NVRAM poll mask is "
1635 "0x%08x): no firmware mask support\n",
1636 mask
, hotkey_mask
, hotkey_source_mask
);
1641 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1647 static int hotkey_status_get(int *status
)
1649 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1655 static int hotkey_status_set(bool enable
)
1657 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
1663 static void tpacpi_input_send_tabletsw(void)
1667 if (tp_features
.hotkey_tablet
&&
1668 !hotkey_get_tablet_mode(&state
)) {
1669 mutex_lock(&tpacpi_inputdev_send_mutex
);
1671 input_report_switch(tpacpi_inputdev
,
1672 SW_TABLET_MODE
, !!state
);
1673 input_sync(tpacpi_inputdev
);
1675 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1679 static void tpacpi_input_send_key(unsigned int scancode
)
1681 unsigned int keycode
;
1683 keycode
= hotkey_keycode_map
[scancode
];
1685 if (keycode
!= KEY_RESERVED
) {
1686 mutex_lock(&tpacpi_inputdev_send_mutex
);
1688 input_report_key(tpacpi_inputdev
, keycode
, 1);
1689 if (keycode
== KEY_UNKNOWN
)
1690 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1692 input_sync(tpacpi_inputdev
);
1694 input_report_key(tpacpi_inputdev
, keycode
, 0);
1695 if (keycode
== KEY_UNKNOWN
)
1696 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1698 input_sync(tpacpi_inputdev
);
1700 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1704 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1705 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1707 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1709 tpacpi_input_send_key(scancode
);
1710 if (hotkey_report_mode
< 2) {
1711 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1712 0x80, 0x1001 + scancode
);
1716 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1720 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1721 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1722 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1723 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1724 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1725 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1727 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1728 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1729 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1731 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1732 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1733 n
->displayexp_toggle
=
1734 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1736 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1737 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1738 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1739 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1740 n
->brightness_toggle
=
1741 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1743 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1744 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1745 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1746 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1747 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1748 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1752 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1754 if ((mask & (1 << __scancode)) && \
1755 oldn->__member != newn->__member) \
1756 tpacpi_hotkey_send_key(__scancode); \
1759 #define TPACPI_MAY_SEND_KEY(__scancode) \
1760 do { if (mask & (1 << __scancode)) \
1761 tpacpi_hotkey_send_key(__scancode); } while (0)
1763 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1764 struct tp_nvram_state
*newn
,
1767 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1768 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1769 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1770 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1772 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1774 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1777 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1778 if (oldn
->mute
!= newn
->mute
) {
1779 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1781 if (oldn
->volume_level
> newn
->volume_level
) {
1782 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1783 } else if (oldn
->volume_level
< newn
->volume_level
) {
1784 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1785 } else if (oldn
->mute
== newn
->mute
) {
1786 /* repeated key presses that didn't change state */
1788 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1789 } else if (newn
->volume_level
!= 0) {
1790 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1792 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1797 /* handle brightness */
1798 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1799 if (oldn
->brightness_level
< newn
->brightness_level
) {
1800 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1801 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1802 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1804 /* repeated key presses that didn't change state */
1805 if (newn
->brightness_level
!= 0) {
1806 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1808 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1814 #undef TPACPI_COMPARE_KEY
1815 #undef TPACPI_MAY_SEND_KEY
1817 static int hotkey_kthread(void *data
)
1819 struct tp_nvram_state s
[2];
1821 unsigned int si
, so
;
1823 unsigned int change_detector
, must_reset
;
1825 mutex_lock(&hotkey_thread_mutex
);
1827 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1836 /* Initial state for compares */
1837 mutex_lock(&hotkey_thread_data_mutex
);
1838 change_detector
= hotkey_config_change
;
1839 mask
= hotkey_source_mask
& hotkey_mask
;
1840 mutex_unlock(&hotkey_thread_data_mutex
);
1841 hotkey_read_nvram(&s
[so
], mask
);
1843 while (!kthread_should_stop() && hotkey_poll_freq
) {
1845 t
= 1000/hotkey_poll_freq
;
1846 t
= msleep_interruptible(t
);
1847 if (unlikely(kthread_should_stop()))
1849 must_reset
= try_to_freeze();
1850 if (t
> 0 && !must_reset
)
1853 mutex_lock(&hotkey_thread_data_mutex
);
1854 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1855 /* forget old state on thaw or config change */
1858 change_detector
= hotkey_config_change
;
1860 mask
= hotkey_source_mask
& hotkey_mask
;
1861 mutex_unlock(&hotkey_thread_data_mutex
);
1864 hotkey_read_nvram(&s
[si
], mask
);
1865 if (likely(si
!= so
)) {
1866 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1876 mutex_unlock(&hotkey_thread_mutex
);
1880 static void hotkey_poll_stop_sync(void)
1882 if (tpacpi_hotkey_task
) {
1883 if (frozen(tpacpi_hotkey_task
) ||
1884 freezing(tpacpi_hotkey_task
))
1885 thaw_process(tpacpi_hotkey_task
);
1887 kthread_stop(tpacpi_hotkey_task
);
1888 tpacpi_hotkey_task
= NULL
;
1889 mutex_lock(&hotkey_thread_mutex
);
1890 /* at this point, the thread did exit */
1891 mutex_unlock(&hotkey_thread_mutex
);
1895 /* call with hotkey_mutex held */
1896 static void hotkey_poll_setup(int may_warn
)
1898 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1899 hotkey_poll_freq
> 0 &&
1900 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1901 if (!tpacpi_hotkey_task
) {
1902 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1903 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
1904 if (IS_ERR(tpacpi_hotkey_task
)) {
1905 tpacpi_hotkey_task
= NULL
;
1907 "could not create kernel thread "
1908 "for hotkey polling\n");
1912 hotkey_poll_stop_sync();
1914 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1915 printk(TPACPI_NOTICE
1916 "hot keys 0x%08x require polling, "
1917 "which is currently disabled\n",
1918 hotkey_source_mask
);
1923 static void hotkey_poll_setup_safe(int may_warn
)
1925 mutex_lock(&hotkey_mutex
);
1926 hotkey_poll_setup(may_warn
);
1927 mutex_unlock(&hotkey_mutex
);
1930 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1932 static void hotkey_poll_setup_safe(int __unused
)
1936 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1938 static int hotkey_inputdev_open(struct input_dev
*dev
)
1940 switch (tpacpi_lifecycle
) {
1941 case TPACPI_LIFE_INIT
:
1943 * hotkey_init will call hotkey_poll_setup_safe
1944 * at the appropriate moment
1947 case TPACPI_LIFE_EXITING
:
1949 case TPACPI_LIFE_RUNNING
:
1950 hotkey_poll_setup_safe(0);
1954 /* Should only happen if tpacpi_lifecycle is corrupt */
1959 static void hotkey_inputdev_close(struct input_dev
*dev
)
1961 /* disable hotkey polling when possible */
1962 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1963 hotkey_poll_setup_safe(0);
1966 /* sysfs hotkey enable ------------------------------------------------- */
1967 static ssize_t
hotkey_enable_show(struct device
*dev
,
1968 struct device_attribute
*attr
,
1973 printk_deprecated_attribute("hotkey_enable",
1974 "Hotkey reporting is always enabled");
1976 res
= hotkey_status_get(&status
);
1980 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1983 static ssize_t
hotkey_enable_store(struct device
*dev
,
1984 struct device_attribute
*attr
,
1985 const char *buf
, size_t count
)
1989 printk_deprecated_attribute("hotkey_enable",
1990 "Hotkeys can be disabled through hotkey_mask");
1992 if (parse_strtoul(buf
, 1, &t
))
2001 static struct device_attribute dev_attr_hotkey_enable
=
2002 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2003 hotkey_enable_show
, hotkey_enable_store
);
2005 /* sysfs hotkey mask --------------------------------------------------- */
2006 static ssize_t
hotkey_mask_show(struct device
*dev
,
2007 struct device_attribute
*attr
,
2012 if (mutex_lock_killable(&hotkey_mutex
))
2013 return -ERESTARTSYS
;
2014 res
= hotkey_mask_get();
2015 mutex_unlock(&hotkey_mutex
);
2018 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
2021 static ssize_t
hotkey_mask_store(struct device
*dev
,
2022 struct device_attribute
*attr
,
2023 const char *buf
, size_t count
)
2028 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2031 if (mutex_lock_killable(&hotkey_mutex
))
2032 return -ERESTARTSYS
;
2034 res
= hotkey_mask_set(t
);
2036 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2037 hotkey_poll_setup(1);
2040 mutex_unlock(&hotkey_mutex
);
2042 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2044 return (res
) ? res
: count
;
2047 static struct device_attribute dev_attr_hotkey_mask
=
2048 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2049 hotkey_mask_show
, hotkey_mask_store
);
2051 /* sysfs hotkey bios_enabled ------------------------------------------- */
2052 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2053 struct device_attribute
*attr
,
2056 return sprintf(buf
, "0\n");
2059 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2060 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2062 /* sysfs hotkey bios_mask ---------------------------------------------- */
2063 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2064 struct device_attribute
*attr
,
2067 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2070 static struct device_attribute dev_attr_hotkey_bios_mask
=
2071 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2073 /* sysfs hotkey all_mask ----------------------------------------------- */
2074 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2075 struct device_attribute
*attr
,
2078 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2079 hotkey_all_mask
| hotkey_source_mask
);
2082 static struct device_attribute dev_attr_hotkey_all_mask
=
2083 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2085 /* sysfs hotkey recommended_mask --------------------------------------- */
2086 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2087 struct device_attribute
*attr
,
2090 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2091 (hotkey_all_mask
| hotkey_source_mask
)
2092 & ~hotkey_reserved_mask
);
2095 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2096 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2097 hotkey_recommended_mask_show
, NULL
);
2099 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2101 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2102 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2103 struct device_attribute
*attr
,
2106 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2109 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2110 struct device_attribute
*attr
,
2111 const char *buf
, size_t count
)
2115 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2116 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2119 if (mutex_lock_killable(&hotkey_mutex
))
2120 return -ERESTARTSYS
;
2122 HOTKEY_CONFIG_CRITICAL_START
2123 hotkey_source_mask
= t
;
2124 HOTKEY_CONFIG_CRITICAL_END
2126 hotkey_poll_setup(1);
2128 mutex_unlock(&hotkey_mutex
);
2130 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2135 static struct device_attribute dev_attr_hotkey_source_mask
=
2136 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2137 hotkey_source_mask_show
, hotkey_source_mask_store
);
2139 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2140 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2141 struct device_attribute
*attr
,
2144 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2147 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2148 struct device_attribute
*attr
,
2149 const char *buf
, size_t count
)
2153 if (parse_strtoul(buf
, 25, &t
))
2156 if (mutex_lock_killable(&hotkey_mutex
))
2157 return -ERESTARTSYS
;
2159 hotkey_poll_freq
= t
;
2161 hotkey_poll_setup(1);
2162 mutex_unlock(&hotkey_mutex
);
2164 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2169 static struct device_attribute dev_attr_hotkey_poll_freq
=
2170 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2171 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2173 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2175 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2176 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2177 struct device_attribute
*attr
,
2181 res
= hotkey_get_wlsw(&s
);
2185 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2188 static struct device_attribute dev_attr_hotkey_radio_sw
=
2189 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2191 static void hotkey_radio_sw_notify_change(void)
2193 if (tp_features
.hotkey_wlsw
)
2194 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2198 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2199 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2200 struct device_attribute
*attr
,
2204 res
= hotkey_get_tablet_mode(&s
);
2208 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2211 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2212 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2214 static void hotkey_tablet_mode_notify_change(void)
2216 if (tp_features
.hotkey_tablet
)
2217 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2218 "hotkey_tablet_mode");
2221 /* sysfs hotkey report_mode -------------------------------------------- */
2222 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2223 struct device_attribute
*attr
,
2226 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2227 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2230 static struct device_attribute dev_attr_hotkey_report_mode
=
2231 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2233 /* sysfs wakeup reason (pollable) -------------------------------------- */
2234 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2235 struct device_attribute
*attr
,
2238 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2241 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2242 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2244 static void hotkey_wakeup_reason_notify_change(void)
2246 if (tp_features
.hotkey_mask
)
2247 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2251 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2252 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2253 struct device_attribute
*attr
,
2256 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2259 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2260 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2261 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2263 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2265 if (tp_features
.hotkey_mask
)
2266 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2267 "wakeup_hotunplug_complete");
2270 /* --------------------------------------------------------------------- */
2272 static struct attribute
*hotkey_attributes
[] __initdata
= {
2273 &dev_attr_hotkey_enable
.attr
,
2274 &dev_attr_hotkey_bios_enabled
.attr
,
2275 &dev_attr_hotkey_report_mode
.attr
,
2276 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2277 &dev_attr_hotkey_mask
.attr
,
2278 &dev_attr_hotkey_all_mask
.attr
,
2279 &dev_attr_hotkey_recommended_mask
.attr
,
2280 &dev_attr_hotkey_source_mask
.attr
,
2281 &dev_attr_hotkey_poll_freq
.attr
,
2285 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
2286 &dev_attr_hotkey_bios_mask
.attr
,
2287 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2288 &dev_attr_hotkey_mask
.attr
,
2289 &dev_attr_hotkey_all_mask
.attr
,
2290 &dev_attr_hotkey_recommended_mask
.attr
,
2292 &dev_attr_hotkey_wakeup_reason
.attr
,
2293 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2296 static void bluetooth_update_rfk(void);
2297 static void wan_update_rfk(void);
2298 static void uwb_update_rfk(void);
2299 static void tpacpi_send_radiosw_update(void)
2303 /* Sync these BEFORE sending any rfkill events */
2304 if (tp_features
.bluetooth
)
2305 bluetooth_update_rfk();
2306 if (tp_features
.wan
)
2308 if (tp_features
.uwb
)
2311 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2312 mutex_lock(&tpacpi_inputdev_send_mutex
);
2314 input_report_switch(tpacpi_inputdev
,
2315 SW_RFKILL_ALL
, !!wlsw
);
2316 input_sync(tpacpi_inputdev
);
2318 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2320 hotkey_radio_sw_notify_change();
2323 static void hotkey_exit(void)
2325 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2326 hotkey_poll_stop_sync();
2329 if (hotkey_dev_attributes
)
2330 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2332 kfree(hotkey_keycode_map
);
2334 if (tp_features
.hotkey
) {
2335 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
2336 "restoring original hot key mask\n");
2337 /* no short-circuit boolean operator below! */
2338 if ((hotkey_mask_set(hotkey_orig_mask
) |
2339 hotkey_status_set(false)) != 0)
2341 "failed to restore hot key mask "
2342 "to BIOS defaults\n");
2346 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2348 /* Requirements for changing the default keymaps:
2350 * 1. Many of the keys are mapped to KEY_RESERVED for very
2351 * good reasons. Do not change them unless you have deep
2352 * knowledge on the IBM and Lenovo ThinkPad firmware for
2353 * the various ThinkPad models. The driver behaves
2354 * differently for KEY_RESERVED: such keys have their
2355 * hot key mask *unset* in mask_recommended, and also
2356 * in the initial hot key mask programmed into the
2357 * firmware at driver load time, which means the firm-
2358 * ware may react very differently if you change them to
2361 * 2. You must be subscribed to the linux-thinkpad and
2362 * ibm-acpi-devel mailing lists, and you should read the
2363 * list archives since 2007 if you want to change the
2364 * keymaps. This requirement exists so that you will
2365 * know the past history of problems with the thinkpad-
2366 * acpi driver keymaps, and also that you will be
2367 * listening to any bug reports;
2369 * 3. Do not send thinkpad-acpi specific patches directly to
2370 * for merging, *ever*. Send them to the linux-acpi
2371 * mailinglist for comments. Merging is to be done only
2372 * through acpi-test and the ACPI maintainer.
2374 * If the above is too much to ask, don't change the keymap.
2375 * Ask the thinkpad-acpi maintainer to do it, instead.
2377 static u16 ibm_keycode_map
[] __initdata
= {
2378 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2379 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2380 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2381 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2383 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2384 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2385 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2386 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2388 /* brightness: firmware always reacts to them, unless
2389 * X.org did some tricks in the radeon BIOS scratch
2390 * registers of *some* models */
2391 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2392 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2394 /* Thinklight: firmware always react to it */
2395 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2397 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2398 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2400 /* Volume: firmware always react to it and reprograms
2401 * the built-in *extra* mixer. Never map it to control
2402 * another mixer by default. */
2403 KEY_RESERVED
, /* 0x14: VOLUME UP */
2404 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2405 KEY_RESERVED
, /* 0x16: MUTE */
2407 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2409 /* (assignments unknown, please report if found) */
2410 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2411 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2413 static u16 lenovo_keycode_map
[] __initdata
= {
2414 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2415 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2416 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2417 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2419 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2420 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2421 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2422 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2424 /* These either have to go through ACPI video, or
2425 * act like in the IBM ThinkPads, so don't ever
2426 * enable them by default */
2427 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2428 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2430 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2432 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2433 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2435 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2436 * react to it and reprograms the built-in *extra* mixer.
2437 * Never map it to control another mixer by default.
2439 * T60?, T61, R60?, R61: firmware and EC tries to send
2440 * these over the regular keyboard, so these are no-ops,
2441 * but there are still weird bugs re. MUTE, so do not
2442 * change unless you get test reports from all Lenovo
2443 * models. May cause the BIOS to interfere with the
2446 KEY_RESERVED
, /* 0x14: VOLUME UP */
2447 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2448 KEY_RESERVED
, /* 0x16: MUTE */
2450 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2452 /* (assignments unknown, please report if found) */
2453 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2454 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2457 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2458 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2459 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2465 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2466 "initializing hotkey subdriver\n");
2468 BUG_ON(!tpacpi_inputdev
);
2469 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2470 tpacpi_inputdev
->close
!= NULL
);
2472 TPACPI_ACPIHANDLE_INIT(hkey
);
2473 mutex_init(&hotkey_mutex
);
2475 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2476 mutex_init(&hotkey_thread_mutex
);
2477 mutex_init(&hotkey_thread_data_mutex
);
2480 /* hotkey not supported on 570 */
2481 tp_features
.hotkey
= hkey_handle
!= NULL
;
2483 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2485 str_supported(tp_features
.hotkey
));
2487 if (!tp_features
.hotkey
)
2490 tpacpi_disable_brightness_delay();
2492 hotkey_dev_attributes
= create_attr_set(13, NULL
);
2493 if (!hotkey_dev_attributes
)
2495 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2497 ARRAY_SIZE(hotkey_attributes
));
2501 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2502 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2503 for HKEY interface version 0x100 */
2504 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2505 if ((hkeyv
>> 8) != 1) {
2506 printk(TPACPI_ERR
"unknown version of the "
2507 "HKEY interface: 0x%x\n", hkeyv
);
2508 printk(TPACPI_ERR
"please report this to %s\n",
2512 * MHKV 0x100 in A31, R40, R40e,
2513 * T4x, X31, and later
2515 tp_features
.hotkey_mask
= 1;
2516 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2517 "firmware HKEY interface version: 0x%x\n",
2522 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2523 "hotkey masks are %s\n",
2524 str_supported(tp_features
.hotkey_mask
));
2526 if (tp_features
.hotkey_mask
) {
2527 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2530 "missing MHKA handler, "
2531 "please report this to %s\n",
2533 /* FN+F12, FN+F4, FN+F3 */
2534 hotkey_all_mask
= 0x080cU
;
2538 /* hotkey_source_mask *must* be zero for
2539 * the first hotkey_mask_get */
2540 if (tp_features
.hotkey_mask
) {
2541 res
= hotkey_mask_get();
2545 hotkey_orig_mask
= hotkey_mask
;
2546 res
= add_many_to_attr_set(
2547 hotkey_dev_attributes
,
2548 hotkey_mask_attributes
,
2549 ARRAY_SIZE(hotkey_mask_attributes
));
2554 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2555 if (tp_features
.hotkey_mask
) {
2556 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2559 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2562 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2563 "hotkey source mask 0x%08x, polling freq %d\n",
2564 hotkey_source_mask
, hotkey_poll_freq
);
2567 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2569 tp_features
.hotkey_wlsw
= 1;
2571 "radio switch emulation enabled\n");
2574 /* Not all thinkpads have a hardware radio switch */
2575 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2576 tp_features
.hotkey_wlsw
= 1;
2578 "radio switch found; radios are %s\n",
2579 enabled(status
, 0));
2581 if (tp_features
.hotkey_wlsw
)
2582 res
= add_to_attr_set(hotkey_dev_attributes
,
2583 &dev_attr_hotkey_radio_sw
.attr
);
2585 /* For X41t, X60t, X61t Tablets... */
2586 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2587 tp_features
.hotkey_tablet
= 1;
2589 "possible tablet mode switch found; "
2590 "ThinkPad in %s mode\n",
2591 (status
& TP_HOTKEY_TABLET_MASK
)?
2592 "tablet" : "laptop");
2593 res
= add_to_attr_set(hotkey_dev_attributes
,
2594 &dev_attr_hotkey_tablet_mode
.attr
);
2598 res
= register_attr_set_with_sysfs(
2599 hotkey_dev_attributes
,
2600 &tpacpi_pdev
->dev
.kobj
);
2604 /* Set up key map */
2606 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2608 if (!hotkey_keycode_map
) {
2610 "failed to allocate memory for key map\n");
2615 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2616 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2617 "using Lenovo default hot key map\n");
2618 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2619 TPACPI_HOTKEY_MAP_SIZE
);
2621 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2622 "using IBM default hot key map\n");
2623 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2624 TPACPI_HOTKEY_MAP_SIZE
);
2627 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2628 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2629 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2630 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2631 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2632 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2633 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2634 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2635 set_bit(hotkey_keycode_map
[i
],
2636 tpacpi_inputdev
->keybit
);
2638 if (i
< sizeof(hotkey_reserved_mask
)*8)
2639 hotkey_reserved_mask
|= 1 << i
;
2643 if (tp_features
.hotkey_wlsw
) {
2644 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2645 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
2647 if (tp_features
.hotkey_tablet
) {
2648 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2649 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2652 /* Do not issue duplicate brightness change events to
2654 if (!tp_features
.bright_acpimode
)
2655 /* update bright_acpimode... */
2656 tpacpi_check_std_acpi_brightness_support();
2658 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
2660 "This ThinkPad has standard ACPI backlight "
2661 "brightness control, supported by the ACPI "
2663 printk(TPACPI_NOTICE
2664 "Disabling thinkpad-acpi brightness events "
2667 /* The hotkey_reserved_mask change below is not
2668 * necessary while the keys are at KEY_RESERVED in the
2669 * default map, but better safe than sorry, leave it
2670 * here as a marker of what we have to do, especially
2671 * when we finally become able to set this at runtime
2672 * on response to X.org requests */
2673 hotkey_reserved_mask
|=
2674 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
2675 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
2678 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2679 "enabling firmware HKEY event interface...\n");
2680 res
= hotkey_status_set(true);
2685 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2686 & ~hotkey_reserved_mask
)
2687 | hotkey_orig_mask
);
2688 if (res
< 0 && res
!= -ENXIO
) {
2693 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2694 "legacy ibm/hotkey event reporting over procfs %s\n",
2695 (hotkey_report_mode
< 2) ?
2696 "enabled" : "disabled");
2698 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2699 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2701 hotkey_poll_setup_safe(1);
2702 tpacpi_send_radiosw_update();
2703 tpacpi_input_send_tabletsw();
2708 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2709 hotkey_dev_attributes
= NULL
;
2711 return (res
< 0)? res
: 1;
2714 static bool hotkey_notify_hotkey(const u32 hkey
,
2716 bool *ignore_acpi_ev
)
2718 /* 0x1000-0x1FFF: key presses */
2719 unsigned int scancode
= hkey
& 0xfff;
2720 *send_acpi_ev
= true;
2721 *ignore_acpi_ev
= false;
2723 if (scancode
> 0 && scancode
< 0x21) {
2725 if (!(hotkey_source_mask
& (1 << scancode
))) {
2726 tpacpi_input_send_key(scancode
);
2727 *send_acpi_ev
= false;
2729 *ignore_acpi_ev
= true;
2736 static bool hotkey_notify_wakeup(const u32 hkey
,
2738 bool *ignore_acpi_ev
)
2740 /* 0x2000-0x2FFF: Wakeup reason */
2741 *send_acpi_ev
= true;
2742 *ignore_acpi_ev
= false;
2745 case 0x2304: /* suspend, undock */
2746 case 0x2404: /* hibernation, undock */
2747 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2748 *ignore_acpi_ev
= true;
2751 case 0x2305: /* suspend, bay eject */
2752 case 0x2405: /* hibernation, bay eject */
2753 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2754 *ignore_acpi_ev
= true;
2757 case 0x2313: /* Battery on critical low level (S3) */
2758 case 0x2413: /* Battery on critical low level (S4) */
2760 "EMERGENCY WAKEUP: battery almost empty\n");
2761 /* how to auto-heal: */
2762 /* 2313: woke up from S3, go to S4/S5 */
2763 /* 2413: woke up from S4, go to S5 */
2770 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2772 "woke up due to a hot-unplug "
2774 hotkey_wakeup_reason_notify_change();
2779 static bool hotkey_notify_usrevent(const u32 hkey
,
2781 bool *ignore_acpi_ev
)
2783 /* 0x5000-0x5FFF: human interface helpers */
2784 *send_acpi_ev
= true;
2785 *ignore_acpi_ev
= false;
2788 case 0x5010: /* Lenovo new BIOS: brightness changed */
2789 case 0x500b: /* X61t: tablet pen inserted into bay */
2790 case 0x500c: /* X61t: tablet pen removed from bay */
2793 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2794 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2795 tpacpi_input_send_tabletsw();
2796 hotkey_tablet_mode_notify_change();
2797 *send_acpi_ev
= false;
2802 /* LID switch events. Do not propagate */
2803 *ignore_acpi_ev
= true;
2811 static bool hotkey_notify_thermal(const u32 hkey
,
2813 bool *ignore_acpi_ev
)
2815 /* 0x6000-0x6FFF: thermal alarms */
2816 *send_acpi_ev
= true;
2817 *ignore_acpi_ev
= false;
2822 "THERMAL ALARM: battery is too hot!\n");
2823 /* recommended action: warn user through gui */
2827 "THERMAL EMERGENCY: battery is extremely hot!\n");
2828 /* recommended action: immediate sleep/hibernate */
2833 "a sensor reports something is too hot!\n");
2834 /* recommended action: warn user through gui, that */
2835 /* some internal component is too hot */
2839 "THERMAL EMERGENCY: "
2840 "a sensor reports something is extremely hot!\n");
2841 /* recommended action: immediate sleep/hibernate */
2845 "EC reports that Thermal Table has changed\n");
2846 /* recommended action: do nothing, we don't have
2847 * Lenovo ATM information */
2851 "THERMAL ALERT: unknown thermal alarm received\n");
2856 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2860 bool ignore_acpi_ev
;
2863 if (event
!= 0x80) {
2865 "unknown HKEY notification event %d\n", event
);
2866 /* forward it to userspace, maybe it knows how to handle it */
2867 acpi_bus_generate_netlink_event(
2868 ibm
->acpi
->device
->pnp
.device_class
,
2869 dev_name(&ibm
->acpi
->device
->dev
),
2875 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2876 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2885 send_acpi_ev
= true;
2886 ignore_acpi_ev
= false;
2888 switch (hkey
>> 12) {
2890 /* 0x1000-0x1FFF: key presses */
2891 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
2895 /* 0x2000-0x2FFF: Wakeup reason */
2896 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
2900 /* 0x3000-0x3FFF: bay-related wakeups */
2901 if (hkey
== 0x3003) {
2902 hotkey_autosleep_ack
= 1;
2905 hotkey_wakeup_hotunplug_complete_notify_change();
2912 /* 0x4000-0x4FFF: dock-related wakeups */
2913 if (hkey
== 0x4003) {
2914 hotkey_autosleep_ack
= 1;
2917 hotkey_wakeup_hotunplug_complete_notify_change();
2924 /* 0x5000-0x5FFF: human interface helpers */
2925 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
2929 /* 0x6000-0x6FFF: thermal alarms */
2930 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
2934 /* 0x7000-0x7FFF: misc */
2935 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2936 tpacpi_send_radiosw_update();
2941 /* fallthrough to default */
2946 printk(TPACPI_NOTICE
2947 "unhandled HKEY event 0x%04x\n", hkey
);
2948 printk(TPACPI_NOTICE
2949 "please report the conditions when this "
2950 "event happened to %s\n", TPACPI_MAIL
);
2954 if (!ignore_acpi_ev
&&
2955 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2956 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2960 /* netlink events */
2961 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2962 acpi_bus_generate_netlink_event(
2963 ibm
->acpi
->device
->pnp
.device_class
,
2964 dev_name(&ibm
->acpi
->device
->dev
),
2970 static void hotkey_suspend(pm_message_t state
)
2972 /* Do these on suspend, we get the events on early resume! */
2973 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2974 hotkey_autosleep_ack
= 0;
2977 static void hotkey_resume(void)
2979 tpacpi_disable_brightness_delay();
2981 if (hotkey_mask_get())
2983 "error while trying to read hot key mask "
2985 tpacpi_send_radiosw_update();
2986 hotkey_tablet_mode_notify_change();
2987 hotkey_wakeup_reason_notify_change();
2988 hotkey_wakeup_hotunplug_complete_notify_change();
2989 hotkey_poll_setup_safe(0);
2992 /* procfs -------------------------------------------------------------- */
2993 static int hotkey_read(char *p
)
2998 if (!tp_features
.hotkey
) {
2999 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3003 if (mutex_lock_killable(&hotkey_mutex
))
3004 return -ERESTARTSYS
;
3005 res
= hotkey_status_get(&status
);
3007 res
= hotkey_mask_get();
3008 mutex_unlock(&hotkey_mutex
);
3012 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
3013 if (tp_features
.hotkey_mask
) {
3014 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
3015 len
+= sprintf(p
+ len
,
3016 "commands:\tenable, disable, reset, <mask>\n");
3018 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
3019 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
3025 static void hotkey_enabledisable_warn(bool enable
)
3027 tpacpi_log_usertask("procfs hotkey enable/disable");
3028 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3030 "hotkey enable/disable functionality has been "
3031 "removed from the driver. Hotkeys are always "
3034 "Please remove the hotkey=enable module "
3035 "parameter, it is deprecated. Hotkeys are always "
3039 static int hotkey_write(char *buf
)
3045 if (!tp_features
.hotkey
)
3048 if (mutex_lock_killable(&hotkey_mutex
))
3049 return -ERESTARTSYS
;
3054 while ((cmd
= next_cmd(&buf
))) {
3055 if (strlencmp(cmd
, "enable") == 0) {
3056 hotkey_enabledisable_warn(1);
3057 } else if (strlencmp(cmd
, "disable") == 0) {
3058 hotkey_enabledisable_warn(0);
3060 } else if (strlencmp(cmd
, "reset") == 0) {
3061 mask
= hotkey_orig_mask
;
3062 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3064 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3073 tpacpi_disclose_usertask("procfs hotkey",
3074 "set mask to 0x%08x\n", mask
);
3076 if (!res
&& mask
!= hotkey_mask
)
3077 res
= hotkey_mask_set(mask
);
3080 mutex_unlock(&hotkey_mutex
);
3084 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3085 {TPACPI_ACPI_HKEY_HID
, 0},
3089 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3090 .hid
= ibm_htk_device_ids
,
3091 .notify
= hotkey_notify
,
3092 .handle
= &hkey_handle
,
3093 .type
= ACPI_DEVICE_NOTIFY
,
3096 static struct ibm_struct hotkey_driver_data
= {
3098 .read
= hotkey_read
,
3099 .write
= hotkey_write
,
3100 .exit
= hotkey_exit
,
3101 .resume
= hotkey_resume
,
3102 .suspend
= hotkey_suspend
,
3103 .acpi
= &ibm_hotkey_acpidriver
,
3106 /*************************************************************************
3107 * Bluetooth subdriver
3111 /* ACPI GBDC/SBDC bits */
3112 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3113 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3114 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3119 /* ACPI \BLTH commands */
3120 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3121 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3122 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3123 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3124 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3127 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3129 static struct rfkill
*tpacpi_bluetooth_rfkill
;
3131 static void bluetooth_suspend(pm_message_t state
)
3133 /* Try to make sure radio will resume powered off */
3134 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3135 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
))
3136 vdbg_printk(TPACPI_DBG_RFKILL
,
3137 "bluetooth power down on resume request failed\n");
3140 static int bluetooth_get_radiosw(void)
3144 if (!tp_features
.bluetooth
)
3147 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
3148 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3149 return RFKILL_STATE_HARD_BLOCKED
;
3151 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3152 if (dbg_bluetoothemul
)
3153 return (tpacpi_bluetooth_emulstate
) ?
3154 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3157 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3160 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3161 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3164 static void bluetooth_update_rfk(void)
3168 if (!tpacpi_bluetooth_rfkill
)
3171 status
= bluetooth_get_radiosw();
3174 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
3176 vdbg_printk(TPACPI_DBG_RFKILL
,
3177 "forced rfkill state to %d\n",
3181 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
3185 if (!tp_features
.bluetooth
)
3188 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3189 * reason to risk weird behaviour. */
3190 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3194 vdbg_printk(TPACPI_DBG_RFKILL
,
3195 "will %s bluetooth\n", radio_on
? "enable" : "disable");
3197 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3198 if (dbg_bluetoothemul
) {
3199 tpacpi_bluetooth_emulstate
= !!radio_on
;
3201 bluetooth_update_rfk();
3206 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3208 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
3211 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3215 bluetooth_update_rfk();
3220 /* sysfs bluetooth enable ---------------------------------------------- */
3221 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3222 struct device_attribute
*attr
,
3227 printk_deprecated_rfkill_attribute("bluetooth_enable");
3229 status
= bluetooth_get_radiosw();
3233 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3234 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3237 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3238 struct device_attribute
*attr
,
3239 const char *buf
, size_t count
)
3244 printk_deprecated_rfkill_attribute("bluetooth_enable");
3246 if (parse_strtoul(buf
, 1, &t
))
3249 tpacpi_disclose_usertask("bluetooth_enable", "set to %ld\n", t
);
3251 res
= bluetooth_set_radiosw(t
, 1);
3253 return (res
) ? res
: count
;
3256 static struct device_attribute dev_attr_bluetooth_enable
=
3257 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3258 bluetooth_enable_show
, bluetooth_enable_store
);
3260 /* --------------------------------------------------------------------- */
3262 static struct attribute
*bluetooth_attributes
[] = {
3263 &dev_attr_bluetooth_enable
.attr
,
3267 static const struct attribute_group bluetooth_attr_group
= {
3268 .attrs
= bluetooth_attributes
,
3271 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
3273 int bts
= bluetooth_get_radiosw();
3282 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
3284 dbg_printk(TPACPI_DBG_RFKILL
,
3285 "request to change radio state to %d\n", state
);
3286 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3289 static void bluetooth_shutdown(void)
3291 /* Order firmware to save current state to NVRAM */
3292 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3293 TP_ACPI_BLTH_SAVE_STATE
))
3294 printk(TPACPI_NOTICE
3295 "failed to save bluetooth state to NVRAM\n");
3297 vdbg_printk(TPACPI_DBG_RFKILL
,
3298 "bluestooth state saved to NVRAM\n");
3301 static void bluetooth_exit(void)
3303 bluetooth_shutdown();
3305 if (tpacpi_bluetooth_rfkill
)
3306 rfkill_unregister(tpacpi_bluetooth_rfkill
);
3308 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3309 &bluetooth_attr_group
);
3312 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3317 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3318 "initializing bluetooth subdriver\n");
3320 TPACPI_ACPIHANDLE_INIT(hkey
);
3322 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3323 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3324 tp_features
.bluetooth
= hkey_handle
&&
3325 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3327 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3328 "bluetooth is %s, status 0x%02x\n",
3329 str_supported(tp_features
.bluetooth
),
3332 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3333 if (dbg_bluetoothemul
) {
3334 tp_features
.bluetooth
= 1;
3336 "bluetooth switch emulation enabled\n");
3339 if (tp_features
.bluetooth
&&
3340 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
3341 /* no bluetooth hardware present in system */
3342 tp_features
.bluetooth
= 0;
3343 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3344 "bluetooth hardware not installed\n");
3347 if (!tp_features
.bluetooth
)
3350 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3351 &bluetooth_attr_group
);
3355 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3356 &tpacpi_bluetooth_rfkill
,
3357 RFKILL_TYPE_BLUETOOTH
,
3358 TPACPI_RFK_BLUETOOTH_SW_NAME
,
3360 tpacpi_bluetooth_rfk_set
,
3361 tpacpi_bluetooth_rfk_get
);
3370 /* procfs -------------------------------------------------------------- */
3371 static int bluetooth_read(char *p
)
3374 int status
= bluetooth_get_radiosw();
3376 if (!tp_features
.bluetooth
)
3377 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3379 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3380 (status
== RFKILL_STATE_UNBLOCKED
) ?
3381 "enabled" : "disabled");
3382 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3388 static int bluetooth_write(char *buf
)
3393 if (!tp_features
.bluetooth
)
3396 while ((cmd
= next_cmd(&buf
))) {
3397 if (strlencmp(cmd
, "enable") == 0) {
3399 } else if (strlencmp(cmd
, "disable") == 0) {
3406 tpacpi_disclose_usertask("procfs bluetooth",
3408 state
? "enable" : "disable");
3409 bluetooth_set_radiosw(state
, 1);
3415 static struct ibm_struct bluetooth_driver_data
= {
3416 .name
= "bluetooth",
3417 .read
= bluetooth_read
,
3418 .write
= bluetooth_write
,
3419 .exit
= bluetooth_exit
,
3420 .suspend
= bluetooth_suspend
,
3421 .shutdown
= bluetooth_shutdown
,
3424 /*************************************************************************
3429 /* ACPI GWAN/SWAN bits */
3430 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3431 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3432 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3436 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
3438 static struct rfkill
*tpacpi_wan_rfkill
;
3440 static void wan_suspend(pm_message_t state
)
3442 /* Try to make sure radio will resume powered off */
3443 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3444 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
))
3445 vdbg_printk(TPACPI_DBG_RFKILL
,
3446 "WWAN power down on resume request failed\n");
3449 static int wan_get_radiosw(void)
3453 if (!tp_features
.wan
)
3456 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3457 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3458 return RFKILL_STATE_HARD_BLOCKED
;
3460 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3462 return (tpacpi_wwan_emulstate
) ?
3463 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3466 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3469 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3470 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3473 static void wan_update_rfk(void)
3477 if (!tpacpi_wan_rfkill
)
3480 status
= wan_get_radiosw();
3483 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3485 vdbg_printk(TPACPI_DBG_RFKILL
,
3486 "forced rfkill state to %d\n",
3490 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3494 if (!tp_features
.wan
)
3497 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3498 * reason to risk weird behaviour. */
3499 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3503 vdbg_printk(TPACPI_DBG_RFKILL
,
3504 "will %s WWAN\n", radio_on
? "enable" : "disable");
3506 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3508 tpacpi_wwan_emulstate
= !!radio_on
;
3515 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3517 status
= TP_ACPI_WANCARD_RADIOSSW
;
3520 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3529 /* sysfs wan enable ---------------------------------------------------- */
3530 static ssize_t
wan_enable_show(struct device
*dev
,
3531 struct device_attribute
*attr
,
3536 printk_deprecated_rfkill_attribute("wwan_enable");
3538 status
= wan_get_radiosw();
3542 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3543 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3546 static ssize_t
wan_enable_store(struct device
*dev
,
3547 struct device_attribute
*attr
,
3548 const char *buf
, size_t count
)
3553 printk_deprecated_rfkill_attribute("wwan_enable");
3555 if (parse_strtoul(buf
, 1, &t
))
3558 tpacpi_disclose_usertask("wwan_enable", "set to %ld\n", t
);
3560 res
= wan_set_radiosw(t
, 1);
3562 return (res
) ? res
: count
;
3565 static struct device_attribute dev_attr_wan_enable
=
3566 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
3567 wan_enable_show
, wan_enable_store
);
3569 /* --------------------------------------------------------------------- */
3571 static struct attribute
*wan_attributes
[] = {
3572 &dev_attr_wan_enable
.attr
,
3576 static const struct attribute_group wan_attr_group
= {
3577 .attrs
= wan_attributes
,
3580 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
3582 int wans
= wan_get_radiosw();
3591 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
3593 dbg_printk(TPACPI_DBG_RFKILL
,
3594 "request to change radio state to %d\n", state
);
3595 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3598 static void wan_shutdown(void)
3600 /* Order firmware to save current state to NVRAM */
3601 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
3602 TP_ACPI_WGSV_SAVE_STATE
))
3603 printk(TPACPI_NOTICE
3604 "failed to save WWAN state to NVRAM\n");
3606 vdbg_printk(TPACPI_DBG_RFKILL
,
3607 "WWAN state saved to NVRAM\n");
3610 static void wan_exit(void)
3614 if (tpacpi_wan_rfkill
)
3615 rfkill_unregister(tpacpi_wan_rfkill
);
3617 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3621 static int __init
wan_init(struct ibm_init_struct
*iibm
)
3626 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3627 "initializing wan subdriver\n");
3629 TPACPI_ACPIHANDLE_INIT(hkey
);
3631 tp_features
.wan
= hkey_handle
&&
3632 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
3634 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3635 "wan is %s, status 0x%02x\n",
3636 str_supported(tp_features
.wan
),
3639 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3641 tp_features
.wan
= 1;
3643 "wwan switch emulation enabled\n");
3646 if (tp_features
.wan
&&
3647 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
3648 /* no wan hardware present in system */
3649 tp_features
.wan
= 0;
3650 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3651 "wan hardware not installed\n");
3654 if (!tp_features
.wan
)
3657 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3662 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
3665 TPACPI_RFK_WWAN_SW_NAME
,
3668 tpacpi_wan_rfk_get
);
3677 /* procfs -------------------------------------------------------------- */
3678 static int wan_read(char *p
)
3681 int status
= wan_get_radiosw();
3683 tpacpi_disclose_usertask("procfs wan", "read");
3685 if (!tp_features
.wan
)
3686 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3688 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3689 (status
== RFKILL_STATE_UNBLOCKED
) ?
3690 "enabled" : "disabled");
3691 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3697 static int wan_write(char *buf
)
3702 if (!tp_features
.wan
)
3705 while ((cmd
= next_cmd(&buf
))) {
3706 if (strlencmp(cmd
, "enable") == 0) {
3708 } else if (strlencmp(cmd
, "disable") == 0) {
3715 tpacpi_disclose_usertask("procfs wan",
3717 state
? "enable" : "disable");
3718 wan_set_radiosw(state
, 1);
3724 static struct ibm_struct wan_driver_data
= {
3729 .suspend
= wan_suspend
,
3730 .shutdown
= wan_shutdown
,
3733 /*************************************************************************
3738 /* ACPI GUWB/SUWB bits */
3739 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
3740 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
3743 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
3745 static struct rfkill
*tpacpi_uwb_rfkill
;
3747 static int uwb_get_radiosw(void)
3751 if (!tp_features
.uwb
)
3754 /* WLSW overrides UWB in firmware/hardware, reflect that */
3755 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3756 return RFKILL_STATE_HARD_BLOCKED
;
3758 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3760 return (tpacpi_uwb_emulstate
) ?
3761 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3764 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
3767 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
3768 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3771 static void uwb_update_rfk(void)
3775 if (!tpacpi_uwb_rfkill
)
3778 status
= uwb_get_radiosw();
3781 rfkill_force_state(tpacpi_uwb_rfkill
, status
);
3783 vdbg_printk(TPACPI_DBG_RFKILL
,
3784 "forced rfkill state to %d\n",
3788 static int uwb_set_radiosw(int radio_on
, int update_rfk
)
3792 if (!tp_features
.uwb
)
3795 /* WLSW overrides UWB in firmware/hardware, but there is no
3796 * reason to risk weird behaviour. */
3797 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3801 vdbg_printk(TPACPI_DBG_RFKILL
,
3802 "will %s UWB\n", radio_on
? "enable" : "disable");
3804 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3806 tpacpi_uwb_emulstate
= !!radio_on
;
3813 status
= (radio_on
) ? TP_ACPI_UWB_RADIOSSW
: 0;
3814 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
3823 /* --------------------------------------------------------------------- */
3825 static int tpacpi_uwb_rfk_get(void *data
, enum rfkill_state
*state
)
3827 int uwbs
= uwb_get_radiosw();
3836 static int tpacpi_uwb_rfk_set(void *data
, enum rfkill_state state
)
3838 dbg_printk(TPACPI_DBG_RFKILL
,
3839 "request to change radio state to %d\n", state
);
3840 return uwb_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3843 static void uwb_exit(void)
3845 if (tpacpi_uwb_rfkill
)
3846 rfkill_unregister(tpacpi_uwb_rfkill
);
3849 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
3854 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3855 "initializing uwb subdriver\n");
3857 TPACPI_ACPIHANDLE_INIT(hkey
);
3859 tp_features
.uwb
= hkey_handle
&&
3860 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
3862 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3863 "uwb is %s, status 0x%02x\n",
3864 str_supported(tp_features
.uwb
),
3867 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3869 tp_features
.uwb
= 1;
3871 "uwb switch emulation enabled\n");
3874 if (tp_features
.uwb
&&
3875 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
3876 /* no uwb hardware present in system */
3877 tp_features
.uwb
= 0;
3878 dbg_printk(TPACPI_DBG_INIT
,
3879 "uwb hardware not installed\n");
3882 if (!tp_features
.uwb
)
3885 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
3888 TPACPI_RFK_UWB_SW_NAME
,
3891 tpacpi_uwb_rfk_get
);
3896 static struct ibm_struct uwb_driver_data
= {
3899 .flags
.experimental
= 1,
3902 /*************************************************************************
3906 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
3908 enum video_access_mode
{
3909 TPACPI_VIDEO_NONE
= 0,
3910 TPACPI_VIDEO_570
, /* 570 */
3911 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
3912 TPACPI_VIDEO_NEW
, /* all others */
3915 enum { /* video status flags, based on VIDEO_570 */
3916 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
3917 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
3918 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
3921 enum { /* TPACPI_VIDEO_570 constants */
3922 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
3923 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
3924 * video_status_flags */
3925 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
3926 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
3929 static enum video_access_mode video_supported
;
3930 static int video_orig_autosw
;
3932 static int video_autosw_get(void);
3933 static int video_autosw_set(int enable
);
3935 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
3937 static int __init
video_init(struct ibm_init_struct
*iibm
)
3941 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
3943 TPACPI_ACPIHANDLE_INIT(vid
);
3944 TPACPI_ACPIHANDLE_INIT(vid2
);
3946 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
3947 /* G41, assume IVGA doesn't change */
3948 vid_handle
= vid2_handle
;
3951 /* video switching not supported on R30, R31 */
3952 video_supported
= TPACPI_VIDEO_NONE
;
3953 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
3955 video_supported
= TPACPI_VIDEO_570
;
3956 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
3957 /* 600e/x, 770e, 770x */
3958 video_supported
= TPACPI_VIDEO_770
;
3961 video_supported
= TPACPI_VIDEO_NEW
;
3963 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
3964 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
3967 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
3970 static void video_exit(void)
3972 dbg_printk(TPACPI_DBG_EXIT
,
3973 "restoring original video autoswitch mode\n");
3974 if (video_autosw_set(video_orig_autosw
))
3975 printk(TPACPI_ERR
"error while trying to restore original "
3976 "video autoswitch mode\n");
3979 static int video_outputsw_get(void)
3984 switch (video_supported
) {
3985 case TPACPI_VIDEO_570
:
3986 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
3987 TP_ACPI_VIDEO_570_PHSCMD
))
3989 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
3991 case TPACPI_VIDEO_770
:
3992 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3995 status
|= TP_ACPI_VIDEO_S_LCD
;
3996 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3999 status
|= TP_ACPI_VIDEO_S_CRT
;
4001 case TPACPI_VIDEO_NEW
:
4002 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4003 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4006 status
|= TP_ACPI_VIDEO_S_CRT
;
4008 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4009 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4012 status
|= TP_ACPI_VIDEO_S_LCD
;
4013 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4016 status
|= TP_ACPI_VIDEO_S_DVI
;
4025 static int video_outputsw_set(int status
)
4030 switch (video_supported
) {
4031 case TPACPI_VIDEO_570
:
4032 res
= acpi_evalf(NULL
, NULL
,
4033 "\\_SB.PHS2", "vdd",
4034 TP_ACPI_VIDEO_570_PHS2CMD
,
4035 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4037 case TPACPI_VIDEO_770
:
4038 autosw
= video_autosw_get();
4042 res
= video_autosw_set(1);
4045 res
= acpi_evalf(vid_handle
, NULL
,
4046 "ASWT", "vdd", status
* 0x100, 0);
4047 if (!autosw
&& video_autosw_set(autosw
)) {
4049 "video auto-switch left enabled due to error\n");
4053 case TPACPI_VIDEO_NEW
:
4054 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4055 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4061 return (res
)? 0 : -EIO
;
4064 static int video_autosw_get(void)
4068 switch (video_supported
) {
4069 case TPACPI_VIDEO_570
:
4070 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4073 case TPACPI_VIDEO_770
:
4074 case TPACPI_VIDEO_NEW
:
4075 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4085 static int video_autosw_set(int enable
)
4087 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4092 static int video_outputsw_cycle(void)
4094 int autosw
= video_autosw_get();
4100 switch (video_supported
) {
4101 case TPACPI_VIDEO_570
:
4102 res
= video_autosw_set(1);
4105 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4107 case TPACPI_VIDEO_770
:
4108 case TPACPI_VIDEO_NEW
:
4109 res
= video_autosw_set(1);
4112 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4117 if (!autosw
&& video_autosw_set(autosw
)) {
4119 "video auto-switch left enabled due to error\n");
4123 return (res
)? 0 : -EIO
;
4126 static int video_expand_toggle(void)
4128 switch (video_supported
) {
4129 case TPACPI_VIDEO_570
:
4130 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4132 case TPACPI_VIDEO_770
:
4133 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4135 case TPACPI_VIDEO_NEW
:
4136 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4144 static int video_read(char *p
)
4149 if (video_supported
== TPACPI_VIDEO_NONE
) {
4150 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4154 status
= video_outputsw_get();
4158 autosw
= video_autosw_get();
4162 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4163 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
4164 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
4165 if (video_supported
== TPACPI_VIDEO_NEW
)
4166 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
4167 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
4168 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
4169 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
4170 if (video_supported
== TPACPI_VIDEO_NEW
)
4171 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
4172 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
4173 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
4178 static int video_write(char *buf
)
4181 int enable
, disable
, status
;
4184 if (video_supported
== TPACPI_VIDEO_NONE
)
4190 while ((cmd
= next_cmd(&buf
))) {
4191 if (strlencmp(cmd
, "lcd_enable") == 0) {
4192 enable
|= TP_ACPI_VIDEO_S_LCD
;
4193 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4194 disable
|= TP_ACPI_VIDEO_S_LCD
;
4195 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4196 enable
|= TP_ACPI_VIDEO_S_CRT
;
4197 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4198 disable
|= TP_ACPI_VIDEO_S_CRT
;
4199 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4200 strlencmp(cmd
, "dvi_enable") == 0) {
4201 enable
|= TP_ACPI_VIDEO_S_DVI
;
4202 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4203 strlencmp(cmd
, "dvi_disable") == 0) {
4204 disable
|= TP_ACPI_VIDEO_S_DVI
;
4205 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4206 res
= video_autosw_set(1);
4209 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4210 res
= video_autosw_set(0);
4213 } else if (strlencmp(cmd
, "video_switch") == 0) {
4214 res
= video_outputsw_cycle();
4217 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4218 res
= video_expand_toggle();
4225 if (enable
|| disable
) {
4226 status
= video_outputsw_get();
4229 res
= video_outputsw_set((status
& ~disable
) | enable
);
4237 static struct ibm_struct video_driver_data
= {
4240 .write
= video_write
,
4244 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4246 /*************************************************************************
4247 * Light (thinklight) subdriver
4250 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4251 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4253 static int light_get_status(void)
4257 if (tp_features
.light_status
) {
4258 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4266 static int light_set_status(int status
)
4270 if (tp_features
.light
) {
4272 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4274 TP_CMOS_THINKLIGHT_ON
:
4275 TP_CMOS_THINKLIGHT_OFF
);
4277 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4280 return (rc
)? 0 : -EIO
;
4286 static void light_set_status_worker(struct work_struct
*work
)
4288 struct tpacpi_led_classdev
*data
=
4289 container_of(work
, struct tpacpi_led_classdev
, work
);
4291 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4292 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4295 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4296 enum led_brightness brightness
)
4298 struct tpacpi_led_classdev
*data
=
4299 container_of(led_cdev
,
4300 struct tpacpi_led_classdev
,
4302 data
->new_state
= (brightness
!= LED_OFF
) ?
4303 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4304 queue_work(tpacpi_wq
, &data
->work
);
4307 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4309 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4312 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4314 .name
= "tpacpi::thinklight",
4315 .brightness_set
= &light_sysfs_set
,
4316 .brightness_get
= &light_sysfs_get
,
4320 static int __init
light_init(struct ibm_init_struct
*iibm
)
4324 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4326 TPACPI_ACPIHANDLE_INIT(ledb
);
4327 TPACPI_ACPIHANDLE_INIT(lght
);
4328 TPACPI_ACPIHANDLE_INIT(cmos
);
4329 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4331 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4332 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4334 if (tp_features
.light
)
4335 /* light status not supported on
4336 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4337 tp_features
.light_status
=
4338 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4340 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4341 str_supported(tp_features
.light
),
4342 str_supported(tp_features
.light_status
));
4344 if (!tp_features
.light
)
4347 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4348 &tpacpi_led_thinklight
.led_classdev
);
4351 tp_features
.light
= 0;
4352 tp_features
.light_status
= 0;
4360 static void light_exit(void)
4362 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4363 if (work_pending(&tpacpi_led_thinklight
.work
))
4364 flush_workqueue(tpacpi_wq
);
4367 static int light_read(char *p
)
4372 if (!tp_features
.light
) {
4373 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4374 } else if (!tp_features
.light_status
) {
4375 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
4376 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4378 status
= light_get_status();
4381 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
4382 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4388 static int light_write(char *buf
)
4393 if (!tp_features
.light
)
4396 while ((cmd
= next_cmd(&buf
))) {
4397 if (strlencmp(cmd
, "on") == 0) {
4399 } else if (strlencmp(cmd
, "off") == 0) {
4405 return light_set_status(newstatus
);
4408 static struct ibm_struct light_driver_data
= {
4411 .write
= light_write
,
4415 /*************************************************************************
4419 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4421 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
4422 static int dock_read(char *p
);
4423 static int dock_write(char *buf
);
4425 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
4426 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
4427 "\\_SB.PCI0.PCI1.DOCK", /* all others */
4428 "\\_SB.PCI.ISA.SLCE", /* 570 */
4429 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
4431 /* don't list other alternatives as we install a notify handler on the 570 */
4432 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
4434 static const struct acpi_device_id ibm_pci_device_ids
[] = {
4435 {PCI_ROOT_HID_STRING
, 0},
4439 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
4441 .notify
= dock_notify
,
4442 .handle
= &dock_handle
,
4443 .type
= ACPI_SYSTEM_NOTIFY
,
4446 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
4447 * We just use it to get notifications of dock hotplug
4448 * in very old thinkpads */
4449 .hid
= ibm_pci_device_ids
,
4450 .notify
= dock_notify
,
4451 .handle
= &pci_handle
,
4452 .type
= ACPI_SYSTEM_NOTIFY
,
4456 static struct ibm_struct dock_driver_data
[2] = {
4460 .write
= dock_write
,
4461 .acpi
= &ibm_dock_acpidriver
[0],
4465 .acpi
= &ibm_dock_acpidriver
[1],
4469 #define dock_docked() (_sta(dock_handle) & 1)
4471 static int __init
dock_init(struct ibm_init_struct
*iibm
)
4473 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
4475 TPACPI_ACPIHANDLE_INIT(dock
);
4477 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
4478 str_supported(dock_handle
!= NULL
));
4480 return (dock_handle
)? 0 : 1;
4483 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
4487 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
4489 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
4490 dock_driver_data
[0].flags
.acpi_notify_installed
) {
4491 TPACPI_ACPIHANDLE_INIT(pci
);
4492 dock2_needed
= (pci_handle
!= NULL
);
4493 vdbg_printk(TPACPI_DBG_INIT
,
4494 "dock PCI handler for the TP 570 is %s\n",
4495 str_supported(dock2_needed
));
4497 vdbg_printk(TPACPI_DBG_INIT
,
4498 "dock subdriver part 2 not required\n");
4502 return (dock2_needed
)? 0 : 1;
4505 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
4507 int docked
= dock_docked();
4508 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
4509 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
4512 if (event
== 1 && !pci
) /* 570 */
4513 data
= 1; /* button */
4514 else if (event
== 1 && pci
) /* 570 */
4515 data
= 3; /* dock */
4516 else if (event
== 3 && docked
)
4517 data
= 1; /* button */
4518 else if (event
== 3 && !docked
)
4519 data
= 2; /* undock */
4520 else if (event
== 0 && docked
)
4521 data
= 3; /* dock */
4523 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
4524 event
, _sta(dock_handle
));
4525 data
= 0; /* unknown */
4527 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
4528 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
4529 dev_name(&ibm
->acpi
->device
->dev
),
4533 static int dock_read(char *p
)
4536 int docked
= dock_docked();
4539 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4541 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
4543 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
4544 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
4550 static int dock_write(char *buf
)
4557 while ((cmd
= next_cmd(&buf
))) {
4558 if (strlencmp(cmd
, "undock") == 0) {
4559 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
4560 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
4562 } else if (strlencmp(cmd
, "dock") == 0) {
4563 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
4572 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
4574 /*************************************************************************
4578 #ifdef CONFIG_THINKPAD_ACPI_BAY
4580 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
4581 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
4582 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
4583 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
4584 ); /* A21e, R30, R31 */
4585 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
4586 "_EJ0", /* all others */
4587 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
4588 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
4589 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
4591 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
4595 static int __init
bay_init(struct ibm_init_struct
*iibm
)
4597 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
4599 TPACPI_ACPIHANDLE_INIT(bay
);
4601 TPACPI_ACPIHANDLE_INIT(bay_ej
);
4602 TPACPI_ACPIHANDLE_INIT(bay2
);
4604 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
4606 tp_features
.bay_status
= bay_handle
&&
4607 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
4608 tp_features
.bay_status2
= bay2_handle
&&
4609 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
4611 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
4612 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
4613 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
4614 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
4616 vdbg_printk(TPACPI_DBG_INIT
,
4617 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
4618 str_supported(tp_features
.bay_status
),
4619 str_supported(tp_features
.bay_eject
),
4620 str_supported(tp_features
.bay_status2
),
4621 str_supported(tp_features
.bay_eject2
));
4623 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
4624 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
4627 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
4629 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
4630 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
4631 dev_name(&ibm
->acpi
->device
->dev
),
4635 #define bay_occupied(b) (_sta(b##_handle) & 1)
4637 static int bay_read(char *p
)
4640 int occupied
= bay_occupied(bay
);
4641 int occupied2
= bay_occupied(bay2
);
4644 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4645 tp_features
.bay_status
?
4646 (occupied
? "occupied" : "unoccupied") :
4648 if (tp_features
.bay_status2
)
4649 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
4650 "occupied" : "unoccupied");
4652 eject
= tp_features
.bay_eject
&& occupied
;
4653 eject2
= tp_features
.bay_eject2
&& occupied2
;
4655 if (eject
&& eject2
)
4656 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
4658 len
+= sprintf(p
+ len
, "commands:\teject\n");
4660 len
+= sprintf(p
+ len
, "commands:\teject2\n");
4665 static int bay_write(char *buf
)
4669 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
4672 while ((cmd
= next_cmd(&buf
))) {
4673 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
4674 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
4676 } else if (tp_features
.bay_eject2
&&
4677 strlencmp(cmd
, "eject2") == 0) {
4678 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
4687 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
4688 .notify
= bay_notify
,
4689 .handle
= &bay_handle
,
4690 .type
= ACPI_SYSTEM_NOTIFY
,
4693 static struct ibm_struct bay_driver_data
= {
4697 .acpi
= &ibm_bay_acpidriver
,
4700 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4702 /*************************************************************************
4706 /* sysfs cmos_command -------------------------------------------------- */
4707 static ssize_t
cmos_command_store(struct device
*dev
,
4708 struct device_attribute
*attr
,
4709 const char *buf
, size_t count
)
4711 unsigned long cmos_cmd
;
4714 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4717 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4718 return (res
)? res
: count
;
4721 static struct device_attribute dev_attr_cmos_command
=
4722 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4724 /* --------------------------------------------------------------------- */
4726 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4730 vdbg_printk(TPACPI_DBG_INIT
,
4731 "initializing cmos commands subdriver\n");
4733 TPACPI_ACPIHANDLE_INIT(cmos
);
4735 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4736 str_supported(cmos_handle
!= NULL
));
4738 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4742 return (cmos_handle
)? 0 : 1;
4745 static void cmos_exit(void)
4747 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4750 static int cmos_read(char *p
)
4754 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4755 R30, R31, T20-22, X20-21 */
4757 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4759 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4760 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4766 static int cmos_write(char *buf
)
4771 while ((cmd
= next_cmd(&buf
))) {
4772 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4773 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4778 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4786 static struct ibm_struct cmos_driver_data
= {
4789 .write
= cmos_write
,
4793 /*************************************************************************
4797 enum led_access_mode
{
4798 TPACPI_LED_NONE
= 0,
4799 TPACPI_LED_570
, /* 570 */
4800 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4801 TPACPI_LED_NEW
, /* all others */
4804 enum { /* For TPACPI_LED_OLD */
4805 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4806 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4807 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4810 static enum led_access_mode led_supported
;
4812 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4813 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4814 /* T20-22, X20-21 */
4815 "LED", /* all others */
4818 #define TPACPI_LED_NUMLEDS 16
4819 static struct tpacpi_led_classdev
*tpacpi_leds
;
4820 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4821 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4822 /* there's a limit of 19 chars + NULL before 2.6.26 */
4824 "tpacpi:orange:batt",
4825 "tpacpi:green:batt",
4826 "tpacpi::dock_active",
4827 "tpacpi::bay_active",
4828 "tpacpi::dock_batt",
4829 "tpacpi::unknown_led",
4831 "tpacpi::dock_status1",
4832 "tpacpi::dock_status2",
4833 "tpacpi::unknown_led2",
4834 "tpacpi::unknown_led3",
4835 "tpacpi::thinkvantage",
4837 #define TPACPI_SAFE_LEDS 0x1081U
4839 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
4841 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
4844 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
4848 static int led_get_status(const unsigned int led
)
4851 enum led_status_t led_s
;
4853 switch (led_supported
) {
4854 case TPACPI_LED_570
:
4855 if (!acpi_evalf(ec_handle
,
4856 &status
, "GLED", "dd", 1 << led
))
4858 led_s
= (status
== 0)?
4863 tpacpi_led_state_cache
[led
] = led_s
;
4872 static int led_set_status(const unsigned int led
,
4873 const enum led_status_t ledstatus
)
4875 /* off, on, blink. Index is led_status_t */
4876 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
4877 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
4881 switch (led_supported
) {
4882 case TPACPI_LED_570
:
4884 if (unlikely(led
> 7))
4886 if (unlikely(tpacpi_is_led_restricted(led
)))
4888 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4889 (1 << led
), led_sled_arg1
[ledstatus
]))
4892 case TPACPI_LED_OLD
:
4893 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4894 if (unlikely(led
> 7))
4896 if (unlikely(tpacpi_is_led_restricted(led
)))
4898 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
4900 rc
= ec_write(TPACPI_LED_EC_HLBL
,
4901 (ledstatus
== TPACPI_LED_BLINK
) << led
);
4903 rc
= ec_write(TPACPI_LED_EC_HLCL
,
4904 (ledstatus
!= TPACPI_LED_OFF
) << led
);
4906 case TPACPI_LED_NEW
:
4908 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
4910 if (unlikely(tpacpi_is_led_restricted(led
)))
4912 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4913 led
, led_led_arg1
[ledstatus
]))
4921 tpacpi_led_state_cache
[led
] = ledstatus
;
4926 static void led_set_status_worker(struct work_struct
*work
)
4928 struct tpacpi_led_classdev
*data
=
4929 container_of(work
, struct tpacpi_led_classdev
, work
);
4931 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4932 led_set_status(data
->led
, data
->new_state
);
4935 static void led_sysfs_set(struct led_classdev
*led_cdev
,
4936 enum led_brightness brightness
)
4938 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4939 struct tpacpi_led_classdev
, led_classdev
);
4941 if (brightness
== LED_OFF
)
4942 data
->new_state
= TPACPI_LED_OFF
;
4943 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
4944 data
->new_state
= TPACPI_LED_ON
;
4946 data
->new_state
= TPACPI_LED_BLINK
;
4948 queue_work(tpacpi_wq
, &data
->work
);
4951 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
4952 unsigned long *delay_on
, unsigned long *delay_off
)
4954 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4955 struct tpacpi_led_classdev
, led_classdev
);
4957 /* Can we choose the flash rate? */
4958 if (*delay_on
== 0 && *delay_off
== 0) {
4959 /* yes. set them to the hardware blink rate (1 Hz) */
4960 *delay_on
= 500; /* ms */
4961 *delay_off
= 500; /* ms */
4962 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
4965 data
->new_state
= TPACPI_LED_BLINK
;
4966 queue_work(tpacpi_wq
, &data
->work
);
4971 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
4975 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4976 struct tpacpi_led_classdev
, led_classdev
);
4978 rc
= led_get_status(data
->led
);
4980 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
4981 rc
= LED_OFF
; /* no error handling in led class :( */
4988 static void led_exit(void)
4992 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4993 if (tpacpi_leds
[i
].led_classdev
.name
)
4994 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5000 static int __init
tpacpi_init_led(unsigned int led
)
5004 tpacpi_leds
[led
].led
= led
;
5006 /* LEDs with no name don't get registered */
5007 if (!tpacpi_led_names
[led
])
5010 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5011 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5012 if (led_supported
== TPACPI_LED_570
)
5013 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5016 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5018 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5020 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5021 &tpacpi_leds
[led
].led_classdev
);
5023 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5028 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5029 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5030 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5031 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5033 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5034 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5035 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5036 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5037 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5038 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5039 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5040 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5042 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5043 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5044 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5045 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5046 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5048 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5049 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5050 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5051 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5053 /* (1) - may have excess leds enabled on MSB */
5055 /* Defaults (order matters, keep last, don't reorder!) */
5057 .vendor
= PCI_VENDOR_ID_LENOVO
,
5058 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5061 { /* IBM ThinkPads with no EC version string */
5062 .vendor
= PCI_VENDOR_ID_IBM
,
5063 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5066 { /* IBM ThinkPads with EC version string */
5067 .vendor
= PCI_VENDOR_ID_IBM
,
5068 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5073 #undef TPACPI_LEDQ_IBM
5074 #undef TPACPI_LEDQ_LNV
5076 static int __init
led_init(struct ibm_init_struct
*iibm
)
5080 unsigned long useful_leds
;
5082 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5084 TPACPI_ACPIHANDLE_INIT(led
);
5087 /* led not supported on R30, R31 */
5088 led_supported
= TPACPI_LED_NONE
;
5089 else if (strlencmp(led_path
, "SLED") == 0)
5091 led_supported
= TPACPI_LED_570
;
5092 else if (strlencmp(led_path
, "SYSL") == 0)
5093 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5094 led_supported
= TPACPI_LED_OLD
;
5097 led_supported
= TPACPI_LED_NEW
;
5099 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5100 str_supported(led_supported
), led_supported
);
5102 if (led_supported
== TPACPI_LED_NONE
)
5105 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5108 printk(TPACPI_ERR
"Out of memory for LED data\n");
5112 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5113 ARRAY_SIZE(led_useful_qtable
));
5115 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5116 if (!tpacpi_is_led_restricted(i
) &&
5117 test_bit(i
, &useful_leds
)) {
5118 rc
= tpacpi_init_led(i
);
5126 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5127 printk(TPACPI_NOTICE
5128 "warning: userspace override of important "
5129 "firmware LEDs is enabled\n");
5134 #define str_led_status(s) \
5135 ((s) == TPACPI_LED_OFF ? "off" : \
5136 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5138 static int led_read(char *p
)
5142 if (!led_supported
) {
5143 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5146 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
5148 if (led_supported
== TPACPI_LED_570
) {
5151 for (i
= 0; i
< 8; i
++) {
5152 status
= led_get_status(i
);
5155 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
5156 i
, str_led_status(status
));
5160 len
+= sprintf(p
+ len
, "commands:\t"
5161 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5166 static int led_write(char *buf
)
5170 enum led_status_t s
;
5175 while ((cmd
= next_cmd(&buf
))) {
5176 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5179 if (strstr(cmd
, "off")) {
5181 } else if (strstr(cmd
, "on")) {
5183 } else if (strstr(cmd
, "blink")) {
5184 s
= TPACPI_LED_BLINK
;
5189 rc
= led_set_status(led
, s
);
5197 static struct ibm_struct led_driver_data
= {
5204 /*************************************************************************
5208 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5210 #define TPACPI_BEEP_Q1 0x0001
5212 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5213 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5214 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5217 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5219 unsigned long quirks
;
5221 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5223 TPACPI_ACPIHANDLE_INIT(beep
);
5225 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5226 str_supported(beep_handle
!= NULL
));
5228 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5229 ARRAY_SIZE(beep_quirk_table
));
5231 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5233 return (beep_handle
)? 0 : 1;
5236 static int beep_read(char *p
)
5241 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5243 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
5244 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5250 static int beep_write(char *buf
)
5258 while ((cmd
= next_cmd(&buf
))) {
5259 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5260 beep_cmd
>= 0 && beep_cmd
<= 17) {
5264 if (tp_features
.beep_needs_two_args
) {
5265 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5269 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5278 static struct ibm_struct beep_driver_data
= {
5281 .write
= beep_write
,
5284 /*************************************************************************
5288 enum thermal_access_mode
{
5289 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5290 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5291 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5292 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5293 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5296 enum { /* TPACPI_THERMAL_TPEC_* */
5297 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5298 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5299 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5302 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5303 struct ibm_thermal_sensors_struct
{
5304 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5307 static enum thermal_access_mode thermal_read_mode
;
5309 /* idx is zero-based */
5310 static int thermal_get_sensor(int idx
, s32
*value
)
5316 t
= TP_EC_THERMAL_TMP0
;
5318 switch (thermal_read_mode
) {
5319 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5320 case TPACPI_THERMAL_TPEC_16
:
5321 if (idx
>= 8 && idx
<= 15) {
5322 t
= TP_EC_THERMAL_TMP8
;
5327 case TPACPI_THERMAL_TPEC_8
:
5329 if (!acpi_ec_read(t
+ idx
, &tmp
))
5331 *value
= tmp
* 1000;
5336 case TPACPI_THERMAL_ACPI_UPDT
:
5338 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5339 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5341 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5343 *value
= (t
- 2732) * 100;
5348 case TPACPI_THERMAL_ACPI_TMP07
:
5350 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5351 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5353 if (t
> 127 || t
< -127)
5354 t
= TP_EC_THERMAL_TMP_NA
;
5360 case TPACPI_THERMAL_NONE
:
5368 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5379 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5382 for (i
= 0 ; i
< n
; i
++) {
5383 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5391 /* sysfs temp##_input -------------------------------------------------- */
5393 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5394 struct device_attribute
*attr
,
5397 struct sensor_device_attribute
*sensor_attr
=
5398 to_sensor_dev_attr(attr
);
5399 int idx
= sensor_attr
->index
;
5403 res
= thermal_get_sensor(idx
, &value
);
5406 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
5409 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5412 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5413 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5414 thermal_temp_input_show, NULL, _idxB)
5416 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5417 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5418 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5419 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5420 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5421 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5422 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5423 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5424 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5425 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5426 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5427 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5428 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5429 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5430 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5431 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5432 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5435 #define THERMAL_ATTRS(X) \
5436 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5438 static struct attribute
*thermal_temp_input_attr
[] = {
5458 static const struct attribute_group thermal_temp_input16_group
= {
5459 .attrs
= thermal_temp_input_attr
5462 static const struct attribute_group thermal_temp_input8_group
= {
5463 .attrs
= &thermal_temp_input_attr
[8]
5466 #undef THERMAL_SENSOR_ATTR_TEMP
5467 #undef THERMAL_ATTRS
5469 /* --------------------------------------------------------------------- */
5471 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5478 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5480 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5482 if (thinkpad_id
.ec_model
) {
5484 * Direct EC access mode: sensors at registers
5485 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5486 * non-implemented, thermal sensors return 0x80 when
5491 for (i
= 0; i
< 8; i
++) {
5492 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5498 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5506 /* This is sheer paranoia, but we handle it anyway */
5509 "ThinkPad ACPI EC access misbehaving, "
5510 "falling back to ACPI TMPx access "
5512 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5515 "ThinkPad ACPI EC access misbehaving, "
5516 "disabling thermal sensors access\n");
5517 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5522 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5524 } else if (acpi_tmp7
) {
5525 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5526 /* 600e/x, 770e, 770x */
5527 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5529 /* Standard ACPI TMPx access, max 8 sensors */
5530 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5533 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5534 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5537 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5538 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5541 switch (thermal_read_mode
) {
5542 case TPACPI_THERMAL_TPEC_16
:
5543 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5544 &thermal_temp_input16_group
);
5548 case TPACPI_THERMAL_TPEC_8
:
5549 case TPACPI_THERMAL_ACPI_TMP07
:
5550 case TPACPI_THERMAL_ACPI_UPDT
:
5551 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5552 &thermal_temp_input8_group
);
5556 case TPACPI_THERMAL_NONE
:
5564 static void thermal_exit(void)
5566 switch (thermal_read_mode
) {
5567 case TPACPI_THERMAL_TPEC_16
:
5568 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5569 &thermal_temp_input16_group
);
5571 case TPACPI_THERMAL_TPEC_8
:
5572 case TPACPI_THERMAL_ACPI_TMP07
:
5573 case TPACPI_THERMAL_ACPI_UPDT
:
5574 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5575 &thermal_temp_input16_group
);
5577 case TPACPI_THERMAL_NONE
:
5583 static int thermal_read(char *p
)
5587 struct ibm_thermal_sensors_struct t
;
5589 n
= thermal_get_sensors(&t
);
5590 if (unlikely(n
< 0))
5593 len
+= sprintf(p
+ len
, "temperatures:\t");
5596 for (i
= 0; i
< (n
- 1); i
++)
5597 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
5598 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
5600 len
+= sprintf(p
+ len
, "not supported\n");
5605 static struct ibm_struct thermal_driver_data
= {
5607 .read
= thermal_read
,
5608 .exit
= thermal_exit
,
5611 /*************************************************************************
5615 static u8 ecdump_regs
[256];
5617 static int ecdump_read(char *p
)
5623 len
+= sprintf(p
+ len
, "EC "
5624 " +00 +01 +02 +03 +04 +05 +06 +07"
5625 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5626 for (i
= 0; i
< 256; i
+= 16) {
5627 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
5628 for (j
= 0; j
< 16; j
++) {
5629 if (!acpi_ec_read(i
+ j
, &v
))
5631 if (v
!= ecdump_regs
[i
+ j
])
5632 len
+= sprintf(p
+ len
, " *%02x", v
);
5634 len
+= sprintf(p
+ len
, " %02x", v
);
5635 ecdump_regs
[i
+ j
] = v
;
5637 len
+= sprintf(p
+ len
, "\n");
5642 /* These are way too dangerous to advertise openly... */
5644 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
5645 " (<offset> is 00-ff, <value> is 00-ff)\n");
5646 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
5647 " (<offset> is 00-ff, <value> is 0-255)\n");
5652 static int ecdump_write(char *buf
)
5657 while ((cmd
= next_cmd(&buf
))) {
5658 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5660 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5664 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5665 if (!acpi_ec_write(i
, v
))
5674 static struct ibm_struct ecdump_driver_data
= {
5676 .read
= ecdump_read
,
5677 .write
= ecdump_write
,
5678 .flags
.experimental
= 1,
5681 /*************************************************************************
5682 * Backlight/brightness subdriver
5685 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5688 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5689 * CMOS NVRAM byte 0x5E, bits 0-3.
5691 * EC HBRV (0x31) has the following layout
5692 * Bit 7: unknown function
5693 * Bit 6: unknown function
5694 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5695 * Bit 4: must be set to zero to avoid problems
5696 * Bit 3-0: backlight brightness level
5698 * brightness_get_raw returns status data in the HBRV layout
5700 * WARNING: The X61 has been verified to use HBRV for something else, so
5701 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5702 * testing on the very early *60 Lenovo models...
5706 TP_EC_BACKLIGHT
= 0x31,
5708 /* TP_EC_BACKLIGHT bitmasks */
5709 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5710 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5711 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5714 enum tpacpi_brightness_access_mode
{
5715 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5716 TPACPI_BRGHT_MODE_EC
, /* EC control */
5717 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5718 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5719 TPACPI_BRGHT_MODE_MAX
5722 static struct backlight_device
*ibm_backlight_device
;
5724 static enum tpacpi_brightness_access_mode brightness_mode
=
5725 TPACPI_BRGHT_MODE_MAX
;
5727 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5729 static struct mutex brightness_mutex
;
5731 /* NVRAM brightness access,
5732 * call with brightness_mutex held! */
5733 static unsigned int tpacpi_brightness_nvram_get(void)
5737 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5738 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5739 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5740 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5745 static void tpacpi_brightness_checkpoint_nvram(void)
5750 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5753 vdbg_printk(TPACPI_DBG_BRGHT
,
5754 "trying to checkpoint backlight level to NVRAM...\n");
5756 if (mutex_lock_killable(&brightness_mutex
) < 0)
5759 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5761 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5762 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5764 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5765 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5766 /* NVRAM needs update */
5767 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5768 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5770 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5771 dbg_printk(TPACPI_DBG_BRGHT
,
5772 "updated NVRAM backlight level to %u (0x%02x)\n",
5773 (unsigned int) lec
, (unsigned int) b_nvram
);
5775 vdbg_printk(TPACPI_DBG_BRGHT
,
5776 "NVRAM backlight level already is %u (0x%02x)\n",
5777 (unsigned int) lec
, (unsigned int) b_nvram
);
5780 mutex_unlock(&brightness_mutex
);
5784 /* call with brightness_mutex held! */
5785 static int tpacpi_brightness_get_raw(int *status
)
5789 switch (brightness_mode
) {
5790 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5791 *status
= tpacpi_brightness_nvram_get();
5793 case TPACPI_BRGHT_MODE_EC
:
5794 case TPACPI_BRGHT_MODE_ECNVRAM
:
5795 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5804 /* call with brightness_mutex held! */
5805 /* do NOT call with illegal backlight level value */
5806 static int tpacpi_brightness_set_ec(unsigned int value
)
5810 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5813 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
5814 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
5815 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
5821 /* call with brightness_mutex held! */
5822 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
5825 unsigned int current_value
, i
;
5827 current_value
= tpacpi_brightness_nvram_get();
5829 if (value
== current_value
)
5832 cmos_cmd
= (value
> current_value
) ?
5833 TP_CMOS_BRIGHTNESS_UP
:
5834 TP_CMOS_BRIGHTNESS_DOWN
;
5835 inc
= (value
> current_value
) ? 1 : -1;
5837 for (i
= current_value
; i
!= value
; i
+= inc
)
5838 if (issue_thinkpad_cmos_command(cmos_cmd
))
5844 /* May return EINTR which can always be mapped to ERESTARTSYS */
5845 static int brightness_set(unsigned int value
)
5849 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
5853 vdbg_printk(TPACPI_DBG_BRGHT
,
5854 "set backlight level to %d\n", value
);
5856 res
= mutex_lock_killable(&brightness_mutex
);
5860 switch (brightness_mode
) {
5861 case TPACPI_BRGHT_MODE_EC
:
5862 case TPACPI_BRGHT_MODE_ECNVRAM
:
5863 res
= tpacpi_brightness_set_ec(value
);
5865 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5866 res
= tpacpi_brightness_set_ucmsstep(value
);
5872 mutex_unlock(&brightness_mutex
);
5876 /* sysfs backlight class ----------------------------------------------- */
5878 static int brightness_update_status(struct backlight_device
*bd
)
5880 unsigned int level
=
5881 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
5882 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
5883 bd
->props
.brightness
: 0;
5885 dbg_printk(TPACPI_DBG_BRGHT
,
5886 "backlight: attempt to set level to %d\n",
5889 /* it is the backlight class's job (caller) to handle
5890 * EINTR and other errors properly */
5891 return brightness_set(level
);
5894 static int brightness_get(struct backlight_device
*bd
)
5898 res
= mutex_lock_killable(&brightness_mutex
);
5902 res
= tpacpi_brightness_get_raw(&status
);
5904 mutex_unlock(&brightness_mutex
);
5909 return status
& TP_EC_BACKLIGHT_LVLMSK
;
5912 static struct backlight_ops ibm_backlight_data
= {
5913 .get_brightness
= brightness_get
,
5914 .update_status
= brightness_update_status
,
5917 /* --------------------------------------------------------------------- */
5919 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
5923 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
5925 mutex_init(&brightness_mutex
);
5928 * We always attempt to detect acpi support, so as to switch
5929 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
5930 * going to publish a backlight interface
5932 b
= tpacpi_check_std_acpi_brightness_support();
5935 if (acpi_video_backlight_support()) {
5936 if (brightness_enable
> 1) {
5937 printk(TPACPI_NOTICE
5938 "Standard ACPI backlight interface "
5939 "available, not loading native one.\n");
5941 } else if (brightness_enable
== 1) {
5942 printk(TPACPI_NOTICE
5943 "Backlight control force enabled, even if standard "
5944 "ACPI backlight interface is available\n");
5947 if (brightness_enable
> 1) {
5948 printk(TPACPI_NOTICE
5949 "Standard ACPI backlight interface not "
5950 "available, thinkpad_acpi native "
5951 "brightness control enabled\n");
5956 if (!brightness_enable
) {
5957 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
5958 "brightness support disabled by "
5959 "module parameter\n");
5965 "Unsupported brightness interface, "
5966 "please contact %s\n", TPACPI_MAIL
);
5970 tp_features
.bright_16levels
= 1;
5973 * Check for module parameter bogosity, note that we
5974 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
5975 * able to detect "unspecified"
5977 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
5980 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
5981 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
5982 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
5983 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) {
5985 * IBM models that define HBRV probably have
5986 * EC-based backlight level control
5988 if (acpi_evalf(ec_handle
, NULL
, "HBRV", "qd"))
5989 /* T40-T43, R50-R52, R50e, R51e, X31-X41 */
5990 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
5992 /* all other IBM ThinkPads */
5993 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
5995 /* All Lenovo ThinkPads */
5996 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
5998 dbg_printk(TPACPI_DBG_BRGHT
,
5999 "selected brightness_mode=%d\n",
6004 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6005 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6006 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6009 if (tpacpi_brightness_get_raw(&b
) < 0)
6012 if (tp_features
.bright_16levels
)
6014 "detected a 16-level brightness capable ThinkPad\n");
6016 ibm_backlight_device
= backlight_device_register(
6017 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6018 &ibm_backlight_data
);
6019 if (IS_ERR(ibm_backlight_device
)) {
6020 printk(TPACPI_ERR
"Could not register backlight device\n");
6021 return PTR_ERR(ibm_backlight_device
);
6023 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6024 "brightness is supported\n");
6026 ibm_backlight_device
->props
.max_brightness
=
6027 (tp_features
.bright_16levels
)? 15 : 7;
6028 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6029 backlight_update_status(ibm_backlight_device
);
6034 static void brightness_suspend(pm_message_t state
)
6036 tpacpi_brightness_checkpoint_nvram();
6039 static void brightness_shutdown(void)
6041 tpacpi_brightness_checkpoint_nvram();
6044 static void brightness_exit(void)
6046 if (ibm_backlight_device
) {
6047 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6048 "calling backlight_device_unregister()\n");
6049 backlight_device_unregister(ibm_backlight_device
);
6052 tpacpi_brightness_checkpoint_nvram();
6055 static int brightness_read(char *p
)
6060 level
= brightness_get(NULL
);
6062 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
6064 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
6065 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
6066 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
6067 " (<level> is 0-%d)\n",
6068 (tp_features
.bright_16levels
) ? 15 : 7);
6074 static int brightness_write(char *buf
)
6079 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6081 level
= brightness_get(NULL
);
6085 while ((cmd
= next_cmd(&buf
))) {
6086 if (strlencmp(cmd
, "up") == 0) {
6087 if (level
< max_level
)
6089 } else if (strlencmp(cmd
, "down") == 0) {
6092 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6093 level
>= 0 && level
<= max_level
) {
6099 tpacpi_disclose_usertask("procfs brightness",
6100 "set level to %d\n", level
);
6103 * Now we know what the final level should be, so we try to set it.
6104 * Doing it this way makes the syscall restartable in case of EINTR
6106 rc
= brightness_set(level
);
6107 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
6110 static struct ibm_struct brightness_driver_data
= {
6111 .name
= "brightness",
6112 .read
= brightness_read
,
6113 .write
= brightness_write
,
6114 .exit
= brightness_exit
,
6115 .suspend
= brightness_suspend
,
6116 .shutdown
= brightness_shutdown
,
6119 /*************************************************************************
6123 static int volume_offset
= 0x30;
6125 static int volume_read(char *p
)
6130 if (!acpi_ec_read(volume_offset
, &level
)) {
6131 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
6133 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
6134 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
6135 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
6136 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
6137 " (<level> is 0-15)\n");
6143 static int volume_write(char *buf
)
6145 int cmos_cmd
, inc
, i
;
6147 int new_level
, new_mute
;
6150 while ((cmd
= next_cmd(&buf
))) {
6151 if (!acpi_ec_read(volume_offset
, &level
))
6153 new_mute
= mute
= level
& 0x40;
6154 new_level
= level
= level
& 0xf;
6156 if (strlencmp(cmd
, "up") == 0) {
6160 new_level
= level
== 15 ? 15 : level
+ 1;
6161 } else if (strlencmp(cmd
, "down") == 0) {
6165 new_level
= level
== 0 ? 0 : level
- 1;
6166 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
6167 new_level
>= 0 && new_level
<= 15) {
6169 } else if (strlencmp(cmd
, "mute") == 0) {
6174 if (new_level
!= level
) {
6175 /* mute doesn't change */
6177 cmos_cmd
= (new_level
> level
) ?
6178 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
6179 inc
= new_level
> level
? 1 : -1;
6181 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
6182 !acpi_ec_write(volume_offset
, level
)))
6185 for (i
= level
; i
!= new_level
; i
+= inc
)
6186 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
6187 !acpi_ec_write(volume_offset
, i
+ inc
))
6191 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
6192 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
6197 if (new_mute
!= mute
) {
6198 /* level doesn't change */
6200 cmos_cmd
= (new_mute
) ?
6201 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
6203 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
6204 !acpi_ec_write(volume_offset
, level
+ new_mute
))
6212 static struct ibm_struct volume_driver_data
= {
6214 .read
= volume_read
,
6215 .write
= volume_write
,
6218 /*************************************************************************
6225 * TPACPI_FAN_RD_ACPI_GFAN:
6226 * ACPI GFAN method: returns fan level
6228 * see TPACPI_FAN_WR_ACPI_SFAN
6229 * EC 0x2f (HFSP) not available if GFAN exists
6231 * TPACPI_FAN_WR_ACPI_SFAN:
6232 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
6234 * EC 0x2f (HFSP) might be available *for reading*, but do not use
6237 * TPACPI_FAN_WR_TPEC:
6238 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
6239 * Supported on almost all ThinkPads
6241 * Fan speed changes of any sort (including those caused by the
6242 * disengaged mode) are usually done slowly by the firmware as the
6243 * maximum ammount of fan duty cycle change per second seems to be
6246 * Reading is not available if GFAN exists.
6247 * Writing is not available if SFAN exists.
6250 * 7 automatic mode engaged;
6251 * (default operation mode of the ThinkPad)
6252 * fan level is ignored in this mode.
6253 * 6 full speed mode (takes precedence over bit 7);
6254 * not available on all thinkpads. May disable
6255 * the tachometer while the fan controller ramps up
6256 * the speed (which can take up to a few *minutes*).
6257 * Speeds up fan to 100% duty-cycle, which is far above
6258 * the standard RPM levels. It is not impossible that
6259 * it could cause hardware damage.
6260 * 5-3 unused in some models. Extra bits for fan level
6261 * in others, but still useless as all values above
6262 * 7 map to the same speed as level 7 in these models.
6263 * 2-0 fan level (0..7 usually)
6265 * 0x07 = max (set when temperatures critical)
6266 * Some ThinkPads may have other levels, see
6267 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
6269 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
6270 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
6271 * does so, its initial value is meaningless (0x07).
6273 * For firmware bugs, refer to:
6274 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6278 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
6279 * Main fan tachometer reading (in RPM)
6281 * This register is present on all ThinkPads with a new-style EC, and
6282 * it is known not to be present on the A21m/e, and T22, as there is
6283 * something else in offset 0x84 according to the ACPI DSDT. Other
6284 * ThinkPads from this same time period (and earlier) probably lack the
6285 * tachometer as well.
6287 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
6288 * was never fixed by IBM to report the EC firmware version string
6289 * probably support the tachometer (like the early X models), so
6290 * detecting it is quite hard. We need more data to know for sure.
6292 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
6295 * FIRMWARE BUG: may go stale while the EC is switching to full speed
6298 * For firmware bugs, refer to:
6299 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6301 * TPACPI_FAN_WR_ACPI_FANS:
6302 * ThinkPad X31, X40, X41. Not available in the X60.
6304 * FANS ACPI handle: takes three arguments: low speed, medium speed,
6305 * high speed. ACPI DSDT seems to map these three speeds to levels
6306 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
6307 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
6309 * The speeds are stored on handles
6310 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
6312 * There are three default speed sets, acessible as handles:
6313 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
6315 * ACPI DSDT switches which set is in use depending on various
6318 * TPACPI_FAN_WR_TPEC is also available and should be used to
6319 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
6320 * but the ACPI tables just mention level 7.
6323 enum { /* Fan control constants */
6324 fan_status_offset
= 0x2f, /* EC register 0x2f */
6325 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
6326 * 0x84 must be read before 0x85 */
6328 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
6329 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
6331 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
6334 enum fan_status_access_mode
{
6335 TPACPI_FAN_NONE
= 0, /* No fan status or control */
6336 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
6337 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
6340 enum fan_control_access_mode
{
6341 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
6342 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
6343 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
6344 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
6347 enum fan_control_commands
{
6348 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
6349 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
6350 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
6351 * and also watchdog cmd */
6354 static int fan_control_allowed
;
6356 static enum fan_status_access_mode fan_status_access_mode
;
6357 static enum fan_control_access_mode fan_control_access_mode
;
6358 static enum fan_control_commands fan_control_commands
;
6360 static u8 fan_control_initial_status
;
6361 static u8 fan_control_desired_level
;
6362 static u8 fan_control_resume_level
;
6363 static int fan_watchdog_maxinterval
;
6365 static struct mutex fan_mutex
;
6367 static void fan_watchdog_fire(struct work_struct
*ignored
);
6368 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
6370 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
6371 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
6372 "\\FSPD", /* 600e/x, 770e, 770x */
6374 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
6375 "JFNS", /* 770x-JL */
6379 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
6380 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
6381 * be in auto mode (0x80).
6383 * This is corrected by any write to HFSP either by the driver, or
6386 * We assume 0x07 really means auto mode while this quirk is active,
6387 * as this is far more likely than the ThinkPad being in level 7,
6388 * which is only used by the firmware during thermal emergencies.
6390 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
6391 * TP-70 (T43, R52), which are known to be buggy.
6394 static void fan_quirk1_setup(void)
6396 if (fan_control_initial_status
== 0x07) {
6397 printk(TPACPI_NOTICE
6398 "fan_init: initial fan status is unknown, "
6399 "assuming it is in auto mode\n");
6400 tp_features
.fan_ctrl_status_undef
= 1;
6404 static void fan_quirk1_handle(u8
*fan_status
)
6406 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6407 if (*fan_status
!= fan_control_initial_status
) {
6408 /* something changed the HFSP regisnter since
6409 * driver init time, so it is not undefined
6411 tp_features
.fan_ctrl_status_undef
= 0;
6413 /* Return most likely status. In fact, it
6414 * might be the only possible status */
6415 *fan_status
= TP_EC_FAN_AUTO
;
6421 * Call with fan_mutex held
6423 static void fan_update_desired_level(u8 status
)
6426 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6428 fan_control_desired_level
= 7;
6430 fan_control_desired_level
= status
;
6434 static int fan_get_status(u8
*status
)
6439 * Add TPACPI_FAN_RD_ACPI_FANS ? */
6441 switch (fan_status_access_mode
) {
6442 case TPACPI_FAN_RD_ACPI_GFAN
:
6443 /* 570, 600e/x, 770e, 770x */
6445 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
6453 case TPACPI_FAN_RD_TPEC
:
6454 /* all except 570, 600e/x, 770e, 770x */
6455 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
6458 if (likely(status
)) {
6460 fan_quirk1_handle(status
);
6472 static int fan_get_status_safe(u8
*status
)
6477 if (mutex_lock_killable(&fan_mutex
))
6478 return -ERESTARTSYS
;
6479 rc
= fan_get_status(&s
);
6481 fan_update_desired_level(s
);
6482 mutex_unlock(&fan_mutex
);
6490 static int fan_get_speed(unsigned int *speed
)
6494 switch (fan_status_access_mode
) {
6495 case TPACPI_FAN_RD_TPEC
:
6496 /* all except 570, 600e/x, 770e, 770x */
6497 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
6498 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
6502 *speed
= (hi
<< 8) | lo
;
6513 static int fan_set_level(int level
)
6515 if (!fan_control_allowed
)
6518 switch (fan_control_access_mode
) {
6519 case TPACPI_FAN_WR_ACPI_SFAN
:
6520 if (level
>= 0 && level
<= 7) {
6521 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
6527 case TPACPI_FAN_WR_ACPI_FANS
:
6528 case TPACPI_FAN_WR_TPEC
:
6529 if (!(level
& TP_EC_FAN_AUTO
) &&
6530 !(level
& TP_EC_FAN_FULLSPEED
) &&
6531 ((level
< 0) || (level
> 7)))
6534 /* safety net should the EC not support AUTO
6535 * or FULLSPEED mode bits and just ignore them */
6536 if (level
& TP_EC_FAN_FULLSPEED
)
6537 level
|= 7; /* safety min speed 7 */
6538 else if (level
& TP_EC_FAN_AUTO
)
6539 level
|= 4; /* safety min speed 4 */
6541 if (!acpi_ec_write(fan_status_offset
, level
))
6544 tp_features
.fan_ctrl_status_undef
= 0;
6551 vdbg_printk(TPACPI_DBG_FAN
,
6552 "fan control: set fan control register to 0x%02x\n", level
);
6556 static int fan_set_level_safe(int level
)
6560 if (!fan_control_allowed
)
6563 if (mutex_lock_killable(&fan_mutex
))
6564 return -ERESTARTSYS
;
6566 if (level
== TPACPI_FAN_LAST_LEVEL
)
6567 level
= fan_control_desired_level
;
6569 rc
= fan_set_level(level
);
6571 fan_update_desired_level(level
);
6573 mutex_unlock(&fan_mutex
);
6577 static int fan_set_enable(void)
6582 if (!fan_control_allowed
)
6585 if (mutex_lock_killable(&fan_mutex
))
6586 return -ERESTARTSYS
;
6588 switch (fan_control_access_mode
) {
6589 case TPACPI_FAN_WR_ACPI_FANS
:
6590 case TPACPI_FAN_WR_TPEC
:
6591 rc
= fan_get_status(&s
);
6595 /* Don't go out of emergency fan mode */
6598 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
6601 if (!acpi_ec_write(fan_status_offset
, s
))
6604 tp_features
.fan_ctrl_status_undef
= 0;
6609 case TPACPI_FAN_WR_ACPI_SFAN
:
6610 rc
= fan_get_status(&s
);
6616 /* Set fan to at least level 4 */
6619 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
6629 mutex_unlock(&fan_mutex
);
6632 vdbg_printk(TPACPI_DBG_FAN
,
6633 "fan control: set fan control register to 0x%02x\n",
6638 static int fan_set_disable(void)
6642 if (!fan_control_allowed
)
6645 if (mutex_lock_killable(&fan_mutex
))
6646 return -ERESTARTSYS
;
6649 switch (fan_control_access_mode
) {
6650 case TPACPI_FAN_WR_ACPI_FANS
:
6651 case TPACPI_FAN_WR_TPEC
:
6652 if (!acpi_ec_write(fan_status_offset
, 0x00))
6655 fan_control_desired_level
= 0;
6656 tp_features
.fan_ctrl_status_undef
= 0;
6660 case TPACPI_FAN_WR_ACPI_SFAN
:
6661 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
6664 fan_control_desired_level
= 0;
6672 vdbg_printk(TPACPI_DBG_FAN
,
6673 "fan control: set fan control register to 0\n");
6675 mutex_unlock(&fan_mutex
);
6679 static int fan_set_speed(int speed
)
6683 if (!fan_control_allowed
)
6686 if (mutex_lock_killable(&fan_mutex
))
6687 return -ERESTARTSYS
;
6690 switch (fan_control_access_mode
) {
6691 case TPACPI_FAN_WR_ACPI_FANS
:
6692 if (speed
>= 0 && speed
<= 65535) {
6693 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
6694 speed
, speed
, speed
))
6704 mutex_unlock(&fan_mutex
);
6708 static void fan_watchdog_reset(void)
6710 static int fan_watchdog_active
;
6712 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
6715 if (fan_watchdog_active
)
6716 cancel_delayed_work(&fan_watchdog_task
);
6718 if (fan_watchdog_maxinterval
> 0 &&
6719 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
6720 fan_watchdog_active
= 1;
6721 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
6722 msecs_to_jiffies(fan_watchdog_maxinterval
6725 "failed to queue the fan watchdog, "
6726 "watchdog will not trigger\n");
6729 fan_watchdog_active
= 0;
6732 static void fan_watchdog_fire(struct work_struct
*ignored
)
6736 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
6739 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
6740 rc
= fan_set_enable();
6742 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
6743 "will try again later...\n", -rc
);
6744 /* reschedule for later */
6745 fan_watchdog_reset();
6750 * SYSFS fan layout: hwmon compatible (device)
6753 * 0: "disengaged" mode
6755 * 2: native EC "auto" mode (recommended, hardware default)
6757 * pwm*: set speed in manual mode, ignored otherwise.
6758 * 0 is level 0; 255 is level 7. Intermediate points done with linear
6761 * fan*_input: tachometer reading, RPM
6764 * SYSFS fan layout: extensions
6766 * fan_watchdog (driver):
6767 * fan watchdog interval in seconds, 0 disables (default), max 120
6770 /* sysfs fan pwm1_enable ----------------------------------------------- */
6771 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
6772 struct device_attribute
*attr
,
6778 res
= fan_get_status_safe(&status
);
6782 if (status
& TP_EC_FAN_FULLSPEED
) {
6784 } else if (status
& TP_EC_FAN_AUTO
) {
6789 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
6792 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
6793 struct device_attribute
*attr
,
6794 const char *buf
, size_t count
)
6799 if (parse_strtoul(buf
, 2, &t
))
6802 tpacpi_disclose_usertask("hwmon pwm1_enable",
6803 "set fan mode to %lu\n", t
);
6807 level
= TP_EC_FAN_FULLSPEED
;
6810 level
= TPACPI_FAN_LAST_LEVEL
;
6813 level
= TP_EC_FAN_AUTO
;
6816 /* reserved for software-controlled auto mode */
6822 res
= fan_set_level_safe(level
);
6828 fan_watchdog_reset();
6833 static struct device_attribute dev_attr_fan_pwm1_enable
=
6834 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
6835 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
6837 /* sysfs fan pwm1 ------------------------------------------------------ */
6838 static ssize_t
fan_pwm1_show(struct device
*dev
,
6839 struct device_attribute
*attr
,
6845 res
= fan_get_status_safe(&status
);
6850 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
6851 status
= fan_control_desired_level
;
6856 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
6859 static ssize_t
fan_pwm1_store(struct device
*dev
,
6860 struct device_attribute
*attr
,
6861 const char *buf
, size_t count
)
6865 u8 status
, newlevel
;
6867 if (parse_strtoul(buf
, 255, &s
))
6870 tpacpi_disclose_usertask("hwmon pwm1",
6871 "set fan speed to %lu\n", s
);
6873 /* scale down from 0-255 to 0-7 */
6874 newlevel
= (s
>> 5) & 0x07;
6876 if (mutex_lock_killable(&fan_mutex
))
6877 return -ERESTARTSYS
;
6879 rc
= fan_get_status(&status
);
6880 if (!rc
&& (status
&
6881 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6882 rc
= fan_set_level(newlevel
);
6886 fan_update_desired_level(newlevel
);
6887 fan_watchdog_reset();
6891 mutex_unlock(&fan_mutex
);
6892 return (rc
)? rc
: count
;
6895 static struct device_attribute dev_attr_fan_pwm1
=
6896 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
6897 fan_pwm1_show
, fan_pwm1_store
);
6899 /* sysfs fan fan1_input ------------------------------------------------ */
6900 static ssize_t
fan_fan1_input_show(struct device
*dev
,
6901 struct device_attribute
*attr
,
6907 res
= fan_get_speed(&speed
);
6911 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
6914 static struct device_attribute dev_attr_fan_fan1_input
=
6915 __ATTR(fan1_input
, S_IRUGO
,
6916 fan_fan1_input_show
, NULL
);
6918 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
6919 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
6922 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
6925 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
6926 const char *buf
, size_t count
)
6930 if (parse_strtoul(buf
, 120, &t
))
6933 if (!fan_control_allowed
)
6936 fan_watchdog_maxinterval
= t
;
6937 fan_watchdog_reset();
6939 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
6944 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
6945 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
6947 /* --------------------------------------------------------------------- */
6948 static struct attribute
*fan_attributes
[] = {
6949 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
6950 &dev_attr_fan_fan1_input
.attr
,
6954 static const struct attribute_group fan_attr_group
= {
6955 .attrs
= fan_attributes
,
6958 #define TPACPI_FAN_Q1 0x0001
6960 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
6961 { .vendor = PCI_VENDOR_ID_IBM, \
6962 .bios = TPACPI_MATCH_ANY, \
6963 .ec = TPID(__id1, __id2), \
6964 .quirks = __quirks }
6966 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
6967 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
6968 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
6969 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
6970 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
6973 #undef TPACPI_FAN_QI
6975 static int __init
fan_init(struct ibm_init_struct
*iibm
)
6978 unsigned long quirks
;
6980 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
6981 "initializing fan subdriver\n");
6983 mutex_init(&fan_mutex
);
6984 fan_status_access_mode
= TPACPI_FAN_NONE
;
6985 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6986 fan_control_commands
= 0;
6987 fan_watchdog_maxinterval
= 0;
6988 tp_features
.fan_ctrl_status_undef
= 0;
6989 fan_control_desired_level
= 7;
6991 TPACPI_ACPIHANDLE_INIT(fans
);
6992 TPACPI_ACPIHANDLE_INIT(gfan
);
6993 TPACPI_ACPIHANDLE_INIT(sfan
);
6995 quirks
= tpacpi_check_quirks(fan_quirk_table
,
6996 ARRAY_SIZE(fan_quirk_table
));
6999 /* 570, 600e/x, 770e, 770x */
7000 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7002 /* all other ThinkPads: note that even old-style
7003 * ThinkPad ECs supports the fan control register */
7004 if (likely(acpi_ec_read(fan_status_offset
,
7005 &fan_control_initial_status
))) {
7006 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7007 if (quirks
& TPACPI_FAN_Q1
)
7011 "ThinkPad ACPI EC access misbehaving, "
7012 "fan status and control unavailable\n");
7019 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
7020 fan_control_commands
|=
7021 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
7024 /* gfan without sfan means no fan control */
7025 /* all other models implement TP EC 0x2f control */
7029 fan_control_access_mode
=
7030 TPACPI_FAN_WR_ACPI_FANS
;
7031 fan_control_commands
|=
7032 TPACPI_FAN_CMD_SPEED
|
7033 TPACPI_FAN_CMD_LEVEL
|
7034 TPACPI_FAN_CMD_ENABLE
;
7036 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
7037 fan_control_commands
|=
7038 TPACPI_FAN_CMD_LEVEL
|
7039 TPACPI_FAN_CMD_ENABLE
;
7044 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7045 "fan is %s, modes %d, %d\n",
7046 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
7047 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
7048 fan_status_access_mode
, fan_control_access_mode
);
7050 /* fan control master switch */
7051 if (!fan_control_allowed
) {
7052 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7053 fan_control_commands
= 0;
7054 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7055 "fan control features disabled by parameter\n");
7058 /* update fan_control_desired_level */
7059 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
7060 fan_get_status_safe(NULL
);
7062 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
7063 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
7064 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7069 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
7070 &driver_attr_fan_watchdog
);
7072 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7081 static void fan_exit(void)
7083 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
7084 "cancelling any pending fan watchdog tasks\n");
7086 /* FIXME: can we really do this unconditionally? */
7087 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
7088 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
7089 &driver_attr_fan_watchdog
);
7091 cancel_delayed_work(&fan_watchdog_task
);
7092 flush_workqueue(tpacpi_wq
);
7095 static void fan_suspend(pm_message_t state
)
7099 if (!fan_control_allowed
)
7102 /* Store fan status in cache */
7103 fan_control_resume_level
= 0;
7104 rc
= fan_get_status_safe(&fan_control_resume_level
);
7106 printk(TPACPI_NOTICE
7107 "failed to read fan level for later "
7108 "restore during resume: %d\n", rc
);
7110 /* if it is undefined, don't attempt to restore it.
7112 if (tp_features
.fan_ctrl_status_undef
)
7113 fan_control_resume_level
= 0;
7116 static void fan_resume(void)
7118 u8 current_level
= 7;
7119 bool do_set
= false;
7122 /* DSDT *always* updates status on resume */
7123 tp_features
.fan_ctrl_status_undef
= 0;
7125 if (!fan_control_allowed
||
7126 !fan_control_resume_level
||
7127 (fan_get_status_safe(¤t_level
) < 0))
7130 switch (fan_control_access_mode
) {
7131 case TPACPI_FAN_WR_ACPI_SFAN
:
7132 /* never decrease fan level */
7133 do_set
= (fan_control_resume_level
> current_level
);
7135 case TPACPI_FAN_WR_ACPI_FANS
:
7136 case TPACPI_FAN_WR_TPEC
:
7137 /* never decrease fan level, scale is:
7138 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
7140 * We expect the firmware to set either 7 or AUTO, but we
7141 * handle FULLSPEED out of paranoia.
7143 * So, we can safely only restore FULLSPEED or 7, anything
7144 * else could slow the fan. Restoring AUTO is useless, at
7145 * best that's exactly what the DSDT already set (it is the
7148 * Always keep in mind that the DSDT *will* have set the
7149 * fans to what the vendor supposes is the best level. We
7150 * muck with it only to speed the fan up.
7152 if (fan_control_resume_level
!= 7 &&
7153 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
7156 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
7157 (current_level
!= fan_control_resume_level
);
7163 printk(TPACPI_NOTICE
7164 "restoring fan level to 0x%02x\n",
7165 fan_control_resume_level
);
7166 rc
= fan_set_level_safe(fan_control_resume_level
);
7168 printk(TPACPI_NOTICE
7169 "failed to restore fan level: %d\n", rc
);
7173 static int fan_read(char *p
)
7178 unsigned int speed
= 0;
7180 switch (fan_status_access_mode
) {
7181 case TPACPI_FAN_RD_ACPI_GFAN
:
7182 /* 570, 600e/x, 770e, 770x */
7183 rc
= fan_get_status_safe(&status
);
7187 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
7189 (status
!= 0) ? "enabled" : "disabled", status
);
7192 case TPACPI_FAN_RD_TPEC
:
7193 /* all except 570, 600e/x, 770e, 770x */
7194 rc
= fan_get_status_safe(&status
);
7198 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
7199 (status
!= 0) ? "enabled" : "disabled");
7201 rc
= fan_get_speed(&speed
);
7205 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
7207 if (status
& TP_EC_FAN_FULLSPEED
)
7208 /* Disengaged mode takes precedence */
7209 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
7210 else if (status
& TP_EC_FAN_AUTO
)
7211 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
7213 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
7216 case TPACPI_FAN_NONE
:
7218 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
7221 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
7222 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
7224 switch (fan_control_access_mode
) {
7225 case TPACPI_FAN_WR_ACPI_SFAN
:
7226 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
7230 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
7231 "auto, disengaged, full-speed)\n");
7236 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
7237 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
7238 "commands:\twatchdog <timeout> (<timeout> "
7239 "is 0 (off), 1-120 (seconds))\n");
7241 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
7242 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
7243 " (<speed> is 0-65535)\n");
7248 static int fan_write_cmd_level(const char *cmd
, int *rc
)
7252 if (strlencmp(cmd
, "level auto") == 0)
7253 level
= TP_EC_FAN_AUTO
;
7254 else if ((strlencmp(cmd
, "level disengaged") == 0) |
7255 (strlencmp(cmd
, "level full-speed") == 0))
7256 level
= TP_EC_FAN_FULLSPEED
;
7257 else if (sscanf(cmd
, "level %d", &level
) != 1)
7260 *rc
= fan_set_level_safe(level
);
7262 printk(TPACPI_ERR
"level command accepted for unsupported "
7263 "access mode %d", fan_control_access_mode
);
7265 tpacpi_disclose_usertask("procfs fan",
7266 "set level to %d\n", level
);
7271 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
7273 if (strlencmp(cmd
, "enable") != 0)
7276 *rc
= fan_set_enable();
7278 printk(TPACPI_ERR
"enable command accepted for unsupported "
7279 "access mode %d", fan_control_access_mode
);
7281 tpacpi_disclose_usertask("procfs fan", "enable\n");
7286 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
7288 if (strlencmp(cmd
, "disable") != 0)
7291 *rc
= fan_set_disable();
7293 printk(TPACPI_ERR
"disable command accepted for unsupported "
7294 "access mode %d", fan_control_access_mode
);
7296 tpacpi_disclose_usertask("procfs fan", "disable\n");
7301 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
7306 * Support speed <low> <medium> <high> ? */
7308 if (sscanf(cmd
, "speed %d", &speed
) != 1)
7311 *rc
= fan_set_speed(speed
);
7313 printk(TPACPI_ERR
"speed command accepted for unsupported "
7314 "access mode %d", fan_control_access_mode
);
7316 tpacpi_disclose_usertask("procfs fan",
7317 "set speed to %d\n", speed
);
7322 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
7326 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
7329 if (interval
< 0 || interval
> 120)
7332 fan_watchdog_maxinterval
= interval
;
7333 tpacpi_disclose_usertask("procfs fan",
7334 "set watchdog timer to %d\n",
7341 static int fan_write(char *buf
)
7346 while (!rc
&& (cmd
= next_cmd(&buf
))) {
7347 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
7348 fan_write_cmd_level(cmd
, &rc
)) &&
7349 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
7350 (fan_write_cmd_enable(cmd
, &rc
) ||
7351 fan_write_cmd_disable(cmd
, &rc
) ||
7352 fan_write_cmd_watchdog(cmd
, &rc
))) &&
7353 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
7354 fan_write_cmd_speed(cmd
, &rc
))
7358 fan_watchdog_reset();
7364 static struct ibm_struct fan_driver_data
= {
7369 .suspend
= fan_suspend
,
7370 .resume
= fan_resume
,
7373 /****************************************************************************
7374 ****************************************************************************
7378 ****************************************************************************
7379 ****************************************************************************/
7381 /* sysfs name ---------------------------------------------------------- */
7382 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
7383 struct device_attribute
*attr
,
7386 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
7389 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
7390 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
7392 /* --------------------------------------------------------------------- */
7395 static struct proc_dir_entry
*proc_dir
;
7398 * Module and infrastructure proble, init and exit handling
7401 static int force_load
;
7403 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
7404 static const char * __init
str_supported(int is_supported
)
7406 static char text_unsupported
[] __initdata
= "not supported";
7408 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
7410 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
7412 static void ibm_exit(struct ibm_struct
*ibm
)
7414 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
7416 list_del_init(&ibm
->all_drivers
);
7418 if (ibm
->flags
.acpi_notify_installed
) {
7419 dbg_printk(TPACPI_DBG_EXIT
,
7420 "%s: acpi_remove_notify_handler\n", ibm
->name
);
7422 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
7424 dispatch_acpi_notify
);
7425 ibm
->flags
.acpi_notify_installed
= 0;
7426 ibm
->flags
.acpi_notify_installed
= 0;
7429 if (ibm
->flags
.proc_created
) {
7430 dbg_printk(TPACPI_DBG_EXIT
,
7431 "%s: remove_proc_entry\n", ibm
->name
);
7432 remove_proc_entry(ibm
->name
, proc_dir
);
7433 ibm
->flags
.proc_created
= 0;
7436 if (ibm
->flags
.acpi_driver_registered
) {
7437 dbg_printk(TPACPI_DBG_EXIT
,
7438 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
7440 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
7441 kfree(ibm
->acpi
->driver
);
7442 ibm
->acpi
->driver
= NULL
;
7443 ibm
->flags
.acpi_driver_registered
= 0;
7446 if (ibm
->flags
.init_called
&& ibm
->exit
) {
7448 ibm
->flags
.init_called
= 0;
7451 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
7454 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
7457 struct ibm_struct
*ibm
= iibm
->data
;
7458 struct proc_dir_entry
*entry
;
7460 BUG_ON(ibm
== NULL
);
7462 INIT_LIST_HEAD(&ibm
->all_drivers
);
7464 if (ibm
->flags
.experimental
&& !experimental
)
7467 dbg_printk(TPACPI_DBG_INIT
,
7468 "probing for %s\n", ibm
->name
);
7471 ret
= iibm
->init(iibm
);
7473 return 0; /* probe failed */
7477 ibm
->flags
.init_called
= 1;
7481 if (ibm
->acpi
->hid
) {
7482 ret
= register_tpacpi_subdriver(ibm
);
7487 if (ibm
->acpi
->notify
) {
7488 ret
= setup_acpi_notify(ibm
);
7489 if (ret
== -ENODEV
) {
7490 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
7500 dbg_printk(TPACPI_DBG_INIT
,
7501 "%s installed\n", ibm
->name
);
7504 entry
= create_proc_entry(ibm
->name
,
7505 S_IFREG
| S_IRUGO
| S_IWUSR
,
7508 printk(TPACPI_ERR
"unable to create proc entry %s\n",
7513 entry
->owner
= THIS_MODULE
;
7515 entry
->read_proc
= &dispatch_procfs_read
;
7517 entry
->write_proc
= &dispatch_procfs_write
;
7518 ibm
->flags
.proc_created
= 1;
7521 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
7526 dbg_printk(TPACPI_DBG_INIT
,
7527 "%s: at error exit path with result %d\n",
7531 return (ret
< 0)? ret
: 0;
7536 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
7538 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
7541 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
7542 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
7545 return s
&& strlen(s
) >= 8 &&
7546 tpacpi_is_fw_digit(s
[0]) &&
7547 tpacpi_is_fw_digit(s
[1]) &&
7548 s
[2] == t
&& s
[3] == 'T' &&
7549 tpacpi_is_fw_digit(s
[4]) &&
7550 tpacpi_is_fw_digit(s
[5]) &&
7551 s
[6] == 'W' && s
[7] == 'W';
7554 /* returns 0 - probe ok, or < 0 - probe error.
7555 * Probe ok doesn't mean thinkpad found.
7556 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
7557 static int __must_check __init
get_thinkpad_model_data(
7558 struct thinkpad_id_data
*tp
)
7560 const struct dmi_device
*dev
= NULL
;
7561 char ec_fw_string
[18];
7567 memset(tp
, 0, sizeof(*tp
));
7569 if (dmi_name_in_vendors("IBM"))
7570 tp
->vendor
= PCI_VENDOR_ID_IBM
;
7571 else if (dmi_name_in_vendors("LENOVO"))
7572 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
7576 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
7577 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
7578 if (s
&& !tp
->bios_version_str
)
7581 /* Really ancient ThinkPad 240X will fail this, which is fine */
7582 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
7585 tp
->bios_model
= tp
->bios_version_str
[0]
7586 | (tp
->bios_version_str
[1] << 8);
7587 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
7588 | tp
->bios_version_str
[5];
7591 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
7592 * X32 or newer, all Z series; Some models must have an
7593 * up-to-date BIOS or they will not be detected.
7595 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7597 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
7598 if (sscanf(dev
->name
,
7599 "IBM ThinkPad Embedded Controller -[%17c",
7600 ec_fw_string
) == 1) {
7601 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
7602 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
7604 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
7605 if (!tp
->ec_version_str
)
7608 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
7609 tp
->ec_model
= ec_fw_string
[0]
7610 | (ec_fw_string
[1] << 8);
7611 tp
->ec_release
= (ec_fw_string
[4] << 8)
7614 printk(TPACPI_NOTICE
7615 "ThinkPad firmware release %s "
7616 "doesn't match the known patterns\n",
7618 printk(TPACPI_NOTICE
7619 "please report this to %s\n",
7626 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
7627 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
7628 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
7633 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
7634 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
7635 if (s
&& !tp
->nummodel_str
)
7641 static int __init
probe_for_thinkpad(void)
7649 * Non-ancient models have better DMI tagging, but very old models
7652 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
7654 /* ec is required because many other handles are relative to it */
7655 TPACPI_ACPIHANDLE_INIT(ec
);
7659 "Not yet supported ThinkPad detected!\n");
7664 * Risks a regression on very old machines, but reduces potential
7665 * false positives a damn great deal
7668 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
7670 if (!is_thinkpad
&& !force_load
)
7677 /* Module init, exit, parameters */
7679 static struct ibm_init_struct ibms_init
[] __initdata
= {
7681 .init
= thinkpad_acpi_driver_init
,
7682 .data
= &thinkpad_acpi_driver_data
,
7685 .init
= hotkey_init
,
7686 .data
= &hotkey_driver_data
,
7689 .init
= bluetooth_init
,
7690 .data
= &bluetooth_driver_data
,
7694 .data
= &wan_driver_data
,
7698 .data
= &uwb_driver_data
,
7700 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
7703 .data
= &video_driver_data
,
7708 .data
= &light_driver_data
,
7710 #ifdef CONFIG_THINKPAD_ACPI_DOCK
7713 .data
= &dock_driver_data
[0],
7717 .data
= &dock_driver_data
[1],
7720 #ifdef CONFIG_THINKPAD_ACPI_BAY
7723 .data
= &bay_driver_data
,
7728 .data
= &cmos_driver_data
,
7732 .data
= &led_driver_data
,
7736 .data
= &beep_driver_data
,
7739 .init
= thermal_init
,
7740 .data
= &thermal_driver_data
,
7743 .data
= &ecdump_driver_data
,
7746 .init
= brightness_init
,
7747 .data
= &brightness_driver_data
,
7750 .data
= &volume_driver_data
,
7754 .data
= &fan_driver_data
,
7758 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
7761 struct ibm_struct
*ibm
;
7763 if (!kp
|| !kp
->name
|| !val
)
7766 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7767 ibm
= ibms_init
[i
].data
;
7768 WARN_ON(ibm
== NULL
);
7770 if (!ibm
|| !ibm
->name
)
7773 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
7774 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
7776 strcpy(ibms_init
[i
].param
, val
);
7777 strcat(ibms_init
[i
].param
, ",");
7785 module_param(experimental
, int, 0);
7786 MODULE_PARM_DESC(experimental
,
7787 "Enables experimental features when non-zero");
7789 module_param_named(debug
, dbg_level
, uint
, 0);
7790 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
7792 module_param(force_load
, bool, 0);
7793 MODULE_PARM_DESC(force_load
,
7794 "Attempts to load the driver even on a "
7795 "mis-identified ThinkPad when true");
7797 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
7798 MODULE_PARM_DESC(fan_control
,
7799 "Enables setting fan parameters features when true");
7801 module_param_named(brightness_mode
, brightness_mode
, uint
, 0);
7802 MODULE_PARM_DESC(brightness_mode
,
7803 "Selects brightness control strategy: "
7804 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
7806 module_param(brightness_enable
, uint
, 0);
7807 MODULE_PARM_DESC(brightness_enable
,
7808 "Enables backlight control when 1, disables when 0");
7810 module_param(hotkey_report_mode
, uint
, 0);
7811 MODULE_PARM_DESC(hotkey_report_mode
,
7812 "used for backwards compatibility with userspace, "
7813 "see documentation");
7815 #define TPACPI_PARAM(feature) \
7816 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
7817 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
7818 "at module load, see documentation")
7820 TPACPI_PARAM(hotkey
);
7821 TPACPI_PARAM(bluetooth
);
7822 TPACPI_PARAM(video
);
7823 TPACPI_PARAM(light
);
7824 #ifdef CONFIG_THINKPAD_ACPI_DOCK
7827 #ifdef CONFIG_THINKPAD_ACPI_BAY
7829 #endif /* CONFIG_THINKPAD_ACPI_BAY */
7833 TPACPI_PARAM(ecdump
);
7834 TPACPI_PARAM(brightness
);
7835 TPACPI_PARAM(volume
);
7838 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
7839 module_param(dbg_wlswemul
, uint
, 0);
7840 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
7841 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
7842 MODULE_PARM_DESC(wlsw_state
,
7843 "Initial state of the emulated WLSW switch");
7845 module_param(dbg_bluetoothemul
, uint
, 0);
7846 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
7847 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
7848 MODULE_PARM_DESC(bluetooth_state
,
7849 "Initial state of the emulated bluetooth switch");
7851 module_param(dbg_wwanemul
, uint
, 0);
7852 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
7853 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
7854 MODULE_PARM_DESC(wwan_state
,
7855 "Initial state of the emulated WWAN switch");
7857 module_param(dbg_uwbemul
, uint
, 0);
7858 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
7859 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
7860 MODULE_PARM_DESC(uwb_state
,
7861 "Initial state of the emulated UWB switch");
7864 static void thinkpad_acpi_module_exit(void)
7866 struct ibm_struct
*ibm
, *itmp
;
7868 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
7870 list_for_each_entry_safe_reverse(ibm
, itmp
,
7871 &tpacpi_all_drivers
,
7876 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
7878 if (tpacpi_inputdev
) {
7879 if (tp_features
.input_device_registered
)
7880 input_unregister_device(tpacpi_inputdev
);
7882 input_free_device(tpacpi_inputdev
);
7886 hwmon_device_unregister(tpacpi_hwmon
);
7888 if (tp_features
.sensors_pdev_attrs_registered
)
7889 device_remove_file(&tpacpi_sensors_pdev
->dev
,
7890 &dev_attr_thinkpad_acpi_pdev_name
);
7891 if (tpacpi_sensors_pdev
)
7892 platform_device_unregister(tpacpi_sensors_pdev
);
7894 platform_device_unregister(tpacpi_pdev
);
7896 if (tp_features
.sensors_pdrv_attrs_registered
)
7897 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
7898 if (tp_features
.platform_drv_attrs_registered
)
7899 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
7901 if (tp_features
.sensors_pdrv_registered
)
7902 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
7904 if (tp_features
.platform_drv_registered
)
7905 platform_driver_unregister(&tpacpi_pdriver
);
7908 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
7911 destroy_workqueue(tpacpi_wq
);
7913 kfree(thinkpad_id
.bios_version_str
);
7914 kfree(thinkpad_id
.ec_version_str
);
7915 kfree(thinkpad_id
.model_str
);
7919 static int __init
thinkpad_acpi_module_init(void)
7923 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
7925 /* Parameter checking */
7926 if (hotkey_report_mode
> 2)
7929 /* Driver-level probe */
7931 ret
= get_thinkpad_model_data(&thinkpad_id
);
7934 "unable to get DMI data: %d\n", ret
);
7935 thinkpad_acpi_module_exit();
7938 ret
= probe_for_thinkpad();
7940 thinkpad_acpi_module_exit();
7944 /* Driver initialization */
7946 TPACPI_ACPIHANDLE_INIT(ecrd
);
7947 TPACPI_ACPIHANDLE_INIT(ecwr
);
7949 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
7951 thinkpad_acpi_module_exit();
7955 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
7958 "unable to create proc dir " TPACPI_PROC_DIR
);
7959 thinkpad_acpi_module_exit();
7962 proc_dir
->owner
= THIS_MODULE
;
7964 ret
= platform_driver_register(&tpacpi_pdriver
);
7967 "unable to register main platform driver\n");
7968 thinkpad_acpi_module_exit();
7971 tp_features
.platform_drv_registered
= 1;
7973 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
7976 "unable to register hwmon platform driver\n");
7977 thinkpad_acpi_module_exit();
7980 tp_features
.sensors_pdrv_registered
= 1;
7982 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
7984 tp_features
.platform_drv_attrs_registered
= 1;
7985 ret
= tpacpi_create_driver_attributes(
7986 &tpacpi_hwmon_pdriver
.driver
);
7990 "unable to create sysfs driver attributes\n");
7991 thinkpad_acpi_module_exit();
7994 tp_features
.sensors_pdrv_attrs_registered
= 1;
7997 /* Device initialization */
7998 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
8000 if (IS_ERR(tpacpi_pdev
)) {
8001 ret
= PTR_ERR(tpacpi_pdev
);
8003 printk(TPACPI_ERR
"unable to register platform device\n");
8004 thinkpad_acpi_module_exit();
8007 tpacpi_sensors_pdev
= platform_device_register_simple(
8008 TPACPI_HWMON_DRVR_NAME
,
8010 if (IS_ERR(tpacpi_sensors_pdev
)) {
8011 ret
= PTR_ERR(tpacpi_sensors_pdev
);
8012 tpacpi_sensors_pdev
= NULL
;
8014 "unable to register hwmon platform device\n");
8015 thinkpad_acpi_module_exit();
8018 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
8019 &dev_attr_thinkpad_acpi_pdev_name
);
8022 "unable to create sysfs hwmon device attributes\n");
8023 thinkpad_acpi_module_exit();
8026 tp_features
.sensors_pdev_attrs_registered
= 1;
8027 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
8028 if (IS_ERR(tpacpi_hwmon
)) {
8029 ret
= PTR_ERR(tpacpi_hwmon
);
8030 tpacpi_hwmon
= NULL
;
8031 printk(TPACPI_ERR
"unable to register hwmon device\n");
8032 thinkpad_acpi_module_exit();
8035 mutex_init(&tpacpi_inputdev_send_mutex
);
8036 tpacpi_inputdev
= input_allocate_device();
8037 if (!tpacpi_inputdev
) {
8038 printk(TPACPI_ERR
"unable to allocate input device\n");
8039 thinkpad_acpi_module_exit();
8042 /* Prepare input device, but don't register */
8043 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
8044 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
8045 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
8046 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
8047 thinkpad_id
.vendor
:
8049 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
8050 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
8052 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8053 ret
= ibm_init(&ibms_init
[i
]);
8054 if (ret
>= 0 && *ibms_init
[i
].param
)
8055 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
8057 thinkpad_acpi_module_exit();
8061 ret
= input_register_device(tpacpi_inputdev
);
8063 printk(TPACPI_ERR
"unable to register input device\n");
8064 thinkpad_acpi_module_exit();
8067 tp_features
.input_device_registered
= 1;
8070 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
8074 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
8077 * This will autoload the driver in almost every ThinkPad
8078 * in widespread use.
8080 * Only _VERY_ old models, like the 240, 240x and 570 lack
8081 * the HKEY event interface.
8083 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
8086 * DMI matching for module autoloading
8088 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8089 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
8091 * Only models listed in thinkwiki will be supported, so add yours
8092 * if it is not there yet.
8094 #define IBM_BIOS_MODULE_ALIAS(__type) \
8095 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
8097 /* Ancient thinkpad BIOSes have to be identified by
8098 * BIOS type or model number, and there are far less
8099 * BIOS types than model numbers... */
8100 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
8102 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
8103 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
8104 MODULE_DESCRIPTION(TPACPI_DESC
);
8105 MODULE_VERSION(TPACPI_VERSION
);
8106 MODULE_LICENSE("GPL");
8108 module_init(thinkpad_acpi_module_init
);
8109 module_exit(thinkpad_acpi_module_exit
);