1 /* 2 * Copyright (c) 2016 Intel Corporation 3 * 4 * Permission to use, copy, modify, distribute, and sell this software and its 5 * documentation for any purpose is hereby granted without fee, provided that 6 * the above copyright notice appear in all copies and that both that copyright 7 * notice and this permission notice appear in supporting documentation, and 8 * that the name of the copyright holders not be used in advertising or 9 * publicity pertaining to distribution of the software without specific, 10 * written prior permission. The copyright holders make no representations 11 * about the suitability of this software for any purpose. It is provided "as 12 * is" without express or implied warranty. 13 * 14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 20 * OF THIS SOFTWARE. 21 */ 22 23 #ifndef __DRM_BRIDGE_H__ 24 #define __DRM_BRIDGE_H__ 25 26 #include <linux/cleanup.h> 27 #include <linux/ctype.h> 28 #include <linux/list.h> 29 #include <linux/mutex.h> 30 31 #include <drm/drm_atomic.h> 32 #include <drm/drm_encoder.h> 33 #include <drm/drm_mode_object.h> 34 #include <drm/drm_modes.h> 35 36 struct cec_msg; 37 struct device_node; 38 39 struct drm_bridge; 40 struct drm_bridge_timings; 41 struct drm_connector; 42 struct drm_display_info; 43 struct drm_minor; 44 struct drm_panel; 45 struct edid; 46 struct hdmi_codec_daifmt; 47 struct hdmi_codec_params; 48 struct i2c_adapter; 49 50 /** 51 * enum drm_bridge_attach_flags - Flags for &drm_bridge_funcs.attach 52 */ 53 enum drm_bridge_attach_flags { 54 /** 55 * @DRM_BRIDGE_ATTACH_NO_CONNECTOR: When this flag is set the bridge 56 * shall not create a drm_connector. 57 */ 58 DRM_BRIDGE_ATTACH_NO_CONNECTOR = BIT(0), 59 }; 60 61 /** 62 * struct drm_bridge_funcs - drm_bridge control functions 63 */ 64 struct drm_bridge_funcs { 65 /** 66 * @attach: 67 * 68 * This callback is invoked whenever our bridge is being attached to a 69 * &drm_encoder. The flags argument tunes the behaviour of the attach 70 * operation (see DRM_BRIDGE_ATTACH_*). 71 * 72 * The @attach callback is optional. 73 * 74 * RETURNS: 75 * 76 * Zero on success, error code on failure. 77 */ 78 int (*attach)(struct drm_bridge *bridge, struct drm_encoder *encoder, 79 enum drm_bridge_attach_flags flags); 80 81 /** 82 * @destroy: 83 * 84 * This callback is invoked when the bridge is about to be 85 * deallocated. 86 * 87 * The @destroy callback is optional. 88 */ 89 void (*destroy)(struct drm_bridge *bridge); 90 91 /** 92 * @detach: 93 * 94 * This callback is invoked whenever our bridge is being detached from a 95 * &drm_encoder. 96 * 97 * The @detach callback is optional. 98 */ 99 void (*detach)(struct drm_bridge *bridge); 100 101 /** 102 * @mode_valid: 103 * 104 * This callback is used to check if a specific mode is valid in this 105 * bridge. This should be implemented if the bridge has some sort of 106 * restriction in the modes it can display. For example, a given bridge 107 * may be responsible to set a clock value. If the clock can not 108 * produce all the values for the available modes then this callback 109 * can be used to restrict the number of modes to only the ones that 110 * can be displayed. 111 * 112 * This hook is used by the probe helpers to filter the mode list in 113 * drm_helper_probe_single_connector_modes(), and it is used by the 114 * atomic helpers to validate modes supplied by userspace in 115 * drm_atomic_helper_check_modeset(). 116 * 117 * The @mode_valid callback is optional. 118 * 119 * NOTE: 120 * 121 * Since this function is both called from the check phase of an atomic 122 * commit, and the mode validation in the probe paths it is not allowed 123 * to look at anything else but the passed-in mode, and validate it 124 * against configuration-invariant hardware constraints. Any further 125 * limits which depend upon the configuration can only be checked in 126 * @mode_fixup. 127 * 128 * RETURNS: 129 * 130 * drm_mode_status Enum 131 */ 132 enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge, 133 const struct drm_display_info *info, 134 const struct drm_display_mode *mode); 135 136 /** 137 * @mode_fixup: 138 * 139 * This callback is used to validate and adjust a mode. The parameter 140 * mode is the display mode that should be fed to the next element in 141 * the display chain, either the final &drm_connector or the next 142 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge 143 * requires. It can be modified by this callback and does not need to 144 * match mode. See also &drm_crtc_state.adjusted_mode for more details. 145 * 146 * This is the only hook that allows a bridge to reject a modeset. If 147 * this function passes all other callbacks must succeed for this 148 * configuration. 149 * 150 * The mode_fixup callback is optional. &drm_bridge_funcs.mode_fixup() 151 * is not called when &drm_bridge_funcs.atomic_check() is implemented, 152 * so only one of them should be provided. 153 * 154 * NOTE: 155 * 156 * This function is called in the check phase of atomic modesets, which 157 * can be aborted for any reason (including on userspace's request to 158 * just check whether a configuration would be possible). Drivers MUST 159 * NOT touch any persistent state (hardware or software) or data 160 * structures except the passed in @state parameter. 161 * 162 * Also beware that userspace can request its own custom modes, neither 163 * core nor helpers filter modes to the list of probe modes reported by 164 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure 165 * that modes are filtered consistently put any bridge constraints and 166 * limits checks into @mode_valid. 167 * 168 * RETURNS: 169 * 170 * True if an acceptable configuration is possible, false if the modeset 171 * operation should be rejected. 172 */ 173 bool (*mode_fixup)(struct drm_bridge *bridge, 174 const struct drm_display_mode *mode, 175 struct drm_display_mode *adjusted_mode); 176 /** 177 * @disable: 178 * 179 * The @disable callback should disable the bridge. 180 * 181 * The bridge can assume that the display pipe (i.e. clocks and timing 182 * signals) feeding it is still running when this callback is called. 183 * 184 * 185 * If the preceding element is a &drm_bridge, then this is called before 186 * that bridge is disabled via one of: 187 * 188 * - &drm_bridge_funcs.disable 189 * - &drm_bridge_funcs.atomic_disable 190 * 191 * If the preceding element of the bridge is a display controller, then 192 * this callback is called before the encoder is disabled via one of: 193 * 194 * - &drm_encoder_helper_funcs.atomic_disable 195 * - &drm_encoder_helper_funcs.prepare 196 * - &drm_encoder_helper_funcs.disable 197 * - &drm_encoder_helper_funcs.dpms 198 * 199 * and the CRTC is disabled via one of: 200 * 201 * - &drm_crtc_helper_funcs.prepare 202 * - &drm_crtc_helper_funcs.atomic_disable 203 * - &drm_crtc_helper_funcs.disable 204 * - &drm_crtc_helper_funcs.dpms. 205 * 206 * The @disable callback is optional. 207 * 208 * NOTE: 209 * 210 * This is deprecated, do not use! 211 * New drivers shall use &drm_bridge_funcs.atomic_disable. 212 */ 213 void (*disable)(struct drm_bridge *bridge); 214 215 /** 216 * @post_disable: 217 * 218 * The bridge must assume that the display pipe (i.e. clocks and timing 219 * signals) feeding this bridge is no longer running when the 220 * @post_disable is called. 221 * 222 * This callback should perform all the actions required by the hardware 223 * after it has stopped receiving signals from the preceding element. 224 * 225 * If the preceding element is a &drm_bridge, then this is called after 226 * that bridge is post-disabled (unless marked otherwise by the 227 * @pre_enable_prev_first flag) via one of: 228 * 229 * - &drm_bridge_funcs.post_disable 230 * - &drm_bridge_funcs.atomic_post_disable 231 * 232 * If the preceding element of the bridge is a display controller, then 233 * this callback is called after the encoder is disabled via one of: 234 * 235 * - &drm_encoder_helper_funcs.atomic_disable 236 * - &drm_encoder_helper_funcs.prepare 237 * - &drm_encoder_helper_funcs.disable 238 * - &drm_encoder_helper_funcs.dpms 239 * 240 * and the CRTC is disabled via one of: 241 * 242 * - &drm_crtc_helper_funcs.prepare 243 * - &drm_crtc_helper_funcs.atomic_disable 244 * - &drm_crtc_helper_funcs.disable 245 * - &drm_crtc_helper_funcs.dpms 246 * 247 * The @post_disable callback is optional. 248 * 249 * NOTE: 250 * 251 * This is deprecated, do not use! 252 * New drivers shall use &drm_bridge_funcs.atomic_post_disable. 253 */ 254 void (*post_disable)(struct drm_bridge *bridge); 255 256 /** 257 * @mode_set: 258 * 259 * This callback should set the given mode on the bridge. It is called 260 * after the @mode_set callback for the preceding element in the display 261 * pipeline has been called already. If the bridge is the first element 262 * then this would be &drm_encoder_helper_funcs.mode_set. The display 263 * pipe (i.e. clocks and timing signals) is off when this function is 264 * called. 265 * 266 * The adjusted_mode parameter is the mode output by the CRTC for the 267 * first bridge in the chain. It can be different from the mode 268 * parameter that contains the desired mode for the connector at the end 269 * of the bridges chain, for instance when the first bridge in the chain 270 * performs scaling. The adjusted mode is mostly useful for the first 271 * bridge in the chain and is likely irrelevant for the other bridges. 272 * 273 * For atomic drivers the adjusted_mode is the mode stored in 274 * &drm_crtc_state.adjusted_mode. 275 * 276 * NOTE: 277 * 278 * This is deprecated, do not use! 279 * New drivers shall set their mode in the 280 * &drm_bridge_funcs.atomic_enable operation. 281 */ 282 void (*mode_set)(struct drm_bridge *bridge, 283 const struct drm_display_mode *mode, 284 const struct drm_display_mode *adjusted_mode); 285 /** 286 * @pre_enable: 287 * 288 * The display pipe (i.e. clocks and timing signals) feeding this bridge 289 * will not yet be running when the @pre_enable is called. 290 * 291 * This callback should perform all the necessary actions to prepare the 292 * bridge to accept signals from the preceding element. 293 * 294 * If the preceding element is a &drm_bridge, then this is called before 295 * that bridge is pre-enabled (unless marked otherwise by 296 * @pre_enable_prev_first flag) via one of: 297 * 298 * - &drm_bridge_funcs.pre_enable 299 * - &drm_bridge_funcs.atomic_pre_enable 300 * 301 * If the preceding element of the bridge is a display controller, then 302 * this callback is called before the CRTC is enabled via one of: 303 * 304 * - &drm_crtc_helper_funcs.atomic_enable 305 * - &drm_crtc_helper_funcs.commit 306 * 307 * and the encoder is enabled via one of: 308 * 309 * - &drm_encoder_helper_funcs.atomic_enable 310 * - &drm_encoder_helper_funcs.enable 311 * - &drm_encoder_helper_funcs.commit 312 * 313 * The @pre_enable callback is optional. 314 * 315 * NOTE: 316 * 317 * This is deprecated, do not use! 318 * New drivers shall use &drm_bridge_funcs.atomic_pre_enable. 319 */ 320 void (*pre_enable)(struct drm_bridge *bridge); 321 322 /** 323 * @enable: 324 * 325 * The @enable callback should enable the bridge. 326 * 327 * The bridge can assume that the display pipe (i.e. clocks and timing 328 * signals) feeding it is running when this callback is called. This 329 * callback must enable the display link feeding the next bridge in the 330 * chain if there is one. 331 * 332 * If the preceding element is a &drm_bridge, then this is called after 333 * that bridge is enabled via one of: 334 * 335 * - &drm_bridge_funcs.enable 336 * - &drm_bridge_funcs.atomic_enable 337 * 338 * If the preceding element of the bridge is a display controller, then 339 * this callback is called after the CRTC is enabled via one of: 340 * 341 * - &drm_crtc_helper_funcs.atomic_enable 342 * - &drm_crtc_helper_funcs.commit 343 * 344 * and the encoder is enabled via one of: 345 * 346 * - &drm_encoder_helper_funcs.atomic_enable 347 * - &drm_encoder_helper_funcs.enable 348 * - drm_encoder_helper_funcs.commit 349 * 350 * The @enable callback is optional. 351 * 352 * NOTE: 353 * 354 * This is deprecated, do not use! 355 * New drivers shall use &drm_bridge_funcs.atomic_enable. 356 */ 357 void (*enable)(struct drm_bridge *bridge); 358 359 /** 360 * @atomic_pre_enable: 361 * 362 * The display pipe (i.e. clocks and timing signals) feeding this bridge 363 * will not yet be running when the @atomic_pre_enable is called. 364 * 365 * This callback should perform all the necessary actions to prepare the 366 * bridge to accept signals from the preceding element. 367 * 368 * If the preceding element is a &drm_bridge, then this is called before 369 * that bridge is pre-enabled (unless marked otherwise by 370 * @pre_enable_prev_first flag) via one of: 371 * 372 * - &drm_bridge_funcs.pre_enable 373 * - &drm_bridge_funcs.atomic_pre_enable 374 * 375 * If the preceding element of the bridge is a display controller, then 376 * this callback is called before the CRTC is enabled via one of: 377 * 378 * - &drm_crtc_helper_funcs.atomic_enable 379 * - &drm_crtc_helper_funcs.commit 380 * 381 * and the encoder is enabled via one of: 382 * 383 * - &drm_encoder_helper_funcs.atomic_enable 384 * - &drm_encoder_helper_funcs.enable 385 * - &drm_encoder_helper_funcs.commit 386 * 387 * The @atomic_pre_enable callback is optional. 388 */ 389 void (*atomic_pre_enable)(struct drm_bridge *bridge, 390 struct drm_atomic_state *state); 391 392 /** 393 * @atomic_enable: 394 * 395 * The @atomic_enable callback should enable the bridge. 396 * 397 * The bridge can assume that the display pipe (i.e. clocks and timing 398 * signals) feeding it is running when this callback is called. This 399 * callback must enable the display link feeding the next bridge in the 400 * chain if there is one. 401 * 402 * If the preceding element is a &drm_bridge, then this is called after 403 * that bridge is enabled via one of: 404 * 405 * - &drm_bridge_funcs.enable 406 * - &drm_bridge_funcs.atomic_enable 407 * 408 * If the preceding element of the bridge is a display controller, then 409 * this callback is called after the CRTC is enabled via one of: 410 * 411 * - &drm_crtc_helper_funcs.atomic_enable 412 * - &drm_crtc_helper_funcs.commit 413 * 414 * and the encoder is enabled via one of: 415 * 416 * - &drm_encoder_helper_funcs.atomic_enable 417 * - &drm_encoder_helper_funcs.enable 418 * - drm_encoder_helper_funcs.commit 419 * 420 * The @atomic_enable callback is optional. 421 */ 422 void (*atomic_enable)(struct drm_bridge *bridge, 423 struct drm_atomic_state *state); 424 /** 425 * @atomic_disable: 426 * 427 * The @atomic_disable callback should disable the bridge. 428 * 429 * The bridge can assume that the display pipe (i.e. clocks and timing 430 * signals) feeding it is still running when this callback is called. 431 * 432 * If the preceding element is a &drm_bridge, then this is called before 433 * that bridge is disabled via one of: 434 * 435 * - &drm_bridge_funcs.disable 436 * - &drm_bridge_funcs.atomic_disable 437 * 438 * If the preceding element of the bridge is a display controller, then 439 * this callback is called before the encoder is disabled via one of: 440 * 441 * - &drm_encoder_helper_funcs.atomic_disable 442 * - &drm_encoder_helper_funcs.prepare 443 * - &drm_encoder_helper_funcs.disable 444 * - &drm_encoder_helper_funcs.dpms 445 * 446 * and the CRTC is disabled via one of: 447 * 448 * - &drm_crtc_helper_funcs.prepare 449 * - &drm_crtc_helper_funcs.atomic_disable 450 * - &drm_crtc_helper_funcs.disable 451 * - &drm_crtc_helper_funcs.dpms. 452 * 453 * The @atomic_disable callback is optional. 454 */ 455 void (*atomic_disable)(struct drm_bridge *bridge, 456 struct drm_atomic_state *state); 457 458 /** 459 * @atomic_post_disable: 460 * 461 * The bridge must assume that the display pipe (i.e. clocks and timing 462 * signals) feeding this bridge is no longer running when the 463 * @atomic_post_disable is called. 464 * 465 * This callback should perform all the actions required by the hardware 466 * after it has stopped receiving signals from the preceding element. 467 * 468 * If the preceding element is a &drm_bridge, then this is called after 469 * that bridge is post-disabled (unless marked otherwise by the 470 * @pre_enable_prev_first flag) via one of: 471 * 472 * - &drm_bridge_funcs.post_disable 473 * - &drm_bridge_funcs.atomic_post_disable 474 * 475 * If the preceding element of the bridge is a display controller, then 476 * this callback is called after the encoder is disabled via one of: 477 * 478 * - &drm_encoder_helper_funcs.atomic_disable 479 * - &drm_encoder_helper_funcs.prepare 480 * - &drm_encoder_helper_funcs.disable 481 * - &drm_encoder_helper_funcs.dpms 482 * 483 * and the CRTC is disabled via one of: 484 * 485 * - &drm_crtc_helper_funcs.prepare 486 * - &drm_crtc_helper_funcs.atomic_disable 487 * - &drm_crtc_helper_funcs.disable 488 * - &drm_crtc_helper_funcs.dpms 489 * 490 * The @atomic_post_disable callback is optional. 491 */ 492 void (*atomic_post_disable)(struct drm_bridge *bridge, 493 struct drm_atomic_state *state); 494 495 /** 496 * @atomic_duplicate_state: 497 * 498 * Duplicate the current bridge state object (which is guaranteed to be 499 * non-NULL). 500 * 501 * The atomic_duplicate_state hook is mandatory if the bridge 502 * implements any of the atomic hooks, and should be left unassigned 503 * otherwise. For bridges that don't subclass &drm_bridge_state, the 504 * drm_atomic_helper_bridge_duplicate_state() helper function shall be 505 * used to implement this hook. 506 * 507 * RETURNS: 508 * A valid drm_bridge_state object or NULL if the allocation fails. 509 */ 510 struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge); 511 512 /** 513 * @atomic_destroy_state: 514 * 515 * Destroy a bridge state object previously allocated by 516 * &drm_bridge_funcs.atomic_duplicate_state(). 517 * 518 * The atomic_destroy_state hook is mandatory if the bridge implements 519 * any of the atomic hooks, and should be left unassigned otherwise. 520 * For bridges that don't subclass &drm_bridge_state, the 521 * drm_atomic_helper_bridge_destroy_state() helper function shall be 522 * used to implement this hook. 523 */ 524 void (*atomic_destroy_state)(struct drm_bridge *bridge, 525 struct drm_bridge_state *state); 526 527 /** 528 * @atomic_get_output_bus_fmts: 529 * 530 * Return the supported bus formats on the output end of a bridge. 531 * The returned array must be allocated with kmalloc() and will be 532 * freed by the caller. If the allocation fails, NULL should be 533 * returned. num_output_fmts must be set to the returned array size. 534 * Formats listed in the returned array should be listed in decreasing 535 * preference order (the core will try all formats until it finds one 536 * that works). 537 * 538 * This method is only called on the last element of the bridge chain 539 * as part of the bus format negotiation process that happens in 540 * &drm_atomic_bridge_chain_select_bus_fmts(). 541 * This method is optional. When not implemented, the core will 542 * fall back to &drm_connector.display_info.bus_formats[0] if 543 * &drm_connector.display_info.num_bus_formats > 0, 544 * or to MEDIA_BUS_FMT_FIXED otherwise. 545 */ 546 u32 *(*atomic_get_output_bus_fmts)(struct drm_bridge *bridge, 547 struct drm_bridge_state *bridge_state, 548 struct drm_crtc_state *crtc_state, 549 struct drm_connector_state *conn_state, 550 unsigned int *num_output_fmts); 551 552 /** 553 * @atomic_get_input_bus_fmts: 554 * 555 * Return the supported bus formats on the input end of a bridge for 556 * a specific output bus format. 557 * 558 * The returned array must be allocated with kmalloc() and will be 559 * freed by the caller. If the allocation fails, NULL should be 560 * returned. num_input_fmts must be set to the returned array size. 561 * Formats listed in the returned array should be listed in decreasing 562 * preference order (the core will try all formats until it finds one 563 * that works). When the format is not supported NULL should be 564 * returned and num_input_fmts should be set to 0. 565 * 566 * This method is called on all elements of the bridge chain as part of 567 * the bus format negotiation process that happens in 568 * drm_atomic_bridge_chain_select_bus_fmts(). 569 * This method is optional. When not implemented, the core will bypass 570 * bus format negotiation on this element of the bridge without 571 * failing, and the previous element in the chain will be passed 572 * MEDIA_BUS_FMT_FIXED as its output bus format. 573 * 574 * Bridge drivers that need to support being linked to bridges that are 575 * not supporting bus format negotiation should handle the 576 * output_fmt == MEDIA_BUS_FMT_FIXED case appropriately, by selecting a 577 * sensible default value or extracting this information from somewhere 578 * else (FW property, &drm_display_mode, &drm_display_info, ...) 579 * 580 * Note: Even if input format selection on the first bridge has no 581 * impact on the negotiation process (bus format negotiation stops once 582 * we reach the first element of the chain), drivers are expected to 583 * return accurate input formats as the input format may be used to 584 * configure the CRTC output appropriately. 585 */ 586 u32 *(*atomic_get_input_bus_fmts)(struct drm_bridge *bridge, 587 struct drm_bridge_state *bridge_state, 588 struct drm_crtc_state *crtc_state, 589 struct drm_connector_state *conn_state, 590 u32 output_fmt, 591 unsigned int *num_input_fmts); 592 593 /** 594 * @atomic_check: 595 * 596 * This method is responsible for checking bridge state correctness. 597 * It can also check the state of the surrounding components in chain 598 * to make sure the whole pipeline can work properly. 599 * 600 * &drm_bridge_funcs.atomic_check() hooks are called in reverse 601 * order (from the last to the first bridge). 602 * 603 * This method is optional. &drm_bridge_funcs.mode_fixup() is not 604 * called when &drm_bridge_funcs.atomic_check() is implemented, so only 605 * one of them should be provided. 606 * 607 * If drivers need to tweak &drm_bridge_state.input_bus_cfg.flags or 608 * &drm_bridge_state.output_bus_cfg.flags it should happen in 609 * this function. By default the &drm_bridge_state.output_bus_cfg.flags 610 * field is set to the next bridge 611 * &drm_bridge_state.input_bus_cfg.flags value or 612 * &drm_connector.display_info.bus_flags if the bridge is the last 613 * element in the chain. 614 * 615 * RETURNS: 616 * zero if the check passed, a negative error code otherwise. 617 */ 618 int (*atomic_check)(struct drm_bridge *bridge, 619 struct drm_bridge_state *bridge_state, 620 struct drm_crtc_state *crtc_state, 621 struct drm_connector_state *conn_state); 622 623 /** 624 * @atomic_reset: 625 * 626 * Reset the bridge to a predefined state (or retrieve its current 627 * state) and return a &drm_bridge_state object matching this state. 628 * This function is called at attach time. 629 * 630 * The atomic_reset hook is mandatory if the bridge implements any of 631 * the atomic hooks, and should be left unassigned otherwise. For 632 * bridges that don't subclass &drm_bridge_state, the 633 * drm_atomic_helper_bridge_reset() helper function shall be used to 634 * implement this hook. 635 * 636 * Note that the atomic_reset() semantics is not exactly matching the 637 * reset() semantics found on other components (connector, plane, ...). 638 * 639 * 1. The reset operation happens when the bridge is attached, not when 640 * drm_mode_config_reset() is called 641 * 2. It's meant to be used exclusively on bridges that have been 642 * converted to the ATOMIC API 643 * 644 * RETURNS: 645 * A valid drm_bridge_state object in case of success, an ERR_PTR() 646 * giving the reason of the failure otherwise. 647 */ 648 struct drm_bridge_state *(*atomic_reset)(struct drm_bridge *bridge); 649 650 /** 651 * @detect: 652 * 653 * Check if anything is attached to the bridge output. 654 * 655 * This callback is optional, if not implemented the bridge will be 656 * considered as always having a component attached to its output. 657 * Bridges that implement this callback shall set the 658 * DRM_BRIDGE_OP_DETECT flag in their &drm_bridge->ops. 659 * 660 * RETURNS: 661 * 662 * drm_connector_status indicating the bridge output status. 663 */ 664 enum drm_connector_status (*detect)(struct drm_bridge *bridge, 665 struct drm_connector *connector); 666 667 /** 668 * @get_modes: 669 * 670 * Fill all modes currently valid for the sink into the &drm_connector 671 * with drm_mode_probed_add(). 672 * 673 * The @get_modes callback is mostly intended to support non-probeable 674 * displays such as many fixed panels. Bridges that support reading 675 * EDID shall leave @get_modes unimplemented and implement the 676 * &drm_bridge_funcs->edid_read callback instead. 677 * 678 * This callback is optional. Bridges that implement it shall set the 679 * DRM_BRIDGE_OP_MODES flag in their &drm_bridge->ops. 680 * 681 * The connector parameter shall be used for the sole purpose of 682 * filling modes, and shall not be stored internally by bridge drivers 683 * for future usage. 684 * 685 * RETURNS: 686 * 687 * The number of modes added by calling drm_mode_probed_add(). 688 */ 689 int (*get_modes)(struct drm_bridge *bridge, 690 struct drm_connector *connector); 691 692 /** 693 * @edid_read: 694 * 695 * Read the EDID data of the connected display. 696 * 697 * The @edid_read callback is the preferred way of reporting mode 698 * information for a display connected to the bridge output. Bridges 699 * that support reading EDID shall implement this callback and leave 700 * the @get_modes callback unimplemented. 701 * 702 * The caller of this operation shall first verify the output 703 * connection status and refrain from reading EDID from a disconnected 704 * output. 705 * 706 * This callback is optional. Bridges that implement it shall set the 707 * DRM_BRIDGE_OP_EDID flag in their &drm_bridge->ops. 708 * 709 * The connector parameter shall be used for the sole purpose of EDID 710 * retrieval, and shall not be stored internally by bridge drivers for 711 * future usage. 712 * 713 * RETURNS: 714 * 715 * An edid structure newly allocated with drm_edid_alloc() or returned 716 * from drm_edid_read() family of functions on success, or NULL 717 * otherwise. The caller is responsible for freeing the returned edid 718 * structure with drm_edid_free(). 719 */ 720 const struct drm_edid *(*edid_read)(struct drm_bridge *bridge, 721 struct drm_connector *connector); 722 723 /** 724 * @hpd_notify: 725 * 726 * Notify the bridge of hot plug detection. 727 * 728 * This callback is optional, it may be implemented by bridges that 729 * need to be notified of display connection or disconnection for 730 * internal reasons. One use case is to reset the internal state of CEC 731 * controllers for HDMI bridges. 732 */ 733 void (*hpd_notify)(struct drm_bridge *bridge, 734 struct drm_connector *connector, 735 enum drm_connector_status status); 736 737 /** 738 * @hpd_enable: 739 * 740 * Enable hot plug detection. From now on the bridge shall call 741 * drm_bridge_hpd_notify() each time a change is detected in the output 742 * connection status, until hot plug detection gets disabled with 743 * @hpd_disable. 744 * 745 * This callback is optional and shall only be implemented by bridges 746 * that support hot-plug notification without polling. Bridges that 747 * implement it shall also implement the @hpd_disable callback and set 748 * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops. 749 */ 750 void (*hpd_enable)(struct drm_bridge *bridge); 751 752 /** 753 * @hpd_disable: 754 * 755 * Disable hot plug detection. Once this function returns the bridge 756 * shall not call drm_bridge_hpd_notify() when a change in the output 757 * connection status occurs. 758 * 759 * This callback is optional and shall only be implemented by bridges 760 * that support hot-plug notification without polling. Bridges that 761 * implement it shall also implement the @hpd_enable callback and set 762 * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops. 763 */ 764 void (*hpd_disable)(struct drm_bridge *bridge); 765 766 /** 767 * @hdmi_tmds_char_rate_valid: 768 * 769 * Check whether a particular TMDS character rate is supported by the 770 * driver. 771 * 772 * This callback is optional and should only be implemented by the 773 * bridges that take part in the HDMI connector implementation. Bridges 774 * that implement it shall set the DRM_BRIDGE_OP_HDMI flag in their 775 * &drm_bridge->ops. 776 * 777 * Returns: 778 * 779 * Either &drm_mode_status.MODE_OK or one of the failure reasons 780 * in &enum drm_mode_status. 781 */ 782 enum drm_mode_status 783 (*hdmi_tmds_char_rate_valid)(const struct drm_bridge *bridge, 784 const struct drm_display_mode *mode, 785 unsigned long long tmds_rate); 786 787 /** 788 * @hdmi_clear_avi_infoframe: 789 * 790 * This callback clears the infoframes in the hardware during commit. 791 * 792 * This callback is optional but it must be implemented by bridges that 793 * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops. 794 */ 795 int (*hdmi_clear_avi_infoframe)(struct drm_bridge *bridge); 796 797 /** 798 * @hdmi_write_avi_infoframe: 799 * 800 * Program the infoframe into the hardware. 801 * 802 * This callback is optional but it must be implemented by bridges that 803 * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops. 804 */ 805 int (*hdmi_write_avi_infoframe)(struct drm_bridge *bridge, 806 const u8 *buffer, size_t len); 807 808 /** 809 * @hdmi_clear_hdmi_infoframe: 810 * 811 * This callback clears the infoframes in the hardware during commit. 812 * 813 * This callback is optional but it must be implemented by bridges that 814 * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops. 815 */ 816 int (*hdmi_clear_hdmi_infoframe)(struct drm_bridge *bridge); 817 818 /** 819 * @hdmi_write_hdmi_infoframe: 820 * 821 * Program the infoframe into the hardware. 822 * 823 * This callback is optional but it must be implemented by bridges that 824 * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops. 825 */ 826 int (*hdmi_write_hdmi_infoframe)(struct drm_bridge *bridge, 827 const u8 *buffer, size_t len); 828 829 /** 830 * @hdmi_clear_hdr_drm_infoframe: 831 * 832 * This callback clears the infoframes in the hardware during commit. 833 * 834 * This callback is optional but it must be implemented by bridges that 835 * set the DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME flag in their 836 * &drm_bridge->ops. 837 */ 838 int (*hdmi_clear_hdr_drm_infoframe)(struct drm_bridge *bridge); 839 840 /** 841 * @hdmi_write_hdr_drm_infoframe: 842 * 843 * Program the infoframe into the hardware. 844 * 845 * This callback is optional but it must be implemented by bridges that 846 * set the DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME flag in their 847 * &drm_bridge->ops. 848 */ 849 int (*hdmi_write_hdr_drm_infoframe)(struct drm_bridge *bridge, 850 const u8 *buffer, size_t len); 851 852 /** 853 * @hdmi_clear_spd_infoframe: 854 * 855 * This callback clears the infoframes in the hardware during commit. 856 * 857 * This callback is optional but it must be implemented by bridges that 858 * set the DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME flag in their 859 * &drm_bridge->ops. 860 */ 861 int (*hdmi_clear_spd_infoframe)(struct drm_bridge *bridge); 862 863 /** 864 * @hdmi_write_spd_infoframe: 865 * 866 * Program the infoframe into the hardware. 867 * 868 * This callback is optional but it must be implemented by bridges that 869 * set the DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME flag in their 870 * &drm_bridge->ops. 871 */ 872 int (*hdmi_write_spd_infoframe)(struct drm_bridge *bridge, 873 const u8 *buffer, size_t len); 874 875 /** 876 * @hdmi_clear_audio_infoframe: 877 * 878 * This callback clears the infoframes in the hardware during commit. 879 * 880 * This callback is optional but it must be implemented by bridges that 881 * set the DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops. 882 */ 883 int (*hdmi_clear_audio_infoframe)(struct drm_bridge *bridge); 884 885 /** 886 * @hdmi_write_audio_infoframe: 887 * 888 * Program the infoframe into the hardware. 889 * 890 * This callback is optional but it must be implemented by bridges that 891 * set the DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops. 892 */ 893 int (*hdmi_write_audio_infoframe)(struct drm_bridge *bridge, 894 const u8 *buffer, size_t len); 895 896 /** 897 * @hdmi_audio_startup: 898 * 899 * Called when ASoC starts an audio stream setup. 900 * 901 * This callback is optional, it can be implemented by bridges that 902 * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops. 903 * 904 * Returns: 905 * 0 on success, a negative error code otherwise 906 */ 907 int (*hdmi_audio_startup)(struct drm_bridge *bridge, 908 struct drm_connector *connector); 909 910 /** 911 * @hdmi_audio_prepare: 912 * Configures HDMI-encoder for audio stream. Can be called multiple 913 * times for each setup. 914 * 915 * This callback is optional but it must be implemented by bridges that 916 * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops. 917 * 918 * Returns: 919 * 0 on success, a negative error code otherwise 920 */ 921 int (*hdmi_audio_prepare)(struct drm_bridge *bridge, 922 struct drm_connector *connector, 923 struct hdmi_codec_daifmt *fmt, 924 struct hdmi_codec_params *hparms); 925 926 /** 927 * @hdmi_audio_shutdown: 928 * 929 * Shut down the audio stream. 930 * 931 * This callback is optional but it must be implemented by bridges that 932 * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops. 933 * 934 * Returns: 935 * 0 on success, a negative error code otherwise 936 */ 937 void (*hdmi_audio_shutdown)(struct drm_bridge *bridge, 938 struct drm_connector *connector); 939 940 /** 941 * @hdmi_audio_mute_stream: 942 * 943 * Mute/unmute HDMI audio stream. 944 * 945 * This callback is optional, it can be implemented by bridges that 946 * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops. 947 * 948 * Returns: 949 * 0 on success, a negative error code otherwise 950 */ 951 int (*hdmi_audio_mute_stream)(struct drm_bridge *bridge, 952 struct drm_connector *connector, 953 bool enable, int direction); 954 955 /** 956 * @hdmi_cec_init: 957 * 958 * Initialize CEC part of the bridge. 959 * 960 * This callback is optional, it can be implemented by bridges that 961 * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their 962 * &drm_bridge->ops. 963 * 964 * Returns: 965 * 0 on success, a negative error code otherwise 966 */ 967 int (*hdmi_cec_init)(struct drm_bridge *bridge, 968 struct drm_connector *connector); 969 970 /** 971 * @hdmi_cec_enable: 972 * 973 * Enable or disable the CEC adapter inside the bridge. 974 * 975 * This callback is optional, it can be implemented by bridges that 976 * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their 977 * &drm_bridge->ops. 978 * 979 * Returns: 980 * 0 on success, a negative error code otherwise 981 */ 982 int (*hdmi_cec_enable)(struct drm_bridge *bridge, bool enable); 983 984 /** 985 * @hdmi_cec_log_addr: 986 * 987 * Set the logical address of the CEC adapter inside the bridge. 988 * 989 * This callback is optional, it can be implemented by bridges that 990 * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their 991 * &drm_bridge->ops. 992 * 993 * Returns: 994 * 0 on success, a negative error code otherwise 995 */ 996 int (*hdmi_cec_log_addr)(struct drm_bridge *bridge, u8 logical_addr); 997 998 /** 999 * @hdmi_cec_transmit: 1000 * 1001 * Transmit the message using the CEC adapter inside the bridge. 1002 * 1003 * This callback is optional, it can be implemented by bridges that 1004 * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their 1005 * &drm_bridge->ops. 1006 * 1007 * Returns: 1008 * 0 on success, a negative error code otherwise 1009 */ 1010 int (*hdmi_cec_transmit)(struct drm_bridge *bridge, u8 attempts, 1011 u32 signal_free_time, struct cec_msg *msg); 1012 1013 /** 1014 * @dp_audio_startup: 1015 * 1016 * Called when ASoC starts a DisplayPort audio stream setup. 1017 * 1018 * This callback is optional, it can be implemented by bridges that 1019 * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops. 1020 * 1021 * Returns: 1022 * 0 on success, a negative error code otherwise 1023 */ 1024 int (*dp_audio_startup)(struct drm_bridge *bridge, 1025 struct drm_connector *connector); 1026 1027 /** 1028 * @dp_audio_prepare: 1029 * Configures DisplayPort audio stream. Can be called multiple 1030 * times for each setup. 1031 * 1032 * This callback is optional but it must be implemented by bridges that 1033 * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops. 1034 * 1035 * Returns: 1036 * 0 on success, a negative error code otherwise 1037 */ 1038 int (*dp_audio_prepare)(struct drm_bridge *bridge, 1039 struct drm_connector *connector, 1040 struct hdmi_codec_daifmt *fmt, 1041 struct hdmi_codec_params *hparms); 1042 1043 /** 1044 * @dp_audio_shutdown: 1045 * 1046 * Shut down the DisplayPort audio stream. 1047 * 1048 * This callback is optional but it must be implemented by bridges that 1049 * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops. 1050 * 1051 * Returns: 1052 * 0 on success, a negative error code otherwise 1053 */ 1054 void (*dp_audio_shutdown)(struct drm_bridge *bridge, 1055 struct drm_connector *connector); 1056 1057 /** 1058 * @dp_audio_mute_stream: 1059 * 1060 * Mute/unmute DisplayPort audio stream. 1061 * 1062 * This callback is optional, it can be implemented by bridges that 1063 * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops. 1064 * 1065 * Returns: 1066 * 0 on success, a negative error code otherwise 1067 */ 1068 int (*dp_audio_mute_stream)(struct drm_bridge *bridge, 1069 struct drm_connector *connector, 1070 bool enable, int direction); 1071 1072 /** 1073 * @debugfs_init: 1074 * 1075 * Allows bridges to create bridge-specific debugfs files. 1076 */ 1077 void (*debugfs_init)(struct drm_bridge *bridge, struct dentry *root); 1078 }; 1079 1080 /** 1081 * struct drm_bridge_timings - timing information for the bridge 1082 */ 1083 struct drm_bridge_timings { 1084 /** 1085 * @input_bus_flags: 1086 * 1087 * Tells what additional settings for the pixel data on the bus 1088 * this bridge requires (like pixel signal polarity). See also 1089 * &drm_display_info->bus_flags. 1090 */ 1091 u32 input_bus_flags; 1092 /** 1093 * @setup_time_ps: 1094 * 1095 * Defines the time in picoseconds the input data lines must be 1096 * stable before the clock edge. 1097 */ 1098 u32 setup_time_ps; 1099 /** 1100 * @hold_time_ps: 1101 * 1102 * Defines the time in picoseconds taken for the bridge to sample the 1103 * input signal after the clock edge. 1104 */ 1105 u32 hold_time_ps; 1106 /** 1107 * @dual_link: 1108 * 1109 * True if the bus operates in dual-link mode. The exact meaning is 1110 * dependent on the bus type. For LVDS buses, this indicates that even- 1111 * and odd-numbered pixels are received on separate links. 1112 */ 1113 bool dual_link; 1114 }; 1115 1116 /** 1117 * enum drm_bridge_ops - Bitmask of operations supported by the bridge 1118 */ 1119 enum drm_bridge_ops { 1120 /** 1121 * @DRM_BRIDGE_OP_DETECT: The bridge can detect displays connected to 1122 * its output. Bridges that set this flag shall implement the 1123 * &drm_bridge_funcs->detect callback. 1124 */ 1125 DRM_BRIDGE_OP_DETECT = BIT(0), 1126 /** 1127 * @DRM_BRIDGE_OP_EDID: The bridge can retrieve the EDID of the display 1128 * connected to its output. Bridges that set this flag shall implement 1129 * the &drm_bridge_funcs->edid_read callback. 1130 */ 1131 DRM_BRIDGE_OP_EDID = BIT(1), 1132 /** 1133 * @DRM_BRIDGE_OP_HPD: The bridge can detect hot-plug and hot-unplug 1134 * without requiring polling. Bridges that set this flag shall 1135 * implement the &drm_bridge_funcs->hpd_enable and 1136 * &drm_bridge_funcs->hpd_disable callbacks if they support enabling 1137 * and disabling hot-plug detection dynamically. 1138 */ 1139 DRM_BRIDGE_OP_HPD = BIT(2), 1140 /** 1141 * @DRM_BRIDGE_OP_MODES: The bridge can retrieve the modes supported 1142 * by the display at its output. This does not include reading EDID 1143 * which is separately covered by @DRM_BRIDGE_OP_EDID. Bridges that set 1144 * this flag shall implement the &drm_bridge_funcs->get_modes callback. 1145 */ 1146 DRM_BRIDGE_OP_MODES = BIT(3), 1147 /** 1148 * @DRM_BRIDGE_OP_HDMI: The bridge provides HDMI connector operations, 1149 * including infoframes support. Bridges that set this flag must 1150 * provide HDMI-related information and implement the 1151 * &drm_bridge_funcs->clear_avi_infoframe, 1152 * &drm_bridge_funcs->write_avi_infoframe, 1153 * &drm_bridge_funcs->clear_hdmi_infoframe and 1154 * &drm_bridge_funcs->write_hdmi_infoframe callbacks. 1155 * 1156 * Note: currently there can be at most one bridge in a chain that sets 1157 * this bit. This is to simplify corresponding glue code in connector 1158 * drivers. 1159 */ 1160 DRM_BRIDGE_OP_HDMI = BIT(4), 1161 /** 1162 * @DRM_BRIDGE_OP_HDMI_AUDIO: The bridge provides HDMI audio operations. 1163 * Bridges that set this flag must implement the 1164 * &drm_bridge_funcs->hdmi_audio_prepare and 1165 * &drm_bridge_funcs->hdmi_audio_shutdown callbacks. 1166 * If the bridge implements @DRM_BRIDGE_OP_HDMI, it also must implement 1167 * &drm_bridge_funcs->hdmi_write_audio_infoframe and 1168 * &drm_bridge_funcs->hdmi_cleaer_audio_infoframe callbacks. 1169 * 1170 * Note: currently there can be at most one bridge in a chain that sets 1171 * this bit. This is to simplify corresponding glue code in connector 1172 * drivers. Also it is not possible to have a bridge in the chain that 1173 * sets @DRM_BRIDGE_OP_DP_AUDIO if there is a bridge that sets this 1174 * flag. 1175 */ 1176 DRM_BRIDGE_OP_HDMI_AUDIO = BIT(5), 1177 /** 1178 * @DRM_BRIDGE_OP_DP_AUDIO: The bridge provides DisplayPort audio operations. 1179 * Bridges that set this flag must implement the 1180 * &drm_bridge_funcs->dp_audio_prepare and 1181 * &drm_bridge_funcs->dp_audio_shutdown callbacks. 1182 * 1183 * Note: currently there can be at most one bridge in a chain that sets 1184 * this bit. This is to simplify corresponding glue code in connector 1185 * drivers. Also it is not possible to have a bridge in the chain that 1186 * sets @DRM_BRIDGE_OP_HDMI_AUDIO if there is a bridge that sets this 1187 * flag. 1188 */ 1189 DRM_BRIDGE_OP_DP_AUDIO = BIT(6), 1190 /** 1191 * @DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER: The bridge requires CEC notifier 1192 * to be present. 1193 */ 1194 DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER = BIT(7), 1195 /** 1196 * @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER: The bridge requires CEC adapter 1197 * to be present. 1198 */ 1199 DRM_BRIDGE_OP_HDMI_CEC_ADAPTER = BIT(8), 1200 /** 1201 * @DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME: The bridge supports 1202 * &drm_bridge_funcs->hdmi_write_hdr_drm_infoframe and 1203 * &drm_bridge_funcs->hdmi_clear_hdr_drm_infoframe callbacks. 1204 */ 1205 DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME = BIT(9), 1206 /** 1207 * @DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME: The bridge supports 1208 * &drm_bridge_funcs->hdmi_write_spd_infoframe and 1209 * &drm_bridge_funcs->hdmi_clear_spd_infoframe callbacks. 1210 */ 1211 DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME = BIT(10), 1212 }; 1213 1214 /** 1215 * struct drm_bridge - central DRM bridge control structure 1216 */ 1217 struct drm_bridge { 1218 /** @base: inherit from &drm_private_object */ 1219 struct drm_private_obj base; 1220 /** @dev: DRM device this bridge belongs to */ 1221 struct drm_device *dev; 1222 /** @encoder: encoder to which this bridge is connected */ 1223 struct drm_encoder *encoder; 1224 /** @chain_node: used to form a bridge chain */ 1225 struct list_head chain_node; 1226 /** @of_node: device node pointer to the bridge */ 1227 struct device_node *of_node; 1228 /** @list: to keep track of all added bridges */ 1229 struct list_head list; 1230 /** 1231 * @timings: 1232 * 1233 * the timing specification for the bridge, if any (may be NULL) 1234 */ 1235 const struct drm_bridge_timings *timings; 1236 /** @funcs: control functions */ 1237 const struct drm_bridge_funcs *funcs; 1238 1239 /** 1240 * @container: Pointer to the private driver struct embedding this 1241 * @struct drm_bridge. 1242 */ 1243 void *container; 1244 1245 /** 1246 * @refcount: reference count of users referencing this bridge. 1247 */ 1248 struct kref refcount; 1249 1250 /** 1251 * @unplugged: 1252 * 1253 * Flag to tell if the bridge has been unplugged. 1254 * See drm_bridge_enter() and drm_bridge_unplug(). 1255 */ 1256 bool unplugged; 1257 1258 /** @driver_private: pointer to the bridge driver's internal context */ 1259 void *driver_private; 1260 /** @ops: bitmask of operations supported by the bridge */ 1261 enum drm_bridge_ops ops; 1262 /** 1263 * @type: Type of the connection at the bridge output 1264 * (DRM_MODE_CONNECTOR_*). For bridges at the end of this chain this 1265 * identifies the type of connected display. 1266 */ 1267 int type; 1268 /** 1269 * @interlace_allowed: Indicate that the bridge can handle interlaced 1270 * modes. 1271 */ 1272 bool interlace_allowed; 1273 /** 1274 * @ycbcr_420_allowed: Indicate that the bridge can handle YCbCr 420 1275 * output. 1276 */ 1277 bool ycbcr_420_allowed; 1278 /** 1279 * @pre_enable_prev_first: The bridge requires that the prev 1280 * bridge @pre_enable function is called before its @pre_enable, 1281 * and conversely for post_disable. This is most frequently a 1282 * requirement for DSI devices which need the host to be initialised 1283 * before the peripheral. 1284 */ 1285 bool pre_enable_prev_first; 1286 /** 1287 * @support_hdcp: Indicate that the bridge supports HDCP. 1288 */ 1289 bool support_hdcp; 1290 /** 1291 * @ddc: Associated I2C adapter for DDC access, if any. 1292 */ 1293 struct i2c_adapter *ddc; 1294 1295 /** 1296 * @vendor: Vendor of the product to be used for the SPD InfoFrame 1297 * generation. This is required if @DRM_BRIDGE_OP_HDMI is set. 1298 */ 1299 const char *vendor; 1300 1301 /** 1302 * @product: Name of the product to be used for the SPD InfoFrame 1303 * generation. This is required if @DRM_BRIDGE_OP_HDMI is set. 1304 */ 1305 const char *product; 1306 1307 /** 1308 * @supported_formats: Bitmask of @hdmi_colorspace listing supported 1309 * output formats. This is only relevant if @DRM_BRIDGE_OP_HDMI is set. 1310 */ 1311 unsigned int supported_formats; 1312 1313 /** 1314 * @max_bpc: Maximum bits per char the HDMI bridge supports. Allowed 1315 * values are 8, 10 and 12. This is only relevant if 1316 * @DRM_BRIDGE_OP_HDMI is set. 1317 */ 1318 unsigned int max_bpc; 1319 1320 /** 1321 * @hdmi_cec_dev: device to be used as a containing device for CEC 1322 * functions. 1323 */ 1324 struct device *hdmi_cec_dev; 1325 1326 /** 1327 * @hdmi_audio_dev: device to be used as a parent for the HDMI Codec if 1328 * either of @DRM_BRIDGE_OP_HDMI_AUDIO or @DRM_BRIDGE_OP_DP_AUDIO is set. 1329 */ 1330 struct device *hdmi_audio_dev; 1331 1332 /** 1333 * @hdmi_audio_max_i2s_playback_channels: maximum number of playback 1334 * I2S channels for the @DRM_BRIDGE_OP_HDMI_AUDIO or 1335 * @DRM_BRIDGE_OP_DP_AUDIO. 1336 */ 1337 int hdmi_audio_max_i2s_playback_channels; 1338 1339 /** 1340 * @hdmi_audio_i2s_formats: supported I2S formats, optional. The 1341 * default is to allow all formats supported by the corresponding I2S 1342 * bus driver. This is only used for bridges setting 1343 * @DRM_BRIDGE_OP_HDMI_AUDIO or @DRM_BRIDGE_OP_DP_AUDIO. 1344 */ 1345 u64 hdmi_audio_i2s_formats; 1346 1347 /** 1348 * @hdmi_audio_spdif_playback: set if this bridge has S/PDIF playback 1349 * port for @DRM_BRIDGE_OP_HDMI_AUDIO or @DRM_BRIDGE_OP_DP_AUDIO. 1350 */ 1351 unsigned int hdmi_audio_spdif_playback : 1; 1352 1353 /** 1354 * @hdmi_audio_dai_port: sound DAI port for either of 1355 * @DRM_BRIDGE_OP_HDMI_AUDIO and @DRM_BRIDGE_OP_DP_AUDIO, -1 if it is 1356 * not used. 1357 */ 1358 int hdmi_audio_dai_port; 1359 1360 /** 1361 * @hdmi_cec_adapter_name: the name of the adapter to register 1362 */ 1363 const char *hdmi_cec_adapter_name; 1364 1365 /** 1366 * @hdmi_cec_available_las: number of logical addresses, CEC_MAX_LOG_ADDRS if unset 1367 */ 1368 u8 hdmi_cec_available_las; 1369 1370 /** private: */ 1371 /** 1372 * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields. 1373 */ 1374 struct mutex hpd_mutex; 1375 /** 1376 * @hpd_cb: Hot plug detection callback, registered with 1377 * drm_bridge_hpd_enable(). 1378 */ 1379 void (*hpd_cb)(void *data, enum drm_connector_status status); 1380 /** 1381 * @hpd_data: Private data passed to the Hot plug detection callback 1382 * @hpd_cb. 1383 */ 1384 void *hpd_data; 1385 1386 /** 1387 * @next_bridge: Pointer to the following bridge, automatically put 1388 * when this bridge is freed (i.e. at destroy time). This is for 1389 * drivers needing to store a pointer to the next bridge in the 1390 * chain, and ensures any code still holding a reference to this 1391 * bridge after its removal cannot use-after-free the next 1392 * bridge. Any other bridge pointers stored by the driver must be 1393 * put in the .destroy callback by driver code. 1394 */ 1395 struct drm_bridge *next_bridge; 1396 }; 1397 1398 static inline struct drm_bridge * 1399 drm_priv_to_bridge(struct drm_private_obj *priv) 1400 { 1401 return container_of(priv, struct drm_bridge, base); 1402 } 1403 1404 bool drm_bridge_enter(struct drm_bridge *bridge, int *idx); 1405 void drm_bridge_exit(int idx); 1406 void drm_bridge_unplug(struct drm_bridge *bridge); 1407 1408 struct drm_bridge *drm_bridge_get(struct drm_bridge *bridge); 1409 void drm_bridge_put(struct drm_bridge *bridge); 1410 1411 /* Cleanup action for use with __free() */ 1412 DEFINE_FREE(drm_bridge_put, struct drm_bridge *, if (_T) drm_bridge_put(_T)) 1413 1414 void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offset, 1415 const struct drm_bridge_funcs *funcs); 1416 1417 /** 1418 * devm_drm_bridge_alloc - Allocate and initialize a bridge 1419 * @dev: struct device of the bridge device 1420 * @type: the type of the struct which contains struct &drm_bridge 1421 * @member: the name of the &drm_bridge within @type 1422 * @funcs: callbacks for this bridge 1423 * 1424 * The reference count of the returned bridge is initialized to 1. This 1425 * reference will be automatically dropped via devm (by calling 1426 * drm_bridge_put()) when @dev is removed. 1427 * 1428 * Returns: 1429 * Pointer to new bridge, or ERR_PTR on failure. 1430 */ 1431 #define devm_drm_bridge_alloc(dev, type, member, funcs) \ 1432 ((type *)__devm_drm_bridge_alloc(dev, sizeof(type), \ 1433 offsetof(type, member), funcs)) 1434 1435 void drm_bridge_add(struct drm_bridge *bridge); 1436 int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge); 1437 void drm_bridge_remove(struct drm_bridge *bridge); 1438 int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge, 1439 struct drm_bridge *previous, 1440 enum drm_bridge_attach_flags flags); 1441 1442 #ifdef CONFIG_OF 1443 struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np); 1444 struct drm_bridge *of_drm_find_bridge(struct device_node *np); 1445 #else 1446 static inline struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np) 1447 { 1448 return NULL; 1449 } 1450 static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np) 1451 { 1452 return NULL; 1453 } 1454 #endif 1455 1456 static inline bool drm_bridge_is_last(struct drm_bridge *bridge) 1457 { 1458 return list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain); 1459 } 1460 1461 /** 1462 * drm_bridge_get_current_state() - Get the current bridge state 1463 * @bridge: bridge object 1464 * 1465 * This function must be called with the modeset lock held. 1466 * 1467 * RETURNS: 1468 * 1469 * The current bridge state, or NULL if there is none. 1470 */ 1471 static inline struct drm_bridge_state * 1472 drm_bridge_get_current_state(struct drm_bridge *bridge) 1473 { 1474 if (!bridge) 1475 return NULL; 1476 1477 /* 1478 * Only atomic bridges will have bridge->base initialized by 1479 * drm_atomic_private_obj_init(), so we need to make sure we're 1480 * working with one before we try to use the lock. 1481 */ 1482 if (!bridge->funcs || !bridge->funcs->atomic_reset) 1483 return NULL; 1484 1485 drm_modeset_lock_assert_held(&bridge->base.lock); 1486 1487 if (!bridge->base.state) 1488 return NULL; 1489 1490 return drm_priv_to_bridge_state(bridge->base.state); 1491 } 1492 1493 /** 1494 * drm_bridge_get_next_bridge() - Get the next bridge in the chain 1495 * @bridge: bridge object 1496 * 1497 * The caller is responsible of having a reference to @bridge via 1498 * drm_bridge_get() or equivalent. This function leaves the refcount of 1499 * @bridge unmodified. 1500 * 1501 * The refcount of the returned bridge is incremented. Use drm_bridge_put() 1502 * when done with it. 1503 * 1504 * RETURNS: 1505 * the next bridge in the chain after @bridge, or NULL if @bridge is the last. 1506 */ 1507 static inline struct drm_bridge * 1508 drm_bridge_get_next_bridge(struct drm_bridge *bridge) 1509 { 1510 if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain)) 1511 return NULL; 1512 1513 return drm_bridge_get(list_next_entry(bridge, chain_node)); 1514 } 1515 1516 /** 1517 * drm_bridge_get_prev_bridge() - Get the previous bridge in the chain 1518 * @bridge: bridge object 1519 * 1520 * The caller is responsible of having a reference to @bridge via 1521 * drm_bridge_get() or equivalent. This function leaves the refcount of 1522 * @bridge unmodified. 1523 * 1524 * The refcount of the returned bridge is incremented. Use drm_bridge_put() 1525 * when done with it. 1526 * 1527 * RETURNS: 1528 * the previous bridge in the chain, or NULL if @bridge is the first. 1529 */ 1530 static inline struct drm_bridge * 1531 drm_bridge_get_prev_bridge(struct drm_bridge *bridge) 1532 { 1533 if (list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain)) 1534 return NULL; 1535 1536 return drm_bridge_get(list_prev_entry(bridge, chain_node)); 1537 } 1538 1539 /** 1540 * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain 1541 * @encoder: encoder object 1542 * 1543 * The refcount of the returned bridge is incremented. Use drm_bridge_put() 1544 * when done with it. 1545 * 1546 * RETURNS: 1547 * the first bridge in the chain, or NULL if @encoder has no bridge attached 1548 * to it. 1549 */ 1550 static inline struct drm_bridge * 1551 drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder) 1552 { 1553 return drm_bridge_get(list_first_entry_or_null(&encoder->bridge_chain, 1554 struct drm_bridge, chain_node)); 1555 } 1556 1557 /** 1558 * drm_bridge_chain_get_last_bridge() - Get the last bridge in the chain 1559 * @encoder: encoder object 1560 * 1561 * The refcount of the returned bridge is incremented. Use drm_bridge_put() 1562 * when done with it. 1563 * 1564 * RETURNS: 1565 * the last bridge in the chain, or NULL if @encoder has no bridge attached 1566 * to it. 1567 */ 1568 static inline struct drm_bridge * 1569 drm_bridge_chain_get_last_bridge(struct drm_encoder *encoder) 1570 { 1571 return drm_bridge_get(list_last_entry_or_null(&encoder->bridge_chain, 1572 struct drm_bridge, chain_node)); 1573 } 1574 1575 /** 1576 * drm_bridge_get_next_bridge_and_put - Get the next bridge in the chain 1577 * and put the previous 1578 * @bridge: bridge object 1579 * 1580 * Same as drm_bridge_get_next_bridge() but additionally puts the @bridge. 1581 * 1582 * RETURNS: 1583 * the next bridge in the chain after @bridge, or NULL if @bridge is the last. 1584 */ 1585 static inline struct drm_bridge * 1586 drm_bridge_get_next_bridge_and_put(struct drm_bridge *bridge) 1587 { 1588 struct drm_bridge *next = drm_bridge_get_next_bridge(bridge); 1589 1590 drm_bridge_put(bridge); 1591 1592 return next; 1593 } 1594 1595 /** 1596 * drm_for_each_bridge_in_chain_scoped - iterate over all bridges attached 1597 * to an encoder 1598 * @encoder: the encoder to iterate bridges on 1599 * @bridge: a bridge pointer updated to point to the current bridge at each 1600 * iteration 1601 * 1602 * Iterate over all bridges present in the bridge chain attached to @encoder. 1603 * 1604 * Automatically gets/puts the bridge reference while iterating, and puts 1605 * the reference even if returning or breaking in the middle of the loop. 1606 */ 1607 #define drm_for_each_bridge_in_chain_scoped(encoder, bridge) \ 1608 for (struct drm_bridge *bridge __free(drm_bridge_put) = \ 1609 drm_bridge_chain_get_first_bridge(encoder); \ 1610 bridge; \ 1611 bridge = drm_bridge_get_next_bridge_and_put(bridge)) 1612 1613 /** 1614 * drm_for_each_bridge_in_chain_from - iterate over all bridges starting 1615 * from the given bridge 1616 * @first_bridge: the bridge to start from 1617 * @bridge: a bridge pointer updated to point to the current bridge at each 1618 * iteration 1619 * 1620 * Iterate over all bridges in the encoder chain starting from 1621 * @first_bridge, included. 1622 * 1623 * Automatically gets/puts the bridge reference while iterating, and puts 1624 * the reference even if returning or breaking in the middle of the loop. 1625 */ 1626 #define drm_for_each_bridge_in_chain_from(first_bridge, bridge) \ 1627 for (struct drm_bridge *bridge __free(drm_bridge_put) = \ 1628 drm_bridge_get(first_bridge); \ 1629 bridge; \ 1630 bridge = drm_bridge_get_next_bridge_and_put(bridge)) 1631 1632 enum drm_mode_status 1633 drm_bridge_chain_mode_valid(struct drm_bridge *bridge, 1634 const struct drm_display_info *info, 1635 const struct drm_display_mode *mode); 1636 void drm_bridge_chain_mode_set(struct drm_bridge *bridge, 1637 const struct drm_display_mode *mode, 1638 const struct drm_display_mode *adjusted_mode); 1639 1640 int drm_atomic_bridge_chain_check(struct drm_bridge *bridge, 1641 struct drm_crtc_state *crtc_state, 1642 struct drm_connector_state *conn_state); 1643 void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge, 1644 struct drm_atomic_state *state); 1645 void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge, 1646 struct drm_atomic_state *state); 1647 void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge, 1648 struct drm_atomic_state *state); 1649 void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge, 1650 struct drm_atomic_state *state); 1651 1652 u32 * 1653 drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge, 1654 struct drm_bridge_state *bridge_state, 1655 struct drm_crtc_state *crtc_state, 1656 struct drm_connector_state *conn_state, 1657 u32 output_fmt, 1658 unsigned int *num_input_fmts); 1659 1660 enum drm_connector_status 1661 drm_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connector); 1662 int drm_bridge_get_modes(struct drm_bridge *bridge, 1663 struct drm_connector *connector); 1664 const struct drm_edid *drm_bridge_edid_read(struct drm_bridge *bridge, 1665 struct drm_connector *connector); 1666 void drm_bridge_hpd_enable(struct drm_bridge *bridge, 1667 void (*cb)(void *data, 1668 enum drm_connector_status status), 1669 void *data); 1670 void drm_bridge_hpd_disable(struct drm_bridge *bridge); 1671 void drm_bridge_hpd_notify(struct drm_bridge *bridge, 1672 enum drm_connector_status status); 1673 1674 #ifdef CONFIG_DRM_PANEL_BRIDGE 1675 bool drm_bridge_is_panel(const struct drm_bridge *bridge); 1676 struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel); 1677 struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel, 1678 u32 connector_type); 1679 void drm_panel_bridge_remove(struct drm_bridge *bridge); 1680 int drm_panel_bridge_set_orientation(struct drm_connector *connector, 1681 struct drm_bridge *bridge); 1682 struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev, 1683 struct drm_panel *panel); 1684 struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev, 1685 struct drm_panel *panel, 1686 u32 connector_type); 1687 struct drm_bridge *drmm_panel_bridge_add(struct drm_device *drm, 1688 struct drm_panel *panel); 1689 struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge); 1690 #else 1691 static inline bool drm_bridge_is_panel(const struct drm_bridge *bridge) 1692 { 1693 return false; 1694 } 1695 1696 static inline int drm_panel_bridge_set_orientation(struct drm_connector *connector, 1697 struct drm_bridge *bridge) 1698 { 1699 return -EINVAL; 1700 } 1701 #endif 1702 1703 #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL_BRIDGE) 1704 struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, struct device_node *node, 1705 u32 port, u32 endpoint); 1706 struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm, struct device_node *node, 1707 u32 port, u32 endpoint); 1708 #else 1709 static inline struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, 1710 struct device_node *node, 1711 u32 port, 1712 u32 endpoint) 1713 { 1714 return ERR_PTR(-ENODEV); 1715 } 1716 1717 static inline struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm, 1718 struct device_node *node, 1719 u32 port, 1720 u32 endpoint) 1721 { 1722 return ERR_PTR(-ENODEV); 1723 } 1724 #endif 1725 1726 void devm_drm_put_bridge(struct device *dev, struct drm_bridge *bridge); 1727 1728 void drm_bridge_debugfs_params(struct dentry *root); 1729 void drm_bridge_debugfs_encoder_params(struct dentry *root, struct drm_encoder *encoder); 1730 1731 #endif 1732