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
1 change: 1 addition & 0 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ struct apple_dcp {
bool sleep_v27_unhandled;
bool s2r_active;
bool s2r_stopped;
bool s2r_hdmi_irq_disabled;
/* DPMS off stopped the firmware and lowered the domains; DPMS on brings them back. */
bool dpms_powered_off;
/* Refused its idle with the display off: the firmware still runs, the display is dark. */
Expand Down
86 changes: 76 additions & 10 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4932,20 +4932,43 @@ static const struct dcp_fabric_resume_ops dcp_resume_ops = {
.sample = dcp_resume_sample,
};

/*
* Sample fixed-HDMI HPD and reconnect DPTX port 0 (or power off / report
* unplug when no sink is present). Shared by initial bring-up and deep sleep
* recovery.
*/
static void dcp_fixed_hdmi_reconnect(struct apple_dcp *dcp, bool poweroff_unplugged)
{
bool connected;
int ret;

if (dcp_is_typec_output(dcp) || !dcp->hdmi_hpd ||
READ_ONCE(dcp->active_typec_route))
return;

/* Check HPD before enabling the edge-triggered IRQ. */
connected = gpiod_get_value_cansleep(dcp->hdmi_hpd);
dev_info(dcp->dev, "%s: DP2HDMI HPD connected:%d\n", __func__, connected);

if (connected && !READ_ONCE(dcp->hdmi_yielded)) {
ret = dcp_dptx_connect(dcp, 0);
if (ret)
dev_warn(dcp->dev, "HDMI DPTX connect failed: %d\n", ret);
} else if (!connected) {
if (poweroff_unplugged)
_dcp_poweroff(dcp);
else if (dcp->connector)
disconnected_hpd_event(dcp->connector);
}
}

static int dcp_enable_dp2hdmi_hpd(struct apple_dcp *dcp)
{
if (dcp_is_typec_output(dcp)) {
if (READ_ONCE(dcp->typec_cable_connected))
dcp_dptx_connect(dcp, 0);
} else if (dcp->hdmi_hpd) {
/* Check HPD before enabling the edge-triggered IRQ. */
bool connected = gpiod_get_value_cansleep(dcp->hdmi_hpd);
dev_info(dcp->dev, "%s: DP2HDMI HPD connected:%d\n", __func__, connected);

if (connected && !READ_ONCE(dcp->hdmi_yielded))
dcp_dptx_connect(dcp, 0);
else if (!connected)
_dcp_poweroff(dcp);
} else {
dcp_fixed_hdmi_reconnect(dcp, true);
}

if (dcp->hdmi_hpd_irq)
Expand Down Expand Up @@ -8686,11 +8709,28 @@ static int dcp_s2r_stop_crashed(struct apple_dcp *dcp)
return 0;
}

static void dcp_s2r_hdmi_irq_disable(struct apple_dcp *dcp)
{
if (dcp->hdmi_hpd_irq && !dcp->s2r_hdmi_irq_disabled) {
disable_irq(dcp->hdmi_hpd_irq);
dcp->s2r_hdmi_irq_disabled = true;
}
}

static void dcp_s2r_hdmi_irq_enable(struct apple_dcp *dcp)
{
if (dcp->hdmi_hpd_irq && dcp->s2r_hdmi_irq_disabled) {
dcp->s2r_hdmi_irq_disabled = false;
dcp_fabric_run_resume(&dcp_resume_ops, dcp);
}
}

static int dcp_s2r_ext_suspend(struct apple_dcp *dcp)
{
int ret;

if (READ_ONCE(dcp->s2r_fw_down)) {
dcp_s2r_hdmi_irq_disable(dcp);
dcp_s2r_stop_failed_start(dcp);
dcp_s2r_find_darts(dcp);
dcp->s2r_stopped = true;
Expand All @@ -8705,9 +8745,15 @@ static int dcp_s2r_ext_suspend(struct apple_dcp *dcp)
return 0;
}

/* No A500 and no disconnect: the link and its crossbar output just go down. */
/*
* No A500 and no disconnect: the link and its crossbar output just go down.
* If dcp_s2r_stop_crashed() fails, it calls dcp_s2r_restart_failed_stop(),
* which re-enables hdmi_hpd_irq on a clean restart or leaves it disabled
* while the firmware stays crashed.
*/
if (dcp_s2r_stops_crashed(dcp)) {
dcp_disable_typec_work(dcp, false);
dcp_s2r_hdmi_irq_disable(dcp);
dcp_typec_route_park(dcp);
return dcp_s2r_stop_crashed(dcp);
}
Expand All @@ -8718,9 +8764,11 @@ static int dcp_s2r_ext_suspend(struct apple_dcp *dcp)
dev_dbg(dcp->dev, "a display is attached: released for the sleep, connected again after it\n");

dcp_disable_typec_work(dcp, false);
dcp_s2r_hdmi_irq_disable(dcp);
ret = dcp_external_disconnect(dcp, false);
if (ret) {
dcp_enable_typec_work(dcp);
dcp_s2r_hdmi_irq_enable(dcp);
return ret;
}

Expand All @@ -8730,6 +8778,7 @@ static int dcp_s2r_ext_suspend(struct apple_dcp *dcp)
if (iomfb_queue_settle(dcp, msecs_to_jiffies(500))) {
iomfb_pause_presentation(dcp, false);
dcp_enable_typec_work(dcp);
dcp_s2r_hdmi_irq_enable(dcp);
dev_err(dcp->dev, "display updates still pending, refusing sleep\n");
return -EBUSY;
}
Expand All @@ -8742,6 +8791,7 @@ static int dcp_s2r_ext_suspend(struct apple_dcp *dcp)
dev_err(dcp->dev, "no reply to A500: %d\n", ret);
WRITE_ONCE(dcp->crashed, true);
dcp_typec_route_unpark(dcp);
/* Keep typec work and hdmi_hpd_irq disabled while firmware is crashed. */
return ret == -ETIMEDOUT ? -EBUSY : ret;
}
usleep_range(4000, 5000);
Expand All @@ -8753,6 +8803,7 @@ static int dcp_s2r_ext_suspend(struct apple_dcp *dcp)
readl(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_STATUS));
WRITE_ONCE(dcp->crashed, true);
dcp_typec_route_unpark(dcp);
/* Keep typec work and hdmi_hpd_irq disabled while firmware is crashed. */
return ret == -ETIMEDOUT ? -EBUSY : ret;
}

Expand Down Expand Up @@ -9272,6 +9323,7 @@ static void dcp_s2r_restart_done(struct apple_dcp *dcp, int ret)
dcp_typec_route_unpark(dcp);
if (ret) {
WRITE_ONCE(dcp->crashed, true);
/* Firmware stays stopped/crashed, so hdmi_hpd_irq intentionally stays disabled. */
dev_warn(dcp->dev, "firmware stopped for sleep, display stays off until reboot\n");
return;
}
Expand All @@ -9281,6 +9333,20 @@ static void dcp_s2r_restart_done(struct apple_dcp *dcp, int ret)
iomfb_pause_presentation(dcp, false);
if (ext && !READ_ONCE(dcp->typec_work_enabled))
dcp_enable_typec_work(dcp);
if (ext && !dcp_is_typec_output(dcp) && dcp->hdmi_hpd &&
!READ_ONCE(dcp->active_typec_route)) {
if (dcp->external_native) {
dcp_fabric_hdmi_reinit(dcp, "after deep sleep");
} else {
if (dcp->hdmi_pwren)
gpiod_set_value_cansleep(dcp->hdmi_pwren, 1);
if (dcp->dp2hdmi_pwren)
gpiod_set_value_cansleep(dcp->dp2hdmi_pwren, 1);
}
dcp_fixed_hdmi_reconnect(dcp, false);
}
if (ext)
dcp_s2r_hdmi_irq_enable(dcp);
}

/*
Expand Down
Loading