Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2016 Intel Corporation
0003  *
0004  * Permission to use, copy, modify, distribute, and sell this software and its
0005  * documentation for any purpose is hereby granted without fee, provided that
0006  * the above copyright notice appear in all copies and that both that copyright
0007  * notice and this permission notice appear in supporting documentation, and
0008  * that the name of the copyright holders not be used in advertising or
0009  * publicity pertaining to distribution of the software without specific,
0010  * written prior permission.  The copyright holders make no representations
0011  * about the suitability of this software for any purpose.  It is provided "as
0012  * is" without express or implied warranty.
0013  *
0014  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
0015  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
0016  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
0017  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
0018  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
0019  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
0020  * OF THIS SOFTWARE.
0021  */
0022 
0023 #ifndef __DRM_BRIDGE_H__
0024 #define __DRM_BRIDGE_H__
0025 
0026 #include <linux/ctype.h>
0027 #include <linux/list.h>
0028 #include <linux/mutex.h>
0029 
0030 #include <drm/drm_atomic.h>
0031 #include <drm/drm_encoder.h>
0032 #include <drm/drm_mode_object.h>
0033 #include <drm/drm_modes.h>
0034 
0035 struct drm_bridge;
0036 struct drm_bridge_timings;
0037 struct drm_connector;
0038 struct drm_display_info;
0039 struct drm_panel;
0040 struct edid;
0041 struct i2c_adapter;
0042 
0043 /**
0044  * enum drm_bridge_attach_flags - Flags for &drm_bridge_funcs.attach
0045  */
0046 enum drm_bridge_attach_flags {
0047     /**
0048      * @DRM_BRIDGE_ATTACH_NO_CONNECTOR: When this flag is set the bridge
0049      * shall not create a drm_connector.
0050      */
0051     DRM_BRIDGE_ATTACH_NO_CONNECTOR = BIT(0),
0052 };
0053 
0054 /**
0055  * struct drm_bridge_funcs - drm_bridge control functions
0056  */
0057 struct drm_bridge_funcs {
0058     /**
0059      * @attach:
0060      *
0061      * This callback is invoked whenever our bridge is being attached to a
0062      * &drm_encoder. The flags argument tunes the behaviour of the attach
0063      * operation (see DRM_BRIDGE_ATTACH_*).
0064      *
0065      * The @attach callback is optional.
0066      *
0067      * RETURNS:
0068      *
0069      * Zero on success, error code on failure.
0070      */
0071     int (*attach)(struct drm_bridge *bridge,
0072               enum drm_bridge_attach_flags flags);
0073 
0074     /**
0075      * @detach:
0076      *
0077      * This callback is invoked whenever our bridge is being detached from a
0078      * &drm_encoder.
0079      *
0080      * The @detach callback is optional.
0081      */
0082     void (*detach)(struct drm_bridge *bridge);
0083 
0084     /**
0085      * @mode_valid:
0086      *
0087      * This callback is used to check if a specific mode is valid in this
0088      * bridge. This should be implemented if the bridge has some sort of
0089      * restriction in the modes it can display. For example, a given bridge
0090      * may be responsible to set a clock value. If the clock can not
0091      * produce all the values for the available modes then this callback
0092      * can be used to restrict the number of modes to only the ones that
0093      * can be displayed.
0094      *
0095      * This hook is used by the probe helpers to filter the mode list in
0096      * drm_helper_probe_single_connector_modes(), and it is used by the
0097      * atomic helpers to validate modes supplied by userspace in
0098      * drm_atomic_helper_check_modeset().
0099      *
0100      * The @mode_valid callback is optional.
0101      *
0102      * NOTE:
0103      *
0104      * Since this function is both called from the check phase of an atomic
0105      * commit, and the mode validation in the probe paths it is not allowed
0106      * to look at anything else but the passed-in mode, and validate it
0107      * against configuration-invariant hardward constraints. Any further
0108      * limits which depend upon the configuration can only be checked in
0109      * @mode_fixup.
0110      *
0111      * RETURNS:
0112      *
0113      * drm_mode_status Enum
0114      */
0115     enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge,
0116                        const struct drm_display_info *info,
0117                        const struct drm_display_mode *mode);
0118 
0119     /**
0120      * @mode_fixup:
0121      *
0122      * This callback is used to validate and adjust a mode. The parameter
0123      * mode is the display mode that should be fed to the next element in
0124      * the display chain, either the final &drm_connector or the next
0125      * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
0126      * requires. It can be modified by this callback and does not need to
0127      * match mode. See also &drm_crtc_state.adjusted_mode for more details.
0128      *
0129      * This is the only hook that allows a bridge to reject a modeset. If
0130      * this function passes all other callbacks must succeed for this
0131      * configuration.
0132      *
0133      * The mode_fixup callback is optional. &drm_bridge_funcs.mode_fixup()
0134      * is not called when &drm_bridge_funcs.atomic_check() is implemented,
0135      * so only one of them should be provided.
0136      *
0137      * NOTE:
0138      *
0139      * This function is called in the check phase of atomic modesets, which
0140      * can be aborted for any reason (including on userspace's request to
0141      * just check whether a configuration would be possible). Drivers MUST
0142      * NOT touch any persistent state (hardware or software) or data
0143      * structures except the passed in @state parameter.
0144      *
0145      * Also beware that userspace can request its own custom modes, neither
0146      * core nor helpers filter modes to the list of probe modes reported by
0147      * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
0148      * that modes are filtered consistently put any bridge constraints and
0149      * limits checks into @mode_valid.
0150      *
0151      * RETURNS:
0152      *
0153      * True if an acceptable configuration is possible, false if the modeset
0154      * operation should be rejected.
0155      */
0156     bool (*mode_fixup)(struct drm_bridge *bridge,
0157                const struct drm_display_mode *mode,
0158                struct drm_display_mode *adjusted_mode);
0159     /**
0160      * @disable:
0161      *
0162      * This callback should disable the bridge. It is called right before
0163      * the preceding element in the display pipe is disabled. If the
0164      * preceding element is a bridge this means it's called before that
0165      * bridge's @disable vfunc. If the preceding element is a &drm_encoder
0166      * it's called right before the &drm_encoder_helper_funcs.disable,
0167      * &drm_encoder_helper_funcs.prepare or &drm_encoder_helper_funcs.dpms
0168      * hook.
0169      *
0170      * The bridge can assume that the display pipe (i.e. clocks and timing
0171      * signals) feeding it is still running when this callback is called.
0172      *
0173      * The @disable callback is optional.
0174      *
0175      * NOTE:
0176      *
0177      * This is deprecated, do not use!
0178      * New drivers shall use &drm_bridge_funcs.atomic_disable.
0179      */
0180     void (*disable)(struct drm_bridge *bridge);
0181 
0182     /**
0183      * @post_disable:
0184      *
0185      * This callback should disable the bridge. It is called right after the
0186      * preceding element in the display pipe is disabled. If the preceding
0187      * element is a bridge this means it's called after that bridge's
0188      * @post_disable function. If the preceding element is a &drm_encoder
0189      * it's called right after the encoder's
0190      * &drm_encoder_helper_funcs.disable, &drm_encoder_helper_funcs.prepare
0191      * or &drm_encoder_helper_funcs.dpms hook.
0192      *
0193      * The bridge must assume that the display pipe (i.e. clocks and timing
0194      * singals) feeding it is no longer running when this callback is
0195      * called.
0196      *
0197      * The @post_disable callback is optional.
0198      *
0199      * NOTE:
0200      *
0201      * This is deprecated, do not use!
0202      * New drivers shall use &drm_bridge_funcs.atomic_post_disable.
0203      */
0204     void (*post_disable)(struct drm_bridge *bridge);
0205 
0206     /**
0207      * @mode_set:
0208      *
0209      * This callback should set the given mode on the bridge. It is called
0210      * after the @mode_set callback for the preceding element in the display
0211      * pipeline has been called already. If the bridge is the first element
0212      * then this would be &drm_encoder_helper_funcs.mode_set. The display
0213      * pipe (i.e.  clocks and timing signals) is off when this function is
0214      * called.
0215      *
0216      * The adjusted_mode parameter is the mode output by the CRTC for the
0217      * first bridge in the chain. It can be different from the mode
0218      * parameter that contains the desired mode for the connector at the end
0219      * of the bridges chain, for instance when the first bridge in the chain
0220      * performs scaling. The adjusted mode is mostly useful for the first
0221      * bridge in the chain and is likely irrelevant for the other bridges.
0222      *
0223      * For atomic drivers the adjusted_mode is the mode stored in
0224      * &drm_crtc_state.adjusted_mode.
0225      *
0226      * NOTE:
0227      *
0228      * This is deprecated, do not use!
0229      * New drivers shall set their mode in the
0230      * &drm_bridge_funcs.atomic_enable operation.
0231      */
0232     void (*mode_set)(struct drm_bridge *bridge,
0233              const struct drm_display_mode *mode,
0234              const struct drm_display_mode *adjusted_mode);
0235     /**
0236      * @pre_enable:
0237      *
0238      * This callback should enable the bridge. It is called right before
0239      * the preceding element in the display pipe is enabled. If the
0240      * preceding element is a bridge this means it's called before that
0241      * bridge's @pre_enable function. If the preceding element is a
0242      * &drm_encoder it's called right before the encoder's
0243      * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
0244      * &drm_encoder_helper_funcs.dpms hook.
0245      *
0246      * The display pipe (i.e. clocks and timing signals) feeding this bridge
0247      * will not yet be running when this callback is called. The bridge must
0248      * not enable the display link feeding the next bridge in the chain (if
0249      * there is one) when this callback is called.
0250      *
0251      * The @pre_enable callback is optional.
0252      *
0253      * NOTE:
0254      *
0255      * This is deprecated, do not use!
0256      * New drivers shall use &drm_bridge_funcs.atomic_pre_enable.
0257      */
0258     void (*pre_enable)(struct drm_bridge *bridge);
0259 
0260     /**
0261      * @enable:
0262      *
0263      * This callback should enable the bridge. It is called right after
0264      * the preceding element in the display pipe is enabled. If the
0265      * preceding element is a bridge this means it's called after that
0266      * bridge's @enable function. If the preceding element is a
0267      * &drm_encoder it's called right after the encoder's
0268      * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
0269      * &drm_encoder_helper_funcs.dpms hook.
0270      *
0271      * The bridge can assume that the display pipe (i.e. clocks and timing
0272      * signals) feeding it is running when this callback is called. This
0273      * callback must enable the display link feeding the next bridge in the
0274      * chain if there is one.
0275      *
0276      * The @enable callback is optional.
0277      *
0278      * NOTE:
0279      *
0280      * This is deprecated, do not use!
0281      * New drivers shall use &drm_bridge_funcs.atomic_enable.
0282      */
0283     void (*enable)(struct drm_bridge *bridge);
0284 
0285     /**
0286      * @atomic_pre_enable:
0287      *
0288      * This callback should enable the bridge. It is called right before
0289      * the preceding element in the display pipe is enabled. If the
0290      * preceding element is a bridge this means it's called before that
0291      * bridge's @atomic_pre_enable or @pre_enable function. If the preceding
0292      * element is a &drm_encoder it's called right before the encoder's
0293      * &drm_encoder_helper_funcs.atomic_enable hook.
0294      *
0295      * The display pipe (i.e. clocks and timing signals) feeding this bridge
0296      * will not yet be running when this callback is called. The bridge must
0297      * not enable the display link feeding the next bridge in the chain (if
0298      * there is one) when this callback is called.
0299      *
0300      * Note that this function will only be invoked in the context of an
0301      * atomic commit. It will not be invoked from
0302      * &drm_bridge_chain_pre_enable. It would be prudent to also provide an
0303      * implementation of @pre_enable if you are expecting driver calls into
0304      * &drm_bridge_chain_pre_enable.
0305      *
0306      * The @atomic_pre_enable callback is optional.
0307      */
0308     void (*atomic_pre_enable)(struct drm_bridge *bridge,
0309                   struct drm_bridge_state *old_bridge_state);
0310 
0311     /**
0312      * @atomic_enable:
0313      *
0314      * This callback should enable the bridge. It is called right after
0315      * the preceding element in the display pipe is enabled. If the
0316      * preceding element is a bridge this means it's called after that
0317      * bridge's @atomic_enable or @enable function. If the preceding element
0318      * is a &drm_encoder it's called right after the encoder's
0319      * &drm_encoder_helper_funcs.atomic_enable hook.
0320      *
0321      * The bridge can assume that the display pipe (i.e. clocks and timing
0322      * signals) feeding it is running when this callback is called. This
0323      * callback must enable the display link feeding the next bridge in the
0324      * chain if there is one.
0325      *
0326      * Note that this function will only be invoked in the context of an
0327      * atomic commit. It will not be invoked from &drm_bridge_chain_enable.
0328      * It would be prudent to also provide an implementation of @enable if
0329      * you are expecting driver calls into &drm_bridge_chain_enable.
0330      *
0331      * The @atomic_enable callback is optional.
0332      */
0333     void (*atomic_enable)(struct drm_bridge *bridge,
0334                   struct drm_bridge_state *old_bridge_state);
0335     /**
0336      * @atomic_disable:
0337      *
0338      * This callback should disable the bridge. It is called right before
0339      * the preceding element in the display pipe is disabled. If the
0340      * preceding element is a bridge this means it's called before that
0341      * bridge's @atomic_disable or @disable vfunc. If the preceding element
0342      * is a &drm_encoder it's called right before the
0343      * &drm_encoder_helper_funcs.atomic_disable hook.
0344      *
0345      * The bridge can assume that the display pipe (i.e. clocks and timing
0346      * signals) feeding it is still running when this callback is called.
0347      *
0348      * Note that this function will only be invoked in the context of an
0349      * atomic commit. It will not be invoked from
0350      * &drm_bridge_chain_disable. It would be prudent to also provide an
0351      * implementation of @disable if you are expecting driver calls into
0352      * &drm_bridge_chain_disable.
0353      *
0354      * The @atomic_disable callback is optional.
0355      */
0356     void (*atomic_disable)(struct drm_bridge *bridge,
0357                    struct drm_bridge_state *old_bridge_state);
0358 
0359     /**
0360      * @atomic_post_disable:
0361      *
0362      * This callback should disable the bridge. It is called right after the
0363      * preceding element in the display pipe is disabled. If the preceding
0364      * element is a bridge this means it's called after that bridge's
0365      * @atomic_post_disable or @post_disable function. If the preceding
0366      * element is a &drm_encoder it's called right after the encoder's
0367      * &drm_encoder_helper_funcs.atomic_disable hook.
0368      *
0369      * The bridge must assume that the display pipe (i.e. clocks and timing
0370      * signals) feeding it is no longer running when this callback is
0371      * called.
0372      *
0373      * Note that this function will only be invoked in the context of an
0374      * atomic commit. It will not be invoked from
0375      * &drm_bridge_chain_post_disable.
0376      * It would be prudent to also provide an implementation of
0377      * @post_disable if you are expecting driver calls into
0378      * &drm_bridge_chain_post_disable.
0379      *
0380      * The @atomic_post_disable callback is optional.
0381      */
0382     void (*atomic_post_disable)(struct drm_bridge *bridge,
0383                     struct drm_bridge_state *old_bridge_state);
0384 
0385     /**
0386      * @atomic_duplicate_state:
0387      *
0388      * Duplicate the current bridge state object (which is guaranteed to be
0389      * non-NULL).
0390      *
0391      * The atomic_duplicate_state hook is mandatory if the bridge
0392      * implements any of the atomic hooks, and should be left unassigned
0393      * otherwise. For bridges that don't subclass &drm_bridge_state, the
0394      * drm_atomic_helper_bridge_duplicate_state() helper function shall be
0395      * used to implement this hook.
0396      *
0397      * RETURNS:
0398      * A valid drm_bridge_state object or NULL if the allocation fails.
0399      */
0400     struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge);
0401 
0402     /**
0403      * @atomic_destroy_state:
0404      *
0405      * Destroy a bridge state object previously allocated by
0406      * &drm_bridge_funcs.atomic_duplicate_state().
0407      *
0408      * The atomic_destroy_state hook is mandatory if the bridge implements
0409      * any of the atomic hooks, and should be left unassigned otherwise.
0410      * For bridges that don't subclass &drm_bridge_state, the
0411      * drm_atomic_helper_bridge_destroy_state() helper function shall be
0412      * used to implement this hook.
0413      */
0414     void (*atomic_destroy_state)(struct drm_bridge *bridge,
0415                      struct drm_bridge_state *state);
0416 
0417     /**
0418      * @atomic_get_output_bus_fmts:
0419      *
0420      * Return the supported bus formats on the output end of a bridge.
0421      * The returned array must be allocated with kmalloc() and will be
0422      * freed by the caller. If the allocation fails, NULL should be
0423      * returned. num_output_fmts must be set to the returned array size.
0424      * Formats listed in the returned array should be listed in decreasing
0425      * preference order (the core will try all formats until it finds one
0426      * that works).
0427      *
0428      * This method is only called on the last element of the bridge chain
0429      * as part of the bus format negotiation process that happens in
0430      * &drm_atomic_bridge_chain_select_bus_fmts().
0431      * This method is optional. When not implemented, the core will
0432      * fall back to &drm_connector.display_info.bus_formats[0] if
0433      * &drm_connector.display_info.num_bus_formats > 0,
0434      * or to MEDIA_BUS_FMT_FIXED otherwise.
0435      */
0436     u32 *(*atomic_get_output_bus_fmts)(struct drm_bridge *bridge,
0437                        struct drm_bridge_state *bridge_state,
0438                        struct drm_crtc_state *crtc_state,
0439                        struct drm_connector_state *conn_state,
0440                        unsigned int *num_output_fmts);
0441 
0442     /**
0443      * @atomic_get_input_bus_fmts:
0444      *
0445      * Return the supported bus formats on the input end of a bridge for
0446      * a specific output bus format.
0447      *
0448      * The returned array must be allocated with kmalloc() and will be
0449      * freed by the caller. If the allocation fails, NULL should be
0450      * returned. num_output_fmts must be set to the returned array size.
0451      * Formats listed in the returned array should be listed in decreasing
0452      * preference order (the core will try all formats until it finds one
0453      * that works). When the format is not supported NULL should be
0454      * returned and num_output_fmts should be set to 0.
0455      *
0456      * This method is called on all elements of the bridge chain as part of
0457      * the bus format negotiation process that happens in
0458      * drm_atomic_bridge_chain_select_bus_fmts().
0459      * This method is optional. When not implemented, the core will bypass
0460      * bus format negotiation on this element of the bridge without
0461      * failing, and the previous element in the chain will be passed
0462      * MEDIA_BUS_FMT_FIXED as its output bus format.
0463      *
0464      * Bridge drivers that need to support being linked to bridges that are
0465      * not supporting bus format negotiation should handle the
0466      * output_fmt == MEDIA_BUS_FMT_FIXED case appropriately, by selecting a
0467      * sensible default value or extracting this information from somewhere
0468      * else (FW property, &drm_display_mode, &drm_display_info, ...)
0469      *
0470      * Note: Even if input format selection on the first bridge has no
0471      * impact on the negotiation process (bus format negotiation stops once
0472      * we reach the first element of the chain), drivers are expected to
0473      * return accurate input formats as the input format may be used to
0474      * configure the CRTC output appropriately.
0475      */
0476     u32 *(*atomic_get_input_bus_fmts)(struct drm_bridge *bridge,
0477                       struct drm_bridge_state *bridge_state,
0478                       struct drm_crtc_state *crtc_state,
0479                       struct drm_connector_state *conn_state,
0480                       u32 output_fmt,
0481                       unsigned int *num_input_fmts);
0482 
0483     /**
0484      * @atomic_check:
0485      *
0486      * This method is responsible for checking bridge state correctness.
0487      * It can also check the state of the surrounding components in chain
0488      * to make sure the whole pipeline can work properly.
0489      *
0490      * &drm_bridge_funcs.atomic_check() hooks are called in reverse
0491      * order (from the last to the first bridge).
0492      *
0493      * This method is optional. &drm_bridge_funcs.mode_fixup() is not
0494      * called when &drm_bridge_funcs.atomic_check() is implemented, so only
0495      * one of them should be provided.
0496      *
0497      * If drivers need to tweak &drm_bridge_state.input_bus_cfg.flags or
0498      * &drm_bridge_state.output_bus_cfg.flags it should happen in
0499      * this function. By default the &drm_bridge_state.output_bus_cfg.flags
0500      * field is set to the next bridge
0501      * &drm_bridge_state.input_bus_cfg.flags value or
0502      * &drm_connector.display_info.bus_flags if the bridge is the last
0503      * element in the chain.
0504      *
0505      * RETURNS:
0506      * zero if the check passed, a negative error code otherwise.
0507      */
0508     int (*atomic_check)(struct drm_bridge *bridge,
0509                 struct drm_bridge_state *bridge_state,
0510                 struct drm_crtc_state *crtc_state,
0511                 struct drm_connector_state *conn_state);
0512 
0513     /**
0514      * @atomic_reset:
0515      *
0516      * Reset the bridge to a predefined state (or retrieve its current
0517      * state) and return a &drm_bridge_state object matching this state.
0518      * This function is called at attach time.
0519      *
0520      * The atomic_reset hook is mandatory if the bridge implements any of
0521      * the atomic hooks, and should be left unassigned otherwise. For
0522      * bridges that don't subclass &drm_bridge_state, the
0523      * drm_atomic_helper_bridge_reset() helper function shall be used to
0524      * implement this hook.
0525      *
0526      * Note that the atomic_reset() semantics is not exactly matching the
0527      * reset() semantics found on other components (connector, plane, ...).
0528      *
0529      * 1. The reset operation happens when the bridge is attached, not when
0530      *    drm_mode_config_reset() is called
0531      * 2. It's meant to be used exclusively on bridges that have been
0532      *    converted to the ATOMIC API
0533      *
0534      * RETURNS:
0535      * A valid drm_bridge_state object in case of success, an ERR_PTR()
0536      * giving the reason of the failure otherwise.
0537      */
0538     struct drm_bridge_state *(*atomic_reset)(struct drm_bridge *bridge);
0539 
0540     /**
0541      * @detect:
0542      *
0543      * Check if anything is attached to the bridge output.
0544      *
0545      * This callback is optional, if not implemented the bridge will be
0546      * considered as always having a component attached to its output.
0547      * Bridges that implement this callback shall set the
0548      * DRM_BRIDGE_OP_DETECT flag in their &drm_bridge->ops.
0549      *
0550      * RETURNS:
0551      *
0552      * drm_connector_status indicating the bridge output status.
0553      */
0554     enum drm_connector_status (*detect)(struct drm_bridge *bridge);
0555 
0556     /**
0557      * @get_modes:
0558      *
0559      * Fill all modes currently valid for the sink into the &drm_connector
0560      * with drm_mode_probed_add().
0561      *
0562      * The @get_modes callback is mostly intended to support non-probeable
0563      * displays such as many fixed panels. Bridges that support reading
0564      * EDID shall leave @get_modes unimplemented and implement the
0565      * &drm_bridge_funcs->get_edid callback instead.
0566      *
0567      * This callback is optional. Bridges that implement it shall set the
0568      * DRM_BRIDGE_OP_MODES flag in their &drm_bridge->ops.
0569      *
0570      * The connector parameter shall be used for the sole purpose of
0571      * filling modes, and shall not be stored internally by bridge drivers
0572      * for future usage.
0573      *
0574      * RETURNS:
0575      *
0576      * The number of modes added by calling drm_mode_probed_add().
0577      */
0578     int (*get_modes)(struct drm_bridge *bridge,
0579              struct drm_connector *connector);
0580 
0581     /**
0582      * @get_edid:
0583      *
0584      * Read and parse the EDID data of the connected display.
0585      *
0586      * The @get_edid callback is the preferred way of reporting mode
0587      * information for a display connected to the bridge output. Bridges
0588      * that support reading EDID shall implement this callback and leave
0589      * the @get_modes callback unimplemented.
0590      *
0591      * The caller of this operation shall first verify the output
0592      * connection status and refrain from reading EDID from a disconnected
0593      * output.
0594      *
0595      * This callback is optional. Bridges that implement it shall set the
0596      * DRM_BRIDGE_OP_EDID flag in their &drm_bridge->ops.
0597      *
0598      * The connector parameter shall be used for the sole purpose of EDID
0599      * retrieval and parsing, and shall not be stored internally by bridge
0600      * drivers for future usage.
0601      *
0602      * RETURNS:
0603      *
0604      * An edid structure newly allocated with kmalloc() (or similar) on
0605      * success, or NULL otherwise. The caller is responsible for freeing
0606      * the returned edid structure with kfree().
0607      */
0608     struct edid *(*get_edid)(struct drm_bridge *bridge,
0609                  struct drm_connector *connector);
0610 
0611     /**
0612      * @hpd_notify:
0613      *
0614      * Notify the bridge of hot plug detection.
0615      *
0616      * This callback is optional, it may be implemented by bridges that
0617      * need to be notified of display connection or disconnection for
0618      * internal reasons. One use case is to reset the internal state of CEC
0619      * controllers for HDMI bridges.
0620      */
0621     void (*hpd_notify)(struct drm_bridge *bridge,
0622                enum drm_connector_status status);
0623 
0624     /**
0625      * @hpd_enable:
0626      *
0627      * Enable hot plug detection. From now on the bridge shall call
0628      * drm_bridge_hpd_notify() each time a change is detected in the output
0629      * connection status, until hot plug detection gets disabled with
0630      * @hpd_disable.
0631      *
0632      * This callback is optional and shall only be implemented by bridges
0633      * that support hot-plug notification without polling. Bridges that
0634      * implement it shall also implement the @hpd_disable callback and set
0635      * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
0636      */
0637     void (*hpd_enable)(struct drm_bridge *bridge);
0638 
0639     /**
0640      * @hpd_disable:
0641      *
0642      * Disable hot plug detection. Once this function returns the bridge
0643      * shall not call drm_bridge_hpd_notify() when a change in the output
0644      * connection status occurs.
0645      *
0646      * This callback is optional and shall only be implemented by bridges
0647      * that support hot-plug notification without polling. Bridges that
0648      * implement it shall also implement the @hpd_enable callback and set
0649      * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
0650      */
0651     void (*hpd_disable)(struct drm_bridge *bridge);
0652 
0653     /**
0654      * @debugfs_init:
0655      *
0656      * Allows bridges to create bridge-specific debugfs files.
0657      */
0658     void (*debugfs_init)(struct drm_bridge *bridge, struct dentry *root);
0659 };
0660 
0661 /**
0662  * struct drm_bridge_timings - timing information for the bridge
0663  */
0664 struct drm_bridge_timings {
0665     /**
0666      * @input_bus_flags:
0667      *
0668      * Tells what additional settings for the pixel data on the bus
0669      * this bridge requires (like pixel signal polarity). See also
0670      * &drm_display_info->bus_flags.
0671      */
0672     u32 input_bus_flags;
0673     /**
0674      * @setup_time_ps:
0675      *
0676      * Defines the time in picoseconds the input data lines must be
0677      * stable before the clock edge.
0678      */
0679     u32 setup_time_ps;
0680     /**
0681      * @hold_time_ps:
0682      *
0683      * Defines the time in picoseconds taken for the bridge to sample the
0684      * input signal after the clock edge.
0685      */
0686     u32 hold_time_ps;
0687     /**
0688      * @dual_link:
0689      *
0690      * True if the bus operates in dual-link mode. The exact meaning is
0691      * dependent on the bus type. For LVDS buses, this indicates that even-
0692      * and odd-numbered pixels are received on separate links.
0693      */
0694     bool dual_link;
0695 };
0696 
0697 /**
0698  * enum drm_bridge_ops - Bitmask of operations supported by the bridge
0699  */
0700 enum drm_bridge_ops {
0701     /**
0702      * @DRM_BRIDGE_OP_DETECT: The bridge can detect displays connected to
0703      * its output. Bridges that set this flag shall implement the
0704      * &drm_bridge_funcs->detect callback.
0705      */
0706     DRM_BRIDGE_OP_DETECT = BIT(0),
0707     /**
0708      * @DRM_BRIDGE_OP_EDID: The bridge can retrieve the EDID of the display
0709      * connected to its output. Bridges that set this flag shall implement
0710      * the &drm_bridge_funcs->get_edid callback.
0711      */
0712     DRM_BRIDGE_OP_EDID = BIT(1),
0713     /**
0714      * @DRM_BRIDGE_OP_HPD: The bridge can detect hot-plug and hot-unplug
0715      * without requiring polling. Bridges that set this flag shall
0716      * implement the &drm_bridge_funcs->hpd_enable and
0717      * &drm_bridge_funcs->hpd_disable callbacks if they support enabling
0718      * and disabling hot-plug detection dynamically.
0719      */
0720     DRM_BRIDGE_OP_HPD = BIT(2),
0721     /**
0722      * @DRM_BRIDGE_OP_MODES: The bridge can retrieve the modes supported
0723      * by the display at its output. This does not include reading EDID
0724      * which is separately covered by @DRM_BRIDGE_OP_EDID. Bridges that set
0725      * this flag shall implement the &drm_bridge_funcs->get_modes callback.
0726      */
0727     DRM_BRIDGE_OP_MODES = BIT(3),
0728 };
0729 
0730 /**
0731  * struct drm_bridge - central DRM bridge control structure
0732  */
0733 struct drm_bridge {
0734     /** @base: inherit from &drm_private_object */
0735     struct drm_private_obj base;
0736     /** @dev: DRM device this bridge belongs to */
0737     struct drm_device *dev;
0738     /** @encoder: encoder to which this bridge is connected */
0739     struct drm_encoder *encoder;
0740     /** @chain_node: used to form a bridge chain */
0741     struct list_head chain_node;
0742 #ifdef CONFIG_OF
0743     /** @of_node: device node pointer to the bridge */
0744     struct device_node *of_node;
0745 #endif
0746     /** @list: to keep track of all added bridges */
0747     struct list_head list;
0748     /**
0749      * @timings:
0750      *
0751      * the timing specification for the bridge, if any (may be NULL)
0752      */
0753     const struct drm_bridge_timings *timings;
0754     /** @funcs: control functions */
0755     const struct drm_bridge_funcs *funcs;
0756     /** @driver_private: pointer to the bridge driver's internal context */
0757     void *driver_private;
0758     /** @ops: bitmask of operations supported by the bridge */
0759     enum drm_bridge_ops ops;
0760     /**
0761      * @type: Type of the connection at the bridge output
0762      * (DRM_MODE_CONNECTOR_*). For bridges at the end of this chain this
0763      * identifies the type of connected display.
0764      */
0765     int type;
0766     /**
0767      * @interlace_allowed: Indicate that the bridge can handle interlaced
0768      * modes.
0769      */
0770     bool interlace_allowed;
0771     /**
0772      * @ddc: Associated I2C adapter for DDC access, if any.
0773      */
0774     struct i2c_adapter *ddc;
0775     /** private: */
0776     /**
0777      * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields.
0778      */
0779     struct mutex hpd_mutex;
0780     /**
0781      * @hpd_cb: Hot plug detection callback, registered with
0782      * drm_bridge_hpd_enable().
0783      */
0784     void (*hpd_cb)(void *data, enum drm_connector_status status);
0785     /**
0786      * @hpd_data: Private data passed to the Hot plug detection callback
0787      * @hpd_cb.
0788      */
0789     void *hpd_data;
0790 };
0791 
0792 static inline struct drm_bridge *
0793 drm_priv_to_bridge(struct drm_private_obj *priv)
0794 {
0795     return container_of(priv, struct drm_bridge, base);
0796 }
0797 
0798 void drm_bridge_add(struct drm_bridge *bridge);
0799 int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge);
0800 void drm_bridge_remove(struct drm_bridge *bridge);
0801 int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
0802               struct drm_bridge *previous,
0803               enum drm_bridge_attach_flags flags);
0804 
0805 #ifdef CONFIG_OF
0806 struct drm_bridge *of_drm_find_bridge(struct device_node *np);
0807 #else
0808 static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np)
0809 {
0810     return NULL;
0811 }
0812 #endif
0813 
0814 /**
0815  * drm_bridge_get_next_bridge() - Get the next bridge in the chain
0816  * @bridge: bridge object
0817  *
0818  * RETURNS:
0819  * the next bridge in the chain after @bridge, or NULL if @bridge is the last.
0820  */
0821 static inline struct drm_bridge *
0822 drm_bridge_get_next_bridge(struct drm_bridge *bridge)
0823 {
0824     if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain))
0825         return NULL;
0826 
0827     return list_next_entry(bridge, chain_node);
0828 }
0829 
0830 /**
0831  * drm_bridge_get_prev_bridge() - Get the previous bridge in the chain
0832  * @bridge: bridge object
0833  *
0834  * RETURNS:
0835  * the previous bridge in the chain, or NULL if @bridge is the first.
0836  */
0837 static inline struct drm_bridge *
0838 drm_bridge_get_prev_bridge(struct drm_bridge *bridge)
0839 {
0840     if (list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain))
0841         return NULL;
0842 
0843     return list_prev_entry(bridge, chain_node);
0844 }
0845 
0846 /**
0847  * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain
0848  * @encoder: encoder object
0849  *
0850  * RETURNS:
0851  * the first bridge in the chain, or NULL if @encoder has no bridge attached
0852  * to it.
0853  */
0854 static inline struct drm_bridge *
0855 drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder)
0856 {
0857     return list_first_entry_or_null(&encoder->bridge_chain,
0858                     struct drm_bridge, chain_node);
0859 }
0860 
0861 /**
0862  * drm_for_each_bridge_in_chain() - Iterate over all bridges present in a chain
0863  * @encoder: the encoder to iterate bridges on
0864  * @bridge: a bridge pointer updated to point to the current bridge at each
0865  *      iteration
0866  *
0867  * Iterate over all bridges present in the bridge chain attached to @encoder.
0868  */
0869 #define drm_for_each_bridge_in_chain(encoder, bridge)           \
0870     list_for_each_entry(bridge, &(encoder)->bridge_chain, chain_node)
0871 
0872 bool drm_bridge_chain_mode_fixup(struct drm_bridge *bridge,
0873                  const struct drm_display_mode *mode,
0874                  struct drm_display_mode *adjusted_mode);
0875 enum drm_mode_status
0876 drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
0877                 const struct drm_display_info *info,
0878                 const struct drm_display_mode *mode);
0879 void drm_bridge_chain_disable(struct drm_bridge *bridge);
0880 void drm_bridge_chain_post_disable(struct drm_bridge *bridge);
0881 void drm_bridge_chain_mode_set(struct drm_bridge *bridge,
0882                    const struct drm_display_mode *mode,
0883                    const struct drm_display_mode *adjusted_mode);
0884 void drm_bridge_chain_pre_enable(struct drm_bridge *bridge);
0885 void drm_bridge_chain_enable(struct drm_bridge *bridge);
0886 
0887 int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,
0888                   struct drm_crtc_state *crtc_state,
0889                   struct drm_connector_state *conn_state);
0890 void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,
0891                      struct drm_atomic_state *state);
0892 void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,
0893                       struct drm_atomic_state *state);
0894 void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,
0895                     struct drm_atomic_state *state);
0896 void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,
0897                     struct drm_atomic_state *state);
0898 
0899 u32 *
0900 drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
0901                     struct drm_bridge_state *bridge_state,
0902                     struct drm_crtc_state *crtc_state,
0903                     struct drm_connector_state *conn_state,
0904                     u32 output_fmt,
0905                     unsigned int *num_input_fmts);
0906 
0907 enum drm_connector_status drm_bridge_detect(struct drm_bridge *bridge);
0908 int drm_bridge_get_modes(struct drm_bridge *bridge,
0909              struct drm_connector *connector);
0910 struct edid *drm_bridge_get_edid(struct drm_bridge *bridge,
0911                  struct drm_connector *connector);
0912 void drm_bridge_hpd_enable(struct drm_bridge *bridge,
0913                void (*cb)(void *data,
0914                       enum drm_connector_status status),
0915                void *data);
0916 void drm_bridge_hpd_disable(struct drm_bridge *bridge);
0917 void drm_bridge_hpd_notify(struct drm_bridge *bridge,
0918                enum drm_connector_status status);
0919 
0920 #ifdef CONFIG_DRM_PANEL_BRIDGE
0921 bool drm_bridge_is_panel(const struct drm_bridge *bridge);
0922 struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel);
0923 struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
0924                           u32 connector_type);
0925 void drm_panel_bridge_remove(struct drm_bridge *bridge);
0926 int drm_panel_bridge_set_orientation(struct drm_connector *connector,
0927                      struct drm_bridge *bridge);
0928 struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
0929                          struct drm_panel *panel);
0930 struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
0931                            struct drm_panel *panel,
0932                            u32 connector_type);
0933 struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge);
0934 #else
0935 static inline bool drm_bridge_is_panel(const struct drm_bridge *bridge)
0936 {
0937     return false;
0938 }
0939 
0940 static inline int drm_panel_bridge_set_orientation(struct drm_connector *connector,
0941                            struct drm_bridge *bridge)
0942 {
0943     return -EINVAL;
0944 }
0945 #endif
0946 
0947 #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL_BRIDGE)
0948 struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, struct device_node *node,
0949                       u32 port, u32 endpoint);
0950 #else
0951 static inline struct drm_bridge *devm_drm_of_get_bridge(struct device *dev,
0952                             struct device_node *node,
0953                             u32 port,
0954                             u32 endpoint)
0955 {
0956     return ERR_PTR(-ENODEV);
0957 }
0958 #endif
0959 
0960 #endif