[PATCH v6 10/26] drm/bridge: add devm_drm_of_get_bridge_by_node()

Luca Ceresoli
2025-02-06T19:01:43Z

devm_drm_of_get_bridge(), which is based on graph links, is the recommended
function to get a pointer to the following bridge.

This is valid even for panels, for which the recommended device tree
description is via graph links and not (or not only) panel subnodes of a
panel controller (e.g. "dsi@1234" controller node with a "panel@0"
subnode).

However there are drivers supporting the panel subnode description in
addition to the graph links. For those drivers add a _by_node variant that
takes the node of the target node.

Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>

---

This patch was added in v6.
---
drivers/gpu/drm/drm_bridge.c | 30 ++++++++++++++++++++++++++++++
include/drm/drm_bridge.h | 8 ++++++++
2 files changed, 38 insertions(+)

diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index 2aa17fbe538b86066c4e68f0d0e8046e9ca9b965..b0834b8644284e5f7751cec81724af849b4180e7 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -1407,6 +1407,36 @@ struct drm_bridge *devm_drm_of_get_bridge(struct device *dev,
}
EXPORT_SYMBOL(devm_drm_of_get_bridge);

+/**
+ * devm_drm_of_get_bridge_by_node - Return bridge for a given OF node
+ * @dev: device to tie the bridge lifetime to
+ * @bridge_node: device node of the remote bridge
+ *
+ * Given a bridge DT node, returns the associated bridge if any. This
+ * should be used in addition to devm_drm_of_get_bridge() when the regular
+ * graph link search is not enough, e.g. for drivers that need to support
+ * panels described only as subnodes.
+ *
+ * RETURNS:
+ * A pointer to the bridge if successful, or an error pointer otherwise.
+ */
+struct drm_bridge *devm_drm_of_get_bridge_by_node(struct device *dev,
+ struct device_node *bridge_node)
+{
+ struct drm_bridge *bridge;
+ int ret;
+
+ if (!bridge_node)
+ return ERR_PTR(-EINVAL);
+
+ bridge = of_drm_find_bridge(bridge_node);
+ if (!bridge)
+ return ERR_PTR(-ENODEV);
+
+ return bridge;
+}
+EXPORT_SYMBOL(devm_drm_of_get_bridge_by_node);
+
/**
* drmm_of_get_bridge - Return next bridge in the chain
* @drm: device to tie the bridge lifetime to
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index 496dbbd2ad7edff7f091adfbe62de1e33ef0cf07..1561347c4991dac6022319774510f9560c9283c3 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -1088,6 +1088,8 @@ static inline int drm_panel_bridge_set_orientation(struct drm_connector *connect
#if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL_BRIDGE)
struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, struct device_node *node,
u32 port, u32 endpoint);
+struct drm_bridge *devm_drm_of_get_bridge_by_node(struct device *dev,
+ struct device_node *bridge_node);
struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm, struct device_node *node,
u32 port, u32 endpoint);
#else
@@ -1099,6 +1101,12 @@ static inline struct drm_bridge *devm_drm_of_get_bridge(struct device *dev,
return ERR_PTR(-ENODEV);
}

+static inline struct drm_bridge *devm_drm_of_get_bridge_by_node(struct device *dev,
+ struct device_node *bridge_node)
+{
+ return ERR_PTR(-ENODEV);
+}
+
static inline struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm,
struct device_node *node,
u32 port,

--
2.34.1