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