linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jernej Škrabec" <jernej.skrabec@gmail.com>
To: Karol Herbst <kherbst@redhat.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
	Daniel Vetter <daniel@ffwll.ch>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	David Airlie <airlied@linux.ie>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Lyude Paul <lyude@redhat.com>, Maxime Ripard <mripard@kernel.org>,
	Emma Anholt <emma@anholt.net>, Chen-Yu Tsai <wens@csie.org>,
	Samuel Holland <samuel@sholland.org>,
	Ben Skeggs <bskeggs@redhat.com>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Maxime Ripard <maxime@cerno.tech>
Cc: "Dom Cobley" <dom@raspberrypi.com>,
	"Maxime Ripard" <maxime@cerno.tech>,
	linux-sunxi@lists.linux.dev,
	"Dave Stevenson" <dave.stevenson@raspberrypi.com>,
	"Noralf Trønnes" <noralf@tronnes.org>,
	intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	nouveau@lists.freedesktop.org,
	"Geert Uytterhoeven" <geert@linux-m68k.org>,
	linux-arm-kernel@lists.infradead.org,
	"Mateusz Kwiatkowski" <kfyatek+publicgit@gmail.com>,
	dri-devel@lists.freedesktop.org,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Phil Elwell" <phil@raspberrypi.com>
Subject: Re: [PATCH v5 22/22] drm/sun4i: tv: Convert to the new TV mode property
Date: Thu, 13 Oct 2022 20:23:51 +0200	[thread overview]
Message-ID: <6482539.4vTCxPXJkl@kista> (raw)
In-Reply-To: <20220728-rpi-analog-tv-properties-v5-22-d841cc64fe4b@cerno.tech>

Hi Maxime,

