xref: /linux/drivers/gpu/drm/drm_connector.c (revision 948de84233d32be56e0b7ee5c1c4b2d960efee27)
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>
30968d81a6SJeykumar Sankaran #include <drm/drm_sysfs.h>
3199f45e32SDaniel Vetter 
3299f45e32SDaniel Vetter #include <linux/uaccess.h>
3352217195SDaniel Vetter 
3452217195SDaniel Vetter #include "drm_crtc_internal.h"
3552217195SDaniel Vetter #include "drm_internal.h"
3652217195SDaniel Vetter 
37ae2a6da8SDaniel Vetter /**
38ae2a6da8SDaniel Vetter  * DOC: overview
39ae2a6da8SDaniel Vetter  *
40ae2a6da8SDaniel Vetter  * In DRM connectors are the general abstraction for display sinks, and include
4184e543bcSAntonio Borneo  * also fixed panels or anything else that can display pixels in some form. As
42ae2a6da8SDaniel Vetter  * opposed to all other KMS objects representing hardware (like CRTC, encoder or
43ae2a6da8SDaniel Vetter  * plane abstractions) connectors can be hotplugged and unplugged at runtime.
44ad093607SThierry Reding  * Hence they are reference-counted using drm_connector_get() and
45ad093607SThierry Reding  * drm_connector_put().
46ae2a6da8SDaniel Vetter  *
47d574528aSDaniel Vetter  * KMS driver must create, initialize, register and attach at a &struct
48d574528aSDaniel Vetter  * drm_connector for each such sink. The instance is created as other KMS
49aec97460SDaniel Vetter  * objects and initialized by setting the following fields. The connector is
50aec97460SDaniel Vetter  * initialized with a call to drm_connector_init() with a pointer to the
51aec97460SDaniel Vetter  * &struct drm_connector_funcs and a connector type, and then exposed to
52aec97460SDaniel Vetter  * userspace with a call to drm_connector_register().
53ae2a6da8SDaniel Vetter  *
54ae2a6da8SDaniel Vetter  * Connectors must be attached to an encoder to be used. For devices that map
55ae2a6da8SDaniel Vetter  * connectors to encoders 1:1, the connector should be attached at
56cde4c44dSDaniel Vetter  * initialization time with a call to drm_connector_attach_encoder(). The
57d574528aSDaniel Vetter  * driver must also set the &drm_connector.encoder field to point to the
58ae2a6da8SDaniel Vetter  * attached encoder.
59ae2a6da8SDaniel Vetter  *
60ae2a6da8SDaniel Vetter  * For connectors which are not fixed (like built-in panels) the driver needs to
61ae2a6da8SDaniel Vetter  * support hotplug notifications. The simplest way to do that is by using the
62ae2a6da8SDaniel Vetter  * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
63ae2a6da8SDaniel Vetter  * hardware support for hotplug interrupts. Connectors with hardware hotplug
64ae2a6da8SDaniel Vetter  * support can instead use e.g. drm_helper_hpd_irq_event().
65ae2a6da8SDaniel Vetter  */
66ae2a6da8SDaniel Vetter 
6752217195SDaniel Vetter struct drm_conn_prop_enum_list {
6852217195SDaniel Vetter 	int type;
6952217195SDaniel Vetter 	const char *name;
7052217195SDaniel Vetter 	struct ida ida;
7152217195SDaniel Vetter };
7252217195SDaniel Vetter 
7352217195SDaniel Vetter /*
7452217195SDaniel Vetter  * Connector and encoder types.
7552217195SDaniel Vetter  */
7652217195SDaniel Vetter static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
7752217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Unknown, "Unknown" },
7852217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
7952217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
8052217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
8152217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
8252217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Composite, "Composite" },
8352217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
8452217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
8552217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Component, "Component" },
8652217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
8752217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },
8852217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
8952217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
9052217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_TV, "TV" },
9152217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_eDP, "eDP" },
9252217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
9352217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DSI, "DSI" },
9452217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DPI, "DPI" },
95935774cdSBrian Starkey 	{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
96fc06bf1dSNoralf Trønnes 	{ DRM_MODE_CONNECTOR_SPI, "SPI" },
9752217195SDaniel Vetter };
9852217195SDaniel Vetter 
9952217195SDaniel Vetter void drm_connector_ida_init(void)
10052217195SDaniel Vetter {
10152217195SDaniel Vetter 	int i;
10252217195SDaniel Vetter 
10352217195SDaniel Vetter 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
10452217195SDaniel Vetter 		ida_init(&drm_connector_enum_list[i].ida);
10552217195SDaniel Vetter }
10652217195SDaniel Vetter 
10752217195SDaniel Vetter void drm_connector_ida_destroy(void)
10852217195SDaniel Vetter {
10952217195SDaniel Vetter 	int i;
11052217195SDaniel Vetter 
11152217195SDaniel Vetter 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
11252217195SDaniel Vetter 		ida_destroy(&drm_connector_enum_list[i].ida);
11352217195SDaniel Vetter }
11452217195SDaniel Vetter 
11552217195SDaniel Vetter /**
116b35f90f2SLaurent Pinchart  * drm_get_connector_type_name - return a string for connector type
117b35f90f2SLaurent Pinchart  * @type: The connector type (DRM_MODE_CONNECTOR_*)
118b35f90f2SLaurent Pinchart  *
119b35f90f2SLaurent Pinchart  * Returns: the name of the connector type, or NULL if the type is not valid.
120b35f90f2SLaurent Pinchart  */
121b35f90f2SLaurent Pinchart const char *drm_get_connector_type_name(unsigned int type)
122b35f90f2SLaurent Pinchart {
123b35f90f2SLaurent Pinchart 	if (type < ARRAY_SIZE(drm_connector_enum_list))
124b35f90f2SLaurent Pinchart 		return drm_connector_enum_list[type].name;
125b35f90f2SLaurent Pinchart 
126b35f90f2SLaurent Pinchart 	return NULL;
127b35f90f2SLaurent Pinchart }
128b35f90f2SLaurent Pinchart EXPORT_SYMBOL(drm_get_connector_type_name);
129b35f90f2SLaurent Pinchart 
130b35f90f2SLaurent Pinchart /**
13152217195SDaniel Vetter  * drm_connector_get_cmdline_mode - reads the user's cmdline mode
13284e543bcSAntonio Borneo  * @connector: connector to query
13352217195SDaniel Vetter  *
134ae2a6da8SDaniel Vetter  * The kernel supports per-connector configuration of its consoles through
13552217195SDaniel Vetter  * use of the video= parameter. This function parses that option and
13652217195SDaniel Vetter  * extracts the user's specified mode (or enable/disable status) for a
13752217195SDaniel Vetter  * particular connector. This is typically only used during the early fbdev
13852217195SDaniel Vetter  * setup.
13952217195SDaniel Vetter  */
14052217195SDaniel Vetter static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
14152217195SDaniel Vetter {
14252217195SDaniel Vetter 	struct drm_cmdline_mode *mode = &connector->cmdline_mode;
14352217195SDaniel Vetter 	char *option = NULL;
14452217195SDaniel Vetter 
14552217195SDaniel Vetter 	if (fb_get_options(connector->name, &option))
14652217195SDaniel Vetter 		return;
14752217195SDaniel Vetter 
14852217195SDaniel Vetter 	if (!drm_mode_parse_command_line_for_connector(option,
14952217195SDaniel Vetter 						       connector,
15052217195SDaniel Vetter 						       mode))
15152217195SDaniel Vetter 		return;
15252217195SDaniel Vetter 
15352217195SDaniel Vetter 	if (mode->force) {
1546140cf20SJani Nikula 		DRM_INFO("forcing %s connector %s\n", connector->name,
1556140cf20SJani Nikula 			 drm_get_connector_force_name(mode->force));
15652217195SDaniel Vetter 		connector->force = mode->force;
15752217195SDaniel Vetter 	}
15852217195SDaniel Vetter 
1590980939dSHans de Goede 	if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) {
1600980939dSHans de Goede 		DRM_INFO("cmdline forces connector %s panel_orientation to %d\n",
1610980939dSHans de Goede 			 connector->name, mode->panel_orientation);
1620980939dSHans de Goede 		drm_connector_set_panel_orientation(connector,
1630980939dSHans de Goede 						    mode->panel_orientation);
1640980939dSHans de Goede 	}
1650980939dSHans de Goede 
1663aeeb13dSMaxime Ripard 	DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
16750b0946dSMaxime Ripard 		      connector->name, mode->name,
16852217195SDaniel Vetter 		      mode->xres, mode->yres,
16952217195SDaniel Vetter 		      mode->refresh_specified ? mode->refresh : 60,
17052217195SDaniel Vetter 		      mode->rb ? " reduced blanking" : "",
17152217195SDaniel Vetter 		      mode->margins ? " with margins" : "",
17252217195SDaniel Vetter 		      mode->interlace ?  " interlaced" : "");
17352217195SDaniel Vetter }
17452217195SDaniel Vetter 
17552217195SDaniel Vetter static void drm_connector_free(struct kref *kref)
17652217195SDaniel Vetter {
17752217195SDaniel Vetter 	struct drm_connector *connector =
17852217195SDaniel Vetter 		container_of(kref, struct drm_connector, base.refcount);
17952217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
18052217195SDaniel Vetter 
18152217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
18252217195SDaniel Vetter 	connector->funcs->destroy(connector);
18352217195SDaniel Vetter }
18452217195SDaniel Vetter 
185ea497bb9SDaniel Vetter void drm_connector_free_work_fn(struct work_struct *work)
186a703c550SDaniel Vetter {
187ea497bb9SDaniel Vetter 	struct drm_connector *connector, *n;
188ea497bb9SDaniel Vetter 	struct drm_device *dev =
189ea497bb9SDaniel Vetter 		container_of(work, struct drm_device, mode_config.connector_free_work);
190ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &dev->mode_config;
191ea497bb9SDaniel Vetter 	unsigned long flags;
192ea497bb9SDaniel Vetter 	struct llist_node *freed;
193a703c550SDaniel Vetter 
194ea497bb9SDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
195ea497bb9SDaniel Vetter 	freed = llist_del_all(&config->connector_free_list);
196ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
197ea497bb9SDaniel Vetter 
198ea497bb9SDaniel Vetter 	llist_for_each_entry_safe(connector, n, freed, free_node) {
199a703c550SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
200a703c550SDaniel Vetter 		connector->funcs->destroy(connector);
201a703c550SDaniel Vetter 	}
202ea497bb9SDaniel Vetter }
203a703c550SDaniel Vetter 
20452217195SDaniel Vetter /**
20552217195SDaniel Vetter  * drm_connector_init - Init a preallocated connector
20652217195SDaniel Vetter  * @dev: DRM device
20752217195SDaniel Vetter  * @connector: the connector to init
20852217195SDaniel Vetter  * @funcs: callbacks for this connector
20952217195SDaniel Vetter  * @connector_type: user visible type of the connector
21052217195SDaniel Vetter  *
21152217195SDaniel Vetter  * Initialises a preallocated connector. Connectors should be
21252217195SDaniel Vetter  * subclassed as part of driver connector objects.
21352217195SDaniel Vetter  *
21452217195SDaniel Vetter  * Returns:
21552217195SDaniel Vetter  * Zero on success, error code on failure.
21652217195SDaniel Vetter  */
21752217195SDaniel Vetter int drm_connector_init(struct drm_device *dev,
21852217195SDaniel Vetter 		       struct drm_connector *connector,
21952217195SDaniel Vetter 		       const struct drm_connector_funcs *funcs,
22052217195SDaniel Vetter 		       int connector_type)
22152217195SDaniel Vetter {
22252217195SDaniel Vetter 	struct drm_mode_config *config = &dev->mode_config;
22352217195SDaniel Vetter 	int ret;
22452217195SDaniel Vetter 	struct ida *connector_ida =
22552217195SDaniel Vetter 		&drm_connector_enum_list[connector_type].ida;
22652217195SDaniel Vetter 
227ba1f665fSHaneen Mohammed 	WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
228ba1f665fSHaneen Mohammed 		(!funcs->atomic_destroy_state ||
229ba1f665fSHaneen Mohammed 		 !funcs->atomic_duplicate_state));
230ba1f665fSHaneen Mohammed 
2312135ea7aSThierry Reding 	ret = __drm_mode_object_add(dev, &connector->base,
23252217195SDaniel Vetter 				    DRM_MODE_OBJECT_CONNECTOR,
23352217195SDaniel Vetter 				    false, drm_connector_free);
23452217195SDaniel Vetter 	if (ret)
235613051daSDaniel Vetter 		return ret;
23652217195SDaniel Vetter 
23752217195SDaniel Vetter 	connector->base.properties = &connector->properties;
23852217195SDaniel Vetter 	connector->dev = dev;
23952217195SDaniel Vetter 	connector->funcs = funcs;
24052217195SDaniel Vetter 
2412a8d3eacSVille Syrjälä 	/* connector index is used with 32bit bitmasks */
2422a8d3eacSVille Syrjälä 	ret = ida_simple_get(&config->connector_ida, 0, 32, GFP_KERNEL);
2432a8d3eacSVille Syrjälä 	if (ret < 0) {
2442a8d3eacSVille Syrjälä 		DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
2452a8d3eacSVille Syrjälä 			      drm_connector_enum_list[connector_type].name,
2462a8d3eacSVille Syrjälä 			      ret);
24752217195SDaniel Vetter 		goto out_put;
2482a8d3eacSVille Syrjälä 	}
24952217195SDaniel Vetter 	connector->index = ret;
25052217195SDaniel Vetter 	ret = 0;
25152217195SDaniel Vetter 
25252217195SDaniel Vetter 	connector->connector_type = connector_type;
25352217195SDaniel Vetter 	connector->connector_type_id =
25452217195SDaniel Vetter 		ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
25552217195SDaniel Vetter 	if (connector->connector_type_id < 0) {
25652217195SDaniel Vetter 		ret = connector->connector_type_id;
25752217195SDaniel Vetter 		goto out_put_id;
25852217195SDaniel Vetter 	}
25952217195SDaniel Vetter 	connector->name =
26052217195SDaniel Vetter 		kasprintf(GFP_KERNEL, "%s-%d",
26152217195SDaniel Vetter 			  drm_connector_enum_list[connector_type].name,
26252217195SDaniel Vetter 			  connector->connector_type_id);
26352217195SDaniel Vetter 	if (!connector->name) {
26452217195SDaniel Vetter 		ret = -ENOMEM;
26552217195SDaniel Vetter 		goto out_put_type_id;
26652217195SDaniel Vetter 	}
26752217195SDaniel Vetter 
26852217195SDaniel Vetter 	INIT_LIST_HEAD(&connector->probed_modes);
26952217195SDaniel Vetter 	INIT_LIST_HEAD(&connector->modes);
270e73ab00eSDaniel Vetter 	mutex_init(&connector->mutex);
27152217195SDaniel Vetter 	connector->edid_blob_ptr = NULL;
2725186421cSStanislav Lisovskiy 	connector->epoch_counter = 0;
2732de3a078SManasi Navare 	connector->tile_blob_ptr = NULL;
27452217195SDaniel Vetter 	connector->status = connector_status_unknown;
2758d70f395SHans de Goede 	connector->display_info.panel_orientation =
2768d70f395SHans de Goede 		DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
27752217195SDaniel Vetter 
27852217195SDaniel Vetter 	drm_connector_get_cmdline_mode(connector);
27952217195SDaniel Vetter 
28052217195SDaniel Vetter 	/* We should add connectors at the end to avoid upsetting the connector
28152217195SDaniel Vetter 	 * index too much. */
282613051daSDaniel Vetter 	spin_lock_irq(&config->connector_list_lock);
28352217195SDaniel Vetter 	list_add_tail(&connector->head, &config->connector_list);
28452217195SDaniel Vetter 	config->num_connector++;
285613051daSDaniel Vetter 	spin_unlock_irq(&config->connector_list_lock);
28652217195SDaniel Vetter 
287935774cdSBrian Starkey 	if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
288935774cdSBrian Starkey 	    connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
2896b7e2d5cSGerd Hoffmann 		drm_connector_attach_edid_property(connector);
29052217195SDaniel Vetter 
29152217195SDaniel Vetter 	drm_object_attach_property(&connector->base,
29252217195SDaniel Vetter 				      config->dpms_property, 0);
29352217195SDaniel Vetter 
29440ee6fbeSManasi Navare 	drm_object_attach_property(&connector->base,
29540ee6fbeSManasi Navare 				   config->link_status_property,
29640ee6fbeSManasi Navare 				   0);
29740ee6fbeSManasi Navare 
29866660d4cSDave Airlie 	drm_object_attach_property(&connector->base,
29966660d4cSDave Airlie 				   config->non_desktop_property,
30066660d4cSDave Airlie 				   0);
3012de3a078SManasi Navare 	drm_object_attach_property(&connector->base,
3022de3a078SManasi Navare 				   config->tile_property,
3032de3a078SManasi Navare 				   0);
30466660d4cSDave Airlie 
30552217195SDaniel Vetter 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
30652217195SDaniel Vetter 		drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
30752217195SDaniel Vetter 	}
30852217195SDaniel Vetter 
30952217195SDaniel Vetter 	connector->debugfs_entry = NULL;
31052217195SDaniel Vetter out_put_type_id:
31152217195SDaniel Vetter 	if (ret)
312587680c1SChristophe JAILLET 		ida_simple_remove(connector_ida, connector->connector_type_id);
31352217195SDaniel Vetter out_put_id:
31452217195SDaniel Vetter 	if (ret)
315587680c1SChristophe JAILLET 		ida_simple_remove(&config->connector_ida, connector->index);
31652217195SDaniel Vetter out_put:
31752217195SDaniel Vetter 	if (ret)
31852217195SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
31952217195SDaniel Vetter 
32052217195SDaniel Vetter 	return ret;
32152217195SDaniel Vetter }
32252217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_init);
32352217195SDaniel Vetter 
32452217195SDaniel Vetter /**
325100163dfSAndrzej Pietrasiewicz  * drm_connector_init_with_ddc - Init a preallocated connector
326100163dfSAndrzej Pietrasiewicz  * @dev: DRM device
327100163dfSAndrzej Pietrasiewicz  * @connector: the connector to init
328100163dfSAndrzej Pietrasiewicz  * @funcs: callbacks for this connector
329100163dfSAndrzej Pietrasiewicz  * @connector_type: user visible type of the connector
330100163dfSAndrzej Pietrasiewicz  * @ddc: pointer to the associated ddc adapter
331100163dfSAndrzej Pietrasiewicz  *
332100163dfSAndrzej Pietrasiewicz  * Initialises a preallocated connector. Connectors should be
333100163dfSAndrzej Pietrasiewicz  * subclassed as part of driver connector objects.
334100163dfSAndrzej Pietrasiewicz  *
335100163dfSAndrzej Pietrasiewicz  * Ensures that the ddc field of the connector is correctly set.
336100163dfSAndrzej Pietrasiewicz  *
337100163dfSAndrzej Pietrasiewicz  * Returns:
338100163dfSAndrzej Pietrasiewicz  * Zero on success, error code on failure.
339100163dfSAndrzej Pietrasiewicz  */
340100163dfSAndrzej Pietrasiewicz int drm_connector_init_with_ddc(struct drm_device *dev,
341100163dfSAndrzej Pietrasiewicz 				struct drm_connector *connector,
342100163dfSAndrzej Pietrasiewicz 				const struct drm_connector_funcs *funcs,
343100163dfSAndrzej Pietrasiewicz 				int connector_type,
344100163dfSAndrzej Pietrasiewicz 				struct i2c_adapter *ddc)
345100163dfSAndrzej Pietrasiewicz {
346100163dfSAndrzej Pietrasiewicz 	int ret;
347100163dfSAndrzej Pietrasiewicz 
348100163dfSAndrzej Pietrasiewicz 	ret = drm_connector_init(dev, connector, funcs, connector_type);
349100163dfSAndrzej Pietrasiewicz 	if (ret)
350100163dfSAndrzej Pietrasiewicz 		return ret;
351100163dfSAndrzej Pietrasiewicz 
352100163dfSAndrzej Pietrasiewicz 	/* provide ddc symlink in sysfs */
353100163dfSAndrzej Pietrasiewicz 	connector->ddc = ddc;
354100163dfSAndrzej Pietrasiewicz 
355100163dfSAndrzej Pietrasiewicz 	return ret;
356100163dfSAndrzej Pietrasiewicz }
357100163dfSAndrzej Pietrasiewicz EXPORT_SYMBOL(drm_connector_init_with_ddc);
358100163dfSAndrzej Pietrasiewicz 
359100163dfSAndrzej Pietrasiewicz /**
3606b7e2d5cSGerd Hoffmann  * drm_connector_attach_edid_property - attach edid property.
3616b7e2d5cSGerd Hoffmann  * @connector: the connector
3626b7e2d5cSGerd Hoffmann  *
3636b7e2d5cSGerd Hoffmann  * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
3646b7e2d5cSGerd Hoffmann  * edid property attached by default.  This function can be used to
3656b7e2d5cSGerd Hoffmann  * explicitly enable the edid property in these cases.
3666b7e2d5cSGerd Hoffmann  */
3676b7e2d5cSGerd Hoffmann void drm_connector_attach_edid_property(struct drm_connector *connector)
3686b7e2d5cSGerd Hoffmann {
3696b7e2d5cSGerd Hoffmann 	struct drm_mode_config *config = &connector->dev->mode_config;
3706b7e2d5cSGerd Hoffmann 
3716b7e2d5cSGerd Hoffmann 	drm_object_attach_property(&connector->base,
3726b7e2d5cSGerd Hoffmann 				   config->edid_property,
3736b7e2d5cSGerd Hoffmann 				   0);
3746b7e2d5cSGerd Hoffmann }
3756b7e2d5cSGerd Hoffmann EXPORT_SYMBOL(drm_connector_attach_edid_property);
3766b7e2d5cSGerd Hoffmann 
3776b7e2d5cSGerd Hoffmann /**
378cde4c44dSDaniel Vetter  * drm_connector_attach_encoder - attach a connector to an encoder
37952217195SDaniel Vetter  * @connector: connector to attach
38052217195SDaniel Vetter  * @encoder: encoder to attach @connector to
38152217195SDaniel Vetter  *
38252217195SDaniel Vetter  * This function links up a connector to an encoder. Note that the routing
38352217195SDaniel Vetter  * restrictions between encoders and crtcs are exposed to userspace through the
38452217195SDaniel Vetter  * possible_clones and possible_crtcs bitmasks.
38552217195SDaniel Vetter  *
38652217195SDaniel Vetter  * Returns:
38752217195SDaniel Vetter  * Zero on success, negative errno on failure.
38852217195SDaniel Vetter  */
389cde4c44dSDaniel Vetter int drm_connector_attach_encoder(struct drm_connector *connector,
39052217195SDaniel Vetter 				 struct drm_encoder *encoder)
39152217195SDaniel Vetter {
39252217195SDaniel Vetter 	/*
39352217195SDaniel Vetter 	 * In the past, drivers have attempted to model the static association
39452217195SDaniel Vetter 	 * of connector to encoder in simple connector/encoder devices using a
39552217195SDaniel Vetter 	 * direct assignment of connector->encoder = encoder. This connection
39652217195SDaniel Vetter 	 * is a logical one and the responsibility of the core, so drivers are
39752217195SDaniel Vetter 	 * expected not to mess with this.
39852217195SDaniel Vetter 	 *
39952217195SDaniel Vetter 	 * Note that the error return should've been enough here, but a large
40052217195SDaniel Vetter 	 * majority of drivers ignores the return value, so add in a big WARN
40152217195SDaniel Vetter 	 * to get people's attention.
40252217195SDaniel Vetter 	 */
40352217195SDaniel Vetter 	if (WARN_ON(connector->encoder))
40452217195SDaniel Vetter 		return -EINVAL;
40552217195SDaniel Vetter 
40662afb4adSJosé Roberto de Souza 	connector->possible_encoders |= drm_encoder_mask(encoder);
40762afb4adSJosé Roberto de Souza 
40852217195SDaniel Vetter 	return 0;
40952217195SDaniel Vetter }
410cde4c44dSDaniel Vetter EXPORT_SYMBOL(drm_connector_attach_encoder);
41152217195SDaniel Vetter 
41238cb8d96SVille Syrjälä /**
41362afb4adSJosé Roberto de Souza  * drm_connector_has_possible_encoder - check if the connector and encoder are
41462afb4adSJosé Roberto de Souza  * associated with each other
41538cb8d96SVille Syrjälä  * @connector: the connector
41638cb8d96SVille Syrjälä  * @encoder: the encoder
41738cb8d96SVille Syrjälä  *
41838cb8d96SVille Syrjälä  * Returns:
41938cb8d96SVille Syrjälä  * True if @encoder is one of the possible encoders for @connector.
42038cb8d96SVille Syrjälä  */
42138cb8d96SVille Syrjälä bool drm_connector_has_possible_encoder(struct drm_connector *connector,
42238cb8d96SVille Syrjälä 					struct drm_encoder *encoder)
42338cb8d96SVille Syrjälä {
42462afb4adSJosé Roberto de Souza 	return connector->possible_encoders & drm_encoder_mask(encoder);
42538cb8d96SVille Syrjälä }
42638cb8d96SVille Syrjälä EXPORT_SYMBOL(drm_connector_has_possible_encoder);
42738cb8d96SVille Syrjälä 
42852217195SDaniel Vetter static void drm_mode_remove(struct drm_connector *connector,
42952217195SDaniel Vetter 			    struct drm_display_mode *mode)
43052217195SDaniel Vetter {
43152217195SDaniel Vetter 	list_del(&mode->head);
43252217195SDaniel Vetter 	drm_mode_destroy(connector->dev, mode);
43352217195SDaniel Vetter }
43452217195SDaniel Vetter 
43552217195SDaniel Vetter /**
43652217195SDaniel Vetter  * drm_connector_cleanup - cleans up an initialised connector
43752217195SDaniel Vetter  * @connector: connector to cleanup
43852217195SDaniel Vetter  *
43952217195SDaniel Vetter  * Cleans up the connector but doesn't free the object.
44052217195SDaniel Vetter  */
44152217195SDaniel Vetter void drm_connector_cleanup(struct drm_connector *connector)
44252217195SDaniel Vetter {
44352217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
44452217195SDaniel Vetter 	struct drm_display_mode *mode, *t;
44552217195SDaniel Vetter 
44652217195SDaniel Vetter 	/* The connector should have been removed from userspace long before
44752217195SDaniel Vetter 	 * it is finally destroyed.
44852217195SDaniel Vetter 	 */
44939b50c60SLyude Paul 	if (WARN_ON(connector->registration_state ==
45039b50c60SLyude Paul 		    DRM_CONNECTOR_REGISTERED))
45152217195SDaniel Vetter 		drm_connector_unregister(connector);
45252217195SDaniel Vetter 
45352217195SDaniel Vetter 	if (connector->tile_group) {
45452217195SDaniel Vetter 		drm_mode_put_tile_group(dev, connector->tile_group);
45552217195SDaniel Vetter 		connector->tile_group = NULL;
45652217195SDaniel Vetter 	}
45752217195SDaniel Vetter 
45852217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
45952217195SDaniel Vetter 		drm_mode_remove(connector, mode);
46052217195SDaniel Vetter 
46152217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->modes, head)
46252217195SDaniel Vetter 		drm_mode_remove(connector, mode);
46352217195SDaniel Vetter 
4649a47dba1SChristophe JAILLET 	ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida,
46552217195SDaniel Vetter 			  connector->connector_type_id);
46652217195SDaniel Vetter 
4679a47dba1SChristophe JAILLET 	ida_simple_remove(&dev->mode_config.connector_ida,
46852217195SDaniel Vetter 			  connector->index);
46952217195SDaniel Vetter 
47052217195SDaniel Vetter 	kfree(connector->display_info.bus_formats);
47152217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
47252217195SDaniel Vetter 	kfree(connector->name);
47352217195SDaniel Vetter 	connector->name = NULL;
474613051daSDaniel Vetter 	spin_lock_irq(&dev->mode_config.connector_list_lock);
47552217195SDaniel Vetter 	list_del(&connector->head);
47652217195SDaniel Vetter 	dev->mode_config.num_connector--;
477613051daSDaniel Vetter 	spin_unlock_irq(&dev->mode_config.connector_list_lock);
47852217195SDaniel Vetter 
47952217195SDaniel Vetter 	WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
48052217195SDaniel Vetter 	if (connector->state && connector->funcs->atomic_destroy_state)
48152217195SDaniel Vetter 		connector->funcs->atomic_destroy_state(connector,
48252217195SDaniel Vetter 						       connector->state);
48352217195SDaniel Vetter 
484e73ab00eSDaniel Vetter 	mutex_destroy(&connector->mutex);
485e73ab00eSDaniel Vetter 
48652217195SDaniel Vetter 	memset(connector, 0, sizeof(*connector));
48752217195SDaniel Vetter }
48852217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_cleanup);
48952217195SDaniel Vetter 
49052217195SDaniel Vetter /**
49152217195SDaniel Vetter  * drm_connector_register - register a connector
49252217195SDaniel Vetter  * @connector: the connector to register
49352217195SDaniel Vetter  *
49469b22f51SDaniel Vetter  * Register userspace interfaces for a connector. Only call this for connectors
49569b22f51SDaniel Vetter  * which can be hotplugged after drm_dev_register() has been called already,
49669b22f51SDaniel Vetter  * e.g. DP MST connectors. All other connectors will be registered automatically
49769b22f51SDaniel Vetter  * when calling drm_dev_register().
49852217195SDaniel Vetter  *
49952217195SDaniel Vetter  * Returns:
50052217195SDaniel Vetter  * Zero on success, error code on failure.
50152217195SDaniel Vetter  */
50252217195SDaniel Vetter int drm_connector_register(struct drm_connector *connector)
50352217195SDaniel Vetter {
504e73ab00eSDaniel Vetter 	int ret = 0;
50552217195SDaniel Vetter 
506e6e7b48bSDaniel Vetter 	if (!connector->dev->registered)
507e6e7b48bSDaniel Vetter 		return 0;
508e6e7b48bSDaniel Vetter 
509e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
51039b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
511e73ab00eSDaniel Vetter 		goto unlock;
51252217195SDaniel Vetter 
51352217195SDaniel Vetter 	ret = drm_sysfs_connector_add(connector);
51452217195SDaniel Vetter 	if (ret)
515e73ab00eSDaniel Vetter 		goto unlock;
51652217195SDaniel Vetter 
517b792e640SGreg Kroah-Hartman 	drm_debugfs_connector_add(connector);
51852217195SDaniel Vetter 
51952217195SDaniel Vetter 	if (connector->funcs->late_register) {
52052217195SDaniel Vetter 		ret = connector->funcs->late_register(connector);
52152217195SDaniel Vetter 		if (ret)
52252217195SDaniel Vetter 			goto err_debugfs;
52352217195SDaniel Vetter 	}
52452217195SDaniel Vetter 
52552217195SDaniel Vetter 	drm_mode_object_register(connector->dev, &connector->base);
52652217195SDaniel Vetter 
52739b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_REGISTERED;
528968d81a6SJeykumar Sankaran 
529968d81a6SJeykumar Sankaran 	/* Let userspace know we have a new connector */
530968d81a6SJeykumar Sankaran 	drm_sysfs_hotplug_event(connector->dev);
531968d81a6SJeykumar Sankaran 
532e73ab00eSDaniel Vetter 	goto unlock;
53352217195SDaniel Vetter 
53452217195SDaniel Vetter err_debugfs:
53552217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
53652217195SDaniel Vetter 	drm_sysfs_connector_remove(connector);
537e73ab00eSDaniel Vetter unlock:
538e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
53952217195SDaniel Vetter 	return ret;
54052217195SDaniel Vetter }
54152217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_register);
54252217195SDaniel Vetter 
54352217195SDaniel Vetter /**
54452217195SDaniel Vetter  * drm_connector_unregister - unregister a connector
54552217195SDaniel Vetter  * @connector: the connector to unregister
54652217195SDaniel Vetter  *
54769b22f51SDaniel Vetter  * Unregister userspace interfaces for a connector. Only call this for
54869b22f51SDaniel Vetter  * connectors which have registered explicitly by calling drm_dev_register(),
54969b22f51SDaniel Vetter  * since connectors are unregistered automatically when drm_dev_unregister() is
55069b22f51SDaniel Vetter  * called.
55152217195SDaniel Vetter  */
55252217195SDaniel Vetter void drm_connector_unregister(struct drm_connector *connector)
55352217195SDaniel Vetter {
554e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
55539b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
556e73ab00eSDaniel Vetter 		mutex_unlock(&connector->mutex);
55752217195SDaniel Vetter 		return;
558e73ab00eSDaniel Vetter 	}
55952217195SDaniel Vetter 
56052217195SDaniel Vetter 	if (connector->funcs->early_unregister)
56152217195SDaniel Vetter 		connector->funcs->early_unregister(connector);
56252217195SDaniel Vetter 
56352217195SDaniel Vetter 	drm_sysfs_connector_remove(connector);
56452217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
56552217195SDaniel Vetter 
56639b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
567e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
56852217195SDaniel Vetter }
56952217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_unregister);
57052217195SDaniel Vetter 
57152217195SDaniel Vetter void drm_connector_unregister_all(struct drm_device *dev)
57252217195SDaniel Vetter {
57352217195SDaniel Vetter 	struct drm_connector *connector;
574613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
57552217195SDaniel Vetter 
576b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
577613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter)
57852217195SDaniel Vetter 		drm_connector_unregister(connector);
579b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
58052217195SDaniel Vetter }
58152217195SDaniel Vetter 
58252217195SDaniel Vetter int drm_connector_register_all(struct drm_device *dev)
58352217195SDaniel Vetter {
58452217195SDaniel Vetter 	struct drm_connector *connector;
585613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
586613051daSDaniel Vetter 	int ret = 0;
58752217195SDaniel Vetter 
588b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
589613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter) {
59052217195SDaniel Vetter 		ret = drm_connector_register(connector);
59152217195SDaniel Vetter 		if (ret)
592613051daSDaniel Vetter 			break;
59352217195SDaniel Vetter 	}
594b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
59552217195SDaniel Vetter 
596613051daSDaniel Vetter 	if (ret)
59752217195SDaniel Vetter 		drm_connector_unregister_all(dev);
59852217195SDaniel Vetter 	return ret;
59952217195SDaniel Vetter }
60052217195SDaniel Vetter 
60152217195SDaniel Vetter /**
60252217195SDaniel Vetter  * drm_get_connector_status_name - return a string for connector status
60352217195SDaniel Vetter  * @status: connector status to compute name of
60452217195SDaniel Vetter  *
60552217195SDaniel Vetter  * In contrast to the other drm_get_*_name functions this one here returns a
60652217195SDaniel Vetter  * const pointer and hence is threadsafe.
60752217195SDaniel Vetter  */
60852217195SDaniel Vetter const char *drm_get_connector_status_name(enum drm_connector_status status)
60952217195SDaniel Vetter {
61052217195SDaniel Vetter 	if (status == connector_status_connected)
61152217195SDaniel Vetter 		return "connected";
61252217195SDaniel Vetter 	else if (status == connector_status_disconnected)
61352217195SDaniel Vetter 		return "disconnected";
61452217195SDaniel Vetter 	else
61552217195SDaniel Vetter 		return "unknown";
61652217195SDaniel Vetter }
61752217195SDaniel Vetter EXPORT_SYMBOL(drm_get_connector_status_name);
61852217195SDaniel Vetter 
6196140cf20SJani Nikula /**
6206140cf20SJani Nikula  * drm_get_connector_force_name - return a string for connector force
6216140cf20SJani Nikula  * @force: connector force to get name of
6226140cf20SJani Nikula  *
6236140cf20SJani Nikula  * Returns: const pointer to name.
6246140cf20SJani Nikula  */
6256140cf20SJani Nikula const char *drm_get_connector_force_name(enum drm_connector_force force)
6266140cf20SJani Nikula {
6276140cf20SJani Nikula 	switch (force) {
6286140cf20SJani Nikula 	case DRM_FORCE_UNSPECIFIED:
6296140cf20SJani Nikula 		return "unspecified";
6306140cf20SJani Nikula 	case DRM_FORCE_OFF:
6316140cf20SJani Nikula 		return "off";
6326140cf20SJani Nikula 	case DRM_FORCE_ON:
6336140cf20SJani Nikula 		return "on";
6346140cf20SJani Nikula 	case DRM_FORCE_ON_DIGITAL:
6356140cf20SJani Nikula 		return "digital";
6366140cf20SJani Nikula 	default:
6376140cf20SJani Nikula 		return "unknown";
6386140cf20SJani Nikula 	}
6396140cf20SJani Nikula }
6406140cf20SJani Nikula 
641613051daSDaniel Vetter #ifdef CONFIG_LOCKDEP
642613051daSDaniel Vetter static struct lockdep_map connector_list_iter_dep_map = {
643613051daSDaniel Vetter 	.name = "drm_connector_list_iter"
644613051daSDaniel Vetter };
645613051daSDaniel Vetter #endif
646613051daSDaniel Vetter 
647613051daSDaniel Vetter /**
648b982dab1SThierry Reding  * drm_connector_list_iter_begin - initialize a connector_list iterator
649613051daSDaniel Vetter  * @dev: DRM device
650613051daSDaniel Vetter  * @iter: connector_list iterator
651613051daSDaniel Vetter  *
652d574528aSDaniel Vetter  * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
653b982dab1SThierry Reding  * must always be cleaned up again by calling drm_connector_list_iter_end().
654613051daSDaniel Vetter  * Iteration itself happens using drm_connector_list_iter_next() or
655613051daSDaniel Vetter  * drm_for_each_connector_iter().
656613051daSDaniel Vetter  */
657b982dab1SThierry Reding void drm_connector_list_iter_begin(struct drm_device *dev,
658613051daSDaniel Vetter 				   struct drm_connector_list_iter *iter)
659613051daSDaniel Vetter {
660613051daSDaniel Vetter 	iter->dev = dev;
661613051daSDaniel Vetter 	iter->conn = NULL;
662613051daSDaniel Vetter 	lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
663613051daSDaniel Vetter }
664b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_begin);
665613051daSDaniel Vetter 
666a703c550SDaniel Vetter /*
667a703c550SDaniel Vetter  * Extra-safe connector put function that works in any context. Should only be
668a703c550SDaniel Vetter  * used from the connector_iter functions, where we never really expect to
669a703c550SDaniel Vetter  * actually release the connector when dropping our final reference.
670a703c550SDaniel Vetter  */
671a703c550SDaniel Vetter static void
672ea497bb9SDaniel Vetter __drm_connector_put_safe(struct drm_connector *conn)
673a703c550SDaniel Vetter {
674ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &conn->dev->mode_config;
675ea497bb9SDaniel Vetter 
676ea497bb9SDaniel Vetter 	lockdep_assert_held(&config->connector_list_lock);
677ea497bb9SDaniel Vetter 
678ea497bb9SDaniel Vetter 	if (!refcount_dec_and_test(&conn->base.refcount.refcount))
679ea497bb9SDaniel Vetter 		return;
680ea497bb9SDaniel Vetter 
681ea497bb9SDaniel Vetter 	llist_add(&conn->free_node, &config->connector_free_list);
682ea497bb9SDaniel Vetter 	schedule_work(&config->connector_free_work);
683a703c550SDaniel Vetter }
684a703c550SDaniel Vetter 
685613051daSDaniel Vetter /**
686613051daSDaniel Vetter  * drm_connector_list_iter_next - return next connector
6874f45c778SLyude Paul  * @iter: connector_list iterator
688613051daSDaniel Vetter  *
689613051daSDaniel Vetter  * Returns the next connector for @iter, or NULL when the list walk has
690613051daSDaniel Vetter  * completed.
691613051daSDaniel Vetter  */
692613051daSDaniel Vetter struct drm_connector *
693613051daSDaniel Vetter drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
694613051daSDaniel Vetter {
695613051daSDaniel Vetter 	struct drm_connector *old_conn = iter->conn;
696613051daSDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
697613051daSDaniel Vetter 	struct list_head *lhead;
698613051daSDaniel Vetter 	unsigned long flags;
699613051daSDaniel Vetter 
700613051daSDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
701613051daSDaniel Vetter 	lhead = old_conn ? &old_conn->head : &config->connector_list;
702613051daSDaniel Vetter 
703613051daSDaniel Vetter 	do {
704613051daSDaniel Vetter 		if (lhead->next == &config->connector_list) {
705613051daSDaniel Vetter 			iter->conn = NULL;
706613051daSDaniel Vetter 			break;
707613051daSDaniel Vetter 		}
708613051daSDaniel Vetter 
709613051daSDaniel Vetter 		lhead = lhead->next;
710613051daSDaniel Vetter 		iter->conn = list_entry(lhead, struct drm_connector, head);
711613051daSDaniel Vetter 
712613051daSDaniel Vetter 		/* loop until it's not a zombie connector */
713613051daSDaniel Vetter 	} while (!kref_get_unless_zero(&iter->conn->base.refcount));
714613051daSDaniel Vetter 
715613051daSDaniel Vetter 	if (old_conn)
716ea497bb9SDaniel Vetter 		__drm_connector_put_safe(old_conn);
717ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
718613051daSDaniel Vetter 
719613051daSDaniel Vetter 	return iter->conn;
720613051daSDaniel Vetter }
721613051daSDaniel Vetter EXPORT_SYMBOL(drm_connector_list_iter_next);
722613051daSDaniel Vetter 
723613051daSDaniel Vetter /**
724b982dab1SThierry Reding  * drm_connector_list_iter_end - tear down a connector_list iterator
725613051daSDaniel Vetter  * @iter: connector_list iterator
726613051daSDaniel Vetter  *
727613051daSDaniel Vetter  * Tears down @iter and releases any resources (like &drm_connector references)
728613051daSDaniel Vetter  * acquired while walking the list. This must always be called, both when the
729613051daSDaniel Vetter  * iteration completes fully or when it was aborted without walking the entire
730613051daSDaniel Vetter  * list.
731613051daSDaniel Vetter  */
732b982dab1SThierry Reding void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
733613051daSDaniel Vetter {
734ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
735ea497bb9SDaniel Vetter 	unsigned long flags;
736ea497bb9SDaniel Vetter 
737613051daSDaniel Vetter 	iter->dev = NULL;
738ea497bb9SDaniel Vetter 	if (iter->conn) {
739ea497bb9SDaniel Vetter 		spin_lock_irqsave(&config->connector_list_lock, flags);
740ea497bb9SDaniel Vetter 		__drm_connector_put_safe(iter->conn);
741ea497bb9SDaniel Vetter 		spin_unlock_irqrestore(&config->connector_list_lock, flags);
742ea497bb9SDaniel Vetter 	}
7435facae4fSQian Cai 	lock_release(&connector_list_iter_dep_map, _RET_IP_);
744613051daSDaniel Vetter }
745b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_end);
746613051daSDaniel Vetter 
74752217195SDaniel Vetter static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
74852217195SDaniel Vetter 	{ SubPixelUnknown, "Unknown" },
74952217195SDaniel Vetter 	{ SubPixelHorizontalRGB, "Horizontal RGB" },
75052217195SDaniel Vetter 	{ SubPixelHorizontalBGR, "Horizontal BGR" },
75152217195SDaniel Vetter 	{ SubPixelVerticalRGB, "Vertical RGB" },
75252217195SDaniel Vetter 	{ SubPixelVerticalBGR, "Vertical BGR" },
75352217195SDaniel Vetter 	{ SubPixelNone, "None" },
75452217195SDaniel Vetter };
75552217195SDaniel Vetter 
75652217195SDaniel Vetter /**
75752217195SDaniel Vetter  * drm_get_subpixel_order_name - return a string for a given subpixel enum
75852217195SDaniel Vetter  * @order: enum of subpixel_order
75952217195SDaniel Vetter  *
76052217195SDaniel Vetter  * Note you could abuse this and return something out of bounds, but that
76152217195SDaniel Vetter  * would be a caller error.  No unscrubbed user data should make it here.
76252217195SDaniel Vetter  */
76352217195SDaniel Vetter const char *drm_get_subpixel_order_name(enum subpixel_order order)
76452217195SDaniel Vetter {
76552217195SDaniel Vetter 	return drm_subpixel_enum_list[order].name;
76652217195SDaniel Vetter }
76752217195SDaniel Vetter EXPORT_SYMBOL(drm_get_subpixel_order_name);
76852217195SDaniel Vetter 
76952217195SDaniel Vetter static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
77052217195SDaniel Vetter 	{ DRM_MODE_DPMS_ON, "On" },
77152217195SDaniel Vetter 	{ DRM_MODE_DPMS_STANDBY, "Standby" },
77252217195SDaniel Vetter 	{ DRM_MODE_DPMS_SUSPEND, "Suspend" },
77352217195SDaniel Vetter 	{ DRM_MODE_DPMS_OFF, "Off" }
77452217195SDaniel Vetter };
77552217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
77652217195SDaniel Vetter 
77740ee6fbeSManasi Navare static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
77840ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_GOOD, "Good" },
77940ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_BAD, "Bad" },
78040ee6fbeSManasi Navare };
78140ee6fbeSManasi Navare 
782b3c6c8bfSDaniel Vetter /**
783b3c6c8bfSDaniel Vetter  * drm_display_info_set_bus_formats - set the supported bus formats
784b3c6c8bfSDaniel Vetter  * @info: display info to store bus formats in
785b3c6c8bfSDaniel Vetter  * @formats: array containing the supported bus formats
786b3c6c8bfSDaniel Vetter  * @num_formats: the number of entries in the fmts array
787b3c6c8bfSDaniel Vetter  *
788b3c6c8bfSDaniel Vetter  * Store the supported bus formats in display info structure.
789b3c6c8bfSDaniel Vetter  * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
790b3c6c8bfSDaniel Vetter  * a full list of available formats.
791b3c6c8bfSDaniel Vetter  */
792b3c6c8bfSDaniel Vetter int drm_display_info_set_bus_formats(struct drm_display_info *info,
793b3c6c8bfSDaniel Vetter 				     const u32 *formats,
794b3c6c8bfSDaniel Vetter 				     unsigned int num_formats)
795b3c6c8bfSDaniel Vetter {
796b3c6c8bfSDaniel Vetter 	u32 *fmts = NULL;
797b3c6c8bfSDaniel Vetter 
798b3c6c8bfSDaniel Vetter 	if (!formats && num_formats)
799b3c6c8bfSDaniel Vetter 		return -EINVAL;
800b3c6c8bfSDaniel Vetter 
801b3c6c8bfSDaniel Vetter 	if (formats && num_formats) {
802b3c6c8bfSDaniel Vetter 		fmts = kmemdup(formats, sizeof(*formats) * num_formats,
803b3c6c8bfSDaniel Vetter 			       GFP_KERNEL);
804b3c6c8bfSDaniel Vetter 		if (!fmts)
805b3c6c8bfSDaniel Vetter 			return -ENOMEM;
806b3c6c8bfSDaniel Vetter 	}
807b3c6c8bfSDaniel Vetter 
808b3c6c8bfSDaniel Vetter 	kfree(info->bus_formats);
809b3c6c8bfSDaniel Vetter 	info->bus_formats = fmts;
810b3c6c8bfSDaniel Vetter 	info->num_bus_formats = num_formats;
811b3c6c8bfSDaniel Vetter 
812b3c6c8bfSDaniel Vetter 	return 0;
813b3c6c8bfSDaniel Vetter }
814b3c6c8bfSDaniel Vetter EXPORT_SYMBOL(drm_display_info_set_bus_formats);
815b3c6c8bfSDaniel Vetter 
81652217195SDaniel Vetter /* Optional connector properties. */
81752217195SDaniel Vetter static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
81852217195SDaniel Vetter 	{ DRM_MODE_SCALE_NONE, "None" },
81952217195SDaniel Vetter 	{ DRM_MODE_SCALE_FULLSCREEN, "Full" },
82052217195SDaniel Vetter 	{ DRM_MODE_SCALE_CENTER, "Center" },
82152217195SDaniel Vetter 	{ DRM_MODE_SCALE_ASPECT, "Full aspect" },
82252217195SDaniel Vetter };
82352217195SDaniel Vetter 
82452217195SDaniel Vetter static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
82552217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
82652217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
82752217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
82852217195SDaniel Vetter };
82952217195SDaniel Vetter 
83050525c33SStanislav Lisovskiy static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
83150525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
83250525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
83350525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
83450525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
83550525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GAME, "Game" },
83650525c33SStanislav Lisovskiy };
83750525c33SStanislav Lisovskiy 
8388d70f395SHans de Goede static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
8398d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_NORMAL,	"Normal"	},
8408d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP,	"Upside Down"	},
8418d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_LEFT_UP,	"Left Side Up"	},
8428d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,	"Right Side Up"	},
8438d70f395SHans de Goede };
8448d70f395SHans de Goede 
84552217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
84652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
84752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
84852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
84952217195SDaniel Vetter };
85052217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
85152217195SDaniel Vetter 
85252217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
85352217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I and TV-out */
85452217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
85552217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
85652217195SDaniel Vetter };
85752217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
85852217195SDaniel Vetter 		 drm_dvi_i_subconnector_enum_list)
85952217195SDaniel Vetter 
86052217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
86152217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
86252217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
86352217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
86452217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
86552217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
86652217195SDaniel Vetter };
86752217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
86852217195SDaniel Vetter 
86952217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
87052217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I and TV-out */
87152217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
87252217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
87352217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
87452217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
87552217195SDaniel Vetter };
87652217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
87752217195SDaniel Vetter 		 drm_tv_subconnector_enum_list)
87852217195SDaniel Vetter 
879d2c6a405SUma Shankar static const struct drm_prop_enum_list hdmi_colorspaces[] = {
880d2c6a405SUma Shankar 	/* For Default case, driver will set the colorspace */
881d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
882d2c6a405SUma Shankar 	/* Standard Definition Colorimetry based on CEA 861 */
883d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_SMPTE_170M_YCC, "SMPTE_170M_YCC" },
884d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
885d2c6a405SUma Shankar 	/* Standard Definition Colorimetry based on IEC 61966-2-4 */
886d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
887d2c6a405SUma Shankar 	/* High Definition Colorimetry based on IEC 61966-2-4 */
888d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
889d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-1/Amendment 1 */
890d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
891d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-5 [33] */
892d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
893d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-5 */
894d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
895d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
896d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
897d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
898d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
899d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
900d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
901d2c6a405SUma Shankar 	/* Added as part of Additional Colorimetry Extension in 861.G */
902d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
903d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, "DCI-P3_RGB_Theater" },
904d2c6a405SUma Shankar };
905d2c6a405SUma Shankar 
90645cf0e91SGwan-gyeong Mun /*
90745cf0e91SGwan-gyeong Mun  * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
90845cf0e91SGwan-gyeong Mun  * Format Table 2-120
90945cf0e91SGwan-gyeong Mun  */
91045cf0e91SGwan-gyeong Mun static const struct drm_prop_enum_list dp_colorspaces[] = {
91145cf0e91SGwan-gyeong Mun 	/* For Default case, driver will set the colorspace */
91245cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
91345cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED, "RGB_Wide_Gamut_Fixed_Point" },
91445cf0e91SGwan-gyeong Mun 	/* Colorimetry based on scRGB (IEC 61966-2-2) */
91545cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT, "RGB_Wide_Gamut_Floating_Point" },
91645cf0e91SGwan-gyeong Mun 	/* Colorimetry based on IEC 61966-2-5 */
91745cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
91845cf0e91SGwan-gyeong Mun 	/* Colorimetry based on SMPTE RP 431-2 */
91945cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
92045cf0e91SGwan-gyeong Mun 	/* Colorimetry based on ITU-R BT.2020 */
92145cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
92245cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT601_YCC, "BT601_YCC" },
92345cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
92445cf0e91SGwan-gyeong Mun 	/* Standard Definition Colorimetry based on IEC 61966-2-4 */
92545cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
92645cf0e91SGwan-gyeong Mun 	/* High Definition Colorimetry based on IEC 61966-2-4 */
92745cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
92845cf0e91SGwan-gyeong Mun 	/* Colorimetry based on IEC 61966-2-1/Amendment 1 */
92945cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
93045cf0e91SGwan-gyeong Mun 	/* Colorimetry based on IEC 61966-2-5 [33] */
93145cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
93245cf0e91SGwan-gyeong Mun 	/* Colorimetry based on ITU-R BT.2020 */
93345cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
93445cf0e91SGwan-gyeong Mun 	/* Colorimetry based on ITU-R BT.2020 */
93545cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
93645cf0e91SGwan-gyeong Mun };
93745cf0e91SGwan-gyeong Mun 
9384ada6f22SDaniel Vetter /**
9394ada6f22SDaniel Vetter  * DOC: standard connector properties
9404ada6f22SDaniel Vetter  *
9414ada6f22SDaniel Vetter  * DRM connectors have a few standardized properties:
9424ada6f22SDaniel Vetter  *
9434ada6f22SDaniel Vetter  * EDID:
9444ada6f22SDaniel Vetter  * 	Blob property which contains the current EDID read from the sink. This
9454ada6f22SDaniel Vetter  * 	is useful to parse sink identification information like vendor, model
9464ada6f22SDaniel Vetter  * 	and serial. Drivers should update this property by calling
947c555f023SDaniel Vetter  * 	drm_connector_update_edid_property(), usually after having parsed
9484ada6f22SDaniel Vetter  * 	the EDID using drm_add_edid_modes(). Userspace cannot change this
9494ada6f22SDaniel Vetter  * 	property.
9504ada6f22SDaniel Vetter  * DPMS:
9514ada6f22SDaniel Vetter  * 	Legacy property for setting the power state of the connector. For atomic
9524ada6f22SDaniel Vetter  * 	drivers this is only provided for backwards compatibility with existing
9534ada6f22SDaniel Vetter  * 	drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
9544ada6f22SDaniel Vetter  * 	connector is linked to. Drivers should never set this property directly,
955d574528aSDaniel Vetter  * 	it is handled by the DRM core by calling the &drm_connector_funcs.dpms
956144a7999SDaniel Vetter  * 	callback. For atomic drivers the remapping to the "ACTIVE" property is
9571e3e4caeSSimon Ser  * 	implemented in the DRM core.
958d0d1aee5SDaniel Vetter  *
959d0d1aee5SDaniel Vetter  * 	Note that this property cannot be set through the MODE_ATOMIC ioctl,
960d0d1aee5SDaniel Vetter  * 	userspace must use "ACTIVE" on the CRTC instead.
961d0d1aee5SDaniel Vetter  *
962d0d1aee5SDaniel Vetter  * 	WARNING:
963d0d1aee5SDaniel Vetter  *
964d0d1aee5SDaniel Vetter  * 	For userspace also running on legacy drivers the "DPMS" semantics are a
965d0d1aee5SDaniel Vetter  * 	lot more complicated. First, userspace cannot rely on the "DPMS" value
966d0d1aee5SDaniel Vetter  * 	returned by the GETCONNECTOR actually reflecting reality, because many
967d0d1aee5SDaniel Vetter  * 	drivers fail to update it. For atomic drivers this is taken care of in
968d0d1aee5SDaniel Vetter  * 	drm_atomic_helper_update_legacy_modeset_state().
969d0d1aee5SDaniel Vetter  *
970d0d1aee5SDaniel Vetter  * 	The second issue is that the DPMS state is only well-defined when the
971d0d1aee5SDaniel Vetter  * 	connector is connected to a CRTC. In atomic the DRM core enforces that
972d0d1aee5SDaniel Vetter  * 	"ACTIVE" is off in such a case, no such checks exists for "DPMS".
973d0d1aee5SDaniel Vetter  *
974d0d1aee5SDaniel Vetter  * 	Finally, when enabling an output using the legacy SETCONFIG ioctl then
975d0d1aee5SDaniel Vetter  * 	"DPMS" is forced to ON. But see above, that might not be reflected in
976d0d1aee5SDaniel Vetter  * 	the software value on legacy drivers.
977d0d1aee5SDaniel Vetter  *
978d0d1aee5SDaniel Vetter  * 	Summarizing: Only set "DPMS" when the connector is known to be enabled,
979d0d1aee5SDaniel Vetter  * 	assume that a successful SETCONFIG call also sets "DPMS" to on, and
980d0d1aee5SDaniel Vetter  * 	never read back the value of "DPMS" because it can be incorrect.
9814ada6f22SDaniel Vetter  * PATH:
9824ada6f22SDaniel Vetter  * 	Connector path property to identify how this sink is physically
9834ada6f22SDaniel Vetter  * 	connected. Used by DP MST. This should be set by calling
98497e14fbeSDaniel Vetter  * 	drm_connector_set_path_property(), in the case of DP MST with the
9854ada6f22SDaniel Vetter  * 	path property the MST manager created. Userspace cannot change this
9864ada6f22SDaniel Vetter  * 	property.
9874ada6f22SDaniel Vetter  * TILE:
9884ada6f22SDaniel Vetter  * 	Connector tile group property to indicate how a set of DRM connector
9894ada6f22SDaniel Vetter  * 	compose together into one logical screen. This is used by both high-res
9904ada6f22SDaniel Vetter  * 	external screens (often only using a single cable, but exposing multiple
9914ada6f22SDaniel Vetter  * 	DP MST sinks), or high-res integrated panels (like dual-link DSI) which
9924ada6f22SDaniel Vetter  * 	are not gen-locked. Note that for tiled panels which are genlocked, like
9934ada6f22SDaniel Vetter  * 	dual-link LVDS or dual-link DSI, the driver should try to not expose the
99484e543bcSAntonio Borneo  * 	tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers
99597e14fbeSDaniel Vetter  * 	should update this value using drm_connector_set_tile_property().
9964ada6f22SDaniel Vetter  * 	Userspace cannot change this property.
99740ee6fbeSManasi Navare  * link-status:
998716719a3SSean Paul  *      Connector link-status property to indicate the status of link. The
999716719a3SSean Paul  *      default value of link-status is "GOOD". If something fails during or
1000716719a3SSean Paul  *      after modeset, the kernel driver may set this to "BAD" and issue a
1001716719a3SSean Paul  *      hotplug uevent. Drivers should update this value using
100297e14fbeSDaniel Vetter  *      drm_connector_set_link_status_property().
1003a66da873SSimon Ser  *
1004a66da873SSimon Ser  *      When user-space receives the hotplug uevent and detects a "BAD"
1005a66da873SSimon Ser  *      link-status, the sink doesn't receive pixels anymore (e.g. the screen
1006a66da873SSimon Ser  *      becomes completely black). The list of available modes may have
1007a66da873SSimon Ser  *      changed. User-space is expected to pick a new mode if the current one
1008a66da873SSimon Ser  *      has disappeared and perform a new modeset with link-status set to
1009a66da873SSimon Ser  *      "GOOD" to re-enable the connector.
1010a66da873SSimon Ser  *
1011a66da873SSimon Ser  *      If multiple connectors share the same CRTC and one of them gets a "BAD"
1012a66da873SSimon Ser  *      link-status, the other are unaffected (ie. the sinks still continue to
1013a66da873SSimon Ser  *      receive pixels).
1014a66da873SSimon Ser  *
1015a66da873SSimon Ser  *      When user-space performs an atomic commit on a connector with a "BAD"
1016a66da873SSimon Ser  *      link-status without resetting the property to "GOOD", the sink may
1017a66da873SSimon Ser  *      still not receive pixels. When user-space performs an atomic commit
1018a66da873SSimon Ser  *      which resets the link-status property to "GOOD" without the
1019a66da873SSimon Ser  *      ALLOW_MODESET flag set, it might fail because a modeset is required.
1020a66da873SSimon Ser  *
1021a66da873SSimon Ser  *      User-space can only change link-status to "GOOD", changing it to "BAD"
1022a66da873SSimon Ser  *      is a no-op.
1023a66da873SSimon Ser  *
1024a66da873SSimon Ser  *      For backwards compatibility with non-atomic userspace the kernel
1025a66da873SSimon Ser  *      tries to automatically set the link-status back to "GOOD" in the
1026a66da873SSimon Ser  *      SETCRTC IOCTL. This might fail if the mode is no longer valid, similar
1027a66da873SSimon Ser  *      to how it might fail if a different screen has been connected in the
1028a66da873SSimon Ser  *      interim.
102966660d4cSDave Airlie  * non_desktop:
103066660d4cSDave Airlie  * 	Indicates the output should be ignored for purposes of displaying a
103166660d4cSDave Airlie  * 	standard desktop environment or console. This is most likely because
103266660d4cSDave Airlie  * 	the output device is not rectilinear.
103324557865SSean Paul  * Content Protection:
103424557865SSean Paul  *	This property is used by userspace to request the kernel protect future
103524557865SSean Paul  *	content communicated over the link. When requested, kernel will apply
103624557865SSean Paul  *	the appropriate means of protection (most often HDCP), and use the
103724557865SSean Paul  *	property to tell userspace the protection is active.
103824557865SSean Paul  *
103924557865SSean Paul  *	Drivers can set this up by calling
104024557865SSean Paul  *	drm_connector_attach_content_protection_property() on initialization.
104124557865SSean Paul  *
104224557865SSean Paul  *	The value of this property can be one of the following:
104324557865SSean Paul  *
1044bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
104524557865SSean Paul  *		The link is not protected, content is transmitted in the clear.
1046bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
104724557865SSean Paul  *		Userspace has requested content protection, but the link is not
104824557865SSean Paul  *		currently protected. When in this state, kernel should enable
104924557865SSean Paul  *		Content Protection as soon as possible.
1050bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
105124557865SSean Paul  *		Userspace has requested content protection, and the link is
105224557865SSean Paul  *		protected. Only the driver can set the property to this value.
105324557865SSean Paul  *		If userspace attempts to set to ENABLED, kernel will return
105424557865SSean Paul  *		-EINVAL.
105524557865SSean Paul  *
105624557865SSean Paul  *	A few guidelines:
105724557865SSean Paul  *
105824557865SSean Paul  *	- DESIRED state should be preserved until userspace de-asserts it by
105924557865SSean Paul  *	  setting the property to UNDESIRED. This means ENABLED should only
106024557865SSean Paul  *	  transition to UNDESIRED when the user explicitly requests it.
106124557865SSean Paul  *	- If the state is DESIRED, kernel should attempt to re-authenticate the
106224557865SSean Paul  *	  link whenever possible. This includes across disable/enable, dpms,
106324557865SSean Paul  *	  hotplug, downstream device changes, link status failures, etc..
1064bb5a45d4SRamalingam C  *	- Kernel sends uevent with the connector id and property id through
1065bb5a45d4SRamalingam C  *	  @drm_hdcp_update_content_protection, upon below kernel triggered
1066bb5a45d4SRamalingam C  *	  scenarios:
106712db36bcSSean Paul  *
106812db36bcSSean Paul  *		- DESIRED -> ENABLED (authentication success)
106912db36bcSSean Paul  *		- ENABLED -> DESIRED (termination of authentication)
1070bb5a45d4SRamalingam C  *	- Please note no uevents for userspace triggered property state changes,
1071bb5a45d4SRamalingam C  *	  which can't fail such as
107212db36bcSSean Paul  *
107312db36bcSSean Paul  *		- DESIRED/ENABLED -> UNDESIRED
107412db36bcSSean Paul  *		- UNDESIRED -> DESIRED
1075bb5a45d4SRamalingam C  *	- Userspace is responsible for polling the property or listen to uevents
1076bb5a45d4SRamalingam C  *	  to determine when the value transitions from ENABLED to DESIRED.
1077bb5a45d4SRamalingam C  *	  This signifies the link is no longer protected and userspace should
1078bb5a45d4SRamalingam C  *	  take appropriate action (whatever that might be).
10794ada6f22SDaniel Vetter  *
10807672dbbaSRamalingam C  * HDCP Content Type:
10817672dbbaSRamalingam C  *	This Enum property is used by the userspace to declare the content type
10827672dbbaSRamalingam C  *	of the display stream, to kernel. Here display stream stands for any
10837672dbbaSRamalingam C  *	display content that userspace intended to display through HDCP
10847672dbbaSRamalingam C  *	encryption.
10857672dbbaSRamalingam C  *
10867672dbbaSRamalingam C  *	Content Type of a stream is decided by the owner of the stream, as
10877672dbbaSRamalingam C  *	"HDCP Type0" or "HDCP Type1".
10887672dbbaSRamalingam C  *
10897672dbbaSRamalingam C  *	The value of the property can be one of the below:
10907672dbbaSRamalingam C  *	  - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0
10917672dbbaSRamalingam C  *	  - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1
10927672dbbaSRamalingam C  *
10937672dbbaSRamalingam C  *	When kernel starts the HDCP authentication (see "Content Protection"
10947672dbbaSRamalingam C  *	for details), it uses the content type in "HDCP Content Type"
10957672dbbaSRamalingam C  *	for performing the HDCP authentication with the display sink.
10967672dbbaSRamalingam C  *
10977672dbbaSRamalingam C  *	Please note in HDCP spec versions, a link can be authenticated with
10987672dbbaSRamalingam C  *	HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be
10997672dbbaSRamalingam C  *	authenticated with HDCP1.4 only for Content Type 0(though it is implicit
11007672dbbaSRamalingam C  *	in nature. As there is no reference for Content Type in HDCP1.4).
11017672dbbaSRamalingam C  *
11027672dbbaSRamalingam C  *	HDCP2.2 authentication protocol itself takes the "Content Type" as a
11037672dbbaSRamalingam C  *	parameter, which is a input for the DP HDCP2.2 encryption algo.
11047672dbbaSRamalingam C  *
11057672dbbaSRamalingam C  *	In case of Type 0 content protection request, kernel driver can choose
11067672dbbaSRamalingam C  *	either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for
11077672dbbaSRamalingam C  *	"HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send
11087672dbbaSRamalingam C  *	that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).
11097672dbbaSRamalingam C  *	But if the content is classified as "HDCP Type 1", above mentioned
11107672dbbaSRamalingam C  *	HDCP 2.2 repeater wont send the content to the HDCP sink as it can't
11117672dbbaSRamalingam C  *	authenticate the HDCP1.4 capable sink for "HDCP Type 1".
11127672dbbaSRamalingam C  *
11137672dbbaSRamalingam C  *	Please note userspace can be ignorant of the HDCP versions used by the
11147672dbbaSRamalingam C  *	kernel driver to achieve the "HDCP Content Type".
11157672dbbaSRamalingam C  *
11167672dbbaSRamalingam C  *	At current scenario, classifying a content as Type 1 ensures that the
11177672dbbaSRamalingam C  *	content will be displayed only through the HDCP2.2 encrypted link.
11187672dbbaSRamalingam C  *
11197672dbbaSRamalingam C  *	Note that the HDCP Content Type property is introduced at HDCP 2.2, and
11207672dbbaSRamalingam C  *	defaults to type 0. It is only exposed by drivers supporting HDCP 2.2
11217672dbbaSRamalingam C  *	(hence supporting Type 0 and Type 1). Based on how next versions of
11227672dbbaSRamalingam C  *	HDCP specs are defined content Type could be used for higher versions
11237672dbbaSRamalingam C  *	too.
11247672dbbaSRamalingam C  *
11257672dbbaSRamalingam C  *	If content type is changed when "Content Protection" is not UNDESIRED,
11267672dbbaSRamalingam C  *	then kernel will disable the HDCP and re-enable with new type in the
11277672dbbaSRamalingam C  *	same atomic commit. And when "Content Protection" is ENABLED, it means
11287672dbbaSRamalingam C  *	that link is HDCP authenticated and encrypted, for the transmission of
11297672dbbaSRamalingam C  *	the Type of stream mentioned at "HDCP Content Type".
11307672dbbaSRamalingam C  *
1131a09db883SUma Shankar  * HDR_OUTPUT_METADATA:
1132a09db883SUma Shankar  *	Connector property to enable userspace to send HDR Metadata to
1133a09db883SUma Shankar  *	driver. This metadata is based on the composition and blending
1134a09db883SUma Shankar  *	policies decided by user, taking into account the hardware and
1135a09db883SUma Shankar  *	sink capabilities. The driver gets this metadata and creates a
1136a09db883SUma Shankar  *	Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,
1137a09db883SUma Shankar  *	SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then
1138a09db883SUma Shankar  *	sent to sink. This notifies the sink of the upcoming frame's Color
1139a09db883SUma Shankar  *	Encoding and Luminance parameters.
1140a09db883SUma Shankar  *
1141a09db883SUma Shankar  *	Userspace first need to detect the HDR capabilities of sink by
1142a09db883SUma Shankar  *	reading and parsing the EDID. Details of HDR metadata for HDMI
1143a09db883SUma Shankar  *	are added in CTA 861.G spec. For DP , its defined in VESA DP
1144a09db883SUma Shankar  *	Standard v1.4. It needs to then get the metadata information
1145a09db883SUma Shankar  *	of the video/game/app content which are encoded in HDR (basically
1146a09db883SUma Shankar  *	using HDR transfer functions). With this information it needs to
1147a09db883SUma Shankar  *	decide on a blending policy and compose the relevant
1148a09db883SUma Shankar  *	layers/overlays into a common format. Once this blending is done,
1149a09db883SUma Shankar  *	userspace will be aware of the metadata of the composed frame to
1150a09db883SUma Shankar  *	be send to sink. It then uses this property to communicate this
1151a09db883SUma Shankar  *	metadata to driver which then make a Infoframe packet and sends
1152a09db883SUma Shankar  *	to sink based on the type of encoder connected.
1153a09db883SUma Shankar  *
1154a09db883SUma Shankar  *	Userspace will be responsible to do Tone mapping operation in case:
1155a09db883SUma Shankar  *		- Some layers are HDR and others are SDR
1156a09db883SUma Shankar  *		- HDR layers luminance is not same as sink
11579f9b2559SSean Paul  *
1158a09db883SUma Shankar  *	It will even need to do colorspace conversion and get all layers
1159a09db883SUma Shankar  *	to one common colorspace for blending. It can use either GL, Media
116084e543bcSAntonio Borneo  *	or display engine to get this done based on the capabilities of the
1161a09db883SUma Shankar  *	associated hardware.
1162a09db883SUma Shankar  *
1163a09db883SUma Shankar  *	Driver expects metadata to be put in &struct hdr_output_metadata
1164a09db883SUma Shankar  *	structure from userspace. This is received as blob and stored in
1165a09db883SUma Shankar  *	&drm_connector_state.hdr_output_metadata. It parses EDID and saves the
1166a09db883SUma Shankar  *	sink metadata in &struct hdr_sink_metadata, as
1167a09db883SUma Shankar  *	&drm_connector.hdr_sink_metadata.  Driver uses
1168a09db883SUma Shankar  *	drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,
1169a09db883SUma Shankar  *	hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of
1170a09db883SUma Shankar  *	HDMI encoder.
1171a09db883SUma Shankar  *
117247e22ff1SRadhakrishna Sripada  * max bpc:
117347e22ff1SRadhakrishna Sripada  *	This range property is used by userspace to limit the bit depth. When
117447e22ff1SRadhakrishna Sripada  *	used the driver would limit the bpc in accordance with the valid range
117547e22ff1SRadhakrishna Sripada  *	supported by the hardware and sink. Drivers to use the function
117647e22ff1SRadhakrishna Sripada  *	drm_connector_attach_max_bpc_property() to create and attach the
117747e22ff1SRadhakrishna Sripada  *	property to the connector during initialization.
117847e22ff1SRadhakrishna Sripada  *
11794ada6f22SDaniel Vetter  * Connectors also have one standardized atomic property:
11804ada6f22SDaniel Vetter  *
11814ada6f22SDaniel Vetter  * CRTC_ID:
11824ada6f22SDaniel Vetter  * 	Mode object ID of the &drm_crtc this connector should be connected to.
11838d70f395SHans de Goede  *
11848d70f395SHans de Goede  * Connectors for LCD panels may also have one standardized property:
11858d70f395SHans de Goede  *
11868d70f395SHans de Goede  * panel orientation:
11878d70f395SHans de Goede  *	On some devices the LCD panel is mounted in the casing in such a way
11888d70f395SHans de Goede  *	that the up/top side of the panel does not match with the top side of
11898d70f395SHans de Goede  *	the device. Userspace can use this property to check for this.
11908d70f395SHans de Goede  *	Note that input coordinates from touchscreens (input devices with
11918d70f395SHans de Goede  *	INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
11928d70f395SHans de Goede  *	coordinates, so if userspace rotates the picture to adjust for
11938d70f395SHans de Goede  *	the orientation it must also apply the same transformation to the
1194bbeba09fSDaniel Vetter  *	touchscreen input coordinates. This property is initialized by calling
119569654c63SDerek Basehore  *	drm_connector_set_panel_orientation() or
119669654c63SDerek Basehore  *	drm_connector_set_panel_orientation_with_quirk()
1197bbeba09fSDaniel Vetter  *
1198bbeba09fSDaniel Vetter  * scaling mode:
1199bbeba09fSDaniel Vetter  *	This property defines how a non-native mode is upscaled to the native
1200bbeba09fSDaniel Vetter  *	mode of an LCD panel:
1201bbeba09fSDaniel Vetter  *
1202bbeba09fSDaniel Vetter  *	None:
1203bbeba09fSDaniel Vetter  *		No upscaling happens, scaling is left to the panel. Not all
1204bbeba09fSDaniel Vetter  *		drivers expose this mode.
1205bbeba09fSDaniel Vetter  *	Full:
1206bbeba09fSDaniel Vetter  *		The output is upscaled to the full resolution of the panel,
1207bbeba09fSDaniel Vetter  *		ignoring the aspect ratio.
1208bbeba09fSDaniel Vetter  *	Center:
1209bbeba09fSDaniel Vetter  *		No upscaling happens, the output is centered within the native
1210bbeba09fSDaniel Vetter  *		resolution the panel.
1211bbeba09fSDaniel Vetter  *	Full aspect:
1212bbeba09fSDaniel Vetter  *		The output is upscaled to maximize either the width or height
1213bbeba09fSDaniel Vetter  *		while retaining the aspect ratio.
1214bbeba09fSDaniel Vetter  *
1215bbeba09fSDaniel Vetter  *	This property should be set up by calling
1216bbeba09fSDaniel Vetter  *	drm_connector_attach_scaling_mode_property(). Note that drivers
1217bbeba09fSDaniel Vetter  *	can also expose this property to external outputs, in which case they
1218bbeba09fSDaniel Vetter  *	must support "None", which should be the default (since external screens
1219bbeba09fSDaniel Vetter  *	have a built-in scaler).
12204ada6f22SDaniel Vetter  */
12214ada6f22SDaniel Vetter 
122252217195SDaniel Vetter int drm_connector_create_standard_properties(struct drm_device *dev)
122352217195SDaniel Vetter {
122452217195SDaniel Vetter 	struct drm_property *prop;
122552217195SDaniel Vetter 
122652217195SDaniel Vetter 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
122752217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
122852217195SDaniel Vetter 				   "EDID", 0);
122952217195SDaniel Vetter 	if (!prop)
123052217195SDaniel Vetter 		return -ENOMEM;
123152217195SDaniel Vetter 	dev->mode_config.edid_property = prop;
123252217195SDaniel Vetter 
123352217195SDaniel Vetter 	prop = drm_property_create_enum(dev, 0,
123452217195SDaniel Vetter 				   "DPMS", drm_dpms_enum_list,
123552217195SDaniel Vetter 				   ARRAY_SIZE(drm_dpms_enum_list));
123652217195SDaniel Vetter 	if (!prop)
123752217195SDaniel Vetter 		return -ENOMEM;
123852217195SDaniel Vetter 	dev->mode_config.dpms_property = prop;
123952217195SDaniel Vetter 
124052217195SDaniel Vetter 	prop = drm_property_create(dev,
124152217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
124252217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
124352217195SDaniel Vetter 				   "PATH", 0);
124452217195SDaniel Vetter 	if (!prop)
124552217195SDaniel Vetter 		return -ENOMEM;
124652217195SDaniel Vetter 	dev->mode_config.path_property = prop;
124752217195SDaniel Vetter 
124852217195SDaniel Vetter 	prop = drm_property_create(dev,
124952217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
125052217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
125152217195SDaniel Vetter 				   "TILE", 0);
125252217195SDaniel Vetter 	if (!prop)
125352217195SDaniel Vetter 		return -ENOMEM;
125452217195SDaniel Vetter 	dev->mode_config.tile_property = prop;
125552217195SDaniel Vetter 
125640ee6fbeSManasi Navare 	prop = drm_property_create_enum(dev, 0, "link-status",
125740ee6fbeSManasi Navare 					drm_link_status_enum_list,
125840ee6fbeSManasi Navare 					ARRAY_SIZE(drm_link_status_enum_list));
125940ee6fbeSManasi Navare 	if (!prop)
126040ee6fbeSManasi Navare 		return -ENOMEM;
126140ee6fbeSManasi Navare 	dev->mode_config.link_status_property = prop;
126240ee6fbeSManasi Navare 
126366660d4cSDave Airlie 	prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
126466660d4cSDave Airlie 	if (!prop)
126566660d4cSDave Airlie 		return -ENOMEM;
126666660d4cSDave Airlie 	dev->mode_config.non_desktop_property = prop;
126766660d4cSDave Airlie 
1268fbb5d035SUma Shankar 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
1269fbb5d035SUma Shankar 				   "HDR_OUTPUT_METADATA", 0);
1270fbb5d035SUma Shankar 	if (!prop)
1271fbb5d035SUma Shankar 		return -ENOMEM;
1272fbb5d035SUma Shankar 	dev->mode_config.hdr_output_metadata_property = prop;
1273fbb5d035SUma Shankar 
127452217195SDaniel Vetter 	return 0;
127552217195SDaniel Vetter }
127652217195SDaniel Vetter 
127752217195SDaniel Vetter /**
127852217195SDaniel Vetter  * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
127952217195SDaniel Vetter  * @dev: DRM device
128052217195SDaniel Vetter  *
128152217195SDaniel Vetter  * Called by a driver the first time a DVI-I connector is made.
128252217195SDaniel Vetter  */
128352217195SDaniel Vetter int drm_mode_create_dvi_i_properties(struct drm_device *dev)
128452217195SDaniel Vetter {
128552217195SDaniel Vetter 	struct drm_property *dvi_i_selector;
128652217195SDaniel Vetter 	struct drm_property *dvi_i_subconnector;
128752217195SDaniel Vetter 
128852217195SDaniel Vetter 	if (dev->mode_config.dvi_i_select_subconnector_property)
128952217195SDaniel Vetter 		return 0;
129052217195SDaniel Vetter 
129152217195SDaniel Vetter 	dvi_i_selector =
129252217195SDaniel Vetter 		drm_property_create_enum(dev, 0,
129352217195SDaniel Vetter 				    "select subconnector",
129452217195SDaniel Vetter 				    drm_dvi_i_select_enum_list,
129552217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_select_enum_list));
129652217195SDaniel Vetter 	dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
129752217195SDaniel Vetter 
129852217195SDaniel Vetter 	dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
129952217195SDaniel Vetter 				    "subconnector",
130052217195SDaniel Vetter 				    drm_dvi_i_subconnector_enum_list,
130152217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
130252217195SDaniel Vetter 	dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
130352217195SDaniel Vetter 
130452217195SDaniel Vetter 	return 0;
130552217195SDaniel Vetter }
130652217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
130752217195SDaniel Vetter 
130852217195SDaniel Vetter /**
130950525c33SStanislav Lisovskiy  * DOC: HDMI connector properties
131050525c33SStanislav Lisovskiy  *
131150525c33SStanislav Lisovskiy  * content type (HDMI specific):
131250525c33SStanislav Lisovskiy  *	Indicates content type setting to be used in HDMI infoframes to indicate
13131e55a53aSMatt Roper  *	content type for the external device, so that it adjusts its display
131450525c33SStanislav Lisovskiy  *	settings accordingly.
131550525c33SStanislav Lisovskiy  *
131650525c33SStanislav Lisovskiy  *	The value of this property can be one of the following:
131750525c33SStanislav Lisovskiy  *
131850525c33SStanislav Lisovskiy  *	No Data:
131950525c33SStanislav Lisovskiy  *		Content type is unknown
132050525c33SStanislav Lisovskiy  *	Graphics:
132150525c33SStanislav Lisovskiy  *		Content type is graphics
132250525c33SStanislav Lisovskiy  *	Photo:
132350525c33SStanislav Lisovskiy  *		Content type is photo
132450525c33SStanislav Lisovskiy  *	Cinema:
132550525c33SStanislav Lisovskiy  *		Content type is cinema
132650525c33SStanislav Lisovskiy  *	Game:
132750525c33SStanislav Lisovskiy  *		Content type is game
132850525c33SStanislav Lisovskiy  *
132950525c33SStanislav Lisovskiy  *	Drivers can set up this property by calling
133050525c33SStanislav Lisovskiy  *	drm_connector_attach_content_type_property(). Decoding to
1331ba609631SDaniel Vetter  *	infoframe values is done through drm_hdmi_avi_infoframe_content_type().
133250525c33SStanislav Lisovskiy  */
133350525c33SStanislav Lisovskiy 
133450525c33SStanislav Lisovskiy /**
133550525c33SStanislav Lisovskiy  * drm_connector_attach_content_type_property - attach content-type property
133650525c33SStanislav Lisovskiy  * @connector: connector to attach content type property on.
133750525c33SStanislav Lisovskiy  *
133850525c33SStanislav Lisovskiy  * Called by a driver the first time a HDMI connector is made.
133950525c33SStanislav Lisovskiy  */
134050525c33SStanislav Lisovskiy int drm_connector_attach_content_type_property(struct drm_connector *connector)
134150525c33SStanislav Lisovskiy {
134250525c33SStanislav Lisovskiy 	if (!drm_mode_create_content_type_property(connector->dev))
134350525c33SStanislav Lisovskiy 		drm_object_attach_property(&connector->base,
134450525c33SStanislav Lisovskiy 					   connector->dev->mode_config.content_type_property,
134550525c33SStanislav Lisovskiy 					   DRM_MODE_CONTENT_TYPE_NO_DATA);
134650525c33SStanislav Lisovskiy 	return 0;
134750525c33SStanislav Lisovskiy }
134850525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_connector_attach_content_type_property);
134950525c33SStanislav Lisovskiy 
135050525c33SStanislav Lisovskiy 
135150525c33SStanislav Lisovskiy /**
135250525c33SStanislav Lisovskiy  * drm_hdmi_avi_infoframe_content_type() - fill the HDMI AVI infoframe
135350525c33SStanislav Lisovskiy  *                                         content type information, based
135450525c33SStanislav Lisovskiy  *                                         on correspondent DRM property.
135550525c33SStanislav Lisovskiy  * @frame: HDMI AVI infoframe
135650525c33SStanislav Lisovskiy  * @conn_state: DRM display connector state
135750525c33SStanislav Lisovskiy  *
135850525c33SStanislav Lisovskiy  */
135950525c33SStanislav Lisovskiy void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame,
136050525c33SStanislav Lisovskiy 					 const struct drm_connector_state *conn_state)
136150525c33SStanislav Lisovskiy {
136250525c33SStanislav Lisovskiy 	switch (conn_state->content_type) {
136350525c33SStanislav Lisovskiy 	case DRM_MODE_CONTENT_TYPE_GRAPHICS:
136450525c33SStanislav Lisovskiy 		frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
136550525c33SStanislav Lisovskiy 		break;
136650525c33SStanislav Lisovskiy 	case DRM_MODE_CONTENT_TYPE_CINEMA:
136750525c33SStanislav Lisovskiy 		frame->content_type = HDMI_CONTENT_TYPE_CINEMA;
136850525c33SStanislav Lisovskiy 		break;
136950525c33SStanislav Lisovskiy 	case DRM_MODE_CONTENT_TYPE_GAME:
137050525c33SStanislav Lisovskiy 		frame->content_type = HDMI_CONTENT_TYPE_GAME;
137150525c33SStanislav Lisovskiy 		break;
137250525c33SStanislav Lisovskiy 	case DRM_MODE_CONTENT_TYPE_PHOTO:
137350525c33SStanislav Lisovskiy 		frame->content_type = HDMI_CONTENT_TYPE_PHOTO;
137450525c33SStanislav Lisovskiy 		break;
137550525c33SStanislav Lisovskiy 	default:
137650525c33SStanislav Lisovskiy 		/* Graphics is the default(0) */
137750525c33SStanislav Lisovskiy 		frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
137850525c33SStanislav Lisovskiy 	}
137950525c33SStanislav Lisovskiy 
138050525c33SStanislav Lisovskiy 	frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA;
138150525c33SStanislav Lisovskiy }
138250525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type);
138350525c33SStanislav Lisovskiy 
138450525c33SStanislav Lisovskiy /**
13856c4f52dcSBoris Brezillon  * drm_mode_attach_tv_margin_properties - attach TV connector margin properties
13866c4f52dcSBoris Brezillon  * @connector: DRM connector
13876c4f52dcSBoris Brezillon  *
13886c4f52dcSBoris Brezillon  * Called by a driver when it needs to attach TV margin props to a connector.
13896c4f52dcSBoris Brezillon  * Typically used on SDTV and HDMI connectors.
13906c4f52dcSBoris Brezillon  */
13916c4f52dcSBoris Brezillon void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
13926c4f52dcSBoris Brezillon {
13936c4f52dcSBoris Brezillon 	struct drm_device *dev = connector->dev;
13946c4f52dcSBoris Brezillon 
13956c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
13966c4f52dcSBoris Brezillon 				   dev->mode_config.tv_left_margin_property,
13976c4f52dcSBoris Brezillon 				   0);
13986c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
13996c4f52dcSBoris Brezillon 				   dev->mode_config.tv_right_margin_property,
14006c4f52dcSBoris Brezillon 				   0);
14016c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
14026c4f52dcSBoris Brezillon 				   dev->mode_config.tv_top_margin_property,
14036c4f52dcSBoris Brezillon 				   0);
14046c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
14056c4f52dcSBoris Brezillon 				   dev->mode_config.tv_bottom_margin_property,
14066c4f52dcSBoris Brezillon 				   0);
14076c4f52dcSBoris Brezillon }
14086c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
14096c4f52dcSBoris Brezillon 
14106c4f52dcSBoris Brezillon /**
14116c4f52dcSBoris Brezillon  * drm_mode_create_tv_margin_properties - create TV connector margin properties
14126c4f52dcSBoris Brezillon  * @dev: DRM device
14136c4f52dcSBoris Brezillon  *
14146c4f52dcSBoris Brezillon  * Called by a driver's HDMI connector initialization routine, this function
14156c4f52dcSBoris Brezillon  * creates the TV margin properties for a given device. No need to call this
14166c4f52dcSBoris Brezillon  * function for an SDTV connector, it's already called from
14176c4f52dcSBoris Brezillon  * drm_mode_create_tv_properties().
14186c4f52dcSBoris Brezillon  */
14196c4f52dcSBoris Brezillon int drm_mode_create_tv_margin_properties(struct drm_device *dev)
14206c4f52dcSBoris Brezillon {
14216c4f52dcSBoris Brezillon 	if (dev->mode_config.tv_left_margin_property)
14226c4f52dcSBoris Brezillon 		return 0;
14236c4f52dcSBoris Brezillon 
14246c4f52dcSBoris Brezillon 	dev->mode_config.tv_left_margin_property =
14256c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "left margin", 0, 100);
14266c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_left_margin_property)
14276c4f52dcSBoris Brezillon 		return -ENOMEM;
14286c4f52dcSBoris Brezillon 
14296c4f52dcSBoris Brezillon 	dev->mode_config.tv_right_margin_property =
14306c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "right margin", 0, 100);
14316c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_right_margin_property)
14326c4f52dcSBoris Brezillon 		return -ENOMEM;
14336c4f52dcSBoris Brezillon 
14346c4f52dcSBoris Brezillon 	dev->mode_config.tv_top_margin_property =
14356c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "top margin", 0, 100);
14366c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_top_margin_property)
14376c4f52dcSBoris Brezillon 		return -ENOMEM;
14386c4f52dcSBoris Brezillon 
14396c4f52dcSBoris Brezillon 	dev->mode_config.tv_bottom_margin_property =
14406c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "bottom margin", 0, 100);
14416c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_bottom_margin_property)
14426c4f52dcSBoris Brezillon 		return -ENOMEM;
14436c4f52dcSBoris Brezillon 
14446c4f52dcSBoris Brezillon 	return 0;
14456c4f52dcSBoris Brezillon }
14466c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
14476c4f52dcSBoris Brezillon 
14486c4f52dcSBoris Brezillon /**
1449eda6887fSBoris Brezillon  * drm_mode_create_tv_properties - create TV specific connector properties
145052217195SDaniel Vetter  * @dev: DRM device
145152217195SDaniel Vetter  * @num_modes: number of different TV formats (modes) supported
145252217195SDaniel Vetter  * @modes: array of pointers to strings containing name of each format
145352217195SDaniel Vetter  *
145452217195SDaniel Vetter  * Called by a driver's TV initialization routine, this function creates
145552217195SDaniel Vetter  * the TV specific connector properties for a given device.  Caller is
145652217195SDaniel Vetter  * responsible for allocating a list of format names and passing them to
145752217195SDaniel Vetter  * this routine.
145852217195SDaniel Vetter  */
145952217195SDaniel Vetter int drm_mode_create_tv_properties(struct drm_device *dev,
146052217195SDaniel Vetter 				  unsigned int num_modes,
146152217195SDaniel Vetter 				  const char * const modes[])
146252217195SDaniel Vetter {
146352217195SDaniel Vetter 	struct drm_property *tv_selector;
146452217195SDaniel Vetter 	struct drm_property *tv_subconnector;
146552217195SDaniel Vetter 	unsigned int i;
146652217195SDaniel Vetter 
146752217195SDaniel Vetter 	if (dev->mode_config.tv_select_subconnector_property)
146852217195SDaniel Vetter 		return 0;
146952217195SDaniel Vetter 
147052217195SDaniel Vetter 	/*
147152217195SDaniel Vetter 	 * Basic connector properties
147252217195SDaniel Vetter 	 */
147352217195SDaniel Vetter 	tv_selector = drm_property_create_enum(dev, 0,
147452217195SDaniel Vetter 					  "select subconnector",
147552217195SDaniel Vetter 					  drm_tv_select_enum_list,
147652217195SDaniel Vetter 					  ARRAY_SIZE(drm_tv_select_enum_list));
147752217195SDaniel Vetter 	if (!tv_selector)
147852217195SDaniel Vetter 		goto nomem;
147952217195SDaniel Vetter 
148052217195SDaniel Vetter 	dev->mode_config.tv_select_subconnector_property = tv_selector;
148152217195SDaniel Vetter 
148252217195SDaniel Vetter 	tv_subconnector =
148352217195SDaniel Vetter 		drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
148452217195SDaniel Vetter 				    "subconnector",
148552217195SDaniel Vetter 				    drm_tv_subconnector_enum_list,
148652217195SDaniel Vetter 				    ARRAY_SIZE(drm_tv_subconnector_enum_list));
148752217195SDaniel Vetter 	if (!tv_subconnector)
148852217195SDaniel Vetter 		goto nomem;
148952217195SDaniel Vetter 	dev->mode_config.tv_subconnector_property = tv_subconnector;
149052217195SDaniel Vetter 
149152217195SDaniel Vetter 	/*
149252217195SDaniel Vetter 	 * Other, TV specific properties: margins & TV modes.
149352217195SDaniel Vetter 	 */
14946c4f52dcSBoris Brezillon 	if (drm_mode_create_tv_margin_properties(dev))
149552217195SDaniel Vetter 		goto nomem;
149652217195SDaniel Vetter 
149752217195SDaniel Vetter 	dev->mode_config.tv_mode_property =
149852217195SDaniel Vetter 		drm_property_create(dev, DRM_MODE_PROP_ENUM,
149952217195SDaniel Vetter 				    "mode", num_modes);
150052217195SDaniel Vetter 	if (!dev->mode_config.tv_mode_property)
150152217195SDaniel Vetter 		goto nomem;
150252217195SDaniel Vetter 
150352217195SDaniel Vetter 	for (i = 0; i < num_modes; i++)
150430e9db6dSVille Syrjälä 		drm_property_add_enum(dev->mode_config.tv_mode_property,
150552217195SDaniel Vetter 				      i, modes[i]);
150652217195SDaniel Vetter 
150752217195SDaniel Vetter 	dev->mode_config.tv_brightness_property =
150852217195SDaniel Vetter 		drm_property_create_range(dev, 0, "brightness", 0, 100);
150952217195SDaniel Vetter 	if (!dev->mode_config.tv_brightness_property)
151052217195SDaniel Vetter 		goto nomem;
151152217195SDaniel Vetter 
151252217195SDaniel Vetter 	dev->mode_config.tv_contrast_property =
151352217195SDaniel Vetter 		drm_property_create_range(dev, 0, "contrast", 0, 100);
151452217195SDaniel Vetter 	if (!dev->mode_config.tv_contrast_property)
151552217195SDaniel Vetter 		goto nomem;
151652217195SDaniel Vetter 
151752217195SDaniel Vetter 	dev->mode_config.tv_flicker_reduction_property =
151852217195SDaniel Vetter 		drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
151952217195SDaniel Vetter 	if (!dev->mode_config.tv_flicker_reduction_property)
152052217195SDaniel Vetter 		goto nomem;
152152217195SDaniel Vetter 
152252217195SDaniel Vetter 	dev->mode_config.tv_overscan_property =
152352217195SDaniel Vetter 		drm_property_create_range(dev, 0, "overscan", 0, 100);
152452217195SDaniel Vetter 	if (!dev->mode_config.tv_overscan_property)
152552217195SDaniel Vetter 		goto nomem;
152652217195SDaniel Vetter 
152752217195SDaniel Vetter 	dev->mode_config.tv_saturation_property =
152852217195SDaniel Vetter 		drm_property_create_range(dev, 0, "saturation", 0, 100);
152952217195SDaniel Vetter 	if (!dev->mode_config.tv_saturation_property)
153052217195SDaniel Vetter 		goto nomem;
153152217195SDaniel Vetter 
153252217195SDaniel Vetter 	dev->mode_config.tv_hue_property =
153352217195SDaniel Vetter 		drm_property_create_range(dev, 0, "hue", 0, 100);
153452217195SDaniel Vetter 	if (!dev->mode_config.tv_hue_property)
153552217195SDaniel Vetter 		goto nomem;
153652217195SDaniel Vetter 
153752217195SDaniel Vetter 	return 0;
153852217195SDaniel Vetter nomem:
153952217195SDaniel Vetter 	return -ENOMEM;
154052217195SDaniel Vetter }
154152217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tv_properties);
154252217195SDaniel Vetter 
154352217195SDaniel Vetter /**
154452217195SDaniel Vetter  * drm_mode_create_scaling_mode_property - create scaling mode property
154552217195SDaniel Vetter  * @dev: DRM device
154652217195SDaniel Vetter  *
154752217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
154852217195SDaniel Vetter  * connectors.
15498f6e1e22SMaarten Lankhorst  *
15508f6e1e22SMaarten Lankhorst  * Atomic drivers should use drm_connector_attach_scaling_mode_property()
15518f6e1e22SMaarten Lankhorst  * instead to correctly assign &drm_connector_state.picture_aspect_ratio
15528f6e1e22SMaarten Lankhorst  * in the atomic state.
155352217195SDaniel Vetter  */
155452217195SDaniel Vetter int drm_mode_create_scaling_mode_property(struct drm_device *dev)
155552217195SDaniel Vetter {
155652217195SDaniel Vetter 	struct drm_property *scaling_mode;
155752217195SDaniel Vetter 
155852217195SDaniel Vetter 	if (dev->mode_config.scaling_mode_property)
155952217195SDaniel Vetter 		return 0;
156052217195SDaniel Vetter 
156152217195SDaniel Vetter 	scaling_mode =
156252217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "scaling mode",
156352217195SDaniel Vetter 				drm_scaling_mode_enum_list,
156452217195SDaniel Vetter 				    ARRAY_SIZE(drm_scaling_mode_enum_list));
156552217195SDaniel Vetter 
156652217195SDaniel Vetter 	dev->mode_config.scaling_mode_property = scaling_mode;
156752217195SDaniel Vetter 
156852217195SDaniel Vetter 	return 0;
156952217195SDaniel Vetter }
157052217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
157152217195SDaniel Vetter 
157252217195SDaniel Vetter /**
1573ab7a664fSNicholas Kazlauskas  * DOC: Variable refresh properties
1574ab7a664fSNicholas Kazlauskas  *
1575ab7a664fSNicholas Kazlauskas  * Variable refresh rate capable displays can dynamically adjust their
1576ab7a664fSNicholas Kazlauskas  * refresh rate by extending the duration of their vertical front porch
1577ab7a664fSNicholas Kazlauskas  * until page flip or timeout occurs. This can reduce or remove stuttering
1578ab7a664fSNicholas Kazlauskas  * and latency in scenarios where the page flip does not align with the
1579ab7a664fSNicholas Kazlauskas  * vblank interval.
1580ab7a664fSNicholas Kazlauskas  *
1581ab7a664fSNicholas Kazlauskas  * An example scenario would be an application flipping at a constant rate
1582ab7a664fSNicholas Kazlauskas  * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
1583ab7a664fSNicholas Kazlauskas  * interval and the same contents will be displayed twice. This can be
1584ab7a664fSNicholas Kazlauskas  * observed as stuttering for content with motion.
1585ab7a664fSNicholas Kazlauskas  *
1586ab7a664fSNicholas Kazlauskas  * If variable refresh rate was active on a display that supported a
1587ab7a664fSNicholas Kazlauskas  * variable refresh range from 35Hz to 60Hz no stuttering would be observable
1588ab7a664fSNicholas Kazlauskas  * for the example scenario. The minimum supported variable refresh rate of
1589ab7a664fSNicholas Kazlauskas  * 35Hz is below the page flip frequency and the vertical front porch can
1590ab7a664fSNicholas Kazlauskas  * be extended until the page flip occurs. The vblank interval will be
1591ab7a664fSNicholas Kazlauskas  * directly aligned to the page flip rate.
1592ab7a664fSNicholas Kazlauskas  *
1593ab7a664fSNicholas Kazlauskas  * Not all userspace content is suitable for use with variable refresh rate.
1594ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may worsen
1595ab7a664fSNicholas Kazlauskas  * perceived stuttering for input sensitive applications.
1596ab7a664fSNicholas Kazlauskas  *
1597ab7a664fSNicholas Kazlauskas  * Panel brightness will also vary with vertical front porch duration. Some
1598ab7a664fSNicholas Kazlauskas  * panels may have noticeable differences in brightness between the minimum
1599ab7a664fSNicholas Kazlauskas  * vertical front porch duration and the maximum vertical front porch duration.
1600ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may produce
1601ab7a664fSNicholas Kazlauskas  * observable flickering for such panels.
1602ab7a664fSNicholas Kazlauskas  *
1603ab7a664fSNicholas Kazlauskas  * Userspace control for variable refresh rate is supported via properties
1604ab7a664fSNicholas Kazlauskas  * on the &drm_connector and &drm_crtc objects.
1605ab7a664fSNicholas Kazlauskas  *
1606ab7a664fSNicholas Kazlauskas  * "vrr_capable":
1607ab7a664fSNicholas Kazlauskas  *	Optional &drm_connector boolean property that drivers should attach
1608ab7a664fSNicholas Kazlauskas  *	with drm_connector_attach_vrr_capable_property() on connectors that
1609ab7a664fSNicholas Kazlauskas  *	could support variable refresh rates. Drivers should update the
1610ab7a664fSNicholas Kazlauskas  *	property value by calling drm_connector_set_vrr_capable_property().
1611ab7a664fSNicholas Kazlauskas  *
1612ab7a664fSNicholas Kazlauskas  *	Absence of the property should indicate absence of support.
1613ab7a664fSNicholas Kazlauskas  *
161477086014SDaniel Vetter  * "VRR_ENABLED":
1615ab7a664fSNicholas Kazlauskas  *	Default &drm_crtc boolean property that notifies the driver that the
1616ab7a664fSNicholas Kazlauskas  *	content on the CRTC is suitable for variable refresh rate presentation.
1617ab7a664fSNicholas Kazlauskas  *	The driver will take this property as a hint to enable variable
1618ab7a664fSNicholas Kazlauskas  *	refresh rate support if the receiver supports it, ie. if the
1619ab7a664fSNicholas Kazlauskas  *	"vrr_capable" property is true on the &drm_connector object. The
1620ab7a664fSNicholas Kazlauskas  *	vertical front porch duration will be extended until page-flip or
1621ab7a664fSNicholas Kazlauskas  *	timeout when enabled.
1622ab7a664fSNicholas Kazlauskas  *
1623ab7a664fSNicholas Kazlauskas  *	The minimum vertical front porch duration is defined as the vertical
1624ab7a664fSNicholas Kazlauskas  *	front porch duration for the current mode.
1625ab7a664fSNicholas Kazlauskas  *
1626ab7a664fSNicholas Kazlauskas  *	The maximum vertical front porch duration is greater than or equal to
1627ab7a664fSNicholas Kazlauskas  *	the minimum vertical front porch duration. The duration is derived
1628ab7a664fSNicholas Kazlauskas  *	from the minimum supported variable refresh rate for the connector.
1629ab7a664fSNicholas Kazlauskas  *
1630ab7a664fSNicholas Kazlauskas  *	The driver may place further restrictions within these minimum
1631ab7a664fSNicholas Kazlauskas  *	and maximum bounds.
1632ab7a664fSNicholas Kazlauskas  */
1633ab7a664fSNicholas Kazlauskas 
1634ab7a664fSNicholas Kazlauskas /**
1635ba1b0f6cSNicholas Kazlauskas  * drm_connector_attach_vrr_capable_property - creates the
1636ba1b0f6cSNicholas Kazlauskas  * vrr_capable property
1637ba1b0f6cSNicholas Kazlauskas  * @connector: connector to create the vrr_capable property on.
1638ba1b0f6cSNicholas Kazlauskas  *
1639ba1b0f6cSNicholas Kazlauskas  * This is used by atomic drivers to add support for querying
1640ba1b0f6cSNicholas Kazlauskas  * variable refresh rate capability for a connector.
1641ba1b0f6cSNicholas Kazlauskas  *
1642ba1b0f6cSNicholas Kazlauskas  * Returns:
164384e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
1644ba1b0f6cSNicholas Kazlauskas  */
1645ba1b0f6cSNicholas Kazlauskas int drm_connector_attach_vrr_capable_property(
1646ba1b0f6cSNicholas Kazlauskas 	struct drm_connector *connector)
1647ba1b0f6cSNicholas Kazlauskas {
1648ba1b0f6cSNicholas Kazlauskas 	struct drm_device *dev = connector->dev;
1649ba1b0f6cSNicholas Kazlauskas 	struct drm_property *prop;
1650ba1b0f6cSNicholas Kazlauskas 
1651ba1b0f6cSNicholas Kazlauskas 	if (!connector->vrr_capable_property) {
1652ba1b0f6cSNicholas Kazlauskas 		prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
1653ba1b0f6cSNicholas Kazlauskas 			"vrr_capable");
1654ba1b0f6cSNicholas Kazlauskas 		if (!prop)
1655ba1b0f6cSNicholas Kazlauskas 			return -ENOMEM;
1656ba1b0f6cSNicholas Kazlauskas 
1657ba1b0f6cSNicholas Kazlauskas 		connector->vrr_capable_property = prop;
1658ba1b0f6cSNicholas Kazlauskas 		drm_object_attach_property(&connector->base, prop, 0);
1659ba1b0f6cSNicholas Kazlauskas 	}
1660ba1b0f6cSNicholas Kazlauskas 
1661ba1b0f6cSNicholas Kazlauskas 	return 0;
1662ba1b0f6cSNicholas Kazlauskas }
1663ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
1664ba1b0f6cSNicholas Kazlauskas 
1665ba1b0f6cSNicholas Kazlauskas /**
16668f6e1e22SMaarten Lankhorst  * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
16678f6e1e22SMaarten Lankhorst  * @connector: connector to attach scaling mode property on.
16688f6e1e22SMaarten Lankhorst  * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
16698f6e1e22SMaarten Lankhorst  *
16708f6e1e22SMaarten Lankhorst  * This is used to add support for scaling mode to atomic drivers.
16718f6e1e22SMaarten Lankhorst  * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio
16728f6e1e22SMaarten Lankhorst  * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
16738f6e1e22SMaarten Lankhorst  *
16748f6e1e22SMaarten Lankhorst  * This is the atomic version of drm_mode_create_scaling_mode_property().
16758f6e1e22SMaarten Lankhorst  *
16768f6e1e22SMaarten Lankhorst  * Returns:
16778f6e1e22SMaarten Lankhorst  * Zero on success, negative errno on failure.
16788f6e1e22SMaarten Lankhorst  */
16798f6e1e22SMaarten Lankhorst int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
16808f6e1e22SMaarten Lankhorst 					       u32 scaling_mode_mask)
16818f6e1e22SMaarten Lankhorst {
16828f6e1e22SMaarten Lankhorst 	struct drm_device *dev = connector->dev;
16838f6e1e22SMaarten Lankhorst 	struct drm_property *scaling_mode_property;
168430e9db6dSVille Syrjälä 	int i;
16858f6e1e22SMaarten Lankhorst 	const unsigned valid_scaling_mode_mask =
16868f6e1e22SMaarten Lankhorst 		(1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
16878f6e1e22SMaarten Lankhorst 
16888f6e1e22SMaarten Lankhorst 	if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
16898f6e1e22SMaarten Lankhorst 		    scaling_mode_mask & ~valid_scaling_mode_mask))
16908f6e1e22SMaarten Lankhorst 		return -EINVAL;
16918f6e1e22SMaarten Lankhorst 
16928f6e1e22SMaarten Lankhorst 	scaling_mode_property =
16938f6e1e22SMaarten Lankhorst 		drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
16948f6e1e22SMaarten Lankhorst 				    hweight32(scaling_mode_mask));
16958f6e1e22SMaarten Lankhorst 
16968f6e1e22SMaarten Lankhorst 	if (!scaling_mode_property)
16978f6e1e22SMaarten Lankhorst 		return -ENOMEM;
16988f6e1e22SMaarten Lankhorst 
16998f6e1e22SMaarten Lankhorst 	for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
17008f6e1e22SMaarten Lankhorst 		int ret;
17018f6e1e22SMaarten Lankhorst 
17028f6e1e22SMaarten Lankhorst 		if (!(BIT(i) & scaling_mode_mask))
17038f6e1e22SMaarten Lankhorst 			continue;
17048f6e1e22SMaarten Lankhorst 
170530e9db6dSVille Syrjälä 		ret = drm_property_add_enum(scaling_mode_property,
17068f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].type,
17078f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].name);
17088f6e1e22SMaarten Lankhorst 
17098f6e1e22SMaarten Lankhorst 		if (ret) {
17108f6e1e22SMaarten Lankhorst 			drm_property_destroy(dev, scaling_mode_property);
17118f6e1e22SMaarten Lankhorst 
17128f6e1e22SMaarten Lankhorst 			return ret;
17138f6e1e22SMaarten Lankhorst 		}
17148f6e1e22SMaarten Lankhorst 	}
17158f6e1e22SMaarten Lankhorst 
17168f6e1e22SMaarten Lankhorst 	drm_object_attach_property(&connector->base,
17178f6e1e22SMaarten Lankhorst 				   scaling_mode_property, 0);
17188f6e1e22SMaarten Lankhorst 
17198f6e1e22SMaarten Lankhorst 	connector->scaling_mode_property = scaling_mode_property;
17208f6e1e22SMaarten Lankhorst 
17218f6e1e22SMaarten Lankhorst 	return 0;
17228f6e1e22SMaarten Lankhorst }
17238f6e1e22SMaarten Lankhorst EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
17248f6e1e22SMaarten Lankhorst 
17258f6e1e22SMaarten Lankhorst /**
172652217195SDaniel Vetter  * drm_mode_create_aspect_ratio_property - create aspect ratio property
172752217195SDaniel Vetter  * @dev: DRM device
172852217195SDaniel Vetter  *
172952217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
173052217195SDaniel Vetter  * connectors.
173152217195SDaniel Vetter  *
173252217195SDaniel Vetter  * Returns:
173352217195SDaniel Vetter  * Zero on success, negative errno on failure.
173452217195SDaniel Vetter  */
173552217195SDaniel Vetter int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
173652217195SDaniel Vetter {
173752217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property)
173852217195SDaniel Vetter 		return 0;
173952217195SDaniel Vetter 
174052217195SDaniel Vetter 	dev->mode_config.aspect_ratio_property =
174152217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "aspect ratio",
174252217195SDaniel Vetter 				drm_aspect_ratio_enum_list,
174352217195SDaniel Vetter 				ARRAY_SIZE(drm_aspect_ratio_enum_list));
174452217195SDaniel Vetter 
174552217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property == NULL)
174652217195SDaniel Vetter 		return -ENOMEM;
174752217195SDaniel Vetter 
174852217195SDaniel Vetter 	return 0;
174952217195SDaniel Vetter }
175052217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
175152217195SDaniel Vetter 
175252217195SDaniel Vetter /**
1753d2c6a405SUma Shankar  * DOC: standard connector properties
1754d2c6a405SUma Shankar  *
1755d2c6a405SUma Shankar  * Colorspace:
1756d2c6a405SUma Shankar  *     This property helps select a suitable colorspace based on the sink
1757d2c6a405SUma Shankar  *     capability. Modern sink devices support wider gamut like BT2020.
1758d2c6a405SUma Shankar  *     This helps switch to BT2020 mode if the BT2020 encoded video stream
1759d2c6a405SUma Shankar  *     is being played by the user, same for any other colorspace. Thereby
1760d2c6a405SUma Shankar  *     giving a good visual experience to users.
1761d2c6a405SUma Shankar  *
1762d2c6a405SUma Shankar  *     The expectation from userspace is that it should parse the EDID
1763d2c6a405SUma Shankar  *     and get supported colorspaces. Use this property and switch to the
1764d2c6a405SUma Shankar  *     one supported. Sink supported colorspaces should be retrieved by
1765d2c6a405SUma Shankar  *     userspace from EDID and driver will not explicitly expose them.
1766d2c6a405SUma Shankar  *
1767d2c6a405SUma Shankar  *     Basically the expectation from userspace is:
1768d2c6a405SUma Shankar  *      - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink
1769d2c6a405SUma Shankar  *        colorspace
1770d2c6a405SUma Shankar  *      - Set this new property to let the sink know what it
1771d2c6a405SUma Shankar  *        converted the CRTC output to.
1772d2c6a405SUma Shankar  *      - This property is just to inform sink what colorspace
1773d2c6a405SUma Shankar  *        source is trying to drive.
1774d2c6a405SUma Shankar  *
17758806cd3aSGwan-gyeong Mun  * Because between HDMI and DP have different colorspaces,
177645cf0e91SGwan-gyeong Mun  * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and
177745cf0e91SGwan-gyeong Mun  * drm_mode_create_dp_colorspace_property() is used for DP connector.
1778d2c6a405SUma Shankar  */
17798806cd3aSGwan-gyeong Mun 
17808806cd3aSGwan-gyeong Mun /**
17818806cd3aSGwan-gyeong Mun  * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
17828806cd3aSGwan-gyeong Mun  * @connector: connector to create the Colorspace property on.
17838806cd3aSGwan-gyeong Mun  *
17848806cd3aSGwan-gyeong Mun  * Called by a driver the first time it's needed, must be attached to desired
17858806cd3aSGwan-gyeong Mun  * HDMI connectors.
17868806cd3aSGwan-gyeong Mun  *
17878806cd3aSGwan-gyeong Mun  * Returns:
178884e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
17898806cd3aSGwan-gyeong Mun  */
17908806cd3aSGwan-gyeong Mun int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector)
1791d2c6a405SUma Shankar {
1792d2c6a405SUma Shankar 	struct drm_device *dev = connector->dev;
1793d2c6a405SUma Shankar 
17948806cd3aSGwan-gyeong Mun 	if (connector->colorspace_property)
17958806cd3aSGwan-gyeong Mun 		return 0;
17968806cd3aSGwan-gyeong Mun 
17978806cd3aSGwan-gyeong Mun 	connector->colorspace_property =
17988806cd3aSGwan-gyeong Mun 		drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
1799d2c6a405SUma Shankar 					 hdmi_colorspaces,
1800d2c6a405SUma Shankar 					 ARRAY_SIZE(hdmi_colorspaces));
18018806cd3aSGwan-gyeong Mun 
18028806cd3aSGwan-gyeong Mun 	if (!connector->colorspace_property)
1803d2c6a405SUma Shankar 		return -ENOMEM;
1804d2c6a405SUma Shankar 
1805d2c6a405SUma Shankar 	return 0;
1806d2c6a405SUma Shankar }
18078806cd3aSGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
1808d2c6a405SUma Shankar 
1809d2c6a405SUma Shankar /**
181045cf0e91SGwan-gyeong Mun  * drm_mode_create_dp_colorspace_property - create dp colorspace property
181145cf0e91SGwan-gyeong Mun  * @connector: connector to create the Colorspace property on.
181245cf0e91SGwan-gyeong Mun  *
181345cf0e91SGwan-gyeong Mun  * Called by a driver the first time it's needed, must be attached to desired
181445cf0e91SGwan-gyeong Mun  * DP connectors.
181545cf0e91SGwan-gyeong Mun  *
181645cf0e91SGwan-gyeong Mun  * Returns:
181784e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
181845cf0e91SGwan-gyeong Mun  */
181945cf0e91SGwan-gyeong Mun int drm_mode_create_dp_colorspace_property(struct drm_connector *connector)
182045cf0e91SGwan-gyeong Mun {
182145cf0e91SGwan-gyeong Mun 	struct drm_device *dev = connector->dev;
182245cf0e91SGwan-gyeong Mun 
182345cf0e91SGwan-gyeong Mun 	if (connector->colorspace_property)
182445cf0e91SGwan-gyeong Mun 		return 0;
182545cf0e91SGwan-gyeong Mun 
182645cf0e91SGwan-gyeong Mun 	connector->colorspace_property =
182745cf0e91SGwan-gyeong Mun 		drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
182845cf0e91SGwan-gyeong Mun 					 dp_colorspaces,
182945cf0e91SGwan-gyeong Mun 					 ARRAY_SIZE(dp_colorspaces));
183045cf0e91SGwan-gyeong Mun 
183145cf0e91SGwan-gyeong Mun 	if (!connector->colorspace_property)
183245cf0e91SGwan-gyeong Mun 		return -ENOMEM;
183345cf0e91SGwan-gyeong Mun 
183445cf0e91SGwan-gyeong Mun 	return 0;
183545cf0e91SGwan-gyeong Mun }
183645cf0e91SGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
183752217195SDaniel Vetter 
183897e14fbeSDaniel Vetter /**
183952217195SDaniel Vetter  * drm_mode_create_content_type_property - create content type property
184052217195SDaniel Vetter  * @dev: DRM device
184197e14fbeSDaniel Vetter  *
184252217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
184352217195SDaniel Vetter  * connectors.
184452217195SDaniel Vetter  *
184552217195SDaniel Vetter  * Returns:
184652217195SDaniel Vetter  * Zero on success, negative errno on failure.
184752217195SDaniel Vetter  */
184852217195SDaniel Vetter int drm_mode_create_content_type_property(struct drm_device *dev)
184952217195SDaniel Vetter {
185052217195SDaniel Vetter 	if (dev->mode_config.content_type_property)
185197e14fbeSDaniel Vetter 		return 0;
185252217195SDaniel Vetter 
185352217195SDaniel Vetter 	dev->mode_config.content_type_property =
185452217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "content type",
185552217195SDaniel Vetter 					 drm_content_type_enum_list,
185652217195SDaniel Vetter 					 ARRAY_SIZE(drm_content_type_enum_list));
185752217195SDaniel Vetter 
185852217195SDaniel Vetter 	if (dev->mode_config.content_type_property == NULL)
185952217195SDaniel Vetter 		return -ENOMEM;
186052217195SDaniel Vetter 
186152217195SDaniel Vetter 	return 0;
186252217195SDaniel Vetter }
186352217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_content_type_property);
186452217195SDaniel Vetter 
186552217195SDaniel Vetter /**
186652217195SDaniel Vetter  * drm_mode_create_suggested_offset_properties - create suggests offset properties
186752217195SDaniel Vetter  * @dev: DRM device
186852217195SDaniel Vetter  *
186984e543bcSAntonio Borneo  * Create the suggested x/y offset property for connectors.
187052217195SDaniel Vetter  */
187152217195SDaniel Vetter int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
187252217195SDaniel Vetter {
187352217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
187452217195SDaniel Vetter 		return 0;
187552217195SDaniel Vetter 
187652217195SDaniel Vetter 	dev->mode_config.suggested_x_property =
187752217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
187852217195SDaniel Vetter 
187952217195SDaniel Vetter 	dev->mode_config.suggested_y_property =
188052217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
188152217195SDaniel Vetter 
188252217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property == NULL ||
188352217195SDaniel Vetter 	    dev->mode_config.suggested_y_property == NULL)
188452217195SDaniel Vetter 		return -ENOMEM;
188552217195SDaniel Vetter 	return 0;
188652217195SDaniel Vetter }
188752217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
188852217195SDaniel Vetter 
188952217195SDaniel Vetter /**
189052217195SDaniel Vetter  * drm_connector_set_path_property - set tile property on connector
189152217195SDaniel Vetter  * @connector: connector to set property on.
189252217195SDaniel Vetter  * @path: path to use for property; must not be NULL.
189352217195SDaniel Vetter  *
189452217195SDaniel Vetter  * This creates a property to expose to userspace to specify a
189552217195SDaniel Vetter  * connector path. This is mainly used for DisplayPort MST where
189652217195SDaniel Vetter  * connectors have a topology and we want to allow userspace to give
189752217195SDaniel Vetter  * them more meaningful names.
189852217195SDaniel Vetter  *
189952217195SDaniel Vetter  * Returns:
190052217195SDaniel Vetter  * Zero on success, negative errno on failure.
190152217195SDaniel Vetter  */
190252217195SDaniel Vetter int drm_connector_set_path_property(struct drm_connector *connector,
190352217195SDaniel Vetter 				    const char *path)
190452217195SDaniel Vetter {
190552217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
190652217195SDaniel Vetter 	int ret;
190752217195SDaniel Vetter 
190852217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
190952217195SDaniel Vetter 	                                       &connector->path_blob_ptr,
191052217195SDaniel Vetter 	                                       strlen(path) + 1,
191152217195SDaniel Vetter 	                                       path,
191252217195SDaniel Vetter 	                                       &connector->base,
191352217195SDaniel Vetter 	                                       dev->mode_config.path_property);
191452217195SDaniel Vetter 	return ret;
191552217195SDaniel Vetter }
191652217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_set_path_property);
191752217195SDaniel Vetter 
191852217195SDaniel Vetter /**
191952217195SDaniel Vetter  * drm_connector_set_tile_property - set tile property on connector
192052217195SDaniel Vetter  * @connector: connector to set property on.
192152217195SDaniel Vetter  *
192252217195SDaniel Vetter  * This looks up the tile information for a connector, and creates a
192352217195SDaniel Vetter  * property for userspace to parse if it exists. The property is of
192452217195SDaniel Vetter  * the form of 8 integers using ':' as a separator.
19252de3a078SManasi Navare  * This is used for dual port tiled displays with DisplayPort SST
19262de3a078SManasi Navare  * or DisplayPort MST connectors.
192752217195SDaniel Vetter  *
192852217195SDaniel Vetter  * Returns:
192952217195SDaniel Vetter  * Zero on success, errno on failure.
193052217195SDaniel Vetter  */
193152217195SDaniel Vetter int drm_connector_set_tile_property(struct drm_connector *connector)
193252217195SDaniel Vetter {
193352217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
193452217195SDaniel Vetter 	char tile[256];
193552217195SDaniel Vetter 	int ret;
193652217195SDaniel Vetter 
193752217195SDaniel Vetter 	if (!connector->has_tile) {
193852217195SDaniel Vetter 		ret  = drm_property_replace_global_blob(dev,
193952217195SDaniel Vetter 		                                        &connector->tile_blob_ptr,
194052217195SDaniel Vetter 		                                        0,
194152217195SDaniel Vetter 		                                        NULL,
194252217195SDaniel Vetter 		                                        &connector->base,
194352217195SDaniel Vetter 		                                        dev->mode_config.tile_property);
194452217195SDaniel Vetter 		return ret;
194552217195SDaniel Vetter 	}
194652217195SDaniel Vetter 
194752217195SDaniel Vetter 	snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
194852217195SDaniel Vetter 		 connector->tile_group->id, connector->tile_is_single_monitor,
194952217195SDaniel Vetter 		 connector->num_h_tile, connector->num_v_tile,
195052217195SDaniel Vetter 		 connector->tile_h_loc, connector->tile_v_loc,
195152217195SDaniel Vetter 		 connector->tile_h_size, connector->tile_v_size);
195252217195SDaniel Vetter 
195352217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
195452217195SDaniel Vetter 	                                       &connector->tile_blob_ptr,
195552217195SDaniel Vetter 	                                       strlen(tile) + 1,
195652217195SDaniel Vetter 	                                       tile,
195752217195SDaniel Vetter 	                                       &connector->base,
195852217195SDaniel Vetter 	                                       dev->mode_config.tile_property);
195952217195SDaniel Vetter 	return ret;
196052217195SDaniel Vetter }
196197e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_tile_property);
196252217195SDaniel Vetter 
196352217195SDaniel Vetter /**
1964c555f023SDaniel Vetter  * drm_connector_update_edid_property - update the edid property of a connector
196552217195SDaniel Vetter  * @connector: drm connector
196652217195SDaniel Vetter  * @edid: new value of the edid property
196752217195SDaniel Vetter  *
196852217195SDaniel Vetter  * This function creates a new blob modeset object and assigns its id to the
196952217195SDaniel Vetter  * connector's edid property.
19702de3a078SManasi Navare  * Since we also parse tile information from EDID's displayID block, we also
19712de3a078SManasi Navare  * set the connector's tile property here. See drm_connector_set_tile_property()
19722de3a078SManasi Navare  * for more details.
197352217195SDaniel Vetter  *
197452217195SDaniel Vetter  * Returns:
197552217195SDaniel Vetter  * Zero on success, negative errno on failure.
197652217195SDaniel Vetter  */
1977c555f023SDaniel Vetter int drm_connector_update_edid_property(struct drm_connector *connector,
197852217195SDaniel Vetter 				       const struct edid *edid)
197952217195SDaniel Vetter {
198052217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
198152217195SDaniel Vetter 	size_t size = 0;
198252217195SDaniel Vetter 	int ret;
19835186421cSStanislav Lisovskiy 	const struct edid *old_edid;
198452217195SDaniel Vetter 
198552217195SDaniel Vetter 	/* ignore requests to set edid when overridden */
198652217195SDaniel Vetter 	if (connector->override_edid)
198752217195SDaniel Vetter 		return 0;
198852217195SDaniel Vetter 
198952217195SDaniel Vetter 	if (edid)
199052217195SDaniel Vetter 		size = EDID_LENGTH * (1 + edid->extensions);
199152217195SDaniel Vetter 
1992170178feSKeith Packard 	/* Set the display info, using edid if available, otherwise
199384e543bcSAntonio Borneo 	 * resetting the values to defaults. This duplicates the work
1994170178feSKeith Packard 	 * done in drm_add_edid_modes, but that function is not
1995170178feSKeith Packard 	 * consistently called before this one in all drivers and the
1996170178feSKeith Packard 	 * computation is cheap enough that it seems better to
1997170178feSKeith Packard 	 * duplicate it rather than attempt to ensure some arbitrary
1998170178feSKeith Packard 	 * ordering of calls.
1999170178feSKeith Packard 	 */
2000170178feSKeith Packard 	if (edid)
2001170178feSKeith Packard 		drm_add_display_info(connector, edid);
2002170178feSKeith Packard 	else
2003170178feSKeith Packard 		drm_reset_display_info(connector);
2004170178feSKeith Packard 
2005092c367aSVille Syrjälä 	drm_update_tile_info(connector, edid);
2006092c367aSVille Syrjälä 
20075186421cSStanislav Lisovskiy 	if (connector->edid_blob_ptr) {
20085186421cSStanislav Lisovskiy 		old_edid = (const struct edid *)connector->edid_blob_ptr->data;
20095186421cSStanislav Lisovskiy 		if (old_edid) {
20105186421cSStanislav Lisovskiy 			if (!drm_edid_are_equal(edid, old_edid)) {
20115186421cSStanislav Lisovskiy 				DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Edid was changed.\n",
20125186421cSStanislav Lisovskiy 					      connector->base.id, connector->name);
20135186421cSStanislav Lisovskiy 
20145186421cSStanislav Lisovskiy 				connector->epoch_counter += 1;
20155186421cSStanislav Lisovskiy 				DRM_DEBUG_KMS("Updating change counter to %llu\n",
20165186421cSStanislav Lisovskiy 					      connector->epoch_counter);
20175186421cSStanislav Lisovskiy 			}
20185186421cSStanislav Lisovskiy 		}
20195186421cSStanislav Lisovskiy 	}
20205186421cSStanislav Lisovskiy 
202166660d4cSDave Airlie 	drm_object_property_set_value(&connector->base,
202266660d4cSDave Airlie 				      dev->mode_config.non_desktop_property,
202366660d4cSDave Airlie 				      connector->display_info.non_desktop);
202466660d4cSDave Airlie 
202552217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
202652217195SDaniel Vetter 					       &connector->edid_blob_ptr,
202752217195SDaniel Vetter 	                                       size,
202852217195SDaniel Vetter 	                                       edid,
202952217195SDaniel Vetter 	                                       &connector->base,
203052217195SDaniel Vetter 	                                       dev->mode_config.edid_property);
20312de3a078SManasi Navare 	if (ret)
203252217195SDaniel Vetter 		return ret;
20332de3a078SManasi Navare 	return drm_connector_set_tile_property(connector);
203452217195SDaniel Vetter }
2035c555f023SDaniel Vetter EXPORT_SYMBOL(drm_connector_update_edid_property);
203652217195SDaniel Vetter 
203740ee6fbeSManasi Navare /**
203897e14fbeSDaniel Vetter  * drm_connector_set_link_status_property - Set link status property of a connector
203940ee6fbeSManasi Navare  * @connector: drm connector
204040ee6fbeSManasi Navare  * @link_status: new value of link status property (0: Good, 1: Bad)
204140ee6fbeSManasi Navare  *
204240ee6fbeSManasi Navare  * In usual working scenario, this link status property will always be set to
204340ee6fbeSManasi Navare  * "GOOD". If something fails during or after a mode set, the kernel driver
204440ee6fbeSManasi Navare  * may set this link status property to "BAD". The caller then needs to send a
204540ee6fbeSManasi Navare  * hotplug uevent for userspace to re-check the valid modes through
204640ee6fbeSManasi Navare  * GET_CONNECTOR_IOCTL and retry modeset.
204740ee6fbeSManasi Navare  *
204840ee6fbeSManasi Navare  * Note: Drivers cannot rely on userspace to support this property and
204940ee6fbeSManasi Navare  * issue a modeset. As such, they may choose to handle issues (like
205040ee6fbeSManasi Navare  * re-training a link) without userspace's intervention.
205140ee6fbeSManasi Navare  *
205240ee6fbeSManasi Navare  * The reason for adding this property is to handle link training failures, but
205340ee6fbeSManasi Navare  * it is not limited to DP or link training. For example, if we implement
205440ee6fbeSManasi Navare  * asynchronous setcrtc, this property can be used to report any failures in that.
205540ee6fbeSManasi Navare  */
205697e14fbeSDaniel Vetter void drm_connector_set_link_status_property(struct drm_connector *connector,
205740ee6fbeSManasi Navare 					    uint64_t link_status)
205840ee6fbeSManasi Navare {
205940ee6fbeSManasi Navare 	struct drm_device *dev = connector->dev;
206040ee6fbeSManasi Navare 
206140ee6fbeSManasi Navare 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
206240ee6fbeSManasi Navare 	connector->state->link_status = link_status;
206340ee6fbeSManasi Navare 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
206440ee6fbeSManasi Navare }
206597e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_link_status_property);
206640ee6fbeSManasi Navare 
20678d70f395SHans de Goede /**
206847e22ff1SRadhakrishna Sripada  * drm_connector_attach_max_bpc_property - attach "max bpc" property
206947e22ff1SRadhakrishna Sripada  * @connector: connector to attach max bpc property on.
207047e22ff1SRadhakrishna Sripada  * @min: The minimum bit depth supported by the connector.
207147e22ff1SRadhakrishna Sripada  * @max: The maximum bit depth supported by the connector.
207247e22ff1SRadhakrishna Sripada  *
207347e22ff1SRadhakrishna Sripada  * This is used to add support for limiting the bit depth on a connector.
207447e22ff1SRadhakrishna Sripada  *
207547e22ff1SRadhakrishna Sripada  * Returns:
207647e22ff1SRadhakrishna Sripada  * Zero on success, negative errno on failure.
207747e22ff1SRadhakrishna Sripada  */
207847e22ff1SRadhakrishna Sripada int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
207947e22ff1SRadhakrishna Sripada 					  int min, int max)
208047e22ff1SRadhakrishna Sripada {
208147e22ff1SRadhakrishna Sripada 	struct drm_device *dev = connector->dev;
208247e22ff1SRadhakrishna Sripada 	struct drm_property *prop;
208347e22ff1SRadhakrishna Sripada 
208447e22ff1SRadhakrishna Sripada 	prop = connector->max_bpc_property;
208547e22ff1SRadhakrishna Sripada 	if (!prop) {
208647e22ff1SRadhakrishna Sripada 		prop = drm_property_create_range(dev, 0, "max bpc", min, max);
208747e22ff1SRadhakrishna Sripada 		if (!prop)
208847e22ff1SRadhakrishna Sripada 			return -ENOMEM;
208947e22ff1SRadhakrishna Sripada 
209047e22ff1SRadhakrishna Sripada 		connector->max_bpc_property = prop;
209147e22ff1SRadhakrishna Sripada 	}
209247e22ff1SRadhakrishna Sripada 
209347e22ff1SRadhakrishna Sripada 	drm_object_attach_property(&connector->base, prop, max);
209447e22ff1SRadhakrishna Sripada 	connector->state->max_requested_bpc = max;
209547e22ff1SRadhakrishna Sripada 	connector->state->max_bpc = max;
209647e22ff1SRadhakrishna Sripada 
209747e22ff1SRadhakrishna Sripada 	return 0;
209847e22ff1SRadhakrishna Sripada }
209947e22ff1SRadhakrishna Sripada EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
210047e22ff1SRadhakrishna Sripada 
210147e22ff1SRadhakrishna Sripada /**
2102ba1b0f6cSNicholas Kazlauskas  * drm_connector_set_vrr_capable_property - sets the variable refresh rate
2103ba1b0f6cSNicholas Kazlauskas  * capable property for a connector
2104ba1b0f6cSNicholas Kazlauskas  * @connector: drm connector
2105ba1b0f6cSNicholas Kazlauskas  * @capable: True if the connector is variable refresh rate capable
2106ba1b0f6cSNicholas Kazlauskas  *
2107ba1b0f6cSNicholas Kazlauskas  * Should be used by atomic drivers to update the indicated support for
2108ba1b0f6cSNicholas Kazlauskas  * variable refresh rate over a connector.
2109ba1b0f6cSNicholas Kazlauskas  */
2110ba1b0f6cSNicholas Kazlauskas void drm_connector_set_vrr_capable_property(
2111ba1b0f6cSNicholas Kazlauskas 		struct drm_connector *connector, bool capable)
2112ba1b0f6cSNicholas Kazlauskas {
2113ba1b0f6cSNicholas Kazlauskas 	drm_object_property_set_value(&connector->base,
2114ba1b0f6cSNicholas Kazlauskas 				      connector->vrr_capable_property,
2115ba1b0f6cSNicholas Kazlauskas 				      capable);
2116ba1b0f6cSNicholas Kazlauskas }
2117ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
2118ba1b0f6cSNicholas Kazlauskas 
2119ba1b0f6cSNicholas Kazlauskas /**
212084e543bcSAntonio Borneo  * drm_connector_set_panel_orientation - sets the connector's panel_orientation
212169654c63SDerek Basehore  * @connector: connector for which to set the panel-orientation property.
212269654c63SDerek Basehore  * @panel_orientation: drm_panel_orientation value to set
21238d70f395SHans de Goede  *
212469654c63SDerek Basehore  * This function sets the connector's panel_orientation and attaches
212569654c63SDerek Basehore  * a "panel orientation" property to the connector.
21268d70f395SHans de Goede  *
212769654c63SDerek Basehore  * Calling this function on a connector where the panel_orientation has
212869654c63SDerek Basehore  * already been set is a no-op (e.g. the orientation has been overridden with
212969654c63SDerek Basehore  * a kernel commandline option).
213069654c63SDerek Basehore  *
213169654c63SDerek Basehore  * It is allowed to call this function with a panel_orientation of
213269654c63SDerek Basehore  * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
21338d70f395SHans de Goede  *
21348d70f395SHans de Goede  * Returns:
21358d70f395SHans de Goede  * Zero on success, negative errno on failure.
21368d70f395SHans de Goede  */
213769654c63SDerek Basehore int drm_connector_set_panel_orientation(
213869654c63SDerek Basehore 	struct drm_connector *connector,
213969654c63SDerek Basehore 	enum drm_panel_orientation panel_orientation)
21408d70f395SHans de Goede {
21418d70f395SHans de Goede 	struct drm_device *dev = connector->dev;
21428d70f395SHans de Goede 	struct drm_display_info *info = &connector->display_info;
21438d70f395SHans de Goede 	struct drm_property *prop;
21448d70f395SHans de Goede 
214569654c63SDerek Basehore 	/* Already set? */
214669654c63SDerek Basehore 	if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
21478d70f395SHans de Goede 		return 0;
21488d70f395SHans de Goede 
214969654c63SDerek Basehore 	/* Don't attach the property if the orientation is unknown */
215069654c63SDerek Basehore 	if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
215169654c63SDerek Basehore 		return 0;
215269654c63SDerek Basehore 
215369654c63SDerek Basehore 	info->panel_orientation = panel_orientation;
215469654c63SDerek Basehore 
21558d70f395SHans de Goede 	prop = dev->mode_config.panel_orientation_property;
21568d70f395SHans de Goede 	if (!prop) {
21578d70f395SHans de Goede 		prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
21588d70f395SHans de Goede 				"panel orientation",
21598d70f395SHans de Goede 				drm_panel_orientation_enum_list,
21608d70f395SHans de Goede 				ARRAY_SIZE(drm_panel_orientation_enum_list));
21618d70f395SHans de Goede 		if (!prop)
21628d70f395SHans de Goede 			return -ENOMEM;
21638d70f395SHans de Goede 
21648d70f395SHans de Goede 		dev->mode_config.panel_orientation_property = prop;
21658d70f395SHans de Goede 	}
21668d70f395SHans de Goede 
21678d70f395SHans de Goede 	drm_object_attach_property(&connector->base, prop,
21688d70f395SHans de Goede 				   info->panel_orientation);
21698d70f395SHans de Goede 	return 0;
21708d70f395SHans de Goede }
217169654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation);
217269654c63SDerek Basehore 
217369654c63SDerek Basehore /**
217469654c63SDerek Basehore  * drm_connector_set_panel_orientation_with_quirk -
217584e543bcSAntonio Borneo  *	set the connector's panel_orientation after checking for quirks
217669654c63SDerek Basehore  * @connector: connector for which to init the panel-orientation property.
217769654c63SDerek Basehore  * @panel_orientation: drm_panel_orientation value to set
217869654c63SDerek Basehore  * @width: width in pixels of the panel, used for panel quirk detection
217969654c63SDerek Basehore  * @height: height in pixels of the panel, used for panel quirk detection
218069654c63SDerek Basehore  *
218169654c63SDerek Basehore  * Like drm_connector_set_panel_orientation(), but with a check for platform
218269654c63SDerek Basehore  * specific (e.g. DMI based) quirks overriding the passed in panel_orientation.
218369654c63SDerek Basehore  *
218469654c63SDerek Basehore  * Returns:
218569654c63SDerek Basehore  * Zero on success, negative errno on failure.
218669654c63SDerek Basehore  */
218769654c63SDerek Basehore int drm_connector_set_panel_orientation_with_quirk(
218869654c63SDerek Basehore 	struct drm_connector *connector,
218969654c63SDerek Basehore 	enum drm_panel_orientation panel_orientation,
219069654c63SDerek Basehore 	int width, int height)
219169654c63SDerek Basehore {
219269654c63SDerek Basehore 	int orientation_quirk;
219369654c63SDerek Basehore 
219469654c63SDerek Basehore 	orientation_quirk = drm_get_panel_orientation_quirk(width, height);
219569654c63SDerek Basehore 	if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
219669654c63SDerek Basehore 		panel_orientation = orientation_quirk;
219769654c63SDerek Basehore 
219869654c63SDerek Basehore 	return drm_connector_set_panel_orientation(connector,
219969654c63SDerek Basehore 						   panel_orientation);
220069654c63SDerek Basehore }
220169654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
22028d70f395SHans de Goede 
220397e14fbeSDaniel Vetter int drm_connector_set_obj_prop(struct drm_mode_object *obj,
220452217195SDaniel Vetter 				    struct drm_property *property,
220552217195SDaniel Vetter 				    uint64_t value)
220652217195SDaniel Vetter {
220752217195SDaniel Vetter 	int ret = -EINVAL;
220852217195SDaniel Vetter 	struct drm_connector *connector = obj_to_connector(obj);
220952217195SDaniel Vetter 
221052217195SDaniel Vetter 	/* Do DPMS ourselves */
221152217195SDaniel Vetter 	if (property == connector->dev->mode_config.dpms_property) {
221252217195SDaniel Vetter 		ret = (*connector->funcs->dpms)(connector, (int)value);
221352217195SDaniel Vetter 	} else if (connector->funcs->set_property)
221452217195SDaniel Vetter 		ret = connector->funcs->set_property(connector, property, value);
221552217195SDaniel Vetter 
2216144a7999SDaniel Vetter 	if (!ret)
221752217195SDaniel Vetter 		drm_object_property_set_value(&connector->base, property, value);
221852217195SDaniel Vetter 	return ret;
221952217195SDaniel Vetter }
222052217195SDaniel Vetter 
222197e14fbeSDaniel Vetter int drm_connector_property_set_ioctl(struct drm_device *dev,
222252217195SDaniel Vetter 				     void *data, struct drm_file *file_priv)
222352217195SDaniel Vetter {
222452217195SDaniel Vetter 	struct drm_mode_connector_set_property *conn_set_prop = data;
222552217195SDaniel Vetter 	struct drm_mode_obj_set_property obj_set_prop = {
222652217195SDaniel Vetter 		.value = conn_set_prop->value,
222752217195SDaniel Vetter 		.prop_id = conn_set_prop->prop_id,
222852217195SDaniel Vetter 		.obj_id = conn_set_prop->connector_id,
222952217195SDaniel Vetter 		.obj_type = DRM_MODE_OBJECT_CONNECTOR
223052217195SDaniel Vetter 	};
223152217195SDaniel Vetter 
223252217195SDaniel Vetter 	/* It does all the locking and checking we need */
223352217195SDaniel Vetter 	return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
223452217195SDaniel Vetter }
223552217195SDaniel Vetter 
223652217195SDaniel Vetter static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
223752217195SDaniel Vetter {
223852217195SDaniel Vetter 	/* For atomic drivers only state objects are synchronously updated and
223952217195SDaniel Vetter 	 * protected by modeset locks, so check those first. */
224052217195SDaniel Vetter 	if (connector->state)
224152217195SDaniel Vetter 		return connector->state->best_encoder;
224252217195SDaniel Vetter 	return connector->encoder;
224352217195SDaniel Vetter }
224452217195SDaniel Vetter 
2245c3ff0cdbSAnkit Nautiyal static bool
2246c3ff0cdbSAnkit Nautiyal drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
2247c3ff0cdbSAnkit Nautiyal 			     const struct list_head *export_list,
224852217195SDaniel Vetter 			     const struct drm_file *file_priv)
224952217195SDaniel Vetter {
225052217195SDaniel Vetter 	/*
225152217195SDaniel Vetter 	 * If user-space hasn't configured the driver to expose the stereo 3D
225252217195SDaniel Vetter 	 * modes, don't expose them.
225352217195SDaniel Vetter 	 */
225452217195SDaniel Vetter 	if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
225552217195SDaniel Vetter 		return false;
2256c3ff0cdbSAnkit Nautiyal 	/*
2257c3ff0cdbSAnkit Nautiyal 	 * If user-space hasn't configured the driver to expose the modes
2258c3ff0cdbSAnkit Nautiyal 	 * with aspect-ratio, don't expose them. However if such a mode
2259c3ff0cdbSAnkit Nautiyal 	 * is unique, let it be exposed, but reset the aspect-ratio flags
2260c3ff0cdbSAnkit Nautiyal 	 * while preparing the list of user-modes.
2261c3ff0cdbSAnkit Nautiyal 	 */
2262c3ff0cdbSAnkit Nautiyal 	if (!file_priv->aspect_ratio_allowed) {
2263c3ff0cdbSAnkit Nautiyal 		struct drm_display_mode *mode_itr;
2264c3ff0cdbSAnkit Nautiyal 
2265c3ff0cdbSAnkit Nautiyal 		list_for_each_entry(mode_itr, export_list, export_head)
2266c3ff0cdbSAnkit Nautiyal 			if (drm_mode_match(mode_itr, mode,
2267c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_TIMINGS |
2268c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_CLOCK |
2269c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_FLAGS |
2270c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_3D_FLAGS))
2271c3ff0cdbSAnkit Nautiyal 				return false;
2272c3ff0cdbSAnkit Nautiyal 	}
227352217195SDaniel Vetter 
227452217195SDaniel Vetter 	return true;
227552217195SDaniel Vetter }
227652217195SDaniel Vetter 
227752217195SDaniel Vetter int drm_mode_getconnector(struct drm_device *dev, void *data,
227852217195SDaniel Vetter 			  struct drm_file *file_priv)
227952217195SDaniel Vetter {
228052217195SDaniel Vetter 	struct drm_mode_get_connector *out_resp = data;
228152217195SDaniel Vetter 	struct drm_connector *connector;
228252217195SDaniel Vetter 	struct drm_encoder *encoder;
228352217195SDaniel Vetter 	struct drm_display_mode *mode;
228452217195SDaniel Vetter 	int mode_count = 0;
228552217195SDaniel Vetter 	int encoders_count = 0;
228652217195SDaniel Vetter 	int ret = 0;
228752217195SDaniel Vetter 	int copied = 0;
228852217195SDaniel Vetter 	struct drm_mode_modeinfo u_mode;
228952217195SDaniel Vetter 	struct drm_mode_modeinfo __user *mode_ptr;
229052217195SDaniel Vetter 	uint32_t __user *encoder_ptr;
2291c3ff0cdbSAnkit Nautiyal 	LIST_HEAD(export_list);
229252217195SDaniel Vetter 
229352217195SDaniel Vetter 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
229469fdf420SChris Wilson 		return -EOPNOTSUPP;
229552217195SDaniel Vetter 
229652217195SDaniel Vetter 	memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
229752217195SDaniel Vetter 
2298418da172SKeith Packard 	connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
229991eefc05SDaniel Vetter 	if (!connector)
230091eefc05SDaniel Vetter 		return -ENOENT;
230152217195SDaniel Vetter 
230262afb4adSJosé Roberto de Souza 	encoders_count = hweight32(connector->possible_encoders);
230391eefc05SDaniel Vetter 
230491eefc05SDaniel Vetter 	if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
230591eefc05SDaniel Vetter 		copied = 0;
230691eefc05SDaniel Vetter 		encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
230783aefbb8SVille Syrjälä 
230862afb4adSJosé Roberto de Souza 		drm_connector_for_each_possible_encoder(connector, encoder) {
230983aefbb8SVille Syrjälä 			if (put_user(encoder->base.id, encoder_ptr + copied)) {
231091eefc05SDaniel Vetter 				ret = -EFAULT;
2311e94ac351SDaniel Vetter 				goto out;
231291eefc05SDaniel Vetter 			}
231391eefc05SDaniel Vetter 			copied++;
231491eefc05SDaniel Vetter 		}
231591eefc05SDaniel Vetter 	}
231691eefc05SDaniel Vetter 	out_resp->count_encoders = encoders_count;
231791eefc05SDaniel Vetter 
231891eefc05SDaniel Vetter 	out_resp->connector_id = connector->base.id;
231991eefc05SDaniel Vetter 	out_resp->connector_type = connector->connector_type;
232091eefc05SDaniel Vetter 	out_resp->connector_type_id = connector->connector_type_id;
232191eefc05SDaniel Vetter 
232291eefc05SDaniel Vetter 	mutex_lock(&dev->mode_config.mutex);
232391eefc05SDaniel Vetter 	if (out_resp->count_modes == 0) {
232491eefc05SDaniel Vetter 		connector->funcs->fill_modes(connector,
232591eefc05SDaniel Vetter 					     dev->mode_config.max_width,
232691eefc05SDaniel Vetter 					     dev->mode_config.max_height);
232791eefc05SDaniel Vetter 	}
232891eefc05SDaniel Vetter 
232991eefc05SDaniel Vetter 	out_resp->mm_width = connector->display_info.width_mm;
233091eefc05SDaniel Vetter 	out_resp->mm_height = connector->display_info.height_mm;
233191eefc05SDaniel Vetter 	out_resp->subpixel = connector->display_info.subpixel_order;
233291eefc05SDaniel Vetter 	out_resp->connection = connector->status;
233391eefc05SDaniel Vetter 
233491eefc05SDaniel Vetter 	/* delayed so we get modes regardless of pre-fill_modes state */
233591eefc05SDaniel Vetter 	list_for_each_entry(mode, &connector->modes, head)
2336c3ff0cdbSAnkit Nautiyal 		if (drm_mode_expose_to_userspace(mode, &export_list,
2337c3ff0cdbSAnkit Nautiyal 						 file_priv)) {
2338c3ff0cdbSAnkit Nautiyal 			list_add_tail(&mode->export_head, &export_list);
233991eefc05SDaniel Vetter 			mode_count++;
2340c3ff0cdbSAnkit Nautiyal 		}
234191eefc05SDaniel Vetter 
234252217195SDaniel Vetter 	/*
234352217195SDaniel Vetter 	 * This ioctl is called twice, once to determine how much space is
234452217195SDaniel Vetter 	 * needed, and the 2nd time to fill it.
2345c3ff0cdbSAnkit Nautiyal 	 * The modes that need to be exposed to the user are maintained in the
2346c3ff0cdbSAnkit Nautiyal 	 * 'export_list'. When the ioctl is called first time to determine the,
2347c3ff0cdbSAnkit Nautiyal 	 * space, the export_list gets filled, to find the no.of modes. In the
2348c3ff0cdbSAnkit Nautiyal 	 * 2nd time, the user modes are filled, one by one from the export_list.
234952217195SDaniel Vetter 	 */
235052217195SDaniel Vetter 	if ((out_resp->count_modes >= mode_count) && mode_count) {
235152217195SDaniel Vetter 		copied = 0;
235252217195SDaniel Vetter 		mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
2353c3ff0cdbSAnkit Nautiyal 		list_for_each_entry(mode, &export_list, export_head) {
235452217195SDaniel Vetter 			drm_mode_convert_to_umode(&u_mode, mode);
2355c3ff0cdbSAnkit Nautiyal 			/*
2356c3ff0cdbSAnkit Nautiyal 			 * Reset aspect ratio flags of user-mode, if modes with
2357c3ff0cdbSAnkit Nautiyal 			 * aspect-ratio are not supported.
2358c3ff0cdbSAnkit Nautiyal 			 */
2359c3ff0cdbSAnkit Nautiyal 			if (!file_priv->aspect_ratio_allowed)
2360c3ff0cdbSAnkit Nautiyal 				u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
236152217195SDaniel Vetter 			if (copy_to_user(mode_ptr + copied,
236252217195SDaniel Vetter 					 &u_mode, sizeof(u_mode))) {
236352217195SDaniel Vetter 				ret = -EFAULT;
2364e94ac351SDaniel Vetter 				mutex_unlock(&dev->mode_config.mutex);
2365e94ac351SDaniel Vetter 
236652217195SDaniel Vetter 				goto out;
236752217195SDaniel Vetter 			}
236852217195SDaniel Vetter 			copied++;
236952217195SDaniel Vetter 		}
237052217195SDaniel Vetter 	}
237152217195SDaniel Vetter 	out_resp->count_modes = mode_count;
237252217195SDaniel Vetter 	mutex_unlock(&dev->mode_config.mutex);
2373e94ac351SDaniel Vetter 
2374e94ac351SDaniel Vetter 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2375e94ac351SDaniel Vetter 	encoder = drm_connector_get_encoder(connector);
2376e94ac351SDaniel Vetter 	if (encoder)
2377e94ac351SDaniel Vetter 		out_resp->encoder_id = encoder->base.id;
2378e94ac351SDaniel Vetter 	else
2379e94ac351SDaniel Vetter 		out_resp->encoder_id = 0;
2380e94ac351SDaniel Vetter 
2381e94ac351SDaniel Vetter 	/* Only grab properties after probing, to make sure EDID and other
2382e94ac351SDaniel Vetter 	 * properties reflect the latest status. */
2383e94ac351SDaniel Vetter 	ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
2384e94ac351SDaniel Vetter 			(uint32_t __user *)(unsigned long)(out_resp->props_ptr),
2385e94ac351SDaniel Vetter 			(uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
2386e94ac351SDaniel Vetter 			&out_resp->count_props);
2387e94ac351SDaniel Vetter 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
2388e94ac351SDaniel Vetter 
2389e94ac351SDaniel Vetter out:
2390ad093607SThierry Reding 	drm_connector_put(connector);
239152217195SDaniel Vetter 
239252217195SDaniel Vetter 	return ret;
239352217195SDaniel Vetter }
239452217195SDaniel Vetter 
23959498c19bSDaniel Vetter 
23969498c19bSDaniel Vetter /**
23979498c19bSDaniel Vetter  * DOC: Tile group
23989498c19bSDaniel Vetter  *
23999498c19bSDaniel Vetter  * Tile groups are used to represent tiled monitors with a unique integer
24009498c19bSDaniel Vetter  * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
24019498c19bSDaniel Vetter  * we store this in a tile group, so we have a common identifier for all tiles
24029498c19bSDaniel Vetter  * in a monitor group. The property is called "TILE". Drivers can manage tile
24039498c19bSDaniel Vetter  * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
24049498c19bSDaniel Vetter  * drm_mode_get_tile_group(). But this is only needed for internal panels where
24059498c19bSDaniel Vetter  * the tile group information is exposed through a non-standard way.
24069498c19bSDaniel Vetter  */
24079498c19bSDaniel Vetter 
24089498c19bSDaniel Vetter static void drm_tile_group_free(struct kref *kref)
24099498c19bSDaniel Vetter {
24109498c19bSDaniel Vetter 	struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
24119498c19bSDaniel Vetter 	struct drm_device *dev = tg->dev;
2412*948de842SSuraj Upadhyay 
24139498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
24149498c19bSDaniel Vetter 	idr_remove(&dev->mode_config.tile_idr, tg->id);
24159498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
24169498c19bSDaniel Vetter 	kfree(tg);
24179498c19bSDaniel Vetter }
24189498c19bSDaniel Vetter 
24199498c19bSDaniel Vetter /**
24209498c19bSDaniel Vetter  * drm_mode_put_tile_group - drop a reference to a tile group.
24219498c19bSDaniel Vetter  * @dev: DRM device
24229498c19bSDaniel Vetter  * @tg: tile group to drop reference to.
24239498c19bSDaniel Vetter  *
24249498c19bSDaniel Vetter  * drop reference to tile group and free if 0.
24259498c19bSDaniel Vetter  */
24269498c19bSDaniel Vetter void drm_mode_put_tile_group(struct drm_device *dev,
24279498c19bSDaniel Vetter 			     struct drm_tile_group *tg)
24289498c19bSDaniel Vetter {
24299498c19bSDaniel Vetter 	kref_put(&tg->refcount, drm_tile_group_free);
24309498c19bSDaniel Vetter }
24319498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_put_tile_group);
24329498c19bSDaniel Vetter 
24339498c19bSDaniel Vetter /**
24349498c19bSDaniel Vetter  * drm_mode_get_tile_group - get a reference to an existing tile group
24359498c19bSDaniel Vetter  * @dev: DRM device
24369498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
24379498c19bSDaniel Vetter  *
24389498c19bSDaniel Vetter  * Use the unique bytes to get a reference to an existing tile group.
24399498c19bSDaniel Vetter  *
24409498c19bSDaniel Vetter  * RETURNS:
24419498c19bSDaniel Vetter  * tile group or NULL if not found.
24429498c19bSDaniel Vetter  */
24439498c19bSDaniel Vetter struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2444267ea759SVille Syrjälä 					       const char topology[8])
24459498c19bSDaniel Vetter {
24469498c19bSDaniel Vetter 	struct drm_tile_group *tg;
24479498c19bSDaniel Vetter 	int id;
2448*948de842SSuraj Upadhyay 
24499498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
24509498c19bSDaniel Vetter 	idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
24519498c19bSDaniel Vetter 		if (!memcmp(tg->group_data, topology, 8)) {
24529498c19bSDaniel Vetter 			if (!kref_get_unless_zero(&tg->refcount))
24539498c19bSDaniel Vetter 				tg = NULL;
24549498c19bSDaniel Vetter 			mutex_unlock(&dev->mode_config.idr_mutex);
24559498c19bSDaniel Vetter 			return tg;
24569498c19bSDaniel Vetter 		}
24579498c19bSDaniel Vetter 	}
24589498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
24599498c19bSDaniel Vetter 	return NULL;
24609498c19bSDaniel Vetter }
24619498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_get_tile_group);
24629498c19bSDaniel Vetter 
24639498c19bSDaniel Vetter /**
24649498c19bSDaniel Vetter  * drm_mode_create_tile_group - create a tile group from a displayid description
24659498c19bSDaniel Vetter  * @dev: DRM device
24669498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
24679498c19bSDaniel Vetter  *
24689498c19bSDaniel Vetter  * Create a tile group for the unique monitor, and get a unique
24699498c19bSDaniel Vetter  * identifier for the tile group.
24709498c19bSDaniel Vetter  *
24719498c19bSDaniel Vetter  * RETURNS:
2472705c8160SDan Carpenter  * new tile group or NULL.
24739498c19bSDaniel Vetter  */
24749498c19bSDaniel Vetter struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2475267ea759SVille Syrjälä 						  const char topology[8])
24769498c19bSDaniel Vetter {
24779498c19bSDaniel Vetter 	struct drm_tile_group *tg;
24789498c19bSDaniel Vetter 	int ret;
24799498c19bSDaniel Vetter 
24809498c19bSDaniel Vetter 	tg = kzalloc(sizeof(*tg), GFP_KERNEL);
24819498c19bSDaniel Vetter 	if (!tg)
2482705c8160SDan Carpenter 		return NULL;
24839498c19bSDaniel Vetter 
24849498c19bSDaniel Vetter 	kref_init(&tg->refcount);
24859498c19bSDaniel Vetter 	memcpy(tg->group_data, topology, 8);
24869498c19bSDaniel Vetter 	tg->dev = dev;
24879498c19bSDaniel Vetter 
24889498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
24899498c19bSDaniel Vetter 	ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
24909498c19bSDaniel Vetter 	if (ret >= 0) {
24919498c19bSDaniel Vetter 		tg->id = ret;
24929498c19bSDaniel Vetter 	} else {
24939498c19bSDaniel Vetter 		kfree(tg);
2494705c8160SDan Carpenter 		tg = NULL;
24959498c19bSDaniel Vetter 	}
24969498c19bSDaniel Vetter 
24979498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
24989498c19bSDaniel Vetter 	return tg;
24999498c19bSDaniel Vetter }
25009498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tile_group);
2501