xref: /openbmc/linux/drivers/gpu/drm/bridge/panel.c (revision 34263c1b)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
213dfc054SEric Anholt /*
313dfc054SEric Anholt  * Copyright (C) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
413dfc054SEric Anholt  * Copyright (C) 2017 Broadcom
513dfc054SEric Anholt  */
613dfc054SEric Anholt 
713dfc054SEric Anholt #include <drm/drm_atomic_helper.h>
8ee68c743SBoris Brezillon #include <drm/drm_bridge.h>
913dfc054SEric Anholt #include <drm/drm_connector.h>
1013dfc054SEric Anholt #include <drm/drm_encoder.h>
1113dfc054SEric Anholt #include <drm/drm_modeset_helper_vtables.h>
12d4ae66f1SMaxime Ripard #include <drm/drm_of.h>
1313dfc054SEric Anholt #include <drm/drm_panel.h>
1495b60804SSam Ravnborg #include <drm/drm_print.h>
1578666baaSSabyasachi Gupta #include <drm/drm_probe_helper.h>
1613dfc054SEric Anholt 
1713dfc054SEric Anholt struct panel_bridge {
1813dfc054SEric Anholt 	struct drm_bridge bridge;
1913dfc054SEric Anholt 	struct drm_connector connector;
2013dfc054SEric Anholt 	struct drm_panel *panel;
2113dfc054SEric Anholt 	u32 connector_type;
2213dfc054SEric Anholt };
2313dfc054SEric Anholt 
2413dfc054SEric Anholt static inline struct panel_bridge *
2513dfc054SEric Anholt drm_bridge_to_panel_bridge(struct drm_bridge *bridge)
2613dfc054SEric Anholt {
2713dfc054SEric Anholt 	return container_of(bridge, struct panel_bridge, bridge);
2813dfc054SEric Anholt }
2913dfc054SEric Anholt 
3013dfc054SEric Anholt static inline struct panel_bridge *
3113dfc054SEric Anholt drm_connector_to_panel_bridge(struct drm_connector *connector)
3213dfc054SEric Anholt {
3313dfc054SEric Anholt 	return container_of(connector, struct panel_bridge, connector);
3413dfc054SEric Anholt }
3513dfc054SEric Anholt 
3613dfc054SEric Anholt static int panel_bridge_connector_get_modes(struct drm_connector *connector)
3713dfc054SEric Anholt {
3813dfc054SEric Anholt 	struct panel_bridge *panel_bridge =
3913dfc054SEric Anholt 		drm_connector_to_panel_bridge(connector);
4013dfc054SEric Anholt 
4106c4a9c2SSam Ravnborg 	return drm_panel_get_modes(panel_bridge->panel, connector);
4213dfc054SEric Anholt }
4313dfc054SEric Anholt 
4413dfc054SEric Anholt static const struct drm_connector_helper_funcs
4513dfc054SEric Anholt panel_bridge_connector_helper_funcs = {
4613dfc054SEric Anholt 	.get_modes = panel_bridge_connector_get_modes,
4713dfc054SEric Anholt };
4813dfc054SEric Anholt 
4913dfc054SEric Anholt static const struct drm_connector_funcs panel_bridge_connector_funcs = {
5013dfc054SEric Anholt 	.reset = drm_atomic_helper_connector_reset,
5113dfc054SEric Anholt 	.fill_modes = drm_helper_probe_single_connector_modes,
5213dfc054SEric Anholt 	.destroy = drm_connector_cleanup,
5313dfc054SEric Anholt 	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
5413dfc054SEric Anholt 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
5513dfc054SEric Anholt };
5613dfc054SEric Anholt 
57a25b988fSLaurent Pinchart static int panel_bridge_attach(struct drm_bridge *bridge,
58a25b988fSLaurent Pinchart 			       enum drm_bridge_attach_flags flags)
5913dfc054SEric Anholt {
6013dfc054SEric Anholt 	struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
6113dfc054SEric Anholt 	struct drm_connector *connector = &panel_bridge->connector;
6213dfc054SEric Anholt 	int ret;
6313dfc054SEric Anholt 
642be68b59SLaurent Pinchart 	if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)
652be68b59SLaurent Pinchart 		return 0;
66a25b988fSLaurent Pinchart 
6713dfc054SEric Anholt 	if (!bridge->encoder) {
6813dfc054SEric Anholt 		DRM_ERROR("Missing encoder\n");
6913dfc054SEric Anholt 		return -ENODEV;
7013dfc054SEric Anholt 	}
7113dfc054SEric Anholt 
7213dfc054SEric Anholt 	drm_connector_helper_add(connector,
7313dfc054SEric Anholt 				 &panel_bridge_connector_helper_funcs);
7413dfc054SEric Anholt 
7513dfc054SEric Anholt 	ret = drm_connector_init(bridge->dev, connector,
7613dfc054SEric Anholt 				 &panel_bridge_connector_funcs,
7713dfc054SEric Anholt 				 panel_bridge->connector_type);
7813dfc054SEric Anholt 	if (ret) {
7913dfc054SEric Anholt 		DRM_ERROR("Failed to initialize connector\n");
8013dfc054SEric Anholt 		return ret;
8113dfc054SEric Anholt 	}
8213dfc054SEric Anholt 
83cde4c44dSDaniel Vetter 	drm_connector_attach_encoder(&panel_bridge->connector,
8413dfc054SEric Anholt 					  bridge->encoder);
8513dfc054SEric Anholt 
86*34263c1bSMarek Szyprowski 	if (bridge->dev->registered) {
87934aef88SJagan Teki 		if (connector->funcs->reset)
88934aef88SJagan Teki 			connector->funcs->reset(connector);
89*34263c1bSMarek Szyprowski 		drm_connector_register(connector);
90*34263c1bSMarek Szyprowski 	}
91934aef88SJagan Teki 
9213dfc054SEric Anholt 	return 0;
9313dfc054SEric Anholt }
9413dfc054SEric Anholt 
9513dfc054SEric Anholt static void panel_bridge_detach(struct drm_bridge *bridge)
9613dfc054SEric Anholt {
974d906839SPaul Cercueil 	struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
984d906839SPaul Cercueil 	struct drm_connector *connector = &panel_bridge->connector;
994d906839SPaul Cercueil 
1004d906839SPaul Cercueil 	/*
1014d906839SPaul Cercueil 	 * Cleanup the connector if we know it was initialized.
1024d906839SPaul Cercueil 	 *
1034d906839SPaul Cercueil 	 * FIXME: This wouldn't be needed if the panel_bridge structure was
1044d906839SPaul Cercueil 	 * allocated with drmm_kzalloc(). This might be tricky since the
1054d906839SPaul Cercueil 	 * drm_device pointer can only be retrieved when the bridge is attached.
1064d906839SPaul Cercueil 	 */
1074d906839SPaul Cercueil 	if (connector->dev)
1084d906839SPaul Cercueil 		drm_connector_cleanup(connector);
10913dfc054SEric Anholt }
11013dfc054SEric Anholt 
11113dfc054SEric Anholt static void panel_bridge_pre_enable(struct drm_bridge *bridge)
11213dfc054SEric Anholt {
11313dfc054SEric Anholt 	struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
11413dfc054SEric Anholt 
11513dfc054SEric Anholt 	drm_panel_prepare(panel_bridge->panel);
11613dfc054SEric Anholt }
11713dfc054SEric Anholt 
11813dfc054SEric Anholt static void panel_bridge_enable(struct drm_bridge *bridge)
11913dfc054SEric Anholt {
12013dfc054SEric Anholt 	struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
12113dfc054SEric Anholt 
12213dfc054SEric Anholt 	drm_panel_enable(panel_bridge->panel);
12313dfc054SEric Anholt }
12413dfc054SEric Anholt 
12513dfc054SEric Anholt static void panel_bridge_disable(struct drm_bridge *bridge)
12613dfc054SEric Anholt {
12713dfc054SEric Anholt 	struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
12813dfc054SEric Anholt 
12913dfc054SEric Anholt 	drm_panel_disable(panel_bridge->panel);
13013dfc054SEric Anholt }
13113dfc054SEric Anholt 
13213dfc054SEric Anholt static void panel_bridge_post_disable(struct drm_bridge *bridge)
13313dfc054SEric Anholt {
13413dfc054SEric Anholt 	struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
13513dfc054SEric Anholt 
13613dfc054SEric Anholt 	drm_panel_unprepare(panel_bridge->panel);
13713dfc054SEric Anholt }
13813dfc054SEric Anholt 
1392be68b59SLaurent Pinchart static int panel_bridge_get_modes(struct drm_bridge *bridge,
1402be68b59SLaurent Pinchart 				  struct drm_connector *connector)
1412be68b59SLaurent Pinchart {
1422be68b59SLaurent Pinchart 	struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
1432be68b59SLaurent Pinchart 
1442be68b59SLaurent Pinchart 	return drm_panel_get_modes(panel_bridge->panel, connector);
1452be68b59SLaurent Pinchart }
1462be68b59SLaurent Pinchart 
1472509969aSDouglas Anderson static void panel_bridge_debugfs_init(struct drm_bridge *bridge,
1482509969aSDouglas Anderson 				      struct dentry *root)
1492509969aSDouglas Anderson {
1502509969aSDouglas Anderson 	struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
1512509969aSDouglas Anderson 	struct drm_panel *panel = panel_bridge->panel;
1522509969aSDouglas Anderson 
1532509969aSDouglas Anderson 	root = debugfs_create_dir("panel", root);
1542509969aSDouglas Anderson 	if (panel->funcs->debugfs_init)
1552509969aSDouglas Anderson 		panel->funcs->debugfs_init(panel, root);
1562509969aSDouglas Anderson }
1572509969aSDouglas Anderson 
15813dfc054SEric Anholt static const struct drm_bridge_funcs panel_bridge_bridge_funcs = {
15913dfc054SEric Anholt 	.attach = panel_bridge_attach,
16013dfc054SEric Anholt 	.detach = panel_bridge_detach,
16113dfc054SEric Anholt 	.pre_enable = panel_bridge_pre_enable,
16213dfc054SEric Anholt 	.enable = panel_bridge_enable,
16313dfc054SEric Anholt 	.disable = panel_bridge_disable,
16413dfc054SEric Anholt 	.post_disable = panel_bridge_post_disable,
1652be68b59SLaurent Pinchart 	.get_modes = panel_bridge_get_modes,
166cf52925aSBoris Brezillon 	.atomic_reset = drm_atomic_helper_bridge_reset,
167cf52925aSBoris Brezillon 	.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
168cf52925aSBoris Brezillon 	.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
169cf52925aSBoris Brezillon 	.atomic_get_input_bus_fmts = drm_atomic_helper_bridge_propagate_bus_fmt,
1702509969aSDouglas Anderson 	.debugfs_init = panel_bridge_debugfs_init,
17113dfc054SEric Anholt };
17213dfc054SEric Anholt 
17313dfc054SEric Anholt /**
1740aa5eb3aSDaniel Vetter  * drm_panel_bridge_add - Creates a &drm_bridge and &drm_connector that
1750aa5eb3aSDaniel Vetter  * just calls the appropriate functions from &drm_panel.
17613dfc054SEric Anholt  *
17713dfc054SEric Anholt  * @panel: The drm_panel being wrapped.  Must be non-NULL.
17813dfc054SEric Anholt  *
17913dfc054SEric Anholt  * For drivers converting from directly using drm_panel: The expected
18013dfc054SEric Anholt  * usage pattern is that during either encoder module probe or DSI
18113dfc054SEric Anholt  * host attach, a drm_panel will be looked up through
18213dfc054SEric Anholt  * drm_of_find_panel_or_bridge().  drm_panel_bridge_add() is used to
18313dfc054SEric Anholt  * wrap that panel in the new bridge, and the result can then be
18413dfc054SEric Anholt  * passed to drm_bridge_attach().  The drm_panel_prepare() and related
18513dfc054SEric Anholt  * functions can be dropped from the encoder driver (they're now
18613dfc054SEric Anholt  * called by the KMS helpers before calling into the encoder), along
1870aa5eb3aSDaniel Vetter  * with connector creation.  When done with the bridge (after
1880aa5eb3aSDaniel Vetter  * drm_mode_config_cleanup() if the bridge has already been attached), then
18913dfc054SEric Anholt  * drm_panel_bridge_remove() to free it.
1900aa5eb3aSDaniel Vetter  *
19189958b7cSLaurent Pinchart  * The connector type is set to @panel->connector_type, which must be set to a
19289958b7cSLaurent Pinchart  * known type. Calling this function with a panel whose connector type is
19330be3031SEnric Balletbo i Serra  * DRM_MODE_CONNECTOR_Unknown will return ERR_PTR(-EINVAL).
19489958b7cSLaurent Pinchart  *
195cb05ec58SEnric Balletbo i Serra  * See devm_drm_panel_bridge_add() for an automatically managed version of this
1960aa5eb3aSDaniel Vetter  * function.
19713dfc054SEric Anholt  */
19889958b7cSLaurent Pinchart struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel)
19989958b7cSLaurent Pinchart {
20089958b7cSLaurent Pinchart 	if (WARN_ON(panel->connector_type == DRM_MODE_CONNECTOR_Unknown))
20130be3031SEnric Balletbo i Serra 		return ERR_PTR(-EINVAL);
20289958b7cSLaurent Pinchart 
20389958b7cSLaurent Pinchart 	return drm_panel_bridge_add_typed(panel, panel->connector_type);
20489958b7cSLaurent Pinchart }
20589958b7cSLaurent Pinchart EXPORT_SYMBOL(drm_panel_bridge_add);
20689958b7cSLaurent Pinchart 
20789958b7cSLaurent Pinchart /**
20889958b7cSLaurent Pinchart  * drm_panel_bridge_add_typed - Creates a &drm_bridge and &drm_connector with
20989958b7cSLaurent Pinchart  * an explicit connector type.
21089958b7cSLaurent Pinchart  * @panel: The drm_panel being wrapped.  Must be non-NULL.
21189958b7cSLaurent Pinchart  * @connector_type: The connector type (DRM_MODE_CONNECTOR_*)
21289958b7cSLaurent Pinchart  *
21389958b7cSLaurent Pinchart  * This is just like drm_panel_bridge_add(), but forces the connector type to
21489958b7cSLaurent Pinchart  * @connector_type instead of infering it from the panel.
21589958b7cSLaurent Pinchart  *
21689958b7cSLaurent Pinchart  * This function is deprecated and should not be used in new drivers. Use
21789958b7cSLaurent Pinchart  * drm_panel_bridge_add() instead, and fix panel drivers as necessary if they
21889958b7cSLaurent Pinchart  * don't report a connector type.
21989958b7cSLaurent Pinchart  */
22089958b7cSLaurent Pinchart struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
22113dfc054SEric Anholt 					      u32 connector_type)
22213dfc054SEric Anholt {
22313dfc054SEric Anholt 	struct panel_bridge *panel_bridge;
22413dfc054SEric Anholt 
22513dfc054SEric Anholt 	if (!panel)
226e6f0acb2SEric Anholt 		return ERR_PTR(-EINVAL);
22713dfc054SEric Anholt 
22813dfc054SEric Anholt 	panel_bridge = devm_kzalloc(panel->dev, sizeof(*panel_bridge),
22913dfc054SEric Anholt 				    GFP_KERNEL);
23013dfc054SEric Anholt 	if (!panel_bridge)
23113dfc054SEric Anholt 		return ERR_PTR(-ENOMEM);
23213dfc054SEric Anholt 
23313dfc054SEric Anholt 	panel_bridge->connector_type = connector_type;
23413dfc054SEric Anholt 	panel_bridge->panel = panel;
23513dfc054SEric Anholt 
23613dfc054SEric Anholt 	panel_bridge->bridge.funcs = &panel_bridge_bridge_funcs;
23713dfc054SEric Anholt #ifdef CONFIG_OF
23813dfc054SEric Anholt 	panel_bridge->bridge.of_node = panel->dev->of_node;
23913dfc054SEric Anholt #endif
2402be68b59SLaurent Pinchart 	panel_bridge->bridge.ops = DRM_BRIDGE_OP_MODES;
2412be68b59SLaurent Pinchart 	panel_bridge->bridge.type = connector_type;
24213dfc054SEric Anholt 
2433a45d25dSInki Dae 	drm_bridge_add(&panel_bridge->bridge);
24413dfc054SEric Anholt 
24513dfc054SEric Anholt 	return &panel_bridge->bridge;
24613dfc054SEric Anholt }
24789958b7cSLaurent Pinchart EXPORT_SYMBOL(drm_panel_bridge_add_typed);
24813dfc054SEric Anholt 
24913dfc054SEric Anholt /**
25013dfc054SEric Anholt  * drm_panel_bridge_remove - Unregisters and frees a drm_bridge
25113dfc054SEric Anholt  * created by drm_panel_bridge_add().
25213dfc054SEric Anholt  *
25313dfc054SEric Anholt  * @bridge: The drm_bridge being freed.
25413dfc054SEric Anholt  */
25513dfc054SEric Anholt void drm_panel_bridge_remove(struct drm_bridge *bridge)
25613dfc054SEric Anholt {
2576b0e284cSbenjamin.gaignard@linaro.org 	struct panel_bridge *panel_bridge;
2586b0e284cSbenjamin.gaignard@linaro.org 
2596b0e284cSbenjamin.gaignard@linaro.org 	if (!bridge)
2606b0e284cSbenjamin.gaignard@linaro.org 		return;
2616b0e284cSbenjamin.gaignard@linaro.org 
2626b0e284cSbenjamin.gaignard@linaro.org 	if (bridge->funcs != &panel_bridge_bridge_funcs)
2636b0e284cSbenjamin.gaignard@linaro.org 		return;
2646b0e284cSbenjamin.gaignard@linaro.org 
2656b0e284cSbenjamin.gaignard@linaro.org 	panel_bridge = drm_bridge_to_panel_bridge(bridge);
26613dfc054SEric Anholt 
26713dfc054SEric Anholt 	drm_bridge_remove(bridge);
26813dfc054SEric Anholt 	devm_kfree(panel_bridge->panel->dev, bridge);
26913dfc054SEric Anholt }
27013dfc054SEric Anholt EXPORT_SYMBOL(drm_panel_bridge_remove);
27167022227SEric Anholt 
27267022227SEric Anholt static void devm_drm_panel_bridge_release(struct device *dev, void *res)
27367022227SEric Anholt {
27467022227SEric Anholt 	struct drm_bridge **bridge = res;
27567022227SEric Anholt 
27667022227SEric Anholt 	drm_panel_bridge_remove(*bridge);
27767022227SEric Anholt }
27867022227SEric Anholt 
2790aa5eb3aSDaniel Vetter /**
2800aa5eb3aSDaniel Vetter  * devm_drm_panel_bridge_add - Creates a managed &drm_bridge and &drm_connector
2810aa5eb3aSDaniel Vetter  * that just calls the appropriate functions from &drm_panel.
2820aa5eb3aSDaniel Vetter  * @dev: device to tie the bridge lifetime to
2830aa5eb3aSDaniel Vetter  * @panel: The drm_panel being wrapped.  Must be non-NULL.
2840aa5eb3aSDaniel Vetter  *
2850aa5eb3aSDaniel Vetter  * This is the managed version of drm_panel_bridge_add() which automatically
2860aa5eb3aSDaniel Vetter  * calls drm_panel_bridge_remove() when @dev is unbound.
2870aa5eb3aSDaniel Vetter  */
28867022227SEric Anholt struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
28989958b7cSLaurent Pinchart 					     struct drm_panel *panel)
29089958b7cSLaurent Pinchart {
29189958b7cSLaurent Pinchart 	if (WARN_ON(panel->connector_type == DRM_MODE_CONNECTOR_Unknown))
29230be3031SEnric Balletbo i Serra 		return ERR_PTR(-EINVAL);
29389958b7cSLaurent Pinchart 
29489958b7cSLaurent Pinchart 	return devm_drm_panel_bridge_add_typed(dev, panel,
29589958b7cSLaurent Pinchart 					       panel->connector_type);
29689958b7cSLaurent Pinchart }
29789958b7cSLaurent Pinchart EXPORT_SYMBOL(devm_drm_panel_bridge_add);
29889958b7cSLaurent Pinchart 
29989958b7cSLaurent Pinchart /**
30089958b7cSLaurent Pinchart  * devm_drm_panel_bridge_add_typed - Creates a managed &drm_bridge and
30189958b7cSLaurent Pinchart  * &drm_connector with an explicit connector type.
30289958b7cSLaurent Pinchart  * @dev: device to tie the bridge lifetime to
30389958b7cSLaurent Pinchart  * @panel: The drm_panel being wrapped.  Must be non-NULL.
30489958b7cSLaurent Pinchart  * @connector_type: The connector type (DRM_MODE_CONNECTOR_*)
30589958b7cSLaurent Pinchart  *
30689958b7cSLaurent Pinchart  * This is just like devm_drm_panel_bridge_add(), but forces the connector type
30789958b7cSLaurent Pinchart  * to @connector_type instead of infering it from the panel.
30889958b7cSLaurent Pinchart  *
30989958b7cSLaurent Pinchart  * This function is deprecated and should not be used in new drivers. Use
31089958b7cSLaurent Pinchart  * devm_drm_panel_bridge_add() instead, and fix panel drivers as necessary if
31189958b7cSLaurent Pinchart  * they don't report a connector type.
31289958b7cSLaurent Pinchart  */
31389958b7cSLaurent Pinchart struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
31467022227SEric Anholt 						   struct drm_panel *panel,
31567022227SEric Anholt 						   u32 connector_type)
31667022227SEric Anholt {
31767022227SEric Anholt 	struct drm_bridge **ptr, *bridge;
31867022227SEric Anholt 
31967022227SEric Anholt 	ptr = devres_alloc(devm_drm_panel_bridge_release, sizeof(*ptr),
32067022227SEric Anholt 			   GFP_KERNEL);
32167022227SEric Anholt 	if (!ptr)
32267022227SEric Anholt 		return ERR_PTR(-ENOMEM);
32367022227SEric Anholt 
32489958b7cSLaurent Pinchart 	bridge = drm_panel_bridge_add_typed(panel, connector_type);
32567022227SEric Anholt 	if (!IS_ERR(bridge)) {
32667022227SEric Anholt 		*ptr = bridge;
32767022227SEric Anholt 		devres_add(dev, ptr);
32867022227SEric Anholt 	} else {
32967022227SEric Anholt 		devres_free(ptr);
33067022227SEric Anholt 	}
33167022227SEric Anholt 
33267022227SEric Anholt 	return bridge;
33367022227SEric Anholt }
33489958b7cSLaurent Pinchart EXPORT_SYMBOL(devm_drm_panel_bridge_add_typed);
335d383fb5fSSam Ravnborg 
336d383fb5fSSam Ravnborg /**
337d383fb5fSSam Ravnborg  * drm_panel_bridge_connector - return the connector for the panel bridge
33891fcf8e6SSam Ravnborg  * @bridge: The drm_bridge.
339d383fb5fSSam Ravnborg  *
340d383fb5fSSam Ravnborg  * drm_panel_bridge creates the connector.
341d383fb5fSSam Ravnborg  * This function gives external access to the connector.
342d383fb5fSSam Ravnborg  *
343d383fb5fSSam Ravnborg  * Returns: Pointer to drm_connector
344d383fb5fSSam Ravnborg  */
345d383fb5fSSam Ravnborg struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge)
346d383fb5fSSam Ravnborg {
347d383fb5fSSam Ravnborg 	struct panel_bridge *panel_bridge;
348d383fb5fSSam Ravnborg 
349d383fb5fSSam Ravnborg 	panel_bridge = drm_bridge_to_panel_bridge(bridge);
350d383fb5fSSam Ravnborg 
351d383fb5fSSam Ravnborg 	return &panel_bridge->connector;
352d383fb5fSSam Ravnborg }
3533cc1430cSMihail Atanassov EXPORT_SYMBOL(drm_panel_bridge_connector);
354d4ae66f1SMaxime Ripard 
355d4ae66f1SMaxime Ripard #ifdef CONFIG_OF
356d4ae66f1SMaxime Ripard /**
357d4ae66f1SMaxime Ripard  * devm_drm_of_get_bridge - Return next bridge in the chain
358d4ae66f1SMaxime Ripard  * @dev: device to tie the bridge lifetime to
359d4ae66f1SMaxime Ripard  * @np: device tree node containing encoder output ports
360d4ae66f1SMaxime Ripard  * @port: port in the device tree node
361d4ae66f1SMaxime Ripard  * @endpoint: endpoint in the device tree node
362d4ae66f1SMaxime Ripard  *
363d4ae66f1SMaxime Ripard  * Given a DT node's port and endpoint number, finds the connected node
364d4ae66f1SMaxime Ripard  * and returns the associated bridge if any, or creates and returns a
365d4ae66f1SMaxime Ripard  * drm panel bridge instance if a panel is connected.
366d4ae66f1SMaxime Ripard  *
367d4ae66f1SMaxime Ripard  * Returns a pointer to the bridge if successful, or an error pointer
368d4ae66f1SMaxime Ripard  * otherwise.
369d4ae66f1SMaxime Ripard  */
370d4ae66f1SMaxime Ripard struct drm_bridge *devm_drm_of_get_bridge(struct device *dev,
371d4ae66f1SMaxime Ripard 					  struct device_node *np,
372d4ae66f1SMaxime Ripard 					  u32 port, u32 endpoint)
373d4ae66f1SMaxime Ripard {
374d4ae66f1SMaxime Ripard 	struct drm_bridge *bridge;
375d4ae66f1SMaxime Ripard 	struct drm_panel *panel;
376d4ae66f1SMaxime Ripard 	int ret;
377d4ae66f1SMaxime Ripard 
378d4ae66f1SMaxime Ripard 	ret = drm_of_find_panel_or_bridge(np, port, endpoint,
379d4ae66f1SMaxime Ripard 					  &panel, &bridge);
380d4ae66f1SMaxime Ripard 	if (ret)
381d4ae66f1SMaxime Ripard 		return ERR_PTR(ret);
382d4ae66f1SMaxime Ripard 
383d4ae66f1SMaxime Ripard 	if (panel)
384d4ae66f1SMaxime Ripard 		bridge = devm_drm_panel_bridge_add(dev, panel);
385d4ae66f1SMaxime Ripard 
386d4ae66f1SMaxime Ripard 	return bridge;
387d4ae66f1SMaxime Ripard }
388d4ae66f1SMaxime Ripard EXPORT_SYMBOL(devm_drm_of_get_bridge);
389d4ae66f1SMaxime Ripard #endif
390