All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <mripard@kernel.org>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	 Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>,
	 Simona Vetter <simona@ffwll.ch>,
	Andrzej Hajda <andrzej.hajda@intel.com>,
	 Neil Armstrong <neil.armstrong@linaro.org>,
	Robert Foss <rfoss@kernel.org>,
	 Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
	 Jonas Karlman <jonas@kwiboo.se>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	 Jyri Sarha <jyri.sarha@iki.fi>,
	 Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Cc: Devarsh Thakkar <devarsht@ti.com>,
	dri-devel@lists.freedesktop.org,
	 Maxime Ripard <mripard@kernel.org>
Subject: [PATCH v9 32/42] drm/tidss: crtc: Implement hardware state readout
Date: Fri, 20 Nov 2026 13:55:24 +0100	[thread overview]
Message-ID: <20261120-drm-state-readout-v9-32-a67c2b45b8ec@kernel.org> (raw)
In-Reply-To: <20261120-drm-state-readout-v9-0-a67c2b45b8ec@kernel.org>

The firmware can leave a video port running when the driver probes, and
the KMS state of its CRTC should then reflect it instead of being
pristine, so that the first modeset can be skipped if it matches.

Implement the state readout hooks for the CRTCs.
tidss_crtc_readout_state() reports the CRTC as active when its video
port is enabled, and reads out its mode, bus flags and bus format. The
connectors and planes bound to the CRTC are filled by their own readout
hooks.

tidss_crtc_install_state() takes over the video port of an active CRTC
when its state is installed: it takes the runtime PM reference and the
video port clock that tidss_crtc_atomic_disable() later releases, flags
the video port as a DPI output, and turns the vblank reporting on. The
hook can't fail, so if one of those resources can't be acquired, the
CRTC is installed as inactive instead, and the next modeset fully
programs the video port.

Finally, implement tidss_crtc_compare_state(), that checks the bus
format and bus flags on top of the generic CRTC comparison, unless both
states are inactive since the bus configuration isn't read out from a
disabled pipeline.

Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
 drivers/gpu/drm/tidss/tidss_crtc.c | 132 +++++++++++++++++++++++++++++++++++++
 1 file changed, 132 insertions(+)

diff --git a/drivers/gpu/drm/tidss/tidss_crtc.c b/drivers/gpu/drm/tidss/tidss_crtc.c
index d2664bda53a9..c72194e93bde 100644
--- a/drivers/gpu/drm/tidss/tidss_crtc.c
+++ b/drivers/gpu/drm/tidss/tidss_crtc.c
@@ -2,12 +2,16 @@
 /*
  * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
  * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  */
 
+#include <linux/clk.h>
+
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
+#include <drm/drm_atomic_state_readout_helper.h>
+#include <drm/drm_atomic_uapi.h>
 #include <drm/drm_crtc.h>
 #include <drm/drm_gem_dma_helper.h>
 #include <drm/drm_print.h>
 #include <drm/drm_vblank.h>
 
@@ -370,10 +374,135 @@ static struct drm_crtc_state *tidss_crtc_create_state(struct drm_crtc *crtc)
 	__drm_atomic_helper_crtc_state_init(&tstate->base, crtc);
 
 	return &tstate->base;
 }
 
