24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 #define TPACPI_VERSION "0.24"
27 #define TPACPI_SYSFS_VERSION 0x020700
52 #include <linux/kernel.h>
53 #include <linux/module.h>
55 #include <linux/types.h>
56 #include <linux/string.h>
57 #include <linux/list.h>
59 #include <linux/sched.h>
63 #include <linux/slab.h>
65 #include <linux/nvram.h>
74 #include <linux/input.h>
76 #include <linux/rfkill.h>
77 #include <asm/uaccess.h>
93 #define TP_CMOS_VOLUME_DOWN 0
94 #define TP_CMOS_VOLUME_UP 1
95 #define TP_CMOS_VOLUME_MUTE 2
96 #define TP_CMOS_BRIGHTNESS_UP 4
97 #define TP_CMOS_BRIGHTNESS_DOWN 5
98 #define TP_CMOS_THINKLIGHT_ON 12
99 #define TP_CMOS_THINKLIGHT_OFF 13
133 #define TPACPI_ACPI_IBM_HKEY_HID "IBM0068"
134 #define TPACPI_ACPI_LENOVO_HKEY_HID "LEN0068"
135 #define TPACPI_ACPI_EC_HID "PNP0C09"
138 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054
139 #define TPACPI_HKEY_INPUT_VERSION 0x4101
224 #define TPACPI_NAME "thinkpad"
225 #define TPACPI_DESC "ThinkPad ACPI Extras"
226 #define TPACPI_FILE TPACPI_NAME "_acpi"
227 #define TPACPI_URL "http://ibm-acpi.sf.net/"
230 #define TPACPI_PROC_DIR "ibm"
231 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
232 #define TPACPI_DRVR_NAME TPACPI_FILE
233 #define TPACPI_DRVR_SHORTNAME "tpacpi"
234 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
236 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
237 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
239 #define TPACPI_MAX_ACPI_ARGS 3
242 #define TPACPI_DBG_ALL 0xffff
243 #define TPACPI_DBG_DISCLOSETASK 0x8000
244 #define TPACPI_DBG_INIT 0x0001
245 #define TPACPI_DBG_EXIT 0x0002
246 #define TPACPI_DBG_RFKILL 0x0004
247 #define TPACPI_DBG_HKEY 0x0008
248 #define TPACPI_DBG_FAN 0x0010
249 #define TPACPI_DBG_BRGHT 0x0020
250 #define TPACPI_DBG_MIXER 0x0040
252 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
253 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
254 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
357 static int experimental;
358 static u32 dbg_level;
377 static unsigned int bright_maxlvl;
379 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
380 static int dbg_wlswemul;
381 static bool tpacpi_wlsw_emulstate;
382 static int dbg_bluetoothemul;
383 static bool tpacpi_bluetooth_emulstate;
384 static int dbg_wwanemul;
385 static bool tpacpi_wwan_emulstate;
386 static int dbg_uwbemul;
387 static bool tpacpi_uwb_emulstate;
395 #define dbg_printk(a_dbg_level, format, arg...) \
397 if (dbg_level & (a_dbg_level)) \
398 printk(KERN_DEBUG pr_fmt("%s: " format), \
402 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
403 #define vdbg_printk dbg_printk
404 static const char *str_supported(
int is_supported);
406 static inline const char *str_supported(
int is_supported) {
return ""; }
407 #define vdbg_printk(a_dbg_level, format, arg...) \
408 no_printk(format, ##arg)
411 static void tpacpi_log_usertask(
const char *
const what)
417 #define tpacpi_disclose_usertask(what, format, arg...) \
419 if (unlikely((dbg_level & TPACPI_DBG_DISCLOSETASK) && \
420 (tpacpi_lifecycle == TPACPI_LIFE_RUNNING))) { \
421 printk(KERN_DEBUG pr_fmt("%s: PID %d: " format), \
422 what, task_tgid_vnr(current), ## arg); \
435 #define TPACPI_MATCH_ANY 0xffffU
436 #define TPACPI_MATCH_UNKNOWN 0U
439 #define TPID(__c1, __c2) (((__c2) << 8) | (__c1))
441 #define TPACPI_Q_IBM(__id1, __id2, __quirk) \
442 { .vendor = PCI_VENDOR_ID_IBM, \
443 .bios = TPID(__id1, __id2), \
444 .ec = TPACPI_MATCH_ANY, \
445 .quirks = (__quirk) }
447 #define TPACPI_Q_LNV(__id1, __id2, __quirk) \
448 { .vendor = PCI_VENDOR_ID_LENOVO, \
449 .bios = TPID(__id1, __id2), \
450 .ec = TPACPI_MATCH_ANY, \
451 .quirks = (__quirk) }
453 #define TPACPI_QEC_LNV(__id1, __id2, __quirk) \
454 { .vendor = PCI_VENDOR_ID_LENOVO, \
455 .bios = TPACPI_MATCH_ANY, \
456 .ec = TPID(__id1, __id2), \
457 .quirks = (__quirk) }
479 static unsigned long __init tpacpi_check_quirks(
481 unsigned int qlist_size)
484 if ((qlist->
vendor == thinkpad_id.vendor ||
486 (qlist->
bios == thinkpad_id.bios_model ||
488 (qlist->
ec == thinkpad_id.ec_model ||
523 #define TPACPI_HANDLE(object, parent, paths...) \
524 static acpi_handle object##_handle; \
525 static const acpi_handle * const object##_parent __initconst = \
527 static char *object##_paths[] __initdata = { paths }
562 pr_err(
"acpi_evalf() called with empty format\n");
575 params.pointer = &in_objs[0];
587 pr_err(
"acpi_evalf() called "
588 "with invalid format character '%c'\n", c);
595 if (res_type !=
'v') {
596 result.length =
sizeof(out_obj);
597 result.pointer = &out_obj;
606 success = (status ==
AE_OK &&
609 *res = out_obj.integer.value;
612 success = status ==
AE_OK;
616 pr_err(
"acpi_evalf() called "
617 "with invalid format character '%c'\n", res_type);
621 if (!success && !quiet)
622 pr_err(
"acpi_evalf(%s, %s, ...) failed: %s\n",
628 static int acpi_ec_read(
int i,
u8 *
p)
633 if (!acpi_evalf(ecrd_handle, &v,
NULL,
"dd", i))
644 static int acpi_ec_write(
int i,
u8 v)
647 if (!acpi_evalf(ecwr_handle,
NULL,
NULL,
"vdd", i, v))
657 static int issue_thinkpad_cmos_command(
int cmos_cmd)
662 if (!acpi_evalf(cmos_handle,
NULL,
NULL,
"vd", cmos_cmd))
672 #define TPACPI_ACPIHANDLE_INIT(object) \
673 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
674 object##_paths, ARRAY_SIZE(object##_paths))
676 static void __init drv_acpi_handle_init(
const char *
name,
678 char **paths,
const int num_paths)
686 for (i = 0; i < num_paths; i++) {
690 "Found ACPI handle %s for %s\n",
709 static void __init tpacpi_acpi_handle_locate(
const char *
name,
716 BUG_ON(!name || !hid || !handle);
718 "trying to locate ACPI handle for %s, using HID %s\n",
721 memset(&device_found, 0,
sizeof(device_found));
723 (
void *)name, &device_found);
728 *handle = device_found;
730 "Found ACPI handle for %s\n", name);
733 "Could not locate an ACPI handle for %s: %s\n",
745 if (!ibm || !ibm->
acpi || !ibm->
acpi->notify)
748 ibm->
acpi->notify(ibm, event);
758 if (!*ibm->
acpi->handle)
762 "setting up ACPI notify for %s\n", ibm->
name);
766 pr_err(
"acpi_bus_get_device(%s) failed: %d\n", ibm->
name, rc);
770 ibm->
acpi->device->driver_data = ibm;
771 sprintf(acpi_device_class(ibm->
acpi->device),
"%s/%s",
776 ibm->
acpi->type, dispatch_acpi_notify, ibm);
779 pr_notice(
"another device driver is already "
780 "handling %s events\n", ibm->
name);
782 pr_err(
"acpi_install_notify_handler(%s) failed: %s\n",
787 ibm->
flags.acpi_notify_installed = 1;
791 static int __init tpacpi_device_add(
struct acpi_device *
device)
801 "registering %s as an ACPI driver\n", ibm->
name);
805 ibm->
acpi->driver = kzalloc(
sizeof(
struct acpi_driver),
GFP_KERNEL);
806 if (!ibm->
acpi->driver) {
807 pr_err(
"failed to allocate memory for ibm->acpi->driver\n");
812 ibm->
acpi->driver->ids = ibm->
acpi->hid;
814 ibm->
acpi->driver->ops.add = &tpacpi_device_add;
818 pr_err(
"acpi_bus_register_driver(%s) failed: %d\n",
823 ibm->
flags.acpi_driver_registered = 1;
837 static int dispatch_proc_show(
struct seq_file *
m,
void *v)
841 if (!ibm || !ibm->
read)
848 return single_open(file, dispatch_proc_show, PDE(inode)->data);
851 static ssize_t dispatch_proc_write(
struct file *file,
852 const char __user *userbuf,
859 if (!ibm || !ibm->
write)
875 ret = ibm->
write(kernbuf);
886 .open = dispatch_proc_open,
890 .write = dispatch_proc_write,
893 static char *next_cmd(
char **
cmds)
898 while ((end =
strchr(start,
',')) && end == start)
920 static struct device *tpacpi_hwmon;
921 static struct input_dev *tpacpi_inputdev;
922 static struct mutex tpacpi_inputdev_send_mutex;
925 #ifdef CONFIG_PM_SLEEP
926 static int tpacpi_suspend_handler(
struct device *
dev)
940 static int tpacpi_resume_handler(
struct device *dev)
956 tpacpi_suspend_handler, tpacpi_resume_handler);
976 .shutdown = tpacpi_shutdown_handler,
1005 if (max_members == 0)
1010 max_members *
sizeof(
struct attribute *),
1014 sobj->
s.max_members = max_members;
1015 sobj->
s.group.attrs = &sobj->
a;
1016 sobj->
s.group.name =
name;
1021 #define destroy_attr_set(_set) \
1045 for (i = 0; i <
count; i++) {
1046 res = add_to_attr_set(s, attr[i]);
1060 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
1061 sysfs_create_group(_kobj, &_attr_set->group)
1063 static int parse_strtoul(
const char *
buf,
1064 unsigned long max,
unsigned long *
value)
1070 if (*endp || *value > max)
1076 static void tpacpi_disable_brightness_delay(
void)
1078 if (acpi_evalf(hkey_handle,
NULL,
"PWMS",
"qvd", 0))
1079 pr_notice(
"ACPI backlight control delay disabled\n");
1082 static void printk_deprecated_attribute(
const char *
const what,
1083 const char *
const details)
1085 tpacpi_log_usertask(
"deprecated sysfs attribute");
1086 pr_warn(
"WARNING: sysfs attribute %s is deprecated and "
1087 "will be removed. %s\n",
1128 static const char *tpacpi_rfkill_names[] = {
1151 static int tpacpi_rfk_update_swstate(
const struct tpacpi_rfk *tp_rfk)
1158 status = (tp_rfk->
ops->get_status)();
1169 static void tpacpi_rfk_update_swstate_all(
void)
1174 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[i]);
1181 static void tpacpi_rfk_update_hwblock_state(
bool blocked)
1187 tp_rfk = tpacpi_rfkill_switches[
i];
1198 static int hotkey_get_wlsw(
void);
1201 static bool tpacpi_rfk_check_hwblock_state(
void)
1203 int res = hotkey_get_wlsw();
1211 tpacpi_rfk_update_hwblock_state(hw_blocked);
1216 static int tpacpi_rfk_hook_set_block(
void *data,
bool blocked)
1222 "request to change radio state to %s\n",
1223 blocked ?
"blocked" :
"unblocked");
1226 res = (tp_rfk->
ops->set_status)(blocked ?
1230 tpacpi_rfk_update_swstate(tp_rfk);
1232 return (res < 0) ? res : 0;
1235 static const struct rfkill_ops tpacpi_rfk_rfkill_ops = {
1236 .set_block = tpacpi_rfk_hook_set_block,
1243 const bool set_default)
1247 bool sw_state =
false;
1251 BUG_ON(
id >= TPACPI_RFK_SW_MAX || tpacpi_rfkill_switches[
id]);
1258 &tpacpi_rfk_rfkill_ops,
1260 if (!atp_rfk || !atp_rfk->
rfkill) {
1261 pr_err(
"failed to allocate memory for rfkill class\n");
1267 atp_rfk->
ops = tp_rfkops;
1270 if (sw_status < 0) {
1271 pr_err(
"failed to read initial state for %s, error %d\n",
1281 hw_state = tpacpi_rfk_check_hwblock_state();
1286 pr_err(
"failed to register %s rfkill switch: %d\n", name, res);
1292 tpacpi_rfkill_switches[
id] = atp_rfk;
1294 pr_info(
"rfkill switch %s: radio is %sblocked\n",
1295 name, (sw_state || hw_state) ?
"" :
"un");
1299 static void tpacpi_destroy_rfkill(
const enum tpacpi_rfk_id id)
1303 BUG_ON(
id >= TPACPI_RFK_SW_MAX);
1305 tp_rfk = tpacpi_rfkill_switches[
id];
1309 tpacpi_rfkill_switches[
id] =
NULL;
1314 static void printk_deprecated_rfkill_attribute(
const char *
const what)
1316 printk_deprecated_attribute(what,
1317 "Please switch to generic rfkill before year 2010");
1327 printk_deprecated_rfkill_attribute(attr->
attr.name);
1330 if (tpacpi_rfk_check_hwblock_state()) {
1333 status = tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[
id]);
1339 (status == TPACPI_RFK_RADIO_ON) ? 1 : 0);
1344 const char *buf,
size_t count)
1349 printk_deprecated_rfkill_attribute(attr->
attr.name);
1351 if (parse_strtoul(buf, 1, &t))
1357 if (tpacpi_rfk_check_hwblock_state() && !!t)
1360 res = tpacpi_rfkill_switches[
id]->
ops->set_status((!!t) ?
1362 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[
id]);
1364 return (res < 0) ? res :
count;
1370 if (
id >= TPACPI_RFK_SW_MAX)
1376 if (tpacpi_rfk_check_hwblock_state()) {
1379 status = tpacpi_rfk_update_swstate(
1380 tpacpi_rfkill_switches[
id]);
1386 (status == TPACPI_RFK_RADIO_ON) ?
1387 "enabled" :
"disabled");
1388 seq_printf(m,
"commands:\tenable, disable\n");
1394 static int tpacpi_rfk_procfs_write(
const enum tpacpi_rfk_id id,
char *buf)
1400 if (
id >= TPACPI_RFK_SW_MAX)
1403 while ((cmd = next_cmd(&buf))) {
1406 else if (
strlencmp(cmd,
"disable") == 0)
1414 (status == TPACPI_RFK_RADIO_ON) ?
1415 "enable" :
"disable",
1416 tpacpi_rfkill_names[
id]);
1417 res = (tpacpi_rfkill_switches[
id]->
ops->set_status)(status);
1418 tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[
id]);
1429 static ssize_t tpacpi_driver_interface_version_show(
1437 tpacpi_driver_interface_version_show,
NULL);
1447 const char *buf,
size_t count)
1451 if (parse_strtoul(buf, 0xffff, &t))
1460 tpacpi_driver_debug_show, tpacpi_driver_debug_store);
1471 tpacpi_driver_version_show,
NULL);
1475 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1485 const char *buf,
size_t count)
1489 if (parse_strtoul(buf, 1, &t))
1492 if (tpacpi_wlsw_emulstate != !!t) {
1493 tpacpi_wlsw_emulstate = !!
t;
1494 tpacpi_rfk_update_hwblock_state(!t);
1501 tpacpi_driver_wlsw_emulstate_show,
1502 tpacpi_driver_wlsw_emulstate_store);
1505 static ssize_t tpacpi_driver_bluetooth_emulstate_show(
1512 static ssize_t tpacpi_driver_bluetooth_emulstate_store(
1514 const char *buf,
size_t count)
1518 if (parse_strtoul(buf, 1, &t))
1521 tpacpi_bluetooth_emulstate = !!
t;
1527 tpacpi_driver_bluetooth_emulstate_show,
1528 tpacpi_driver_bluetooth_emulstate_store);
1531 static ssize_t tpacpi_driver_wwan_emulstate_show(
1538 static ssize_t tpacpi_driver_wwan_emulstate_store(
1540 const char *buf,
size_t count)
1544 if (parse_strtoul(buf, 1, &t))
1547 tpacpi_wwan_emulstate = !!
t;
1553 tpacpi_driver_wwan_emulstate_show,
1554 tpacpi_driver_wwan_emulstate_store);
1557 static ssize_t tpacpi_driver_uwb_emulstate_show(
1564 static ssize_t tpacpi_driver_uwb_emulstate_store(
1566 const char *buf,
size_t count)
1570 if (parse_strtoul(buf, 1, &t))
1573 tpacpi_uwb_emulstate = !!
t;
1579 tpacpi_driver_uwb_emulstate_show,
1580 tpacpi_driver_uwb_emulstate_store);
1586 &driver_attr_debug_level, &driver_attr_version,
1587 &driver_attr_interface_version,
1596 while (!res && i <
ARRAY_SIZE(tpacpi_driver_attributes)) {
1601 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1602 if (!res && dbg_wlswemul)
1604 if (!res && dbg_bluetoothemul)
1606 if (!res && dbg_wwanemul)
1608 if (!res && dbg_uwbemul)
1615 static void tpacpi_remove_driver_attributes(
struct device_driver *drv)
1619 for (i = 0; i <
ARRAY_SIZE(tpacpi_driver_attributes); i++)
1622 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1655 #define TPV_Q(__v, __id1, __id2, __bv1, __bv2) \
1656 { .vendor = (__v), \
1657 .bios = TPID(__id1, __id2), \
1658 .ec = TPACPI_MATCH_ANY, \
1659 .quirks = TPACPI_MATCH_ANY << 16 \
1660 | (__bv1) << 8 | (__bv2) }
1662 #define TPV_Q_X(__v, __bid1, __bid2, __bv1, __bv2, \
1663 __eid, __ev1, __ev2) \
1664 { .vendor = (__v), \
1665 .bios = TPID(__bid1, __bid2), \
1667 .quirks = (__ev1) << 24 | (__ev2) << 16 \
1668 | (__bv1) << 8 | (__bv2) }
1670 #define TPV_QI0(__id1, __id2, __bv1, __bv2) \
1671 TPV_Q(PCI_VENDOR_ID_IBM, __id1, __id2, __bv1, __bv2)
1674 #define TPV_QI1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1675 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1676 __bv1, __bv2, TPID(__id1, __id2), \
1678 TPV_Q_X(PCI_VENDOR_ID_IBM, __id1, __id2, \
1679 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1683 #define TPV_QI2(__bid1, __bid2, __bv1, __bv2, \
1684 __eid1, __eid2, __ev1, __ev2) \
1685 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1686 __bv1, __bv2, TPID(__eid1, __eid2), \
1688 TPV_Q_X(PCI_VENDOR_ID_IBM, __bid1, __bid2, \
1689 __bv1, __bv2, TPACPI_MATCH_UNKNOWN, \
1692 #define TPV_QL0(__id1, __id2, __bv1, __bv2) \
1693 TPV_Q(PCI_VENDOR_ID_LENOVO, __id1, __id2, __bv1, __bv2)
1695 #define TPV_QL1(__id1, __id2, __bv1, __bv2, __ev1, __ev2) \
1696 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __id1, __id2, \
1697 __bv1, __bv2, TPID(__id1, __id2), \
1700 #define TPV_QL2(__bid1, __bid2, __bv1, __bv2, \
1701 __eid1, __eid2, __ev1, __ev2) \
1702 TPV_Q_X(PCI_VENDOR_ID_LENOVO, __bid1, __bid2, \
1703 __bv1, __bv2, TPID(__eid1, __eid2), \
1730 TPV_QI1(
'1',
'G',
'4',
'1',
'1',
'7'),
1731 TPV_QI1(
'1',
'N',
'1',
'6',
'0',
'7'),
1746 TPV_QI1(
'1',
'R',
'D',
'R',
'7',
'1'),
1748 TPV_QI1(
'1',
'V',
'7',
'1',
'2',
'8'),
1749 TPV_QI1(
'7',
'8',
'7',
'1',
'0',
'6'),
1750 TPV_QI1(
'7',
'6',
'6',
'9',
'1',
'6'),
1751 TPV_QI1(
'7',
'0',
'6',
'9',
'2',
'8'),
1756 TPV_QI1(
'1',
'A',
'6',
'4',
'2',
'3'),
1757 TPV_QI1(
'1',
'I',
'7',
'1',
'2',
'0'),
1758 TPV_QI1(
'1',
'Y',
'6',
'5',
'2',
'9'),
1760 TPV_QL1(
'7',
'9',
'E',
'3',
'5',
'0'),
1761 TPV_QL1(
'7',
'C',
'D',
'2',
'2',
'2'),
1762 TPV_QL1(
'7',
'E',
'D',
'0',
'1',
'5'),
1765 TPV_QI2(
'1',
'W',
'9',
'0',
'1',
'V',
'2',
'8'),
1766 TPV_QL2(
'7',
'I',
'3',
'4',
'7',
'9',
'5',
'0'),
1772 TPV_QI1(
'1',
'K',
'4',
'8',
'1',
'8'),
1773 TPV_QI1(
'1',
'Q',
'9',
'7',
'2',
'3'),
1774 TPV_QI1(
'1',
'U',
'D',
'3',
'B',
'2'),
1775 TPV_QI1(
'7',
'4',
'6',
'4',
'2',
'7'),
1776 TPV_QI1(
'7',
'5',
'6',
'0',
'2',
'0'),
1778 TPV_QL1(
'7',
'B',
'D',
'7',
'4',
'0'),
1779 TPV_QL1(
'7',
'J',
'3',
'0',
'1',
'3'),
1793 static void __init tpacpi_check_outdated_fw(
void)
1795 unsigned long fwvers;
1796 u16 ec_version, bios_version;
1798 fwvers = tpacpi_check_quirks(tpacpi_bios_version_qtable,
1804 bios_version = fwvers & 0xffff
U;
1805 ec_version = (fwvers >> 16) & 0xffffU;
1808 if ((bios_version > thinkpad_id.bios_release) ||
1809 (ec_version > thinkpad_id.ec_release &&
1818 pr_warn(
"WARNING: Outdated ThinkPad BIOS/EC firmware\n");
1819 pr_warn(
"WARNING: This firmware may be missing critical bug "
1820 "fixes and/or important features\n");
1824 static bool __init tpacpi_is_fw_known(
void)
1826 return tpacpi_check_quirks(tpacpi_bios_version_qtable,
1827 ARRAY_SIZE(tpacpi_bios_version_qtable)) != 0;
1842 static int thinkpad_acpi_driver_read(
struct seq_file *m)
1849 static struct ibm_struct thinkpad_acpi_driver_data = {
1851 .read = thinkpad_acpi_driver_read,
1948 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1949 struct tp_nvram_state {
1950 u16 thinkpad_toggle:1;
1952 u16 display_toggle:1;
1953 u16 thinklight_toggle:1;
1954 u16 hibernate_toggle:1;
1955 u16 displayexp_toggle:1;
1956 u16 display_state:1;
1957 u16 brightness_toggle:1;
1958 u16 volume_toggle:1;
1961 u8 brightness_level;
1969 static struct mutex hotkey_thread_mutex;
1980 static struct mutex hotkey_thread_data_mutex;
1981 static unsigned int hotkey_config_change;
1994 static unsigned int hotkey_poll_freq = 10;
1996 #define HOTKEY_CONFIG_CRITICAL_START \
1998 mutex_lock(&hotkey_thread_data_mutex); \
1999 hotkey_config_change++; \
2001 #define HOTKEY_CONFIG_CRITICAL_END \
2002 mutex_unlock(&hotkey_thread_data_mutex);
2006 #define hotkey_source_mask 0U
2007 #define HOTKEY_CONFIG_CRITICAL_START
2008 #define HOTKEY_CONFIG_CRITICAL_END
2012 static struct mutex hotkey_mutex;
2018 } hotkey_wakeup_reason;
2020 static int hotkey_autosleep_ack;
2022 static u32 hotkey_orig_mask;
2023 static u32 hotkey_all_mask;
2024 static u32 hotkey_reserved_mask;
2025 static u32 hotkey_driver_mask;
2026 static u32 hotkey_user_mask;
2027 static u32 hotkey_acpi_mask;
2029 static unsigned int hotkey_report_mode;
2031 static u16 *hotkey_keycode_map;
2035 static void tpacpi_driver_event(
const unsigned int hkey_event);
2036 static void hotkey_driver_event(
const unsigned int scancode);
2037 static void hotkey_poll_setup(
const bool may_warn);
2040 #define TP_HOTKEY_TABLET_MASK (1 << 3)
2042 static int hotkey_get_wlsw(
void)
2046 if (!tp_features.hotkey_wlsw)
2049 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2051 return (tpacpi_wlsw_emulstate) ?
2055 if (!acpi_evalf(hkey_handle, &status,
"WLSW",
"d"))
2061 static int hotkey_get_tablet_mode(
int *status)
2065 if (!acpi_evalf(hkey_handle, &s,
"MHKG",
"d"))
2080 static int hotkey_mask_get(
void)
2082 if (tp_features.hotkey_mask) {
2085 if (!acpi_evalf(hkey_handle, &m,
"DHKN",
"d"))
2088 hotkey_acpi_mask =
m;
2091 hotkey_acpi_mask = hotkey_all_mask;
2100 void static hotkey_mask_warn_incomplete_mask(
void)
2103 const u32 wantedmask = hotkey_driver_mask &
2108 pr_notice(
"required events 0x%08x not enabled!\n", wantedmask);
2120 static int hotkey_mask_set(
u32 mask)
2125 const u32 fwmask = mask & ~hotkey_source_mask;
2127 if (tp_features.hotkey_mask) {
2128 for (i = 0; i < 32; i++) {
2129 if (!acpi_evalf(hkey_handle,
2130 NULL,
"MHKM",
"vdd", i + 1,
2131 !!(mask & (1 << i)))) {
2145 if (!hotkey_mask_get() && !rc && (fwmask & ~hotkey_acpi_mask)) {
2146 pr_notice(
"asked for hotkey mask 0x%08x, but "
2147 "firmware forced it to 0x%08x\n",
2148 fwmask, hotkey_acpi_mask);
2152 hotkey_mask_warn_incomplete_mask();
2162 static int hotkey_user_mask_set(
const u32 mask)
2168 if (!tp_warned.hotkey_mask_ff &&
2169 (mask == 0xffff || mask == 0xffffff ||
2170 mask == 0xffffffff)) {
2171 tp_warned.hotkey_mask_ff = 1;
2172 pr_notice(
"setting the hotkey mask to 0x%08x is likely "
2173 "not the best way to go about it\n", mask);
2174 pr_notice(
"please consider using the driver defaults, "
2175 "and refer to up-to-date thinkpad-acpi "
2181 rc = hotkey_mask_set((mask | hotkey_driver_mask) & ~hotkey_source_mask);
2194 static int tpacpi_hotkey_driver_mask_set(
const u32 mask)
2199 if (!tp_features.hotkey) {
2200 hotkey_driver_mask =
mask;
2207 hotkey_driver_mask =
mask;
2208 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2209 hotkey_source_mask |= (mask & ~hotkey_all_mask);
2213 rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) &
2214 ~hotkey_source_mask);
2215 hotkey_poll_setup(
true);
2222 static int hotkey_status_get(
int *status)
2224 if (!acpi_evalf(hkey_handle, status,
"DHKC",
"d"))
2230 static int hotkey_status_set(
bool enable)
2232 if (!acpi_evalf(hkey_handle,
NULL,
"MHKC",
"vd", enable ? 1 : 0))
2238 static void tpacpi_input_send_tabletsw(
void)
2242 if (tp_features.hotkey_tablet &&
2243 !hotkey_get_tablet_mode(&state)) {
2246 input_report_switch(tpacpi_inputdev,
2248 input_sync(tpacpi_inputdev);
2255 static void tpacpi_input_send_key(
const unsigned int scancode)
2257 const unsigned int keycode = hotkey_keycode_map[scancode];
2263 input_report_key(tpacpi_inputdev, keycode, 1);
2264 input_sync(tpacpi_inputdev);
2267 input_report_key(tpacpi_inputdev, keycode, 0);
2268 input_sync(tpacpi_inputdev);
2275 static void tpacpi_input_send_key_masked(
const unsigned int scancode)
2277 hotkey_driver_event(scancode);
2278 if (hotkey_user_mask & (1 << scancode))
2279 tpacpi_input_send_key(scancode);
2282 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2286 static void tpacpi_hotkey_send_key(
unsigned int scancode)
2288 tpacpi_input_send_key_masked(scancode);
2289 if (hotkey_report_mode < 2) {
2290 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device,
2295 static void hotkey_read_nvram(
struct tp_nvram_state *
n,
const u32 m)
2312 n->displayexp_toggle =
2319 n->brightness_toggle =
2331 static void hotkey_compare_and_issue_event(
struct tp_nvram_state *oldn,
2332 struct tp_nvram_state *newn,
2333 const u32 event_mask)
2336 #define TPACPI_COMPARE_KEY(__scancode, __member) \
2338 if ((event_mask & (1 << __scancode)) && \
2339 oldn->__member != newn->__member) \
2340 tpacpi_hotkey_send_key(__scancode); \
2343 #define TPACPI_MAY_SEND_KEY(__scancode) \
2345 if (event_mask & (1 << __scancode)) \
2346 tpacpi_hotkey_send_key(__scancode); \
2349 void issue_volchange(
const unsigned int oldvol,
2350 const unsigned int newvol)
2352 unsigned int i = oldvol;
2354 while (i > newvol) {
2358 while (i < newvol) {
2364 void issue_brightnesschange(
const unsigned int oldbrt,
2365 const unsigned int newbrt)
2367 unsigned int i = oldbrt;
2369 while (i > newbrt) {
2373 while (i < newbrt) {
2408 oldn->volume_toggle != newn->volume_toggle ||
2409 oldn->volume_level != newn->volume_level) {
2412 issue_volchange(oldn->volume_level, newn->volume_level);
2421 if (oldn->volume_level != newn->volume_level) {
2422 issue_volchange(oldn->volume_level, newn->volume_level);
2423 }
else if (oldn->volume_toggle != newn->volume_toggle) {
2425 if (newn->volume_level == 0)
2433 if (oldn->brightness_level != newn->brightness_level) {
2434 issue_brightnesschange(oldn->brightness_level,
2435 newn->brightness_level);
2436 }
else if (oldn->brightness_toggle != newn->brightness_toggle) {
2438 if (newn->brightness_level == 0)
2440 else if (newn->brightness_level >= bright_maxlvl
2441 && !tp_features.bright_unkfw)
2445 #undef TPACPI_COMPARE_KEY
2446 #undef TPACPI_MAY_SEND_KEY
2456 static int hotkey_kthread(
void *data)
2458 struct tp_nvram_state s[2];
2459 u32 poll_mask, event_mask;
2460 unsigned int si, so;
2462 unsigned int change_detector;
2463 unsigned int poll_freq;
2479 change_detector = hotkey_config_change;
2481 event_mask = hotkey_source_mask &
2482 (hotkey_driver_mask | hotkey_user_mask);
2483 poll_freq = hotkey_poll_freq;
2485 hotkey_read_nvram(&s[so], poll_mask);
2498 if (t > 0 && !was_frozen)
2502 if (was_frozen || hotkey_config_change != change_detector) {
2506 change_detector = hotkey_config_change;
2509 event_mask = hotkey_source_mask &
2510 (hotkey_driver_mask | hotkey_user_mask);
2511 poll_freq = hotkey_poll_freq;
2515 hotkey_read_nvram(&s[si], poll_mask);
2517 hotkey_compare_and_issue_event(&s[so], &s[si],
2532 static void hotkey_poll_stop_sync(
void)
2534 if (tpacpi_hotkey_task) {
2536 tpacpi_hotkey_task =
NULL;
2544 static void hotkey_poll_setup(
const bool may_warn)
2549 if (hotkey_poll_freq > 0 &&
2550 (poll_driver_mask ||
2551 (poll_user_mask && tpacpi_inputdev->users > 0))) {
2552 if (!tpacpi_hotkey_task) {
2555 if (IS_ERR(tpacpi_hotkey_task)) {
2556 tpacpi_hotkey_task =
NULL;
2557 pr_err(
"could not create kernel thread "
2558 "for hotkey polling\n");
2562 hotkey_poll_stop_sync();
2563 if (may_warn && (poll_driver_mask || poll_user_mask) &&
2564 hotkey_poll_freq == 0) {
2565 pr_notice(
"hot keys 0x%08x and/or events 0x%08x "
2566 "require polling, which is currently "
2568 poll_user_mask, poll_driver_mask);
2573 static void hotkey_poll_setup_safe(
const bool may_warn)
2576 hotkey_poll_setup(may_warn);
2581 static void hotkey_poll_set_freq(
unsigned int freq)
2584 hotkey_poll_stop_sync();
2586 hotkey_poll_freq =
freq;
2591 static void hotkey_poll_setup(
const bool __unused)
2595 static void hotkey_poll_setup_safe(
const bool __unused)
2601 static int hotkey_inputdev_open(
struct input_dev *dev)
2603 switch (tpacpi_lifecycle) {
2606 hotkey_poll_setup_safe(
false);
2617 static void hotkey_inputdev_close(
struct input_dev *dev)
2621 !(hotkey_source_mask & hotkey_driver_mask))
2622 hotkey_poll_setup_safe(
false);
2632 printk_deprecated_attribute(
"hotkey_enable",
2633 "Hotkey reporting is always enabled");
2635 res = hotkey_status_get(&status);
2644 const char *buf,
size_t count)
2648 printk_deprecated_attribute(
"hotkey_enable",
2649 "Hotkeys can be disabled through hotkey_mask");
2651 if (parse_strtoul(buf, 1, &t))
2662 hotkey_enable_show, hotkey_enable_store);
2674 const char *buf,
size_t count)
2679 if (parse_strtoul(buf, 0xffffffffUL, &t))
2685 res = hotkey_user_mask_set(t);
2687 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2688 hotkey_poll_setup(
true);
2695 return (res) ? res :
count;
2700 hotkey_mask_show, hotkey_mask_store);
2718 printk_deprecated_attribute(
"hotkey_bios_mask",
2719 "This attribute is useless.");
2732 hotkey_all_mask | hotkey_source_mask);
2739 static ssize_t hotkey_recommended_mask_show(
struct device *dev,
2744 (hotkey_all_mask | hotkey_source_mask)
2745 & ~hotkey_reserved_mask);
2750 hotkey_recommended_mask_show,
NULL);
2752 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2764 const char *buf,
size_t count)
2770 if (parse_strtoul(buf, 0xffffffffUL, &t) ||
2778 hotkey_source_mask =
t;
2781 rc = hotkey_mask_set((hotkey_user_mask | hotkey_driver_mask) &
2782 ~hotkey_source_mask);
2783 hotkey_poll_setup(
true);
2786 r_ev = hotkey_driver_mask & ~(hotkey_acpi_mask & hotkey_all_mask)
2792 pr_err(
"hotkey_source_mask: "
2793 "failed to update the firmware event mask!\n");
2797 "some important events were disabled: 0x%04x\n",
2802 return (rc < 0) ? rc :
count;
2807 hotkey_source_mask_show, hotkey_source_mask_store);
2819 const char *buf,
size_t count)
2823 if (parse_strtoul(buf, 25, &t))
2829 hotkey_poll_set_freq(t);
2830 hotkey_poll_setup(
true);
2841 hotkey_poll_freq_show, hotkey_poll_freq_store);
2851 res = hotkey_get_wlsw();
2856 tpacpi_rfk_update_hwblock_state((res == TPACPI_RFK_RADIO_OFF));
2859 (res == TPACPI_RFK_RADIO_OFF) ? 0 : 1);
2865 static void hotkey_radio_sw_notify_change(
void)
2867 if (tp_features.hotkey_wlsw)
2878 res = hotkey_get_tablet_mode(&s);
2888 static void hotkey_tablet_mode_notify_change(
void)
2890 if (tp_features.hotkey_tablet)
2892 "hotkey_tablet_mode");
2901 (hotkey_report_mode != 0) ? hotkey_report_mode : 1);
2908 static ssize_t hotkey_wakeup_reason_show(
struct device *dev,
2918 static void hotkey_wakeup_reason_notify_change(
void)
2925 static ssize_t hotkey_wakeup_hotunplug_complete_show(
struct device *dev,
2934 hotkey_wakeup_hotunplug_complete_show,
NULL);
2936 static void hotkey_wakeup_hotunplug_complete_notify_change(
void)
2939 "wakeup_hotunplug_complete");
2945 &dev_attr_hotkey_enable.
attr,
2946 &dev_attr_hotkey_bios_enabled.
attr,
2947 &dev_attr_hotkey_bios_mask.
attr,
2948 &dev_attr_hotkey_report_mode.
attr,
2949 &dev_attr_hotkey_wakeup_reason.
attr,
2950 &dev_attr_hotkey_wakeup_hotunplug_complete.
attr,
2951 &dev_attr_hotkey_mask.
attr,
2952 &dev_attr_hotkey_all_mask.
attr,
2953 &dev_attr_hotkey_recommended_mask.
attr,
2954 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2955 &dev_attr_hotkey_source_mask.
attr,
2956 &dev_attr_hotkey_poll_freq.
attr,
2963 static void tpacpi_send_radiosw_update(
void)
2978 wlsw = hotkey_get_wlsw();
2981 if (wlsw == TPACPI_RFK_RADIO_OFF)
2982 tpacpi_rfk_update_hwblock_state(
true);
2985 tpacpi_rfk_update_swstate_all();
2988 if (wlsw == TPACPI_RFK_RADIO_ON)
2989 tpacpi_rfk_update_hwblock_state(
false);
2995 input_report_switch(tpacpi_inputdev,
2997 input_sync(tpacpi_inputdev);
3006 hotkey_radio_sw_notify_change();
3009 static void hotkey_exit(
void)
3011 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3013 hotkey_poll_stop_sync();
3017 if (hotkey_dev_attributes)
3018 delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->
dev.kobj);
3021 "restoring original HKEY status and mask\n");
3024 if (((tp_features.hotkey_mask &&
3025 hotkey_mask_set(hotkey_orig_mask)) |
3026 hotkey_status_set(
false)) != 0)
3027 pr_err(
"failed to restore hot key mask "
3028 "to BIOS defaults\n");
3031 static void __init hotkey_unmap(
const unsigned int scancode)
3035 tpacpi_inputdev->keybit);
3045 #define TPACPI_HK_Q_INIMASK 0x0001
3047 static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = {
3105 TPACPI_KEYMAP_IBM_GENERIC = 0,
3106 TPACPI_KEYMAP_LENOVO_GENERIC,
3109 static const tpacpi_keymap_t tpacpi_keymaps[] __initconst = {
3111 [TPACPI_KEYMAP_IBM_GENERIC] = {
3147 [TPACPI_KEYMAP_LENOVO_GENERIC] = {
3201 static const struct tpacpi_quirk tpacpi_keymap_qtable[] __initconst = {
3206 .quirks = TPACPI_KEYMAP_IBM_GENERIC,
3211 .quirks = TPACPI_KEYMAP_LENOVO_GENERIC,
3215 #define TPACPI_HOTKEY_MAP_SIZE sizeof(tpacpi_keymap_t)
3216 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(tpacpi_keymap_entry_t)
3221 bool radiosw_state =
false;
3222 bool tabletsw_state =
false;
3225 unsigned long keymap_id;
3228 "initializing hotkey subdriver\n");
3230 BUG_ON(!tpacpi_inputdev);
3232 tpacpi_inputdev->close !=
NULL);
3237 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3243 tp_features.hotkey = hkey_handle !=
NULL;
3247 str_supported(tp_features.hotkey));
3249 if (!tp_features.hotkey)
3252 quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable,
3255 tpacpi_disable_brightness_delay();
3259 hotkey_dev_attributes = create_attr_set(
3262 if (!hotkey_dev_attributes)
3264 res = add_many_to_attr_set(hotkey_dev_attributes,
3273 if (acpi_evalf(hkey_handle, &hkeyv,
"MHKV",
"qd")) {
3274 if ((hkeyv >> 8) != 1) {
3275 pr_err(
"unknown version of the HKEY interface: 0x%x\n",
3284 "firmware HKEY interface version: 0x%x\n",
3288 if (!acpi_evalf(hkey_handle, &hotkey_all_mask,
3290 pr_err(
"missing MHKA handler, "
3291 "please report this to %s\n",
3294 hotkey_all_mask = 0x080c
U;
3296 tp_features.hotkey_mask = 1;
3302 "hotkey masks are %s\n",
3303 str_supported(tp_features.hotkey_mask));
3306 if (!tp_features.hotkey_mask && !hotkey_all_mask &&
3308 hotkey_all_mask = 0x080c
U;
3311 if (tp_features.hotkey_mask) {
3314 res = hotkey_mask_get();
3318 hotkey_orig_mask = hotkey_acpi_mask;
3320 hotkey_orig_mask = hotkey_all_mask;
3321 hotkey_acpi_mask = hotkey_all_mask;
3324 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3326 tp_features.hotkey_wlsw = 1;
3327 radiosw_state = !!tpacpi_wlsw_emulstate;
3328 pr_info(
"radio switch emulation enabled\n");
3332 if (acpi_evalf(hkey_handle, &status,
"WLSW",
"qd")) {
3333 tp_features.hotkey_wlsw = 1;
3334 radiosw_state = !!
status;
3335 pr_info(
"radio switch found; radios are %s\n",
3338 if (tp_features.hotkey_wlsw)
3339 res = add_to_attr_set(hotkey_dev_attributes,
3340 &dev_attr_hotkey_radio_sw.
attr);
3343 if (!res && acpi_evalf(hkey_handle, &status,
"MHKG",
"qd")) {
3344 tp_features.hotkey_tablet = 1;
3346 pr_info(
"possible tablet mode switch found; "
3347 "ThinkPad in %s mode\n",
3348 (tabletsw_state) ?
"tablet" :
"laptop");
3349 res = add_to_attr_set(hotkey_dev_attributes,
3350 &dev_attr_hotkey_tablet_mode.
attr);
3355 hotkey_dev_attributes,
3356 &tpacpi_pdev->
dev.kobj);
3363 if (!hotkey_keycode_map) {
3364 pr_err(
"failed to allocate memory for key map\n");
3369 keymap_id = tpacpi_check_quirks(tpacpi_keymap_qtable,
3373 "using keymap number %lu\n", keymap_id);
3375 memcpy(hotkey_keycode_map, &tpacpi_keymaps[keymap_id],
3381 tpacpi_inputdev->keycode = hotkey_keycode_map;
3384 input_set_capability(tpacpi_inputdev,
EV_KEY,
3385 hotkey_keycode_map[i]);
3387 if (i <
sizeof(hotkey_reserved_mask)*8)
3388 hotkey_reserved_mask |= 1 <<
i;
3392 if (tp_features.hotkey_wlsw) {
3394 input_report_switch(tpacpi_inputdev,
3397 if (tp_features.hotkey_tablet) {
3399 input_report_switch(tpacpi_inputdev,
3407 pr_info(
"This ThinkPad has standard ACPI backlight "
3408 "brightness control, supported by the ACPI "
3410 pr_notice(
"Disabling thinkpad-acpi brightness events "
3416 hotkey_reserved_mask |=
3423 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
3426 & ~hotkey_reserved_mask;
3429 "hotkey source mask 0x%08x, polling freq %u\n",
3430 hotkey_source_mask, hotkey_poll_freq);
3434 "enabling firmware HKEY event interface...\n");
3435 res = hotkey_status_set(
true);
3440 res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask)
3441 | hotkey_driver_mask)
3442 & ~hotkey_source_mask);
3443 if (res < 0 && res != -
ENXIO) {
3448 & ~hotkey_reserved_mask;
3450 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
3451 hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask);
3454 "legacy ibm/hotkey event reporting over procfs %s\n",
3455 (hotkey_report_mode < 2) ?
3456 "enabled" :
"disabled");
3458 tpacpi_inputdev->open = &hotkey_inputdev_open;
3459 tpacpi_inputdev->close = &hotkey_inputdev_close;
3461 hotkey_poll_setup_safe(
true);
3466 delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->
dev.kobj);
3467 hotkey_dev_attributes =
NULL;
3469 return (res < 0)? res : 1;
3472 static bool hotkey_notify_hotkey(
const u32 hkey,
3474 bool *ignore_acpi_ev)
3477 unsigned int scancode = hkey & 0xfff;
3478 *send_acpi_ev =
true;
3479 *ignore_acpi_ev =
false;
3484 if (!(hotkey_source_mask & (1 << scancode))) {
3485 tpacpi_input_send_key_masked(scancode);
3486 *send_acpi_ev =
false;
3488 *ignore_acpi_ev =
true;
3495 static bool hotkey_notify_wakeup(
const u32 hkey,
3497 bool *ignore_acpi_ev)
3500 *send_acpi_ev =
true;
3501 *ignore_acpi_ev =
false;
3507 *ignore_acpi_ev =
true;
3513 *ignore_acpi_ev =
true;
3518 pr_alert(
"EMERGENCY WAKEUP: battery almost empty\n");
3529 pr_info(
"woke up due to a hot-unplug request...\n");
3530 hotkey_wakeup_reason_notify_change();
3535 static bool hotkey_notify_dockevent(
const u32 hkey,
3537 bool *ignore_acpi_ev)
3540 *send_acpi_ev =
true;
3541 *ignore_acpi_ev =
false;
3546 hotkey_autosleep_ack = 1;
3548 hotkey_wakeup_hotunplug_complete_notify_change();
3552 pr_info(
"docked into hotplug port replicator\n");
3555 pr_info(
"undocked from hotplug port replicator\n");
3563 static bool hotkey_notify_usrevent(
const u32 hkey,
3565 bool *ignore_acpi_ev)
3568 *send_acpi_ev =
true;
3569 *ignore_acpi_ev =
false;
3578 tpacpi_input_send_tabletsw();
3579 hotkey_tablet_mode_notify_change();
3580 *send_acpi_ev =
false;
3587 *ignore_acpi_ev =
true;
3595 static void thermal_dump_all_sensors(
void);
3597 static bool hotkey_notify_6xxx(
const u32 hkey,
3599 bool *ignore_acpi_ev)
3604 *send_acpi_ev =
true;
3605 *ignore_acpi_ev =
false;
3609 pr_info(
"EC reports that Thermal Table has changed\n");
3614 pr_crit(
"THERMAL ALARM: battery is too hot!\n");
3618 pr_alert(
"THERMAL EMERGENCY: battery is extremely hot!\n");
3623 "a sensor reports something is too hot!\n");
3629 "a sensor reports something is extremely hot!\n");
3637 *send_acpi_ev =
false;
3638 *ignore_acpi_ev =
true;
3642 pr_warn(
"unknown possible thermal alarm or keyboard event received\n");
3646 thermal_dump_all_sensors();
3651 static void hotkey_notify(
struct ibm_struct *ibm,
u32 event)
3655 bool ignore_acpi_ev;
3658 if (event != 0x80) {
3659 pr_err(
"unknown HKEY notification event %d\n", event);
3662 ibm->
acpi->device->pnp.device_class,
3663 dev_name(&ibm->
acpi->device->dev),
3669 if (!acpi_evalf(hkey_handle, &hkey,
"MHKP",
"d")) {
3670 pr_err(
"failed to retrieve HKEY event\n");
3679 send_acpi_ev =
true;
3680 ignore_acpi_ev =
false;
3682 switch (hkey >> 12) {
3685 known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev,
3690 known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev,
3697 hotkey_autosleep_ack = 1;
3699 hotkey_wakeup_hotunplug_complete_notify_change();
3712 known_ev = hotkey_notify_dockevent(hkey, &send_acpi_ev,
3717 known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev,
3723 known_ev = hotkey_notify_6xxx(hkey, &send_acpi_ev,
3728 if (tp_features.hotkey_wlsw &&
3730 tpacpi_send_radiosw_update();
3740 pr_notice(
"unhandled HKEY event 0x%04x\n", hkey);
3741 pr_notice(
"please report the conditions when this "
3746 if (!ignore_acpi_ev &&
3747 (send_acpi_ev || hotkey_report_mode < 2)) {
3748 acpi_bus_generate_proc_event(ibm->
acpi->device,
3753 if (!ignore_acpi_ev && send_acpi_ev) {
3755 ibm->
acpi->device->pnp.device_class,
3756 dev_name(&ibm->
acpi->device->dev),
3762 static void hotkey_suspend(
void)
3766 hotkey_autosleep_ack = 0;
3769 static void hotkey_resume(
void)
3771 tpacpi_disable_brightness_delay();
3773 if (hotkey_status_set(
true) < 0 ||
3774 hotkey_mask_set(hotkey_acpi_mask) < 0)
3775 pr_err(
"error while attempting to reset the event "
3776 "firmware interface\n");
3778 tpacpi_send_radiosw_update();
3779 hotkey_tablet_mode_notify_change();
3780 hotkey_wakeup_reason_notify_change();
3781 hotkey_wakeup_hotunplug_complete_notify_change();
3782 hotkey_poll_setup_safe(
false);
3786 static int hotkey_read(
struct seq_file *m)
3790 if (!tp_features.hotkey) {
3797 res = hotkey_status_get(&status);
3799 res = hotkey_mask_get();
3805 if (hotkey_all_mask) {
3806 seq_printf(m,
"mask:\t\t0x%08x\n", hotkey_user_mask);
3807 seq_printf(m,
"commands:\tenable, disable, reset, <mask>\n");
3810 seq_printf(m,
"commands:\tenable, disable, reset\n");
3816 static void hotkey_enabledisable_warn(
bool enable)
3818 tpacpi_log_usertask(
"procfs hotkey enable/disable");
3820 pr_fmt(
"hotkey enable/disable functionality has been "
3821 "removed from the driver. "
3822 "Hotkeys are always enabled.\n")))
3823 pr_err(
"Please remove the hotkey=enable module "
3824 "parameter, it is deprecated. "
3825 "Hotkeys are always enabled.\n");
3828 static int hotkey_write(
char *buf)
3834 if (!tp_features.hotkey)
3840 mask = hotkey_user_mask;
3843 while ((cmd = next_cmd(&buf))) {
3845 hotkey_enabledisable_warn(1);
3846 }
else if (
strlencmp(cmd,
"disable") == 0) {
3847 hotkey_enabledisable_warn(0);
3849 }
else if (
strlencmp(cmd,
"reset") == 0) {
3851 & ~hotkey_reserved_mask;
3852 }
else if (
sscanf(cmd,
"0x%x", &mask) == 1) {
3854 }
else if (
sscanf(cmd,
"%x", &mask) == 1) {
3864 "set mask to 0x%08x\n", mask);
3865 res = hotkey_user_mask_set(mask);
3880 .hid = ibm_htk_device_ids,
3881 .notify = hotkey_notify,
3882 .handle = &hkey_handle,
3886 static struct ibm_struct hotkey_driver_data = {
3888 .read = hotkey_read,
3889 .write = hotkey_write,
3890 .exit = hotkey_exit,
3891 .resume = hotkey_resume,
3892 .suspend = hotkey_suspend,
3893 .acpi = &ibm_hotkey_acpidriver,
3917 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw"
3919 static int bluetooth_get_status(
void)
3923 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3924 if (dbg_bluetoothemul)
3925 return (tpacpi_bluetooth_emulstate) ?
3929 if (!acpi_evalf(hkey_handle, &status,
"GBDC",
"d"))
3941 "will attempt to %s bluetooth\n",
3942 (state == TPACPI_RFK_RADIO_ON) ?
"enable" :
"disable");
3944 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3945 if (dbg_bluetoothemul) {
3951 if (state == TPACPI_RFK_RADIO_ON)
3957 if (!acpi_evalf(hkey_handle,
NULL,
"SBDC",
"vd", status))
3974 const char *buf,
size_t count)
3982 bluetooth_enable_show, bluetooth_enable_store);
3986 static struct attribute *bluetooth_attributes[] = {
3987 &dev_attr_bluetooth_enable.
attr,
3992 .attrs = bluetooth_attributes,
3996 .get_status = bluetooth_get_status,
3997 .set_status = bluetooth_set_status,
4000 static void bluetooth_shutdown(
void)
4003 if (!acpi_evalf(
NULL,
NULL,
"\\BLTH",
"vd",
4005 pr_notice(
"failed to save bluetooth state to NVRAM\n");
4008 "bluetooth state saved to NVRAM\n");
4011 static void bluetooth_exit(
void)
4014 &bluetooth_attr_group);
4018 bluetooth_shutdown();
4027 "initializing bluetooth subdriver\n");
4033 tp_features.bluetooth = hkey_handle &&
4034 acpi_evalf(hkey_handle, &status,
"GBDC",
"qd");
4037 "bluetooth is %s, status 0x%02x\n",
4038 str_supported(tp_features.bluetooth),
4041 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4042 if (dbg_bluetoothemul) {
4043 tp_features.bluetooth = 1;
4044 pr_info(
"bluetooth switch emulation enabled\n");
4047 if (tp_features.bluetooth &&
4050 tp_features.bluetooth = 0;
4052 "bluetooth hardware not installed\n");
4055 if (!tp_features.bluetooth)
4059 &bluetooth_tprfk_ops,
4067 &bluetooth_attr_group);
4077 static int bluetooth_read(
struct seq_file *m)
4082 static int bluetooth_write(
char *buf)
4087 static struct ibm_struct bluetooth_driver_data = {
4088 .name =
"bluetooth",
4089 .read = bluetooth_read,
4090 .write = bluetooth_write,
4091 .exit = bluetooth_exit,
4092 .shutdown = bluetooth_shutdown,
4107 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw"
4109 static int wan_get_status(
void)
4113 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4115 return (tpacpi_wwan_emulstate) ?
4119 if (!acpi_evalf(hkey_handle, &status,
"GWAN",
"d"))
4131 "will attempt to %s wwan\n",
4132 (state == TPACPI_RFK_RADIO_ON) ?
"enable" :
"disable");
4134 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4141 if (state == TPACPI_RFK_RADIO_ON)
4147 if (!acpi_evalf(hkey_handle,
NULL,
"SWAN",
"vd", status))
4164 const char *buf,
size_t count)
4172 wan_enable_show, wan_enable_store);
4176 static struct attribute *wan_attributes[] = {
4177 &dev_attr_wan_enable.
attr,
4182 .attrs = wan_attributes,
4186 .get_status = wan_get_status,
4187 .set_status = wan_set_status,
4190 static void wan_shutdown(
void)
4193 if (!acpi_evalf(
NULL,
NULL,
"\\WGSV",
"vd",
4195 pr_notice(
"failed to save WWAN state to NVRAM\n");
4198 "WWAN state saved to NVRAM\n");
4201 static void wan_exit(
void)
4217 "initializing wan subdriver\n");
4221 tp_features.wan = hkey_handle &&
4222 acpi_evalf(hkey_handle, &status,
"GWAN",
"qd");
4225 "wan is %s, status 0x%02x\n",
4226 str_supported(tp_features.wan),
4229 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4231 tp_features.wan = 1;
4232 pr_info(
"wwan switch emulation enabled\n");
4235 if (tp_features.wan &&
4238 tp_features.wan = 0;
4240 "wan hardware not installed\n");
4243 if (!tp_features.wan)
4266 static int wan_read(
struct seq_file *m)
4271 static int wan_write(
char *buf)
4281 .shutdown = wan_shutdown,
4294 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw"
4296 static int uwb_get_status(
void)
4300 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4302 return (tpacpi_uwb_emulstate) ?
4306 if (!acpi_evalf(hkey_handle, &status,
"GUWB",
"d"))
4318 "will attempt to %s UWB\n",
4319 (state == TPACPI_RFK_RADIO_ON) ?
"enable" :
"disable");
4321 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4328 if (state == TPACPI_RFK_RADIO_ON)
4333 if (!acpi_evalf(hkey_handle,
NULL,
"SUWB",
"vd", status))
4342 .get_status = uwb_get_status,
4343 .set_status = uwb_set_status,
4346 static void uwb_exit(
void)
4357 "initializing uwb subdriver\n");
4361 tp_features.uwb = hkey_handle &&
4362 acpi_evalf(hkey_handle, &status,
"GUWB",
"qd");
4365 "uwb is %s, status 0x%02x\n",
4366 str_supported(tp_features.uwb),
4369 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
4371 tp_features.uwb = 1;
4372 pr_info(
"uwb switch emulation enabled\n");
4375 if (tp_features.uwb &&
4378 tp_features.uwb = 0;
4380 "uwb hardware not installed\n");
4383 if (!tp_features.uwb)
4397 .flags.experimental = 1,
4404 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
4406 enum video_access_mode {
4407 TPACPI_VIDEO_NONE = 0,
4414 TP_ACPI_VIDEO_S_LCD = 0x01,
4415 TP_ACPI_VIDEO_S_CRT = 0x02,
4416 TP_ACPI_VIDEO_S_DVI = 0x08,
4420 TP_ACPI_VIDEO_570_PHSCMD = 0x87,
4421 TP_ACPI_VIDEO_570_PHSMASK = 0x03,
4423 TP_ACPI_VIDEO_570_PHS2CMD = 0x8b,
4424 TP_ACPI_VIDEO_570_PHS2SET = 0x80,
4427 static enum video_access_mode video_supported;
4428 static int video_orig_autosw;
4430 static int video_autosw_get(
void);
4431 static int video_autosw_set(
int enable);
4434 "\\_SB.PCI.AGP.VGA",
4435 "\\_SB.PCI0.AGP0.VID0",
4438 "\\_SB.PCI0.AGP.VGA",
4439 "\\_SB.PCI0.AGP.VID",
4451 if (tpacpi_is_ibm())
4454 if (vid2_handle && acpi_evalf(
NULL, &ivga,
"\\IVGA",
"d") && ivga)
4456 vid_handle = vid2_handle;
4460 video_supported = TPACPI_VIDEO_NONE;
4461 else if (tpacpi_is_ibm() &&
4462 acpi_evalf(vid_handle, &video_orig_autosw,
"SWIT",
"qd"))
4464 video_supported = TPACPI_VIDEO_570;
4465 else if (tpacpi_is_ibm() &&
4466 acpi_evalf(vid_handle, &video_orig_autosw,
"^VADL",
"qd"))
4468 video_supported = TPACPI_VIDEO_770;
4471 video_supported = TPACPI_VIDEO_NEW;
4474 str_supported(video_supported != TPACPI_VIDEO_NONE),
4477 return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
4480 static void video_exit(
void)
4483 "restoring original video autoswitch mode\n");
4484 if (video_autosw_set(video_orig_autosw))
4485 pr_err(
"error while trying to restore original "
4486 "video autoswitch mode\n");
4489 static int video_outputsw_get(
void)
4494 switch (video_supported) {
4495 case TPACPI_VIDEO_570:
4496 if (!acpi_evalf(
NULL, &i,
"\\_SB.PHS",
"dd",
4497 TP_ACPI_VIDEO_570_PHSCMD))
4499 status = i & TP_ACPI_VIDEO_570_PHSMASK;
4501 case TPACPI_VIDEO_770:
4502 if (!acpi_evalf(
NULL, &i,
"\\VCDL",
"d"))
4505 status |= TP_ACPI_VIDEO_S_LCD;
4506 if (!acpi_evalf(
NULL, &i,
"\\VCDC",
"d"))
4509 status |= TP_ACPI_VIDEO_S_CRT;
4511 case TPACPI_VIDEO_NEW:
4512 if (!acpi_evalf(
NULL,
NULL,
"\\VUPS",
"vd", 1) ||
4513 !acpi_evalf(
NULL, &i,
"\\VCDC",
"d"))
4516 status |= TP_ACPI_VIDEO_S_CRT;
4518 if (!acpi_evalf(
NULL,
NULL,
"\\VUPS",
"vd", 0) ||
4519 !acpi_evalf(
NULL, &i,
"\\VCDL",
"d"))
4522 status |= TP_ACPI_VIDEO_S_LCD;
4523 if (!acpi_evalf(
NULL, &i,
"\\VCDD",
"d"))
4526 status |= TP_ACPI_VIDEO_S_DVI;
4535 static int video_outputsw_set(
int status)
4540 switch (video_supported) {
4541 case TPACPI_VIDEO_570:
4543 "\\_SB.PHS2",
"vdd",
4544 TP_ACPI_VIDEO_570_PHS2CMD,
4545 status | TP_ACPI_VIDEO_570_PHS2SET);
4547 case TPACPI_VIDEO_770:
4548 autosw = video_autosw_get();
4552 res = video_autosw_set(1);
4555 res = acpi_evalf(vid_handle,
NULL,
4556 "ASWT",
"vdd", status * 0x100, 0);
4557 if (!autosw && video_autosw_set(autosw)) {
4558 pr_err(
"video auto-switch left enabled due to error\n");
4562 case TPACPI_VIDEO_NEW:
4563 res = acpi_evalf(
NULL,
NULL,
"\\VUPS",
"vd", 0x80) &&
4564 acpi_evalf(
NULL,
NULL,
"\\VSDS",
"vdd", status, 1);
4570 return (res)? 0 : -
EIO;
4573 static int video_autosw_get(
void)
4577 switch (video_supported) {
4578 case TPACPI_VIDEO_570:
4579 if (!acpi_evalf(vid_handle, &autosw,
"SWIT",
"d"))
4582 case TPACPI_VIDEO_770:
4583 case TPACPI_VIDEO_NEW:
4584 if (!acpi_evalf(vid_handle, &autosw,
"^VDEE",
"d"))
4594 static int video_autosw_set(
int enable)
4596 if (!acpi_evalf(vid_handle,
NULL,
"_DOS",
"vd", (enable)? 1 : 0))
4601 static int video_outputsw_cycle(
void)
4603 int autosw = video_autosw_get();
4609 switch (video_supported) {
4610 case TPACPI_VIDEO_570:
4611 res = video_autosw_set(1);
4614 res = acpi_evalf(ec_handle,
NULL,
"_Q16",
"v");
4616 case TPACPI_VIDEO_770:
4617 case TPACPI_VIDEO_NEW:
4618 res = video_autosw_set(1);
4621 res = acpi_evalf(vid_handle,
NULL,
"VSWT",
"v");
4626 if (!autosw && video_autosw_set(autosw)) {
4627 pr_err(
"video auto-switch left enabled due to error\n");
4631 return (res)? 0 : -
EIO;
4634 static int video_expand_toggle(
void)
4636 switch (video_supported) {
4637 case TPACPI_VIDEO_570:
4638 return acpi_evalf(ec_handle,
NULL,
"_Q17",
"v")?
4640 case TPACPI_VIDEO_770:
4641 return acpi_evalf(vid_handle,
NULL,
"VEXP",
"v")?
4643 case TPACPI_VIDEO_NEW:
4644 return acpi_evalf(
NULL,
NULL,
"\\VEXP",
"v")?
4652 static int video_read(
struct seq_file *m)
4656 if (video_supported == TPACPI_VIDEO_NONE) {
4665 status = video_outputsw_get();
4669 autosw = video_autosw_get();
4676 if (video_supported == TPACPI_VIDEO_NEW)
4679 seq_printf(m,
"commands:\tlcd_enable, lcd_disable\n");
4680 seq_printf(m,
"commands:\tcrt_enable, crt_disable\n");
4681 if (video_supported == TPACPI_VIDEO_NEW)
4682 seq_printf(m,
"commands:\tdvi_enable, dvi_disable\n");
4683 seq_printf(m,
"commands:\tauto_enable, auto_disable\n");
4684 seq_printf(m,
"commands:\tvideo_switch, expand_toggle\n");
4689 static int video_write(
char *buf)
4695 if (video_supported == TPACPI_VIDEO_NONE)
4705 while ((cmd = next_cmd(&buf))) {
4706 if (
strlencmp(cmd,
"lcd_enable") == 0) {
4707 enable |= TP_ACPI_VIDEO_S_LCD;
4708 }
else if (
strlencmp(cmd,
"lcd_disable") == 0) {
4709 disable |= TP_ACPI_VIDEO_S_LCD;
4710 }
else if (
strlencmp(cmd,
"crt_enable") == 0) {
4711 enable |= TP_ACPI_VIDEO_S_CRT;
4712 }
else if (
strlencmp(cmd,
"crt_disable") == 0) {
4713 disable |= TP_ACPI_VIDEO_S_CRT;
4714 }
else if (video_supported == TPACPI_VIDEO_NEW &&
4716 enable |= TP_ACPI_VIDEO_S_DVI;
4717 }
else if (video_supported == TPACPI_VIDEO_NEW &&
4719 disable |= TP_ACPI_VIDEO_S_DVI;
4720 }
else if (
strlencmp(cmd,
"auto_enable") == 0) {
4721 res = video_autosw_set(1);
4724 }
else if (
strlencmp(cmd,
"auto_disable") == 0) {
4725 res = video_autosw_set(0);
4728 }
else if (
strlencmp(cmd,
"video_switch") == 0) {
4729 res = video_outputsw_cycle();
4732 }
else if (
strlencmp(cmd,
"expand_toggle") == 0) {
4733 res = video_expand_toggle();
4740 if (enable || disable) {
4741 status = video_outputsw_get();
4744 res = video_outputsw_set((status & ~disable) | enable);
4752 static struct ibm_struct video_driver_data = {
4755 .write = video_write,
4768 static int light_get_status(
void)
4772 if (tp_features.light_status) {
4773 if (!acpi_evalf(ec_handle, &status,
"KBLT",
"d"))
4781 static int light_set_status(
int status)
4785 if (tp_features.light) {
4787 rc = acpi_evalf(cmos_handle,
NULL,
NULL,
"vd",
4792 rc = acpi_evalf(lght_handle,
NULL,
NULL,
"vd",
4795 return (rc)? 0 : -
EIO;
4810 static void light_sysfs_set(
struct led_classdev *led_cdev,
4829 .name =
"tpacpi::thinklight",
4830 .brightness_set = &light_sysfs_set,
4831 .brightness_get = &light_sysfs_get,
4841 if (tpacpi_is_ibm()) {
4846 INIT_WORK(&tpacpi_led_thinklight.
work, light_set_status_worker);
4849 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
4851 if (tp_features.light)
4854 tp_features.light_status =
4855 acpi_evalf(ec_handle,
NULL,
"KBLT",
"qv");
4858 str_supported(tp_features.light),
4859 str_supported(tp_features.light_status));
4861 if (!tp_features.light)
4868 tp_features.light = 0;
4869 tp_features.light_status = 0;
4877 static void light_exit(
void)
4884 static int light_read(
struct seq_file *m)
4888 if (!tp_features.light) {
4890 }
else if (!tp_features.light_status) {
4894 status = light_get_status();
4904 static int light_write(
char *buf)
4909 if (!tp_features.light)
4912 while ((cmd = next_cmd(&buf))) {
4915 }
else if (
strlencmp(cmd,
"off") == 0) {
4921 return light_set_status(newstatus);
4924 static struct ibm_struct light_driver_data = {
4927 .write = light_write,
4938 const char *buf,
size_t count)
4940 unsigned long cmos_cmd;
4943 if (parse_strtoul(buf, 21, &cmos_cmd))
4946 res = issue_thinkpad_cmos_command(cmos_cmd);
4947 return (res)? res :
count;
4960 "initializing cmos commands subdriver\n");
4965 str_supported(cmos_handle !=
NULL));
4971 return (cmos_handle)? 0 : 1;
4974 static void cmos_exit(
void)
4979 static int cmos_read(
struct seq_file *m)
4987 seq_printf(m,
"commands:\t<cmd> (<cmd> is 0-21)\n");
4993 static int cmos_write(
char *buf)
4998 while ((cmd = next_cmd(&buf))) {
4999 if (
sscanf(cmd,
"%u", &cmos_cmd) == 1 &&
5000 cmos_cmd >= 0 && cmos_cmd <= 21) {
5005 res = issue_thinkpad_cmos_command(cmos_cmd);
5013 static struct ibm_struct cmos_driver_data = {
5016 .write = cmos_write,
5041 #define TPACPI_LED_NUMLEDS 16
5047 "tpacpi:orange:batt",
5048 "tpacpi:green:batt",
5049 "tpacpi::dock_active",
5050 "tpacpi::bay_active",
5051 "tpacpi::dock_batt",
5052 "tpacpi::unknown_led",
5054 "tpacpi::dock_status1",
5055 "tpacpi::dock_status2",
5056 "tpacpi::unknown_led2",
5057 "tpacpi::unknown_led3",
5058 "tpacpi::thinkvantage",
5060 #define TPACPI_SAFE_LEDS 0x1081U
5062 static inline bool tpacpi_is_led_restricted(
const unsigned int led)
5064 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5071 static int led_get_status(
const unsigned int led)
5076 switch (led_supported) {
5078 if (!acpi_evalf(ec_handle,
5079 &status,
"GLED",
"dd", 1 << led))
5081 led_s = (status == 0)?
5086 tpacpi_led_state_cache[
led] = led_s;
5095 static int led_set_status(
const unsigned int led,
5099 static const unsigned int led_sled_arg1[] = { 0, 1, 3 };
5100 static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 };
5104 switch (led_supported) {
5109 if (
unlikely(tpacpi_is_led_restricted(led)))
5111 if (!acpi_evalf(led_handle,
NULL,
NULL,
"vdd",
5112 (1 << led), led_sled_arg1[ledstatus]))
5119 if (
unlikely(tpacpi_is_led_restricted(led)))
5133 if (
unlikely(tpacpi_is_led_restricted(led)))
5135 if (!acpi_evalf(led_handle,
NULL,
NULL,
"vdd",
5136 led, led_led_arg1[ledstatus]))
5144 tpacpi_led_state_cache[
led] = ledstatus;
5149 static void led_set_status_worker(
struct work_struct *work)
5158 static void led_sysfs_set(
struct led_classdev *led_cdev,
5174 static int led_sysfs_blink_set(
struct led_classdev *led_cdev,
5175 unsigned long *delay_on,
unsigned long *delay_off)
5181 if (*delay_on == 0 && *delay_off == 0) {
5185 }
else if ((*delay_on != 500) || (*delay_off != 500))
5201 rc = led_get_status(data->
led);
5211 static void led_exit(
void)
5224 static int __init tpacpi_init_led(
unsigned int led)
5231 if (!tpacpi_led_names[led])
5242 INIT_WORK(&tpacpi_leds[led].work, led_set_status_worker);
5252 static const struct tpacpi_quirk led_useful_qtable[] __initconst = {
5297 #undef TPACPI_LEDQ_IBM
5298 #undef TPACPI_LEDQ_LNV
5304 if (tpacpi_is_ibm()) {
5330 unsigned long useful_leds;
5334 led_supported = led_init_detect_mode();
5337 str_supported(led_supported), led_supported);
5342 tpacpi_leds = kzalloc(
sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS,
5345 pr_err(
"Out of memory for LED data\n");
5349 useful_leds = tpacpi_check_quirks(led_useful_qtable,
5353 if (!tpacpi_is_led_restricted(i) &&
5355 rc = tpacpi_init_led(i);
5363 #ifdef CONFIG_THINKPAD_ACPI_UNSAFE_LEDS
5364 pr_notice(
"warning: userspace override of important "
5365 "firmware LEDs is enabled\n");
5370 #define str_led_status(s) \
5371 ((s) == TPACPI_LED_OFF ? "off" : \
5372 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
5374 static int led_read(
struct seq_file *m)
5376 if (!led_supported) {
5385 for (i = 0; i < 8; i++) {
5386 status = led_get_status(i);
5395 "<led> on, <led> off, <led> blink (<led> is 0-15)\n");
5400 static int led_write(
char *buf)
5409 while ((cmd = next_cmd(&buf))) {
5410 if (
sscanf(cmd,
"%d", &led) != 1 || led < 0 || led > 15)
5413 if (
strstr(cmd,
"off")) {
5415 }
else if (
strstr(cmd,
"on")) {
5417 }
else if (
strstr(cmd,
"blink")) {
5423 rc = led_set_status(led, s);
5444 #define TPACPI_BEEP_Q1 0x0001
5446 static const struct tpacpi_quirk beep_quirk_table[] __initconst = {
5460 str_supported(beep_handle !=
NULL));
5462 quirks = tpacpi_check_quirks(beep_quirk_table,
5467 return (beep_handle)? 0 : 1;
5470 static int beep_read(
struct seq_file *m)
5476 seq_printf(m,
"commands:\t<cmd> (<cmd> is 0-17)\n");
5482 static int beep_write(
char *buf)
5490 while ((cmd = next_cmd(&buf))) {
5491 if (
sscanf(cmd,
"%u", &beep_cmd) == 1 &&
5492 beep_cmd >= 0 && beep_cmd <= 17) {
5496 if (tp_features.beep_needs_two_args) {
5497 if (!acpi_evalf(beep_handle,
NULL,
NULL,
"vdd",
5501 if (!acpi_evalf(beep_handle,
NULL,
NULL,
"vd",
5510 static struct ibm_struct beep_driver_data = {
5513 .write = beep_write,
5537 #define TPACPI_MAX_THERMAL_SENSORS 16
5545 static int thermal_get_sensor(
int idx,
s32 *
value)
5553 switch (thermal_read_mode) {
5554 #if TPACPI_MAX_THERMAL_SENSORS >= 16
5556 if (idx >= 8 && idx <= 15) {
5564 if (!acpi_ec_read(t + idx, &tmp))
5566 *value = tmp * 1000;
5573 snprintf(tmpi,
sizeof(tmpi),
"TMP%c",
'0' + idx);
5574 if (!acpi_evalf(ec_handle,
NULL,
"UPDT",
"v"))
5576 if (!acpi_evalf(ec_handle, &t, tmpi,
"d"))
5578 *value = (t - 2732) * 100;
5585 snprintf(tmpi,
sizeof(tmpi),
"TMP%c",
'0' + idx);
5586 if (!acpi_evalf(ec_handle, &t, tmpi,
"d"))
5588 if (t > 127 || t < -127)
5617 for (i = 0 ; i <
n; i++) {
5618 res = thermal_get_sensor(i, &s->
temp[i]);
5626 static void thermal_dump_all_sensors(
void)
5631 n = thermal_get_sensors(&t);
5637 for (i = 0; i <
n; i++) {
5639 pr_cont(
" %d", (
int)(t.temp[i] / 1000));
5659 res = thermal_get_sensor(idx, &value);
5668 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5669 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5670 thermal_temp_input_show, NULL, _idxB)
5691 #define THERMAL_ATTRS(X) \
5692 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5694 static struct attribute *thermal_temp_input_attr[] = {
5715 .attrs = thermal_temp_input_attr
5719 .attrs = &thermal_temp_input_attr[8]
5722 #undef THERMAL_SENSOR_ATTR_TEMP
5723 #undef THERMAL_ATTRS
5736 acpi_tmp7 = acpi_evalf(ec_handle,
NULL,
"TMP7",
"qv");
5738 if (thinkpad_id.ec_model) {
5747 for (i = 0; i < 8; i++) {
5764 pr_err(
"ThinkPad ACPI EC access misbehaving, "
5765 "falling back to ACPI TMPx access "
5769 pr_err(
"ThinkPad ACPI EC access misbehaving, "
5770 "disabling thermal sensors access\n");
5778 }
else if (acpi_tmp7) {
5779 if (tpacpi_is_ibm() &&
5780 acpi_evalf(ec_handle,
NULL,
"UPDT",
"qv")) {
5796 switch (thermal_read_mode) {
5799 &thermal_temp_input16_group);
5807 &thermal_temp_input8_group);
5819 static void thermal_exit(
void)
5821 switch (thermal_read_mode) {
5824 &thermal_temp_input16_group);
5830 &thermal_temp_input8_group);
5838 static int thermal_read(
struct seq_file *m)
5843 n = thermal_get_sensors(&t);
5850 for (i = 0; i < (n - 1); i++)
5859 static struct ibm_struct thermal_driver_data = {
5861 .read = thermal_read,
5862 .exit = thermal_exit,
5869 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5911 static unsigned int brightness_enable = 2;
5913 static struct mutex brightness_mutex;
5917 static unsigned int tpacpi_brightness_nvram_get(
void)
5924 lnvram &= bright_maxlvl;
5929 static void tpacpi_brightness_checkpoint_nvram(
void)
5938 "trying to checkpoint backlight level to NVRAM...\n");
5951 b_nvram &= ~(TP_NVRAM_MASK_LEVEL_BRIGHTNESS <<
5956 "updated NVRAM backlight level to %u (0x%02x)\n",
5957 (
unsigned int) lec, (
unsigned int) b_nvram);
5960 "NVRAM backlight level already is %u (0x%02x)\n",
5961 (
unsigned int) lec, (
unsigned int) b_nvram);
5969 static int tpacpi_brightness_get_raw(
int *status)
5973 switch (brightness_mode) {
5975 *status = tpacpi_brightness_nvram_get();
5990 static int tpacpi_brightness_set_ec(
unsigned int value)
6006 static int tpacpi_brightness_set_ucmsstep(
unsigned int value)
6009 unsigned int current_value,
i;
6011 current_value = tpacpi_brightness_nvram_get();
6013 if (value == current_value)
6016 cmos_cmd = (value > current_value) ?
6019 inc = (value > current_value) ? 1 : -1;
6021 for (i = current_value; i !=
value; i +=
inc)
6022 if (issue_thinkpad_cmos_command(cmos_cmd))
6029 static int brightness_set(
unsigned int value)
6033 if (value > bright_maxlvl || value < 0)
6037 "set backlight level to %d\n", value);
6043 switch (brightness_mode) {
6046 res = tpacpi_brightness_set_ec(value);
6049 res = tpacpi_brightness_set_ucmsstep(value);
6063 unsigned int level =
6066 bd->
props.brightness : 0;
6069 "backlight: attempt to set level to %d\n",
6074 return brightness_set(level);
6085 res = tpacpi_brightness_get_raw(&status);
6095 static void tpacpi_brightness_notify_change(
void)
6102 .get_brightness = brightness_get,
6103 .update_status = brightness_update_status,
6122 pr_err(
"Unknown _BCL data, please report this to %s\n",
6140 static unsigned int __init tpacpi_check_std_acpi_brightness_support(
void)
6145 tpacpi_acpi_handle_locate(
"video",
ACPI_VIDEO_HID, &video_device);
6147 bcl_levels = tpacpi_query_bcl_levels(video_device);
6149 tp_features.bright_acpimode = (bcl_levels > 0);
6151 return (bcl_levels > 2) ? (bcl_levels - 2) : 0;
6159 #define TPACPI_BRGHT_Q_NOEC 0x0001
6160 #define TPACPI_BRGHT_Q_EC 0x0002
6161 #define TPACPI_BRGHT_Q_ASK 0x8000
6163 static const struct tpacpi_quirk brightness_quirk_table[] __initconst = {
6188 static void __init tpacpi_detect_brightness_capabilities(
void)
6193 "detecting firmware brightness interface capabilities\n");
6203 b = tpacpi_check_std_acpi_brightness_support();
6207 pr_info(
"detected a 16-level brightness capable ThinkPad\n");
6212 pr_info(
"detected a 8-level brightness capable ThinkPad\n");
6215 pr_err(
"Unsupported brightness interface, "
6217 tp_features.bright_unkfw = 1;
6218 bright_maxlvl = b - 1;
6226 unsigned long quirks;
6232 quirks = tpacpi_check_quirks(brightness_quirk_table,
6238 if (tp_features.bright_unkfw)
6241 if (!brightness_enable) {
6243 "brightness support disabled by "
6244 "module parameter\n");
6249 if (brightness_enable > 1) {
6250 pr_info(
"Standard ACPI backlight interface "
6251 "available, not loading native one\n");
6253 }
else if (brightness_enable == 1) {
6254 pr_warn(
"Cannot enable backlight brightness support, "
6255 "ACPI is already handling it. Refer to the "
6256 "acpi_backlight kernel parameter.\n");
6259 }
else if (tp_features.bright_acpimode && brightness_enable > 1) {
6260 pr_notice(
"Standard ACPI backlight interface not "
6261 "available, thinkpad_acpi native "
6262 "brightness control enabled\n");
6282 "driver auto-selected brightness_mode=%d\n",
6287 if (!tpacpi_is_ibm() &&
6292 if (tpacpi_brightness_get_raw(&b) < 0)
6297 props.max_brightness = bright_maxlvl;
6301 &ibm_backlight_data,
6303 if (IS_ERR(ibm_backlight_device)) {
6304 int rc = PTR_ERR(ibm_backlight_device);
6305 ibm_backlight_device =
NULL;
6306 pr_err(
"Could not register backlight device\n");
6310 "brightness is supported\n");
6313 pr_notice(
"brightness: will use unverified default: "
6314 "brightness_mode=%d\n", brightness_mode);
6315 pr_notice(
"brightness: please report to %s whether it works well "
6323 backlight_update_status(ibm_backlight_device);
6326 "brightness: registering brightness hotkeys "
6327 "as change notification\n");
6328 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6334 static void brightness_suspend(
void)
6336 tpacpi_brightness_checkpoint_nvram();
6339 static void brightness_shutdown(
void)
6341 tpacpi_brightness_checkpoint_nvram();
6344 static void brightness_exit(
void)
6346 if (ibm_backlight_device) {
6348 "calling backlight_device_unregister()\n");
6352 tpacpi_brightness_checkpoint_nvram();
6355 static int brightness_read(
struct seq_file *m)
6359 level = brightness_get(
NULL);
6365 seq_printf(m,
"commands:\tlevel <level> (<level> is 0-%d)\n",
6372 static int brightness_write(
char *buf)
6378 level = brightness_get(
NULL);
6382 while ((cmd = next_cmd(&buf))) {
6384 if (level < bright_maxlvl)
6386 }
else if (
strlencmp(cmd,
"down") == 0) {
6389 }
else if (
sscanf(cmd,
"level %d", &level) == 1 &&
6390 level >= 0 && level <= bright_maxlvl) {
6397 "set level to %d\n", level);
6403 rc = brightness_set(level);
6404 if (!rc && ibm_backlight_device)
6410 static struct ibm_struct brightness_driver_data = {
6411 .name =
"brightness",
6412 .read = brightness_read,
6413 .write = brightness_write,
6414 .exit = brightness_exit,
6415 .suspend = brightness_suspend,
6416 .shutdown = brightness_shutdown,
6441 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
6443 #define TPACPI_ALSA_DRVNAME "ThinkPad EC"
6444 #define TPACPI_ALSA_SHRTNAME "ThinkPad Console Audio Control"
6445 #define TPACPI_ALSA_MIXERNAME TPACPI_ALSA_SHRTNAME
6447 static int alsa_index = ~((1 << (
SNDRV_CARDS - 3)) - 1);
6448 static char *alsa_id =
"ThinkPadEC";
6451 struct tpacpi_alsa_data {
6463 TP_EC_AUDIO_MUTESW = 6,
6466 TP_EC_AUDIO_LVL_MSK = 0x0F,
6467 TP_EC_AUDIO_MUTESW_MSK = (1 << TP_EC_AUDIO_MUTESW),
6470 TP_EC_VOLUME_MAX = 14,
6473 enum tpacpi_volume_access_mode {
6474 TPACPI_VOL_MODE_AUTO = 0,
6476 TPACPI_VOL_MODE_UCMS_STEP,
6477 TPACPI_VOL_MODE_ECNVRAM,
6481 enum tpacpi_volume_capabilities {
6482 TPACPI_VOL_CAP_AUTO = 0,
6483 TPACPI_VOL_CAP_VOLMUTE,
6484 TPACPI_VOL_CAP_MUTEONLY,
6488 static enum tpacpi_volume_access_mode volume_mode =
6489 TPACPI_VOL_MODE_MAX;
6491 static enum tpacpi_volume_capabilities volume_capabilities;
6492 static bool volume_control_allowed;
6498 static struct mutex volume_mutex;
6500 static void tpacpi_volume_checkpoint_nvram(
void)
6506 if (volume_mode != TPACPI_VOL_MODE_ECNVRAM)
6508 if (!volume_control_allowed)
6512 "trying to checkpoint mixer state to NVRAM...\n");
6514 if (tp_features.mixer_no_level_control)
6515 ec_mask = TP_EC_AUDIO_MUTESW_MSK;
6517 ec_mask = TP_EC_AUDIO_MUTESW_MSK | TP_EC_AUDIO_LVL_MSK;
6522 if (
unlikely(!acpi_ec_read(TP_EC_AUDIO, &lec)))
6527 if (lec != (b_nvram & ec_mask)) {
6529 b_nvram &= ~ec_mask;
6533 "updated NVRAM mixer status to 0x%02x (0x%02x)\n",
6534 (
unsigned int) lec, (
unsigned int) b_nvram);
6537 "NVRAM mixer status already is 0x%02x (0x%02x)\n",
6538 (
unsigned int) lec, (
unsigned int) b_nvram);
6545 static int volume_get_status_ec(
u8 *status)
6549 if (!acpi_ec_read(TP_EC_AUDIO, &s))
6559 static int volume_get_status(
u8 *status)
6561 return volume_get_status_ec(status);
6564 static int volume_set_status_ec(
const u8 status)
6566 if (!acpi_ec_write(TP_EC_AUDIO, status))
6574 static int volume_set_status(
const u8 status)
6576 return volume_set_status_ec(status);
6580 static int __volume_set_mute_ec(
const bool mute)
6588 rc = volume_get_status_ec(&s);
6592 n = (
mute) ? s | TP_EC_AUDIO_MUTESW_MSK :
6593 s & ~TP_EC_AUDIO_MUTESW_MSK;
6596 rc = volume_set_status_ec(n);
6606 static int volume_alsa_set_mute(
const bool mute)
6609 (mute) ?
"" :
"un");
6610 return __volume_set_mute_ec(mute);
6613 static int volume_set_mute(
const bool mute)
6618 (mute) ?
"" :
"un");
6620 rc = __volume_set_mute_ec(mute);
6621 return (rc < 0) ? rc : 0;
6625 static int __volume_set_volume_ec(
const u8 vol)
6630 if (vol > TP_EC_VOLUME_MAX)
6636 rc = volume_get_status_ec(&s);
6640 n = (s & ~TP_EC_AUDIO_LVL_MSK) | vol;
6643 rc = volume_set_status_ec(n);
6653 static int volume_alsa_set_volume(
const u8 vol)
6656 "ALSA: trying to set volume level to %hu\n", vol);
6657 return __volume_set_volume_ec(vol);
6660 static void volume_alsa_notify_change(
void)
6662 struct tpacpi_alsa_data *
d;
6677 static int volume_alsa_vol_info(
struct snd_kcontrol *kcontrol,
6687 static int volume_alsa_vol_get(
struct snd_kcontrol *kcontrol,
6693 rc = volume_get_status(&s);
6697 ucontrol->
value.integer.value[0] = s & TP_EC_AUDIO_LVL_MSK;
6701 static int volume_alsa_vol_put(
struct snd_kcontrol *kcontrol,
6705 ucontrol->
value.integer.value[0]);
6706 return volume_alsa_set_volume(ucontrol->
value.integer.value[0]);
6709 #define volume_alsa_mute_info snd_ctl_boolean_mono_info
6711 static int volume_alsa_mute_get(
struct snd_kcontrol *kcontrol,
6717 rc = volume_get_status(&s);
6721 ucontrol->
value.integer.value[0] =
6722 (s & TP_EC_AUDIO_MUTESW_MSK) ? 0 : 1;
6726 static int volume_alsa_mute_put(
struct snd_kcontrol *kcontrol,
6730 ucontrol->
value.integer.value[0] ?
6732 return volume_alsa_set_mute(!ucontrol->
value.integer.value[0]);
6737 .name =
"Console Playback Volume",
6740 .info = volume_alsa_vol_info,
6741 .get = volume_alsa_vol_get,
6746 .name =
"Console Playback Switch",
6749 .info = volume_alsa_mute_info,
6750 .get = volume_alsa_mute_get,
6753 static void volume_suspend(
void)
6755 tpacpi_volume_checkpoint_nvram();
6758 static void volume_resume(
void)
6760 volume_alsa_notify_change();
6763 static void volume_shutdown(
void)
6765 tpacpi_volume_checkpoint_nvram();
6768 static void volume_exit(
void)
6775 tpacpi_volume_checkpoint_nvram();
6778 static int __init volume_create_alsa_mixer(
void)
6781 struct tpacpi_alsa_data *
data;
6787 sizeof(
struct tpacpi_alsa_data), &card);
6788 if (rc < 0 || !card) {
6789 pr_err(
"Failed to create ALSA card structures: %d\n", rc);
6802 (thinkpad_id.ec_version_str) ?
6803 thinkpad_id.ec_version_str :
"(unknown)");
6805 "%s at EC reg 0x%02x, fw %s", card->
shortname, TP_EC_AUDIO,
6806 (thinkpad_id.ec_version_str) ?
6807 thinkpad_id.ec_version_str :
"unknown");
6809 if (volume_control_allowed) {
6810 volume_alsa_control_vol.put = volume_alsa_vol_put;
6811 volume_alsa_control_vol.access =
6814 volume_alsa_control_mute.put = volume_alsa_mute_put;
6815 volume_alsa_control_mute.access =
6819 if (!tp_features.mixer_no_level_control) {
6823 pr_err(
"Failed to create ALSA volume control: %d\n",
6827 data->ctl_vol_id = &ctl_vol->
id;
6833 pr_err(
"Failed to create ALSA mute control: %d\n", rc);
6836 data->ctl_mute_id = &ctl_mute->
id;
6841 pr_err(
"Failed to register ALSA card: %d\n", rc);
6853 #define TPACPI_VOL_Q_MUTEONLY 0x0001
6854 #define TPACPI_VOL_Q_LEVEL 0x0002
6856 static const struct tpacpi_quirk volume_quirk_table[] __initconst = {
6861 .quirks = TPACPI_VOL_Q_LEVEL },
6876 .quirks = TPACPI_VOL_Q_MUTEONLY }
6893 if (volume_mode > TPACPI_VOL_MODE_MAX)
6896 if (volume_mode == TPACPI_VOL_MODE_UCMS_STEP) {
6897 pr_err(
"UCMS step volume mode not implemented, "
6902 if (volume_capabilities >= TPACPI_VOL_CAP_MAX)
6911 "ALSA mixer disabled by parameter, "
6912 "not loading volume subdriver...\n");
6916 quirks = tpacpi_check_quirks(volume_quirk_table,
6919 switch (volume_capabilities) {
6920 case TPACPI_VOL_CAP_AUTO:
6921 if (quirks & TPACPI_VOL_Q_MUTEONLY)
6922 tp_features.mixer_no_level_control = 1;
6923 else if (quirks & TPACPI_VOL_Q_LEVEL)
6924 tp_features.mixer_no_level_control = 0;
6928 case TPACPI_VOL_CAP_VOLMUTE:
6929 tp_features.mixer_no_level_control = 0;
6931 case TPACPI_VOL_CAP_MUTEONLY:
6932 tp_features.mixer_no_level_control = 1;
6938 if (volume_capabilities != TPACPI_VOL_CAP_AUTO)
6940 "using user-supplied volume_capabilities=%d\n",
6941 volume_capabilities);
6943 if (volume_mode == TPACPI_VOL_MODE_AUTO ||
6944 volume_mode == TPACPI_VOL_MODE_MAX) {
6945 volume_mode = TPACPI_VOL_MODE_ECNVRAM;
6948 "driver auto-selected volume_mode=%d\n",
6952 "using user-supplied volume_mode=%d\n",
6957 "mute is supported, volume control is %s\n",
6958 str_supported(!tp_features.mixer_no_level_control));
6960 rc = volume_create_alsa_mixer();
6962 pr_err(
"Could not create the ALSA mixer interface\n");
6966 pr_info(
"Console audio control enabled, mode: %s\n",
6967 (volume_control_allowed) ?
6968 "override (read/write)" :
6969 "monitor (read only)");
6972 "registering volume hotkeys as change notification\n");
6973 tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
6981 static int volume_read(
struct seq_file *m)
6985 if (volume_get_status(&status) < 0) {
6988 if (tp_features.mixer_no_level_control)
6992 status & TP_EC_AUDIO_LVL_MSK);
6995 onoff(status, TP_EC_AUDIO_MUTESW));
6997 if (volume_control_allowed) {
6999 if (!tp_features.mixer_no_level_control) {
7001 "commands:\tup, down\n");
7003 "commands:\tlevel <level>"
7004 " (<level> is 0-%d)\n",
7013 static int volume_write(
char *buf)
7016 u8 new_level, new_mute;
7026 if (
unlikely(!tp_warned.volume_ctrl_forbidden)) {
7027 tp_warned.volume_ctrl_forbidden = 1;
7028 pr_notice(
"Console audio control in monitor mode, "
7029 "changes are not allowed\n");
7030 pr_notice(
"Use the volume_control=1 module parameter "
7031 "to enable volume control\n");
7036 rc = volume_get_status(&s);
7040 new_level = s & TP_EC_AUDIO_LVL_MSK;
7041 new_mute = s & TP_EC_AUDIO_MUTESW_MSK;
7043 while ((cmd = next_cmd(&buf))) {
7044 if (!tp_features.mixer_no_level_control) {
7048 else if (new_level < TP_EC_VOLUME_MAX)
7051 }
else if (
strlencmp(cmd,
"down") == 0) {
7054 else if (new_level > 0)
7057 }
else if (
sscanf(cmd,
"level %u", &l) == 1 &&
7058 l >= 0 && l <= TP_EC_VOLUME_MAX) {
7064 new_mute = TP_EC_AUDIO_MUTESW_MSK;
7071 if (tp_features.mixer_no_level_control) {
7073 new_mute ?
"" :
"un");
7074 rc = volume_set_mute(!!new_mute);
7077 "%smute and set level to %d\n",
7078 new_mute ?
"" :
"un", new_level);
7079 rc = volume_set_status(new_mute | new_level);
7081 volume_alsa_notify_change();
7086 static struct ibm_struct volume_driver_data = {
7088 .read = volume_read,
7089 .write = volume_write,
7090 .exit = volume_exit,
7091 .suspend = volume_suspend,
7092 .resume = volume_resume,
7093 .shutdown = volume_shutdown,
7098 #define alsa_card NULL
7100 static void inline volume_alsa_notify_change(
void)
7106 pr_info(
"volume: disabled as there is no ALSA support in this kernel\n");
7111 static struct ibm_struct volume_driver_data = {
7270 static bool fan_control_allowed;
7276 static u8 fan_control_initial_status;
7277 static u8 fan_control_desired_level;
7278 static u8 fan_control_resume_level;
7279 static int fan_watchdog_maxinterval;
7281 static struct mutex fan_mutex;
7310 static void fan_quirk1_setup(
void)
7312 if (fan_control_initial_status == 0x07) {
7313 pr_notice(
"fan_init: initial fan status is unknown, "
7314 "assuming it is in auto mode\n");
7315 tp_features.fan_ctrl_status_undef = 1;
7319 static void fan_quirk1_handle(
u8 *fan_status)
7321 if (
unlikely(tp_features.fan_ctrl_status_undef)) {
7322 if (*fan_status != fan_control_initial_status) {
7326 tp_features.fan_ctrl_status_undef = 0;
7336 static bool fan_select_fan1(
void)
7338 if (tp_features.second_fan) {
7351 static bool fan_select_fan2(
void)
7355 if (!tp_features.second_fan)
7370 static void fan_update_desired_level(
u8 status)
7375 fan_control_desired_level = 7;
7377 fan_control_desired_level =
status;
7381 static int fan_get_status(
u8 *status)
7388 switch (fan_status_access_mode) {
7393 if (
unlikely(!acpi_evalf(gfan_handle, &res,
NULL,
"d")))
7397 *status = res & 0x07;
7408 fan_quirk1_handle(status);
7420 static int fan_get_status_safe(
u8 *status)
7427 rc = fan_get_status(&s);
7429 fan_update_desired_level(s);
7438 static int fan_get_speed(
unsigned int *speed)
7442 switch (fan_status_access_mode) {
7452 *speed = (hi << 8) | lo;
7463 static int fan2_get_speed(
unsigned int *speed)
7468 switch (fan_status_access_mode) {
7480 *speed = (hi << 8) | lo;
7491 static int fan_set_level(
int level)
7493 if (!fan_control_allowed)
7496 switch (fan_control_access_mode) {
7498 if (level >= 0 && level <= 7) {
7499 if (!acpi_evalf(sfan_handle,
NULL,
NULL,
"vd", level))
7509 ((level < 0) || (level > 7)))
7514 if (level & TP_EC_FAN_FULLSPEED)
7516 else if (level & TP_EC_FAN_AUTO)
7522 tp_features.fan_ctrl_status_undef = 0;
7530 "fan control: set fan control register to 0x%02x\n", level);
7534 static int fan_set_level_safe(
int level)
7538 if (!fan_control_allowed)
7545 level = fan_control_desired_level;
7547 rc = fan_set_level(level);
7549 fan_update_desired_level(level);
7555 static int fan_set_enable(
void)
7560 if (!fan_control_allowed)
7566 switch (fan_control_access_mode) {
7569 rc = fan_get_status(&s);
7576 s |= TP_EC_FAN_AUTO | 4;
7582 tp_features.fan_ctrl_status_undef = 0;
7588 rc = fan_get_status(&s);
7597 if (!acpi_evalf(sfan_handle,
NULL,
NULL,
"vd", s))
7611 "fan control: set fan control register to 0x%02x\n",
7616 static int fan_set_disable(
void)
7620 if (!fan_control_allowed)
7627 switch (fan_control_access_mode) {
7633 fan_control_desired_level = 0;
7634 tp_features.fan_ctrl_status_undef = 0;
7639 if (!acpi_evalf(sfan_handle,
NULL,
NULL,
"vd", 0x00))
7642 fan_control_desired_level = 0;
7651 "fan control: set fan control register to 0\n");
7657 static int fan_set_speed(
int speed)
7661 if (!fan_control_allowed)
7668 switch (fan_control_access_mode) {
7670 if (speed >= 0 && speed <= 65535) {
7671 if (!acpi_evalf(fans_handle,
NULL,
NULL,
"vddd",
7672 speed, speed, speed))
7686 static void fan_watchdog_reset(
void)
7691 if (fan_watchdog_maxinterval > 0 &&
7706 pr_notice(
"fan watchdog: enabling fan\n");
7707 rc = fan_set_enable();
7709 pr_err(
"fan watchdog: error %d while enabling fan, "
7710 "will try again later...\n", -rc);
7712 fan_watchdog_reset();
7745 res = fan_get_status_safe(&status);
7749 if (status & TP_EC_FAN_FULLSPEED) {
7751 }
else if (status & TP_EC_FAN_AUTO) {
7761 const char *buf,
size_t count)
7766 if (parse_strtoul(buf, 2, &t))
7770 "set fan mode to %lu\n", t);
7789 res = fan_set_level_safe(level);
7795 fan_watchdog_reset();
7802 fan_pwm1_enable_show, fan_pwm1_enable_store);
7812 res = fan_get_status_safe(&status);
7817 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0)
7818 status = fan_control_desired_level;
7828 const char *buf,
size_t count)
7834 if (parse_strtoul(buf, 255, &s))
7838 "set fan speed to %lu\n", s);
7841 newlevel = (s >> 5) & 0x07;
7846 rc = fan_get_status(&status);
7847 if (!rc && (status &
7848 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
7849 rc = fan_set_level(newlevel);
7853 fan_update_desired_level(newlevel);
7854 fan_watchdog_reset();
7859 return (rc)? rc :
count;
7864 fan_pwm1_show, fan_pwm1_store);
7874 res = fan_get_speed(&speed);
7883 fan_fan1_input_show,
NULL);
7893 res = fan2_get_speed(&speed);
7902 fan_fan2_input_show,
NULL);
7912 const char *buf,
size_t count)
7916 if (parse_strtoul(buf, 120, &t))
7919 if (!fan_control_allowed)
7922 fan_watchdog_maxinterval =
t;
7923 fan_watchdog_reset();
7931 fan_fan_watchdog_show, fan_fan_watchdog_store);
7934 static struct attribute *fan_attributes[] = {
7935 &dev_attr_fan_pwm1_enable.
attr, &dev_attr_fan_pwm1.
attr,
7936 &dev_attr_fan_fan1_input.
attr,
7942 .attrs = fan_attributes,
7945 #define TPACPI_FAN_Q1 0x0001
7946 #define TPACPI_FAN_2FAN 0x0002
7948 #define TPACPI_FAN_QI(__id1, __id2, __quirks) \
7949 { .vendor = PCI_VENDOR_ID_IBM, \
7950 .bios = TPACPI_MATCH_ANY, \
7951 .ec = TPID(__id1, __id2), \
7952 .quirks = __quirks }
7954 #define TPACPI_FAN_QL(__id1, __id2, __quirks) \
7955 { .vendor = PCI_VENDOR_ID_LENOVO, \
7956 .bios = TPACPI_MATCH_ANY, \
7957 .ec = TPID(__id1, __id2), \
7958 .quirks = __quirks }
7960 static const struct tpacpi_quirk fan_quirk_table[] __initconst = {
7968 #undef TPACPI_FAN_QL
7969 #undef TPACPI_FAN_QI
7977 "initializing fan subdriver\n");
7982 fan_control_commands = 0;
7983 fan_watchdog_maxinterval = 0;
7984 tp_features.fan_ctrl_status_undef = 0;
7985 tp_features.second_fan = 0;
7986 fan_control_desired_level = 7;
7988 if (tpacpi_is_ibm()) {
7994 quirks = tpacpi_check_quirks(fan_quirk_table,
8004 &fan_control_initial_status))) {
8009 tp_features.second_fan = 1;
8011 "secondary fan support enabled\n");
8014 pr_err(
"ThinkPad ACPI EC access misbehaving, "
8015 "fan status and control unavailable\n");
8023 fan_control_commands |=
8032 fan_control_access_mode =
8034 fan_control_commands |=
8040 fan_control_commands |=
8048 "fan is %s, modes %d, %d\n",
8051 fan_status_access_mode, fan_control_access_mode);
8054 if (!fan_control_allowed) {
8056 fan_control_commands = 0;
8058 "fan control features disabled by parameter\n");
8063 fan_get_status_safe(
NULL);
8067 if (tp_features.second_fan) {
8069 fan_attributes[
ARRAY_SIZE(fan_attributes)-2] =
8070 &dev_attr_fan_fan2_input.
attr;
8078 &driver_attr_fan_watchdog);
8089 static void fan_exit(
void)
8092 "cancelling any pending fan watchdog tasks\n");
8097 &driver_attr_fan_watchdog);
8103 static void fan_suspend(
void)
8107 if (!fan_control_allowed)
8111 fan_control_resume_level = 0;
8112 rc = fan_get_status_safe(&fan_control_resume_level);
8114 pr_notice(
"failed to read fan level for later "
8115 "restore during resume: %d\n", rc);
8119 if (tp_features.fan_ctrl_status_undef)
8120 fan_control_resume_level = 0;
8123 static void fan_resume(
void)
8125 u8 current_level = 7;
8126 bool do_set =
false;
8130 tp_features.fan_ctrl_status_undef = 0;
8132 if (!fan_control_allowed ||
8133 !fan_control_resume_level ||
8134 (fan_get_status_safe(¤t_level) < 0))
8137 switch (fan_control_access_mode) {
8140 do_set = (fan_control_resume_level > current_level);
8159 if (fan_control_resume_level != 7 &&
8160 !(fan_control_resume_level & TP_EC_FAN_FULLSPEED))
8164 (current_level != fan_control_resume_level);
8170 pr_notice(
"restoring fan level to 0x%02x\n",
8171 fan_control_resume_level);
8172 rc = fan_set_level_safe(fan_control_resume_level);
8174 pr_notice(
"failed to restore fan level: %d\n", rc);
8178 static int fan_read(
struct seq_file *m)
8182 unsigned int speed = 0;
8184 switch (fan_status_access_mode) {
8187 rc = fan_get_status_safe(&status);
8193 (status != 0) ?
"enabled" :
"disabled", status);
8198 rc = fan_get_status_safe(&status);
8203 (status != 0) ?
"enabled" :
"disabled");
8205 rc = fan_get_speed(&speed);
8211 if (status & TP_EC_FAN_FULLSPEED)
8214 else if (status & TP_EC_FAN_AUTO)
8228 switch (fan_control_access_mode) {
8235 "auto, disengaged, full-speed)\n");
8242 "commands:\twatchdog <timeout> (<timeout> "
8243 "is 0 (off), 1-120 (seconds))\n");
8247 " (<speed> is 0-65535)\n");
8252 static int fan_write_cmd_level(
const char *cmd,
int *rc)
8258 else if ((
strlencmp(cmd,
"level disengaged") == 0) |
8259 (
strlencmp(cmd,
"level full-speed") == 0))
8261 else if (
sscanf(cmd,
"level %d", &level) != 1)
8264 *rc = fan_set_level_safe(level);
8266 pr_err(
"level command accepted for unsupported access mode %d\n",
8267 fan_control_access_mode);
8270 "set level to %d\n", level);
8275 static int fan_write_cmd_enable(
const char *cmd,
int *rc)
8280 *rc = fan_set_enable();
8282 pr_err(
"enable command accepted for unsupported access mode %d\n",
8283 fan_control_access_mode);
8290 static int fan_write_cmd_disable(
const char *cmd,
int *rc)
8295 *rc = fan_set_disable();
8297 pr_err(
"disable command accepted for unsupported access mode %d\n",
8298 fan_control_access_mode);
8305 static int fan_write_cmd_speed(
const char *cmd,
int *rc)
8312 if (
sscanf(cmd,
"speed %d", &speed) != 1)
8315 *rc = fan_set_speed(speed);
8317 pr_err(
"speed command accepted for unsupported access mode %d\n",
8318 fan_control_access_mode);
8321 "set speed to %d\n", speed);
8326 static int fan_write_cmd_watchdog(
const char *cmd,
int *rc)
8330 if (
sscanf(cmd,
"watchdog %d", &interval) != 1)
8336 fan_watchdog_maxinterval =
interval;
8338 "set watchdog timer to %d\n",
8345 static int fan_write(
char *buf)
8350 while (!rc && (cmd = next_cmd(&buf))) {
8351 if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
8352 fan_write_cmd_level(cmd, &rc)) &&
8353 !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
8354 (fan_write_cmd_enable(cmd, &rc) ||
8355 fan_write_cmd_disable(cmd, &rc) ||
8356 fan_write_cmd_watchdog(cmd, &rc))) &&
8358 fan_write_cmd_speed(cmd, &rc))
8362 fan_watchdog_reset();
8373 .suspend = fan_suspend,
8374 .resume = fan_resume,
8389 static void tpacpi_driver_event(
const unsigned int hkey_event)
8391 if (ibm_backlight_device) {
8392 switch (hkey_event) {
8395 tpacpi_brightness_notify_change();
8399 switch (hkey_event) {
8403 volume_alsa_notify_change();
8408 static void hotkey_driver_event(
const unsigned int scancode)
8414 static ssize_t thinkpad_acpi_pdev_name_show(
struct device *dev,
8433 static bool force_load;
8435 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
8436 static const char *
__init str_supported(
int is_supported)
8438 static char text_unsupported[] __initdata =
"not supported";
8440 return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
8450 if (ibm->
flags.acpi_notify_installed) {
8452 "%s: acpi_remove_notify_handler\n", ibm->
name);
8456 dispatch_acpi_notify);
8457 ibm->
flags.acpi_notify_installed = 0;
8460 if (ibm->
flags.proc_created) {
8462 "%s: remove_proc_entry\n", ibm->
name);
8464 ibm->
flags.proc_created = 0;
8467 if (ibm->
flags.acpi_driver_registered) {
8469 "%s: acpi_bus_unregister_driver\n", ibm->
name);
8474 ibm->
flags.acpi_driver_registered = 0;
8477 if (ibm->
flags.init_called && ibm->
exit) {
8479 ibm->
flags.init_called = 0;
8495 if (ibm->
flags.experimental && !experimental)
8499 "probing for %s\n", ibm->
name);
8502 ret = iibm->
init(iibm);
8508 ibm->
flags.init_called = 1;
8512 if (ibm->
acpi->hid) {
8513 ret = register_tpacpi_subdriver(ibm);
8518 if (ibm->
acpi->notify) {
8519 ret = setup_acpi_notify(ibm);
8532 "%s installed\n", ibm->
name);
8542 &dispatch_proc_fops, ibm);
8544 pr_err(
"unable to create proc entry %s\n", ibm->
name);
8548 ibm->
flags.proc_created = 1;
8557 "%s: at error exit path with result %d\n",
8561 return (ret < 0)? ret : 0;
8566 static bool __pure __init tpacpi_is_fw_digit(
const char c)
8568 return (c >=
'0' && c <=
'9') || (c >=
'A' && c <=
'Z');
8572 static bool __pure __init tpacpi_is_valid_fw_id(
const char*
const s,
8575 return s &&
strlen(s) >= 8 &&
8576 tpacpi_is_fw_digit(s[0]) &&
8577 tpacpi_is_fw_digit(s[1]) &&
8578 s[2] == t && s[3] ==
'T' &&
8579 tpacpi_is_fw_digit(s[4]) &&
8580 tpacpi_is_fw_digit(s[5]);
8590 char ec_fw_string[18];
8596 memset(tp, 0,
sizeof(*tp));
8628 "IBM ThinkPad Embedded Controller -[%17c",
8629 ec_fw_string) == 1) {
8630 ec_fw_string[
sizeof(ec_fw_string) - 1] = 0;
8631 ec_fw_string[
strcspn(ec_fw_string,
" ]")] = 0;
8637 if (tpacpi_is_valid_fw_id(ec_fw_string,
'H')) {
8639 | (ec_fw_string[1] << 8);
8643 pr_notice(
"ThinkPad firmware release %s "
8644 "doesn't match the known patterns\n",
8660 if (s && !(
strnicmp(s,
"Lenovo", 6))) {
8675 static int __init probe_for_thinkpad(
void)
8683 if (!tpacpi_is_ibm() && !tpacpi_is_lenovo())
8690 is_thinkpad = (thinkpad_id.model_str !=
NULL) ||
8691 (thinkpad_id.ec_model != 0) ||
8692 tpacpi_is_fw_known();
8698 pr_err(
"Not yet supported ThinkPad detected!\n");
8702 if (!is_thinkpad && !force_load)
8708 static void __init thinkpad_acpi_init_banner(
void)
8713 pr_info(
"ThinkPad BIOS %s, EC %s\n",
8714 (thinkpad_id.bios_version_str) ?
8715 thinkpad_id.bios_version_str :
"unknown",
8716 (thinkpad_id.ec_version_str) ?
8717 thinkpad_id.ec_version_str :
"unknown");
8719 BUG_ON(!thinkpad_id.vendor);
8721 if (thinkpad_id.model_str)
8724 "IBM" : ((thinkpad_id.vendor ==
8726 "Lenovo" :
"Unknown vendor"),
8727 thinkpad_id.model_str,
8728 (thinkpad_id.nummodel_str) ?
8729 thinkpad_id.nummodel_str :
"unknown");
8736 .
data = &thinkpad_acpi_driver_data,
8739 .init = hotkey_init,
8740 .data = &hotkey_driver_data,
8743 .init = bluetooth_init,
8744 .data = &bluetooth_driver_data,
8748 .data = &wan_driver_data,
8752 .data = &uwb_driver_data,
8754 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
8758 .data = &video_driver_data,
8763 .data = &light_driver_data,
8767 .data = &cmos_driver_data,
8771 .data = &led_driver_data,
8775 .data = &beep_driver_data,
8778 .init = thermal_init,
8779 .data = &thermal_driver_data,
8782 .init = brightness_init,
8783 .data = &brightness_driver_data,
8786 .init = volume_init,
8787 .data = &volume_driver_data,
8791 .data = &fan_driver_data,
8800 if (!kp || !kp->
name || !val)
8803 for (i = 0; i <
ARRAY_SIZE(ibms_init); i++) {
8804 ibm = ibms_init[
i].data;
8807 if (!ibm || !ibm->
name)
8813 strcpy(ibms_init[i].param, val);
8814 strcat(ibms_init[i].param,
",");
8824 "Enables experimental features when non-zero");
8831 "Attempts to load the driver even on a "
8832 "mis-identified ThinkPad when true");
8836 "Enables setting fan parameters features when true");
8840 "Selects brightness control strategy: "
8841 "0=auto, 1=EC, 2=UCMS, 3=EC+NVRAM");
8845 "Enables backlight control when 1, disables when 0");
8849 "used for backwards compatibility with userspace, "
8850 "see documentation");
8852 #ifdef CONFIG_THINKPAD_ACPI_ALSA_SUPPORT
8855 "Selects volume control strategy: "
8856 "0=auto, 1=EC, 2=N/A, 3=EC+NVRAM");
8860 "Selects the mixer capabilites: "
8861 "0=auto, 1=volume and mute, 2=mute only");
8865 "Enables software override for the console audio "
8866 "control when true");
8874 MODULE_PARM_DESC(enable,
"Enable the ALSA interface for the ACPI EC Mixer");
8877 #define TPACPI_PARAM(feature) \
8878 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
8879 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
8880 "at module load, see documentation")
8893 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
8898 "Initial state of the emulated WLSW switch");
8904 "Initial state of the emulated bluetooth switch");
8910 "Initial state of the emulated WWAN switch");
8916 "Initial state of the emulated UWB switch");
8919 static void thinkpad_acpi_module_exit(
void)
8926 &tpacpi_all_drivers,
8933 if (tpacpi_inputdev) {
8934 if (tp_features.input_device_registered)
8935 input_unregister_device(tpacpi_inputdev);
8937 input_free_device(tpacpi_inputdev);
8938 kfree(hotkey_keycode_map);
8944 if (tp_features.sensors_pdev_attrs_registered)
8946 &dev_attr_thinkpad_acpi_pdev_name);
8947 if (tpacpi_sensors_pdev)
8952 if (tp_features.sensors_pdrv_attrs_registered)
8953 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.
driver);
8954 if (tp_features.platform_drv_attrs_registered)
8955 tpacpi_remove_driver_attributes(&tpacpi_pdriver.
driver);
8957 if (tp_features.sensors_pdrv_registered)
8960 if (tp_features.platform_drv_registered)
8969 kfree(thinkpad_id.bios_version_str);
8970 kfree(thinkpad_id.ec_version_str);
8971 kfree(thinkpad_id.model_str);
8972 kfree(thinkpad_id.nummodel_str);
8976 static int __init thinkpad_acpi_module_init(
void)
8983 if (hotkey_report_mode > 2)
8988 ret = get_thinkpad_model_data(&thinkpad_id);
8990 pr_err(
"unable to get DMI data: %d\n", ret);
8991 thinkpad_acpi_module_exit();
8994 ret = probe_for_thinkpad();
8996 thinkpad_acpi_module_exit();
9002 thinkpad_acpi_init_banner();
9003 tpacpi_check_outdated_fw();
9010 thinkpad_acpi_module_exit();
9017 thinkpad_acpi_module_exit();
9023 pr_err(
"unable to register main platform driver\n");
9024 thinkpad_acpi_module_exit();
9027 tp_features.platform_drv_registered = 1;
9031 pr_err(
"unable to register hwmon platform driver\n");
9032 thinkpad_acpi_module_exit();
9035 tp_features.sensors_pdrv_registered = 1;
9037 ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.
driver);
9039 tp_features.platform_drv_attrs_registered = 1;
9040 ret = tpacpi_create_driver_attributes(
9041 &tpacpi_hwmon_pdriver.
driver);
9044 pr_err(
"unable to create sysfs driver attributes\n");
9045 thinkpad_acpi_module_exit();
9048 tp_features.sensors_pdrv_attrs_registered = 1;
9054 if (IS_ERR(tpacpi_pdev)) {
9055 ret = PTR_ERR(tpacpi_pdev);
9057 pr_err(
"unable to register platform device\n");
9058 thinkpad_acpi_module_exit();
9061 tpacpi_sensors_pdev = platform_device_register_simple(
9064 if (IS_ERR(tpacpi_sensors_pdev)) {
9065 ret = PTR_ERR(tpacpi_sensors_pdev);
9066 tpacpi_sensors_pdev =
NULL;
9067 pr_err(
"unable to register hwmon platform device\n");
9068 thinkpad_acpi_module_exit();
9072 &dev_attr_thinkpad_acpi_pdev_name);
9074 pr_err(
"unable to create sysfs hwmon device attributes\n");
9075 thinkpad_acpi_module_exit();
9078 tp_features.sensors_pdev_attrs_registered = 1;
9080 if (IS_ERR(tpacpi_hwmon)) {
9081 ret = PTR_ERR(tpacpi_hwmon);
9082 tpacpi_hwmon =
NULL;
9083 pr_err(
"unable to register hwmon device\n");
9084 thinkpad_acpi_module_exit();
9088 tpacpi_inputdev = input_allocate_device();
9089 if (!tpacpi_inputdev) {
9090 pr_err(
"unable to allocate input device\n");
9091 thinkpad_acpi_module_exit();
9095 tpacpi_inputdev->name =
"ThinkPad Extra Buttons";
9097 tpacpi_inputdev->id.bustype =
BUS_HOST;
9098 tpacpi_inputdev->id.vendor = thinkpad_id.vendor;
9101 tpacpi_inputdev->dev.parent = &tpacpi_pdev->
dev;
9105 tpacpi_detect_brightness_capabilities();
9108 for (i = 0; i <
ARRAY_SIZE(ibms_init); i++) {
9109 ret = ibm_init(&ibms_init[i]);
9110 if (ret >= 0 && *ibms_init[i].
param)
9111 ret = ibms_init[
i].data->write(ibms_init[i].param);
9113 thinkpad_acpi_module_exit();
9120 ret = input_register_device(tpacpi_inputdev);
9122 pr_err(
"unable to register input device\n");
9123 thinkpad_acpi_module_exit();
9126 tp_features.input_device_registered = 1;
9152 #define IBM_BIOS_MODULE_ALIAS(__type) \
9153 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")