HID: amd_sfh: operating-mode telemetry sysfs and report fixes
Subsystems (3)
Basavaraj Natikar
maintainerv2 cover HID: amd_sfh: operating-mode telemetry sysfs and report fixes
This series extends the amd-sfh sysfs interface with operating-mode telemetry and fixes two HID report handling issues.
Patch 1 moves the existing sysfs attribute handling into a dedicated file in preparation for adding more attributes (no functional change).
Patch 2 exposes the operating-mode telemetry reported by the SRA sensor (in-bag, out-of-bag, on-table, hinge angle, lid status and device mode) as read-only sysfs attributes.
Patch 3 removes an unsupported motion-state field from the accelerometer HID report descriptor that the hardware never populates, which caused hid-core to drop every accelerometer input report.
Patch 4 passes the requested report type to HID core. This prevents ALS feature reports from being parsed as input reports and fixes the "Event data for report 4 was too short (18 vs 14)" warning.
Changes in v2:
- Add a fix for feature reports being sent to HID core as input reports.
Basavaraj Natikar (4):
HID: amd_sfh: Move sysfs attributes to a separate file
HID: amd_sfh: Add operating-mode telemetry sysfs attributes
HID: amd_sfh: Remove unsupported motion-state field from accelerometer
report
HID: amd_sfh: Use report type from request node
.../ABI/testing/sysfs-driver-amd-sfh | 60 ++++++++ MAINTAINERS | 1 + drivers/hid/amd-sfh-hid/Makefile | 1 + drivers/hid/amd-sfh-hid/amd_sfh_client.c | 4 +- drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 55 +------ drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c | 134 ++++++++++++++++++ drivers/hid/amd-sfh-hid/amd_sfh_sysfs.h | 19 +++ .../hid_descriptor/amd_sfh_hid_desc.h | 2 - .../hid_descriptor/amd_sfh_hid_report_desc.h | 7 - 9 files changed, 219 insertions(+), 64 deletions(-) create mode 100644 drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c create mode 100644 drivers/hid/amd-sfh-hid/amd_sfh_sysfs.h
Signature · 1 line
2.34.1
Basavaraj Natikar
maintainerPATCH v2 1/4 HID: amd_sfh: Move sysfs attributes to a separate file
The sysfs attribute handling is defined in amd_sfh_pcie.c along with the PCIe transport code. More attributes will be added and the same handling is useful across SFH versions.
Therefore, move the attribute definitions, the visibility callback and the group update helper into a dedicated amd_sfh_sysfs.c file.
No functional change intended.
--- drivers/hid/amd-sfh-hid/Makefile | 1 + drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 55 +------------------ drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c | 73 +++++++++++++++++++++++++ drivers/hid/amd-sfh-hid/amd_sfh_sysfs.h | 19 +++++++ 4 files changed, 95 insertions(+), 53 deletions(-) create mode 100644 drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c create mode 100644 drivers/hid/amd-sfh-hid/amd_sfh_sysfs.h
drivers/hid/amd-sfh-hid/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_AMD_SFH_HID) += amd_sfh.o amd_sfh-objs := amd_sfh_hid.o amd_sfh-objs += amd_sfh_client.o amd_sfh-objs += amd_sfh_pcie.o +amd_sfh-objs += amd_sfh_sysfs.o amd_sfh-objs += hid_descriptor/amd_sfh_hid_desc.o amd_sfh-objs += sfh1_1/amd_sfh_init.o amd_sfh-objs += sfh1_1/amd_sfh_interface.o
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +2 -53
75 lines not on this page · raw message
drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c new file +73 -0
73 lines not on this page · raw message
drivers/hid/amd-sfh-hid/amd_sfh_sysfs.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* AMD SFH sysfs attributes +* +* Copyright (c) 2026, Advanced Micro Devices, Inc. +* All Rights Reserved. +* +* Author: Basavaraj Natikar <[email protected]> +*/ +#ifndef AMD_SFH_SYSFS_H +#define AMD_SFH_SYSFS_H + +#include "amd_sfh_common.h" + +extern const struct attribute_group *amd_sfh_groups[]; + +int amd_sfh_update_sysfs (struct amd_mp2_dev *mp2); + +#endif
Signature · 1 line
2.34.1
Basavaraj Natikar
maintainerPATCH v2 2/4 HID: amd_sfh: Add operating-mode telemetry sysfs attributes
In reply to Basavaraj NatikarThe 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.
--- .../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(-)
Documentation/ABI/testing/sysfs-driver-amd-sfh +60 -0
@@ -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: [email protected] +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: [email protected] +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: [email protected] +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: [email protected] +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: [email protected] +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: [email protected] +Description: + Operating-mode telemetry reported by the SRA sensor that + reports the platform/device mode. + + Access: Read only + Valid values: unsigned integer
MAINTAINERS +1 -0
@@ -1331,6 +1331,7 @@ AMD SENSOR FUSION HUB DRIVER M: Basavaraj Natikar <[email protected]> L: [email protected] 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
drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c +62 -1
93 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH -next v2 2/4] HID: amd_sfh: Add operating-mode telemetry sysfs attributes
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] hid: non-atomic copy into mismatched struct for SRA data - [Low] hid: build failure due to…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] hid: non-atomic copy into mismatched struct for SRA data
- [Low] hid: build failure due to non-existent c2p3_data member
--
commit ee7fce24f1e5a01f6f7e6e6cd19e09582b434ae4
Author: Basavaraj Natikar <[email protected]>
HID: amd_sfh: Add operating-mode telemetry sysfs attributes
The Sensor Fusion Hub reports additional operating-mode telemetry through the SRA sensor. This commit exposes these states read-only through sysfs so that userspace can consume them.
Quoted 4 lines
drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c +0
-0
[ ... ]
Quoted 8 lines
drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c +4
-0@@ -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;
drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c static ssize_t hpd_store(struct device *dev, · line 59
Quoted 10 lines
drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c +10
-0+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 ));
[Severity: Medium]
Does amd_sfh_read_op_mode() perform a multi-byte, non-atomic bulk I/O copy from shared hardware memory using the wrong struct type (accelerometer instead of SRA)?
Reading any of the new SRA telemetry sysfs attributes on a device with MP2 version >= 1.2 could risk torn reads from concurrent hardware updates.
Could a targeted, atomic readl() be used instead to read the single 32-bit register value?
drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c static ssize_t hpd_store(struct device *dev, · line 60
Quoted 1 line
drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c +1
-0+ mode->val = accel_data.c2p3_data;
[Severity: Low]
Does struct sfh_accel_data have a c2p3_data member?
It appears this member does not exist, which causes an immediate compilation failure when compiling the amd_sfh module.
Quoted 6 lines
drivers/hid/amd-sfh-hid/amd_sfh_sysfs.c +6
-0+ }else { + mode->val =readl (mp2->mmio +amd_get_c2p_val (mp2,3 )); + } + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Basavaraj Natikar
maintainerPATCH v2 3/4 HID: amd_sfh: Remove unsupported motion-state field from accelerometer report
In reply to Basavaraj NatikarThe accelerometer HID report descriptor declares a trailing motion-state field (usage 0x0451), but the Sensor Fusion Hub never reports this data, so each accelerometer input report is one byte shorter than the descriptor advertises.
This was previously harmless because hid-core zero-padded short reports. Since commit 0a3fe972a7cb ("HID: core: Mitigate potential OOB by removing bogus memset()") such reports are rejected instead:
hid-sensor-hub 0020:1022:0001.0003: Event data for report 1 was too short (15 vs 14)
As a result the accelerometer input events are dropped and screen auto-rotation stops working on AMD SFH systems.
Remove the motion-state field from the accelerometer report descriptor and drop the unused in_accel_shake_detection member, so the descriptor matches the report actually provided by the hardware.
--- drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.h | 2 -- .../amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_desc.h | 7 ------- 2 files changed, 9 deletions(-)
drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.h +0 -2
@@ -48,8 +48,6 @@ struct accel3_input_report {int in_accel_x_value;int in_accel_y_value;int in_accel_z_value; -/* include if required to support the "shake" event */ -u8 in_accel_shake_detection; } __packed;struct gyro_feature_report {
drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_desc.h +0 -7
@@ -169,13 +169,6 @@ static const u8 accel3_report_descriptor[] = {0x95 ,1 ,/* HID report count (1) */ 0x55 ,0x0E ,/* HID unit exponent(0x0E) */ 0X81 ,0x02 ,/* HID Input (Data_Arr_Abs) */ - -0x0A ,0x51 ,0x04 ,/* HID usage sensor data motion state */ -0x15 ,0 ,/* HID logical Min_8(0) False = Still*/ -0x25 ,1 ,/* HID logical Min_8(1) True = In motion */ -0x75 ,8 ,/* HID report size(8) */ -0x95 ,1 ,/* HID report count (1) */ -0X81 ,0x02 ,/* HID Input (Data_Arr_Abs) */ 0xC0 /* HID end collection */ };
Signature · 1 line
2.34.1
Basavaraj Natikar
maintainerPATCH v2 4/4 HID: amd_sfh: Use report type from request node
In reply to Basavaraj NatikarUse report type from request node while sending feature and input reports to HID core. The cli_data report type array is never assigned and feature reports are sent as input reports.
--- drivers/hid/amd-sfh-hid/amd_sfh_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/amd-sfh-hid/amd_sfh_client.c +2 -2
@@ -95,7 +95,7 @@ void amd_sfh_work(struct work_struct *work) cli_data->feature_report[current_index]);if (report_size)hid_input_report (cli_data->hid_sensor_hubs[current_index], - cli_data->report_type[current_index], + node_type, cli_data->feature_report[current_index], report_size,0 );else pr_err ("AMDSFH: Invalid report size\n" );
@@ -104,7 +104,7 @@ void amd_sfh_work(struct work_struct *work) report_size = mp2_ops->get_in_rep (current_index, sensor_index, report_id, in_data);if (report_size)hid_input_report (cli_data->hid_sensor_hubs[current_index], - cli_data->report_type[current_index], + node_type, in_data->input_report[current_index], report_size,0 );else pr_err ("AMDSFH: Invalid report size\n" );
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH -next v2 4/4] HID: amd_sfh: Use report type from request node
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] amd_sfh: incomplete cleanup of report_type array in amdtp_cl_data --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] amd_sfh: incomplete cleanup of report_type array in amdtp_cl_data --
commit 8029dfd0564b3015a23fe39f335b6a6e8b4706ba
Author: Basavaraj Natikar <[email protected]>
HID: amd_sfh: Use report type from request node
Use report type from request node while sending feature and input reports to HID core. The cli_data report type array is never assigned and feature reports are sent as input reports.
drivers/hid/amd-sfh-hid/amd_sfh_client.c void amd_sfh_work(struct work_struct *work) · line 98
Quoted 10 lines
drivers/hid/amd-sfh-hid/amd_sfh_client.c +1
-1@@ -95,7 +95,7 @@ void amd_sfh_work(struct work_struct *work) cli_data->feature_report[current_index]);if (report_size) hid_input_report(cli_data->hid_sensor_hubs[current_index], - cli_data->report_type[current_index], + node_type,
[Severity: Low]
This isn't a bug, but since this patch removes the usage of the report_type array, should its declaration also be removed from struct amdtp_cl_data?
drivers/hid/amd-sfh-hid/amd_sfh_hid.h:amdtp_cl_data {
...
u32 sensor_requested_cnt[MAX_HID_DEVICES];
u8 report_type[MAX_HID_DEVICES];
u8 report_id[MAX_HID_DEVICES];
...
};Leaving the declaration wastes a small amount of memory and adds clutter as dead code.
Quoted 3 lines
drivers/hid/amd-sfh-hid/amd_sfh_client.c +0
-0cli_data->feature_report[current_index], report_size, 0); else pr_err("AMDSFH: Invalid report size\n");
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Quoted 14 lines · Basavaraj Natikar
This series extends the amd-sfh sysfs interface with operating-mode telemetry and fixes two HID report handling issues.
Patch 1 moves the existing sysfs attribute handling into a dedicated file in preparation for adding more attributes (no functional change).
Patch 2 exposes the operating-mode telemetry reported by the SRA sensor (in-bag, out-of-bag, on-table, hinge angle, lid status and device mode) as read-only sysfs attributes.
Patch 3 removes an unsupported motion-state field from the accelerometer HID report descriptor that the hardware never populates, which caused hid-core to drop every accelerometer input report.
Quoted 6 lines
Patch 4 passes the requested report type to HID core. This prevents ALS feature reports from being parsed as input reports and fixes the "Event data for report 4 was too short (18 vs 14)" warning.
Changes in v2:
- Add a fix for feature reports being sent to HID core as input reports.
Applied to hid.git#for-7.4/amd_sfh, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs