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
24 #include <drm/drm_connector.h>
25 #include <drm/drm_edid.h>
26 #include <drm/drm_encoder.h>
27 #include <drm/drm_utils.h>
29 #include "drm_crtc_internal.h"
30 #include "drm_internal.h"
35 * In DRM connectors are the general abstraction for display sinks, and include
36 * als fixed panels or anything else that can display pixels in some form. As
37 * opposed to all other KMS objects representing hardware (like CRTC, encoder or
38 * plane abstractions) connectors can be hotplugged and unplugged at runtime.
39 * Hence they are reference-counted using drm_connector_get() and
40 * drm_connector_put().
42 * KMS driver must create, initialize, register and attach at a &struct
43 * drm_connector for each such sink. The instance is created as other KMS
44 * objects and initialized by setting the following fields. The connector is
45 * initialized with a call to drm_connector_init() with a pointer to the
46 * &struct drm_connector_funcs and a connector type, and then exposed to
47 * userspace with a call to drm_connector_register().
49 * Connectors must be attached to an encoder to be used. For devices that map
50 * connectors to encoders 1:1, the connector should be attached at
51 * initialization time with a call to drm_connector_attach_encoder(). The
52 * driver must also set the &drm_connector.encoder field to point to the
55 * For connectors which are not fixed (like built-in panels) the driver needs to
56 * support hotplug notifications. The simplest way to do that is by using the
57 * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
58 * hardware support for hotplug interrupts. Connectors with hardware hotplug
59 * support can instead use e.g. drm_helper_hpd_irq_event().
62 struct drm_conn_prop_enum_list {
69 * Connector and encoder types.
71 static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
72 { DRM_MODE_CONNECTOR_Unknown, "Unknown" },
73 { DRM_MODE_CONNECTOR_VGA, "VGA" },
74 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
75 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
76 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
77 { DRM_MODE_CONNECTOR_Composite, "Composite" },
78 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
79 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
80 { DRM_MODE_CONNECTOR_Component, "Component" },
81 { DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
82 { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
83 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
84 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
85 { DRM_MODE_CONNECTOR_TV, "TV" },
86 { DRM_MODE_CONNECTOR_eDP, "eDP" },
87 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
88 { DRM_MODE_CONNECTOR_DSI, "DSI" },
89 { DRM_MODE_CONNECTOR_DPI, "DPI" },
90 { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
93 void drm_connector_ida_init(void)
97 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
98 ida_init(&drm_connector_enum_list[i].ida);
101 void drm_connector_ida_destroy(void)
105 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
106 ida_destroy(&drm_connector_enum_list[i].ida);
110 * drm_connector_get_cmdline_mode - reads the user's cmdline mode
111 * @connector: connector to quwery
113 * The kernel supports per-connector configuration of its consoles through
114 * use of the video= parameter. This function parses that option and
115 * extracts the user's specified mode (or enable/disable status) for a
116 * particular connector. This is typically only used during the early fbdev
119 static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
121 struct drm_cmdline_mode *mode = &connector->cmdline_mode;
124 if (fb_get_options(connector->name, &option))
127 if (!drm_mode_parse_command_line_for_connector(option,
133 DRM_INFO("forcing %s connector %s\n", connector->name,
134 drm_get_connector_force_name(mode->force));
135 connector->force = mode->force;
138 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
140 mode->xres, mode->yres,
141 mode->refresh_specified ? mode->refresh : 60,
142 mode->rb ? " reduced blanking" : "",
143 mode->margins ? " with margins" : "",
144 mode->interlace ? " interlaced" : "");
147 static void drm_connector_free(struct kref *kref)
149 struct drm_connector *connector =
150 container_of(kref, struct drm_connector, base.refcount);
151 struct drm_device *dev = connector->dev;
153 drm_mode_object_unregister(dev, &connector->base);
154 connector->funcs->destroy(connector);
157 void drm_connector_free_work_fn(struct work_struct *work)
159 struct drm_connector *connector, *n;
160 struct drm_device *dev =
161 container_of(work, struct drm_device, mode_config.connector_free_work);
162 struct drm_mode_config *config = &dev->mode_config;
164 struct llist_node *freed;
166 spin_lock_irqsave(&config->connector_list_lock, flags);
167 freed = llist_del_all(&config->connector_free_list);
168 spin_unlock_irqrestore(&config->connector_list_lock, flags);
170 llist_for_each_entry_safe(connector, n, freed, free_node) {
171 drm_mode_object_unregister(dev, &connector->base);
172 connector->funcs->destroy(connector);
177 * drm_connector_init - Init a preallocated connector
179 * @connector: the connector to init
180 * @funcs: callbacks for this connector
181 * @connector_type: user visible type of the connector
183 * Initialises a preallocated connector. Connectors should be
184 * subclassed as part of driver connector objects.
187 * Zero on success, error code on failure.
189 int drm_connector_init(struct drm_device *dev,
190 struct drm_connector *connector,
191 const struct drm_connector_funcs *funcs,
194 struct drm_mode_config *config = &dev->mode_config;
196 struct ida *connector_ida =
197 &drm_connector_enum_list[connector_type].ida;
199 WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
200 (!funcs->atomic_destroy_state ||
201 !funcs->atomic_duplicate_state));
203 ret = __drm_mode_object_add(dev, &connector->base,
204 DRM_MODE_OBJECT_CONNECTOR,
205 false, drm_connector_free);
209 connector->base.properties = &connector->properties;
210 connector->dev = dev;
211 connector->funcs = funcs;
213 /* connector index is used with 32bit bitmasks */
214 ret = ida_simple_get(&config->connector_ida, 0, 32, GFP_KERNEL);
216 DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
217 drm_connector_enum_list[connector_type].name,
221 connector->index = ret;
224 connector->connector_type = connector_type;
225 connector->connector_type_id =
226 ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
227 if (connector->connector_type_id < 0) {
228 ret = connector->connector_type_id;
232 kasprintf(GFP_KERNEL, "%s-%d",
233 drm_connector_enum_list[connector_type].name,
234 connector->connector_type_id);
235 if (!connector->name) {
237 goto out_put_type_id;
240 INIT_LIST_HEAD(&connector->probed_modes);
241 INIT_LIST_HEAD(&connector->modes);
242 mutex_init(&connector->mutex);
243 connector->edid_blob_ptr = NULL;
244 connector->status = connector_status_unknown;
245 connector->display_info.panel_orientation =
246 DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
248 drm_connector_get_cmdline_mode(connector);
250 /* We should add connectors at the end to avoid upsetting the connector
252 spin_lock_irq(&config->connector_list_lock);
253 list_add_tail(&connector->head, &config->connector_list);
254 config->num_connector++;
255 spin_unlock_irq(&config->connector_list_lock);
257 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
258 connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
259 drm_object_attach_property(&connector->base,
260 config->edid_property,
263 drm_object_attach_property(&connector->base,
264 config->dpms_property, 0);
266 drm_object_attach_property(&connector->base,
267 config->link_status_property,
270 drm_object_attach_property(&connector->base,
271 config->non_desktop_property,
274 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
275 drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
278 connector->debugfs_entry = NULL;
281 ida_simple_remove(connector_ida, connector->connector_type_id);
284 ida_simple_remove(&config->connector_ida, connector->index);
287 drm_mode_object_unregister(dev, &connector->base);
291 EXPORT_SYMBOL(drm_connector_init);
294 * drm_connector_attach_encoder - attach a connector to an encoder
295 * @connector: connector to attach
296 * @encoder: encoder to attach @connector to
298 * This function links up a connector to an encoder. Note that the routing
299 * restrictions between encoders and crtcs are exposed to userspace through the
300 * possible_clones and possible_crtcs bitmasks.
303 * Zero on success, negative errno on failure.
305 int drm_connector_attach_encoder(struct drm_connector *connector,
306 struct drm_encoder *encoder)
311 * In the past, drivers have attempted to model the static association
312 * of connector to encoder in simple connector/encoder devices using a
313 * direct assignment of connector->encoder = encoder. This connection
314 * is a logical one and the responsibility of the core, so drivers are
315 * expected not to mess with this.
317 * Note that the error return should've been enough here, but a large
318 * majority of drivers ignores the return value, so add in a big WARN
319 * to get people's attention.
321 if (WARN_ON(connector->encoder))
324 for (i = 0; i < ARRAY_SIZE(connector->encoder_ids); i++) {
325 if (connector->encoder_ids[i] == 0) {
326 connector->encoder_ids[i] = encoder->base.id;
332 EXPORT_SYMBOL(drm_connector_attach_encoder);
335 * drm_connector_has_possible_encoder - check if the connector and encoder are assosicated with each other
336 * @connector: the connector
337 * @encoder: the encoder
340 * True if @encoder is one of the possible encoders for @connector.
342 bool drm_connector_has_possible_encoder(struct drm_connector *connector,
343 struct drm_encoder *encoder)
345 struct drm_encoder *enc;
348 drm_connector_for_each_possible_encoder(connector, enc, i) {
355 EXPORT_SYMBOL(drm_connector_has_possible_encoder);
357 static void drm_mode_remove(struct drm_connector *connector,
358 struct drm_display_mode *mode)
360 list_del(&mode->head);
361 drm_mode_destroy(connector->dev, mode);
365 * drm_connector_cleanup - cleans up an initialised connector
366 * @connector: connector to cleanup
368 * Cleans up the connector but doesn't free the object.
370 void drm_connector_cleanup(struct drm_connector *connector)
372 struct drm_device *dev = connector->dev;
373 struct drm_display_mode *mode, *t;
375 /* The connector should have been removed from userspace long before
376 * it is finally destroyed.
378 if (WARN_ON(connector->registration_state ==
379 DRM_CONNECTOR_REGISTERED))
380 drm_connector_unregister(connector);
382 if (connector->tile_group) {
383 drm_mode_put_tile_group(dev, connector->tile_group);
384 connector->tile_group = NULL;
387 list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
388 drm_mode_remove(connector, mode);
390 list_for_each_entry_safe(mode, t, &connector->modes, head)
391 drm_mode_remove(connector, mode);
393 ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida,
394 connector->connector_type_id);
396 ida_simple_remove(&dev->mode_config.connector_ida,
399 kfree(connector->display_info.bus_formats);
400 drm_mode_object_unregister(dev, &connector->base);
401 kfree(connector->name);
402 connector->name = NULL;
403 spin_lock_irq(&dev->mode_config.connector_list_lock);
404 list_del(&connector->head);
405 dev->mode_config.num_connector--;
406 spin_unlock_irq(&dev->mode_config.connector_list_lock);
408 WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
409 if (connector->state && connector->funcs->atomic_destroy_state)
410 connector->funcs->atomic_destroy_state(connector,
413 mutex_destroy(&connector->mutex);
415 memset(connector, 0, sizeof(*connector));
418 drm_sysfs_hotplug_event(dev);
420 EXPORT_SYMBOL(drm_connector_cleanup);
423 * drm_connector_register - register a connector
424 * @connector: the connector to register
426 * Register userspace interfaces for a connector
429 * Zero on success, error code on failure.
431 int drm_connector_register(struct drm_connector *connector)
435 if (!connector->dev->registered)
438 mutex_lock(&connector->mutex);
439 if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
442 ret = drm_sysfs_connector_add(connector);
446 ret = drm_debugfs_connector_add(connector);
451 if (connector->funcs->late_register) {
452 ret = connector->funcs->late_register(connector);
457 drm_mode_object_register(connector->dev, &connector->base);
459 connector->registration_state = DRM_CONNECTOR_REGISTERED;
463 drm_debugfs_connector_remove(connector);
465 drm_sysfs_connector_remove(connector);
467 mutex_unlock(&connector->mutex);
470 EXPORT_SYMBOL(drm_connector_register);
473 * drm_connector_unregister - unregister a connector
474 * @connector: the connector to unregister
476 * Unregister userspace interfaces for a connector
478 void drm_connector_unregister(struct drm_connector *connector)
480 mutex_lock(&connector->mutex);
481 if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
482 mutex_unlock(&connector->mutex);
486 if (connector->funcs->early_unregister)
487 connector->funcs->early_unregister(connector);
489 drm_sysfs_connector_remove(connector);
490 drm_debugfs_connector_remove(connector);
492 connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
493 mutex_unlock(&connector->mutex);
495 EXPORT_SYMBOL(drm_connector_unregister);
497 void drm_connector_unregister_all(struct drm_device *dev)
499 struct drm_connector *connector;
500 struct drm_connector_list_iter conn_iter;
502 drm_connector_list_iter_begin(dev, &conn_iter);
503 drm_for_each_connector_iter(connector, &conn_iter)
504 drm_connector_unregister(connector);
505 drm_connector_list_iter_end(&conn_iter);
508 int drm_connector_register_all(struct drm_device *dev)
510 struct drm_connector *connector;
511 struct drm_connector_list_iter conn_iter;
514 drm_connector_list_iter_begin(dev, &conn_iter);
515 drm_for_each_connector_iter(connector, &conn_iter) {
516 ret = drm_connector_register(connector);
520 drm_connector_list_iter_end(&conn_iter);
523 drm_connector_unregister_all(dev);
528 * drm_get_connector_status_name - return a string for connector status
529 * @status: connector status to compute name of
531 * In contrast to the other drm_get_*_name functions this one here returns a
532 * const pointer and hence is threadsafe.
534 const char *drm_get_connector_status_name(enum drm_connector_status status)
536 if (status == connector_status_connected)
538 else if (status == connector_status_disconnected)
539 return "disconnected";
543 EXPORT_SYMBOL(drm_get_connector_status_name);
546 * drm_get_connector_force_name - return a string for connector force
547 * @force: connector force to get name of
549 * Returns: const pointer to name.
551 const char *drm_get_connector_force_name(enum drm_connector_force force)
554 case DRM_FORCE_UNSPECIFIED:
555 return "unspecified";
560 case DRM_FORCE_ON_DIGITAL:
567 #ifdef CONFIG_LOCKDEP
568 static struct lockdep_map connector_list_iter_dep_map = {
569 .name = "drm_connector_list_iter"
574 * drm_connector_list_iter_begin - initialize a connector_list iterator
576 * @iter: connector_list iterator
578 * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
579 * must always be cleaned up again by calling drm_connector_list_iter_end().
580 * Iteration itself happens using drm_connector_list_iter_next() or
581 * drm_for_each_connector_iter().
583 void drm_connector_list_iter_begin(struct drm_device *dev,
584 struct drm_connector_list_iter *iter)
588 lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
590 EXPORT_SYMBOL(drm_connector_list_iter_begin);
593 * Extra-safe connector put function that works in any context. Should only be
594 * used from the connector_iter functions, where we never really expect to
595 * actually release the connector when dropping our final reference.
598 __drm_connector_put_safe(struct drm_connector *conn)
600 struct drm_mode_config *config = &conn->dev->mode_config;
602 lockdep_assert_held(&config->connector_list_lock);
604 if (!refcount_dec_and_test(&conn->base.refcount.refcount))
607 llist_add(&conn->free_node, &config->connector_free_list);
608 schedule_work(&config->connector_free_work);
612 * drm_connector_list_iter_next - return next connector
613 * @iter: connector_list iterator
615 * Returns the next connector for @iter, or NULL when the list walk has
618 struct drm_connector *
619 drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
621 struct drm_connector *old_conn = iter->conn;
622 struct drm_mode_config *config = &iter->dev->mode_config;
623 struct list_head *lhead;
626 spin_lock_irqsave(&config->connector_list_lock, flags);
627 lhead = old_conn ? &old_conn->head : &config->connector_list;
630 if (lhead->next == &config->connector_list) {
636 iter->conn = list_entry(lhead, struct drm_connector, head);
638 /* loop until it's not a zombie connector */
639 } while (!kref_get_unless_zero(&iter->conn->base.refcount));
642 __drm_connector_put_safe(old_conn);
643 spin_unlock_irqrestore(&config->connector_list_lock, flags);
647 EXPORT_SYMBOL(drm_connector_list_iter_next);
650 * drm_connector_list_iter_end - tear down a connector_list iterator
651 * @iter: connector_list iterator
653 * Tears down @iter and releases any resources (like &drm_connector references)
654 * acquired while walking the list. This must always be called, both when the
655 * iteration completes fully or when it was aborted without walking the entire
658 void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
660 struct drm_mode_config *config = &iter->dev->mode_config;
665 spin_lock_irqsave(&config->connector_list_lock, flags);
666 __drm_connector_put_safe(iter->conn);
667 spin_unlock_irqrestore(&config->connector_list_lock, flags);
669 lock_release(&connector_list_iter_dep_map, 0, _RET_IP_);
671 EXPORT_SYMBOL(drm_connector_list_iter_end);
673 static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
674 { SubPixelUnknown, "Unknown" },
675 { SubPixelHorizontalRGB, "Horizontal RGB" },
676 { SubPixelHorizontalBGR, "Horizontal BGR" },
677 { SubPixelVerticalRGB, "Vertical RGB" },
678 { SubPixelVerticalBGR, "Vertical BGR" },
679 { SubPixelNone, "None" },
683 * drm_get_subpixel_order_name - return a string for a given subpixel enum
684 * @order: enum of subpixel_order
686 * Note you could abuse this and return something out of bounds, but that
687 * would be a caller error. No unscrubbed user data should make it here.
689 const char *drm_get_subpixel_order_name(enum subpixel_order order)
691 return drm_subpixel_enum_list[order].name;
693 EXPORT_SYMBOL(drm_get_subpixel_order_name);
695 static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
696 { DRM_MODE_DPMS_ON, "On" },
697 { DRM_MODE_DPMS_STANDBY, "Standby" },
698 { DRM_MODE_DPMS_SUSPEND, "Suspend" },
699 { DRM_MODE_DPMS_OFF, "Off" }
701 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
703 static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
704 { DRM_MODE_LINK_STATUS_GOOD, "Good" },
705 { DRM_MODE_LINK_STATUS_BAD, "Bad" },
709 * drm_display_info_set_bus_formats - set the supported bus formats
710 * @info: display info to store bus formats in
711 * @formats: array containing the supported bus formats
712 * @num_formats: the number of entries in the fmts array
714 * Store the supported bus formats in display info structure.
715 * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
716 * a full list of available formats.
718 int drm_display_info_set_bus_formats(struct drm_display_info *info,
720 unsigned int num_formats)
724 if (!formats && num_formats)
727 if (formats && num_formats) {
728 fmts = kmemdup(formats, sizeof(*formats) * num_formats,
734 kfree(info->bus_formats);
735 info->bus_formats = fmts;
736 info->num_bus_formats = num_formats;
740 EXPORT_SYMBOL(drm_display_info_set_bus_formats);
742 /* Optional connector properties. */
743 static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
744 { DRM_MODE_SCALE_NONE, "None" },
745 { DRM_MODE_SCALE_FULLSCREEN, "Full" },
746 { DRM_MODE_SCALE_CENTER, "Center" },
747 { DRM_MODE_SCALE_ASPECT, "Full aspect" },
750 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
751 { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
752 { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
753 { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
756 static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
757 { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
758 { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
759 { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
760 { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
761 { DRM_MODE_CONTENT_TYPE_GAME, "Game" },
764 static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
765 { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" },
766 { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" },
767 { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" },
768 { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" },
771 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
772 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
773 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
774 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
776 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
778 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
779 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
780 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
781 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
783 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
784 drm_dvi_i_subconnector_enum_list)
786 static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
787 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
788 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
789 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
790 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
791 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
793 DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
795 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
796 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
797 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
798 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
799 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
800 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
802 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
803 drm_tv_subconnector_enum_list)
805 static struct drm_prop_enum_list drm_cp_enum_list[] = {
806 { DRM_MODE_CONTENT_PROTECTION_UNDESIRED, "Undesired" },
807 { DRM_MODE_CONTENT_PROTECTION_DESIRED, "Desired" },
808 { DRM_MODE_CONTENT_PROTECTION_ENABLED, "Enabled" },
810 DRM_ENUM_NAME_FN(drm_get_content_protection_name, drm_cp_enum_list)
813 * DOC: standard connector properties
815 * DRM connectors have a few standardized properties:
818 * Blob property which contains the current EDID read from the sink. This
819 * is useful to parse sink identification information like vendor, model
820 * and serial. Drivers should update this property by calling
821 * drm_connector_update_edid_property(), usually after having parsed
822 * the EDID using drm_add_edid_modes(). Userspace cannot change this
825 * Legacy property for setting the power state of the connector. For atomic
826 * drivers this is only provided for backwards compatibility with existing
827 * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
828 * connector is linked to. Drivers should never set this property directly,
829 * it is handled by the DRM core by calling the &drm_connector_funcs.dpms
830 * callback. For atomic drivers the remapping to the "ACTIVE" property is
831 * implemented in the DRM core. This is the only standard connector
832 * property that userspace can change.
834 * Note that this property cannot be set through the MODE_ATOMIC ioctl,
835 * userspace must use "ACTIVE" on the CRTC instead.
839 * For userspace also running on legacy drivers the "DPMS" semantics are a
840 * lot more complicated. First, userspace cannot rely on the "DPMS" value
841 * returned by the GETCONNECTOR actually reflecting reality, because many
842 * drivers fail to update it. For atomic drivers this is taken care of in
843 * drm_atomic_helper_update_legacy_modeset_state().
845 * The second issue is that the DPMS state is only well-defined when the
846 * connector is connected to a CRTC. In atomic the DRM core enforces that
847 * "ACTIVE" is off in such a case, no such checks exists for "DPMS".
849 * Finally, when enabling an output using the legacy SETCONFIG ioctl then
850 * "DPMS" is forced to ON. But see above, that might not be reflected in
851 * the software value on legacy drivers.
853 * Summarizing: Only set "DPMS" when the connector is known to be enabled,
854 * assume that a successful SETCONFIG call also sets "DPMS" to on, and
855 * never read back the value of "DPMS" because it can be incorrect.
857 * Connector path property to identify how this sink is physically
858 * connected. Used by DP MST. This should be set by calling
859 * drm_connector_set_path_property(), in the case of DP MST with the
860 * path property the MST manager created. Userspace cannot change this
863 * Connector tile group property to indicate how a set of DRM connector
864 * compose together into one logical screen. This is used by both high-res
865 * external screens (often only using a single cable, but exposing multiple
866 * DP MST sinks), or high-res integrated panels (like dual-link DSI) which
867 * are not gen-locked. Note that for tiled panels which are genlocked, like
868 * dual-link LVDS or dual-link DSI, the driver should try to not expose the
869 * tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
870 * should update this value using drm_connector_set_tile_property().
871 * Userspace cannot change this property.
873 * Connector link-status property to indicate the status of link. The
874 * default value of link-status is "GOOD". If something fails during or
875 * after modeset, the kernel driver may set this to "BAD" and issue a
876 * hotplug uevent. Drivers should update this value using
877 * drm_connector_set_link_status_property().
879 * Indicates the output should be ignored for purposes of displaying a
880 * standard desktop environment or console. This is most likely because
881 * the output device is not rectilinear.
882 * Content Protection:
883 * This property is used by userspace to request the kernel protect future
884 * content communicated over the link. When requested, kernel will apply
885 * the appropriate means of protection (most often HDCP), and use the
886 * property to tell userspace the protection is active.
888 * Drivers can set this up by calling
889 * drm_connector_attach_content_protection_property() on initialization.
891 * The value of this property can be one of the following:
893 * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
894 * The link is not protected, content is transmitted in the clear.
895 * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
896 * Userspace has requested content protection, but the link is not
897 * currently protected. When in this state, kernel should enable
898 * Content Protection as soon as possible.
899 * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
900 * Userspace has requested content protection, and the link is
901 * protected. Only the driver can set the property to this value.
902 * If userspace attempts to set to ENABLED, kernel will return
907 * - DESIRED state should be preserved until userspace de-asserts it by
908 * setting the property to UNDESIRED. This means ENABLED should only
909 * transition to UNDESIRED when the user explicitly requests it.
910 * - If the state is DESIRED, kernel should attempt to re-authenticate the
911 * link whenever possible. This includes across disable/enable, dpms,
912 * hotplug, downstream device changes, link status failures, etc..
913 * - Userspace is responsible for polling the property to determine when
914 * the value transitions from ENABLED to DESIRED. This signifies the link
915 * is no longer protected and userspace should take appropriate action
916 * (whatever that might be).
918 * Connectors also have one standardized atomic property:
921 * Mode object ID of the &drm_crtc this connector should be connected to.
923 * Connectors for LCD panels may also have one standardized property:
926 * On some devices the LCD panel is mounted in the casing in such a way
927 * that the up/top side of the panel does not match with the top side of
928 * the device. Userspace can use this property to check for this.
929 * Note that input coordinates from touchscreens (input devices with
930 * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
931 * coordinates, so if userspace rotates the picture to adjust for
932 * the orientation it must also apply the same transformation to the
933 * touchscreen input coordinates. This property is initialized by calling
934 * drm_connector_init_panel_orientation_property().
937 * This property defines how a non-native mode is upscaled to the native
938 * mode of an LCD panel:
941 * No upscaling happens, scaling is left to the panel. Not all
942 * drivers expose this mode.
944 * The output is upscaled to the full resolution of the panel,
945 * ignoring the aspect ratio.
947 * No upscaling happens, the output is centered within the native
948 * resolution the panel.
950 * The output is upscaled to maximize either the width or height
951 * while retaining the aspect ratio.
953 * This property should be set up by calling
954 * drm_connector_attach_scaling_mode_property(). Note that drivers
955 * can also expose this property to external outputs, in which case they
956 * must support "None", which should be the default (since external screens
957 * have a built-in scaler).
960 int drm_connector_create_standard_properties(struct drm_device *dev)
962 struct drm_property *prop;
964 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
965 DRM_MODE_PROP_IMMUTABLE,
969 dev->mode_config.edid_property = prop;
971 prop = drm_property_create_enum(dev, 0,
972 "DPMS", drm_dpms_enum_list,
973 ARRAY_SIZE(drm_dpms_enum_list));
976 dev->mode_config.dpms_property = prop;
978 prop = drm_property_create(dev,
980 DRM_MODE_PROP_IMMUTABLE,
984 dev->mode_config.path_property = prop;
986 prop = drm_property_create(dev,
988 DRM_MODE_PROP_IMMUTABLE,
992 dev->mode_config.tile_property = prop;
994 prop = drm_property_create_enum(dev, 0, "link-status",
995 drm_link_status_enum_list,
996 ARRAY_SIZE(drm_link_status_enum_list));
999 dev->mode_config.link_status_property = prop;
1001 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
1004 dev->mode_config.non_desktop_property = prop;
1010 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1013 * Called by a driver the first time a DVI-I connector is made.
1015 int drm_mode_create_dvi_i_properties(struct drm_device *dev)
1017 struct drm_property *dvi_i_selector;
1018 struct drm_property *dvi_i_subconnector;
1020 if (dev->mode_config.dvi_i_select_subconnector_property)
1024 drm_property_create_enum(dev, 0,
1025 "select subconnector",
1026 drm_dvi_i_select_enum_list,
1027 ARRAY_SIZE(drm_dvi_i_select_enum_list));
1028 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
1030 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1032 drm_dvi_i_subconnector_enum_list,
1033 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
1034 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
1038 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
1041 * DOC: HDMI connector properties
1043 * content type (HDMI specific):
1044 * Indicates content type setting to be used in HDMI infoframes to indicate
1045 * content type for the external device, so that it adjusts it's display
1046 * settings accordingly.
1048 * The value of this property can be one of the following:
1051 * Content type is unknown
1053 * Content type is graphics
1055 * Content type is photo
1057 * Content type is cinema
1059 * Content type is game
1061 * Drivers can set up this property by calling
1062 * drm_connector_attach_content_type_property(). Decoding to
1063 * infoframe values is done through drm_hdmi_avi_infoframe_content_type().
1067 * drm_connector_attach_content_type_property - attach content-type property
1068 * @connector: connector to attach content type property on.
1070 * Called by a driver the first time a HDMI connector is made.
1072 int drm_connector_attach_content_type_property(struct drm_connector *connector)
1074 if (!drm_mode_create_content_type_property(connector->dev))
1075 drm_object_attach_property(&connector->base,
1076 connector->dev->mode_config.content_type_property,
1077 DRM_MODE_CONTENT_TYPE_NO_DATA);
1080 EXPORT_SYMBOL(drm_connector_attach_content_type_property);
1084 * drm_hdmi_avi_infoframe_content_type() - fill the HDMI AVI infoframe
1085 * content type information, based
1086 * on correspondent DRM property.
1087 * @frame: HDMI AVI infoframe
1088 * @conn_state: DRM display connector state
1091 void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame,
1092 const struct drm_connector_state *conn_state)
1094 switch (conn_state->content_type) {
1095 case DRM_MODE_CONTENT_TYPE_GRAPHICS:
1096 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
1098 case DRM_MODE_CONTENT_TYPE_CINEMA:
1099 frame->content_type = HDMI_CONTENT_TYPE_CINEMA;
1101 case DRM_MODE_CONTENT_TYPE_GAME:
1102 frame->content_type = HDMI_CONTENT_TYPE_GAME;
1104 case DRM_MODE_CONTENT_TYPE_PHOTO:
1105 frame->content_type = HDMI_CONTENT_TYPE_PHOTO;
1108 /* Graphics is the default(0) */
1109 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
1112 frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA;
1114 EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type);
1117 * drm_create_tv_properties - create TV specific connector properties
1119 * @num_modes: number of different TV formats (modes) supported
1120 * @modes: array of pointers to strings containing name of each format
1122 * Called by a driver's TV initialization routine, this function creates
1123 * the TV specific connector properties for a given device. Caller is
1124 * responsible for allocating a list of format names and passing them to
1127 int drm_mode_create_tv_properties(struct drm_device *dev,
1128 unsigned int num_modes,
1129 const char * const modes[])
1131 struct drm_property *tv_selector;
1132 struct drm_property *tv_subconnector;
1135 if (dev->mode_config.tv_select_subconnector_property)
1139 * Basic connector properties
1141 tv_selector = drm_property_create_enum(dev, 0,
1142 "select subconnector",
1143 drm_tv_select_enum_list,
1144 ARRAY_SIZE(drm_tv_select_enum_list));
1148 dev->mode_config.tv_select_subconnector_property = tv_selector;
1151 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1153 drm_tv_subconnector_enum_list,
1154 ARRAY_SIZE(drm_tv_subconnector_enum_list));
1155 if (!tv_subconnector)
1157 dev->mode_config.tv_subconnector_property = tv_subconnector;
1160 * Other, TV specific properties: margins & TV modes.
1162 dev->mode_config.tv_left_margin_property =
1163 drm_property_create_range(dev, 0, "left margin", 0, 100);
1164 if (!dev->mode_config.tv_left_margin_property)
1167 dev->mode_config.tv_right_margin_property =
1168 drm_property_create_range(dev, 0, "right margin", 0, 100);
1169 if (!dev->mode_config.tv_right_margin_property)
1172 dev->mode_config.tv_top_margin_property =
1173 drm_property_create_range(dev, 0, "top margin", 0, 100);
1174 if (!dev->mode_config.tv_top_margin_property)
1177 dev->mode_config.tv_bottom_margin_property =
1178 drm_property_create_range(dev, 0, "bottom margin", 0, 100);
1179 if (!dev->mode_config.tv_bottom_margin_property)
1182 dev->mode_config.tv_mode_property =
1183 drm_property_create(dev, DRM_MODE_PROP_ENUM,
1185 if (!dev->mode_config.tv_mode_property)
1188 for (i = 0; i < num_modes; i++)
1189 drm_property_add_enum(dev->mode_config.tv_mode_property,
1192 dev->mode_config.tv_brightness_property =
1193 drm_property_create_range(dev, 0, "brightness", 0, 100);
1194 if (!dev->mode_config.tv_brightness_property)
1197 dev->mode_config.tv_contrast_property =
1198 drm_property_create_range(dev, 0, "contrast", 0, 100);
1199 if (!dev->mode_config.tv_contrast_property)
1202 dev->mode_config.tv_flicker_reduction_property =
1203 drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
1204 if (!dev->mode_config.tv_flicker_reduction_property)
1207 dev->mode_config.tv_overscan_property =
1208 drm_property_create_range(dev, 0, "overscan", 0, 100);
1209 if (!dev->mode_config.tv_overscan_property)
1212 dev->mode_config.tv_saturation_property =
1213 drm_property_create_range(dev, 0, "saturation", 0, 100);
1214 if (!dev->mode_config.tv_saturation_property)
1217 dev->mode_config.tv_hue_property =
1218 drm_property_create_range(dev, 0, "hue", 0, 100);
1219 if (!dev->mode_config.tv_hue_property)
1226 EXPORT_SYMBOL(drm_mode_create_tv_properties);
1229 * drm_mode_create_scaling_mode_property - create scaling mode property
1232 * Called by a driver the first time it's needed, must be attached to desired
1235 * Atomic drivers should use drm_connector_attach_scaling_mode_property()
1236 * instead to correctly assign &drm_connector_state.picture_aspect_ratio
1237 * in the atomic state.
1239 int drm_mode_create_scaling_mode_property(struct drm_device *dev)
1241 struct drm_property *scaling_mode;
1243 if (dev->mode_config.scaling_mode_property)
1247 drm_property_create_enum(dev, 0, "scaling mode",
1248 drm_scaling_mode_enum_list,
1249 ARRAY_SIZE(drm_scaling_mode_enum_list));
1251 dev->mode_config.scaling_mode_property = scaling_mode;
1255 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
1258 * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
1259 * @connector: connector to attach scaling mode property on.
1260 * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
1262 * This is used to add support for scaling mode to atomic drivers.
1263 * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio
1264 * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
1266 * This is the atomic version of drm_mode_create_scaling_mode_property().
1269 * Zero on success, negative errno on failure.
1271 int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
1272 u32 scaling_mode_mask)
1274 struct drm_device *dev = connector->dev;
1275 struct drm_property *scaling_mode_property;
1277 const unsigned valid_scaling_mode_mask =
1278 (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
1280 if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
1281 scaling_mode_mask & ~valid_scaling_mode_mask))
1284 scaling_mode_property =
1285 drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
1286 hweight32(scaling_mode_mask));
1288 if (!scaling_mode_property)
1291 for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
1294 if (!(BIT(i) & scaling_mode_mask))
1297 ret = drm_property_add_enum(scaling_mode_property,
1298 drm_scaling_mode_enum_list[i].type,
1299 drm_scaling_mode_enum_list[i].name);
1302 drm_property_destroy(dev, scaling_mode_property);
1308 drm_object_attach_property(&connector->base,
1309 scaling_mode_property, 0);
1311 connector->scaling_mode_property = scaling_mode_property;
1315 EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
1318 * drm_connector_attach_content_protection_property - attach content protection
1321 * @connector: connector to attach CP property on.
1323 * This is used to add support for content protection on select connectors.
1324 * Content Protection is intentionally vague to allow for different underlying
1325 * technologies, however it is most implemented by HDCP.
1327 * The content protection will be set to &drm_connector_state.content_protection
1330 * Zero on success, negative errno on failure.
1332 int drm_connector_attach_content_protection_property(
1333 struct drm_connector *connector)
1335 struct drm_device *dev = connector->dev;
1336 struct drm_property *prop;
1338 prop = drm_property_create_enum(dev, 0, "Content Protection",
1340 ARRAY_SIZE(drm_cp_enum_list));
1344 drm_object_attach_property(&connector->base, prop,
1345 DRM_MODE_CONTENT_PROTECTION_UNDESIRED);
1347 connector->content_protection_property = prop;
1351 EXPORT_SYMBOL(drm_connector_attach_content_protection_property);
1354 * drm_mode_create_aspect_ratio_property - create aspect ratio property
1357 * Called by a driver the first time it's needed, must be attached to desired
1361 * Zero on success, negative errno on failure.
1363 int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
1365 if (dev->mode_config.aspect_ratio_property)
1368 dev->mode_config.aspect_ratio_property =
1369 drm_property_create_enum(dev, 0, "aspect ratio",
1370 drm_aspect_ratio_enum_list,
1371 ARRAY_SIZE(drm_aspect_ratio_enum_list));
1373 if (dev->mode_config.aspect_ratio_property == NULL)
1378 EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
1381 * drm_mode_create_content_type_property - create content type property
1384 * Called by a driver the first time it's needed, must be attached to desired
1388 * Zero on success, negative errno on failure.
1390 int drm_mode_create_content_type_property(struct drm_device *dev)
1392 if (dev->mode_config.content_type_property)
1395 dev->mode_config.content_type_property =
1396 drm_property_create_enum(dev, 0, "content type",
1397 drm_content_type_enum_list,
1398 ARRAY_SIZE(drm_content_type_enum_list));
1400 if (dev->mode_config.content_type_property == NULL)
1405 EXPORT_SYMBOL(drm_mode_create_content_type_property);
1408 * drm_mode_create_suggested_offset_properties - create suggests offset properties
1411 * Create the the suggested x/y offset property for connectors.
1413 int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
1415 if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
1418 dev->mode_config.suggested_x_property =
1419 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
1421 dev->mode_config.suggested_y_property =
1422 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
1424 if (dev->mode_config.suggested_x_property == NULL ||
1425 dev->mode_config.suggested_y_property == NULL)
1429 EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
1432 * drm_connector_set_path_property - set tile property on connector
1433 * @connector: connector to set property on.
1434 * @path: path to use for property; must not be NULL.
1436 * This creates a property to expose to userspace to specify a
1437 * connector path. This is mainly used for DisplayPort MST where
1438 * connectors have a topology and we want to allow userspace to give
1439 * them more meaningful names.
1442 * Zero on success, negative errno on failure.
1444 int drm_connector_set_path_property(struct drm_connector *connector,
1447 struct drm_device *dev = connector->dev;
1450 ret = drm_property_replace_global_blob(dev,
1451 &connector->path_blob_ptr,
1455 dev->mode_config.path_property);
1458 EXPORT_SYMBOL(drm_connector_set_path_property);
1461 * drm_connector_set_tile_property - set tile property on connector
1462 * @connector: connector to set property on.
1464 * This looks up the tile information for a connector, and creates a
1465 * property for userspace to parse if it exists. The property is of
1466 * the form of 8 integers using ':' as a separator.
1469 * Zero on success, errno on failure.
1471 int drm_connector_set_tile_property(struct drm_connector *connector)
1473 struct drm_device *dev = connector->dev;
1477 if (!connector->has_tile) {
1478 ret = drm_property_replace_global_blob(dev,
1479 &connector->tile_blob_ptr,
1483 dev->mode_config.tile_property);
1487 snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
1488 connector->tile_group->id, connector->tile_is_single_monitor,
1489 connector->num_h_tile, connector->num_v_tile,
1490 connector->tile_h_loc, connector->tile_v_loc,
1491 connector->tile_h_size, connector->tile_v_size);
1493 ret = drm_property_replace_global_blob(dev,
1494 &connector->tile_blob_ptr,
1498 dev->mode_config.tile_property);
1501 EXPORT_SYMBOL(drm_connector_set_tile_property);
1504 * drm_connector_update_edid_property - update the edid property of a connector
1505 * @connector: drm connector
1506 * @edid: new value of the edid property
1508 * This function creates a new blob modeset object and assigns its id to the
1509 * connector's edid property.
1512 * Zero on success, negative errno on failure.
1514 int drm_connector_update_edid_property(struct drm_connector *connector,
1515 const struct edid *edid)
1517 struct drm_device *dev = connector->dev;
1521 /* ignore requests to set edid when overridden */
1522 if (connector->override_edid)
1526 size = EDID_LENGTH * (1 + edid->extensions);
1528 /* Set the display info, using edid if available, otherwise
1529 * reseting the values to defaults. This duplicates the work
1530 * done in drm_add_edid_modes, but that function is not
1531 * consistently called before this one in all drivers and the
1532 * computation is cheap enough that it seems better to
1533 * duplicate it rather than attempt to ensure some arbitrary
1534 * ordering of calls.
1537 drm_add_display_info(connector, edid);
1539 drm_reset_display_info(connector);
1541 drm_object_property_set_value(&connector->base,
1542 dev->mode_config.non_desktop_property,
1543 connector->display_info.non_desktop);
1545 ret = drm_property_replace_global_blob(dev,
1546 &connector->edid_blob_ptr,
1550 dev->mode_config.edid_property);
1553 EXPORT_SYMBOL(drm_connector_update_edid_property);
1556 * drm_connector_set_link_status_property - Set link status property of a connector
1557 * @connector: drm connector
1558 * @link_status: new value of link status property (0: Good, 1: Bad)
1560 * In usual working scenario, this link status property will always be set to
1561 * "GOOD". If something fails during or after a mode set, the kernel driver
1562 * may set this link status property to "BAD". The caller then needs to send a
1563 * hotplug uevent for userspace to re-check the valid modes through
1564 * GET_CONNECTOR_IOCTL and retry modeset.
1566 * Note: Drivers cannot rely on userspace to support this property and
1567 * issue a modeset. As such, they may choose to handle issues (like
1568 * re-training a link) without userspace's intervention.
1570 * The reason for adding this property is to handle link training failures, but
1571 * it is not limited to DP or link training. For example, if we implement
1572 * asynchronous setcrtc, this property can be used to report any failures in that.
1574 void drm_connector_set_link_status_property(struct drm_connector *connector,
1575 uint64_t link_status)
1577 struct drm_device *dev = connector->dev;
1579 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1580 connector->state->link_status = link_status;
1581 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1583 EXPORT_SYMBOL(drm_connector_set_link_status_property);
1586 * drm_connector_init_panel_orientation_property -
1587 * initialize the connecters panel_orientation property
1588 * @connector: connector for which to init the panel-orientation property.
1589 * @width: width in pixels of the panel, used for panel quirk detection
1590 * @height: height in pixels of the panel, used for panel quirk detection
1592 * This function should only be called for built-in panels, after setting
1593 * connector->display_info.panel_orientation first (if known).
1595 * This function will check for platform specific (e.g. DMI based) quirks
1596 * overriding display_info.panel_orientation first, then if panel_orientation
1597 * is not DRM_MODE_PANEL_ORIENTATION_UNKNOWN it will attach the
1598 * "panel orientation" property to the connector.
1601 * Zero on success, negative errno on failure.
1603 int drm_connector_init_panel_orientation_property(
1604 struct drm_connector *connector, int width, int height)
1606 struct drm_device *dev = connector->dev;
1607 struct drm_display_info *info = &connector->display_info;
1608 struct drm_property *prop;
1609 int orientation_quirk;
1611 orientation_quirk = drm_get_panel_orientation_quirk(width, height);
1612 if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
1613 info->panel_orientation = orientation_quirk;
1615 if (info->panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
1618 prop = dev->mode_config.panel_orientation_property;
1620 prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1621 "panel orientation",
1622 drm_panel_orientation_enum_list,
1623 ARRAY_SIZE(drm_panel_orientation_enum_list));
1627 dev->mode_config.panel_orientation_property = prop;
1630 drm_object_attach_property(&connector->base, prop,
1631 info->panel_orientation);
1634 EXPORT_SYMBOL(drm_connector_init_panel_orientation_property);
1636 int drm_connector_set_obj_prop(struct drm_mode_object *obj,
1637 struct drm_property *property,
1641 struct drm_connector *connector = obj_to_connector(obj);
1643 /* Do DPMS ourselves */
1644 if (property == connector->dev->mode_config.dpms_property) {
1645 ret = (*connector->funcs->dpms)(connector, (int)value);
1646 } else if (connector->funcs->set_property)
1647 ret = connector->funcs->set_property(connector, property, value);
1650 drm_object_property_set_value(&connector->base, property, value);
1654 int drm_connector_property_set_ioctl(struct drm_device *dev,
1655 void *data, struct drm_file *file_priv)
1657 struct drm_mode_connector_set_property *conn_set_prop = data;
1658 struct drm_mode_obj_set_property obj_set_prop = {
1659 .value = conn_set_prop->value,
1660 .prop_id = conn_set_prop->prop_id,
1661 .obj_id = conn_set_prop->connector_id,
1662 .obj_type = DRM_MODE_OBJECT_CONNECTOR
1665 /* It does all the locking and checking we need */
1666 return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
1669 static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
1671 /* For atomic drivers only state objects are synchronously updated and
1672 * protected by modeset locks, so check those first. */
1673 if (connector->state)
1674 return connector->state->best_encoder;
1675 return connector->encoder;
1679 drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
1680 const struct list_head *export_list,
1681 const struct drm_file *file_priv)
1684 * If user-space hasn't configured the driver to expose the stereo 3D
1685 * modes, don't expose them.
1687 if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
1690 * If user-space hasn't configured the driver to expose the modes
1691 * with aspect-ratio, don't expose them. However if such a mode
1692 * is unique, let it be exposed, but reset the aspect-ratio flags
1693 * while preparing the list of user-modes.
1695 if (!file_priv->aspect_ratio_allowed) {
1696 struct drm_display_mode *mode_itr;
1698 list_for_each_entry(mode_itr, export_list, export_head)
1699 if (drm_mode_match(mode_itr, mode,
1700 DRM_MODE_MATCH_TIMINGS |
1701 DRM_MODE_MATCH_CLOCK |
1702 DRM_MODE_MATCH_FLAGS |
1703 DRM_MODE_MATCH_3D_FLAGS))
1710 int drm_mode_getconnector(struct drm_device *dev, void *data,
1711 struct drm_file *file_priv)
1713 struct drm_mode_get_connector *out_resp = data;
1714 struct drm_connector *connector;
1715 struct drm_encoder *encoder;
1716 struct drm_display_mode *mode;
1718 int encoders_count = 0;
1722 struct drm_mode_modeinfo u_mode;
1723 struct drm_mode_modeinfo __user *mode_ptr;
1724 uint32_t __user *encoder_ptr;
1725 LIST_HEAD(export_list);
1727 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1730 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
1732 connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
1736 drm_connector_for_each_possible_encoder(connector, encoder, i)
1739 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
1741 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
1743 drm_connector_for_each_possible_encoder(connector, encoder, i) {
1744 if (put_user(encoder->base.id, encoder_ptr + copied)) {
1751 out_resp->count_encoders = encoders_count;
1753 out_resp->connector_id = connector->base.id;
1754 out_resp->connector_type = connector->connector_type;
1755 out_resp->connector_type_id = connector->connector_type_id;
1757 mutex_lock(&dev->mode_config.mutex);
1758 if (out_resp->count_modes == 0) {
1759 connector->funcs->fill_modes(connector,
1760 dev->mode_config.max_width,
1761 dev->mode_config.max_height);
1764 out_resp->mm_width = connector->display_info.width_mm;
1765 out_resp->mm_height = connector->display_info.height_mm;
1766 out_resp->subpixel = connector->display_info.subpixel_order;
1767 out_resp->connection = connector->status;
1769 /* delayed so we get modes regardless of pre-fill_modes state */
1770 list_for_each_entry(mode, &connector->modes, head)
1771 if (drm_mode_expose_to_userspace(mode, &export_list,
1773 list_add_tail(&mode->export_head, &export_list);
1778 * This ioctl is called twice, once to determine how much space is
1779 * needed, and the 2nd time to fill it.
1780 * The modes that need to be exposed to the user are maintained in the
1781 * 'export_list'. When the ioctl is called first time to determine the,
1782 * space, the export_list gets filled, to find the no.of modes. In the
1783 * 2nd time, the user modes are filled, one by one from the export_list.
1785 if ((out_resp->count_modes >= mode_count) && mode_count) {
1787 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
1788 list_for_each_entry(mode, &export_list, export_head) {
1789 drm_mode_convert_to_umode(&u_mode, mode);
1791 * Reset aspect ratio flags of user-mode, if modes with
1792 * aspect-ratio are not supported.
1794 if (!file_priv->aspect_ratio_allowed)
1795 u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
1796 if (copy_to_user(mode_ptr + copied,
1797 &u_mode, sizeof(u_mode))) {
1799 mutex_unlock(&dev->mode_config.mutex);
1806 out_resp->count_modes = mode_count;
1807 mutex_unlock(&dev->mode_config.mutex);
1809 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1810 encoder = drm_connector_get_encoder(connector);
1812 out_resp->encoder_id = encoder->base.id;
1814 out_resp->encoder_id = 0;
1816 /* Only grab properties after probing, to make sure EDID and other
1817 * properties reflect the latest status. */
1818 ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
1819 (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
1820 (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
1821 &out_resp->count_props);
1822 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1825 drm_connector_put(connector);
1834 * Tile groups are used to represent tiled monitors with a unique integer
1835 * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
1836 * we store this in a tile group, so we have a common identifier for all tiles
1837 * in a monitor group. The property is called "TILE". Drivers can manage tile
1838 * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
1839 * drm_mode_get_tile_group(). But this is only needed for internal panels where
1840 * the tile group information is exposed through a non-standard way.
1843 static void drm_tile_group_free(struct kref *kref)
1845 struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
1846 struct drm_device *dev = tg->dev;
1847 mutex_lock(&dev->mode_config.idr_mutex);
1848 idr_remove(&dev->mode_config.tile_idr, tg->id);
1849 mutex_unlock(&dev->mode_config.idr_mutex);
1854 * drm_mode_put_tile_group - drop a reference to a tile group.
1856 * @tg: tile group to drop reference to.
1858 * drop reference to tile group and free if 0.
1860 void drm_mode_put_tile_group(struct drm_device *dev,
1861 struct drm_tile_group *tg)
1863 kref_put(&tg->refcount, drm_tile_group_free);
1865 EXPORT_SYMBOL(drm_mode_put_tile_group);
1868 * drm_mode_get_tile_group - get a reference to an existing tile group
1870 * @topology: 8-bytes unique per monitor.
1872 * Use the unique bytes to get a reference to an existing tile group.
1875 * tile group or NULL if not found.
1877 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1880 struct drm_tile_group *tg;
1882 mutex_lock(&dev->mode_config.idr_mutex);
1883 idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
1884 if (!memcmp(tg->group_data, topology, 8)) {
1885 if (!kref_get_unless_zero(&tg->refcount))
1887 mutex_unlock(&dev->mode_config.idr_mutex);
1891 mutex_unlock(&dev->mode_config.idr_mutex);
1894 EXPORT_SYMBOL(drm_mode_get_tile_group);
1897 * drm_mode_create_tile_group - create a tile group from a displayid description
1899 * @topology: 8-bytes unique per monitor.
1901 * Create a tile group for the unique monitor, and get a unique
1902 * identifier for the tile group.
1905 * new tile group or error.
1907 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1910 struct drm_tile_group *tg;
1913 tg = kzalloc(sizeof(*tg), GFP_KERNEL);
1915 return ERR_PTR(-ENOMEM);
1917 kref_init(&tg->refcount);
1918 memcpy(tg->group_data, topology, 8);
1921 mutex_lock(&dev->mode_config.idr_mutex);
1922 ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
1930 mutex_unlock(&dev->mode_config.idr_mutex);
1933 EXPORT_SYMBOL(drm_mode_create_tile_group);