[PATCH -next v2 2/4] HID: amd_sfh: Add operating-mode telemetry sysfs attributes
flat view
WARM1d
From: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
Date: 2026-10-06 10:38:29
Subsystem:
amd sensor fusion hub driver, hid core layer, the rest · Maintainers:
Basavaraj Natikar, Jiri Kosina, Benjamin Tissoires, Linus Torvalds
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