From patchwork Thu Feb 22 18:13:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 204958 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp126776dyb; Thu, 22 Feb 2024 10:23:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWRsehFiZeoaOG5vgS5EnsNyj2H+Wgpdr7uOdw4AhrwXG3ORfDCjQlCAO4h5s6DH5OEVwaDmYt0unzMHga5qU2K5z6msA== X-Google-Smtp-Source: AGHT+IHbY3cvYVa9Uhqyr8BkD5ON+mhor3KPvJ/cS1GEP5zmiVDIkxV8/Ss28zXDEOIXj0zsGWKJ X-Received: by 2002:a05:6a20:1b30:b0:1a0:db5c:9762 with SMTP id ch48-20020a056a201b3000b001a0db5c9762mr1109128pzb.19.1708626238226; Thu, 22 Feb 2024 10:23:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708626238; cv=pass; d=google.com; s=arc-20160816; b=HfgyB4PQZsyHD09yI5ySbA01kYkHXOXpdJqv9QzcmtMQTpM24Crns5Cxjk3MMo2XMm JfB0ibZOfju+FzlyV+DFZMOBeUnbnzNxLMNG4CPvUyXIhALSwlIxHGqboXuviw1YN8zF wZJ4/Y83z/z10whU7oP51yluDiKylPkVBCVyYD358+jXPomYWoejZCxI8PF3Bt1Msc4c +xYQleScZqGP9/vhXdzG4/uWnT6zLw1j3Tw+aRtmersL9OTquTxJDqge2pmk/zYibVm/ VCMosZLTMY4w9AhHqwLbWoUpnCoV84zYxr0q6aoxGDb9hohhE5sYIte0cRDQwSY8HEK7 yO4w== 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=Xy17dsD1lCO9uPc2lkfo0V9gblRagmFiVy0uC3OyX80=; fh=8wcoxKk21hICD+6obVirG13fsSSMhKa/pufykSf87d0=; b=PUax3Uawm8D//bTOa/lI+AmTdEmetMHzdns9swGCNIW3CGmPUTz9bXcpsP7Sijg4Zh mj9udpg49PQr+9dnvjcEWdp7sxnNH2WWhn9TlT3QPN+vtPC5oc8DVo0myA118hirGGvu TRVZBLHWuofHAK6n+rxLIfc8xZxXSkvlTQbSXmq2Wg+7eFXY5jvVmnS0kqMNDrz1DMWK aTZwCJB4pFM0pf7g0z/OcNsy1cWewPOqlz1m1q2vfV44hy3UyDXJm873lAhZ/f6wnaAU mJLV7RvnMaqFJhRGEI5a+rBpgVtZ5iF8Q3TJy1ao5n2F0UJ+rK7sfj4FOOwZr/JbgALz SKuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LvyFNzgD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77090-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77090-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id nl13-20020a17090b384d00b0029927c58570si11119379pjb.12.2024.02.22.10.23.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:23:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77090-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LvyFNzgD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77090-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77090-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 0E56F28506E for ; Thu, 22 Feb 2024 18:23:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00D2C13BAC7; Thu, 22 Feb 2024 18:15:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LvyFNzgD" 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 A2D8312D20E; Thu, 22 Feb 2024 18:15:05 +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=1708625705; cv=none; b=UvWIWSjTqWY9qaG/BJx8Vk8GJn1ORUF5nH8lC6ovezSR3XGsK+TTcuyi4HXx4qx3c12P4YrKNiwgMmvhAM8EDVzJPzaof0n9YSy0uXtYKlKi3/niMjiaqkE1X7ilR3PwYiVEy/ajptSTgtI5zeZyr+QXWeSEbwWrIFgImnWK/9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625705; c=relaxed/simple; bh=mh6yrZRFWWWgJBk2sU4bljECM9b4FtLl0mec212hJfc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=G8p11/Z07rgWkW6QpdO93w/+xMrPn3X3OXFs7WkjZKZN3k7/YAQdIVoezzwpc7WD1J4qOO+d5DCCzUKBlKjvCSgfUnxXX3dWnhkDlCmSIzWRrl2mvU0n6pKDJNgJdmHqWCFRg2mKg2ByM+SqgQaDf7ZcBvzLuLRF+Myq7YMg+gI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LvyFNzgD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB1C5C433F1; Thu, 22 Feb 2024 18:15:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708625705; bh=mh6yrZRFWWWgJBk2sU4bljECM9b4FtLl0mec212hJfc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LvyFNzgDE13kd6VGv2xijkQwQX8ujAAe6vaMdo5zRRzb37jaxP24x0rtuGc4fW/le yzKkevujM1S5D+PNXpWFphGPuWe2uDAlkSgnuKmJNN5ZGxkT2kdzGf6cXzz2pxVDAA jSmPuHZH4mscj6tU85CATGgp5+qK2ARaHtqtySny7OIC1myGHWRpaGslQpyOvrBWTT aelzxobALmoBu+x2T2/oOMX9htJJOSPD9OMFFM3o9t684kneUov/mx1xepyM27U/bn 4s9V5LvWaocHn91BEW2EX84o6UcgQk+95YJZlXWNaWDJosjRY+waKhVbtWadikJfN0 ZIfEh0wT83Adw== From: Maxime Ripard Date: Thu, 22 Feb 2024 19:13:59 +0100 Subject: [PATCH v7 13/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: <20240222-kms-hdmi-connector-state-v7-13-8f4af575fce2@kernel.org> References: <20240222-kms-hdmi-connector-state-v7-0-8f4af575fce2@kernel.org> In-Reply-To: <20240222-kms-hdmi-connector-state-v7-0-8f4af575fce2@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=4017; i=mripard@kernel.org; h=from:subject:message-id; bh=mh6yrZRFWWWgJBk2sU4bljECM9b4FtLl0mec212hJfc=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKnX+z7GcMXcWSeRGnorTf30af/4AzK3283C3II+vwxes eGy1JfPHaUsDGJcDLJiiiwxwuZL4k7Net3JxjcPZg4rE8gQBi5OAZjIh0cM/0w/lr0I/LNmouSr oPabZTXb3jf/Li67Yty1U6GIZ/sFB3tGhrly8oe4VDOPnuu8NXP6fy2Fz5/iDtnI7BTfvsH9qWm GNysA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791624466619089152 X-GMAIL-MSGID: 1791624466619089152 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 b629c8e990f4..8cc1332f11c2 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -2897,6 +2897,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 29883e6f8e50..a859ad7ee04b 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; @@ -2094,6 +2095,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