diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 50bcff5415ed..6a1d06e1e68e 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -5187,9 +5187,42 @@ static void dcp_v27_dptx_layout(struct apple_dcp *dcp) DPTX_CONTROLLER_ENDPOINT, DPTX_ENDPOINT); } +/* + * A boot stage that handed this DCP over running (dcp-live-v1) left the port's + * display up on a link it trained. Release it, so that the next connect trains + * the link and reads the sink again: until then the firmware only has its + * default modes and no EDID. Its HPD goes low as well; dcp_dptx_connect() + * raises it again, so that the firmware sees the display plugged. + */ +static void dcp_release_adopted_dptx(struct apple_dcp *dcp) +{ + int ret; + + ret = dptxport_set_hpd(dcp->dptxport[0].service, false); + if (!ret) + ret = dptxport_release_display(dcp->dptxport[0].service); + if (ret) + dev_warn(dcp->dev, "adopted DPTX display not released: %d\n", ret); +} + +/* + * Whether that release waits until IOMFB has started. A Type-C output (a USB-C + * connector in the device tree, or a Type-C route already bound) needs it after + * iomfb_start_rtkit(): released before, the firmware never sees the disconnect + * over IOMFB, and on the next Type-C connect it trains the link and reads the + * sink but never sends the connect hotplug. A fixed HDMI or DisplayPort output + * releases it before iomfb_start_rtkit(): released after, some boots never + * display a swap, so the boot scanout is never retired. + */ +static bool dcp_adopted_release_after_iomfb(struct apple_dcp *dcp) +{ + return dcp_is_typec_output(dcp); +} + int dcp_start(struct platform_device *pdev) { struct apple_dcp *dcp = platform_get_drvdata(pdev); + bool release_after_iomfb; int ret; if (iomfb_is_m4(dcp)) { @@ -5231,6 +5264,8 @@ int dcp_start(struct platform_device *pdev) if (dcp_is_ext26(dcp)) return dcp_ext26_start_services(dcp); dcp_v27_dptx_layout(dcp); + /* Read once: a route binding while IOMFB starts must not skip both releases. */ + release_after_iomfb = dcp_adopted_release_after_iomfb(dcp); /* Make the H17P allocator available before external service discovery. */ if (dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17P_EXTERNAL) { @@ -5272,6 +5307,9 @@ int dcp_start(struct platform_device *pdev) if (ret) { dev_warn(dcp->dev, "Failed to start DPTX endpoint: %d\n", ret); + } else if (dcp->rtkit_adopted && !release_after_iomfb && + dptx_service_available(&dcp->dptxport[0])) { + dcp_release_adopted_dptx(dcp); #ifdef DCP_DPTX_DISCONNECT_ON_INIT /* * This disconnect / connect cycle on init is only necessary @@ -5306,24 +5344,9 @@ int dcp_start(struct platform_device *pdev) return ret; } - if (dcp->rtkit_adopted && dptx_service_available(&dcp->dptxport[0])) { - /* - * The boot stage that handed this DCP over left the port's - * display up on a link it trained. Release it after IOMFB is - * up so firmware observes the disconnect and delivers the - * connect hotplug on the next connect, which trains the link - * and reads the sink again. Its HPD goes low as well; - * dcp_dptx_connect() raises it again, so that the firmware - * sees the display plugged. - */ - ret = dptxport_set_hpd(dcp->dptxport[0].service, false); - if (!ret) - ret = dptxport_release_display(dcp->dptxport[0].service); - if (ret) - dev_warn(dcp->dev, "adopted DPTX display not released: %d\n", - ret); - ret = 0; - } + if (dcp->rtkit_adopted && release_after_iomfb && + dptx_service_available(&dcp->dptxport[0])) + dcp_release_adopted_dptx(dcp); /* On the board they have run on; elsewhere these endpoints are not started, as before. */ if (dcp->v27_j714s && !dcp->external && dcp_has_panel(dcp)) { diff --git a/drivers/gpu/drm/apple/dcp_handoff_test.c b/drivers/gpu/drm/apple/dcp_handoff_test.c index 72aecbc55e69..b1207d189744 100644 --- a/drivers/gpu/drm/apple/dcp_handoff_test.c +++ b/drivers/gpu/drm/apple/dcp_handoff_test.c @@ -140,10 +140,40 @@ static void dcp_handoff_live_rtkit_buf_valid(struct kunit *test) KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(1, U64_MAX - SZ_4K + 1, SZ_4K, 1)); } +/* + * Where dcp_start() releases a display handed over running: after + * iomfb_start_rtkit() only on a Type-C output, before it on a fixed port. + */ +static void dcp_handoff_adopted_release_order(struct kunit *test) +{ + struct apple_dcp_typec_route route = {}; + struct apple_dcp *dcp = kunit_kzalloc(test, sizeof(*dcp), GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, dcp); + + /* A USB-C connector (T8103 dcpext): after IOMFB has started. */ + dcp->fixed_connector_type = DRM_MODE_CONNECTOR_USB; + KUNIT_EXPECT_TRUE(test, dcp_adopted_release_after_iomfb(dcp)); + + /* A fixed HDMI or DP port wired to the DPTX PHY: before. */ + dcp->fixed_connector_type = DRM_MODE_CONNECTOR_HDMIA; + KUNIT_EXPECT_FALSE(test, dcp_adopted_release_after_iomfb(dcp)); + dcp->fixed_connector_type = DRM_MODE_CONNECTOR_DisplayPort; + KUNIT_EXPECT_FALSE(test, dcp_adopted_release_after_iomfb(dcp)); + dcp->fixed_connector_type = DRM_MODE_CONNECTOR_Unknown; + KUNIT_EXPECT_FALSE(test, dcp_adopted_release_after_iomfb(dcp)); + + /* A hybrid whose Type-C route is already bound: after. */ + dcp->fixed_connector_type = DRM_MODE_CONNECTOR_HDMIA; + dcp->active_typec_route = &route; + KUNIT_EXPECT_TRUE(test, dcp_adopted_release_after_iomfb(dcp)); +} + static struct kunit_case dcp_handoff_cases[] = { KUNIT_CASE(dcp_handoff_external_idle), KUNIT_CASE(dcp_handoff_boot_notch), KUNIT_CASE(dcp_handoff_live_rtkit_buf_valid), + KUNIT_CASE(dcp_handoff_adopted_release_order), {} };