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 8634263c1bSMarek Szyprowski if (bridge->dev->registered) { 87934aef88SJagan Teki if (connector->funcs->reset) 88934aef88SJagan Teki connector->funcs->reset(connector); 8934263c1bSMarek Szyprowski drm_connector_register(connector); 9034263c1bSMarek 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 /** 174*15b9ca16SHsin-Yi Wang * drm_bridge_is_panel - Checks if a drm_bridge is a panel_bridge. 175*15b9ca16SHsin-Yi Wang * 176*15b9ca16SHsin-Yi Wang * @bridge: The drm_bridge to be checked. 177*15b9ca16SHsin-Yi Wang * 178*15b9ca16SHsin-Yi Wang * Returns true if the bridge is a panel bridge, or false otherwise. 179*15b9ca16SHsin-Yi Wang */ 180*15b9ca16SHsin-Yi Wang bool drm_bridge_is_panel(const struct drm_bridge *bridge) 181*15b9ca16SHsin-Yi Wang { 182*15b9ca16SHsin-Yi Wang return bridge->funcs == &panel_bridge_bridge_funcs; 183*15b9ca16SHsin-Yi Wang } 184*15b9ca16SHsin-Yi Wang EXPORT_SYMBOL(drm_bridge_is_panel); 185*15b9ca16SHsin-Yi Wang 186*15b9ca16SHsin-Yi Wang /** 1870aa5eb3aSDaniel Vetter * drm_panel_bridge_add - Creates a &drm_bridge and &drm_connector that 1880aa5eb3aSDaniel Vetter * just calls the appropriate functions from &drm_panel. 18913dfc054SEric Anholt * 19013dfc054SEric Anholt * @panel: The drm_panel being wrapped. Must be non-NULL. 19113dfc054SEric Anholt * 19213dfc054SEric Anholt * For drivers converting from directly using drm_panel: The expected 19313dfc054SEric Anholt * usage pattern is that during either encoder module probe or DSI 19413dfc054SEric Anholt * host attach, a drm_panel will be looked up through 19513dfc054SEric Anholt * drm_of_find_panel_or_bridge(). drm_panel_bridge_add() is used to 19613dfc054SEric Anholt * wrap that panel in the new bridge, and the result can then be 19713dfc054SEric Anholt * passed to drm_bridge_attach(). The drm_panel_prepare() and related 19813dfc054SEric Anholt * functions can be dropped from the encoder driver (they're now 19913dfc054SEric Anholt * called by the KMS helpers before calling into the encoder), along 2000aa5eb3aSDaniel Vetter * with connector creation. When done with the bridge (after 2010aa5eb3aSDaniel Vetter * drm_mode_config_cleanup() if the bridge has already been attached), then 20213dfc054SEric Anholt * drm_panel_bridge_remove() to free it. 2030aa5eb3aSDaniel Vetter * 20489958b7cSLaurent Pinchart * The connector type is set to @panel->connector_type, which must be set to a 20589958b7cSLaurent Pinchart * known type. Calling this function with a panel whose connector type is 20630be3031SEnric Balletbo i Serra * DRM_MODE_CONNECTOR_Unknown will return ERR_PTR(-EINVAL). 20789958b7cSLaurent Pinchart * 208cb05ec58SEnric Balletbo i Serra * See devm_drm_panel_bridge_add() for an automatically managed version of this 2090aa5eb3aSDaniel Vetter * function. 21013dfc054SEric Anholt */ 21189958b7cSLaurent Pinchart struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel) 21289958b7cSLaurent Pinchart { 21389958b7cSLaurent Pinchart if (WARN_ON(panel->connector_type == DRM_MODE_CONNECTOR_Unknown)) 21430be3031SEnric Balletbo i Serra return ERR_PTR(-EINVAL); 21589958b7cSLaurent Pinchart 21689958b7cSLaurent Pinchart return drm_panel_bridge_add_typed(panel, panel->connector_type); 21789958b7cSLaurent Pinchart } 21889958b7cSLaurent Pinchart EXPORT_SYMBOL(drm_panel_bridge_add); 21989958b7cSLaurent Pinchart 22089958b7cSLaurent Pinchart /** 22189958b7cSLaurent Pinchart * drm_panel_bridge_add_typed - Creates a &drm_bridge and &drm_connector with 22289958b7cSLaurent Pinchart * an explicit connector type. 22389958b7cSLaurent Pinchart * @panel: The drm_panel being wrapped. Must be non-NULL. 22489958b7cSLaurent Pinchart * @connector_type: The connector type (DRM_MODE_CONNECTOR_*) 22589958b7cSLaurent Pinchart * 22689958b7cSLaurent Pinchart * This is just like drm_panel_bridge_add(), but forces the connector type to 22789958b7cSLaurent Pinchart * @connector_type instead of infering it from the panel. 22889958b7cSLaurent Pinchart * 22989958b7cSLaurent Pinchart * This function is deprecated and should not be used in new drivers. Use 23089958b7cSLaurent Pinchart * drm_panel_bridge_add() instead, and fix panel drivers as necessary if they 23189958b7cSLaurent Pinchart * don't report a connector type. 23289958b7cSLaurent Pinchart */ 23389958b7cSLaurent Pinchart struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel, 23413dfc054SEric Anholt u32 connector_type) 23513dfc054SEric Anholt { 23613dfc054SEric Anholt struct panel_bridge *panel_bridge; 23713dfc054SEric Anholt 23813dfc054SEric Anholt if (!panel) 239e6f0acb2SEric Anholt return ERR_PTR(-EINVAL); 24013dfc054SEric Anholt 24113dfc054SEric Anholt panel_bridge = devm_kzalloc(panel->dev, sizeof(*panel_bridge), 24213dfc054SEric Anholt GFP_KERNEL); 24313dfc054SEric Anholt if (!panel_bridge) 24413dfc054SEric Anholt return ERR_PTR(-ENOMEM); 24513dfc054SEric Anholt 24613dfc054SEric Anholt panel_bridge->connector_type = connector_type; 24713dfc054SEric Anholt panel_bridge->panel = panel; 24813dfc054SEric Anholt 24913dfc054SEric Anholt panel_bridge->bridge.funcs = &panel_bridge_bridge_funcs; 25013dfc054SEric Anholt #ifdef CONFIG_OF 25113dfc054SEric Anholt panel_bridge->bridge.of_node = panel->dev->of_node; 25213dfc054SEric Anholt #endif 2532be68b59SLaurent Pinchart panel_bridge->bridge.ops = DRM_BRIDGE_OP_MODES; 2542be68b59SLaurent Pinchart panel_bridge->bridge.type = connector_type; 25513dfc054SEric Anholt 2563a45d25dSInki Dae drm_bridge_add(&panel_bridge->bridge); 25713dfc054SEric Anholt 25813dfc054SEric Anholt return &panel_bridge->bridge; 25913dfc054SEric Anholt } 26089958b7cSLaurent Pinchart EXPORT_SYMBOL(drm_panel_bridge_add_typed); 26113dfc054SEric Anholt 26213dfc054SEric Anholt /** 26313dfc054SEric Anholt * drm_panel_bridge_remove - Unregisters and frees a drm_bridge 26413dfc054SEric Anholt * created by drm_panel_bridge_add(). 26513dfc054SEric Anholt * 26613dfc054SEric Anholt * @bridge: The drm_bridge being freed. 26713dfc054SEric Anholt */ 26813dfc054SEric Anholt void drm_panel_bridge_remove(struct drm_bridge *bridge) 26913dfc054SEric Anholt { 2706b0e284cSbenjamin.gaignard@linaro.org struct panel_bridge *panel_bridge; 2716b0e284cSbenjamin.gaignard@linaro.org 2726b0e284cSbenjamin.gaignard@linaro.org if (!bridge) 2736b0e284cSbenjamin.gaignard@linaro.org return; 2746b0e284cSbenjamin.gaignard@linaro.org 2756b0e284cSbenjamin.gaignard@linaro.org if (bridge->funcs != &panel_bridge_bridge_funcs) 2766b0e284cSbenjamin.gaignard@linaro.org return; 2776b0e284cSbenjamin.gaignard@linaro.org 2786b0e284cSbenjamin.gaignard@linaro.org panel_bridge = drm_bridge_to_panel_bridge(bridge); 27913dfc054SEric Anholt 28013dfc054SEric Anholt drm_bridge_remove(bridge); 28113dfc054SEric Anholt devm_kfree(panel_bridge->panel->dev, bridge); 28213dfc054SEric Anholt } 28313dfc054SEric Anholt EXPORT_SYMBOL(drm_panel_bridge_remove); 28467022227SEric Anholt 285*15b9ca16SHsin-Yi Wang /** 286*15b9ca16SHsin-Yi Wang * drm_panel_bridge_set_orientation - Set the connector's panel orientation 287*15b9ca16SHsin-Yi Wang * from the bridge that can be transformed to panel bridge. 288*15b9ca16SHsin-Yi Wang * 289*15b9ca16SHsin-Yi Wang * @connector: The connector to be set panel orientation. 290*15b9ca16SHsin-Yi Wang * @bridge: The drm_bridge to be transformed to panel bridge. 291*15b9ca16SHsin-Yi Wang * 292*15b9ca16SHsin-Yi Wang * Returns 0 on success, negative errno on failure. 293*15b9ca16SHsin-Yi Wang */ 294*15b9ca16SHsin-Yi Wang int drm_panel_bridge_set_orientation(struct drm_connector *connector, 295*15b9ca16SHsin-Yi Wang struct drm_bridge *bridge) 296*15b9ca16SHsin-Yi Wang { 297*15b9ca16SHsin-Yi Wang struct panel_bridge *panel_bridge; 298*15b9ca16SHsin-Yi Wang 299*15b9ca16SHsin-Yi Wang panel_bridge = drm_bridge_to_panel_bridge(bridge); 300*15b9ca16SHsin-Yi Wang 301*15b9ca16SHsin-Yi Wang return drm_connector_set_orientation_from_panel(connector, 302*15b9ca16SHsin-Yi Wang panel_bridge->panel); 303*15b9ca16SHsin-Yi Wang } 304*15b9ca16SHsin-Yi Wang EXPORT_SYMBOL(drm_panel_bridge_set_orientation); 305*15b9ca16SHsin-Yi Wang 30667022227SEric Anholt static void devm_drm_panel_bridge_release(struct device *dev, void *res) 30767022227SEric Anholt { 30867022227SEric Anholt struct drm_bridge **bridge = res; 30967022227SEric Anholt 31067022227SEric Anholt drm_panel_bridge_remove(*bridge); 31167022227SEric Anholt } 31267022227SEric Anholt 3130aa5eb3aSDaniel Vetter /** 3140aa5eb3aSDaniel Vetter * devm_drm_panel_bridge_add - Creates a managed &drm_bridge and &drm_connector 3150aa5eb3aSDaniel Vetter * that just calls the appropriate functions from &drm_panel. 3160aa5eb3aSDaniel Vetter * @dev: device to tie the bridge lifetime to 3170aa5eb3aSDaniel Vetter * @panel: The drm_panel being wrapped. Must be non-NULL. 3180aa5eb3aSDaniel Vetter * 3190aa5eb3aSDaniel Vetter * This is the managed version of drm_panel_bridge_add() which automatically 3200aa5eb3aSDaniel Vetter * calls drm_panel_bridge_remove() when @dev is unbound. 3210aa5eb3aSDaniel Vetter */ 32267022227SEric Anholt struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev, 32389958b7cSLaurent Pinchart struct drm_panel *panel) 32489958b7cSLaurent Pinchart { 32589958b7cSLaurent Pinchart if (WARN_ON(panel->connector_type == DRM_MODE_CONNECTOR_Unknown)) 32630be3031SEnric Balletbo i Serra return ERR_PTR(-EINVAL); 32789958b7cSLaurent Pinchart 32889958b7cSLaurent Pinchart return devm_drm_panel_bridge_add_typed(dev, panel, 32989958b7cSLaurent Pinchart panel->connector_type); 33089958b7cSLaurent Pinchart } 33189958b7cSLaurent Pinchart EXPORT_SYMBOL(devm_drm_panel_bridge_add); 33289958b7cSLaurent Pinchart 33389958b7cSLaurent Pinchart /** 33489958b7cSLaurent Pinchart * devm_drm_panel_bridge_add_typed - Creates a managed &drm_bridge and 33589958b7cSLaurent Pinchart * &drm_connector with an explicit connector type. 33689958b7cSLaurent Pinchart * @dev: device to tie the bridge lifetime to 33789958b7cSLaurent Pinchart * @panel: The drm_panel being wrapped. Must be non-NULL. 33889958b7cSLaurent Pinchart * @connector_type: The connector type (DRM_MODE_CONNECTOR_*) 33989958b7cSLaurent Pinchart * 34089958b7cSLaurent Pinchart * This is just like devm_drm_panel_bridge_add(), but forces the connector type 34189958b7cSLaurent Pinchart * to @connector_type instead of infering it from the panel. 34289958b7cSLaurent Pinchart * 34389958b7cSLaurent Pinchart * This function is deprecated and should not be used in new drivers. Use 34489958b7cSLaurent Pinchart * devm_drm_panel_bridge_add() instead, and fix panel drivers as necessary if 34589958b7cSLaurent Pinchart * they don't report a connector type. 34689958b7cSLaurent Pinchart */ 34789958b7cSLaurent Pinchart struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev, 34867022227SEric Anholt struct drm_panel *panel, 34967022227SEric Anholt u32 connector_type) 35067022227SEric Anholt { 35167022227SEric Anholt struct drm_bridge **ptr, *bridge; 35267022227SEric Anholt 35367022227SEric Anholt ptr = devres_alloc(devm_drm_panel_bridge_release, sizeof(*ptr), 35467022227SEric Anholt GFP_KERNEL); 35567022227SEric Anholt if (!ptr) 35667022227SEric Anholt return ERR_PTR(-ENOMEM); 35767022227SEric Anholt 35889958b7cSLaurent Pinchart bridge = drm_panel_bridge_add_typed(panel, connector_type); 35967022227SEric Anholt if (!IS_ERR(bridge)) { 36067022227SEric Anholt *ptr = bridge; 36167022227SEric Anholt devres_add(dev, ptr); 36267022227SEric Anholt } else { 36367022227SEric Anholt devres_free(ptr); 36467022227SEric Anholt } 36567022227SEric Anholt 36667022227SEric Anholt return bridge; 36767022227SEric Anholt } 36889958b7cSLaurent Pinchart EXPORT_SYMBOL(devm_drm_panel_bridge_add_typed); 369d383fb5fSSam Ravnborg 370d383fb5fSSam Ravnborg /** 371d383fb5fSSam Ravnborg * drm_panel_bridge_connector - return the connector for the panel bridge 37291fcf8e6SSam Ravnborg * @bridge: The drm_bridge. 373d383fb5fSSam Ravnborg * 374d383fb5fSSam Ravnborg * drm_panel_bridge creates the connector. 375d383fb5fSSam Ravnborg * This function gives external access to the connector. 376d383fb5fSSam Ravnborg * 377d383fb5fSSam Ravnborg * Returns: Pointer to drm_connector 378d383fb5fSSam Ravnborg */ 379d383fb5fSSam Ravnborg struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge) 380d383fb5fSSam Ravnborg { 381d383fb5fSSam Ravnborg struct panel_bridge *panel_bridge; 382d383fb5fSSam Ravnborg 383d383fb5fSSam Ravnborg panel_bridge = drm_bridge_to_panel_bridge(bridge); 384d383fb5fSSam Ravnborg 385d383fb5fSSam Ravnborg return &panel_bridge->connector; 386d383fb5fSSam Ravnborg } 3873cc1430cSMihail Atanassov EXPORT_SYMBOL(drm_panel_bridge_connector); 388d4ae66f1SMaxime Ripard 389d4ae66f1SMaxime Ripard #ifdef CONFIG_OF 390d4ae66f1SMaxime Ripard /** 391d4ae66f1SMaxime Ripard * devm_drm_of_get_bridge - Return next bridge in the chain 392d4ae66f1SMaxime Ripard * @dev: device to tie the bridge lifetime to 393d4ae66f1SMaxime Ripard * @np: device tree node containing encoder output ports 394d4ae66f1SMaxime Ripard * @port: port in the device tree node 395d4ae66f1SMaxime Ripard * @endpoint: endpoint in the device tree node 396d4ae66f1SMaxime Ripard * 397d4ae66f1SMaxime Ripard * Given a DT node's port and endpoint number, finds the connected node 398d4ae66f1SMaxime Ripard * and returns the associated bridge if any, or creates and returns a 399d4ae66f1SMaxime Ripard * drm panel bridge instance if a panel is connected. 400d4ae66f1SMaxime Ripard * 401d4ae66f1SMaxime Ripard * Returns a pointer to the bridge if successful, or an error pointer 402d4ae66f1SMaxime Ripard * otherwise. 403d4ae66f1SMaxime Ripard */ 404d4ae66f1SMaxime Ripard struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, 405d4ae66f1SMaxime Ripard struct device_node *np, 406d4ae66f1SMaxime Ripard u32 port, u32 endpoint) 407d4ae66f1SMaxime Ripard { 408d4ae66f1SMaxime Ripard struct drm_bridge *bridge; 409d4ae66f1SMaxime Ripard struct drm_panel *panel; 410d4ae66f1SMaxime Ripard int ret; 411d4ae66f1SMaxime Ripard 412d4ae66f1SMaxime Ripard ret = drm_of_find_panel_or_bridge(np, port, endpoint, 413d4ae66f1SMaxime Ripard &panel, &bridge); 414d4ae66f1SMaxime Ripard if (ret) 415d4ae66f1SMaxime Ripard return ERR_PTR(ret); 416d4ae66f1SMaxime Ripard 417d4ae66f1SMaxime Ripard if (panel) 418d4ae66f1SMaxime Ripard bridge = devm_drm_panel_bridge_add(dev, panel); 419d4ae66f1SMaxime Ripard 420d4ae66f1SMaxime Ripard return bridge; 421d4ae66f1SMaxime Ripard } 422d4ae66f1SMaxime Ripard EXPORT_SYMBOL(devm_drm_of_get_bridge); 423d4ae66f1SMaxime Ripard #endif 424