2 * Copyright (c) 2016 Intel Corporation
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.
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
23 #ifndef __DRM_CONNECTOR_H__
24 #define __DRM_CONNECTOR_H__
26 #include <linux/list.h>
27 #include <linux/ctype.h>
28 #include <drm/drm_modeset.h>
30 struct drm_connector_helper_funcs;
35 struct drm_property_blob;
38 enum drm_connector_force {
39 DRM_FORCE_UNSPECIFIED,
41 DRM_FORCE_ON, /* force on analog part normally */
42 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
46 * enum drm_connector_status - status for a &drm_connector
48 * This enum is used to track the connector status. There are no separate
49 * #defines for the uapi!
51 enum drm_connector_status {
53 * @connector_status_connected: The connector is definitely connected to
54 * a sink device, and can be enabled.
56 connector_status_connected = 1,
58 * @connector_status_disconnected: The connector isn't connected to a
59 * sink device which can be autodetect. For digital outputs like DP or
60 * HDMI (which can be realiable probed) this means there's really
61 * nothing there. It is driver-dependent whether a connector with this
62 * status can be lit up or not.
64 connector_status_disconnected = 2,
66 * @connector_status_unknown: The connector's status could not be
67 * reliably detected. This happens when probing would either cause
68 * flicker (like load-detection when the connector is in use), or when a
69 * hardware resource isn't available (like when load-detection needs a
70 * free CRTC). It should be possible to light up the connector with one
71 * of the listed fallback modes. For default configuration userspace
72 * should only try to light up connectors with unknown status when
73 * there's not connector with @connector_status_connected.
75 connector_status_unknown = 3,
80 SubPixelHorizontalRGB,
81 SubPixelHorizontalBGR,
88 * Describes a given display (e.g. CRT or flat panel) and its limitations.
90 struct drm_display_info {
91 char name[DRM_DISPLAY_INFO_LEN];
94 unsigned int width_mm;
95 unsigned int height_mm;
97 unsigned int pixel_clock;
100 enum subpixel_order subpixel_order;
102 #define DRM_COLOR_FORMAT_RGB444 (1<<0)
103 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
104 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
108 const u32 *bus_formats;
109 unsigned int num_bus_formats;
111 #define DRM_BUS_FLAG_DE_LOW (1<<0)
112 #define DRM_BUS_FLAG_DE_HIGH (1<<1)
113 /* drive data on pos. edge */
114 #define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
115 /* drive data on neg. edge */
116 #define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
120 /* Mask of supported hdmi deep color modes */
121 u8 edid_hdmi_dc_modes;
127 * struct drm_connector_state - mutable connector state
128 * @connector: backpointer to the connector
129 * @crtc: CRTC to connect connector to, NULL if disabled
130 * @best_encoder: can be used by helpers and drivers to select the encoder
131 * @state: backpointer to global drm_atomic_state
133 struct drm_connector_state {
134 struct drm_connector *connector;
136 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
138 struct drm_encoder *best_encoder;
140 struct drm_atomic_state *state;
144 * struct drm_connector_funcs - control connectors on a given device
146 * Each CRTC may have one or more connectors attached to it. The functions
147 * below allow the core DRM code to control connectors, enumerate available modes,
150 struct drm_connector_funcs {
154 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
155 * is exposed as a standard property on the connector, but diverted to
156 * this callback in the drm core. Note that atomic drivers don't
157 * implement the 4 level DPMS support on the connector any more, but
158 * instead only have an on/off "ACTIVE" property on the CRTC object.
160 * Drivers implementing atomic modeset should use
161 * drm_atomic_helper_connector_dpms() to implement this hook.
165 * 0 on success or a negative error code on failure.
167 int (*dpms)(struct drm_connector *connector, int mode);
172 * Reset connector hardware and software state to off. This function isn't
173 * called by the core directly, only through drm_mode_config_reset().
174 * It's not a helper hook only for historical reasons.
176 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
177 * atomic state using this hook.
179 void (*reset)(struct drm_connector *connector);
184 * Check to see if anything is attached to the connector. The parameter
185 * force is set to false whilst polling, true when checking the
186 * connector due to a user request. force can be used by the driver to
187 * avoid expensive, destructive operations during automated probing.
191 * Note that this hook is only called by the probe helper. It's not in
192 * the helper library vtable purely for historical reasons. The only DRM
193 * core entry point to probe connector state is @fill_modes.
197 * drm_connector_status indicating the connector's status.
199 enum drm_connector_status (*detect)(struct drm_connector *connector,
205 * This function is called to update internal encoder state when the
206 * connector is forced to a certain state by userspace, either through
207 * the sysfs interfaces or on the kernel cmdline. In that case the
208 * @detect callback isn't called.
212 * Note that this hook is only called by the probe helper. It's not in
213 * the helper library vtable purely for historical reasons. The only DRM
214 * core entry point to probe connector state is @fill_modes.
216 void (*force)(struct drm_connector *connector);
221 * Entry point for output detection and basic mode validation. The
222 * driver should reprobe the output if needed (e.g. when hotplug
223 * handling is unreliable), add all detected modes to connector->modes
224 * and filter out any the device can't support in any configuration. It
225 * also needs to filter out any modes wider or higher than the
226 * parameters max_width and max_height indicate.
228 * The drivers must also prune any modes no longer valid from
229 * connector->modes. Furthermore it must update connector->status and
230 * connector->edid. If no EDID has been received for this output
231 * connector->edid must be NULL.
233 * Drivers using the probe helpers should use
234 * drm_helper_probe_single_connector_modes() or
235 * drm_helper_probe_single_connector_modes_nomerge() to implement this
240 * The number of modes detected and filled into connector->modes.
242 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
247 * This is the legacy entry point to update a property attached to the
250 * Drivers implementing atomic modeset should use
251 * drm_atomic_helper_connector_set_property() to implement this hook.
253 * This callback is optional if the driver does not support any legacy
254 * driver-private properties.
258 * 0 on success or a negative error code on failure.
260 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
266 * This optional hook can be used to register additional userspace
267 * interfaces attached to the connector, light backlight control, i2c,
268 * DP aux or similar interfaces. It is called late in the driver load
269 * sequence from drm_connector_register() when registering all the
270 * core drm connector interfaces. Everything added from this callback
271 * should be unregistered in the early_unregister callback.
275 * 0 on success, or a negative error code on failure.
277 int (*late_register)(struct drm_connector *connector);
282 * This optional hook should be used to unregister the additional
283 * userspace interfaces attached to the connector from
284 * late_unregister(). It is called from drm_connector_unregister(),
285 * early in the driver unload sequence to disable userspace access
286 * before data structures are torndown.
288 void (*early_unregister)(struct drm_connector *connector);
293 * Clean up connector resources. This is called at driver unload time
294 * through drm_mode_config_cleanup(). It can also be called at runtime
295 * when a connector is being hot-unplugged for drivers that support
296 * connector hotplugging (e.g. DisplayPort MST).
298 void (*destroy)(struct drm_connector *connector);
301 * @atomic_duplicate_state:
303 * Duplicate the current atomic state for this connector and return it.
304 * The core and helpers gurantee that any atomic state duplicated with
305 * this hook and still owned by the caller (i.e. not transferred to the
306 * driver by calling ->atomic_commit() from struct
307 * &drm_mode_config_funcs) will be cleaned up by calling the
308 * @atomic_destroy_state hook in this structure.
310 * Atomic drivers which don't subclass struct &drm_connector_state should use
311 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
312 * state structure to extend it with driver-private state should use
313 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
314 * duplicated in a consistent fashion across drivers.
316 * It is an error to call this hook before connector->state has been
317 * initialized correctly.
321 * If the duplicate state references refcounted resources this hook must
322 * acquire a reference for each of them. The driver must release these
323 * references again in @atomic_destroy_state.
327 * Duplicated atomic state or NULL when the allocation failed.
329 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
332 * @atomic_destroy_state:
334 * Destroy a state duplicated with @atomic_duplicate_state and release
335 * or unreference all resources it references
337 void (*atomic_destroy_state)(struct drm_connector *connector,
338 struct drm_connector_state *state);
341 * @atomic_set_property:
343 * Decode a driver-private property value and store the decoded value
344 * into the passed-in state structure. Since the atomic core decodes all
345 * standardized properties (even for extensions beyond the core set of
346 * properties which might not be implemented by all drivers) this
347 * requires drivers to subclass the state structure.
349 * Such driver-private properties should really only be implemented for
350 * truly hardware/vendor specific state. Instead it is preferred to
351 * standardize atomic extension and decode the properties used to expose
352 * such an extension in the core.
354 * Do not call this function directly, use
355 * drm_atomic_connector_set_property() instead.
357 * This callback is optional if the driver does not support any
358 * driver-private atomic properties.
362 * This function is called in the state assembly phase of atomic
363 * modesets, which can be aborted for any reason (including on
364 * userspace's request to just check whether a configuration would be
365 * possible). Drivers MUST NOT touch any persistent state (hardware or
366 * software) or data structures except the passed in @state parameter.
368 * Also since userspace controls in which order properties are set this
369 * function must not do any input validation (since the state update is
370 * incomplete and hence likely inconsistent). Instead any such input
371 * validation must be done in the various atomic_check callbacks.
375 * 0 if the property has been found, -EINVAL if the property isn't
376 * implemented by the driver (which shouldn't ever happen, the core only
377 * asks for properties attached to this connector). No other validation
378 * is allowed by the driver. The core already checks that the property
379 * value is within the range (integer, valid enum value, ...) the driver
380 * set when registering the property.
382 int (*atomic_set_property)(struct drm_connector *connector,
383 struct drm_connector_state *state,
384 struct drm_property *property,
388 * @atomic_get_property:
390 * Reads out the decoded driver-private property. This is used to
391 * implement the GETCONNECTOR IOCTL.
393 * Do not call this function directly, use
394 * drm_atomic_connector_get_property() instead.
396 * This callback is optional if the driver does not support any
397 * driver-private atomic properties.
401 * 0 on success, -EINVAL if the property isn't implemented by the
402 * driver (which shouldn't ever happen, the core only asks for
403 * properties attached to this connector).
405 int (*atomic_get_property)(struct drm_connector *connector,
406 const struct drm_connector_state *state,
407 struct drm_property *property,
411 /* mode specified on the command line */
412 struct drm_cmdline_mode {
414 bool refresh_specified;
423 enum drm_connector_force force;
427 * struct drm_connector - central DRM connector control structure
428 * @dev: parent DRM device
429 * @kdev: kernel device for sysfs attributes
430 * @attr: sysfs attributes
431 * @head: list management
432 * @base: base KMS object
433 * @name: human readable name, can be overwritten by the driver
434 * @connector_type: one of the DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
435 * @connector_type_id: index into connector type enum
436 * @interlace_allowed: can this connector handle interlaced modes?
437 * @doublescan_allowed: can this connector handle doublescan?
438 * @stereo_allowed: can this connector handle stereo modes?
439 * @registered: is this connector exposed (registered) with userspace?
440 * @modes: modes available on this connector (from fill_modes() + user)
441 * @status: one of the drm_connector_status enums (connected, not, or unknown)
442 * @probed_modes: list of modes derived directly from the display
443 * @funcs: connector control functions
444 * @edid_blob_ptr: DRM property containing EDID if present
445 * @properties: property tracking for this connector
446 * @dpms: current dpms state
447 * @helper_private: mid-layer private data
448 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
449 * @force: a DRM_FORCE_<foo> state for forced mode sets
450 * @override_edid: has the EDID been overwritten through debugfs for testing?
451 * @encoder_ids: valid encoders for this connector
452 * @encoder: encoder driving this connector, if any
453 * @eld: EDID-like data, if present
454 * @dvi_dual: dual link DVI, if found
455 * @max_tmds_clock: max clock rate, if found
456 * @latency_present: AV delay info from ELD, if found
457 * @video_latency: video latency info from ELD, if found
458 * @audio_latency: audio latency info from ELD, if found
459 * @null_edid_counter: track sinks that give us all zeros for the EDID
460 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
461 * @edid_corrupt: indicates whether the last read EDID was corrupt
462 * @debugfs_entry: debugfs directory for this connector
463 * @state: current atomic state for this connector
464 * @has_tile: is this connector connected to a tiled monitor
465 * @tile_group: tile group for the connected monitor
466 * @tile_is_single_monitor: whether the tile is one monitor housing
467 * @num_h_tile: number of horizontal tiles in the tile group
468 * @num_v_tile: number of vertical tiles in the tile group
469 * @tile_h_loc: horizontal location of this tile
470 * @tile_v_loc: vertical location of this tile
471 * @tile_h_size: horizontal size of this tile.
472 * @tile_v_size: vertical size of this tile.
474 * Each connector may be connected to one or more CRTCs, or may be clonable by
475 * another connector if they can share a CRTC. Each connector also has a specific
476 * position in the broader display (referred to as a 'screen' though it could
477 * span multiple monitors).
479 struct drm_connector {
480 struct drm_device *dev;
482 struct device_attribute *attr;
483 struct list_head head;
485 struct drm_mode_object base;
490 * @index: Compacted connector index, which matches the position inside
491 * the mode_config.list for drivers not supporting hot-add/removing. Can
492 * be used as an array index. It is invariant over the lifetime of the
498 int connector_type_id;
499 bool interlace_allowed;
500 bool doublescan_allowed;
503 struct list_head modes; /* list of modes on this connector */
505 enum drm_connector_status status;
507 /* these are modes added by probing with DDC or the BIOS */
508 struct list_head probed_modes;
511 * @display_info: Display information is filled from EDID information
512 * when a display is detected. For non hot-pluggable displays such as
513 * flat panels in embedded systems, the driver should initialize the
514 * display_info.width_mm and display_info.height_mm fields with the
515 * physical size of the display.
517 struct drm_display_info display_info;
518 const struct drm_connector_funcs *funcs;
520 struct drm_property_blob *edid_blob_ptr;
521 struct drm_object_properties properties;
526 * DRM blob property data for the DP MST path property.
528 struct drm_property_blob *path_blob_ptr;
533 * DRM blob property data for the tile property (used mostly by DP MST).
534 * This is meant for screens which are driven through separate display
535 * pipelines represented by &drm_crtc, which might not be running with
536 * genlocked clocks. For tiled panels which are genlocked, like
537 * dual-link LVDS or dual-link DSI, the driver should try to not expose
538 * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
540 struct drm_property_blob *tile_blob_ptr;
542 /* should we poll this connector for connects and disconnects */
543 /* hot plug detectable */
544 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
545 /* poll for connections */
546 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
547 /* can cleanly poll for disconnections without flickering the screen */
548 /* DACs should rarely do this without a lot of testing */
549 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
554 * Connector polling mode, a combination of
556 * DRM_CONNECTOR_POLL_HPD
557 * The connector generates hotplug events and doesn't need to be
558 * periodically polled. The CONNECT and DISCONNECT flags must not
559 * be set together with the HPD flag.
561 * DRM_CONNECTOR_POLL_CONNECT
562 * Periodically poll the connector for connection.
564 * DRM_CONNECTOR_POLL_DISCONNECT
565 * Periodically poll the connector for disconnection.
567 * Set to 0 for connectors that don't support connection status
572 /* requested DPMS state */
575 const struct drm_connector_helper_funcs *helper_private;
577 /* forced on connector */
578 struct drm_cmdline_mode cmdline_mode;
579 enum drm_connector_force force;
582 #define DRM_CONNECTOR_MAX_ENCODER 3
583 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
584 struct drm_encoder *encoder; /* currently active encoder */
586 #define MAX_ELD_BYTES 128
588 uint8_t eld[MAX_ELD_BYTES];
590 int max_tmds_clock; /* in MHz */
591 bool latency_present[2];
592 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
593 int audio_latency[2];
594 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
595 unsigned bad_edid_counter;
597 /* Flag for raw EDID header corruption - used in Displayport
598 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
602 struct dentry *debugfs_entry;
604 struct drm_connector_state *state;
608 struct drm_tile_group *tile_group;
609 bool tile_is_single_monitor;
611 uint8_t num_h_tile, num_v_tile;
612 uint8_t tile_h_loc, tile_v_loc;
613 uint16_t tile_h_size, tile_v_size;
616 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
618 int drm_connector_init(struct drm_device *dev,
619 struct drm_connector *connector,
620 const struct drm_connector_funcs *funcs,
622 int drm_connector_register(struct drm_connector *connector);
623 void drm_connector_unregister(struct drm_connector *connector);
624 int drm_mode_connector_attach_encoder(struct drm_connector *connector,
625 struct drm_encoder *encoder);
627 void drm_connector_cleanup(struct drm_connector *connector);
628 static inline unsigned drm_connector_index(struct drm_connector *connector)
630 return connector->index;
634 * drm_connector_lookup - lookup connector object
636 * @id: connector object id
638 * This function looks up the connector object specified by id
639 * add takes a reference to it.
641 static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
644 struct drm_mode_object *mo;
645 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
646 return mo ? obj_to_connector(mo) : NULL;
650 * drm_connector_reference - incr the connector refcnt
651 * @connector: connector
653 * This function increments the connector's refcount.
655 static inline void drm_connector_reference(struct drm_connector *connector)
657 drm_mode_object_reference(&connector->base);
661 * drm_connector_unreference - unref a connector
662 * @connector: connector to unref
664 * This function decrements the connector's refcount and frees it if it drops to zero.
666 static inline void drm_connector_unreference(struct drm_connector *connector)
668 drm_mode_object_unreference(&connector->base);
671 const char *drm_get_connector_status_name(enum drm_connector_status status);
672 const char *drm_get_subpixel_order_name(enum subpixel_order order);
673 const char *drm_get_dpms_name(int val);
674 const char *drm_get_dvi_i_subconnector_name(int val);
675 const char *drm_get_dvi_i_select_name(int val);
676 const char *drm_get_tv_subconnector_name(int val);
677 const char *drm_get_tv_select_name(int val);
679 int drm_mode_create_dvi_i_properties(struct drm_device *dev);
680 int drm_mode_create_tv_properties(struct drm_device *dev,
681 unsigned int num_modes,
682 const char * const modes[]);
683 int drm_mode_create_scaling_mode_property(struct drm_device *dev);
684 int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
685 int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
687 int drm_mode_connector_set_path_property(struct drm_connector *connector,
689 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
690 int drm_mode_connector_update_edid_property(struct drm_connector *connector,
691 const struct edid *edid);