[RFC PATCH 2/4] drm/panel: Implement state readout in the panel bridge
From: Màxim Pedraza Padilla
Date: Mon Nov 16 2026 - 08:27:30 EST
The state readout core gives up if a private object doesn't implement
readout, so a driver using a panel bridge can't adopt the firmware state,
even if it implements readout itself.
A panel has no state to read back: it's part of the pipeline if the CRTC
feeding its encoder is active. Implement the connector and bridge readout
on that assumption, relying on the encoder's
atomic_sro_get_current_crtc hook, and fill the bus configuration with what
the commit negotiation would give.
When the state is installed, prepare and enable the panel, since nothing
else would until the first modeset.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Màxim Pedraza Padilla <maximpedraza@xxxxxxxxx>
---
drivers/gpu/drm/drm_panel.c | 92 ++++++++++++++++++++++++++++++++++++-
1 file changed, 91 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
index c00529bfb706..7cee228f798b 100644
--- a/drivers/gpu/drm/drm_panel.c
+++ b/drivers/gpu/drm/drm_panel.c
@@ -9,10 +9,14 @@
#include <linux/debugfs.h>
#include <linux/err.h>
#include <linux/export.h>
+#include <linux/media-bus-format.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
+#include <drm/drm_atomic_state_readout.h>
+#include <drm/drm_atomic_state_readout_helper.h>
#include <drm/drm_bridge.h>
#include <drm/drm_connector.h>
#include <drm/drm_crtc.h>
@@ -216,6 +220,88 @@ static void panel_bridge_debugfs_init(struct drm_bridge *bridge,
panel->funcs->debugfs_init(panel, root);
}
+/*
+ * A panel has no state to read back: it's part of the pipeline if the CRTC
+ * feeding its encoder is active.
+ */
+static int panel_bridge_connector_readout(struct drm_bridge *bridge,
+ struct drm_atomic_sro_state *state,
+ struct drm_connector_state *conn_state)
+{
+ struct drm_connector *connector = conn_state->connector;
+ struct drm_encoder *encoder = bridge->encoder;
+ struct drm_crtc_state *crtc_state;
+ struct drm_crtc *crtc;
+
+ if (!encoder->funcs || !encoder->funcs->atomic_sro_get_current_crtc)
+ return -ENODEV;
+
+ crtc = encoder->funcs->atomic_sro_get_current_crtc(encoder);
+ if (!crtc)
+ return -ENODEV;
+
+ crtc_state = drm_atomic_sro_get_crtc_state(state, crtc);
+ if (!crtc_state)
+ return -ENODEV;
+
+ if (!crtc_state->active)
+ return 0;
+
+ crtc_state->encoder_mask |= drm_encoder_mask(encoder);
+ crtc_state->connector_mask |= drm_connector_mask(connector);
+
+ /* Released by __drm_atomic_helper_connector_destroy_state(). */
+ drm_connector_get(connector);
+ conn_state->crtc = crtc;
+ conn_state->best_encoder = encoder;
+
+ return 0;
+}
+
+/*
+ * Same result as the bus format negotiation of a commit, which doesn't run
+ * during readout: the panel asks for its first format and flags, and passes
+ * them on through drm_atomic_helper_bridge_propagate_bus_fmt().
+ */
+static int panel_bridge_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)
+{
+ const struct drm_display_info *di = &conn_state->connector->display_info;
+ u32 format = di->num_bus_formats ? di->bus_formats[0] : MEDIA_BUS_FMT_FIXED;
+
+ bridge_state->input_bus_cfg.format = format;
+ bridge_state->input_bus_cfg.flags = di->bus_flags;
+ bridge_state->output_bus_cfg.format = format;
+ bridge_state->output_bus_cfg.flags = di->bus_flags;
+
+ return 0;
+}
+
+/*
+ * The firmware left the pipeline running, so the panel is taken as part of it.
+ * Without this it would stay off until the first modeset.
+ */
+static void panel_bridge_install_state(struct drm_bridge *bridge,
+ struct drm_bridge_state *state)
+{
+ struct drm_panel *panel = drm_bridge_to_panel(bridge);
+ struct drm_encoder *encoder = bridge->encoder;
+ struct drm_crtc *crtc;
+
+ if (!encoder->funcs || !encoder->funcs->atomic_sro_get_current_crtc)
+ return;
+
+ crtc = encoder->funcs->atomic_sro_get_current_crtc(encoder);
+ if (!crtc || !crtc->state->active)
+ return;
+
+ drm_panel_prepare(panel);
+ drm_panel_enable(panel);
+}
+
static const struct drm_bridge_funcs panel_bridge_bridge_funcs = {
.attach = panel_bridge_attach,
.detach = panel_bridge_detach,
@@ -228,6 +314,10 @@ static const struct drm_bridge_funcs panel_bridge_bridge_funcs = {
.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
.atomic_get_input_bus_fmts = drm_atomic_helper_bridge_propagate_bus_fmt,
+ .atomic_sro_readout_state = panel_bridge_readout_state,
+ .atomic_sro_compare_state = drm_atomic_helper_bridge_compare_state,
+ .atomic_sro_connector_readout = panel_bridge_connector_readout,
+ .atomic_sro_install_state = panel_bridge_install_state,
.debugfs_init = panel_bridge_debugfs_init,
};
@@ -600,7 +690,7 @@ void drm_panel_add(struct drm_panel *panel)
mutex_unlock(&panel_lock);
panel->bridge.of_node = panel->dev->of_node;
- panel->bridge.ops = DRM_BRIDGE_OP_MODES;
+ panel->bridge.ops = DRM_BRIDGE_OP_MODES | DRM_BRIDGE_OP_CONNECTOR_HW_READOUT;
panel->bridge.type = panel->connector_type;
panel->bridge.pre_enable_prev_first = panel->prepare_prev_first;
--
2.39.5