From: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
To: <jikos@kernel.org>, <bentiss@kernel.org>, <dmitry.torokhov@gmail.com>
Cc: <linux-input@vger.kernel.org>,
Basavaraj Natikar <Basavaraj.Natikar@amd.com>,
Helge Bahmann <hcb@chaoticmind.net>
Subject: [PATCH v2 5/5] Input: misc: Add AMD SFH tablet-mode switch driver
Date: Mon, 3 Aug 2026 20:28:01 +0530 [thread overview]
Message-ID: <20260803145801.3801862-6-Basavaraj.Natikar@amd.com> (raw)
In-Reply-To: <20260803145801.3801862-1-Basavaraj.Natikar@amd.com>
Report whether an AMD convertible is in laptop or tablet mode using the
operating-mode sensor provided by the Sensor Fusion Hub, and expose it
to userspace as SW_TABLET_MODE, so userspace can react to the device
being folded into tablet posture.
Cc: Helge Bahmann <hcb@chaoticmind.net>
Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
---
MAINTAINERS | 1 +
drivers/input/misc/Kconfig | 15 +++++
drivers/input/misc/Makefile | 1 +
drivers/input/misc/amd_sfh_tabletmode.c | 81 +++++++++++++++++++++++++
4 files changed, 98 insertions(+)
create mode 100644 drivers/input/misc/amd_sfh_tabletmode.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 5114e6db7307..30b429eb9286 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1301,6 +1301,7 @@ L: linux-input@vger.kernel.org
S: Maintained
F: Documentation/hid/amd-sfh*
F: drivers/hid/amd-sfh-hid/
+F: drivers/input/misc/amd_sfh_tabletmode.c
AMD SPI DRIVER
M: Raju Rangoju <Raju.Rangoju@amd.com>
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 1f6c57dba030..5b76be31f687 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -899,6 +899,21 @@ config INPUT_SOC_BUTTON_ARRAY
To compile this driver as a module, choose M here: the
module will be called soc_button_array.
+config INPUT_AMD_SFH_TABLETMODE
+ tristate "AMD SFH tablet-mode switch"
+ depends on AMD_SFH_HID
+ select AUXILIARY_BUS
+ help
+ Expose SW_TABLET_MODE for AMD convertible laptops whose
+ operation-mode sensor is provided by the AMD Sensor Fusion Hub.
+
+ Userspace components such as systemd-logind and modern desktop
+ environments react to SW_TABLET_MODE when the device is folded
+ into tablet posture.
+
+ To compile this driver as a module, choose M here: the module
+ will be called amd_sfh_tabletmode.
+
config INPUT_DRV260X_HAPTICS
tristate "TI DRV260X haptics support"
depends on INPUT && I2C
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 2281d6803fce..72aa0658ebb3 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -81,6 +81,7 @@ obj-$(CONFIG_INPUT_RK805_PWRKEY) += rk805-pwrkey.o
obj-$(CONFIG_INPUT_SC27XX_VIBRA) += sc27xx-vibra.o
obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o
obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY) += soc_button_array.o
+obj-$(CONFIG_INPUT_AMD_SFH_TABLETMODE) += amd_sfh_tabletmode.o
obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o
obj-$(CONFIG_INPUT_STPMIC1_ONKEY) += stpmic1_onkey.o
obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON) += tps65218-pwrbutton.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..3931a1c6eb74
--- /dev/null
+++ b/drivers/input/misc/amd_sfh_tabletmode.c
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * AMD SFH tablet-mode switch driver
+ *
+ * Copyright (c) 2026, Advanced Micro Devices, Inc.
+ * All Rights Reserved.
+ *
+ * Author: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
+ */
+
+#include <linux/amd-pmf-io.h>
+#include <linux/auxiliary_bus.h>
+#include <linux/input.h>
+#include <linux/module.h>
+#include <linux/pci_ids.h>
+
+#define POLL_INTERVAL_MS 200
+
+static void sfh_tm_poll(struct input_dev *input)
+{
+ struct amd_sfh_info info = {};
+
+ if (amd_get_sfh_info(&info, MT_OP_MODE))
+ return;
+
+ input_report_switch(input, SW_TABLET_MODE,
+ info.op_mode == SFH_MODE_TABLET);
+ input_sync(input);
+}
+
+static int sfh_tm_probe(struct auxiliary_device *auxdev,
+ const struct auxiliary_device_id *id)
+{
+ struct device *dev = &auxdev->dev;
+ struct amd_sfh_info info = {};
+ struct input_dev *input;
+ int error;
+
+ error = amd_get_sfh_info(&info, MT_OP_MODE);
+ if (error)
+ return error == -EINVAL ? -ENODEV : error;
+
+ input = devm_input_allocate_device(dev);
+ if (!input)
+ return -ENOMEM;
+
+ input->name = "AMD SFH tablet mode switch";
+ input->phys = "amd-sfh/tabletmode";
+ input->id.bustype = BUS_HOST;
+ input->id.vendor = PCI_VENDOR_ID_AMD;
+ input_set_capability(input, EV_SW, SW_TABLET_MODE);
+
+ error = input_setup_polling(input, sfh_tm_poll);
+ if (error)
+ return error;
+ input_set_poll_interval(input, POLL_INTERVAL_MS);
+
+ sfh_tm_poll(input);
+
+ error = input_register_device(input);
+ if (error)
+ return error;
+
+ return 0;
+}
+
+static const struct auxiliary_device_id sfh_tm_id_table[] = {
+ { .name = "amd_sfh.tabletmode" },
+ {}
+};
+MODULE_DEVICE_TABLE(auxiliary, sfh_tm_id_table);
+
+static struct auxiliary_driver sfh_tm_driver = {
+ .name = "tabletmode",
+ .id_table = sfh_tm_id_table,
+ .probe = sfh_tm_probe,
+};
+module_auxiliary_driver(sfh_tm_driver);
+
+MODULE_DESCRIPTION("AMD SFH tablet mode switch");
+MODULE_LICENSE("GPL");
--
2.34.1
next prev parent reply other threads:[~2026-08-03 14:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 14:57 [PATCH v2 0/5] Add SW_TABLET_MODE support for AMD SFH convertibles Basavaraj Natikar
2026-08-03 14:57 ` [PATCH v2 1/5] HID: amd_sfh: Track MP2 version explicitly Basavaraj Natikar
2026-08-03 14:57 ` [PATCH v2 2/5] HID: amd_sfh: Serialize access to the shared emp2 pointer Basavaraj Natikar
2026-08-03 14:57 ` [PATCH v2 3/5] HID: amd_sfh: Add accessor to read the operating-mode sensor Basavaraj Natikar
2026-08-03 14:58 ` [PATCH v2 4/5] HID: amd_sfh: Register tablet-mode auxiliary device Basavaraj Natikar
2026-08-03 15:16 ` sashiko-bot
2026-08-03 14:58 ` Basavaraj Natikar [this message]
2026-08-03 16:18 ` [PATCH v2 5/5] Input: misc: Add AMD SFH tablet-mode switch driver Dmitry Torokhov
2026-08-03 17:42 ` Basavaraj Natikar
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=20260803145801.3801862-6-Basavaraj.Natikar@amd.com \
--to=basavaraj.natikar@amd.com \
--cc=bentiss@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=hcb@chaoticmind.net \
--cc=jikos@kernel.org \
--cc=linux-input@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.