+static int tidss_crtc_readout_state(struct drm_crtc *crtc,
+				    struct drm_atomic_sro_state *state,
+				    struct drm_crtc_state *crtc_state)
+{
+	struct drm_device *ddev = crtc->dev;
+	struct tidss_device *tidss = to_tidss(ddev);
+	struct dispc_device *dispc = tidss->dispc;
+	struct tidss_crtc_state *tstate = to_tidss_crtc_state(crtc_state);
+	struct tidss_crtc *tcrtc =
+		to_tidss_crtc(crtc);
+	struct drm_display_mode mode = {};
+	int ret;
+
+	tidss_runtime_get(tidss);
+
+	if (!dispc_vp_is_enabled(dispc, tcrtc->hw_videoport))
+		goto out;
+
+	tstate->base.active = 1;
+	tstate->base.enable = 1;
+
+	ret = dispc_vp_readout_mode(dispc, tcrtc->hw_videoport, &mode);
+	if (ret)
+		goto err_runtime_put;
+
+	ret = drm_atomic_set_mode_for_crtc(&tstate->base, &mode);
+	if (WARN_ON(ret))
+		goto err_runtime_put;
+
+	drm_mode_copy(&tstate->base.adjusted_mode, &mode);
+
+	tstate->bus_flags = dispc_vp_get_bus_flags(dispc, tcrtc->hw_videoport);
+	ret = dispc_vp_get_bus_format(dispc, tcrtc->hw_videoport,
+				      &tstate->bus_format);
+	if (ret)
+		goto err_runtime_put;
+
+	/*
+	 * The active connectors and planes will be filled by their
+	 * respective readout callbacks.
+	 */
+
+out:
+	tidss_runtime_put(tidss);
+	return 0;
+
+err_runtime_put:
+	tidss_runtime_put(tidss);
+	return ret;
+}
+
+static void tidss_crtc_install_state(struct drm_crtc *crtc,
+				     struct drm_crtc_state *crtc_state)
+{
+	struct tidss_crtc *tcrtc = to_tidss_crtc(crtc);
+	struct drm_device *ddev = crtc->dev;
+	struct tidss_device *tidss = to_tidss(ddev);
+	int ret;
+
+	/*
+	 * The video port wasn't enabled in hardware: nothing to take
+	 * over for it, and enabling the clock and the vblank reporting
+	 * would leak their reference for a CRTC that no disable will
+	 * ever release.
+	 */
+	if (!crtc_state->active)
+		return;
+
+	ret = tidss_runtime_get(tidss);
+	if (ret < 0)
+		goto err_inactive;
+
+	ret = dispc_vp_enable_clk(tidss->dispc, tcrtc->hw_videoport);
+	if (ret != 0) {
+		tidss_runtime_put(tidss);
+		goto err_inactive;
+	}
+
+	/*
+	 * dispc_vp_unprepare() only clears DPIENABLE for video ports
+	 * that dispc_vp_setup() flagged as DPI outputs, which hasn't
+	 * run for a video port enabled before the driver probed.
+	 */
+	dispc_vp_set_dpi_output(tidss->dispc, tcrtc->hw_videoport,
+				tcrtc->dpi_output);
+
+	/* Turn vertical blanking interrupt reporting on. */
+	drm_crtc_vblank_on(crtc);
+
+	return;
+
+err_inactive:
+	/*
+	 * This hook can't fail. Without the references taken above, a
+	 * later tidss_crtc_atomic_disable() would release references
+	 * it doesn't hold, so install the CRTC as inactive instead:
+	 * the next modeset will fully program the video port.
+	 */
+	drm_warn(ddev, "[CRTC:%d:%s] Couldn't take over the video port: %d\n",
+		 crtc->base.id, crtc->name, ret);
+	crtc_state->active = false;
+}
+
+static bool tidss_crtc_compare_state(struct drm_crtc *crtc,
+				     struct drm_printer *p,
+				     struct drm_crtc_state *expected,
+				     struct drm_crtc_state *actual)
+{
+	struct tidss_crtc_state *t_expected = to_tidss_crtc_state(expected);
+	struct tidss_crtc_state *t_actual = to_tidss_crtc_state(actual);
+	bool ret = drm_atomic_helper_crtc_compare_state(crtc, p, expected, actual);
+
+	/*
+	 * Both inactive: the bus configuration wasn't read out from the
+	 * disabled pipeline, and the committed one is stale anyway.
+	 */
+	if (!expected->active && !actual->active)
+		return ret;
+
+	STATE_CHECK_U32_X(ret, p, crtc->name, t_expected, t_actual, bus_format);
+	STATE_CHECK_U32_X(ret, p, crtc->name, t_expected, t_actual, bus_flags);
+
+	return ret;
+}
+
 static struct drm_crtc_state *tidss_crtc_duplicate_state(struct drm_crtc *crtc)
 {
 	struct tidss_crtc_state *state, *current_state;
 
 	if (WARN_ON(!crtc->state))
@@ -415,10 +544,13 @@ static void tidss_crtc_atomic_print_state(struct drm_printer *p,
 static const struct drm_crtc_funcs tidss_crtc_funcs = {
 	.destroy = tidss_crtc_destroy,
 	.set_config = drm_atomic_helper_set_config,
 	.page_flip = drm_atomic_helper_page_flip,
 	.atomic_create_state = tidss_crtc_create_state,
+	.atomic_sro_readout_state = tidss_crtc_readout_state,
+	.atomic_sro_install_state = tidss_crtc_install_state,
+	.atomic_sro_compare_state = tidss_crtc_compare_state,
 	.atomic_duplicate_state = tidss_crtc_duplicate_state,
 	.atomic_destroy_state = tidss_crtc_destroy_state,
 	.atomic_print_state = tidss_crtc_atomic_print_state,
 	.enable_vblank = tidss_crtc_enable_vblank,
 	.disable_vblank = tidss_crtc_disable_vblank,

-- 
2.56.1


  parent reply	other threads:[~2026-11-20 12:58 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 12:54 [PATCH v9 00/42] drm: Implement state readout support Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 01/42] drm/atomic: Add drm_atomic_get_connector_for_encoder_locked() Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 02/42] drm/bridge-helper: Don't unlock the connection mutex after a backoff Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 03/42] drm/tests: hdmi-state-helper: Handle EDEADLK in the 420-only test Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 04/42] drm/tests: hdmi-state-helper: Handle EDEADLK in the color format test Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 05/42] drm/colorop: Export drm_atomic_helper_colorop_create_state() Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 06/42] drm/atomic: Fix private obj error handling Maxime Ripard
2026-11-20 12:54 ` [PATCH v9 07/42] drm/atomic: Add drm_private_obj name Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 08/42] drm/bridge: Switch print_state to use bridge name Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 09/42] drm/bridge: Add drm_private_obj_is_bridge() Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 10/42] drm/fb-dma-helper: Handle framebuffers without a GEM object Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 11/42] drm/gem-atomic-helper: " Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 12/42] drm/atomic: Export drm_atomic_*_print_state Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 13/42] drm/atomic_sro: Create drm_atomic_sro_state container Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 14/42] drm/atomic_sro: Create kernel parameter to force or disable readout Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 15/42] drm/atomic_sro: Add atomic state readout infrastructure Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 16/42] drm/atomic_sro: Create documentation Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 17/42] drm/bridge: Handle bridges with hardware state readout Maxime Ripard
2026-11-20 13:18   ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 18/42] drm/mode-config: Read out hardware state in drm_mode_config_create_initial_state Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 19/42] drm/atomic_sro: Provide helpers to implement hardware state readout Maxime Ripard
2026-11-20 13:17   ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 20/42] drm/mode-config: Introduce hw_reset hook Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 21/42] drm/modeset-helper: Add drm_mode_config_helper_hw_reset() Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 22/42] drm/atomic_helper: Compare actual and readout states once the commit is done Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 23/42] drm/atomic-state-helper: Provide comparison macros Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 24/42] drm/atomic-state-helper: Provide atomic_compare_state helpers Maxime Ripard
2026-11-20 13:14   ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 25/42] drm/atomic-helper: Document State Read-Out as a state initialization approach Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 26/42] drm/tests: kunit: Add a drm_printer helper Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 27/42] drm/tests: Add tests for the atomic state readout Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 28/42] drm/encoder: Create atomic_sro_get_current_crtc hook Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 29/42] drm/bridge: display-connector: Implement readout support Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 30/42] drm/bridge_connector: Implement hw readout for connector Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 31/42] drm/tidss: Implement hw_reset Maxime Ripard
2026-11-20 12:55 ` Maxime Ripard [this message]
2026-11-20 13:14   ` [PATCH v9 32/42] drm/tidss: crtc: Implement hardware state readout sashiko-bot
2026-11-20 12:55 ` [PATCH v9 33/42] drm/tidss: encoder: " Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 34/42] drm/tidss: kms: Hook up " Maxime Ripard
2026-11-20 13:25   ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 35/42] drm/tidss: plane: Implement " Maxime Ripard
2026-11-20 13:28   ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 36/42] drm/tidss: dispc: Add hardware state readout helpers Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 37/42] drm/tidss: encoder: Implement atomic_sro_get_current_crtc Maxime Ripard
2026-11-20 12:55 ` [PATCH v9 38/42] drm/bridge: sii902x: Implement hw state readout Maxime Ripard
2026-11-20 13:26   ` sashiko-bot
2026-11-20 12:55 ` [PATCH v9 39/42] drm/panel: Implement state readout support Maxime Ripard
2026-11-20 12:55 ` [PATCH DO NOT MERGE v9 40/42] fixup! drm/tidss: dispc: Add hardware state readout helpers Maxime Ripard
2026-11-20 12:55 ` [PATCH DO NOT MERGE v9 41/42] drm/tidss: oldi: Implement hardware state readout Maxime Ripard
2026-11-20 13:34   ` sashiko-bot
2026-11-20 12:55 ` [PATCH HACK v9 42/42] drm/panel: Prepare and enable panels read out as active 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=20261120-drm-state-readout-v9-32-a67c2b45b8ec@kernel.org \
    --to=mripard@kernel.org \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=airlied@gmail.com \
    --cc=andrzej.hajda@intel.com \
    --cc=devarsht@ti.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=jonas@kwiboo.se \
    --cc=jyri.sarha@iki.fi \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=neil.armstrong@linaro.org \
    --cc=rfoss@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tomi.valkeinen@ideasonboard.com \
    --cc=tzimmermann@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.