Skip to content

Commit 65a3e6c

Browse files
Stefan Seyfriedjwrdegoede
authored andcommitted
platform/x86: panasonic-laptop: de-obfuscate button codes
In the definition of panasonic_keymap[] the key codes are given in decimal, later checks are done with hexadecimal values, which does not help in understanding the code. Additionally use two helper variables to shorten the code and make the logic more obvious. Fixes: ed83c91 ("platform/x86: panasonic-laptop: Resolve hotkey double trigger bug") Signed-off-by: Stefan Seyfried <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3a0cf7a commit 65a3e6c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

drivers/platform/x86/panasonic-laptop.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ static void acpi_pcc_generate_keyinput(struct pcc_acpi *pcc)
762762
struct input_dev *hotk_input_dev = pcc->input_dev;
763763
int rc;
764764
unsigned long long result;
765+
unsigned int key;
766+
unsigned int updown;
765767

766768
rc = acpi_evaluate_integer(pcc->handle, METHOD_HKEY_QUERY,
767769
NULL, &result);
@@ -770,18 +772,22 @@ static void acpi_pcc_generate_keyinput(struct pcc_acpi *pcc)
770772
return;
771773
}
772774

775+
key = result & 0xf;
776+
updown = result & 0x80; /* 0x80 == key down; 0x00 = key up */
777+
773778
/* hack: some firmware sends no key down for sleep / hibernate */
774-
if ((result & 0xf) == 0x7 || (result & 0xf) == 0xa) {
775-
if (result & 0x80)
779+
if (key == 7 || key == 10) {
780+
if (updown)
776781
sleep_keydown_seen = 1;
777782
if (!sleep_keydown_seen)
778783
sparse_keymap_report_event(hotk_input_dev,
779-
result & 0xf, 0x80, false);
784+
key, 0x80, false);
780785
}
781786

782-
if ((result & 0xf) == 0x7 || (result & 0xf) == 0x9 || (result & 0xf) == 0xa) {
787+
/* for the magic values, see panasonic_keymap[] above */
788+
if (key == 7 || key == 9 || key == 10) {
783789
if (!sparse_keymap_report_event(hotk_input_dev,
784-
result & 0xf, result & 0x80, false))
790+
key, updown, false))
785791
pr_err("Unknown hotkey event: 0x%04llx\n", result);
786792
}
787793
}

0 commit comments

Comments
 (0)