mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
To: Maxime Ripard <mripard@kernel.org>
Cc: michael@amarulasolutions.com, linux-amarula@amarulasolutions.com,
	Dario Binacchi <dario.binacchi@amarulasolutions.com>,
	Andrzej Hajda <andrzej.hajda@intel.com>,
	David Airlie <airlied@gmail.com>, Inki Dae <inki.dae@samsung.com>,
	Jagan Teki <jagan@amarulasolutions.com>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	Jonas Karlman <jonas@kwiboo.se>,
	Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
	Luca Ceresoli <luca.ceresoli@bootlin.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Robert Foss <rfoss@kernel.org>, Simona Vetter <simona@ffwll.ch>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 7/8] drm/bridge: samsung-dsim: Implement hw state readout
Date: Sun, 22 Nov 2026 16:30:07 +0100	[thread overview]
Message-ID: <20261122153032.2782768-8-dario.binacchi@amarulasolutions.com> (raw)
In-Reply-To: <20261122153032.2782768-1-dario.binacchi@amarulasolutions.com>

Read out the state of the bridge from the hardware, so that a video
stream left running by the bootloader is taken over without
initializing the bridge again.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

 drivers/gpu/drm/bridge/samsung-dsim.c | 125 +++++++++++++++++++++++---
 1 file changed, 112 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/bridge/samsung-dsim.c b/drivers/gpu/drm/bridge/samsung-dsim.c
index 480e568dd2c9..2eba8f482d0c 100644
--- a/drivers/gpu/drm/bridge/samsung-dsim.c
+++ b/drivers/gpu/drm/bridge/samsung-dsim.c
@@ -20,11 +20,15 @@
 #include <linux/of.h>
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/units.h>
 
 #include <video/mipi_display.h>
 
 #include <drm/bridge/samsung-dsim.h>
+#include <drm/drm_atomic_state_readout.h>
+#include <drm/drm_atomic_state_readout_helper.h>
+#include <drm/drm_connector.h>
 #include <drm/drm_print.h>
 
 /* returns true iff both arguments logically differs */
@@ -1562,6 +1566,17 @@ static int samsung_dsim_transfer(struct samsung_dsim *dsi,
 	return xfer->result;
 }
 
