diff --git a/drivers/soc/apple/rtkit-helper.c b/drivers/soc/apple/rtkit-helper.c index 7c4521ef6783b..8c518ef4349e9 100644 --- a/drivers/soc/apple/rtkit-helper.c +++ b/drivers/soc/apple/rtkit-helper.c @@ -44,6 +44,8 @@ struct apple_rtkit_helper { bool ap_idle; /* It was told, gave no answer, and wasn't told otherwise. */ bool idle_unanswered; + /* An idle notice that still had no answer when its sleep ended. */ + bool idle_pending; /* Ends a sleep whose .prepare failed, which gets no .complete. */ struct notifier_block pm_nb; @@ -414,6 +416,25 @@ static int apple_rtkit_helper_ap_idle(struct apple_rtkit_helper *helper) if (helper->ap_idle) return 0; + /* + * A firmware that never answered the last idle notice still holds it: T8142's MTP + * asserts on a second ("Invalid AP power") and takes the keyboard and trackpad with + * it. Refuse this sleep instead, unless the answer has come since; then the AP on + * the last sleep's end skipped goes first. + */ + if (helper->idle_pending) { + if (apple_rtkit_is_running(helper->rtk)) { + dev_err(helper->dev, "the last AP idle notice is still unanswered: no sleep\n"); + return -EBUSY; + } + helper->idle_pending = false; + dev_info(helper->dev, "the last AP idle notice was answered late, sending AP on first\n"); + if (apple_rtkit_ap_power(helper->rtk, true)) { + dev_err(helper->dev, "AP on after the late answer not answered: no sleep\n"); + helper->idle_pending = true; + return -EBUSY; + } + } ret = apple_rtkit_helper_ap_power(helper, false); if (ret) return ret; @@ -452,6 +473,8 @@ static void apple_rtkit_helper_sleep_end(struct apple_rtkit_helper *helper) late ? "its answer came late, sending AP on" : "still no answer, nothing sent"); helper->ap_idle = late; + /* Its answer may still come: the next sleep looks again before sending another. */ + helper->idle_pending = !late; } apple_rtkit_helper_ap_on(helper); } diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 63fe4ed39057a..8230ebe11d411 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -1832,8 +1832,14 @@ static struct apple_rtkit *__apple_rtkit_init(struct device *dev, void *cookie, rtk->handshake_timeout_ms = APPLE_RTKIT_HANDSHAKE_TIMEOUT_MS; rtk->sync_syslog_ack = of_property_read_bool(dev->of_node, "apple,sync-syslog-ack"); - /* As macOS does; a driver whose firmware shouldn't get them turns it off. */ - rtk->oslog_echo = of_machine_is_compatible("apple,t8140"); + /* + * As macOS does; a driver whose firmware shouldn't get them turns it off. T8142 too: + * its MTP left a counter unechoed after the first sleep's resume, then took no AP + * idle notice for the next one (J815, -ETIME at prepare) and asserted on the one + * after ("Invalid AP power"). + */ + rtk->oslog_echo = of_machine_is_compatible("apple,t8140") || + of_machine_is_compatible("apple,t8142"); INIT_KFIFO(rtk->sync_ack_fifo); INIT_WORK(&rtk->sync_ack_work, apple_rtkit_sync_ack_work);