2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define TPACPI_VERSION "0.23"
25 #define TPACPI_SYSFS_VERSION 0x020600
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/sched.h>
58 #include <linux/kthread.h>
59 #include <linux/freezer.h>
60 #include <linux/delay.h>
62 #include <linux/nvram.h>
63 #include <linux/proc_fs.h>
64 #include <linux/sysfs.h>
65 #include <linux/backlight.h>
67 #include <linux/platform_device.h>
68 #include <linux/hwmon.h>
69 #include <linux/hwmon-sysfs.h>
70 #include <linux/input.h>
71 #include <linux/leds.h>
72 #include <linux/rfkill.h>
73 #include <asm/uaccess.h>
75 #include <linux/dmi.h>
76 #include <linux/jiffies.h>
77 #include <linux/workqueue.h>
79 #include <acpi/acpi_drivers.h>
81 #include <linux/pci_ids.h>
84 /* ThinkPad CMOS commands */
85 #define TP_CMOS_VOLUME_DOWN 0
86 #define TP_CMOS_VOLUME_UP 1
87 #define TP_CMOS_VOLUME_MUTE 2
88 #define TP_CMOS_BRIGHTNESS_UP 4
89 #define TP_CMOS_BRIGHTNESS_DOWN 5
90 #define TP_CMOS_THINKLIGHT_ON 12
91 #define TP_CMOS_THINKLIGHT_OFF 13
95 TP_NVRAM_ADDR_HK2
= 0x57,
96 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
97 TP_NVRAM_ADDR_VIDEO
= 0x59,
98 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
99 TP_NVRAM_ADDR_MIXER
= 0x60,
102 /* NVRAM bit masks */
104 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
105 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
106 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
107 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
108 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
109 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
110 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
111 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
112 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
113 TP_NVRAM_MASK_MUTE
= 0x40,
114 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
115 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
116 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
120 #define TPACPI_ACPI_HKEY_HID "IBM0068"
123 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
124 #define TPACPI_HKEY_INPUT_VERSION 0x4101
126 /* ACPI \WGSV commands */
128 TP_ACPI_WGSV_GET_STATE
= 0x01, /* Get state information */
129 TP_ACPI_WGSV_PWR_ON_ON_RESUME
= 0x02, /* Resume WWAN powered on */
130 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
= 0x03, /* Resume WWAN powered off */
131 TP_ACPI_WGSV_SAVE_STATE
= 0x04, /* Save state for S4/S5 */
134 /* TP_ACPI_WGSV_GET_STATE bits */
136 TP_ACPI_WGSV_STATE_WWANEXIST
= 0x0001, /* WWAN hw available */
137 TP_ACPI_WGSV_STATE_WWANPWR
= 0x0002, /* WWAN radio enabled */
138 TP_ACPI_WGSV_STATE_WWANPWRRES
= 0x0004, /* WWAN state at resume */
139 TP_ACPI_WGSV_STATE_WWANBIOSOFF
= 0x0008, /* WWAN disabled in BIOS */
140 TP_ACPI_WGSV_STATE_BLTHEXIST
= 0x0001, /* BLTH hw available */
141 TP_ACPI_WGSV_STATE_BLTHPWR
= 0x0002, /* BLTH radio enabled */
142 TP_ACPI_WGSV_STATE_BLTHPWRRES
= 0x0004, /* BLTH state at resume */
143 TP_ACPI_WGSV_STATE_BLTHBIOSOFF
= 0x0008, /* BLTH disabled in BIOS */
144 TP_ACPI_WGSV_STATE_UWBEXIST
= 0x0010, /* UWB hw available */
145 TP_ACPI_WGSV_STATE_UWBPWR
= 0x0020, /* UWB radio enabled */
149 enum tpacpi_hkey_event_t
{
151 TP_HKEY_EV_HOTKEY_BASE
= 0x1001, /* first hotkey (FN+F1) */
152 TP_HKEY_EV_BRGHT_UP
= 0x1010, /* Brightness up */
153 TP_HKEY_EV_BRGHT_DOWN
= 0x1011, /* Brightness down */
154 TP_HKEY_EV_VOL_UP
= 0x1015, /* Volume up or unmute */
155 TP_HKEY_EV_VOL_DOWN
= 0x1016, /* Volume down or unmute */
156 TP_HKEY_EV_VOL_MUTE
= 0x1017, /* Mixer output mute */
158 /* Reasons for waking up from S3/S4 */
159 TP_HKEY_EV_WKUP_S3_UNDOCK
= 0x2304, /* undock requested, S3 */
160 TP_HKEY_EV_WKUP_S4_UNDOCK
= 0x2404, /* undock requested, S4 */
161 TP_HKEY_EV_WKUP_S3_BAYEJ
= 0x2305, /* bay ejection req, S3 */
162 TP_HKEY_EV_WKUP_S4_BAYEJ
= 0x2405, /* bay ejection req, S4 */
163 TP_HKEY_EV_WKUP_S3_BATLOW
= 0x2313, /* battery empty, S3 */
164 TP_HKEY_EV_WKUP_S4_BATLOW
= 0x2413, /* battery empty, S4 */
166 /* Auto-sleep after eject request */
167 TP_HKEY_EV_BAYEJ_ACK
= 0x3003, /* bay ejection complete */
168 TP_HKEY_EV_UNDOCK_ACK
= 0x4003, /* undock complete */
170 /* Misc bay events */
171 TP_HKEY_EV_OPTDRV_EJ
= 0x3006, /* opt. drive tray ejected */
173 /* User-interface events */
174 TP_HKEY_EV_LID_CLOSE
= 0x5001, /* laptop lid closed */
175 TP_HKEY_EV_LID_OPEN
= 0x5002, /* laptop lid opened */
176 TP_HKEY_EV_TABLET_TABLET
= 0x5009, /* tablet swivel up */
177 TP_HKEY_EV_TABLET_NOTEBOOK
= 0x500a, /* tablet swivel down */
178 TP_HKEY_EV_PEN_INSERTED
= 0x500b, /* tablet pen inserted */
179 TP_HKEY_EV_PEN_REMOVED
= 0x500c, /* tablet pen removed */
180 TP_HKEY_EV_BRGHT_CHANGED
= 0x5010, /* backlight control event */
183 TP_HKEY_EV_ALARM_BAT_HOT
= 0x6011, /* battery too hot */
184 TP_HKEY_EV_ALARM_BAT_XHOT
= 0x6012, /* battery critically hot */
185 TP_HKEY_EV_ALARM_SENSOR_HOT
= 0x6021, /* sensor too hot */
186 TP_HKEY_EV_ALARM_SENSOR_XHOT
= 0x6022, /* sensor critically hot */
187 TP_HKEY_EV_THM_TABLE_CHANGED
= 0x6030, /* thermal table changed */
190 TP_HKEY_EV_RFKILL_CHANGED
= 0x7000, /* rfkill switch changed */
193 /****************************************************************************
197 #define TPACPI_NAME "thinkpad"
198 #define TPACPI_DESC "ThinkPad ACPI Extras"
199 #define TPACPI_FILE TPACPI_NAME "_acpi"
200 #define TPACPI_URL "http://ibm-acpi.sf.net/"
201 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
203 #define TPACPI_PROC_DIR "ibm"
204 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
205 #define TPACPI_DRVR_NAME TPACPI_FILE
206 #define TPACPI_DRVR_SHORTNAME "tpacpi"
207 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
209 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
210 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
212 #define TPACPI_MAX_ACPI_ARGS 3
215 #define TPACPI_LOG TPACPI_FILE ": "
216 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
217 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
218 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
219 #define TPACPI_ERR KERN_ERR TPACPI_LOG
220 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
221 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
222 #define TPACPI_INFO KERN_INFO TPACPI_LOG
223 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
225 /* Debugging printk groups */
226 #define TPACPI_DBG_ALL 0xffff
227 #define TPACPI_DBG_DISCLOSETASK 0x8000
228 #define TPACPI_DBG_INIT 0x0001
229 #define TPACPI_DBG_EXIT 0x0002
230 #define TPACPI_DBG_RFKILL 0x0004
231 #define TPACPI_DBG_HKEY 0x0008
232 #define TPACPI_DBG_FAN 0x0010
233 #define TPACPI_DBG_BRGHT 0x0020
235 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
236 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
237 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
240 /****************************************************************************
241 * Driver-wide structs and misc. variables
246 struct tp_acpi_drv_struct
{
247 const struct acpi_device_id
*hid
;
248 struct acpi_driver
*driver
;
250 void (*notify
) (struct ibm_struct
*, u32
);
253 struct acpi_device
*device
;
259 int (*read
) (char *);
260 int (*write
) (char *);
262 void (*resume
) (void);
263 void (*suspend
) (pm_message_t state
);
264 void (*shutdown
) (void);
266 struct list_head all_drivers
;
268 struct tp_acpi_drv_struct
*acpi
;
271 u8 acpi_driver_registered
:1;
272 u8 acpi_notify_installed
:1;
279 struct ibm_init_struct
{
282 int (*init
) (struct ibm_init_struct
*);
283 struct ibm_struct
*data
;
294 u32 bright_16levels
:1;
295 u32 bright_acpimode
:1;
298 u32 fan_ctrl_status_undef
:1;
300 u32 beep_needs_two_args
:1;
301 u32 input_device_registered
:1;
302 u32 platform_drv_registered
:1;
303 u32 platform_drv_attrs_registered
:1;
304 u32 sensors_pdrv_registered
:1;
305 u32 sensors_pdrv_attrs_registered
:1;
306 u32 sensors_pdev_attrs_registered
:1;
307 u32 hotkey_poll_active
:1;
311 u16 hotkey_mask_ff
:1;
314 struct thinkpad_id_data
{
315 unsigned int vendor
; /* ThinkPad vendor:
316 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
318 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
319 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
321 u16 bios_model
; /* 1Y = 0x5931, 0 = unknown */
323 u16 bios_release
; /* 1ZETK1WW = 0x314b, 0 = unknown */
326 char *model_str
; /* ThinkPad T43 */
327 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
329 static struct thinkpad_id_data thinkpad_id
;
332 TPACPI_LIFE_INIT
= 0,
337 static int experimental
;
338 static u32 dbg_level
;
340 static struct workqueue_struct
*tpacpi_wq
;
348 /* Special LED class that can defer work */
349 struct tpacpi_led_classdev
{
350 struct led_classdev led_classdev
;
351 struct work_struct work
;
352 enum led_status_t new_state
;
356 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
357 static int dbg_wlswemul
;
358 static int tpacpi_wlsw_emulstate
;
359 static int dbg_bluetoothemul
;
360 static int tpacpi_bluetooth_emulstate
;
361 static int dbg_wwanemul
;
362 static int tpacpi_wwan_emulstate
;
363 static int dbg_uwbemul
;
364 static int tpacpi_uwb_emulstate
;
368 /*************************************************************************
372 #define dbg_printk(a_dbg_level, format, arg...) \
373 do { if (dbg_level & (a_dbg_level)) \
374 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
377 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
378 #define vdbg_printk dbg_printk
379 static const char *str_supported(int is_supported
);
381 #define vdbg_printk(a_dbg_level, format, arg...) \
385 static void tpacpi_log_usertask(const char * const what
)
387 printk(TPACPI_DEBUG
"%s: access by process with PID %d\n",
388 what
, task_tgid_vnr(current
));
391 #define tpacpi_disclose_usertask(what, format, arg...) \
394 (dbg_level & TPACPI_DBG_DISCLOSETASK) && \
395 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
396 printk(TPACPI_DEBUG "%s: PID %d: " format, \
397 what, task_tgid_vnr(current), ## arg); \
402 * Quirk handling helpers
404 * ThinkPad IDs and versions seen in the field so far
405 * are two-characters from the set [0-9A-Z], i.e. base 36.
407 * We use values well outside that range as specials.
410 #define TPACPI_MATCH_ANY 0xffffU
411 #define TPACPI_MATCH_UNKNOWN 0U
413 /* TPID('1', 'Y') == 0x5931 */
414 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
416 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
417 { .vendor = PCI_VENDOR_ID_IBM, \
418 .bios = TPID(__id1, __id2), \
419 .ec = TPACPI_MATCH_ANY, \
420 .quirks = (__quirk) }
422 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
423 { .vendor = PCI_VENDOR_ID_LENOVO, \
424 .bios = TPID(__id1, __id2), \
425 .ec = TPACPI_MATCH_ANY, \
426 .quirks = (__quirk) }
428 struct tpacpi_quirk
{
432 unsigned long quirks
;
436 * tpacpi_check_quirks() - search BIOS/EC version on a list
437 * @qlist: array of &struct tpacpi_quirk
438 * @qlist_size: number of elements in @qlist
440 * Iterates over a quirks list until one is found that matches the
441 * ThinkPad's vendor, BIOS and EC model.
443 * Returns 0 if nothing matches, otherwise returns the quirks field of
444 * the matching &struct tpacpi_quirk entry.
446 * The match criteria is: vendor, ec and bios much match.
448 static unsigned long __init
tpacpi_check_quirks(
449 const struct tpacpi_quirk
*qlist
,
450 unsigned int qlist_size
)
453 if ((qlist
->vendor
== thinkpad_id
.vendor
||
454 qlist
->vendor
== TPACPI_MATCH_ANY
) &&
455 (qlist
->bios
== thinkpad_id
.bios_model
||
456 qlist
->bios
== TPACPI_MATCH_ANY
) &&
457 (qlist
->ec
== thinkpad_id
.ec_model
||
458 qlist
->ec
== TPACPI_MATCH_ANY
))
459 return qlist
->quirks
;
468 /****************************************************************************
469 ****************************************************************************
471 * ACPI Helpers and device model
473 ****************************************************************************
474 ****************************************************************************/
476 /*************************************************************************
480 static acpi_handle root_handle
;
482 #define TPACPI_HANDLE(object, parent, paths...) \
483 static acpi_handle object##_handle; \
484 static acpi_handle *object##_parent = &parent##_handle; \
485 static char *object##_path; \
486 static char *object##_paths[] = { paths }
488 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
489 "\\_SB.PCI.ISA.EC", /* 570 */
490 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
491 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
492 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
493 "\\_SB.PCI0.ICH3.EC0", /* R31 */
494 "\\_SB.PCI0.LPC.EC", /* all others */
497 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
498 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
500 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
502 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
503 "\\CMS", /* R40, R40e */
506 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
507 "^HKEY", /* R30, R31 */
508 "HKEY", /* all others */
511 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
512 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
513 "\\_SB.PCI0.VID0", /* 770e */
514 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
515 "\\_SB.PCI0.AGP.VID", /* all others */
519 /*************************************************************************
523 static int acpi_evalf(acpi_handle handle
,
524 void *res
, char *method
, char *fmt
, ...)
527 struct acpi_object_list params
;
528 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
529 struct acpi_buffer result
, *resultp
;
530 union acpi_object out_obj
;
538 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
551 params
.pointer
= &in_objs
[0];
558 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
559 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
561 /* add more types as needed */
563 printk(TPACPI_ERR
"acpi_evalf() called "
564 "with invalid format character '%c'\n", c
);
570 if (res_type
!= 'v') {
571 result
.length
= sizeof(out_obj
);
572 result
.pointer
= &out_obj
;
577 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
582 *(int *)res
= out_obj
.integer
.value
;
583 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
586 success
= status
== AE_OK
;
588 /* add more types as needed */
590 printk(TPACPI_ERR
"acpi_evalf() called "
591 "with invalid format character '%c'\n", res_type
);
595 if (!success
&& !quiet
)
596 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
597 method
, fmt0
, status
);
602 static int acpi_ec_read(int i
, u8
*p
)
607 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
611 if (ec_read(i
, p
) < 0)
618 static int acpi_ec_write(int i
, u8 v
)
621 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
624 if (ec_write(i
, v
) < 0)
631 static int issue_thinkpad_cmos_command(int cmos_cmd
)
636 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
642 /*************************************************************************
646 #define TPACPI_ACPIHANDLE_INIT(object) \
647 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
648 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
650 static void drv_acpi_handle_init(char *name
,
651 acpi_handle
*handle
, acpi_handle parent
,
652 char **paths
, int num_paths
, char **path
)
657 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
660 for (i
= 0; i
< num_paths
; i
++) {
661 status
= acpi_get_handle(parent
, paths
[i
], handle
);
662 if (ACPI_SUCCESS(status
)) {
664 dbg_printk(TPACPI_DBG_INIT
,
665 "Found ACPI handle %s for %s\n",
671 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
676 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
678 struct ibm_struct
*ibm
= data
;
680 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
683 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
686 ibm
->acpi
->notify(ibm
, event
);
689 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
696 if (!*ibm
->acpi
->handle
)
699 vdbg_printk(TPACPI_DBG_INIT
,
700 "setting up ACPI notify for %s\n", ibm
->name
);
702 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
704 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
709 ibm
->acpi
->device
->driver_data
= ibm
;
710 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
711 TPACPI_ACPI_EVENT_PREFIX
,
714 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
715 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
716 if (ACPI_FAILURE(status
)) {
717 if (status
== AE_ALREADY_EXISTS
) {
719 "another device driver is already "
720 "handling %s events\n", ibm
->name
);
723 "acpi_install_notify_handler(%s) failed: %d\n",
728 ibm
->flags
.acpi_notify_installed
= 1;
732 static int __init
tpacpi_device_add(struct acpi_device
*device
)
737 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
741 dbg_printk(TPACPI_DBG_INIT
,
742 "registering %s as an ACPI driver\n", ibm
->name
);
746 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
747 if (!ibm
->acpi
->driver
) {
749 "failed to allocate memory for ibm->acpi->driver\n");
753 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
754 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
756 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
758 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
760 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
762 kfree(ibm
->acpi
->driver
);
763 ibm
->acpi
->driver
= NULL
;
765 ibm
->flags
.acpi_driver_registered
= 1;
771 /****************************************************************************
772 ****************************************************************************
776 ****************************************************************************
777 ****************************************************************************/
779 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
780 int count
, int *eof
, void *data
)
782 struct ibm_struct
*ibm
= data
;
785 if (!ibm
|| !ibm
->read
)
788 len
= ibm
->read(page
);
792 if (len
<= off
+ count
)
804 static int dispatch_procfs_write(struct file
*file
,
805 const char __user
*userbuf
,
806 unsigned long count
, void *data
)
808 struct ibm_struct
*ibm
= data
;
812 if (!ibm
|| !ibm
->write
)
814 if (count
> PAGE_SIZE
- 2)
817 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
821 if (copy_from_user(kernbuf
, userbuf
, count
)) {
827 strcat(kernbuf
, ",");
828 ret
= ibm
->write(kernbuf
);
837 static char *next_cmd(char **cmds
)
842 while ((end
= strchr(start
, ',')) && end
== start
)
854 /****************************************************************************
855 ****************************************************************************
857 * Device model: input, hwmon and platform
859 ****************************************************************************
860 ****************************************************************************/
862 static struct platform_device
*tpacpi_pdev
;
863 static struct platform_device
*tpacpi_sensors_pdev
;
864 static struct device
*tpacpi_hwmon
;
865 static struct input_dev
*tpacpi_inputdev
;
866 static struct mutex tpacpi_inputdev_send_mutex
;
867 static LIST_HEAD(tpacpi_all_drivers
);
869 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
872 struct ibm_struct
*ibm
, *itmp
;
874 list_for_each_entry_safe(ibm
, itmp
,
878 (ibm
->suspend
)(state
);
884 static int tpacpi_resume_handler(struct platform_device
*pdev
)
886 struct ibm_struct
*ibm
, *itmp
;
888 list_for_each_entry_safe(ibm
, itmp
,
898 static void tpacpi_shutdown_handler(struct platform_device
*pdev
)
900 struct ibm_struct
*ibm
, *itmp
;
902 list_for_each_entry_safe(ibm
, itmp
,
910 static struct platform_driver tpacpi_pdriver
= {
912 .name
= TPACPI_DRVR_NAME
,
913 .owner
= THIS_MODULE
,
915 .suspend
= tpacpi_suspend_handler
,
916 .resume
= tpacpi_resume_handler
,
917 .shutdown
= tpacpi_shutdown_handler
,
920 static struct platform_driver tpacpi_hwmon_pdriver
= {
922 .name
= TPACPI_HWMON_DRVR_NAME
,
923 .owner
= THIS_MODULE
,
927 /*************************************************************************
928 * sysfs support helpers
931 struct attribute_set
{
932 unsigned int members
, max_members
;
933 struct attribute_group group
;
936 struct attribute_set_obj
{
937 struct attribute_set s
;
939 } __attribute__((packed
));
941 static struct attribute_set
*create_attr_set(unsigned int max_members
,
944 struct attribute_set_obj
*sobj
;
946 if (max_members
== 0)
949 /* Allocates space for implicit NULL at the end too */
950 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
951 max_members
* sizeof(struct attribute
*),
955 sobj
->s
.max_members
= max_members
;
956 sobj
->s
.group
.attrs
= &sobj
->a
;
957 sobj
->s
.group
.name
= name
;
962 #define destroy_attr_set(_set) \
965 /* not multi-threaded safe, use it in a single thread per set */
966 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
971 if (s
->members
>= s
->max_members
)
974 s
->group
.attrs
[s
->members
] = attr
;
980 static int add_many_to_attr_set(struct attribute_set
*s
,
981 struct attribute
**attr
,
986 for (i
= 0; i
< count
; i
++) {
987 res
= add_to_attr_set(s
, attr
[i
]);
995 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
997 sysfs_remove_group(kobj
, &s
->group
);
1001 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
1002 sysfs_create_group(_kobj, &_attr_set->group)
1004 static int parse_strtoul(const char *buf
,
1005 unsigned long max
, unsigned long *value
)
1009 *value
= simple_strtoul(skip_spaces(buf
), &endp
, 0);
1010 endp
= skip_spaces(endp
);
1011 if (*endp
|| *value
> max
)
1017 static void tpacpi_disable_brightness_delay(void)
1019 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
1020 printk(TPACPI_NOTICE
1021 "ACPI backlight control delay disabled\n");
1024 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
1026 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1027 union acpi_object
*obj
;
1030 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
1031 obj
= (union acpi_object
*)buffer
.pointer
;
1032 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
1033 printk(TPACPI_ERR
"Unknown _BCL data, "
1034 "please report this to %s\n", TPACPI_MAIL
);
1037 rc
= obj
->package
.count
;
1043 kfree(buffer
.pointer
);
1047 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1048 u32 lvl
, void *context
, void **rv
)
1050 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1051 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1053 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1054 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1055 BUG_ON(!rv
|| !*rv
);
1056 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1057 return AE_CTRL_TERMINATE
;
1064 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1066 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1070 void *bcl_ptr
= &bcl_levels
;
1073 TPACPI_ACPIHANDLE_INIT(vid
);
1079 * Search for a _BCL method, and execute it. This is safe on all
1080 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1081 * BIOS in ACPI backlight control mode. We do NOT have to care
1082 * about calling the _BCL method in an enabled video device, any
1083 * will do for our purposes.
1086 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1087 tpacpi_acpi_walk_find_bcl
, NULL
, NULL
,
1090 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1091 tp_features
.bright_acpimode
= 1;
1092 return (bcl_levels
- 2);
1098 static void printk_deprecated_attribute(const char * const what
,
1099 const char * const details
)
1101 tpacpi_log_usertask("deprecated sysfs attribute");
1102 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1103 "will be removed. %s\n",
1107 /*************************************************************************
1108 * rfkill and radio control support helpers
1112 * ThinkPad-ACPI firmware handling model:
1114 * WLSW (master wireless switch) is event-driven, and is common to all
1115 * firmware-controlled radios. It cannot be controlled, just monitored,
1116 * as expected. It overrides all radio state in firmware
1118 * The kernel, a masked-off hotkey, and WLSW can change the radio state
1119 * (TODO: verify how WLSW interacts with the returned radio state).
1121 * The only time there are shadow radio state changes, is when
1122 * masked-off hotkeys are used.
1126 * Internal driver API for radio state:
1128 * int: < 0 = error, otherwise enum tpacpi_rfkill_state
1129 * bool: true means radio blocked (off)
1131 enum tpacpi_rfkill_state
{
1132 TPACPI_RFK_RADIO_OFF
= 0,
1136 /* rfkill switches */
1137 enum tpacpi_rfk_id
{
1138 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
1139 TPACPI_RFK_WWAN_SW_ID
,
1140 TPACPI_RFK_UWB_SW_ID
,
1144 static const char *tpacpi_rfkill_names
[] = {
1145 [TPACPI_RFK_BLUETOOTH_SW_ID
] = "bluetooth",
1146 [TPACPI_RFK_WWAN_SW_ID
] = "wwan",
1147 [TPACPI_RFK_UWB_SW_ID
] = "uwb",
1148 [TPACPI_RFK_SW_MAX
] = NULL
1151 /* ThinkPad-ACPI rfkill subdriver */
1153 struct rfkill
*rfkill
;
1154 enum tpacpi_rfk_id id
;
1155 const struct tpacpi_rfk_ops
*ops
;
1158 struct tpacpi_rfk_ops
{
1159 /* firmware interface */
1160 int (*get_status
)(void);
1161 int (*set_status
)(const enum tpacpi_rfkill_state
);
1164 static struct tpacpi_rfk
*tpacpi_rfkill_switches
[TPACPI_RFK_SW_MAX
];
1166 /* Query FW and update rfkill sw state for a given rfkill switch */
1167 static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk
*tp_rfk
)
1174 status
= (tp_rfk
->ops
->get_status
)();
1178 rfkill_set_sw_state(tp_rfk
->rfkill
,
1179 (status
== TPACPI_RFK_RADIO_OFF
));
1184 /* Query FW and update rfkill sw state for all rfkill switches */
1185 static void tpacpi_rfk_update_swstate_all(void)
1189 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++)
1190 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[i
]);
1194 * Sync the HW-blocking state of all rfkill switches,
1195 * do notice it causes the rfkill core to schedule uevents
1197 static void tpacpi_rfk_update_hwblock_state(bool blocked
)
1200 struct tpacpi_rfk
*tp_rfk
;
1202 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++) {
1203 tp_rfk
= tpacpi_rfkill_switches
[i
];
1205 if (rfkill_set_hw_state(tp_rfk
->rfkill
,
1207 /* ignore -- we track sw block */
1213 /* Call to get the WLSW state from the firmware */
1214 static int hotkey_get_wlsw(void);
1216 /* Call to query WLSW state and update all rfkill switches */
1217 static bool tpacpi_rfk_check_hwblock_state(void)
1219 int res
= hotkey_get_wlsw();
1222 /* When unknown or unsupported, we have to assume it is unblocked */
1226 hw_blocked
= (res
== TPACPI_RFK_RADIO_OFF
);
1227 tpacpi_rfk_update_hwblock_state(hw_blocked
);
1232 static int tpacpi_rfk_hook_set_block(void *data
, bool blocked
)
1234 struct tpacpi_rfk
*tp_rfk
= data
;
1237 dbg_printk(TPACPI_DBG_RFKILL
,
1238 "request to change radio state to %s\n",
1239 blocked
? "blocked" : "unblocked");
1241 /* try to set radio state */
1242 res
= (tp_rfk
->ops
->set_status
)(blocked
?
1243 TPACPI_RFK_RADIO_OFF
: TPACPI_RFK_RADIO_ON
);
1245 /* and update the rfkill core with whatever the FW really did */
1246 tpacpi_rfk_update_swstate(tp_rfk
);
1248 return (res
< 0) ? res
: 0;
1251 static const struct rfkill_ops tpacpi_rfk_rfkill_ops
= {
1252 .set_block
= tpacpi_rfk_hook_set_block
,
1255 static int __init
tpacpi_new_rfkill(const enum tpacpi_rfk_id id
,
1256 const struct tpacpi_rfk_ops
*tp_rfkops
,
1257 const enum rfkill_type rfktype
,
1259 const bool set_default
)
1261 struct tpacpi_rfk
*atp_rfk
;
1263 bool sw_state
= false;
1266 BUG_ON(id
>= TPACPI_RFK_SW_MAX
|| tpacpi_rfkill_switches
[id
]);
1268 atp_rfk
= kzalloc(sizeof(struct tpacpi_rfk
), GFP_KERNEL
);
1270 atp_rfk
->rfkill
= rfkill_alloc(name
,
1273 &tpacpi_rfk_rfkill_ops
,
1275 if (!atp_rfk
|| !atp_rfk
->rfkill
) {
1277 "failed to allocate memory for rfkill class\n");
1283 atp_rfk
->ops
= tp_rfkops
;
1285 sw_status
= (tp_rfkops
->get_status
)();
1286 if (sw_status
< 0) {
1288 "failed to read initial state for %s, error %d\n",
1291 sw_state
= (sw_status
== TPACPI_RFK_RADIO_OFF
);
1293 /* try to keep the initial state, since we ask the
1294 * firmware to preserve it across S5 in NVRAM */
1295 rfkill_init_sw_state(atp_rfk
->rfkill
, sw_state
);
1298 rfkill_set_hw_state(atp_rfk
->rfkill
, tpacpi_rfk_check_hwblock_state());
1300 res
= rfkill_register(atp_rfk
->rfkill
);
1303 "failed to register %s rfkill switch: %d\n",
1305 rfkill_destroy(atp_rfk
->rfkill
);
1310 tpacpi_rfkill_switches
[id
] = atp_rfk
;
1314 static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id
)
1316 struct tpacpi_rfk
*tp_rfk
;
1318 BUG_ON(id
>= TPACPI_RFK_SW_MAX
);
1320 tp_rfk
= tpacpi_rfkill_switches
[id
];
1322 rfkill_unregister(tp_rfk
->rfkill
);
1323 rfkill_destroy(tp_rfk
->rfkill
);
1324 tpacpi_rfkill_switches
[id
] = NULL
;
1329 static void printk_deprecated_rfkill_attribute(const char * const what
)
1331 printk_deprecated_attribute(what
,
1332 "Please switch to generic rfkill before year 2010");
1335 /* sysfs <radio> enable ------------------------------------------------ */
1336 static ssize_t
tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id
,
1337 struct device_attribute
*attr
,
1342 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1344 /* This is in the ABI... */
1345 if (tpacpi_rfk_check_hwblock_state()) {
1346 status
= TPACPI_RFK_RADIO_OFF
;
1348 status
= tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1353 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1354 (status
== TPACPI_RFK_RADIO_ON
) ? 1 : 0);
1357 static ssize_t
tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id
,
1358 struct device_attribute
*attr
,
1359 const char *buf
, size_t count
)
1364 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1366 if (parse_strtoul(buf
, 1, &t
))
1369 tpacpi_disclose_usertask(attr
->attr
.name
, "set to %ld\n", t
);
1371 /* This is in the ABI... */
1372 if (tpacpi_rfk_check_hwblock_state() && !!t
)
1375 res
= tpacpi_rfkill_switches
[id
]->ops
->set_status((!!t
) ?
1376 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
);
1377 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1379 return (res
< 0) ? res
: count
;
1382 /* procfs -------------------------------------------------------------- */
1383 static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id
, char *p
)
1387 if (id
>= TPACPI_RFK_SW_MAX
)
1388 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1392 /* This is in the ABI... */
1393 if (tpacpi_rfk_check_hwblock_state()) {
1394 status
= TPACPI_RFK_RADIO_OFF
;
1396 status
= tpacpi_rfk_update_swstate(
1397 tpacpi_rfkill_switches
[id
]);
1402 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1403 (status
== TPACPI_RFK_RADIO_ON
) ?
1404 "enabled" : "disabled");
1405 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1411 static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id
, char *buf
)
1417 if (id
>= TPACPI_RFK_SW_MAX
)
1420 while ((cmd
= next_cmd(&buf
))) {
1421 if (strlencmp(cmd
, "enable") == 0)
1422 status
= TPACPI_RFK_RADIO_ON
;
1423 else if (strlencmp(cmd
, "disable") == 0)
1424 status
= TPACPI_RFK_RADIO_OFF
;
1430 tpacpi_disclose_usertask("procfs", "attempt to %s %s\n",
1431 (status
== TPACPI_RFK_RADIO_ON
) ?
1432 "enable" : "disable",
1433 tpacpi_rfkill_names
[id
]);
1434 res
= (tpacpi_rfkill_switches
[id
]->ops
->set_status
)(status
);
1435 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1441 /*************************************************************************
1442 * thinkpad-acpi driver attributes
1445 /* interface_version --------------------------------------------------- */
1446 static ssize_t
tpacpi_driver_interface_version_show(
1447 struct device_driver
*drv
,
1450 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1453 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1454 tpacpi_driver_interface_version_show
, NULL
);
1456 /* debug_level --------------------------------------------------------- */
1457 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1460 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1463 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1464 const char *buf
, size_t count
)
1468 if (parse_strtoul(buf
, 0xffff, &t
))
1476 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1477 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1479 /* version ------------------------------------------------------------- */
1480 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1483 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1484 TPACPI_DESC
, TPACPI_VERSION
);
1487 static DRIVER_ATTR(version
, S_IRUGO
,
1488 tpacpi_driver_version_show
, NULL
);
1490 /* --------------------------------------------------------------------- */
1492 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1494 /* wlsw_emulstate ------------------------------------------------------ */
1495 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1498 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1501 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1502 const char *buf
, size_t count
)
1506 if (parse_strtoul(buf
, 1, &t
))
1509 if (tpacpi_wlsw_emulstate
!= !!t
) {
1510 tpacpi_wlsw_emulstate
= !!t
;
1511 tpacpi_rfk_update_hwblock_state(!t
); /* negative logic */
1517 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1518 tpacpi_driver_wlsw_emulstate_show
,
1519 tpacpi_driver_wlsw_emulstate_store
);
1521 /* bluetooth_emulstate ------------------------------------------------- */
1522 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1523 struct device_driver
*drv
,
1526 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1529 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1530 struct device_driver
*drv
,
1531 const char *buf
, size_t count
)
1535 if (parse_strtoul(buf
, 1, &t
))
1538 tpacpi_bluetooth_emulstate
= !!t
;
1543 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1544 tpacpi_driver_bluetooth_emulstate_show
,
1545 tpacpi_driver_bluetooth_emulstate_store
);
1547 /* wwan_emulstate ------------------------------------------------- */
1548 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1549 struct device_driver
*drv
,
1552 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1555 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1556 struct device_driver
*drv
,
1557 const char *buf
, size_t count
)
1561 if (parse_strtoul(buf
, 1, &t
))
1564 tpacpi_wwan_emulstate
= !!t
;
1569 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1570 tpacpi_driver_wwan_emulstate_show
,
1571 tpacpi_driver_wwan_emulstate_store
);
1573 /* uwb_emulstate ------------------------------------------------- */
1574 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1575 struct device_driver
*drv
,
1578 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1581 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1582 struct device_driver
*drv
,
1583 const char *buf
, size_t count
)
1587 if (parse_strtoul(buf
, 1, &t
))
1590 tpacpi_uwb_emulstate
= !!t
;
1595 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1596 tpacpi_driver_uwb_emulstate_show
,
1597 tpacpi_driver_uwb_emulstate_store
);
1600 /* --------------------------------------------------------------------- */
1602 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1603 &driver_attr_debug_level
, &driver_attr_version
,
1604 &driver_attr_interface_version
,
1607 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1613 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1614 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1618 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1619 if (!res
&& dbg_wlswemul
)
1620 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1621 if (!res
&& dbg_bluetoothemul
)
1622 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1623 if (!res
&& dbg_wwanemul
)
1624 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1625 if (!res
&& dbg_uwbemul
)
1626 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1632 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1636 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1637 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1639 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1640 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1641 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1642 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1643 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1647 /*************************************************************************
1652 * Table of recommended minimum BIOS versions
1654 * Reasons for listing:
1655 * 1. Stable BIOS, listed because the unknown ammount of
1656 * bugs and bad ACPI behaviour on older versions
1658 * 2. BIOS or EC fw with known bugs that trigger on Linux
1660 * 3. BIOS with known reduced functionality in older versions
1662 * We recommend the latest BIOS and EC version.
1663 * We only support the latest BIOS and EC fw version as a rule.
1665 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1666 * Information from users in ThinkWiki
1668 * WARNING: we use this table also to detect that the machine is
1669 * a ThinkPad in some cases, so don't remove entries lightly.
1672 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1673 { .vendor = (__v), \
1674 .bios = TPID(__id1, __id2), \
1675 .ec = TPACPI_MATCH_ANY, \
1676 .quirks = TPACPI_MATCH_ANY << 16 \
1677 | (__bv1) << 8 | (__bv2) }
1679 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1680 __eid, __ev1, __ev2) \
1681 { .vendor = (__v), \
1682 .bios = TPID(__bid1, __bid2), \
1684 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1685 | (__bv1) << 8 | (__bv2) }
1687 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1688 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1690 /* Outdated IBM BIOSes often lack the EC id string */
1691 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1692 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1693 __bv1, __bv2, TPID(__id1, __id2), \
1695 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1696 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1699 /* Outdated IBM BIOSes often lack the EC id string */
1700 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1701 __eid1, __eid2, __ev1, __ev2) \
1702 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1703 __bv1, __bv2, TPID(__eid1, __eid2), \
1705 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1706 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1709 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1710 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1712 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1713 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1714 __bv1, __bv2, TPID(__id1, __id2), \
1717 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1718 __eid1, __eid2, __ev1, __ev2) \
1719 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1720 __bv1, __bv2, TPID(__eid1, __eid2), \
1723 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1724 /* Numeric models ------------------ */
1725 /* FW MODEL BIOS VERS */
1726 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1727 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1728 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1729 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1730 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1731 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1732 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1733 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1734 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1736 /* A-series ------------------------- */
1737 /* FW MODEL BIOS VERS EC VERS */
1738 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1739 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1740 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1741 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1742 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1743 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1744 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1745 TPV_QI0('1', '3', '2', '0'), /* A22m */
1746 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1747 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1748 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1750 /* G-series ------------------------- */
1751 /* FW MODEL BIOS VERS */
1752 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1753 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1755 /* R-series, T-series --------------- */
1756 /* FW MODEL BIOS VERS EC VERS */
1757 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1758 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1759 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1760 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1761 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1762 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1763 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1764 T40/p, T41/p, T42/p (1) */
1765 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1766 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1767 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1768 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1770 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1771 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1772 TPV_QI0('1', '6', '3', '2'), /* T22 */
1773 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1774 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1775 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1777 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1778 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1779 TPV_QL0('7', 'E', 'D', '0'), /* R60e, R60i */
1781 /* BIOS FW BIOS VERS EC FW EC VERS */
1782 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1783 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1785 /* X-series ------------------------- */
1786 /* FW MODEL BIOS VERS EC VERS */
1787 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1788 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1789 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1790 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1791 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1792 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1793 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1795 TPV_QL0('7', 'B', 'D', '7'), /* X60/s */
1796 TPV_QL0('7', 'J', '3', '0'), /* X60t */
1798 /* (0) - older versions lack DMI EC fw string and functionality */
1799 /* (1) - older versions known to lack functionality */
1810 static void __init
tpacpi_check_outdated_fw(void)
1812 unsigned long fwvers
;
1813 u16 ec_version
, bios_version
;
1815 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1816 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1821 bios_version
= fwvers
& 0xffffU
;
1822 ec_version
= (fwvers
>> 16) & 0xffffU
;
1824 /* note that unknown versions are set to 0x0000 and we use that */
1825 if ((bios_version
> thinkpad_id
.bios_release
) ||
1826 (ec_version
> thinkpad_id
.ec_release
&&
1827 ec_version
!= TPACPI_MATCH_ANY
)) {
1829 * The changelogs would let us track down the exact
1830 * reason, but it is just too much of a pain to track
1831 * it. We only list BIOSes that are either really
1832 * broken, or really stable to begin with, so it is
1833 * best if the user upgrades the firmware anyway.
1836 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1838 "WARNING: This firmware may be missing critical bug "
1839 "fixes and/or important features\n");
1843 static bool __init
tpacpi_is_fw_known(void)
1845 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1846 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1849 /****************************************************************************
1850 ****************************************************************************
1854 ****************************************************************************
1855 ****************************************************************************/
1857 /*************************************************************************
1858 * thinkpad-acpi init subdriver
1861 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1863 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1864 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1866 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1867 (thinkpad_id
.bios_version_str
) ?
1868 thinkpad_id
.bios_version_str
: "unknown",
1869 (thinkpad_id
.ec_version_str
) ?
1870 thinkpad_id
.ec_version_str
: "unknown");
1872 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1873 printk(TPACPI_INFO
"%s %s, model %s\n",
1874 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1875 "IBM" : ((thinkpad_id
.vendor
==
1876 PCI_VENDOR_ID_LENOVO
) ?
1877 "Lenovo" : "Unknown vendor"),
1878 thinkpad_id
.model_str
,
1879 (thinkpad_id
.nummodel_str
) ?
1880 thinkpad_id
.nummodel_str
: "unknown");
1882 tpacpi_check_outdated_fw();
1886 static int thinkpad_acpi_driver_read(char *p
)
1890 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1891 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1896 static struct ibm_struct thinkpad_acpi_driver_data
= {
1898 .read
= thinkpad_acpi_driver_read
,
1901 /*************************************************************************
1906 * ThinkPad firmware event model
1908 * The ThinkPad firmware has two main event interfaces: normal ACPI
1909 * notifications (which follow the ACPI standard), and a private event
1912 * The private event interface also issues events for the hotkeys. As
1913 * the driver gained features, the event handling code ended up being
1914 * built around the hotkey subdriver. This will need to be refactored
1915 * to a more formal event API eventually.
1917 * Some "hotkeys" are actually supposed to be used as event reports,
1918 * such as "brightness has changed", "volume has changed", depending on
1919 * the ThinkPad model and how the firmware is operating.
1921 * Unlike other classes, hotkey-class events have mask/unmask control on
1922 * non-ancient firmware. However, how it behaves changes a lot with the
1923 * firmware model and version.
1926 enum { /* hot key scan codes (derived from ACPI DSDT) */
1927 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1928 TP_ACPI_HOTKEYSCAN_FNF2
,
1929 TP_ACPI_HOTKEYSCAN_FNF3
,
1930 TP_ACPI_HOTKEYSCAN_FNF4
,
1931 TP_ACPI_HOTKEYSCAN_FNF5
,
1932 TP_ACPI_HOTKEYSCAN_FNF6
,
1933 TP_ACPI_HOTKEYSCAN_FNF7
,
1934 TP_ACPI_HOTKEYSCAN_FNF8
,
1935 TP_ACPI_HOTKEYSCAN_FNF9
,
1936 TP_ACPI_HOTKEYSCAN_FNF10
,
1937 TP_ACPI_HOTKEYSCAN_FNF11
,
1938 TP_ACPI_HOTKEYSCAN_FNF12
,
1939 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1940 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1941 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1942 TP_ACPI_HOTKEYSCAN_FNHOME
,
1943 TP_ACPI_HOTKEYSCAN_FNEND
,
1944 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1945 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1946 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1947 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1948 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1949 TP_ACPI_HOTKEYSCAN_MUTE
,
1950 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1953 enum { /* Keys/events available through NVRAM polling */
1954 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1955 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1958 enum { /* Positions of some of the keys in hotkey masks */
1959 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1960 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1961 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1962 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1963 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1964 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1965 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1966 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1967 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1968 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1969 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1972 enum { /* NVRAM to ACPI HKEY group map */
1973 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1974 TP_ACPI_HKEY_ZOOM_MASK
|
1975 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1976 TP_ACPI_HKEY_HIBERNATE_MASK
,
1977 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1978 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1979 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1980 TP_ACPI_HKEY_VOLDWN_MASK
|
1981 TP_ACPI_HKEY_MUTE_MASK
,
1984 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1985 struct tp_nvram_state
{
1986 u16 thinkpad_toggle
:1;
1988 u16 display_toggle
:1;
1989 u16 thinklight_toggle
:1;
1990 u16 hibernate_toggle
:1;
1991 u16 displayexp_toggle
:1;
1992 u16 display_state
:1;
1993 u16 brightness_toggle
:1;
1994 u16 volume_toggle
:1;
1997 u8 brightness_level
;
2001 /* kthread for the hotkey poller */
2002 static struct task_struct
*tpacpi_hotkey_task
;
2004 /* Acquired while the poller kthread is running, use to sync start/stop */
2005 static struct mutex hotkey_thread_mutex
;
2008 * Acquire mutex to write poller control variables as an
2011 * Increment hotkey_config_change when changing them if you
2012 * want the kthread to forget old state.
2014 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2016 static struct mutex hotkey_thread_data_mutex
;
2017 static unsigned int hotkey_config_change
;
2020 * hotkey poller control variables
2022 * Must be atomic or readers will also need to acquire mutex
2024 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2025 * should be used only when the changes need to be taken as
2026 * a block, OR when one needs to force the kthread to forget
2029 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
2030 static unsigned int hotkey_poll_freq
= 10; /* Hz */
2032 #define HOTKEY_CONFIG_CRITICAL_START \
2034 mutex_lock(&hotkey_thread_data_mutex); \
2035 hotkey_config_change++; \
2037 #define HOTKEY_CONFIG_CRITICAL_END \
2038 mutex_unlock(&hotkey_thread_data_mutex);
2040 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2042 #define hotkey_source_mask 0U
2043 #define HOTKEY_CONFIG_CRITICAL_START
2044 #define HOTKEY_CONFIG_CRITICAL_END
2046 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2048 static struct mutex hotkey_mutex
;
2050 static enum { /* Reasons for waking up */
2051 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
2052 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
2053 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
2054 } hotkey_wakeup_reason
;
2056 static int hotkey_autosleep_ack
;
2058 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
2059 static u32 hotkey_all_mask
; /* all events supported in fw */
2060 static u32 hotkey_reserved_mask
; /* events better left disabled */
2061 static u32 hotkey_driver_mask
; /* events needed by the driver */
2062 static u32 hotkey_user_mask
; /* events visible to userspace */
2063 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
2065 static unsigned int hotkey_report_mode
;
2067 static u16
*hotkey_keycode_map
;
2069 static struct attribute_set
*hotkey_dev_attributes
;
2071 static void tpacpi_driver_event(const unsigned int hkey_event
);
2072 static void hotkey_driver_event(const unsigned int scancode
);
2074 /* HKEY.MHKG() return bits */
2075 #define TP_HOTKEY_TABLET_MASK (1 << 3)
2077 static int hotkey_get_wlsw(void)
2081 if (!tp_features
.hotkey_wlsw
)
2084 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2086 return (tpacpi_wlsw_emulstate
) ?
2087 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2090 if (!acpi_evalf(hkey_handle
, &status
, "WLSW", "d"))
2093 return (status
) ? TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2096 static int hotkey_get_tablet_mode(int *status
)
2100 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
2103 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
2108 * Reads current event mask from firmware, and updates
2109 * hotkey_acpi_mask accordingly. Also resets any bits
2110 * from hotkey_user_mask that are unavailable to be
2111 * delivered (shadow requirement of the userspace ABI).
2113 * Call with hotkey_mutex held
2115 static int hotkey_mask_get(void)
2117 if (tp_features
.hotkey_mask
) {
2120 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
2123 hotkey_acpi_mask
= m
;
2125 /* no mask support doesn't mean no event support... */
2126 hotkey_acpi_mask
= hotkey_all_mask
;
2129 /* sync userspace-visible mask */
2130 hotkey_user_mask
&= (hotkey_acpi_mask
| hotkey_source_mask
);
2135 void static hotkey_mask_warn_incomplete_mask(void)
2137 /* log only what the user can fix... */
2138 const u32 wantedmask
= hotkey_driver_mask
&
2139 ~(hotkey_acpi_mask
| hotkey_source_mask
) &
2140 (hotkey_all_mask
| TPACPI_HKEY_NVRAM_KNOWN_MASK
);
2143 printk(TPACPI_NOTICE
2144 "required events 0x%08x not enabled!\n",
2149 * Set the firmware mask when supported
2151 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
2153 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
2155 * Call with hotkey_mutex held
2157 static int hotkey_mask_set(u32 mask
)
2162 const u32 fwmask
= mask
& ~hotkey_source_mask
;
2164 if (tp_features
.hotkey_mask
) {
2165 for (i
= 0; i
< 32; i
++) {
2166 if (!acpi_evalf(hkey_handle
,
2167 NULL
, "MHKM", "vdd", i
+ 1,
2168 !!(mask
& (1 << i
)))) {
2176 * We *must* make an inconditional call to hotkey_mask_get to
2177 * refresh hotkey_acpi_mask and update hotkey_user_mask
2179 * Take the opportunity to also log when we cannot _enable_
2182 if (!hotkey_mask_get() && !rc
&& (fwmask
& ~hotkey_acpi_mask
)) {
2183 printk(TPACPI_NOTICE
2184 "asked for hotkey mask 0x%08x, but "
2185 "firmware forced it to 0x%08x\n",
2186 fwmask
, hotkey_acpi_mask
);
2189 hotkey_mask_warn_incomplete_mask();
2195 * Sets hotkey_user_mask and tries to set the firmware mask
2197 * Call with hotkey_mutex held
2199 static int hotkey_user_mask_set(const u32 mask
)
2203 /* Give people a chance to notice they are doing something that
2204 * is bound to go boom on their users sooner or later */
2205 if (!tp_warned
.hotkey_mask_ff
&&
2206 (mask
== 0xffff || mask
== 0xffffff ||
2207 mask
== 0xffffffff)) {
2208 tp_warned
.hotkey_mask_ff
= 1;
2209 printk(TPACPI_NOTICE
2210 "setting the hotkey mask to 0x%08x is likely "
2211 "not the best way to go about it\n", mask
);
2212 printk(TPACPI_NOTICE
2213 "please consider using the driver defaults, "
2214 "and refer to up-to-date thinkpad-acpi "
2218 /* Try to enable what the user asked for, plus whatever we need.
2219 * this syncs everything but won't enable bits in hotkey_user_mask */
2220 rc
= hotkey_mask_set((mask
| hotkey_driver_mask
) & ~hotkey_source_mask
);
2222 /* Enable the available bits in hotkey_user_mask */
2223 hotkey_user_mask
= mask
& (hotkey_acpi_mask
| hotkey_source_mask
);
2229 * Sets the driver hotkey mask.
2231 * Can be called even if the hotkey subdriver is inactive
2233 static int tpacpi_hotkey_driver_mask_set(const u32 mask
)
2237 /* Do the right thing if hotkey_init has not been called yet */
2238 if (!tp_features
.hotkey
) {
2239 hotkey_driver_mask
= mask
;
2243 mutex_lock(&hotkey_mutex
);
2245 HOTKEY_CONFIG_CRITICAL_START
2246 hotkey_driver_mask
= mask
;
2247 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2248 hotkey_source_mask
|= (mask
& ~hotkey_all_mask
);
2250 HOTKEY_CONFIG_CRITICAL_END
2252 rc
= hotkey_mask_set((hotkey_acpi_mask
| hotkey_driver_mask
) &
2253 ~hotkey_source_mask
);
2254 mutex_unlock(&hotkey_mutex
);
2259 static int hotkey_status_get(int *status
)
2261 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
2267 static int hotkey_status_set(bool enable
)
2269 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
2275 static void tpacpi_input_send_tabletsw(void)
2279 if (tp_features
.hotkey_tablet
&&
2280 !hotkey_get_tablet_mode(&state
)) {
2281 mutex_lock(&tpacpi_inputdev_send_mutex
);
2283 input_report_switch(tpacpi_inputdev
,
2284 SW_TABLET_MODE
, !!state
);
2285 input_sync(tpacpi_inputdev
);
2287 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2291 /* Do NOT call without validating scancode first */
2292 static void tpacpi_input_send_key(const unsigned int scancode
)
2294 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
2296 if (keycode
!= KEY_RESERVED
) {
2297 mutex_lock(&tpacpi_inputdev_send_mutex
);
2299 input_report_key(tpacpi_inputdev
, keycode
, 1);
2300 if (keycode
== KEY_UNKNOWN
)
2301 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2303 input_sync(tpacpi_inputdev
);
2305 input_report_key(tpacpi_inputdev
, keycode
, 0);
2306 if (keycode
== KEY_UNKNOWN
)
2307 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2309 input_sync(tpacpi_inputdev
);
2311 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2315 /* Do NOT call without validating scancode first */
2316 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
2318 hotkey_driver_event(scancode
);
2319 if (hotkey_user_mask
& (1 << scancode
))
2320 tpacpi_input_send_key(scancode
);
2323 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2324 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2326 /* Do NOT call without validating scancode first */
2327 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2329 tpacpi_input_send_key_masked(scancode
);
2330 if (hotkey_report_mode
< 2) {
2331 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2332 0x80, TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
2336 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2340 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2341 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2342 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2343 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2344 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2345 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2347 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2348 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2349 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2351 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2352 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2353 n
->displayexp_toggle
=
2354 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2356 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2357 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2358 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2359 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2360 n
->brightness_toggle
=
2361 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2363 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2364 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2365 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2366 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2367 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2368 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2372 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2373 struct tp_nvram_state
*newn
,
2374 const u32 event_mask
)
2377 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2379 if ((event_mask & (1 << __scancode)) && \
2380 oldn->__member != newn->__member) \
2381 tpacpi_hotkey_send_key(__scancode); \
2384 #define TPACPI_MAY_SEND_KEY(__scancode) \
2386 if (event_mask & (1 << __scancode)) \
2387 tpacpi_hotkey_send_key(__scancode); \
2390 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2391 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2392 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2393 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2395 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2397 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2400 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2401 if (oldn
->mute
!= newn
->mute
) {
2402 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2404 if (oldn
->volume_level
> newn
->volume_level
) {
2405 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2406 } else if (oldn
->volume_level
< newn
->volume_level
) {
2407 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2408 } else if (oldn
->mute
== newn
->mute
) {
2409 /* repeated key presses that didn't change state */
2411 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2412 } else if (newn
->volume_level
!= 0) {
2413 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2415 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2420 /* handle brightness */
2421 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2422 if (oldn
->brightness_level
< newn
->brightness_level
) {
2423 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2424 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
2425 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2427 /* repeated key presses that didn't change state */
2428 if (newn
->brightness_level
!= 0) {
2429 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2431 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2436 #undef TPACPI_COMPARE_KEY
2437 #undef TPACPI_MAY_SEND_KEY
2443 * We track all events in hotkey_source_mask all the time, since
2444 * most of them are edge-based. We only issue those requested by
2445 * hotkey_user_mask or hotkey_driver_mask, though.
2447 static int hotkey_kthread(void *data
)
2449 struct tp_nvram_state s
[2];
2450 u32 poll_mask
, event_mask
;
2451 unsigned int si
, so
;
2453 unsigned int change_detector
, must_reset
;
2454 unsigned int poll_freq
;
2456 mutex_lock(&hotkey_thread_mutex
);
2458 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2467 /* Initial state for compares */
2468 mutex_lock(&hotkey_thread_data_mutex
);
2469 change_detector
= hotkey_config_change
;
2470 poll_mask
= hotkey_source_mask
;
2471 event_mask
= hotkey_source_mask
&
2472 (hotkey_driver_mask
| hotkey_user_mask
);
2473 poll_freq
= hotkey_poll_freq
;
2474 mutex_unlock(&hotkey_thread_data_mutex
);
2475 hotkey_read_nvram(&s
[so
], poll_mask
);
2477 while (!kthread_should_stop()) {
2479 if (likely(poll_freq
))
2482 t
= 100; /* should never happen... */
2484 t
= msleep_interruptible(t
);
2485 if (unlikely(kthread_should_stop()))
2487 must_reset
= try_to_freeze();
2488 if (t
> 0 && !must_reset
)
2491 mutex_lock(&hotkey_thread_data_mutex
);
2492 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2493 /* forget old state on thaw or config change */
2496 change_detector
= hotkey_config_change
;
2498 poll_mask
= hotkey_source_mask
;
2499 event_mask
= hotkey_source_mask
&
2500 (hotkey_driver_mask
| hotkey_user_mask
);
2501 poll_freq
= hotkey_poll_freq
;
2502 mutex_unlock(&hotkey_thread_data_mutex
);
2504 if (likely(poll_mask
)) {
2505 hotkey_read_nvram(&s
[si
], poll_mask
);
2506 if (likely(si
!= so
)) {
2507 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2517 mutex_unlock(&hotkey_thread_mutex
);
2521 /* call with hotkey_mutex held */
2522 static void hotkey_poll_stop_sync(void)
2524 if (tpacpi_hotkey_task
) {
2525 if (frozen(tpacpi_hotkey_task
) ||
2526 freezing(tpacpi_hotkey_task
))
2527 thaw_process(tpacpi_hotkey_task
);
2529 kthread_stop(tpacpi_hotkey_task
);
2530 tpacpi_hotkey_task
= NULL
;
2531 mutex_lock(&hotkey_thread_mutex
);
2532 /* at this point, the thread did exit */
2533 mutex_unlock(&hotkey_thread_mutex
);
2537 /* call with hotkey_mutex held */
2538 static void hotkey_poll_setup(bool may_warn
)
2540 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2541 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2543 if (hotkey_poll_freq
> 0 &&
2544 (poll_driver_mask
||
2545 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2546 if (!tpacpi_hotkey_task
) {
2547 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2548 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2549 if (IS_ERR(tpacpi_hotkey_task
)) {
2550 tpacpi_hotkey_task
= NULL
;
2552 "could not create kernel thread "
2553 "for hotkey polling\n");
2557 hotkey_poll_stop_sync();
2558 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2559 hotkey_poll_freq
== 0) {
2560 printk(TPACPI_NOTICE
2561 "hot keys 0x%08x and/or events 0x%08x "
2562 "require polling, which is currently "
2564 poll_user_mask
, poll_driver_mask
);
2569 static void hotkey_poll_setup_safe(bool may_warn
)
2571 mutex_lock(&hotkey_mutex
);
2572 hotkey_poll_setup(may_warn
);
2573 mutex_unlock(&hotkey_mutex
);
2576 /* call with hotkey_mutex held */
2577 static void hotkey_poll_set_freq(unsigned int freq
)
2580 hotkey_poll_stop_sync();
2582 hotkey_poll_freq
= freq
;
2585 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2587 static void hotkey_poll_setup_safe(bool __unused
)
2591 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2593 static int hotkey_inputdev_open(struct input_dev
*dev
)
2595 switch (tpacpi_lifecycle
) {
2596 case TPACPI_LIFE_INIT
:
2598 * hotkey_init will call hotkey_poll_setup_safe
2599 * at the appropriate moment
2602 case TPACPI_LIFE_EXITING
:
2604 case TPACPI_LIFE_RUNNING
:
2605 hotkey_poll_setup_safe(false);
2609 /* Should only happen if tpacpi_lifecycle is corrupt */
2614 static void hotkey_inputdev_close(struct input_dev
*dev
)
2616 /* disable hotkey polling when possible */
2617 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
&&
2618 !(hotkey_source_mask
& hotkey_driver_mask
))
2619 hotkey_poll_setup_safe(false);
2622 /* sysfs hotkey enable ------------------------------------------------- */
2623 static ssize_t
hotkey_enable_show(struct device
*dev
,
2624 struct device_attribute
*attr
,
2629 printk_deprecated_attribute("hotkey_enable",
2630 "Hotkey reporting is always enabled");
2632 res
= hotkey_status_get(&status
);
2636 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2639 static ssize_t
hotkey_enable_store(struct device
*dev
,
2640 struct device_attribute
*attr
,
2641 const char *buf
, size_t count
)
2645 printk_deprecated_attribute("hotkey_enable",
2646 "Hotkeys can be disabled through hotkey_mask");
2648 if (parse_strtoul(buf
, 1, &t
))
2657 static struct device_attribute dev_attr_hotkey_enable
=
2658 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2659 hotkey_enable_show
, hotkey_enable_store
);
2661 /* sysfs hotkey mask --------------------------------------------------- */
2662 static ssize_t
hotkey_mask_show(struct device
*dev
,
2663 struct device_attribute
*attr
,
2666 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2669 static ssize_t
hotkey_mask_store(struct device
*dev
,
2670 struct device_attribute
*attr
,
2671 const char *buf
, size_t count
)
2676 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2679 if (mutex_lock_killable(&hotkey_mutex
))
2680 return -ERESTARTSYS
;
2682 res
= hotkey_user_mask_set(t
);
2684 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2685 hotkey_poll_setup(true);
2688 mutex_unlock(&hotkey_mutex
);
2690 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2692 return (res
) ? res
: count
;
2695 static struct device_attribute dev_attr_hotkey_mask
=
2696 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2697 hotkey_mask_show
, hotkey_mask_store
);
2699 /* sysfs hotkey bios_enabled ------------------------------------------- */
2700 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2701 struct device_attribute
*attr
,
2704 return sprintf(buf
, "0\n");
2707 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2708 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2710 /* sysfs hotkey bios_mask ---------------------------------------------- */
2711 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2712 struct device_attribute
*attr
,
2715 printk_deprecated_attribute("hotkey_bios_mask",
2716 "This attribute is useless.");
2717 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2720 static struct device_attribute dev_attr_hotkey_bios_mask
=
2721 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2723 /* sysfs hotkey all_mask ----------------------------------------------- */
2724 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2725 struct device_attribute
*attr
,
2728 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2729 hotkey_all_mask
| hotkey_source_mask
);
2732 static struct device_attribute dev_attr_hotkey_all_mask
=
2733 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2735 /* sysfs hotkey recommended_mask --------------------------------------- */
2736 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2737 struct device_attribute
*attr
,
2740 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2741 (hotkey_all_mask
| hotkey_source_mask
)
2742 & ~hotkey_reserved_mask
);
2745 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2746 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2747 hotkey_recommended_mask_show
, NULL
);
2749 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2751 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2752 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2753 struct device_attribute
*attr
,
2756 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2759 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2760 struct device_attribute
*attr
,
2761 const char *buf
, size_t count
)
2767 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2768 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2771 if (mutex_lock_killable(&hotkey_mutex
))
2772 return -ERESTARTSYS
;
2774 HOTKEY_CONFIG_CRITICAL_START
2775 hotkey_source_mask
= t
;
2776 HOTKEY_CONFIG_CRITICAL_END
2778 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2779 ~hotkey_source_mask
);
2780 hotkey_poll_setup(true);
2782 /* check if events needed by the driver got disabled */
2783 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2784 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2786 mutex_unlock(&hotkey_mutex
);
2789 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2790 "firmware event mask!\n");
2793 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2794 "some important events were disabled: "
2797 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2799 return (rc
< 0) ? rc
: count
;
2802 static struct device_attribute dev_attr_hotkey_source_mask
=
2803 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2804 hotkey_source_mask_show
, hotkey_source_mask_store
);
2806 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2807 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2808 struct device_attribute
*attr
,
2811 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2814 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2815 struct device_attribute
*attr
,
2816 const char *buf
, size_t count
)
2820 if (parse_strtoul(buf
, 25, &t
))
2823 if (mutex_lock_killable(&hotkey_mutex
))
2824 return -ERESTARTSYS
;
2826 hotkey_poll_set_freq(t
);
2827 hotkey_poll_setup(true);
2829 mutex_unlock(&hotkey_mutex
);
2831 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2836 static struct device_attribute dev_attr_hotkey_poll_freq
=
2837 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2838 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2840 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2842 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2843 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2844 struct device_attribute
*attr
,
2848 res
= hotkey_get_wlsw();
2852 /* Opportunistic update */
2853 tpacpi_rfk_update_hwblock_state((res
== TPACPI_RFK_RADIO_OFF
));
2855 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2856 (res
== TPACPI_RFK_RADIO_OFF
) ? 0 : 1);
2859 static struct device_attribute dev_attr_hotkey_radio_sw
=
2860 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2862 static void hotkey_radio_sw_notify_change(void)
2864 if (tp_features
.hotkey_wlsw
)
2865 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2869 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2870 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2871 struct device_attribute
*attr
,
2875 res
= hotkey_get_tablet_mode(&s
);
2879 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2882 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2883 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2885 static void hotkey_tablet_mode_notify_change(void)
2887 if (tp_features
.hotkey_tablet
)
2888 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2889 "hotkey_tablet_mode");
2892 /* sysfs hotkey report_mode -------------------------------------------- */
2893 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2894 struct device_attribute
*attr
,
2897 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2898 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2901 static struct device_attribute dev_attr_hotkey_report_mode
=
2902 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2904 /* sysfs wakeup reason (pollable) -------------------------------------- */
2905 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2906 struct device_attribute
*attr
,
2909 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2912 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2913 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2915 static void hotkey_wakeup_reason_notify_change(void)
2917 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2921 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2922 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2923 struct device_attribute
*attr
,
2926 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2929 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2930 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2931 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2933 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2935 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2936 "wakeup_hotunplug_complete");
2939 /* --------------------------------------------------------------------- */
2941 static struct attribute
*hotkey_attributes
[] __initdata
= {
2942 &dev_attr_hotkey_enable
.attr
,
2943 &dev_attr_hotkey_bios_enabled
.attr
,
2944 &dev_attr_hotkey_bios_mask
.attr
,
2945 &dev_attr_hotkey_report_mode
.attr
,
2946 &dev_attr_hotkey_wakeup_reason
.attr
,
2947 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2948 &dev_attr_hotkey_mask
.attr
,
2949 &dev_attr_hotkey_all_mask
.attr
,
2950 &dev_attr_hotkey_recommended_mask
.attr
,
2951 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2952 &dev_attr_hotkey_source_mask
.attr
,
2953 &dev_attr_hotkey_poll_freq
.attr
,
2958 * Sync both the hw and sw blocking state of all switches
2960 static void tpacpi_send_radiosw_update(void)
2965 * We must sync all rfkill controllers *before* issuing any
2966 * rfkill input events, or we will race the rfkill core input
2969 * tpacpi_inputdev_send_mutex works as a syncronization point
2972 * We optimize to avoid numerous calls to hotkey_get_wlsw.
2975 wlsw
= hotkey_get_wlsw();
2977 /* Sync hw blocking state first if it is hw-blocked */
2978 if (wlsw
== TPACPI_RFK_RADIO_OFF
)
2979 tpacpi_rfk_update_hwblock_state(true);
2981 /* Sync sw blocking state */
2982 tpacpi_rfk_update_swstate_all();
2984 /* Sync hw blocking state last if it is hw-unblocked */
2985 if (wlsw
== TPACPI_RFK_RADIO_ON
)
2986 tpacpi_rfk_update_hwblock_state(false);
2988 /* Issue rfkill input event for WLSW switch */
2990 mutex_lock(&tpacpi_inputdev_send_mutex
);
2992 input_report_switch(tpacpi_inputdev
,
2993 SW_RFKILL_ALL
, (wlsw
> 0));
2994 input_sync(tpacpi_inputdev
);
2996 mutex_unlock(&tpacpi_inputdev_send_mutex
);
3000 * this can be unconditional, as we will poll state again
3001 * if userspace uses the notify to read data
3003 hotkey_radio_sw_notify_change();
3006 static void hotkey_exit(void)
3008 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3009 mutex_lock(&hotkey_mutex
);
3010 hotkey_poll_stop_sync();
3011 mutex_unlock(&hotkey_mutex
);
3014 if (hotkey_dev_attributes
)
3015 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3017 kfree(hotkey_keycode_map
);
3019 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
3020 "restoring original HKEY status and mask\n");
3021 /* yes, there is a bitwise or below, we want the
3022 * functions to be called even if one of them fail */
3023 if (((tp_features
.hotkey_mask
&&
3024 hotkey_mask_set(hotkey_orig_mask
)) |
3025 hotkey_status_set(false)) != 0)
3027 "failed to restore hot key mask "
3028 "to BIOS defaults\n");
3031 static void __init
hotkey_unmap(const unsigned int scancode
)
3033 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
3034 clear_bit(hotkey_keycode_map
[scancode
],
3035 tpacpi_inputdev
->keybit
);
3036 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
3042 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
3045 #define TPACPI_HK_Q_INIMASK 0x0001
3047 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
3048 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
3049 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
3050 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
3051 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
3052 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
3053 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
3054 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
3055 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
3056 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
3057 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
3058 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
3059 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
3060 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
3061 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
3062 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
3063 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
3064 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
3065 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
3066 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
3069 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
3071 /* Requirements for changing the default keymaps:
3073 * 1. Many of the keys are mapped to KEY_RESERVED for very
3074 * good reasons. Do not change them unless you have deep
3075 * knowledge on the IBM and Lenovo ThinkPad firmware for
3076 * the various ThinkPad models. The driver behaves
3077 * differently for KEY_RESERVED: such keys have their
3078 * hot key mask *unset* in mask_recommended, and also
3079 * in the initial hot key mask programmed into the
3080 * firmware at driver load time, which means the firm-
3081 * ware may react very differently if you change them to
3084 * 2. You must be subscribed to the linux-thinkpad and
3085 * ibm-acpi-devel mailing lists, and you should read the
3086 * list archives since 2007 if you want to change the
3087 * keymaps. This requirement exists so that you will
3088 * know the past history of problems with the thinkpad-
3089 * acpi driver keymaps, and also that you will be
3090 * listening to any bug reports;
3092 * 3. Do not send thinkpad-acpi specific patches directly to
3093 * for merging, *ever*. Send them to the linux-acpi
3094 * mailinglist for comments. Merging is to be done only
3095 * through acpi-test and the ACPI maintainer.
3097 * If the above is too much to ask, don't change the keymap.
3098 * Ask the thinkpad-acpi maintainer to do it, instead.
3100 static u16 ibm_keycode_map
[] __initdata
= {
3101 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3102 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
3103 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3104 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3106 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3107 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3108 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3109 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3111 /* brightness: firmware always reacts to them */
3112 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
3113 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
3115 /* Thinklight: firmware always react to it */
3116 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3118 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3119 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3121 /* Volume: firmware always react to it and reprograms
3122 * the built-in *extra* mixer. Never map it to control
3123 * another mixer by default. */
3124 KEY_RESERVED
, /* 0x14: VOLUME UP */
3125 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3126 KEY_RESERVED
, /* 0x16: MUTE */
3128 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3130 /* (assignments unknown, please report if found) */
3131 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3132 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3134 static u16 lenovo_keycode_map
[] __initdata
= {
3135 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3136 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
3137 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3138 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3140 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3141 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3142 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3143 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3145 /* These should be enabled --only-- when ACPI video
3146 * is disabled (i.e. in "vendor" mode), and are handled
3147 * in a special way by the init code */
3148 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
3149 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
3151 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3153 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3154 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3156 /* Volume: z60/z61, T60 (BIOS version?): firmware always
3157 * react to it and reprograms the built-in *extra* mixer.
3158 * Never map it to control another mixer by default.
3160 * T60?, T61, R60?, R61: firmware and EC tries to send
3161 * these over the regular keyboard, so these are no-ops,
3162 * but there are still weird bugs re. MUTE, so do not
3163 * change unless you get test reports from all Lenovo
3164 * models. May cause the BIOS to interfere with the
3167 KEY_RESERVED
, /* 0x14: VOLUME UP */
3168 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3169 KEY_RESERVED
, /* 0x16: MUTE */
3171 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3173 /* (assignments unknown, please report if found) */
3174 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3175 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3178 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
3179 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
3180 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
3186 unsigned long quirks
;
3188 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3189 "initializing hotkey subdriver\n");
3191 BUG_ON(!tpacpi_inputdev
);
3192 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
3193 tpacpi_inputdev
->close
!= NULL
);
3195 TPACPI_ACPIHANDLE_INIT(hkey
);
3196 mutex_init(&hotkey_mutex
);
3198 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3199 mutex_init(&hotkey_thread_mutex
);
3200 mutex_init(&hotkey_thread_data_mutex
);
3203 /* hotkey not supported on 570 */
3204 tp_features
.hotkey
= hkey_handle
!= NULL
;
3206 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3208 str_supported(tp_features
.hotkey
));
3210 if (!tp_features
.hotkey
)
3213 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
3214 ARRAY_SIZE(tpacpi_hotkey_qtable
));
3216 tpacpi_disable_brightness_delay();
3218 /* MUST have enough space for all attributes to be added to
3219 * hotkey_dev_attributes */
3220 hotkey_dev_attributes
= create_attr_set(
3221 ARRAY_SIZE(hotkey_attributes
) + 2,
3223 if (!hotkey_dev_attributes
)
3225 res
= add_many_to_attr_set(hotkey_dev_attributes
,
3227 ARRAY_SIZE(hotkey_attributes
));
3231 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
3232 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
3233 for HKEY interface version 0x100 */
3234 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
3235 if ((hkeyv
>> 8) != 1) {
3236 printk(TPACPI_ERR
"unknown version of the "
3237 "HKEY interface: 0x%x\n", hkeyv
);
3238 printk(TPACPI_ERR
"please report this to %s\n",
3242 * MHKV 0x100 in A31, R40, R40e,
3243 * T4x, X31, and later
3245 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3246 "firmware HKEY interface version: 0x%x\n",
3249 /* Paranoia check AND init hotkey_all_mask */
3250 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
3253 "missing MHKA handler, "
3254 "please report this to %s\n",
3256 /* Fallback: pre-init for FN+F3,F4,F12 */
3257 hotkey_all_mask
= 0x080cU
;
3259 tp_features
.hotkey_mask
= 1;
3264 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3265 "hotkey masks are %s\n",
3266 str_supported(tp_features
.hotkey_mask
));
3268 /* Init hotkey_all_mask if not initialized yet */
3269 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
3270 (quirks
& TPACPI_HK_Q_INIMASK
))
3271 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
3273 /* Init hotkey_acpi_mask and hotkey_orig_mask */
3274 if (tp_features
.hotkey_mask
) {
3275 /* hotkey_source_mask *must* be zero for
3276 * the first hotkey_mask_get to return hotkey_orig_mask */
3277 res
= hotkey_mask_get();
3281 hotkey_orig_mask
= hotkey_acpi_mask
;
3283 hotkey_orig_mask
= hotkey_all_mask
;
3284 hotkey_acpi_mask
= hotkey_all_mask
;
3287 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3289 tp_features
.hotkey_wlsw
= 1;
3291 "radio switch emulation enabled\n");
3294 /* Not all thinkpads have a hardware radio switch */
3295 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3296 tp_features
.hotkey_wlsw
= 1;
3298 "radio switch found; radios are %s\n",
3299 enabled(status
, 0));
3301 if (tp_features
.hotkey_wlsw
)
3302 res
= add_to_attr_set(hotkey_dev_attributes
,
3303 &dev_attr_hotkey_radio_sw
.attr
);
3305 /* For X41t, X60t, X61t Tablets... */
3306 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3307 tp_features
.hotkey_tablet
= 1;
3309 "possible tablet mode switch found; "
3310 "ThinkPad in %s mode\n",
3311 (status
& TP_HOTKEY_TABLET_MASK
)?
3312 "tablet" : "laptop");
3313 res
= add_to_attr_set(hotkey_dev_attributes
,
3314 &dev_attr_hotkey_tablet_mode
.attr
);
3318 res
= register_attr_set_with_sysfs(
3319 hotkey_dev_attributes
,
3320 &tpacpi_pdev
->dev
.kobj
);
3324 /* Set up key map */
3326 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3328 if (!hotkey_keycode_map
) {
3330 "failed to allocate memory for key map\n");
3335 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
3336 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3337 "using Lenovo default hot key map\n");
3338 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
3339 TPACPI_HOTKEY_MAP_SIZE
);
3341 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3342 "using IBM default hot key map\n");
3343 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
3344 TPACPI_HOTKEY_MAP_SIZE
);
3347 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
3348 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
3349 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
3350 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3351 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3352 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3353 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3354 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3355 set_bit(hotkey_keycode_map
[i
],
3356 tpacpi_inputdev
->keybit
);
3358 if (i
< sizeof(hotkey_reserved_mask
)*8)
3359 hotkey_reserved_mask
|= 1 << i
;
3363 if (tp_features
.hotkey_wlsw
) {
3364 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
3365 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
3367 if (tp_features
.hotkey_tablet
) {
3368 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
3369 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
3372 /* Do not issue duplicate brightness change events to
3374 if (!tp_features
.bright_acpimode
)
3375 /* update bright_acpimode... */
3376 tpacpi_check_std_acpi_brightness_support();
3378 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
3380 "This ThinkPad has standard ACPI backlight "
3381 "brightness control, supported by the ACPI "
3383 printk(TPACPI_NOTICE
3384 "Disabling thinkpad-acpi brightness events "
3387 /* Disable brightness up/down on Lenovo thinkpads when
3388 * ACPI is handling them, otherwise it is plain impossible
3389 * for userspace to do something even remotely sane */
3390 hotkey_reserved_mask
|=
3391 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3392 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3393 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3394 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3397 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3398 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3400 & ~hotkey_reserved_mask
;
3402 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3403 "hotkey source mask 0x%08x, polling freq %u\n",
3404 hotkey_source_mask
, hotkey_poll_freq
);
3407 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3408 "enabling firmware HKEY event interface...\n");
3409 res
= hotkey_status_set(true);
3414 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3415 | hotkey_driver_mask
)
3416 & ~hotkey_source_mask
);
3417 if (res
< 0 && res
!= -ENXIO
) {
3421 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3422 & ~hotkey_reserved_mask
;
3423 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3424 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3425 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3427 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3428 "legacy ibm/hotkey event reporting over procfs %s\n",
3429 (hotkey_report_mode
< 2) ?
3430 "enabled" : "disabled");
3432 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3433 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3435 hotkey_poll_setup_safe(true);
3436 tpacpi_send_radiosw_update();
3437 tpacpi_input_send_tabletsw();
3442 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3443 hotkey_dev_attributes
= NULL
;
3445 return (res
< 0)? res
: 1;
3448 static bool hotkey_notify_hotkey(const u32 hkey
,
3450 bool *ignore_acpi_ev
)
3452 /* 0x1000-0x1FFF: key presses */
3453 unsigned int scancode
= hkey
& 0xfff;
3454 *send_acpi_ev
= true;
3455 *ignore_acpi_ev
= false;
3457 if (scancode
> 0 && scancode
< 0x21) {
3459 if (!(hotkey_source_mask
& (1 << scancode
))) {
3460 tpacpi_input_send_key_masked(scancode
);
3461 *send_acpi_ev
= false;
3463 *ignore_acpi_ev
= true;
3470 static bool hotkey_notify_wakeup(const u32 hkey
,
3472 bool *ignore_acpi_ev
)
3474 /* 0x2000-0x2FFF: Wakeup reason */
3475 *send_acpi_ev
= true;
3476 *ignore_acpi_ev
= false;
3479 case TP_HKEY_EV_WKUP_S3_UNDOCK
: /* suspend, undock */
3480 case TP_HKEY_EV_WKUP_S4_UNDOCK
: /* hibernation, undock */
3481 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3482 *ignore_acpi_ev
= true;
3485 case TP_HKEY_EV_WKUP_S3_BAYEJ
: /* suspend, bay eject */
3486 case TP_HKEY_EV_WKUP_S4_BAYEJ
: /* hibernation, bay eject */
3487 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3488 *ignore_acpi_ev
= true;
3491 case TP_HKEY_EV_WKUP_S3_BATLOW
: /* Battery on critical low level/S3 */
3492 case TP_HKEY_EV_WKUP_S4_BATLOW
: /* Battery on critical low level/S4 */
3494 "EMERGENCY WAKEUP: battery almost empty\n");
3495 /* how to auto-heal: */
3496 /* 2313: woke up from S3, go to S4/S5 */
3497 /* 2413: woke up from S4, go to S5 */
3504 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3506 "woke up due to a hot-unplug "
3508 hotkey_wakeup_reason_notify_change();
3513 static bool hotkey_notify_usrevent(const u32 hkey
,
3515 bool *ignore_acpi_ev
)
3517 /* 0x5000-0x5FFF: human interface helpers */
3518 *send_acpi_ev
= true;
3519 *ignore_acpi_ev
= false;
3522 case TP_HKEY_EV_PEN_INSERTED
: /* X61t: tablet pen inserted into bay */
3523 case TP_HKEY_EV_PEN_REMOVED
: /* X61t: tablet pen removed from bay */
3526 case TP_HKEY_EV_TABLET_TABLET
: /* X41t-X61t: tablet mode */
3527 case TP_HKEY_EV_TABLET_NOTEBOOK
: /* X41t-X61t: normal mode */
3528 tpacpi_input_send_tabletsw();
3529 hotkey_tablet_mode_notify_change();
3530 *send_acpi_ev
= false;
3533 case TP_HKEY_EV_LID_CLOSE
: /* Lid closed */
3534 case TP_HKEY_EV_LID_OPEN
: /* Lid opened */
3535 case TP_HKEY_EV_BRGHT_CHANGED
: /* brightness changed */
3536 /* do not propagate these events */
3537 *ignore_acpi_ev
= true;
3545 static bool hotkey_notify_thermal(const u32 hkey
,
3547 bool *ignore_acpi_ev
)
3549 /* 0x6000-0x6FFF: thermal alarms */
3550 *send_acpi_ev
= true;
3551 *ignore_acpi_ev
= false;
3554 case TP_HKEY_EV_ALARM_BAT_HOT
:
3556 "THERMAL ALARM: battery is too hot!\n");
3557 /* recommended action: warn user through gui */
3559 case TP_HKEY_EV_ALARM_BAT_XHOT
:
3561 "THERMAL EMERGENCY: battery is extremely hot!\n");
3562 /* recommended action: immediate sleep/hibernate */
3564 case TP_HKEY_EV_ALARM_SENSOR_HOT
:
3567 "a sensor reports something is too hot!\n");
3568 /* recommended action: warn user through gui, that */
3569 /* some internal component is too hot */
3571 case TP_HKEY_EV_ALARM_SENSOR_XHOT
:
3573 "THERMAL EMERGENCY: "
3574 "a sensor reports something is extremely hot!\n");
3575 /* recommended action: immediate sleep/hibernate */
3577 case TP_HKEY_EV_THM_TABLE_CHANGED
:
3579 "EC reports that Thermal Table has changed\n");
3580 /* recommended action: do nothing, we don't have
3581 * Lenovo ATM information */
3585 "THERMAL ALERT: unknown thermal alarm received\n");
3590 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3594 bool ignore_acpi_ev
;
3597 if (event
!= 0x80) {
3599 "unknown HKEY notification event %d\n", event
);
3600 /* forward it to userspace, maybe it knows how to handle it */
3601 acpi_bus_generate_netlink_event(
3602 ibm
->acpi
->device
->pnp
.device_class
,
3603 dev_name(&ibm
->acpi
->device
->dev
),
3609 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3610 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3619 send_acpi_ev
= true;
3620 ignore_acpi_ev
= false;
3622 switch (hkey
>> 12) {
3624 /* 0x1000-0x1FFF: key presses */
3625 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3629 /* 0x2000-0x2FFF: Wakeup reason */
3630 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3634 /* 0x3000-0x3FFF: bay-related wakeups */
3635 if (hkey
== TP_HKEY_EV_BAYEJ_ACK
) {
3636 hotkey_autosleep_ack
= 1;
3639 hotkey_wakeup_hotunplug_complete_notify_change();
3646 /* 0x4000-0x4FFF: dock-related wakeups */
3647 if (hkey
== TP_HKEY_EV_UNDOCK_ACK
) {
3648 hotkey_autosleep_ack
= 1;
3651 hotkey_wakeup_hotunplug_complete_notify_change();
3658 /* 0x5000-0x5FFF: human interface helpers */
3659 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3663 /* 0x6000-0x6FFF: thermal alarms */
3664 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3668 /* 0x7000-0x7FFF: misc */
3669 if (tp_features
.hotkey_wlsw
&&
3670 hkey
== TP_HKEY_EV_RFKILL_CHANGED
) {
3671 tpacpi_send_radiosw_update();
3676 /* fallthrough to default */
3681 printk(TPACPI_NOTICE
3682 "unhandled HKEY event 0x%04x\n", hkey
);
3683 printk(TPACPI_NOTICE
3684 "please report the conditions when this "
3685 "event happened to %s\n", TPACPI_MAIL
);
3689 if (!ignore_acpi_ev
&&
3690 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3691 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3695 /* netlink events */
3696 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3697 acpi_bus_generate_netlink_event(
3698 ibm
->acpi
->device
->pnp
.device_class
,
3699 dev_name(&ibm
->acpi
->device
->dev
),
3705 static void hotkey_suspend(pm_message_t state
)
3707 /* Do these on suspend, we get the events on early resume! */
3708 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3709 hotkey_autosleep_ack
= 0;
3712 static void hotkey_resume(void)
3714 tpacpi_disable_brightness_delay();
3716 if (hotkey_status_set(true) < 0 ||
3717 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3719 "error while attempting to reset the event "
3720 "firmware interface\n");
3722 tpacpi_send_radiosw_update();
3723 hotkey_tablet_mode_notify_change();
3724 hotkey_wakeup_reason_notify_change();
3725 hotkey_wakeup_hotunplug_complete_notify_change();
3726 hotkey_poll_setup_safe(false);
3729 /* procfs -------------------------------------------------------------- */
3730 static int hotkey_read(char *p
)
3735 if (!tp_features
.hotkey
) {
3736 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3740 if (mutex_lock_killable(&hotkey_mutex
))
3741 return -ERESTARTSYS
;
3742 res
= hotkey_status_get(&status
);
3744 res
= hotkey_mask_get();
3745 mutex_unlock(&hotkey_mutex
);
3749 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
3750 if (hotkey_all_mask
) {
3751 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3752 len
+= sprintf(p
+ len
,
3753 "commands:\tenable, disable, reset, <mask>\n");
3755 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
3756 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
3762 static void hotkey_enabledisable_warn(bool enable
)
3764 tpacpi_log_usertask("procfs hotkey enable/disable");
3765 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3767 "hotkey enable/disable functionality has been "
3768 "removed from the driver. Hotkeys are always "
3771 "Please remove the hotkey=enable module "
3772 "parameter, it is deprecated. Hotkeys are always "
3776 static int hotkey_write(char *buf
)
3782 if (!tp_features
.hotkey
)
3785 if (mutex_lock_killable(&hotkey_mutex
))
3786 return -ERESTARTSYS
;
3788 mask
= hotkey_user_mask
;
3791 while ((cmd
= next_cmd(&buf
))) {
3792 if (strlencmp(cmd
, "enable") == 0) {
3793 hotkey_enabledisable_warn(1);
3794 } else if (strlencmp(cmd
, "disable") == 0) {
3795 hotkey_enabledisable_warn(0);
3797 } else if (strlencmp(cmd
, "reset") == 0) {
3798 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3799 & ~hotkey_reserved_mask
;
3800 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3802 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3811 tpacpi_disclose_usertask("procfs hotkey",
3812 "set mask to 0x%08x\n", mask
);
3813 res
= hotkey_user_mask_set(mask
);
3817 mutex_unlock(&hotkey_mutex
);
3821 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3822 {TPACPI_ACPI_HKEY_HID
, 0},
3826 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3827 .hid
= ibm_htk_device_ids
,
3828 .notify
= hotkey_notify
,
3829 .handle
= &hkey_handle
,
3830 .type
= ACPI_DEVICE_NOTIFY
,
3833 static struct ibm_struct hotkey_driver_data
= {
3835 .read
= hotkey_read
,
3836 .write
= hotkey_write
,
3837 .exit
= hotkey_exit
,
3838 .resume
= hotkey_resume
,
3839 .suspend
= hotkey_suspend
,
3840 .acpi
= &ibm_hotkey_acpidriver
,
3843 /*************************************************************************
3844 * Bluetooth subdriver
3848 /* ACPI GBDC/SBDC bits */
3849 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3850 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3851 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3856 /* ACPI \BLTH commands */
3857 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3858 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3859 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3860 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3861 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3864 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3866 static void bluetooth_suspend(pm_message_t state
)
3868 /* Try to make sure radio will resume powered off */
3869 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3870 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
))
3871 vdbg_printk(TPACPI_DBG_RFKILL
,
3872 "bluetooth power down on resume request failed\n");
3875 static int bluetooth_get_status(void)
3879 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3880 if (dbg_bluetoothemul
)
3881 return (tpacpi_bluetooth_emulstate
) ?
3882 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3885 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3888 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3889 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3892 static int bluetooth_set_status(enum tpacpi_rfkill_state state
)
3896 vdbg_printk(TPACPI_DBG_RFKILL
,
3897 "will attempt to %s bluetooth\n",
3898 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
3900 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3901 if (dbg_bluetoothemul
) {
3902 tpacpi_bluetooth_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
3907 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3908 if (state
== TPACPI_RFK_RADIO_ON
)
3909 status
= TP_ACPI_BLUETOOTH_RADIOSSW
;
3913 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3919 /* sysfs bluetooth enable ---------------------------------------------- */
3920 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3921 struct device_attribute
*attr
,
3924 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID
,
3928 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3929 struct device_attribute
*attr
,
3930 const char *buf
, size_t count
)
3932 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID
,
3936 static struct device_attribute dev_attr_bluetooth_enable
=
3937 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3938 bluetooth_enable_show
, bluetooth_enable_store
);
3940 /* --------------------------------------------------------------------- */
3942 static struct attribute
*bluetooth_attributes
[] = {
3943 &dev_attr_bluetooth_enable
.attr
,
3947 static const struct attribute_group bluetooth_attr_group
= {
3948 .attrs
= bluetooth_attributes
,
3951 static const struct tpacpi_rfk_ops bluetooth_tprfk_ops
= {
3952 .get_status
= bluetooth_get_status
,
3953 .set_status
= bluetooth_set_status
,
3956 static void bluetooth_shutdown(void)
3958 /* Order firmware to save current state to NVRAM */
3959 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3960 TP_ACPI_BLTH_SAVE_STATE
))
3961 printk(TPACPI_NOTICE
3962 "failed to save bluetooth state to NVRAM\n");
3964 vdbg_printk(TPACPI_DBG_RFKILL
,
3965 "bluestooth state saved to NVRAM\n");
3968 static void bluetooth_exit(void)
3970 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3971 &bluetooth_attr_group
);
3973 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
3975 bluetooth_shutdown();
3978 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
3983 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3984 "initializing bluetooth subdriver\n");
3986 TPACPI_ACPIHANDLE_INIT(hkey
);
3988 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3989 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3990 tp_features
.bluetooth
= hkey_handle
&&
3991 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
3993 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
3994 "bluetooth is %s, status 0x%02x\n",
3995 str_supported(tp_features
.bluetooth
),
3998 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3999 if (dbg_bluetoothemul
) {
4000 tp_features
.bluetooth
= 1;
4002 "bluetooth switch emulation enabled\n");
4005 if (tp_features
.bluetooth
&&
4006 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
4007 /* no bluetooth hardware present in system */
4008 tp_features
.bluetooth
= 0;
4009 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4010 "bluetooth hardware not installed\n");
4013 if (!tp_features
.bluetooth
)
4016 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
4017 &bluetooth_tprfk_ops
,
4018 RFKILL_TYPE_BLUETOOTH
,
4019 TPACPI_RFK_BLUETOOTH_SW_NAME
,
4024 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4025 &bluetooth_attr_group
);
4027 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
4034 /* procfs -------------------------------------------------------------- */
4035 static int bluetooth_read(char *p
)
4037 return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID
, p
);
4040 static int bluetooth_write(char *buf
)
4042 return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID
, buf
);
4045 static struct ibm_struct bluetooth_driver_data
= {
4046 .name
= "bluetooth",
4047 .read
= bluetooth_read
,
4048 .write
= bluetooth_write
,
4049 .exit
= bluetooth_exit
,
4050 .suspend
= bluetooth_suspend
,
4051 .shutdown
= bluetooth_shutdown
,
4054 /*************************************************************************
4059 /* ACPI GWAN/SWAN bits */
4060 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
4061 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
4062 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
4066 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
4068 static void wan_suspend(pm_message_t state
)
4070 /* Try to make sure radio will resume powered off */
4071 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "qvd",
4072 TP_ACPI_WGSV_PWR_OFF_ON_RESUME
))
4073 vdbg_printk(TPACPI_DBG_RFKILL
,
4074 "WWAN power down on resume request failed\n");
4077 static int wan_get_status(void)
4081 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4083 return (tpacpi_wwan_emulstate
) ?
4084 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4087 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
4090 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
4091 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4094 static int wan_set_status(enum tpacpi_rfkill_state state
)
4098 vdbg_printk(TPACPI_DBG_RFKILL
,
4099 "will attempt to %s wwan\n",
4100 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4102 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4104 tpacpi_wwan_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4109 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
4110 if (state
== TPACPI_RFK_RADIO_ON
)
4111 status
= TP_ACPI_WANCARD_RADIOSSW
;
4115 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
4121 /* sysfs wan enable ---------------------------------------------------- */
4122 static ssize_t
wan_enable_show(struct device
*dev
,
4123 struct device_attribute
*attr
,
4126 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID
,
4130 static ssize_t
wan_enable_store(struct device
*dev
,
4131 struct device_attribute
*attr
,
4132 const char *buf
, size_t count
)
4134 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID
,
4138 static struct device_attribute dev_attr_wan_enable
=
4139 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4140 wan_enable_show
, wan_enable_store
);
4142 /* --------------------------------------------------------------------- */
4144 static struct attribute
*wan_attributes
[] = {
4145 &dev_attr_wan_enable
.attr
,
4149 static const struct attribute_group wan_attr_group
= {
4150 .attrs
= wan_attributes
,
4153 static const struct tpacpi_rfk_ops wan_tprfk_ops
= {
4154 .get_status
= wan_get_status
,
4155 .set_status
= wan_set_status
,
4158 static void wan_shutdown(void)
4160 /* Order firmware to save current state to NVRAM */
4161 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4162 TP_ACPI_WGSV_SAVE_STATE
))
4163 printk(TPACPI_NOTICE
4164 "failed to save WWAN state to NVRAM\n");
4166 vdbg_printk(TPACPI_DBG_RFKILL
,
4167 "WWAN state saved to NVRAM\n");
4170 static void wan_exit(void)
4172 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4175 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4180 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4185 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4186 "initializing wan subdriver\n");
4188 TPACPI_ACPIHANDLE_INIT(hkey
);
4190 tp_features
.wan
= hkey_handle
&&
4191 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4193 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4194 "wan is %s, status 0x%02x\n",
4195 str_supported(tp_features
.wan
),
4198 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4200 tp_features
.wan
= 1;
4202 "wwan switch emulation enabled\n");
4205 if (tp_features
.wan
&&
4206 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4207 /* no wan hardware present in system */
4208 tp_features
.wan
= 0;
4209 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4210 "wan hardware not installed\n");
4213 if (!tp_features
.wan
)
4216 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4219 TPACPI_RFK_WWAN_SW_NAME
,
4224 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4228 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4235 /* procfs -------------------------------------------------------------- */
4236 static int wan_read(char *p
)
4238 return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID
, p
);
4241 static int wan_write(char *buf
)
4243 return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID
, buf
);
4246 static struct ibm_struct wan_driver_data
= {
4251 .suspend
= wan_suspend
,
4252 .shutdown
= wan_shutdown
,
4255 /*************************************************************************
4260 /* ACPI GUWB/SUWB bits */
4261 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4262 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4265 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4267 static int uwb_get_status(void)
4271 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4273 return (tpacpi_uwb_emulstate
) ?
4274 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4277 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4280 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4281 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4284 static int uwb_set_status(enum tpacpi_rfkill_state state
)
4288 vdbg_printk(TPACPI_DBG_RFKILL
,
4289 "will attempt to %s UWB\n",
4290 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4292 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4294 tpacpi_uwb_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4299 if (state
== TPACPI_RFK_RADIO_ON
)
4300 status
= TP_ACPI_UWB_RADIOSSW
;
4304 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4310 /* --------------------------------------------------------------------- */
4312 static const struct tpacpi_rfk_ops uwb_tprfk_ops
= {
4313 .get_status
= uwb_get_status
,
4314 .set_status
= uwb_set_status
,
4317 static void uwb_exit(void)
4319 tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID
);
4322 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4327 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4328 "initializing uwb subdriver\n");
4330 TPACPI_ACPIHANDLE_INIT(hkey
);
4332 tp_features
.uwb
= hkey_handle
&&
4333 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4335 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4336 "uwb is %s, status 0x%02x\n",
4337 str_supported(tp_features
.uwb
),
4340 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4342 tp_features
.uwb
= 1;
4344 "uwb switch emulation enabled\n");
4347 if (tp_features
.uwb
&&
4348 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4349 /* no uwb hardware present in system */
4350 tp_features
.uwb
= 0;
4351 dbg_printk(TPACPI_DBG_INIT
,
4352 "uwb hardware not installed\n");
4355 if (!tp_features
.uwb
)
4358 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4361 TPACPI_RFK_UWB_SW_NAME
,
4366 static struct ibm_struct uwb_driver_data
= {
4369 .flags
.experimental
= 1,
4372 /*************************************************************************
4376 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4378 enum video_access_mode
{
4379 TPACPI_VIDEO_NONE
= 0,
4380 TPACPI_VIDEO_570
, /* 570 */
4381 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4382 TPACPI_VIDEO_NEW
, /* all others */
4385 enum { /* video status flags, based on VIDEO_570 */
4386 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4387 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4388 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4391 enum { /* TPACPI_VIDEO_570 constants */
4392 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4393 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4394 * video_status_flags */
4395 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4396 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4399 static enum video_access_mode video_supported
;
4400 static int video_orig_autosw
;
4402 static int video_autosw_get(void);
4403 static int video_autosw_set(int enable
);
4405 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4407 static int __init
video_init(struct ibm_init_struct
*iibm
)
4411 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4413 TPACPI_ACPIHANDLE_INIT(vid
);
4414 TPACPI_ACPIHANDLE_INIT(vid2
);
4416 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4417 /* G41, assume IVGA doesn't change */
4418 vid_handle
= vid2_handle
;
4421 /* video switching not supported on R30, R31 */
4422 video_supported
= TPACPI_VIDEO_NONE
;
4423 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4425 video_supported
= TPACPI_VIDEO_570
;
4426 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4427 /* 600e/x, 770e, 770x */
4428 video_supported
= TPACPI_VIDEO_770
;
4431 video_supported
= TPACPI_VIDEO_NEW
;
4433 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4434 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4437 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4440 static void video_exit(void)
4442 dbg_printk(TPACPI_DBG_EXIT
,
4443 "restoring original video autoswitch mode\n");
4444 if (video_autosw_set(video_orig_autosw
))
4445 printk(TPACPI_ERR
"error while trying to restore original "
4446 "video autoswitch mode\n");
4449 static int video_outputsw_get(void)
4454 switch (video_supported
) {
4455 case TPACPI_VIDEO_570
:
4456 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4457 TP_ACPI_VIDEO_570_PHSCMD
))
4459 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4461 case TPACPI_VIDEO_770
:
4462 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4465 status
|= TP_ACPI_VIDEO_S_LCD
;
4466 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4469 status
|= TP_ACPI_VIDEO_S_CRT
;
4471 case TPACPI_VIDEO_NEW
:
4472 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4473 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4476 status
|= TP_ACPI_VIDEO_S_CRT
;
4478 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4479 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4482 status
|= TP_ACPI_VIDEO_S_LCD
;
4483 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4486 status
|= TP_ACPI_VIDEO_S_DVI
;
4495 static int video_outputsw_set(int status
)
4500 switch (video_supported
) {
4501 case TPACPI_VIDEO_570
:
4502 res
= acpi_evalf(NULL
, NULL
,
4503 "\\_SB.PHS2", "vdd",
4504 TP_ACPI_VIDEO_570_PHS2CMD
,
4505 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4507 case TPACPI_VIDEO_770
:
4508 autosw
= video_autosw_get();
4512 res
= video_autosw_set(1);
4515 res
= acpi_evalf(vid_handle
, NULL
,
4516 "ASWT", "vdd", status
* 0x100, 0);
4517 if (!autosw
&& video_autosw_set(autosw
)) {
4519 "video auto-switch left enabled due to error\n");
4523 case TPACPI_VIDEO_NEW
:
4524 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4525 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4531 return (res
)? 0 : -EIO
;
4534 static int video_autosw_get(void)
4538 switch (video_supported
) {
4539 case TPACPI_VIDEO_570
:
4540 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4543 case TPACPI_VIDEO_770
:
4544 case TPACPI_VIDEO_NEW
:
4545 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4555 static int video_autosw_set(int enable
)
4557 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4562 static int video_outputsw_cycle(void)
4564 int autosw
= video_autosw_get();
4570 switch (video_supported
) {
4571 case TPACPI_VIDEO_570
:
4572 res
= video_autosw_set(1);
4575 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4577 case TPACPI_VIDEO_770
:
4578 case TPACPI_VIDEO_NEW
:
4579 res
= video_autosw_set(1);
4582 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4587 if (!autosw
&& video_autosw_set(autosw
)) {
4589 "video auto-switch left enabled due to error\n");
4593 return (res
)? 0 : -EIO
;
4596 static int video_expand_toggle(void)
4598 switch (video_supported
) {
4599 case TPACPI_VIDEO_570
:
4600 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4602 case TPACPI_VIDEO_770
:
4603 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4605 case TPACPI_VIDEO_NEW
:
4606 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4614 static int video_read(char *p
)
4619 if (video_supported
== TPACPI_VIDEO_NONE
) {
4620 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4624 status
= video_outputsw_get();
4628 autosw
= video_autosw_get();
4632 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4633 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
4634 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
4635 if (video_supported
== TPACPI_VIDEO_NEW
)
4636 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
4637 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
4638 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
4639 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
4640 if (video_supported
== TPACPI_VIDEO_NEW
)
4641 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
4642 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
4643 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
4648 static int video_write(char *buf
)
4651 int enable
, disable
, status
;
4654 if (video_supported
== TPACPI_VIDEO_NONE
)
4660 while ((cmd
= next_cmd(&buf
))) {
4661 if (strlencmp(cmd
, "lcd_enable") == 0) {
4662 enable
|= TP_ACPI_VIDEO_S_LCD
;
4663 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4664 disable
|= TP_ACPI_VIDEO_S_LCD
;
4665 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4666 enable
|= TP_ACPI_VIDEO_S_CRT
;
4667 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4668 disable
|= TP_ACPI_VIDEO_S_CRT
;
4669 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4670 strlencmp(cmd
, "dvi_enable") == 0) {
4671 enable
|= TP_ACPI_VIDEO_S_DVI
;
4672 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4673 strlencmp(cmd
, "dvi_disable") == 0) {
4674 disable
|= TP_ACPI_VIDEO_S_DVI
;
4675 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4676 res
= video_autosw_set(1);
4679 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4680 res
= video_autosw_set(0);
4683 } else if (strlencmp(cmd
, "video_switch") == 0) {
4684 res
= video_outputsw_cycle();
4687 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4688 res
= video_expand_toggle();
4695 if (enable
|| disable
) {
4696 status
= video_outputsw_get();
4699 res
= video_outputsw_set((status
& ~disable
) | enable
);
4707 static struct ibm_struct video_driver_data
= {
4710 .write
= video_write
,
4714 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4716 /*************************************************************************
4717 * Light (thinklight) subdriver
4720 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4721 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4723 static int light_get_status(void)
4727 if (tp_features
.light_status
) {
4728 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4736 static int light_set_status(int status
)
4740 if (tp_features
.light
) {
4742 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4744 TP_CMOS_THINKLIGHT_ON
:
4745 TP_CMOS_THINKLIGHT_OFF
);
4747 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4750 return (rc
)? 0 : -EIO
;
4756 static void light_set_status_worker(struct work_struct
*work
)
4758 struct tpacpi_led_classdev
*data
=
4759 container_of(work
, struct tpacpi_led_classdev
, work
);
4761 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4762 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4765 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4766 enum led_brightness brightness
)
4768 struct tpacpi_led_classdev
*data
=
4769 container_of(led_cdev
,
4770 struct tpacpi_led_classdev
,
4772 data
->new_state
= (brightness
!= LED_OFF
) ?
4773 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4774 queue_work(tpacpi_wq
, &data
->work
);
4777 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4779 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4782 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4784 .name
= "tpacpi::thinklight",
4785 .brightness_set
= &light_sysfs_set
,
4786 .brightness_get
= &light_sysfs_get
,
4790 static int __init
light_init(struct ibm_init_struct
*iibm
)
4794 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4796 TPACPI_ACPIHANDLE_INIT(ledb
);
4797 TPACPI_ACPIHANDLE_INIT(lght
);
4798 TPACPI_ACPIHANDLE_INIT(cmos
);
4799 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4801 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4802 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4804 if (tp_features
.light
)
4805 /* light status not supported on
4806 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4807 tp_features
.light_status
=
4808 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4810 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4811 str_supported(tp_features
.light
),
4812 str_supported(tp_features
.light_status
));
4814 if (!tp_features
.light
)
4817 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4818 &tpacpi_led_thinklight
.led_classdev
);
4821 tp_features
.light
= 0;
4822 tp_features
.light_status
= 0;
4830 static void light_exit(void)
4832 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4833 if (work_pending(&tpacpi_led_thinklight
.work
))
4834 flush_workqueue(tpacpi_wq
);
4837 static int light_read(char *p
)
4842 if (!tp_features
.light
) {
4843 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4844 } else if (!tp_features
.light_status
) {
4845 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
4846 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4848 status
= light_get_status();
4851 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
4852 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4858 static int light_write(char *buf
)
4863 if (!tp_features
.light
)
4866 while ((cmd
= next_cmd(&buf
))) {
4867 if (strlencmp(cmd
, "on") == 0) {
4869 } else if (strlencmp(cmd
, "off") == 0) {
4875 return light_set_status(newstatus
);
4878 static struct ibm_struct light_driver_data
= {
4881 .write
= light_write
,
4885 /*************************************************************************
4889 /* sysfs cmos_command -------------------------------------------------- */
4890 static ssize_t
cmos_command_store(struct device
*dev
,
4891 struct device_attribute
*attr
,
4892 const char *buf
, size_t count
)
4894 unsigned long cmos_cmd
;
4897 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4900 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4901 return (res
)? res
: count
;
4904 static struct device_attribute dev_attr_cmos_command
=
4905 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4907 /* --------------------------------------------------------------------- */
4909 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4913 vdbg_printk(TPACPI_DBG_INIT
,
4914 "initializing cmos commands subdriver\n");
4916 TPACPI_ACPIHANDLE_INIT(cmos
);
4918 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4919 str_supported(cmos_handle
!= NULL
));
4921 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4925 return (cmos_handle
)? 0 : 1;
4928 static void cmos_exit(void)
4930 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4933 static int cmos_read(char *p
)
4937 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4938 R30, R31, T20-22, X20-21 */
4940 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4942 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4943 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4949 static int cmos_write(char *buf
)
4954 while ((cmd
= next_cmd(&buf
))) {
4955 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4956 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4961 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4969 static struct ibm_struct cmos_driver_data
= {
4972 .write
= cmos_write
,
4976 /*************************************************************************
4980 enum led_access_mode
{
4981 TPACPI_LED_NONE
= 0,
4982 TPACPI_LED_570
, /* 570 */
4983 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4984 TPACPI_LED_NEW
, /* all others */
4987 enum { /* For TPACPI_LED_OLD */
4988 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4989 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4990 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4993 static enum led_access_mode led_supported
;
4995 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4996 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4997 /* T20-22, X20-21 */
4998 "LED", /* all others */
5001 #define TPACPI_LED_NUMLEDS 16
5002 static struct tpacpi_led_classdev
*tpacpi_leds
;
5003 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
5004 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
5005 /* there's a limit of 19 chars + NULL before 2.6.26 */
5007 "tpacpi:orange:batt",
5008 "tpacpi:green:batt",
5009 "tpacpi::dock_active",
5010 "tpacpi::bay_active",
5011 "tpacpi::dock_batt",
5012 "tpacpi::unknown_led",
5014 "tpacpi::dock_status1",
5015 "tpacpi::dock_status2",
5016 "tpacpi::unknown_led2",
5017 "tpacpi::unknown_led3",
5018 "tpacpi::thinkvantage",
5020 #define TPACPI_SAFE_LEDS 0x1081U
5022 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
5024 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5027 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
5031 static int led_get_status(const unsigned int led
)
5034 enum led_status_t led_s
;
5036 switch (led_supported
) {
5037 case TPACPI_LED_570
:
5038 if (!acpi_evalf(ec_handle
,
5039 &status
, "GLED", "dd", 1 << led
))
5041 led_s
= (status
== 0)?
5046 tpacpi_led_state_cache
[led
] = led_s
;
5055 static int led_set_status(const unsigned int led
,
5056 const enum led_status_t ledstatus
)
5058 /* off, on, blink. Index is led_status_t */
5059 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
5060 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
5064 switch (led_supported
) {
5065 case TPACPI_LED_570
:
5067 if (unlikely(led
> 7))
5069 if (unlikely(tpacpi_is_led_restricted(led
)))
5071 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5072 (1 << led
), led_sled_arg1
[ledstatus
]))
5075 case TPACPI_LED_OLD
:
5076 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
5077 if (unlikely(led
> 7))
5079 if (unlikely(tpacpi_is_led_restricted(led
)))
5081 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
5083 rc
= ec_write(TPACPI_LED_EC_HLBL
,
5084 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5086 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5087 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5089 case TPACPI_LED_NEW
:
5091 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5093 if (unlikely(tpacpi_is_led_restricted(led
)))
5095 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5096 led
, led_led_arg1
[ledstatus
]))
5104 tpacpi_led_state_cache
[led
] = ledstatus
;
5109 static void led_set_status_worker(struct work_struct
*work
)
5111 struct tpacpi_led_classdev
*data
=
5112 container_of(work
, struct tpacpi_led_classdev
, work
);
5114 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5115 led_set_status(data
->led
, data
->new_state
);
5118 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5119 enum led_brightness brightness
)
5121 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5122 struct tpacpi_led_classdev
, led_classdev
);
5124 if (brightness
== LED_OFF
)
5125 data
->new_state
= TPACPI_LED_OFF
;
5126 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5127 data
->new_state
= TPACPI_LED_ON
;
5129 data
->new_state
= TPACPI_LED_BLINK
;
5131 queue_work(tpacpi_wq
, &data
->work
);
5134 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5135 unsigned long *delay_on
, unsigned long *delay_off
)
5137 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5138 struct tpacpi_led_classdev
, led_classdev
);
5140 /* Can we choose the flash rate? */
5141 if (*delay_on
== 0 && *delay_off
== 0) {
5142 /* yes. set them to the hardware blink rate (1 Hz) */
5143 *delay_on
= 500; /* ms */
5144 *delay_off
= 500; /* ms */
5145 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5148 data
->new_state
= TPACPI_LED_BLINK
;
5149 queue_work(tpacpi_wq
, &data
->work
);
5154 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5158 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5159 struct tpacpi_led_classdev
, led_classdev
);
5161 rc
= led_get_status(data
->led
);
5163 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5164 rc
= LED_OFF
; /* no error handling in led class :( */
5171 static void led_exit(void)
5175 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5176 if (tpacpi_leds
[i
].led_classdev
.name
)
5177 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5183 static int __init
tpacpi_init_led(unsigned int led
)
5187 tpacpi_leds
[led
].led
= led
;
5189 /* LEDs with no name don't get registered */
5190 if (!tpacpi_led_names
[led
])
5193 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5194 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5195 if (led_supported
== TPACPI_LED_570
)
5196 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5199 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5201 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5203 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5204 &tpacpi_leds
[led
].led_classdev
);
5206 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5211 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5212 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5213 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5214 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5216 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5217 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5218 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5219 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5220 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5221 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5222 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5223 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5225 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5226 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5227 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5228 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5229 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5231 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5232 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5233 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5234 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5236 /* (1) - may have excess leds enabled on MSB */
5238 /* Defaults (order matters, keep last, don't reorder!) */
5240 .vendor
= PCI_VENDOR_ID_LENOVO
,
5241 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5244 { /* IBM ThinkPads with no EC version string */
5245 .vendor
= PCI_VENDOR_ID_IBM
,
5246 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5249 { /* IBM ThinkPads with EC version string */
5250 .vendor
= PCI_VENDOR_ID_IBM
,
5251 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5256 #undef TPACPI_LEDQ_IBM
5257 #undef TPACPI_LEDQ_LNV
5259 static int __init
led_init(struct ibm_init_struct
*iibm
)
5263 unsigned long useful_leds
;
5265 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5267 TPACPI_ACPIHANDLE_INIT(led
);
5270 /* led not supported on R30, R31 */
5271 led_supported
= TPACPI_LED_NONE
;
5272 else if (strlencmp(led_path
, "SLED") == 0)
5274 led_supported
= TPACPI_LED_570
;
5275 else if (strlencmp(led_path
, "SYSL") == 0)
5276 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5277 led_supported
= TPACPI_LED_OLD
;
5280 led_supported
= TPACPI_LED_NEW
;
5282 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5283 str_supported(led_supported
), led_supported
);
5285 if (led_supported
== TPACPI_LED_NONE
)
5288 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5291 printk(TPACPI_ERR
"Out of memory for LED data\n");
5295 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5296 ARRAY_SIZE(led_useful_qtable
));
5298 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5299 if (!tpacpi_is_led_restricted(i
) &&
5300 test_bit(i
, &useful_leds
)) {
5301 rc
= tpacpi_init_led(i
);
5309 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5310 printk(TPACPI_NOTICE
5311 "warning: userspace override of important "
5312 "firmware LEDs is enabled\n");
5317 #define str_led_status(s) \
5318 ((s) == TPACPI_LED_OFF ? "off" : \
5319 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5321 static int led_read(char *p
)
5325 if (!led_supported
) {
5326 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5329 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
5331 if (led_supported
== TPACPI_LED_570
) {
5334 for (i
= 0; i
< 8; i
++) {
5335 status
= led_get_status(i
);
5338 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
5339 i
, str_led_status(status
));
5343 len
+= sprintf(p
+ len
, "commands:\t"
5344 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5349 static int led_write(char *buf
)
5353 enum led_status_t s
;
5358 while ((cmd
= next_cmd(&buf
))) {
5359 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5362 if (strstr(cmd
, "off")) {
5364 } else if (strstr(cmd
, "on")) {
5366 } else if (strstr(cmd
, "blink")) {
5367 s
= TPACPI_LED_BLINK
;
5372 rc
= led_set_status(led
, s
);
5380 static struct ibm_struct led_driver_data
= {
5387 /*************************************************************************
5391 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5393 #define TPACPI_BEEP_Q1 0x0001
5395 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5396 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5397 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5400 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5402 unsigned long quirks
;
5404 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5406 TPACPI_ACPIHANDLE_INIT(beep
);
5408 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5409 str_supported(beep_handle
!= NULL
));
5411 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5412 ARRAY_SIZE(beep_quirk_table
));
5414 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5416 return (beep_handle
)? 0 : 1;
5419 static int beep_read(char *p
)
5424 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5426 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
5427 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5433 static int beep_write(char *buf
)
5441 while ((cmd
= next_cmd(&buf
))) {
5442 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5443 beep_cmd
>= 0 && beep_cmd
<= 17) {
5447 if (tp_features
.beep_needs_two_args
) {
5448 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5452 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5461 static struct ibm_struct beep_driver_data
= {
5464 .write
= beep_write
,
5467 /*************************************************************************
5471 enum thermal_access_mode
{
5472 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5473 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5474 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5475 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5476 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5479 enum { /* TPACPI_THERMAL_TPEC_* */
5480 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5481 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5482 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5485 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5486 struct ibm_thermal_sensors_struct
{
5487 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5490 static enum thermal_access_mode thermal_read_mode
;
5492 /* idx is zero-based */
5493 static int thermal_get_sensor(int idx
, s32
*value
)
5499 t
= TP_EC_THERMAL_TMP0
;
5501 switch (thermal_read_mode
) {
5502 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5503 case TPACPI_THERMAL_TPEC_16
:
5504 if (idx
>= 8 && idx
<= 15) {
5505 t
= TP_EC_THERMAL_TMP8
;
5510 case TPACPI_THERMAL_TPEC_8
:
5512 if (!acpi_ec_read(t
+ idx
, &tmp
))
5514 *value
= tmp
* 1000;
5519 case TPACPI_THERMAL_ACPI_UPDT
:
5521 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5522 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5524 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5526 *value
= (t
- 2732) * 100;
5531 case TPACPI_THERMAL_ACPI_TMP07
:
5533 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5534 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5536 if (t
> 127 || t
< -127)
5537 t
= TP_EC_THERMAL_TMP_NA
;
5543 case TPACPI_THERMAL_NONE
:
5551 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5562 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5565 for (i
= 0 ; i
< n
; i
++) {
5566 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5574 /* sysfs temp##_input -------------------------------------------------- */
5576 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5577 struct device_attribute
*attr
,
5580 struct sensor_device_attribute
*sensor_attr
=
5581 to_sensor_dev_attr(attr
);
5582 int idx
= sensor_attr
->index
;
5586 res
= thermal_get_sensor(idx
, &value
);
5589 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
5592 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5595 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5596 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5597 thermal_temp_input_show, NULL, _idxB)
5599 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5600 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5601 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5602 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5603 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5604 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5605 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5606 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5607 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5608 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5609 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5610 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5611 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5612 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5613 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5614 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5615 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5618 #define THERMAL_ATTRS(X) \
5619 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5621 static struct attribute
*thermal_temp_input_attr
[] = {
5641 static const struct attribute_group thermal_temp_input16_group
= {
5642 .attrs
= thermal_temp_input_attr
5645 static const struct attribute_group thermal_temp_input8_group
= {
5646 .attrs
= &thermal_temp_input_attr
[8]
5649 #undef THERMAL_SENSOR_ATTR_TEMP
5650 #undef THERMAL_ATTRS
5652 /* --------------------------------------------------------------------- */
5654 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5661 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5663 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5665 if (thinkpad_id
.ec_model
) {
5667 * Direct EC access mode: sensors at registers
5668 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5669 * non-implemented, thermal sensors return 0x80 when
5674 for (i
= 0; i
< 8; i
++) {
5675 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5681 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5689 /* This is sheer paranoia, but we handle it anyway */
5692 "ThinkPad ACPI EC access misbehaving, "
5693 "falling back to ACPI TMPx access "
5695 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5698 "ThinkPad ACPI EC access misbehaving, "
5699 "disabling thermal sensors access\n");
5700 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5705 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5707 } else if (acpi_tmp7
) {
5708 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5709 /* 600e/x, 770e, 770x */
5710 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5712 /* Standard ACPI TMPx access, max 8 sensors */
5713 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5716 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5717 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5720 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5721 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5724 switch (thermal_read_mode
) {
5725 case TPACPI_THERMAL_TPEC_16
:
5726 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5727 &thermal_temp_input16_group
);
5731 case TPACPI_THERMAL_TPEC_8
:
5732 case TPACPI_THERMAL_ACPI_TMP07
:
5733 case TPACPI_THERMAL_ACPI_UPDT
:
5734 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5735 &thermal_temp_input8_group
);
5739 case TPACPI_THERMAL_NONE
:
5747 static void thermal_exit(void)
5749 switch (thermal_read_mode
) {
5750 case TPACPI_THERMAL_TPEC_16
:
5751 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5752 &thermal_temp_input16_group
);
5754 case TPACPI_THERMAL_TPEC_8
:
5755 case TPACPI_THERMAL_ACPI_TMP07
:
5756 case TPACPI_THERMAL_ACPI_UPDT
:
5757 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5758 &thermal_temp_input16_group
);
5760 case TPACPI_THERMAL_NONE
:
5766 static int thermal_read(char *p
)
5770 struct ibm_thermal_sensors_struct t
;
5772 n
= thermal_get_sensors(&t
);
5773 if (unlikely(n
< 0))
5776 len
+= sprintf(p
+ len
, "temperatures:\t");
5779 for (i
= 0; i
< (n
- 1); i
++)
5780 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
5781 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
5783 len
+= sprintf(p
+ len
, "not supported\n");
5788 static struct ibm_struct thermal_driver_data
= {
5790 .read
= thermal_read
,
5791 .exit
= thermal_exit
,
5794 /*************************************************************************
5798 static u8 ecdump_regs
[256];
5800 static int ecdump_read(char *p
)
5806 len
+= sprintf(p
+ len
, "EC "
5807 " +00 +01 +02 +03 +04 +05 +06 +07"
5808 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5809 for (i
= 0; i
< 256; i
+= 16) {
5810 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
5811 for (j
= 0; j
< 16; j
++) {
5812 if (!acpi_ec_read(i
+ j
, &v
))
5814 if (v
!= ecdump_regs
[i
+ j
])
5815 len
+= sprintf(p
+ len
, " *%02x", v
);
5817 len
+= sprintf(p
+ len
, " %02x", v
);
5818 ecdump_regs
[i
+ j
] = v
;
5820 len
+= sprintf(p
+ len
, "\n");
5825 /* These are way too dangerous to advertise openly... */
5827 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
5828 " (<offset> is 00-ff, <value> is 00-ff)\n");
5829 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
5830 " (<offset> is 00-ff, <value> is 0-255)\n");
5835 static int ecdump_write(char *buf
)
5840 while ((cmd
= next_cmd(&buf
))) {
5841 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5843 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5847 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5848 if (!acpi_ec_write(i
, v
))
5857 static struct ibm_struct ecdump_driver_data
= {
5859 .read
= ecdump_read
,
5860 .write
= ecdump_write
,
5861 .flags
.experimental
= 1,
5864 /*************************************************************************
5865 * Backlight/brightness subdriver
5868 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5871 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5872 * CMOS NVRAM byte 0x5E, bits 0-3.
5874 * EC HBRV (0x31) has the following layout
5875 * Bit 7: unknown function
5876 * Bit 6: unknown function
5877 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5878 * Bit 4: must be set to zero to avoid problems
5879 * Bit 3-0: backlight brightness level
5881 * brightness_get_raw returns status data in the HBRV layout
5883 * WARNING: The X61 has been verified to use HBRV for something else, so
5884 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5885 * testing on the very early *60 Lenovo models...
5889 TP_EC_BACKLIGHT
= 0x31,
5891 /* TP_EC_BACKLIGHT bitmasks */
5892 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5893 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5894 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5897 enum tpacpi_brightness_access_mode
{
5898 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5899 TPACPI_BRGHT_MODE_EC
, /* EC control */
5900 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5901 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5902 TPACPI_BRGHT_MODE_MAX
5905 static struct backlight_device
*ibm_backlight_device
;
5907 static enum tpacpi_brightness_access_mode brightness_mode
=
5908 TPACPI_BRGHT_MODE_MAX
;
5910 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5912 static struct mutex brightness_mutex
;
5914 /* NVRAM brightness access,
5915 * call with brightness_mutex held! */
5916 static unsigned int tpacpi_brightness_nvram_get(void)
5920 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5921 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5922 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5923 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5928 static void tpacpi_brightness_checkpoint_nvram(void)
5933 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5936 vdbg_printk(TPACPI_DBG_BRGHT
,
5937 "trying to checkpoint backlight level to NVRAM...\n");
5939 if (mutex_lock_killable(&brightness_mutex
) < 0)
5942 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5944 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5945 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5947 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5948 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5949 /* NVRAM needs update */
5950 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5951 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5953 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5954 dbg_printk(TPACPI_DBG_BRGHT
,
5955 "updated NVRAM backlight level to %u (0x%02x)\n",
5956 (unsigned int) lec
, (unsigned int) b_nvram
);
5958 vdbg_printk(TPACPI_DBG_BRGHT
,
5959 "NVRAM backlight level already is %u (0x%02x)\n",
5960 (unsigned int) lec
, (unsigned int) b_nvram
);
5963 mutex_unlock(&brightness_mutex
);
5967 /* call with brightness_mutex held! */
5968 static int tpacpi_brightness_get_raw(int *status
)
5972 switch (brightness_mode
) {
5973 case TPACPI_BRGHT_MODE_UCMS_STEP
:
5974 *status
= tpacpi_brightness_nvram_get();
5976 case TPACPI_BRGHT_MODE_EC
:
5977 case TPACPI_BRGHT_MODE_ECNVRAM
:
5978 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5987 /* call with brightness_mutex held! */
5988 /* do NOT call with illegal backlight level value */
5989 static int tpacpi_brightness_set_ec(unsigned int value
)
5993 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5996 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
5997 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
5998 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
6004 /* call with brightness_mutex held! */
6005 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
6008 unsigned int current_value
, i
;
6010 current_value
= tpacpi_brightness_nvram_get();
6012 if (value
== current_value
)
6015 cmos_cmd
= (value
> current_value
) ?
6016 TP_CMOS_BRIGHTNESS_UP
:
6017 TP_CMOS_BRIGHTNESS_DOWN
;
6018 inc
= (value
> current_value
) ? 1 : -1;
6020 for (i
= current_value
; i
!= value
; i
+= inc
)
6021 if (issue_thinkpad_cmos_command(cmos_cmd
))
6027 /* May return EINTR which can always be mapped to ERESTARTSYS */
6028 static int brightness_set(unsigned int value
)
6032 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
6036 vdbg_printk(TPACPI_DBG_BRGHT
,
6037 "set backlight level to %d\n", value
);
6039 res
= mutex_lock_killable(&brightness_mutex
);
6043 switch (brightness_mode
) {
6044 case TPACPI_BRGHT_MODE_EC
:
6045 case TPACPI_BRGHT_MODE_ECNVRAM
:
6046 res
= tpacpi_brightness_set_ec(value
);
6048 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6049 res
= tpacpi_brightness_set_ucmsstep(value
);
6055 mutex_unlock(&brightness_mutex
);
6059 /* sysfs backlight class ----------------------------------------------- */
6061 static int brightness_update_status(struct backlight_device
*bd
)
6063 unsigned int level
=
6064 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
6065 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
6066 bd
->props
.brightness
: 0;
6068 dbg_printk(TPACPI_DBG_BRGHT
,
6069 "backlight: attempt to set level to %d\n",
6072 /* it is the backlight class's job (caller) to handle
6073 * EINTR and other errors properly */
6074 return brightness_set(level
);
6077 static int brightness_get(struct backlight_device
*bd
)
6081 res
= mutex_lock_killable(&brightness_mutex
);
6085 res
= tpacpi_brightness_get_raw(&status
);
6087 mutex_unlock(&brightness_mutex
);
6092 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6095 static void tpacpi_brightness_notify_change(void)
6097 backlight_force_update(ibm_backlight_device
,
6098 BACKLIGHT_UPDATE_HOTKEY
);
6101 static struct backlight_ops ibm_backlight_data
= {
6102 .get_brightness
= brightness_get
,
6103 .update_status
= brightness_update_status
,
6106 /* --------------------------------------------------------------------- */
6109 * These are only useful for models that have only one possibility
6110 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6113 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6114 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6115 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6117 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6118 /* Models with ATI GPUs known to require ECNVRAM mode */
6119 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6121 /* Models with ATI GPUs that can use ECNVRAM */
6122 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
),
6123 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6124 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6125 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6127 /* Models with Intel Extreme Graphics 2 */
6128 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
),
6129 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_NOEC
),
6130 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_NOEC
),
6132 /* Models with Intel GMA900 */
6133 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6134 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6135 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6138 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6141 unsigned long quirks
;
6143 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6145 mutex_init(&brightness_mutex
);
6147 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6148 ARRAY_SIZE(brightness_quirk_table
));
6151 * We always attempt to detect acpi support, so as to switch
6152 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6153 * going to publish a backlight interface
6155 b
= tpacpi_check_std_acpi_brightness_support();
6158 if (acpi_video_backlight_support()) {
6159 if (brightness_enable
> 1) {
6160 printk(TPACPI_NOTICE
6161 "Standard ACPI backlight interface "
6162 "available, not loading native one.\n");
6164 } else if (brightness_enable
== 1) {
6165 printk(TPACPI_NOTICE
6166 "Backlight control force enabled, even if standard "
6167 "ACPI backlight interface is available\n");
6170 if (brightness_enable
> 1) {
6171 printk(TPACPI_NOTICE
6172 "Standard ACPI backlight interface not "
6173 "available, thinkpad_acpi native "
6174 "brightness control enabled\n");
6179 if (!brightness_enable
) {
6180 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6181 "brightness support disabled by "
6182 "module parameter\n");
6188 "Unsupported brightness interface, "
6189 "please contact %s\n", TPACPI_MAIL
);
6193 tp_features
.bright_16levels
= 1;
6196 * Check for module parameter bogosity, note that we
6197 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6198 * able to detect "unspecified"
6200 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6203 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6204 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6205 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6206 if (quirks
& TPACPI_BRGHT_Q_EC
)
6207 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6209 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6211 dbg_printk(TPACPI_DBG_BRGHT
,
6212 "driver auto-selected brightness_mode=%d\n",
6217 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6218 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6219 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6222 if (tpacpi_brightness_get_raw(&b
) < 0)
6225 if (tp_features
.bright_16levels
)
6227 "detected a 16-level brightness capable ThinkPad\n");
6229 ibm_backlight_device
= backlight_device_register(
6230 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6231 &ibm_backlight_data
);
6232 if (IS_ERR(ibm_backlight_device
)) {
6233 int rc
= PTR_ERR(ibm_backlight_device
);
6234 ibm_backlight_device
= NULL
;
6235 printk(TPACPI_ERR
"Could not register backlight device\n");
6238 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6239 "brightness is supported\n");
6241 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6242 printk(TPACPI_NOTICE
6243 "brightness: will use unverified default: "
6244 "brightness_mode=%d\n", brightness_mode
);
6245 printk(TPACPI_NOTICE
6246 "brightness: please report to %s whether it works well "
6247 "or not on your ThinkPad\n", TPACPI_MAIL
);
6250 ibm_backlight_device
->props
.max_brightness
=
6251 (tp_features
.bright_16levels
)? 15 : 7;
6252 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6253 backlight_update_status(ibm_backlight_device
);
6255 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6256 "brightness: registering brightness hotkeys "
6257 "as change notification\n");
6258 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6259 | TP_ACPI_HKEY_BRGHTUP_MASK
6260 | TP_ACPI_HKEY_BRGHTDWN_MASK
);;
6264 static void brightness_suspend(pm_message_t state
)
6266 tpacpi_brightness_checkpoint_nvram();
6269 static void brightness_shutdown(void)
6271 tpacpi_brightness_checkpoint_nvram();
6274 static void brightness_exit(void)
6276 if (ibm_backlight_device
) {
6277 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6278 "calling backlight_device_unregister()\n");
6279 backlight_device_unregister(ibm_backlight_device
);
6282 tpacpi_brightness_checkpoint_nvram();
6285 static int brightness_read(char *p
)
6290 level
= brightness_get(NULL
);
6292 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
6294 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
6295 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
6296 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
6297 " (<level> is 0-%d)\n",
6298 (tp_features
.bright_16levels
) ? 15 : 7);
6304 static int brightness_write(char *buf
)
6309 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6311 level
= brightness_get(NULL
);
6315 while ((cmd
= next_cmd(&buf
))) {
6316 if (strlencmp(cmd
, "up") == 0) {
6317 if (level
< max_level
)
6319 } else if (strlencmp(cmd
, "down") == 0) {
6322 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6323 level
>= 0 && level
<= max_level
) {
6329 tpacpi_disclose_usertask("procfs brightness",
6330 "set level to %d\n", level
);
6333 * Now we know what the final level should be, so we try to set it.
6334 * Doing it this way makes the syscall restartable in case of EINTR
6336 rc
= brightness_set(level
);
6337 if (!rc
&& ibm_backlight_device
)
6338 backlight_force_update(ibm_backlight_device
,
6339 BACKLIGHT_UPDATE_SYSFS
);
6340 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6343 static struct ibm_struct brightness_driver_data
= {
6344 .name
= "brightness",
6345 .read
= brightness_read
,
6346 .write
= brightness_write
,
6347 .exit
= brightness_exit
,
6348 .suspend
= brightness_suspend
,
6349 .shutdown
= brightness_shutdown
,
6352 /*************************************************************************
6356 static int volume_offset
= 0x30;
6358 static int volume_read(char *p
)
6363 if (!acpi_ec_read(volume_offset
, &level
)) {
6364 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
6366 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
6367 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
6368 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
6369 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
6370 " (<level> is 0-15)\n");
6376 static int volume_write(char *buf
)
6378 int cmos_cmd
, inc
, i
;
6380 int new_level
, new_mute
;
6383 while ((cmd
= next_cmd(&buf
))) {
6384 if (!acpi_ec_read(volume_offset
, &level
))
6386 new_mute
= mute
= level
& 0x40;
6387 new_level
= level
= level
& 0xf;
6389 if (strlencmp(cmd
, "up") == 0) {
6393 new_level
= level
== 15 ? 15 : level
+ 1;
6394 } else if (strlencmp(cmd
, "down") == 0) {
6398 new_level
= level
== 0 ? 0 : level
- 1;
6399 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
6400 new_level
>= 0 && new_level
<= 15) {
6402 } else if (strlencmp(cmd
, "mute") == 0) {
6407 if (new_level
!= level
) {
6408 /* mute doesn't change */
6410 cmos_cmd
= (new_level
> level
) ?
6411 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
6412 inc
= new_level
> level
? 1 : -1;
6414 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
6415 !acpi_ec_write(volume_offset
, level
)))
6418 for (i
= level
; i
!= new_level
; i
+= inc
)
6419 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
6420 !acpi_ec_write(volume_offset
, i
+ inc
))
6424 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
6425 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
6430 if (new_mute
!= mute
) {
6431 /* level doesn't change */
6433 cmos_cmd
= (new_mute
) ?
6434 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
6436 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
6437 !acpi_ec_write(volume_offset
, level
+ new_mute
))
6445 static struct ibm_struct volume_driver_data
= {
6447 .read
= volume_read
,
6448 .write
= volume_write
,
6451 /*************************************************************************
6458 * TPACPI_FAN_RD_ACPI_GFAN:
6459 * ACPI GFAN method: returns fan level
6461 * see TPACPI_FAN_WR_ACPI_SFAN
6462 * EC 0x2f (HFSP) not available if GFAN exists
6464 * TPACPI_FAN_WR_ACPI_SFAN:
6465 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
6467 * EC 0x2f (HFSP) might be available *for reading*, but do not use
6470 * TPACPI_FAN_WR_TPEC:
6471 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
6472 * Supported on almost all ThinkPads
6474 * Fan speed changes of any sort (including those caused by the
6475 * disengaged mode) are usually done slowly by the firmware as the
6476 * maximum ammount of fan duty cycle change per second seems to be
6479 * Reading is not available if GFAN exists.
6480 * Writing is not available if SFAN exists.
6483 * 7 automatic mode engaged;
6484 * (default operation mode of the ThinkPad)
6485 * fan level is ignored in this mode.
6486 * 6 full speed mode (takes precedence over bit 7);
6487 * not available on all thinkpads. May disable
6488 * the tachometer while the fan controller ramps up
6489 * the speed (which can take up to a few *minutes*).
6490 * Speeds up fan to 100% duty-cycle, which is far above
6491 * the standard RPM levels. It is not impossible that
6492 * it could cause hardware damage.
6493 * 5-3 unused in some models. Extra bits for fan level
6494 * in others, but still useless as all values above
6495 * 7 map to the same speed as level 7 in these models.
6496 * 2-0 fan level (0..7 usually)
6498 * 0x07 = max (set when temperatures critical)
6499 * Some ThinkPads may have other levels, see
6500 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
6502 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
6503 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
6504 * does so, its initial value is meaningless (0x07).
6506 * For firmware bugs, refer to:
6507 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6511 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
6512 * Main fan tachometer reading (in RPM)
6514 * This register is present on all ThinkPads with a new-style EC, and
6515 * it is known not to be present on the A21m/e, and T22, as there is
6516 * something else in offset 0x84 according to the ACPI DSDT. Other
6517 * ThinkPads from this same time period (and earlier) probably lack the
6518 * tachometer as well.
6520 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
6521 * was never fixed by IBM to report the EC firmware version string
6522 * probably support the tachometer (like the early X models), so
6523 * detecting it is quite hard. We need more data to know for sure.
6525 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
6528 * FIRMWARE BUG: may go stale while the EC is switching to full speed
6531 * For firmware bugs, refer to:
6532 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6536 * ThinkPad EC register 0x31 bit 0 (only on select models)
6538 * When bit 0 of EC register 0x31 is zero, the tachometer registers
6539 * show the speed of the main fan. When bit 0 of EC register 0x31
6540 * is one, the tachometer registers show the speed of the auxiliary
6543 * Fan control seems to affect both fans, regardless of the state
6546 * So far, only the firmware for the X60/X61 non-tablet versions
6547 * seem to support this (firmware TP-7M).
6549 * TPACPI_FAN_WR_ACPI_FANS:
6550 * ThinkPad X31, X40, X41. Not available in the X60.
6552 * FANS ACPI handle: takes three arguments: low speed, medium speed,
6553 * high speed. ACPI DSDT seems to map these three speeds to levels
6554 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
6555 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
6557 * The speeds are stored on handles
6558 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
6560 * There are three default speed sets, accessible as handles:
6561 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
6563 * ACPI DSDT switches which set is in use depending on various
6566 * TPACPI_FAN_WR_TPEC is also available and should be used to
6567 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
6568 * but the ACPI tables just mention level 7.
6571 enum { /* Fan control constants */
6572 fan_status_offset
= 0x2f, /* EC register 0x2f */
6573 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
6574 * 0x84 must be read before 0x85 */
6575 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
6576 bit 0 selects which fan is active */
6578 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
6579 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
6581 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
6584 enum fan_status_access_mode
{
6585 TPACPI_FAN_NONE
= 0, /* No fan status or control */
6586 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
6587 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
6590 enum fan_control_access_mode
{
6591 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
6592 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
6593 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
6594 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
6597 enum fan_control_commands
{
6598 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
6599 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
6600 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
6601 * and also watchdog cmd */
6604 static int fan_control_allowed
;
6606 static enum fan_status_access_mode fan_status_access_mode
;
6607 static enum fan_control_access_mode fan_control_access_mode
;
6608 static enum fan_control_commands fan_control_commands
;
6610 static u8 fan_control_initial_status
;
6611 static u8 fan_control_desired_level
;
6612 static u8 fan_control_resume_level
;
6613 static int fan_watchdog_maxinterval
;
6615 static struct mutex fan_mutex
;
6617 static void fan_watchdog_fire(struct work_struct
*ignored
);
6618 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
6620 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
6621 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
6622 "\\FSPD", /* 600e/x, 770e, 770x */
6624 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
6625 "JFNS", /* 770x-JL */
6629 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
6630 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
6631 * be in auto mode (0x80).
6633 * This is corrected by any write to HFSP either by the driver, or
6636 * We assume 0x07 really means auto mode while this quirk is active,
6637 * as this is far more likely than the ThinkPad being in level 7,
6638 * which is only used by the firmware during thermal emergencies.
6640 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
6641 * TP-70 (T43, R52), which are known to be buggy.
6644 static void fan_quirk1_setup(void)
6646 if (fan_control_initial_status
== 0x07) {
6647 printk(TPACPI_NOTICE
6648 "fan_init: initial fan status is unknown, "
6649 "assuming it is in auto mode\n");
6650 tp_features
.fan_ctrl_status_undef
= 1;
6654 static void fan_quirk1_handle(u8
*fan_status
)
6656 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6657 if (*fan_status
!= fan_control_initial_status
) {
6658 /* something changed the HFSP regisnter since
6659 * driver init time, so it is not undefined
6661 tp_features
.fan_ctrl_status_undef
= 0;
6663 /* Return most likely status. In fact, it
6664 * might be the only possible status */
6665 *fan_status
= TP_EC_FAN_AUTO
;
6670 /* Select main fan on X60/X61, NOOP on others */
6671 static bool fan_select_fan1(void)
6673 if (tp_features
.second_fan
) {
6676 if (ec_read(fan_select_offset
, &val
) < 0)
6679 if (ec_write(fan_select_offset
, val
) < 0)
6685 /* Select secondary fan on X60/X61 */
6686 static bool fan_select_fan2(void)
6690 if (!tp_features
.second_fan
)
6693 if (ec_read(fan_select_offset
, &val
) < 0)
6696 if (ec_write(fan_select_offset
, val
) < 0)
6703 * Call with fan_mutex held
6705 static void fan_update_desired_level(u8 status
)
6708 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6710 fan_control_desired_level
= 7;
6712 fan_control_desired_level
= status
;
6716 static int fan_get_status(u8
*status
)
6721 * Add TPACPI_FAN_RD_ACPI_FANS ? */
6723 switch (fan_status_access_mode
) {
6724 case TPACPI_FAN_RD_ACPI_GFAN
:
6725 /* 570, 600e/x, 770e, 770x */
6727 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
6735 case TPACPI_FAN_RD_TPEC
:
6736 /* all except 570, 600e/x, 770e, 770x */
6737 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
6740 if (likely(status
)) {
6742 fan_quirk1_handle(status
);
6754 static int fan_get_status_safe(u8
*status
)
6759 if (mutex_lock_killable(&fan_mutex
))
6760 return -ERESTARTSYS
;
6761 rc
= fan_get_status(&s
);
6763 fan_update_desired_level(s
);
6764 mutex_unlock(&fan_mutex
);
6772 static int fan_get_speed(unsigned int *speed
)
6776 switch (fan_status_access_mode
) {
6777 case TPACPI_FAN_RD_TPEC
:
6778 /* all except 570, 600e/x, 770e, 770x */
6779 if (unlikely(!fan_select_fan1()))
6781 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
6782 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
6786 *speed
= (hi
<< 8) | lo
;
6797 static int fan2_get_speed(unsigned int *speed
)
6802 switch (fan_status_access_mode
) {
6803 case TPACPI_FAN_RD_TPEC
:
6804 /* all except 570, 600e/x, 770e, 770x */
6805 if (unlikely(!fan_select_fan2()))
6807 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
6808 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
6809 fan_select_fan1(); /* play it safe */
6814 *speed
= (hi
<< 8) | lo
;
6825 static int fan_set_level(int level
)
6827 if (!fan_control_allowed
)
6830 switch (fan_control_access_mode
) {
6831 case TPACPI_FAN_WR_ACPI_SFAN
:
6832 if (level
>= 0 && level
<= 7) {
6833 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
6839 case TPACPI_FAN_WR_ACPI_FANS
:
6840 case TPACPI_FAN_WR_TPEC
:
6841 if (!(level
& TP_EC_FAN_AUTO
) &&
6842 !(level
& TP_EC_FAN_FULLSPEED
) &&
6843 ((level
< 0) || (level
> 7)))
6846 /* safety net should the EC not support AUTO
6847 * or FULLSPEED mode bits and just ignore them */
6848 if (level
& TP_EC_FAN_FULLSPEED
)
6849 level
|= 7; /* safety min speed 7 */
6850 else if (level
& TP_EC_FAN_AUTO
)
6851 level
|= 4; /* safety min speed 4 */
6853 if (!acpi_ec_write(fan_status_offset
, level
))
6856 tp_features
.fan_ctrl_status_undef
= 0;
6863 vdbg_printk(TPACPI_DBG_FAN
,
6864 "fan control: set fan control register to 0x%02x\n", level
);
6868 static int fan_set_level_safe(int level
)
6872 if (!fan_control_allowed
)
6875 if (mutex_lock_killable(&fan_mutex
))
6876 return -ERESTARTSYS
;
6878 if (level
== TPACPI_FAN_LAST_LEVEL
)
6879 level
= fan_control_desired_level
;
6881 rc
= fan_set_level(level
);
6883 fan_update_desired_level(level
);
6885 mutex_unlock(&fan_mutex
);
6889 static int fan_set_enable(void)
6894 if (!fan_control_allowed
)
6897 if (mutex_lock_killable(&fan_mutex
))
6898 return -ERESTARTSYS
;
6900 switch (fan_control_access_mode
) {
6901 case TPACPI_FAN_WR_ACPI_FANS
:
6902 case TPACPI_FAN_WR_TPEC
:
6903 rc
= fan_get_status(&s
);
6907 /* Don't go out of emergency fan mode */
6910 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
6913 if (!acpi_ec_write(fan_status_offset
, s
))
6916 tp_features
.fan_ctrl_status_undef
= 0;
6921 case TPACPI_FAN_WR_ACPI_SFAN
:
6922 rc
= fan_get_status(&s
);
6928 /* Set fan to at least level 4 */
6931 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
6941 mutex_unlock(&fan_mutex
);
6944 vdbg_printk(TPACPI_DBG_FAN
,
6945 "fan control: set fan control register to 0x%02x\n",
6950 static int fan_set_disable(void)
6954 if (!fan_control_allowed
)
6957 if (mutex_lock_killable(&fan_mutex
))
6958 return -ERESTARTSYS
;
6961 switch (fan_control_access_mode
) {
6962 case TPACPI_FAN_WR_ACPI_FANS
:
6963 case TPACPI_FAN_WR_TPEC
:
6964 if (!acpi_ec_write(fan_status_offset
, 0x00))
6967 fan_control_desired_level
= 0;
6968 tp_features
.fan_ctrl_status_undef
= 0;
6972 case TPACPI_FAN_WR_ACPI_SFAN
:
6973 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
6976 fan_control_desired_level
= 0;
6984 vdbg_printk(TPACPI_DBG_FAN
,
6985 "fan control: set fan control register to 0\n");
6987 mutex_unlock(&fan_mutex
);
6991 static int fan_set_speed(int speed
)
6995 if (!fan_control_allowed
)
6998 if (mutex_lock_killable(&fan_mutex
))
6999 return -ERESTARTSYS
;
7002 switch (fan_control_access_mode
) {
7003 case TPACPI_FAN_WR_ACPI_FANS
:
7004 if (speed
>= 0 && speed
<= 65535) {
7005 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
7006 speed
, speed
, speed
))
7016 mutex_unlock(&fan_mutex
);
7020 static void fan_watchdog_reset(void)
7022 static int fan_watchdog_active
;
7024 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
7027 if (fan_watchdog_active
)
7028 cancel_delayed_work(&fan_watchdog_task
);
7030 if (fan_watchdog_maxinterval
> 0 &&
7031 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
7032 fan_watchdog_active
= 1;
7033 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
7034 msecs_to_jiffies(fan_watchdog_maxinterval
7037 "failed to queue the fan watchdog, "
7038 "watchdog will not trigger\n");
7041 fan_watchdog_active
= 0;
7044 static void fan_watchdog_fire(struct work_struct
*ignored
)
7048 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
7051 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
7052 rc
= fan_set_enable();
7054 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
7055 "will try again later...\n", -rc
);
7056 /* reschedule for later */
7057 fan_watchdog_reset();
7062 * SYSFS fan layout: hwmon compatible (device)
7065 * 0: "disengaged" mode
7067 * 2: native EC "auto" mode (recommended, hardware default)
7069 * pwm*: set speed in manual mode, ignored otherwise.
7070 * 0 is level 0; 255 is level 7. Intermediate points done with linear
7073 * fan*_input: tachometer reading, RPM
7076 * SYSFS fan layout: extensions
7078 * fan_watchdog (driver):
7079 * fan watchdog interval in seconds, 0 disables (default), max 120
7082 /* sysfs fan pwm1_enable ----------------------------------------------- */
7083 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
7084 struct device_attribute
*attr
,
7090 res
= fan_get_status_safe(&status
);
7094 if (status
& TP_EC_FAN_FULLSPEED
) {
7096 } else if (status
& TP_EC_FAN_AUTO
) {
7101 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
7104 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7105 struct device_attribute
*attr
,
7106 const char *buf
, size_t count
)
7111 if (parse_strtoul(buf
, 2, &t
))
7114 tpacpi_disclose_usertask("hwmon pwm1_enable",
7115 "set fan mode to %lu\n", t
);
7119 level
= TP_EC_FAN_FULLSPEED
;
7122 level
= TPACPI_FAN_LAST_LEVEL
;
7125 level
= TP_EC_FAN_AUTO
;
7128 /* reserved for software-controlled auto mode */
7134 res
= fan_set_level_safe(level
);
7140 fan_watchdog_reset();
7145 static struct device_attribute dev_attr_fan_pwm1_enable
=
7146 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7147 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7149 /* sysfs fan pwm1 ------------------------------------------------------ */
7150 static ssize_t
fan_pwm1_show(struct device
*dev
,
7151 struct device_attribute
*attr
,
7157 res
= fan_get_status_safe(&status
);
7162 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7163 status
= fan_control_desired_level
;
7168 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7171 static ssize_t
fan_pwm1_store(struct device
*dev
,
7172 struct device_attribute
*attr
,
7173 const char *buf
, size_t count
)
7177 u8 status
, newlevel
;
7179 if (parse_strtoul(buf
, 255, &s
))
7182 tpacpi_disclose_usertask("hwmon pwm1",
7183 "set fan speed to %lu\n", s
);
7185 /* scale down from 0-255 to 0-7 */
7186 newlevel
= (s
>> 5) & 0x07;
7188 if (mutex_lock_killable(&fan_mutex
))
7189 return -ERESTARTSYS
;
7191 rc
= fan_get_status(&status
);
7192 if (!rc
&& (status
&
7193 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7194 rc
= fan_set_level(newlevel
);
7198 fan_update_desired_level(newlevel
);
7199 fan_watchdog_reset();
7203 mutex_unlock(&fan_mutex
);
7204 return (rc
)? rc
: count
;
7207 static struct device_attribute dev_attr_fan_pwm1
=
7208 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7209 fan_pwm1_show
, fan_pwm1_store
);
7211 /* sysfs fan fan1_input ------------------------------------------------ */
7212 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7213 struct device_attribute
*attr
,
7219 res
= fan_get_speed(&speed
);
7223 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7226 static struct device_attribute dev_attr_fan_fan1_input
=
7227 __ATTR(fan1_input
, S_IRUGO
,
7228 fan_fan1_input_show
, NULL
);
7230 /* sysfs fan fan2_input ------------------------------------------------ */
7231 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7232 struct device_attribute
*attr
,
7238 res
= fan2_get_speed(&speed
);
7242 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7245 static struct device_attribute dev_attr_fan_fan2_input
=
7246 __ATTR(fan2_input
, S_IRUGO
,
7247 fan_fan2_input_show
, NULL
);
7249 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
7250 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
7253 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
7256 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
7257 const char *buf
, size_t count
)
7261 if (parse_strtoul(buf
, 120, &t
))
7264 if (!fan_control_allowed
)
7267 fan_watchdog_maxinterval
= t
;
7268 fan_watchdog_reset();
7270 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
7275 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
7276 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
7278 /* --------------------------------------------------------------------- */
7279 static struct attribute
*fan_attributes
[] = {
7280 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
7281 &dev_attr_fan_fan1_input
.attr
,
7282 NULL
, /* for fan2_input */
7286 static const struct attribute_group fan_attr_group
= {
7287 .attrs
= fan_attributes
,
7290 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
7291 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
7293 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7294 { .vendor = PCI_VENDOR_ID_IBM, \
7295 .bios = TPACPI_MATCH_ANY, \
7296 .ec = TPID(__id1, __id2), \
7297 .quirks = __quirks }
7299 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7300 { .vendor = PCI_VENDOR_ID_LENOVO, \
7301 .bios = TPACPI_MATCH_ANY, \
7302 .ec = TPID(__id1, __id2), \
7303 .quirks = __quirks }
7305 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
7306 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
7307 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
7308 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
7309 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
7310 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
7313 #undef TPACPI_FAN_QL
7314 #undef TPACPI_FAN_QI
7316 static int __init
fan_init(struct ibm_init_struct
*iibm
)
7319 unsigned long quirks
;
7321 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7322 "initializing fan subdriver\n");
7324 mutex_init(&fan_mutex
);
7325 fan_status_access_mode
= TPACPI_FAN_NONE
;
7326 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7327 fan_control_commands
= 0;
7328 fan_watchdog_maxinterval
= 0;
7329 tp_features
.fan_ctrl_status_undef
= 0;
7330 tp_features
.second_fan
= 0;
7331 fan_control_desired_level
= 7;
7333 TPACPI_ACPIHANDLE_INIT(fans
);
7334 TPACPI_ACPIHANDLE_INIT(gfan
);
7335 TPACPI_ACPIHANDLE_INIT(sfan
);
7337 quirks
= tpacpi_check_quirks(fan_quirk_table
,
7338 ARRAY_SIZE(fan_quirk_table
));
7341 /* 570, 600e/x, 770e, 770x */
7342 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7344 /* all other ThinkPads: note that even old-style
7345 * ThinkPad ECs supports the fan control register */
7346 if (likely(acpi_ec_read(fan_status_offset
,
7347 &fan_control_initial_status
))) {
7348 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7349 if (quirks
& TPACPI_FAN_Q1
)
7351 if (quirks
& TPACPI_FAN_2FAN
) {
7352 tp_features
.second_fan
= 1;
7353 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7354 "secondary fan support enabled\n");
7358 "ThinkPad ACPI EC access misbehaving, "
7359 "fan status and control unavailable\n");
7366 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
7367 fan_control_commands
|=
7368 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
7371 /* gfan without sfan means no fan control */
7372 /* all other models implement TP EC 0x2f control */
7376 fan_control_access_mode
=
7377 TPACPI_FAN_WR_ACPI_FANS
;
7378 fan_control_commands
|=
7379 TPACPI_FAN_CMD_SPEED
|
7380 TPACPI_FAN_CMD_LEVEL
|
7381 TPACPI_FAN_CMD_ENABLE
;
7383 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
7384 fan_control_commands
|=
7385 TPACPI_FAN_CMD_LEVEL
|
7386 TPACPI_FAN_CMD_ENABLE
;
7391 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7392 "fan is %s, modes %d, %d\n",
7393 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
7394 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
7395 fan_status_access_mode
, fan_control_access_mode
);
7397 /* fan control master switch */
7398 if (!fan_control_allowed
) {
7399 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7400 fan_control_commands
= 0;
7401 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7402 "fan control features disabled by parameter\n");
7405 /* update fan_control_desired_level */
7406 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
7407 fan_get_status_safe(NULL
);
7409 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
7410 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
7411 if (tp_features
.second_fan
) {
7412 /* attach second fan tachometer */
7413 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
7414 &dev_attr_fan_fan2_input
.attr
;
7416 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7421 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
7422 &driver_attr_fan_watchdog
);
7424 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7433 static void fan_exit(void)
7435 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
7436 "cancelling any pending fan watchdog tasks\n");
7438 /* FIXME: can we really do this unconditionally? */
7439 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
7440 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
7441 &driver_attr_fan_watchdog
);
7443 cancel_delayed_work(&fan_watchdog_task
);
7444 flush_workqueue(tpacpi_wq
);
7447 static void fan_suspend(pm_message_t state
)
7451 if (!fan_control_allowed
)
7454 /* Store fan status in cache */
7455 fan_control_resume_level
= 0;
7456 rc
= fan_get_status_safe(&fan_control_resume_level
);
7458 printk(TPACPI_NOTICE
7459 "failed to read fan level for later "
7460 "restore during resume: %d\n", rc
);
7462 /* if it is undefined, don't attempt to restore it.
7464 if (tp_features
.fan_ctrl_status_undef
)
7465 fan_control_resume_level
= 0;
7468 static void fan_resume(void)
7470 u8 current_level
= 7;
7471 bool do_set
= false;
7474 /* DSDT *always* updates status on resume */
7475 tp_features
.fan_ctrl_status_undef
= 0;
7477 if (!fan_control_allowed
||
7478 !fan_control_resume_level
||
7479 (fan_get_status_safe(¤t_level
) < 0))
7482 switch (fan_control_access_mode
) {
7483 case TPACPI_FAN_WR_ACPI_SFAN
:
7484 /* never decrease fan level */
7485 do_set
= (fan_control_resume_level
> current_level
);
7487 case TPACPI_FAN_WR_ACPI_FANS
:
7488 case TPACPI_FAN_WR_TPEC
:
7489 /* never decrease fan level, scale is:
7490 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
7492 * We expect the firmware to set either 7 or AUTO, but we
7493 * handle FULLSPEED out of paranoia.
7495 * So, we can safely only restore FULLSPEED or 7, anything
7496 * else could slow the fan. Restoring AUTO is useless, at
7497 * best that's exactly what the DSDT already set (it is the
7500 * Always keep in mind that the DSDT *will* have set the
7501 * fans to what the vendor supposes is the best level. We
7502 * muck with it only to speed the fan up.
7504 if (fan_control_resume_level
!= 7 &&
7505 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
7508 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
7509 (current_level
!= fan_control_resume_level
);
7515 printk(TPACPI_NOTICE
7516 "restoring fan level to 0x%02x\n",
7517 fan_control_resume_level
);
7518 rc
= fan_set_level_safe(fan_control_resume_level
);
7520 printk(TPACPI_NOTICE
7521 "failed to restore fan level: %d\n", rc
);
7525 static int fan_read(char *p
)
7530 unsigned int speed
= 0;
7532 switch (fan_status_access_mode
) {
7533 case TPACPI_FAN_RD_ACPI_GFAN
:
7534 /* 570, 600e/x, 770e, 770x */
7535 rc
= fan_get_status_safe(&status
);
7539 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
7541 (status
!= 0) ? "enabled" : "disabled", status
);
7544 case TPACPI_FAN_RD_TPEC
:
7545 /* all except 570, 600e/x, 770e, 770x */
7546 rc
= fan_get_status_safe(&status
);
7550 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
7551 (status
!= 0) ? "enabled" : "disabled");
7553 rc
= fan_get_speed(&speed
);
7557 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
7559 if (status
& TP_EC_FAN_FULLSPEED
)
7560 /* Disengaged mode takes precedence */
7561 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
7562 else if (status
& TP_EC_FAN_AUTO
)
7563 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
7565 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
7568 case TPACPI_FAN_NONE
:
7570 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
7573 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
7574 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
7576 switch (fan_control_access_mode
) {
7577 case TPACPI_FAN_WR_ACPI_SFAN
:
7578 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
7582 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
7583 "auto, disengaged, full-speed)\n");
7588 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
7589 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
7590 "commands:\twatchdog <timeout> (<timeout> "
7591 "is 0 (off), 1-120 (seconds))\n");
7593 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
7594 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
7595 " (<speed> is 0-65535)\n");
7600 static int fan_write_cmd_level(const char *cmd
, int *rc
)
7604 if (strlencmp(cmd
, "level auto") == 0)
7605 level
= TP_EC_FAN_AUTO
;
7606 else if ((strlencmp(cmd
, "level disengaged") == 0) |
7607 (strlencmp(cmd
, "level full-speed") == 0))
7608 level
= TP_EC_FAN_FULLSPEED
;
7609 else if (sscanf(cmd
, "level %d", &level
) != 1)
7612 *rc
= fan_set_level_safe(level
);
7614 printk(TPACPI_ERR
"level command accepted for unsupported "
7615 "access mode %d", fan_control_access_mode
);
7617 tpacpi_disclose_usertask("procfs fan",
7618 "set level to %d\n", level
);
7623 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
7625 if (strlencmp(cmd
, "enable") != 0)
7628 *rc
= fan_set_enable();
7630 printk(TPACPI_ERR
"enable command accepted for unsupported "
7631 "access mode %d", fan_control_access_mode
);
7633 tpacpi_disclose_usertask("procfs fan", "enable\n");
7638 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
7640 if (strlencmp(cmd
, "disable") != 0)
7643 *rc
= fan_set_disable();
7645 printk(TPACPI_ERR
"disable command accepted for unsupported "
7646 "access mode %d", fan_control_access_mode
);
7648 tpacpi_disclose_usertask("procfs fan", "disable\n");
7653 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
7658 * Support speed <low> <medium> <high> ? */
7660 if (sscanf(cmd
, "speed %d", &speed
) != 1)
7663 *rc
= fan_set_speed(speed
);
7665 printk(TPACPI_ERR
"speed command accepted for unsupported "
7666 "access mode %d", fan_control_access_mode
);
7668 tpacpi_disclose_usertask("procfs fan",
7669 "set speed to %d\n", speed
);
7674 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
7678 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
7681 if (interval
< 0 || interval
> 120)
7684 fan_watchdog_maxinterval
= interval
;
7685 tpacpi_disclose_usertask("procfs fan",
7686 "set watchdog timer to %d\n",
7693 static int fan_write(char *buf
)
7698 while (!rc
&& (cmd
= next_cmd(&buf
))) {
7699 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
7700 fan_write_cmd_level(cmd
, &rc
)) &&
7701 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
7702 (fan_write_cmd_enable(cmd
, &rc
) ||
7703 fan_write_cmd_disable(cmd
, &rc
) ||
7704 fan_write_cmd_watchdog(cmd
, &rc
))) &&
7705 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
7706 fan_write_cmd_speed(cmd
, &rc
))
7710 fan_watchdog_reset();
7716 static struct ibm_struct fan_driver_data
= {
7721 .suspend
= fan_suspend
,
7722 .resume
= fan_resume
,
7725 /****************************************************************************
7726 ****************************************************************************
7730 ****************************************************************************
7731 ****************************************************************************/
7734 * HKEY event callout for other subdrivers go here
7735 * (yes, it is ugly, but it is quick, safe, and gets the job done
7737 static void tpacpi_driver_event(const unsigned int hkey_event
)
7739 if (ibm_backlight_device
) {
7740 switch (hkey_event
) {
7741 case TP_HKEY_EV_BRGHT_UP
:
7742 case TP_HKEY_EV_BRGHT_DOWN
:
7743 tpacpi_brightness_notify_change();
7750 static void hotkey_driver_event(const unsigned int scancode
)
7752 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
7755 /* sysfs name ---------------------------------------------------------- */
7756 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
7757 struct device_attribute
*attr
,
7760 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
7763 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
7764 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
7766 /* --------------------------------------------------------------------- */
7769 static struct proc_dir_entry
*proc_dir
;
7772 * Module and infrastructure proble, init and exit handling
7775 static int force_load
;
7777 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
7778 static const char * __init
str_supported(int is_supported
)
7780 static char text_unsupported
[] __initdata
= "not supported";
7782 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
7784 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
7786 static void ibm_exit(struct ibm_struct
*ibm
)
7788 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
7790 list_del_init(&ibm
->all_drivers
);
7792 if (ibm
->flags
.acpi_notify_installed
) {
7793 dbg_printk(TPACPI_DBG_EXIT
,
7794 "%s: acpi_remove_notify_handler\n", ibm
->name
);
7796 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
7798 dispatch_acpi_notify
);
7799 ibm
->flags
.acpi_notify_installed
= 0;
7800 ibm
->flags
.acpi_notify_installed
= 0;
7803 if (ibm
->flags
.proc_created
) {
7804 dbg_printk(TPACPI_DBG_EXIT
,
7805 "%s: remove_proc_entry\n", ibm
->name
);
7806 remove_proc_entry(ibm
->name
, proc_dir
);
7807 ibm
->flags
.proc_created
= 0;
7810 if (ibm
->flags
.acpi_driver_registered
) {
7811 dbg_printk(TPACPI_DBG_EXIT
,
7812 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
7814 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
7815 kfree(ibm
->acpi
->driver
);
7816 ibm
->acpi
->driver
= NULL
;
7817 ibm
->flags
.acpi_driver_registered
= 0;
7820 if (ibm
->flags
.init_called
&& ibm
->exit
) {
7822 ibm
->flags
.init_called
= 0;
7825 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
7828 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
7831 struct ibm_struct
*ibm
= iibm
->data
;
7832 struct proc_dir_entry
*entry
;
7834 BUG_ON(ibm
== NULL
);
7836 INIT_LIST_HEAD(&ibm
->all_drivers
);
7838 if (ibm
->flags
.experimental
&& !experimental
)
7841 dbg_printk(TPACPI_DBG_INIT
,
7842 "probing for %s\n", ibm
->name
);
7845 ret
= iibm
->init(iibm
);
7847 return 0; /* probe failed */
7851 ibm
->flags
.init_called
= 1;
7855 if (ibm
->acpi
->hid
) {
7856 ret
= register_tpacpi_subdriver(ibm
);
7861 if (ibm
->acpi
->notify
) {
7862 ret
= setup_acpi_notify(ibm
);
7863 if (ret
== -ENODEV
) {
7864 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
7874 dbg_printk(TPACPI_DBG_INIT
,
7875 "%s installed\n", ibm
->name
);
7878 entry
= create_proc_entry(ibm
->name
,
7879 S_IFREG
| S_IRUGO
| S_IWUSR
,
7882 printk(TPACPI_ERR
"unable to create proc entry %s\n",
7888 entry
->read_proc
= &dispatch_procfs_read
;
7890 entry
->write_proc
= &dispatch_procfs_write
;
7891 ibm
->flags
.proc_created
= 1;
7894 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
7899 dbg_printk(TPACPI_DBG_INIT
,
7900 "%s: at error exit path with result %d\n",
7904 return (ret
< 0)? ret
: 0;
7909 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
7911 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
7914 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
7915 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
7918 return s
&& strlen(s
) >= 8 &&
7919 tpacpi_is_fw_digit(s
[0]) &&
7920 tpacpi_is_fw_digit(s
[1]) &&
7921 s
[2] == t
&& s
[3] == 'T' &&
7922 tpacpi_is_fw_digit(s
[4]) &&
7923 tpacpi_is_fw_digit(s
[5]) &&
7924 s
[6] == 'W' && s
[7] == 'W';
7927 /* returns 0 - probe ok, or < 0 - probe error.
7928 * Probe ok doesn't mean thinkpad found.
7929 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
7930 static int __must_check __init
get_thinkpad_model_data(
7931 struct thinkpad_id_data
*tp
)
7933 const struct dmi_device
*dev
= NULL
;
7934 char ec_fw_string
[18];
7940 memset(tp
, 0, sizeof(*tp
));
7942 if (dmi_name_in_vendors("IBM"))
7943 tp
->vendor
= PCI_VENDOR_ID_IBM
;
7944 else if (dmi_name_in_vendors("LENOVO"))
7945 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
7949 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
7950 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
7951 if (s
&& !tp
->bios_version_str
)
7954 /* Really ancient ThinkPad 240X will fail this, which is fine */
7955 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
7958 tp
->bios_model
= tp
->bios_version_str
[0]
7959 | (tp
->bios_version_str
[1] << 8);
7960 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
7961 | tp
->bios_version_str
[5];
7964 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
7965 * X32 or newer, all Z series; Some models must have an
7966 * up-to-date BIOS or they will not be detected.
7968 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7970 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
7971 if (sscanf(dev
->name
,
7972 "IBM ThinkPad Embedded Controller -[%17c",
7973 ec_fw_string
) == 1) {
7974 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
7975 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
7977 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
7978 if (!tp
->ec_version_str
)
7981 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
7982 tp
->ec_model
= ec_fw_string
[0]
7983 | (ec_fw_string
[1] << 8);
7984 tp
->ec_release
= (ec_fw_string
[4] << 8)
7987 printk(TPACPI_NOTICE
7988 "ThinkPad firmware release %s "
7989 "doesn't match the known patterns\n",
7991 printk(TPACPI_NOTICE
7992 "please report this to %s\n",
7999 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
8000 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
8001 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
8006 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
8007 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
8008 if (s
&& !tp
->nummodel_str
)
8014 static int __init
probe_for_thinkpad(void)
8022 * Non-ancient models have better DMI tagging, but very old models
8023 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
8025 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
8026 (thinkpad_id
.ec_model
!= 0) ||
8027 tpacpi_is_fw_known();
8029 /* ec is required because many other handles are relative to it */
8030 TPACPI_ACPIHANDLE_INIT(ec
);
8034 "Not yet supported ThinkPad detected!\n");
8038 if (!is_thinkpad
&& !force_load
)
8045 /* Module init, exit, parameters */
8047 static struct ibm_init_struct ibms_init
[] __initdata
= {
8049 .init
= thinkpad_acpi_driver_init
,
8050 .data
= &thinkpad_acpi_driver_data
,
8053 .init
= hotkey_init
,
8054 .data
= &hotkey_driver_data
,
8057 .init
= bluetooth_init
,
8058 .data
= &bluetooth_driver_data
,
8062 .data
= &wan_driver_data
,
8066 .data
= &uwb_driver_data
,
8068 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8071 .data
= &video_driver_data
,
8076 .data
= &light_driver_data
,
8080 .data
= &cmos_driver_data
,
8084 .data
= &led_driver_data
,
8088 .data
= &beep_driver_data
,
8091 .init
= thermal_init
,
8092 .data
= &thermal_driver_data
,
8095 .data
= &ecdump_driver_data
,
8098 .init
= brightness_init
,
8099 .data
= &brightness_driver_data
,
8102 .data
= &volume_driver_data
,
8106 .data
= &fan_driver_data
,
8110 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
8113 struct ibm_struct
*ibm
;
8115 if (!kp
|| !kp
->name
|| !val
)
8118 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8119 ibm
= ibms_init
[i
].data
;
8120 WARN_ON(ibm
== NULL
);
8122 if (!ibm
|| !ibm
->name
)
8125 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8126 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8128 strcpy(ibms_init
[i
].param
, val
);
8129 strcat(ibms_init
[i
].param
, ",");
8137 module_param(experimental
, int, 0);
8138 MODULE_PARM_DESC(experimental
,
8139 "Enables experimental features when non-zero");
8141 module_param_named(debug
, dbg_level
, uint
, 0);
8142 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8144 module_param(force_load
, bool, 0);
8145 MODULE_PARM_DESC(force_load
,
8146 "Attempts to load the driver even on a "
8147 "mis-identified ThinkPad when true");
8149 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
8150 MODULE_PARM_DESC(fan_control
,
8151 "Enables setting fan parameters features when true");
8153 module_param_named(brightness_mode
, brightness_mode
, uint
, 0);
8154 MODULE_PARM_DESC(brightness_mode
,
8155 "Selects brightness control strategy: "
8156 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8158 module_param(brightness_enable
, uint
, 0);
8159 MODULE_PARM_DESC(brightness_enable
,
8160 "Enables backlight control when 1, disables when 0");
8162 module_param(hotkey_report_mode
, uint
, 0);
8163 MODULE_PARM_DESC(hotkey_report_mode
,
8164 "used for backwards compatibility with userspace, "
8165 "see documentation");
8167 #define TPACPI_PARAM(feature) \
8168 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8169 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8170 "at module load, see documentation")
8172 TPACPI_PARAM(hotkey
);
8173 TPACPI_PARAM(bluetooth
);
8174 TPACPI_PARAM(video
);
8175 TPACPI_PARAM(light
);
8179 TPACPI_PARAM(ecdump
);
8180 TPACPI_PARAM(brightness
);
8181 TPACPI_PARAM(volume
);
8184 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8185 module_param(dbg_wlswemul
, uint
, 0);
8186 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
8187 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
8188 MODULE_PARM_DESC(wlsw_state
,
8189 "Initial state of the emulated WLSW switch");
8191 module_param(dbg_bluetoothemul
, uint
, 0);
8192 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
8193 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
8194 MODULE_PARM_DESC(bluetooth_state
,
8195 "Initial state of the emulated bluetooth switch");
8197 module_param(dbg_wwanemul
, uint
, 0);
8198 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
8199 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
8200 MODULE_PARM_DESC(wwan_state
,
8201 "Initial state of the emulated WWAN switch");
8203 module_param(dbg_uwbemul
, uint
, 0);
8204 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
8205 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
8206 MODULE_PARM_DESC(uwb_state
,
8207 "Initial state of the emulated UWB switch");
8210 static void thinkpad_acpi_module_exit(void)
8212 struct ibm_struct
*ibm
, *itmp
;
8214 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
8216 list_for_each_entry_safe_reverse(ibm
, itmp
,
8217 &tpacpi_all_drivers
,
8222 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
8224 if (tpacpi_inputdev
) {
8225 if (tp_features
.input_device_registered
)
8226 input_unregister_device(tpacpi_inputdev
);
8228 input_free_device(tpacpi_inputdev
);
8232 hwmon_device_unregister(tpacpi_hwmon
);
8234 if (tp_features
.sensors_pdev_attrs_registered
)
8235 device_remove_file(&tpacpi_sensors_pdev
->dev
,
8236 &dev_attr_thinkpad_acpi_pdev_name
);
8237 if (tpacpi_sensors_pdev
)
8238 platform_device_unregister(tpacpi_sensors_pdev
);
8240 platform_device_unregister(tpacpi_pdev
);
8242 if (tp_features
.sensors_pdrv_attrs_registered
)
8243 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
8244 if (tp_features
.platform_drv_attrs_registered
)
8245 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
8247 if (tp_features
.sensors_pdrv_registered
)
8248 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
8250 if (tp_features
.platform_drv_registered
)
8251 platform_driver_unregister(&tpacpi_pdriver
);
8254 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
8257 destroy_workqueue(tpacpi_wq
);
8259 kfree(thinkpad_id
.bios_version_str
);
8260 kfree(thinkpad_id
.ec_version_str
);
8261 kfree(thinkpad_id
.model_str
);
8265 static int __init
thinkpad_acpi_module_init(void)
8269 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
8271 /* Parameter checking */
8272 if (hotkey_report_mode
> 2)
8275 /* Driver-level probe */
8277 ret
= get_thinkpad_model_data(&thinkpad_id
);
8280 "unable to get DMI data: %d\n", ret
);
8281 thinkpad_acpi_module_exit();
8284 ret
= probe_for_thinkpad();
8286 thinkpad_acpi_module_exit();
8290 /* Driver initialization */
8292 TPACPI_ACPIHANDLE_INIT(ecrd
);
8293 TPACPI_ACPIHANDLE_INIT(ecwr
);
8295 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
8297 thinkpad_acpi_module_exit();
8301 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
8304 "unable to create proc dir " TPACPI_PROC_DIR
);
8305 thinkpad_acpi_module_exit();
8309 ret
= platform_driver_register(&tpacpi_pdriver
);
8312 "unable to register main platform driver\n");
8313 thinkpad_acpi_module_exit();
8316 tp_features
.platform_drv_registered
= 1;
8318 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
8321 "unable to register hwmon platform driver\n");
8322 thinkpad_acpi_module_exit();
8325 tp_features
.sensors_pdrv_registered
= 1;
8327 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
8329 tp_features
.platform_drv_attrs_registered
= 1;
8330 ret
= tpacpi_create_driver_attributes(
8331 &tpacpi_hwmon_pdriver
.driver
);
8335 "unable to create sysfs driver attributes\n");
8336 thinkpad_acpi_module_exit();
8339 tp_features
.sensors_pdrv_attrs_registered
= 1;
8342 /* Device initialization */
8343 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
8345 if (IS_ERR(tpacpi_pdev
)) {
8346 ret
= PTR_ERR(tpacpi_pdev
);
8348 printk(TPACPI_ERR
"unable to register platform device\n");
8349 thinkpad_acpi_module_exit();
8352 tpacpi_sensors_pdev
= platform_device_register_simple(
8353 TPACPI_HWMON_DRVR_NAME
,
8355 if (IS_ERR(tpacpi_sensors_pdev
)) {
8356 ret
= PTR_ERR(tpacpi_sensors_pdev
);
8357 tpacpi_sensors_pdev
= NULL
;
8359 "unable to register hwmon platform device\n");
8360 thinkpad_acpi_module_exit();
8363 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
8364 &dev_attr_thinkpad_acpi_pdev_name
);
8367 "unable to create sysfs hwmon device attributes\n");
8368 thinkpad_acpi_module_exit();
8371 tp_features
.sensors_pdev_attrs_registered
= 1;
8372 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
8373 if (IS_ERR(tpacpi_hwmon
)) {
8374 ret
= PTR_ERR(tpacpi_hwmon
);
8375 tpacpi_hwmon
= NULL
;
8376 printk(TPACPI_ERR
"unable to register hwmon device\n");
8377 thinkpad_acpi_module_exit();
8380 mutex_init(&tpacpi_inputdev_send_mutex
);
8381 tpacpi_inputdev
= input_allocate_device();
8382 if (!tpacpi_inputdev
) {
8383 printk(TPACPI_ERR
"unable to allocate input device\n");
8384 thinkpad_acpi_module_exit();
8387 /* Prepare input device, but don't register */
8388 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
8389 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
8390 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
8391 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
8392 thinkpad_id
.vendor
:
8394 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
8395 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
8397 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8398 ret
= ibm_init(&ibms_init
[i
]);
8399 if (ret
>= 0 && *ibms_init
[i
].param
)
8400 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
8402 thinkpad_acpi_module_exit();
8406 ret
= input_register_device(tpacpi_inputdev
);
8408 printk(TPACPI_ERR
"unable to register input device\n");
8409 thinkpad_acpi_module_exit();
8412 tp_features
.input_device_registered
= 1;
8415 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
8419 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
8422 * This will autoload the driver in almost every ThinkPad
8423 * in widespread use.
8425 * Only _VERY_ old models, like the 240, 240x and 570 lack
8426 * the HKEY event interface.
8428 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
8431 * DMI matching for module autoloading
8433 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8434 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
8436 * Only models listed in thinkwiki will be supported, so add yours
8437 * if it is not there yet.
8439 #define IBM_BIOS_MODULE_ALIAS(__type) \
8440 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
8442 /* Ancient thinkpad BIOSes have to be identified by
8443 * BIOS type or model number, and there are far less
8444 * BIOS types than model numbers... */
8445 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
8447 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
8448 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
8449 MODULE_DESCRIPTION(TPACPI_DESC
);
8450 MODULE_VERSION(TPACPI_VERSION
);
8451 MODULE_LICENSE("GPL");
8453 module_init(thinkpad_acpi_module_init
);
8454 module_exit(thinkpad_acpi_module_exit
);