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