2 * Copyright (c) 2016 Intel Corporation
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.
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
23 #ifndef __DRM_BRIDGE_H__
24 #define __DRM_BRIDGE_H__
26 #include <linux/list.h>
27 #include <linux/ctype.h>
29 #include <drm/drm_atomic.h>
30 #include <drm/drm_encoder.h>
31 #include <drm/drm_mode_object.h>
32 #include <drm/drm_modes.h>
35 struct drm_bridge_timings;
39 * struct drm_bridge_funcs - drm_bridge control functions
41 struct drm_bridge_funcs {
45 * This callback is invoked whenever our bridge is being attached to a
48 * The @attach callback is optional.
52 * Zero on success, error code on failure.
54 int (*attach)(struct drm_bridge *bridge);
59 * This callback is invoked whenever our bridge is being detached from a
62 * The @detach callback is optional.
64 void (*detach)(struct drm_bridge *bridge);
69 * This callback is used to check if a specific mode is valid in this
70 * bridge. This should be implemented if the bridge has some sort of
71 * restriction in the modes it can display. For example, a given bridge
72 * may be responsible to set a clock value. If the clock can not
73 * produce all the values for the available modes then this callback
74 * can be used to restrict the number of modes to only the ones that
77 * This hook is used by the probe helpers to filter the mode list in
78 * drm_helper_probe_single_connector_modes(), and it is used by the
79 * atomic helpers to validate modes supplied by userspace in
80 * drm_atomic_helper_check_modeset().
82 * The @mode_valid callback is optional.
86 * Since this function is both called from the check phase of an atomic
87 * commit, and the mode validation in the probe paths it is not allowed
88 * to look at anything else but the passed-in mode, and validate it
89 * against configuration-invariant hardward constraints. Any further
90 * limits which depend upon the configuration can only be checked in
95 * drm_mode_status Enum
97 enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge,
98 const struct drm_display_mode *mode);
103 * This callback is used to validate and adjust a mode. The parameter
104 * mode is the display mode that should be fed to the next element in
105 * the display chain, either the final &drm_connector or the next
106 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
107 * requires. It can be modified by this callback and does not need to
108 * match mode. See also &drm_crtc_state.adjusted_mode for more details.
110 * This is the only hook that allows a bridge to reject a modeset. If
111 * this function passes all other callbacks must succeed for this
114 * The @mode_fixup callback is optional.
118 * This function is called in the check phase of atomic modesets, which
119 * can be aborted for any reason (including on userspace's request to
120 * just check whether a configuration would be possible). Drivers MUST
121 * NOT touch any persistent state (hardware or software) or data
122 * structures except the passed in @state parameter.
124 * Also beware that userspace can request its own custom modes, neither
125 * core nor helpers filter modes to the list of probe modes reported by
126 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
127 * that modes are filtered consistently put any bridge constraints and
128 * limits checks into @mode_valid.
132 * True if an acceptable configuration is possible, false if the modeset
133 * operation should be rejected.
135 bool (*mode_fixup)(struct drm_bridge *bridge,
136 const struct drm_display_mode *mode,
137 struct drm_display_mode *adjusted_mode);
141 * This callback should disable the bridge. It is called right before
142 * the preceding element in the display pipe is disabled. If the
143 * preceding element is a bridge this means it's called before that
144 * bridge's @disable vfunc. If the preceding element is a &drm_encoder
145 * it's called right before the &drm_encoder_helper_funcs.disable,
146 * &drm_encoder_helper_funcs.prepare or &drm_encoder_helper_funcs.dpms
149 * The bridge can assume that the display pipe (i.e. clocks and timing
150 * signals) feeding it is still running when this callback is called.
152 * The @disable callback is optional.
154 void (*disable)(struct drm_bridge *bridge);
159 * This callback should disable the bridge. It is called right after the
160 * preceding element in the display pipe is disabled. If the preceding
161 * element is a bridge this means it's called after that bridge's
162 * @post_disable function. If the preceding element is a &drm_encoder
163 * it's called right after the encoder's
164 * &drm_encoder_helper_funcs.disable, &drm_encoder_helper_funcs.prepare
165 * or &drm_encoder_helper_funcs.dpms hook.
167 * The bridge must assume that the display pipe (i.e. clocks and timing
168 * singals) feeding it is no longer running when this callback is
171 * The @post_disable callback is optional.
173 void (*post_disable)(struct drm_bridge *bridge);
178 * This callback should set the given mode on the bridge. It is called
179 * after the @mode_set callback for the preceding element in the display
180 * pipeline has been called already. If the bridge is the first element
181 * then this would be &drm_encoder_helper_funcs.mode_set. The display
182 * pipe (i.e. clocks and timing signals) is off when this function is
185 * The adjusted_mode parameter is the mode output by the CRTC for the
186 * first bridge in the chain. It can be different from the mode
187 * parameter that contains the desired mode for the connector at the end
188 * of the bridges chain, for instance when the first bridge in the chain
189 * performs scaling. The adjusted mode is mostly useful for the first
190 * bridge in the chain and is likely irrelevant for the other bridges.
192 * For atomic drivers the adjusted_mode is the mode stored in
193 * &drm_crtc_state.adjusted_mode.
197 * If a need arises to store and access modes adjusted for other
198 * locations than the connection between the CRTC and the first bridge,
199 * the DRM framework will have to be extended with DRM bridge states.
201 void (*mode_set)(struct drm_bridge *bridge,
202 const struct drm_display_mode *mode,
203 const struct drm_display_mode *adjusted_mode);
207 * This callback should enable the bridge. It is called right before
208 * the preceding element in the display pipe is enabled. If the
209 * preceding element is a bridge this means it's called before that
210 * bridge's @pre_enable function. If the preceding element is a
211 * &drm_encoder it's called right before the encoder's
212 * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
213 * &drm_encoder_helper_funcs.dpms hook.
215 * The display pipe (i.e. clocks and timing signals) feeding this bridge
216 * will not yet be running when this callback is called. The bridge must
217 * not enable the display link feeding the next bridge in the chain (if
218 * there is one) when this callback is called.
220 * The @pre_enable callback is optional.
222 void (*pre_enable)(struct drm_bridge *bridge);
227 * This callback should enable the bridge. It is called right after
228 * the preceding element in the display pipe is enabled. If the
229 * preceding element is a bridge this means it's called after that
230 * bridge's @enable function. If the preceding element is a
231 * &drm_encoder it's called right after the encoder's
232 * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
233 * &drm_encoder_helper_funcs.dpms hook.
235 * The bridge can assume that the display pipe (i.e. clocks and timing
236 * signals) feeding it is running when this callback is called. This
237 * callback must enable the display link feeding the next bridge in the
238 * chain if there is one.
240 * The @enable callback is optional.
242 void (*enable)(struct drm_bridge *bridge);
245 * @atomic_pre_enable:
247 * This callback should enable the bridge. It is called right before
248 * the preceding element in the display pipe is enabled. If the
249 * preceding element is a bridge this means it's called before that
250 * bridge's @atomic_pre_enable or @pre_enable function. If the preceding
251 * element is a &drm_encoder it's called right before the encoder's
252 * &drm_encoder_helper_funcs.atomic_enable hook.
254 * The display pipe (i.e. clocks and timing signals) feeding this bridge
255 * will not yet be running when this callback is called. The bridge must
256 * not enable the display link feeding the next bridge in the chain (if
257 * there is one) when this callback is called.
259 * Note that this function will only be invoked in the context of an
260 * atomic commit. It will not be invoked from
261 * &drm_bridge_chain_pre_enable. It would be prudent to also provide an
262 * implementation of @pre_enable if you are expecting driver calls into
263 * &drm_bridge_chain_pre_enable.
265 * The @atomic_pre_enable callback is optional.
267 void (*atomic_pre_enable)(struct drm_bridge *bridge,
268 struct drm_atomic_state *old_state);
273 * This callback should enable the bridge. It is called right after
274 * the preceding element in the display pipe is enabled. If the
275 * preceding element is a bridge this means it's called after that
276 * bridge's @atomic_enable or @enable function. If the preceding element
277 * is a &drm_encoder it's called right after the encoder's
278 * &drm_encoder_helper_funcs.atomic_enable hook.
280 * The bridge can assume that the display pipe (i.e. clocks and timing
281 * signals) feeding it is running when this callback is called. This
282 * callback must enable the display link feeding the next bridge in the
283 * chain if there is one.
285 * Note that this function will only be invoked in the context of an
286 * atomic commit. It will not be invoked from &drm_bridge_chain_enable.
287 * It would be prudent to also provide an implementation of @enable if
288 * you are expecting driver calls into &drm_bridge_chain_enable.
290 * The @atomic_enable callback is optional.
292 void (*atomic_enable)(struct drm_bridge *bridge,
293 struct drm_atomic_state *old_state);
297 * This callback should disable the bridge. It is called right before
298 * the preceding element in the display pipe is disabled. If the
299 * preceding element is a bridge this means it's called before that
300 * bridge's @atomic_disable or @disable vfunc. If the preceding element
301 * is a &drm_encoder it's called right before the
302 * &drm_encoder_helper_funcs.atomic_disable hook.
304 * The bridge can assume that the display pipe (i.e. clocks and timing
305 * signals) feeding it is still running when this callback is called.
307 * Note that this function will only be invoked in the context of an
308 * atomic commit. It will not be invoked from
309 * &drm_bridge_chain_disable. It would be prudent to also provide an
310 * implementation of @disable if you are expecting driver calls into
311 * &drm_bridge_chain_disable.
313 * The @atomic_disable callback is optional.
315 void (*atomic_disable)(struct drm_bridge *bridge,
316 struct drm_atomic_state *old_state);
319 * @atomic_post_disable:
321 * This callback should disable the bridge. It is called right after the
322 * preceding element in the display pipe is disabled. If the preceding
323 * element is a bridge this means it's called after that bridge's
324 * @atomic_post_disable or @post_disable function. If the preceding
325 * element is a &drm_encoder it's called right after the encoder's
326 * &drm_encoder_helper_funcs.atomic_disable hook.
328 * The bridge must assume that the display pipe (i.e. clocks and timing
329 * signals) feeding it is no longer running when this callback is
332 * Note that this function will only be invoked in the context of an
333 * atomic commit. It will not be invoked from
334 * &drm_bridge_chain_post_disable.
335 * It would be prudent to also provide an implementation of
336 * @post_disable if you are expecting driver calls into
337 * &drm_bridge_chain_post_disable.
339 * The @atomic_post_disable callback is optional.
341 void (*atomic_post_disable)(struct drm_bridge *bridge,
342 struct drm_atomic_state *old_state);
345 * @atomic_duplicate_state:
347 * Duplicate the current bridge state object (which is guaranteed to be
350 * The atomic_duplicate_state() is optional. When not implemented the
351 * core allocates a drm_bridge_state object and calls
352 * &__drm_atomic_helper_bridge_duplicate_state() to initialize it.
355 * A valid drm_bridge_state object or NULL if the allocation fails.
357 struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge);
360 * @atomic_destroy_state:
362 * Destroy a bridge state object previously allocated by
363 * &drm_bridge_funcs.atomic_duplicate_state().
365 * The atomic_destroy_state hook is optional. When not implemented the
366 * core calls kfree() on the state.
368 void (*atomic_destroy_state)(struct drm_bridge *bridge,
369 struct drm_bridge_state *state);
374 * Reset the bridge to a predefined state (or retrieve its current
375 * state) and return a &drm_bridge_state object matching this state.
376 * This function is called at attach time.
378 * The atomic_reset hook is mandatory if the bridge implements any of
379 * the atomic hooks, and should be left unassigned otherwise.
381 * Note that the atomic_reset() semantics is not exactly matching the
382 * reset() semantics found on other components (connector, plane, ...).
383 * 1/ The reset operation happens when the bridge is attached, not when
384 * drm_mode_config_reset() is called
385 * 2/ It's meant to be used exclusively on bridges that have been
386 * converted to the ATOMIC API
389 * A valid drm_bridge_state object in case of success, an ERR_PTR()
390 * giving the reason of the failure otherwise.
392 struct drm_bridge_state *(*atomic_reset)(struct drm_bridge *bridge);
396 * struct drm_bridge_timings - timing information for the bridge
398 struct drm_bridge_timings {
402 * Tells what additional settings for the pixel data on the bus
403 * this bridge requires (like pixel signal polarity). See also
404 * &drm_display_info->bus_flags.
410 * Defines the time in picoseconds the input data lines must be
411 * stable before the clock edge.
417 * Defines the time in picoseconds taken for the bridge to sample the
418 * input signal after the clock edge.
424 * True if the bus operates in dual-link mode. The exact meaning is
425 * dependent on the bus type. For LVDS buses, this indicates that even-
426 * and odd-numbered pixels are received on separate links.
432 * struct drm_bridge - central DRM bridge control structure
435 /** @base: inherit from &drm_private_object */
436 struct drm_private_obj base;
437 /** @dev: DRM device this bridge belongs to */
438 struct drm_device *dev;
439 /** @encoder: encoder to which this bridge is connected */
440 struct drm_encoder *encoder;
441 /** @chain_node: used to form a bridge chain */
442 struct list_head chain_node;
444 /** @of_node: device node pointer to the bridge */
445 struct device_node *of_node;
447 /** @list: to keep track of all added bridges */
448 struct list_head list;
452 * the timing specification for the bridge, if any (may be NULL)
454 const struct drm_bridge_timings *timings;
455 /** @funcs: control functions */
456 const struct drm_bridge_funcs *funcs;
457 /** @driver_private: pointer to the bridge driver's internal context */
458 void *driver_private;
461 static inline struct drm_bridge *
462 drm_priv_to_bridge(struct drm_private_obj *priv)
464 return container_of(priv, struct drm_bridge, base);
467 void drm_bridge_add(struct drm_bridge *bridge);
468 void drm_bridge_remove(struct drm_bridge *bridge);
469 struct drm_bridge *of_drm_find_bridge(struct device_node *np);
470 int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
471 struct drm_bridge *previous);
474 * drm_bridge_get_next_bridge() - Get the next bridge in the chain
475 * @bridge: bridge object
478 * the next bridge in the chain after @bridge, or NULL if @bridge is the last.
480 static inline struct drm_bridge *
481 drm_bridge_get_next_bridge(struct drm_bridge *bridge)
483 if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain))
486 return list_next_entry(bridge, chain_node);
490 * drm_bridge_get_prev_bridge() - Get the previous bridge in the chain
491 * @bridge: bridge object
494 * the previous bridge in the chain, or NULL if @bridge is the first.
496 static inline struct drm_bridge *
497 drm_bridge_get_prev_bridge(struct drm_bridge *bridge)
499 if (list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain))
502 return list_prev_entry(bridge, chain_node);
506 * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain
507 * @encoder: encoder object
510 * the first bridge in the chain, or NULL if @encoder has no bridge attached
513 static inline struct drm_bridge *
514 drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder)
516 return list_first_entry_or_null(&encoder->bridge_chain,
517 struct drm_bridge, chain_node);
521 * drm_for_each_bridge_in_chain() - Iterate over all bridges present in a chain
522 * @encoder: the encoder to iterate bridges on
523 * @bridge: a bridge pointer updated to point to the current bridge at each
526 * Iterate over all bridges present in the bridge chain attached to @encoder.
528 #define drm_for_each_bridge_in_chain(encoder, bridge) \
529 list_for_each_entry(bridge, &(encoder)->bridge_chain, chain_node)
531 bool drm_bridge_chain_mode_fixup(struct drm_bridge *bridge,
532 const struct drm_display_mode *mode,
533 struct drm_display_mode *adjusted_mode);
535 drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
536 const struct drm_display_mode *mode);
537 void drm_bridge_chain_disable(struct drm_bridge *bridge);
538 void drm_bridge_chain_post_disable(struct drm_bridge *bridge);
539 void drm_bridge_chain_mode_set(struct drm_bridge *bridge,
540 const struct drm_display_mode *mode,
541 const struct drm_display_mode *adjusted_mode);
542 void drm_bridge_chain_pre_enable(struct drm_bridge *bridge);
543 void drm_bridge_chain_enable(struct drm_bridge *bridge);
545 void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,
546 struct drm_atomic_state *state);
547 void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,
548 struct drm_atomic_state *state);
549 void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,
550 struct drm_atomic_state *state);
551 void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,
552 struct drm_atomic_state *state);
554 #ifdef CONFIG_DRM_PANEL_BRIDGE
555 struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel);
556 struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
558 void drm_panel_bridge_remove(struct drm_bridge *bridge);
559 struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
560 struct drm_panel *panel);
561 struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
562 struct drm_panel *panel,
564 struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge);