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> 11*abea75e9SMaxime Ripard #include <drm/drm_managed.h> 1213dfc054SEric Anholt #include <drm/drm_modeset_helper_vtables.h> 13d4ae66f1SMaxime Ripard #include <drm/drm_of.h> 1413dfc054SEric Anholt #include <drm/drm_panel.h> 1595b60804SSam Ravnborg #include <drm/drm_print.h> 1678666baaSSabyasachi Gupta #include <drm/drm_probe_helper.h> 1713dfc054SEric Anholt 1813dfc054SEric Anholt struct panel_bridge { 1913dfc054SEric Anholt struct drm_bridge bridge; 2013dfc054SEric Anholt struct drm_connector connector; 2113dfc054SEric Anholt struct drm_panel *panel; 2213dfc054SEric Anholt u32 connector_type; 2313dfc054SEric Anholt }; 2413dfc054SEric Anholt 2513dfc054SEric Anholt static inline struct panel_bridge * 2613dfc054SEric Anholt drm_bridge_to_panel_bridge(struct drm_bridge *bridge) 2713dfc054SEric Anholt { 2813dfc054SEric Anholt return container_of(bridge, struct panel_bridge, bridge); 2913dfc054SEric Anholt } 3013dfc054SEric Anholt 3113dfc054SEric Anholt static inline struct panel_bridge * 3213dfc054SEric Anholt drm_connector_to_panel_bridge(struct drm_connector *connector) 3313dfc054SEric Anholt { 3413dfc054SEric Anholt return container_of(connector, struct panel_bridge, connector); 3513dfc054SEric Anholt } 3613dfc054SEric Anholt 3713dfc054SEric Anholt static int panel_bridge_connector_get_modes(struct drm_connector *connector) 3813dfc054SEric Anholt { 3913dfc054SEric Anholt struct panel_bridge *panel_bridge = 4013dfc054SEric Anholt drm_connector_to_panel_bridge(connector); 4113dfc054SEric Anholt 4206c4a9c2SSam Ravnborg return drm_panel_get_modes(panel_bridge->panel, connector); 4313dfc054SEric Anholt } 4413dfc054SEric Anholt 4513dfc054SEric Anholt static const struct drm_connector_helper_funcs 4613dfc054SEric Anholt panel_bridge_connector_helper_funcs = { 4713dfc054SEric Anholt .get_modes = panel_bridge_connector_get_modes, 4813dfc054SEric Anholt }; 4913dfc054SEric Anholt 5013dfc054SEric Anholt static const struct drm_connector_funcs panel_bridge_connector_funcs = { 5113dfc054SEric Anholt .reset = drm_atomic_helper_connector_reset, 5213dfc054SEric Anholt .fill_modes = drm_helper_probe_single_connector_modes, 5313dfc054SEric Anholt .destroy = drm_connector_cleanup, 5413dfc054SEric Anholt .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 5513dfc054SEric Anholt .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 5613dfc054SEric Anholt }; 5713dfc054SEric Anholt 58a25b988fSLaurent Pinchart static int panel_bridge_attach(struct drm_bridge *bridge, 59a25b988fSLaurent Pinchart enum drm_bridge_attach_flags flags) 6013dfc054SEric Anholt { 6113dfc054SEric Anholt struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); 6213dfc054SEric Anholt struct drm_connector *connector = &panel_bridge->connector; 6313dfc054SEric Anholt int ret; 6413dfc054SEric Anholt 652be68b59SLaurent Pinchart if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) 662be68b59SLaurent Pinchart return 0; 67a25b988fSLaurent Pinchart 6813dfc054SEric Anholt if (!bridge->encoder) { 6913dfc054SEric Anholt DRM_ERROR("Missing encoder\n"); 7013dfc054SEric Anholt return -ENODEV; 7113dfc054SEric Anholt } 7213dfc054SEric Anholt 7313dfc054SEric Anholt drm_connector_helper_add(connector, 7413dfc054SEric Anholt &panel_bridge_connector_helper_funcs); 7513dfc054SEric Anholt 7613dfc054SEric Anholt ret = drm_connector_init(bridge->dev, connector, 7713dfc054SEric Anholt &panel_bridge_connector_funcs, 7813dfc054SEric Anholt panel_bridge->connector_type); 7913dfc054SEric Anholt if (ret) { 8013dfc054SEric Anholt DRM_ERROR("Failed to initialize connector\n"); 8113dfc054SEric Anholt return ret; 8213dfc054SEric Anholt } 8313dfc054SEric Anholt 84cde4c44dSDaniel Vetter drm_connector_attach_encoder(&panel_bridge->connector, 8513dfc054SEric Anholt bridge->encoder); 8613dfc054SEric Anholt 8734263c1bSMarek Szyprowski if (bridge->dev->registered) { 88934aef88SJagan Teki if (connector->funcs->reset) 89934aef88SJagan Teki connector->funcs->reset(connector); 9034263c1bSMarek Szyprowski drm_connector_register(connector); 9134263c1bSMarek Szyprowski } 92934aef88SJagan Teki 9313dfc054SEric Anholt return 0; 9413dfc054SEric Anholt } 9513dfc054SEric Anholt 9613dfc054SEric Anholt static void panel_bridge_detach(struct drm_bridge *bridge) 9713dfc054SEric Anholt { 984d906839SPaul Cercueil struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); 994d906839SPaul Cercueil struct drm_connector *connector = &panel_bridge->connector; 1004d906839SPaul Cercueil 1014d906839SPaul Cercueil /* 1024d906839SPaul Cercueil * Cleanup the connector if we know it was initialized. 1034d906839SPaul Cercueil * 1044d906839SPaul Cercueil * FIXME: This wouldn't be needed if the panel_bridge structure was 1054d906839SPaul Cercueil * allocated with drmm_kzalloc(). This might be tricky since the 1064d906839SPaul Cercueil * drm_device pointer can only be retrieved when the bridge is attached. 1074d906839SPaul Cercueil */ 1084d906839SPaul Cercueil if (connector->dev) 1094d906839SPaul Cercueil drm_connector_cleanup(connector); 11013dfc054SEric Anholt } 11113dfc054SEric Anholt 11213dfc054SEric Anholt static void panel_bridge_pre_enable(struct drm_bridge *bridge) 11313dfc054SEric Anholt { 11413dfc054SEric Anholt struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); 11513dfc054SEric Anholt 11613dfc054SEric Anholt drm_panel_prepare(panel_bridge->panel); 11713dfc054SEric Anholt } 11813dfc054SEric Anholt 11913dfc054SEric Anholt static void panel_bridge_enable(struct drm_bridge *bridge) 12013dfc054SEric Anholt { 12113dfc054SEric Anholt struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); 12213dfc054SEric Anholt 12313dfc054SEric Anholt drm_panel_enable(panel_bridge->panel); 12413dfc054SEric Anholt } 12513dfc054SEric Anholt 12613dfc054SEric Anholt static void panel_bridge_disable(struct drm_bridge *bridge) 12713dfc054SEric Anholt { 12813dfc054SEric Anholt struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); 12913dfc054SEric Anholt 13013dfc054SEric Anholt drm_panel_disable(panel_bridge->panel); 13113dfc054SEric Anholt } 13213dfc054SEric Anholt 13313dfc054SEric Anholt static void panel_bridge_post_disable(struct drm_bridge *bridge) 13413dfc054SEric Anholt { 13513dfc054SEric Anholt struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); 13613dfc054SEric Anholt 13713dfc054SEric Anholt drm_panel_unprepare(panel_bridge->panel); 13813dfc054SEric Anholt } 13913dfc054SEric Anholt 1402be68b59SLaurent Pinchart static int panel_bridge_get_modes(struct drm_bridge *bridge, 1412be68b59SLaurent Pinchart struct drm_connector *connector) 1422be68b59SLaurent Pinchart { 1432be68b59SLaurent Pinchart struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); 1442be68b59SLaurent Pinchart 1452be68b59SLaurent Pinchart return drm_panel_get_modes(panel_bridge->panel, connector); 1462be68b59SLaurent Pinchart } 1472be68b59SLaurent Pinchart 1482509969aSDouglas Anderson static void panel_bridge_debugfs_init(struct drm_bridge *bridge, 1492509969aSDouglas Anderson struct dentry *root) 1502509969aSDouglas Anderson { 1512509969aSDouglas Anderson struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); 1522509969aSDouglas Anderson struct drm_panel *panel = panel_bridge->panel; 1532509969aSDouglas Anderson 1542509969aSDouglas Anderson root = debugfs_create_dir("panel", root); 1552509969aSDouglas Anderson if (panel->funcs->debugfs_init) 1562509969aSDouglas Anderson panel->funcs->debugfs_init(panel, root); 1572509969aSDouglas Anderson } 1582509969aSDouglas Anderson 15913dfc054SEric Anholt static const struct drm_bridge_funcs panel_bridge_bridge_funcs = { 16013dfc054SEric Anholt .attach = panel_bridge_attach, 16113dfc054SEric Anholt .detach = panel_bridge_detach, 16213dfc054SEric Anholt .pre_enable = panel_bridge_pre_enable, 16313dfc054SEric Anholt .enable = panel_bridge_enable, 16413dfc054SEric Anholt .disable = panel_bridge_disable, 16513dfc054SEric Anholt .post_disable = panel_bridge_post_disable, 1662be68b59SLaurent Pinchart .get_modes = panel_bridge_get_modes, 167cf52925aSBoris Brezillon .atomic_reset = drm_atomic_helper_bridge_reset, 168cf52925aSBoris Brezillon .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, 169cf52925aSBoris Brezillon .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, 170cf52925aSBoris Brezillon .atomic_get_input_bus_fmts = drm_atomic_helper_bridge_propagate_bus_fmt, 1712509969aSDouglas Anderson .debugfs_init = panel_bridge_debugfs_init, 17213dfc054SEric Anholt }; 17313dfc054SEric Anholt 17413dfc054SEric Anholt /** 17515b9ca16SHsin-Yi Wang * drm_bridge_is_panel - Checks if a drm_bridge is a panel_bridge. 17615b9ca16SHsin-Yi Wang * 17715b9ca16SHsin-Yi Wang * @bridge: The drm_bridge to be checked. 17815b9ca16SHsin-Yi Wang * 17915b9ca16SHsin-Yi Wang * Returns true if the bridge is a panel bridge, or false otherwise. 18015b9ca16SHsin-Yi Wang */ 18115b9ca16SHsin-Yi Wang bool drm_bridge_is_panel(const struct drm_bridge *bridge) 18215b9ca16SHsin-Yi Wang { 18315b9ca16SHsin-Yi Wang return bridge->funcs == &panel_bridge_bridge_funcs; 18415b9ca16SHsin-Yi Wang } 18515b9ca16SHsin-Yi Wang EXPORT_SYMBOL(drm_bridge_is_panel); 18615b9ca16SHsin-Yi Wang 18715b9ca16SHsin-Yi Wang /** 1880aa5eb3aSDaniel Vetter * drm_panel_bridge_add - Creates a &drm_bridge and &drm_connector that 1890aa5eb3aSDaniel Vetter * just calls the appropriate functions from &drm_panel. 19013dfc054SEric Anholt * 19113dfc054SEric Anholt * @panel: The drm_panel being wrapped. Must be non-NULL. 19213dfc054SEric Anholt * 19313dfc054SEric Anholt * For drivers converting from directly using drm_panel: The expected 19413dfc054SEric Anholt * usage pattern is that during either encoder module probe or DSI 19513dfc054SEric Anholt * host attach, a drm_panel will be looked up through 19613dfc054SEric Anholt * drm_of_find_panel_or_bridge(). drm_panel_bridge_add() is used to 19713dfc054SEric Anholt * wrap that panel in the new bridge, and the result can then be 19813dfc054SEric Anholt * passed to drm_bridge_attach(). The drm_panel_prepare() and related 19913dfc054SEric Anholt * functions can be dropped from the encoder driver (they're now 20013dfc054SEric Anholt * called by the KMS helpers before calling into the encoder), along 2010aa5eb3aSDaniel Vetter * with connector creation. When done with the bridge (after 2020aa5eb3aSDaniel Vetter * drm_mode_config_cleanup() if the bridge has already been attached), then 20313dfc054SEric Anholt * drm_panel_bridge_remove() to free it. 2040aa5eb3aSDaniel Vetter * 20589958b7cSLaurent Pinchart * The connector type is set to @panel->connector_type, which must be set to a 20689958b7cSLaurent Pinchart * known type. Calling this function with a panel whose connector type is 20730be3031SEnric Balletbo i Serra * DRM_MODE_CONNECTOR_Unknown will return ERR_PTR(-EINVAL). 20889958b7cSLaurent Pinchart * 209cb05ec58SEnric Balletbo i Serra * See devm_drm_panel_bridge_add() for an automatically managed version of this 2100aa5eb3aSDaniel Vetter * function. 21113dfc054SEric Anholt */ 21289958b7cSLaurent Pinchart struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel) 21389958b7cSLaurent Pinchart { 21489958b7cSLaurent Pinchart if (WARN_ON(panel->connector_type == DRM_MODE_CONNECTOR_Unknown)) 21530be3031SEnric Balletbo i Serra return ERR_PTR(-EINVAL); 21689958b7cSLaurent Pinchart 21789958b7cSLaurent Pinchart return drm_panel_bridge_add_typed(panel, panel->connector_type); 21889958b7cSLaurent Pinchart } 21989958b7cSLaurent Pinchart EXPORT_SYMBOL(drm_panel_bridge_add); 22089958b7cSLaurent Pinchart 22189958b7cSLaurent Pinchart /** 22289958b7cSLaurent Pinchart * drm_panel_bridge_add_typed - Creates a &drm_bridge and &drm_connector with 22389958b7cSLaurent Pinchart * an explicit connector type. 22489958b7cSLaurent Pinchart * @panel: The drm_panel being wrapped. Must be non-NULL. 22589958b7cSLaurent Pinchart * @connector_type: The connector type (DRM_MODE_CONNECTOR_*) 22689958b7cSLaurent Pinchart * 22789958b7cSLaurent Pinchart * This is just like drm_panel_bridge_add(), but forces the connector type to 22889958b7cSLaurent Pinchart * @connector_type instead of infering it from the panel. 22989958b7cSLaurent Pinchart * 23089958b7cSLaurent Pinchart * This function is deprecated and should not be used in new drivers. Use 23189958b7cSLaurent Pinchart * drm_panel_bridge_add() instead, and fix panel drivers as necessary if they 23289958b7cSLaurent Pinchart * don't report a connector type. 23389958b7cSLaurent Pinchart */ 23489958b7cSLaurent Pinchart struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel, 23513dfc054SEric Anholt u32 connector_type) 23613dfc054SEric Anholt { 23713dfc054SEric Anholt struct panel_bridge *panel_bridge; 23813dfc054SEric Anholt 23913dfc054SEric Anholt if (!panel) 240e6f0acb2SEric Anholt return ERR_PTR(-EINVAL); 24113dfc054SEric Anholt 24213dfc054SEric Anholt panel_bridge = devm_kzalloc(panel->dev, sizeof(*panel_bridge), 24313dfc054SEric Anholt GFP_KERNEL); 24413dfc054SEric Anholt if (!panel_bridge) 24513dfc054SEric Anholt return ERR_PTR(-ENOMEM); 24613dfc054SEric Anholt 24713dfc054SEric Anholt panel_bridge->connector_type = connector_type; 24813dfc054SEric Anholt panel_bridge->panel = panel; 24913dfc054SEric Anholt 25013dfc054SEric Anholt panel_bridge->bridge.funcs = &panel_bridge_bridge_funcs; 25113dfc054SEric Anholt #ifdef CONFIG_OF 25213dfc054SEric Anholt panel_bridge->bridge.of_node = panel->dev->of_node; 25313dfc054SEric Anholt #endif 2542be68b59SLaurent Pinchart panel_bridge->bridge.ops = DRM_BRIDGE_OP_MODES; 2552be68b59SLaurent Pinchart panel_bridge->bridge.type = connector_type; 25613dfc054SEric Anholt 2573a45d25dSInki Dae drm_bridge_add(&panel_bridge->bridge); 25813dfc054SEric Anholt 25913dfc054SEric Anholt return &panel_bridge->bridge; 26013dfc054SEric Anholt } 26189958b7cSLaurent Pinchart EXPORT_SYMBOL(drm_panel_bridge_add_typed); 26213dfc054SEric Anholt 26313dfc054SEric Anholt /** 26413dfc054SEric Anholt * drm_panel_bridge_remove - Unregisters and frees a drm_bridge 26513dfc054SEric Anholt * created by drm_panel_bridge_add(). 26613dfc054SEric Anholt * 26713dfc054SEric Anholt * @bridge: The drm_bridge being freed. 26813dfc054SEric Anholt */ 26913dfc054SEric Anholt void drm_panel_bridge_remove(struct drm_bridge *bridge) 27013dfc054SEric Anholt { 2716b0e284cSbenjamin.gaignard@linaro.org struct panel_bridge *panel_bridge; 2726b0e284cSbenjamin.gaignard@linaro.org 2736b0e284cSbenjamin.gaignard@linaro.org if (!bridge) 2746b0e284cSbenjamin.gaignard@linaro.org return; 2756b0e284cSbenjamin.gaignard@linaro.org 2766b0e284cSbenjamin.gaignard@linaro.org if (bridge->funcs != &panel_bridge_bridge_funcs) 2776b0e284cSbenjamin.gaignard@linaro.org return; 2786b0e284cSbenjamin.gaignard@linaro.org 2796b0e284cSbenjamin.gaignard@linaro.org panel_bridge = drm_bridge_to_panel_bridge(bridge); 28013dfc054SEric Anholt 28113dfc054SEric Anholt drm_bridge_remove(bridge); 28213dfc054SEric Anholt devm_kfree(panel_bridge->panel->dev, bridge); 28313dfc054SEric Anholt } 28413dfc054SEric Anholt EXPORT_SYMBOL(drm_panel_bridge_remove); 28567022227SEric Anholt 28615b9ca16SHsin-Yi Wang /** 28715b9ca16SHsin-Yi Wang * drm_panel_bridge_set_orientation - Set the connector's panel orientation 28815b9ca16SHsin-Yi Wang * from the bridge that can be transformed to panel bridge. 28915b9ca16SHsin-Yi Wang * 29015b9ca16SHsin-Yi Wang * @connector: The connector to be set panel orientation. 29115b9ca16SHsin-Yi Wang * @bridge: The drm_bridge to be transformed to panel bridge. 29215b9ca16SHsin-Yi Wang * 29315b9ca16SHsin-Yi Wang * Returns 0 on success, negative errno on failure. 29415b9ca16SHsin-Yi Wang */ 29515b9ca16SHsin-Yi Wang int drm_panel_bridge_set_orientation(struct drm_connector *connector, 29615b9ca16SHsin-Yi Wang struct drm_bridge *bridge) 29715b9ca16SHsin-Yi Wang { 29815b9ca16SHsin-Yi Wang struct panel_bridge *panel_bridge; 29915b9ca16SHsin-Yi Wang 30015b9ca16SHsin-Yi Wang panel_bridge = drm_bridge_to_panel_bridge(bridge); 30115b9ca16SHsin-Yi Wang 30215b9ca16SHsin-Yi Wang return drm_connector_set_orientation_from_panel(connector, 30315b9ca16SHsin-Yi Wang panel_bridge->panel); 30415b9ca16SHsin-Yi Wang } 30515b9ca16SHsin-Yi Wang EXPORT_SYMBOL(drm_panel_bridge_set_orientation); 30615b9ca16SHsin-Yi Wang 30767022227SEric Anholt static void devm_drm_panel_bridge_release(struct device *dev, void *res) 30867022227SEric Anholt { 30967022227SEric Anholt struct drm_bridge **bridge = res; 31067022227SEric Anholt 31167022227SEric Anholt drm_panel_bridge_remove(*bridge); 31267022227SEric Anholt } 31367022227SEric Anholt 3140aa5eb3aSDaniel Vetter /** 3150aa5eb3aSDaniel Vetter * devm_drm_panel_bridge_add - Creates a managed &drm_bridge and &drm_connector 3160aa5eb3aSDaniel Vetter * that just calls the appropriate functions from &drm_panel. 3170aa5eb3aSDaniel Vetter * @dev: device to tie the bridge lifetime to 3180aa5eb3aSDaniel Vetter * @panel: The drm_panel being wrapped. Must be non-NULL. 3190aa5eb3aSDaniel Vetter * 3200aa5eb3aSDaniel Vetter * This is the managed version of drm_panel_bridge_add() which automatically 3210aa5eb3aSDaniel Vetter * calls drm_panel_bridge_remove() when @dev is unbound. 3220aa5eb3aSDaniel Vetter */ 32367022227SEric Anholt struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev, 32489958b7cSLaurent Pinchart struct drm_panel *panel) 32589958b7cSLaurent Pinchart { 32689958b7cSLaurent Pinchart if (WARN_ON(panel->connector_type == DRM_MODE_CONNECTOR_Unknown)) 32730be3031SEnric Balletbo i Serra return ERR_PTR(-EINVAL); 32889958b7cSLaurent Pinchart 32989958b7cSLaurent Pinchart return devm_drm_panel_bridge_add_typed(dev, panel, 33089958b7cSLaurent Pinchart panel->connector_type); 33189958b7cSLaurent Pinchart } 33289958b7cSLaurent Pinchart EXPORT_SYMBOL(devm_drm_panel_bridge_add); 33389958b7cSLaurent Pinchart 33489958b7cSLaurent Pinchart /** 33589958b7cSLaurent Pinchart * devm_drm_panel_bridge_add_typed - Creates a managed &drm_bridge and 33689958b7cSLaurent Pinchart * &drm_connector with an explicit connector type. 33789958b7cSLaurent Pinchart * @dev: device to tie the bridge lifetime to 33889958b7cSLaurent Pinchart * @panel: The drm_panel being wrapped. Must be non-NULL. 33989958b7cSLaurent Pinchart * @connector_type: The connector type (DRM_MODE_CONNECTOR_*) 34089958b7cSLaurent Pinchart * 34189958b7cSLaurent Pinchart * This is just like devm_drm_panel_bridge_add(), but forces the connector type 34289958b7cSLaurent Pinchart * to @connector_type instead of infering it from the panel. 34389958b7cSLaurent Pinchart * 34489958b7cSLaurent Pinchart * This function is deprecated and should not be used in new drivers. Use 34589958b7cSLaurent Pinchart * devm_drm_panel_bridge_add() instead, and fix panel drivers as necessary if 34689958b7cSLaurent Pinchart * they don't report a connector type. 34789958b7cSLaurent Pinchart */ 34889958b7cSLaurent Pinchart struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev, 34967022227SEric Anholt struct drm_panel *panel, 35067022227SEric Anholt u32 connector_type) 35167022227SEric Anholt { 35267022227SEric Anholt struct drm_bridge **ptr, *bridge; 35367022227SEric Anholt 35467022227SEric Anholt ptr = devres_alloc(devm_drm_panel_bridge_release, sizeof(*ptr), 35567022227SEric Anholt GFP_KERNEL); 35667022227SEric Anholt if (!ptr) 35767022227SEric Anholt return ERR_PTR(-ENOMEM); 35867022227SEric Anholt 35989958b7cSLaurent Pinchart bridge = drm_panel_bridge_add_typed(panel, connector_type); 36067022227SEric Anholt if (!IS_ERR(bridge)) { 36167022227SEric Anholt *ptr = bridge; 36267022227SEric Anholt devres_add(dev, ptr); 36367022227SEric Anholt } else { 36467022227SEric Anholt devres_free(ptr); 36567022227SEric Anholt } 36667022227SEric Anholt 36767022227SEric Anholt return bridge; 36867022227SEric Anholt } 36989958b7cSLaurent Pinchart EXPORT_SYMBOL(devm_drm_panel_bridge_add_typed); 370d383fb5fSSam Ravnborg 371*abea75e9SMaxime Ripard static void drmm_drm_panel_bridge_release(struct drm_device *drm, void *ptr) 372*abea75e9SMaxime Ripard { 373*abea75e9SMaxime Ripard struct drm_bridge *bridge = ptr; 374*abea75e9SMaxime Ripard 375*abea75e9SMaxime Ripard drm_panel_bridge_remove(bridge); 376*abea75e9SMaxime Ripard } 377*abea75e9SMaxime Ripard 378*abea75e9SMaxime Ripard /** 379*abea75e9SMaxime Ripard * drmm_panel_bridge_add - Creates a DRM-managed &drm_bridge and 380*abea75e9SMaxime Ripard * &drm_connector that just calls the 381*abea75e9SMaxime Ripard * appropriate functions from &drm_panel. 382*abea75e9SMaxime Ripard * 383*abea75e9SMaxime Ripard * @drm: DRM device to tie the bridge lifetime to 384*abea75e9SMaxime Ripard * @panel: The drm_panel being wrapped. Must be non-NULL. 385*abea75e9SMaxime Ripard * 386*abea75e9SMaxime Ripard * This is the DRM-managed version of drm_panel_bridge_add() which 387*abea75e9SMaxime Ripard * automatically calls drm_panel_bridge_remove() when @dev is cleaned 388*abea75e9SMaxime Ripard * up. 389*abea75e9SMaxime Ripard */ 390*abea75e9SMaxime Ripard struct drm_bridge *drmm_panel_bridge_add(struct drm_device *drm, 391*abea75e9SMaxime Ripard struct drm_panel *panel) 392*abea75e9SMaxime Ripard { 393*abea75e9SMaxime Ripard struct drm_bridge *bridge; 394*abea75e9SMaxime Ripard int ret; 395*abea75e9SMaxime Ripard 396*abea75e9SMaxime Ripard bridge = drm_panel_bridge_add_typed(panel, panel->connector_type); 397*abea75e9SMaxime Ripard if (IS_ERR(bridge)) 398*abea75e9SMaxime Ripard return bridge; 399*abea75e9SMaxime Ripard 400*abea75e9SMaxime Ripard ret = drmm_add_action_or_reset(drm, drmm_drm_panel_bridge_release, 401*abea75e9SMaxime Ripard bridge); 402*abea75e9SMaxime Ripard if (ret) 403*abea75e9SMaxime Ripard return ERR_PTR(ret); 404*abea75e9SMaxime Ripard 405*abea75e9SMaxime Ripard return bridge; 406*abea75e9SMaxime Ripard } 407*abea75e9SMaxime Ripard EXPORT_SYMBOL(drmm_panel_bridge_add); 408*abea75e9SMaxime Ripard 409d383fb5fSSam Ravnborg /** 410d383fb5fSSam Ravnborg * drm_panel_bridge_connector - return the connector for the panel bridge 41191fcf8e6SSam Ravnborg * @bridge: The drm_bridge. 412d383fb5fSSam Ravnborg * 413d383fb5fSSam Ravnborg * drm_panel_bridge creates the connector. 414d383fb5fSSam Ravnborg * This function gives external access to the connector. 415d383fb5fSSam Ravnborg * 416d383fb5fSSam Ravnborg * Returns: Pointer to drm_connector 417d383fb5fSSam Ravnborg */ 418d383fb5fSSam Ravnborg struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge) 419d383fb5fSSam Ravnborg { 420d383fb5fSSam Ravnborg struct panel_bridge *panel_bridge; 421d383fb5fSSam Ravnborg 422d383fb5fSSam Ravnborg panel_bridge = drm_bridge_to_panel_bridge(bridge); 423d383fb5fSSam Ravnborg 424d383fb5fSSam Ravnborg return &panel_bridge->connector; 425d383fb5fSSam Ravnborg } 4263cc1430cSMihail Atanassov EXPORT_SYMBOL(drm_panel_bridge_connector); 427d4ae66f1SMaxime Ripard 428d4ae66f1SMaxime Ripard #ifdef CONFIG_OF 429d4ae66f1SMaxime Ripard /** 430d4ae66f1SMaxime Ripard * devm_drm_of_get_bridge - Return next bridge in the chain 431d4ae66f1SMaxime Ripard * @dev: device to tie the bridge lifetime to 432d4ae66f1SMaxime Ripard * @np: device tree node containing encoder output ports 433d4ae66f1SMaxime Ripard * @port: port in the device tree node 434d4ae66f1SMaxime Ripard * @endpoint: endpoint in the device tree node 435d4ae66f1SMaxime Ripard * 436d4ae66f1SMaxime Ripard * Given a DT node's port and endpoint number, finds the connected node 437d4ae66f1SMaxime Ripard * and returns the associated bridge if any, or creates and returns a 438d4ae66f1SMaxime Ripard * drm panel bridge instance if a panel is connected. 439d4ae66f1SMaxime Ripard * 440d4ae66f1SMaxime Ripard * Returns a pointer to the bridge if successful, or an error pointer 441d4ae66f1SMaxime Ripard * otherwise. 442d4ae66f1SMaxime Ripard */ 443d4ae66f1SMaxime Ripard struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, 444d4ae66f1SMaxime Ripard struct device_node *np, 445d4ae66f1SMaxime Ripard u32 port, u32 endpoint) 446d4ae66f1SMaxime Ripard { 447d4ae66f1SMaxime Ripard struct drm_bridge *bridge; 448d4ae66f1SMaxime Ripard struct drm_panel *panel; 449d4ae66f1SMaxime Ripard int ret; 450d4ae66f1SMaxime Ripard 451d4ae66f1SMaxime Ripard ret = drm_of_find_panel_or_bridge(np, port, endpoint, 452d4ae66f1SMaxime Ripard &panel, &bridge); 453d4ae66f1SMaxime Ripard if (ret) 454d4ae66f1SMaxime Ripard return ERR_PTR(ret); 455d4ae66f1SMaxime Ripard 456d4ae66f1SMaxime Ripard if (panel) 457d4ae66f1SMaxime Ripard bridge = devm_drm_panel_bridge_add(dev, panel); 458d4ae66f1SMaxime Ripard 459d4ae66f1SMaxime Ripard return bridge; 460d4ae66f1SMaxime Ripard } 461d4ae66f1SMaxime Ripard EXPORT_SYMBOL(devm_drm_of_get_bridge); 462d4ae66f1SMaxime Ripard #endif 463