* Re: [PATCH v8 06/24] drm/modes: Add a function to generate analog display modes
[not found] ` <20220728-rpi-analog-tv-properties-v8-6-09ce1466967c@cerno.tech>
@ 2022-11-10 23:01 ` Maíra Canal
0 siblings, 0 replies; 7+ messages in thread
From: Maíra Canal @ 2022-11-10 23:01 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, Chen-Yu Tsai, Maxime Ripard,
Jernej Skrabec, Karol Herbst, Jani Nikula, Daniel Vetter,
Lyude Paul, Samuel Holland, Joonas Lahtinen, Thomas Zimmermann,
Emma Anholt, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Ben Skeggs
Cc: Dom Cobley, Dave Stevenson, nouveau, intel-gfx, linux-kernel,
dri-devel, Phil Elwell, Hans de Goede, Noralf Trønnes,
Geert Uytterhoeven, Mateusz Kwiatkowski, linux-sunxi,
linux-arm-kernel
Hi Maxime,
On 11/10/22 08:07, Maxime Ripard wrote:
> Multiple drivers (meson, vc4, sun4i) define analog TV 525-lines and
> 625-lines modes in their drivers.
>
> Since those modes are fairly standard, and that we'll need to use them
> in more places in the future, it makes sense to move their definition
> into the core framework.
>
> However, analog display usually have fairly loose timings requirements,
> the only discrete parameters being the total number of lines and pixel
> clock frequency. Thus, we created a function that will create a display
> mode from the standard, the pixel frequency and the active area.
>
> Tested-by: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
>
> ---
> Changes in v6:
> - Fix typo
>
> Changes in v4:
> - Reworded the line length check comment
> - Switch to HZ_PER_KHZ in tests
> - Use previous timing to fill our mode
> - Move the number of lines check earlier
> ---
> drivers/gpu/drm/drm_modes.c | 474 +++++++++++++++++++++++++++++++++
> drivers/gpu/drm/tests/Makefile | 1 +
> drivers/gpu/drm/tests/drm_modes_test.c | 145 ++++++++++
> include/drm/drm_modes.h | 17 ++
> 4 files changed, 637 insertions(+)
>
> diff --git a/drivers/gpu/drm/tests/drm_modes_test.c b/drivers/gpu/drm/tests/drm_modes_test.c
> new file mode 100644
> index 000000000000..afeda9f07859
> --- /dev/null
> +++ b/drivers/gpu/drm/tests/drm_modes_test.c
> @@ -0,0 +1,145 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Kunit test for drm_modes functions
> + */
> +
> +#include <drm/drm_drv.h>
> +#include <drm/drm_modes.h>
> +
> +#include <kunit/test.h>
> +
> +#include <linux/units.h>
> +
> +#include "drm_kunit_helpers.h"
> +
> +struct drm_modes_test_priv {
> + struct drm_device *drm;
> +};
> +
> +static int drm_modes_test_init(struct kunit *test)
> +{
> + struct drm_modes_test_priv *priv;
> +
> + priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
> + KUNIT_ASSERT_NOT_NULL(test, priv);
> +
> + priv->drm = drm_kunit_device_init(test, DRIVER_MODESET, "drm-modes-test");
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->drm);
> +
> + test->priv = priv;
> +
> + return 0;
> +}
> +
As you did on the other tests, it would be nice to use the same naming
convention as the other DRM tests. So, maybe change the "drm_modes"
prefix to "drm_test_modes".
> +static void drm_modes_analog_tv_ntsc_480i(struct kunit *test)
> +{
> + struct drm_modes_test_priv *priv = test->priv;
> + struct drm_display_mode *mode;
> +
> + mode = drm_analog_tv_mode(priv->drm,
> + DRM_MODE_TV_MODE_NTSC,
> + 13500 * HZ_PER_KHZ, 720, 480,
> + true);
> + KUNIT_ASSERT_NOT_NULL(test, mode);
> +
> + KUNIT_EXPECT_EQ(test, drm_mode_vrefresh(mode), 60);
> + KUNIT_EXPECT_EQ(test, mode->hdisplay, 720);
> +
> + /* BT.601 defines hsync_start at 736 for 480i */
> + KUNIT_EXPECT_EQ(test, mode->hsync_start, 736);
> +
> + /*
> + * The NTSC standard expects a line to take 63.556us. With a
> + * pixel clock of 13.5 MHz, a pixel takes around 74ns, so we
> + * need to have 63556ns / 74ns = 858.
> + *
> + * This is also mandated by BT.601.
> + */
> + KUNIT_EXPECT_EQ(test, mode->htotal, 858);
> +
> + KUNIT_EXPECT_EQ(test, mode->vdisplay, 480);
> + KUNIT_EXPECT_EQ(test, mode->vtotal, 525);
> +}
> +
> +static void drm_modes_analog_tv_ntsc_480i_inlined(struct kunit *test)
> +{
> + struct drm_modes_test_priv *priv = test->priv;
> + struct drm_display_mode *expected, *mode;
> +
> + expected = drm_analog_tv_mode(priv->drm,
> + DRM_MODE_TV_MODE_NTSC,
> + 13500 * HZ_PER_KHZ, 720, 480,
> + true);
> + KUNIT_ASSERT_NOT_NULL(test, expected);
> +
> + mode = drm_mode_analog_ntsc_480i(priv->drm);
> + KUNIT_ASSERT_NOT_NULL(test, mode);
> +
> + KUNIT_EXPECT_TRUE(test, drm_mode_equal(expected, mode));
> +}
> +
> +static void drm_modes_analog_tv_pal_576i(struct kunit *test)
> +{
> + struct drm_modes_test_priv *priv = test->priv;
> + struct drm_display_mode *mode;
> +
> + mode = drm_analog_tv_mode(priv->drm,
> + DRM_MODE_TV_MODE_PAL,
> + 13500 * HZ_PER_KHZ, 720, 576,
> + true);
> + KUNIT_ASSERT_NOT_NULL(test, mode);
> +
> + KUNIT_EXPECT_EQ(test, drm_mode_vrefresh(mode), 50);
> + KUNIT_EXPECT_EQ(test, mode->hdisplay, 720);
> +
> + /* BT.601 defines hsync_start at 732 for 576i */
> + KUNIT_EXPECT_EQ(test, mode->hsync_start, 732);
> +
> + /*
> + * The PAL standard expects a line to take 64us. With a pixel
> + * clock of 13.5 MHz, a pixel takes around 74ns, so we need to
> + * have 64000ns / 74ns = 864.
> + *
> + * This is also mandated by BT.601.
> + */
> + KUNIT_EXPECT_EQ(test, mode->htotal, 864);
> +
> + KUNIT_EXPECT_EQ(test, mode->vdisplay, 576);
> + KUNIT_EXPECT_EQ(test, mode->vtotal, 625);
> +}
> +
> +static void drm_modes_analog_tv_pal_576i_inlined(struct kunit *test)
> +{
> + struct drm_modes_test_priv *priv = test->priv;
> + struct drm_display_mode *expected, *mode;
> +
> + expected = drm_analog_tv_mode(priv->drm,
> + DRM_MODE_TV_MODE_PAL,
> + 13500 * HZ_PER_KHZ, 720, 576,
> + true);
> + KUNIT_ASSERT_NOT_NULL(test, expected);
> +
> + mode = drm_mode_analog_pal_576i(priv->drm);
> + KUNIT_ASSERT_NOT_NULL(test, mode);
> +
> + KUNIT_EXPECT_TRUE(test, drm_mode_equal(expected, mode));
> +}
> +
> +static struct kunit_case drm_modes_analog_tv_tests[] = {
> + KUNIT_CASE(drm_modes_analog_tv_ntsc_480i),
> + KUNIT_CASE(drm_modes_analog_tv_ntsc_480i_inlined),
> + KUNIT_CASE(drm_modes_analog_tv_pal_576i),
> + KUNIT_CASE(drm_modes_analog_tv_pal_576i_inlined),
> + { }
> +};
> +
> +static struct kunit_suite drm_modes_analog_tv_test_suite = {
> + .name = "drm_modes_analog_tv",
> + .init = drm_modes_test_init,
> + .test_cases = drm_modes_analog_tv_tests,
> +};
> +
> +kunit_test_suites(
> + &drm_modes_analog_tv_test_suite
> +);
Considering that there is only one suite, you could use the
kunit_test_suite macro instead.
Best Regards,
- Maíra Canal
> +MODULE_LICENSE("GPL v2");
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 12/24] drm/connector: Add a function to lookup a TV mode by its name
[not found] ` <20220728-rpi-analog-tv-properties-v8-12-09ce1466967c@cerno.tech>
@ 2022-11-10 23:11 ` Maíra Canal
0 siblings, 0 replies; 7+ messages in thread
From: Maíra Canal @ 2022-11-10 23:11 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, Chen-Yu Tsai, Maxime Ripard,
Jernej Skrabec, Karol Herbst, Jani Nikula, Daniel Vetter,
Lyude Paul, Samuel Holland, Joonas Lahtinen, Thomas Zimmermann,
Emma Anholt, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Ben Skeggs
Cc: Dom Cobley, Dave Stevenson, nouveau, intel-gfx, linux-kernel,
dri-devel, Phil Elwell, Hans de Goede, Noralf Trønnes,
Geert Uytterhoeven, Mateusz Kwiatkowski, linux-sunxi,
linux-arm-kernel
Hi Maxime,
On 11/10/22 08:07, Maxime Ripard wrote:
> As part of the command line parsing rework coming in the next patches,
> we'll need to lookup drm_connector_tv_mode values by their name, already
> defined in drm_tv_mode_enum_list.
>
> In order to avoid any code duplication, let's do a function that will
> perform a lookup of a TV mode name and return its value.
>
> Reviewed-by: Noralf Trønnes <noralf@tronnes.org>
> Tested-by: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
>
> ---
> Changes in v7:
> - Add kunit tests
> ---
> drivers/gpu/drm/drm_connector.c | 24 ++++++++
> drivers/gpu/drm/tests/Makefile | 1 +
> drivers/gpu/drm/tests/drm_connector_test.c | 90 ++++++++++++++++++++++++++++++
> include/drm/drm_connector.h | 2 +
> 4 files changed, 117 insertions(+)
>
> diff --git a/drivers/gpu/drm/tests/drm_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c
> new file mode 100644
> index 000000000000..f2272b9df211
> --- /dev/null
> +++ b/drivers/gpu/drm/tests/drm_connector_test.c
> @@ -0,0 +1,90 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Kunit test for drm_modes functions
> + */
> +
> +#include <drm/drm_connector.h>
> +
> +#include <kunit/test.h>
> +
> +struct drm_get_tv_mode_from_name_test {
> + const char *name;
> + enum drm_connector_tv_mode expected_mode;
> +};
> +
> +#define TV_MODE_NAME(_name, _mode) \
> + { \
> + .name = _name, \
> + .expected_mode = _mode, \
> + }
> +
> +static void drm_test_get_tv_mode_from_name_valid(struct kunit *test)
> +{
> + const struct drm_get_tv_mode_from_name_test *params = test->param_value;
> +
> + KUNIT_EXPECT_EQ(test,
> + drm_get_tv_mode_from_name(params->name, strlen(params->name)),
> + params->expected_mode);
> +}
> +
> +static const
> +struct drm_get_tv_mode_from_name_test drm_get_tv_mode_from_name_valid_tests[] = {
> + TV_MODE_NAME("NTSC", DRM_MODE_TV_MODE_NTSC),
> + TV_MODE_NAME("NTSC-443", DRM_MODE_TV_MODE_NTSC_443),
> + TV_MODE_NAME("NTSC-J", DRM_MODE_TV_MODE_NTSC_J),
> + TV_MODE_NAME("PAL", DRM_MODE_TV_MODE_PAL),
> + TV_MODE_NAME("PAL-M", DRM_MODE_TV_MODE_PAL_M),
> + TV_MODE_NAME("PAL-N", DRM_MODE_TV_MODE_PAL_N),
> + TV_MODE_NAME("SECAM", DRM_MODE_TV_MODE_SECAM),
> +};
> +
> +static void
> +drm_get_tv_mode_from_name_valid_desc(const struct drm_get_tv_mode_from_name_test *t,
> + char *desc)
> +{
> + sprintf(desc, "%s", t->name);
> +}
I believe that it should be a blank line here for code style.
> +KUNIT_ARRAY_PARAM(drm_get_tv_mode_from_name_valid,
> + drm_get_tv_mode_from_name_valid_tests,
> + drm_get_tv_mode_from_name_valid_desc);
> +
> +static void drm_test_get_tv_mode_from_name_invalid(struct kunit *test)
> +{
> + const char *name = *(const char **)test->param_value;
> +
> + KUNIT_EXPECT_LT(test,
> + drm_get_tv_mode_from_name(name, strlen(name)),
> + 0);
> +}
> +
> +static const
> +char *drm_get_tv_mode_from_name_invalid_tests[] = {
> + /* Truncated */
> + "NTS",
> +};
Considering that there is only one invalid test, is there a particular
reason to parametrize this test?
> +
> +static void
> +drm_get_tv_mode_from_name_invalid_desc(const char **name, char *desc)
> +{
> + sprintf(desc, "%s", *name);
> +}
> +KUNIT_ARRAY_PARAM(drm_get_tv_mode_from_name_invalid,
> + drm_get_tv_mode_from_name_invalid_tests,
> + drm_get_tv_mode_from_name_invalid_desc);
> +
> +static struct kunit_case drm_get_tv_mode_from_name_tests[] = {
> + KUNIT_CASE_PARAM(drm_test_get_tv_mode_from_name_valid,
> + drm_get_tv_mode_from_name_valid_gen_params),
> + KUNIT_CASE_PARAM(drm_test_get_tv_mode_from_name_invalid,
> + drm_get_tv_mode_from_name_invalid_gen_params),
> + { }
> +};
> +
> +static struct kunit_suite drm_get_tv_mode_from_name_test_suite = {
> + .name = "drm_get_tv_mode_from_name",
> + .test_cases = drm_get_tv_mode_from_name_tests,
> +};
> +
> +kunit_test_suites(
> + &drm_get_tv_mode_from_name_test_suite
> +);
Considering that there is only one suite, you could use the
kunit_test_suite macro instead.
Best Regards,
- Maíra Canal
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 16/24] drm/modes: Introduce more named modes
[not found] ` <20220728-rpi-analog-tv-properties-v8-16-09ce1466967c@cerno.tech>
@ 2022-11-10 23:22 ` Maíra Canal
2022-11-12 16:32 ` Noralf Trønnes
1 sibling, 0 replies; 7+ messages in thread
From: Maíra Canal @ 2022-11-10 23:22 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, Chen-Yu Tsai, Maxime Ripard,
Jernej Skrabec, Karol Herbst, Jani Nikula, Daniel Vetter,
Lyude Paul, Samuel Holland, Joonas Lahtinen, Thomas Zimmermann,
Emma Anholt, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Ben Skeggs
Cc: Dom Cobley, Dave Stevenson, nouveau, intel-gfx, linux-kernel,
dri-devel, Phil Elwell, Hans de Goede, Noralf Trønnes,
Geert Uytterhoeven, Mateusz Kwiatkowski, linux-sunxi,
linux-arm-kernel
Hi Maxime,
On 11/10/22 08:07, Maxime Ripard wrote:
> Now that we can easily extend the named modes list, let's add a few more
> analog TV modes that were used in the wild, and some unit tests to make
> sure it works as intended.
>
> Tested-by: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
>
> ---
> Changes in v6:
> - Renamed the tests to follow DRM test naming convention
>
> Changes in v5:
> - Switched to KUNIT_ASSERT_NOT_NULL
> ---
> drivers/gpu/drm/drm_modes.c | 2 +
> drivers/gpu/drm/tests/drm_client_modeset_test.c | 54 +++++++++++++++++++++++++
> 2 files changed, 56 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> index d3f0a3559812..855569a269b8 100644
> --- a/drivers/gpu/drm/drm_modes.c
> +++ b/drivers/gpu/drm/drm_modes.c
> @@ -2272,7 +2272,9 @@ struct drm_named_mode {
>
> static const struct drm_named_mode drm_named_modes[] = {
> NAMED_MODE("NTSC", 13500, 720, 480, DRM_MODE_FLAG_INTERLACE, DRM_MODE_TV_MODE_NTSC),
> + NAMED_MODE("NTSC-J", 13500, 720, 480, DRM_MODE_FLAG_INTERLACE, DRM_MODE_TV_MODE_NTSC_J),
> NAMED_MODE("PAL", 13500, 720, 576, DRM_MODE_FLAG_INTERLACE, DRM_MODE_TV_MODE_PAL),
> + NAMED_MODE("PAL-M", 13500, 720, 480, DRM_MODE_FLAG_INTERLACE, DRM_MODE_TV_MODE_PAL_M),
> };
>
> static int drm_mode_parse_cmdline_named_mode(const char *name,
> diff --git a/drivers/gpu/drm/tests/drm_client_modeset_test.c b/drivers/gpu/drm/tests/drm_client_modeset_test.c
> index 768e8efb2f52..cf38e7cf0f08 100644
> --- a/drivers/gpu/drm/tests/drm_client_modeset_test.c
> +++ b/drivers/gpu/drm/tests/drm_client_modeset_test.c
> @@ -133,6 +133,32 @@ static void drm_test_pick_cmdline_named_ntsc(struct kunit *test)
> KUNIT_EXPECT_TRUE(test, drm_mode_equal(drm_mode_analog_ntsc_480i(drm), mode));
> }
>
> +static void drm_test_pick_cmdline_named_ntsc_j(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-J";
> + 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;
> @@ -159,10 +185,38 @@ static void drm_test_pick_cmdline_named_pal(struct kunit *test)
> KUNIT_EXPECT_TRUE(test, drm_mode_equal(drm_mode_analog_pal_576i(drm), mode));
> }
>
> +static void drm_test_pick_cmdline_named_pal_m(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-M";
> + 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 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_ntsc_j),
> KUNIT_CASE(drm_test_pick_cmdline_named_pal),
> + KUNIT_CASE(drm_test_pick_cmdline_named_pal_m),
As the tests drm_test_pick_cmdline_named_ntsc,
drm_test_pick_cmdline_named_ntsc_j, drm_test_pick_cmdline_named_pal and
drm_test_pick_cmdline_named_pal_m follow a pretty similar structure, it
would be nice to parametrize those tests.
Best Regards,
- Maíra Canal
> {}
> };
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 17/24] drm/probe-helper: Provide a TV get_modes helper
[not found] ` <20220728-rpi-analog-tv-properties-v8-17-09ce1466967c@cerno.tech>
@ 2022-11-10 23:29 ` Maíra Canal
0 siblings, 0 replies; 7+ messages in thread
From: Maíra Canal @ 2022-11-10 23:29 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, Chen-Yu Tsai, Maxime Ripard,
Jernej Skrabec, Karol Herbst, Jani Nikula, Daniel Vetter,
Lyude Paul, Samuel Holland, Joonas Lahtinen, Thomas Zimmermann,
Emma Anholt, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Ben Skeggs
Cc: Dom Cobley, Dave Stevenson, nouveau, intel-gfx, linux-kernel,
dri-devel, Phil Elwell, Hans de Goede, Noralf Trønnes,
Geert Uytterhoeven, Mateusz Kwiatkowski, linux-sunxi,
linux-arm-kernel
Hi Maxime,
On 11/10/22 08:07, Maxime Ripard wrote:
> From: Noralf Trønnes <noralf@tronnes.org>
>
> Most of the TV connectors will need a similar get_modes implementation
> that will, depending on the drivers' capabilities, register the 480i and
> 576i modes.
>
> That implementation will also need to set the preferred flag and order
> the modes based on the driver and users preferrence.
>
> This is especially important to guarantee that a userspace stack such as
> Xorg can start and pick up the preferred mode while maintaining a
> working output.
>
> Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
> Tested-by: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
>
> ---
> Changes in v8:
> - Remove unused tv_mode_support function
> - Add unit tests
>
> Changes in v7:
> - Used Noralf's implementation
>
> Changes in v6:
> - New patch
> ---
> drivers/gpu/drm/drm_probe_helper.c | 82 ++++++++++
> drivers/gpu/drm/tests/Makefile | 1 +
> drivers/gpu/drm/tests/drm_probe_helper_test.c | 209 ++++++++++++++++++++++++++
> include/drm/drm_probe_helper.h | 1 +
> 4 files changed, 293 insertions(+)
>
> diff --git a/drivers/gpu/drm/tests/drm_probe_helper_test.c b/drivers/gpu/drm/tests/drm_probe_helper_test.c
> new file mode 100644
> index 000000000000..4f295b39f746
> --- /dev/null
> +++ b/drivers/gpu/drm/tests/drm_probe_helper_test.c
> @@ -0,0 +1,209 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Kunit test for drm_probe_helper functions
> + */
> +
> +#include <drm/drm_atomic_state_helper.h>
> +#include <drm/drm_connector.h>
> +#include <drm/drm_device.h>
> +#include <drm/drm_drv.h>
> +#include <drm/drm_mode.h>
> +#include <drm/drm_modes.h>
> +#include <drm/drm_modeset_helper_vtables.h>
> +#include <drm/drm_probe_helper.h>
> +
> +#include <kunit/test.h>
> +
> +#include "drm_kunit_helpers.h"
> +
> +static const struct drm_display_mode ntsc_mode = {
> + DRM_MODE("720x480i", 0, 13500,
> + 720, 736, 800, 858, 0,
> + 480, 486, 492, 525, 0,
> + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_INTERLACE)
> +};
> +
> +static const struct drm_display_mode pal_mode = {
> + DRM_MODE("720x576i", 0, 13500,
> + 720, 732, 796, 864, 0,
> + 576, 581, 587, 625, 0,
> + DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_INTERLACE)
> +};
> +
> +struct drm_probe_helper_test_priv {
> + struct drm_device *drm;
> + struct drm_connector connector;
> +};
> +
> +static const struct drm_connector_helper_funcs drm_probe_helper_connector_helper_funcs = {
> +};
> +
> +static const struct drm_connector_funcs drm_probe_helper_connector_funcs = {
> + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
> + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
> + .reset = drm_atomic_helper_connector_reset,
> +};
> +
> +static int drm_probe_helper_test_init(struct kunit *test)
> +{
> + struct drm_probe_helper_test_priv *priv;
> + struct drm_connector *connector;
> + int ret;
> +
> + priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
> + KUNIT_ASSERT_NOT_NULL(test, priv);
> + test->priv = priv;
> +
> + priv->drm = drm_kunit_device_init(test, DRIVER_MODESET | DRIVER_ATOMIC,
> + "drm-probe-helper-test");
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->drm);
> +
> + connector = &priv->connector;
> + ret = drmm_connector_init(priv->drm, connector,
> + &drm_probe_helper_connector_funcs,
> + DRM_MODE_CONNECTOR_Unknown,
> + NULL);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> + drm_connector_helper_add(connector, &drm_probe_helper_connector_helper_funcs);
> +
> + return 0;
> +}
> +
> +struct drm_connector_helper_tv_get_modes_test {
> + const char *name;
> + unsigned int supported_tv_modes;
> + enum drm_connector_tv_mode default_mode;
> + bool cmdline;
> + enum drm_connector_tv_mode cmdline_mode;
> + const struct drm_display_mode **expected_modes;
> + unsigned int num_expected_modes;
> +};
> +
> +#define _TV_MODE_TEST(_name, _supported, _default, _cmdline, _cmdline_mode, ...) \
> + { \
> + .name = _name, \
> + .supported_tv_modes = _supported, \
> + .default_mode = _default, \
> + .cmdline = _cmdline, \
> + .cmdline_mode = _cmdline_mode, \
> + .expected_modes = (const struct drm_display_mode*[]) { __VA_ARGS__ }, \
> + .num_expected_modes = sizeof((const struct drm_display_mode*[]) { __VA_ARGS__ }) / \
> + (sizeof(const struct drm_display_mode*)), \
> + }
> +
> +#define TV_MODE_TEST(_name, _supported, _default, ...) \
> + _TV_MODE_TEST(_name, _supported, _default, false, 0, __VA_ARGS__)
> +
> +#define TV_MODE_TEST_CMDLINE(_name, _supported, _default, _cmdline, ...) \
> + _TV_MODE_TEST(_name, _supported, _default, true, _cmdline, __VA_ARGS__)
> +
> +static void
> +drm_test_connector_helper_tv_get_modes_check(struct kunit *test)
> +{
> + const struct drm_connector_helper_tv_get_modes_test *params = test->param_value;
> + struct drm_probe_helper_test_priv *priv = test->priv;
> + struct drm_connector *connector = &priv->connector;
> + struct drm_cmdline_mode *cmdline = &connector->cmdline_mode;
> + struct drm_display_mode *mode;
> + const struct drm_display_mode *expected;
> + size_t len;
> + int ret;
> +
> + if (params->cmdline) {
> + cmdline->tv_mode_specified = true;
> + cmdline->tv_mode = params->cmdline_mode;
> + }
> +
> + ret = drm_mode_create_tv_properties(priv->drm, params->supported_tv_modes);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> + drm_object_attach_property(&connector->base,
> + priv->drm->mode_config.tv_mode_property,
> + params->default_mode);
> +
> + mutex_lock(&priv->drm->mode_config.mutex);
> +
> + ret = drm_connector_helper_tv_get_modes(connector);
> + KUNIT_EXPECT_EQ(test, ret, params->num_expected_modes);
> +
> + list_for_each_entry(mode, &connector->probed_modes, head)
> + len++;
> + KUNIT_EXPECT_EQ(test, len, params->num_expected_modes);
> +
> + if (params->num_expected_modes >= 1) {
> + mode = list_first_entry_or_null(&connector->probed_modes,
> + struct drm_display_mode, head);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mode);
> +
> + expected = params->expected_modes[0];
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, expected);
> +
> + KUNIT_EXPECT_TRUE(test, drm_mode_equal(mode, expected));
> + KUNIT_EXPECT_TRUE(test, mode->type & DRM_MODE_TYPE_PREFERRED);
> + }
> +
> + if (params->num_expected_modes >= 2) {
> + mode = list_next_entry(mode, head);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mode);
> +
> + expected = params->expected_modes[1];
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, expected);
> +
> + KUNIT_EXPECT_TRUE(test, drm_mode_equal(mode, expected));
> + KUNIT_EXPECT_FALSE(test, mode->type & DRM_MODE_TYPE_PREFERRED);
> + }
> +
> + mutex_unlock(&priv->drm->mode_config.mutex);
> +}
> +
> +static const
> +struct drm_connector_helper_tv_get_modes_test drm_connector_helper_tv_get_modes_tests[] = {
> + { .name = "None" },
> + TV_MODE_TEST("PAL", BIT(DRM_MODE_TV_MODE_PAL), DRM_MODE_TV_MODE_PAL, &pal_mode),
> + TV_MODE_TEST("NTSC", BIT(DRM_MODE_TV_MODE_NTSC), DRM_MODE_TV_MODE_NTSC, &ntsc_mode),
> + TV_MODE_TEST("Both, NTSC Default",
> + BIT(DRM_MODE_TV_MODE_NTSC) | BIT(DRM_MODE_TV_MODE_PAL),
> + DRM_MODE_TV_MODE_NTSC,
> + &ntsc_mode, &pal_mode),
> + TV_MODE_TEST("Both, PAL Default",
> + BIT(DRM_MODE_TV_MODE_NTSC) | BIT(DRM_MODE_TV_MODE_PAL),
> + DRM_MODE_TV_MODE_PAL,
> + &pal_mode, &ntsc_mode),
> + TV_MODE_TEST_CMDLINE("Both, NTSC Default, with PAL on command-line",
> + BIT(DRM_MODE_TV_MODE_NTSC) | BIT(DRM_MODE_TV_MODE_PAL),
> + DRM_MODE_TV_MODE_NTSC,
> + DRM_MODE_TV_MODE_PAL,
> + &pal_mode, &ntsc_mode),
> + TV_MODE_TEST_CMDLINE("Both, PAL Default, with NTSC on command-line",
> + BIT(DRM_MODE_TV_MODE_NTSC) | BIT(DRM_MODE_TV_MODE_PAL),
> + DRM_MODE_TV_MODE_PAL,
> + DRM_MODE_TV_MODE_NTSC,
> + &ntsc_mode, &pal_mode),
> +};
> +
> +static void
> +drm_connector_helper_tv_get_modes_desc(const struct drm_connector_helper_tv_get_modes_test *t,
> + char *desc)
> +{
> + sprintf(desc, "%s", t->name);
> +}
> +KUNIT_ARRAY_PARAM(drm_connector_helper_tv_get_modes,
> + drm_connector_helper_tv_get_modes_tests,
> + drm_connector_helper_tv_get_modes_desc);
> +
> +static struct kunit_case drm_test_connector_helper_tv_get_modes_tests[] = {
> + KUNIT_CASE_PARAM(drm_test_connector_helper_tv_get_modes_check,
> + drm_connector_helper_tv_get_modes_gen_params),
> + { }
> +};
> +
> +static struct kunit_suite drm_test_connector_helper_tv_get_modes_suite = {
> + .name = "drm_test_connector_helper_tv_get_modes",
> + .init = drm_probe_helper_test_init,
> + .test_cases = drm_test_connector_helper_tv_get_modes_tests,
> +};
> +
> +kunit_test_suites(
> + &drm_test_connector_helper_tv_get_modes_suite
> +);
Considering that there is only one suite, you could use the
kunit_test_suite macro instead.
Moreover, it would be nice to run the checkpatch script on this test, as
there are a couple of problems with the code style.
Best Regards,
- Maíra Canal
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 14/24] drm/modes: Properly generate a drm_display_mode from a named mode
[not found] ` <20220728-rpi-analog-tv-properties-v8-14-09ce1466967c@cerno.tech>
@ 2022-11-12 16:29 ` Noralf Trønnes
0 siblings, 0 replies; 7+ messages in thread
From: Noralf Trønnes @ 2022-11-12 16:29 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, Chen-Yu Tsai, Maxime Ripard,
Jernej Skrabec, Karol Herbst, Jani Nikula, Daniel Vetter,
Lyude Paul, Samuel Holland, Joonas Lahtinen, Thomas Zimmermann,
Emma Anholt, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Ben Skeggs
Cc: nouveau, Dom Cobley, intel-gfx, Phil Elwell, linux-sunxi,
Mateusz Kwiatkowski, Hans de Goede, linux-kernel, Dave Stevenson,
dri-devel, linux-arm-kernel, Geert Uytterhoeven,
Noralf Trønnes
Den 10.11.2022 12.07, 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.
>
> Tested-by: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
>
> ---
Reviewed-by: Noralf Trønnes <noralf@tronnes.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 15/24] drm/client: Remove match on mode name
[not found] ` <20220728-rpi-analog-tv-properties-v8-15-09ce1466967c@cerno.tech>
@ 2022-11-12 16:30 ` Noralf Trønnes
0 siblings, 0 replies; 7+ messages in thread
From: Noralf Trønnes @ 2022-11-12 16:30 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, Chen-Yu Tsai, Maxime Ripard,
Jernej Skrabec, Karol Herbst, Jani Nikula, Daniel Vetter,
Lyude Paul, Samuel Holland, Joonas Lahtinen, Thomas Zimmermann,
Emma Anholt, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Ben Skeggs
Cc: nouveau, Dom Cobley, intel-gfx, Phil Elwell, linux-sunxi,
Mateusz Kwiatkowski, Hans de Goede, linux-kernel, Dave Stevenson,
dri-devel, linux-arm-kernel, Geert Uytterhoeven,
Noralf Trønnes
Den 10.11.2022 12.07, skrev Maxime Ripard:
> Commit 3aeeb13d8996 ("drm/modes: Support modes names on the command
> line") initially introduced the named modes support by essentially
> matching the name passed on the command-line to the mode names defined
> by the drivers.
>
> This proved to be difficult to work with, since all drivers had to
> provide properly named modes. This was also needed because we weren't
> passing a full blown-mode to the drivers, but were only filling its
> name.
>
> Thanks to the previous patches, we now generate a proper mode, and we
> thus can use the usual matching algo on timings, and can simply drop the
> name match.
>
> Suggested-by: Noralf Trønnes <noralf@tronnes.org>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
>
> ---
Reviewed-by: Noralf Trønnes <noralf@tronnes.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 16/24] drm/modes: Introduce more named modes
[not found] ` <20220728-rpi-analog-tv-properties-v8-16-09ce1466967c@cerno.tech>
2022-11-10 23:22 ` [PATCH v8 16/24] drm/modes: Introduce more named modes Maíra Canal
@ 2022-11-12 16:32 ` Noralf Trønnes
1 sibling, 0 replies; 7+ messages in thread
From: Noralf Trønnes @ 2022-11-12 16:32 UTC (permalink / raw)
To: Maxime Ripard, Maarten Lankhorst, Chen-Yu Tsai, Maxime Ripard,
Jernej Skrabec, Karol Herbst, Jani Nikula, Daniel Vetter,
Lyude Paul, Samuel Holland, Joonas Lahtinen, Thomas Zimmermann,
Emma Anholt, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Ben Skeggs
Cc: nouveau, Dom Cobley, intel-gfx, Phil Elwell, linux-sunxi,
Mateusz Kwiatkowski, Hans de Goede, linux-kernel, Dave Stevenson,
dri-devel, linux-arm-kernel, Geert Uytterhoeven,
Noralf Trønnes
Den 10.11.2022 12.07, skrev Maxime Ripard:
> Now that we can easily extend the named modes list, let's add a few more
> analog TV modes that were used in the wild, and some unit tests to make
> sure it works as intended.
>
> Tested-by: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
>
> ---
> Changes in v6:
> - Renamed the tests to follow DRM test naming convention
>
> Changes in v5:
> - Switched to KUNIT_ASSERT_NOT_NULL
> ---
> drivers/gpu/drm/drm_modes.c | 2 +
> drivers/gpu/drm/tests/drm_client_modeset_test.c | 54 +++++++++++++++++++++++++
> 2 files changed, 56 insertions(+)
>
This needs an entry in modedb.rst so people know named modes exist, with
that:
Reviewed-by: Noralf Trønnes <noralf@tronnes.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-11-12 16:32 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20220728-rpi-analog-tv-properties-v8-0-09ce1466967c@cerno.tech>
[not found] ` <20220728-rpi-analog-tv-properties-v8-6-09ce1466967c@cerno.tech>
2022-11-10 23:01 ` [PATCH v8 06/24] drm/modes: Add a function to generate analog display modes Maíra Canal
[not found] ` <20220728-rpi-analog-tv-properties-v8-12-09ce1466967c@cerno.tech>
2022-11-10 23:11 ` [PATCH v8 12/24] drm/connector: Add a function to lookup a TV mode by its name Maíra Canal
[not found] ` <20220728-rpi-analog-tv-properties-v8-17-09ce1466967c@cerno.tech>
2022-11-10 23:29 ` [PATCH v8 17/24] drm/probe-helper: Provide a TV get_modes helper Maíra Canal
[not found] ` <20220728-rpi-analog-tv-properties-v8-14-09ce1466967c@cerno.tech>
2022-11-12 16:29 ` [PATCH v8 14/24] drm/modes: Properly generate a drm_display_mode from a named mode Noralf Trønnes
[not found] ` <20220728-rpi-analog-tv-properties-v8-15-09ce1466967c@cerno.tech>
2022-11-12 16:30 ` [PATCH v8 15/24] drm/client: Remove match on mode name Noralf Trønnes
[not found] ` <20220728-rpi-analog-tv-properties-v8-16-09ce1466967c@cerno.tech>
2022-11-10 23:22 ` [PATCH v8 16/24] drm/modes: Introduce more named modes Maíra Canal
2022-11-12 16:32 ` Noralf Trønnes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).