[PATCH RFC v3 19/31] drm/bridge: add drm_bridge_get_next() and supporting func

From: Luca Ceresoli

Date: Wed Nov 18 2026 - 11:53:15 EST


For bridge hotplug we need to successfully probe a card with an incomplete
bridge chain, i.e. a chain whose last bridge currently in bridge_chain
needs another bridge at its output. Such a card would have no connector,
and be able to add one as soon as the following bridges are added up to the
bridge that requires no further ones (like a panel or a connector_bridge).

So we need a way to know whether the pipeline is complete in the hardware
(all bridges probed), in order to complete it in software (attach all
bridges not yet attached). Currently common DRM code has no way to know
that.

Add drm_bridge_get_next() and a supporting get_next_bridge func so each
bridge can expose its next bridge, and whether there's supposed to be one.

A subsequent commit will use this function to detect whether the pipeline
is complete in the hardware or not.

Link: https://lore.kernel.org/r/20260624-vagabond-neon-gorilla-cd6487@houat
Suggested-by: Maxime Ripard <mripard@xxxxxxxxxx>
Signed-off-by: Luca Ceresoli <luca.ceresoli@xxxxxxxxxxx>

---

Changes in v3:
- fix and improve kerneldoc

New patch in v2, replacing the is_tail patch in v1
---
drivers/gpu/drm/drm_bridge.c | 30 ++++++++++++++++++++++++++++++
include/drm/drm_bridge.h | 25 +++++++++++++++++++++++++
2 files changed, 55 insertions(+)

diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index bcf65cddbd6e..e0a1e016b37c 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -705,6 +705,36 @@ void drm_bridge_detach(struct drm_bridge *bridge)
drm_bridge_put(bridge);
}

+/**
+ * drm_bridge_get_next - return the bridge at this bridge's output port
+ * @bridge: the bridge to query
+ *
+ * Return the next bridge, i.e. the bridge that is connected at the output
+ * port of @bridge. Unlike drm_bridge_get_next_bridge(), the next bridge
+ * might or not be in the encoder chain.
+ *
+ * Returns:
+ * * Pointer to a bridge connected to the output port of this bridge,
+ * with refcount incremented; call drm_bridge_put() when done
+ * * ERR_PTR(-ENODEV): this bridge has an output port where a next bridge
+ * needs to be present for video output, but the next
+ * bridge is not currently available
+ * * NULL: this bridge does not have an output port where a next bridge
+ * is expected
+ * * ERR_PTR(-ENOENT): the bridge does not implement the func
+ * * Another negative error returned by the bridge func
+ */
+struct drm_bridge *drm_bridge_get_next(struct drm_bridge *bridge)
+{
+ if (!(bridge->ops & DRM_BRIDGE_OP_GET_NEXT_BRIDGE)) {
+ drm_warn_once(bridge->dev, "get_next_bridge func not implemented!");
+ return ERR_PTR(-ENOENT);
+ }
+
+ return bridge->funcs->get_next_bridge(bridge);
+}
+EXPORT_SYMBOL(drm_bridge_get_next);
+
/**
* DOC: bridge operations
*
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index c88532998aae..32962224a6e7 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -62,6 +62,25 @@ enum drm_bridge_attach_flags {
* struct drm_bridge_funcs - drm_bridge control functions
*/
struct drm_bridge_funcs {
+ /**
+ * @get_next_bridge:
+ *
+ * Return a pointer to the bridge connected at the output port of
+ * this bridge.
+ *
+ * Returns:
+ * * Pointer to a bridge connected to the output port of this bridge,
+ * with refcount incremented; call drm_bridge_put() when done
+ * * ERR_PTR(-ENODEV): this bridge has an output port where a next
+ * bridge needs to be present for video output,
+ * but the next bridge is not currently
+ * available
+ * * NULL: this bridge does not have an output port where a next
+ * bridge is expected (e.g. a panel)
+ * * Another negative error returned by the bridge func
+ */
+ struct drm_bridge *(*get_next_bridge)(struct drm_bridge *bridge);
+
/**
* @attach:
*
@@ -1021,6 +1040,11 @@ enum drm_bridge_ops {
* &drm_bridge_funcs->hdmi_clear_spd_infoframe callbacks.
*/
DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME = BIT(10),
+ /**
+ * @DRM_BRIDGE_OP_GET_NEXT_BRIDGE: The bridge implements the
+ * &drm_bridge_funcs->get_next_bridge callback.
+ */
+ DRM_BRIDGE_OP_GET_NEXT_BRIDGE = BIT(11),
};

/**
@@ -1270,6 +1294,7 @@ void drm_bridge_remove(struct drm_bridge *bridge);
int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
struct drm_bridge *previous,
enum drm_bridge_attach_flags flags);
+struct drm_bridge *drm_bridge_get_next(struct drm_bridge *bridge);

#ifdef CONFIG_OF
struct drm_bridge *of_drm_find_and_get_bridge(const struct device_node *np);

--
2.56.1