From patchwork Thu Mar 21 15:29:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 782185 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD81512A171; Thu, 21 Mar 2024 15:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711035018; cv=none; b=ehsh816SYPYIMowQuVR9oc/aHn4Z9rKd32IB+GM+4KqxFHcFXthExviH2p1UCW1D6HcgORtot2UD949gHEr08wp32xakUYNFin09wyjh95cyD3fpoNIcfGPSxxB4fmPneja7OI6jnJlD2Tgi2CIckTNc4UssD+Jv2psL5VkrU9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711035018; c=relaxed/simple; bh=L0EsraHYt0YTCl5UwbssCMZ0y8+hOONQTrFMViBzI1k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WSJ6XybDCbbov1a5QJTsckJU4HM7d08sZ/ES/bZgygyb4Mo10w6pqQNXE9f5CES++Uz++Y1TmIfpAGkaDt8L6y9PNiO/osDTaFjxpm1KnYJHVRGmbKxaoLEgyZ2IibZ5QHQpwdF/SlxIvdbE8JBpKJqKbAlqHt12rWpcj6DXZtg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dfLs6Iiz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dfLs6Iiz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CD7BC433F1; Thu, 21 Mar 2024 15:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711035018; bh=L0EsraHYt0YTCl5UwbssCMZ0y8+hOONQTrFMViBzI1k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dfLs6IizXvP86SaRTeQXcwF2Cgsxf8Tcto0ZQcgpefhkhEtayyiqsHOTfWTAX4DbM 5wOvsIVRKVwa+pCOj4pINEEayK9s4D1Mj2nY5+CQoY6/QvDk7lxoqS2zzzNONH+crj RDajxJjM+BL54OlGvPYjAAcpwEfo+THXrqZKvJdSCmluOkzUNXuLZOhK9Z/HihPpns 7/Os9eAGaN7GQ7zoz2V1CsCk7PiGeWk+C9SbE8p0Ac+1BrEOCJC0C9MHLTNtVxt7KI dnBPDmK24MGDEhUJH7qYHmfTEXsHWciskyMrKvHtvl/5FwDwKcHUMpKRSQ0E9A7++c D4j5Kf1xLhI9w== From: Maxime Ripard Date: Thu, 21 Mar 2024 16:29:14 +0100 Subject: [PATCH v10 18/27] drm/connector: hdmi: Add RGB Quantization Range to the connector state Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240321-kms-hdmi-connector-state-v10-18-e6c178361898@kernel.org> References: <20240321-kms-hdmi-connector-state-v10-0-e6c178361898@kernel.org> In-Reply-To: <20240321-kms-hdmi-connector-state-v10-0-e6c178361898@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , Sebastian Wick , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Maxime Ripard , Dave Stevenson X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4069; i=mripard@kernel.org; h=from:subject:message-id; bh=L0EsraHYt0YTCl5UwbssCMZ0y8+hOONQTrFMViBzI1k=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKl/gnx3ZHDEb5dPFt/9MebR3lUVjgUL7GqOKc+6uWzRo y4rhqT0jlIWBjEuBlkxRZYYYfMlcadmve5k45sHM4eVCWQIAxenAEyk7APD/wCV/9/vrWcrS9n4 5PbsSYIbPfl1D3Csurw1klNwifFiFzFGhq2TRR+w/r0ZVfo88Xaw+tKkpcdjpDvU7Bcc3Xxg5Qa DNXwA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D 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 Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_atomic.c | 1 + drivers/gpu/drm/drm_atomic_state_helper.c | 29 +++++++++++++++++++++++++++++ include/drm/drm_connector.h | 6 ++++++ 3 files changed, 36 insertions(+) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 3e57d98d8418..ec6c6beda5c9 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1145,10 +1145,11 @@ static void drm_atomic_connector_print_state(struct drm_printer *p, if (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA || 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_full_range=%c\n", state->hdmi.is_full_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)); drm_printf(p, "\ttmds_char_rate=%llu\n", state->hdmi.tmds_char_rate); } diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c index 2ad3cfafde27..8d436fdc5c91 100644 --- a/drivers/gpu/drm/drm_atomic_state_helper.c +++ b/drivers/gpu/drm/drm_atomic_state_helper.c @@ -662,10 +662,37 @@ connector_state_get_mode(const struct drm_connector_state *conn_state) return NULL; return &crtc_state->mode; } +static bool hdmi_is_full_range(const struct drm_connector *connector, + const struct drm_connector_state *conn_state) +{ + const struct drm_display_info *display = &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 false; + + if (conn_state->hdmi.broadcast_rgb == DRM_HDMI_BROADCAST_RGB_FULL) + return true; + + if (conn_state->hdmi.broadcast_rgb == DRM_HDMI_BROADCAST_RGB_LIMITED) + return false; + + if (!display->is_hdmi) + return true; + + return drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_FULL ? true : false; +} + static bool sink_supports_format_bpc(const struct drm_connector *connector, const struct drm_display_info *info, const struct drm_display_mode *mode, unsigned int format, unsigned int bpc) @@ -920,10 +947,12 @@ int drm_atomic_helper_connector_hdmi_check(struct drm_connector *connector, drm_atomic_get_new_connector_state(state, connector); const struct drm_display_mode *mode = connector_state_get_mode(new_conn_state); int ret; + new_conn_state->hdmi.is_full_range = hdmi_is_full_range(connector, new_conn_state); + ret = hdmi_compute_config(connector, new_conn_state, mode); if (ret) return ret; if (old_conn_state->hdmi.broadcast_rgb != new_conn_state->hdmi.broadcast_rgb || diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index bb6b6a36ade3..3eaf4d54364d 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -1068,10 +1068,16 @@ struct drm_connector_state { * @broadcast_rgb: Connector property to pass the * Broadcast RGB selection value. */ 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_full_range; + /** * @output_bpc: Bits per color channel to output. */ unsigned int output_bpc;