aboutsummaryrefslogtreecommitdiff
path: root/drivers/platform
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2024-04-24 14:28:23 +0200
committerHans de Goede <hdegoede@redhat.com>2024-04-29 11:44:13 +0200
commitc1a8c7f1dc2ff4e0041fd333317bca06615fbb9e (patch)
treef51c787d89fb211421af3135f2208cc932d7df31 /drivers/platform
parent99ce461c845adb5877c21d960b369aa86b8e1f41 (diff)
platform/x86: thinkpad_acpi: Move hkey > scancode mapping to tpacpi_input_send_key()
Move the mapping of hkey events to scancodes to tpacpi_input_send_key(), this results in a nice cleanup and prepares things for adding sparse-keymap support. Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Link: https://lore.kernel.org/r/20240424122834.19801-14-hdegoede@redhat.com
Diffstat (limited to 'drivers/platform')
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c85
1 files changed, 26 insertions, 59 deletions
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index edae3b6020e4..313880ccd363 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -2250,15 +2250,28 @@ static void tpacpi_input_send_tabletsw(void)
}
}
-/* Do NOT call without validating scancode first */
-static void tpacpi_input_send_key(const unsigned int scancode)
-{
- const unsigned int keycode = hotkey_keycode_map[scancode];
-
- if (scancode < TP_ACPI_HOTKEYSCAN_ADAPTIVE_START &&
- !(hotkey_user_mask & (1 << scancode)))
- return;
+static bool tpacpi_input_send_key(const u32 hkey)
+{
+ unsigned int keycode, scancode;
+
+ if (hkey >= TP_HKEY_EV_ORIG_KEY_START &&
+ hkey <= TP_HKEY_EV_ORIG_KEY_END) {
+ scancode = hkey - TP_HKEY_EV_ORIG_KEY_START;
+ if (!(hotkey_user_mask & (1 << scancode)))
+ return true; /* Not reported but still a known code */
+ } else if (hkey >= TP_HKEY_EV_ADAPTIVE_KEY_START &&
+ hkey <= TP_HKEY_EV_ADAPTIVE_KEY_END) {
+ scancode = hkey - TP_HKEY_EV_ADAPTIVE_KEY_START +
+ TP_ACPI_HOTKEYSCAN_ADAPTIVE_START;
+ } else if (hkey >= TP_HKEY_EV_EXTENDED_KEY_START &&
+ hkey <= TP_HKEY_EV_EXTENDED_KEY_END) {
+ scancode = hkey - TP_HKEY_EV_EXTENDED_KEY_START +
+ TP_ACPI_HOTKEYSCAN_EXTENDED_START;
+ } else {
+ return false;
+ }
+ keycode = hotkey_keycode_map[scancode];
if (keycode != KEY_RESERVED) {
mutex_lock(&tpacpi_inputdev_send_mutex);
@@ -2272,6 +2285,8 @@ static void tpacpi_input_send_key(const unsigned int scancode)
mutex_unlock(&tpacpi_inputdev_send_mutex);
}
+
+ return true;
}
#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
@@ -2281,7 +2296,7 @@ static struct tp_acpi_drv_struct ibm_hotkey_acpidriver;
static void tpacpi_hotkey_send_key(unsigned int scancode)
{
tpacpi_driver_event(TP_HKEY_EV_ORIG_KEY_START + scancode);
- tpacpi_input_send_key(scancode);
+ tpacpi_input_send_key(TP_HKEY_EV_ORIG_KEY_START + scancode);
}
static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
@@ -3704,42 +3719,15 @@ static void adaptive_keyboard_s_quickview_row(void)
adaptive_keyboard_set_mode(FUNCTION_MODE);
}
-static bool adaptive_keyboard_hotkey_notify_hotkey(const u32 hkey)
-{
- if (hkey < TP_HKEY_EV_ADAPTIVE_KEY_START ||
- hkey > TP_HKEY_EV_ADAPTIVE_KEY_END) {
- pr_info("Unhandled adaptive keyboard key: 0x%x\n", hkey);
- return false;
- }
-
- tpacpi_input_send_key(hkey - TP_HKEY_EV_ADAPTIVE_KEY_START +
- TP_ACPI_HOTKEYSCAN_ADAPTIVE_START);
- return true;
-}
-
-static bool hotkey_notify_extended_hotkey(const u32 hkey)
-{
- if (hkey >= TP_HKEY_EV_EXTENDED_KEY_START &&
- hkey <= TP_HKEY_EV_EXTENDED_KEY_END) {
- unsigned int scancode = hkey - TP_HKEY_EV_EXTENDED_KEY_START +
- TP_ACPI_HOTKEYSCAN_EXTENDED_START;
- tpacpi_input_send_key(scancode);
- return true;
- }
-
- return false;
-}
-
/* 0x1000-0x1FFF: key presses */
static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
{
- unsigned int scancode = hkey - TP_HKEY_EV_ORIG_KEY_START;
-
/* Never send ACPI netlink events for original hotkeys (hkey: 0x1001 - 0x1020) */
if (hkey >= TP_HKEY_EV_ORIG_KEY_START && hkey <= TP_HKEY_EV_ORIG_KEY_END) {
*send_acpi_ev = false;
/* Original hotkeys may be polled from NVRAM instead */
+ unsigned int scancode = hkey - TP_HKEY_EV_ORIG_KEY_START;
if (hotkey_source_mask & (1 << scancode))
return true;
}
@@ -3747,28 +3735,7 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
if (tpacpi_driver_event(hkey))
return true;
- /*
- * Original events are in the 0x10XX range, the adaptive keyboard
- * found in 2014 X1 Carbon emits events are of 0x11XX. In 2017
- * models, additional keys are emitted through 0x13XX.
- */
- switch ((hkey >> 8) & 0xf) {
- case 0:
- if (hkey >= TP_HKEY_EV_ORIG_KEY_START &&
- hkey <= TP_HKEY_EV_ORIG_KEY_END) {
- tpacpi_input_send_key(scancode);
- return true;
- }
- break;
-
- case 1:
- return adaptive_keyboard_hotkey_notify_hotkey(hkey);
-
- case 3:
- return hotkey_notify_extended_hotkey(hkey);
- }
-
- return false;
+ return tpacpi_input_send_key(hkey);
}
/* 0x2000-0x2FFF: Wakeup reason */