From: John Iliopoulos On cold boot on some AMD Renoir/Lucienne platforms (observed on HP ENVY x360 Convertible 15-eu0xxx with BIOS F.18, MP2 PCI ID 1022:15e4), AMD_P2C_MSG(0) is 0x00000000 and AMD_P2C_MSG(1) has discovery status 0 (0x10055803) when amd_sfh probes. Sending the first ENABLE_SENSOR command transitions AMD_P2C_MSG(1) to discovery status 3 (0x1005581b) within ~2 ms, but MP2 leaves AMD_P2C_MSG(0) at 0x00000000 for the full 10-second timeout until a second C2P doorbell arrives. When the next sensor's ENABLE_SENSOR command is sent after the timeout, MP2 completes both the first sensor (~733 ms later) and the second sensor (~734 ms later). This affects whichever sensor is enabled first (normally accelerometer, sid 0x0), causing amd_sfh to mark it SENSOR_DISABLED after 10 seconds and skip registering accel_3d, breaking automatic screen rotation until the module is reloaded. When waiting for SENSOR_ENABLED while AMD_P2C_MSG(0) was zero prior to the command, split the 10-second timeout into an initial 2-second poll followed by a single re-write of AMD_C2P_MSG0 and an 8-second poll if AMD_P2C_MSG(0) is still zero. Systems that respond normally within 2 seconds see no behavioral change, and the overall 10-second maximum timeout is preserved. Fixes: 173709f50e98 ("HID: amd_sfh: Add command response to check command status") Cc: stable@vger.kernel.org Signed-off-by: John Iliopoulos --- drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c index a2ddd1b5b1e5..8eb001963d46 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c @@ -46,6 +46,7 @@ MODULE_PARM_DESC(intr_disable, "override the interrupt disable sensor bit"); #define AMD_SFH_POLL_INTERVAL_US 50 #define AMD_SFH_COMPANION_WAIT_US 50000 +#define AMD_SFH_COLD_RETRY_US 2000000 #define AMD_SFH_RESP_TIMEOUT_US 10000000 static bool amd_sfh_resp_v2_matches(union cmd_response resp, u8 sid, u32 sensor_sts) @@ -68,15 +69,20 @@ static int amd_sfh_wait_response_v2(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_ { union cmd_response cmd_resp; u32 prev_p2c0 = mp2->prev_p2c0; + u32 timeout_us = AMD_SFH_RESP_TIMEOUT_US; + bool cold_boot = sensor_sts == SENSOR_ENABLED && !prev_p2c0; bool retried = false; for (;;) { + u32 poll_us = (!retried && cold_boot) ? + AMD_SFH_COLD_RETRY_US : timeout_us; + if (!readl_poll_timeout(mp2->mmio + AMD_P2C_MSG(0), cmd_resp.resp, amd_sfh_resp_v2_matches(cmd_resp, sid, sensor_sts) || (!retried && amd_sfh_resp_v2_is_companion(cmd_resp, prev_p2c0, sid, sensor_sts)), - AMD_SFH_POLL_INTERVAL_US, AMD_SFH_RESP_TIMEOUT_US)) { + AMD_SFH_POLL_INTERVAL_US, poll_us)) { if (amd_sfh_resp_v2_matches(cmd_resp, sid, sensor_sts)) return cmd_resp.response_v2.response; @@ -100,6 +106,25 @@ static int amd_sfh_wait_response_v2(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_ continue; } + /* + * On cold boot, some MP2 v2 firmwares latch the first ENABLE_SENSOR + * command without writing P2C_MSG0 until a second C2P doorbell arrives. + * Re-trigger once if P2C_MSG0 is still zero after the initial wait, + * then poll for the remainder of the overall timeout. + */ + if (!retried && cold_boot) { + if (cmd_resp.resp == 0) { + dev_dbg(&mp2->pdev->dev, + "sid 0x%x cold-boot command stalled, retrying\n", + sid); + writel(readl(mp2->mmio + AMD_C2P_MSG0), + mp2->mmio + AMD_C2P_MSG0); + } + retried = true; + timeout_us -= poll_us; + continue; + } + break; } -- 2.56.1