Skip to contentSkip to conversation

Adjust behavior for HPD sensor

PATCH In review Mario Limonciello 2 participants 5 messages Feb 28, 2025 – Mar 4, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Adjust behavior for HPD sensor

From: Mario Limonciello <[email protected]>

Some platforms include a human presence detection (HPD) sensor. When enabled and a user is detected a wake event will be emitted from the sensor fusion hub that software can react to.

Example use cases are "wake from suspend on approach" or to "lock when leaving".

This is currently enabled by default on supported systems, but users can't control it. This essentially means that wake on approach is enabled which is a really surprising behavior to users that don't expect it.

Instead of defaulting to enabled add a sysfs knob that users can use to enable the feature if desirable and set it to disabled by default.

Cc Pratap Nirujogi <[email protected]>
Cc Anson Tsao <[email protected]>

Mario Limonciello (3):
HID: amd_sfh: Allow configuring whether HPD is enabled or disabled
HID: amd_sfh: Default to HPD disabled
HID: amd_sfh: Don't show wrong status for amd_sfh_hpd_info()

 .../ABI/testing/sysfs-driver-amd-sfh          | 13 +++++
 drivers/hid/amd-sfh-hid/amd_sfh_common.h      |  1 +
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c        | 58 +++++++++++++++++++
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c | 50 +++++++++++++++-
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.h |  3 +
 .../amd-sfh-hid/sfh1_1/amd_sfh_interface.c    |  2 +-
 6 files changed, 124 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-amd-sfh
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/3 HID: amd_sfh: Allow configuring whether HPD is enabled or disabled

From: Mario Limonciello <[email protected]>

Human presence detection (HPD) sensor uses a camera to determine when user is physically in front of the machine. This might not be a desirable behavior because it can (for example) cause the machine to wake on approach.

Add a new sysfs file "hpd" that will control whether this sensor is enabled. Use the value of this sysfs file to turn off HPD and prevent it from re-enabling after resume from suspend.

---
 .../ABI/testing/sysfs-driver-amd-sfh          | 13 +++++
 drivers/hid/amd-sfh-hid/amd_sfh_common.h      |  1 +
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c        | 58 +++++++++++++++++++
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c | 49 +++++++++++++++-
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.h |  3 +
 5 files changed, 122 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-amd-sfh
Documentation/ABI/testing/sysfs-driver-amd-sfh new file +13 -0
new file mode 100644
index 0000000000000..c053126a83bb3
@@ -0,0 +1,13 @@
+What:		/sys/bus/pci/drivers/pcie_mp2_amd/*/hpd
+Date:		April 2025
+Contact:	[email protected]
+Description:
+		Human presence detection (HPD) enable/disable.
+		When HPD is enabled, the device will be able to detect the
+		presence of a human and will send an interrupt that can be
+		used to wake the system from a low power state.
+		When HPD is disabled, the device will not be able to detect
+		the presence of a human.
+
+		Access: Read/Write
+		Valid values: enabled/disabled
drivers/hid/amd-sfh-hid/amd_sfh_common.h +1 -0
index 799b8686a88a4..f44a3bb2fbd4f 100644
@@ -42,6 +42,7 @@ struct amd_mp2_sensor_info {
 
 struct sfh_dev_status {
 	bool is_hpd_present;
+	bool is_hpd_enabled;
 	bool is_als_present;
 	bool is_sra_present;
 };
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +58 -0

82 lines not on this page · raw message

drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c +47 -2

73 lines not on this page · raw message

drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.h +3 -0
index 21c44990bbeba..797d206641c69 100644
@@ -15,12 +15,15 @@
 
 struct amd_sfh1_1_ops {
 	int (*init)(struct amd_mp2_dev *mp2);
+	void (*toggle_hpd)(struct amd_mp2_dev *mp2, bool enable);
 };
 
 int amd_sfh1_1_init(struct amd_mp2_dev *mp2);
+void amd_sfh_toggle_hpd(struct amd_mp2_dev *mp2, bool enabled);
 
 static const struct amd_sfh1_1_ops __maybe_unused sfh1_1_ops = {
 	.init = amd_sfh1_1_init,
+	.toggle_hpd = amd_sfh_toggle_hpd,
 };
 
 #endif
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/3 HID: amd_sfh: Default to HPD disabled

In reply to Mario Limonciello

From: Mario Limonciello <[email protected]>

Unless you know to look for it, HPD is a surprising behavior; particularly because it can wake the system from suspend. It also has implications for power consumption because sensors are left enabled.

After the sensors have been probed (and HPD is found present), explicitly turn off HPD by default. Userspace can manually turn it on if desirable.

---
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c +1 -0
index fc9c297d0db7f..25f0ebfcbd5f5 100644
@@ -213,6 +213,7 @@ static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev *privdata)
 			case HPD_IDX:
 				privdata->dev_en.is_hpd_present = true;
 				privdata->dev_en.is_hpd_enabled = true;
+				amd_sfh_toggle_hpd(privdata, false);
 				break;
 			case ALS_IDX:
 				privdata->dev_en.is_als_present = true;
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/3 HID: amd_sfh: Don't show wrong status for amd_sfh_hpd_info()

In reply to Mario Limonciello

From: Mario Limonciello <[email protected]>

When HPD is present but has been disabled, avoid reporting HPD status to PMF.

---
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c +1 -1
index ffb98b4c36cbd..837d59e7a6610 100644
@@ -129,7 +129,7 @@ static int amd_sfh_hpd_info(u8 *user_present)
 	if (!user_present)
 		return -EINVAL;
 
-	if (!emp2 || !emp2->dev_en.is_hpd_present)
+	if (!emp2 || !emp2->dev_en.is_hpd_present || !emp2->dev_en.is_hpd_enabled)
 		return -ENODEV;
 
 	hpdstatus.val = readl(emp2->mmio + amd_get_c2p_val(emp2, 4));
Signature · 1 line
2.43.0
maintainer
#4 lore raw
In reply to Mario Limonciello
Quoted 26 lines · Mario Limonciello

From: Mario Limonciello <[email protected]>

Some platforms include a human presence detection (HPD) sensor. When enabled and a user is detected a wake event will be emitted from the sensor fusion hub that software can react to.

Example use cases are "wake from suspend on approach" or to "lock when leaving".

This is currently enabled by default on supported systems, but users can't control it. This essentially means that wake on approach is enabled which is a really surprising behavior to users that don't expect it.

Instead of defaulting to enabled add a sysfs knob that users can use to enable the feature if desirable and set it to disabled by default.

Cc Pratap Nirujogi <[email protected]>
Cc Anson Tsao <[email protected]>

Mario Limonciello (3):
HID: amd_sfh: Allow configuring whether HPD is enabled or disabled
HID: amd_sfh: Default to HPD disabled
HID: amd_sfh: Don't show wrong status for amd_sfh_hpd_info()

Quoted 8 lines
 .../ABI/testing/sysfs-driver-amd-sfh          | 13 +++++
 drivers/hid/amd-sfh-hid/amd_sfh_common.h      |  1 +
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c        | 58 +++++++++++++++++++
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c | 50 +++++++++++++++-
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.h |  3 +
 .../amd-sfh-hid/sfh1_1/amd_sfh_interface.c    |  2 +-
 6 files changed, 124 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-amd-sfh

Now applied to hid.git#for-6.14/amd_sfh. Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs