Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6045311rdb; Thu, 14 Dec 2023 07:04:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRLSSipQhBkd2JeY/wC61aX9BdW/f/G6rEE6H7hiCV2PaXyQVk6JGxwpvDYSBQA1kHwSJX X-Received: by 2002:a05:6a20:918d:b0:190:46c8:a3dc with SMTP id v13-20020a056a20918d00b0019046c8a3dcmr5621768pzd.5.1702566246741; Thu, 14 Dec 2023 07:04:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702566246; cv=none; d=google.com; s=arc-20160816; b=R1aTdWt2WECLG2F+o/bUlInuoDXoPSQZMIlQJV8JG+JGnAX0CS9QghsA1UMucAxpjR 4rKLFah4z53SITccCm5fBkgM2jCwGkNHB/zt3caUzCfw0suYz9V7h9/qbjrdeVKmljsd HaQKxrz4p9wbbZg9q5YdOGFEVUUUMIiI2YOt+PiPJBH28sS3UVvux4/XBLsTHAxLMw+u 4G7HSO915RjNGI8Jc4bYQZLnu0AYayHHX4Gx0lG2/V5LerSlyTdGVoSJh5N0DLERp2V5 iaVcCB4PoVfJJ4X7im/ACFmf/hbN/MjKYPuV8S55KQwFsrKfNmB0xYMFZYIeaYwGxWc9 PeFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7GPW7ASfN74rjpX0yjIvwEOj4Z6A4Vz+3oxubPbP0Jc=; fh=zQ9/wNmcVHWu4SuPOylBxCR7EoDQI9lVwbYU0s8q4Hc=; b=NrVz6uY700r26BDGn9/JiNdPzPF5BH5WKhUoqUTYVltWaCQzLWu2XPIdJgdf0BtPaA wrnu5W47u8UPz+fVlp8RBIi+Au4f9LJEVORCX/3qGGgi64xx2AVBkalIk/QmT5EZNNQe u8LstRbmG6CnuRWX3MmdsQmsDcyUlCrE92M/m8EXbaBKArHg6uAkNYNnVpcMuGVH/IWJ 8dl6WBkoys+9RhJbv0AIQeHlOBeY0SCISIwjpSZ3OLObQow5ffi8oN9kD6ZWoygAFMHV EJIoI15oISaQuoB4795xzLWMM1m+qE8alylgQ+48e7axfs0fmPqxW4f+WtPF3c1MNa3t JKtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@raspberrypi.com header.s=google header.b="g/azNR9V"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=raspberrypi.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id cn7-20020a056a020a8700b005a0737404a7si12170170pgb.258.2023.12.14.07.03.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 07:04:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@raspberrypi.com header.s=google header.b="g/azNR9V"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=raspberrypi.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id C564C829AA08; Thu, 14 Dec 2023 07:03:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573626AbjLNPDJ (ORCPT + 99 others); Thu, 14 Dec 2023 10:03:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573588AbjLNPDI (ORCPT ); Thu, 14 Dec 2023 10:03:08 -0500 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1050410F for ; Thu, 14 Dec 2023 07:03:12 -0800 (PST) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-5df49931b4eso59068307b3.0 for ; Thu, 14 Dec 2023 07:03:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1702566191; x=1703170991; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7GPW7ASfN74rjpX0yjIvwEOj4Z6A4Vz+3oxubPbP0Jc=; b=g/azNR9VJWzpRHwPNS9ZTqjL0g/xZ9qMoc02vW5sW51r2QRJd0sDbgi68ErSjpBBE0 kUrjEZmYMz1whUWEqlFtCpKDqFDKifRpw7Aj8MHcCrj+srcrp/PAAN4uaaiggwVl2leM WJDrvfmmJdLkeoTCB/3WTkMfiSpssvCVMTuc1QOTVC5XUwrfLqyk/RltrJuONZ1LDHx6 S1kHk88zj7JqRwDPYlyCLGw1F5/0ydhzlPKgHo/rUjGUtl8vI/POaTpBXa3zVOOR49+W q6QVizbHNtY8iJirN9d03zho5Adxl/nmsjvekTX5DekPVvp3kIlx0p9zNIbyok7lUUDO 7BSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702566191; x=1703170991; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7GPW7ASfN74rjpX0yjIvwEOj4Z6A4Vz+3oxubPbP0Jc=; b=rDEB0Mwax25hlG8lTXOXJC5kRo8GDU7pHZ3EP2Ocqsso8/bDg9ul2WAqORJOU21zbF U/C69FxbIKxTL3xRpv7JzfnXOkAoODRmTqKPIb0l5w88MOH1BVINwakYYCO7oa+aT/01 7MdeGixbwreZTHSYCxCKblYd0A6vapVGPTAKjkg9AglhkeDnNVhlHjWe1sGL8w3e1Q/W rTkHKoIjykbs+lnGZwAf9B/7sE+KvD+TcKQ0BwmSdWUmmtmgwmWQeBMoHMZ/X0EyLRjy 0evHVtl0SXIgsVDdVKgMA+s1yFtPWMggnUS/Erk3d22n22T1Y/WB5RzyGNuVCLm/Unfe AUew== X-Gm-Message-State: AOJu0YyIRnuCZ2No+wKVvYHwjJ25J3iyHMbnT8xwSdcF643ULIeozxS0 MJhMbfhAaAka1Lu+OhQoROrLCE2jNO4uF7W0CAXuqQ== X-Received: by 2002:a81:df06:0:b0:5d4:b7a:ebfc with SMTP id c6-20020a81df06000000b005d40b7aebfcmr8726362ywn.22.1702566191165; Thu, 14 Dec 2023 07:03:11 -0800 (PST) MIME-Version: 1.0 References: <20231207-kms-hdmi-connector-state-v5-0-6538e19d634d@kernel.org> <20231207-kms-hdmi-connector-state-v5-12-6538e19d634d@kernel.org> In-Reply-To: <20231207-kms-hdmi-connector-state-v5-12-6538e19d634d@kernel.org> From: Dave Stevenson Date: Thu, 14 Dec 2023 15:02:54 +0000 Message-ID: Subject: Re: [PATCH v5 12/44] drm/connector: hdmi: Add HDMI compute clock helper To: Maxime Ripard Cc: 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 , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Hans Verkuil , linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 14 Dec 2023 07:03:52 -0800 (PST) On Thu, 7 Dec 2023 at 15:50, Maxime Ripard wrote: > > 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. > > Signed-off-by: Maxime Ripard > --- > drivers/gpu/drm/drm_connector.c | 59 ++++++ > drivers/gpu/drm/tests/drm_connector_test.c | 323 +++++++++++++++++++++++++++++ > include/drm/drm_connector.h | 5 + > 3 files changed, 387 insertions(+) > > diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c > index a72f38b6dbc8..667326b09acc 100644 > --- a/drivers/gpu/drm/drm_connector.c > +++ b/drivers/gpu/drm/drm_connector.c > @@ -2973,6 +2973,65 @@ 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; > + > + /* > + * HDMI 1.4b Spec, section 6.2.3 - Pixel Encoding Requirements > + * specifies that YUV422 is 36-bit only. > + */ > + if (fmt == HDMI_COLORSPACE_YUV422 && bpc != 12) > + return 0; > + > + if (fmt == HDMI_COLORSPACE_YUV420) > + clock = clock / 2; > + > + if (mode->flags & DRM_MODE_FLAG_DBLCLK) > + clock = clock * 2; > + > + if (fmt == HDMI_COLORSPACE_YUV422) > + bpc = 8; Possibly a comment on why we have these munges for 420 and 422 as they aren't immediately obvious. Reviewed-by: Dave Stevenson > + > + 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/drivers/gpu/drm/tests/drm_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c > index fa6fe8084107..0a838924a546 100644 > --- a/drivers/gpu/drm/tests/drm_connector_test.c > +++ b/drivers/gpu/drm/tests/drm_connector_test.c > @@ -8,7 +8,9 @@ > #include > #include > #include > +#include > #include > +#include > > #include > > @@ -719,10 +721,331 @@ static struct kunit_suite drm_connector_attach_broadcast_rgb_property_test_suite > .test_cases = drm_connector_attach_broadcast_rgb_property_tests, > }; > > +/* > + * Test that for a given mode, with 8bpc and an RGB output the TMDS > + * character rate is equal to the mode pixel clock. > + */ > +static void drm_test_drm_connector_hdmi_compute_mode_clock_rgb(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + unsigned long long rate; > + struct drm_device *drm = &priv->drm; > + > + mode = drm_display_mode_from_cea_vic(drm, 16); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + KUNIT_ASSERT_FALSE(test, mode->flags & DRM_MODE_FLAG_DBLCLK); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 8, HDMI_COLORSPACE_RGB); > + KUNIT_ASSERT_GT(test, rate, 0); > + KUNIT_EXPECT_EQ(test, mode->clock * 1000ULL, rate); > +} > + > +/* > + * Test that for a given mode, with 10bpc and an RGB output the TMDS > + * character rate is equal to 1.25 times the mode pixel clock. > + */ > +static void drm_test_drm_connector_hdmi_compute_mode_clock_rgb_10bpc(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + unsigned long long rate; > + struct drm_device *drm = &priv->drm; > + > + mode = drm_display_mode_from_cea_vic(drm, 16); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + KUNIT_ASSERT_FALSE(test, mode->flags & DRM_MODE_FLAG_DBLCLK); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 10, HDMI_COLORSPACE_RGB); > + KUNIT_ASSERT_GT(test, rate, 0); > + KUNIT_EXPECT_EQ(test, mode->clock * 1250, rate); > +} > + > +/* > + * Test that for the VIC-1 mode, with 10bpc and an RGB output the TMDS > + * character rate computation fails. > + */ > +static void drm_test_drm_connector_hdmi_compute_mode_clock_rgb_10bpc_vic_1(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + unsigned long long rate; > + struct drm_device *drm = &priv->drm; > + > + mode = drm_display_mode_from_cea_vic(drm, 1); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 10, HDMI_COLORSPACE_RGB); > + KUNIT_EXPECT_EQ(test, rate, 0); > +} > + > +/* > + * Test that for a given mode, with 12bpc and an RGB output the TMDS > + * character rate is equal to 1.5 times the mode pixel clock. > + */ > +static void drm_test_drm_connector_hdmi_compute_mode_clock_rgb_12bpc(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + unsigned long long rate; > + struct drm_device *drm = &priv->drm; > + > + mode = drm_display_mode_from_cea_vic(drm, 16); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + KUNIT_ASSERT_FALSE(test, mode->flags & DRM_MODE_FLAG_DBLCLK); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 12, HDMI_COLORSPACE_RGB); > + KUNIT_ASSERT_GT(test, rate, 0); > + KUNIT_EXPECT_EQ(test, mode->clock * 1500, rate); > +} > + > +/* > + * Test that for the VIC-1 mode, with 12bpc and an RGB output the TMDS > + * character rate computation fails. > + */ > +static void drm_test_drm_connector_hdmi_compute_mode_clock_rgb_12bpc_vic_1(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + unsigned long long rate; > + struct drm_device *drm = &priv->drm; > + > + mode = drm_display_mode_from_cea_vic(drm, 1); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 12, HDMI_COLORSPACE_RGB); > + KUNIT_EXPECT_EQ(test, rate, 0); > +} > + > +/* > + * Test that for a mode with the pixel repetition flag, the TMDS > + * character rate is indeed double the mode pixel clock. > + */ > +static void drm_test_drm_connector_hdmi_compute_mode_clock_rgb_double(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + unsigned long long rate; > + struct drm_device *drm = &priv->drm; > + > + mode = drm_display_mode_from_cea_vic(drm, 6); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + KUNIT_ASSERT_TRUE(test, mode->flags & DRM_MODE_FLAG_DBLCLK); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 8, HDMI_COLORSPACE_RGB); > + KUNIT_ASSERT_GT(test, rate, 0); > + KUNIT_EXPECT_EQ(test, (mode->clock * 1000ULL) * 2, rate); > +} > + > +/* > + * Test that the TMDS character rate computation for the VIC modes > + * explicitly listed in the spec as supporting YUV420 succeed and return > + * half the mode pixel clock. > + */ > +static void drm_test_connector_hdmi_compute_mode_clock_yuv420_valid(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + struct drm_device *drm = &priv->drm; > + unsigned long long rate; > + unsigned int vic = *(unsigned int *)test->param_value; > + > + mode = drm_display_mode_from_cea_vic(drm, vic); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + KUNIT_ASSERT_FALSE(test, mode->flags & DRM_MODE_FLAG_DBLCLK); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 8, HDMI_COLORSPACE_YUV420); > + KUNIT_ASSERT_GT(test, rate, 0); > + KUNIT_EXPECT_EQ(test, (mode->clock * 1000ULL) / 2, rate); > +} > + > +static const unsigned int drm_connector_hdmi_compute_mode_clock_yuv420_vic_valid_tests[] = { > + 96, 97, 101, 102, 106, 107, > +}; > + > +static void drm_connector_hdmi_compute_mode_clock_yuv420_vic_desc(const unsigned int *vic, char *desc) > +{ > + sprintf(desc, "VIC %u", *vic); > +} > + > +KUNIT_ARRAY_PARAM(drm_connector_hdmi_compute_mode_clock_yuv420_valid, > + drm_connector_hdmi_compute_mode_clock_yuv420_vic_valid_tests, > + drm_connector_hdmi_compute_mode_clock_yuv420_vic_desc); > + > +/* > + * Test that trying to compute the TMDS char rate with the YUV420 format > + * for a mode that doesn't support the YUV420 encoding returns an error. > + * > + * TODO: We should probably test this with all the VIC but the > + * explicitly supported ones. Since the list of VIC is quite long and > + * not linear, the best way to support it at the moment would be to > + * create a custom gen_params function that would only return valid > + * VICs. At the moment, that function expects to get a pointer back > + * however, and compilers don't really like casting between integer and > + * pointers. > + */ > +static void drm_test_connector_hdmi_compute_mode_clock_yuv420_invalid(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + struct drm_device *drm = &priv->drm; > + unsigned long long rate; > + > + mode = drm_display_mode_from_cea_vic(drm, 42); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + KUNIT_ASSERT_FALSE(test, mode->flags & DRM_MODE_FLAG_DBLCLK); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 8, HDMI_COLORSPACE_YUV420); > + KUNIT_EXPECT_EQ(test, rate, 0); > +} > + > +/* > + * Test that for a given mode listed supporting it and an YUV420 output > + * with 10bpc, the TMDS character rate is equal to 0.625 times the mode > + * pixel clock. > + */ > +static void drm_test_connector_hdmi_compute_mode_clock_yuv420_10_bpc(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + struct drm_device *drm = &priv->drm; > + unsigned int vic = > + drm_connector_hdmi_compute_mode_clock_yuv420_vic_valid_tests[0]; > + unsigned long long rate; > + > + mode = drm_display_mode_from_cea_vic(drm, vic); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + KUNIT_ASSERT_FALSE(test, mode->flags & DRM_MODE_FLAG_DBLCLK); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 10, HDMI_COLORSPACE_YUV420); > + KUNIT_ASSERT_GT(test, rate, 0); > + > + KUNIT_EXPECT_EQ(test, mode->clock * 625, rate); > +} > + > +/* > + * Test that for a given mode listed supporting it and an YUV420 output > + * with 12bpc, the TMDS character rate is equal to 0.75 times the mode > + * pixel clock. > + */ > +static void drm_test_connector_hdmi_compute_mode_clock_yuv420_12_bpc(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + struct drm_device *drm = &priv->drm; > + unsigned int vic = > + drm_connector_hdmi_compute_mode_clock_yuv420_vic_valid_tests[0]; > + unsigned long long rate; > + > + mode = drm_display_mode_from_cea_vic(drm, vic); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + KUNIT_ASSERT_FALSE(test, mode->flags & DRM_MODE_FLAG_DBLCLK); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 12, HDMI_COLORSPACE_YUV420); > + KUNIT_ASSERT_GT(test, rate, 0); > + > + KUNIT_EXPECT_EQ(test, mode->clock * 750, rate); > +} > + > +/* > + * Test that for a given mode, the computation of the TMDS character > + * rate with 8bpc and a YUV422 output fails. > + */ > +static void drm_test_connector_hdmi_compute_mode_clock_yuv422_8_bpc(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + struct drm_device *drm = &priv->drm; > + unsigned long long rate; > + > + mode = drm_display_mode_from_cea_vic(drm, 16); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + KUNIT_ASSERT_FALSE(test, mode->flags & DRM_MODE_FLAG_DBLCLK); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 8, HDMI_COLORSPACE_YUV422); > + KUNIT_EXPECT_EQ(test, rate, 0); > +} > + > +/* > + * Test that for a given mode, the computation of the TMDS character > + * rate with 10bpc and a YUV422 output fails. > + */ > +static void drm_test_connector_hdmi_compute_mode_clock_yuv422_10_bpc(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + struct drm_device *drm = &priv->drm; > + unsigned long long rate; > + > + mode = drm_display_mode_from_cea_vic(drm, 16); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + KUNIT_ASSERT_FALSE(test, mode->flags & DRM_MODE_FLAG_DBLCLK); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 10, HDMI_COLORSPACE_YUV422); > + KUNIT_EXPECT_EQ(test, rate, 0); > +} > + > +/* > + * Test that for a given mode, the computation of the TMDS character > + * rate with 12bpc and a YUV422 output succeeds and returns a rate equal > + * to the mode pixel clock. > + */ > +static void drm_test_connector_hdmi_compute_mode_clock_yuv422_12_bpc(struct kunit *test) > +{ > + struct drm_connector_init_priv *priv = test->priv; > + const struct drm_display_mode *mode; > + struct drm_device *drm = &priv->drm; > + unsigned long long rate; > + > + mode = drm_display_mode_from_cea_vic(drm, 16); > + KUNIT_ASSERT_NOT_NULL(test, mode); > + > + KUNIT_ASSERT_FALSE(test, mode->flags & DRM_MODE_FLAG_DBLCLK); > + > + rate = drm_connector_hdmi_compute_mode_clock(mode, 12, HDMI_COLORSPACE_YUV422); > + KUNIT_ASSERT_GT(test, rate, 0); > + KUNIT_EXPECT_EQ(test, mode->clock * 1000, rate); > +} > + > +static struct kunit_case drm_connector_hdmi_compute_mode_clock_tests[] = { > + KUNIT_CASE(drm_test_drm_connector_hdmi_compute_mode_clock_rgb), > + KUNIT_CASE(drm_test_drm_connector_hdmi_compute_mode_clock_rgb_10bpc), > + KUNIT_CASE(drm_test_drm_connector_hdmi_compute_mode_clock_rgb_10bpc_vic_1), > + KUNIT_CASE(drm_test_drm_connector_hdmi_compute_mode_clock_rgb_12bpc), > + KUNIT_CASE(drm_test_drm_connector_hdmi_compute_mode_clock_rgb_12bpc_vic_1), > + KUNIT_CASE(drm_test_drm_connector_hdmi_compute_mode_clock_rgb_double), > + KUNIT_CASE_PARAM(drm_test_connector_hdmi_compute_mode_clock_yuv420_valid, > + drm_connector_hdmi_compute_mode_clock_yuv420_valid_gen_params), > + KUNIT_CASE(drm_test_connector_hdmi_compute_mode_clock_yuv420_invalid), > + KUNIT_CASE(drm_test_connector_hdmi_compute_mode_clock_yuv420_10_bpc), > + KUNIT_CASE(drm_test_connector_hdmi_compute_mode_clock_yuv420_12_bpc), > + KUNIT_CASE(drm_test_connector_hdmi_compute_mode_clock_yuv422_8_bpc), > + KUNIT_CASE(drm_test_connector_hdmi_compute_mode_clock_yuv422_10_bpc), > + KUNIT_CASE(drm_test_connector_hdmi_compute_mode_clock_yuv422_12_bpc), > + { } > +}; > + > +static struct kunit_suite drm_connector_hdmi_compute_mode_clock_test_suite = { > + .name = "drm_test_connector_hdmi_compute_mode_clock", > + .init = drm_test_connector_init, > + .test_cases = drm_connector_hdmi_compute_mode_clock_tests, > +}; > + > kunit_test_suites( > &drmm_connector_hdmi_init_test_suite, > &drmm_connector_init_test_suite, > &drm_connector_attach_broadcast_rgb_property_test_suite, > + &drm_connector_hdmi_compute_mode_clock_test_suite, > &drm_get_tv_mode_from_name_test_suite, > &drm_hdmi_connector_get_broadcast_rgb_name_test_suite, > &drm_hdmi_connector_get_output_format_name_test_suite > 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 > > -- > 2.43.0 >