* [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys
@ 2024-04-24 12:28 Hans de Goede
2024-04-24 12:28 ` [PATCH v2 01/24] platform/x86: thinkpad_acpi: Take hotkey_mutex during hotkey_exit() Hans de Goede
` (26 more replies)
0 siblings, 27 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Hi All,
Here is v2 of my patch-series to refactor thinkpad_acpi's hotkey handling
and to add support for some new hotkeys on new models.
Changes in v2:
- Some small code style tweaks in response to reviews
- Add various Reviewed-by and Tested-by tags
Relevant parts of v1 cover-letter:
I have been very careful to not introduce any changes wrt support for
the original ThinkPad models / hotkeys which use the hotkey_*_mask
related code.
I've also done my best to avoid any *significant* functional change but
there are still some functional changes, which should all not impact
userspace compatibility:
1. Adaptive keyboard special keys will now also send EV_MSC events with
the scancode, just like all the other hotkeys.
2. Rely on the input core for KEY_RESERVED suppression. This means that
keys marked as KEY_RESERVED will still send EV_MSC evdev events when
pressed (which helps users with mapping them to non reserved KEY_FOO
values if desired).
3. Align the keycodes for volume up/down/mute and brightness up/down with
those set by userspace through udev upstream's hwdb. Note these are all
for keys which are suppressed by hotkey_reserved_mask by default.
So this is only a functional change for users who override the default
hotkey-mask *and* who do not have udev's default hwdb installed.
4. Suppress ACPI netlink event generation for unknown 0x1xxx hkey events to
avoid userspace starting to rely on the netlink events for new hotkeys
before these have been added to the keymap, only to have the netlink
events get disabled by the adding of the new hotkeys to the keymap.
This should not cause a behavior change for existing models since all
currently known 0x1xxx events have a mapping.
Here is a quick breakdown of the patches in this series:
Patch 1 - 2: Fix a small locking issue on rmmod the only problem here
really is a lockdep warning, so I plan to route these fixes through
for-next together with the rest to keep things simple.
Patch 3 - 14: Do a bunch of cleanups and refactoring
Patch 15: Implements functional change no 4. I really kinda want to just
completely disable ACPI netlink event generation when also sending evdev
events instead of reporting these twice. But for the 0x11xx / 0x13xx
hkey events the kernel has send ACPI netlink events for years now. So
this disables ACPI netlink events for any new hotkeys going forward.
Patch 16 - 18: Refactor / cleanup reserved key handling
Patch 19: Actually move to sparse-keymaps
Patch 20: Update the keymap for 2 adaptive kbd Fn row keys
Patch 21 - 24: Mark's original patches adding support for the new Fn + N
key combo and for trackpoint doubletap slightly reworked to use
the new sparse-keymap.
Regards,
Hans
Hans de Goede (20):
platform/x86: thinkpad_acpi: Take hotkey_mutex during hotkey_exit()
platform/x86: thinkpad_acpi: Provide hotkey_poll_stop_sync() dummy
platform/x86: thinkpad_acpi: Drop setting send_/ignore_acpi_ev
defaults twice
platform/x86: thinkpad_acpi: Drop ignore_acpi_ev
platform/x86: thinkpad_acpi: Use tpacpi_input_send_key() in adaptive
kbd code
platform/x86: thinkpad_acpi: Do hkey to scancode translation later
platform/x86: thinkpad_acpi: Make tpacpi_driver_event() return if it
handled the event
platform/x86: thinkpad_acpi: Move adaptive kbd event handling to
tpacpi_driver_event()
platform/x86: thinkpad_acpi: Move special original hotkeys handling
out of switch-case
platform/x86: thinkpad_acpi: Move hotkey_user_mask check to
tpacpi_input_send_key()
platform/x86: thinkpad_acpi: Always call tpacpi_driver_event() for
hotkeys
platform/x86: thinkpad_acpi: Drop tpacpi_input_send_key_masked() and
hotkey_driver_event()
platform/x86: thinkpad_acpi: Move hkey > scancode mapping to
tpacpi_input_send_key()
platform/x86: thinkpad_acpi: Move tpacpi_driver_event() call to
tpacpi_input_send_key()
platform/x86: thinkpad_acpi: Do not send ACPI netlink events for
unknown hotkeys
platform/x86: thinkpad_acpi: Change hotkey_reserved_mask
initialization
platform/x86: thinkpad_acpi: Use correct keycodes for volume and
brightness keys
platform/x86: thinkpad_acpi: Drop KEY_RESERVED special handling
platform/x86: thinkpad_acpi: Switch to using sparse-keymap helpers
platform/x86: thinkpad_acpi: Add mappings for adaptive kbd
clipping-tool and cloud keys
Mark Pearson (4):
platform/x86: thinkpad_acpi: Simplify known_ev handling
platform/x86: thinkpad_acpi: Support for trackpoint doubletap
platform/x86: thinkpad_acpi: Support for system debug info hotkey
platform/x86: thinkpad_acpi: Support hotkey to disable trackpoint
doubletap
drivers/platform/x86/thinkpad_acpi.c | 854 +++++++++++----------------
1 file changed, 353 insertions(+), 501 deletions(-)
--
2.44.0
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v2 01/24] platform/x86: thinkpad_acpi: Take hotkey_mutex during hotkey_exit()
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 02/24] platform/x86: thinkpad_acpi: Provide hotkey_poll_stop_sync() dummy Hans de Goede
` (25 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
hotkey_exit() already takes the mutex around the hotkey_poll_stop_sync()
call, but not around the other calls.
commit 38831eaf7d4c ("platform/x86: thinkpad_acpi: use lockdep
annotations") has added lockdep_assert_held() checks to various hotkey
functions.
These lockdep_assert_held() checks fail causing WARN() backtraces in
dmesg due to missing locking in hotkey_exit(), fix this.
Fixes: 38831eaf7d4c ("platform/x86: thinkpad_acpi: use lockdep annotations")
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 771aaa7ae4cf..ba4df8f68c2a 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3044,10 +3044,9 @@ static void tpacpi_send_radiosw_update(void)
static void hotkey_exit(void)
{
-#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
mutex_lock(&hotkey_mutex);
+#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
hotkey_poll_stop_sync();
- mutex_unlock(&hotkey_mutex);
#endif
dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY,
"restoring original HKEY status and mask\n");
@@ -3057,6 +3056,8 @@ static void hotkey_exit(void)
hotkey_mask_set(hotkey_orig_mask)) |
hotkey_status_set(false)) != 0)
pr_err("failed to restore hot key mask to BIOS defaults\n");
+
+ mutex_unlock(&hotkey_mutex);
}
static void __init hotkey_unmap(const unsigned int scancode)
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 02/24] platform/x86: thinkpad_acpi: Provide hotkey_poll_stop_sync() dummy
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
2024-04-24 12:28 ` [PATCH v2 01/24] platform/x86: thinkpad_acpi: Take hotkey_mutex during hotkey_exit() Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 03/24] platform/x86: thinkpad_acpi: Drop setting send_/ignore_acpi_ev defaults twice Hans de Goede
` (24 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Provide a hotkey_poll_stop_sync() dummy implementation when
CONFIG_THINKPAD_ACPI_HOTKEY_POLL, so that the #ifdef-ery around
hotkey_poll_stop_sync() can be removed from hotkey_exit().
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index ba4df8f68c2a..fc5681808c3b 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -2575,6 +2575,9 @@ static void hotkey_poll_setup_safe(const bool __unused)
{
}
+static void hotkey_poll_stop_sync(void)
+{
+}
#endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
static int hotkey_inputdev_open(struct input_dev *dev)
@@ -3045,9 +3048,7 @@ static void tpacpi_send_radiosw_update(void)
static void hotkey_exit(void)
{
mutex_lock(&hotkey_mutex);
-#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
hotkey_poll_stop_sync();
-#endif
dbg_printk(TPACPI_DBG_EXIT | TPACPI_DBG_HKEY,
"restoring original HKEY status and mask\n");
/* yes, there is a bitwise or below, we want the
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 03/24] platform/x86: thinkpad_acpi: Drop setting send_/ignore_acpi_ev defaults twice
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
2024-04-24 12:28 ` [PATCH v2 01/24] platform/x86: thinkpad_acpi: Take hotkey_mutex during hotkey_exit() Hans de Goede
2024-04-24 12:28 ` [PATCH v2 02/24] platform/x86: thinkpad_acpi: Provide hotkey_poll_stop_sync() dummy Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 04/24] platform/x86: thinkpad_acpi: Drop ignore_acpi_ev Hans de Goede
` (23 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
send_acpi_ev and ignore_acpi_ev are already initialized to true and false
respectively by hotkey_notify() before calling the various helpers. Drop
the needless re-initialization from the helpers.
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index fc5681808c3b..007223fded30 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3754,14 +3754,12 @@ static bool hotkey_notify_extended_hotkey(const u32 hkey)
return false;
}
+/* 0x1000-0x1FFF: key presses */
static bool hotkey_notify_hotkey(const u32 hkey,
bool *send_acpi_ev,
bool *ignore_acpi_ev)
{
- /* 0x1000-0x1FFF: key presses */
unsigned int scancode = hkey & 0xfff;
- *send_acpi_ev = true;
- *ignore_acpi_ev = false;
/*
* Original events are in the 0x10XX range, the adaptive keyboard
@@ -3794,14 +3792,11 @@ static bool hotkey_notify_hotkey(const u32 hkey,
return false;
}
+/* 0x2000-0x2FFF: Wakeup reason */
static bool hotkey_notify_wakeup(const u32 hkey,
bool *send_acpi_ev,
bool *ignore_acpi_ev)
{
- /* 0x2000-0x2FFF: Wakeup reason */
- *send_acpi_ev = true;
- *ignore_acpi_ev = false;
-
switch (hkey) {
case TP_HKEY_EV_WKUP_S3_UNDOCK: /* suspend, undock */
case TP_HKEY_EV_WKUP_S4_UNDOCK: /* hibernation, undock */
@@ -3834,14 +3829,11 @@ static bool hotkey_notify_wakeup(const u32 hkey,
return true;
}
+/* 0x4000-0x4FFF: dock-related events */
static bool hotkey_notify_dockevent(const u32 hkey,
bool *send_acpi_ev,
bool *ignore_acpi_ev)
{
- /* 0x4000-0x4FFF: dock-related events */
- *send_acpi_ev = true;
- *ignore_acpi_ev = false;
-
switch (hkey) {
case TP_HKEY_EV_UNDOCK_ACK:
/* ACPI undock operation completed after wakeup */
@@ -3879,14 +3871,11 @@ static bool hotkey_notify_dockevent(const u32 hkey,
}
}
+/* 0x5000-0x5FFF: human interface helpers */
static bool hotkey_notify_usrevent(const u32 hkey,
bool *send_acpi_ev,
bool *ignore_acpi_ev)
{
- /* 0x5000-0x5FFF: human interface helpers */
- *send_acpi_ev = true;
- *ignore_acpi_ev = false;
-
switch (hkey) {
case TP_HKEY_EV_PEN_INSERTED: /* X61t: tablet pen inserted into bay */
case TP_HKEY_EV_PEN_REMOVED: /* X61t: tablet pen removed from bay */
@@ -3914,14 +3903,11 @@ static bool hotkey_notify_usrevent(const u32 hkey,
static void thermal_dump_all_sensors(void);
static void palmsensor_refresh(void);
+/* 0x6000-0x6FFF: thermal alarms/notices and keyboard events */
static bool hotkey_notify_6xxx(const u32 hkey,
bool *send_acpi_ev,
bool *ignore_acpi_ev)
{
- /* 0x6000-0x6FFF: thermal alarms/notices and keyboard events */
- *send_acpi_ev = true;
- *ignore_acpi_ev = false;
-
switch (hkey) {
case TP_HKEY_EV_THM_TABLE_CHANGED:
pr_debug("EC reports: Thermal Table has changed\n");
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 04/24] platform/x86: thinkpad_acpi: Drop ignore_acpi_ev
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (2 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 03/24] platform/x86: thinkpad_acpi: Drop setting send_/ignore_acpi_ev defaults twice Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-25 7:13 ` Ilpo Järvinen
2024-04-24 12:28 ` [PATCH v2 05/24] platform/x86: thinkpad_acpi: Use tpacpi_input_send_key() in adaptive kbd code Hans de Goede
` (22 subsequent siblings)
26 siblings, 1 reply; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Setting ignore_acpi_ev to true has the same result as setting
send_acpi_ev to false, so there is no need to have both.
Drop ignore_acpi_ev.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 56 +++++++++-------------------
1 file changed, 17 insertions(+), 39 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 007223fded30..bb6b880a5b50 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3755,9 +3755,7 @@ static bool hotkey_notify_extended_hotkey(const u32 hkey)
}
/* 0x1000-0x1FFF: key presses */
-static bool hotkey_notify_hotkey(const u32 hkey,
- bool *send_acpi_ev,
- bool *ignore_acpi_ev)
+static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
{
unsigned int scancode = hkey & 0xfff;
@@ -3772,12 +3770,10 @@ static bool hotkey_notify_hotkey(const u32 hkey,
scancode <= TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
/* HKEY event 0x1001 is scancode 0x00 */
scancode--;
- if (!(hotkey_source_mask & (1 << scancode))) {
+ if (!(hotkey_source_mask & (1 << scancode)))
tpacpi_input_send_key_masked(scancode);
- *send_acpi_ev = false;
- } else {
- *ignore_acpi_ev = true;
- }
+
+ *send_acpi_ev = false;
return true;
}
break;
@@ -3793,21 +3789,19 @@ static bool hotkey_notify_hotkey(const u32 hkey,
}
/* 0x2000-0x2FFF: Wakeup reason */
-static bool hotkey_notify_wakeup(const u32 hkey,
- bool *send_acpi_ev,
- bool *ignore_acpi_ev)
+static bool hotkey_notify_wakeup(const u32 hkey, bool *send_acpi_ev)
{
switch (hkey) {
case TP_HKEY_EV_WKUP_S3_UNDOCK: /* suspend, undock */
case TP_HKEY_EV_WKUP_S4_UNDOCK: /* hibernation, undock */
hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK;
- *ignore_acpi_ev = true;
+ *send_acpi_ev = false;
break;
case TP_HKEY_EV_WKUP_S3_BAYEJ: /* suspend, bay eject */
case TP_HKEY_EV_WKUP_S4_BAYEJ: /* hibernation, bay eject */
hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ;
- *ignore_acpi_ev = true;
+ *send_acpi_ev = false;
break;
case TP_HKEY_EV_WKUP_S3_BATLOW: /* Battery on critical low level/S3 */
@@ -3830,9 +3824,7 @@ static bool hotkey_notify_wakeup(const u32 hkey,
}
/* 0x4000-0x4FFF: dock-related events */
-static bool hotkey_notify_dockevent(const u32 hkey,
- bool *send_acpi_ev,
- bool *ignore_acpi_ev)
+static bool hotkey_notify_dockevent(const u32 hkey, bool *send_acpi_ev)
{
switch (hkey) {
case TP_HKEY_EV_UNDOCK_ACK:
@@ -3863,7 +3855,6 @@ static bool hotkey_notify_dockevent(const u32 hkey,
case TP_HKEY_EV_KBD_COVER_ATTACH:
case TP_HKEY_EV_KBD_COVER_DETACH:
*send_acpi_ev = false;
- *ignore_acpi_ev = true;
return true;
default:
@@ -3872,9 +3863,7 @@ static bool hotkey_notify_dockevent(const u32 hkey,
}
/* 0x5000-0x5FFF: human interface helpers */
-static bool hotkey_notify_usrevent(const u32 hkey,
- bool *send_acpi_ev,
- bool *ignore_acpi_ev)
+static bool hotkey_notify_usrevent(const u32 hkey, bool *send_acpi_ev)
{
switch (hkey) {
case TP_HKEY_EV_PEN_INSERTED: /* X61t: tablet pen inserted into bay */
@@ -3892,7 +3881,7 @@ static bool hotkey_notify_usrevent(const u32 hkey,
case TP_HKEY_EV_LID_OPEN: /* Lid opened */
case TP_HKEY_EV_BRGHT_CHANGED: /* brightness changed */
/* do not propagate these events */
- *ignore_acpi_ev = true;
+ *send_acpi_ev = false;
return true;
default:
@@ -3904,9 +3893,7 @@ static void thermal_dump_all_sensors(void);
static void palmsensor_refresh(void);
/* 0x6000-0x6FFF: thermal alarms/notices and keyboard events */
-static bool hotkey_notify_6xxx(const u32 hkey,
- bool *send_acpi_ev,
- bool *ignore_acpi_ev)
+static bool hotkey_notify_6xxx(const u32 hkey, bool *send_acpi_ev)
{
switch (hkey) {
case TP_HKEY_EV_THM_TABLE_CHANGED:
@@ -3953,14 +3940,12 @@ static bool hotkey_notify_6xxx(const u32 hkey,
/* key press events, we just ignore them as long as the EC
* is still reporting them in the normal keyboard stream */
*send_acpi_ev = false;
- *ignore_acpi_ev = true;
return true;
case TP_HKEY_EV_KEY_FN_ESC:
/* Get the media key status to force the status LED to update */
acpi_evalf(hkey_handle, NULL, "GMKS", "v");
*send_acpi_ev = false;
- *ignore_acpi_ev = true;
return true;
case TP_HKEY_EV_TABLET_CHANGED:
@@ -3988,7 +3973,6 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
{
u32 hkey;
bool send_acpi_ev;
- bool ignore_acpi_ev;
bool known_ev;
if (event != 0x80) {
@@ -4013,18 +3997,15 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
}
send_acpi_ev = true;
- ignore_acpi_ev = false;
switch (hkey >> 12) {
case 1:
/* 0x1000-0x1FFF: key presses */
- known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev,
- &ignore_acpi_ev);
+ known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev);
break;
case 2:
/* 0x2000-0x2FFF: Wakeup reason */
- known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev,
- &ignore_acpi_ev);
+ known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev);
break;
case 3:
/* 0x3000-0x3FFF: bay-related wakeups */
@@ -4045,19 +4026,16 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
break;
case 4:
/* 0x4000-0x4FFF: dock-related events */
- known_ev = hotkey_notify_dockevent(hkey, &send_acpi_ev,
- &ignore_acpi_ev);
+ known_ev = hotkey_notify_dockevent(hkey, &send_acpi_ev);
break;
case 5:
/* 0x5000-0x5FFF: human interface helpers */
- known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev,
- &ignore_acpi_ev);
+ known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev);
break;
case 6:
/* 0x6000-0x6FFF: thermal alarms/notices and
* keyboard events */
- known_ev = hotkey_notify_6xxx(hkey, &send_acpi_ev,
- &ignore_acpi_ev);
+ known_ev = hotkey_notify_6xxx(hkey, &send_acpi_ev);
break;
case 7:
/* 0x7000-0x7FFF: misc */
@@ -4079,7 +4057,7 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
}
/* netlink events */
- if (!ignore_acpi_ev && send_acpi_ev) {
+ if (send_acpi_ev) {
acpi_bus_generate_netlink_event(
ibm->acpi->device->pnp.device_class,
dev_name(&ibm->acpi->device->dev),
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 05/24] platform/x86: thinkpad_acpi: Use tpacpi_input_send_key() in adaptive kbd code
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (3 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 04/24] platform/x86: thinkpad_acpi: Drop ignore_acpi_ev Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 06/24] platform/x86: thinkpad_acpi: Do hkey to scancode translation later Hans de Goede
` (21 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Use tpacpi_input_send_key() in adaptive_keyboard_hotkey_notify_hotkey()
instead of re-implementing it there.
Note this change will also result in a behavioral change, key presses on
the adaptive keyboard will now also send a EV_MSC event with the scancode,
just like all other hotkey presses already do. This is not a bug but
a feature.
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index bb6b880a5b50..126e39367924 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3670,7 +3670,6 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
{
int current_mode = 0;
int new_mode = 0;
- int keycode;
switch (scancode) {
case DFR_CHANGE_ROW:
@@ -3711,19 +3710,8 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
scancode);
return false;
}
- keycode = hotkey_keycode_map[scancode - FIRST_ADAPTIVE_KEY +
- TP_ACPI_HOTKEYSCAN_ADAPTIVE_START];
- if (keycode != KEY_RESERVED) {
- mutex_lock(&tpacpi_inputdev_send_mutex);
-
- input_report_key(tpacpi_inputdev, keycode, 1);
- input_sync(tpacpi_inputdev);
-
- input_report_key(tpacpi_inputdev, keycode, 0);
- input_sync(tpacpi_inputdev);
-
- mutex_unlock(&tpacpi_inputdev_send_mutex);
- }
+ tpacpi_input_send_key(scancode - FIRST_ADAPTIVE_KEY +
+ TP_ACPI_HOTKEYSCAN_ADAPTIVE_START);
return true;
}
}
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 06/24] platform/x86: thinkpad_acpi: Do hkey to scancode translation later
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (4 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 05/24] platform/x86: thinkpad_acpi: Use tpacpi_input_send_key() in adaptive kbd code Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 07/24] platform/x86: thinkpad_acpi: Make tpacpi_driver_event() return if it handled the event Hans de Goede
` (20 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Modify hotkey_notify_hotkey() and it helpers to mostly directly operate
on hkey codes (TP_HKEY_EV_* returned by "MHKP") instead of on the 0 -
TPACPI_HOTKEY_MAP_LEN scancodes used for scancode -> keycode translation.
Keeping things in the hkey format as long a possible is a bit cleaner and
this patch prepares things for moving to sparse-keymaps.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 71 ++++++++++++++--------------
1 file changed, 36 insertions(+), 35 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 126e39367924..c009885c8820 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -157,15 +157,30 @@ enum {
/* HKEY events */
enum tpacpi_hkey_event_t {
- /* Hotkey-related */
- TP_HKEY_EV_HOTKEY_BASE = 0x1001, /* first hotkey (FN+F1) */
+ /* Original hotkeys */
+ TP_HKEY_EV_ORIG_KEY_START = 0x1001, /* First hotkey (FN+F1) */
TP_HKEY_EV_BRGHT_UP = 0x1010, /* Brightness up */
TP_HKEY_EV_BRGHT_DOWN = 0x1011, /* Brightness down */
TP_HKEY_EV_KBD_LIGHT = 0x1012, /* Thinklight/kbd backlight */
TP_HKEY_EV_VOL_UP = 0x1015, /* Volume up or unmute */
TP_HKEY_EV_VOL_DOWN = 0x1016, /* Volume down or unmute */
TP_HKEY_EV_VOL_MUTE = 0x1017, /* Mixer output mute */
+ TP_HKEY_EV_ORIG_KEY_END = 0x1020, /* Last original hotkey code */
+
+ /* Adaptive keyboard (2014 X1 Carbon) */
+ TP_HKEY_EV_DFR_CHANGE_ROW = 0x1101, /* Change adaptive kbd Fn row mode */
+ TP_HKEY_EV_DFR_S_QUICKVIEW_ROW = 0x1102, /* Set adap. kbd Fn row to function mode */
+ TP_HKEY_EV_ADAPTIVE_KEY_START = 0x1103, /* First hotkey code on adaptive kbd */
+ TP_HKEY_EV_ADAPTIVE_KEY_END = 0x1116, /* Last hotkey code on adaptive kbd */
+
+ /* Extended hotkey events in 2017+ models */
+ TP_HKEY_EV_EXTENDED_KEY_START = 0x1300, /* First extended hotkey code */
TP_HKEY_EV_PRIVACYGUARD_TOGGLE = 0x130f, /* Toggle priv.guard on/off */
+ TP_HKEY_EV_EXTENDED_KEY_END = 0x1319, /* Last extended hotkey code using
+ * hkey -> scancode translation for
+ * compat. Later codes are entered
+ * directly in the sparse-keymap.
+ */
TP_HKEY_EV_AMT_TOGGLE = 0x131a, /* Toggle AMT on/off */
TP_HKEY_EV_PROFILE_TOGGLE = 0x131f, /* Toggle platform profile */
@@ -1752,7 +1767,7 @@ enum { /* hot key scan codes (derived from ACPI DSDT) */
TP_ACPI_HOTKEYSCAN_UNK8,
/* Adaptive keyboard keycodes */
- TP_ACPI_HOTKEYSCAN_ADAPTIVE_START,
+ TP_ACPI_HOTKEYSCAN_ADAPTIVE_START, /* 32 / 0x20 */
TP_ACPI_HOTKEYSCAN_MUTE2 = TP_ACPI_HOTKEYSCAN_ADAPTIVE_START,
TP_ACPI_HOTKEYSCAN_BRIGHTNESS_ZERO,
TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL,
@@ -1775,7 +1790,7 @@ enum { /* hot key scan codes (derived from ACPI DSDT) */
TP_ACPI_HOTKEYSCAN_ROTATE_DISPLAY,
/* Lenovo extended keymap, starting at 0x1300 */
- TP_ACPI_HOTKEYSCAN_EXTENDED_START,
+ TP_ACPI_HOTKEYSCAN_EXTENDED_START, /* 52 / 0x34 */
/* first new observed key (star, favorites) is 0x1311 */
TP_ACPI_HOTKEYSCAN_STAR = 69,
TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL2,
@@ -3612,10 +3627,6 @@ static const int adaptive_keyboard_modes[] = {
FUNCTION_MODE
};
-#define DFR_CHANGE_ROW 0x101
-#define DFR_SHOW_QUICKVIEW_ROW 0x102
-#define FIRST_ADAPTIVE_KEY 0x103
-
/* press Fn key a while second, it will switch to Function Mode. Then
* release Fn key, previous mode be restored.
*/
@@ -3666,13 +3677,13 @@ static int adaptive_keyboard_get_next_mode(int mode)
return adaptive_keyboard_modes[i];
}
-static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
+static bool adaptive_keyboard_hotkey_notify_hotkey(const u32 hkey)
{
int current_mode = 0;
int new_mode = 0;
- switch (scancode) {
- case DFR_CHANGE_ROW:
+ switch (hkey) {
+ case TP_HKEY_EV_DFR_CHANGE_ROW:
if (adaptive_keyboard_mode_is_saved) {
new_mode = adaptive_keyboard_prev_mode;
adaptive_keyboard_mode_is_saved = false;
@@ -3689,7 +3700,7 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
return true;
- case DFR_SHOW_QUICKVIEW_ROW:
+ case TP_HKEY_EV_DFR_S_QUICKVIEW_ROW:
current_mode = adaptive_keyboard_get_mode();
if (current_mode < 0)
return false;
@@ -3702,15 +3713,12 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
return true;
default:
- if (scancode < FIRST_ADAPTIVE_KEY ||
- scancode >= FIRST_ADAPTIVE_KEY +
- TP_ACPI_HOTKEYSCAN_EXTENDED_START -
- TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
- pr_info("Unhandled adaptive keyboard key: 0x%x\n",
- scancode);
+ 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(scancode - FIRST_ADAPTIVE_KEY +
+ tpacpi_input_send_key(hkey - TP_HKEY_EV_ADAPTIVE_KEY_START +
TP_ACPI_HOTKEYSCAN_ADAPTIVE_START);
return true;
}
@@ -3718,8 +3726,6 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
static bool hotkey_notify_extended_hotkey(const u32 hkey)
{
- unsigned int scancode;
-
switch (hkey) {
case TP_HKEY_EV_PRIVACYGUARD_TOGGLE:
case TP_HKEY_EV_AMT_TOGGLE:
@@ -3728,13 +3734,10 @@ static bool hotkey_notify_extended_hotkey(const u32 hkey)
return true;
}
- /* Extended keycodes start at 0x300 and our offset into the map
- * TP_ACPI_HOTKEYSCAN_EXTENDED_START. The calculated scancode
- * will be positive, but might not be in the correct range.
- */
- scancode = (hkey & 0xfff) - (0x300 - TP_ACPI_HOTKEYSCAN_EXTENDED_START);
- if (scancode >= TP_ACPI_HOTKEYSCAN_EXTENDED_START &&
- scancode < TPACPI_HOTKEY_MAP_LEN) {
+ 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;
}
@@ -3745,7 +3748,7 @@ static bool hotkey_notify_extended_hotkey(const u32 hkey)
/* 0x1000-0x1FFF: key presses */
static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
{
- unsigned int scancode = hkey & 0xfff;
+ unsigned int scancode = hkey - TP_HKEY_EV_ORIG_KEY_START;
/*
* Original events are in the 0x10XX range, the adaptive keyboard
@@ -3754,10 +3757,8 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
*/
switch ((hkey >> 8) & 0xf) {
case 0:
- if (scancode > 0 &&
- scancode <= TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
- /* HKEY event 0x1001 is scancode 0x00 */
- scancode--;
+ if (hkey >= TP_HKEY_EV_ORIG_KEY_START &&
+ hkey <= TP_HKEY_EV_ORIG_KEY_END) {
if (!(hotkey_source_mask & (1 << scancode)))
tpacpi_input_send_key_masked(scancode);
@@ -3767,7 +3768,7 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
break;
case 1:
- return adaptive_keyboard_hotkey_notify_hotkey(scancode);
+ return adaptive_keyboard_hotkey_notify_hotkey(hkey);
case 3:
return hotkey_notify_extended_hotkey(hkey);
@@ -11150,7 +11151,7 @@ static void tpacpi_driver_event(const unsigned int hkey_event)
static void hotkey_driver_event(const unsigned int scancode)
{
- tpacpi_driver_event(TP_HKEY_EV_HOTKEY_BASE + scancode);
+ tpacpi_driver_event(TP_HKEY_EV_ORIG_KEY_START + scancode);
}
/* --------------------------------------------------------------------- */
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 07/24] platform/x86: thinkpad_acpi: Make tpacpi_driver_event() return if it handled the event
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (5 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 06/24] platform/x86: thinkpad_acpi: Do hkey to scancode translation later Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 08/24] platform/x86: thinkpad_acpi: Move adaptive kbd event handling to tpacpi_driver_event() Hans de Goede
` (19 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
tpacpi_driver_event() already only responds to hkey events which it knows
about. Make it return a bool and return true when it has handled the event.
This avoids the need to list TP_HKEY_EV_foo values to which it responds
both in its caller and in the function itself.
Instead callers can now call it unconditionally and check the return value.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 115 ++++++++++++++-------------
1 file changed, 61 insertions(+), 54 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index c009885c8820..0bbc462d604c 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -1918,7 +1918,7 @@ static u32 hotkey_acpi_mask; /* events enabled in firmware */
static u16 *hotkey_keycode_map;
-static void tpacpi_driver_event(const unsigned int hkey_event);
+static bool tpacpi_driver_event(const unsigned int hkey_event);
static void hotkey_driver_event(const unsigned int scancode);
static void hotkey_poll_setup(const bool may_warn);
@@ -3726,13 +3726,8 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(const u32 hkey)
static bool hotkey_notify_extended_hotkey(const u32 hkey)
{
- switch (hkey) {
- case TP_HKEY_EV_PRIVACYGUARD_TOGGLE:
- case TP_HKEY_EV_AMT_TOGGLE:
- case TP_HKEY_EV_PROFILE_TOGGLE:
- tpacpi_driver_event(hkey);
+ if (tpacpi_driver_event(hkey))
return true;
- }
if (hkey >= TP_HKEY_EV_EXTENDED_KEY_START &&
hkey <= TP_HKEY_EV_EXTENDED_KEY_END) {
@@ -11081,72 +11076,84 @@ static struct platform_driver tpacpi_hwmon_pdriver = {
* HKEY event callout for other subdrivers go here
* (yes, it is ugly, but it is quick, safe, and gets the job done
*/
-static void tpacpi_driver_event(const unsigned int hkey_event)
+static bool tpacpi_driver_event(const unsigned int hkey_event)
{
- if (ibm_backlight_device) {
- switch (hkey_event) {
- case TP_HKEY_EV_BRGHT_UP:
- case TP_HKEY_EV_BRGHT_DOWN:
+ switch (hkey_event) {
+ case TP_HKEY_EV_BRGHT_UP:
+ case TP_HKEY_EV_BRGHT_DOWN:
+ if (ibm_backlight_device)
tpacpi_brightness_notify_change();
- }
- }
- if (alsa_card) {
- switch (hkey_event) {
- case TP_HKEY_EV_VOL_UP:
- case TP_HKEY_EV_VOL_DOWN:
- case TP_HKEY_EV_VOL_MUTE:
- volume_alsa_notify_change();
- }
- }
- if (tp_features.kbdlight && hkey_event == TP_HKEY_EV_KBD_LIGHT) {
- enum led_brightness brightness;
-
- mutex_lock(&kbdlight_mutex);
-
/*
- * Check the brightness actually changed, setting the brightness
- * through kbdlight_set_level() also triggers this event.
+ * Key press events are suppressed by default hotkey_user_mask
+ * and should still be reported if explicitly requested.
*/
- brightness = kbdlight_sysfs_get(NULL);
- if (kbdlight_brightness != brightness) {
- kbdlight_brightness = brightness;
- led_classdev_notify_brightness_hw_changed(
- &tpacpi_led_kbdlight.led_classdev, brightness);
+ return false;
+ case TP_HKEY_EV_VOL_UP:
+ case TP_HKEY_EV_VOL_DOWN:
+ case TP_HKEY_EV_VOL_MUTE:
+ if (alsa_card)
+ volume_alsa_notify_change();
+
+ /* Key events are suppressed by default hotkey_user_mask */
+ return false;
+ case TP_HKEY_EV_KBD_LIGHT:
+ if (tp_features.kbdlight) {
+ enum led_brightness brightness;
+
+ mutex_lock(&kbdlight_mutex);
+
+ /*
+ * Check the brightness actually changed, setting the brightness
+ * through kbdlight_set_level() also triggers this event.
+ */
+ brightness = kbdlight_sysfs_get(NULL);
+ if (kbdlight_brightness != brightness) {
+ kbdlight_brightness = brightness;
+ led_classdev_notify_brightness_hw_changed(
+ &tpacpi_led_kbdlight.led_classdev, brightness);
+ }
+
+ mutex_unlock(&kbdlight_mutex);
}
-
- mutex_unlock(&kbdlight_mutex);
- }
-
- if (hkey_event == TP_HKEY_EV_THM_CSM_COMPLETED) {
+ /* Key events are suppressed by default hotkey_user_mask */
+ return false;
+ case TP_HKEY_EV_THM_CSM_COMPLETED:
lapsensor_refresh();
/* If we are already accessing DYTC then skip dytc update */
if (!atomic_add_unless(&dytc_ignore_event, -1, 0))
dytc_profile_refresh();
- }
- if (lcdshadow_dev && hkey_event == TP_HKEY_EV_PRIVACYGUARD_TOGGLE) {
- enum drm_privacy_screen_status old_hw_state;
- bool changed;
+ return true;
+ case TP_HKEY_EV_PRIVACYGUARD_TOGGLE:
+ if (lcdshadow_dev) {
+ enum drm_privacy_screen_status old_hw_state;
+ bool changed;
- mutex_lock(&lcdshadow_dev->lock);
- old_hw_state = lcdshadow_dev->hw_state;
- lcdshadow_get_hw_state(lcdshadow_dev);
- changed = lcdshadow_dev->hw_state != old_hw_state;
- mutex_unlock(&lcdshadow_dev->lock);
+ mutex_lock(&lcdshadow_dev->lock);
+ old_hw_state = lcdshadow_dev->hw_state;
+ lcdshadow_get_hw_state(lcdshadow_dev);
+ changed = lcdshadow_dev->hw_state != old_hw_state;
+ mutex_unlock(&lcdshadow_dev->lock);
- if (changed)
- drm_privacy_screen_call_notifier_chain(lcdshadow_dev);
- }
- if (hkey_event == TP_HKEY_EV_AMT_TOGGLE) {
+ if (changed)
+ drm_privacy_screen_call_notifier_chain(lcdshadow_dev);
+ }
+ return true;
+ case TP_HKEY_EV_AMT_TOGGLE:
/* If we're enabling AMT we need to force balanced mode */
if (!dytc_amt_active)
/* This will also set AMT mode enabled */
dytc_profile_set(NULL, PLATFORM_PROFILE_BALANCED);
else
dytc_control_amt(!dytc_amt_active);
- }
- if (hkey_event == TP_HKEY_EV_PROFILE_TOGGLE)
+
+ return true;
+ case TP_HKEY_EV_PROFILE_TOGGLE:
platform_profile_cycle();
+ return true;
+ }
+
+ return false;
}
static void hotkey_driver_event(const unsigned int scancode)
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 08/24] platform/x86: thinkpad_acpi: Move adaptive kbd event handling to tpacpi_driver_event()
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (6 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 07/24] platform/x86: thinkpad_acpi: Make tpacpi_driver_event() return if it handled the event Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 09/24] platform/x86: thinkpad_acpi: Move special original hotkeys handling out of switch-case Hans de Goede
` (18 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Factor out the adaptive kbd non hotkey event handling into
adaptive_keyboard_change_row() and adaptive_keyboard_s_quickview_row()
helpers and move the handling of TP_HKEY_EV_DFR_CHANGE_ROW and
TP_HKEY_EV_DFR_S_QUICKVIEW_ROW to tpacpi_driver_event().
This groups all the handling of hotkey events which do not emit
a key press event together in tpacpi_driver_event().
This also drops the returning of false as known-event value when
adaptive_keyboard_get_mode() / adaptive_keyboard_set_mode() fail.
These functions already log an error on failure, returning false just
leads to an extra messgae being logged about the hkey event being
unknown, which is wrong as the event is not unknown.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 86 +++++++++++++++-------------
1 file changed, 46 insertions(+), 40 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 0bbc462d604c..f4d7f3c25a4a 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3677,51 +3677,51 @@ static int adaptive_keyboard_get_next_mode(int mode)
return adaptive_keyboard_modes[i];
}
+static void adaptive_keyboard_change_row(void)
+{
+ int mode;
+
+ if (adaptive_keyboard_mode_is_saved) {
+ mode = adaptive_keyboard_prev_mode;
+ adaptive_keyboard_mode_is_saved = false;
+ } else {
+ mode = adaptive_keyboard_get_mode();
+ if (mode < 0)
+ return;
+ mode = adaptive_keyboard_get_next_mode(mode);
+ }
+
+ adaptive_keyboard_set_mode(mode);
+}
+
+static void adaptive_keyboard_s_quickview_row(void)
+{
+ int mode;
+
+ mode = adaptive_keyboard_get_mode();
+ if (mode < 0)
+ return;
+
+ adaptive_keyboard_prev_mode = mode;
+ adaptive_keyboard_mode_is_saved = true;
+
+ adaptive_keyboard_set_mode(FUNCTION_MODE);
+}
+
static bool adaptive_keyboard_hotkey_notify_hotkey(const u32 hkey)
{
- int current_mode = 0;
- int new_mode = 0;
-
- switch (hkey) {
- case TP_HKEY_EV_DFR_CHANGE_ROW:
- if (adaptive_keyboard_mode_is_saved) {
- new_mode = adaptive_keyboard_prev_mode;
- adaptive_keyboard_mode_is_saved = false;
- } else {
- current_mode = adaptive_keyboard_get_mode();
- if (current_mode < 0)
- return false;
- new_mode = adaptive_keyboard_get_next_mode(
- current_mode);
- }
-
- if (adaptive_keyboard_set_mode(new_mode) < 0)
- return false;
-
+ if (tpacpi_driver_event(hkey))
return true;
- case TP_HKEY_EV_DFR_S_QUICKVIEW_ROW:
- current_mode = adaptive_keyboard_get_mode();
- if (current_mode < 0)
- return false;
-
- adaptive_keyboard_prev_mode = current_mode;
- adaptive_keyboard_mode_is_saved = true;
-
- if (adaptive_keyboard_set_mode (FUNCTION_MODE) < 0)
- return false;
- return true;
-
- default:
- 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;
+ 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)
@@ -11117,6 +11117,12 @@ static bool tpacpi_driver_event(const unsigned int hkey_event)
}
/* Key events are suppressed by default hotkey_user_mask */
return false;
+ case TP_HKEY_EV_DFR_CHANGE_ROW:
+ adaptive_keyboard_change_row();
+ return true;
+ case TP_HKEY_EV_DFR_S_QUICKVIEW_ROW:
+ adaptive_keyboard_s_quickview_row();
+ return true;
case TP_HKEY_EV_THM_CSM_COMPLETED:
lapsensor_refresh();
/* If we are already accessing DYTC then skip dytc update */
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 09/24] platform/x86: thinkpad_acpi: Move special original hotkeys handling out of switch-case
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (7 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 08/24] platform/x86: thinkpad_acpi: Move adaptive kbd event handling to tpacpi_driver_event() Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 10/24] platform/x86: thinkpad_acpi: Move hotkey_user_mask check to tpacpi_input_send_key() Hans de Goede
` (17 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Move the special handling (send_acpi_ev = false, hotkey_source_mask check)
for original hotkeys out of the switch-case in hotkey_notify_hotkey().
This is a preparation patch for further refactoring.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index f4d7f3c25a4a..ba440213ae49 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3745,6 +3745,15 @@ 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 */
+ if (hotkey_source_mask & (1 << scancode))
+ return true;
+ }
+
/*
* Original events are in the 0x10XX range, the adaptive keyboard
* found in 2014 X1 Carbon emits events are of 0x11XX. In 2017
@@ -3754,10 +3763,7 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
case 0:
if (hkey >= TP_HKEY_EV_ORIG_KEY_START &&
hkey <= TP_HKEY_EV_ORIG_KEY_END) {
- if (!(hotkey_source_mask & (1 << scancode)))
- tpacpi_input_send_key_masked(scancode);
-
- *send_acpi_ev = false;
+ tpacpi_input_send_key_masked(scancode);
return true;
}
break;
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 10/24] platform/x86: thinkpad_acpi: Move hotkey_user_mask check to tpacpi_input_send_key()
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (8 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 09/24] platform/x86: thinkpad_acpi: Move special original hotkeys handling out of switch-case Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 11/24] platform/x86: thinkpad_acpi: Always call tpacpi_driver_event() for hotkeys Hans de Goede
` (16 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Move hotkey_user_mask check to tpacpi_input_send_key(), this is
a preparation patch for further refactoring.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index ba440213ae49..05c1a562f6a1 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -2256,6 +2256,10 @@ 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;
+
if (keycode != KEY_RESERVED) {
mutex_lock(&tpacpi_inputdev_send_mutex);
@@ -2275,8 +2279,7 @@ static void tpacpi_input_send_key(const unsigned int scancode)
static void tpacpi_input_send_key_masked(const unsigned int scancode)
{
hotkey_driver_event(scancode);
- if (hotkey_user_mask & (1 << scancode))
- tpacpi_input_send_key(scancode);
+ tpacpi_input_send_key(scancode);
}
#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 11/24] platform/x86: thinkpad_acpi: Always call tpacpi_driver_event() for hotkeys
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (9 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 10/24] platform/x86: thinkpad_acpi: Move hotkey_user_mask check to tpacpi_input_send_key() Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 12/24] platform/x86: thinkpad_acpi: Drop tpacpi_input_send_key_masked() and hotkey_driver_event() Hans de Goede
` (15 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Call tpacpi_driver_event() at the top of hotkey_notify_hotkey() for all
(orig / adaptive / extended) hotkey types, rather then having the orig
code path call tpacpi_input_send_key_masked() which calls it through
hotkey_driver_event() and having the adaptive / extended helpers call
it separately.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 05c1a562f6a1..25758d252f27 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3713,9 +3713,6 @@ static void adaptive_keyboard_s_quickview_row(void)
static bool adaptive_keyboard_hotkey_notify_hotkey(const u32 hkey)
{
- if (tpacpi_driver_event(hkey))
- return true;
-
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);
@@ -3729,9 +3726,6 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(const u32 hkey)
static bool hotkey_notify_extended_hotkey(const u32 hkey)
{
- if (tpacpi_driver_event(hkey))
- return true;
-
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 +
@@ -3757,6 +3751,9 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
return true;
}
+ 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
@@ -3766,7 +3763,7 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
case 0:
if (hkey >= TP_HKEY_EV_ORIG_KEY_START &&
hkey <= TP_HKEY_EV_ORIG_KEY_END) {
- tpacpi_input_send_key_masked(scancode);
+ tpacpi_input_send_key(scancode);
return true;
}
break;
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 12/24] platform/x86: thinkpad_acpi: Drop tpacpi_input_send_key_masked() and hotkey_driver_event()
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (10 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 11/24] platform/x86: thinkpad_acpi: Always call tpacpi_driver_event() for hotkeys Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 13/24] platform/x86: thinkpad_acpi: Move hkey > scancode mapping to tpacpi_input_send_key() Hans de Goede
` (14 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Both are only 1 / 2 lines and both only have 1 caller fold the contents
into tpacpi_hotkey_send_key() which is their single caller.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 25758d252f27..593093884cc5 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -1919,7 +1919,6 @@ static u32 hotkey_acpi_mask; /* events enabled in firmware */
static u16 *hotkey_keycode_map;
static bool tpacpi_driver_event(const unsigned int hkey_event);
-static void hotkey_driver_event(const unsigned int scancode);
static void hotkey_poll_setup(const bool may_warn);
/* HKEY.MHKG() return bits */
@@ -2275,20 +2274,14 @@ static void tpacpi_input_send_key(const unsigned int scancode)
}
}
-/* Do NOT call without validating scancode first */
-static void tpacpi_input_send_key_masked(const unsigned int scancode)
-{
- hotkey_driver_event(scancode);
- tpacpi_input_send_key(scancode);
-}
-
#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
static struct tp_acpi_drv_struct ibm_hotkey_acpidriver;
/* Do NOT call without validating scancode first */
static void tpacpi_hotkey_send_key(unsigned int scancode)
{
- tpacpi_input_send_key_masked(scancode);
+ tpacpi_driver_event(TP_HKEY_EV_ORIG_KEY_START + scancode);
+ tpacpi_input_send_key(scancode);
}
static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
@@ -11168,11 +11161,6 @@ static bool tpacpi_driver_event(const unsigned int hkey_event)
return false;
}
-static void hotkey_driver_event(const unsigned int scancode)
-{
- tpacpi_driver_event(TP_HKEY_EV_ORIG_KEY_START + scancode);
-}
-
/* --------------------------------------------------------------------- */
/* /proc support */
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 13/24] platform/x86: thinkpad_acpi: Move hkey > scancode mapping to tpacpi_input_send_key()
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (11 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 12/24] platform/x86: thinkpad_acpi: Drop tpacpi_input_send_key_masked() and hotkey_driver_event() Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 14/24] platform/x86: thinkpad_acpi: Move tpacpi_driver_event() call " Hans de Goede
` (13 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
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>
---
drivers/platform/x86/thinkpad_acpi.c | 81 +++++++++-------------------
1 file changed, 24 insertions(+), 57 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 593093884cc5..08419dede995 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)
+static bool tpacpi_input_send_key(const u32 hkey)
{
- const unsigned int keycode = hotkey_keycode_map[scancode];
+ unsigned int keycode, scancode;
- if (scancode < TP_ACPI_HOTKEYSCAN_ADAPTIVE_START &&
- !(hotkey_user_mask & (1 << scancode)))
- return;
+ 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 */
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 14/24] platform/x86: thinkpad_acpi: Move tpacpi_driver_event() call to tpacpi_input_send_key()
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (12 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 13/24] platform/x86: thinkpad_acpi: Move hkey > scancode mapping to tpacpi_input_send_key() Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 15/24] platform/x86: thinkpad_acpi: Do not send ACPI netlink events for unknown hotkeys Hans de Goede
` (12 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
All callers of tpacpi_input_send_key() first call tpacpi_driver_event(),
move the tpacpi_driver_event() inside tpacpi_input_send_key() to avoid
code duplication.
For the original hotkey codes 0x1001 - 0x1020 tpacpi_driver_event() never
returns true. So the added "return true;" inside tpacpi_input_send_key()
never happens when called from tpacpi_hotkey_send_key() so behavior does
not change.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 08419dede995..9b38770412ab 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -2254,6 +2254,9 @@ static bool tpacpi_input_send_key(const u32 hkey)
{
unsigned int keycode, scancode;
+ if (tpacpi_driver_event(hkey))
+ return true;
+
if (hkey >= TP_HKEY_EV_ORIG_KEY_START &&
hkey <= TP_HKEY_EV_ORIG_KEY_END) {
scancode = hkey - TP_HKEY_EV_ORIG_KEY_START;
@@ -2295,7 +2298,6 @@ static struct tp_acpi_drv_struct ibm_hotkey_acpidriver;
/* Do NOT call without validating scancode first */
static void tpacpi_hotkey_send_key(unsigned int scancode)
{
- tpacpi_driver_event(TP_HKEY_EV_ORIG_KEY_START + scancode);
tpacpi_input_send_key(TP_HKEY_EV_ORIG_KEY_START + scancode);
}
@@ -3732,9 +3734,6 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
return true;
}
- if (tpacpi_driver_event(hkey))
- return true;
-
return tpacpi_input_send_key(hkey);
}
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 15/24] platform/x86: thinkpad_acpi: Do not send ACPI netlink events for unknown hotkeys
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (13 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 14/24] platform/x86: thinkpad_acpi: Move tpacpi_driver_event() call " Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-25 8:51 ` Ilpo Järvinen
2024-04-24 12:28 ` [PATCH v2 16/24] platform/x86: thinkpad_acpi: Change hotkey_reserved_mask initialization Hans de Goede
` (11 subsequent siblings)
26 siblings, 1 reply; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Do not send ACPI netlink events for unknown hotkeys, to avoid userspace
starting to rely on them. Instead these should be added to the keymap to
send evdev events.
This should not cause a behavior change for existing laptop models since
all currently known 0x1xxx events have a mapping.
In hindsight the ACPI netlink events should have been suppressed for
the adaptive keyboard and extended hotkeys events too. But the kernel has
been sending ACPI netlink events for those for a long time now, so we
cannot just stop sending them without potentially causing issues for
existing users who may depend on these.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 9b38770412ab..952bac635a18 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -2250,7 +2250,7 @@ static void tpacpi_input_send_tabletsw(void)
}
}
-static bool tpacpi_input_send_key(const u32 hkey)
+static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
{
unsigned int keycode, scancode;
@@ -2271,6 +2271,14 @@ static bool tpacpi_input_send_key(const u32 hkey)
scancode = hkey - TP_HKEY_EV_EXTENDED_KEY_START +
TP_ACPI_HOTKEYSCAN_EXTENDED_START;
} else {
+ /*
+ * Do not send ACPI netlink events for unknown hotkeys, to
+ * avoid userspace starting to rely on them. Instead these
+ * should be added to the keymap to send evdev events.
+ */
+ if (send_acpi_ev)
+ *send_acpi_ev = false;
+
return false;
}
@@ -2298,7 +2306,7 @@ static struct tp_acpi_drv_struct ibm_hotkey_acpidriver;
/* Do NOT call without validating scancode first */
static void tpacpi_hotkey_send_key(unsigned int scancode)
{
- tpacpi_input_send_key(TP_HKEY_EV_ORIG_KEY_START + scancode);
+ tpacpi_input_send_key(TP_HKEY_EV_ORIG_KEY_START + scancode, NULL);
}
static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
@@ -3734,7 +3742,7 @@ static bool hotkey_notify_hotkey(const u32 hkey, bool *send_acpi_ev)
return true;
}
- return tpacpi_input_send_key(hkey);
+ return tpacpi_input_send_key(hkey, send_acpi_ev);
}
/* 0x2000-0x2FFF: Wakeup reason */
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 16/24] platform/x86: thinkpad_acpi: Change hotkey_reserved_mask initialization
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (14 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 15/24] platform/x86: thinkpad_acpi: Do not send ACPI netlink events for unknown hotkeys Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 14:17 ` Mark Pearson
2024-04-25 9:14 ` Ilpo Järvinen
2024-04-24 12:28 ` [PATCH v2 17/24] platform/x86: thinkpad_acpi: Use correct keycodes for volume and brightness keys Hans de Goede
` (10 subsequent siblings)
26 siblings, 2 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Change the hotkey_reserved_mask initialization to hardcode the list
of reserved keys. There are only a few reserved keys and the code to
iterate over the keymap will be removed when moving to sparse-keymaps.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 952bac635a18..cf5c741d1343 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3545,6 +3545,19 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
"using keymap number %lu\n", keymap_id);
+ /* Keys which should be reserved on both IBM and Lenovo models */
+ hotkey_reserved_mask = TP_ACPI_HKEY_KBD_LIGHT_MASK |
+ TP_ACPI_HKEY_VOLUP_MASK |
+ TP_ACPI_HKEY_VOLDWN_MASK |
+ TP_ACPI_HKEY_MUTE_MASK;
+ /*
+ * Reserve brightness up/down unconditionally on IBM models, on Lenovo
+ * models these are disabled based on acpi_video_get_backlight_type().
+ */
+ if (keymap_id == TPACPI_KEYMAP_IBM_GENERIC)
+ hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
+ TP_ACPI_HKEY_BRGHTDWN_MASK;
+
hotkey_keycode_map = kmemdup(&tpacpi_keymaps[keymap_id],
TPACPI_HOTKEY_MAP_SIZE, GFP_KERNEL);
if (!hotkey_keycode_map) {
@@ -3560,9 +3573,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
if (hotkey_keycode_map[i] != KEY_RESERVED) {
input_set_capability(tpacpi_inputdev, EV_KEY,
hotkey_keycode_map[i]);
- } else {
- if (i < sizeof(hotkey_reserved_mask)*8)
- hotkey_reserved_mask |= 1 << i;
}
}
@@ -3587,9 +3597,8 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
/* Disable brightness up/down on Lenovo thinkpads when
* ACPI is handling them, otherwise it is plain impossible
* for userspace to do something even remotely sane */
- hotkey_reserved_mask |=
- (1 << TP_ACPI_HOTKEYSCAN_FNHOME)
- | (1 << TP_ACPI_HOTKEYSCAN_FNEND);
+ hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
+ TP_ACPI_HKEY_BRGHTDWN_MASK;
hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME);
hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND);
}
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 17/24] platform/x86: thinkpad_acpi: Use correct keycodes for volume and brightness keys
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (15 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 16/24] platform/x86: thinkpad_acpi: Change hotkey_reserved_mask initialization Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 18/24] platform/x86: thinkpad_acpi: Drop KEY_RESERVED special handling Hans de Goede
` (9 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Change the default keymap to report the correct keycodes for the volume and
brightness keys. Reporting key events for these is already filtered out by
the hotkey_reserved_mask which masks these keys out of hotkey_user_mask at
initialization time, so there is no need to also map them to KEY_RESERVED.
This avoids users, who want these to be reported, having to also remap
the keycodes on top of overriding hotkey_user_mask to report these
and Linux userspace has already been overriding the KEY_RESERVED mappings
with the correct keycodes through udev/hwdb/60-keyboard.hwdb for years now.
Also drop hotkey_unmap() it was only used to dynamically map the brightness
keys to KEY_RESERVED and after removing that it has no remaining users.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 45 +++++++++++++---------------
1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index cf5c741d1343..89931bb980be 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3097,15 +3097,6 @@ static void hotkey_exit(void)
mutex_unlock(&hotkey_mutex);
}
-static void __init hotkey_unmap(const unsigned int scancode)
-{
- if (hotkey_keycode_map[scancode] != KEY_RESERVED) {
- clear_bit(hotkey_keycode_map[scancode],
- tpacpi_inputdev->keybit);
- hotkey_keycode_map[scancode] = KEY_RESERVED;
- }
-}
-
/*
* HKEY quirks:
* TPACPI_HK_Q_INIMASK: Supports FN+F3,FN+F4,FN+F12
@@ -3224,22 +3215,28 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
KEY_UNKNOWN, /* 0x0D: FN+INSERT */
KEY_UNKNOWN, /* 0x0E: FN+DELETE */
- /* brightness: firmware always reacts to them */
- KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */
- KEY_RESERVED, /* 0x10: FN+END (brightness down) */
+ /* brightness: firmware always reacts to them.
+ * Suppressed by default through hotkey_reserved_mask.
+ */
+ KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */
+ KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */
- /* Thinklight: firmware always react to it */
- KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
+ /* Thinklight: firmware always react to it.
+ * Suppressed by default through hotkey_reserved_mask.
+ */
+ KEY_KBDILLUMTOGGLE, /* 0x11: FN+PGUP (thinklight toggle) */
KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
/* Volume: firmware always react to it and reprograms
* the built-in *extra* mixer. Never map it to control
- * another mixer by default. */
- KEY_RESERVED, /* 0x14: VOLUME UP */
- KEY_RESERVED, /* 0x15: VOLUME DOWN */
- KEY_RESERVED, /* 0x16: MUTE */
+ * another mixer by default.
+ * Suppressed by default through hotkey_reserved_mask.
+ */
+ KEY_VOLUMEUP, /* 0x14: VOLUME UP */
+ KEY_VOLUMEDOWN, /* 0x15: VOLUME DOWN */
+ KEY_MUTE, /* 0x16: MUTE */
KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
@@ -3282,7 +3279,8 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */
KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */
- KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
+ /* Suppressed by default through hotkey_reserved_mask. */
+ KEY_KBDILLUMTOGGLE, /* 0x11: FN+PGUP (thinklight toggle) */
KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
@@ -3297,10 +3295,11 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
* change unless you get test reports from all Lenovo
* models. May cause the BIOS to interfere with the
* HDA mixer.
+ * Suppressed by default through hotkey_reserved_mask.
*/
- KEY_RESERVED, /* 0x14: VOLUME UP */
- KEY_RESERVED, /* 0x15: VOLUME DOWN */
- KEY_RESERVED, /* 0x16: MUTE */
+ KEY_VOLUMEUP, /* 0x14: VOLUME UP */
+ KEY_VOLUMEDOWN, /* 0x15: VOLUME DOWN */
+ KEY_MUTE, /* 0x16: MUTE */
KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
@@ -3599,8 +3598,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
* for userspace to do something even remotely sane */
hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
TP_ACPI_HKEY_BRGHTDWN_MASK;
- hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME);
- hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND);
}
#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 18/24] platform/x86: thinkpad_acpi: Drop KEY_RESERVED special handling
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (16 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 17/24] platform/x86: thinkpad_acpi: Use correct keycodes for volume and brightness keys Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 19/24] platform/x86: thinkpad_acpi: Switch to using sparse-keymap helpers Hans de Goede
` (8 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
The input core already filters out EV_KEY events for KEY_RESERVED,
remove the check for this in tpacpi_input_send_key() and rely
on the input core filtering instead.
Also change tpacpi_input_send_key() to only report the scancode
once instead of reporting it on both press and release. Together
these 2 changes make tpacpi_input_send_key() behave the same as
sparse_keymap_report_event().
The goal of this patch is to have a separate commit with
the slightly different behavior from sparse_keymap_report_event()
before switching over to using the sparse-keymap helpers.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 89931bb980be..6a136d124cab 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -2283,19 +2283,17 @@ static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
}
keycode = hotkey_keycode_map[scancode];
- if (keycode != KEY_RESERVED) {
- mutex_lock(&tpacpi_inputdev_send_mutex);
- input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode);
- input_report_key(tpacpi_inputdev, keycode, 1);
- input_sync(tpacpi_inputdev);
+ mutex_lock(&tpacpi_inputdev_send_mutex);
- input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode);
- input_report_key(tpacpi_inputdev, keycode, 0);
- input_sync(tpacpi_inputdev);
+ input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode);
+ input_report_key(tpacpi_inputdev, keycode, 1);
+ input_sync(tpacpi_inputdev);
- mutex_unlock(&tpacpi_inputdev_send_mutex);
- }
+ input_report_key(tpacpi_inputdev, keycode, 0);
+ input_sync(tpacpi_inputdev);
+
+ mutex_unlock(&tpacpi_inputdev_send_mutex);
return true;
}
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 19/24] platform/x86: thinkpad_acpi: Switch to using sparse-keymap helpers
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (17 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 18/24] platform/x86: thinkpad_acpi: Drop KEY_RESERVED special handling Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-05-22 11:50 ` Vlastimil Babka
2024-04-24 12:28 ` [PATCH v2 20/24] platform/x86: thinkpad_acpi: Add mappings for adaptive kbd clipping-tool and cloud keys Hans de Goede
` (7 subsequent siblings)
26 siblings, 1 reply; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
Switch the hotkey keymap handling over to the sparse-keymap helpers,
there should be no functional changes from this.
Note all the mappings to KEY_UNKNOWN are removed since that is the default
behavior of sparse_keymap_report_event() for unknown scancodes.
Also drop the big comment about making changes to the keymaps since
the contents of that comment are mostly obsolete.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
- Use proper multi-line comment style
---
drivers/platform/x86/thinkpad_acpi.c | 404 ++++++++++-----------------
1 file changed, 145 insertions(+), 259 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 6a136d124cab..8af9406f2a13 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -45,6 +45,7 @@
#include <linux/hwmon-sysfs.h>
#include <linux/init.h>
#include <linux/input.h>
+#include <linux/input/sparse-keymap.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
@@ -1759,12 +1760,12 @@ enum { /* hot key scan codes (derived from ACPI DSDT) */
TP_ACPI_HOTKEYSCAN_THINKPAD,
TP_ACPI_HOTKEYSCAN_UNK1,
TP_ACPI_HOTKEYSCAN_UNK2,
- TP_ACPI_HOTKEYSCAN_UNK3,
+ TP_ACPI_HOTKEYSCAN_MICMUTE,
TP_ACPI_HOTKEYSCAN_UNK4,
- TP_ACPI_HOTKEYSCAN_UNK5,
- TP_ACPI_HOTKEYSCAN_UNK6,
- TP_ACPI_HOTKEYSCAN_UNK7,
- TP_ACPI_HOTKEYSCAN_UNK8,
+ TP_ACPI_HOTKEYSCAN_CONFIG,
+ TP_ACPI_HOTKEYSCAN_SEARCH,
+ TP_ACPI_HOTKEYSCAN_SCALE,
+ TP_ACPI_HOTKEYSCAN_FILE,
/* Adaptive keyboard keycodes */
TP_ACPI_HOTKEYSCAN_ADAPTIVE_START, /* 32 / 0x20 */
@@ -1779,7 +1780,7 @@ enum { /* hot key scan codes (derived from ACPI DSDT) */
TP_ACPI_HOTKEYSCAN_UNK11,
TP_ACPI_HOTKEYSCAN_UNK12,
TP_ACPI_HOTKEYSCAN_UNK13,
- TP_ACPI_HOTKEYSCAN_CONFIG,
+ TP_ACPI_HOTKEYSCAN_CONFIG2,
TP_ACPI_HOTKEYSCAN_NEW_TAB,
TP_ACPI_HOTKEYSCAN_RELOAD,
TP_ACPI_HOTKEYSCAN_BACK,
@@ -1801,9 +1802,6 @@ enum { /* hot key scan codes (derived from ACPI DSDT) */
TP_ACPI_HOTKEYSCAN_NOTIFICATION_CENTER,
TP_ACPI_HOTKEYSCAN_PICKUP_PHONE,
TP_ACPI_HOTKEYSCAN_HANGUP_PHONE,
-
- /* Hotkey keymap size */
- TPACPI_HOTKEY_MAP_LEN
};
enum { /* Keys/events available through NVRAM polling */
@@ -1916,8 +1914,6 @@ static u32 hotkey_driver_mask; /* events needed by the driver */
static u32 hotkey_user_mask; /* events visible to userspace */
static u32 hotkey_acpi_mask; /* events enabled in firmware */
-static u16 *hotkey_keycode_map;
-
static bool tpacpi_driver_event(const unsigned int hkey_event);
static void hotkey_poll_setup(const bool may_warn);
@@ -2252,11 +2248,24 @@ static void tpacpi_input_send_tabletsw(void)
static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
{
- unsigned int keycode, scancode;
+ bool known_ev;
+ u32 scancode;
if (tpacpi_driver_event(hkey))
return true;
+ /*
+ * Before the conversion to using the sparse-keymap helpers the driver used to
+ * map the hkey event codes to 0x00 - 0x4d scancodes so that a straight scancode
+ * indexed array could be used to map scancodes to keycodes:
+ *
+ * 0x1001 - 0x1020 -> 0x00 - 0x1f (Original ThinkPad events)
+ * 0x1103 - 0x1116 -> 0x20 - 0x33 (Adaptive keyboard, 2014 X1 Carbon)
+ * 0x1300 - 0x1319 -> 0x34 - 0x4d (Additional keys send in 2017+ models)
+ *
+ * The sparse-keymap tables still use these scancodes for these ranges to
+ * preserve userspace API compatibility (e.g. hwdb keymappings).
+ */
if (hkey >= TP_HKEY_EV_ORIG_KEY_START &&
hkey <= TP_HKEY_EV_ORIG_KEY_END) {
scancode = hkey - TP_HKEY_EV_ORIG_KEY_START;
@@ -2279,23 +2288,14 @@ static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
if (send_acpi_ev)
*send_acpi_ev = false;
- return false;
+ scancode = hkey;
}
- keycode = hotkey_keycode_map[scancode];
-
mutex_lock(&tpacpi_inputdev_send_mutex);
-
- input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode);
- input_report_key(tpacpi_inputdev, keycode, 1);
- input_sync(tpacpi_inputdev);
-
- input_report_key(tpacpi_inputdev, keycode, 0);
- input_sync(tpacpi_inputdev);
-
+ known_ev = sparse_keymap_report_event(tpacpi_inputdev, scancode, 1, true);
mutex_unlock(&tpacpi_inputdev_send_mutex);
- return true;
+ return known_ev;
}
#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
@@ -3124,9 +3124,6 @@ static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = {
TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */
};
-typedef u16 tpacpi_keymap_entry_t;
-typedef tpacpi_keymap_entry_t tpacpi_keymap_t[TPACPI_HOTKEY_MAP_LEN];
-
static int hotkey_init_tablet_mode(void)
{
int in_tablet_mode = 0, res;
@@ -3163,217 +3160,124 @@ static int hotkey_init_tablet_mode(void)
return in_tablet_mode;
}
+static const struct key_entry keymap_ibm[] __initconst = {
+ /* Original hotkey mappings translated scancodes 0x00 - 0x1f */
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF1, { KEY_FN_F1 } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF2, { KEY_BATTERY } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF3, { KEY_COFFEE } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF4, { KEY_SLEEP } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF5, { KEY_WLAN } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF6, { KEY_FN_F6 } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF7, { KEY_SWITCHVIDEOMODE } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF8, { KEY_FN_F8 } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF9, { KEY_FN_F9 } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF10, { KEY_FN_F10 } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF11, { KEY_FN_F11 } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF12, { KEY_SUSPEND } },
+ /* Brightness: firmware always reacts, suppressed through hotkey_reserved_mask. */
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNHOME, { KEY_BRIGHTNESSUP } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNEND, { KEY_BRIGHTNESSDOWN } },
+ /* Thinklight: firmware always reacts, suppressed through hotkey_reserved_mask. */
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNPAGEUP, { KEY_KBDILLUMTOGGLE } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNSPACE, { KEY_ZOOM } },
+ /*
+ * Volume: firmware always reacts and reprograms the built-in *extra* mixer.
+ * Suppressed by default through hotkey_reserved_mask.
+ */
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_VOLUMEUP, { KEY_VOLUMEUP } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, { KEY_VOLUMEDOWN } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_MUTE, { KEY_MUTE } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_THINKPAD, { KEY_VENDOR } },
+ { KE_END }
+};
+
+static const struct key_entry keymap_lenovo[] __initconst = {
+ /* Original hotkey mappings translated scancodes 0x00 - 0x1f */
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF1, { KEY_FN_F1 } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF2, { KEY_COFFEE } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF3, { KEY_BATTERY } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF4, { KEY_SLEEP } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF5, { KEY_WLAN } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF6, { KEY_CAMERA, } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF7, { KEY_SWITCHVIDEOMODE } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF8, { KEY_FN_F8 } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF9, { KEY_FN_F9 } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF10, { KEY_FN_F10 } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF11, { KEY_FN_F11 } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF12, { KEY_SUSPEND } },
+ /*
+ * These should be enabled --only-- when ACPI video is disabled and
+ * are handled in a special way by the init code.
+ */
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNHOME, { KEY_BRIGHTNESSUP } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNEND, { KEY_BRIGHTNESSDOWN } },
+ /* Suppressed by default through hotkey_reserved_mask. */
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNPAGEUP, { KEY_KBDILLUMTOGGLE } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FNSPACE, { KEY_ZOOM } },
+ /*
+ * Volume: z60/z61, T60 (BIOS version?): firmware always reacts and
+ * reprograms the built-in *extra* mixer.
+ * T60?, T61, R60?, R61: firmware and EC tries to send these over
+ * the regular keyboard (not through tpacpi). There are still weird bugs
+ * re. MUTE. May cause the BIOS to interfere with the HDA mixer.
+ * Suppressed by default through hotkey_reserved_mask.
+ */
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_VOLUMEUP, { KEY_VOLUMEUP } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, { KEY_VOLUMEDOWN } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_MUTE, { KEY_MUTE } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_THINKPAD, { KEY_VENDOR } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_MICMUTE, { KEY_MICMUTE } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_CONFIG, { KEY_CONFIG } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_SEARCH, { KEY_SEARCH } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_SCALE, { KEY_SCALE } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FILE, { KEY_FILE } },
+ /* Adaptive keyboard mappings for Carbon X1 2014 translated scancodes 0x20 - 0x33 */
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_MUTE2, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_BRIGHTNESS_ZERO, { KEY_BRIGHTNESS_MIN } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_CLOUD, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_UNK9, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_VOICE, { KEY_VOICECOMMAND } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_UNK10, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_GESTURES, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_UNK11, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_UNK12, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_UNK13, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_CONFIG2, { KEY_CONFIG } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_NEW_TAB, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_RELOAD, { KEY_REFRESH } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_BACK, { KEY_BACK } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_MIC_DOWN, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_MIC_UP, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_MIC_CANCELLATION, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_CAMERA_MODE, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_ROTATE_DISPLAY, { KEY_RESERVED } },
+ /* Extended hotkeys mappings translated scancodes 0x34 - 0x4d */
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_STAR, { KEY_BOOKMARKS } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL2, { KEY_SELECTIVE_SCREENSHOT } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_CALCULATOR, { KEY_CALC } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_BLUETOOTH, { KEY_BLUETOOTH } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_KEYBOARD, { KEY_KEYBOARD } },
+ /* Used by "Lenovo Quick Clean" */
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_FN_RIGHT_SHIFT, { KEY_FN_RIGHT_SHIFT } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_NOTIFICATION_CENTER, { KEY_NOTIFICATION_CENTER } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_PICKUP_PHONE, { KEY_PICKUP_PHONE } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_HANGUP_PHONE, { KEY_HANGUP_PHONE } },
+ /*
+ * All mapping below are for raw untranslated hkey event codes mapped directly
+ * after switching to sparse keymap support. The mappings above use translated
+ * scancodes to preserve uAPI compatibility, see tpacpi_input_send_key().
+ */
+ { KE_END }
+};
+
static int __init hotkey_init(struct ibm_init_struct *iibm)
{
- /* Requirements for changing the default keymaps:
- *
- * 1. Many of the keys are mapped to KEY_RESERVED for very
- * good reasons. Do not change them unless you have deep
- * knowledge on the IBM and Lenovo ThinkPad firmware for
- * the various ThinkPad models. The driver behaves
- * differently for KEY_RESERVED: such keys have their
- * hot key mask *unset* in mask_recommended, and also
- * in the initial hot key mask programmed into the
- * firmware at driver load time, which means the firm-
- * ware may react very differently if you change them to
- * something else;
- *
- * 2. You must be subscribed to the linux-thinkpad and
- * ibm-acpi-devel mailing lists, and you should read the
- * list archives since 2007 if you want to change the
- * keymaps. This requirement exists so that you will
- * know the past history of problems with the thinkpad-
- * acpi driver keymaps, and also that you will be
- * listening to any bug reports;
- *
- * 3. Do not send thinkpad-acpi specific patches directly to
- * for merging, *ever*. Send them to the linux-acpi
- * mailinglist for comments. Merging is to be done only
- * through acpi-test and the ACPI maintainer.
- *
- * If the above is too much to ask, don't change the keymap.
- * Ask the thinkpad-acpi maintainer to do it, instead.
- */
-
enum keymap_index {
TPACPI_KEYMAP_IBM_GENERIC = 0,
TPACPI_KEYMAP_LENOVO_GENERIC,
};
- static const tpacpi_keymap_t tpacpi_keymaps[] __initconst = {
- /* Generic keymap for IBM ThinkPads */
- [TPACPI_KEYMAP_IBM_GENERIC] = {
- /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
- KEY_FN_F1, KEY_BATTERY, KEY_COFFEE, KEY_SLEEP,
- KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
- KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
-
- /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
- KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
- KEY_UNKNOWN, /* 0x0D: FN+INSERT */
- KEY_UNKNOWN, /* 0x0E: FN+DELETE */
-
- /* brightness: firmware always reacts to them.
- * Suppressed by default through hotkey_reserved_mask.
- */
- KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */
- KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */
-
- /* Thinklight: firmware always react to it.
- * Suppressed by default through hotkey_reserved_mask.
- */
- KEY_KBDILLUMTOGGLE, /* 0x11: FN+PGUP (thinklight toggle) */
-
- KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
- KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
-
- /* Volume: firmware always react to it and reprograms
- * the built-in *extra* mixer. Never map it to control
- * another mixer by default.
- * Suppressed by default through hotkey_reserved_mask.
- */
- KEY_VOLUMEUP, /* 0x14: VOLUME UP */
- KEY_VOLUMEDOWN, /* 0x15: VOLUME DOWN */
- KEY_MUTE, /* 0x16: MUTE */
-
- KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
-
- /* (assignments unknown, please report if found) */
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
-
- /* No assignments, only used for Adaptive keyboards. */
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
-
- /* No assignment, used for newer Lenovo models */
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN
-
- },
-
- /* Generic keymap for Lenovo ThinkPads */
- [TPACPI_KEYMAP_LENOVO_GENERIC] = {
- /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
- KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP,
- KEY_WLAN, KEY_CAMERA, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
- KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
-
- /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
- KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
- KEY_UNKNOWN, /* 0x0D: FN+INSERT */
- KEY_UNKNOWN, /* 0x0E: FN+DELETE */
-
- /* These should be enabled --only-- when ACPI video
- * is disabled (i.e. in "vendor" mode), and are handled
- * in a special way by the init code */
- KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */
- KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */
-
- /* Suppressed by default through hotkey_reserved_mask. */
- KEY_KBDILLUMTOGGLE, /* 0x11: FN+PGUP (thinklight toggle) */
-
- KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
- KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
-
- /* Volume: z60/z61, T60 (BIOS version?): firmware always
- * react to it and reprograms the built-in *extra* mixer.
- * Never map it to control another mixer by default.
- *
- * T60?, T61, R60?, R61: firmware and EC tries to send
- * these over the regular keyboard, so these are no-ops,
- * but there are still weird bugs re. MUTE, so do not
- * change unless you get test reports from all Lenovo
- * models. May cause the BIOS to interfere with the
- * HDA mixer.
- * Suppressed by default through hotkey_reserved_mask.
- */
- KEY_VOLUMEUP, /* 0x14: VOLUME UP */
- KEY_VOLUMEDOWN, /* 0x15: VOLUME DOWN */
- KEY_MUTE, /* 0x16: MUTE */
-
- KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
-
- /* (assignments unknown, please report if found) */
- KEY_UNKNOWN, KEY_UNKNOWN,
-
- /*
- * The mic mute button only sends 0x1a. It does not
- * automatically mute the mic or change the mute light.
- */
- KEY_MICMUTE, /* 0x1a: Mic mute (since ?400 or so) */
-
- /* (assignments unknown, please report if found) */
- KEY_UNKNOWN,
-
- /* Extra keys in use since the X240 / T440 / T540 */
- KEY_CONFIG, KEY_SEARCH, KEY_SCALE, KEY_FILE,
-
- /*
- * These are the adaptive keyboard keycodes for Carbon X1 2014.
- * The first item in this list is the Mute button which is
- * emitted with 0x103 through
- * adaptive_keyboard_hotkey_notify_hotkey() when the sound
- * symbol is held.
- * We'll need to offset those by 0x20.
- */
- KEY_RESERVED, /* Mute held, 0x103 */
- KEY_BRIGHTNESS_MIN, /* Backlight off */
- KEY_RESERVED, /* Clipping tool */
- KEY_RESERVED, /* Cloud */
- KEY_RESERVED,
- KEY_VOICECOMMAND, /* Voice */
- KEY_RESERVED,
- KEY_RESERVED, /* Gestures */
- KEY_RESERVED,
- KEY_RESERVED,
- KEY_RESERVED,
- KEY_CONFIG, /* Settings */
- KEY_RESERVED, /* New tab */
- KEY_REFRESH, /* Reload */
- KEY_BACK, /* Back */
- KEY_RESERVED, /* Microphone down */
- KEY_RESERVED, /* Microphone up */
- KEY_RESERVED, /* Microphone cancellation */
- KEY_RESERVED, /* Camera mode */
- KEY_RESERVED, /* Rotate display, 0x116 */
-
- /*
- * These are found in 2017 models (e.g. T470s, X270).
- * The lowest known value is 0x311, which according to
- * the manual should launch a user defined favorite
- * application.
- *
- * The offset for these is TP_ACPI_HOTKEYSCAN_EXTENDED_START,
- * corresponding to 0x34.
- */
-
- /* (assignments unknown, please report if found) */
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
- KEY_UNKNOWN,
-
- KEY_BOOKMARKS, /* Favorite app, 0x311 */
- KEY_SELECTIVE_SCREENSHOT, /* Clipping tool */
- KEY_CALC, /* Calculator (above numpad, P52) */
- KEY_BLUETOOTH, /* Bluetooth */
- KEY_KEYBOARD, /* Keyboard, 0x315 */
- KEY_FN_RIGHT_SHIFT, /* Fn + right Shift */
- KEY_NOTIFICATION_CENTER, /* Notification Center */
- KEY_PICKUP_PHONE, /* Answer incoming call */
- KEY_HANGUP_PHONE, /* Decline incoming call */
- },
- };
-
static const struct tpacpi_quirk tpacpi_keymap_qtable[] __initconst = {
/* Generic maps (fallback) */
{
@@ -3388,17 +3292,11 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
},
};
-#define TPACPI_HOTKEY_MAP_SIZE sizeof(tpacpi_keymap_t)
-#define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(tpacpi_keymap_entry_t)
-
- int res, i;
- int status;
- int hkeyv;
+ unsigned long keymap_id, quirks;
+ const struct key_entry *keymap;
bool radiosw_state = false;
bool tabletsw_state = false;
-
- unsigned long quirks;
- unsigned long keymap_id;
+ int hkeyv, res, status;
vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
"initializing hotkey subdriver\n");
@@ -3538,7 +3436,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
/* Set up key map */
keymap_id = tpacpi_check_quirks(tpacpi_keymap_qtable,
ARRAY_SIZE(tpacpi_keymap_qtable));
- BUG_ON(keymap_id >= ARRAY_SIZE(tpacpi_keymaps));
dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
"using keymap number %lu\n", keymap_id);
@@ -3551,27 +3448,17 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
* Reserve brightness up/down unconditionally on IBM models, on Lenovo
* models these are disabled based on acpi_video_get_backlight_type().
*/
- if (keymap_id == TPACPI_KEYMAP_IBM_GENERIC)
+ if (keymap_id == TPACPI_KEYMAP_IBM_GENERIC) {
hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
TP_ACPI_HKEY_BRGHTDWN_MASK;
-
- hotkey_keycode_map = kmemdup(&tpacpi_keymaps[keymap_id],
- TPACPI_HOTKEY_MAP_SIZE, GFP_KERNEL);
- if (!hotkey_keycode_map) {
- pr_err("failed to allocate memory for key map\n");
- return -ENOMEM;
+ keymap = keymap_ibm;
+ } else {
+ keymap = keymap_lenovo;
}
- input_set_capability(tpacpi_inputdev, EV_MSC, MSC_SCAN);
- tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE;
- tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN;
- tpacpi_inputdev->keycode = hotkey_keycode_map;
- for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) {
- if (hotkey_keycode_map[i] != KEY_RESERVED) {
- input_set_capability(tpacpi_inputdev, EV_KEY,
- hotkey_keycode_map[i]);
- }
- }
+ res = sparse_keymap_setup(tpacpi_inputdev, keymap, NULL);
+ if (res)
+ return res;
if (tp_features.hotkey_wlsw) {
input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL);
@@ -11739,7 +11626,6 @@ static void thinkpad_acpi_module_exit(void)
input_unregister_device(tpacpi_inputdev);
else
input_free_device(tpacpi_inputdev);
- kfree(hotkey_keycode_map);
}
if (tpacpi_sensors_pdev)
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 20/24] platform/x86: thinkpad_acpi: Add mappings for adaptive kbd clipping-tool and cloud keys
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (18 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 19/24] platform/x86: thinkpad_acpi: Switch to using sparse-keymap helpers Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 21/24] platform/x86: thinkpad_acpi: Simplify known_ev handling Hans de Goede
` (6 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
The X1 carbon 2014 / 2nd gen's adaptive keyboard top row's "Home" mode,
which is 1 of the 2 modes Linux supports, has clipping-tool and cloud
buttons which so far are not mapped.
I assume these were left as KEY_RESERVED because no suitable KEY_FOO codes
were available when support was added.
In the mean time we have gotten KEY_SELECTIVE_SCREENSHOT and this has been
used for the clipping-tool function under Fn + PrtSc on more traditional
ThinkPad keyboards already.
Finding a KEY_FOO code for the cloud key is harder looking at the symbol
it seems to refer to cloud-storage which made me think of file syncing,
or file transfer which has let me to pick KEY_XFER for this.
Note this is based on looking at a picture of the adaptive top row
in Home mode and has not been tested on an actual adaptive keyboard.
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 8af9406f2a13..469ff6a39d18 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3234,8 +3234,8 @@ static const struct key_entry keymap_lenovo[] __initconst = {
/* Adaptive keyboard mappings for Carbon X1 2014 translated scancodes 0x20 - 0x33 */
{ KE_KEY, TP_ACPI_HOTKEYSCAN_MUTE2, { KEY_RESERVED } },
{ KE_KEY, TP_ACPI_HOTKEYSCAN_BRIGHTNESS_ZERO, { KEY_BRIGHTNESS_MIN } },
- { KE_KEY, TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL, { KEY_RESERVED } },
- { KE_KEY, TP_ACPI_HOTKEYSCAN_CLOUD, { KEY_RESERVED } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL, { KEY_SELECTIVE_SCREENSHOT } },
+ { KE_KEY, TP_ACPI_HOTKEYSCAN_CLOUD, { KEY_XFER } },
{ KE_KEY, TP_ACPI_HOTKEYSCAN_UNK9, { KEY_RESERVED } },
{ KE_KEY, TP_ACPI_HOTKEYSCAN_VOICE, { KEY_VOICECOMMAND } },
{ KE_KEY, TP_ACPI_HOTKEYSCAN_UNK10, { KEY_RESERVED } },
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 21/24] platform/x86: thinkpad_acpi: Simplify known_ev handling
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (19 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 20/24] platform/x86: thinkpad_acpi: Add mappings for adaptive kbd clipping-tool and cloud keys Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 22/24] platform/x86: thinkpad_acpi: Support for trackpoint doubletap Hans de Goede
` (5 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
From: Mark Pearson <mpearson-lenovo@squebb.ca>
Modify how known_ev event is handled in preparation for adding new hkey
event range.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Link: https://lore.kernel.org/r/20240417173124.9953-1-mpearson-lenovo@squebb.ca
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 469ff6a39d18..a53b00fecf1a 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3845,6 +3845,7 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
}
send_acpi_ev = true;
+ known_ev = false;
switch (hkey >> 12) {
case 1:
@@ -3868,8 +3869,6 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
/* FIXME: kick libata if SATA link offline */
known_ev = true;
break;
- default:
- known_ev = false;
}
break;
case 4:
@@ -3892,11 +3891,8 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
tpacpi_send_radiosw_update();
send_acpi_ev = 0;
known_ev = true;
- break;
}
- fallthrough; /* to default */
- default:
- known_ev = false;
+ break;
}
if (!known_ev) {
pr_notice("unhandled HKEY event 0x%04x\n", hkey);
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 22/24] platform/x86: thinkpad_acpi: Support for trackpoint doubletap
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (20 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 21/24] platform/x86: thinkpad_acpi: Simplify known_ev handling Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 18:19 ` Mark Pearson
2024-04-24 12:28 ` [PATCH v2 23/24] platform/x86: thinkpad_acpi: Support for system debug info hotkey Hans de Goede
` (4 subsequent siblings)
26 siblings, 1 reply; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
From: Mark Pearson <mpearson-lenovo@squebb.ca>
Lenovo trackpoints are adding the ability to generate a doubletap event.
This handles the doubletap event and sends the KEY_PROG4 event to
userspace. Despite the driver itself not using KEY_PROG1 - KEY_PROG3 this
still uses KEY_PROG4 because of some keys being remapped to KEY_PROG1 -
KEY_PROG3 by default by the upstream udev hwdb containing:
evdev:name:ThinkPad Extra Buttons:dmi:bvn*:bvr*:bd*:svnLENOVO*:pn*:*
...
KEYBOARD_KEY_17=prog1
KEYBOARD_KEY_1a=f20 # Microphone mute button
KEYBOARD_KEY_45=bookmarks
KEYBOARD_KEY_46=prog2 # Fn + PrtSc, on Windows: Snipping tool
KEYBOARD_KEY_4a=prog3 # Fn + Right shift, on Windows: No idea
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Vishnu Sankar <vishnuocv@gmail.com>
Link: https://lore.kernel.org/r/20240417173124.9953-2-mpearson-lenovo@squebb.ca
[hdegoede@redhat.com: Adjust for switch to sparse-keymap keymaps]
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index a53b00fecf1a..b6d6466215e1 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -248,6 +248,9 @@ enum tpacpi_hkey_event_t {
/* Misc */
TP_HKEY_EV_RFKILL_CHANGED = 0x7000, /* rfkill switch changed */
+
+ /* Misc2 */
+ TP_HKEY_EV_TRACK_DOUBLETAP = 0x8036, /* trackpoint doubletap */
};
/****************************************************************************
@@ -3268,6 +3271,7 @@ static const struct key_entry keymap_lenovo[] __initconst = {
* after switching to sparse keymap support. The mappings above use translated
* scancodes to preserve uAPI compatibility, see tpacpi_input_send_key().
*/
+ { KE_KEY, TP_HKEY_EV_TRACK_DOUBLETAP /* 0x8036 */, { KEY_PROG4 } },
{ KE_END }
};
@@ -3817,6 +3821,17 @@ static bool hotkey_notify_6xxx(const u32 hkey, bool *send_acpi_ev)
return true;
}
+static bool hotkey_notify_8xxx(const u32 hkey, bool *send_acpi_ev)
+{
+ switch (hkey) {
+ case TP_HKEY_EV_TRACK_DOUBLETAP:
+ tpacpi_input_send_key(hkey, send_acpi_ev);
+ return true;
+ default:
+ return false;
+ }
+}
+
static void hotkey_notify(struct ibm_struct *ibm, u32 event)
{
u32 hkey;
@@ -3893,6 +3908,10 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
known_ev = true;
}
break;
+ case 8:
+ /* 0x8000-0x8FFF: misc2 */
+ known_ev = hotkey_notify_8xxx(hkey, &send_acpi_ev);
+ break;
}
if (!known_ev) {
pr_notice("unhandled HKEY event 0x%04x\n", hkey);
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 23/24] platform/x86: thinkpad_acpi: Support for system debug info hotkey
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (21 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 22/24] platform/x86: thinkpad_acpi: Support for trackpoint doubletap Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 24/24] platform/x86: thinkpad_acpi: Support hotkey to disable trackpoint doubletap Hans de Goede
` (3 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
From: Mark Pearson <mpearson-lenovo@squebb.ca>
New Lenovo platforms are adding the FN+N key to generate system debug
details that support can use for collecting important details on any
customer cases for Windows.
Add the infrastructure so we can do the same on Linux by sending
a KEY_VENDOR keycode to userspace.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Nitin Joshi <njoshi1@lenovo.com>
Link: https://lore.kernel.org/r/20240417173124.9953-3-mpearson-lenovo@squebb.ca
[hdegoede@redhat.com: Adjust for switch to sparse-keymap keymaps]
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index b6d6466215e1..7a27cbca6980 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3271,6 +3271,7 @@ static const struct key_entry keymap_lenovo[] __initconst = {
* after switching to sparse keymap support. The mappings above use translated
* scancodes to preserve uAPI compatibility, see tpacpi_input_send_key().
*/
+ { KE_KEY, 0x131d, { KEY_VENDOR } }, /* System debug info, similar to old ThinkPad key */
{ KE_KEY, TP_HKEY_EV_TRACK_DOUBLETAP /* 0x8036 */, { KEY_PROG4 } },
{ KE_END }
};
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 24/24] platform/x86: thinkpad_acpi: Support hotkey to disable trackpoint doubletap
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (22 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 23/24] platform/x86: thinkpad_acpi: Support for system debug info hotkey Hans de Goede
@ 2024-04-24 12:28 ` Hans de Goede
2024-04-24 18:28 ` [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Mark Pearson
` (2 subsequent siblings)
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 12:28 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Hans de Goede, Vishnu Sankar, Nitin Joshi, ibm-acpi-devel,
platform-driver-x86
From: Mark Pearson <mpearson-lenovo@squebb.ca>
The hotkey combination Fn + G can be used to disable the trackpoint
doubletap feature on Windows. Add matching functionality for Linux.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Vishnu Sankar <vishnuocv@gmail.com>
Link: https://lore.kernel.org/r/20240417173124.9953-4-mpearson-lenovo@squebb.ca
[hdegoede@redhat.com: Adjust for switch to sparse-keymap keymaps]
[hdegoede@redhat.com: Do not log unknown event msg for doubletap when disabled]
Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/platform/x86/thinkpad_acpi.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 7a27cbca6980..7e2288009063 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -183,6 +183,7 @@ enum tpacpi_hkey_event_t {
* directly in the sparse-keymap.
*/
TP_HKEY_EV_AMT_TOGGLE = 0x131a, /* Toggle AMT on/off */
+ TP_HKEY_EV_DOUBLETAP_TOGGLE = 0x131c, /* Toggle trackpoint doubletap on/off */
TP_HKEY_EV_PROFILE_TOGGLE = 0x131f, /* Toggle platform profile */
/* Reasons for waking up from S3/S4 */
@@ -372,6 +373,7 @@ static struct {
u32 hotkey_poll_active:1;
u32 has_adaptive_kbd:1;
u32 kbd_lang:1;
+ u32 trackpoint_doubletap:1;
struct quirk_entry *quirks;
} tp_features;
@@ -3527,6 +3529,9 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
hotkey_poll_setup_safe(true);
+ /* Enable doubletap by default */
+ tp_features.trackpoint_doubletap = 1;
+
return 0;
}
@@ -3826,7 +3831,9 @@ static bool hotkey_notify_8xxx(const u32 hkey, bool *send_acpi_ev)
{
switch (hkey) {
case TP_HKEY_EV_TRACK_DOUBLETAP:
- tpacpi_input_send_key(hkey, send_acpi_ev);
+ if (tp_features.trackpoint_doubletap)
+ tpacpi_input_send_key(hkey, send_acpi_ev);
+
return true;
default:
return false;
@@ -11033,6 +11040,9 @@ static bool tpacpi_driver_event(const unsigned int hkey_event)
else
dytc_control_amt(!dytc_amt_active);
+ return true;
+ case TP_HKEY_EV_DOUBLETAP_TOGGLE:
+ tp_features.trackpoint_doubletap = !tp_features.trackpoint_doubletap;
return true;
case TP_HKEY_EV_PROFILE_TOGGLE:
platform_profile_cycle();
--
2.44.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* Re: [PATCH v2 16/24] platform/x86: thinkpad_acpi: Change hotkey_reserved_mask initialization
2024-04-24 12:28 ` [PATCH v2 16/24] platform/x86: thinkpad_acpi: Change hotkey_reserved_mask initialization Hans de Goede
@ 2024-04-24 14:17 ` Mark Pearson
2024-04-24 14:47 ` Hans de Goede
2024-04-25 9:14 ` Ilpo Järvinen
1 sibling, 1 reply; 42+ messages in thread
From: Mark Pearson @ 2024-04-24 14:17 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen, Andy Shevchenko,
Henrique de Moraes Holschuh
Cc: Vishnu Sankar, Nitin Joshi1, ibm-acpi-devel,
platform-driver-x86@vger.kernel.org
Hi Hans,
On Wed, Apr 24, 2024, at 8:28 AM, Hans de Goede wrote:
> Change the hotkey_reserved_mask initialization to hardcode the list
> of reserved keys. There are only a few reserved keys and the code to
> iterate over the keymap will be removed when moving to sparse-keymaps.
>
> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> drivers/platform/x86/thinkpad_acpi.c | 21 +++++++++++++++------
> 1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/platform/x86/thinkpad_acpi.c
> b/drivers/platform/x86/thinkpad_acpi.c
> index 952bac635a18..cf5c741d1343 100644
> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c
> @@ -3545,6 +3545,19 @@ static int __init hotkey_init(struct
> ibm_init_struct *iibm)
> dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
> "using keymap number %lu\n", keymap_id);
>
> + /* Keys which should be reserved on both IBM and Lenovo models */
> + hotkey_reserved_mask = TP_ACPI_HKEY_KBD_LIGHT_MASK |
> + TP_ACPI_HKEY_VOLUP_MASK |
> + TP_ACPI_HKEY_VOLDWN_MASK |
> + TP_ACPI_HKEY_MUTE_MASK;
> + /*
> + * Reserve brightness up/down unconditionally on IBM models, on Lenovo
> + * models these are disabled based on acpi_video_get_backlight_type().
> + */
> + if (keymap_id == TPACPI_KEYMAP_IBM_GENERIC)
> + hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
> + TP_ACPI_HKEY_BRGHTDWN_MASK;
> +
> hotkey_keycode_map = kmemdup(&tpacpi_keymaps[keymap_id],
> TPACPI_HOTKEY_MAP_SIZE, GFP_KERNEL);
> if (!hotkey_keycode_map) {
> @@ -3560,9 +3573,6 @@ static int __init hotkey_init(struct
> ibm_init_struct *iibm)
> if (hotkey_keycode_map[i] != KEY_RESERVED) {
> input_set_capability(tpacpi_inputdev, EV_KEY,
> hotkey_keycode_map[i]);
> - } else {
> - if (i < sizeof(hotkey_reserved_mask)*8)
> - hotkey_reserved_mask |= 1 << i;
Just to check my understanding here - does this change mean that the keys marked as KEY_RESERVED in the lenovo map won't make it into the mask?
e.g the ones in this block:
KEY_RESERVED, /* Mute held, 0x103 */
KEY_BRIGHTNESS_MIN, /* Backlight off */
KEY_RESERVED, /* Clipping tool */
KEY_RESERVED, /* Cloud */
KEY_RESERVED,
KEY_VOICECOMMAND, /* Voice */
KEY_RESERVED,
KEY_RESERVED, /* Gestures */
KEY_RESERVED,
KEY_RESERVED,
KEY_RESERVED,
KEY_CONFIG, /* Settings */
KEY_RESERVED, /* New tab */
KEY_REFRESH, /* Reload */
KEY_BACK, /* Back */
KEY_RESERVED, /* Microphone down */
KEY_RESERVED, /* Microphone up */
KEY_RESERVED, /* Microphone cancellation */
KEY_RESERVED, /* Camera mode */
KEY_RESERVED, /* Rotate display, 0x116 */
I'm not sure what the effect will be and I don't have the 2014 X1 Carbon (I assume it's the G1) available to test with unfortunately.
Just wanted to be sure we weren't breaking something on older platforms.
> }
> }
>
> @@ -3587,9 +3597,8 @@ static int __init hotkey_init(struct
> ibm_init_struct *iibm)
> /* Disable brightness up/down on Lenovo thinkpads when
> * ACPI is handling them, otherwise it is plain impossible
> * for userspace to do something even remotely sane */
> - hotkey_reserved_mask |=
> - (1 << TP_ACPI_HOTKEYSCAN_FNHOME)
> - | (1 << TP_ACPI_HOTKEYSCAN_FNEND);
> + hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
> + TP_ACPI_HKEY_BRGHTDWN_MASK;
> hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME);
> hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND);
> }
> --
> 2.44.0
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 16/24] platform/x86: thinkpad_acpi: Change hotkey_reserved_mask initialization
2024-04-24 14:17 ` Mark Pearson
@ 2024-04-24 14:47 ` Hans de Goede
2024-04-24 15:11 ` Mark Pearson
0 siblings, 1 reply; 42+ messages in thread
From: Hans de Goede @ 2024-04-24 14:47 UTC (permalink / raw)
To: Mark Pearson, Ilpo Järvinen, Andy Shevchenko,
Henrique de Moraes Holschuh
Cc: Vishnu Sankar, Nitin Joshi1, ibm-acpi-devel,
platform-driver-x86@vger.kernel.org
Hi Mark,
On 4/24/24 4:17 PM, Mark Pearson wrote:
> Hi Hans,
>
> On Wed, Apr 24, 2024, at 8:28 AM, Hans de Goede wrote:
>> Change the hotkey_reserved_mask initialization to hardcode the list
>> of reserved keys. There are only a few reserved keys and the code to
>> iterate over the keymap will be removed when moving to sparse-keymaps.
>>
>> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> drivers/platform/x86/thinkpad_acpi.c | 21 +++++++++++++++------
>> 1 file changed, 15 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/platform/x86/thinkpad_acpi.c
>> b/drivers/platform/x86/thinkpad_acpi.c
>> index 952bac635a18..cf5c741d1343 100644
>> --- a/drivers/platform/x86/thinkpad_acpi.c
>> +++ b/drivers/platform/x86/thinkpad_acpi.c
>> @@ -3545,6 +3545,19 @@ static int __init hotkey_init(struct
>> ibm_init_struct *iibm)
>> dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
>> "using keymap number %lu\n", keymap_id);
>>
>> + /* Keys which should be reserved on both IBM and Lenovo models */
>> + hotkey_reserved_mask = TP_ACPI_HKEY_KBD_LIGHT_MASK |
>> + TP_ACPI_HKEY_VOLUP_MASK |
>> + TP_ACPI_HKEY_VOLDWN_MASK |
>> + TP_ACPI_HKEY_MUTE_MASK;
>> + /*
>> + * Reserve brightness up/down unconditionally on IBM models, on Lenovo
>> + * models these are disabled based on acpi_video_get_backlight_type().
>> + */
>> + if (keymap_id == TPACPI_KEYMAP_IBM_GENERIC)
>> + hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
>> + TP_ACPI_HKEY_BRGHTDWN_MASK;
>> +
>> hotkey_keycode_map = kmemdup(&tpacpi_keymaps[keymap_id],
>> TPACPI_HOTKEY_MAP_SIZE, GFP_KERNEL);
>> if (!hotkey_keycode_map) {
>> @@ -3560,9 +3573,6 @@ static int __init hotkey_init(struct
>> ibm_init_struct *iibm)
>> if (hotkey_keycode_map[i] != KEY_RESERVED) {
>> input_set_capability(tpacpi_inputdev, EV_KEY,
>> hotkey_keycode_map[i]);
>> - } else {
>> - if (i < sizeof(hotkey_reserved_mask)*8)
>> - hotkey_reserved_mask |= 1 << i;
>
> Just to check my understanding here - does this change mean that the keys marked as KEY_RESERVED in the lenovo map won't make it into the mask?
>
> e.g the ones in this block:
> KEY_RESERVED, /* Mute held, 0x103 */
> KEY_BRIGHTNESS_MIN, /* Backlight off */
> KEY_RESERVED, /* Clipping tool */
> KEY_RESERVED, /* Cloud */
> KEY_RESERVED,
> KEY_VOICECOMMAND, /* Voice */
> KEY_RESERVED,
> KEY_RESERVED, /* Gestures */
> KEY_RESERVED,
> KEY_RESERVED,
> KEY_RESERVED,
> KEY_CONFIG, /* Settings */
> KEY_RESERVED, /* New tab */
> KEY_REFRESH, /* Reload */
> KEY_BACK, /* Back */
> KEY_RESERVED, /* Microphone down */
> KEY_RESERVED, /* Microphone up */
> KEY_RESERVED, /* Microphone cancellation */
> KEY_RESERVED, /* Camera mode */
> KEY_RESERVED, /* Rotate display, 0x116 */
>
> I'm not sure what the effect will be and I don't have the 2014 X1 Carbon (I assume it's the G1) available to test with unfortunately.
Only the 32 original hotkeys are affected by any of the hotkey_*_mask
values, note:
if (i < sizeof(hotkey_reserved_mask)*8)
hotkey_reserved_mask |= 1 << i;
The (i < sizeof(hotkey_reserved_mask)*8) condition translates to
(i < 32) so this code only ever set bits in hotkey_reserved_mask
for the 32 original hotkeys.
> Just wanted to be sure we weren't breaking something on older platforms.
That is appreciated. As I mentioned in the cover letter I have been
careful to try and not break older platforms, but double checking my
work is appreciated.
Regards,
Hans
>
>> }
>> }
>>
>> @@ -3587,9 +3597,8 @@ static int __init hotkey_init(struct
>> ibm_init_struct *iibm)
>> /* Disable brightness up/down on Lenovo thinkpads when
>> * ACPI is handling them, otherwise it is plain impossible
>> * for userspace to do something even remotely sane */
>> - hotkey_reserved_mask |=
>> - (1 << TP_ACPI_HOTKEYSCAN_FNHOME)
>> - | (1 << TP_ACPI_HOTKEYSCAN_FNEND);
>> + hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
>> + TP_ACPI_HKEY_BRGHTDWN_MASK;
>> hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNHOME);
>> hotkey_unmap(TP_ACPI_HOTKEYSCAN_FNEND);
>> }
>> --
>> 2.44.0
>
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 16/24] platform/x86: thinkpad_acpi: Change hotkey_reserved_mask initialization
2024-04-24 14:47 ` Hans de Goede
@ 2024-04-24 15:11 ` Mark Pearson
0 siblings, 0 replies; 42+ messages in thread
From: Mark Pearson @ 2024-04-24 15:11 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen, Andy Shevchenko,
Henrique de Moraes Holschuh
Cc: Vishnu Sankar, Nitin Joshi1, ibm-acpi-devel,
platform-driver-x86@vger.kernel.org
On Wed, Apr 24, 2024, at 10:47 AM, Hans de Goede wrote:
> Hi Mark,
>
> On 4/24/24 4:17 PM, Mark Pearson wrote:
>> Hi Hans,
>>
>> On Wed, Apr 24, 2024, at 8:28 AM, Hans de Goede wrote:
>>> Change the hotkey_reserved_mask initialization to hardcode the list
>>> of reserved keys. There are only a few reserved keys and the code to
>>> iterate over the keymap will be removed when moving to sparse-keymaps.
>>>
>>> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>>> ---
>>> drivers/platform/x86/thinkpad_acpi.c | 21 +++++++++++++++------
>>> 1 file changed, 15 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/platform/x86/thinkpad_acpi.c
>>> b/drivers/platform/x86/thinkpad_acpi.c
>>> index 952bac635a18..cf5c741d1343 100644
>>> --- a/drivers/platform/x86/thinkpad_acpi.c
>>> +++ b/drivers/platform/x86/thinkpad_acpi.c
>>> @@ -3545,6 +3545,19 @@ static int __init hotkey_init(struct
>>> ibm_init_struct *iibm)
>>> dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
>>> "using keymap number %lu\n", keymap_id);
>>>
>>> + /* Keys which should be reserved on both IBM and Lenovo models */
>>> + hotkey_reserved_mask = TP_ACPI_HKEY_KBD_LIGHT_MASK |
>>> + TP_ACPI_HKEY_VOLUP_MASK |
>>> + TP_ACPI_HKEY_VOLDWN_MASK |
>>> + TP_ACPI_HKEY_MUTE_MASK;
>>> + /*
>>> + * Reserve brightness up/down unconditionally on IBM models, on Lenovo
>>> + * models these are disabled based on acpi_video_get_backlight_type().
>>> + */
>>> + if (keymap_id == TPACPI_KEYMAP_IBM_GENERIC)
>>> + hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
>>> + TP_ACPI_HKEY_BRGHTDWN_MASK;
>>> +
>>> hotkey_keycode_map = kmemdup(&tpacpi_keymaps[keymap_id],
>>> TPACPI_HOTKEY_MAP_SIZE, GFP_KERNEL);
>>> if (!hotkey_keycode_map) {
>>> @@ -3560,9 +3573,6 @@ static int __init hotkey_init(struct
>>> ibm_init_struct *iibm)
>>> if (hotkey_keycode_map[i] != KEY_RESERVED) {
>>> input_set_capability(tpacpi_inputdev, EV_KEY,
>>> hotkey_keycode_map[i]);
>>> - } else {
>>> - if (i < sizeof(hotkey_reserved_mask)*8)
>>> - hotkey_reserved_mask |= 1 << i;
>>
>> Just to check my understanding here - does this change mean that the keys marked as KEY_RESERVED in the lenovo map won't make it into the mask?
>>
>> e.g the ones in this block:
>> KEY_RESERVED, /* Mute held, 0x103 */
>> KEY_BRIGHTNESS_MIN, /* Backlight off */
>> KEY_RESERVED, /* Clipping tool */
>> KEY_RESERVED, /* Cloud */
>> KEY_RESERVED,
>> KEY_VOICECOMMAND, /* Voice */
>> KEY_RESERVED,
>> KEY_RESERVED, /* Gestures */
>> KEY_RESERVED,
>> KEY_RESERVED,
>> KEY_RESERVED,
>> KEY_CONFIG, /* Settings */
>> KEY_RESERVED, /* New tab */
>> KEY_REFRESH, /* Reload */
>> KEY_BACK, /* Back */
>> KEY_RESERVED, /* Microphone down */
>> KEY_RESERVED, /* Microphone up */
>> KEY_RESERVED, /* Microphone cancellation */
>> KEY_RESERVED, /* Camera mode */
>> KEY_RESERVED, /* Rotate display, 0x116 */
>>
>> I'm not sure what the effect will be and I don't have the 2014 X1 Carbon (I assume it's the G1) available to test with unfortunately.
>
> Only the 32 original hotkeys are affected by any of the hotkey_*_mask
> values, note:
>
> if (i < sizeof(hotkey_reserved_mask)*8)
> hotkey_reserved_mask |= 1 << i;
>
> The (i < sizeof(hotkey_reserved_mask)*8) condition translates to
> (i < 32) so this code only ever set bits in hotkey_reserved_mask
> for the 32 original hotkeys.
>
Ah - excellent. I had missed that.
Thanks!
Reviewed-by Mark Pearson <mpearson-lenovo@squebb.ca>
(and that applies for all patches in the series up to this one...getting through them slowly)
Mark
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 22/24] platform/x86: thinkpad_acpi: Support for trackpoint doubletap
2024-04-24 12:28 ` [PATCH v2 22/24] platform/x86: thinkpad_acpi: Support for trackpoint doubletap Hans de Goede
@ 2024-04-24 18:19 ` Mark Pearson
2024-04-29 9:57 ` Hans de Goede
0 siblings, 1 reply; 42+ messages in thread
From: Mark Pearson @ 2024-04-24 18:19 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen, Andy Shevchenko,
Henrique de Moraes Holschuh
Cc: Vishnu Sankar, Nitin Joshi1, ibm-acpi-devel,
platform-driver-x86@vger.kernel.org
Hi Hans,
On Wed, Apr 24, 2024, at 8:28 AM, Hans de Goede wrote:
> From: Mark Pearson <mpearson-lenovo@squebb.ca>
>
> Lenovo trackpoints are adding the ability to generate a doubletap event.
> This handles the doubletap event and sends the KEY_PROG4 event to
> userspace. Despite the driver itself not using KEY_PROG1 - KEY_PROG3 this
> still uses KEY_PROG4 because of some keys being remapped to KEY_PROG1 -
> KEY_PROG3 by default by the upstream udev hwdb containing:
>
> evdev:name:ThinkPad Extra Buttons:dmi:bvn*:bvr*:bd*:svnLENOVO*:pn*:*
> ...
> KEYBOARD_KEY_17=prog1
> KEYBOARD_KEY_1a=f20 # Microphone mute button
> KEYBOARD_KEY_45=bookmarks
> KEYBOARD_KEY_46=prog2 # Fn + PrtSc, on Windows: Snipping tool
> KEYBOARD_KEY_4a=prog3 # Fn + Right shift, on Windows: No idea
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Signed-off-by: Vishnu Sankar <vishnuocv@gmail.com>
> Link: https://lore.kernel.org/r/20240417173124.9953-2-mpearson-lenovo@squebb.ca
> [hdegoede@redhat.com: Adjust for switch to sparse-keymap keymaps]
> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> drivers/platform/x86/thinkpad_acpi.c | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/drivers/platform/x86/thinkpad_acpi.c
> b/drivers/platform/x86/thinkpad_acpi.c
> index a53b00fecf1a..b6d6466215e1 100644
> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c
> @@ -248,6 +248,9 @@ enum tpacpi_hkey_event_t {
>
> /* Misc */
> TP_HKEY_EV_RFKILL_CHANGED = 0x7000, /* rfkill switch changed */
> +
> + /* Misc2 */
> + TP_HKEY_EV_TRACK_DOUBLETAP = 0x8036, /* trackpoint doubletap */
> };
>
>
> /****************************************************************************
> @@ -3268,6 +3271,7 @@ static const struct key_entry keymap_lenovo[]
> __initconst = {
> * after switching to sparse keymap support. The mappings above use
> translated
> * scancodes to preserve uAPI compatibility, see
> tpacpi_input_send_key().
> */
> + { KE_KEY, TP_HKEY_EV_TRACK_DOUBLETAP /* 0x8036 */, { KEY_PROG4 } },
> { KE_END }
> };
>
> @@ -3817,6 +3821,17 @@ static bool hotkey_notify_6xxx(const u32 hkey,
> bool *send_acpi_ev)
> return true;
> }
>
> +static bool hotkey_notify_8xxx(const u32 hkey, bool *send_acpi_ev)
> +{
> + switch (hkey) {
> + case TP_HKEY_EV_TRACK_DOUBLETAP:
> + tpacpi_input_send_key(hkey, send_acpi_ev);
> + return true;
> + default:
> + return false;
> + }
> +}
> +
> static void hotkey_notify(struct ibm_struct *ibm, u32 event)
> {
> u32 hkey;
> @@ -3893,6 +3908,10 @@ static void hotkey_notify(struct ibm_struct
> *ibm, u32 event)
> known_ev = true;
> }
> break;
> + case 8:
> + /* 0x8000-0x8FFF: misc2 */
> + known_ev = hotkey_notify_8xxx(hkey, &send_acpi_ev);
> + break;
> }
> if (!known_ev) {
> pr_notice("unhandled HKEY event 0x%04x\n", hkey);
> --
> 2.44.0
Instead of needing hotkey_notify_8xxx, now we are using the sparse_keymap can we just use hotkey_notify_hotkey for case 8? No need to check what the hkey is either.
Note - the future patch for the FN+G key (patch 24/24) will also need modifying as we'll need to move the check if the doubletap has been disabled for the doubletap hkey, but it's two lines so still seems cleaner overall.
I prototyped it on my system, and it worked.
Mark
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (23 preceding siblings ...)
2024-04-24 12:28 ` [PATCH v2 24/24] platform/x86: thinkpad_acpi: Support hotkey to disable trackpoint doubletap Hans de Goede
@ 2024-04-24 18:28 ` Mark Pearson
2024-04-25 9:31 ` Ilpo Järvinen
2024-04-29 10:03 ` Hans de Goede
26 siblings, 0 replies; 42+ messages in thread
From: Mark Pearson @ 2024-04-24 18:28 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen, Andy Shevchenko,
Henrique de Moraes Holschuh
Cc: Vishnu Sankar, Nitin Joshi1, ibm-acpi-devel,
platform-driver-x86@vger.kernel.org
On Wed, Apr 24, 2024, at 8:28 AM, Hans de Goede wrote:
> Hi All,
>
> Here is v2 of my patch-series to refactor thinkpad_acpi's hotkey handling
> and to add support for some new hotkeys on new models.
>
> Changes in v2:
> - Some small code style tweaks in response to reviews
> - Add various Reviewed-by and Tested-by tags
>
> Relevant parts of v1 cover-letter:
>
> I have been very careful to not introduce any changes wrt support for
> the original ThinkPad models / hotkeys which use the hotkey_*_mask
> related code.
>
> I've also done my best to avoid any *significant* functional change but
> there are still some functional changes, which should all not impact
> userspace compatibility:
>
> 1. Adaptive keyboard special keys will now also send EV_MSC events with
> the scancode, just like all the other hotkeys.
>
> 2. Rely on the input core for KEY_RESERVED suppression. This means that
> keys marked as KEY_RESERVED will still send EV_MSC evdev events when
> pressed (which helps users with mapping them to non reserved KEY_FOO
> values if desired).
>
> 3. Align the keycodes for volume up/down/mute and brightness up/down with
> those set by userspace through udev upstream's hwdb. Note these are all
> for keys which are suppressed by hotkey_reserved_mask by default.
> So this is only a functional change for users who override the default
> hotkey-mask *and* who do not have udev's default hwdb installed.
>
> 4. Suppress ACPI netlink event generation for unknown 0x1xxx hkey events to
> avoid userspace starting to rely on the netlink events for new hotkeys
> before these have been added to the keymap, only to have the netlink
> events get disabled by the adding of the new hotkeys to the keymap.
>
> This should not cause a behavior change for existing models since all
> currently known 0x1xxx events have a mapping.
>
> Here is a quick breakdown of the patches in this series:
>
> Patch 1 - 2: Fix a small locking issue on rmmod the only problem here
> really is a lockdep warning, so I plan to route these fixes through
> for-next together with the rest to keep things simple.
>
> Patch 3 - 14: Do a bunch of cleanups and refactoring
>
> Patch 15: Implements functional change no 4. I really kinda want to just
> completely disable ACPI netlink event generation when also sending evdev
> events instead of reporting these twice. But for the 0x11xx / 0x13xx
> hkey events the kernel has send ACPI netlink events for years now. So
> this disables ACPI netlink events for any new hotkeys going forward.
>
> Patch 16 - 18: Refactor / cleanup reserved key handling
>
> Patch 19: Actually move to sparse-keymaps
>
> Patch 20: Update the keymap for 2 adaptive kbd Fn row keys
>
> Patch 21 - 24: Mark's original patches adding support for the new Fn + N
> key combo and for trackpoint doubletap slightly reworked to use
> the new sparse-keymap.
>
> Regards,
>
> Hans
>
>
> Hans de Goede (20):
> platform/x86: thinkpad_acpi: Take hotkey_mutex during hotkey_exit()
> platform/x86: thinkpad_acpi: Provide hotkey_poll_stop_sync() dummy
> platform/x86: thinkpad_acpi: Drop setting send_/ignore_acpi_ev
> defaults twice
> platform/x86: thinkpad_acpi: Drop ignore_acpi_ev
> platform/x86: thinkpad_acpi: Use tpacpi_input_send_key() in adaptive
> kbd code
> platform/x86: thinkpad_acpi: Do hkey to scancode translation later
> platform/x86: thinkpad_acpi: Make tpacpi_driver_event() return if it
> handled the event
> platform/x86: thinkpad_acpi: Move adaptive kbd event handling to
> tpacpi_driver_event()
> platform/x86: thinkpad_acpi: Move special original hotkeys handling
> out of switch-case
> platform/x86: thinkpad_acpi: Move hotkey_user_mask check to
> tpacpi_input_send_key()
> platform/x86: thinkpad_acpi: Always call tpacpi_driver_event() for
> hotkeys
> platform/x86: thinkpad_acpi: Drop tpacpi_input_send_key_masked() and
> hotkey_driver_event()
> platform/x86: thinkpad_acpi: Move hkey > scancode mapping to
> tpacpi_input_send_key()
> platform/x86: thinkpad_acpi: Move tpacpi_driver_event() call to
> tpacpi_input_send_key()
> platform/x86: thinkpad_acpi: Do not send ACPI netlink events for
> unknown hotkeys
> platform/x86: thinkpad_acpi: Change hotkey_reserved_mask
> initialization
> platform/x86: thinkpad_acpi: Use correct keycodes for volume and
> brightness keys
> platform/x86: thinkpad_acpi: Drop KEY_RESERVED special handling
> platform/x86: thinkpad_acpi: Switch to using sparse-keymap helpers
> platform/x86: thinkpad_acpi: Add mappings for adaptive kbd
> clipping-tool and cloud keys
>
> Mark Pearson (4):
> platform/x86: thinkpad_acpi: Simplify known_ev handling
> platform/x86: thinkpad_acpi: Support for trackpoint doubletap
> platform/x86: thinkpad_acpi: Support for system debug info hotkey
> platform/x86: thinkpad_acpi: Support hotkey to disable trackpoint
> doubletap
>
> drivers/platform/x86/thinkpad_acpi.c | 854 +++++++++++----------------
> 1 file changed, 353 insertions(+), 501 deletions(-)
>
> --
> 2.44.0
For the entire v2 series:
Reviewed-by: mpearson-lenovo@squebb.ca
Plus a thank you. I learnt a bunch about the keymap interface/sub-system from reviewing the patch series; and I think the new sparse-keymap is a really nice cleanup.
Mark
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 04/24] platform/x86: thinkpad_acpi: Drop ignore_acpi_ev
2024-04-24 12:28 ` [PATCH v2 04/24] platform/x86: thinkpad_acpi: Drop ignore_acpi_ev Hans de Goede
@ 2024-04-25 7:13 ` Ilpo Järvinen
2024-04-29 9:34 ` Hans de Goede
0 siblings, 1 reply; 42+ messages in thread
From: Ilpo Järvinen @ 2024-04-25 7:13 UTC (permalink / raw)
To: Hans de Goede
Cc: Andy Shevchenko, Mark Pearson, Henrique de Moraes Holschuh,
Vishnu Sankar, Nitin Joshi, ibm-acpi-devel, platform-driver-x86
On Wed, 24 Apr 2024, Hans de Goede wrote:
> Setting ignore_acpi_ev to true has the same result as setting
> send_acpi_ev to false, so there is no need to have both.
>
> Drop ignore_acpi_ev.
>
> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Not directly related to this patch but while reviewing it I noticed
this which should be converted to false:
send_acpi_ev = 0;
--
i.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 15/24] platform/x86: thinkpad_acpi: Do not send ACPI netlink events for unknown hotkeys
2024-04-24 12:28 ` [PATCH v2 15/24] platform/x86: thinkpad_acpi: Do not send ACPI netlink events for unknown hotkeys Hans de Goede
@ 2024-04-25 8:51 ` Ilpo Järvinen
0 siblings, 0 replies; 42+ messages in thread
From: Ilpo Järvinen @ 2024-04-25 8:51 UTC (permalink / raw)
To: Hans de Goede
Cc: Andy Shevchenko, Mark Pearson, Henrique de Moraes Holschuh,
Vishnu Sankar, Nitin Joshi, ibm-acpi-devel, platform-driver-x86
On Wed, 24 Apr 2024, Hans de Goede wrote:
> Do not send ACPI netlink events for unknown hotkeys, to avoid userspace
> starting to rely on them. Instead these should be added to the keymap to
> send evdev events.
>
> This should not cause a behavior change for existing laptop models since
> all currently known 0x1xxx events have a mapping.
>
> In hindsight the ACPI netlink events should have been suppressed for
> the adaptive keyboard and extended hotkeys events too. But the kernel has
> been sending ACPI netlink events for those for a long time now, so we
> cannot just stop sending them without potentially causing issues for
> existing users who may depend on these.
>
> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> drivers/platform/x86/thinkpad_acpi.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
> index 9b38770412ab..952bac635a18 100644
> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c
> @@ -2250,7 +2250,7 @@ static void tpacpi_input_send_tabletsw(void)
> }
> }
>
> -static bool tpacpi_input_send_key(const u32 hkey)
> +static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
> {
> unsigned int keycode, scancode;
>
> @@ -2271,6 +2271,14 @@ static bool tpacpi_input_send_key(const u32 hkey)
> scancode = hkey - TP_HKEY_EV_EXTENDED_KEY_START +
> TP_ACPI_HOTKEYSCAN_EXTENDED_START;
> } else {
> + /*
> + * Do not send ACPI netlink events for unknown hotkeys, to
> + * avoid userspace starting to rely on them. Instead these
> + * should be added to the keymap to send evdev events.
> + */
> + if (send_acpi_ev)
> + *send_acpi_ev = false;
Hi,
I'd consider dropping the check and passing a pointer to dummy variable
instead of NULL, and comment at the caller defining the dummy variable why
the value is getting ignored. But you know this code better than me so I
leave it up to you what you want to do.
> +
> return false;
> }
>
> @@ -2298,7 +2306,7 @@ static struct tp_acpi_drv_struct ibm_hotkey_acpidriver;
> /* Do NOT call without validating scancode first */
> static void tpacpi_hotkey_send_key(unsigned int scancode)
> {
> - tpacpi_input_send_key(TP_HKEY_EV_ORIG_KEY_START + scancode);
> + tpacpi_input_send_key(TP_HKEY_EV_ORIG_KEY_START + scancode, NULL);
> }
--
i.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 16/24] platform/x86: thinkpad_acpi: Change hotkey_reserved_mask initialization
2024-04-24 12:28 ` [PATCH v2 16/24] platform/x86: thinkpad_acpi: Change hotkey_reserved_mask initialization Hans de Goede
2024-04-24 14:17 ` Mark Pearson
@ 2024-04-25 9:14 ` Ilpo Järvinen
2024-04-29 9:52 ` Hans de Goede
1 sibling, 1 reply; 42+ messages in thread
From: Ilpo Järvinen @ 2024-04-25 9:14 UTC (permalink / raw)
To: Hans de Goede
Cc: Andy Shevchenko, Mark Pearson, Henrique de Moraes Holschuh,
Vishnu Sankar, Nitin Joshi, ibm-acpi-devel, platform-driver-x86
On Wed, 24 Apr 2024, Hans de Goede wrote:
> Change the hotkey_reserved_mask initialization to hardcode the list
> of reserved keys. There are only a few reserved keys and the code to
> iterate over the keymap will be removed when moving to sparse-keymaps.
Hi,
Consider extending this explanation. It's hard to see how the old and new
code are identical because there are more KEY_RESERVED entries in the
array than in the new code. I can see the list of keys in the new code
matches to those set using tpacpi_hotkey_driver_mask_set() but it's hard
to connect the dots here.
> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> drivers/platform/x86/thinkpad_acpi.c | 21 +++++++++++++++------
> 1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
> index 952bac635a18..cf5c741d1343 100644
> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c
> @@ -3545,6 +3545,19 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
> dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
> "using keymap number %lu\n", keymap_id);
>
> + /* Keys which should be reserved on both IBM and Lenovo models */
> + hotkey_reserved_mask = TP_ACPI_HKEY_KBD_LIGHT_MASK |
> + TP_ACPI_HKEY_VOLUP_MASK |
> + TP_ACPI_HKEY_VOLDWN_MASK |
> + TP_ACPI_HKEY_MUTE_MASK;
> + /*
> + * Reserve brightness up/down unconditionally on IBM models, on Lenovo
> + * models these are disabled based on acpi_video_get_backlight_type().
> + */
> + if (keymap_id == TPACPI_KEYMAP_IBM_GENERIC)
> + hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
> + TP_ACPI_HKEY_BRGHTDWN_MASK;
> +
> hotkey_keycode_map = kmemdup(&tpacpi_keymaps[keymap_id],
> TPACPI_HOTKEY_MAP_SIZE, GFP_KERNEL);
> if (!hotkey_keycode_map) {
> @@ -3560,9 +3573,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
> if (hotkey_keycode_map[i] != KEY_RESERVED) {
> input_set_capability(tpacpi_inputdev, EV_KEY,
> hotkey_keycode_map[i]);
> - } else {
> - if (i < sizeof(hotkey_reserved_mask)*8)
> - hotkey_reserved_mask |= 1 << i;
> }
> }
>
> @@ -3587,9 +3597,8 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
> /* Disable brightness up/down on Lenovo thinkpads when
> * ACPI is handling them, otherwise it is plain impossible
> * for userspace to do something even remotely sane */
> - hotkey_reserved_mask |=
> - (1 << TP_ACPI_HOTKEYSCAN_FNHOME)
> - | (1 << TP_ACPI_HOTKEYSCAN_FNEND);
> + hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
> + TP_ACPI_HKEY_BRGHTDWN_MASK;
This is a simple define replace that would belong to own patch?
--
i.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (24 preceding siblings ...)
2024-04-24 18:28 ` [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Mark Pearson
@ 2024-04-25 9:31 ` Ilpo Järvinen
2024-04-29 10:03 ` Hans de Goede
26 siblings, 0 replies; 42+ messages in thread
From: Ilpo Järvinen @ 2024-04-25 9:31 UTC (permalink / raw)
To: Hans de Goede
Cc: Andy Shevchenko, Mark Pearson, Henrique de Moraes Holschuh,
Vishnu Sankar, Nitin Joshi, ibm-acpi-devel, platform-driver-x86
[-- Attachment #1: Type: text/plain, Size: 495 bytes --]
On Wed, 24 Apr 2024, Hans de Goede wrote:
> Hi All,
>
> Here is v2 of my patch-series to refactor thinkpad_acpi's hotkey handling
> and to add support for some new hotkeys on new models.
>
> Changes in v2:
> - Some small code style tweaks in response to reviews
> - Add various Reviewed-by and Tested-by tags
I reviewed the entire v2 series now, the small remarks were posted for the
relevant patches.
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
--
i.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 04/24] platform/x86: thinkpad_acpi: Drop ignore_acpi_ev
2024-04-25 7:13 ` Ilpo Järvinen
@ 2024-04-29 9:34 ` Hans de Goede
0 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-29 9:34 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Andy Shevchenko, Mark Pearson, Henrique de Moraes Holschuh,
Vishnu Sankar, Nitin Joshi, ibm-acpi-devel, platform-driver-x86
Hi,
On 4/25/24 9:13 AM, Ilpo Järvinen wrote:
> On Wed, 24 Apr 2024, Hans de Goede wrote:
>
>> Setting ignore_acpi_ev to true has the same result as setting
>> send_acpi_ev to false, so there is no need to have both.
>>
>> Drop ignore_acpi_ev.
>>
>> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>
> Not directly related to this patch but while reviewing it I noticed
> this which should be converted to false:
>
> send_acpi_ev = 0;
Right I noticed that too, but I decided it would be best to fix that
in a separate patch and then forgot about it.
Let me send a patch to address this right away.
Regards,
Hans
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 16/24] platform/x86: thinkpad_acpi: Change hotkey_reserved_mask initialization
2024-04-25 9:14 ` Ilpo Järvinen
@ 2024-04-29 9:52 ` Hans de Goede
2024-04-29 10:06 ` Ilpo Järvinen
0 siblings, 1 reply; 42+ messages in thread
From: Hans de Goede @ 2024-04-29 9:52 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Andy Shevchenko, Mark Pearson, Henrique de Moraes Holschuh,
Vishnu Sankar, Nitin Joshi, ibm-acpi-devel, platform-driver-x86
Hi Ilpo,
Thank you for reviewing this series.
On 4/25/24 11:14 AM, Ilpo Järvinen wrote:
> On Wed, 24 Apr 2024, Hans de Goede wrote:
>
>> Change the hotkey_reserved_mask initialization to hardcode the list
>> of reserved keys. There are only a few reserved keys and the code to
>> iterate over the keymap will be removed when moving to sparse-keymaps.
>
> Hi,
>
> Consider extending this explanation. It's hard to see how the old and new
> code are identical because there are more KEY_RESERVED entries in the
> array than in the new code. I can see the list of keys in the new code
> matches to those set using tpacpi_hotkey_driver_mask_set() but it's hard
> to connect the dots here.
Right, this is basically the same question as which Mark asked. I've added
the following to the commit message while merging this series to clarify this:
"""
Note only the 32 original hotkeys are affected by any of the hotkey_*_mask
values, note:
if (i < sizeof(hotkey_reserved_mask)*8)
hotkey_reserved_mask |= 1 << i;
The (i < sizeof(hotkey_reserved_mask)*8) condition translates to (i < 32)
so this code only ever set bits in hotkey_reserved_mask for the 32 original
hotkeys. Therefor this patch does not set any bits in hotkey_reserved_mask
for the KEY_RESERVED mappings for the adaptive keyboard scancodes.
"""
>
>> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> drivers/platform/x86/thinkpad_acpi.c | 21 +++++++++++++++------
>> 1 file changed, 15 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
>> index 952bac635a18..cf5c741d1343 100644
>> --- a/drivers/platform/x86/thinkpad_acpi.c
>> +++ b/drivers/platform/x86/thinkpad_acpi.c
>> @@ -3545,6 +3545,19 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
>> dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
>> "using keymap number %lu\n", keymap_id);
>>
>> + /* Keys which should be reserved on both IBM and Lenovo models */
>> + hotkey_reserved_mask = TP_ACPI_HKEY_KBD_LIGHT_MASK |
>> + TP_ACPI_HKEY_VOLUP_MASK |
>> + TP_ACPI_HKEY_VOLDWN_MASK |
>> + TP_ACPI_HKEY_MUTE_MASK;
>> + /*
>> + * Reserve brightness up/down unconditionally on IBM models, on Lenovo
>> + * models these are disabled based on acpi_video_get_backlight_type().
>> + */
>> + if (keymap_id == TPACPI_KEYMAP_IBM_GENERIC)
>> + hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
>> + TP_ACPI_HKEY_BRGHTDWN_MASK;
>> +
>> hotkey_keycode_map = kmemdup(&tpacpi_keymaps[keymap_id],
>> TPACPI_HOTKEY_MAP_SIZE, GFP_KERNEL);
>> if (!hotkey_keycode_map) {
>> @@ -3560,9 +3573,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
>> if (hotkey_keycode_map[i] != KEY_RESERVED) {
>> input_set_capability(tpacpi_inputdev, EV_KEY,
>> hotkey_keycode_map[i]);
>> - } else {
>> - if (i < sizeof(hotkey_reserved_mask)*8)
>> - hotkey_reserved_mask |= 1 << i;
>> }
>> }
>>
>> @@ -3587,9 +3597,8 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
>> /* Disable brightness up/down on Lenovo thinkpads when
>> * ACPI is handling them, otherwise it is plain impossible
>> * for userspace to do something even remotely sane */
>> - hotkey_reserved_mask |=
>> - (1 << TP_ACPI_HOTKEYSCAN_FNHOME)
>> - | (1 << TP_ACPI_HOTKEYSCAN_FNEND);
>> + hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
>> + TP_ACPI_HKEY_BRGHTDWN_MASK;
>
> This is a simple define replace that would belong to own patch?
This makes the code style identical to how the brightness keys are added
to the mask above. I guess this could have been in a separate patch, but
since it is less work for me to just leave it here I'm going to leave it here.
Regards,
Hans
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 22/24] platform/x86: thinkpad_acpi: Support for trackpoint doubletap
2024-04-24 18:19 ` Mark Pearson
@ 2024-04-29 9:57 ` Hans de Goede
2024-04-29 12:40 ` Mark Pearson
0 siblings, 1 reply; 42+ messages in thread
From: Hans de Goede @ 2024-04-29 9:57 UTC (permalink / raw)
To: Mark Pearson, Ilpo Järvinen, Andy Shevchenko,
Henrique de Moraes Holschuh
Cc: Vishnu Sankar, Nitin Joshi1, ibm-acpi-devel,
platform-driver-x86@vger.kernel.org
Hi Mark,
On 4/24/24 8:19 PM, Mark Pearson wrote:
> Hi Hans,
>
> On Wed, Apr 24, 2024, at 8:28 AM, Hans de Goede wrote:
>> From: Mark Pearson <mpearson-lenovo@squebb.ca>
>>
>> Lenovo trackpoints are adding the ability to generate a doubletap event.
>> This handles the doubletap event and sends the KEY_PROG4 event to
>> userspace. Despite the driver itself not using KEY_PROG1 - KEY_PROG3 this
>> still uses KEY_PROG4 because of some keys being remapped to KEY_PROG1 -
>> KEY_PROG3 by default by the upstream udev hwdb containing:
>>
>> evdev:name:ThinkPad Extra Buttons:dmi:bvn*:bvr*:bd*:svnLENOVO*:pn*:*
>> ...
>> KEYBOARD_KEY_17=prog1
>> KEYBOARD_KEY_1a=f20 # Microphone mute button
>> KEYBOARD_KEY_45=bookmarks
>> KEYBOARD_KEY_46=prog2 # Fn + PrtSc, on Windows: Snipping tool
>> KEYBOARD_KEY_4a=prog3 # Fn + Right shift, on Windows: No idea
>>
>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> Signed-off-by: Vishnu Sankar <vishnuocv@gmail.com>
>> Link: https://lore.kernel.org/r/20240417173124.9953-2-mpearson-lenovo@squebb.ca
>> [hdegoede@redhat.com: Adjust for switch to sparse-keymap keymaps]
>> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> drivers/platform/x86/thinkpad_acpi.c | 19 +++++++++++++++++++
>> 1 file changed, 19 insertions(+)
>>
>> diff --git a/drivers/platform/x86/thinkpad_acpi.c
>> b/drivers/platform/x86/thinkpad_acpi.c
>> index a53b00fecf1a..b6d6466215e1 100644
>> --- a/drivers/platform/x86/thinkpad_acpi.c
>> +++ b/drivers/platform/x86/thinkpad_acpi.c
>> @@ -248,6 +248,9 @@ enum tpacpi_hkey_event_t {
>>
>> /* Misc */
>> TP_HKEY_EV_RFKILL_CHANGED = 0x7000, /* rfkill switch changed */
>> +
>> + /* Misc2 */
>> + TP_HKEY_EV_TRACK_DOUBLETAP = 0x8036, /* trackpoint doubletap */
>> };
>>
>>
>> /****************************************************************************
>> @@ -3268,6 +3271,7 @@ static const struct key_entry keymap_lenovo[]
>> __initconst = {
>> * after switching to sparse keymap support. The mappings above use
>> translated
>> * scancodes to preserve uAPI compatibility, see
>> tpacpi_input_send_key().
>> */
>> + { KE_KEY, TP_HKEY_EV_TRACK_DOUBLETAP /* 0x8036 */, { KEY_PROG4 } },
>> { KE_END }
>> };
>>
>> @@ -3817,6 +3821,17 @@ static bool hotkey_notify_6xxx(const u32 hkey,
>> bool *send_acpi_ev)
>> return true;
>> }
>>
>> +static bool hotkey_notify_8xxx(const u32 hkey, bool *send_acpi_ev)
>> +{
>> + switch (hkey) {
>> + case TP_HKEY_EV_TRACK_DOUBLETAP:
>> + tpacpi_input_send_key(hkey, send_acpi_ev);
>> + return true;
>> + default:
>> + return false;
>> + }
>> +}
>> +
>> static void hotkey_notify(struct ibm_struct *ibm, u32 event)
>> {
>> u32 hkey;
>> @@ -3893,6 +3908,10 @@ static void hotkey_notify(struct ibm_struct
>> *ibm, u32 event)
>> known_ev = true;
>> }
>> break;
>> + case 8:
>> + /* 0x8000-0x8FFF: misc2 */
>> + known_ev = hotkey_notify_8xxx(hkey, &send_acpi_ev);
>> + break;
>> }
>> if (!known_ev) {
>> pr_notice("unhandled HKEY event 0x%04x\n", hkey);
>> --
>> 2.44.0
>
> Instead of needing hotkey_notify_8xxx, now we are using the sparse_keymap can we just use hotkey_notify_hotkey for case 8? No need to check what the hkey is either.
I prefer to keep things consistent and have each case #: path call a separate
helper for those #xxx codes.
ATM some of the simpler cases handle things directly, but as more handling for
different events get added that becomes a bit messy IMHO. I would actually
like to see those other cases converted to use a small helper function too
(with a switch-case in the helper for future proofing) to make things consistent.
Patches to do this small cleanup are welcome.
Regards,
Hans
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
` (25 preceding siblings ...)
2024-04-25 9:31 ` Ilpo Järvinen
@ 2024-04-29 10:03 ` Hans de Goede
26 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-04-29 10:03 UTC (permalink / raw)
To: Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Vishnu Sankar, Nitin Joshi, ibm-acpi-devel, platform-driver-x86
Hi All,
On 4/24/24 2:28 PM, Hans de Goede wrote:
> Hi All,
>
> Here is v2 of my patch-series to refactor thinkpad_acpi's hotkey handling
> and to add support for some new hotkeys on new models.
>
> Changes in v2:
> - Some small code style tweaks in response to reviews
> - Add various Reviewed-by and Tested-by tags
>
> Relevant parts of v1 cover-letter:
>
> I have been very careful to not introduce any changes wrt support for
> the original ThinkPad models / hotkeys which use the hotkey_*_mask
> related code.
>
> I've also done my best to avoid any *significant* functional change but
> there are still some functional changes, which should all not impact
> userspace compatibility:
>
> 1. Adaptive keyboard special keys will now also send EV_MSC events with
> the scancode, just like all the other hotkeys.
>
> 2. Rely on the input core for KEY_RESERVED suppression. This means that
> keys marked as KEY_RESERVED will still send EV_MSC evdev events when
> pressed (which helps users with mapping them to non reserved KEY_FOO
> values if desired).
>
> 3. Align the keycodes for volume up/down/mute and brightness up/down with
> those set by userspace through udev upstream's hwdb. Note these are all
> for keys which are suppressed by hotkey_reserved_mask by default.
> So this is only a functional change for users who override the default
> hotkey-mask *and* who do not have udev's default hwdb installed.
>
> 4. Suppress ACPI netlink event generation for unknown 0x1xxx hkey events to
> avoid userspace starting to rely on the netlink events for new hotkeys
> before these have been added to the keymap, only to have the netlink
> events get disabled by the adding of the new hotkeys to the keymap.
>
> This should not cause a behavior change for existing models since all
> currently known 0x1xxx events have a mapping.
>
> Here is a quick breakdown of the patches in this series:
>
> Patch 1 - 2: Fix a small locking issue on rmmod the only problem here
> really is a lockdep warning, so I plan to route these fixes through
> for-next together with the rest to keep things simple.
>
> Patch 3 - 14: Do a bunch of cleanups and refactoring
>
> Patch 15: Implements functional change no 4. I really kinda want to just
> completely disable ACPI netlink event generation when also sending evdev
> events instead of reporting these twice. But for the 0x11xx / 0x13xx
> hkey events the kernel has send ACPI netlink events for years now. So
> this disables ACPI netlink events for any new hotkeys going forward.
>
> Patch 16 - 18: Refactor / cleanup reserved key handling
>
> Patch 19: Actually move to sparse-keymaps
>
> Patch 20: Update the keymap for 2 adaptive kbd Fn row keys
>
> Patch 21 - 24: Mark's original patches adding support for the new Fn + N
> key combo and for trackpoint doubletap slightly reworked to use
> the new sparse-keymap.
I've added this series to my review-hans (soon to be for-next) branch now.
Regards,
Hans
> Hans de Goede (20):
> platform/x86: thinkpad_acpi: Take hotkey_mutex during hotkey_exit()
> platform/x86: thinkpad_acpi: Provide hotkey_poll_stop_sync() dummy
> platform/x86: thinkpad_acpi: Drop setting send_/ignore_acpi_ev
> defaults twice
> platform/x86: thinkpad_acpi: Drop ignore_acpi_ev
> platform/x86: thinkpad_acpi: Use tpacpi_input_send_key() in adaptive
> kbd code
> platform/x86: thinkpad_acpi: Do hkey to scancode translation later
> platform/x86: thinkpad_acpi: Make tpacpi_driver_event() return if it
> handled the event
> platform/x86: thinkpad_acpi: Move adaptive kbd event handling to
> tpacpi_driver_event()
> platform/x86: thinkpad_acpi: Move special original hotkeys handling
> out of switch-case
> platform/x86: thinkpad_acpi: Move hotkey_user_mask check to
> tpacpi_input_send_key()
> platform/x86: thinkpad_acpi: Always call tpacpi_driver_event() for
> hotkeys
> platform/x86: thinkpad_acpi: Drop tpacpi_input_send_key_masked() and
> hotkey_driver_event()
> platform/x86: thinkpad_acpi: Move hkey > scancode mapping to
> tpacpi_input_send_key()
> platform/x86: thinkpad_acpi: Move tpacpi_driver_event() call to
> tpacpi_input_send_key()
> platform/x86: thinkpad_acpi: Do not send ACPI netlink events for
> unknown hotkeys
> platform/x86: thinkpad_acpi: Change hotkey_reserved_mask
> initialization
> platform/x86: thinkpad_acpi: Use correct keycodes for volume and
> brightness keys
> platform/x86: thinkpad_acpi: Drop KEY_RESERVED special handling
> platform/x86: thinkpad_acpi: Switch to using sparse-keymap helpers
> platform/x86: thinkpad_acpi: Add mappings for adaptive kbd
> clipping-tool and cloud keys
>
> Mark Pearson (4):
> platform/x86: thinkpad_acpi: Simplify known_ev handling
> platform/x86: thinkpad_acpi: Support for trackpoint doubletap
> platform/x86: thinkpad_acpi: Support for system debug info hotkey
> platform/x86: thinkpad_acpi: Support hotkey to disable trackpoint
> doubletap
>
> drivers/platform/x86/thinkpad_acpi.c | 854 +++++++++++----------------
> 1 file changed, 353 insertions(+), 501 deletions(-)
>
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 16/24] platform/x86: thinkpad_acpi: Change hotkey_reserved_mask initialization
2024-04-29 9:52 ` Hans de Goede
@ 2024-04-29 10:06 ` Ilpo Järvinen
0 siblings, 0 replies; 42+ messages in thread
From: Ilpo Järvinen @ 2024-04-29 10:06 UTC (permalink / raw)
To: Hans de Goede
Cc: Andy Shevchenko, Mark Pearson, Henrique de Moraes Holschuh,
Vishnu Sankar, Nitin Joshi, ibm-acpi-devel, platform-driver-x86
[-- Attachment #1: Type: text/plain, Size: 1520 bytes --]
On Mon, 29 Apr 2024, Hans de Goede wrote:
>
> Thank you for reviewing this series.
>
> On 4/25/24 11:14 AM, Ilpo Järvinen wrote:
> > On Wed, 24 Apr 2024, Hans de Goede wrote:
> >
> >> Change the hotkey_reserved_mask initialization to hardcode the list
> >> of reserved keys. There are only a few reserved keys and the code to
> >> iterate over the keymap will be removed when moving to sparse-keymaps.
> >
> > Hi,
> >
> > Consider extending this explanation. It's hard to see how the old and new
> > code are identical because there are more KEY_RESERVED entries in the
> > array than in the new code. I can see the list of keys in the new code
> > matches to those set using tpacpi_hotkey_driver_mask_set() but it's hard
> > to connect the dots here.
>
> Right, this is basically the same question as which Mark asked. I've added
> the following to the commit message while merging this series to clarify this:
>
> """
> Note only the 32 original hotkeys are affected by any of the hotkey_*_mask
> values, note:
>
> if (i < sizeof(hotkey_reserved_mask)*8)
> hotkey_reserved_mask |= 1 << i;
>
> The (i < sizeof(hotkey_reserved_mask)*8) condition translates to (i < 32)
> so this code only ever set bits in hotkey_reserved_mask for the 32 original
> hotkeys. Therefor this patch does not set any bits in hotkey_reserved_mask
> for the KEY_RESERVED mappings for the adaptive keyboard scancodes.
> """
Thanks for adding it, very clear now!
--
i.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 22/24] platform/x86: thinkpad_acpi: Support for trackpoint doubletap
2024-04-29 9:57 ` Hans de Goede
@ 2024-04-29 12:40 ` Mark Pearson
0 siblings, 0 replies; 42+ messages in thread
From: Mark Pearson @ 2024-04-29 12:40 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen, Andy Shevchenko,
Henrique de Moraes Holschuh
Cc: Vishnu Sankar, Nitin Joshi1, ibm-acpi-devel,
platform-driver-x86@vger.kernel.org
On Mon, Apr 29, 2024, at 5:57 AM, Hans de Goede wrote:
> Hi Mark,
>
> On 4/24/24 8:19 PM, Mark Pearson wrote:
>> Hi Hans,
>>
>> On Wed, Apr 24, 2024, at 8:28 AM, Hans de Goede wrote:
>>> From: Mark Pearson <mpearson-lenovo@squebb.ca>
>>>
>>> Lenovo trackpoints are adding the ability to generate a doubletap event.
>>> This handles the doubletap event and sends the KEY_PROG4 event to
>>> userspace. Despite the driver itself not using KEY_PROG1 - KEY_PROG3 this
>>> still uses KEY_PROG4 because of some keys being remapped to KEY_PROG1 -
>>> KEY_PROG3 by default by the upstream udev hwdb containing:
>>>
>>> evdev:name:ThinkPad Extra Buttons:dmi:bvn*:bvr*:bd*:svnLENOVO*:pn*:*
>>> ...
>>> KEYBOARD_KEY_17=prog1
>>> KEYBOARD_KEY_1a=f20 # Microphone mute button
>>> KEYBOARD_KEY_45=bookmarks
>>> KEYBOARD_KEY_46=prog2 # Fn + PrtSc, on Windows: Snipping tool
>>> KEYBOARD_KEY_4a=prog3 # Fn + Right shift, on Windows: No idea
>>>
>>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>>> Signed-off-by: Vishnu Sankar <vishnuocv@gmail.com>
>>> Link: https://lore.kernel.org/r/20240417173124.9953-2-mpearson-lenovo@squebb.ca
>>> [hdegoede@redhat.com: Adjust for switch to sparse-keymap keymaps]
>>> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>>> ---
>>> drivers/platform/x86/thinkpad_acpi.c | 19 +++++++++++++++++++
>>> 1 file changed, 19 insertions(+)
>>>
>>> diff --git a/drivers/platform/x86/thinkpad_acpi.c
>>> b/drivers/platform/x86/thinkpad_acpi.c
>>> index a53b00fecf1a..b6d6466215e1 100644
>>> --- a/drivers/platform/x86/thinkpad_acpi.c
>>> +++ b/drivers/platform/x86/thinkpad_acpi.c
>>> @@ -248,6 +248,9 @@ enum tpacpi_hkey_event_t {
>>>
>>> /* Misc */
>>> TP_HKEY_EV_RFKILL_CHANGED = 0x7000, /* rfkill switch changed */
>>> +
>>> + /* Misc2 */
>>> + TP_HKEY_EV_TRACK_DOUBLETAP = 0x8036, /* trackpoint doubletap */
>>> };
>>>
>>>
>>> /****************************************************************************
>>> @@ -3268,6 +3271,7 @@ static const struct key_entry keymap_lenovo[]
>>> __initconst = {
>>> * after switching to sparse keymap support. The mappings above use
>>> translated
>>> * scancodes to preserve uAPI compatibility, see
>>> tpacpi_input_send_key().
>>> */
>>> + { KE_KEY, TP_HKEY_EV_TRACK_DOUBLETAP /* 0x8036 */, { KEY_PROG4 } },
>>> { KE_END }
>>> };
>>>
>>> @@ -3817,6 +3821,17 @@ static bool hotkey_notify_6xxx(const u32 hkey,
>>> bool *send_acpi_ev)
>>> return true;
>>> }
>>>
>>> +static bool hotkey_notify_8xxx(const u32 hkey, bool *send_acpi_ev)
>>> +{
>>> + switch (hkey) {
>>> + case TP_HKEY_EV_TRACK_DOUBLETAP:
>>> + tpacpi_input_send_key(hkey, send_acpi_ev);
>>> + return true;
>>> + default:
>>> + return false;
>>> + }
>>> +}
>>> +
>>> static void hotkey_notify(struct ibm_struct *ibm, u32 event)
>>> {
>>> u32 hkey;
>>> @@ -3893,6 +3908,10 @@ static void hotkey_notify(struct ibm_struct
>>> *ibm, u32 event)
>>> known_ev = true;
>>> }
>>> break;
>>> + case 8:
>>> + /* 0x8000-0x8FFF: misc2 */
>>> + known_ev = hotkey_notify_8xxx(hkey, &send_acpi_ev);
>>> + break;
>>> }
>>> if (!known_ev) {
>>> pr_notice("unhandled HKEY event 0x%04x\n", hkey);
>>> --
>>> 2.44.0
>>
>> Instead of needing hotkey_notify_8xxx, now we are using the sparse_keymap can we just use hotkey_notify_hotkey for case 8? No need to check what the hkey is either.
>
> I prefer to keep things consistent and have each case #: path call a separate
> helper for those #xxx codes.
>
> ATM some of the simpler cases handle things directly, but as more
> handling for
> different events get added that becomes a bit messy IMHO. I would
> actually
> like to see those other cases converted to use a small helper function
> too
> (with a switch-case in the helper for future proofing) to make things
> consistent.
>
Got it - no problem.
> Patches to do this small cleanup are welcome.
>
Sounds good. Will look at doing this.
Mark
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 19/24] platform/x86: thinkpad_acpi: Switch to using sparse-keymap helpers
2024-04-24 12:28 ` [PATCH v2 19/24] platform/x86: thinkpad_acpi: Switch to using sparse-keymap helpers Hans de Goede
@ 2024-05-22 11:50 ` Vlastimil Babka
2024-05-22 13:30 ` Hans de Goede
0 siblings, 1 reply; 42+ messages in thread
From: Vlastimil Babka @ 2024-05-22 11:50 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen, Andy Shevchenko, Mark Pearson,
Henrique de Moraes Holschuh
Cc: Vishnu Sankar, Nitin Joshi, ibm-acpi-devel, platform-driver-x86
On 4/24/24 2:28 PM, Hans de Goede wrote:
> Switch the hotkey keymap handling over to the sparse-keymap helpers,
> there should be no functional changes from this.
>
> Note all the mappings to KEY_UNKNOWN are removed since that is the default
> behavior of sparse_keymap_report_event() for unknown scancodes.
>
> Also drop the big comment about making changes to the keymaps since
> the contents of that comment are mostly obsolete.
>
> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Hi,
I believe this is what gave me the following error compiling current
Linus's master:
ERROR: modpost: "sparse_keymap_report_event"
[drivers/platform/x86/thinkpad_acpi.ko] undefined!
ERROR: modpost: "sparse_keymap_setup"
[drivers/platform/x86/thinkpad_acpi.ko] undefined!
probably config THINKPAD_ACPI now has to depend/select INPUT_SPARSEKMAP?
It's fixed when I configure it =m manually.
Thanks,
Vlastimil
> ---
> Changes in v2:
> - Use proper multi-line comment style
> ---
> drivers/platform/x86/thinkpad_acpi.c | 404 ++++++++++-----------------
> 1 file changed, 145 insertions(+), 259 deletions(-)
>
> diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
> index 6a136d124cab..8af9406f2a13 100644
> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c
> @@ -45,6 +45,7 @@
> #include <linux/hwmon-sysfs.h>
> #include <linux/init.h>
> #include <linux/input.h>
> +#include <linux/input/sparse-keymap.h>
> #include <linux/jiffies.h>
> #include <linux/kernel.h>
> #include <linux/kthread.h>
> @@ -1759,12 +1760,12 @@ enum { /* hot key scan codes (derived from ACPI DSDT) */
> TP_ACPI_HOTKEYSCAN_THINKPAD,
> TP_ACPI_HOTKEYSCAN_UNK1,
> TP_ACPI_HOTKEYSCAN_UNK2,
> - TP_ACPI_HOTKEYSCAN_UNK3,
> + TP_ACPI_HOTKEYSCAN_MICMUTE,
> TP_ACPI_HOTKEYSCAN_UNK4,
> - TP_ACPI_HOTKEYSCAN_UNK5,
> - TP_ACPI_HOTKEYSCAN_UNK6,
> - TP_ACPI_HOTKEYSCAN_UNK7,
> - TP_ACPI_HOTKEYSCAN_UNK8,
> + TP_ACPI_HOTKEYSCAN_CONFIG,
> + TP_ACPI_HOTKEYSCAN_SEARCH,
> + TP_ACPI_HOTKEYSCAN_SCALE,
> + TP_ACPI_HOTKEYSCAN_FILE,
>
> /* Adaptive keyboard keycodes */
> TP_ACPI_HOTKEYSCAN_ADAPTIVE_START, /* 32 / 0x20 */
> @@ -1779,7 +1780,7 @@ enum { /* hot key scan codes (derived from ACPI DSDT) */
> TP_ACPI_HOTKEYSCAN_UNK11,
> TP_ACPI_HOTKEYSCAN_UNK12,
> TP_ACPI_HOTKEYSCAN_UNK13,
> - TP_ACPI_HOTKEYSCAN_CONFIG,
> + TP_ACPI_HOTKEYSCAN_CONFIG2,
> TP_ACPI_HOTKEYSCAN_NEW_TAB,
> TP_ACPI_HOTKEYSCAN_RELOAD,
> TP_ACPI_HOTKEYSCAN_BACK,
> @@ -1801,9 +1802,6 @@ enum { /* hot key scan codes (derived from ACPI DSDT) */
> TP_ACPI_HOTKEYSCAN_NOTIFICATION_CENTER,
> TP_ACPI_HOTKEYSCAN_PICKUP_PHONE,
> TP_ACPI_HOTKEYSCAN_HANGUP_PHONE,
> -
> - /* Hotkey keymap size */
> - TPACPI_HOTKEY_MAP_LEN
> };
>
> enum { /* Keys/events available through NVRAM polling */
> @@ -1916,8 +1914,6 @@ static u32 hotkey_driver_mask; /* events needed by the driver */
> static u32 hotkey_user_mask; /* events visible to userspace */
> static u32 hotkey_acpi_mask; /* events enabled in firmware */
>
> -static u16 *hotkey_keycode_map;
> -
> static bool tpacpi_driver_event(const unsigned int hkey_event);
> static void hotkey_poll_setup(const bool may_warn);
>
> @@ -2252,11 +2248,24 @@ static void tpacpi_input_send_tabletsw(void)
>
> static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
> {
> - unsigned int keycode, scancode;
> + bool known_ev;
> + u32 scancode;
>
> if (tpacpi_driver_event(hkey))
> return true;
>
> + /*
> + * Before the conversion to using the sparse-keymap helpers the driver used to
> + * map the hkey event codes to 0x00 - 0x4d scancodes so that a straight scancode
> + * indexed array could be used to map scancodes to keycodes:
> + *
> + * 0x1001 - 0x1020 -> 0x00 - 0x1f (Original ThinkPad events)
> + * 0x1103 - 0x1116 -> 0x20 - 0x33 (Adaptive keyboard, 2014 X1 Carbon)
> + * 0x1300 - 0x1319 -> 0x34 - 0x4d (Additional keys send in 2017+ models)
> + *
> + * The sparse-keymap tables still use these scancodes for these ranges to
> + * preserve userspace API compatibility (e.g. hwdb keymappings).
> + */
> if (hkey >= TP_HKEY_EV_ORIG_KEY_START &&
> hkey <= TP_HKEY_EV_ORIG_KEY_END) {
> scancode = hkey - TP_HKEY_EV_ORIG_KEY_START;
> @@ -2279,23 +2288,14 @@ static bool tpacpi_input_send_key(const u32 hkey, bool *send_acpi_ev)
> if (send_acpi_ev)
> *send_acpi_ev = false;
>
> - return false;
> + scancode = hkey;
> }
>
> - keycode = hotkey_keycode_map[scancode];
> -
> mutex_lock(&tpacpi_inputdev_send_mutex);
> -
> - input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode);
> - input_report_key(tpacpi_inputdev, keycode, 1);
> - input_sync(tpacpi_inputdev);
> -
> - input_report_key(tpacpi_inputdev, keycode, 0);
> - input_sync(tpacpi_inputdev);
> -
> + known_ev = sparse_keymap_report_event(tpacpi_inputdev, scancode, 1, true);
> mutex_unlock(&tpacpi_inputdev_send_mutex);
>
> - return true;
> + return known_ev;
> }
>
> #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
> @@ -3124,9 +3124,6 @@ static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = {
> TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */
> };
>
> -typedef u16 tpacpi_keymap_entry_t;
> -typedef tpacpi_keymap_entry_t tpacpi_keymap_t[TPACPI_HOTKEY_MAP_LEN];
> -
> static int hotkey_init_tablet_mode(void)
> {
> int in_tablet_mode = 0, res;
> @@ -3163,217 +3160,124 @@ static int hotkey_init_tablet_mode(void)
> return in_tablet_mode;
> }
>
> +static const struct key_entry keymap_ibm[] __initconst = {
> + /* Original hotkey mappings translated scancodes 0x00 - 0x1f */
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF1, { KEY_FN_F1 } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF2, { KEY_BATTERY } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF3, { KEY_COFFEE } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF4, { KEY_SLEEP } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF5, { KEY_WLAN } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF6, { KEY_FN_F6 } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF7, { KEY_SWITCHVIDEOMODE } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF8, { KEY_FN_F8 } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF9, { KEY_FN_F9 } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF10, { KEY_FN_F10 } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF11, { KEY_FN_F11 } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF12, { KEY_SUSPEND } },
> + /* Brightness: firmware always reacts, suppressed through hotkey_reserved_mask. */
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNHOME, { KEY_BRIGHTNESSUP } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNEND, { KEY_BRIGHTNESSDOWN } },
> + /* Thinklight: firmware always reacts, suppressed through hotkey_reserved_mask. */
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNPAGEUP, { KEY_KBDILLUMTOGGLE } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNSPACE, { KEY_ZOOM } },
> + /*
> + * Volume: firmware always reacts and reprograms the built-in *extra* mixer.
> + * Suppressed by default through hotkey_reserved_mask.
> + */
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_VOLUMEUP, { KEY_VOLUMEUP } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, { KEY_VOLUMEDOWN } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_MUTE, { KEY_MUTE } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_THINKPAD, { KEY_VENDOR } },
> + { KE_END }
> +};
> +
> +static const struct key_entry keymap_lenovo[] __initconst = {
> + /* Original hotkey mappings translated scancodes 0x00 - 0x1f */
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF1, { KEY_FN_F1 } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF2, { KEY_COFFEE } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF3, { KEY_BATTERY } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF4, { KEY_SLEEP } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF5, { KEY_WLAN } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF6, { KEY_CAMERA, } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF7, { KEY_SWITCHVIDEOMODE } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF8, { KEY_FN_F8 } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF9, { KEY_FN_F9 } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF10, { KEY_FN_F10 } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF11, { KEY_FN_F11 } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNF12, { KEY_SUSPEND } },
> + /*
> + * These should be enabled --only-- when ACPI video is disabled and
> + * are handled in a special way by the init code.
> + */
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNHOME, { KEY_BRIGHTNESSUP } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNEND, { KEY_BRIGHTNESSDOWN } },
> + /* Suppressed by default through hotkey_reserved_mask. */
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNPAGEUP, { KEY_KBDILLUMTOGGLE } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FNSPACE, { KEY_ZOOM } },
> + /*
> + * Volume: z60/z61, T60 (BIOS version?): firmware always reacts and
> + * reprograms the built-in *extra* mixer.
> + * T60?, T61, R60?, R61: firmware and EC tries to send these over
> + * the regular keyboard (not through tpacpi). There are still weird bugs
> + * re. MUTE. May cause the BIOS to interfere with the HDA mixer.
> + * Suppressed by default through hotkey_reserved_mask.
> + */
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_VOLUMEUP, { KEY_VOLUMEUP } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, { KEY_VOLUMEDOWN } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_MUTE, { KEY_MUTE } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_THINKPAD, { KEY_VENDOR } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_MICMUTE, { KEY_MICMUTE } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_CONFIG, { KEY_CONFIG } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_SEARCH, { KEY_SEARCH } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_SCALE, { KEY_SCALE } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FILE, { KEY_FILE } },
> + /* Adaptive keyboard mappings for Carbon X1 2014 translated scancodes 0x20 - 0x33 */
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_MUTE2, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_BRIGHTNESS_ZERO, { KEY_BRIGHTNESS_MIN } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_CLOUD, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_UNK9, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_VOICE, { KEY_VOICECOMMAND } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_UNK10, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_GESTURES, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_UNK11, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_UNK12, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_UNK13, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_CONFIG2, { KEY_CONFIG } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_NEW_TAB, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_RELOAD, { KEY_REFRESH } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_BACK, { KEY_BACK } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_MIC_DOWN, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_MIC_UP, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_MIC_CANCELLATION, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_CAMERA_MODE, { KEY_RESERVED } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_ROTATE_DISPLAY, { KEY_RESERVED } },
> + /* Extended hotkeys mappings translated scancodes 0x34 - 0x4d */
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_STAR, { KEY_BOOKMARKS } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL2, { KEY_SELECTIVE_SCREENSHOT } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_CALCULATOR, { KEY_CALC } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_BLUETOOTH, { KEY_BLUETOOTH } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_KEYBOARD, { KEY_KEYBOARD } },
> + /* Used by "Lenovo Quick Clean" */
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_FN_RIGHT_SHIFT, { KEY_FN_RIGHT_SHIFT } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_NOTIFICATION_CENTER, { KEY_NOTIFICATION_CENTER } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_PICKUP_PHONE, { KEY_PICKUP_PHONE } },
> + { KE_KEY, TP_ACPI_HOTKEYSCAN_HANGUP_PHONE, { KEY_HANGUP_PHONE } },
> + /*
> + * All mapping below are for raw untranslated hkey event codes mapped directly
> + * after switching to sparse keymap support. The mappings above use translated
> + * scancodes to preserve uAPI compatibility, see tpacpi_input_send_key().
> + */
> + { KE_END }
> +};
> +
> static int __init hotkey_init(struct ibm_init_struct *iibm)
> {
> - /* Requirements for changing the default keymaps:
> - *
> - * 1. Many of the keys are mapped to KEY_RESERVED for very
> - * good reasons. Do not change them unless you have deep
> - * knowledge on the IBM and Lenovo ThinkPad firmware for
> - * the various ThinkPad models. The driver behaves
> - * differently for KEY_RESERVED: such keys have their
> - * hot key mask *unset* in mask_recommended, and also
> - * in the initial hot key mask programmed into the
> - * firmware at driver load time, which means the firm-
> - * ware may react very differently if you change them to
> - * something else;
> - *
> - * 2. You must be subscribed to the linux-thinkpad and
> - * ibm-acpi-devel mailing lists, and you should read the
> - * list archives since 2007 if you want to change the
> - * keymaps. This requirement exists so that you will
> - * know the past history of problems with the thinkpad-
> - * acpi driver keymaps, and also that you will be
> - * listening to any bug reports;
> - *
> - * 3. Do not send thinkpad-acpi specific patches directly to
> - * for merging, *ever*. Send them to the linux-acpi
> - * mailinglist for comments. Merging is to be done only
> - * through acpi-test and the ACPI maintainer.
> - *
> - * If the above is too much to ask, don't change the keymap.
> - * Ask the thinkpad-acpi maintainer to do it, instead.
> - */
> -
> enum keymap_index {
> TPACPI_KEYMAP_IBM_GENERIC = 0,
> TPACPI_KEYMAP_LENOVO_GENERIC,
> };
>
> - static const tpacpi_keymap_t tpacpi_keymaps[] __initconst = {
> - /* Generic keymap for IBM ThinkPads */
> - [TPACPI_KEYMAP_IBM_GENERIC] = {
> - /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
> - KEY_FN_F1, KEY_BATTERY, KEY_COFFEE, KEY_SLEEP,
> - KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
> - KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
> -
> - /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
> - KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
> - KEY_UNKNOWN, /* 0x0D: FN+INSERT */
> - KEY_UNKNOWN, /* 0x0E: FN+DELETE */
> -
> - /* brightness: firmware always reacts to them.
> - * Suppressed by default through hotkey_reserved_mask.
> - */
> - KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */
> - KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */
> -
> - /* Thinklight: firmware always react to it.
> - * Suppressed by default through hotkey_reserved_mask.
> - */
> - KEY_KBDILLUMTOGGLE, /* 0x11: FN+PGUP (thinklight toggle) */
> -
> - KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
> - KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
> -
> - /* Volume: firmware always react to it and reprograms
> - * the built-in *extra* mixer. Never map it to control
> - * another mixer by default.
> - * Suppressed by default through hotkey_reserved_mask.
> - */
> - KEY_VOLUMEUP, /* 0x14: VOLUME UP */
> - KEY_VOLUMEDOWN, /* 0x15: VOLUME DOWN */
> - KEY_MUTE, /* 0x16: MUTE */
> -
> - KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
> -
> - /* (assignments unknown, please report if found) */
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> -
> - /* No assignments, only used for Adaptive keyboards. */
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> -
> - /* No assignment, used for newer Lenovo models */
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN
> -
> - },
> -
> - /* Generic keymap for Lenovo ThinkPads */
> - [TPACPI_KEYMAP_LENOVO_GENERIC] = {
> - /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
> - KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP,
> - KEY_WLAN, KEY_CAMERA, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
> - KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
> -
> - /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
> - KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
> - KEY_UNKNOWN, /* 0x0D: FN+INSERT */
> - KEY_UNKNOWN, /* 0x0E: FN+DELETE */
> -
> - /* These should be enabled --only-- when ACPI video
> - * is disabled (i.e. in "vendor" mode), and are handled
> - * in a special way by the init code */
> - KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */
> - KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */
> -
> - /* Suppressed by default through hotkey_reserved_mask. */
> - KEY_KBDILLUMTOGGLE, /* 0x11: FN+PGUP (thinklight toggle) */
> -
> - KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
> - KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
> -
> - /* Volume: z60/z61, T60 (BIOS version?): firmware always
> - * react to it and reprograms the built-in *extra* mixer.
> - * Never map it to control another mixer by default.
> - *
> - * T60?, T61, R60?, R61: firmware and EC tries to send
> - * these over the regular keyboard, so these are no-ops,
> - * but there are still weird bugs re. MUTE, so do not
> - * change unless you get test reports from all Lenovo
> - * models. May cause the BIOS to interfere with the
> - * HDA mixer.
> - * Suppressed by default through hotkey_reserved_mask.
> - */
> - KEY_VOLUMEUP, /* 0x14: VOLUME UP */
> - KEY_VOLUMEDOWN, /* 0x15: VOLUME DOWN */
> - KEY_MUTE, /* 0x16: MUTE */
> -
> - KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
> -
> - /* (assignments unknown, please report if found) */
> - KEY_UNKNOWN, KEY_UNKNOWN,
> -
> - /*
> - * The mic mute button only sends 0x1a. It does not
> - * automatically mute the mic or change the mute light.
> - */
> - KEY_MICMUTE, /* 0x1a: Mic mute (since ?400 or so) */
> -
> - /* (assignments unknown, please report if found) */
> - KEY_UNKNOWN,
> -
> - /* Extra keys in use since the X240 / T440 / T540 */
> - KEY_CONFIG, KEY_SEARCH, KEY_SCALE, KEY_FILE,
> -
> - /*
> - * These are the adaptive keyboard keycodes for Carbon X1 2014.
> - * The first item in this list is the Mute button which is
> - * emitted with 0x103 through
> - * adaptive_keyboard_hotkey_notify_hotkey() when the sound
> - * symbol is held.
> - * We'll need to offset those by 0x20.
> - */
> - KEY_RESERVED, /* Mute held, 0x103 */
> - KEY_BRIGHTNESS_MIN, /* Backlight off */
> - KEY_RESERVED, /* Clipping tool */
> - KEY_RESERVED, /* Cloud */
> - KEY_RESERVED,
> - KEY_VOICECOMMAND, /* Voice */
> - KEY_RESERVED,
> - KEY_RESERVED, /* Gestures */
> - KEY_RESERVED,
> - KEY_RESERVED,
> - KEY_RESERVED,
> - KEY_CONFIG, /* Settings */
> - KEY_RESERVED, /* New tab */
> - KEY_REFRESH, /* Reload */
> - KEY_BACK, /* Back */
> - KEY_RESERVED, /* Microphone down */
> - KEY_RESERVED, /* Microphone up */
> - KEY_RESERVED, /* Microphone cancellation */
> - KEY_RESERVED, /* Camera mode */
> - KEY_RESERVED, /* Rotate display, 0x116 */
> -
> - /*
> - * These are found in 2017 models (e.g. T470s, X270).
> - * The lowest known value is 0x311, which according to
> - * the manual should launch a user defined favorite
> - * application.
> - *
> - * The offset for these is TP_ACPI_HOTKEYSCAN_EXTENDED_START,
> - * corresponding to 0x34.
> - */
> -
> - /* (assignments unknown, please report if found) */
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
> - KEY_UNKNOWN,
> -
> - KEY_BOOKMARKS, /* Favorite app, 0x311 */
> - KEY_SELECTIVE_SCREENSHOT, /* Clipping tool */
> - KEY_CALC, /* Calculator (above numpad, P52) */
> - KEY_BLUETOOTH, /* Bluetooth */
> - KEY_KEYBOARD, /* Keyboard, 0x315 */
> - KEY_FN_RIGHT_SHIFT, /* Fn + right Shift */
> - KEY_NOTIFICATION_CENTER, /* Notification Center */
> - KEY_PICKUP_PHONE, /* Answer incoming call */
> - KEY_HANGUP_PHONE, /* Decline incoming call */
> - },
> - };
> -
> static const struct tpacpi_quirk tpacpi_keymap_qtable[] __initconst = {
> /* Generic maps (fallback) */
> {
> @@ -3388,17 +3292,11 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
> },
> };
>
> -#define TPACPI_HOTKEY_MAP_SIZE sizeof(tpacpi_keymap_t)
> -#define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(tpacpi_keymap_entry_t)
> -
> - int res, i;
> - int status;
> - int hkeyv;
> + unsigned long keymap_id, quirks;
> + const struct key_entry *keymap;
> bool radiosw_state = false;
> bool tabletsw_state = false;
> -
> - unsigned long quirks;
> - unsigned long keymap_id;
> + int hkeyv, res, status;
>
> vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
> "initializing hotkey subdriver\n");
> @@ -3538,7 +3436,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
> /* Set up key map */
> keymap_id = tpacpi_check_quirks(tpacpi_keymap_qtable,
> ARRAY_SIZE(tpacpi_keymap_qtable));
> - BUG_ON(keymap_id >= ARRAY_SIZE(tpacpi_keymaps));
> dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
> "using keymap number %lu\n", keymap_id);
>
> @@ -3551,27 +3448,17 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
> * Reserve brightness up/down unconditionally on IBM models, on Lenovo
> * models these are disabled based on acpi_video_get_backlight_type().
> */
> - if (keymap_id == TPACPI_KEYMAP_IBM_GENERIC)
> + if (keymap_id == TPACPI_KEYMAP_IBM_GENERIC) {
> hotkey_reserved_mask |= TP_ACPI_HKEY_BRGHTUP_MASK |
> TP_ACPI_HKEY_BRGHTDWN_MASK;
> -
> - hotkey_keycode_map = kmemdup(&tpacpi_keymaps[keymap_id],
> - TPACPI_HOTKEY_MAP_SIZE, GFP_KERNEL);
> - if (!hotkey_keycode_map) {
> - pr_err("failed to allocate memory for key map\n");
> - return -ENOMEM;
> + keymap = keymap_ibm;
> + } else {
> + keymap = keymap_lenovo;
> }
>
> - input_set_capability(tpacpi_inputdev, EV_MSC, MSC_SCAN);
> - tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE;
> - tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN;
> - tpacpi_inputdev->keycode = hotkey_keycode_map;
> - for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) {
> - if (hotkey_keycode_map[i] != KEY_RESERVED) {
> - input_set_capability(tpacpi_inputdev, EV_KEY,
> - hotkey_keycode_map[i]);
> - }
> - }
> + res = sparse_keymap_setup(tpacpi_inputdev, keymap, NULL);
> + if (res)
> + return res;
>
> if (tp_features.hotkey_wlsw) {
> input_set_capability(tpacpi_inputdev, EV_SW, SW_RFKILL_ALL);
> @@ -11739,7 +11626,6 @@ static void thinkpad_acpi_module_exit(void)
> input_unregister_device(tpacpi_inputdev);
> else
> input_free_device(tpacpi_inputdev);
> - kfree(hotkey_keycode_map);
> }
>
> if (tpacpi_sensors_pdev)
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 19/24] platform/x86: thinkpad_acpi: Switch to using sparse-keymap helpers
2024-05-22 11:50 ` Vlastimil Babka
@ 2024-05-22 13:30 ` Hans de Goede
0 siblings, 0 replies; 42+ messages in thread
From: Hans de Goede @ 2024-05-22 13:30 UTC (permalink / raw)
To: Vlastimil Babka, Ilpo Järvinen, Andy Shevchenko,
Mark Pearson, Henrique de Moraes Holschuh
Cc: Vishnu Sankar, Nitin Joshi, ibm-acpi-devel, platform-driver-x86
Hi Vlastimil,
On 5/22/24 1:50 PM, Vlastimil Babka wrote:
> On 4/24/24 2:28 PM, Hans de Goede wrote:
>> Switch the hotkey keymap handling over to the sparse-keymap helpers,
>> there should be no functional changes from this.
>>
>> Note all the mappings to KEY_UNKNOWN are removed since that is the default
>> behavior of sparse_keymap_report_event() for unknown scancodes.
>>
>> Also drop the big comment about making changes to the keymaps since
>> the contents of that comment are mostly obsolete.
>>
>> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>
> Hi,
>
> I believe this is what gave me the following error compiling current
> Linus's master:
>
> ERROR: modpost: "sparse_keymap_report_event"
> [drivers/platform/x86/thinkpad_acpi.ko] undefined!
> ERROR: modpost: "sparse_keymap_setup"
> [drivers/platform/x86/thinkpad_acpi.ko] undefined!
>
> probably config THINKPAD_ACPI now has to depend/select INPUT_SPARSEKMAP?
> It's fixed when I configure it =m manually.
Thank you for reporting this. This should be fixed by:
https://lore.kernel.org/platform-driver-x86/20240522074813.379b9fc2@gandalf.local.home/T/#u
Which I will include in my next pdx86 fixes pull-request to Linus.
Regards,
Hans
^ permalink raw reply [flat|nested] 42+ messages in thread
end of thread, other threads:[~2024-05-22 13:30 UTC | newest]
Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-24 12:28 [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Hans de Goede
2024-04-24 12:28 ` [PATCH v2 01/24] platform/x86: thinkpad_acpi: Take hotkey_mutex during hotkey_exit() Hans de Goede
2024-04-24 12:28 ` [PATCH v2 02/24] platform/x86: thinkpad_acpi: Provide hotkey_poll_stop_sync() dummy Hans de Goede
2024-04-24 12:28 ` [PATCH v2 03/24] platform/x86: thinkpad_acpi: Drop setting send_/ignore_acpi_ev defaults twice Hans de Goede
2024-04-24 12:28 ` [PATCH v2 04/24] platform/x86: thinkpad_acpi: Drop ignore_acpi_ev Hans de Goede
2024-04-25 7:13 ` Ilpo Järvinen
2024-04-29 9:34 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 05/24] platform/x86: thinkpad_acpi: Use tpacpi_input_send_key() in adaptive kbd code Hans de Goede
2024-04-24 12:28 ` [PATCH v2 06/24] platform/x86: thinkpad_acpi: Do hkey to scancode translation later Hans de Goede
2024-04-24 12:28 ` [PATCH v2 07/24] platform/x86: thinkpad_acpi: Make tpacpi_driver_event() return if it handled the event Hans de Goede
2024-04-24 12:28 ` [PATCH v2 08/24] platform/x86: thinkpad_acpi: Move adaptive kbd event handling to tpacpi_driver_event() Hans de Goede
2024-04-24 12:28 ` [PATCH v2 09/24] platform/x86: thinkpad_acpi: Move special original hotkeys handling out of switch-case Hans de Goede
2024-04-24 12:28 ` [PATCH v2 10/24] platform/x86: thinkpad_acpi: Move hotkey_user_mask check to tpacpi_input_send_key() Hans de Goede
2024-04-24 12:28 ` [PATCH v2 11/24] platform/x86: thinkpad_acpi: Always call tpacpi_driver_event() for hotkeys Hans de Goede
2024-04-24 12:28 ` [PATCH v2 12/24] platform/x86: thinkpad_acpi: Drop tpacpi_input_send_key_masked() and hotkey_driver_event() Hans de Goede
2024-04-24 12:28 ` [PATCH v2 13/24] platform/x86: thinkpad_acpi: Move hkey > scancode mapping to tpacpi_input_send_key() Hans de Goede
2024-04-24 12:28 ` [PATCH v2 14/24] platform/x86: thinkpad_acpi: Move tpacpi_driver_event() call " Hans de Goede
2024-04-24 12:28 ` [PATCH v2 15/24] platform/x86: thinkpad_acpi: Do not send ACPI netlink events for unknown hotkeys Hans de Goede
2024-04-25 8:51 ` Ilpo Järvinen
2024-04-24 12:28 ` [PATCH v2 16/24] platform/x86: thinkpad_acpi: Change hotkey_reserved_mask initialization Hans de Goede
2024-04-24 14:17 ` Mark Pearson
2024-04-24 14:47 ` Hans de Goede
2024-04-24 15:11 ` Mark Pearson
2024-04-25 9:14 ` Ilpo Järvinen
2024-04-29 9:52 ` Hans de Goede
2024-04-29 10:06 ` Ilpo Järvinen
2024-04-24 12:28 ` [PATCH v2 17/24] platform/x86: thinkpad_acpi: Use correct keycodes for volume and brightness keys Hans de Goede
2024-04-24 12:28 ` [PATCH v2 18/24] platform/x86: thinkpad_acpi: Drop KEY_RESERVED special handling Hans de Goede
2024-04-24 12:28 ` [PATCH v2 19/24] platform/x86: thinkpad_acpi: Switch to using sparse-keymap helpers Hans de Goede
2024-05-22 11:50 ` Vlastimil Babka
2024-05-22 13:30 ` Hans de Goede
2024-04-24 12:28 ` [PATCH v2 20/24] platform/x86: thinkpad_acpi: Add mappings for adaptive kbd clipping-tool and cloud keys Hans de Goede
2024-04-24 12:28 ` [PATCH v2 21/24] platform/x86: thinkpad_acpi: Simplify known_ev handling Hans de Goede
2024-04-24 12:28 ` [PATCH v2 22/24] platform/x86: thinkpad_acpi: Support for trackpoint doubletap Hans de Goede
2024-04-24 18:19 ` Mark Pearson
2024-04-29 9:57 ` Hans de Goede
2024-04-29 12:40 ` Mark Pearson
2024-04-24 12:28 ` [PATCH v2 23/24] platform/x86: thinkpad_acpi: Support for system debug info hotkey Hans de Goede
2024-04-24 12:28 ` [PATCH v2 24/24] platform/x86: thinkpad_acpi: Support hotkey to disable trackpoint doubletap Hans de Goede
2024-04-24 18:28 ` [PATCH v2 00/24] platform/x86: thinkpad_acpi: Refactor hotkey handling and add support for some new hotkeys Mark Pearson
2024-04-25 9:31 ` Ilpo Järvinen
2024-04-29 10:03 ` Hans de Goede
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.