blob: f8b766d70a46390c57c58e28328acc8dafe6e004 [file] [log] [blame]
Daniel Vetter52217192016-08-12 22:48:50 +02001/*
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>
Daniel Vetter949619f2016-08-29 10:27:51 +020028#include <drm/drm_mode_object.h>
Daniel Vetter52217192016-08-12 22:48:50 +020029
Daniel Vetter199e4e92016-08-31 18:09:05 +020030#include <uapi/drm/drm_mode.h>
31
32struct drm_device;
33
Daniel Vetter52217192016-08-12 22:48:50 +020034struct drm_connector_helper_funcs;
35struct drm_device;
36struct drm_crtc;
37struct drm_encoder;
38struct drm_property;
39struct drm_property_blob;
Rob Clarkfceffb322016-11-05 11:08:09 -040040struct drm_printer;
Daniel Vetter52217192016-08-12 22:48:50 +020041struct 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
Daniel Vetterae2a6da2016-08-12 22:48:53 +020050/**
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 */
Daniel Vetter52217192016-08-12 22:48:50 +020056enum drm_connector_status {
Daniel Vetterae2a6da2016-08-12 22:48:53 +020057 /**
58 * @connector_status_connected: The connector is definitely connected to
59 * a sink device, and can be enabled.
60 */
Daniel Vetter52217192016-08-12 22:48:50 +020061 connector_status_connected = 1,
Daniel Vetterae2a6da2016-08-12 22:48:53 +020062 /**
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 */
Daniel Vetter52217192016-08-12 22:48:50 +020069 connector_status_disconnected = 2,
Daniel Vetterae2a6da2016-08-12 22:48:53 +020070 /**
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 */
Daniel Vetter52217192016-08-12 22:48:50 +020080 connector_status_unknown = 3,
81};
82
83enum subpixel_order {
84 SubPixelUnknown = 0,
85 SubPixelHorizontalRGB,
86 SubPixelHorizontalBGR,
87 SubPixelVerticalRGB,
88 SubPixelVerticalBGR,
89 SubPixelNone,
Shashank Sharmaafa1c762017-03-13 16:54:01 +053090
91};
92
Shashank Sharma62c58af2017-03-13 16:54:02 +053093/**
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
Shashank Sharmaafa1c762017-03-13 16:54:01 +0530107/*
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;
Shashank Sharma62c58af2017-03-13 16:54:02 +0530122 /**
123 * @scrambling: sink's scrambling capabilities
124 */
125 struct drm_scrambling scrambling;
Shashank Sharmaafa1c762017-03-13 16:54:01 +0530126};
127
Shashank Sharma62c58af2017-03-13 16:54:02 +0530128
Shashank Sharmaafa1c762017-03-13 16:54:01 +0530129/**
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 {
136 struct drm_scdc scdc;
Daniel Vetter52217192016-08-12 22:48:50 +0200137};
138
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200139/**
Manasi Navare40ee6fb2016-12-16 12:29:06 +0200140 * enum drm_link_status - connector's link_status property value
141 *
142 * This enum is used as the connector's link status property value.
143 * It is set to the values defined in uapi.
Manasi Navare41232c12017-03-01 06:45:10 -0800144 *
145 * @DRM_LINK_STATUS_GOOD: DP Link is Good as a result of successful
146 * link training
147 * @DRM_LINK_STATUS_BAD: DP Link is BAD as a result of link training
148 * failure
Manasi Navare40ee6fb2016-12-16 12:29:06 +0200149 */
150enum drm_link_status {
151 DRM_LINK_STATUS_GOOD = DRM_MODE_LINK_STATUS_GOOD,
152 DRM_LINK_STATUS_BAD = DRM_MODE_LINK_STATUS_BAD,
153};
154
155/**
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200156 * struct drm_display_info - runtime data about the connected sink
157 *
158 * Describes a given display (e.g. CRT or flat panel) and its limitations. For
159 * fixed display sinks like built-in panels there's not much difference between
Daniel Vetterea0dd852016-12-29 21:48:26 +0100160 * this and &struct drm_connector. But for sinks with a real cable this
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200161 * structure is meant to describe all the things at the other end of the cable.
162 *
163 * For sinks which provide an EDID this can be filled out by calling
164 * drm_add_edid_modes().
Daniel Vetter52217192016-08-12 22:48:50 +0200165 */
166struct drm_display_info {
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200167 /**
168 * @name: Name of the display.
169 */
Daniel Vetter52217192016-08-12 22:48:50 +0200170 char name[DRM_DISPLAY_INFO_LEN];
171
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200172 /**
173 * @width_mm: Physical width in mm.
174 */
Daniel Vetter52217192016-08-12 22:48:50 +0200175 unsigned int width_mm;
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200176 /**
177 * @height_mm: Physical height in mm.
178 */
Daniel Vetter52217192016-08-12 22:48:50 +0200179 unsigned int height_mm;
180
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200181 /**
182 * @pixel_clock: Maximum pixel clock supported by the sink, in units of
Peter Meerwald-Stadler188f78822016-12-16 14:24:23 +0100183 * 100Hz. This mismatches the clock in &drm_display_mode (which is in
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200184 * kHZ), because that's what the EDID uses as base unit.
185 */
Daniel Vetter52217192016-08-12 22:48:50 +0200186 unsigned int pixel_clock;
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200187 /**
188 * @bpc: Maximum bits per color channel. Used by HDMI and DP outputs.
189 */
Daniel Vetter52217192016-08-12 22:48:50 +0200190 unsigned int bpc;
191
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200192 /**
193 * @subpixel_order: Subpixel order of LCD panels.
194 */
Daniel Vetter52217192016-08-12 22:48:50 +0200195 enum subpixel_order subpixel_order;
196
197#define DRM_COLOR_FORMAT_RGB444 (1<<0)
198#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
199#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
200
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200201 /**
202 * @color_formats: HDMI Color formats, selects between RGB and YCrCb
203 * modes. Used DRM_COLOR_FORMAT\_ defines, which are _not_ the same ones
204 * as used to describe the pixel format in framebuffers, and also don't
205 * match the formats in @bus_formats which are shared with v4l.
206 */
Daniel Vetter52217192016-08-12 22:48:50 +0200207 u32 color_formats;
208
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200209 /**
210 * @bus_formats: Pixel data format on the wire, somewhat redundant with
211 * @color_formats. Array of size @num_bus_formats encoded using
212 * MEDIA_BUS_FMT\_ defines shared with v4l and media drivers.
213 */
Daniel Vetter52217192016-08-12 22:48:50 +0200214 const u32 *bus_formats;
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200215 /**
216 * @num_bus_formats: Size of @bus_formats array.
217 */
Daniel Vetter52217192016-08-12 22:48:50 +0200218 unsigned int num_bus_formats;
219
220#define DRM_BUS_FLAG_DE_LOW (1<<0)
221#define DRM_BUS_FLAG_DE_HIGH (1<<1)
222/* drive data on pos. edge */
223#define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
224/* drive data on neg. edge */
225#define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
226
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200227 /**
228 * @bus_flags: Additional information (like pixel signal polarity) for
229 * the pixel data on the bus, using DRM_BUS_FLAGS\_ defines.
230 */
Daniel Vetter52217192016-08-12 22:48:50 +0200231 u32 bus_flags;
232
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200233 /**
Ville Syrjälä2a272ca2016-09-28 16:51:37 +0300234 * @max_tmds_clock: Maximum TMDS clock rate supported by the
235 * sink in kHz. 0 means undefined.
236 */
237 int max_tmds_clock;
238
239 /**
240 * @dvi_dual: Dual-link DVI sink?
241 */
242 bool dvi_dual;
243
244 /**
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200245 * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even
246 * more stuff redundant with @bus_formats.
247 */
Daniel Vetter52217192016-08-12 22:48:50 +0200248 u8 edid_hdmi_dc_modes;
249
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200250 /**
251 * @cea_rev: CEA revision of the HDMI sink.
252 */
Daniel Vetter52217192016-08-12 22:48:50 +0200253 u8 cea_rev;
Shashank Sharmaafa1c762017-03-13 16:54:01 +0530254
255 /**
256 * @hdmi: advance features of a HDMI sink.
257 */
258 struct drm_hdmi_info hdmi;
Daniel Vetter52217192016-08-12 22:48:50 +0200259};
260
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +0200261int drm_display_info_set_bus_formats(struct drm_display_info *info,
262 const u32 *formats,
263 unsigned int num_formats);
264
Daniel Vetter52217192016-08-12 22:48:50 +0200265/**
Boris Brezillon299a16b2016-12-02 14:48:09 +0100266 * struct drm_tv_connector_state - TV connector related states
267 * @subconnector: selected subconnector
268 * @margins: left/right/top/bottom margins
269 * @mode: TV mode
270 * @brightness: brightness in percent
271 * @contrast: contrast in percent
272 * @flicker_reduction: flicker reduction in percent
273 * @overscan: overscan in percent
274 * @saturation: saturation in percent
275 * @hue: hue in percent
276 */
277struct drm_tv_connector_state {
278 enum drm_mode_subconnector subconnector;
279 struct {
280 unsigned int left;
281 unsigned int right;
282 unsigned int top;
283 unsigned int bottom;
284 } margins;
285 unsigned int mode;
286 unsigned int brightness;
287 unsigned int contrast;
288 unsigned int flicker_reduction;
289 unsigned int overscan;
290 unsigned int saturation;
291 unsigned int hue;
292};
293
294/**
Daniel Vetter52217192016-08-12 22:48:50 +0200295 * struct drm_connector_state - mutable connector state
296 * @connector: backpointer to the connector
Daniel Vetter52217192016-08-12 22:48:50 +0200297 * @best_encoder: can be used by helpers and drivers to select the encoder
298 * @state: backpointer to global drm_atomic_state
Boris Brezillon299a16b2016-12-02 14:48:09 +0100299 * @tv: TV connector state
Daniel Vetter52217192016-08-12 22:48:50 +0200300 */
301struct drm_connector_state {
302 struct drm_connector *connector;
303
Daniel Vetterafb21ea62016-08-31 18:09:04 +0200304 /**
305 * @crtc: CRTC to connect connector to, NULL if disabled.
306 *
307 * Do not change this directly, use drm_atomic_set_crtc_for_connector()
308 * instead.
309 */
310 struct drm_crtc *crtc;
Daniel Vetter52217192016-08-12 22:48:50 +0200311
312 struct drm_encoder *best_encoder;
313
Manasi Navare40ee6fb2016-12-16 12:29:06 +0200314 /**
315 * @link_status: Connector link_status to keep track of whether link is
316 * GOOD or BAD to notify userspace if retraining is necessary.
317 */
318 enum drm_link_status link_status;
319
Daniel Vetter52217192016-08-12 22:48:50 +0200320 struct drm_atomic_state *state;
Boris Brezillon299a16b2016-12-02 14:48:09 +0100321
322 struct drm_tv_connector_state tv;
Daniel Vetter52217192016-08-12 22:48:50 +0200323};
324
325/**
326 * struct drm_connector_funcs - control connectors on a given device
327 *
328 * Each CRTC may have one or more connectors attached to it. The functions
329 * below allow the core DRM code to control connectors, enumerate available modes,
330 * etc.
331 */
332struct drm_connector_funcs {
333 /**
334 * @dpms:
335 *
336 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
337 * is exposed as a standard property on the connector, but diverted to
338 * this callback in the drm core. Note that atomic drivers don't
339 * implement the 4 level DPMS support on the connector any more, but
340 * instead only have an on/off "ACTIVE" property on the CRTC object.
341 *
342 * Drivers implementing atomic modeset should use
343 * drm_atomic_helper_connector_dpms() to implement this hook.
344 *
345 * RETURNS:
346 *
347 * 0 on success or a negative error code on failure.
348 */
349 int (*dpms)(struct drm_connector *connector, int mode);
350
351 /**
352 * @reset:
353 *
354 * Reset connector hardware and software state to off. This function isn't
355 * called by the core directly, only through drm_mode_config_reset().
356 * It's not a helper hook only for historical reasons.
357 *
358 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
359 * atomic state using this hook.
360 */
361 void (*reset)(struct drm_connector *connector);
362
363 /**
364 * @detect:
365 *
366 * Check to see if anything is attached to the connector. The parameter
367 * force is set to false whilst polling, true when checking the
368 * connector due to a user request. force can be used by the driver to
369 * avoid expensive, destructive operations during automated probing.
370 *
Laurent Pinchart949f0882016-11-29 22:56:30 +0200371 * This callback is optional, if not implemented the connector will be
372 * considered as always being attached.
373 *
Daniel Vetter52217192016-08-12 22:48:50 +0200374 * FIXME:
375 *
376 * Note that this hook is only called by the probe helper. It's not in
377 * the helper library vtable purely for historical reasons. The only DRM
378 * core entry point to probe connector state is @fill_modes.
379 *
380 * RETURNS:
381 *
382 * drm_connector_status indicating the connector's status.
383 */
384 enum drm_connector_status (*detect)(struct drm_connector *connector,
385 bool force);
386
387 /**
388 * @force:
389 *
390 * This function is called to update internal encoder state when the
391 * connector is forced to a certain state by userspace, either through
392 * the sysfs interfaces or on the kernel cmdline. In that case the
393 * @detect callback isn't called.
394 *
395 * FIXME:
396 *
397 * Note that this hook is only called by the probe helper. It's not in
398 * the helper library vtable purely for historical reasons. The only DRM
399 * core entry point to probe connector state is @fill_modes.
400 */
401 void (*force)(struct drm_connector *connector);
402
403 /**
404 * @fill_modes:
405 *
406 * Entry point for output detection and basic mode validation. The
407 * driver should reprobe the output if needed (e.g. when hotplug
Daniel Vetterd5745282017-01-25 07:26:45 +0100408 * handling is unreliable), add all detected modes to &drm_connector.modes
Daniel Vetter52217192016-08-12 22:48:50 +0200409 * and filter out any the device can't support in any configuration. It
410 * also needs to filter out any modes wider or higher than the
411 * parameters max_width and max_height indicate.
412 *
413 * The drivers must also prune any modes no longer valid from
Daniel Vetterd5745282017-01-25 07:26:45 +0100414 * &drm_connector.modes. Furthermore it must update
415 * &drm_connector.status and &drm_connector.edid. If no EDID has been
416 * received for this output connector->edid must be NULL.
Daniel Vetter52217192016-08-12 22:48:50 +0200417 *
418 * Drivers using the probe helpers should use
419 * drm_helper_probe_single_connector_modes() or
420 * drm_helper_probe_single_connector_modes_nomerge() to implement this
421 * function.
422 *
423 * RETURNS:
424 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100425 * The number of modes detected and filled into &drm_connector.modes.
Daniel Vetter52217192016-08-12 22:48:50 +0200426 */
427 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
428
429 /**
430 * @set_property:
431 *
432 * This is the legacy entry point to update a property attached to the
433 * connector.
434 *
435 * Drivers implementing atomic modeset should use
436 * drm_atomic_helper_connector_set_property() to implement this hook.
437 *
438 * This callback is optional if the driver does not support any legacy
439 * driver-private properties.
440 *
441 * RETURNS:
442 *
443 * 0 on success or a negative error code on failure.
444 */
445 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
446 uint64_t val);
447
448 /**
449 * @late_register:
450 *
451 * This optional hook can be used to register additional userspace
452 * interfaces attached to the connector, light backlight control, i2c,
453 * DP aux or similar interfaces. It is called late in the driver load
454 * sequence from drm_connector_register() when registering all the
455 * core drm connector interfaces. Everything added from this callback
456 * should be unregistered in the early_unregister callback.
457 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100458 * This is called while holding &drm_connector.mutex.
Daniel Vettere73ab002016-12-18 14:35:45 +0100459 *
Daniel Vetter52217192016-08-12 22:48:50 +0200460 * Returns:
461 *
462 * 0 on success, or a negative error code on failure.
463 */
464 int (*late_register)(struct drm_connector *connector);
465
466 /**
467 * @early_unregister:
468 *
469 * This optional hook should be used to unregister the additional
470 * userspace interfaces attached to the connector from
Grazvydas Ignotas621a9992016-10-09 20:07:00 +0300471 * late_register(). It is called from drm_connector_unregister(),
Daniel Vetter52217192016-08-12 22:48:50 +0200472 * early in the driver unload sequence to disable userspace access
473 * before data structures are torndown.
Daniel Vettere73ab002016-12-18 14:35:45 +0100474 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100475 * This is called while holding &drm_connector.mutex.
Daniel Vetter52217192016-08-12 22:48:50 +0200476 */
477 void (*early_unregister)(struct drm_connector *connector);
478
479 /**
480 * @destroy:
481 *
482 * Clean up connector resources. This is called at driver unload time
483 * through drm_mode_config_cleanup(). It can also be called at runtime
484 * when a connector is being hot-unplugged for drivers that support
485 * connector hotplugging (e.g. DisplayPort MST).
486 */
487 void (*destroy)(struct drm_connector *connector);
488
489 /**
490 * @atomic_duplicate_state:
491 *
492 * Duplicate the current atomic state for this connector and return it.
Grazvydas Ignotas621a9992016-10-09 20:07:00 +0300493 * The core and helpers guarantee that any atomic state duplicated with
Daniel Vetter52217192016-08-12 22:48:50 +0200494 * this hook and still owned by the caller (i.e. not transferred to the
Daniel Vetterd5745282017-01-25 07:26:45 +0100495 * driver by calling &drm_mode_config_funcs.atomic_commit) will be
496 * cleaned up by calling the @atomic_destroy_state hook in this
497 * structure.
Daniel Vetter52217192016-08-12 22:48:50 +0200498 *
Daniel Vetterea0dd852016-12-29 21:48:26 +0100499 * Atomic drivers which don't subclass &struct drm_connector_state should use
Daniel Vetter52217192016-08-12 22:48:50 +0200500 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
501 * state structure to extend it with driver-private state should use
502 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
503 * duplicated in a consistent fashion across drivers.
504 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100505 * It is an error to call this hook before &drm_connector.state has been
Daniel Vetter52217192016-08-12 22:48:50 +0200506 * initialized correctly.
507 *
508 * NOTE:
509 *
510 * If the duplicate state references refcounted resources this hook must
511 * acquire a reference for each of them. The driver must release these
512 * references again in @atomic_destroy_state.
513 *
514 * RETURNS:
515 *
516 * Duplicated atomic state or NULL when the allocation failed.
517 */
518 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
519
520 /**
521 * @atomic_destroy_state:
522 *
523 * Destroy a state duplicated with @atomic_duplicate_state and release
524 * or unreference all resources it references
525 */
526 void (*atomic_destroy_state)(struct drm_connector *connector,
527 struct drm_connector_state *state);
528
529 /**
530 * @atomic_set_property:
531 *
532 * Decode a driver-private property value and store the decoded value
533 * into the passed-in state structure. Since the atomic core decodes all
534 * standardized properties (even for extensions beyond the core set of
535 * properties which might not be implemented by all drivers) this
536 * requires drivers to subclass the state structure.
537 *
538 * Such driver-private properties should really only be implemented for
539 * truly hardware/vendor specific state. Instead it is preferred to
540 * standardize atomic extension and decode the properties used to expose
541 * such an extension in the core.
542 *
543 * Do not call this function directly, use
544 * drm_atomic_connector_set_property() instead.
545 *
546 * This callback is optional if the driver does not support any
547 * driver-private atomic properties.
548 *
549 * NOTE:
550 *
551 * This function is called in the state assembly phase of atomic
552 * modesets, which can be aborted for any reason (including on
553 * userspace's request to just check whether a configuration would be
554 * possible). Drivers MUST NOT touch any persistent state (hardware or
555 * software) or data structures except the passed in @state parameter.
556 *
557 * Also since userspace controls in which order properties are set this
558 * function must not do any input validation (since the state update is
559 * incomplete and hence likely inconsistent). Instead any such input
560 * validation must be done in the various atomic_check callbacks.
561 *
562 * RETURNS:
563 *
564 * 0 if the property has been found, -EINVAL if the property isn't
565 * implemented by the driver (which shouldn't ever happen, the core only
566 * asks for properties attached to this connector). No other validation
567 * is allowed by the driver. The core already checks that the property
568 * value is within the range (integer, valid enum value, ...) the driver
569 * set when registering the property.
570 */
571 int (*atomic_set_property)(struct drm_connector *connector,
572 struct drm_connector_state *state,
573 struct drm_property *property,
574 uint64_t val);
575
576 /**
577 * @atomic_get_property:
578 *
579 * Reads out the decoded driver-private property. This is used to
580 * implement the GETCONNECTOR IOCTL.
581 *
582 * Do not call this function directly, use
583 * drm_atomic_connector_get_property() instead.
584 *
585 * This callback is optional if the driver does not support any
586 * driver-private atomic properties.
587 *
588 * RETURNS:
589 *
590 * 0 on success, -EINVAL if the property isn't implemented by the
591 * driver (which shouldn't ever happen, the core only asks for
592 * properties attached to this connector).
593 */
594 int (*atomic_get_property)(struct drm_connector *connector,
595 const struct drm_connector_state *state,
596 struct drm_property *property,
597 uint64_t *val);
Rob Clarkfceffb322016-11-05 11:08:09 -0400598
599 /**
600 * @atomic_print_state:
601 *
Daniel Vetterea0dd852016-12-29 21:48:26 +0100602 * If driver subclasses &struct drm_connector_state, it should implement
Rob Clarkfceffb322016-11-05 11:08:09 -0400603 * this optional hook for printing additional driver specific state.
604 *
605 * Do not call this directly, use drm_atomic_connector_print_state()
606 * instead.
607 */
608 void (*atomic_print_state)(struct drm_printer *p,
609 const struct drm_connector_state *state);
Daniel Vetter52217192016-08-12 22:48:50 +0200610};
611
612/* mode specified on the command line */
613struct drm_cmdline_mode {
614 bool specified;
615 bool refresh_specified;
616 bool bpp_specified;
617 int xres, yres;
618 int bpp;
619 int refresh;
620 bool rb;
621 bool interlace;
622 bool cvt;
623 bool margins;
624 enum drm_connector_force force;
625};
626
627/**
628 * struct drm_connector - central DRM connector control structure
629 * @dev: parent DRM device
630 * @kdev: kernel device for sysfs attributes
631 * @attr: sysfs attributes
632 * @head: list management
633 * @base: base KMS object
634 * @name: human readable name, can be overwritten by the driver
635 * @connector_type: one of the DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
636 * @connector_type_id: index into connector type enum
637 * @interlace_allowed: can this connector handle interlaced modes?
638 * @doublescan_allowed: can this connector handle doublescan?
639 * @stereo_allowed: can this connector handle stereo modes?
Daniel Vetter52217192016-08-12 22:48:50 +0200640 * @funcs: connector control functions
641 * @edid_blob_ptr: DRM property containing EDID if present
642 * @properties: property tracking for this connector
Daniel Vetter52217192016-08-12 22:48:50 +0200643 * @dpms: current dpms state
644 * @helper_private: mid-layer private data
645 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
646 * @force: a DRM_FORCE_<foo> state for forced mode sets
647 * @override_edid: has the EDID been overwritten through debugfs for testing?
648 * @encoder_ids: valid encoders for this connector
649 * @encoder: encoder driving this connector, if any
650 * @eld: EDID-like data, if present
Daniel Vetter52217192016-08-12 22:48:50 +0200651 * @latency_present: AV delay info from ELD, if found
652 * @video_latency: video latency info from ELD, if found
653 * @audio_latency: audio latency info from ELD, if found
654 * @null_edid_counter: track sinks that give us all zeros for the EDID
655 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
656 * @edid_corrupt: indicates whether the last read EDID was corrupt
657 * @debugfs_entry: debugfs directory for this connector
658 * @state: current atomic state for this connector
659 * @has_tile: is this connector connected to a tiled monitor
660 * @tile_group: tile group for the connected monitor
661 * @tile_is_single_monitor: whether the tile is one monitor housing
662 * @num_h_tile: number of horizontal tiles in the tile group
663 * @num_v_tile: number of vertical tiles in the tile group
664 * @tile_h_loc: horizontal location of this tile
665 * @tile_v_loc: vertical location of this tile
666 * @tile_h_size: horizontal size of this tile.
667 * @tile_v_size: vertical size of this tile.
668 *
669 * Each connector may be connected to one or more CRTCs, or may be clonable by
670 * another connector if they can share a CRTC. Each connector also has a specific
671 * position in the broader display (referred to as a 'screen' though it could
672 * span multiple monitors).
673 */
674struct drm_connector {
675 struct drm_device *dev;
676 struct device *kdev;
677 struct device_attribute *attr;
678 struct list_head head;
679
680 struct drm_mode_object base;
681
682 char *name;
683
684 /**
Daniel Vettere73ab002016-12-18 14:35:45 +0100685 * @mutex: Lock for general connector state, but currently only protects
Daniel Vetterd5745282017-01-25 07:26:45 +0100686 * @registered. Most of the connector state is still protected by
687 * &drm_mode_config.mutex.
Daniel Vettere73ab002016-12-18 14:35:45 +0100688 */
689 struct mutex mutex;
690
691 /**
Daniel Vetter52217192016-08-12 22:48:50 +0200692 * @index: Compacted connector index, which matches the position inside
693 * the mode_config.list for drivers not supporting hot-add/removing. Can
694 * be used as an array index. It is invariant over the lifetime of the
695 * connector.
696 */
697 unsigned index;
698
699 int connector_type;
700 int connector_type_id;
701 bool interlace_allowed;
702 bool doublescan_allowed;
703 bool stereo_allowed;
Daniel Vettere73ab002016-12-18 14:35:45 +0100704 /**
705 * @registered: Is this connector exposed (registered) with userspace?
706 * Protected by @mutex.
707 */
Daniel Vetter52217192016-08-12 22:48:50 +0200708 bool registered;
Daniel Vetter91eefc02016-12-14 00:08:10 +0100709
710 /**
711 * @modes:
712 * Modes available on this connector (from fill_modes() + user).
Daniel Vetterd5745282017-01-25 07:26:45 +0100713 * Protected by &drm_mode_config.mutex.
Daniel Vetter91eefc02016-12-14 00:08:10 +0100714 */
Daniel Vetterd5745282017-01-25 07:26:45 +0100715 struct list_head modes;
Daniel Vetter52217192016-08-12 22:48:50 +0200716
Daniel Vetter91eefc02016-12-14 00:08:10 +0100717 /**
718 * @status:
719 * One of the drm_connector_status enums (connected, not, or unknown).
Daniel Vetterd5745282017-01-25 07:26:45 +0100720 * Protected by &drm_mode_config.mutex.
Daniel Vetter91eefc02016-12-14 00:08:10 +0100721 */
Daniel Vetter52217192016-08-12 22:48:50 +0200722 enum drm_connector_status status;
723
Daniel Vetter91eefc02016-12-14 00:08:10 +0100724 /**
725 * @probed_modes:
726 * These are modes added by probing with DDC or the BIOS, before
Daniel Vetterd5745282017-01-25 07:26:45 +0100727 * filtering is applied. Used by the probe helpers. Protected by
728 * &drm_mode_config.mutex.
Daniel Vetter91eefc02016-12-14 00:08:10 +0100729 */
Daniel Vetter52217192016-08-12 22:48:50 +0200730 struct list_head probed_modes;
731
Daniel Vetterae2a6da2016-08-12 22:48:53 +0200732 /**
733 * @display_info: Display information is filled from EDID information
734 * when a display is detected. For non hot-pluggable displays such as
735 * flat panels in embedded systems, the driver should initialize the
Daniel Vetterd5745282017-01-25 07:26:45 +0100736 * &drm_display_info.width_mm and &drm_display_info.height_mm fields
737 * with the physical size of the display.
Daniel Vetter91eefc02016-12-14 00:08:10 +0100738 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100739 * Protected by &drm_mode_config.mutex.
Daniel Vetterae2a6da2016-08-12 22:48:53 +0200740 */
Daniel Vetter52217192016-08-12 22:48:50 +0200741 struct drm_display_info display_info;
742 const struct drm_connector_funcs *funcs;
743
744 struct drm_property_blob *edid_blob_ptr;
745 struct drm_object_properties properties;
746
747 /**
748 * @path_blob_ptr:
749 *
750 * DRM blob property data for the DP MST path property.
751 */
752 struct drm_property_blob *path_blob_ptr;
753
754 /**
755 * @tile_blob_ptr:
756 *
757 * DRM blob property data for the tile property (used mostly by DP MST).
758 * This is meant for screens which are driven through separate display
759 * pipelines represented by &drm_crtc, which might not be running with
760 * genlocked clocks. For tiled panels which are genlocked, like
761 * dual-link LVDS or dual-link DSI, the driver should try to not expose
762 * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
763 */
764 struct drm_property_blob *tile_blob_ptr;
765
766/* should we poll this connector for connects and disconnects */
767/* hot plug detectable */
768#define DRM_CONNECTOR_POLL_HPD (1 << 0)
769/* poll for connections */
770#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
771/* can cleanly poll for disconnections without flickering the screen */
772/* DACs should rarely do this without a lot of testing */
773#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
774
Daniel Vetterae2a6da2016-08-12 22:48:53 +0200775 /**
776 * @polled:
777 *
778 * Connector polling mode, a combination of
779 *
780 * DRM_CONNECTOR_POLL_HPD
781 * The connector generates hotplug events and doesn't need to be
782 * periodically polled. The CONNECT and DISCONNECT flags must not
783 * be set together with the HPD flag.
784 *
785 * DRM_CONNECTOR_POLL_CONNECT
786 * Periodically poll the connector for connection.
787 *
788 * DRM_CONNECTOR_POLL_DISCONNECT
789 * Periodically poll the connector for disconnection.
790 *
791 * Set to 0 for connectors that don't support connection status
792 * discovery.
793 */
794 uint8_t polled;
Daniel Vetter52217192016-08-12 22:48:50 +0200795
796 /* requested DPMS state */
797 int dpms;
798
799 const struct drm_connector_helper_funcs *helper_private;
800
801 /* forced on connector */
802 struct drm_cmdline_mode cmdline_mode;
803 enum drm_connector_force force;
804 bool override_edid;
805
806#define DRM_CONNECTOR_MAX_ENCODER 3
807 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
808 struct drm_encoder *encoder; /* currently active encoder */
809
810#define MAX_ELD_BYTES 128
811 /* EDID bits */
812 uint8_t eld[MAX_ELD_BYTES];
Daniel Vetter52217192016-08-12 22:48:50 +0200813 bool latency_present[2];
814 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
815 int audio_latency[2];
816 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
817 unsigned bad_edid_counter;
818
819 /* Flag for raw EDID header corruption - used in Displayport
820 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
821 */
822 bool edid_corrupt;
823
824 struct dentry *debugfs_entry;
825
826 struct drm_connector_state *state;
827
828 /* DisplayID bits */
829 bool has_tile;
830 struct drm_tile_group *tile_group;
831 bool tile_is_single_monitor;
832
833 uint8_t num_h_tile, num_v_tile;
834 uint8_t tile_h_loc, tile_v_loc;
835 uint16_t tile_h_size, tile_v_size;
836};
837
838#define obj_to_connector(x) container_of(x, struct drm_connector, base)
839
840int drm_connector_init(struct drm_device *dev,
841 struct drm_connector *connector,
842 const struct drm_connector_funcs *funcs,
843 int connector_type);
844int drm_connector_register(struct drm_connector *connector);
845void drm_connector_unregister(struct drm_connector *connector);
846int drm_mode_connector_attach_encoder(struct drm_connector *connector,
847 struct drm_encoder *encoder);
848
849void drm_connector_cleanup(struct drm_connector *connector);
850static inline unsigned drm_connector_index(struct drm_connector *connector)
851{
852 return connector->index;
853}
854
855/**
856 * drm_connector_lookup - lookup connector object
857 * @dev: DRM device
858 * @id: connector object id
859 *
860 * This function looks up the connector object specified by id
861 * add takes a reference to it.
862 */
863static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
864 uint32_t id)
865{
866 struct drm_mode_object *mo;
867 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
868 return mo ? obj_to_connector(mo) : NULL;
869}
870
871/**
Thierry Redingad093602017-02-28 15:46:39 +0100872 * drm_connector_get - acquire a connector reference
873 * @connector: DRM connector
Daniel Vetter52217192016-08-12 22:48:50 +0200874 *
875 * This function increments the connector's refcount.
876 */
Thierry Redingad093602017-02-28 15:46:39 +0100877static inline void drm_connector_get(struct drm_connector *connector)
Daniel Vetter52217192016-08-12 22:48:50 +0200878{
Thierry Redingad093602017-02-28 15:46:39 +0100879 drm_mode_object_get(&connector->base);
Daniel Vetter52217192016-08-12 22:48:50 +0200880}
881
882/**
Thierry Redingad093602017-02-28 15:46:39 +0100883 * drm_connector_put - release a connector reference
884 * @connector: DRM connector
Daniel Vetter52217192016-08-12 22:48:50 +0200885 *
Thierry Redingad093602017-02-28 15:46:39 +0100886 * This function decrements the connector's reference count and frees the
887 * object if the reference count drops to zero.
888 */
889static inline void drm_connector_put(struct drm_connector *connector)
890{
891 drm_mode_object_put(&connector->base);
892}
893
894/**
895 * drm_connector_reference - acquire a connector reference
896 * @connector: DRM connector
897 *
898 * This is a compatibility alias for drm_connector_get() and should not be
899 * used by new code.
900 */
901static inline void drm_connector_reference(struct drm_connector *connector)
902{
903 drm_connector_get(connector);
904}
905
906/**
907 * drm_connector_unreference - release a connector reference
908 * @connector: DRM connector
909 *
910 * This is a compatibility alias for drm_connector_put() and should not be
911 * used by new code.
Daniel Vetter52217192016-08-12 22:48:50 +0200912 */
913static inline void drm_connector_unreference(struct drm_connector *connector)
914{
Thierry Redingad093602017-02-28 15:46:39 +0100915 drm_connector_put(connector);
Daniel Vetter52217192016-08-12 22:48:50 +0200916}
917
918const char *drm_get_connector_status_name(enum drm_connector_status status);
919const char *drm_get_subpixel_order_name(enum subpixel_order order);
920const char *drm_get_dpms_name(int val);
921const char *drm_get_dvi_i_subconnector_name(int val);
922const char *drm_get_dvi_i_select_name(int val);
923const char *drm_get_tv_subconnector_name(int val);
924const char *drm_get_tv_select_name(int val);
925
926int drm_mode_create_dvi_i_properties(struct drm_device *dev);
927int drm_mode_create_tv_properties(struct drm_device *dev,
928 unsigned int num_modes,
929 const char * const modes[]);
930int drm_mode_create_scaling_mode_property(struct drm_device *dev);
931int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
932int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
933
934int drm_mode_connector_set_path_property(struct drm_connector *connector,
935 const char *path);
936int drm_mode_connector_set_tile_property(struct drm_connector *connector);
937int drm_mode_connector_update_edid_property(struct drm_connector *connector,
938 const struct edid *edid);
Manasi Navare40ee6fb2016-12-16 12:29:06 +0200939void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
940 uint64_t link_status);
Daniel Vetterafb21ea62016-08-31 18:09:04 +0200941
942/**
Daniel Vetter9498c192016-11-14 12:58:24 +0100943 * struct drm_tile_group - Tile group metadata
944 * @refcount: reference count
945 * @dev: DRM device
946 * @id: tile group id exposed to userspace
947 * @group_data: Sink-private data identifying this group
948 *
949 * @group_data corresponds to displayid vend/prod/serial for external screens
950 * with an EDID.
951 */
952struct drm_tile_group {
953 struct kref refcount;
954 struct drm_device *dev;
955 int id;
956 u8 group_data[8];
957};
958
959struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
960 char topology[8]);
961struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
962 char topology[8]);
963void drm_mode_put_tile_group(struct drm_device *dev,
964 struct drm_tile_group *tg);
965
966/**
Daniel Vetterafb21ea62016-08-31 18:09:04 +0200967 * drm_for_each_connector - iterate over all connectors
968 * @connector: the loop cursor
969 * @dev: the DRM device
970 *
971 * Iterate over all connectors of @dev.
Daniel Vetter613051d2016-12-14 00:08:06 +0100972 *
973 * WARNING:
974 *
975 * This iterator is not safe against hotadd/removal of connectors and is
976 * deprecated. Use drm_for_each_connector_iter() instead.
Daniel Vetterafb21ea62016-08-31 18:09:04 +0200977 */
978#define drm_for_each_connector(connector, dev) \
Daniel Vetter347e8902016-12-29 21:48:27 +0100979 list_for_each_entry(connector, &(dev)->mode_config.connector_list, head)
Daniel Vetterafb21ea62016-08-31 18:09:04 +0200980
Daniel Vetter613051d2016-12-14 00:08:06 +0100981/**
982 * struct drm_connector_list_iter - connector_list iterator
983 *
984 * This iterator tracks state needed to be able to walk the connector_list
985 * within struct drm_mode_config. Only use together with
Thierry Redingb982dab2017-02-28 15:46:43 +0100986 * drm_connector_list_iter_begin(), drm_connector_list_iter_end() and
Daniel Vetter613051d2016-12-14 00:08:06 +0100987 * drm_connector_list_iter_next() respectively the convenience macro
988 * drm_for_each_connector_iter().
989 */
990struct drm_connector_list_iter {
991/* private: */
992 struct drm_device *dev;
993 struct drm_connector *conn;
994};
995
Thierry Redingb982dab2017-02-28 15:46:43 +0100996void drm_connector_list_iter_begin(struct drm_device *dev,
997 struct drm_connector_list_iter *iter);
Daniel Vetter613051d2016-12-14 00:08:06 +0100998struct drm_connector *
999drm_connector_list_iter_next(struct drm_connector_list_iter *iter);
Thierry Redingb982dab2017-02-28 15:46:43 +01001000void drm_connector_list_iter_end(struct drm_connector_list_iter *iter);
Daniel Vetter613051d2016-12-14 00:08:06 +01001001
1002/**
1003 * drm_for_each_connector_iter - connector_list iterator macro
Daniel Vetterea0dd852016-12-29 21:48:26 +01001004 * @connector: &struct drm_connector pointer used as cursor
1005 * @iter: &struct drm_connector_list_iter
Daniel Vetter613051d2016-12-14 00:08:06 +01001006 *
1007 * Note that @connector is only valid within the list body, if you want to use
Thierry Redingb982dab2017-02-28 15:46:43 +01001008 * @connector after calling drm_connector_list_iter_end() then you need to grab
1009 * your own reference first using drm_connector_begin().
Daniel Vetter613051d2016-12-14 00:08:06 +01001010 */
1011#define drm_for_each_connector_iter(connector, iter) \
1012 while ((connector = drm_connector_list_iter_next(iter)))
1013
Daniel Vetter52217192016-08-12 22:48:50 +02001014#endif