]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/connector: hdmi: Add RGB Quantization Range to the connector state
authorMaxime Ripard <mripard@kernel.org>
Mon, 27 May 2024 13:58:09 +0000 (15:58 +0200)
committerMaxime Ripard <mripard@kernel.org>
Tue, 28 May 2024 08:24:38 +0000 (10:24 +0200)
HDMI controller drivers will need to figure out the RGB range they need
to configure based on a mode and property values. Let's expose that in
the HDMI connector state so drivers can just use that value.

Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240527-kms-hdmi-connector-state-v15-20-c5af16c3aae2@kernel.org
Signed-off-by: Maxime Ripard <mripard@kernel.org>
drivers/gpu/drm/display/drm_hdmi_state_helper.c
drivers/gpu/drm/drm_atomic.c
include/drm/drm_connector.h

index 57c66beec5bce57882f9f19e4b4964c3bf5d88f4..f18020cfe4ea72893da39713f4f0b822f311df3e 100644 (file)
@@ -51,6 +51,33 @@ connector_state_get_mode(const struct drm_connector_state *conn_state)
        return &crtc_state->mode;
 }
 
+static bool hdmi_is_limited_range(const struct drm_connector *connector,
+                                 const struct drm_connector_state *conn_state)
+{
+       const struct drm_display_info *info = &connector->display_info;
+       const struct drm_display_mode *mode =
+               connector_state_get_mode(conn_state);
+
+       /*
+        * The Broadcast RGB property only applies to RGB format, and
+        * i915 just assumes limited range for YCbCr output, so let's
+        * just do the same.
+        */
+       if (conn_state->hdmi.output_format != HDMI_COLORSPACE_RGB)
+               return true;
+
+       if (conn_state->hdmi.broadcast_rgb == DRM_HDMI_BROADCAST_RGB_FULL)
+               return false;
+
+       if (conn_state->hdmi.broadcast_rgb == DRM_HDMI_BROADCAST_RGB_LIMITED)
+               return true;
+
+       if (!info->is_hdmi)
+               return false;
+
+       return drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_LIMITED;
+}
+
 static bool
 sink_supports_format_bpc(const struct drm_connector *connector,
                         const struct drm_display_info *info,
@@ -329,6 +356,8 @@ int drm_atomic_helper_connector_hdmi_check(struct drm_connector *connector,
                connector_state_get_mode(new_conn_state);
        int ret;
 
+       new_conn_state->hdmi.is_limited_range = hdmi_is_limited_range(connector, new_conn_state);
+
        ret = hdmi_compute_config(connector, new_conn_state, mode);
        if (ret)
                return ret;
index 3e57d98d841836117e3e369fc37d139736c3b98e..07b4b394e3bfbb9e7217db9edf82a4006a3e5f0d 100644 (file)
@@ -1147,6 +1147,7 @@ static void drm_atomic_connector_print_state(struct drm_printer *p,
            connector->connector_type == DRM_MODE_CONNECTOR_HDMIB) {
                drm_printf(p, "\tbroadcast_rgb=%s\n",
                           drm_hdmi_connector_get_broadcast_rgb_name(state->hdmi.broadcast_rgb));
+               drm_printf(p, "\tis_limited_range=%c\n", state->hdmi.is_limited_range ? 'y' : 'n');
                drm_printf(p, "\toutput_bpc=%u\n", state->hdmi.output_bpc);
                drm_printf(p, "\toutput_format=%s\n",
                           drm_hdmi_connector_get_output_format_name(state->hdmi.output_format));
index 207635715466c2934fb801a6f6b280156969e42d..dcad2d46fabe5f9cc9f71f2cfe2af1b6234bf3e5 100644 (file)
@@ -1070,6 +1070,12 @@ struct drm_connector_state {
                 */
                enum drm_hdmi_broadcast_rgb broadcast_rgb;
 
+               /**
+                * @is_full_range: Is the output supposed to use a full
+                * RGB Quantization Range or not?
+                */
+               bool is_limited_range;
+
                /**
                 * @output_bpc: Bits per color channel to output.
                 */