+static void samsung_dsim_unmask_irqs(struct samsung_dsim *dsi)
+{
+	unsigned long mask = ~(DSIM_INT_RX_DONE |
+			       DSIM_INT_SFR_FIFO_EMPTY |
+			       DSIM_INT_SFR_HDR_FIFO_EMPTY |
+			       DSIM_INT_RX_ECC_ERR |
+			       DSIM_INT_SW_RST_RELEASE);
+
+	samsung_dsim_write(dsi, DSIM_INTMSK_REG, mask);
+}
+
 static irqreturn_t samsung_dsim_irq(int irq, void *dev_id)
 {
 	struct samsung_dsim *dsi = dev_id;
@@ -1578,12 +1593,7 @@ static irqreturn_t samsung_dsim_irq(int irq, void *dev_id)
 	samsung_dsim_write(dsi, DSIM_INTSRC_REG, status);
 
 	if (status & DSIM_INT_SW_RST_RELEASE) {
-		unsigned long mask = ~(DSIM_INT_RX_DONE |
-				       DSIM_INT_SFR_FIFO_EMPTY |
-				       DSIM_INT_SFR_HDR_FIFO_EMPTY |
-				       DSIM_INT_RX_ECC_ERR |
-				       DSIM_INT_SW_RST_RELEASE);
-		samsung_dsim_write(dsi, DSIM_INTMSK_REG, mask);
+		samsung_dsim_unmask_irqs(dsi);
 		complete(&dsi->completed);
 		return IRQ_HANDLED;
 	}
@@ -1758,14 +1768,9 @@ samsung_dsim_atomic_get_input_bus_fmts(struct drm_bridge *bridge,
 	return input_fmts;
 }
 
-static int samsung_dsim_atomic_check(struct drm_bridge *bridge,
-				     struct drm_bridge_state *bridge_state,
-				     struct drm_crtc_state *crtc_state,
-				     struct drm_connector_state *conn_state)
+static void samsung_dsim_fixup_mode(struct samsung_dsim *dsi,
+				    struct drm_display_mode *adjusted_mode)
 {
-	struct samsung_dsim *dsi = bridge_to_dsi(bridge);
-	struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
-
 	/*
 	 * The i.MX8M Mini/Nano glue logic between LCDIF and DSIM
 	 * inverts HS/VS/DE sync signals polarity, therefore, while
@@ -1808,6 +1813,16 @@ static int samsung_dsim_atomic_check(struct drm_bridge *bridge,
 			adjusted_mode->htotal      += remainder;
 		}
 	}
+}
+
+static int samsung_dsim_atomic_check(struct drm_bridge *bridge,
+				     struct drm_bridge_state *bridge_state,
+				     struct drm_crtc_state *crtc_state,
+				     struct drm_connector_state *conn_state)
+{
+	struct samsung_dsim *dsi = bridge_to_dsi(bridge);
+
+	samsung_dsim_fixup_mode(dsi, &crtc_state->adjusted_mode);
 
 	return 0;
 }
@@ -1831,6 +1846,87 @@ static int samsung_dsim_attach(struct drm_bridge *bridge,
 				 flags);
 }
 
+static bool samsung_dsim_hw_is_running(struct samsung_dsim *dsi)
+{
+	const struct samsung_dsim_driver_data *driver_data = dsi->driver_data;
+	u32 reg;
+
+	if (!(samsung_dsim_read(dsi, DSIM_PLLCTRL_REG) & DSIM_PLL_EN))
+		return false;
+
+	if (driver_data->has_legacy_status_reg)
+		reg = samsung_dsim_read(dsi, DSIM_STATUS_REG);
+	else
+		reg = samsung_dsim_read(dsi, DSIM_LINK_STATUS_REG);
+
+	if (!(reg & BIT(driver_data->pll_stable_bit)))
+		return false;
+
+	return samsung_dsim_read(dsi, DSIM_MDRESOL_REG) & DSIM_MAIN_STAND_BY;
+}
+
+static int samsung_dsim_readout_state(struct drm_bridge *bridge,
+				      struct drm_atomic_sro_state *state,
+				      struct drm_bridge_state *bridge_state,
+				      struct drm_crtc_state *crtc_state,
+				      struct drm_connector_state *conn_state)
+{
+	struct samsung_dsim *dsi = bridge_to_dsi(bridge);
+	struct drm_display_info *info = &conn_state->connector->display_info;
+	u32 format = MEDIA_BUS_FMT_FIXED;
+	bool running;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(dsi->dev);
+	if (ret < 0)
+		return ret;
+
+	running = samsung_dsim_hw_is_running(dsi);
+	pm_runtime_put(dsi->dev);
+
+	/* The pipeline is active but the video stream is not */
+	if (!running)
+		return -EINVAL;
+
+	/* Rebuild the bus configuration the atomic helpers negotiate */
+	if (info->num_bus_formats)
+		format = info->bus_formats[0];
+
+	bridge_state->output_bus_cfg.format = format;
+	bridge_state->output_bus_cfg.flags = info->bus_flags;
+
+	if (!samsung_dsim_pixel_output_fmt_supported(format))
+		format = MEDIA_BUS_FMT_RGB888_1X24;
+
+	bridge_state->input_bus_cfg.format = format;
+	bridge_state->input_bus_cfg.flags = info->bus_flags;
+
+	/* The mode fixups done in atomic_check can't be read back */
+	samsung_dsim_fixup_mode(dsi, &crtc_state->adjusted_mode);
+
+	return 0;
+}
+
+static void samsung_dsim_install_state(struct drm_bridge *bridge,
+				       struct drm_bridge_state *bridge_state)
+{
+	struct samsung_dsim *dsi = bridge_to_dsi(bridge);
+
+	/* Take the reference samsung_dsim_atomic_pre_enable() would have */
+	if (pm_runtime_resume_and_get(dsi->dev) < 0) {
+		dev_err(dsi->dev, "failed to enable DSI device.\n");
+		return;
+	}
+
+	samsung_dsim_write(dsi, DSIM_INTSRC_REG,
+			   samsung_dsim_read(dsi, DSIM_INTSRC_REG));
+	samsung_dsim_unmask_irqs(dsi);
+	samsung_dsim_enable_irq(dsi);
+
+	dsi->state |= DSIM_STATE_ENABLED | DSIM_STATE_INITIALIZED |
+		      DSIM_STATE_VIDOUT_AVAILABLE;
+}
+
 static const struct drm_bridge_funcs samsung_dsim_bridge_funcs = {
 	.atomic_duplicate_state		= drm_atomic_helper_bridge_duplicate_state,
 	.atomic_destroy_state		= drm_atomic_helper_bridge_destroy_state,
@@ -1843,6 +1939,9 @@ static const struct drm_bridge_funcs samsung_dsim_bridge_funcs = {
 	.atomic_post_disable		= samsung_dsim_atomic_post_disable,
 	.mode_set			= samsung_dsim_mode_set,
 	.attach				= samsung_dsim_attach,
+	.atomic_sro_readout_state	= samsung_dsim_readout_state,
+	.atomic_sro_install_state	= samsung_dsim_install_state,
+	.atomic_sro_compare_state	= drm_atomic_helper_bridge_compare_state,
 };
 
 static irqreturn_t samsung_dsim_te_irq_handler(int irq, void *dev_id)
-- 
2.43.0


  parent reply	other threads:[~2026-11-22 15:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 15:30 [RFC PATCH 0/8] drm: State readout for the i.MX8MN display pipeline Dario Binacchi
2026-11-22 15:30 ` [RFC PATCH 1/8] drm/bridge: Add atomic_sro_install_state hook Dario Binacchi
2026-11-22 15:30 ` [RFC PATCH 2/8] drm/panel: Add sro_install hook Dario Binacchi
2026-11-22 15:30 ` [RFC PATCH 3/8] drm/mxsfb: Use the bridge connector Dario Binacchi
2026-11-22 15:30 ` [RFC PATCH 4/8] drm/mxsfb: Switch to drm_mode_config_create_initial_state() Dario Binacchi
2026-11-22 15:30 ` [RFC PATCH 5/8] drm/mxsfb: Stop the controller in hw_reset Dario Binacchi
2026-11-22 15:30 ` [RFC PATCH 6/8] drm/mxsfb: Implement hw state readout Dario Binacchi
2026-11-22 15:30 ` Dario Binacchi [this message]
2026-11-22 15:30 ` [RFC PATCH 8/8] drm/panel: synaptics-r63353: Support " Dario Binacchi

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=20261122153032.2782768-8-dario.binacchi@amarulasolutions.com \
    --to=dario.binacchi@amarulasolutions.com \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=airlied@gmail.com \
    --cc=andrzej.hajda@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=inki.dae@samsung.com \
    --cc=jagan@amarulasolutions.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=jonas@kwiboo.se \
    --cc=linux-amarula@amarulasolutions.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=m.szyprowski@samsung.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=michael@amarulasolutions.com \
    --cc=mripard@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=rfoss@kernel.org \
    --cc=simona@ffwll.ch \
    --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 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®