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
170 #define TPACPI_LOG TPACPI_FILE ": "
171 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
172 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
173 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
174 #define TPACPI_ERR KERN_ERR TPACPI_LOG
175 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
176 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
177 #define TPACPI_INFO KERN_INFO TPACPI_LOG
178 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
180 /* Debugging printk groups */
181 #define TPACPI_DBG_ALL 0xffff
182 #define TPACPI_DBG_DISCLOSETASK 0x8000
183 #define TPACPI_DBG_INIT 0x0001
184 #define TPACPI_DBG_EXIT 0x0002
185 #define TPACPI_DBG_RFKILL 0x0004
186 #define TPACPI_DBG_HKEY 0x0008
187 #define TPACPI_DBG_FAN 0x0010
188 #define TPACPI_DBG_BRGHT 0x0020
190 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
191 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
192 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
195 /****************************************************************************
196 * Driver-wide structs and misc. variables
201 struct tp_acpi_drv_struct
{
202 const struct acpi_device_id
*hid
;
203 struct acpi_driver
*driver
;
205 void (*notify
) (struct ibm_struct
*, u32
);
208 struct acpi_device
*device
;
214 int (*read
) (char *);
215 int (*write
) (char *);
217 void (*resume
) (void);
218 void (*suspend
) (pm_message_t state
);
219 void (*shutdown
) (void);
221 struct list_head all_drivers
;
223 struct tp_acpi_drv_struct
*acpi
;
226 u8 acpi_driver_registered
:1;
227 u8 acpi_notify_installed
:1;
234 struct ibm_init_struct
{
237 int (*init
) (struct ibm_init_struct
*);
238 struct ibm_struct
*data
;
249 u32 bright_16levels
:1;
250 u32 bright_acpimode
:1;
253 u32 fan_ctrl_status_undef
:1;
255 u32 beep_needs_two_args
:1;
256 u32 input_device_registered
:1;
257 u32 platform_drv_registered
:1;
258 u32 platform_drv_attrs_registered
:1;
259 u32 sensors_pdrv_registered
:1;
260 u32 sensors_pdrv_attrs_registered
:1;
261 u32 sensors_pdev_attrs_registered
:1;
262 u32 hotkey_poll_active
:1;
266 u16 hotkey_mask_ff
:1;
269 struct thinkpad_id_data
{
270 unsigned int vendor
; /* ThinkPad vendor:
271 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
273 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
274 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
276 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
278 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
281 char *model_str
; /* ThinkPad T43 */
282 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
284 static struct thinkpad_id_data thinkpad_id
;
287 TPACPI_LIFE_INIT
= 0,
292 static int experimental
;
293 static u32 dbg_level
;
295 static struct workqueue_struct
*tpacpi_wq
;
303 /* Special LED class that can defer work */
304 struct tpacpi_led_classdev
{
305 struct led_classdev led_classdev
;
306 struct work_struct work
;
307 enum led_status_t new_state
;
311 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
312 static int dbg_wlswemul
;
313 static int tpacpi_wlsw_emulstate
;
314 static int dbg_bluetoothemul
;
315 static int tpacpi_bluetooth_emulstate
;
316 static int dbg_wwanemul
;
317 static int tpacpi_wwan_emulstate
;
318 static int dbg_uwbemul
;
319 static int tpacpi_uwb_emulstate
;
323 /*************************************************************************
327 #define dbg_printk(a_dbg_level, format, arg...) \
328 do { if (dbg_level & (a_dbg_level)) \
329 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
332 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
333 #define vdbg_printk dbg_printk
334 static const char *str_supported(int is_supported
);
336 #define vdbg_printk(a_dbg_level, format, arg...) \
340 static void tpacpi_log_usertask(const char * const what
)
342 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
343 what
, task_tgid_vnr(current
));
346 #define tpacpi_disclose_usertask(what, format, arg...) \
349 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
350 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
351 printk(TPACPI_DEBUG "%s: PID %d: " format, \
352 what, task_tgid_vnr(current), ## arg); \
357 * Quirk handling helpers
359 * ThinkPad IDs and versions seen in the field so far
360 * are two-characters from the set [0-9A-Z], i.e. base 36.
362 * We use values well outside that range as specials.
365 #define TPACPI_MATCH_ANY 0xffffU
366 #define TPACPI_MATCH_UNKNOWN 0U
368 /* TPID('1', 'Y') == 0x5931 */
369 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
371 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
372 { .vendor = PCI_VENDOR_ID_IBM, \
373 .bios = TPID(__id1, __id2), \
374 .ec = TPACPI_MATCH_ANY, \
375 .quirks = (__quirk) }
377 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
378 { .vendor = PCI_VENDOR_ID_LENOVO, \
379 .bios = TPID(__id1, __id2), \
380 .ec = TPACPI_MATCH_ANY, \
381 .quirks = (__quirk) }
383 struct tpacpi_quirk
{
387 unsigned long quirks
;
391 * tpacpi_check_quirks() - search BIOS/EC version on a list
392 * @qlist: array of &struct tpacpi_quirk
393 * @qlist_size: number of elements in @qlist
395 * Iterates over a quirks list until one is found that matches the
396 * ThinkPad's vendor, BIOS and EC model.
398 * Returns 0 if nothing matches, otherwise returns the quirks field of
399 * the matching &struct tpacpi_quirk entry.
401 * The match criteria is: vendor, ec and bios much match.
403 static unsigned long __init
tpacpi_check_quirks(
404 const struct tpacpi_quirk
*qlist
,
405 unsigned int qlist_size
)
408 if ((qlist
->vendor
== thinkpad_id
.vendor
||
409 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
410 (qlist
->bios
== thinkpad_id
.bios_model
||
411 qlist
->bios
== TPACPI_MATCH_ANY
) &&
412 (qlist
->ec
== thinkpad_id
.ec_model
||
413 qlist
->ec
== TPACPI_MATCH_ANY
))
414 return qlist
->quirks
;
423 /****************************************************************************
424 ****************************************************************************
426 * ACPI Helpers and device model
428 ****************************************************************************
429 ****************************************************************************/
431 /*************************************************************************
435 static acpi_handle root_handle
;
437 #define TPACPI_HANDLE(object, parent, paths...) \
438 static acpi_handle object##_handle; \
439 static acpi_handle *object##_parent = &parent##_handle; \
440 static char *object##_path; \
441 static char *object##_paths[] = { paths }
443 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
444 "\\_SB.PCI.ISA.EC", /* 570 */
445 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
446 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
447 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
448 "\\_SB.PCI0.ICH3.EC0", /* R31 */
449 "\\_SB.PCI0.LPC.EC", /* all others */
452 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
453 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
455 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
457 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
458 "\\CMS", /* R40, R40e */
461 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
462 "^HKEY", /* R30, R31 */
463 "HKEY", /* all others */
466 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
467 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
468 "\\_SB.PCI0.VID0", /* 770e */
469 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
470 "\\_SB.PCI0.AGP.VID", /* all others */
474 /*************************************************************************
478 static int acpi_evalf(acpi_handle handle
,
479 void *res
, char *method
, char *fmt
, ...)
482 struct acpi_object_list params
;
483 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
484 struct acpi_buffer result
, *resultp
;
485 union acpi_object out_obj
;
493 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
506 params
.pointer
= &in_objs
[0];
513 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
514 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
516 /* add more types as needed */
518 printk(TPACPI_ERR
"acpi_evalf() called "
519 "with invalid format character '%c'\n", c
);
525 if (res_type
!= 'v') {
526 result
.length
= sizeof(out_obj
);
527 result
.pointer
= &out_obj
;
532 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
537 *(int *)res
= out_obj
.integer
.value
;
538 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
541 success
= status
== AE_OK
;
543 /* add more types as needed */
545 printk(TPACPI_ERR
"acpi_evalf() called "
546 "with invalid format character '%c'\n", res_type
);
550 if (!success
&& !quiet
)
551 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
552 method
, fmt0
, status
);
557 static int acpi_ec_read(int i
, u8
*p
)
562 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
566 if (ec_read(i
, p
) < 0)
573 static int acpi_ec_write(int i
, u8 v
)
576 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
579 if (ec_write(i
, v
) < 0)
586 static int issue_thinkpad_cmos_command(int cmos_cmd
)
591 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
597 /*************************************************************************
601 #define TPACPI_ACPIHANDLE_INIT(object) \
602 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
603 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
605 static void drv_acpi_handle_init(char *name
,
606 acpi_handle
*handle
, acpi_handle parent
,
607 char **paths
, int num_paths
, char **path
)
612 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
615 for (i
= 0; i
< num_paths
; i
++) {
616 status
= acpi_get_handle(parent
, paths
[i
], handle
);
617 if (ACPI_SUCCESS(status
)) {
619 dbg_printk(TPACPI_DBG_INIT
,
620 "Found ACPI handle %s for %s\n",
626 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
631 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
633 struct ibm_struct
*ibm
= data
;
635 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
638 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
641 ibm
->acpi
->notify(ibm
, event
);
644 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
651 if (!*ibm
->acpi
->handle
)
654 vdbg_printk(TPACPI_DBG_INIT
,
655 "setting up ACPI notify for %s\n", ibm
->name
);
657 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
659 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
664 ibm
->acpi
->device
->driver_data
= ibm
;
665 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
666 TPACPI_ACPI_EVENT_PREFIX
,
669 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
670 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
671 if (ACPI_FAILURE(status
)) {
672 if (status
== AE_ALREADY_EXISTS
) {
674 "another device driver is already "
675 "handling %s events\n", ibm
->name
);
678 "acpi_install_notify_handler(%s) failed: %d\n",
683 ibm
->flags
.acpi_notify_installed
= 1;
687 static int __init
tpacpi_device_add(struct acpi_device
*device
)
692 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
696 dbg_printk(TPACPI_DBG_INIT
,
697 "registering %s as an ACPI driver\n", ibm
->name
);
701 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
702 if (!ibm
->acpi
->driver
) {
704 "failed to allocate memory for ibm->acpi->driver\n");
708 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
709 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
711 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
713 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
715 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
717 kfree(ibm
->acpi
->driver
);
718 ibm
->acpi
->driver
= NULL
;
720 ibm
->flags
.acpi_driver_registered
= 1;
726 /****************************************************************************
727 ****************************************************************************
731 ****************************************************************************
732 ****************************************************************************/
734 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
735 int count
, int *eof
, void *data
)
737 struct ibm_struct
*ibm
= data
;
740 if (!ibm
|| !ibm
->read
)
743 len
= ibm
->read(page
);
747 if (len
<= off
+ count
)
759 static int dispatch_procfs_write(struct file
*file
,
760 const char __user
*userbuf
,
761 unsigned long count
, void *data
)
763 struct ibm_struct
*ibm
= data
;
767 if (!ibm
|| !ibm
->write
)
770 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
774 if (copy_from_user(kernbuf
, userbuf
, count
)) {
780 strcat(kernbuf
, ",");
781 ret
= ibm
->write(kernbuf
);
790 static char *next_cmd(char **cmds
)
795 while ((end
= strchr(start
, ',')) && end
== start
)
807 /****************************************************************************
808 ****************************************************************************
810 * Device model: input, hwmon and platform
812 ****************************************************************************
813 ****************************************************************************/
815 static struct platform_device
*tpacpi_pdev
;
816 static struct platform_device
*tpacpi_sensors_pdev
;
817 static struct device
*tpacpi_hwmon
;
818 static struct input_dev
*tpacpi_inputdev
;
819 static struct mutex tpacpi_inputdev_send_mutex
;
820 static LIST_HEAD(tpacpi_all_drivers
);
822 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
825 struct ibm_struct
*ibm
, *itmp
;
827 list_for_each_entry_safe(ibm
, itmp
,
831 (ibm
->suspend
)(state
);
837 static int tpacpi_resume_handler(struct platform_device
*pdev
)
839 struct ibm_struct
*ibm
, *itmp
;
841 list_for_each_entry_safe(ibm
, itmp
,
851 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
853 struct ibm_struct
*ibm
, *itmp
;
855 list_for_each_entry_safe(ibm
, itmp
,
863 static struct platform_driver tpacpi_pdriver
= {
865 .name
= TPACPI_DRVR_NAME
,
866 .owner
= THIS_MODULE
,
868 .suspend
= tpacpi_suspend_handler
,
869 .resume
= tpacpi_resume_handler
,
870 .shutdown
= tpacpi_shutdown_handler
,
873 static struct platform_driver tpacpi_hwmon_pdriver
= {
875 .name
= TPACPI_HWMON_DRVR_NAME
,
876 .owner
= THIS_MODULE
,
880 /*************************************************************************
881 * sysfs support helpers
884 struct attribute_set
{
885 unsigned int members
, max_members
;
886 struct attribute_group group
;
889 struct attribute_set_obj
{
890 struct attribute_set s
;
892 } __attribute__((packed
));
894 static struct attribute_set
*create_attr_set(unsigned int max_members
,
897 struct attribute_set_obj
*sobj
;
899 if (max_members
== 0)
902 /* Allocates space for implicit NULL at the end too */
903 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
904 max_members
* sizeof(struct attribute
*),
908 sobj
->s
.max_members
= max_members
;
909 sobj
->s
.group
.attrs
= &sobj
->a
;
910 sobj
->s
.group
.name
= name
;
915 #define destroy_attr_set(_set) \
918 /* not multi-threaded safe, use it in a single thread per set */
919 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
924 if (s
->members
>= s
->max_members
)
927 s
->group
.attrs
[s
->members
] = attr
;
933 static int add_many_to_attr_set(struct attribute_set
*s
,
934 struct attribute
**attr
,
939 for (i
= 0; i
< count
; i
++) {
940 res
= add_to_attr_set(s
, attr
[i
]);
948 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
950 sysfs_remove_group(kobj
, &s
->group
);
954 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
955 sysfs_create_group(_kobj, &_attr_set->group)
957 static int parse_strtoul(const char *buf
,
958 unsigned long max
, unsigned long *value
)
962 while (*buf
&& isspace(*buf
))
964 *value
= simple_strtoul(buf
, &endp
, 0);
965 while (*endp
&& isspace(*endp
))
967 if (*endp
|| *value
> max
)
973 static void tpacpi_disable_brightness_delay(void)
975 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
977 "ACPI backlight control delay disabled\n");
980 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
982 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
983 union acpi_object
*obj
;
986 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
987 obj
= (union acpi_object
*)buffer
.pointer
;
988 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
989 printk(TPACPI_ERR
"Unknown _BCL data, "
990 "please report this to %s\n", TPACPI_MAIL
);
993 rc
= obj
->package
.count
;
999 kfree(buffer
.pointer
);
1003 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1004 u32 lvl
, void *context
, void **rv
)
1006 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1007 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1009 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1010 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1011 BUG_ON(!rv
|| !*rv
);
1012 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1013 return AE_CTRL_TERMINATE
;
1020 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1022 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1026 void *bcl_ptr
= &bcl_levels
;
1029 TPACPI_ACPIHANDLE_INIT(vid
);
1035 * Search for a _BCL method, and execute it. This is safe on all
1036 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1037 * BIOS in ACPI backlight control mode. We do NOT have to care
1038 * about calling the _BCL method in an enabled video device, any
1039 * will do for our purposes.
1042 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1043 tpacpi_acpi_walk_find_bcl
, NULL
,
1046 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1047 tp_features
.bright_acpimode
= 1;
1048 return (bcl_levels
- 2);
1054 static void printk_deprecated_attribute(const char * const what
,
1055 const char * const details
)
1057 tpacpi_log_usertask("deprecated sysfs attribute");
1058 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1059 "will be removed. %s\n",
1063 /*************************************************************************
1064 * rfkill and radio control support helpers
1068 * ThinkPad-ACPI firmware handling model:
1070 * WLSW (master wireless switch) is event-driven, and is common to all
1071 * firmware-controlled radios. It cannot be controlled, just monitored,
1072 * as expected. It overrides all radio state in firmware
1074 * The kernel, a masked-off hotkey, and WLSW can change the radio state
1075 * (TODO: verify how WLSW interacts with the returned radio state).
1077 * The only time there are shadow radio state changes, is when
1078 * masked-off hotkeys are used.
1082 * Internal driver API for radio state:
1084 * int: < 0 = error, otherwise enum tpacpi_rfkill_state
1085 * bool: true means radio blocked (off)
1087 enum tpacpi_rfkill_state
{
1088 TPACPI_RFK_RADIO_OFF
= 0,
1092 /* rfkill switches */
1093 enum tpacpi_rfk_id
{
1094 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
1095 TPACPI_RFK_WWAN_SW_ID
,
1096 TPACPI_RFK_UWB_SW_ID
,
1100 static const char *tpacpi_rfkill_names
[] = {
1101 [TPACPI_RFK_BLUETOOTH_SW_ID
] = "bluetooth",
1102 [TPACPI_RFK_WWAN_SW_ID
] = "wwan",
1103 [TPACPI_RFK_UWB_SW_ID
] = "uwb",
1104 [TPACPI_RFK_SW_MAX
] = NULL
1107 /* ThinkPad-ACPI rfkill subdriver */
1109 struct rfkill
*rfkill
;
1110 enum tpacpi_rfk_id id
;
1111 const struct tpacpi_rfk_ops
*ops
;
1114 struct tpacpi_rfk_ops
{
1115 /* firmware interface */
1116 int (*get_status
)(void);
1117 int (*set_status
)(const enum tpacpi_rfkill_state
);
1120 static struct tpacpi_rfk
*tpacpi_rfkill_switches
[TPACPI_RFK_SW_MAX
];
1122 /* Query FW and update rfkill sw state for a given rfkill switch */
1123 static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk
*tp_rfk
)
1130 status
= (tp_rfk
->ops
->get_status
)();
1134 rfkill_set_sw_state(tp_rfk
->rfkill
,
1135 (status
== TPACPI_RFK_RADIO_OFF
));
1140 /* Query FW and update rfkill sw state for all rfkill switches */
1141 static void tpacpi_rfk_update_swstate_all(void)
1145 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++)
1146 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[i
]);
1150 * Sync the HW-blocking state of all rfkill switches,
1151 * do notice it causes the rfkill core to schedule uevents
1153 static void tpacpi_rfk_update_hwblock_state(bool blocked
)
1156 struct tpacpi_rfk
*tp_rfk
;
1158 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++) {
1159 tp_rfk
= tpacpi_rfkill_switches
[i
];
1161 if (rfkill_set_hw_state(tp_rfk
->rfkill
,
1163 /* ignore -- we track sw block */
1169 /* Call to get the WLSW state from the firmware */
1170 static int hotkey_get_wlsw(void);
1172 /* Call to query WLSW state and update all rfkill switches */
1173 static bool tpacpi_rfk_check_hwblock_state(void)
1175 int res
= hotkey_get_wlsw();
1178 /* When unknown or unsupported, we have to assume it is unblocked */
1182 hw_blocked
= (res
== TPACPI_RFK_RADIO_OFF
);
1183 tpacpi_rfk_update_hwblock_state(hw_blocked
);
1188 static int tpacpi_rfk_hook_set_block(void *data
, bool blocked
)
1190 struct tpacpi_rfk
*tp_rfk
= data
;
1193 dbg_printk(TPACPI_DBG_RFKILL
,
1194 "request to change radio state to %s\n",
1195 blocked
? "blocked" : "unblocked");
1197 /* try to set radio state */
1198 res
= (tp_rfk
->ops
->set_status
)(blocked
?
1199 TPACPI_RFK_RADIO_OFF
: TPACPI_RFK_RADIO_ON
);
1201 /* and update the rfkill core with whatever the FW really did */
1202 tpacpi_rfk_update_swstate(tp_rfk
);
1204 return (res
< 0) ? res
: 0;
1207 static const struct rfkill_ops tpacpi_rfk_rfkill_ops
= {
1208 .set_block
= tpacpi_rfk_hook_set_block
,
1211 static int __init
tpacpi_new_rfkill(const enum tpacpi_rfk_id id
,
1212 const struct tpacpi_rfk_ops
*tp_rfkops
,
1213 const enum rfkill_type rfktype
,
1215 const bool set_default
)
1217 struct tpacpi_rfk
*atp_rfk
;
1219 bool sw_state
= false;
1222 BUG_ON(id
>= TPACPI_RFK_SW_MAX
|| tpacpi_rfkill_switches
[id
]);
1224 atp_rfk
= kzalloc(sizeof(struct tpacpi_rfk
), GFP_KERNEL
);
1226 atp_rfk
->rfkill
= rfkill_alloc(name
,
1229 &tpacpi_rfk_rfkill_ops
,
1231 if (!atp_rfk
|| !atp_rfk
->rfkill
) {
1233 "failed to allocate memory for rfkill class\n");
1239 atp_rfk
->ops
= tp_rfkops
;
1241 sw_status
= (tp_rfkops
->get_status
)();
1242 if (sw_status
< 0) {
1244 "failed to read initial state for %s, error %d\n",
1247 sw_state
= (sw_status
== TPACPI_RFK_RADIO_OFF
);
1249 /* try to keep the initial state, since we ask the
1250 * firmware to preserve it across S5 in NVRAM */
1251 rfkill_init_sw_state(atp_rfk
->rfkill
, sw_state
);
1254 rfkill_set_hw_state(atp_rfk
->rfkill
, tpacpi_rfk_check_hwblock_state());
1256 res
= rfkill_register(atp_rfk
->rfkill
);
1259 "failed to register %s rfkill switch: %d\n",
1261 rfkill_destroy(atp_rfk
->rfkill
);
1266 tpacpi_rfkill_switches
[id
] = atp_rfk
;
1270 static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id
)
1272 struct tpacpi_rfk
*tp_rfk
;
1274 BUG_ON(id
>= TPACPI_RFK_SW_MAX
);
1276 tp_rfk
= tpacpi_rfkill_switches
[id
];
1278 rfkill_unregister(tp_rfk
->rfkill
);
1279 tpacpi_rfkill_switches
[id
] = NULL
;
1284 static void printk_deprecated_rfkill_attribute(const char * const what
)
1286 printk_deprecated_attribute(what
,
1287 "Please switch to generic rfkill before year 2010");
1290 /* sysfs <radio> enable ------------------------------------------------ */
1291 static ssize_t
tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id
,
1292 struct device_attribute
*attr
,
1297 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1299 /* This is in the ABI... */
1300 if (tpacpi_rfk_check_hwblock_state()) {
1301 status
= TPACPI_RFK_RADIO_OFF
;
1303 status
= tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1308 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1309 (status
== TPACPI_RFK_RADIO_ON
) ? 1 : 0);
1312 static ssize_t
tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id
,
1313 struct device_attribute
*attr
,
1314 const char *buf
, size_t count
)
1319 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1321 if (parse_strtoul(buf
, 1, &t
))
1324 tpacpi_disclose_usertask(attr
->attr
.name
, "set to %ld\n", t
);
1326 /* This is in the ABI... */
1327 if (tpacpi_rfk_check_hwblock_state() && !!t
)
1330 res
= tpacpi_rfkill_switches
[id
]->ops
->set_status((!!t
) ?
1331 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
);
1332 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1334 return (res
< 0) ? res
: count
;
1337 /* procfs -------------------------------------------------------------- */
1338 static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id
, char *p
)
1342 if (id
>= TPACPI_RFK_SW_MAX
)
1343 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1347 /* This is in the ABI... */
1348 if (tpacpi_rfk_check_hwblock_state()) {
1349 status
= TPACPI_RFK_RADIO_OFF
;
1351 status
= tpacpi_rfk_update_swstate(
1352 tpacpi_rfkill_switches
[id
]);
1357 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1358 (status
== TPACPI_RFK_RADIO_ON
) ?
1359 "enabled" : "disabled");
1360 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1366 static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id
, char *buf
)
1372 if (id
>= TPACPI_RFK_SW_MAX
)
1375 while ((cmd
= next_cmd(&buf
))) {
1376 if (strlencmp(cmd
, "enable") == 0)
1377 status
= TPACPI_RFK_RADIO_ON
;
1378 else if (strlencmp(cmd
, "disable") == 0)
1379 status
= TPACPI_RFK_RADIO_OFF
;
1385 tpacpi_disclose_usertask("procfs", "attempt to %s %s\n",
1386 (status
== TPACPI_RFK_RADIO_ON
) ?
1387 "enable" : "disable",
1388 tpacpi_rfkill_names
[id
]);
1389 res
= (tpacpi_rfkill_switches
[id
]->ops
->set_status
)(status
);
1390 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1396 /*************************************************************************
1397 * thinkpad-acpi driver attributes
1400 /* interface_version --------------------------------------------------- */
1401 static ssize_t
tpacpi_driver_interface_version_show(
1402 struct device_driver
*drv
,
1405 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1408 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1409 tpacpi_driver_interface_version_show
, NULL
);
1411 /* debug_level --------------------------------------------------------- */
1412 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1415 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1418 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1419 const char *buf
, size_t count
)
1423 if (parse_strtoul(buf
, 0xffff, &t
))
1431 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1432 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1434 /* version ------------------------------------------------------------- */
1435 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1438 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1439 TPACPI_DESC
, TPACPI_VERSION
);
1442 static DRIVER_ATTR(version
, S_IRUGO
,
1443 tpacpi_driver_version_show
, NULL
);
1445 /* --------------------------------------------------------------------- */
1447 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1449 /* wlsw_emulstate ------------------------------------------------------ */
1450 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1453 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1456 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1457 const char *buf
, size_t count
)
1461 if (parse_strtoul(buf
, 1, &t
))
1464 if (tpacpi_wlsw_emulstate
!= !!t
) {
1465 tpacpi_wlsw_emulstate
= !!t
;
1466 tpacpi_rfk_update_hwblock_state(!t
); /* negative logic */
1472 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1473 tpacpi_driver_wlsw_emulstate_show
,
1474 tpacpi_driver_wlsw_emulstate_store
);
1476 /* bluetooth_emulstate ------------------------------------------------- */
1477 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1478 struct device_driver
*drv
,
1481 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1484 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1485 struct device_driver
*drv
,
1486 const char *buf
, size_t count
)
1490 if (parse_strtoul(buf
, 1, &t
))
1493 tpacpi_bluetooth_emulstate
= !!t
;
1498 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1499 tpacpi_driver_bluetooth_emulstate_show
,
1500 tpacpi_driver_bluetooth_emulstate_store
);
1502 /* wwan_emulstate ------------------------------------------------- */
1503 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1504 struct device_driver
*drv
,
1507 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1510 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1511 struct device_driver
*drv
,
1512 const char *buf
, size_t count
)
1516 if (parse_strtoul(buf
, 1, &t
))
1519 tpacpi_wwan_emulstate
= !!t
;
1524 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1525 tpacpi_driver_wwan_emulstate_show
,
1526 tpacpi_driver_wwan_emulstate_store
);
1528 /* uwb_emulstate ------------------------------------------------- */
1529 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1530 struct device_driver
*drv
,
1533 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1536 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1537 struct device_driver
*drv
,
1538 const char *buf
, size_t count
)
1542 if (parse_strtoul(buf
, 1, &t
))
1545 tpacpi_uwb_emulstate
= !!t
;
1550 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1551 tpacpi_driver_uwb_emulstate_show
,
1552 tpacpi_driver_uwb_emulstate_store
);
1555 /* --------------------------------------------------------------------- */
1557 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1558 &driver_attr_debug_level
, &driver_attr_version
,
1559 &driver_attr_interface_version
,
1562 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1568 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1569 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1573 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1574 if (!res
&& dbg_wlswemul
)
1575 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1576 if (!res
&& dbg_bluetoothemul
)
1577 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1578 if (!res
&& dbg_wwanemul
)
1579 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1580 if (!res
&& dbg_uwbemul
)
1581 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1587 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1591 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1592 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1594 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1595 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1596 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1597 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1598 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1602 /****************************************************************************
1603 ****************************************************************************
1607 ****************************************************************************
1608 ****************************************************************************/
1610 /*************************************************************************
1611 * thinkpad-acpi init subdriver
1614 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1616 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1617 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1619 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1620 (thinkpad_id
.bios_version_str
) ?
1621 thinkpad_id
.bios_version_str
: "unknown",
1622 (thinkpad_id
.ec_version_str
) ?
1623 thinkpad_id
.ec_version_str
: "unknown");
1625 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1626 printk(TPACPI_INFO
"%s %s, model %s\n",
1627 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1628 "IBM" : ((thinkpad_id
.vendor
==
1629 PCI_VENDOR_ID_LENOVO
) ?
1630 "Lenovo" : "Unknown vendor"),
1631 thinkpad_id
.model_str
,
1632 (thinkpad_id
.nummodel_str
) ?
1633 thinkpad_id
.nummodel_str
: "unknown");
1638 static int thinkpad_acpi_driver_read(char *p
)
1642 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1643 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1648 static struct ibm_struct thinkpad_acpi_driver_data
= {
1650 .read
= thinkpad_acpi_driver_read
,
1653 /*************************************************************************
1657 enum { /* hot key scan codes (derived from ACPI DSDT) */
1658 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1659 TP_ACPI_HOTKEYSCAN_FNF2
,
1660 TP_ACPI_HOTKEYSCAN_FNF3
,
1661 TP_ACPI_HOTKEYSCAN_FNF4
,
1662 TP_ACPI_HOTKEYSCAN_FNF5
,
1663 TP_ACPI_HOTKEYSCAN_FNF6
,
1664 TP_ACPI_HOTKEYSCAN_FNF7
,
1665 TP_ACPI_HOTKEYSCAN_FNF8
,
1666 TP_ACPI_HOTKEYSCAN_FNF9
,
1667 TP_ACPI_HOTKEYSCAN_FNF10
,
1668 TP_ACPI_HOTKEYSCAN_FNF11
,
1669 TP_ACPI_HOTKEYSCAN_FNF12
,
1670 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1671 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1672 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1673 TP_ACPI_HOTKEYSCAN_FNHOME
,
1674 TP_ACPI_HOTKEYSCAN_FNEND
,
1675 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1676 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1677 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1678 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1679 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1680 TP_ACPI_HOTKEYSCAN_MUTE
,
1681 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1684 enum { /* Keys available through NVRAM polling */
1685 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1686 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1689 enum { /* Positions of some of the keys in hotkey masks */
1690 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1691 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1692 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1693 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1694 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1695 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1696 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1697 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1698 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1699 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1700 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1703 enum { /* NVRAM to ACPI HKEY group map */
1704 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1705 TP_ACPI_HKEY_ZOOM_MASK
|
1706 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1707 TP_ACPI_HKEY_HIBERNATE_MASK
,
1708 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1709 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1710 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1711 TP_ACPI_HKEY_VOLDWN_MASK
|
1712 TP_ACPI_HKEY_MUTE_MASK
,
1715 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1716 struct tp_nvram_state
{
1717 u16 thinkpad_toggle
:1;
1719 u16 display_toggle
:1;
1720 u16 thinklight_toggle
:1;
1721 u16 hibernate_toggle
:1;
1722 u16 displayexp_toggle
:1;
1723 u16 display_state
:1;
1724 u16 brightness_toggle
:1;
1725 u16 volume_toggle
:1;
1728 u8 brightness_level
;
1732 static struct task_struct
*tpacpi_hotkey_task
;
1733 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1734 static int hotkey_poll_freq
= 10; /* Hz */
1735 static struct mutex hotkey_thread_mutex
;
1736 static struct mutex hotkey_thread_data_mutex
;
1737 static unsigned int hotkey_config_change
;
1739 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1741 #define hotkey_source_mask 0U
1743 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1745 static struct mutex hotkey_mutex
;
1747 static enum { /* Reasons for waking up */
1748 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1749 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1750 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1751 } hotkey_wakeup_reason
;
1753 static int hotkey_autosleep_ack
;
1755 static u32 hotkey_orig_mask
;
1756 static u32 hotkey_all_mask
;
1757 static u32 hotkey_reserved_mask
;
1758 static u32 hotkey_mask
;
1760 static unsigned int hotkey_report_mode
;
1762 static u16
*hotkey_keycode_map
;
1764 static struct attribute_set
*hotkey_dev_attributes
;
1766 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1767 #define HOTKEY_CONFIG_CRITICAL_START \
1769 mutex_lock(&hotkey_thread_data_mutex); \
1770 hotkey_config_change++; \
1772 #define HOTKEY_CONFIG_CRITICAL_END \
1773 mutex_unlock(&hotkey_thread_data_mutex);
1775 #define HOTKEY_CONFIG_CRITICAL_START
1776 #define HOTKEY_CONFIG_CRITICAL_END
1777 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1779 /* HKEY.MHKG() return bits */
1780 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1782 static int hotkey_get_wlsw(void)
1786 if (!tp_features
.hotkey_wlsw
)
1789 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1791 return (tpacpi_wlsw_emulstate
) ?
1792 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
1795 if (!acpi_evalf(hkey_handle
, &status
, "WLSW", "d"))
1798 return (status
) ? TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
1801 static int hotkey_get_tablet_mode(int *status
)
1805 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1808 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1813 * Call with hotkey_mutex held
1815 static int hotkey_mask_get(void)
1819 if (tp_features
.hotkey_mask
) {
1820 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1823 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1829 * Call with hotkey_mutex held
1831 static int hotkey_mask_set(u32 mask
)
1836 if (tp_features
.hotkey_mask
) {
1837 if (!tp_warned
.hotkey_mask_ff
&&
1838 (mask
== 0xffff || mask
== 0xffffff ||
1839 mask
== 0xffffffff)) {
1840 tp_warned
.hotkey_mask_ff
= 1;
1841 printk(TPACPI_NOTICE
1842 "setting the hotkey mask to 0x%08x is likely "
1843 "not the best way to go about it\n", mask
);
1844 printk(TPACPI_NOTICE
1845 "please consider using the driver defaults, "
1846 "and refer to up-to-date thinkpad-acpi "
1850 HOTKEY_CONFIG_CRITICAL_START
1851 for (i
= 0; i
< 32; i
++) {
1853 /* enable in firmware mask only keys not in NVRAM
1854 * mode, but enable the key in the cached hotkey_mask
1855 * regardless of mode, or the key will end up
1856 * disabled by hotkey_mask_get() */
1857 if (!acpi_evalf(hkey_handle
,
1858 NULL
, "MHKM", "vdd", i
+ 1,
1859 !!((mask
& ~hotkey_source_mask
) & m
))) {
1863 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1866 HOTKEY_CONFIG_CRITICAL_END
1868 /* hotkey_mask_get must be called unconditionally below */
1869 if (!hotkey_mask_get() && !rc
&&
1870 (hotkey_mask
& ~hotkey_source_mask
) !=
1871 (mask
& ~hotkey_source_mask
)) {
1872 printk(TPACPI_NOTICE
1873 "requested hot key mask 0x%08x, but "
1874 "firmware forced it to 0x%08x\n",
1878 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1879 HOTKEY_CONFIG_CRITICAL_START
1880 hotkey_mask
= mask
& hotkey_source_mask
;
1881 HOTKEY_CONFIG_CRITICAL_END
1883 if (hotkey_mask
!= mask
) {
1884 printk(TPACPI_NOTICE
1885 "requested hot key mask 0x%08x, "
1886 "forced to 0x%08x (NVRAM poll mask is "
1887 "0x%08x): no firmware mask support\n",
1888 mask
, hotkey_mask
, hotkey_source_mask
);
1893 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1899 static int hotkey_status_get(int *status
)
1901 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1907 static int hotkey_status_set(bool enable
)
1909 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
1915 static void tpacpi_input_send_tabletsw(void)
1919 if (tp_features
.hotkey_tablet
&&
1920 !hotkey_get_tablet_mode(&state
)) {
1921 mutex_lock(&tpacpi_inputdev_send_mutex
);
1923 input_report_switch(tpacpi_inputdev
,
1924 SW_TABLET_MODE
, !!state
);
1925 input_sync(tpacpi_inputdev
);
1927 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1931 static void tpacpi_input_send_key(unsigned int scancode
)
1933 unsigned int keycode
;
1935 keycode
= hotkey_keycode_map
[scancode
];
1937 if (keycode
!= KEY_RESERVED
) {
1938 mutex_lock(&tpacpi_inputdev_send_mutex
);
1940 input_report_key(tpacpi_inputdev
, keycode
, 1);
1941 if (keycode
== KEY_UNKNOWN
)
1942 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1944 input_sync(tpacpi_inputdev
);
1946 input_report_key(tpacpi_inputdev
, keycode
, 0);
1947 if (keycode
== KEY_UNKNOWN
)
1948 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1950 input_sync(tpacpi_inputdev
);
1952 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1956 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1957 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1959 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1961 tpacpi_input_send_key(scancode
);
1962 if (hotkey_report_mode
< 2) {
1963 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1964 0x80, 0x1001 + scancode
);
1968 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1972 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1973 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1974 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1975 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1976 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1977 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1979 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1980 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1981 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1983 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1984 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1985 n
->displayexp_toggle
=
1986 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1988 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1989 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1990 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1991 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1992 n
->brightness_toggle
=
1993 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1995 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1996 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1997 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1998 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1999 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2000 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2004 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2006 if ((mask & (1 << __scancode)) && \
2007 oldn->__member != newn->__member) \
2008 tpacpi_hotkey_send_key(__scancode); \
2011 #define TPACPI_MAY_SEND_KEY(__scancode) \
2012 do { if (mask & (1 << __scancode)) \
2013 tpacpi_hotkey_send_key(__scancode); } while (0)
2015 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2016 struct tp_nvram_state
*newn
,
2019 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2020 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2021 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2022 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2024 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2026 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2029 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2030 if (oldn
->mute
!= newn
->mute
) {
2031 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2033 if (oldn
->volume_level
> newn
->volume_level
) {
2034 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2035 } else if (oldn
->volume_level
< newn
->volume_level
) {
2036 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2037 } else if (oldn
->mute
== newn
->mute
) {
2038 /* repeated key presses that didn't change state */
2040 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2041 } else if (newn
->volume_level
!= 0) {
2042 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2044 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2049 /* handle brightness */
2050 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2051 if (oldn
->brightness_level
< newn
->brightness_level
) {
2052 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2053 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
2054 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2056 /* repeated key presses that didn't change state */
2057 if (newn
->brightness_level
!= 0) {
2058 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2060 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2066 #undef TPACPI_COMPARE_KEY
2067 #undef TPACPI_MAY_SEND_KEY
2069 static int hotkey_kthread(void *data
)
2071 struct tp_nvram_state s
[2];
2073 unsigned int si
, so
;
2075 unsigned int change_detector
, must_reset
;
2077 mutex_lock(&hotkey_thread_mutex
);
2079 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2088 /* Initial state for compares */
2089 mutex_lock(&hotkey_thread_data_mutex
);
2090 change_detector
= hotkey_config_change
;
2091 mask
= hotkey_source_mask
& hotkey_mask
;
2092 mutex_unlock(&hotkey_thread_data_mutex
);
2093 hotkey_read_nvram(&s
[so
], mask
);
2095 while (!kthread_should_stop() && hotkey_poll_freq
) {
2097 t
= 1000/hotkey_poll_freq
;
2098 t
= msleep_interruptible(t
);
2099 if (unlikely(kthread_should_stop()))
2101 must_reset
= try_to_freeze();
2102 if (t
> 0 && !must_reset
)
2105 mutex_lock(&hotkey_thread_data_mutex
);
2106 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2107 /* forget old state on thaw or config change */
2110 change_detector
= hotkey_config_change
;
2112 mask
= hotkey_source_mask
& hotkey_mask
;
2113 mutex_unlock(&hotkey_thread_data_mutex
);
2116 hotkey_read_nvram(&s
[si
], mask
);
2117 if (likely(si
!= so
)) {
2118 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2128 mutex_unlock(&hotkey_thread_mutex
);
2132 static void hotkey_poll_stop_sync(void)
2134 if (tpacpi_hotkey_task
) {
2135 if (frozen(tpacpi_hotkey_task
) ||
2136 freezing(tpacpi_hotkey_task
))
2137 thaw_process(tpacpi_hotkey_task
);
2139 kthread_stop(tpacpi_hotkey_task
);
2140 tpacpi_hotkey_task
= NULL
;
2141 mutex_lock(&hotkey_thread_mutex
);
2142 /* at this point, the thread did exit */
2143 mutex_unlock(&hotkey_thread_mutex
);
2147 /* call with hotkey_mutex held */
2148 static void hotkey_poll_setup(int may_warn
)
2150 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
2151 hotkey_poll_freq
> 0 &&
2152 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
2153 if (!tpacpi_hotkey_task
) {
2154 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2155 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2156 if (IS_ERR(tpacpi_hotkey_task
)) {
2157 tpacpi_hotkey_task
= NULL
;
2159 "could not create kernel thread "
2160 "for hotkey polling\n");
2164 hotkey_poll_stop_sync();
2166 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
2167 printk(TPACPI_NOTICE
2168 "hot keys 0x%08x require polling, "
2169 "which is currently disabled\n",
2170 hotkey_source_mask
);
2175 static void hotkey_poll_setup_safe(int may_warn
)
2177 mutex_lock(&hotkey_mutex
);
2178 hotkey_poll_setup(may_warn
);
2179 mutex_unlock(&hotkey_mutex
);
2182 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2184 static void hotkey_poll_setup_safe(int __unused
)
2188 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2190 static int hotkey_inputdev_open(struct input_dev
*dev
)
2192 switch (tpacpi_lifecycle
) {
2193 case TPACPI_LIFE_INIT
:
2195 * hotkey_init will call hotkey_poll_setup_safe
2196 * at the appropriate moment
2199 case TPACPI_LIFE_EXITING
:
2201 case TPACPI_LIFE_RUNNING
:
2202 hotkey_poll_setup_safe(0);
2206 /* Should only happen if tpacpi_lifecycle is corrupt */
2211 static void hotkey_inputdev_close(struct input_dev
*dev
)
2213 /* disable hotkey polling when possible */
2214 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
2215 hotkey_poll_setup_safe(0);
2218 /* sysfs hotkey enable ------------------------------------------------- */
2219 static ssize_t
hotkey_enable_show(struct device
*dev
,
2220 struct device_attribute
*attr
,
2225 printk_deprecated_attribute("hotkey_enable",
2226 "Hotkey reporting is always enabled");
2228 res
= hotkey_status_get(&status
);
2232 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2235 static ssize_t
hotkey_enable_store(struct device
*dev
,
2236 struct device_attribute
*attr
,
2237 const char *buf
, size_t count
)
2241 printk_deprecated_attribute("hotkey_enable",
2242 "Hotkeys can be disabled through hotkey_mask");
2244 if (parse_strtoul(buf
, 1, &t
))
2253 static struct device_attribute dev_attr_hotkey_enable
=
2254 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2255 hotkey_enable_show
, hotkey_enable_store
);
2257 /* sysfs hotkey mask --------------------------------------------------- */
2258 static ssize_t
hotkey_mask_show(struct device
*dev
,
2259 struct device_attribute
*attr
,
2264 if (mutex_lock_killable(&hotkey_mutex
))
2265 return -ERESTARTSYS
;
2266 res
= hotkey_mask_get();
2267 mutex_unlock(&hotkey_mutex
);
2270 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
2273 static ssize_t
hotkey_mask_store(struct device
*dev
,
2274 struct device_attribute
*attr
,
2275 const char *buf
, size_t count
)
2280 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2283 if (mutex_lock_killable(&hotkey_mutex
))
2284 return -ERESTARTSYS
;
2286 res
= hotkey_mask_set(t
);
2288 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2289 hotkey_poll_setup(1);
2292 mutex_unlock(&hotkey_mutex
);
2294 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2296 return (res
) ? res
: count
;
2299 static struct device_attribute dev_attr_hotkey_mask
=
2300 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2301 hotkey_mask_show
, hotkey_mask_store
);
2303 /* sysfs hotkey bios_enabled ------------------------------------------- */
2304 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2305 struct device_attribute
*attr
,
2308 return sprintf(buf
, "0\n");
2311 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2312 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2314 /* sysfs hotkey bios_mask ---------------------------------------------- */
2315 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2316 struct device_attribute
*attr
,
2319 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2322 static struct device_attribute dev_attr_hotkey_bios_mask
=
2323 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2325 /* sysfs hotkey all_mask ----------------------------------------------- */
2326 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2327 struct device_attribute
*attr
,
2330 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2331 hotkey_all_mask
| hotkey_source_mask
);
2334 static struct device_attribute dev_attr_hotkey_all_mask
=
2335 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2337 /* sysfs hotkey recommended_mask --------------------------------------- */
2338 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2339 struct device_attribute
*attr
,
2342 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2343 (hotkey_all_mask
| hotkey_source_mask
)
2344 & ~hotkey_reserved_mask
);
2347 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2348 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2349 hotkey_recommended_mask_show
, NULL
);
2351 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2353 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2354 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2355 struct device_attribute
*attr
,
2358 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2361 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2362 struct device_attribute
*attr
,
2363 const char *buf
, size_t count
)
2367 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2368 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2371 if (mutex_lock_killable(&hotkey_mutex
))
2372 return -ERESTARTSYS
;
2374 HOTKEY_CONFIG_CRITICAL_START
2375 hotkey_source_mask
= t
;
2376 HOTKEY_CONFIG_CRITICAL_END
2378 hotkey_poll_setup(1);
2380 mutex_unlock(&hotkey_mutex
);
2382 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2387 static struct device_attribute dev_attr_hotkey_source_mask
=
2388 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2389 hotkey_source_mask_show
, hotkey_source_mask_store
);
2391 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2392 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2393 struct device_attribute
*attr
,
2396 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2399 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2400 struct device_attribute
*attr
,
2401 const char *buf
, size_t count
)
2405 if (parse_strtoul(buf
, 25, &t
))
2408 if (mutex_lock_killable(&hotkey_mutex
))
2409 return -ERESTARTSYS
;
2411 hotkey_poll_freq
= t
;
2413 hotkey_poll_setup(1);
2414 mutex_unlock(&hotkey_mutex
);
2416 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2421 static struct device_attribute dev_attr_hotkey_poll_freq
=
2422 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2423 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2425 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2427 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2428 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2429 struct device_attribute
*attr
,
2433 res
= hotkey_get_wlsw();
2437 /* Opportunistic update */
2438 tpacpi_rfk_update_hwblock_state((res
== TPACPI_RFK_RADIO_OFF
));
2440 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2441 (res
== TPACPI_RFK_RADIO_OFF
) ? 0 : 1);
2444 static struct device_attribute dev_attr_hotkey_radio_sw
=
2445 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2447 static void hotkey_radio_sw_notify_change(void)
2449 if (tp_features
.hotkey_wlsw
)
2450 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2454 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2455 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2456 struct device_attribute
*attr
,
2460 res
= hotkey_get_tablet_mode(&s
);
2464 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2467 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2468 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2470 static void hotkey_tablet_mode_notify_change(void)
2472 if (tp_features
.hotkey_tablet
)
2473 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2474 "hotkey_tablet_mode");
2477 /* sysfs hotkey report_mode -------------------------------------------- */
2478 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2479 struct device_attribute
*attr
,
2482 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2483 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2486 static struct device_attribute dev_attr_hotkey_report_mode
=
2487 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2489 /* sysfs wakeup reason (pollable) -------------------------------------- */
2490 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2491 struct device_attribute
*attr
,
2494 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2497 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2498 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2500 static void hotkey_wakeup_reason_notify_change(void)
2502 if (tp_features
.hotkey_mask
)
2503 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2507 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2508 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2509 struct device_attribute
*attr
,
2512 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2515 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2516 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2517 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2519 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2521 if (tp_features
.hotkey_mask
)
2522 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2523 "wakeup_hotunplug_complete");
2526 /* --------------------------------------------------------------------- */
2528 static struct attribute
*hotkey_attributes
[] __initdata
= {
2529 &dev_attr_hotkey_enable
.attr
,
2530 &dev_attr_hotkey_bios_enabled
.attr
,
2531 &dev_attr_hotkey_report_mode
.attr
,
2532 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2533 &dev_attr_hotkey_mask
.attr
,
2534 &dev_attr_hotkey_all_mask
.attr
,
2535 &dev_attr_hotkey_recommended_mask
.attr
,
2536 &dev_attr_hotkey_source_mask
.attr
,
2537 &dev_attr_hotkey_poll_freq
.attr
,
2541 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
2542 &dev_attr_hotkey_bios_mask
.attr
,
2543 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2544 &dev_attr_hotkey_mask
.attr
,
2545 &dev_attr_hotkey_all_mask
.attr
,
2546 &dev_attr_hotkey_recommended_mask
.attr
,
2548 &dev_attr_hotkey_wakeup_reason
.attr
,
2549 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2553 * Sync both the hw and sw blocking state of all switches
2555 static void tpacpi_send_radiosw_update(void)
2560 * We must sync all rfkill controllers *before* issuing any
2561 * rfkill input events, or we will race the rfkill core input
2564 * tpacpi_inputdev_send_mutex works as a syncronization point
2567 * We optimize to avoid numerous calls to hotkey_get_wlsw.
2570 wlsw
= hotkey_get_wlsw();
2572 /* Sync hw blocking state first if it is hw-blocked */
2573 if (wlsw
== TPACPI_RFK_RADIO_OFF
)
2574 tpacpi_rfk_update_hwblock_state(true);
2576 /* Sync sw blocking state */
2577 tpacpi_rfk_update_swstate_all();
2579 /* Sync hw blocking state last if it is hw-unblocked */
2580 if (wlsw
== TPACPI_RFK_RADIO_ON
)
2581 tpacpi_rfk_update_hwblock_state(false);
2583 /* Issue rfkill input event for WLSW switch */
2585 mutex_lock(&tpacpi_inputdev_send_mutex
);
2587 input_report_switch(tpacpi_inputdev
,
2588 SW_RFKILL_ALL
, (wlsw
> 0));
2589 input_sync(tpacpi_inputdev
);
2591 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2595 * this can be unconditional, as we will poll state again
2596 * if userspace uses the notify to read data
2598 hotkey_radio_sw_notify_change();
2601 static void hotkey_exit(void)
2603 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2604 hotkey_poll_stop_sync();
2607 if (hotkey_dev_attributes
)
2608 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2610 kfree(hotkey_keycode_map
);
2612 if (tp_features
.hotkey
) {
2613 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
2614 "restoring original hot key mask\n");
2615 /* no short-circuit boolean operator below! */
2616 if ((hotkey_mask_set(hotkey_orig_mask
) |
2617 hotkey_status_set(false)) != 0)
2619 "failed to restore hot key mask "
2620 "to BIOS defaults\n");
2624 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2626 /* Requirements for changing the default keymaps:
2628 * 1. Many of the keys are mapped to KEY_RESERVED for very
2629 * good reasons. Do not change them unless you have deep
2630 * knowledge on the IBM and Lenovo ThinkPad firmware for
2631 * the various ThinkPad models. The driver behaves
2632 * differently for KEY_RESERVED: such keys have their
2633 * hot key mask *unset* in mask_recommended, and also
2634 * in the initial hot key mask programmed into the
2635 * firmware at driver load time, which means the firm-
2636 * ware may react very differently if you change them to
2639 * 2. You must be subscribed to the linux-thinkpad and
2640 * ibm-acpi-devel mailing lists, and you should read the
2641 * list archives since 2007 if you want to change the
2642 * keymaps. This requirement exists so that you will
2643 * know the past history of problems with the thinkpad-
2644 * acpi driver keymaps, and also that you will be
2645 * listening to any bug reports;
2647 * 3. Do not send thinkpad-acpi specific patches directly to
2648 * for merging, *ever*. Send them to the linux-acpi
2649 * mailinglist for comments. Merging is to be done only
2650 * through acpi-test and the ACPI maintainer.
2652 * If the above is too much to ask, don't change the keymap.
2653 * Ask the thinkpad-acpi maintainer to do it, instead.
2655 static u16 ibm_keycode_map
[] __initdata
= {
2656 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2657 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2658 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2659 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2661 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2662 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2663 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2664 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2666 /* brightness: firmware always reacts to them, unless
2667 * X.org did some tricks in the radeon BIOS scratch
2668 * registers of *some* models */
2669 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2670 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2672 /* Thinklight: firmware always react to it */
2673 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2675 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2676 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2678 /* Volume: firmware always react to it and reprograms
2679 * the built-in *extra* mixer. Never map it to control
2680 * another mixer by default. */
2681 KEY_RESERVED
, /* 0x14: VOLUME UP */
2682 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2683 KEY_RESERVED
, /* 0x16: MUTE */
2685 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2687 /* (assignments unknown, please report if found) */
2688 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2689 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2691 static u16 lenovo_keycode_map
[] __initdata
= {
2692 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2693 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2694 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2695 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2697 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2698 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2699 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2700 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2702 /* These either have to go through ACPI video, or
2703 * act like in the IBM ThinkPads, so don't ever
2704 * enable them by default */
2705 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2706 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2708 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2710 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2711 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2713 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2714 * react to it and reprograms the built-in *extra* mixer.
2715 * Never map it to control another mixer by default.
2717 * T60?, T61, R60?, R61: firmware and EC tries to send
2718 * these over the regular keyboard, so these are no-ops,
2719 * but there are still weird bugs re. MUTE, so do not
2720 * change unless you get test reports from all Lenovo
2721 * models. May cause the BIOS to interfere with the
2724 KEY_RESERVED
, /* 0x14: VOLUME UP */
2725 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2726 KEY_RESERVED
, /* 0x16: MUTE */
2728 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2730 /* (assignments unknown, please report if found) */
2731 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2732 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2735 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2736 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2737 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2743 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2744 "initializing hotkey subdriver\n");
2746 BUG_ON(!tpacpi_inputdev
);
2747 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2748 tpacpi_inputdev
->close
!= NULL
);
2750 TPACPI_ACPIHANDLE_INIT(hkey
);
2751 mutex_init(&hotkey_mutex
);
2753 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2754 mutex_init(&hotkey_thread_mutex
);
2755 mutex_init(&hotkey_thread_data_mutex
);
2758 /* hotkey not supported on 570 */
2759 tp_features
.hotkey
= hkey_handle
!= NULL
;
2761 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2763 str_supported(tp_features
.hotkey
));
2765 if (!tp_features
.hotkey
)
2768 tpacpi_disable_brightness_delay();
2770 hotkey_dev_attributes
= create_attr_set(13, NULL
);
2771 if (!hotkey_dev_attributes
)
2773 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2775 ARRAY_SIZE(hotkey_attributes
));
2779 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2780 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2781 for HKEY interface version 0x100 */
2782 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2783 if ((hkeyv
>> 8) != 1) {
2784 printk(TPACPI_ERR
"unknown version of the "
2785 "HKEY interface: 0x%x\n", hkeyv
);
2786 printk(TPACPI_ERR
"please report this to %s\n",
2790 * MHKV 0x100 in A31, R40, R40e,
2791 * T4x, X31, and later
2793 tp_features
.hotkey_mask
= 1;
2794 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2795 "firmware HKEY interface version: 0x%x\n",
2800 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2801 "hotkey masks are %s\n",
2802 str_supported(tp_features
.hotkey_mask
));
2804 if (tp_features
.hotkey_mask
) {
2805 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2808 "missing MHKA handler, "
2809 "please report this to %s\n",
2811 /* FN+F12, FN+F4, FN+F3 */
2812 hotkey_all_mask
= 0x080cU
;
2816 /* hotkey_source_mask *must* be zero for
2817 * the first hotkey_mask_get */
2818 if (tp_features
.hotkey_mask
) {
2819 res
= hotkey_mask_get();
2823 hotkey_orig_mask
= hotkey_mask
;
2824 res
= add_many_to_attr_set(
2825 hotkey_dev_attributes
,
2826 hotkey_mask_attributes
,
2827 ARRAY_SIZE(hotkey_mask_attributes
));
2832 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2833 if (tp_features
.hotkey_mask
) {
2834 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2837 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2840 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2841 "hotkey source mask 0x%08x, polling freq %d\n",
2842 hotkey_source_mask
, hotkey_poll_freq
);
2845 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2847 tp_features
.hotkey_wlsw
= 1;
2849 "radio switch emulation enabled\n");
2852 /* Not all thinkpads have a hardware radio switch */
2853 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2854 tp_features
.hotkey_wlsw
= 1;
2856 "radio switch found; radios are %s\n",
2857 enabled(status
, 0));
2859 if (tp_features
.hotkey_wlsw
)
2860 res
= add_to_attr_set(hotkey_dev_attributes
,
2861 &dev_attr_hotkey_radio_sw
.attr
);
2863 /* For X41t, X60t, X61t Tablets... */
2864 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2865 tp_features
.hotkey_tablet
= 1;
2867 "possible tablet mode switch found; "
2868 "ThinkPad in %s mode\n",
2869 (status
& TP_HOTKEY_TABLET_MASK
)?
2870 "tablet" : "laptop");
2871 res
= add_to_attr_set(hotkey_dev_attributes
,
2872 &dev_attr_hotkey_tablet_mode
.attr
);
2876 res
= register_attr_set_with_sysfs(
2877 hotkey_dev_attributes
,
2878 &tpacpi_pdev
->dev
.kobj
);
2882 /* Set up key map */
2884 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2886 if (!hotkey_keycode_map
) {
2888 "failed to allocate memory for key map\n");
2893 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2894 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2895 "using Lenovo default hot key map\n");
2896 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2897 TPACPI_HOTKEY_MAP_SIZE
);
2899 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2900 "using IBM default hot key map\n");
2901 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2902 TPACPI_HOTKEY_MAP_SIZE
);
2905 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2906 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2907 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2908 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2909 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2910 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2911 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2912 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2913 set_bit(hotkey_keycode_map
[i
],
2914 tpacpi_inputdev
->keybit
);
2916 if (i
< sizeof(hotkey_reserved_mask
)*8)
2917 hotkey_reserved_mask
|= 1 << i
;
2921 if (tp_features
.hotkey_wlsw
) {
2922 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2923 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
2925 if (tp_features
.hotkey_tablet
) {
2926 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2927 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2930 /* Do not issue duplicate brightness change events to
2932 if (!tp_features
.bright_acpimode
)
2933 /* update bright_acpimode... */
2934 tpacpi_check_std_acpi_brightness_support();
2936 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
2938 "This ThinkPad has standard ACPI backlight "
2939 "brightness control, supported by the ACPI "
2941 printk(TPACPI_NOTICE
2942 "Disabling thinkpad-acpi brightness events "
2945 /* The hotkey_reserved_mask change below is not
2946 * necessary while the keys are at KEY_RESERVED in the
2947 * default map, but better safe than sorry, leave it
2948 * here as a marker of what we have to do, especially
2949 * when we finally become able to set this at runtime
2950 * on response to X.org requests */
2951 hotkey_reserved_mask
|=
2952 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
2953 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
2956 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2957 "enabling firmware HKEY event interface...\n");
2958 res
= hotkey_status_set(true);
2963 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2964 & ~hotkey_reserved_mask
)
2965 | hotkey_orig_mask
);
2966 if (res
< 0 && res
!= -ENXIO
) {
2971 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
2972 "legacy ibm/hotkey event reporting over procfs %s\n",
2973 (hotkey_report_mode
< 2) ?
2974 "enabled" : "disabled");
2976 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2977 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2979 hotkey_poll_setup_safe(1);
2980 tpacpi_send_radiosw_update();
2981 tpacpi_input_send_tabletsw();
2986 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2987 hotkey_dev_attributes
= NULL
;
2989 return (res
< 0)? res
: 1;
2992 static bool hotkey_notify_hotkey(const u32 hkey
,
2994 bool *ignore_acpi_ev
)
2996 /* 0x1000-0x1FFF: key presses */
2997 unsigned int scancode
= hkey
& 0xfff;
2998 *send_acpi_ev
= true;
2999 *ignore_acpi_ev
= false;
3001 if (scancode
> 0 && scancode
< 0x21) {
3003 if (!(hotkey_source_mask
& (1 << scancode
))) {
3004 tpacpi_input_send_key(scancode
);
3005 *send_acpi_ev
= false;
3007 *ignore_acpi_ev
= true;
3014 static bool hotkey_notify_wakeup(const u32 hkey
,
3016 bool *ignore_acpi_ev
)
3018 /* 0x2000-0x2FFF: Wakeup reason */
3019 *send_acpi_ev
= true;
3020 *ignore_acpi_ev
= false;
3023 case 0x2304: /* suspend, undock */
3024 case 0x2404: /* hibernation, undock */
3025 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3026 *ignore_acpi_ev
= true;
3029 case 0x2305: /* suspend, bay eject */
3030 case 0x2405: /* hibernation, bay eject */
3031 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3032 *ignore_acpi_ev
= true;
3035 case 0x2313: /* Battery on critical low level (S3) */
3036 case 0x2413: /* Battery on critical low level (S4) */
3038 "EMERGENCY WAKEUP: battery almost empty\n");
3039 /* how to auto-heal: */
3040 /* 2313: woke up from S3, go to S4/S5 */
3041 /* 2413: woke up from S4, go to S5 */
3048 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3050 "woke up due to a hot-unplug "
3052 hotkey_wakeup_reason_notify_change();
3057 static bool hotkey_notify_usrevent(const u32 hkey
,
3059 bool *ignore_acpi_ev
)
3061 /* 0x5000-0x5FFF: human interface helpers */
3062 *send_acpi_ev
= true;
3063 *ignore_acpi_ev
= false;
3066 case 0x5010: /* Lenovo new BIOS: brightness changed */
3067 case 0x500b: /* X61t: tablet pen inserted into bay */
3068 case 0x500c: /* X61t: tablet pen removed from bay */
3071 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
3072 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
3073 tpacpi_input_send_tabletsw();
3074 hotkey_tablet_mode_notify_change();
3075 *send_acpi_ev
= false;
3080 /* LID switch events. Do not propagate */
3081 *ignore_acpi_ev
= true;
3089 static bool hotkey_notify_thermal(const u32 hkey
,
3091 bool *ignore_acpi_ev
)
3093 /* 0x6000-0x6FFF: thermal alarms */
3094 *send_acpi_ev
= true;
3095 *ignore_acpi_ev
= false;
3100 "THERMAL ALARM: battery is too hot!\n");
3101 /* recommended action: warn user through gui */
3105 "THERMAL EMERGENCY: battery is extremely hot!\n");
3106 /* recommended action: immediate sleep/hibernate */
3111 "a sensor reports something is too hot!\n");
3112 /* recommended action: warn user through gui, that */
3113 /* some internal component is too hot */
3117 "THERMAL EMERGENCY: "
3118 "a sensor reports something is extremely hot!\n");
3119 /* recommended action: immediate sleep/hibernate */
3123 "EC reports that Thermal Table has changed\n");
3124 /* recommended action: do nothing, we don't have
3125 * Lenovo ATM information */
3129 "THERMAL ALERT: unknown thermal alarm received\n");
3134 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3138 bool ignore_acpi_ev
;
3141 if (event
!= 0x80) {
3143 "unknown HKEY notification event %d\n", event
);
3144 /* forward it to userspace, maybe it knows how to handle it */
3145 acpi_bus_generate_netlink_event(
3146 ibm
->acpi
->device
->pnp
.device_class
,
3147 dev_name(&ibm
->acpi
->device
->dev
),
3153 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3154 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3163 send_acpi_ev
= true;
3164 ignore_acpi_ev
= false;
3166 switch (hkey
>> 12) {
3168 /* 0x1000-0x1FFF: key presses */
3169 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3173 /* 0x2000-0x2FFF: Wakeup reason */
3174 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3178 /* 0x3000-0x3FFF: bay-related wakeups */
3179 if (hkey
== 0x3003) {
3180 hotkey_autosleep_ack
= 1;
3183 hotkey_wakeup_hotunplug_complete_notify_change();
3190 /* 0x4000-0x4FFF: dock-related wakeups */
3191 if (hkey
== 0x4003) {
3192 hotkey_autosleep_ack
= 1;
3195 hotkey_wakeup_hotunplug_complete_notify_change();
3202 /* 0x5000-0x5FFF: human interface helpers */
3203 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3207 /* 0x6000-0x6FFF: thermal alarms */
3208 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3212 /* 0x7000-0x7FFF: misc */
3213 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
3214 tpacpi_send_radiosw_update();
3219 /* fallthrough to default */
3224 printk(TPACPI_NOTICE
3225 "unhandled HKEY event 0x%04x\n", hkey
);
3226 printk(TPACPI_NOTICE
3227 "please report the conditions when this "
3228 "event happened to %s\n", TPACPI_MAIL
);
3232 if (!ignore_acpi_ev
&&
3233 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3234 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3238 /* netlink events */
3239 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3240 acpi_bus_generate_netlink_event(
3241 ibm
->acpi
->device
->pnp
.device_class
,
3242 dev_name(&ibm
->acpi
->device
->dev
),
3248 static void hotkey_suspend(pm_message_t state
)
3250 /* Do these on suspend, we get the events on early resume! */
3251 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3252 hotkey_autosleep_ack
= 0;
3255 static void hotkey_resume(void)
3257 tpacpi_disable_brightness_delay();
3259 if (hotkey_mask_get())
3261 "error while trying to read hot key mask "
3263 tpacpi_send_radiosw_update();
3264 hotkey_tablet_mode_notify_change();
3265 hotkey_wakeup_reason_notify_change();
3266 hotkey_wakeup_hotunplug_complete_notify_change();
3267 hotkey_poll_setup_safe(0);
3270 /* procfs -------------------------------------------------------------- */
3271 static int hotkey_read(char *p
)
3276 if (!tp_features
.hotkey
) {
3277 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3281 if (mutex_lock_killable(&hotkey_mutex
))
3282 return -ERESTARTSYS
;
3283 res
= hotkey_status_get(&status
);
3285 res
= hotkey_mask_get();
3286 mutex_unlock(&hotkey_mutex
);
3290 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
3291 if (tp_features
.hotkey_mask
) {
3292 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
3293 len
+= sprintf(p
+ len
,
3294 "commands:\tenable, disable, reset, <mask>\n");
3296 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
3297 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
3303 static void hotkey_enabledisable_warn(bool enable
)
3305 tpacpi_log_usertask("procfs hotkey enable/disable");
3306 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3308 "hotkey enable/disable functionality has been "
3309 "removed from the driver. Hotkeys are always "
3312 "Please remove the hotkey=enable module "
3313 "parameter, it is deprecated. Hotkeys are always "
3317 static int hotkey_write(char *buf
)
3323 if (!tp_features
.hotkey
)
3326 if (mutex_lock_killable(&hotkey_mutex
))
3327 return -ERESTARTSYS
;
3332 while ((cmd
= next_cmd(&buf
))) {
3333 if (strlencmp(cmd
, "enable") == 0) {
3334 hotkey_enabledisable_warn(1);
3335 } else if (strlencmp(cmd
, "disable") == 0) {
3336 hotkey_enabledisable_warn(0);
3338 } else if (strlencmp(cmd
, "reset") == 0) {
3339 mask
= hotkey_orig_mask
;
3340 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3342 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3351 tpacpi_disclose_usertask("procfs hotkey",
3352 "set mask to 0x%08x\n", mask
);
3354 if (!res
&& mask
!= hotkey_mask
)
3355 res
= hotkey_mask_set(mask
);
3358 mutex_unlock(&hotkey_mutex
);
3362 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3363 {TPACPI_ACPI_HKEY_HID
, 0},
3367 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3368 .hid
= ibm_htk_device_ids
,
3369 .notify
= hotkey_notify
,
3370 .handle
= &hkey_handle
,
3371 .type
= ACPI_DEVICE_NOTIFY
,
3374 static struct ibm_struct hotkey_driver_data
= {
3376 .read
= hotkey_read
,
3377 .write
= hotkey_write
,
3378 .exit
= hotkey_exit
,
3379 .resume
= hotkey_resume
,
3380 .suspend
= hotkey_suspend
,
3381 .acpi
= &ibm_hotkey_acpidriver
,
3384 /*************************************************************************
3385 * Bluetooth subdriver
3389 /* ACPI GBDC/SBDC bits */
3390 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3391 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3392 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3397 /* ACPI \BLTH commands */
3398 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3399 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3400 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3401 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3402 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3405 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3407 static void bluetooth_suspend(pm_message_t state
)
3409 /* Try to make sure radio will resume powered off */
3410 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3411 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
))
3412 vdbg_printk(TPACPI_DBG_RFKILL
,
3413 "bluetooth power down on resume request failed\n");
3416 static int bluetooth_get_status(void)
3420 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3421 if (dbg_bluetoothemul
)
3422 return (tpacpi_bluetooth_emulstate
) ?
3423 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3426 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3429 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3430 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3433 static int bluetooth_set_status(enum tpacpi_rfkill_state state
)
3437 vdbg_printk(TPACPI_DBG_RFKILL
,
3438 "will attempt to %s bluetooth\n",
3439 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
3441 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3442 if (dbg_bluetoothemul
) {
3443 tpacpi_bluetooth_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
3448 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3449 if (state
== TPACPI_RFK_RADIO_ON
)
3450 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
3454 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3460 /* sysfs bluetooth enable ---------------------------------------------- */
3461 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3462 struct device_attribute
*attr
,
3465 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID
,
3469 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3470 struct device_attribute
*attr
,
3471 const char *buf
, size_t count
)
3473 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID
,
3477 static struct device_attribute dev_attr_bluetooth_enable
=
3478 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3479 bluetooth_enable_show
, bluetooth_enable_store
);
3481 /* --------------------------------------------------------------------- */
3483 static struct attribute
*bluetooth_attributes
[] = {
3484 &dev_attr_bluetooth_enable
.attr
,
3488 static const struct attribute_group bluetooth_attr_group
= {
3489 .attrs
= bluetooth_attributes
,
3492 static const struct tpacpi_rfk_ops bluetooth_tprfk_ops
= {
3493 .get_status
= bluetooth_get_status
,
3494 .set_status
= bluetooth_set_status
,
3497 static void bluetooth_shutdown(void)
3499 /* Order firmware to save current state to NVRAM */
3500 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3501 TP_ACPI_BLTH_SAVE_STATE
))
3502 printk(TPACPI_NOTICE
3503 "failed to save bluetooth state to NVRAM\n");
3505 vdbg_printk(TPACPI_DBG_RFKILL
,
3506 "bluestooth state saved to NVRAM\n");
3509 static void bluetooth_exit(void)
3511 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3512 &bluetooth_attr_group
);
3514 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
3516 bluetooth_shutdown();
3519 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3524 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3525 "initializing bluetooth subdriver\n");
3527 TPACPI_ACPIHANDLE_INIT(hkey
);
3529 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3530 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3531 tp_features
.bluetooth
= hkey_handle
&&
3532 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3534 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3535 "bluetooth is %s, status 0x%02x\n",
3536 str_supported(tp_features
.bluetooth
),
3539 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3540 if (dbg_bluetoothemul
) {
3541 tp_features
.bluetooth
= 1;
3543 "bluetooth switch emulation enabled\n");
3546 if (tp_features
.bluetooth
&&
3547 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
3548 /* no bluetooth hardware present in system */
3549 tp_features
.bluetooth
= 0;
3550 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3551 "bluetooth hardware not installed\n");
3554 if (!tp_features
.bluetooth
)
3557 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
3558 &bluetooth_tprfk_ops
,
3559 RFKILL_TYPE_BLUETOOTH
,
3560 TPACPI_RFK_BLUETOOTH_SW_NAME
,
3565 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3566 &bluetooth_attr_group
);
3568 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
3575 /* procfs -------------------------------------------------------------- */
3576 static int bluetooth_read(char *p
)
3578 return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID
, p
);
3581 static int bluetooth_write(char *buf
)
3583 return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID
, buf
);
3586 static struct ibm_struct bluetooth_driver_data
= {
3587 .name
= "bluetooth",
3588 .read
= bluetooth_read
,
3589 .write
= bluetooth_write
,
3590 .exit
= bluetooth_exit
,
3591 .suspend
= bluetooth_suspend
,
3592 .shutdown
= bluetooth_shutdown
,
3595 /*************************************************************************
3600 /* ACPI GWAN/SWAN bits */
3601 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3602 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3603 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
3607 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
3609 static void wan_suspend(pm_message_t state
)
3611 /* Try to make sure radio will resume powered off */
3612 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
3613 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
))
3614 vdbg_printk(TPACPI_DBG_RFKILL
,
3615 "WWAN power down on resume request failed\n");
3618 static int wan_get_status(void)
3622 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3624 return (tpacpi_wwan_emulstate
) ?
3625 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3628 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3631 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3632 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3635 static int wan_set_status(enum tpacpi_rfkill_state state
)
3639 vdbg_printk(TPACPI_DBG_RFKILL
,
3640 "will attempt to %s wwan\n",
3641 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
3643 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3645 tpacpi_wwan_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
3650 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3651 if (state
== TPACPI_RFK_RADIO_ON
)
3652 status
= TP_ACPI_WANCARD_RADIOSSW
;
3656 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3662 /* sysfs wan enable ---------------------------------------------------- */
3663 static ssize_t
wan_enable_show(struct device
*dev
,
3664 struct device_attribute
*attr
,
3667 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID
,
3671 static ssize_t
wan_enable_store(struct device
*dev
,
3672 struct device_attribute
*attr
,
3673 const char *buf
, size_t count
)
3675 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID
,
3679 static struct device_attribute dev_attr_wan_enable
=
3680 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
3681 wan_enable_show
, wan_enable_store
);
3683 /* --------------------------------------------------------------------- */
3685 static struct attribute
*wan_attributes
[] = {
3686 &dev_attr_wan_enable
.attr
,
3690 static const struct attribute_group wan_attr_group
= {
3691 .attrs
= wan_attributes
,
3694 static const struct tpacpi_rfk_ops wan_tprfk_ops
= {
3695 .get_status
= wan_get_status
,
3696 .set_status
= wan_set_status
,
3699 static void wan_shutdown(void)
3701 /* Order firmware to save current state to NVRAM */
3702 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
3703 TP_ACPI_WGSV_SAVE_STATE
))
3704 printk(TPACPI_NOTICE
3705 "failed to save WWAN state to NVRAM\n");
3707 vdbg_printk(TPACPI_DBG_RFKILL
,
3708 "WWAN state saved to NVRAM\n");
3711 static void wan_exit(void)
3713 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3716 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
3721 static int __init
wan_init(struct ibm_init_struct
*iibm
)
3726 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3727 "initializing wan subdriver\n");
3729 TPACPI_ACPIHANDLE_INIT(hkey
);
3731 tp_features
.wan
= hkey_handle
&&
3732 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
3734 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3735 "wan is %s, status 0x%02x\n",
3736 str_supported(tp_features
.wan
),
3739 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3741 tp_features
.wan
= 1;
3743 "wwan switch emulation enabled\n");
3746 if (tp_features
.wan
&&
3747 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
3748 /* no wan hardware present in system */
3749 tp_features
.wan
= 0;
3750 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3751 "wan hardware not installed\n");
3754 if (!tp_features
.wan
)
3757 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
3760 TPACPI_RFK_WWAN_SW_NAME
,
3765 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3769 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
3776 /* procfs -------------------------------------------------------------- */
3777 static int wan_read(char *p
)
3779 return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID
, p
);
3782 static int wan_write(char *buf
)
3784 return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID
, buf
);
3787 static struct ibm_struct wan_driver_data
= {
3792 .suspend
= wan_suspend
,
3793 .shutdown
= wan_shutdown
,
3796 /*************************************************************************
3801 /* ACPI GUWB/SUWB bits */
3802 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
3803 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
3806 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
3808 static int uwb_get_status(void)
3812 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3814 return (tpacpi_uwb_emulstate
) ?
3815 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3818 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
3821 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
3822 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3825 static int uwb_set_status(enum tpacpi_rfkill_state state
)
3829 vdbg_printk(TPACPI_DBG_RFKILL
,
3830 "will attempt to %s UWB\n",
3831 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
3833 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3835 tpacpi_uwb_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
3840 if (state
== TPACPI_RFK_RADIO_ON
)
3841 status
= TP_ACPI_UWB_RADIOSSW
;
3845 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
3851 /* --------------------------------------------------------------------- */
3853 static const struct tpacpi_rfk_ops uwb_tprfk_ops
= {
3854 .get_status
= uwb_get_status
,
3855 .set_status
= uwb_set_status
,
3858 static void uwb_exit(void)
3860 tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID
);
3863 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
3868 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3869 "initializing uwb subdriver\n");
3871 TPACPI_ACPIHANDLE_INIT(hkey
);
3873 tp_features
.uwb
= hkey_handle
&&
3874 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
3876 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3877 "uwb is %s, status 0x%02x\n",
3878 str_supported(tp_features
.uwb
),
3881 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3883 tp_features
.uwb
= 1;
3885 "uwb switch emulation enabled\n");
3888 if (tp_features
.uwb
&&
3889 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
3890 /* no uwb hardware present in system */
3891 tp_features
.uwb
= 0;
3892 dbg_printk(TPACPI_DBG_INIT
,
3893 "uwb hardware not installed\n");
3896 if (!tp_features
.uwb
)
3899 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
3902 TPACPI_RFK_UWB_SW_NAME
,
3907 static struct ibm_struct uwb_driver_data
= {
3910 .flags
.experimental
= 1,
3913 /*************************************************************************
3917 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
3919 enum video_access_mode
{
3920 TPACPI_VIDEO_NONE
= 0,
3921 TPACPI_VIDEO_570
, /* 570 */
3922 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
3923 TPACPI_VIDEO_NEW
, /* all others */
3926 enum { /* video status flags, based on VIDEO_570 */
3927 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
3928 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
3929 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
3932 enum { /* TPACPI_VIDEO_570 constants */
3933 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
3934 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
3935 * video_status_flags */
3936 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
3937 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
3940 static enum video_access_mode video_supported
;
3941 static int video_orig_autosw
;
3943 static int video_autosw_get(void);
3944 static int video_autosw_set(int enable
);
3946 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
3948 static int __init
video_init(struct ibm_init_struct
*iibm
)
3952 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
3954 TPACPI_ACPIHANDLE_INIT(vid
);
3955 TPACPI_ACPIHANDLE_INIT(vid2
);
3957 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
3958 /* G41, assume IVGA doesn't change */
3959 vid_handle
= vid2_handle
;
3962 /* video switching not supported on R30, R31 */
3963 video_supported
= TPACPI_VIDEO_NONE
;
3964 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
3966 video_supported
= TPACPI_VIDEO_570
;
3967 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
3968 /* 600e/x, 770e, 770x */
3969 video_supported
= TPACPI_VIDEO_770
;
3972 video_supported
= TPACPI_VIDEO_NEW
;
3974 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
3975 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
3978 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
3981 static void video_exit(void)
3983 dbg_printk(TPACPI_DBG_EXIT
,
3984 "restoring original video autoswitch mode\n");
3985 if (video_autosw_set(video_orig_autosw
))
3986 printk(TPACPI_ERR
"error while trying to restore original "
3987 "video autoswitch mode\n");
3990 static int video_outputsw_get(void)
3995 switch (video_supported
) {
3996 case TPACPI_VIDEO_570
:
3997 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
3998 TP_ACPI_VIDEO_570_PHSCMD
))
4000 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4002 case TPACPI_VIDEO_770
:
4003 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4006 status
|= TP_ACPI_VIDEO_S_LCD
;
4007 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4010 status
|= TP_ACPI_VIDEO_S_CRT
;
4012 case TPACPI_VIDEO_NEW
:
4013 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4014 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4017 status
|= TP_ACPI_VIDEO_S_CRT
;
4019 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4020 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4023 status
|= TP_ACPI_VIDEO_S_LCD
;
4024 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4027 status
|= TP_ACPI_VIDEO_S_DVI
;
4036 static int video_outputsw_set(int status
)
4041 switch (video_supported
) {
4042 case TPACPI_VIDEO_570
:
4043 res
= acpi_evalf(NULL
, NULL
,
4044 "\\_SB.PHS2", "vdd",
4045 TP_ACPI_VIDEO_570_PHS2CMD
,
4046 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4048 case TPACPI_VIDEO_770
:
4049 autosw
= video_autosw_get();
4053 res
= video_autosw_set(1);
4056 res
= acpi_evalf(vid_handle
, NULL
,
4057 "ASWT", "vdd", status
* 0x100, 0);
4058 if (!autosw
&& video_autosw_set(autosw
)) {
4060 "video auto-switch left enabled due to error\n");
4064 case TPACPI_VIDEO_NEW
:
4065 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4066 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4072 return (res
)? 0 : -EIO
;
4075 static int video_autosw_get(void)
4079 switch (video_supported
) {
4080 case TPACPI_VIDEO_570
:
4081 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4084 case TPACPI_VIDEO_770
:
4085 case TPACPI_VIDEO_NEW
:
4086 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4096 static int video_autosw_set(int enable
)
4098 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4103 static int video_outputsw_cycle(void)
4105 int autosw
= video_autosw_get();
4111 switch (video_supported
) {
4112 case TPACPI_VIDEO_570
:
4113 res
= video_autosw_set(1);
4116 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4118 case TPACPI_VIDEO_770
:
4119 case TPACPI_VIDEO_NEW
:
4120 res
= video_autosw_set(1);
4123 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4128 if (!autosw
&& video_autosw_set(autosw
)) {
4130 "video auto-switch left enabled due to error\n");
4134 return (res
)? 0 : -EIO
;
4137 static int video_expand_toggle(void)
4139 switch (video_supported
) {
4140 case TPACPI_VIDEO_570
:
4141 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4143 case TPACPI_VIDEO_770
:
4144 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4146 case TPACPI_VIDEO_NEW
:
4147 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4155 static int video_read(char *p
)
4160 if (video_supported
== TPACPI_VIDEO_NONE
) {
4161 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4165 status
= video_outputsw_get();
4169 autosw
= video_autosw_get();
4173 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4174 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
4175 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
4176 if (video_supported
== TPACPI_VIDEO_NEW
)
4177 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
4178 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
4179 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
4180 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
4181 if (video_supported
== TPACPI_VIDEO_NEW
)
4182 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
4183 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
4184 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
4189 static int video_write(char *buf
)
4192 int enable
, disable
, status
;
4195 if (video_supported
== TPACPI_VIDEO_NONE
)
4201 while ((cmd
= next_cmd(&buf
))) {
4202 if (strlencmp(cmd
, "lcd_enable") == 0) {
4203 enable
|= TP_ACPI_VIDEO_S_LCD
;
4204 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4205 disable
|= TP_ACPI_VIDEO_S_LCD
;
4206 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4207 enable
|= TP_ACPI_VIDEO_S_CRT
;
4208 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4209 disable
|= TP_ACPI_VIDEO_S_CRT
;
4210 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4211 strlencmp(cmd
, "dvi_enable") == 0) {
4212 enable
|= TP_ACPI_VIDEO_S_DVI
;
4213 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4214 strlencmp(cmd
, "dvi_disable") == 0) {
4215 disable
|= TP_ACPI_VIDEO_S_DVI
;
4216 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4217 res
= video_autosw_set(1);
4220 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4221 res
= video_autosw_set(0);
4224 } else if (strlencmp(cmd
, "video_switch") == 0) {
4225 res
= video_outputsw_cycle();
4228 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4229 res
= video_expand_toggle();
4236 if (enable
|| disable
) {
4237 status
= video_outputsw_get();
4240 res
= video_outputsw_set((status
& ~disable
) | enable
);
4248 static struct ibm_struct video_driver_data
= {
4251 .write
= video_write
,
4255 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4257 /*************************************************************************
4258 * Light (thinklight) subdriver
4261 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4262 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4264 static int light_get_status(void)
4268 if (tp_features
.light_status
) {
4269 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4277 static int light_set_status(int status
)
4281 if (tp_features
.light
) {
4283 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4285 TP_CMOS_THINKLIGHT_ON
:
4286 TP_CMOS_THINKLIGHT_OFF
);
4288 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4291 return (rc
)? 0 : -EIO
;
4297 static void light_set_status_worker(struct work_struct
*work
)
4299 struct tpacpi_led_classdev
*data
=
4300 container_of(work
, struct tpacpi_led_classdev
, work
);
4302 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4303 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4306 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4307 enum led_brightness brightness
)
4309 struct tpacpi_led_classdev
*data
=
4310 container_of(led_cdev
,
4311 struct tpacpi_led_classdev
,
4313 data
->new_state
= (brightness
!= LED_OFF
) ?
4314 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4315 queue_work(tpacpi_wq
, &data
->work
);
4318 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4320 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4323 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4325 .name
= "tpacpi::thinklight",
4326 .brightness_set
= &light_sysfs_set
,
4327 .brightness_get
= &light_sysfs_get
,
4331 static int __init
light_init(struct ibm_init_struct
*iibm
)
4335 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4337 TPACPI_ACPIHANDLE_INIT(ledb
);
4338 TPACPI_ACPIHANDLE_INIT(lght
);
4339 TPACPI_ACPIHANDLE_INIT(cmos
);
4340 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4342 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4343 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4345 if (tp_features
.light
)
4346 /* light status not supported on
4347 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4348 tp_features
.light_status
=
4349 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4351 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4352 str_supported(tp_features
.light
),
4353 str_supported(tp_features
.light_status
));
4355 if (!tp_features
.light
)
4358 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4359 &tpacpi_led_thinklight
.led_classdev
);
4362 tp_features
.light
= 0;
4363 tp_features
.light_status
= 0;
4371 static void light_exit(void)
4373 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4374 if (work_pending(&tpacpi_led_thinklight
.work
))
4375 flush_workqueue(tpacpi_wq
);
4378 static int light_read(char *p
)
4383 if (!tp_features
.light
) {
4384 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4385 } else if (!tp_features
.light_status
) {
4386 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
4387 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4389 status
= light_get_status();
4392 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
4393 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4399 static int light_write(char *buf
)
4404 if (!tp_features
.light
)
4407 while ((cmd
= next_cmd(&buf
))) {
4408 if (strlencmp(cmd
, "on") == 0) {
4410 } else if (strlencmp(cmd
, "off") == 0) {
4416 return light_set_status(newstatus
);
4419 static struct ibm_struct light_driver_data
= {
4422 .write
= light_write
,
4426 /*************************************************************************
4430 /* sysfs cmos_command -------------------------------------------------- */
4431 static ssize_t
cmos_command_store(struct device
*dev
,
4432 struct device_attribute
*attr
,
4433 const char *buf
, size_t count
)
4435 unsigned long cmos_cmd
;
4438 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4441 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4442 return (res
)? res
: count
;
4445 static struct device_attribute dev_attr_cmos_command
=
4446 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4448 /* --------------------------------------------------------------------- */
4450 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4454 vdbg_printk(TPACPI_DBG_INIT
,
4455 "initializing cmos commands subdriver\n");
4457 TPACPI_ACPIHANDLE_INIT(cmos
);
4459 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4460 str_supported(cmos_handle
!= NULL
));
4462 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4466 return (cmos_handle
)? 0 : 1;
4469 static void cmos_exit(void)
4471 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4474 static int cmos_read(char *p
)
4478 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4479 R30, R31, T20-22, X20-21 */
4481 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4483 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4484 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4490 static int cmos_write(char *buf
)
4495 while ((cmd
= next_cmd(&buf
))) {
4496 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4497 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4502 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4510 static struct ibm_struct cmos_driver_data
= {
4513 .write
= cmos_write
,
4517 /*************************************************************************
4521 enum led_access_mode
{
4522 TPACPI_LED_NONE
= 0,
4523 TPACPI_LED_570
, /* 570 */
4524 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4525 TPACPI_LED_NEW
, /* all others */
4528 enum { /* For TPACPI_LED_OLD */
4529 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4530 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4531 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4534 static enum led_access_mode led_supported
;
4536 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4537 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4538 /* T20-22, X20-21 */
4539 "LED", /* all others */
4542 #define TPACPI_LED_NUMLEDS 16
4543 static struct tpacpi_led_classdev
*tpacpi_leds
;
4544 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4545 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4546 /* there's a limit of 19 chars + NULL before 2.6.26 */
4548 "tpacpi:orange:batt",
4549 "tpacpi:green:batt",
4550 "tpacpi::dock_active",
4551 "tpacpi::bay_active",
4552 "tpacpi::dock_batt",
4553 "tpacpi::unknown_led",
4555 "tpacpi::dock_status1",
4556 "tpacpi::dock_status2",
4557 "tpacpi::unknown_led2",
4558 "tpacpi::unknown_led3",
4559 "tpacpi::thinkvantage",
4561 #define TPACPI_SAFE_LEDS 0x1081U
4563 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
4565 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
4568 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
4572 static int led_get_status(const unsigned int led
)
4575 enum led_status_t led_s
;
4577 switch (led_supported
) {
4578 case TPACPI_LED_570
:
4579 if (!acpi_evalf(ec_handle
,
4580 &status
, "GLED", "dd", 1 << led
))
4582 led_s
= (status
== 0)?
4587 tpacpi_led_state_cache
[led
] = led_s
;
4596 static int led_set_status(const unsigned int led
,
4597 const enum led_status_t ledstatus
)
4599 /* off, on, blink. Index is led_status_t */
4600 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
4601 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
4605 switch (led_supported
) {
4606 case TPACPI_LED_570
:
4608 if (unlikely(led
> 7))
4610 if (unlikely(tpacpi_is_led_restricted(led
)))
4612 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4613 (1 << led
), led_sled_arg1
[ledstatus
]))
4616 case TPACPI_LED_OLD
:
4617 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4618 if (unlikely(led
> 7))
4620 if (unlikely(tpacpi_is_led_restricted(led
)))
4622 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
4624 rc
= ec_write(TPACPI_LED_EC_HLBL
,
4625 (ledstatus
== TPACPI_LED_BLINK
) << led
);
4627 rc
= ec_write(TPACPI_LED_EC_HLCL
,
4628 (ledstatus
!= TPACPI_LED_OFF
) << led
);
4630 case TPACPI_LED_NEW
:
4632 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
4634 if (unlikely(tpacpi_is_led_restricted(led
)))
4636 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4637 led
, led_led_arg1
[ledstatus
]))
4645 tpacpi_led_state_cache
[led
] = ledstatus
;
4650 static void led_set_status_worker(struct work_struct
*work
)
4652 struct tpacpi_led_classdev
*data
=
4653 container_of(work
, struct tpacpi_led_classdev
, work
);
4655 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4656 led_set_status(data
->led
, data
->new_state
);
4659 static void led_sysfs_set(struct led_classdev
*led_cdev
,
4660 enum led_brightness brightness
)
4662 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4663 struct tpacpi_led_classdev
, led_classdev
);
4665 if (brightness
== LED_OFF
)
4666 data
->new_state
= TPACPI_LED_OFF
;
4667 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
4668 data
->new_state
= TPACPI_LED_ON
;
4670 data
->new_state
= TPACPI_LED_BLINK
;
4672 queue_work(tpacpi_wq
, &data
->work
);
4675 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
4676 unsigned long *delay_on
, unsigned long *delay_off
)
4678 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4679 struct tpacpi_led_classdev
, led_classdev
);
4681 /* Can we choose the flash rate? */
4682 if (*delay_on
== 0 && *delay_off
== 0) {
4683 /* yes. set them to the hardware blink rate (1 Hz) */
4684 *delay_on
= 500; /* ms */
4685 *delay_off
= 500; /* ms */
4686 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
4689 data
->new_state
= TPACPI_LED_BLINK
;
4690 queue_work(tpacpi_wq
, &data
->work
);
4695 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
4699 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4700 struct tpacpi_led_classdev
, led_classdev
);
4702 rc
= led_get_status(data
->led
);
4704 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
4705 rc
= LED_OFF
; /* no error handling in led class :( */
4712 static void led_exit(void)
4716 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4717 if (tpacpi_leds
[i
].led_classdev
.name
)
4718 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
4724 static int __init
tpacpi_init_led(unsigned int led
)
4728 tpacpi_leds
[led
].led
= led
;
4730 /* LEDs with no name don't get registered */
4731 if (!tpacpi_led_names
[led
])
4734 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
4735 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
4736 if (led_supported
== TPACPI_LED_570
)
4737 tpacpi_leds
[led
].led_classdev
.brightness_get
=
4740 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
4742 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
4744 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4745 &tpacpi_leds
[led
].led_classdev
);
4747 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
4752 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
4753 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
4754 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
4755 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
4757 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
4758 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
4759 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
4760 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
4761 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
4762 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
4763 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
4764 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
4766 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
4767 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
4768 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
4769 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
4770 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
4772 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
4773 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
4774 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
4775 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
4777 /* (1) - may have excess leds enabled on MSB */
4779 /* Defaults (order matters, keep last, don't reorder!) */
4781 .vendor
= PCI_VENDOR_ID_LENOVO
,
4782 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
4785 { /* IBM ThinkPads with no EC version string */
4786 .vendor
= PCI_VENDOR_ID_IBM
,
4787 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
4790 { /* IBM ThinkPads with EC version string */
4791 .vendor
= PCI_VENDOR_ID_IBM
,
4792 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
4797 #undef TPACPI_LEDQ_IBM
4798 #undef TPACPI_LEDQ_LNV
4800 static int __init
led_init(struct ibm_init_struct
*iibm
)
4804 unsigned long useful_leds
;
4806 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
4808 TPACPI_ACPIHANDLE_INIT(led
);
4811 /* led not supported on R30, R31 */
4812 led_supported
= TPACPI_LED_NONE
;
4813 else if (strlencmp(led_path
, "SLED") == 0)
4815 led_supported
= TPACPI_LED_570
;
4816 else if (strlencmp(led_path
, "SYSL") == 0)
4817 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4818 led_supported
= TPACPI_LED_OLD
;
4821 led_supported
= TPACPI_LED_NEW
;
4823 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
4824 str_supported(led_supported
), led_supported
);
4826 if (led_supported
== TPACPI_LED_NONE
)
4829 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
4832 printk(TPACPI_ERR
"Out of memory for LED data\n");
4836 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
4837 ARRAY_SIZE(led_useful_qtable
));
4839 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4840 if (!tpacpi_is_led_restricted(i
) &&
4841 test_bit(i
, &useful_leds
)) {
4842 rc
= tpacpi_init_led(i
);
4850 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
4851 printk(TPACPI_NOTICE
4852 "warning: userspace override of important "
4853 "firmware LEDs is enabled\n");
4858 #define str_led_status(s) \
4859 ((s) == TPACPI_LED_OFF ? "off" : \
4860 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
4862 static int led_read(char *p
)
4866 if (!led_supported
) {
4867 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4870 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4872 if (led_supported
== TPACPI_LED_570
) {
4875 for (i
= 0; i
< 8; i
++) {
4876 status
= led_get_status(i
);
4879 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
4880 i
, str_led_status(status
));
4884 len
+= sprintf(p
+ len
, "commands:\t"
4885 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
4890 static int led_write(char *buf
)
4894 enum led_status_t s
;
4899 while ((cmd
= next_cmd(&buf
))) {
4900 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
4903 if (strstr(cmd
, "off")) {
4905 } else if (strstr(cmd
, "on")) {
4907 } else if (strstr(cmd
, "blink")) {
4908 s
= TPACPI_LED_BLINK
;
4913 rc
= led_set_status(led
, s
);
4921 static struct ibm_struct led_driver_data
= {
4928 /*************************************************************************
4932 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
4934 #define TPACPI_BEEP_Q1 0x0001
4936 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
4937 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
4938 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
4941 static int __init
beep_init(struct ibm_init_struct
*iibm
)
4943 unsigned long quirks
;
4945 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
4947 TPACPI_ACPIHANDLE_INIT(beep
);
4949 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
4950 str_supported(beep_handle
!= NULL
));
4952 quirks
= tpacpi_check_quirks(beep_quirk_table
,
4953 ARRAY_SIZE(beep_quirk_table
));
4955 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
4957 return (beep_handle
)? 0 : 1;
4960 static int beep_read(char *p
)
4965 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4967 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4968 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
4974 static int beep_write(char *buf
)
4982 while ((cmd
= next_cmd(&buf
))) {
4983 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
4984 beep_cmd
>= 0 && beep_cmd
<= 17) {
4988 if (tp_features
.beep_needs_two_args
) {
4989 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
4993 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5002 static struct ibm_struct beep_driver_data
= {
5005 .write
= beep_write
,
5008 /*************************************************************************
5012 enum thermal_access_mode
{
5013 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5014 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5015 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5016 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5017 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5020 enum { /* TPACPI_THERMAL_TPEC_* */
5021 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5022 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5023 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5026 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5027 struct ibm_thermal_sensors_struct
{
5028 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5031 static enum thermal_access_mode thermal_read_mode
;
5033 /* idx is zero-based */
5034 static int thermal_get_sensor(int idx
, s32
*value
)
5040 t
= TP_EC_THERMAL_TMP0
;
5042 switch (thermal_read_mode
) {
5043 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5044 case TPACPI_THERMAL_TPEC_16
:
5045 if (idx
>= 8 && idx
<= 15) {
5046 t
= TP_EC_THERMAL_TMP8
;
5051 case TPACPI_THERMAL_TPEC_8
:
5053 if (!acpi_ec_read(t
+ idx
, &tmp
))
5055 *value
= tmp
* 1000;
5060 case TPACPI_THERMAL_ACPI_UPDT
:
5062 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5063 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5065 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5067 *value
= (t
- 2732) * 100;
5072 case TPACPI_THERMAL_ACPI_TMP07
:
5074 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5075 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5077 if (t
> 127 || t
< -127)
5078 t
= TP_EC_THERMAL_TMP_NA
;
5084 case TPACPI_THERMAL_NONE
:
5092 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5103 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5106 for (i
= 0 ; i
< n
; i
++) {
5107 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5115 /* sysfs temp##_input -------------------------------------------------- */
5117 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5118 struct device_attribute
*attr
,
5121 struct sensor_device_attribute
*sensor_attr
=
5122 to_sensor_dev_attr(attr
);
5123 int idx
= sensor_attr
->index
;
5127 res
= thermal_get_sensor(idx
, &value
);
5130 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
5133 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5136 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5137 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5138 thermal_temp_input_show, NULL, _idxB)
5140 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5141 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5142 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5143 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5144 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5145 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5146 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5147 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5148 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5149 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5150 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5151 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5152 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5153 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5154 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5155 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5156 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5159 #define THERMAL_ATTRS(X) \
5160 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5162 static struct attribute
*thermal_temp_input_attr
[] = {
5182 static const struct attribute_group thermal_temp_input16_group
= {
5183 .attrs
= thermal_temp_input_attr
5186 static const struct attribute_group thermal_temp_input8_group
= {
5187 .attrs
= &thermal_temp_input_attr
[8]
5190 #undef THERMAL_SENSOR_ATTR_TEMP
5191 #undef THERMAL_ATTRS
5193 /* --------------------------------------------------------------------- */
5195 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5202 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5204 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5206 if (thinkpad_id
.ec_model
) {
5208 * Direct EC access mode: sensors at registers
5209 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5210 * non-implemented, thermal sensors return 0x80 when
5215 for (i
= 0; i
< 8; i
++) {
5216 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5222 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5230 /* This is sheer paranoia, but we handle it anyway */
5233 "ThinkPad ACPI EC access misbehaving, "
5234 "falling back to ACPI TMPx access "
5236 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5239 "ThinkPad ACPI EC access misbehaving, "
5240 "disabling thermal sensors access\n");
5241 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5246 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5248 } else if (acpi_tmp7
) {
5249 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5250 /* 600e/x, 770e, 770x */
5251 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5253 /* Standard ACPI TMPx access, max 8 sensors */
5254 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5257 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5258 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5261 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5262 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5265 switch (thermal_read_mode
) {
5266 case TPACPI_THERMAL_TPEC_16
:
5267 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5268 &thermal_temp_input16_group
);
5272 case TPACPI_THERMAL_TPEC_8
:
5273 case TPACPI_THERMAL_ACPI_TMP07
:
5274 case TPACPI_THERMAL_ACPI_UPDT
:
5275 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5276 &thermal_temp_input8_group
);
5280 case TPACPI_THERMAL_NONE
:
5288 static void thermal_exit(void)
5290 switch (thermal_read_mode
) {
5291 case TPACPI_THERMAL_TPEC_16
:
5292 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5293 &thermal_temp_input16_group
);
5295 case TPACPI_THERMAL_TPEC_8
:
5296 case TPACPI_THERMAL_ACPI_TMP07
:
5297 case TPACPI_THERMAL_ACPI_UPDT
:
5298 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5299 &thermal_temp_input16_group
);
5301 case TPACPI_THERMAL_NONE
:
5307 static int thermal_read(char *p
)
5311 struct ibm_thermal_sensors_struct t
;
5313 n
= thermal_get_sensors(&t
);
5314 if (unlikely(n
< 0))
5317 len
+= sprintf(p
+ len
, "temperatures:\t");
5320 for (i
= 0; i
< (n
- 1); i
++)
5321 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
5322 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
5324 len
+= sprintf(p
+ len
, "not supported\n");
5329 static struct ibm_struct thermal_driver_data
= {
5331 .read
= thermal_read
,
5332 .exit
= thermal_exit
,
5335 /*************************************************************************
5339 static u8 ecdump_regs
[256];
5341 static int ecdump_read(char *p
)
5347 len
+= sprintf(p
+ len
, "EC "
5348 " +00 +01 +02 +03 +04 +05 +06 +07"
5349 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5350 for (i
= 0; i
< 256; i
+= 16) {
5351 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
5352 for (j
= 0; j
< 16; j
++) {
5353 if (!acpi_ec_read(i
+ j
, &v
))
5355 if (v
!= ecdump_regs
[i
+ j
])
5356 len
+= sprintf(p
+ len
, " *%02x", v
);
5358 len
+= sprintf(p
+ len
, " %02x", v
);
5359 ecdump_regs
[i
+ j
] = v
;
5361 len
+= sprintf(p
+ len
, "\n");
5366 /* These are way too dangerous to advertise openly... */
5368 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
5369 " (<offset> is 00-ff, <value> is 00-ff)\n");
5370 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
5371 " (<offset> is 00-ff, <value> is 0-255)\n");
5376 static int ecdump_write(char *buf
)
5381 while ((cmd
= next_cmd(&buf
))) {
5382 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5384 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5388 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5389 if (!acpi_ec_write(i
, v
))
5398 static struct ibm_struct ecdump_driver_data
= {
5400 .read
= ecdump_read
,
5401 .write
= ecdump_write
,
5402 .flags
.experimental
= 1,
5405 /*************************************************************************
5406 * Backlight/brightness subdriver
5409 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5412 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5413 * CMOS NVRAM byte 0x5E, bits 0-3.
5415 * EC HBRV (0x31) has the following layout
5416 * Bit 7: unknown function
5417 * Bit 6: unknown function
5418 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5419 * Bit 4: must be set to zero to avoid problems
5420 * Bit 3-0: backlight brightness level
5422 * brightness_get_raw returns status data in the HBRV layout
5424 * WARNING: The X61 has been verified to use HBRV for something else, so
5425 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5426 * testing on the very early *60 Lenovo models...
5430 TP_EC_BACKLIGHT
= 0x31,
5432 /* TP_EC_BACKLIGHT bitmasks */
5433 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5434 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5435 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5438 enum tpacpi_brightness_access_mode
{
5439 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5440 TPACPI_BRGHT_MODE_EC
, /* EC control */
5441 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5442 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5443 TPACPI_BRGHT_MODE_MAX
5446 static struct backlight_device
*ibm_backlight_device
;
5448 static enum tpacpi_brightness_access_mode brightness_mode
=
5449 TPACPI_BRGHT_MODE_MAX
;
5451 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5453 static struct mutex brightness_mutex
;
5455 /* NVRAM brightness access,
5456 * call with brightness_mutex held! */
5457 static unsigned int tpacpi_brightness_nvram_get(void)
5461 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5462 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5463 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5464 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5469 static void tpacpi_brightness_checkpoint_nvram(void)
5474 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5477 vdbg_printk(TPACPI_DBG_BRGHT
,
5478 "trying to checkpoint backlight level to NVRAM...\n");
5480 if (mutex_lock_killable(&brightness_mutex
) < 0)
5483 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5485 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5486 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5488 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5489 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5490 /* NVRAM needs update */
5491 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5492 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5494 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5495 dbg_printk(TPACPI_DBG_BRGHT
,
5496 "updated NVRAM backlight level to %u (0x%02x)\n",
5497 (unsigned int) lec
, (unsigned int) b_nvram
);
5499 vdbg_printk(TPACPI_DBG_BRGHT
,
5500 "NVRAM backlight level already is %u (0x%02x)\n",
5501 (unsigned int) lec
, (unsigned int) b_nvram
);
5504 mutex_unlock(&brightness_mutex
);
5508 /* call with brightness_mutex held! */
5509 static int tpacpi_brightness_get_raw(int *status
)
5513 switch (brightness_mode
) {
5514 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5515 *status
= tpacpi_brightness_nvram_get();
5517 case TPACPI_BRGHT_MODE_EC
:
5518 case TPACPI_BRGHT_MODE_ECNVRAM
:
5519 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5528 /* call with brightness_mutex held! */
5529 /* do NOT call with illegal backlight level value */
5530 static int tpacpi_brightness_set_ec(unsigned int value
)
5534 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5537 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
5538 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
5539 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
5545 /* call with brightness_mutex held! */
5546 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
5549 unsigned int current_value
, i
;
5551 current_value
= tpacpi_brightness_nvram_get();
5553 if (value
== current_value
)
5556 cmos_cmd
= (value
> current_value
) ?
5557 TP_CMOS_BRIGHTNESS_UP
:
5558 TP_CMOS_BRIGHTNESS_DOWN
;
5559 inc
= (value
> current_value
) ? 1 : -1;
5561 for (i
= current_value
; i
!= value
; i
+= inc
)
5562 if (issue_thinkpad_cmos_command(cmos_cmd
))
5568 /* May return EINTR which can always be mapped to ERESTARTSYS */
5569 static int brightness_set(unsigned int value
)
5573 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
5577 vdbg_printk(TPACPI_DBG_BRGHT
,
5578 "set backlight level to %d\n", value
);
5580 res
= mutex_lock_killable(&brightness_mutex
);
5584 switch (brightness_mode
) {
5585 case TPACPI_BRGHT_MODE_EC
:
5586 case TPACPI_BRGHT_MODE_ECNVRAM
:
5587 res
= tpacpi_brightness_set_ec(value
);
5589 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5590 res
= tpacpi_brightness_set_ucmsstep(value
);
5596 mutex_unlock(&brightness_mutex
);
5600 /* sysfs backlight class ----------------------------------------------- */
5602 static int brightness_update_status(struct backlight_device
*bd
)
5604 unsigned int level
=
5605 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
5606 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
5607 bd
->props
.brightness
: 0;
5609 dbg_printk(TPACPI_DBG_BRGHT
,
5610 "backlight: attempt to set level to %d\n",
5613 /* it is the backlight class's job (caller) to handle
5614 * EINTR and other errors properly */
5615 return brightness_set(level
);
5618 static int brightness_get(struct backlight_device
*bd
)
5622 res
= mutex_lock_killable(&brightness_mutex
);
5626 res
= tpacpi_brightness_get_raw(&status
);
5628 mutex_unlock(&brightness_mutex
);
5633 return status
& TP_EC_BACKLIGHT_LVLMSK
;
5636 static struct backlight_ops ibm_backlight_data
= {
5637 .get_brightness
= brightness_get
,
5638 .update_status
= brightness_update_status
,
5641 /* --------------------------------------------------------------------- */
5643 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
5647 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
5649 mutex_init(&brightness_mutex
);
5652 * We always attempt to detect acpi support, so as to switch
5653 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
5654 * going to publish a backlight interface
5656 b
= tpacpi_check_std_acpi_brightness_support();
5659 if (acpi_video_backlight_support()) {
5660 if (brightness_enable
> 1) {
5661 printk(TPACPI_NOTICE
5662 "Standard ACPI backlight interface "
5663 "available, not loading native one.\n");
5665 } else if (brightness_enable
== 1) {
5666 printk(TPACPI_NOTICE
5667 "Backlight control force enabled, even if standard "
5668 "ACPI backlight interface is available\n");
5671 if (brightness_enable
> 1) {
5672 printk(TPACPI_NOTICE
5673 "Standard ACPI backlight interface not "
5674 "available, thinkpad_acpi native "
5675 "brightness control enabled\n");
5680 if (!brightness_enable
) {
5681 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
5682 "brightness support disabled by "
5683 "module parameter\n");
5689 "Unsupported brightness interface, "
5690 "please contact %s\n", TPACPI_MAIL
);
5694 tp_features
.bright_16levels
= 1;
5697 * Check for module parameter bogosity, note that we
5698 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
5699 * able to detect "unspecified"
5701 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
5704 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
5705 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
5706 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
5707 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) {
5709 * IBM models that define HBRV probably have
5710 * EC-based backlight level control
5712 if (acpi_evalf(ec_handle
, NULL
, "HBRV", "qd"))
5713 /* T40-T43, R50-R52, R50e, R51e, X31-X41 */
5714 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
5716 /* all other IBM ThinkPads */
5717 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
5719 /* All Lenovo ThinkPads */
5720 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
5722 dbg_printk(TPACPI_DBG_BRGHT
,
5723 "selected brightness_mode=%d\n",
5728 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
5729 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
5730 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
5733 if (tpacpi_brightness_get_raw(&b
) < 0)
5736 if (tp_features
.bright_16levels
)
5738 "detected a 16-level brightness capable ThinkPad\n");
5740 ibm_backlight_device
= backlight_device_register(
5741 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
5742 &ibm_backlight_data
);
5743 if (IS_ERR(ibm_backlight_device
)) {
5744 printk(TPACPI_ERR
"Could not register backlight device\n");
5745 return PTR_ERR(ibm_backlight_device
);
5747 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
5748 "brightness is supported\n");
5750 ibm_backlight_device
->props
.max_brightness
=
5751 (tp_features
.bright_16levels
)? 15 : 7;
5752 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
5753 backlight_update_status(ibm_backlight_device
);
5758 static void brightness_suspend(pm_message_t state
)
5760 tpacpi_brightness_checkpoint_nvram();
5763 static void brightness_shutdown(void)
5765 tpacpi_brightness_checkpoint_nvram();
5768 static void brightness_exit(void)
5770 if (ibm_backlight_device
) {
5771 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
5772 "calling backlight_device_unregister()\n");
5773 backlight_device_unregister(ibm_backlight_device
);
5776 tpacpi_brightness_checkpoint_nvram();
5779 static int brightness_read(char *p
)
5784 level
= brightness_get(NULL
);
5786 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5788 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
5789 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
5790 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5791 " (<level> is 0-%d)\n",
5792 (tp_features
.bright_16levels
) ? 15 : 7);
5798 static int brightness_write(char *buf
)
5803 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
5805 level
= brightness_get(NULL
);
5809 while ((cmd
= next_cmd(&buf
))) {
5810 if (strlencmp(cmd
, "up") == 0) {
5811 if (level
< max_level
)
5813 } else if (strlencmp(cmd
, "down") == 0) {
5816 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
5817 level
>= 0 && level
<= max_level
) {
5823 tpacpi_disclose_usertask("procfs brightness",
5824 "set level to %d\n", level
);
5827 * Now we know what the final level should be, so we try to set it.
5828 * Doing it this way makes the syscall restartable in case of EINTR
5830 rc
= brightness_set(level
);
5831 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
5834 static struct ibm_struct brightness_driver_data
= {
5835 .name
= "brightness",
5836 .read
= brightness_read
,
5837 .write
= brightness_write
,
5838 .exit
= brightness_exit
,
5839 .suspend
= brightness_suspend
,
5840 .shutdown
= brightness_shutdown
,
5843 /*************************************************************************
5847 static int volume_offset
= 0x30;
5849 static int volume_read(char *p
)
5854 if (!acpi_ec_read(volume_offset
, &level
)) {
5855 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5857 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
5858 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
5859 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
5860 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5861 " (<level> is 0-15)\n");
5867 static int volume_write(char *buf
)
5869 int cmos_cmd
, inc
, i
;
5871 int new_level
, new_mute
;
5874 while ((cmd
= next_cmd(&buf
))) {
5875 if (!acpi_ec_read(volume_offset
, &level
))
5877 new_mute
= mute
= level
& 0x40;
5878 new_level
= level
= level
& 0xf;
5880 if (strlencmp(cmd
, "up") == 0) {
5884 new_level
= level
== 15 ? 15 : level
+ 1;
5885 } else if (strlencmp(cmd
, "down") == 0) {
5889 new_level
= level
== 0 ? 0 : level
- 1;
5890 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
5891 new_level
>= 0 && new_level
<= 15) {
5893 } else if (strlencmp(cmd
, "mute") == 0) {
5898 if (new_level
!= level
) {
5899 /* mute doesn't change */
5901 cmos_cmd
= (new_level
> level
) ?
5902 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
5903 inc
= new_level
> level
? 1 : -1;
5905 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
5906 !acpi_ec_write(volume_offset
, level
)))
5909 for (i
= level
; i
!= new_level
; i
+= inc
)
5910 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5911 !acpi_ec_write(volume_offset
, i
+ inc
))
5915 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
5916 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
5921 if (new_mute
!= mute
) {
5922 /* level doesn't change */
5924 cmos_cmd
= (new_mute
) ?
5925 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
5927 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5928 !acpi_ec_write(volume_offset
, level
+ new_mute
))
5936 static struct ibm_struct volume_driver_data
= {
5938 .read
= volume_read
,
5939 .write
= volume_write
,
5942 /*************************************************************************
5949 * TPACPI_FAN_RD_ACPI_GFAN:
5950 * ACPI GFAN method: returns fan level
5952 * see TPACPI_FAN_WR_ACPI_SFAN
5953 * EC 0x2f (HFSP) not available if GFAN exists
5955 * TPACPI_FAN_WR_ACPI_SFAN:
5956 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
5958 * EC 0x2f (HFSP) might be available *for reading*, but do not use
5961 * TPACPI_FAN_WR_TPEC:
5962 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
5963 * Supported on almost all ThinkPads
5965 * Fan speed changes of any sort (including those caused by the
5966 * disengaged mode) are usually done slowly by the firmware as the
5967 * maximum ammount of fan duty cycle change per second seems to be
5970 * Reading is not available if GFAN exists.
5971 * Writing is not available if SFAN exists.
5974 * 7 automatic mode engaged;
5975 * (default operation mode of the ThinkPad)
5976 * fan level is ignored in this mode.
5977 * 6 full speed mode (takes precedence over bit 7);
5978 * not available on all thinkpads. May disable
5979 * the tachometer while the fan controller ramps up
5980 * the speed (which can take up to a few *minutes*).
5981 * Speeds up fan to 100% duty-cycle, which is far above
5982 * the standard RPM levels. It is not impossible that
5983 * it could cause hardware damage.
5984 * 5-3 unused in some models. Extra bits for fan level
5985 * in others, but still useless as all values above
5986 * 7 map to the same speed as level 7 in these models.
5987 * 2-0 fan level (0..7 usually)
5989 * 0x07 = max (set when temperatures critical)
5990 * Some ThinkPads may have other levels, see
5991 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
5993 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
5994 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
5995 * does so, its initial value is meaningless (0x07).
5997 * For firmware bugs, refer to:
5998 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6002 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
6003 * Main fan tachometer reading (in RPM)
6005 * This register is present on all ThinkPads with a new-style EC, and
6006 * it is known not to be present on the A21m/e, and T22, as there is
6007 * something else in offset 0x84 according to the ACPI DSDT. Other
6008 * ThinkPads from this same time period (and earlier) probably lack the
6009 * tachometer as well.
6011 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
6012 * was never fixed by IBM to report the EC firmware version string
6013 * probably support the tachometer (like the early X models), so
6014 * detecting it is quite hard. We need more data to know for sure.
6016 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
6019 * FIRMWARE BUG: may go stale while the EC is switching to full speed
6022 * For firmware bugs, refer to:
6023 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6027 * ThinkPad EC register 0x31 bit 0 (only on select models)
6029 * When bit 0 of EC register 0x31 is zero, the tachometer registers
6030 * show the speed of the main fan. When bit 0 of EC register 0x31
6031 * is one, the tachometer registers show the speed of the auxiliary
6034 * Fan control seems to affect both fans, regardless of the state
6037 * So far, only the firmware for the X60/X61 non-tablet versions
6038 * seem to support this (firmware TP-7M).
6040 * TPACPI_FAN_WR_ACPI_FANS:
6041 * ThinkPad X31, X40, X41. Not available in the X60.
6043 * FANS ACPI handle: takes three arguments: low speed, medium speed,
6044 * high speed. ACPI DSDT seems to map these three speeds to levels
6045 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
6046 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
6048 * The speeds are stored on handles
6049 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
6051 * There are three default speed sets, acessible as handles:
6052 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
6054 * ACPI DSDT switches which set is in use depending on various
6057 * TPACPI_FAN_WR_TPEC is also available and should be used to
6058 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
6059 * but the ACPI tables just mention level 7.
6062 enum { /* Fan control constants */
6063 fan_status_offset
= 0x2f, /* EC register 0x2f */
6064 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
6065 * 0x84 must be read before 0x85 */
6066 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
6067 bit 0 selects which fan is active */
6069 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
6070 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
6072 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
6075 enum fan_status_access_mode
{
6076 TPACPI_FAN_NONE
= 0, /* No fan status or control */
6077 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
6078 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
6081 enum fan_control_access_mode
{
6082 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
6083 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
6084 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
6085 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
6088 enum fan_control_commands
{
6089 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
6090 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
6091 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
6092 * and also watchdog cmd */
6095 static int fan_control_allowed
;
6097 static enum fan_status_access_mode fan_status_access_mode
;
6098 static enum fan_control_access_mode fan_control_access_mode
;
6099 static enum fan_control_commands fan_control_commands
;
6101 static u8 fan_control_initial_status
;
6102 static u8 fan_control_desired_level
;
6103 static u8 fan_control_resume_level
;
6104 static int fan_watchdog_maxinterval
;
6106 static struct mutex fan_mutex
;
6108 static void fan_watchdog_fire(struct work_struct
*ignored
);
6109 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
6111 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
6112 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
6113 "\\FSPD", /* 600e/x, 770e, 770x */
6115 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
6116 "JFNS", /* 770x-JL */
6120 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
6121 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
6122 * be in auto mode (0x80).
6124 * This is corrected by any write to HFSP either by the driver, or
6127 * We assume 0x07 really means auto mode while this quirk is active,
6128 * as this is far more likely than the ThinkPad being in level 7,
6129 * which is only used by the firmware during thermal emergencies.
6131 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
6132 * TP-70 (T43, R52), which are known to be buggy.
6135 static void fan_quirk1_setup(void)
6137 if (fan_control_initial_status
== 0x07) {
6138 printk(TPACPI_NOTICE
6139 "fan_init: initial fan status is unknown, "
6140 "assuming it is in auto mode\n");
6141 tp_features
.fan_ctrl_status_undef
= 1;
6145 static void fan_quirk1_handle(u8
*fan_status
)
6147 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6148 if (*fan_status
!= fan_control_initial_status
) {
6149 /* something changed the HFSP regisnter since
6150 * driver init time, so it is not undefined
6152 tp_features
.fan_ctrl_status_undef
= 0;
6154 /* Return most likely status. In fact, it
6155 * might be the only possible status */
6156 *fan_status
= TP_EC_FAN_AUTO
;
6161 /* Select main fan on X60/X61, NOOP on others */
6162 static bool fan_select_fan1(void)
6164 if (tp_features
.second_fan
) {
6167 if (ec_read(fan_select_offset
, &val
) < 0)
6170 if (ec_write(fan_select_offset
, val
) < 0)
6176 /* Select secondary fan on X60/X61 */
6177 static bool fan_select_fan2(void)
6181 if (!tp_features
.second_fan
)
6184 if (ec_read(fan_select_offset
, &val
) < 0)
6187 if (ec_write(fan_select_offset
, val
) < 0)
6194 * Call with fan_mutex held
6196 static void fan_update_desired_level(u8 status
)
6199 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6201 fan_control_desired_level
= 7;
6203 fan_control_desired_level
= status
;
6207 static int fan_get_status(u8
*status
)
6212 * Add TPACPI_FAN_RD_ACPI_FANS ? */
6214 switch (fan_status_access_mode
) {
6215 case TPACPI_FAN_RD_ACPI_GFAN
:
6216 /* 570, 600e/x, 770e, 770x */
6218 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
6226 case TPACPI_FAN_RD_TPEC
:
6227 /* all except 570, 600e/x, 770e, 770x */
6228 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
6231 if (likely(status
)) {
6233 fan_quirk1_handle(status
);
6245 static int fan_get_status_safe(u8
*status
)
6250 if (mutex_lock_killable(&fan_mutex
))
6251 return -ERESTARTSYS
;
6252 rc
= fan_get_status(&s
);
6254 fan_update_desired_level(s
);
6255 mutex_unlock(&fan_mutex
);
6263 static int fan_get_speed(unsigned int *speed
)
6267 switch (fan_status_access_mode
) {
6268 case TPACPI_FAN_RD_TPEC
:
6269 /* all except 570, 600e/x, 770e, 770x */
6270 if (unlikely(!fan_select_fan1()))
6272 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
6273 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
6277 *speed
= (hi
<< 8) | lo
;
6288 static int fan2_get_speed(unsigned int *speed
)
6293 switch (fan_status_access_mode
) {
6294 case TPACPI_FAN_RD_TPEC
:
6295 /* all except 570, 600e/x, 770e, 770x */
6296 if (unlikely(!fan_select_fan2()))
6298 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
6299 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
6300 fan_select_fan1(); /* play it safe */
6305 *speed
= (hi
<< 8) | lo
;
6316 static int fan_set_level(int level
)
6318 if (!fan_control_allowed
)
6321 switch (fan_control_access_mode
) {
6322 case TPACPI_FAN_WR_ACPI_SFAN
:
6323 if (level
>= 0 && level
<= 7) {
6324 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
6330 case TPACPI_FAN_WR_ACPI_FANS
:
6331 case TPACPI_FAN_WR_TPEC
:
6332 if (!(level
& TP_EC_FAN_AUTO
) &&
6333 !(level
& TP_EC_FAN_FULLSPEED
) &&
6334 ((level
< 0) || (level
> 7)))
6337 /* safety net should the EC not support AUTO
6338 * or FULLSPEED mode bits and just ignore them */
6339 if (level
& TP_EC_FAN_FULLSPEED
)
6340 level
|= 7; /* safety min speed 7 */
6341 else if (level
& TP_EC_FAN_AUTO
)
6342 level
|= 4; /* safety min speed 4 */
6344 if (!acpi_ec_write(fan_status_offset
, level
))
6347 tp_features
.fan_ctrl_status_undef
= 0;
6354 vdbg_printk(TPACPI_DBG_FAN
,
6355 "fan control: set fan control register to 0x%02x\n", level
);
6359 static int fan_set_level_safe(int level
)
6363 if (!fan_control_allowed
)
6366 if (mutex_lock_killable(&fan_mutex
))
6367 return -ERESTARTSYS
;
6369 if (level
== TPACPI_FAN_LAST_LEVEL
)
6370 level
= fan_control_desired_level
;
6372 rc
= fan_set_level(level
);
6374 fan_update_desired_level(level
);
6376 mutex_unlock(&fan_mutex
);
6380 static int fan_set_enable(void)
6385 if (!fan_control_allowed
)
6388 if (mutex_lock_killable(&fan_mutex
))
6389 return -ERESTARTSYS
;
6391 switch (fan_control_access_mode
) {
6392 case TPACPI_FAN_WR_ACPI_FANS
:
6393 case TPACPI_FAN_WR_TPEC
:
6394 rc
= fan_get_status(&s
);
6398 /* Don't go out of emergency fan mode */
6401 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
6404 if (!acpi_ec_write(fan_status_offset
, s
))
6407 tp_features
.fan_ctrl_status_undef
= 0;
6412 case TPACPI_FAN_WR_ACPI_SFAN
:
6413 rc
= fan_get_status(&s
);
6419 /* Set fan to at least level 4 */
6422 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
6432 mutex_unlock(&fan_mutex
);
6435 vdbg_printk(TPACPI_DBG_FAN
,
6436 "fan control: set fan control register to 0x%02x\n",
6441 static int fan_set_disable(void)
6445 if (!fan_control_allowed
)
6448 if (mutex_lock_killable(&fan_mutex
))
6449 return -ERESTARTSYS
;
6452 switch (fan_control_access_mode
) {
6453 case TPACPI_FAN_WR_ACPI_FANS
:
6454 case TPACPI_FAN_WR_TPEC
:
6455 if (!acpi_ec_write(fan_status_offset
, 0x00))
6458 fan_control_desired_level
= 0;
6459 tp_features
.fan_ctrl_status_undef
= 0;
6463 case TPACPI_FAN_WR_ACPI_SFAN
:
6464 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
6467 fan_control_desired_level
= 0;
6475 vdbg_printk(TPACPI_DBG_FAN
,
6476 "fan control: set fan control register to 0\n");
6478 mutex_unlock(&fan_mutex
);
6482 static int fan_set_speed(int speed
)
6486 if (!fan_control_allowed
)
6489 if (mutex_lock_killable(&fan_mutex
))
6490 return -ERESTARTSYS
;
6493 switch (fan_control_access_mode
) {
6494 case TPACPI_FAN_WR_ACPI_FANS
:
6495 if (speed
>= 0 && speed
<= 65535) {
6496 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
6497 speed
, speed
, speed
))
6507 mutex_unlock(&fan_mutex
);
6511 static void fan_watchdog_reset(void)
6513 static int fan_watchdog_active
;
6515 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
6518 if (fan_watchdog_active
)
6519 cancel_delayed_work(&fan_watchdog_task
);
6521 if (fan_watchdog_maxinterval
> 0 &&
6522 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
6523 fan_watchdog_active
= 1;
6524 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
6525 msecs_to_jiffies(fan_watchdog_maxinterval
6528 "failed to queue the fan watchdog, "
6529 "watchdog will not trigger\n");
6532 fan_watchdog_active
= 0;
6535 static void fan_watchdog_fire(struct work_struct
*ignored
)
6539 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
6542 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
6543 rc
= fan_set_enable();
6545 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
6546 "will try again later...\n", -rc
);
6547 /* reschedule for later */
6548 fan_watchdog_reset();
6553 * SYSFS fan layout: hwmon compatible (device)
6556 * 0: "disengaged" mode
6558 * 2: native EC "auto" mode (recommended, hardware default)
6560 * pwm*: set speed in manual mode, ignored otherwise.
6561 * 0 is level 0; 255 is level 7. Intermediate points done with linear
6564 * fan*_input: tachometer reading, RPM
6567 * SYSFS fan layout: extensions
6569 * fan_watchdog (driver):
6570 * fan watchdog interval in seconds, 0 disables (default), max 120
6573 /* sysfs fan pwm1_enable ----------------------------------------------- */
6574 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
6575 struct device_attribute
*attr
,
6581 res
= fan_get_status_safe(&status
);
6585 if (status
& TP_EC_FAN_FULLSPEED
) {
6587 } else if (status
& TP_EC_FAN_AUTO
) {
6592 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
6595 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
6596 struct device_attribute
*attr
,
6597 const char *buf
, size_t count
)
6602 if (parse_strtoul(buf
, 2, &t
))
6605 tpacpi_disclose_usertask("hwmon pwm1_enable",
6606 "set fan mode to %lu\n", t
);
6610 level
= TP_EC_FAN_FULLSPEED
;
6613 level
= TPACPI_FAN_LAST_LEVEL
;
6616 level
= TP_EC_FAN_AUTO
;
6619 /* reserved for software-controlled auto mode */
6625 res
= fan_set_level_safe(level
);
6631 fan_watchdog_reset();
6636 static struct device_attribute dev_attr_fan_pwm1_enable
=
6637 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
6638 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
6640 /* sysfs fan pwm1 ------------------------------------------------------ */
6641 static ssize_t
fan_pwm1_show(struct device
*dev
,
6642 struct device_attribute
*attr
,
6648 res
= fan_get_status_safe(&status
);
6653 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
6654 status
= fan_control_desired_level
;
6659 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
6662 static ssize_t
fan_pwm1_store(struct device
*dev
,
6663 struct device_attribute
*attr
,
6664 const char *buf
, size_t count
)
6668 u8 status
, newlevel
;
6670 if (parse_strtoul(buf
, 255, &s
))
6673 tpacpi_disclose_usertask("hwmon pwm1",
6674 "set fan speed to %lu\n", s
);
6676 /* scale down from 0-255 to 0-7 */
6677 newlevel
= (s
>> 5) & 0x07;
6679 if (mutex_lock_killable(&fan_mutex
))
6680 return -ERESTARTSYS
;
6682 rc
= fan_get_status(&status
);
6683 if (!rc
&& (status
&
6684 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6685 rc
= fan_set_level(newlevel
);
6689 fan_update_desired_level(newlevel
);
6690 fan_watchdog_reset();
6694 mutex_unlock(&fan_mutex
);
6695 return (rc
)? rc
: count
;
6698 static struct device_attribute dev_attr_fan_pwm1
=
6699 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
6700 fan_pwm1_show
, fan_pwm1_store
);
6702 /* sysfs fan fan1_input ------------------------------------------------ */
6703 static ssize_t
fan_fan1_input_show(struct device
*dev
,
6704 struct device_attribute
*attr
,
6710 res
= fan_get_speed(&speed
);
6714 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
6717 static struct device_attribute dev_attr_fan_fan1_input
=
6718 __ATTR(fan1_input
, S_IRUGO
,
6719 fan_fan1_input_show
, NULL
);
6721 /* sysfs fan fan2_input ------------------------------------------------ */
6722 static ssize_t
fan_fan2_input_show(struct device
*dev
,
6723 struct device_attribute
*attr
,
6729 res
= fan2_get_speed(&speed
);
6733 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
6736 static struct device_attribute dev_attr_fan_fan2_input
=
6737 __ATTR(fan2_input
, S_IRUGO
,
6738 fan_fan2_input_show
, NULL
);
6740 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
6741 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
6744 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
6747 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
6748 const char *buf
, size_t count
)
6752 if (parse_strtoul(buf
, 120, &t
))
6755 if (!fan_control_allowed
)
6758 fan_watchdog_maxinterval
= t
;
6759 fan_watchdog_reset();
6761 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
6766 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
6767 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
6769 /* --------------------------------------------------------------------- */
6770 static struct attribute
*fan_attributes
[] = {
6771 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
6772 &dev_attr_fan_fan1_input
.attr
,
6773 NULL
, /* for fan2_input */
6777 static const struct attribute_group fan_attr_group
= {
6778 .attrs
= fan_attributes
,
6781 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
6782 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
6784 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
6785 { .vendor = PCI_VENDOR_ID_IBM, \
6786 .bios = TPACPI_MATCH_ANY, \
6787 .ec = TPID(__id1, __id2), \
6788 .quirks = __quirks }
6790 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
6791 { .vendor = PCI_VENDOR_ID_LENOVO, \
6792 .bios = TPACPI_MATCH_ANY, \
6793 .ec = TPID(__id1, __id2), \
6794 .quirks = __quirks }
6796 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
6797 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
6798 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
6799 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
6800 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
6801 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
6804 #undef TPACPI_FAN_QL
6805 #undef TPACPI_FAN_QI
6807 static int __init
fan_init(struct ibm_init_struct
*iibm
)
6810 unsigned long quirks
;
6812 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
6813 "initializing fan subdriver\n");
6815 mutex_init(&fan_mutex
);
6816 fan_status_access_mode
= TPACPI_FAN_NONE
;
6817 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6818 fan_control_commands
= 0;
6819 fan_watchdog_maxinterval
= 0;
6820 tp_features
.fan_ctrl_status_undef
= 0;
6821 tp_features
.second_fan
= 0;
6822 fan_control_desired_level
= 7;
6824 TPACPI_ACPIHANDLE_INIT(fans
);
6825 TPACPI_ACPIHANDLE_INIT(gfan
);
6826 TPACPI_ACPIHANDLE_INIT(sfan
);
6828 quirks
= tpacpi_check_quirks(fan_quirk_table
,
6829 ARRAY_SIZE(fan_quirk_table
));
6832 /* 570, 600e/x, 770e, 770x */
6833 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
6835 /* all other ThinkPads: note that even old-style
6836 * ThinkPad ECs supports the fan control register */
6837 if (likely(acpi_ec_read(fan_status_offset
,
6838 &fan_control_initial_status
))) {
6839 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
6840 if (quirks
& TPACPI_FAN_Q1
)
6842 if (quirks
& TPACPI_FAN_2FAN
) {
6843 tp_features
.second_fan
= 1;
6844 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
6845 "secondary fan support enabled\n");
6849 "ThinkPad ACPI EC access misbehaving, "
6850 "fan status and control unavailable\n");
6857 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
6858 fan_control_commands
|=
6859 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
6862 /* gfan without sfan means no fan control */
6863 /* all other models implement TP EC 0x2f control */
6867 fan_control_access_mode
=
6868 TPACPI_FAN_WR_ACPI_FANS
;
6869 fan_control_commands
|=
6870 TPACPI_FAN_CMD_SPEED
|
6871 TPACPI_FAN_CMD_LEVEL
|
6872 TPACPI_FAN_CMD_ENABLE
;
6874 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
6875 fan_control_commands
|=
6876 TPACPI_FAN_CMD_LEVEL
|
6877 TPACPI_FAN_CMD_ENABLE
;
6882 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
6883 "fan is %s, modes %d, %d\n",
6884 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
6885 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
6886 fan_status_access_mode
, fan_control_access_mode
);
6888 /* fan control master switch */
6889 if (!fan_control_allowed
) {
6890 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6891 fan_control_commands
= 0;
6892 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
6893 "fan control features disabled by parameter\n");
6896 /* update fan_control_desired_level */
6897 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
6898 fan_get_status_safe(NULL
);
6900 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
6901 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
6902 if (tp_features
.second_fan
) {
6903 /* attach second fan tachometer */
6904 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
6905 &dev_attr_fan_fan2_input
.attr
;
6907 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6912 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
6913 &driver_attr_fan_watchdog
);
6915 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6924 static void fan_exit(void)
6926 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
6927 "cancelling any pending fan watchdog tasks\n");
6929 /* FIXME: can we really do this unconditionally? */
6930 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
6931 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
6932 &driver_attr_fan_watchdog
);
6934 cancel_delayed_work(&fan_watchdog_task
);
6935 flush_workqueue(tpacpi_wq
);
6938 static void fan_suspend(pm_message_t state
)
6942 if (!fan_control_allowed
)
6945 /* Store fan status in cache */
6946 fan_control_resume_level
= 0;
6947 rc
= fan_get_status_safe(&fan_control_resume_level
);
6949 printk(TPACPI_NOTICE
6950 "failed to read fan level for later "
6951 "restore during resume: %d\n", rc
);
6953 /* if it is undefined, don't attempt to restore it.
6955 if (tp_features
.fan_ctrl_status_undef
)
6956 fan_control_resume_level
= 0;
6959 static void fan_resume(void)
6961 u8 current_level
= 7;
6962 bool do_set
= false;
6965 /* DSDT *always* updates status on resume */
6966 tp_features
.fan_ctrl_status_undef
= 0;
6968 if (!fan_control_allowed
||
6969 !fan_control_resume_level
||
6970 (fan_get_status_safe(¤t_level
) < 0))
6973 switch (fan_control_access_mode
) {
6974 case TPACPI_FAN_WR_ACPI_SFAN
:
6975 /* never decrease fan level */
6976 do_set
= (fan_control_resume_level
> current_level
);
6978 case TPACPI_FAN_WR_ACPI_FANS
:
6979 case TPACPI_FAN_WR_TPEC
:
6980 /* never decrease fan level, scale is:
6981 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
6983 * We expect the firmware to set either 7 or AUTO, but we
6984 * handle FULLSPEED out of paranoia.
6986 * So, we can safely only restore FULLSPEED or 7, anything
6987 * else could slow the fan. Restoring AUTO is useless, at
6988 * best that's exactly what the DSDT already set (it is the
6991 * Always keep in mind that the DSDT *will* have set the
6992 * fans to what the vendor supposes is the best level. We
6993 * muck with it only to speed the fan up.
6995 if (fan_control_resume_level
!= 7 &&
6996 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
6999 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
7000 (current_level
!= fan_control_resume_level
);
7006 printk(TPACPI_NOTICE
7007 "restoring fan level to 0x%02x\n",
7008 fan_control_resume_level
);
7009 rc
= fan_set_level_safe(fan_control_resume_level
);
7011 printk(TPACPI_NOTICE
7012 "failed to restore fan level: %d\n", rc
);
7016 static int fan_read(char *p
)
7021 unsigned int speed
= 0;
7023 switch (fan_status_access_mode
) {
7024 case TPACPI_FAN_RD_ACPI_GFAN
:
7025 /* 570, 600e/x, 770e, 770x */
7026 rc
= fan_get_status_safe(&status
);
7030 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
7032 (status
!= 0) ? "enabled" : "disabled", status
);
7035 case TPACPI_FAN_RD_TPEC
:
7036 /* all except 570, 600e/x, 770e, 770x */
7037 rc
= fan_get_status_safe(&status
);
7041 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
7042 (status
!= 0) ? "enabled" : "disabled");
7044 rc
= fan_get_speed(&speed
);
7048 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
7050 if (status
& TP_EC_FAN_FULLSPEED
)
7051 /* Disengaged mode takes precedence */
7052 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
7053 else if (status
& TP_EC_FAN_AUTO
)
7054 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
7056 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
7059 case TPACPI_FAN_NONE
:
7061 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
7064 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
7065 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
7067 switch (fan_control_access_mode
) {
7068 case TPACPI_FAN_WR_ACPI_SFAN
:
7069 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
7073 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
7074 "auto, disengaged, full-speed)\n");
7079 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
7080 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
7081 "commands:\twatchdog <timeout> (<timeout> "
7082 "is 0 (off), 1-120 (seconds))\n");
7084 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
7085 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
7086 " (<speed> is 0-65535)\n");
7091 static int fan_write_cmd_level(const char *cmd
, int *rc
)
7095 if (strlencmp(cmd
, "level auto") == 0)
7096 level
= TP_EC_FAN_AUTO
;
7097 else if ((strlencmp(cmd
, "level disengaged") == 0) |
7098 (strlencmp(cmd
, "level full-speed") == 0))
7099 level
= TP_EC_FAN_FULLSPEED
;
7100 else if (sscanf(cmd
, "level %d", &level
) != 1)
7103 *rc
= fan_set_level_safe(level
);
7105 printk(TPACPI_ERR
"level command accepted for unsupported "
7106 "access mode %d", fan_control_access_mode
);
7108 tpacpi_disclose_usertask("procfs fan",
7109 "set level to %d\n", level
);
7114 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
7116 if (strlencmp(cmd
, "enable") != 0)
7119 *rc
= fan_set_enable();
7121 printk(TPACPI_ERR
"enable command accepted for unsupported "
7122 "access mode %d", fan_control_access_mode
);
7124 tpacpi_disclose_usertask("procfs fan", "enable\n");
7129 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
7131 if (strlencmp(cmd
, "disable") != 0)
7134 *rc
= fan_set_disable();
7136 printk(TPACPI_ERR
"disable command accepted for unsupported "
7137 "access mode %d", fan_control_access_mode
);
7139 tpacpi_disclose_usertask("procfs fan", "disable\n");
7144 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
7149 * Support speed <low> <medium> <high> ? */
7151 if (sscanf(cmd
, "speed %d", &speed
) != 1)
7154 *rc
= fan_set_speed(speed
);
7156 printk(TPACPI_ERR
"speed command accepted for unsupported "
7157 "access mode %d", fan_control_access_mode
);
7159 tpacpi_disclose_usertask("procfs fan",
7160 "set speed to %d\n", speed
);
7165 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
7169 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
7172 if (interval
< 0 || interval
> 120)
7175 fan_watchdog_maxinterval
= interval
;
7176 tpacpi_disclose_usertask("procfs fan",
7177 "set watchdog timer to %d\n",
7184 static int fan_write(char *buf
)
7189 while (!rc
&& (cmd
= next_cmd(&buf
))) {
7190 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
7191 fan_write_cmd_level(cmd
, &rc
)) &&
7192 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
7193 (fan_write_cmd_enable(cmd
, &rc
) ||
7194 fan_write_cmd_disable(cmd
, &rc
) ||
7195 fan_write_cmd_watchdog(cmd
, &rc
))) &&
7196 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
7197 fan_write_cmd_speed(cmd
, &rc
))
7201 fan_watchdog_reset();
7207 static struct ibm_struct fan_driver_data
= {
7212 .suspend
= fan_suspend
,
7213 .resume
= fan_resume
,
7216 /****************************************************************************
7217 ****************************************************************************
7221 ****************************************************************************
7222 ****************************************************************************/
7224 /* sysfs name ---------------------------------------------------------- */
7225 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
7226 struct device_attribute
*attr
,
7229 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
7232 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
7233 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
7235 /* --------------------------------------------------------------------- */
7238 static struct proc_dir_entry
*proc_dir
;
7241 * Module and infrastructure proble, init and exit handling
7244 static int force_load
;
7246 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
7247 static const char * __init
str_supported(int is_supported
)
7249 static char text_unsupported
[] __initdata
= "not supported";
7251 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
7253 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
7255 static void ibm_exit(struct ibm_struct
*ibm
)
7257 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
7259 list_del_init(&ibm
->all_drivers
);
7261 if (ibm
->flags
.acpi_notify_installed
) {
7262 dbg_printk(TPACPI_DBG_EXIT
,
7263 "%s: acpi_remove_notify_handler\n", ibm
->name
);
7265 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
7267 dispatch_acpi_notify
);
7268 ibm
->flags
.acpi_notify_installed
= 0;
7269 ibm
->flags
.acpi_notify_installed
= 0;
7272 if (ibm
->flags
.proc_created
) {
7273 dbg_printk(TPACPI_DBG_EXIT
,
7274 "%s: remove_proc_entry\n", ibm
->name
);
7275 remove_proc_entry(ibm
->name
, proc_dir
);
7276 ibm
->flags
.proc_created
= 0;
7279 if (ibm
->flags
.acpi_driver_registered
) {
7280 dbg_printk(TPACPI_DBG_EXIT
,
7281 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
7283 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
7284 kfree(ibm
->acpi
->driver
);
7285 ibm
->acpi
->driver
= NULL
;
7286 ibm
->flags
.acpi_driver_registered
= 0;
7289 if (ibm
->flags
.init_called
&& ibm
->exit
) {
7291 ibm
->flags
.init_called
= 0;
7294 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
7297 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
7300 struct ibm_struct
*ibm
= iibm
->data
;
7301 struct proc_dir_entry
*entry
;
7303 BUG_ON(ibm
== NULL
);
7305 INIT_LIST_HEAD(&ibm
->all_drivers
);
7307 if (ibm
->flags
.experimental
&& !experimental
)
7310 dbg_printk(TPACPI_DBG_INIT
,
7311 "probing for %s\n", ibm
->name
);
7314 ret
= iibm
->init(iibm
);
7316 return 0; /* probe failed */
7320 ibm
->flags
.init_called
= 1;
7324 if (ibm
->acpi
->hid
) {
7325 ret
= register_tpacpi_subdriver(ibm
);
7330 if (ibm
->acpi
->notify
) {
7331 ret
= setup_acpi_notify(ibm
);
7332 if (ret
== -ENODEV
) {
7333 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
7343 dbg_printk(TPACPI_DBG_INIT
,
7344 "%s installed\n", ibm
->name
);
7347 entry
= create_proc_entry(ibm
->name
,
7348 S_IFREG
| S_IRUGO
| S_IWUSR
,
7351 printk(TPACPI_ERR
"unable to create proc entry %s\n",
7357 entry
->read_proc
= &dispatch_procfs_read
;
7359 entry
->write_proc
= &dispatch_procfs_write
;
7360 ibm
->flags
.proc_created
= 1;
7363 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
7368 dbg_printk(TPACPI_DBG_INIT
,
7369 "%s: at error exit path with result %d\n",
7373 return (ret
< 0)? ret
: 0;
7378 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
7380 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
7383 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
7384 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
7387 return s
&& strlen(s
) >= 8 &&
7388 tpacpi_is_fw_digit(s
[0]) &&
7389 tpacpi_is_fw_digit(s
[1]) &&
7390 s
[2] == t
&& s
[3] == 'T' &&
7391 tpacpi_is_fw_digit(s
[4]) &&
7392 tpacpi_is_fw_digit(s
[5]) &&
7393 s
[6] == 'W' && s
[7] == 'W';
7396 /* returns 0 - probe ok, or < 0 - probe error.
7397 * Probe ok doesn't mean thinkpad found.
7398 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
7399 static int __must_check __init
get_thinkpad_model_data(
7400 struct thinkpad_id_data
*tp
)
7402 const struct dmi_device
*dev
= NULL
;
7403 char ec_fw_string
[18];
7409 memset(tp
, 0, sizeof(*tp
));
7411 if (dmi_name_in_vendors("IBM"))
7412 tp
->vendor
= PCI_VENDOR_ID_IBM
;
7413 else if (dmi_name_in_vendors("LENOVO"))
7414 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
7418 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
7419 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
7420 if (s
&& !tp
->bios_version_str
)
7423 /* Really ancient ThinkPad 240X will fail this, which is fine */
7424 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
7427 tp
->bios_model
= tp
->bios_version_str
[0]
7428 | (tp
->bios_version_str
[1] << 8);
7429 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
7430 | tp
->bios_version_str
[5];
7433 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
7434 * X32 or newer, all Z series; Some models must have an
7435 * up-to-date BIOS or they will not be detected.
7437 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7439 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
7440 if (sscanf(dev
->name
,
7441 "IBM ThinkPad Embedded Controller -[%17c",
7442 ec_fw_string
) == 1) {
7443 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
7444 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
7446 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
7447 if (!tp
->ec_version_str
)
7450 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
7451 tp
->ec_model
= ec_fw_string
[0]
7452 | (ec_fw_string
[1] << 8);
7453 tp
->ec_release
= (ec_fw_string
[4] << 8)
7456 printk(TPACPI_NOTICE
7457 "ThinkPad firmware release %s "
7458 "doesn't match the known patterns\n",
7460 printk(TPACPI_NOTICE
7461 "please report this to %s\n",
7468 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
7469 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
7470 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
7475 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
7476 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
7477 if (s
&& !tp
->nummodel_str
)
7483 static int __init
probe_for_thinkpad(void)
7491 * Non-ancient models have better DMI tagging, but very old models
7494 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
7496 /* ec is required because many other handles are relative to it */
7497 TPACPI_ACPIHANDLE_INIT(ec
);
7501 "Not yet supported ThinkPad detected!\n");
7506 * Risks a regression on very old machines, but reduces potential
7507 * false positives a damn great deal
7510 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
7512 if (!is_thinkpad
&& !force_load
)
7519 /* Module init, exit, parameters */
7521 static struct ibm_init_struct ibms_init
[] __initdata
= {
7523 .init
= thinkpad_acpi_driver_init
,
7524 .data
= &thinkpad_acpi_driver_data
,
7527 .init
= hotkey_init
,
7528 .data
= &hotkey_driver_data
,
7531 .init
= bluetooth_init
,
7532 .data
= &bluetooth_driver_data
,
7536 .data
= &wan_driver_data
,
7540 .data
= &uwb_driver_data
,
7542 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
7545 .data
= &video_driver_data
,
7550 .data
= &light_driver_data
,
7554 .data
= &cmos_driver_data
,
7558 .data
= &led_driver_data
,
7562 .data
= &beep_driver_data
,
7565 .init
= thermal_init
,
7566 .data
= &thermal_driver_data
,
7569 .data
= &ecdump_driver_data
,
7572 .init
= brightness_init
,
7573 .data
= &brightness_driver_data
,
7576 .data
= &volume_driver_data
,
7580 .data
= &fan_driver_data
,
7584 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
7587 struct ibm_struct
*ibm
;
7589 if (!kp
|| !kp
->name
|| !val
)
7592 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7593 ibm
= ibms_init
[i
].data
;
7594 WARN_ON(ibm
== NULL
);
7596 if (!ibm
|| !ibm
->name
)
7599 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
7600 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
7602 strcpy(ibms_init
[i
].param
, val
);
7603 strcat(ibms_init
[i
].param
, ",");
7611 module_param(experimental
, int, 0);
7612 MODULE_PARM_DESC(experimental
,
7613 "Enables experimental features when non-zero");
7615 module_param_named(debug
, dbg_level
, uint
, 0);
7616 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
7618 module_param(force_load
, bool, 0);
7619 MODULE_PARM_DESC(force_load
,
7620 "Attempts to load the driver even on a "
7621 "mis-identified ThinkPad when true");
7623 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
7624 MODULE_PARM_DESC(fan_control
,
7625 "Enables setting fan parameters features when true");
7627 module_param_named(brightness_mode
, brightness_mode
, uint
, 0);
7628 MODULE_PARM_DESC(brightness_mode
,
7629 "Selects brightness control strategy: "
7630 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
7632 module_param(brightness_enable
, uint
, 0);
7633 MODULE_PARM_DESC(brightness_enable
,
7634 "Enables backlight control when 1, disables when 0");
7636 module_param(hotkey_report_mode
, uint
, 0);
7637 MODULE_PARM_DESC(hotkey_report_mode
,
7638 "used for backwards compatibility with userspace, "
7639 "see documentation");
7641 #define TPACPI_PARAM(feature) \
7642 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
7643 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
7644 "at module load, see documentation")
7646 TPACPI_PARAM(hotkey
);
7647 TPACPI_PARAM(bluetooth
);
7648 TPACPI_PARAM(video
);
7649 TPACPI_PARAM(light
);
7653 TPACPI_PARAM(ecdump
);
7654 TPACPI_PARAM(brightness
);
7655 TPACPI_PARAM(volume
);
7658 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
7659 module_param(dbg_wlswemul
, uint
, 0);
7660 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
7661 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
7662 MODULE_PARM_DESC(wlsw_state
,
7663 "Initial state of the emulated WLSW switch");
7665 module_param(dbg_bluetoothemul
, uint
, 0);
7666 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
7667 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
7668 MODULE_PARM_DESC(bluetooth_state
,
7669 "Initial state of the emulated bluetooth switch");
7671 module_param(dbg_wwanemul
, uint
, 0);
7672 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
7673 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
7674 MODULE_PARM_DESC(wwan_state
,
7675 "Initial state of the emulated WWAN switch");
7677 module_param(dbg_uwbemul
, uint
, 0);
7678 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
7679 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
7680 MODULE_PARM_DESC(uwb_state
,
7681 "Initial state of the emulated UWB switch");
7684 static void thinkpad_acpi_module_exit(void)
7686 struct ibm_struct
*ibm
, *itmp
;
7688 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
7690 list_for_each_entry_safe_reverse(ibm
, itmp
,
7691 &tpacpi_all_drivers
,
7696 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
7698 if (tpacpi_inputdev
) {
7699 if (tp_features
.input_device_registered
)
7700 input_unregister_device(tpacpi_inputdev
);
7702 input_free_device(tpacpi_inputdev
);
7706 hwmon_device_unregister(tpacpi_hwmon
);
7708 if (tp_features
.sensors_pdev_attrs_registered
)
7709 device_remove_file(&tpacpi_sensors_pdev
->dev
,
7710 &dev_attr_thinkpad_acpi_pdev_name
);
7711 if (tpacpi_sensors_pdev
)
7712 platform_device_unregister(tpacpi_sensors_pdev
);
7714 platform_device_unregister(tpacpi_pdev
);
7716 if (tp_features
.sensors_pdrv_attrs_registered
)
7717 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
7718 if (tp_features
.platform_drv_attrs_registered
)
7719 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
7721 if (tp_features
.sensors_pdrv_registered
)
7722 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
7724 if (tp_features
.platform_drv_registered
)
7725 platform_driver_unregister(&tpacpi_pdriver
);
7728 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
7731 destroy_workqueue(tpacpi_wq
);
7733 kfree(thinkpad_id
.bios_version_str
);
7734 kfree(thinkpad_id
.ec_version_str
);
7735 kfree(thinkpad_id
.model_str
);
7739 static int __init
thinkpad_acpi_module_init(void)
7743 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
7745 /* Parameter checking */
7746 if (hotkey_report_mode
> 2)
7749 /* Driver-level probe */
7751 ret
= get_thinkpad_model_data(&thinkpad_id
);
7754 "unable to get DMI data: %d\n", ret
);
7755 thinkpad_acpi_module_exit();
7758 ret
= probe_for_thinkpad();
7760 thinkpad_acpi_module_exit();
7764 /* Driver initialization */
7766 TPACPI_ACPIHANDLE_INIT(ecrd
);
7767 TPACPI_ACPIHANDLE_INIT(ecwr
);
7769 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
7771 thinkpad_acpi_module_exit();
7775 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
7778 "unable to create proc dir " TPACPI_PROC_DIR
);
7779 thinkpad_acpi_module_exit();
7783 ret
= platform_driver_register(&tpacpi_pdriver
);
7786 "unable to register main platform driver\n");
7787 thinkpad_acpi_module_exit();
7790 tp_features
.platform_drv_registered
= 1;
7792 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
7795 "unable to register hwmon platform driver\n");
7796 thinkpad_acpi_module_exit();
7799 tp_features
.sensors_pdrv_registered
= 1;
7801 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
7803 tp_features
.platform_drv_attrs_registered
= 1;
7804 ret
= tpacpi_create_driver_attributes(
7805 &tpacpi_hwmon_pdriver
.driver
);
7809 "unable to create sysfs driver attributes\n");
7810 thinkpad_acpi_module_exit();
7813 tp_features
.sensors_pdrv_attrs_registered
= 1;
7816 /* Device initialization */
7817 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
7819 if (IS_ERR(tpacpi_pdev
)) {
7820 ret
= PTR_ERR(tpacpi_pdev
);
7822 printk(TPACPI_ERR
"unable to register platform device\n");
7823 thinkpad_acpi_module_exit();
7826 tpacpi_sensors_pdev
= platform_device_register_simple(
7827 TPACPI_HWMON_DRVR_NAME
,
7829 if (IS_ERR(tpacpi_sensors_pdev
)) {
7830 ret
= PTR_ERR(tpacpi_sensors_pdev
);
7831 tpacpi_sensors_pdev
= NULL
;
7833 "unable to register hwmon platform device\n");
7834 thinkpad_acpi_module_exit();
7837 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
7838 &dev_attr_thinkpad_acpi_pdev_name
);
7841 "unable to create sysfs hwmon device attributes\n");
7842 thinkpad_acpi_module_exit();
7845 tp_features
.sensors_pdev_attrs_registered
= 1;
7846 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
7847 if (IS_ERR(tpacpi_hwmon
)) {
7848 ret
= PTR_ERR(tpacpi_hwmon
);
7849 tpacpi_hwmon
= NULL
;
7850 printk(TPACPI_ERR
"unable to register hwmon device\n");
7851 thinkpad_acpi_module_exit();
7854 mutex_init(&tpacpi_inputdev_send_mutex
);
7855 tpacpi_inputdev
= input_allocate_device();
7856 if (!tpacpi_inputdev
) {
7857 printk(TPACPI_ERR
"unable to allocate input device\n");
7858 thinkpad_acpi_module_exit();
7861 /* Prepare input device, but don't register */
7862 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
7863 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
7864 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
7865 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
7866 thinkpad_id
.vendor
:
7868 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
7869 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
7871 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7872 ret
= ibm_init(&ibms_init
[i
]);
7873 if (ret
>= 0 && *ibms_init
[i
].param
)
7874 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
7876 thinkpad_acpi_module_exit();
7880 ret
= input_register_device(tpacpi_inputdev
);
7882 printk(TPACPI_ERR
"unable to register input device\n");
7883 thinkpad_acpi_module_exit();
7886 tp_features
.input_device_registered
= 1;
7889 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
7893 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
7896 * This will autoload the driver in almost every ThinkPad
7897 * in widespread use.
7899 * Only _VERY_ old models, like the 240, 240x and 570 lack
7900 * the HKEY event interface.
7902 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
7905 * DMI matching for module autoloading
7907 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7908 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
7910 * Only models listed in thinkwiki will be supported, so add yours
7911 * if it is not there yet.
7913 #define IBM_BIOS_MODULE_ALIAS(__type) \
7914 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
7916 /* Ancient thinkpad BIOSes have to be identified by
7917 * BIOS type or model number, and there are far less
7918 * BIOS types than model numbers... */
7919 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
7921 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
7922 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
7923 MODULE_DESCRIPTION(TPACPI_DESC
);
7924 MODULE_VERSION(TPACPI_VERSION
);
7925 MODULE_LICENSE("GPL");
7927 module_init(thinkpad_acpi_module_init
);
7928 module_exit(thinkpad_acpi_module_exit
);