Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp562831lqi; Thu, 7 Mar 2024 05:42:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUUPtgLJ1Z3NyII+ltNx6ca3y93Ght0rwUcQRyPdW9jcBta3Dozcrbrk+uV2/4gcXe/9KCnD6FgPAbIf0agxeLSW2c/Cr5eAf25ebDqyw== X-Google-Smtp-Source: AGHT+IFztlYTBCxuxv5BCHFnYa0kSWpZQ02b3sg1K9STLH6g7Kq+v2djmg2drObVq/1z855sulC4 X-Received: by 2002:ac2:5544:0:b0:513:40f7:3915 with SMTP id l4-20020ac25544000000b0051340f73915mr1397129lfk.58.1709818963921; Thu, 07 Mar 2024 05:42:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709818963; cv=pass; d=google.com; s=arc-20160816; b=RUL7ylam7I3QAfMZajG0aT2eHfHHJHeDFQdhVP9VqblF9J/Uc9+zwyNmGNEHnhl9qQ sIm5tyTTKzTB/VmpibjpAagiimSbrDL+nN/J0Qi1GTOHI4dS3+cALLhxm9wnDvkL4V2I nKMXN//Ft+DELiorDZhn4aBPkwQ+lz2EEEWcfSg61s0BwXdV3Izm7IK8LDNnpYAfArfC ucfTsM/khUnohnw84aO3SDLle3Tb/dBsWU3j27Q1FjMlndaWmj7bTME4gc5RQ7nVt1Vp u6ivhWPZHvmIT0VJT81T79hIzzfu0u9cJoO86FY21nSHGMbkmToiySV9zOm67kqtsd0I 0CTQ== 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=D/v+p3iAVXQSJO9deztTpEmkPSTu0pH3C4kbA9jHy6o=; fh=8wcoxKk21hICD+6obVirG13fsSSMhKa/pufykSf87d0=; b=QEvftFqG28o2hEISXuMCuNbwFXnffWxOlkisRp2rhgOY+KFT/d1oI+EuVq1IlxTpMd I6v/Ylk7jaVbC+bo8RkNkOQMvdAGt+Fyf3hqBiD0XZpOF/WAd+fieCUi3WPpR99R1mSc Y6wqwgQov1hCjHpGj3VUd7Wb620NRHdXGvMRYVDNDuxbV3g1LMbLoREkt5vf8JUIWvAb 4zoxfKhzogXBx7KKAP2UebiSQuarGf9341y+7Xt6gnhXT2J7tefwpI9mY+7w+E2dxX7H lOudkA6NMRXCQfv/SEL1Ruv8rsnRrldo4BFXcd9nP6Le++dX4LwCV+eTVSl+15bYntdA TBrw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GIudKkeo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-95627-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95627-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id en22-20020a056402529600b005682573bddasi6971edb.254.2024.03.07.05.42.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 05:42:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-95627-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GIudKkeo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-95627-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95627-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 am.mirrors.kernel.org (Postfix) with ESMTPS id DE1671F2494A for ; Thu, 7 Mar 2024 13:42:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D392812FF99; Thu, 7 Mar 2024 13:39:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GIudKkeo" 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 9413712FB2C; Thu, 7 Mar 2024 13:39:19 +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=1709818759; cv=none; b=Y4B2cCxdFNDRRjAgeLJkQ4I9zNTXOS8OYxk2YwTfmPi5KetMKXMNLohGB5qm5QHCegu8hfNKzUtPWOGjyt2k4QgREgTbF1lENlnK1CRWQ53LbyiwIjzr8mb98lG6pkudsnwniSTNbeW8L1n2NNcASP+eTL4giSrFGZ9cvy6Bhh4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709818759; c=relaxed/simple; bh=knNLcwVqg8jv1l/rgrHhTRsj59b8/zn3xoeOIeIyJfk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WdR4/f0CEbuAoeKUkeV12HX5cUFlM4Tp/jNeG+akzPvq/rcqijq6s315nftLKuHHjx+14QL8rNRWzjkstTlwpYHgrlaO3MB0ZdRMI0VHRoFMbwPeNd2yheWCGTPwcOzz+gGgfUweFRtrckt0U2ktKMYB3gIqfy/KYl1U/DhA3mM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GIudKkeo; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6071C43601; Thu, 7 Mar 2024 13:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709818759; bh=knNLcwVqg8jv1l/rgrHhTRsj59b8/zn3xoeOIeIyJfk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GIudKkeoDkMn+BtPXzwCpS6xMMrGuBZ7UV0fROChdqK4tX3gTXq98vHz2Bl/MaCPT /cAT78VQ9RE3ne+lj4+xlS/m4QvUEk+c37XfyIBPDL6OZ7YHWjfpfLyqmFpmDsop+r CzVLcXvjeWpVuq6xpe/X+fD+35WvgxTGJgvaQHnNrEXAMOvCQEZMdrT86sQzc/tB6h npjDzMohXJUalDiYu7oPusTqBamuw8+4a6I2+v9s5ORSv+u2xTk2VgISUoJ6VjZ63r XJeijMh219Wgf2GjpVlsoO0ZdEqUFyGGdVD4EXSrLQFDvcXwX1CONHaS6ZIxryGQOf 3QaVuZIaZDGhQ== From: Maxime Ripard Date: Thu, 07 Mar 2024 14:38:35 +0100 Subject: [PATCH v8 08/27] 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240307-kms-hdmi-connector-state-v8-8-ef6a6f31964b@kernel.org> References: <20240307-kms-hdmi-connector-state-v8-0-ef6a6f31964b@kernel.org> In-Reply-To: <20240307-kms-hdmi-connector-state-v8-0-ef6a6f31964b@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?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.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4451; i=mripard@kernel.org; h=from:subject:message-id; bh=knNLcwVqg8jv1l/rgrHhTRsj59b8/zn3xoeOIeIyJfk=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKkvDye8FffR6jZ5UdDre3Ujn+Omhbc/L9T6ee1s1WcPr 617Nu6611HKwiDGxSArpsgSI2y+JO7UrNedbHzzYOawMoEMYeDiFICJZE5k+O/gJsh9RN9fcILC px9r4m5tPCu7xeeNnuR+C5+CiwUSR/8zMqxlU/9f+vOk/O+/M7sXNgu0q31uso5d6hzooJ6aNPc OAzMA 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/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 @@ -2895,10 +2895,81 @@ void drm_connector_update_privacy_screen(const struct drm_connector_state *conne /* The hw_state property value may have changed, update it. */ drm_connector_update_privacy_screen_properties(connector, false); } 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) { int ret = -EINVAL; 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 @@ -36,10 +36,11 @@ 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; struct drm_property_blob; struct drm_printer; @@ -2092,10 +2093,14 @@ int drm_connector_attach_max_bpc_property(struct drm_connector *connector, void drm_connector_create_privacy_screen_properties(struct drm_connector *conn); 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 * @refcount: reference count * @dev: DRM device -- 2.43.2