All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: "Rafael J . Wysocki" <rafael@kernel.org>,
	Mark Gross <markgross@kernel.org>,
	Andy Shevchenko <andy@kernel.org>
Cc: Hans de Goede <hdegoede@redhat.com>, Len Brown <lenb@kernel.org>,
	linux-acpi@vger.kernel.org,
	Stefan Seyfried <stefan.seyfried@googlemail.com>,
	Kenneth Chan <kenneth.t.chan@gmail.com>,
	platform-driver-x86@vger.kernel.org,
	Stefan Seyfried <seife+kernel@b1-systems.com>
Subject: [PATCH 2/7] platform/x86: panasonic-laptop: de-obfuscate button codes
Date: Fri, 24 Jun 2022 13:23:35 +0200	[thread overview]
Message-ID: <20220624112340.10130-3-hdegoede@redhat.com> (raw)
In-Reply-To: <20220624112340.10130-1-hdegoede@redhat.com>

From: Stefan Seyfried <seife+kernel@b1-systems.com>

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: ed83c9171829 ("platform/x86: panasonic-laptop: Resolve hotkey double trigger bug")
Signed-off-by: Stefan Seyfried <seife+kernel@b1-systems.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/panasonic-laptop.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index 37850d07987d..ca6137f4000f 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -762,6 +762,8 @@ static void acpi_pcc_generate_keyinput(struct pcc_acpi *pcc)
 	struct input_dev *hotk_input_dev = pcc->input_dev;
 	int rc;
 	unsigned long long result;
+	unsigned int key;
+	unsigned int updown;
 
 	rc = acpi_evaluate_integer(pcc->handle, METHOD_HKEY_QUERY,
 				   NULL, &result);
@@ -770,18 +772,22 @@ static void acpi_pcc_generate_keyinput(struct pcc_acpi *pcc)
 		return;
 	}
 
+	key = result & 0xf;
+	updown = result & 0x80; /* 0x80 == key down; 0x00 = key up */
+
 	/* hack: some firmware sends no key down for sleep / hibernate */
-	if ((result & 0xf) == 0x7 || (result & 0xf) == 0xa) {
-		if (result & 0x80)
+	if (key == 7 || key == 10) {
+		if (updown)
 			sleep_keydown_seen = 1;
 		if (!sleep_keydown_seen)
 			sparse_keymap_report_event(hotk_input_dev,
-					result & 0xf, 0x80, false);
+					key, 0x80, false);
 	}
 
-	if ((result & 0xf) == 0x7 || (result & 0xf) == 0x9 || (result & 0xf) == 0xa) {
+	/* for the magic values, see panasonic_keymap[] above */
+	if (key == 7 || key == 9 || key == 10) {
 		if (!sparse_keymap_report_event(hotk_input_dev,
-						result & 0xf, result & 0x80, false))
+						key, updown, false))
 			pr_err("Unknown hotkey event: 0x%04llx\n", result);
 	}
 }
-- 
2.36.0


  parent reply	other threads:[~2022-06-24 11:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-24 11:23 [PATCH 0/7] ACPI: video / platform/x86: Fix Panasonic laptop missing keypresses Hans de Goede
2022-06-24 11:23 ` [PATCH 1/7] ACPI: video: Change how we determine if brightness key-presses are handled Hans de Goede
2022-06-25 13:43   ` Rafael J. Wysocki
2022-06-28 10:24   ` Andy Shevchenko
2022-06-24 11:23 ` Hans de Goede [this message]
2022-06-28 10:29   ` [PATCH 2/7] platform/x86: panasonic-laptop: de-obfuscate button codes Andy Shevchenko
2022-06-24 11:23 ` [PATCH 3/7] platform/x86: panasonic-laptop: sort includes alphabetically Hans de Goede
2022-06-24 11:23 ` [PATCH 4/7] platform/x86: panasonic-laptop: revert "Resolve hotkey double trigger bug" Hans de Goede
2022-06-24 11:23 ` [PATCH 5/7] platform/x86: panasonic-laptop: don't report duplicate brightness key-presses Hans de Goede
2022-06-24 11:23 ` [PATCH 6/7] platform/x86: panasonic-laptop: filter out duplicate volume up/down/mute keypresses Hans de Goede
2022-06-28 10:34   ` Andy Shevchenko
2022-06-24 11:23 ` [PATCH 7/7] platform/x86: panasonic-laptop: Use acpi_video_get_backlight_type() Hans de Goede
2022-06-24 19:49 ` [PATCH 0/7] ACPI: video / platform/x86: Fix Panasonic laptop missing keypresses Stefan Seyfried
2022-06-26  6:58   ` Kenneth Chan
2022-06-28 20:09     ` Hans de Goede
2022-06-28 10:35 ` Andy Shevchenko
2022-06-28 20:02 ` Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220624112340.10130-3-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=andy@kernel.org \
    --cc=kenneth.t.chan@gmail.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=markgross@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=seife+kernel@b1-systems.com \
    --cc=stefan.seyfried@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.