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 #include <drm/drm_connector.h>
24 #include <drm/drm_edid.h>
25 #include <drm/drm_encoder.h>
26 #include <drm/drm_utils.h>
27 #include <drm/drm_print.h>
28 #include <drm/drm_drv.h>
29 #include <drm/drm_file.h>
31 #include <linux/uaccess.h>
33 #include "drm_crtc_internal.h"
34 #include "drm_internal.h"
39 * In DRM connectors are the general abstraction for display sinks, and include
40 * als fixed panels or anything else that can display pixels in some form. As
41 * opposed to all other KMS objects representing hardware (like CRTC, encoder or
42 * plane abstractions) connectors can be hotplugged and unplugged at runtime.
43 * Hence they are reference-counted using drm_connector_get() and
44 * drm_connector_put().
46 * KMS driver must create, initialize, register and attach at a &struct
47 * drm_connector for each such sink. The instance is created as other KMS
48 * objects and initialized by setting the following fields. The connector is
49 * initialized with a call to drm_connector_init() with a pointer to the
50 * &struct drm_connector_funcs and a connector type, and then exposed to
51 * userspace with a call to drm_connector_register().
53 * Connectors must be attached to an encoder to be used. For devices that map
54 * connectors to encoders 1:1, the connector should be attached at
55 * initialization time with a call to drm_connector_attach_encoder(). The
56 * driver must also set the &drm_connector.encoder field to point to the
59 * For connectors which are not fixed (like built-in panels) the driver needs to
60 * support hotplug notifications. The simplest way to do that is by using the
61 * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
62 * hardware support for hotplug interrupts. Connectors with hardware hotplug
63 * support can instead use e.g. drm_helper_hpd_irq_event().
66 struct drm_conn_prop_enum_list {
73 * Connector and encoder types.
75 static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
76 { DRM_MODE_CONNECTOR_Unknown, "Unknown" },
77 { DRM_MODE_CONNECTOR_VGA, "VGA" },
78 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
79 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
80 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
81 { DRM_MODE_CONNECTOR_Composite, "Composite" },
82 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
83 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
84 { DRM_MODE_CONNECTOR_Component, "Component" },
85 { DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
86 { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
87 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
88 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
89 { DRM_MODE_CONNECTOR_TV, "TV" },
90 { DRM_MODE_CONNECTOR_eDP, "eDP" },
91 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
92 { DRM_MODE_CONNECTOR_DSI, "DSI" },
93 { DRM_MODE_CONNECTOR_DPI, "DPI" },
94 { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
97 void drm_connector_ida_init(void)
101 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
102 ida_init(&drm_connector_enum_list[i].ida);
105 void drm_connector_ida_destroy(void)
109 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
110 ida_destroy(&drm_connector_enum_list[i].ida);
114 * drm_connector_get_cmdline_mode - reads the user's cmdline mode
115 * @connector: connector to quwery
117 * The kernel supports per-connector configuration of its consoles through
118 * use of the video= parameter. This function parses that option and
119 * extracts the user's specified mode (or enable/disable status) for a
120 * particular connector. This is typically only used during the early fbdev
123 static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
125 struct drm_cmdline_mode *mode = &connector->cmdline_mode;
128 if (fb_get_options(connector->name, &option))
131 if (!drm_mode_parse_command_line_for_connector(option,
137 DRM_INFO("forcing %s connector %s\n", connector->name,
138 drm_get_connector_force_name(mode->force));
139 connector->force = mode->force;
142 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
144 mode->xres, mode->yres,
145 mode->refresh_specified ? mode->refresh : 60,
146 mode->rb ? " reduced blanking" : "",
147 mode->margins ? " with margins" : "",
148 mode->interlace ? " interlaced" : "");
151 static void drm_connector_free(struct kref *kref)
153 struct drm_connector *connector =
154 container_of(kref, struct drm_connector, base.refcount);
155 struct drm_device *dev = connector->dev;
157 drm_mode_object_unregister(dev, &connector->base);
158 connector->funcs->destroy(connector);
161 void drm_connector_free_work_fn(struct work_struct *work)
163 struct drm_connector *connector, *n;
164 struct drm_device *dev =
165 container_of(work, struct drm_device, mode_config.connector_free_work);
166 struct drm_mode_config *config = &dev->mode_config;
168 struct llist_node *freed;
170 spin_lock_irqsave(&config->connector_list_lock, flags);
171 freed = llist_del_all(&config->connector_free_list);
172 spin_unlock_irqrestore(&config->connector_list_lock, flags);
174 llist_for_each_entry_safe(connector, n, freed, free_node) {
175 drm_mode_object_unregister(dev, &connector->base);
176 connector->funcs->destroy(connector);
181 * drm_connector_init - Init a preallocated connector
183 * @connector: the connector to init
184 * @funcs: callbacks for this connector
185 * @connector_type: user visible type of the connector
187 * Initialises a preallocated connector. Connectors should be
188 * subclassed as part of driver connector objects.
191 * Zero on success, error code on failure.
193 int drm_connector_init(struct drm_device *dev,
194 struct drm_connector *connector,
195 const struct drm_connector_funcs *funcs,
198 struct drm_mode_config *config = &dev->mode_config;
200 struct ida *connector_ida =
201 &drm_connector_enum_list[connector_type].ida;
203 WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
204 (!funcs->atomic_destroy_state ||
205 !funcs->atomic_duplicate_state));
207 ret = __drm_mode_object_add(dev, &connector->base,
208 DRM_MODE_OBJECT_CONNECTOR,
209 false, drm_connector_free);
213 connector->base.properties = &connector->properties;
214 connector->dev = dev;
215 connector->funcs = funcs;
217 /* connector index is used with 32bit bitmasks */
218 ret = ida_simple_get(&config->connector_ida, 0, 32, GFP_KERNEL);
220 DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
221 drm_connector_enum_list[connector_type].name,
225 connector->index = ret;
228 connector->connector_type = connector_type;
229 connector->connector_type_id =
230 ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
231 if (connector->connector_type_id < 0) {
232 ret = connector->connector_type_id;
236 kasprintf(GFP_KERNEL, "%s-%d",
237 drm_connector_enum_list[connector_type].name,
238 connector->connector_type_id);
239 if (!connector->name) {
241 goto out_put_type_id;
244 INIT_LIST_HEAD(&connector->probed_modes);
245 INIT_LIST_HEAD(&connector->modes);
246 mutex_init(&connector->mutex);
247 connector->edid_blob_ptr = NULL;
248 connector->tile_blob_ptr = NULL;
249 connector->status = connector_status_unknown;
250 connector->display_info.panel_orientation =
251 DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
253 drm_connector_get_cmdline_mode(connector);
255 /* We should add connectors at the end to avoid upsetting the connector
257 spin_lock_irq(&config->connector_list_lock);
258 list_add_tail(&connector->head, &config->connector_list);
259 config->num_connector++;
260 spin_unlock_irq(&config->connector_list_lock);
262 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
263 connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
264 drm_connector_attach_edid_property(connector);
266 drm_object_attach_property(&connector->base,
267 config->dpms_property, 0);
269 drm_object_attach_property(&connector->base,
270 config->link_status_property,
273 drm_object_attach_property(&connector->base,
274 config->non_desktop_property,
276 drm_object_attach_property(&connector->base,
277 config->tile_property,
280 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
281 drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
284 connector->debugfs_entry = NULL;
287 ida_simple_remove(connector_ida, connector->connector_type_id);
290 ida_simple_remove(&config->connector_ida, connector->index);
293 drm_mode_object_unregister(dev, &connector->base);
297 EXPORT_SYMBOL(drm_connector_init);
300 * drm_connector_attach_edid_property - attach edid property.
301 * @connector: the connector
303 * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
304 * edid property attached by default. This function can be used to
305 * explicitly enable the edid property in these cases.
307 void drm_connector_attach_edid_property(struct drm_connector *connector)
309 struct drm_mode_config *config = &connector->dev->mode_config;
311 drm_object_attach_property(&connector->base,
312 config->edid_property,
315 EXPORT_SYMBOL(drm_connector_attach_edid_property);
318 * drm_connector_attach_encoder - attach a connector to an encoder
319 * @connector: connector to attach
320 * @encoder: encoder to attach @connector to
322 * This function links up a connector to an encoder. Note that the routing
323 * restrictions between encoders and crtcs are exposed to userspace through the
324 * possible_clones and possible_crtcs bitmasks.
327 * Zero on success, negative errno on failure.
329 int drm_connector_attach_encoder(struct drm_connector *connector,
330 struct drm_encoder *encoder)
335 * In the past, drivers have attempted to model the static association
336 * of connector to encoder in simple connector/encoder devices using a
337 * direct assignment of connector->encoder = encoder. This connection
338 * is a logical one and the responsibility of the core, so drivers are
339 * expected not to mess with this.
341 * Note that the error return should've been enough here, but a large
342 * majority of drivers ignores the return value, so add in a big WARN
343 * to get people's attention.
345 if (WARN_ON(connector->encoder))
348 for (i = 0; i < ARRAY_SIZE(connector->encoder_ids); i++) {
349 if (connector->encoder_ids[i] == 0) {
350 connector->encoder_ids[i] = encoder->base.id;
356 EXPORT_SYMBOL(drm_connector_attach_encoder);
359 * drm_connector_has_possible_encoder - check if the connector and encoder are assosicated with each other
360 * @connector: the connector
361 * @encoder: the encoder
364 * True if @encoder is one of the possible encoders for @connector.
366 bool drm_connector_has_possible_encoder(struct drm_connector *connector,
367 struct drm_encoder *encoder)
369 struct drm_encoder *enc;
372 drm_connector_for_each_possible_encoder(connector, enc, i) {
379 EXPORT_SYMBOL(drm_connector_has_possible_encoder);
381 static void drm_mode_remove(struct drm_connector *connector,
382 struct drm_display_mode *mode)
384 list_del(&mode->head);
385 drm_mode_destroy(connector->dev, mode);
389 * drm_connector_cleanup - cleans up an initialised connector
390 * @connector: connector to cleanup
392 * Cleans up the connector but doesn't free the object.
394 void drm_connector_cleanup(struct drm_connector *connector)
396 struct drm_device *dev = connector->dev;
397 struct drm_display_mode *mode, *t;
399 /* The connector should have been removed from userspace long before
400 * it is finally destroyed.
402 if (WARN_ON(connector->registration_state ==
403 DRM_CONNECTOR_REGISTERED))
404 drm_connector_unregister(connector);
406 if (connector->tile_group) {
407 drm_mode_put_tile_group(dev, connector->tile_group);
408 connector->tile_group = NULL;
411 list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
412 drm_mode_remove(connector, mode);
414 list_for_each_entry_safe(mode, t, &connector->modes, head)
415 drm_mode_remove(connector, mode);
417 ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida,
418 connector->connector_type_id);
420 ida_simple_remove(&dev->mode_config.connector_ida,
423 kfree(connector->display_info.bus_formats);
424 drm_mode_object_unregister(dev, &connector->base);
425 kfree(connector->name);
426 connector->name = NULL;
427 spin_lock_irq(&dev->mode_config.connector_list_lock);
428 list_del(&connector->head);
429 dev->mode_config.num_connector--;
430 spin_unlock_irq(&dev->mode_config.connector_list_lock);
432 WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
433 if (connector->state && connector->funcs->atomic_destroy_state)
434 connector->funcs->atomic_destroy_state(connector,
437 mutex_destroy(&connector->mutex);
439 memset(connector, 0, sizeof(*connector));
441 EXPORT_SYMBOL(drm_connector_cleanup);
444 * drm_connector_register - register a connector
445 * @connector: the connector to register
447 * Register userspace interfaces for a connector
450 * Zero on success, error code on failure.
452 int drm_connector_register(struct drm_connector *connector)
456 if (!connector->dev->registered)
459 mutex_lock(&connector->mutex);
460 if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
463 ret = drm_sysfs_connector_add(connector);
467 ret = drm_debugfs_connector_add(connector);
472 if (connector->funcs->late_register) {
473 ret = connector->funcs->late_register(connector);
478 drm_mode_object_register(connector->dev, &connector->base);
480 connector->registration_state = DRM_CONNECTOR_REGISTERED;
484 drm_debugfs_connector_remove(connector);
486 drm_sysfs_connector_remove(connector);
488 mutex_unlock(&connector->mutex);
491 EXPORT_SYMBOL(drm_connector_register);
494 * drm_connector_unregister - unregister a connector
495 * @connector: the connector to unregister
497 * Unregister userspace interfaces for a connector
499 void drm_connector_unregister(struct drm_connector *connector)
501 mutex_lock(&connector->mutex);
502 if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
503 mutex_unlock(&connector->mutex);
507 if (connector->funcs->early_unregister)
508 connector->funcs->early_unregister(connector);
510 drm_sysfs_connector_remove(connector);
511 drm_debugfs_connector_remove(connector);
513 connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
514 mutex_unlock(&connector->mutex);
516 EXPORT_SYMBOL(drm_connector_unregister);
518 void drm_connector_unregister_all(struct drm_device *dev)
520 struct drm_connector *connector;
521 struct drm_connector_list_iter conn_iter;
523 drm_connector_list_iter_begin(dev, &conn_iter);
524 drm_for_each_connector_iter(connector, &conn_iter)
525 drm_connector_unregister(connector);
526 drm_connector_list_iter_end(&conn_iter);
529 int drm_connector_register_all(struct drm_device *dev)
531 struct drm_connector *connector;
532 struct drm_connector_list_iter conn_iter;
535 drm_connector_list_iter_begin(dev, &conn_iter);
536 drm_for_each_connector_iter(connector, &conn_iter) {
537 ret = drm_connector_register(connector);
541 drm_connector_list_iter_end(&conn_iter);
544 drm_connector_unregister_all(dev);
549 * drm_get_connector_status_name - return a string for connector status
550 * @status: connector status to compute name of
552 * In contrast to the other drm_get_*_name functions this one here returns a
553 * const pointer and hence is threadsafe.
555 const char *drm_get_connector_status_name(enum drm_connector_status status)
557 if (status == connector_status_connected)
559 else if (status == connector_status_disconnected)
560 return "disconnected";
564 EXPORT_SYMBOL(drm_get_connector_status_name);
567 * drm_get_connector_force_name - return a string for connector force
568 * @force: connector force to get name of
570 * Returns: const pointer to name.
572 const char *drm_get_connector_force_name(enum drm_connector_force force)
575 case DRM_FORCE_UNSPECIFIED:
576 return "unspecified";
581 case DRM_FORCE_ON_DIGITAL:
588 #ifdef CONFIG_LOCKDEP
589 static struct lockdep_map connector_list_iter_dep_map = {
590 .name = "drm_connector_list_iter"
595 * drm_connector_list_iter_begin - initialize a connector_list iterator
597 * @iter: connector_list iterator
599 * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
600 * must always be cleaned up again by calling drm_connector_list_iter_end().
601 * Iteration itself happens using drm_connector_list_iter_next() or
602 * drm_for_each_connector_iter().
604 void drm_connector_list_iter_begin(struct drm_device *dev,
605 struct drm_connector_list_iter *iter)
609 lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
611 EXPORT_SYMBOL(drm_connector_list_iter_begin);
614 * Extra-safe connector put function that works in any context. Should only be
615 * used from the connector_iter functions, where we never really expect to
616 * actually release the connector when dropping our final reference.
619 __drm_connector_put_safe(struct drm_connector *conn)
621 struct drm_mode_config *config = &conn->dev->mode_config;
623 lockdep_assert_held(&config->connector_list_lock);
625 if (!refcount_dec_and_test(&conn->base.refcount.refcount))
628 llist_add(&conn->free_node, &config->connector_free_list);
629 schedule_work(&config->connector_free_work);
633 * drm_connector_list_iter_next - return next connector
634 * @iter: connector_list iterator
636 * Returns the next connector for @iter, or NULL when the list walk has
639 struct drm_connector *
640 drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
642 struct drm_connector *old_conn = iter->conn;
643 struct drm_mode_config *config = &iter->dev->mode_config;
644 struct list_head *lhead;
647 spin_lock_irqsave(&config->connector_list_lock, flags);
648 lhead = old_conn ? &old_conn->head : &config->connector_list;
651 if (lhead->next == &config->connector_list) {
657 iter->conn = list_entry(lhead, struct drm_connector, head);
659 /* loop until it's not a zombie connector */
660 } while (!kref_get_unless_zero(&iter->conn->base.refcount));
663 __drm_connector_put_safe(old_conn);
664 spin_unlock_irqrestore(&config->connector_list_lock, flags);
668 EXPORT_SYMBOL(drm_connector_list_iter_next);
671 * drm_connector_list_iter_end - tear down a connector_list iterator
672 * @iter: connector_list iterator
674 * Tears down @iter and releases any resources (like &drm_connector references)
675 * acquired while walking the list. This must always be called, both when the
676 * iteration completes fully or when it was aborted without walking the entire
679 void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
681 struct drm_mode_config *config = &iter->dev->mode_config;
686 spin_lock_irqsave(&config->connector_list_lock, flags);
687 __drm_connector_put_safe(iter->conn);
688 spin_unlock_irqrestore(&config->connector_list_lock, flags);
690 lock_release(&connector_list_iter_dep_map, 0, _RET_IP_);
692 EXPORT_SYMBOL(drm_connector_list_iter_end);
694 static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
695 { SubPixelUnknown, "Unknown" },
696 { SubPixelHorizontalRGB, "Horizontal RGB" },
697 { SubPixelHorizontalBGR, "Horizontal BGR" },
698 { SubPixelVerticalRGB, "Vertical RGB" },
699 { SubPixelVerticalBGR, "Vertical BGR" },
700 { SubPixelNone, "None" },
704 * drm_get_subpixel_order_name - return a string for a given subpixel enum
705 * @order: enum of subpixel_order
707 * Note you could abuse this and return something out of bounds, but that
708 * would be a caller error. No unscrubbed user data should make it here.
710 const char *drm_get_subpixel_order_name(enum subpixel_order order)
712 return drm_subpixel_enum_list[order].name;
714 EXPORT_SYMBOL(drm_get_subpixel_order_name);
716 static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
717 { DRM_MODE_DPMS_ON, "On" },
718 { DRM_MODE_DPMS_STANDBY, "Standby" },
719 { DRM_MODE_DPMS_SUSPEND, "Suspend" },
720 { DRM_MODE_DPMS_OFF, "Off" }
722 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
724 static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
725 { DRM_MODE_LINK_STATUS_GOOD, "Good" },
726 { DRM_MODE_LINK_STATUS_BAD, "Bad" },
730 * drm_display_info_set_bus_formats - set the supported bus formats
731 * @info: display info to store bus formats in
732 * @formats: array containing the supported bus formats
733 * @num_formats: the number of entries in the fmts array
735 * Store the supported bus formats in display info structure.
736 * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
737 * a full list of available formats.
739 int drm_display_info_set_bus_formats(struct drm_display_info *info,
741 unsigned int num_formats)
745 if (!formats && num_formats)
748 if (formats && num_formats) {
749 fmts = kmemdup(formats, sizeof(*formats) * num_formats,
755 kfree(info->bus_formats);
756 info->bus_formats = fmts;
757 info->num_bus_formats = num_formats;
761 EXPORT_SYMBOL(drm_display_info_set_bus_formats);
763 /* Optional connector properties. */
764 static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
765 { DRM_MODE_SCALE_NONE, "None" },
766 { DRM_MODE_SCALE_FULLSCREEN, "Full" },
767 { DRM_MODE_SCALE_CENTER, "Center" },
768 { DRM_MODE_SCALE_ASPECT, "Full aspect" },
771 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
772 { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
773 { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
774 { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
777 static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
778 { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
779 { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
780 { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
781 { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
782 { DRM_MODE_CONTENT_TYPE_GAME, "Game" },
785 static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
786 { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" },
787 { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" },
788 { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" },
789 { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" },
792 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
793 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
794 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
795 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
797 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
799 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
800 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
801 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
802 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
804 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
805 drm_dvi_i_subconnector_enum_list)
807 static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
808 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
809 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
810 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
811 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
812 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
814 DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
816 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
817 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
818 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
819 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
820 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
821 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
823 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
824 drm_tv_subconnector_enum_list)
826 static const struct drm_prop_enum_list hdmi_colorspaces[] = {
827 /* For Default case, driver will set the colorspace */
828 { DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
829 /* Standard Definition Colorimetry based on CEA 861 */
830 { DRM_MODE_COLORIMETRY_SMPTE_170M_YCC, "SMPTE_170M_YCC" },
831 { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
832 /* Standard Definition Colorimetry based on IEC 61966-2-4 */
833 { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
834 /* High Definition Colorimetry based on IEC 61966-2-4 */
835 { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
836 /* Colorimetry based on IEC 61966-2-1/Amendment 1 */
837 { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
838 /* Colorimetry based on IEC 61966-2-5 [33] */
839 { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
840 /* Colorimetry based on IEC 61966-2-5 */
841 { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
842 /* Colorimetry based on ITU-R BT.2020 */
843 { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
844 /* Colorimetry based on ITU-R BT.2020 */
845 { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
846 /* Colorimetry based on ITU-R BT.2020 */
847 { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
848 /* Added as part of Additional Colorimetry Extension in 861.G */
849 { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
850 { DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, "DCI-P3_RGB_Theater" },
854 * DOC: standard connector properties
856 * DRM connectors have a few standardized properties:
859 * Blob property which contains the current EDID read from the sink. This
860 * is useful to parse sink identification information like vendor, model
861 * and serial. Drivers should update this property by calling
862 * drm_connector_update_edid_property(), usually after having parsed
863 * the EDID using drm_add_edid_modes(). Userspace cannot change this
866 * Legacy property for setting the power state of the connector. For atomic
867 * drivers this is only provided for backwards compatibility with existing
868 * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
869 * connector is linked to. Drivers should never set this property directly,
870 * it is handled by the DRM core by calling the &drm_connector_funcs.dpms
871 * callback. For atomic drivers the remapping to the "ACTIVE" property is
872 * implemented in the DRM core. This is the only standard connector
873 * property that userspace can change.
875 * Note that this property cannot be set through the MODE_ATOMIC ioctl,
876 * userspace must use "ACTIVE" on the CRTC instead.
880 * For userspace also running on legacy drivers the "DPMS" semantics are a
881 * lot more complicated. First, userspace cannot rely on the "DPMS" value
882 * returned by the GETCONNECTOR actually reflecting reality, because many
883 * drivers fail to update it. For atomic drivers this is taken care of in
884 * drm_atomic_helper_update_legacy_modeset_state().
886 * The second issue is that the DPMS state is only well-defined when the
887 * connector is connected to a CRTC. In atomic the DRM core enforces that
888 * "ACTIVE" is off in such a case, no such checks exists for "DPMS".
890 * Finally, when enabling an output using the legacy SETCONFIG ioctl then
891 * "DPMS" is forced to ON. But see above, that might not be reflected in
892 * the software value on legacy drivers.
894 * Summarizing: Only set "DPMS" when the connector is known to be enabled,
895 * assume that a successful SETCONFIG call also sets "DPMS" to on, and
896 * never read back the value of "DPMS" because it can be incorrect.
898 * Connector path property to identify how this sink is physically
899 * connected. Used by DP MST. This should be set by calling
900 * drm_connector_set_path_property(), in the case of DP MST with the
901 * path property the MST manager created. Userspace cannot change this
904 * Connector tile group property to indicate how a set of DRM connector
905 * compose together into one logical screen. This is used by both high-res
906 * external screens (often only using a single cable, but exposing multiple
907 * DP MST sinks), or high-res integrated panels (like dual-link DSI) which
908 * are not gen-locked. Note that for tiled panels which are genlocked, like
909 * dual-link LVDS or dual-link DSI, the driver should try to not expose the
910 * tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
911 * should update this value using drm_connector_set_tile_property().
912 * Userspace cannot change this property.
914 * Connector link-status property to indicate the status of link. The
915 * default value of link-status is "GOOD". If something fails during or
916 * after modeset, the kernel driver may set this to "BAD" and issue a
917 * hotplug uevent. Drivers should update this value using
918 * drm_connector_set_link_status_property().
920 * Indicates the output should be ignored for purposes of displaying a
921 * standard desktop environment or console. This is most likely because
922 * the output device is not rectilinear.
923 * Content Protection:
924 * This property is used by userspace to request the kernel protect future
925 * content communicated over the link. When requested, kernel will apply
926 * the appropriate means of protection (most often HDCP), and use the
927 * property to tell userspace the protection is active.
929 * Drivers can set this up by calling
930 * drm_connector_attach_content_protection_property() on initialization.
932 * The value of this property can be one of the following:
934 * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
935 * The link is not protected, content is transmitted in the clear.
936 * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
937 * Userspace has requested content protection, but the link is not
938 * currently protected. When in this state, kernel should enable
939 * Content Protection as soon as possible.
940 * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
941 * Userspace has requested content protection, and the link is
942 * protected. Only the driver can set the property to this value.
943 * If userspace attempts to set to ENABLED, kernel will return
948 * - DESIRED state should be preserved until userspace de-asserts it by
949 * setting the property to UNDESIRED. This means ENABLED should only
950 * transition to UNDESIRED when the user explicitly requests it.
951 * - If the state is DESIRED, kernel should attempt to re-authenticate the
952 * link whenever possible. This includes across disable/enable, dpms,
953 * hotplug, downstream device changes, link status failures, etc..
954 * - Userspace is responsible for polling the property to determine when
955 * the value transitions from ENABLED to DESIRED. This signifies the link
956 * is no longer protected and userspace should take appropriate action
957 * (whatever that might be).
960 * This range property is used by userspace to limit the bit depth. When
961 * used the driver would limit the bpc in accordance with the valid range
962 * supported by the hardware and sink. Drivers to use the function
963 * drm_connector_attach_max_bpc_property() to create and attach the
964 * property to the connector during initialization.
966 * Connectors also have one standardized atomic property:
969 * Mode object ID of the &drm_crtc this connector should be connected to.
971 * Connectors for LCD panels may also have one standardized property:
974 * On some devices the LCD panel is mounted in the casing in such a way
975 * that the up/top side of the panel does not match with the top side of
976 * the device. Userspace can use this property to check for this.
977 * Note that input coordinates from touchscreens (input devices with
978 * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
979 * coordinates, so if userspace rotates the picture to adjust for
980 * the orientation it must also apply the same transformation to the
981 * touchscreen input coordinates. This property is initialized by calling
982 * drm_connector_init_panel_orientation_property().
985 * This property defines how a non-native mode is upscaled to the native
986 * mode of an LCD panel:
989 * No upscaling happens, scaling is left to the panel. Not all
990 * drivers expose this mode.
992 * The output is upscaled to the full resolution of the panel,
993 * ignoring the aspect ratio.
995 * No upscaling happens, the output is centered within the native
996 * resolution the panel.
998 * The output is upscaled to maximize either the width or height
999 * while retaining the aspect ratio.
1001 * This property should be set up by calling
1002 * drm_connector_attach_scaling_mode_property(). Note that drivers
1003 * can also expose this property to external outputs, in which case they
1004 * must support "None", which should be the default (since external screens
1005 * have a built-in scaler).
1008 int drm_connector_create_standard_properties(struct drm_device *dev)
1010 struct drm_property *prop;
1012 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
1013 DRM_MODE_PROP_IMMUTABLE,
1017 dev->mode_config.edid_property = prop;
1019 prop = drm_property_create_enum(dev, 0,
1020 "DPMS", drm_dpms_enum_list,
1021 ARRAY_SIZE(drm_dpms_enum_list));
1024 dev->mode_config.dpms_property = prop;
1026 prop = drm_property_create(dev,
1027 DRM_MODE_PROP_BLOB |
1028 DRM_MODE_PROP_IMMUTABLE,
1032 dev->mode_config.path_property = prop;
1034 prop = drm_property_create(dev,
1035 DRM_MODE_PROP_BLOB |
1036 DRM_MODE_PROP_IMMUTABLE,
1040 dev->mode_config.tile_property = prop;
1042 prop = drm_property_create_enum(dev, 0, "link-status",
1043 drm_link_status_enum_list,
1044 ARRAY_SIZE(drm_link_status_enum_list));
1047 dev->mode_config.link_status_property = prop;
1049 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
1052 dev->mode_config.non_desktop_property = prop;
1054 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
1055 "HDR_OUTPUT_METADATA", 0);
1058 dev->mode_config.hdr_output_metadata_property = prop;
1064 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1067 * Called by a driver the first time a DVI-I connector is made.
1069 int drm_mode_create_dvi_i_properties(struct drm_device *dev)
1071 struct drm_property *dvi_i_selector;
1072 struct drm_property *dvi_i_subconnector;
1074 if (dev->mode_config.dvi_i_select_subconnector_property)
1078 drm_property_create_enum(dev, 0,
1079 "select subconnector",
1080 drm_dvi_i_select_enum_list,
1081 ARRAY_SIZE(drm_dvi_i_select_enum_list));
1082 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
1084 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1086 drm_dvi_i_subconnector_enum_list,
1087 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
1088 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
1092 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
1095 * DOC: HDMI connector properties
1097 * content type (HDMI specific):
1098 * Indicates content type setting to be used in HDMI infoframes to indicate
1099 * content type for the external device, so that it adjusts its display
1100 * settings accordingly.
1102 * The value of this property can be one of the following:
1105 * Content type is unknown
1107 * Content type is graphics
1109 * Content type is photo
1111 * Content type is cinema
1113 * Content type is game
1115 * Drivers can set up this property by calling
1116 * drm_connector_attach_content_type_property(). Decoding to
1117 * infoframe values is done through drm_hdmi_avi_infoframe_content_type().
1121 * drm_connector_attach_content_type_property - attach content-type property
1122 * @connector: connector to attach content type property on.
1124 * Called by a driver the first time a HDMI connector is made.
1126 int drm_connector_attach_content_type_property(struct drm_connector *connector)
1128 if (!drm_mode_create_content_type_property(connector->dev))
1129 drm_object_attach_property(&connector->base,
1130 connector->dev->mode_config.content_type_property,
1131 DRM_MODE_CONTENT_TYPE_NO_DATA);
1134 EXPORT_SYMBOL(drm_connector_attach_content_type_property);
1138 * drm_hdmi_avi_infoframe_content_type() - fill the HDMI AVI infoframe
1139 * content type information, based
1140 * on correspondent DRM property.
1141 * @frame: HDMI AVI infoframe
1142 * @conn_state: DRM display connector state
1145 void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame,
1146 const struct drm_connector_state *conn_state)
1148 switch (conn_state->content_type) {
1149 case DRM_MODE_CONTENT_TYPE_GRAPHICS:
1150 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
1152 case DRM_MODE_CONTENT_TYPE_CINEMA:
1153 frame->content_type = HDMI_CONTENT_TYPE_CINEMA;
1155 case DRM_MODE_CONTENT_TYPE_GAME:
1156 frame->content_type = HDMI_CONTENT_TYPE_GAME;
1158 case DRM_MODE_CONTENT_TYPE_PHOTO:
1159 frame->content_type = HDMI_CONTENT_TYPE_PHOTO;
1162 /* Graphics is the default(0) */
1163 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
1166 frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA;
1168 EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type);
1171 * drm_mode_attach_tv_margin_properties - attach TV connector margin properties
1172 * @connector: DRM connector
1174 * Called by a driver when it needs to attach TV margin props to a connector.
1175 * Typically used on SDTV and HDMI connectors.
1177 void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
1179 struct drm_device *dev = connector->dev;
1181 drm_object_attach_property(&connector->base,
1182 dev->mode_config.tv_left_margin_property,
1184 drm_object_attach_property(&connector->base,
1185 dev->mode_config.tv_right_margin_property,
1187 drm_object_attach_property(&connector->base,
1188 dev->mode_config.tv_top_margin_property,
1190 drm_object_attach_property(&connector->base,
1191 dev->mode_config.tv_bottom_margin_property,
1194 EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
1197 * drm_mode_create_tv_margin_properties - create TV connector margin properties
1200 * Called by a driver's HDMI connector initialization routine, this function
1201 * creates the TV margin properties for a given device. No need to call this
1202 * function for an SDTV connector, it's already called from
1203 * drm_mode_create_tv_properties().
1205 int drm_mode_create_tv_margin_properties(struct drm_device *dev)
1207 if (dev->mode_config.tv_left_margin_property)
1210 dev->mode_config.tv_left_margin_property =
1211 drm_property_create_range(dev, 0, "left margin", 0, 100);
1212 if (!dev->mode_config.tv_left_margin_property)
1215 dev->mode_config.tv_right_margin_property =
1216 drm_property_create_range(dev, 0, "right margin", 0, 100);
1217 if (!dev->mode_config.tv_right_margin_property)
1220 dev->mode_config.tv_top_margin_property =
1221 drm_property_create_range(dev, 0, "top margin", 0, 100);
1222 if (!dev->mode_config.tv_top_margin_property)
1225 dev->mode_config.tv_bottom_margin_property =
1226 drm_property_create_range(dev, 0, "bottom margin", 0, 100);
1227 if (!dev->mode_config.tv_bottom_margin_property)
1232 EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
1235 * drm_mode_create_tv_properties - create TV specific connector properties
1237 * @num_modes: number of different TV formats (modes) supported
1238 * @modes: array of pointers to strings containing name of each format
1240 * Called by a driver's TV initialization routine, this function creates
1241 * the TV specific connector properties for a given device. Caller is
1242 * responsible for allocating a list of format names and passing them to
1245 int drm_mode_create_tv_properties(struct drm_device *dev,
1246 unsigned int num_modes,
1247 const char * const modes[])
1249 struct drm_property *tv_selector;
1250 struct drm_property *tv_subconnector;
1253 if (dev->mode_config.tv_select_subconnector_property)
1257 * Basic connector properties
1259 tv_selector = drm_property_create_enum(dev, 0,
1260 "select subconnector",
1261 drm_tv_select_enum_list,
1262 ARRAY_SIZE(drm_tv_select_enum_list));
1266 dev->mode_config.tv_select_subconnector_property = tv_selector;
1269 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1271 drm_tv_subconnector_enum_list,
1272 ARRAY_SIZE(drm_tv_subconnector_enum_list));
1273 if (!tv_subconnector)
1275 dev->mode_config.tv_subconnector_property = tv_subconnector;
1278 * Other, TV specific properties: margins & TV modes.
1280 if (drm_mode_create_tv_margin_properties(dev))
1283 dev->mode_config.tv_mode_property =
1284 drm_property_create(dev, DRM_MODE_PROP_ENUM,
1286 if (!dev->mode_config.tv_mode_property)
1289 for (i = 0; i < num_modes; i++)
1290 drm_property_add_enum(dev->mode_config.tv_mode_property,
1293 dev->mode_config.tv_brightness_property =
1294 drm_property_create_range(dev, 0, "brightness", 0, 100);
1295 if (!dev->mode_config.tv_brightness_property)
1298 dev->mode_config.tv_contrast_property =
1299 drm_property_create_range(dev, 0, "contrast", 0, 100);
1300 if (!dev->mode_config.tv_contrast_property)
1303 dev->mode_config.tv_flicker_reduction_property =
1304 drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
1305 if (!dev->mode_config.tv_flicker_reduction_property)
1308 dev->mode_config.tv_overscan_property =
1309 drm_property_create_range(dev, 0, "overscan", 0, 100);
1310 if (!dev->mode_config.tv_overscan_property)
1313 dev->mode_config.tv_saturation_property =
1314 drm_property_create_range(dev, 0, "saturation", 0, 100);
1315 if (!dev->mode_config.tv_saturation_property)
1318 dev->mode_config.tv_hue_property =
1319 drm_property_create_range(dev, 0, "hue", 0, 100);
1320 if (!dev->mode_config.tv_hue_property)
1327 EXPORT_SYMBOL(drm_mode_create_tv_properties);
1330 * drm_mode_create_scaling_mode_property - create scaling mode property
1333 * Called by a driver the first time it's needed, must be attached to desired
1336 * Atomic drivers should use drm_connector_attach_scaling_mode_property()
1337 * instead to correctly assign &drm_connector_state.picture_aspect_ratio
1338 * in the atomic state.
1340 int drm_mode_create_scaling_mode_property(struct drm_device *dev)
1342 struct drm_property *scaling_mode;
1344 if (dev->mode_config.scaling_mode_property)
1348 drm_property_create_enum(dev, 0, "scaling mode",
1349 drm_scaling_mode_enum_list,
1350 ARRAY_SIZE(drm_scaling_mode_enum_list));
1352 dev->mode_config.scaling_mode_property = scaling_mode;
1356 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
1359 * DOC: Variable refresh properties
1361 * Variable refresh rate capable displays can dynamically adjust their
1362 * refresh rate by extending the duration of their vertical front porch
1363 * until page flip or timeout occurs. This can reduce or remove stuttering
1364 * and latency in scenarios where the page flip does not align with the
1367 * An example scenario would be an application flipping at a constant rate
1368 * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
1369 * interval and the same contents will be displayed twice. This can be
1370 * observed as stuttering for content with motion.
1372 * If variable refresh rate was active on a display that supported a
1373 * variable refresh range from 35Hz to 60Hz no stuttering would be observable
1374 * for the example scenario. The minimum supported variable refresh rate of
1375 * 35Hz is below the page flip frequency and the vertical front porch can
1376 * be extended until the page flip occurs. The vblank interval will be
1377 * directly aligned to the page flip rate.
1379 * Not all userspace content is suitable for use with variable refresh rate.
1380 * Large and frequent changes in vertical front porch duration may worsen
1381 * perceived stuttering for input sensitive applications.
1383 * Panel brightness will also vary with vertical front porch duration. Some
1384 * panels may have noticeable differences in brightness between the minimum
1385 * vertical front porch duration and the maximum vertical front porch duration.
1386 * Large and frequent changes in vertical front porch duration may produce
1387 * observable flickering for such panels.
1389 * Userspace control for variable refresh rate is supported via properties
1390 * on the &drm_connector and &drm_crtc objects.
1393 * Optional &drm_connector boolean property that drivers should attach
1394 * with drm_connector_attach_vrr_capable_property() on connectors that
1395 * could support variable refresh rates. Drivers should update the
1396 * property value by calling drm_connector_set_vrr_capable_property().
1398 * Absence of the property should indicate absence of support.
1401 * Default &drm_crtc boolean property that notifies the driver that the
1402 * content on the CRTC is suitable for variable refresh rate presentation.
1403 * The driver will take this property as a hint to enable variable
1404 * refresh rate support if the receiver supports it, ie. if the
1405 * "vrr_capable" property is true on the &drm_connector object. The
1406 * vertical front porch duration will be extended until page-flip or
1407 * timeout when enabled.
1409 * The minimum vertical front porch duration is defined as the vertical
1410 * front porch duration for the current mode.
1412 * The maximum vertical front porch duration is greater than or equal to
1413 * the minimum vertical front porch duration. The duration is derived
1414 * from the minimum supported variable refresh rate for the connector.
1416 * The driver may place further restrictions within these minimum
1417 * and maximum bounds.
1421 * drm_connector_attach_vrr_capable_property - creates the
1422 * vrr_capable property
1423 * @connector: connector to create the vrr_capable property on.
1425 * This is used by atomic drivers to add support for querying
1426 * variable refresh rate capability for a connector.
1429 * Zero on success, negative errono on failure.
1431 int drm_connector_attach_vrr_capable_property(
1432 struct drm_connector *connector)
1434 struct drm_device *dev = connector->dev;
1435 struct drm_property *prop;
1437 if (!connector->vrr_capable_property) {
1438 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
1443 connector->vrr_capable_property = prop;
1444 drm_object_attach_property(&connector->base, prop, 0);
1449 EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
1452 * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
1453 * @connector: connector to attach scaling mode property on.
1454 * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
1456 * This is used to add support for scaling mode to atomic drivers.
1457 * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio
1458 * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
1460 * This is the atomic version of drm_mode_create_scaling_mode_property().
1463 * Zero on success, negative errno on failure.
1465 int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
1466 u32 scaling_mode_mask)
1468 struct drm_device *dev = connector->dev;
1469 struct drm_property *scaling_mode_property;
1471 const unsigned valid_scaling_mode_mask =
1472 (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
1474 if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
1475 scaling_mode_mask & ~valid_scaling_mode_mask))
1478 scaling_mode_property =
1479 drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
1480 hweight32(scaling_mode_mask));
1482 if (!scaling_mode_property)
1485 for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
1488 if (!(BIT(i) & scaling_mode_mask))
1491 ret = drm_property_add_enum(scaling_mode_property,
1492 drm_scaling_mode_enum_list[i].type,
1493 drm_scaling_mode_enum_list[i].name);
1496 drm_property_destroy(dev, scaling_mode_property);
1502 drm_object_attach_property(&connector->base,
1503 scaling_mode_property, 0);
1505 connector->scaling_mode_property = scaling_mode_property;
1509 EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
1512 * drm_mode_create_aspect_ratio_property - create aspect ratio property
1515 * Called by a driver the first time it's needed, must be attached to desired
1519 * Zero on success, negative errno on failure.
1521 int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
1523 if (dev->mode_config.aspect_ratio_property)
1526 dev->mode_config.aspect_ratio_property =
1527 drm_property_create_enum(dev, 0, "aspect ratio",
1528 drm_aspect_ratio_enum_list,
1529 ARRAY_SIZE(drm_aspect_ratio_enum_list));
1531 if (dev->mode_config.aspect_ratio_property == NULL)
1536 EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
1539 * DOC: standard connector properties
1542 * drm_mode_create_colorspace_property - create colorspace property
1543 * This property helps select a suitable colorspace based on the sink
1544 * capability. Modern sink devices support wider gamut like BT2020.
1545 * This helps switch to BT2020 mode if the BT2020 encoded video stream
1546 * is being played by the user, same for any other colorspace. Thereby
1547 * giving a good visual experience to users.
1549 * The expectation from userspace is that it should parse the EDID
1550 * and get supported colorspaces. Use this property and switch to the
1551 * one supported. Sink supported colorspaces should be retrieved by
1552 * userspace from EDID and driver will not explicitly expose them.
1554 * Basically the expectation from userspace is:
1555 * - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink
1557 * - Set this new property to let the sink know what it
1558 * converted the CRTC output to.
1559 * - This property is just to inform sink what colorspace
1560 * source is trying to drive.
1562 * Called by a driver the first time it's needed, must be attached to desired
1565 int drm_mode_create_colorspace_property(struct drm_connector *connector)
1567 struct drm_device *dev = connector->dev;
1568 struct drm_property *prop;
1570 if (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA ||
1571 connector->connector_type == DRM_MODE_CONNECTOR_HDMIB) {
1572 prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
1575 ARRAY_SIZE(hdmi_colorspaces));
1579 DRM_DEBUG_KMS("Colorspace property not supported\n");
1583 connector->colorspace_property = prop;
1587 EXPORT_SYMBOL(drm_mode_create_colorspace_property);
1590 * drm_mode_create_content_type_property - create content type property
1593 * Called by a driver the first time it's needed, must be attached to desired
1597 * Zero on success, negative errno on failure.
1599 int drm_mode_create_content_type_property(struct drm_device *dev)
1601 if (dev->mode_config.content_type_property)
1604 dev->mode_config.content_type_property =
1605 drm_property_create_enum(dev, 0, "content type",
1606 drm_content_type_enum_list,
1607 ARRAY_SIZE(drm_content_type_enum_list));
1609 if (dev->mode_config.content_type_property == NULL)
1614 EXPORT_SYMBOL(drm_mode_create_content_type_property);
1617 * drm_mode_create_suggested_offset_properties - create suggests offset properties
1620 * Create the the suggested x/y offset property for connectors.
1622 int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
1624 if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
1627 dev->mode_config.suggested_x_property =
1628 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
1630 dev->mode_config.suggested_y_property =
1631 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
1633 if (dev->mode_config.suggested_x_property == NULL ||
1634 dev->mode_config.suggested_y_property == NULL)
1638 EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
1641 * drm_connector_set_path_property - set tile property on connector
1642 * @connector: connector to set property on.
1643 * @path: path to use for property; must not be NULL.
1645 * This creates a property to expose to userspace to specify a
1646 * connector path. This is mainly used for DisplayPort MST where
1647 * connectors have a topology and we want to allow userspace to give
1648 * them more meaningful names.
1651 * Zero on success, negative errno on failure.
1653 int drm_connector_set_path_property(struct drm_connector *connector,
1656 struct drm_device *dev = connector->dev;
1659 ret = drm_property_replace_global_blob(dev,
1660 &connector->path_blob_ptr,
1664 dev->mode_config.path_property);
1667 EXPORT_SYMBOL(drm_connector_set_path_property);
1670 * drm_connector_set_tile_property - set tile property on connector
1671 * @connector: connector to set property on.
1673 * This looks up the tile information for a connector, and creates a
1674 * property for userspace to parse if it exists. The property is of
1675 * the form of 8 integers using ':' as a separator.
1676 * This is used for dual port tiled displays with DisplayPort SST
1677 * or DisplayPort MST connectors.
1680 * Zero on success, errno on failure.
1682 int drm_connector_set_tile_property(struct drm_connector *connector)
1684 struct drm_device *dev = connector->dev;
1688 if (!connector->has_tile) {
1689 ret = drm_property_replace_global_blob(dev,
1690 &connector->tile_blob_ptr,
1694 dev->mode_config.tile_property);
1698 snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
1699 connector->tile_group->id, connector->tile_is_single_monitor,
1700 connector->num_h_tile, connector->num_v_tile,
1701 connector->tile_h_loc, connector->tile_v_loc,
1702 connector->tile_h_size, connector->tile_v_size);
1704 ret = drm_property_replace_global_blob(dev,
1705 &connector->tile_blob_ptr,
1709 dev->mode_config.tile_property);
1712 EXPORT_SYMBOL(drm_connector_set_tile_property);
1715 * drm_connector_update_edid_property - update the edid property of a connector
1716 * @connector: drm connector
1717 * @edid: new value of the edid property
1719 * This function creates a new blob modeset object and assigns its id to the
1720 * connector's edid property.
1721 * Since we also parse tile information from EDID's displayID block, we also
1722 * set the connector's tile property here. See drm_connector_set_tile_property()
1726 * Zero on success, negative errno on failure.
1728 int drm_connector_update_edid_property(struct drm_connector *connector,
1729 const struct edid *edid)
1731 struct drm_device *dev = connector->dev;
1735 /* ignore requests to set edid when overridden */
1736 if (connector->override_edid)
1740 size = EDID_LENGTH * (1 + edid->extensions);
1742 /* Set the display info, using edid if available, otherwise
1743 * reseting the values to defaults. This duplicates the work
1744 * done in drm_add_edid_modes, but that function is not
1745 * consistently called before this one in all drivers and the
1746 * computation is cheap enough that it seems better to
1747 * duplicate it rather than attempt to ensure some arbitrary
1748 * ordering of calls.
1751 drm_add_display_info(connector, edid);
1753 drm_reset_display_info(connector);
1755 drm_object_property_set_value(&connector->base,
1756 dev->mode_config.non_desktop_property,
1757 connector->display_info.non_desktop);
1759 ret = drm_property_replace_global_blob(dev,
1760 &connector->edid_blob_ptr,
1764 dev->mode_config.edid_property);
1767 return drm_connector_set_tile_property(connector);
1769 EXPORT_SYMBOL(drm_connector_update_edid_property);
1772 * drm_connector_set_link_status_property - Set link status property of a connector
1773 * @connector: drm connector
1774 * @link_status: new value of link status property (0: Good, 1: Bad)
1776 * In usual working scenario, this link status property will always be set to
1777 * "GOOD". If something fails during or after a mode set, the kernel driver
1778 * may set this link status property to "BAD". The caller then needs to send a
1779 * hotplug uevent for userspace to re-check the valid modes through
1780 * GET_CONNECTOR_IOCTL and retry modeset.
1782 * Note: Drivers cannot rely on userspace to support this property and
1783 * issue a modeset. As such, they may choose to handle issues (like
1784 * re-training a link) without userspace's intervention.
1786 * The reason for adding this property is to handle link training failures, but
1787 * it is not limited to DP or link training. For example, if we implement
1788 * asynchronous setcrtc, this property can be used to report any failures in that.
1790 void drm_connector_set_link_status_property(struct drm_connector *connector,
1791 uint64_t link_status)
1793 struct drm_device *dev = connector->dev;
1795 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1796 connector->state->link_status = link_status;
1797 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1799 EXPORT_SYMBOL(drm_connector_set_link_status_property);
1802 * drm_connector_attach_max_bpc_property - attach "max bpc" property
1803 * @connector: connector to attach max bpc property on.
1804 * @min: The minimum bit depth supported by the connector.
1805 * @max: The maximum bit depth supported by the connector.
1807 * This is used to add support for limiting the bit depth on a connector.
1810 * Zero on success, negative errno on failure.
1812 int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
1815 struct drm_device *dev = connector->dev;
1816 struct drm_property *prop;
1818 prop = connector->max_bpc_property;
1820 prop = drm_property_create_range(dev, 0, "max bpc", min, max);
1824 connector->max_bpc_property = prop;
1827 drm_object_attach_property(&connector->base, prop, max);
1828 connector->state->max_requested_bpc = max;
1829 connector->state->max_bpc = max;
1833 EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
1836 * drm_connector_set_vrr_capable_property - sets the variable refresh rate
1837 * capable property for a connector
1838 * @connector: drm connector
1839 * @capable: True if the connector is variable refresh rate capable
1841 * Should be used by atomic drivers to update the indicated support for
1842 * variable refresh rate over a connector.
1844 void drm_connector_set_vrr_capable_property(
1845 struct drm_connector *connector, bool capable)
1847 drm_object_property_set_value(&connector->base,
1848 connector->vrr_capable_property,
1851 EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
1854 * drm_connector_init_panel_orientation_property -
1855 * initialize the connecters panel_orientation property
1856 * @connector: connector for which to init the panel-orientation property.
1857 * @width: width in pixels of the panel, used for panel quirk detection
1858 * @height: height in pixels of the panel, used for panel quirk detection
1860 * This function should only be called for built-in panels, after setting
1861 * connector->display_info.panel_orientation first (if known).
1863 * This function will check for platform specific (e.g. DMI based) quirks
1864 * overriding display_info.panel_orientation first, then if panel_orientation
1865 * is not DRM_MODE_PANEL_ORIENTATION_UNKNOWN it will attach the
1866 * "panel orientation" property to the connector.
1869 * Zero on success, negative errno on failure.
1871 int drm_connector_init_panel_orientation_property(
1872 struct drm_connector *connector, int width, int height)
1874 struct drm_device *dev = connector->dev;
1875 struct drm_display_info *info = &connector->display_info;
1876 struct drm_property *prop;
1877 int orientation_quirk;
1879 orientation_quirk = drm_get_panel_orientation_quirk(width, height);
1880 if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
1881 info->panel_orientation = orientation_quirk;
1883 if (info->panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
1886 prop = dev->mode_config.panel_orientation_property;
1888 prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1889 "panel orientation",
1890 drm_panel_orientation_enum_list,
1891 ARRAY_SIZE(drm_panel_orientation_enum_list));
1895 dev->mode_config.panel_orientation_property = prop;
1898 drm_object_attach_property(&connector->base, prop,
1899 info->panel_orientation);
1902 EXPORT_SYMBOL(drm_connector_init_panel_orientation_property);
1904 int drm_connector_set_obj_prop(struct drm_mode_object *obj,
1905 struct drm_property *property,
1909 struct drm_connector *connector = obj_to_connector(obj);
1911 /* Do DPMS ourselves */
1912 if (property == connector->dev->mode_config.dpms_property) {
1913 ret = (*connector->funcs->dpms)(connector, (int)value);
1914 } else if (connector->funcs->set_property)
1915 ret = connector->funcs->set_property(connector, property, value);
1918 drm_object_property_set_value(&connector->base, property, value);
1922 int drm_connector_property_set_ioctl(struct drm_device *dev,
1923 void *data, struct drm_file *file_priv)
1925 struct drm_mode_connector_set_property *conn_set_prop = data;
1926 struct drm_mode_obj_set_property obj_set_prop = {
1927 .value = conn_set_prop->value,
1928 .prop_id = conn_set_prop->prop_id,
1929 .obj_id = conn_set_prop->connector_id,
1930 .obj_type = DRM_MODE_OBJECT_CONNECTOR
1933 /* It does all the locking and checking we need */
1934 return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
1937 static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
1939 /* For atomic drivers only state objects are synchronously updated and
1940 * protected by modeset locks, so check those first. */
1941 if (connector->state)
1942 return connector->state->best_encoder;
1943 return connector->encoder;
1947 drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
1948 const struct list_head *export_list,
1949 const struct drm_file *file_priv)
1952 * If user-space hasn't configured the driver to expose the stereo 3D
1953 * modes, don't expose them.
1955 if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
1958 * If user-space hasn't configured the driver to expose the modes
1959 * with aspect-ratio, don't expose them. However if such a mode
1960 * is unique, let it be exposed, but reset the aspect-ratio flags
1961 * while preparing the list of user-modes.
1963 if (!file_priv->aspect_ratio_allowed) {
1964 struct drm_display_mode *mode_itr;
1966 list_for_each_entry(mode_itr, export_list, export_head)
1967 if (drm_mode_match(mode_itr, mode,
1968 DRM_MODE_MATCH_TIMINGS |
1969 DRM_MODE_MATCH_CLOCK |
1970 DRM_MODE_MATCH_FLAGS |
1971 DRM_MODE_MATCH_3D_FLAGS))
1978 int drm_mode_getconnector(struct drm_device *dev, void *data,
1979 struct drm_file *file_priv)
1981 struct drm_mode_get_connector *out_resp = data;
1982 struct drm_connector *connector;
1983 struct drm_encoder *encoder;
1984 struct drm_display_mode *mode;
1986 int encoders_count = 0;
1990 struct drm_mode_modeinfo u_mode;
1991 struct drm_mode_modeinfo __user *mode_ptr;
1992 uint32_t __user *encoder_ptr;
1993 LIST_HEAD(export_list);
1995 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1998 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
2000 connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
2004 drm_connector_for_each_possible_encoder(connector, encoder, i)
2007 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
2009 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
2011 drm_connector_for_each_possible_encoder(connector, encoder, i) {
2012 if (put_user(encoder->base.id, encoder_ptr + copied)) {
2019 out_resp->count_encoders = encoders_count;
2021 out_resp->connector_id = connector->base.id;
2022 out_resp->connector_type = connector->connector_type;
2023 out_resp->connector_type_id = connector->connector_type_id;
2025 mutex_lock(&dev->mode_config.mutex);
2026 if (out_resp->count_modes == 0) {
2027 connector->funcs->fill_modes(connector,
2028 dev->mode_config.max_width,
2029 dev->mode_config.max_height);
2032 out_resp->mm_width = connector->display_info.width_mm;
2033 out_resp->mm_height = connector->display_info.height_mm;
2034 out_resp->subpixel = connector->display_info.subpixel_order;
2035 out_resp->connection = connector->status;
2037 /* delayed so we get modes regardless of pre-fill_modes state */
2038 list_for_each_entry(mode, &connector->modes, head)
2039 if (drm_mode_expose_to_userspace(mode, &export_list,
2041 list_add_tail(&mode->export_head, &export_list);
2046 * This ioctl is called twice, once to determine how much space is
2047 * needed, and the 2nd time to fill it.
2048 * The modes that need to be exposed to the user are maintained in the
2049 * 'export_list'. When the ioctl is called first time to determine the,
2050 * space, the export_list gets filled, to find the no.of modes. In the
2051 * 2nd time, the user modes are filled, one by one from the export_list.
2053 if ((out_resp->count_modes >= mode_count) && mode_count) {
2055 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
2056 list_for_each_entry(mode, &export_list, export_head) {
2057 drm_mode_convert_to_umode(&u_mode, mode);
2059 * Reset aspect ratio flags of user-mode, if modes with
2060 * aspect-ratio are not supported.
2062 if (!file_priv->aspect_ratio_allowed)
2063 u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
2064 if (copy_to_user(mode_ptr + copied,
2065 &u_mode, sizeof(u_mode))) {
2067 mutex_unlock(&dev->mode_config.mutex);
2074 out_resp->count_modes = mode_count;
2075 mutex_unlock(&dev->mode_config.mutex);
2077 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2078 encoder = drm_connector_get_encoder(connector);
2080 out_resp->encoder_id = encoder->base.id;
2082 out_resp->encoder_id = 0;
2084 /* Only grab properties after probing, to make sure EDID and other
2085 * properties reflect the latest status. */
2086 ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
2087 (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
2088 (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
2089 &out_resp->count_props);
2090 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2093 drm_connector_put(connector);
2102 * Tile groups are used to represent tiled monitors with a unique integer
2103 * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
2104 * we store this in a tile group, so we have a common identifier for all tiles
2105 * in a monitor group. The property is called "TILE". Drivers can manage tile
2106 * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
2107 * drm_mode_get_tile_group(). But this is only needed for internal panels where
2108 * the tile group information is exposed through a non-standard way.
2111 static void drm_tile_group_free(struct kref *kref)
2113 struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
2114 struct drm_device *dev = tg->dev;
2115 mutex_lock(&dev->mode_config.idr_mutex);
2116 idr_remove(&dev->mode_config.tile_idr, tg->id);
2117 mutex_unlock(&dev->mode_config.idr_mutex);
2122 * drm_mode_put_tile_group - drop a reference to a tile group.
2124 * @tg: tile group to drop reference to.
2126 * drop reference to tile group and free if 0.
2128 void drm_mode_put_tile_group(struct drm_device *dev,
2129 struct drm_tile_group *tg)
2131 kref_put(&tg->refcount, drm_tile_group_free);
2133 EXPORT_SYMBOL(drm_mode_put_tile_group);
2136 * drm_mode_get_tile_group - get a reference to an existing tile group
2138 * @topology: 8-bytes unique per monitor.
2140 * Use the unique bytes to get a reference to an existing tile group.
2143 * tile group or NULL if not found.
2145 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2148 struct drm_tile_group *tg;
2150 mutex_lock(&dev->mode_config.idr_mutex);
2151 idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
2152 if (!memcmp(tg->group_data, topology, 8)) {
2153 if (!kref_get_unless_zero(&tg->refcount))
2155 mutex_unlock(&dev->mode_config.idr_mutex);
2159 mutex_unlock(&dev->mode_config.idr_mutex);
2162 EXPORT_SYMBOL(drm_mode_get_tile_group);
2165 * drm_mode_create_tile_group - create a tile group from a displayid description
2167 * @topology: 8-bytes unique per monitor.
2169 * Create a tile group for the unique monitor, and get a unique
2170 * identifier for the tile group.
2173 * new tile group or NULL.
2175 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2178 struct drm_tile_group *tg;
2181 tg = kzalloc(sizeof(*tg), GFP_KERNEL);
2185 kref_init(&tg->refcount);
2186 memcpy(tg->group_data, topology, 8);
2189 mutex_lock(&dev->mode_config.idr_mutex);
2190 ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
2198 mutex_unlock(&dev->mode_config.idr_mutex);
2201 EXPORT_SYMBOL(drm_mode_create_tile_group);