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