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