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