Linux Audio

Check our new training course

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