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