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: 199787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2428553dyd; Mon, 12 Feb 2024 05:32:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU1eIllD/Wi+xj41PTPaSlKedj9dNU1E1c3Ey13j2K+fE5RbNB2dUOD0cAeZ8k7qAePW/NTUFWX2wS8b2KYqM/ysy43cw== X-Google-Smtp-Source: AGHT+IE/MrZewi3K/+R6dImQQ44GxXOmvFZIzjVEO80+D8SIEWM9HIeoCAX95RdPw3Oz/qmIH8g/ X-Received: by 2002:a05:6a20:e198:b0:19c:b457:fb8 with SMTP id ks24-20020a056a20e19800b0019cb4570fb8mr8024922pzb.51.1707744775670; Mon, 12 Feb 2024 05:32:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707744775; cv=pass; d=google.com; s=arc-20160816; b=Xm5lQ2g7AG5RmJbVasQ9G2tZVJ6/c5ivK7IXwoz8FOM0it7DIJE+44y3o3SVY9urpW VCoF0xsc8FkjHyW+Id4dctvmY6oxbblo4s80w7DqpfOP1SGgrE/RwinDjqk/NFoNLffJ rMew5b8e12rCEWE+V73jlfGoq8gQNjHFev38VvcsSOFMD1EFofc/GFgO8j7cTagDJ3eo phBVXK5pk9axkcLkQoAA89RaPeiimvWShMZz+26gL6KopyvyL+dCoxb0dMwoqVeJlkX4 mSuUM62tWYm5iljqlEbwb/9/6EEvCp1JilMTB5pM8enLHlHV4XTds8UnvdpaF2sBl8us qwzg== 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=+6DVY3JtzWU8GyzyAFnNghrdY5u1oHmETT7zvi/Zn70=; fh=nIqkONzN568JupYUNRGvrA5/OLYA4ddG4IGlb88oskg=; b=NZJaCEE9HJbhiyzWpfi5vejs2YREX8gLxTY89EKOijfZiYLZj91+8oVohrxDd4QmmH J1ANewf7091sqT3zHKe41dFCZ0T9RESdahZXhtyRKcCLbe9PTqnjVQvji9z2hTKOEHcw dPkaa6Jx7jMbG5QVOR4oi5j9VqMXKavIYO4Q9Bh3UI8vllYzVDKN5bzxy/N7Dqmh15Uf VieLjMFltqFES5uC6AJJ9b1L0IEbQRJ5wREY2Ldq63wLnTomp4F2309j0pXzOUwSVENm O+Mg2m6t935f7dmLrDtHhMJr8CXjZY9uJf7b8VlNYWtjqCIEq0j5vTwNxFF7Fn1Hej2F tZlg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q1MN1sec; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61631-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61631-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCVWys8TcXnbvP0E+y/o+17m4ldbr/1OK5m6TRoOVSxgg4lt75KrWXU+jIMiUqDd+WxII3ZgDVkKQCKhKqZf5XnzJfQogg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l197-20020a633ece000000b005dc4e7d879csi266350pga.66.2024.02.12.05.32.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 05:32:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61631-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q1MN1sec; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61631-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61631-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C95A6280F89 for ; Mon, 12 Feb 2024 13:19:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE55C3B191; Mon, 12 Feb 2024 13:14:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Q1MN1sec" 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 80FB03F9C4; Mon, 12 Feb 2024 13:14:16 +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=1707743656; cv=none; b=fJjvRpcZVq1Bh+boWFpFwBhdFyOUHuJ9DjpJ7rmgoh+22A083MMKXvWcFqC6t6WtOKKgnOHaVzQuBaJOCdkc46vNkDRIwg802yLFcO1C0H8fPwPUFPkD1JPjwTcGRAv25NFVoaOKXYWhOy0/w8Rtv1Tp7U9KUpBJ8hLz5jcqZy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707743656; c=relaxed/simple; bh=s5W/xSAdD1+rl96fJKi18NgBJWzOCTMahxkAxJFesPk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kHoF+lrmWsO9WTttoBWXRx98X3ZYjmY/sgOh9a5A77UzDCvNkkgqBwIgdh43J88ZYevbx2OeEG+7pR2soVC6JxRG0elhVuSplDb+zprMyYm3Rq7u45SunqE5/HqCJsrF3BtvscX91Wp1Yu7nI4ifxQJR0PfcJe68NgcIUM8LNHM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q1MN1sec; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790700185382083850 X-GMAIL-MSGID: 1790700185382083850 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