• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CONNECTOR_H__
24 #define __DRM_CONNECTOR_H__
25 
26 #include <linux/list.h>
27 #include <linux/llist.h>
28 #include <linux/ctype.h>
29 #include <linux/hdmi.h>
30 #include <drm/drm_mode_object.h>
31 #include <drm/drm_util.h>
32 
33 #include <uapi/drm/drm_mode.h>
34 
35 struct drm_connector_helper_funcs;
36 struct drm_modeset_acquire_ctx;
37 struct drm_device;
38 struct drm_crtc;
39 struct drm_encoder;
40 struct drm_property;
41 struct drm_property_blob;
42 struct drm_printer;
43 struct drm_panel;
44 struct edid;
45 struct i2c_adapter;
46 
47 enum drm_connector_force {
48 	DRM_FORCE_UNSPECIFIED,
49 	DRM_FORCE_OFF,
50 	DRM_FORCE_ON,         /* force on analog part normally */
51 	DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
52 };
53 
54 /**
55  * enum drm_connector_status - status for a &drm_connector
56  *
57  * This enum is used to track the connector status. There are no separate
58  * #defines for the uapi!
59  */
60 enum drm_connector_status {
61 	/**
62 	 * @connector_status_connected: The connector is definitely connected to
63 	 * a sink device, and can be enabled.
64 	 */
65 	connector_status_connected = 1,
66 	/**
67 	 * @connector_status_disconnected: The connector isn't connected to a
68 	 * sink device which can be autodetect. For digital outputs like DP or
69 	 * HDMI (which can be realiable probed) this means there's really
70 	 * nothing there. It is driver-dependent whether a connector with this
71 	 * status can be lit up or not.
72 	 */
73 	connector_status_disconnected = 2,
74 	/**
75 	 * @connector_status_unknown: The connector's status could not be
76 	 * reliably detected. This happens when probing would either cause
77 	 * flicker (like load-detection when the connector is in use), or when a
78 	 * hardware resource isn't available (like when load-detection needs a
79 	 * free CRTC). It should be possible to light up the connector with one
80 	 * of the listed fallback modes. For default configuration userspace
81 	 * should only try to light up connectors with unknown status when
82 	 * there's not connector with @connector_status_connected.
83 	 */
84 	connector_status_unknown = 3,
85 };
86 
87 /**
88  * enum drm_connector_registration_status - userspace registration status for
89  * a &drm_connector
90  *
91  * This enum is used to track the status of initializing a connector and
92  * registering it with userspace, so that DRM can prevent bogus modesets on
93  * connectors that no longer exist.
94  */
95 enum drm_connector_registration_state {
96 	/**
97 	 * @DRM_CONNECTOR_INITIALIZING: The connector has just been created,
98 	 * but has yet to be exposed to userspace. There should be no
99 	 * additional restrictions to how the state of this connector may be
100 	 * modified.
101 	 */
102 	DRM_CONNECTOR_INITIALIZING = 0,
103 
104 	/**
105 	 * @DRM_CONNECTOR_REGISTERED: The connector has been fully initialized
106 	 * and registered with sysfs, as such it has been exposed to
107 	 * userspace. There should be no additional restrictions to how the
108 	 * state of this connector may be modified.
109 	 */
110 	DRM_CONNECTOR_REGISTERED = 1,
111 
112 	/**
113 	 * @DRM_CONNECTOR_UNREGISTERED: The connector has either been exposed
114 	 * to userspace and has since been unregistered and removed from
115 	 * userspace, or the connector was unregistered before it had a chance
116 	 * to be exposed to userspace (e.g. still in the
117 	 * @DRM_CONNECTOR_INITIALIZING state). When a connector is
118 	 * unregistered, there are additional restrictions to how its state
119 	 * may be modified:
120 	 *
121 	 * - An unregistered connector may only have its DPMS changed from
122 	 *   On->Off. Once DPMS is changed to Off, it may not be switched back
123 	 *   to On.
124 	 * - Modesets are not allowed on unregistered connectors, unless they
125 	 *   would result in disabling its assigned CRTCs. This means
126 	 *   disabling a CRTC on an unregistered connector is OK, but enabling
127 	 *   one is not.
128 	 * - Removing a CRTC from an unregistered connector is OK, but new
129 	 *   CRTCs may never be assigned to an unregistered connector.
130 	 */
131 	DRM_CONNECTOR_UNREGISTERED = 2,
132 };
133 
134 enum subpixel_order {
135 	SubPixelUnknown = 0,
136 	SubPixelHorizontalRGB,
137 	SubPixelHorizontalBGR,
138 	SubPixelVerticalRGB,
139 	SubPixelVerticalBGR,
140 	SubPixelNone,
141 
142 };
143 
144 /**
145  * struct drm_scrambling: sink's scrambling support.
146  */
147 struct drm_scrambling {
148 	/**
149 	 * @supported: scrambling supported for rates > 340 Mhz.
150 	 */
151 	bool supported;
152 	/**
153 	 * @low_rates: scrambling supported for rates <= 340 Mhz.
154 	 */
155 	bool low_rates;
156 };
157 
158 /*
159  * struct drm_scdc - Information about scdc capabilities of a HDMI 2.0 sink
160  *
161  * Provides SCDC register support and capabilities related information on a
162  * HDMI 2.0 sink. In case of a HDMI 1.4 sink, all parameter must be 0.
163  */
164 struct drm_scdc {
165 	/**
166 	 * @supported: status control & data channel present.
167 	 */
168 	bool supported;
169 	/**
170 	 * @read_request: sink is capable of generating scdc read request.
171 	 */
172 	bool read_request;
173 	/**
174 	 * @scrambling: sink's scrambling capabilities
175 	 */
176 	struct drm_scrambling scrambling;
177 };
178 
179 
180 /**
181  * struct drm_hdmi_info - runtime information about the connected HDMI sink
182  *
183  * Describes if a given display supports advanced HDMI 2.0 features.
184  * This information is available in CEA-861-F extension blocks (like HF-VSDB).
185  */
186 struct drm_hdmi_info {
187 	/** @scdc: sink's scdc support and capabilities */
188 	struct drm_scdc scdc;
189 
190 	/**
191 	 * @y420_vdb_modes: bitmap of modes which can support ycbcr420
192 	 * output only (not normal RGB/YCBCR444/422 outputs). There are total
193 	 * 107 VICs defined by CEA-861-F spec, so the size is 128 bits to map
194 	 * upto 128 VICs;
195 	 */
196 	unsigned long y420_vdb_modes[BITS_TO_LONGS(128)];
197 
198 	/**
199 	 * @y420_cmdb_modes: bitmap of modes which can support ycbcr420
200 	 * output also, along with normal HDMI outputs. There are total 107
201 	 * VICs defined by CEA-861-F spec, so the size is 128 bits to map upto
202 	 * 128 VICs;
203 	 */
204 	unsigned long y420_cmdb_modes[BITS_TO_LONGS(128)];
205 
206 	/** @y420_cmdb_map: bitmap of SVD index, to extraxt vcb modes */
207 	u64 y420_cmdb_map;
208 
209 	/** @y420_dc_modes: bitmap of deep color support index */
210 	u8 y420_dc_modes;
211 };
212 
213 /**
214  * enum drm_link_status - connector's link_status property value
215  *
216  * This enum is used as the connector's link status property value.
217  * It is set to the values defined in uapi.
218  *
219  * @DRM_LINK_STATUS_GOOD: DP Link is Good as a result of successful
220  *                        link training
221  * @DRM_LINK_STATUS_BAD: DP Link is BAD as a result of link training
222  *                       failure
223  */
224 enum drm_link_status {
225 	DRM_LINK_STATUS_GOOD = DRM_MODE_LINK_STATUS_GOOD,
226 	DRM_LINK_STATUS_BAD = DRM_MODE_LINK_STATUS_BAD,
227 };
228 
229 /**
230  * enum drm_panel_orientation - panel_orientation info for &drm_display_info
231  *
232  * This enum is used to track the (LCD) panel orientation. There are no
233  * separate #defines for the uapi!
234  *
235  * @DRM_MODE_PANEL_ORIENTATION_UNKNOWN: The drm driver has not provided any
236  *					panel orientation information (normal
237  *					for non panels) in this case the "panel
238  *					orientation" connector prop will not be
239  *					attached.
240  * @DRM_MODE_PANEL_ORIENTATION_NORMAL:	The top side of the panel matches the
241  *					top side of the device's casing.
242  * @DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP: The top side of the panel matches the
243  *					bottom side of the device's casing, iow
244  *					the panel is mounted upside-down.
245  * @DRM_MODE_PANEL_ORIENTATION_LEFT_UP:	The left side of the panel matches the
246  *					top side of the device's casing.
247  * @DRM_MODE_PANEL_ORIENTATION_RIGHT_UP: The right side of the panel matches the
248  *					top side of the device's casing.
249  */
250 enum drm_panel_orientation {
251 	DRM_MODE_PANEL_ORIENTATION_UNKNOWN = -1,
252 	DRM_MODE_PANEL_ORIENTATION_NORMAL = 0,
253 	DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP,
254 	DRM_MODE_PANEL_ORIENTATION_LEFT_UP,
255 	DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
256 };
257 
258 /*
259  * This is a consolidated colorimetry list supported by HDMI and
260  * DP protocol standard. The respective connectors will register
261  * a property with the subset of this list (supported by that
262  * respective protocol). Userspace will set the colorspace through
263  * a colorspace property which will be created and exposed to
264  * userspace.
265  */
266 
267 /* For Default case, driver will set the colorspace */
268 #define DRM_MODE_COLORIMETRY_DEFAULT			0
269 /* CEA 861 Normal Colorimetry options */
270 #define DRM_MODE_COLORIMETRY_NO_DATA			0
271 #define DRM_MODE_COLORIMETRY_SMPTE_170M_YCC		1
272 #define DRM_MODE_COLORIMETRY_BT709_YCC			2
273 /* CEA 861 Extended Colorimetry Options */
274 #define DRM_MODE_COLORIMETRY_XVYCC_601			3
275 #define DRM_MODE_COLORIMETRY_XVYCC_709			4
276 #define DRM_MODE_COLORIMETRY_SYCC_601			5
277 #define DRM_MODE_COLORIMETRY_OPYCC_601			6
278 #define DRM_MODE_COLORIMETRY_OPRGB			7
279 #define DRM_MODE_COLORIMETRY_BT2020_CYCC		8
280 #define DRM_MODE_COLORIMETRY_BT2020_RGB			9
281 #define DRM_MODE_COLORIMETRY_BT2020_YCC			10
282 /* Additional Colorimetry extension added as part of CTA 861.G */
283 #define DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65		11
284 #define DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER		12
285 /* Additional Colorimetry Options added for DP 1.4a VSC Colorimetry Format */
286 #define DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED		13
287 #define DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT		14
288 #define DRM_MODE_COLORIMETRY_BT601_YCC			15
289 
290 /**
291  * enum drm_bus_flags - bus_flags info for &drm_display_info
292  *
293  * This enum defines signal polarities and clock edge information for signals on
294  * a bus as bitmask flags.
295  *
296  * The clock edge information is conveyed by two sets of symbols,
297  * DRM_BUS_FLAGS_*_DRIVE_\* and DRM_BUS_FLAGS_*_SAMPLE_\*. When this enum is
298  * used to describe a bus from the point of view of the transmitter, the
299  * \*_DRIVE_\* flags should be used. When used from the point of view of the
300  * receiver, the \*_SAMPLE_\* flags should be used. The \*_DRIVE_\* and
301  * \*_SAMPLE_\* flags alias each other, with the \*_SAMPLE_POSEDGE and
302  * \*_SAMPLE_NEGEDGE flags being equal to \*_DRIVE_NEGEDGE and \*_DRIVE_POSEDGE
303  * respectively. This simplifies code as signals are usually sampled on the
304  * opposite edge of the driving edge. Transmitters and receivers may however
305  * need to take other signal timings into account to convert between driving
306  * and sample edges.
307  *
308  * @DRM_BUS_FLAG_DE_LOW:		The Data Enable signal is active low
309  * @DRM_BUS_FLAG_DE_HIGH:		The Data Enable signal is active high
310  * @DRM_BUS_FLAG_PIXDATA_POSEDGE:	Legacy value, do not use
311  * @DRM_BUS_FLAG_PIXDATA_NEGEDGE:	Legacy value, do not use
312  * @DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE:	Data is driven on the rising edge of
313  *					the pixel clock
314  * @DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE:	Data is driven on the falling edge of
315  *					the pixel clock
316  * @DRM_BUS_FLAG_PIXDATA_SAMPLE_POSEDGE: Data is sampled on the rising edge of
317  *					the pixel clock
318  * @DRM_BUS_FLAG_PIXDATA_SAMPLE_NEGEDGE: Data is sampled on the falling edge of
319  *					the pixel clock
320  * @DRM_BUS_FLAG_DATA_MSB_TO_LSB:	Data is transmitted MSB to LSB on the bus
321  * @DRM_BUS_FLAG_DATA_LSB_TO_MSB:	Data is transmitted LSB to MSB on the bus
322  * @DRM_BUS_FLAG_SYNC_POSEDGE:		Legacy value, do not use
323  * @DRM_BUS_FLAG_SYNC_NEGEDGE:		Legacy value, do not use
324  * @DRM_BUS_FLAG_SYNC_DRIVE_POSEDGE:	Sync signals are driven on the rising
325  *					edge of the pixel clock
326  * @DRM_BUS_FLAG_SYNC_DRIVE_NEGEDGE:	Sync signals are driven on the falling
327  *					edge of the pixel clock
328  * @DRM_BUS_FLAG_SYNC_SAMPLE_POSEDGE:	Sync signals are sampled on the rising
329  *					edge of the pixel clock
330  * @DRM_BUS_FLAG_SYNC_SAMPLE_NEGEDGE:	Sync signals are sampled on the falling
331  *					edge of the pixel clock
332  * @DRM_BUS_FLAG_SHARP_SIGNALS:		Set if the Sharp-specific signals
333  *					(SPL, CLS, PS, REV) must be used
334  */
335 enum drm_bus_flags {
336 	DRM_BUS_FLAG_DE_LOW = BIT(0),
337 	DRM_BUS_FLAG_DE_HIGH = BIT(1),
338 	DRM_BUS_FLAG_PIXDATA_POSEDGE = BIT(2),
339 	DRM_BUS_FLAG_PIXDATA_NEGEDGE = BIT(3),
340 	DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE = DRM_BUS_FLAG_PIXDATA_POSEDGE,
341 	DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE = DRM_BUS_FLAG_PIXDATA_NEGEDGE,
342 	DRM_BUS_FLAG_PIXDATA_SAMPLE_POSEDGE = DRM_BUS_FLAG_PIXDATA_NEGEDGE,
343 	DRM_BUS_FLAG_PIXDATA_SAMPLE_NEGEDGE = DRM_BUS_FLAG_PIXDATA_POSEDGE,
344 	DRM_BUS_FLAG_DATA_MSB_TO_LSB = BIT(4),
345 	DRM_BUS_FLAG_DATA_LSB_TO_MSB = BIT(5),
346 	DRM_BUS_FLAG_SYNC_POSEDGE = BIT(6),
347 	DRM_BUS_FLAG_SYNC_NEGEDGE = BIT(7),
348 	DRM_BUS_FLAG_SYNC_DRIVE_POSEDGE = DRM_BUS_FLAG_SYNC_POSEDGE,
349 	DRM_BUS_FLAG_SYNC_DRIVE_NEGEDGE = DRM_BUS_FLAG_SYNC_NEGEDGE,
350 	DRM_BUS_FLAG_SYNC_SAMPLE_POSEDGE = DRM_BUS_FLAG_SYNC_NEGEDGE,
351 	DRM_BUS_FLAG_SYNC_SAMPLE_NEGEDGE = DRM_BUS_FLAG_SYNC_POSEDGE,
352 	DRM_BUS_FLAG_SHARP_SIGNALS = BIT(8),
353 };
354 
355 /**
356  * struct drm_display_info - runtime data about the connected sink
357  *
358  * Describes a given display (e.g. CRT or flat panel) and its limitations. For
359  * fixed display sinks like built-in panels there's not much difference between
360  * this and &struct drm_connector. But for sinks with a real cable this
361  * structure is meant to describe all the things at the other end of the cable.
362  *
363  * For sinks which provide an EDID this can be filled out by calling
364  * drm_add_edid_modes().
365  */
366 struct drm_display_info {
367 	/**
368 	 * @width_mm: Physical width in mm.
369 	 */
370 	unsigned int width_mm;
371 
372 	/**
373 	 * @height_mm: Physical height in mm.
374 	 */
375 	unsigned int height_mm;
376 
377 	/**
378 	 * @bpc: Maximum bits per color channel. Used by HDMI and DP outputs.
379 	 */
380 	unsigned int bpc;
381 
382 	/**
383 	 * @subpixel_order: Subpixel order of LCD panels.
384 	 */
385 	enum subpixel_order subpixel_order;
386 
387 #define DRM_COLOR_FORMAT_RGB444		(1<<0)
388 #define DRM_COLOR_FORMAT_YCRCB444	(1<<1)
389 #define DRM_COLOR_FORMAT_YCRCB422	(1<<2)
390 #define DRM_COLOR_FORMAT_YCRCB420	(1<<3)
391 
392 	/**
393 	 * @panel_orientation: Read only connector property for built-in panels,
394 	 * indicating the orientation of the panel vs the device's casing.
395 	 * drm_connector_init() sets this to DRM_MODE_PANEL_ORIENTATION_UNKNOWN.
396 	 * When not UNKNOWN this gets used by the drm_fb_helpers to rotate the
397 	 * fb to compensate and gets exported as prop to userspace.
398 	 */
399 	int panel_orientation;
400 
401 	/**
402 	 * @color_formats: HDMI Color formats, selects between RGB and YCrCb
403 	 * modes. Used DRM_COLOR_FORMAT\_ defines, which are _not_ the same ones
404 	 * as used to describe the pixel format in framebuffers, and also don't
405 	 * match the formats in @bus_formats which are shared with v4l.
406 	 */
407 	u32 color_formats;
408 
409 	/**
410 	 * @bus_formats: Pixel data format on the wire, somewhat redundant with
411 	 * @color_formats. Array of size @num_bus_formats encoded using
412 	 * MEDIA_BUS_FMT\_ defines shared with v4l and media drivers.
413 	 */
414 	const u32 *bus_formats;
415 	/**
416 	 * @num_bus_formats: Size of @bus_formats array.
417 	 */
418 	unsigned int num_bus_formats;
419 
420 	/**
421 	 * @bus_flags: Additional information (like pixel signal polarity) for
422 	 * the pixel data on the bus, using &enum drm_bus_flags values
423 	 * DRM_BUS_FLAGS\_.
424 	 */
425 	u32 bus_flags;
426 
427 	/**
428 	 * @max_tmds_clock: Maximum TMDS clock rate supported by the
429 	 * sink in kHz. 0 means undefined.
430 	 */
431 	int max_tmds_clock;
432 
433 	/**
434 	 * @dvi_dual: Dual-link DVI sink?
435 	 */
436 	bool dvi_dual;
437 
438 	/**
439 	 * @has_hdmi_infoframe: Does the sink support the HDMI infoframe?
440 	 */
441 	bool has_hdmi_infoframe;
442 
443 	/**
444 	 * @rgb_quant_range_selectable: Does the sink support selecting
445 	 * the RGB quantization range?
446 	 */
447 	bool rgb_quant_range_selectable;
448 
449 	/**
450 	 * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even
451 	 * more stuff redundant with @bus_formats.
452 	 */
453 	u8 edid_hdmi_dc_modes;
454 
455 	/**
456 	 * @cea_rev: CEA revision of the HDMI sink.
457 	 */
458 	u8 cea_rev;
459 
460 	/**
461 	 * @hdmi: advance features of a HDMI sink.
462 	 */
463 	struct drm_hdmi_info hdmi;
464 
465 	/**
466 	 * @non_desktop: Non desktop display (HMD).
467 	 */
468 	bool non_desktop;
469 };
470 
471 int drm_display_info_set_bus_formats(struct drm_display_info *info,
472 				     const u32 *formats,
473 				     unsigned int num_formats);
474 
475 /**
476  * struct drm_connector_tv_margins - TV connector related margins
477  *
478  * Describes the margins in pixels to put around the image on TV
479  * connectors to deal with overscan.
480  */
481 struct drm_connector_tv_margins {
482 	/**
483 	 * @bottom: Bottom margin in pixels.
484 	 */
485 	unsigned int bottom;
486 
487 	/**
488 	 * @left: Left margin in pixels.
489 	 */
490 	unsigned int left;
491 
492 	/**
493 	 * @right: Right margin in pixels.
494 	 */
495 	unsigned int right;
496 
497 	/**
498 	 * @top: Top margin in pixels.
499 	 */
500 	unsigned int top;
501 };
502 
503 /**
504  * struct drm_tv_connector_state - TV connector related states
505  * @subconnector: selected subconnector
506  * @margins: TV margins
507  * @mode: TV mode
508  * @brightness: brightness in percent
509  * @contrast: contrast in percent
510  * @flicker_reduction: flicker reduction in percent
511  * @overscan: overscan in percent
512  * @saturation: saturation in percent
513  * @hue: hue in percent
514  */
515 struct drm_tv_connector_state {
516 	enum drm_mode_subconnector subconnector;
517 	struct drm_connector_tv_margins margins;
518 	unsigned int mode;
519 	unsigned int brightness;
520 	unsigned int contrast;
521 	unsigned int flicker_reduction;
522 	unsigned int overscan;
523 	unsigned int saturation;
524 	unsigned int hue;
525 };
526 
527 /**
528  * struct drm_connector_state - mutable connector state
529  */
530 struct drm_connector_state {
531 	/** @connector: backpointer to the connector */
532 	struct drm_connector *connector;
533 
534 	/**
535 	 * @crtc: CRTC to connect connector to, NULL if disabled.
536 	 *
537 	 * Do not change this directly, use drm_atomic_set_crtc_for_connector()
538 	 * instead.
539 	 */
540 	struct drm_crtc *crtc;
541 
542 	/**
543 	 * @best_encoder:
544 	 *
545 	 * Used by the atomic helpers to select the encoder, through the
546 	 * &drm_connector_helper_funcs.atomic_best_encoder or
547 	 * &drm_connector_helper_funcs.best_encoder callbacks.
548 	 *
549 	 * This is also used in the atomic helpers to map encoders to their
550 	 * current and previous connectors, see
551 	 * drm_atomic_get_old_connector_for_encoder() and
552 	 * drm_atomic_get_new_connector_for_encoder().
553 	 *
554 	 * NOTE: Atomic drivers must fill this out (either themselves or through
555 	 * helpers), for otherwise the GETCONNECTOR and GETENCODER IOCTLs will
556 	 * not return correct data to userspace.
557 	 */
558 	struct drm_encoder *best_encoder;
559 
560 	/**
561 	 * @link_status: Connector link_status to keep track of whether link is
562 	 * GOOD or BAD to notify userspace if retraining is necessary.
563 	 */
564 	enum drm_link_status link_status;
565 
566 	/** @state: backpointer to global drm_atomic_state */
567 	struct drm_atomic_state *state;
568 
569 	/**
570 	 * @commit: Tracks the pending commit to prevent use-after-free conditions.
571 	 *
572 	 * Is only set when @crtc is NULL.
573 	 */
574 	struct drm_crtc_commit *commit;
575 
576 	/** @tv: TV connector state */
577 	struct drm_tv_connector_state tv;
578 
579 	/**
580 	 * @self_refresh_aware:
581 	 *
582 	 * This tracks whether a connector is aware of the self refresh state.
583 	 * It should be set to true for those connector implementations which
584 	 * understand the self refresh state. This is needed since the crtc
585 	 * registers the self refresh helpers and it doesn't know if the
586 	 * connectors downstream have implemented self refresh entry/exit.
587 	 *
588 	 * Drivers should set this to true in atomic_check if they know how to
589 	 * handle self_refresh requests.
590 	 */
591 	bool self_refresh_aware;
592 
593 	/**
594 	 * @picture_aspect_ratio: Connector property to control the
595 	 * HDMI infoframe aspect ratio setting.
596 	 *
597 	 * The %DRM_MODE_PICTURE_ASPECT_\* values much match the
598 	 * values for &enum hdmi_picture_aspect
599 	 */
600 	enum hdmi_picture_aspect picture_aspect_ratio;
601 
602 	/**
603 	 * @content_type: Connector property to control the
604 	 * HDMI infoframe content type setting.
605 	 * The %DRM_MODE_CONTENT_TYPE_\* values much
606 	 * match the values.
607 	 */
608 	unsigned int content_type;
609 
610 	/**
611 	 * @hdcp_content_type: Connector property to pass the type of
612 	 * protected content. This is most commonly used for HDCP.
613 	 */
614 	unsigned int hdcp_content_type;
615 
616 	/**
617 	 * @scaling_mode: Connector property to control the
618 	 * upscaling, mostly used for built-in panels.
619 	 */
620 	unsigned int scaling_mode;
621 
622 	/**
623 	 * @content_protection: Connector property to request content
624 	 * protection. This is most commonly used for HDCP.
625 	 */
626 	unsigned int content_protection;
627 
628 	/**
629 	 * @colorspace: State variable for Connector property to request
630 	 * colorspace change on Sink. This is most commonly used to switch
631 	 * to wider color gamuts like BT2020.
632 	 */
633 	u32 colorspace;
634 
635 	/**
636 	 * @writeback_job: Writeback job for writeback connectors
637 	 *
638 	 * Holds the framebuffer and out-fence for a writeback connector. As
639 	 * the writeback completion may be asynchronous to the normal commit
640 	 * cycle, the writeback job lifetime is managed separately from the
641 	 * normal atomic state by this object.
642 	 *
643 	 * See also: drm_writeback_queue_job() and
644 	 * drm_writeback_signal_completion()
645 	 */
646 	struct drm_writeback_job *writeback_job;
647 
648 	/**
649 	 * @max_requested_bpc: Connector property to limit the maximum bit
650 	 * depth of the pixels.
651 	 */
652 	u8 max_requested_bpc;
653 
654 	/**
655 	 * @max_bpc: Connector max_bpc based on the requested max_bpc property
656 	 * and the connector bpc limitations obtained from edid.
657 	 */
658 	u8 max_bpc;
659 
660 	/**
661 	 * @hdr_output_metadata:
662 	 * DRM blob property for HDR output metadata
663 	 */
664 	struct drm_property_blob *hdr_output_metadata;
665 };
666 
667 /**
668  * struct drm_connector_funcs - control connectors on a given device
669  *
670  * Each CRTC may have one or more connectors attached to it.  The functions
671  * below allow the core DRM code to control connectors, enumerate available modes,
672  * etc.
673  */
674 struct drm_connector_funcs {
675 	/**
676 	 * @dpms:
677 	 *
678 	 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
679 	 * is exposed as a standard property on the connector, but diverted to
680 	 * this callback in the drm core. Note that atomic drivers don't
681 	 * implement the 4 level DPMS support on the connector any more, but
682 	 * instead only have an on/off "ACTIVE" property on the CRTC object.
683 	 *
684 	 * This hook is not used by atomic drivers, remapping of the legacy DPMS
685 	 * property is entirely handled in the DRM core.
686 	 *
687 	 * RETURNS:
688 	 *
689 	 * 0 on success or a negative error code on failure.
690 	 */
691 	int (*dpms)(struct drm_connector *connector, int mode);
692 
693 	/**
694 	 * @reset:
695 	 *
696 	 * Reset connector hardware and software state to off. This function isn't
697 	 * called by the core directly, only through drm_mode_config_reset().
698 	 * It's not a helper hook only for historical reasons.
699 	 *
700 	 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
701 	 * atomic state using this hook.
702 	 */
703 	void (*reset)(struct drm_connector *connector);
704 
705 	/**
706 	 * @detect:
707 	 *
708 	 * Check to see if anything is attached to the connector. The parameter
709 	 * force is set to false whilst polling, true when checking the
710 	 * connector due to a user request. force can be used by the driver to
711 	 * avoid expensive, destructive operations during automated probing.
712 	 *
713 	 * This callback is optional, if not implemented the connector will be
714 	 * considered as always being attached.
715 	 *
716 	 * FIXME:
717 	 *
718 	 * Note that this hook is only called by the probe helper. It's not in
719 	 * the helper library vtable purely for historical reasons. The only DRM
720 	 * core	entry point to probe connector state is @fill_modes.
721 	 *
722 	 * Note that the helper library will already hold
723 	 * &drm_mode_config.connection_mutex. Drivers which need to grab additional
724 	 * locks to avoid races with concurrent modeset changes need to use
725 	 * &drm_connector_helper_funcs.detect_ctx instead.
726 	 *
727 	 * RETURNS:
728 	 *
729 	 * drm_connector_status indicating the connector's status.
730 	 */
731 	enum drm_connector_status (*detect)(struct drm_connector *connector,
732 					    bool force);
733 
734 	/**
735 	 * @force:
736 	 *
737 	 * This function is called to update internal encoder state when the
738 	 * connector is forced to a certain state by userspace, either through
739 	 * the sysfs interfaces or on the kernel cmdline. In that case the
740 	 * @detect callback isn't called.
741 	 *
742 	 * FIXME:
743 	 *
744 	 * Note that this hook is only called by the probe helper. It's not in
745 	 * the helper library vtable purely for historical reasons. The only DRM
746 	 * core	entry point to probe connector state is @fill_modes.
747 	 */
748 	void (*force)(struct drm_connector *connector);
749 
750 	/**
751 	 * @fill_modes:
752 	 *
753 	 * Entry point for output detection and basic mode validation. The
754 	 * driver should reprobe the output if needed (e.g. when hotplug
755 	 * handling is unreliable), add all detected modes to &drm_connector.modes
756 	 * and filter out any the device can't support in any configuration. It
757 	 * also needs to filter out any modes wider or higher than the
758 	 * parameters max_width and max_height indicate.
759 	 *
760 	 * The drivers must also prune any modes no longer valid from
761 	 * &drm_connector.modes. Furthermore it must update
762 	 * &drm_connector.status and &drm_connector.edid.  If no EDID has been
763 	 * received for this output connector->edid must be NULL.
764 	 *
765 	 * Drivers using the probe helpers should use
766 	 * drm_helper_probe_single_connector_modes() to implement this
767 	 * function.
768 	 *
769 	 * RETURNS:
770 	 *
771 	 * The number of modes detected and filled into &drm_connector.modes.
772 	 */
773 	int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
774 
775 	/**
776 	 * @set_property:
777 	 *
778 	 * This is the legacy entry point to update a property attached to the
779 	 * connector.
780 	 *
781 	 * This callback is optional if the driver does not support any legacy
782 	 * driver-private properties. For atomic drivers it is not used because
783 	 * property handling is done entirely in the DRM core.
784 	 *
785 	 * RETURNS:
786 	 *
787 	 * 0 on success or a negative error code on failure.
788 	 */
789 	int (*set_property)(struct drm_connector *connector, struct drm_property *property,
790 			     uint64_t val);
791 
792 	/**
793 	 * @late_register:
794 	 *
795 	 * This optional hook can be used to register additional userspace
796 	 * interfaces attached to the connector, light backlight control, i2c,
797 	 * DP aux or similar interfaces. It is called late in the driver load
798 	 * sequence from drm_connector_register() when registering all the
799 	 * core drm connector interfaces. Everything added from this callback
800 	 * should be unregistered in the early_unregister callback.
801 	 *
802 	 * This is called while holding &drm_connector.mutex.
803 	 *
804 	 * Returns:
805 	 *
806 	 * 0 on success, or a negative error code on failure.
807 	 */
808 	int (*late_register)(struct drm_connector *connector);
809 
810 	/**
811 	 * @early_unregister:
812 	 *
813 	 * This optional hook should be used to unregister the additional
814 	 * userspace interfaces attached to the connector from
815 	 * late_register(). It is called from drm_connector_unregister(),
816 	 * early in the driver unload sequence to disable userspace access
817 	 * before data structures are torndown.
818 	 *
819 	 * This is called while holding &drm_connector.mutex.
820 	 */
821 	void (*early_unregister)(struct drm_connector *connector);
822 
823 	/**
824 	 * @destroy:
825 	 *
826 	 * Clean up connector resources. This is called at driver unload time
827 	 * through drm_mode_config_cleanup(). It can also be called at runtime
828 	 * when a connector is being hot-unplugged for drivers that support
829 	 * connector hotplugging (e.g. DisplayPort MST).
830 	 */
831 	void (*destroy)(struct drm_connector *connector);
832 
833 	/**
834 	 * @atomic_duplicate_state:
835 	 *
836 	 * Duplicate the current atomic state for this connector and return it.
837 	 * The core and helpers guarantee that any atomic state duplicated with
838 	 * this hook and still owned by the caller (i.e. not transferred to the
839 	 * driver by calling &drm_mode_config_funcs.atomic_commit) will be
840 	 * cleaned up by calling the @atomic_destroy_state hook in this
841 	 * structure.
842 	 *
843 	 * This callback is mandatory for atomic drivers.
844 	 *
845 	 * Atomic drivers which don't subclass &struct drm_connector_state should use
846 	 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
847 	 * state structure to extend it with driver-private state should use
848 	 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
849 	 * duplicated in a consistent fashion across drivers.
850 	 *
851 	 * It is an error to call this hook before &drm_connector.state has been
852 	 * initialized correctly.
853 	 *
854 	 * NOTE:
855 	 *
856 	 * If the duplicate state references refcounted resources this hook must
857 	 * acquire a reference for each of them. The driver must release these
858 	 * references again in @atomic_destroy_state.
859 	 *
860 	 * RETURNS:
861 	 *
862 	 * Duplicated atomic state or NULL when the allocation failed.
863 	 */
864 	struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
865 
866 	/**
867 	 * @atomic_destroy_state:
868 	 *
869 	 * Destroy a state duplicated with @atomic_duplicate_state and release
870 	 * or unreference all resources it references
871 	 *
872 	 * This callback is mandatory for atomic drivers.
873 	 */
874 	void (*atomic_destroy_state)(struct drm_connector *connector,
875 				     struct drm_connector_state *state);
876 
877 	/**
878 	 * @atomic_set_property:
879 	 *
880 	 * Decode a driver-private property value and store the decoded value
881 	 * into the passed-in state structure. Since the atomic core decodes all
882 	 * standardized properties (even for extensions beyond the core set of
883 	 * properties which might not be implemented by all drivers) this
884 	 * requires drivers to subclass the state structure.
885 	 *
886 	 * Such driver-private properties should really only be implemented for
887 	 * truly hardware/vendor specific state. Instead it is preferred to
888 	 * standardize atomic extension and decode the properties used to expose
889 	 * such an extension in the core.
890 	 *
891 	 * Do not call this function directly, use
892 	 * drm_atomic_connector_set_property() instead.
893 	 *
894 	 * This callback is optional if the driver does not support any
895 	 * driver-private atomic properties.
896 	 *
897 	 * NOTE:
898 	 *
899 	 * This function is called in the state assembly phase of atomic
900 	 * modesets, which can be aborted for any reason (including on
901 	 * userspace's request to just check whether a configuration would be
902 	 * possible). Drivers MUST NOT touch any persistent state (hardware or
903 	 * software) or data structures except the passed in @state parameter.
904 	 *
905 	 * Also since userspace controls in which order properties are set this
906 	 * function must not do any input validation (since the state update is
907 	 * incomplete and hence likely inconsistent). Instead any such input
908 	 * validation must be done in the various atomic_check callbacks.
909 	 *
910 	 * RETURNS:
911 	 *
912 	 * 0 if the property has been found, -EINVAL if the property isn't
913 	 * implemented by the driver (which shouldn't ever happen, the core only
914 	 * asks for properties attached to this connector). No other validation
915 	 * is allowed by the driver. The core already checks that the property
916 	 * value is within the range (integer, valid enum value, ...) the driver
917 	 * set when registering the property.
918 	 */
919 	int (*atomic_set_property)(struct drm_connector *connector,
920 				   struct drm_connector_state *state,
921 				   struct drm_property *property,
922 				   uint64_t val);
923 
924 	/**
925 	 * @atomic_get_property:
926 	 *
927 	 * Reads out the decoded driver-private property. This is used to
928 	 * implement the GETCONNECTOR IOCTL.
929 	 *
930 	 * Do not call this function directly, use
931 	 * drm_atomic_connector_get_property() instead.
932 	 *
933 	 * This callback is optional if the driver does not support any
934 	 * driver-private atomic properties.
935 	 *
936 	 * RETURNS:
937 	 *
938 	 * 0 on success, -EINVAL if the property isn't implemented by the
939 	 * driver (which shouldn't ever happen, the core only asks for
940 	 * properties attached to this connector).
941 	 */
942 	int (*atomic_get_property)(struct drm_connector *connector,
943 				   const struct drm_connector_state *state,
944 				   struct drm_property *property,
945 				   uint64_t *val);
946 
947 	/**
948 	 * @atomic_print_state:
949 	 *
950 	 * If driver subclasses &struct drm_connector_state, it should implement
951 	 * this optional hook for printing additional driver specific state.
952 	 *
953 	 * Do not call this directly, use drm_atomic_connector_print_state()
954 	 * instead.
955 	 */
956 	void (*atomic_print_state)(struct drm_printer *p,
957 				   const struct drm_connector_state *state);
958 };
959 
960 /**
961  * struct drm_cmdline_mode - DRM Mode passed through the kernel command-line
962  *
963  * Each connector can have an initial mode with additional options
964  * passed through the kernel command line. This structure allows to
965  * express those parameters and will be filled by the command-line
966  * parser.
967  */
968 struct drm_cmdline_mode {
969 	/**
970 	 * @name:
971 	 *
972 	 * Name of the mode.
973 	 */
974 	char name[DRM_DISPLAY_MODE_LEN];
975 
976 	/**
977 	 * @specified:
978 	 *
979 	 * Has a mode been read from the command-line?
980 	 */
981 	bool specified;
982 
983 	/**
984 	 * @refresh_specified:
985 	 *
986 	 * Did the mode have a preferred refresh rate?
987 	 */
988 	bool refresh_specified;
989 
990 	/**
991 	 * @bpp_specified:
992 	 *
993 	 * Did the mode have a preferred BPP?
994 	 */
995 	bool bpp_specified;
996 
997 	/**
998 	 * @xres:
999 	 *
1000 	 * Active resolution on the X axis, in pixels.
1001 	 */
1002 	int xres;
1003 
1004 	/**
1005 	 * @yres:
1006 	 *
1007 	 * Active resolution on the Y axis, in pixels.
1008 	 */
1009 	int yres;
1010 
1011 	/**
1012 	 * @bpp:
1013 	 *
1014 	 * Bits per pixels for the mode.
1015 	 */
1016 	int bpp;
1017 
1018 	/**
1019 	 * @refresh:
1020 	 *
1021 	 * Refresh rate, in Hertz.
1022 	 */
1023 	int refresh;
1024 
1025 	/**
1026 	 * @rb:
1027 	 *
1028 	 * Do we need to use reduced blanking?
1029 	 */
1030 	bool rb;
1031 
1032 	/**
1033 	 * @interlace:
1034 	 *
1035 	 * The mode is interlaced.
1036 	 */
1037 	bool interlace;
1038 
1039 	/**
1040 	 * @cvt:
1041 	 *
1042 	 * The timings will be calculated using the VESA Coordinated
1043 	 * Video Timings instead of looking up the mode from a table.
1044 	 */
1045 	bool cvt;
1046 
1047 	/**
1048 	 * @margins:
1049 	 *
1050 	 * Add margins to the mode calculation (1.8% of xres rounded
1051 	 * down to 8 pixels and 1.8% of yres).
1052 	 */
1053 	bool margins;
1054 
1055 	/**
1056 	 * @force:
1057 	 *
1058 	 * Ignore the hotplug state of the connector, and force its
1059 	 * state to one of the DRM_FORCE_* values.
1060 	 */
1061 	enum drm_connector_force force;
1062 
1063 	/**
1064 	 * @rotation_reflection:
1065 	 *
1066 	 * Initial rotation and reflection of the mode setup from the
1067 	 * command line. See DRM_MODE_ROTATE_* and
1068 	 * DRM_MODE_REFLECT_*. The only rotations supported are
1069 	 * DRM_MODE_ROTATE_0 and DRM_MODE_ROTATE_180.
1070 	 */
1071 	unsigned int rotation_reflection;
1072 
1073 	/**
1074 	 * @tv_margins: TV margins to apply to the mode.
1075 	 */
1076 	struct drm_connector_tv_margins tv_margins;
1077 };
1078 
1079 /**
1080  * struct drm_connector - central DRM connector control structure
1081  *
1082  * Each connector may be connected to one or more CRTCs, or may be clonable by
1083  * another connector if they can share a CRTC.  Each connector also has a specific
1084  * position in the broader display (referred to as a 'screen' though it could
1085  * span multiple monitors).
1086  */
1087 struct drm_connector {
1088 	/** @dev: parent DRM device */
1089 	struct drm_device *dev;
1090 	/** @kdev: kernel device for sysfs attributes */
1091 	struct device *kdev;
1092 	/** @attr: sysfs attributes */
1093 	struct device_attribute *attr;
1094 
1095 	/**
1096 	 * @head:
1097 	 *
1098 	 * List of all connectors on a @dev, linked from
1099 	 * &drm_mode_config.connector_list. Protected by
1100 	 * &drm_mode_config.connector_list_lock, but please only use
1101 	 * &drm_connector_list_iter to walk this list.
1102 	 */
1103 	struct list_head head;
1104 
1105 	/** @base: base KMS object */
1106 	struct drm_mode_object base;
1107 
1108 	/** @name: human readable name, can be overwritten by the driver */
1109 	char *name;
1110 
1111 	/**
1112 	 * @mutex: Lock for general connector state, but currently only protects
1113 	 * @registered. Most of the connector state is still protected by
1114 	 * &drm_mode_config.mutex.
1115 	 */
1116 	struct mutex mutex;
1117 
1118 	/**
1119 	 * @index: Compacted connector index, which matches the position inside
1120 	 * the mode_config.list for drivers not supporting hot-add/removing. Can
1121 	 * be used as an array index. It is invariant over the lifetime of the
1122 	 * connector.
1123 	 */
1124 	unsigned index;
1125 
1126 	/**
1127 	 * @connector_type:
1128 	 * one of the DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1129 	 */
1130 	int connector_type;
1131 	/** @connector_type_id: index into connector type enum */
1132 	int connector_type_id;
1133 	/**
1134 	 * @interlace_allowed:
1135 	 * Can this connector handle interlaced modes? Only used by
1136 	 * drm_helper_probe_single_connector_modes() for mode filtering.
1137 	 */
1138 	bool interlace_allowed;
1139 	/**
1140 	 * @doublescan_allowed:
1141 	 * Can this connector handle doublescan? Only used by
1142 	 * drm_helper_probe_single_connector_modes() for mode filtering.
1143 	 */
1144 	bool doublescan_allowed;
1145 	/**
1146 	 * @stereo_allowed:
1147 	 * Can this connector handle stereo modes? Only used by
1148 	 * drm_helper_probe_single_connector_modes() for mode filtering.
1149 	 */
1150 	bool stereo_allowed;
1151 
1152 	/**
1153 	 * @ycbcr_420_allowed : This bool indicates if this connector is
1154 	 * capable of handling YCBCR 420 output. While parsing the EDID
1155 	 * blocks it's very helpful to know if the source is capable of
1156 	 * handling YCBCR 420 outputs.
1157 	 */
1158 	bool ycbcr_420_allowed;
1159 
1160 	/**
1161 	 * @registration_state: Is this connector initializing, exposed
1162 	 * (registered) with userspace, or unregistered?
1163 	 *
1164 	 * Protected by @mutex.
1165 	 */
1166 	enum drm_connector_registration_state registration_state;
1167 
1168 	/**
1169 	 * @modes:
1170 	 * Modes available on this connector (from fill_modes() + user).
1171 	 * Protected by &drm_mode_config.mutex.
1172 	 */
1173 	struct list_head modes;
1174 
1175 	/**
1176 	 * @status:
1177 	 * One of the drm_connector_status enums (connected, not, or unknown).
1178 	 * Protected by &drm_mode_config.mutex.
1179 	 */
1180 	enum drm_connector_status status;
1181 
1182 	/**
1183 	 * @probed_modes:
1184 	 * These are modes added by probing with DDC or the BIOS, before
1185 	 * filtering is applied. Used by the probe helpers. Protected by
1186 	 * &drm_mode_config.mutex.
1187 	 */
1188 	struct list_head probed_modes;
1189 
1190 	/**
1191 	 * @display_info: Display information is filled from EDID information
1192 	 * when a display is detected. For non hot-pluggable displays such as
1193 	 * flat panels in embedded systems, the driver should initialize the
1194 	 * &drm_display_info.width_mm and &drm_display_info.height_mm fields
1195 	 * with the physical size of the display.
1196 	 *
1197 	 * Protected by &drm_mode_config.mutex.
1198 	 */
1199 	struct drm_display_info display_info;
1200 
1201 	/** @funcs: connector control functions */
1202 	const struct drm_connector_funcs *funcs;
1203 
1204 	/**
1205 	 * @edid_blob_ptr: DRM property containing EDID if present. Protected by
1206 	 * &drm_mode_config.mutex. This should be updated only by calling
1207 	 * drm_connector_update_edid_property().
1208 	 */
1209 	struct drm_property_blob *edid_blob_ptr;
1210 
1211 	/** @properties: property tracking for this connector */
1212 	struct drm_object_properties properties;
1213 
1214 	/**
1215 	 * @scaling_mode_property: Optional atomic property to control the
1216 	 * upscaling. See drm_connector_attach_content_protection_property().
1217 	 */
1218 	struct drm_property *scaling_mode_property;
1219 
1220 	/**
1221 	 * @vrr_capable_property: Optional property to help userspace
1222 	 * query hardware support for variable refresh rate on a connector.
1223 	 * connector. Drivers can add the property to a connector by
1224 	 * calling drm_connector_attach_vrr_capable_property().
1225 	 *
1226 	 * This should be updated only by calling
1227 	 * drm_connector_set_vrr_capable_property().
1228 	 */
1229 	struct drm_property *vrr_capable_property;
1230 
1231 	/**
1232 	 * @colorspace_property: Connector property to set the suitable
1233 	 * colorspace supported by the sink.
1234 	 */
1235 	struct drm_property *colorspace_property;
1236 
1237 	/**
1238 	 * @path_blob_ptr:
1239 	 *
1240 	 * DRM blob property data for the DP MST path property. This should only
1241 	 * be updated by calling drm_connector_set_path_property().
1242 	 */
1243 	struct drm_property_blob *path_blob_ptr;
1244 
1245 	/**
1246 	 * @max_bpc_property: Default connector property for the max bpc to be
1247 	 * driven out of the connector.
1248 	 */
1249 	struct drm_property *max_bpc_property;
1250 
1251 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
1252 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1253 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1254 
1255 	/**
1256 	 * @polled:
1257 	 *
1258 	 * Connector polling mode, a combination of
1259 	 *
1260 	 * DRM_CONNECTOR_POLL_HPD
1261 	 *     The connector generates hotplug events and doesn't need to be
1262 	 *     periodically polled. The CONNECT and DISCONNECT flags must not
1263 	 *     be set together with the HPD flag.
1264 	 *
1265 	 * DRM_CONNECTOR_POLL_CONNECT
1266 	 *     Periodically poll the connector for connection.
1267 	 *
1268 	 * DRM_CONNECTOR_POLL_DISCONNECT
1269 	 *     Periodically poll the connector for disconnection, without
1270 	 *     causing flickering even when the connector is in use. DACs should
1271 	 *     rarely do this without a lot of testing.
1272 	 *
1273 	 * Set to 0 for connectors that don't support connection status
1274 	 * discovery.
1275 	 */
1276 	uint8_t polled;
1277 
1278 	/**
1279 	 * @dpms: Current dpms state. For legacy drivers the
1280 	 * &drm_connector_funcs.dpms callback must update this. For atomic
1281 	 * drivers, this is handled by the core atomic code, and drivers must
1282 	 * only take &drm_crtc_state.active into account.
1283 	 */
1284 	int dpms;
1285 
1286 	/** @helper_private: mid-layer private data */
1287 	const struct drm_connector_helper_funcs *helper_private;
1288 
1289 	/** @cmdline_mode: mode line parsed from the kernel cmdline for this connector */
1290 	struct drm_cmdline_mode cmdline_mode;
1291 	/** @force: a DRM_FORCE_<foo> state for forced mode sets */
1292 	enum drm_connector_force force;
1293 	/** @override_edid: has the EDID been overwritten through debugfs for testing? */
1294 	bool override_edid;
1295 
1296 #define DRM_CONNECTOR_MAX_ENCODER 3
1297 	/**
1298 	 * @encoder_ids: Valid encoders for this connector. Please only use
1299 	 * drm_connector_for_each_possible_encoder() to enumerate these.
1300 	 */
1301 	uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
1302 
1303 	/**
1304 	 * @encoder: Currently bound encoder driving this connector, if any.
1305 	 * Only really meaningful for non-atomic drivers. Atomic drivers should
1306 	 * instead look at &drm_connector_state.best_encoder, and in case they
1307 	 * need the CRTC driving this output, &drm_connector_state.crtc.
1308 	 */
1309 	struct drm_encoder *encoder;
1310 
1311 #define MAX_ELD_BYTES	128
1312 	/** @eld: EDID-like data, if present */
1313 	uint8_t eld[MAX_ELD_BYTES];
1314 	/** @latency_present: AV delay info from ELD, if found */
1315 	bool latency_present[2];
1316 	/**
1317 	 * @video_latency: Video latency info from ELD, if found.
1318 	 * [0]: progressive, [1]: interlaced
1319 	 */
1320 	int video_latency[2];
1321 	/**
1322 	 * @audio_latency: audio latency info from ELD, if found
1323 	 * [0]: progressive, [1]: interlaced
1324 	 */
1325 	int audio_latency[2];
1326 
1327 	/**
1328 	 * @ddc: associated ddc adapter.
1329 	 * A connector usually has its associated ddc adapter. If a driver uses
1330 	 * this field, then an appropriate symbolic link is created in connector
1331 	 * sysfs directory to make it easy for the user to tell which i2c
1332 	 * adapter is for a particular display.
1333 	 *
1334 	 * The field should be set by calling drm_connector_init_with_ddc().
1335 	 */
1336 	struct i2c_adapter *ddc;
1337 
1338 	/**
1339 	 * @null_edid_counter: track sinks that give us all zeros for the EDID.
1340 	 * Needed to workaround some HW bugs where we get all 0s
1341 	 */
1342 	int null_edid_counter;
1343 
1344 	/** @bad_edid_counter: track sinks that give us an EDID with invalid checksum */
1345 	unsigned bad_edid_counter;
1346 
1347 	/**
1348 	 * @edid_corrupt: Indicates whether the last read EDID was corrupt. Used
1349 	 * in Displayport compliance testing - Displayport Link CTS Core 1.2
1350 	 * rev1.1 4.2.2.6
1351 	 */
1352 	bool edid_corrupt;
1353 	/**
1354 	 * @real_edid_checksum: real edid checksum for corrupted edid block.
1355 	 * Required in Displayport 1.4 compliance testing
1356 	 * rev1.1 4.2.2.6
1357 	 */
1358 	u8 real_edid_checksum;
1359 
1360 	/** @debugfs_entry: debugfs directory for this connector */
1361 	struct dentry *debugfs_entry;
1362 
1363 	/**
1364 	 * @state:
1365 	 *
1366 	 * Current atomic state for this connector.
1367 	 *
1368 	 * This is protected by &drm_mode_config.connection_mutex. Note that
1369 	 * nonblocking atomic commits access the current connector state without
1370 	 * taking locks. Either by going through the &struct drm_atomic_state
1371 	 * pointers, see for_each_oldnew_connector_in_state(),
1372 	 * for_each_old_connector_in_state() and
1373 	 * for_each_new_connector_in_state(). Or through careful ordering of
1374 	 * atomic commit operations as implemented in the atomic helpers, see
1375 	 * &struct drm_crtc_commit.
1376 	 */
1377 	struct drm_connector_state *state;
1378 
1379 	/* DisplayID bits. FIXME: Extract into a substruct? */
1380 
1381 	/**
1382 	 * @tile_blob_ptr:
1383 	 *
1384 	 * DRM blob property data for the tile property (used mostly by DP MST).
1385 	 * This is meant for screens which are driven through separate display
1386 	 * pipelines represented by &drm_crtc, which might not be running with
1387 	 * genlocked clocks. For tiled panels which are genlocked, like
1388 	 * dual-link LVDS or dual-link DSI, the driver should try to not expose
1389 	 * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
1390 	 *
1391 	 * This should only be updated by calling
1392 	 * drm_connector_set_tile_property().
1393 	 */
1394 	struct drm_property_blob *tile_blob_ptr;
1395 
1396 	/** @has_tile: is this connector connected to a tiled monitor */
1397 	bool has_tile;
1398 	/** @tile_group: tile group for the connected monitor */
1399 	struct drm_tile_group *tile_group;
1400 	/** @tile_is_single_monitor: whether the tile is one monitor housing */
1401 	bool tile_is_single_monitor;
1402 
1403 	/** @num_h_tile: number of horizontal tiles in the tile group */
1404 	/** @num_v_tile: number of vertical tiles in the tile group */
1405 	uint8_t num_h_tile, num_v_tile;
1406 	/** @tile_h_loc: horizontal location of this tile */
1407 	/** @tile_v_loc: vertical location of this tile */
1408 	uint8_t tile_h_loc, tile_v_loc;
1409 	/** @tile_h_size: horizontal size of this tile. */
1410 	/** @tile_v_size: vertical size of this tile. */
1411 	uint16_t tile_h_size, tile_v_size;
1412 
1413 	/**
1414 	 * @free_node:
1415 	 *
1416 	 * List used only by &drm_connector_list_iter to be able to clean up a
1417 	 * connector from any context, in conjunction with
1418 	 * &drm_mode_config.connector_free_work.
1419 	 */
1420 	struct llist_node free_node;
1421 
1422 	/** @hdr_sink_metadata: HDR Metadata Information read from sink */
1423 	struct hdr_sink_metadata hdr_sink_metadata;
1424 
1425 	/**
1426 	 * @panel:
1427 	 *
1428 	 * Can find the panel which connected to drm_connector.
1429 	 */
1430 	struct drm_panel *panel;
1431 };
1432 
1433 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
1434 
1435 int drm_connector_init(struct drm_device *dev,
1436 		       struct drm_connector *connector,
1437 		       const struct drm_connector_funcs *funcs,
1438 		       int connector_type);
1439 int drm_connector_init_with_ddc(struct drm_device *dev,
1440 				struct drm_connector *connector,
1441 				const struct drm_connector_funcs *funcs,
1442 				int connector_type,
1443 				struct i2c_adapter *ddc);
1444 void drm_connector_attach_edid_property(struct drm_connector *connector);
1445 int drm_connector_register(struct drm_connector *connector);
1446 void drm_connector_unregister(struct drm_connector *connector);
1447 int drm_connector_attach_encoder(struct drm_connector *connector,
1448 				      struct drm_encoder *encoder);
1449 
1450 void drm_connector_cleanup(struct drm_connector *connector);
1451 
drm_connector_index(const struct drm_connector * connector)1452 static inline unsigned int drm_connector_index(const struct drm_connector *connector)
1453 {
1454 	return connector->index;
1455 }
1456 
drm_connector_mask(const struct drm_connector * connector)1457 static inline u32 drm_connector_mask(const struct drm_connector *connector)
1458 {
1459 	return 1 << connector->index;
1460 }
1461 
1462 /**
1463  * drm_connector_lookup - lookup connector object
1464  * @dev: DRM device
1465  * @file_priv: drm file to check for lease against.
1466  * @id: connector object id
1467  *
1468  * This function looks up the connector object specified by id
1469  * add takes a reference to it.
1470  */
drm_connector_lookup(struct drm_device * dev,struct drm_file * file_priv,uint32_t id)1471 static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
1472 		struct drm_file *file_priv,
1473 		uint32_t id)
1474 {
1475 	struct drm_mode_object *mo;
1476 	mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_CONNECTOR);
1477 	return mo ? obj_to_connector(mo) : NULL;
1478 }
1479 
1480 /**
1481  * drm_connector_get - acquire a connector reference
1482  * @connector: DRM connector
1483  *
1484  * This function increments the connector's refcount.
1485  */
drm_connector_get(struct drm_connector * connector)1486 static inline void drm_connector_get(struct drm_connector *connector)
1487 {
1488 	drm_mode_object_get(&connector->base);
1489 }
1490 
1491 /**
1492  * drm_connector_put - release a connector reference
1493  * @connector: DRM connector
1494  *
1495  * This function decrements the connector's reference count and frees the
1496  * object if the reference count drops to zero.
1497  */
drm_connector_put(struct drm_connector * connector)1498 static inline void drm_connector_put(struct drm_connector *connector)
1499 {
1500 	drm_mode_object_put(&connector->base);
1501 }
1502 
1503 /**
1504  * drm_connector_is_unregistered - has the connector been unregistered from
1505  * userspace?
1506  * @connector: DRM connector
1507  *
1508  * Checks whether or not @connector has been unregistered from userspace.
1509  *
1510  * Returns:
1511  * True if the connector was unregistered, false if the connector is
1512  * registered or has not yet been registered with userspace.
1513  */
1514 static inline bool
drm_connector_is_unregistered(struct drm_connector * connector)1515 drm_connector_is_unregistered(struct drm_connector *connector)
1516 {
1517 	return READ_ONCE(connector->registration_state) ==
1518 		DRM_CONNECTOR_UNREGISTERED;
1519 }
1520 
1521 const char *drm_get_connector_status_name(enum drm_connector_status status);
1522 const char *drm_get_subpixel_order_name(enum subpixel_order order);
1523 const char *drm_get_dpms_name(int val);
1524 const char *drm_get_dvi_i_subconnector_name(int val);
1525 const char *drm_get_dvi_i_select_name(int val);
1526 const char *drm_get_tv_subconnector_name(int val);
1527 const char *drm_get_tv_select_name(int val);
1528 const char *drm_get_content_protection_name(int val);
1529 const char *drm_get_hdcp_content_type_name(int val);
1530 
1531 int drm_mode_create_dvi_i_properties(struct drm_device *dev);
1532 int drm_mode_create_tv_margin_properties(struct drm_device *dev);
1533 int drm_mode_create_tv_properties(struct drm_device *dev,
1534 				  unsigned int num_modes,
1535 				  const char * const modes[]);
1536 void drm_connector_attach_tv_margin_properties(struct drm_connector *conn);
1537 int drm_mode_create_scaling_mode_property(struct drm_device *dev);
1538 int drm_connector_attach_content_type_property(struct drm_connector *dev);
1539 int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
1540 					       u32 scaling_mode_mask);
1541 int drm_connector_attach_vrr_capable_property(
1542 		struct drm_connector *connector);
1543 int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
1544 int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector);
1545 int drm_mode_create_dp_colorspace_property(struct drm_connector *connector);
1546 int drm_mode_create_content_type_property(struct drm_device *dev);
1547 void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame,
1548 					 const struct drm_connector_state *conn_state);
1549 
1550 int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
1551 
1552 int drm_connector_set_path_property(struct drm_connector *connector,
1553 				    const char *path);
1554 int drm_connector_set_tile_property(struct drm_connector *connector);
1555 int drm_connector_update_edid_property(struct drm_connector *connector,
1556 				       const struct edid *edid);
1557 void drm_connector_set_link_status_property(struct drm_connector *connector,
1558 					    uint64_t link_status);
1559 void drm_connector_set_vrr_capable_property(
1560 		struct drm_connector *connector, bool capable);
1561 int drm_connector_init_panel_orientation_property(
1562 	struct drm_connector *connector, int width, int height);
1563 int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
1564 					  int min, int max);
1565 
1566 /**
1567  * struct drm_tile_group - Tile group metadata
1568  * @refcount: reference count
1569  * @dev: DRM device
1570  * @id: tile group id exposed to userspace
1571  * @group_data: Sink-private data identifying this group
1572  *
1573  * @group_data corresponds to displayid vend/prod/serial for external screens
1574  * with an EDID.
1575  */
1576 struct drm_tile_group {
1577 	struct kref refcount;
1578 	struct drm_device *dev;
1579 	int id;
1580 	u8 group_data[8];
1581 };
1582 
1583 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1584 						  char topology[8]);
1585 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1586 					       char topology[8]);
1587 void drm_mode_put_tile_group(struct drm_device *dev,
1588 			     struct drm_tile_group *tg);
1589 
1590 /**
1591  * struct drm_connector_list_iter - connector_list iterator
1592  *
1593  * This iterator tracks state needed to be able to walk the connector_list
1594  * within struct drm_mode_config. Only use together with
1595  * drm_connector_list_iter_begin(), drm_connector_list_iter_end() and
1596  * drm_connector_list_iter_next() respectively the convenience macro
1597  * drm_for_each_connector_iter().
1598  */
1599 struct drm_connector_list_iter {
1600 /* private: */
1601 	struct drm_device *dev;
1602 	struct drm_connector *conn;
1603 };
1604 
1605 void drm_connector_list_iter_begin(struct drm_device *dev,
1606 				   struct drm_connector_list_iter *iter);
1607 struct drm_connector *
1608 drm_connector_list_iter_next(struct drm_connector_list_iter *iter);
1609 void drm_connector_list_iter_end(struct drm_connector_list_iter *iter);
1610 
1611 bool drm_connector_has_possible_encoder(struct drm_connector *connector,
1612 					struct drm_encoder *encoder);
1613 
1614 /**
1615  * drm_for_each_connector_iter - connector_list iterator macro
1616  * @connector: &struct drm_connector pointer used as cursor
1617  * @iter: &struct drm_connector_list_iter
1618  *
1619  * Note that @connector is only valid within the list body, if you want to use
1620  * @connector after calling drm_connector_list_iter_end() then you need to grab
1621  * your own reference first using drm_connector_get().
1622  */
1623 #define drm_for_each_connector_iter(connector, iter) \
1624 	while ((connector = drm_connector_list_iter_next(iter)))
1625 
1626 /**
1627  * drm_connector_for_each_possible_encoder - iterate connector's possible encoders
1628  * @connector: &struct drm_connector pointer
1629  * @encoder: &struct drm_encoder pointer used as cursor
1630  * @__i: int iteration cursor, for macro-internal use
1631  */
1632 #define drm_connector_for_each_possible_encoder(connector, encoder, __i) \
1633 	for ((__i) = 0; (__i) < ARRAY_SIZE((connector)->encoder_ids) && \
1634 		     (connector)->encoder_ids[(__i)] != 0; (__i)++) \
1635 		for_each_if((encoder) = \
1636 			    drm_encoder_find((connector)->dev, NULL, \
1637 					     (connector)->encoder_ids[(__i)])) \
1638 
1639 #endif
1640