| .. | .. |
|---|
| 23 | 23 | #ifndef __DRM_BRIDGE_H__ |
|---|
| 24 | 24 | #define __DRM_BRIDGE_H__ |
|---|
| 25 | 25 | |
|---|
| 26 | | -#include <linux/list.h> |
|---|
| 27 | 26 | #include <linux/ctype.h> |
|---|
| 27 | +#include <linux/list.h> |
|---|
| 28 | +#include <linux/mutex.h> |
|---|
| 29 | + |
|---|
| 30 | +#include <drm/drm_atomic.h> |
|---|
| 31 | +#include <drm/drm_encoder.h> |
|---|
| 28 | 32 | #include <drm/drm_mode_object.h> |
|---|
| 29 | 33 | #include <drm/drm_modes.h> |
|---|
| 30 | 34 | |
|---|
| 31 | 35 | struct drm_bridge; |
|---|
| 32 | 36 | struct drm_bridge_timings; |
|---|
| 37 | +struct drm_connector; |
|---|
| 38 | +struct drm_display_info; |
|---|
| 33 | 39 | struct drm_panel; |
|---|
| 40 | +struct edid; |
|---|
| 41 | +struct i2c_adapter; |
|---|
| 42 | + |
|---|
| 43 | +/** |
|---|
| 44 | + * enum drm_bridge_attach_flags - Flags for &drm_bridge_funcs.attach |
|---|
| 45 | + */ |
|---|
| 46 | +enum drm_bridge_attach_flags { |
|---|
| 47 | + /** |
|---|
| 48 | + * @DRM_BRIDGE_ATTACH_NO_CONNECTOR: When this flag is set the bridge |
|---|
| 49 | + * shall not create a drm_connector. |
|---|
| 50 | + */ |
|---|
| 51 | + DRM_BRIDGE_ATTACH_NO_CONNECTOR = BIT(0), |
|---|
| 52 | +}; |
|---|
| 34 | 53 | |
|---|
| 35 | 54 | /** |
|---|
| 36 | 55 | * struct drm_bridge_funcs - drm_bridge control functions |
|---|
| .. | .. |
|---|
| 40 | 59 | * @attach: |
|---|
| 41 | 60 | * |
|---|
| 42 | 61 | * This callback is invoked whenever our bridge is being attached to a |
|---|
| 43 | | - * &drm_encoder. |
|---|
| 62 | + * &drm_encoder. The flags argument tunes the behaviour of the attach |
|---|
| 63 | + * operation (see DRM_BRIDGE_ATTACH_*). |
|---|
| 44 | 64 | * |
|---|
| 45 | | - * The attach callback is optional. |
|---|
| 65 | + * The @attach callback is optional. |
|---|
| 46 | 66 | * |
|---|
| 47 | 67 | * RETURNS: |
|---|
| 48 | 68 | * |
|---|
| 49 | 69 | * Zero on success, error code on failure. |
|---|
| 50 | 70 | */ |
|---|
| 51 | | - int (*attach)(struct drm_bridge *bridge); |
|---|
| 71 | + int (*attach)(struct drm_bridge *bridge, |
|---|
| 72 | + enum drm_bridge_attach_flags flags); |
|---|
| 52 | 73 | |
|---|
| 53 | 74 | /** |
|---|
| 54 | 75 | * @detach: |
|---|
| .. | .. |
|---|
| 56 | 77 | * This callback is invoked whenever our bridge is being detached from a |
|---|
| 57 | 78 | * &drm_encoder. |
|---|
| 58 | 79 | * |
|---|
| 59 | | - * The detach callback is optional. |
|---|
| 80 | + * The @detach callback is optional. |
|---|
| 60 | 81 | */ |
|---|
| 61 | 82 | void (*detach)(struct drm_bridge *bridge); |
|---|
| 62 | 83 | |
|---|
| .. | .. |
|---|
| 76 | 97 | * atomic helpers to validate modes supplied by userspace in |
|---|
| 77 | 98 | * drm_atomic_helper_check_modeset(). |
|---|
| 78 | 99 | * |
|---|
| 79 | | - * This function is optional. |
|---|
| 100 | + * The @mode_valid callback is optional. |
|---|
| 80 | 101 | * |
|---|
| 81 | 102 | * NOTE: |
|---|
| 82 | 103 | * |
|---|
| .. | .. |
|---|
| 92 | 113 | * drm_mode_status Enum |
|---|
| 93 | 114 | */ |
|---|
| 94 | 115 | enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge, |
|---|
| 116 | + const struct drm_display_info *info, |
|---|
| 95 | 117 | const struct drm_display_mode *mode); |
|---|
| 96 | 118 | |
|---|
| 97 | 119 | /** |
|---|
| .. | .. |
|---|
| 108 | 130 | * this function passes all other callbacks must succeed for this |
|---|
| 109 | 131 | * configuration. |
|---|
| 110 | 132 | * |
|---|
| 111 | | - * The mode_fixup callback is optional. |
|---|
| 133 | + * The mode_fixup callback is optional. &drm_bridge_funcs.mode_fixup() |
|---|
| 134 | + * is not called when &drm_bridge_funcs.atomic_check() is implemented, |
|---|
| 135 | + * so only one of them should be provided. |
|---|
| 112 | 136 | * |
|---|
| 113 | 137 | * NOTE: |
|---|
| 114 | 138 | * |
|---|
| .. | .. |
|---|
| 146 | 170 | * The bridge can assume that the display pipe (i.e. clocks and timing |
|---|
| 147 | 171 | * signals) feeding it is still running when this callback is called. |
|---|
| 148 | 172 | * |
|---|
| 149 | | - * The disable callback is optional. |
|---|
| 173 | + * The @disable callback is optional. |
|---|
| 150 | 174 | */ |
|---|
| 151 | 175 | void (*disable)(struct drm_bridge *bridge); |
|---|
| 152 | 176 | |
|---|
| .. | .. |
|---|
| 165 | 189 | * singals) feeding it is no longer running when this callback is |
|---|
| 166 | 190 | * called. |
|---|
| 167 | 191 | * |
|---|
| 168 | | - * The post_disable callback is optional. |
|---|
| 192 | + * The @post_disable callback is optional. |
|---|
| 169 | 193 | */ |
|---|
| 170 | 194 | void (*post_disable)(struct drm_bridge *bridge); |
|---|
| 171 | 195 | |
|---|
| .. | .. |
|---|
| 196 | 220 | * the DRM framework will have to be extended with DRM bridge states. |
|---|
| 197 | 221 | */ |
|---|
| 198 | 222 | void (*mode_set)(struct drm_bridge *bridge, |
|---|
| 199 | | - struct drm_display_mode *mode, |
|---|
| 200 | | - struct drm_display_mode *adjusted_mode); |
|---|
| 223 | + const struct drm_display_mode *mode, |
|---|
| 224 | + const struct drm_display_mode *adjusted_mode); |
|---|
| 201 | 225 | /** |
|---|
| 202 | 226 | * @pre_enable: |
|---|
| 203 | 227 | * |
|---|
| .. | .. |
|---|
| 214 | 238 | * not enable the display link feeding the next bridge in the chain (if |
|---|
| 215 | 239 | * there is one) when this callback is called. |
|---|
| 216 | 240 | * |
|---|
| 217 | | - * The pre_enable callback is optional. |
|---|
| 241 | + * The @pre_enable callback is optional. |
|---|
| 218 | 242 | */ |
|---|
| 219 | 243 | void (*pre_enable)(struct drm_bridge *bridge); |
|---|
| 220 | 244 | |
|---|
| .. | .. |
|---|
| 234 | 258 | * callback must enable the display link feeding the next bridge in the |
|---|
| 235 | 259 | * chain if there is one. |
|---|
| 236 | 260 | * |
|---|
| 237 | | - * The enable callback is optional. |
|---|
| 261 | + * The @enable callback is optional. |
|---|
| 238 | 262 | */ |
|---|
| 239 | 263 | void (*enable)(struct drm_bridge *bridge); |
|---|
| 264 | + |
|---|
| 265 | + /** |
|---|
| 266 | + * @atomic_pre_enable: |
|---|
| 267 | + * |
|---|
| 268 | + * This callback should enable the bridge. It is called right before |
|---|
| 269 | + * the preceding element in the display pipe is enabled. If the |
|---|
| 270 | + * preceding element is a bridge this means it's called before that |
|---|
| 271 | + * bridge's @atomic_pre_enable or @pre_enable function. If the preceding |
|---|
| 272 | + * element is a &drm_encoder it's called right before the encoder's |
|---|
| 273 | + * &drm_encoder_helper_funcs.atomic_enable hook. |
|---|
| 274 | + * |
|---|
| 275 | + * The display pipe (i.e. clocks and timing signals) feeding this bridge |
|---|
| 276 | + * will not yet be running when this callback is called. The bridge must |
|---|
| 277 | + * not enable the display link feeding the next bridge in the chain (if |
|---|
| 278 | + * there is one) when this callback is called. |
|---|
| 279 | + * |
|---|
| 280 | + * Note that this function will only be invoked in the context of an |
|---|
| 281 | + * atomic commit. It will not be invoked from |
|---|
| 282 | + * &drm_bridge_chain_pre_enable. It would be prudent to also provide an |
|---|
| 283 | + * implementation of @pre_enable if you are expecting driver calls into |
|---|
| 284 | + * &drm_bridge_chain_pre_enable. |
|---|
| 285 | + * |
|---|
| 286 | + * The @atomic_pre_enable callback is optional. |
|---|
| 287 | + */ |
|---|
| 288 | + void (*atomic_pre_enable)(struct drm_bridge *bridge, |
|---|
| 289 | + struct drm_bridge_state *old_bridge_state); |
|---|
| 290 | + |
|---|
| 291 | + /** |
|---|
| 292 | + * @atomic_enable: |
|---|
| 293 | + * |
|---|
| 294 | + * This callback should enable the bridge. It is called right after |
|---|
| 295 | + * the preceding element in the display pipe is enabled. If the |
|---|
| 296 | + * preceding element is a bridge this means it's called after that |
|---|
| 297 | + * bridge's @atomic_enable or @enable function. If the preceding element |
|---|
| 298 | + * is a &drm_encoder it's called right after the encoder's |
|---|
| 299 | + * &drm_encoder_helper_funcs.atomic_enable hook. |
|---|
| 300 | + * |
|---|
| 301 | + * The bridge can assume that the display pipe (i.e. clocks and timing |
|---|
| 302 | + * signals) feeding it is running when this callback is called. This |
|---|
| 303 | + * callback must enable the display link feeding the next bridge in the |
|---|
| 304 | + * chain if there is one. |
|---|
| 305 | + * |
|---|
| 306 | + * Note that this function will only be invoked in the context of an |
|---|
| 307 | + * atomic commit. It will not be invoked from &drm_bridge_chain_enable. |
|---|
| 308 | + * It would be prudent to also provide an implementation of @enable if |
|---|
| 309 | + * you are expecting driver calls into &drm_bridge_chain_enable. |
|---|
| 310 | + * |
|---|
| 311 | + * The @atomic_enable callback is optional. |
|---|
| 312 | + */ |
|---|
| 313 | + void (*atomic_enable)(struct drm_bridge *bridge, |
|---|
| 314 | + struct drm_bridge_state *old_bridge_state); |
|---|
| 315 | + /** |
|---|
| 316 | + * @atomic_disable: |
|---|
| 317 | + * |
|---|
| 318 | + * This callback should disable the bridge. It is called right before |
|---|
| 319 | + * the preceding element in the display pipe is disabled. If the |
|---|
| 320 | + * preceding element is a bridge this means it's called before that |
|---|
| 321 | + * bridge's @atomic_disable or @disable vfunc. If the preceding element |
|---|
| 322 | + * is a &drm_encoder it's called right before the |
|---|
| 323 | + * &drm_encoder_helper_funcs.atomic_disable hook. |
|---|
| 324 | + * |
|---|
| 325 | + * The bridge can assume that the display pipe (i.e. clocks and timing |
|---|
| 326 | + * signals) feeding it is still running when this callback is called. |
|---|
| 327 | + * |
|---|
| 328 | + * Note that this function will only be invoked in the context of an |
|---|
| 329 | + * atomic commit. It will not be invoked from |
|---|
| 330 | + * &drm_bridge_chain_disable. It would be prudent to also provide an |
|---|
| 331 | + * implementation of @disable if you are expecting driver calls into |
|---|
| 332 | + * &drm_bridge_chain_disable. |
|---|
| 333 | + * |
|---|
| 334 | + * The @atomic_disable callback is optional. |
|---|
| 335 | + */ |
|---|
| 336 | + void (*atomic_disable)(struct drm_bridge *bridge, |
|---|
| 337 | + struct drm_bridge_state *old_bridge_state); |
|---|
| 338 | + |
|---|
| 339 | + /** |
|---|
| 340 | + * @atomic_post_disable: |
|---|
| 341 | + * |
|---|
| 342 | + * This callback should disable the bridge. It is called right after the |
|---|
| 343 | + * preceding element in the display pipe is disabled. If the preceding |
|---|
| 344 | + * element is a bridge this means it's called after that bridge's |
|---|
| 345 | + * @atomic_post_disable or @post_disable function. If the preceding |
|---|
| 346 | + * element is a &drm_encoder it's called right after the encoder's |
|---|
| 347 | + * &drm_encoder_helper_funcs.atomic_disable hook. |
|---|
| 348 | + * |
|---|
| 349 | + * The bridge must assume that the display pipe (i.e. clocks and timing |
|---|
| 350 | + * signals) feeding it is no longer running when this callback is |
|---|
| 351 | + * called. |
|---|
| 352 | + * |
|---|
| 353 | + * Note that this function will only be invoked in the context of an |
|---|
| 354 | + * atomic commit. It will not be invoked from |
|---|
| 355 | + * &drm_bridge_chain_post_disable. |
|---|
| 356 | + * It would be prudent to also provide an implementation of |
|---|
| 357 | + * @post_disable if you are expecting driver calls into |
|---|
| 358 | + * &drm_bridge_chain_post_disable. |
|---|
| 359 | + * |
|---|
| 360 | + * The @atomic_post_disable callback is optional. |
|---|
| 361 | + */ |
|---|
| 362 | + void (*atomic_post_disable)(struct drm_bridge *bridge, |
|---|
| 363 | + struct drm_bridge_state *old_bridge_state); |
|---|
| 364 | + |
|---|
| 365 | + /** |
|---|
| 366 | + * @atomic_duplicate_state: |
|---|
| 367 | + * |
|---|
| 368 | + * Duplicate the current bridge state object (which is guaranteed to be |
|---|
| 369 | + * non-NULL). |
|---|
| 370 | + * |
|---|
| 371 | + * The atomic_duplicate_state hook is mandatory if the bridge |
|---|
| 372 | + * implements any of the atomic hooks, and should be left unassigned |
|---|
| 373 | + * otherwise. For bridges that don't subclass &drm_bridge_state, the |
|---|
| 374 | + * drm_atomic_helper_bridge_duplicate_state() helper function shall be |
|---|
| 375 | + * used to implement this hook. |
|---|
| 376 | + * |
|---|
| 377 | + * RETURNS: |
|---|
| 378 | + * A valid drm_bridge_state object or NULL if the allocation fails. |
|---|
| 379 | + */ |
|---|
| 380 | + struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge); |
|---|
| 381 | + |
|---|
| 382 | + /** |
|---|
| 383 | + * @atomic_destroy_state: |
|---|
| 384 | + * |
|---|
| 385 | + * Destroy a bridge state object previously allocated by |
|---|
| 386 | + * &drm_bridge_funcs.atomic_duplicate_state(). |
|---|
| 387 | + * |
|---|
| 388 | + * The atomic_destroy_state hook is mandatory if the bridge implements |
|---|
| 389 | + * any of the atomic hooks, and should be left unassigned otherwise. |
|---|
| 390 | + * For bridges that don't subclass &drm_bridge_state, the |
|---|
| 391 | + * drm_atomic_helper_bridge_destroy_state() helper function shall be |
|---|
| 392 | + * used to implement this hook. |
|---|
| 393 | + */ |
|---|
| 394 | + void (*atomic_destroy_state)(struct drm_bridge *bridge, |
|---|
| 395 | + struct drm_bridge_state *state); |
|---|
| 396 | + |
|---|
| 397 | + /** |
|---|
| 398 | + * @atomic_get_output_bus_fmts: |
|---|
| 399 | + * |
|---|
| 400 | + * Return the supported bus formats on the output end of a bridge. |
|---|
| 401 | + * The returned array must be allocated with kmalloc() and will be |
|---|
| 402 | + * freed by the caller. If the allocation fails, NULL should be |
|---|
| 403 | + * returned. num_output_fmts must be set to the returned array size. |
|---|
| 404 | + * Formats listed in the returned array should be listed in decreasing |
|---|
| 405 | + * preference order (the core will try all formats until it finds one |
|---|
| 406 | + * that works). |
|---|
| 407 | + * |
|---|
| 408 | + * This method is only called on the last element of the bridge chain |
|---|
| 409 | + * as part of the bus format negotiation process that happens in |
|---|
| 410 | + * &drm_atomic_bridge_chain_select_bus_fmts(). |
|---|
| 411 | + * This method is optional. When not implemented, the core will |
|---|
| 412 | + * fall back to &drm_connector.display_info.bus_formats[0] if |
|---|
| 413 | + * &drm_connector.display_info.num_bus_formats > 0, |
|---|
| 414 | + * or to MEDIA_BUS_FMT_FIXED otherwise. |
|---|
| 415 | + */ |
|---|
| 416 | + u32 *(*atomic_get_output_bus_fmts)(struct drm_bridge *bridge, |
|---|
| 417 | + struct drm_bridge_state *bridge_state, |
|---|
| 418 | + struct drm_crtc_state *crtc_state, |
|---|
| 419 | + struct drm_connector_state *conn_state, |
|---|
| 420 | + unsigned int *num_output_fmts); |
|---|
| 421 | + |
|---|
| 422 | + /** |
|---|
| 423 | + * @atomic_get_input_bus_fmts: |
|---|
| 424 | + * |
|---|
| 425 | + * Return the supported bus formats on the input end of a bridge for |
|---|
| 426 | + * a specific output bus format. |
|---|
| 427 | + * |
|---|
| 428 | + * The returned array must be allocated with kmalloc() and will be |
|---|
| 429 | + * freed by the caller. If the allocation fails, NULL should be |
|---|
| 430 | + * returned. num_input_fmts must be set to the returned array size. |
|---|
| 431 | + * Formats listed in the returned array should be listed in decreasing |
|---|
| 432 | + * preference order (the core will try all formats until it finds one |
|---|
| 433 | + * that works). When the format is not supported NULL should be |
|---|
| 434 | + * returned and num_input_fmts should be set to 0. |
|---|
| 435 | + * |
|---|
| 436 | + * This method is called on all elements of the bridge chain as part of |
|---|
| 437 | + * the bus format negotiation process that happens in |
|---|
| 438 | + * drm_atomic_bridge_chain_select_bus_fmts(). |
|---|
| 439 | + * This method is optional. When not implemented, the core will bypass |
|---|
| 440 | + * bus format negotiation on this element of the bridge without |
|---|
| 441 | + * failing, and the previous element in the chain will be passed |
|---|
| 442 | + * MEDIA_BUS_FMT_FIXED as its output bus format. |
|---|
| 443 | + * |
|---|
| 444 | + * Bridge drivers that need to support being linked to bridges that are |
|---|
| 445 | + * not supporting bus format negotiation should handle the |
|---|
| 446 | + * output_fmt == MEDIA_BUS_FMT_FIXED case appropriately, by selecting a |
|---|
| 447 | + * sensible default value or extracting this information from somewhere |
|---|
| 448 | + * else (FW property, &drm_display_mode, &drm_display_info, ...) |
|---|
| 449 | + * |
|---|
| 450 | + * Note: Even if input format selection on the first bridge has no |
|---|
| 451 | + * impact on the negotiation process (bus format negotiation stops once |
|---|
| 452 | + * we reach the first element of the chain), drivers are expected to |
|---|
| 453 | + * return accurate input formats as the input format may be used to |
|---|
| 454 | + * configure the CRTC output appropriately. |
|---|
| 455 | + */ |
|---|
| 456 | + u32 *(*atomic_get_input_bus_fmts)(struct drm_bridge *bridge, |
|---|
| 457 | + struct drm_bridge_state *bridge_state, |
|---|
| 458 | + struct drm_crtc_state *crtc_state, |
|---|
| 459 | + struct drm_connector_state *conn_state, |
|---|
| 460 | + u32 output_fmt, |
|---|
| 461 | + unsigned int *num_input_fmts); |
|---|
| 462 | + |
|---|
| 463 | + /** |
|---|
| 464 | + * @atomic_check: |
|---|
| 465 | + * |
|---|
| 466 | + * This method is responsible for checking bridge state correctness. |
|---|
| 467 | + * It can also check the state of the surrounding components in chain |
|---|
| 468 | + * to make sure the whole pipeline can work properly. |
|---|
| 469 | + * |
|---|
| 470 | + * &drm_bridge_funcs.atomic_check() hooks are called in reverse |
|---|
| 471 | + * order (from the last to the first bridge). |
|---|
| 472 | + * |
|---|
| 473 | + * This method is optional. &drm_bridge_funcs.mode_fixup() is not |
|---|
| 474 | + * called when &drm_bridge_funcs.atomic_check() is implemented, so only |
|---|
| 475 | + * one of them should be provided. |
|---|
| 476 | + * |
|---|
| 477 | + * If drivers need to tweak &drm_bridge_state.input_bus_cfg.flags or |
|---|
| 478 | + * &drm_bridge_state.output_bus_cfg.flags it should happen in |
|---|
| 479 | + * this function. By default the &drm_bridge_state.output_bus_cfg.flags |
|---|
| 480 | + * field is set to the next bridge |
|---|
| 481 | + * &drm_bridge_state.input_bus_cfg.flags value or |
|---|
| 482 | + * &drm_connector.display_info.bus_flags if the bridge is the last |
|---|
| 483 | + * element in the chain. |
|---|
| 484 | + * |
|---|
| 485 | + * RETURNS: |
|---|
| 486 | + * zero if the check passed, a negative error code otherwise. |
|---|
| 487 | + */ |
|---|
| 488 | + int (*atomic_check)(struct drm_bridge *bridge, |
|---|
| 489 | + struct drm_bridge_state *bridge_state, |
|---|
| 490 | + struct drm_crtc_state *crtc_state, |
|---|
| 491 | + struct drm_connector_state *conn_state); |
|---|
| 492 | + |
|---|
| 493 | + /** |
|---|
| 494 | + * @atomic_reset: |
|---|
| 495 | + * |
|---|
| 496 | + * Reset the bridge to a predefined state (or retrieve its current |
|---|
| 497 | + * state) and return a &drm_bridge_state object matching this state. |
|---|
| 498 | + * This function is called at attach time. |
|---|
| 499 | + * |
|---|
| 500 | + * The atomic_reset hook is mandatory if the bridge implements any of |
|---|
| 501 | + * the atomic hooks, and should be left unassigned otherwise. For |
|---|
| 502 | + * bridges that don't subclass &drm_bridge_state, the |
|---|
| 503 | + * drm_atomic_helper_bridge_reset() helper function shall be used to |
|---|
| 504 | + * implement this hook. |
|---|
| 505 | + * |
|---|
| 506 | + * Note that the atomic_reset() semantics is not exactly matching the |
|---|
| 507 | + * reset() semantics found on other components (connector, plane, ...). |
|---|
| 508 | + * |
|---|
| 509 | + * 1. The reset operation happens when the bridge is attached, not when |
|---|
| 510 | + * drm_mode_config_reset() is called |
|---|
| 511 | + * 2. It's meant to be used exclusively on bridges that have been |
|---|
| 512 | + * converted to the ATOMIC API |
|---|
| 513 | + * |
|---|
| 514 | + * RETURNS: |
|---|
| 515 | + * A valid drm_bridge_state object in case of success, an ERR_PTR() |
|---|
| 516 | + * giving the reason of the failure otherwise. |
|---|
| 517 | + */ |
|---|
| 518 | + struct drm_bridge_state *(*atomic_reset)(struct drm_bridge *bridge); |
|---|
| 519 | + |
|---|
| 520 | + /** |
|---|
| 521 | + * @detect: |
|---|
| 522 | + * |
|---|
| 523 | + * Check if anything is attached to the bridge output. |
|---|
| 524 | + * |
|---|
| 525 | + * This callback is optional, if not implemented the bridge will be |
|---|
| 526 | + * considered as always having a component attached to its output. |
|---|
| 527 | + * Bridges that implement this callback shall set the |
|---|
| 528 | + * DRM_BRIDGE_OP_DETECT flag in their &drm_bridge->ops. |
|---|
| 529 | + * |
|---|
| 530 | + * RETURNS: |
|---|
| 531 | + * |
|---|
| 532 | + * drm_connector_status indicating the bridge output status. |
|---|
| 533 | + */ |
|---|
| 534 | + enum drm_connector_status (*detect)(struct drm_bridge *bridge); |
|---|
| 535 | + |
|---|
| 536 | + /** |
|---|
| 537 | + * @get_modes: |
|---|
| 538 | + * |
|---|
| 539 | + * Fill all modes currently valid for the sink into the &drm_connector |
|---|
| 540 | + * with drm_mode_probed_add(). |
|---|
| 541 | + * |
|---|
| 542 | + * The @get_modes callback is mostly intended to support non-probeable |
|---|
| 543 | + * displays such as many fixed panels. Bridges that support reading |
|---|
| 544 | + * EDID shall leave @get_modes unimplemented and implement the |
|---|
| 545 | + * &drm_bridge_funcs->get_edid callback instead. |
|---|
| 546 | + * |
|---|
| 547 | + * This callback is optional. Bridges that implement it shall set the |
|---|
| 548 | + * DRM_BRIDGE_OP_MODES flag in their &drm_bridge->ops. |
|---|
| 549 | + * |
|---|
| 550 | + * The connector parameter shall be used for the sole purpose of |
|---|
| 551 | + * filling modes, and shall not be stored internally by bridge drivers |
|---|
| 552 | + * for future usage. |
|---|
| 553 | + * |
|---|
| 554 | + * RETURNS: |
|---|
| 555 | + * |
|---|
| 556 | + * The number of modes added by calling drm_mode_probed_add(). |
|---|
| 557 | + */ |
|---|
| 558 | + int (*get_modes)(struct drm_bridge *bridge, |
|---|
| 559 | + struct drm_connector *connector); |
|---|
| 560 | + |
|---|
| 561 | + /** |
|---|
| 562 | + * @get_edid: |
|---|
| 563 | + * |
|---|
| 564 | + * Read and parse the EDID data of the connected display. |
|---|
| 565 | + * |
|---|
| 566 | + * The @get_edid callback is the preferred way of reporting mode |
|---|
| 567 | + * information for a display connected to the bridge output. Bridges |
|---|
| 568 | + * that support reading EDID shall implement this callback and leave |
|---|
| 569 | + * the @get_modes callback unimplemented. |
|---|
| 570 | + * |
|---|
| 571 | + * The caller of this operation shall first verify the output |
|---|
| 572 | + * connection status and refrain from reading EDID from a disconnected |
|---|
| 573 | + * output. |
|---|
| 574 | + * |
|---|
| 575 | + * This callback is optional. Bridges that implement it shall set the |
|---|
| 576 | + * DRM_BRIDGE_OP_EDID flag in their &drm_bridge->ops. |
|---|
| 577 | + * |
|---|
| 578 | + * The connector parameter shall be used for the sole purpose of EDID |
|---|
| 579 | + * retrieval and parsing, and shall not be stored internally by bridge |
|---|
| 580 | + * drivers for future usage. |
|---|
| 581 | + * |
|---|
| 582 | + * RETURNS: |
|---|
| 583 | + * |
|---|
| 584 | + * An edid structure newly allocated with kmalloc() (or similar) on |
|---|
| 585 | + * success, or NULL otherwise. The caller is responsible for freeing |
|---|
| 586 | + * the returned edid structure with kfree(). |
|---|
| 587 | + */ |
|---|
| 588 | + struct edid *(*get_edid)(struct drm_bridge *bridge, |
|---|
| 589 | + struct drm_connector *connector); |
|---|
| 590 | + |
|---|
| 591 | + /** |
|---|
| 592 | + * @hpd_notify: |
|---|
| 593 | + * |
|---|
| 594 | + * Notify the bridge of hot plug detection. |
|---|
| 595 | + * |
|---|
| 596 | + * This callback is optional, it may be implemented by bridges that |
|---|
| 597 | + * need to be notified of display connection or disconnection for |
|---|
| 598 | + * internal reasons. One use case is to reset the internal state of CEC |
|---|
| 599 | + * controllers for HDMI bridges. |
|---|
| 600 | + */ |
|---|
| 601 | + void (*hpd_notify)(struct drm_bridge *bridge, |
|---|
| 602 | + enum drm_connector_status status); |
|---|
| 603 | + |
|---|
| 604 | + /** |
|---|
| 605 | + * @hpd_enable: |
|---|
| 606 | + * |
|---|
| 607 | + * Enable hot plug detection. From now on the bridge shall call |
|---|
| 608 | + * drm_bridge_hpd_notify() each time a change is detected in the output |
|---|
| 609 | + * connection status, until hot plug detection gets disabled with |
|---|
| 610 | + * @hpd_disable. |
|---|
| 611 | + * |
|---|
| 612 | + * This callback is optional and shall only be implemented by bridges |
|---|
| 613 | + * that support hot-plug notification without polling. Bridges that |
|---|
| 614 | + * implement it shall also implement the @hpd_disable callback and set |
|---|
| 615 | + * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops. |
|---|
| 616 | + */ |
|---|
| 617 | + void (*hpd_enable)(struct drm_bridge *bridge); |
|---|
| 618 | + |
|---|
| 619 | + /** |
|---|
| 620 | + * @hpd_disable: |
|---|
| 621 | + * |
|---|
| 622 | + * Disable hot plug detection. Once this function returns the bridge |
|---|
| 623 | + * shall not call drm_bridge_hpd_notify() when a change in the output |
|---|
| 624 | + * connection status occurs. |
|---|
| 625 | + * |
|---|
| 626 | + * This callback is optional and shall only be implemented by bridges |
|---|
| 627 | + * that support hot-plug notification without polling. Bridges that |
|---|
| 628 | + * implement it shall also implement the @hpd_enable callback and set |
|---|
| 629 | + * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops. |
|---|
| 630 | + */ |
|---|
| 631 | + void (*hpd_disable)(struct drm_bridge *bridge); |
|---|
| 240 | 632 | }; |
|---|
| 241 | 633 | |
|---|
| 242 | 634 | /** |
|---|
| .. | .. |
|---|
| 244 | 636 | */ |
|---|
| 245 | 637 | struct drm_bridge_timings { |
|---|
| 246 | 638 | /** |
|---|
| 247 | | - * @sampling_edge: |
|---|
| 639 | + * @input_bus_flags: |
|---|
| 248 | 640 | * |
|---|
| 249 | | - * Tells whether the bridge samples the digital input signal |
|---|
| 250 | | - * from the display engine on the positive or negative edge of the |
|---|
| 251 | | - * clock, this should reuse the DRM_BUS_FLAG_PIXDATA_[POS|NEG]EDGE |
|---|
| 252 | | - * bitwise flags from the DRM connector (bit 2 and 3 valid). |
|---|
| 641 | + * Tells what additional settings for the pixel data on the bus |
|---|
| 642 | + * this bridge requires (like pixel signal polarity). See also |
|---|
| 643 | + * &drm_display_info->bus_flags. |
|---|
| 253 | 644 | */ |
|---|
| 254 | | - u32 sampling_edge; |
|---|
| 645 | + u32 input_bus_flags; |
|---|
| 255 | 646 | /** |
|---|
| 256 | 647 | * @setup_time_ps: |
|---|
| 257 | 648 | * |
|---|
| .. | .. |
|---|
| 266 | 657 | * input signal after the clock edge. |
|---|
| 267 | 658 | */ |
|---|
| 268 | 659 | u32 hold_time_ps; |
|---|
| 660 | + /** |
|---|
| 661 | + * @dual_link: |
|---|
| 662 | + * |
|---|
| 663 | + * True if the bus operates in dual-link mode. The exact meaning is |
|---|
| 664 | + * dependent on the bus type. For LVDS buses, this indicates that even- |
|---|
| 665 | + * and odd-numbered pixels are received on separate links. |
|---|
| 666 | + */ |
|---|
| 667 | + bool dual_link; |
|---|
| 668 | +}; |
|---|
| 669 | + |
|---|
| 670 | +/** |
|---|
| 671 | + * enum drm_bridge_ops - Bitmask of operations supported by the bridge |
|---|
| 672 | + */ |
|---|
| 673 | +enum drm_bridge_ops { |
|---|
| 674 | + /** |
|---|
| 675 | + * @DRM_BRIDGE_OP_DETECT: The bridge can detect displays connected to |
|---|
| 676 | + * its output. Bridges that set this flag shall implement the |
|---|
| 677 | + * &drm_bridge_funcs->detect callback. |
|---|
| 678 | + */ |
|---|
| 679 | + DRM_BRIDGE_OP_DETECT = BIT(0), |
|---|
| 680 | + /** |
|---|
| 681 | + * @DRM_BRIDGE_OP_EDID: The bridge can retrieve the EDID of the display |
|---|
| 682 | + * connected to its output. Bridges that set this flag shall implement |
|---|
| 683 | + * the &drm_bridge_funcs->get_edid callback. |
|---|
| 684 | + */ |
|---|
| 685 | + DRM_BRIDGE_OP_EDID = BIT(1), |
|---|
| 686 | + /** |
|---|
| 687 | + * @DRM_BRIDGE_OP_HPD: The bridge can detect hot-plug and hot-unplug |
|---|
| 688 | + * without requiring polling. Bridges that set this flag shall |
|---|
| 689 | + * implement the &drm_bridge_funcs->hpd_enable and |
|---|
| 690 | + * &drm_bridge_funcs->hpd_disable callbacks if they support enabling |
|---|
| 691 | + * and disabling hot-plug detection dynamically. |
|---|
| 692 | + */ |
|---|
| 693 | + DRM_BRIDGE_OP_HPD = BIT(2), |
|---|
| 694 | + /** |
|---|
| 695 | + * @DRM_BRIDGE_OP_MODES: The bridge can retrieve the modes supported |
|---|
| 696 | + * by the display at its output. This does not include reading EDID |
|---|
| 697 | + * which is separately covered by @DRM_BRIDGE_OP_EDID. Bridges that set |
|---|
| 698 | + * this flag shall implement the &drm_bridge_funcs->get_modes callback. |
|---|
| 699 | + */ |
|---|
| 700 | + DRM_BRIDGE_OP_MODES = BIT(3), |
|---|
| 269 | 701 | }; |
|---|
| 270 | 702 | |
|---|
| 271 | 703 | /** |
|---|
| 272 | 704 | * struct drm_bridge - central DRM bridge control structure |
|---|
| 273 | 705 | */ |
|---|
| 274 | 706 | struct drm_bridge { |
|---|
| 707 | + /** @base: inherit from &drm_private_object */ |
|---|
| 708 | + struct drm_private_obj base; |
|---|
| 275 | 709 | /** @dev: DRM device this bridge belongs to */ |
|---|
| 276 | 710 | struct drm_device *dev; |
|---|
| 277 | 711 | /** @encoder: encoder to which this bridge is connected */ |
|---|
| 278 | 712 | struct drm_encoder *encoder; |
|---|
| 279 | | - /** @next: the next bridge in the encoder chain */ |
|---|
| 280 | | - struct drm_bridge *next; |
|---|
| 713 | + /** @chain_node: used to form a bridge chain */ |
|---|
| 714 | + struct list_head chain_node; |
|---|
| 281 | 715 | #ifdef CONFIG_OF |
|---|
| 282 | 716 | /** @of_node: device node pointer to the bridge */ |
|---|
| 283 | 717 | struct device_node *of_node; |
|---|
| .. | .. |
|---|
| 294 | 728 | const struct drm_bridge_funcs *funcs; |
|---|
| 295 | 729 | /** @driver_private: pointer to the bridge driver's internal context */ |
|---|
| 296 | 730 | void *driver_private; |
|---|
| 731 | + /** @ops: bitmask of operations supported by the bridge */ |
|---|
| 732 | + enum drm_bridge_ops ops; |
|---|
| 733 | + /** |
|---|
| 734 | + * @type: Type of the connection at the bridge output |
|---|
| 735 | + * (DRM_MODE_CONNECTOR_*). For bridges at the end of this chain this |
|---|
| 736 | + * identifies the type of connected display. |
|---|
| 737 | + */ |
|---|
| 738 | + int type; |
|---|
| 739 | + /** |
|---|
| 740 | + * @interlace_allowed: Indicate that the bridge can handle interlaced |
|---|
| 741 | + * modes. |
|---|
| 742 | + */ |
|---|
| 743 | + bool interlace_allowed; |
|---|
| 744 | + /** |
|---|
| 745 | + * @ddc: Associated I2C adapter for DDC access, if any. |
|---|
| 746 | + */ |
|---|
| 747 | + struct i2c_adapter *ddc; |
|---|
| 748 | + /** private: */ |
|---|
| 749 | + /** |
|---|
| 750 | + * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields. |
|---|
| 751 | + */ |
|---|
| 752 | + struct mutex hpd_mutex; |
|---|
| 753 | + /** |
|---|
| 754 | + * @hpd_cb: Hot plug detection callback, registered with |
|---|
| 755 | + * drm_bridge_hpd_enable(). |
|---|
| 756 | + */ |
|---|
| 757 | + void (*hpd_cb)(void *data, enum drm_connector_status status); |
|---|
| 758 | + /** |
|---|
| 759 | + * @hpd_data: Private data passed to the Hot plug detection callback |
|---|
| 760 | + * @hpd_cb. |
|---|
| 761 | + */ |
|---|
| 762 | + void *hpd_data; |
|---|
| 297 | 763 | }; |
|---|
| 764 | + |
|---|
| 765 | +static inline struct drm_bridge * |
|---|
| 766 | +drm_priv_to_bridge(struct drm_private_obj *priv) |
|---|
| 767 | +{ |
|---|
| 768 | + return container_of(priv, struct drm_bridge, base); |
|---|
| 769 | +} |
|---|
| 298 | 770 | |
|---|
| 299 | 771 | void drm_bridge_add(struct drm_bridge *bridge); |
|---|
| 300 | 772 | void drm_bridge_remove(struct drm_bridge *bridge); |
|---|
| 301 | 773 | struct drm_bridge *of_drm_find_bridge(struct device_node *np); |
|---|
| 302 | 774 | int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge, |
|---|
| 303 | | - struct drm_bridge *previous); |
|---|
| 775 | + struct drm_bridge *previous, |
|---|
| 776 | + enum drm_bridge_attach_flags flags); |
|---|
| 304 | 777 | |
|---|
| 305 | | -bool drm_bridge_mode_fixup(struct drm_bridge *bridge, |
|---|
| 306 | | - const struct drm_display_mode *mode, |
|---|
| 307 | | - struct drm_display_mode *adjusted_mode); |
|---|
| 308 | | -enum drm_mode_status drm_bridge_mode_valid(struct drm_bridge *bridge, |
|---|
| 309 | | - const struct drm_display_mode *mode); |
|---|
| 310 | | -void drm_bridge_disable(struct drm_bridge *bridge); |
|---|
| 311 | | -void drm_bridge_post_disable(struct drm_bridge *bridge); |
|---|
| 312 | | -void drm_bridge_mode_set(struct drm_bridge *bridge, |
|---|
| 313 | | - struct drm_display_mode *mode, |
|---|
| 314 | | - struct drm_display_mode *adjusted_mode); |
|---|
| 315 | | -void drm_bridge_pre_enable(struct drm_bridge *bridge); |
|---|
| 316 | | -void drm_bridge_enable(struct drm_bridge *bridge); |
|---|
| 778 | +/** |
|---|
| 779 | + * drm_bridge_get_next_bridge() - Get the next bridge in the chain |
|---|
| 780 | + * @bridge: bridge object |
|---|
| 781 | + * |
|---|
| 782 | + * RETURNS: |
|---|
| 783 | + * the next bridge in the chain after @bridge, or NULL if @bridge is the last. |
|---|
| 784 | + */ |
|---|
| 785 | +static inline struct drm_bridge * |
|---|
| 786 | +drm_bridge_get_next_bridge(struct drm_bridge *bridge) |
|---|
| 787 | +{ |
|---|
| 788 | + if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain)) |
|---|
| 789 | + return NULL; |
|---|
| 790 | + |
|---|
| 791 | + return list_next_entry(bridge, chain_node); |
|---|
| 792 | +} |
|---|
| 793 | + |
|---|
| 794 | +/** |
|---|
| 795 | + * drm_bridge_get_prev_bridge() - Get the previous bridge in the chain |
|---|
| 796 | + * @bridge: bridge object |
|---|
| 797 | + * |
|---|
| 798 | + * RETURNS: |
|---|
| 799 | + * the previous bridge in the chain, or NULL if @bridge is the first. |
|---|
| 800 | + */ |
|---|
| 801 | +static inline struct drm_bridge * |
|---|
| 802 | +drm_bridge_get_prev_bridge(struct drm_bridge *bridge) |
|---|
| 803 | +{ |
|---|
| 804 | + if (list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain)) |
|---|
| 805 | + return NULL; |
|---|
| 806 | + |
|---|
| 807 | + return list_prev_entry(bridge, chain_node); |
|---|
| 808 | +} |
|---|
| 809 | + |
|---|
| 810 | +/** |
|---|
| 811 | + * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain |
|---|
| 812 | + * @encoder: encoder object |
|---|
| 813 | + * |
|---|
| 814 | + * RETURNS: |
|---|
| 815 | + * the first bridge in the chain, or NULL if @encoder has no bridge attached |
|---|
| 816 | + * to it. |
|---|
| 817 | + */ |
|---|
| 818 | +static inline struct drm_bridge * |
|---|
| 819 | +drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder) |
|---|
| 820 | +{ |
|---|
| 821 | + return list_first_entry_or_null(&encoder->bridge_chain, |
|---|
| 822 | + struct drm_bridge, chain_node); |
|---|
| 823 | +} |
|---|
| 824 | + |
|---|
| 825 | +/** |
|---|
| 826 | + * drm_for_each_bridge_in_chain() - Iterate over all bridges present in a chain |
|---|
| 827 | + * @encoder: the encoder to iterate bridges on |
|---|
| 828 | + * @bridge: a bridge pointer updated to point to the current bridge at each |
|---|
| 829 | + * iteration |
|---|
| 830 | + * |
|---|
| 831 | + * Iterate over all bridges present in the bridge chain attached to @encoder. |
|---|
| 832 | + */ |
|---|
| 833 | +#define drm_for_each_bridge_in_chain(encoder, bridge) \ |
|---|
| 834 | + list_for_each_entry(bridge, &(encoder)->bridge_chain, chain_node) |
|---|
| 835 | + |
|---|
| 836 | +bool drm_bridge_chain_mode_fixup(struct drm_bridge *bridge, |
|---|
| 837 | + const struct drm_display_mode *mode, |
|---|
| 838 | + struct drm_display_mode *adjusted_mode); |
|---|
| 839 | +enum drm_mode_status |
|---|
| 840 | +drm_bridge_chain_mode_valid(struct drm_bridge *bridge, |
|---|
| 841 | + const struct drm_display_info *info, |
|---|
| 842 | + const struct drm_display_mode *mode); |
|---|
| 843 | +void drm_bridge_chain_disable(struct drm_bridge *bridge); |
|---|
| 844 | +void drm_bridge_chain_post_disable(struct drm_bridge *bridge); |
|---|
| 845 | +void drm_bridge_chain_mode_set(struct drm_bridge *bridge, |
|---|
| 846 | + const struct drm_display_mode *mode, |
|---|
| 847 | + const struct drm_display_mode *adjusted_mode); |
|---|
| 848 | +void drm_bridge_chain_pre_enable(struct drm_bridge *bridge); |
|---|
| 849 | +void drm_bridge_chain_enable(struct drm_bridge *bridge); |
|---|
| 850 | + |
|---|
| 851 | +int drm_atomic_bridge_chain_check(struct drm_bridge *bridge, |
|---|
| 852 | + struct drm_crtc_state *crtc_state, |
|---|
| 853 | + struct drm_connector_state *conn_state); |
|---|
| 854 | +void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge, |
|---|
| 855 | + struct drm_atomic_state *state); |
|---|
| 856 | +void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge, |
|---|
| 857 | + struct drm_atomic_state *state); |
|---|
| 858 | +void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge, |
|---|
| 859 | + struct drm_atomic_state *state); |
|---|
| 860 | +void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge, |
|---|
| 861 | + struct drm_atomic_state *state); |
|---|
| 862 | + |
|---|
| 863 | +u32 * |
|---|
| 864 | +drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge, |
|---|
| 865 | + struct drm_bridge_state *bridge_state, |
|---|
| 866 | + struct drm_crtc_state *crtc_state, |
|---|
| 867 | + struct drm_connector_state *conn_state, |
|---|
| 868 | + u32 output_fmt, |
|---|
| 869 | + unsigned int *num_input_fmts); |
|---|
| 870 | + |
|---|
| 871 | +enum drm_connector_status drm_bridge_detect(struct drm_bridge *bridge); |
|---|
| 872 | +int drm_bridge_get_modes(struct drm_bridge *bridge, |
|---|
| 873 | + struct drm_connector *connector); |
|---|
| 874 | +struct edid *drm_bridge_get_edid(struct drm_bridge *bridge, |
|---|
| 875 | + struct drm_connector *connector); |
|---|
| 876 | +void drm_bridge_hpd_enable(struct drm_bridge *bridge, |
|---|
| 877 | + void (*cb)(void *data, |
|---|
| 878 | + enum drm_connector_status status), |
|---|
| 879 | + void *data); |
|---|
| 880 | +void drm_bridge_hpd_disable(struct drm_bridge *bridge); |
|---|
| 881 | +void drm_bridge_hpd_notify(struct drm_bridge *bridge, |
|---|
| 882 | + enum drm_connector_status status); |
|---|
| 317 | 883 | |
|---|
| 318 | 884 | #ifdef CONFIG_DRM_PANEL_BRIDGE |
|---|
| 319 | | -struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel, |
|---|
| 320 | | - u32 connector_type); |
|---|
| 885 | +struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel); |
|---|
| 886 | +struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel, |
|---|
| 887 | + u32 connector_type); |
|---|
| 321 | 888 | void drm_panel_bridge_remove(struct drm_bridge *bridge); |
|---|
| 322 | 889 | struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev, |
|---|
| 323 | | - struct drm_panel *panel, |
|---|
| 324 | | - u32 connector_type); |
|---|
| 890 | + struct drm_panel *panel); |
|---|
| 891 | +struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev, |
|---|
| 892 | + struct drm_panel *panel, |
|---|
| 893 | + u32 connector_type); |
|---|
| 894 | +struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge); |
|---|
| 325 | 895 | #endif |
|---|
| 326 | 896 | |
|---|
| 327 | 897 | #endif |
|---|