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 while (*buf
&& isspace(*buf
))
1011 *value
= simple_strtoul(buf
, &endp
, 0);
1012 while (*endp
&& isspace(*endp
))
1014 if (*endp
|| *value
> max
)
1020 static void tpacpi_disable_brightness_delay(void)
1022 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
1023 printk(TPACPI_NOTICE
1024 "ACPI backlight control delay disabled\n");
1027 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
1029 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1030 union acpi_object
*obj
;
1033 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
1034 obj
= (union acpi_object
*)buffer
.pointer
;
1035 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
1036 printk(TPACPI_ERR
"Unknown _BCL data, "
1037 "please report this to %s\n", TPACPI_MAIL
);
1040 rc
= obj
->package
.count
;
1046 kfree(buffer
.pointer
);
1050 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
1051 u32 lvl
, void *context
, void **rv
)
1053 char name
[ACPI_PATH_SEGMENT_LENGTH
];
1054 struct acpi_buffer buffer
= { sizeof(name
), &name
};
1056 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
1057 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
1058 BUG_ON(!rv
|| !*rv
);
1059 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
1060 return AE_CTRL_TERMINATE
;
1067 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
1069 static int __init
tpacpi_check_std_acpi_brightness_support(void)
1073 void *bcl_ptr
= &bcl_levels
;
1076 TPACPI_ACPIHANDLE_INIT(vid
);
1082 * Search for a _BCL method, and execute it. This is safe on all
1083 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
1084 * BIOS in ACPI backlight control mode. We do NOT have to care
1085 * about calling the _BCL method in an enabled video device, any
1086 * will do for our purposes.
1089 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
1090 tpacpi_acpi_walk_find_bcl
, NULL
,
1093 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
1094 tp_features
.bright_acpimode
= 1;
1095 return (bcl_levels
- 2);
1101 static void printk_deprecated_attribute(const char * const what
,
1102 const char * const details
)
1104 tpacpi_log_usertask("deprecated sysfs attribute");
1105 printk(TPACPI_WARN
"WARNING: sysfs attribute %s is deprecated and "
1106 "will be removed. %s\n",
1110 /*************************************************************************
1111 * rfkill and radio control support helpers
1115 * ThinkPad-ACPI firmware handling model:
1117 * WLSW (master wireless switch) is event-driven, and is common to all
1118 * firmware-controlled radios. It cannot be controlled, just monitored,
1119 * as expected. It overrides all radio state in firmware
1121 * The kernel, a masked-off hotkey, and WLSW can change the radio state
1122 * (TODO: verify how WLSW interacts with the returned radio state).
1124 * The only time there are shadow radio state changes, is when
1125 * masked-off hotkeys are used.
1129 * Internal driver API for radio state:
1131 * int: < 0 = error, otherwise enum tpacpi_rfkill_state
1132 * bool: true means radio blocked (off)
1134 enum tpacpi_rfkill_state
{
1135 TPACPI_RFK_RADIO_OFF
= 0,
1139 /* rfkill switches */
1140 enum tpacpi_rfk_id
{
1141 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
1142 TPACPI_RFK_WWAN_SW_ID
,
1143 TPACPI_RFK_UWB_SW_ID
,
1147 static const char *tpacpi_rfkill_names
[] = {
1148 [TPACPI_RFK_BLUETOOTH_SW_ID
] = "bluetooth",
1149 [TPACPI_RFK_WWAN_SW_ID
] = "wwan",
1150 [TPACPI_RFK_UWB_SW_ID
] = "uwb",
1151 [TPACPI_RFK_SW_MAX
] = NULL
1154 /* ThinkPad-ACPI rfkill subdriver */
1156 struct rfkill
*rfkill
;
1157 enum tpacpi_rfk_id id
;
1158 const struct tpacpi_rfk_ops
*ops
;
1161 struct tpacpi_rfk_ops
{
1162 /* firmware interface */
1163 int (*get_status
)(void);
1164 int (*set_status
)(const enum tpacpi_rfkill_state
);
1167 static struct tpacpi_rfk
*tpacpi_rfkill_switches
[TPACPI_RFK_SW_MAX
];
1169 /* Query FW and update rfkill sw state for a given rfkill switch */
1170 static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk
*tp_rfk
)
1177 status
= (tp_rfk
->ops
->get_status
)();
1181 rfkill_set_sw_state(tp_rfk
->rfkill
,
1182 (status
== TPACPI_RFK_RADIO_OFF
));
1187 /* Query FW and update rfkill sw state for all rfkill switches */
1188 static void tpacpi_rfk_update_swstate_all(void)
1192 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++)
1193 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[i
]);
1197 * Sync the HW-blocking state of all rfkill switches,
1198 * do notice it causes the rfkill core to schedule uevents
1200 static void tpacpi_rfk_update_hwblock_state(bool blocked
)
1203 struct tpacpi_rfk
*tp_rfk
;
1205 for (i
= 0; i
< TPACPI_RFK_SW_MAX
; i
++) {
1206 tp_rfk
= tpacpi_rfkill_switches
[i
];
1208 if (rfkill_set_hw_state(tp_rfk
->rfkill
,
1210 /* ignore -- we track sw block */
1216 /* Call to get the WLSW state from the firmware */
1217 static int hotkey_get_wlsw(void);
1219 /* Call to query WLSW state and update all rfkill switches */
1220 static bool tpacpi_rfk_check_hwblock_state(void)
1222 int res
= hotkey_get_wlsw();
1225 /* When unknown or unsupported, we have to assume it is unblocked */
1229 hw_blocked
= (res
== TPACPI_RFK_RADIO_OFF
);
1230 tpacpi_rfk_update_hwblock_state(hw_blocked
);
1235 static int tpacpi_rfk_hook_set_block(void *data
, bool blocked
)
1237 struct tpacpi_rfk
*tp_rfk
= data
;
1240 dbg_printk(TPACPI_DBG_RFKILL
,
1241 "request to change radio state to %s\n",
1242 blocked
? "blocked" : "unblocked");
1244 /* try to set radio state */
1245 res
= (tp_rfk
->ops
->set_status
)(blocked
?
1246 TPACPI_RFK_RADIO_OFF
: TPACPI_RFK_RADIO_ON
);
1248 /* and update the rfkill core with whatever the FW really did */
1249 tpacpi_rfk_update_swstate(tp_rfk
);
1251 return (res
< 0) ? res
: 0;
1254 static const struct rfkill_ops tpacpi_rfk_rfkill_ops
= {
1255 .set_block
= tpacpi_rfk_hook_set_block
,
1258 static int __init
tpacpi_new_rfkill(const enum tpacpi_rfk_id id
,
1259 const struct tpacpi_rfk_ops
*tp_rfkops
,
1260 const enum rfkill_type rfktype
,
1262 const bool set_default
)
1264 struct tpacpi_rfk
*atp_rfk
;
1266 bool sw_state
= false;
1270 BUG_ON(id
>= TPACPI_RFK_SW_MAX
|| tpacpi_rfkill_switches
[id
]);
1272 atp_rfk
= kzalloc(sizeof(struct tpacpi_rfk
), GFP_KERNEL
);
1274 atp_rfk
->rfkill
= rfkill_alloc(name
,
1277 &tpacpi_rfk_rfkill_ops
,
1279 if (!atp_rfk
|| !atp_rfk
->rfkill
) {
1281 "failed to allocate memory for rfkill class\n");
1287 atp_rfk
->ops
= tp_rfkops
;
1289 sw_status
= (tp_rfkops
->get_status
)();
1290 if (sw_status
< 0) {
1292 "failed to read initial state for %s, error %d\n",
1295 sw_state
= (sw_status
== TPACPI_RFK_RADIO_OFF
);
1297 /* try to keep the initial state, since we ask the
1298 * firmware to preserve it across S5 in NVRAM */
1299 rfkill_init_sw_state(atp_rfk
->rfkill
, sw_state
);
1302 hw_state
= tpacpi_rfk_check_hwblock_state();
1303 rfkill_set_hw_state(atp_rfk
->rfkill
, hw_state
);
1305 res
= rfkill_register(atp_rfk
->rfkill
);
1308 "failed to register %s rfkill switch: %d\n",
1310 rfkill_destroy(atp_rfk
->rfkill
);
1315 tpacpi_rfkill_switches
[id
] = atp_rfk
;
1317 printk(TPACPI_INFO
"rfkill switch %s: radio is %sblocked\n",
1318 name
, (sw_state
|| hw_state
) ? "" : "un");
1322 static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id
)
1324 struct tpacpi_rfk
*tp_rfk
;
1326 BUG_ON(id
>= TPACPI_RFK_SW_MAX
);
1328 tp_rfk
= tpacpi_rfkill_switches
[id
];
1330 rfkill_unregister(tp_rfk
->rfkill
);
1331 rfkill_destroy(tp_rfk
->rfkill
);
1332 tpacpi_rfkill_switches
[id
] = NULL
;
1337 static void printk_deprecated_rfkill_attribute(const char * const what
)
1339 printk_deprecated_attribute(what
,
1340 "Please switch to generic rfkill before year 2010");
1343 /* sysfs <radio> enable ------------------------------------------------ */
1344 static ssize_t
tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id
,
1345 struct device_attribute
*attr
,
1350 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1352 /* This is in the ABI... */
1353 if (tpacpi_rfk_check_hwblock_state()) {
1354 status
= TPACPI_RFK_RADIO_OFF
;
1356 status
= tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1361 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1362 (status
== TPACPI_RFK_RADIO_ON
) ? 1 : 0);
1365 static ssize_t
tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id
,
1366 struct device_attribute
*attr
,
1367 const char *buf
, size_t count
)
1372 printk_deprecated_rfkill_attribute(attr
->attr
.name
);
1374 if (parse_strtoul(buf
, 1, &t
))
1377 tpacpi_disclose_usertask(attr
->attr
.name
, "set to %ld\n", t
);
1379 /* This is in the ABI... */
1380 if (tpacpi_rfk_check_hwblock_state() && !!t
)
1383 res
= tpacpi_rfkill_switches
[id
]->ops
->set_status((!!t
) ?
1384 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
);
1385 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1387 return (res
< 0) ? res
: count
;
1390 /* procfs -------------------------------------------------------------- */
1391 static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id
, char *p
)
1395 if (id
>= TPACPI_RFK_SW_MAX
)
1396 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1400 /* This is in the ABI... */
1401 if (tpacpi_rfk_check_hwblock_state()) {
1402 status
= TPACPI_RFK_RADIO_OFF
;
1404 status
= tpacpi_rfk_update_swstate(
1405 tpacpi_rfkill_switches
[id
]);
1410 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1411 (status
== TPACPI_RFK_RADIO_ON
) ?
1412 "enabled" : "disabled");
1413 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1419 static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id
, char *buf
)
1425 if (id
>= TPACPI_RFK_SW_MAX
)
1428 while ((cmd
= next_cmd(&buf
))) {
1429 if (strlencmp(cmd
, "enable") == 0)
1430 status
= TPACPI_RFK_RADIO_ON
;
1431 else if (strlencmp(cmd
, "disable") == 0)
1432 status
= TPACPI_RFK_RADIO_OFF
;
1438 tpacpi_disclose_usertask("procfs", "attempt to %s %s\n",
1439 (status
== TPACPI_RFK_RADIO_ON
) ?
1440 "enable" : "disable",
1441 tpacpi_rfkill_names
[id
]);
1442 res
= (tpacpi_rfkill_switches
[id
]->ops
->set_status
)(status
);
1443 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches
[id
]);
1449 /*************************************************************************
1450 * thinkpad-acpi driver attributes
1453 /* interface_version --------------------------------------------------- */
1454 static ssize_t
tpacpi_driver_interface_version_show(
1455 struct device_driver
*drv
,
1458 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
1461 static DRIVER_ATTR(interface_version
, S_IRUGO
,
1462 tpacpi_driver_interface_version_show
, NULL
);
1464 /* debug_level --------------------------------------------------------- */
1465 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
1468 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
1471 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
1472 const char *buf
, size_t count
)
1476 if (parse_strtoul(buf
, 0xffff, &t
))
1484 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1485 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1487 /* version ------------------------------------------------------------- */
1488 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1491 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1492 TPACPI_DESC
, TPACPI_VERSION
);
1495 static DRIVER_ATTR(version
, S_IRUGO
,
1496 tpacpi_driver_version_show
, NULL
);
1498 /* --------------------------------------------------------------------- */
1500 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1502 /* wlsw_emulstate ------------------------------------------------------ */
1503 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1506 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1509 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1510 const char *buf
, size_t count
)
1514 if (parse_strtoul(buf
, 1, &t
))
1517 if (tpacpi_wlsw_emulstate
!= !!t
) {
1518 tpacpi_wlsw_emulstate
= !!t
;
1519 tpacpi_rfk_update_hwblock_state(!t
); /* negative logic */
1525 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1526 tpacpi_driver_wlsw_emulstate_show
,
1527 tpacpi_driver_wlsw_emulstate_store
);
1529 /* bluetooth_emulstate ------------------------------------------------- */
1530 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1531 struct device_driver
*drv
,
1534 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1537 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1538 struct device_driver
*drv
,
1539 const char *buf
, size_t count
)
1543 if (parse_strtoul(buf
, 1, &t
))
1546 tpacpi_bluetooth_emulstate
= !!t
;
1551 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1552 tpacpi_driver_bluetooth_emulstate_show
,
1553 tpacpi_driver_bluetooth_emulstate_store
);
1555 /* wwan_emulstate ------------------------------------------------- */
1556 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1557 struct device_driver
*drv
,
1560 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1563 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1564 struct device_driver
*drv
,
1565 const char *buf
, size_t count
)
1569 if (parse_strtoul(buf
, 1, &t
))
1572 tpacpi_wwan_emulstate
= !!t
;
1577 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1578 tpacpi_driver_wwan_emulstate_show
,
1579 tpacpi_driver_wwan_emulstate_store
);
1581 /* uwb_emulstate ------------------------------------------------- */
1582 static ssize_t
tpacpi_driver_uwb_emulstate_show(
1583 struct device_driver
*drv
,
1586 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_uwb_emulstate
);
1589 static ssize_t
tpacpi_driver_uwb_emulstate_store(
1590 struct device_driver
*drv
,
1591 const char *buf
, size_t count
)
1595 if (parse_strtoul(buf
, 1, &t
))
1598 tpacpi_uwb_emulstate
= !!t
;
1603 static DRIVER_ATTR(uwb_emulstate
, S_IWUSR
| S_IRUGO
,
1604 tpacpi_driver_uwb_emulstate_show
,
1605 tpacpi_driver_uwb_emulstate_store
);
1608 /* --------------------------------------------------------------------- */
1610 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1611 &driver_attr_debug_level
, &driver_attr_version
,
1612 &driver_attr_interface_version
,
1615 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1621 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1622 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1626 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1627 if (!res
&& dbg_wlswemul
)
1628 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1629 if (!res
&& dbg_bluetoothemul
)
1630 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1631 if (!res
&& dbg_wwanemul
)
1632 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1633 if (!res
&& dbg_uwbemul
)
1634 res
= driver_create_file(drv
, &driver_attr_uwb_emulstate
);
1640 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1644 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1645 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1647 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1648 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1649 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1650 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1651 driver_remove_file(drv
, &driver_attr_uwb_emulstate
);
1655 /*************************************************************************
1660 * Table of recommended minimum BIOS versions
1662 * Reasons for listing:
1663 * 1. Stable BIOS, listed because the unknown ammount of
1664 * bugs and bad ACPI behaviour on older versions
1666 * 2. BIOS or EC fw with known bugs that trigger on Linux
1668 * 3. BIOS with known reduced functionality in older versions
1670 * We recommend the latest BIOS and EC version.
1671 * We only support the latest BIOS and EC fw version as a rule.
1673 * Sources: IBM ThinkPad Public Web Documents (update changelogs),
1674 * Information from users in ThinkWiki
1676 * WARNING: we use this table also to detect that the machine is
1677 * a ThinkPad in some cases, so don't remove entries lightly.
1680 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1681 { .vendor = (__v), \
1682 .bios = TPID(__id1, __id2), \
1683 .ec = TPACPI_MATCH_ANY, \
1684 .quirks = TPACPI_MATCH_ANY << 16 \
1685 | (__bv1) << 8 | (__bv2) }
1687 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1688 __eid, __ev1, __ev2) \
1689 { .vendor = (__v), \
1690 .bios = TPID(__bid1, __bid2), \
1692 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1693 | (__bv1) << 8 | (__bv2) }
1695 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1696 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1698 /* Outdated IBM BIOSes often lack the EC id string */
1699 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1700 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1701 __bv1, __bv2, TPID(__id1, __id2), \
1703 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1704 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1707 /* Outdated IBM BIOSes often lack the EC id string */
1708 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1709 __eid1, __eid2, __ev1, __ev2) \
1710 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1711 __bv1, __bv2, TPID(__eid1, __eid2), \
1713 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1714 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1717 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1718 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1720 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1721 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1722 __bv1, __bv2, TPID(__id1, __id2), \
1725 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1726 __eid1, __eid2, __ev1, __ev2) \
1727 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1728 __bv1, __bv2, TPID(__eid1, __eid2), \
1731 static const struct tpacpi_quirk tpacpi_bios_version_qtable
[] __initconst
= {
1732 /* Numeric models ------------------ */
1733 /* FW MODEL BIOS VERS */
1734 TPV_QI0('I', 'M', '6', '5'), /* 570 */
1735 TPV_QI0('I', 'U', '2', '6'), /* 570E */
1736 TPV_QI0('I', 'B', '5', '4'), /* 600 */
1737 TPV_QI0('I', 'H', '4', '7'), /* 600E */
1738 TPV_QI0('I', 'N', '3', '6'), /* 600E */
1739 TPV_QI0('I', 'T', '5', '5'), /* 600X */
1740 TPV_QI0('I', 'D', '4', '8'), /* 770, 770E, 770ED */
1741 TPV_QI0('I', 'I', '4', '2'), /* 770X */
1742 TPV_QI0('I', 'O', '2', '3'), /* 770Z */
1744 /* A-series ------------------------- */
1745 /* FW MODEL BIOS VERS EC VERS */
1746 TPV_QI0('I', 'W', '5', '9'), /* A20m */
1747 TPV_QI0('I', 'V', '6', '9'), /* A20p */
1748 TPV_QI0('1', '0', '2', '6'), /* A21e, A22e */
1749 TPV_QI0('K', 'U', '3', '6'), /* A21e */
1750 TPV_QI0('K', 'X', '3', '6'), /* A21m, A22m */
1751 TPV_QI0('K', 'Y', '3', '8'), /* A21p, A22p */
1752 TPV_QI0('1', 'B', '1', '7'), /* A22e */
1753 TPV_QI0('1', '3', '2', '0'), /* A22m */
1754 TPV_QI0('1', 'E', '7', '3'), /* A30/p (0) */
1755 TPV_QI1('1', 'G', '4', '1', '1', '7'), /* A31/p (0) */
1756 TPV_QI1('1', 'N', '1', '6', '0', '7'), /* A31/p (0) */
1758 /* G-series ------------------------- */
1759 /* FW MODEL BIOS VERS */
1760 TPV_QI0('1', 'T', 'A', '6'), /* G40 */
1761 TPV_QI0('1', 'X', '5', '7'), /* G41 */
1763 /* R-series, T-series --------------- */
1764 /* FW MODEL BIOS VERS EC VERS */
1765 TPV_QI0('1', 'C', 'F', '0'), /* R30 */
1766 TPV_QI0('1', 'F', 'F', '1'), /* R31 */
1767 TPV_QI0('1', 'M', '9', '7'), /* R32 */
1768 TPV_QI0('1', 'O', '6', '1'), /* R40 */
1769 TPV_QI0('1', 'P', '6', '5'), /* R40 */
1770 TPV_QI0('1', 'S', '7', '0'), /* R40e */
1771 TPV_QI1('1', 'R', 'D', 'R', '7', '1'), /* R50/p, R51,
1772 T40/p, T41/p, T42/p (1) */
1773 TPV_QI1('1', 'V', '7', '1', '2', '8'), /* R50e, R51 (1) */
1774 TPV_QI1('7', '8', '7', '1', '0', '6'), /* R51e (1) */
1775 TPV_QI1('7', '6', '6', '9', '1', '6'), /* R52 (1) */
1776 TPV_QI1('7', '0', '6', '9', '2', '8'), /* R52, T43 (1) */
1778 TPV_QI0('I', 'Y', '6', '1'), /* T20 */
1779 TPV_QI0('K', 'Z', '3', '4'), /* T21 */
1780 TPV_QI0('1', '6', '3', '2'), /* T22 */
1781 TPV_QI1('1', 'A', '6', '4', '2', '3'), /* T23 (0) */
1782 TPV_QI1('1', 'I', '7', '1', '2', '0'), /* T30 (0) */
1783 TPV_QI1('1', 'Y', '6', '5', '2', '9'), /* T43/p (1) */
1785 TPV_QL1('7', '9', 'E', '3', '5', '0'), /* T60/p */
1786 TPV_QL1('7', 'C', 'D', '2', '2', '2'), /* R60, R60i */
1787 TPV_QL1('7', 'E', 'D', '0', '1', '5'), /* R60e, R60i */
1789 /* BIOS FW BIOS VERS EC FW EC VERS */
1790 TPV_QI2('1', 'W', '9', '0', '1', 'V', '2', '8'), /* R50e (1) */
1791 TPV_QL2('7', 'I', '3', '4', '7', '9', '5', '0'), /* T60/p wide */
1793 /* X-series ------------------------- */
1794 /* FW MODEL BIOS VERS EC VERS */
1795 TPV_QI0('I', 'Z', '9', 'D'), /* X20, X21 */
1796 TPV_QI0('1', 'D', '7', '0'), /* X22, X23, X24 */
1797 TPV_QI1('1', 'K', '4', '8', '1', '8'), /* X30 (0) */
1798 TPV_QI1('1', 'Q', '9', '7', '2', '3'), /* X31, X32 (0) */
1799 TPV_QI1('1', 'U', 'D', '3', 'B', '2'), /* X40 (0) */
1800 TPV_QI1('7', '4', '6', '4', '2', '7'), /* X41 (0) */
1801 TPV_QI1('7', '5', '6', '0', '2', '0'), /* X41t (0) */
1803 TPV_QL1('7', 'B', 'D', '7', '4', '0'), /* X60/s */
1804 TPV_QL1('7', 'J', '3', '0', '1', '3'), /* X60t */
1806 /* (0) - older versions lack DMI EC fw string and functionality */
1807 /* (1) - older versions known to lack functionality */
1818 static void __init
tpacpi_check_outdated_fw(void)
1820 unsigned long fwvers
;
1821 u16 ec_version
, bios_version
;
1823 fwvers
= tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1824 ARRAY_SIZE(tpacpi_bios_version_qtable
));
1829 bios_version
= fwvers
& 0xffffU
;
1830 ec_version
= (fwvers
>> 16) & 0xffffU
;
1832 /* note that unknown versions are set to 0x0000 and we use that */
1833 if ((bios_version
> thinkpad_id
.bios_release
) ||
1834 (ec_version
> thinkpad_id
.ec_release
&&
1835 ec_version
!= TPACPI_MATCH_ANY
)) {
1837 * The changelogs would let us track down the exact
1838 * reason, but it is just too much of a pain to track
1839 * it. We only list BIOSes that are either really
1840 * broken, or really stable to begin with, so it is
1841 * best if the user upgrades the firmware anyway.
1844 "WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1846 "WARNING: This firmware may be missing critical bug "
1847 "fixes and/or important features\n");
1851 static bool __init
tpacpi_is_fw_known(void)
1853 return tpacpi_check_quirks(tpacpi_bios_version_qtable
,
1854 ARRAY_SIZE(tpacpi_bios_version_qtable
)) != 0;
1857 /****************************************************************************
1858 ****************************************************************************
1862 ****************************************************************************
1863 ****************************************************************************/
1865 /*************************************************************************
1866 * thinkpad-acpi init subdriver
1869 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1871 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1872 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1874 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1875 (thinkpad_id
.bios_version_str
) ?
1876 thinkpad_id
.bios_version_str
: "unknown",
1877 (thinkpad_id
.ec_version_str
) ?
1878 thinkpad_id
.ec_version_str
: "unknown");
1880 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1881 printk(TPACPI_INFO
"%s %s, model %s\n",
1882 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1883 "IBM" : ((thinkpad_id
.vendor
==
1884 PCI_VENDOR_ID_LENOVO
) ?
1885 "Lenovo" : "Unknown vendor"),
1886 thinkpad_id
.model_str
,
1887 (thinkpad_id
.nummodel_str
) ?
1888 thinkpad_id
.nummodel_str
: "unknown");
1890 tpacpi_check_outdated_fw();
1894 static int thinkpad_acpi_driver_read(char *p
)
1898 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1899 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1904 static struct ibm_struct thinkpad_acpi_driver_data
= {
1906 .read
= thinkpad_acpi_driver_read
,
1909 /*************************************************************************
1914 * ThinkPad firmware event model
1916 * The ThinkPad firmware has two main event interfaces: normal ACPI
1917 * notifications (which follow the ACPI standard), and a private event
1920 * The private event interface also issues events for the hotkeys. As
1921 * the driver gained features, the event handling code ended up being
1922 * built around the hotkey subdriver. This will need to be refactored
1923 * to a more formal event API eventually.
1925 * Some "hotkeys" are actually supposed to be used as event reports,
1926 * such as "brightness has changed", "volume has changed", depending on
1927 * the ThinkPad model and how the firmware is operating.
1929 * Unlike other classes, hotkey-class events have mask/unmask control on
1930 * non-ancient firmware. However, how it behaves changes a lot with the
1931 * firmware model and version.
1934 enum { /* hot key scan codes (derived from ACPI DSDT) */
1935 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1936 TP_ACPI_HOTKEYSCAN_FNF2
,
1937 TP_ACPI_HOTKEYSCAN_FNF3
,
1938 TP_ACPI_HOTKEYSCAN_FNF4
,
1939 TP_ACPI_HOTKEYSCAN_FNF5
,
1940 TP_ACPI_HOTKEYSCAN_FNF6
,
1941 TP_ACPI_HOTKEYSCAN_FNF7
,
1942 TP_ACPI_HOTKEYSCAN_FNF8
,
1943 TP_ACPI_HOTKEYSCAN_FNF9
,
1944 TP_ACPI_HOTKEYSCAN_FNF10
,
1945 TP_ACPI_HOTKEYSCAN_FNF11
,
1946 TP_ACPI_HOTKEYSCAN_FNF12
,
1947 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1948 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1949 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1950 TP_ACPI_HOTKEYSCAN_FNHOME
,
1951 TP_ACPI_HOTKEYSCAN_FNEND
,
1952 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1953 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1954 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1955 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1956 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1957 TP_ACPI_HOTKEYSCAN_MUTE
,
1958 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1961 enum { /* Keys/events available through NVRAM polling */
1962 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1963 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1966 enum { /* Positions of some of the keys in hotkey masks */
1967 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1968 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1969 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1970 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1971 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1972 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1973 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1974 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1975 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1976 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1977 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1980 enum { /* NVRAM to ACPI HKEY group map */
1981 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1982 TP_ACPI_HKEY_ZOOM_MASK
|
1983 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1984 TP_ACPI_HKEY_HIBERNATE_MASK
,
1985 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1986 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1987 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1988 TP_ACPI_HKEY_VOLDWN_MASK
|
1989 TP_ACPI_HKEY_MUTE_MASK
,
1992 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1993 struct tp_nvram_state
{
1994 u16 thinkpad_toggle
:1;
1996 u16 display_toggle
:1;
1997 u16 thinklight_toggle
:1;
1998 u16 hibernate_toggle
:1;
1999 u16 displayexp_toggle
:1;
2000 u16 display_state
:1;
2001 u16 brightness_toggle
:1;
2002 u16 volume_toggle
:1;
2005 u8 brightness_level
;
2009 /* kthread for the hotkey poller */
2010 static struct task_struct
*tpacpi_hotkey_task
;
2012 /* Acquired while the poller kthread is running, use to sync start/stop */
2013 static struct mutex hotkey_thread_mutex
;
2016 * Acquire mutex to write poller control variables as an
2019 * Increment hotkey_config_change when changing them if you
2020 * want the kthread to forget old state.
2022 * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2024 static struct mutex hotkey_thread_data_mutex
;
2025 static unsigned int hotkey_config_change
;
2028 * hotkey poller control variables
2030 * Must be atomic or readers will also need to acquire mutex
2032 * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
2033 * should be used only when the changes need to be taken as
2034 * a block, OR when one needs to force the kthread to forget
2037 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
2038 static unsigned int hotkey_poll_freq
= 10; /* Hz */
2040 #define HOTKEY_CONFIG_CRITICAL_START \
2042 mutex_lock(&hotkey_thread_data_mutex); \
2043 hotkey_config_change++; \
2045 #define HOTKEY_CONFIG_CRITICAL_END \
2046 mutex_unlock(&hotkey_thread_data_mutex);
2048 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2050 #define hotkey_source_mask 0U
2051 #define HOTKEY_CONFIG_CRITICAL_START
2052 #define HOTKEY_CONFIG_CRITICAL_END
2054 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2056 static struct mutex hotkey_mutex
;
2058 static enum { /* Reasons for waking up */
2059 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
2060 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
2061 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
2062 } hotkey_wakeup_reason
;
2064 static int hotkey_autosleep_ack
;
2066 static u32 hotkey_orig_mask
; /* events the BIOS had enabled */
2067 static u32 hotkey_all_mask
; /* all events supported in fw */
2068 static u32 hotkey_reserved_mask
; /* events better left disabled */
2069 static u32 hotkey_driver_mask
; /* events needed by the driver */
2070 static u32 hotkey_user_mask
; /* events visible to userspace */
2071 static u32 hotkey_acpi_mask
; /* events enabled in firmware */
2073 static unsigned int hotkey_report_mode
;
2075 static u16
*hotkey_keycode_map
;
2077 static struct attribute_set
*hotkey_dev_attributes
;
2079 static void tpacpi_driver_event(const unsigned int hkey_event
);
2080 static void hotkey_driver_event(const unsigned int scancode
);
2081 static void hotkey_poll_setup(const bool may_warn
);
2083 /* HKEY.MHKG() return bits */
2084 #define TP_HOTKEY_TABLET_MASK (1 << 3)
2086 static int hotkey_get_wlsw(void)
2090 if (!tp_features
.hotkey_wlsw
)
2093 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2095 return (tpacpi_wlsw_emulstate
) ?
2096 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2099 if (!acpi_evalf(hkey_handle
, &status
, "WLSW", "d"))
2102 return (status
) ? TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
2105 static int hotkey_get_tablet_mode(int *status
)
2109 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
2112 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
2117 * Reads current event mask from firmware, and updates
2118 * hotkey_acpi_mask accordingly. Also resets any bits
2119 * from hotkey_user_mask that are unavailable to be
2120 * delivered (shadow requirement of the userspace ABI).
2122 * Call with hotkey_mutex held
2124 static int hotkey_mask_get(void)
2126 if (tp_features
.hotkey_mask
) {
2129 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
2132 hotkey_acpi_mask
= m
;
2134 /* no mask support doesn't mean no event support... */
2135 hotkey_acpi_mask
= hotkey_all_mask
;
2138 /* sync userspace-visible mask */
2139 hotkey_user_mask
&= (hotkey_acpi_mask
| hotkey_source_mask
);
2144 void static hotkey_mask_warn_incomplete_mask(void)
2146 /* log only what the user can fix... */
2147 const u32 wantedmask
= hotkey_driver_mask
&
2148 ~(hotkey_acpi_mask
| hotkey_source_mask
) &
2149 (hotkey_all_mask
| TPACPI_HKEY_NVRAM_KNOWN_MASK
);
2152 printk(TPACPI_NOTICE
2153 "required events 0x%08x not enabled!\n",
2158 * Set the firmware mask when supported
2160 * Also calls hotkey_mask_get to update hotkey_acpi_mask.
2162 * NOTE: does not set bits in hotkey_user_mask, but may reset them.
2164 * Call with hotkey_mutex held
2166 static int hotkey_mask_set(u32 mask
)
2171 const u32 fwmask
= mask
& ~hotkey_source_mask
;
2173 if (tp_features
.hotkey_mask
) {
2174 for (i
= 0; i
< 32; i
++) {
2175 if (!acpi_evalf(hkey_handle
,
2176 NULL
, "MHKM", "vdd", i
+ 1,
2177 !!(mask
& (1 << i
)))) {
2185 * We *must* make an inconditional call to hotkey_mask_get to
2186 * refresh hotkey_acpi_mask and update hotkey_user_mask
2188 * Take the opportunity to also log when we cannot _enable_
2191 if (!hotkey_mask_get() && !rc
&& (fwmask
& ~hotkey_acpi_mask
)) {
2192 printk(TPACPI_NOTICE
2193 "asked for hotkey mask 0x%08x, but "
2194 "firmware forced it to 0x%08x\n",
2195 fwmask
, hotkey_acpi_mask
);
2198 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
)
2199 hotkey_mask_warn_incomplete_mask();
2205 * Sets hotkey_user_mask and tries to set the firmware mask
2207 * Call with hotkey_mutex held
2209 static int hotkey_user_mask_set(const u32 mask
)
2213 /* Give people a chance to notice they are doing something that
2214 * is bound to go boom on their users sooner or later */
2215 if (!tp_warned
.hotkey_mask_ff
&&
2216 (mask
== 0xffff || mask
== 0xffffff ||
2217 mask
== 0xffffffff)) {
2218 tp_warned
.hotkey_mask_ff
= 1;
2219 printk(TPACPI_NOTICE
2220 "setting the hotkey mask to 0x%08x is likely "
2221 "not the best way to go about it\n", mask
);
2222 printk(TPACPI_NOTICE
2223 "please consider using the driver defaults, "
2224 "and refer to up-to-date thinkpad-acpi "
2228 /* Try to enable what the user asked for, plus whatever we need.
2229 * this syncs everything but won't enable bits in hotkey_user_mask */
2230 rc
= hotkey_mask_set((mask
| hotkey_driver_mask
) & ~hotkey_source_mask
);
2232 /* Enable the available bits in hotkey_user_mask */
2233 hotkey_user_mask
= mask
& (hotkey_acpi_mask
| hotkey_source_mask
);
2239 * Sets the driver hotkey mask.
2241 * Can be called even if the hotkey subdriver is inactive
2243 static int tpacpi_hotkey_driver_mask_set(const u32 mask
)
2247 /* Do the right thing if hotkey_init has not been called yet */
2248 if (!tp_features
.hotkey
) {
2249 hotkey_driver_mask
= mask
;
2253 mutex_lock(&hotkey_mutex
);
2255 HOTKEY_CONFIG_CRITICAL_START
2256 hotkey_driver_mask
= mask
;
2257 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2258 hotkey_source_mask
|= (mask
& ~hotkey_all_mask
);
2260 HOTKEY_CONFIG_CRITICAL_END
2262 rc
= hotkey_mask_set((hotkey_acpi_mask
| hotkey_driver_mask
) &
2263 ~hotkey_source_mask
);
2264 hotkey_poll_setup(true);
2266 mutex_unlock(&hotkey_mutex
);
2271 static int hotkey_status_get(int *status
)
2273 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
2279 static int hotkey_status_set(bool enable
)
2281 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", enable
? 1 : 0))
2287 static void tpacpi_input_send_tabletsw(void)
2291 if (tp_features
.hotkey_tablet
&&
2292 !hotkey_get_tablet_mode(&state
)) {
2293 mutex_lock(&tpacpi_inputdev_send_mutex
);
2295 input_report_switch(tpacpi_inputdev
,
2296 SW_TABLET_MODE
, !!state
);
2297 input_sync(tpacpi_inputdev
);
2299 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2303 /* Do NOT call without validating scancode first */
2304 static void tpacpi_input_send_key(const unsigned int scancode
)
2306 const unsigned int keycode
= hotkey_keycode_map
[scancode
];
2308 if (keycode
!= KEY_RESERVED
) {
2309 mutex_lock(&tpacpi_inputdev_send_mutex
);
2311 input_report_key(tpacpi_inputdev
, keycode
, 1);
2312 if (keycode
== KEY_UNKNOWN
)
2313 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2315 input_sync(tpacpi_inputdev
);
2317 input_report_key(tpacpi_inputdev
, keycode
, 0);
2318 if (keycode
== KEY_UNKNOWN
)
2319 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
2321 input_sync(tpacpi_inputdev
);
2323 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2327 /* Do NOT call without validating scancode first */
2328 static void tpacpi_input_send_key_masked(const unsigned int scancode
)
2330 hotkey_driver_event(scancode
);
2331 if (hotkey_user_mask
& (1 << scancode
))
2332 tpacpi_input_send_key(scancode
);
2335 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2336 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
2338 /* Do NOT call without validating scancode first */
2339 static void tpacpi_hotkey_send_key(unsigned int scancode
)
2341 tpacpi_input_send_key_masked(scancode
);
2342 if (hotkey_report_mode
< 2) {
2343 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
2344 0x80, TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
2348 static void hotkey_read_nvram(struct tp_nvram_state
*n
, const u32 m
)
2352 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
2353 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
2354 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
2355 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
2356 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
2357 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
2359 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
2360 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
2361 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
2363 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
2364 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
2365 n
->displayexp_toggle
=
2366 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
2368 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
2369 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
2370 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
2371 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
2372 n
->brightness_toggle
=
2373 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
2375 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
2376 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
2377 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
2378 >> TP_NVRAM_POS_LEVEL_VOLUME
;
2379 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
2380 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
2384 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
2385 struct tp_nvram_state
*newn
,
2386 const u32 event_mask
)
2389 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2391 if ((event_mask & (1 << __scancode)) && \
2392 oldn->__member != newn->__member) \
2393 tpacpi_hotkey_send_key(__scancode); \
2396 #define TPACPI_MAY_SEND_KEY(__scancode) \
2398 if (event_mask & (1 << __scancode)) \
2399 tpacpi_hotkey_send_key(__scancode); \
2402 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
2403 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
2404 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
2405 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
2407 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
2409 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
2412 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
2413 if (oldn
->mute
!= newn
->mute
) {
2414 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2416 if (oldn
->volume_level
> newn
->volume_level
) {
2417 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2418 } else if (oldn
->volume_level
< newn
->volume_level
) {
2419 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2420 } else if (oldn
->mute
== newn
->mute
) {
2421 /* repeated key presses that didn't change state */
2423 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
2424 } else if (newn
->volume_level
!= 0) {
2425 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
2427 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
2432 /* handle brightness */
2433 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
2434 if (oldn
->brightness_level
< newn
->brightness_level
) {
2435 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2436 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
2437 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2439 /* repeated key presses that didn't change state */
2440 if (newn
->brightness_level
!= 0) {
2441 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
2443 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
2448 #undef TPACPI_COMPARE_KEY
2449 #undef TPACPI_MAY_SEND_KEY
2455 * We track all events in hotkey_source_mask all the time, since
2456 * most of them are edge-based. We only issue those requested by
2457 * hotkey_user_mask or hotkey_driver_mask, though.
2459 static int hotkey_kthread(void *data
)
2461 struct tp_nvram_state s
[2];
2462 u32 poll_mask
, event_mask
;
2463 unsigned int si
, so
;
2465 unsigned int change_detector
, must_reset
;
2466 unsigned int poll_freq
;
2468 mutex_lock(&hotkey_thread_mutex
);
2470 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
2479 /* Initial state for compares */
2480 mutex_lock(&hotkey_thread_data_mutex
);
2481 change_detector
= hotkey_config_change
;
2482 poll_mask
= hotkey_source_mask
;
2483 event_mask
= hotkey_source_mask
&
2484 (hotkey_driver_mask
| hotkey_user_mask
);
2485 poll_freq
= hotkey_poll_freq
;
2486 mutex_unlock(&hotkey_thread_data_mutex
);
2487 hotkey_read_nvram(&s
[so
], poll_mask
);
2489 while (!kthread_should_stop()) {
2491 if (likely(poll_freq
))
2494 t
= 100; /* should never happen... */
2496 t
= msleep_interruptible(t
);
2497 if (unlikely(kthread_should_stop()))
2499 must_reset
= try_to_freeze();
2500 if (t
> 0 && !must_reset
)
2503 mutex_lock(&hotkey_thread_data_mutex
);
2504 if (must_reset
|| hotkey_config_change
!= change_detector
) {
2505 /* forget old state on thaw or config change */
2508 change_detector
= hotkey_config_change
;
2510 poll_mask
= hotkey_source_mask
;
2511 event_mask
= hotkey_source_mask
&
2512 (hotkey_driver_mask
| hotkey_user_mask
);
2513 poll_freq
= hotkey_poll_freq
;
2514 mutex_unlock(&hotkey_thread_data_mutex
);
2516 if (likely(poll_mask
)) {
2517 hotkey_read_nvram(&s
[si
], poll_mask
);
2518 if (likely(si
!= so
)) {
2519 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
2529 mutex_unlock(&hotkey_thread_mutex
);
2533 /* call with hotkey_mutex held */
2534 static void hotkey_poll_stop_sync(void)
2536 if (tpacpi_hotkey_task
) {
2537 if (frozen(tpacpi_hotkey_task
) ||
2538 freezing(tpacpi_hotkey_task
))
2539 thaw_process(tpacpi_hotkey_task
);
2541 kthread_stop(tpacpi_hotkey_task
);
2542 tpacpi_hotkey_task
= NULL
;
2543 mutex_lock(&hotkey_thread_mutex
);
2544 /* at this point, the thread did exit */
2545 mutex_unlock(&hotkey_thread_mutex
);
2549 /* call with hotkey_mutex held */
2550 static void hotkey_poll_setup(const bool may_warn
)
2552 const u32 poll_driver_mask
= hotkey_driver_mask
& hotkey_source_mask
;
2553 const u32 poll_user_mask
= hotkey_user_mask
& hotkey_source_mask
;
2555 if (hotkey_poll_freq
> 0 &&
2556 (poll_driver_mask
||
2557 (poll_user_mask
&& tpacpi_inputdev
->users
> 0))) {
2558 if (!tpacpi_hotkey_task
) {
2559 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
2560 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
2561 if (IS_ERR(tpacpi_hotkey_task
)) {
2562 tpacpi_hotkey_task
= NULL
;
2564 "could not create kernel thread "
2565 "for hotkey polling\n");
2569 hotkey_poll_stop_sync();
2570 if (may_warn
&& (poll_driver_mask
|| poll_user_mask
) &&
2571 hotkey_poll_freq
== 0) {
2572 printk(TPACPI_NOTICE
2573 "hot keys 0x%08x and/or events 0x%08x "
2574 "require polling, which is currently "
2576 poll_user_mask
, poll_driver_mask
);
2581 static void hotkey_poll_setup_safe(const bool may_warn
)
2583 mutex_lock(&hotkey_mutex
);
2584 hotkey_poll_setup(may_warn
);
2585 mutex_unlock(&hotkey_mutex
);
2588 /* call with hotkey_mutex held */
2589 static void hotkey_poll_set_freq(unsigned int freq
)
2592 hotkey_poll_stop_sync();
2594 hotkey_poll_freq
= freq
;
2597 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2599 static void hotkey_poll_setup(const bool __unused
)
2603 static void hotkey_poll_setup_safe(const bool __unused
)
2607 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2609 static int hotkey_inputdev_open(struct input_dev
*dev
)
2611 switch (tpacpi_lifecycle
) {
2612 case TPACPI_LIFE_INIT
:
2613 case TPACPI_LIFE_RUNNING
:
2614 hotkey_poll_setup_safe(false);
2616 case TPACPI_LIFE_EXITING
:
2620 /* Should only happen if tpacpi_lifecycle is corrupt */
2625 static void hotkey_inputdev_close(struct input_dev
*dev
)
2627 /* disable hotkey polling when possible */
2628 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
&&
2629 !(hotkey_source_mask
& hotkey_driver_mask
))
2630 hotkey_poll_setup_safe(false);
2633 /* sysfs hotkey enable ------------------------------------------------- */
2634 static ssize_t
hotkey_enable_show(struct device
*dev
,
2635 struct device_attribute
*attr
,
2640 printk_deprecated_attribute("hotkey_enable",
2641 "Hotkey reporting is always enabled");
2643 res
= hotkey_status_get(&status
);
2647 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
2650 static ssize_t
hotkey_enable_store(struct device
*dev
,
2651 struct device_attribute
*attr
,
2652 const char *buf
, size_t count
)
2656 printk_deprecated_attribute("hotkey_enable",
2657 "Hotkeys can be disabled through hotkey_mask");
2659 if (parse_strtoul(buf
, 1, &t
))
2668 static struct device_attribute dev_attr_hotkey_enable
=
2669 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
2670 hotkey_enable_show
, hotkey_enable_store
);
2672 /* sysfs hotkey mask --------------------------------------------------- */
2673 static ssize_t
hotkey_mask_show(struct device
*dev
,
2674 struct device_attribute
*attr
,
2677 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_user_mask
);
2680 static ssize_t
hotkey_mask_store(struct device
*dev
,
2681 struct device_attribute
*attr
,
2682 const char *buf
, size_t count
)
2687 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
2690 if (mutex_lock_killable(&hotkey_mutex
))
2691 return -ERESTARTSYS
;
2693 res
= hotkey_user_mask_set(t
);
2695 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2696 hotkey_poll_setup(true);
2699 mutex_unlock(&hotkey_mutex
);
2701 tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t
);
2703 return (res
) ? res
: count
;
2706 static struct device_attribute dev_attr_hotkey_mask
=
2707 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
2708 hotkey_mask_show
, hotkey_mask_store
);
2710 /* sysfs hotkey bios_enabled ------------------------------------------- */
2711 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
2712 struct device_attribute
*attr
,
2715 return sprintf(buf
, "0\n");
2718 static struct device_attribute dev_attr_hotkey_bios_enabled
=
2719 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
2721 /* sysfs hotkey bios_mask ---------------------------------------------- */
2722 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
2723 struct device_attribute
*attr
,
2726 printk_deprecated_attribute("hotkey_bios_mask",
2727 "This attribute is useless.");
2728 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
2731 static struct device_attribute dev_attr_hotkey_bios_mask
=
2732 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
2734 /* sysfs hotkey all_mask ----------------------------------------------- */
2735 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
2736 struct device_attribute
*attr
,
2739 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2740 hotkey_all_mask
| hotkey_source_mask
);
2743 static struct device_attribute dev_attr_hotkey_all_mask
=
2744 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
2746 /* sysfs hotkey recommended_mask --------------------------------------- */
2747 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
2748 struct device_attribute
*attr
,
2751 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
2752 (hotkey_all_mask
| hotkey_source_mask
)
2753 & ~hotkey_reserved_mask
);
2756 static struct device_attribute dev_attr_hotkey_recommended_mask
=
2757 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
2758 hotkey_recommended_mask_show
, NULL
);
2760 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2762 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2763 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
2764 struct device_attribute
*attr
,
2767 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
2770 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
2771 struct device_attribute
*attr
,
2772 const char *buf
, size_t count
)
2778 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
2779 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
2782 if (mutex_lock_killable(&hotkey_mutex
))
2783 return -ERESTARTSYS
;
2785 HOTKEY_CONFIG_CRITICAL_START
2786 hotkey_source_mask
= t
;
2787 HOTKEY_CONFIG_CRITICAL_END
2789 rc
= hotkey_mask_set((hotkey_user_mask
| hotkey_driver_mask
) &
2790 ~hotkey_source_mask
);
2791 hotkey_poll_setup(true);
2793 /* check if events needed by the driver got disabled */
2794 r_ev
= hotkey_driver_mask
& ~(hotkey_acpi_mask
& hotkey_all_mask
)
2795 & ~hotkey_source_mask
& TPACPI_HKEY_NVRAM_KNOWN_MASK
;
2797 mutex_unlock(&hotkey_mutex
);
2800 printk(TPACPI_ERR
"hotkey_source_mask: failed to update the"
2801 "firmware event mask!\n");
2804 printk(TPACPI_NOTICE
"hotkey_source_mask: "
2805 "some important events were disabled: "
2808 tpacpi_disclose_usertask("hotkey_source_mask", "set to 0x%08lx\n", t
);
2810 return (rc
< 0) ? rc
: count
;
2813 static struct device_attribute dev_attr_hotkey_source_mask
=
2814 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
2815 hotkey_source_mask_show
, hotkey_source_mask_store
);
2817 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2818 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
2819 struct device_attribute
*attr
,
2822 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
2825 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
2826 struct device_attribute
*attr
,
2827 const char *buf
, size_t count
)
2831 if (parse_strtoul(buf
, 25, &t
))
2834 if (mutex_lock_killable(&hotkey_mutex
))
2835 return -ERESTARTSYS
;
2837 hotkey_poll_set_freq(t
);
2838 hotkey_poll_setup(true);
2840 mutex_unlock(&hotkey_mutex
);
2842 tpacpi_disclose_usertask("hotkey_poll_freq", "set to %lu\n", t
);
2847 static struct device_attribute dev_attr_hotkey_poll_freq
=
2848 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
2849 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
2851 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2853 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2854 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
2855 struct device_attribute
*attr
,
2859 res
= hotkey_get_wlsw();
2863 /* Opportunistic update */
2864 tpacpi_rfk_update_hwblock_state((res
== TPACPI_RFK_RADIO_OFF
));
2866 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2867 (res
== TPACPI_RFK_RADIO_OFF
) ? 0 : 1);
2870 static struct device_attribute dev_attr_hotkey_radio_sw
=
2871 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
2873 static void hotkey_radio_sw_notify_change(void)
2875 if (tp_features
.hotkey_wlsw
)
2876 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2880 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2881 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
2882 struct device_attribute
*attr
,
2886 res
= hotkey_get_tablet_mode(&s
);
2890 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
2893 static struct device_attribute dev_attr_hotkey_tablet_mode
=
2894 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
2896 static void hotkey_tablet_mode_notify_change(void)
2898 if (tp_features
.hotkey_tablet
)
2899 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2900 "hotkey_tablet_mode");
2903 /* sysfs hotkey report_mode -------------------------------------------- */
2904 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2905 struct device_attribute
*attr
,
2908 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2909 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2912 static struct device_attribute dev_attr_hotkey_report_mode
=
2913 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2915 /* sysfs wakeup reason (pollable) -------------------------------------- */
2916 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2917 struct device_attribute
*attr
,
2920 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2923 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2924 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2926 static void hotkey_wakeup_reason_notify_change(void)
2928 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2932 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2933 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2934 struct device_attribute
*attr
,
2937 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2940 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2941 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2942 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2944 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2946 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2947 "wakeup_hotunplug_complete");
2950 /* --------------------------------------------------------------------- */
2952 static struct attribute
*hotkey_attributes
[] __initdata
= {
2953 &dev_attr_hotkey_enable
.attr
,
2954 &dev_attr_hotkey_bios_enabled
.attr
,
2955 &dev_attr_hotkey_bios_mask
.attr
,
2956 &dev_attr_hotkey_report_mode
.attr
,
2957 &dev_attr_hotkey_wakeup_reason
.attr
,
2958 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2959 &dev_attr_hotkey_mask
.attr
,
2960 &dev_attr_hotkey_all_mask
.attr
,
2961 &dev_attr_hotkey_recommended_mask
.attr
,
2962 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2963 &dev_attr_hotkey_source_mask
.attr
,
2964 &dev_attr_hotkey_poll_freq
.attr
,
2969 * Sync both the hw and sw blocking state of all switches
2971 static void tpacpi_send_radiosw_update(void)
2976 * We must sync all rfkill controllers *before* issuing any
2977 * rfkill input events, or we will race the rfkill core input
2980 * tpacpi_inputdev_send_mutex works as a syncronization point
2983 * We optimize to avoid numerous calls to hotkey_get_wlsw.
2986 wlsw
= hotkey_get_wlsw();
2988 /* Sync hw blocking state first if it is hw-blocked */
2989 if (wlsw
== TPACPI_RFK_RADIO_OFF
)
2990 tpacpi_rfk_update_hwblock_state(true);
2992 /* Sync sw blocking state */
2993 tpacpi_rfk_update_swstate_all();
2995 /* Sync hw blocking state last if it is hw-unblocked */
2996 if (wlsw
== TPACPI_RFK_RADIO_ON
)
2997 tpacpi_rfk_update_hwblock_state(false);
2999 /* Issue rfkill input event for WLSW switch */
3001 mutex_lock(&tpacpi_inputdev_send_mutex
);
3003 input_report_switch(tpacpi_inputdev
,
3004 SW_RFKILL_ALL
, (wlsw
> 0));
3005 input_sync(tpacpi_inputdev
);
3007 mutex_unlock(&tpacpi_inputdev_send_mutex
);
3011 * this can be unconditional, as we will poll state again
3012 * if userspace uses the notify to read data
3014 hotkey_radio_sw_notify_change();
3017 static void hotkey_exit(void)
3019 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3020 mutex_lock(&hotkey_mutex
);
3021 hotkey_poll_stop_sync();
3022 mutex_unlock(&hotkey_mutex
);
3025 if (hotkey_dev_attributes
)
3026 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3028 kfree(hotkey_keycode_map
);
3030 dbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_HKEY
,
3031 "restoring original HKEY status and mask\n");
3032 /* yes, there is a bitwise or below, we want the
3033 * functions to be called even if one of them fail */
3034 if (((tp_features
.hotkey_mask
&&
3035 hotkey_mask_set(hotkey_orig_mask
)) |
3036 hotkey_status_set(false)) != 0)
3038 "failed to restore hot key mask "
3039 "to BIOS defaults\n");
3042 static void __init
hotkey_unmap(const unsigned int scancode
)
3044 if (hotkey_keycode_map
[scancode
] != KEY_RESERVED
) {
3045 clear_bit(hotkey_keycode_map
[scancode
],
3046 tpacpi_inputdev
->keybit
);
3047 hotkey_keycode_map
[scancode
] = KEY_RESERVED
;
3053 * TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
3056 #define TPACPI_HK_Q_INIMASK 0x0001
3058 static const struct tpacpi_quirk tpacpi_hotkey_qtable
[] __initconst
= {
3059 TPACPI_Q_IBM('I', 'H', TPACPI_HK_Q_INIMASK
), /* 600E */
3060 TPACPI_Q_IBM('I', 'N', TPACPI_HK_Q_INIMASK
), /* 600E */
3061 TPACPI_Q_IBM('I', 'D', TPACPI_HK_Q_INIMASK
), /* 770, 770E, 770ED */
3062 TPACPI_Q_IBM('I', 'W', TPACPI_HK_Q_INIMASK
), /* A20m */
3063 TPACPI_Q_IBM('I', 'V', TPACPI_HK_Q_INIMASK
), /* A20p */
3064 TPACPI_Q_IBM('1', '0', TPACPI_HK_Q_INIMASK
), /* A21e, A22e */
3065 TPACPI_Q_IBM('K', 'U', TPACPI_HK_Q_INIMASK
), /* A21e */
3066 TPACPI_Q_IBM('K', 'X', TPACPI_HK_Q_INIMASK
), /* A21m, A22m */
3067 TPACPI_Q_IBM('K', 'Y', TPACPI_HK_Q_INIMASK
), /* A21p, A22p */
3068 TPACPI_Q_IBM('1', 'B', TPACPI_HK_Q_INIMASK
), /* A22e */
3069 TPACPI_Q_IBM('1', '3', TPACPI_HK_Q_INIMASK
), /* A22m */
3070 TPACPI_Q_IBM('1', 'E', TPACPI_HK_Q_INIMASK
), /* A30/p (0) */
3071 TPACPI_Q_IBM('1', 'C', TPACPI_HK_Q_INIMASK
), /* R30 */
3072 TPACPI_Q_IBM('1', 'F', TPACPI_HK_Q_INIMASK
), /* R31 */
3073 TPACPI_Q_IBM('I', 'Y', TPACPI_HK_Q_INIMASK
), /* T20 */
3074 TPACPI_Q_IBM('K', 'Z', TPACPI_HK_Q_INIMASK
), /* T21 */
3075 TPACPI_Q_IBM('1', '6', TPACPI_HK_Q_INIMASK
), /* T22 */
3076 TPACPI_Q_IBM('I', 'Z', TPACPI_HK_Q_INIMASK
), /* X20, X21 */
3077 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK
), /* X22, X23, X24 */
3080 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
3082 /* Requirements for changing the default keymaps:
3084 * 1. Many of the keys are mapped to KEY_RESERVED for very
3085 * good reasons. Do not change them unless you have deep
3086 * knowledge on the IBM and Lenovo ThinkPad firmware for
3087 * the various ThinkPad models. The driver behaves
3088 * differently for KEY_RESERVED: such keys have their
3089 * hot key mask *unset* in mask_recommended, and also
3090 * in the initial hot key mask programmed into the
3091 * firmware at driver load time, which means the firm-
3092 * ware may react very differently if you change them to
3095 * 2. You must be subscribed to the linux-thinkpad and
3096 * ibm-acpi-devel mailing lists, and you should read the
3097 * list archives since 2007 if you want to change the
3098 * keymaps. This requirement exists so that you will
3099 * know the past history of problems with the thinkpad-
3100 * acpi driver keymaps, and also that you will be
3101 * listening to any bug reports;
3103 * 3. Do not send thinkpad-acpi specific patches directly to
3104 * for merging, *ever*. Send them to the linux-acpi
3105 * mailinglist for comments. Merging is to be done only
3106 * through acpi-test and the ACPI maintainer.
3108 * If the above is too much to ask, don't change the keymap.
3109 * Ask the thinkpad-acpi maintainer to do it, instead.
3111 static u16 ibm_keycode_map
[] __initdata
= {
3112 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3113 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
3114 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3115 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3117 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3118 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3119 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3120 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3122 /* brightness: firmware always reacts to them */
3123 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
3124 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
3126 /* Thinklight: firmware always react to it */
3127 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3129 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3130 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3132 /* Volume: firmware always react to it and reprograms
3133 * the built-in *extra* mixer. Never map it to control
3134 * another mixer by default. */
3135 KEY_RESERVED
, /* 0x14: VOLUME UP */
3136 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3137 KEY_RESERVED
, /* 0x16: MUTE */
3139 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3141 /* (assignments unknown, please report if found) */
3142 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3143 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3145 static u16 lenovo_keycode_map
[] __initdata
= {
3146 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
3147 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
3148 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
3149 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
3151 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
3152 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
3153 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
3154 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
3156 /* These should be enabled --only-- when ACPI video
3157 * is disabled (i.e. in "vendor" mode), and are handled
3158 * in a special way by the init code */
3159 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
3160 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
3162 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
3164 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
3165 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
3167 /* Volume: z60/z61, T60 (BIOS version?): firmware always
3168 * react to it and reprograms the built-in *extra* mixer.
3169 * Never map it to control another mixer by default.
3171 * T60?, T61, R60?, R61: firmware and EC tries to send
3172 * these over the regular keyboard, so these are no-ops,
3173 * but there are still weird bugs re. MUTE, so do not
3174 * change unless you get test reports from all Lenovo
3175 * models. May cause the BIOS to interfere with the
3178 KEY_RESERVED
, /* 0x14: VOLUME UP */
3179 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
3180 KEY_RESERVED
, /* 0x16: MUTE */
3182 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
3184 /* (assignments unknown, please report if found) */
3185 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3186 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
3189 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
3190 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
3191 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
3196 bool radiosw_state
= false;
3197 bool tabletsw_state
= false;
3199 unsigned long quirks
;
3201 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3202 "initializing hotkey subdriver\n");
3204 BUG_ON(!tpacpi_inputdev
);
3205 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
3206 tpacpi_inputdev
->close
!= NULL
);
3208 TPACPI_ACPIHANDLE_INIT(hkey
);
3209 mutex_init(&hotkey_mutex
);
3211 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3212 mutex_init(&hotkey_thread_mutex
);
3213 mutex_init(&hotkey_thread_data_mutex
);
3216 /* hotkey not supported on 570 */
3217 tp_features
.hotkey
= hkey_handle
!= NULL
;
3219 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3221 str_supported(tp_features
.hotkey
));
3223 if (!tp_features
.hotkey
)
3226 quirks
= tpacpi_check_quirks(tpacpi_hotkey_qtable
,
3227 ARRAY_SIZE(tpacpi_hotkey_qtable
));
3229 tpacpi_disable_brightness_delay();
3231 /* MUST have enough space for all attributes to be added to
3232 * hotkey_dev_attributes */
3233 hotkey_dev_attributes
= create_attr_set(
3234 ARRAY_SIZE(hotkey_attributes
) + 2,
3236 if (!hotkey_dev_attributes
)
3238 res
= add_many_to_attr_set(hotkey_dev_attributes
,
3240 ARRAY_SIZE(hotkey_attributes
));
3244 /* mask not supported on 600e/x, 770e, 770x, A21e, A2xm/p,
3245 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
3246 for HKEY interface version 0x100 */
3247 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
3248 if ((hkeyv
>> 8) != 1) {
3249 printk(TPACPI_ERR
"unknown version of the "
3250 "HKEY interface: 0x%x\n", hkeyv
);
3251 printk(TPACPI_ERR
"please report this to %s\n",
3255 * MHKV 0x100 in A31, R40, R40e,
3256 * T4x, X31, and later
3258 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3259 "firmware HKEY interface version: 0x%x\n",
3262 /* Paranoia check AND init hotkey_all_mask */
3263 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
3266 "missing MHKA handler, "
3267 "please report this to %s\n",
3269 /* Fallback: pre-init for FN+F3,F4,F12 */
3270 hotkey_all_mask
= 0x080cU
;
3272 tp_features
.hotkey_mask
= 1;
3277 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3278 "hotkey masks are %s\n",
3279 str_supported(tp_features
.hotkey_mask
));
3281 /* Init hotkey_all_mask if not initialized yet */
3282 if (!tp_features
.hotkey_mask
&& !hotkey_all_mask
&&
3283 (quirks
& TPACPI_HK_Q_INIMASK
))
3284 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
3286 /* Init hotkey_acpi_mask and hotkey_orig_mask */
3287 if (tp_features
.hotkey_mask
) {
3288 /* hotkey_source_mask *must* be zero for
3289 * the first hotkey_mask_get to return hotkey_orig_mask */
3290 res
= hotkey_mask_get();
3294 hotkey_orig_mask
= hotkey_acpi_mask
;
3296 hotkey_orig_mask
= hotkey_all_mask
;
3297 hotkey_acpi_mask
= hotkey_all_mask
;
3300 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3302 tp_features
.hotkey_wlsw
= 1;
3303 radiosw_state
= !!tpacpi_wlsw_emulstate
;
3305 "radio switch emulation enabled\n");
3308 /* Not all thinkpads have a hardware radio switch */
3309 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
3310 tp_features
.hotkey_wlsw
= 1;
3311 radiosw_state
= !!status
;
3313 "radio switch found; radios are %s\n",
3314 enabled(status
, 0));
3316 if (tp_features
.hotkey_wlsw
)
3317 res
= add_to_attr_set(hotkey_dev_attributes
,
3318 &dev_attr_hotkey_radio_sw
.attr
);
3320 /* For X41t, X60t, X61t Tablets... */
3321 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
3322 tp_features
.hotkey_tablet
= 1;
3323 tabletsw_state
= !!(status
& TP_HOTKEY_TABLET_MASK
);
3325 "possible tablet mode switch found; "
3326 "ThinkPad in %s mode\n",
3327 (tabletsw_state
) ? "tablet" : "laptop");
3328 res
= add_to_attr_set(hotkey_dev_attributes
,
3329 &dev_attr_hotkey_tablet_mode
.attr
);
3333 res
= register_attr_set_with_sysfs(
3334 hotkey_dev_attributes
,
3335 &tpacpi_pdev
->dev
.kobj
);
3339 /* Set up key map */
3341 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
3343 if (!hotkey_keycode_map
) {
3345 "failed to allocate memory for key map\n");
3350 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
3351 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3352 "using Lenovo default hot key map\n");
3353 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
3354 TPACPI_HOTKEY_MAP_SIZE
);
3356 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3357 "using IBM default hot key map\n");
3358 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
3359 TPACPI_HOTKEY_MAP_SIZE
);
3362 input_set_capability(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
);
3363 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
3364 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
3365 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
3366 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
3367 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
3368 input_set_capability(tpacpi_inputdev
, EV_KEY
,
3369 hotkey_keycode_map
[i
]);
3371 if (i
< sizeof(hotkey_reserved_mask
)*8)
3372 hotkey_reserved_mask
|= 1 << i
;
3376 if (tp_features
.hotkey_wlsw
) {
3377 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_RFKILL_ALL
);
3378 input_report_switch(tpacpi_inputdev
,
3379 SW_RFKILL_ALL
, radiosw_state
);
3381 if (tp_features
.hotkey_tablet
) {
3382 input_set_capability(tpacpi_inputdev
, EV_SW
, SW_TABLET_MODE
);
3383 input_report_switch(tpacpi_inputdev
,
3384 SW_TABLET_MODE
, tabletsw_state
);
3387 /* Do not issue duplicate brightness change events to
3389 if (!tp_features
.bright_acpimode
)
3390 /* update bright_acpimode... */
3391 tpacpi_check_std_acpi_brightness_support();
3393 if (tp_features
.bright_acpimode
&& acpi_video_backlight_support()) {
3395 "This ThinkPad has standard ACPI backlight "
3396 "brightness control, supported by the ACPI "
3398 printk(TPACPI_NOTICE
3399 "Disabling thinkpad-acpi brightness events "
3402 /* Disable brightness up/down on Lenovo thinkpads when
3403 * ACPI is handling them, otherwise it is plain impossible
3404 * for userspace to do something even remotely sane */
3405 hotkey_reserved_mask
|=
3406 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
3407 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
3408 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME
);
3409 hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND
);
3412 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3413 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
3415 & ~hotkey_reserved_mask
;
3417 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3418 "hotkey source mask 0x%08x, polling freq %u\n",
3419 hotkey_source_mask
, hotkey_poll_freq
);
3422 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3423 "enabling firmware HKEY event interface...\n");
3424 res
= hotkey_status_set(true);
3429 res
= hotkey_mask_set(((hotkey_all_mask
& ~hotkey_reserved_mask
)
3430 | hotkey_driver_mask
)
3431 & ~hotkey_source_mask
);
3432 if (res
< 0 && res
!= -ENXIO
) {
3436 hotkey_user_mask
= (hotkey_acpi_mask
| hotkey_source_mask
)
3437 & ~hotkey_reserved_mask
;
3438 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3439 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3440 hotkey_user_mask
, hotkey_acpi_mask
, hotkey_source_mask
);
3442 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_HKEY
,
3443 "legacy ibm/hotkey event reporting over procfs %s\n",
3444 (hotkey_report_mode
< 2) ?
3445 "enabled" : "disabled");
3447 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
3448 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
3450 hotkey_poll_setup_safe(true);
3455 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
3456 hotkey_dev_attributes
= NULL
;
3458 return (res
< 0)? res
: 1;
3461 static bool hotkey_notify_hotkey(const u32 hkey
,
3463 bool *ignore_acpi_ev
)
3465 /* 0x1000-0x1FFF: key presses */
3466 unsigned int scancode
= hkey
& 0xfff;
3467 *send_acpi_ev
= true;
3468 *ignore_acpi_ev
= false;
3470 if (scancode
> 0 && scancode
< 0x21) {
3472 if (!(hotkey_source_mask
& (1 << scancode
))) {
3473 tpacpi_input_send_key_masked(scancode
);
3474 *send_acpi_ev
= false;
3476 *ignore_acpi_ev
= true;
3483 static bool hotkey_notify_wakeup(const u32 hkey
,
3485 bool *ignore_acpi_ev
)
3487 /* 0x2000-0x2FFF: Wakeup reason */
3488 *send_acpi_ev
= true;
3489 *ignore_acpi_ev
= false;
3492 case TP_HKEY_EV_WKUP_S3_UNDOCK
: /* suspend, undock */
3493 case TP_HKEY_EV_WKUP_S4_UNDOCK
: /* hibernation, undock */
3494 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
3495 *ignore_acpi_ev
= true;
3498 case TP_HKEY_EV_WKUP_S3_BAYEJ
: /* suspend, bay eject */
3499 case TP_HKEY_EV_WKUP_S4_BAYEJ
: /* hibernation, bay eject */
3500 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
3501 *ignore_acpi_ev
= true;
3504 case TP_HKEY_EV_WKUP_S3_BATLOW
: /* Battery on critical low level/S3 */
3505 case TP_HKEY_EV_WKUP_S4_BATLOW
: /* Battery on critical low level/S4 */
3507 "EMERGENCY WAKEUP: battery almost empty\n");
3508 /* how to auto-heal: */
3509 /* 2313: woke up from S3, go to S4/S5 */
3510 /* 2413: woke up from S4, go to S5 */
3517 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
3519 "woke up due to a hot-unplug "
3521 hotkey_wakeup_reason_notify_change();
3526 static bool hotkey_notify_usrevent(const u32 hkey
,
3528 bool *ignore_acpi_ev
)
3530 /* 0x5000-0x5FFF: human interface helpers */
3531 *send_acpi_ev
= true;
3532 *ignore_acpi_ev
= false;
3535 case TP_HKEY_EV_PEN_INSERTED
: /* X61t: tablet pen inserted into bay */
3536 case TP_HKEY_EV_PEN_REMOVED
: /* X61t: tablet pen removed from bay */
3539 case TP_HKEY_EV_TABLET_TABLET
: /* X41t-X61t: tablet mode */
3540 case TP_HKEY_EV_TABLET_NOTEBOOK
: /* X41t-X61t: normal mode */
3541 tpacpi_input_send_tabletsw();
3542 hotkey_tablet_mode_notify_change();
3543 *send_acpi_ev
= false;
3546 case TP_HKEY_EV_LID_CLOSE
: /* Lid closed */
3547 case TP_HKEY_EV_LID_OPEN
: /* Lid opened */
3548 case TP_HKEY_EV_BRGHT_CHANGED
: /* brightness changed */
3549 /* do not propagate these events */
3550 *ignore_acpi_ev
= true;
3558 static void thermal_dump_all_sensors(void);
3560 static bool hotkey_notify_thermal(const u32 hkey
,
3562 bool *ignore_acpi_ev
)
3566 /* 0x6000-0x6FFF: thermal alarms */
3567 *send_acpi_ev
= true;
3568 *ignore_acpi_ev
= false;
3571 case TP_HKEY_EV_THM_TABLE_CHANGED
:
3573 "EC reports that Thermal Table has changed\n");
3574 /* recommended action: do nothing, we don't have
3575 * Lenovo ATM information */
3577 case TP_HKEY_EV_ALARM_BAT_HOT
:
3579 "THERMAL ALARM: battery is too hot!\n");
3580 /* recommended action: warn user through gui */
3582 case TP_HKEY_EV_ALARM_BAT_XHOT
:
3584 "THERMAL EMERGENCY: battery is extremely hot!\n");
3585 /* recommended action: immediate sleep/hibernate */
3587 case TP_HKEY_EV_ALARM_SENSOR_HOT
:
3590 "a sensor reports something is too hot!\n");
3591 /* recommended action: warn user through gui, that */
3592 /* some internal component is too hot */
3594 case TP_HKEY_EV_ALARM_SENSOR_XHOT
:
3596 "THERMAL EMERGENCY: "
3597 "a sensor reports something is extremely hot!\n");
3598 /* recommended action: immediate sleep/hibernate */
3602 "THERMAL ALERT: unknown thermal alarm received\n");
3606 thermal_dump_all_sensors();
3611 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
3615 bool ignore_acpi_ev
;
3618 if (event
!= 0x80) {
3620 "unknown HKEY notification event %d\n", event
);
3621 /* forward it to userspace, maybe it knows how to handle it */
3622 acpi_bus_generate_netlink_event(
3623 ibm
->acpi
->device
->pnp
.device_class
,
3624 dev_name(&ibm
->acpi
->device
->dev
),
3630 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
3631 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
3640 send_acpi_ev
= true;
3641 ignore_acpi_ev
= false;
3643 switch (hkey
>> 12) {
3645 /* 0x1000-0x1FFF: key presses */
3646 known_ev
= hotkey_notify_hotkey(hkey
, &send_acpi_ev
,
3650 /* 0x2000-0x2FFF: Wakeup reason */
3651 known_ev
= hotkey_notify_wakeup(hkey
, &send_acpi_ev
,
3655 /* 0x3000-0x3FFF: bay-related wakeups */
3657 case TP_HKEY_EV_BAYEJ_ACK
:
3658 hotkey_autosleep_ack
= 1;
3661 hotkey_wakeup_hotunplug_complete_notify_change();
3664 case TP_HKEY_EV_OPTDRV_EJ
:
3665 /* FIXME: kick libata if SATA link offline */
3673 /* 0x4000-0x4FFF: dock-related wakeups */
3674 if (hkey
== TP_HKEY_EV_UNDOCK_ACK
) {
3675 hotkey_autosleep_ack
= 1;
3678 hotkey_wakeup_hotunplug_complete_notify_change();
3685 /* 0x5000-0x5FFF: human interface helpers */
3686 known_ev
= hotkey_notify_usrevent(hkey
, &send_acpi_ev
,
3690 /* 0x6000-0x6FFF: thermal alarms */
3691 known_ev
= hotkey_notify_thermal(hkey
, &send_acpi_ev
,
3695 /* 0x7000-0x7FFF: misc */
3696 if (tp_features
.hotkey_wlsw
&&
3697 hkey
== TP_HKEY_EV_RFKILL_CHANGED
) {
3698 tpacpi_send_radiosw_update();
3703 /* fallthrough to default */
3708 printk(TPACPI_NOTICE
3709 "unhandled HKEY event 0x%04x\n", hkey
);
3710 printk(TPACPI_NOTICE
3711 "please report the conditions when this "
3712 "event happened to %s\n", TPACPI_MAIL
);
3716 if (!ignore_acpi_ev
&&
3717 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
3718 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
3722 /* netlink events */
3723 if (!ignore_acpi_ev
&& send_acpi_ev
) {
3724 acpi_bus_generate_netlink_event(
3725 ibm
->acpi
->device
->pnp
.device_class
,
3726 dev_name(&ibm
->acpi
->device
->dev
),
3732 static void hotkey_suspend(pm_message_t state
)
3734 /* Do these on suspend, we get the events on early resume! */
3735 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
3736 hotkey_autosleep_ack
= 0;
3739 static void hotkey_resume(void)
3741 tpacpi_disable_brightness_delay();
3743 if (hotkey_status_set(true) < 0 ||
3744 hotkey_mask_set(hotkey_acpi_mask
) < 0)
3746 "error while attempting to reset the event "
3747 "firmware interface\n");
3749 tpacpi_send_radiosw_update();
3750 hotkey_tablet_mode_notify_change();
3751 hotkey_wakeup_reason_notify_change();
3752 hotkey_wakeup_hotunplug_complete_notify_change();
3753 hotkey_poll_setup_safe(false);
3756 /* procfs -------------------------------------------------------------- */
3757 static int hotkey_read(char *p
)
3762 if (!tp_features
.hotkey
) {
3763 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3767 if (mutex_lock_killable(&hotkey_mutex
))
3768 return -ERESTARTSYS
;
3769 res
= hotkey_status_get(&status
);
3771 res
= hotkey_mask_get();
3772 mutex_unlock(&hotkey_mutex
);
3776 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
3777 if (hotkey_all_mask
) {
3778 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_user_mask
);
3779 len
+= sprintf(p
+ len
,
3780 "commands:\tenable, disable, reset, <mask>\n");
3782 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
3783 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
3789 static void hotkey_enabledisable_warn(bool enable
)
3791 tpacpi_log_usertask("procfs hotkey enable/disable");
3792 if (!WARN((tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
|| !enable
),
3794 "hotkey enable/disable functionality has been "
3795 "removed from the driver. Hotkeys are always "
3798 "Please remove the hotkey=enable module "
3799 "parameter, it is deprecated. Hotkeys are always "
3803 static int hotkey_write(char *buf
)
3809 if (!tp_features
.hotkey
)
3812 if (mutex_lock_killable(&hotkey_mutex
))
3813 return -ERESTARTSYS
;
3815 mask
= hotkey_user_mask
;
3818 while ((cmd
= next_cmd(&buf
))) {
3819 if (strlencmp(cmd
, "enable") == 0) {
3820 hotkey_enabledisable_warn(1);
3821 } else if (strlencmp(cmd
, "disable") == 0) {
3822 hotkey_enabledisable_warn(0);
3824 } else if (strlencmp(cmd
, "reset") == 0) {
3825 mask
= (hotkey_all_mask
| hotkey_source_mask
)
3826 & ~hotkey_reserved_mask
;
3827 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
3829 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
3838 tpacpi_disclose_usertask("procfs hotkey",
3839 "set mask to 0x%08x\n", mask
);
3840 res
= hotkey_user_mask_set(mask
);
3844 mutex_unlock(&hotkey_mutex
);
3848 static const struct acpi_device_id ibm_htk_device_ids
[] = {
3849 {TPACPI_ACPI_HKEY_HID
, 0},
3853 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
3854 .hid
= ibm_htk_device_ids
,
3855 .notify
= hotkey_notify
,
3856 .handle
= &hkey_handle
,
3857 .type
= ACPI_DEVICE_NOTIFY
,
3860 static struct ibm_struct hotkey_driver_data
= {
3862 .read
= hotkey_read
,
3863 .write
= hotkey_write
,
3864 .exit
= hotkey_exit
,
3865 .resume
= hotkey_resume
,
3866 .suspend
= hotkey_suspend
,
3867 .acpi
= &ibm_hotkey_acpidriver
,
3870 /*************************************************************************
3871 * Bluetooth subdriver
3875 /* ACPI GBDC/SBDC bits */
3876 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
3877 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
3878 TP_ACPI_BLUETOOTH_RESUMECTRL
= 0x04, /* Bluetooth state at resume:
3879 0 = disable, 1 = enable */
3883 /* ACPI \BLTH commands */
3884 TP_ACPI_BLTH_GET_ULTRAPORT_ID
= 0x00, /* Get Ultraport BT ID */
3885 TP_ACPI_BLTH_GET_PWR_ON_RESUME
= 0x01, /* Get power-on-resume state */
3886 TP_ACPI_BLTH_PWR_ON_ON_RESUME
= 0x02, /* Resume powered on */
3887 TP_ACPI_BLTH_PWR_OFF_ON_RESUME
= 0x03, /* Resume powered off */
3888 TP_ACPI_BLTH_SAVE_STATE
= 0x05, /* Save state for S4/S5 */
3891 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3893 static int bluetooth_get_status(void)
3897 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3898 if (dbg_bluetoothemul
)
3899 return (tpacpi_bluetooth_emulstate
) ?
3900 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3903 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
3906 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
3907 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
3910 static int bluetooth_set_status(enum tpacpi_rfkill_state state
)
3914 vdbg_printk(TPACPI_DBG_RFKILL
,
3915 "will attempt to %s bluetooth\n",
3916 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
3918 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3919 if (dbg_bluetoothemul
) {
3920 tpacpi_bluetooth_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
3925 if (state
== TPACPI_RFK_RADIO_ON
)
3926 status
= TP_ACPI_BLUETOOTH_RADIOSSW
3927 | TP_ACPI_BLUETOOTH_RESUMECTRL
;
3931 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
3937 /* sysfs bluetooth enable ---------------------------------------------- */
3938 static ssize_t
bluetooth_enable_show(struct device
*dev
,
3939 struct device_attribute
*attr
,
3942 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID
,
3946 static ssize_t
bluetooth_enable_store(struct device
*dev
,
3947 struct device_attribute
*attr
,
3948 const char *buf
, size_t count
)
3950 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID
,
3954 static struct device_attribute dev_attr_bluetooth_enable
=
3955 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
3956 bluetooth_enable_show
, bluetooth_enable_store
);
3958 /* --------------------------------------------------------------------- */
3960 static struct attribute
*bluetooth_attributes
[] = {
3961 &dev_attr_bluetooth_enable
.attr
,
3965 static const struct attribute_group bluetooth_attr_group
= {
3966 .attrs
= bluetooth_attributes
,
3969 static const struct tpacpi_rfk_ops bluetooth_tprfk_ops
= {
3970 .get_status
= bluetooth_get_status
,
3971 .set_status
= bluetooth_set_status
,
3974 static void bluetooth_shutdown(void)
3976 /* Order firmware to save current state to NVRAM */
3977 if (!acpi_evalf(NULL
, NULL
, "\\BLTH", "vd",
3978 TP_ACPI_BLTH_SAVE_STATE
))
3979 printk(TPACPI_NOTICE
3980 "failed to save bluetooth state to NVRAM\n");
3982 vdbg_printk(TPACPI_DBG_RFKILL
,
3983 "bluestooth state saved to NVRAM\n");
3986 static void bluetooth_exit(void)
3988 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3989 &bluetooth_attr_group
);
3991 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
3993 bluetooth_shutdown();
3996 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
4001 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4002 "initializing bluetooth subdriver\n");
4004 TPACPI_ACPIHANDLE_INIT(hkey
);
4006 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4007 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
4008 tp_features
.bluetooth
= hkey_handle
&&
4009 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
4011 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4012 "bluetooth is %s, status 0x%02x\n",
4013 str_supported(tp_features
.bluetooth
),
4016 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4017 if (dbg_bluetoothemul
) {
4018 tp_features
.bluetooth
= 1;
4020 "bluetooth switch emulation enabled\n");
4023 if (tp_features
.bluetooth
&&
4024 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
4025 /* no bluetooth hardware present in system */
4026 tp_features
.bluetooth
= 0;
4027 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4028 "bluetooth hardware not installed\n");
4031 if (!tp_features
.bluetooth
)
4034 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
4035 &bluetooth_tprfk_ops
,
4036 RFKILL_TYPE_BLUETOOTH
,
4037 TPACPI_RFK_BLUETOOTH_SW_NAME
,
4042 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4043 &bluetooth_attr_group
);
4045 tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
);
4052 /* procfs -------------------------------------------------------------- */
4053 static int bluetooth_read(char *p
)
4055 return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID
, p
);
4058 static int bluetooth_write(char *buf
)
4060 return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID
, buf
);
4063 static struct ibm_struct bluetooth_driver_data
= {
4064 .name
= "bluetooth",
4065 .read
= bluetooth_read
,
4066 .write
= bluetooth_write
,
4067 .exit
= bluetooth_exit
,
4068 .shutdown
= bluetooth_shutdown
,
4071 /*************************************************************************
4076 /* ACPI GWAN/SWAN bits */
4077 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
4078 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
4079 TP_ACPI_WANCARD_RESUMECTRL
= 0x04, /* Wan state at resume:
4080 0 = disable, 1 = enable */
4083 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
4085 static int wan_get_status(void)
4089 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4091 return (tpacpi_wwan_emulstate
) ?
4092 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4095 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
4098 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
4099 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4102 static int wan_set_status(enum tpacpi_rfkill_state state
)
4106 vdbg_printk(TPACPI_DBG_RFKILL
,
4107 "will attempt to %s wwan\n",
4108 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4110 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4112 tpacpi_wwan_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4117 if (state
== TPACPI_RFK_RADIO_ON
)
4118 status
= TP_ACPI_WANCARD_RADIOSSW
4119 | TP_ACPI_WANCARD_RESUMECTRL
;
4123 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
4129 /* sysfs wan enable ---------------------------------------------------- */
4130 static ssize_t
wan_enable_show(struct device
*dev
,
4131 struct device_attribute
*attr
,
4134 return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID
,
4138 static ssize_t
wan_enable_store(struct device
*dev
,
4139 struct device_attribute
*attr
,
4140 const char *buf
, size_t count
)
4142 return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID
,
4146 static struct device_attribute dev_attr_wan_enable
=
4147 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
4148 wan_enable_show
, wan_enable_store
);
4150 /* --------------------------------------------------------------------- */
4152 static struct attribute
*wan_attributes
[] = {
4153 &dev_attr_wan_enable
.attr
,
4157 static const struct attribute_group wan_attr_group
= {
4158 .attrs
= wan_attributes
,
4161 static const struct tpacpi_rfk_ops wan_tprfk_ops
= {
4162 .get_status
= wan_get_status
,
4163 .set_status
= wan_set_status
,
4166 static void wan_shutdown(void)
4168 /* Order firmware to save current state to NVRAM */
4169 if (!acpi_evalf(NULL
, NULL
, "\\WGSV", "vd",
4170 TP_ACPI_WGSV_SAVE_STATE
))
4171 printk(TPACPI_NOTICE
4172 "failed to save WWAN state to NVRAM\n");
4174 vdbg_printk(TPACPI_DBG_RFKILL
,
4175 "WWAN state saved to NVRAM\n");
4178 static void wan_exit(void)
4180 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
4183 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4188 static int __init
wan_init(struct ibm_init_struct
*iibm
)
4193 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4194 "initializing wan subdriver\n");
4196 TPACPI_ACPIHANDLE_INIT(hkey
);
4198 tp_features
.wan
= hkey_handle
&&
4199 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
4201 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4202 "wan is %s, status 0x%02x\n",
4203 str_supported(tp_features
.wan
),
4206 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4208 tp_features
.wan
= 1;
4210 "wwan switch emulation enabled\n");
4213 if (tp_features
.wan
&&
4214 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
4215 /* no wan hardware present in system */
4216 tp_features
.wan
= 0;
4217 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4218 "wan hardware not installed\n");
4221 if (!tp_features
.wan
)
4224 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
4227 TPACPI_RFK_WWAN_SW_NAME
,
4232 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4236 tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID
);
4243 /* procfs -------------------------------------------------------------- */
4244 static int wan_read(char *p
)
4246 return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID
, p
);
4249 static int wan_write(char *buf
)
4251 return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID
, buf
);
4254 static struct ibm_struct wan_driver_data
= {
4259 .shutdown
= wan_shutdown
,
4262 /*************************************************************************
4267 /* ACPI GUWB/SUWB bits */
4268 TP_ACPI_UWB_HWPRESENT
= 0x01, /* UWB hw available */
4269 TP_ACPI_UWB_RADIOSSW
= 0x02, /* UWB radio enabled */
4272 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4274 static int uwb_get_status(void)
4278 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4280 return (tpacpi_uwb_emulstate
) ?
4281 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4284 if (!acpi_evalf(hkey_handle
, &status
, "GUWB", "d"))
4287 return ((status
& TP_ACPI_UWB_RADIOSSW
) != 0) ?
4288 TPACPI_RFK_RADIO_ON
: TPACPI_RFK_RADIO_OFF
;
4291 static int uwb_set_status(enum tpacpi_rfkill_state state
)
4295 vdbg_printk(TPACPI_DBG_RFKILL
,
4296 "will attempt to %s UWB\n",
4297 (state
== TPACPI_RFK_RADIO_ON
) ? "enable" : "disable");
4299 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4301 tpacpi_uwb_emulstate
= (state
== TPACPI_RFK_RADIO_ON
);
4306 if (state
== TPACPI_RFK_RADIO_ON
)
4307 status
= TP_ACPI_UWB_RADIOSSW
;
4311 if (!acpi_evalf(hkey_handle
, NULL
, "SUWB", "vd", status
))
4317 /* --------------------------------------------------------------------- */
4319 static const struct tpacpi_rfk_ops uwb_tprfk_ops
= {
4320 .get_status
= uwb_get_status
,
4321 .set_status
= uwb_set_status
,
4324 static void uwb_exit(void)
4326 tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID
);
4329 static int __init
uwb_init(struct ibm_init_struct
*iibm
)
4334 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4335 "initializing uwb subdriver\n");
4337 TPACPI_ACPIHANDLE_INIT(hkey
);
4339 tp_features
.uwb
= hkey_handle
&&
4340 acpi_evalf(hkey_handle
, &status
, "GUWB", "qd");
4342 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_RFKILL
,
4343 "uwb is %s, status 0x%02x\n",
4344 str_supported(tp_features
.uwb
),
4347 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4349 tp_features
.uwb
= 1;
4351 "uwb switch emulation enabled\n");
4354 if (tp_features
.uwb
&&
4355 !(status
& TP_ACPI_UWB_HWPRESENT
)) {
4356 /* no uwb hardware present in system */
4357 tp_features
.uwb
= 0;
4358 dbg_printk(TPACPI_DBG_INIT
,
4359 "uwb hardware not installed\n");
4362 if (!tp_features
.uwb
)
4365 res
= tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID
,
4368 TPACPI_RFK_UWB_SW_NAME
,
4373 static struct ibm_struct uwb_driver_data
= {
4376 .flags
.experimental
= 1,
4379 /*************************************************************************
4383 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4385 enum video_access_mode
{
4386 TPACPI_VIDEO_NONE
= 0,
4387 TPACPI_VIDEO_570
, /* 570 */
4388 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
4389 TPACPI_VIDEO_NEW
, /* all others */
4392 enum { /* video status flags, based on VIDEO_570 */
4393 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
4394 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
4395 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
4398 enum { /* TPACPI_VIDEO_570 constants */
4399 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
4400 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
4401 * video_status_flags */
4402 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
4403 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
4406 static enum video_access_mode video_supported
;
4407 static int video_orig_autosw
;
4409 static int video_autosw_get(void);
4410 static int video_autosw_set(int enable
);
4412 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
4414 static int __init
video_init(struct ibm_init_struct
*iibm
)
4418 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
4420 TPACPI_ACPIHANDLE_INIT(vid
);
4421 TPACPI_ACPIHANDLE_INIT(vid2
);
4423 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
4424 /* G41, assume IVGA doesn't change */
4425 vid_handle
= vid2_handle
;
4428 /* video switching not supported on R30, R31 */
4429 video_supported
= TPACPI_VIDEO_NONE
;
4430 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
4432 video_supported
= TPACPI_VIDEO_570
;
4433 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
4434 /* 600e/x, 770e, 770x */
4435 video_supported
= TPACPI_VIDEO_770
;
4438 video_supported
= TPACPI_VIDEO_NEW
;
4440 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
4441 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
4444 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
4447 static void video_exit(void)
4449 dbg_printk(TPACPI_DBG_EXIT
,
4450 "restoring original video autoswitch mode\n");
4451 if (video_autosw_set(video_orig_autosw
))
4452 printk(TPACPI_ERR
"error while trying to restore original "
4453 "video autoswitch mode\n");
4456 static int video_outputsw_get(void)
4461 switch (video_supported
) {
4462 case TPACPI_VIDEO_570
:
4463 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
4464 TP_ACPI_VIDEO_570_PHSCMD
))
4466 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
4468 case TPACPI_VIDEO_770
:
4469 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4472 status
|= TP_ACPI_VIDEO_S_LCD
;
4473 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4476 status
|= TP_ACPI_VIDEO_S_CRT
;
4478 case TPACPI_VIDEO_NEW
:
4479 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
4480 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
4483 status
|= TP_ACPI_VIDEO_S_CRT
;
4485 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
4486 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
4489 status
|= TP_ACPI_VIDEO_S_LCD
;
4490 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
4493 status
|= TP_ACPI_VIDEO_S_DVI
;
4502 static int video_outputsw_set(int status
)
4507 switch (video_supported
) {
4508 case TPACPI_VIDEO_570
:
4509 res
= acpi_evalf(NULL
, NULL
,
4510 "\\_SB.PHS2", "vdd",
4511 TP_ACPI_VIDEO_570_PHS2CMD
,
4512 status
| TP_ACPI_VIDEO_570_PHS2SET
);
4514 case TPACPI_VIDEO_770
:
4515 autosw
= video_autosw_get();
4519 res
= video_autosw_set(1);
4522 res
= acpi_evalf(vid_handle
, NULL
,
4523 "ASWT", "vdd", status
* 0x100, 0);
4524 if (!autosw
&& video_autosw_set(autosw
)) {
4526 "video auto-switch left enabled due to error\n");
4530 case TPACPI_VIDEO_NEW
:
4531 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
4532 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
4538 return (res
)? 0 : -EIO
;
4541 static int video_autosw_get(void)
4545 switch (video_supported
) {
4546 case TPACPI_VIDEO_570
:
4547 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
4550 case TPACPI_VIDEO_770
:
4551 case TPACPI_VIDEO_NEW
:
4552 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
4562 static int video_autosw_set(int enable
)
4564 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
4569 static int video_outputsw_cycle(void)
4571 int autosw
= video_autosw_get();
4577 switch (video_supported
) {
4578 case TPACPI_VIDEO_570
:
4579 res
= video_autosw_set(1);
4582 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
4584 case TPACPI_VIDEO_770
:
4585 case TPACPI_VIDEO_NEW
:
4586 res
= video_autosw_set(1);
4589 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
4594 if (!autosw
&& video_autosw_set(autosw
)) {
4596 "video auto-switch left enabled due to error\n");
4600 return (res
)? 0 : -EIO
;
4603 static int video_expand_toggle(void)
4605 switch (video_supported
) {
4606 case TPACPI_VIDEO_570
:
4607 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
4609 case TPACPI_VIDEO_770
:
4610 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
4612 case TPACPI_VIDEO_NEW
:
4613 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
4621 static int video_read(char *p
)
4626 if (video_supported
== TPACPI_VIDEO_NONE
) {
4627 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4631 status
= video_outputsw_get();
4635 autosw
= video_autosw_get();
4639 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4640 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
4641 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
4642 if (video_supported
== TPACPI_VIDEO_NEW
)
4643 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
4644 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
4645 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
4646 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
4647 if (video_supported
== TPACPI_VIDEO_NEW
)
4648 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
4649 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
4650 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
4655 static int video_write(char *buf
)
4658 int enable
, disable
, status
;
4661 if (video_supported
== TPACPI_VIDEO_NONE
)
4667 while ((cmd
= next_cmd(&buf
))) {
4668 if (strlencmp(cmd
, "lcd_enable") == 0) {
4669 enable
|= TP_ACPI_VIDEO_S_LCD
;
4670 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
4671 disable
|= TP_ACPI_VIDEO_S_LCD
;
4672 } else if (strlencmp(cmd
, "crt_enable") == 0) {
4673 enable
|= TP_ACPI_VIDEO_S_CRT
;
4674 } else if (strlencmp(cmd
, "crt_disable") == 0) {
4675 disable
|= TP_ACPI_VIDEO_S_CRT
;
4676 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4677 strlencmp(cmd
, "dvi_enable") == 0) {
4678 enable
|= TP_ACPI_VIDEO_S_DVI
;
4679 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
4680 strlencmp(cmd
, "dvi_disable") == 0) {
4681 disable
|= TP_ACPI_VIDEO_S_DVI
;
4682 } else if (strlencmp(cmd
, "auto_enable") == 0) {
4683 res
= video_autosw_set(1);
4686 } else if (strlencmp(cmd
, "auto_disable") == 0) {
4687 res
= video_autosw_set(0);
4690 } else if (strlencmp(cmd
, "video_switch") == 0) {
4691 res
= video_outputsw_cycle();
4694 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
4695 res
= video_expand_toggle();
4702 if (enable
|| disable
) {
4703 status
= video_outputsw_get();
4706 res
= video_outputsw_set((status
& ~disable
) | enable
);
4714 static struct ibm_struct video_driver_data
= {
4717 .write
= video_write
,
4721 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4723 /*************************************************************************
4724 * Light (thinklight) subdriver
4727 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4728 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
4730 static int light_get_status(void)
4734 if (tp_features
.light_status
) {
4735 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
4743 static int light_set_status(int status
)
4747 if (tp_features
.light
) {
4749 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
4751 TP_CMOS_THINKLIGHT_ON
:
4752 TP_CMOS_THINKLIGHT_OFF
);
4754 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
4757 return (rc
)? 0 : -EIO
;
4763 static void light_set_status_worker(struct work_struct
*work
)
4765 struct tpacpi_led_classdev
*data
=
4766 container_of(work
, struct tpacpi_led_classdev
, work
);
4768 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4769 light_set_status((data
->new_state
!= TPACPI_LED_OFF
));
4772 static void light_sysfs_set(struct led_classdev
*led_cdev
,
4773 enum led_brightness brightness
)
4775 struct tpacpi_led_classdev
*data
=
4776 container_of(led_cdev
,
4777 struct tpacpi_led_classdev
,
4779 data
->new_state
= (brightness
!= LED_OFF
) ?
4780 TPACPI_LED_ON
: TPACPI_LED_OFF
;
4781 queue_work(tpacpi_wq
, &data
->work
);
4784 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
4786 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
4789 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
4791 .name
= "tpacpi::thinklight",
4792 .brightness_set
= &light_sysfs_set
,
4793 .brightness_get
= &light_sysfs_get
,
4797 static int __init
light_init(struct ibm_init_struct
*iibm
)
4801 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
4803 TPACPI_ACPIHANDLE_INIT(ledb
);
4804 TPACPI_ACPIHANDLE_INIT(lght
);
4805 TPACPI_ACPIHANDLE_INIT(cmos
);
4806 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
4808 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4809 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
4811 if (tp_features
.light
)
4812 /* light status not supported on
4813 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4814 tp_features
.light_status
=
4815 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
4817 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
4818 str_supported(tp_features
.light
),
4819 str_supported(tp_features
.light_status
));
4821 if (!tp_features
.light
)
4824 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4825 &tpacpi_led_thinklight
.led_classdev
);
4828 tp_features
.light
= 0;
4829 tp_features
.light_status
= 0;
4837 static void light_exit(void)
4839 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
4840 if (work_pending(&tpacpi_led_thinklight
.work
))
4841 flush_workqueue(tpacpi_wq
);
4844 static int light_read(char *p
)
4849 if (!tp_features
.light
) {
4850 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4851 } else if (!tp_features
.light_status
) {
4852 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
4853 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4855 status
= light_get_status();
4858 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
4859 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
4865 static int light_write(char *buf
)
4870 if (!tp_features
.light
)
4873 while ((cmd
= next_cmd(&buf
))) {
4874 if (strlencmp(cmd
, "on") == 0) {
4876 } else if (strlencmp(cmd
, "off") == 0) {
4882 return light_set_status(newstatus
);
4885 static struct ibm_struct light_driver_data
= {
4888 .write
= light_write
,
4892 /*************************************************************************
4896 /* sysfs cmos_command -------------------------------------------------- */
4897 static ssize_t
cmos_command_store(struct device
*dev
,
4898 struct device_attribute
*attr
,
4899 const char *buf
, size_t count
)
4901 unsigned long cmos_cmd
;
4904 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4907 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4908 return (res
)? res
: count
;
4911 static struct device_attribute dev_attr_cmos_command
=
4912 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4914 /* --------------------------------------------------------------------- */
4916 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4920 vdbg_printk(TPACPI_DBG_INIT
,
4921 "initializing cmos commands subdriver\n");
4923 TPACPI_ACPIHANDLE_INIT(cmos
);
4925 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4926 str_supported(cmos_handle
!= NULL
));
4928 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4932 return (cmos_handle
)? 0 : 1;
4935 static void cmos_exit(void)
4937 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4940 static int cmos_read(char *p
)
4944 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4945 R30, R31, T20-22, X20-21 */
4947 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4949 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4950 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4956 static int cmos_write(char *buf
)
4961 while ((cmd
= next_cmd(&buf
))) {
4962 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4963 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4968 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4976 static struct ibm_struct cmos_driver_data
= {
4979 .write
= cmos_write
,
4983 /*************************************************************************
4987 enum led_access_mode
{
4988 TPACPI_LED_NONE
= 0,
4989 TPACPI_LED_570
, /* 570 */
4990 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4991 TPACPI_LED_NEW
, /* all others */
4994 enum { /* For TPACPI_LED_OLD */
4995 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4996 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4997 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
5000 static enum led_access_mode led_supported
;
5002 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
5003 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
5004 /* T20-22, X20-21 */
5005 "LED", /* all others */
5008 #define TPACPI_LED_NUMLEDS 16
5009 static struct tpacpi_led_classdev
*tpacpi_leds
;
5010 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
5011 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
5012 /* there's a limit of 19 chars + NULL before 2.6.26 */
5014 "tpacpi:orange:batt",
5015 "tpacpi:green:batt",
5016 "tpacpi::dock_active",
5017 "tpacpi::bay_active",
5018 "tpacpi::dock_batt",
5019 "tpacpi::unknown_led",
5021 "tpacpi::dock_status1",
5022 "tpacpi::dock_status2",
5023 "tpacpi::unknown_led2",
5024 "tpacpi::unknown_led3",
5025 "tpacpi::thinkvantage",
5027 #define TPACPI_SAFE_LEDS 0x1081U
5029 static inline bool tpacpi_is_led_restricted(const unsigned int led
)
5031 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5034 return (1U & (TPACPI_SAFE_LEDS
>> led
)) == 0;
5038 static int led_get_status(const unsigned int led
)
5041 enum led_status_t led_s
;
5043 switch (led_supported
) {
5044 case TPACPI_LED_570
:
5045 if (!acpi_evalf(ec_handle
,
5046 &status
, "GLED", "dd", 1 << led
))
5048 led_s
= (status
== 0)?
5053 tpacpi_led_state_cache
[led
] = led_s
;
5062 static int led_set_status(const unsigned int led
,
5063 const enum led_status_t ledstatus
)
5065 /* off, on, blink. Index is led_status_t */
5066 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
5067 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
5071 switch (led_supported
) {
5072 case TPACPI_LED_570
:
5074 if (unlikely(led
> 7))
5076 if (unlikely(tpacpi_is_led_restricted(led
)))
5078 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5079 (1 << led
), led_sled_arg1
[ledstatus
]))
5082 case TPACPI_LED_OLD
:
5083 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
5084 if (unlikely(led
> 7))
5086 if (unlikely(tpacpi_is_led_restricted(led
)))
5088 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
5090 rc
= ec_write(TPACPI_LED_EC_HLBL
,
5091 (ledstatus
== TPACPI_LED_BLINK
) << led
);
5093 rc
= ec_write(TPACPI_LED_EC_HLCL
,
5094 (ledstatus
!= TPACPI_LED_OFF
) << led
);
5096 case TPACPI_LED_NEW
:
5098 if (unlikely(led
>= TPACPI_LED_NUMLEDS
))
5100 if (unlikely(tpacpi_is_led_restricted(led
)))
5102 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
5103 led
, led_led_arg1
[ledstatus
]))
5111 tpacpi_led_state_cache
[led
] = ledstatus
;
5116 static void led_set_status_worker(struct work_struct
*work
)
5118 struct tpacpi_led_classdev
*data
=
5119 container_of(work
, struct tpacpi_led_classdev
, work
);
5121 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
5122 led_set_status(data
->led
, data
->new_state
);
5125 static void led_sysfs_set(struct led_classdev
*led_cdev
,
5126 enum led_brightness brightness
)
5128 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5129 struct tpacpi_led_classdev
, led_classdev
);
5131 if (brightness
== LED_OFF
)
5132 data
->new_state
= TPACPI_LED_OFF
;
5133 else if (tpacpi_led_state_cache
[data
->led
] != TPACPI_LED_BLINK
)
5134 data
->new_state
= TPACPI_LED_ON
;
5136 data
->new_state
= TPACPI_LED_BLINK
;
5138 queue_work(tpacpi_wq
, &data
->work
);
5141 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
5142 unsigned long *delay_on
, unsigned long *delay_off
)
5144 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5145 struct tpacpi_led_classdev
, led_classdev
);
5147 /* Can we choose the flash rate? */
5148 if (*delay_on
== 0 && *delay_off
== 0) {
5149 /* yes. set them to the hardware blink rate (1 Hz) */
5150 *delay_on
= 500; /* ms */
5151 *delay_off
= 500; /* ms */
5152 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
5155 data
->new_state
= TPACPI_LED_BLINK
;
5156 queue_work(tpacpi_wq
, &data
->work
);
5161 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
5165 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
5166 struct tpacpi_led_classdev
, led_classdev
);
5168 rc
= led_get_status(data
->led
);
5170 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
5171 rc
= LED_OFF
; /* no error handling in led class :( */
5178 static void led_exit(void)
5182 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5183 if (tpacpi_leds
[i
].led_classdev
.name
)
5184 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
5190 static int __init
tpacpi_init_led(unsigned int led
)
5194 tpacpi_leds
[led
].led
= led
;
5196 /* LEDs with no name don't get registered */
5197 if (!tpacpi_led_names
[led
])
5200 tpacpi_leds
[led
].led_classdev
.brightness_set
= &led_sysfs_set
;
5201 tpacpi_leds
[led
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
5202 if (led_supported
== TPACPI_LED_570
)
5203 tpacpi_leds
[led
].led_classdev
.brightness_get
=
5206 tpacpi_leds
[led
].led_classdev
.name
= tpacpi_led_names
[led
];
5208 INIT_WORK(&tpacpi_leds
[led
].work
, led_set_status_worker
);
5210 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
5211 &tpacpi_leds
[led
].led_classdev
);
5213 tpacpi_leds
[led
].led_classdev
.name
= NULL
;
5218 static const struct tpacpi_quirk led_useful_qtable
[] __initconst
= {
5219 TPACPI_Q_IBM('1', 'E', 0x009f), /* A30 */
5220 TPACPI_Q_IBM('1', 'N', 0x009f), /* A31 */
5221 TPACPI_Q_IBM('1', 'G', 0x009f), /* A31 */
5223 TPACPI_Q_IBM('1', 'I', 0x0097), /* T30 */
5224 TPACPI_Q_IBM('1', 'R', 0x0097), /* T40, T41, T42, R50, R51 */
5225 TPACPI_Q_IBM('7', '0', 0x0097), /* T43, R52 */
5226 TPACPI_Q_IBM('1', 'Y', 0x0097), /* T43 */
5227 TPACPI_Q_IBM('1', 'W', 0x0097), /* R50e */
5228 TPACPI_Q_IBM('1', 'V', 0x0097), /* R51 */
5229 TPACPI_Q_IBM('7', '8', 0x0097), /* R51e */
5230 TPACPI_Q_IBM('7', '6', 0x0097), /* R52 */
5232 TPACPI_Q_IBM('1', 'K', 0x00bf), /* X30 */
5233 TPACPI_Q_IBM('1', 'Q', 0x00bf), /* X31, X32 */
5234 TPACPI_Q_IBM('1', 'U', 0x00bf), /* X40 */
5235 TPACPI_Q_IBM('7', '4', 0x00bf), /* X41 */
5236 TPACPI_Q_IBM('7', '5', 0x00bf), /* X41t */
5238 TPACPI_Q_IBM('7', '9', 0x1f97), /* T60 (1) */
5239 TPACPI_Q_IBM('7', '7', 0x1f97), /* Z60* (1) */
5240 TPACPI_Q_IBM('7', 'F', 0x1f97), /* Z61* (1) */
5241 TPACPI_Q_IBM('7', 'B', 0x1fb7), /* X60 (1) */
5243 /* (1) - may have excess leds enabled on MSB */
5245 /* Defaults (order matters, keep last, don't reorder!) */
5247 .vendor
= PCI_VENDOR_ID_LENOVO
,
5248 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5251 { /* IBM ThinkPads with no EC version string */
5252 .vendor
= PCI_VENDOR_ID_IBM
,
5253 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_UNKNOWN
,
5256 { /* IBM ThinkPads with EC version string */
5257 .vendor
= PCI_VENDOR_ID_IBM
,
5258 .bios
= TPACPI_MATCH_ANY
, .ec
= TPACPI_MATCH_ANY
,
5263 #undef TPACPI_LEDQ_IBM
5264 #undef TPACPI_LEDQ_LNV
5266 static int __init
led_init(struct ibm_init_struct
*iibm
)
5270 unsigned long useful_leds
;
5272 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
5274 TPACPI_ACPIHANDLE_INIT(led
);
5277 /* led not supported on R30, R31 */
5278 led_supported
= TPACPI_LED_NONE
;
5279 else if (strlencmp(led_path
, "SLED") == 0)
5281 led_supported
= TPACPI_LED_570
;
5282 else if (strlencmp(led_path
, "SYSL") == 0)
5283 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5284 led_supported
= TPACPI_LED_OLD
;
5287 led_supported
= TPACPI_LED_NEW
;
5289 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
5290 str_supported(led_supported
), led_supported
);
5292 if (led_supported
== TPACPI_LED_NONE
)
5295 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
5298 printk(TPACPI_ERR
"Out of memory for LED data\n");
5302 useful_leds
= tpacpi_check_quirks(led_useful_qtable
,
5303 ARRAY_SIZE(led_useful_qtable
));
5305 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
5306 if (!tpacpi_is_led_restricted(i
) &&
5307 test_bit(i
, &useful_leds
)) {
5308 rc
= tpacpi_init_led(i
);
5316 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5317 printk(TPACPI_NOTICE
5318 "warning: userspace override of important "
5319 "firmware LEDs is enabled\n");
5324 #define str_led_status(s) \
5325 ((s) == TPACPI_LED_OFF ? "off" : \
5326 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5328 static int led_read(char *p
)
5332 if (!led_supported
) {
5333 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5336 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
5338 if (led_supported
== TPACPI_LED_570
) {
5341 for (i
= 0; i
< 8; i
++) {
5342 status
= led_get_status(i
);
5345 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
5346 i
, str_led_status(status
));
5350 len
+= sprintf(p
+ len
, "commands:\t"
5351 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5356 static int led_write(char *buf
)
5360 enum led_status_t s
;
5365 while ((cmd
= next_cmd(&buf
))) {
5366 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 15)
5369 if (strstr(cmd
, "off")) {
5371 } else if (strstr(cmd
, "on")) {
5373 } else if (strstr(cmd
, "blink")) {
5374 s
= TPACPI_LED_BLINK
;
5379 rc
= led_set_status(led
, s
);
5387 static struct ibm_struct led_driver_data
= {
5394 /*************************************************************************
5398 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
5400 #define TPACPI_BEEP_Q1 0x0001
5402 static const struct tpacpi_quirk beep_quirk_table
[] __initconst
= {
5403 TPACPI_Q_IBM('I', 'M', TPACPI_BEEP_Q1
), /* 570 */
5404 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1
), /* 570E - unverified */
5407 static int __init
beep_init(struct ibm_init_struct
*iibm
)
5409 unsigned long quirks
;
5411 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
5413 TPACPI_ACPIHANDLE_INIT(beep
);
5415 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
5416 str_supported(beep_handle
!= NULL
));
5418 quirks
= tpacpi_check_quirks(beep_quirk_table
,
5419 ARRAY_SIZE(beep_quirk_table
));
5421 tp_features
.beep_needs_two_args
= !!(quirks
& TPACPI_BEEP_Q1
);
5423 return (beep_handle
)? 0 : 1;
5426 static int beep_read(char *p
)
5431 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5433 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
5434 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
5440 static int beep_write(char *buf
)
5448 while ((cmd
= next_cmd(&buf
))) {
5449 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
5450 beep_cmd
>= 0 && beep_cmd
<= 17) {
5454 if (tp_features
.beep_needs_two_args
) {
5455 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd",
5459 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vd",
5468 static struct ibm_struct beep_driver_data
= {
5471 .write
= beep_write
,
5474 /*************************************************************************
5478 enum thermal_access_mode
{
5479 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
5480 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
5481 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
5482 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
5483 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
5486 enum { /* TPACPI_THERMAL_TPEC_* */
5487 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
5488 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
5489 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
5491 TPACPI_THERMAL_SENSOR_NA
= -128000, /* Sensor not available */
5495 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
5496 struct ibm_thermal_sensors_struct
{
5497 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
5500 static enum thermal_access_mode thermal_read_mode
;
5502 /* idx is zero-based */
5503 static int thermal_get_sensor(int idx
, s32
*value
)
5509 t
= TP_EC_THERMAL_TMP0
;
5511 switch (thermal_read_mode
) {
5512 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5513 case TPACPI_THERMAL_TPEC_16
:
5514 if (idx
>= 8 && idx
<= 15) {
5515 t
= TP_EC_THERMAL_TMP8
;
5520 case TPACPI_THERMAL_TPEC_8
:
5522 if (!acpi_ec_read(t
+ idx
, &tmp
))
5524 *value
= tmp
* 1000;
5529 case TPACPI_THERMAL_ACPI_UPDT
:
5531 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5532 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
5534 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5536 *value
= (t
- 2732) * 100;
5541 case TPACPI_THERMAL_ACPI_TMP07
:
5543 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
5544 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
5546 if (t
> 127 || t
< -127)
5547 t
= TP_EC_THERMAL_TMP_NA
;
5553 case TPACPI_THERMAL_NONE
:
5561 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
5572 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
5575 for (i
= 0 ; i
< n
; i
++) {
5576 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
5584 static void thermal_dump_all_sensors(void)
5587 struct ibm_thermal_sensors_struct t
;
5589 n
= thermal_get_sensors(&t
);
5593 printk(TPACPI_NOTICE
5594 "temperatures (Celsius):");
5596 for (i
= 0; i
< n
; i
++) {
5597 if (t
.temp
[i
] != TPACPI_THERMAL_SENSOR_NA
)
5598 printk(KERN_CONT
" %d", (int)(t
.temp
[i
] / 1000));
5600 printk(KERN_CONT
" N/A");
5603 printk(KERN_CONT
"\n");
5606 /* sysfs temp##_input -------------------------------------------------- */
5608 static ssize_t
thermal_temp_input_show(struct device
*dev
,
5609 struct device_attribute
*attr
,
5612 struct sensor_device_attribute
*sensor_attr
=
5613 to_sensor_dev_attr(attr
);
5614 int idx
= sensor_attr
->index
;
5618 res
= thermal_get_sensor(idx
, &value
);
5621 if (value
== TPACPI_THERMAL_SENSOR_NA
)
5624 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
5627 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5628 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5629 thermal_temp_input_show, NULL, _idxB)
5631 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
5632 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5633 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5634 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5635 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5636 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5637 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5638 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5639 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5640 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5641 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5642 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5643 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5644 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5645 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5646 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5647 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5650 #define THERMAL_ATTRS(X) \
5651 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5653 static struct attribute
*thermal_temp_input_attr
[] = {
5673 static const struct attribute_group thermal_temp_input16_group
= {
5674 .attrs
= thermal_temp_input_attr
5677 static const struct attribute_group thermal_temp_input8_group
= {
5678 .attrs
= &thermal_temp_input_attr
[8]
5681 #undef THERMAL_SENSOR_ATTR_TEMP
5682 #undef THERMAL_ATTRS
5684 /* --------------------------------------------------------------------- */
5686 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
5693 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
5695 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
5697 if (thinkpad_id
.ec_model
) {
5699 * Direct EC access mode: sensors at registers
5700 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5701 * non-implemented, thermal sensors return 0x80 when
5706 for (i
= 0; i
< 8; i
++) {
5707 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
5713 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
5721 /* This is sheer paranoia, but we handle it anyway */
5724 "ThinkPad ACPI EC access misbehaving, "
5725 "falling back to ACPI TMPx access "
5727 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5730 "ThinkPad ACPI EC access misbehaving, "
5731 "disabling thermal sensors access\n");
5732 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5737 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
5739 } else if (acpi_tmp7
) {
5740 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
5741 /* 600e/x, 770e, 770x */
5742 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
5744 /* Standard ACPI TMPx access, max 8 sensors */
5745 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
5748 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5749 thermal_read_mode
= TPACPI_THERMAL_NONE
;
5752 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
5753 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
5756 switch (thermal_read_mode
) {
5757 case TPACPI_THERMAL_TPEC_16
:
5758 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5759 &thermal_temp_input16_group
);
5763 case TPACPI_THERMAL_TPEC_8
:
5764 case TPACPI_THERMAL_ACPI_TMP07
:
5765 case TPACPI_THERMAL_ACPI_UPDT
:
5766 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5767 &thermal_temp_input8_group
);
5771 case TPACPI_THERMAL_NONE
:
5779 static void thermal_exit(void)
5781 switch (thermal_read_mode
) {
5782 case TPACPI_THERMAL_TPEC_16
:
5783 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5784 &thermal_temp_input16_group
);
5786 case TPACPI_THERMAL_TPEC_8
:
5787 case TPACPI_THERMAL_ACPI_TMP07
:
5788 case TPACPI_THERMAL_ACPI_UPDT
:
5789 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5790 &thermal_temp_input8_group
);
5792 case TPACPI_THERMAL_NONE
:
5798 static int thermal_read(char *p
)
5802 struct ibm_thermal_sensors_struct t
;
5804 n
= thermal_get_sensors(&t
);
5805 if (unlikely(n
< 0))
5808 len
+= sprintf(p
+ len
, "temperatures:\t");
5811 for (i
= 0; i
< (n
- 1); i
++)
5812 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
5813 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
5815 len
+= sprintf(p
+ len
, "not supported\n");
5820 static struct ibm_struct thermal_driver_data
= {
5822 .read
= thermal_read
,
5823 .exit
= thermal_exit
,
5826 /*************************************************************************
5830 static u8 ecdump_regs
[256];
5832 static int ecdump_read(char *p
)
5838 len
+= sprintf(p
+ len
, "EC "
5839 " +00 +01 +02 +03 +04 +05 +06 +07"
5840 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5841 for (i
= 0; i
< 256; i
+= 16) {
5842 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
5843 for (j
= 0; j
< 16; j
++) {
5844 if (!acpi_ec_read(i
+ j
, &v
))
5846 if (v
!= ecdump_regs
[i
+ j
])
5847 len
+= sprintf(p
+ len
, " *%02x", v
);
5849 len
+= sprintf(p
+ len
, " %02x", v
);
5850 ecdump_regs
[i
+ j
] = v
;
5852 len
+= sprintf(p
+ len
, "\n");
5857 /* These are way too dangerous to advertise openly... */
5859 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
5860 " (<offset> is 00-ff, <value> is 00-ff)\n");
5861 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
5862 " (<offset> is 00-ff, <value> is 0-255)\n");
5867 static int ecdump_write(char *buf
)
5872 while ((cmd
= next_cmd(&buf
))) {
5873 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
5875 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
5879 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
5880 if (!acpi_ec_write(i
, v
))
5889 static struct ibm_struct ecdump_driver_data
= {
5891 .read
= ecdump_read
,
5892 .write
= ecdump_write
,
5893 .flags
.experimental
= 1,
5896 /*************************************************************************
5897 * Backlight/brightness subdriver
5900 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5903 * ThinkPads can read brightness from two places: EC HBRV (0x31), or
5904 * CMOS NVRAM byte 0x5E, bits 0-3.
5906 * EC HBRV (0x31) has the following layout
5907 * Bit 7: unknown function
5908 * Bit 6: unknown function
5909 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5910 * Bit 4: must be set to zero to avoid problems
5911 * Bit 3-0: backlight brightness level
5913 * brightness_get_raw returns status data in the HBRV layout
5915 * WARNING: The X61 has been verified to use HBRV for something else, so
5916 * this should be used _only_ on IBM ThinkPads, and maybe with some careful
5917 * testing on the very early *60 Lenovo models...
5921 TP_EC_BACKLIGHT
= 0x31,
5923 /* TP_EC_BACKLIGHT bitmasks */
5924 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
5925 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
5926 TP_EC_BACKLIGHT_MAPSW
= 0x20,
5929 enum tpacpi_brightness_access_mode
{
5930 TPACPI_BRGHT_MODE_AUTO
= 0, /* Not implemented yet */
5931 TPACPI_BRGHT_MODE_EC
, /* EC control */
5932 TPACPI_BRGHT_MODE_UCMS_STEP
, /* UCMS step-based control */
5933 TPACPI_BRGHT_MODE_ECNVRAM
, /* EC control w/ NVRAM store */
5934 TPACPI_BRGHT_MODE_MAX
5937 static struct backlight_device
*ibm_backlight_device
;
5939 static enum tpacpi_brightness_access_mode brightness_mode
=
5940 TPACPI_BRGHT_MODE_MAX
;
5942 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
5944 static struct mutex brightness_mutex
;
5946 /* NVRAM brightness access,
5947 * call with brightness_mutex held! */
5948 static unsigned int tpacpi_brightness_nvram_get(void)
5952 lnvram
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
5953 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5954 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
5955 lnvram
&= (tp_features
.bright_16levels
) ? 0x0f : 0x07;
5960 static void tpacpi_brightness_checkpoint_nvram(void)
5965 if (brightness_mode
!= TPACPI_BRGHT_MODE_ECNVRAM
)
5968 vdbg_printk(TPACPI_DBG_BRGHT
,
5969 "trying to checkpoint backlight level to NVRAM...\n");
5971 if (mutex_lock_killable(&brightness_mutex
) < 0)
5974 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
5976 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
5977 b_nvram
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
5979 if (lec
!= ((b_nvram
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
5980 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
)) {
5981 /* NVRAM needs update */
5982 b_nvram
&= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS
<<
5983 TP_NVRAM_POS_LEVEL_BRIGHTNESS
);
5985 nvram_write_byte(b_nvram
, TP_NVRAM_ADDR_BRIGHTNESS
);
5986 dbg_printk(TPACPI_DBG_BRGHT
,
5987 "updated NVRAM backlight level to %u (0x%02x)\n",
5988 (unsigned int) lec
, (unsigned int) b_nvram
);
5990 vdbg_printk(TPACPI_DBG_BRGHT
,
5991 "NVRAM backlight level already is %u (0x%02x)\n",
5992 (unsigned int) lec
, (unsigned int) b_nvram
);
5995 mutex_unlock(&brightness_mutex
);
5999 /* call with brightness_mutex held! */
6000 static int tpacpi_brightness_get_raw(int *status
)
6004 switch (brightness_mode
) {
6005 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6006 *status
= tpacpi_brightness_nvram_get();
6008 case TPACPI_BRGHT_MODE_EC
:
6009 case TPACPI_BRGHT_MODE_ECNVRAM
:
6010 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6019 /* call with brightness_mutex held! */
6020 /* do NOT call with illegal backlight level value */
6021 static int tpacpi_brightness_set_ec(unsigned int value
)
6025 if (unlikely(!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
)))
6028 if (unlikely(!acpi_ec_write(TP_EC_BACKLIGHT
,
6029 (lec
& TP_EC_BACKLIGHT_CMDMSK
) |
6030 (value
& TP_EC_BACKLIGHT_LVLMSK
))))
6036 /* call with brightness_mutex held! */
6037 static int tpacpi_brightness_set_ucmsstep(unsigned int value
)
6040 unsigned int current_value
, i
;
6042 current_value
= tpacpi_brightness_nvram_get();
6044 if (value
== current_value
)
6047 cmos_cmd
= (value
> current_value
) ?
6048 TP_CMOS_BRIGHTNESS_UP
:
6049 TP_CMOS_BRIGHTNESS_DOWN
;
6050 inc
= (value
> current_value
) ? 1 : -1;
6052 for (i
= current_value
; i
!= value
; i
+= inc
)
6053 if (issue_thinkpad_cmos_command(cmos_cmd
))
6059 /* May return EINTR which can always be mapped to ERESTARTSYS */
6060 static int brightness_set(unsigned int value
)
6064 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
6068 vdbg_printk(TPACPI_DBG_BRGHT
,
6069 "set backlight level to %d\n", value
);
6071 res
= mutex_lock_killable(&brightness_mutex
);
6075 switch (brightness_mode
) {
6076 case TPACPI_BRGHT_MODE_EC
:
6077 case TPACPI_BRGHT_MODE_ECNVRAM
:
6078 res
= tpacpi_brightness_set_ec(value
);
6080 case TPACPI_BRGHT_MODE_UCMS_STEP
:
6081 res
= tpacpi_brightness_set_ucmsstep(value
);
6087 mutex_unlock(&brightness_mutex
);
6091 /* sysfs backlight class ----------------------------------------------- */
6093 static int brightness_update_status(struct backlight_device
*bd
)
6095 unsigned int level
=
6096 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
6097 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
6098 bd
->props
.brightness
: 0;
6100 dbg_printk(TPACPI_DBG_BRGHT
,
6101 "backlight: attempt to set level to %d\n",
6104 /* it is the backlight class's job (caller) to handle
6105 * EINTR and other errors properly */
6106 return brightness_set(level
);
6109 static int brightness_get(struct backlight_device
*bd
)
6113 res
= mutex_lock_killable(&brightness_mutex
);
6117 res
= tpacpi_brightness_get_raw(&status
);
6119 mutex_unlock(&brightness_mutex
);
6124 return status
& TP_EC_BACKLIGHT_LVLMSK
;
6127 static void tpacpi_brightness_notify_change(void)
6129 backlight_force_update(ibm_backlight_device
,
6130 BACKLIGHT_UPDATE_HOTKEY
);
6133 static struct backlight_ops ibm_backlight_data
= {
6134 .get_brightness
= brightness_get
,
6135 .update_status
= brightness_update_status
,
6138 /* --------------------------------------------------------------------- */
6141 * These are only useful for models that have only one possibility
6142 * of GPU. If the BIOS model handles both ATI and Intel, don't use
6145 #define TPACPI_BRGHT_Q_NOEC 0x0001 /* Must NOT use EC HBRV */
6146 #define TPACPI_BRGHT_Q_EC 0x0002 /* Should or must use EC HBRV */
6147 #define TPACPI_BRGHT_Q_ASK 0x8000 /* Ask for user report */
6149 static const struct tpacpi_quirk brightness_quirk_table
[] __initconst
= {
6150 /* Models with ATI GPUs known to require ECNVRAM mode */
6151 TPACPI_Q_IBM('1', 'Y', TPACPI_BRGHT_Q_EC
), /* T43/p ATI */
6153 /* Models with ATI GPUs that can use ECNVRAM */
6154 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC
), /* R50,51 T40-42 */
6155 TPACPI_Q_IBM('1', 'Q', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6156 TPACPI_Q_IBM('7', '6', TPACPI_BRGHT_Q_EC
), /* R52 */
6157 TPACPI_Q_IBM('7', '8', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6159 /* Models with Intel Extreme Graphics 2 */
6160 TPACPI_Q_IBM('1', 'U', TPACPI_BRGHT_Q_NOEC
), /* X40 */
6161 TPACPI_Q_IBM('1', 'V', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6162 TPACPI_Q_IBM('1', 'W', TPACPI_BRGHT_Q_ASK
|TPACPI_BRGHT_Q_EC
),
6164 /* Models with Intel GMA900 */
6165 TPACPI_Q_IBM('7', '0', TPACPI_BRGHT_Q_NOEC
), /* T43, R52 */
6166 TPACPI_Q_IBM('7', '4', TPACPI_BRGHT_Q_NOEC
), /* X41 */
6167 TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC
), /* X41 Tablet */
6170 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
6173 unsigned long quirks
;
6175 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
6177 mutex_init(&brightness_mutex
);
6179 quirks
= tpacpi_check_quirks(brightness_quirk_table
,
6180 ARRAY_SIZE(brightness_quirk_table
));
6183 * We always attempt to detect acpi support, so as to switch
6184 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
6185 * going to publish a backlight interface
6187 b
= tpacpi_check_std_acpi_brightness_support();
6190 if (acpi_video_backlight_support()) {
6191 if (brightness_enable
> 1) {
6192 printk(TPACPI_NOTICE
6193 "Standard ACPI backlight interface "
6194 "available, not loading native one.\n");
6196 } else if (brightness_enable
== 1) {
6197 printk(TPACPI_NOTICE
6198 "Backlight control force enabled, even if standard "
6199 "ACPI backlight interface is available\n");
6202 if (brightness_enable
> 1) {
6203 printk(TPACPI_NOTICE
6204 "Standard ACPI backlight interface not "
6205 "available, thinkpad_acpi native "
6206 "brightness control enabled\n");
6211 if (!brightness_enable
) {
6212 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6213 "brightness support disabled by "
6214 "module parameter\n");
6220 "Unsupported brightness interface, "
6221 "please contact %s\n", TPACPI_MAIL
);
6225 tp_features
.bright_16levels
= 1;
6228 * Check for module parameter bogosity, note that we
6229 * init brightness_mode to TPACPI_BRGHT_MODE_MAX in order to be
6230 * able to detect "unspecified"
6232 if (brightness_mode
> TPACPI_BRGHT_MODE_MAX
)
6235 /* TPACPI_BRGHT_MODE_AUTO not implemented yet, just use default */
6236 if (brightness_mode
== TPACPI_BRGHT_MODE_AUTO
||
6237 brightness_mode
== TPACPI_BRGHT_MODE_MAX
) {
6238 if (quirks
& TPACPI_BRGHT_Q_EC
)
6239 brightness_mode
= TPACPI_BRGHT_MODE_ECNVRAM
;
6241 brightness_mode
= TPACPI_BRGHT_MODE_UCMS_STEP
;
6243 dbg_printk(TPACPI_DBG_BRGHT
,
6244 "driver auto-selected brightness_mode=%d\n",
6249 if (thinkpad_id
.vendor
!= PCI_VENDOR_ID_IBM
&&
6250 (brightness_mode
== TPACPI_BRGHT_MODE_ECNVRAM
||
6251 brightness_mode
== TPACPI_BRGHT_MODE_EC
))
6254 if (tpacpi_brightness_get_raw(&b
) < 0)
6257 if (tp_features
.bright_16levels
)
6259 "detected a 16-level brightness capable ThinkPad\n");
6261 ibm_backlight_device
= backlight_device_register(
6262 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
6263 &ibm_backlight_data
);
6264 if (IS_ERR(ibm_backlight_device
)) {
6265 int rc
= PTR_ERR(ibm_backlight_device
);
6266 ibm_backlight_device
= NULL
;
6267 printk(TPACPI_ERR
"Could not register backlight device\n");
6270 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6271 "brightness is supported\n");
6273 if (quirks
& TPACPI_BRGHT_Q_ASK
) {
6274 printk(TPACPI_NOTICE
6275 "brightness: will use unverified default: "
6276 "brightness_mode=%d\n", brightness_mode
);
6277 printk(TPACPI_NOTICE
6278 "brightness: please report to %s whether it works well "
6279 "or not on your ThinkPad\n", TPACPI_MAIL
);
6282 ibm_backlight_device
->props
.max_brightness
=
6283 (tp_features
.bright_16levels
)? 15 : 7;
6284 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
6285 backlight_update_status(ibm_backlight_device
);
6287 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_BRGHT
,
6288 "brightness: registering brightness hotkeys "
6289 "as change notification\n");
6290 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6291 | TP_ACPI_HKEY_BRGHTUP_MASK
6292 | TP_ACPI_HKEY_BRGHTDWN_MASK
);;
6296 static void brightness_suspend(pm_message_t state
)
6298 tpacpi_brightness_checkpoint_nvram();
6301 static void brightness_shutdown(void)
6303 tpacpi_brightness_checkpoint_nvram();
6306 static void brightness_exit(void)
6308 if (ibm_backlight_device
) {
6309 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_BRGHT
,
6310 "calling backlight_device_unregister()\n");
6311 backlight_device_unregister(ibm_backlight_device
);
6314 tpacpi_brightness_checkpoint_nvram();
6317 static int brightness_read(char *p
)
6322 level
= brightness_get(NULL
);
6324 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
6326 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
6327 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
6328 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
6329 " (<level> is 0-%d)\n",
6330 (tp_features
.bright_16levels
) ? 15 : 7);
6336 static int brightness_write(char *buf
)
6341 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
6343 level
= brightness_get(NULL
);
6347 while ((cmd
= next_cmd(&buf
))) {
6348 if (strlencmp(cmd
, "up") == 0) {
6349 if (level
< max_level
)
6351 } else if (strlencmp(cmd
, "down") == 0) {
6354 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
6355 level
>= 0 && level
<= max_level
) {
6361 tpacpi_disclose_usertask("procfs brightness",
6362 "set level to %d\n", level
);
6365 * Now we know what the final level should be, so we try to set it.
6366 * Doing it this way makes the syscall restartable in case of EINTR
6368 rc
= brightness_set(level
);
6369 if (!rc
&& ibm_backlight_device
)
6370 backlight_force_update(ibm_backlight_device
,
6371 BACKLIGHT_UPDATE_SYSFS
);
6372 return (rc
== -EINTR
)? -ERESTARTSYS
: rc
;
6375 static struct ibm_struct brightness_driver_data
= {
6376 .name
= "brightness",
6377 .read
= brightness_read
,
6378 .write
= brightness_write
,
6379 .exit
= brightness_exit
,
6380 .suspend
= brightness_suspend
,
6381 .shutdown
= brightness_shutdown
,
6384 /*************************************************************************
6388 static int volume_offset
= 0x30;
6390 static int volume_read(char *p
)
6395 if (!acpi_ec_read(volume_offset
, &level
)) {
6396 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
6398 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
6399 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
6400 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
6401 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
6402 " (<level> is 0-15)\n");
6408 static int volume_write(char *buf
)
6410 int cmos_cmd
, inc
, i
;
6412 int new_level
, new_mute
;
6415 while ((cmd
= next_cmd(&buf
))) {
6416 if (!acpi_ec_read(volume_offset
, &level
))
6418 new_mute
= mute
= level
& 0x40;
6419 new_level
= level
= level
& 0xf;
6421 if (strlencmp(cmd
, "up") == 0) {
6425 new_level
= level
== 15 ? 15 : level
+ 1;
6426 } else if (strlencmp(cmd
, "down") == 0) {
6430 new_level
= level
== 0 ? 0 : level
- 1;
6431 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
6432 new_level
>= 0 && new_level
<= 15) {
6434 } else if (strlencmp(cmd
, "mute") == 0) {
6439 if (new_level
!= level
) {
6440 /* mute doesn't change */
6442 cmos_cmd
= (new_level
> level
) ?
6443 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
6444 inc
= new_level
> level
? 1 : -1;
6446 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
6447 !acpi_ec_write(volume_offset
, level
)))
6450 for (i
= level
; i
!= new_level
; i
+= inc
)
6451 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
6452 !acpi_ec_write(volume_offset
, i
+ inc
))
6456 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
6457 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
6462 if (new_mute
!= mute
) {
6463 /* level doesn't change */
6465 cmos_cmd
= (new_mute
) ?
6466 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
6468 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
6469 !acpi_ec_write(volume_offset
, level
+ new_mute
))
6477 static struct ibm_struct volume_driver_data
= {
6479 .read
= volume_read
,
6480 .write
= volume_write
,
6483 /*************************************************************************
6490 * TPACPI_FAN_RD_ACPI_GFAN:
6491 * ACPI GFAN method: returns fan level
6493 * see TPACPI_FAN_WR_ACPI_SFAN
6494 * EC 0x2f (HFSP) not available if GFAN exists
6496 * TPACPI_FAN_WR_ACPI_SFAN:
6497 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
6499 * EC 0x2f (HFSP) might be available *for reading*, but do not use
6502 * TPACPI_FAN_WR_TPEC:
6503 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
6504 * Supported on almost all ThinkPads
6506 * Fan speed changes of any sort (including those caused by the
6507 * disengaged mode) are usually done slowly by the firmware as the
6508 * maximum ammount of fan duty cycle change per second seems to be
6511 * Reading is not available if GFAN exists.
6512 * Writing is not available if SFAN exists.
6515 * 7 automatic mode engaged;
6516 * (default operation mode of the ThinkPad)
6517 * fan level is ignored in this mode.
6518 * 6 full speed mode (takes precedence over bit 7);
6519 * not available on all thinkpads. May disable
6520 * the tachometer while the fan controller ramps up
6521 * the speed (which can take up to a few *minutes*).
6522 * Speeds up fan to 100% duty-cycle, which is far above
6523 * the standard RPM levels. It is not impossible that
6524 * it could cause hardware damage.
6525 * 5-3 unused in some models. Extra bits for fan level
6526 * in others, but still useless as all values above
6527 * 7 map to the same speed as level 7 in these models.
6528 * 2-0 fan level (0..7 usually)
6530 * 0x07 = max (set when temperatures critical)
6531 * Some ThinkPads may have other levels, see
6532 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
6534 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
6535 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
6536 * does so, its initial value is meaningless (0x07).
6538 * For firmware bugs, refer to:
6539 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6543 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
6544 * Main fan tachometer reading (in RPM)
6546 * This register is present on all ThinkPads with a new-style EC, and
6547 * it is known not to be present on the A21m/e, and T22, as there is
6548 * something else in offset 0x84 according to the ACPI DSDT. Other
6549 * ThinkPads from this same time period (and earlier) probably lack the
6550 * tachometer as well.
6552 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
6553 * was never fixed by IBM to report the EC firmware version string
6554 * probably support the tachometer (like the early X models), so
6555 * detecting it is quite hard. We need more data to know for sure.
6557 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
6560 * FIRMWARE BUG: may go stale while the EC is switching to full speed
6563 * For firmware bugs, refer to:
6564 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
6568 * ThinkPad EC register 0x31 bit 0 (only on select models)
6570 * When bit 0 of EC register 0x31 is zero, the tachometer registers
6571 * show the speed of the main fan. When bit 0 of EC register 0x31
6572 * is one, the tachometer registers show the speed of the auxiliary
6575 * Fan control seems to affect both fans, regardless of the state
6578 * So far, only the firmware for the X60/X61 non-tablet versions
6579 * seem to support this (firmware TP-7M).
6581 * TPACPI_FAN_WR_ACPI_FANS:
6582 * ThinkPad X31, X40, X41. Not available in the X60.
6584 * FANS ACPI handle: takes three arguments: low speed, medium speed,
6585 * high speed. ACPI DSDT seems to map these three speeds to levels
6586 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
6587 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
6589 * The speeds are stored on handles
6590 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
6592 * There are three default speed sets, acessible as handles:
6593 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
6595 * ACPI DSDT switches which set is in use depending on various
6598 * TPACPI_FAN_WR_TPEC is also available and should be used to
6599 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
6600 * but the ACPI tables just mention level 7.
6603 enum { /* Fan control constants */
6604 fan_status_offset
= 0x2f, /* EC register 0x2f */
6605 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
6606 * 0x84 must be read before 0x85 */
6607 fan_select_offset
= 0x31, /* EC register 0x31 (Firmware 7M)
6608 bit 0 selects which fan is active */
6610 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
6611 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
6613 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
6616 enum fan_status_access_mode
{
6617 TPACPI_FAN_NONE
= 0, /* No fan status or control */
6618 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
6619 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
6622 enum fan_control_access_mode
{
6623 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
6624 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
6625 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
6626 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
6629 enum fan_control_commands
{
6630 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
6631 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
6632 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
6633 * and also watchdog cmd */
6636 static int fan_control_allowed
;
6638 static enum fan_status_access_mode fan_status_access_mode
;
6639 static enum fan_control_access_mode fan_control_access_mode
;
6640 static enum fan_control_commands fan_control_commands
;
6642 static u8 fan_control_initial_status
;
6643 static u8 fan_control_desired_level
;
6644 static u8 fan_control_resume_level
;
6645 static int fan_watchdog_maxinterval
;
6647 static struct mutex fan_mutex
;
6649 static void fan_watchdog_fire(struct work_struct
*ignored
);
6650 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
6652 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
6653 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
6654 "\\FSPD", /* 600e/x, 770e, 770x */
6656 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
6657 "JFNS", /* 770x-JL */
6661 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
6662 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
6663 * be in auto mode (0x80).
6665 * This is corrected by any write to HFSP either by the driver, or
6668 * We assume 0x07 really means auto mode while this quirk is active,
6669 * as this is far more likely than the ThinkPad being in level 7,
6670 * which is only used by the firmware during thermal emergencies.
6672 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
6673 * TP-70 (T43, R52), which are known to be buggy.
6676 static void fan_quirk1_setup(void)
6678 if (fan_control_initial_status
== 0x07) {
6679 printk(TPACPI_NOTICE
6680 "fan_init: initial fan status is unknown, "
6681 "assuming it is in auto mode\n");
6682 tp_features
.fan_ctrl_status_undef
= 1;
6686 static void fan_quirk1_handle(u8
*fan_status
)
6688 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6689 if (*fan_status
!= fan_control_initial_status
) {
6690 /* something changed the HFSP regisnter since
6691 * driver init time, so it is not undefined
6693 tp_features
.fan_ctrl_status_undef
= 0;
6695 /* Return most likely status. In fact, it
6696 * might be the only possible status */
6697 *fan_status
= TP_EC_FAN_AUTO
;
6702 /* Select main fan on X60/X61, NOOP on others */
6703 static bool fan_select_fan1(void)
6705 if (tp_features
.second_fan
) {
6708 if (ec_read(fan_select_offset
, &val
) < 0)
6711 if (ec_write(fan_select_offset
, val
) < 0)
6717 /* Select secondary fan on X60/X61 */
6718 static bool fan_select_fan2(void)
6722 if (!tp_features
.second_fan
)
6725 if (ec_read(fan_select_offset
, &val
) < 0)
6728 if (ec_write(fan_select_offset
, val
) < 0)
6735 * Call with fan_mutex held
6737 static void fan_update_desired_level(u8 status
)
6740 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
6742 fan_control_desired_level
= 7;
6744 fan_control_desired_level
= status
;
6748 static int fan_get_status(u8
*status
)
6753 * Add TPACPI_FAN_RD_ACPI_FANS ? */
6755 switch (fan_status_access_mode
) {
6756 case TPACPI_FAN_RD_ACPI_GFAN
:
6757 /* 570, 600e/x, 770e, 770x */
6759 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
6767 case TPACPI_FAN_RD_TPEC
:
6768 /* all except 570, 600e/x, 770e, 770x */
6769 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
6772 if (likely(status
)) {
6774 fan_quirk1_handle(status
);
6786 static int fan_get_status_safe(u8
*status
)
6791 if (mutex_lock_killable(&fan_mutex
))
6792 return -ERESTARTSYS
;
6793 rc
= fan_get_status(&s
);
6795 fan_update_desired_level(s
);
6796 mutex_unlock(&fan_mutex
);
6804 static int fan_get_speed(unsigned int *speed
)
6808 switch (fan_status_access_mode
) {
6809 case TPACPI_FAN_RD_TPEC
:
6810 /* all except 570, 600e/x, 770e, 770x */
6811 if (unlikely(!fan_select_fan1()))
6813 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
6814 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
6818 *speed
= (hi
<< 8) | lo
;
6829 static int fan2_get_speed(unsigned int *speed
)
6834 switch (fan_status_access_mode
) {
6835 case TPACPI_FAN_RD_TPEC
:
6836 /* all except 570, 600e/x, 770e, 770x */
6837 if (unlikely(!fan_select_fan2()))
6839 rc
= !acpi_ec_read(fan_rpm_offset
, &lo
) ||
6840 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
);
6841 fan_select_fan1(); /* play it safe */
6846 *speed
= (hi
<< 8) | lo
;
6857 static int fan_set_level(int level
)
6859 if (!fan_control_allowed
)
6862 switch (fan_control_access_mode
) {
6863 case TPACPI_FAN_WR_ACPI_SFAN
:
6864 if (level
>= 0 && level
<= 7) {
6865 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
6871 case TPACPI_FAN_WR_ACPI_FANS
:
6872 case TPACPI_FAN_WR_TPEC
:
6873 if (!(level
& TP_EC_FAN_AUTO
) &&
6874 !(level
& TP_EC_FAN_FULLSPEED
) &&
6875 ((level
< 0) || (level
> 7)))
6878 /* safety net should the EC not support AUTO
6879 * or FULLSPEED mode bits and just ignore them */
6880 if (level
& TP_EC_FAN_FULLSPEED
)
6881 level
|= 7; /* safety min speed 7 */
6882 else if (level
& TP_EC_FAN_AUTO
)
6883 level
|= 4; /* safety min speed 4 */
6885 if (!acpi_ec_write(fan_status_offset
, level
))
6888 tp_features
.fan_ctrl_status_undef
= 0;
6895 vdbg_printk(TPACPI_DBG_FAN
,
6896 "fan control: set fan control register to 0x%02x\n", level
);
6900 static int fan_set_level_safe(int level
)
6904 if (!fan_control_allowed
)
6907 if (mutex_lock_killable(&fan_mutex
))
6908 return -ERESTARTSYS
;
6910 if (level
== TPACPI_FAN_LAST_LEVEL
)
6911 level
= fan_control_desired_level
;
6913 rc
= fan_set_level(level
);
6915 fan_update_desired_level(level
);
6917 mutex_unlock(&fan_mutex
);
6921 static int fan_set_enable(void)
6926 if (!fan_control_allowed
)
6929 if (mutex_lock_killable(&fan_mutex
))
6930 return -ERESTARTSYS
;
6932 switch (fan_control_access_mode
) {
6933 case TPACPI_FAN_WR_ACPI_FANS
:
6934 case TPACPI_FAN_WR_TPEC
:
6935 rc
= fan_get_status(&s
);
6939 /* Don't go out of emergency fan mode */
6942 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
6945 if (!acpi_ec_write(fan_status_offset
, s
))
6948 tp_features
.fan_ctrl_status_undef
= 0;
6953 case TPACPI_FAN_WR_ACPI_SFAN
:
6954 rc
= fan_get_status(&s
);
6960 /* Set fan to at least level 4 */
6963 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
6973 mutex_unlock(&fan_mutex
);
6976 vdbg_printk(TPACPI_DBG_FAN
,
6977 "fan control: set fan control register to 0x%02x\n",
6982 static int fan_set_disable(void)
6986 if (!fan_control_allowed
)
6989 if (mutex_lock_killable(&fan_mutex
))
6990 return -ERESTARTSYS
;
6993 switch (fan_control_access_mode
) {
6994 case TPACPI_FAN_WR_ACPI_FANS
:
6995 case TPACPI_FAN_WR_TPEC
:
6996 if (!acpi_ec_write(fan_status_offset
, 0x00))
6999 fan_control_desired_level
= 0;
7000 tp_features
.fan_ctrl_status_undef
= 0;
7004 case TPACPI_FAN_WR_ACPI_SFAN
:
7005 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
7008 fan_control_desired_level
= 0;
7016 vdbg_printk(TPACPI_DBG_FAN
,
7017 "fan control: set fan control register to 0\n");
7019 mutex_unlock(&fan_mutex
);
7023 static int fan_set_speed(int speed
)
7027 if (!fan_control_allowed
)
7030 if (mutex_lock_killable(&fan_mutex
))
7031 return -ERESTARTSYS
;
7034 switch (fan_control_access_mode
) {
7035 case TPACPI_FAN_WR_ACPI_FANS
:
7036 if (speed
>= 0 && speed
<= 65535) {
7037 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
7038 speed
, speed
, speed
))
7048 mutex_unlock(&fan_mutex
);
7052 static void fan_watchdog_reset(void)
7054 static int fan_watchdog_active
;
7056 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
7059 if (fan_watchdog_active
)
7060 cancel_delayed_work(&fan_watchdog_task
);
7062 if (fan_watchdog_maxinterval
> 0 &&
7063 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
7064 fan_watchdog_active
= 1;
7065 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
7066 msecs_to_jiffies(fan_watchdog_maxinterval
7069 "failed to queue the fan watchdog, "
7070 "watchdog will not trigger\n");
7073 fan_watchdog_active
= 0;
7076 static void fan_watchdog_fire(struct work_struct
*ignored
)
7080 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
7083 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
7084 rc
= fan_set_enable();
7086 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
7087 "will try again later...\n", -rc
);
7088 /* reschedule for later */
7089 fan_watchdog_reset();
7094 * SYSFS fan layout: hwmon compatible (device)
7097 * 0: "disengaged" mode
7099 * 2: native EC "auto" mode (recommended, hardware default)
7101 * pwm*: set speed in manual mode, ignored otherwise.
7102 * 0 is level 0; 255 is level 7. Intermediate points done with linear
7105 * fan*_input: tachometer reading, RPM
7108 * SYSFS fan layout: extensions
7110 * fan_watchdog (driver):
7111 * fan watchdog interval in seconds, 0 disables (default), max 120
7114 /* sysfs fan pwm1_enable ----------------------------------------------- */
7115 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
7116 struct device_attribute
*attr
,
7122 res
= fan_get_status_safe(&status
);
7126 if (status
& TP_EC_FAN_FULLSPEED
) {
7128 } else if (status
& TP_EC_FAN_AUTO
) {
7133 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
7136 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
7137 struct device_attribute
*attr
,
7138 const char *buf
, size_t count
)
7143 if (parse_strtoul(buf
, 2, &t
))
7146 tpacpi_disclose_usertask("hwmon pwm1_enable",
7147 "set fan mode to %lu\n", t
);
7151 level
= TP_EC_FAN_FULLSPEED
;
7154 level
= TPACPI_FAN_LAST_LEVEL
;
7157 level
= TP_EC_FAN_AUTO
;
7160 /* reserved for software-controlled auto mode */
7166 res
= fan_set_level_safe(level
);
7172 fan_watchdog_reset();
7177 static struct device_attribute dev_attr_fan_pwm1_enable
=
7178 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
7179 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
7181 /* sysfs fan pwm1 ------------------------------------------------------ */
7182 static ssize_t
fan_pwm1_show(struct device
*dev
,
7183 struct device_attribute
*attr
,
7189 res
= fan_get_status_safe(&status
);
7194 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
7195 status
= fan_control_desired_level
;
7200 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
7203 static ssize_t
fan_pwm1_store(struct device
*dev
,
7204 struct device_attribute
*attr
,
7205 const char *buf
, size_t count
)
7209 u8 status
, newlevel
;
7211 if (parse_strtoul(buf
, 255, &s
))
7214 tpacpi_disclose_usertask("hwmon pwm1",
7215 "set fan speed to %lu\n", s
);
7217 /* scale down from 0-255 to 0-7 */
7218 newlevel
= (s
>> 5) & 0x07;
7220 if (mutex_lock_killable(&fan_mutex
))
7221 return -ERESTARTSYS
;
7223 rc
= fan_get_status(&status
);
7224 if (!rc
&& (status
&
7225 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
7226 rc
= fan_set_level(newlevel
);
7230 fan_update_desired_level(newlevel
);
7231 fan_watchdog_reset();
7235 mutex_unlock(&fan_mutex
);
7236 return (rc
)? rc
: count
;
7239 static struct device_attribute dev_attr_fan_pwm1
=
7240 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
7241 fan_pwm1_show
, fan_pwm1_store
);
7243 /* sysfs fan fan1_input ------------------------------------------------ */
7244 static ssize_t
fan_fan1_input_show(struct device
*dev
,
7245 struct device_attribute
*attr
,
7251 res
= fan_get_speed(&speed
);
7255 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7258 static struct device_attribute dev_attr_fan_fan1_input
=
7259 __ATTR(fan1_input
, S_IRUGO
,
7260 fan_fan1_input_show
, NULL
);
7262 /* sysfs fan fan2_input ------------------------------------------------ */
7263 static ssize_t
fan_fan2_input_show(struct device
*dev
,
7264 struct device_attribute
*attr
,
7270 res
= fan2_get_speed(&speed
);
7274 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
7277 static struct device_attribute dev_attr_fan_fan2_input
=
7278 __ATTR(fan2_input
, S_IRUGO
,
7279 fan_fan2_input_show
, NULL
);
7281 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
7282 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
7285 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
7288 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
7289 const char *buf
, size_t count
)
7293 if (parse_strtoul(buf
, 120, &t
))
7296 if (!fan_control_allowed
)
7299 fan_watchdog_maxinterval
= t
;
7300 fan_watchdog_reset();
7302 tpacpi_disclose_usertask("fan_watchdog", "set to %lu\n", t
);
7307 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
7308 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
7310 /* --------------------------------------------------------------------- */
7311 static struct attribute
*fan_attributes
[] = {
7312 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
7313 &dev_attr_fan_fan1_input
.attr
,
7314 NULL
, /* for fan2_input */
7318 static const struct attribute_group fan_attr_group
= {
7319 .attrs
= fan_attributes
,
7322 #define TPACPI_FAN_Q1 0x0001 /* Unitialized HFSP */
7323 #define TPACPI_FAN_2FAN 0x0002 /* EC 0x31 bit 0 selects fan2 */
7325 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7326 { .vendor = PCI_VENDOR_ID_IBM, \
7327 .bios = TPACPI_MATCH_ANY, \
7328 .ec = TPID(__id1, __id2), \
7329 .quirks = __quirks }
7331 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7332 { .vendor = PCI_VENDOR_ID_LENOVO, \
7333 .bios = TPACPI_MATCH_ANY, \
7334 .ec = TPID(__id1, __id2), \
7335 .quirks = __quirks }
7337 static const struct tpacpi_quirk fan_quirk_table
[] __initconst
= {
7338 TPACPI_FAN_QI('1', 'Y', TPACPI_FAN_Q1
),
7339 TPACPI_FAN_QI('7', '8', TPACPI_FAN_Q1
),
7340 TPACPI_FAN_QI('7', '6', TPACPI_FAN_Q1
),
7341 TPACPI_FAN_QI('7', '0', TPACPI_FAN_Q1
),
7342 TPACPI_FAN_QL('7', 'M', TPACPI_FAN_2FAN
),
7345 #undef TPACPI_FAN_QL
7346 #undef TPACPI_FAN_QI
7348 static int __init
fan_init(struct ibm_init_struct
*iibm
)
7351 unsigned long quirks
;
7353 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7354 "initializing fan subdriver\n");
7356 mutex_init(&fan_mutex
);
7357 fan_status_access_mode
= TPACPI_FAN_NONE
;
7358 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7359 fan_control_commands
= 0;
7360 fan_watchdog_maxinterval
= 0;
7361 tp_features
.fan_ctrl_status_undef
= 0;
7362 tp_features
.second_fan
= 0;
7363 fan_control_desired_level
= 7;
7365 TPACPI_ACPIHANDLE_INIT(fans
);
7366 TPACPI_ACPIHANDLE_INIT(gfan
);
7367 TPACPI_ACPIHANDLE_INIT(sfan
);
7369 quirks
= tpacpi_check_quirks(fan_quirk_table
,
7370 ARRAY_SIZE(fan_quirk_table
));
7373 /* 570, 600e/x, 770e, 770x */
7374 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
7376 /* all other ThinkPads: note that even old-style
7377 * ThinkPad ECs supports the fan control register */
7378 if (likely(acpi_ec_read(fan_status_offset
,
7379 &fan_control_initial_status
))) {
7380 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
7381 if (quirks
& TPACPI_FAN_Q1
)
7383 if (quirks
& TPACPI_FAN_2FAN
) {
7384 tp_features
.second_fan
= 1;
7385 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7386 "secondary fan support enabled\n");
7390 "ThinkPad ACPI EC access misbehaving, "
7391 "fan status and control unavailable\n");
7398 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
7399 fan_control_commands
|=
7400 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
7403 /* gfan without sfan means no fan control */
7404 /* all other models implement TP EC 0x2f control */
7408 fan_control_access_mode
=
7409 TPACPI_FAN_WR_ACPI_FANS
;
7410 fan_control_commands
|=
7411 TPACPI_FAN_CMD_SPEED
|
7412 TPACPI_FAN_CMD_LEVEL
|
7413 TPACPI_FAN_CMD_ENABLE
;
7415 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
7416 fan_control_commands
|=
7417 TPACPI_FAN_CMD_LEVEL
|
7418 TPACPI_FAN_CMD_ENABLE
;
7423 vdbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7424 "fan is %s, modes %d, %d\n",
7425 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
7426 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
7427 fan_status_access_mode
, fan_control_access_mode
);
7429 /* fan control master switch */
7430 if (!fan_control_allowed
) {
7431 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
7432 fan_control_commands
= 0;
7433 dbg_printk(TPACPI_DBG_INIT
| TPACPI_DBG_FAN
,
7434 "fan control features disabled by parameter\n");
7437 /* update fan_control_desired_level */
7438 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
7439 fan_get_status_safe(NULL
);
7441 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
7442 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
7443 if (tp_features
.second_fan
) {
7444 /* attach second fan tachometer */
7445 fan_attributes
[ARRAY_SIZE(fan_attributes
)-2] =
7446 &dev_attr_fan_fan2_input
.attr
;
7448 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7453 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
7454 &driver_attr_fan_watchdog
);
7456 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
7465 static void fan_exit(void)
7467 vdbg_printk(TPACPI_DBG_EXIT
| TPACPI_DBG_FAN
,
7468 "cancelling any pending fan watchdog tasks\n");
7470 /* FIXME: can we really do this unconditionally? */
7471 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
7472 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
7473 &driver_attr_fan_watchdog
);
7475 cancel_delayed_work(&fan_watchdog_task
);
7476 flush_workqueue(tpacpi_wq
);
7479 static void fan_suspend(pm_message_t state
)
7483 if (!fan_control_allowed
)
7486 /* Store fan status in cache */
7487 fan_control_resume_level
= 0;
7488 rc
= fan_get_status_safe(&fan_control_resume_level
);
7490 printk(TPACPI_NOTICE
7491 "failed to read fan level for later "
7492 "restore during resume: %d\n", rc
);
7494 /* if it is undefined, don't attempt to restore it.
7496 if (tp_features
.fan_ctrl_status_undef
)
7497 fan_control_resume_level
= 0;
7500 static void fan_resume(void)
7502 u8 current_level
= 7;
7503 bool do_set
= false;
7506 /* DSDT *always* updates status on resume */
7507 tp_features
.fan_ctrl_status_undef
= 0;
7509 if (!fan_control_allowed
||
7510 !fan_control_resume_level
||
7511 (fan_get_status_safe(¤t_level
) < 0))
7514 switch (fan_control_access_mode
) {
7515 case TPACPI_FAN_WR_ACPI_SFAN
:
7516 /* never decrease fan level */
7517 do_set
= (fan_control_resume_level
> current_level
);
7519 case TPACPI_FAN_WR_ACPI_FANS
:
7520 case TPACPI_FAN_WR_TPEC
:
7521 /* never decrease fan level, scale is:
7522 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
7524 * We expect the firmware to set either 7 or AUTO, but we
7525 * handle FULLSPEED out of paranoia.
7527 * So, we can safely only restore FULLSPEED or 7, anything
7528 * else could slow the fan. Restoring AUTO is useless, at
7529 * best that's exactly what the DSDT already set (it is the
7532 * Always keep in mind that the DSDT *will* have set the
7533 * fans to what the vendor supposes is the best level. We
7534 * muck with it only to speed the fan up.
7536 if (fan_control_resume_level
!= 7 &&
7537 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
7540 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
7541 (current_level
!= fan_control_resume_level
);
7547 printk(TPACPI_NOTICE
7548 "restoring fan level to 0x%02x\n",
7549 fan_control_resume_level
);
7550 rc
= fan_set_level_safe(fan_control_resume_level
);
7552 printk(TPACPI_NOTICE
7553 "failed to restore fan level: %d\n", rc
);
7557 static int fan_read(char *p
)
7562 unsigned int speed
= 0;
7564 switch (fan_status_access_mode
) {
7565 case TPACPI_FAN_RD_ACPI_GFAN
:
7566 /* 570, 600e/x, 770e, 770x */
7567 rc
= fan_get_status_safe(&status
);
7571 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
7573 (status
!= 0) ? "enabled" : "disabled", status
);
7576 case TPACPI_FAN_RD_TPEC
:
7577 /* all except 570, 600e/x, 770e, 770x */
7578 rc
= fan_get_status_safe(&status
);
7582 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
7583 (status
!= 0) ? "enabled" : "disabled");
7585 rc
= fan_get_speed(&speed
);
7589 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
7591 if (status
& TP_EC_FAN_FULLSPEED
)
7592 /* Disengaged mode takes precedence */
7593 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
7594 else if (status
& TP_EC_FAN_AUTO
)
7595 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
7597 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
7600 case TPACPI_FAN_NONE
:
7602 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
7605 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
7606 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
7608 switch (fan_control_access_mode
) {
7609 case TPACPI_FAN_WR_ACPI_SFAN
:
7610 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
7614 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
7615 "auto, disengaged, full-speed)\n");
7620 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
7621 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
7622 "commands:\twatchdog <timeout> (<timeout> "
7623 "is 0 (off), 1-120 (seconds))\n");
7625 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
7626 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
7627 " (<speed> is 0-65535)\n");
7632 static int fan_write_cmd_level(const char *cmd
, int *rc
)
7636 if (strlencmp(cmd
, "level auto") == 0)
7637 level
= TP_EC_FAN_AUTO
;
7638 else if ((strlencmp(cmd
, "level disengaged") == 0) |
7639 (strlencmp(cmd
, "level full-speed") == 0))
7640 level
= TP_EC_FAN_FULLSPEED
;
7641 else if (sscanf(cmd
, "level %d", &level
) != 1)
7644 *rc
= fan_set_level_safe(level
);
7646 printk(TPACPI_ERR
"level command accepted for unsupported "
7647 "access mode %d", fan_control_access_mode
);
7649 tpacpi_disclose_usertask("procfs fan",
7650 "set level to %d\n", level
);
7655 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
7657 if (strlencmp(cmd
, "enable") != 0)
7660 *rc
= fan_set_enable();
7662 printk(TPACPI_ERR
"enable command accepted for unsupported "
7663 "access mode %d", fan_control_access_mode
);
7665 tpacpi_disclose_usertask("procfs fan", "enable\n");
7670 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
7672 if (strlencmp(cmd
, "disable") != 0)
7675 *rc
= fan_set_disable();
7677 printk(TPACPI_ERR
"disable command accepted for unsupported "
7678 "access mode %d", fan_control_access_mode
);
7680 tpacpi_disclose_usertask("procfs fan", "disable\n");
7685 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
7690 * Support speed <low> <medium> <high> ? */
7692 if (sscanf(cmd
, "speed %d", &speed
) != 1)
7695 *rc
= fan_set_speed(speed
);
7697 printk(TPACPI_ERR
"speed command accepted for unsupported "
7698 "access mode %d", fan_control_access_mode
);
7700 tpacpi_disclose_usertask("procfs fan",
7701 "set speed to %d\n", speed
);
7706 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
7710 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
7713 if (interval
< 0 || interval
> 120)
7716 fan_watchdog_maxinterval
= interval
;
7717 tpacpi_disclose_usertask("procfs fan",
7718 "set watchdog timer to %d\n",
7725 static int fan_write(char *buf
)
7730 while (!rc
&& (cmd
= next_cmd(&buf
))) {
7731 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
7732 fan_write_cmd_level(cmd
, &rc
)) &&
7733 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
7734 (fan_write_cmd_enable(cmd
, &rc
) ||
7735 fan_write_cmd_disable(cmd
, &rc
) ||
7736 fan_write_cmd_watchdog(cmd
, &rc
))) &&
7737 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
7738 fan_write_cmd_speed(cmd
, &rc
))
7742 fan_watchdog_reset();
7748 static struct ibm_struct fan_driver_data
= {
7753 .suspend
= fan_suspend
,
7754 .resume
= fan_resume
,
7757 /****************************************************************************
7758 ****************************************************************************
7762 ****************************************************************************
7763 ****************************************************************************/
7766 * HKEY event callout for other subdrivers go here
7767 * (yes, it is ugly, but it is quick, safe, and gets the job done
7769 static void tpacpi_driver_event(const unsigned int hkey_event
)
7771 if (ibm_backlight_device
) {
7772 switch (hkey_event
) {
7773 case TP_HKEY_EV_BRGHT_UP
:
7774 case TP_HKEY_EV_BRGHT_DOWN
:
7775 tpacpi_brightness_notify_change();
7782 static void hotkey_driver_event(const unsigned int scancode
)
7784 tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE
+ scancode
);
7787 /* sysfs name ---------------------------------------------------------- */
7788 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
7789 struct device_attribute
*attr
,
7792 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
7795 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
7796 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
7798 /* --------------------------------------------------------------------- */
7801 static struct proc_dir_entry
*proc_dir
;
7804 * Module and infrastructure proble, init and exit handling
7807 static int force_load
;
7809 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
7810 static const char * __init
str_supported(int is_supported
)
7812 static char text_unsupported
[] __initdata
= "not supported";
7814 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
7816 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
7818 static void ibm_exit(struct ibm_struct
*ibm
)
7820 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
7822 list_del_init(&ibm
->all_drivers
);
7824 if (ibm
->flags
.acpi_notify_installed
) {
7825 dbg_printk(TPACPI_DBG_EXIT
,
7826 "%s: acpi_remove_notify_handler\n", ibm
->name
);
7828 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
7830 dispatch_acpi_notify
);
7831 ibm
->flags
.acpi_notify_installed
= 0;
7832 ibm
->flags
.acpi_notify_installed
= 0;
7835 if (ibm
->flags
.proc_created
) {
7836 dbg_printk(TPACPI_DBG_EXIT
,
7837 "%s: remove_proc_entry\n", ibm
->name
);
7838 remove_proc_entry(ibm
->name
, proc_dir
);
7839 ibm
->flags
.proc_created
= 0;
7842 if (ibm
->flags
.acpi_driver_registered
) {
7843 dbg_printk(TPACPI_DBG_EXIT
,
7844 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
7846 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
7847 kfree(ibm
->acpi
->driver
);
7848 ibm
->acpi
->driver
= NULL
;
7849 ibm
->flags
.acpi_driver_registered
= 0;
7852 if (ibm
->flags
.init_called
&& ibm
->exit
) {
7854 ibm
->flags
.init_called
= 0;
7857 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
7860 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
7863 struct ibm_struct
*ibm
= iibm
->data
;
7864 struct proc_dir_entry
*entry
;
7866 BUG_ON(ibm
== NULL
);
7868 INIT_LIST_HEAD(&ibm
->all_drivers
);
7870 if (ibm
->flags
.experimental
&& !experimental
)
7873 dbg_printk(TPACPI_DBG_INIT
,
7874 "probing for %s\n", ibm
->name
);
7877 ret
= iibm
->init(iibm
);
7879 return 0; /* probe failed */
7883 ibm
->flags
.init_called
= 1;
7887 if (ibm
->acpi
->hid
) {
7888 ret
= register_tpacpi_subdriver(ibm
);
7893 if (ibm
->acpi
->notify
) {
7894 ret
= setup_acpi_notify(ibm
);
7895 if (ret
== -ENODEV
) {
7896 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
7906 dbg_printk(TPACPI_DBG_INIT
,
7907 "%s installed\n", ibm
->name
);
7910 entry
= create_proc_entry(ibm
->name
,
7911 S_IFREG
| S_IRUGO
| S_IWUSR
,
7914 printk(TPACPI_ERR
"unable to create proc entry %s\n",
7920 entry
->read_proc
= &dispatch_procfs_read
;
7922 entry
->write_proc
= &dispatch_procfs_write
;
7923 ibm
->flags
.proc_created
= 1;
7926 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
7931 dbg_printk(TPACPI_DBG_INIT
,
7932 "%s: at error exit path with result %d\n",
7936 return (ret
< 0)? ret
: 0;
7941 static bool __pure __init
tpacpi_is_fw_digit(const char c
)
7943 return (c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'Z');
7946 /* Most models: xxyTkkWW (#.##c); Ancient 570/600 and -SL lacks (#.##c) */
7947 static bool __pure __init
tpacpi_is_valid_fw_id(const char* const s
,
7950 return s
&& strlen(s
) >= 8 &&
7951 tpacpi_is_fw_digit(s
[0]) &&
7952 tpacpi_is_fw_digit(s
[1]) &&
7953 s
[2] == t
&& s
[3] == 'T' &&
7954 tpacpi_is_fw_digit(s
[4]) &&
7955 tpacpi_is_fw_digit(s
[5]) &&
7956 s
[6] == 'W' && s
[7] == 'W';
7959 /* returns 0 - probe ok, or < 0 - probe error.
7960 * Probe ok doesn't mean thinkpad found.
7961 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
7962 static int __must_check __init
get_thinkpad_model_data(
7963 struct thinkpad_id_data
*tp
)
7965 const struct dmi_device
*dev
= NULL
;
7966 char ec_fw_string
[18];
7972 memset(tp
, 0, sizeof(*tp
));
7974 if (dmi_name_in_vendors("IBM"))
7975 tp
->vendor
= PCI_VENDOR_ID_IBM
;
7976 else if (dmi_name_in_vendors("LENOVO"))
7977 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
7981 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
7982 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
7983 if (s
&& !tp
->bios_version_str
)
7986 /* Really ancient ThinkPad 240X will fail this, which is fine */
7987 if (!tpacpi_is_valid_fw_id(tp
->bios_version_str
, 'E'))
7990 tp
->bios_model
= tp
->bios_version_str
[0]
7991 | (tp
->bios_version_str
[1] << 8);
7992 tp
->bios_release
= (tp
->bios_version_str
[4] << 8)
7993 | tp
->bios_version_str
[5];
7996 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
7997 * X32 or newer, all Z series; Some models must have an
7998 * up-to-date BIOS or they will not be detected.
8000 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8002 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
8003 if (sscanf(dev
->name
,
8004 "IBM ThinkPad Embedded Controller -[%17c",
8005 ec_fw_string
) == 1) {
8006 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
8007 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
8009 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
8010 if (!tp
->ec_version_str
)
8013 if (tpacpi_is_valid_fw_id(ec_fw_string
, 'H')) {
8014 tp
->ec_model
= ec_fw_string
[0]
8015 | (ec_fw_string
[1] << 8);
8016 tp
->ec_release
= (ec_fw_string
[4] << 8)
8019 printk(TPACPI_NOTICE
8020 "ThinkPad firmware release %s "
8021 "doesn't match the known patterns\n",
8023 printk(TPACPI_NOTICE
8024 "please report this to %s\n",
8031 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
8032 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
8033 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
8038 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
8039 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
8040 if (s
&& !tp
->nummodel_str
)
8046 static int __init
probe_for_thinkpad(void)
8054 * Non-ancient models have better DMI tagging, but very old models
8055 * don't. tpacpi_is_fw_known() is a cheat to help in that case.
8057 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
) ||
8058 (thinkpad_id
.ec_model
!= 0) ||
8059 tpacpi_is_fw_known();
8061 /* ec is required because many other handles are relative to it */
8062 TPACPI_ACPIHANDLE_INIT(ec
);
8066 "Not yet supported ThinkPad detected!\n");
8070 if (!is_thinkpad
&& !force_load
)
8077 /* Module init, exit, parameters */
8079 static struct ibm_init_struct ibms_init
[] __initdata
= {
8081 .init
= thinkpad_acpi_driver_init
,
8082 .data
= &thinkpad_acpi_driver_data
,
8085 .init
= hotkey_init
,
8086 .data
= &hotkey_driver_data
,
8089 .init
= bluetooth_init
,
8090 .data
= &bluetooth_driver_data
,
8094 .data
= &wan_driver_data
,
8098 .data
= &uwb_driver_data
,
8100 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8103 .data
= &video_driver_data
,
8108 .data
= &light_driver_data
,
8112 .data
= &cmos_driver_data
,
8116 .data
= &led_driver_data
,
8120 .data
= &beep_driver_data
,
8123 .init
= thermal_init
,
8124 .data
= &thermal_driver_data
,
8127 .data
= &ecdump_driver_data
,
8130 .init
= brightness_init
,
8131 .data
= &brightness_driver_data
,
8134 .data
= &volume_driver_data
,
8138 .data
= &fan_driver_data
,
8142 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
8145 struct ibm_struct
*ibm
;
8147 if (!kp
|| !kp
->name
|| !val
)
8150 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8151 ibm
= ibms_init
[i
].data
;
8152 WARN_ON(ibm
== NULL
);
8154 if (!ibm
|| !ibm
->name
)
8157 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
8158 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
8160 strcpy(ibms_init
[i
].param
, val
);
8161 strcat(ibms_init
[i
].param
, ",");
8169 module_param(experimental
, int, 0444);
8170 MODULE_PARM_DESC(experimental
,
8171 "Enables experimental features when non-zero");
8173 module_param_named(debug
, dbg_level
, uint
, 0);
8174 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
8176 module_param(force_load
, bool, 0444);
8177 MODULE_PARM_DESC(force_load
,
8178 "Attempts to load the driver even on a "
8179 "mis-identified ThinkPad when true");
8181 module_param_named(fan_control
, fan_control_allowed
, bool, 0444);
8182 MODULE_PARM_DESC(fan_control
,
8183 "Enables setting fan parameters features when true");
8185 module_param_named(brightness_mode
, brightness_mode
, uint
, 0444);
8186 MODULE_PARM_DESC(brightness_mode
,
8187 "Selects brightness control strategy: "
8188 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8190 module_param(brightness_enable
, uint
, 0444);
8191 MODULE_PARM_DESC(brightness_enable
,
8192 "Enables backlight control when 1, disables when 0");
8194 module_param(hotkey_report_mode
, uint
, 0444);
8195 MODULE_PARM_DESC(hotkey_report_mode
,
8196 "used for backwards compatibility with userspace, "
8197 "see documentation");
8199 #define TPACPI_PARAM(feature) \
8200 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8201 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8202 "at module load, see documentation")
8204 TPACPI_PARAM(hotkey
);
8205 TPACPI_PARAM(bluetooth
);
8206 TPACPI_PARAM(video
);
8207 TPACPI_PARAM(light
);
8211 TPACPI_PARAM(ecdump
);
8212 TPACPI_PARAM(brightness
);
8213 TPACPI_PARAM(volume
);
8216 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8217 module_param(dbg_wlswemul
, uint
, 0444);
8218 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
8219 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
8220 MODULE_PARM_DESC(wlsw_state
,
8221 "Initial state of the emulated WLSW switch");
8223 module_param(dbg_bluetoothemul
, uint
, 0444);
8224 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
8225 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
8226 MODULE_PARM_DESC(bluetooth_state
,
8227 "Initial state of the emulated bluetooth switch");
8229 module_param(dbg_wwanemul
, uint
, 0444);
8230 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
8231 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
8232 MODULE_PARM_DESC(wwan_state
,
8233 "Initial state of the emulated WWAN switch");
8235 module_param(dbg_uwbemul
, uint
, 0444);
8236 MODULE_PARM_DESC(dbg_uwbemul
, "Enables UWB switch emulation");
8237 module_param_named(uwb_state
, tpacpi_uwb_emulstate
, bool, 0);
8238 MODULE_PARM_DESC(uwb_state
,
8239 "Initial state of the emulated UWB switch");
8242 static void thinkpad_acpi_module_exit(void)
8244 struct ibm_struct
*ibm
, *itmp
;
8246 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
8248 list_for_each_entry_safe_reverse(ibm
, itmp
,
8249 &tpacpi_all_drivers
,
8254 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
8256 if (tpacpi_inputdev
) {
8257 if (tp_features
.input_device_registered
)
8258 input_unregister_device(tpacpi_inputdev
);
8260 input_free_device(tpacpi_inputdev
);
8264 hwmon_device_unregister(tpacpi_hwmon
);
8266 if (tp_features
.sensors_pdev_attrs_registered
)
8267 device_remove_file(&tpacpi_sensors_pdev
->dev
,
8268 &dev_attr_thinkpad_acpi_pdev_name
);
8269 if (tpacpi_sensors_pdev
)
8270 platform_device_unregister(tpacpi_sensors_pdev
);
8272 platform_device_unregister(tpacpi_pdev
);
8274 if (tp_features
.sensors_pdrv_attrs_registered
)
8275 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
8276 if (tp_features
.platform_drv_attrs_registered
)
8277 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
8279 if (tp_features
.sensors_pdrv_registered
)
8280 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
8282 if (tp_features
.platform_drv_registered
)
8283 platform_driver_unregister(&tpacpi_pdriver
);
8286 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
8289 destroy_workqueue(tpacpi_wq
);
8291 kfree(thinkpad_id
.bios_version_str
);
8292 kfree(thinkpad_id
.ec_version_str
);
8293 kfree(thinkpad_id
.model_str
);
8297 static int __init
thinkpad_acpi_module_init(void)
8301 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
8303 /* Parameter checking */
8304 if (hotkey_report_mode
> 2)
8307 /* Driver-level probe */
8309 ret
= get_thinkpad_model_data(&thinkpad_id
);
8312 "unable to get DMI data: %d\n", ret
);
8313 thinkpad_acpi_module_exit();
8316 ret
= probe_for_thinkpad();
8318 thinkpad_acpi_module_exit();
8322 /* Driver initialization */
8324 TPACPI_ACPIHANDLE_INIT(ecrd
);
8325 TPACPI_ACPIHANDLE_INIT(ecwr
);
8327 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
8329 thinkpad_acpi_module_exit();
8333 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
8336 "unable to create proc dir " TPACPI_PROC_DIR
);
8337 thinkpad_acpi_module_exit();
8341 ret
= platform_driver_register(&tpacpi_pdriver
);
8344 "unable to register main platform driver\n");
8345 thinkpad_acpi_module_exit();
8348 tp_features
.platform_drv_registered
= 1;
8350 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
8353 "unable to register hwmon platform driver\n");
8354 thinkpad_acpi_module_exit();
8357 tp_features
.sensors_pdrv_registered
= 1;
8359 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
8361 tp_features
.platform_drv_attrs_registered
= 1;
8362 ret
= tpacpi_create_driver_attributes(
8363 &tpacpi_hwmon_pdriver
.driver
);
8367 "unable to create sysfs driver attributes\n");
8368 thinkpad_acpi_module_exit();
8371 tp_features
.sensors_pdrv_attrs_registered
= 1;
8374 /* Device initialization */
8375 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
8377 if (IS_ERR(tpacpi_pdev
)) {
8378 ret
= PTR_ERR(tpacpi_pdev
);
8380 printk(TPACPI_ERR
"unable to register platform device\n");
8381 thinkpad_acpi_module_exit();
8384 tpacpi_sensors_pdev
= platform_device_register_simple(
8385 TPACPI_HWMON_DRVR_NAME
,
8387 if (IS_ERR(tpacpi_sensors_pdev
)) {
8388 ret
= PTR_ERR(tpacpi_sensors_pdev
);
8389 tpacpi_sensors_pdev
= NULL
;
8391 "unable to register hwmon platform device\n");
8392 thinkpad_acpi_module_exit();
8395 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
8396 &dev_attr_thinkpad_acpi_pdev_name
);
8399 "unable to create sysfs hwmon device attributes\n");
8400 thinkpad_acpi_module_exit();
8403 tp_features
.sensors_pdev_attrs_registered
= 1;
8404 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
8405 if (IS_ERR(tpacpi_hwmon
)) {
8406 ret
= PTR_ERR(tpacpi_hwmon
);
8407 tpacpi_hwmon
= NULL
;
8408 printk(TPACPI_ERR
"unable to register hwmon device\n");
8409 thinkpad_acpi_module_exit();
8412 mutex_init(&tpacpi_inputdev_send_mutex
);
8413 tpacpi_inputdev
= input_allocate_device();
8414 if (!tpacpi_inputdev
) {
8415 printk(TPACPI_ERR
"unable to allocate input device\n");
8416 thinkpad_acpi_module_exit();
8419 /* Prepare input device, but don't register */
8420 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
8421 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
8422 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
8423 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
8424 thinkpad_id
.vendor
:
8426 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
8427 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
8428 tpacpi_inputdev
->dev
.parent
= &tpacpi_pdev
->dev
;
8430 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
8431 ret
= ibm_init(&ibms_init
[i
]);
8432 if (ret
>= 0 && *ibms_init
[i
].param
)
8433 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
8435 thinkpad_acpi_module_exit();
8440 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
8442 ret
= input_register_device(tpacpi_inputdev
);
8444 printk(TPACPI_ERR
"unable to register input device\n");
8445 thinkpad_acpi_module_exit();
8448 tp_features
.input_device_registered
= 1;
8454 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
8457 * This will autoload the driver in almost every ThinkPad
8458 * in widespread use.
8460 * Only _VERY_ old models, like the 240, 240x and 570 lack
8461 * the HKEY event interface.
8463 MODULE_DEVICE_TABLE(acpi
, ibm_htk_device_ids
);
8466 * DMI matching for module autoloading
8468 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
8469 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
8471 * Only models listed in thinkwiki will be supported, so add yours
8472 * if it is not there yet.
8474 #define IBM_BIOS_MODULE_ALIAS(__type) \
8475 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
8477 /* Ancient thinkpad BIOSes have to be identified by
8478 * BIOS type or model number, and there are far less
8479 * BIOS types than model numbers... */
8480 IBM_BIOS_MODULE_ALIAS("I[MU]"); /* 570, 570e */
8482 MODULE_AUTHOR("Borislav Deianov <borislav@users.sf.net>");
8483 MODULE_AUTHOR("Henrique de Moraes Holschuh <hmh@hmh.eng.br>");
8484 MODULE_DESCRIPTION(TPACPI_DESC
);
8485 MODULE_VERSION(TPACPI_VERSION
);
8486 MODULE_LICENSE("GPL");
8488 module_init(thinkpad_acpi_module_init
);
8489 module_exit(thinkpad_acpi_module_exit
);