All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hilgad Montelo <hilgad.montelo@gmail.com>
To: kenneth.t.chan@gmail.com, hansg@kernel.org,
	ilpo.jarvinen@linux.intel.com
Cc: platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Hilgad Montelo <hilgad.montelo@gmail.com>
Subject: [PATCH v2 1/3] platform/x86: panasonic-laptop: Handle CF-33 rotation-lock button
Date: Thu, 13 Aug 2026 19:17:42 -0300	[thread overview]
Message-ID: <20260813221744.25668-2-hilgad.montelo@gmail.com> (raw)
In-Reply-To: <20260813221744.25668-1-hilgad.montelo@gmail.com>

On the Panasonic Toughbook CF-33 the bezel "Rotation Lock" button does
not signal via ACPI notify like the other hotkeys. Instead the
embedded controller injects raw i8042/PS2 scancodes that alias the
real Left-GUI/Meta key:

    press:   e0 5b   65
    release: e5      e0 db

e0 5b / e0 db are the standard AT scancode for the physical Left-GUI
key. The bare 65 / e5 bytes interleaved with them are not valid codes
for any real key and only ever appear as part of this vendor signal
(confirmed by tracing raw bytes crossing the i8042 port on the actual
hardware). Left unfiltered, this shows up as a spurious KEY_LEFTMETA +
KEY_F14 combo, which does nothing useful and can trigger desktop
environment Meta-key bindings on every press.

This driver already installs an i8042 filter (panasonic_i8042_filter)
to de-duplicate volume key events. Extend it with a small state
machine that recognizes and swallows the exact e0 5b 65 ... e5 e0 db
sequence, and emits a single debounced KEY_ROTATE_LOCK_TOGGLE event
instead. The 600ms debounce is needed because the EC repeats the
make/break unit every ~280-400ms for as long as the button is
physically held, which would otherwise fire multiple toggles for one
tap. If a byte sequence starts the same way but doesn't complete the
pattern, the buffered e0 5b bytes are replayed unfiltered, so a
genuine Left-GUI keypress is unaffected.

Verified on a CF-33 Mk1: each button press now produces exactly one
KEY_ROTATE_LOCK_TOGGLE pair, the plain keyboard device stays silent
during presses (no more stray LEFTMETA/F14), and GNOME's auto-rotate
lock correctly engages/disengages. Brightness and volume hotkeys are
unaffected.

Signed-off-by: Hilgad Montelo <hilgad.montelo@gmail.com>
---
 drivers/platform/x86/panasonic-laptop.c | 85 ++++++++++++++++++++++++-
 1 file changed, 84 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index 719add7..0c0e4a6 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -127,6 +127,7 @@
 #include <linux/init.h>
 #include <linux/input.h>
 #include <linux/input/sparse-keymap.h>