Dne četrtek, 13. oktober 2022 ob 15:19:06 CEST je Maxime Ripard napisal(a):
> Now that the core can deal fine with analog TV modes, let's convert the
> sun4i TV driver to leverage those new features.
> 
> Acked-by: Noralf Trønnes <noralf@tronnes.org>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
> 
> ---
> Changes in v5:
> - Removed the count variable in get_modes
> - Removed spurious vc4 change
> ---
>  drivers/gpu/drm/sun4i/sun4i_tv.c | 145
> +++++++++++++-------------------------- 1 file changed, 48 insertions(+),
> 97 deletions(-)
> 
> diff --git a/drivers/gpu/drm/sun4i/sun4i_tv.c
> b/drivers/gpu/drm/sun4i/sun4i_tv.c index c65f0a89b6b0..4f07aff11551 100644
> --- a/drivers/gpu/drm/sun4i/sun4i_tv.c
> +++ b/drivers/gpu/drm/sun4i/sun4i_tv.c
> @@ -141,23 +141,14 @@ struct resync_parameters {
>  struct tv_mode {
>  	char		*name;
> 
> +	unsigned int	tv_mode;
> +
>  	u32		mode;
>  	u32		chroma_freq;
>  	u16		back_porch;
>  	u16		front_porch;
> -	u16		line_number;
>  	u16		vblank_level;

isn't there a way to get or calculate back_porch, front_porch and vblank_level 
from mode? From quick glance over removed values below, I would say that at 
least back_porch can be removed too?

Otherwise this patch looks ok.

Best regards,
Jernej

> 
> -	u32		hdisplay;
> -	u16		hfront_porch;
> -	u16		hsync_len;
> -	u16		hback_porch;
> -
> -	u32		vdisplay;
> -	u16		vfront_porch;
> -	u16		vsync_len;
> -	u16		vback_porch;
> -
>  	bool		yc_en;
>  	bool		dac3_en;
>  	bool		dac_bit25_en;
> @@ -213,7 +204,7 @@ static const struct resync_parameters
> pal_resync_parameters = {
> 
>  static const struct tv_mode tv_modes[] = {
>  	{
> -		.name		= "NTSC",
> +		.tv_mode	= DRM_MODE_TV_MODE_NTSC,
>  		.mode		= SUN4I_TVE_CFG0_RES_480i,
>  		.chroma_freq	= 0x21f07c1f,
>  		.yc_en		= true,
> @@ -222,17 +213,6 @@ static const struct tv_mode tv_modes[] = {
> 
>  		.back_porch	= 118,
>  		.front_porch	= 32,
> -		.line_number	= 525,
> -
> -		.hdisplay	= 720,
> -		.hfront_porch	= 18,
> -		.hsync_len	= 2,
> -		.hback_porch	= 118,
> -
> -		.vdisplay	= 480,
> -		.vfront_porch	= 26,
> -		.vsync_len	= 2,
> -		.vback_porch	= 17,
> 
>  		.vblank_level	= 240,
> 
> @@ -242,23 +222,12 @@ static const struct tv_mode tv_modes[] = {
>  		.resync_params	= &ntsc_resync_parameters,
>  	},
>  	{
> -		.name		= "PAL",
> +		.tv_mode	= DRM_MODE_TV_MODE_PAL,
>  		.mode		= SUN4I_TVE_CFG0_RES_576i,
>  		.chroma_freq	= 0x2a098acb,
> 
>  		.back_porch	= 138,
>  		.front_porch	= 24,
> -		.line_number	= 625,
> -
> -		.hdisplay	= 720,
> -		.hfront_porch	= 3,
> -		.hsync_len	= 2,
> -		.hback_porch	= 139,
> -
> -		.vdisplay	= 576,
> -		.vfront_porch	= 28,
> -		.vsync_len	= 2,
> -		.vback_porch	= 19,
> 
>  		.vblank_level	= 252,
> 
> @@ -276,63 +245,21 @@ drm_encoder_to_sun4i_tv(struct drm_encoder *encoder)
>  			    encoder);
>  }
> 
> -/*
> - * FIXME: If only the drm_display_mode private field was usable, this
> - * could go away...
> - *
> - * So far, it doesn't seem to be preserved when the mode is passed by
> - * to mode_set for some reason.
> - */
> -static const struct tv_mode *sun4i_tv_find_tv_by_mode(const struct
> drm_display_mode *mode) +static const struct tv_mode *
> +sun4i_tv_find_tv_by_mode(unsigned int mode)
>  {
>  	int i;
> 
> -	/* First try to identify the mode by name */
>  	for (i = 0; i < ARRAY_SIZE(tv_modes); i++) {
>  		const struct tv_mode *tv_mode = &tv_modes[i];
> 
> -		DRM_DEBUG_DRIVER("Comparing mode %s vs %s",
> -				 mode->name, tv_mode->name);
> -
> -		if (!strcmp(mode->name, tv_mode->name))
> -			return tv_mode;
> -	}
> -
> -	/* Then by number of lines */
> -	for (i = 0; i < ARRAY_SIZE(tv_modes); i++) {
> -		const struct tv_mode *tv_mode = &tv_modes[i];
> -
> -		DRM_DEBUG_DRIVER("Comparing mode %s vs %s (X: %d vs 
%d)",
> -				 mode->name, tv_mode->name,
> -				 mode->vdisplay, tv_mode-
>vdisplay);
> -
> -		if (mode->vdisplay == tv_mode->vdisplay)
> +		if (tv_mode->tv_mode == mode)
>  			return tv_mode;
>  	}
> 
>  	return NULL;
>  }
> 
> -static void sun4i_tv_mode_to_drm_mode(const struct tv_mode *tv_mode,
> -				      struct drm_display_mode 
*mode)
> -{
> -	DRM_DEBUG_DRIVER("Creating mode %s\n", mode->name);
> -
> -	mode->type = DRM_MODE_TYPE_DRIVER;
> -	mode->clock = 13500;
> -	mode->flags = DRM_MODE_FLAG_INTERLACE;
> -
> -	mode->hdisplay = tv_mode->hdisplay;
> -	mode->hsync_start = mode->hdisplay + tv_mode->hfront_porch;
> -	mode->hsync_end = mode->hsync_start + tv_mode->hsync_len;
> -	mode->htotal = mode->hsync_end  + tv_mode->hback_porch;
> -
> -	mode->vdisplay = tv_mode->vdisplay;
> -	mode->vsync_start = mode->vdisplay + tv_mode->vfront_porch;
> -	mode->vsync_end = mode->vsync_start + tv_mode->vsync_len;
> -	mode->vtotal = mode->vsync_end  + tv_mode->vback_porch;
> -}
> -
>  static void sun4i_tv_disable(struct drm_encoder *encoder,
>  			    struct drm_atomic_state *state)
>  {
> @@ -356,7 +283,11 @@ static void sun4i_tv_enable(struct drm_encoder
> *encoder, struct drm_crtc_state *crtc_state =
>  		drm_atomic_get_new_crtc_state(state, encoder->crtc);
>  	struct drm_display_mode *mode = &crtc_state->mode;
> -	const struct tv_mode *tv_mode = sun4i_tv_find_tv_by_mode(mode);
> +	struct drm_connector *connector = &tv->connector;
> +	struct drm_connector_state *conn_state =
> +		drm_atomic_get_new_connector_state(state, connector);
> +	const struct tv_mode *tv_mode =
> +		sun4i_tv_find_tv_by_mode(conn_state->tv.mode);
> 
>  	DRM_DEBUG_DRIVER("Enabling the TV Output\n");
> 
> @@ -404,7 +335,7 @@ static void sun4i_tv_enable(struct drm_encoder *encoder,
> /* Set the lines setup */
>  	regmap_write(tv->regs, SUN4I_TVE_LINE_REG,
>  		     SUN4I_TVE_LINE_FIRST(22) |
> -		     SUN4I_TVE_LINE_NUMBER(tv_mode->line_number));
> +		     SUN4I_TVE_LINE_NUMBER(mode->vtotal));
> 
>  	regmap_write(tv->regs, SUN4I_TVE_LEVEL_REG,
>  		     SUN4I_TVE_LEVEL_BLANK(tv_mode->video_levels-
>blank) |
> @@ -467,35 +398,43 @@ static const struct drm_encoder_helper_funcs
> sun4i_tv_helper_funcs = {
> 
>  static int sun4i_tv_comp_get_modes(struct drm_connector *connector)
>  {
> -	int i;
> +	struct drm_display_mode *mode;
> 
> -	for (i = 0; i < ARRAY_SIZE(tv_modes); i++) {
> -		struct drm_display_mode *mode;
> -		const struct tv_mode *tv_mode = &tv_modes[i];
> -
> -		mode = drm_mode_create(connector->dev);
> -		if (!mode) {
> -			DRM_ERROR("Failed to create a new display 
mode\n");
> -			return 0;
> -		}
> +	mode = drm_mode_analog_ntsc_480i(connector->dev);
> +	if (!mode) {
> +		DRM_ERROR("Failed to create a new display mode\n");
> +		return -ENOMEM;
> +	}
> 
> -		strcpy(mode->name, tv_mode->name);
> +	mode->type |= DRM_MODE_TYPE_PREFERRED;
> +	drm_mode_probed_add(connector, mode);
> 
> -		sun4i_tv_mode_to_drm_mode(tv_mode, mode);
> -		drm_mode_probed_add(connector, mode);
> +	mode = drm_mode_analog_pal_576i(connector->dev);
> +	if (!mode) {
> +		DRM_ERROR("Failed to create a new display mode\n");
> +		return -ENOMEM;
>  	}
> 
> -	return i;
> +	drm_mode_probed_add(connector, mode);
> +
> +	return 2;
>  }
> 
>  static const struct drm_connector_helper_funcs
> sun4i_tv_comp_connector_helper_funcs = { +	.atomic_check	=
> drm_atomic_helper_connector_tv_check,
>  	.get_modes	= sun4i_tv_comp_get_modes,
>  };
> 
> +static void sun4i_tv_connector_reset(struct drm_connector *connector)
> +{
> +	drm_atomic_helper_connector_reset(connector);
> +	drm_atomic_helper_connector_tv_reset(connector);
> +}
> +
>  static const struct drm_connector_funcs sun4i_tv_comp_connector_funcs = {
>  	.fill_modes		= drm_helper_probe_single_connector_modes,
>  	.destroy		= drm_connector_cleanup,
> -	.reset			= 
drm_atomic_helper_connector_reset,
> +	.reset			= sun4i_tv_connector_reset,
>  	.atomic_duplicate_state	= 
drm_atomic_helper_connector_duplicate_state,
>  	.atomic_destroy_state	= 
drm_atomic_helper_connector_destroy_state,
>  };
> @@ -587,8 +526,20 @@ static int sun4i_tv_bind(struct device *dev, struct
> device *master,
> 
>  	drm_connector_attach_encoder(&tv->connector, &tv->encoder);
> 
> +	ret = drm_mode_create_tv_properties(drm,
> +					    
BIT(DRM_MODE_TV_MODE_NTSC) |
> +					    
BIT(DRM_MODE_TV_MODE_PAL));
> +	if (ret)
> +		goto err_cleanup_connector;
> +
> +	drm_object_attach_property(&tv->connector.base,
> +				   drm-
>mode_config.tv_mode_property,
> +				   DRM_MODE_TV_MODE_NTSC);
> +
>  	return 0;
> 
> +err_cleanup_connector:
> +	drm_connector_cleanup(&tv->connector);
>  err_cleanup_encoder:
>  	drm_encoder_cleanup(&tv->encoder);
>  err_disable_clk:
> 
> --
> b4 0.11.0-dev-7da52



       reply	other threads:[~2022-10-13 18:34 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220728-rpi-analog-tv-properties-v5-0-d841cc64fe4b@cerno.tech>
     [not found] ` <20220728-rpi-analog-tv-properties-v5-22-d841cc64fe4b@cerno.tech>
2022-10-13 18:23   ` Jernej Škrabec [this message]
2022-10-14  7:38     ` [PATCH v5 22/22] drm/sun4i: tv: Convert to the new TV mode property Maxime Ripard
2022-10-15  8:59       ` Jernej Škrabec
     [not found] ` <20220728-rpi-analog-tv-properties-v5-1-d841cc64fe4b@cerno.tech>
2022-10-15 15:06   ` [PATCH v5 01/22] drm/tests: Add Kunit Helpers Noralf Trønnes
     [not found] ` <20220728-rpi-analog-tv-properties-v5-8-d841cc64fe4b@cerno.tech>
2022-10-16 16:11   ` [PATCH v5 08/22] drm/modes: Move named modes parsing to a separate function Noralf Trønnes
2022-10-18  7:57     ` Maxime Ripard
     [not found] ` <20220728-rpi-analog-tv-properties-v5-6-d841cc64fe4b@cerno.tech>
2022-10-16 17:34   ` [PATCH v5 06/22] drm/modes: Add a function to generate analog display modes Mateusz Kwiatkowski
2022-10-18  8:08     ` Maxime Ripard
     [not found] ` <20220728-rpi-analog-tv-properties-v5-13-d841cc64fe4b@cerno.tech>
2022-10-16 17:51   ` [PATCH v5 13/22] drm/modes: Introduce the tv_mode property as a command-line option Mateusz Kwiatkowski
2022-10-17 10:21     ` Noralf Trønnes
     [not found] ` <20220728-rpi-analog-tv-properties-v5-19-d841cc64fe4b@cerno.tech>
2022-10-16 18:12   ` [PATCH v5 19/22] drm/vc4: vec: Check for VEC output constraints Mateusz Kwiatkowski
2022-10-16 18:16     ` Mateusz Kwiatkowski
2022-10-18  8:27       ` Maxime Ripard
     [not found] ` <20220728-rpi-analog-tv-properties-v5-20-d841cc64fe4b@cerno.tech>
2022-10-16 18:52   ` [PATCH v5 20/22] drm/vc4: vec: Convert to the new TV mode property Mateusz Kwiatkowski
2022-10-16 18:56     ` Mateusz Kwiatkowski
2022-10-17 10:31     ` Noralf Trønnes
2022-10-18 10:00       ` Maxime Ripard
     [not found]         ` <da2b4cb4-5d12-3161-64e3-e87a8cc63e81@gmail.com>
2022-10-20 11:58           ` maxime
2022-10-17 11:39   ` Noralf Trønnes
     [not found] ` <20220728-rpi-analog-tv-properties-v5-21-d841cc64fe4b@cerno.tech>
2022-10-16 19:02   ` [PATCH v5 21/22] drm/vc4: vec: Add support for more analog TV standards Mateusz Kwiatkowski
2022-10-16 19:46   ` [PATCH] drm/vc4: vec: Add support for PAL-60 Mateusz Kwiatkowski
2022-10-18  8:31     ` Maxime Ripard
2022-10-18 20:57       ` Mateusz Kwiatkowski
2022-10-20 15:34         ` maxime
     [not found] ` <20220728-rpi-analog-tv-properties-v5-16-d841cc64fe4b@cerno.tech>
2022-10-17 10:36   ` [PATCH v5 16/22] drm/atomic-helper: Add a TV properties reset helper Noralf Trønnes
     [not found] ` <20220728-rpi-analog-tv-properties-v5-12-d841cc64fe4b@cerno.tech>
2022-10-17 10:44   ` [PATCH v5 12/22] drm/connector: Add a function to lookup a TV mode by its name Noralf Trønnes
2022-10-18  9:33     ` Maxime Ripard
2022-10-18 12:29       ` Noralf Trønnes
2022-10-19  8:48         ` Maxime Ripard
2022-10-19 10:43           ` Noralf Trønnes
2022-10-20 11:29             ` maxime
     [not found] ` <20220728-rpi-analog-tv-properties-v5-7-d841cc64fe4b@cerno.tech>
2022-10-15 16:58   ` [PATCH v5 07/22] drm/client: Add some tests for drm_connector_pick_cmdline_mode() Noralf Trønnes
2022-10-20  7:55   ` Michał Winiarski

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=6482539.4vTCxPXJkl@kista \
    --to=jernej.skrabec@gmail.com \
    --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=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=noralf@tronnes.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;
as well as URLs for NNTP newsgroup(s).