HID: amd_sfh: Add operating-mode telemetry sysfs attributes

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>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
This commit is contained in:
Basavaraj Natikar 2026-10-06 16:07:52 +05:30 committed by Jiri Kosina
parent a06165477d
commit 912f942b3b
3 changed files with 123 additions and 1 deletions

View File

@ -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

View File

@ -1322,6 +1322,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

View File

@ -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,
};