xref: /linux/drivers/gpu/drm/drm_connector.c (revision d87fbea50b819b76f180bc8420c5f9efa0670deb)
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 
238f86c82aSSimon Ser #include <drm/drm_auth.h>
2452217195SDaniel Vetter #include <drm/drm_connector.h>
25d71d8a4bSMaxime Ripard #include <drm/drm_drv.h>
2652217195SDaniel Vetter #include <drm/drm_edid.h>
279338203cSLaurent Pinchart #include <drm/drm_encoder.h>
2899f45e32SDaniel Vetter #include <drm/drm_file.h>
29d71d8a4bSMaxime Ripard #include <drm/drm_panel.h>
30d71d8a4bSMaxime Ripard #include <drm/drm_print.h>
31334f74eeSHans de Goede #include <drm/drm_privacy_screen_consumer.h>
32968d81a6SJeykumar Sankaran #include <drm/drm_sysfs.h>
33d71d8a4bSMaxime Ripard #include <drm/drm_utils.h>
3499f45e32SDaniel Vetter 
3573289afeSVille Syrjälä #include <linux/fb.h>
3699f45e32SDaniel Vetter #include <linux/uaccess.h>
3752217195SDaniel Vetter 
3852217195SDaniel Vetter #include "drm_crtc_internal.h"
3952217195SDaniel Vetter #include "drm_internal.h"
4052217195SDaniel Vetter 
41ae2a6da8SDaniel Vetter /**
42ae2a6da8SDaniel Vetter  * DOC: overview
43ae2a6da8SDaniel Vetter  *
44ae2a6da8SDaniel Vetter  * In DRM connectors are the general abstraction for display sinks, and include
4584e543bcSAntonio Borneo  * also fixed panels or anything else that can display pixels in some form. As
46ae2a6da8SDaniel Vetter  * opposed to all other KMS objects representing hardware (like CRTC, encoder or
47ae2a6da8SDaniel Vetter  * plane abstractions) connectors can be hotplugged and unplugged at runtime.
48ad093607SThierry Reding  * Hence they are reference-counted using drm_connector_get() and
49ad093607SThierry Reding  * drm_connector_put().
50ae2a6da8SDaniel Vetter  *
51d574528aSDaniel Vetter  * KMS driver must create, initialize, register and attach at a &struct
52d574528aSDaniel Vetter  * drm_connector for each such sink. The instance is created as other KMS
53aec97460SDaniel Vetter  * objects and initialized by setting the following fields. The connector is
54aec97460SDaniel Vetter  * initialized with a call to drm_connector_init() with a pointer to the
55aec97460SDaniel Vetter  * &struct drm_connector_funcs and a connector type, and then exposed to
56aec97460SDaniel Vetter  * userspace with a call to drm_connector_register().
57ae2a6da8SDaniel Vetter  *
58ae2a6da8SDaniel Vetter  * Connectors must be attached to an encoder to be used. For devices that map
59ae2a6da8SDaniel Vetter  * connectors to encoders 1:1, the connector should be attached at
60cde4c44dSDaniel Vetter  * initialization time with a call to drm_connector_attach_encoder(). The
61d574528aSDaniel Vetter  * driver must also set the &drm_connector.encoder field to point to the
62ae2a6da8SDaniel Vetter  * attached encoder.
63ae2a6da8SDaniel Vetter  *
64ae2a6da8SDaniel Vetter  * For connectors which are not fixed (like built-in panels) the driver needs to
65ae2a6da8SDaniel Vetter  * support hotplug notifications. The simplest way to do that is by using the
66ae2a6da8SDaniel Vetter  * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
67ae2a6da8SDaniel Vetter  * hardware support for hotplug interrupts. Connectors with hardware hotplug
68ae2a6da8SDaniel Vetter  * support can instead use e.g. drm_helper_hpd_irq_event().
69ae2a6da8SDaniel Vetter  */
70ae2a6da8SDaniel Vetter 
713d3f7c1eSHans de Goede /*
723d3f7c1eSHans de Goede  * Global connector list for drm_connector_find_by_fwnode().
733d3f7c1eSHans de Goede  * Note drm_connector_[un]register() first take connector->lock and then
743d3f7c1eSHans de Goede  * take the connector_list_lock.
753d3f7c1eSHans de Goede  */
763d3f7c1eSHans de Goede static DEFINE_MUTEX(connector_list_lock);
773d3f7c1eSHans de Goede static LIST_HEAD(connector_list);
783d3f7c1eSHans de Goede 
7952217195SDaniel Vetter struct drm_conn_prop_enum_list {
8052217195SDaniel Vetter 	int type;
8152217195SDaniel Vetter 	const char *name;
8252217195SDaniel Vetter 	struct ida ida;
8352217195SDaniel Vetter };
8452217195SDaniel Vetter 
8552217195SDaniel Vetter /*
8652217195SDaniel Vetter  * Connector and encoder types.
8752217195SDaniel Vetter  */
8852217195SDaniel Vetter static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
8952217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Unknown, "Unknown" },
9052217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
9152217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
9252217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
9352217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
9452217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Composite, "Composite" },
9552217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
9652217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
9752217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Component, "Component" },
9852217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
9952217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },
10052217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
10152217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
10252217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_TV, "TV" },
10352217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_eDP, "eDP" },
10452217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
10552217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DSI, "DSI" },
10652217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DPI, "DPI" },
107935774cdSBrian Starkey 	{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
108fc06bf1dSNoralf Trønnes 	{ DRM_MODE_CONNECTOR_SPI, "SPI" },
109757e2671SNoralf Trønnes 	{ DRM_MODE_CONNECTOR_USB, "USB" },
11052217195SDaniel Vetter };
11152217195SDaniel Vetter 
11252217195SDaniel Vetter void drm_connector_ida_init(void)
11352217195SDaniel Vetter {
11452217195SDaniel Vetter 	int i;
11552217195SDaniel Vetter 
11652217195SDaniel Vetter 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
11752217195SDaniel Vetter 		ida_init(&drm_connector_enum_list[i].ida);
11852217195SDaniel Vetter }
11952217195SDaniel Vetter 
12052217195SDaniel Vetter void drm_connector_ida_destroy(void)
12152217195SDaniel Vetter {
12252217195SDaniel Vetter 	int i;
12352217195SDaniel Vetter 
12452217195SDaniel Vetter 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
12552217195SDaniel Vetter 		ida_destroy(&drm_connector_enum_list[i].ida);
12652217195SDaniel Vetter }
12752217195SDaniel Vetter 
12852217195SDaniel Vetter /**
129b35f90f2SLaurent Pinchart  * drm_get_connector_type_name - return a string for connector type
130b35f90f2SLaurent Pinchart  * @type: The connector type (DRM_MODE_CONNECTOR_*)
131b35f90f2SLaurent Pinchart  *
132b35f90f2SLaurent Pinchart  * Returns: the name of the connector type, or NULL if the type is not valid.
133b35f90f2SLaurent Pinchart  */
134b35f90f2SLaurent Pinchart const char *drm_get_connector_type_name(unsigned int type)
135b35f90f2SLaurent Pinchart {
136b35f90f2SLaurent Pinchart 	if (type < ARRAY_SIZE(drm_connector_enum_list))
137b35f90f2SLaurent Pinchart 		return drm_connector_enum_list[type].name;
138b35f90f2SLaurent Pinchart 
139b35f90f2SLaurent Pinchart 	return NULL;
140b35f90f2SLaurent Pinchart }
141b35f90f2SLaurent Pinchart EXPORT_SYMBOL(drm_get_connector_type_name);
142b35f90f2SLaurent Pinchart 
143b35f90f2SLaurent Pinchart /**
14452217195SDaniel Vetter  * drm_connector_get_cmdline_mode - reads the user's cmdline mode
14584e543bcSAntonio Borneo  * @connector: connector to query
14652217195SDaniel Vetter  *
147ae2a6da8SDaniel Vetter  * The kernel supports per-connector configuration of its consoles through
14852217195SDaniel Vetter  * use of the video= parameter. This function parses that option and
14952217195SDaniel Vetter  * extracts the user's specified mode (or enable/disable status) for a
15052217195SDaniel Vetter  * particular connector. This is typically only used during the early fbdev
15152217195SDaniel Vetter  * setup.
15252217195SDaniel Vetter  */
15352217195SDaniel Vetter static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
15452217195SDaniel Vetter {
15552217195SDaniel Vetter 	struct drm_cmdline_mode *mode = &connector->cmdline_mode;
15652217195SDaniel Vetter 	char *option = NULL;
15752217195SDaniel Vetter 
15852217195SDaniel Vetter 	if (fb_get_options(connector->name, &option))
15952217195SDaniel Vetter 		return;
16052217195SDaniel Vetter 
16152217195SDaniel Vetter 	if (!drm_mode_parse_command_line_for_connector(option,
16252217195SDaniel Vetter 						       connector,
16352217195SDaniel Vetter 						       mode))
16452217195SDaniel Vetter 		return;
16552217195SDaniel Vetter 
16652217195SDaniel Vetter 	if (mode->force) {
1676140cf20SJani Nikula 		DRM_INFO("forcing %s connector %s\n", connector->name,
1686140cf20SJani Nikula 			 drm_get_connector_force_name(mode->force));
16952217195SDaniel Vetter 		connector->force = mode->force;
17052217195SDaniel Vetter 	}
17152217195SDaniel Vetter 
1720980939dSHans de Goede 	if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) {
1730980939dSHans de Goede 		DRM_INFO("cmdline forces connector %s panel_orientation to %d\n",
1740980939dSHans de Goede 			 connector->name, mode->panel_orientation);
1750980939dSHans de Goede 		drm_connector_set_panel_orientation(connector,
1760980939dSHans de Goede 						    mode->panel_orientation);
1770980939dSHans de Goede 	}
1780980939dSHans de Goede 
1793aeeb13dSMaxime Ripard 	DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
18050b0946dSMaxime Ripard 		      connector->name, mode->name,
18152217195SDaniel Vetter 		      mode->xres, mode->yres,
18252217195SDaniel Vetter 		      mode->refresh_specified ? mode->refresh : 60,
18352217195SDaniel Vetter 		      mode->rb ? " reduced blanking" : "",
18452217195SDaniel Vetter 		      mode->margins ? " with margins" : "",
18552217195SDaniel Vetter 		      mode->interlace ?  " interlaced" : "");
18652217195SDaniel Vetter }
18752217195SDaniel Vetter 
18852217195SDaniel Vetter static void drm_connector_free(struct kref *kref)
18952217195SDaniel Vetter {
19052217195SDaniel Vetter 	struct drm_connector *connector =
19152217195SDaniel Vetter 		container_of(kref, struct drm_connector, base.refcount);
19252217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
19352217195SDaniel Vetter 
19452217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
19552217195SDaniel Vetter 	connector->funcs->destroy(connector);
19652217195SDaniel Vetter }
19752217195SDaniel Vetter 
198ea497bb9SDaniel Vetter void drm_connector_free_work_fn(struct work_struct *work)
199a703c550SDaniel Vetter {
200ea497bb9SDaniel Vetter 	struct drm_connector *connector, *n;
201ea497bb9SDaniel Vetter 	struct drm_device *dev =
202ea497bb9SDaniel Vetter 		container_of(work, struct drm_device, mode_config.connector_free_work);
203ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &dev->mode_config;
204ea497bb9SDaniel Vetter 	unsigned long flags;
205ea497bb9SDaniel Vetter 	struct llist_node *freed;
206a703c550SDaniel Vetter 
207ea497bb9SDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
208ea497bb9SDaniel Vetter 	freed = llist_del_all(&config->connector_free_list);
209ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
210ea497bb9SDaniel Vetter 
211ea497bb9SDaniel Vetter 	llist_for_each_entry_safe(connector, n, freed, free_node) {
212a703c550SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
213a703c550SDaniel Vetter 		connector->funcs->destroy(connector);
214a703c550SDaniel Vetter 	}
215ea497bb9SDaniel Vetter }
216a703c550SDaniel Vetter 
21752217195SDaniel Vetter /**
21852217195SDaniel Vetter  * drm_connector_init - Init a preallocated connector
21952217195SDaniel Vetter  * @dev: DRM device
22052217195SDaniel Vetter  * @connector: the connector to init
22152217195SDaniel Vetter  * @funcs: callbacks for this connector
22252217195SDaniel Vetter  * @connector_type: user visible type of the connector
22352217195SDaniel Vetter  *
22452217195SDaniel Vetter  * Initialises a preallocated connector. Connectors should be
22552217195SDaniel Vetter  * subclassed as part of driver connector objects.
22652217195SDaniel Vetter  *
22700ec947cSMaxime Ripard  * At driver unload time the driver's &drm_connector_funcs.destroy hook
22800ec947cSMaxime Ripard  * should call drm_connector_cleanup() and free the connector structure.
22900ec947cSMaxime Ripard  * The connector structure should not be allocated with devm_kzalloc().
23000ec947cSMaxime Ripard  *
23152217195SDaniel Vetter  * Returns:
23252217195SDaniel Vetter  * Zero on success, error code on failure.
23352217195SDaniel Vetter  */
23452217195SDaniel Vetter int drm_connector_init(struct drm_device *dev,
23552217195SDaniel Vetter 		       struct drm_connector *connector,
23652217195SDaniel Vetter 		       const struct drm_connector_funcs *funcs,
23752217195SDaniel Vetter 		       int connector_type)
23852217195SDaniel Vetter {
23952217195SDaniel Vetter 	struct drm_mode_config *config = &dev->mode_config;
24052217195SDaniel Vetter 	int ret;
24152217195SDaniel Vetter 	struct ida *connector_ida =
24252217195SDaniel Vetter 		&drm_connector_enum_list[connector_type].ida;
24352217195SDaniel Vetter 
244ba1f665fSHaneen Mohammed 	WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
245ba1f665fSHaneen Mohammed 		(!funcs->atomic_destroy_state ||
246ba1f665fSHaneen Mohammed 		 !funcs->atomic_duplicate_state));
247ba1f665fSHaneen Mohammed 
2482135ea7aSThierry Reding 	ret = __drm_mode_object_add(dev, &connector->base,
24952217195SDaniel Vetter 				    DRM_MODE_OBJECT_CONNECTOR,
25052217195SDaniel Vetter 				    false, drm_connector_free);
25152217195SDaniel Vetter 	if (ret)
252613051daSDaniel Vetter 		return ret;
25352217195SDaniel Vetter 
25452217195SDaniel Vetter 	connector->base.properties = &connector->properties;
25552217195SDaniel Vetter 	connector->dev = dev;
25652217195SDaniel Vetter 	connector->funcs = funcs;
25752217195SDaniel Vetter 
2582a8d3eacSVille Syrjälä 	/* connector index is used with 32bit bitmasks */
259e5d6eeeaSBo Liu 	ret = ida_alloc_max(&config->connector_ida, 31, GFP_KERNEL);
2602a8d3eacSVille Syrjälä 	if (ret < 0) {
2612a8d3eacSVille Syrjälä 		DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
2622a8d3eacSVille Syrjälä 			      drm_connector_enum_list[connector_type].name,
2632a8d3eacSVille Syrjälä 			      ret);
26452217195SDaniel Vetter 		goto out_put;
2652a8d3eacSVille Syrjälä 	}
26652217195SDaniel Vetter 	connector->index = ret;
26752217195SDaniel Vetter 	ret = 0;
26852217195SDaniel Vetter 
26952217195SDaniel Vetter 	connector->connector_type = connector_type;
27052217195SDaniel Vetter 	connector->connector_type_id =
271e5d6eeeaSBo Liu 		ida_alloc_min(connector_ida, 1, GFP_KERNEL);
27252217195SDaniel Vetter 	if (connector->connector_type_id < 0) {
27352217195SDaniel Vetter 		ret = connector->connector_type_id;
27452217195SDaniel Vetter 		goto out_put_id;
27552217195SDaniel Vetter 	}
27652217195SDaniel Vetter 	connector->name =
27752217195SDaniel Vetter 		kasprintf(GFP_KERNEL, "%s-%d",
27852217195SDaniel Vetter 			  drm_connector_enum_list[connector_type].name,
27952217195SDaniel Vetter 			  connector->connector_type_id);
28052217195SDaniel Vetter 	if (!connector->name) {
28152217195SDaniel Vetter 		ret = -ENOMEM;
28252217195SDaniel Vetter 		goto out_put_type_id;
28352217195SDaniel Vetter 	}
28452217195SDaniel Vetter 
2853d3f7c1eSHans de Goede 	INIT_LIST_HEAD(&connector->global_connector_list_entry);
28652217195SDaniel Vetter 	INIT_LIST_HEAD(&connector->probed_modes);
28752217195SDaniel Vetter 	INIT_LIST_HEAD(&connector->modes);
288e73ab00eSDaniel Vetter 	mutex_init(&connector->mutex);
28952217195SDaniel Vetter 	connector->edid_blob_ptr = NULL;
2905186421cSStanislav Lisovskiy 	connector->epoch_counter = 0;
2912de3a078SManasi Navare 	connector->tile_blob_ptr = NULL;
29252217195SDaniel Vetter 	connector->status = connector_status_unknown;
2938d70f395SHans de Goede 	connector->display_info.panel_orientation =
2948d70f395SHans de Goede 		DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
29552217195SDaniel Vetter 
29652217195SDaniel Vetter 	drm_connector_get_cmdline_mode(connector);
29752217195SDaniel Vetter 
29852217195SDaniel Vetter 	/* We should add connectors at the end to avoid upsetting the connector
299c2ce66daSBeatriz Martins de Carvalho 	 * index too much.
300c2ce66daSBeatriz Martins de Carvalho 	 */
301613051daSDaniel Vetter 	spin_lock_irq(&config->connector_list_lock);
30252217195SDaniel Vetter 	list_add_tail(&connector->head, &config->connector_list);
30352217195SDaniel Vetter 	config->num_connector++;
304613051daSDaniel Vetter 	spin_unlock_irq(&config->connector_list_lock);
30552217195SDaniel Vetter 
306935774cdSBrian Starkey 	if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
307935774cdSBrian Starkey 	    connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
3086b7e2d5cSGerd Hoffmann 		drm_connector_attach_edid_property(connector);
30952217195SDaniel Vetter 
31052217195SDaniel Vetter 	drm_object_attach_property(&connector->base,
31152217195SDaniel Vetter 				      config->dpms_property, 0);
31252217195SDaniel Vetter 
31340ee6fbeSManasi Navare 	drm_object_attach_property(&connector->base,
31440ee6fbeSManasi Navare 				   config->link_status_property,
31540ee6fbeSManasi Navare 				   0);
31640ee6fbeSManasi Navare 
31766660d4cSDave Airlie 	drm_object_attach_property(&connector->base,
31866660d4cSDave Airlie 				   config->non_desktop_property,
31966660d4cSDave Airlie 				   0);
3202de3a078SManasi Navare 	drm_object_attach_property(&connector->base,
3212de3a078SManasi Navare 				   config->tile_property,
3222de3a078SManasi Navare 				   0);
32366660d4cSDave Airlie 
32452217195SDaniel Vetter 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
32552217195SDaniel Vetter 		drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
32652217195SDaniel Vetter 	}
32752217195SDaniel Vetter 
32852217195SDaniel Vetter 	connector->debugfs_entry = NULL;
32952217195SDaniel Vetter out_put_type_id:
33052217195SDaniel Vetter 	if (ret)
331e5d6eeeaSBo Liu 		ida_free(connector_ida, connector->connector_type_id);
33252217195SDaniel Vetter out_put_id:
33352217195SDaniel Vetter 	if (ret)
334e5d6eeeaSBo Liu 		ida_free(&config->connector_ida, connector->index);
33552217195SDaniel Vetter out_put:
33652217195SDaniel Vetter 	if (ret)
33752217195SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
33852217195SDaniel Vetter 
33952217195SDaniel Vetter 	return ret;
34052217195SDaniel Vetter }
34152217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_init);
34252217195SDaniel Vetter 
34352217195SDaniel Vetter /**
344100163dfSAndrzej Pietrasiewicz  * drm_connector_init_with_ddc - Init a preallocated connector
345100163dfSAndrzej Pietrasiewicz  * @dev: DRM device
346100163dfSAndrzej Pietrasiewicz  * @connector: the connector to init
347100163dfSAndrzej Pietrasiewicz  * @funcs: callbacks for this connector
348100163dfSAndrzej Pietrasiewicz  * @connector_type: user visible type of the connector
349100163dfSAndrzej Pietrasiewicz  * @ddc: pointer to the associated ddc adapter
350100163dfSAndrzej Pietrasiewicz  *
351100163dfSAndrzej Pietrasiewicz  * Initialises a preallocated connector. Connectors should be
352100163dfSAndrzej Pietrasiewicz  * subclassed as part of driver connector objects.
353100163dfSAndrzej Pietrasiewicz  *
35400ec947cSMaxime Ripard  * At driver unload time the driver's &drm_connector_funcs.destroy hook
35500ec947cSMaxime Ripard  * should call drm_connector_cleanup() and free the connector structure.
35600ec947cSMaxime Ripard  * The connector structure should not be allocated with devm_kzalloc().
35700ec947cSMaxime Ripard  *
358100163dfSAndrzej Pietrasiewicz  * Ensures that the ddc field of the connector is correctly set.
359100163dfSAndrzej Pietrasiewicz  *
360100163dfSAndrzej Pietrasiewicz  * Returns:
361100163dfSAndrzej Pietrasiewicz  * Zero on success, error code on failure.
362100163dfSAndrzej Pietrasiewicz  */
363100163dfSAndrzej Pietrasiewicz int drm_connector_init_with_ddc(struct drm_device *dev,
364100163dfSAndrzej Pietrasiewicz 				struct drm_connector *connector,
365100163dfSAndrzej Pietrasiewicz 				const struct drm_connector_funcs *funcs,
366100163dfSAndrzej Pietrasiewicz 				int connector_type,
367100163dfSAndrzej Pietrasiewicz 				struct i2c_adapter *ddc)
368100163dfSAndrzej Pietrasiewicz {
369100163dfSAndrzej Pietrasiewicz 	int ret;
370100163dfSAndrzej Pietrasiewicz 
371100163dfSAndrzej Pietrasiewicz 	ret = drm_connector_init(dev, connector, funcs, connector_type);
372100163dfSAndrzej Pietrasiewicz 	if (ret)
373100163dfSAndrzej Pietrasiewicz 		return ret;
374100163dfSAndrzej Pietrasiewicz 
375100163dfSAndrzej Pietrasiewicz 	/* provide ddc symlink in sysfs */
376100163dfSAndrzej Pietrasiewicz 	connector->ddc = ddc;
377100163dfSAndrzej Pietrasiewicz 
378100163dfSAndrzej Pietrasiewicz 	return ret;
379100163dfSAndrzej Pietrasiewicz }
380100163dfSAndrzej Pietrasiewicz EXPORT_SYMBOL(drm_connector_init_with_ddc);
381100163dfSAndrzej Pietrasiewicz 
382100163dfSAndrzej Pietrasiewicz /**
3836b7e2d5cSGerd Hoffmann  * drm_connector_attach_edid_property - attach edid property.
3846b7e2d5cSGerd Hoffmann  * @connector: the connector
3856b7e2d5cSGerd Hoffmann  *
3866b7e2d5cSGerd Hoffmann  * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
3876b7e2d5cSGerd Hoffmann  * edid property attached by default.  This function can be used to
3886b7e2d5cSGerd Hoffmann  * explicitly enable the edid property in these cases.
3896b7e2d5cSGerd Hoffmann  */
3906b7e2d5cSGerd Hoffmann void drm_connector_attach_edid_property(struct drm_connector *connector)
3916b7e2d5cSGerd Hoffmann {
3926b7e2d5cSGerd Hoffmann 	struct drm_mode_config *config = &connector->dev->mode_config;
3936b7e2d5cSGerd Hoffmann 
3946b7e2d5cSGerd Hoffmann 	drm_object_attach_property(&connector->base,
3956b7e2d5cSGerd Hoffmann 				   config->edid_property,
3966b7e2d5cSGerd Hoffmann 				   0);
3976b7e2d5cSGerd Hoffmann }
3986b7e2d5cSGerd Hoffmann EXPORT_SYMBOL(drm_connector_attach_edid_property);
3996b7e2d5cSGerd Hoffmann 
4006b7e2d5cSGerd Hoffmann /**
401cde4c44dSDaniel Vetter  * drm_connector_attach_encoder - attach a connector to an encoder
40252217195SDaniel Vetter  * @connector: connector to attach
40352217195SDaniel Vetter  * @encoder: encoder to attach @connector to
40452217195SDaniel Vetter  *
40552217195SDaniel Vetter  * This function links up a connector to an encoder. Note that the routing
40652217195SDaniel Vetter  * restrictions between encoders and crtcs are exposed to userspace through the
40752217195SDaniel Vetter  * possible_clones and possible_crtcs bitmasks.
40852217195SDaniel Vetter  *
40952217195SDaniel Vetter  * Returns:
41052217195SDaniel Vetter  * Zero on success, negative errno on failure.
41152217195SDaniel Vetter  */
412cde4c44dSDaniel Vetter int drm_connector_attach_encoder(struct drm_connector *connector,
41352217195SDaniel Vetter 				 struct drm_encoder *encoder)
41452217195SDaniel Vetter {
41552217195SDaniel Vetter 	/*
41652217195SDaniel Vetter 	 * In the past, drivers have attempted to model the static association
41752217195SDaniel Vetter 	 * of connector to encoder in simple connector/encoder devices using a
41852217195SDaniel Vetter 	 * direct assignment of connector->encoder = encoder. This connection
41952217195SDaniel Vetter 	 * is a logical one and the responsibility of the core, so drivers are
42052217195SDaniel Vetter 	 * expected not to mess with this.
42152217195SDaniel Vetter 	 *
42252217195SDaniel Vetter 	 * Note that the error return should've been enough here, but a large
42352217195SDaniel Vetter 	 * majority of drivers ignores the return value, so add in a big WARN
42452217195SDaniel Vetter 	 * to get people's attention.
42552217195SDaniel Vetter 	 */
42652217195SDaniel Vetter 	if (WARN_ON(connector->encoder))
42752217195SDaniel Vetter 		return -EINVAL;
42852217195SDaniel Vetter 
42962afb4adSJosé Roberto de Souza 	connector->possible_encoders |= drm_encoder_mask(encoder);
43062afb4adSJosé Roberto de Souza 
43152217195SDaniel Vetter 	return 0;
43252217195SDaniel Vetter }
433cde4c44dSDaniel Vetter EXPORT_SYMBOL(drm_connector_attach_encoder);
43452217195SDaniel Vetter 
43538cb8d96SVille Syrjälä /**
43662afb4adSJosé Roberto de Souza  * drm_connector_has_possible_encoder - check if the connector and encoder are
43762afb4adSJosé Roberto de Souza  * associated with each other
43838cb8d96SVille Syrjälä  * @connector: the connector
43938cb8d96SVille Syrjälä  * @encoder: the encoder
44038cb8d96SVille Syrjälä  *
44138cb8d96SVille Syrjälä  * Returns:
44238cb8d96SVille Syrjälä  * True if @encoder is one of the possible encoders for @connector.
44338cb8d96SVille Syrjälä  */
44438cb8d96SVille Syrjälä bool drm_connector_has_possible_encoder(struct drm_connector *connector,
44538cb8d96SVille Syrjälä 					struct drm_encoder *encoder)
44638cb8d96SVille Syrjälä {
44762afb4adSJosé Roberto de Souza 	return connector->possible_encoders & drm_encoder_mask(encoder);
44838cb8d96SVille Syrjälä }
44938cb8d96SVille Syrjälä EXPORT_SYMBOL(drm_connector_has_possible_encoder);
45038cb8d96SVille Syrjälä 
45152217195SDaniel Vetter static void drm_mode_remove(struct drm_connector *connector,
45252217195SDaniel Vetter 			    struct drm_display_mode *mode)
45352217195SDaniel Vetter {
45452217195SDaniel Vetter 	list_del(&mode->head);
45552217195SDaniel Vetter 	drm_mode_destroy(connector->dev, mode);
45652217195SDaniel Vetter }
45752217195SDaniel Vetter 
45852217195SDaniel Vetter /**
45952217195SDaniel Vetter  * drm_connector_cleanup - cleans up an initialised connector
46052217195SDaniel Vetter  * @connector: connector to cleanup
46152217195SDaniel Vetter  *
46252217195SDaniel Vetter  * Cleans up the connector but doesn't free the object.
46352217195SDaniel Vetter  */
46452217195SDaniel Vetter void drm_connector_cleanup(struct drm_connector *connector)
46552217195SDaniel Vetter {
46652217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
46752217195SDaniel Vetter 	struct drm_display_mode *mode, *t;
46852217195SDaniel Vetter 
46952217195SDaniel Vetter 	/* The connector should have been removed from userspace long before
47052217195SDaniel Vetter 	 * it is finally destroyed.
47152217195SDaniel Vetter 	 */
47239b50c60SLyude Paul 	if (WARN_ON(connector->registration_state ==
47339b50c60SLyude Paul 		    DRM_CONNECTOR_REGISTERED))
47452217195SDaniel Vetter 		drm_connector_unregister(connector);
47552217195SDaniel Vetter 
476334f74eeSHans de Goede 	if (connector->privacy_screen) {
477334f74eeSHans de Goede 		drm_privacy_screen_put(connector->privacy_screen);
478334f74eeSHans de Goede 		connector->privacy_screen = NULL;
479334f74eeSHans de Goede 	}
480334f74eeSHans de Goede 
48152217195SDaniel Vetter 	if (connector->tile_group) {
48252217195SDaniel Vetter 		drm_mode_put_tile_group(dev, connector->tile_group);
48352217195SDaniel Vetter 		connector->tile_group = NULL;
48452217195SDaniel Vetter 	}
48552217195SDaniel Vetter 
48652217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
48752217195SDaniel Vetter 		drm_mode_remove(connector, mode);
48852217195SDaniel Vetter 
48952217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->modes, head)
49052217195SDaniel Vetter 		drm_mode_remove(connector, mode);
49152217195SDaniel Vetter 
492e5d6eeeaSBo Liu 	ida_free(&drm_connector_enum_list[connector->connector_type].ida,
49352217195SDaniel Vetter 			  connector->connector_type_id);
49452217195SDaniel Vetter 
495e5d6eeeaSBo Liu 	ida_free(&dev->mode_config.connector_ida, connector->index);
49652217195SDaniel Vetter 
49752217195SDaniel Vetter 	kfree(connector->display_info.bus_formats);
49852217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
49952217195SDaniel Vetter 	kfree(connector->name);
50052217195SDaniel Vetter 	connector->name = NULL;
50148c429c6SHans de Goede 	fwnode_handle_put(connector->fwnode);
50248c429c6SHans de Goede 	connector->fwnode = NULL;
503613051daSDaniel Vetter 	spin_lock_irq(&dev->mode_config.connector_list_lock);
50452217195SDaniel Vetter 	list_del(&connector->head);
50552217195SDaniel Vetter 	dev->mode_config.num_connector--;
506613051daSDaniel Vetter 	spin_unlock_irq(&dev->mode_config.connector_list_lock);
50752217195SDaniel Vetter 
50852217195SDaniel Vetter 	WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
50952217195SDaniel Vetter 	if (connector->state && connector->funcs->atomic_destroy_state)
51052217195SDaniel Vetter 		connector->funcs->atomic_destroy_state(connector,
51152217195SDaniel Vetter 						       connector->state);
51252217195SDaniel Vetter 
513e73ab00eSDaniel Vetter 	mutex_destroy(&connector->mutex);
514e73ab00eSDaniel Vetter 
51552217195SDaniel Vetter 	memset(connector, 0, sizeof(*connector));
51652217195SDaniel Vetter }
51752217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_cleanup);
51852217195SDaniel Vetter 
51952217195SDaniel Vetter /**
52052217195SDaniel Vetter  * drm_connector_register - register a connector
52152217195SDaniel Vetter  * @connector: the connector to register
52252217195SDaniel Vetter  *
52369b22f51SDaniel Vetter  * Register userspace interfaces for a connector. Only call this for connectors
52469b22f51SDaniel Vetter  * which can be hotplugged after drm_dev_register() has been called already,
52569b22f51SDaniel Vetter  * e.g. DP MST connectors. All other connectors will be registered automatically
52669b22f51SDaniel Vetter  * when calling drm_dev_register().
52752217195SDaniel Vetter  *
528*d87fbea5SMaxime Ripard  * When the connector is no longer available, callers must call
529*d87fbea5SMaxime Ripard  * drm_connector_unregister().
530*d87fbea5SMaxime Ripard  *
53152217195SDaniel Vetter  * Returns:
53252217195SDaniel Vetter  * Zero on success, error code on failure.
53352217195SDaniel Vetter  */
53452217195SDaniel Vetter int drm_connector_register(struct drm_connector *connector)
53552217195SDaniel Vetter {
536e73ab00eSDaniel Vetter 	int ret = 0;
53752217195SDaniel Vetter 
538e6e7b48bSDaniel Vetter 	if (!connector->dev->registered)
539e6e7b48bSDaniel Vetter 		return 0;
540e6e7b48bSDaniel Vetter 
541e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
54239b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
543e73ab00eSDaniel Vetter 		goto unlock;
54452217195SDaniel Vetter 
54552217195SDaniel Vetter 	ret = drm_sysfs_connector_add(connector);
54652217195SDaniel Vetter 	if (ret)
547e73ab00eSDaniel Vetter 		goto unlock;
54852217195SDaniel Vetter 
549b792e640SGreg Kroah-Hartman 	drm_debugfs_connector_add(connector);
55052217195SDaniel Vetter 
55152217195SDaniel Vetter 	if (connector->funcs->late_register) {
55252217195SDaniel Vetter 		ret = connector->funcs->late_register(connector);
55352217195SDaniel Vetter 		if (ret)
55452217195SDaniel Vetter 			goto err_debugfs;
55552217195SDaniel Vetter 	}
55652217195SDaniel Vetter 
55752217195SDaniel Vetter 	drm_mode_object_register(connector->dev, &connector->base);
55852217195SDaniel Vetter 
55939b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_REGISTERED;
560968d81a6SJeykumar Sankaran 
561968d81a6SJeykumar Sankaran 	/* Let userspace know we have a new connector */
562ad935754SSimon Ser 	drm_sysfs_connector_hotplug_event(connector);
563968d81a6SJeykumar Sankaran 
564334f74eeSHans de Goede 	if (connector->privacy_screen)
565334f74eeSHans de Goede 		drm_privacy_screen_register_notifier(connector->privacy_screen,
566334f74eeSHans de Goede 					   &connector->privacy_screen_notifier);
567334f74eeSHans de Goede 
5683d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
5693d3f7c1eSHans de Goede 	list_add_tail(&connector->global_connector_list_entry, &connector_list);
5703d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
571e73ab00eSDaniel Vetter 	goto unlock;
57252217195SDaniel Vetter 
57352217195SDaniel Vetter err_debugfs:
57452217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
57552217195SDaniel Vetter 	drm_sysfs_connector_remove(connector);
576e73ab00eSDaniel Vetter unlock:
577e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
57852217195SDaniel Vetter 	return ret;
57952217195SDaniel Vetter }
58052217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_register);
58152217195SDaniel Vetter 
58252217195SDaniel Vetter /**
58352217195SDaniel Vetter  * drm_connector_unregister - unregister a connector
58452217195SDaniel Vetter  * @connector: the connector to unregister
58552217195SDaniel Vetter  *
58669b22f51SDaniel Vetter  * Unregister userspace interfaces for a connector. Only call this for
587*d87fbea5SMaxime Ripard  * connectors which have been registered explicitly by calling
588*d87fbea5SMaxime Ripard  * drm_connector_register().
58952217195SDaniel Vetter  */
59052217195SDaniel Vetter void drm_connector_unregister(struct drm_connector *connector)
59152217195SDaniel Vetter {
592e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
59339b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
594e73ab00eSDaniel Vetter 		mutex_unlock(&connector->mutex);
59552217195SDaniel Vetter 		return;
596e73ab00eSDaniel Vetter 	}
59752217195SDaniel Vetter 
5983d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
5993d3f7c1eSHans de Goede 	list_del_init(&connector->global_connector_list_entry);
6003d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
6013d3f7c1eSHans de Goede 
602334f74eeSHans de Goede 	if (connector->privacy_screen)
603334f74eeSHans de Goede 		drm_privacy_screen_unregister_notifier(
604334f74eeSHans de Goede 					connector->privacy_screen,
605334f74eeSHans de Goede 					&connector->privacy_screen_notifier);
606334f74eeSHans de Goede 
60752217195SDaniel Vetter 	if (connector->funcs->early_unregister)
60852217195SDaniel Vetter 		connector->funcs->early_unregister(connector);
60952217195SDaniel Vetter 
61052217195SDaniel Vetter 	drm_sysfs_connector_remove(connector);
61152217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
61252217195SDaniel Vetter 
61339b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
614e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
61552217195SDaniel Vetter }
61652217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_unregister);
61752217195SDaniel Vetter 
61852217195SDaniel Vetter void drm_connector_unregister_all(struct drm_device *dev)
61952217195SDaniel Vetter {
62052217195SDaniel Vetter 	struct drm_connector *connector;
621613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
62252217195SDaniel Vetter 
623b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
624613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter)
62552217195SDaniel Vetter 		drm_connector_unregister(connector);
626b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
62752217195SDaniel Vetter }
62852217195SDaniel Vetter 
62952217195SDaniel Vetter int drm_connector_register_all(struct drm_device *dev)
63052217195SDaniel Vetter {
63152217195SDaniel Vetter 	struct drm_connector *connector;
632613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
633613051daSDaniel Vetter 	int ret = 0;
63452217195SDaniel Vetter 
635b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
636613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter) {
63752217195SDaniel Vetter 		ret = drm_connector_register(connector);
63852217195SDaniel Vetter 		if (ret)
639613051daSDaniel Vetter 			break;
64052217195SDaniel Vetter 	}
641b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
64252217195SDaniel Vetter 
643613051daSDaniel Vetter 	if (ret)
64452217195SDaniel Vetter 		drm_connector_unregister_all(dev);
64552217195SDaniel Vetter 	return ret;
64652217195SDaniel Vetter }
64752217195SDaniel Vetter 
64852217195SDaniel Vetter /**
64952217195SDaniel Vetter  * drm_get_connector_status_name - return a string for connector status
65052217195SDaniel Vetter  * @status: connector status to compute name of
65152217195SDaniel Vetter  *
65252217195SDaniel Vetter  * In contrast to the other drm_get_*_name functions this one here returns a
65352217195SDaniel Vetter  * const pointer and hence is threadsafe.
654f85d9e59SRandy Dunlap  *
655f85d9e59SRandy Dunlap  * Returns: connector status string
65652217195SDaniel Vetter  */
65752217195SDaniel Vetter const char *drm_get_connector_status_name(enum drm_connector_status status)
65852217195SDaniel Vetter {
65952217195SDaniel Vetter 	if (status == connector_status_connected)
66052217195SDaniel Vetter 		return "connected";
66152217195SDaniel Vetter 	else if (status == connector_status_disconnected)
66252217195SDaniel Vetter 		return "disconnected";
66352217195SDaniel Vetter 	else
66452217195SDaniel Vetter 		return "unknown";
66552217195SDaniel Vetter }
66652217195SDaniel Vetter EXPORT_SYMBOL(drm_get_connector_status_name);
66752217195SDaniel Vetter 
6686140cf20SJani Nikula /**
6696140cf20SJani Nikula  * drm_get_connector_force_name - return a string for connector force
6706140cf20SJani Nikula  * @force: connector force to get name of
6716140cf20SJani Nikula  *
6726140cf20SJani Nikula  * Returns: const pointer to name.
6736140cf20SJani Nikula  */
6746140cf20SJani Nikula const char *drm_get_connector_force_name(enum drm_connector_force force)
6756140cf20SJani Nikula {
6766140cf20SJani Nikula 	switch (force) {
6776140cf20SJani Nikula 	case DRM_FORCE_UNSPECIFIED:
6786140cf20SJani Nikula 		return "unspecified";
6796140cf20SJani Nikula 	case DRM_FORCE_OFF:
6806140cf20SJani Nikula 		return "off";
6816140cf20SJani Nikula 	case DRM_FORCE_ON:
6826140cf20SJani Nikula 		return "on";
6836140cf20SJani Nikula 	case DRM_FORCE_ON_DIGITAL:
6846140cf20SJani Nikula 		return "digital";
6856140cf20SJani Nikula 	default:
6866140cf20SJani Nikula 		return "unknown";
6876140cf20SJani Nikula 	}
6886140cf20SJani Nikula }
6896140cf20SJani Nikula 
690613051daSDaniel Vetter #ifdef CONFIG_LOCKDEP
691613051daSDaniel Vetter static struct lockdep_map connector_list_iter_dep_map = {
692613051daSDaniel Vetter 	.name = "drm_connector_list_iter"
693613051daSDaniel Vetter };
694613051daSDaniel Vetter #endif
695613051daSDaniel Vetter 
696613051daSDaniel Vetter /**
697b982dab1SThierry Reding  * drm_connector_list_iter_begin - initialize a connector_list iterator
698613051daSDaniel Vetter  * @dev: DRM device
699613051daSDaniel Vetter  * @iter: connector_list iterator
700613051daSDaniel Vetter  *
701d574528aSDaniel Vetter  * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
702b982dab1SThierry Reding  * must always be cleaned up again by calling drm_connector_list_iter_end().
703613051daSDaniel Vetter  * Iteration itself happens using drm_connector_list_iter_next() or
704613051daSDaniel Vetter  * drm_for_each_connector_iter().
705613051daSDaniel Vetter  */
706b982dab1SThierry Reding void drm_connector_list_iter_begin(struct drm_device *dev,
707613051daSDaniel Vetter 				   struct drm_connector_list_iter *iter)
708613051daSDaniel Vetter {
709613051daSDaniel Vetter 	iter->dev = dev;
710613051daSDaniel Vetter 	iter->conn = NULL;
711613051daSDaniel Vetter 	lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
712613051daSDaniel Vetter }
713b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_begin);
714613051daSDaniel Vetter 
715a703c550SDaniel Vetter /*
716a703c550SDaniel Vetter  * Extra-safe connector put function that works in any context. Should only be
717a703c550SDaniel Vetter  * used from the connector_iter functions, where we never really expect to
718a703c550SDaniel Vetter  * actually release the connector when dropping our final reference.
719a703c550SDaniel Vetter  */
720a703c550SDaniel Vetter static void
721ea497bb9SDaniel Vetter __drm_connector_put_safe(struct drm_connector *conn)
722a703c550SDaniel Vetter {
723ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &conn->dev->mode_config;
724ea497bb9SDaniel Vetter 
725ea497bb9SDaniel Vetter 	lockdep_assert_held(&config->connector_list_lock);
726ea497bb9SDaniel Vetter 
727ea497bb9SDaniel Vetter 	if (!refcount_dec_and_test(&conn->base.refcount.refcount))
728ea497bb9SDaniel Vetter 		return;
729ea497bb9SDaniel Vetter 
730ea497bb9SDaniel Vetter 	llist_add(&conn->free_node, &config->connector_free_list);
731ea497bb9SDaniel Vetter 	schedule_work(&config->connector_free_work);
732a703c550SDaniel Vetter }
733a703c550SDaniel Vetter 
734613051daSDaniel Vetter /**
735613051daSDaniel Vetter  * drm_connector_list_iter_next - return next connector
7364f45c778SLyude Paul  * @iter: connector_list iterator
737613051daSDaniel Vetter  *
738f85d9e59SRandy Dunlap  * Returns: the next connector for @iter, or NULL when the list walk has
739613051daSDaniel Vetter  * completed.
740613051daSDaniel Vetter  */
741613051daSDaniel Vetter struct drm_connector *
742613051daSDaniel Vetter drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
743613051daSDaniel Vetter {
744613051daSDaniel Vetter 	struct drm_connector *old_conn = iter->conn;
745613051daSDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
746613051daSDaniel Vetter 	struct list_head *lhead;
747613051daSDaniel Vetter 	unsigned long flags;
748613051daSDaniel Vetter 
749613051daSDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
750613051daSDaniel Vetter 	lhead = old_conn ? &old_conn->head : &config->connector_list;
751613051daSDaniel Vetter 
752613051daSDaniel Vetter 	do {
753613051daSDaniel Vetter 		if (lhead->next == &config->connector_list) {
754613051daSDaniel Vetter 			iter->conn = NULL;
755613051daSDaniel Vetter 			break;
756613051daSDaniel Vetter 		}
757613051daSDaniel Vetter 
758613051daSDaniel Vetter 		lhead = lhead->next;
759613051daSDaniel Vetter 		iter->conn = list_entry(lhead, struct drm_connector, head);
760613051daSDaniel Vetter 
761613051daSDaniel Vetter 		/* loop until it's not a zombie connector */
762613051daSDaniel Vetter 	} while (!kref_get_unless_zero(&iter->conn->base.refcount));
763613051daSDaniel Vetter 
764613051daSDaniel Vetter 	if (old_conn)
765ea497bb9SDaniel Vetter 		__drm_connector_put_safe(old_conn);
766ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
767613051daSDaniel Vetter 
768613051daSDaniel Vetter 	return iter->conn;
769613051daSDaniel Vetter }
770613051daSDaniel Vetter EXPORT_SYMBOL(drm_connector_list_iter_next);
771613051daSDaniel Vetter 
772613051daSDaniel Vetter /**
773b982dab1SThierry Reding  * drm_connector_list_iter_end - tear down a connector_list iterator
774613051daSDaniel Vetter  * @iter: connector_list iterator
775613051daSDaniel Vetter  *
776613051daSDaniel Vetter  * Tears down @iter and releases any resources (like &drm_connector references)
777613051daSDaniel Vetter  * acquired while walking the list. This must always be called, both when the
778613051daSDaniel Vetter  * iteration completes fully or when it was aborted without walking the entire
779613051daSDaniel Vetter  * list.
780613051daSDaniel Vetter  */
781b982dab1SThierry Reding void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
782613051daSDaniel Vetter {
783ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
784ea497bb9SDaniel Vetter 	unsigned long flags;
785ea497bb9SDaniel Vetter 
786613051daSDaniel Vetter 	iter->dev = NULL;
787ea497bb9SDaniel Vetter 	if (iter->conn) {
788ea497bb9SDaniel Vetter 		spin_lock_irqsave(&config->connector_list_lock, flags);
789ea497bb9SDaniel Vetter 		__drm_connector_put_safe(iter->conn);
790ea497bb9SDaniel Vetter 		spin_unlock_irqrestore(&config->connector_list_lock, flags);
791ea497bb9SDaniel Vetter 	}
7925facae4fSQian Cai 	lock_release(&connector_list_iter_dep_map, _RET_IP_);
793613051daSDaniel Vetter }
794b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_end);
795613051daSDaniel Vetter 
79652217195SDaniel Vetter static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
79752217195SDaniel Vetter 	{ SubPixelUnknown, "Unknown" },
79852217195SDaniel Vetter 	{ SubPixelHorizontalRGB, "Horizontal RGB" },
79952217195SDaniel Vetter 	{ SubPixelHorizontalBGR, "Horizontal BGR" },
80052217195SDaniel Vetter 	{ SubPixelVerticalRGB, "Vertical RGB" },
80152217195SDaniel Vetter 	{ SubPixelVerticalBGR, "Vertical BGR" },
80252217195SDaniel Vetter 	{ SubPixelNone, "None" },
80352217195SDaniel Vetter };
80452217195SDaniel Vetter 
80552217195SDaniel Vetter /**
80652217195SDaniel Vetter  * drm_get_subpixel_order_name - return a string for a given subpixel enum
80752217195SDaniel Vetter  * @order: enum of subpixel_order
80852217195SDaniel Vetter  *
80952217195SDaniel Vetter  * Note you could abuse this and return something out of bounds, but that
81052217195SDaniel Vetter  * would be a caller error.  No unscrubbed user data should make it here.
811f85d9e59SRandy Dunlap  *
812f85d9e59SRandy Dunlap  * Returns: string describing an enumerated subpixel property
81352217195SDaniel Vetter  */
81452217195SDaniel Vetter const char *drm_get_subpixel_order_name(enum subpixel_order order)
81552217195SDaniel Vetter {
81652217195SDaniel Vetter 	return drm_subpixel_enum_list[order].name;
81752217195SDaniel Vetter }
81852217195SDaniel Vetter EXPORT_SYMBOL(drm_get_subpixel_order_name);
81952217195SDaniel Vetter 
82052217195SDaniel Vetter static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
82152217195SDaniel Vetter 	{ DRM_MODE_DPMS_ON, "On" },
82252217195SDaniel Vetter 	{ DRM_MODE_DPMS_STANDBY, "Standby" },
82352217195SDaniel Vetter 	{ DRM_MODE_DPMS_SUSPEND, "Suspend" },
82452217195SDaniel Vetter 	{ DRM_MODE_DPMS_OFF, "Off" }
82552217195SDaniel Vetter };
82652217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
82752217195SDaniel Vetter 
82840ee6fbeSManasi Navare static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
82940ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_GOOD, "Good" },
83040ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_BAD, "Bad" },
83140ee6fbeSManasi Navare };
83240ee6fbeSManasi Navare 
833b3c6c8bfSDaniel Vetter /**
834b3c6c8bfSDaniel Vetter  * drm_display_info_set_bus_formats - set the supported bus formats
835b3c6c8bfSDaniel Vetter  * @info: display info to store bus formats in
836b3c6c8bfSDaniel Vetter  * @formats: array containing the supported bus formats
837b3c6c8bfSDaniel Vetter  * @num_formats: the number of entries in the fmts array
838b3c6c8bfSDaniel Vetter  *
839b3c6c8bfSDaniel Vetter  * Store the supported bus formats in display info structure.
840b3c6c8bfSDaniel Vetter  * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
841b3c6c8bfSDaniel Vetter  * a full list of available formats.
842f85d9e59SRandy Dunlap  *
843f85d9e59SRandy Dunlap  * Returns:
844f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
845b3c6c8bfSDaniel Vetter  */
846b3c6c8bfSDaniel Vetter int drm_display_info_set_bus_formats(struct drm_display_info *info,
847b3c6c8bfSDaniel Vetter 				     const u32 *formats,
848b3c6c8bfSDaniel Vetter 				     unsigned int num_formats)
849b3c6c8bfSDaniel Vetter {
850b3c6c8bfSDaniel Vetter 	u32 *fmts = NULL;
851b3c6c8bfSDaniel Vetter 
852b3c6c8bfSDaniel Vetter 	if (!formats && num_formats)
853b3c6c8bfSDaniel Vetter 		return -EINVAL;
854b3c6c8bfSDaniel Vetter 
855b3c6c8bfSDaniel Vetter 	if (formats && num_formats) {
856b3c6c8bfSDaniel Vetter 		fmts = kmemdup(formats, sizeof(*formats) * num_formats,
857b3c6c8bfSDaniel Vetter 			       GFP_KERNEL);
858b3c6c8bfSDaniel Vetter 		if (!fmts)
859b3c6c8bfSDaniel Vetter 			return -ENOMEM;
860b3c6c8bfSDaniel Vetter 	}
861b3c6c8bfSDaniel Vetter 
862b3c6c8bfSDaniel Vetter 	kfree(info->bus_formats);
863b3c6c8bfSDaniel Vetter 	info->bus_formats = fmts;
864b3c6c8bfSDaniel Vetter 	info->num_bus_formats = num_formats;
865b3c6c8bfSDaniel Vetter 
866b3c6c8bfSDaniel Vetter 	return 0;
867b3c6c8bfSDaniel Vetter }
868b3c6c8bfSDaniel Vetter EXPORT_SYMBOL(drm_display_info_set_bus_formats);
869b3c6c8bfSDaniel Vetter 
87052217195SDaniel Vetter /* Optional connector properties. */
87152217195SDaniel Vetter static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
87252217195SDaniel Vetter 	{ DRM_MODE_SCALE_NONE, "None" },
87352217195SDaniel Vetter 	{ DRM_MODE_SCALE_FULLSCREEN, "Full" },
87452217195SDaniel Vetter 	{ DRM_MODE_SCALE_CENTER, "Center" },
87552217195SDaniel Vetter 	{ DRM_MODE_SCALE_ASPECT, "Full aspect" },
87652217195SDaniel Vetter };
87752217195SDaniel Vetter 
87852217195SDaniel Vetter static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
87952217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
88052217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
88152217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
88252217195SDaniel Vetter };
88352217195SDaniel Vetter 
88450525c33SStanislav Lisovskiy static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
88550525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
88650525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
88750525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
88850525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
88950525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GAME, "Game" },
89050525c33SStanislav Lisovskiy };
89150525c33SStanislav Lisovskiy 
8928d70f395SHans de Goede static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
8938d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_NORMAL,	"Normal"	},
8948d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP,	"Upside Down"	},
8958d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_LEFT_UP,	"Left Side Up"	},
8968d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,	"Right Side Up"	},
8978d70f395SHans de Goede };
8988d70f395SHans de Goede 
89952217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
90052217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
90152217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
90252217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
90352217195SDaniel Vetter };
90452217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
90552217195SDaniel Vetter 
90652217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
907e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I, TV-out and DP */
90852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
90952217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
91052217195SDaniel Vetter };
91152217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
91252217195SDaniel Vetter 		 drm_dvi_i_subconnector_enum_list)
91352217195SDaniel Vetter 
91452217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
91552217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
91652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
91752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
91852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
91952217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
92052217195SDaniel Vetter };
92152217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
92252217195SDaniel Vetter 
92352217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
924e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I, TV-out and DP */
92552217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
92652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
92752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
92852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
92952217195SDaniel Vetter };
93052217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
93152217195SDaniel Vetter 		 drm_tv_subconnector_enum_list)
93252217195SDaniel Vetter 
933e5b92773SOleg Vasilev static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = {
934e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,     "Unknown"   }, /* DVI-I, TV-out and DP */
935e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_VGA,	     "VGA"       }, /* DP */
936e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_DVID,	     "DVI-D"     }, /* DP */
937e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_HDMIA,	     "HDMI"      }, /* DP */
938e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_DisplayPort, "DP"        }, /* DP */
939e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Wireless,    "Wireless"  }, /* DP */
940e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Native,	     "Native"    }, /* DP */
941e5b92773SOleg Vasilev };
942e5b92773SOleg Vasilev 
943e5b92773SOleg Vasilev DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name,
944e5b92773SOleg Vasilev 		 drm_dp_subconnector_enum_list)
945e5b92773SOleg Vasilev 
946d2c6a405SUma Shankar static const struct drm_prop_enum_list hdmi_colorspaces[] = {
947d2c6a405SUma Shankar 	/* For Default case, driver will set the colorspace */
948d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
949d2c6a405SUma Shankar 	/* Standard Definition Colorimetry based on CEA 861 */
950d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_SMPTE_170M_YCC, "SMPTE_170M_YCC" },
951d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
952d2c6a405SUma Shankar 	/* Standard Definition Colorimetry based on IEC 61966-2-4 */
953d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
954d2c6a405SUma Shankar 	/* High Definition Colorimetry based on IEC 61966-2-4 */
955d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
956d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-1/Amendment 1 */
957d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
958d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-5 [33] */
959d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
960d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-5 */
961d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
962d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
963d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
964d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
965d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
966d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
967d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
968d2c6a405SUma Shankar 	/* Added as part of Additional Colorimetry Extension in 861.G */
969d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
970d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, "DCI-P3_RGB_Theater" },
971d2c6a405SUma Shankar };
972d2c6a405SUma Shankar 
97345cf0e91SGwan-gyeong Mun /*
97445cf0e91SGwan-gyeong Mun  * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
97545cf0e91SGwan-gyeong Mun  * Format Table 2-120
97645cf0e91SGwan-gyeong Mun  */
97745cf0e91SGwan-gyeong Mun static const struct drm_prop_enum_list dp_colorspaces[] = {
97845cf0e91SGwan-gyeong Mun 	/* For Default case, driver will set the colorspace */
97945cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
98045cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED, "RGB_Wide_Gamut_Fixed_Point" },
98145cf0e91SGwan-gyeong Mun 	/* Colorimetry based on scRGB (IEC 61966-2-2) */
98245cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT, "RGB_Wide_Gamut_Floating_Point" },
98345cf0e91SGwan-gyeong Mun 	/* Colorimetry based on IEC 61966-2-5 */
98445cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
98545cf0e91SGwan-gyeong Mun 	/* Colorimetry based on SMPTE RP 431-2 */
98645cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
98745cf0e91SGwan-gyeong Mun 	/* Colorimetry based on ITU-R BT.2020 */
98845cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
98945cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT601_YCC, "BT601_YCC" },
99045cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
99145cf0e91SGwan-gyeong Mun 	/* Standard Definition Colorimetry based on IEC 61966-2-4 */
99245cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
99345cf0e91SGwan-gyeong Mun 	/* High Definition Colorimetry based on IEC 61966-2-4 */
99445cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
99545cf0e91SGwan-gyeong Mun 	/* Colorimetry based on IEC 61966-2-1/Amendment 1 */
99645cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
99745cf0e91SGwan-gyeong Mun 	/* Colorimetry based on IEC 61966-2-5 [33] */
99845cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
99945cf0e91SGwan-gyeong Mun 	/* Colorimetry based on ITU-R BT.2020 */
100045cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
100145cf0e91SGwan-gyeong Mun 	/* Colorimetry based on ITU-R BT.2020 */
100245cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
100345cf0e91SGwan-gyeong Mun };
100445cf0e91SGwan-gyeong Mun 
10054ada6f22SDaniel Vetter /**
10064ada6f22SDaniel Vetter  * DOC: standard connector properties
10074ada6f22SDaniel Vetter  *
10084ada6f22SDaniel Vetter  * DRM connectors have a few standardized properties:
10094ada6f22SDaniel Vetter  *
10104ada6f22SDaniel Vetter  * EDID:
10114ada6f22SDaniel Vetter  * 	Blob property which contains the current EDID read from the sink. This
10124ada6f22SDaniel Vetter  * 	is useful to parse sink identification information like vendor, model
10134ada6f22SDaniel Vetter  * 	and serial. Drivers should update this property by calling
1014c555f023SDaniel Vetter  * 	drm_connector_update_edid_property(), usually after having parsed
10154ada6f22SDaniel Vetter  * 	the EDID using drm_add_edid_modes(). Userspace cannot change this
10164ada6f22SDaniel Vetter  * 	property.
101712767469SSimon Ser  *
101812767469SSimon Ser  * 	User-space should not parse the EDID to obtain information exposed via
101912767469SSimon Ser  * 	other KMS properties (because the kernel might apply limits, quirks or
102012767469SSimon Ser  * 	fixups to the EDID). For instance, user-space should not try to parse
102112767469SSimon Ser  * 	mode lists from the EDID.
10224ada6f22SDaniel Vetter  * DPMS:
10234ada6f22SDaniel Vetter  * 	Legacy property for setting the power state of the connector. For atomic
10244ada6f22SDaniel Vetter  * 	drivers this is only provided for backwards compatibility with existing
10254ada6f22SDaniel Vetter  * 	drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
10264ada6f22SDaniel Vetter  * 	connector is linked to. Drivers should never set this property directly,
1027d574528aSDaniel Vetter  * 	it is handled by the DRM core by calling the &drm_connector_funcs.dpms
1028144a7999SDaniel Vetter  * 	callback. For atomic drivers the remapping to the "ACTIVE" property is
10291e3e4caeSSimon Ser  * 	implemented in the DRM core.
1030d0d1aee5SDaniel Vetter  *
1031d0d1aee5SDaniel Vetter  * 	Note that this property cannot be set through the MODE_ATOMIC ioctl,
1032d0d1aee5SDaniel Vetter  * 	userspace must use "ACTIVE" on the CRTC instead.
1033d0d1aee5SDaniel Vetter  *
1034d0d1aee5SDaniel Vetter  * 	WARNING:
1035d0d1aee5SDaniel Vetter  *
1036d0d1aee5SDaniel Vetter  * 	For userspace also running on legacy drivers the "DPMS" semantics are a
1037d0d1aee5SDaniel Vetter  * 	lot more complicated. First, userspace cannot rely on the "DPMS" value
1038d0d1aee5SDaniel Vetter  * 	returned by the GETCONNECTOR actually reflecting reality, because many
1039d0d1aee5SDaniel Vetter  * 	drivers fail to update it. For atomic drivers this is taken care of in
1040d0d1aee5SDaniel Vetter  * 	drm_atomic_helper_update_legacy_modeset_state().
1041d0d1aee5SDaniel Vetter  *
1042d0d1aee5SDaniel Vetter  * 	The second issue is that the DPMS state is only well-defined when the
1043d0d1aee5SDaniel Vetter  * 	connector is connected to a CRTC. In atomic the DRM core enforces that
1044d0d1aee5SDaniel Vetter  * 	"ACTIVE" is off in such a case, no such checks exists for "DPMS".
1045d0d1aee5SDaniel Vetter  *
1046d0d1aee5SDaniel Vetter  * 	Finally, when enabling an output using the legacy SETCONFIG ioctl then
1047d0d1aee5SDaniel Vetter  * 	"DPMS" is forced to ON. But see above, that might not be reflected in
1048d0d1aee5SDaniel Vetter  * 	the software value on legacy drivers.
1049d0d1aee5SDaniel Vetter  *
1050d0d1aee5SDaniel Vetter  * 	Summarizing: Only set "DPMS" when the connector is known to be enabled,
1051d0d1aee5SDaniel Vetter  * 	assume that a successful SETCONFIG call also sets "DPMS" to on, and
1052d0d1aee5SDaniel Vetter  * 	never read back the value of "DPMS" because it can be incorrect.
10534ada6f22SDaniel Vetter  * PATH:
10544ada6f22SDaniel Vetter  * 	Connector path property to identify how this sink is physically
10554ada6f22SDaniel Vetter  * 	connected. Used by DP MST. This should be set by calling
105697e14fbeSDaniel Vetter  * 	drm_connector_set_path_property(), in the case of DP MST with the
10574ada6f22SDaniel Vetter  * 	path property the MST manager created. Userspace cannot change this
10584ada6f22SDaniel Vetter  * 	property.
10594ada6f22SDaniel Vetter  * TILE:
10604ada6f22SDaniel Vetter  * 	Connector tile group property to indicate how a set of DRM connector
10614ada6f22SDaniel Vetter  * 	compose together into one logical screen. This is used by both high-res
10624ada6f22SDaniel Vetter  * 	external screens (often only using a single cable, but exposing multiple
10634ada6f22SDaniel Vetter  * 	DP MST sinks), or high-res integrated panels (like dual-link DSI) which
10644ada6f22SDaniel Vetter  * 	are not gen-locked. Note that for tiled panels which are genlocked, like
10654ada6f22SDaniel Vetter  * 	dual-link LVDS or dual-link DSI, the driver should try to not expose the
106684e543bcSAntonio Borneo  * 	tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers
106797e14fbeSDaniel Vetter  * 	should update this value using drm_connector_set_tile_property().
10684ada6f22SDaniel Vetter  * 	Userspace cannot change this property.
106940ee6fbeSManasi Navare  * link-status:
1070716719a3SSean Paul  *      Connector link-status property to indicate the status of link. The
1071716719a3SSean Paul  *      default value of link-status is "GOOD". If something fails during or
1072716719a3SSean Paul  *      after modeset, the kernel driver may set this to "BAD" and issue a
1073716719a3SSean Paul  *      hotplug uevent. Drivers should update this value using
107497e14fbeSDaniel Vetter  *      drm_connector_set_link_status_property().
1075a66da873SSimon Ser  *
1076a66da873SSimon Ser  *      When user-space receives the hotplug uevent and detects a "BAD"
1077a66da873SSimon Ser  *      link-status, the sink doesn't receive pixels anymore (e.g. the screen
1078a66da873SSimon Ser  *      becomes completely black). The list of available modes may have
1079a66da873SSimon Ser  *      changed. User-space is expected to pick a new mode if the current one
1080a66da873SSimon Ser  *      has disappeared and perform a new modeset with link-status set to
1081a66da873SSimon Ser  *      "GOOD" to re-enable the connector.
1082a66da873SSimon Ser  *
1083a66da873SSimon Ser  *      If multiple connectors share the same CRTC and one of them gets a "BAD"
1084a66da873SSimon Ser  *      link-status, the other are unaffected (ie. the sinks still continue to
1085a66da873SSimon Ser  *      receive pixels).
1086a66da873SSimon Ser  *
1087a66da873SSimon Ser  *      When user-space performs an atomic commit on a connector with a "BAD"
1088a66da873SSimon Ser  *      link-status without resetting the property to "GOOD", the sink may
1089a66da873SSimon Ser  *      still not receive pixels. When user-space performs an atomic commit
1090a66da873SSimon Ser  *      which resets the link-status property to "GOOD" without the
1091a66da873SSimon Ser  *      ALLOW_MODESET flag set, it might fail because a modeset is required.
1092a66da873SSimon Ser  *
1093a66da873SSimon Ser  *      User-space can only change link-status to "GOOD", changing it to "BAD"
1094a66da873SSimon Ser  *      is a no-op.
1095a66da873SSimon Ser  *
1096a66da873SSimon Ser  *      For backwards compatibility with non-atomic userspace the kernel
1097a66da873SSimon Ser  *      tries to automatically set the link-status back to "GOOD" in the
1098a66da873SSimon Ser  *      SETCRTC IOCTL. This might fail if the mode is no longer valid, similar
1099a66da873SSimon Ser  *      to how it might fail if a different screen has been connected in the
1100a66da873SSimon Ser  *      interim.
110166660d4cSDave Airlie  * non_desktop:
110266660d4cSDave Airlie  * 	Indicates the output should be ignored for purposes of displaying a
110366660d4cSDave Airlie  * 	standard desktop environment or console. This is most likely because
110466660d4cSDave Airlie  * 	the output device is not rectilinear.
110524557865SSean Paul  * Content Protection:
110624557865SSean Paul  *	This property is used by userspace to request the kernel protect future
110724557865SSean Paul  *	content communicated over the link. When requested, kernel will apply
110824557865SSean Paul  *	the appropriate means of protection (most often HDCP), and use the
110924557865SSean Paul  *	property to tell userspace the protection is active.
111024557865SSean Paul  *
111124557865SSean Paul  *	Drivers can set this up by calling
111224557865SSean Paul  *	drm_connector_attach_content_protection_property() on initialization.
111324557865SSean Paul  *
111424557865SSean Paul  *	The value of this property can be one of the following:
111524557865SSean Paul  *
1116bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
111724557865SSean Paul  *		The link is not protected, content is transmitted in the clear.
1118bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
111924557865SSean Paul  *		Userspace has requested content protection, but the link is not
112024557865SSean Paul  *		currently protected. When in this state, kernel should enable
112124557865SSean Paul  *		Content Protection as soon as possible.
1122bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
112324557865SSean Paul  *		Userspace has requested content protection, and the link is
112424557865SSean Paul  *		protected. Only the driver can set the property to this value.
112524557865SSean Paul  *		If userspace attempts to set to ENABLED, kernel will return
112624557865SSean Paul  *		-EINVAL.
112724557865SSean Paul  *
112824557865SSean Paul  *	A few guidelines:
112924557865SSean Paul  *
113024557865SSean Paul  *	- DESIRED state should be preserved until userspace de-asserts it by
113124557865SSean Paul  *	  setting the property to UNDESIRED. This means ENABLED should only
113224557865SSean Paul  *	  transition to UNDESIRED when the user explicitly requests it.
113324557865SSean Paul  *	- If the state is DESIRED, kernel should attempt to re-authenticate the
113424557865SSean Paul  *	  link whenever possible. This includes across disable/enable, dpms,
113524557865SSean Paul  *	  hotplug, downstream device changes, link status failures, etc..
1136bb5a45d4SRamalingam C  *	- Kernel sends uevent with the connector id and property id through
1137bb5a45d4SRamalingam C  *	  @drm_hdcp_update_content_protection, upon below kernel triggered
1138bb5a45d4SRamalingam C  *	  scenarios:
113912db36bcSSean Paul  *
114012db36bcSSean Paul  *		- DESIRED -> ENABLED (authentication success)
114112db36bcSSean Paul  *		- ENABLED -> DESIRED (termination of authentication)
1142bb5a45d4SRamalingam C  *	- Please note no uevents for userspace triggered property state changes,
1143bb5a45d4SRamalingam C  *	  which can't fail such as
114412db36bcSSean Paul  *
114512db36bcSSean Paul  *		- DESIRED/ENABLED -> UNDESIRED
114612db36bcSSean Paul  *		- UNDESIRED -> DESIRED
1147bb5a45d4SRamalingam C  *	- Userspace is responsible for polling the property or listen to uevents
1148bb5a45d4SRamalingam C  *	  to determine when the value transitions from ENABLED to DESIRED.
1149bb5a45d4SRamalingam C  *	  This signifies the link is no longer protected and userspace should
1150bb5a45d4SRamalingam C  *	  take appropriate action (whatever that might be).
11514ada6f22SDaniel Vetter  *
11527672dbbaSRamalingam C  * HDCP Content Type:
11537672dbbaSRamalingam C  *	This Enum property is used by the userspace to declare the content type
11547672dbbaSRamalingam C  *	of the display stream, to kernel. Here display stream stands for any
11557672dbbaSRamalingam C  *	display content that userspace intended to display through HDCP
11567672dbbaSRamalingam C  *	encryption.
11577672dbbaSRamalingam C  *
11587672dbbaSRamalingam C  *	Content Type of a stream is decided by the owner of the stream, as
11597672dbbaSRamalingam C  *	"HDCP Type0" or "HDCP Type1".
11607672dbbaSRamalingam C  *
11617672dbbaSRamalingam C  *	The value of the property can be one of the below:
11627672dbbaSRamalingam C  *	  - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0
11637672dbbaSRamalingam C  *	  - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1
11647672dbbaSRamalingam C  *
11657672dbbaSRamalingam C  *	When kernel starts the HDCP authentication (see "Content Protection"
11667672dbbaSRamalingam C  *	for details), it uses the content type in "HDCP Content Type"
11677672dbbaSRamalingam C  *	for performing the HDCP authentication with the display sink.
11687672dbbaSRamalingam C  *
11697672dbbaSRamalingam C  *	Please note in HDCP spec versions, a link can be authenticated with
11707672dbbaSRamalingam C  *	HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be
11717672dbbaSRamalingam C  *	authenticated with HDCP1.4 only for Content Type 0(though it is implicit
11727672dbbaSRamalingam C  *	in nature. As there is no reference for Content Type in HDCP1.4).
11737672dbbaSRamalingam C  *
11747672dbbaSRamalingam C  *	HDCP2.2 authentication protocol itself takes the "Content Type" as a
11757672dbbaSRamalingam C  *	parameter, which is a input for the DP HDCP2.2 encryption algo.
11767672dbbaSRamalingam C  *
11777672dbbaSRamalingam C  *	In case of Type 0 content protection request, kernel driver can choose
11787672dbbaSRamalingam C  *	either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for
11797672dbbaSRamalingam C  *	"HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send
11807672dbbaSRamalingam C  *	that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).
11817672dbbaSRamalingam C  *	But if the content is classified as "HDCP Type 1", above mentioned
11827672dbbaSRamalingam C  *	HDCP 2.2 repeater wont send the content to the HDCP sink as it can't
11837672dbbaSRamalingam C  *	authenticate the HDCP1.4 capable sink for "HDCP Type 1".
11847672dbbaSRamalingam C  *
11857672dbbaSRamalingam C  *	Please note userspace can be ignorant of the HDCP versions used by the
11867672dbbaSRamalingam C  *	kernel driver to achieve the "HDCP Content Type".
11877672dbbaSRamalingam C  *
11887672dbbaSRamalingam C  *	At current scenario, classifying a content as Type 1 ensures that the
11897672dbbaSRamalingam C  *	content will be displayed only through the HDCP2.2 encrypted link.
11907672dbbaSRamalingam C  *
11917672dbbaSRamalingam C  *	Note that the HDCP Content Type property is introduced at HDCP 2.2, and
11927672dbbaSRamalingam C  *	defaults to type 0. It is only exposed by drivers supporting HDCP 2.2
11937672dbbaSRamalingam C  *	(hence supporting Type 0 and Type 1). Based on how next versions of
11947672dbbaSRamalingam C  *	HDCP specs are defined content Type could be used for higher versions
11957672dbbaSRamalingam C  *	too.
11967672dbbaSRamalingam C  *
11977672dbbaSRamalingam C  *	If content type is changed when "Content Protection" is not UNDESIRED,
11987672dbbaSRamalingam C  *	then kernel will disable the HDCP and re-enable with new type in the
11997672dbbaSRamalingam C  *	same atomic commit. And when "Content Protection" is ENABLED, it means
12007672dbbaSRamalingam C  *	that link is HDCP authenticated and encrypted, for the transmission of
12017672dbbaSRamalingam C  *	the Type of stream mentioned at "HDCP Content Type".
12027672dbbaSRamalingam C  *
1203a09db883SUma Shankar  * HDR_OUTPUT_METADATA:
1204a09db883SUma Shankar  *	Connector property to enable userspace to send HDR Metadata to
1205a09db883SUma Shankar  *	driver. This metadata is based on the composition and blending
1206a09db883SUma Shankar  *	policies decided by user, taking into account the hardware and
1207a09db883SUma Shankar  *	sink capabilities. The driver gets this metadata and creates a
1208a09db883SUma Shankar  *	Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,
1209a09db883SUma Shankar  *	SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then
1210a09db883SUma Shankar  *	sent to sink. This notifies the sink of the upcoming frame's Color
1211a09db883SUma Shankar  *	Encoding and Luminance parameters.
1212a09db883SUma Shankar  *
1213a09db883SUma Shankar  *	Userspace first need to detect the HDR capabilities of sink by
1214a09db883SUma Shankar  *	reading and parsing the EDID. Details of HDR metadata for HDMI
1215a09db883SUma Shankar  *	are added in CTA 861.G spec. For DP , its defined in VESA DP
1216a09db883SUma Shankar  *	Standard v1.4. It needs to then get the metadata information
1217a09db883SUma Shankar  *	of the video/game/app content which are encoded in HDR (basically
1218a09db883SUma Shankar  *	using HDR transfer functions). With this information it needs to
1219a09db883SUma Shankar  *	decide on a blending policy and compose the relevant
1220a09db883SUma Shankar  *	layers/overlays into a common format. Once this blending is done,
1221a09db883SUma Shankar  *	userspace will be aware of the metadata of the composed frame to
1222a09db883SUma Shankar  *	be send to sink. It then uses this property to communicate this
1223a09db883SUma Shankar  *	metadata to driver which then make a Infoframe packet and sends
1224a09db883SUma Shankar  *	to sink based on the type of encoder connected.
1225a09db883SUma Shankar  *
1226a09db883SUma Shankar  *	Userspace will be responsible to do Tone mapping operation in case:
1227a09db883SUma Shankar  *		- Some layers are HDR and others are SDR
1228a09db883SUma Shankar  *		- HDR layers luminance is not same as sink
12299f9b2559SSean Paul  *
1230a09db883SUma Shankar  *	It will even need to do colorspace conversion and get all layers
1231a09db883SUma Shankar  *	to one common colorspace for blending. It can use either GL, Media
123284e543bcSAntonio Borneo  *	or display engine to get this done based on the capabilities of the
1233a09db883SUma Shankar  *	associated hardware.
1234a09db883SUma Shankar  *
1235a09db883SUma Shankar  *	Driver expects metadata to be put in &struct hdr_output_metadata
1236a09db883SUma Shankar  *	structure from userspace. This is received as blob and stored in
1237a09db883SUma Shankar  *	&drm_connector_state.hdr_output_metadata. It parses EDID and saves the
1238a09db883SUma Shankar  *	sink metadata in &struct hdr_sink_metadata, as
1239a09db883SUma Shankar  *	&drm_connector.hdr_sink_metadata.  Driver uses
1240a09db883SUma Shankar  *	drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,
1241a09db883SUma Shankar  *	hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of
1242a09db883SUma Shankar  *	HDMI encoder.
1243a09db883SUma Shankar  *
124447e22ff1SRadhakrishna Sripada  * max bpc:
124547e22ff1SRadhakrishna Sripada  *	This range property is used by userspace to limit the bit depth. When
124647e22ff1SRadhakrishna Sripada  *	used the driver would limit the bpc in accordance with the valid range
124747e22ff1SRadhakrishna Sripada  *	supported by the hardware and sink. Drivers to use the function
124847e22ff1SRadhakrishna Sripada  *	drm_connector_attach_max_bpc_property() to create and attach the
124947e22ff1SRadhakrishna Sripada  *	property to the connector during initialization.
125047e22ff1SRadhakrishna Sripada  *
12514ada6f22SDaniel Vetter  * Connectors also have one standardized atomic property:
12524ada6f22SDaniel Vetter  *
12534ada6f22SDaniel Vetter  * CRTC_ID:
12544ada6f22SDaniel Vetter  * 	Mode object ID of the &drm_crtc this connector should be connected to.
12558d70f395SHans de Goede  *
12568d70f395SHans de Goede  * Connectors for LCD panels may also have one standardized property:
12578d70f395SHans de Goede  *
12588d70f395SHans de Goede  * panel orientation:
12598d70f395SHans de Goede  *	On some devices the LCD panel is mounted in the casing in such a way
12608d70f395SHans de Goede  *	that the up/top side of the panel does not match with the top side of
12618d70f395SHans de Goede  *	the device. Userspace can use this property to check for this.
12628d70f395SHans de Goede  *	Note that input coordinates from touchscreens (input devices with
12638d70f395SHans de Goede  *	INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
12648d70f395SHans de Goede  *	coordinates, so if userspace rotates the picture to adjust for
12658d70f395SHans de Goede  *	the orientation it must also apply the same transformation to the
1266bbeba09fSDaniel Vetter  *	touchscreen input coordinates. This property is initialized by calling
126769654c63SDerek Basehore  *	drm_connector_set_panel_orientation() or
126869654c63SDerek Basehore  *	drm_connector_set_panel_orientation_with_quirk()
1269bbeba09fSDaniel Vetter  *
1270bbeba09fSDaniel Vetter  * scaling mode:
1271bbeba09fSDaniel Vetter  *	This property defines how a non-native mode is upscaled to the native
1272bbeba09fSDaniel Vetter  *	mode of an LCD panel:
1273bbeba09fSDaniel Vetter  *
1274bbeba09fSDaniel Vetter  *	None:
1275bbeba09fSDaniel Vetter  *		No upscaling happens, scaling is left to the panel. Not all
1276bbeba09fSDaniel Vetter  *		drivers expose this mode.
1277bbeba09fSDaniel Vetter  *	Full:
1278bbeba09fSDaniel Vetter  *		The output is upscaled to the full resolution of the panel,
1279bbeba09fSDaniel Vetter  *		ignoring the aspect ratio.
1280bbeba09fSDaniel Vetter  *	Center:
1281bbeba09fSDaniel Vetter  *		No upscaling happens, the output is centered within the native
1282bbeba09fSDaniel Vetter  *		resolution the panel.
1283bbeba09fSDaniel Vetter  *	Full aspect:
1284bbeba09fSDaniel Vetter  *		The output is upscaled to maximize either the width or height
1285bbeba09fSDaniel Vetter  *		while retaining the aspect ratio.
1286bbeba09fSDaniel Vetter  *
1287bbeba09fSDaniel Vetter  *	This property should be set up by calling
1288bbeba09fSDaniel Vetter  *	drm_connector_attach_scaling_mode_property(). Note that drivers
1289bbeba09fSDaniel Vetter  *	can also expose this property to external outputs, in which case they
1290bbeba09fSDaniel Vetter  *	must support "None", which should be the default (since external screens
1291bbeba09fSDaniel Vetter  *	have a built-in scaler).
1292e5b92773SOleg Vasilev  *
1293e5b92773SOleg Vasilev  * subconnector:
1294e5b92773SOleg Vasilev  *	This property is used by DVI-I, TVout and DisplayPort to indicate different
1295e5b92773SOleg Vasilev  *	connector subtypes. Enum values more or less match with those from main
1296e5b92773SOleg Vasilev  *	connector types.
1297e5b92773SOleg Vasilev  *	For DVI-I and TVout there is also a matching property "select subconnector"
1298e5b92773SOleg Vasilev  *	allowing to switch between signal types.
1299e5b92773SOleg Vasilev  *	DP subconnector corresponds to a downstream port.
1300107fe904SRajat Jain  *
1301107fe904SRajat Jain  * privacy-screen sw-state, privacy-screen hw-state:
1302107fe904SRajat Jain  *	These 2 optional properties can be used to query the state of the
1303107fe904SRajat Jain  *	electronic privacy screen that is available on some displays; and in
1304107fe904SRajat Jain  *	some cases also control the state. If a driver implements these
1305107fe904SRajat Jain  *	properties then both properties must be present.
1306107fe904SRajat Jain  *
1307107fe904SRajat Jain  *	"privacy-screen hw-state" is read-only and reflects the actual state
1308107fe904SRajat Jain  *	of the privacy-screen, possible values: "Enabled", "Disabled,
1309107fe904SRajat Jain  *	"Enabled-locked", "Disabled-locked". The locked states indicate
1310107fe904SRajat Jain  *	that the state cannot be changed through the DRM API. E.g. there
1311107fe904SRajat Jain  *	might be devices where the firmware-setup options, or a hardware
1312107fe904SRajat Jain  *	slider-switch, offer always on / off modes.
1313107fe904SRajat Jain  *
1314107fe904SRajat Jain  *	"privacy-screen sw-state" can be set to change the privacy-screen state
1315107fe904SRajat Jain  *	when not locked. In this case the driver must update the hw-state
1316107fe904SRajat Jain  *	property to reflect the new state on completion of the commit of the
1317107fe904SRajat Jain  *	sw-state property. Setting the sw-state property when the hw-state is
1318107fe904SRajat Jain  *	locked must be interpreted by the driver as a request to change the
1319107fe904SRajat Jain  *	state to the set state when the hw-state becomes unlocked. E.g. if
1320107fe904SRajat Jain  *	"privacy-screen hw-state" is "Enabled-locked" and the sw-state
1321107fe904SRajat Jain  *	gets set to "Disabled" followed by the user unlocking the state by
1322107fe904SRajat Jain  *	changing the slider-switch position, then the driver must set the
1323107fe904SRajat Jain  *	state to "Disabled" upon receiving the unlock event.
1324107fe904SRajat Jain  *
1325107fe904SRajat Jain  *	In some cases the privacy-screen's actual state might change outside of
1326107fe904SRajat Jain  *	control of the DRM code. E.g. there might be a firmware handled hotkey
1327107fe904SRajat Jain  *	which toggles the actual state, or the actual state might be changed
1328107fe904SRajat Jain  *	through another userspace API such as writing /proc/acpi/ibm/lcdshadow.
1329107fe904SRajat Jain  *	In this case the driver must update both the hw-state and the sw-state
1330107fe904SRajat Jain  *	to reflect the new value, overwriting any pending state requests in the
1331107fe904SRajat Jain  *	sw-state. Any pending sw-state requests are thus discarded.
1332107fe904SRajat Jain  *
1333107fe904SRajat Jain  *	Note that the ability for the state to change outside of control of
1334107fe904SRajat Jain  *	the DRM master process means that userspace must not cache the value
1335107fe904SRajat Jain  *	of the sw-state. Caching the sw-state value and including it in later
1336107fe904SRajat Jain  *	atomic commits may lead to overriding a state change done through e.g.
1337107fe904SRajat Jain  *	a firmware handled hotkey. Therefor userspace must not include the
1338107fe904SRajat Jain  *	privacy-screen sw-state in an atomic commit unless it wants to change
1339107fe904SRajat Jain  *	its value.
13404ada6f22SDaniel Vetter  */
13414ada6f22SDaniel Vetter 
134252217195SDaniel Vetter int drm_connector_create_standard_properties(struct drm_device *dev)
134352217195SDaniel Vetter {
134452217195SDaniel Vetter 	struct drm_property *prop;
134552217195SDaniel Vetter 
134652217195SDaniel Vetter 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
134752217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
134852217195SDaniel Vetter 				   "EDID", 0);
134952217195SDaniel Vetter 	if (!prop)
135052217195SDaniel Vetter 		return -ENOMEM;
135152217195SDaniel Vetter 	dev->mode_config.edid_property = prop;
135252217195SDaniel Vetter 
135352217195SDaniel Vetter 	prop = drm_property_create_enum(dev, 0,
135452217195SDaniel Vetter 				   "DPMS", drm_dpms_enum_list,
135552217195SDaniel Vetter 				   ARRAY_SIZE(drm_dpms_enum_list));
135652217195SDaniel Vetter 	if (!prop)
135752217195SDaniel Vetter 		return -ENOMEM;
135852217195SDaniel Vetter 	dev->mode_config.dpms_property = prop;
135952217195SDaniel Vetter 
136052217195SDaniel Vetter 	prop = drm_property_create(dev,
136152217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
136252217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
136352217195SDaniel Vetter 				   "PATH", 0);
136452217195SDaniel Vetter 	if (!prop)
136552217195SDaniel Vetter 		return -ENOMEM;
136652217195SDaniel Vetter 	dev->mode_config.path_property = prop;
136752217195SDaniel Vetter 
136852217195SDaniel Vetter 	prop = drm_property_create(dev,
136952217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
137052217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
137152217195SDaniel Vetter 				   "TILE", 0);
137252217195SDaniel Vetter 	if (!prop)
137352217195SDaniel Vetter 		return -ENOMEM;
137452217195SDaniel Vetter 	dev->mode_config.tile_property = prop;
137552217195SDaniel Vetter 
137640ee6fbeSManasi Navare 	prop = drm_property_create_enum(dev, 0, "link-status",
137740ee6fbeSManasi Navare 					drm_link_status_enum_list,
137840ee6fbeSManasi Navare 					ARRAY_SIZE(drm_link_status_enum_list));
137940ee6fbeSManasi Navare 	if (!prop)
138040ee6fbeSManasi Navare 		return -ENOMEM;
138140ee6fbeSManasi Navare 	dev->mode_config.link_status_property = prop;
138240ee6fbeSManasi Navare 
138366660d4cSDave Airlie 	prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
138466660d4cSDave Airlie 	if (!prop)
138566660d4cSDave Airlie 		return -ENOMEM;
138666660d4cSDave Airlie 	dev->mode_config.non_desktop_property = prop;
138766660d4cSDave Airlie 
1388fbb5d035SUma Shankar 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
1389fbb5d035SUma Shankar 				   "HDR_OUTPUT_METADATA", 0);
1390fbb5d035SUma Shankar 	if (!prop)
1391fbb5d035SUma Shankar 		return -ENOMEM;
1392fbb5d035SUma Shankar 	dev->mode_config.hdr_output_metadata_property = prop;
1393fbb5d035SUma Shankar 
139452217195SDaniel Vetter 	return 0;
139552217195SDaniel Vetter }
139652217195SDaniel Vetter 
139752217195SDaniel Vetter /**
139852217195SDaniel Vetter  * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
139952217195SDaniel Vetter  * @dev: DRM device
140052217195SDaniel Vetter  *
140152217195SDaniel Vetter  * Called by a driver the first time a DVI-I connector is made.
1402f85d9e59SRandy Dunlap  *
1403f85d9e59SRandy Dunlap  * Returns: %0
140452217195SDaniel Vetter  */
140552217195SDaniel Vetter int drm_mode_create_dvi_i_properties(struct drm_device *dev)
140652217195SDaniel Vetter {
140752217195SDaniel Vetter 	struct drm_property *dvi_i_selector;
140852217195SDaniel Vetter 	struct drm_property *dvi_i_subconnector;
140952217195SDaniel Vetter 
141052217195SDaniel Vetter 	if (dev->mode_config.dvi_i_select_subconnector_property)
141152217195SDaniel Vetter 		return 0;
141252217195SDaniel Vetter 
141352217195SDaniel Vetter 	dvi_i_selector =
141452217195SDaniel Vetter 		drm_property_create_enum(dev, 0,
141552217195SDaniel Vetter 				    "select subconnector",
141652217195SDaniel Vetter 				    drm_dvi_i_select_enum_list,
141752217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_select_enum_list));
141852217195SDaniel Vetter 	dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
141952217195SDaniel Vetter 
142052217195SDaniel Vetter 	dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
142152217195SDaniel Vetter 				    "subconnector",
142252217195SDaniel Vetter 				    drm_dvi_i_subconnector_enum_list,
142352217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
142452217195SDaniel Vetter 	dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
142552217195SDaniel Vetter 
142652217195SDaniel Vetter 	return 0;
142752217195SDaniel Vetter }
142852217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
142952217195SDaniel Vetter 
143052217195SDaniel Vetter /**
1431e5b92773SOleg Vasilev  * drm_connector_attach_dp_subconnector_property - create subconnector property for DP
1432e5b92773SOleg Vasilev  * @connector: drm_connector to attach property
1433e5b92773SOleg Vasilev  *
1434e5b92773SOleg Vasilev  * Called by a driver when DP connector is created.
1435e5b92773SOleg Vasilev  */
1436e5b92773SOleg Vasilev void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector)
1437e5b92773SOleg Vasilev {
1438e5b92773SOleg Vasilev 	struct drm_mode_config *mode_config = &connector->dev->mode_config;
1439e5b92773SOleg Vasilev 
1440e5b92773SOleg Vasilev 	if (!mode_config->dp_subconnector_property)
1441e5b92773SOleg Vasilev 		mode_config->dp_subconnector_property =
1442e5b92773SOleg Vasilev 			drm_property_create_enum(connector->dev,
1443e5b92773SOleg Vasilev 				DRM_MODE_PROP_IMMUTABLE,
1444e5b92773SOleg Vasilev 				"subconnector",
1445e5b92773SOleg Vasilev 				drm_dp_subconnector_enum_list,
1446e5b92773SOleg Vasilev 				ARRAY_SIZE(drm_dp_subconnector_enum_list));
1447e5b92773SOleg Vasilev 
1448e5b92773SOleg Vasilev 	drm_object_attach_property(&connector->base,
1449e5b92773SOleg Vasilev 				   mode_config->dp_subconnector_property,
1450e5b92773SOleg Vasilev 				   DRM_MODE_SUBCONNECTOR_Unknown);
1451e5b92773SOleg Vasilev }
1452e5b92773SOleg Vasilev EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property);
1453e5b92773SOleg Vasilev 
1454e5b92773SOleg Vasilev /**
145550525c33SStanislav Lisovskiy  * DOC: HDMI connector properties
145650525c33SStanislav Lisovskiy  *
145750525c33SStanislav Lisovskiy  * content type (HDMI specific):
145850525c33SStanislav Lisovskiy  *	Indicates content type setting to be used in HDMI infoframes to indicate
14591e55a53aSMatt Roper  *	content type for the external device, so that it adjusts its display
146050525c33SStanislav Lisovskiy  *	settings accordingly.
146150525c33SStanislav Lisovskiy  *
146250525c33SStanislav Lisovskiy  *	The value of this property can be one of the following:
146350525c33SStanislav Lisovskiy  *
146450525c33SStanislav Lisovskiy  *	No Data:
146550525c33SStanislav Lisovskiy  *		Content type is unknown
146650525c33SStanislav Lisovskiy  *	Graphics:
146750525c33SStanislav Lisovskiy  *		Content type is graphics
146850525c33SStanislav Lisovskiy  *	Photo:
146950525c33SStanislav Lisovskiy  *		Content type is photo
147050525c33SStanislav Lisovskiy  *	Cinema:
147150525c33SStanislav Lisovskiy  *		Content type is cinema
147250525c33SStanislav Lisovskiy  *	Game:
147350525c33SStanislav Lisovskiy  *		Content type is game
147450525c33SStanislav Lisovskiy  *
1475a0a33067SSimon Ser  *	The meaning of each content type is defined in CTA-861-G table 15.
1476a0a33067SSimon Ser  *
147750525c33SStanislav Lisovskiy  *	Drivers can set up this property by calling
147850525c33SStanislav Lisovskiy  *	drm_connector_attach_content_type_property(). Decoding to
1479ba609631SDaniel Vetter  *	infoframe values is done through drm_hdmi_avi_infoframe_content_type().
148050525c33SStanislav Lisovskiy  */
148150525c33SStanislav Lisovskiy 
148250525c33SStanislav Lisovskiy /**
148350525c33SStanislav Lisovskiy  * drm_connector_attach_content_type_property - attach content-type property
148450525c33SStanislav Lisovskiy  * @connector: connector to attach content type property on.
148550525c33SStanislav Lisovskiy  *
148650525c33SStanislav Lisovskiy  * Called by a driver the first time a HDMI connector is made.
1487f85d9e59SRandy Dunlap  *
1488f85d9e59SRandy Dunlap  * Returns: %0
148950525c33SStanislav Lisovskiy  */
149050525c33SStanislav Lisovskiy int drm_connector_attach_content_type_property(struct drm_connector *connector)
149150525c33SStanislav Lisovskiy {
149250525c33SStanislav Lisovskiy 	if (!drm_mode_create_content_type_property(connector->dev))
149350525c33SStanislav Lisovskiy 		drm_object_attach_property(&connector->base,
149450525c33SStanislav Lisovskiy 					   connector->dev->mode_config.content_type_property,
149550525c33SStanislav Lisovskiy 					   DRM_MODE_CONTENT_TYPE_NO_DATA);
149650525c33SStanislav Lisovskiy 	return 0;
149750525c33SStanislav Lisovskiy }
149850525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_connector_attach_content_type_property);
149950525c33SStanislav Lisovskiy 
150050525c33SStanislav Lisovskiy /**
1501e9d2871fSMauro Carvalho Chehab  * drm_connector_attach_tv_margin_properties - attach TV connector margin
1502e9d2871fSMauro Carvalho Chehab  * 	properties
15036c4f52dcSBoris Brezillon  * @connector: DRM connector
15046c4f52dcSBoris Brezillon  *
15056c4f52dcSBoris Brezillon  * Called by a driver when it needs to attach TV margin props to a connector.
15066c4f52dcSBoris Brezillon  * Typically used on SDTV and HDMI connectors.
15076c4f52dcSBoris Brezillon  */
15086c4f52dcSBoris Brezillon void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
15096c4f52dcSBoris Brezillon {
15106c4f52dcSBoris Brezillon 	struct drm_device *dev = connector->dev;
15116c4f52dcSBoris Brezillon 
15126c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
15136c4f52dcSBoris Brezillon 				   dev->mode_config.tv_left_margin_property,
15146c4f52dcSBoris Brezillon 				   0);
15156c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
15166c4f52dcSBoris Brezillon 				   dev->mode_config.tv_right_margin_property,
15176c4f52dcSBoris Brezillon 				   0);
15186c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
15196c4f52dcSBoris Brezillon 				   dev->mode_config.tv_top_margin_property,
15206c4f52dcSBoris Brezillon 				   0);
15216c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
15226c4f52dcSBoris Brezillon 				   dev->mode_config.tv_bottom_margin_property,
15236c4f52dcSBoris Brezillon 				   0);
15246c4f52dcSBoris Brezillon }
15256c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
15266c4f52dcSBoris Brezillon 
15276c4f52dcSBoris Brezillon /**
15286c4f52dcSBoris Brezillon  * drm_mode_create_tv_margin_properties - create TV connector margin properties
15296c4f52dcSBoris Brezillon  * @dev: DRM device
15306c4f52dcSBoris Brezillon  *
15316c4f52dcSBoris Brezillon  * Called by a driver's HDMI connector initialization routine, this function
15326c4f52dcSBoris Brezillon  * creates the TV margin properties for a given device. No need to call this
15336c4f52dcSBoris Brezillon  * function for an SDTV connector, it's already called from
15346c4f52dcSBoris Brezillon  * drm_mode_create_tv_properties().
1535f85d9e59SRandy Dunlap  *
1536f85d9e59SRandy Dunlap  * Returns:
1537f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
15386c4f52dcSBoris Brezillon  */
15396c4f52dcSBoris Brezillon int drm_mode_create_tv_margin_properties(struct drm_device *dev)
15406c4f52dcSBoris Brezillon {
15416c4f52dcSBoris Brezillon 	if (dev->mode_config.tv_left_margin_property)
15426c4f52dcSBoris Brezillon 		return 0;
15436c4f52dcSBoris Brezillon 
15446c4f52dcSBoris Brezillon 	dev->mode_config.tv_left_margin_property =
15456c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "left margin", 0, 100);
15466c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_left_margin_property)
15476c4f52dcSBoris Brezillon 		return -ENOMEM;
15486c4f52dcSBoris Brezillon 
15496c4f52dcSBoris Brezillon 	dev->mode_config.tv_right_margin_property =
15506c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "right margin", 0, 100);
15516c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_right_margin_property)
15526c4f52dcSBoris Brezillon 		return -ENOMEM;
15536c4f52dcSBoris Brezillon 
15546c4f52dcSBoris Brezillon 	dev->mode_config.tv_top_margin_property =
15556c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "top margin", 0, 100);
15566c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_top_margin_property)
15576c4f52dcSBoris Brezillon 		return -ENOMEM;
15586c4f52dcSBoris Brezillon 
15596c4f52dcSBoris Brezillon 	dev->mode_config.tv_bottom_margin_property =
15606c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "bottom margin", 0, 100);
15616c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_bottom_margin_property)
15626c4f52dcSBoris Brezillon 		return -ENOMEM;
15636c4f52dcSBoris Brezillon 
15646c4f52dcSBoris Brezillon 	return 0;
15656c4f52dcSBoris Brezillon }
15666c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
15676c4f52dcSBoris Brezillon 
15686c4f52dcSBoris Brezillon /**
1569eda6887fSBoris Brezillon  * drm_mode_create_tv_properties - create TV specific connector properties
157052217195SDaniel Vetter  * @dev: DRM device
157152217195SDaniel Vetter  * @num_modes: number of different TV formats (modes) supported
157252217195SDaniel Vetter  * @modes: array of pointers to strings containing name of each format
157352217195SDaniel Vetter  *
157452217195SDaniel Vetter  * Called by a driver's TV initialization routine, this function creates
157552217195SDaniel Vetter  * the TV specific connector properties for a given device.  Caller is
157652217195SDaniel Vetter  * responsible for allocating a list of format names and passing them to
157752217195SDaniel Vetter  * this routine.
1578f85d9e59SRandy Dunlap  *
1579f85d9e59SRandy Dunlap  * Returns:
1580f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
158152217195SDaniel Vetter  */
158252217195SDaniel Vetter int drm_mode_create_tv_properties(struct drm_device *dev,
158352217195SDaniel Vetter 				  unsigned int num_modes,
158452217195SDaniel Vetter 				  const char * const modes[])
158552217195SDaniel Vetter {
158652217195SDaniel Vetter 	struct drm_property *tv_selector;
158752217195SDaniel Vetter 	struct drm_property *tv_subconnector;
158852217195SDaniel Vetter 	unsigned int i;
158952217195SDaniel Vetter 
159052217195SDaniel Vetter 	if (dev->mode_config.tv_select_subconnector_property)
159152217195SDaniel Vetter 		return 0;
159252217195SDaniel Vetter 
159352217195SDaniel Vetter 	/*
159452217195SDaniel Vetter 	 * Basic connector properties
159552217195SDaniel Vetter 	 */
159652217195SDaniel Vetter 	tv_selector = drm_property_create_enum(dev, 0,
159752217195SDaniel Vetter 					  "select subconnector",
159852217195SDaniel Vetter 					  drm_tv_select_enum_list,
159952217195SDaniel Vetter 					  ARRAY_SIZE(drm_tv_select_enum_list));
160052217195SDaniel Vetter 	if (!tv_selector)
160152217195SDaniel Vetter 		goto nomem;
160252217195SDaniel Vetter 
160352217195SDaniel Vetter 	dev->mode_config.tv_select_subconnector_property = tv_selector;
160452217195SDaniel Vetter 
160552217195SDaniel Vetter 	tv_subconnector =
160652217195SDaniel Vetter 		drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
160752217195SDaniel Vetter 				    "subconnector",
160852217195SDaniel Vetter 				    drm_tv_subconnector_enum_list,
160952217195SDaniel Vetter 				    ARRAY_SIZE(drm_tv_subconnector_enum_list));
161052217195SDaniel Vetter 	if (!tv_subconnector)
161152217195SDaniel Vetter 		goto nomem;
161252217195SDaniel Vetter 	dev->mode_config.tv_subconnector_property = tv_subconnector;
161352217195SDaniel Vetter 
161452217195SDaniel Vetter 	/*
161552217195SDaniel Vetter 	 * Other, TV specific properties: margins & TV modes.
161652217195SDaniel Vetter 	 */
16176c4f52dcSBoris Brezillon 	if (drm_mode_create_tv_margin_properties(dev))
161852217195SDaniel Vetter 		goto nomem;
161952217195SDaniel Vetter 
162052217195SDaniel Vetter 	dev->mode_config.tv_mode_property =
162152217195SDaniel Vetter 		drm_property_create(dev, DRM_MODE_PROP_ENUM,
162252217195SDaniel Vetter 				    "mode", num_modes);
162352217195SDaniel Vetter 	if (!dev->mode_config.tv_mode_property)
162452217195SDaniel Vetter 		goto nomem;
162552217195SDaniel Vetter 
162652217195SDaniel Vetter 	for (i = 0; i < num_modes; i++)
162730e9db6dSVille Syrjälä 		drm_property_add_enum(dev->mode_config.tv_mode_property,
162852217195SDaniel Vetter 				      i, modes[i]);
162952217195SDaniel Vetter 
163052217195SDaniel Vetter 	dev->mode_config.tv_brightness_property =
163152217195SDaniel Vetter 		drm_property_create_range(dev, 0, "brightness", 0, 100);
163252217195SDaniel Vetter 	if (!dev->mode_config.tv_brightness_property)
163352217195SDaniel Vetter 		goto nomem;
163452217195SDaniel Vetter 
163552217195SDaniel Vetter 	dev->mode_config.tv_contrast_property =
163652217195SDaniel Vetter 		drm_property_create_range(dev, 0, "contrast", 0, 100);
163752217195SDaniel Vetter 	if (!dev->mode_config.tv_contrast_property)
163852217195SDaniel Vetter 		goto nomem;
163952217195SDaniel Vetter 
164052217195SDaniel Vetter 	dev->mode_config.tv_flicker_reduction_property =
164152217195SDaniel Vetter 		drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
164252217195SDaniel Vetter 	if (!dev->mode_config.tv_flicker_reduction_property)
164352217195SDaniel Vetter 		goto nomem;
164452217195SDaniel Vetter 
164552217195SDaniel Vetter 	dev->mode_config.tv_overscan_property =
164652217195SDaniel Vetter 		drm_property_create_range(dev, 0, "overscan", 0, 100);
164752217195SDaniel Vetter 	if (!dev->mode_config.tv_overscan_property)
164852217195SDaniel Vetter 		goto nomem;
164952217195SDaniel Vetter 
165052217195SDaniel Vetter 	dev->mode_config.tv_saturation_property =
165152217195SDaniel Vetter 		drm_property_create_range(dev, 0, "saturation", 0, 100);
165252217195SDaniel Vetter 	if (!dev->mode_config.tv_saturation_property)
165352217195SDaniel Vetter 		goto nomem;
165452217195SDaniel Vetter 
165552217195SDaniel Vetter 	dev->mode_config.tv_hue_property =
165652217195SDaniel Vetter 		drm_property_create_range(dev, 0, "hue", 0, 100);
165752217195SDaniel Vetter 	if (!dev->mode_config.tv_hue_property)
165852217195SDaniel Vetter 		goto nomem;
165952217195SDaniel Vetter 
166052217195SDaniel Vetter 	return 0;
166152217195SDaniel Vetter nomem:
166252217195SDaniel Vetter 	return -ENOMEM;
166352217195SDaniel Vetter }
166452217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tv_properties);
166552217195SDaniel Vetter 
166652217195SDaniel Vetter /**
166752217195SDaniel Vetter  * drm_mode_create_scaling_mode_property - create scaling mode property
166852217195SDaniel Vetter  * @dev: DRM device
166952217195SDaniel Vetter  *
167052217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
167152217195SDaniel Vetter  * connectors.
16728f6e1e22SMaarten Lankhorst  *
16738f6e1e22SMaarten Lankhorst  * Atomic drivers should use drm_connector_attach_scaling_mode_property()
16749c2fce13SVille Syrjälä  * instead to correctly assign &drm_connector_state.scaling_mode
16758f6e1e22SMaarten Lankhorst  * in the atomic state.
1676f85d9e59SRandy Dunlap  *
1677f85d9e59SRandy Dunlap  * Returns: %0
167852217195SDaniel Vetter  */
167952217195SDaniel Vetter int drm_mode_create_scaling_mode_property(struct drm_device *dev)
168052217195SDaniel Vetter {
168152217195SDaniel Vetter 	struct drm_property *scaling_mode;
168252217195SDaniel Vetter 
168352217195SDaniel Vetter 	if (dev->mode_config.scaling_mode_property)
168452217195SDaniel Vetter 		return 0;
168552217195SDaniel Vetter 
168652217195SDaniel Vetter 	scaling_mode =
168752217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "scaling mode",
168852217195SDaniel Vetter 				drm_scaling_mode_enum_list,
168952217195SDaniel Vetter 				    ARRAY_SIZE(drm_scaling_mode_enum_list));
169052217195SDaniel Vetter 
169152217195SDaniel Vetter 	dev->mode_config.scaling_mode_property = scaling_mode;
169252217195SDaniel Vetter 
169352217195SDaniel Vetter 	return 0;
169452217195SDaniel Vetter }
169552217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
169652217195SDaniel Vetter 
169752217195SDaniel Vetter /**
1698ab7a664fSNicholas Kazlauskas  * DOC: Variable refresh properties
1699ab7a664fSNicholas Kazlauskas  *
1700ab7a664fSNicholas Kazlauskas  * Variable refresh rate capable displays can dynamically adjust their
1701ab7a664fSNicholas Kazlauskas  * refresh rate by extending the duration of their vertical front porch
1702ab7a664fSNicholas Kazlauskas  * until page flip or timeout occurs. This can reduce or remove stuttering
1703ab7a664fSNicholas Kazlauskas  * and latency in scenarios where the page flip does not align with the
1704ab7a664fSNicholas Kazlauskas  * vblank interval.
1705ab7a664fSNicholas Kazlauskas  *
1706ab7a664fSNicholas Kazlauskas  * An example scenario would be an application flipping at a constant rate
1707ab7a664fSNicholas Kazlauskas  * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
1708ab7a664fSNicholas Kazlauskas  * interval and the same contents will be displayed twice. This can be
1709ab7a664fSNicholas Kazlauskas  * observed as stuttering for content with motion.
1710ab7a664fSNicholas Kazlauskas  *
1711ab7a664fSNicholas Kazlauskas  * If variable refresh rate was active on a display that supported a
1712ab7a664fSNicholas Kazlauskas  * variable refresh range from 35Hz to 60Hz no stuttering would be observable
1713ab7a664fSNicholas Kazlauskas  * for the example scenario. The minimum supported variable refresh rate of
1714ab7a664fSNicholas Kazlauskas  * 35Hz is below the page flip frequency and the vertical front porch can
1715ab7a664fSNicholas Kazlauskas  * be extended until the page flip occurs. The vblank interval will be
1716ab7a664fSNicholas Kazlauskas  * directly aligned to the page flip rate.
1717ab7a664fSNicholas Kazlauskas  *
1718ab7a664fSNicholas Kazlauskas  * Not all userspace content is suitable for use with variable refresh rate.
1719ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may worsen
1720ab7a664fSNicholas Kazlauskas  * perceived stuttering for input sensitive applications.
1721ab7a664fSNicholas Kazlauskas  *
1722ab7a664fSNicholas Kazlauskas  * Panel brightness will also vary with vertical front porch duration. Some
1723ab7a664fSNicholas Kazlauskas  * panels may have noticeable differences in brightness between the minimum
1724ab7a664fSNicholas Kazlauskas  * vertical front porch duration and the maximum vertical front porch duration.
1725ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may produce
1726ab7a664fSNicholas Kazlauskas  * observable flickering for such panels.
1727ab7a664fSNicholas Kazlauskas  *
1728ab7a664fSNicholas Kazlauskas  * Userspace control for variable refresh rate is supported via properties
1729ab7a664fSNicholas Kazlauskas  * on the &drm_connector and &drm_crtc objects.
1730ab7a664fSNicholas Kazlauskas  *
1731ab7a664fSNicholas Kazlauskas  * "vrr_capable":
1732ab7a664fSNicholas Kazlauskas  *	Optional &drm_connector boolean property that drivers should attach
1733ab7a664fSNicholas Kazlauskas  *	with drm_connector_attach_vrr_capable_property() on connectors that
1734ab7a664fSNicholas Kazlauskas  *	could support variable refresh rates. Drivers should update the
1735ab7a664fSNicholas Kazlauskas  *	property value by calling drm_connector_set_vrr_capable_property().
1736ab7a664fSNicholas Kazlauskas  *
1737ab7a664fSNicholas Kazlauskas  *	Absence of the property should indicate absence of support.
1738ab7a664fSNicholas Kazlauskas  *
173977086014SDaniel Vetter  * "VRR_ENABLED":
1740ab7a664fSNicholas Kazlauskas  *	Default &drm_crtc boolean property that notifies the driver that the
1741ab7a664fSNicholas Kazlauskas  *	content on the CRTC is suitable for variable refresh rate presentation.
1742ab7a664fSNicholas Kazlauskas  *	The driver will take this property as a hint to enable variable
1743ab7a664fSNicholas Kazlauskas  *	refresh rate support if the receiver supports it, ie. if the
1744ab7a664fSNicholas Kazlauskas  *	"vrr_capable" property is true on the &drm_connector object. The
1745ab7a664fSNicholas Kazlauskas  *	vertical front porch duration will be extended until page-flip or
1746ab7a664fSNicholas Kazlauskas  *	timeout when enabled.
1747ab7a664fSNicholas Kazlauskas  *
1748ab7a664fSNicholas Kazlauskas  *	The minimum vertical front porch duration is defined as the vertical
1749ab7a664fSNicholas Kazlauskas  *	front porch duration for the current mode.
1750ab7a664fSNicholas Kazlauskas  *
1751ab7a664fSNicholas Kazlauskas  *	The maximum vertical front porch duration is greater than or equal to
1752ab7a664fSNicholas Kazlauskas  *	the minimum vertical front porch duration. The duration is derived
1753ab7a664fSNicholas Kazlauskas  *	from the minimum supported variable refresh rate for the connector.
1754ab7a664fSNicholas Kazlauskas  *
1755ab7a664fSNicholas Kazlauskas  *	The driver may place further restrictions within these minimum
1756ab7a664fSNicholas Kazlauskas  *	and maximum bounds.
1757ab7a664fSNicholas Kazlauskas  */
1758ab7a664fSNicholas Kazlauskas 
1759ab7a664fSNicholas Kazlauskas /**
1760ba1b0f6cSNicholas Kazlauskas  * drm_connector_attach_vrr_capable_property - creates the
1761ba1b0f6cSNicholas Kazlauskas  * vrr_capable property
1762ba1b0f6cSNicholas Kazlauskas  * @connector: connector to create the vrr_capable property on.
1763ba1b0f6cSNicholas Kazlauskas  *
1764ba1b0f6cSNicholas Kazlauskas  * This is used by atomic drivers to add support for querying
1765ba1b0f6cSNicholas Kazlauskas  * variable refresh rate capability for a connector.
1766ba1b0f6cSNicholas Kazlauskas  *
1767ba1b0f6cSNicholas Kazlauskas  * Returns:
176884e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
1769ba1b0f6cSNicholas Kazlauskas  */
1770ba1b0f6cSNicholas Kazlauskas int drm_connector_attach_vrr_capable_property(
1771ba1b0f6cSNicholas Kazlauskas 	struct drm_connector *connector)
1772ba1b0f6cSNicholas Kazlauskas {
1773ba1b0f6cSNicholas Kazlauskas 	struct drm_device *dev = connector->dev;
1774ba1b0f6cSNicholas Kazlauskas 	struct drm_property *prop;
1775ba1b0f6cSNicholas Kazlauskas 
1776ba1b0f6cSNicholas Kazlauskas 	if (!connector->vrr_capable_property) {
1777ba1b0f6cSNicholas Kazlauskas 		prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
1778ba1b0f6cSNicholas Kazlauskas 			"vrr_capable");
1779ba1b0f6cSNicholas Kazlauskas 		if (!prop)
1780ba1b0f6cSNicholas Kazlauskas 			return -ENOMEM;
1781ba1b0f6cSNicholas Kazlauskas 
1782ba1b0f6cSNicholas Kazlauskas 		connector->vrr_capable_property = prop;
1783ba1b0f6cSNicholas Kazlauskas 		drm_object_attach_property(&connector->base, prop, 0);
1784ba1b0f6cSNicholas Kazlauskas 	}
1785ba1b0f6cSNicholas Kazlauskas 
1786ba1b0f6cSNicholas Kazlauskas 	return 0;
1787ba1b0f6cSNicholas Kazlauskas }
1788ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
1789ba1b0f6cSNicholas Kazlauskas 
1790ba1b0f6cSNicholas Kazlauskas /**
17918f6e1e22SMaarten Lankhorst  * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
17928f6e1e22SMaarten Lankhorst  * @connector: connector to attach scaling mode property on.
17938f6e1e22SMaarten Lankhorst  * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
17948f6e1e22SMaarten Lankhorst  *
17958f6e1e22SMaarten Lankhorst  * This is used to add support for scaling mode to atomic drivers.
17969c2fce13SVille Syrjälä  * The scaling mode will be set to &drm_connector_state.scaling_mode
17978f6e1e22SMaarten Lankhorst  * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
17988f6e1e22SMaarten Lankhorst  *
17998f6e1e22SMaarten Lankhorst  * This is the atomic version of drm_mode_create_scaling_mode_property().
18008f6e1e22SMaarten Lankhorst  *
18018f6e1e22SMaarten Lankhorst  * Returns:
18028f6e1e22SMaarten Lankhorst  * Zero on success, negative errno on failure.
18038f6e1e22SMaarten Lankhorst  */
18048f6e1e22SMaarten Lankhorst int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
18058f6e1e22SMaarten Lankhorst 					       u32 scaling_mode_mask)
18068f6e1e22SMaarten Lankhorst {
18078f6e1e22SMaarten Lankhorst 	struct drm_device *dev = connector->dev;
18088f6e1e22SMaarten Lankhorst 	struct drm_property *scaling_mode_property;
180930e9db6dSVille Syrjälä 	int i;
18108f6e1e22SMaarten Lankhorst 	const unsigned valid_scaling_mode_mask =
18118f6e1e22SMaarten Lankhorst 		(1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
18128f6e1e22SMaarten Lankhorst 
18138f6e1e22SMaarten Lankhorst 	if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
18148f6e1e22SMaarten Lankhorst 		    scaling_mode_mask & ~valid_scaling_mode_mask))
18158f6e1e22SMaarten Lankhorst 		return -EINVAL;
18168f6e1e22SMaarten Lankhorst 
18178f6e1e22SMaarten Lankhorst 	scaling_mode_property =
18188f6e1e22SMaarten Lankhorst 		drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
18198f6e1e22SMaarten Lankhorst 				    hweight32(scaling_mode_mask));
18208f6e1e22SMaarten Lankhorst 
18218f6e1e22SMaarten Lankhorst 	if (!scaling_mode_property)
18228f6e1e22SMaarten Lankhorst 		return -ENOMEM;
18238f6e1e22SMaarten Lankhorst 
18248f6e1e22SMaarten Lankhorst 	for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
18258f6e1e22SMaarten Lankhorst 		int ret;
18268f6e1e22SMaarten Lankhorst 
18278f6e1e22SMaarten Lankhorst 		if (!(BIT(i) & scaling_mode_mask))
18288f6e1e22SMaarten Lankhorst 			continue;
18298f6e1e22SMaarten Lankhorst 
183030e9db6dSVille Syrjälä 		ret = drm_property_add_enum(scaling_mode_property,
18318f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].type,
18328f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].name);
18338f6e1e22SMaarten Lankhorst 
18348f6e1e22SMaarten Lankhorst 		if (ret) {
18358f6e1e22SMaarten Lankhorst 			drm_property_destroy(dev, scaling_mode_property);
18368f6e1e22SMaarten Lankhorst 
18378f6e1e22SMaarten Lankhorst 			return ret;
18388f6e1e22SMaarten Lankhorst 		}
18398f6e1e22SMaarten Lankhorst 	}
18408f6e1e22SMaarten Lankhorst 
18418f6e1e22SMaarten Lankhorst 	drm_object_attach_property(&connector->base,
18428f6e1e22SMaarten Lankhorst 				   scaling_mode_property, 0);
18438f6e1e22SMaarten Lankhorst 
18448f6e1e22SMaarten Lankhorst 	connector->scaling_mode_property = scaling_mode_property;
18458f6e1e22SMaarten Lankhorst 
18468f6e1e22SMaarten Lankhorst 	return 0;
18478f6e1e22SMaarten Lankhorst }
18488f6e1e22SMaarten Lankhorst EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
18498f6e1e22SMaarten Lankhorst 
18508f6e1e22SMaarten Lankhorst /**
185152217195SDaniel Vetter  * drm_mode_create_aspect_ratio_property - create aspect ratio property
185252217195SDaniel Vetter  * @dev: DRM device
185352217195SDaniel Vetter  *
185452217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
185552217195SDaniel Vetter  * connectors.
185652217195SDaniel Vetter  *
185752217195SDaniel Vetter  * Returns:
185852217195SDaniel Vetter  * Zero on success, negative errno on failure.
185952217195SDaniel Vetter  */
186052217195SDaniel Vetter int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
186152217195SDaniel Vetter {
186252217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property)
186352217195SDaniel Vetter 		return 0;
186452217195SDaniel Vetter 
186552217195SDaniel Vetter 	dev->mode_config.aspect_ratio_property =
186652217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "aspect ratio",
186752217195SDaniel Vetter 				drm_aspect_ratio_enum_list,
186852217195SDaniel Vetter 				ARRAY_SIZE(drm_aspect_ratio_enum_list));
186952217195SDaniel Vetter 
187052217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property == NULL)
187152217195SDaniel Vetter 		return -ENOMEM;
187252217195SDaniel Vetter 
187352217195SDaniel Vetter 	return 0;
187452217195SDaniel Vetter }
187552217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
187652217195SDaniel Vetter 
187752217195SDaniel Vetter /**
1878d2c6a405SUma Shankar  * DOC: standard connector properties
1879d2c6a405SUma Shankar  *
1880d2c6a405SUma Shankar  * Colorspace:
1881d2c6a405SUma Shankar  *     This property helps select a suitable colorspace based on the sink
1882d2c6a405SUma Shankar  *     capability. Modern sink devices support wider gamut like BT2020.
1883d2c6a405SUma Shankar  *     This helps switch to BT2020 mode if the BT2020 encoded video stream
1884d2c6a405SUma Shankar  *     is being played by the user, same for any other colorspace. Thereby
1885d2c6a405SUma Shankar  *     giving a good visual experience to users.
1886d2c6a405SUma Shankar  *
1887d2c6a405SUma Shankar  *     The expectation from userspace is that it should parse the EDID
1888d2c6a405SUma Shankar  *     and get supported colorspaces. Use this property and switch to the
1889d2c6a405SUma Shankar  *     one supported. Sink supported colorspaces should be retrieved by
1890d2c6a405SUma Shankar  *     userspace from EDID and driver will not explicitly expose them.
1891d2c6a405SUma Shankar  *
1892d2c6a405SUma Shankar  *     Basically the expectation from userspace is:
1893d2c6a405SUma Shankar  *      - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink
1894d2c6a405SUma Shankar  *        colorspace
1895d2c6a405SUma Shankar  *      - Set this new property to let the sink know what it
1896d2c6a405SUma Shankar  *        converted the CRTC output to.
1897d2c6a405SUma Shankar  *      - This property is just to inform sink what colorspace
1898d2c6a405SUma Shankar  *        source is trying to drive.
1899d2c6a405SUma Shankar  *
19008806cd3aSGwan-gyeong Mun  * Because between HDMI and DP have different colorspaces,
190145cf0e91SGwan-gyeong Mun  * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and
190245cf0e91SGwan-gyeong Mun  * drm_mode_create_dp_colorspace_property() is used for DP connector.
1903d2c6a405SUma Shankar  */
19048806cd3aSGwan-gyeong Mun 
19058806cd3aSGwan-gyeong Mun /**
19068806cd3aSGwan-gyeong Mun  * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
19078806cd3aSGwan-gyeong Mun  * @connector: connector to create the Colorspace property on.
19088806cd3aSGwan-gyeong Mun  *
19098806cd3aSGwan-gyeong Mun  * Called by a driver the first time it's needed, must be attached to desired
19108806cd3aSGwan-gyeong Mun  * HDMI connectors.
19118806cd3aSGwan-gyeong Mun  *
19128806cd3aSGwan-gyeong Mun  * Returns:
191384e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
19148806cd3aSGwan-gyeong Mun  */
19158806cd3aSGwan-gyeong Mun int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector)
1916d2c6a405SUma Shankar {
1917d2c6a405SUma Shankar 	struct drm_device *dev = connector->dev;
1918d2c6a405SUma Shankar 
19198806cd3aSGwan-gyeong Mun 	if (connector->colorspace_property)
19208806cd3aSGwan-gyeong Mun 		return 0;
19218806cd3aSGwan-gyeong Mun 
19228806cd3aSGwan-gyeong Mun 	connector->colorspace_property =
19238806cd3aSGwan-gyeong Mun 		drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
1924d2c6a405SUma Shankar 					 hdmi_colorspaces,
1925d2c6a405SUma Shankar 					 ARRAY_SIZE(hdmi_colorspaces));
19268806cd3aSGwan-gyeong Mun 
19278806cd3aSGwan-gyeong Mun 	if (!connector->colorspace_property)
1928d2c6a405SUma Shankar 		return -ENOMEM;
1929d2c6a405SUma Shankar 
1930d2c6a405SUma Shankar 	return 0;
1931d2c6a405SUma Shankar }
19328806cd3aSGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
1933d2c6a405SUma Shankar 
1934d2c6a405SUma Shankar /**
193545cf0e91SGwan-gyeong Mun  * drm_mode_create_dp_colorspace_property - create dp colorspace property
193645cf0e91SGwan-gyeong Mun  * @connector: connector to create the Colorspace property on.
193745cf0e91SGwan-gyeong Mun  *
193845cf0e91SGwan-gyeong Mun  * Called by a driver the first time it's needed, must be attached to desired
193945cf0e91SGwan-gyeong Mun  * DP connectors.
194045cf0e91SGwan-gyeong Mun  *
194145cf0e91SGwan-gyeong Mun  * Returns:
194284e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
194345cf0e91SGwan-gyeong Mun  */
194445cf0e91SGwan-gyeong Mun int drm_mode_create_dp_colorspace_property(struct drm_connector *connector)
194545cf0e91SGwan-gyeong Mun {
194645cf0e91SGwan-gyeong Mun 	struct drm_device *dev = connector->dev;
194745cf0e91SGwan-gyeong Mun 
194845cf0e91SGwan-gyeong Mun 	if (connector->colorspace_property)
194945cf0e91SGwan-gyeong Mun 		return 0;
195045cf0e91SGwan-gyeong Mun 
195145cf0e91SGwan-gyeong Mun 	connector->colorspace_property =
195245cf0e91SGwan-gyeong Mun 		drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
195345cf0e91SGwan-gyeong Mun 					 dp_colorspaces,
195445cf0e91SGwan-gyeong Mun 					 ARRAY_SIZE(dp_colorspaces));
195545cf0e91SGwan-gyeong Mun 
195645cf0e91SGwan-gyeong Mun 	if (!connector->colorspace_property)
195745cf0e91SGwan-gyeong Mun 		return -ENOMEM;
195845cf0e91SGwan-gyeong Mun 
195945cf0e91SGwan-gyeong Mun 	return 0;
196045cf0e91SGwan-gyeong Mun }
196145cf0e91SGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
196252217195SDaniel Vetter 
196397e14fbeSDaniel Vetter /**
196452217195SDaniel Vetter  * drm_mode_create_content_type_property - create content type property
196552217195SDaniel Vetter  * @dev: DRM device
196697e14fbeSDaniel Vetter  *
196752217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
196852217195SDaniel Vetter  * connectors.
196952217195SDaniel Vetter  *
197052217195SDaniel Vetter  * Returns:
197152217195SDaniel Vetter  * Zero on success, negative errno on failure.
197252217195SDaniel Vetter  */
197352217195SDaniel Vetter int drm_mode_create_content_type_property(struct drm_device *dev)
197452217195SDaniel Vetter {
197552217195SDaniel Vetter 	if (dev->mode_config.content_type_property)
197697e14fbeSDaniel Vetter 		return 0;
197752217195SDaniel Vetter 
197852217195SDaniel Vetter 	dev->mode_config.content_type_property =
197952217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "content type",
198052217195SDaniel Vetter 					 drm_content_type_enum_list,
198152217195SDaniel Vetter 					 ARRAY_SIZE(drm_content_type_enum_list));
198252217195SDaniel Vetter 
198352217195SDaniel Vetter 	if (dev->mode_config.content_type_property == NULL)
198452217195SDaniel Vetter 		return -ENOMEM;
198552217195SDaniel Vetter 
198652217195SDaniel Vetter 	return 0;
198752217195SDaniel Vetter }
198852217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_content_type_property);
198952217195SDaniel Vetter 
199052217195SDaniel Vetter /**
199152217195SDaniel Vetter  * drm_mode_create_suggested_offset_properties - create suggests offset properties
199252217195SDaniel Vetter  * @dev: DRM device
199352217195SDaniel Vetter  *
199484e543bcSAntonio Borneo  * Create the suggested x/y offset property for connectors.
1995f85d9e59SRandy Dunlap  *
1996f85d9e59SRandy Dunlap  * Returns:
1997f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
199852217195SDaniel Vetter  */
199952217195SDaniel Vetter int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
200052217195SDaniel Vetter {
200152217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
200252217195SDaniel Vetter 		return 0;
200352217195SDaniel Vetter 
200452217195SDaniel Vetter 	dev->mode_config.suggested_x_property =
200552217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
200652217195SDaniel Vetter 
200752217195SDaniel Vetter 	dev->mode_config.suggested_y_property =
200852217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
200952217195SDaniel Vetter 
201052217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property == NULL ||
201152217195SDaniel Vetter 	    dev->mode_config.suggested_y_property == NULL)
201252217195SDaniel Vetter 		return -ENOMEM;
201352217195SDaniel Vetter 	return 0;
201452217195SDaniel Vetter }
201552217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
201652217195SDaniel Vetter 
201752217195SDaniel Vetter /**
201852217195SDaniel Vetter  * drm_connector_set_path_property - set tile property on connector
201952217195SDaniel Vetter  * @connector: connector to set property on.
202052217195SDaniel Vetter  * @path: path to use for property; must not be NULL.
202152217195SDaniel Vetter  *
202252217195SDaniel Vetter  * This creates a property to expose to userspace to specify a
202352217195SDaniel Vetter  * connector path. This is mainly used for DisplayPort MST where
202452217195SDaniel Vetter  * connectors have a topology and we want to allow userspace to give
202552217195SDaniel Vetter  * them more meaningful names.
202652217195SDaniel Vetter  *
202752217195SDaniel Vetter  * Returns:
202852217195SDaniel Vetter  * Zero on success, negative errno on failure.
202952217195SDaniel Vetter  */
203052217195SDaniel Vetter int drm_connector_set_path_property(struct drm_connector *connector,
203152217195SDaniel Vetter 				    const char *path)
203252217195SDaniel Vetter {
203352217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
203452217195SDaniel Vetter 	int ret;
203552217195SDaniel Vetter 
203652217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
203752217195SDaniel Vetter 					       &connector->path_blob_ptr,
203852217195SDaniel Vetter 					       strlen(path) + 1,
203952217195SDaniel Vetter 					       path,
204052217195SDaniel Vetter 					       &connector->base,
204152217195SDaniel Vetter 					       dev->mode_config.path_property);
204252217195SDaniel Vetter 	return ret;
204352217195SDaniel Vetter }
204452217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_set_path_property);
204552217195SDaniel Vetter 
204652217195SDaniel Vetter /**
204752217195SDaniel Vetter  * drm_connector_set_tile_property - set tile property on connector
204852217195SDaniel Vetter  * @connector: connector to set property on.
204952217195SDaniel Vetter  *
205052217195SDaniel Vetter  * This looks up the tile information for a connector, and creates a
205152217195SDaniel Vetter  * property for userspace to parse if it exists. The property is of
205252217195SDaniel Vetter  * the form of 8 integers using ':' as a separator.
20532de3a078SManasi Navare  * This is used for dual port tiled displays with DisplayPort SST
20542de3a078SManasi Navare  * or DisplayPort MST connectors.
205552217195SDaniel Vetter  *
205652217195SDaniel Vetter  * Returns:
205752217195SDaniel Vetter  * Zero on success, errno on failure.
205852217195SDaniel Vetter  */
205952217195SDaniel Vetter int drm_connector_set_tile_property(struct drm_connector *connector)
206052217195SDaniel Vetter {
206152217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
206252217195SDaniel Vetter 	char tile[256];
206352217195SDaniel Vetter 	int ret;
206452217195SDaniel Vetter 
206552217195SDaniel Vetter 	if (!connector->has_tile) {
206652217195SDaniel Vetter 		ret  = drm_property_replace_global_blob(dev,
206752217195SDaniel Vetter 							&connector->tile_blob_ptr,
206852217195SDaniel Vetter 							0,
206952217195SDaniel Vetter 							NULL,
207052217195SDaniel Vetter 							&connector->base,
207152217195SDaniel Vetter 							dev->mode_config.tile_property);
207252217195SDaniel Vetter 		return ret;
207352217195SDaniel Vetter 	}
207452217195SDaniel Vetter 
207552217195SDaniel Vetter 	snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
207652217195SDaniel Vetter 		 connector->tile_group->id, connector->tile_is_single_monitor,
207752217195SDaniel Vetter 		 connector->num_h_tile, connector->num_v_tile,
207852217195SDaniel Vetter 		 connector->tile_h_loc, connector->tile_v_loc,
207952217195SDaniel Vetter 		 connector->tile_h_size, connector->tile_v_size);
208052217195SDaniel Vetter 
208152217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
208252217195SDaniel Vetter 					       &connector->tile_blob_ptr,
208352217195SDaniel Vetter 					       strlen(tile) + 1,
208452217195SDaniel Vetter 					       tile,
208552217195SDaniel Vetter 					       &connector->base,
208652217195SDaniel Vetter 					       dev->mode_config.tile_property);
208752217195SDaniel Vetter 	return ret;
208852217195SDaniel Vetter }
208997e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_tile_property);
209052217195SDaniel Vetter 
209152217195SDaniel Vetter /**
209297e14fbeSDaniel Vetter  * drm_connector_set_link_status_property - Set link status property of a connector
209340ee6fbeSManasi Navare  * @connector: drm connector
209440ee6fbeSManasi Navare  * @link_status: new value of link status property (0: Good, 1: Bad)
209540ee6fbeSManasi Navare  *
209640ee6fbeSManasi Navare  * In usual working scenario, this link status property will always be set to
209740ee6fbeSManasi Navare  * "GOOD". If something fails during or after a mode set, the kernel driver
209840ee6fbeSManasi Navare  * may set this link status property to "BAD". The caller then needs to send a
209940ee6fbeSManasi Navare  * hotplug uevent for userspace to re-check the valid modes through
210040ee6fbeSManasi Navare  * GET_CONNECTOR_IOCTL and retry modeset.
210140ee6fbeSManasi Navare  *
210240ee6fbeSManasi Navare  * Note: Drivers cannot rely on userspace to support this property and
210340ee6fbeSManasi Navare  * issue a modeset. As such, they may choose to handle issues (like
210440ee6fbeSManasi Navare  * re-training a link) without userspace's intervention.
210540ee6fbeSManasi Navare  *
210640ee6fbeSManasi Navare  * The reason for adding this property is to handle link training failures, but
210740ee6fbeSManasi Navare  * it is not limited to DP or link training. For example, if we implement
210840ee6fbeSManasi Navare  * asynchronous setcrtc, this property can be used to report any failures in that.
210940ee6fbeSManasi Navare  */
211097e14fbeSDaniel Vetter void drm_connector_set_link_status_property(struct drm_connector *connector,
211140ee6fbeSManasi Navare 					    uint64_t link_status)
211240ee6fbeSManasi Navare {
211340ee6fbeSManasi Navare 	struct drm_device *dev = connector->dev;
211440ee6fbeSManasi Navare 
211540ee6fbeSManasi Navare 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
211640ee6fbeSManasi Navare 	connector->state->link_status = link_status;
211740ee6fbeSManasi Navare 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
211840ee6fbeSManasi Navare }
211997e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_link_status_property);
212040ee6fbeSManasi Navare 
21218d70f395SHans de Goede /**
212247e22ff1SRadhakrishna Sripada  * drm_connector_attach_max_bpc_property - attach "max bpc" property
212347e22ff1SRadhakrishna Sripada  * @connector: connector to attach max bpc property on.
212447e22ff1SRadhakrishna Sripada  * @min: The minimum bit depth supported by the connector.
212547e22ff1SRadhakrishna Sripada  * @max: The maximum bit depth supported by the connector.
212647e22ff1SRadhakrishna Sripada  *
212747e22ff1SRadhakrishna Sripada  * This is used to add support for limiting the bit depth on a connector.
212847e22ff1SRadhakrishna Sripada  *
212947e22ff1SRadhakrishna Sripada  * Returns:
213047e22ff1SRadhakrishna Sripada  * Zero on success, negative errno on failure.
213147e22ff1SRadhakrishna Sripada  */
213247e22ff1SRadhakrishna Sripada int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
213347e22ff1SRadhakrishna Sripada 					  int min, int max)
213447e22ff1SRadhakrishna Sripada {
213547e22ff1SRadhakrishna Sripada 	struct drm_device *dev = connector->dev;
213647e22ff1SRadhakrishna Sripada 	struct drm_property *prop;
213747e22ff1SRadhakrishna Sripada 
213847e22ff1SRadhakrishna Sripada 	prop = connector->max_bpc_property;
213947e22ff1SRadhakrishna Sripada 	if (!prop) {
214047e22ff1SRadhakrishna Sripada 		prop = drm_property_create_range(dev, 0, "max bpc", min, max);
214147e22ff1SRadhakrishna Sripada 		if (!prop)
214247e22ff1SRadhakrishna Sripada 			return -ENOMEM;
214347e22ff1SRadhakrishna Sripada 
214447e22ff1SRadhakrishna Sripada 		connector->max_bpc_property = prop;
214547e22ff1SRadhakrishna Sripada 	}
214647e22ff1SRadhakrishna Sripada 
214747e22ff1SRadhakrishna Sripada 	drm_object_attach_property(&connector->base, prop, max);
214847e22ff1SRadhakrishna Sripada 	connector->state->max_requested_bpc = max;
214947e22ff1SRadhakrishna Sripada 	connector->state->max_bpc = max;
215047e22ff1SRadhakrishna Sripada 
215147e22ff1SRadhakrishna Sripada 	return 0;
215247e22ff1SRadhakrishna Sripada }
215347e22ff1SRadhakrishna Sripada EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
215447e22ff1SRadhakrishna Sripada 
215547e22ff1SRadhakrishna Sripada /**
2156e057b52cSMaxime Ripard  * drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADA" property
2157e057b52cSMaxime Ripard  * @connector: connector to attach the property on.
2158e057b52cSMaxime Ripard  *
2159e057b52cSMaxime Ripard  * This is used to allow the userspace to send HDR Metadata to the
2160e057b52cSMaxime Ripard  * driver.
2161e057b52cSMaxime Ripard  *
2162e057b52cSMaxime Ripard  * Returns:
2163e057b52cSMaxime Ripard  * Zero on success, negative errno on failure.
2164e057b52cSMaxime Ripard  */
2165e057b52cSMaxime Ripard int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector)
2166e057b52cSMaxime Ripard {
2167e057b52cSMaxime Ripard 	struct drm_device *dev = connector->dev;
2168e057b52cSMaxime Ripard 	struct drm_property *prop = dev->mode_config.hdr_output_metadata_property;
2169e057b52cSMaxime Ripard 
2170e057b52cSMaxime Ripard 	drm_object_attach_property(&connector->base, prop, 0);
2171e057b52cSMaxime Ripard 
2172e057b52cSMaxime Ripard 	return 0;
2173e057b52cSMaxime Ripard }
2174e057b52cSMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property);
2175e057b52cSMaxime Ripard 
2176e057b52cSMaxime Ripard /**
217721f79128SMaxime Ripard  * drm_connector_attach_colorspace_property - attach "Colorspace" property
217821f79128SMaxime Ripard  * @connector: connector to attach the property on.
217921f79128SMaxime Ripard  *
218021f79128SMaxime Ripard  * This is used to allow the userspace to signal the output colorspace
218121f79128SMaxime Ripard  * to the driver.
218221f79128SMaxime Ripard  *
218321f79128SMaxime Ripard  * Returns:
218421f79128SMaxime Ripard  * Zero on success, negative errno on failure.
218521f79128SMaxime Ripard  */
218621f79128SMaxime Ripard int drm_connector_attach_colorspace_property(struct drm_connector *connector)
218721f79128SMaxime Ripard {
218821f79128SMaxime Ripard 	struct drm_property *prop = connector->colorspace_property;
218921f79128SMaxime Ripard 
219021f79128SMaxime Ripard 	drm_object_attach_property(&connector->base, prop, DRM_MODE_COLORIMETRY_DEFAULT);
219121f79128SMaxime Ripard 
219221f79128SMaxime Ripard 	return 0;
219321f79128SMaxime Ripard }
219421f79128SMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_colorspace_property);
219521f79128SMaxime Ripard 
219621f79128SMaxime Ripard /**
219772921cdfSMaxime Ripard  * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed
219872921cdfSMaxime Ripard  * @old_state: old connector state to compare
219972921cdfSMaxime Ripard  * @new_state: new connector state to compare
220072921cdfSMaxime Ripard  *
220172921cdfSMaxime Ripard  * This is used by HDR-enabled drivers to test whether the HDR metadata
220272921cdfSMaxime Ripard  * have changed between two different connector state (and thus probably
220372921cdfSMaxime Ripard  * requires a full blown mode change).
220472921cdfSMaxime Ripard  *
220572921cdfSMaxime Ripard  * Returns:
220672921cdfSMaxime Ripard  * True if the metadata are equal, False otherwise
220772921cdfSMaxime Ripard  */
220872921cdfSMaxime Ripard bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state,
220972921cdfSMaxime Ripard 					     struct drm_connector_state *new_state)
221072921cdfSMaxime Ripard {
221172921cdfSMaxime Ripard 	struct drm_property_blob *old_blob = old_state->hdr_output_metadata;
221272921cdfSMaxime Ripard 	struct drm_property_blob *new_blob = new_state->hdr_output_metadata;
221372921cdfSMaxime Ripard 
221472921cdfSMaxime Ripard 	if (!old_blob || !new_blob)
221572921cdfSMaxime Ripard 		return old_blob == new_blob;
221672921cdfSMaxime Ripard 
221772921cdfSMaxime Ripard 	if (old_blob->length != new_blob->length)
221872921cdfSMaxime Ripard 		return false;
221972921cdfSMaxime Ripard 
222072921cdfSMaxime Ripard 	return !memcmp(old_blob->data, new_blob->data, old_blob->length);
222172921cdfSMaxime Ripard }
222272921cdfSMaxime Ripard EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal);
222372921cdfSMaxime Ripard 
222472921cdfSMaxime Ripard /**
2225ba1b0f6cSNicholas Kazlauskas  * drm_connector_set_vrr_capable_property - sets the variable refresh rate
2226ba1b0f6cSNicholas Kazlauskas  * capable property for a connector
2227ba1b0f6cSNicholas Kazlauskas  * @connector: drm connector
2228ba1b0f6cSNicholas Kazlauskas  * @capable: True if the connector is variable refresh rate capable
2229ba1b0f6cSNicholas Kazlauskas  *
2230ba1b0f6cSNicholas Kazlauskas  * Should be used by atomic drivers to update the indicated support for
2231ba1b0f6cSNicholas Kazlauskas  * variable refresh rate over a connector.
2232ba1b0f6cSNicholas Kazlauskas  */
2233ba1b0f6cSNicholas Kazlauskas void drm_connector_set_vrr_capable_property(
2234ba1b0f6cSNicholas Kazlauskas 		struct drm_connector *connector, bool capable)
2235ba1b0f6cSNicholas Kazlauskas {
223662929726SManasi Navare 	if (!connector->vrr_capable_property)
223762929726SManasi Navare 		return;
223862929726SManasi Navare 
2239ba1b0f6cSNicholas Kazlauskas 	drm_object_property_set_value(&connector->base,
2240ba1b0f6cSNicholas Kazlauskas 				      connector->vrr_capable_property,
2241ba1b0f6cSNicholas Kazlauskas 				      capable);
2242ba1b0f6cSNicholas Kazlauskas }
2243ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
2244ba1b0f6cSNicholas Kazlauskas 
2245ba1b0f6cSNicholas Kazlauskas /**
224684e543bcSAntonio Borneo  * drm_connector_set_panel_orientation - sets the connector's panel_orientation
224769654c63SDerek Basehore  * @connector: connector for which to set the panel-orientation property.
224869654c63SDerek Basehore  * @panel_orientation: drm_panel_orientation value to set
22498d70f395SHans de Goede  *
225069654c63SDerek Basehore  * This function sets the connector's panel_orientation and attaches
225169654c63SDerek Basehore  * a "panel orientation" property to the connector.
22528d70f395SHans de Goede  *
225369654c63SDerek Basehore  * Calling this function on a connector where the panel_orientation has
225469654c63SDerek Basehore  * already been set is a no-op (e.g. the orientation has been overridden with
225569654c63SDerek Basehore  * a kernel commandline option).
225669654c63SDerek Basehore  *
225769654c63SDerek Basehore  * It is allowed to call this function with a panel_orientation of
225869654c63SDerek Basehore  * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
22598d70f395SHans de Goede  *
22605e41b01aSHsin-Yi Wang  * The function shouldn't be called in panel after drm is registered (i.e.
22615e41b01aSHsin-Yi Wang  * drm_dev_register() is called in drm).
22625e41b01aSHsin-Yi Wang  *
22638d70f395SHans de Goede  * Returns:
22648d70f395SHans de Goede  * Zero on success, negative errno on failure.
22658d70f395SHans de Goede  */
226669654c63SDerek Basehore int drm_connector_set_panel_orientation(
226769654c63SDerek Basehore 	struct drm_connector *connector,
226869654c63SDerek Basehore 	enum drm_panel_orientation panel_orientation)
22698d70f395SHans de Goede {
22708d70f395SHans de Goede 	struct drm_device *dev = connector->dev;
22718d70f395SHans de Goede 	struct drm_display_info *info = &connector->display_info;
22728d70f395SHans de Goede 	struct drm_property *prop;
22738d70f395SHans de Goede 
227469654c63SDerek Basehore 	/* Already set? */
227569654c63SDerek Basehore 	if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
22768d70f395SHans de Goede 		return 0;
22778d70f395SHans de Goede 
227869654c63SDerek Basehore 	/* Don't attach the property if the orientation is unknown */
227969654c63SDerek Basehore 	if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
228069654c63SDerek Basehore 		return 0;
228169654c63SDerek Basehore 
228269654c63SDerek Basehore 	info->panel_orientation = panel_orientation;
228369654c63SDerek Basehore 
22848d70f395SHans de Goede 	prop = dev->mode_config.panel_orientation_property;
22858d70f395SHans de Goede 	if (!prop) {
22868d70f395SHans de Goede 		prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
22878d70f395SHans de Goede 				"panel orientation",
22888d70f395SHans de Goede 				drm_panel_orientation_enum_list,
22898d70f395SHans de Goede 				ARRAY_SIZE(drm_panel_orientation_enum_list));
22908d70f395SHans de Goede 		if (!prop)
22918d70f395SHans de Goede 			return -ENOMEM;
22928d70f395SHans de Goede 
22938d70f395SHans de Goede 		dev->mode_config.panel_orientation_property = prop;
22948d70f395SHans de Goede 	}
22958d70f395SHans de Goede 
22968d70f395SHans de Goede 	drm_object_attach_property(&connector->base, prop,
22978d70f395SHans de Goede 				   info->panel_orientation);
22988d70f395SHans de Goede 	return 0;
22998d70f395SHans de Goede }
230069654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation);
230169654c63SDerek Basehore 
230269654c63SDerek Basehore /**
2303f85d9e59SRandy Dunlap  * drm_connector_set_panel_orientation_with_quirk - set the
2304f85d9e59SRandy Dunlap  *	connector's panel_orientation after checking for quirks
230569654c63SDerek Basehore  * @connector: connector for which to init the panel-orientation property.
230669654c63SDerek Basehore  * @panel_orientation: drm_panel_orientation value to set
230769654c63SDerek Basehore  * @width: width in pixels of the panel, used for panel quirk detection
230869654c63SDerek Basehore  * @height: height in pixels of the panel, used for panel quirk detection
230969654c63SDerek Basehore  *
231069654c63SDerek Basehore  * Like drm_connector_set_panel_orientation(), but with a check for platform
231169654c63SDerek Basehore  * specific (e.g. DMI based) quirks overriding the passed in panel_orientation.
231269654c63SDerek Basehore  *
231369654c63SDerek Basehore  * Returns:
231469654c63SDerek Basehore  * Zero on success, negative errno on failure.
231569654c63SDerek Basehore  */
231669654c63SDerek Basehore int drm_connector_set_panel_orientation_with_quirk(
231769654c63SDerek Basehore 	struct drm_connector *connector,
231869654c63SDerek Basehore 	enum drm_panel_orientation panel_orientation,
231969654c63SDerek Basehore 	int width, int height)
232069654c63SDerek Basehore {
232169654c63SDerek Basehore 	int orientation_quirk;
232269654c63SDerek Basehore 
232369654c63SDerek Basehore 	orientation_quirk = drm_get_panel_orientation_quirk(width, height);
232469654c63SDerek Basehore 	if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
232569654c63SDerek Basehore 		panel_orientation = orientation_quirk;
232669654c63SDerek Basehore 
232769654c63SDerek Basehore 	return drm_connector_set_panel_orientation(connector,
232869654c63SDerek Basehore 						   panel_orientation);
232969654c63SDerek Basehore }
233069654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
23318d70f395SHans de Goede 
23325e41b01aSHsin-Yi Wang /**
23335e41b01aSHsin-Yi Wang  * drm_connector_set_orientation_from_panel -
23345e41b01aSHsin-Yi Wang  *	set the connector's panel_orientation from panel's callback.
23355e41b01aSHsin-Yi Wang  * @connector: connector for which to init the panel-orientation property.
23365e41b01aSHsin-Yi Wang  * @panel: panel that can provide orientation information.
23375e41b01aSHsin-Yi Wang  *
23385e41b01aSHsin-Yi Wang  * Drm drivers should call this function before drm_dev_register().
23395e41b01aSHsin-Yi Wang  * Orientation is obtained from panel's .get_orientation() callback.
23405e41b01aSHsin-Yi Wang  *
23415e41b01aSHsin-Yi Wang  * Returns:
23425e41b01aSHsin-Yi Wang  * Zero on success, negative errno on failure.
23435e41b01aSHsin-Yi Wang  */
23445e41b01aSHsin-Yi Wang int drm_connector_set_orientation_from_panel(
23455e41b01aSHsin-Yi Wang 	struct drm_connector *connector,
23465e41b01aSHsin-Yi Wang 	struct drm_panel *panel)
23475e41b01aSHsin-Yi Wang {
23485e41b01aSHsin-Yi Wang 	enum drm_panel_orientation orientation;
23495e41b01aSHsin-Yi Wang 
23505e41b01aSHsin-Yi Wang 	if (panel && panel->funcs && panel->funcs->get_orientation)
23515e41b01aSHsin-Yi Wang 		orientation = panel->funcs->get_orientation(panel);
23525e41b01aSHsin-Yi Wang 	else
23535e41b01aSHsin-Yi Wang 		orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
23545e41b01aSHsin-Yi Wang 
23555e41b01aSHsin-Yi Wang 	return drm_connector_set_panel_orientation(connector, orientation);
23565e41b01aSHsin-Yi Wang }
23575e41b01aSHsin-Yi Wang EXPORT_SYMBOL(drm_connector_set_orientation_from_panel);
23585e41b01aSHsin-Yi Wang 
2359107fe904SRajat Jain static const struct drm_prop_enum_list privacy_screen_enum[] = {
2360107fe904SRajat Jain 	{ PRIVACY_SCREEN_DISABLED,		"Disabled" },
2361107fe904SRajat Jain 	{ PRIVACY_SCREEN_ENABLED,		"Enabled" },
2362107fe904SRajat Jain 	{ PRIVACY_SCREEN_DISABLED_LOCKED,	"Disabled-locked" },
2363107fe904SRajat Jain 	{ PRIVACY_SCREEN_ENABLED_LOCKED,	"Enabled-locked" },
2364107fe904SRajat Jain };
2365107fe904SRajat Jain 
2366107fe904SRajat Jain /**
2367107fe904SRajat Jain  * drm_connector_create_privacy_screen_properties - create the drm connecter's
2368107fe904SRajat Jain  *    privacy-screen properties.
2369107fe904SRajat Jain  * @connector: connector for which to create the privacy-screen properties
2370107fe904SRajat Jain  *
2371107fe904SRajat Jain  * This function creates the "privacy-screen sw-state" and "privacy-screen
2372107fe904SRajat Jain  * hw-state" properties for the connector. They are not attached.
2373107fe904SRajat Jain  */
2374107fe904SRajat Jain void
2375107fe904SRajat Jain drm_connector_create_privacy_screen_properties(struct drm_connector *connector)
2376107fe904SRajat Jain {
2377107fe904SRajat Jain 	if (connector->privacy_screen_sw_state_property)
2378107fe904SRajat Jain 		return;
2379107fe904SRajat Jain 
2380107fe904SRajat Jain 	/* Note sw-state only supports the first 2 values of the enum */
2381107fe904SRajat Jain 	connector->privacy_screen_sw_state_property =
2382107fe904SRajat Jain 		drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM,
2383107fe904SRajat Jain 				"privacy-screen sw-state",
2384107fe904SRajat Jain 				privacy_screen_enum, 2);
2385107fe904SRajat Jain 
2386107fe904SRajat Jain 	connector->privacy_screen_hw_state_property =
2387107fe904SRajat Jain 		drm_property_create_enum(connector->dev,
2388107fe904SRajat Jain 				DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM,
2389107fe904SRajat Jain 				"privacy-screen hw-state",
2390107fe904SRajat Jain 				privacy_screen_enum,
2391107fe904SRajat Jain 				ARRAY_SIZE(privacy_screen_enum));
2392107fe904SRajat Jain }
2393107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties);
2394107fe904SRajat Jain 
2395107fe904SRajat Jain /**
2396107fe904SRajat Jain  * drm_connector_attach_privacy_screen_properties - attach the drm connecter's
2397107fe904SRajat Jain  *    privacy-screen properties.
2398107fe904SRajat Jain  * @connector: connector on which to attach the privacy-screen properties
2399107fe904SRajat Jain  *
2400107fe904SRajat Jain  * This function attaches the "privacy-screen sw-state" and "privacy-screen
2401107fe904SRajat Jain  * hw-state" properties to the connector. The initial state of both is set
2402107fe904SRajat Jain  * to "Disabled".
2403107fe904SRajat Jain  */
2404107fe904SRajat Jain void
2405107fe904SRajat Jain drm_connector_attach_privacy_screen_properties(struct drm_connector *connector)
2406107fe904SRajat Jain {
2407107fe904SRajat Jain 	if (!connector->privacy_screen_sw_state_property)
2408107fe904SRajat Jain 		return;
2409107fe904SRajat Jain 
2410107fe904SRajat Jain 	drm_object_attach_property(&connector->base,
2411107fe904SRajat Jain 				   connector->privacy_screen_sw_state_property,
2412107fe904SRajat Jain 				   PRIVACY_SCREEN_DISABLED);
2413107fe904SRajat Jain 
2414107fe904SRajat Jain 	drm_object_attach_property(&connector->base,
2415107fe904SRajat Jain 				   connector->privacy_screen_hw_state_property,
2416107fe904SRajat Jain 				   PRIVACY_SCREEN_DISABLED);
2417107fe904SRajat Jain }
2418107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties);
2419107fe904SRajat Jain 
2420334f74eeSHans de Goede static void drm_connector_update_privacy_screen_properties(
2421334f74eeSHans de Goede 	struct drm_connector *connector, bool set_sw_state)
2422334f74eeSHans de Goede {
2423334f74eeSHans de Goede 	enum drm_privacy_screen_status sw_state, hw_state;
2424334f74eeSHans de Goede 
2425334f74eeSHans de Goede 	drm_privacy_screen_get_state(connector->privacy_screen,
2426334f74eeSHans de Goede 				     &sw_state, &hw_state);
2427334f74eeSHans de Goede 
2428334f74eeSHans de Goede 	if (set_sw_state)
2429334f74eeSHans de Goede 		connector->state->privacy_screen_sw_state = sw_state;
2430334f74eeSHans de Goede 	drm_object_property_set_value(&connector->base,
2431334f74eeSHans de Goede 			connector->privacy_screen_hw_state_property, hw_state);
2432334f74eeSHans de Goede }
2433334f74eeSHans de Goede 
2434334f74eeSHans de Goede static int drm_connector_privacy_screen_notifier(
2435334f74eeSHans de Goede 	struct notifier_block *nb, unsigned long action, void *data)
2436334f74eeSHans de Goede {
2437334f74eeSHans de Goede 	struct drm_connector *connector =
2438334f74eeSHans de Goede 		container_of(nb, struct drm_connector, privacy_screen_notifier);
2439334f74eeSHans de Goede 	struct drm_device *dev = connector->dev;
2440334f74eeSHans de Goede 
2441334f74eeSHans de Goede 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2442334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, true);
2443334f74eeSHans de Goede 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
2444334f74eeSHans de Goede 
2445334f74eeSHans de Goede 	drm_sysfs_connector_status_event(connector,
2446334f74eeSHans de Goede 				connector->privacy_screen_sw_state_property);
2447334f74eeSHans de Goede 	drm_sysfs_connector_status_event(connector,
2448334f74eeSHans de Goede 				connector->privacy_screen_hw_state_property);
2449334f74eeSHans de Goede 
2450334f74eeSHans de Goede 	return NOTIFY_DONE;
2451334f74eeSHans de Goede }
2452334f74eeSHans de Goede 
2453334f74eeSHans de Goede /**
2454334f74eeSHans de Goede  * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to
2455334f74eeSHans de Goede  *    the connector
2456334f74eeSHans de Goede  * @connector: connector to attach the privacy-screen to
2457334f74eeSHans de Goede  * @priv: drm_privacy_screen to attach
2458334f74eeSHans de Goede  *
2459334f74eeSHans de Goede  * Create and attach the standard privacy-screen properties and register
2460334f74eeSHans de Goede  * a generic notifier for generating sysfs-connector-status-events
2461334f74eeSHans de Goede  * on external changes to the privacy-screen status.
2462334f74eeSHans de Goede  * This function takes ownership of the passed in drm_privacy_screen and will
2463334f74eeSHans de Goede  * call drm_privacy_screen_put() on it when the connector is destroyed.
2464334f74eeSHans de Goede  */
2465334f74eeSHans de Goede void drm_connector_attach_privacy_screen_provider(
2466334f74eeSHans de Goede 	struct drm_connector *connector, struct drm_privacy_screen *priv)
2467334f74eeSHans de Goede {
2468334f74eeSHans de Goede 	connector->privacy_screen = priv;
2469334f74eeSHans de Goede 	connector->privacy_screen_notifier.notifier_call =
2470334f74eeSHans de Goede 		drm_connector_privacy_screen_notifier;
2471334f74eeSHans de Goede 
2472334f74eeSHans de Goede 	drm_connector_create_privacy_screen_properties(connector);
2473334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, true);
2474334f74eeSHans de Goede 	drm_connector_attach_privacy_screen_properties(connector);
2475334f74eeSHans de Goede }
2476334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider);
2477334f74eeSHans de Goede 
2478334f74eeSHans de Goede /**
2479334f74eeSHans de Goede  * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state
2480334f74eeSHans de Goede  * @connector_state: connector-state to update the privacy-screen for
2481334f74eeSHans de Goede  *
2482334f74eeSHans de Goede  * This function calls drm_privacy_screen_set_sw_state() on the connector's
2483334f74eeSHans de Goede  * privacy-screen.
2484334f74eeSHans de Goede  *
2485334f74eeSHans de Goede  * If the connector has no privacy-screen, then this is a no-op.
2486334f74eeSHans de Goede  */
2487334f74eeSHans de Goede void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state)
2488334f74eeSHans de Goede {
2489334f74eeSHans de Goede 	struct drm_connector *connector = connector_state->connector;
2490334f74eeSHans de Goede 	int ret;
2491334f74eeSHans de Goede 
2492334f74eeSHans de Goede 	if (!connector->privacy_screen)
2493334f74eeSHans de Goede 		return;
2494334f74eeSHans de Goede 
2495334f74eeSHans de Goede 	ret = drm_privacy_screen_set_sw_state(connector->privacy_screen,
2496334f74eeSHans de Goede 					      connector_state->privacy_screen_sw_state);
2497334f74eeSHans de Goede 	if (ret) {
2498334f74eeSHans de Goede 		drm_err(connector->dev, "Error updating privacy-screen sw_state\n");
2499334f74eeSHans de Goede 		return;
2500334f74eeSHans de Goede 	}
2501334f74eeSHans de Goede 
2502334f74eeSHans de Goede 	/* The hw_state property value may have changed, update it. */
2503334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, false);
2504334f74eeSHans de Goede }
2505334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_update_privacy_screen);
2506334f74eeSHans de Goede 
250797e14fbeSDaniel Vetter int drm_connector_set_obj_prop(struct drm_mode_object *obj,
250852217195SDaniel Vetter 				    struct drm_property *property,
250952217195SDaniel Vetter 				    uint64_t value)
251052217195SDaniel Vetter {
251152217195SDaniel Vetter 	int ret = -EINVAL;
251252217195SDaniel Vetter 	struct drm_connector *connector = obj_to_connector(obj);
251352217195SDaniel Vetter 
251452217195SDaniel Vetter 	/* Do DPMS ourselves */
251552217195SDaniel Vetter 	if (property == connector->dev->mode_config.dpms_property) {
251652217195SDaniel Vetter 		ret = (*connector->funcs->dpms)(connector, (int)value);
251752217195SDaniel Vetter 	} else if (connector->funcs->set_property)
251852217195SDaniel Vetter 		ret = connector->funcs->set_property(connector, property, value);
251952217195SDaniel Vetter 
2520144a7999SDaniel Vetter 	if (!ret)
252152217195SDaniel Vetter 		drm_object_property_set_value(&connector->base, property, value);
252252217195SDaniel Vetter 	return ret;
252352217195SDaniel Vetter }
252452217195SDaniel Vetter 
252597e14fbeSDaniel Vetter int drm_connector_property_set_ioctl(struct drm_device *dev,
252652217195SDaniel Vetter 				     void *data, struct drm_file *file_priv)
252752217195SDaniel Vetter {
252852217195SDaniel Vetter 	struct drm_mode_connector_set_property *conn_set_prop = data;
252952217195SDaniel Vetter 	struct drm_mode_obj_set_property obj_set_prop = {
253052217195SDaniel Vetter 		.value = conn_set_prop->value,
253152217195SDaniel Vetter 		.prop_id = conn_set_prop->prop_id,
253252217195SDaniel Vetter 		.obj_id = conn_set_prop->connector_id,
253352217195SDaniel Vetter 		.obj_type = DRM_MODE_OBJECT_CONNECTOR
253452217195SDaniel Vetter 	};
253552217195SDaniel Vetter 
253652217195SDaniel Vetter 	/* It does all the locking and checking we need */
253752217195SDaniel Vetter 	return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
253852217195SDaniel Vetter }
253952217195SDaniel Vetter 
254052217195SDaniel Vetter static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
254152217195SDaniel Vetter {
254252217195SDaniel Vetter 	/* For atomic drivers only state objects are synchronously updated and
2543c2ce66daSBeatriz Martins de Carvalho 	 * protected by modeset locks, so check those first.
2544c2ce66daSBeatriz Martins de Carvalho 	 */
254552217195SDaniel Vetter 	if (connector->state)
254652217195SDaniel Vetter 		return connector->state->best_encoder;
254752217195SDaniel Vetter 	return connector->encoder;
254852217195SDaniel Vetter }
254952217195SDaniel Vetter 
2550c3ff0cdbSAnkit Nautiyal static bool
2551c3ff0cdbSAnkit Nautiyal drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
25528445e2c5SVille Syrjälä 			     const struct list_head *modes,
255352217195SDaniel Vetter 			     const struct drm_file *file_priv)
255452217195SDaniel Vetter {
255552217195SDaniel Vetter 	/*
255652217195SDaniel Vetter 	 * If user-space hasn't configured the driver to expose the stereo 3D
255752217195SDaniel Vetter 	 * modes, don't expose them.
255852217195SDaniel Vetter 	 */
255952217195SDaniel Vetter 	if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
256052217195SDaniel Vetter 		return false;
2561c3ff0cdbSAnkit Nautiyal 	/*
2562c3ff0cdbSAnkit Nautiyal 	 * If user-space hasn't configured the driver to expose the modes
2563c3ff0cdbSAnkit Nautiyal 	 * with aspect-ratio, don't expose them. However if such a mode
2564c3ff0cdbSAnkit Nautiyal 	 * is unique, let it be exposed, but reset the aspect-ratio flags
2565c3ff0cdbSAnkit Nautiyal 	 * while preparing the list of user-modes.
2566c3ff0cdbSAnkit Nautiyal 	 */
2567c3ff0cdbSAnkit Nautiyal 	if (!file_priv->aspect_ratio_allowed) {
25688445e2c5SVille Syrjälä 		const struct drm_display_mode *mode_itr;
2569c3ff0cdbSAnkit Nautiyal 
25708445e2c5SVille Syrjälä 		list_for_each_entry(mode_itr, modes, head) {
25718445e2c5SVille Syrjälä 			if (mode_itr->expose_to_userspace &&
25728445e2c5SVille Syrjälä 			    drm_mode_match(mode_itr, mode,
2573c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_TIMINGS |
2574c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_CLOCK |
2575c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_FLAGS |
2576c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_3D_FLAGS))
2577c3ff0cdbSAnkit Nautiyal 				return false;
2578c3ff0cdbSAnkit Nautiyal 		}
25798445e2c5SVille Syrjälä 	}
258052217195SDaniel Vetter 
258152217195SDaniel Vetter 	return true;
258252217195SDaniel Vetter }
258352217195SDaniel Vetter 
258452217195SDaniel Vetter int drm_mode_getconnector(struct drm_device *dev, void *data,
258552217195SDaniel Vetter 			  struct drm_file *file_priv)
258652217195SDaniel Vetter {
258752217195SDaniel Vetter 	struct drm_mode_get_connector *out_resp = data;
258852217195SDaniel Vetter 	struct drm_connector *connector;
258952217195SDaniel Vetter 	struct drm_encoder *encoder;
259052217195SDaniel Vetter 	struct drm_display_mode *mode;
259152217195SDaniel Vetter 	int mode_count = 0;
259252217195SDaniel Vetter 	int encoders_count = 0;
259352217195SDaniel Vetter 	int ret = 0;
259452217195SDaniel Vetter 	int copied = 0;
259552217195SDaniel Vetter 	struct drm_mode_modeinfo u_mode;
259652217195SDaniel Vetter 	struct drm_mode_modeinfo __user *mode_ptr;
259752217195SDaniel Vetter 	uint32_t __user *encoder_ptr;
2598869e76f7SDesmond Cheong Zhi Xi 	bool is_current_master;
259952217195SDaniel Vetter 
260052217195SDaniel Vetter 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
260169fdf420SChris Wilson 		return -EOPNOTSUPP;
260252217195SDaniel Vetter 
260352217195SDaniel Vetter 	memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
260452217195SDaniel Vetter 
2605418da172SKeith Packard 	connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
260691eefc05SDaniel Vetter 	if (!connector)
260791eefc05SDaniel Vetter 		return -ENOENT;
260852217195SDaniel Vetter 
260962afb4adSJosé Roberto de Souza 	encoders_count = hweight32(connector->possible_encoders);
261091eefc05SDaniel Vetter 
261191eefc05SDaniel Vetter 	if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
261291eefc05SDaniel Vetter 		copied = 0;
261391eefc05SDaniel Vetter 		encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
261483aefbb8SVille Syrjälä 
261562afb4adSJosé Roberto de Souza 		drm_connector_for_each_possible_encoder(connector, encoder) {
261683aefbb8SVille Syrjälä 			if (put_user(encoder->base.id, encoder_ptr + copied)) {
261791eefc05SDaniel Vetter 				ret = -EFAULT;
2618e94ac351SDaniel Vetter 				goto out;
261991eefc05SDaniel Vetter 			}
262091eefc05SDaniel Vetter 			copied++;
262191eefc05SDaniel Vetter 		}
262291eefc05SDaniel Vetter 	}
262391eefc05SDaniel Vetter 	out_resp->count_encoders = encoders_count;
262491eefc05SDaniel Vetter 
262591eefc05SDaniel Vetter 	out_resp->connector_id = connector->base.id;
262691eefc05SDaniel Vetter 	out_resp->connector_type = connector->connector_type;
262791eefc05SDaniel Vetter 	out_resp->connector_type_id = connector->connector_type_id;
262891eefc05SDaniel Vetter 
2629869e76f7SDesmond Cheong Zhi Xi 	is_current_master = drm_is_current_master(file_priv);
2630869e76f7SDesmond Cheong Zhi Xi 
263191eefc05SDaniel Vetter 	mutex_lock(&dev->mode_config.mutex);
263291eefc05SDaniel Vetter 	if (out_resp->count_modes == 0) {
2633869e76f7SDesmond Cheong Zhi Xi 		if (is_current_master)
263491eefc05SDaniel Vetter 			connector->funcs->fill_modes(connector,
263591eefc05SDaniel Vetter 						     dev->mode_config.max_width,
263691eefc05SDaniel Vetter 						     dev->mode_config.max_height);
26378f86c82aSSimon Ser 		else
26388f86c82aSSimon Ser 			drm_dbg_kms(dev, "User-space requested a forced probe on [CONNECTOR:%d:%s] but is not the DRM master, demoting to read-only probe",
26398f86c82aSSimon Ser 				    connector->base.id, connector->name);
264091eefc05SDaniel Vetter 	}
264191eefc05SDaniel Vetter 
264291eefc05SDaniel Vetter 	out_resp->mm_width = connector->display_info.width_mm;
264391eefc05SDaniel Vetter 	out_resp->mm_height = connector->display_info.height_mm;
264491eefc05SDaniel Vetter 	out_resp->subpixel = connector->display_info.subpixel_order;
264591eefc05SDaniel Vetter 	out_resp->connection = connector->status;
264691eefc05SDaniel Vetter 
264791eefc05SDaniel Vetter 	/* delayed so we get modes regardless of pre-fill_modes state */
26488445e2c5SVille Syrjälä 	list_for_each_entry(mode, &connector->modes, head) {
26498445e2c5SVille Syrjälä 		WARN_ON(mode->expose_to_userspace);
26508445e2c5SVille Syrjälä 
26518445e2c5SVille Syrjälä 		if (drm_mode_expose_to_userspace(mode, &connector->modes,
2652c3ff0cdbSAnkit Nautiyal 						 file_priv)) {
26538445e2c5SVille Syrjälä 			mode->expose_to_userspace = true;
265491eefc05SDaniel Vetter 			mode_count++;
2655c3ff0cdbSAnkit Nautiyal 		}
26568445e2c5SVille Syrjälä 	}
265791eefc05SDaniel Vetter 
265852217195SDaniel Vetter 	/*
265952217195SDaniel Vetter 	 * This ioctl is called twice, once to determine how much space is
266052217195SDaniel Vetter 	 * needed, and the 2nd time to fill it.
266152217195SDaniel Vetter 	 */
266252217195SDaniel Vetter 	if ((out_resp->count_modes >= mode_count) && mode_count) {
266352217195SDaniel Vetter 		copied = 0;
266452217195SDaniel Vetter 		mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
26658445e2c5SVille Syrjälä 		list_for_each_entry(mode, &connector->modes, head) {
26668445e2c5SVille Syrjälä 			if (!mode->expose_to_userspace)
26678445e2c5SVille Syrjälä 				continue;
26688445e2c5SVille Syrjälä 
26698445e2c5SVille Syrjälä 			/* Clear the tag for the next time around */
26708445e2c5SVille Syrjälä 			mode->expose_to_userspace = false;
26718445e2c5SVille Syrjälä 
267252217195SDaniel Vetter 			drm_mode_convert_to_umode(&u_mode, mode);
2673c3ff0cdbSAnkit Nautiyal 			/*
2674c3ff0cdbSAnkit Nautiyal 			 * Reset aspect ratio flags of user-mode, if modes with
2675c3ff0cdbSAnkit Nautiyal 			 * aspect-ratio are not supported.
2676c3ff0cdbSAnkit Nautiyal 			 */
2677c3ff0cdbSAnkit Nautiyal 			if (!file_priv->aspect_ratio_allowed)
2678c3ff0cdbSAnkit Nautiyal 				u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
267952217195SDaniel Vetter 			if (copy_to_user(mode_ptr + copied,
268052217195SDaniel Vetter 					 &u_mode, sizeof(u_mode))) {
268152217195SDaniel Vetter 				ret = -EFAULT;
26828445e2c5SVille Syrjälä 
26838445e2c5SVille Syrjälä 				/*
26848445e2c5SVille Syrjälä 				 * Clear the tag for the rest of
26858445e2c5SVille Syrjälä 				 * the modes for the next time around.
26868445e2c5SVille Syrjälä 				 */
26878445e2c5SVille Syrjälä 				list_for_each_entry_continue(mode, &connector->modes, head)
26888445e2c5SVille Syrjälä 					mode->expose_to_userspace = false;
26898445e2c5SVille Syrjälä 
2690e94ac351SDaniel Vetter 				mutex_unlock(&dev->mode_config.mutex);
2691e94ac351SDaniel Vetter 
269252217195SDaniel Vetter 				goto out;
269352217195SDaniel Vetter 			}
269452217195SDaniel Vetter 			copied++;
269552217195SDaniel Vetter 		}
26968445e2c5SVille Syrjälä 	} else {
26978445e2c5SVille Syrjälä 		/* Clear the tag for the next time around */
26988445e2c5SVille Syrjälä 		list_for_each_entry(mode, &connector->modes, head)
26998445e2c5SVille Syrjälä 			mode->expose_to_userspace = false;
270052217195SDaniel Vetter 	}
27018445e2c5SVille Syrjälä 
270252217195SDaniel Vetter 	out_resp->count_modes = mode_count;
270352217195SDaniel Vetter 	mutex_unlock(&dev->mode_config.mutex);
2704e94ac351SDaniel Vetter 
2705e94ac351SDaniel Vetter 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2706e94ac351SDaniel Vetter 	encoder = drm_connector_get_encoder(connector);
2707e94ac351SDaniel Vetter 	if (encoder)
2708e94ac351SDaniel Vetter 		out_resp->encoder_id = encoder->base.id;
2709e94ac351SDaniel Vetter 	else
2710e94ac351SDaniel Vetter 		out_resp->encoder_id = 0;
2711e94ac351SDaniel Vetter 
2712e94ac351SDaniel Vetter 	/* Only grab properties after probing, to make sure EDID and other
2713c2ce66daSBeatriz Martins de Carvalho 	 * properties reflect the latest status.
2714c2ce66daSBeatriz Martins de Carvalho 	 */
2715e94ac351SDaniel Vetter 	ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
2716e94ac351SDaniel Vetter 			(uint32_t __user *)(unsigned long)(out_resp->props_ptr),
2717e94ac351SDaniel Vetter 			(uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
2718e94ac351SDaniel Vetter 			&out_resp->count_props);
2719e94ac351SDaniel Vetter 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
2720e94ac351SDaniel Vetter 
2721e94ac351SDaniel Vetter out:
2722ad093607SThierry Reding 	drm_connector_put(connector);
272352217195SDaniel Vetter 
272452217195SDaniel Vetter 	return ret;
272552217195SDaniel Vetter }
272652217195SDaniel Vetter 
27273d3f7c1eSHans de Goede /**
27283d3f7c1eSHans de Goede  * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode
27293d3f7c1eSHans de Goede  * @fwnode: fwnode for which to find the matching drm_connector
27303d3f7c1eSHans de Goede  *
27313d3f7c1eSHans de Goede  * This functions looks up a drm_connector based on its associated fwnode. When
27323d3f7c1eSHans de Goede  * a connector is found a reference to the connector is returned. The caller must
27333d3f7c1eSHans de Goede  * call drm_connector_put() to release this reference when it is done with the
27343d3f7c1eSHans de Goede  * connector.
27353d3f7c1eSHans de Goede  *
27363d3f7c1eSHans de Goede  * Returns: A reference to the found connector or an ERR_PTR().
27373d3f7c1eSHans de Goede  */
27383d3f7c1eSHans de Goede struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode)
27393d3f7c1eSHans de Goede {
27403d3f7c1eSHans de Goede 	struct drm_connector *connector, *found = ERR_PTR(-ENODEV);
27413d3f7c1eSHans de Goede 
27423d3f7c1eSHans de Goede 	if (!fwnode)
27433d3f7c1eSHans de Goede 		return ERR_PTR(-ENODEV);
27443d3f7c1eSHans de Goede 
27453d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
27463d3f7c1eSHans de Goede 
27473d3f7c1eSHans de Goede 	list_for_each_entry(connector, &connector_list, global_connector_list_entry) {
27483d3f7c1eSHans de Goede 		if (connector->fwnode == fwnode ||
27493d3f7c1eSHans de Goede 		    (connector->fwnode && connector->fwnode->secondary == fwnode)) {
27503d3f7c1eSHans de Goede 			drm_connector_get(connector);
27513d3f7c1eSHans de Goede 			found = connector;
27523d3f7c1eSHans de Goede 			break;
27533d3f7c1eSHans de Goede 		}
27543d3f7c1eSHans de Goede 	}
27553d3f7c1eSHans de Goede 
27563d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
27573d3f7c1eSHans de Goede 
27583d3f7c1eSHans de Goede 	return found;
27593d3f7c1eSHans de Goede }
27603d3f7c1eSHans de Goede 
276172ad4968SHans de Goede /**
276272ad4968SHans de Goede  * drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector
2763f85d9e59SRandy Dunlap  * @connector_fwnode: fwnode_handle to report the event on
276472ad4968SHans de Goede  *
276572ad4968SHans de Goede  * On some hardware a hotplug event notification may come from outside the display
276672ad4968SHans de Goede  * driver / device. An example of this is some USB Type-C setups where the hardware
276772ad4968SHans de Goede  * muxes the DisplayPort data and aux-lines but does not pass the altmode HPD
276872ad4968SHans de Goede  * status bit to the GPU's DP HPD pin.
276972ad4968SHans de Goede  *
277072ad4968SHans de Goede  * This function can be used to report these out-of-band events after obtaining
277172ad4968SHans de Goede  * a drm_connector reference through calling drm_connector_find_by_fwnode().
277272ad4968SHans de Goede  */
277372ad4968SHans de Goede void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode)
277472ad4968SHans de Goede {
277572ad4968SHans de Goede 	struct drm_connector *connector;
277672ad4968SHans de Goede 
277772ad4968SHans de Goede 	connector = drm_connector_find_by_fwnode(connector_fwnode);
277872ad4968SHans de Goede 	if (IS_ERR(connector))
277972ad4968SHans de Goede 		return;
278072ad4968SHans de Goede 
278172ad4968SHans de Goede 	if (connector->funcs->oob_hotplug_event)
278272ad4968SHans de Goede 		connector->funcs->oob_hotplug_event(connector);
278372ad4968SHans de Goede 
278472ad4968SHans de Goede 	drm_connector_put(connector);
278572ad4968SHans de Goede }
278672ad4968SHans de Goede EXPORT_SYMBOL(drm_connector_oob_hotplug_event);
278772ad4968SHans de Goede 
27889498c19bSDaniel Vetter 
27899498c19bSDaniel Vetter /**
27909498c19bSDaniel Vetter  * DOC: Tile group
27919498c19bSDaniel Vetter  *
27929498c19bSDaniel Vetter  * Tile groups are used to represent tiled monitors with a unique integer
27939498c19bSDaniel Vetter  * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
27949498c19bSDaniel Vetter  * we store this in a tile group, so we have a common identifier for all tiles
27959498c19bSDaniel Vetter  * in a monitor group. The property is called "TILE". Drivers can manage tile
27969498c19bSDaniel Vetter  * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
27979498c19bSDaniel Vetter  * drm_mode_get_tile_group(). But this is only needed for internal panels where
27989498c19bSDaniel Vetter  * the tile group information is exposed through a non-standard way.
27999498c19bSDaniel Vetter  */
28009498c19bSDaniel Vetter 
28019498c19bSDaniel Vetter static void drm_tile_group_free(struct kref *kref)
28029498c19bSDaniel Vetter {
28039498c19bSDaniel Vetter 	struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
28049498c19bSDaniel Vetter 	struct drm_device *dev = tg->dev;
2805948de842SSuraj Upadhyay 
28069498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
28079498c19bSDaniel Vetter 	idr_remove(&dev->mode_config.tile_idr, tg->id);
28089498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
28099498c19bSDaniel Vetter 	kfree(tg);
28109498c19bSDaniel Vetter }
28119498c19bSDaniel Vetter 
28129498c19bSDaniel Vetter /**
28139498c19bSDaniel Vetter  * drm_mode_put_tile_group - drop a reference to a tile group.
28149498c19bSDaniel Vetter  * @dev: DRM device
28159498c19bSDaniel Vetter  * @tg: tile group to drop reference to.
28169498c19bSDaniel Vetter  *
28179498c19bSDaniel Vetter  * drop reference to tile group and free if 0.
28189498c19bSDaniel Vetter  */
28199498c19bSDaniel Vetter void drm_mode_put_tile_group(struct drm_device *dev,
28209498c19bSDaniel Vetter 			     struct drm_tile_group *tg)
28219498c19bSDaniel Vetter {
28229498c19bSDaniel Vetter 	kref_put(&tg->refcount, drm_tile_group_free);
28239498c19bSDaniel Vetter }
28249498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_put_tile_group);
28259498c19bSDaniel Vetter 
28269498c19bSDaniel Vetter /**
28279498c19bSDaniel Vetter  * drm_mode_get_tile_group - get a reference to an existing tile group
28289498c19bSDaniel Vetter  * @dev: DRM device
28299498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
28309498c19bSDaniel Vetter  *
28319498c19bSDaniel Vetter  * Use the unique bytes to get a reference to an existing tile group.
28329498c19bSDaniel Vetter  *
28339498c19bSDaniel Vetter  * RETURNS:
28349498c19bSDaniel Vetter  * tile group or NULL if not found.
28359498c19bSDaniel Vetter  */
28369498c19bSDaniel Vetter struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2837267ea759SVille Syrjälä 					       const char topology[8])
28389498c19bSDaniel Vetter {
28399498c19bSDaniel Vetter 	struct drm_tile_group *tg;
28409498c19bSDaniel Vetter 	int id;
2841948de842SSuraj Upadhyay 
28429498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
28439498c19bSDaniel Vetter 	idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
28449498c19bSDaniel Vetter 		if (!memcmp(tg->group_data, topology, 8)) {
28459498c19bSDaniel Vetter 			if (!kref_get_unless_zero(&tg->refcount))
28469498c19bSDaniel Vetter 				tg = NULL;
28479498c19bSDaniel Vetter 			mutex_unlock(&dev->mode_config.idr_mutex);
28489498c19bSDaniel Vetter 			return tg;
28499498c19bSDaniel Vetter 		}
28509498c19bSDaniel Vetter 	}
28519498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
28529498c19bSDaniel Vetter 	return NULL;
28539498c19bSDaniel Vetter }
28549498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_get_tile_group);
28559498c19bSDaniel Vetter 
28569498c19bSDaniel Vetter /**
28579498c19bSDaniel Vetter  * drm_mode_create_tile_group - create a tile group from a displayid description
28589498c19bSDaniel Vetter  * @dev: DRM device
28599498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
28609498c19bSDaniel Vetter  *
28619498c19bSDaniel Vetter  * Create a tile group for the unique monitor, and get a unique
28629498c19bSDaniel Vetter  * identifier for the tile group.
28639498c19bSDaniel Vetter  *
28649498c19bSDaniel Vetter  * RETURNS:
2865705c8160SDan Carpenter  * new tile group or NULL.
28669498c19bSDaniel Vetter  */
28679498c19bSDaniel Vetter struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2868267ea759SVille Syrjälä 						  const char topology[8])
28699498c19bSDaniel Vetter {
28709498c19bSDaniel Vetter 	struct drm_tile_group *tg;
28719498c19bSDaniel Vetter 	int ret;
28729498c19bSDaniel Vetter 
28739498c19bSDaniel Vetter 	tg = kzalloc(sizeof(*tg), GFP_KERNEL);
28749498c19bSDaniel Vetter 	if (!tg)
2875705c8160SDan Carpenter 		return NULL;
28769498c19bSDaniel Vetter 
28779498c19bSDaniel Vetter 	kref_init(&tg->refcount);
28789498c19bSDaniel Vetter 	memcpy(tg->group_data, topology, 8);
28799498c19bSDaniel Vetter 	tg->dev = dev;
28809498c19bSDaniel Vetter 
28819498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
28829498c19bSDaniel Vetter 	ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
28839498c19bSDaniel Vetter 	if (ret >= 0) {
28849498c19bSDaniel Vetter 		tg->id = ret;
28859498c19bSDaniel Vetter 	} else {
28869498c19bSDaniel Vetter 		kfree(tg);
2887705c8160SDan Carpenter 		tg = NULL;
28889498c19bSDaniel Vetter 	}
28899498c19bSDaniel Vetter 
28909498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
28919498c19bSDaniel Vetter 	return tg;
28929498c19bSDaniel Vetter }
28939498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tile_group);
2894