blob: 018e195c48083e765d229524ed56ecdc5327820f [file] [log] [blame]
Daniel Vetter199e4e92016-08-31 18:09:05 +02001/*
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
Daniel Vetter199e4e92016-08-31 18:09:05 +020026#include <linux/ctype.h>
Laurent Pinchart11f6c4b2020-02-26 13:24:27 +020027#include <linux/list.h>
28#include <linux/mutex.h>
Boris Brezillon75146592020-01-28 14:55:03 +010029
30#include <drm/drm_atomic.h>
Boris Brezillon35a61fe2019-12-03 15:15:07 +010031#include <drm/drm_encoder.h>
Daniel Vetter199e4e92016-08-31 18:09:05 +020032#include <drm/drm_mode_object.h>
33#include <drm/drm_modes.h>
34
35struct drm_bridge;
Linus Walleij36a776d2018-01-12 08:48:52 +010036struct drm_bridge_timings;
Laurent Pinchart11f6c4b2020-02-26 13:24:27 +020037struct drm_connector;
Eric Anholt13dfc052017-06-02 13:25:14 -070038struct drm_panel;
Laurent Pinchart11f6c4b2020-02-26 13:24:27 +020039struct edid;
40struct i2c_adapter;
Daniel Vetter199e4e92016-08-31 18:09:05 +020041
42/**
43 * struct drm_bridge_funcs - drm_bridge control functions
44 */
45struct drm_bridge_funcs {
46 /**
47 * @attach:
48 *
49 * This callback is invoked whenever our bridge is being attached to a
50 * &drm_encoder.
51 *
Laurent Pinchartfe9e5572019-08-22 02:55:02 +030052 * The @attach callback is optional.
Daniel Vetter199e4e92016-08-31 18:09:05 +020053 *
54 * RETURNS:
55 *
56 * Zero on success, error code on failure.
57 */
58 int (*attach)(struct drm_bridge *bridge);
59
60 /**
61 * @detach:
62 *
63 * This callback is invoked whenever our bridge is being detached from a
64 * &drm_encoder.
65 *
Laurent Pinchartfe9e5572019-08-22 02:55:02 +030066 * The @detach callback is optional.
Daniel Vetter199e4e92016-08-31 18:09:05 +020067 */
68 void (*detach)(struct drm_bridge *bridge);
69
70 /**
Jose Abreu3eb220a2017-05-15 11:33:47 +020071 * @mode_valid:
72 *
73 * This callback is used to check if a specific mode is valid in this
74 * bridge. This should be implemented if the bridge has some sort of
75 * restriction in the modes it can display. For example, a given bridge
76 * may be responsible to set a clock value. If the clock can not
77 * produce all the values for the available modes then this callback
78 * can be used to restrict the number of modes to only the ones that
79 * can be displayed.
80 *
81 * This hook is used by the probe helpers to filter the mode list in
82 * drm_helper_probe_single_connector_modes(), and it is used by the
83 * atomic helpers to validate modes supplied by userspace in
84 * drm_atomic_helper_check_modeset().
85 *
Laurent Pinchartfe9e5572019-08-22 02:55:02 +030086 * The @mode_valid callback is optional.
Jose Abreu3eb220a2017-05-15 11:33:47 +020087 *
88 * NOTE:
89 *
90 * Since this function is both called from the check phase of an atomic
91 * commit, and the mode validation in the probe paths it is not allowed
92 * to look at anything else but the passed-in mode, and validate it
93 * against configuration-invariant hardward constraints. Any further
94 * limits which depend upon the configuration can only be checked in
95 * @mode_fixup.
96 *
97 * RETURNS:
98 *
99 * drm_mode_status Enum
100 */
Linus Walleij312924d2018-01-29 10:55:31 +0100101 enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge,
Jose Abreu3eb220a2017-05-15 11:33:47 +0200102 const struct drm_display_mode *mode);
103
104 /**
Daniel Vetter199e4e92016-08-31 18:09:05 +0200105 * @mode_fixup:
106 *
Philippe Cornu5d435b42018-05-15 22:37:36 +0200107 * This callback is used to validate and adjust a mode. The parameter
Daniel Vetter199e4e92016-08-31 18:09:05 +0200108 * mode is the display mode that should be fed to the next element in
109 * the display chain, either the final &drm_connector or the next
110 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
111 * requires. It can be modified by this callback and does not need to
Daniel Vetter9de5d4a2017-05-15 11:11:35 +0200112 * match mode. See also &drm_crtc_state.adjusted_mode for more details.
Daniel Vetter199e4e92016-08-31 18:09:05 +0200113 *
114 * This is the only hook that allows a bridge to reject a modeset. If
115 * this function passes all other callbacks must succeed for this
116 * configuration.
117 *
Boris Brezillon5061b8a2020-01-28 14:55:07 +0100118 * The mode_fixup callback is optional. &drm_bridge_funcs.mode_fixup()
119 * is not called when &drm_bridge_funcs.atomic_check() is implemented,
120 * so only one of them should be provided.
Daniel Vetter199e4e92016-08-31 18:09:05 +0200121 *
122 * NOTE:
123 *
124 * This function is called in the check phase of atomic modesets, which
125 * can be aborted for any reason (including on userspace's request to
126 * just check whether a configuration would be possible). Drivers MUST
127 * NOT touch any persistent state (hardware or software) or data
128 * structures except the passed in @state parameter.
129 *
Jose Abreu3eb220a2017-05-15 11:33:47 +0200130 * Also beware that userspace can request its own custom modes, neither
131 * core nor helpers filter modes to the list of probe modes reported by
132 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
133 * that modes are filtered consistently put any bridge constraints and
134 * limits checks into @mode_valid.
135 *
Daniel Vetter199e4e92016-08-31 18:09:05 +0200136 * RETURNS:
137 *
138 * True if an acceptable configuration is possible, false if the modeset
139 * operation should be rejected.
140 */
141 bool (*mode_fixup)(struct drm_bridge *bridge,
142 const struct drm_display_mode *mode,
143 struct drm_display_mode *adjusted_mode);
144 /**
145 * @disable:
146 *
147 * This callback should disable the bridge. It is called right before
148 * the preceding element in the display pipe is disabled. If the
149 * preceding element is a bridge this means it's called before that
Daniel Vetter4541d312017-01-02 09:17:26 +0100150 * bridge's @disable vfunc. If the preceding element is a &drm_encoder
151 * it's called right before the &drm_encoder_helper_funcs.disable,
152 * &drm_encoder_helper_funcs.prepare or &drm_encoder_helper_funcs.dpms
153 * hook.
Daniel Vetter199e4e92016-08-31 18:09:05 +0200154 *
155 * The bridge can assume that the display pipe (i.e. clocks and timing
156 * signals) feeding it is still running when this callback is called.
157 *
Laurent Pinchartfe9e5572019-08-22 02:55:02 +0300158 * The @disable callback is optional.
Daniel Vetter199e4e92016-08-31 18:09:05 +0200159 */
160 void (*disable)(struct drm_bridge *bridge);
161
162 /**
163 * @post_disable:
164 *
Daniel Vetter4541d312017-01-02 09:17:26 +0100165 * This callback should disable the bridge. It is called right after the
166 * preceding element in the display pipe is disabled. If the preceding
167 * element is a bridge this means it's called after that bridge's
168 * @post_disable function. If the preceding element is a &drm_encoder
169 * it's called right after the encoder's
170 * &drm_encoder_helper_funcs.disable, &drm_encoder_helper_funcs.prepare
171 * or &drm_encoder_helper_funcs.dpms hook.
Daniel Vetter199e4e92016-08-31 18:09:05 +0200172 *
173 * The bridge must assume that the display pipe (i.e. clocks and timing
174 * singals) feeding it is no longer running when this callback is
175 * called.
176 *
Laurent Pinchartfe9e5572019-08-22 02:55:02 +0300177 * The @post_disable callback is optional.
Daniel Vetter199e4e92016-08-31 18:09:05 +0200178 */
179 void (*post_disable)(struct drm_bridge *bridge);
180
181 /**
182 * @mode_set:
183 *
184 * This callback should set the given mode on the bridge. It is called
Daniel Vetter4541d312017-01-02 09:17:26 +0100185 * after the @mode_set callback for the preceding element in the display
186 * pipeline has been called already. If the bridge is the first element
187 * then this would be &drm_encoder_helper_funcs.mode_set. The display
188 * pipe (i.e. clocks and timing signals) is off when this function is
189 * called.
Philippe Cornu584a0142018-04-09 17:24:27 +0200190 *
191 * The adjusted_mode parameter is the mode output by the CRTC for the
192 * first bridge in the chain. It can be different from the mode
193 * parameter that contains the desired mode for the connector at the end
194 * of the bridges chain, for instance when the first bridge in the chain
195 * performs scaling. The adjusted mode is mostly useful for the first
196 * bridge in the chain and is likely irrelevant for the other bridges.
197 *
198 * For atomic drivers the adjusted_mode is the mode stored in
199 * &drm_crtc_state.adjusted_mode.
200 *
201 * NOTE:
202 *
203 * If a need arises to store and access modes adjusted for other
204 * locations than the connection between the CRTC and the first bridge,
205 * the DRM framework will have to be extended with DRM bridge states.
Daniel Vetter199e4e92016-08-31 18:09:05 +0200206 */
207 void (*mode_set)(struct drm_bridge *bridge,
Laurent Pinchart63f8f3b2018-04-06 17:39:01 +0300208 const struct drm_display_mode *mode,
209 const struct drm_display_mode *adjusted_mode);
Daniel Vetter199e4e92016-08-31 18:09:05 +0200210 /**
211 * @pre_enable:
212 *
213 * This callback should enable the bridge. It is called right before
214 * the preceding element in the display pipe is enabled. If the
215 * preceding element is a bridge this means it's called before that
Daniel Vetter4541d312017-01-02 09:17:26 +0100216 * bridge's @pre_enable function. If the preceding element is a
217 * &drm_encoder it's called right before the encoder's
218 * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
219 * &drm_encoder_helper_funcs.dpms hook.
Daniel Vetter199e4e92016-08-31 18:09:05 +0200220 *
221 * The display pipe (i.e. clocks and timing signals) feeding this bridge
222 * will not yet be running when this callback is called. The bridge must
223 * not enable the display link feeding the next bridge in the chain (if
224 * there is one) when this callback is called.
225 *
Laurent Pinchartfe9e5572019-08-22 02:55:02 +0300226 * The @pre_enable callback is optional.
Daniel Vetter199e4e92016-08-31 18:09:05 +0200227 */
228 void (*pre_enable)(struct drm_bridge *bridge);
229
230 /**
231 * @enable:
232 *
233 * This callback should enable the bridge. It is called right after
234 * the preceding element in the display pipe is enabled. If the
235 * preceding element is a bridge this means it's called after that
Daniel Vetter4541d312017-01-02 09:17:26 +0100236 * bridge's @enable function. If the preceding element is a
237 * &drm_encoder it's called right after the encoder's
238 * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
239 * &drm_encoder_helper_funcs.dpms hook.
Daniel Vetter199e4e92016-08-31 18:09:05 +0200240 *
241 * The bridge can assume that the display pipe (i.e. clocks and timing
242 * signals) feeding it is running when this callback is called. This
243 * callback must enable the display link feeding the next bridge in the
244 * chain if there is one.
245 *
Laurent Pinchartfe9e5572019-08-22 02:55:02 +0300246 * The @enable callback is optional.
Daniel Vetter199e4e92016-08-31 18:09:05 +0200247 */
248 void (*enable)(struct drm_bridge *bridge);
Sean Paul5ade0712019-06-11 12:08:17 -0400249
250 /**
251 * @atomic_pre_enable:
252 *
253 * This callback should enable the bridge. It is called right before
254 * the preceding element in the display pipe is enabled. If the
255 * preceding element is a bridge this means it's called before that
256 * bridge's @atomic_pre_enable or @pre_enable function. If the preceding
257 * element is a &drm_encoder it's called right before the encoder's
258 * &drm_encoder_helper_funcs.atomic_enable hook.
259 *
260 * The display pipe (i.e. clocks and timing signals) feeding this bridge
261 * will not yet be running when this callback is called. The bridge must
262 * not enable the display link feeding the next bridge in the chain (if
263 * there is one) when this callback is called.
264 *
265 * Note that this function will only be invoked in the context of an
Boris Brezillonea099ad2019-12-03 15:15:05 +0100266 * atomic commit. It will not be invoked from
267 * &drm_bridge_chain_pre_enable. It would be prudent to also provide an
268 * implementation of @pre_enable if you are expecting driver calls into
269 * &drm_bridge_chain_pre_enable.
Sean Paul5ade0712019-06-11 12:08:17 -0400270 *
271 * The @atomic_pre_enable callback is optional.
272 */
273 void (*atomic_pre_enable)(struct drm_bridge *bridge,
Boris Brezillon41cf5712020-01-28 14:55:06 +0100274 struct drm_bridge_state *old_bridge_state);
Sean Paul5ade0712019-06-11 12:08:17 -0400275
276 /**
277 * @atomic_enable:
278 *
279 * This callback should enable the bridge. It is called right after
280 * the preceding element in the display pipe is enabled. If the
281 * preceding element is a bridge this means it's called after that
282 * bridge's @atomic_enable or @enable function. If the preceding element
283 * is a &drm_encoder it's called right after the encoder's
284 * &drm_encoder_helper_funcs.atomic_enable hook.
285 *
286 * The bridge can assume that the display pipe (i.e. clocks and timing
287 * signals) feeding it is running when this callback is called. This
288 * callback must enable the display link feeding the next bridge in the
289 * chain if there is one.
290 *
291 * Note that this function will only be invoked in the context of an
Boris Brezillonea099ad2019-12-03 15:15:05 +0100292 * atomic commit. It will not be invoked from &drm_bridge_chain_enable.
293 * It would be prudent to also provide an implementation of @enable if
294 * you are expecting driver calls into &drm_bridge_chain_enable.
Sean Paul5ade0712019-06-11 12:08:17 -0400295 *
Laurent Pinchartfe9e5572019-08-22 02:55:02 +0300296 * The @atomic_enable callback is optional.
Sean Paul5ade0712019-06-11 12:08:17 -0400297 */
298 void (*atomic_enable)(struct drm_bridge *bridge,
Boris Brezillon41cf5712020-01-28 14:55:06 +0100299 struct drm_bridge_state *old_bridge_state);
Sean Paul5ade0712019-06-11 12:08:17 -0400300 /**
301 * @atomic_disable:
302 *
303 * This callback should disable the bridge. It is called right before
304 * the preceding element in the display pipe is disabled. If the
305 * preceding element is a bridge this means it's called before that
306 * bridge's @atomic_disable or @disable vfunc. If the preceding element
307 * is a &drm_encoder it's called right before the
308 * &drm_encoder_helper_funcs.atomic_disable hook.
309 *
310 * The bridge can assume that the display pipe (i.e. clocks and timing
311 * signals) feeding it is still running when this callback is called.
312 *
313 * Note that this function will only be invoked in the context of an
Boris Brezillonea099ad2019-12-03 15:15:05 +0100314 * atomic commit. It will not be invoked from
315 * &drm_bridge_chain_disable. It would be prudent to also provide an
316 * implementation of @disable if you are expecting driver calls into
317 * &drm_bridge_chain_disable.
Sean Paul5ade0712019-06-11 12:08:17 -0400318 *
Laurent Pinchartfe9e5572019-08-22 02:55:02 +0300319 * The @atomic_disable callback is optional.
Sean Paul5ade0712019-06-11 12:08:17 -0400320 */
321 void (*atomic_disable)(struct drm_bridge *bridge,
Boris Brezillon41cf5712020-01-28 14:55:06 +0100322 struct drm_bridge_state *old_bridge_state);
Sean Paul5ade0712019-06-11 12:08:17 -0400323
324 /**
325 * @atomic_post_disable:
326 *
327 * This callback should disable the bridge. It is called right after the
328 * preceding element in the display pipe is disabled. If the preceding
329 * element is a bridge this means it's called after that bridge's
330 * @atomic_post_disable or @post_disable function. If the preceding
331 * element is a &drm_encoder it's called right after the encoder's
332 * &drm_encoder_helper_funcs.atomic_disable hook.
333 *
334 * The bridge must assume that the display pipe (i.e. clocks and timing
335 * signals) feeding it is no longer running when this callback is
336 * called.
337 *
338 * Note that this function will only be invoked in the context of an
Boris Brezillonea099ad2019-12-03 15:15:05 +0100339 * atomic commit. It will not be invoked from
340 * &drm_bridge_chain_post_disable.
Sean Paul5ade0712019-06-11 12:08:17 -0400341 * It would be prudent to also provide an implementation of
342 * @post_disable if you are expecting driver calls into
Boris Brezillonea099ad2019-12-03 15:15:05 +0100343 * &drm_bridge_chain_post_disable.
Sean Paul5ade0712019-06-11 12:08:17 -0400344 *
Laurent Pinchartfe9e5572019-08-22 02:55:02 +0300345 * The @atomic_post_disable callback is optional.
Sean Paul5ade0712019-06-11 12:08:17 -0400346 */
347 void (*atomic_post_disable)(struct drm_bridge *bridge,
Boris Brezillon41cf5712020-01-28 14:55:06 +0100348 struct drm_bridge_state *old_bridge_state);
Boris Brezillon75146592020-01-28 14:55:03 +0100349
350 /**
351 * @atomic_duplicate_state:
352 *
353 * Duplicate the current bridge state object (which is guaranteed to be
354 * non-NULL).
355 *
Laurent Pinchart282f7132020-02-26 13:24:25 +0200356 * The atomic_duplicate_state hook is mandatory if the bridge
357 * implements any of the atomic hooks, and should be left unassigned
358 * otherwise. For bridges that don't subclass &drm_bridge_state, the
359 * drm_atomic_helper_bridge_duplicate_state() helper function shall be
360 * used to implement this hook.
Boris Brezillon75146592020-01-28 14:55:03 +0100361 *
362 * RETURNS:
363 * A valid drm_bridge_state object or NULL if the allocation fails.
364 */
365 struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge);
366
367 /**
368 * @atomic_destroy_state:
369 *
370 * Destroy a bridge state object previously allocated by
371 * &drm_bridge_funcs.atomic_duplicate_state().
372 *
Laurent Pinchart282f7132020-02-26 13:24:25 +0200373 * The atomic_destroy_state hook is mandatory if the bridge implements
374 * any of the atomic hooks, and should be left unassigned otherwise.
375 * For bridges that don't subclass &drm_bridge_state, the
376 * drm_atomic_helper_bridge_destroy_state() helper function shall be
377 * used to implement this hook.
Boris Brezillon75146592020-01-28 14:55:03 +0100378 */
379 void (*atomic_destroy_state)(struct drm_bridge *bridge,
380 struct drm_bridge_state *state);
381
382 /**
Boris Brezillonf32df582020-01-28 14:55:08 +0100383 * @atomic_get_output_bus_fmts:
384 *
385 * Return the supported bus formats on the output end of a bridge.
386 * The returned array must be allocated with kmalloc() and will be
387 * freed by the caller. If the allocation fails, NULL should be
388 * returned. num_output_fmts must be set to the returned array size.
389 * Formats listed in the returned array should be listed in decreasing
390 * preference order (the core will try all formats until it finds one
391 * that works).
392 *
393 * This method is only called on the last element of the bridge chain
394 * as part of the bus format negotiation process that happens in
395 * &drm_atomic_bridge_chain_select_bus_fmts().
396 * This method is optional. When not implemented, the core will
397 * fall back to &drm_connector.display_info.bus_formats[0] if
398 * &drm_connector.display_info.num_bus_formats > 0,
399 * or to MEDIA_BUS_FMT_FIXED otherwise.
400 */
401 u32 *(*atomic_get_output_bus_fmts)(struct drm_bridge *bridge,
402 struct drm_bridge_state *bridge_state,
403 struct drm_crtc_state *crtc_state,
404 struct drm_connector_state *conn_state,
405 unsigned int *num_output_fmts);
406
407 /**
408 * @atomic_get_input_bus_fmts:
409 *
410 * Return the supported bus formats on the input end of a bridge for
411 * a specific output bus format.
412 *
413 * The returned array must be allocated with kmalloc() and will be
414 * freed by the caller. If the allocation fails, NULL should be
415 * returned. num_output_fmts must be set to the returned array size.
416 * Formats listed in the returned array should be listed in decreasing
417 * preference order (the core will try all formats until it finds one
418 * that works). When the format is not supported NULL should be
Boris Brezillon91ea8332020-02-18 16:15:03 +0100419 * returned and num_output_fmts should be set to 0.
Boris Brezillonf32df582020-01-28 14:55:08 +0100420 *
421 * This method is called on all elements of the bridge chain as part of
422 * the bus format negotiation process that happens in
Boris Brezillon91ea8332020-02-18 16:15:03 +0100423 * drm_atomic_bridge_chain_select_bus_fmts().
Boris Brezillonf32df582020-01-28 14:55:08 +0100424 * This method is optional. When not implemented, the core will bypass
425 * bus format negotiation on this element of the bridge without
426 * failing, and the previous element in the chain will be passed
427 * MEDIA_BUS_FMT_FIXED as its output bus format.
428 *
429 * Bridge drivers that need to support being linked to bridges that are
430 * not supporting bus format negotiation should handle the
431 * output_fmt == MEDIA_BUS_FMT_FIXED case appropriately, by selecting a
432 * sensible default value or extracting this information from somewhere
433 * else (FW property, &drm_display_mode, &drm_display_info, ...)
434 *
435 * Note: Even if input format selection on the first bridge has no
436 * impact on the negotiation process (bus format negotiation stops once
437 * we reach the first element of the chain), drivers are expected to
438 * return accurate input formats as the input format may be used to
439 * configure the CRTC output appropriately.
440 */
441 u32 *(*atomic_get_input_bus_fmts)(struct drm_bridge *bridge,
442 struct drm_bridge_state *bridge_state,
443 struct drm_crtc_state *crtc_state,
444 struct drm_connector_state *conn_state,
445 u32 output_fmt,
446 unsigned int *num_input_fmts);
447
448 /**
Boris Brezillon5061b8a2020-01-28 14:55:07 +0100449 * @atomic_check:
450 *
451 * This method is responsible for checking bridge state correctness.
452 * It can also check the state of the surrounding components in chain
453 * to make sure the whole pipeline can work properly.
454 *
455 * &drm_bridge_funcs.atomic_check() hooks are called in reverse
456 * order (from the last to the first bridge).
457 *
458 * This method is optional. &drm_bridge_funcs.mode_fixup() is not
459 * called when &drm_bridge_funcs.atomic_check() is implemented, so only
460 * one of them should be provided.
461 *
Boris Brezillonf32df582020-01-28 14:55:08 +0100462 * If drivers need to tweak &drm_bridge_state.input_bus_cfg.flags or
463 * &drm_bridge_state.output_bus_cfg.flags it should should happen in
464 * this function. By default the &drm_bridge_state.output_bus_cfg.flags
465 * field is set to the next bridge
466 * &drm_bridge_state.input_bus_cfg.flags value or
467 * &drm_connector.display_info.bus_flags if the bridge is the last
468 * element in the chain.
469 *
Boris Brezillon5061b8a2020-01-28 14:55:07 +0100470 * RETURNS:
471 * zero if the check passed, a negative error code otherwise.
472 */
473 int (*atomic_check)(struct drm_bridge *bridge,
474 struct drm_bridge_state *bridge_state,
475 struct drm_crtc_state *crtc_state,
476 struct drm_connector_state *conn_state);
477
478 /**
Boris Brezillon75146592020-01-28 14:55:03 +0100479 * @atomic_reset:
480 *
481 * Reset the bridge to a predefined state (or retrieve its current
482 * state) and return a &drm_bridge_state object matching this state.
483 * This function is called at attach time.
484 *
485 * The atomic_reset hook is mandatory if the bridge implements any of
Laurent Pinchart282f7132020-02-26 13:24:25 +0200486 * the atomic hooks, and should be left unassigned otherwise. For
487 * bridges that don't subclass &drm_bridge_state, the
488 * drm_atomic_helper_bridge_reset() helper function shall be used to
489 * implement this hook.
Boris Brezillon75146592020-01-28 14:55:03 +0100490 *
491 * Note that the atomic_reset() semantics is not exactly matching the
492 * reset() semantics found on other components (connector, plane, ...).
Boris Brezillon91ea8332020-02-18 16:15:03 +0100493 *
494 * 1. The reset operation happens when the bridge is attached, not when
Boris Brezillon75146592020-01-28 14:55:03 +0100495 * drm_mode_config_reset() is called
Boris Brezillon91ea8332020-02-18 16:15:03 +0100496 * 2. It's meant to be used exclusively on bridges that have been
Boris Brezillon75146592020-01-28 14:55:03 +0100497 * converted to the ATOMIC API
498 *
499 * RETURNS:
500 * A valid drm_bridge_state object in case of success, an ERR_PTR()
501 * giving the reason of the failure otherwise.
502 */
503 struct drm_bridge_state *(*atomic_reset)(struct drm_bridge *bridge);
Laurent Pinchart11f6c4b2020-02-26 13:24:27 +0200504
505 /**
506 * @detect:
507 *
508 * Check if anything is attached to the bridge output.
509 *
510 * This callback is optional, if not implemented the bridge will be
511 * considered as always having a component attached to its output.
512 * Bridges that implement this callback shall set the
513 * DRM_BRIDGE_OP_DETECT flag in their &drm_bridge->ops.
514 *
515 * RETURNS:
516 *
517 * drm_connector_status indicating the bridge output status.
518 */
519 enum drm_connector_status (*detect)(struct drm_bridge *bridge);
520
521 /**
522 * @get_modes:
523 *
524 * Fill all modes currently valid for the sink into the &drm_connector
525 * with drm_mode_probed_add().
526 *
527 * The @get_modes callback is mostly intended to support non-probeable
528 * displays such as many fixed panels. Bridges that support reading
529 * EDID shall leave @get_modes unimplemented and implement the
530 * &drm_bridge_funcs->get_edid callback instead.
531 *
532 * This callback is optional. Bridges that implement it shall set the
533 * DRM_BRIDGE_OP_MODES flag in their &drm_bridge->ops.
534 *
535 * The connector parameter shall be used for the sole purpose of
536 * filling modes, and shall not be stored internally by bridge drivers
537 * for future usage.
538 *
539 * RETURNS:
540 *
541 * The number of modes added by calling drm_mode_probed_add().
542 */
543 int (*get_modes)(struct drm_bridge *bridge,
544 struct drm_connector *connector);
545
546 /**
547 * @get_edid:
548 *
549 * Read and parse the EDID data of the connected display.
550 *
551 * The @get_edid callback is the preferred way of reporting mode
552 * information for a display connected to the bridge output. Bridges
553 * that support reading EDID shall implement this callback and leave
554 * the @get_modes callback unimplemented.
555 *
556 * The caller of this operation shall first verify the output
557 * connection status and refrain from reading EDID from a disconnected
558 * output.
559 *
560 * This callback is optional. Bridges that implement it shall set the
561 * DRM_BRIDGE_OP_EDID flag in their &drm_bridge->ops.
562 *
563 * The connector parameter shall be used for the sole purpose of EDID
564 * retrieval and parsing, and shall not be stored internally by bridge
565 * drivers for future usage.
566 *
567 * RETURNS:
568 *
569 * An edid structure newly allocated with kmalloc() (or similar) on
570 * success, or NULL otherwise. The caller is responsible for freeing
571 * the returned edid structure with kfree().
572 */
573 struct edid *(*get_edid)(struct drm_bridge *bridge,
574 struct drm_connector *connector);
575
576 /**
577 * @hpd_notify:
578 *
579 * Notify the bridge of hot plug detection.
580 *
581 * This callback is optional, it may be implemented by bridges that
582 * need to be notified of display connection or disconnection for
583 * internal reasons. One use case is to reset the internal state of CEC
584 * controllers for HDMI bridges.
585 */
586 void (*hpd_notify)(struct drm_bridge *bridge,
587 enum drm_connector_status status);
588
589 /**
590 * @hpd_enable:
591 *
592 * Enable hot plug detection. From now on the bridge shall call
593 * drm_bridge_hpd_notify() each time a change is detected in the output
594 * connection status, until hot plug detection gets disabled with
595 * @hpd_disable.
596 *
597 * This callback is optional and shall only be implemented by bridges
598 * that support hot-plug notification without polling. Bridges that
599 * implement it shall also implement the @hpd_disable callback and set
600 * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
601 */
602 void (*hpd_enable)(struct drm_bridge *bridge);
603
604 /**
605 * @hpd_disable:
606 *
607 * Disable hot plug detection. Once this function returns the bridge
608 * shall not call drm_bridge_hpd_notify() when a change in the output
609 * connection status occurs.
610 *
611 * This callback is optional and shall only be implemented by bridges
612 * that support hot-plug notification without polling. Bridges that
613 * implement it shall also implement the @hpd_enable callback and set
614 * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
615 */
616 void (*hpd_disable)(struct drm_bridge *bridge);
Daniel Vetter199e4e92016-08-31 18:09:05 +0200617};
618
619/**
Linus Walleij36a776d2018-01-12 08:48:52 +0100620 * struct drm_bridge_timings - timing information for the bridge
621 */
622struct drm_bridge_timings {
623 /**
Stefan Agnerd23286f2018-09-04 22:21:08 -0700624 * @input_bus_flags:
Linus Walleij36a776d2018-01-12 08:48:52 +0100625 *
Stefan Agnerd23286f2018-09-04 22:21:08 -0700626 * Tells what additional settings for the pixel data on the bus
627 * this bridge requires (like pixel signal polarity). See also
628 * &drm_display_info->bus_flags.
Linus Walleij36a776d2018-01-12 08:48:52 +0100629 */
Stefan Agnerd23286f2018-09-04 22:21:08 -0700630 u32 input_bus_flags;
Linus Walleij36a776d2018-01-12 08:48:52 +0100631 /**
632 * @setup_time_ps:
633 *
634 * Defines the time in picoseconds the input data lines must be
635 * stable before the clock edge.
636 */
637 u32 setup_time_ps;
638 /**
639 * @hold_time_ps:
640 *
641 * Defines the time in picoseconds taken for the bridge to sample the
642 * input signal after the clock edge.
643 */
644 u32 hold_time_ps;
Laurent Pinchartb0a6b942019-03-04 23:05:34 +0200645 /**
646 * @dual_link:
647 *
648 * True if the bus operates in dual-link mode. The exact meaning is
649 * dependent on the bus type. For LVDS buses, this indicates that even-
650 * and odd-numbered pixels are received on separate links.
651 */
652 bool dual_link;
Linus Walleij36a776d2018-01-12 08:48:52 +0100653};
654
655/**
Laurent Pinchart11f6c4b2020-02-26 13:24:27 +0200656 * enum drm_bridge_ops - Bitmask of operations supported by the bridge
657 */
658enum drm_bridge_ops {
659 /**
660 * @DRM_BRIDGE_OP_DETECT: The bridge can detect displays connected to
661 * its output. Bridges that set this flag shall implement the
662 * &drm_bridge_funcs->detect callback.
663 */
664 DRM_BRIDGE_OP_DETECT = BIT(0),
665 /**
666 * @DRM_BRIDGE_OP_EDID: The bridge can retrieve the EDID of the display
667 * connected to its output. Bridges that set this flag shall implement
668 * the &drm_bridge_funcs->get_edid callback.
669 */
670 DRM_BRIDGE_OP_EDID = BIT(1),
671 /**
672 * @DRM_BRIDGE_OP_HPD: The bridge can detect hot-plug and hot-unplug
673 * without requiring polling. Bridges that set this flag shall
674 * implement the &drm_bridge_funcs->hpd_enable and
675 * &drm_bridge_funcs->hpd_disable callbacks if they support enabling
676 * and disabling hot-plug detection dynamically.
677 */
678 DRM_BRIDGE_OP_HPD = BIT(2),
679 /**
680 * @DRM_BRIDGE_OP_MODES: The bridge can retrieve the modes supported
681 * by the display at its output. This does not include reading EDID
682 * which is separately covered by @DRM_BRIDGE_OP_EDID. Bridges that set
683 * this flag shall implement the &drm_bridge_funcs->get_modes callback.
684 */
685 DRM_BRIDGE_OP_MODES = BIT(3),
686};
687
688/**
Daniel Vetter199e4e92016-08-31 18:09:05 +0200689 * struct drm_bridge - central DRM bridge control structure
Daniel Vetter199e4e92016-08-31 18:09:05 +0200690 */
691struct drm_bridge {
Boris Brezillon75146592020-01-28 14:55:03 +0100692 /** @base: inherit from &drm_private_object */
693 struct drm_private_obj base;
Eric Anholt6aa13402018-06-06 12:04:29 -0700694 /** @dev: DRM device this bridge belongs to */
Daniel Vetter199e4e92016-08-31 18:09:05 +0200695 struct drm_device *dev;
Eric Anholt6aa13402018-06-06 12:04:29 -0700696 /** @encoder: encoder to which this bridge is connected */
Daniel Vetter199e4e92016-08-31 18:09:05 +0200697 struct drm_encoder *encoder;
Boris Brezillon05193dc2019-12-03 15:15:08 +0100698 /** @chain_node: used to form a bridge chain */
699 struct list_head chain_node;
Daniel Vetter199e4e92016-08-31 18:09:05 +0200700#ifdef CONFIG_OF
Eric Anholt6aa13402018-06-06 12:04:29 -0700701 /** @of_node: device node pointer to the bridge */
Daniel Vetter199e4e92016-08-31 18:09:05 +0200702 struct device_node *of_node;
703#endif
Eric Anholt6aa13402018-06-06 12:04:29 -0700704 /** @list: to keep track of all added bridges */
Daniel Vetter199e4e92016-08-31 18:09:05 +0200705 struct list_head list;
Eric Anholt6aa13402018-06-06 12:04:29 -0700706 /**
707 * @timings:
708 *
709 * the timing specification for the bridge, if any (may be NULL)
710 */
Linus Walleij36a776d2018-01-12 08:48:52 +0100711 const struct drm_bridge_timings *timings;
Eric Anholt6aa13402018-06-06 12:04:29 -0700712 /** @funcs: control functions */
Daniel Vetter199e4e92016-08-31 18:09:05 +0200713 const struct drm_bridge_funcs *funcs;
Eric Anholt6aa13402018-06-06 12:04:29 -0700714 /** @driver_private: pointer to the bridge driver's internal context */
Daniel Vetter199e4e92016-08-31 18:09:05 +0200715 void *driver_private;
Laurent Pinchart11f6c4b2020-02-26 13:24:27 +0200716 /** @ops: bitmask of operations supported by the bridge */
717 enum drm_bridge_ops ops;
718 /**
719 * @type: Type of the connection at the bridge output
720 * (DRM_MODE_CONNECTOR_*). For bridges at the end of this chain this
721 * identifies the type of connected display.
722 */
723 int type;
724 /**
Laurent Pinchart64d05ff2020-02-26 13:24:28 +0200725 * @interlace_allowed: Indicate that the bridge can handle interlaced
726 * modes.
727 */
728 bool interlace_allowed;
729 /**
Laurent Pinchart11f6c4b2020-02-26 13:24:27 +0200730 * @ddc: Associated I2C adapter for DDC access, if any.
731 */
732 struct i2c_adapter *ddc;
733 /** private: */
734 /**
735 * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields.
736 */
737 struct mutex hpd_mutex;
738 /**
739 * @hpd_cb: Hot plug detection callback, registered with
740 * drm_bridge_hpd_enable().
741 */
742 void (*hpd_cb)(void *data, enum drm_connector_status status);
743 /**
744 * @hpd_data: Private data passed to the Hot plug detection callback
745 * @hpd_cb.
746 */
747 void *hpd_data;
Daniel Vetter199e4e92016-08-31 18:09:05 +0200748};
749
Boris Brezillon75146592020-01-28 14:55:03 +0100750static inline struct drm_bridge *
751drm_priv_to_bridge(struct drm_private_obj *priv)
752{
753 return container_of(priv, struct drm_bridge, base);
754}
755
Inki Dae992868842017-07-03 17:42:17 +0900756void drm_bridge_add(struct drm_bridge *bridge);
Daniel Vetter199e4e92016-08-31 18:09:05 +0200757void drm_bridge_remove(struct drm_bridge *bridge);
758struct drm_bridge *of_drm_find_bridge(struct device_node *np);
Laurent Pinchart3bb80f22016-11-28 17:59:08 +0200759int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
760 struct drm_bridge *previous);
Daniel Vetter199e4e92016-08-31 18:09:05 +0200761
Boris Brezillonfadf8722019-12-03 15:15:06 +0100762/**
763 * drm_bridge_get_next_bridge() - Get the next bridge in the chain
764 * @bridge: bridge object
765 *
766 * RETURNS:
767 * the next bridge in the chain after @bridge, or NULL if @bridge is the last.
768 */
769static inline struct drm_bridge *
770drm_bridge_get_next_bridge(struct drm_bridge *bridge)
771{
Boris Brezillon05193dc2019-12-03 15:15:08 +0100772 if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain))
773 return NULL;
774
775 return list_next_entry(bridge, chain_node);
Boris Brezillonfadf8722019-12-03 15:15:06 +0100776}
777
Boris Brezillon35a61fe2019-12-03 15:15:07 +0100778/**
Boris Brezillonac877c62019-12-03 15:15:10 +0100779 * drm_bridge_get_prev_bridge() - Get the previous bridge in the chain
780 * @bridge: bridge object
781 *
782 * RETURNS:
783 * the previous bridge in the chain, or NULL if @bridge is the first.
784 */
785static inline struct drm_bridge *
786drm_bridge_get_prev_bridge(struct drm_bridge *bridge)
787{
788 if (list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain))
789 return NULL;
790
791 return list_prev_entry(bridge, chain_node);
792}
793
794/**
Boris Brezillon35a61fe2019-12-03 15:15:07 +0100795 * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain
796 * @encoder: encoder object
797 *
798 * RETURNS:
799 * the first bridge in the chain, or NULL if @encoder has no bridge attached
800 * to it.
801 */
802static inline struct drm_bridge *
803drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder)
804{
Boris Brezillon05193dc2019-12-03 15:15:08 +0100805 return list_first_entry_or_null(&encoder->bridge_chain,
806 struct drm_bridge, chain_node);
Boris Brezillon35a61fe2019-12-03 15:15:07 +0100807}
808
Boris Brezillon4ec5c902019-12-03 15:15:09 +0100809/**
810 * drm_for_each_bridge_in_chain() - Iterate over all bridges present in a chain
811 * @encoder: the encoder to iterate bridges on
812 * @bridge: a bridge pointer updated to point to the current bridge at each
813 * iteration
814 *
815 * Iterate over all bridges present in the bridge chain attached to @encoder.
816 */
817#define drm_for_each_bridge_in_chain(encoder, bridge) \
818 list_for_each_entry(bridge, &(encoder)->bridge_chain, chain_node)
819
Boris Brezillonea099ad2019-12-03 15:15:05 +0100820bool drm_bridge_chain_mode_fixup(struct drm_bridge *bridge,
821 const struct drm_display_mode *mode,
822 struct drm_display_mode *adjusted_mode);
823enum drm_mode_status
824drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
825 const struct drm_display_mode *mode);
826void drm_bridge_chain_disable(struct drm_bridge *bridge);
827void drm_bridge_chain_post_disable(struct drm_bridge *bridge);
828void drm_bridge_chain_mode_set(struct drm_bridge *bridge,
829 const struct drm_display_mode *mode,
830 const struct drm_display_mode *adjusted_mode);
831void drm_bridge_chain_pre_enable(struct drm_bridge *bridge);
832void drm_bridge_chain_enable(struct drm_bridge *bridge);
Daniel Vetter199e4e92016-08-31 18:09:05 +0200833
Boris Brezillon5061b8a2020-01-28 14:55:07 +0100834int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,
835 struct drm_crtc_state *crtc_state,
836 struct drm_connector_state *conn_state);
Boris Brezillonea099ad2019-12-03 15:15:05 +0100837void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,
838 struct drm_atomic_state *state);
839void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,
840 struct drm_atomic_state *state);
841void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,
842 struct drm_atomic_state *state);
843void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,
Sean Paul5ade0712019-06-11 12:08:17 -0400844 struct drm_atomic_state *state);
Sean Paul5ade0712019-06-11 12:08:17 -0400845
Boris Brezillonf32df582020-01-28 14:55:08 +0100846u32 *
847drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
848 struct drm_bridge_state *bridge_state,
849 struct drm_crtc_state *crtc_state,
850 struct drm_connector_state *conn_state,
851 u32 output_fmt,
852 unsigned int *num_input_fmts);
853
Laurent Pinchart11f6c4b2020-02-26 13:24:27 +0200854enum drm_connector_status drm_bridge_detect(struct drm_bridge *bridge);
855int drm_bridge_get_modes(struct drm_bridge *bridge,
856 struct drm_connector *connector);
857struct edid *drm_bridge_get_edid(struct drm_bridge *bridge,
858 struct drm_connector *connector);
859void drm_bridge_hpd_enable(struct drm_bridge *bridge,
860 void (*cb)(void *data,
861 enum drm_connector_status status),
862 void *data);
863void drm_bridge_hpd_disable(struct drm_bridge *bridge);
864void drm_bridge_hpd_notify(struct drm_bridge *bridge,
865 enum drm_connector_status status);
866
Eric Anholt13dfc052017-06-02 13:25:14 -0700867#ifdef CONFIG_DRM_PANEL_BRIDGE
Laurent Pinchart89958b72019-09-04 16:28:04 +0300868struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel);
869struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
870 u32 connector_type);
Eric Anholt13dfc052017-06-02 13:25:14 -0700871void drm_panel_bridge_remove(struct drm_bridge *bridge);
Eric Anholt67022222017-07-18 14:05:06 -0700872struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
Laurent Pinchart89958b72019-09-04 16:28:04 +0300873 struct drm_panel *panel);
874struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
875 struct drm_panel *panel,
876 u32 connector_type);
Sam Ravnborgd383fb52019-12-07 15:03:32 +0100877struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge);
Eric Anholt13dfc052017-06-02 13:25:14 -0700878#endif
879
Daniel Vetter199e4e92016-08-31 18:09:05 +0200880#endif