drm/bridge: Add a function to abstract away panels
authorMaxime Ripard <maxime@cerno.tech>
Fri, 10 Sep 2021 13:09:39 +0000 (15:09 +0200)
committerMaxime Ripard <maxime@cerno.tech>
Wed, 7 Sep 2022 08:52:58 +0000 (10:52 +0200)
Display drivers so far need to have a lot of boilerplate to first
retrieve either the panel or bridge that they are connected to using
drm_of_find_panel_or_bridge(), and then either deal with each with ad-hoc
functions or create a drm panel bridge through drm_panel_bridge_add.

In order to reduce the boilerplate and hopefully create a path of least
resistance towards using the DRM panel bridge layer, let's create the
function devm_drm_of_get_bridge() to reduce that boilerplate.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20210910130941.1740182-2-maxime@cerno.tech
drivers/gpu/drm/drm_bridge.c

index 726a393..0755224 100644 (file)
@@ -1313,6 +1313,40 @@ struct drm_bridge *of_drm_find_bridge(struct device_node *np)
        return NULL;
 }
 EXPORT_SYMBOL(of_drm_find_bridge);
+
+/**
+ * devm_drm_of_get_bridge - Return next bridge in the chain
+ * @dev: device to tie the bridge lifetime to
+ * @np: device tree node containing encoder output ports
+ * @port: port in the device tree node
+ * @endpoint: endpoint in the device tree node
+ *
+ * Given a DT node's port and endpoint number, finds the connected node
+ * and returns the associated bridge if any, or creates and returns a
+ * drm panel bridge instance if a panel is connected.
+ *
+ * Returns a pointer to the bridge if successful, or an error pointer
+ * otherwise.
+ */
+struct drm_bridge *devm_drm_of_get_bridge(struct device *dev,
+                                         struct device_node *np,
+                                         u32 port, u32 endpoint)
+{
+       struct drm_bridge *bridge;
+       struct drm_panel *panel;
+       int ret;
+
+       ret = drm_of_find_panel_or_bridge(np, port, endpoint,
+                                         &panel, &bridge);
+       if (ret)
+               return ERR_PTR(ret);
+
+       if (panel)
+               bridge = devm_drm_panel_bridge_add(dev, panel);
+
+       return bridge;
+}
+EXPORT_SYMBOL(devm_drm_of_get_bridge);
 #endif
 
 MODULE_AUTHOR("Ajay Kumar <ajaykumar.rs@samsung.com>");