]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/tests: hdmi: Add max TMDS rate fallback tests for YUV420 mode
authorCristian Ciocaltea <cristian.ciocaltea@collabora.com>
Tue, 27 May 2025 12:11:26 +0000 (15:11 +0300)
committerMaxime Ripard <mripard@kernel.org>
Mon, 2 Jun 2025 09:02:39 +0000 (11:02 +0200)
Provide tests to verify drm_atomic_helper_connector_hdmi_check() helper
fallback behavior when using YUV420 output format.

Acked-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
Link: https://lore.kernel.org/r/20250527-hdmi-conn-yuv-v5-18-74c9c4a8ac0c@collabora.com
Signed-off-by: Maxime Ripard <mripard@kernel.org>
drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c

index c6f7c33f5f7142d6ee80970f73e9757fbc08b3d5..d98fb9803b46902016747f3fc9701eacd493d473 100644 (file)
@@ -1309,6 +1309,80 @@ static void drm_test_check_max_tmds_rate_bpc_fallback_rgb(struct kunit *test)
        drm_modeset_acquire_fini(&ctx);
 }
 
+/*
+ * Test that if:
+ * - We have an HDMI connector and a display supporting both RGB and YUV420
+ * - The chosen mode can be supported in YUV420 output format only
+ * - The chosen mode has a TMDS character rate higher than the display
+ *   supports in YUV420/12bpc
+ * - The chosen mode has a TMDS character rate lower than the display
+ *   supports in YUV420/10bpc.
+ *
+ * Then we will pick the latter, and the computed TMDS character rate
+ * will be equal to 1.25 * 0.5 times the mode pixel clock.
+ */
+static void drm_test_check_max_tmds_rate_bpc_fallback_yuv420(struct kunit *test)
+{
+       struct drm_atomic_helper_connector_hdmi_priv *priv;
+       struct drm_modeset_acquire_ctx ctx;
+       struct drm_connector_state *conn_state;
+       struct drm_display_info *info;
+       struct drm_display_mode *yuv420_only_mode;
+       unsigned long long rate;
+       struct drm_connector *conn;
+       struct drm_device *drm;
+       struct drm_crtc *crtc;
+       int ret;
+
+       priv = drm_kunit_helper_connector_hdmi_init_with_edid_funcs(test,
+                               BIT(HDMI_COLORSPACE_RGB) |
+                               BIT(HDMI_COLORSPACE_YUV420),
+                               12,
+                               &dummy_connector_hdmi_funcs,
+                               test_edid_hdmi_1080p_rgb_yuv_4k_yuv420_dc_max_200mhz);
+       KUNIT_ASSERT_NOT_NULL(test, priv);
+
+       drm = &priv->drm;
+       crtc = priv->crtc;
+       conn = &priv->connector;
+       info = &conn->display_info;
+       KUNIT_ASSERT_TRUE(test, info->is_hdmi);
+       KUNIT_ASSERT_GT(test, info->max_tmds_clock, 0);
+       KUNIT_ASSERT_TRUE(test, conn->ycbcr_420_allowed);
+
+       yuv420_only_mode = drm_kunit_display_mode_from_cea_vic(test, drm, 95);
+       KUNIT_ASSERT_NOT_NULL(test, yuv420_only_mode);
+       KUNIT_ASSERT_TRUE(test, drm_mode_is_420_only(info, yuv420_only_mode));
+
+       rate = drm_hdmi_compute_mode_clock(yuv420_only_mode, 12, HDMI_COLORSPACE_YUV420);
+       KUNIT_ASSERT_GT(test, rate, info->max_tmds_clock * 1000);
+
+       rate = drm_hdmi_compute_mode_clock(yuv420_only_mode, 10, HDMI_COLORSPACE_YUV420);
+       KUNIT_ASSERT_LT(test, rate, info->max_tmds_clock * 1000);
+
+       drm_modeset_acquire_init(&ctx, 0);
+
+retry_conn_enable:
+       ret = drm_kunit_helper_enable_crtc_connector(test, drm, crtc, conn,
+                                                    yuv420_only_mode, &ctx);
+       if (ret == -EDEADLK) {
+               ret = drm_modeset_backoff(&ctx);
+               if (!ret)
+                       goto retry_conn_enable;
+       }
+       KUNIT_EXPECT_EQ(test, ret, 0);
+
+       conn_state = conn->state;
+       KUNIT_ASSERT_NOT_NULL(test, conn_state);
+
+       KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_bpc, 10);
+       KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_format, HDMI_COLORSPACE_YUV420);
+       KUNIT_EXPECT_EQ(test, conn_state->hdmi.tmds_char_rate, yuv420_only_mode->clock * 625);
+
+       drm_modeset_drop_locks(&ctx);
+       drm_modeset_acquire_fini(&ctx);
+}
+
 /*
  * Test that if:
  * - We have an HDMI connector supporting both RGB and YUV422 and up to
@@ -1382,6 +1456,84 @@ static void drm_test_check_max_tmds_rate_bpc_fallback_ignore_yuv422(struct kunit
        drm_modeset_acquire_fini(&ctx);
 }
 
+/*
+ * Test that if:
+ * - We have an HDMI connector supporting both RGB and YUV420 and up to
+ *   12 bpc
+ * - The chosen mode has a TMDS character rate higher than the display
+ *   supports in RGB/10bpc but lower than the display supports in
+ *   RGB/8bpc
+ * - The chosen mode has a TMDS character rate lower than the display
+ *   supports in YUV420/12bpc.
+ *
+ * Then we will prefer to keep the RGB format with a lower bpc over
+ * picking YUV420.
+ */
+static void drm_test_check_max_tmds_rate_bpc_fallback_ignore_yuv420(struct kunit *test)
+{
+       struct drm_atomic_helper_connector_hdmi_priv *priv;
+       struct drm_modeset_acquire_ctx ctx;
+       struct drm_connector_state *conn_state;
+       struct drm_display_info *info;
+       struct drm_display_mode *preferred;
+       unsigned long long rate;
+       struct drm_connector *conn;
+       struct drm_device *drm;
+       struct drm_crtc *crtc;
+       int ret;
+
+       priv = drm_kunit_helper_connector_hdmi_init_with_edid_funcs(test,
+                               BIT(HDMI_COLORSPACE_RGB) |
+                               BIT(HDMI_COLORSPACE_YUV420),
+                               12,
+                               &dummy_connector_hdmi_funcs,
+                               test_edid_hdmi_4k_rgb_yuv420_dc_max_340mhz);
+       KUNIT_ASSERT_NOT_NULL(test, priv);
+
+       drm = &priv->drm;
+       crtc = priv->crtc;
+       conn = &priv->connector;
+       info = &conn->display_info;
+       KUNIT_ASSERT_TRUE(test, info->is_hdmi);
+       KUNIT_ASSERT_GT(test, info->max_tmds_clock, 0);
+       KUNIT_ASSERT_TRUE(test, conn->ycbcr_420_allowed);
+
+       preferred = find_preferred_mode(conn);
+       KUNIT_ASSERT_NOT_NULL(test, preferred);
+       KUNIT_ASSERT_FALSE(test, preferred->flags & DRM_MODE_FLAG_DBLCLK);
+       KUNIT_ASSERT_TRUE(test, drm_mode_is_420_also(info, preferred));
+
+       rate = drm_hdmi_compute_mode_clock(preferred, 8, HDMI_COLORSPACE_RGB);
+       KUNIT_ASSERT_LT(test, rate, info->max_tmds_clock * 1000);
+
+       rate = drm_hdmi_compute_mode_clock(preferred, 10, HDMI_COLORSPACE_RGB);
+       KUNIT_ASSERT_GT(test, rate, info->max_tmds_clock * 1000);
+
+       rate = drm_hdmi_compute_mode_clock(preferred, 12, HDMI_COLORSPACE_YUV420);
+       KUNIT_ASSERT_LT(test, rate, info->max_tmds_clock * 1000);
+
+       drm_modeset_acquire_init(&ctx, 0);
+
+retry_conn_enable:
+       ret = drm_kunit_helper_enable_crtc_connector(test, drm, crtc, conn,
+                                                    preferred, &ctx);
+       if (ret == -EDEADLK) {
+               ret = drm_modeset_backoff(&ctx);
+               if (!ret)
+                       goto retry_conn_enable;
+       }
+       KUNIT_EXPECT_EQ(test, ret, 0);
+
+       conn_state = conn->state;
+       KUNIT_ASSERT_NOT_NULL(test, conn_state);
+
+       KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_bpc, 8);
+       KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_format, HDMI_COLORSPACE_RGB);
+
+       drm_modeset_drop_locks(&ctx);
+       drm_modeset_acquire_fini(&ctx);
+}
+
 /*
  * Test that if a driver and screen supports RGB and YUV formats, and we
  * try to set the VIC 1 mode, we end up with 8bpc RGB even if we could
@@ -1775,7 +1927,9 @@ static struct kunit_case drm_atomic_helper_connector_hdmi_check_tests[] = {
        KUNIT_CASE(drm_test_check_disable_connector),
        KUNIT_CASE(drm_test_check_hdmi_funcs_reject_rate),
        KUNIT_CASE(drm_test_check_max_tmds_rate_bpc_fallback_rgb),
+       KUNIT_CASE(drm_test_check_max_tmds_rate_bpc_fallback_yuv420),
        KUNIT_CASE(drm_test_check_max_tmds_rate_bpc_fallback_ignore_yuv422),
+       KUNIT_CASE(drm_test_check_max_tmds_rate_bpc_fallback_ignore_yuv420),
        KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_changed),
        KUNIT_CASE(drm_test_check_output_bpc_crtc_mode_not_changed),
        KUNIT_CASE(drm_test_check_output_bpc_dvi),