ARM Sunxi Platform Development
 help / color / mirror / Atom feed
From: "Noralf Trønnes" <noralf@tronnes.org>
To: Maxime Ripard <maxime@cerno.tech>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
	Ben Skeggs <bskeggs@redhat.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Samuel Holland <samuel@sholland.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Emma Anholt <emma@anholt.net>, Karol Herbst <kherbst@redhat.com>,
	Daniel Vetter <daniel@ffwll.ch>, Chen-Yu Tsai <wens@csie.org>,
	Lyude Paul <lyude@redhat.com>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@linux.ie>
Cc: "Phil Elwell" <phil@raspberrypi.com>,
	"Hans de Goede" <hdegoede@redhat.com>,
	linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org,
	"Geert Uytterhoeven" <geert@linux-m68k.org>,
	"Dave Stevenson" <dave.stevenson@raspberrypi.com>,
	linux-arm-kernel@lists.infradead.org,
	"Dom Cobley" <dom@raspberrypi.com>,
	"Mateusz Kwiatkowski" <kfyatek+publicgit@gmail.com>,
	dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	nouveau@lists.freedesktop.org,
	"Noralf Trønnes" <noralf@tronnes.org>
Subject: Re: [PATCH v7 14/23] drm/modes: Properly generate a drm_display_mode from a named mode
Date: Mon, 7 Nov 2022 18:49:57 +0100	[thread overview]
Message-ID: <9e9a8a48-89f2-35d4-b26f-afa7cc44f2f6@tronnes.org> (raw)
In-Reply-To: <20220728-rpi-analog-tv-properties-v7-14-7072a478c6b3@cerno.tech>



Den 07.11.2022 15.16, skrev Maxime Ripard:
> 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 <maxime@cerno.tech>
> 
> ---
> Changes in v7:
> - Use tv_mode_specified in drm_mode_parse_command_line_for_connector
> 
> Changes in v6:
> - Fix get_modes to return 0 instead of an error code
> - Rename the tests to follow the DRM test naming convention
> 
> Changes in v5:
> - Switched to KUNIT_ASSERT_NOT_NULL
> ---
>  drivers/gpu/drm/drm_modes.c                     | 34 ++++++++++-
>  drivers/gpu/drm/tests/drm_client_modeset_test.c | 77 ++++++++++++++++++++++++-
>  2 files changed, 109 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> index dc037f7ceb37..49441cabdd9d 100644
> --- a/drivers/gpu/drm/drm_modes.c
> +++ b/drivers/gpu/drm/drm_modes.c
> @@ -2497,6 +2497,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 (!cmd->tv_mode_specified)
> +			continue;

Only a named mode will set cmd->name, so is this check necessary?

> +
> +		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;

You can just return the result from drm_analog_tv_mode() directly.

With those considered:

Reviewed-by: Noralf Trønnes <noralf@tronnes.org>

