xref: /linux/include/drm/drm_connector.h (revision 99a97a8ba9881fc47901ff36b057e5cd0bf06af0)
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/ctype.h>
28 #include <drm/drm_mode_object.h>
29 
30 #include <uapi/drm/drm_mode.h>
31 
32 struct drm_device;
33 
34 struct drm_connector_helper_funcs;
35 struct drm_device;
36 struct drm_crtc;
37 struct drm_encoder;
38 struct drm_property;
39 struct drm_property_blob;
40 struct drm_printer;
41 struct edid;
42 
43 enum drm_connector_force {
44 	DRM_FORCE_UNSPECIFIED,
45 	DRM_FORCE_OFF,
46 	DRM_FORCE_ON,         /* force on analog part normally */
47 	DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
48 };
49 
50 /**
51  * enum drm_connector_status - status for a &drm_connector
52  *
53  * This enum is used to track the connector status. There are no separate
54  * #defines for the uapi!
55  */
56 enum drm_connector_status {
57 	/**
58 	 * @connector_status_connected: The connector is definitely connected to
59 	 * a sink device, and can be enabled.
60 	 */
61 	connector_status_connected = 1,
62 	/**
63 	 * @connector_status_disconnected: The connector isn't connected to a
64 	 * sink device which can be autodetect. For digital outputs like DP or
65 	 * HDMI (which can be realiable probed) this means there's really
66 	 * nothing there. It is driver-dependent whether a connector with this
67 	 * status can be lit up or not.
68 	 */
69 	connector_status_disconnected = 2,
70 	/**
71 	 * @connector_status_unknown: The connector's status could not be
72 	 * reliably detected. This happens when probing would either cause
73 	 * flicker (like load-detection when the connector is in use), or when a
74 	 * hardware resource isn't available (like when load-detection needs a
75 	 * free CRTC). It should be possible to light up the connector with one
76 	 * of the listed fallback modes. For default configuration userspace
77 	 * should only try to light up connectors with unknown status when
78 	 * there's not connector with @connector_status_connected.
79 	 */
80 	connector_status_unknown = 3,
81 };
82 
83 enum subpixel_order {
84 	SubPixelUnknown = 0,
85 	SubPixelHorizontalRGB,
86 	SubPixelHorizontalBGR,
87 	SubPixelVerticalRGB,
88 	SubPixelVerticalBGR,
89 	SubPixelNone,
90 
91 };
92 
93 /**
94  * struct drm_scrambling: sink's scrambling support.
95  */
96 struct drm_scrambling {
97 	/**
98 	 * @supported: scrambling supported for rates > 340 Mhz.
99 	 */
100 	bool supported;
101 	/**
102 	 * @low_rates: scrambling supported for rates <= 340 Mhz.
103 	 */
104 	bool low_rates;
105 };
106 
107 /*
108  * struct drm_scdc - Information about scdc capabilities of a HDMI 2.0 sink
109  *
110  * Provides SCDC register support and capabilities related information on a
111  * HDMI 2.0 sink. In case of a HDMI 1.4 sink, all parameter must be 0.
112  */
113 struct drm_scdc {
114 	/**
115 	 * @supported: status control & data channel present.
116 	 */
117 	bool supported;
118 	/**
119 	 * @read_request: sink is capable of generating scdc read request.
120 	 */
121 	bool read_request;
122 	/**
123 	 * @scrambling: sink's scrambling capabilities
124 	 */
125 	struct drm_scrambling scrambling;
126 };
127 
128 
129 /**
130  * struct drm_hdmi_info - runtime information about the connected HDMI sink
131  *
132  * Describes if a given display supports advanced HDMI 2.0 features.
133  * This information is available in CEA-861-F extension blocks (like HF-VSDB).
134  */
135 struct drm_hdmi_info {
136 	/** @scdc: sink's scdc support and capabilities */
137 	struct drm_scdc scdc;
138 };
139 
140 /**
141  * enum drm_link_status - connector's link_status property value
142  *
143  * This enum is used as the connector's link status property value.
144  * It is set to the values defined in uapi.
145  *
146  * @DRM_LINK_STATUS_GOOD: DP Link is Good as a result of successful
147  *                        link training
148  * @DRM_LINK_STATUS_BAD: DP Link is BAD as a result of link training
149  *                       failure
150  */
151 enum drm_link_status {
152 	DRM_LINK_STATUS_GOOD = DRM_MODE_LINK_STATUS_GOOD,
153 	DRM_LINK_STATUS_BAD = DRM_MODE_LINK_STATUS_BAD,
154 };
155 
156 /**
157  * struct drm_display_info - runtime data about the connected sink
158  *
159  * Describes a given display (e.g. CRT or flat panel) and its limitations. For
160  * fixed display sinks like built-in panels there's not much difference between
161  * this and &struct drm_connector. But for sinks with a real cable this
162  * structure is meant to describe all the things at the other end of the cable.
163  *
164  * For sinks which provide an EDID this can be filled out by calling
165  * drm_add_edid_modes().
166  */
167 struct drm_display_info {
168 	/**
169 	 * @name: Name of the display.
170 	 */
171 	char name[DRM_DISPLAY_INFO_LEN];
172 
173 	/**
174 	 * @width_mm: Physical width in mm.
175 	 */
176         unsigned int width_mm;
177 	/**
178 	 * @height_mm: Physical height in mm.
179 	 */
180 	unsigned int height_mm;
181 
182 	/**
183 	 * @pixel_clock: Maximum pixel clock supported by the sink, in units of
184 	 * 100Hz. This mismatches the clock in &drm_display_mode (which is in
185 	 * kHZ), because that's what the EDID uses as base unit.
186 	 */
187 	unsigned int pixel_clock;
188 	/**
189 	 * @bpc: Maximum bits per color channel. Used by HDMI and DP outputs.
190 	 */
191 	unsigned int bpc;
192 
193 	/**
194 	 * @subpixel_order: Subpixel order of LCD panels.
195 	 */
196 	enum subpixel_order subpixel_order;
197 
198 #define DRM_COLOR_FORMAT_RGB444		(1<<0)
199 #define DRM_COLOR_FORMAT_YCRCB444	(1<<1)
200 #define DRM_COLOR_FORMAT_YCRCB422	(1<<2)
201 
202 	/**
203 	 * @color_formats: HDMI Color formats, selects between RGB and YCrCb
204 	 * modes. Used DRM_COLOR_FORMAT\_ defines, which are _not_ the same ones
205 	 * as used to describe the pixel format in framebuffers, and also don't
206 	 * match the formats in @bus_formats which are shared with v4l.
207 	 */
208 	u32 color_formats;
209 
210 	/**
211 	 * @bus_formats: Pixel data format on the wire, somewhat redundant with
212 	 * @color_formats. Array of size @num_bus_formats encoded using
213 	 * MEDIA_BUS_FMT\_ defines shared with v4l and media drivers.
214 	 */
215 	const u32 *bus_formats;
216 	/**
217 	 * @num_bus_formats: Size of @bus_formats array.
218 	 */
219 	unsigned int num_bus_formats;
220 
221 #define DRM_BUS_FLAG_DE_LOW		(1<<0)
222 #define DRM_BUS_FLAG_DE_HIGH		(1<<1)
223 /* drive data on pos. edge */
224 #define DRM_BUS_FLAG_PIXDATA_POSEDGE	(1<<2)
225 /* drive data on neg. edge */
226 #define DRM_BUS_FLAG_PIXDATA_NEGEDGE	(1<<3)
227 /* data is transmitted MSB to LSB on the bus */
228 #define DRM_BUS_FLAG_DATA_MSB_TO_LSB	(1<<4)
229 /* data is transmitted LSB to MSB on the bus */
230 #define DRM_BUS_FLAG_DATA_LSB_TO_MSB	(1<<5)
231 
232 	/**
233 	 * @bus_flags: Additional information (like pixel signal polarity) for
234 	 * the pixel data on the bus, using DRM_BUS_FLAGS\_ defines.
235 	 */
236 	u32 bus_flags;
237 
238 	/**
239 	 * @max_tmds_clock: Maximum TMDS clock rate supported by the
240 	 * sink in kHz. 0 means undefined.
241 	 */
242 	int max_tmds_clock;
243 
244 	/**
245 	 * @dvi_dual: Dual-link DVI sink?
246 	 */
247 	bool dvi_dual;
248 
249 	/**
250 	 * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even
251 	 * more stuff redundant with @bus_formats.
252 	 */
253 	u8 edid_hdmi_dc_modes;
254 
255 	/**
256 	 * @cea_rev: CEA revision of the HDMI sink.
257 	 */
258 	u8 cea_rev;
259 
260 	/**
261 	 * @hdmi: advance features of a HDMI sink.
262 	 */
263 	struct drm_hdmi_info hdmi;
264 };
265 
266 int drm_display_info_set_bus_formats(struct drm_display_info *info,
267 				     const u32 *formats,
268 				     unsigned int num_formats);
269 
270 /**
271  * struct drm_tv_connector_state - TV connector related states
272  * @subconnector: selected subconnector
273  * @margins: left/right/top/bottom margins
274  * @mode: TV mode
275  * @brightness: brightness in percent
276  * @contrast: contrast in percent
277  * @flicker_reduction: flicker reduction in percent
278  * @overscan: overscan in percent
279  * @saturation: saturation in percent
280  * @hue: hue in percent
281  */
282 struct drm_tv_connector_state {
283 	enum drm_mode_subconnector subconnector;
284 	struct {
285 		unsigned int left;
286 		unsigned int right;
287 		unsigned int top;
288 		unsigned int bottom;
289 	} margins;
290 	unsigned int mode;
291 	unsigned int brightness;
292 	unsigned int contrast;
293 	unsigned int flicker_reduction;
294 	unsigned int overscan;
295 	unsigned int saturation;
296 	unsigned int hue;
297 };
298 
299 /**
300  * struct drm_connector_state - mutable connector state
301  * @connector: backpointer to the connector
302  * @best_encoder: can be used by helpers and drivers to select the encoder
303  * @state: backpointer to global drm_atomic_state
304  * @tv: TV connector state
305  */
306 struct drm_connector_state {
307 	struct drm_connector *connector;
308 
309 	/**
310 	 * @crtc: CRTC to connect connector to, NULL if disabled.
311 	 *
312 	 * Do not change this directly, use drm_atomic_set_crtc_for_connector()
313 	 * instead.
314 	 */
315 	struct drm_crtc *crtc;
316 
317 	struct drm_encoder *best_encoder;
318 
319 	/**
320 	 * @link_status: Connector link_status to keep track of whether link is
321 	 * GOOD or BAD to notify userspace if retraining is necessary.
322 	 */
323 	enum drm_link_status link_status;
324 
325 	struct drm_atomic_state *state;
326 
327 	struct drm_tv_connector_state tv;
328 };
329 
330 /**
331  * struct drm_connector_funcs - control connectors on a given device
332  *
333  * Each CRTC may have one or more connectors attached to it.  The functions
334  * below allow the core DRM code to control connectors, enumerate available modes,
335  * etc.
336  */
337 struct drm_connector_funcs {
338 	/**
339 	 * @dpms:
340 	 *
341 	 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
342 	 * is exposed as a standard property on the connector, but diverted to
343 	 * this callback in the drm core. Note that atomic drivers don't
344 	 * implement the 4 level DPMS support on the connector any more, but
345 	 * instead only have an on/off "ACTIVE" property on the CRTC object.
346 	 *
347 	 * Drivers implementing atomic modeset should use
348 	 * drm_atomic_helper_connector_dpms() to implement this hook.
349 	 *
350 	 * RETURNS:
351 	 *
352 	 * 0 on success or a negative error code on failure.
353 	 */
354 	int (*dpms)(struct drm_connector *connector, int mode);
355 
356 	/**
357 	 * @reset:
358 	 *
359 	 * Reset connector hardware and software state to off. This function isn't
360 	 * called by the core directly, only through drm_mode_config_reset().
361 	 * It's not a helper hook only for historical reasons.
362 	 *
363 	 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
364 	 * atomic state using this hook.
365 	 */
366 	void (*reset)(struct drm_connector *connector);
367 
368 	/**
369 	 * @detect:
370 	 *
371 	 * Check to see if anything is attached to the connector. The parameter
372 	 * force is set to false whilst polling, true when checking the
373 	 * connector due to a user request. force can be used by the driver to
374 	 * avoid expensive, destructive operations during automated probing.
375 	 *
376 	 * This callback is optional, if not implemented the connector will be
377 	 * considered as always being attached.
378 	 *
379 	 * FIXME:
380 	 *
381 	 * Note that this hook is only called by the probe helper. It's not in
382 	 * the helper library vtable purely for historical reasons. The only DRM
383 	 * core	entry point to probe connector state is @fill_modes.
384 	 *
385 	 * RETURNS:
386 	 *
387 	 * drm_connector_status indicating the connector's status.
388 	 */
389 	enum drm_connector_status (*detect)(struct drm_connector *connector,
390 					    bool force);
391 
392 	/**
393 	 * @force:
394 	 *
395 	 * This function is called to update internal encoder state when the
396 	 * connector is forced to a certain state by userspace, either through
397 	 * the sysfs interfaces or on the kernel cmdline. In that case the
398 	 * @detect callback isn't called.
399 	 *
400 	 * FIXME:
401 	 *
402 	 * Note that this hook is only called by the probe helper. It's not in
403 	 * the helper library vtable purely for historical reasons. The only DRM
404 	 * core	entry point to probe connector state is @fill_modes.
405 	 */
406 	void (*force)(struct drm_connector *connector);
407 
408 	/**
409 	 * @fill_modes:
410 	 *
411 	 * Entry point for output detection and basic mode validation. The
412 	 * driver should reprobe the output if needed (e.g. when hotplug
413 	 * handling is unreliable), add all detected modes to &drm_connector.modes
414 	 * and filter out any the device can't support in any configuration. It
415 	 * also needs to filter out any modes wider or higher than the
416 	 * parameters max_width and max_height indicate.
417 	 *
418 	 * The drivers must also prune any modes no longer valid from
419 	 * &drm_connector.modes. Furthermore it must update
420 	 * &drm_connector.status and &drm_connector.edid.  If no EDID has been
421 	 * received for this output connector->edid must be NULL.
422 	 *
423 	 * Drivers using the probe helpers should use
424 	 * drm_helper_probe_single_connector_modes() or
425 	 * drm_helper_probe_single_connector_modes_nomerge() to implement this
426 	 * function.
427 	 *
428 	 * RETURNS:
429 	 *
430 	 * The number of modes detected and filled into &drm_connector.modes.
431 	 */
432 	int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
433 
434 	/**
435 	 * @set_property:
436 	 *
437 	 * This is the legacy entry point to update a property attached to the
438 	 * connector.
439 	 *
440 	 * Drivers implementing atomic modeset should use
441 	 * drm_atomic_helper_connector_set_property() to implement this hook.
442 	 *
443 	 * This callback is optional if the driver does not support any legacy
444 	 * driver-private properties.
445 	 *
446 	 * RETURNS:
447 	 *
448 	 * 0 on success or a negative error code on failure.
449 	 */
450 	int (*set_property)(struct drm_connector *connector, struct drm_property *property,
451 			     uint64_t val);
452 
453 	/**
454 	 * @late_register:
455 	 *
456 	 * This optional hook can be used to register additional userspace
457 	 * interfaces attached to the connector, light backlight control, i2c,
458 	 * DP aux or similar interfaces. It is called late in the driver load
459 	 * sequence from drm_connector_register() when registering all the
460 	 * core drm connector interfaces. Everything added from this callback
461 	 * should be unregistered in the early_unregister callback.
462 	 *
463 	 * This is called while holding &drm_connector.mutex.
464 	 *
465 	 * Returns:
466 	 *
467 	 * 0 on success, or a negative error code on failure.
468 	 */
469 	int (*late_register)(struct drm_connector *connector);
470 
471 	/**
472 	 * @early_unregister:
473 	 *
474 	 * This optional hook should be used to unregister the additional
475 	 * userspace interfaces attached to the connector from
476 	 * late_register(). It is called from drm_connector_unregister(),
477 	 * early in the driver unload sequence to disable userspace access
478 	 * before data structures are torndown.
479 	 *
480 	 * This is called while holding &drm_connector.mutex.
481 	 */
482 	void (*early_unregister)(struct drm_connector *connector);
483 
484 	/**
485 	 * @destroy:
486 	 *
487 	 * Clean up connector resources. This is called at driver unload time
488 	 * through drm_mode_config_cleanup(). It can also be called at runtime
489 	 * when a connector is being hot-unplugged for drivers that support
490 	 * connector hotplugging (e.g. DisplayPort MST).
491 	 */
492 	void (*destroy)(struct drm_connector *connector);
493 
494 	/**
495 	 * @atomic_duplicate_state:
496 	 *
497 	 * Duplicate the current atomic state for this connector and return it.
498 	 * The core and helpers guarantee that any atomic state duplicated with
499 	 * this hook and still owned by the caller (i.e. not transferred to the
500 	 * driver by calling &drm_mode_config_funcs.atomic_commit) will be
501 	 * cleaned up by calling the @atomic_destroy_state hook in this
502 	 * structure.
503 	 *
504 	 * Atomic drivers which don't subclass &struct drm_connector_state should use
505 	 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
506 	 * state structure to extend it with driver-private state should use
507 	 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
508 	 * duplicated in a consistent fashion across drivers.
509 	 *
510 	 * It is an error to call this hook before &drm_connector.state has been
511 	 * initialized correctly.
512 	 *
513 	 * NOTE:
514 	 *
515 	 * If the duplicate state references refcounted resources this hook must
516 	 * acquire a reference for each of them. The driver must release these
517 	 * references again in @atomic_destroy_state.
518 	 *
519 	 * RETURNS:
520 	 *
521 	 * Duplicated atomic state or NULL when the allocation failed.
522 	 */
523 	struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
524 
525 	/**
526 	 * @atomic_destroy_state:
527 	 *
528 	 * Destroy a state duplicated with @atomic_duplicate_state and release
529 	 * or unreference all resources it references
530 	 */
531 	void (*atomic_destroy_state)(struct drm_connector *connector,
532 				     struct drm_connector_state *state);
533 
534 	/**
535 	 * @atomic_set_property:
536 	 *
537 	 * Decode a driver-private property value and store the decoded value
538 	 * into the passed-in state structure. Since the atomic core decodes all
539 	 * standardized properties (even for extensions beyond the core set of
540 	 * properties which might not be implemented by all drivers) this
541 	 * requires drivers to subclass the state structure.
542 	 *
543 	 * Such driver-private properties should really only be implemented for
544 	 * truly hardware/vendor specific state. Instead it is preferred to
545 	 * standardize atomic extension and decode the properties used to expose
546 	 * such an extension in the core.
547 	 *
548 	 * Do not call this function directly, use
549 	 * drm_atomic_connector_set_property() instead.
550 	 *
551 	 * This callback is optional if the driver does not support any
552 	 * driver-private atomic properties.
553 	 *
554 	 * NOTE:
555 	 *
556 	 * This function is called in the state assembly phase of atomic
557 	 * modesets, which can be aborted for any reason (including on
558 	 * userspace's request to just check whether a configuration would be
559 	 * possible). Drivers MUST NOT touch any persistent state (hardware or
560 	 * software) or data structures except the passed in @state parameter.
561 	 *
562 	 * Also since userspace controls in which order properties are set this
563 	 * function must not do any input validation (since the state update is
564 	 * incomplete and hence likely inconsistent). Instead any such input
565 	 * validation must be done in the various atomic_check callbacks.
566 	 *
567 	 * RETURNS:
568 	 *
569 	 * 0 if the property has been found, -EINVAL if the property isn't
570 	 * implemented by the driver (which shouldn't ever happen, the core only
571 	 * asks for properties attached to this connector). No other validation
572 	 * is allowed by the driver. The core already checks that the property
573 	 * value is within the range (integer, valid enum value, ...) the driver
574 	 * set when registering the property.
575 	 */
576 	int (*atomic_set_property)(struct drm_connector *connector,
577 				   struct drm_connector_state *state,
578 				   struct drm_property *property,
579 				   uint64_t val);
580 
581 	/**
582 	 * @atomic_get_property:
583 	 *
584 	 * Reads out the decoded driver-private property. This is used to
585 	 * implement the GETCONNECTOR IOCTL.
586 	 *
587 	 * Do not call this function directly, use
588 	 * drm_atomic_connector_get_property() instead.
589 	 *
590 	 * This callback is optional if the driver does not support any
591 	 * driver-private atomic properties.
592 	 *
593 	 * RETURNS:
594 	 *
595 	 * 0 on success, -EINVAL if the property isn't implemented by the
596 	 * driver (which shouldn't ever happen, the core only asks for
597 	 * properties attached to this connector).
598 	 */
599 	int (*atomic_get_property)(struct drm_connector *connector,
600 				   const struct drm_connector_state *state,
601 				   struct drm_property *property,
602 				   uint64_t *val);
603 
604 	/**
605 	 * @atomic_print_state:
606 	 *
607 	 * If driver subclasses &struct drm_connector_state, it should implement
608 	 * this optional hook for printing additional driver specific state.
609 	 *
610 	 * Do not call this directly, use drm_atomic_connector_print_state()
611 	 * instead.
612 	 */
613 	void (*atomic_print_state)(struct drm_printer *p,
614 				   const struct drm_connector_state *state);
615 };
616 
617 /* mode specified on the command line */
618 struct drm_cmdline_mode {
619 	bool specified;
620 	bool refresh_specified;
621 	bool bpp_specified;
622 	int xres, yres;
623 	int bpp;
624 	int refresh;
625 	bool rb;
626 	bool interlace;
627 	bool cvt;
628 	bool margins;
629 	enum drm_connector_force force;
630 };
631 
632 /**
633  * struct drm_connector - central DRM connector control structure
634  * @dev: parent DRM device
635  * @kdev: kernel device for sysfs attributes
636  * @attr: sysfs attributes
637  * @head: list management
638  * @base: base KMS object
639  * @name: human readable name, can be overwritten by the driver
640  * @connector_type: one of the DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
641  * @connector_type_id: index into connector type enum
642  * @interlace_allowed: can this connector handle interlaced modes?
643  * @doublescan_allowed: can this connector handle doublescan?
644  * @stereo_allowed: can this connector handle stereo modes?
645  * @funcs: connector control functions
646  * @edid_blob_ptr: DRM property containing EDID if present
647  * @properties: property tracking for this connector
648  * @dpms: current dpms state
649  * @helper_private: mid-layer private data
650  * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
651  * @force: a DRM_FORCE_<foo> state for forced mode sets
652  * @override_edid: has the EDID been overwritten through debugfs for testing?
653  * @encoder_ids: valid encoders for this connector
654  * @encoder: encoder driving this connector, if any
655  * @eld: EDID-like data, if present
656  * @latency_present: AV delay info from ELD, if found
657  * @video_latency: video latency info from ELD, if found
658  * @audio_latency: audio latency info from ELD, if found
659  * @null_edid_counter: track sinks that give us all zeros for the EDID
660  * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
661  * @edid_corrupt: indicates whether the last read EDID was corrupt
662  * @debugfs_entry: debugfs directory for this connector
663  * @has_tile: is this connector connected to a tiled monitor
664  * @tile_group: tile group for the connected monitor
665  * @tile_is_single_monitor: whether the tile is one monitor housing
666  * @num_h_tile: number of horizontal tiles in the tile group
667  * @num_v_tile: number of vertical tiles in the tile group
668  * @tile_h_loc: horizontal location of this tile
669  * @tile_v_loc: vertical location of this tile
670  * @tile_h_size: horizontal size of this tile.
671  * @tile_v_size: vertical size of this tile.
672  *
673  * Each connector may be connected to one or more CRTCs, or may be clonable by
674  * another connector if they can share a CRTC.  Each connector also has a specific
675  * position in the broader display (referred to as a 'screen' though it could
676  * span multiple monitors).
677  */
678 struct drm_connector {
679 	struct drm_device *dev;
680 	struct device *kdev;
681 	struct device_attribute *attr;
682 	struct list_head head;
683 
684 	struct drm_mode_object base;
685 
686 	char *name;
687 
688 	/**
689 	 * @mutex: Lock for general connector state, but currently only protects
690 	 * @registered. Most of the connector state is still protected by
691 	 * &drm_mode_config.mutex.
692 	 */
693 	struct mutex mutex;
694 
695 	/**
696 	 * @index: Compacted connector index, which matches the position inside
697 	 * the mode_config.list for drivers not supporting hot-add/removing. Can
698 	 * be used as an array index. It is invariant over the lifetime of the
699 	 * connector.
700 	 */
701 	unsigned index;
702 
703 	int connector_type;
704 	int connector_type_id;
705 	bool interlace_allowed;
706 	bool doublescan_allowed;
707 	bool stereo_allowed;
708 	/**
709 	 * @registered: Is this connector exposed (registered) with userspace?
710 	 * Protected by @mutex.
711 	 */
712 	bool registered;
713 
714 	/**
715 	 * @modes:
716 	 * Modes available on this connector (from fill_modes() + user).
717 	 * Protected by &drm_mode_config.mutex.
718 	 */
719 	struct list_head modes;
720 
721 	/**
722 	 * @status:
723 	 * One of the drm_connector_status enums (connected, not, or unknown).
724 	 * Protected by &drm_mode_config.mutex.
725 	 */
726 	enum drm_connector_status status;
727 
728 	/**
729 	 * @probed_modes:
730 	 * These are modes added by probing with DDC or the BIOS, before
731 	 * filtering is applied. Used by the probe helpers. Protected by
732 	 * &drm_mode_config.mutex.
733 	 */
734 	struct list_head probed_modes;
735 
736 	/**
737 	 * @display_info: Display information is filled from EDID information
738 	 * when a display is detected. For non hot-pluggable displays such as
739 	 * flat panels in embedded systems, the driver should initialize the
740 	 * &drm_display_info.width_mm and &drm_display_info.height_mm fields
741 	 * with the physical size of the display.
742 	 *
743 	 * Protected by &drm_mode_config.mutex.
744 	 */
745 	struct drm_display_info display_info;
746 	const struct drm_connector_funcs *funcs;
747 
748 	struct drm_property_blob *edid_blob_ptr;
749 	struct drm_object_properties properties;
750 
751 	/**
752 	 * @path_blob_ptr:
753 	 *
754 	 * DRM blob property data for the DP MST path property.
755 	 */
756 	struct drm_property_blob *path_blob_ptr;
757 
758 	/**
759 	 * @tile_blob_ptr:
760 	 *
761 	 * DRM blob property data for the tile property (used mostly by DP MST).
762 	 * This is meant for screens which are driven through separate display
763 	 * pipelines represented by &drm_crtc, which might not be running with
764 	 * genlocked clocks. For tiled panels which are genlocked, like
765 	 * dual-link LVDS or dual-link DSI, the driver should try to not expose
766 	 * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
767 	 */
768 	struct drm_property_blob *tile_blob_ptr;
769 
770 /* should we poll this connector for connects and disconnects */
771 /* hot plug detectable */
772 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
773 /* poll for connections */
774 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
775 /* can cleanly poll for disconnections without flickering the screen */
776 /* DACs should rarely do this without a lot of testing */
777 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
778 
779 	/**
780 	 * @polled:
781 	 *
782 	 * Connector polling mode, a combination of
783 	 *
784 	 * DRM_CONNECTOR_POLL_HPD
785 	 *     The connector generates hotplug events and doesn't need to be
786 	 *     periodically polled. The CONNECT and DISCONNECT flags must not
787 	 *     be set together with the HPD flag.
788 	 *
789 	 * DRM_CONNECTOR_POLL_CONNECT
790 	 *     Periodically poll the connector for connection.
791 	 *
792 	 * DRM_CONNECTOR_POLL_DISCONNECT
793 	 *     Periodically poll the connector for disconnection.
794 	 *
795 	 * Set to 0 for connectors that don't support connection status
796 	 * discovery.
797 	 */
798 	uint8_t polled;
799 
800 	/* requested DPMS state */
801 	int dpms;
802 
803 	const struct drm_connector_helper_funcs *helper_private;
804 
805 	/* forced on connector */
806 	struct drm_cmdline_mode cmdline_mode;
807 	enum drm_connector_force force;
808 	bool override_edid;
809 
810 #define DRM_CONNECTOR_MAX_ENCODER 3
811 	uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
812 	struct drm_encoder *encoder; /* currently active encoder */
813 
814 #define MAX_ELD_BYTES	128
815 	/* EDID bits */
816 	uint8_t eld[MAX_ELD_BYTES];
817 	bool latency_present[2];
818 	int video_latency[2];	/* [0]: progressive, [1]: interlaced */
819 	int audio_latency[2];
820 	int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
821 	unsigned bad_edid_counter;
822 
823 	/* Flag for raw EDID header corruption - used in Displayport
824 	 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
825 	 */
826 	bool edid_corrupt;
827 
828 	struct dentry *debugfs_entry;
829 
830 	/**
831 	 * @state:
832 	 *
833 	 * Current atomic state for this connector.
834 	 *
835 	 * This is protected by @drm_mode_config.connection_mutex. Note that
836 	 * nonblocking atomic commits access the current connector state without
837 	 * taking locks. Either by going through the &struct drm_atomic_state
838 	 * pointers, see for_each_connector_in_state(),
839 	 * for_each_oldnew_connector_in_state(),
840 	 * for_each_old_connector_in_state() and
841 	 * for_each_new_connector_in_state(). Or through careful ordering of
842 	 * atomic commit operations as implemented in the atomic helpers, see
843 	 * &struct drm_crtc_commit.
844 	 */
845 	struct drm_connector_state *state;
846 
847 	/* DisplayID bits */
848 	bool has_tile;
849 	struct drm_tile_group *tile_group;
850 	bool tile_is_single_monitor;
851 
852 	uint8_t num_h_tile, num_v_tile;
853 	uint8_t tile_h_loc, tile_v_loc;
854 	uint16_t tile_h_size, tile_v_size;
855 };
856 
857 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
858 
859 int drm_connector_init(struct drm_device *dev,
860 		       struct drm_connector *connector,
861 		       const struct drm_connector_funcs *funcs,
862 		       int connector_type);
863 int drm_connector_register(struct drm_connector *connector);
864 void drm_connector_unregister(struct drm_connector *connector);
865 int drm_mode_connector_attach_encoder(struct drm_connector *connector,
866 				      struct drm_encoder *encoder);
867 
868 void drm_connector_cleanup(struct drm_connector *connector);
869 static inline unsigned drm_connector_index(struct drm_connector *connector)
870 {
871 	return connector->index;
872 }
873 
874 /**
875  * drm_connector_lookup - lookup connector object
876  * @dev: DRM device
877  * @id: connector object id
878  *
879  * This function looks up the connector object specified by id
880  * add takes a reference to it.
881  */
882 static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
883 		uint32_t id)
884 {
885 	struct drm_mode_object *mo;
886 	mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
887 	return mo ? obj_to_connector(mo) : NULL;
888 }
889 
890 /**
891  * drm_connector_get - acquire a connector reference
892  * @connector: DRM connector
893  *
894  * This function increments the connector's refcount.
895  */
896 static inline void drm_connector_get(struct drm_connector *connector)
897 {
898 	drm_mode_object_get(&connector->base);
899 }
900 
901 /**
902  * drm_connector_put - release a connector reference
903  * @connector: DRM connector
904  *
905  * This function decrements the connector's reference count and frees the
906  * object if the reference count drops to zero.
907  */
908 static inline void drm_connector_put(struct drm_connector *connector)
909 {
910 	drm_mode_object_put(&connector->base);
911 }
912 
913 /**
914  * drm_connector_reference - acquire a connector reference
915  * @connector: DRM connector
916  *
917  * This is a compatibility alias for drm_connector_get() and should not be
918  * used by new code.
919  */
920 static inline void drm_connector_reference(struct drm_connector *connector)
921 {
922 	drm_connector_get(connector);
923 }
924 
925 /**
926  * drm_connector_unreference - release a connector reference
927  * @connector: DRM connector
928  *
929  * This is a compatibility alias for drm_connector_put() and should not be
930  * used by new code.
931  */
932 static inline void drm_connector_unreference(struct drm_connector *connector)
933 {
934 	drm_connector_put(connector);
935 }
936 
937 const char *drm_get_connector_status_name(enum drm_connector_status status);
938 const char *drm_get_subpixel_order_name(enum subpixel_order order);
939 const char *drm_get_dpms_name(int val);
940 const char *drm_get_dvi_i_subconnector_name(int val);
941 const char *drm_get_dvi_i_select_name(int val);
942 const char *drm_get_tv_subconnector_name(int val);
943 const char *drm_get_tv_select_name(int val);
944 
945 int drm_mode_create_dvi_i_properties(struct drm_device *dev);
946 int drm_mode_create_tv_properties(struct drm_device *dev,
947 				  unsigned int num_modes,
948 				  const char * const modes[]);
949 int drm_mode_create_scaling_mode_property(struct drm_device *dev);
950 int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
951 int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
952 
953 int drm_mode_connector_set_path_property(struct drm_connector *connector,
954 					 const char *path);
955 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
956 int drm_mode_connector_update_edid_property(struct drm_connector *connector,
957 					    const struct edid *edid);
958 void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
959 						 uint64_t link_status);
960 
961 /**
962  * struct drm_tile_group - Tile group metadata
963  * @refcount: reference count
964  * @dev: DRM device
965  * @id: tile group id exposed to userspace
966  * @group_data: Sink-private data identifying this group
967  *
968  * @group_data corresponds to displayid vend/prod/serial for external screens
969  * with an EDID.
970  */
971 struct drm_tile_group {
972 	struct kref refcount;
973 	struct drm_device *dev;
974 	int id;
975 	u8 group_data[8];
976 };
977 
978 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
979 						  char topology[8]);
980 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
981 					       char topology[8]);
982 void drm_mode_put_tile_group(struct drm_device *dev,
983 			     struct drm_tile_group *tg);
984 
985 /**
986  * drm_for_each_connector - iterate over all connectors
987  * @connector: the loop cursor
988  * @dev: the DRM device
989  *
990  * Iterate over all connectors of @dev.
991  *
992  * WARNING:
993  *
994  * This iterator is not safe against hotadd/removal of connectors and is
995  * deprecated. Use drm_for_each_connector_iter() instead.
996  */
997 #define drm_for_each_connector(connector, dev) \
998 	list_for_each_entry(connector, &(dev)->mode_config.connector_list, head)
999 
1000 /**
1001  * struct drm_connector_list_iter - connector_list iterator
1002  *
1003  * This iterator tracks state needed to be able to walk the connector_list
1004  * within struct drm_mode_config. Only use together with
1005  * drm_connector_list_iter_begin(), drm_connector_list_iter_end() and
1006  * drm_connector_list_iter_next() respectively the convenience macro
1007  * drm_for_each_connector_iter().
1008  */
1009 struct drm_connector_list_iter {
1010 /* private: */
1011 	struct drm_device *dev;
1012 	struct drm_connector *conn;
1013 };
1014 
1015 void drm_connector_list_iter_begin(struct drm_device *dev,
1016 				   struct drm_connector_list_iter *iter);
1017 struct drm_connector *
1018 drm_connector_list_iter_next(struct drm_connector_list_iter *iter);
1019 void drm_connector_list_iter_end(struct drm_connector_list_iter *iter);
1020 
1021 /**
1022  * drm_for_each_connector_iter - connector_list iterator macro
1023  * @connector: &struct drm_connector pointer used as cursor
1024  * @iter: &struct drm_connector_list_iter
1025  *
1026  * Note that @connector is only valid within the list body, if you want to use
1027  * @connector after calling drm_connector_list_iter_end() then you need to grab
1028  * your own reference first using drm_connector_begin().
1029  */
1030 #define drm_for_each_connector_iter(connector, iter) \
1031 	while ((connector = drm_connector_list_iter_next(iter)))
1032 
1033 #endif
1034