xref: /linux/drivers/gpu/drm/drm_connector.c (revision 1e55a53a28d3e52a68e11917dd25a216c3e7c182)
152217195SDaniel Vetter /*
252217195SDaniel Vetter  * Copyright (c) 2016 Intel Corporation
352217195SDaniel Vetter  *
452217195SDaniel Vetter  * Permission to use, copy, modify, distribute, and sell this software and its
552217195SDaniel Vetter  * documentation for any purpose is hereby granted without fee, provided that
652217195SDaniel Vetter  * the above copyright notice appear in all copies and that both that copyright
752217195SDaniel Vetter  * notice and this permission notice appear in supporting documentation, and
852217195SDaniel Vetter  * that the name of the copyright holders not be used in advertising or
952217195SDaniel Vetter  * publicity pertaining to distribution of the software without specific,
1052217195SDaniel Vetter  * written prior permission.  The copyright holders make no representations
1152217195SDaniel Vetter  * about the suitability of this software for any purpose.  It is provided "as
1252217195SDaniel Vetter  * is" without express or implied warranty.
1352217195SDaniel Vetter  *
1452217195SDaniel Vetter  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1552217195SDaniel Vetter  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1652217195SDaniel Vetter  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1752217195SDaniel Vetter  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1852217195SDaniel Vetter  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1952217195SDaniel Vetter  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2052217195SDaniel Vetter  * OF THIS SOFTWARE.
2152217195SDaniel Vetter  */
2252217195SDaniel Vetter 
2352217195SDaniel Vetter #include <drm/drm_connector.h>
2452217195SDaniel Vetter #include <drm/drm_edid.h>
259338203cSLaurent Pinchart #include <drm/drm_encoder.h>
268d70f395SHans de Goede #include <drm/drm_utils.h>
2799f45e32SDaniel Vetter #include <drm/drm_print.h>
2899f45e32SDaniel Vetter #include <drm/drm_drv.h>
2999f45e32SDaniel Vetter #include <drm/drm_file.h>
3099f45e32SDaniel Vetter 
3199f45e32SDaniel Vetter #include <linux/uaccess.h>
3252217195SDaniel Vetter 
3352217195SDaniel Vetter #include "drm_crtc_internal.h"
3452217195SDaniel Vetter #include "drm_internal.h"
3552217195SDaniel Vetter 
36ae2a6da8SDaniel Vetter /**
37ae2a6da8SDaniel Vetter  * DOC: overview
38ae2a6da8SDaniel Vetter  *
39ae2a6da8SDaniel Vetter  * In DRM connectors are the general abstraction for display sinks, and include
40ae2a6da8SDaniel Vetter  * als fixed panels or anything else that can display pixels in some form. As
41ae2a6da8SDaniel Vetter  * opposed to all other KMS objects representing hardware (like CRTC, encoder or
42ae2a6da8SDaniel Vetter  * plane abstractions) connectors can be hotplugged and unplugged at runtime.
43ad093607SThierry Reding  * Hence they are reference-counted using drm_connector_get() and
44ad093607SThierry Reding  * drm_connector_put().
45ae2a6da8SDaniel Vetter  *
46d574528aSDaniel Vetter  * KMS driver must create, initialize, register and attach at a &struct
47d574528aSDaniel Vetter  * drm_connector for each such sink. The instance is created as other KMS
48aec97460SDaniel Vetter  * objects and initialized by setting the following fields. The connector is
49aec97460SDaniel Vetter  * initialized with a call to drm_connector_init() with a pointer to the
50aec97460SDaniel Vetter  * &struct drm_connector_funcs and a connector type, and then exposed to
51aec97460SDaniel Vetter  * userspace with a call to drm_connector_register().
52ae2a6da8SDaniel Vetter  *
53ae2a6da8SDaniel Vetter  * Connectors must be attached to an encoder to be used. For devices that map
54ae2a6da8SDaniel Vetter  * connectors to encoders 1:1, the connector should be attached at
55cde4c44dSDaniel Vetter  * initialization time with a call to drm_connector_attach_encoder(). The
56d574528aSDaniel Vetter  * driver must also set the &drm_connector.encoder field to point to the
57ae2a6da8SDaniel Vetter  * attached encoder.
58ae2a6da8SDaniel Vetter  *
59ae2a6da8SDaniel Vetter  * For connectors which are not fixed (like built-in panels) the driver needs to
60ae2a6da8SDaniel Vetter  * support hotplug notifications. The simplest way to do that is by using the
61ae2a6da8SDaniel Vetter  * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
62ae2a6da8SDaniel Vetter  * hardware support for hotplug interrupts. Connectors with hardware hotplug
63ae2a6da8SDaniel Vetter  * support can instead use e.g. drm_helper_hpd_irq_event().
64ae2a6da8SDaniel Vetter  */
65ae2a6da8SDaniel Vetter 
6652217195SDaniel Vetter struct drm_conn_prop_enum_list {
6752217195SDaniel Vetter 	int type;
6852217195SDaniel Vetter 	const char *name;
6952217195SDaniel Vetter 	struct ida ida;
7052217195SDaniel Vetter };
7152217195SDaniel Vetter 
7252217195SDaniel Vetter /*
7352217195SDaniel Vetter  * Connector and encoder types.
7452217195SDaniel Vetter  */
7552217195SDaniel Vetter static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
7652217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Unknown, "Unknown" },
7752217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
7852217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
7952217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
8052217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
8152217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Composite, "Composite" },
8252217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
8352217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
8452217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Component, "Component" },
8552217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
8652217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },
8752217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
8852217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
8952217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_TV, "TV" },
9052217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_eDP, "eDP" },
9152217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
9252217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DSI, "DSI" },
9352217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DPI, "DPI" },
94935774cdSBrian Starkey 	{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
9552217195SDaniel Vetter };
9652217195SDaniel Vetter 
9752217195SDaniel Vetter void drm_connector_ida_init(void)
9852217195SDaniel Vetter {
9952217195SDaniel Vetter 	int i;
10052217195SDaniel Vetter 
10152217195SDaniel Vetter 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
10252217195SDaniel Vetter 		ida_init(&drm_connector_enum_list[i].ida);
10352217195SDaniel Vetter }
10452217195SDaniel Vetter 
10552217195SDaniel Vetter void drm_connector_ida_destroy(void)
10652217195SDaniel Vetter {
10752217195SDaniel Vetter 	int i;
10852217195SDaniel Vetter 
10952217195SDaniel Vetter 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
11052217195SDaniel Vetter 		ida_destroy(&drm_connector_enum_list[i].ida);
11152217195SDaniel Vetter }
11252217195SDaniel Vetter 
11352217195SDaniel Vetter /**
11452217195SDaniel Vetter  * drm_connector_get_cmdline_mode - reads the user's cmdline mode
11552217195SDaniel Vetter  * @connector: connector to quwery
11652217195SDaniel Vetter  *
117ae2a6da8SDaniel Vetter  * The kernel supports per-connector configuration of its consoles through
11852217195SDaniel Vetter  * use of the video= parameter. This function parses that option and
11952217195SDaniel Vetter  * extracts the user's specified mode (or enable/disable status) for a
12052217195SDaniel Vetter  * particular connector. This is typically only used during the early fbdev
12152217195SDaniel Vetter  * setup.
12252217195SDaniel Vetter  */
12352217195SDaniel Vetter static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
12452217195SDaniel Vetter {
12552217195SDaniel Vetter 	struct drm_cmdline_mode *mode = &connector->cmdline_mode;
12652217195SDaniel Vetter 	char *option = NULL;
12752217195SDaniel Vetter 
12852217195SDaniel Vetter 	if (fb_get_options(connector->name, &option))
12952217195SDaniel Vetter 		return;
13052217195SDaniel Vetter 
13152217195SDaniel Vetter 	if (!drm_mode_parse_command_line_for_connector(option,
13252217195SDaniel Vetter 						       connector,
13352217195SDaniel Vetter 						       mode))
13452217195SDaniel Vetter 		return;
13552217195SDaniel Vetter 
13652217195SDaniel Vetter 	if (mode->force) {
1376140cf20SJani Nikula 		DRM_INFO("forcing %s connector %s\n", connector->name,
1386140cf20SJani Nikula 			 drm_get_connector_force_name(mode->force));
13952217195SDaniel Vetter 		connector->force = mode->force;
14052217195SDaniel Vetter 	}
14152217195SDaniel Vetter 
14252217195SDaniel Vetter 	DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
14352217195SDaniel Vetter 		      connector->name,
14452217195SDaniel Vetter 		      mode->xres, mode->yres,
14552217195SDaniel Vetter 		      mode->refresh_specified ? mode->refresh : 60,
14652217195SDaniel Vetter 		      mode->rb ? " reduced blanking" : "",
14752217195SDaniel Vetter 		      mode->margins ? " with margins" : "",
14852217195SDaniel Vetter 		      mode->interlace ?  " interlaced" : "");
14952217195SDaniel Vetter }
15052217195SDaniel Vetter 
15152217195SDaniel Vetter static void drm_connector_free(struct kref *kref)
15252217195SDaniel Vetter {
15352217195SDaniel Vetter 	struct drm_connector *connector =
15452217195SDaniel Vetter 		container_of(kref, struct drm_connector, base.refcount);
15552217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
15652217195SDaniel Vetter 
15752217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
15852217195SDaniel Vetter 	connector->funcs->destroy(connector);
15952217195SDaniel Vetter }
16052217195SDaniel Vetter 
161ea497bb9SDaniel Vetter void drm_connector_free_work_fn(struct work_struct *work)
162a703c550SDaniel Vetter {
163ea497bb9SDaniel Vetter 	struct drm_connector *connector, *n;
164ea497bb9SDaniel Vetter 	struct drm_device *dev =
165ea497bb9SDaniel Vetter 		container_of(work, struct drm_device, mode_config.connector_free_work);
166ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &dev->mode_config;
167ea497bb9SDaniel Vetter 	unsigned long flags;
168ea497bb9SDaniel Vetter 	struct llist_node *freed;
169a703c550SDaniel Vetter 
170ea497bb9SDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
171ea497bb9SDaniel Vetter 	freed = llist_del_all(&config->connector_free_list);
172ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
173ea497bb9SDaniel Vetter 
174ea497bb9SDaniel Vetter 	llist_for_each_entry_safe(connector, n, freed, free_node) {
175a703c550SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
176a703c550SDaniel Vetter 		connector->funcs->destroy(connector);
177a703c550SDaniel Vetter 	}
178ea497bb9SDaniel Vetter }
179a703c550SDaniel Vetter 
18052217195SDaniel Vetter /**
18152217195SDaniel Vetter  * drm_connector_init - Init a preallocated connector
18252217195SDaniel Vetter  * @dev: DRM device
18352217195SDaniel Vetter  * @connector: the connector to init
18452217195SDaniel Vetter  * @funcs: callbacks for this connector
18552217195SDaniel Vetter  * @connector_type: user visible type of the connector
18652217195SDaniel Vetter  *
18752217195SDaniel Vetter  * Initialises a preallocated connector. Connectors should be
18852217195SDaniel Vetter  * subclassed as part of driver connector objects.
18952217195SDaniel Vetter  *
19052217195SDaniel Vetter  * Returns:
19152217195SDaniel Vetter  * Zero on success, error code on failure.
19252217195SDaniel Vetter  */
19352217195SDaniel Vetter int drm_connector_init(struct drm_device *dev,
19452217195SDaniel Vetter 		       struct drm_connector *connector,
19552217195SDaniel Vetter 		       const struct drm_connector_funcs *funcs,
19652217195SDaniel Vetter 		       int connector_type)
19752217195SDaniel Vetter {
19852217195SDaniel Vetter 	struct drm_mode_config *config = &dev->mode_config;
19952217195SDaniel Vetter 	int ret;
20052217195SDaniel Vetter 	struct ida *connector_ida =
20152217195SDaniel Vetter 		&drm_connector_enum_list[connector_type].ida;
20252217195SDaniel Vetter 
203ba1f665fSHaneen Mohammed 	WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
204ba1f665fSHaneen Mohammed 		(!funcs->atomic_destroy_state ||
205ba1f665fSHaneen Mohammed 		 !funcs->atomic_duplicate_state));
206ba1f665fSHaneen Mohammed 
2072135ea7aSThierry Reding 	ret = __drm_mode_object_add(dev, &connector->base,
20852217195SDaniel Vetter 				    DRM_MODE_OBJECT_CONNECTOR,
20952217195SDaniel Vetter 				    false, drm_connector_free);
21052217195SDaniel Vetter 	if (ret)
211613051daSDaniel Vetter 		return ret;
21252217195SDaniel Vetter 
21352217195SDaniel Vetter 	connector->base.properties = &connector->properties;
21452217195SDaniel Vetter 	connector->dev = dev;
21552217195SDaniel Vetter 	connector->funcs = funcs;
21652217195SDaniel Vetter 
2172a8d3eacSVille Syrjälä 	/* connector index is used with 32bit bitmasks */
2182a8d3eacSVille Syrjälä 	ret = ida_simple_get(&config->connector_ida, 0, 32, GFP_KERNEL);
2192a8d3eacSVille Syrjälä 	if (ret < 0) {
2202a8d3eacSVille Syrjälä 		DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
2212a8d3eacSVille Syrjälä 			      drm_connector_enum_list[connector_type].name,
2222a8d3eacSVille Syrjälä 			      ret);
22352217195SDaniel Vetter 		goto out_put;
2242a8d3eacSVille Syrjälä 	}
22552217195SDaniel Vetter 	connector->index = ret;
22652217195SDaniel Vetter 	ret = 0;
22752217195SDaniel Vetter 
22852217195SDaniel Vetter 	connector->connector_type = connector_type;
22952217195SDaniel Vetter 	connector->connector_type_id =
23052217195SDaniel Vetter 		ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
23152217195SDaniel Vetter 	if (connector->connector_type_id < 0) {
23252217195SDaniel Vetter 		ret = connector->connector_type_id;
23352217195SDaniel Vetter 		goto out_put_id;
23452217195SDaniel Vetter 	}
23552217195SDaniel Vetter 	connector->name =
23652217195SDaniel Vetter 		kasprintf(GFP_KERNEL, "%s-%d",
23752217195SDaniel Vetter 			  drm_connector_enum_list[connector_type].name,
23852217195SDaniel Vetter 			  connector->connector_type_id);
23952217195SDaniel Vetter 	if (!connector->name) {
24052217195SDaniel Vetter 		ret = -ENOMEM;
24152217195SDaniel Vetter 		goto out_put_type_id;
24252217195SDaniel Vetter 	}
24352217195SDaniel Vetter 
24452217195SDaniel Vetter 	INIT_LIST_HEAD(&connector->probed_modes);
24552217195SDaniel Vetter 	INIT_LIST_HEAD(&connector->modes);
246e73ab00eSDaniel Vetter 	mutex_init(&connector->mutex);
24752217195SDaniel Vetter 	connector->edid_blob_ptr = NULL;
24852217195SDaniel Vetter 	connector->status = connector_status_unknown;
2498d70f395SHans de Goede 	connector->display_info.panel_orientation =
2508d70f395SHans de Goede 		DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
25152217195SDaniel Vetter 
25252217195SDaniel Vetter 	drm_connector_get_cmdline_mode(connector);
25352217195SDaniel Vetter 
25452217195SDaniel Vetter 	/* We should add connectors at the end to avoid upsetting the connector
25552217195SDaniel Vetter 	 * index too much. */
256613051daSDaniel Vetter 	spin_lock_irq(&config->connector_list_lock);
25752217195SDaniel Vetter 	list_add_tail(&connector->head, &config->connector_list);
25852217195SDaniel Vetter 	config->num_connector++;
259613051daSDaniel Vetter 	spin_unlock_irq(&config->connector_list_lock);
26052217195SDaniel Vetter 
261935774cdSBrian Starkey 	if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
262935774cdSBrian Starkey 	    connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
2636b7e2d5cSGerd Hoffmann 		drm_connector_attach_edid_property(connector);
26452217195SDaniel Vetter 
26552217195SDaniel Vetter 	drm_object_attach_property(&connector->base,
26652217195SDaniel Vetter 				      config->dpms_property, 0);
26752217195SDaniel Vetter 
26840ee6fbeSManasi Navare 	drm_object_attach_property(&connector->base,
26940ee6fbeSManasi Navare 				   config->link_status_property,
27040ee6fbeSManasi Navare 				   0);
27140ee6fbeSManasi Navare 
27266660d4cSDave Airlie 	drm_object_attach_property(&connector->base,
27366660d4cSDave Airlie 				   config->non_desktop_property,
27466660d4cSDave Airlie 				   0);
27566660d4cSDave Airlie 
27652217195SDaniel Vetter 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
27752217195SDaniel Vetter 		drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
27852217195SDaniel Vetter 	}
27952217195SDaniel Vetter 
28052217195SDaniel Vetter 	connector->debugfs_entry = NULL;
28152217195SDaniel Vetter out_put_type_id:
28252217195SDaniel Vetter 	if (ret)
283587680c1SChristophe JAILLET 		ida_simple_remove(connector_ida, connector->connector_type_id);
28452217195SDaniel Vetter out_put_id:
28552217195SDaniel Vetter 	if (ret)
286587680c1SChristophe JAILLET 		ida_simple_remove(&config->connector_ida, connector->index);
28752217195SDaniel Vetter out_put:
28852217195SDaniel Vetter 	if (ret)
28952217195SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
29052217195SDaniel Vetter 
29152217195SDaniel Vetter 	return ret;
29252217195SDaniel Vetter }
29352217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_init);
29452217195SDaniel Vetter 
29552217195SDaniel Vetter /**
2966b7e2d5cSGerd Hoffmann  * drm_connector_attach_edid_property - attach edid property.
2976b7e2d5cSGerd Hoffmann  * @connector: the connector
2986b7e2d5cSGerd Hoffmann  *
2996b7e2d5cSGerd Hoffmann  * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
3006b7e2d5cSGerd Hoffmann  * edid property attached by default.  This function can be used to
3016b7e2d5cSGerd Hoffmann  * explicitly enable the edid property in these cases.
3026b7e2d5cSGerd Hoffmann  */
3036b7e2d5cSGerd Hoffmann void drm_connector_attach_edid_property(struct drm_connector *connector)
3046b7e2d5cSGerd Hoffmann {
3056b7e2d5cSGerd Hoffmann 	struct drm_mode_config *config = &connector->dev->mode_config;
3066b7e2d5cSGerd Hoffmann 
3076b7e2d5cSGerd Hoffmann 	drm_object_attach_property(&connector->base,
3086b7e2d5cSGerd Hoffmann 				   config->edid_property,
3096b7e2d5cSGerd Hoffmann 				   0);
3106b7e2d5cSGerd Hoffmann }
3116b7e2d5cSGerd Hoffmann EXPORT_SYMBOL(drm_connector_attach_edid_property);
3126b7e2d5cSGerd Hoffmann 
3136b7e2d5cSGerd Hoffmann /**
314cde4c44dSDaniel Vetter  * drm_connector_attach_encoder - attach a connector to an encoder
31552217195SDaniel Vetter  * @connector: connector to attach
31652217195SDaniel Vetter  * @encoder: encoder to attach @connector to
31752217195SDaniel Vetter  *
31852217195SDaniel Vetter  * This function links up a connector to an encoder. Note that the routing
31952217195SDaniel Vetter  * restrictions between encoders and crtcs are exposed to userspace through the
32052217195SDaniel Vetter  * possible_clones and possible_crtcs bitmasks.
32152217195SDaniel Vetter  *
32252217195SDaniel Vetter  * Returns:
32352217195SDaniel Vetter  * Zero on success, negative errno on failure.
32452217195SDaniel Vetter  */
325cde4c44dSDaniel Vetter int drm_connector_attach_encoder(struct drm_connector *connector,
32652217195SDaniel Vetter 				 struct drm_encoder *encoder)
32752217195SDaniel Vetter {
32852217195SDaniel Vetter 	int i;
32952217195SDaniel Vetter 
33052217195SDaniel Vetter 	/*
33152217195SDaniel Vetter 	 * In the past, drivers have attempted to model the static association
33252217195SDaniel Vetter 	 * of connector to encoder in simple connector/encoder devices using a
33352217195SDaniel Vetter 	 * direct assignment of connector->encoder = encoder. This connection
33452217195SDaniel Vetter 	 * is a logical one and the responsibility of the core, so drivers are
33552217195SDaniel Vetter 	 * expected not to mess with this.
33652217195SDaniel Vetter 	 *
33752217195SDaniel Vetter 	 * Note that the error return should've been enough here, but a large
33852217195SDaniel Vetter 	 * majority of drivers ignores the return value, so add in a big WARN
33952217195SDaniel Vetter 	 * to get people's attention.
34052217195SDaniel Vetter 	 */
34152217195SDaniel Vetter 	if (WARN_ON(connector->encoder))
34252217195SDaniel Vetter 		return -EINVAL;
34352217195SDaniel Vetter 
34483aefbb8SVille Syrjälä 	for (i = 0; i < ARRAY_SIZE(connector->encoder_ids); i++) {
34552217195SDaniel Vetter 		if (connector->encoder_ids[i] == 0) {
34652217195SDaniel Vetter 			connector->encoder_ids[i] = encoder->base.id;
34752217195SDaniel Vetter 			return 0;
34852217195SDaniel Vetter 		}
34952217195SDaniel Vetter 	}
35052217195SDaniel Vetter 	return -ENOMEM;
35152217195SDaniel Vetter }
352cde4c44dSDaniel Vetter EXPORT_SYMBOL(drm_connector_attach_encoder);
35352217195SDaniel Vetter 
35438cb8d96SVille Syrjälä /**
35538cb8d96SVille Syrjälä  * drm_connector_has_possible_encoder - check if the connector and encoder are assosicated with each other
35638cb8d96SVille Syrjälä  * @connector: the connector
35738cb8d96SVille Syrjälä  * @encoder: the encoder
35838cb8d96SVille Syrjälä  *
35938cb8d96SVille Syrjälä  * Returns:
36038cb8d96SVille Syrjälä  * True if @encoder is one of the possible encoders for @connector.
36138cb8d96SVille Syrjälä  */
36238cb8d96SVille Syrjälä bool drm_connector_has_possible_encoder(struct drm_connector *connector,
36338cb8d96SVille Syrjälä 					struct drm_encoder *encoder)
36438cb8d96SVille Syrjälä {
36538cb8d96SVille Syrjälä 	struct drm_encoder *enc;
36638cb8d96SVille Syrjälä 	int i;
36738cb8d96SVille Syrjälä 
36838cb8d96SVille Syrjälä 	drm_connector_for_each_possible_encoder(connector, enc, i) {
36938cb8d96SVille Syrjälä 		if (enc == encoder)
37038cb8d96SVille Syrjälä 			return true;
37138cb8d96SVille Syrjälä 	}
37238cb8d96SVille Syrjälä 
37338cb8d96SVille Syrjälä 	return false;
37438cb8d96SVille Syrjälä }
37538cb8d96SVille Syrjälä EXPORT_SYMBOL(drm_connector_has_possible_encoder);
37638cb8d96SVille Syrjälä 
37752217195SDaniel Vetter static void drm_mode_remove(struct drm_connector *connector,
37852217195SDaniel Vetter 			    struct drm_display_mode *mode)
37952217195SDaniel Vetter {
38052217195SDaniel Vetter 	list_del(&mode->head);
38152217195SDaniel Vetter 	drm_mode_destroy(connector->dev, mode);
38252217195SDaniel Vetter }
38352217195SDaniel Vetter 
38452217195SDaniel Vetter /**
38552217195SDaniel Vetter  * drm_connector_cleanup - cleans up an initialised connector
38652217195SDaniel Vetter  * @connector: connector to cleanup
38752217195SDaniel Vetter  *
38852217195SDaniel Vetter  * Cleans up the connector but doesn't free the object.
38952217195SDaniel Vetter  */
39052217195SDaniel Vetter void drm_connector_cleanup(struct drm_connector *connector)
39152217195SDaniel Vetter {
39252217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
39352217195SDaniel Vetter 	struct drm_display_mode *mode, *t;
39452217195SDaniel Vetter 
39552217195SDaniel Vetter 	/* The connector should have been removed from userspace long before
39652217195SDaniel Vetter 	 * it is finally destroyed.
39752217195SDaniel Vetter 	 */
39839b50c60SLyude Paul 	if (WARN_ON(connector->registration_state ==
39939b50c60SLyude Paul 		    DRM_CONNECTOR_REGISTERED))
40052217195SDaniel Vetter 		drm_connector_unregister(connector);
40152217195SDaniel Vetter 
40252217195SDaniel Vetter 	if (connector->tile_group) {
40352217195SDaniel Vetter 		drm_mode_put_tile_group(dev, connector->tile_group);
40452217195SDaniel Vetter 		connector->tile_group = NULL;
40552217195SDaniel Vetter 	}
40652217195SDaniel Vetter 
40752217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
40852217195SDaniel Vetter 		drm_mode_remove(connector, mode);
40952217195SDaniel Vetter 
41052217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->modes, head)
41152217195SDaniel Vetter 		drm_mode_remove(connector, mode);
41252217195SDaniel Vetter 
4139a47dba1SChristophe JAILLET 	ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida,
41452217195SDaniel Vetter 			  connector->connector_type_id);
41552217195SDaniel Vetter 
4169a47dba1SChristophe JAILLET 	ida_simple_remove(&dev->mode_config.connector_ida,
41752217195SDaniel Vetter 			  connector->index);
41852217195SDaniel Vetter 
41952217195SDaniel Vetter 	kfree(connector->display_info.bus_formats);
42052217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
42152217195SDaniel Vetter 	kfree(connector->name);
42252217195SDaniel Vetter 	connector->name = NULL;
423613051daSDaniel Vetter 	spin_lock_irq(&dev->mode_config.connector_list_lock);
42452217195SDaniel Vetter 	list_del(&connector->head);
42552217195SDaniel Vetter 	dev->mode_config.num_connector--;
426613051daSDaniel Vetter 	spin_unlock_irq(&dev->mode_config.connector_list_lock);
42752217195SDaniel Vetter 
42852217195SDaniel Vetter 	WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
42952217195SDaniel Vetter 	if (connector->state && connector->funcs->atomic_destroy_state)
43052217195SDaniel Vetter 		connector->funcs->atomic_destroy_state(connector,
43152217195SDaniel Vetter 						       connector->state);
43252217195SDaniel Vetter 
433e73ab00eSDaniel Vetter 	mutex_destroy(&connector->mutex);
434e73ab00eSDaniel Vetter 
43552217195SDaniel Vetter 	memset(connector, 0, sizeof(*connector));
43652217195SDaniel Vetter }
43752217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_cleanup);
43852217195SDaniel Vetter 
43952217195SDaniel Vetter /**
44052217195SDaniel Vetter  * drm_connector_register - register a connector
44152217195SDaniel Vetter  * @connector: the connector to register
44252217195SDaniel Vetter  *
44352217195SDaniel Vetter  * Register userspace interfaces for a connector
44452217195SDaniel Vetter  *
44552217195SDaniel Vetter  * Returns:
44652217195SDaniel Vetter  * Zero on success, error code on failure.
44752217195SDaniel Vetter  */
44852217195SDaniel Vetter int drm_connector_register(struct drm_connector *connector)
44952217195SDaniel Vetter {
450e73ab00eSDaniel Vetter 	int ret = 0;
45152217195SDaniel Vetter 
452e6e7b48bSDaniel Vetter 	if (!connector->dev->registered)
453e6e7b48bSDaniel Vetter 		return 0;
454e6e7b48bSDaniel Vetter 
455e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
45639b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
457e73ab00eSDaniel Vetter 		goto unlock;
45852217195SDaniel Vetter 
45952217195SDaniel Vetter 	ret = drm_sysfs_connector_add(connector);
46052217195SDaniel Vetter 	if (ret)
461e73ab00eSDaniel Vetter 		goto unlock;
46252217195SDaniel Vetter 
46352217195SDaniel Vetter 	ret = drm_debugfs_connector_add(connector);
46452217195SDaniel Vetter 	if (ret) {
46552217195SDaniel Vetter 		goto err_sysfs;
46652217195SDaniel Vetter 	}
46752217195SDaniel Vetter 
46852217195SDaniel Vetter 	if (connector->funcs->late_register) {
46952217195SDaniel Vetter 		ret = connector->funcs->late_register(connector);
47052217195SDaniel Vetter 		if (ret)
47152217195SDaniel Vetter 			goto err_debugfs;
47252217195SDaniel Vetter 	}
47352217195SDaniel Vetter 
47452217195SDaniel Vetter 	drm_mode_object_register(connector->dev, &connector->base);
47552217195SDaniel Vetter 
47639b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_REGISTERED;
477e73ab00eSDaniel Vetter 	goto unlock;
47852217195SDaniel Vetter 
47952217195SDaniel Vetter err_debugfs:
48052217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
48152217195SDaniel Vetter err_sysfs:
48252217195SDaniel Vetter 	drm_sysfs_connector_remove(connector);
483e73ab00eSDaniel Vetter unlock:
484e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
48552217195SDaniel Vetter 	return ret;
48652217195SDaniel Vetter }
48752217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_register);
48852217195SDaniel Vetter 
48952217195SDaniel Vetter /**
49052217195SDaniel Vetter  * drm_connector_unregister - unregister a connector
49152217195SDaniel Vetter  * @connector: the connector to unregister
49252217195SDaniel Vetter  *
49352217195SDaniel Vetter  * Unregister userspace interfaces for a connector
49452217195SDaniel Vetter  */
49552217195SDaniel Vetter void drm_connector_unregister(struct drm_connector *connector)
49652217195SDaniel Vetter {
497e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
49839b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
499e73ab00eSDaniel Vetter 		mutex_unlock(&connector->mutex);
50052217195SDaniel Vetter 		return;
501e73ab00eSDaniel Vetter 	}
50252217195SDaniel Vetter 
50352217195SDaniel Vetter 	if (connector->funcs->early_unregister)
50452217195SDaniel Vetter 		connector->funcs->early_unregister(connector);
50552217195SDaniel Vetter 
50652217195SDaniel Vetter 	drm_sysfs_connector_remove(connector);
50752217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
50852217195SDaniel Vetter 
50939b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
510e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
51152217195SDaniel Vetter }
51252217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_unregister);
51352217195SDaniel Vetter 
51452217195SDaniel Vetter void drm_connector_unregister_all(struct drm_device *dev)
51552217195SDaniel Vetter {
51652217195SDaniel Vetter 	struct drm_connector *connector;
517613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
51852217195SDaniel Vetter 
519b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
520613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter)
52152217195SDaniel Vetter 		drm_connector_unregister(connector);
522b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
52352217195SDaniel Vetter }
52452217195SDaniel Vetter 
52552217195SDaniel Vetter int drm_connector_register_all(struct drm_device *dev)
52652217195SDaniel Vetter {
52752217195SDaniel Vetter 	struct drm_connector *connector;
528613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
529613051daSDaniel Vetter 	int ret = 0;
53052217195SDaniel Vetter 
531b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
532613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter) {
53352217195SDaniel Vetter 		ret = drm_connector_register(connector);
53452217195SDaniel Vetter 		if (ret)
535613051daSDaniel Vetter 			break;
53652217195SDaniel Vetter 	}
537b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
53852217195SDaniel Vetter 
539613051daSDaniel Vetter 	if (ret)
54052217195SDaniel Vetter 		drm_connector_unregister_all(dev);
54152217195SDaniel Vetter 	return ret;
54252217195SDaniel Vetter }
54352217195SDaniel Vetter 
54452217195SDaniel Vetter /**
54552217195SDaniel Vetter  * drm_get_connector_status_name - return a string for connector status
54652217195SDaniel Vetter  * @status: connector status to compute name of
54752217195SDaniel Vetter  *
54852217195SDaniel Vetter  * In contrast to the other drm_get_*_name functions this one here returns a
54952217195SDaniel Vetter  * const pointer and hence is threadsafe.
55052217195SDaniel Vetter  */
55152217195SDaniel Vetter const char *drm_get_connector_status_name(enum drm_connector_status status)
55252217195SDaniel Vetter {
55352217195SDaniel Vetter 	if (status == connector_status_connected)
55452217195SDaniel Vetter 		return "connected";
55552217195SDaniel Vetter 	else if (status == connector_status_disconnected)
55652217195SDaniel Vetter 		return "disconnected";
55752217195SDaniel Vetter 	else
55852217195SDaniel Vetter 		return "unknown";
55952217195SDaniel Vetter }
56052217195SDaniel Vetter EXPORT_SYMBOL(drm_get_connector_status_name);
56152217195SDaniel Vetter 
5626140cf20SJani Nikula /**
5636140cf20SJani Nikula  * drm_get_connector_force_name - return a string for connector force
5646140cf20SJani Nikula  * @force: connector force to get name of
5656140cf20SJani Nikula  *
5666140cf20SJani Nikula  * Returns: const pointer to name.
5676140cf20SJani Nikula  */
5686140cf20SJani Nikula const char *drm_get_connector_force_name(enum drm_connector_force force)
5696140cf20SJani Nikula {
5706140cf20SJani Nikula 	switch (force) {
5716140cf20SJani Nikula 	case DRM_FORCE_UNSPECIFIED:
5726140cf20SJani Nikula 		return "unspecified";
5736140cf20SJani Nikula 	case DRM_FORCE_OFF:
5746140cf20SJani Nikula 		return "off";
5756140cf20SJani Nikula 	case DRM_FORCE_ON:
5766140cf20SJani Nikula 		return "on";
5776140cf20SJani Nikula 	case DRM_FORCE_ON_DIGITAL:
5786140cf20SJani Nikula 		return "digital";
5796140cf20SJani Nikula 	default:
5806140cf20SJani Nikula 		return "unknown";
5816140cf20SJani Nikula 	}
5826140cf20SJani Nikula }
5836140cf20SJani Nikula 
584613051daSDaniel Vetter #ifdef CONFIG_LOCKDEP
585613051daSDaniel Vetter static struct lockdep_map connector_list_iter_dep_map = {
586613051daSDaniel Vetter 	.name = "drm_connector_list_iter"
587613051daSDaniel Vetter };
588613051daSDaniel Vetter #endif
589613051daSDaniel Vetter 
590613051daSDaniel Vetter /**
591b982dab1SThierry Reding  * drm_connector_list_iter_begin - initialize a connector_list iterator
592613051daSDaniel Vetter  * @dev: DRM device
593613051daSDaniel Vetter  * @iter: connector_list iterator
594613051daSDaniel Vetter  *
595d574528aSDaniel Vetter  * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
596b982dab1SThierry Reding  * must always be cleaned up again by calling drm_connector_list_iter_end().
597613051daSDaniel Vetter  * Iteration itself happens using drm_connector_list_iter_next() or
598613051daSDaniel Vetter  * drm_for_each_connector_iter().
599613051daSDaniel Vetter  */
600b982dab1SThierry Reding void drm_connector_list_iter_begin(struct drm_device *dev,
601613051daSDaniel Vetter 				   struct drm_connector_list_iter *iter)
602613051daSDaniel Vetter {
603613051daSDaniel Vetter 	iter->dev = dev;
604613051daSDaniel Vetter 	iter->conn = NULL;
605613051daSDaniel Vetter 	lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
606613051daSDaniel Vetter }
607b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_begin);
608613051daSDaniel Vetter 
609a703c550SDaniel Vetter /*
610a703c550SDaniel Vetter  * Extra-safe connector put function that works in any context. Should only be
611a703c550SDaniel Vetter  * used from the connector_iter functions, where we never really expect to
612a703c550SDaniel Vetter  * actually release the connector when dropping our final reference.
613a703c550SDaniel Vetter  */
614a703c550SDaniel Vetter static void
615ea497bb9SDaniel Vetter __drm_connector_put_safe(struct drm_connector *conn)
616a703c550SDaniel Vetter {
617ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &conn->dev->mode_config;
618ea497bb9SDaniel Vetter 
619ea497bb9SDaniel Vetter 	lockdep_assert_held(&config->connector_list_lock);
620ea497bb9SDaniel Vetter 
621ea497bb9SDaniel Vetter 	if (!refcount_dec_and_test(&conn->base.refcount.refcount))
622ea497bb9SDaniel Vetter 		return;
623ea497bb9SDaniel Vetter 
624ea497bb9SDaniel Vetter 	llist_add(&conn->free_node, &config->connector_free_list);
625ea497bb9SDaniel Vetter 	schedule_work(&config->connector_free_work);
626a703c550SDaniel Vetter }
627a703c550SDaniel Vetter 
628613051daSDaniel Vetter /**
629613051daSDaniel Vetter  * drm_connector_list_iter_next - return next connector
6304f45c778SLyude Paul  * @iter: connector_list iterator
631613051daSDaniel Vetter  *
632613051daSDaniel Vetter  * Returns the next connector for @iter, or NULL when the list walk has
633613051daSDaniel Vetter  * completed.
634613051daSDaniel Vetter  */
635613051daSDaniel Vetter struct drm_connector *
636613051daSDaniel Vetter drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
637613051daSDaniel Vetter {
638613051daSDaniel Vetter 	struct drm_connector *old_conn = iter->conn;
639613051daSDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
640613051daSDaniel Vetter 	struct list_head *lhead;
641613051daSDaniel Vetter 	unsigned long flags;
642613051daSDaniel Vetter 
643613051daSDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
644613051daSDaniel Vetter 	lhead = old_conn ? &old_conn->head : &config->connector_list;
645613051daSDaniel Vetter 
646613051daSDaniel Vetter 	do {
647613051daSDaniel Vetter 		if (lhead->next == &config->connector_list) {
648613051daSDaniel Vetter 			iter->conn = NULL;
649613051daSDaniel Vetter 			break;
650613051daSDaniel Vetter 		}
651613051daSDaniel Vetter 
652613051daSDaniel Vetter 		lhead = lhead->next;
653613051daSDaniel Vetter 		iter->conn = list_entry(lhead, struct drm_connector, head);
654613051daSDaniel Vetter 
655613051daSDaniel Vetter 		/* loop until it's not a zombie connector */
656613051daSDaniel Vetter 	} while (!kref_get_unless_zero(&iter->conn->base.refcount));
657613051daSDaniel Vetter 
658613051daSDaniel Vetter 	if (old_conn)
659ea497bb9SDaniel Vetter 		__drm_connector_put_safe(old_conn);
660ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
661613051daSDaniel Vetter 
662613051daSDaniel Vetter 	return iter->conn;
663613051daSDaniel Vetter }
664613051daSDaniel Vetter EXPORT_SYMBOL(drm_connector_list_iter_next);
665613051daSDaniel Vetter 
666613051daSDaniel Vetter /**
667b982dab1SThierry Reding  * drm_connector_list_iter_end - tear down a connector_list iterator
668613051daSDaniel Vetter  * @iter: connector_list iterator
669613051daSDaniel Vetter  *
670613051daSDaniel Vetter  * Tears down @iter and releases any resources (like &drm_connector references)
671613051daSDaniel Vetter  * acquired while walking the list. This must always be called, both when the
672613051daSDaniel Vetter  * iteration completes fully or when it was aborted without walking the entire
673613051daSDaniel Vetter  * list.
674613051daSDaniel Vetter  */
675b982dab1SThierry Reding void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
676613051daSDaniel Vetter {
677ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
678ea497bb9SDaniel Vetter 	unsigned long flags;
679ea497bb9SDaniel Vetter 
680613051daSDaniel Vetter 	iter->dev = NULL;
681ea497bb9SDaniel Vetter 	if (iter->conn) {
682ea497bb9SDaniel Vetter 		spin_lock_irqsave(&config->connector_list_lock, flags);
683ea497bb9SDaniel Vetter 		__drm_connector_put_safe(iter->conn);
684ea497bb9SDaniel Vetter 		spin_unlock_irqrestore(&config->connector_list_lock, flags);
685ea497bb9SDaniel Vetter 	}
686613051daSDaniel Vetter 	lock_release(&connector_list_iter_dep_map, 0, _RET_IP_);
687613051daSDaniel Vetter }
688b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_end);
689613051daSDaniel Vetter 
69052217195SDaniel Vetter static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
69152217195SDaniel Vetter 	{ SubPixelUnknown, "Unknown" },
69252217195SDaniel Vetter 	{ SubPixelHorizontalRGB, "Horizontal RGB" },
69352217195SDaniel Vetter 	{ SubPixelHorizontalBGR, "Horizontal BGR" },
69452217195SDaniel Vetter 	{ SubPixelVerticalRGB, "Vertical RGB" },
69552217195SDaniel Vetter 	{ SubPixelVerticalBGR, "Vertical BGR" },
69652217195SDaniel Vetter 	{ SubPixelNone, "None" },
69752217195SDaniel Vetter };
69852217195SDaniel Vetter 
69952217195SDaniel Vetter /**
70052217195SDaniel Vetter  * drm_get_subpixel_order_name - return a string for a given subpixel enum
70152217195SDaniel Vetter  * @order: enum of subpixel_order
70252217195SDaniel Vetter  *
70352217195SDaniel Vetter  * Note you could abuse this and return something out of bounds, but that
70452217195SDaniel Vetter  * would be a caller error.  No unscrubbed user data should make it here.
70552217195SDaniel Vetter  */
70652217195SDaniel Vetter const char *drm_get_subpixel_order_name(enum subpixel_order order)
70752217195SDaniel Vetter {
70852217195SDaniel Vetter 	return drm_subpixel_enum_list[order].name;
70952217195SDaniel Vetter }
71052217195SDaniel Vetter EXPORT_SYMBOL(drm_get_subpixel_order_name);
71152217195SDaniel Vetter 
71252217195SDaniel Vetter static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
71352217195SDaniel Vetter 	{ DRM_MODE_DPMS_ON, "On" },
71452217195SDaniel Vetter 	{ DRM_MODE_DPMS_STANDBY, "Standby" },
71552217195SDaniel Vetter 	{ DRM_MODE_DPMS_SUSPEND, "Suspend" },
71652217195SDaniel Vetter 	{ DRM_MODE_DPMS_OFF, "Off" }
71752217195SDaniel Vetter };
71852217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
71952217195SDaniel Vetter 
72040ee6fbeSManasi Navare static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
72140ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_GOOD, "Good" },
72240ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_BAD, "Bad" },
72340ee6fbeSManasi Navare };
72440ee6fbeSManasi Navare 
725b3c6c8bfSDaniel Vetter /**
726b3c6c8bfSDaniel Vetter  * drm_display_info_set_bus_formats - set the supported bus formats
727b3c6c8bfSDaniel Vetter  * @info: display info to store bus formats in
728b3c6c8bfSDaniel Vetter  * @formats: array containing the supported bus formats
729b3c6c8bfSDaniel Vetter  * @num_formats: the number of entries in the fmts array
730b3c6c8bfSDaniel Vetter  *
731b3c6c8bfSDaniel Vetter  * Store the supported bus formats in display info structure.
732b3c6c8bfSDaniel Vetter  * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
733b3c6c8bfSDaniel Vetter  * a full list of available formats.
734b3c6c8bfSDaniel Vetter  */
735b3c6c8bfSDaniel Vetter int drm_display_info_set_bus_formats(struct drm_display_info *info,
736b3c6c8bfSDaniel Vetter 				     const u32 *formats,
737b3c6c8bfSDaniel Vetter 				     unsigned int num_formats)
738b3c6c8bfSDaniel Vetter {
739b3c6c8bfSDaniel Vetter 	u32 *fmts = NULL;
740b3c6c8bfSDaniel Vetter 
741b3c6c8bfSDaniel Vetter 	if (!formats && num_formats)
742b3c6c8bfSDaniel Vetter 		return -EINVAL;
743b3c6c8bfSDaniel Vetter 
744b3c6c8bfSDaniel Vetter 	if (formats && num_formats) {
745b3c6c8bfSDaniel Vetter 		fmts = kmemdup(formats, sizeof(*formats) * num_formats,
746b3c6c8bfSDaniel Vetter 			       GFP_KERNEL);
747b3c6c8bfSDaniel Vetter 		if (!fmts)
748b3c6c8bfSDaniel Vetter 			return -ENOMEM;
749b3c6c8bfSDaniel Vetter 	}
750b3c6c8bfSDaniel Vetter 
751b3c6c8bfSDaniel Vetter 	kfree(info->bus_formats);
752b3c6c8bfSDaniel Vetter 	info->bus_formats = fmts;
753b3c6c8bfSDaniel Vetter 	info->num_bus_formats = num_formats;
754b3c6c8bfSDaniel Vetter 
755b3c6c8bfSDaniel Vetter 	return 0;
756b3c6c8bfSDaniel Vetter }
757b3c6c8bfSDaniel Vetter EXPORT_SYMBOL(drm_display_info_set_bus_formats);
758b3c6c8bfSDaniel Vetter 
75952217195SDaniel Vetter /* Optional connector properties. */
76052217195SDaniel Vetter static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
76152217195SDaniel Vetter 	{ DRM_MODE_SCALE_NONE, "None" },
76252217195SDaniel Vetter 	{ DRM_MODE_SCALE_FULLSCREEN, "Full" },
76352217195SDaniel Vetter 	{ DRM_MODE_SCALE_CENTER, "Center" },
76452217195SDaniel Vetter 	{ DRM_MODE_SCALE_ASPECT, "Full aspect" },
76552217195SDaniel Vetter };
76652217195SDaniel Vetter 
76752217195SDaniel Vetter static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
76852217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
76952217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
77052217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
77152217195SDaniel Vetter };
77252217195SDaniel Vetter 
77350525c33SStanislav Lisovskiy static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
77450525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
77550525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
77650525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
77750525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
77850525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GAME, "Game" },
77950525c33SStanislav Lisovskiy };
78050525c33SStanislav Lisovskiy 
7818d70f395SHans de Goede static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
7828d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_NORMAL,	"Normal"	},
7838d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP,	"Upside Down"	},
7848d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_LEFT_UP,	"Left Side Up"	},
7858d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,	"Right Side Up"	},
7868d70f395SHans de Goede };
7878d70f395SHans de Goede 
78852217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
78952217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
79052217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
79152217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
79252217195SDaniel Vetter };
79352217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
79452217195SDaniel Vetter 
79552217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
79652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I and TV-out */
79752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
79852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
79952217195SDaniel Vetter };
80052217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
80152217195SDaniel Vetter 		 drm_dvi_i_subconnector_enum_list)
80252217195SDaniel Vetter 
80352217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
80452217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
80552217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
80652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
80752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
80852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
80952217195SDaniel Vetter };
81052217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
81152217195SDaniel Vetter 
81252217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
81352217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I and TV-out */
81452217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
81552217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
81652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
81752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
81852217195SDaniel Vetter };
81952217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
82052217195SDaniel Vetter 		 drm_tv_subconnector_enum_list)
82152217195SDaniel Vetter 
82224557865SSean Paul static struct drm_prop_enum_list drm_cp_enum_list[] = {
82324557865SSean Paul 	{ DRM_MODE_CONTENT_PROTECTION_UNDESIRED, "Undesired" },
82424557865SSean Paul 	{ DRM_MODE_CONTENT_PROTECTION_DESIRED, "Desired" },
82524557865SSean Paul 	{ DRM_MODE_CONTENT_PROTECTION_ENABLED, "Enabled" },
82624557865SSean Paul };
82724557865SSean Paul DRM_ENUM_NAME_FN(drm_get_content_protection_name, drm_cp_enum_list)
82824557865SSean Paul 
8294ada6f22SDaniel Vetter /**
8304ada6f22SDaniel Vetter  * DOC: standard connector properties
8314ada6f22SDaniel Vetter  *
8324ada6f22SDaniel Vetter  * DRM connectors have a few standardized properties:
8334ada6f22SDaniel Vetter  *
8344ada6f22SDaniel Vetter  * EDID:
8354ada6f22SDaniel Vetter  * 	Blob property which contains the current EDID read from the sink. This
8364ada6f22SDaniel Vetter  * 	is useful to parse sink identification information like vendor, model
8374ada6f22SDaniel Vetter  * 	and serial. Drivers should update this property by calling
838c555f023SDaniel Vetter  * 	drm_connector_update_edid_property(), usually after having parsed
8394ada6f22SDaniel Vetter  * 	the EDID using drm_add_edid_modes(). Userspace cannot change this
8404ada6f22SDaniel Vetter  * 	property.
8414ada6f22SDaniel Vetter  * DPMS:
8424ada6f22SDaniel Vetter  * 	Legacy property for setting the power state of the connector. For atomic
8434ada6f22SDaniel Vetter  * 	drivers this is only provided for backwards compatibility with existing
8444ada6f22SDaniel Vetter  * 	drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
8454ada6f22SDaniel Vetter  * 	connector is linked to. Drivers should never set this property directly,
846d574528aSDaniel Vetter  * 	it is handled by the DRM core by calling the &drm_connector_funcs.dpms
847144a7999SDaniel Vetter  * 	callback. For atomic drivers the remapping to the "ACTIVE" property is
848144a7999SDaniel Vetter  * 	implemented in the DRM core.  This is the only standard connector
849144a7999SDaniel Vetter  * 	property that userspace can change.
850d0d1aee5SDaniel Vetter  *
851d0d1aee5SDaniel Vetter  * 	Note that this property cannot be set through the MODE_ATOMIC ioctl,
852d0d1aee5SDaniel Vetter  * 	userspace must use "ACTIVE" on the CRTC instead.
853d0d1aee5SDaniel Vetter  *
854d0d1aee5SDaniel Vetter  * 	WARNING:
855d0d1aee5SDaniel Vetter  *
856d0d1aee5SDaniel Vetter  * 	For userspace also running on legacy drivers the "DPMS" semantics are a
857d0d1aee5SDaniel Vetter  * 	lot more complicated. First, userspace cannot rely on the "DPMS" value
858d0d1aee5SDaniel Vetter  * 	returned by the GETCONNECTOR actually reflecting reality, because many
859d0d1aee5SDaniel Vetter  * 	drivers fail to update it. For atomic drivers this is taken care of in
860d0d1aee5SDaniel Vetter  * 	drm_atomic_helper_update_legacy_modeset_state().
861d0d1aee5SDaniel Vetter  *
862d0d1aee5SDaniel Vetter  * 	The second issue is that the DPMS state is only well-defined when the
863d0d1aee5SDaniel Vetter  * 	connector is connected to a CRTC. In atomic the DRM core enforces that
864d0d1aee5SDaniel Vetter  * 	"ACTIVE" is off in such a case, no such checks exists for "DPMS".
865d0d1aee5SDaniel Vetter  *
866d0d1aee5SDaniel Vetter  * 	Finally, when enabling an output using the legacy SETCONFIG ioctl then
867d0d1aee5SDaniel Vetter  * 	"DPMS" is forced to ON. But see above, that might not be reflected in
868d0d1aee5SDaniel Vetter  * 	the software value on legacy drivers.
869d0d1aee5SDaniel Vetter  *
870d0d1aee5SDaniel Vetter  * 	Summarizing: Only set "DPMS" when the connector is known to be enabled,
871d0d1aee5SDaniel Vetter  * 	assume that a successful SETCONFIG call also sets "DPMS" to on, and
872d0d1aee5SDaniel Vetter  * 	never read back the value of "DPMS" because it can be incorrect.
8734ada6f22SDaniel Vetter  * PATH:
8744ada6f22SDaniel Vetter  * 	Connector path property to identify how this sink is physically
8754ada6f22SDaniel Vetter  * 	connected. Used by DP MST. This should be set by calling
87697e14fbeSDaniel Vetter  * 	drm_connector_set_path_property(), in the case of DP MST with the
8774ada6f22SDaniel Vetter  * 	path property the MST manager created. Userspace cannot change this
8784ada6f22SDaniel Vetter  * 	property.
8794ada6f22SDaniel Vetter  * TILE:
8804ada6f22SDaniel Vetter  * 	Connector tile group property to indicate how a set of DRM connector
8814ada6f22SDaniel Vetter  * 	compose together into one logical screen. This is used by both high-res
8824ada6f22SDaniel Vetter  * 	external screens (often only using a single cable, but exposing multiple
8834ada6f22SDaniel Vetter  * 	DP MST sinks), or high-res integrated panels (like dual-link DSI) which
8844ada6f22SDaniel Vetter  * 	are not gen-locked. Note that for tiled panels which are genlocked, like
8854ada6f22SDaniel Vetter  * 	dual-link LVDS or dual-link DSI, the driver should try to not expose the
8864ada6f22SDaniel Vetter  * 	tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
88797e14fbeSDaniel Vetter  * 	should update this value using drm_connector_set_tile_property().
8884ada6f22SDaniel Vetter  * 	Userspace cannot change this property.
88940ee6fbeSManasi Navare  * link-status:
890716719a3SSean Paul  *      Connector link-status property to indicate the status of link. The
891716719a3SSean Paul  *      default value of link-status is "GOOD". If something fails during or
892716719a3SSean Paul  *      after modeset, the kernel driver may set this to "BAD" and issue a
893716719a3SSean Paul  *      hotplug uevent. Drivers should update this value using
89497e14fbeSDaniel Vetter  *      drm_connector_set_link_status_property().
89566660d4cSDave Airlie  * non_desktop:
89666660d4cSDave Airlie  * 	Indicates the output should be ignored for purposes of displaying a
89766660d4cSDave Airlie  * 	standard desktop environment or console. This is most likely because
89866660d4cSDave Airlie  * 	the output device is not rectilinear.
89924557865SSean Paul  * Content Protection:
90024557865SSean Paul  *	This property is used by userspace to request the kernel protect future
90124557865SSean Paul  *	content communicated over the link. When requested, kernel will apply
90224557865SSean Paul  *	the appropriate means of protection (most often HDCP), and use the
90324557865SSean Paul  *	property to tell userspace the protection is active.
90424557865SSean Paul  *
90524557865SSean Paul  *	Drivers can set this up by calling
90624557865SSean Paul  *	drm_connector_attach_content_protection_property() on initialization.
90724557865SSean Paul  *
90824557865SSean Paul  *	The value of this property can be one of the following:
90924557865SSean Paul  *
910bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
91124557865SSean Paul  *		The link is not protected, content is transmitted in the clear.
912bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
91324557865SSean Paul  *		Userspace has requested content protection, but the link is not
91424557865SSean Paul  *		currently protected. When in this state, kernel should enable
91524557865SSean Paul  *		Content Protection as soon as possible.
916bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
91724557865SSean Paul  *		Userspace has requested content protection, and the link is
91824557865SSean Paul  *		protected. Only the driver can set the property to this value.
91924557865SSean Paul  *		If userspace attempts to set to ENABLED, kernel will return
92024557865SSean Paul  *		-EINVAL.
92124557865SSean Paul  *
92224557865SSean Paul  *	A few guidelines:
92324557865SSean Paul  *
92424557865SSean Paul  *	- DESIRED state should be preserved until userspace de-asserts it by
92524557865SSean Paul  *	  setting the property to UNDESIRED. This means ENABLED should only
92624557865SSean Paul  *	  transition to UNDESIRED when the user explicitly requests it.
92724557865SSean Paul  *	- If the state is DESIRED, kernel should attempt to re-authenticate the
92824557865SSean Paul  *	  link whenever possible. This includes across disable/enable, dpms,
92924557865SSean Paul  *	  hotplug, downstream device changes, link status failures, etc..
93024557865SSean Paul  *	- Userspace is responsible for polling the property to determine when
93124557865SSean Paul  *	  the value transitions from ENABLED to DESIRED. This signifies the link
93224557865SSean Paul  *	  is no longer protected and userspace should take appropriate action
93324557865SSean Paul  *	  (whatever that might be).
9344ada6f22SDaniel Vetter  *
93547e22ff1SRadhakrishna Sripada  * max bpc:
93647e22ff1SRadhakrishna Sripada  *	This range property is used by userspace to limit the bit depth. When
93747e22ff1SRadhakrishna Sripada  *	used the driver would limit the bpc in accordance with the valid range
93847e22ff1SRadhakrishna Sripada  *	supported by the hardware and sink. Drivers to use the function
93947e22ff1SRadhakrishna Sripada  *	drm_connector_attach_max_bpc_property() to create and attach the
94047e22ff1SRadhakrishna Sripada  *	property to the connector during initialization.
94147e22ff1SRadhakrishna Sripada  *
9424ada6f22SDaniel Vetter  * Connectors also have one standardized atomic property:
9434ada6f22SDaniel Vetter  *
9444ada6f22SDaniel Vetter  * CRTC_ID:
9454ada6f22SDaniel Vetter  * 	Mode object ID of the &drm_crtc this connector should be connected to.
9468d70f395SHans de Goede  *
9478d70f395SHans de Goede  * Connectors for LCD panels may also have one standardized property:
9488d70f395SHans de Goede  *
9498d70f395SHans de Goede  * panel orientation:
9508d70f395SHans de Goede  *	On some devices the LCD panel is mounted in the casing in such a way
9518d70f395SHans de Goede  *	that the up/top side of the panel does not match with the top side of
9528d70f395SHans de Goede  *	the device. Userspace can use this property to check for this.
9538d70f395SHans de Goede  *	Note that input coordinates from touchscreens (input devices with
9548d70f395SHans de Goede  *	INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
9558d70f395SHans de Goede  *	coordinates, so if userspace rotates the picture to adjust for
9568d70f395SHans de Goede  *	the orientation it must also apply the same transformation to the
957bbeba09fSDaniel Vetter  *	touchscreen input coordinates. This property is initialized by calling
958bbeba09fSDaniel Vetter  *	drm_connector_init_panel_orientation_property().
959bbeba09fSDaniel Vetter  *
960bbeba09fSDaniel Vetter  * scaling mode:
961bbeba09fSDaniel Vetter  *	This property defines how a non-native mode is upscaled to the native
962bbeba09fSDaniel Vetter  *	mode of an LCD panel:
963bbeba09fSDaniel Vetter  *
964bbeba09fSDaniel Vetter  *	None:
965bbeba09fSDaniel Vetter  *		No upscaling happens, scaling is left to the panel. Not all
966bbeba09fSDaniel Vetter  *		drivers expose this mode.
967bbeba09fSDaniel Vetter  *	Full:
968bbeba09fSDaniel Vetter  *		The output is upscaled to the full resolution of the panel,
969bbeba09fSDaniel Vetter  *		ignoring the aspect ratio.
970bbeba09fSDaniel Vetter  *	Center:
971bbeba09fSDaniel Vetter  *		No upscaling happens, the output is centered within the native
972bbeba09fSDaniel Vetter  *		resolution the panel.
973bbeba09fSDaniel Vetter  *	Full aspect:
974bbeba09fSDaniel Vetter  *		The output is upscaled to maximize either the width or height
975bbeba09fSDaniel Vetter  *		while retaining the aspect ratio.
976bbeba09fSDaniel Vetter  *
977bbeba09fSDaniel Vetter  *	This property should be set up by calling
978bbeba09fSDaniel Vetter  *	drm_connector_attach_scaling_mode_property(). Note that drivers
979bbeba09fSDaniel Vetter  *	can also expose this property to external outputs, in which case they
980bbeba09fSDaniel Vetter  *	must support "None", which should be the default (since external screens
981bbeba09fSDaniel Vetter  *	have a built-in scaler).
9824ada6f22SDaniel Vetter  */
9834ada6f22SDaniel Vetter 
98452217195SDaniel Vetter int drm_connector_create_standard_properties(struct drm_device *dev)
98552217195SDaniel Vetter {
98652217195SDaniel Vetter 	struct drm_property *prop;
98752217195SDaniel Vetter 
98852217195SDaniel Vetter 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
98952217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
99052217195SDaniel Vetter 				   "EDID", 0);
99152217195SDaniel Vetter 	if (!prop)
99252217195SDaniel Vetter 		return -ENOMEM;
99352217195SDaniel Vetter 	dev->mode_config.edid_property = prop;
99452217195SDaniel Vetter 
99552217195SDaniel Vetter 	prop = drm_property_create_enum(dev, 0,
99652217195SDaniel Vetter 				   "DPMS", drm_dpms_enum_list,
99752217195SDaniel Vetter 				   ARRAY_SIZE(drm_dpms_enum_list));
99852217195SDaniel Vetter 	if (!prop)
99952217195SDaniel Vetter 		return -ENOMEM;
100052217195SDaniel Vetter 	dev->mode_config.dpms_property = prop;
100152217195SDaniel Vetter 
100252217195SDaniel Vetter 	prop = drm_property_create(dev,
100352217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
100452217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
100552217195SDaniel Vetter 				   "PATH", 0);
100652217195SDaniel Vetter 	if (!prop)
100752217195SDaniel Vetter 		return -ENOMEM;
100852217195SDaniel Vetter 	dev->mode_config.path_property = prop;
100952217195SDaniel Vetter 
101052217195SDaniel Vetter 	prop = drm_property_create(dev,
101152217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
101252217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
101352217195SDaniel Vetter 				   "TILE", 0);
101452217195SDaniel Vetter 	if (!prop)
101552217195SDaniel Vetter 		return -ENOMEM;
101652217195SDaniel Vetter 	dev->mode_config.tile_property = prop;
101752217195SDaniel Vetter 
101840ee6fbeSManasi Navare 	prop = drm_property_create_enum(dev, 0, "link-status",
101940ee6fbeSManasi Navare 					drm_link_status_enum_list,
102040ee6fbeSManasi Navare 					ARRAY_SIZE(drm_link_status_enum_list));
102140ee6fbeSManasi Navare 	if (!prop)
102240ee6fbeSManasi Navare 		return -ENOMEM;
102340ee6fbeSManasi Navare 	dev->mode_config.link_status_property = prop;
102440ee6fbeSManasi Navare 
102566660d4cSDave Airlie 	prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
102666660d4cSDave Airlie 	if (!prop)
102766660d4cSDave Airlie 		return -ENOMEM;
102866660d4cSDave Airlie 	dev->mode_config.non_desktop_property = prop;
102966660d4cSDave Airlie 
103052217195SDaniel Vetter 	return 0;
103152217195SDaniel Vetter }
103252217195SDaniel Vetter 
103352217195SDaniel Vetter /**
103452217195SDaniel Vetter  * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
103552217195SDaniel Vetter  * @dev: DRM device
103652217195SDaniel Vetter  *
103752217195SDaniel Vetter  * Called by a driver the first time a DVI-I connector is made.
103852217195SDaniel Vetter  */
103952217195SDaniel Vetter int drm_mode_create_dvi_i_properties(struct drm_device *dev)
104052217195SDaniel Vetter {
104152217195SDaniel Vetter 	struct drm_property *dvi_i_selector;
104252217195SDaniel Vetter 	struct drm_property *dvi_i_subconnector;
104352217195SDaniel Vetter 
104452217195SDaniel Vetter 	if (dev->mode_config.dvi_i_select_subconnector_property)
104552217195SDaniel Vetter 		return 0;
104652217195SDaniel Vetter 
104752217195SDaniel Vetter 	dvi_i_selector =
104852217195SDaniel Vetter 		drm_property_create_enum(dev, 0,
104952217195SDaniel Vetter 				    "select subconnector",
105052217195SDaniel Vetter 				    drm_dvi_i_select_enum_list,
105152217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_select_enum_list));
105252217195SDaniel Vetter 	dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
105352217195SDaniel Vetter 
105452217195SDaniel Vetter 	dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
105552217195SDaniel Vetter 				    "subconnector",
105652217195SDaniel Vetter 				    drm_dvi_i_subconnector_enum_list,
105752217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
105852217195SDaniel Vetter 	dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
105952217195SDaniel Vetter 
106052217195SDaniel Vetter 	return 0;
106152217195SDaniel Vetter }
106252217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
106352217195SDaniel Vetter 
106452217195SDaniel Vetter /**
106550525c33SStanislav Lisovskiy  * DOC: HDMI connector properties
106650525c33SStanislav Lisovskiy  *
106750525c33SStanislav Lisovskiy  * content type (HDMI specific):
106850525c33SStanislav Lisovskiy  *	Indicates content type setting to be used in HDMI infoframes to indicate
1069*1e55a53aSMatt Roper  *	content type for the external device, so that it adjusts its display
107050525c33SStanislav Lisovskiy  *	settings accordingly.
107150525c33SStanislav Lisovskiy  *
107250525c33SStanislav Lisovskiy  *	The value of this property can be one of the following:
107350525c33SStanislav Lisovskiy  *
107450525c33SStanislav Lisovskiy  *	No Data:
107550525c33SStanislav Lisovskiy  *		Content type is unknown
107650525c33SStanislav Lisovskiy  *	Graphics:
107750525c33SStanislav Lisovskiy  *		Content type is graphics
107850525c33SStanislav Lisovskiy  *	Photo:
107950525c33SStanislav Lisovskiy  *		Content type is photo
108050525c33SStanislav Lisovskiy  *	Cinema:
108150525c33SStanislav Lisovskiy  *		Content type is cinema
108250525c33SStanislav Lisovskiy  *	Game:
108350525c33SStanislav Lisovskiy  *		Content type is game
108450525c33SStanislav Lisovskiy  *
108550525c33SStanislav Lisovskiy  *	Drivers can set up this property by calling
108650525c33SStanislav Lisovskiy  *	drm_connector_attach_content_type_property(). Decoding to
1087ba609631SDaniel Vetter  *	infoframe values is done through drm_hdmi_avi_infoframe_content_type().
108850525c33SStanislav Lisovskiy  */
108950525c33SStanislav Lisovskiy 
109050525c33SStanislav Lisovskiy /**
109150525c33SStanislav Lisovskiy  * drm_connector_attach_content_type_property - attach content-type property
109250525c33SStanislav Lisovskiy  * @connector: connector to attach content type property on.
109350525c33SStanislav Lisovskiy  *
109450525c33SStanislav Lisovskiy  * Called by a driver the first time a HDMI connector is made.
109550525c33SStanislav Lisovskiy  */
109650525c33SStanislav Lisovskiy int drm_connector_attach_content_type_property(struct drm_connector *connector)
109750525c33SStanislav Lisovskiy {
109850525c33SStanislav Lisovskiy 	if (!drm_mode_create_content_type_property(connector->dev))
109950525c33SStanislav Lisovskiy 		drm_object_attach_property(&connector->base,
110050525c33SStanislav Lisovskiy 					   connector->dev->mode_config.content_type_property,
110150525c33SStanislav Lisovskiy 					   DRM_MODE_CONTENT_TYPE_NO_DATA);
110250525c33SStanislav Lisovskiy 	return 0;
110350525c33SStanislav Lisovskiy }
110450525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_connector_attach_content_type_property);
110550525c33SStanislav Lisovskiy 
110650525c33SStanislav Lisovskiy 
110750525c33SStanislav Lisovskiy /**
110850525c33SStanislav Lisovskiy  * drm_hdmi_avi_infoframe_content_type() - fill the HDMI AVI infoframe
110950525c33SStanislav Lisovskiy  *                                         content type information, based
111050525c33SStanislav Lisovskiy  *                                         on correspondent DRM property.
111150525c33SStanislav Lisovskiy  * @frame: HDMI AVI infoframe
111250525c33SStanislav Lisovskiy  * @conn_state: DRM display connector state
111350525c33SStanislav Lisovskiy  *
111450525c33SStanislav Lisovskiy  */
111550525c33SStanislav Lisovskiy void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame,
111650525c33SStanislav Lisovskiy 					 const struct drm_connector_state *conn_state)
111750525c33SStanislav Lisovskiy {
111850525c33SStanislav Lisovskiy 	switch (conn_state->content_type) {
111950525c33SStanislav Lisovskiy 	case DRM_MODE_CONTENT_TYPE_GRAPHICS:
112050525c33SStanislav Lisovskiy 		frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
112150525c33SStanislav Lisovskiy 		break;
112250525c33SStanislav Lisovskiy 	case DRM_MODE_CONTENT_TYPE_CINEMA:
112350525c33SStanislav Lisovskiy 		frame->content_type = HDMI_CONTENT_TYPE_CINEMA;
112450525c33SStanislav Lisovskiy 		break;
112550525c33SStanislav Lisovskiy 	case DRM_MODE_CONTENT_TYPE_GAME:
112650525c33SStanislav Lisovskiy 		frame->content_type = HDMI_CONTENT_TYPE_GAME;
112750525c33SStanislav Lisovskiy 		break;
112850525c33SStanislav Lisovskiy 	case DRM_MODE_CONTENT_TYPE_PHOTO:
112950525c33SStanislav Lisovskiy 		frame->content_type = HDMI_CONTENT_TYPE_PHOTO;
113050525c33SStanislav Lisovskiy 		break;
113150525c33SStanislav Lisovskiy 	default:
113250525c33SStanislav Lisovskiy 		/* Graphics is the default(0) */
113350525c33SStanislav Lisovskiy 		frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
113450525c33SStanislav Lisovskiy 	}
113550525c33SStanislav Lisovskiy 
113650525c33SStanislav Lisovskiy 	frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA;
113750525c33SStanislav Lisovskiy }
113850525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type);
113950525c33SStanislav Lisovskiy 
114050525c33SStanislav Lisovskiy /**
11416c4f52dcSBoris Brezillon  * drm_mode_attach_tv_margin_properties - attach TV connector margin properties
11426c4f52dcSBoris Brezillon  * @connector: DRM connector
11436c4f52dcSBoris Brezillon  *
11446c4f52dcSBoris Brezillon  * Called by a driver when it needs to attach TV margin props to a connector.
11456c4f52dcSBoris Brezillon  * Typically used on SDTV and HDMI connectors.
11466c4f52dcSBoris Brezillon  */
11476c4f52dcSBoris Brezillon void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
11486c4f52dcSBoris Brezillon {
11496c4f52dcSBoris Brezillon 	struct drm_device *dev = connector->dev;
11506c4f52dcSBoris Brezillon 
11516c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
11526c4f52dcSBoris Brezillon 				   dev->mode_config.tv_left_margin_property,
11536c4f52dcSBoris Brezillon 				   0);
11546c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
11556c4f52dcSBoris Brezillon 				   dev->mode_config.tv_right_margin_property,
11566c4f52dcSBoris Brezillon 				   0);
11576c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
11586c4f52dcSBoris Brezillon 				   dev->mode_config.tv_top_margin_property,
11596c4f52dcSBoris Brezillon 				   0);
11606c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
11616c4f52dcSBoris Brezillon 				   dev->mode_config.tv_bottom_margin_property,
11626c4f52dcSBoris Brezillon 				   0);
11636c4f52dcSBoris Brezillon }
11646c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
11656c4f52dcSBoris Brezillon 
11666c4f52dcSBoris Brezillon /**
11676c4f52dcSBoris Brezillon  * drm_mode_create_tv_margin_properties - create TV connector margin properties
11686c4f52dcSBoris Brezillon  * @dev: DRM device
11696c4f52dcSBoris Brezillon  *
11706c4f52dcSBoris Brezillon  * Called by a driver's HDMI connector initialization routine, this function
11716c4f52dcSBoris Brezillon  * creates the TV margin properties for a given device. No need to call this
11726c4f52dcSBoris Brezillon  * function for an SDTV connector, it's already called from
11736c4f52dcSBoris Brezillon  * drm_mode_create_tv_properties().
11746c4f52dcSBoris Brezillon  */
11756c4f52dcSBoris Brezillon int drm_mode_create_tv_margin_properties(struct drm_device *dev)
11766c4f52dcSBoris Brezillon {
11776c4f52dcSBoris Brezillon 	if (dev->mode_config.tv_left_margin_property)
11786c4f52dcSBoris Brezillon 		return 0;
11796c4f52dcSBoris Brezillon 
11806c4f52dcSBoris Brezillon 	dev->mode_config.tv_left_margin_property =
11816c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "left margin", 0, 100);
11826c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_left_margin_property)
11836c4f52dcSBoris Brezillon 		return -ENOMEM;
11846c4f52dcSBoris Brezillon 
11856c4f52dcSBoris Brezillon 	dev->mode_config.tv_right_margin_property =
11866c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "right margin", 0, 100);
11876c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_right_margin_property)
11886c4f52dcSBoris Brezillon 		return -ENOMEM;
11896c4f52dcSBoris Brezillon 
11906c4f52dcSBoris Brezillon 	dev->mode_config.tv_top_margin_property =
11916c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "top margin", 0, 100);
11926c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_top_margin_property)
11936c4f52dcSBoris Brezillon 		return -ENOMEM;
11946c4f52dcSBoris Brezillon 
11956c4f52dcSBoris Brezillon 	dev->mode_config.tv_bottom_margin_property =
11966c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "bottom margin", 0, 100);
11976c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_bottom_margin_property)
11986c4f52dcSBoris Brezillon 		return -ENOMEM;
11996c4f52dcSBoris Brezillon 
12006c4f52dcSBoris Brezillon 	return 0;
12016c4f52dcSBoris Brezillon }
12026c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
12036c4f52dcSBoris Brezillon 
12046c4f52dcSBoris Brezillon /**
1205eda6887fSBoris Brezillon  * drm_mode_create_tv_properties - create TV specific connector properties
120652217195SDaniel Vetter  * @dev: DRM device
120752217195SDaniel Vetter  * @num_modes: number of different TV formats (modes) supported
120852217195SDaniel Vetter  * @modes: array of pointers to strings containing name of each format
120952217195SDaniel Vetter  *
121052217195SDaniel Vetter  * Called by a driver's TV initialization routine, this function creates
121152217195SDaniel Vetter  * the TV specific connector properties for a given device.  Caller is
121252217195SDaniel Vetter  * responsible for allocating a list of format names and passing them to
121352217195SDaniel Vetter  * this routine.
121452217195SDaniel Vetter  */
121552217195SDaniel Vetter int drm_mode_create_tv_properties(struct drm_device *dev,
121652217195SDaniel Vetter 				  unsigned int num_modes,
121752217195SDaniel Vetter 				  const char * const modes[])
121852217195SDaniel Vetter {
121952217195SDaniel Vetter 	struct drm_property *tv_selector;
122052217195SDaniel Vetter 	struct drm_property *tv_subconnector;
122152217195SDaniel Vetter 	unsigned int i;
122252217195SDaniel Vetter 
122352217195SDaniel Vetter 	if (dev->mode_config.tv_select_subconnector_property)
122452217195SDaniel Vetter 		return 0;
122552217195SDaniel Vetter 
122652217195SDaniel Vetter 	/*
122752217195SDaniel Vetter 	 * Basic connector properties
122852217195SDaniel Vetter 	 */
122952217195SDaniel Vetter 	tv_selector = drm_property_create_enum(dev, 0,
123052217195SDaniel Vetter 					  "select subconnector",
123152217195SDaniel Vetter 					  drm_tv_select_enum_list,
123252217195SDaniel Vetter 					  ARRAY_SIZE(drm_tv_select_enum_list));
123352217195SDaniel Vetter 	if (!tv_selector)
123452217195SDaniel Vetter 		goto nomem;
123552217195SDaniel Vetter 
123652217195SDaniel Vetter 	dev->mode_config.tv_select_subconnector_property = tv_selector;
123752217195SDaniel Vetter 
123852217195SDaniel Vetter 	tv_subconnector =
123952217195SDaniel Vetter 		drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
124052217195SDaniel Vetter 				    "subconnector",
124152217195SDaniel Vetter 				    drm_tv_subconnector_enum_list,
124252217195SDaniel Vetter 				    ARRAY_SIZE(drm_tv_subconnector_enum_list));
124352217195SDaniel Vetter 	if (!tv_subconnector)
124452217195SDaniel Vetter 		goto nomem;
124552217195SDaniel Vetter 	dev->mode_config.tv_subconnector_property = tv_subconnector;
124652217195SDaniel Vetter 
124752217195SDaniel Vetter 	/*
124852217195SDaniel Vetter 	 * Other, TV specific properties: margins & TV modes.
124952217195SDaniel Vetter 	 */
12506c4f52dcSBoris Brezillon 	if (drm_mode_create_tv_margin_properties(dev))
125152217195SDaniel Vetter 		goto nomem;
125252217195SDaniel Vetter 
125352217195SDaniel Vetter 	dev->mode_config.tv_mode_property =
125452217195SDaniel Vetter 		drm_property_create(dev, DRM_MODE_PROP_ENUM,
125552217195SDaniel Vetter 				    "mode", num_modes);
125652217195SDaniel Vetter 	if (!dev->mode_config.tv_mode_property)
125752217195SDaniel Vetter 		goto nomem;
125852217195SDaniel Vetter 
125952217195SDaniel Vetter 	for (i = 0; i < num_modes; i++)
126030e9db6dSVille Syrjälä 		drm_property_add_enum(dev->mode_config.tv_mode_property,
126152217195SDaniel Vetter 				      i, modes[i]);
126252217195SDaniel Vetter 
126352217195SDaniel Vetter 	dev->mode_config.tv_brightness_property =
126452217195SDaniel Vetter 		drm_property_create_range(dev, 0, "brightness", 0, 100);
126552217195SDaniel Vetter 	if (!dev->mode_config.tv_brightness_property)
126652217195SDaniel Vetter 		goto nomem;
126752217195SDaniel Vetter 
126852217195SDaniel Vetter 	dev->mode_config.tv_contrast_property =
126952217195SDaniel Vetter 		drm_property_create_range(dev, 0, "contrast", 0, 100);
127052217195SDaniel Vetter 	if (!dev->mode_config.tv_contrast_property)
127152217195SDaniel Vetter 		goto nomem;
127252217195SDaniel Vetter 
127352217195SDaniel Vetter 	dev->mode_config.tv_flicker_reduction_property =
127452217195SDaniel Vetter 		drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
127552217195SDaniel Vetter 	if (!dev->mode_config.tv_flicker_reduction_property)
127652217195SDaniel Vetter 		goto nomem;
127752217195SDaniel Vetter 
127852217195SDaniel Vetter 	dev->mode_config.tv_overscan_property =
127952217195SDaniel Vetter 		drm_property_create_range(dev, 0, "overscan", 0, 100);
128052217195SDaniel Vetter 	if (!dev->mode_config.tv_overscan_property)
128152217195SDaniel Vetter 		goto nomem;
128252217195SDaniel Vetter 
128352217195SDaniel Vetter 	dev->mode_config.tv_saturation_property =
128452217195SDaniel Vetter 		drm_property_create_range(dev, 0, "saturation", 0, 100);
128552217195SDaniel Vetter 	if (!dev->mode_config.tv_saturation_property)
128652217195SDaniel Vetter 		goto nomem;
128752217195SDaniel Vetter 
128852217195SDaniel Vetter 	dev->mode_config.tv_hue_property =
128952217195SDaniel Vetter 		drm_property_create_range(dev, 0, "hue", 0, 100);
129052217195SDaniel Vetter 	if (!dev->mode_config.tv_hue_property)
129152217195SDaniel Vetter 		goto nomem;
129252217195SDaniel Vetter 
129352217195SDaniel Vetter 	return 0;
129452217195SDaniel Vetter nomem:
129552217195SDaniel Vetter 	return -ENOMEM;
129652217195SDaniel Vetter }
129752217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tv_properties);
129852217195SDaniel Vetter 
129952217195SDaniel Vetter /**
130052217195SDaniel Vetter  * drm_mode_create_scaling_mode_property - create scaling mode property
130152217195SDaniel Vetter  * @dev: DRM device
130252217195SDaniel Vetter  *
130352217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
130452217195SDaniel Vetter  * connectors.
13058f6e1e22SMaarten Lankhorst  *
13068f6e1e22SMaarten Lankhorst  * Atomic drivers should use drm_connector_attach_scaling_mode_property()
13078f6e1e22SMaarten Lankhorst  * instead to correctly assign &drm_connector_state.picture_aspect_ratio
13088f6e1e22SMaarten Lankhorst  * in the atomic state.
130952217195SDaniel Vetter  */
131052217195SDaniel Vetter int drm_mode_create_scaling_mode_property(struct drm_device *dev)
131152217195SDaniel Vetter {
131252217195SDaniel Vetter 	struct drm_property *scaling_mode;
131352217195SDaniel Vetter 
131452217195SDaniel Vetter 	if (dev->mode_config.scaling_mode_property)
131552217195SDaniel Vetter 		return 0;
131652217195SDaniel Vetter 
131752217195SDaniel Vetter 	scaling_mode =
131852217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "scaling mode",
131952217195SDaniel Vetter 				drm_scaling_mode_enum_list,
132052217195SDaniel Vetter 				    ARRAY_SIZE(drm_scaling_mode_enum_list));
132152217195SDaniel Vetter 
132252217195SDaniel Vetter 	dev->mode_config.scaling_mode_property = scaling_mode;
132352217195SDaniel Vetter 
132452217195SDaniel Vetter 	return 0;
132552217195SDaniel Vetter }
132652217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
132752217195SDaniel Vetter 
132852217195SDaniel Vetter /**
1329ab7a664fSNicholas Kazlauskas  * DOC: Variable refresh properties
1330ab7a664fSNicholas Kazlauskas  *
1331ab7a664fSNicholas Kazlauskas  * Variable refresh rate capable displays can dynamically adjust their
1332ab7a664fSNicholas Kazlauskas  * refresh rate by extending the duration of their vertical front porch
1333ab7a664fSNicholas Kazlauskas  * until page flip or timeout occurs. This can reduce or remove stuttering
1334ab7a664fSNicholas Kazlauskas  * and latency in scenarios where the page flip does not align with the
1335ab7a664fSNicholas Kazlauskas  * vblank interval.
1336ab7a664fSNicholas Kazlauskas  *
1337ab7a664fSNicholas Kazlauskas  * An example scenario would be an application flipping at a constant rate
1338ab7a664fSNicholas Kazlauskas  * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
1339ab7a664fSNicholas Kazlauskas  * interval and the same contents will be displayed twice. This can be
1340ab7a664fSNicholas Kazlauskas  * observed as stuttering for content with motion.
1341ab7a664fSNicholas Kazlauskas  *
1342ab7a664fSNicholas Kazlauskas  * If variable refresh rate was active on a display that supported a
1343ab7a664fSNicholas Kazlauskas  * variable refresh range from 35Hz to 60Hz no stuttering would be observable
1344ab7a664fSNicholas Kazlauskas  * for the example scenario. The minimum supported variable refresh rate of
1345ab7a664fSNicholas Kazlauskas  * 35Hz is below the page flip frequency and the vertical front porch can
1346ab7a664fSNicholas Kazlauskas  * be extended until the page flip occurs. The vblank interval will be
1347ab7a664fSNicholas Kazlauskas  * directly aligned to the page flip rate.
1348ab7a664fSNicholas Kazlauskas  *
1349ab7a664fSNicholas Kazlauskas  * Not all userspace content is suitable for use with variable refresh rate.
1350ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may worsen
1351ab7a664fSNicholas Kazlauskas  * perceived stuttering for input sensitive applications.
1352ab7a664fSNicholas Kazlauskas  *
1353ab7a664fSNicholas Kazlauskas  * Panel brightness will also vary with vertical front porch duration. Some
1354ab7a664fSNicholas Kazlauskas  * panels may have noticeable differences in brightness between the minimum
1355ab7a664fSNicholas Kazlauskas  * vertical front porch duration and the maximum vertical front porch duration.
1356ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may produce
1357ab7a664fSNicholas Kazlauskas  * observable flickering for such panels.
1358ab7a664fSNicholas Kazlauskas  *
1359ab7a664fSNicholas Kazlauskas  * Userspace control for variable refresh rate is supported via properties
1360ab7a664fSNicholas Kazlauskas  * on the &drm_connector and &drm_crtc objects.
1361ab7a664fSNicholas Kazlauskas  *
1362ab7a664fSNicholas Kazlauskas  * "vrr_capable":
1363ab7a664fSNicholas Kazlauskas  *	Optional &drm_connector boolean property that drivers should attach
1364ab7a664fSNicholas Kazlauskas  *	with drm_connector_attach_vrr_capable_property() on connectors that
1365ab7a664fSNicholas Kazlauskas  *	could support variable refresh rates. Drivers should update the
1366ab7a664fSNicholas Kazlauskas  *	property value by calling drm_connector_set_vrr_capable_property().
1367ab7a664fSNicholas Kazlauskas  *
1368ab7a664fSNicholas Kazlauskas  *	Absence of the property should indicate absence of support.
1369ab7a664fSNicholas Kazlauskas  *
137077086014SDaniel Vetter  * "VRR_ENABLED":
1371ab7a664fSNicholas Kazlauskas  *	Default &drm_crtc boolean property that notifies the driver that the
1372ab7a664fSNicholas Kazlauskas  *	content on the CRTC is suitable for variable refresh rate presentation.
1373ab7a664fSNicholas Kazlauskas  *	The driver will take this property as a hint to enable variable
1374ab7a664fSNicholas Kazlauskas  *	refresh rate support if the receiver supports it, ie. if the
1375ab7a664fSNicholas Kazlauskas  *	"vrr_capable" property is true on the &drm_connector object. The
1376ab7a664fSNicholas Kazlauskas  *	vertical front porch duration will be extended until page-flip or
1377ab7a664fSNicholas Kazlauskas  *	timeout when enabled.
1378ab7a664fSNicholas Kazlauskas  *
1379ab7a664fSNicholas Kazlauskas  *	The minimum vertical front porch duration is defined as the vertical
1380ab7a664fSNicholas Kazlauskas  *	front porch duration for the current mode.
1381ab7a664fSNicholas Kazlauskas  *
1382ab7a664fSNicholas Kazlauskas  *	The maximum vertical front porch duration is greater than or equal to
1383ab7a664fSNicholas Kazlauskas  *	the minimum vertical front porch duration. The duration is derived
1384ab7a664fSNicholas Kazlauskas  *	from the minimum supported variable refresh rate for the connector.
1385ab7a664fSNicholas Kazlauskas  *
1386ab7a664fSNicholas Kazlauskas  *	The driver may place further restrictions within these minimum
1387ab7a664fSNicholas Kazlauskas  *	and maximum bounds.
1388ab7a664fSNicholas Kazlauskas  *
1389ab7a664fSNicholas Kazlauskas  *	The semantics for the vertical blank timestamp differ when
1390ab7a664fSNicholas Kazlauskas  *	variable refresh rate is active. The vertical blank timestamp
1391ab7a664fSNicholas Kazlauskas  *	is defined to be an estimate using the current mode's fixed
1392ab7a664fSNicholas Kazlauskas  *	refresh rate timings. The semantics for the page-flip event
1393ab7a664fSNicholas Kazlauskas  *	timestamp remain the same.
1394ab7a664fSNicholas Kazlauskas  */
1395ab7a664fSNicholas Kazlauskas 
1396ab7a664fSNicholas Kazlauskas /**
1397ba1b0f6cSNicholas Kazlauskas  * drm_connector_attach_vrr_capable_property - creates the
1398ba1b0f6cSNicholas Kazlauskas  * vrr_capable property
1399ba1b0f6cSNicholas Kazlauskas  * @connector: connector to create the vrr_capable property on.
1400ba1b0f6cSNicholas Kazlauskas  *
1401ba1b0f6cSNicholas Kazlauskas  * This is used by atomic drivers to add support for querying
1402ba1b0f6cSNicholas Kazlauskas  * variable refresh rate capability for a connector.
1403ba1b0f6cSNicholas Kazlauskas  *
1404ba1b0f6cSNicholas Kazlauskas  * Returns:
1405ba1b0f6cSNicholas Kazlauskas  * Zero on success, negative errono on failure.
1406ba1b0f6cSNicholas Kazlauskas  */
1407ba1b0f6cSNicholas Kazlauskas int drm_connector_attach_vrr_capable_property(
1408ba1b0f6cSNicholas Kazlauskas 	struct drm_connector *connector)
1409ba1b0f6cSNicholas Kazlauskas {
1410ba1b0f6cSNicholas Kazlauskas 	struct drm_device *dev = connector->dev;
1411ba1b0f6cSNicholas Kazlauskas 	struct drm_property *prop;
1412ba1b0f6cSNicholas Kazlauskas 
1413ba1b0f6cSNicholas Kazlauskas 	if (!connector->vrr_capable_property) {
1414ba1b0f6cSNicholas Kazlauskas 		prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
1415ba1b0f6cSNicholas Kazlauskas 			"vrr_capable");
1416ba1b0f6cSNicholas Kazlauskas 		if (!prop)
1417ba1b0f6cSNicholas Kazlauskas 			return -ENOMEM;
1418ba1b0f6cSNicholas Kazlauskas 
1419ba1b0f6cSNicholas Kazlauskas 		connector->vrr_capable_property = prop;
1420ba1b0f6cSNicholas Kazlauskas 		drm_object_attach_property(&connector->base, prop, 0);
1421ba1b0f6cSNicholas Kazlauskas 	}
1422ba1b0f6cSNicholas Kazlauskas 
1423ba1b0f6cSNicholas Kazlauskas 	return 0;
1424ba1b0f6cSNicholas Kazlauskas }
1425ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
1426ba1b0f6cSNicholas Kazlauskas 
1427ba1b0f6cSNicholas Kazlauskas /**
14288f6e1e22SMaarten Lankhorst  * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
14298f6e1e22SMaarten Lankhorst  * @connector: connector to attach scaling mode property on.
14308f6e1e22SMaarten Lankhorst  * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
14318f6e1e22SMaarten Lankhorst  *
14328f6e1e22SMaarten Lankhorst  * This is used to add support for scaling mode to atomic drivers.
14338f6e1e22SMaarten Lankhorst  * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio
14348f6e1e22SMaarten Lankhorst  * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
14358f6e1e22SMaarten Lankhorst  *
14368f6e1e22SMaarten Lankhorst  * This is the atomic version of drm_mode_create_scaling_mode_property().
14378f6e1e22SMaarten Lankhorst  *
14388f6e1e22SMaarten Lankhorst  * Returns:
14398f6e1e22SMaarten Lankhorst  * Zero on success, negative errno on failure.
14408f6e1e22SMaarten Lankhorst  */
14418f6e1e22SMaarten Lankhorst int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
14428f6e1e22SMaarten Lankhorst 					       u32 scaling_mode_mask)
14438f6e1e22SMaarten Lankhorst {
14448f6e1e22SMaarten Lankhorst 	struct drm_device *dev = connector->dev;
14458f6e1e22SMaarten Lankhorst 	struct drm_property *scaling_mode_property;
144630e9db6dSVille Syrjälä 	int i;
14478f6e1e22SMaarten Lankhorst 	const unsigned valid_scaling_mode_mask =
14488f6e1e22SMaarten Lankhorst 		(1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
14498f6e1e22SMaarten Lankhorst 
14508f6e1e22SMaarten Lankhorst 	if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
14518f6e1e22SMaarten Lankhorst 		    scaling_mode_mask & ~valid_scaling_mode_mask))
14528f6e1e22SMaarten Lankhorst 		return -EINVAL;
14538f6e1e22SMaarten Lankhorst 
14548f6e1e22SMaarten Lankhorst 	scaling_mode_property =
14558f6e1e22SMaarten Lankhorst 		drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
14568f6e1e22SMaarten Lankhorst 				    hweight32(scaling_mode_mask));
14578f6e1e22SMaarten Lankhorst 
14588f6e1e22SMaarten Lankhorst 	if (!scaling_mode_property)
14598f6e1e22SMaarten Lankhorst 		return -ENOMEM;
14608f6e1e22SMaarten Lankhorst 
14618f6e1e22SMaarten Lankhorst 	for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
14628f6e1e22SMaarten Lankhorst 		int ret;
14638f6e1e22SMaarten Lankhorst 
14648f6e1e22SMaarten Lankhorst 		if (!(BIT(i) & scaling_mode_mask))
14658f6e1e22SMaarten Lankhorst 			continue;
14668f6e1e22SMaarten Lankhorst 
146730e9db6dSVille Syrjälä 		ret = drm_property_add_enum(scaling_mode_property,
14688f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].type,
14698f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].name);
14708f6e1e22SMaarten Lankhorst 
14718f6e1e22SMaarten Lankhorst 		if (ret) {
14728f6e1e22SMaarten Lankhorst 			drm_property_destroy(dev, scaling_mode_property);
14738f6e1e22SMaarten Lankhorst 
14748f6e1e22SMaarten Lankhorst 			return ret;
14758f6e1e22SMaarten Lankhorst 		}
14768f6e1e22SMaarten Lankhorst 	}
14778f6e1e22SMaarten Lankhorst 
14788f6e1e22SMaarten Lankhorst 	drm_object_attach_property(&connector->base,
14798f6e1e22SMaarten Lankhorst 				   scaling_mode_property, 0);
14808f6e1e22SMaarten Lankhorst 
14818f6e1e22SMaarten Lankhorst 	connector->scaling_mode_property = scaling_mode_property;
14828f6e1e22SMaarten Lankhorst 
14838f6e1e22SMaarten Lankhorst 	return 0;
14848f6e1e22SMaarten Lankhorst }
14858f6e1e22SMaarten Lankhorst EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
14868f6e1e22SMaarten Lankhorst 
14878f6e1e22SMaarten Lankhorst /**
148824557865SSean Paul  * drm_connector_attach_content_protection_property - attach content protection
148924557865SSean Paul  * property
149024557865SSean Paul  *
149124557865SSean Paul  * @connector: connector to attach CP property on.
149224557865SSean Paul  *
149324557865SSean Paul  * This is used to add support for content protection on select connectors.
149424557865SSean Paul  * Content Protection is intentionally vague to allow for different underlying
149524557865SSean Paul  * technologies, however it is most implemented by HDCP.
149624557865SSean Paul  *
149724557865SSean Paul  * The content protection will be set to &drm_connector_state.content_protection
149824557865SSean Paul  *
149924557865SSean Paul  * Returns:
150024557865SSean Paul  * Zero on success, negative errno on failure.
150124557865SSean Paul  */
150224557865SSean Paul int drm_connector_attach_content_protection_property(
150324557865SSean Paul 		struct drm_connector *connector)
150424557865SSean Paul {
150524557865SSean Paul 	struct drm_device *dev = connector->dev;
150624557865SSean Paul 	struct drm_property *prop;
150724557865SSean Paul 
150824557865SSean Paul 	prop = drm_property_create_enum(dev, 0, "Content Protection",
150924557865SSean Paul 					drm_cp_enum_list,
151024557865SSean Paul 					ARRAY_SIZE(drm_cp_enum_list));
151124557865SSean Paul 	if (!prop)
151224557865SSean Paul 		return -ENOMEM;
151324557865SSean Paul 
151424557865SSean Paul 	drm_object_attach_property(&connector->base, prop,
151524557865SSean Paul 				   DRM_MODE_CONTENT_PROTECTION_UNDESIRED);
151624557865SSean Paul 
151724557865SSean Paul 	connector->content_protection_property = prop;
151824557865SSean Paul 
151924557865SSean Paul 	return 0;
152024557865SSean Paul }
152124557865SSean Paul EXPORT_SYMBOL(drm_connector_attach_content_protection_property);
152224557865SSean Paul 
152324557865SSean Paul /**
152452217195SDaniel Vetter  * drm_mode_create_aspect_ratio_property - create aspect ratio property
152552217195SDaniel Vetter  * @dev: DRM device
152652217195SDaniel Vetter  *
152752217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
152852217195SDaniel Vetter  * connectors.
152952217195SDaniel Vetter  *
153052217195SDaniel Vetter  * Returns:
153152217195SDaniel Vetter  * Zero on success, negative errno on failure.
153252217195SDaniel Vetter  */
153352217195SDaniel Vetter int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
153452217195SDaniel Vetter {
153552217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property)
153652217195SDaniel Vetter 		return 0;
153752217195SDaniel Vetter 
153852217195SDaniel Vetter 	dev->mode_config.aspect_ratio_property =
153952217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "aspect ratio",
154052217195SDaniel Vetter 				drm_aspect_ratio_enum_list,
154152217195SDaniel Vetter 				ARRAY_SIZE(drm_aspect_ratio_enum_list));
154252217195SDaniel Vetter 
154352217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property == NULL)
154452217195SDaniel Vetter 		return -ENOMEM;
154552217195SDaniel Vetter 
154652217195SDaniel Vetter 	return 0;
154752217195SDaniel Vetter }
154852217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
154952217195SDaniel Vetter 
155052217195SDaniel Vetter /**
155150525c33SStanislav Lisovskiy  * drm_mode_create_content_type_property - create content type property
155250525c33SStanislav Lisovskiy  * @dev: DRM device
155350525c33SStanislav Lisovskiy  *
155450525c33SStanislav Lisovskiy  * Called by a driver the first time it's needed, must be attached to desired
155550525c33SStanislav Lisovskiy  * connectors.
155650525c33SStanislav Lisovskiy  *
155750525c33SStanislav Lisovskiy  * Returns:
155850525c33SStanislav Lisovskiy  * Zero on success, negative errno on failure.
155950525c33SStanislav Lisovskiy  */
156050525c33SStanislav Lisovskiy int drm_mode_create_content_type_property(struct drm_device *dev)
156150525c33SStanislav Lisovskiy {
156250525c33SStanislav Lisovskiy 	if (dev->mode_config.content_type_property)
156350525c33SStanislav Lisovskiy 		return 0;
156450525c33SStanislav Lisovskiy 
156550525c33SStanislav Lisovskiy 	dev->mode_config.content_type_property =
156650525c33SStanislav Lisovskiy 		drm_property_create_enum(dev, 0, "content type",
156750525c33SStanislav Lisovskiy 					 drm_content_type_enum_list,
156850525c33SStanislav Lisovskiy 					 ARRAY_SIZE(drm_content_type_enum_list));
156950525c33SStanislav Lisovskiy 
157050525c33SStanislav Lisovskiy 	if (dev->mode_config.content_type_property == NULL)
157150525c33SStanislav Lisovskiy 		return -ENOMEM;
157250525c33SStanislav Lisovskiy 
157350525c33SStanislav Lisovskiy 	return 0;
157450525c33SStanislav Lisovskiy }
157550525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_mode_create_content_type_property);
157650525c33SStanislav Lisovskiy 
157750525c33SStanislav Lisovskiy /**
157852217195SDaniel Vetter  * drm_mode_create_suggested_offset_properties - create suggests offset properties
157952217195SDaniel Vetter  * @dev: DRM device
158052217195SDaniel Vetter  *
158152217195SDaniel Vetter  * Create the the suggested x/y offset property for connectors.
158252217195SDaniel Vetter  */
158352217195SDaniel Vetter int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
158452217195SDaniel Vetter {
158552217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
158652217195SDaniel Vetter 		return 0;
158752217195SDaniel Vetter 
158852217195SDaniel Vetter 	dev->mode_config.suggested_x_property =
158952217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
159052217195SDaniel Vetter 
159152217195SDaniel Vetter 	dev->mode_config.suggested_y_property =
159252217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
159352217195SDaniel Vetter 
159452217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property == NULL ||
159552217195SDaniel Vetter 	    dev->mode_config.suggested_y_property == NULL)
159652217195SDaniel Vetter 		return -ENOMEM;
159752217195SDaniel Vetter 	return 0;
159852217195SDaniel Vetter }
159952217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
160052217195SDaniel Vetter 
160152217195SDaniel Vetter /**
160297e14fbeSDaniel Vetter  * drm_connector_set_path_property - set tile property on connector
160352217195SDaniel Vetter  * @connector: connector to set property on.
160452217195SDaniel Vetter  * @path: path to use for property; must not be NULL.
160552217195SDaniel Vetter  *
160652217195SDaniel Vetter  * This creates a property to expose to userspace to specify a
160752217195SDaniel Vetter  * connector path. This is mainly used for DisplayPort MST where
160852217195SDaniel Vetter  * connectors have a topology and we want to allow userspace to give
160952217195SDaniel Vetter  * them more meaningful names.
161052217195SDaniel Vetter  *
161152217195SDaniel Vetter  * Returns:
161252217195SDaniel Vetter  * Zero on success, negative errno on failure.
161352217195SDaniel Vetter  */
161497e14fbeSDaniel Vetter int drm_connector_set_path_property(struct drm_connector *connector,
161552217195SDaniel Vetter 				    const char *path)
161652217195SDaniel Vetter {
161752217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
161852217195SDaniel Vetter 	int ret;
161952217195SDaniel Vetter 
162052217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
162152217195SDaniel Vetter 	                                       &connector->path_blob_ptr,
162252217195SDaniel Vetter 	                                       strlen(path) + 1,
162352217195SDaniel Vetter 	                                       path,
162452217195SDaniel Vetter 	                                       &connector->base,
162552217195SDaniel Vetter 	                                       dev->mode_config.path_property);
162652217195SDaniel Vetter 	return ret;
162752217195SDaniel Vetter }
162897e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_path_property);
162952217195SDaniel Vetter 
163052217195SDaniel Vetter /**
163197e14fbeSDaniel Vetter  * drm_connector_set_tile_property - set tile property on connector
163252217195SDaniel Vetter  * @connector: connector to set property on.
163352217195SDaniel Vetter  *
163452217195SDaniel Vetter  * This looks up the tile information for a connector, and creates a
163552217195SDaniel Vetter  * property for userspace to parse if it exists. The property is of
163652217195SDaniel Vetter  * the form of 8 integers using ':' as a separator.
163752217195SDaniel Vetter  *
163852217195SDaniel Vetter  * Returns:
163952217195SDaniel Vetter  * Zero on success, errno on failure.
164052217195SDaniel Vetter  */
164197e14fbeSDaniel Vetter int drm_connector_set_tile_property(struct drm_connector *connector)
164252217195SDaniel Vetter {
164352217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
164452217195SDaniel Vetter 	char tile[256];
164552217195SDaniel Vetter 	int ret;
164652217195SDaniel Vetter 
164752217195SDaniel Vetter 	if (!connector->has_tile) {
164852217195SDaniel Vetter 		ret  = drm_property_replace_global_blob(dev,
164952217195SDaniel Vetter 		                                        &connector->tile_blob_ptr,
165052217195SDaniel Vetter 		                                        0,
165152217195SDaniel Vetter 		                                        NULL,
165252217195SDaniel Vetter 		                                        &connector->base,
165352217195SDaniel Vetter 		                                        dev->mode_config.tile_property);
165452217195SDaniel Vetter 		return ret;
165552217195SDaniel Vetter 	}
165652217195SDaniel Vetter 
165752217195SDaniel Vetter 	snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
165852217195SDaniel Vetter 		 connector->tile_group->id, connector->tile_is_single_monitor,
165952217195SDaniel Vetter 		 connector->num_h_tile, connector->num_v_tile,
166052217195SDaniel Vetter 		 connector->tile_h_loc, connector->tile_v_loc,
166152217195SDaniel Vetter 		 connector->tile_h_size, connector->tile_v_size);
166252217195SDaniel Vetter 
166352217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
166452217195SDaniel Vetter 	                                       &connector->tile_blob_ptr,
166552217195SDaniel Vetter 	                                       strlen(tile) + 1,
166652217195SDaniel Vetter 	                                       tile,
166752217195SDaniel Vetter 	                                       &connector->base,
166852217195SDaniel Vetter 	                                       dev->mode_config.tile_property);
166952217195SDaniel Vetter 	return ret;
167052217195SDaniel Vetter }
167197e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_tile_property);
167252217195SDaniel Vetter 
167352217195SDaniel Vetter /**
1674c555f023SDaniel Vetter  * drm_connector_update_edid_property - update the edid property of a connector
167552217195SDaniel Vetter  * @connector: drm connector
167652217195SDaniel Vetter  * @edid: new value of the edid property
167752217195SDaniel Vetter  *
167852217195SDaniel Vetter  * This function creates a new blob modeset object and assigns its id to the
167952217195SDaniel Vetter  * connector's edid property.
168052217195SDaniel Vetter  *
168152217195SDaniel Vetter  * Returns:
168252217195SDaniel Vetter  * Zero on success, negative errno on failure.
168352217195SDaniel Vetter  */
1684c555f023SDaniel Vetter int drm_connector_update_edid_property(struct drm_connector *connector,
168552217195SDaniel Vetter 				       const struct edid *edid)
168652217195SDaniel Vetter {
168752217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
168852217195SDaniel Vetter 	size_t size = 0;
168952217195SDaniel Vetter 	int ret;
169052217195SDaniel Vetter 
169152217195SDaniel Vetter 	/* ignore requests to set edid when overridden */
169252217195SDaniel Vetter 	if (connector->override_edid)
169352217195SDaniel Vetter 		return 0;
169452217195SDaniel Vetter 
169552217195SDaniel Vetter 	if (edid)
169652217195SDaniel Vetter 		size = EDID_LENGTH * (1 + edid->extensions);
169752217195SDaniel Vetter 
1698170178feSKeith Packard 	/* Set the display info, using edid if available, otherwise
1699170178feSKeith Packard 	 * reseting the values to defaults. This duplicates the work
1700170178feSKeith Packard 	 * done in drm_add_edid_modes, but that function is not
1701170178feSKeith Packard 	 * consistently called before this one in all drivers and the
1702170178feSKeith Packard 	 * computation is cheap enough that it seems better to
1703170178feSKeith Packard 	 * duplicate it rather than attempt to ensure some arbitrary
1704170178feSKeith Packard 	 * ordering of calls.
1705170178feSKeith Packard 	 */
1706170178feSKeith Packard 	if (edid)
1707170178feSKeith Packard 		drm_add_display_info(connector, edid);
1708170178feSKeith Packard 	else
1709170178feSKeith Packard 		drm_reset_display_info(connector);
1710170178feSKeith Packard 
171166660d4cSDave Airlie 	drm_object_property_set_value(&connector->base,
171266660d4cSDave Airlie 				      dev->mode_config.non_desktop_property,
171366660d4cSDave Airlie 				      connector->display_info.non_desktop);
171466660d4cSDave Airlie 
171552217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
171652217195SDaniel Vetter 					       &connector->edid_blob_ptr,
171752217195SDaniel Vetter 	                                       size,
171852217195SDaniel Vetter 	                                       edid,
171952217195SDaniel Vetter 	                                       &connector->base,
172052217195SDaniel Vetter 	                                       dev->mode_config.edid_property);
172152217195SDaniel Vetter 	return ret;
172252217195SDaniel Vetter }
1723c555f023SDaniel Vetter EXPORT_SYMBOL(drm_connector_update_edid_property);
172452217195SDaniel Vetter 
172540ee6fbeSManasi Navare /**
172697e14fbeSDaniel Vetter  * drm_connector_set_link_status_property - Set link status property of a connector
172740ee6fbeSManasi Navare  * @connector: drm connector
172840ee6fbeSManasi Navare  * @link_status: new value of link status property (0: Good, 1: Bad)
172940ee6fbeSManasi Navare  *
173040ee6fbeSManasi Navare  * In usual working scenario, this link status property will always be set to
173140ee6fbeSManasi Navare  * "GOOD". If something fails during or after a mode set, the kernel driver
173240ee6fbeSManasi Navare  * may set this link status property to "BAD". The caller then needs to send a
173340ee6fbeSManasi Navare  * hotplug uevent for userspace to re-check the valid modes through
173440ee6fbeSManasi Navare  * GET_CONNECTOR_IOCTL and retry modeset.
173540ee6fbeSManasi Navare  *
173640ee6fbeSManasi Navare  * Note: Drivers cannot rely on userspace to support this property and
173740ee6fbeSManasi Navare  * issue a modeset. As such, they may choose to handle issues (like
173840ee6fbeSManasi Navare  * re-training a link) without userspace's intervention.
173940ee6fbeSManasi Navare  *
174040ee6fbeSManasi Navare  * The reason for adding this property is to handle link training failures, but
174140ee6fbeSManasi Navare  * it is not limited to DP or link training. For example, if we implement
174240ee6fbeSManasi Navare  * asynchronous setcrtc, this property can be used to report any failures in that.
174340ee6fbeSManasi Navare  */
174497e14fbeSDaniel Vetter void drm_connector_set_link_status_property(struct drm_connector *connector,
174540ee6fbeSManasi Navare 					    uint64_t link_status)
174640ee6fbeSManasi Navare {
174740ee6fbeSManasi Navare 	struct drm_device *dev = connector->dev;
174840ee6fbeSManasi Navare 
174940ee6fbeSManasi Navare 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
175040ee6fbeSManasi Navare 	connector->state->link_status = link_status;
175140ee6fbeSManasi Navare 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
175240ee6fbeSManasi Navare }
175397e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_link_status_property);
175440ee6fbeSManasi Navare 
17558d70f395SHans de Goede /**
175647e22ff1SRadhakrishna Sripada  * drm_connector_attach_max_bpc_property - attach "max bpc" property
175747e22ff1SRadhakrishna Sripada  * @connector: connector to attach max bpc property on.
175847e22ff1SRadhakrishna Sripada  * @min: The minimum bit depth supported by the connector.
175947e22ff1SRadhakrishna Sripada  * @max: The maximum bit depth supported by the connector.
176047e22ff1SRadhakrishna Sripada  *
176147e22ff1SRadhakrishna Sripada  * This is used to add support for limiting the bit depth on a connector.
176247e22ff1SRadhakrishna Sripada  *
176347e22ff1SRadhakrishna Sripada  * Returns:
176447e22ff1SRadhakrishna Sripada  * Zero on success, negative errno on failure.
176547e22ff1SRadhakrishna Sripada  */
176647e22ff1SRadhakrishna Sripada int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
176747e22ff1SRadhakrishna Sripada 					  int min, int max)
176847e22ff1SRadhakrishna Sripada {
176947e22ff1SRadhakrishna Sripada 	struct drm_device *dev = connector->dev;
177047e22ff1SRadhakrishna Sripada 	struct drm_property *prop;
177147e22ff1SRadhakrishna Sripada 
177247e22ff1SRadhakrishna Sripada 	prop = connector->max_bpc_property;
177347e22ff1SRadhakrishna Sripada 	if (!prop) {
177447e22ff1SRadhakrishna Sripada 		prop = drm_property_create_range(dev, 0, "max bpc", min, max);
177547e22ff1SRadhakrishna Sripada 		if (!prop)
177647e22ff1SRadhakrishna Sripada 			return -ENOMEM;
177747e22ff1SRadhakrishna Sripada 
177847e22ff1SRadhakrishna Sripada 		connector->max_bpc_property = prop;
177947e22ff1SRadhakrishna Sripada 	}
178047e22ff1SRadhakrishna Sripada 
178147e22ff1SRadhakrishna Sripada 	drm_object_attach_property(&connector->base, prop, max);
178247e22ff1SRadhakrishna Sripada 	connector->state->max_requested_bpc = max;
178347e22ff1SRadhakrishna Sripada 	connector->state->max_bpc = max;
178447e22ff1SRadhakrishna Sripada 
178547e22ff1SRadhakrishna Sripada 	return 0;
178647e22ff1SRadhakrishna Sripada }
178747e22ff1SRadhakrishna Sripada EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
178847e22ff1SRadhakrishna Sripada 
178947e22ff1SRadhakrishna Sripada /**
1790ba1b0f6cSNicholas Kazlauskas  * drm_connector_set_vrr_capable_property - sets the variable refresh rate
1791ba1b0f6cSNicholas Kazlauskas  * capable property for a connector
1792ba1b0f6cSNicholas Kazlauskas  * @connector: drm connector
1793ba1b0f6cSNicholas Kazlauskas  * @capable: True if the connector is variable refresh rate capable
1794ba1b0f6cSNicholas Kazlauskas  *
1795ba1b0f6cSNicholas Kazlauskas  * Should be used by atomic drivers to update the indicated support for
1796ba1b0f6cSNicholas Kazlauskas  * variable refresh rate over a connector.
1797ba1b0f6cSNicholas Kazlauskas  */
1798ba1b0f6cSNicholas Kazlauskas void drm_connector_set_vrr_capable_property(
1799ba1b0f6cSNicholas Kazlauskas 		struct drm_connector *connector, bool capable)
1800ba1b0f6cSNicholas Kazlauskas {
1801ba1b0f6cSNicholas Kazlauskas 	drm_object_property_set_value(&connector->base,
1802ba1b0f6cSNicholas Kazlauskas 				      connector->vrr_capable_property,
1803ba1b0f6cSNicholas Kazlauskas 				      capable);
1804ba1b0f6cSNicholas Kazlauskas }
1805ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
1806ba1b0f6cSNicholas Kazlauskas 
1807ba1b0f6cSNicholas Kazlauskas /**
18088d70f395SHans de Goede  * drm_connector_init_panel_orientation_property -
18098d70f395SHans de Goede  *	initialize the connecters panel_orientation property
18108d70f395SHans de Goede  * @connector: connector for which to init the panel-orientation property.
18118d70f395SHans de Goede  * @width: width in pixels of the panel, used for panel quirk detection
18128d70f395SHans de Goede  * @height: height in pixels of the panel, used for panel quirk detection
18138d70f395SHans de Goede  *
18148d70f395SHans de Goede  * This function should only be called for built-in panels, after setting
18158d70f395SHans de Goede  * connector->display_info.panel_orientation first (if known).
18168d70f395SHans de Goede  *
18178d70f395SHans de Goede  * This function will check for platform specific (e.g. DMI based) quirks
18188d70f395SHans de Goede  * overriding display_info.panel_orientation first, then if panel_orientation
18198d70f395SHans de Goede  * is not DRM_MODE_PANEL_ORIENTATION_UNKNOWN it will attach the
18208d70f395SHans de Goede  * "panel orientation" property to the connector.
18218d70f395SHans de Goede  *
18228d70f395SHans de Goede  * Returns:
18238d70f395SHans de Goede  * Zero on success, negative errno on failure.
18248d70f395SHans de Goede  */
18258d70f395SHans de Goede int drm_connector_init_panel_orientation_property(
18268d70f395SHans de Goede 	struct drm_connector *connector, int width, int height)
18278d70f395SHans de Goede {
18288d70f395SHans de Goede 	struct drm_device *dev = connector->dev;
18298d70f395SHans de Goede 	struct drm_display_info *info = &connector->display_info;
18308d70f395SHans de Goede 	struct drm_property *prop;
18318d70f395SHans de Goede 	int orientation_quirk;
18328d70f395SHans de Goede 
18338d70f395SHans de Goede 	orientation_quirk = drm_get_panel_orientation_quirk(width, height);
18348d70f395SHans de Goede 	if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
18358d70f395SHans de Goede 		info->panel_orientation = orientation_quirk;
18368d70f395SHans de Goede 
18378d70f395SHans de Goede 	if (info->panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
18388d70f395SHans de Goede 		return 0;
18398d70f395SHans de Goede 
18408d70f395SHans de Goede 	prop = dev->mode_config.panel_orientation_property;
18418d70f395SHans de Goede 	if (!prop) {
18428d70f395SHans de Goede 		prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
18438d70f395SHans de Goede 				"panel orientation",
18448d70f395SHans de Goede 				drm_panel_orientation_enum_list,
18458d70f395SHans de Goede 				ARRAY_SIZE(drm_panel_orientation_enum_list));
18468d70f395SHans de Goede 		if (!prop)
18478d70f395SHans de Goede 			return -ENOMEM;
18488d70f395SHans de Goede 
18498d70f395SHans de Goede 		dev->mode_config.panel_orientation_property = prop;
18508d70f395SHans de Goede 	}
18518d70f395SHans de Goede 
18528d70f395SHans de Goede 	drm_object_attach_property(&connector->base, prop,
18538d70f395SHans de Goede 				   info->panel_orientation);
18548d70f395SHans de Goede 	return 0;
18558d70f395SHans de Goede }
18568d70f395SHans de Goede EXPORT_SYMBOL(drm_connector_init_panel_orientation_property);
18578d70f395SHans de Goede 
185897e14fbeSDaniel Vetter int drm_connector_set_obj_prop(struct drm_mode_object *obj,
185952217195SDaniel Vetter 				    struct drm_property *property,
186052217195SDaniel Vetter 				    uint64_t value)
186152217195SDaniel Vetter {
186252217195SDaniel Vetter 	int ret = -EINVAL;
186352217195SDaniel Vetter 	struct drm_connector *connector = obj_to_connector(obj);
186452217195SDaniel Vetter 
186552217195SDaniel Vetter 	/* Do DPMS ourselves */
186652217195SDaniel Vetter 	if (property == connector->dev->mode_config.dpms_property) {
186752217195SDaniel Vetter 		ret = (*connector->funcs->dpms)(connector, (int)value);
186852217195SDaniel Vetter 	} else if (connector->funcs->set_property)
186952217195SDaniel Vetter 		ret = connector->funcs->set_property(connector, property, value);
187052217195SDaniel Vetter 
1871144a7999SDaniel Vetter 	if (!ret)
187252217195SDaniel Vetter 		drm_object_property_set_value(&connector->base, property, value);
187352217195SDaniel Vetter 	return ret;
187452217195SDaniel Vetter }
187552217195SDaniel Vetter 
187697e14fbeSDaniel Vetter int drm_connector_property_set_ioctl(struct drm_device *dev,
187752217195SDaniel Vetter 				     void *data, struct drm_file *file_priv)
187852217195SDaniel Vetter {
187952217195SDaniel Vetter 	struct drm_mode_connector_set_property *conn_set_prop = data;
188052217195SDaniel Vetter 	struct drm_mode_obj_set_property obj_set_prop = {
188152217195SDaniel Vetter 		.value = conn_set_prop->value,
188252217195SDaniel Vetter 		.prop_id = conn_set_prop->prop_id,
188352217195SDaniel Vetter 		.obj_id = conn_set_prop->connector_id,
188452217195SDaniel Vetter 		.obj_type = DRM_MODE_OBJECT_CONNECTOR
188552217195SDaniel Vetter 	};
188652217195SDaniel Vetter 
188752217195SDaniel Vetter 	/* It does all the locking and checking we need */
188852217195SDaniel Vetter 	return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
188952217195SDaniel Vetter }
189052217195SDaniel Vetter 
189152217195SDaniel Vetter static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
189252217195SDaniel Vetter {
189352217195SDaniel Vetter 	/* For atomic drivers only state objects are synchronously updated and
189452217195SDaniel Vetter 	 * protected by modeset locks, so check those first. */
189552217195SDaniel Vetter 	if (connector->state)
189652217195SDaniel Vetter 		return connector->state->best_encoder;
189752217195SDaniel Vetter 	return connector->encoder;
189852217195SDaniel Vetter }
189952217195SDaniel Vetter 
1900c3ff0cdbSAnkit Nautiyal static bool
1901c3ff0cdbSAnkit Nautiyal drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
1902c3ff0cdbSAnkit Nautiyal 			     const struct list_head *export_list,
190352217195SDaniel Vetter 			     const struct drm_file *file_priv)
190452217195SDaniel Vetter {
190552217195SDaniel Vetter 	/*
190652217195SDaniel Vetter 	 * If user-space hasn't configured the driver to expose the stereo 3D
190752217195SDaniel Vetter 	 * modes, don't expose them.
190852217195SDaniel Vetter 	 */
190952217195SDaniel Vetter 	if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
191052217195SDaniel Vetter 		return false;
1911c3ff0cdbSAnkit Nautiyal 	/*
1912c3ff0cdbSAnkit Nautiyal 	 * If user-space hasn't configured the driver to expose the modes
1913c3ff0cdbSAnkit Nautiyal 	 * with aspect-ratio, don't expose them. However if such a mode
1914c3ff0cdbSAnkit Nautiyal 	 * is unique, let it be exposed, but reset the aspect-ratio flags
1915c3ff0cdbSAnkit Nautiyal 	 * while preparing the list of user-modes.
1916c3ff0cdbSAnkit Nautiyal 	 */
1917c3ff0cdbSAnkit Nautiyal 	if (!file_priv->aspect_ratio_allowed) {
1918c3ff0cdbSAnkit Nautiyal 		struct drm_display_mode *mode_itr;
1919c3ff0cdbSAnkit Nautiyal 
1920c3ff0cdbSAnkit Nautiyal 		list_for_each_entry(mode_itr, export_list, export_head)
1921c3ff0cdbSAnkit Nautiyal 			if (drm_mode_match(mode_itr, mode,
1922c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_TIMINGS |
1923c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_CLOCK |
1924c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_FLAGS |
1925c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_3D_FLAGS))
1926c3ff0cdbSAnkit Nautiyal 				return false;
1927c3ff0cdbSAnkit Nautiyal 	}
192852217195SDaniel Vetter 
192952217195SDaniel Vetter 	return true;
193052217195SDaniel Vetter }
193152217195SDaniel Vetter 
193252217195SDaniel Vetter int drm_mode_getconnector(struct drm_device *dev, void *data,
193352217195SDaniel Vetter 			  struct drm_file *file_priv)
193452217195SDaniel Vetter {
193552217195SDaniel Vetter 	struct drm_mode_get_connector *out_resp = data;
193652217195SDaniel Vetter 	struct drm_connector *connector;
193752217195SDaniel Vetter 	struct drm_encoder *encoder;
193852217195SDaniel Vetter 	struct drm_display_mode *mode;
193952217195SDaniel Vetter 	int mode_count = 0;
194052217195SDaniel Vetter 	int encoders_count = 0;
194152217195SDaniel Vetter 	int ret = 0;
194252217195SDaniel Vetter 	int copied = 0;
194352217195SDaniel Vetter 	int i;
194452217195SDaniel Vetter 	struct drm_mode_modeinfo u_mode;
194552217195SDaniel Vetter 	struct drm_mode_modeinfo __user *mode_ptr;
194652217195SDaniel Vetter 	uint32_t __user *encoder_ptr;
1947c3ff0cdbSAnkit Nautiyal 	LIST_HEAD(export_list);
194852217195SDaniel Vetter 
194952217195SDaniel Vetter 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
195069fdf420SChris Wilson 		return -EOPNOTSUPP;
195152217195SDaniel Vetter 
195252217195SDaniel Vetter 	memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
195352217195SDaniel Vetter 
1954418da172SKeith Packard 	connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
195591eefc05SDaniel Vetter 	if (!connector)
195691eefc05SDaniel Vetter 		return -ENOENT;
195752217195SDaniel Vetter 
195883aefbb8SVille Syrjälä 	drm_connector_for_each_possible_encoder(connector, encoder, i)
195991eefc05SDaniel Vetter 		encoders_count++;
196091eefc05SDaniel Vetter 
196191eefc05SDaniel Vetter 	if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
196291eefc05SDaniel Vetter 		copied = 0;
196391eefc05SDaniel Vetter 		encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
196483aefbb8SVille Syrjälä 
196583aefbb8SVille Syrjälä 		drm_connector_for_each_possible_encoder(connector, encoder, i) {
196683aefbb8SVille Syrjälä 			if (put_user(encoder->base.id, encoder_ptr + copied)) {
196791eefc05SDaniel Vetter 				ret = -EFAULT;
1968e94ac351SDaniel Vetter 				goto out;
196991eefc05SDaniel Vetter 			}
197091eefc05SDaniel Vetter 			copied++;
197191eefc05SDaniel Vetter 		}
197291eefc05SDaniel Vetter 	}
197391eefc05SDaniel Vetter 	out_resp->count_encoders = encoders_count;
197491eefc05SDaniel Vetter 
197591eefc05SDaniel Vetter 	out_resp->connector_id = connector->base.id;
197691eefc05SDaniel Vetter 	out_resp->connector_type = connector->connector_type;
197791eefc05SDaniel Vetter 	out_resp->connector_type_id = connector->connector_type_id;
197891eefc05SDaniel Vetter 
197991eefc05SDaniel Vetter 	mutex_lock(&dev->mode_config.mutex);
198091eefc05SDaniel Vetter 	if (out_resp->count_modes == 0) {
198191eefc05SDaniel Vetter 		connector->funcs->fill_modes(connector,
198291eefc05SDaniel Vetter 					     dev->mode_config.max_width,
198391eefc05SDaniel Vetter 					     dev->mode_config.max_height);
198491eefc05SDaniel Vetter 	}
198591eefc05SDaniel Vetter 
198691eefc05SDaniel Vetter 	out_resp->mm_width = connector->display_info.width_mm;
198791eefc05SDaniel Vetter 	out_resp->mm_height = connector->display_info.height_mm;
198891eefc05SDaniel Vetter 	out_resp->subpixel = connector->display_info.subpixel_order;
198991eefc05SDaniel Vetter 	out_resp->connection = connector->status;
199091eefc05SDaniel Vetter 
199191eefc05SDaniel Vetter 	/* delayed so we get modes regardless of pre-fill_modes state */
199291eefc05SDaniel Vetter 	list_for_each_entry(mode, &connector->modes, head)
1993c3ff0cdbSAnkit Nautiyal 		if (drm_mode_expose_to_userspace(mode, &export_list,
1994c3ff0cdbSAnkit Nautiyal 						 file_priv)) {
1995c3ff0cdbSAnkit Nautiyal 			list_add_tail(&mode->export_head, &export_list);
199691eefc05SDaniel Vetter 			mode_count++;
1997c3ff0cdbSAnkit Nautiyal 		}
199891eefc05SDaniel Vetter 
199952217195SDaniel Vetter 	/*
200052217195SDaniel Vetter 	 * This ioctl is called twice, once to determine how much space is
200152217195SDaniel Vetter 	 * needed, and the 2nd time to fill it.
2002c3ff0cdbSAnkit Nautiyal 	 * The modes that need to be exposed to the user are maintained in the
2003c3ff0cdbSAnkit Nautiyal 	 * 'export_list'. When the ioctl is called first time to determine the,
2004c3ff0cdbSAnkit Nautiyal 	 * space, the export_list gets filled, to find the no.of modes. In the
2005c3ff0cdbSAnkit Nautiyal 	 * 2nd time, the user modes are filled, one by one from the export_list.
200652217195SDaniel Vetter 	 */
200752217195SDaniel Vetter 	if ((out_resp->count_modes >= mode_count) && mode_count) {
200852217195SDaniel Vetter 		copied = 0;
200952217195SDaniel Vetter 		mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
2010c3ff0cdbSAnkit Nautiyal 		list_for_each_entry(mode, &export_list, export_head) {
201152217195SDaniel Vetter 			drm_mode_convert_to_umode(&u_mode, mode);
2012c3ff0cdbSAnkit Nautiyal 			/*
2013c3ff0cdbSAnkit Nautiyal 			 * Reset aspect ratio flags of user-mode, if modes with
2014c3ff0cdbSAnkit Nautiyal 			 * aspect-ratio are not supported.
2015c3ff0cdbSAnkit Nautiyal 			 */
2016c3ff0cdbSAnkit Nautiyal 			if (!file_priv->aspect_ratio_allowed)
2017c3ff0cdbSAnkit Nautiyal 				u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
201852217195SDaniel Vetter 			if (copy_to_user(mode_ptr + copied,
201952217195SDaniel Vetter 					 &u_mode, sizeof(u_mode))) {
202052217195SDaniel Vetter 				ret = -EFAULT;
2021e94ac351SDaniel Vetter 				mutex_unlock(&dev->mode_config.mutex);
2022e94ac351SDaniel Vetter 
202352217195SDaniel Vetter 				goto out;
202452217195SDaniel Vetter 			}
202552217195SDaniel Vetter 			copied++;
202652217195SDaniel Vetter 		}
202752217195SDaniel Vetter 	}
202852217195SDaniel Vetter 	out_resp->count_modes = mode_count;
202952217195SDaniel Vetter 	mutex_unlock(&dev->mode_config.mutex);
2030e94ac351SDaniel Vetter 
2031e94ac351SDaniel Vetter 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2032e94ac351SDaniel Vetter 	encoder = drm_connector_get_encoder(connector);
2033e94ac351SDaniel Vetter 	if (encoder)
2034e94ac351SDaniel Vetter 		out_resp->encoder_id = encoder->base.id;
2035e94ac351SDaniel Vetter 	else
2036e94ac351SDaniel Vetter 		out_resp->encoder_id = 0;
2037e94ac351SDaniel Vetter 
2038e94ac351SDaniel Vetter 	/* Only grab properties after probing, to make sure EDID and other
2039e94ac351SDaniel Vetter 	 * properties reflect the latest status. */
2040e94ac351SDaniel Vetter 	ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
2041e94ac351SDaniel Vetter 			(uint32_t __user *)(unsigned long)(out_resp->props_ptr),
2042e94ac351SDaniel Vetter 			(uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
2043e94ac351SDaniel Vetter 			&out_resp->count_props);
2044e94ac351SDaniel Vetter 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
2045e94ac351SDaniel Vetter 
2046e94ac351SDaniel Vetter out:
2047ad093607SThierry Reding 	drm_connector_put(connector);
204852217195SDaniel Vetter 
204952217195SDaniel Vetter 	return ret;
205052217195SDaniel Vetter }
205152217195SDaniel Vetter 
20529498c19bSDaniel Vetter 
20539498c19bSDaniel Vetter /**
20549498c19bSDaniel Vetter  * DOC: Tile group
20559498c19bSDaniel Vetter  *
20569498c19bSDaniel Vetter  * Tile groups are used to represent tiled monitors with a unique integer
20579498c19bSDaniel Vetter  * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
20589498c19bSDaniel Vetter  * we store this in a tile group, so we have a common identifier for all tiles
20599498c19bSDaniel Vetter  * in a monitor group. The property is called "TILE". Drivers can manage tile
20609498c19bSDaniel Vetter  * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
20619498c19bSDaniel Vetter  * drm_mode_get_tile_group(). But this is only needed for internal panels where
20629498c19bSDaniel Vetter  * the tile group information is exposed through a non-standard way.
20639498c19bSDaniel Vetter  */
20649498c19bSDaniel Vetter 
20659498c19bSDaniel Vetter static void drm_tile_group_free(struct kref *kref)
20669498c19bSDaniel Vetter {
20679498c19bSDaniel Vetter 	struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
20689498c19bSDaniel Vetter 	struct drm_device *dev = tg->dev;
20699498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
20709498c19bSDaniel Vetter 	idr_remove(&dev->mode_config.tile_idr, tg->id);
20719498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
20729498c19bSDaniel Vetter 	kfree(tg);
20739498c19bSDaniel Vetter }
20749498c19bSDaniel Vetter 
20759498c19bSDaniel Vetter /**
20769498c19bSDaniel Vetter  * drm_mode_put_tile_group - drop a reference to a tile group.
20779498c19bSDaniel Vetter  * @dev: DRM device
20789498c19bSDaniel Vetter  * @tg: tile group to drop reference to.
20799498c19bSDaniel Vetter  *
20809498c19bSDaniel Vetter  * drop reference to tile group and free if 0.
20819498c19bSDaniel Vetter  */
20829498c19bSDaniel Vetter void drm_mode_put_tile_group(struct drm_device *dev,
20839498c19bSDaniel Vetter 			     struct drm_tile_group *tg)
20849498c19bSDaniel Vetter {
20859498c19bSDaniel Vetter 	kref_put(&tg->refcount, drm_tile_group_free);
20869498c19bSDaniel Vetter }
20879498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_put_tile_group);
20889498c19bSDaniel Vetter 
20899498c19bSDaniel Vetter /**
20909498c19bSDaniel Vetter  * drm_mode_get_tile_group - get a reference to an existing tile group
20919498c19bSDaniel Vetter  * @dev: DRM device
20929498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
20939498c19bSDaniel Vetter  *
20949498c19bSDaniel Vetter  * Use the unique bytes to get a reference to an existing tile group.
20959498c19bSDaniel Vetter  *
20969498c19bSDaniel Vetter  * RETURNS:
20979498c19bSDaniel Vetter  * tile group or NULL if not found.
20989498c19bSDaniel Vetter  */
20999498c19bSDaniel Vetter struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
21009498c19bSDaniel Vetter 					       char topology[8])
21019498c19bSDaniel Vetter {
21029498c19bSDaniel Vetter 	struct drm_tile_group *tg;
21039498c19bSDaniel Vetter 	int id;
21049498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
21059498c19bSDaniel Vetter 	idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
21069498c19bSDaniel Vetter 		if (!memcmp(tg->group_data, topology, 8)) {
21079498c19bSDaniel Vetter 			if (!kref_get_unless_zero(&tg->refcount))
21089498c19bSDaniel Vetter 				tg = NULL;
21099498c19bSDaniel Vetter 			mutex_unlock(&dev->mode_config.idr_mutex);
21109498c19bSDaniel Vetter 			return tg;
21119498c19bSDaniel Vetter 		}
21129498c19bSDaniel Vetter 	}
21139498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
21149498c19bSDaniel Vetter 	return NULL;
21159498c19bSDaniel Vetter }
21169498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_get_tile_group);
21179498c19bSDaniel Vetter 
21189498c19bSDaniel Vetter /**
21199498c19bSDaniel Vetter  * drm_mode_create_tile_group - create a tile group from a displayid description
21209498c19bSDaniel Vetter  * @dev: DRM device
21219498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
21229498c19bSDaniel Vetter  *
21239498c19bSDaniel Vetter  * Create a tile group for the unique monitor, and get a unique
21249498c19bSDaniel Vetter  * identifier for the tile group.
21259498c19bSDaniel Vetter  *
21269498c19bSDaniel Vetter  * RETURNS:
2127705c8160SDan Carpenter  * new tile group or NULL.
21289498c19bSDaniel Vetter  */
21299498c19bSDaniel Vetter struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
21309498c19bSDaniel Vetter 						  char topology[8])
21319498c19bSDaniel Vetter {
21329498c19bSDaniel Vetter 	struct drm_tile_group *tg;
21339498c19bSDaniel Vetter 	int ret;
21349498c19bSDaniel Vetter 
21359498c19bSDaniel Vetter 	tg = kzalloc(sizeof(*tg), GFP_KERNEL);
21369498c19bSDaniel Vetter 	if (!tg)
2137705c8160SDan Carpenter 		return NULL;
21389498c19bSDaniel Vetter 
21399498c19bSDaniel Vetter 	kref_init(&tg->refcount);
21409498c19bSDaniel Vetter 	memcpy(tg->group_data, topology, 8);
21419498c19bSDaniel Vetter 	tg->dev = dev;
21429498c19bSDaniel Vetter 
21439498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
21449498c19bSDaniel Vetter 	ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
21459498c19bSDaniel Vetter 	if (ret >= 0) {
21469498c19bSDaniel Vetter 		tg->id = ret;
21479498c19bSDaniel Vetter 	} else {
21489498c19bSDaniel Vetter 		kfree(tg);
2149705c8160SDan Carpenter 		tg = NULL;
21509498c19bSDaniel Vetter 	}
21519498c19bSDaniel Vetter 
21529498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
21539498c19bSDaniel Vetter 	return tg;
21549498c19bSDaniel Vetter }
21559498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tile_group);
2156