From: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
To: <jikos@kernel.org>, <bentiss@kernel.org>
Cc: <linux-input@vger.kernel.org>,
Basavaraj Natikar <Basavaraj.Natikar@amd.com>
Subject: [PATCH -next v2 2/4] HID: amd_sfh: Add operating-mode telemetry sysfs attributes
Date: Tue, 6 Oct 2026 16:07:52 +0530 [thread overview]
Message-ID: <20261006103754.3614316-3-Basavaraj.Natikar@amd.com> (raw)
In-Reply-To: <20261006103754.3614316-1-Basavaraj.Natikar@amd.com>
The Sensor Fusion Hub reports additional operating-mode telemetry
through the SRA sensor, such as in-bag and out-of-bag detection,
on-table or on-lap placement, hinge angle, lid status and the platform
device mode.
Expose these states read-only through sysfs so that userspace can
consume them. The attributes are visible only on SFH 1.1 or greater when
the SRA sensor is present.
Signed-off-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
---
.../ABI/testing/sysfs-driver-amd-sfh | 60 ++++++++++++++++++
MAINTAINERS | 1 +
drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c | 63 ++++++++++++++++++-
3 files changed, 123 insertions(+), 1 deletion(-)
diff --git a/Documentation/ABI/testing/sysfs-driver-amd-sfh b/Documentation/ABI/testing/sysfs-driver-amd-sfh
index c053126a83bb..15abd994e9ee 100644
--- a/Documentation/ABI/testing/sysfs-driver-amd-sfh
+++ b/Documentation/ABI/testing/sysfs-driver-amd-sfh
@@ -11,3 +11,63 @@ Description:
Access: Read/Write
Valid values: enabled/disabled
+
+What: /sys/bus/pci/drivers/pcie_mp2_amd/*/in_bag_state
+Date: August 2026
+Contact: Basavaraj.Natikar@amd.com
+Description:
+ Operating-mode telemetry reported by the SRA sensor that
+ indicates whether the device is detected inside a bag.
+
+ Access: Read only
+ Valid values: unsigned integer
+
+What: /sys/bus/pci/drivers/pcie_mp2_amd/*/out_bag_state
+Date: August 2026
+Contact: Basavaraj.Natikar@amd.com
+Description:
+ Operating-mode telemetry reported by the SRA sensor that
+ indicates whether the device is detected outside a bag.
+
+ Access: Read only
+ Valid values: unsigned integer
+
+What: /sys/bus/pci/drivers/pcie_mp2_amd/*/on_table_state
+Date: August 2026
+Contact: Basavaraj.Natikar@amd.com
+Description:
+ Operating-mode telemetry reported by the SRA sensor that
+ indicates whether the device is placed on a table or on a lap.
+
+ Access: Read only
+ Valid values: unsigned integer
+
+What: /sys/bus/pci/drivers/pcie_mp2_amd/*/hinge_angle
+Date: August 2026
+Contact: Basavaraj.Natikar@amd.com
+Description:
+ Operating-mode telemetry reported by the SRA sensor that
+ reports the hinge angle of the device in degrees.
+
+ Access: Read only
+ Valid values: unsigned integer (degrees)
+
+What: /sys/bus/pci/drivers/pcie_mp2_amd/*/lid_status
+Date: August 2026
+Contact: Basavaraj.Natikar@amd.com
+Description:
+ Operating-mode telemetry reported by the SRA sensor that
+ indicates whether the device lid is open or closed.
+
+ Access: Read only
+ Valid values: unsigned integer
+
+What: /sys/bus/pci/drivers/pcie_mp2_amd/*/device_mode
+Date: August 2026
+Contact: Basavaraj.Natikar@amd.com
+Description:
+ Operating-mode telemetry reported by the SRA sensor that
+ reports the platform/device mode.
+
+ Access: Read only
+ Valid values: unsigned integer
diff --git a/MAINTAINERS b/MAINTAINERS
index 5c57cbb68060..ad3477693db5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1331,6 +1331,7 @@ AMD SENSOR FUSION HUB DRIVER
M: Basavaraj Natikar <basavaraj.natikar@amd.com>
L: linux-input@vger.kernel.org
S: Maintained
+F: Documentation/ABI/testing/sysfs-driver-amd-sfh
F: Documentation/hid/amd-sfh*
F: drivers/hid/amd-sfh-hid/
F: drivers/input/misc/amd_sfh_tabletmode.c
diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c b/drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c
index db1cc205d25b..8af4df09760f 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c
@@ -8,6 +8,7 @@
* Author: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
*/
#include <linux/device.h>
+#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/string_choices.h>
#include <linux/sysfs.h>
@@ -15,6 +16,7 @@
#include "amd_sfh_common.h"
#include "amd_sfh_sysfs.h"
#include "sfh1_1/amd_sfh_init.h"
+#include "sfh1_1/amd_sfh_interface.h"
static ssize_t hpd_show(struct device *dev, struct device_attribute *attr, char *buf)
{
@@ -41,19 +43,78 @@ static ssize_t hpd_store(struct device *dev,
}
static DEVICE_ATTR_RW(hpd);
+/* Operating-mode telemetry reported by the SRA sensor, exposed read-only. */
+static int amd_sfh_read_op_mode(struct amd_mp2_dev *mp2, struct sfh_op_mode *mode)
+{
+ struct sfh_accel_data accel_data;
+ void __iomem *sensoraddr;
+
+ if (!mp2->sfh1_1_ops || !mp2->dev_en.is_sra_present)
+ return -ENODEV;
+
+ if (mp2->mp2_ver >= MP2_VER_1_2) {
+ sensoraddr = mp2->vsbase +
+ (SRA_IDX * SENSOR_DATA_MEM_SIZE_DEFAULT) +
+ OFFSET_SENSOR_DATA_DEFAULT;
+ memcpy_fromio(&accel_data, sensoraddr, sizeof(struct sfh_accel_data));
+ mode->val = accel_data.c2p3_data;
+ } else {
+ mode->val = readl(mp2->mmio + amd_get_c2p_val(mp2, 3));
+ }
+
+ return 0;
+}
+
+#define SFH_OP_MODE_ATTR(_name, _field) \
+static ssize_t _name##_show(struct device *dev, \
+ struct device_attribute *attr, char *buf) \
+{ \
+ struct amd_mp2_dev *mp2 = dev_get_drvdata(dev); \
+ struct sfh_op_mode mode; \
+ int ret; \
+ \
+ ret = amd_sfh_read_op_mode(mp2, &mode); \
+ if (ret) \
+ return ret; \
+ \
+ return sysfs_emit(buf, "%u\n", mode.op_mode._field); \
+} \
+static DEVICE_ATTR_RO(_name)
+
+SFH_OP_MODE_ATTR(in_bag_state, inbagstate);
+SFH_OP_MODE_ATTR(out_bag_state, outbagstate);
+SFH_OP_MODE_ATTR(on_table_state, ontablestate);
+SFH_OP_MODE_ATTR(hinge_angle, angle);
+SFH_OP_MODE_ATTR(lid_status, lidstatus);
+SFH_OP_MODE_ATTR(device_mode, devicemode);
+
static umode_t sfh_attr_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
{
struct device *dev = kobj_to_dev(kobj);
struct amd_mp2_dev *mp2 = dev_get_drvdata(dev);
- if (!mp2->sfh1_1_ops || !mp2->dev_en.is_hpd_present)
+ if (!mp2->sfh1_1_ops)
+ return 0;
+
+ if (attr == &dev_attr_hpd.attr) {
+ if (!mp2->dev_en.is_hpd_present)
+ return 0;
+ } else if (!mp2->dev_en.is_sra_present) {
+ /* operating-mode telemetry requires the SRA sensor */
return 0;
+ }
return attr->mode;
}
static struct attribute *sfh_attrs[] = {
&dev_attr_hpd.attr,
+ &dev_attr_in_bag_state.attr,
+ &dev_attr_out_bag_state.attr,
+ &dev_attr_on_table_state.attr,
+ &dev_attr_hinge_angle.attr,
+ &dev_attr_lid_status.attr,
+ &dev_attr_device_mode.attr,
NULL,
};
--
2.34.1
next prev parent reply other threads:[~2026-10-06 10:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 10:37 [PATCH -next v2 0/4] HID: amd_sfh: operating-mode telemetry sysfs and report fixes Basavaraj Natikar
2026-10-06 10:37 ` [PATCH -next v2 1/4] HID: amd_sfh: Move sysfs attributes to a separate file Basavaraj Natikar
2026-10-06 10:37 ` Basavaraj Natikar [this message]
2026-10-06 10:50 ` [PATCH -next v2 2/4] HID: amd_sfh: Add operating-mode telemetry sysfs attributes sashiko-bot
2026-10-06 10:37 ` [PATCH -next v2 3/4] HID: amd_sfh: Remove unsupported motion-state field from accelerometer report Basavaraj Natikar
2026-10-06 10:37 ` [PATCH -next v2 4/4] HID: amd_sfh: Use report type from request node Basavaraj Natikar
2026-10-06 10:51 ` sashiko-bot
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=20261006103754.3614316-3-Basavaraj.Natikar@amd.com \
--to=basavaraj.natikar@amd.com \
--cc=bentiss@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox