xref: /linux/drivers/gpu/drm/drm_connector.c (revision 21b6c2812f3d9cbcfce9eca76632e2cc8fef214f)
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>
2935a3b82fSMaxime Ripard #include <drm/drm_managed.h>
30d71d8a4bSMaxime Ripard #include <drm/drm_panel.h>
31d71d8a4bSMaxime Ripard #include <drm/drm_print.h>
32334f74eeSHans de Goede #include <drm/drm_privacy_screen_consumer.h>
33968d81a6SJeykumar Sankaran #include <drm/drm_sysfs.h>
34d71d8a4bSMaxime Ripard #include <drm/drm_utils.h>
3599f45e32SDaniel Vetter 
36495e440bSThomas Zimmermann #include <linux/property.h>
3799f45e32SDaniel Vetter #include <linux/uaccess.h>
3852217195SDaniel Vetter 
39495e440bSThomas Zimmermann #include <video/cmdline.h>
40495e440bSThomas Zimmermann 
4152217195SDaniel Vetter #include "drm_crtc_internal.h"
4252217195SDaniel Vetter #include "drm_internal.h"
4352217195SDaniel Vetter 
44ae2a6da8SDaniel Vetter /**
45ae2a6da8SDaniel Vetter  * DOC: overview
46ae2a6da8SDaniel Vetter  *
47ae2a6da8SDaniel Vetter  * In DRM connectors are the general abstraction for display sinks, and include
4884e543bcSAntonio Borneo  * also fixed panels or anything else that can display pixels in some form. As
49ae2a6da8SDaniel Vetter  * opposed to all other KMS objects representing hardware (like CRTC, encoder or
50ae2a6da8SDaniel Vetter  * plane abstractions) connectors can be hotplugged and unplugged at runtime.
51ad093607SThierry Reding  * Hence they are reference-counted using drm_connector_get() and
52ad093607SThierry Reding  * drm_connector_put().
53ae2a6da8SDaniel Vetter  *
54d574528aSDaniel Vetter  * KMS driver must create, initialize, register and attach at a &struct
55d574528aSDaniel Vetter  * drm_connector for each such sink. The instance is created as other KMS
56aec97460SDaniel Vetter  * objects and initialized by setting the following fields. The connector is
57aec97460SDaniel Vetter  * initialized with a call to drm_connector_init() with a pointer to the
58aec97460SDaniel Vetter  * &struct drm_connector_funcs and a connector type, and then exposed to
59aec97460SDaniel Vetter  * userspace with a call to drm_connector_register().
60ae2a6da8SDaniel Vetter  *
61ae2a6da8SDaniel Vetter  * Connectors must be attached to an encoder to be used. For devices that map
62ae2a6da8SDaniel Vetter  * connectors to encoders 1:1, the connector should be attached at
63cde4c44dSDaniel Vetter  * initialization time with a call to drm_connector_attach_encoder(). The
64d574528aSDaniel Vetter  * driver must also set the &drm_connector.encoder field to point to the
65ae2a6da8SDaniel Vetter  * attached encoder.
66ae2a6da8SDaniel Vetter  *
67ae2a6da8SDaniel Vetter  * For connectors which are not fixed (like built-in panels) the driver needs to
68ae2a6da8SDaniel Vetter  * support hotplug notifications. The simplest way to do that is by using the
69ae2a6da8SDaniel Vetter  * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
70ae2a6da8SDaniel Vetter  * hardware support for hotplug interrupts. Connectors with hardware hotplug
71ae2a6da8SDaniel Vetter  * support can instead use e.g. drm_helper_hpd_irq_event().
72ae2a6da8SDaniel Vetter  */
73ae2a6da8SDaniel Vetter 
743d3f7c1eSHans de Goede /*
753d3f7c1eSHans de Goede  * Global connector list for drm_connector_find_by_fwnode().
763d3f7c1eSHans de Goede  * Note drm_connector_[un]register() first take connector->lock and then
773d3f7c1eSHans de Goede  * take the connector_list_lock.
783d3f7c1eSHans de Goede  */
793d3f7c1eSHans de Goede static DEFINE_MUTEX(connector_list_lock);
803d3f7c1eSHans de Goede static LIST_HEAD(connector_list);
813d3f7c1eSHans de Goede 
8252217195SDaniel Vetter struct drm_conn_prop_enum_list {
8352217195SDaniel Vetter 	int type;
8452217195SDaniel Vetter 	const char *name;
8552217195SDaniel Vetter 	struct ida ida;
8652217195SDaniel Vetter };
8752217195SDaniel Vetter 
8852217195SDaniel Vetter /*
8952217195SDaniel Vetter  * Connector and encoder types.
9052217195SDaniel Vetter  */
9152217195SDaniel Vetter static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
9252217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Unknown, "Unknown" },
9352217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
9452217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
9552217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
9652217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
9752217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Composite, "Composite" },
9852217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
9952217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
10052217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Component, "Component" },
10152217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
10252217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },
10352217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
10452217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
10552217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_TV, "TV" },
10652217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_eDP, "eDP" },
10752217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
10852217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DSI, "DSI" },
10952217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DPI, "DPI" },
110935774cdSBrian Starkey 	{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
111fc06bf1dSNoralf Trønnes 	{ DRM_MODE_CONNECTOR_SPI, "SPI" },
112757e2671SNoralf Trønnes 	{ DRM_MODE_CONNECTOR_USB, "USB" },
11352217195SDaniel Vetter };
11452217195SDaniel Vetter 
11552217195SDaniel Vetter void drm_connector_ida_init(void)
11652217195SDaniel Vetter {
11752217195SDaniel Vetter 	int i;
11852217195SDaniel Vetter 
11952217195SDaniel Vetter 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
12052217195SDaniel Vetter 		ida_init(&drm_connector_enum_list[i].ida);
12152217195SDaniel Vetter }
12252217195SDaniel Vetter 
12352217195SDaniel Vetter void drm_connector_ida_destroy(void)
12452217195SDaniel Vetter {
12552217195SDaniel Vetter 	int i;
12652217195SDaniel Vetter 
12752217195SDaniel Vetter 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
12852217195SDaniel Vetter 		ida_destroy(&drm_connector_enum_list[i].ida);
12952217195SDaniel Vetter }
13052217195SDaniel Vetter 
13152217195SDaniel Vetter /**
132b35f90f2SLaurent Pinchart  * drm_get_connector_type_name - return a string for connector type
133b35f90f2SLaurent Pinchart  * @type: The connector type (DRM_MODE_CONNECTOR_*)
134b35f90f2SLaurent Pinchart  *
135b35f90f2SLaurent Pinchart  * Returns: the name of the connector type, or NULL if the type is not valid.
136b35f90f2SLaurent Pinchart  */
137b35f90f2SLaurent Pinchart const char *drm_get_connector_type_name(unsigned int type)
138b35f90f2SLaurent Pinchart {
139b35f90f2SLaurent Pinchart 	if (type < ARRAY_SIZE(drm_connector_enum_list))
140b35f90f2SLaurent Pinchart 		return drm_connector_enum_list[type].name;
141b35f90f2SLaurent Pinchart 
142b35f90f2SLaurent Pinchart 	return NULL;
143b35f90f2SLaurent Pinchart }
144b35f90f2SLaurent Pinchart EXPORT_SYMBOL(drm_get_connector_type_name);
145b35f90f2SLaurent Pinchart 
146b35f90f2SLaurent Pinchart /**
14752217195SDaniel Vetter  * drm_connector_get_cmdline_mode - reads the user's cmdline mode
14884e543bcSAntonio Borneo  * @connector: connector to query
14952217195SDaniel Vetter  *
150ae2a6da8SDaniel Vetter  * The kernel supports per-connector configuration of its consoles through
15152217195SDaniel Vetter  * use of the video= parameter. This function parses that option and
15252217195SDaniel Vetter  * extracts the user's specified mode (or enable/disable status) for a
15352217195SDaniel Vetter  * particular connector. This is typically only used during the early fbdev
15452217195SDaniel Vetter  * setup.
15552217195SDaniel Vetter  */
15652217195SDaniel Vetter static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
15752217195SDaniel Vetter {
15852217195SDaniel Vetter 	struct drm_cmdline_mode *mode = &connector->cmdline_mode;
159495e440bSThomas Zimmermann 	const char *option;
16052217195SDaniel Vetter 
161495e440bSThomas Zimmermann 	option = video_get_options(connector->name);
162495e440bSThomas Zimmermann 	if (!option)
16352217195SDaniel Vetter 		return;
16452217195SDaniel Vetter 
16552217195SDaniel Vetter 	if (!drm_mode_parse_command_line_for_connector(option,
16652217195SDaniel Vetter 						       connector,
16752217195SDaniel Vetter 						       mode))
16852217195SDaniel Vetter 		return;
16952217195SDaniel Vetter 
17052217195SDaniel Vetter 	if (mode->force) {
1716140cf20SJani Nikula 		DRM_INFO("forcing %s connector %s\n", connector->name,
1726140cf20SJani Nikula 			 drm_get_connector_force_name(mode->force));
17352217195SDaniel Vetter 		connector->force = mode->force;
17452217195SDaniel Vetter 	}
17552217195SDaniel Vetter 
1760980939dSHans de Goede 	if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) {
1770980939dSHans de Goede 		DRM_INFO("cmdline forces connector %s panel_orientation to %d\n",
1780980939dSHans de Goede 			 connector->name, mode->panel_orientation);
1790980939dSHans de Goede 		drm_connector_set_panel_orientation(connector,
1800980939dSHans de Goede 						    mode->panel_orientation);
1810980939dSHans de Goede 	}
1820980939dSHans de Goede 
1833aeeb13dSMaxime Ripard 	DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
18450b0946dSMaxime Ripard 		      connector->name, mode->name,
18552217195SDaniel Vetter 		      mode->xres, mode->yres,
18652217195SDaniel Vetter 		      mode->refresh_specified ? mode->refresh : 60,
18752217195SDaniel Vetter 		      mode->rb ? " reduced blanking" : "",
18852217195SDaniel Vetter 		      mode->margins ? " with margins" : "",
18952217195SDaniel Vetter 		      mode->interlace ?  " interlaced" : "");
19052217195SDaniel Vetter }
19152217195SDaniel Vetter 
19252217195SDaniel Vetter static void drm_connector_free(struct kref *kref)
19352217195SDaniel Vetter {
19452217195SDaniel Vetter 	struct drm_connector *connector =
19552217195SDaniel Vetter 		container_of(kref, struct drm_connector, base.refcount);
19652217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
19752217195SDaniel Vetter 
19852217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
19952217195SDaniel Vetter 	connector->funcs->destroy(connector);
20052217195SDaniel Vetter }
20152217195SDaniel Vetter 
202ea497bb9SDaniel Vetter void drm_connector_free_work_fn(struct work_struct *work)
203a703c550SDaniel Vetter {
204ea497bb9SDaniel Vetter 	struct drm_connector *connector, *n;
205ea497bb9SDaniel Vetter 	struct drm_device *dev =
206ea497bb9SDaniel Vetter 		container_of(work, struct drm_device, mode_config.connector_free_work);
207ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &dev->mode_config;
208ea497bb9SDaniel Vetter 	unsigned long flags;
209ea497bb9SDaniel Vetter 	struct llist_node *freed;
210a703c550SDaniel Vetter 
211ea497bb9SDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
212ea497bb9SDaniel Vetter 	freed = llist_del_all(&config->connector_free_list);
213ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
214ea497bb9SDaniel Vetter 
215ea497bb9SDaniel Vetter 	llist_for_each_entry_safe(connector, n, freed, free_node) {
216a703c550SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
217a703c550SDaniel Vetter 		connector->funcs->destroy(connector);
218a703c550SDaniel Vetter 	}
219ea497bb9SDaniel Vetter }
220a703c550SDaniel Vetter 
221b11af8a2SMaxime Ripard static int __drm_connector_init(struct drm_device *dev,
22252217195SDaniel Vetter 				struct drm_connector *connector,
22352217195SDaniel Vetter 				const struct drm_connector_funcs *funcs,
224b11af8a2SMaxime Ripard 				int connector_type,
225b11af8a2SMaxime Ripard 				struct i2c_adapter *ddc)
22652217195SDaniel Vetter {
22752217195SDaniel Vetter 	struct drm_mode_config *config = &dev->mode_config;
22852217195SDaniel Vetter 	int ret;
22952217195SDaniel Vetter 	struct ida *connector_ida =
23052217195SDaniel Vetter 		&drm_connector_enum_list[connector_type].ida;
23152217195SDaniel Vetter 
232ba1f665fSHaneen Mohammed 	WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
233ba1f665fSHaneen Mohammed 		(!funcs->atomic_destroy_state ||
234ba1f665fSHaneen Mohammed 		 !funcs->atomic_duplicate_state));
235ba1f665fSHaneen Mohammed 
2362135ea7aSThierry Reding 	ret = __drm_mode_object_add(dev, &connector->base,
23752217195SDaniel Vetter 				    DRM_MODE_OBJECT_CONNECTOR,
23852217195SDaniel Vetter 				    false, drm_connector_free);
23952217195SDaniel Vetter 	if (ret)
240613051daSDaniel Vetter 		return ret;
24152217195SDaniel Vetter 
24252217195SDaniel Vetter 	connector->base.properties = &connector->properties;
24352217195SDaniel Vetter 	connector->dev = dev;
24452217195SDaniel Vetter 	connector->funcs = funcs;
24552217195SDaniel Vetter 
2462a8d3eacSVille Syrjälä 	/* connector index is used with 32bit bitmasks */
247e5d6eeeaSBo Liu 	ret = ida_alloc_max(&config->connector_ida, 31, GFP_KERNEL);
2482a8d3eacSVille Syrjälä 	if (ret < 0) {
2492a8d3eacSVille Syrjälä 		DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
2502a8d3eacSVille Syrjälä 			      drm_connector_enum_list[connector_type].name,
2512a8d3eacSVille Syrjälä 			      ret);
25252217195SDaniel Vetter 		goto out_put;
2532a8d3eacSVille Syrjälä 	}
25452217195SDaniel Vetter 	connector->index = ret;
25552217195SDaniel Vetter 	ret = 0;
25652217195SDaniel Vetter 
25752217195SDaniel Vetter 	connector->connector_type = connector_type;
25852217195SDaniel Vetter 	connector->connector_type_id =
259e5d6eeeaSBo Liu 		ida_alloc_min(connector_ida, 1, GFP_KERNEL);
26052217195SDaniel Vetter 	if (connector->connector_type_id < 0) {
26152217195SDaniel Vetter 		ret = connector->connector_type_id;
26252217195SDaniel Vetter 		goto out_put_id;
26352217195SDaniel Vetter 	}
26452217195SDaniel Vetter 	connector->name =
26552217195SDaniel Vetter 		kasprintf(GFP_KERNEL, "%s-%d",
26652217195SDaniel Vetter 			  drm_connector_enum_list[connector_type].name,
26752217195SDaniel Vetter 			  connector->connector_type_id);
26852217195SDaniel Vetter 	if (!connector->name) {
26952217195SDaniel Vetter 		ret = -ENOMEM;
27052217195SDaniel Vetter 		goto out_put_type_id;
27152217195SDaniel Vetter 	}
27252217195SDaniel Vetter 
273b11af8a2SMaxime Ripard 	/* provide ddc symlink in sysfs */
274b11af8a2SMaxime Ripard 	connector->ddc = ddc;
275b11af8a2SMaxime Ripard 
2763d3f7c1eSHans de Goede 	INIT_LIST_HEAD(&connector->global_connector_list_entry);
27752217195SDaniel Vetter 	INIT_LIST_HEAD(&connector->probed_modes);
27852217195SDaniel Vetter 	INIT_LIST_HEAD(&connector->modes);
279e73ab00eSDaniel Vetter 	mutex_init(&connector->mutex);
28090b575f5SJani Nikula 	mutex_init(&connector->edid_override_mutex);
28152217195SDaniel Vetter 	connector->edid_blob_ptr = NULL;
2825186421cSStanislav Lisovskiy 	connector->epoch_counter = 0;
2832de3a078SManasi Navare 	connector->tile_blob_ptr = NULL;
28452217195SDaniel Vetter 	connector->status = connector_status_unknown;
2858d70f395SHans de Goede 	connector->display_info.panel_orientation =
2868d70f395SHans de Goede 		DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
28752217195SDaniel Vetter 
28852217195SDaniel Vetter 	drm_connector_get_cmdline_mode(connector);
28952217195SDaniel Vetter 
29052217195SDaniel Vetter 	/* We should add connectors at the end to avoid upsetting the connector
291c2ce66daSBeatriz Martins de Carvalho 	 * index too much.
292c2ce66daSBeatriz Martins de Carvalho 	 */
293613051daSDaniel Vetter 	spin_lock_irq(&config->connector_list_lock);
29452217195SDaniel Vetter 	list_add_tail(&connector->head, &config->connector_list);
29552217195SDaniel Vetter 	config->num_connector++;
296613051daSDaniel Vetter 	spin_unlock_irq(&config->connector_list_lock);
29752217195SDaniel Vetter 
298935774cdSBrian Starkey 	if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
299935774cdSBrian Starkey 	    connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
3006b7e2d5cSGerd Hoffmann 		drm_connector_attach_edid_property(connector);
30152217195SDaniel Vetter 
30252217195SDaniel Vetter 	drm_object_attach_property(&connector->base,
30352217195SDaniel Vetter 				      config->dpms_property, 0);
30452217195SDaniel Vetter 
30540ee6fbeSManasi Navare 	drm_object_attach_property(&connector->base,
30640ee6fbeSManasi Navare 				   config->link_status_property,
30740ee6fbeSManasi Navare 				   0);
30840ee6fbeSManasi Navare 
30966660d4cSDave Airlie 	drm_object_attach_property(&connector->base,
31066660d4cSDave Airlie 				   config->non_desktop_property,
31166660d4cSDave Airlie 				   0);
3122de3a078SManasi Navare 	drm_object_attach_property(&connector->base,
3132de3a078SManasi Navare 				   config->tile_property,
3142de3a078SManasi Navare 				   0);
31566660d4cSDave Airlie 
31652217195SDaniel Vetter 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
31752217195SDaniel Vetter 		drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
31852217195SDaniel Vetter 	}
31952217195SDaniel Vetter 
32052217195SDaniel Vetter 	connector->debugfs_entry = NULL;
32152217195SDaniel Vetter out_put_type_id:
32252217195SDaniel Vetter 	if (ret)
323e5d6eeeaSBo Liu 		ida_free(connector_ida, connector->connector_type_id);
32452217195SDaniel Vetter out_put_id:
32552217195SDaniel Vetter 	if (ret)
326e5d6eeeaSBo Liu 		ida_free(&config->connector_ida, connector->index);
32752217195SDaniel Vetter out_put:
32852217195SDaniel Vetter 	if (ret)
32952217195SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
33052217195SDaniel Vetter 
33152217195SDaniel Vetter 	return ret;
33252217195SDaniel Vetter }
333b11af8a2SMaxime Ripard 
334b11af8a2SMaxime Ripard /**
335b11af8a2SMaxime Ripard  * drm_connector_init - Init a preallocated connector
336b11af8a2SMaxime Ripard  * @dev: DRM device
337b11af8a2SMaxime Ripard  * @connector: the connector to init
338b11af8a2SMaxime Ripard  * @funcs: callbacks for this connector
339b11af8a2SMaxime Ripard  * @connector_type: user visible type of the connector
340b11af8a2SMaxime Ripard  *
341b11af8a2SMaxime Ripard  * Initialises a preallocated connector. Connectors should be
342b11af8a2SMaxime Ripard  * subclassed as part of driver connector objects.
343b11af8a2SMaxime Ripard  *
344b11af8a2SMaxime Ripard  * At driver unload time the driver's &drm_connector_funcs.destroy hook
345b11af8a2SMaxime Ripard  * should call drm_connector_cleanup() and free the connector structure.
346b11af8a2SMaxime Ripard  * The connector structure should not be allocated with devm_kzalloc().
347b11af8a2SMaxime Ripard  *
34835a3b82fSMaxime Ripard  * Note: consider using drmm_connector_init() instead of
34935a3b82fSMaxime Ripard  * drm_connector_init() to let the DRM managed resource infrastructure
35035a3b82fSMaxime Ripard  * take care of cleanup and deallocation.
35135a3b82fSMaxime Ripard  *
352b11af8a2SMaxime Ripard  * Returns:
353b11af8a2SMaxime Ripard  * Zero on success, error code on failure.
354b11af8a2SMaxime Ripard  */
355b11af8a2SMaxime Ripard int drm_connector_init(struct drm_device *dev,
356b11af8a2SMaxime Ripard 		       struct drm_connector *connector,
357b11af8a2SMaxime Ripard 		       const struct drm_connector_funcs *funcs,
358b11af8a2SMaxime Ripard 		       int connector_type)
359b11af8a2SMaxime Ripard {
360a961b197SMaxime Ripard 	if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
361a961b197SMaxime Ripard 		return -EINVAL;
362a961b197SMaxime Ripard 
363b11af8a2SMaxime Ripard 	return __drm_connector_init(dev, connector, funcs, connector_type, NULL);
364b11af8a2SMaxime Ripard }
36552217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_init);
36652217195SDaniel Vetter 
36752217195SDaniel Vetter /**
368100163dfSAndrzej Pietrasiewicz  * drm_connector_init_with_ddc - Init a preallocated connector
369100163dfSAndrzej Pietrasiewicz  * @dev: DRM device
370100163dfSAndrzej Pietrasiewicz  * @connector: the connector to init
371100163dfSAndrzej Pietrasiewicz  * @funcs: callbacks for this connector
372100163dfSAndrzej Pietrasiewicz  * @connector_type: user visible type of the connector
373100163dfSAndrzej Pietrasiewicz  * @ddc: pointer to the associated ddc adapter
374100163dfSAndrzej Pietrasiewicz  *
375100163dfSAndrzej Pietrasiewicz  * Initialises a preallocated connector. Connectors should be
376100163dfSAndrzej Pietrasiewicz  * subclassed as part of driver connector objects.
377100163dfSAndrzej Pietrasiewicz  *
37800ec947cSMaxime Ripard  * At driver unload time the driver's &drm_connector_funcs.destroy hook
37900ec947cSMaxime Ripard  * should call drm_connector_cleanup() and free the connector structure.
38000ec947cSMaxime Ripard  * The connector structure should not be allocated with devm_kzalloc().
38100ec947cSMaxime Ripard  *
382100163dfSAndrzej Pietrasiewicz  * Ensures that the ddc field of the connector is correctly set.
383100163dfSAndrzej Pietrasiewicz  *
38435a3b82fSMaxime Ripard  * Note: consider using drmm_connector_init() instead of
38535a3b82fSMaxime Ripard  * drm_connector_init_with_ddc() to let the DRM managed resource
38635a3b82fSMaxime Ripard  * infrastructure take care of cleanup and deallocation.
38735a3b82fSMaxime Ripard  *
388100163dfSAndrzej Pietrasiewicz  * Returns:
389100163dfSAndrzej Pietrasiewicz  * Zero on success, error code on failure.
390100163dfSAndrzej Pietrasiewicz  */
391100163dfSAndrzej Pietrasiewicz int drm_connector_init_with_ddc(struct drm_device *dev,
392100163dfSAndrzej Pietrasiewicz 				struct drm_connector *connector,
393100163dfSAndrzej Pietrasiewicz 				const struct drm_connector_funcs *funcs,
394100163dfSAndrzej Pietrasiewicz 				int connector_type,
395100163dfSAndrzej Pietrasiewicz 				struct i2c_adapter *ddc)
396100163dfSAndrzej Pietrasiewicz {
397a961b197SMaxime Ripard 	if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
398a961b197SMaxime Ripard 		return -EINVAL;
399a961b197SMaxime Ripard 
400b11af8a2SMaxime Ripard 	return __drm_connector_init(dev, connector, funcs, connector_type, ddc);
401100163dfSAndrzej Pietrasiewicz }
402100163dfSAndrzej Pietrasiewicz EXPORT_SYMBOL(drm_connector_init_with_ddc);
403100163dfSAndrzej Pietrasiewicz 
40435a3b82fSMaxime Ripard static void drm_connector_cleanup_action(struct drm_device *dev,
40535a3b82fSMaxime Ripard 					 void *ptr)
40635a3b82fSMaxime Ripard {
40735a3b82fSMaxime Ripard 	struct drm_connector *connector = ptr;
40835a3b82fSMaxime Ripard 
40935a3b82fSMaxime Ripard 	drm_connector_cleanup(connector);
41035a3b82fSMaxime Ripard }
41135a3b82fSMaxime Ripard 
41235a3b82fSMaxime Ripard /**
41335a3b82fSMaxime Ripard  * drmm_connector_init - Init a preallocated connector
41435a3b82fSMaxime Ripard  * @dev: DRM device
41535a3b82fSMaxime Ripard  * @connector: the connector to init
41635a3b82fSMaxime Ripard  * @funcs: callbacks for this connector
41735a3b82fSMaxime Ripard  * @connector_type: user visible type of the connector
41835a3b82fSMaxime Ripard  * @ddc: optional pointer to the associated ddc adapter
41935a3b82fSMaxime Ripard  *
42035a3b82fSMaxime Ripard  * Initialises a preallocated connector. Connectors should be
42135a3b82fSMaxime Ripard  * subclassed as part of driver connector objects.
42235a3b82fSMaxime Ripard  *
42335a3b82fSMaxime Ripard  * Cleanup is automatically handled with a call to
42435a3b82fSMaxime Ripard  * drm_connector_cleanup() in a DRM-managed action.
42535a3b82fSMaxime Ripard  *
42635a3b82fSMaxime Ripard  * The connector structure should be allocated with drmm_kzalloc().
42735a3b82fSMaxime Ripard  *
42835a3b82fSMaxime Ripard  * Returns:
42935a3b82fSMaxime Ripard  * Zero on success, error code on failure.
43035a3b82fSMaxime Ripard  */
43135a3b82fSMaxime Ripard int drmm_connector_init(struct drm_device *dev,
43235a3b82fSMaxime Ripard 			struct drm_connector *connector,
43335a3b82fSMaxime Ripard 			const struct drm_connector_funcs *funcs,
43435a3b82fSMaxime Ripard 			int connector_type,
43535a3b82fSMaxime Ripard 			struct i2c_adapter *ddc)
43635a3b82fSMaxime Ripard {
43735a3b82fSMaxime Ripard 	int ret;
43835a3b82fSMaxime Ripard 
43935a3b82fSMaxime Ripard 	if (drm_WARN_ON(dev, funcs && funcs->destroy))
44035a3b82fSMaxime Ripard 		return -EINVAL;
44135a3b82fSMaxime Ripard 
442a91e5e3eSMaxime Ripard 	ret = __drm_connector_init(dev, connector, funcs, connector_type, ddc);
44335a3b82fSMaxime Ripard 	if (ret)
44435a3b82fSMaxime Ripard 		return ret;
44535a3b82fSMaxime Ripard 
44635a3b82fSMaxime Ripard 	ret = drmm_add_action_or_reset(dev, drm_connector_cleanup_action,
44735a3b82fSMaxime Ripard 				       connector);
44835a3b82fSMaxime Ripard 	if (ret)
44935a3b82fSMaxime Ripard 		return ret;
45035a3b82fSMaxime Ripard 
45135a3b82fSMaxime Ripard 	return 0;
45235a3b82fSMaxime Ripard }
45335a3b82fSMaxime Ripard EXPORT_SYMBOL(drmm_connector_init);
45435a3b82fSMaxime Ripard 
455100163dfSAndrzej Pietrasiewicz /**
4566b7e2d5cSGerd Hoffmann  * drm_connector_attach_edid_property - attach edid property.
4576b7e2d5cSGerd Hoffmann  * @connector: the connector
4586b7e2d5cSGerd Hoffmann  *
4596b7e2d5cSGerd Hoffmann  * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
4606b7e2d5cSGerd Hoffmann  * edid property attached by default.  This function can be used to
4616b7e2d5cSGerd Hoffmann  * explicitly enable the edid property in these cases.
4626b7e2d5cSGerd Hoffmann  */
4636b7e2d5cSGerd Hoffmann void drm_connector_attach_edid_property(struct drm_connector *connector)
4646b7e2d5cSGerd Hoffmann {
4656b7e2d5cSGerd Hoffmann 	struct drm_mode_config *config = &connector->dev->mode_config;
4666b7e2d5cSGerd Hoffmann 
4676b7e2d5cSGerd Hoffmann 	drm_object_attach_property(&connector->base,
4686b7e2d5cSGerd Hoffmann 				   config->edid_property,
4696b7e2d5cSGerd Hoffmann 				   0);
4706b7e2d5cSGerd Hoffmann }
4716b7e2d5cSGerd Hoffmann EXPORT_SYMBOL(drm_connector_attach_edid_property);
4726b7e2d5cSGerd Hoffmann 
4736b7e2d5cSGerd Hoffmann /**
474cde4c44dSDaniel Vetter  * drm_connector_attach_encoder - attach a connector to an encoder
47552217195SDaniel Vetter  * @connector: connector to attach
47652217195SDaniel Vetter  * @encoder: encoder to attach @connector to
47752217195SDaniel Vetter  *
47852217195SDaniel Vetter  * This function links up a connector to an encoder. Note that the routing
47952217195SDaniel Vetter  * restrictions between encoders and crtcs are exposed to userspace through the
48052217195SDaniel Vetter  * possible_clones and possible_crtcs bitmasks.
48152217195SDaniel Vetter  *
48252217195SDaniel Vetter  * Returns:
48352217195SDaniel Vetter  * Zero on success, negative errno on failure.
48452217195SDaniel Vetter  */
485cde4c44dSDaniel Vetter int drm_connector_attach_encoder(struct drm_connector *connector,
48652217195SDaniel Vetter 				 struct drm_encoder *encoder)
48752217195SDaniel Vetter {
48852217195SDaniel Vetter 	/*
48952217195SDaniel Vetter 	 * In the past, drivers have attempted to model the static association
49052217195SDaniel Vetter 	 * of connector to encoder in simple connector/encoder devices using a
49152217195SDaniel Vetter 	 * direct assignment of connector->encoder = encoder. This connection
49252217195SDaniel Vetter 	 * is a logical one and the responsibility of the core, so drivers are
49352217195SDaniel Vetter 	 * expected not to mess with this.
49452217195SDaniel Vetter 	 *
49552217195SDaniel Vetter 	 * Note that the error return should've been enough here, but a large
49652217195SDaniel Vetter 	 * majority of drivers ignores the return value, so add in a big WARN
49752217195SDaniel Vetter 	 * to get people's attention.
49852217195SDaniel Vetter 	 */
49952217195SDaniel Vetter 	if (WARN_ON(connector->encoder))
50052217195SDaniel Vetter 		return -EINVAL;
50152217195SDaniel Vetter 
50262afb4adSJosé Roberto de Souza 	connector->possible_encoders |= drm_encoder_mask(encoder);
50362afb4adSJosé Roberto de Souza 
50452217195SDaniel Vetter 	return 0;
50552217195SDaniel Vetter }
506cde4c44dSDaniel Vetter EXPORT_SYMBOL(drm_connector_attach_encoder);
50752217195SDaniel Vetter 
50838cb8d96SVille Syrjälä /**
50962afb4adSJosé Roberto de Souza  * drm_connector_has_possible_encoder - check if the connector and encoder are
51062afb4adSJosé Roberto de Souza  * associated with each other
51138cb8d96SVille Syrjälä  * @connector: the connector
51238cb8d96SVille Syrjälä  * @encoder: the encoder
51338cb8d96SVille Syrjälä  *
51438cb8d96SVille Syrjälä  * Returns:
51538cb8d96SVille Syrjälä  * True if @encoder is one of the possible encoders for @connector.
51638cb8d96SVille Syrjälä  */
51738cb8d96SVille Syrjälä bool drm_connector_has_possible_encoder(struct drm_connector *connector,
51838cb8d96SVille Syrjälä 					struct drm_encoder *encoder)
51938cb8d96SVille Syrjälä {
52062afb4adSJosé Roberto de Souza 	return connector->possible_encoders & drm_encoder_mask(encoder);
52138cb8d96SVille Syrjälä }
52238cb8d96SVille Syrjälä EXPORT_SYMBOL(drm_connector_has_possible_encoder);
52338cb8d96SVille Syrjälä 
52452217195SDaniel Vetter static void drm_mode_remove(struct drm_connector *connector,
52552217195SDaniel Vetter 			    struct drm_display_mode *mode)
52652217195SDaniel Vetter {
52752217195SDaniel Vetter 	list_del(&mode->head);
52852217195SDaniel Vetter 	drm_mode_destroy(connector->dev, mode);
52952217195SDaniel Vetter }
53052217195SDaniel Vetter 
53152217195SDaniel Vetter /**
53252217195SDaniel Vetter  * drm_connector_cleanup - cleans up an initialised connector
53352217195SDaniel Vetter  * @connector: connector to cleanup
53452217195SDaniel Vetter  *
53552217195SDaniel Vetter  * Cleans up the connector but doesn't free the object.
53652217195SDaniel Vetter  */
53752217195SDaniel Vetter void drm_connector_cleanup(struct drm_connector *connector)
53852217195SDaniel Vetter {
53952217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
54052217195SDaniel Vetter 	struct drm_display_mode *mode, *t;
54152217195SDaniel Vetter 
54252217195SDaniel Vetter 	/* The connector should have been removed from userspace long before
54352217195SDaniel Vetter 	 * it is finally destroyed.
54452217195SDaniel Vetter 	 */
54539b50c60SLyude Paul 	if (WARN_ON(connector->registration_state ==
54639b50c60SLyude Paul 		    DRM_CONNECTOR_REGISTERED))
54752217195SDaniel Vetter 		drm_connector_unregister(connector);
54852217195SDaniel Vetter 
549334f74eeSHans de Goede 	if (connector->privacy_screen) {
550334f74eeSHans de Goede 		drm_privacy_screen_put(connector->privacy_screen);
551334f74eeSHans de Goede 		connector->privacy_screen = NULL;
552334f74eeSHans de Goede 	}
553334f74eeSHans de Goede 
55452217195SDaniel Vetter 	if (connector->tile_group) {
55552217195SDaniel Vetter 		drm_mode_put_tile_group(dev, connector->tile_group);
55652217195SDaniel Vetter 		connector->tile_group = NULL;
55752217195SDaniel Vetter 	}
55852217195SDaniel Vetter 
55952217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
56052217195SDaniel Vetter 		drm_mode_remove(connector, mode);
56152217195SDaniel Vetter 
56252217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->modes, head)
56352217195SDaniel Vetter 		drm_mode_remove(connector, mode);
56452217195SDaniel Vetter 
565e5d6eeeaSBo Liu 	ida_free(&drm_connector_enum_list[connector->connector_type].ida,
56652217195SDaniel Vetter 			  connector->connector_type_id);
56752217195SDaniel Vetter 
568e5d6eeeaSBo Liu 	ida_free(&dev->mode_config.connector_ida, connector->index);
56952217195SDaniel Vetter 
57052217195SDaniel Vetter 	kfree(connector->display_info.bus_formats);
571c3292ab5SJani Nikula 	kfree(connector->display_info.vics);
57252217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
57352217195SDaniel Vetter 	kfree(connector->name);
57452217195SDaniel Vetter 	connector->name = NULL;
57548c429c6SHans de Goede 	fwnode_handle_put(connector->fwnode);
57648c429c6SHans de Goede 	connector->fwnode = NULL;
577613051daSDaniel Vetter 	spin_lock_irq(&dev->mode_config.connector_list_lock);
57852217195SDaniel Vetter 	list_del(&connector->head);
57952217195SDaniel Vetter 	dev->mode_config.num_connector--;
580613051daSDaniel Vetter 	spin_unlock_irq(&dev->mode_config.connector_list_lock);
58152217195SDaniel Vetter 
58252217195SDaniel Vetter 	WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
58352217195SDaniel Vetter 	if (connector->state && connector->funcs->atomic_destroy_state)
58452217195SDaniel Vetter 		connector->funcs->atomic_destroy_state(connector,
58552217195SDaniel Vetter 						       connector->state);
58652217195SDaniel Vetter 
587e73ab00eSDaniel Vetter 	mutex_destroy(&connector->mutex);
588e73ab00eSDaniel Vetter 
58952217195SDaniel Vetter 	memset(connector, 0, sizeof(*connector));
5906fdc2d49SSimon Ser 
5916fdc2d49SSimon Ser 	if (dev->registered)
5926fdc2d49SSimon Ser 		drm_sysfs_hotplug_event(dev);
59352217195SDaniel Vetter }
59452217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_cleanup);
59552217195SDaniel Vetter 
59652217195SDaniel Vetter /**
59752217195SDaniel Vetter  * drm_connector_register - register a connector
59852217195SDaniel Vetter  * @connector: the connector to register
59952217195SDaniel Vetter  *
60069b22f51SDaniel Vetter  * Register userspace interfaces for a connector. Only call this for connectors
60169b22f51SDaniel Vetter  * which can be hotplugged after drm_dev_register() has been called already,
60269b22f51SDaniel Vetter  * e.g. DP MST connectors. All other connectors will be registered automatically
60369b22f51SDaniel Vetter  * when calling drm_dev_register().
60452217195SDaniel Vetter  *
605d87fbea5SMaxime Ripard  * When the connector is no longer available, callers must call
606d87fbea5SMaxime Ripard  * drm_connector_unregister().
607d87fbea5SMaxime Ripard  *
60852217195SDaniel Vetter  * Returns:
60952217195SDaniel Vetter  * Zero on success, error code on failure.
61052217195SDaniel Vetter  */
61152217195SDaniel Vetter int drm_connector_register(struct drm_connector *connector)
61252217195SDaniel Vetter {
613e73ab00eSDaniel Vetter 	int ret = 0;
61452217195SDaniel Vetter 
615e6e7b48bSDaniel Vetter 	if (!connector->dev->registered)
616e6e7b48bSDaniel Vetter 		return 0;
617e6e7b48bSDaniel Vetter 
618e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
61939b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
620e73ab00eSDaniel Vetter 		goto unlock;
62152217195SDaniel Vetter 
62252217195SDaniel Vetter 	ret = drm_sysfs_connector_add(connector);
62352217195SDaniel Vetter 	if (ret)
624e73ab00eSDaniel Vetter 		goto unlock;
62552217195SDaniel Vetter 
626b792e640SGreg Kroah-Hartman 	drm_debugfs_connector_add(connector);
62752217195SDaniel Vetter 
62852217195SDaniel Vetter 	if (connector->funcs->late_register) {
62952217195SDaniel Vetter 		ret = connector->funcs->late_register(connector);
63052217195SDaniel Vetter 		if (ret)
63152217195SDaniel Vetter 			goto err_debugfs;
63252217195SDaniel Vetter 	}
63352217195SDaniel Vetter 
634*21b6c281SVille Syrjälä 	ret = drm_sysfs_connector_add_late(connector);
635*21b6c281SVille Syrjälä 	if (ret)
636*21b6c281SVille Syrjälä 		goto err_late_register;
637*21b6c281SVille Syrjälä 
63852217195SDaniel Vetter 	drm_mode_object_register(connector->dev, &connector->base);
63952217195SDaniel Vetter 
64039b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_REGISTERED;
641968d81a6SJeykumar Sankaran 
642968d81a6SJeykumar Sankaran 	/* Let userspace know we have a new connector */
643ad935754SSimon Ser 	drm_sysfs_connector_hotplug_event(connector);
644968d81a6SJeykumar Sankaran 
645334f74eeSHans de Goede 	if (connector->privacy_screen)
646334f74eeSHans de Goede 		drm_privacy_screen_register_notifier(connector->privacy_screen,
647334f74eeSHans de Goede 					   &connector->privacy_screen_notifier);
648334f74eeSHans de Goede 
6493d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
6503d3f7c1eSHans de Goede 	list_add_tail(&connector->global_connector_list_entry, &connector_list);
6513d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
652e73ab00eSDaniel Vetter 	goto unlock;
65352217195SDaniel Vetter 
654*21b6c281SVille Syrjälä err_late_register:
655*21b6c281SVille Syrjälä 	if (connector->funcs->early_unregister)
656*21b6c281SVille Syrjälä 		connector->funcs->early_unregister(connector);
65752217195SDaniel Vetter err_debugfs:
65852217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
65952217195SDaniel Vetter 	drm_sysfs_connector_remove(connector);
660e73ab00eSDaniel Vetter unlock:
661e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
66252217195SDaniel Vetter 	return ret;
66352217195SDaniel Vetter }
66452217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_register);
66552217195SDaniel Vetter 
66652217195SDaniel Vetter /**
66752217195SDaniel Vetter  * drm_connector_unregister - unregister a connector
66852217195SDaniel Vetter  * @connector: the connector to unregister
66952217195SDaniel Vetter  *
67069b22f51SDaniel Vetter  * Unregister userspace interfaces for a connector. Only call this for
671d87fbea5SMaxime Ripard  * connectors which have been registered explicitly by calling
672d87fbea5SMaxime Ripard  * drm_connector_register().
67352217195SDaniel Vetter  */
67452217195SDaniel Vetter void drm_connector_unregister(struct drm_connector *connector)
67552217195SDaniel Vetter {
676e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
67739b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
678e73ab00eSDaniel Vetter 		mutex_unlock(&connector->mutex);
67952217195SDaniel Vetter 		return;
680e73ab00eSDaniel Vetter 	}
68152217195SDaniel Vetter 
6823d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
6833d3f7c1eSHans de Goede 	list_del_init(&connector->global_connector_list_entry);
6843d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
6853d3f7c1eSHans de Goede 
686334f74eeSHans de Goede 	if (connector->privacy_screen)
687334f74eeSHans de Goede 		drm_privacy_screen_unregister_notifier(
688334f74eeSHans de Goede 					connector->privacy_screen,
689334f74eeSHans de Goede 					&connector->privacy_screen_notifier);
690334f74eeSHans de Goede 
691*21b6c281SVille Syrjälä 	drm_sysfs_connector_remove_early(connector);
692*21b6c281SVille Syrjälä 
69352217195SDaniel Vetter 	if (connector->funcs->early_unregister)
69452217195SDaniel Vetter 		connector->funcs->early_unregister(connector);
69552217195SDaniel Vetter 
69652217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
69783a30739SVille Syrjälä 	drm_sysfs_connector_remove(connector);
69852217195SDaniel Vetter 
69939b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
700e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
70152217195SDaniel Vetter }
70252217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_unregister);
70352217195SDaniel Vetter 
70452217195SDaniel Vetter void drm_connector_unregister_all(struct drm_device *dev)
70552217195SDaniel Vetter {
70652217195SDaniel Vetter 	struct drm_connector *connector;
707613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
70852217195SDaniel Vetter 
709b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
710613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter)
71152217195SDaniel Vetter 		drm_connector_unregister(connector);
712b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
71352217195SDaniel Vetter }
71452217195SDaniel Vetter 
71552217195SDaniel Vetter int drm_connector_register_all(struct drm_device *dev)
71652217195SDaniel Vetter {
71752217195SDaniel Vetter 	struct drm_connector *connector;
718613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
719613051daSDaniel Vetter 	int ret = 0;
72052217195SDaniel Vetter 
721b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
722613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter) {
72352217195SDaniel Vetter 		ret = drm_connector_register(connector);
72452217195SDaniel Vetter 		if (ret)
725613051daSDaniel Vetter 			break;
72652217195SDaniel Vetter 	}
727b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
72852217195SDaniel Vetter 
729613051daSDaniel Vetter 	if (ret)
73052217195SDaniel Vetter 		drm_connector_unregister_all(dev);
73152217195SDaniel Vetter 	return ret;
73252217195SDaniel Vetter }
73352217195SDaniel Vetter 
73452217195SDaniel Vetter /**
73552217195SDaniel Vetter  * drm_get_connector_status_name - return a string for connector status
73652217195SDaniel Vetter  * @status: connector status to compute name of
73752217195SDaniel Vetter  *
73852217195SDaniel Vetter  * In contrast to the other drm_get_*_name functions this one here returns a
73952217195SDaniel Vetter  * const pointer and hence is threadsafe.
740f85d9e59SRandy Dunlap  *
741f85d9e59SRandy Dunlap  * Returns: connector status string
74252217195SDaniel Vetter  */
74352217195SDaniel Vetter const char *drm_get_connector_status_name(enum drm_connector_status status)
74452217195SDaniel Vetter {
74552217195SDaniel Vetter 	if (status == connector_status_connected)
74652217195SDaniel Vetter 		return "connected";
74752217195SDaniel Vetter 	else if (status == connector_status_disconnected)
74852217195SDaniel Vetter 		return "disconnected";
74952217195SDaniel Vetter 	else
75052217195SDaniel Vetter 		return "unknown";
75152217195SDaniel Vetter }
75252217195SDaniel Vetter EXPORT_SYMBOL(drm_get_connector_status_name);
75352217195SDaniel Vetter 
7546140cf20SJani Nikula /**
7556140cf20SJani Nikula  * drm_get_connector_force_name - return a string for connector force
7566140cf20SJani Nikula  * @force: connector force to get name of
7576140cf20SJani Nikula  *
7586140cf20SJani Nikula  * Returns: const pointer to name.
7596140cf20SJani Nikula  */
7606140cf20SJani Nikula const char *drm_get_connector_force_name(enum drm_connector_force force)
7616140cf20SJani Nikula {
7626140cf20SJani Nikula 	switch (force) {
7636140cf20SJani Nikula 	case DRM_FORCE_UNSPECIFIED:
7646140cf20SJani Nikula 		return "unspecified";
7656140cf20SJani Nikula 	case DRM_FORCE_OFF:
7666140cf20SJani Nikula 		return "off";
7676140cf20SJani Nikula 	case DRM_FORCE_ON:
7686140cf20SJani Nikula 		return "on";
7696140cf20SJani Nikula 	case DRM_FORCE_ON_DIGITAL:
7706140cf20SJani Nikula 		return "digital";
7716140cf20SJani Nikula 	default:
7726140cf20SJani Nikula 		return "unknown";
7736140cf20SJani Nikula 	}
7746140cf20SJani Nikula }
7756140cf20SJani Nikula 
776613051daSDaniel Vetter #ifdef CONFIG_LOCKDEP
777613051daSDaniel Vetter static struct lockdep_map connector_list_iter_dep_map = {
778613051daSDaniel Vetter 	.name = "drm_connector_list_iter"
779613051daSDaniel Vetter };
780613051daSDaniel Vetter #endif
781613051daSDaniel Vetter 
782613051daSDaniel Vetter /**
783b982dab1SThierry Reding  * drm_connector_list_iter_begin - initialize a connector_list iterator
784613051daSDaniel Vetter  * @dev: DRM device
785613051daSDaniel Vetter  * @iter: connector_list iterator
786613051daSDaniel Vetter  *
787d574528aSDaniel Vetter  * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
788b982dab1SThierry Reding  * must always be cleaned up again by calling drm_connector_list_iter_end().
789613051daSDaniel Vetter  * Iteration itself happens using drm_connector_list_iter_next() or
790613051daSDaniel Vetter  * drm_for_each_connector_iter().
791613051daSDaniel Vetter  */
792b982dab1SThierry Reding void drm_connector_list_iter_begin(struct drm_device *dev,
793613051daSDaniel Vetter 				   struct drm_connector_list_iter *iter)
794613051daSDaniel Vetter {
795613051daSDaniel Vetter 	iter->dev = dev;
796613051daSDaniel Vetter 	iter->conn = NULL;
797613051daSDaniel Vetter 	lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
798613051daSDaniel Vetter }
799b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_begin);
800613051daSDaniel Vetter 
801a703c550SDaniel Vetter /*
802a703c550SDaniel Vetter  * Extra-safe connector put function that works in any context. Should only be
803a703c550SDaniel Vetter  * used from the connector_iter functions, where we never really expect to
804a703c550SDaniel Vetter  * actually release the connector when dropping our final reference.
805a703c550SDaniel Vetter  */
806a703c550SDaniel Vetter static void
807ea497bb9SDaniel Vetter __drm_connector_put_safe(struct drm_connector *conn)
808a703c550SDaniel Vetter {
809ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &conn->dev->mode_config;
810ea497bb9SDaniel Vetter 
811ea497bb9SDaniel Vetter 	lockdep_assert_held(&config->connector_list_lock);
812ea497bb9SDaniel Vetter 
813ea497bb9SDaniel Vetter 	if (!refcount_dec_and_test(&conn->base.refcount.refcount))
814ea497bb9SDaniel Vetter 		return;
815ea497bb9SDaniel Vetter 
816ea497bb9SDaniel Vetter 	llist_add(&conn->free_node, &config->connector_free_list);
817ea497bb9SDaniel Vetter 	schedule_work(&config->connector_free_work);
818a703c550SDaniel Vetter }
819a703c550SDaniel Vetter 
820613051daSDaniel Vetter /**
821613051daSDaniel Vetter  * drm_connector_list_iter_next - return next connector
8224f45c778SLyude Paul  * @iter: connector_list iterator
823613051daSDaniel Vetter  *
824f85d9e59SRandy Dunlap  * Returns: the next connector for @iter, or NULL when the list walk has
825613051daSDaniel Vetter  * completed.
826613051daSDaniel Vetter  */
827613051daSDaniel Vetter struct drm_connector *
828613051daSDaniel Vetter drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
829613051daSDaniel Vetter {
830613051daSDaniel Vetter 	struct drm_connector *old_conn = iter->conn;
831613051daSDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
832613051daSDaniel Vetter 	struct list_head *lhead;
833613051daSDaniel Vetter 	unsigned long flags;
834613051daSDaniel Vetter 
835613051daSDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
836613051daSDaniel Vetter 	lhead = old_conn ? &old_conn->head : &config->connector_list;
837613051daSDaniel Vetter 
838613051daSDaniel Vetter 	do {
839613051daSDaniel Vetter 		if (lhead->next == &config->connector_list) {
840613051daSDaniel Vetter 			iter->conn = NULL;
841613051daSDaniel Vetter 			break;
842613051daSDaniel Vetter 		}
843613051daSDaniel Vetter 
844613051daSDaniel Vetter 		lhead = lhead->next;
845613051daSDaniel Vetter 		iter->conn = list_entry(lhead, struct drm_connector, head);
846613051daSDaniel Vetter 
847613051daSDaniel Vetter 		/* loop until it's not a zombie connector */
848613051daSDaniel Vetter 	} while (!kref_get_unless_zero(&iter->conn->base.refcount));
849613051daSDaniel Vetter 
850613051daSDaniel Vetter 	if (old_conn)
851ea497bb9SDaniel Vetter 		__drm_connector_put_safe(old_conn);
852ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
853613051daSDaniel Vetter 
854613051daSDaniel Vetter 	return iter->conn;
855613051daSDaniel Vetter }
856613051daSDaniel Vetter EXPORT_SYMBOL(drm_connector_list_iter_next);
857613051daSDaniel Vetter 
858613051daSDaniel Vetter /**
859b982dab1SThierry Reding  * drm_connector_list_iter_end - tear down a connector_list iterator
860613051daSDaniel Vetter  * @iter: connector_list iterator
861613051daSDaniel Vetter  *
862613051daSDaniel Vetter  * Tears down @iter and releases any resources (like &drm_connector references)
863613051daSDaniel Vetter  * acquired while walking the list. This must always be called, both when the
864613051daSDaniel Vetter  * iteration completes fully or when it was aborted without walking the entire
865613051daSDaniel Vetter  * list.
866613051daSDaniel Vetter  */
867b982dab1SThierry Reding void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
868613051daSDaniel Vetter {
869ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
870ea497bb9SDaniel Vetter 	unsigned long flags;
871ea497bb9SDaniel Vetter 
872613051daSDaniel Vetter 	iter->dev = NULL;
873ea497bb9SDaniel Vetter 	if (iter->conn) {
874ea497bb9SDaniel Vetter 		spin_lock_irqsave(&config->connector_list_lock, flags);
875ea497bb9SDaniel Vetter 		__drm_connector_put_safe(iter->conn);
876ea497bb9SDaniel Vetter 		spin_unlock_irqrestore(&config->connector_list_lock, flags);
877ea497bb9SDaniel Vetter 	}
8785facae4fSQian Cai 	lock_release(&connector_list_iter_dep_map, _RET_IP_);
879613051daSDaniel Vetter }
880b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_end);
881613051daSDaniel Vetter 
88252217195SDaniel Vetter static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
88352217195SDaniel Vetter 	{ SubPixelUnknown, "Unknown" },
88452217195SDaniel Vetter 	{ SubPixelHorizontalRGB, "Horizontal RGB" },
88552217195SDaniel Vetter 	{ SubPixelHorizontalBGR, "Horizontal BGR" },
88652217195SDaniel Vetter 	{ SubPixelVerticalRGB, "Vertical RGB" },
88752217195SDaniel Vetter 	{ SubPixelVerticalBGR, "Vertical BGR" },
88852217195SDaniel Vetter 	{ SubPixelNone, "None" },
88952217195SDaniel Vetter };
89052217195SDaniel Vetter 
89152217195SDaniel Vetter /**
89252217195SDaniel Vetter  * drm_get_subpixel_order_name - return a string for a given subpixel enum
89352217195SDaniel Vetter  * @order: enum of subpixel_order
89452217195SDaniel Vetter  *
89552217195SDaniel Vetter  * Note you could abuse this and return something out of bounds, but that
89652217195SDaniel Vetter  * would be a caller error.  No unscrubbed user data should make it here.
897f85d9e59SRandy Dunlap  *
898f85d9e59SRandy Dunlap  * Returns: string describing an enumerated subpixel property
89952217195SDaniel Vetter  */
90052217195SDaniel Vetter const char *drm_get_subpixel_order_name(enum subpixel_order order)
90152217195SDaniel Vetter {
90252217195SDaniel Vetter 	return drm_subpixel_enum_list[order].name;
90352217195SDaniel Vetter }
90452217195SDaniel Vetter EXPORT_SYMBOL(drm_get_subpixel_order_name);
90552217195SDaniel Vetter 
90652217195SDaniel Vetter static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
90752217195SDaniel Vetter 	{ DRM_MODE_DPMS_ON, "On" },
90852217195SDaniel Vetter 	{ DRM_MODE_DPMS_STANDBY, "Standby" },
90952217195SDaniel Vetter 	{ DRM_MODE_DPMS_SUSPEND, "Suspend" },
91052217195SDaniel Vetter 	{ DRM_MODE_DPMS_OFF, "Off" }
91152217195SDaniel Vetter };
91252217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
91352217195SDaniel Vetter 
91440ee6fbeSManasi Navare static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
91540ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_GOOD, "Good" },
91640ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_BAD, "Bad" },
91740ee6fbeSManasi Navare };
91840ee6fbeSManasi Navare 
919b3c6c8bfSDaniel Vetter /**
920b3c6c8bfSDaniel Vetter  * drm_display_info_set_bus_formats - set the supported bus formats
921b3c6c8bfSDaniel Vetter  * @info: display info to store bus formats in
922b3c6c8bfSDaniel Vetter  * @formats: array containing the supported bus formats
923b3c6c8bfSDaniel Vetter  * @num_formats: the number of entries in the fmts array
924b3c6c8bfSDaniel Vetter  *
925b3c6c8bfSDaniel Vetter  * Store the supported bus formats in display info structure.
926b3c6c8bfSDaniel Vetter  * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
927b3c6c8bfSDaniel Vetter  * a full list of available formats.
928f85d9e59SRandy Dunlap  *
929f85d9e59SRandy Dunlap  * Returns:
930f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
931b3c6c8bfSDaniel Vetter  */
932b3c6c8bfSDaniel Vetter int drm_display_info_set_bus_formats(struct drm_display_info *info,
933b3c6c8bfSDaniel Vetter 				     const u32 *formats,
934b3c6c8bfSDaniel Vetter 				     unsigned int num_formats)
935b3c6c8bfSDaniel Vetter {
936b3c6c8bfSDaniel Vetter 	u32 *fmts = NULL;
937b3c6c8bfSDaniel Vetter 
938b3c6c8bfSDaniel Vetter 	if (!formats && num_formats)
939b3c6c8bfSDaniel Vetter 		return -EINVAL;
940b3c6c8bfSDaniel Vetter 
941b3c6c8bfSDaniel Vetter 	if (formats && num_formats) {
942b3c6c8bfSDaniel Vetter 		fmts = kmemdup(formats, sizeof(*formats) * num_formats,
943b3c6c8bfSDaniel Vetter 			       GFP_KERNEL);
944b3c6c8bfSDaniel Vetter 		if (!fmts)
945b3c6c8bfSDaniel Vetter 			return -ENOMEM;
946b3c6c8bfSDaniel Vetter 	}
947b3c6c8bfSDaniel Vetter 
948b3c6c8bfSDaniel Vetter 	kfree(info->bus_formats);
949b3c6c8bfSDaniel Vetter 	info->bus_formats = fmts;
950b3c6c8bfSDaniel Vetter 	info->num_bus_formats = num_formats;
951b3c6c8bfSDaniel Vetter 
952b3c6c8bfSDaniel Vetter 	return 0;
953b3c6c8bfSDaniel Vetter }
954b3c6c8bfSDaniel Vetter EXPORT_SYMBOL(drm_display_info_set_bus_formats);
955b3c6c8bfSDaniel Vetter 
95652217195SDaniel Vetter /* Optional connector properties. */
95752217195SDaniel Vetter static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
95852217195SDaniel Vetter 	{ DRM_MODE_SCALE_NONE, "None" },
95952217195SDaniel Vetter 	{ DRM_MODE_SCALE_FULLSCREEN, "Full" },
96052217195SDaniel Vetter 	{ DRM_MODE_SCALE_CENTER, "Center" },
96152217195SDaniel Vetter 	{ DRM_MODE_SCALE_ASPECT, "Full aspect" },
96252217195SDaniel Vetter };
96352217195SDaniel Vetter 
96452217195SDaniel Vetter static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
96552217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
96652217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
96752217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
96852217195SDaniel Vetter };
96952217195SDaniel Vetter 
97050525c33SStanislav Lisovskiy static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
97150525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
97250525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
97350525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
97450525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
97550525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GAME, "Game" },
97650525c33SStanislav Lisovskiy };
97750525c33SStanislav Lisovskiy 
9788d70f395SHans de Goede static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
9798d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_NORMAL,	"Normal"	},
9808d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP,	"Upside Down"	},
9818d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_LEFT_UP,	"Left Side Up"	},
9828d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,	"Right Side Up"	},
9838d70f395SHans de Goede };
9848d70f395SHans de Goede 
98552217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
98652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
98752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
98852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
98952217195SDaniel Vetter };
99052217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
99152217195SDaniel Vetter 
99252217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
993e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I, TV-out and DP */
99452217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
99552217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
99652217195SDaniel Vetter };
99752217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
99852217195SDaniel Vetter 		 drm_dvi_i_subconnector_enum_list)
99952217195SDaniel Vetter 
10007d63cd85SMaxime Ripard static const struct drm_prop_enum_list drm_tv_mode_enum_list[] = {
10017d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_NTSC, "NTSC" },
10027d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_NTSC_443, "NTSC-443" },
10037d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_NTSC_J, "NTSC-J" },
10047d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_PAL, "PAL" },
10057d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_PAL_M, "PAL-M" },
10067d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_PAL_N, "PAL-N" },
10077d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_SECAM, "SECAM" },
10087d63cd85SMaxime Ripard };
10097d63cd85SMaxime Ripard DRM_ENUM_NAME_FN(drm_get_tv_mode_name, drm_tv_mode_enum_list)
10107d63cd85SMaxime Ripard 
1011d4613e3eSMaxime Ripard /**
1012d4613e3eSMaxime Ripard  * drm_get_tv_mode_from_name - Translates a TV mode name into its enum value
1013d4613e3eSMaxime Ripard  * @name: TV Mode name we want to convert
1014d4613e3eSMaxime Ripard  * @len: Length of @name
1015d4613e3eSMaxime Ripard  *
1016d4613e3eSMaxime Ripard  * Translates @name into an enum drm_connector_tv_mode.
1017d4613e3eSMaxime Ripard  *
1018d4613e3eSMaxime Ripard  * Returns: the enum value on success, a negative errno otherwise.
1019d4613e3eSMaxime Ripard  */
1020d4613e3eSMaxime Ripard int drm_get_tv_mode_from_name(const char *name, size_t len)
1021d4613e3eSMaxime Ripard {
1022d4613e3eSMaxime Ripard 	unsigned int i;
1023d4613e3eSMaxime Ripard 
1024d4613e3eSMaxime Ripard 	for (i = 0; i < ARRAY_SIZE(drm_tv_mode_enum_list); i++) {
1025d4613e3eSMaxime Ripard 		const struct drm_prop_enum_list *item = &drm_tv_mode_enum_list[i];
1026d4613e3eSMaxime Ripard 
1027d4613e3eSMaxime Ripard 		if (strlen(item->name) == len && !strncmp(item->name, name, len))
1028d4613e3eSMaxime Ripard 			return item->type;
1029d4613e3eSMaxime Ripard 	}
1030d4613e3eSMaxime Ripard 
1031d4613e3eSMaxime Ripard 	return -EINVAL;
1032d4613e3eSMaxime Ripard }
1033d4613e3eSMaxime Ripard EXPORT_SYMBOL(drm_get_tv_mode_from_name);
1034d4613e3eSMaxime Ripard 
103552217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
103652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
103752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
103852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
103952217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
104052217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
104152217195SDaniel Vetter };
104252217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
104352217195SDaniel Vetter 
104452217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
1045e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I, TV-out and DP */
104652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
104752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
104852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
104952217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
105052217195SDaniel Vetter };
105152217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
105252217195SDaniel Vetter 		 drm_tv_subconnector_enum_list)
105352217195SDaniel Vetter 
1054e5b92773SOleg Vasilev static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = {
1055e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,     "Unknown"   }, /* DVI-I, TV-out and DP */
1056e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_VGA,	     "VGA"       }, /* DP */
1057e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_DVID,	     "DVI-D"     }, /* DP */
1058e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_HDMIA,	     "HDMI"      }, /* DP */
1059e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_DisplayPort, "DP"        }, /* DP */
1060e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Wireless,    "Wireless"  }, /* DP */
1061e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Native,	     "Native"    }, /* DP */
1062e5b92773SOleg Vasilev };
1063e5b92773SOleg Vasilev 
1064e5b92773SOleg Vasilev DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name,
1065e5b92773SOleg Vasilev 		 drm_dp_subconnector_enum_list)
1066e5b92773SOleg Vasilev 
1067c627087cSHarry Wentland 
1068c627087cSHarry Wentland static const char * const colorspace_names[] = {
1069d2c6a405SUma Shankar 	/* For Default case, driver will set the colorspace */
1070c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_DEFAULT] = "Default",
1071d2c6a405SUma Shankar 	/* Standard Definition Colorimetry based on CEA 861 */
1072c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = "SMPTE_170M_YCC",
1073c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT709_YCC] = "BT709_YCC",
1074d2c6a405SUma Shankar 	/* Standard Definition Colorimetry based on IEC 61966-2-4 */
1075c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_XVYCC_601] = "XVYCC_601",
1076d2c6a405SUma Shankar 	/* High Definition Colorimetry based on IEC 61966-2-4 */
1077c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_XVYCC_709] = "XVYCC_709",
1078d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-1/Amendment 1 */
1079c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_SYCC_601] = "SYCC_601",
1080d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-5 [33] */
1081c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_OPYCC_601] = "opYCC_601",
1082d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-5 */
1083c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_OPRGB] = "opRGB",
1084d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
1085c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT2020_CYCC] = "BT2020_CYCC",
1086d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
1087c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT2020_RGB] = "BT2020_RGB",
1088d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
1089c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT2020_YCC] = "BT2020_YCC",
1090d2c6a405SUma Shankar 	/* Added as part of Additional Colorimetry Extension in 861.G */
1091c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65] = "DCI-P3_RGB_D65",
1092c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER] = "DCI-P3_RGB_Theater",
1093c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED] = "RGB_WIDE_FIXED",
1094c627087cSHarry Wentland 	/* Colorimetry based on scRGB (IEC 61966-2-2) */
1095c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT] = "RGB_WIDE_FLOAT",
1096c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT601_YCC] = "BT601_YCC",
1097d2c6a405SUma Shankar };
1098d2c6a405SUma Shankar 
1099035d53e0SHarry Wentland /**
1100035d53e0SHarry Wentland  * drm_get_colorspace_name - return a string for color encoding
1101035d53e0SHarry Wentland  * @colorspace: color space to compute name of
1102035d53e0SHarry Wentland  *
1103035d53e0SHarry Wentland  * In contrast to the other drm_get_*_name functions this one here returns a
1104035d53e0SHarry Wentland  * const pointer and hence is threadsafe.
1105035d53e0SHarry Wentland  */
1106035d53e0SHarry Wentland const char *drm_get_colorspace_name(enum drm_colorspace colorspace)
1107035d53e0SHarry Wentland {
1108035d53e0SHarry Wentland 	if (colorspace < ARRAY_SIZE(colorspace_names) && colorspace_names[colorspace])
1109035d53e0SHarry Wentland 		return colorspace_names[colorspace];
1110035d53e0SHarry Wentland 	else
1111035d53e0SHarry Wentland 		return "(null)";
1112035d53e0SHarry Wentland }
1113035d53e0SHarry Wentland 
1114c627087cSHarry Wentland static const u32 hdmi_colorspaces =
1115c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_SMPTE_170M_YCC) |
1116c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |
1117c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_XVYCC_601) |
1118c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_XVYCC_709) |
1119c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_SYCC_601) |
1120c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_OPYCC_601) |
1121c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_OPRGB) |
1122c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) |
1123c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) |
1124c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_YCC) |
1125c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) |
1126c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER);
1127c627087cSHarry Wentland 
112845cf0e91SGwan-gyeong Mun /*
112945cf0e91SGwan-gyeong Mun  * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
113045cf0e91SGwan-gyeong Mun  * Format Table 2-120
113145cf0e91SGwan-gyeong Mun  */
1132c627087cSHarry Wentland static const u32 dp_colorspaces =
1133c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED) |
1134c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT) |
1135c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_OPRGB) |
1136c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) |
1137c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) |
1138c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT601_YCC) |
1139c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |
1140c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_XVYCC_601) |
1141c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_XVYCC_709) |
1142c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_SYCC_601) |
1143c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_OPYCC_601) |
1144c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) |
1145c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_YCC);
114645cf0e91SGwan-gyeong Mun 
11474ada6f22SDaniel Vetter /**
11484ada6f22SDaniel Vetter  * DOC: standard connector properties
11494ada6f22SDaniel Vetter  *
11504ada6f22SDaniel Vetter  * DRM connectors have a few standardized properties:
11514ada6f22SDaniel Vetter  *
11524ada6f22SDaniel Vetter  * EDID:
11534ada6f22SDaniel Vetter  * 	Blob property which contains the current EDID read from the sink. This
11544ada6f22SDaniel Vetter  * 	is useful to parse sink identification information like vendor, model
11554ada6f22SDaniel Vetter  * 	and serial. Drivers should update this property by calling
1156c555f023SDaniel Vetter  * 	drm_connector_update_edid_property(), usually after having parsed
11574ada6f22SDaniel Vetter  * 	the EDID using drm_add_edid_modes(). Userspace cannot change this
11584ada6f22SDaniel Vetter  * 	property.
115912767469SSimon Ser  *
116012767469SSimon Ser  * 	User-space should not parse the EDID to obtain information exposed via
116112767469SSimon Ser  * 	other KMS properties (because the kernel might apply limits, quirks or
116212767469SSimon Ser  * 	fixups to the EDID). For instance, user-space should not try to parse
116312767469SSimon Ser  * 	mode lists from the EDID.
11644ada6f22SDaniel Vetter  * DPMS:
11654ada6f22SDaniel Vetter  * 	Legacy property for setting the power state of the connector. For atomic
11664ada6f22SDaniel Vetter  * 	drivers this is only provided for backwards compatibility with existing
11674ada6f22SDaniel Vetter  * 	drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
11684ada6f22SDaniel Vetter  * 	connector is linked to. Drivers should never set this property directly,
1169d574528aSDaniel Vetter  * 	it is handled by the DRM core by calling the &drm_connector_funcs.dpms
1170144a7999SDaniel Vetter  * 	callback. For atomic drivers the remapping to the "ACTIVE" property is
11711e3e4caeSSimon Ser  * 	implemented in the DRM core.
1172d0d1aee5SDaniel Vetter  *
1173d0d1aee5SDaniel Vetter  * 	Note that this property cannot be set through the MODE_ATOMIC ioctl,
1174d0d1aee5SDaniel Vetter  * 	userspace must use "ACTIVE" on the CRTC instead.
1175d0d1aee5SDaniel Vetter  *
1176d0d1aee5SDaniel Vetter  * 	WARNING:
1177d0d1aee5SDaniel Vetter  *
1178d0d1aee5SDaniel Vetter  * 	For userspace also running on legacy drivers the "DPMS" semantics are a
1179d0d1aee5SDaniel Vetter  * 	lot more complicated. First, userspace cannot rely on the "DPMS" value
1180d0d1aee5SDaniel Vetter  * 	returned by the GETCONNECTOR actually reflecting reality, because many
1181d0d1aee5SDaniel Vetter  * 	drivers fail to update it. For atomic drivers this is taken care of in
1182d0d1aee5SDaniel Vetter  * 	drm_atomic_helper_update_legacy_modeset_state().
1183d0d1aee5SDaniel Vetter  *
1184d0d1aee5SDaniel Vetter  * 	The second issue is that the DPMS state is only well-defined when the
1185d0d1aee5SDaniel Vetter  * 	connector is connected to a CRTC. In atomic the DRM core enforces that
1186d0d1aee5SDaniel Vetter  * 	"ACTIVE" is off in such a case, no such checks exists for "DPMS".
1187d0d1aee5SDaniel Vetter  *
1188d0d1aee5SDaniel Vetter  * 	Finally, when enabling an output using the legacy SETCONFIG ioctl then
1189d0d1aee5SDaniel Vetter  * 	"DPMS" is forced to ON. But see above, that might not be reflected in
1190d0d1aee5SDaniel Vetter  * 	the software value on legacy drivers.
1191d0d1aee5SDaniel Vetter  *
1192d0d1aee5SDaniel Vetter  * 	Summarizing: Only set "DPMS" when the connector is known to be enabled,
1193d0d1aee5SDaniel Vetter  * 	assume that a successful SETCONFIG call also sets "DPMS" to on, and
1194d0d1aee5SDaniel Vetter  * 	never read back the value of "DPMS" because it can be incorrect.
11954ada6f22SDaniel Vetter  * PATH:
11964ada6f22SDaniel Vetter  * 	Connector path property to identify how this sink is physically
11974ada6f22SDaniel Vetter  * 	connected. Used by DP MST. This should be set by calling
119897e14fbeSDaniel Vetter  * 	drm_connector_set_path_property(), in the case of DP MST with the
11994ada6f22SDaniel Vetter  * 	path property the MST manager created. Userspace cannot change this
12004ada6f22SDaniel Vetter  * 	property.
12014ada6f22SDaniel Vetter  * TILE:
12024ada6f22SDaniel Vetter  * 	Connector tile group property to indicate how a set of DRM connector
12034ada6f22SDaniel Vetter  * 	compose together into one logical screen. This is used by both high-res
12044ada6f22SDaniel Vetter  * 	external screens (often only using a single cable, but exposing multiple
12054ada6f22SDaniel Vetter  * 	DP MST sinks), or high-res integrated panels (like dual-link DSI) which
12064ada6f22SDaniel Vetter  * 	are not gen-locked. Note that for tiled panels which are genlocked, like
12074ada6f22SDaniel Vetter  * 	dual-link LVDS or dual-link DSI, the driver should try to not expose the
120884e543bcSAntonio Borneo  * 	tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers
120997e14fbeSDaniel Vetter  * 	should update this value using drm_connector_set_tile_property().
12104ada6f22SDaniel Vetter  * 	Userspace cannot change this property.
121140ee6fbeSManasi Navare  * link-status:
1212716719a3SSean Paul  *      Connector link-status property to indicate the status of link. The
1213716719a3SSean Paul  *      default value of link-status is "GOOD". If something fails during or
1214716719a3SSean Paul  *      after modeset, the kernel driver may set this to "BAD" and issue a
1215716719a3SSean Paul  *      hotplug uevent. Drivers should update this value using
121697e14fbeSDaniel Vetter  *      drm_connector_set_link_status_property().
1217a66da873SSimon Ser  *
1218a66da873SSimon Ser  *      When user-space receives the hotplug uevent and detects a "BAD"
1219a66da873SSimon Ser  *      link-status, the sink doesn't receive pixels anymore (e.g. the screen
1220a66da873SSimon Ser  *      becomes completely black). The list of available modes may have
1221a66da873SSimon Ser  *      changed. User-space is expected to pick a new mode if the current one
1222a66da873SSimon Ser  *      has disappeared and perform a new modeset with link-status set to
1223a66da873SSimon Ser  *      "GOOD" to re-enable the connector.
1224a66da873SSimon Ser  *
1225a66da873SSimon Ser  *      If multiple connectors share the same CRTC and one of them gets a "BAD"
1226a66da873SSimon Ser  *      link-status, the other are unaffected (ie. the sinks still continue to
1227a66da873SSimon Ser  *      receive pixels).
1228a66da873SSimon Ser  *
1229a66da873SSimon Ser  *      When user-space performs an atomic commit on a connector with a "BAD"
1230a66da873SSimon Ser  *      link-status without resetting the property to "GOOD", the sink may
1231a66da873SSimon Ser  *      still not receive pixels. When user-space performs an atomic commit
1232a66da873SSimon Ser  *      which resets the link-status property to "GOOD" without the
1233a66da873SSimon Ser  *      ALLOW_MODESET flag set, it might fail because a modeset is required.
1234a66da873SSimon Ser  *
1235a66da873SSimon Ser  *      User-space can only change link-status to "GOOD", changing it to "BAD"
1236a66da873SSimon Ser  *      is a no-op.
1237a66da873SSimon Ser  *
1238a66da873SSimon Ser  *      For backwards compatibility with non-atomic userspace the kernel
1239a66da873SSimon Ser  *      tries to automatically set the link-status back to "GOOD" in the
1240a66da873SSimon Ser  *      SETCRTC IOCTL. This might fail if the mode is no longer valid, similar
1241a66da873SSimon Ser  *      to how it might fail if a different screen has been connected in the
1242a66da873SSimon Ser  *      interim.
124366660d4cSDave Airlie  * non_desktop:
124466660d4cSDave Airlie  * 	Indicates the output should be ignored for purposes of displaying a
124566660d4cSDave Airlie  * 	standard desktop environment or console. This is most likely because
124666660d4cSDave Airlie  * 	the output device is not rectilinear.
124724557865SSean Paul  * Content Protection:
124824557865SSean Paul  *	This property is used by userspace to request the kernel protect future
124924557865SSean Paul  *	content communicated over the link. When requested, kernel will apply
125024557865SSean Paul  *	the appropriate means of protection (most often HDCP), and use the
125124557865SSean Paul  *	property to tell userspace the protection is active.
125224557865SSean Paul  *
125324557865SSean Paul  *	Drivers can set this up by calling
125424557865SSean Paul  *	drm_connector_attach_content_protection_property() on initialization.
125524557865SSean Paul  *
125624557865SSean Paul  *	The value of this property can be one of the following:
125724557865SSean Paul  *
1258bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
125924557865SSean Paul  *		The link is not protected, content is transmitted in the clear.
1260bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
126124557865SSean Paul  *		Userspace has requested content protection, but the link is not
126224557865SSean Paul  *		currently protected. When in this state, kernel should enable
126324557865SSean Paul  *		Content Protection as soon as possible.
1264bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
126524557865SSean Paul  *		Userspace has requested content protection, and the link is
126624557865SSean Paul  *		protected. Only the driver can set the property to this value.
126724557865SSean Paul  *		If userspace attempts to set to ENABLED, kernel will return
126824557865SSean Paul  *		-EINVAL.
126924557865SSean Paul  *
127024557865SSean Paul  *	A few guidelines:
127124557865SSean Paul  *
127224557865SSean Paul  *	- DESIRED state should be preserved until userspace de-asserts it by
127324557865SSean Paul  *	  setting the property to UNDESIRED. This means ENABLED should only
127424557865SSean Paul  *	  transition to UNDESIRED when the user explicitly requests it.
127524557865SSean Paul  *	- If the state is DESIRED, kernel should attempt to re-authenticate the
127624557865SSean Paul  *	  link whenever possible. This includes across disable/enable, dpms,
127724557865SSean Paul  *	  hotplug, downstream device changes, link status failures, etc..
1278bb5a45d4SRamalingam C  *	- Kernel sends uevent with the connector id and property id through
1279bb5a45d4SRamalingam C  *	  @drm_hdcp_update_content_protection, upon below kernel triggered
1280bb5a45d4SRamalingam C  *	  scenarios:
128112db36bcSSean Paul  *
128212db36bcSSean Paul  *		- DESIRED -> ENABLED (authentication success)
128312db36bcSSean Paul  *		- ENABLED -> DESIRED (termination of authentication)
1284bb5a45d4SRamalingam C  *	- Please note no uevents for userspace triggered property state changes,
1285bb5a45d4SRamalingam C  *	  which can't fail such as
128612db36bcSSean Paul  *
128712db36bcSSean Paul  *		- DESIRED/ENABLED -> UNDESIRED
128812db36bcSSean Paul  *		- UNDESIRED -> DESIRED
1289bb5a45d4SRamalingam C  *	- Userspace is responsible for polling the property or listen to uevents
1290bb5a45d4SRamalingam C  *	  to determine when the value transitions from ENABLED to DESIRED.
1291bb5a45d4SRamalingam C  *	  This signifies the link is no longer protected and userspace should
1292bb5a45d4SRamalingam C  *	  take appropriate action (whatever that might be).
12934ada6f22SDaniel Vetter  *
12947672dbbaSRamalingam C  * HDCP Content Type:
12957672dbbaSRamalingam C  *	This Enum property is used by the userspace to declare the content type
12967672dbbaSRamalingam C  *	of the display stream, to kernel. Here display stream stands for any
12977672dbbaSRamalingam C  *	display content that userspace intended to display through HDCP
12987672dbbaSRamalingam C  *	encryption.
12997672dbbaSRamalingam C  *
13007672dbbaSRamalingam C  *	Content Type of a stream is decided by the owner of the stream, as
13017672dbbaSRamalingam C  *	"HDCP Type0" or "HDCP Type1".
13027672dbbaSRamalingam C  *
13037672dbbaSRamalingam C  *	The value of the property can be one of the below:
13047672dbbaSRamalingam C  *	  - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0
13057672dbbaSRamalingam C  *	  - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1
13067672dbbaSRamalingam C  *
13077672dbbaSRamalingam C  *	When kernel starts the HDCP authentication (see "Content Protection"
13087672dbbaSRamalingam C  *	for details), it uses the content type in "HDCP Content Type"
13097672dbbaSRamalingam C  *	for performing the HDCP authentication with the display sink.
13107672dbbaSRamalingam C  *
13117672dbbaSRamalingam C  *	Please note in HDCP spec versions, a link can be authenticated with
13127672dbbaSRamalingam C  *	HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be
13137672dbbaSRamalingam C  *	authenticated with HDCP1.4 only for Content Type 0(though it is implicit
13147672dbbaSRamalingam C  *	in nature. As there is no reference for Content Type in HDCP1.4).
13157672dbbaSRamalingam C  *
13167672dbbaSRamalingam C  *	HDCP2.2 authentication protocol itself takes the "Content Type" as a
13177672dbbaSRamalingam C  *	parameter, which is a input for the DP HDCP2.2 encryption algo.
13187672dbbaSRamalingam C  *
13197672dbbaSRamalingam C  *	In case of Type 0 content protection request, kernel driver can choose
13207672dbbaSRamalingam C  *	either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for
13217672dbbaSRamalingam C  *	"HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send
13227672dbbaSRamalingam C  *	that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).
13237672dbbaSRamalingam C  *	But if the content is classified as "HDCP Type 1", above mentioned
13247672dbbaSRamalingam C  *	HDCP 2.2 repeater wont send the content to the HDCP sink as it can't
13257672dbbaSRamalingam C  *	authenticate the HDCP1.4 capable sink for "HDCP Type 1".
13267672dbbaSRamalingam C  *
13277672dbbaSRamalingam C  *	Please note userspace can be ignorant of the HDCP versions used by the
13287672dbbaSRamalingam C  *	kernel driver to achieve the "HDCP Content Type".
13297672dbbaSRamalingam C  *
13307672dbbaSRamalingam C  *	At current scenario, classifying a content as Type 1 ensures that the
13317672dbbaSRamalingam C  *	content will be displayed only through the HDCP2.2 encrypted link.
13327672dbbaSRamalingam C  *
13337672dbbaSRamalingam C  *	Note that the HDCP Content Type property is introduced at HDCP 2.2, and
13347672dbbaSRamalingam C  *	defaults to type 0. It is only exposed by drivers supporting HDCP 2.2
13357672dbbaSRamalingam C  *	(hence supporting Type 0 and Type 1). Based on how next versions of
13367672dbbaSRamalingam C  *	HDCP specs are defined content Type could be used for higher versions
13377672dbbaSRamalingam C  *	too.
13387672dbbaSRamalingam C  *
13397672dbbaSRamalingam C  *	If content type is changed when "Content Protection" is not UNDESIRED,
13407672dbbaSRamalingam C  *	then kernel will disable the HDCP and re-enable with new type in the
13417672dbbaSRamalingam C  *	same atomic commit. And when "Content Protection" is ENABLED, it means
13427672dbbaSRamalingam C  *	that link is HDCP authenticated and encrypted, for the transmission of
13437672dbbaSRamalingam C  *	the Type of stream mentioned at "HDCP Content Type".
13447672dbbaSRamalingam C  *
1345a09db883SUma Shankar  * HDR_OUTPUT_METADATA:
1346a09db883SUma Shankar  *	Connector property to enable userspace to send HDR Metadata to
1347a09db883SUma Shankar  *	driver. This metadata is based on the composition and blending
1348a09db883SUma Shankar  *	policies decided by user, taking into account the hardware and
1349a09db883SUma Shankar  *	sink capabilities. The driver gets this metadata and creates a
1350a09db883SUma Shankar  *	Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,
1351a09db883SUma Shankar  *	SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then
1352a09db883SUma Shankar  *	sent to sink. This notifies the sink of the upcoming frame's Color
1353a09db883SUma Shankar  *	Encoding and Luminance parameters.
1354a09db883SUma Shankar  *
1355a09db883SUma Shankar  *	Userspace first need to detect the HDR capabilities of sink by
1356a09db883SUma Shankar  *	reading and parsing the EDID. Details of HDR metadata for HDMI
1357a09db883SUma Shankar  *	are added in CTA 861.G spec. For DP , its defined in VESA DP
1358a09db883SUma Shankar  *	Standard v1.4. It needs to then get the metadata information
1359a09db883SUma Shankar  *	of the video/game/app content which are encoded in HDR (basically
1360a09db883SUma Shankar  *	using HDR transfer functions). With this information it needs to
1361a09db883SUma Shankar  *	decide on a blending policy and compose the relevant
1362a09db883SUma Shankar  *	layers/overlays into a common format. Once this blending is done,
1363a09db883SUma Shankar  *	userspace will be aware of the metadata of the composed frame to
1364a09db883SUma Shankar  *	be send to sink. It then uses this property to communicate this
1365a09db883SUma Shankar  *	metadata to driver which then make a Infoframe packet and sends
1366a09db883SUma Shankar  *	to sink based on the type of encoder connected.
1367a09db883SUma Shankar  *
1368a09db883SUma Shankar  *	Userspace will be responsible to do Tone mapping operation in case:
1369a09db883SUma Shankar  *		- Some layers are HDR and others are SDR
1370a09db883SUma Shankar  *		- HDR layers luminance is not same as sink
13719f9b2559SSean Paul  *
1372a09db883SUma Shankar  *	It will even need to do colorspace conversion and get all layers
1373a09db883SUma Shankar  *	to one common colorspace for blending. It can use either GL, Media
137484e543bcSAntonio Borneo  *	or display engine to get this done based on the capabilities of the
1375a09db883SUma Shankar  *	associated hardware.
1376a09db883SUma Shankar  *
1377a09db883SUma Shankar  *	Driver expects metadata to be put in &struct hdr_output_metadata
1378a09db883SUma Shankar  *	structure from userspace. This is received as blob and stored in
1379a09db883SUma Shankar  *	&drm_connector_state.hdr_output_metadata. It parses EDID and saves the
1380a09db883SUma Shankar  *	sink metadata in &struct hdr_sink_metadata, as
1381a09db883SUma Shankar  *	&drm_connector.hdr_sink_metadata.  Driver uses
1382a09db883SUma Shankar  *	drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,
1383a09db883SUma Shankar  *	hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of
1384a09db883SUma Shankar  *	HDMI encoder.
1385a09db883SUma Shankar  *
138647e22ff1SRadhakrishna Sripada  * max bpc:
138747e22ff1SRadhakrishna Sripada  *	This range property is used by userspace to limit the bit depth. When
138847e22ff1SRadhakrishna Sripada  *	used the driver would limit the bpc in accordance with the valid range
138947e22ff1SRadhakrishna Sripada  *	supported by the hardware and sink. Drivers to use the function
139047e22ff1SRadhakrishna Sripada  *	drm_connector_attach_max_bpc_property() to create and attach the
139147e22ff1SRadhakrishna Sripada  *	property to the connector during initialization.
139247e22ff1SRadhakrishna Sripada  *
13934ada6f22SDaniel Vetter  * Connectors also have one standardized atomic property:
13944ada6f22SDaniel Vetter  *
13954ada6f22SDaniel Vetter  * CRTC_ID:
13964ada6f22SDaniel Vetter  * 	Mode object ID of the &drm_crtc this connector should be connected to.
13978d70f395SHans de Goede  *
13988d70f395SHans de Goede  * Connectors for LCD panels may also have one standardized property:
13998d70f395SHans de Goede  *
14008d70f395SHans de Goede  * panel orientation:
14018d70f395SHans de Goede  *	On some devices the LCD panel is mounted in the casing in such a way
14028d70f395SHans de Goede  *	that the up/top side of the panel does not match with the top side of
14038d70f395SHans de Goede  *	the device. Userspace can use this property to check for this.
14048d70f395SHans de Goede  *	Note that input coordinates from touchscreens (input devices with
14058d70f395SHans de Goede  *	INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
14068d70f395SHans de Goede  *	coordinates, so if userspace rotates the picture to adjust for
14078d70f395SHans de Goede  *	the orientation it must also apply the same transformation to the
1408bbeba09fSDaniel Vetter  *	touchscreen input coordinates. This property is initialized by calling
140969654c63SDerek Basehore  *	drm_connector_set_panel_orientation() or
141069654c63SDerek Basehore  *	drm_connector_set_panel_orientation_with_quirk()
1411bbeba09fSDaniel Vetter  *
1412bbeba09fSDaniel Vetter  * scaling mode:
1413bbeba09fSDaniel Vetter  *	This property defines how a non-native mode is upscaled to the native
1414bbeba09fSDaniel Vetter  *	mode of an LCD panel:
1415bbeba09fSDaniel Vetter  *
1416bbeba09fSDaniel Vetter  *	None:
1417bbeba09fSDaniel Vetter  *		No upscaling happens, scaling is left to the panel. Not all
1418bbeba09fSDaniel Vetter  *		drivers expose this mode.
1419bbeba09fSDaniel Vetter  *	Full:
1420bbeba09fSDaniel Vetter  *		The output is upscaled to the full resolution of the panel,
1421bbeba09fSDaniel Vetter  *		ignoring the aspect ratio.
1422bbeba09fSDaniel Vetter  *	Center:
1423bbeba09fSDaniel Vetter  *		No upscaling happens, the output is centered within the native
1424bbeba09fSDaniel Vetter  *		resolution the panel.
1425bbeba09fSDaniel Vetter  *	Full aspect:
1426bbeba09fSDaniel Vetter  *		The output is upscaled to maximize either the width or height
1427bbeba09fSDaniel Vetter  *		while retaining the aspect ratio.
1428bbeba09fSDaniel Vetter  *
1429bbeba09fSDaniel Vetter  *	This property should be set up by calling
1430bbeba09fSDaniel Vetter  *	drm_connector_attach_scaling_mode_property(). Note that drivers
1431bbeba09fSDaniel Vetter  *	can also expose this property to external outputs, in which case they
1432bbeba09fSDaniel Vetter  *	must support "None", which should be the default (since external screens
1433bbeba09fSDaniel Vetter  *	have a built-in scaler).
1434e5b92773SOleg Vasilev  *
1435e5b92773SOleg Vasilev  * subconnector:
1436e5b92773SOleg Vasilev  *	This property is used by DVI-I, TVout and DisplayPort to indicate different
1437e5b92773SOleg Vasilev  *	connector subtypes. Enum values more or less match with those from main
1438e5b92773SOleg Vasilev  *	connector types.
1439e5b92773SOleg Vasilev  *	For DVI-I and TVout there is also a matching property "select subconnector"
1440e5b92773SOleg Vasilev  *	allowing to switch between signal types.
1441e5b92773SOleg Vasilev  *	DP subconnector corresponds to a downstream port.
1442107fe904SRajat Jain  *
1443107fe904SRajat Jain  * privacy-screen sw-state, privacy-screen hw-state:
1444107fe904SRajat Jain  *	These 2 optional properties can be used to query the state of the
1445107fe904SRajat Jain  *	electronic privacy screen that is available on some displays; and in
1446107fe904SRajat Jain  *	some cases also control the state. If a driver implements these
1447107fe904SRajat Jain  *	properties then both properties must be present.
1448107fe904SRajat Jain  *
1449107fe904SRajat Jain  *	"privacy-screen hw-state" is read-only and reflects the actual state
1450107fe904SRajat Jain  *	of the privacy-screen, possible values: "Enabled", "Disabled,
1451107fe904SRajat Jain  *	"Enabled-locked", "Disabled-locked". The locked states indicate
1452107fe904SRajat Jain  *	that the state cannot be changed through the DRM API. E.g. there
1453107fe904SRajat Jain  *	might be devices where the firmware-setup options, or a hardware
1454107fe904SRajat Jain  *	slider-switch, offer always on / off modes.
1455107fe904SRajat Jain  *
1456107fe904SRajat Jain  *	"privacy-screen sw-state" can be set to change the privacy-screen state
1457107fe904SRajat Jain  *	when not locked. In this case the driver must update the hw-state
1458107fe904SRajat Jain  *	property to reflect the new state on completion of the commit of the
1459107fe904SRajat Jain  *	sw-state property. Setting the sw-state property when the hw-state is
1460107fe904SRajat Jain  *	locked must be interpreted by the driver as a request to change the
1461107fe904SRajat Jain  *	state to the set state when the hw-state becomes unlocked. E.g. if
1462107fe904SRajat Jain  *	"privacy-screen hw-state" is "Enabled-locked" and the sw-state
1463107fe904SRajat Jain  *	gets set to "Disabled" followed by the user unlocking the state by
1464107fe904SRajat Jain  *	changing the slider-switch position, then the driver must set the
1465107fe904SRajat Jain  *	state to "Disabled" upon receiving the unlock event.
1466107fe904SRajat Jain  *
1467107fe904SRajat Jain  *	In some cases the privacy-screen's actual state might change outside of
1468107fe904SRajat Jain  *	control of the DRM code. E.g. there might be a firmware handled hotkey
1469107fe904SRajat Jain  *	which toggles the actual state, or the actual state might be changed
1470107fe904SRajat Jain  *	through another userspace API such as writing /proc/acpi/ibm/lcdshadow.
1471107fe904SRajat Jain  *	In this case the driver must update both the hw-state and the sw-state
1472107fe904SRajat Jain  *	to reflect the new value, overwriting any pending state requests in the
1473107fe904SRajat Jain  *	sw-state. Any pending sw-state requests are thus discarded.
1474107fe904SRajat Jain  *
1475107fe904SRajat Jain  *	Note that the ability for the state to change outside of control of
1476107fe904SRajat Jain  *	the DRM master process means that userspace must not cache the value
1477107fe904SRajat Jain  *	of the sw-state. Caching the sw-state value and including it in later
1478107fe904SRajat Jain  *	atomic commits may lead to overriding a state change done through e.g.
1479107fe904SRajat Jain  *	a firmware handled hotkey. Therefor userspace must not include the
1480107fe904SRajat Jain  *	privacy-screen sw-state in an atomic commit unless it wants to change
1481107fe904SRajat Jain  *	its value.
1482409f07d3SSimon Ser  *
1483409f07d3SSimon Ser  * left margin, right margin, top margin, bottom margin:
1484409f07d3SSimon Ser  *	Add margins to the connector's viewport. This is typically used to
14853cf15dc2SSimon Ser  *	mitigate overscan on TVs.
1486409f07d3SSimon Ser  *
1487409f07d3SSimon Ser  *	The value is the size in pixels of the black border which will be
1488409f07d3SSimon Ser  *	added. The attached CRTC's content will be scaled to fill the whole
1489409f07d3SSimon Ser  *	area inside the margin.
1490409f07d3SSimon Ser  *
1491409f07d3SSimon Ser  *	The margins configuration might be sent to the sink, e.g. via HDMI AVI
1492409f07d3SSimon Ser  *	InfoFrames.
1493409f07d3SSimon Ser  *
1494409f07d3SSimon Ser  *	Drivers can set up these properties by calling
1495409f07d3SSimon Ser  *	drm_mode_create_tv_margin_properties().
14964ada6f22SDaniel Vetter  */
14974ada6f22SDaniel Vetter 
149852217195SDaniel Vetter int drm_connector_create_standard_properties(struct drm_device *dev)
149952217195SDaniel Vetter {
150052217195SDaniel Vetter 	struct drm_property *prop;
150152217195SDaniel Vetter 
150252217195SDaniel Vetter 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
150352217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
150452217195SDaniel Vetter 				   "EDID", 0);
150552217195SDaniel Vetter 	if (!prop)
150652217195SDaniel Vetter 		return -ENOMEM;
150752217195SDaniel Vetter 	dev->mode_config.edid_property = prop;
150852217195SDaniel Vetter 
150952217195SDaniel Vetter 	prop = drm_property_create_enum(dev, 0,
151052217195SDaniel Vetter 				   "DPMS", drm_dpms_enum_list,
151152217195SDaniel Vetter 				   ARRAY_SIZE(drm_dpms_enum_list));
151252217195SDaniel Vetter 	if (!prop)
151352217195SDaniel Vetter 		return -ENOMEM;
151452217195SDaniel Vetter 	dev->mode_config.dpms_property = prop;
151552217195SDaniel Vetter 
151652217195SDaniel Vetter 	prop = drm_property_create(dev,
151752217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
151852217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
151952217195SDaniel Vetter 				   "PATH", 0);
152052217195SDaniel Vetter 	if (!prop)
152152217195SDaniel Vetter 		return -ENOMEM;
152252217195SDaniel Vetter 	dev->mode_config.path_property = prop;
152352217195SDaniel Vetter 
152452217195SDaniel Vetter 	prop = drm_property_create(dev,
152552217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
152652217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
152752217195SDaniel Vetter 				   "TILE", 0);
152852217195SDaniel Vetter 	if (!prop)
152952217195SDaniel Vetter 		return -ENOMEM;
153052217195SDaniel Vetter 	dev->mode_config.tile_property = prop;
153152217195SDaniel Vetter 
153240ee6fbeSManasi Navare 	prop = drm_property_create_enum(dev, 0, "link-status",
153340ee6fbeSManasi Navare 					drm_link_status_enum_list,
153440ee6fbeSManasi Navare 					ARRAY_SIZE(drm_link_status_enum_list));
153540ee6fbeSManasi Navare 	if (!prop)
153640ee6fbeSManasi Navare 		return -ENOMEM;
153740ee6fbeSManasi Navare 	dev->mode_config.link_status_property = prop;
153840ee6fbeSManasi Navare 
153966660d4cSDave Airlie 	prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
154066660d4cSDave Airlie 	if (!prop)
154166660d4cSDave Airlie 		return -ENOMEM;
154266660d4cSDave Airlie 	dev->mode_config.non_desktop_property = prop;
154366660d4cSDave Airlie 
1544fbb5d035SUma Shankar 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
1545fbb5d035SUma Shankar 				   "HDR_OUTPUT_METADATA", 0);
1546fbb5d035SUma Shankar 	if (!prop)
1547fbb5d035SUma Shankar 		return -ENOMEM;
1548fbb5d035SUma Shankar 	dev->mode_config.hdr_output_metadata_property = prop;
1549fbb5d035SUma Shankar 
155052217195SDaniel Vetter 	return 0;
155152217195SDaniel Vetter }
155252217195SDaniel Vetter 
155352217195SDaniel Vetter /**
155452217195SDaniel Vetter  * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
155552217195SDaniel Vetter  * @dev: DRM device
155652217195SDaniel Vetter  *
155752217195SDaniel Vetter  * Called by a driver the first time a DVI-I connector is made.
1558f85d9e59SRandy Dunlap  *
1559f85d9e59SRandy Dunlap  * Returns: %0
156052217195SDaniel Vetter  */
156152217195SDaniel Vetter int drm_mode_create_dvi_i_properties(struct drm_device *dev)
156252217195SDaniel Vetter {
156352217195SDaniel Vetter 	struct drm_property *dvi_i_selector;
156452217195SDaniel Vetter 	struct drm_property *dvi_i_subconnector;
156552217195SDaniel Vetter 
156652217195SDaniel Vetter 	if (dev->mode_config.dvi_i_select_subconnector_property)
156752217195SDaniel Vetter 		return 0;
156852217195SDaniel Vetter 
156952217195SDaniel Vetter 	dvi_i_selector =
157052217195SDaniel Vetter 		drm_property_create_enum(dev, 0,
157152217195SDaniel Vetter 				    "select subconnector",
157252217195SDaniel Vetter 				    drm_dvi_i_select_enum_list,
157352217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_select_enum_list));
157452217195SDaniel Vetter 	dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
157552217195SDaniel Vetter 
157652217195SDaniel Vetter 	dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
157752217195SDaniel Vetter 				    "subconnector",
157852217195SDaniel Vetter 				    drm_dvi_i_subconnector_enum_list,
157952217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
158052217195SDaniel Vetter 	dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
158152217195SDaniel Vetter 
158252217195SDaniel Vetter 	return 0;
158352217195SDaniel Vetter }
158452217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
158552217195SDaniel Vetter 
158652217195SDaniel Vetter /**
1587e5b92773SOleg Vasilev  * drm_connector_attach_dp_subconnector_property - create subconnector property for DP
1588e5b92773SOleg Vasilev  * @connector: drm_connector to attach property
1589e5b92773SOleg Vasilev  *
1590e5b92773SOleg Vasilev  * Called by a driver when DP connector is created.
1591e5b92773SOleg Vasilev  */
1592e5b92773SOleg Vasilev void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector)
1593e5b92773SOleg Vasilev {
1594e5b92773SOleg Vasilev 	struct drm_mode_config *mode_config = &connector->dev->mode_config;
1595e5b92773SOleg Vasilev 
1596e5b92773SOleg Vasilev 	if (!mode_config->dp_subconnector_property)
1597e5b92773SOleg Vasilev 		mode_config->dp_subconnector_property =
1598e5b92773SOleg Vasilev 			drm_property_create_enum(connector->dev,
1599e5b92773SOleg Vasilev 				DRM_MODE_PROP_IMMUTABLE,
1600e5b92773SOleg Vasilev 				"subconnector",
1601e5b92773SOleg Vasilev 				drm_dp_subconnector_enum_list,
1602e5b92773SOleg Vasilev 				ARRAY_SIZE(drm_dp_subconnector_enum_list));
1603e5b92773SOleg Vasilev 
1604e5b92773SOleg Vasilev 	drm_object_attach_property(&connector->base,
1605e5b92773SOleg Vasilev 				   mode_config->dp_subconnector_property,
1606e5b92773SOleg Vasilev 				   DRM_MODE_SUBCONNECTOR_Unknown);
1607e5b92773SOleg Vasilev }
1608e5b92773SOleg Vasilev EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property);
1609e5b92773SOleg Vasilev 
1610e5b92773SOleg Vasilev /**
161150525c33SStanislav Lisovskiy  * DOC: HDMI connector properties
161250525c33SStanislav Lisovskiy  *
161350525c33SStanislav Lisovskiy  * content type (HDMI specific):
161450525c33SStanislav Lisovskiy  *	Indicates content type setting to be used in HDMI infoframes to indicate
16151e55a53aSMatt Roper  *	content type for the external device, so that it adjusts its display
161650525c33SStanislav Lisovskiy  *	settings accordingly.
161750525c33SStanislav Lisovskiy  *
161850525c33SStanislav Lisovskiy  *	The value of this property can be one of the following:
161950525c33SStanislav Lisovskiy  *
162050525c33SStanislav Lisovskiy  *	No Data:
162150525c33SStanislav Lisovskiy  *		Content type is unknown
162250525c33SStanislav Lisovskiy  *	Graphics:
162350525c33SStanislav Lisovskiy  *		Content type is graphics
162450525c33SStanislav Lisovskiy  *	Photo:
162550525c33SStanislav Lisovskiy  *		Content type is photo
162650525c33SStanislav Lisovskiy  *	Cinema:
162750525c33SStanislav Lisovskiy  *		Content type is cinema
162850525c33SStanislav Lisovskiy  *	Game:
162950525c33SStanislav Lisovskiy  *		Content type is game
163050525c33SStanislav Lisovskiy  *
1631a0a33067SSimon Ser  *	The meaning of each content type is defined in CTA-861-G table 15.
1632a0a33067SSimon Ser  *
163350525c33SStanislav Lisovskiy  *	Drivers can set up this property by calling
163450525c33SStanislav Lisovskiy  *	drm_connector_attach_content_type_property(). Decoding to
1635ba609631SDaniel Vetter  *	infoframe values is done through drm_hdmi_avi_infoframe_content_type().
163650525c33SStanislav Lisovskiy  */
163750525c33SStanislav Lisovskiy 
16387d63cd85SMaxime Ripard /*
16397d63cd85SMaxime Ripard  * TODO: Document the properties:
16407d63cd85SMaxime Ripard  *   - brightness
16417d63cd85SMaxime Ripard  *   - contrast
16427d63cd85SMaxime Ripard  *   - flicker reduction
16437d63cd85SMaxime Ripard  *   - hue
16447d63cd85SMaxime Ripard  *   - mode
16457d63cd85SMaxime Ripard  *   - overscan
16467d63cd85SMaxime Ripard  *   - saturation
16477d63cd85SMaxime Ripard  *   - select subconnector
16487d63cd85SMaxime Ripard  */
16497d63cd85SMaxime Ripard /**
16507d63cd85SMaxime Ripard  * DOC: Analog TV Connector Properties
16517d63cd85SMaxime Ripard  *
16527d63cd85SMaxime Ripard  * TV Mode:
16537d63cd85SMaxime Ripard  *	Indicates the TV Mode used on an analog TV connector. The value
16547d63cd85SMaxime Ripard  *	of this property can be one of the following:
16557d63cd85SMaxime Ripard  *
16567d63cd85SMaxime Ripard  *	NTSC:
16577d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
16587d63cd85SMaxime Ripard  *		the NTSC Color Encoding.
16597d63cd85SMaxime Ripard  *
16607d63cd85SMaxime Ripard  *	NTSC-443:
16617d63cd85SMaxime Ripard  *
16627d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
16637d63cd85SMaxime Ripard  *		the NTSC Color Encoding, but with a color subcarrier
16647d63cd85SMaxime Ripard  *		frequency of 4.43MHz
16657d63cd85SMaxime Ripard  *
16667d63cd85SMaxime Ripard  *	NTSC-J:
16677d63cd85SMaxime Ripard  *
16687d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
16697d63cd85SMaxime Ripard  *		the NTSC Color Encoding, but with a black level equal to
16707d63cd85SMaxime Ripard  *		the blanking level.
16717d63cd85SMaxime Ripard  *
16727d63cd85SMaxime Ripard  *	PAL:
16737d63cd85SMaxime Ripard  *
16747d63cd85SMaxime Ripard  *		TV Mode is CCIR System B (aka 625-lines) together with
16757d63cd85SMaxime Ripard  *		the PAL Color Encoding.
16767d63cd85SMaxime Ripard  *
16777d63cd85SMaxime Ripard  *	PAL-M:
16787d63cd85SMaxime Ripard  *
16797d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
16807d63cd85SMaxime Ripard  *		the PAL Color Encoding.
16817d63cd85SMaxime Ripard  *
16827d63cd85SMaxime Ripard  *	PAL-N:
16837d63cd85SMaxime Ripard  *
16847d63cd85SMaxime Ripard  *		TV Mode is CCIR System N together with the PAL Color
16857d63cd85SMaxime Ripard  *		Encoding, a color subcarrier frequency of 3.58MHz, the
16867d63cd85SMaxime Ripard  *		SECAM color space, and narrower channels than other PAL
16877d63cd85SMaxime Ripard  *		variants.
16887d63cd85SMaxime Ripard  *
16897d63cd85SMaxime Ripard  *	SECAM:
16907d63cd85SMaxime Ripard  *
16917d63cd85SMaxime Ripard  *		TV Mode is CCIR System B (aka 625-lines) together with
16927d63cd85SMaxime Ripard  *		the SECAM Color Encoding.
16937d63cd85SMaxime Ripard  *
16947d63cd85SMaxime Ripard  *	Drivers can set up this property by calling
16957d63cd85SMaxime Ripard  *	drm_mode_create_tv_properties().
16967d63cd85SMaxime Ripard  */
16977d63cd85SMaxime Ripard 
169850525c33SStanislav Lisovskiy /**
169950525c33SStanislav Lisovskiy  * drm_connector_attach_content_type_property - attach content-type property
170050525c33SStanislav Lisovskiy  * @connector: connector to attach content type property on.
170150525c33SStanislav Lisovskiy  *
170250525c33SStanislav Lisovskiy  * Called by a driver the first time a HDMI connector is made.
1703f85d9e59SRandy Dunlap  *
1704f85d9e59SRandy Dunlap  * Returns: %0
170550525c33SStanislav Lisovskiy  */
170650525c33SStanislav Lisovskiy int drm_connector_attach_content_type_property(struct drm_connector *connector)
170750525c33SStanislav Lisovskiy {
170850525c33SStanislav Lisovskiy 	if (!drm_mode_create_content_type_property(connector->dev))
170950525c33SStanislav Lisovskiy 		drm_object_attach_property(&connector->base,
171050525c33SStanislav Lisovskiy 					   connector->dev->mode_config.content_type_property,
171150525c33SStanislav Lisovskiy 					   DRM_MODE_CONTENT_TYPE_NO_DATA);
171250525c33SStanislav Lisovskiy 	return 0;
171350525c33SStanislav Lisovskiy }
171450525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_connector_attach_content_type_property);
171550525c33SStanislav Lisovskiy 
171650525c33SStanislav Lisovskiy /**
1717e9d2871fSMauro Carvalho Chehab  * drm_connector_attach_tv_margin_properties - attach TV connector margin
1718e9d2871fSMauro Carvalho Chehab  * 	properties
17196c4f52dcSBoris Brezillon  * @connector: DRM connector
17206c4f52dcSBoris Brezillon  *
17216c4f52dcSBoris Brezillon  * Called by a driver when it needs to attach TV margin props to a connector.
17226c4f52dcSBoris Brezillon  * Typically used on SDTV and HDMI connectors.
17236c4f52dcSBoris Brezillon  */
17246c4f52dcSBoris Brezillon void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
17256c4f52dcSBoris Brezillon {
17266c4f52dcSBoris Brezillon 	struct drm_device *dev = connector->dev;
17276c4f52dcSBoris Brezillon 
17286c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
17296c4f52dcSBoris Brezillon 				   dev->mode_config.tv_left_margin_property,
17306c4f52dcSBoris Brezillon 				   0);
17316c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
17326c4f52dcSBoris Brezillon 				   dev->mode_config.tv_right_margin_property,
17336c4f52dcSBoris Brezillon 				   0);
17346c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
17356c4f52dcSBoris Brezillon 				   dev->mode_config.tv_top_margin_property,
17366c4f52dcSBoris Brezillon 				   0);
17376c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
17386c4f52dcSBoris Brezillon 				   dev->mode_config.tv_bottom_margin_property,
17396c4f52dcSBoris Brezillon 				   0);
17406c4f52dcSBoris Brezillon }
17416c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
17426c4f52dcSBoris Brezillon 
17436c4f52dcSBoris Brezillon /**
17446c4f52dcSBoris Brezillon  * drm_mode_create_tv_margin_properties - create TV connector margin properties
17456c4f52dcSBoris Brezillon  * @dev: DRM device
17466c4f52dcSBoris Brezillon  *
17476c4f52dcSBoris Brezillon  * Called by a driver's HDMI connector initialization routine, this function
17486c4f52dcSBoris Brezillon  * creates the TV margin properties for a given device. No need to call this
17496c4f52dcSBoris Brezillon  * function for an SDTV connector, it's already called from
175080ed86d4SMaxime Ripard  * drm_mode_create_tv_properties_legacy().
1751f85d9e59SRandy Dunlap  *
1752f85d9e59SRandy Dunlap  * Returns:
1753f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
17546c4f52dcSBoris Brezillon  */
17556c4f52dcSBoris Brezillon int drm_mode_create_tv_margin_properties(struct drm_device *dev)
17566c4f52dcSBoris Brezillon {
17576c4f52dcSBoris Brezillon 	if (dev->mode_config.tv_left_margin_property)
17586c4f52dcSBoris Brezillon 		return 0;
17596c4f52dcSBoris Brezillon 
17606c4f52dcSBoris Brezillon 	dev->mode_config.tv_left_margin_property =
17616c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "left margin", 0, 100);
17626c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_left_margin_property)
17636c4f52dcSBoris Brezillon 		return -ENOMEM;
17646c4f52dcSBoris Brezillon 
17656c4f52dcSBoris Brezillon 	dev->mode_config.tv_right_margin_property =
17666c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "right margin", 0, 100);
17676c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_right_margin_property)
17686c4f52dcSBoris Brezillon 		return -ENOMEM;
17696c4f52dcSBoris Brezillon 
17706c4f52dcSBoris Brezillon 	dev->mode_config.tv_top_margin_property =
17716c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "top margin", 0, 100);
17726c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_top_margin_property)
17736c4f52dcSBoris Brezillon 		return -ENOMEM;
17746c4f52dcSBoris Brezillon 
17756c4f52dcSBoris Brezillon 	dev->mode_config.tv_bottom_margin_property =
17766c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "bottom margin", 0, 100);
17776c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_bottom_margin_property)
17786c4f52dcSBoris Brezillon 		return -ENOMEM;
17796c4f52dcSBoris Brezillon 
17806c4f52dcSBoris Brezillon 	return 0;
17816c4f52dcSBoris Brezillon }
17826c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
17836c4f52dcSBoris Brezillon 
17846c4f52dcSBoris Brezillon /**
178580ed86d4SMaxime Ripard  * drm_mode_create_tv_properties_legacy - create TV specific connector properties
178652217195SDaniel Vetter  * @dev: DRM device
178752217195SDaniel Vetter  * @num_modes: number of different TV formats (modes) supported
178852217195SDaniel Vetter  * @modes: array of pointers to strings containing name of each format
178952217195SDaniel Vetter  *
179052217195SDaniel Vetter  * Called by a driver's TV initialization routine, this function creates
179152217195SDaniel Vetter  * the TV specific connector properties for a given device.  Caller is
179252217195SDaniel Vetter  * responsible for allocating a list of format names and passing them to
179352217195SDaniel Vetter  * this routine.
1794f85d9e59SRandy Dunlap  *
17957d63cd85SMaxime Ripard  * NOTE: This functions registers the deprecated "mode" connector
17967d63cd85SMaxime Ripard  * property to select the analog TV mode (ie, NTSC, PAL, etc.). New
17977d63cd85SMaxime Ripard  * drivers must use drm_mode_create_tv_properties() instead.
17987d63cd85SMaxime Ripard  *
1799f85d9e59SRandy Dunlap  * Returns:
1800f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
180152217195SDaniel Vetter  */
180280ed86d4SMaxime Ripard int drm_mode_create_tv_properties_legacy(struct drm_device *dev,
180352217195SDaniel Vetter 					 unsigned int num_modes,
180452217195SDaniel Vetter 					 const char * const modes[])
180552217195SDaniel Vetter {
180652217195SDaniel Vetter 	struct drm_property *tv_selector;
180752217195SDaniel Vetter 	struct drm_property *tv_subconnector;
180852217195SDaniel Vetter 	unsigned int i;
180952217195SDaniel Vetter 
181052217195SDaniel Vetter 	if (dev->mode_config.tv_select_subconnector_property)
181152217195SDaniel Vetter 		return 0;
181252217195SDaniel Vetter 
181352217195SDaniel Vetter 	/*
181452217195SDaniel Vetter 	 * Basic connector properties
181552217195SDaniel Vetter 	 */
181652217195SDaniel Vetter 	tv_selector = drm_property_create_enum(dev, 0,
181752217195SDaniel Vetter 					  "select subconnector",
181852217195SDaniel Vetter 					  drm_tv_select_enum_list,
181952217195SDaniel Vetter 					  ARRAY_SIZE(drm_tv_select_enum_list));
182052217195SDaniel Vetter 	if (!tv_selector)
182152217195SDaniel Vetter 		goto nomem;
182252217195SDaniel Vetter 
182352217195SDaniel Vetter 	dev->mode_config.tv_select_subconnector_property = tv_selector;
182452217195SDaniel Vetter 
182552217195SDaniel Vetter 	tv_subconnector =
182652217195SDaniel Vetter 		drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
182752217195SDaniel Vetter 				    "subconnector",
182852217195SDaniel Vetter 				    drm_tv_subconnector_enum_list,
182952217195SDaniel Vetter 				    ARRAY_SIZE(drm_tv_subconnector_enum_list));
183052217195SDaniel Vetter 	if (!tv_subconnector)
183152217195SDaniel Vetter 		goto nomem;
183252217195SDaniel Vetter 	dev->mode_config.tv_subconnector_property = tv_subconnector;
183352217195SDaniel Vetter 
183452217195SDaniel Vetter 	/*
183552217195SDaniel Vetter 	 * Other, TV specific properties: margins & TV modes.
183652217195SDaniel Vetter 	 */
18376c4f52dcSBoris Brezillon 	if (drm_mode_create_tv_margin_properties(dev))
183852217195SDaniel Vetter 		goto nomem;
183952217195SDaniel Vetter 
1840aab5aaa7SMaxime Ripard 	if (num_modes) {
18411fd4a5a3SMaxime Ripard 		dev->mode_config.legacy_tv_mode_property =
184252217195SDaniel Vetter 			drm_property_create(dev, DRM_MODE_PROP_ENUM,
184352217195SDaniel Vetter 					    "mode", num_modes);
18441fd4a5a3SMaxime Ripard 		if (!dev->mode_config.legacy_tv_mode_property)
184552217195SDaniel Vetter 			goto nomem;
184652217195SDaniel Vetter 
184752217195SDaniel Vetter 		for (i = 0; i < num_modes; i++)
18481fd4a5a3SMaxime Ripard 			drm_property_add_enum(dev->mode_config.legacy_tv_mode_property,
184952217195SDaniel Vetter 					      i, modes[i]);
1850aab5aaa7SMaxime Ripard 	}
185152217195SDaniel Vetter 
185252217195SDaniel Vetter 	dev->mode_config.tv_brightness_property =
185352217195SDaniel Vetter 		drm_property_create_range(dev, 0, "brightness", 0, 100);
185452217195SDaniel Vetter 	if (!dev->mode_config.tv_brightness_property)
185552217195SDaniel Vetter 		goto nomem;
185652217195SDaniel Vetter 
185752217195SDaniel Vetter 	dev->mode_config.tv_contrast_property =
185852217195SDaniel Vetter 		drm_property_create_range(dev, 0, "contrast", 0, 100);
185952217195SDaniel Vetter 	if (!dev->mode_config.tv_contrast_property)
186052217195SDaniel Vetter 		goto nomem;
186152217195SDaniel Vetter 
186252217195SDaniel Vetter 	dev->mode_config.tv_flicker_reduction_property =
186352217195SDaniel Vetter 		drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
186452217195SDaniel Vetter 	if (!dev->mode_config.tv_flicker_reduction_property)
186552217195SDaniel Vetter 		goto nomem;
186652217195SDaniel Vetter 
186752217195SDaniel Vetter 	dev->mode_config.tv_overscan_property =
186852217195SDaniel Vetter 		drm_property_create_range(dev, 0, "overscan", 0, 100);
186952217195SDaniel Vetter 	if (!dev->mode_config.tv_overscan_property)
187052217195SDaniel Vetter 		goto nomem;
187152217195SDaniel Vetter 
187252217195SDaniel Vetter 	dev->mode_config.tv_saturation_property =
187352217195SDaniel Vetter 		drm_property_create_range(dev, 0, "saturation", 0, 100);
187452217195SDaniel Vetter 	if (!dev->mode_config.tv_saturation_property)
187552217195SDaniel Vetter 		goto nomem;
187652217195SDaniel Vetter 
187752217195SDaniel Vetter 	dev->mode_config.tv_hue_property =
187852217195SDaniel Vetter 		drm_property_create_range(dev, 0, "hue", 0, 100);
187952217195SDaniel Vetter 	if (!dev->mode_config.tv_hue_property)
188052217195SDaniel Vetter 		goto nomem;
188152217195SDaniel Vetter 
188252217195SDaniel Vetter 	return 0;
188352217195SDaniel Vetter nomem:
188452217195SDaniel Vetter 	return -ENOMEM;
188552217195SDaniel Vetter }
188680ed86d4SMaxime Ripard EXPORT_SYMBOL(drm_mode_create_tv_properties_legacy);
188752217195SDaniel Vetter 
188852217195SDaniel Vetter /**
18897d63cd85SMaxime Ripard  * drm_mode_create_tv_properties - create TV specific connector properties
18907d63cd85SMaxime Ripard  * @dev: DRM device
18917d63cd85SMaxime Ripard  * @supported_tv_modes: Bitmask of TV modes supported (See DRM_MODE_TV_MODE_*)
189204ee2767SRandy Dunlap  *
18937d63cd85SMaxime Ripard  * Called by a driver's TV initialization routine, this function creates
18947d63cd85SMaxime Ripard  * the TV specific connector properties for a given device.
18957d63cd85SMaxime Ripard  *
18967d63cd85SMaxime Ripard  * Returns:
18977d63cd85SMaxime Ripard  * 0 on success or a negative error code on failure.
18987d63cd85SMaxime Ripard  */
18997d63cd85SMaxime Ripard int drm_mode_create_tv_properties(struct drm_device *dev,
19007d63cd85SMaxime Ripard 				  unsigned int supported_tv_modes)
19017d63cd85SMaxime Ripard {
19027d63cd85SMaxime Ripard 	struct drm_prop_enum_list tv_mode_list[DRM_MODE_TV_MODE_MAX];
19037d63cd85SMaxime Ripard 	struct drm_property *tv_mode;
19047d63cd85SMaxime Ripard 	unsigned int i, len = 0;
19057d63cd85SMaxime Ripard 
19067d63cd85SMaxime Ripard 	if (dev->mode_config.tv_mode_property)
19077d63cd85SMaxime Ripard 		return 0;
19087d63cd85SMaxime Ripard 
19097d63cd85SMaxime Ripard 	for (i = 0; i < DRM_MODE_TV_MODE_MAX; i++) {
19107d63cd85SMaxime Ripard 		if (!(supported_tv_modes & BIT(i)))
19117d63cd85SMaxime Ripard 			continue;
19127d63cd85SMaxime Ripard 
19137d63cd85SMaxime Ripard 		tv_mode_list[len].type = i;
19147d63cd85SMaxime Ripard 		tv_mode_list[len].name = drm_get_tv_mode_name(i);
19157d63cd85SMaxime Ripard 		len++;
19167d63cd85SMaxime Ripard 	}
19177d63cd85SMaxime Ripard 
19187d63cd85SMaxime Ripard 	tv_mode = drm_property_create_enum(dev, 0, "TV mode",
19197d63cd85SMaxime Ripard 					   tv_mode_list, len);
19207d63cd85SMaxime Ripard 	if (!tv_mode)
19217d63cd85SMaxime Ripard 		return -ENOMEM;
19227d63cd85SMaxime Ripard 
19237d63cd85SMaxime Ripard 	dev->mode_config.tv_mode_property = tv_mode;
19247d63cd85SMaxime Ripard 
19257d63cd85SMaxime Ripard 	return drm_mode_create_tv_properties_legacy(dev, 0, NULL);
19267d63cd85SMaxime Ripard }
19277d63cd85SMaxime Ripard EXPORT_SYMBOL(drm_mode_create_tv_properties);
19287d63cd85SMaxime Ripard 
19297d63cd85SMaxime Ripard /**
193052217195SDaniel Vetter  * drm_mode_create_scaling_mode_property - create scaling mode property
193152217195SDaniel Vetter  * @dev: DRM device
193252217195SDaniel Vetter  *
193352217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
193452217195SDaniel Vetter  * connectors.
19358f6e1e22SMaarten Lankhorst  *
19368f6e1e22SMaarten Lankhorst  * Atomic drivers should use drm_connector_attach_scaling_mode_property()
19379c2fce13SVille Syrjälä  * instead to correctly assign &drm_connector_state.scaling_mode
19388f6e1e22SMaarten Lankhorst  * in the atomic state.
1939f85d9e59SRandy Dunlap  *
1940f85d9e59SRandy Dunlap  * Returns: %0
194152217195SDaniel Vetter  */
194252217195SDaniel Vetter int drm_mode_create_scaling_mode_property(struct drm_device *dev)
194352217195SDaniel Vetter {
194452217195SDaniel Vetter 	struct drm_property *scaling_mode;
194552217195SDaniel Vetter 
194652217195SDaniel Vetter 	if (dev->mode_config.scaling_mode_property)
194752217195SDaniel Vetter 		return 0;
194852217195SDaniel Vetter 
194952217195SDaniel Vetter 	scaling_mode =
195052217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "scaling mode",
195152217195SDaniel Vetter 				drm_scaling_mode_enum_list,
195252217195SDaniel Vetter 				    ARRAY_SIZE(drm_scaling_mode_enum_list));
195352217195SDaniel Vetter 
195452217195SDaniel Vetter 	dev->mode_config.scaling_mode_property = scaling_mode;
195552217195SDaniel Vetter 
195652217195SDaniel Vetter 	return 0;
195752217195SDaniel Vetter }
195852217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
195952217195SDaniel Vetter 
196052217195SDaniel Vetter /**
1961ab7a664fSNicholas Kazlauskas  * DOC: Variable refresh properties
1962ab7a664fSNicholas Kazlauskas  *
1963ab7a664fSNicholas Kazlauskas  * Variable refresh rate capable displays can dynamically adjust their
1964ab7a664fSNicholas Kazlauskas  * refresh rate by extending the duration of their vertical front porch
1965ab7a664fSNicholas Kazlauskas  * until page flip or timeout occurs. This can reduce or remove stuttering
1966ab7a664fSNicholas Kazlauskas  * and latency in scenarios where the page flip does not align with the
1967ab7a664fSNicholas Kazlauskas  * vblank interval.
1968ab7a664fSNicholas Kazlauskas  *
1969ab7a664fSNicholas Kazlauskas  * An example scenario would be an application flipping at a constant rate
1970ab7a664fSNicholas Kazlauskas  * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
1971ab7a664fSNicholas Kazlauskas  * interval and the same contents will be displayed twice. This can be
1972ab7a664fSNicholas Kazlauskas  * observed as stuttering for content with motion.
1973ab7a664fSNicholas Kazlauskas  *
1974ab7a664fSNicholas Kazlauskas  * If variable refresh rate was active on a display that supported a
1975ab7a664fSNicholas Kazlauskas  * variable refresh range from 35Hz to 60Hz no stuttering would be observable
1976ab7a664fSNicholas Kazlauskas  * for the example scenario. The minimum supported variable refresh rate of
1977ab7a664fSNicholas Kazlauskas  * 35Hz is below the page flip frequency and the vertical front porch can
1978ab7a664fSNicholas Kazlauskas  * be extended until the page flip occurs. The vblank interval will be
1979ab7a664fSNicholas Kazlauskas  * directly aligned to the page flip rate.
1980ab7a664fSNicholas Kazlauskas  *
1981ab7a664fSNicholas Kazlauskas  * Not all userspace content is suitable for use with variable refresh rate.
1982ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may worsen
1983ab7a664fSNicholas Kazlauskas  * perceived stuttering for input sensitive applications.
1984ab7a664fSNicholas Kazlauskas  *
1985ab7a664fSNicholas Kazlauskas  * Panel brightness will also vary with vertical front porch duration. Some
1986ab7a664fSNicholas Kazlauskas  * panels may have noticeable differences in brightness between the minimum
1987ab7a664fSNicholas Kazlauskas  * vertical front porch duration and the maximum vertical front porch duration.
1988ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may produce
1989ab7a664fSNicholas Kazlauskas  * observable flickering for such panels.
1990ab7a664fSNicholas Kazlauskas  *
1991ab7a664fSNicholas Kazlauskas  * Userspace control for variable refresh rate is supported via properties
1992ab7a664fSNicholas Kazlauskas  * on the &drm_connector and &drm_crtc objects.
1993ab7a664fSNicholas Kazlauskas  *
1994ab7a664fSNicholas Kazlauskas  * "vrr_capable":
1995ab7a664fSNicholas Kazlauskas  *	Optional &drm_connector boolean property that drivers should attach
1996ab7a664fSNicholas Kazlauskas  *	with drm_connector_attach_vrr_capable_property() on connectors that
1997ab7a664fSNicholas Kazlauskas  *	could support variable refresh rates. Drivers should update the
1998ab7a664fSNicholas Kazlauskas  *	property value by calling drm_connector_set_vrr_capable_property().
1999ab7a664fSNicholas Kazlauskas  *
2000ab7a664fSNicholas Kazlauskas  *	Absence of the property should indicate absence of support.
2001ab7a664fSNicholas Kazlauskas  *
200277086014SDaniel Vetter  * "VRR_ENABLED":
2003ab7a664fSNicholas Kazlauskas  *	Default &drm_crtc boolean property that notifies the driver that the
2004ab7a664fSNicholas Kazlauskas  *	content on the CRTC is suitable for variable refresh rate presentation.
2005ab7a664fSNicholas Kazlauskas  *	The driver will take this property as a hint to enable variable
2006ab7a664fSNicholas Kazlauskas  *	refresh rate support if the receiver supports it, ie. if the
2007ab7a664fSNicholas Kazlauskas  *	"vrr_capable" property is true on the &drm_connector object. The
2008ab7a664fSNicholas Kazlauskas  *	vertical front porch duration will be extended until page-flip or
2009ab7a664fSNicholas Kazlauskas  *	timeout when enabled.
2010ab7a664fSNicholas Kazlauskas  *
2011ab7a664fSNicholas Kazlauskas  *	The minimum vertical front porch duration is defined as the vertical
2012ab7a664fSNicholas Kazlauskas  *	front porch duration for the current mode.
2013ab7a664fSNicholas Kazlauskas  *
2014ab7a664fSNicholas Kazlauskas  *	The maximum vertical front porch duration is greater than or equal to
2015ab7a664fSNicholas Kazlauskas  *	the minimum vertical front porch duration. The duration is derived
2016ab7a664fSNicholas Kazlauskas  *	from the minimum supported variable refresh rate for the connector.
2017ab7a664fSNicholas Kazlauskas  *
2018ab7a664fSNicholas Kazlauskas  *	The driver may place further restrictions within these minimum
2019ab7a664fSNicholas Kazlauskas  *	and maximum bounds.
2020ab7a664fSNicholas Kazlauskas  */
2021ab7a664fSNicholas Kazlauskas 
2022ab7a664fSNicholas Kazlauskas /**
2023ba1b0f6cSNicholas Kazlauskas  * drm_connector_attach_vrr_capable_property - creates the
2024ba1b0f6cSNicholas Kazlauskas  * vrr_capable property
2025ba1b0f6cSNicholas Kazlauskas  * @connector: connector to create the vrr_capable property on.
2026ba1b0f6cSNicholas Kazlauskas  *
2027ba1b0f6cSNicholas Kazlauskas  * This is used by atomic drivers to add support for querying
2028ba1b0f6cSNicholas Kazlauskas  * variable refresh rate capability for a connector.
2029ba1b0f6cSNicholas Kazlauskas  *
2030ba1b0f6cSNicholas Kazlauskas  * Returns:
203184e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
2032ba1b0f6cSNicholas Kazlauskas  */
2033ba1b0f6cSNicholas Kazlauskas int drm_connector_attach_vrr_capable_property(
2034ba1b0f6cSNicholas Kazlauskas 	struct drm_connector *connector)
2035ba1b0f6cSNicholas Kazlauskas {
2036ba1b0f6cSNicholas Kazlauskas 	struct drm_device *dev = connector->dev;
2037ba1b0f6cSNicholas Kazlauskas 	struct drm_property *prop;
2038ba1b0f6cSNicholas Kazlauskas 
2039ba1b0f6cSNicholas Kazlauskas 	if (!connector->vrr_capable_property) {
2040ba1b0f6cSNicholas Kazlauskas 		prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
2041ba1b0f6cSNicholas Kazlauskas 			"vrr_capable");
2042ba1b0f6cSNicholas Kazlauskas 		if (!prop)
2043ba1b0f6cSNicholas Kazlauskas 			return -ENOMEM;
2044ba1b0f6cSNicholas Kazlauskas 
2045ba1b0f6cSNicholas Kazlauskas 		connector->vrr_capable_property = prop;
2046ba1b0f6cSNicholas Kazlauskas 		drm_object_attach_property(&connector->base, prop, 0);
2047ba1b0f6cSNicholas Kazlauskas 	}
2048ba1b0f6cSNicholas Kazlauskas 
2049ba1b0f6cSNicholas Kazlauskas 	return 0;
2050ba1b0f6cSNicholas Kazlauskas }
2051ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
2052ba1b0f6cSNicholas Kazlauskas 
2053ba1b0f6cSNicholas Kazlauskas /**
20548f6e1e22SMaarten Lankhorst  * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
20558f6e1e22SMaarten Lankhorst  * @connector: connector to attach scaling mode property on.
20568f6e1e22SMaarten Lankhorst  * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
20578f6e1e22SMaarten Lankhorst  *
20588f6e1e22SMaarten Lankhorst  * This is used to add support for scaling mode to atomic drivers.
20599c2fce13SVille Syrjälä  * The scaling mode will be set to &drm_connector_state.scaling_mode
20608f6e1e22SMaarten Lankhorst  * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
20618f6e1e22SMaarten Lankhorst  *
20628f6e1e22SMaarten Lankhorst  * This is the atomic version of drm_mode_create_scaling_mode_property().
20638f6e1e22SMaarten Lankhorst  *
20648f6e1e22SMaarten Lankhorst  * Returns:
20658f6e1e22SMaarten Lankhorst  * Zero on success, negative errno on failure.
20668f6e1e22SMaarten Lankhorst  */
20678f6e1e22SMaarten Lankhorst int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
20688f6e1e22SMaarten Lankhorst 					       u32 scaling_mode_mask)
20698f6e1e22SMaarten Lankhorst {
20708f6e1e22SMaarten Lankhorst 	struct drm_device *dev = connector->dev;
20718f6e1e22SMaarten Lankhorst 	struct drm_property *scaling_mode_property;
207230e9db6dSVille Syrjälä 	int i;
20738f6e1e22SMaarten Lankhorst 	const unsigned valid_scaling_mode_mask =
20748f6e1e22SMaarten Lankhorst 		(1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
20758f6e1e22SMaarten Lankhorst 
20768f6e1e22SMaarten Lankhorst 	if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
20778f6e1e22SMaarten Lankhorst 		    scaling_mode_mask & ~valid_scaling_mode_mask))
20788f6e1e22SMaarten Lankhorst 		return -EINVAL;
20798f6e1e22SMaarten Lankhorst 
20808f6e1e22SMaarten Lankhorst 	scaling_mode_property =
20818f6e1e22SMaarten Lankhorst 		drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
20828f6e1e22SMaarten Lankhorst 				    hweight32(scaling_mode_mask));
20838f6e1e22SMaarten Lankhorst 
20848f6e1e22SMaarten Lankhorst 	if (!scaling_mode_property)
20858f6e1e22SMaarten Lankhorst 		return -ENOMEM;
20868f6e1e22SMaarten Lankhorst 
20878f6e1e22SMaarten Lankhorst 	for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
20888f6e1e22SMaarten Lankhorst 		int ret;
20898f6e1e22SMaarten Lankhorst 
20908f6e1e22SMaarten Lankhorst 		if (!(BIT(i) & scaling_mode_mask))
20918f6e1e22SMaarten Lankhorst 			continue;
20928f6e1e22SMaarten Lankhorst 
209330e9db6dSVille Syrjälä 		ret = drm_property_add_enum(scaling_mode_property,
20948f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].type,
20958f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].name);
20968f6e1e22SMaarten Lankhorst 
20978f6e1e22SMaarten Lankhorst 		if (ret) {
20988f6e1e22SMaarten Lankhorst 			drm_property_destroy(dev, scaling_mode_property);
20998f6e1e22SMaarten Lankhorst 
21008f6e1e22SMaarten Lankhorst 			return ret;
21018f6e1e22SMaarten Lankhorst 		}
21028f6e1e22SMaarten Lankhorst 	}
21038f6e1e22SMaarten Lankhorst 
21048f6e1e22SMaarten Lankhorst 	drm_object_attach_property(&connector->base,
21058f6e1e22SMaarten Lankhorst 				   scaling_mode_property, 0);
21068f6e1e22SMaarten Lankhorst 
21078f6e1e22SMaarten Lankhorst 	connector->scaling_mode_property = scaling_mode_property;
21088f6e1e22SMaarten Lankhorst 
21098f6e1e22SMaarten Lankhorst 	return 0;
21108f6e1e22SMaarten Lankhorst }
21118f6e1e22SMaarten Lankhorst EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
21128f6e1e22SMaarten Lankhorst 
21138f6e1e22SMaarten Lankhorst /**
211452217195SDaniel Vetter  * drm_mode_create_aspect_ratio_property - create aspect ratio property
211552217195SDaniel Vetter  * @dev: DRM device
211652217195SDaniel Vetter  *
211752217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
211852217195SDaniel Vetter  * connectors.
211952217195SDaniel Vetter  *
212052217195SDaniel Vetter  * Returns:
212152217195SDaniel Vetter  * Zero on success, negative errno on failure.
212252217195SDaniel Vetter  */
212352217195SDaniel Vetter int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
212452217195SDaniel Vetter {
212552217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property)
212652217195SDaniel Vetter 		return 0;
212752217195SDaniel Vetter 
212852217195SDaniel Vetter 	dev->mode_config.aspect_ratio_property =
212952217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "aspect ratio",
213052217195SDaniel Vetter 				drm_aspect_ratio_enum_list,
213152217195SDaniel Vetter 				ARRAY_SIZE(drm_aspect_ratio_enum_list));
213252217195SDaniel Vetter 
213352217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property == NULL)
213452217195SDaniel Vetter 		return -ENOMEM;
213552217195SDaniel Vetter 
213652217195SDaniel Vetter 	return 0;
213752217195SDaniel Vetter }
213852217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
213952217195SDaniel Vetter 
214052217195SDaniel Vetter /**
2141d2c6a405SUma Shankar  * DOC: standard connector properties
2142d2c6a405SUma Shankar  *
2143d2c6a405SUma Shankar  * Colorspace:
2144d2c6a405SUma Shankar  *     This property helps select a suitable colorspace based on the sink
2145d2c6a405SUma Shankar  *     capability. Modern sink devices support wider gamut like BT2020.
2146d2c6a405SUma Shankar  *     This helps switch to BT2020 mode if the BT2020 encoded video stream
2147d2c6a405SUma Shankar  *     is being played by the user, same for any other colorspace. Thereby
2148d2c6a405SUma Shankar  *     giving a good visual experience to users.
2149d2c6a405SUma Shankar  *
2150d2c6a405SUma Shankar  *     The expectation from userspace is that it should parse the EDID
2151d2c6a405SUma Shankar  *     and get supported colorspaces. Use this property and switch to the
2152d2c6a405SUma Shankar  *     one supported. Sink supported colorspaces should be retrieved by
2153d2c6a405SUma Shankar  *     userspace from EDID and driver will not explicitly expose them.
2154d2c6a405SUma Shankar  *
2155d2c6a405SUma Shankar  *     Basically the expectation from userspace is:
2156d2c6a405SUma Shankar  *      - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink
2157d2c6a405SUma Shankar  *        colorspace
2158d2c6a405SUma Shankar  *      - Set this new property to let the sink know what it
2159d2c6a405SUma Shankar  *        converted the CRTC output to.
2160d2c6a405SUma Shankar  *      - This property is just to inform sink what colorspace
2161d2c6a405SUma Shankar  *        source is trying to drive.
2162d2c6a405SUma Shankar  *
21638806cd3aSGwan-gyeong Mun  * Because between HDMI and DP have different colorspaces,
216445cf0e91SGwan-gyeong Mun  * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and
216545cf0e91SGwan-gyeong Mun  * drm_mode_create_dp_colorspace_property() is used for DP connector.
2166d2c6a405SUma Shankar  */
21678806cd3aSGwan-gyeong Mun 
21686120611aSHarry Wentland static int drm_mode_create_colorspace_property(struct drm_connector *connector,
2169c627087cSHarry Wentland 					u32 supported_colorspaces)
21706120611aSHarry Wentland {
21716120611aSHarry Wentland 	struct drm_device *dev = connector->dev;
2172c627087cSHarry Wentland 	u32 colorspaces = supported_colorspaces | BIT(DRM_MODE_COLORIMETRY_DEFAULT);
2173c627087cSHarry Wentland 	struct drm_prop_enum_list enum_list[DRM_MODE_COLORIMETRY_COUNT];
2174c627087cSHarry Wentland 	int i, len;
21756120611aSHarry Wentland 
21766120611aSHarry Wentland 	if (connector->colorspace_property)
21776120611aSHarry Wentland 		return 0;
21786120611aSHarry Wentland 
2179c627087cSHarry Wentland 	if (!supported_colorspaces) {
2180c627087cSHarry Wentland 		drm_err(dev, "No supported colorspaces provded on [CONNECTOR:%d:%s]\n",
2181c627087cSHarry Wentland 			    connector->base.id, connector->name);
2182c627087cSHarry Wentland 		return -EINVAL;
2183c627087cSHarry Wentland 	}
2184c627087cSHarry Wentland 
2185c627087cSHarry Wentland 	if ((supported_colorspaces & -BIT(DRM_MODE_COLORIMETRY_COUNT)) != 0) {
2186c627087cSHarry Wentland 		drm_err(dev, "Unknown colorspace provded on [CONNECTOR:%d:%s]\n",
2187c627087cSHarry Wentland 			    connector->base.id, connector->name);
2188c627087cSHarry Wentland 		return -EINVAL;
2189c627087cSHarry Wentland 	}
2190c627087cSHarry Wentland 
2191c627087cSHarry Wentland 	len = 0;
2192c627087cSHarry Wentland 	for (i = 0; i < DRM_MODE_COLORIMETRY_COUNT; i++) {
2193c627087cSHarry Wentland 		if ((colorspaces & BIT(i)) == 0)
2194c627087cSHarry Wentland 			continue;
2195c627087cSHarry Wentland 
2196c627087cSHarry Wentland 		enum_list[len].type = i;
2197c627087cSHarry Wentland 		enum_list[len].name = colorspace_names[i];
2198c627087cSHarry Wentland 		len++;
2199c627087cSHarry Wentland 	}
22006120611aSHarry Wentland 
22016120611aSHarry Wentland 	connector->colorspace_property =
22026120611aSHarry Wentland 		drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
2203c627087cSHarry Wentland 					enum_list,
2204c627087cSHarry Wentland 					len);
22056120611aSHarry Wentland 
22066120611aSHarry Wentland 	if (!connector->colorspace_property)
22076120611aSHarry Wentland 		return -ENOMEM;
22086120611aSHarry Wentland 
22096120611aSHarry Wentland 	return 0;
22106120611aSHarry Wentland }
2211c627087cSHarry Wentland 
22128806cd3aSGwan-gyeong Mun /**
22138806cd3aSGwan-gyeong Mun  * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
22148806cd3aSGwan-gyeong Mun  * @connector: connector to create the Colorspace property on.
22158806cd3aSGwan-gyeong Mun  *
22168806cd3aSGwan-gyeong Mun  * Called by a driver the first time it's needed, must be attached to desired
22178806cd3aSGwan-gyeong Mun  * HDMI connectors.
22188806cd3aSGwan-gyeong Mun  *
22198806cd3aSGwan-gyeong Mun  * Returns:
222084e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
22218806cd3aSGwan-gyeong Mun  */
2222c265f340SHarry Wentland int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector,
2223c265f340SHarry Wentland 					     u32 supported_colorspaces)
2224d2c6a405SUma Shankar {
2225c265f340SHarry Wentland 	u32 colorspaces;
2226c265f340SHarry Wentland 
2227c265f340SHarry Wentland 	if (supported_colorspaces)
2228c265f340SHarry Wentland 		colorspaces = supported_colorspaces & hdmi_colorspaces;
2229c265f340SHarry Wentland 	else
2230c265f340SHarry Wentland 		colorspaces = hdmi_colorspaces;
2231c265f340SHarry Wentland 
2232c265f340SHarry Wentland 	return drm_mode_create_colorspace_property(connector, colorspaces);
2233d2c6a405SUma Shankar }
22348806cd3aSGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
2235d2c6a405SUma Shankar 
2236d2c6a405SUma Shankar /**
223745cf0e91SGwan-gyeong Mun  * drm_mode_create_dp_colorspace_property - create dp colorspace property
223845cf0e91SGwan-gyeong Mun  * @connector: connector to create the Colorspace property on.
223945cf0e91SGwan-gyeong Mun  *
224045cf0e91SGwan-gyeong Mun  * Called by a driver the first time it's needed, must be attached to desired
224145cf0e91SGwan-gyeong Mun  * DP connectors.
224245cf0e91SGwan-gyeong Mun  *
224345cf0e91SGwan-gyeong Mun  * Returns:
224484e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
224545cf0e91SGwan-gyeong Mun  */
2246c265f340SHarry Wentland int drm_mode_create_dp_colorspace_property(struct drm_connector *connector,
2247c265f340SHarry Wentland 					   u32 supported_colorspaces)
224845cf0e91SGwan-gyeong Mun {
2249c265f340SHarry Wentland 	u32 colorspaces;
2250c265f340SHarry Wentland 
2251c265f340SHarry Wentland 	if (supported_colorspaces)
2252c265f340SHarry Wentland 		colorspaces = supported_colorspaces & dp_colorspaces;
2253c265f340SHarry Wentland 	else
2254c265f340SHarry Wentland 		colorspaces = dp_colorspaces;
2255c265f340SHarry Wentland 
2256c265f340SHarry Wentland 	return drm_mode_create_colorspace_property(connector, colorspaces);
225745cf0e91SGwan-gyeong Mun }
225845cf0e91SGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
225952217195SDaniel Vetter 
226097e14fbeSDaniel Vetter /**
226152217195SDaniel Vetter  * drm_mode_create_content_type_property - create content type property
226252217195SDaniel Vetter  * @dev: DRM device
226397e14fbeSDaniel Vetter  *
226452217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
226552217195SDaniel Vetter  * connectors.
226652217195SDaniel Vetter  *
226752217195SDaniel Vetter  * Returns:
226852217195SDaniel Vetter  * Zero on success, negative errno on failure.
226952217195SDaniel Vetter  */
227052217195SDaniel Vetter int drm_mode_create_content_type_property(struct drm_device *dev)
227152217195SDaniel Vetter {
227252217195SDaniel Vetter 	if (dev->mode_config.content_type_property)
227397e14fbeSDaniel Vetter 		return 0;
227452217195SDaniel Vetter 
227552217195SDaniel Vetter 	dev->mode_config.content_type_property =
227652217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "content type",
227752217195SDaniel Vetter 					 drm_content_type_enum_list,
227852217195SDaniel Vetter 					 ARRAY_SIZE(drm_content_type_enum_list));
227952217195SDaniel Vetter 
228052217195SDaniel Vetter 	if (dev->mode_config.content_type_property == NULL)
228152217195SDaniel Vetter 		return -ENOMEM;
228252217195SDaniel Vetter 
228352217195SDaniel Vetter 	return 0;
228452217195SDaniel Vetter }
228552217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_content_type_property);
228652217195SDaniel Vetter 
228752217195SDaniel Vetter /**
228852217195SDaniel Vetter  * drm_mode_create_suggested_offset_properties - create suggests offset properties
228952217195SDaniel Vetter  * @dev: DRM device
229052217195SDaniel Vetter  *
229184e543bcSAntonio Borneo  * Create the suggested x/y offset property for connectors.
2292f85d9e59SRandy Dunlap  *
2293f85d9e59SRandy Dunlap  * Returns:
2294f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
229552217195SDaniel Vetter  */
229652217195SDaniel Vetter int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
229752217195SDaniel Vetter {
229852217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
229952217195SDaniel Vetter 		return 0;
230052217195SDaniel Vetter 
230152217195SDaniel Vetter 	dev->mode_config.suggested_x_property =
230252217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
230352217195SDaniel Vetter 
230452217195SDaniel Vetter 	dev->mode_config.suggested_y_property =
230552217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
230652217195SDaniel Vetter 
230752217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property == NULL ||
230852217195SDaniel Vetter 	    dev->mode_config.suggested_y_property == NULL)
230952217195SDaniel Vetter 		return -ENOMEM;
231052217195SDaniel Vetter 	return 0;
231152217195SDaniel Vetter }
231252217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
231352217195SDaniel Vetter 
231452217195SDaniel Vetter /**
231552217195SDaniel Vetter  * drm_connector_set_path_property - set tile property on connector
231652217195SDaniel Vetter  * @connector: connector to set property on.
231752217195SDaniel Vetter  * @path: path to use for property; must not be NULL.
231852217195SDaniel Vetter  *
231952217195SDaniel Vetter  * This creates a property to expose to userspace to specify a
232052217195SDaniel Vetter  * connector path. This is mainly used for DisplayPort MST where
232152217195SDaniel Vetter  * connectors have a topology and we want to allow userspace to give
232252217195SDaniel Vetter  * them more meaningful names.
232352217195SDaniel Vetter  *
232452217195SDaniel Vetter  * Returns:
232552217195SDaniel Vetter  * Zero on success, negative errno on failure.
232652217195SDaniel Vetter  */
232752217195SDaniel Vetter int drm_connector_set_path_property(struct drm_connector *connector,
232852217195SDaniel Vetter 				    const char *path)
232952217195SDaniel Vetter {
233052217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
233152217195SDaniel Vetter 	int ret;
233252217195SDaniel Vetter 
233352217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
233452217195SDaniel Vetter 					       &connector->path_blob_ptr,
233552217195SDaniel Vetter 					       strlen(path) + 1,
233652217195SDaniel Vetter 					       path,
233752217195SDaniel Vetter 					       &connector->base,
233852217195SDaniel Vetter 					       dev->mode_config.path_property);
233952217195SDaniel Vetter 	return ret;
234052217195SDaniel Vetter }
234152217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_set_path_property);
234252217195SDaniel Vetter 
234352217195SDaniel Vetter /**
234452217195SDaniel Vetter  * drm_connector_set_tile_property - set tile property on connector
234552217195SDaniel Vetter  * @connector: connector to set property on.
234652217195SDaniel Vetter  *
234752217195SDaniel Vetter  * This looks up the tile information for a connector, and creates a
234852217195SDaniel Vetter  * property for userspace to parse if it exists. The property is of
234952217195SDaniel Vetter  * the form of 8 integers using ':' as a separator.
23502de3a078SManasi Navare  * This is used for dual port tiled displays with DisplayPort SST
23512de3a078SManasi Navare  * or DisplayPort MST connectors.
235252217195SDaniel Vetter  *
235352217195SDaniel Vetter  * Returns:
235452217195SDaniel Vetter  * Zero on success, errno on failure.
235552217195SDaniel Vetter  */
235652217195SDaniel Vetter int drm_connector_set_tile_property(struct drm_connector *connector)
235752217195SDaniel Vetter {
235852217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
235952217195SDaniel Vetter 	char tile[256];
236052217195SDaniel Vetter 	int ret;
236152217195SDaniel Vetter 
236252217195SDaniel Vetter 	if (!connector->has_tile) {
236352217195SDaniel Vetter 		ret  = drm_property_replace_global_blob(dev,
236452217195SDaniel Vetter 							&connector->tile_blob_ptr,
236552217195SDaniel Vetter 							0,
236652217195SDaniel Vetter 							NULL,
236752217195SDaniel Vetter 							&connector->base,
236852217195SDaniel Vetter 							dev->mode_config.tile_property);
236952217195SDaniel Vetter 		return ret;
237052217195SDaniel Vetter 	}
237152217195SDaniel Vetter 
237252217195SDaniel Vetter 	snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
237352217195SDaniel Vetter 		 connector->tile_group->id, connector->tile_is_single_monitor,
237452217195SDaniel Vetter 		 connector->num_h_tile, connector->num_v_tile,
237552217195SDaniel Vetter 		 connector->tile_h_loc, connector->tile_v_loc,
237652217195SDaniel Vetter 		 connector->tile_h_size, connector->tile_v_size);
237752217195SDaniel Vetter 
237852217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
237952217195SDaniel Vetter 					       &connector->tile_blob_ptr,
238052217195SDaniel Vetter 					       strlen(tile) + 1,
238152217195SDaniel Vetter 					       tile,
238252217195SDaniel Vetter 					       &connector->base,
238352217195SDaniel Vetter 					       dev->mode_config.tile_property);
238452217195SDaniel Vetter 	return ret;
238552217195SDaniel Vetter }
238697e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_tile_property);
238752217195SDaniel Vetter 
238852217195SDaniel Vetter /**
238997e14fbeSDaniel Vetter  * drm_connector_set_link_status_property - Set link status property of a connector
239040ee6fbeSManasi Navare  * @connector: drm connector
239140ee6fbeSManasi Navare  * @link_status: new value of link status property (0: Good, 1: Bad)
239240ee6fbeSManasi Navare  *
239340ee6fbeSManasi Navare  * In usual working scenario, this link status property will always be set to
239440ee6fbeSManasi Navare  * "GOOD". If something fails during or after a mode set, the kernel driver
239540ee6fbeSManasi Navare  * may set this link status property to "BAD". The caller then needs to send a
239640ee6fbeSManasi Navare  * hotplug uevent for userspace to re-check the valid modes through
239740ee6fbeSManasi Navare  * GET_CONNECTOR_IOCTL and retry modeset.
239840ee6fbeSManasi Navare  *
239940ee6fbeSManasi Navare  * Note: Drivers cannot rely on userspace to support this property and
240040ee6fbeSManasi Navare  * issue a modeset. As such, they may choose to handle issues (like
240140ee6fbeSManasi Navare  * re-training a link) without userspace's intervention.
240240ee6fbeSManasi Navare  *
240340ee6fbeSManasi Navare  * The reason for adding this property is to handle link training failures, but
240440ee6fbeSManasi Navare  * it is not limited to DP or link training. For example, if we implement
240540ee6fbeSManasi Navare  * asynchronous setcrtc, this property can be used to report any failures in that.
240640ee6fbeSManasi Navare  */
240797e14fbeSDaniel Vetter void drm_connector_set_link_status_property(struct drm_connector *connector,
240840ee6fbeSManasi Navare 					    uint64_t link_status)
240940ee6fbeSManasi Navare {
241040ee6fbeSManasi Navare 	struct drm_device *dev = connector->dev;
241140ee6fbeSManasi Navare 
241240ee6fbeSManasi Navare 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
241340ee6fbeSManasi Navare 	connector->state->link_status = link_status;
241440ee6fbeSManasi Navare 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
241540ee6fbeSManasi Navare }
241697e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_link_status_property);
241740ee6fbeSManasi Navare 
24188d70f395SHans de Goede /**
241947e22ff1SRadhakrishna Sripada  * drm_connector_attach_max_bpc_property - attach "max bpc" property
242047e22ff1SRadhakrishna Sripada  * @connector: connector to attach max bpc property on.
242147e22ff1SRadhakrishna Sripada  * @min: The minimum bit depth supported by the connector.
242247e22ff1SRadhakrishna Sripada  * @max: The maximum bit depth supported by the connector.
242347e22ff1SRadhakrishna Sripada  *
242447e22ff1SRadhakrishna Sripada  * This is used to add support for limiting the bit depth on a connector.
242547e22ff1SRadhakrishna Sripada  *
242647e22ff1SRadhakrishna Sripada  * Returns:
242747e22ff1SRadhakrishna Sripada  * Zero on success, negative errno on failure.
242847e22ff1SRadhakrishna Sripada  */
242947e22ff1SRadhakrishna Sripada int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
243047e22ff1SRadhakrishna Sripada 					  int min, int max)
243147e22ff1SRadhakrishna Sripada {
243247e22ff1SRadhakrishna Sripada 	struct drm_device *dev = connector->dev;
243347e22ff1SRadhakrishna Sripada 	struct drm_property *prop;
243447e22ff1SRadhakrishna Sripada 
243547e22ff1SRadhakrishna Sripada 	prop = connector->max_bpc_property;
243647e22ff1SRadhakrishna Sripada 	if (!prop) {
243747e22ff1SRadhakrishna Sripada 		prop = drm_property_create_range(dev, 0, "max bpc", min, max);
243847e22ff1SRadhakrishna Sripada 		if (!prop)
243947e22ff1SRadhakrishna Sripada 			return -ENOMEM;
244047e22ff1SRadhakrishna Sripada 
244147e22ff1SRadhakrishna Sripada 		connector->max_bpc_property = prop;
244247e22ff1SRadhakrishna Sripada 	}
244347e22ff1SRadhakrishna Sripada 
244447e22ff1SRadhakrishna Sripada 	drm_object_attach_property(&connector->base, prop, max);
244547e22ff1SRadhakrishna Sripada 	connector->state->max_requested_bpc = max;
244647e22ff1SRadhakrishna Sripada 	connector->state->max_bpc = max;
244747e22ff1SRadhakrishna Sripada 
244847e22ff1SRadhakrishna Sripada 	return 0;
244947e22ff1SRadhakrishna Sripada }
245047e22ff1SRadhakrishna Sripada EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
245147e22ff1SRadhakrishna Sripada 
245247e22ff1SRadhakrishna Sripada /**
2453e057b52cSMaxime Ripard  * drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADA" property
2454e057b52cSMaxime Ripard  * @connector: connector to attach the property on.
2455e057b52cSMaxime Ripard  *
2456e057b52cSMaxime Ripard  * This is used to allow the userspace to send HDR Metadata to the
2457e057b52cSMaxime Ripard  * driver.
2458e057b52cSMaxime Ripard  *
2459e057b52cSMaxime Ripard  * Returns:
2460e057b52cSMaxime Ripard  * Zero on success, negative errno on failure.
2461e057b52cSMaxime Ripard  */
2462e057b52cSMaxime Ripard int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector)
2463e057b52cSMaxime Ripard {
2464e057b52cSMaxime Ripard 	struct drm_device *dev = connector->dev;
2465e057b52cSMaxime Ripard 	struct drm_property *prop = dev->mode_config.hdr_output_metadata_property;
2466e057b52cSMaxime Ripard 
2467e057b52cSMaxime Ripard 	drm_object_attach_property(&connector->base, prop, 0);
2468e057b52cSMaxime Ripard 
2469e057b52cSMaxime Ripard 	return 0;
2470e057b52cSMaxime Ripard }
2471e057b52cSMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property);
2472e057b52cSMaxime Ripard 
2473e057b52cSMaxime Ripard /**
247421f79128SMaxime Ripard  * drm_connector_attach_colorspace_property - attach "Colorspace" property
247521f79128SMaxime Ripard  * @connector: connector to attach the property on.
247621f79128SMaxime Ripard  *
247721f79128SMaxime Ripard  * This is used to allow the userspace to signal the output colorspace
247821f79128SMaxime Ripard  * to the driver.
247921f79128SMaxime Ripard  *
248021f79128SMaxime Ripard  * Returns:
248121f79128SMaxime Ripard  * Zero on success, negative errno on failure.
248221f79128SMaxime Ripard  */
248321f79128SMaxime Ripard int drm_connector_attach_colorspace_property(struct drm_connector *connector)
248421f79128SMaxime Ripard {
248521f79128SMaxime Ripard 	struct drm_property *prop = connector->colorspace_property;
248621f79128SMaxime Ripard 
248721f79128SMaxime Ripard 	drm_object_attach_property(&connector->base, prop, DRM_MODE_COLORIMETRY_DEFAULT);
248821f79128SMaxime Ripard 
248921f79128SMaxime Ripard 	return 0;
249021f79128SMaxime Ripard }
249121f79128SMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_colorspace_property);
249221f79128SMaxime Ripard 
249321f79128SMaxime Ripard /**
249472921cdfSMaxime Ripard  * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed
249572921cdfSMaxime Ripard  * @old_state: old connector state to compare
249672921cdfSMaxime Ripard  * @new_state: new connector state to compare
249772921cdfSMaxime Ripard  *
249872921cdfSMaxime Ripard  * This is used by HDR-enabled drivers to test whether the HDR metadata
249972921cdfSMaxime Ripard  * have changed between two different connector state (and thus probably
250072921cdfSMaxime Ripard  * requires a full blown mode change).
250172921cdfSMaxime Ripard  *
250272921cdfSMaxime Ripard  * Returns:
250372921cdfSMaxime Ripard  * True if the metadata are equal, False otherwise
250472921cdfSMaxime Ripard  */
250572921cdfSMaxime Ripard bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state,
250672921cdfSMaxime Ripard 					     struct drm_connector_state *new_state)
250772921cdfSMaxime Ripard {
250872921cdfSMaxime Ripard 	struct drm_property_blob *old_blob = old_state->hdr_output_metadata;
250972921cdfSMaxime Ripard 	struct drm_property_blob *new_blob = new_state->hdr_output_metadata;
251072921cdfSMaxime Ripard 
251172921cdfSMaxime Ripard 	if (!old_blob || !new_blob)
251272921cdfSMaxime Ripard 		return old_blob == new_blob;
251372921cdfSMaxime Ripard 
251472921cdfSMaxime Ripard 	if (old_blob->length != new_blob->length)
251572921cdfSMaxime Ripard 		return false;
251672921cdfSMaxime Ripard 
251772921cdfSMaxime Ripard 	return !memcmp(old_blob->data, new_blob->data, old_blob->length);
251872921cdfSMaxime Ripard }
251972921cdfSMaxime Ripard EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal);
252072921cdfSMaxime Ripard 
252172921cdfSMaxime Ripard /**
2522ba1b0f6cSNicholas Kazlauskas  * drm_connector_set_vrr_capable_property - sets the variable refresh rate
2523ba1b0f6cSNicholas Kazlauskas  * capable property for a connector
2524ba1b0f6cSNicholas Kazlauskas  * @connector: drm connector
2525ba1b0f6cSNicholas Kazlauskas  * @capable: True if the connector is variable refresh rate capable
2526ba1b0f6cSNicholas Kazlauskas  *
2527ba1b0f6cSNicholas Kazlauskas  * Should be used by atomic drivers to update the indicated support for
2528ba1b0f6cSNicholas Kazlauskas  * variable refresh rate over a connector.
2529ba1b0f6cSNicholas Kazlauskas  */
2530ba1b0f6cSNicholas Kazlauskas void drm_connector_set_vrr_capable_property(
2531ba1b0f6cSNicholas Kazlauskas 		struct drm_connector *connector, bool capable)
2532ba1b0f6cSNicholas Kazlauskas {
253362929726SManasi Navare 	if (!connector->vrr_capable_property)
253462929726SManasi Navare 		return;
253562929726SManasi Navare 
2536ba1b0f6cSNicholas Kazlauskas 	drm_object_property_set_value(&connector->base,
2537ba1b0f6cSNicholas Kazlauskas 				      connector->vrr_capable_property,
2538ba1b0f6cSNicholas Kazlauskas 				      capable);
2539ba1b0f6cSNicholas Kazlauskas }
2540ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
2541ba1b0f6cSNicholas Kazlauskas 
2542ba1b0f6cSNicholas Kazlauskas /**
254384e543bcSAntonio Borneo  * drm_connector_set_panel_orientation - sets the connector's panel_orientation
254469654c63SDerek Basehore  * @connector: connector for which to set the panel-orientation property.
254569654c63SDerek Basehore  * @panel_orientation: drm_panel_orientation value to set
25468d70f395SHans de Goede  *
254769654c63SDerek Basehore  * This function sets the connector's panel_orientation and attaches
254869654c63SDerek Basehore  * a "panel orientation" property to the connector.
25498d70f395SHans de Goede  *
255069654c63SDerek Basehore  * Calling this function on a connector where the panel_orientation has
255169654c63SDerek Basehore  * already been set is a no-op (e.g. the orientation has been overridden with
255269654c63SDerek Basehore  * a kernel commandline option).
255369654c63SDerek Basehore  *
255469654c63SDerek Basehore  * It is allowed to call this function with a panel_orientation of
255569654c63SDerek Basehore  * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
25568d70f395SHans de Goede  *
25575e41b01aSHsin-Yi Wang  * The function shouldn't be called in panel after drm is registered (i.e.
25585e41b01aSHsin-Yi Wang  * drm_dev_register() is called in drm).
25595e41b01aSHsin-Yi Wang  *
25608d70f395SHans de Goede  * Returns:
25618d70f395SHans de Goede  * Zero on success, negative errno on failure.
25628d70f395SHans de Goede  */
256369654c63SDerek Basehore int drm_connector_set_panel_orientation(
256469654c63SDerek Basehore 	struct drm_connector *connector,
256569654c63SDerek Basehore 	enum drm_panel_orientation panel_orientation)
25668d70f395SHans de Goede {
25678d70f395SHans de Goede 	struct drm_device *dev = connector->dev;
25688d70f395SHans de Goede 	struct drm_display_info *info = &connector->display_info;
25698d70f395SHans de Goede 	struct drm_property *prop;
25708d70f395SHans de Goede 
257169654c63SDerek Basehore 	/* Already set? */
257269654c63SDerek Basehore 	if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
25738d70f395SHans de Goede 		return 0;
25748d70f395SHans de Goede 
257569654c63SDerek Basehore 	/* Don't attach the property if the orientation is unknown */
257669654c63SDerek Basehore 	if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
257769654c63SDerek Basehore 		return 0;
257869654c63SDerek Basehore 
257969654c63SDerek Basehore 	info->panel_orientation = panel_orientation;
258069654c63SDerek Basehore 
25818d70f395SHans de Goede 	prop = dev->mode_config.panel_orientation_property;
25828d70f395SHans de Goede 	if (!prop) {
25838d70f395SHans de Goede 		prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
25848d70f395SHans de Goede 				"panel orientation",
25858d70f395SHans de Goede 				drm_panel_orientation_enum_list,
25868d70f395SHans de Goede 				ARRAY_SIZE(drm_panel_orientation_enum_list));
25878d70f395SHans de Goede 		if (!prop)
25888d70f395SHans de Goede 			return -ENOMEM;
25898d70f395SHans de Goede 
25908d70f395SHans de Goede 		dev->mode_config.panel_orientation_property = prop;
25918d70f395SHans de Goede 	}
25928d70f395SHans de Goede 
25938d70f395SHans de Goede 	drm_object_attach_property(&connector->base, prop,
25948d70f395SHans de Goede 				   info->panel_orientation);
25958d70f395SHans de Goede 	return 0;
25968d70f395SHans de Goede }
259769654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation);
259869654c63SDerek Basehore 
259969654c63SDerek Basehore /**
2600f85d9e59SRandy Dunlap  * drm_connector_set_panel_orientation_with_quirk - set the
2601f85d9e59SRandy Dunlap  *	connector's panel_orientation after checking for quirks
260269654c63SDerek Basehore  * @connector: connector for which to init the panel-orientation property.
260369654c63SDerek Basehore  * @panel_orientation: drm_panel_orientation value to set
260469654c63SDerek Basehore  * @width: width in pixels of the panel, used for panel quirk detection
260569654c63SDerek Basehore  * @height: height in pixels of the panel, used for panel quirk detection
260669654c63SDerek Basehore  *
260769654c63SDerek Basehore  * Like drm_connector_set_panel_orientation(), but with a check for platform
260869654c63SDerek Basehore  * specific (e.g. DMI based) quirks overriding the passed in panel_orientation.
260969654c63SDerek Basehore  *
261069654c63SDerek Basehore  * Returns:
261169654c63SDerek Basehore  * Zero on success, negative errno on failure.
261269654c63SDerek Basehore  */
261369654c63SDerek Basehore int drm_connector_set_panel_orientation_with_quirk(
261469654c63SDerek Basehore 	struct drm_connector *connector,
261569654c63SDerek Basehore 	enum drm_panel_orientation panel_orientation,
261669654c63SDerek Basehore 	int width, int height)
261769654c63SDerek Basehore {
261869654c63SDerek Basehore 	int orientation_quirk;
261969654c63SDerek Basehore 
262069654c63SDerek Basehore 	orientation_quirk = drm_get_panel_orientation_quirk(width, height);
262169654c63SDerek Basehore 	if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
262269654c63SDerek Basehore 		panel_orientation = orientation_quirk;
262369654c63SDerek Basehore 
262469654c63SDerek Basehore 	return drm_connector_set_panel_orientation(connector,
262569654c63SDerek Basehore 						   panel_orientation);
262669654c63SDerek Basehore }
262769654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
26288d70f395SHans de Goede 
26295e41b01aSHsin-Yi Wang /**
26305e41b01aSHsin-Yi Wang  * drm_connector_set_orientation_from_panel -
26315e41b01aSHsin-Yi Wang  *	set the connector's panel_orientation from panel's callback.
26325e41b01aSHsin-Yi Wang  * @connector: connector for which to init the panel-orientation property.
26335e41b01aSHsin-Yi Wang  * @panel: panel that can provide orientation information.
26345e41b01aSHsin-Yi Wang  *
26355e41b01aSHsin-Yi Wang  * Drm drivers should call this function before drm_dev_register().
26365e41b01aSHsin-Yi Wang  * Orientation is obtained from panel's .get_orientation() callback.
26375e41b01aSHsin-Yi Wang  *
26385e41b01aSHsin-Yi Wang  * Returns:
26395e41b01aSHsin-Yi Wang  * Zero on success, negative errno on failure.
26405e41b01aSHsin-Yi Wang  */
26415e41b01aSHsin-Yi Wang int drm_connector_set_orientation_from_panel(
26425e41b01aSHsin-Yi Wang 	struct drm_connector *connector,
26435e41b01aSHsin-Yi Wang 	struct drm_panel *panel)
26445e41b01aSHsin-Yi Wang {
26455e41b01aSHsin-Yi Wang 	enum drm_panel_orientation orientation;
26465e41b01aSHsin-Yi Wang 
26475e41b01aSHsin-Yi Wang 	if (panel && panel->funcs && panel->funcs->get_orientation)
26485e41b01aSHsin-Yi Wang 		orientation = panel->funcs->get_orientation(panel);
26495e41b01aSHsin-Yi Wang 	else
26505e41b01aSHsin-Yi Wang 		orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
26515e41b01aSHsin-Yi Wang 
26525e41b01aSHsin-Yi Wang 	return drm_connector_set_panel_orientation(connector, orientation);
26535e41b01aSHsin-Yi Wang }
26545e41b01aSHsin-Yi Wang EXPORT_SYMBOL(drm_connector_set_orientation_from_panel);
26555e41b01aSHsin-Yi Wang 
2656107fe904SRajat Jain static const struct drm_prop_enum_list privacy_screen_enum[] = {
2657107fe904SRajat Jain 	{ PRIVACY_SCREEN_DISABLED,		"Disabled" },
2658107fe904SRajat Jain 	{ PRIVACY_SCREEN_ENABLED,		"Enabled" },
2659107fe904SRajat Jain 	{ PRIVACY_SCREEN_DISABLED_LOCKED,	"Disabled-locked" },
2660107fe904SRajat Jain 	{ PRIVACY_SCREEN_ENABLED_LOCKED,	"Enabled-locked" },
2661107fe904SRajat Jain };
2662107fe904SRajat Jain 
2663107fe904SRajat Jain /**
2664107fe904SRajat Jain  * drm_connector_create_privacy_screen_properties - create the drm connecter's
2665107fe904SRajat Jain  *    privacy-screen properties.
2666107fe904SRajat Jain  * @connector: connector for which to create the privacy-screen properties
2667107fe904SRajat Jain  *
2668107fe904SRajat Jain  * This function creates the "privacy-screen sw-state" and "privacy-screen
2669107fe904SRajat Jain  * hw-state" properties for the connector. They are not attached.
2670107fe904SRajat Jain  */
2671107fe904SRajat Jain void
2672107fe904SRajat Jain drm_connector_create_privacy_screen_properties(struct drm_connector *connector)
2673107fe904SRajat Jain {
2674107fe904SRajat Jain 	if (connector->privacy_screen_sw_state_property)
2675107fe904SRajat Jain 		return;
2676107fe904SRajat Jain 
2677107fe904SRajat Jain 	/* Note sw-state only supports the first 2 values of the enum */
2678107fe904SRajat Jain 	connector->privacy_screen_sw_state_property =
2679107fe904SRajat Jain 		drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM,
2680107fe904SRajat Jain 				"privacy-screen sw-state",
2681107fe904SRajat Jain 				privacy_screen_enum, 2);
2682107fe904SRajat Jain 
2683107fe904SRajat Jain 	connector->privacy_screen_hw_state_property =
2684107fe904SRajat Jain 		drm_property_create_enum(connector->dev,
2685107fe904SRajat Jain 				DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM,
2686107fe904SRajat Jain 				"privacy-screen hw-state",
2687107fe904SRajat Jain 				privacy_screen_enum,
2688107fe904SRajat Jain 				ARRAY_SIZE(privacy_screen_enum));
2689107fe904SRajat Jain }
2690107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties);
2691107fe904SRajat Jain 
2692107fe904SRajat Jain /**
2693107fe904SRajat Jain  * drm_connector_attach_privacy_screen_properties - attach the drm connecter's
2694107fe904SRajat Jain  *    privacy-screen properties.
2695107fe904SRajat Jain  * @connector: connector on which to attach the privacy-screen properties
2696107fe904SRajat Jain  *
2697107fe904SRajat Jain  * This function attaches the "privacy-screen sw-state" and "privacy-screen
2698107fe904SRajat Jain  * hw-state" properties to the connector. The initial state of both is set
2699107fe904SRajat Jain  * to "Disabled".
2700107fe904SRajat Jain  */
2701107fe904SRajat Jain void
2702107fe904SRajat Jain drm_connector_attach_privacy_screen_properties(struct drm_connector *connector)
2703107fe904SRajat Jain {
2704107fe904SRajat Jain 	if (!connector->privacy_screen_sw_state_property)
2705107fe904SRajat Jain 		return;
2706107fe904SRajat Jain 
2707107fe904SRajat Jain 	drm_object_attach_property(&connector->base,
2708107fe904SRajat Jain 				   connector->privacy_screen_sw_state_property,
2709107fe904SRajat Jain 				   PRIVACY_SCREEN_DISABLED);
2710107fe904SRajat Jain 
2711107fe904SRajat Jain 	drm_object_attach_property(&connector->base,
2712107fe904SRajat Jain 				   connector->privacy_screen_hw_state_property,
2713107fe904SRajat Jain 				   PRIVACY_SCREEN_DISABLED);
2714107fe904SRajat Jain }
2715107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties);
2716107fe904SRajat Jain 
2717334f74eeSHans de Goede static void drm_connector_update_privacy_screen_properties(
2718334f74eeSHans de Goede 	struct drm_connector *connector, bool set_sw_state)
2719334f74eeSHans de Goede {
2720334f74eeSHans de Goede 	enum drm_privacy_screen_status sw_state, hw_state;
2721334f74eeSHans de Goede 
2722334f74eeSHans de Goede 	drm_privacy_screen_get_state(connector->privacy_screen,
2723334f74eeSHans de Goede 				     &sw_state, &hw_state);
2724334f74eeSHans de Goede 
2725334f74eeSHans de Goede 	if (set_sw_state)
2726334f74eeSHans de Goede 		connector->state->privacy_screen_sw_state = sw_state;
2727334f74eeSHans de Goede 	drm_object_property_set_value(&connector->base,
2728334f74eeSHans de Goede 			connector->privacy_screen_hw_state_property, hw_state);
2729334f74eeSHans de Goede }
2730334f74eeSHans de Goede 
2731334f74eeSHans de Goede static int drm_connector_privacy_screen_notifier(
2732334f74eeSHans de Goede 	struct notifier_block *nb, unsigned long action, void *data)
2733334f74eeSHans de Goede {
2734334f74eeSHans de Goede 	struct drm_connector *connector =
2735334f74eeSHans de Goede 		container_of(nb, struct drm_connector, privacy_screen_notifier);
2736334f74eeSHans de Goede 	struct drm_device *dev = connector->dev;
2737334f74eeSHans de Goede 
2738334f74eeSHans de Goede 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2739334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, true);
2740334f74eeSHans de Goede 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
2741334f74eeSHans de Goede 
27420cf8d292SSimon Ser 	drm_sysfs_connector_property_event(connector,
2743334f74eeSHans de Goede 					   connector->privacy_screen_sw_state_property);
27440cf8d292SSimon Ser 	drm_sysfs_connector_property_event(connector,
2745334f74eeSHans de Goede 					   connector->privacy_screen_hw_state_property);
2746334f74eeSHans de Goede 
2747334f74eeSHans de Goede 	return NOTIFY_DONE;
2748334f74eeSHans de Goede }
2749334f74eeSHans de Goede 
2750334f74eeSHans de Goede /**
2751334f74eeSHans de Goede  * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to
2752334f74eeSHans de Goede  *    the connector
2753334f74eeSHans de Goede  * @connector: connector to attach the privacy-screen to
2754334f74eeSHans de Goede  * @priv: drm_privacy_screen to attach
2755334f74eeSHans de Goede  *
2756334f74eeSHans de Goede  * Create and attach the standard privacy-screen properties and register
2757334f74eeSHans de Goede  * a generic notifier for generating sysfs-connector-status-events
2758334f74eeSHans de Goede  * on external changes to the privacy-screen status.
2759334f74eeSHans de Goede  * This function takes ownership of the passed in drm_privacy_screen and will
2760334f74eeSHans de Goede  * call drm_privacy_screen_put() on it when the connector is destroyed.
2761334f74eeSHans de Goede  */
2762334f74eeSHans de Goede void drm_connector_attach_privacy_screen_provider(
2763334f74eeSHans de Goede 	struct drm_connector *connector, struct drm_privacy_screen *priv)
2764334f74eeSHans de Goede {
2765334f74eeSHans de Goede 	connector->privacy_screen = priv;
2766334f74eeSHans de Goede 	connector->privacy_screen_notifier.notifier_call =
2767334f74eeSHans de Goede 		drm_connector_privacy_screen_notifier;
2768334f74eeSHans de Goede 
2769334f74eeSHans de Goede 	drm_connector_create_privacy_screen_properties(connector);
2770334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, true);
2771334f74eeSHans de Goede 	drm_connector_attach_privacy_screen_properties(connector);
2772334f74eeSHans de Goede }
2773334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider);
2774334f74eeSHans de Goede 
2775334f74eeSHans de Goede /**
2776334f74eeSHans de Goede  * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state
2777334f74eeSHans de Goede  * @connector_state: connector-state to update the privacy-screen for
2778334f74eeSHans de Goede  *
2779334f74eeSHans de Goede  * This function calls drm_privacy_screen_set_sw_state() on the connector's
2780334f74eeSHans de Goede  * privacy-screen.
2781334f74eeSHans de Goede  *
2782334f74eeSHans de Goede  * If the connector has no privacy-screen, then this is a no-op.
2783334f74eeSHans de Goede  */
2784334f74eeSHans de Goede void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state)
2785334f74eeSHans de Goede {
2786334f74eeSHans de Goede 	struct drm_connector *connector = connector_state->connector;
2787334f74eeSHans de Goede 	int ret;
2788334f74eeSHans de Goede 
2789334f74eeSHans de Goede 	if (!connector->privacy_screen)
2790334f74eeSHans de Goede 		return;
2791334f74eeSHans de Goede 
2792334f74eeSHans de Goede 	ret = drm_privacy_screen_set_sw_state(connector->privacy_screen,
2793334f74eeSHans de Goede 					      connector_state->privacy_screen_sw_state);
2794334f74eeSHans de Goede 	if (ret) {
2795334f74eeSHans de Goede 		drm_err(connector->dev, "Error updating privacy-screen sw_state\n");
2796334f74eeSHans de Goede 		return;
2797334f74eeSHans de Goede 	}
2798334f74eeSHans de Goede 
2799334f74eeSHans de Goede 	/* The hw_state property value may have changed, update it. */
2800334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, false);
2801334f74eeSHans de Goede }
2802334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_update_privacy_screen);
2803334f74eeSHans de Goede 
280497e14fbeSDaniel Vetter int drm_connector_set_obj_prop(struct drm_mode_object *obj,
280552217195SDaniel Vetter 				    struct drm_property *property,
280652217195SDaniel Vetter 				    uint64_t value)
280752217195SDaniel Vetter {
280852217195SDaniel Vetter 	int ret = -EINVAL;
280952217195SDaniel Vetter 	struct drm_connector *connector = obj_to_connector(obj);
281052217195SDaniel Vetter 
281152217195SDaniel Vetter 	/* Do DPMS ourselves */
281252217195SDaniel Vetter 	if (property == connector->dev->mode_config.dpms_property) {
281352217195SDaniel Vetter 		ret = (*connector->funcs->dpms)(connector, (int)value);
281452217195SDaniel Vetter 	} else if (connector->funcs->set_property)
281552217195SDaniel Vetter 		ret = connector->funcs->set_property(connector, property, value);
281652217195SDaniel Vetter 
2817144a7999SDaniel Vetter 	if (!ret)
281852217195SDaniel Vetter 		drm_object_property_set_value(&connector->base, property, value);
281952217195SDaniel Vetter 	return ret;
282052217195SDaniel Vetter }
282152217195SDaniel Vetter 
282297e14fbeSDaniel Vetter int drm_connector_property_set_ioctl(struct drm_device *dev,
282352217195SDaniel Vetter 				     void *data, struct drm_file *file_priv)
282452217195SDaniel Vetter {
282552217195SDaniel Vetter 	struct drm_mode_connector_set_property *conn_set_prop = data;
282652217195SDaniel Vetter 	struct drm_mode_obj_set_property obj_set_prop = {
282752217195SDaniel Vetter 		.value = conn_set_prop->value,
282852217195SDaniel Vetter 		.prop_id = conn_set_prop->prop_id,
282952217195SDaniel Vetter 		.obj_id = conn_set_prop->connector_id,
283052217195SDaniel Vetter 		.obj_type = DRM_MODE_OBJECT_CONNECTOR
283152217195SDaniel Vetter 	};
283252217195SDaniel Vetter 
283352217195SDaniel Vetter 	/* It does all the locking and checking we need */
283452217195SDaniel Vetter 	return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
283552217195SDaniel Vetter }
283652217195SDaniel Vetter 
283752217195SDaniel Vetter static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
283852217195SDaniel Vetter {
283952217195SDaniel Vetter 	/* For atomic drivers only state objects are synchronously updated and
2840c2ce66daSBeatriz Martins de Carvalho 	 * protected by modeset locks, so check those first.
2841c2ce66daSBeatriz Martins de Carvalho 	 */
284252217195SDaniel Vetter 	if (connector->state)
284352217195SDaniel Vetter 		return connector->state->best_encoder;
284452217195SDaniel Vetter 	return connector->encoder;
284552217195SDaniel Vetter }
284652217195SDaniel Vetter 
2847c3ff0cdbSAnkit Nautiyal static bool
2848c3ff0cdbSAnkit Nautiyal drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
28498445e2c5SVille Syrjälä 			     const struct list_head *modes,
285052217195SDaniel Vetter 			     const struct drm_file *file_priv)
285152217195SDaniel Vetter {
285252217195SDaniel Vetter 	/*
285352217195SDaniel Vetter 	 * If user-space hasn't configured the driver to expose the stereo 3D
285452217195SDaniel Vetter 	 * modes, don't expose them.
285552217195SDaniel Vetter 	 */
285652217195SDaniel Vetter 	if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
285752217195SDaniel Vetter 		return false;
2858c3ff0cdbSAnkit Nautiyal 	/*
2859c3ff0cdbSAnkit Nautiyal 	 * If user-space hasn't configured the driver to expose the modes
2860c3ff0cdbSAnkit Nautiyal 	 * with aspect-ratio, don't expose them. However if such a mode
2861c3ff0cdbSAnkit Nautiyal 	 * is unique, let it be exposed, but reset the aspect-ratio flags
2862c3ff0cdbSAnkit Nautiyal 	 * while preparing the list of user-modes.
2863c3ff0cdbSAnkit Nautiyal 	 */
2864c3ff0cdbSAnkit Nautiyal 	if (!file_priv->aspect_ratio_allowed) {
28658445e2c5SVille Syrjälä 		const struct drm_display_mode *mode_itr;
2866c3ff0cdbSAnkit Nautiyal 
28678445e2c5SVille Syrjälä 		list_for_each_entry(mode_itr, modes, head) {
28688445e2c5SVille Syrjälä 			if (mode_itr->expose_to_userspace &&
28698445e2c5SVille Syrjälä 			    drm_mode_match(mode_itr, mode,
2870c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_TIMINGS |
2871c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_CLOCK |
2872c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_FLAGS |
2873c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_3D_FLAGS))
2874c3ff0cdbSAnkit Nautiyal 				return false;
2875c3ff0cdbSAnkit Nautiyal 		}
28768445e2c5SVille Syrjälä 	}
287752217195SDaniel Vetter 
287852217195SDaniel Vetter 	return true;
287952217195SDaniel Vetter }
288052217195SDaniel Vetter 
288152217195SDaniel Vetter int drm_mode_getconnector(struct drm_device *dev, void *data,
288252217195SDaniel Vetter 			  struct drm_file *file_priv)
288352217195SDaniel Vetter {
288452217195SDaniel Vetter 	struct drm_mode_get_connector *out_resp = data;
288552217195SDaniel Vetter 	struct drm_connector *connector;
288652217195SDaniel Vetter 	struct drm_encoder *encoder;
288752217195SDaniel Vetter 	struct drm_display_mode *mode;
288852217195SDaniel Vetter 	int mode_count = 0;
288952217195SDaniel Vetter 	int encoders_count = 0;
289052217195SDaniel Vetter 	int ret = 0;
289152217195SDaniel Vetter 	int copied = 0;
289252217195SDaniel Vetter 	struct drm_mode_modeinfo u_mode;
289352217195SDaniel Vetter 	struct drm_mode_modeinfo __user *mode_ptr;
289452217195SDaniel Vetter 	uint32_t __user *encoder_ptr;
2895869e76f7SDesmond Cheong Zhi Xi 	bool is_current_master;
289652217195SDaniel Vetter 
289752217195SDaniel Vetter 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
289869fdf420SChris Wilson 		return -EOPNOTSUPP;
289952217195SDaniel Vetter 
290052217195SDaniel Vetter 	memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
290152217195SDaniel Vetter 
2902418da172SKeith Packard 	connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
290391eefc05SDaniel Vetter 	if (!connector)
290491eefc05SDaniel Vetter 		return -ENOENT;
290552217195SDaniel Vetter 
290662afb4adSJosé Roberto de Souza 	encoders_count = hweight32(connector->possible_encoders);
290791eefc05SDaniel Vetter 
290891eefc05SDaniel Vetter 	if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
290991eefc05SDaniel Vetter 		copied = 0;
291091eefc05SDaniel Vetter 		encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
291183aefbb8SVille Syrjälä 
291262afb4adSJosé Roberto de Souza 		drm_connector_for_each_possible_encoder(connector, encoder) {
291383aefbb8SVille Syrjälä 			if (put_user(encoder->base.id, encoder_ptr + copied)) {
291491eefc05SDaniel Vetter 				ret = -EFAULT;
2915e94ac351SDaniel Vetter 				goto out;
291691eefc05SDaniel Vetter 			}
291791eefc05SDaniel Vetter 			copied++;
291891eefc05SDaniel Vetter 		}
291991eefc05SDaniel Vetter 	}
292091eefc05SDaniel Vetter 	out_resp->count_encoders = encoders_count;
292191eefc05SDaniel Vetter 
292291eefc05SDaniel Vetter 	out_resp->connector_id = connector->base.id;
292391eefc05SDaniel Vetter 	out_resp->connector_type = connector->connector_type;
292491eefc05SDaniel Vetter 	out_resp->connector_type_id = connector->connector_type_id;
292591eefc05SDaniel Vetter 
2926869e76f7SDesmond Cheong Zhi Xi 	is_current_master = drm_is_current_master(file_priv);
2927869e76f7SDesmond Cheong Zhi Xi 
292891eefc05SDaniel Vetter 	mutex_lock(&dev->mode_config.mutex);
292991eefc05SDaniel Vetter 	if (out_resp->count_modes == 0) {
2930869e76f7SDesmond Cheong Zhi Xi 		if (is_current_master)
293191eefc05SDaniel Vetter 			connector->funcs->fill_modes(connector,
293291eefc05SDaniel Vetter 						     dev->mode_config.max_width,
293391eefc05SDaniel Vetter 						     dev->mode_config.max_height);
29348f86c82aSSimon Ser 		else
29358f86c82aSSimon 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",
29368f86c82aSSimon Ser 				    connector->base.id, connector->name);
293791eefc05SDaniel Vetter 	}
293891eefc05SDaniel Vetter 
293991eefc05SDaniel Vetter 	out_resp->mm_width = connector->display_info.width_mm;
294091eefc05SDaniel Vetter 	out_resp->mm_height = connector->display_info.height_mm;
294191eefc05SDaniel Vetter 	out_resp->subpixel = connector->display_info.subpixel_order;
294291eefc05SDaniel Vetter 	out_resp->connection = connector->status;
294391eefc05SDaniel Vetter 
294491eefc05SDaniel Vetter 	/* delayed so we get modes regardless of pre-fill_modes state */
29458445e2c5SVille Syrjälä 	list_for_each_entry(mode, &connector->modes, head) {
29468445e2c5SVille Syrjälä 		WARN_ON(mode->expose_to_userspace);
29478445e2c5SVille Syrjälä 
29488445e2c5SVille Syrjälä 		if (drm_mode_expose_to_userspace(mode, &connector->modes,
2949c3ff0cdbSAnkit Nautiyal 						 file_priv)) {
29508445e2c5SVille Syrjälä 			mode->expose_to_userspace = true;
295191eefc05SDaniel Vetter 			mode_count++;
2952c3ff0cdbSAnkit Nautiyal 		}
29538445e2c5SVille Syrjälä 	}
295491eefc05SDaniel Vetter 
295552217195SDaniel Vetter 	/*
295652217195SDaniel Vetter 	 * This ioctl is called twice, once to determine how much space is
295752217195SDaniel Vetter 	 * needed, and the 2nd time to fill it.
295852217195SDaniel Vetter 	 */
295952217195SDaniel Vetter 	if ((out_resp->count_modes >= mode_count) && mode_count) {
296052217195SDaniel Vetter 		copied = 0;
296152217195SDaniel Vetter 		mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
29628445e2c5SVille Syrjälä 		list_for_each_entry(mode, &connector->modes, head) {
29638445e2c5SVille Syrjälä 			if (!mode->expose_to_userspace)
29648445e2c5SVille Syrjälä 				continue;
29658445e2c5SVille Syrjälä 
29668445e2c5SVille Syrjälä 			/* Clear the tag for the next time around */
29678445e2c5SVille Syrjälä 			mode->expose_to_userspace = false;
29688445e2c5SVille Syrjälä 
296952217195SDaniel Vetter 			drm_mode_convert_to_umode(&u_mode, mode);
2970c3ff0cdbSAnkit Nautiyal 			/*
2971c3ff0cdbSAnkit Nautiyal 			 * Reset aspect ratio flags of user-mode, if modes with
2972c3ff0cdbSAnkit Nautiyal 			 * aspect-ratio are not supported.
2973c3ff0cdbSAnkit Nautiyal 			 */
2974c3ff0cdbSAnkit Nautiyal 			if (!file_priv->aspect_ratio_allowed)
2975c3ff0cdbSAnkit Nautiyal 				u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
297652217195SDaniel Vetter 			if (copy_to_user(mode_ptr + copied,
297752217195SDaniel Vetter 					 &u_mode, sizeof(u_mode))) {
297852217195SDaniel Vetter 				ret = -EFAULT;
29798445e2c5SVille Syrjälä 
29808445e2c5SVille Syrjälä 				/*
29818445e2c5SVille Syrjälä 				 * Clear the tag for the rest of
29828445e2c5SVille Syrjälä 				 * the modes for the next time around.
29838445e2c5SVille Syrjälä 				 */
29848445e2c5SVille Syrjälä 				list_for_each_entry_continue(mode, &connector->modes, head)
29858445e2c5SVille Syrjälä 					mode->expose_to_userspace = false;
29868445e2c5SVille Syrjälä 
2987e94ac351SDaniel Vetter 				mutex_unlock(&dev->mode_config.mutex);
2988e94ac351SDaniel Vetter 
298952217195SDaniel Vetter 				goto out;
299052217195SDaniel Vetter 			}
299152217195SDaniel Vetter 			copied++;
299252217195SDaniel Vetter 		}
29938445e2c5SVille Syrjälä 	} else {
29948445e2c5SVille Syrjälä 		/* Clear the tag for the next time around */
29958445e2c5SVille Syrjälä 		list_for_each_entry(mode, &connector->modes, head)
29968445e2c5SVille Syrjälä 			mode->expose_to_userspace = false;
299752217195SDaniel Vetter 	}
29988445e2c5SVille Syrjälä 
299952217195SDaniel Vetter 	out_resp->count_modes = mode_count;
300052217195SDaniel Vetter 	mutex_unlock(&dev->mode_config.mutex);
3001e94ac351SDaniel Vetter 
3002e94ac351SDaniel Vetter 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
3003e94ac351SDaniel Vetter 	encoder = drm_connector_get_encoder(connector);
3004e94ac351SDaniel Vetter 	if (encoder)
3005e94ac351SDaniel Vetter 		out_resp->encoder_id = encoder->base.id;
3006e94ac351SDaniel Vetter 	else
3007e94ac351SDaniel Vetter 		out_resp->encoder_id = 0;
3008e94ac351SDaniel Vetter 
3009e94ac351SDaniel Vetter 	/* Only grab properties after probing, to make sure EDID and other
3010c2ce66daSBeatriz Martins de Carvalho 	 * properties reflect the latest status.
3011c2ce66daSBeatriz Martins de Carvalho 	 */
3012e94ac351SDaniel Vetter 	ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
3013e94ac351SDaniel Vetter 			(uint32_t __user *)(unsigned long)(out_resp->props_ptr),
3014e94ac351SDaniel Vetter 			(uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
3015e94ac351SDaniel Vetter 			&out_resp->count_props);
3016e94ac351SDaniel Vetter 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
3017e94ac351SDaniel Vetter 
3018e94ac351SDaniel Vetter out:
3019ad093607SThierry Reding 	drm_connector_put(connector);
302052217195SDaniel Vetter 
302152217195SDaniel Vetter 	return ret;
302252217195SDaniel Vetter }
302352217195SDaniel Vetter 
30243d3f7c1eSHans de Goede /**
30253d3f7c1eSHans de Goede  * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode
30263d3f7c1eSHans de Goede  * @fwnode: fwnode for which to find the matching drm_connector
30273d3f7c1eSHans de Goede  *
30283d3f7c1eSHans de Goede  * This functions looks up a drm_connector based on its associated fwnode. When
30293d3f7c1eSHans de Goede  * a connector is found a reference to the connector is returned. The caller must
30303d3f7c1eSHans de Goede  * call drm_connector_put() to release this reference when it is done with the
30313d3f7c1eSHans de Goede  * connector.
30323d3f7c1eSHans de Goede  *
30333d3f7c1eSHans de Goede  * Returns: A reference to the found connector or an ERR_PTR().
30343d3f7c1eSHans de Goede  */
30353d3f7c1eSHans de Goede struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode)
30363d3f7c1eSHans de Goede {
30373d3f7c1eSHans de Goede 	struct drm_connector *connector, *found = ERR_PTR(-ENODEV);
30383d3f7c1eSHans de Goede 
30393d3f7c1eSHans de Goede 	if (!fwnode)
30403d3f7c1eSHans de Goede 		return ERR_PTR(-ENODEV);
30413d3f7c1eSHans de Goede 
30423d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
30433d3f7c1eSHans de Goede 
30443d3f7c1eSHans de Goede 	list_for_each_entry(connector, &connector_list, global_connector_list_entry) {
30453d3f7c1eSHans de Goede 		if (connector->fwnode == fwnode ||
30463d3f7c1eSHans de Goede 		    (connector->fwnode && connector->fwnode->secondary == fwnode)) {
30473d3f7c1eSHans de Goede 			drm_connector_get(connector);
30483d3f7c1eSHans de Goede 			found = connector;
30493d3f7c1eSHans de Goede 			break;
30503d3f7c1eSHans de Goede 		}
30513d3f7c1eSHans de Goede 	}
30523d3f7c1eSHans de Goede 
30533d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
30543d3f7c1eSHans de Goede 
30553d3f7c1eSHans de Goede 	return found;
30563d3f7c1eSHans de Goede }
30573d3f7c1eSHans de Goede 
305872ad4968SHans de Goede /**
305972ad4968SHans de Goede  * drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector
3060f85d9e59SRandy Dunlap  * @connector_fwnode: fwnode_handle to report the event on
306172ad4968SHans de Goede  *
306272ad4968SHans de Goede  * On some hardware a hotplug event notification may come from outside the display
306372ad4968SHans de Goede  * driver / device. An example of this is some USB Type-C setups where the hardware
306472ad4968SHans de Goede  * muxes the DisplayPort data and aux-lines but does not pass the altmode HPD
306572ad4968SHans de Goede  * status bit to the GPU's DP HPD pin.
306672ad4968SHans de Goede  *
306772ad4968SHans de Goede  * This function can be used to report these out-of-band events after obtaining
306872ad4968SHans de Goede  * a drm_connector reference through calling drm_connector_find_by_fwnode().
306972ad4968SHans de Goede  */
307072ad4968SHans de Goede void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode)
307172ad4968SHans de Goede {
307272ad4968SHans de Goede 	struct drm_connector *connector;
307372ad4968SHans de Goede 
307472ad4968SHans de Goede 	connector = drm_connector_find_by_fwnode(connector_fwnode);
307572ad4968SHans de Goede 	if (IS_ERR(connector))
307672ad4968SHans de Goede 		return;
307772ad4968SHans de Goede 
307872ad4968SHans de Goede 	if (connector->funcs->oob_hotplug_event)
307972ad4968SHans de Goede 		connector->funcs->oob_hotplug_event(connector);
308072ad4968SHans de Goede 
308172ad4968SHans de Goede 	drm_connector_put(connector);
308272ad4968SHans de Goede }
308372ad4968SHans de Goede EXPORT_SYMBOL(drm_connector_oob_hotplug_event);
308472ad4968SHans de Goede 
30859498c19bSDaniel Vetter 
30869498c19bSDaniel Vetter /**
30879498c19bSDaniel Vetter  * DOC: Tile group
30889498c19bSDaniel Vetter  *
30899498c19bSDaniel Vetter  * Tile groups are used to represent tiled monitors with a unique integer
30909498c19bSDaniel Vetter  * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
30919498c19bSDaniel Vetter  * we store this in a tile group, so we have a common identifier for all tiles
30929498c19bSDaniel Vetter  * in a monitor group. The property is called "TILE". Drivers can manage tile
30939498c19bSDaniel Vetter  * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
30949498c19bSDaniel Vetter  * drm_mode_get_tile_group(). But this is only needed for internal panels where
30959498c19bSDaniel Vetter  * the tile group information is exposed through a non-standard way.
30969498c19bSDaniel Vetter  */
30979498c19bSDaniel Vetter 
30989498c19bSDaniel Vetter static void drm_tile_group_free(struct kref *kref)
30999498c19bSDaniel Vetter {
31009498c19bSDaniel Vetter 	struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
31019498c19bSDaniel Vetter 	struct drm_device *dev = tg->dev;
3102948de842SSuraj Upadhyay 
31039498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
31049498c19bSDaniel Vetter 	idr_remove(&dev->mode_config.tile_idr, tg->id);
31059498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
31069498c19bSDaniel Vetter 	kfree(tg);
31079498c19bSDaniel Vetter }
31089498c19bSDaniel Vetter 
31099498c19bSDaniel Vetter /**
31109498c19bSDaniel Vetter  * drm_mode_put_tile_group - drop a reference to a tile group.
31119498c19bSDaniel Vetter  * @dev: DRM device
31129498c19bSDaniel Vetter  * @tg: tile group to drop reference to.
31139498c19bSDaniel Vetter  *
31149498c19bSDaniel Vetter  * drop reference to tile group and free if 0.
31159498c19bSDaniel Vetter  */
31169498c19bSDaniel Vetter void drm_mode_put_tile_group(struct drm_device *dev,
31179498c19bSDaniel Vetter 			     struct drm_tile_group *tg)
31189498c19bSDaniel Vetter {
31199498c19bSDaniel Vetter 	kref_put(&tg->refcount, drm_tile_group_free);
31209498c19bSDaniel Vetter }
31219498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_put_tile_group);
31229498c19bSDaniel Vetter 
31239498c19bSDaniel Vetter /**
31249498c19bSDaniel Vetter  * drm_mode_get_tile_group - get a reference to an existing tile group
31259498c19bSDaniel Vetter  * @dev: DRM device
31269498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
31279498c19bSDaniel Vetter  *
31289498c19bSDaniel Vetter  * Use the unique bytes to get a reference to an existing tile group.
31299498c19bSDaniel Vetter  *
31309498c19bSDaniel Vetter  * RETURNS:
31319498c19bSDaniel Vetter  * tile group or NULL if not found.
31329498c19bSDaniel Vetter  */
31339498c19bSDaniel Vetter struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
3134267ea759SVille Syrjälä 					       const char topology[8])
31359498c19bSDaniel Vetter {
31369498c19bSDaniel Vetter 	struct drm_tile_group *tg;
31379498c19bSDaniel Vetter 	int id;
3138948de842SSuraj Upadhyay 
31399498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
31409498c19bSDaniel Vetter 	idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
31419498c19bSDaniel Vetter 		if (!memcmp(tg->group_data, topology, 8)) {
31429498c19bSDaniel Vetter 			if (!kref_get_unless_zero(&tg->refcount))
31439498c19bSDaniel Vetter 				tg = NULL;
31449498c19bSDaniel Vetter 			mutex_unlock(&dev->mode_config.idr_mutex);
31459498c19bSDaniel Vetter 			return tg;
31469498c19bSDaniel Vetter 		}
31479498c19bSDaniel Vetter 	}
31489498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
31499498c19bSDaniel Vetter 	return NULL;
31509498c19bSDaniel Vetter }
31519498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_get_tile_group);
31529498c19bSDaniel Vetter 
31539498c19bSDaniel Vetter /**
31549498c19bSDaniel Vetter  * drm_mode_create_tile_group - create a tile group from a displayid description
31559498c19bSDaniel Vetter  * @dev: DRM device
31569498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
31579498c19bSDaniel Vetter  *
31589498c19bSDaniel Vetter  * Create a tile group for the unique monitor, and get a unique
31599498c19bSDaniel Vetter  * identifier for the tile group.
31609498c19bSDaniel Vetter  *
31619498c19bSDaniel Vetter  * RETURNS:
3162705c8160SDan Carpenter  * new tile group or NULL.
31639498c19bSDaniel Vetter  */
31649498c19bSDaniel Vetter struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
3165267ea759SVille Syrjälä 						  const char topology[8])
31669498c19bSDaniel Vetter {
31679498c19bSDaniel Vetter 	struct drm_tile_group *tg;
31689498c19bSDaniel Vetter 	int ret;
31699498c19bSDaniel Vetter 
31709498c19bSDaniel Vetter 	tg = kzalloc(sizeof(*tg), GFP_KERNEL);
31719498c19bSDaniel Vetter 	if (!tg)
3172705c8160SDan Carpenter 		return NULL;
31739498c19bSDaniel Vetter 
31749498c19bSDaniel Vetter 	kref_init(&tg->refcount);
31759498c19bSDaniel Vetter 	memcpy(tg->group_data, topology, 8);
31769498c19bSDaniel Vetter 	tg->dev = dev;
31779498c19bSDaniel Vetter 
31789498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
31799498c19bSDaniel Vetter 	ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
31809498c19bSDaniel Vetter 	if (ret >= 0) {
31819498c19bSDaniel Vetter 		tg->id = ret;
31829498c19bSDaniel Vetter 	} else {
31839498c19bSDaniel Vetter 		kfree(tg);
3184705c8160SDan Carpenter 		tg = NULL;
31859498c19bSDaniel Vetter 	}
31869498c19bSDaniel Vetter 
31879498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
31889498c19bSDaniel Vetter 	return tg;
31899498c19bSDaniel Vetter }
31909498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tile_group);
3191