From b9f1df9aaff9de8179673398825498e70b9a6841 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:08:45 +1100 Subject: [PATCH 1/3] soc: apple: sleep: wait for the debug link's contract on a defined condition After the port controller's cold reset cuts the debug link, the sleep waits for the partner to renegotiate its contract. That wait was an mdelay(50) and then an mdelay(10) loop for up to 1.5 s. Whether the reset had been taken was inferred from seeing the contract gone (no answer, or no contract); a contract that never seemed to go counted as back only after a 1 s floor. The controller names the boot loader's debug link in its MODE register ("DBMa"), and only the cold reset ends that mode. Read MODE before each reset. Where it is the debug link's, the reset counts as taken once the controller has left that mode, so a quick reset is no longer held to the 1 s floor. A controller still waking reads zeros, which say nothing of its mode and are ignored. Where MODE reads anything else, the old test is used as before, floor included. One look at the controller is now a function polled with read_poll_timeout_atomic(). The look itself bounds the wait in wall time (1.5 s, as before): its SPMI commands take a while, and the atomic poll counts only its own delays. The 50 ms after the reset command, in which the controller still answers as before it, is named HPM_RESET_STALE_MS. The stale-read finding and the 50 ms first look are Diljit Singh's. Fixes: 2a57a36f5f28 ("soc: apple: sleep: look for the debug link's contract from 50 ms after its cut") Signed-off-by: Ryan Murray --- drivers/soc/apple/sleep.c | 116 ++++++++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 36 deletions(-) diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index ce1bcee755574..31b31e27b9e43 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -182,8 +182,16 @@ struct aura_s2r_mailbox { #define HPM_CMD_SSPS 0x53505353 #define HPM_CMD_COLD_RESET 0x64696147 #define HPM_SSPS_S3 3 -/* The first look after the reset, and how long a contract that never seemed to go is trusted to have gone. */ -#define HPM_RESET_FIRST_MS 50 +#define HPM_PAGE_MODE 0x03 +/* "DBMa" in MODE: the boot loader's debug link, which only the cold reset ends */ +#define HPM_MODE_DEBUG_LINK 0x614d4244 +/* + * For a moment after the reset command the controller still answers as before it, with its + * old contract; nothing read in that window tells whether the reset was taken. Then: how often + * it is looked at, and how long a contract that never seemed to go is trusted to have gone. + */ +#define HPM_RESET_STALE_MS 50 +#define HPM_CONTRACT_POLL_MS 10 #define HPM_RESET_FLOOR_MS 1000 #define HPM_PAGE_POWER_STATUS 0x3f #define HPM_POWER_CONNECTED BIT(0) @@ -3573,43 +3581,75 @@ static int sleep_hpm_sleep(struct apple_sleep *s) return ret; } +/* A port controller register: its page selected, then four bytes of the data window. */ +static int sleep_hpm_read(struct apple_sleep *s, u32 page, u32 *val) +{ + int ret = sleep_hpm_select(s, page); + + return ret ?: sleep_hpm_cmd(s, SPMI_OP_EXT_READ(4), HPM_REG_DATA, NULL, val); +} + +struct sleep_hpm_contract { + ktime_t start; + /* ms from the reset to the first look that saw it taken, or -1 */ + int gone_ms; + /* The last look had no answer: wake it first. */ + bool wake; + /* MODE read the debug link's before the reset. */ + bool debug_mode; +}; + +/* + * One look at the port controller after the reset: 1 once the partner's contract is back, 0 + * while not yet, -ETIMEDOUT after HPM_CONTRACT_MS. The reset counts as taken once the + * controller has left the debug link's mode, or had no answer or no contract (it restarts); a + * contract that never seemed to go counts as back only after HPM_RESET_FLOOR_MS. + */ +static int sleep_hpm_contract_back(struct apple_sleep *s, struct sleep_hpm_contract *c) +{ + int ms = ktime_ms_delta(ktime_get(), c->start); + u32 mode = HPM_MODE_DEBUG_LINK, val = 0; + bool up, taken; + int ret; + + if (ms >= HPM_CONTRACT_MS) + return -ETIMEDOUT; + ret = c->wake ? sleep_hpm_cmd(s, SPMI_OP_WAKEUP, 0, NULL, NULL) : 0; + if (!ret && c->debug_mode) + ret = sleep_hpm_read(s, HPM_PAGE_MODE, &mode); + if (!ret) + ret = sleep_hpm_read(s, HPM_PAGE_POWER_STATUS, &val); + up = !ret && (val & HPM_POWER_CONNECTED) && + FIELD_GET(HPM_POWER_TYPEC_MODE, val) == HPM_POWER_TYPEC_PD; + /* A controller still waking reads zeros: that says nothing of its mode. */ + taken = !up || (c->debug_mode && mode && mode != HPM_MODE_DEBUG_LINK); + if (taken && c->gone_ms < 0) + c->gone_ms = ms; + c->wake = ret; + + return up && (c->gone_ms >= 0 || ms >= HPM_RESET_FLOOR_MS); +} + /* * The partner takes the reset as an unplug, attaches again and renegotiates its contract. * Left to finish across the commit, that sometimes failed: neither side had a contract or * saw the other, and no VDM got through until a replug. Returns the ms it took. */ -static int sleep_hpm_wait_contract(struct apple_sleep *s, int *gone_ms) +static int sleep_hpm_wait_contract(struct apple_sleep *s, bool debug_mode, int *gone_ms) { - ktime_t start = ktime_get(); - bool wake = true, up; - u32 val = 0; - int ms, ret; + struct sleep_hpm_contract c = { + .start = ktime_get(), .gone_ms = -1, .wake = true, .debug_mode = debug_mode, + }; + int back, ret; - /* - * It reads back as before for a moment after the reset. Count it as back once it was - * seen gone (no contract, or no answer while the controller restarts), or after the - * floor if it never seemed to go. - */ - *gone_ms = -1; - mdelay(HPM_RESET_FIRST_MS); - for (;;) { - ms = ktime_ms_delta(ktime_get(), start); - if (ms >= HPM_CONTRACT_MS) - return -ETIMEDOUT; - ret = wake ? sleep_hpm_cmd(s, SPMI_OP_WAKEUP, 0, NULL, NULL) : 0; - if (!ret) - ret = sleep_hpm_select(s, HPM_PAGE_POWER_STATUS); - if (!ret) - ret = sleep_hpm_cmd(s, SPMI_OP_EXT_READ(4), HPM_REG_DATA, NULL, &val); - up = !ret && (val & HPM_POWER_CONNECTED) && - FIELD_GET(HPM_POWER_TYPEC_MODE, val) == HPM_POWER_TYPEC_PD; - if (!up && *gone_ms < 0) - *gone_ms = ms; - if (up && (*gone_ms >= 0 || ms >= HPM_RESET_FLOOR_MS)) - return ms; - wake = ret; - mdelay(10); - } + mdelay(HPM_RESET_STALE_MS); + /* The look itself bounds the wait in wall time: its SPMI commands take a while. */ + ret = read_poll_timeout_atomic(sleep_hpm_contract_back, back, back, + HPM_CONTRACT_POLL_MS * USEC_PER_MSEC, 0, false, s, &c); + *gone_ms = c.gone_ms; + if (ret || back < 0) + return ret ?: back; + return ktime_ms_delta(ktime_get(), c.start); } /* A live debug link holds the debug switch domain on. */ @@ -3629,7 +3669,8 @@ static bool sleep_debug_link_up(struct apple_sleep *s) static bool apple_sleep_usb_down(struct apple_sleep *s) { u32 cmd = HPM_CMD_COLD_RESET; - u32 enable; + u32 enable, mode = 0; + bool debug_mode; int i, ret, ms, gone; if (s->usb_down_ran) @@ -3645,6 +3686,9 @@ static bool apple_sleep_usb_down(struct apple_sleep *s) /* A reset that the partner doesn't come back from is done again. */ for (i = 1; i <= HPM_RESET_TRIES; i++) { ret = sleep_hpm_cmd(s, SPMI_OP_WAKEUP, 0, NULL, NULL); + /* Where it is in the debug link's mode, leaving that mode is the reset taken. */ + debug_mode = !ret && !sleep_hpm_read(s, HPM_PAGE_MODE, &mode) && + mode == HPM_MODE_DEBUG_LINK; if (!ret) ret = sleep_hpm_select(s, HPM_PAGE_CMD1); if (!ret) @@ -3652,10 +3696,10 @@ static bool apple_sleep_usb_down(struct apple_sleep *s) if (ret) break; WRITE_ONCE(sleep_debug_link_cut, true); - ms = sleep_hpm_wait_contract(s, &gone); + ms = sleep_hpm_wait_contract(s, debug_mode, &gone); if (ms >= 0) { - dev_info(s->dev, "debug link: contract back %d ms after reset %d (gone at %d ms)\n", - ms, i, gone); + dev_info(s->dev, "debug link: contract back %d ms after reset %d (gone at %d ms%s)\n", + ms, i, gone, debug_mode ? ", mode" : ""); break; } dev_warn(s->dev, "debug link: no contract with the partner after reset %d\n", i); From 86fea1a5fa5c7ca78a825c09a83697ab8ab31eb5 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:09:42 +1100 Subject: [PATCH 2/3] soc: apple: clpc: say why the GPU floor hold is a time APPLE_CLPC_GPU_BACKOFF_MS keeps the GPU floor released for 100 ms after the PMP last limited the DCS. It reads as a fixed delay standing in for an event, so say why it is not one: the PMP's limit is its vote in the PMC floor word, a register it rewrites with no interrupt or message to the AP, and under heavy work that vote goes back to the top between limits. Only sampling sees it; the hold is hysteresis on that sample. No functional change. Signed-off-by: Ryan Murray --- drivers/soc/apple/clpc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/soc/apple/clpc.c b/drivers/soc/apple/clpc.c index e257fefa310fa..39c836f437a25 100644 --- a/drivers/soc/apple/clpc.c +++ b/drivers/soc/apple/clpc.c @@ -64,6 +64,12 @@ enum apple_clpc_rail { * sustained heavy rendering the PMP limits the DCS again well within this, so * the floor stays released; light submissions that follow get the floor back * this long after the PMP stops limiting. + * + * This is hysteresis, not a wait for an event: the PMP's limit is its vote in + * the PMC floor word, a register it rewrites with no interrupt or message to + * the AP, and under heavy work it goes back to the top between limits. Only + * sampling sees it, so the floor follows the vote with this hold, measured on + * T8140 (51350a0d5022). */ #define APPLE_CLPC_GPU_BACKOFF_MS 100 /* Package power readings in the low-power profile: every 100 ms */ From 076609612dcb8bf7272f934a2e19c62bce4ef5ba Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 5 Dec 2026 12:37:04 +1100 Subject: [PATCH 3/3] drm/apple: restore main's T6031 refresh-rate change dropped by the merge The previous merge of main recorded 7b10eb104ce6 as its parent but kept the tree of the merge with the main before it, which dropped #4379 (T6031 fixed refresh rates) from dcp.c, iomfb.c and dcp-firmware-test.c. Take those three files as main has them; nothing else changes. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-firmware-test.c | 11 +++++++++++ drivers/gpu/drm/apple/dcp.c | 3 +-- drivers/gpu/drm/apple/iomfb.c | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-firmware-test.c b/drivers/gpu/drm/apple/dcp-firmware-test.c index 57b950fa07ddc..23ba452ddafe4 100644 --- a/drivers/gpu/drm/apple/dcp-firmware-test.c +++ b/drivers/gpu/drm/apple/dcp-firmware-test.c @@ -374,6 +374,17 @@ static void dcp_firmware_27_t6030_boot_rate(struct kunit *test) KUNIT_ASSERT_NOT_NULL(test, hw); KUNIT_EXPECT_FALSE(test, hw->only_120hz_modes); + /* T6031 exposes all fixed ProMotion rates after the 5-window ADT layout fix. */ + { + static const char t6031[] = "apple,t6031-dcp"; + + compatible.length = sizeof(t6031); + compatible.value = (void *)t6031; + hw = of_device_get_match_data(&dev); + KUNIT_ASSERT_NOT_NULL(test, hw); + KUNIT_EXPECT_FALSE(test, hw->only_120hz_modes); + } + /* The catalogue is the test's. */ dcp->modes = NULL; dcp->nr_modes = 0; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index dd2e73d25110f..410f1c8bc1e7a 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -13864,7 +13864,7 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t6030 = { /* Firmware 27.2's sleep: only with the DT's sleep arguments and display power words */ .v27_early_stop = true, .s2r_layout = &dcp_s2r_t6030, - /* Firmware 27: the boot timing only, as on T6050 and T6031, see dcp_mode_settable(). */ + /* Firmware 27: the boot timing only, as on T6050, see dcp_mode_settable(). */ .only_120hz_modes = true, /* Firmware 27.2 panel path decodes ST 2084 with sRGB*100 saturation (#4171). */ .no_fw27_panel_pq = true, @@ -13885,7 +13885,6 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t6031 = { .iboot_handoff = "apple,t6031-handoff", .num_dptx_ports = 1, .afk_name_fallback = true, - .only_120hz_modes = true, }; static const struct apple_dcp_hw_data apple_dcp_hw_t6030_dcpext = { diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 0198d12adff2e..91f084aa2e28b 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -4728,7 +4728,7 @@ static bool dcp_mode_settable(struct apple_dcp *dcp, return dcp_mode->mode.type & DRM_MODE_TYPE_PREFERRED; /* - * The T6050 (M5 Max, K114s) and firmware-27 T6031 (M3 Max) internal + * The T6050 (M5 Max, K114s) and firmware-27 T6030 (M3 Pro) internal * DCPs crash on a mode set away from the timing iBoot left the panel * at: 120 -> 60 Hz, and 60 -> 120 Hz when macOS left it at 60 Hz. * Offer only the rate the firmware reported at start