]>
Commit | Line | Data |
---|---|---|
199e4e96 SV |
1 | /* |
2 | * Copyright (c) 2016 Intel Corporation | |
3 | * | |
4 | * Permission to use, copy, modify, distribute, and sell this software and its | |
5 | * documentation for any purpose is hereby granted without fee, provided that | |
6 | * the above copyright notice appear in all copies and that both that copyright | |
7 | * notice and this permission notice appear in supporting documentation, and | |
8 | * that the name of the copyright holders not be used in advertising or | |
9 | * publicity pertaining to distribution of the software without specific, | |
10 | * written prior permission. The copyright holders make no representations | |
11 | * about the suitability of this software for any purpose. It is provided "as | |
12 | * is" without express or implied warranty. | |
13 | * | |
14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | |
15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | |
16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR | |
17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | |
18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | |
19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | |
20 | * OF THIS SOFTWARE. | |
21 | */ | |
22 | ||
23 | #ifndef __DRM_BRIDGE_H__ | |
24 | #define __DRM_BRIDGE_H__ | |
25 | ||
26 | #include <linux/list.h> | |
27 | #include <linux/ctype.h> | |
35a61fe9 | 28 | #include <drm/drm_encoder.h> |
199e4e96 SV |
29 | #include <drm/drm_mode_object.h> |
30 | #include <drm/drm_modes.h> | |
31 | ||
32 | struct drm_bridge; | |
36a776df | 33 | struct drm_bridge_timings; |
13dfc054 | 34 | struct drm_panel; |
199e4e96 SV |
35 | |
36 | /** | |
37 | * struct drm_bridge_funcs - drm_bridge control functions | |
38 | */ | |
39 | struct drm_bridge_funcs { | |
40 | /** | |
41 | * @attach: | |
42 | * | |
43 | * This callback is invoked whenever our bridge is being attached to a | |
44 | * &drm_encoder. | |
45 | * | |
fe9e557d | 46 | * The @attach callback is optional. |
199e4e96 SV |
47 | * |
48 | * RETURNS: | |
49 | * | |
50 | * Zero on success, error code on failure. | |
51 | */ | |
52 | int (*attach)(struct drm_bridge *bridge); | |
53 | ||
54 | /** | |
55 | * @detach: | |
56 | * | |
57 | * This callback is invoked whenever our bridge is being detached from a | |
58 | * &drm_encoder. | |
59 | * | |
fe9e557d | 60 | * The @detach callback is optional. |
199e4e96 SV |
61 | */ |
62 | void (*detach)(struct drm_bridge *bridge); | |
63 | ||
3eb220a5 JA |
64 | /** |
65 | * @mode_valid: | |
66 | * | |
67 | * This callback is used to check if a specific mode is valid in this | |
68 | * bridge. This should be implemented if the bridge has some sort of | |
69 | * restriction in the modes it can display. For example, a given bridge | |
70 | * may be responsible to set a clock value. If the clock can not | |
71 | * produce all the values for the available modes then this callback | |
72 | * can be used to restrict the number of modes to only the ones that | |
73 | * can be displayed. | |
74 | * | |
75 | * This hook is used by the probe helpers to filter the mode list in | |
76 | * drm_helper_probe_single_connector_modes(), and it is used by the | |
77 | * atomic helpers to validate modes supplied by userspace in | |
78 | * drm_atomic_helper_check_modeset(). | |
79 | * | |
fe9e557d | 80 | * The @mode_valid callback is optional. |
3eb220a5 JA |
81 | * |
82 | * NOTE: | |
83 | * | |
84 | * Since this function is both called from the check phase of an atomic | |
85 | * commit, and the mode validation in the probe paths it is not allowed | |
86 | * to look at anything else but the passed-in mode, and validate it | |
87 | * against configuration-invariant hardward constraints. Any further | |
88 | * limits which depend upon the configuration can only be checked in | |
89 | * @mode_fixup. | |
90 | * | |
91 | * RETURNS: | |
92 | * | |
93 | * drm_mode_status Enum | |
94 | */ | |
312924d3 | 95 | enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge, |
3eb220a5 JA |
96 | const struct drm_display_mode *mode); |
97 | ||
199e4e96 SV |
98 | /** |
99 | * @mode_fixup: | |
100 | * | |
5d435b46 | 101 | * This callback is used to validate and adjust a mode. The parameter |
199e4e96 SV |
102 | * mode is the display mode that should be fed to the next element in |
103 | * the display chain, either the final &drm_connector or the next | |
104 | * &drm_bridge. The parameter adjusted_mode is the input mode the bridge | |
105 | * requires. It can be modified by this callback and does not need to | |
9de5d4a6 | 106 | * match mode. See also &drm_crtc_state.adjusted_mode for more details. |
199e4e96 SV |
107 | * |
108 | * This is the only hook that allows a bridge to reject a modeset. If | |
109 | * this function passes all other callbacks must succeed for this | |
110 | * configuration. | |
111 | * | |
fe9e557d | 112 | * The @mode_fixup callback is optional. |
199e4e96 SV |
113 | * |
114 | * NOTE: | |
115 | * | |
116 | * This function is called in the check phase of atomic modesets, which | |
117 | * can be aborted for any reason (including on userspace's request to | |
118 | * just check whether a configuration would be possible). Drivers MUST | |
119 | * NOT touch any persistent state (hardware or software) or data | |
120 | * structures except the passed in @state parameter. | |
121 | * | |
3eb220a5 JA |
122 | * Also beware that userspace can request its own custom modes, neither |
123 | * core nor helpers filter modes to the list of probe modes reported by | |
124 | * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure | |
125 | * that modes are filtered consistently put any bridge constraints and | |
126 | * limits checks into @mode_valid. | |
127 | * | |
199e4e96 SV |
128 | * RETURNS: |
129 | * | |
130 | * True if an acceptable configuration is possible, false if the modeset | |
131 | * operation should be rejected. | |
132 | */ | |
133 | bool (*mode_fixup)(struct drm_bridge *bridge, | |
134 | const struct drm_display_mode *mode, | |
135 | struct drm_display_mode *adjusted_mode); | |
136 | /** | |
137 | * @disable: | |
138 | * | |
139 | * This callback should disable the bridge. It is called right before | |
140 | * the preceding element in the display pipe is disabled. If the | |
141 | * preceding element is a bridge this means it's called before that | |
4541d31e SV |
142 | * bridge's @disable vfunc. If the preceding element is a &drm_encoder |
143 | * it's called right before the &drm_encoder_helper_funcs.disable, | |
144 | * &drm_encoder_helper_funcs.prepare or &drm_encoder_helper_funcs.dpms | |
145 | * hook. | |
199e4e96 SV |
146 | * |
147 | * The bridge can assume that the display pipe (i.e. clocks and timing | |
148 | * signals) feeding it is still running when this callback is called. | |
149 | * | |
fe9e557d | 150 | * The @disable callback is optional. |
199e4e96 SV |
151 | */ |
152 | void (*disable)(struct drm_bridge *bridge); | |
153 | ||
154 | /** | |
155 | * @post_disable: | |
156 | * | |
4541d31e SV |
157 | * This callback should disable the bridge. It is called right after the |
158 | * preceding element in the display pipe is disabled. If the preceding | |
159 | * element is a bridge this means it's called after that bridge's | |
160 | * @post_disable function. If the preceding element is a &drm_encoder | |
161 | * it's called right after the encoder's | |
162 | * &drm_encoder_helper_funcs.disable, &drm_encoder_helper_funcs.prepare | |
163 | * or &drm_encoder_helper_funcs.dpms hook. | |
199e4e96 SV |
164 | * |
165 | * The bridge must assume that the display pipe (i.e. clocks and timing | |
166 | * singals) feeding it is no longer running when this callback is | |
167 | * called. | |
168 | * | |
fe9e557d | 169 | * The @post_disable callback is optional. |
199e4e96 SV |
170 | */ |
171 | void (*post_disable)(struct drm_bridge *bridge); | |
172 | ||
173 | /** | |
174 | * @mode_set: | |
175 | * | |
176 | * This callback should set the given mode on the bridge. It is called | |
4541d31e SV |
177 | * after the @mode_set callback for the preceding element in the display |
178 | * pipeline has been called already. If the bridge is the first element | |
179 | * then this would be &drm_encoder_helper_funcs.mode_set. The display | |
180 | * pipe (i.e. clocks and timing signals) is off when this function is | |
181 | * called. | |
584a0146 PC |
182 | * |
183 | * The adjusted_mode parameter is the mode output by the CRTC for the | |
184 | * first bridge in the chain. It can be different from the mode | |
185 | * parameter that contains the desired mode for the connector at the end | |
186 | * of the bridges chain, for instance when the first bridge in the chain | |
187 | * performs scaling. The adjusted mode is mostly useful for the first | |
188 | * bridge in the chain and is likely irrelevant for the other bridges. | |
189 | * | |
190 | * For atomic drivers the adjusted_mode is the mode stored in | |
191 | * &drm_crtc_state.adjusted_mode. | |
192 | * | |
193 | * NOTE: | |
194 | * | |
195 | * If a need arises to store and access modes adjusted for other | |
196 | * locations than the connection between the CRTC and the first bridge, | |
197 | * the DRM framework will have to be extended with DRM bridge states. | |
199e4e96 SV |
198 | */ |
199 | void (*mode_set)(struct drm_bridge *bridge, | |
63f8f3ba LP |
200 | const struct drm_display_mode *mode, |
201 | const struct drm_display_mode *adjusted_mode); | |
199e4e96 SV |
202 | /** |
203 | * @pre_enable: | |
204 | * | |
205 | * This callback should enable the bridge. It is called right before | |
206 | * the preceding element in the display pipe is enabled. If the | |
207 | * preceding element is a bridge this means it's called before that | |
4541d31e SV |
208 | * bridge's @pre_enable function. If the preceding element is a |
209 | * &drm_encoder it's called right before the encoder's | |
210 | * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or | |
211 | * &drm_encoder_helper_funcs.dpms hook. | |
199e4e96 SV |
212 | * |
213 | * The display pipe (i.e. clocks and timing signals) feeding this bridge | |
214 | * will not yet be running when this callback is called. The bridge must | |
215 | * not enable the display link feeding the next bridge in the chain (if | |
216 | * there is one) when this callback is called. | |
217 | * | |
fe9e557d | 218 | * The @pre_enable callback is optional. |
199e4e96 SV |
219 | */ |
220 | void (*pre_enable)(struct drm_bridge *bridge); | |
221 | ||
222 | /** | |
223 | * @enable: | |
224 | * | |
225 | * This callback should enable the bridge. It is called right after | |
226 | * the preceding element in the display pipe is enabled. If the | |
227 | * preceding element is a bridge this means it's called after that | |
4541d31e SV |
228 | * bridge's @enable function. If the preceding element is a |
229 | * &drm_encoder it's called right after the encoder's | |
230 | * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or | |
231 | * &drm_encoder_helper_funcs.dpms hook. | |
199e4e96 SV |
232 | * |
233 | * The bridge can assume that the display pipe (i.e. clocks and timing | |
234 | * signals) feeding it is running when this callback is called. This | |
235 | * callback must enable the display link feeding the next bridge in the | |
236 | * chain if there is one. | |
237 | * | |
fe9e557d | 238 | * The @enable callback is optional. |
199e4e96 SV |
239 | */ |
240 | void (*enable)(struct drm_bridge *bridge); | |
5ade071b SP |
241 | |
242 | /** | |
243 | * @atomic_pre_enable: | |
244 | * | |
245 | * This callback should enable the bridge. It is called right before | |
246 | * the preceding element in the display pipe is enabled. If the | |
247 | * preceding element is a bridge this means it's called before that | |
248 | * bridge's @atomic_pre_enable or @pre_enable function. If the preceding | |
249 | * element is a &drm_encoder it's called right before the encoder's | |
250 | * &drm_encoder_helper_funcs.atomic_enable hook. | |
251 | * | |
252 | * The display pipe (i.e. clocks and timing signals) feeding this bridge | |
253 | * will not yet be running when this callback is called. The bridge must | |
254 | * not enable the display link feeding the next bridge in the chain (if | |
255 | * there is one) when this callback is called. | |
256 | * | |
257 | * Note that this function will only be invoked in the context of an | |
ea099adf BB |
258 | * atomic commit. It will not be invoked from |
259 | * &drm_bridge_chain_pre_enable. It would be prudent to also provide an | |
260 | * implementation of @pre_enable if you are expecting driver calls into | |
261 | * &drm_bridge_chain_pre_enable. | |
5ade071b SP |
262 | * |
263 | * The @atomic_pre_enable callback is optional. | |
264 | */ | |
265 | void (*atomic_pre_enable)(struct drm_bridge *bridge, | |
266 | struct drm_atomic_state *state); | |
267 | ||
268 | /** | |
269 | * @atomic_enable: | |
270 | * | |
271 | * This callback should enable the bridge. It is called right after | |
272 | * the preceding element in the display pipe is enabled. If the | |
273 | * preceding element is a bridge this means it's called after that | |
274 | * bridge's @atomic_enable or @enable function. If the preceding element | |
275 | * is a &drm_encoder it's called right after the encoder's | |
276 | * &drm_encoder_helper_funcs.atomic_enable hook. | |
277 | * | |
278 | * The bridge can assume that the display pipe (i.e. clocks and timing | |
279 | * signals) feeding it is running when this callback is called. This | |
280 | * callback must enable the display link feeding the next bridge in the | |
281 | * chain if there is one. | |
282 | * | |
283 | * Note that this function will only be invoked in the context of an | |
ea099adf BB |
284 | * atomic commit. It will not be invoked from &drm_bridge_chain_enable. |
285 | * It would be prudent to also provide an implementation of @enable if | |
286 | * you are expecting driver calls into &drm_bridge_chain_enable. | |
5ade071b | 287 | * |
fe9e557d | 288 | * The @atomic_enable callback is optional. |
5ade071b SP |
289 | */ |
290 | void (*atomic_enable)(struct drm_bridge *bridge, | |
291 | struct drm_atomic_state *state); | |
292 | /** | |
293 | * @atomic_disable: | |
294 | * | |
295 | * This callback should disable the bridge. It is called right before | |
296 | * the preceding element in the display pipe is disabled. If the | |
297 | * preceding element is a bridge this means it's called before that | |
298 | * bridge's @atomic_disable or @disable vfunc. If the preceding element | |
299 | * is a &drm_encoder it's called right before the | |
300 | * &drm_encoder_helper_funcs.atomic_disable hook. | |
301 | * | |
302 | * The bridge can assume that the display pipe (i.e. clocks and timing | |
303 | * signals) feeding it is still running when this callback is called. | |
304 | * | |
305 | * Note that this function will only be invoked in the context of an | |
ea099adf BB |
306 | * atomic commit. It will not be invoked from |
307 | * &drm_bridge_chain_disable. It would be prudent to also provide an | |
308 | * implementation of @disable if you are expecting driver calls into | |
309 | * &drm_bridge_chain_disable. | |
5ade071b | 310 | * |
fe9e557d | 311 | * The @atomic_disable callback is optional. |
5ade071b SP |
312 | */ |
313 | void (*atomic_disable)(struct drm_bridge *bridge, | |
314 | struct drm_atomic_state *state); | |
315 | ||
316 | /** | |
317 | * @atomic_post_disable: | |
318 | * | |
319 | * This callback should disable the bridge. It is called right after the | |
320 | * preceding element in the display pipe is disabled. If the preceding | |
321 | * element is a bridge this means it's called after that bridge's | |
322 | * @atomic_post_disable or @post_disable function. If the preceding | |
323 | * element is a &drm_encoder it's called right after the encoder's | |
324 | * &drm_encoder_helper_funcs.atomic_disable hook. | |
325 | * | |
326 | * The bridge must assume that the display pipe (i.e. clocks and timing | |
327 | * signals) feeding it is no longer running when this callback is | |
328 | * called. | |
329 | * | |
330 | * Note that this function will only be invoked in the context of an | |
ea099adf BB |
331 | * atomic commit. It will not be invoked from |
332 | * &drm_bridge_chain_post_disable. | |
5ade071b SP |
333 | * It would be prudent to also provide an implementation of |
334 | * @post_disable if you are expecting driver calls into | |
ea099adf | 335 | * &drm_bridge_chain_post_disable. |
5ade071b | 336 | * |
fe9e557d | 337 | * The @atomic_post_disable callback is optional. |
5ade071b SP |
338 | */ |
339 | void (*atomic_post_disable)(struct drm_bridge *bridge, | |
340 | struct drm_atomic_state *state); | |
199e4e96 SV |
341 | }; |
342 | ||
36a776df LW |
343 | /** |
344 | * struct drm_bridge_timings - timing information for the bridge | |
345 | */ | |
346 | struct drm_bridge_timings { | |
347 | /** | |
d23286ff | 348 | * @input_bus_flags: |
36a776df | 349 | * |
d23286ff SA |
350 | * Tells what additional settings for the pixel data on the bus |
351 | * this bridge requires (like pixel signal polarity). See also | |
352 | * &drm_display_info->bus_flags. | |
36a776df | 353 | */ |
d23286ff | 354 | u32 input_bus_flags; |
36a776df LW |
355 | /** |
356 | * @setup_time_ps: | |
357 | * | |
358 | * Defines the time in picoseconds the input data lines must be | |
359 | * stable before the clock edge. | |
360 | */ | |
361 | u32 setup_time_ps; | |
362 | /** | |
363 | * @hold_time_ps: | |
364 | * | |
365 | * Defines the time in picoseconds taken for the bridge to sample the | |
366 | * input signal after the clock edge. | |
367 | */ | |
368 | u32 hold_time_ps; | |
b0a6b940 LP |
369 | /** |
370 | * @dual_link: | |
371 | * | |
372 | * True if the bus operates in dual-link mode. The exact meaning is | |
373 | * dependent on the bus type. For LVDS buses, this indicates that even- | |
374 | * and odd-numbered pixels are received on separate links. | |
375 | */ | |
376 | bool dual_link; | |
36a776df LW |
377 | }; |
378 | ||
199e4e96 SV |
379 | /** |
380 | * struct drm_bridge - central DRM bridge control structure | |
199e4e96 SV |
381 | */ |
382 | struct drm_bridge { | |
6aa13402 | 383 | /** @dev: DRM device this bridge belongs to */ |
199e4e96 | 384 | struct drm_device *dev; |
6aa13402 | 385 | /** @encoder: encoder to which this bridge is connected */ |
199e4e96 | 386 | struct drm_encoder *encoder; |
05193dc3 BB |
387 | /** @chain_node: used to form a bridge chain */ |
388 | struct list_head chain_node; | |
199e4e96 | 389 | #ifdef CONFIG_OF |
6aa13402 | 390 | /** @of_node: device node pointer to the bridge */ |
199e4e96 SV |
391 | struct device_node *of_node; |
392 | #endif | |
6aa13402 | 393 | /** @list: to keep track of all added bridges */ |
199e4e96 | 394 | struct list_head list; |
6aa13402 EA |
395 | /** |
396 | * @timings: | |
397 | * | |
398 | * the timing specification for the bridge, if any (may be NULL) | |
399 | */ | |
36a776df | 400 | const struct drm_bridge_timings *timings; |
6aa13402 | 401 | /** @funcs: control functions */ |
199e4e96 | 402 | const struct drm_bridge_funcs *funcs; |
6aa13402 | 403 | /** @driver_private: pointer to the bridge driver's internal context */ |
199e4e96 SV |
404 | void *driver_private; |
405 | }; | |
406 | ||
99286884 | 407 | void drm_bridge_add(struct drm_bridge *bridge); |
199e4e96 SV |
408 | void drm_bridge_remove(struct drm_bridge *bridge); |
409 | struct drm_bridge *of_drm_find_bridge(struct device_node *np); | |
3bb80f24 LP |
410 | int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge, |
411 | struct drm_bridge *previous); | |
199e4e96 | 412 | |
fadf872d BB |
413 | /** |
414 | * drm_bridge_get_next_bridge() - Get the next bridge in the chain | |
415 | * @bridge: bridge object | |
416 | * | |
417 | * RETURNS: | |
418 | * the next bridge in the chain after @bridge, or NULL if @bridge is the last. | |
419 | */ | |
420 | static inline struct drm_bridge * | |
421 | drm_bridge_get_next_bridge(struct drm_bridge *bridge) | |
422 | { | |
05193dc3 BB |
423 | if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain)) |
424 | return NULL; | |
425 | ||
426 | return list_next_entry(bridge, chain_node); | |
fadf872d BB |
427 | } |
428 | ||
35a61fe9 BB |
429 | /** |
430 | * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain | |
431 | * @encoder: encoder object | |
432 | * | |
433 | * RETURNS: | |
434 | * the first bridge in the chain, or NULL if @encoder has no bridge attached | |
435 | * to it. | |
436 | */ | |
437 | static inline struct drm_bridge * | |
438 | drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder) | |
439 | { | |
05193dc3 BB |
440 | return list_first_entry_or_null(&encoder->bridge_chain, |
441 | struct drm_bridge, chain_node); | |
35a61fe9 BB |
442 | } |
443 | ||
ea099adf BB |
444 | bool drm_bridge_chain_mode_fixup(struct drm_bridge *bridge, |
445 | const struct drm_display_mode *mode, | |
446 | struct drm_display_mode *adjusted_mode); | |
447 | enum drm_mode_status | |
448 | drm_bridge_chain_mode_valid(struct drm_bridge *bridge, | |
449 | const struct drm_display_mode *mode); | |
450 | void drm_bridge_chain_disable(struct drm_bridge *bridge); | |
451 | void drm_bridge_chain_post_disable(struct drm_bridge *bridge); | |
452 | void drm_bridge_chain_mode_set(struct drm_bridge *bridge, | |
453 | const struct drm_display_mode *mode, | |
454 | const struct drm_display_mode *adjusted_mode); | |
455 | void drm_bridge_chain_pre_enable(struct drm_bridge *bridge); | |
456 | void drm_bridge_chain_enable(struct drm_bridge *bridge); | |
199e4e96 | 457 | |
ea099adf BB |
458 | void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge, |
459 | struct drm_atomic_state *state); | |
460 | void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge, | |
461 | struct drm_atomic_state *state); | |
462 | void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge, | |
463 | struct drm_atomic_state *state); | |
464 | void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge, | |
5ade071b | 465 | struct drm_atomic_state *state); |
5ade071b | 466 | |
13dfc054 | 467 | #ifdef CONFIG_DRM_PANEL_BRIDGE |
89958b7c LP |
468 | struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel); |
469 | struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel, | |
470 | u32 connector_type); | |
13dfc054 | 471 | void drm_panel_bridge_remove(struct drm_bridge *bridge); |
67022227 | 472 | struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev, |
89958b7c LP |
473 | struct drm_panel *panel); |
474 | struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev, | |
475 | struct drm_panel *panel, | |
476 | u32 connector_type); | |
13dfc054 EA |
477 | #endif |
478 | ||
199e4e96 | 479 | #endif |