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