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->status = connector_status_unknown;
249 connector->display_info.panel_orientation =
250 DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
252 drm_connector_get_cmdline_mode(connector);
254 /* We should add connectors at the end to avoid upsetting the connector
256 spin_lock_irq(&config->connector_list_lock);
257 list_add_tail(&connector->head, &config->connector_list);
258 config->num_connector++;
259 spin_unlock_irq(&config->connector_list_lock);
261 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
262 connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
263 drm_connector_attach_edid_property(connector);
265 drm_object_attach_property(&connector->base,
266 config->dpms_property, 0);
268 drm_object_attach_property(&connector->base,
269 config->link_status_property,
272 drm_object_attach_property(&connector->base,
273 config->non_desktop_property,
276 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
277 drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
280 connector->debugfs_entry = NULL;
283 ida_simple_remove(connector_ida, connector->connector_type_id);
286 ida_simple_remove(&config->connector_ida, connector->index);
289 drm_mode_object_unregister(dev, &connector->base);
293 EXPORT_SYMBOL(drm_connector_init);
296 * drm_connector_attach_edid_property - attach edid property.
297 * @connector: the connector
299 * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
300 * edid property attached by default. This function can be used to
301 * explicitly enable the edid property in these cases.
303 void drm_connector_attach_edid_property(struct drm_connector *connector)
305 struct drm_mode_config *config = &connector->dev->mode_config;
307 drm_object_attach_property(&connector->base,
308 config->edid_property,
311 EXPORT_SYMBOL(drm_connector_attach_edid_property);
314 * drm_connector_attach_encoder - attach a connector to an encoder
315 * @connector: connector to attach
316 * @encoder: encoder to attach @connector to
318 * This function links up a connector to an encoder. Note that the routing
319 * restrictions between encoders and crtcs are exposed to userspace through the
320 * possible_clones and possible_crtcs bitmasks.
323 * Zero on success, negative errno on failure.
325 int drm_connector_attach_encoder(struct drm_connector *connector,
326 struct drm_encoder *encoder)
331 * In the past, drivers have attempted to model the static association
332 * of connector to encoder in simple connector/encoder devices using a
333 * direct assignment of connector->encoder = encoder. This connection
334 * is a logical one and the responsibility of the core, so drivers are
335 * expected not to mess with this.
337 * Note that the error return should've been enough here, but a large
338 * majority of drivers ignores the return value, so add in a big WARN
339 * to get people's attention.
341 if (WARN_ON(connector->encoder))
344 for (i = 0; i < ARRAY_SIZE(connector->encoder_ids); i++) {
345 if (connector->encoder_ids[i] == 0) {
346 connector->encoder_ids[i] = encoder->base.id;
352 EXPORT_SYMBOL(drm_connector_attach_encoder);
355 * drm_connector_has_possible_encoder - check if the connector and encoder are assosicated with each other
356 * @connector: the connector
357 * @encoder: the encoder
360 * True if @encoder is one of the possible encoders for @connector.
362 bool drm_connector_has_possible_encoder(struct drm_connector *connector,
363 struct drm_encoder *encoder)
365 struct drm_encoder *enc;
368 drm_connector_for_each_possible_encoder(connector, enc, i) {
375 EXPORT_SYMBOL(drm_connector_has_possible_encoder);
377 static void drm_mode_remove(struct drm_connector *connector,
378 struct drm_display_mode *mode)
380 list_del(&mode->head);
381 drm_mode_destroy(connector->dev, mode);
385 * drm_connector_cleanup - cleans up an initialised connector
386 * @connector: connector to cleanup
388 * Cleans up the connector but doesn't free the object.
390 void drm_connector_cleanup(struct drm_connector *connector)
392 struct drm_device *dev = connector->dev;
393 struct drm_display_mode *mode, *t;
395 /* The connector should have been removed from userspace long before
396 * it is finally destroyed.
398 if (WARN_ON(connector->registration_state ==
399 DRM_CONNECTOR_REGISTERED))
400 drm_connector_unregister(connector);
402 if (connector->tile_group) {
403 drm_mode_put_tile_group(dev, connector->tile_group);
404 connector->tile_group = NULL;
407 list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
408 drm_mode_remove(connector, mode);
410 list_for_each_entry_safe(mode, t, &connector->modes, head)
411 drm_mode_remove(connector, mode);
413 ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida,
414 connector->connector_type_id);
416 ida_simple_remove(&dev->mode_config.connector_ida,
419 kfree(connector->display_info.bus_formats);
420 drm_mode_object_unregister(dev, &connector->base);
421 kfree(connector->name);
422 connector->name = NULL;
423 spin_lock_irq(&dev->mode_config.connector_list_lock);
424 list_del(&connector->head);
425 dev->mode_config.num_connector--;
426 spin_unlock_irq(&dev->mode_config.connector_list_lock);
428 WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
429 if (connector->state && connector->funcs->atomic_destroy_state)
430 connector->funcs->atomic_destroy_state(connector,
433 mutex_destroy(&connector->mutex);
435 memset(connector, 0, sizeof(*connector));
437 EXPORT_SYMBOL(drm_connector_cleanup);
440 * drm_connector_register - register a connector
441 * @connector: the connector to register
443 * Register userspace interfaces for a connector
446 * Zero on success, error code on failure.
448 int drm_connector_register(struct drm_connector *connector)
452 if (!connector->dev->registered)
455 mutex_lock(&connector->mutex);
456 if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
459 ret = drm_sysfs_connector_add(connector);
463 ret = drm_debugfs_connector_add(connector);
468 if (connector->funcs->late_register) {
469 ret = connector->funcs->late_register(connector);
474 drm_mode_object_register(connector->dev, &connector->base);
476 connector->registration_state = DRM_CONNECTOR_REGISTERED;
480 drm_debugfs_connector_remove(connector);
482 drm_sysfs_connector_remove(connector);
484 mutex_unlock(&connector->mutex);
487 EXPORT_SYMBOL(drm_connector_register);
490 * drm_connector_unregister - unregister a connector
491 * @connector: the connector to unregister
493 * Unregister userspace interfaces for a connector
495 void drm_connector_unregister(struct drm_connector *connector)
497 mutex_lock(&connector->mutex);
498 if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
499 mutex_unlock(&connector->mutex);
503 if (connector->funcs->early_unregister)
504 connector->funcs->early_unregister(connector);
506 drm_sysfs_connector_remove(connector);
507 drm_debugfs_connector_remove(connector);
509 connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
510 mutex_unlock(&connector->mutex);
512 EXPORT_SYMBOL(drm_connector_unregister);
514 void drm_connector_unregister_all(struct drm_device *dev)
516 struct drm_connector *connector;
517 struct drm_connector_list_iter conn_iter;
519 drm_connector_list_iter_begin(dev, &conn_iter);
520 drm_for_each_connector_iter(connector, &conn_iter)
521 drm_connector_unregister(connector);
522 drm_connector_list_iter_end(&conn_iter);
525 int drm_connector_register_all(struct drm_device *dev)
527 struct drm_connector *connector;
528 struct drm_connector_list_iter conn_iter;
531 drm_connector_list_iter_begin(dev, &conn_iter);
532 drm_for_each_connector_iter(connector, &conn_iter) {
533 ret = drm_connector_register(connector);
537 drm_connector_list_iter_end(&conn_iter);
540 drm_connector_unregister_all(dev);
545 * drm_get_connector_status_name - return a string for connector status
546 * @status: connector status to compute name of
548 * In contrast to the other drm_get_*_name functions this one here returns a
549 * const pointer and hence is threadsafe.
551 const char *drm_get_connector_status_name(enum drm_connector_status status)
553 if (status == connector_status_connected)
555 else if (status == connector_status_disconnected)
556 return "disconnected";
560 EXPORT_SYMBOL(drm_get_connector_status_name);
563 * drm_get_connector_force_name - return a string for connector force
564 * @force: connector force to get name of
566 * Returns: const pointer to name.
568 const char *drm_get_connector_force_name(enum drm_connector_force force)
571 case DRM_FORCE_UNSPECIFIED:
572 return "unspecified";
577 case DRM_FORCE_ON_DIGITAL:
584 #ifdef CONFIG_LOCKDEP
585 static struct lockdep_map connector_list_iter_dep_map = {
586 .name = "drm_connector_list_iter"
591 * drm_connector_list_iter_begin - initialize a connector_list iterator
593 * @iter: connector_list iterator
595 * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
596 * must always be cleaned up again by calling drm_connector_list_iter_end().
597 * Iteration itself happens using drm_connector_list_iter_next() or
598 * drm_for_each_connector_iter().
600 void drm_connector_list_iter_begin(struct drm_device *dev,
601 struct drm_connector_list_iter *iter)
605 lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
607 EXPORT_SYMBOL(drm_connector_list_iter_begin);
610 * Extra-safe connector put function that works in any context. Should only be
611 * used from the connector_iter functions, where we never really expect to
612 * actually release the connector when dropping our final reference.
615 __drm_connector_put_safe(struct drm_connector *conn)
617 struct drm_mode_config *config = &conn->dev->mode_config;
619 lockdep_assert_held(&config->connector_list_lock);
621 if (!refcount_dec_and_test(&conn->base.refcount.refcount))
624 llist_add(&conn->free_node, &config->connector_free_list);
625 schedule_work(&config->connector_free_work);
629 * drm_connector_list_iter_next - return next connector
630 * @iter: connector_list iterator
632 * Returns the next connector for @iter, or NULL when the list walk has
635 struct drm_connector *
636 drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
638 struct drm_connector *old_conn = iter->conn;
639 struct drm_mode_config *config = &iter->dev->mode_config;
640 struct list_head *lhead;
643 spin_lock_irqsave(&config->connector_list_lock, flags);
644 lhead = old_conn ? &old_conn->head : &config->connector_list;
647 if (lhead->next == &config->connector_list) {
653 iter->conn = list_entry(lhead, struct drm_connector, head);
655 /* loop until it's not a zombie connector */
656 } while (!kref_get_unless_zero(&iter->conn->base.refcount));
659 __drm_connector_put_safe(old_conn);
660 spin_unlock_irqrestore(&config->connector_list_lock, flags);
664 EXPORT_SYMBOL(drm_connector_list_iter_next);
667 * drm_connector_list_iter_end - tear down a connector_list iterator
668 * @iter: connector_list iterator
670 * Tears down @iter and releases any resources (like &drm_connector references)
671 * acquired while walking the list. This must always be called, both when the
672 * iteration completes fully or when it was aborted without walking the entire
675 void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
677 struct drm_mode_config *config = &iter->dev->mode_config;
682 spin_lock_irqsave(&config->connector_list_lock, flags);
683 __drm_connector_put_safe(iter->conn);
684 spin_unlock_irqrestore(&config->connector_list_lock, flags);
686 lock_release(&connector_list_iter_dep_map, 0, _RET_IP_);
688 EXPORT_SYMBOL(drm_connector_list_iter_end);
690 static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
691 { SubPixelUnknown, "Unknown" },
692 { SubPixelHorizontalRGB, "Horizontal RGB" },
693 { SubPixelHorizontalBGR, "Horizontal BGR" },
694 { SubPixelVerticalRGB, "Vertical RGB" },
695 { SubPixelVerticalBGR, "Vertical BGR" },
696 { SubPixelNone, "None" },
700 * drm_get_subpixel_order_name - return a string for a given subpixel enum
701 * @order: enum of subpixel_order
703 * Note you could abuse this and return something out of bounds, but that
704 * would be a caller error. No unscrubbed user data should make it here.
706 const char *drm_get_subpixel_order_name(enum subpixel_order order)
708 return drm_subpixel_enum_list[order].name;
710 EXPORT_SYMBOL(drm_get_subpixel_order_name);
712 static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
713 { DRM_MODE_DPMS_ON, "On" },
714 { DRM_MODE_DPMS_STANDBY, "Standby" },
715 { DRM_MODE_DPMS_SUSPEND, "Suspend" },
716 { DRM_MODE_DPMS_OFF, "Off" }
718 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
720 static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
721 { DRM_MODE_LINK_STATUS_GOOD, "Good" },
722 { DRM_MODE_LINK_STATUS_BAD, "Bad" },
726 * drm_display_info_set_bus_formats - set the supported bus formats
727 * @info: display info to store bus formats in
728 * @formats: array containing the supported bus formats
729 * @num_formats: the number of entries in the fmts array
731 * Store the supported bus formats in display info structure.
732 * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
733 * a full list of available formats.
735 int drm_display_info_set_bus_formats(struct drm_display_info *info,
737 unsigned int num_formats)
741 if (!formats && num_formats)
744 if (formats && num_formats) {
745 fmts = kmemdup(formats, sizeof(*formats) * num_formats,
751 kfree(info->bus_formats);
752 info->bus_formats = fmts;
753 info->num_bus_formats = num_formats;
757 EXPORT_SYMBOL(drm_display_info_set_bus_formats);
759 /* Optional connector properties. */
760 static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
761 { DRM_MODE_SCALE_NONE, "None" },
762 { DRM_MODE_SCALE_FULLSCREEN, "Full" },
763 { DRM_MODE_SCALE_CENTER, "Center" },
764 { DRM_MODE_SCALE_ASPECT, "Full aspect" },
767 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
768 { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
769 { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
770 { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
773 static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
774 { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
775 { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
776 { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
777 { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
778 { DRM_MODE_CONTENT_TYPE_GAME, "Game" },
781 static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
782 { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" },
783 { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" },
784 { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" },
785 { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" },
788 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
789 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
790 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
791 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
793 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
795 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
796 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
797 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
798 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
800 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
801 drm_dvi_i_subconnector_enum_list)
803 static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
804 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
805 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
806 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
807 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
808 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
810 DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
812 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
813 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
814 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
815 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
816 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
817 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
819 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
820 drm_tv_subconnector_enum_list)
822 static struct drm_prop_enum_list drm_cp_enum_list[] = {
823 { DRM_MODE_CONTENT_PROTECTION_UNDESIRED, "Undesired" },
824 { DRM_MODE_CONTENT_PROTECTION_DESIRED, "Desired" },
825 { DRM_MODE_CONTENT_PROTECTION_ENABLED, "Enabled" },
827 DRM_ENUM_NAME_FN(drm_get_content_protection_name, drm_cp_enum_list)
830 * DOC: standard connector properties
832 * DRM connectors have a few standardized properties:
835 * Blob property which contains the current EDID read from the sink. This
836 * is useful to parse sink identification information like vendor, model
837 * and serial. Drivers should update this property by calling
838 * drm_connector_update_edid_property(), usually after having parsed
839 * the EDID using drm_add_edid_modes(). Userspace cannot change this
842 * Legacy property for setting the power state of the connector. For atomic
843 * drivers this is only provided for backwards compatibility with existing
844 * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
845 * connector is linked to. Drivers should never set this property directly,
846 * it is handled by the DRM core by calling the &drm_connector_funcs.dpms
847 * callback. For atomic drivers the remapping to the "ACTIVE" property is
848 * implemented in the DRM core. This is the only standard connector
849 * property that userspace can change.
851 * Note that this property cannot be set through the MODE_ATOMIC ioctl,
852 * userspace must use "ACTIVE" on the CRTC instead.
856 * For userspace also running on legacy drivers the "DPMS" semantics are a
857 * lot more complicated. First, userspace cannot rely on the "DPMS" value
858 * returned by the GETCONNECTOR actually reflecting reality, because many
859 * drivers fail to update it. For atomic drivers this is taken care of in
860 * drm_atomic_helper_update_legacy_modeset_state().
862 * The second issue is that the DPMS state is only well-defined when the
863 * connector is connected to a CRTC. In atomic the DRM core enforces that
864 * "ACTIVE" is off in such a case, no such checks exists for "DPMS".
866 * Finally, when enabling an output using the legacy SETCONFIG ioctl then
867 * "DPMS" is forced to ON. But see above, that might not be reflected in
868 * the software value on legacy drivers.
870 * Summarizing: Only set "DPMS" when the connector is known to be enabled,
871 * assume that a successful SETCONFIG call also sets "DPMS" to on, and
872 * never read back the value of "DPMS" because it can be incorrect.
874 * Connector path property to identify how this sink is physically
875 * connected. Used by DP MST. This should be set by calling
876 * drm_connector_set_path_property(), in the case of DP MST with the
877 * path property the MST manager created. Userspace cannot change this
880 * Connector tile group property to indicate how a set of DRM connector
881 * compose together into one logical screen. This is used by both high-res
882 * external screens (often only using a single cable, but exposing multiple
883 * DP MST sinks), or high-res integrated panels (like dual-link DSI) which
884 * are not gen-locked. Note that for tiled panels which are genlocked, like
885 * dual-link LVDS or dual-link DSI, the driver should try to not expose the
886 * tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
887 * should update this value using drm_connector_set_tile_property().
888 * Userspace cannot change this property.
890 * Connector link-status property to indicate the status of link. The
891 * default value of link-status is "GOOD". If something fails during or
892 * after modeset, the kernel driver may set this to "BAD" and issue a
893 * hotplug uevent. Drivers should update this value using
894 * drm_connector_set_link_status_property().
896 * Indicates the output should be ignored for purposes of displaying a
897 * standard desktop environment or console. This is most likely because
898 * the output device is not rectilinear.
899 * Content Protection:
900 * This property is used by userspace to request the kernel protect future
901 * content communicated over the link. When requested, kernel will apply
902 * the appropriate means of protection (most often HDCP), and use the
903 * property to tell userspace the protection is active.
905 * Drivers can set this up by calling
906 * drm_connector_attach_content_protection_property() on initialization.
908 * The value of this property can be one of the following:
910 * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
911 * The link is not protected, content is transmitted in the clear.
912 * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
913 * Userspace has requested content protection, but the link is not
914 * currently protected. When in this state, kernel should enable
915 * Content Protection as soon as possible.
916 * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
917 * Userspace has requested content protection, and the link is
918 * protected. Only the driver can set the property to this value.
919 * If userspace attempts to set to ENABLED, kernel will return
924 * - DESIRED state should be preserved until userspace de-asserts it by
925 * setting the property to UNDESIRED. This means ENABLED should only
926 * transition to UNDESIRED when the user explicitly requests it.
927 * - If the state is DESIRED, kernel should attempt to re-authenticate the
928 * link whenever possible. This includes across disable/enable, dpms,
929 * hotplug, downstream device changes, link status failures, etc..
930 * - Userspace is responsible for polling the property to determine when
931 * the value transitions from ENABLED to DESIRED. This signifies the link
932 * is no longer protected and userspace should take appropriate action
933 * (whatever that might be).
935 * Connectors also have one standardized atomic property:
938 * Mode object ID of the &drm_crtc this connector should be connected to.
940 * Connectors for LCD panels may also have one standardized property:
943 * On some devices the LCD panel is mounted in the casing in such a way
944 * that the up/top side of the panel does not match with the top side of
945 * the device. Userspace can use this property to check for this.
946 * Note that input coordinates from touchscreens (input devices with
947 * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
948 * coordinates, so if userspace rotates the picture to adjust for
949 * the orientation it must also apply the same transformation to the
950 * touchscreen input coordinates. This property is initialized by calling
951 * drm_connector_init_panel_orientation_property().
954 * This property defines how a non-native mode is upscaled to the native
955 * mode of an LCD panel:
958 * No upscaling happens, scaling is left to the panel. Not all
959 * drivers expose this mode.
961 * The output is upscaled to the full resolution of the panel,
962 * ignoring the aspect ratio.
964 * No upscaling happens, the output is centered within the native
965 * resolution the panel.
967 * The output is upscaled to maximize either the width or height
968 * while retaining the aspect ratio.
970 * This property should be set up by calling
971 * drm_connector_attach_scaling_mode_property(). Note that drivers
972 * can also expose this property to external outputs, in which case they
973 * must support "None", which should be the default (since external screens
974 * have a built-in scaler).
977 int drm_connector_create_standard_properties(struct drm_device *dev)
979 struct drm_property *prop;
981 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
982 DRM_MODE_PROP_IMMUTABLE,
986 dev->mode_config.edid_property = prop;
988 prop = drm_property_create_enum(dev, 0,
989 "DPMS", drm_dpms_enum_list,
990 ARRAY_SIZE(drm_dpms_enum_list));
993 dev->mode_config.dpms_property = prop;
995 prop = drm_property_create(dev,
997 DRM_MODE_PROP_IMMUTABLE,
1001 dev->mode_config.path_property = prop;
1003 prop = drm_property_create(dev,
1004 DRM_MODE_PROP_BLOB |
1005 DRM_MODE_PROP_IMMUTABLE,
1009 dev->mode_config.tile_property = prop;
1011 prop = drm_property_create_enum(dev, 0, "link-status",
1012 drm_link_status_enum_list,
1013 ARRAY_SIZE(drm_link_status_enum_list));
1016 dev->mode_config.link_status_property = prop;
1018 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
1021 dev->mode_config.non_desktop_property = prop;
1027 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1030 * Called by a driver the first time a DVI-I connector is made.
1032 int drm_mode_create_dvi_i_properties(struct drm_device *dev)
1034 struct drm_property *dvi_i_selector;
1035 struct drm_property *dvi_i_subconnector;
1037 if (dev->mode_config.dvi_i_select_subconnector_property)
1041 drm_property_create_enum(dev, 0,
1042 "select subconnector",
1043 drm_dvi_i_select_enum_list,
1044 ARRAY_SIZE(drm_dvi_i_select_enum_list));
1045 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
1047 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1049 drm_dvi_i_subconnector_enum_list,
1050 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
1051 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
1055 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
1058 * DOC: HDMI connector properties
1060 * content type (HDMI specific):
1061 * Indicates content type setting to be used in HDMI infoframes to indicate
1062 * content type for the external device, so that it adjusts it's display
1063 * settings accordingly.
1065 * The value of this property can be one of the following:
1068 * Content type is unknown
1070 * Content type is graphics
1072 * Content type is photo
1074 * Content type is cinema
1076 * Content type is game
1078 * Drivers can set up this property by calling
1079 * drm_connector_attach_content_type_property(). Decoding to
1080 * infoframe values is done through drm_hdmi_avi_infoframe_content_type().
1084 * drm_connector_attach_content_type_property - attach content-type property
1085 * @connector: connector to attach content type property on.
1087 * Called by a driver the first time a HDMI connector is made.
1089 int drm_connector_attach_content_type_property(struct drm_connector *connector)
1091 if (!drm_mode_create_content_type_property(connector->dev))
1092 drm_object_attach_property(&connector->base,
1093 connector->dev->mode_config.content_type_property,
1094 DRM_MODE_CONTENT_TYPE_NO_DATA);
1097 EXPORT_SYMBOL(drm_connector_attach_content_type_property);
1101 * drm_hdmi_avi_infoframe_content_type() - fill the HDMI AVI infoframe
1102 * content type information, based
1103 * on correspondent DRM property.
1104 * @frame: HDMI AVI infoframe
1105 * @conn_state: DRM display connector state
1108 void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame,
1109 const struct drm_connector_state *conn_state)
1111 switch (conn_state->content_type) {
1112 case DRM_MODE_CONTENT_TYPE_GRAPHICS:
1113 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
1115 case DRM_MODE_CONTENT_TYPE_CINEMA:
1116 frame->content_type = HDMI_CONTENT_TYPE_CINEMA;
1118 case DRM_MODE_CONTENT_TYPE_GAME:
1119 frame->content_type = HDMI_CONTENT_TYPE_GAME;
1121 case DRM_MODE_CONTENT_TYPE_PHOTO:
1122 frame->content_type = HDMI_CONTENT_TYPE_PHOTO;
1125 /* Graphics is the default(0) */
1126 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
1129 frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA;
1131 EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type);
1134 * drm_create_tv_properties - create TV specific connector properties
1136 * @num_modes: number of different TV formats (modes) supported
1137 * @modes: array of pointers to strings containing name of each format
1139 * Called by a driver's TV initialization routine, this function creates
1140 * the TV specific connector properties for a given device. Caller is
1141 * responsible for allocating a list of format names and passing them to
1144 int drm_mode_create_tv_properties(struct drm_device *dev,
1145 unsigned int num_modes,
1146 const char * const modes[])
1148 struct drm_property *tv_selector;
1149 struct drm_property *tv_subconnector;
1152 if (dev->mode_config.tv_select_subconnector_property)
1156 * Basic connector properties
1158 tv_selector = drm_property_create_enum(dev, 0,
1159 "select subconnector",
1160 drm_tv_select_enum_list,
1161 ARRAY_SIZE(drm_tv_select_enum_list));
1165 dev->mode_config.tv_select_subconnector_property = tv_selector;
1168 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1170 drm_tv_subconnector_enum_list,
1171 ARRAY_SIZE(drm_tv_subconnector_enum_list));
1172 if (!tv_subconnector)
1174 dev->mode_config.tv_subconnector_property = tv_subconnector;
1177 * Other, TV specific properties: margins & TV modes.
1179 dev->mode_config.tv_left_margin_property =
1180 drm_property_create_range(dev, 0, "left margin", 0, 100);
1181 if (!dev->mode_config.tv_left_margin_property)
1184 dev->mode_config.tv_right_margin_property =
1185 drm_property_create_range(dev, 0, "right margin", 0, 100);
1186 if (!dev->mode_config.tv_right_margin_property)
1189 dev->mode_config.tv_top_margin_property =
1190 drm_property_create_range(dev, 0, "top margin", 0, 100);
1191 if (!dev->mode_config.tv_top_margin_property)
1194 dev->mode_config.tv_bottom_margin_property =
1195 drm_property_create_range(dev, 0, "bottom margin", 0, 100);
1196 if (!dev->mode_config.tv_bottom_margin_property)
1199 dev->mode_config.tv_mode_property =
1200 drm_property_create(dev, DRM_MODE_PROP_ENUM,
1202 if (!dev->mode_config.tv_mode_property)
1205 for (i = 0; i < num_modes; i++)
1206 drm_property_add_enum(dev->mode_config.tv_mode_property,
1209 dev->mode_config.tv_brightness_property =
1210 drm_property_create_range(dev, 0, "brightness", 0, 100);
1211 if (!dev->mode_config.tv_brightness_property)
1214 dev->mode_config.tv_contrast_property =
1215 drm_property_create_range(dev, 0, "contrast", 0, 100);
1216 if (!dev->mode_config.tv_contrast_property)
1219 dev->mode_config.tv_flicker_reduction_property =
1220 drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
1221 if (!dev->mode_config.tv_flicker_reduction_property)
1224 dev->mode_config.tv_overscan_property =
1225 drm_property_create_range(dev, 0, "overscan", 0, 100);
1226 if (!dev->mode_config.tv_overscan_property)
1229 dev->mode_config.tv_saturation_property =
1230 drm_property_create_range(dev, 0, "saturation", 0, 100);
1231 if (!dev->mode_config.tv_saturation_property)
1234 dev->mode_config.tv_hue_property =
1235 drm_property_create_range(dev, 0, "hue", 0, 100);
1236 if (!dev->mode_config.tv_hue_property)
1243 EXPORT_SYMBOL(drm_mode_create_tv_properties);
1246 * drm_mode_create_scaling_mode_property - create scaling mode property
1249 * Called by a driver the first time it's needed, must be attached to desired
1252 * Atomic drivers should use drm_connector_attach_scaling_mode_property()
1253 * instead to correctly assign &drm_connector_state.picture_aspect_ratio
1254 * in the atomic state.
1256 int drm_mode_create_scaling_mode_property(struct drm_device *dev)
1258 struct drm_property *scaling_mode;
1260 if (dev->mode_config.scaling_mode_property)
1264 drm_property_create_enum(dev, 0, "scaling mode",
1265 drm_scaling_mode_enum_list,
1266 ARRAY_SIZE(drm_scaling_mode_enum_list));
1268 dev->mode_config.scaling_mode_property = scaling_mode;
1272 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
1275 * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
1276 * @connector: connector to attach scaling mode property on.
1277 * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
1279 * This is used to add support for scaling mode to atomic drivers.
1280 * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio
1281 * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
1283 * This is the atomic version of drm_mode_create_scaling_mode_property().
1286 * Zero on success, negative errno on failure.
1288 int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
1289 u32 scaling_mode_mask)
1291 struct drm_device *dev = connector->dev;
1292 struct drm_property *scaling_mode_property;
1294 const unsigned valid_scaling_mode_mask =
1295 (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
1297 if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
1298 scaling_mode_mask & ~valid_scaling_mode_mask))
1301 scaling_mode_property =
1302 drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
1303 hweight32(scaling_mode_mask));
1305 if (!scaling_mode_property)
1308 for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
1311 if (!(BIT(i) & scaling_mode_mask))
1314 ret = drm_property_add_enum(scaling_mode_property,
1315 drm_scaling_mode_enum_list[i].type,
1316 drm_scaling_mode_enum_list[i].name);
1319 drm_property_destroy(dev, scaling_mode_property);
1325 drm_object_attach_property(&connector->base,
1326 scaling_mode_property, 0);
1328 connector->scaling_mode_property = scaling_mode_property;
1332 EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
1335 * drm_connector_attach_content_protection_property - attach content protection
1338 * @connector: connector to attach CP property on.
1340 * This is used to add support for content protection on select connectors.
1341 * Content Protection is intentionally vague to allow for different underlying
1342 * technologies, however it is most implemented by HDCP.
1344 * The content protection will be set to &drm_connector_state.content_protection
1347 * Zero on success, negative errno on failure.
1349 int drm_connector_attach_content_protection_property(
1350 struct drm_connector *connector)
1352 struct drm_device *dev = connector->dev;
1353 struct drm_property *prop;
1355 prop = drm_property_create_enum(dev, 0, "Content Protection",
1357 ARRAY_SIZE(drm_cp_enum_list));
1361 drm_object_attach_property(&connector->base, prop,
1362 DRM_MODE_CONTENT_PROTECTION_UNDESIRED);
1364 connector->content_protection_property = prop;
1368 EXPORT_SYMBOL(drm_connector_attach_content_protection_property);
1371 * drm_mode_create_aspect_ratio_property - create aspect ratio property
1374 * Called by a driver the first time it's needed, must be attached to desired
1378 * Zero on success, negative errno on failure.
1380 int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
1382 if (dev->mode_config.aspect_ratio_property)
1385 dev->mode_config.aspect_ratio_property =
1386 drm_property_create_enum(dev, 0, "aspect ratio",
1387 drm_aspect_ratio_enum_list,
1388 ARRAY_SIZE(drm_aspect_ratio_enum_list));
1390 if (dev->mode_config.aspect_ratio_property == NULL)
1395 EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
1398 * drm_mode_create_content_type_property - create content type property
1401 * Called by a driver the first time it's needed, must be attached to desired
1405 * Zero on success, negative errno on failure.
1407 int drm_mode_create_content_type_property(struct drm_device *dev)
1409 if (dev->mode_config.content_type_property)
1412 dev->mode_config.content_type_property =
1413 drm_property_create_enum(dev, 0, "content type",
1414 drm_content_type_enum_list,
1415 ARRAY_SIZE(drm_content_type_enum_list));
1417 if (dev->mode_config.content_type_property == NULL)
1422 EXPORT_SYMBOL(drm_mode_create_content_type_property);
1425 * drm_mode_create_suggested_offset_properties - create suggests offset properties
1428 * Create the the suggested x/y offset property for connectors.
1430 int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
1432 if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
1435 dev->mode_config.suggested_x_property =
1436 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
1438 dev->mode_config.suggested_y_property =
1439 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
1441 if (dev->mode_config.suggested_x_property == NULL ||
1442 dev->mode_config.suggested_y_property == NULL)
1446 EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
1449 * drm_connector_set_path_property - set tile property on connector
1450 * @connector: connector to set property on.
1451 * @path: path to use for property; must not be NULL.
1453 * This creates a property to expose to userspace to specify a
1454 * connector path. This is mainly used for DisplayPort MST where
1455 * connectors have a topology and we want to allow userspace to give
1456 * them more meaningful names.
1459 * Zero on success, negative errno on failure.
1461 int drm_connector_set_path_property(struct drm_connector *connector,
1464 struct drm_device *dev = connector->dev;
1467 ret = drm_property_replace_global_blob(dev,
1468 &connector->path_blob_ptr,
1472 dev->mode_config.path_property);
1475 EXPORT_SYMBOL(drm_connector_set_path_property);
1478 * drm_connector_set_tile_property - set tile property on connector
1479 * @connector: connector to set property on.
1481 * This looks up the tile information for a connector, and creates a
1482 * property for userspace to parse if it exists. The property is of
1483 * the form of 8 integers using ':' as a separator.
1486 * Zero on success, errno on failure.
1488 int drm_connector_set_tile_property(struct drm_connector *connector)
1490 struct drm_device *dev = connector->dev;
1494 if (!connector->has_tile) {
1495 ret = drm_property_replace_global_blob(dev,
1496 &connector->tile_blob_ptr,
1500 dev->mode_config.tile_property);
1504 snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
1505 connector->tile_group->id, connector->tile_is_single_monitor,
1506 connector->num_h_tile, connector->num_v_tile,
1507 connector->tile_h_loc, connector->tile_v_loc,
1508 connector->tile_h_size, connector->tile_v_size);
1510 ret = drm_property_replace_global_blob(dev,
1511 &connector->tile_blob_ptr,
1515 dev->mode_config.tile_property);
1518 EXPORT_SYMBOL(drm_connector_set_tile_property);
1521 * drm_connector_update_edid_property - update the edid property of a connector
1522 * @connector: drm connector
1523 * @edid: new value of the edid property
1525 * This function creates a new blob modeset object and assigns its id to the
1526 * connector's edid property.
1529 * Zero on success, negative errno on failure.
1531 int drm_connector_update_edid_property(struct drm_connector *connector,
1532 const struct edid *edid)
1534 struct drm_device *dev = connector->dev;
1538 /* ignore requests to set edid when overridden */
1539 if (connector->override_edid)
1543 size = EDID_LENGTH * (1 + edid->extensions);
1545 /* Set the display info, using edid if available, otherwise
1546 * reseting the values to defaults. This duplicates the work
1547 * done in drm_add_edid_modes, but that function is not
1548 * consistently called before this one in all drivers and the
1549 * computation is cheap enough that it seems better to
1550 * duplicate it rather than attempt to ensure some arbitrary
1551 * ordering of calls.
1554 drm_add_display_info(connector, edid);
1556 drm_reset_display_info(connector);
1558 drm_object_property_set_value(&connector->base,
1559 dev->mode_config.non_desktop_property,
1560 connector->display_info.non_desktop);
1562 ret = drm_property_replace_global_blob(dev,
1563 &connector->edid_blob_ptr,
1567 dev->mode_config.edid_property);
1570 EXPORT_SYMBOL(drm_connector_update_edid_property);
1573 * drm_connector_set_link_status_property - Set link status property of a connector
1574 * @connector: drm connector
1575 * @link_status: new value of link status property (0: Good, 1: Bad)
1577 * In usual working scenario, this link status property will always be set to
1578 * "GOOD". If something fails during or after a mode set, the kernel driver
1579 * may set this link status property to "BAD". The caller then needs to send a
1580 * hotplug uevent for userspace to re-check the valid modes through
1581 * GET_CONNECTOR_IOCTL and retry modeset.
1583 * Note: Drivers cannot rely on userspace to support this property and
1584 * issue a modeset. As such, they may choose to handle issues (like
1585 * re-training a link) without userspace's intervention.
1587 * The reason for adding this property is to handle link training failures, but
1588 * it is not limited to DP or link training. For example, if we implement
1589 * asynchronous setcrtc, this property can be used to report any failures in that.
1591 void drm_connector_set_link_status_property(struct drm_connector *connector,
1592 uint64_t link_status)
1594 struct drm_device *dev = connector->dev;
1596 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1597 connector->state->link_status = link_status;
1598 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1600 EXPORT_SYMBOL(drm_connector_set_link_status_property);
1603 * drm_connector_init_panel_orientation_property -
1604 * initialize the connecters panel_orientation property
1605 * @connector: connector for which to init the panel-orientation property.
1606 * @width: width in pixels of the panel, used for panel quirk detection
1607 * @height: height in pixels of the panel, used for panel quirk detection
1609 * This function should only be called for built-in panels, after setting
1610 * connector->display_info.panel_orientation first (if known).
1612 * This function will check for platform specific (e.g. DMI based) quirks
1613 * overriding display_info.panel_orientation first, then if panel_orientation
1614 * is not DRM_MODE_PANEL_ORIENTATION_UNKNOWN it will attach the
1615 * "panel orientation" property to the connector.
1618 * Zero on success, negative errno on failure.
1620 int drm_connector_init_panel_orientation_property(
1621 struct drm_connector *connector, int width, int height)
1623 struct drm_device *dev = connector->dev;
1624 struct drm_display_info *info = &connector->display_info;
1625 struct drm_property *prop;
1626 int orientation_quirk;
1628 orientation_quirk = drm_get_panel_orientation_quirk(width, height);
1629 if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
1630 info->panel_orientation = orientation_quirk;
1632 if (info->panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
1635 prop = dev->mode_config.panel_orientation_property;
1637 prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1638 "panel orientation",
1639 drm_panel_orientation_enum_list,
1640 ARRAY_SIZE(drm_panel_orientation_enum_list));
1644 dev->mode_config.panel_orientation_property = prop;
1647 drm_object_attach_property(&connector->base, prop,
1648 info->panel_orientation);
1651 EXPORT_SYMBOL(drm_connector_init_panel_orientation_property);
1653 int drm_connector_set_obj_prop(struct drm_mode_object *obj,
1654 struct drm_property *property,
1658 struct drm_connector *connector = obj_to_connector(obj);
1660 /* Do DPMS ourselves */
1661 if (property == connector->dev->mode_config.dpms_property) {
1662 ret = (*connector->funcs->dpms)(connector, (int)value);
1663 } else if (connector->funcs->set_property)
1664 ret = connector->funcs->set_property(connector, property, value);
1667 drm_object_property_set_value(&connector->base, property, value);
1671 int drm_connector_property_set_ioctl(struct drm_device *dev,
1672 void *data, struct drm_file *file_priv)
1674 struct drm_mode_connector_set_property *conn_set_prop = data;
1675 struct drm_mode_obj_set_property obj_set_prop = {
1676 .value = conn_set_prop->value,
1677 .prop_id = conn_set_prop->prop_id,
1678 .obj_id = conn_set_prop->connector_id,
1679 .obj_type = DRM_MODE_OBJECT_CONNECTOR
1682 /* It does all the locking and checking we need */
1683 return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
1686 static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
1688 /* For atomic drivers only state objects are synchronously updated and
1689 * protected by modeset locks, so check those first. */
1690 if (connector->state)
1691 return connector->state->best_encoder;
1692 return connector->encoder;
1696 drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
1697 const struct list_head *export_list,
1698 const struct drm_file *file_priv)
1701 * If user-space hasn't configured the driver to expose the stereo 3D
1702 * modes, don't expose them.
1704 if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
1707 * If user-space hasn't configured the driver to expose the modes
1708 * with aspect-ratio, don't expose them. However if such a mode
1709 * is unique, let it be exposed, but reset the aspect-ratio flags
1710 * while preparing the list of user-modes.
1712 if (!file_priv->aspect_ratio_allowed) {
1713 struct drm_display_mode *mode_itr;
1715 list_for_each_entry(mode_itr, export_list, export_head)
1716 if (drm_mode_match(mode_itr, mode,
1717 DRM_MODE_MATCH_TIMINGS |
1718 DRM_MODE_MATCH_CLOCK |
1719 DRM_MODE_MATCH_FLAGS |
1720 DRM_MODE_MATCH_3D_FLAGS))
1727 int drm_mode_getconnector(struct drm_device *dev, void *data,
1728 struct drm_file *file_priv)
1730 struct drm_mode_get_connector *out_resp = data;
1731 struct drm_connector *connector;
1732 struct drm_encoder *encoder;
1733 struct drm_display_mode *mode;
1735 int encoders_count = 0;
1739 struct drm_mode_modeinfo u_mode;
1740 struct drm_mode_modeinfo __user *mode_ptr;
1741 uint32_t __user *encoder_ptr;
1742 LIST_HEAD(export_list);
1744 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1747 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
1749 connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
1753 drm_connector_for_each_possible_encoder(connector, encoder, i)
1756 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
1758 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
1760 drm_connector_for_each_possible_encoder(connector, encoder, i) {
1761 if (put_user(encoder->base.id, encoder_ptr + copied)) {
1768 out_resp->count_encoders = encoders_count;
1770 out_resp->connector_id = connector->base.id;
1771 out_resp->connector_type = connector->connector_type;
1772 out_resp->connector_type_id = connector->connector_type_id;
1774 mutex_lock(&dev->mode_config.mutex);
1775 if (out_resp->count_modes == 0) {
1776 connector->funcs->fill_modes(connector,
1777 dev->mode_config.max_width,
1778 dev->mode_config.max_height);
1781 out_resp->mm_width = connector->display_info.width_mm;
1782 out_resp->mm_height = connector->display_info.height_mm;
1783 out_resp->subpixel = connector->display_info.subpixel_order;
1784 out_resp->connection = connector->status;
1786 /* delayed so we get modes regardless of pre-fill_modes state */
1787 list_for_each_entry(mode, &connector->modes, head)
1788 if (drm_mode_expose_to_userspace(mode, &export_list,
1790 list_add_tail(&mode->export_head, &export_list);
1795 * This ioctl is called twice, once to determine how much space is
1796 * needed, and the 2nd time to fill it.
1797 * The modes that need to be exposed to the user are maintained in the
1798 * 'export_list'. When the ioctl is called first time to determine the,
1799 * space, the export_list gets filled, to find the no.of modes. In the
1800 * 2nd time, the user modes are filled, one by one from the export_list.
1802 if ((out_resp->count_modes >= mode_count) && mode_count) {
1804 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
1805 list_for_each_entry(mode, &export_list, export_head) {
1806 drm_mode_convert_to_umode(&u_mode, mode);
1808 * Reset aspect ratio flags of user-mode, if modes with
1809 * aspect-ratio are not supported.
1811 if (!file_priv->aspect_ratio_allowed)
1812 u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
1813 if (copy_to_user(mode_ptr + copied,
1814 &u_mode, sizeof(u_mode))) {
1816 mutex_unlock(&dev->mode_config.mutex);
1823 out_resp->count_modes = mode_count;
1824 mutex_unlock(&dev->mode_config.mutex);
1826 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1827 encoder = drm_connector_get_encoder(connector);
1829 out_resp->encoder_id = encoder->base.id;
1831 out_resp->encoder_id = 0;
1833 /* Only grab properties after probing, to make sure EDID and other
1834 * properties reflect the latest status. */
1835 ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
1836 (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
1837 (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
1838 &out_resp->count_props);
1839 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1842 drm_connector_put(connector);
1851 * Tile groups are used to represent tiled monitors with a unique integer
1852 * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
1853 * we store this in a tile group, so we have a common identifier for all tiles
1854 * in a monitor group. The property is called "TILE". Drivers can manage tile
1855 * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
1856 * drm_mode_get_tile_group(). But this is only needed for internal panels where
1857 * the tile group information is exposed through a non-standard way.
1860 static void drm_tile_group_free(struct kref *kref)
1862 struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
1863 struct drm_device *dev = tg->dev;
1864 mutex_lock(&dev->mode_config.idr_mutex);
1865 idr_remove(&dev->mode_config.tile_idr, tg->id);
1866 mutex_unlock(&dev->mode_config.idr_mutex);
1871 * drm_mode_put_tile_group - drop a reference to a tile group.
1873 * @tg: tile group to drop reference to.
1875 * drop reference to tile group and free if 0.
1877 void drm_mode_put_tile_group(struct drm_device *dev,
1878 struct drm_tile_group *tg)
1880 kref_put(&tg->refcount, drm_tile_group_free);
1882 EXPORT_SYMBOL(drm_mode_put_tile_group);
1885 * drm_mode_get_tile_group - get a reference to an existing tile group
1887 * @topology: 8-bytes unique per monitor.
1889 * Use the unique bytes to get a reference to an existing tile group.
1892 * tile group or NULL if not found.
1894 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1897 struct drm_tile_group *tg;
1899 mutex_lock(&dev->mode_config.idr_mutex);
1900 idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
1901 if (!memcmp(tg->group_data, topology, 8)) {
1902 if (!kref_get_unless_zero(&tg->refcount))
1904 mutex_unlock(&dev->mode_config.idr_mutex);
1908 mutex_unlock(&dev->mode_config.idr_mutex);
1911 EXPORT_SYMBOL(drm_mode_get_tile_group);
1914 * drm_mode_create_tile_group - create a tile group from a displayid description
1916 * @topology: 8-bytes unique per monitor.
1918 * Create a tile group for the unique monitor, and get a unique
1919 * identifier for the tile group.
1922 * new tile group or error.
1924 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1927 struct drm_tile_group *tg;
1930 tg = kzalloc(sizeof(*tg), GFP_KERNEL);
1932 return ERR_PTR(-ENOMEM);
1934 kref_init(&tg->refcount);
1935 memcpy(tg->group_data, topology, 8);
1938 mutex_lock(&dev->mode_config.idr_mutex);
1939 ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
1947 mutex_unlock(&dev->mode_config.idr_mutex);
1950 EXPORT_SYMBOL(drm_mode_create_tile_group);