OSDN Git Service

drm/i915: Update DRIVER_DATE to 20200114
[tomoyo/tomoyo-test1.git] / include / drm / drm_bridge.h
1 /*
2  * Copyright (c) 2016 Intel Corporation
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting documentation, and
8  * that the name of the copyright holders not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission.  The copyright holders make no representations
11  * about the suitability of this software for any purpose.  It is provided "as
12  * is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20  * OF THIS SOFTWARE.
21  */
22
23 #ifndef __DRM_BRIDGE_H__
24 #define __DRM_BRIDGE_H__
25
26 #include <linux/list.h>
27 #include <linux/ctype.h>
28
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>
33
34 struct drm_bridge;
35 struct drm_bridge_timings;
36 struct drm_panel;
37
38 /**
39  * struct drm_bus_cfg - bus configuration
40  *
41  * This structure stores the configuration of a physical bus between two
42  * components in an output pipeline, usually between two bridges, an encoder
43  * and a bridge, or a bridge and a connector.
44  *
45  * The bus configuration is stored in &drm_bridge_state separately for the
46  * input and output buses, as seen from the point of view of each bridge. The
47  * bus configuration of a bridge output is usually identical to the
48  * configuration of the next bridge's input, but may differ if the signals are
49  * modified between the two bridges, for instance by an inverter on the board.
50  * The input and output configurations of a bridge may differ if the bridge
51  * modifies the signals internally, for instance by performing format
52  * conversion, or modifying signals polarities.
53  */
54 struct drm_bus_cfg {
55         /**
56          * @format: format used on this bus (one of the MEDIA_BUS_FMT_* format)
57          *
58          * This field should not be directly modified by drivers
59          * (&drm_atomic_bridge_chain_select_bus_fmts() takes care of the bus
60          * format negotiation).
61          */
62         u32 format;
63
64         /**
65          * @flags: DRM_BUS_* flags used on this bus
66          */
67         u32 flags;
68 };
69
70 /**
71  * struct drm_bridge_state - Atomic bridge state object
72  * @base: inherit from &drm_private_state
73  * @bridge: the bridge this state refers to
74  */
75 struct drm_bridge_state {
76         struct drm_private_state base;
77
78         struct drm_bridge *bridge;
79
80         /**
81          * @input_bus_cfg: input bus configuration
82          */
83         struct drm_bus_cfg input_bus_cfg;
84
85         /**
86          * @output_bus_cfg: input bus configuration
87          */
88         struct drm_bus_cfg output_bus_cfg;
89 };
90
91 static inline struct drm_bridge_state *
92 drm_priv_to_bridge_state(struct drm_private_state *priv)
93 {
94         return container_of(priv, struct drm_bridge_state, base);
95 }
96
97 /**
98  * struct drm_bridge_funcs - drm_bridge control functions
99  */
100 struct drm_bridge_funcs {
101         /**
102          * @attach:
103          *
104          * This callback is invoked whenever our bridge is being attached to a
105          * &drm_encoder.
106          *
107          * The @attach callback is optional.
108          *
109          * RETURNS:
110          *
111          * Zero on success, error code on failure.
112          */
113         int (*attach)(struct drm_bridge *bridge);
114
115         /**
116          * @detach:
117          *
118          * This callback is invoked whenever our bridge is being detached from a
119          * &drm_encoder.
120          *
121          * The @detach callback is optional.
122          */
123         void (*detach)(struct drm_bridge *bridge);
124
125         /**
126          * @mode_valid:
127          *
128          * This callback is used to check if a specific mode is valid in this
129          * bridge. This should be implemented if the bridge has some sort of
130          * restriction in the modes it can display. For example, a given bridge
131          * may be responsible to set a clock value. If the clock can not
132          * produce all the values for the available modes then this callback
133          * can be used to restrict the number of modes to only the ones that
134          * can be displayed.
135          *
136          * This hook is used by the probe helpers to filter the mode list in
137          * drm_helper_probe_single_connector_modes(), and it is used by the
138          * atomic helpers to validate modes supplied by userspace in
139          * drm_atomic_helper_check_modeset().
140          *
141          * The @mode_valid callback is optional.
142          *
143          * NOTE:
144          *
145          * Since this function is both called from the check phase of an atomic
146          * commit, and the mode validation in the probe paths it is not allowed
147          * to look at anything else but the passed-in mode, and validate it
148          * against configuration-invariant hardward constraints. Any further
149          * limits which depend upon the configuration can only be checked in
150          * @mode_fixup.
151          *
152          * RETURNS:
153          *
154          * drm_mode_status Enum
155          */
156         enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge,
157                                            const struct drm_display_mode *mode);
158
159         /**
160          * @mode_fixup:
161          *
162          * This callback is used to validate and adjust a mode. The parameter
163          * mode is the display mode that should be fed to the next element in
164          * the display chain, either the final &drm_connector or the next
165          * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
166          * requires. It can be modified by this callback and does not need to
167          * match mode. See also &drm_crtc_state.adjusted_mode for more details.
168          *
169          * This is the only hook that allows a bridge to reject a modeset. If
170          * this function passes all other callbacks must succeed for this
171          * configuration.
172          *
173          * The mode_fixup callback is optional. &drm_bridge_funcs.mode_fixup()
174          * is not called when &drm_bridge_funcs.atomic_check() is implemented,
175          * so only one of them should be provided.
176          *
177          * NOTE:
178          *
179          * This function is called in the check phase of atomic modesets, which
180          * can be aborted for any reason (including on userspace's request to
181          * just check whether a configuration would be possible). Drivers MUST
182          * NOT touch any persistent state (hardware or software) or data
183          * structures except the passed in @state parameter.
184          *
185          * Also beware that userspace can request its own custom modes, neither
186          * core nor helpers filter modes to the list of probe modes reported by
187          * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
188          * that modes are filtered consistently put any bridge constraints and
189          * limits checks into @mode_valid.
190          *
191          * RETURNS:
192          *
193          * True if an acceptable configuration is possible, false if the modeset
194          * operation should be rejected.
195          */
196         bool (*mode_fixup)(struct drm_bridge *bridge,
197                            const struct drm_display_mode *mode,
198                            struct drm_display_mode *adjusted_mode);
199         /**
200          * @disable:
201          *
202          * This callback should disable the bridge. It is called right before
203          * the preceding element in the display pipe is disabled. If the
204          * preceding element is a bridge this means it's called before that
205          * bridge's @disable vfunc. If the preceding element is a &drm_encoder
206          * it's called right before the &drm_encoder_helper_funcs.disable,
207          * &drm_encoder_helper_funcs.prepare or &drm_encoder_helper_funcs.dpms
208          * hook.
209          *
210          * The bridge can assume that the display pipe (i.e. clocks and timing
211          * signals) feeding it is still running when this callback is called.
212          *
213          * The @disable callback is optional.
214          */
215         void (*disable)(struct drm_bridge *bridge);
216
217         /**
218          * @post_disable:
219          *
220          * This callback should disable the bridge. It is called right after the
221          * preceding element in the display pipe is disabled. If the preceding
222          * element is a bridge this means it's called after that bridge's
223          * @post_disable function. If the preceding element is a &drm_encoder
224          * it's called right after the encoder's
225          * &drm_encoder_helper_funcs.disable, &drm_encoder_helper_funcs.prepare
226          * or &drm_encoder_helper_funcs.dpms hook.
227          *
228          * The bridge must assume that the display pipe (i.e. clocks and timing
229          * singals) feeding it is no longer running when this callback is
230          * called.
231          *
232          * The @post_disable callback is optional.
233          */
234         void (*post_disable)(struct drm_bridge *bridge);
235
236         /**
237          * @mode_set:
238          *
239          * This callback should set the given mode on the bridge. It is called
240          * after the @mode_set callback for the preceding element in the display
241          * pipeline has been called already. If the bridge is the first element
242          * then this would be &drm_encoder_helper_funcs.mode_set. The display
243          * pipe (i.e.  clocks and timing signals) is off when this function is
244          * called.
245          *
246          * The adjusted_mode parameter is the mode output by the CRTC for the
247          * first bridge in the chain. It can be different from the mode
248          * parameter that contains the desired mode for the connector at the end
249          * of the bridges chain, for instance when the first bridge in the chain
250          * performs scaling. The adjusted mode is mostly useful for the first
251          * bridge in the chain and is likely irrelevant for the other bridges.
252          *
253          * For atomic drivers the adjusted_mode is the mode stored in
254          * &drm_crtc_state.adjusted_mode.
255          *
256          * NOTE:
257          *
258          * If a need arises to store and access modes adjusted for other
259          * locations than the connection between the CRTC and the first bridge,
260          * the DRM framework will have to be extended with DRM bridge states.
261          */
262         void (*mode_set)(struct drm_bridge *bridge,
263                          const struct drm_display_mode *mode,
264                          const struct drm_display_mode *adjusted_mode);
265         /**
266          * @pre_enable:
267          *
268          * This callback should enable the bridge. It is called right before
269          * the preceding element in the display pipe is enabled. If the
270          * preceding element is a bridge this means it's called before that
271          * bridge's @pre_enable function. If the preceding element is a
272          * &drm_encoder it's called right before the encoder's
273          * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
274          * &drm_encoder_helper_funcs.dpms hook.
275          *
276          * The display pipe (i.e. clocks and timing signals) feeding this bridge
277          * will not yet be running when this callback is called. The bridge must
278          * not enable the display link feeding the next bridge in the chain (if
279          * there is one) when this callback is called.
280          *
281          * The @pre_enable callback is optional.
282          */
283         void (*pre_enable)(struct drm_bridge *bridge);
284
285         /**
286          * @enable:
287          *
288          * This callback should enable the bridge. It is called right after
289          * the preceding element in the display pipe is enabled. If the
290          * preceding element is a bridge this means it's called after that
291          * bridge's @enable function. If the preceding element is a
292          * &drm_encoder it's called right after the encoder's
293          * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
294          * &drm_encoder_helper_funcs.dpms hook.
295          *
296          * The bridge can assume that the display pipe (i.e. clocks and timing
297          * signals) feeding it is running when this callback is called. This
298          * callback must enable the display link feeding the next bridge in the
299          * chain if there is one.
300          *
301          * The @enable callback is optional.
302          */
303         void (*enable)(struct drm_bridge *bridge);
304
305         /**
306          * @atomic_pre_enable:
307          *
308          * This callback should enable the bridge. It is called right before
309          * the preceding element in the display pipe is enabled. If the
310          * preceding element is a bridge this means it's called before that
311          * bridge's @atomic_pre_enable or @pre_enable function. If the preceding
312          * element is a &drm_encoder it's called right before the encoder's
313          * &drm_encoder_helper_funcs.atomic_enable hook.
314          *
315          * The display pipe (i.e. clocks and timing signals) feeding this bridge
316          * will not yet be running when this callback is called. The bridge must
317          * not enable the display link feeding the next bridge in the chain (if
318          * there is one) when this callback is called.
319          *
320          * Note that this function will only be invoked in the context of an
321          * atomic commit. It will not be invoked from
322          * &drm_bridge_chain_pre_enable. It would be prudent to also provide an
323          * implementation of @pre_enable if you are expecting driver calls into
324          * &drm_bridge_chain_pre_enable.
325          *
326          * The @atomic_pre_enable callback is optional.
327          */
328         void (*atomic_pre_enable)(struct drm_bridge *bridge,
329                                   struct drm_bridge_state *old_bridge_state);
330
331         /**
332          * @atomic_enable:
333          *
334          * This callback should enable the bridge. It is called right after
335          * the preceding element in the display pipe is enabled. If the
336          * preceding element is a bridge this means it's called after that
337          * bridge's @atomic_enable or @enable function. If the preceding element
338          * is a &drm_encoder it's called right after the encoder's
339          * &drm_encoder_helper_funcs.atomic_enable hook.
340          *
341          * The bridge can assume that the display pipe (i.e. clocks and timing
342          * signals) feeding it is running when this callback is called. This
343          * callback must enable the display link feeding the next bridge in the
344          * chain if there is one.
345          *
346          * Note that this function will only be invoked in the context of an
347          * atomic commit. It will not be invoked from &drm_bridge_chain_enable.
348          * It would be prudent to also provide an implementation of @enable if
349          * you are expecting driver calls into &drm_bridge_chain_enable.
350          *
351          * The @atomic_enable callback is optional.
352          */
353         void (*atomic_enable)(struct drm_bridge *bridge,
354                               struct drm_bridge_state *old_bridge_state);
355         /**
356          * @atomic_disable:
357          *
358          * This callback should disable the bridge. It is called right before
359          * the preceding element in the display pipe is disabled. If the
360          * preceding element is a bridge this means it's called before that
361          * bridge's @atomic_disable or @disable vfunc. If the preceding element
362          * is a &drm_encoder it's called right before the
363          * &drm_encoder_helper_funcs.atomic_disable hook.
364          *
365          * The bridge can assume that the display pipe (i.e. clocks and timing
366          * signals) feeding it is still running when this callback is called.
367          *
368          * Note that this function will only be invoked in the context of an
369          * atomic commit. It will not be invoked from
370          * &drm_bridge_chain_disable. It would be prudent to also provide an
371          * implementation of @disable if you are expecting driver calls into
372          * &drm_bridge_chain_disable.
373          *
374          * The @atomic_disable callback is optional.
375          */
376         void (*atomic_disable)(struct drm_bridge *bridge,
377                                struct drm_bridge_state *old_bridge_state);
378
379         /**
380          * @atomic_post_disable:
381          *
382          * This callback should disable the bridge. It is called right after the
383          * preceding element in the display pipe is disabled. If the preceding
384          * element is a bridge this means it's called after that bridge's
385          * @atomic_post_disable or @post_disable function. If the preceding
386          * element is a &drm_encoder it's called right after the encoder's
387          * &drm_encoder_helper_funcs.atomic_disable hook.
388          *
389          * The bridge must assume that the display pipe (i.e. clocks and timing
390          * signals) feeding it is no longer running when this callback is
391          * called.
392          *
393          * Note that this function will only be invoked in the context of an
394          * atomic commit. It will not be invoked from
395          * &drm_bridge_chain_post_disable.
396          * It would be prudent to also provide an implementation of
397          * @post_disable if you are expecting driver calls into
398          * &drm_bridge_chain_post_disable.
399          *
400          * The @atomic_post_disable callback is optional.
401          */
402         void (*atomic_post_disable)(struct drm_bridge *bridge,
403                                     struct drm_bridge_state *old_bridge_state);
404
405         /**
406          * @atomic_duplicate_state:
407          *
408          * Duplicate the current bridge state object (which is guaranteed to be
409          * non-NULL).
410          *
411          * The atomic_duplicate_state() is optional. When not implemented the
412          * core allocates a drm_bridge_state object and calls
413          * &__drm_atomic_helper_bridge_duplicate_state() to initialize it.
414          *
415          * RETURNS:
416          * A valid drm_bridge_state object or NULL if the allocation fails.
417          */
418         struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge);
419
420         /**
421          * @atomic_destroy_state:
422          *
423          * Destroy a bridge state object previously allocated by
424          * &drm_bridge_funcs.atomic_duplicate_state().
425          *
426          * The atomic_destroy_state hook is optional. When not implemented the
427          * core calls kfree() on the state.
428          */
429         void (*atomic_destroy_state)(struct drm_bridge *bridge,
430                                      struct drm_bridge_state *state);
431
432         /**
433          * @atomic_get_output_bus_fmts:
434          *
435          * Return the supported bus formats on the output end of a bridge.
436          * The returned array must be allocated with kmalloc() and will be
437          * freed by the caller. If the allocation fails, NULL should be
438          * returned. num_output_fmts must be set to the returned array size.
439          * Formats listed in the returned array should be listed in decreasing
440          * preference order (the core will try all formats until it finds one
441          * that works).
442          *
443          * This method is only called on the last element of the bridge chain
444          * as part of the bus format negotiation process that happens in
445          * &drm_atomic_bridge_chain_select_bus_fmts().
446          * This method is optional. When not implemented, the core will
447          * fall back to &drm_connector.display_info.bus_formats[0] if
448          * &drm_connector.display_info.num_bus_formats > 0,
449          * or to MEDIA_BUS_FMT_FIXED otherwise.
450          */
451         u32 *(*atomic_get_output_bus_fmts)(struct drm_bridge *bridge,
452                                            struct drm_bridge_state *bridge_state,
453                                            struct drm_crtc_state *crtc_state,
454                                            struct drm_connector_state *conn_state,
455                                            unsigned int *num_output_fmts);
456
457         /**
458          * @atomic_get_input_bus_fmts:
459          *
460          * Return the supported bus formats on the input end of a bridge for
461          * a specific output bus format.
462          *
463          * The returned array must be allocated with kmalloc() and will be
464          * freed by the caller. If the allocation fails, NULL should be
465          * returned. num_output_fmts must be set to the returned array size.
466          * Formats listed in the returned array should be listed in decreasing
467          * preference order (the core will try all formats until it finds one
468          * that works). When the format is not supported NULL should be
469          * returned and *num_output_fmts should be set to 0.
470          *
471          * This method is called on all elements of the bridge chain as part of
472          * the bus format negotiation process that happens in
473          * &drm_atomic_bridge_chain_select_bus_fmts().
474          * This method is optional. When not implemented, the core will bypass
475          * bus format negotiation on this element of the bridge without
476          * failing, and the previous element in the chain will be passed
477          * MEDIA_BUS_FMT_FIXED as its output bus format.
478          *
479          * Bridge drivers that need to support being linked to bridges that are
480          * not supporting bus format negotiation should handle the
481          * output_fmt == MEDIA_BUS_FMT_FIXED case appropriately, by selecting a
482          * sensible default value or extracting this information from somewhere
483          * else (FW property, &drm_display_mode, &drm_display_info, ...)
484          *
485          * Note: Even if input format selection on the first bridge has no
486          * impact on the negotiation process (bus format negotiation stops once
487          * we reach the first element of the chain), drivers are expected to
488          * return accurate input formats as the input format may be used to
489          * configure the CRTC output appropriately.
490          */
491         u32 *(*atomic_get_input_bus_fmts)(struct drm_bridge *bridge,
492                                           struct drm_bridge_state *bridge_state,
493                                           struct drm_crtc_state *crtc_state,
494                                           struct drm_connector_state *conn_state,
495                                           u32 output_fmt,
496                                           unsigned int *num_input_fmts);
497
498         /**
499          * @atomic_check:
500          *
501          * This method is responsible for checking bridge state correctness.
502          * It can also check the state of the surrounding components in chain
503          * to make sure the whole pipeline can work properly.
504          *
505          * &drm_bridge_funcs.atomic_check() hooks are called in reverse
506          * order (from the last to the first bridge).
507          *
508          * This method is optional. &drm_bridge_funcs.mode_fixup() is not
509          * called when &drm_bridge_funcs.atomic_check() is implemented, so only
510          * one of them should be provided.
511          *
512          * If drivers need to tweak &drm_bridge_state.input_bus_cfg.flags or
513          * &drm_bridge_state.output_bus_cfg.flags it should should happen in
514          * this function. By default the &drm_bridge_state.output_bus_cfg.flags
515          * field is set to the next bridge
516          * &drm_bridge_state.input_bus_cfg.flags value or
517          * &drm_connector.display_info.bus_flags if the bridge is the last
518          * element in the chain.
519          *
520          * RETURNS:
521          * zero if the check passed, a negative error code otherwise.
522          */
523         int (*atomic_check)(struct drm_bridge *bridge,
524                             struct drm_bridge_state *bridge_state,
525                             struct drm_crtc_state *crtc_state,
526                             struct drm_connector_state *conn_state);
527
528         /**
529          * @atomic_reset:
530          *
531          * Reset the bridge to a predefined state (or retrieve its current
532          * state) and return a &drm_bridge_state object matching this state.
533          * This function is called at attach time.
534          *
535          * The atomic_reset hook is optional. When not implemented the core
536          * allocates a new state and calls &__drm_atomic_helper_bridge_reset().
537          *
538          * RETURNS:
539          * A valid drm_bridge_state object in case of success, an ERR_PTR()
540          * giving the reason of the failure otherwise.
541          */
542         struct drm_bridge_state *(*atomic_reset)(struct drm_bridge *bridge);
543 };
544
545 /**
546  * struct drm_bridge_timings - timing information for the bridge
547  */
548 struct drm_bridge_timings {
549         /**
550          * @input_bus_flags:
551          *
552          * Tells what additional settings for the pixel data on the bus
553          * this bridge requires (like pixel signal polarity). See also
554          * &drm_display_info->bus_flags.
555          */
556         u32 input_bus_flags;
557         /**
558          * @setup_time_ps:
559          *
560          * Defines the time in picoseconds the input data lines must be
561          * stable before the clock edge.
562          */
563         u32 setup_time_ps;
564         /**
565          * @hold_time_ps:
566          *
567          * Defines the time in picoseconds taken for the bridge to sample the
568          * input signal after the clock edge.
569          */
570         u32 hold_time_ps;
571         /**
572          * @dual_link:
573          *
574          * True if the bus operates in dual-link mode. The exact meaning is
575          * dependent on the bus type. For LVDS buses, this indicates that even-
576          * and odd-numbered pixels are received on separate links.
577          */
578         bool dual_link;
579 };
580
581 /**
582  * struct drm_bridge - central DRM bridge control structure
583  */
584 struct drm_bridge {
585         /** @base: inherit from &drm_private_object */
586         struct drm_private_obj base;
587         /** @dev: DRM device this bridge belongs to */
588         struct drm_device *dev;
589         /** @encoder: encoder to which this bridge is connected */
590         struct drm_encoder *encoder;
591         /** @chain_node: used to form a bridge chain */
592         struct list_head chain_node;
593 #ifdef CONFIG_OF
594         /** @of_node: device node pointer to the bridge */
595         struct device_node *of_node;
596 #endif
597         /** @list: to keep track of all added bridges */
598         struct list_head list;
599         /**
600          * @timings:
601          *
602          * the timing specification for the bridge, if any (may be NULL)
603          */
604         const struct drm_bridge_timings *timings;
605         /** @funcs: control functions */
606         const struct drm_bridge_funcs *funcs;
607         /** @driver_private: pointer to the bridge driver's internal context */
608         void *driver_private;
609 };
610
611 static inline struct drm_bridge *
612 drm_priv_to_bridge(struct drm_private_obj *priv)
613 {
614         return container_of(priv, struct drm_bridge, base);
615 }
616
617 void drm_bridge_add(struct drm_bridge *bridge);
618 void drm_bridge_remove(struct drm_bridge *bridge);
619 struct drm_bridge *of_drm_find_bridge(struct device_node *np);
620 int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
621                       struct drm_bridge *previous);
622
623 /**
624  * drm_bridge_get_next_bridge() - Get the next bridge in the chain
625  * @bridge: bridge object
626  *
627  * RETURNS:
628  * the next bridge in the chain after @bridge, or NULL if @bridge is the last.
629  */
630 static inline struct drm_bridge *
631 drm_bridge_get_next_bridge(struct drm_bridge *bridge)
632 {
633         if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain))
634                 return NULL;
635
636         return list_next_entry(bridge, chain_node);
637 }
638
639 /**
640  * drm_bridge_get_prev_bridge() - Get the previous bridge in the chain
641  * @bridge: bridge object
642  *
643  * RETURNS:
644  * the previous bridge in the chain, or NULL if @bridge is the first.
645  */
646 static inline struct drm_bridge *
647 drm_bridge_get_prev_bridge(struct drm_bridge *bridge)
648 {
649         if (list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain))
650                 return NULL;
651
652         return list_prev_entry(bridge, chain_node);
653 }
654
655 /**
656  * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain
657  * @encoder: encoder object
658  *
659  * RETURNS:
660  * the first bridge in the chain, or NULL if @encoder has no bridge attached
661  * to it.
662  */
663 static inline struct drm_bridge *
664 drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder)
665 {
666         return list_first_entry_or_null(&encoder->bridge_chain,
667                                         struct drm_bridge, chain_node);
668 }
669
670 /**
671  * drm_for_each_bridge_in_chain() - Iterate over all bridges present in a chain
672  * @encoder: the encoder to iterate bridges on
673  * @bridge: a bridge pointer updated to point to the current bridge at each
674  *          iteration
675  *
676  * Iterate over all bridges present in the bridge chain attached to @encoder.
677  */
678 #define drm_for_each_bridge_in_chain(encoder, bridge)                   \
679         list_for_each_entry(bridge, &(encoder)->bridge_chain, chain_node)
680
681 bool drm_bridge_chain_mode_fixup(struct drm_bridge *bridge,
682                                  const struct drm_display_mode *mode,
683                                  struct drm_display_mode *adjusted_mode);
684 enum drm_mode_status
685 drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
686                             const struct drm_display_mode *mode);
687 void drm_bridge_chain_disable(struct drm_bridge *bridge);
688 void drm_bridge_chain_post_disable(struct drm_bridge *bridge);
689 void drm_bridge_chain_mode_set(struct drm_bridge *bridge,
690                                const struct drm_display_mode *mode,
691                                const struct drm_display_mode *adjusted_mode);
692 void drm_bridge_chain_pre_enable(struct drm_bridge *bridge);
693 void drm_bridge_chain_enable(struct drm_bridge *bridge);
694
695 int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,
696                                   struct drm_crtc_state *crtc_state,
697                                   struct drm_connector_state *conn_state);
698 void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,
699                                      struct drm_atomic_state *state);
700 void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,
701                                           struct drm_atomic_state *state);
702 void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,
703                                         struct drm_atomic_state *state);
704 void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,
705                                     struct drm_atomic_state *state);
706
707 u32 *
708 drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
709                                         struct drm_bridge_state *bridge_state,
710                                         struct drm_crtc_state *crtc_state,
711                                         struct drm_connector_state *conn_state,
712                                         u32 output_fmt,
713                                         unsigned int *num_input_fmts);
714
715 void __drm_atomic_helper_bridge_reset(struct drm_bridge *bridge,
716                                       struct drm_bridge_state *state);
717 void __drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge,
718                                                 struct drm_bridge_state *new);
719
720 static inline struct drm_bridge_state *
721 drm_atomic_get_bridge_state(struct drm_atomic_state *state,
722                             struct drm_bridge *bridge)
723 {
724         struct drm_private_state *obj_state;
725
726         obj_state = drm_atomic_get_private_obj_state(state, &bridge->base);
727         if (IS_ERR(obj_state))
728                 return ERR_CAST(obj_state);
729
730         return drm_priv_to_bridge_state(obj_state);
731 }
732
733 static inline struct drm_bridge_state *
734 drm_atomic_get_old_bridge_state(struct drm_atomic_state *state,
735                                 struct drm_bridge *bridge)
736 {
737         struct drm_private_state *obj_state;
738
739         obj_state = drm_atomic_get_old_private_obj_state(state, &bridge->base);
740         if (!obj_state)
741                 return NULL;
742
743         return drm_priv_to_bridge_state(obj_state);
744 }
745
746 static inline struct drm_bridge_state *
747 drm_atomic_get_new_bridge_state(struct drm_atomic_state *state,
748                                 struct drm_bridge *bridge)
749 {
750         struct drm_private_state *obj_state;
751
752         obj_state = drm_atomic_get_new_private_obj_state(state, &bridge->base);
753         if (!obj_state)
754                 return NULL;
755
756         return drm_priv_to_bridge_state(obj_state);
757 }
758
759 #ifdef CONFIG_DRM_PANEL_BRIDGE
760 struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel);
761 struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
762                                               u32 connector_type);
763 void drm_panel_bridge_remove(struct drm_bridge *bridge);
764 struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
765                                              struct drm_panel *panel);
766 struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
767                                                    struct drm_panel *panel,
768                                                    u32 connector_type);
769 struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge);
770 #endif
771
772 #endif