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