+#include <linux/jiffies.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
@@ -256,15 +257,81 @@ struct pcc_acpi {
 /*
  * On some Panasonic models the volume up / down / mute keys send duplicate
  * keypress events over the PS/2 kbd interface, filter these out.
+ *
+ * On the CF-33 the bezel "Rotation Lock" button also signals over this same
+ * interface, instead of via an ACPI notify like the other hotkeys. It does
+ * so by injecting scancodes that alias the real Left-GUI/Meta key
+ * (e0 5b make / e0 db break), interleaved with a bare byte (0x65 / 0xe5)
+ * that no physical key on this keyboard uses. Left unfiltered this shows up
+ * as a bogus LEFTMETA+F14 combo. We recognize and swallow the whole
+ * sequence and emit a single debounced KEY_ROTATE_LOCK_TOGGLE instead; any
+ * byte that breaks the expected pattern is treated as a genuine key and
+ * replayed unfiltered.
  */
+enum rot_lock_state {
+	ROT_IDLE,
+	ROT_WAIT_65,
+	ROT_WAIT_E5,
+	ROT_WAIT_E0B,
+	ROT_WAIT_DB,
+};
+
 static bool panasonic_i8042_filter(unsigned char data, unsigned char str,
 				   struct serio *port, void *context)
 {
+	struct pcc_acpi *pcc = context;
 	static bool extended;
+	static enum rot_lock_state rstate = ROT_IDLE;
+	static unsigned long last_toggle;
+	const unsigned long debounce = msecs_to_jiffies(600);
 
 	if (str & I8042_STR_AUXDATA)
 		return false;
 
+	switch (rstate) {
+	case ROT_WAIT_65:
+		if (data == 0x65) {
+			rstate = ROT_WAIT_E5;
+			if (pcc && pcc->input_dev &&
+			    time_after(jiffies, last_toggle + debounce)) {
+				input_report_key(pcc->input_dev,
+						  KEY_ROTATE_LOCK_TOGGLE, 1);
+				input_sync(pcc->input_dev);
+				input_report_key(pcc->input_dev,
+						  KEY_ROTATE_LOCK_TOGGLE, 0);
+				input_sync(pcc->input_dev);
+				last_toggle = jiffies;
+			}
+			return true;
+		}
+		/* Not our sequence: replay the buffered genuine Left-GUI make. */
+		rstate = ROT_IDLE;
+		serio_interrupt(port, 0xe0, 0);
+		serio_interrupt(port, 0x5b, 0);
+		break;
+	case ROT_WAIT_E5:
+		if (data == 0xe5) {
+			rstate = ROT_WAIT_E0B;
+			return true;
+		}
+		rstate = ROT_IDLE;
+		break;
+	case ROT_WAIT_E0B:
+		if (data == 0xe0) {
+			rstate = ROT_WAIT_DB;
+			return true;
+		}
+		rstate = ROT_IDLE;
+		break;
+	case ROT_WAIT_DB:
+		rstate = ROT_IDLE;
+		if (data == 0xdb)
+			return true;
+		break;
+	case ROT_IDLE:
+		break;
+	}
+
 	if (data == 0xe0) {
 		extended = true;
 		return true;
@@ -276,6 +343,19 @@ static bool panasonic_i8042_filter(unsigned char data, unsigned char str,
 		case 0x2e: /* e0 2e / e0 ae, Volume Down press / release */
 		case 0x30: /* e0 30 / e0 b0, Volume Up press / release */
 			return true;
+		case 0x5b: /* e0 5b, possible start of rotate-lock sequence */
+			if (data == 0x5b) {
+				rstate = ROT_WAIT_65;
+				return true;
+			}
+			/*
+			 * data == 0xdb: genuine Left-GUI/Meta break code.
+			 * The rotate-lock sequence only ever begins with
+			 * the make code, so this is a real key release,
+			 * not our sequence; the code below replays it
+			 * untouched.
+			 */
+			fallthrough;
 		default:
 			/*
 			 * Report the previously filtered e0 before continuing
@@ -944,6 +1024,9 @@ static int acpi_pcc_init_input(struct pcc_acpi *pcc)
 		goto err_free_dev;
 	}
 
+	/* Synthesized by panasonic_i8042_filter(), not part of the ACPI keymap. */
+	input_set_capability(input_dev, EV_KEY, KEY_ROTATE_LOCK_TOGGLE);
+
 	error = input_register_device(input_dev);
 	if (error) {
 		pr_err("Unable to register input device\n");
@@ -1090,7 +1173,7 @@ static int acpi_pcc_hotkey_probe(struct platform_device *pdev)
 		pcc->platform = NULL;
 	}
 
-	i8042_install_filter(panasonic_i8042_filter, NULL);
+	i8042_install_filter(panasonic_i8042_filter, pcc);
 	return 0;
 
 out_platform:
-- 
2.53.0


  reply	other threads:[~2026-08-13 22:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-13 22:17 [PATCH v2 0/3] platform/x86: panasonic-laptop: CF-33 hotkey fixes Hilgad Montelo
2026-08-13 22:17 ` Hilgad Montelo [this message]
2026-08-13 22:17 ` [PATCH v2 2/3] platform/x86: panasonic-laptop: Add driver for CF-33 A1/A2 buttons (TBTN) Hilgad Montelo
2026-08-13 22:17 ` [PATCH v2 3/3] platform/x86: panasonic-laptop: Fix sentinel write past pcc->sinf[] Hilgad Montelo
2026-08-18 11:09   ` Ilpo Järvinen

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=20260813221744.25668-2-hilgad.montelo@gmail.com \
    --to=hilgad.montelo@gmail.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=kenneth.t.chan@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /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.