> +	}
> +
> +	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
> @@ -2514,7 +2544,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 3aa1acfe75df..fdfe9e20702e 100644
> --- a/drivers/gpu/drm/tests/drm_client_modeset_test.c
> +++ b/drivers/gpu/drm/tests/drm_client_modeset_test.c
> @@ -21,7 +21,26 @@ struct drm_client_modeset_test_priv {
>  
>  static int drm_client_modeset_connector_get_modes(struct drm_connector *connector)
>  {
> -	return drm_add_modes_noedid(connector, 1920, 1200);
> +	struct drm_display_mode *mode;
> +	int count;
> +
> +	count = drm_add_modes_noedid(connector, 1920, 1200);
> +
> +	mode = drm_mode_analog_ntsc_480i(connector->dev);
> +	if (!mode)
> +		return count;
> +
> +	drm_mode_probed_add(connector, mode);
> +	count += 1;
> +
> +	mode = drm_mode_analog_pal_576i(connector->dev);
> +	if (!mode)
> +		return count;
> +
> +	drm_mode_probed_add(connector, mode);
> +	count += 1;
> +
> +	return count;
>  }
>  
>  static const struct drm_connector_helper_funcs drm_client_modeset_connector_helper_funcs = {
> @@ -52,6 +71,9 @@ static int drm_client_modeset_test_init(struct kunit *test)
>  
>  	drm_connector_helper_add(&priv->connector, &drm_client_modeset_connector_helper_funcs);
>  
> +	priv->connector.interlace_allowed = true;
> +	priv->connector.doublescan_allowed = true;
> +
>  	return 0;
>  
>  }
> @@ -85,9 +107,62 @@ static void drm_test_pick_cmdline_res_1920_1080_60(struct kunit *test)
>  	KUNIT_EXPECT_TRUE(test, drm_mode_equal(expected_mode, mode));
>  }
>  
> +static void drm_test_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_NOT_NULL(test, mode);
> +
> +	KUNIT_EXPECT_TRUE(test, drm_mode_equal(drm_mode_analog_ntsc_480i(drm), mode));
> +}
> +
> +static void drm_test_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_NOT_NULL(test, mode);
> +
> +	KUNIT_EXPECT_TRUE(test, drm_mode_equal(drm_mode_analog_pal_576i(drm), mode));
> +}
>  
>  static struct kunit_case drm_test_pick_cmdline_tests[] = {
>  	KUNIT_CASE(drm_test_pick_cmdline_res_1920_1080_60),
> +	KUNIT_CASE(drm_test_pick_cmdline_named_ntsc),
> +	KUNIT_CASE(drm_test_pick_cmdline_named_pal),
>  	{}
>  };
>  
> 

  reply	other threads:[~2022-11-07 17:50 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 14:16 [PATCH v7 00/23] drm: Analog TV Improvements Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 01/23] drm/tests: Add Kunit Helpers Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 02/23] drm/connector: Rename legacy TV property Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 03/23] drm/connector: Only register TV mode property if present Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 04/23] drm/connector: Rename drm_mode_create_tv_properties Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 05/23] drm/connector: Add TV standard property Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 06/23] drm/modes: Add a function to generate analog display modes Maxime Ripard
     [not found]   ` <CAEFVmOJbjK2iug+UsxD8w7W0RTc0AGD=wxB5bX-es=Qc-Mcgrw@mail.gmail.com>
2022-11-08 21:51     ` [Nouveau] " Mateusz Kwiatkowski
2022-11-07 14:16 ` [PATCH v7 07/23] drm/client: Add some tests for drm_connector_pick_cmdline_mode() Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 08/23] drm/modes: Move named modes parsing to a separate function Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 09/23] drm/modes: Switch to named mode descriptors Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 10/23] drm/modes: Fill drm_cmdline mode from named modes Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 11/23] drm/connector: Add pixel clock to cmdline mode Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 12/23] drm/connector: Add a function to lookup a TV mode by its name Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 13/23] drm/modes: Introduce the tv_mode property as a command-line option Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 14/23] drm/modes: Properly generate a drm_display_mode from a named mode Maxime Ripard
2022-11-07 17:49   ` Noralf Trønnes [this message]
2022-11-08  9:40     ` Noralf Trønnes
2022-11-10 10:36       ` Maxime Ripard
2022-11-10  9:31     ` Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 15/23] drm/modes: Introduce more named modes Maxime Ripard
2022-11-07 18:03   ` Noralf Trønnes
2022-11-08  9:38     ` Noralf Trønnes
2022-11-08 21:27       ` Mateusz Kwiatkowski
2022-11-09 11:18         ` Maxime Ripard
2022-11-09 14:09   ` Noralf Trønnes
2022-11-07 14:16 ` [PATCH v7 16/23] drm/probe-helper: Provide a TV get_modes helper Maxime Ripard
2022-11-07 18:11   ` Noralf Trønnes
2022-11-09 15:41     ` Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 17/23] drm/atomic-helper: Add a TV properties reset helper Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 18/23] drm/atomic-helper: Add an analog TV atomic_check implementation Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 19/23] drm/vc4: vec: Use TV Reset implementation Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 20/23] drm/vc4: vec: Check for VEC output constraints Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 21/23] drm/vc4: vec: Convert to the new TV mode property Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 22/23] drm/vc4: vec: Add support for more analog TV standards Maxime Ripard
     [not found]   ` <CAEFVmOKn4Won90xyX2Efh2esZ94npoy0BuTQ7n-in+KapfBb=w@mail.gmail.com>
2022-11-08 22:16     ` [Nouveau] " Mateusz Kwiatkowski
2022-11-09  1:15   ` Mateusz Kwiatkowski
     [not found]     ` <CAEFVmOJ5A7+hUPwb3yUiVegJfUb_1-DGKu1YUCsF=hFTrjASzA@mail.gmail.com>
2022-11-10 10:39       ` [Nouveau] " Maxime Ripard
2022-11-10 10:57     ` Maxime Ripard
2022-11-07 14:16 ` [PATCH v7 23/23] drm/sun4i: tv: Convert to the new TV mode property Maxime Ripard
     [not found] ` <CAEFVmOKCTc_ZrFyCxiSwCmhtjJj_fzr6n99cWtb9aECFzzYVXg@mail.gmail.com>
2022-11-08 13:42   ` [Nouveau] [PATCH v7 00/23] drm: Analog TV Improvements Geert Uytterhoeven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9e9a8a48-89f2-35d4-b26f-afa7cc44f2f6@tronnes.org \
    --to=noralf@tronnes.org \
    --cc=airlied@linux.ie \
    --cc=bskeggs@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=dom@raspberrypi.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emma@anholt.net \
    --cc=geert@linux-m68k.org \
    --cc=hdegoede@redhat.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=kfyatek+publicgit@gmail.com \
    --cc=kherbst@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=lyude@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=maxime@cerno.tech \
    --cc=mripard@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=phil@raspberrypi.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=samuel@sholland.org \
    --cc=tvrtko.ursulin@linux.intel.com \
    --cc=tzimmermann@suse.de \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox