1033 lines · c
1/*2 * Copyright (c) 2016 Intel Corporation3 *4 * Permission to use, copy, modify, distribute, and sell this software and its5 * documentation for any purpose is hereby granted without fee, provided that6 * the above copyright notice appear in all copies and that both that copyright7 * notice and this permission notice appear in supporting documentation, and8 * that the name of the copyright holders not be used in advertising or9 * publicity pertaining to distribution of the software without specific,10 * written prior permission. The copyright holders make no representations11 * about the suitability of this software for any purpose. It is provided "as12 * 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 NO16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE20 * 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 35struct device_node;36 37struct drm_bridge;38struct drm_bridge_timings;39struct drm_connector;40struct drm_display_info;41struct drm_minor;42struct drm_panel;43struct edid;44struct i2c_adapter;45 46/**47 * enum drm_bridge_attach_flags - Flags for &drm_bridge_funcs.attach48 */49enum drm_bridge_attach_flags {50 /**51 * @DRM_BRIDGE_ATTACH_NO_CONNECTOR: When this flag is set the bridge52 * shall not create a drm_connector.53 */54 DRM_BRIDGE_ATTACH_NO_CONNECTOR = BIT(0),55};56 57/**58 * struct drm_bridge_funcs - drm_bridge control functions59 */60struct drm_bridge_funcs {61 /**62 * @attach:63 *64 * This callback is invoked whenever our bridge is being attached to a65 * &drm_encoder. The flags argument tunes the behaviour of the attach66 * operation (see DRM_BRIDGE_ATTACH_*).67 *68 * The @attach callback is optional.69 *70 * RETURNS:71 *72 * Zero on success, error code on failure.73 */74 int (*attach)(struct drm_bridge *bridge,75 enum drm_bridge_attach_flags flags);76 77 /**78 * @detach:79 *80 * This callback is invoked whenever our bridge is being detached from a81 * &drm_encoder.82 *83 * The @detach callback is optional.84 */85 void (*detach)(struct drm_bridge *bridge);86 87 /**88 * @mode_valid:89 *90 * This callback is used to check if a specific mode is valid in this91 * bridge. This should be implemented if the bridge has some sort of92 * restriction in the modes it can display. For example, a given bridge93 * may be responsible to set a clock value. If the clock can not94 * produce all the values for the available modes then this callback95 * can be used to restrict the number of modes to only the ones that96 * can be displayed.97 *98 * This hook is used by the probe helpers to filter the mode list in99 * drm_helper_probe_single_connector_modes(), and it is used by the100 * atomic helpers to validate modes supplied by userspace in101 * drm_atomic_helper_check_modeset().102 *103 * The @mode_valid callback is optional.104 *105 * NOTE:106 *107 * Since this function is both called from the check phase of an atomic108 * commit, and the mode validation in the probe paths it is not allowed109 * to look at anything else but the passed-in mode, and validate it110 * against configuration-invariant hardware constraints. Any further111 * limits which depend upon the configuration can only be checked in112 * @mode_fixup.113 *114 * RETURNS:115 *116 * drm_mode_status Enum117 */118 enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge,119 const struct drm_display_info *info,120 const struct drm_display_mode *mode);121 122 /**123 * @mode_fixup:124 *125 * This callback is used to validate and adjust a mode. The parameter126 * mode is the display mode that should be fed to the next element in127 * the display chain, either the final &drm_connector or the next128 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge129 * requires. It can be modified by this callback and does not need to130 * match mode. See also &drm_crtc_state.adjusted_mode for more details.131 *132 * This is the only hook that allows a bridge to reject a modeset. If133 * this function passes all other callbacks must succeed for this134 * configuration.135 *136 * The mode_fixup callback is optional. &drm_bridge_funcs.mode_fixup()137 * is not called when &drm_bridge_funcs.atomic_check() is implemented,138 * so only one of them should be provided.139 *140 * NOTE:141 *142 * This function is called in the check phase of atomic modesets, which143 * can be aborted for any reason (including on userspace's request to144 * just check whether a configuration would be possible). Drivers MUST145 * NOT touch any persistent state (hardware or software) or data146 * structures except the passed in @state parameter.147 *148 * Also beware that userspace can request its own custom modes, neither149 * core nor helpers filter modes to the list of probe modes reported by150 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure151 * that modes are filtered consistently put any bridge constraints and152 * limits checks into @mode_valid.153 *154 * RETURNS:155 *156 * True if an acceptable configuration is possible, false if the modeset157 * operation should be rejected.158 */159 bool (*mode_fixup)(struct drm_bridge *bridge,160 const struct drm_display_mode *mode,161 struct drm_display_mode *adjusted_mode);162 /**163 * @disable:164 *165 * This callback should disable the bridge. It is called right before166 * the preceding element in the display pipe is disabled. If the167 * preceding element is a bridge this means it's called before that168 * bridge's @disable vfunc. If the preceding element is a &drm_encoder169 * it's called right before the &drm_encoder_helper_funcs.disable,170 * &drm_encoder_helper_funcs.prepare or &drm_encoder_helper_funcs.dpms171 * hook.172 *173 * The bridge can assume that the display pipe (i.e. clocks and timing174 * signals) feeding it is still running when this callback is called.175 *176 * The @disable callback is optional.177 *178 * NOTE:179 *180 * This is deprecated, do not use!181 * New drivers shall use &drm_bridge_funcs.atomic_disable.182 */183 void (*disable)(struct drm_bridge *bridge);184 185 /**186 * @post_disable:187 *188 * This callback should disable the bridge. It is called right after the189 * preceding element in the display pipe is disabled. If the preceding190 * element is a bridge this means it's called after that bridge's191 * @post_disable function. If the preceding element is a &drm_encoder192 * it's called right after the encoder's193 * &drm_encoder_helper_funcs.disable, &drm_encoder_helper_funcs.prepare194 * or &drm_encoder_helper_funcs.dpms hook.195 *196 * The bridge must assume that the display pipe (i.e. clocks and timing197 * signals) feeding it is no longer running when this callback is198 * called.199 *200 * The @post_disable callback is optional.201 *202 * NOTE:203 *204 * This is deprecated, do not use!205 * New drivers shall use &drm_bridge_funcs.atomic_post_disable.206 */207 void (*post_disable)(struct drm_bridge *bridge);208 209 /**210 * @mode_set:211 *212 * This callback should set the given mode on the bridge. It is called213 * after the @mode_set callback for the preceding element in the display214 * pipeline has been called already. If the bridge is the first element215 * then this would be &drm_encoder_helper_funcs.mode_set. The display216 * pipe (i.e. clocks and timing signals) is off when this function is217 * called.218 *219 * The adjusted_mode parameter is the mode output by the CRTC for the220 * first bridge in the chain. It can be different from the mode221 * parameter that contains the desired mode for the connector at the end222 * of the bridges chain, for instance when the first bridge in the chain223 * performs scaling. The adjusted mode is mostly useful for the first224 * bridge in the chain and is likely irrelevant for the other bridges.225 *226 * For atomic drivers the adjusted_mode is the mode stored in227 * &drm_crtc_state.adjusted_mode.228 *229 * NOTE:230 *231 * This is deprecated, do not use!232 * New drivers shall set their mode in the233 * &drm_bridge_funcs.atomic_enable operation.234 */235 void (*mode_set)(struct drm_bridge *bridge,236 const struct drm_display_mode *mode,237 const struct drm_display_mode *adjusted_mode);238 /**239 * @pre_enable:240 *241 * This callback should enable the bridge. It is called right before242 * the preceding element in the display pipe is enabled. If the243 * preceding element is a bridge this means it's called before that244 * bridge's @pre_enable function. If the preceding element is a245 * &drm_encoder it's called right before the encoder's246 * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or247 * &drm_encoder_helper_funcs.dpms hook.248 *249 * The display pipe (i.e. clocks and timing signals) feeding this bridge250 * will not yet be running when this callback is called. The bridge must251 * not enable the display link feeding the next bridge in the chain (if252 * there is one) when this callback is called.253 *254 * The @pre_enable callback is optional.255 *256 * NOTE:257 *258 * This is deprecated, do not use!259 * New drivers shall use &drm_bridge_funcs.atomic_pre_enable.260 */261 void (*pre_enable)(struct drm_bridge *bridge);262 263 /**264 * @enable:265 *266 * This callback should enable the bridge. It is called right after267 * the preceding element in the display pipe is enabled. If the268 * preceding element is a bridge this means it's called after that269 * bridge's @enable function. If the preceding element is a270 * &drm_encoder it's called right after the encoder's271 * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or272 * &drm_encoder_helper_funcs.dpms hook.273 *274 * The bridge can assume that the display pipe (i.e. clocks and timing275 * signals) feeding it is running when this callback is called. This276 * callback must enable the display link feeding the next bridge in the277 * chain if there is one.278 *279 * The @enable callback is optional.280 *281 * NOTE:282 *283 * This is deprecated, do not use!284 * New drivers shall use &drm_bridge_funcs.atomic_enable.285 */286 void (*enable)(struct drm_bridge *bridge);287 288 /**289 * @atomic_pre_enable:290 *291 * This callback should enable the bridge. It is called right before292 * the preceding element in the display pipe is enabled. If the293 * preceding element is a bridge this means it's called before that294 * bridge's @atomic_pre_enable or @pre_enable function. If the preceding295 * element is a &drm_encoder it's called right before the encoder's296 * &drm_encoder_helper_funcs.atomic_enable hook.297 *298 * The display pipe (i.e. clocks and timing signals) feeding this bridge299 * will not yet be running when this callback is called. The bridge must300 * not enable the display link feeding the next bridge in the chain (if301 * there is one) when this callback is called.302 *303 * The @atomic_pre_enable callback is optional.304 */305 void (*atomic_pre_enable)(struct drm_bridge *bridge,306 struct drm_bridge_state *old_bridge_state);307 308 /**309 * @atomic_enable:310 *311 * This callback should enable the bridge. It is called right after312 * the preceding element in the display pipe is enabled. If the313 * preceding element is a bridge this means it's called after that314 * bridge's @atomic_enable or @enable function. If the preceding element315 * is a &drm_encoder it's called right after the encoder's316 * &drm_encoder_helper_funcs.atomic_enable hook.317 *318 * The bridge can assume that the display pipe (i.e. clocks and timing319 * signals) feeding it is running when this callback is called. This320 * callback must enable the display link feeding the next bridge in the321 * chain if there is one.322 *323 * The @atomic_enable callback is optional.324 */325 void (*atomic_enable)(struct drm_bridge *bridge,326 struct drm_bridge_state *old_bridge_state);327 /**328 * @atomic_disable:329 *330 * This callback should disable the bridge. It is called right before331 * the preceding element in the display pipe is disabled. If the332 * preceding element is a bridge this means it's called before that333 * bridge's @atomic_disable or @disable vfunc. If the preceding element334 * is a &drm_encoder it's called right before the335 * &drm_encoder_helper_funcs.atomic_disable hook.336 *337 * The bridge can assume that the display pipe (i.e. clocks and timing338 * signals) feeding it is still running when this callback is called.339 *340 * The @atomic_disable callback is optional.341 */342 void (*atomic_disable)(struct drm_bridge *bridge,343 struct drm_bridge_state *old_bridge_state);344 345 /**346 * @atomic_post_disable:347 *348 * This callback should disable the bridge. It is called right after the349 * preceding element in the display pipe is disabled. If the preceding350 * element is a bridge this means it's called after that bridge's351 * @atomic_post_disable or @post_disable function. If the preceding352 * element is a &drm_encoder it's called right after the encoder's353 * &drm_encoder_helper_funcs.atomic_disable hook.354 *355 * The bridge must assume that the display pipe (i.e. clocks and timing356 * signals) feeding it is no longer running when this callback is357 * called.358 *359 * The @atomic_post_disable callback is optional.360 */361 void (*atomic_post_disable)(struct drm_bridge *bridge,362 struct drm_bridge_state *old_bridge_state);363 364 /**365 * @atomic_duplicate_state:366 *367 * Duplicate the current bridge state object (which is guaranteed to be368 * non-NULL).369 *370 * The atomic_duplicate_state hook is mandatory if the bridge371 * implements any of the atomic hooks, and should be left unassigned372 * otherwise. For bridges that don't subclass &drm_bridge_state, the373 * drm_atomic_helper_bridge_duplicate_state() helper function shall be374 * used to implement this hook.375 *376 * RETURNS:377 * A valid drm_bridge_state object or NULL if the allocation fails.378 */379 struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge);380 381 /**382 * @atomic_destroy_state:383 *384 * Destroy a bridge state object previously allocated by385 * &drm_bridge_funcs.atomic_duplicate_state().386 *387 * The atomic_destroy_state hook is mandatory if the bridge implements388 * any of the atomic hooks, and should be left unassigned otherwise.389 * For bridges that don't subclass &drm_bridge_state, the390 * drm_atomic_helper_bridge_destroy_state() helper function shall be391 * used to implement this hook.392 */393 void (*atomic_destroy_state)(struct drm_bridge *bridge,394 struct drm_bridge_state *state);395 396 /**397 * @atomic_get_output_bus_fmts:398 *399 * Return the supported bus formats on the output end of a bridge.400 * The returned array must be allocated with kmalloc() and will be401 * freed by the caller. If the allocation fails, NULL should be402 * returned. num_output_fmts must be set to the returned array size.403 * Formats listed in the returned array should be listed in decreasing404 * preference order (the core will try all formats until it finds one405 * that works).406 *407 * This method is only called on the last element of the bridge chain408 * as part of the bus format negotiation process that happens in409 * &drm_atomic_bridge_chain_select_bus_fmts().410 * This method is optional. When not implemented, the core will411 * fall back to &drm_connector.display_info.bus_formats[0] if412 * &drm_connector.display_info.num_bus_formats > 0,413 * or to MEDIA_BUS_FMT_FIXED otherwise.414 */415 u32 *(*atomic_get_output_bus_fmts)(struct drm_bridge *bridge,416 struct drm_bridge_state *bridge_state,417 struct drm_crtc_state *crtc_state,418 struct drm_connector_state *conn_state,419 unsigned int *num_output_fmts);420 421 /**422 * @atomic_get_input_bus_fmts:423 *424 * Return the supported bus formats on the input end of a bridge for425 * a specific output bus format.426 *427 * The returned array must be allocated with kmalloc() and will be428 * freed by the caller. If the allocation fails, NULL should be429 * returned. num_input_fmts must be set to the returned array size.430 * Formats listed in the returned array should be listed in decreasing431 * preference order (the core will try all formats until it finds one432 * that works). When the format is not supported NULL should be433 * returned and num_input_fmts should be set to 0.434 *435 * This method is called on all elements of the bridge chain as part of436 * the bus format negotiation process that happens in437 * drm_atomic_bridge_chain_select_bus_fmts().438 * This method is optional. When not implemented, the core will bypass439 * bus format negotiation on this element of the bridge without440 * failing, and the previous element in the chain will be passed441 * MEDIA_BUS_FMT_FIXED as its output bus format.442 *443 * Bridge drivers that need to support being linked to bridges that are444 * not supporting bus format negotiation should handle the445 * output_fmt == MEDIA_BUS_FMT_FIXED case appropriately, by selecting a446 * sensible default value or extracting this information from somewhere447 * else (FW property, &drm_display_mode, &drm_display_info, ...)448 *449 * Note: Even if input format selection on the first bridge has no450 * impact on the negotiation process (bus format negotiation stops once451 * we reach the first element of the chain), drivers are expected to452 * return accurate input formats as the input format may be used to453 * configure the CRTC output appropriately.454 */455 u32 *(*atomic_get_input_bus_fmts)(struct drm_bridge *bridge,456 struct drm_bridge_state *bridge_state,457 struct drm_crtc_state *crtc_state,458 struct drm_connector_state *conn_state,459 u32 output_fmt,460 unsigned int *num_input_fmts);461 462 /**463 * @atomic_check:464 *465 * This method is responsible for checking bridge state correctness.466 * It can also check the state of the surrounding components in chain467 * to make sure the whole pipeline can work properly.468 *469 * &drm_bridge_funcs.atomic_check() hooks are called in reverse470 * order (from the last to the first bridge).471 *472 * This method is optional. &drm_bridge_funcs.mode_fixup() is not473 * called when &drm_bridge_funcs.atomic_check() is implemented, so only474 * one of them should be provided.475 *476 * If drivers need to tweak &drm_bridge_state.input_bus_cfg.flags or477 * &drm_bridge_state.output_bus_cfg.flags it should happen in478 * this function. By default the &drm_bridge_state.output_bus_cfg.flags479 * field is set to the next bridge480 * &drm_bridge_state.input_bus_cfg.flags value or481 * &drm_connector.display_info.bus_flags if the bridge is the last482 * element in the chain.483 *484 * RETURNS:485 * zero if the check passed, a negative error code otherwise.486 */487 int (*atomic_check)(struct drm_bridge *bridge,488 struct drm_bridge_state *bridge_state,489 struct drm_crtc_state *crtc_state,490 struct drm_connector_state *conn_state);491 492 /**493 * @atomic_reset:494 *495 * Reset the bridge to a predefined state (or retrieve its current496 * state) and return a &drm_bridge_state object matching this state.497 * This function is called at attach time.498 *499 * The atomic_reset hook is mandatory if the bridge implements any of500 * the atomic hooks, and should be left unassigned otherwise. For501 * bridges that don't subclass &drm_bridge_state, the502 * drm_atomic_helper_bridge_reset() helper function shall be used to503 * implement this hook.504 *505 * Note that the atomic_reset() semantics is not exactly matching the506 * reset() semantics found on other components (connector, plane, ...).507 *508 * 1. The reset operation happens when the bridge is attached, not when509 * drm_mode_config_reset() is called510 * 2. It's meant to be used exclusively on bridges that have been511 * converted to the ATOMIC API512 *513 * RETURNS:514 * A valid drm_bridge_state object in case of success, an ERR_PTR()515 * giving the reason of the failure otherwise.516 */517 struct drm_bridge_state *(*atomic_reset)(struct drm_bridge *bridge);518 519 /**520 * @detect:521 *522 * Check if anything is attached to the bridge output.523 *524 * This callback is optional, if not implemented the bridge will be525 * considered as always having a component attached to its output.526 * Bridges that implement this callback shall set the527 * DRM_BRIDGE_OP_DETECT flag in their &drm_bridge->ops.528 *529 * RETURNS:530 *531 * drm_connector_status indicating the bridge output status.532 */533 enum drm_connector_status (*detect)(struct drm_bridge *bridge);534 535 /**536 * @get_modes:537 *538 * Fill all modes currently valid for the sink into the &drm_connector539 * with drm_mode_probed_add().540 *541 * The @get_modes callback is mostly intended to support non-probeable542 * displays such as many fixed panels. Bridges that support reading543 * EDID shall leave @get_modes unimplemented and implement the544 * &drm_bridge_funcs->edid_read callback instead.545 *546 * This callback is optional. Bridges that implement it shall set the547 * DRM_BRIDGE_OP_MODES flag in their &drm_bridge->ops.548 *549 * The connector parameter shall be used for the sole purpose of550 * filling modes, and shall not be stored internally by bridge drivers551 * for future usage.552 *553 * RETURNS:554 *555 * The number of modes added by calling drm_mode_probed_add().556 */557 int (*get_modes)(struct drm_bridge *bridge,558 struct drm_connector *connector);559 560 /**561 * @edid_read:562 *563 * Read the EDID data of the connected display.564 *565 * The @edid_read callback is the preferred way of reporting mode566 * information for a display connected to the bridge output. Bridges567 * that support reading EDID shall implement this callback and leave568 * the @get_modes callback unimplemented.569 *570 * The caller of this operation shall first verify the output571 * connection status and refrain from reading EDID from a disconnected572 * output.573 *574 * This callback is optional. Bridges that implement it shall set the575 * DRM_BRIDGE_OP_EDID flag in their &drm_bridge->ops.576 *577 * The connector parameter shall be used for the sole purpose of EDID578 * retrieval, and shall not be stored internally by bridge drivers for579 * future usage.580 *581 * RETURNS:582 *583 * An edid structure newly allocated with drm_edid_alloc() or returned584 * from drm_edid_read() family of functions on success, or NULL585 * otherwise. The caller is responsible for freeing the returned edid586 * structure with drm_edid_free().587 */588 const struct drm_edid *(*edid_read)(struct drm_bridge *bridge,589 struct drm_connector *connector);590 591 /**592 * @hpd_notify:593 *594 * Notify the bridge of hot plug detection.595 *596 * This callback is optional, it may be implemented by bridges that597 * need to be notified of display connection or disconnection for598 * internal reasons. One use case is to reset the internal state of CEC599 * controllers for HDMI bridges.600 */601 void (*hpd_notify)(struct drm_bridge *bridge,602 enum drm_connector_status status);603 604 /**605 * @hpd_enable:606 *607 * Enable hot plug detection. From now on the bridge shall call608 * drm_bridge_hpd_notify() each time a change is detected in the output609 * connection status, until hot plug detection gets disabled with610 * @hpd_disable.611 *612 * This callback is optional and shall only be implemented by bridges613 * that support hot-plug notification without polling. Bridges that614 * implement it shall also implement the @hpd_disable callback and set615 * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.616 */617 void (*hpd_enable)(struct drm_bridge *bridge);618 619 /**620 * @hpd_disable:621 *622 * Disable hot plug detection. Once this function returns the bridge623 * shall not call drm_bridge_hpd_notify() when a change in the output624 * connection status occurs.625 *626 * This callback is optional and shall only be implemented by bridges627 * that support hot-plug notification without polling. Bridges that628 * implement it shall also implement the @hpd_enable callback and set629 * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.630 */631 void (*hpd_disable)(struct drm_bridge *bridge);632 633 /**634 * @hdmi_tmds_char_rate_valid:635 *636 * Check whether a particular TMDS character rate is supported by the637 * driver.638 *639 * This callback is optional and should only be implemented by the640 * bridges that take part in the HDMI connector implementation. Bridges641 * that implement it shall set the DRM_BRIDGE_OP_HDMI flag in their642 * &drm_bridge->ops.643 *644 * Returns:645 *646 * Either &drm_mode_status.MODE_OK or one of the failure reasons647 * in &enum drm_mode_status.648 */649 enum drm_mode_status650 (*hdmi_tmds_char_rate_valid)(const struct drm_bridge *bridge,651 const struct drm_display_mode *mode,652 unsigned long long tmds_rate);653 654 /**655 * @hdmi_clear_infoframe:656 *657 * This callback clears the infoframes in the hardware during commit.658 * It will be called multiple times, once for every disabled infoframe659 * type.660 *661 * This callback is optional but it must be implemented by bridges that662 * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops.663 */664 int (*hdmi_clear_infoframe)(struct drm_bridge *bridge,665 enum hdmi_infoframe_type type);666 /**667 * @hdmi_write_infoframe:668 *669 * Program the infoframe into the hardware. It will be called multiple670 * times, once for every updated infoframe type.671 *672 * This callback is optional but it must be implemented by bridges that673 * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops.674 */675 int (*hdmi_write_infoframe)(struct drm_bridge *bridge,676 enum hdmi_infoframe_type type,677 const u8 *buffer, size_t len);678 679 /**680 * @debugfs_init:681 *682 * Allows bridges to create bridge-specific debugfs files.683 */684 void (*debugfs_init)(struct drm_bridge *bridge, struct dentry *root);685};686 687/**688 * struct drm_bridge_timings - timing information for the bridge689 */690struct drm_bridge_timings {691 /**692 * @input_bus_flags:693 *694 * Tells what additional settings for the pixel data on the bus695 * this bridge requires (like pixel signal polarity). See also696 * &drm_display_info->bus_flags.697 */698 u32 input_bus_flags;699 /**700 * @setup_time_ps:701 *702 * Defines the time in picoseconds the input data lines must be703 * stable before the clock edge.704 */705 u32 setup_time_ps;706 /**707 * @hold_time_ps:708 *709 * Defines the time in picoseconds taken for the bridge to sample the710 * input signal after the clock edge.711 */712 u32 hold_time_ps;713 /**714 * @dual_link:715 *716 * True if the bus operates in dual-link mode. The exact meaning is717 * dependent on the bus type. For LVDS buses, this indicates that even-718 * and odd-numbered pixels are received on separate links.719 */720 bool dual_link;721};722 723/**724 * enum drm_bridge_ops - Bitmask of operations supported by the bridge725 */726enum drm_bridge_ops {727 /**728 * @DRM_BRIDGE_OP_DETECT: The bridge can detect displays connected to729 * its output. Bridges that set this flag shall implement the730 * &drm_bridge_funcs->detect callback.731 */732 DRM_BRIDGE_OP_DETECT = BIT(0),733 /**734 * @DRM_BRIDGE_OP_EDID: The bridge can retrieve the EDID of the display735 * connected to its output. Bridges that set this flag shall implement736 * the &drm_bridge_funcs->edid_read callback.737 */738 DRM_BRIDGE_OP_EDID = BIT(1),739 /**740 * @DRM_BRIDGE_OP_HPD: The bridge can detect hot-plug and hot-unplug741 * without requiring polling. Bridges that set this flag shall742 * implement the &drm_bridge_funcs->hpd_enable and743 * &drm_bridge_funcs->hpd_disable callbacks if they support enabling744 * and disabling hot-plug detection dynamically.745 */746 DRM_BRIDGE_OP_HPD = BIT(2),747 /**748 * @DRM_BRIDGE_OP_MODES: The bridge can retrieve the modes supported749 * by the display at its output. This does not include reading EDID750 * which is separately covered by @DRM_BRIDGE_OP_EDID. Bridges that set751 * this flag shall implement the &drm_bridge_funcs->get_modes callback.752 */753 DRM_BRIDGE_OP_MODES = BIT(3),754 /**755 * @DRM_BRIDGE_OP_HDMI: The bridge provides HDMI connector operations,756 * including infoframes support. Bridges that set this flag must757 * implement the &drm_bridge_funcs->write_infoframe callback.758 *759 * Note: currently there can be at most one bridge in a chain that sets760 * this bit. This is to simplify corresponding glue code in connector761 * drivers.762 */763 DRM_BRIDGE_OP_HDMI = BIT(4),764};765 766/**767 * struct drm_bridge - central DRM bridge control structure768 */769struct drm_bridge {770 /** @base: inherit from &drm_private_object */771 struct drm_private_obj base;772 /** @dev: DRM device this bridge belongs to */773 struct drm_device *dev;774 /** @encoder: encoder to which this bridge is connected */775 struct drm_encoder *encoder;776 /** @chain_node: used to form a bridge chain */777 struct list_head chain_node;778 /** @of_node: device node pointer to the bridge */779 struct device_node *of_node;780 /** @list: to keep track of all added bridges */781 struct list_head list;782 /**783 * @timings:784 *785 * the timing specification for the bridge, if any (may be NULL)786 */787 const struct drm_bridge_timings *timings;788 /** @funcs: control functions */789 const struct drm_bridge_funcs *funcs;790 /** @driver_private: pointer to the bridge driver's internal context */791 void *driver_private;792 /** @ops: bitmask of operations supported by the bridge */793 enum drm_bridge_ops ops;794 /**795 * @type: Type of the connection at the bridge output796 * (DRM_MODE_CONNECTOR_*). For bridges at the end of this chain this797 * identifies the type of connected display.798 */799 int type;800 /**801 * @interlace_allowed: Indicate that the bridge can handle interlaced802 * modes.803 */804 bool interlace_allowed;805 /**806 * @pre_enable_prev_first: The bridge requires that the prev807 * bridge @pre_enable function is called before its @pre_enable,808 * and conversely for post_disable. This is most frequently a809 * requirement for DSI devices which need the host to be initialised810 * before the peripheral.811 */812 bool pre_enable_prev_first;813 /**814 * @ddc: Associated I2C adapter for DDC access, if any.815 */816 struct i2c_adapter *ddc;817 /** private: */818 /**819 * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields.820 */821 struct mutex hpd_mutex;822 /**823 * @hpd_cb: Hot plug detection callback, registered with824 * drm_bridge_hpd_enable().825 */826 void (*hpd_cb)(void *data, enum drm_connector_status status);827 /**828 * @hpd_data: Private data passed to the Hot plug detection callback829 * @hpd_cb.830 */831 void *hpd_data;832 833 /**834 * @vendor: Vendor of the product to be used for the SPD InfoFrame835 * generation. This is required if @DRM_BRIDGE_OP_HDMI is set.836 */837 const char *vendor;838 839 /**840 * @product: Name of the product to be used for the SPD InfoFrame841 * generation. This is required if @DRM_BRIDGE_OP_HDMI is set.842 */843 const char *product;844 845 /**846 * @supported_formats: Bitmask of @hdmi_colorspace listing supported847 * output formats. This is only relevant if @DRM_BRIDGE_OP_HDMI is set.848 */849 unsigned int supported_formats;850 851 /**852 * @max_bpc: Maximum bits per char the HDMI bridge supports. Allowed853 * values are 8, 10 and 12. This is only relevant if854 * @DRM_BRIDGE_OP_HDMI is set.855 */856 unsigned int max_bpc;857};858 859static inline struct drm_bridge *860drm_priv_to_bridge(struct drm_private_obj *priv)861{862 return container_of(priv, struct drm_bridge, base);863}864 865void drm_bridge_add(struct drm_bridge *bridge);866int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge);867void drm_bridge_remove(struct drm_bridge *bridge);868int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,869 struct drm_bridge *previous,870 enum drm_bridge_attach_flags flags);871 872#ifdef CONFIG_OF873struct drm_bridge *of_drm_find_bridge(struct device_node *np);874#else875static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np)876{877 return NULL;878}879#endif880 881/**882 * drm_bridge_get_next_bridge() - Get the next bridge in the chain883 * @bridge: bridge object884 *885 * RETURNS:886 * the next bridge in the chain after @bridge, or NULL if @bridge is the last.887 */888static inline struct drm_bridge *889drm_bridge_get_next_bridge(struct drm_bridge *bridge)890{891 if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain))892 return NULL;893 894 return list_next_entry(bridge, chain_node);895}896 897/**898 * drm_bridge_get_prev_bridge() - Get the previous bridge in the chain899 * @bridge: bridge object900 *901 * RETURNS:902 * the previous bridge in the chain, or NULL if @bridge is the first.903 */904static inline struct drm_bridge *905drm_bridge_get_prev_bridge(struct drm_bridge *bridge)906{907 if (list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain))908 return NULL;909 910 return list_prev_entry(bridge, chain_node);911}912 913/**914 * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain915 * @encoder: encoder object916 *917 * RETURNS:918 * the first bridge in the chain, or NULL if @encoder has no bridge attached919 * to it.920 */921static inline struct drm_bridge *922drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder)923{924 return list_first_entry_or_null(&encoder->bridge_chain,925 struct drm_bridge, chain_node);926}927 928/**929 * drm_for_each_bridge_in_chain() - Iterate over all bridges present in a chain930 * @encoder: the encoder to iterate bridges on931 * @bridge: a bridge pointer updated to point to the current bridge at each932 * iteration933 *934 * Iterate over all bridges present in the bridge chain attached to @encoder.935 */936#define drm_for_each_bridge_in_chain(encoder, bridge) \937 list_for_each_entry(bridge, &(encoder)->bridge_chain, chain_node)938 939enum drm_mode_status940drm_bridge_chain_mode_valid(struct drm_bridge *bridge,941 const struct drm_display_info *info,942 const struct drm_display_mode *mode);943void drm_bridge_chain_mode_set(struct drm_bridge *bridge,944 const struct drm_display_mode *mode,945 const struct drm_display_mode *adjusted_mode);946 947int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,948 struct drm_crtc_state *crtc_state,949 struct drm_connector_state *conn_state);950void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,951 struct drm_atomic_state *state);952void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,953 struct drm_atomic_state *state);954void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,955 struct drm_atomic_state *state);956void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,957 struct drm_atomic_state *state);958 959u32 *960drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,961 struct drm_bridge_state *bridge_state,962 struct drm_crtc_state *crtc_state,963 struct drm_connector_state *conn_state,964 u32 output_fmt,965 unsigned int *num_input_fmts);966 967enum drm_connector_status drm_bridge_detect(struct drm_bridge *bridge);968int drm_bridge_get_modes(struct drm_bridge *bridge,969 struct drm_connector *connector);970const struct drm_edid *drm_bridge_edid_read(struct drm_bridge *bridge,971 struct drm_connector *connector);972void drm_bridge_hpd_enable(struct drm_bridge *bridge,973 void (*cb)(void *data,974 enum drm_connector_status status),975 void *data);976void drm_bridge_hpd_disable(struct drm_bridge *bridge);977void drm_bridge_hpd_notify(struct drm_bridge *bridge,978 enum drm_connector_status status);979 980#ifdef CONFIG_DRM_PANEL_BRIDGE981bool drm_bridge_is_panel(const struct drm_bridge *bridge);982struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel);983struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,984 u32 connector_type);985void drm_panel_bridge_remove(struct drm_bridge *bridge);986int drm_panel_bridge_set_orientation(struct drm_connector *connector,987 struct drm_bridge *bridge);988struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,989 struct drm_panel *panel);990struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,991 struct drm_panel *panel,992 u32 connector_type);993struct drm_bridge *drmm_panel_bridge_add(struct drm_device *drm,994 struct drm_panel *panel);995struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge);996#else997static inline bool drm_bridge_is_panel(const struct drm_bridge *bridge)998{999 return false;1000}1001 1002static inline int drm_panel_bridge_set_orientation(struct drm_connector *connector,1003 struct drm_bridge *bridge)1004{1005 return -EINVAL;1006}1007#endif1008 1009#if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL_BRIDGE)1010struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, struct device_node *node,1011 u32 port, u32 endpoint);1012struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm, struct device_node *node,1013 u32 port, u32 endpoint);1014#else1015static inline struct drm_bridge *devm_drm_of_get_bridge(struct device *dev,1016 struct device_node *node,1017 u32 port,1018 u32 endpoint)1019{1020 return ERR_PTR(-ENODEV);1021}1022 1023static inline struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm,1024 struct device_node *node,1025 u32 port,1026 u32 endpoint)1027{1028 return ERR_PTR(-ENODEV);1029}1030#endif1031 1032#endif1033