From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E8D1C433FE for ; Thu, 29 Sep 2022 16:33:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1F88F10EB07; Thu, 29 Sep 2022 16:32:19 +0000 (UTC) Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by gabe.freedesktop.org (Postfix) with ESMTPS id 831EC10EAEB; Thu, 29 Sep 2022 16:32:02 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailnew.nyi.internal (Postfix) with ESMTP id E35DA580800; Thu, 29 Sep 2022 12:32:01 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 29 Sep 2022 12:32:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1664469121; x= 1664476321; bh=tekZyJgnbZzTiBcFrLNytvn+Y16abjURvheDBR7vB+c=; b=n IcmPmls7gKgAcD3BQqqQes0OxqTE+ufUjhxff7BtDKYyZiDPZ7ypwCakCPfXSJbt o99WqP9xSykd/yGTvNJMhydXzA7ALiDmCR1Ig1Hp6Q9q26OJAuv2kHcGXvXEpHDz VfWkw03tzOMmU68gH5CmRq2m5SRTjoL6KO3Q99KncUlllNUjoKFGIZpd5Du3rGD7 8ce/CFfu9pFe2Sjvoxq4t0fOT7CWB/+HYI3n33IAg800CHf8UhX43kNGj0uCBbt9 nac15sF8kwySO/bQBx/xOXMOWC2n1YWmDvJK1o+o332Y7+T/rRBAnwddJcbx2+z0 D/EN9ZTr6RrvfVLBB/ycg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1664469121; x= 1664476321; bh=tekZyJgnbZzTiBcFrLNytvn+Y16abjURvheDBR7vB+c=; b=k Ae3BUUjbVRgmV+TUCCHEabLHU4UHNuz2JFtkC+ZWMRxjei+M57CjXMBsC7ChAWv1 TLxCXd99mwMnyT/N/Y/dI9u2+a5HNZBWEoERkxB5XzzSo+eiljAdwPyu6eFi8IND lWgMvz7VlPhfk6XIviMpzIMQFcUG9anDd7GKKozsBx4gztAdY69N5v2OH9NiTQZ4 JzJqY6wQdYOnmF/FhJntQuacrX/qruguCit8djay5rwbdfQP5dIRWy80W49kwyAS HyRTZ405VPa97+N6ZvTTJf39Zew8WP0LSGYs3lP3H7hf9g5XZYHvl93VPxOPA7jD HlN0LODAzmeXdd9LIjzpg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeehtddguddtfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthekredtredtjeenucfhrhhomhepofgr gihimhgvucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtf frrghtthgvrhhnpeduudduhfevjeetfeegvdffvdevvdejudegudekjeehtdelhfffveet hfejledtveenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehmrgigihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Sep 2022 12:32:01 -0400 (EDT) From: Maxime Ripard Date: Thu, 29 Sep 2022 18:31:15 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20220728-rpi-analog-tv-properties-v4-21-60d38873f782@cerno.tech> References: <20220728-rpi-analog-tv-properties-v4-0-60d38873f782@cerno.tech> In-Reply-To: <20220728-rpi-analog-tv-properties-v4-0-60d38873f782@cerno.tech> To: Jernej Skrabec , Chen-Yu Tsai , Karol Herbst , Samuel Holland , Lyude Paul , Jani Nikula , Daniel Vetter , Thomas Zimmermann , Emma Anholt , Joonas Lahtinen , Ben Skeggs , David Airlie , Rodrigo Vivi , Tvrtko Ursulin , Maarten Lankhorst , Maxime Ripard X-Mailer: b4 0.11.0-dev-7da52 X-Developer-Signature: v=1; a=openpgp-sha256; l=5614; i=maxime@cerno.tech; h=from:subject:message-id; bh=YDGuC6ATS7JvNzn/WLllVLT4srcgAU+Ea5/GW0Bp/aQ=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDMmmJ9zj8lYcijeWDDMRV7mu8LdleeGPI75rznCqXZvV6vrK JP5kRykLgxgXg6yYIkuMsPmSuFOzXney8c2DmcPKBDKEgYtTACYS6MXwP57n26cLZqJFfMd0Em5t+X H27s1Vq75snPRf+/3a2phHz6uBKj4fWS8q3XCvPO1sKG/E2t1sb/UYdmoxl611av5SGrGcFwA= X-Developer-Key: i=maxime@cerno.tech; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D Subject: [Nouveau] [PATCH v4 21/30] drm/modes: Properly generate a drm_display_mode from a named mode X-BeenThere: nouveau@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Nouveau development list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dom Cobley , Phil Elwell , nouveau@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Mateusz Kwiatkowski , Hans de Goede , Noralf Trønnes , Geert Uytterhoeven , Maxime Ripard , linux-sunxi@lists.linux.dev, linux-arm-kernel@lists.infradead.org Errors-To: nouveau-bounces@lists.freedesktop.org Sender: "Nouveau" The framework will get the drm_display_mode from the drm_cmdline_mode it got by parsing the video command line argument by calling drm_connector_pick_cmdline_mode(). The heavy lifting will then be done by the drm_mode_create_from_cmdline_mode() function. In the case of the named modes though, there's no real code to make that translation and we rely on the drivers to guess which actual display mode we meant. Let's modify drm_mode_create_from_cmdline_mode() to properly generate the drm_display_mode we mean when passing a named mode. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_modes.c | 34 +++++++++++- drivers/gpu/drm/tests/drm_client_modeset_test.c | 71 +++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c index c9b62e30e303..fe818252cd8f 100644 --- a/drivers/gpu/drm/drm_modes.c +++ b/drivers/gpu/drm/drm_modes.c @@ -2500,6 +2500,36 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, } EXPORT_SYMBOL(drm_mode_parse_command_line_for_connector); +static struct drm_display_mode *drm_named_mode(struct drm_device *dev, + struct drm_cmdline_mode *cmd) +{ + struct drm_display_mode *mode; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(drm_named_modes); i++) { + const struct drm_named_mode *named_mode = &drm_named_modes[i]; + + if (strcmp(cmd->name, named_mode->name)) + continue; + + if (!named_mode->tv_mode) + continue; + + mode = drm_analog_tv_mode(dev, + named_mode->tv_mode, + named_mode->pixel_clock_khz * 1000, + named_mode->xres, + named_mode->yres, + named_mode->flags & DRM_MODE_FLAG_INTERLACE); + if (!mode) + return NULL; + + return mode; + } + + return NULL; +} + /** * drm_mode_create_from_cmdline_mode - convert a command line modeline into a DRM display mode * @dev: DRM device to create the new mode for @@ -2517,7 +2547,9 @@ drm_mode_create_from_cmdline_mode(struct drm_device *dev, if (cmd->xres == 0 || cmd->yres == 0) return NULL; - if (cmd->cvt) + if (strlen(cmd->name)) + mode = drm_named_mode(dev, cmd); + else if (cmd->cvt) mode = drm_cvt_mode(dev, cmd->xres, cmd->yres, cmd->refresh_specified ? cmd->refresh : 60, diff --git a/drivers/gpu/drm/tests/drm_client_modeset_test.c b/drivers/gpu/drm/tests/drm_client_modeset_test.c index 09dc5acbbc42..b59029b49201 100644 --- a/drivers/gpu/drm/tests/drm_client_modeset_test.c +++ b/drivers/gpu/drm/tests/drm_client_modeset_test.c @@ -26,6 +26,20 @@ static int drm_client_modeset_connector_get_modes(struct drm_connector *connecto count = drm_add_modes_noedid(connector, 1920, 1200); + mode = drm_mode_analog_ntsc_480i(connector->dev); + if (!mode) + return -ENOMEM; + + drm_mode_probed_add(connector, mode); + count += 1; + + mode = drm_mode_analog_pal_576i(connector->dev); + if (!mode) + return -ENOMEM; + + drm_mode_probed_add(connector, mode); + count += 1; + return count; } @@ -58,6 +72,9 @@ static int drm_client_modeset_test_init(struct kunit *test) return ret; drm_connector_helper_add(&priv->connector, &drm_client_modeset_connector_helper_funcs); + priv->connector.interlace_allowed = true; + priv->connector.doublescan_allowed = true; + return 0; } @@ -91,8 +108,62 @@ static void drm_pick_cmdline_res_1920_1080_60(struct kunit *test) KUNIT_EXPECT_TRUE(test, drm_mode_equal(expected_mode, mode)); } +static void drm_pick_cmdline_named_ntsc(struct kunit *test) +{ + struct drm_client_modeset_test_priv *priv = test->priv; + struct drm_device *drm = priv->drm; + struct drm_connector *connector = &priv->connector; + struct drm_cmdline_mode *cmdline_mode = &connector->cmdline_mode; + struct drm_display_mode *mode; + const char *cmdline = "NTSC"; + int ret; + + KUNIT_ASSERT_TRUE(test, + drm_mode_parse_command_line_for_connector(cmdline, + connector, + cmdline_mode)); + + mutex_lock(&drm->mode_config.mutex); + ret = drm_helper_probe_single_connector_modes(connector, 1920, 1080); + mutex_unlock(&drm->mode_config.mutex); + KUNIT_ASSERT_GT(test, ret, 0); + + mode = drm_connector_pick_cmdline_mode(connector); + KUNIT_ASSERT_PTR_NE(test, mode, NULL); + + KUNIT_EXPECT_TRUE(test, drm_mode_equal(drm_mode_analog_ntsc_480i(drm), mode)); +} + +static void drm_pick_cmdline_named_pal(struct kunit *test) +{ + struct drm_client_modeset_test_priv *priv = test->priv; + struct drm_device *drm = priv->drm; + struct drm_connector *connector = &priv->connector; + struct drm_cmdline_mode *cmdline_mode = &connector->cmdline_mode; + struct drm_display_mode *mode; + const char *cmdline = "PAL"; + int ret; + + KUNIT_ASSERT_TRUE(test, + drm_mode_parse_command_line_for_connector(cmdline, + connector, + cmdline_mode)); + + mutex_lock(&drm->mode_config.mutex); + ret = drm_helper_probe_single_connector_modes(connector, 1920, 1080); + mutex_unlock(&drm->mode_config.mutex); + KUNIT_ASSERT_GT(test, ret, 0); + + mode = drm_connector_pick_cmdline_mode(connector); + KUNIT_ASSERT_PTR_NE(test, mode, NULL); + + KUNIT_EXPECT_TRUE(test, drm_mode_equal(drm_mode_analog_pal_576i(drm), mode)); +} + static struct kunit_case drm_pick_cmdline_tests[] = { KUNIT_CASE(drm_pick_cmdline_res_1920_1080_60), + KUNIT_CASE(drm_pick_cmdline_named_ntsc), + KUNIT_CASE(drm_pick_cmdline_named_pal), {} }; -- b4 0.11.0-dev-7da52