xref: /linux/include/drm/drm_bridge.h (revision aa8a8c7e4641ebcef02dd6fa387ca334857367f4)
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/cleanup.h>
27 #include <linux/ctype.h>
28 #include <linux/list.h>
29 #include <linux/mutex.h>
30 
31 #include <drm/drm_atomic.h>
32 #include <drm/drm_encoder.h>
33 #include <drm/drm_mode_object.h>
34 #include <drm/drm_modes.h>
35 
36 struct cec_msg;
37 struct device_node;
38 
39 struct drm_bridge;
40 struct drm_bridge_timings;
41 struct drm_connector;
42 struct drm_display_info;
43 struct drm_edid;
44 struct drm_minor;
45 struct drm_panel;
46 struct hdmi_codec_daifmt;
47 struct hdmi_codec_params;
48 struct i2c_adapter;
49 
50 /**
51  * enum drm_bridge_attach_flags - Flags for &drm_bridge_funcs.attach
52  */
53 enum drm_bridge_attach_flags {
54 	/**
55 	 * @DRM_BRIDGE_ATTACH_NO_CONNECTOR: When this flag is set the bridge
56 	 * shall not create a drm_connector.
57 	 */
58 	DRM_BRIDGE_ATTACH_NO_CONNECTOR = BIT(0),
59 };
60 
61 /**
62  * struct drm_bridge_funcs - drm_bridge control functions
63  */
64 struct drm_bridge_funcs {
65 	/**
66 	 * @attach:
67 	 *
68 	 * This callback is invoked whenever our bridge is being attached to a
69 	 * &drm_encoder. The flags argument tunes the behaviour of the attach
70 	 * operation (see DRM_BRIDGE_ATTACH_*).
71 	 *
72 	 * The @attach callback is optional.
73 	 *
74 	 * RETURNS:
75 	 *
76 	 * Zero on success, error code on failure.
77 	 */
78 	int (*attach)(struct drm_bridge *bridge, struct drm_encoder *encoder,
79 		      enum drm_bridge_attach_flags flags);
80 
81 	/**
82 	 * @destroy:
83 	 *
84 	 * This callback is invoked when the bridge is about to be
85 	 * deallocated.
86 	 *
87 	 * The @destroy callback is optional.
88 	 */
89 	void (*destroy)(struct drm_bridge *bridge);
90 
91 	/**
92 	 * @detach:
93 	 *
94 	 * This callback is invoked whenever our bridge is being detached from a
95 	 * &drm_encoder.
96 	 *
97 	 * The @detach callback is optional.
98 	 */
99 	void (*detach)(struct drm_bridge *bridge);
100 
101 	/**
102 	 * @mode_valid:
103 	 *
104 	 * This callback is used to check if a specific mode is valid in this
105 	 * bridge. This should be implemented if the bridge has some sort of
106 	 * restriction in the modes it can display. For example, a given bridge
107 	 * may be responsible to set a clock value. If the clock can not
108 	 * produce all the values for the available modes then this callback
109 	 * can be used to restrict the number of modes to only the ones that
110 	 * can be displayed.
111 	 *
112 	 * This hook is used by the probe helpers to filter the mode list in
113 	 * drm_helper_probe_single_connector_modes(), and it is used by the
114 	 * atomic helpers to validate modes supplied by userspace in
115 	 * drm_atomic_helper_check_modeset().
116 	 *
117 	 * The @mode_valid callback is optional.
118 	 *
119 	 * NOTE:
120 	 *
121 	 * Since this function is both called from the check phase of an atomic
122 	 * commit, and the mode validation in the probe paths it is not allowed
123 	 * to look at anything else but the passed-in mode, and validate it
124 	 * against configuration-invariant hardware constraints. Any further
125 	 * limits which depend upon the configuration can only be checked in
126 	 * @mode_fixup.
127 	 *
128 	 * RETURNS:
129 	 *
130 	 * drm_mode_status Enum
131 	 */
132 	enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge,
133 					   const struct drm_display_info *info,
134 					   const struct drm_display_mode *mode);
135 
136 	/**
137 	 * @mode_fixup:
138 	 *
139 	 * This callback is used to validate and adjust a mode. The parameter
140 	 * mode is the display mode that should be fed to the next element in
141 	 * the display chain, either the final &drm_connector or the next
142 	 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
143 	 * requires. It can be modified by this callback and does not need to
144 	 * match mode. See also &drm_crtc_state.adjusted_mode for more details.
145 	 *
146 	 * This is the only hook that allows a bridge to reject a modeset. If
147 	 * this function passes all other callbacks must succeed for this
148 	 * configuration.
149 	 *
150 	 * The mode_fixup callback is optional. &drm_bridge_funcs.mode_fixup()
151 	 * is not called when &drm_bridge_funcs.atomic_check() is implemented,
152 	 * so only one of them should be provided.
153 	 *
154 	 * NOTE:
155 	 *
156 	 * This function is called in the check phase of atomic modesets, which
157 	 * can be aborted for any reason (including on userspace's request to
158 	 * just check whether a configuration would be possible). Drivers MUST
159 	 * NOT touch any persistent state (hardware or software) or data
160 	 * structures except the passed in @state parameter.
161 	 *
162 	 * Also beware that userspace can request its own custom modes, neither
163 	 * core nor helpers filter modes to the list of probe modes reported by
164 	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
165 	 * that modes are filtered consistently put any bridge constraints and
166 	 * limits checks into @mode_valid.
167 	 *
168 	 * RETURNS:
169 	 *
170 	 * True if an acceptable configuration is possible, false if the modeset
171 	 * operation should be rejected.
172 	 */
173 	bool (*mode_fixup)(struct drm_bridge *bridge,
174 			   const struct drm_display_mode *mode,
175 			   struct drm_display_mode *adjusted_mode);
176 
177 	/**
178 	 * @mode_set:
179 	 *
180 	 * This callback should set the given mode on the bridge. It is called
181 	 * after the @mode_set callback for the preceding element in the display
182 	 * pipeline has been called already. If the bridge is the first element
183 	 * then this would be &drm_encoder_helper_funcs.mode_set. The display
184 	 * pipe (i.e.  clocks and timing signals) is off when this function is
185 	 * called.
186 	 *
187 	 * The adjusted_mode parameter is the mode output by the CRTC for the
188 	 * first bridge in the chain. It can be different from the mode
189 	 * parameter that contains the desired mode for the connector at the end
190 	 * of the bridges chain, for instance when the first bridge in the chain
191 	 * performs scaling. The adjusted mode is mostly useful for the first
192 	 * bridge in the chain and is likely irrelevant for the other bridges.
193 	 *
194 	 * For atomic drivers the adjusted_mode is the mode stored in
195 	 * &drm_crtc_state.adjusted_mode.
196 	 *
197 	 * NOTE:
198 	 *
199 	 * This is deprecated, do not use!
200 	 * New drivers shall set their mode in the
201 	 * &drm_bridge_funcs.atomic_enable operation.
202 	 */
203 	void (*mode_set)(struct drm_bridge *bridge,
204 			 const struct drm_display_mode *mode,
205 			 const struct drm_display_mode *adjusted_mode);
206 
207 	/**
208 	 * @atomic_pre_enable:
209 	 *
210 	 * This callback should enable the bridge. It is called right before
211 	 * the preceding element in the display pipe is enabled. If the
212 	 * preceding element is a bridge this means it's called before that
213 	 * bridge's @atomic_pre_enable or @pre_enable function. If the preceding
214 	 * element is a &drm_encoder it's called right before the encoder's
215 	 * &drm_encoder_helper_funcs.atomic_enable hook.
216 	 *
217 	 * The display pipe (i.e. clocks and timing signals) feeding this bridge
218 	 * will not yet be running when this callback is called. The bridge must
219 	 * not enable the display link feeding the next bridge in the chain (if
220 	 * there is one) when this callback is called.
221 	 *
222 	 * The @atomic_pre_enable callback is optional.
223 	 */
224 	void (*atomic_pre_enable)(struct drm_bridge *bridge,
225 				  struct drm_atomic_commit *state);
226 
227 	/**
228 	 * @atomic_enable:
229 	 *
230 	 * This callback should enable the bridge. It is called right after
231 	 * the preceding element in the display pipe is enabled. If the
232 	 * preceding element is a bridge this means it's called after that
233 	 * bridge's @atomic_enable or @enable function. If the preceding element
234 	 * is a &drm_encoder it's called right after the encoder's
235 	 * &drm_encoder_helper_funcs.atomic_enable hook.
236 	 *
237 	 * The bridge can assume that the display pipe (i.e. clocks and timing
238 	 * signals) feeding it is running when this callback is called. This
239 	 * callback must enable the display link feeding the next bridge in the
240 	 * chain if there is one.
241 	 *
242 	 * The @atomic_enable callback is optional.
243 	 */
244 	void (*atomic_enable)(struct drm_bridge *bridge,
245 			      struct drm_atomic_commit *state);
246 	/**
247 	 * @atomic_disable:
248 	 *
249 	 * This callback should disable the bridge. It is called right before
250 	 * the preceding element in the display pipe is disabled. If the
251 	 * preceding element is a bridge this means it's called before that
252 	 * bridge's @atomic_disable or @disable vfunc. If the preceding element
253 	 * is a &drm_encoder it's called right before the
254 	 * &drm_encoder_helper_funcs.atomic_disable hook.
255 	 *
256 	 * The bridge can assume that the display pipe (i.e. clocks and timing
257 	 * signals) feeding it is still running when this callback is called.
258 	 *
259 	 * The @atomic_disable callback is optional.
260 	 */
261 	void (*atomic_disable)(struct drm_bridge *bridge,
262 			       struct drm_atomic_commit *state);
263 
264 	/**
265 	 * @atomic_post_disable:
266 	 *
267 	 * This callback should disable the bridge. It is called right after the
268 	 * preceding element in the display pipe is disabled. If the preceding
269 	 * element is a bridge this means it's called after that bridge's
270 	 * @atomic_post_disable or @post_disable function. If the preceding
271 	 * element is a &drm_encoder it's called right after the encoder's
272 	 * &drm_encoder_helper_funcs.atomic_disable hook.
273 	 *
274 	 * The bridge must assume that the display pipe (i.e. clocks and timing
275 	 * signals) feeding it is no longer running when this callback is
276 	 * called.
277 	 *
278 	 * The @atomic_post_disable callback is optional.
279 	 */
280 	void (*atomic_post_disable)(struct drm_bridge *bridge,
281 				    struct drm_atomic_commit *state);
282 
283 	/**
284 	 * @atomic_duplicate_state:
285 	 *
286 	 * Duplicate the current bridge state object (which is guaranteed to be
287 	 * non-NULL).
288 	 *
289 	 * The atomic_duplicate_state hook is mandatory if the bridge
290 	 * implements any of the atomic hooks, and should be left unassigned
291 	 * otherwise. For bridges that don't subclass &drm_bridge_state, the
292 	 * drm_atomic_helper_bridge_duplicate_state() helper function shall be
293 	 * used to implement this hook.
294 	 *
295 	 * RETURNS:
296 	 * A valid drm_bridge_state object or NULL if the allocation fails.
297 	 */
298 	struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge);
299 
300 	/**
301 	 * @atomic_destroy_state:
302 	 *
303 	 * Destroy a bridge state object previously allocated by
304 	 * &drm_bridge_funcs.atomic_duplicate_state().
305 	 *
306 	 * The atomic_destroy_state hook is mandatory if the bridge implements
307 	 * any of the atomic hooks, and should be left unassigned otherwise.
308 	 * For bridges that don't subclass &drm_bridge_state, the
309 	 * drm_atomic_helper_bridge_destroy_state() helper function shall be
310 	 * used to implement this hook.
311 	 */
312 	void (*atomic_destroy_state)(struct drm_bridge *bridge,
313 				     struct drm_bridge_state *state);
314 
315 	/**
316 	 * @atomic_get_output_bus_fmts:
317 	 *
318 	 * Return the supported bus formats on the output end of a bridge.
319 	 * The returned array must be allocated with kmalloc() and will be
320 	 * freed by the caller. If the allocation fails, NULL should be
321 	 * returned. num_output_fmts must be set to the returned array size.
322 	 * Formats listed in the returned array should be listed in decreasing
323 	 * preference order (the core will try all formats until it finds one
324 	 * that works).
325 	 *
326 	 * This method is only called on the last element of the bridge chain
327 	 * as part of the bus format negotiation process that happens in
328 	 * &drm_atomic_bridge_chain_select_bus_fmts().
329 	 * This method is optional. When not implemented, the core will
330 	 * fall back to &drm_connector.display_info.bus_formats[0] if
331 	 * &drm_connector.display_info.num_bus_formats > 0,
332 	 * or to MEDIA_BUS_FMT_FIXED otherwise.
333 	 */
334 	u32 *(*atomic_get_output_bus_fmts)(struct drm_bridge *bridge,
335 					   struct drm_bridge_state *bridge_state,
336 					   struct drm_crtc_state *crtc_state,
337 					   struct drm_connector_state *conn_state,
338 					   unsigned int *num_output_fmts);
339 
340 	/**
341 	 * @atomic_get_input_bus_fmts:
342 	 *
343 	 * Return the supported bus formats on the input end of a bridge for
344 	 * a specific output bus format.
345 	 *
346 	 * The returned array must be allocated with kmalloc() and will be
347 	 * freed by the caller. If the allocation fails, NULL should be
348 	 * returned. num_input_fmts must be set to the returned array size.
349 	 * Formats listed in the returned array should be listed in decreasing
350 	 * preference order (the core will try all formats until it finds one
351 	 * that works). When the format is not supported NULL should be
352 	 * returned and num_input_fmts should be set to 0.
353 	 *
354 	 * This method is called on all elements of the bridge chain as part of
355 	 * the bus format negotiation process that happens in
356 	 * drm_atomic_bridge_chain_select_bus_fmts().
357 	 * This method is optional. When not implemented, the core will bypass
358 	 * bus format negotiation on this element of the bridge without
359 	 * failing, and the previous element in the chain will be passed
360 	 * MEDIA_BUS_FMT_FIXED as its output bus format.
361 	 *
362 	 * Bridge drivers that need to support being linked to bridges that are
363 	 * not supporting bus format negotiation should handle the
364 	 * output_fmt == MEDIA_BUS_FMT_FIXED case appropriately, by selecting a
365 	 * sensible default value or extracting this information from somewhere
366 	 * else (FW property, &drm_display_mode, &drm_display_info, ...)
367 	 *
368 	 * Note: Even if input format selection on the first bridge has no
369 	 * impact on the negotiation process (bus format negotiation stops once
370 	 * we reach the first element of the chain), drivers are expected to
371 	 * return accurate input formats as the input format may be used to
372 	 * configure the CRTC output appropriately.
373 	 */
374 	u32 *(*atomic_get_input_bus_fmts)(struct drm_bridge *bridge,
375 					  struct drm_bridge_state *bridge_state,
376 					  struct drm_crtc_state *crtc_state,
377 					  struct drm_connector_state *conn_state,
378 					  u32 output_fmt,
379 					  unsigned int *num_input_fmts);
380 
381 	/**
382 	 * @atomic_check:
383 	 *
384 	 * This method is responsible for checking bridge state correctness.
385 	 * It can also check the state of the surrounding components in chain
386 	 * to make sure the whole pipeline can work properly.
387 	 *
388 	 * &drm_bridge_funcs.atomic_check() hooks are called in reverse
389 	 * order (from the last to the first bridge).
390 	 *
391 	 * This method is optional. &drm_bridge_funcs.mode_fixup() is not
392 	 * called when &drm_bridge_funcs.atomic_check() is implemented, so only
393 	 * one of them should be provided.
394 	 *
395 	 * If drivers need to tweak &drm_bridge_state.input_bus_cfg.flags or
396 	 * &drm_bridge_state.output_bus_cfg.flags it should happen in
397 	 * this function. By default the &drm_bridge_state.output_bus_cfg.flags
398 	 * field is set to the next bridge
399 	 * &drm_bridge_state.input_bus_cfg.flags value or
400 	 * &drm_connector.display_info.bus_flags if the bridge is the last
401 	 * element in the chain.
402 	 *
403 	 * RETURNS:
404 	 * zero if the check passed, a negative error code otherwise.
405 	 */
406 	int (*atomic_check)(struct drm_bridge *bridge,
407 			    struct drm_bridge_state *bridge_state,
408 			    struct drm_crtc_state *crtc_state,
409 			    struct drm_connector_state *conn_state);
410 
411 	/**
412 	 * @atomic_create_state:
413 	 *
414 	 * Allocate a pristine, initialized, state for the bridge
415 	 * object and return it. This callback must have no side
416 	 * effects: in particular, the returned state must not be
417 	 * assigned to the object's state pointer and it must not affect
418 	 * the hardware state.
419 	 *
420 	 * RETURNS:
421 	 *
422 	 * A new, pristine, bridge state instance or an error pointer
423 	 * on failure.
424 	 */
425 	struct drm_bridge_state *(*atomic_create_state)(struct drm_bridge *bridge);
426 
427 	/**
428 	 * @detect:
429 	 *
430 	 * Check if anything is attached to the bridge output.
431 	 *
432 	 * This callback is optional, if not implemented the bridge will be
433 	 * considered as always having a component attached to its output.
434 	 * Bridges that implement this callback shall set the
435 	 * DRM_BRIDGE_OP_DETECT flag in their &drm_bridge->ops.
436 	 *
437 	 * RETURNS:
438 	 *
439 	 * drm_connector_status indicating the bridge output status.
440 	 */
441 	enum drm_connector_status (*detect)(struct drm_bridge *bridge,
442 					    struct drm_connector *connector);
443 
444 	/**
445 	 * @get_modes:
446 	 *
447 	 * Fill all modes currently valid for the sink into the &drm_connector
448 	 * with drm_mode_probed_add().
449 	 *
450 	 * The @get_modes callback is mostly intended to support non-probeable
451 	 * displays such as many fixed panels. Bridges that support reading
452 	 * EDID shall leave @get_modes unimplemented and implement the
453 	 * &drm_bridge_funcs->edid_read callback instead.
454 	 *
455 	 * This callback is optional. Bridges that implement it shall set the
456 	 * DRM_BRIDGE_OP_MODES flag in their &drm_bridge->ops.
457 	 *
458 	 * The connector parameter shall be used for the sole purpose of
459 	 * filling modes, and shall not be stored internally by bridge drivers
460 	 * for future usage.
461 	 *
462 	 * RETURNS:
463 	 *
464 	 * The number of modes added by calling drm_mode_probed_add().
465 	 */
466 	int (*get_modes)(struct drm_bridge *bridge,
467 			 struct drm_connector *connector);
468 
469 	/**
470 	 * @edid_read:
471 	 *
472 	 * Read the EDID data of the connected display.
473 	 *
474 	 * The @edid_read callback is the preferred way of reporting mode
475 	 * information for a display connected to the bridge output. Bridges
476 	 * that support reading EDID shall implement this callback and leave
477 	 * the @get_modes callback unimplemented.
478 	 *
479 	 * The caller of this operation shall first verify the output
480 	 * connection status and refrain from reading EDID from a disconnected
481 	 * output.
482 	 *
483 	 * This callback is optional. Bridges that implement it shall set the
484 	 * DRM_BRIDGE_OP_EDID flag in their &drm_bridge->ops.
485 	 *
486 	 * The connector parameter shall be used for the sole purpose of EDID
487 	 * retrieval, and shall not be stored internally by bridge drivers for
488 	 * future usage.
489 	 *
490 	 * RETURNS:
491 	 *
492 	 * An edid structure newly allocated with drm_edid_alloc() or returned
493 	 * from drm_edid_read() family of functions on success, or NULL
494 	 * otherwise. The caller is responsible for freeing the returned edid
495 	 * structure with drm_edid_free().
496 	 */
497 	const struct drm_edid *(*edid_read)(struct drm_bridge *bridge,
498 					    struct drm_connector *connector);
499 
500 	/**
501 	 * @hpd_notify:
502 	 *
503 	 * Notify the bridge of hot plug detection.
504 	 *
505 	 * This callback is optional, it may be implemented by bridges that
506 	 * need to be notified of display connection or disconnection for
507 	 * internal reasons. One use case is to reset the internal state of CEC
508 	 * controllers for HDMI bridges.
509 	 */
510 	void (*hpd_notify)(struct drm_bridge *bridge,
511 			   struct drm_connector *connector,
512 			   enum drm_connector_status status);
513 
514 	/**
515 	 * @hpd_enable:
516 	 *
517 	 * Enable hot plug detection. From now on the bridge shall call
518 	 * drm_bridge_hpd_notify() each time a change is detected in the output
519 	 * connection status, until hot plug detection gets disabled with
520 	 * @hpd_disable.
521 	 *
522 	 * This callback is optional and shall only be implemented by bridges
523 	 * that support hot-plug notification without polling. Bridges that
524 	 * implement it shall also implement the @hpd_disable callback and set
525 	 * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
526 	 */
527 	void (*hpd_enable)(struct drm_bridge *bridge);
528 
529 	/**
530 	 * @hpd_disable:
531 	 *
532 	 * Disable hot plug detection. Once this function returns the bridge
533 	 * shall not call drm_bridge_hpd_notify() when a change in the output
534 	 * connection status occurs.
535 	 *
536 	 * This callback is optional and shall only be implemented by bridges
537 	 * that support hot-plug notification without polling. Bridges that
538 	 * implement it shall also implement the @hpd_enable callback and set
539 	 * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
540 	 */
541 	void (*hpd_disable)(struct drm_bridge *bridge);
542 
543 	/**
544 	 * @hdmi_tmds_char_rate_valid:
545 	 *
546 	 * Check whether a particular TMDS character rate is supported by the
547 	 * driver.
548 	 *
549 	 * This callback is optional and should only be implemented by the
550 	 * bridges that take part in the HDMI connector implementation. Bridges
551 	 * that implement it shall set the DRM_BRIDGE_OP_HDMI flag in their
552 	 * &drm_bridge->ops.
553 	 *
554 	 * Returns:
555 	 *
556 	 * Either &drm_mode_status.MODE_OK or one of the failure reasons
557 	 * in &enum drm_mode_status.
558 	 */
559 	enum drm_mode_status
560 	(*hdmi_tmds_char_rate_valid)(const struct drm_bridge *bridge,
561 				     const struct drm_display_mode *mode,
562 				     unsigned long long tmds_rate);
563 
564 	/**
565 	 * @hdmi_scrambler_enable:
566 	 *
567 	 * Enable source-side scrambling and the high TMDS clock ratio for the
568 	 * mode currently being applied.
569 	 *
570 	 * This only programs the source side. Sink-side SCDC configuration is
571 	 * handled by the HDMI connector helpers.
572 	 *
573 	 * Mandatory for bridges that set the DRM_BRIDGE_OP_HDMI flag in their
574 	 * &drm_bridge->ops and advertise HDMI_VERSION_2_0 or later via
575 	 * &drm_bridge->supported_hdmi_ver; unused otherwise.
576 	 *
577 	 * Returns:
578 	 * 0 on success, a negative error code otherwise.
579 	 */
580 	int (*hdmi_scrambler_enable)(struct drm_bridge *bridge);
581 
582 	/**
583 	 * @hdmi_scrambler_disable:
584 	 *
585 	 * Disable source-side scrambling and the high TMDS clock ratio.
586 	 *
587 	 * This only programs the source side. Sink-side SCDC configuration is
588 	 * handled by the HDMI connector helpers.
589 	 *
590 	 * Mandatory for bridges that set the DRM_BRIDGE_OP_HDMI flag in their
591 	 * &drm_bridge->ops and advertise HDMI_VERSION_2_0 or later via
592 	 * &drm_bridge->supported_hdmi_ver; unused otherwise.
593 	 *
594 	 * Returns:
595 	 * 0 on success, a negative error code otherwise.
596 	 */
597 	int (*hdmi_scrambler_disable)(struct drm_bridge *bridge);
598 
599 	/**
600 	 * @hdmi_clear_avi_infoframe:
601 	 *
602 	 * This callback clears the infoframes in the hardware during commit.
603 	 *
604 	 * This callback is optional but it must be implemented by bridges that
605 	 * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops.
606 	 */
607 	int (*hdmi_clear_avi_infoframe)(struct drm_bridge *bridge);
608 
609 	/**
610 	 * @hdmi_write_avi_infoframe:
611 	 *
612 	 * Program the infoframe into the hardware.
613 	 *
614 	 * This callback is optional but it must be implemented by bridges that
615 	 * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops.
616 	 */
617 	int (*hdmi_write_avi_infoframe)(struct drm_bridge *bridge,
618 					const u8 *buffer, size_t len);
619 
620 	/**
621 	 * @hdmi_clear_hdmi_infoframe:
622 	 *
623 	 * This callback clears the infoframes in the hardware during commit.
624 	 *
625 	 * This callback is optional but it must be implemented by bridges that
626 	 * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops.
627 	 */
628 	int (*hdmi_clear_hdmi_infoframe)(struct drm_bridge *bridge);
629 
630 	/**
631 	 * @hdmi_write_hdmi_infoframe:
632 	 *
633 	 * Program the infoframe into the hardware.
634 	 *
635 	 * This callback is optional but it must be implemented by bridges that
636 	 * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops.
637 	 */
638 	int (*hdmi_write_hdmi_infoframe)(struct drm_bridge *bridge,
639 					    const u8 *buffer, size_t len);
640 
641 	/**
642 	 * @hdmi_clear_hdr_drm_infoframe:
643 	 *
644 	 * This callback clears the infoframes in the hardware during commit.
645 	 *
646 	 * This callback is optional but it must be implemented by bridges that
647 	 * set the DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME flag in their
648 	 * &drm_bridge->ops.
649 	 */
650 	int (*hdmi_clear_hdr_drm_infoframe)(struct drm_bridge *bridge);
651 
652 	/**
653 	 * @hdmi_write_hdr_drm_infoframe:
654 	 *
655 	 * Program the infoframe into the hardware.
656 	 *
657 	 * This callback is optional but it must be implemented by bridges that
658 	 * set the DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME flag in their
659 	 * &drm_bridge->ops.
660 	 */
661 	int (*hdmi_write_hdr_drm_infoframe)(struct drm_bridge *bridge,
662 					const u8 *buffer, size_t len);
663 
664 	/**
665 	 * @hdmi_clear_spd_infoframe:
666 	 *
667 	 * This callback clears the infoframes in the hardware during commit.
668 	 *
669 	 * This callback is optional but it must be implemented by bridges that
670 	 * set the DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME flag in their
671 	 * &drm_bridge->ops.
672 	 */
673 	int (*hdmi_clear_spd_infoframe)(struct drm_bridge *bridge);
674 
675 	/**
676 	 * @hdmi_write_spd_infoframe:
677 	 *
678 	 * Program the infoframe into the hardware.
679 	 *
680 	 * This callback is optional but it must be implemented by bridges that
681 	 * set the DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME flag in their
682 	 * &drm_bridge->ops.
683 	 */
684 	int (*hdmi_write_spd_infoframe)(struct drm_bridge *bridge,
685 					const u8 *buffer, size_t len);
686 
687 	/**
688 	 * @hdmi_clear_audio_infoframe:
689 	 *
690 	 * This callback clears the infoframes in the hardware during commit.
691 	 *
692 	 * This callback is optional but it must be implemented by bridges that
693 	 * set the DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
694 	 */
695 	int (*hdmi_clear_audio_infoframe)(struct drm_bridge *bridge);
696 
697 	/**
698 	 * @hdmi_write_audio_infoframe:
699 	 *
700 	 * Program the infoframe into the hardware.
701 	 *
702 	 * This callback is optional but it must be implemented by bridges that
703 	 * set the DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
704 	 */
705 	int (*hdmi_write_audio_infoframe)(struct drm_bridge *bridge,
706 					  const u8 *buffer, size_t len);
707 
708 	/**
709 	 * @hdmi_audio_startup:
710 	 *
711 	 * Called when ASoC starts an audio stream setup.
712 	 *
713 	 * This callback is optional, it can be implemented by bridges that
714 	 * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
715 	 *
716 	 * Returns:
717 	 * 0 on success, a negative error code otherwise
718 	 */
719 	int (*hdmi_audio_startup)(struct drm_bridge *bridge,
720 				  struct drm_connector *connector);
721 
722 	/**
723 	 * @hdmi_audio_prepare:
724 	 * Configures HDMI-encoder for audio stream. Can be called multiple
725 	 * times for each setup.
726 	 *
727 	 * This callback is optional but it must be implemented by bridges that
728 	 * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
729 	 *
730 	 * Returns:
731 	 * 0 on success, a negative error code otherwise
732 	 */
733 	int (*hdmi_audio_prepare)(struct drm_bridge *bridge,
734 				  struct drm_connector *connector,
735 				  struct hdmi_codec_daifmt *fmt,
736 				  struct hdmi_codec_params *hparms);
737 
738 	/**
739 	 * @hdmi_audio_shutdown:
740 	 *
741 	 * Shut down the audio stream.
742 	 *
743 	 * This callback is optional but it must be implemented by bridges that
744 	 * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
745 	 *
746 	 * Returns:
747 	 * 0 on success, a negative error code otherwise
748 	 */
749 	void (*hdmi_audio_shutdown)(struct drm_bridge *bridge,
750 				    struct drm_connector *connector);
751 
752 	/**
753 	 * @hdmi_audio_mute_stream:
754 	 *
755 	 * Mute/unmute HDMI audio stream.
756 	 *
757 	 * This callback is optional, it can be implemented by bridges that
758 	 * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
759 	 *
760 	 * Returns:
761 	 * 0 on success, a negative error code otherwise
762 	 */
763 	int (*hdmi_audio_mute_stream)(struct drm_bridge *bridge,
764 				      struct drm_connector *connector,
765 				      bool enable, int direction);
766 
767 	/**
768 	 * @hdmi_cec_init:
769 	 *
770 	 * Initialize CEC part of the bridge.
771 	 *
772 	 * This callback is optional, it can be implemented by bridges that
773 	 * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their
774 	 * &drm_bridge->ops.
775 	 *
776 	 * Returns:
777 	 * 0 on success, a negative error code otherwise
778 	 */
779 	int (*hdmi_cec_init)(struct drm_bridge *bridge,
780 			     struct drm_connector *connector);
781 
782 	/**
783 	 * @hdmi_cec_enable:
784 	 *
785 	 * Enable or disable the CEC adapter inside the bridge.
786 	 *
787 	 * This callback is optional, it can be implemented by bridges that
788 	 * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their
789 	 * &drm_bridge->ops.
790 	 *
791 	 * Returns:
792 	 * 0 on success, a negative error code otherwise
793 	 */
794 	int (*hdmi_cec_enable)(struct drm_bridge *bridge, bool enable);
795 
796 	/**
797 	 * @hdmi_cec_log_addr:
798 	 *
799 	 * Set the logical address of the CEC adapter inside the bridge.
800 	 *
801 	 * This callback is optional, it can be implemented by bridges that
802 	 * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their
803 	 * &drm_bridge->ops.
804 	 *
805 	 * Returns:
806 	 * 0 on success, a negative error code otherwise
807 	 */
808 	int (*hdmi_cec_log_addr)(struct drm_bridge *bridge, u8 logical_addr);
809 
810 	/**
811 	 * @hdmi_cec_transmit:
812 	 *
813 	 * Transmit the message using the CEC adapter inside the bridge.
814 	 *
815 	 * This callback is optional, it can be implemented by bridges that
816 	 * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their
817 	 * &drm_bridge->ops.
818 	 *
819 	 * Returns:
820 	 * 0 on success, a negative error code otherwise
821 	 */
822 	int (*hdmi_cec_transmit)(struct drm_bridge *bridge, u8 attempts,
823 				 u32 signal_free_time, struct cec_msg *msg);
824 
825 	/**
826 	 * @dp_audio_startup:
827 	 *
828 	 * Called when ASoC starts a DisplayPort audio stream setup.
829 	 *
830 	 * This callback is optional, it can be implemented by bridges that
831 	 * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops.
832 	 *
833 	 * Returns:
834 	 * 0 on success, a negative error code otherwise
835 	 */
836 	int (*dp_audio_startup)(struct drm_bridge *bridge,
837 				struct drm_connector *connector);
838 
839 	/**
840 	 * @dp_audio_prepare:
841 	 * Configures DisplayPort audio stream. Can be called multiple
842 	 * times for each setup.
843 	 *
844 	 * This callback is optional but it must be implemented by bridges that
845 	 * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops.
846 	 *
847 	 * Returns:
848 	 * 0 on success, a negative error code otherwise
849 	 */
850 	int (*dp_audio_prepare)(struct drm_bridge *bridge,
851 				struct drm_connector *connector,
852 				struct hdmi_codec_daifmt *fmt,
853 				struct hdmi_codec_params *hparms);
854 
855 	/**
856 	 * @dp_audio_shutdown:
857 	 *
858 	 * Shut down the DisplayPort audio stream.
859 	 *
860 	 * This callback is optional but it must be implemented by bridges that
861 	 * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops.
862 	 *
863 	 * Returns:
864 	 * 0 on success, a negative error code otherwise
865 	 */
866 	void (*dp_audio_shutdown)(struct drm_bridge *bridge,
867 				  struct drm_connector *connector);
868 
869 	/**
870 	 * @dp_audio_mute_stream:
871 	 *
872 	 * Mute/unmute DisplayPort audio stream.
873 	 *
874 	 * This callback is optional, it can be implemented by bridges that
875 	 * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops.
876 	 *
877 	 * Returns:
878 	 * 0 on success, a negative error code otherwise
879 	 */
880 	int (*dp_audio_mute_stream)(struct drm_bridge *bridge,
881 				    struct drm_connector *connector,
882 				    bool enable, int direction);
883 
884 	/**
885 	 * @debugfs_init:
886 	 *
887 	 * Allows bridges to create bridge-specific debugfs files.
888 	 */
889 	void (*debugfs_init)(struct drm_bridge *bridge, struct dentry *root);
890 };
891 
892 /**
893  * struct drm_bridge_timings - timing information for the bridge
894  */
895 struct drm_bridge_timings {
896 	/**
897 	 * @input_bus_flags:
898 	 *
899 	 * Tells what additional settings for the pixel data on the bus
900 	 * this bridge requires (like pixel signal polarity). See also
901 	 * &drm_display_info->bus_flags.
902 	 */
903 	u32 input_bus_flags;
904 	/**
905 	 * @setup_time_ps:
906 	 *
907 	 * Defines the time in picoseconds the input data lines must be
908 	 * stable before the clock edge.
909 	 */
910 	u32 setup_time_ps;
911 	/**
912 	 * @hold_time_ps:
913 	 *
914 	 * Defines the time in picoseconds taken for the bridge to sample the
915 	 * input signal after the clock edge.
916 	 */
917 	u32 hold_time_ps;
918 	/**
919 	 * @dual_link:
920 	 *
921 	 * True if the bus operates in dual-link mode. The exact meaning is
922 	 * dependent on the bus type. For LVDS buses, this indicates that even-
923 	 * and odd-numbered pixels are received on separate links.
924 	 */
925 	bool dual_link;
926 };
927 
928 /**
929  * enum drm_bridge_ops - Bitmask of operations supported by the bridge
930  */
931 enum drm_bridge_ops {
932 	/**
933 	 * @DRM_BRIDGE_OP_DETECT: The bridge can detect displays connected to
934 	 * its output. Bridges that set this flag shall implement the
935 	 * &drm_bridge_funcs->detect callback.
936 	 */
937 	DRM_BRIDGE_OP_DETECT = BIT(0),
938 	/**
939 	 * @DRM_BRIDGE_OP_EDID: The bridge can retrieve the EDID of the display
940 	 * connected to its output. Bridges that set this flag shall implement
941 	 * the &drm_bridge_funcs->edid_read callback.
942 	 */
943 	DRM_BRIDGE_OP_EDID = BIT(1),
944 	/**
945 	 * @DRM_BRIDGE_OP_HPD: The bridge can detect hot-plug and hot-unplug
946 	 * without requiring polling. Bridges that set this flag shall
947 	 * implement the &drm_bridge_funcs->hpd_enable and
948 	 * &drm_bridge_funcs->hpd_disable callbacks if they support enabling
949 	 * and disabling hot-plug detection dynamically.
950 	 */
951 	DRM_BRIDGE_OP_HPD = BIT(2),
952 	/**
953 	 * @DRM_BRIDGE_OP_MODES: The bridge can retrieve the modes supported
954 	 * by the display at its output. This does not include reading EDID
955 	 * which is separately covered by @DRM_BRIDGE_OP_EDID. Bridges that set
956 	 * this flag shall implement the &drm_bridge_funcs->get_modes callback.
957 	 */
958 	DRM_BRIDGE_OP_MODES = BIT(3),
959 	/**
960 	 * @DRM_BRIDGE_OP_HDMI: The bridge provides HDMI connector operations,
961 	 * including infoframes support. Bridges that set this flag must
962 	 * provide HDMI-related information and implement the
963 	 * &drm_bridge_funcs->clear_avi_infoframe,
964 	 * &drm_bridge_funcs->write_avi_infoframe,
965 	 * &drm_bridge_funcs->clear_hdmi_infoframe and
966 	 * &drm_bridge_funcs->write_hdmi_infoframe callbacks.
967 	 *
968 	 * Note: currently there can be at most one bridge in a chain that sets
969 	 * this bit. This is to simplify corresponding glue code in connector
970 	 * drivers.
971 	 */
972 	DRM_BRIDGE_OP_HDMI = BIT(4),
973 	/**
974 	 * @DRM_BRIDGE_OP_HDMI_AUDIO: The bridge provides HDMI audio operations.
975 	 * Bridges that set this flag must implement the
976 	 * &drm_bridge_funcs->hdmi_audio_prepare and
977 	 * &drm_bridge_funcs->hdmi_audio_shutdown callbacks.
978 	 * If the bridge implements @DRM_BRIDGE_OP_HDMI, it also must implement
979 	 * &drm_bridge_funcs->hdmi_write_audio_infoframe and
980 	 * &drm_bridge_funcs->hdmi_cleaer_audio_infoframe callbacks.
981 	 *
982 	 * Note: currently there can be at most one bridge in a chain that sets
983 	 * this bit. This is to simplify corresponding glue code in connector
984 	 * drivers. Also it is not possible to have a bridge in the chain that
985 	 * sets @DRM_BRIDGE_OP_DP_AUDIO if there is a bridge that sets this
986 	 * flag.
987 	 */
988 	DRM_BRIDGE_OP_HDMI_AUDIO = BIT(5),
989 	/**
990 	 * @DRM_BRIDGE_OP_DP_AUDIO: The bridge provides DisplayPort audio operations.
991 	 * Bridges that set this flag must implement the
992 	 * &drm_bridge_funcs->dp_audio_prepare and
993 	 * &drm_bridge_funcs->dp_audio_shutdown callbacks.
994 	 *
995 	 * Note: currently there can be at most one bridge in a chain that sets
996 	 * this bit. This is to simplify corresponding glue code in connector
997 	 * drivers. Also it is not possible to have a bridge in the chain that
998 	 * sets @DRM_BRIDGE_OP_HDMI_AUDIO if there is a bridge that sets this
999 	 * flag.
1000 	 */
1001 	DRM_BRIDGE_OP_DP_AUDIO = BIT(6),
1002 	/**
1003 	 * @DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER: The bridge requires CEC notifier
1004 	 * to be present.
1005 	 */
1006 	DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER = BIT(7),
1007 	/**
1008 	 * @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER: The bridge requires CEC adapter
1009 	 * to be present.
1010 	 */
1011 	DRM_BRIDGE_OP_HDMI_CEC_ADAPTER = BIT(8),
1012 	/**
1013 	 * @DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME: The bridge supports
1014 	 * &drm_bridge_funcs->hdmi_write_hdr_drm_infoframe and
1015 	 * &drm_bridge_funcs->hdmi_clear_hdr_drm_infoframe callbacks.
1016 	 */
1017 	DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME = BIT(9),
1018 	/**
1019 	 * @DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME: The bridge supports
1020 	 * &drm_bridge_funcs->hdmi_write_spd_infoframe and
1021 	 * &drm_bridge_funcs->hdmi_clear_spd_infoframe callbacks.
1022 	 */
1023 	DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME = BIT(10),
1024 };
1025 
1026 /**
1027  * struct drm_bridge - central DRM bridge control structure
1028  */
1029 struct drm_bridge {
1030 	/** @base: inherit from &drm_private_object */
1031 	struct drm_private_obj base;
1032 	/** @dev: DRM device this bridge belongs to */
1033 	struct drm_device *dev;
1034 	/** @encoder: encoder to which this bridge is connected */
1035 	struct drm_encoder *encoder;
1036 	/** @chain_node: used to form a bridge chain */
1037 	struct list_head chain_node;
1038 	/** @of_node: device node pointer to the bridge */
1039 	struct device_node *of_node;
1040 	/** @list: to keep track of all added bridges */
1041 	struct list_head list;
1042 	/**
1043 	 * @timings:
1044 	 *
1045 	 * the timing specification for the bridge, if any (may be NULL)
1046 	 */
1047 	const struct drm_bridge_timings *timings;
1048 	/** @funcs: control functions */
1049 	const struct drm_bridge_funcs *funcs;
1050 
1051 	/**
1052 	 * @container: Pointer to the private driver struct embedding this
1053 	 * @struct drm_bridge.
1054 	 */
1055 	void *container;
1056 
1057 	/**
1058 	 * @refcount: reference count of users referencing this bridge.
1059 	 */
1060 	struct kref refcount;
1061 
1062 	/**
1063 	 * @unplugged:
1064 	 *
1065 	 * Flag to tell if the bridge has been unplugged.
1066 	 * See drm_bridge_enter() and drm_bridge_unplug().
1067 	 */
1068 	bool unplugged;
1069 
1070 	/** @driver_private: pointer to the bridge driver's internal context */
1071 	void *driver_private;
1072 	/** @ops: bitmask of operations supported by the bridge */
1073 	enum drm_bridge_ops ops;
1074 	/**
1075 	 * @type: Type of the connection at the bridge output
1076 	 * (DRM_MODE_CONNECTOR_*). For bridges at the end of this chain this
1077 	 * identifies the type of connected display.
1078 	 */
1079 	int type;
1080 	/**
1081 	 * @interlace_allowed: Indicate that the bridge can handle interlaced
1082 	 * modes.
1083 	 */
1084 	bool interlace_allowed;
1085 	/**
1086 	 * @ycbcr_420_allowed: Indicate that the bridge can handle YCbCr 420
1087 	 * output.
1088 	 */
1089 	bool ycbcr_420_allowed;
1090 	/**
1091 	 * @pre_enable_prev_first: The bridge requires that the prev
1092 	 * bridge @pre_enable function is called before its @pre_enable,
1093 	 * and conversely for post_disable. This is most frequently a
1094 	 * requirement for DSI devices which need the host to be initialised
1095 	 * before the peripheral.
1096 	 */
1097 	bool pre_enable_prev_first;
1098 	/**
1099 	 * @support_hdcp: Indicate that the bridge supports HDCP.
1100 	 */
1101 	bool support_hdcp;
1102 	/**
1103 	 * @ddc: Associated I2C adapter for DDC access, if any.
1104 	 */
1105 	struct i2c_adapter *ddc;
1106 
1107 	/**
1108 	 * @vendor: Vendor of the product to be used for the SPD InfoFrame
1109 	 * generation. This is required if @DRM_BRIDGE_OP_HDMI is set.
1110 	 */
1111 	const char *vendor;
1112 
1113 	/**
1114 	 * @product: Name of the product to be used for the SPD InfoFrame
1115 	 * generation. This is required if @DRM_BRIDGE_OP_HDMI is set.
1116 	 */
1117 	const char *product;
1118 
1119 	/**
1120 	 * @supported_hdmi_ver: HDMI version the bridge is conformant with.
1121 	 * This is only relevant if @DRM_BRIDGE_OP_HDMI is set.
1122 	 */
1123 	enum hdmi_version supported_hdmi_ver;
1124 
1125 	/**
1126 	 * @supported_formats: Bitmask of @drm_output_color_format listing
1127 	 * supported output formats. This is only relevant if
1128 	 * @DRM_BRIDGE_OP_HDMI is set.
1129 	 */
1130 	unsigned int supported_formats;
1131 
1132 	/**
1133 	 * @max_tmds_char_rate: Maximum TMDS character rate, in Hz, the HDMI
1134 	 * bridge supports. A value of 0 means the core should use the default
1135 	 * limit implied by @supported_hdmi_ver. This is only relevant if
1136 	 * @DRM_BRIDGE_OP_HDMI is set.
1137 	 */
1138 	unsigned long long max_tmds_char_rate;
1139 
1140 	/**
1141 	 * @max_bpc: Maximum bits per char the HDMI bridge supports. Allowed
1142 	 * values are 8, 10 and 12. This is only relevant if
1143 	 * @DRM_BRIDGE_OP_HDMI is set.
1144 	 */
1145 	unsigned int max_bpc;
1146 
1147 	/**
1148 	 * @hdmi_cec_dev: device to be used as a containing device for CEC
1149 	 * functions.
1150 	 */
1151 	struct device *hdmi_cec_dev;
1152 
1153 	/**
1154 	 * @hdmi_audio_dev: device to be used as a parent for the HDMI Codec if
1155 	 * either of @DRM_BRIDGE_OP_HDMI_AUDIO or @DRM_BRIDGE_OP_DP_AUDIO is set.
1156 	 */
1157 	struct device *hdmi_audio_dev;
1158 
1159 	/**
1160 	 * @hdmi_audio_max_i2s_playback_channels: maximum number of playback
1161 	 * I2S channels for the @DRM_BRIDGE_OP_HDMI_AUDIO or
1162 	 * @DRM_BRIDGE_OP_DP_AUDIO.
1163 	 */
1164 	int hdmi_audio_max_i2s_playback_channels;
1165 
1166 	/**
1167 	 * @hdmi_audio_i2s_formats: supported I2S formats, optional. The
1168 	 * default is to allow all formats supported by the corresponding I2S
1169 	 * bus driver. This is only used for bridges setting
1170 	 * @DRM_BRIDGE_OP_HDMI_AUDIO or @DRM_BRIDGE_OP_DP_AUDIO.
1171 	 */
1172 	u64 hdmi_audio_i2s_formats;
1173 
1174 	/**
1175 	 * @hdmi_audio_spdif_playback: set if this bridge has S/PDIF playback
1176 	 * port for @DRM_BRIDGE_OP_HDMI_AUDIO or @DRM_BRIDGE_OP_DP_AUDIO.
1177 	 */
1178 	unsigned int hdmi_audio_spdif_playback : 1;
1179 
1180 	/**
1181 	 * @hdmi_audio_dai_port: sound DAI port for either of
1182 	 * @DRM_BRIDGE_OP_HDMI_AUDIO and @DRM_BRIDGE_OP_DP_AUDIO, -1 if it is
1183 	 * not used.
1184 	 */
1185 	int hdmi_audio_dai_port;
1186 
1187 	/**
1188 	 * @hdmi_cec_adapter_name: the name of the adapter to register
1189 	 */
1190 	const char *hdmi_cec_adapter_name;
1191 
1192 	/**
1193 	 * @hdmi_cec_available_las: number of logical addresses, CEC_MAX_LOG_ADDRS if unset
1194 	 */
1195 	u8 hdmi_cec_available_las;
1196 
1197 	/** private: */
1198 	/**
1199 	 * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields.
1200 	 */
1201 	struct mutex hpd_mutex;
1202 	/**
1203 	 * @hpd_state_mutex: Protects the HPD en/disablement state for the bridge.
1204 	 */
1205 	struct mutex hpd_state_mutex;
1206 	/**
1207 	 * @hpd_cb: Hot plug detection callback, registered with
1208 	 * drm_bridge_hpd_enable().
1209 	 */
1210 	void (*hpd_cb)(void *data, enum drm_connector_status status);
1211 	/**
1212 	 * @hpd_data: Private data passed to the Hot plug detection callback
1213 	 * @hpd_cb.
1214 	 */
1215 	void *hpd_data;
1216 
1217 	/**
1218 	 * @next_bridge: Pointer to the following bridge, automatically put
1219 	 * when this bridge is freed (i.e. at destroy time). This is for
1220 	 * drivers needing to store a pointer to the next bridge in the
1221 	 * chain, and ensures any code still holding a reference to this
1222 	 * bridge after its removal cannot use-after-free the next
1223 	 * bridge. Any other bridge pointers stored by the driver must be
1224 	 * put in the .destroy callback by driver code.
1225 	 */
1226 	struct drm_bridge *next_bridge;
1227 };
1228 
1229 static inline struct drm_bridge *
1230 drm_priv_to_bridge(struct drm_private_obj *priv)
1231 {
1232 	return container_of(priv, struct drm_bridge, base);
1233 }
1234 
1235 bool drm_bridge_enter(struct drm_bridge *bridge, int *idx);
1236 void drm_bridge_exit(int idx);
1237 void drm_bridge_unplug(struct drm_bridge *bridge);
1238 
1239 struct drm_bridge *drm_bridge_get(struct drm_bridge *bridge);
1240 void drm_bridge_put(struct drm_bridge *bridge);
1241 void drm_bridge_clear_and_put(struct drm_bridge **bridge_pp);
1242 
1243 /* Cleanup action for use with __free() */
1244 DEFINE_FREE(drm_bridge_put, struct drm_bridge *, if (_T) drm_bridge_put(_T))
1245 
1246 void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offset,
1247 			      const struct drm_bridge_funcs *funcs);
1248 
1249 /**
1250  * devm_drm_bridge_alloc - Allocate and initialize a bridge
1251  * @dev: struct device of the bridge device
1252  * @type: the type of the struct which contains struct &drm_bridge
1253  * @member: the name of the &drm_bridge within @type
1254  * @funcs: callbacks for this bridge
1255  *
1256  * The reference count of the returned bridge is initialized to 1. This
1257  * reference will be automatically dropped via devm (by calling
1258  * drm_bridge_put()) when @dev is removed.
1259  *
1260  * Returns:
1261  * Pointer to new bridge, or ERR_PTR on failure.
1262  */
1263 #define devm_drm_bridge_alloc(dev, type, member, funcs) \
1264 	((type *)__devm_drm_bridge_alloc(dev, sizeof(type), \
1265 					 offsetof(type, member), funcs))
1266 
1267 void drm_bridge_add(struct drm_bridge *bridge);
1268 int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge);
1269 void drm_bridge_remove(struct drm_bridge *bridge);
1270 int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
1271 		      struct drm_bridge *previous,
1272 		      enum drm_bridge_attach_flags flags);
1273 
1274 #ifdef CONFIG_OF
1275 struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np);
1276 struct drm_bridge *of_drm_find_bridge(struct device_node *np);
1277 struct drm_bridge *of_drm_get_bridge_by_endpoint(const struct device_node *np,
1278 						 int port, int endpoint);
1279 #else
1280 static inline struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np)
1281 {
1282 	return NULL;
1283 }
1284 static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np)
1285 {
1286 	return NULL;
1287 }
1288 static inline struct drm_bridge *of_drm_get_bridge_by_endpoint(const struct device_node *np,
1289 							       int port, int endpoint)
1290 {
1291 	return ERR_PTR(-ENODEV);
1292 }
1293 #endif
1294 
1295 static inline bool drm_bridge_is_last(struct drm_bridge *bridge)
1296 {
1297 	return list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain);
1298 }
1299 
1300 /**
1301  * drm_bridge_get_current_state() - Get the current bridge state
1302  * @bridge: bridge object
1303  *
1304  * This function must be called with the modeset lock held.
1305  *
1306  * RETURNS:
1307  *
1308  * The current bridge state, or NULL if there is none.
1309  */
1310 static inline struct drm_bridge_state *
1311 drm_bridge_get_current_state(struct drm_bridge *bridge)
1312 {
1313 	if (!bridge)
1314 		return NULL;
1315 
1316 	drm_modeset_lock_assert_held(&bridge->base.lock);
1317 
1318 	if (!bridge->base.state)
1319 		return NULL;
1320 
1321 	return drm_priv_to_bridge_state(bridge->base.state);
1322 }
1323 
1324 /**
1325  * drm_bridge_get_next_bridge() - Get the next bridge in the chain
1326  * @bridge: bridge object
1327  *
1328  * The caller is responsible of having a reference to @bridge via
1329  * drm_bridge_get() or equivalent. This function leaves the refcount of
1330  * @bridge unmodified.
1331  *
1332  * The refcount of the returned bridge is incremented. Use drm_bridge_put()
1333  * when done with it.
1334  *
1335  * RETURNS:
1336  * the next bridge in the chain after @bridge, or NULL if @bridge is the last.
1337  */
1338 static inline struct drm_bridge *
1339 drm_bridge_get_next_bridge(struct drm_bridge *bridge)
1340 {
1341 	if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain))
1342 		return NULL;
1343 
1344 	return drm_bridge_get(list_next_entry(bridge, chain_node));
1345 }
1346 
1347 /**
1348  * drm_bridge_get_prev_bridge() - Get the previous bridge in the chain
1349  * @bridge: bridge object
1350  *
1351  * The caller is responsible of having a reference to @bridge via
1352  * drm_bridge_get() or equivalent. This function leaves the refcount of
1353  * @bridge unmodified.
1354  *
1355  * The refcount of the returned bridge is incremented. Use drm_bridge_put()
1356  * when done with it.
1357  *
1358  * RETURNS:
1359  * the previous bridge in the chain, or NULL if @bridge is the first.
1360  */
1361 static inline struct drm_bridge *
1362 drm_bridge_get_prev_bridge(struct drm_bridge *bridge)
1363 {
1364 	if (list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain))
1365 		return NULL;
1366 
1367 	return drm_bridge_get(list_prev_entry(bridge, chain_node));
1368 }
1369 
1370 /**
1371  * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain
1372  * @encoder: encoder object
1373  *
1374  * The refcount of the returned bridge is incremented. Use drm_bridge_put()
1375  * when done with it.
1376  *
1377  * RETURNS:
1378  * the first bridge in the chain, or NULL if @encoder has no bridge attached
1379  * to it.
1380  */
1381 static inline struct drm_bridge *
1382 drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder)
1383 {
1384 	return drm_bridge_get(list_first_entry_or_null(&encoder->bridge_chain,
1385 						       struct drm_bridge, chain_node));
1386 }
1387 
1388 /**
1389  * drm_bridge_chain_get_last_bridge() - Get the last bridge in the chain
1390  * @encoder: encoder object
1391  *
1392  * The refcount of the returned bridge is incremented. Use drm_bridge_put()
1393  * when done with it.
1394  *
1395  * RETURNS:
1396  * the last bridge in the chain, or NULL if @encoder has no bridge attached
1397  * to it.
1398  */
1399 static inline struct drm_bridge *
1400 drm_bridge_chain_get_last_bridge(struct drm_encoder *encoder)
1401 {
1402 	return drm_bridge_get(list_last_entry_or_null(&encoder->bridge_chain,
1403 						      struct drm_bridge, chain_node));
1404 }
1405 
1406 /* Internal to drm_for_each_bridge_in_chain*() */
1407 static inline struct drm_bridge *__drm_for_each_bridge_in_chain_next(struct drm_bridge *bridge)
1408 {
1409 	struct drm_bridge *next = drm_bridge_get_next_bridge(bridge);
1410 
1411 	if (!next)
1412 		mutex_unlock(&bridge->encoder->bridge_chain_mutex);
1413 
1414 	drm_bridge_put(bridge);
1415 
1416 	return next;
1417 }
1418 
1419 /* Internal to drm_for_each_bridge_in_chain*() */
1420 DEFINE_FREE(__drm_for_each_bridge_in_chain_cleanup, struct drm_bridge *,
1421 	if (_T) { mutex_unlock(&_T->encoder->bridge_chain_mutex); drm_bridge_put(_T); })
1422 
1423 /* Internal to drm_for_each_bridge_in_chain() */
1424 static inline struct drm_bridge *
1425 __drm_for_each_bridge_in_chain_start(struct drm_encoder *encoder)
1426 {
1427 	mutex_lock(&encoder->bridge_chain_mutex);
1428 
1429 	struct drm_bridge *bridge = drm_bridge_chain_get_first_bridge(encoder);
1430 
1431 	if (!bridge)
1432 		mutex_unlock(&encoder->bridge_chain_mutex);
1433 
1434 	return bridge;
1435 }
1436 
1437 /**
1438  * drm_for_each_bridge_in_chain - iterate over all bridges attached to an encoder
1439  * @encoder: the encoder to iterate bridges on
1440  * @bridge: a bridge pointer updated to point to the current bridge at each
1441  *	    iteration
1442  *
1443  * Iterate over all bridges present in the bridge chain attached to @encoder.
1444  *
1445  * Automatically gets/puts the bridge reference while iterating and locks
1446  * the encoder chain mutex to prevent chain modifications while iterating.
1447  */
1448 #define drm_for_each_bridge_in_chain(encoder, bridge)					\
1449 	for (struct drm_bridge *bridge __free(__drm_for_each_bridge_in_chain_cleanup) =	\
1450 		__drm_for_each_bridge_in_chain_start((encoder));			\
1451 	     bridge;									\
1452 	     bridge = __drm_for_each_bridge_in_chain_next(bridge))			\
1453 
1454 /* Internal to drm_for_each_bridge_in_chain_from() */
1455 static inline struct drm_bridge *
1456 __drm_for_each_bridge_in_chain_from_start(struct drm_bridge *bridge)
1457 {
1458 	drm_bridge_get(bridge);
1459 	mutex_lock(&bridge->encoder->bridge_chain_mutex);
1460 
1461 	return bridge;
1462 }
1463 
1464 /**
1465  * drm_for_each_bridge_in_chain_from - iterate over all bridges starting
1466  *                                     from the given bridge
1467  * @first_bridge: the bridge to start from
1468  * @bridge: a bridge pointer updated to point to the current bridge at each
1469  *	    iteration
1470  *
1471  * Iterate over all bridges in the encoder chain starting from
1472  * @first_bridge, included.
1473  *
1474  * Automatically gets/puts the bridge reference while iterating and locks
1475  * the encoder chain mutex to prevent chain modifications while iterating.
1476  */
1477 #define drm_for_each_bridge_in_chain_from(first_bridge, bridge)				\
1478 	for (struct drm_bridge *bridge __free(__drm_for_each_bridge_in_chain_cleanup) =	\
1479 		__drm_for_each_bridge_in_chain_from_start(first_bridge);		\
1480 	     bridge;									\
1481 	     bridge = __drm_for_each_bridge_in_chain_next(bridge))			\
1482 
1483 enum drm_mode_status
1484 drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
1485 			    const struct drm_display_info *info,
1486 			    const struct drm_display_mode *mode);
1487 void drm_bridge_chain_mode_set(struct drm_bridge *bridge,
1488 			       const struct drm_display_mode *mode,
1489 			       const struct drm_display_mode *adjusted_mode);
1490 
1491 int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,
1492 				  struct drm_crtc_state *crtc_state,
1493 				  struct drm_connector_state *conn_state);
1494 void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,
1495 				     struct drm_atomic_commit *state);
1496 void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,
1497 					  struct drm_atomic_commit *state);
1498 void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,
1499 					struct drm_atomic_commit *state);
1500 void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,
1501 				    struct drm_atomic_commit *state);
1502 
1503 u32 *
1504 drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
1505 					struct drm_bridge_state *bridge_state,
1506 					struct drm_crtc_state *crtc_state,
1507 					struct drm_connector_state *conn_state,
1508 					u32 output_fmt,
1509 					unsigned int *num_input_fmts);
1510 
1511 enum drm_connector_status
1512 drm_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connector);
1513 int drm_bridge_get_modes(struct drm_bridge *bridge,
1514 			 struct drm_connector *connector);
1515 const struct drm_edid *drm_bridge_edid_read(struct drm_bridge *bridge,
1516 					    struct drm_connector *connector);
1517 void drm_bridge_hpd_enable(struct drm_bridge *bridge,
1518 			   void (*cb)(void *data,
1519 				      enum drm_connector_status status),
1520 			   void *data);
1521 void drm_bridge_hpd_disable(struct drm_bridge *bridge);
1522 void drm_bridge_hpd_notify(struct drm_bridge *bridge,
1523 			   enum drm_connector_status status);
1524 
1525 void devm_drm_put_bridge(struct device *dev, struct drm_bridge *bridge);
1526 
1527 void drm_bridge_debugfs_params(struct dentry *root);
1528 void drm_bridge_debugfs_encoder_params(struct dentry *root, struct drm_encoder *encoder);
1529 
1530 #endif
1531