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