Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/bridge: Add a function to abstract away panels

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

+42 -4
+37 -4
drivers/gpu/drm/drm_bridge.c
··· 28 28 #include <drm/drm_atomic_state_helper.h> 29 29 #include <drm/drm_bridge.h> 30 30 #include <drm/drm_encoder.h> 31 + #include <drm/drm_of.h> 31 32 #include <drm/drm_print.h> 32 33 33 34 #include "drm_crtc_internal.h" ··· 52 51 * 53 52 * Display drivers are responsible for linking encoders with the first bridge 54 53 * in the chains. This is done by acquiring the appropriate bridge with 55 - * of_drm_find_bridge() or drm_of_find_panel_or_bridge(), or creating it for a 56 - * panel with drm_panel_bridge_add_typed() (or the managed version 57 - * devm_drm_panel_bridge_add_typed()). Once acquired, the bridge shall be 58 - * attached to the encoder with a call to drm_bridge_attach(). 54 + * devm_drm_of_get_bridge(). Once acquired, the bridge shall be attached to the 55 + * encoder with a call to drm_bridge_attach(). 59 56 * 60 57 * Bridges are responsible for linking themselves with the next bridge in the 61 58 * chain, if any. This is done the same way as for encoders, with the call to ··· 1232 1233 return NULL; 1233 1234 } 1234 1235 EXPORT_SYMBOL(of_drm_find_bridge); 1236 + 1237 + /** 1238 + * devm_drm_of_get_bridge - Return next bridge in the chain 1239 + * @dev: device to tie the bridge lifetime to 1240 + * @np: device tree node containing encoder output ports 1241 + * @port: port in the device tree node 1242 + * @endpoint: endpoint in the device tree node 1243 + * 1244 + * Given a DT node's port and endpoint number, finds the connected node 1245 + * and returns the associated bridge if any, or creates and returns a 1246 + * drm panel bridge instance if a panel is connected. 1247 + * 1248 + * Returns a pointer to the bridge if successful, or an error pointer 1249 + * otherwise. 1250 + */ 1251 + struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, 1252 + struct device_node *np, 1253 + u32 port, u32 endpoint) 1254 + { 1255 + struct drm_bridge *bridge; 1256 + struct drm_panel *panel; 1257 + int ret; 1258 + 1259 + ret = drm_of_find_panel_or_bridge(np, port, endpoint, 1260 + &panel, &bridge); 1261 + if (ret) 1262 + return ERR_PTR(ret); 1263 + 1264 + if (panel) 1265 + bridge = devm_drm_panel_bridge_add(dev, panel); 1266 + 1267 + return bridge; 1268 + } 1269 + EXPORT_SYMBOL(devm_drm_of_get_bridge); 1235 1270 #endif 1236 1271 1237 1272 MODULE_AUTHOR("Ajay Kumar <ajaykumar.rs@samsung.com>");
+3
drivers/gpu/drm/drm_of.c
··· 231 231 * return either the associated struct drm_panel or drm_bridge device. Either 232 232 * @panel or @bridge must not be NULL. 233 233 * 234 + * This function is deprecated and should not be used in new drivers. Use 235 + * devm_drm_of_get_bridge() instead. 236 + * 234 237 * Returns zero if successful, or one of the standard error codes if it fails. 235 238 */ 236 239 int drm_of_find_panel_or_bridge(const struct device_node *np,
+2
include/drm/drm_bridge.h
··· 911 911 struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev, 912 912 struct drm_panel *panel, 913 913 u32 connector_type); 914 + struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, struct device_node *node, 915 + u32 port, u32 endpoint); 914 916 struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge); 915 917 #endif 916 918