Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions drivers/soc/apple/rtkit-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 8 additions & 2 deletions drivers/soc/apple/rtkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading