Skip to content
Draft
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
83 changes: 83 additions & 0 deletions drivers/gpu/drm/apple/dcp-fabric.c
Original file line number Diff line number Diff line change
Expand Up @@ -1379,16 +1379,98 @@ static void dcp_hdmi_recheck_work(struct work_struct *work)

static void dcp_hybrid_work(struct work_struct *work);

/*
* The DP-to-HDMI converter draws about 0.6 W whenever it is powered, with or
* without a display. The connector's HPD reaches the SoC without it, so it is
* powered only while an HDMI display is attached, as macOS does.
*/
#define DCP_HDMI_CONVERTER_OFF_MS 10000

/* A converter whose power this driver holds, on a connector with its own HPD line. */
static bool dcp_hdmi_converter_managed(struct apple_dcp *dcp)
{
return dcp->dp2hdmi_pwren && dcp->hdmi_hpd_irq && !dcp->external_native;
}

/* True if the converter's power changed. */
static bool dcp_hdmi_converter_set(struct apple_dcp *dcp, bool on)
{
guard(mutex)(&dcp->hdmi_converter_lock);
if (dcp->hdmi_converter_on == on)
return false;
gpiod_set_value_cansleep(dcp->dp2hdmi_pwren, on);
dcp->hdmi_converter_on = on;
return true;
}

/*
* An HDMI display is about to be connected: power its converter if it was
* down. It needs a little over two seconds to boot, so the connect's wait
* for the link configuration runs out first. On this connector that is not
* an error: the port stays connected, and the firmware raises HPD once the
* converter answers.
*/
void dcp_fabric_hdmi_converter_wake(struct apple_dcp *dcp)
{
if (!dcp->dp2hdmi_pwren)
return;
if (dcp_hdmi_converter_set(dcp, true))
dev_info(dcp->dev, "HDMI: display attached, converter powered up\n");
/* A connect with no display there does not keep it powered. */
dcp_fabric_hdmi_converter_idle(dcp);
}

/* HPD was sampled: no display starts the power-down delay, a display ends it. */
void dcp_fabric_hdmi_converter_idle(struct apple_dcp *dcp)
{
if (!dcp_hdmi_converter_managed(dcp))
return;
/* A failed GPIO read cannot establish absence. */
if (gpiod_get_value_cansleep(dcp->hdmi_hpd) != 0)
cancel_delayed_work(&dcp->hdmi_converter_off_wq);
else if (READ_ONCE(dcp->hdmi_converter_on))
queue_delayed_work(system_freezable_wq, &dcp->hdmi_converter_off_wq,
msecs_to_jiffies(DCP_HDMI_CONVERTER_OFF_MS));
}

static void dcp_hdmi_converter_off_work(struct work_struct *work)
{
struct apple_dcp *dcp = container_of(to_delayed_work(work), struct apple_dcp,
hdmi_converter_off_wq);

guard(mutex)(&dcp_typec_fabric_lock);
if (!dcp_hdmi_converter_managed(dcp) ||
gpiod_get_value_cansleep(dcp->hdmi_hpd) != 0)
return;
/*
* The display has been gone for a while and the firmware has dropped
* its link, which it learns of through the converter. With the CRTC
* off nothing released the port then: do it now, and try again later
* if the firmware does not let go of it.
*/
if (!dcp->active_typec_route && dcp->dptxport[0].connected &&
dcp_dptx_disconnect(dcp, 0)) {
queue_delayed_work(system_freezable_wq, &dcp->hdmi_converter_off_wq,
msecs_to_jiffies(DCP_HDMI_CONVERTER_OFF_MS));
return;
}
if (dcp_hdmi_converter_set(dcp, false))
dev_info(dcp->dev, "HDMI: no display, converter powered down\n");
}

void dcp_fabric_init(struct apple_dcp *dcp)
{
spin_lock_init(&dcp->hdmi_presence_lock);
dcp->hdmi_presence.state = DCP_FABRIC_ABSENT;
dcp->hdmi_presence_prev = DCP_FABRIC_ABSENT;
INIT_DELAYED_WORK(&dcp->hdmi_settle_wq, dcp_hdmi_settle_work);
INIT_DELAYED_WORK(&dcp->hdmi_recheck_wq, dcp_hdmi_recheck_work);
mutex_init(&dcp->hdmi_converter_lock);
INIT_DELAYED_WORK(&dcp->hdmi_converter_off_wq, dcp_hdmi_converter_off_work);
INIT_DELAYED_WORK(&dcp->hybrid_wq, dcp_hybrid_work);
disable_delayed_work(&dcp->hdmi_settle_wq);
disable_delayed_work(&dcp->hdmi_recheck_wq);
disable_delayed_work(&dcp->hdmi_converter_off_wq);
disable_delayed_work(&dcp->hybrid_wq);
}

Expand Down Expand Up @@ -5866,6 +5948,7 @@ static void dcp_hdmi_update_locked(struct apple_dcp *dcp)
dcp_hdmi_sample(dcp, generation, level);
}
dcp_fabric_run_hdmi(&dcp_hdmi_ops, dcp);
dcp_fabric_hdmi_converter_idle(dcp);
}

irqreturn_t dcp_dp2hdmi_hpd(int irq, void *data)
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/apple/dcp-fabric.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ void dcp_fabric_hdmi_resume(struct apple_dcp *dcp);
void dcp_fabric_hdmi_reinit(struct apple_dcp *dcp, const char *why);
void dcp_fabric_hdmi_retry(struct apple_dcp *dcp);
void dcp_dp2hdmi_record_edge(struct apple_dcp *dcp);
void dcp_fabric_hdmi_converter_wake(struct apple_dcp *dcp);
void dcp_fabric_hdmi_converter_idle(struct apple_dcp *dcp);
irqreturn_t dcp_dp2hdmi_hpd_edge(int irq, void *data);
irqreturn_t dcp_dp2hdmi_hpd(int irq, void *data);
void dcp_fabric_shutdown_dptx(struct apple_dcp *dcp);
Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,10 @@ struct apple_dcp {
bool hdmi_edge_seen;
struct delayed_work hdmi_settle_wq;
struct delayed_work hdmi_recheck_wq;
/* The DP-to-HDMI converter is powered down while no display is attached. */
struct mutex hdmi_converter_lock;
struct delayed_work hdmi_converter_off_wq;
bool hdmi_converter_on;
/* T6030 HDMI converter service requests, see dcp-hdmi.c */
struct dcp_hdmi *hdmi;

Expand Down
9 changes: 9 additions & 0 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3575,6 +3575,10 @@ int dcp_dptx_connect(struct apple_dcp *dcp, u32 port)
if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP && !dcp_is_typec_output(dcp))
return dcp_desktop_dptx_connect(dcp, port);

/* The converter of the HDMI output is powered down while no display is attached. */
if (!dcp_is_typec_output(dcp))
dcp_fabric_hdmi_converter_wake(dcp);

if (!dcp_is_retained_external(dcp)) {
if (dcp_typec_sessionless(dcp)) {
ret = dcp_dptx_connect_raw(dcp, port, NULL, NULL, false, false);
Expand Down Expand Up @@ -5448,6 +5452,7 @@ static int dcp_enable_dp2hdmi_hpd(struct apple_dcp *dcp)

if (dcp->hdmi_hpd_irq)
dcp_fabric_run_resume(&dcp_resume_ops, dcp);
dcp_fabric_hdmi_converter_idle(dcp);

return 0;
}
Expand Down Expand Up @@ -6996,6 +7001,7 @@ VISIBLE_IF_KUNIT void dcp_disable_typec_work(struct apple_dcp *dcp, bool release
dcp->tb_event_generation = 0;
}
disable_delayed_work_sync(&dcp->hybrid_wq);
disable_delayed_work_sync(&dcp->hdmi_converter_off_wq);
}

VISIBLE_IF_KUNIT void dcp_enable_typec_work(struct apple_dcp *dcp)
Expand All @@ -7011,6 +7017,7 @@ VISIBLE_IF_KUNIT void dcp_enable_typec_work(struct apple_dcp *dcp)
enable_delayed_work(&dcp->link_recovery_wq);
enable_work(&dcp->tb_event_work);
enable_delayed_work(&dcp->hybrid_wq);
enable_delayed_work(&dcp->hdmi_converter_off_wq);
dcp_hdmi_enable(dcp);
scoped_guard(mutex, &dcp->hpd_mutex)
dcp->typec_work_enabled = true;
Expand Down Expand Up @@ -9022,6 +9029,7 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev)
}
if (IS_ERR(dcp->dp2hdmi_pwren))
return PTR_ERR(dcp->dp2hdmi_pwren);
dcp->hdmi_converter_on = !!dcp->dp2hdmi_pwren;
/* The converter rails must be stable before DCP requests the link. */
if ((fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP ||
(fw_compat == DCP_FIRMWARE_V_27_0 && dcp->desktop_external)) &&
Expand Down Expand Up @@ -11678,6 +11686,7 @@ static int dcp_platform_resume(struct device *dev)
/* Observe future edges before sampling any edges lost in sleep. */
if (dcp->hdmi_hpd_irq)
dcp_fabric_run_resume(&dcp_resume_ops, dcp);
dcp_fabric_hdmi_converter_idle(dcp);
if (dcp->external_native)
enable_work(&dcp->external_audio_work);

Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/apple/dcp_external_announce_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static struct announce_test *announce_test_init(struct kunit *test)
INIT_DELAYED_WORK(&dcp->hdmi_recheck_wq, announce_test_noop);
INIT_DELAYED_WORK(&dcp->link_recovery_wq, announce_test_noop);
INIT_DELAYED_WORK(&dcp->hybrid_wq, announce_test_noop);
INIT_DELAYED_WORK(&dcp->hdmi_converter_off_wq, announce_test_noop);
INIT_DELAYED_WORK(&dcp->bl_fallback_wq, announce_test_noop);
INIT_DELAYED_WORK(&dcp->backlight.fade_work, announce_test_noop);
INIT_DELAYED_WORK(&dcp->brightness.fade_work, announce_test_noop);
Expand Down
Loading