Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp529789lqh; Tue, 7 May 2024 06:47:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVf2DeGtXhvhr8IBax3xSaSmAD+yLWys0wWO0SSmQTZ1CnACa1F9JxmunV+e8+t2zIf+M+hS04UAFbg8glZNLSiVxIjWQcJUUOZksF4+Q== X-Google-Smtp-Source: AGHT+IFSygaWrBZDfKR+VU8C37UMUAqZRwxp9lOSvH56UiW7uSdBy9qTzM0FHJKt/ExAGcqtDIQv X-Received: by 2002:a17:903:2985:b0:1e3:999a:9726 with SMTP id lm5-20020a170903298500b001e3999a9726mr16846926plb.29.1715089669950; Tue, 07 May 2024 06:47:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715089669; cv=pass; d=google.com; s=arc-20160816; b=hOrj0jC9HNCR/PreG4Jv80WqRXDmIovIFJaiMPyGFOM7/EL6WMwqwpFpUsZU82JbHh qn3eAjVz0xmHttA+sNgmnvZne37hzwGZmx7s82WeKbPqNGhPmab+mDOl/kthAoT9p+1g UygdJbPBmczBrQLaG0eXQEpZsZXRyMr8Pl3DNEW8K4WZ2c40JZLK4/bLQCFHYSPa7pb3 1fdhKBAOEM749PLbImr/m36Xjst/WM/DesBCD+ImRNBzSs16KVTe2LtqnXWr8QaqCKeh nsqec5bymZog82jRm2D0Ahl4bMZKieCNu/lCgvTsy3VcvxBgUqmjvllwuqPiWsegyv0q I41Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=yH1/bTQF4tqNEopuXyVKo8GK6e/uBCG4/MDvAwTFabA=; fh=ufmwd8Wo0DI+kdMOJWC7ZXqsyLxoMBbO0En/E/GApYU=; b=zPjb70O02zl4NioD1XE61obuRuqmqITXoXQ4HbkkWiSUBKswsBuIITG0o+rAIJA3lA uhKfHE9kd0/Ct9qetL9ZUEjoCjKpIAauW5LqrPVMnJDGxIzHVMFs+fxOQXLOtGKC+z9a UwLr0E+HLYyFR/CRO2fg1bFz9JTHGAtHKIbFE9Mvl3DNd4OR102pJ3z7XkgN/kYLOcaI KUUXccDVmTv7fRN7iChnPl2qilCTIl+IHnX2c9pTZXddi/+kZfJWGmfcTVIJ9aMpTpTi glvt//7GhXYkVC1g98tcwt1FR9ARiucvUqGkIe/2cf8PBsMwEbQdsiX/ItZ9h+qJ+Eej 7iSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QyzrAp+j; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171379-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171379-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y19-20020a1709027c9300b001eb307662c4si9813538pll.460.2024.05.07.06.47.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 06:47:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171379-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QyzrAp+j; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171379-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171379-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 44EDDB28CFC for ; Tue, 7 May 2024 13:20:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0722C15F316; Tue, 7 May 2024 13:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QyzrAp+j" 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 1455D15F419; Tue, 7 May 2024 13:18:09 +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=1715087890; cv=none; b=czVtUYXCqKbRQgyPRpiA7r+XRYAHhD+YxLF3oYdy2HH60l3an0g1KUYLfDQP5W+ddYcWiEq7u5ryxScGHQCCbrsIdl9bBJRsNlTh57ZZ+cVaWITTSqvRMwgLwJYTrZmS9X+qK3ke1BQ8UKZ2xMf4Yt4I/2rtO6JPblEsc3H4+qc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715087890; c=relaxed/simple; bh=MbjlKvUpIH4Kpzei6mLsDD4DvZW2edzJFxhrN620Y6I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=c56lQ7AVgRtu6SPFrg4v6R78Em8zk0lBY/mCnwxcq6X//VH27fQK5bvLfGyylvbqjOsZt5lD7pvB0Pyle+aixw51TFnvDGmnhlKluZLni/KN6vSAoK7QyTjy5l2uEfR4l4bU6vvpvrVeUanMXW6ukUXAVa4XOvlgrhQEdvXKeB4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QyzrAp+j; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 517BCC4AF66; Tue, 7 May 2024 13:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715087889; bh=MbjlKvUpIH4Kpzei6mLsDD4DvZW2edzJFxhrN620Y6I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QyzrAp+jGv8reICxRHF5XmxuuEo4fE1L1/C1pmJgdC/KRbPTTqZZFXMaItU/HbCo5 e95wvIyhinbV5oiCYaWXOLDBvw6Z8KeXWy0uUGOucNrASf5G02EP2fbNKnHWPPWgxF cFQnD18kMr4epHK3qg6FlbidWb6Buj4J5MHfVeEcr29jS/l3H6fd63QaNwLb+4I8Be dEdzJkDCz2AxsPBzqqK0iyp9eP+TMfBJMh5U1QpelGydFRlCXyjsNkw5eIjzVDygip TpNzgdfV/kaDGFbdeGJG70/c+518CgyR7EGufHbuXakrQa28JOPPGx7lYdJB/nN2gF L2cMpXF9LILhw== From: Maxime Ripard Date: Tue, 07 May 2024 15:17:27 +0200 Subject: [PATCH v13 09/28] drm/display: hdmi: Add HDMI compute clock helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240507-kms-hdmi-connector-state-v13-9-8fafc5efe8be@kernel.org> References: <20240507-kms-hdmi-connector-state-v13-0-8fafc5efe8be@kernel.org> In-Reply-To: <20240507-kms-hdmi-connector-state-v13-0-8fafc5efe8be@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?q?Ville_Syrj=C3=A4l=C3=A4?= , 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=MbjlKvUpIH4Kpzei6mLsDD4DvZW2edzJFxhrN620Y6I=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDGlWmq//7NI93yb596ai9BTRc2oee3fOF774U56Z63OJ4 GWbOb3nO6ayMAhzMsiKKbI8kQk7vbx9cZWD/cofMHNYmUCGMHBxCsBEpkxnrBX1CDX8Z1f+zOkT 8/0LjAlBDOeuFDUxdc/5r1S0KCJE9+2qlcWLZt57ciA0zePFsatLLzPWqZlHqKvlFCeoHtCIDrs 6oVDxVJGc51r9x9lisvffyTRd/74wN1lu7kbW49u83RgeLYwGAA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D 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 -- 2.45.0