Thread (13 messages) 13 messages, 4 authors, 1d ago
WARM1d

[PATCH 2/2] amd-sfh-tabletmode: interpret sfh tablet mode hid report

From: Helge Bahmann <hidden>
Date: 2026-07-21 14:30:06
Subsystem: input (keyboard, mouse, joystick, touchscreen) drivers, the rest · Maintainers: Dmitry Torokhov, Linus Torvalds

Add a driver that hooks into the tablet mode hid reports
generated by the amd-sfh-hid driver. This enables tablet
mode switching on e.g. Asus Vivobook devices.

Signed-off-by: Helge Bahmann <redacted>
---
 drivers/input/misc/Kconfig              | 11 ++++
 drivers/input/misc/Makefile             |  1 +
 drivers/input/misc/amd_sfh_tabletmode.c | 88 +++++++++++++++++++++++++
 3 files changed, 100 insertions(+)
 create mode 100644 drivers/input/misc/amd_sfh_tabletmode.c
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 94a753fcb64f..5a1dacd6f7b9 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -1003,4 +1003,15 @@ config INPUT_STPMIC1_ONKEY
 	  To compile this driver as a module, choose M here: the
 	  module will be called stpmic1_onkey.
 
+config INPUT_AMD_SFH_TABLETMODE
+	tristate "AMD sensor fusion hub tablet mode driver"
+	help
+	  Say Y to enable support of the tablet mode switch driver for
+	  convertible laptops based on the AMD sensor fusion hub. This
+	  driver is known to work on Asus VivoBook but will likely
+	  work on other laptops featuring the same chipset.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called amd_sfh_tabletmode.
+
 endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 415fc4e2918b..3f5abbe39f3a 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -96,3 +96,4 @@ obj-$(CONFIG_INPUT_WM831X_ON)		+= wm831x-on.o
 obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND)	+= xen-kbdfront.o
 obj-$(CONFIG_INPUT_YEALINK)		+= yealink.o
 obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR)	+= ideapad_slidebar.o
+obj-$(CONFIG_INPUT_AMD_SFH_TABLETMODE)	+= amd_sfh_tabletmode.o
diff --git a/drivers/input/misc/amd_sfh_tabletmode.c b/drivers/input/misc/amd_sfh_tabletmode.c
new file mode 100644
index 000000000000..ee1207372207
--- /dev/null
+++ b/drivers/input/misc/amd_sfh_tabletmode.c
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * AMD MP2 PCIe tablet mode hid input driver
+ * Copyright 2026 Helge Bahmann Advanced Micro Devices, Inc.
+ * Authors: Helge Bahmann <hcb@chaoticmind.net>
+ */
+
+#include <linux/hid.h>
+#include <linux/module.h>
+
+#define AMD_SFH_HID_VENDOR        0x1022
+#define AMD_SFH_HID_PRODUCT       0x0001
+
+static int amd_sfh_tabletmode_probe(struct hid_device *hdev,
+				    const struct hid_device_id *id)
+{
+	int error = 0;
+
+	error = hid_parse(hdev);
+	if (error)
+		return error;
+
+	error = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+	if (error)
+		return error;
+
+	return 0;
+}
+
+static void amd_sfh_tabletmode_remove(struct hid_device *hdev)
+{
+	hid_hw_stop(hdev);
+}
+
+static int amd_sfh_tabletmode_input_mapping(struct hid_device *hdev, struct hid_input *hi,
+					    struct hid_field *field, struct hid_usage *usage,
+					    unsigned long **bit, int *max)
+{
+	if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER && (usage->hid & HID_USAGE) == 0x02ff) {
+		input_set_capability(hi->input, EV_SW, SW_TABLET_MODE);
+		usage->type = EV_SW;
+		usage->code = SW_TABLET_MODE;
+		return 1;
+	}
+	return 0;
+}
+
+static int amd_sfh_tabletmode_event(struct hid_device *hid, struct hid_field *field,
+				    struct hid_usage *usage, __s32 value)
+{
+	input_report_switch(field->hidinput->input, SW_TABLET_MODE, value);
+
+	return 0;
+}
+
+static const struct hid_device_id amd_sfh_tabletmode_devices[] = {
+	{ HID_DEVICE(BUS_AMD_SFH, HID_GROUP_GENERIC, AMD_SFH_HID_VENDOR, AMD_SFH_HID_PRODUCT) },
+	{ }
+};
+MODULE_DEVICE_TABLE(hid, amd_sfh_tabletmode_devices);
+
+static struct hid_driver amd_sfh_tabletmode_driver = {
+	.name = "amd_sfh_tabletmode",
+	.id_table = amd_sfh_tabletmode_devices,
+	.probe = amd_sfh_tabletmode_probe,
+	.remove = amd_sfh_tabletmode_remove,
+	.input_mapping = amd_sfh_tabletmode_input_mapping,
+	.event = amd_sfh_tabletmode_event,
+};
+
+static int __init amd_sfh_tabletmode_init(void)
+{
+	int error;
+
+	error = hid_register_driver(&amd_sfh_tabletmode_driver);
+
+	return error;
+}
+module_init(amd_sfh_tabletmode_init);
+
+static void __exit amd_sfh_tabletmode_exit(void)
+{
+	hid_unregister_driver(&amd_sfh_tabletmode_driver);
+}
+module_exit(amd_sfh_tabletmode_exit);
+
+MODULE_DESCRIPTION("Input driver for tablet mode sensor on amd sfh.");
+MODULE_LICENSE("GPL");
-- 
2.47.3


Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help