From patchwork Tue Apr 23 10:45:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13639856 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44679C4345F for ; Tue, 23 Apr 2024 10:50:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3FR72Ye/L5tZPyumXq4Id7XsvqyX35lEIKoy58XOhMQ=; b=J3HOD4ATZab55/ MAcS2c8gak0tX3CgL0Y9omsI0xZem3GsvUCNGDGn23dOjKxl4IZO+Efe4Ul+RkLkFnG4EQ4m7LeIk GLUPBnzGJBaOSMjqiqGj8J7tlfHd1oO6EQ4LvWFJzkeIRbv63tgiBiORSyCQ5ImE/JdcgwKrAANvA 9IsBrmmobKtEHS0qv+aZELi8c3jdy42B9zPT5t8iyD5+5Bh3kC+tDC0eRKvPZQdNkiGCEW+e4bmKy fvWrm21fA5JP0auNCJipHc4Q+2VCAIoJRMtojO4rgU6vPnivSGvEt0JaVRW1xCll7UnLBjQPxj56n 9DGM+Xs5RFJE0YmTAYgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzDjQ-0000000Gwc0-2Hbd; Tue, 23 Apr 2024 10:50:36 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzDfR-0000000Gu7d-2wgJ; Tue, 23 Apr 2024 10:46:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=SQrJvTOkG+cSg++HiSieEi29PgcQGbgYoKSXMtdOljw=; b=SpjGZ/b72zokB9bxi1LvMRJKVu t4TV+17Se5oh2XMj21/Ro2D07Q2Jx+6OFCpcs3sUiXbPXCED4zWKpn22esXGzMU4ZbhVq/SKt6tWB LNGECgBGg4khrzFNRRRcITnE3mq+mbdX/Z4qWuD/PmhOxBppPFqzgiLHtwBvnulA5tws+bb5pn/MO HncJmXOOmTqfETjfLB+yfkEjJbiObnPtna2yi5Ss0v+kR8fvsMu8OOAFBxwLnakjI9ImaD4dBKKUs vJnC7l6rQ25vhIxlrk3GEaLgm5OIBSRe3+9kdxGceUL3Ds9RVIxmkkhDVWgP8QS1z5ZPP1p0xbunz u36WMR1w==; Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzDfJ-0000000DzlF-1uql; Tue, 23 Apr 2024 10:46:27 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id C1F9BCE0F96; Tue, 23 Apr 2024 10:46:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98F22C116B1; Tue, 23 Apr 2024 10:46:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713869171; bh=MATh9kxbk67VrM7g+CeDRm4hqfK/d6VTugpMQHhmWF8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Th1cZZlYjBf471G2N7Ylxvr3z7cCm66gpSgeyVY2tzlJA8EVMTYQ6VeM4SL23bnd0 TG4N6FxYjB52lo/hhtDWUOWR7iUQDYrWmh1AV1mKgW0R+Z980E5+KswC8WJ5FxUbMr 492OhhrA0lYXXT8kExrw+eP8BR0tjeVqyRhL7Ds6hgo7GS51zj27vgbe8UTbDw46q6 aHNr1M5LSdYiebWhRoReC03Hw+YWvygAExfFZwt1G90EL/HtA7z8OU/7U5rxwOA0hL V8EX6ndfmxkytMGbvXn/Abgmo1DbGRJrX8ozVsacvjTkHmmsh531fC+slr8ct5W7NK qXxuGwQriQzKA== From: Maxime Ripard Date: Tue, 23 Apr 2024 12:45:38 +0200 Subject: [PATCH v12 09/28] drm/display: hdmi: Add HDMI compute clock helper MIME-Version: 1.0 Message-Id: <20240423-kms-hdmi-connector-state-v12-9-3338e4c0b189@kernel.org> References: <20240423-kms-hdmi-connector-state-v12-0-3338e4c0b189@kernel.org> In-Reply-To: <20240423-kms-hdmi-connector-state-v12-0-3338e4c0b189@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 , Andy Yan 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.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3352; i=mripard@kernel.org; h=from:subject:message-id; bh=MATh9kxbk67VrM7g+CeDRm4hqfK/d6VTugpMQHhmWF8=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGnqE/2kdPawX3B3L1+wqmdCVfVn95QU04dBNjuKM/8mu nCyZHJ0TGVhEOZkkBVTZHkiE3Z6efviKgf7lT9g5rAygQxh4OIUgIl0nGCsD9rCs47R6SZfZYTv pM0nYmWPffC4k+8T57OSl+GlbUWctugZ4T8HX9/40HNMV2X9gYmJjPWJe/9OCC+QZBTcWbjJP+r cucQP2x4artS/sDA/VzLa+Xgy97xzG39srb23rf+9XOKOxNsA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240423_114622_869468_A3772ED4 X-CRM114-Status: GOOD ( 13.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A lot of HDMI drivers have some variation of the formula to calculate the TMDS character rate from a mode, but few of them actually take all parameters into account. Let's create a helper to provide that rate taking all parameters into account. Reviewed-by: Dave Stevenson Signed-off-by: Maxime Ripard --- drivers/gpu/drm/display/drm_hdmi_helper.c | 57 +++++++++++++++++++++++++++++++ include/drm/display/drm_hdmi_helper.h | 4 +++ 2 files changed, 61 insertions(+) diff --git a/drivers/gpu/drm/display/drm_hdmi_helper.c b/drivers/gpu/drm/display/drm_hdmi_helper.c index faf5e9efa7d3..679eb3e81393 100644 --- a/drivers/gpu/drm/display/drm_hdmi_helper.c +++ b/drivers/gpu/drm/display/drm_hdmi_helper.c @@ -193,5 +193,62 @@ void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame, } frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA; } EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type); + +/** + * drm_hdmi_compute_mode_clock() - Computes the TMDS Character Rate + * @mode: Display mode to compute the clock for + * @bpc: Bits per character + * @fmt: Output Pixel Format used + * + * Returns the TMDS Character Rate for a given mode, bpc count and output format. + * + * RETURNS: + * The TMDS Character Rate, in Hertz, or 0 on error. + */ +unsigned long long +drm_hdmi_compute_mode_clock(const struct drm_display_mode *mode, + unsigned int bpc, enum hdmi_colorspace fmt) +{ + unsigned long long clock = mode->clock * 1000ULL; + unsigned int vic = drm_match_cea_mode(mode); + + /* + * CTA-861-G Spec, section 5.4 - Color Coding and Quantization + * mandates that VIC 1 always uses 8 bpc. + */ + if (vic == 1 && bpc != 8) + return 0; + + if (fmt == HDMI_COLORSPACE_YUV422) { + /* + * HDMI 1.4b Spec, section 6.2.3 - Pixel Encoding Requirements + * specifies that YUV422 is 36-bit only. + */ + if (bpc != 12) + return 0; + + /* + * HDMI 1.0 Spec, section 6.5 - Pixel Encoding + * specifies that YUV422 requires two 12-bits components per + * pixel clock, which is equivalent in our calculation to three + * 8-bits components + */ + bpc = 8; + } + + /* + * HDMI 2.0 Spec, Section 7.1 - YCbCr 4:2:0 Pixel Encoding + * specifies that YUV420 encoding is carried at a TMDS Character Rate + * equal to half the pixel clock rate. + */ + if (fmt == HDMI_COLORSPACE_YUV420) + clock = clock / 2; + + if (mode->flags & DRM_MODE_FLAG_DBLCLK) + clock = clock * 2; + + return DIV_ROUND_CLOSEST_ULL(clock * bpc, 8); +} +EXPORT_SYMBOL(drm_hdmi_compute_mode_clock); diff --git a/include/drm/display/drm_hdmi_helper.h b/include/drm/display/drm_hdmi_helper.h index 76d234826e22..57e3b18c15ec 100644 --- a/include/drm/display/drm_hdmi_helper.h +++ b/include/drm/display/drm_hdmi_helper.h @@ -22,6 +22,10 @@ drm_hdmi_infoframe_set_hdr_metadata(struct hdmi_drm_infoframe *frame, const struct drm_connector_state *conn_state); void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame, const struct drm_connector_state *conn_state); +unsigned long long +drm_hdmi_compute_mode_clock(const struct drm_display_mode *mode, + unsigned int bpc, enum hdmi_colorspace fmt); + #endif