From patchwork Mon Feb 12 13:13:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13553081 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 C8DCDC4829B for ; Mon, 12 Feb 2024 13:15: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=+2wOn3pOMVFsXXl/NQ/PBy5g7D/uibLbBQwvlDyqhxU=; b=f5vUwphTQUhlQm 0PLloIPM/R1++GbJ6ZJDrDTiL338cN2NU9duHmyzkyIhXV6VAoVExGvFAZIEgo7vodaD8uhbpl0jF 19BAlo6MGle16/zowJ+NujoiViW0FbhNSUegGRPTKCzTKx7DbAVoysa5yIW6+wV9PYvKA/2GFH9e/ TgA2lnlBoFLAu69WreKTNIa2ebidW2e3g7A1aSsP5Vm1uhx+v1NmbYVFz8la2pEvK0VaIowWCfvt3 OKK563mMTXgmAbkUygKDAL08uFeBV4MuPibfQ0PAU+MdpYVJhWOvKyxsnZZX9VjVBBckGE3Zd6pRR y4GT7ozRJ6OPxozvMVlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZW9y-00000005QKM-1gVt; Mon, 12 Feb 2024 13:15:46 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZW8X-00000005P2D-1cZe; Mon, 12 Feb 2024 13:14:24 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AAE2F60FB1; Mon, 12 Feb 2024 13:14:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05D21C43390; Mon, 12 Feb 2024 13:14:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707743656; bh=s5W/xSAdD1+rl96fJKi18NgBJWzOCTMahxkAxJFesPk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Q1MN1secIYCFbTnoKCzZKJf5MRpdSH4v4ih46cyrxLB1pWAIJ66jKTuM9mk6XokKc bRCxg5Ri5iGvZ86KzDmfr1RGwT6xGztKaR+PYJzWeOqcfaD6wU/oNLk/RZNSyiydqE c7qZrw3SDCX75q6mGib4SYStbsgzyMQzaVCRAX8RGLmXra3sAWftruAO1F9uZWCSou GxaNK2r+tpsKCW5TOV1EjAfC+0tOWBe9u1cmB7LKKpP+iEMeJdfHDuarfBFehruVDN F5lhOtpo9M+YO1R5hyxiu87H0Qu7XI9lMOykzp3m8RryVD0NRL4BzEMmJbocUpTNsJ ryUiW8GefFtVg== From: Maxime Ripard Date: Mon, 12 Feb 2024 14:13:00 +0100 Subject: [PATCH v6 17/36] drm/connector: hdmi: Add HDMI compute clock helper MIME-Version: 1.0 Message-Id: <20240212-kms-hdmi-connector-state-v6-17-f4bcdc979e6f@kernel.org> References: <20240212-kms-hdmi-connector-state-v6-0-f4bcdc979e6f@kernel.org> In-Reply-To: <20240212-kms-hdmi-connector-state-v6-0-f4bcdc979e6f@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Emma Anholt , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , 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=4017; i=mripard@kernel.org; h=from:subject:message-id; bh=s5W/xSAdD1+rl96fJKi18NgBJWzOCTMahxkAxJFesPk=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmnJDMKZI1Pz/wlzNsgN231LvETAWeq1XNt/5etaroy6 +/NYufIjlIWBjEuBlkxRZYYYfMlcadmve5k45sHM4eVCWQIAxenAEyER4/hn/mGgwdXN2sE3rpv I2b/8mZ+D2PB5vb33g+YtvQq9LCHiTD8lbt97uBup1UeFzv/tLb0Vch/79pxRmGFshOP+dbjl6O e8AMA 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-20240212_051417_905389_A7B47587 X-CRM114-Status: GOOD ( 14.64 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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/drm_connector.c | 71 +++++++++++++++++++++++++++++++++++++++++ include/drm/drm_connector.h | 5 +++ 2 files changed, 76 insertions(+) diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index b895bea667f7..332477c6a987 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -2982,6 +2982,77 @@ void drm_connector_update_privacy_screen(const struct drm_connector_state *conne } EXPORT_SYMBOL(drm_connector_update_privacy_screen); +/** + * drm_connector_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_connector_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; + + /* + * HDMI 2.0 Spec, section 7.1 - YCbCr 4:2:0 Pixel Encoding + * specifies that YUV420 encoding is only available for those + * VICs. + */ + if (fmt == HDMI_COLORSPACE_YUV420 && + !(vic == 96 || vic == 97 || vic == 101 || + vic == 102 || vic == 106 || vic == 107)) + 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; + + clock = clock * bpc; + do_div(clock, 8); + + return clock; +} +EXPORT_SYMBOL(drm_connector_hdmi_compute_mode_clock); + int drm_connector_set_obj_prop(struct drm_mode_object *obj, struct drm_property *property, uint64_t value) diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index 74db5ce47e01..0cc5a8732664 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -38,6 +38,7 @@ struct drm_connector_helper_funcs; struct drm_modeset_acquire_ctx; struct drm_device; struct drm_crtc; +struct drm_display_mode; struct drm_encoder; struct drm_panel; struct drm_property; @@ -2136,6 +2137,10 @@ void drm_connector_attach_privacy_screen_properties(struct drm_connector *conn); void drm_connector_attach_privacy_screen_provider( struct drm_connector *connector, struct drm_privacy_screen *priv); void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state); +unsigned long long +drm_connector_hdmi_compute_mode_clock(const struct drm_display_mode *mode, + unsigned int bpc, + enum hdmi_colorspace fmt); /** * struct drm_tile_group - Tile group metadata