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