| 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright (C) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com> |
| 4 | * Copyright (C) 2017 Broadcom |
| 5 | */ |
| 6 | |
| 7 | #include <linux/debugfs.h> |
| 8 | #include <linux/export.h> |
| 9 | |
| 10 | #include <drm/drm_atomic_helper.h> |
| 11 | #include <drm/drm_bridge.h> |
| 12 | #include <drm/drm_connector.h> |
| 13 | #include <drm/drm_encoder.h> |
| 14 | #include <drm/drm_managed.h> |
| 15 | #include <drm/drm_modeset_helper_vtables.h> |
| 16 | #include <drm/drm_of.h> |
| 17 | #include <drm/drm_panel.h> |
| 18 | #include <drm/drm_print.h> |
| 19 | #include <drm/drm_probe_helper.h> |
| 20 | |
| 21 | struct panel_bridge { |
| 22 | struct drm_bridge bridge; |
| 23 | struct drm_connector connector; |
| 24 | struct drm_panel *panel; |
| 25 | u32 connector_type; |
| 26 | }; |
| 27 | |
| 28 | static inline struct panel_bridge * |
| 29 | drm_bridge_to_panel_bridge(struct drm_bridge *bridge) |
| 30 | { |
| 31 | return container_of(bridge, struct panel_bridge, bridge); |
| 32 | } |
| 33 | |
| 34 | static inline struct panel_bridge * |
| 35 | drm_connector_to_panel_bridge(struct drm_connector *connector) |
| 36 | { |
| 37 | return container_of(connector, struct panel_bridge, connector); |
| 38 | } |
| 39 | |
| 40 | static int panel_bridge_connector_get_modes(struct drm_connector *connector) |
| 41 | { |
| 42 | struct panel_bridge *panel_bridge = |
| 43 | drm_connector_to_panel_bridge(connector); |
| 44 | |
| 45 | return drm_panel_get_modes(panel: panel_bridge->panel, connector); |
| 46 | } |
| 47 | |
| 48 | static const struct drm_connector_helper_funcs |
| 49 | panel_bridge_connector_helper_funcs = { |
| 50 | .get_modes = panel_bridge_connector_get_modes, |
| 51 | }; |
| 52 | |
| 53 | static const struct drm_connector_funcs panel_bridge_connector_funcs = { |
| 54 | .reset = drm_atomic_helper_connector_reset, |
| 55 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 56 | .destroy = drm_connector_cleanup, |
| 57 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
| 58 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
| 59 | }; |
| 60 | |
| 61 | static int panel_bridge_attach(struct drm_bridge *bridge, |
| 62 | struct drm_encoder *encoder, |
| 63 | enum drm_bridge_attach_flags flags) |
| 64 | { |
| 65 | struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); |
| 66 | struct drm_connector *connector = &panel_bridge->connector; |
| 67 | int ret; |
| 68 | |
| 69 | if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) |
| 70 | return 0; |
| 71 | |
| 72 | drm_connector_helper_add(connector, |
| 73 | funcs: &panel_bridge_connector_helper_funcs); |
| 74 | |
| 75 | ret = drm_connector_init(dev: bridge->dev, connector, |
| 76 | funcs: &panel_bridge_connector_funcs, |
| 77 | connector_type: panel_bridge->connector_type); |
| 78 | if (ret) { |
| 79 | DRM_ERROR("Failed to initialize connector\n" ); |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | drm_panel_bridge_set_orientation(connector, bridge); |
| 84 | |
| 85 | drm_connector_attach_encoder(connector: &panel_bridge->connector, |
| 86 | encoder); |
| 87 | |
| 88 | if (bridge->dev->registered) { |
| 89 | if (connector->funcs->reset) |
| 90 | connector->funcs->reset(connector); |
| 91 | drm_connector_register(connector); |
| 92 | } |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static void panel_bridge_detach(struct drm_bridge *bridge) |
| 98 | { |
| 99 | struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); |
| 100 | struct drm_connector *connector = &panel_bridge->connector; |
| 101 | |
| 102 | /* |
| 103 | * Cleanup the connector if we know it was initialized. |
| 104 | * |
| 105 | * FIXME: This wouldn't be needed if the panel_bridge structure was |
| 106 | * allocated with drmm_kzalloc(). This might be tricky since the |
| 107 | * drm_device pointer can only be retrieved when the bridge is attached. |
| 108 | */ |
| 109 | if (connector->dev) |
| 110 | drm_connector_cleanup(connector); |
| 111 | } |
| 112 | |
| 113 | static void panel_bridge_atomic_pre_enable(struct drm_bridge *bridge, |
| 114 | struct drm_atomic_state *atomic_state) |
| 115 | { |
| 116 | struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); |
| 117 | struct drm_encoder *encoder = bridge->encoder; |
| 118 | struct drm_crtc *crtc; |
| 119 | struct drm_crtc_state *old_crtc_state; |
| 120 | |
| 121 | crtc = drm_atomic_get_new_crtc_for_encoder(state: atomic_state, encoder); |
| 122 | if (!crtc) |
| 123 | return; |
| 124 | |
| 125 | old_crtc_state = drm_atomic_get_old_crtc_state(state: atomic_state, crtc); |
| 126 | if (old_crtc_state && old_crtc_state->self_refresh_active) |
| 127 | return; |
| 128 | |
| 129 | drm_panel_prepare(panel: panel_bridge->panel); |
| 130 | } |
| 131 | |
| 132 | static void panel_bridge_atomic_enable(struct drm_bridge *bridge, |
| 133 | struct drm_atomic_state *atomic_state) |
| 134 | { |
| 135 | struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); |
| 136 | struct drm_encoder *encoder = bridge->encoder; |
| 137 | struct drm_crtc *crtc; |
| 138 | struct drm_crtc_state *old_crtc_state; |
| 139 | |
| 140 | crtc = drm_atomic_get_new_crtc_for_encoder(state: atomic_state, encoder); |
| 141 | if (!crtc) |
| 142 | return; |
| 143 | |
| 144 | old_crtc_state = drm_atomic_get_old_crtc_state(state: atomic_state, crtc); |
| 145 | if (old_crtc_state && old_crtc_state->self_refresh_active) |
| 146 | return; |
| 147 | |
| 148 | drm_panel_enable(panel: panel_bridge->panel); |
| 149 | } |
| 150 | |
| 151 | static void panel_bridge_atomic_disable(struct drm_bridge *bridge, |
| 152 | struct drm_atomic_state *atomic_state) |
| 153 | { |
| 154 | struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); |
| 155 | struct drm_encoder *encoder = bridge->encoder; |
| 156 | struct drm_crtc *crtc; |
| 157 | struct drm_crtc_state *new_crtc_state; |
| 158 | |
| 159 | crtc = drm_atomic_get_old_crtc_for_encoder(state: atomic_state, encoder); |
| 160 | if (!crtc) |
| 161 | return; |
| 162 | |
| 163 | new_crtc_state = drm_atomic_get_new_crtc_state(state: atomic_state, crtc); |
| 164 | if (new_crtc_state && new_crtc_state->self_refresh_active) |
| 165 | return; |
| 166 | |
| 167 | drm_panel_disable(panel: panel_bridge->panel); |
| 168 | } |
| 169 | |
| 170 | static void panel_bridge_atomic_post_disable(struct drm_bridge *bridge, |
| 171 | struct drm_atomic_state *atomic_state) |
| 172 | { |
| 173 | struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); |
| 174 | struct drm_encoder *encoder = bridge->encoder; |
| 175 | struct drm_crtc *crtc; |
| 176 | struct drm_crtc_state *new_crtc_state; |
| 177 | |
| 178 | crtc = drm_atomic_get_old_crtc_for_encoder(state: atomic_state, encoder); |
| 179 | if (!crtc) |
| 180 | return; |
| 181 | |
| 182 | new_crtc_state = drm_atomic_get_new_crtc_state(state: atomic_state, crtc); |
| 183 | if (new_crtc_state && new_crtc_state->self_refresh_active) |
| 184 | return; |
| 185 | |
| 186 | drm_panel_unprepare(panel: panel_bridge->panel); |
| 187 | } |
| 188 | |
| 189 | static int panel_bridge_get_modes(struct drm_bridge *bridge, |
| 190 | struct drm_connector *connector) |
| 191 | { |
| 192 | struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); |
| 193 | |
| 194 | return drm_panel_get_modes(panel: panel_bridge->panel, connector); |
| 195 | } |
| 196 | |
| 197 | static void panel_bridge_debugfs_init(struct drm_bridge *bridge, |
| 198 | struct dentry *root) |
| 199 | { |
| 200 | struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge); |
| 201 | struct drm_panel *panel = panel_bridge->panel; |
| 202 | |
| 203 | root = debugfs_create_dir(name: "panel" , parent: root); |
| 204 | if (panel->funcs->debugfs_init) |
| 205 | panel->funcs->debugfs_init(panel, root); |
| 206 | } |
| 207 | |
| 208 | static const struct drm_bridge_funcs panel_bridge_bridge_funcs = { |
| 209 | .attach = panel_bridge_attach, |
| 210 | .detach = panel_bridge_detach, |
| 211 | .atomic_pre_enable = panel_bridge_atomic_pre_enable, |
| 212 | .atomic_enable = panel_bridge_atomic_enable, |
| 213 | .atomic_disable = panel_bridge_atomic_disable, |
| 214 | .atomic_post_disable = panel_bridge_atomic_post_disable, |
| 215 | .get_modes = panel_bridge_get_modes, |
| 216 | .atomic_reset = drm_atomic_helper_bridge_reset, |
| 217 | .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, |
| 218 | .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, |
| 219 | .atomic_get_input_bus_fmts = drm_atomic_helper_bridge_propagate_bus_fmt, |
| 220 | .debugfs_init = panel_bridge_debugfs_init, |
| 221 | }; |
| 222 | |
| 223 | /** |
| 224 | * drm_bridge_is_panel - Checks if a drm_bridge is a panel_bridge. |
| 225 | * |
| 226 | * @bridge: The drm_bridge to be checked. |
| 227 | * |
| 228 | * Returns true if the bridge is a panel bridge, or false otherwise. |
| 229 | */ |
| 230 | bool drm_bridge_is_panel(const struct drm_bridge *bridge) |
| 231 | { |
| 232 | return bridge->funcs == &panel_bridge_bridge_funcs; |
| 233 | } |
| 234 | EXPORT_SYMBOL(drm_bridge_is_panel); |
| 235 | |
| 236 | /** |
| 237 | * drm_panel_bridge_add - Creates a &drm_bridge and &drm_connector that |
| 238 | * just calls the appropriate functions from &drm_panel. |
| 239 | * |
| 240 | * @panel: The drm_panel being wrapped. Must be non-NULL. |
| 241 | * |
| 242 | * For drivers converting from directly using drm_panel: The expected |
| 243 | * usage pattern is that during either encoder module probe or DSI |
| 244 | * host attach, a drm_panel will be looked up through |
| 245 | * drm_of_find_panel_or_bridge(). drm_panel_bridge_add() is used to |
| 246 | * wrap that panel in the new bridge, and the result can then be |
| 247 | * passed to drm_bridge_attach(). The drm_panel_prepare() and related |
| 248 | * functions can be dropped from the encoder driver (they're now |
| 249 | * called by the KMS helpers before calling into the encoder), along |
| 250 | * with connector creation. When done with the bridge (after |
| 251 | * drm_mode_config_cleanup() if the bridge has already been attached), then |
| 252 | * drm_panel_bridge_remove() to free it. |
| 253 | * |
| 254 | * The connector type is set to @panel->connector_type, which must be set to a |
| 255 | * known type. Calling this function with a panel whose connector type is |
| 256 | * DRM_MODE_CONNECTOR_Unknown will return ERR_PTR(-EINVAL). |
| 257 | * |
| 258 | * See devm_drm_panel_bridge_add() for an automatically managed version of this |
| 259 | * function. |
| 260 | */ |
| 261 | struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel) |
| 262 | { |
| 263 | if (WARN_ON(panel->connector_type == DRM_MODE_CONNECTOR_Unknown)) |
| 264 | return ERR_PTR(error: -EINVAL); |
| 265 | |
| 266 | return drm_panel_bridge_add_typed(panel, connector_type: panel->connector_type); |
| 267 | } |
| 268 | EXPORT_SYMBOL(drm_panel_bridge_add); |
| 269 | |
| 270 | /** |
| 271 | * drm_panel_bridge_add_typed - Creates a &drm_bridge and &drm_connector with |
| 272 | * an explicit connector type. |
| 273 | * @panel: The drm_panel being wrapped. Must be non-NULL. |
| 274 | * @connector_type: The connector type (DRM_MODE_CONNECTOR_*) |
| 275 | * |
| 276 | * This is just like drm_panel_bridge_add(), but forces the connector type to |
| 277 | * @connector_type instead of infering it from the panel. |
| 278 | * |
| 279 | * This function is deprecated and should not be used in new drivers. Use |
| 280 | * drm_panel_bridge_add() instead, and fix panel drivers as necessary if they |
| 281 | * don't report a connector type. |
| 282 | */ |
| 283 | struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel, |
| 284 | u32 connector_type) |
| 285 | { |
| 286 | struct panel_bridge *panel_bridge; |
| 287 | |
| 288 | if (!panel) |
| 289 | return ERR_PTR(error: -EINVAL); |
| 290 | |
| 291 | panel_bridge = devm_drm_bridge_alloc(panel->dev, struct panel_bridge, bridge, |
| 292 | &panel_bridge_bridge_funcs); |
| 293 | if (IS_ERR(ptr: panel_bridge)) |
| 294 | return (void *)panel_bridge; |
| 295 | |
| 296 | panel_bridge->connector_type = connector_type; |
| 297 | panel_bridge->panel = panel; |
| 298 | |
| 299 | panel_bridge->bridge.of_node = panel->dev->of_node; |
| 300 | panel_bridge->bridge.ops = DRM_BRIDGE_OP_MODES; |
| 301 | panel_bridge->bridge.type = connector_type; |
| 302 | panel_bridge->bridge.pre_enable_prev_first = panel->prepare_prev_first; |
| 303 | |
| 304 | drm_bridge_add(bridge: &panel_bridge->bridge); |
| 305 | |
| 306 | return &panel_bridge->bridge; |
| 307 | } |
| 308 | EXPORT_SYMBOL(drm_panel_bridge_add_typed); |
| 309 | |
| 310 | /** |
| 311 | * drm_panel_bridge_remove - Unregisters and frees a drm_bridge |
| 312 | * created by drm_panel_bridge_add(). |
| 313 | * |
| 314 | * @bridge: The drm_bridge being freed. |
| 315 | */ |
| 316 | void drm_panel_bridge_remove(struct drm_bridge *bridge) |
| 317 | { |
| 318 | struct panel_bridge *panel_bridge; |
| 319 | |
| 320 | if (!bridge) |
| 321 | return; |
| 322 | |
| 323 | if (!drm_bridge_is_panel(bridge)) { |
| 324 | drm_warn(bridge->dev, "%s: called on non-panel bridge!\n" , __func__); |
| 325 | return; |
| 326 | } |
| 327 | |
| 328 | panel_bridge = drm_bridge_to_panel_bridge(bridge); |
| 329 | |
| 330 | drm_bridge_remove(bridge); |
| 331 | /* TODO remove this after reworking panel_bridge lifetime */ |
| 332 | devm_drm_put_bridge(dev: panel_bridge->panel->dev, bridge); |
| 333 | } |
| 334 | EXPORT_SYMBOL(drm_panel_bridge_remove); |
| 335 | |
| 336 | /** |
| 337 | * drm_panel_bridge_set_orientation - Set the connector's panel orientation |
| 338 | * from the bridge that can be transformed to panel bridge. |
| 339 | * |
| 340 | * @connector: The connector to be set panel orientation. |
| 341 | * @bridge: The drm_bridge to be transformed to panel bridge. |
| 342 | * |
| 343 | * Returns 0 on success, negative errno on failure. |
| 344 | */ |
| 345 | int drm_panel_bridge_set_orientation(struct drm_connector *connector, |
| 346 | struct drm_bridge *bridge) |
| 347 | { |
| 348 | struct panel_bridge *panel_bridge; |
| 349 | |
| 350 | panel_bridge = drm_bridge_to_panel_bridge(bridge); |
| 351 | |
| 352 | return drm_connector_set_orientation_from_panel(connector, |
| 353 | panel: panel_bridge->panel); |
| 354 | } |
| 355 | EXPORT_SYMBOL(drm_panel_bridge_set_orientation); |
| 356 | |
| 357 | static void devm_drm_panel_bridge_release(struct device *dev, void *res) |
| 358 | { |
| 359 | struct drm_bridge *bridge = *(struct drm_bridge **)res; |
| 360 | |
| 361 | if (!bridge) |
| 362 | return; |
| 363 | |
| 364 | drm_bridge_remove(bridge); |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * devm_drm_panel_bridge_add - Creates a managed &drm_bridge and &drm_connector |
| 369 | * that just calls the appropriate functions from &drm_panel. |
| 370 | * @dev: device to tie the bridge lifetime to |
| 371 | * @panel: The drm_panel being wrapped. Must be non-NULL. |
| 372 | * |
| 373 | * This is the managed version of drm_panel_bridge_add() which automatically |
| 374 | * calls drm_panel_bridge_remove() when @dev is unbound. |
| 375 | */ |
| 376 | struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev, |
| 377 | struct drm_panel *panel) |
| 378 | { |
| 379 | if (WARN_ON(panel->connector_type == DRM_MODE_CONNECTOR_Unknown)) |
| 380 | return ERR_PTR(error: -EINVAL); |
| 381 | |
| 382 | return devm_drm_panel_bridge_add_typed(dev, panel, |
| 383 | connector_type: panel->connector_type); |
| 384 | } |
| 385 | EXPORT_SYMBOL(devm_drm_panel_bridge_add); |
| 386 | |
| 387 | /** |
| 388 | * devm_drm_panel_bridge_add_typed - Creates a managed &drm_bridge and |
| 389 | * &drm_connector with an explicit connector type. |
| 390 | * @dev: device to tie the bridge lifetime to |
| 391 | * @panel: The drm_panel being wrapped. Must be non-NULL. |
| 392 | * @connector_type: The connector type (DRM_MODE_CONNECTOR_*) |
| 393 | * |
| 394 | * This is just like devm_drm_panel_bridge_add(), but forces the connector type |
| 395 | * to @connector_type instead of infering it from the panel. |
| 396 | * |
| 397 | * This function is deprecated and should not be used in new drivers. Use |
| 398 | * devm_drm_panel_bridge_add() instead, and fix panel drivers as necessary if |
| 399 | * they don't report a connector type. |
| 400 | */ |
| 401 | struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev, |
| 402 | struct drm_panel *panel, |
| 403 | u32 connector_type) |
| 404 | { |
| 405 | struct drm_bridge **ptr, *bridge; |
| 406 | |
| 407 | ptr = devres_alloc(devm_drm_panel_bridge_release, sizeof(*ptr), |
| 408 | GFP_KERNEL); |
| 409 | if (!ptr) |
| 410 | return ERR_PTR(error: -ENOMEM); |
| 411 | |
| 412 | bridge = drm_panel_bridge_add_typed(panel, connector_type); |
| 413 | if (IS_ERR(ptr: bridge)) { |
| 414 | devres_free(res: ptr); |
| 415 | return bridge; |
| 416 | } |
| 417 | |
| 418 | *ptr = bridge; |
| 419 | devres_add(dev, res: ptr); |
| 420 | |
| 421 | return bridge; |
| 422 | } |
| 423 | EXPORT_SYMBOL(devm_drm_panel_bridge_add_typed); |
| 424 | |
| 425 | static void drmm_drm_panel_bridge_release(struct drm_device *drm, void *ptr) |
| 426 | { |
| 427 | struct drm_bridge *bridge = ptr; |
| 428 | |
| 429 | drm_panel_bridge_remove(bridge); |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * drmm_panel_bridge_add - Creates a DRM-managed &drm_bridge and |
| 434 | * &drm_connector that just calls the |
| 435 | * appropriate functions from &drm_panel. |
| 436 | * |
| 437 | * @drm: DRM device to tie the bridge lifetime to |
| 438 | * @panel: The drm_panel being wrapped. Must be non-NULL. |
| 439 | * |
| 440 | * This is the DRM-managed version of drm_panel_bridge_add() which |
| 441 | * automatically calls drm_panel_bridge_remove() when @dev is cleaned |
| 442 | * up. |
| 443 | */ |
| 444 | struct drm_bridge *drmm_panel_bridge_add(struct drm_device *drm, |
| 445 | struct drm_panel *panel) |
| 446 | { |
| 447 | struct drm_bridge *bridge; |
| 448 | int ret; |
| 449 | |
| 450 | bridge = drm_panel_bridge_add_typed(panel, panel->connector_type); |
| 451 | if (IS_ERR(ptr: bridge)) |
| 452 | return bridge; |
| 453 | |
| 454 | ret = drmm_add_action_or_reset(drm, drmm_drm_panel_bridge_release, |
| 455 | bridge); |
| 456 | if (ret) |
| 457 | return ERR_PTR(error: ret); |
| 458 | |
| 459 | return bridge; |
| 460 | } |
| 461 | EXPORT_SYMBOL(drmm_panel_bridge_add); |
| 462 | |
| 463 | /** |
| 464 | * drm_panel_bridge_connector - return the connector for the panel bridge |
| 465 | * @bridge: The drm_bridge. |
| 466 | * |
| 467 | * drm_panel_bridge creates the connector. |
| 468 | * This function gives external access to the connector. |
| 469 | * |
| 470 | * Returns: Pointer to drm_connector |
| 471 | */ |
| 472 | struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge) |
| 473 | { |
| 474 | struct panel_bridge *panel_bridge; |
| 475 | |
| 476 | panel_bridge = drm_bridge_to_panel_bridge(bridge); |
| 477 | |
| 478 | return &panel_bridge->connector; |
| 479 | } |
| 480 | EXPORT_SYMBOL(drm_panel_bridge_connector); |
| 481 | |
| 482 | #ifdef CONFIG_OF |
| 483 | /** |
| 484 | * devm_drm_of_get_bridge - Return next bridge in the chain |
| 485 | * @dev: device to tie the bridge lifetime to |
| 486 | * @np: device tree node containing encoder output ports |
| 487 | * @port: port in the device tree node |
| 488 | * @endpoint: endpoint in the device tree node |
| 489 | * |
| 490 | * Given a DT node's port and endpoint number, finds the connected node |
| 491 | * and returns the associated bridge if any, or creates and returns a |
| 492 | * drm panel bridge instance if a panel is connected. |
| 493 | * |
| 494 | * Returns a pointer to the bridge if successful, or an error pointer |
| 495 | * otherwise. |
| 496 | */ |
| 497 | struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, |
| 498 | struct device_node *np, |
| 499 | u32 port, u32 endpoint) |
| 500 | { |
| 501 | struct drm_bridge *bridge; |
| 502 | struct drm_panel *panel; |
| 503 | int ret; |
| 504 | |
| 505 | ret = drm_of_find_panel_or_bridge(np, port, endpoint, |
| 506 | panel: &panel, bridge: &bridge); |
| 507 | if (ret) |
| 508 | return ERR_PTR(error: ret); |
| 509 | |
| 510 | if (panel) |
| 511 | bridge = devm_drm_panel_bridge_add(dev, panel); |
| 512 | |
| 513 | return bridge; |
| 514 | } |
| 515 | EXPORT_SYMBOL(devm_drm_of_get_bridge); |
| 516 | |
| 517 | /** |
| 518 | * drmm_of_get_bridge - Return next bridge in the chain |
| 519 | * @drm: device to tie the bridge lifetime to |
| 520 | * @np: device tree node containing encoder output ports |
| 521 | * @port: port in the device tree node |
| 522 | * @endpoint: endpoint in the device tree node |
| 523 | * |
| 524 | * Given a DT node's port and endpoint number, finds the connected node |
| 525 | * and returns the associated bridge if any, or creates and returns a |
| 526 | * drm panel bridge instance if a panel is connected. |
| 527 | * |
| 528 | * Returns a drmm managed pointer to the bridge if successful, or an error |
| 529 | * pointer otherwise. |
| 530 | */ |
| 531 | struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm, |
| 532 | struct device_node *np, |
| 533 | u32 port, u32 endpoint) |
| 534 | { |
| 535 | struct drm_bridge *bridge; |
| 536 | struct drm_panel *panel; |
| 537 | int ret; |
| 538 | |
| 539 | ret = drm_of_find_panel_or_bridge(np, port, endpoint, |
| 540 | panel: &panel, bridge: &bridge); |
| 541 | if (ret) |
| 542 | return ERR_PTR(error: ret); |
| 543 | |
| 544 | if (panel) |
| 545 | bridge = drmm_panel_bridge_add(drm, panel); |
| 546 | |
| 547 | return bridge; |
| 548 | } |
| 549 | EXPORT_SYMBOL(drmm_of_get_bridge); |
| 550 | |
| 551 | #endif |
| 552 | |