mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Noralf Trønnes" <noralf@tronnes.org>
To: Mateusz Kwiatkowski <kfyatek@gmail.com>,
	maxime@cerno.tech, Karol Herbst <kherbst@redhat.com>,
	Emma Anholt <emma@anholt.net>, Ben Skeggs <bskeggs@redhat.com>,
	Chen-Yu Tsai <wens@csie.org>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Daniel Vetter <daniel@ffwll.ch>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
	Samuel Holland <samuel@sholland.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	David Airlie <airlied@linux.ie>,
	Maxime Ripard <mripard@kernel.org>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Lyude Paul <lyude@redhat.com>
Cc: linux-sunxi@lists.linux.dev, intel-gfx@lists.freedesktop.org,
	"Phil Elwell" <phil@raspberrypi.com>,
	linux-arm-kernel@lists.infradead.org,
	nouveau@lists.freedesktop.org,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Dom Cobley" <dom@raspberrypi.com>,
	dri-devel@lists.freedesktop.org,
	"Dave Stevenson" <dave.stevenson@raspberrypi.com>,
	linux-kernel@vger.kernel.org,
	"Geert Uytterhoeven" <geert@linux-m68k.org>,
	"Noralf Trønnes" <noralf@tronnes.org>
Subject: Re: [PATCH v6 16/23] drm/probe-helper: Provide a TV get_modes helper
Date: Sun, 6 Nov 2022 17:59:23 +0100	[thread overview]
Message-ID: <eb485588-2e7a-8455-7ec4-6a9649d2bef8@tronnes.org> (raw)
In-Reply-To: <8d0eee22-50f5-5b0a-c1e6-c5f61dd5bbcd@gmail.com>



Den 27.10.2022 00.02, skrev Mateusz Kwiatkowski:
> Hi Maxime,
> 
> First of all, nice idea with the helper function that can be reused by different
> drivers. This is neat!
> 
> But looking at this function, it feels a bit overcomplicated. You're creating
> the two modes, then checking which one is the default, then set the preferred
> one and possibly reorder them. Maybe it can be simplified somehow?
> 
> Although when I tried to refactor it myself, I ended up with something that's
> not better at all. Maybe it needs to be complicated, after all :(
> 

I also thought that the function was complicated/difficult to read, in
particular the index stuff at the end, but I also failed in finding a
"better" solution, just a different one ;)

Noralf.

My version:

int drm_connector_helper_tv_get_modes(struct drm_connector *connector)
{
	struct drm_device *dev = connector->dev;
	struct drm_property *tv_mode_property = dev->mode_config.tv_mode_property;
	struct drm_cmdline_mode *cmdline = &connector->cmdline_mode;
	unsigned int ntsc_modes = BIT(DRM_MODE_TV_MODE_NTSC) |
				  BIT(DRM_MODE_TV_MODE_NTSC_443) |
				  BIT(DRM_MODE_TV_MODE_NTSC_J) |
				  BIT(DRM_MODE_TV_MODE_PAL_M);
	unsigned int pal_modes = BIT(DRM_MODE_TV_MODE_PAL) |
				 BIT(DRM_MODE_TV_MODE_PAL_N) |
				 BIT(DRM_MODE_TV_MODE_SECAM);
	unsigned int tv_modes[2] = { UINT_MAX, UINT_MAX };
	unsigned int i, supported_tv_modes = 0;

	if (!tv_mode_property)
		return 0;

	for (i = 0; i < tv_mode_property->num_values; i++)
		supported_tv_modes |= BIT(tv_mode_property->values[i]);

	if ((supported_tv_modes & ntsc_modes) && (supported_tv_modes &
pal_modes)) {
		uint64_t default_mode;

		if (drm_object_property_get_default_value(&connector->base,
							  tv_mode_property,
							  &default_mode))
			return 0;

		if (cmdline->tv_mode_specified)
			default_mode = cmdline->tv_mode;

		if (BIT(default_mode) & ntsc_modes) {
			tv_modes[0] = DRM_MODE_TV_MODE_NTSC;
			tv_modes[1] = DRM_MODE_TV_MODE_PAL;
		} else {
			tv_modes[0] = DRM_MODE_TV_MODE_PAL;
			tv_modes[1] = DRM_MODE_TV_MODE_NTSC;
		}
	} else if (supported_tv_modes & ntsc_modes) {
		tv_modes[0] = DRM_MODE_TV_MODE_NTSC;
	} else if (supported_tv_modes & pal_modes) {
		tv_modes[0] = DRM_MODE_TV_MODE_PAL;
	} else {
		return 0;
	}
	
	for (i = 0; i < ARRAY_SIZE(tv_modes); i++) {
		struct drm_display_mode *mode;

		if (tv_modes[i] == DRM_MODE_TV_MODE_NTSC)
			mode = drm_mode_analog_ntsc_480i(dev);
		else if (tv_modes[i] == DRM_MODE_TV_MODE_PAL)
			mode = drm_mode_analog_pal_576i(dev);
		else
			break;
		if (!mode)
			return i;
		if (!i)
			mode->type |= DRM_MODE_TYPE_PREFERRED;
		drm_mode_probed_add(connector, mode);
	}

	return i;
}

  parent reply	other threads:[~2022-11-06 16:59 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220728-rpi-analog-tv-properties-v6-0-e7792734108f@cerno.tech>
     [not found] ` <20220728-rpi-analog-tv-properties-v6-14-e7792734108f@cerno.tech>
2022-10-26 21:25   ` [PATCH v6 14/23] drm/modes: Properly generate a drm_display_mode from a named mode Mateusz Kwiatkowski
2022-11-05 17:50   ` Noralf Trønnes
2022-11-07 13:34     ` Maxime Ripard
     [not found] ` <20220728-rpi-analog-tv-properties-v6-22-e7792734108f@cerno.tech>
2022-10-26 22:32   ` [PATCH v6 22/23] drm/vc4: vec: Add support for more analog TV standards Mateusz Kwiatkowski
2022-10-27 11:58     ` Maxime Ripard
     [not found] ` <20220728-rpi-analog-tv-properties-v6-8-e7792734108f@cerno.tech>
2022-11-05 14:02   ` [PATCH v6 08/23] drm/modes: Move named modes parsing to a separate function Noralf Trønnes
     [not found] ` <20220728-rpi-analog-tv-properties-v6-9-e7792734108f@cerno.tech>
2022-11-05 14:06   ` [PATCH v6 09/23] drm/modes: Switch to named mode descriptors Noralf Trønnes
     [not found] ` <20220728-rpi-analog-tv-properties-v6-10-e7792734108f@cerno.tech>
2022-11-06 13:04   ` [PATCH v6 10/23] drm/modes: Fill drm_cmdline mode from named modes Noralf Trønnes
2022-11-07 10:02     ` Maxime Ripard
     [not found] ` <20220728-rpi-analog-tv-properties-v6-11-e7792734108f@cerno.tech>
2022-11-06 13:06   ` [PATCH v6 11/23] drm/connector: Add pixel clock to cmdline mode Noralf Trønnes
     [not found] ` <20220728-rpi-analog-tv-properties-v6-13-e7792734108f@cerno.tech>
2022-11-06 13:10   ` [PATCH v6 13/23] drm/modes: Introduce the tv_mode property as a command-line option Noralf Trønnes
     [not found] ` <20220728-rpi-analog-tv-properties-v6-16-e7792734108f@cerno.tech>
2022-10-26 22:02   ` [PATCH v6 16/23] drm/probe-helper: Provide a TV get_modes helper Mateusz Kwiatkowski
2022-10-27  9:37     ` Maxime Ripard
2022-11-06 16:59     ` Noralf Trønnes [this message]
2022-11-07 10:07       ` Maxime Ripard
2022-11-07 11:17         ` Noralf Trønnes
2022-11-06 16:33   ` Noralf Trønnes
2022-11-07 10:21     ` Maxime Ripard
2022-11-07 11:29       ` Noralf Trønnes
2022-11-07 12:45         ` Maxime Ripard

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=eb485588-2e7a-8455-7ec4-6a9649d2bef8@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@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

all inboxes | Powered by JetHome®