xref: /linux/drivers/gpu/drm/drm_connector.c (revision f592e01664b4a57b109fcf6f6916145517f94bd7)
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);
281f378b772SMaxime Ripard 	mutex_init(&connector->hdmi.infoframes.lock);
28252217195SDaniel Vetter 	connector->edid_blob_ptr = NULL;
2835186421cSStanislav Lisovskiy 	connector->epoch_counter = 0;
2842de3a078SManasi Navare 	connector->tile_blob_ptr = NULL;
28552217195SDaniel Vetter 	connector->status = connector_status_unknown;
2868d70f395SHans de Goede 	connector->display_info.panel_orientation =
2878d70f395SHans de Goede 		DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
28852217195SDaniel Vetter 
28952217195SDaniel Vetter 	drm_connector_get_cmdline_mode(connector);
29052217195SDaniel Vetter 
29152217195SDaniel Vetter 	/* We should add connectors at the end to avoid upsetting the connector
292c2ce66daSBeatriz Martins de Carvalho 	 * index too much.
293c2ce66daSBeatriz Martins de Carvalho 	 */
294613051daSDaniel Vetter 	spin_lock_irq(&config->connector_list_lock);
29552217195SDaniel Vetter 	list_add_tail(&connector->head, &config->connector_list);
29652217195SDaniel Vetter 	config->num_connector++;
297613051daSDaniel Vetter 	spin_unlock_irq(&config->connector_list_lock);
29852217195SDaniel Vetter 
299935774cdSBrian Starkey 	if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
300935774cdSBrian Starkey 	    connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
3016b7e2d5cSGerd Hoffmann 		drm_connector_attach_edid_property(connector);
30252217195SDaniel Vetter 
30352217195SDaniel Vetter 	drm_object_attach_property(&connector->base,
30452217195SDaniel Vetter 				      config->dpms_property, 0);
30552217195SDaniel Vetter 
30640ee6fbeSManasi Navare 	drm_object_attach_property(&connector->base,
30740ee6fbeSManasi Navare 				   config->link_status_property,
30840ee6fbeSManasi Navare 				   0);
30940ee6fbeSManasi Navare 
31066660d4cSDave Airlie 	drm_object_attach_property(&connector->base,
31166660d4cSDave Airlie 				   config->non_desktop_property,
31266660d4cSDave Airlie 				   0);
3132de3a078SManasi Navare 	drm_object_attach_property(&connector->base,
3142de3a078SManasi Navare 				   config->tile_property,
3152de3a078SManasi Navare 				   0);
31666660d4cSDave Airlie 
31752217195SDaniel Vetter 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
31852217195SDaniel Vetter 		drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
31952217195SDaniel Vetter 	}
32052217195SDaniel Vetter 
32152217195SDaniel Vetter 	connector->debugfs_entry = NULL;
32252217195SDaniel Vetter out_put_type_id:
32352217195SDaniel Vetter 	if (ret)
324e5d6eeeaSBo Liu 		ida_free(connector_ida, connector->connector_type_id);
32552217195SDaniel Vetter out_put_id:
32652217195SDaniel Vetter 	if (ret)
327e5d6eeeaSBo Liu 		ida_free(&config->connector_ida, connector->index);
32852217195SDaniel Vetter out_put:
32952217195SDaniel Vetter 	if (ret)
33052217195SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
33152217195SDaniel Vetter 
33252217195SDaniel Vetter 	return ret;
33352217195SDaniel Vetter }
334b11af8a2SMaxime Ripard 
335b11af8a2SMaxime Ripard /**
336b11af8a2SMaxime Ripard  * drm_connector_init - Init a preallocated connector
337b11af8a2SMaxime Ripard  * @dev: DRM device
338b11af8a2SMaxime Ripard  * @connector: the connector to init
339b11af8a2SMaxime Ripard  * @funcs: callbacks for this connector
340b11af8a2SMaxime Ripard  * @connector_type: user visible type of the connector
341b11af8a2SMaxime Ripard  *
342b11af8a2SMaxime Ripard  * Initialises a preallocated connector. Connectors should be
343b11af8a2SMaxime Ripard  * subclassed as part of driver connector objects.
344b11af8a2SMaxime Ripard  *
345b11af8a2SMaxime Ripard  * At driver unload time the driver's &drm_connector_funcs.destroy hook
346b11af8a2SMaxime Ripard  * should call drm_connector_cleanup() and free the connector structure.
347b11af8a2SMaxime Ripard  * The connector structure should not be allocated with devm_kzalloc().
348b11af8a2SMaxime Ripard  *
34935a3b82fSMaxime Ripard  * Note: consider using drmm_connector_init() instead of
35035a3b82fSMaxime Ripard  * drm_connector_init() to let the DRM managed resource infrastructure
35135a3b82fSMaxime Ripard  * take care of cleanup and deallocation.
35235a3b82fSMaxime Ripard  *
353b11af8a2SMaxime Ripard  * Returns:
354b11af8a2SMaxime Ripard  * Zero on success, error code on failure.
355b11af8a2SMaxime Ripard  */
356b11af8a2SMaxime Ripard int drm_connector_init(struct drm_device *dev,
357b11af8a2SMaxime Ripard 		       struct drm_connector *connector,
358b11af8a2SMaxime Ripard 		       const struct drm_connector_funcs *funcs,
359b11af8a2SMaxime Ripard 		       int connector_type)
360b11af8a2SMaxime Ripard {
361a961b197SMaxime Ripard 	if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
362a961b197SMaxime Ripard 		return -EINVAL;
363a961b197SMaxime Ripard 
364b11af8a2SMaxime Ripard 	return __drm_connector_init(dev, connector, funcs, connector_type, NULL);
365b11af8a2SMaxime Ripard }
36652217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_init);
36752217195SDaniel Vetter 
36852217195SDaniel Vetter /**
369100163dfSAndrzej Pietrasiewicz  * drm_connector_init_with_ddc - Init a preallocated connector
370100163dfSAndrzej Pietrasiewicz  * @dev: DRM device
371100163dfSAndrzej Pietrasiewicz  * @connector: the connector to init
372100163dfSAndrzej Pietrasiewicz  * @funcs: callbacks for this connector
373100163dfSAndrzej Pietrasiewicz  * @connector_type: user visible type of the connector
374100163dfSAndrzej Pietrasiewicz  * @ddc: pointer to the associated ddc adapter
375100163dfSAndrzej Pietrasiewicz  *
376100163dfSAndrzej Pietrasiewicz  * Initialises a preallocated connector. Connectors should be
377100163dfSAndrzej Pietrasiewicz  * subclassed as part of driver connector objects.
378100163dfSAndrzej Pietrasiewicz  *
37900ec947cSMaxime Ripard  * At driver unload time the driver's &drm_connector_funcs.destroy hook
38000ec947cSMaxime Ripard  * should call drm_connector_cleanup() and free the connector structure.
38100ec947cSMaxime Ripard  * The connector structure should not be allocated with devm_kzalloc().
38200ec947cSMaxime Ripard  *
383100163dfSAndrzej Pietrasiewicz  * Ensures that the ddc field of the connector is correctly set.
384100163dfSAndrzej Pietrasiewicz  *
38535a3b82fSMaxime Ripard  * Note: consider using drmm_connector_init() instead of
38635a3b82fSMaxime Ripard  * drm_connector_init_with_ddc() to let the DRM managed resource
38735a3b82fSMaxime Ripard  * infrastructure take care of cleanup and deallocation.
38835a3b82fSMaxime Ripard  *
389100163dfSAndrzej Pietrasiewicz  * Returns:
390100163dfSAndrzej Pietrasiewicz  * Zero on success, error code on failure.
391100163dfSAndrzej Pietrasiewicz  */
392100163dfSAndrzej Pietrasiewicz int drm_connector_init_with_ddc(struct drm_device *dev,
393100163dfSAndrzej Pietrasiewicz 				struct drm_connector *connector,
394100163dfSAndrzej Pietrasiewicz 				const struct drm_connector_funcs *funcs,
395100163dfSAndrzej Pietrasiewicz 				int connector_type,
396100163dfSAndrzej Pietrasiewicz 				struct i2c_adapter *ddc)
397100163dfSAndrzej Pietrasiewicz {
398a961b197SMaxime Ripard 	if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
399a961b197SMaxime Ripard 		return -EINVAL;
400a961b197SMaxime Ripard 
401b11af8a2SMaxime Ripard 	return __drm_connector_init(dev, connector, funcs, connector_type, ddc);
402100163dfSAndrzej Pietrasiewicz }
403100163dfSAndrzej Pietrasiewicz EXPORT_SYMBOL(drm_connector_init_with_ddc);
404100163dfSAndrzej Pietrasiewicz 
40535a3b82fSMaxime Ripard static void drm_connector_cleanup_action(struct drm_device *dev,
40635a3b82fSMaxime Ripard 					 void *ptr)
40735a3b82fSMaxime Ripard {
40835a3b82fSMaxime Ripard 	struct drm_connector *connector = ptr;
40935a3b82fSMaxime Ripard 
41035a3b82fSMaxime Ripard 	drm_connector_cleanup(connector);
41135a3b82fSMaxime Ripard }
41235a3b82fSMaxime Ripard 
41335a3b82fSMaxime Ripard /**
41435a3b82fSMaxime Ripard  * drmm_connector_init - Init a preallocated connector
41535a3b82fSMaxime Ripard  * @dev: DRM device
41635a3b82fSMaxime Ripard  * @connector: the connector to init
41735a3b82fSMaxime Ripard  * @funcs: callbacks for this connector
41835a3b82fSMaxime Ripard  * @connector_type: user visible type of the connector
41935a3b82fSMaxime Ripard  * @ddc: optional pointer to the associated ddc adapter
42035a3b82fSMaxime Ripard  *
42135a3b82fSMaxime Ripard  * Initialises a preallocated connector. Connectors should be
42235a3b82fSMaxime Ripard  * subclassed as part of driver connector objects.
42335a3b82fSMaxime Ripard  *
42435a3b82fSMaxime Ripard  * Cleanup is automatically handled with a call to
42535a3b82fSMaxime Ripard  * drm_connector_cleanup() in a DRM-managed action.
42635a3b82fSMaxime Ripard  *
42735a3b82fSMaxime Ripard  * The connector structure should be allocated with drmm_kzalloc().
42835a3b82fSMaxime Ripard  *
42935a3b82fSMaxime Ripard  * Returns:
43035a3b82fSMaxime Ripard  * Zero on success, error code on failure.
43135a3b82fSMaxime Ripard  */
43235a3b82fSMaxime Ripard int drmm_connector_init(struct drm_device *dev,
43335a3b82fSMaxime Ripard 			struct drm_connector *connector,
43435a3b82fSMaxime Ripard 			const struct drm_connector_funcs *funcs,
43535a3b82fSMaxime Ripard 			int connector_type,
43635a3b82fSMaxime Ripard 			struct i2c_adapter *ddc)
43735a3b82fSMaxime Ripard {
43835a3b82fSMaxime Ripard 	int ret;
43935a3b82fSMaxime Ripard 
44035a3b82fSMaxime Ripard 	if (drm_WARN_ON(dev, funcs && funcs->destroy))
44135a3b82fSMaxime Ripard 		return -EINVAL;
44235a3b82fSMaxime Ripard 
443a91e5e3eSMaxime Ripard 	ret = __drm_connector_init(dev, connector, funcs, connector_type, ddc);
44435a3b82fSMaxime Ripard 	if (ret)
44535a3b82fSMaxime Ripard 		return ret;
44635a3b82fSMaxime Ripard 
44735a3b82fSMaxime Ripard 	ret = drmm_add_action_or_reset(dev, drm_connector_cleanup_action,
44835a3b82fSMaxime Ripard 				       connector);
44935a3b82fSMaxime Ripard 	if (ret)
45035a3b82fSMaxime Ripard 		return ret;
45135a3b82fSMaxime Ripard 
45235a3b82fSMaxime Ripard 	return 0;
45335a3b82fSMaxime Ripard }
45435a3b82fSMaxime Ripard EXPORT_SYMBOL(drmm_connector_init);
45535a3b82fSMaxime Ripard 
456100163dfSAndrzej Pietrasiewicz /**
457582d79f3SMaxime Ripard  * drmm_connector_hdmi_init - Init a preallocated HDMI connector
458582d79f3SMaxime Ripard  * @dev: DRM device
459582d79f3SMaxime Ripard  * @connector: A pointer to the HDMI connector to init
460f378b772SMaxime Ripard  * @vendor: HDMI Controller Vendor name
461f378b772SMaxime Ripard  * @product: HDMI Controller Product name
462582d79f3SMaxime Ripard  * @funcs: callbacks for this connector
463e5030a74SMaxime Ripard  * @hdmi_funcs: HDMI-related callbacks for this connector
464582d79f3SMaxime Ripard  * @connector_type: user visible type of the connector
465582d79f3SMaxime Ripard  * @ddc: optional pointer to the associated ddc adapter
466948f01d5SMaxime Ripard  * @supported_formats: Bitmask of @hdmi_colorspace listing supported output formats
467aadb3e16SMaxime Ripard  * @max_bpc: Maximum bits per char the HDMI connector supports
468582d79f3SMaxime Ripard  *
469582d79f3SMaxime Ripard  * Initialises a preallocated HDMI connector. Connectors can be
470582d79f3SMaxime Ripard  * subclassed as part of driver connector objects.
471582d79f3SMaxime Ripard  *
472582d79f3SMaxime Ripard  * Cleanup is automatically handled with a call to
473582d79f3SMaxime Ripard  * drm_connector_cleanup() in a DRM-managed action.
474582d79f3SMaxime Ripard  *
475582d79f3SMaxime Ripard  * The connector structure should be allocated with drmm_kzalloc().
476582d79f3SMaxime Ripard  *
477582d79f3SMaxime Ripard  * Returns:
478582d79f3SMaxime Ripard  * Zero on success, error code on failure.
479582d79f3SMaxime Ripard  */
480582d79f3SMaxime Ripard int drmm_connector_hdmi_init(struct drm_device *dev,
481582d79f3SMaxime Ripard 			     struct drm_connector *connector,
482f378b772SMaxime Ripard 			     const char *vendor, const char *product,
483582d79f3SMaxime Ripard 			     const struct drm_connector_funcs *funcs,
484e5030a74SMaxime Ripard 			     const struct drm_connector_hdmi_funcs *hdmi_funcs,
485582d79f3SMaxime Ripard 			     int connector_type,
486aadb3e16SMaxime Ripard 			     struct i2c_adapter *ddc,
487948f01d5SMaxime Ripard 			     unsigned long supported_formats,
488aadb3e16SMaxime Ripard 			     unsigned int max_bpc)
489582d79f3SMaxime Ripard {
490582d79f3SMaxime Ripard 	int ret;
491582d79f3SMaxime Ripard 
492f378b772SMaxime Ripard 	if (!vendor || !product)
493f378b772SMaxime Ripard 		return -EINVAL;
494f378b772SMaxime Ripard 
495f378b772SMaxime Ripard 	if ((strlen(vendor) > DRM_CONNECTOR_HDMI_VENDOR_LEN) ||
496f378b772SMaxime Ripard 	    (strlen(product) > DRM_CONNECTOR_HDMI_PRODUCT_LEN))
497f378b772SMaxime Ripard 		return -EINVAL;
498f378b772SMaxime Ripard 
499582d79f3SMaxime Ripard 	if (!(connector_type == DRM_MODE_CONNECTOR_HDMIA ||
500582d79f3SMaxime Ripard 	      connector_type == DRM_MODE_CONNECTOR_HDMIB))
501582d79f3SMaxime Ripard 		return -EINVAL;
502582d79f3SMaxime Ripard 
503948f01d5SMaxime Ripard 	if (!supported_formats || !(supported_formats & BIT(HDMI_COLORSPACE_RGB)))
504948f01d5SMaxime Ripard 		return -EINVAL;
505948f01d5SMaxime Ripard 
506aadb3e16SMaxime Ripard 	if (!(max_bpc == 8 || max_bpc == 10 || max_bpc == 12))
507aadb3e16SMaxime Ripard 		return -EINVAL;
508aadb3e16SMaxime Ripard 
509582d79f3SMaxime Ripard 	ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc);
510582d79f3SMaxime Ripard 	if (ret)
511582d79f3SMaxime Ripard 		return ret;
512582d79f3SMaxime Ripard 
513948f01d5SMaxime Ripard 	connector->hdmi.supported_formats = supported_formats;
514f378b772SMaxime Ripard 	strtomem_pad(connector->hdmi.vendor, vendor, 0);
515f378b772SMaxime Ripard 	strtomem_pad(connector->hdmi.product, product, 0);
516948f01d5SMaxime Ripard 
517aadb3e16SMaxime Ripard 	/*
518aadb3e16SMaxime Ripard 	 * drm_connector_attach_max_bpc_property() requires the
519aadb3e16SMaxime Ripard 	 * connector to have a state.
520aadb3e16SMaxime Ripard 	 */
521aadb3e16SMaxime Ripard 	if (connector->funcs->reset)
522aadb3e16SMaxime Ripard 		connector->funcs->reset(connector);
523aadb3e16SMaxime Ripard 
524aadb3e16SMaxime Ripard 	drm_connector_attach_max_bpc_property(connector, 8, max_bpc);
525aadb3e16SMaxime Ripard 	connector->max_bpc = max_bpc;
526aadb3e16SMaxime Ripard 
527aadb3e16SMaxime Ripard 	if (max_bpc > 8)
528aadb3e16SMaxime Ripard 		drm_connector_attach_hdr_output_metadata_property(connector);
529aadb3e16SMaxime Ripard 
530e5030a74SMaxime Ripard 	connector->hdmi.funcs = hdmi_funcs;
531e5030a74SMaxime Ripard 
532582d79f3SMaxime Ripard 	return 0;
533582d79f3SMaxime Ripard }
534582d79f3SMaxime Ripard EXPORT_SYMBOL(drmm_connector_hdmi_init);
535582d79f3SMaxime Ripard 
536582d79f3SMaxime Ripard /**
5376b7e2d5cSGerd Hoffmann  * drm_connector_attach_edid_property - attach edid property.
5386b7e2d5cSGerd Hoffmann  * @connector: the connector
5396b7e2d5cSGerd Hoffmann  *
5406b7e2d5cSGerd Hoffmann  * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
5416b7e2d5cSGerd Hoffmann  * edid property attached by default.  This function can be used to
5426b7e2d5cSGerd Hoffmann  * explicitly enable the edid property in these cases.
5436b7e2d5cSGerd Hoffmann  */
5446b7e2d5cSGerd Hoffmann void drm_connector_attach_edid_property(struct drm_connector *connector)
5456b7e2d5cSGerd Hoffmann {
5466b7e2d5cSGerd Hoffmann 	struct drm_mode_config *config = &connector->dev->mode_config;
5476b7e2d5cSGerd Hoffmann 
5486b7e2d5cSGerd Hoffmann 	drm_object_attach_property(&connector->base,
5496b7e2d5cSGerd Hoffmann 				   config->edid_property,
5506b7e2d5cSGerd Hoffmann 				   0);
5516b7e2d5cSGerd Hoffmann }
5526b7e2d5cSGerd Hoffmann EXPORT_SYMBOL(drm_connector_attach_edid_property);
5536b7e2d5cSGerd Hoffmann 
5546b7e2d5cSGerd Hoffmann /**
555cde4c44dSDaniel Vetter  * drm_connector_attach_encoder - attach a connector to an encoder
55652217195SDaniel Vetter  * @connector: connector to attach
55752217195SDaniel Vetter  * @encoder: encoder to attach @connector to
55852217195SDaniel Vetter  *
55952217195SDaniel Vetter  * This function links up a connector to an encoder. Note that the routing
56052217195SDaniel Vetter  * restrictions between encoders and crtcs are exposed to userspace through the
56152217195SDaniel Vetter  * possible_clones and possible_crtcs bitmasks.
56252217195SDaniel Vetter  *
56352217195SDaniel Vetter  * Returns:
56452217195SDaniel Vetter  * Zero on success, negative errno on failure.
56552217195SDaniel Vetter  */
566cde4c44dSDaniel Vetter int drm_connector_attach_encoder(struct drm_connector *connector,
56752217195SDaniel Vetter 				 struct drm_encoder *encoder)
56852217195SDaniel Vetter {
56952217195SDaniel Vetter 	/*
57052217195SDaniel Vetter 	 * In the past, drivers have attempted to model the static association
57152217195SDaniel Vetter 	 * of connector to encoder in simple connector/encoder devices using a
57252217195SDaniel Vetter 	 * direct assignment of connector->encoder = encoder. This connection
57352217195SDaniel Vetter 	 * is a logical one and the responsibility of the core, so drivers are
57452217195SDaniel Vetter 	 * expected not to mess with this.
57552217195SDaniel Vetter 	 *
57652217195SDaniel Vetter 	 * Note that the error return should've been enough here, but a large
57752217195SDaniel Vetter 	 * majority of drivers ignores the return value, so add in a big WARN
57852217195SDaniel Vetter 	 * to get people's attention.
57952217195SDaniel Vetter 	 */
58052217195SDaniel Vetter 	if (WARN_ON(connector->encoder))
58152217195SDaniel Vetter 		return -EINVAL;
58252217195SDaniel Vetter 
58362afb4adSJosé Roberto de Souza 	connector->possible_encoders |= drm_encoder_mask(encoder);
58462afb4adSJosé Roberto de Souza 
58552217195SDaniel Vetter 	return 0;
58652217195SDaniel Vetter }
587cde4c44dSDaniel Vetter EXPORT_SYMBOL(drm_connector_attach_encoder);
58852217195SDaniel Vetter 
58938cb8d96SVille Syrjälä /**
59062afb4adSJosé Roberto de Souza  * drm_connector_has_possible_encoder - check if the connector and encoder are
59162afb4adSJosé Roberto de Souza  * associated with each other
59238cb8d96SVille Syrjälä  * @connector: the connector
59338cb8d96SVille Syrjälä  * @encoder: the encoder
59438cb8d96SVille Syrjälä  *
59538cb8d96SVille Syrjälä  * Returns:
59638cb8d96SVille Syrjälä  * True if @encoder is one of the possible encoders for @connector.
59738cb8d96SVille Syrjälä  */
59838cb8d96SVille Syrjälä bool drm_connector_has_possible_encoder(struct drm_connector *connector,
59938cb8d96SVille Syrjälä 					struct drm_encoder *encoder)
60038cb8d96SVille Syrjälä {
60162afb4adSJosé Roberto de Souza 	return connector->possible_encoders & drm_encoder_mask(encoder);
60238cb8d96SVille Syrjälä }
60338cb8d96SVille Syrjälä EXPORT_SYMBOL(drm_connector_has_possible_encoder);
60438cb8d96SVille Syrjälä 
60552217195SDaniel Vetter static void drm_mode_remove(struct drm_connector *connector,
60652217195SDaniel Vetter 			    struct drm_display_mode *mode)
60752217195SDaniel Vetter {
60852217195SDaniel Vetter 	list_del(&mode->head);
60952217195SDaniel Vetter 	drm_mode_destroy(connector->dev, mode);
61052217195SDaniel Vetter }
61152217195SDaniel Vetter 
61252217195SDaniel Vetter /**
61352217195SDaniel Vetter  * drm_connector_cleanup - cleans up an initialised connector
61452217195SDaniel Vetter  * @connector: connector to cleanup
61552217195SDaniel Vetter  *
61652217195SDaniel Vetter  * Cleans up the connector but doesn't free the object.
61752217195SDaniel Vetter  */
61852217195SDaniel Vetter void drm_connector_cleanup(struct drm_connector *connector)
61952217195SDaniel Vetter {
62052217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
62152217195SDaniel Vetter 	struct drm_display_mode *mode, *t;
62252217195SDaniel Vetter 
62352217195SDaniel Vetter 	/* The connector should have been removed from userspace long before
62452217195SDaniel Vetter 	 * it is finally destroyed.
62552217195SDaniel Vetter 	 */
62639b50c60SLyude Paul 	if (WARN_ON(connector->registration_state ==
62739b50c60SLyude Paul 		    DRM_CONNECTOR_REGISTERED))
62852217195SDaniel Vetter 		drm_connector_unregister(connector);
62952217195SDaniel Vetter 
630334f74eeSHans de Goede 	if (connector->privacy_screen) {
631334f74eeSHans de Goede 		drm_privacy_screen_put(connector->privacy_screen);
632334f74eeSHans de Goede 		connector->privacy_screen = NULL;
633334f74eeSHans de Goede 	}
634334f74eeSHans de Goede 
63552217195SDaniel Vetter 	if (connector->tile_group) {
63652217195SDaniel Vetter 		drm_mode_put_tile_group(dev, connector->tile_group);
63752217195SDaniel Vetter 		connector->tile_group = NULL;
63852217195SDaniel Vetter 	}
63952217195SDaniel Vetter 
64052217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
64152217195SDaniel Vetter 		drm_mode_remove(connector, mode);
64252217195SDaniel Vetter 
64352217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->modes, head)
64452217195SDaniel Vetter 		drm_mode_remove(connector, mode);
64552217195SDaniel Vetter 
646e5d6eeeaSBo Liu 	ida_free(&drm_connector_enum_list[connector->connector_type].ida,
64752217195SDaniel Vetter 			  connector->connector_type_id);
64852217195SDaniel Vetter 
649e5d6eeeaSBo Liu 	ida_free(&dev->mode_config.connector_ida, connector->index);
65052217195SDaniel Vetter 
65152217195SDaniel Vetter 	kfree(connector->display_info.bus_formats);
652c3292ab5SJani Nikula 	kfree(connector->display_info.vics);
65352217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
65452217195SDaniel Vetter 	kfree(connector->name);
65552217195SDaniel Vetter 	connector->name = NULL;
65648c429c6SHans de Goede 	fwnode_handle_put(connector->fwnode);
65748c429c6SHans de Goede 	connector->fwnode = NULL;
658613051daSDaniel Vetter 	spin_lock_irq(&dev->mode_config.connector_list_lock);
65952217195SDaniel Vetter 	list_del(&connector->head);
66052217195SDaniel Vetter 	dev->mode_config.num_connector--;
661613051daSDaniel Vetter 	spin_unlock_irq(&dev->mode_config.connector_list_lock);
66252217195SDaniel Vetter 
66352217195SDaniel Vetter 	WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
66452217195SDaniel Vetter 	if (connector->state && connector->funcs->atomic_destroy_state)
66552217195SDaniel Vetter 		connector->funcs->atomic_destroy_state(connector,
66652217195SDaniel Vetter 						       connector->state);
66752217195SDaniel Vetter 
668f378b772SMaxime Ripard 	mutex_destroy(&connector->hdmi.infoframes.lock);
669e73ab00eSDaniel Vetter 	mutex_destroy(&connector->mutex);
670e73ab00eSDaniel Vetter 
67152217195SDaniel Vetter 	memset(connector, 0, sizeof(*connector));
6726fdc2d49SSimon Ser 
6736fdc2d49SSimon Ser 	if (dev->registered)
6746fdc2d49SSimon Ser 		drm_sysfs_hotplug_event(dev);
67552217195SDaniel Vetter }
67652217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_cleanup);
67752217195SDaniel Vetter 
67852217195SDaniel Vetter /**
67952217195SDaniel Vetter  * drm_connector_register - register a connector
68052217195SDaniel Vetter  * @connector: the connector to register
68152217195SDaniel Vetter  *
68269b22f51SDaniel Vetter  * Register userspace interfaces for a connector. Only call this for connectors
68369b22f51SDaniel Vetter  * which can be hotplugged after drm_dev_register() has been called already,
68469b22f51SDaniel Vetter  * e.g. DP MST connectors. All other connectors will be registered automatically
68569b22f51SDaniel Vetter  * when calling drm_dev_register().
68652217195SDaniel Vetter  *
687d87fbea5SMaxime Ripard  * When the connector is no longer available, callers must call
688d87fbea5SMaxime Ripard  * drm_connector_unregister().
689d87fbea5SMaxime Ripard  *
69052217195SDaniel Vetter  * Returns:
69152217195SDaniel Vetter  * Zero on success, error code on failure.
69252217195SDaniel Vetter  */
69352217195SDaniel Vetter int drm_connector_register(struct drm_connector *connector)
69452217195SDaniel Vetter {
695e73ab00eSDaniel Vetter 	int ret = 0;
69652217195SDaniel Vetter 
697e6e7b48bSDaniel Vetter 	if (!connector->dev->registered)
698e6e7b48bSDaniel Vetter 		return 0;
699e6e7b48bSDaniel Vetter 
700e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
70139b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
702e73ab00eSDaniel Vetter 		goto unlock;
70352217195SDaniel Vetter 
70452217195SDaniel Vetter 	ret = drm_sysfs_connector_add(connector);
70552217195SDaniel Vetter 	if (ret)
706e73ab00eSDaniel Vetter 		goto unlock;
70752217195SDaniel Vetter 
708b792e640SGreg Kroah-Hartman 	drm_debugfs_connector_add(connector);
70952217195SDaniel Vetter 
71052217195SDaniel Vetter 	if (connector->funcs->late_register) {
71152217195SDaniel Vetter 		ret = connector->funcs->late_register(connector);
71252217195SDaniel Vetter 		if (ret)
71352217195SDaniel Vetter 			goto err_debugfs;
71452217195SDaniel Vetter 	}
71552217195SDaniel Vetter 
71621b6c281SVille Syrjälä 	ret = drm_sysfs_connector_add_late(connector);
71721b6c281SVille Syrjälä 	if (ret)
71821b6c281SVille Syrjälä 		goto err_late_register;
71921b6c281SVille Syrjälä 
72052217195SDaniel Vetter 	drm_mode_object_register(connector->dev, &connector->base);
72152217195SDaniel Vetter 
72239b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_REGISTERED;
723968d81a6SJeykumar Sankaran 
724968d81a6SJeykumar Sankaran 	/* Let userspace know we have a new connector */
725ad935754SSimon Ser 	drm_sysfs_connector_hotplug_event(connector);
726968d81a6SJeykumar Sankaran 
727334f74eeSHans de Goede 	if (connector->privacy_screen)
728334f74eeSHans de Goede 		drm_privacy_screen_register_notifier(connector->privacy_screen,
729334f74eeSHans de Goede 					   &connector->privacy_screen_notifier);
730334f74eeSHans de Goede 
7313d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
7323d3f7c1eSHans de Goede 	list_add_tail(&connector->global_connector_list_entry, &connector_list);
7333d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
734e73ab00eSDaniel Vetter 	goto unlock;
73552217195SDaniel Vetter 
73621b6c281SVille Syrjälä err_late_register:
73721b6c281SVille Syrjälä 	if (connector->funcs->early_unregister)
73821b6c281SVille Syrjälä 		connector->funcs->early_unregister(connector);
73952217195SDaniel Vetter err_debugfs:
74052217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
74152217195SDaniel Vetter 	drm_sysfs_connector_remove(connector);
742e73ab00eSDaniel Vetter unlock:
743e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
74452217195SDaniel Vetter 	return ret;
74552217195SDaniel Vetter }
74652217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_register);
74752217195SDaniel Vetter 
74852217195SDaniel Vetter /**
74952217195SDaniel Vetter  * drm_connector_unregister - unregister a connector
75052217195SDaniel Vetter  * @connector: the connector to unregister
75152217195SDaniel Vetter  *
75269b22f51SDaniel Vetter  * Unregister userspace interfaces for a connector. Only call this for
753d87fbea5SMaxime Ripard  * connectors which have been registered explicitly by calling
754d87fbea5SMaxime Ripard  * drm_connector_register().
75552217195SDaniel Vetter  */
75652217195SDaniel Vetter void drm_connector_unregister(struct drm_connector *connector)
75752217195SDaniel Vetter {
758e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
75939b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
760e73ab00eSDaniel Vetter 		mutex_unlock(&connector->mutex);
76152217195SDaniel Vetter 		return;
762e73ab00eSDaniel Vetter 	}
76352217195SDaniel Vetter 
7643d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
7653d3f7c1eSHans de Goede 	list_del_init(&connector->global_connector_list_entry);
7663d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
7673d3f7c1eSHans de Goede 
768334f74eeSHans de Goede 	if (connector->privacy_screen)
769334f74eeSHans de Goede 		drm_privacy_screen_unregister_notifier(
770334f74eeSHans de Goede 					connector->privacy_screen,
771334f74eeSHans de Goede 					&connector->privacy_screen_notifier);
772334f74eeSHans de Goede 
77321b6c281SVille Syrjälä 	drm_sysfs_connector_remove_early(connector);
77421b6c281SVille Syrjälä 
77552217195SDaniel Vetter 	if (connector->funcs->early_unregister)
77652217195SDaniel Vetter 		connector->funcs->early_unregister(connector);
77752217195SDaniel Vetter 
77852217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
77983a30739SVille Syrjälä 	drm_sysfs_connector_remove(connector);
78052217195SDaniel Vetter 
78139b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
782e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
78352217195SDaniel Vetter }
78452217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_unregister);
78552217195SDaniel Vetter 
78652217195SDaniel Vetter void drm_connector_unregister_all(struct drm_device *dev)
78752217195SDaniel Vetter {
78852217195SDaniel Vetter 	struct drm_connector *connector;
789613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
79052217195SDaniel Vetter 
791b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
792613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter)
79352217195SDaniel Vetter 		drm_connector_unregister(connector);
794b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
79552217195SDaniel Vetter }
79652217195SDaniel Vetter 
79752217195SDaniel Vetter int drm_connector_register_all(struct drm_device *dev)
79852217195SDaniel Vetter {
79952217195SDaniel Vetter 	struct drm_connector *connector;
800613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
801613051daSDaniel Vetter 	int ret = 0;
80252217195SDaniel Vetter 
803b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
804613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter) {
80552217195SDaniel Vetter 		ret = drm_connector_register(connector);
80652217195SDaniel Vetter 		if (ret)
807613051daSDaniel Vetter 			break;
80852217195SDaniel Vetter 	}
809b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
81052217195SDaniel Vetter 
811613051daSDaniel Vetter 	if (ret)
81252217195SDaniel Vetter 		drm_connector_unregister_all(dev);
81352217195SDaniel Vetter 	return ret;
81452217195SDaniel Vetter }
81552217195SDaniel Vetter 
81652217195SDaniel Vetter /**
81752217195SDaniel Vetter  * drm_get_connector_status_name - return a string for connector status
81852217195SDaniel Vetter  * @status: connector status to compute name of
81952217195SDaniel Vetter  *
82052217195SDaniel Vetter  * In contrast to the other drm_get_*_name functions this one here returns a
82152217195SDaniel Vetter  * const pointer and hence is threadsafe.
822f85d9e59SRandy Dunlap  *
823f85d9e59SRandy Dunlap  * Returns: connector status string
82452217195SDaniel Vetter  */
82552217195SDaniel Vetter const char *drm_get_connector_status_name(enum drm_connector_status status)
82652217195SDaniel Vetter {
82752217195SDaniel Vetter 	if (status == connector_status_connected)
82852217195SDaniel Vetter 		return "connected";
82952217195SDaniel Vetter 	else if (status == connector_status_disconnected)
83052217195SDaniel Vetter 		return "disconnected";
83152217195SDaniel Vetter 	else
83252217195SDaniel Vetter 		return "unknown";
83352217195SDaniel Vetter }
83452217195SDaniel Vetter EXPORT_SYMBOL(drm_get_connector_status_name);
83552217195SDaniel Vetter 
8366140cf20SJani Nikula /**
8376140cf20SJani Nikula  * drm_get_connector_force_name - return a string for connector force
8386140cf20SJani Nikula  * @force: connector force to get name of
8396140cf20SJani Nikula  *
8406140cf20SJani Nikula  * Returns: const pointer to name.
8416140cf20SJani Nikula  */
8426140cf20SJani Nikula const char *drm_get_connector_force_name(enum drm_connector_force force)
8436140cf20SJani Nikula {
8446140cf20SJani Nikula 	switch (force) {
8456140cf20SJani Nikula 	case DRM_FORCE_UNSPECIFIED:
8466140cf20SJani Nikula 		return "unspecified";
8476140cf20SJani Nikula 	case DRM_FORCE_OFF:
8486140cf20SJani Nikula 		return "off";
8496140cf20SJani Nikula 	case DRM_FORCE_ON:
8506140cf20SJani Nikula 		return "on";
8516140cf20SJani Nikula 	case DRM_FORCE_ON_DIGITAL:
8526140cf20SJani Nikula 		return "digital";
8536140cf20SJani Nikula 	default:
8546140cf20SJani Nikula 		return "unknown";
8556140cf20SJani Nikula 	}
8566140cf20SJani Nikula }
8576140cf20SJani Nikula 
858613051daSDaniel Vetter #ifdef CONFIG_LOCKDEP
859613051daSDaniel Vetter static struct lockdep_map connector_list_iter_dep_map = {
860613051daSDaniel Vetter 	.name = "drm_connector_list_iter"
861613051daSDaniel Vetter };
862613051daSDaniel Vetter #endif
863613051daSDaniel Vetter 
864613051daSDaniel Vetter /**
865b982dab1SThierry Reding  * drm_connector_list_iter_begin - initialize a connector_list iterator
866613051daSDaniel Vetter  * @dev: DRM device
867613051daSDaniel Vetter  * @iter: connector_list iterator
868613051daSDaniel Vetter  *
869d574528aSDaniel Vetter  * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
870b982dab1SThierry Reding  * must always be cleaned up again by calling drm_connector_list_iter_end().
871613051daSDaniel Vetter  * Iteration itself happens using drm_connector_list_iter_next() or
872613051daSDaniel Vetter  * drm_for_each_connector_iter().
873613051daSDaniel Vetter  */
874b982dab1SThierry Reding void drm_connector_list_iter_begin(struct drm_device *dev,
875613051daSDaniel Vetter 				   struct drm_connector_list_iter *iter)
876613051daSDaniel Vetter {
877613051daSDaniel Vetter 	iter->dev = dev;
878613051daSDaniel Vetter 	iter->conn = NULL;
879613051daSDaniel Vetter 	lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
880613051daSDaniel Vetter }
881b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_begin);
882613051daSDaniel Vetter 
883a703c550SDaniel Vetter /*
884a703c550SDaniel Vetter  * Extra-safe connector put function that works in any context. Should only be
885a703c550SDaniel Vetter  * used from the connector_iter functions, where we never really expect to
886a703c550SDaniel Vetter  * actually release the connector when dropping our final reference.
887a703c550SDaniel Vetter  */
888a703c550SDaniel Vetter static void
889ea497bb9SDaniel Vetter __drm_connector_put_safe(struct drm_connector *conn)
890a703c550SDaniel Vetter {
891ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &conn->dev->mode_config;
892ea497bb9SDaniel Vetter 
893ea497bb9SDaniel Vetter 	lockdep_assert_held(&config->connector_list_lock);
894ea497bb9SDaniel Vetter 
895ea497bb9SDaniel Vetter 	if (!refcount_dec_and_test(&conn->base.refcount.refcount))
896ea497bb9SDaniel Vetter 		return;
897ea497bb9SDaniel Vetter 
898ea497bb9SDaniel Vetter 	llist_add(&conn->free_node, &config->connector_free_list);
899ea497bb9SDaniel Vetter 	schedule_work(&config->connector_free_work);
900a703c550SDaniel Vetter }
901a703c550SDaniel Vetter 
902613051daSDaniel Vetter /**
903613051daSDaniel Vetter  * drm_connector_list_iter_next - return next connector
9044f45c778SLyude Paul  * @iter: connector_list iterator
905613051daSDaniel Vetter  *
906f85d9e59SRandy Dunlap  * Returns: the next connector for @iter, or NULL when the list walk has
907613051daSDaniel Vetter  * completed.
908613051daSDaniel Vetter  */
909613051daSDaniel Vetter struct drm_connector *
910613051daSDaniel Vetter drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
911613051daSDaniel Vetter {
912613051daSDaniel Vetter 	struct drm_connector *old_conn = iter->conn;
913613051daSDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
914613051daSDaniel Vetter 	struct list_head *lhead;
915613051daSDaniel Vetter 	unsigned long flags;
916613051daSDaniel Vetter 
917613051daSDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
918613051daSDaniel Vetter 	lhead = old_conn ? &old_conn->head : &config->connector_list;
919613051daSDaniel Vetter 
920613051daSDaniel Vetter 	do {
921613051daSDaniel Vetter 		if (lhead->next == &config->connector_list) {
922613051daSDaniel Vetter 			iter->conn = NULL;
923613051daSDaniel Vetter 			break;
924613051daSDaniel Vetter 		}
925613051daSDaniel Vetter 
926613051daSDaniel Vetter 		lhead = lhead->next;
927613051daSDaniel Vetter 		iter->conn = list_entry(lhead, struct drm_connector, head);
928613051daSDaniel Vetter 
929613051daSDaniel Vetter 		/* loop until it's not a zombie connector */
930613051daSDaniel Vetter 	} while (!kref_get_unless_zero(&iter->conn->base.refcount));
931613051daSDaniel Vetter 
932613051daSDaniel Vetter 	if (old_conn)
933ea497bb9SDaniel Vetter 		__drm_connector_put_safe(old_conn);
934ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
935613051daSDaniel Vetter 
936613051daSDaniel Vetter 	return iter->conn;
937613051daSDaniel Vetter }
938613051daSDaniel Vetter EXPORT_SYMBOL(drm_connector_list_iter_next);
939613051daSDaniel Vetter 
940613051daSDaniel Vetter /**
941b982dab1SThierry Reding  * drm_connector_list_iter_end - tear down a connector_list iterator
942613051daSDaniel Vetter  * @iter: connector_list iterator
943613051daSDaniel Vetter  *
944613051daSDaniel Vetter  * Tears down @iter and releases any resources (like &drm_connector references)
945613051daSDaniel Vetter  * acquired while walking the list. This must always be called, both when the
946613051daSDaniel Vetter  * iteration completes fully or when it was aborted without walking the entire
947613051daSDaniel Vetter  * list.
948613051daSDaniel Vetter  */
949b982dab1SThierry Reding void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
950613051daSDaniel Vetter {
951ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
952ea497bb9SDaniel Vetter 	unsigned long flags;
953ea497bb9SDaniel Vetter 
954613051daSDaniel Vetter 	iter->dev = NULL;
955ea497bb9SDaniel Vetter 	if (iter->conn) {
956ea497bb9SDaniel Vetter 		spin_lock_irqsave(&config->connector_list_lock, flags);
957ea497bb9SDaniel Vetter 		__drm_connector_put_safe(iter->conn);
958ea497bb9SDaniel Vetter 		spin_unlock_irqrestore(&config->connector_list_lock, flags);
959ea497bb9SDaniel Vetter 	}
9605facae4fSQian Cai 	lock_release(&connector_list_iter_dep_map, _RET_IP_);
961613051daSDaniel Vetter }
962b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_end);
963613051daSDaniel Vetter 
96452217195SDaniel Vetter static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
96552217195SDaniel Vetter 	{ SubPixelUnknown, "Unknown" },
96652217195SDaniel Vetter 	{ SubPixelHorizontalRGB, "Horizontal RGB" },
96752217195SDaniel Vetter 	{ SubPixelHorizontalBGR, "Horizontal BGR" },
96852217195SDaniel Vetter 	{ SubPixelVerticalRGB, "Vertical RGB" },
96952217195SDaniel Vetter 	{ SubPixelVerticalBGR, "Vertical BGR" },
97052217195SDaniel Vetter 	{ SubPixelNone, "None" },
97152217195SDaniel Vetter };
97252217195SDaniel Vetter 
97352217195SDaniel Vetter /**
97452217195SDaniel Vetter  * drm_get_subpixel_order_name - return a string for a given subpixel enum
97552217195SDaniel Vetter  * @order: enum of subpixel_order
97652217195SDaniel Vetter  *
97752217195SDaniel Vetter  * Note you could abuse this and return something out of bounds, but that
97852217195SDaniel Vetter  * would be a caller error.  No unscrubbed user data should make it here.
979f85d9e59SRandy Dunlap  *
980f85d9e59SRandy Dunlap  * Returns: string describing an enumerated subpixel property
98152217195SDaniel Vetter  */
98252217195SDaniel Vetter const char *drm_get_subpixel_order_name(enum subpixel_order order)
98352217195SDaniel Vetter {
98452217195SDaniel Vetter 	return drm_subpixel_enum_list[order].name;
98552217195SDaniel Vetter }
98652217195SDaniel Vetter EXPORT_SYMBOL(drm_get_subpixel_order_name);
98752217195SDaniel Vetter 
98852217195SDaniel Vetter static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
98952217195SDaniel Vetter 	{ DRM_MODE_DPMS_ON, "On" },
99052217195SDaniel Vetter 	{ DRM_MODE_DPMS_STANDBY, "Standby" },
99152217195SDaniel Vetter 	{ DRM_MODE_DPMS_SUSPEND, "Suspend" },
99252217195SDaniel Vetter 	{ DRM_MODE_DPMS_OFF, "Off" }
99352217195SDaniel Vetter };
99452217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
99552217195SDaniel Vetter 
99640ee6fbeSManasi Navare static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
99740ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_GOOD, "Good" },
99840ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_BAD, "Bad" },
99940ee6fbeSManasi Navare };
100040ee6fbeSManasi Navare 
1001b3c6c8bfSDaniel Vetter /**
1002b3c6c8bfSDaniel Vetter  * drm_display_info_set_bus_formats - set the supported bus formats
1003b3c6c8bfSDaniel Vetter  * @info: display info to store bus formats in
1004b3c6c8bfSDaniel Vetter  * @formats: array containing the supported bus formats
1005b3c6c8bfSDaniel Vetter  * @num_formats: the number of entries in the fmts array
1006b3c6c8bfSDaniel Vetter  *
1007b3c6c8bfSDaniel Vetter  * Store the supported bus formats in display info structure.
1008b3c6c8bfSDaniel Vetter  * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
1009b3c6c8bfSDaniel Vetter  * a full list of available formats.
1010f85d9e59SRandy Dunlap  *
1011f85d9e59SRandy Dunlap  * Returns:
1012f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
1013b3c6c8bfSDaniel Vetter  */
1014b3c6c8bfSDaniel Vetter int drm_display_info_set_bus_formats(struct drm_display_info *info,
1015b3c6c8bfSDaniel Vetter 				     const u32 *formats,
1016b3c6c8bfSDaniel Vetter 				     unsigned int num_formats)
1017b3c6c8bfSDaniel Vetter {
1018b3c6c8bfSDaniel Vetter 	u32 *fmts = NULL;
1019b3c6c8bfSDaniel Vetter 
1020b3c6c8bfSDaniel Vetter 	if (!formats && num_formats)
1021b3c6c8bfSDaniel Vetter 		return -EINVAL;
1022b3c6c8bfSDaniel Vetter 
1023b3c6c8bfSDaniel Vetter 	if (formats && num_formats) {
1024b3c6c8bfSDaniel Vetter 		fmts = kmemdup(formats, sizeof(*formats) * num_formats,
1025b3c6c8bfSDaniel Vetter 			       GFP_KERNEL);
1026b3c6c8bfSDaniel Vetter 		if (!fmts)
1027b3c6c8bfSDaniel Vetter 			return -ENOMEM;
1028b3c6c8bfSDaniel Vetter 	}
1029b3c6c8bfSDaniel Vetter 
1030b3c6c8bfSDaniel Vetter 	kfree(info->bus_formats);
1031b3c6c8bfSDaniel Vetter 	info->bus_formats = fmts;
1032b3c6c8bfSDaniel Vetter 	info->num_bus_formats = num_formats;
1033b3c6c8bfSDaniel Vetter 
1034b3c6c8bfSDaniel Vetter 	return 0;
1035b3c6c8bfSDaniel Vetter }
1036b3c6c8bfSDaniel Vetter EXPORT_SYMBOL(drm_display_info_set_bus_formats);
1037b3c6c8bfSDaniel Vetter 
103852217195SDaniel Vetter /* Optional connector properties. */
103952217195SDaniel Vetter static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
104052217195SDaniel Vetter 	{ DRM_MODE_SCALE_NONE, "None" },
104152217195SDaniel Vetter 	{ DRM_MODE_SCALE_FULLSCREEN, "Full" },
104252217195SDaniel Vetter 	{ DRM_MODE_SCALE_CENTER, "Center" },
104352217195SDaniel Vetter 	{ DRM_MODE_SCALE_ASPECT, "Full aspect" },
104452217195SDaniel Vetter };
104552217195SDaniel Vetter 
104652217195SDaniel Vetter static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
104752217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
104852217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
104952217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
105052217195SDaniel Vetter };
105152217195SDaniel Vetter 
105250525c33SStanislav Lisovskiy static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
105350525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
105450525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
105550525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
105650525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
105750525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GAME, "Game" },
105850525c33SStanislav Lisovskiy };
105950525c33SStanislav Lisovskiy 
10608d70f395SHans de Goede static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
10618d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_NORMAL,	"Normal"	},
10628d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP,	"Upside Down"	},
10638d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_LEFT_UP,	"Left Side Up"	},
10648d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,	"Right Side Up"	},
10658d70f395SHans de Goede };
10668d70f395SHans de Goede 
106752217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
106852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
106952217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
107052217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
107152217195SDaniel Vetter };
107252217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
107352217195SDaniel Vetter 
107452217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
1075e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I, TV-out and DP */
107652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
107752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
107852217195SDaniel Vetter };
107952217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
108052217195SDaniel Vetter 		 drm_dvi_i_subconnector_enum_list)
108152217195SDaniel Vetter 
10827d63cd85SMaxime Ripard static const struct drm_prop_enum_list drm_tv_mode_enum_list[] = {
10837d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_NTSC, "NTSC" },
10847d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_NTSC_443, "NTSC-443" },
10857d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_NTSC_J, "NTSC-J" },
10867d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_PAL, "PAL" },
10877d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_PAL_M, "PAL-M" },
10887d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_PAL_N, "PAL-N" },
10897d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_SECAM, "SECAM" },
109041474d25SNick Hollinghurst 	{ DRM_MODE_TV_MODE_MONOCHROME, "Mono" },
10917d63cd85SMaxime Ripard };
10927d63cd85SMaxime Ripard DRM_ENUM_NAME_FN(drm_get_tv_mode_name, drm_tv_mode_enum_list)
10937d63cd85SMaxime Ripard 
1094d4613e3eSMaxime Ripard /**
1095d4613e3eSMaxime Ripard  * drm_get_tv_mode_from_name - Translates a TV mode name into its enum value
1096d4613e3eSMaxime Ripard  * @name: TV Mode name we want to convert
1097d4613e3eSMaxime Ripard  * @len: Length of @name
1098d4613e3eSMaxime Ripard  *
1099d4613e3eSMaxime Ripard  * Translates @name into an enum drm_connector_tv_mode.
1100d4613e3eSMaxime Ripard  *
1101d4613e3eSMaxime Ripard  * Returns: the enum value on success, a negative errno otherwise.
1102d4613e3eSMaxime Ripard  */
1103d4613e3eSMaxime Ripard int drm_get_tv_mode_from_name(const char *name, size_t len)
1104d4613e3eSMaxime Ripard {
1105d4613e3eSMaxime Ripard 	unsigned int i;
1106d4613e3eSMaxime Ripard 
1107d4613e3eSMaxime Ripard 	for (i = 0; i < ARRAY_SIZE(drm_tv_mode_enum_list); i++) {
1108d4613e3eSMaxime Ripard 		const struct drm_prop_enum_list *item = &drm_tv_mode_enum_list[i];
1109d4613e3eSMaxime Ripard 
1110d4613e3eSMaxime Ripard 		if (strlen(item->name) == len && !strncmp(item->name, name, len))
1111d4613e3eSMaxime Ripard 			return item->type;
1112d4613e3eSMaxime Ripard 	}
1113d4613e3eSMaxime Ripard 
1114d4613e3eSMaxime Ripard 	return -EINVAL;
1115d4613e3eSMaxime Ripard }
1116d4613e3eSMaxime Ripard EXPORT_SYMBOL(drm_get_tv_mode_from_name);
1117d4613e3eSMaxime Ripard 
111852217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
111952217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
112052217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
112152217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
112252217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
112352217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
112452217195SDaniel Vetter };
112552217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
112652217195SDaniel Vetter 
112752217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
1128e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I, TV-out and DP */
112952217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
113052217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
113152217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
113252217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
113352217195SDaniel Vetter };
113452217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
113552217195SDaniel Vetter 		 drm_tv_subconnector_enum_list)
113652217195SDaniel Vetter 
1137e5b92773SOleg Vasilev static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = {
1138e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,     "Unknown"   }, /* DVI-I, TV-out and DP */
1139e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_VGA,	     "VGA"       }, /* DP */
1140e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_DVID,	     "DVI-D"     }, /* DP */
1141e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_HDMIA,	     "HDMI"      }, /* DP */
1142e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_DisplayPort, "DP"        }, /* DP */
1143e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Wireless,    "Wireless"  }, /* DP */
1144e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Native,	     "Native"    }, /* DP */
1145e5b92773SOleg Vasilev };
1146e5b92773SOleg Vasilev 
1147e5b92773SOleg Vasilev DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name,
1148e5b92773SOleg Vasilev 		 drm_dp_subconnector_enum_list)
1149e5b92773SOleg Vasilev 
1150c627087cSHarry Wentland 
1151c627087cSHarry Wentland static const char * const colorspace_names[] = {
1152d2c6a405SUma Shankar 	/* For Default case, driver will set the colorspace */
1153c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_DEFAULT] = "Default",
1154d2c6a405SUma Shankar 	/* Standard Definition Colorimetry based on CEA 861 */
1155c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = "SMPTE_170M_YCC",
1156c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT709_YCC] = "BT709_YCC",
1157d2c6a405SUma Shankar 	/* Standard Definition Colorimetry based on IEC 61966-2-4 */
1158c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_XVYCC_601] = "XVYCC_601",
1159d2c6a405SUma Shankar 	/* High Definition Colorimetry based on IEC 61966-2-4 */
1160c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_XVYCC_709] = "XVYCC_709",
1161d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-1/Amendment 1 */
1162c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_SYCC_601] = "SYCC_601",
1163d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-5 [33] */
1164c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_OPYCC_601] = "opYCC_601",
1165d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-5 */
1166c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_OPRGB] = "opRGB",
1167d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
1168c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT2020_CYCC] = "BT2020_CYCC",
1169d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
1170c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT2020_RGB] = "BT2020_RGB",
1171d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
1172c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT2020_YCC] = "BT2020_YCC",
1173d2c6a405SUma Shankar 	/* Added as part of Additional Colorimetry Extension in 861.G */
1174c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65] = "DCI-P3_RGB_D65",
1175c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER] = "DCI-P3_RGB_Theater",
1176c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED] = "RGB_WIDE_FIXED",
1177c627087cSHarry Wentland 	/* Colorimetry based on scRGB (IEC 61966-2-2) */
1178c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT] = "RGB_WIDE_FLOAT",
1179c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT601_YCC] = "BT601_YCC",
1180d2c6a405SUma Shankar };
1181d2c6a405SUma Shankar 
1182035d53e0SHarry Wentland /**
1183035d53e0SHarry Wentland  * drm_get_colorspace_name - return a string for color encoding
1184035d53e0SHarry Wentland  * @colorspace: color space to compute name of
1185035d53e0SHarry Wentland  *
1186035d53e0SHarry Wentland  * In contrast to the other drm_get_*_name functions this one here returns a
1187035d53e0SHarry Wentland  * const pointer and hence is threadsafe.
1188035d53e0SHarry Wentland  */
1189035d53e0SHarry Wentland const char *drm_get_colorspace_name(enum drm_colorspace colorspace)
1190035d53e0SHarry Wentland {
1191035d53e0SHarry Wentland 	if (colorspace < ARRAY_SIZE(colorspace_names) && colorspace_names[colorspace])
1192035d53e0SHarry Wentland 		return colorspace_names[colorspace];
1193035d53e0SHarry Wentland 	else
1194035d53e0SHarry Wentland 		return "(null)";
1195035d53e0SHarry Wentland }
1196035d53e0SHarry Wentland 
1197c627087cSHarry Wentland static const u32 hdmi_colorspaces =
1198c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_SMPTE_170M_YCC) |
1199c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |
1200c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_XVYCC_601) |
1201c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_XVYCC_709) |
1202c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_SYCC_601) |
1203c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_OPYCC_601) |
1204c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_OPRGB) |
1205c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) |
1206c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) |
1207c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_YCC) |
1208c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) |
1209c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER);
1210c627087cSHarry Wentland 
121145cf0e91SGwan-gyeong Mun /*
121245cf0e91SGwan-gyeong Mun  * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
121345cf0e91SGwan-gyeong Mun  * Format Table 2-120
121445cf0e91SGwan-gyeong Mun  */
1215c627087cSHarry Wentland static const u32 dp_colorspaces =
1216c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED) |
1217c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT) |
1218c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_OPRGB) |
1219c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) |
1220c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) |
1221c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT601_YCC) |
1222c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |
1223c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_XVYCC_601) |
1224c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_XVYCC_709) |
1225c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_SYCC_601) |
1226c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_OPYCC_601) |
1227c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) |
1228c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_YCC);
122945cf0e91SGwan-gyeong Mun 
1230ab52af4bSMaxime Ripard static const struct drm_prop_enum_list broadcast_rgb_names[] = {
1231ab52af4bSMaxime Ripard 	{ DRM_HDMI_BROADCAST_RGB_AUTO, "Automatic" },
1232ab52af4bSMaxime Ripard 	{ DRM_HDMI_BROADCAST_RGB_FULL, "Full" },
1233ab52af4bSMaxime Ripard 	{ DRM_HDMI_BROADCAST_RGB_LIMITED, "Limited 16:235" },
1234ab52af4bSMaxime Ripard };
1235ab52af4bSMaxime Ripard 
1236ab52af4bSMaxime Ripard /*
1237ab52af4bSMaxime Ripard  * drm_hdmi_connector_get_broadcast_rgb_name - Return a string for HDMI connector RGB broadcast selection
1238ab52af4bSMaxime Ripard  * @broadcast_rgb: Broadcast RGB selection to compute name of
1239ab52af4bSMaxime Ripard  *
1240ab52af4bSMaxime Ripard  * Returns: the name of the Broadcast RGB selection, or NULL if the type
1241ab52af4bSMaxime Ripard  * is not valid.
1242ab52af4bSMaxime Ripard  */
1243ab52af4bSMaxime Ripard const char *
1244ab52af4bSMaxime Ripard drm_hdmi_connector_get_broadcast_rgb_name(enum drm_hdmi_broadcast_rgb broadcast_rgb)
1245ab52af4bSMaxime Ripard {
1246ab52af4bSMaxime Ripard 	if (broadcast_rgb >= ARRAY_SIZE(broadcast_rgb_names))
1247ab52af4bSMaxime Ripard 		return NULL;
1248ab52af4bSMaxime Ripard 
1249ab52af4bSMaxime Ripard 	return broadcast_rgb_names[broadcast_rgb].name;
1250ab52af4bSMaxime Ripard }
1251ab52af4bSMaxime Ripard EXPORT_SYMBOL(drm_hdmi_connector_get_broadcast_rgb_name);
1252ab52af4bSMaxime Ripard 
1253948f01d5SMaxime Ripard static const char * const output_format_str[] = {
1254948f01d5SMaxime Ripard 	[HDMI_COLORSPACE_RGB]		= "RGB",
1255948f01d5SMaxime Ripard 	[HDMI_COLORSPACE_YUV420]	= "YUV 4:2:0",
1256948f01d5SMaxime Ripard 	[HDMI_COLORSPACE_YUV422]	= "YUV 4:2:2",
1257948f01d5SMaxime Ripard 	[HDMI_COLORSPACE_YUV444]	= "YUV 4:4:4",
1258948f01d5SMaxime Ripard };
1259948f01d5SMaxime Ripard 
1260948f01d5SMaxime Ripard /*
1261948f01d5SMaxime Ripard  * drm_hdmi_connector_get_output_format_name() - Return a string for HDMI connector output format
1262948f01d5SMaxime Ripard  * @fmt: Output format to compute name of
1263948f01d5SMaxime Ripard  *
1264948f01d5SMaxime Ripard  * Returns: the name of the output format, or NULL if the type is not
1265948f01d5SMaxime Ripard  * valid.
1266948f01d5SMaxime Ripard  */
1267948f01d5SMaxime Ripard const char *
1268948f01d5SMaxime Ripard drm_hdmi_connector_get_output_format_name(enum hdmi_colorspace fmt)
1269948f01d5SMaxime Ripard {
1270948f01d5SMaxime Ripard 	if (fmt >= ARRAY_SIZE(output_format_str))
1271948f01d5SMaxime Ripard 		return NULL;
1272948f01d5SMaxime Ripard 
1273948f01d5SMaxime Ripard 	return output_format_str[fmt];
1274948f01d5SMaxime Ripard }
1275948f01d5SMaxime Ripard EXPORT_SYMBOL(drm_hdmi_connector_get_output_format_name);
1276948f01d5SMaxime Ripard 
12774ada6f22SDaniel Vetter /**
12784ada6f22SDaniel Vetter  * DOC: standard connector properties
12794ada6f22SDaniel Vetter  *
12804ada6f22SDaniel Vetter  * DRM connectors have a few standardized properties:
12814ada6f22SDaniel Vetter  *
12824ada6f22SDaniel Vetter  * EDID:
12834ada6f22SDaniel Vetter  * 	Blob property which contains the current EDID read from the sink. This
12844ada6f22SDaniel Vetter  * 	is useful to parse sink identification information like vendor, model
12854ada6f22SDaniel Vetter  * 	and serial. Drivers should update this property by calling
1286c555f023SDaniel Vetter  * 	drm_connector_update_edid_property(), usually after having parsed
12874ada6f22SDaniel Vetter  * 	the EDID using drm_add_edid_modes(). Userspace cannot change this
12884ada6f22SDaniel Vetter  * 	property.
128912767469SSimon Ser  *
129012767469SSimon Ser  * 	User-space should not parse the EDID to obtain information exposed via
129112767469SSimon Ser  * 	other KMS properties (because the kernel might apply limits, quirks or
129212767469SSimon Ser  * 	fixups to the EDID). For instance, user-space should not try to parse
129312767469SSimon Ser  * 	mode lists from the EDID.
12944ada6f22SDaniel Vetter  * DPMS:
12954ada6f22SDaniel Vetter  * 	Legacy property for setting the power state of the connector. For atomic
12964ada6f22SDaniel Vetter  * 	drivers this is only provided for backwards compatibility with existing
12974ada6f22SDaniel Vetter  * 	drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
12984ada6f22SDaniel Vetter  * 	connector is linked to. Drivers should never set this property directly,
1299d574528aSDaniel Vetter  * 	it is handled by the DRM core by calling the &drm_connector_funcs.dpms
1300144a7999SDaniel Vetter  * 	callback. For atomic drivers the remapping to the "ACTIVE" property is
13011e3e4caeSSimon Ser  * 	implemented in the DRM core.
1302d0d1aee5SDaniel Vetter  *
1303d0d1aee5SDaniel Vetter  * 	Note that this property cannot be set through the MODE_ATOMIC ioctl,
1304d0d1aee5SDaniel Vetter  * 	userspace must use "ACTIVE" on the CRTC instead.
1305d0d1aee5SDaniel Vetter  *
1306d0d1aee5SDaniel Vetter  * 	WARNING:
1307d0d1aee5SDaniel Vetter  *
1308d0d1aee5SDaniel Vetter  * 	For userspace also running on legacy drivers the "DPMS" semantics are a
1309d0d1aee5SDaniel Vetter  * 	lot more complicated. First, userspace cannot rely on the "DPMS" value
1310d0d1aee5SDaniel Vetter  * 	returned by the GETCONNECTOR actually reflecting reality, because many
1311d0d1aee5SDaniel Vetter  * 	drivers fail to update it. For atomic drivers this is taken care of in
1312d0d1aee5SDaniel Vetter  * 	drm_atomic_helper_update_legacy_modeset_state().
1313d0d1aee5SDaniel Vetter  *
1314d0d1aee5SDaniel Vetter  * 	The second issue is that the DPMS state is only well-defined when the
1315d0d1aee5SDaniel Vetter  * 	connector is connected to a CRTC. In atomic the DRM core enforces that
1316d0d1aee5SDaniel Vetter  * 	"ACTIVE" is off in such a case, no such checks exists for "DPMS".
1317d0d1aee5SDaniel Vetter  *
1318d0d1aee5SDaniel Vetter  * 	Finally, when enabling an output using the legacy SETCONFIG ioctl then
1319d0d1aee5SDaniel Vetter  * 	"DPMS" is forced to ON. But see above, that might not be reflected in
1320d0d1aee5SDaniel Vetter  * 	the software value on legacy drivers.
1321d0d1aee5SDaniel Vetter  *
1322d0d1aee5SDaniel Vetter  * 	Summarizing: Only set "DPMS" when the connector is known to be enabled,
1323d0d1aee5SDaniel Vetter  * 	assume that a successful SETCONFIG call also sets "DPMS" to on, and
1324d0d1aee5SDaniel Vetter  * 	never read back the value of "DPMS" because it can be incorrect.
13254ada6f22SDaniel Vetter  * PATH:
13264ada6f22SDaniel Vetter  * 	Connector path property to identify how this sink is physically
13274ada6f22SDaniel Vetter  * 	connected. Used by DP MST. This should be set by calling
132897e14fbeSDaniel Vetter  * 	drm_connector_set_path_property(), in the case of DP MST with the
13294ada6f22SDaniel Vetter  * 	path property the MST manager created. Userspace cannot change this
13304ada6f22SDaniel Vetter  * 	property.
133188b02ebcSSimon Ser  *
133288b02ebcSSimon Ser  * 	In the case of DP MST, the property has the format
133388b02ebcSSimon Ser  * 	``mst:<parent>-<ports>`` where ``<parent>`` is the KMS object ID of the
133488b02ebcSSimon Ser  * 	parent connector and ``<ports>`` is a hyphen-separated list of DP MST
133588b02ebcSSimon Ser  * 	port numbers. Note, KMS object IDs are not guaranteed to be stable
133688b02ebcSSimon Ser  * 	across reboots.
13374ada6f22SDaniel Vetter  * TILE:
13384ada6f22SDaniel Vetter  * 	Connector tile group property to indicate how a set of DRM connector
13394ada6f22SDaniel Vetter  * 	compose together into one logical screen. This is used by both high-res
13404ada6f22SDaniel Vetter  * 	external screens (often only using a single cable, but exposing multiple
13414ada6f22SDaniel Vetter  * 	DP MST sinks), or high-res integrated panels (like dual-link DSI) which
13424ada6f22SDaniel Vetter  * 	are not gen-locked. Note that for tiled panels which are genlocked, like
13434ada6f22SDaniel Vetter  * 	dual-link LVDS or dual-link DSI, the driver should try to not expose the
134484e543bcSAntonio Borneo  * 	tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers
134597e14fbeSDaniel Vetter  * 	should update this value using drm_connector_set_tile_property().
13464ada6f22SDaniel Vetter  * 	Userspace cannot change this property.
134740ee6fbeSManasi Navare  * link-status:
1348716719a3SSean Paul  *      Connector link-status property to indicate the status of link. The
1349716719a3SSean Paul  *      default value of link-status is "GOOD". If something fails during or
1350716719a3SSean Paul  *      after modeset, the kernel driver may set this to "BAD" and issue a
1351716719a3SSean Paul  *      hotplug uevent. Drivers should update this value using
135297e14fbeSDaniel Vetter  *      drm_connector_set_link_status_property().
1353a66da873SSimon Ser  *
1354a66da873SSimon Ser  *      When user-space receives the hotplug uevent and detects a "BAD"
1355a66da873SSimon Ser  *      link-status, the sink doesn't receive pixels anymore (e.g. the screen
1356a66da873SSimon Ser  *      becomes completely black). The list of available modes may have
1357a66da873SSimon Ser  *      changed. User-space is expected to pick a new mode if the current one
1358a66da873SSimon Ser  *      has disappeared and perform a new modeset with link-status set to
1359a66da873SSimon Ser  *      "GOOD" to re-enable the connector.
1360a66da873SSimon Ser  *
1361a66da873SSimon Ser  *      If multiple connectors share the same CRTC and one of them gets a "BAD"
1362a66da873SSimon Ser  *      link-status, the other are unaffected (ie. the sinks still continue to
1363a66da873SSimon Ser  *      receive pixels).
1364a66da873SSimon Ser  *
1365a66da873SSimon Ser  *      When user-space performs an atomic commit on a connector with a "BAD"
1366a66da873SSimon Ser  *      link-status without resetting the property to "GOOD", the sink may
1367a66da873SSimon Ser  *      still not receive pixels. When user-space performs an atomic commit
1368a66da873SSimon Ser  *      which resets the link-status property to "GOOD" without the
1369a66da873SSimon Ser  *      ALLOW_MODESET flag set, it might fail because a modeset is required.
1370a66da873SSimon Ser  *
1371a66da873SSimon Ser  *      User-space can only change link-status to "GOOD", changing it to "BAD"
1372a66da873SSimon Ser  *      is a no-op.
1373a66da873SSimon Ser  *
1374a66da873SSimon Ser  *      For backwards compatibility with non-atomic userspace the kernel
1375a66da873SSimon Ser  *      tries to automatically set the link-status back to "GOOD" in the
1376a66da873SSimon Ser  *      SETCRTC IOCTL. This might fail if the mode is no longer valid, similar
1377a66da873SSimon Ser  *      to how it might fail if a different screen has been connected in the
1378a66da873SSimon Ser  *      interim.
137966660d4cSDave Airlie  * non_desktop:
138066660d4cSDave Airlie  * 	Indicates the output should be ignored for purposes of displaying a
138166660d4cSDave Airlie  * 	standard desktop environment or console. This is most likely because
138266660d4cSDave Airlie  * 	the output device is not rectilinear.
138324557865SSean Paul  * Content Protection:
138424557865SSean Paul  *	This property is used by userspace to request the kernel protect future
138524557865SSean Paul  *	content communicated over the link. When requested, kernel will apply
138624557865SSean Paul  *	the appropriate means of protection (most often HDCP), and use the
138724557865SSean Paul  *	property to tell userspace the protection is active.
138824557865SSean Paul  *
138924557865SSean Paul  *	Drivers can set this up by calling
139024557865SSean Paul  *	drm_connector_attach_content_protection_property() on initialization.
139124557865SSean Paul  *
139224557865SSean Paul  *	The value of this property can be one of the following:
139324557865SSean Paul  *
1394bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
139524557865SSean Paul  *		The link is not protected, content is transmitted in the clear.
1396bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
139724557865SSean Paul  *		Userspace has requested content protection, but the link is not
139824557865SSean Paul  *		currently protected. When in this state, kernel should enable
139924557865SSean Paul  *		Content Protection as soon as possible.
1400bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
140124557865SSean Paul  *		Userspace has requested content protection, and the link is
140224557865SSean Paul  *		protected. Only the driver can set the property to this value.
140324557865SSean Paul  *		If userspace attempts to set to ENABLED, kernel will return
140424557865SSean Paul  *		-EINVAL.
140524557865SSean Paul  *
140624557865SSean Paul  *	A few guidelines:
140724557865SSean Paul  *
140824557865SSean Paul  *	- DESIRED state should be preserved until userspace de-asserts it by
140924557865SSean Paul  *	  setting the property to UNDESIRED. This means ENABLED should only
141024557865SSean Paul  *	  transition to UNDESIRED when the user explicitly requests it.
141124557865SSean Paul  *	- If the state is DESIRED, kernel should attempt to re-authenticate the
141224557865SSean Paul  *	  link whenever possible. This includes across disable/enable, dpms,
141324557865SSean Paul  *	  hotplug, downstream device changes, link status failures, etc..
1414bb5a45d4SRamalingam C  *	- Kernel sends uevent with the connector id and property id through
1415bb5a45d4SRamalingam C  *	  @drm_hdcp_update_content_protection, upon below kernel triggered
1416bb5a45d4SRamalingam C  *	  scenarios:
141712db36bcSSean Paul  *
141812db36bcSSean Paul  *		- DESIRED -> ENABLED (authentication success)
141912db36bcSSean Paul  *		- ENABLED -> DESIRED (termination of authentication)
1420bb5a45d4SRamalingam C  *	- Please note no uevents for userspace triggered property state changes,
1421bb5a45d4SRamalingam C  *	  which can't fail such as
142212db36bcSSean Paul  *
142312db36bcSSean Paul  *		- DESIRED/ENABLED -> UNDESIRED
142412db36bcSSean Paul  *		- UNDESIRED -> DESIRED
1425bb5a45d4SRamalingam C  *	- Userspace is responsible for polling the property or listen to uevents
1426bb5a45d4SRamalingam C  *	  to determine when the value transitions from ENABLED to DESIRED.
1427bb5a45d4SRamalingam C  *	  This signifies the link is no longer protected and userspace should
1428bb5a45d4SRamalingam C  *	  take appropriate action (whatever that might be).
14294ada6f22SDaniel Vetter  *
14307672dbbaSRamalingam C  * HDCP Content Type:
14317672dbbaSRamalingam C  *	This Enum property is used by the userspace to declare the content type
14327672dbbaSRamalingam C  *	of the display stream, to kernel. Here display stream stands for any
14337672dbbaSRamalingam C  *	display content that userspace intended to display through HDCP
14347672dbbaSRamalingam C  *	encryption.
14357672dbbaSRamalingam C  *
14367672dbbaSRamalingam C  *	Content Type of a stream is decided by the owner of the stream, as
14377672dbbaSRamalingam C  *	"HDCP Type0" or "HDCP Type1".
14387672dbbaSRamalingam C  *
14397672dbbaSRamalingam C  *	The value of the property can be one of the below:
14407672dbbaSRamalingam C  *	  - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0
14417672dbbaSRamalingam C  *	  - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1
14427672dbbaSRamalingam C  *
14437672dbbaSRamalingam C  *	When kernel starts the HDCP authentication (see "Content Protection"
14447672dbbaSRamalingam C  *	for details), it uses the content type in "HDCP Content Type"
14457672dbbaSRamalingam C  *	for performing the HDCP authentication with the display sink.
14467672dbbaSRamalingam C  *
14477672dbbaSRamalingam C  *	Please note in HDCP spec versions, a link can be authenticated with
14487672dbbaSRamalingam C  *	HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be
14497672dbbaSRamalingam C  *	authenticated with HDCP1.4 only for Content Type 0(though it is implicit
14507672dbbaSRamalingam C  *	in nature. As there is no reference for Content Type in HDCP1.4).
14517672dbbaSRamalingam C  *
14527672dbbaSRamalingam C  *	HDCP2.2 authentication protocol itself takes the "Content Type" as a
14537672dbbaSRamalingam C  *	parameter, which is a input for the DP HDCP2.2 encryption algo.
14547672dbbaSRamalingam C  *
14557672dbbaSRamalingam C  *	In case of Type 0 content protection request, kernel driver can choose
14567672dbbaSRamalingam C  *	either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for
14577672dbbaSRamalingam C  *	"HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send
14587672dbbaSRamalingam C  *	that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).
14597672dbbaSRamalingam C  *	But if the content is classified as "HDCP Type 1", above mentioned
14607672dbbaSRamalingam C  *	HDCP 2.2 repeater wont send the content to the HDCP sink as it can't
14617672dbbaSRamalingam C  *	authenticate the HDCP1.4 capable sink for "HDCP Type 1".
14627672dbbaSRamalingam C  *
14637672dbbaSRamalingam C  *	Please note userspace can be ignorant of the HDCP versions used by the
14647672dbbaSRamalingam C  *	kernel driver to achieve the "HDCP Content Type".
14657672dbbaSRamalingam C  *
14667672dbbaSRamalingam C  *	At current scenario, classifying a content as Type 1 ensures that the
14677672dbbaSRamalingam C  *	content will be displayed only through the HDCP2.2 encrypted link.
14687672dbbaSRamalingam C  *
14697672dbbaSRamalingam C  *	Note that the HDCP Content Type property is introduced at HDCP 2.2, and
14707672dbbaSRamalingam C  *	defaults to type 0. It is only exposed by drivers supporting HDCP 2.2
14717672dbbaSRamalingam C  *	(hence supporting Type 0 and Type 1). Based on how next versions of
14727672dbbaSRamalingam C  *	HDCP specs are defined content Type could be used for higher versions
14737672dbbaSRamalingam C  *	too.
14747672dbbaSRamalingam C  *
14757672dbbaSRamalingam C  *	If content type is changed when "Content Protection" is not UNDESIRED,
14767672dbbaSRamalingam C  *	then kernel will disable the HDCP and re-enable with new type in the
14777672dbbaSRamalingam C  *	same atomic commit. And when "Content Protection" is ENABLED, it means
14787672dbbaSRamalingam C  *	that link is HDCP authenticated and encrypted, for the transmission of
14797672dbbaSRamalingam C  *	the Type of stream mentioned at "HDCP Content Type".
14807672dbbaSRamalingam C  *
1481a09db883SUma Shankar  * HDR_OUTPUT_METADATA:
1482a09db883SUma Shankar  *	Connector property to enable userspace to send HDR Metadata to
1483a09db883SUma Shankar  *	driver. This metadata is based on the composition and blending
1484a09db883SUma Shankar  *	policies decided by user, taking into account the hardware and
1485a09db883SUma Shankar  *	sink capabilities. The driver gets this metadata and creates a
1486a09db883SUma Shankar  *	Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,
1487a09db883SUma Shankar  *	SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then
1488a09db883SUma Shankar  *	sent to sink. This notifies the sink of the upcoming frame's Color
1489a09db883SUma Shankar  *	Encoding and Luminance parameters.
1490a09db883SUma Shankar  *
1491a09db883SUma Shankar  *	Userspace first need to detect the HDR capabilities of sink by
1492a09db883SUma Shankar  *	reading and parsing the EDID. Details of HDR metadata for HDMI
1493a09db883SUma Shankar  *	are added in CTA 861.G spec. For DP , its defined in VESA DP
1494a09db883SUma Shankar  *	Standard v1.4. It needs to then get the metadata information
1495a09db883SUma Shankar  *	of the video/game/app content which are encoded in HDR (basically
1496a09db883SUma Shankar  *	using HDR transfer functions). With this information it needs to
1497a09db883SUma Shankar  *	decide on a blending policy and compose the relevant
1498a09db883SUma Shankar  *	layers/overlays into a common format. Once this blending is done,
1499a09db883SUma Shankar  *	userspace will be aware of the metadata of the composed frame to
1500a09db883SUma Shankar  *	be send to sink. It then uses this property to communicate this
1501a09db883SUma Shankar  *	metadata to driver which then make a Infoframe packet and sends
1502a09db883SUma Shankar  *	to sink based on the type of encoder connected.
1503a09db883SUma Shankar  *
1504a09db883SUma Shankar  *	Userspace will be responsible to do Tone mapping operation in case:
1505a09db883SUma Shankar  *		- Some layers are HDR and others are SDR
1506a09db883SUma Shankar  *		- HDR layers luminance is not same as sink
15079f9b2559SSean Paul  *
1508a09db883SUma Shankar  *	It will even need to do colorspace conversion and get all layers
1509a09db883SUma Shankar  *	to one common colorspace for blending. It can use either GL, Media
151084e543bcSAntonio Borneo  *	or display engine to get this done based on the capabilities of the
1511a09db883SUma Shankar  *	associated hardware.
1512a09db883SUma Shankar  *
1513a09db883SUma Shankar  *	Driver expects metadata to be put in &struct hdr_output_metadata
1514a09db883SUma Shankar  *	structure from userspace. This is received as blob and stored in
1515a09db883SUma Shankar  *	&drm_connector_state.hdr_output_metadata. It parses EDID and saves the
1516a09db883SUma Shankar  *	sink metadata in &struct hdr_sink_metadata, as
1517a09db883SUma Shankar  *	&drm_connector.hdr_sink_metadata.  Driver uses
1518a09db883SUma Shankar  *	drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,
1519a09db883SUma Shankar  *	hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of
1520a09db883SUma Shankar  *	HDMI encoder.
1521a09db883SUma Shankar  *
152247e22ff1SRadhakrishna Sripada  * max bpc:
152347e22ff1SRadhakrishna Sripada  *	This range property is used by userspace to limit the bit depth. When
152447e22ff1SRadhakrishna Sripada  *	used the driver would limit the bpc in accordance with the valid range
152547e22ff1SRadhakrishna Sripada  *	supported by the hardware and sink. Drivers to use the function
152647e22ff1SRadhakrishna Sripada  *	drm_connector_attach_max_bpc_property() to create and attach the
152747e22ff1SRadhakrishna Sripada  *	property to the connector during initialization.
152847e22ff1SRadhakrishna Sripada  *
15294ada6f22SDaniel Vetter  * Connectors also have one standardized atomic property:
15304ada6f22SDaniel Vetter  *
15314ada6f22SDaniel Vetter  * CRTC_ID:
15324ada6f22SDaniel Vetter  * 	Mode object ID of the &drm_crtc this connector should be connected to.
15338d70f395SHans de Goede  *
15348d70f395SHans de Goede  * Connectors for LCD panels may also have one standardized property:
15358d70f395SHans de Goede  *
15368d70f395SHans de Goede  * panel orientation:
15378d70f395SHans de Goede  *	On some devices the LCD panel is mounted in the casing in such a way
15388d70f395SHans de Goede  *	that the up/top side of the panel does not match with the top side of
15398d70f395SHans de Goede  *	the device. Userspace can use this property to check for this.
15408d70f395SHans de Goede  *	Note that input coordinates from touchscreens (input devices with
15418d70f395SHans de Goede  *	INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
15428d70f395SHans de Goede  *	coordinates, so if userspace rotates the picture to adjust for
15438d70f395SHans de Goede  *	the orientation it must also apply the same transformation to the
1544bbeba09fSDaniel Vetter  *	touchscreen input coordinates. This property is initialized by calling
154569654c63SDerek Basehore  *	drm_connector_set_panel_orientation() or
154669654c63SDerek Basehore  *	drm_connector_set_panel_orientation_with_quirk()
1547bbeba09fSDaniel Vetter  *
1548bbeba09fSDaniel Vetter  * scaling mode:
1549bbeba09fSDaniel Vetter  *	This property defines how a non-native mode is upscaled to the native
1550bbeba09fSDaniel Vetter  *	mode of an LCD panel:
1551bbeba09fSDaniel Vetter  *
1552bbeba09fSDaniel Vetter  *	None:
1553bbeba09fSDaniel Vetter  *		No upscaling happens, scaling is left to the panel. Not all
1554bbeba09fSDaniel Vetter  *		drivers expose this mode.
1555bbeba09fSDaniel Vetter  *	Full:
1556bbeba09fSDaniel Vetter  *		The output is upscaled to the full resolution of the panel,
1557bbeba09fSDaniel Vetter  *		ignoring the aspect ratio.
1558bbeba09fSDaniel Vetter  *	Center:
1559bbeba09fSDaniel Vetter  *		No upscaling happens, the output is centered within the native
1560bbeba09fSDaniel Vetter  *		resolution the panel.
1561bbeba09fSDaniel Vetter  *	Full aspect:
1562bbeba09fSDaniel Vetter  *		The output is upscaled to maximize either the width or height
1563bbeba09fSDaniel Vetter  *		while retaining the aspect ratio.
1564bbeba09fSDaniel Vetter  *
1565bbeba09fSDaniel Vetter  *	This property should be set up by calling
1566bbeba09fSDaniel Vetter  *	drm_connector_attach_scaling_mode_property(). Note that drivers
1567bbeba09fSDaniel Vetter  *	can also expose this property to external outputs, in which case they
1568bbeba09fSDaniel Vetter  *	must support "None", which should be the default (since external screens
1569bbeba09fSDaniel Vetter  *	have a built-in scaler).
1570e5b92773SOleg Vasilev  *
1571e5b92773SOleg Vasilev  * subconnector:
1572e5b92773SOleg Vasilev  *	This property is used by DVI-I, TVout and DisplayPort to indicate different
1573e5b92773SOleg Vasilev  *	connector subtypes. Enum values more or less match with those from main
1574e5b92773SOleg Vasilev  *	connector types.
1575e5b92773SOleg Vasilev  *	For DVI-I and TVout there is also a matching property "select subconnector"
1576e5b92773SOleg Vasilev  *	allowing to switch between signal types.
1577e5b92773SOleg Vasilev  *	DP subconnector corresponds to a downstream port.
1578107fe904SRajat Jain  *
1579107fe904SRajat Jain  * privacy-screen sw-state, privacy-screen hw-state:
1580107fe904SRajat Jain  *	These 2 optional properties can be used to query the state of the
1581107fe904SRajat Jain  *	electronic privacy screen that is available on some displays; and in
1582107fe904SRajat Jain  *	some cases also control the state. If a driver implements these
1583107fe904SRajat Jain  *	properties then both properties must be present.
1584107fe904SRajat Jain  *
1585107fe904SRajat Jain  *	"privacy-screen hw-state" is read-only and reflects the actual state
1586107fe904SRajat Jain  *	of the privacy-screen, possible values: "Enabled", "Disabled,
1587107fe904SRajat Jain  *	"Enabled-locked", "Disabled-locked". The locked states indicate
1588107fe904SRajat Jain  *	that the state cannot be changed through the DRM API. E.g. there
1589107fe904SRajat Jain  *	might be devices where the firmware-setup options, or a hardware
1590107fe904SRajat Jain  *	slider-switch, offer always on / off modes.
1591107fe904SRajat Jain  *
1592107fe904SRajat Jain  *	"privacy-screen sw-state" can be set to change the privacy-screen state
1593107fe904SRajat Jain  *	when not locked. In this case the driver must update the hw-state
1594107fe904SRajat Jain  *	property to reflect the new state on completion of the commit of the
1595107fe904SRajat Jain  *	sw-state property. Setting the sw-state property when the hw-state is
1596107fe904SRajat Jain  *	locked must be interpreted by the driver as a request to change the
1597107fe904SRajat Jain  *	state to the set state when the hw-state becomes unlocked. E.g. if
1598107fe904SRajat Jain  *	"privacy-screen hw-state" is "Enabled-locked" and the sw-state
1599107fe904SRajat Jain  *	gets set to "Disabled" followed by the user unlocking the state by
1600107fe904SRajat Jain  *	changing the slider-switch position, then the driver must set the
1601107fe904SRajat Jain  *	state to "Disabled" upon receiving the unlock event.
1602107fe904SRajat Jain  *
1603107fe904SRajat Jain  *	In some cases the privacy-screen's actual state might change outside of
1604107fe904SRajat Jain  *	control of the DRM code. E.g. there might be a firmware handled hotkey
1605107fe904SRajat Jain  *	which toggles the actual state, or the actual state might be changed
1606107fe904SRajat Jain  *	through another userspace API such as writing /proc/acpi/ibm/lcdshadow.
1607107fe904SRajat Jain  *	In this case the driver must update both the hw-state and the sw-state
1608107fe904SRajat Jain  *	to reflect the new value, overwriting any pending state requests in the
1609107fe904SRajat Jain  *	sw-state. Any pending sw-state requests are thus discarded.
1610107fe904SRajat Jain  *
1611107fe904SRajat Jain  *	Note that the ability for the state to change outside of control of
1612107fe904SRajat Jain  *	the DRM master process means that userspace must not cache the value
1613107fe904SRajat Jain  *	of the sw-state. Caching the sw-state value and including it in later
1614107fe904SRajat Jain  *	atomic commits may lead to overriding a state change done through e.g.
1615107fe904SRajat Jain  *	a firmware handled hotkey. Therefor userspace must not include the
1616107fe904SRajat Jain  *	privacy-screen sw-state in an atomic commit unless it wants to change
1617107fe904SRajat Jain  *	its value.
1618409f07d3SSimon Ser  *
1619409f07d3SSimon Ser  * left margin, right margin, top margin, bottom margin:
1620409f07d3SSimon Ser  *	Add margins to the connector's viewport. This is typically used to
16213cf15dc2SSimon Ser  *	mitigate overscan on TVs.
1622409f07d3SSimon Ser  *
1623409f07d3SSimon Ser  *	The value is the size in pixels of the black border which will be
1624409f07d3SSimon Ser  *	added. The attached CRTC's content will be scaled to fill the whole
1625409f07d3SSimon Ser  *	area inside the margin.
1626409f07d3SSimon Ser  *
1627409f07d3SSimon Ser  *	The margins configuration might be sent to the sink, e.g. via HDMI AVI
1628409f07d3SSimon Ser  *	InfoFrames.
1629409f07d3SSimon Ser  *
1630409f07d3SSimon Ser  *	Drivers can set up these properties by calling
1631409f07d3SSimon Ser  *	drm_mode_create_tv_margin_properties().
16324ada6f22SDaniel Vetter  */
16334ada6f22SDaniel Vetter 
163452217195SDaniel Vetter int drm_connector_create_standard_properties(struct drm_device *dev)
163552217195SDaniel Vetter {
163652217195SDaniel Vetter 	struct drm_property *prop;
163752217195SDaniel Vetter 
163852217195SDaniel Vetter 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
163952217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
164052217195SDaniel Vetter 				   "EDID", 0);
164152217195SDaniel Vetter 	if (!prop)
164252217195SDaniel Vetter 		return -ENOMEM;
164352217195SDaniel Vetter 	dev->mode_config.edid_property = prop;
164452217195SDaniel Vetter 
164552217195SDaniel Vetter 	prop = drm_property_create_enum(dev, 0,
164652217195SDaniel Vetter 				   "DPMS", drm_dpms_enum_list,
164752217195SDaniel Vetter 				   ARRAY_SIZE(drm_dpms_enum_list));
164852217195SDaniel Vetter 	if (!prop)
164952217195SDaniel Vetter 		return -ENOMEM;
165052217195SDaniel Vetter 	dev->mode_config.dpms_property = prop;
165152217195SDaniel Vetter 
165252217195SDaniel Vetter 	prop = drm_property_create(dev,
165352217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
165452217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
165552217195SDaniel Vetter 				   "PATH", 0);
165652217195SDaniel Vetter 	if (!prop)
165752217195SDaniel Vetter 		return -ENOMEM;
165852217195SDaniel Vetter 	dev->mode_config.path_property = prop;
165952217195SDaniel Vetter 
166052217195SDaniel Vetter 	prop = drm_property_create(dev,
166152217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
166252217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
166352217195SDaniel Vetter 				   "TILE", 0);
166452217195SDaniel Vetter 	if (!prop)
166552217195SDaniel Vetter 		return -ENOMEM;
166652217195SDaniel Vetter 	dev->mode_config.tile_property = prop;
166752217195SDaniel Vetter 
166840ee6fbeSManasi Navare 	prop = drm_property_create_enum(dev, 0, "link-status",
166940ee6fbeSManasi Navare 					drm_link_status_enum_list,
167040ee6fbeSManasi Navare 					ARRAY_SIZE(drm_link_status_enum_list));
167140ee6fbeSManasi Navare 	if (!prop)
167240ee6fbeSManasi Navare 		return -ENOMEM;
167340ee6fbeSManasi Navare 	dev->mode_config.link_status_property = prop;
167440ee6fbeSManasi Navare 
167566660d4cSDave Airlie 	prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
167666660d4cSDave Airlie 	if (!prop)
167766660d4cSDave Airlie 		return -ENOMEM;
167866660d4cSDave Airlie 	dev->mode_config.non_desktop_property = prop;
167966660d4cSDave Airlie 
1680fbb5d035SUma Shankar 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
1681fbb5d035SUma Shankar 				   "HDR_OUTPUT_METADATA", 0);
1682fbb5d035SUma Shankar 	if (!prop)
1683fbb5d035SUma Shankar 		return -ENOMEM;
1684fbb5d035SUma Shankar 	dev->mode_config.hdr_output_metadata_property = prop;
1685fbb5d035SUma Shankar 
168652217195SDaniel Vetter 	return 0;
168752217195SDaniel Vetter }
168852217195SDaniel Vetter 
168952217195SDaniel Vetter /**
169052217195SDaniel Vetter  * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
169152217195SDaniel Vetter  * @dev: DRM device
169252217195SDaniel Vetter  *
169352217195SDaniel Vetter  * Called by a driver the first time a DVI-I connector is made.
1694f85d9e59SRandy Dunlap  *
1695f85d9e59SRandy Dunlap  * Returns: %0
169652217195SDaniel Vetter  */
169752217195SDaniel Vetter int drm_mode_create_dvi_i_properties(struct drm_device *dev)
169852217195SDaniel Vetter {
169952217195SDaniel Vetter 	struct drm_property *dvi_i_selector;
170052217195SDaniel Vetter 	struct drm_property *dvi_i_subconnector;
170152217195SDaniel Vetter 
170252217195SDaniel Vetter 	if (dev->mode_config.dvi_i_select_subconnector_property)
170352217195SDaniel Vetter 		return 0;
170452217195SDaniel Vetter 
170552217195SDaniel Vetter 	dvi_i_selector =
170652217195SDaniel Vetter 		drm_property_create_enum(dev, 0,
170752217195SDaniel Vetter 				    "select subconnector",
170852217195SDaniel Vetter 				    drm_dvi_i_select_enum_list,
170952217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_select_enum_list));
171052217195SDaniel Vetter 	dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
171152217195SDaniel Vetter 
171252217195SDaniel Vetter 	dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
171352217195SDaniel Vetter 				    "subconnector",
171452217195SDaniel Vetter 				    drm_dvi_i_subconnector_enum_list,
171552217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
171652217195SDaniel Vetter 	dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
171752217195SDaniel Vetter 
171852217195SDaniel Vetter 	return 0;
171952217195SDaniel Vetter }
172052217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
172152217195SDaniel Vetter 
172252217195SDaniel Vetter /**
1723e5b92773SOleg Vasilev  * drm_connector_attach_dp_subconnector_property - create subconnector property for DP
1724e5b92773SOleg Vasilev  * @connector: drm_connector to attach property
1725e5b92773SOleg Vasilev  *
1726e5b92773SOleg Vasilev  * Called by a driver when DP connector is created.
1727e5b92773SOleg Vasilev  */
1728e5b92773SOleg Vasilev void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector)
1729e5b92773SOleg Vasilev {
1730e5b92773SOleg Vasilev 	struct drm_mode_config *mode_config = &connector->dev->mode_config;
1731e5b92773SOleg Vasilev 
1732e5b92773SOleg Vasilev 	if (!mode_config->dp_subconnector_property)
1733e5b92773SOleg Vasilev 		mode_config->dp_subconnector_property =
1734e5b92773SOleg Vasilev 			drm_property_create_enum(connector->dev,
1735e5b92773SOleg Vasilev 				DRM_MODE_PROP_IMMUTABLE,
1736e5b92773SOleg Vasilev 				"subconnector",
1737e5b92773SOleg Vasilev 				drm_dp_subconnector_enum_list,
1738e5b92773SOleg Vasilev 				ARRAY_SIZE(drm_dp_subconnector_enum_list));
1739e5b92773SOleg Vasilev 
1740e5b92773SOleg Vasilev 	drm_object_attach_property(&connector->base,
1741e5b92773SOleg Vasilev 				   mode_config->dp_subconnector_property,
1742e5b92773SOleg Vasilev 				   DRM_MODE_SUBCONNECTOR_Unknown);
1743e5b92773SOleg Vasilev }
1744e5b92773SOleg Vasilev EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property);
1745e5b92773SOleg Vasilev 
1746e5b92773SOleg Vasilev /**
174750525c33SStanislav Lisovskiy  * DOC: HDMI connector properties
174850525c33SStanislav Lisovskiy  *
1749ab52af4bSMaxime Ripard  * Broadcast RGB (HDMI specific)
1750ab52af4bSMaxime Ripard  *      Indicates the Quantization Range (Full vs Limited) used. The color
1751ab52af4bSMaxime Ripard  *      processing pipeline will be adjusted to match the value of the
1752ab52af4bSMaxime Ripard  *      property, and the Infoframes will be generated and sent accordingly.
1753ab52af4bSMaxime Ripard  *
1754ab52af4bSMaxime Ripard  *      This property is only relevant if the HDMI output format is RGB. If
1755ab52af4bSMaxime Ripard  *      it's one of the YCbCr variant, it will be ignored.
1756ab52af4bSMaxime Ripard  *
1757ab52af4bSMaxime Ripard  *      The CRTC attached to the connector must be configured by user-space to
1758ab52af4bSMaxime Ripard  *      always produce full-range pixels.
1759ab52af4bSMaxime Ripard  *
1760ab52af4bSMaxime Ripard  *      The value of this property can be one of the following:
1761ab52af4bSMaxime Ripard  *
1762ab52af4bSMaxime Ripard  *      Automatic:
1763ab52af4bSMaxime Ripard  *              The quantization range is selected automatically based on the
1764ab52af4bSMaxime Ripard  *              mode according to the HDMI specifications (HDMI 1.4b - Section
1765ab52af4bSMaxime Ripard  *              6.6 - Video Quantization Ranges).
1766ab52af4bSMaxime Ripard  *
1767ab52af4bSMaxime Ripard  *      Full:
1768ab52af4bSMaxime Ripard  *              Full quantization range is forced.
1769ab52af4bSMaxime Ripard  *
1770ab52af4bSMaxime Ripard  *      Limited 16:235:
1771ab52af4bSMaxime Ripard  *              Limited quantization range is forced. Unlike the name suggests,
1772ab52af4bSMaxime Ripard  *              this works for any number of bits-per-component.
1773ab52af4bSMaxime Ripard  *
1774ab52af4bSMaxime Ripard  *      Property values other than Automatic can result in colors being off (if
1775ab52af4bSMaxime Ripard  *      limited is selected but the display expects full), or a black screen
1776ab52af4bSMaxime Ripard  *      (if full is selected but the display expects limited).
1777ab52af4bSMaxime Ripard  *
1778ab52af4bSMaxime Ripard  *      Drivers can set up this property by calling
1779ab52af4bSMaxime Ripard  *      drm_connector_attach_broadcast_rgb_property().
1780ab52af4bSMaxime Ripard  *
178150525c33SStanislav Lisovskiy  * content type (HDMI specific):
178250525c33SStanislav Lisovskiy  *	Indicates content type setting to be used in HDMI infoframes to indicate
17831e55a53aSMatt Roper  *	content type for the external device, so that it adjusts its display
178450525c33SStanislav Lisovskiy  *	settings accordingly.
178550525c33SStanislav Lisovskiy  *
178650525c33SStanislav Lisovskiy  *	The value of this property can be one of the following:
178750525c33SStanislav Lisovskiy  *
178850525c33SStanislav Lisovskiy  *	No Data:
178950525c33SStanislav Lisovskiy  *		Content type is unknown
179050525c33SStanislav Lisovskiy  *	Graphics:
179150525c33SStanislav Lisovskiy  *		Content type is graphics
179250525c33SStanislav Lisovskiy  *	Photo:
179350525c33SStanislav Lisovskiy  *		Content type is photo
179450525c33SStanislav Lisovskiy  *	Cinema:
179550525c33SStanislav Lisovskiy  *		Content type is cinema
179650525c33SStanislav Lisovskiy  *	Game:
179750525c33SStanislav Lisovskiy  *		Content type is game
179850525c33SStanislav Lisovskiy  *
1799a0a33067SSimon Ser  *	The meaning of each content type is defined in CTA-861-G table 15.
1800a0a33067SSimon Ser  *
180150525c33SStanislav Lisovskiy  *	Drivers can set up this property by calling
180250525c33SStanislav Lisovskiy  *	drm_connector_attach_content_type_property(). Decoding to
1803ba609631SDaniel Vetter  *	infoframe values is done through drm_hdmi_avi_infoframe_content_type().
180450525c33SStanislav Lisovskiy  */
180550525c33SStanislav Lisovskiy 
18067d63cd85SMaxime Ripard /*
18077d63cd85SMaxime Ripard  * TODO: Document the properties:
18087d63cd85SMaxime Ripard  *   - brightness
18097d63cd85SMaxime Ripard  *   - contrast
18107d63cd85SMaxime Ripard  *   - flicker reduction
18117d63cd85SMaxime Ripard  *   - hue
18127d63cd85SMaxime Ripard  *   - mode
18137d63cd85SMaxime Ripard  *   - overscan
18147d63cd85SMaxime Ripard  *   - saturation
18157d63cd85SMaxime Ripard  *   - select subconnector
18167d63cd85SMaxime Ripard  */
18177d63cd85SMaxime Ripard /**
18187d63cd85SMaxime Ripard  * DOC: Analog TV Connector Properties
18197d63cd85SMaxime Ripard  *
18207d63cd85SMaxime Ripard  * TV Mode:
18217d63cd85SMaxime Ripard  *	Indicates the TV Mode used on an analog TV connector. The value
18227d63cd85SMaxime Ripard  *	of this property can be one of the following:
18237d63cd85SMaxime Ripard  *
18247d63cd85SMaxime Ripard  *	NTSC:
18257d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
18267d63cd85SMaxime Ripard  *		the NTSC Color Encoding.
18277d63cd85SMaxime Ripard  *
18287d63cd85SMaxime Ripard  *	NTSC-443:
18297d63cd85SMaxime Ripard  *
18307d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
18317d63cd85SMaxime Ripard  *		the NTSC Color Encoding, but with a color subcarrier
18327d63cd85SMaxime Ripard  *		frequency of 4.43MHz
18337d63cd85SMaxime Ripard  *
18347d63cd85SMaxime Ripard  *	NTSC-J:
18357d63cd85SMaxime Ripard  *
18367d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
18377d63cd85SMaxime Ripard  *		the NTSC Color Encoding, but with a black level equal to
18387d63cd85SMaxime Ripard  *		the blanking level.
18397d63cd85SMaxime Ripard  *
18407d63cd85SMaxime Ripard  *	PAL:
18417d63cd85SMaxime Ripard  *
18427d63cd85SMaxime Ripard  *		TV Mode is CCIR System B (aka 625-lines) together with
18437d63cd85SMaxime Ripard  *		the PAL Color Encoding.
18447d63cd85SMaxime Ripard  *
18457d63cd85SMaxime Ripard  *	PAL-M:
18467d63cd85SMaxime Ripard  *
18477d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
18487d63cd85SMaxime Ripard  *		the PAL Color Encoding.
18497d63cd85SMaxime Ripard  *
18507d63cd85SMaxime Ripard  *	PAL-N:
18517d63cd85SMaxime Ripard  *
18527d63cd85SMaxime Ripard  *		TV Mode is CCIR System N together with the PAL Color
18537d63cd85SMaxime Ripard  *		Encoding, a color subcarrier frequency of 3.58MHz, the
18547d63cd85SMaxime Ripard  *		SECAM color space, and narrower channels than other PAL
18557d63cd85SMaxime Ripard  *		variants.
18567d63cd85SMaxime Ripard  *
18577d63cd85SMaxime Ripard  *	SECAM:
18587d63cd85SMaxime Ripard  *
18597d63cd85SMaxime Ripard  *		TV Mode is CCIR System B (aka 625-lines) together with
18607d63cd85SMaxime Ripard  *		the SECAM Color Encoding.
18617d63cd85SMaxime Ripard  *
186241474d25SNick Hollinghurst  *	Mono:
186341474d25SNick Hollinghurst  *
186441474d25SNick Hollinghurst  *		Use timings appropriate to the DRM mode, including
186541474d25SNick Hollinghurst  *		equalizing pulses for a 525-line or 625-line mode,
186641474d25SNick Hollinghurst  *		with no pedestal or color encoding.
186741474d25SNick Hollinghurst  *
18687d63cd85SMaxime Ripard  *	Drivers can set up this property by calling
18697d63cd85SMaxime Ripard  *	drm_mode_create_tv_properties().
18707d63cd85SMaxime Ripard  */
18717d63cd85SMaxime Ripard 
187250525c33SStanislav Lisovskiy /**
187350525c33SStanislav Lisovskiy  * drm_connector_attach_content_type_property - attach content-type property
187450525c33SStanislav Lisovskiy  * @connector: connector to attach content type property on.
187550525c33SStanislav Lisovskiy  *
187650525c33SStanislav Lisovskiy  * Called by a driver the first time a HDMI connector is made.
1877f85d9e59SRandy Dunlap  *
1878f85d9e59SRandy Dunlap  * Returns: %0
187950525c33SStanislav Lisovskiy  */
188050525c33SStanislav Lisovskiy int drm_connector_attach_content_type_property(struct drm_connector *connector)
188150525c33SStanislav Lisovskiy {
188250525c33SStanislav Lisovskiy 	if (!drm_mode_create_content_type_property(connector->dev))
188350525c33SStanislav Lisovskiy 		drm_object_attach_property(&connector->base,
188450525c33SStanislav Lisovskiy 					   connector->dev->mode_config.content_type_property,
188550525c33SStanislav Lisovskiy 					   DRM_MODE_CONTENT_TYPE_NO_DATA);
188650525c33SStanislav Lisovskiy 	return 0;
188750525c33SStanislav Lisovskiy }
188850525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_connector_attach_content_type_property);
188950525c33SStanislav Lisovskiy 
189050525c33SStanislav Lisovskiy /**
1891e9d2871fSMauro Carvalho Chehab  * drm_connector_attach_tv_margin_properties - attach TV connector margin
1892e9d2871fSMauro Carvalho Chehab  * 	properties
18936c4f52dcSBoris Brezillon  * @connector: DRM connector
18946c4f52dcSBoris Brezillon  *
18956c4f52dcSBoris Brezillon  * Called by a driver when it needs to attach TV margin props to a connector.
18966c4f52dcSBoris Brezillon  * Typically used on SDTV and HDMI connectors.
18976c4f52dcSBoris Brezillon  */
18986c4f52dcSBoris Brezillon void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
18996c4f52dcSBoris Brezillon {
19006c4f52dcSBoris Brezillon 	struct drm_device *dev = connector->dev;
19016c4f52dcSBoris Brezillon 
19026c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
19036c4f52dcSBoris Brezillon 				   dev->mode_config.tv_left_margin_property,
19046c4f52dcSBoris Brezillon 				   0);
19056c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
19066c4f52dcSBoris Brezillon 				   dev->mode_config.tv_right_margin_property,
19076c4f52dcSBoris Brezillon 				   0);
19086c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
19096c4f52dcSBoris Brezillon 				   dev->mode_config.tv_top_margin_property,
19106c4f52dcSBoris Brezillon 				   0);
19116c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
19126c4f52dcSBoris Brezillon 				   dev->mode_config.tv_bottom_margin_property,
19136c4f52dcSBoris Brezillon 				   0);
19146c4f52dcSBoris Brezillon }
19156c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
19166c4f52dcSBoris Brezillon 
19176c4f52dcSBoris Brezillon /**
19186c4f52dcSBoris Brezillon  * drm_mode_create_tv_margin_properties - create TV connector margin properties
19196c4f52dcSBoris Brezillon  * @dev: DRM device
19206c4f52dcSBoris Brezillon  *
19216c4f52dcSBoris Brezillon  * Called by a driver's HDMI connector initialization routine, this function
19226c4f52dcSBoris Brezillon  * creates the TV margin properties for a given device. No need to call this
19236c4f52dcSBoris Brezillon  * function for an SDTV connector, it's already called from
192480ed86d4SMaxime Ripard  * drm_mode_create_tv_properties_legacy().
1925f85d9e59SRandy Dunlap  *
1926f85d9e59SRandy Dunlap  * Returns:
1927f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
19286c4f52dcSBoris Brezillon  */
19296c4f52dcSBoris Brezillon int drm_mode_create_tv_margin_properties(struct drm_device *dev)
19306c4f52dcSBoris Brezillon {
19316c4f52dcSBoris Brezillon 	if (dev->mode_config.tv_left_margin_property)
19326c4f52dcSBoris Brezillon 		return 0;
19336c4f52dcSBoris Brezillon 
19346c4f52dcSBoris Brezillon 	dev->mode_config.tv_left_margin_property =
19356c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "left margin", 0, 100);
19366c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_left_margin_property)
19376c4f52dcSBoris Brezillon 		return -ENOMEM;
19386c4f52dcSBoris Brezillon 
19396c4f52dcSBoris Brezillon 	dev->mode_config.tv_right_margin_property =
19406c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "right margin", 0, 100);
19416c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_right_margin_property)
19426c4f52dcSBoris Brezillon 		return -ENOMEM;
19436c4f52dcSBoris Brezillon 
19446c4f52dcSBoris Brezillon 	dev->mode_config.tv_top_margin_property =
19456c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "top margin", 0, 100);
19466c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_top_margin_property)
19476c4f52dcSBoris Brezillon 		return -ENOMEM;
19486c4f52dcSBoris Brezillon 
19496c4f52dcSBoris Brezillon 	dev->mode_config.tv_bottom_margin_property =
19506c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "bottom margin", 0, 100);
19516c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_bottom_margin_property)
19526c4f52dcSBoris Brezillon 		return -ENOMEM;
19536c4f52dcSBoris Brezillon 
19546c4f52dcSBoris Brezillon 	return 0;
19556c4f52dcSBoris Brezillon }
19566c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
19576c4f52dcSBoris Brezillon 
19586c4f52dcSBoris Brezillon /**
195980ed86d4SMaxime Ripard  * drm_mode_create_tv_properties_legacy - create TV specific connector properties
196052217195SDaniel Vetter  * @dev: DRM device
196152217195SDaniel Vetter  * @num_modes: number of different TV formats (modes) supported
196252217195SDaniel Vetter  * @modes: array of pointers to strings containing name of each format
196352217195SDaniel Vetter  *
196452217195SDaniel Vetter  * Called by a driver's TV initialization routine, this function creates
196552217195SDaniel Vetter  * the TV specific connector properties for a given device.  Caller is
196652217195SDaniel Vetter  * responsible for allocating a list of format names and passing them to
196752217195SDaniel Vetter  * this routine.
1968f85d9e59SRandy Dunlap  *
19697d63cd85SMaxime Ripard  * NOTE: This functions registers the deprecated "mode" connector
19707d63cd85SMaxime Ripard  * property to select the analog TV mode (ie, NTSC, PAL, etc.). New
19717d63cd85SMaxime Ripard  * drivers must use drm_mode_create_tv_properties() instead.
19727d63cd85SMaxime Ripard  *
1973f85d9e59SRandy Dunlap  * Returns:
1974f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
197552217195SDaniel Vetter  */
197680ed86d4SMaxime Ripard int drm_mode_create_tv_properties_legacy(struct drm_device *dev,
197752217195SDaniel Vetter 					 unsigned int num_modes,
197852217195SDaniel Vetter 					 const char * const modes[])
197952217195SDaniel Vetter {
198052217195SDaniel Vetter 	struct drm_property *tv_selector;
198152217195SDaniel Vetter 	struct drm_property *tv_subconnector;
198252217195SDaniel Vetter 	unsigned int i;
198352217195SDaniel Vetter 
198452217195SDaniel Vetter 	if (dev->mode_config.tv_select_subconnector_property)
198552217195SDaniel Vetter 		return 0;
198652217195SDaniel Vetter 
198752217195SDaniel Vetter 	/*
198852217195SDaniel Vetter 	 * Basic connector properties
198952217195SDaniel Vetter 	 */
199052217195SDaniel Vetter 	tv_selector = drm_property_create_enum(dev, 0,
199152217195SDaniel Vetter 					  "select subconnector",
199252217195SDaniel Vetter 					  drm_tv_select_enum_list,
199352217195SDaniel Vetter 					  ARRAY_SIZE(drm_tv_select_enum_list));
199452217195SDaniel Vetter 	if (!tv_selector)
199552217195SDaniel Vetter 		goto nomem;
199652217195SDaniel Vetter 
199752217195SDaniel Vetter 	dev->mode_config.tv_select_subconnector_property = tv_selector;
199852217195SDaniel Vetter 
199952217195SDaniel Vetter 	tv_subconnector =
200052217195SDaniel Vetter 		drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
200152217195SDaniel Vetter 				    "subconnector",
200252217195SDaniel Vetter 				    drm_tv_subconnector_enum_list,
200352217195SDaniel Vetter 				    ARRAY_SIZE(drm_tv_subconnector_enum_list));
200452217195SDaniel Vetter 	if (!tv_subconnector)
200552217195SDaniel Vetter 		goto nomem;
200652217195SDaniel Vetter 	dev->mode_config.tv_subconnector_property = tv_subconnector;
200752217195SDaniel Vetter 
200852217195SDaniel Vetter 	/*
200952217195SDaniel Vetter 	 * Other, TV specific properties: margins & TV modes.
201052217195SDaniel Vetter 	 */
20116c4f52dcSBoris Brezillon 	if (drm_mode_create_tv_margin_properties(dev))
201252217195SDaniel Vetter 		goto nomem;
201352217195SDaniel Vetter 
2014aab5aaa7SMaxime Ripard 	if (num_modes) {
20151fd4a5a3SMaxime Ripard 		dev->mode_config.legacy_tv_mode_property =
201652217195SDaniel Vetter 			drm_property_create(dev, DRM_MODE_PROP_ENUM,
201752217195SDaniel Vetter 					    "mode", num_modes);
20181fd4a5a3SMaxime Ripard 		if (!dev->mode_config.legacy_tv_mode_property)
201952217195SDaniel Vetter 			goto nomem;
202052217195SDaniel Vetter 
202152217195SDaniel Vetter 		for (i = 0; i < num_modes; i++)
20221fd4a5a3SMaxime Ripard 			drm_property_add_enum(dev->mode_config.legacy_tv_mode_property,
202352217195SDaniel Vetter 					      i, modes[i]);
2024aab5aaa7SMaxime Ripard 	}
202552217195SDaniel Vetter 
202652217195SDaniel Vetter 	dev->mode_config.tv_brightness_property =
202752217195SDaniel Vetter 		drm_property_create_range(dev, 0, "brightness", 0, 100);
202852217195SDaniel Vetter 	if (!dev->mode_config.tv_brightness_property)
202952217195SDaniel Vetter 		goto nomem;
203052217195SDaniel Vetter 
203152217195SDaniel Vetter 	dev->mode_config.tv_contrast_property =
203252217195SDaniel Vetter 		drm_property_create_range(dev, 0, "contrast", 0, 100);
203352217195SDaniel Vetter 	if (!dev->mode_config.tv_contrast_property)
203452217195SDaniel Vetter 		goto nomem;
203552217195SDaniel Vetter 
203652217195SDaniel Vetter 	dev->mode_config.tv_flicker_reduction_property =
203752217195SDaniel Vetter 		drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
203852217195SDaniel Vetter 	if (!dev->mode_config.tv_flicker_reduction_property)
203952217195SDaniel Vetter 		goto nomem;
204052217195SDaniel Vetter 
204152217195SDaniel Vetter 	dev->mode_config.tv_overscan_property =
204252217195SDaniel Vetter 		drm_property_create_range(dev, 0, "overscan", 0, 100);
204352217195SDaniel Vetter 	if (!dev->mode_config.tv_overscan_property)
204452217195SDaniel Vetter 		goto nomem;
204552217195SDaniel Vetter 
204652217195SDaniel Vetter 	dev->mode_config.tv_saturation_property =
204752217195SDaniel Vetter 		drm_property_create_range(dev, 0, "saturation", 0, 100);
204852217195SDaniel Vetter 	if (!dev->mode_config.tv_saturation_property)
204952217195SDaniel Vetter 		goto nomem;
205052217195SDaniel Vetter 
205152217195SDaniel Vetter 	dev->mode_config.tv_hue_property =
205252217195SDaniel Vetter 		drm_property_create_range(dev, 0, "hue", 0, 100);
205352217195SDaniel Vetter 	if (!dev->mode_config.tv_hue_property)
205452217195SDaniel Vetter 		goto nomem;
205552217195SDaniel Vetter 
205652217195SDaniel Vetter 	return 0;
205752217195SDaniel Vetter nomem:
205852217195SDaniel Vetter 	return -ENOMEM;
205952217195SDaniel Vetter }
206080ed86d4SMaxime Ripard EXPORT_SYMBOL(drm_mode_create_tv_properties_legacy);
206152217195SDaniel Vetter 
206252217195SDaniel Vetter /**
20637d63cd85SMaxime Ripard  * drm_mode_create_tv_properties - create TV specific connector properties
20647d63cd85SMaxime Ripard  * @dev: DRM device
20657d63cd85SMaxime Ripard  * @supported_tv_modes: Bitmask of TV modes supported (See DRM_MODE_TV_MODE_*)
206604ee2767SRandy Dunlap  *
20677d63cd85SMaxime Ripard  * Called by a driver's TV initialization routine, this function creates
20687d63cd85SMaxime Ripard  * the TV specific connector properties for a given device.
20697d63cd85SMaxime Ripard  *
20707d63cd85SMaxime Ripard  * Returns:
20717d63cd85SMaxime Ripard  * 0 on success or a negative error code on failure.
20727d63cd85SMaxime Ripard  */
20737d63cd85SMaxime Ripard int drm_mode_create_tv_properties(struct drm_device *dev,
20747d63cd85SMaxime Ripard 				  unsigned int supported_tv_modes)
20757d63cd85SMaxime Ripard {
20767d63cd85SMaxime Ripard 	struct drm_prop_enum_list tv_mode_list[DRM_MODE_TV_MODE_MAX];
20777d63cd85SMaxime Ripard 	struct drm_property *tv_mode;
20787d63cd85SMaxime Ripard 	unsigned int i, len = 0;
20797d63cd85SMaxime Ripard 
20807d63cd85SMaxime Ripard 	if (dev->mode_config.tv_mode_property)
20817d63cd85SMaxime Ripard 		return 0;
20827d63cd85SMaxime Ripard 
20837d63cd85SMaxime Ripard 	for (i = 0; i < DRM_MODE_TV_MODE_MAX; i++) {
20847d63cd85SMaxime Ripard 		if (!(supported_tv_modes & BIT(i)))
20857d63cd85SMaxime Ripard 			continue;
20867d63cd85SMaxime Ripard 
20877d63cd85SMaxime Ripard 		tv_mode_list[len].type = i;
20887d63cd85SMaxime Ripard 		tv_mode_list[len].name = drm_get_tv_mode_name(i);
20897d63cd85SMaxime Ripard 		len++;
20907d63cd85SMaxime Ripard 	}
20917d63cd85SMaxime Ripard 
20927d63cd85SMaxime Ripard 	tv_mode = drm_property_create_enum(dev, 0, "TV mode",
20937d63cd85SMaxime Ripard 					   tv_mode_list, len);
20947d63cd85SMaxime Ripard 	if (!tv_mode)
20957d63cd85SMaxime Ripard 		return -ENOMEM;
20967d63cd85SMaxime Ripard 
20977d63cd85SMaxime Ripard 	dev->mode_config.tv_mode_property = tv_mode;
20987d63cd85SMaxime Ripard 
20997d63cd85SMaxime Ripard 	return drm_mode_create_tv_properties_legacy(dev, 0, NULL);
21007d63cd85SMaxime Ripard }
21017d63cd85SMaxime Ripard EXPORT_SYMBOL(drm_mode_create_tv_properties);
21027d63cd85SMaxime Ripard 
21037d63cd85SMaxime Ripard /**
210452217195SDaniel Vetter  * drm_mode_create_scaling_mode_property - create scaling mode property
210552217195SDaniel Vetter  * @dev: DRM device
210652217195SDaniel Vetter  *
210752217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
210852217195SDaniel Vetter  * connectors.
21098f6e1e22SMaarten Lankhorst  *
21108f6e1e22SMaarten Lankhorst  * Atomic drivers should use drm_connector_attach_scaling_mode_property()
21119c2fce13SVille Syrjälä  * instead to correctly assign &drm_connector_state.scaling_mode
21128f6e1e22SMaarten Lankhorst  * in the atomic state.
2113f85d9e59SRandy Dunlap  *
2114f85d9e59SRandy Dunlap  * Returns: %0
211552217195SDaniel Vetter  */
211652217195SDaniel Vetter int drm_mode_create_scaling_mode_property(struct drm_device *dev)
211752217195SDaniel Vetter {
211852217195SDaniel Vetter 	struct drm_property *scaling_mode;
211952217195SDaniel Vetter 
212052217195SDaniel Vetter 	if (dev->mode_config.scaling_mode_property)
212152217195SDaniel Vetter 		return 0;
212252217195SDaniel Vetter 
212352217195SDaniel Vetter 	scaling_mode =
212452217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "scaling mode",
212552217195SDaniel Vetter 				drm_scaling_mode_enum_list,
212652217195SDaniel Vetter 				    ARRAY_SIZE(drm_scaling_mode_enum_list));
212752217195SDaniel Vetter 
212852217195SDaniel Vetter 	dev->mode_config.scaling_mode_property = scaling_mode;
212952217195SDaniel Vetter 
213052217195SDaniel Vetter 	return 0;
213152217195SDaniel Vetter }
213252217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
213352217195SDaniel Vetter 
213452217195SDaniel Vetter /**
2135ab7a664fSNicholas Kazlauskas  * DOC: Variable refresh properties
2136ab7a664fSNicholas Kazlauskas  *
2137ab7a664fSNicholas Kazlauskas  * Variable refresh rate capable displays can dynamically adjust their
2138ab7a664fSNicholas Kazlauskas  * refresh rate by extending the duration of their vertical front porch
2139ab7a664fSNicholas Kazlauskas  * until page flip or timeout occurs. This can reduce or remove stuttering
2140ab7a664fSNicholas Kazlauskas  * and latency in scenarios where the page flip does not align with the
2141ab7a664fSNicholas Kazlauskas  * vblank interval.
2142ab7a664fSNicholas Kazlauskas  *
2143ab7a664fSNicholas Kazlauskas  * An example scenario would be an application flipping at a constant rate
2144ab7a664fSNicholas Kazlauskas  * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
2145ab7a664fSNicholas Kazlauskas  * interval and the same contents will be displayed twice. This can be
2146ab7a664fSNicholas Kazlauskas  * observed as stuttering for content with motion.
2147ab7a664fSNicholas Kazlauskas  *
2148ab7a664fSNicholas Kazlauskas  * If variable refresh rate was active on a display that supported a
2149ab7a664fSNicholas Kazlauskas  * variable refresh range from 35Hz to 60Hz no stuttering would be observable
2150ab7a664fSNicholas Kazlauskas  * for the example scenario. The minimum supported variable refresh rate of
2151ab7a664fSNicholas Kazlauskas  * 35Hz is below the page flip frequency and the vertical front porch can
2152ab7a664fSNicholas Kazlauskas  * be extended until the page flip occurs. The vblank interval will be
2153ab7a664fSNicholas Kazlauskas  * directly aligned to the page flip rate.
2154ab7a664fSNicholas Kazlauskas  *
2155ab7a664fSNicholas Kazlauskas  * Not all userspace content is suitable for use with variable refresh rate.
2156ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may worsen
2157ab7a664fSNicholas Kazlauskas  * perceived stuttering for input sensitive applications.
2158ab7a664fSNicholas Kazlauskas  *
2159ab7a664fSNicholas Kazlauskas  * Panel brightness will also vary with vertical front porch duration. Some
2160ab7a664fSNicholas Kazlauskas  * panels may have noticeable differences in brightness between the minimum
2161ab7a664fSNicholas Kazlauskas  * vertical front porch duration and the maximum vertical front porch duration.
2162ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may produce
2163ab7a664fSNicholas Kazlauskas  * observable flickering for such panels.
2164ab7a664fSNicholas Kazlauskas  *
2165ab7a664fSNicholas Kazlauskas  * Userspace control for variable refresh rate is supported via properties
2166ab7a664fSNicholas Kazlauskas  * on the &drm_connector and &drm_crtc objects.
2167ab7a664fSNicholas Kazlauskas  *
2168ab7a664fSNicholas Kazlauskas  * "vrr_capable":
2169ab7a664fSNicholas Kazlauskas  *	Optional &drm_connector boolean property that drivers should attach
2170ab7a664fSNicholas Kazlauskas  *	with drm_connector_attach_vrr_capable_property() on connectors that
2171ab7a664fSNicholas Kazlauskas  *	could support variable refresh rates. Drivers should update the
2172ab7a664fSNicholas Kazlauskas  *	property value by calling drm_connector_set_vrr_capable_property().
2173ab7a664fSNicholas Kazlauskas  *
2174ab7a664fSNicholas Kazlauskas  *	Absence of the property should indicate absence of support.
2175ab7a664fSNicholas Kazlauskas  *
217677086014SDaniel Vetter  * "VRR_ENABLED":
2177ab7a664fSNicholas Kazlauskas  *	Default &drm_crtc boolean property that notifies the driver that the
2178ab7a664fSNicholas Kazlauskas  *	content on the CRTC is suitable for variable refresh rate presentation.
2179ab7a664fSNicholas Kazlauskas  *	The driver will take this property as a hint to enable variable
2180ab7a664fSNicholas Kazlauskas  *	refresh rate support if the receiver supports it, ie. if the
2181ab7a664fSNicholas Kazlauskas  *	"vrr_capable" property is true on the &drm_connector object. The
2182ab7a664fSNicholas Kazlauskas  *	vertical front porch duration will be extended until page-flip or
2183ab7a664fSNicholas Kazlauskas  *	timeout when enabled.
2184ab7a664fSNicholas Kazlauskas  *
2185ab7a664fSNicholas Kazlauskas  *	The minimum vertical front porch duration is defined as the vertical
2186ab7a664fSNicholas Kazlauskas  *	front porch duration for the current mode.
2187ab7a664fSNicholas Kazlauskas  *
2188ab7a664fSNicholas Kazlauskas  *	The maximum vertical front porch duration is greater than or equal to
2189ab7a664fSNicholas Kazlauskas  *	the minimum vertical front porch duration. The duration is derived
2190ab7a664fSNicholas Kazlauskas  *	from the minimum supported variable refresh rate for the connector.
2191ab7a664fSNicholas Kazlauskas  *
2192ab7a664fSNicholas Kazlauskas  *	The driver may place further restrictions within these minimum
2193ab7a664fSNicholas Kazlauskas  *	and maximum bounds.
2194ab7a664fSNicholas Kazlauskas  */
2195ab7a664fSNicholas Kazlauskas 
2196ab7a664fSNicholas Kazlauskas /**
2197ba1b0f6cSNicholas Kazlauskas  * drm_connector_attach_vrr_capable_property - creates the
2198ba1b0f6cSNicholas Kazlauskas  * vrr_capable property
2199ba1b0f6cSNicholas Kazlauskas  * @connector: connector to create the vrr_capable property on.
2200ba1b0f6cSNicholas Kazlauskas  *
2201ba1b0f6cSNicholas Kazlauskas  * This is used by atomic drivers to add support for querying
2202ba1b0f6cSNicholas Kazlauskas  * variable refresh rate capability for a connector.
2203ba1b0f6cSNicholas Kazlauskas  *
2204ba1b0f6cSNicholas Kazlauskas  * Returns:
220584e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
2206ba1b0f6cSNicholas Kazlauskas  */
2207ba1b0f6cSNicholas Kazlauskas int drm_connector_attach_vrr_capable_property(
2208ba1b0f6cSNicholas Kazlauskas 	struct drm_connector *connector)
2209ba1b0f6cSNicholas Kazlauskas {
2210ba1b0f6cSNicholas Kazlauskas 	struct drm_device *dev = connector->dev;
2211ba1b0f6cSNicholas Kazlauskas 	struct drm_property *prop;
2212ba1b0f6cSNicholas Kazlauskas 
2213ba1b0f6cSNicholas Kazlauskas 	if (!connector->vrr_capable_property) {
2214ba1b0f6cSNicholas Kazlauskas 		prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
2215ba1b0f6cSNicholas Kazlauskas 			"vrr_capable");
2216ba1b0f6cSNicholas Kazlauskas 		if (!prop)
2217ba1b0f6cSNicholas Kazlauskas 			return -ENOMEM;
2218ba1b0f6cSNicholas Kazlauskas 
2219ba1b0f6cSNicholas Kazlauskas 		connector->vrr_capable_property = prop;
2220ba1b0f6cSNicholas Kazlauskas 		drm_object_attach_property(&connector->base, prop, 0);
2221ba1b0f6cSNicholas Kazlauskas 	}
2222ba1b0f6cSNicholas Kazlauskas 
2223ba1b0f6cSNicholas Kazlauskas 	return 0;
2224ba1b0f6cSNicholas Kazlauskas }
2225ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
2226ba1b0f6cSNicholas Kazlauskas 
2227ba1b0f6cSNicholas Kazlauskas /**
22288f6e1e22SMaarten Lankhorst  * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
22298f6e1e22SMaarten Lankhorst  * @connector: connector to attach scaling mode property on.
22308f6e1e22SMaarten Lankhorst  * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
22318f6e1e22SMaarten Lankhorst  *
22328f6e1e22SMaarten Lankhorst  * This is used to add support for scaling mode to atomic drivers.
22339c2fce13SVille Syrjälä  * The scaling mode will be set to &drm_connector_state.scaling_mode
22348f6e1e22SMaarten Lankhorst  * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
22358f6e1e22SMaarten Lankhorst  *
22368f6e1e22SMaarten Lankhorst  * This is the atomic version of drm_mode_create_scaling_mode_property().
22378f6e1e22SMaarten Lankhorst  *
22388f6e1e22SMaarten Lankhorst  * Returns:
22398f6e1e22SMaarten Lankhorst  * Zero on success, negative errno on failure.
22408f6e1e22SMaarten Lankhorst  */
22418f6e1e22SMaarten Lankhorst int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
22428f6e1e22SMaarten Lankhorst 					       u32 scaling_mode_mask)
22438f6e1e22SMaarten Lankhorst {
22448f6e1e22SMaarten Lankhorst 	struct drm_device *dev = connector->dev;
22458f6e1e22SMaarten Lankhorst 	struct drm_property *scaling_mode_property;
224630e9db6dSVille Syrjälä 	int i;
22478f6e1e22SMaarten Lankhorst 	const unsigned valid_scaling_mode_mask =
22488f6e1e22SMaarten Lankhorst 		(1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
22498f6e1e22SMaarten Lankhorst 
22508f6e1e22SMaarten Lankhorst 	if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
22518f6e1e22SMaarten Lankhorst 		    scaling_mode_mask & ~valid_scaling_mode_mask))
22528f6e1e22SMaarten Lankhorst 		return -EINVAL;
22538f6e1e22SMaarten Lankhorst 
22548f6e1e22SMaarten Lankhorst 	scaling_mode_property =
22558f6e1e22SMaarten Lankhorst 		drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
22568f6e1e22SMaarten Lankhorst 				    hweight32(scaling_mode_mask));
22578f6e1e22SMaarten Lankhorst 
22588f6e1e22SMaarten Lankhorst 	if (!scaling_mode_property)
22598f6e1e22SMaarten Lankhorst 		return -ENOMEM;
22608f6e1e22SMaarten Lankhorst 
22618f6e1e22SMaarten Lankhorst 	for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
22628f6e1e22SMaarten Lankhorst 		int ret;
22638f6e1e22SMaarten Lankhorst 
22648f6e1e22SMaarten Lankhorst 		if (!(BIT(i) & scaling_mode_mask))
22658f6e1e22SMaarten Lankhorst 			continue;
22668f6e1e22SMaarten Lankhorst 
226730e9db6dSVille Syrjälä 		ret = drm_property_add_enum(scaling_mode_property,
22688f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].type,
22698f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].name);
22708f6e1e22SMaarten Lankhorst 
22718f6e1e22SMaarten Lankhorst 		if (ret) {
22728f6e1e22SMaarten Lankhorst 			drm_property_destroy(dev, scaling_mode_property);
22738f6e1e22SMaarten Lankhorst 
22748f6e1e22SMaarten Lankhorst 			return ret;
22758f6e1e22SMaarten Lankhorst 		}
22768f6e1e22SMaarten Lankhorst 	}
22778f6e1e22SMaarten Lankhorst 
22788f6e1e22SMaarten Lankhorst 	drm_object_attach_property(&connector->base,
22798f6e1e22SMaarten Lankhorst 				   scaling_mode_property, 0);
22808f6e1e22SMaarten Lankhorst 
22818f6e1e22SMaarten Lankhorst 	connector->scaling_mode_property = scaling_mode_property;
22828f6e1e22SMaarten Lankhorst 
22838f6e1e22SMaarten Lankhorst 	return 0;
22848f6e1e22SMaarten Lankhorst }
22858f6e1e22SMaarten Lankhorst EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
22868f6e1e22SMaarten Lankhorst 
22878f6e1e22SMaarten Lankhorst /**
228852217195SDaniel Vetter  * drm_mode_create_aspect_ratio_property - create aspect ratio property
228952217195SDaniel Vetter  * @dev: DRM device
229052217195SDaniel Vetter  *
229152217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
229252217195SDaniel Vetter  * connectors.
229352217195SDaniel Vetter  *
229452217195SDaniel Vetter  * Returns:
229552217195SDaniel Vetter  * Zero on success, negative errno on failure.
229652217195SDaniel Vetter  */
229752217195SDaniel Vetter int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
229852217195SDaniel Vetter {
229952217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property)
230052217195SDaniel Vetter 		return 0;
230152217195SDaniel Vetter 
230252217195SDaniel Vetter 	dev->mode_config.aspect_ratio_property =
230352217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "aspect ratio",
230452217195SDaniel Vetter 				drm_aspect_ratio_enum_list,
230552217195SDaniel Vetter 				ARRAY_SIZE(drm_aspect_ratio_enum_list));
230652217195SDaniel Vetter 
230752217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property == NULL)
230852217195SDaniel Vetter 		return -ENOMEM;
230952217195SDaniel Vetter 
231052217195SDaniel Vetter 	return 0;
231152217195SDaniel Vetter }
231252217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
231352217195SDaniel Vetter 
231452217195SDaniel Vetter /**
2315d2c6a405SUma Shankar  * DOC: standard connector properties
2316d2c6a405SUma Shankar  *
2317d2c6a405SUma Shankar  * Colorspace:
2318*f592e016SSebastian Wick  *	This property is used to inform the driver about the color encoding
2319*f592e016SSebastian Wick  *	user space configured the pixel operation properties to produce.
2320*f592e016SSebastian Wick  *	The variants set the colorimetry, transfer characteristics, and which
2321*f592e016SSebastian Wick  *	YCbCr conversion should be used when necessary.
2322*f592e016SSebastian Wick  *	The transfer characteristics from HDR_OUTPUT_METADATA takes precedence
2323*f592e016SSebastian Wick  *	over this property.
2324*f592e016SSebastian Wick  *	User space always configures the pixel operation properties to produce
2325*f592e016SSebastian Wick  *	full quantization range data (see the Broadcast RGB property).
2326d2c6a405SUma Shankar  *
2327*f592e016SSebastian Wick  *	Drivers inform the sink about what colorimetry, transfer
2328*f592e016SSebastian Wick  *	characteristics, YCbCr conversion, and quantization range to expect
2329*f592e016SSebastian Wick  *	(this can depend on the output mode, output format and other
2330*f592e016SSebastian Wick  *	properties). Drivers also convert the user space provided data to what
2331*f592e016SSebastian Wick  *	the sink expects.
2332d2c6a405SUma Shankar  *
2333*f592e016SSebastian Wick  *	User space has to check if the sink supports all of the possible
2334*f592e016SSebastian Wick  *	colorimetries that the driver is allowed to pick by parsing the EDID.
2335*f592e016SSebastian Wick  *
2336*f592e016SSebastian Wick  *	For historical reasons this property exposes a number of variants which
2337*f592e016SSebastian Wick  *	result in undefined behavior.
2338*f592e016SSebastian Wick  *
2339*f592e016SSebastian Wick  *	Default:
2340*f592e016SSebastian Wick  *		The behavior is driver-specific.
2341*f592e016SSebastian Wick  *	BT2020_RGB:
2342*f592e016SSebastian Wick  *	BT2020_YCC:
2343*f592e016SSebastian Wick  *		User space configures the pixel operation properties to produce
2344*f592e016SSebastian Wick  *		RGB content with Rec. ITU-R BT.2020 colorimetry, Rec.
2345*f592e016SSebastian Wick  *		ITU-R BT.2020 (Table 4, RGB) transfer characteristics and full
2346*f592e016SSebastian Wick  *		quantization range.
2347*f592e016SSebastian Wick  *		User space can use the HDR_OUTPUT_METADATA property to set the
2348*f592e016SSebastian Wick  *		transfer characteristics to PQ (Rec. ITU-R BT.2100 Table 4) or
2349*f592e016SSebastian Wick  *		HLG (Rec. ITU-R BT.2100 Table 5) in which case, user space
2350*f592e016SSebastian Wick  *		configures pixel operation properties to produce content with
2351*f592e016SSebastian Wick  *		the respective transfer characteristics.
2352*f592e016SSebastian Wick  *		User space has to make sure the sink supports Rec.
2353*f592e016SSebastian Wick  *		ITU-R BT.2020 R'G'B' and Rec. ITU-R BT.2020 Y'C'BC'R
2354*f592e016SSebastian Wick  *		colorimetry.
2355*f592e016SSebastian Wick  *		Drivers can configure the sink to use an RGB format, tell the
2356*f592e016SSebastian Wick  *		sink to expect Rec. ITU-R BT.2020 R'G'B' colorimetry and convert
2357*f592e016SSebastian Wick  *		to the appropriate quantization range.
2358*f592e016SSebastian Wick  *		Drivers can configure the sink to use a YCbCr format, tell the
2359*f592e016SSebastian Wick  *		sink to expect Rec. ITU-R BT.2020 Y'C'BC'R colorimetry, convert
2360*f592e016SSebastian Wick  *		to YCbCr using the Rec. ITU-R BT.2020 non-constant luminance
2361*f592e016SSebastian Wick  *		conversion matrix and convert to the appropriate quantization
2362*f592e016SSebastian Wick  *		range.
2363*f592e016SSebastian Wick  *		The variants BT2020_RGB and BT2020_YCC are equivalent and the
2364*f592e016SSebastian Wick  *		driver chooses between RGB and YCbCr on its own.
2365*f592e016SSebastian Wick  *	SMPTE_170M_YCC:
2366*f592e016SSebastian Wick  *	BT709_YCC:
2367*f592e016SSebastian Wick  *	XVYCC_601:
2368*f592e016SSebastian Wick  *	XVYCC_709:
2369*f592e016SSebastian Wick  *	SYCC_601:
2370*f592e016SSebastian Wick  *	opYCC_601:
2371*f592e016SSebastian Wick  *	opRGB:
2372*f592e016SSebastian Wick  *	BT2020_CYCC:
2373*f592e016SSebastian Wick  *	DCI-P3_RGB_D65:
2374*f592e016SSebastian Wick  *	DCI-P3_RGB_Theater:
2375*f592e016SSebastian Wick  *	RGB_WIDE_FIXED:
2376*f592e016SSebastian Wick  *	RGB_WIDE_FLOAT:
2377*f592e016SSebastian Wick  *	BT601_YCC:
2378*f592e016SSebastian Wick  *		The behavior is undefined.
2379d2c6a405SUma Shankar  *
23808806cd3aSGwan-gyeong Mun  * Because between HDMI and DP have different colorspaces,
238145cf0e91SGwan-gyeong Mun  * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and
238245cf0e91SGwan-gyeong Mun  * drm_mode_create_dp_colorspace_property() is used for DP connector.
2383d2c6a405SUma Shankar  */
23848806cd3aSGwan-gyeong Mun 
23856120611aSHarry Wentland static int drm_mode_create_colorspace_property(struct drm_connector *connector,
2386c627087cSHarry Wentland 					u32 supported_colorspaces)
23876120611aSHarry Wentland {
23886120611aSHarry Wentland 	struct drm_device *dev = connector->dev;
2389c627087cSHarry Wentland 	u32 colorspaces = supported_colorspaces | BIT(DRM_MODE_COLORIMETRY_DEFAULT);
2390c627087cSHarry Wentland 	struct drm_prop_enum_list enum_list[DRM_MODE_COLORIMETRY_COUNT];
2391c627087cSHarry Wentland 	int i, len;
23926120611aSHarry Wentland 
23936120611aSHarry Wentland 	if (connector->colorspace_property)
23946120611aSHarry Wentland 		return 0;
23956120611aSHarry Wentland 
2396c627087cSHarry Wentland 	if (!supported_colorspaces) {
2397c627087cSHarry Wentland 		drm_err(dev, "No supported colorspaces provded on [CONNECTOR:%d:%s]\n",
2398c627087cSHarry Wentland 			    connector->base.id, connector->name);
2399c627087cSHarry Wentland 		return -EINVAL;
2400c627087cSHarry Wentland 	}
2401c627087cSHarry Wentland 
2402c627087cSHarry Wentland 	if ((supported_colorspaces & -BIT(DRM_MODE_COLORIMETRY_COUNT)) != 0) {
2403c627087cSHarry Wentland 		drm_err(dev, "Unknown colorspace provded on [CONNECTOR:%d:%s]\n",
2404c627087cSHarry Wentland 			    connector->base.id, connector->name);
2405c627087cSHarry Wentland 		return -EINVAL;
2406c627087cSHarry Wentland 	}
2407c627087cSHarry Wentland 
2408c627087cSHarry Wentland 	len = 0;
2409c627087cSHarry Wentland 	for (i = 0; i < DRM_MODE_COLORIMETRY_COUNT; i++) {
2410c627087cSHarry Wentland 		if ((colorspaces & BIT(i)) == 0)
2411c627087cSHarry Wentland 			continue;
2412c627087cSHarry Wentland 
2413c627087cSHarry Wentland 		enum_list[len].type = i;
2414c627087cSHarry Wentland 		enum_list[len].name = colorspace_names[i];
2415c627087cSHarry Wentland 		len++;
2416c627087cSHarry Wentland 	}
24176120611aSHarry Wentland 
24186120611aSHarry Wentland 	connector->colorspace_property =
24196120611aSHarry Wentland 		drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
2420c627087cSHarry Wentland 					enum_list,
2421c627087cSHarry Wentland 					len);
24226120611aSHarry Wentland 
24236120611aSHarry Wentland 	if (!connector->colorspace_property)
24246120611aSHarry Wentland 		return -ENOMEM;
24256120611aSHarry Wentland 
24266120611aSHarry Wentland 	return 0;
24276120611aSHarry Wentland }
2428c627087cSHarry Wentland 
24298806cd3aSGwan-gyeong Mun /**
24308806cd3aSGwan-gyeong Mun  * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
24318806cd3aSGwan-gyeong Mun  * @connector: connector to create the Colorspace property on.
24320c3b063eSLee Jones  * @supported_colorspaces: bitmap of supported color spaces
24338806cd3aSGwan-gyeong Mun  *
24348806cd3aSGwan-gyeong Mun  * Called by a driver the first time it's needed, must be attached to desired
24358806cd3aSGwan-gyeong Mun  * HDMI connectors.
24368806cd3aSGwan-gyeong Mun  *
24378806cd3aSGwan-gyeong Mun  * Returns:
243884e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
24398806cd3aSGwan-gyeong Mun  */
2440c265f340SHarry Wentland int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector,
2441c265f340SHarry Wentland 					     u32 supported_colorspaces)
2442d2c6a405SUma Shankar {
2443c265f340SHarry Wentland 	u32 colorspaces;
2444c265f340SHarry Wentland 
2445c265f340SHarry Wentland 	if (supported_colorspaces)
2446c265f340SHarry Wentland 		colorspaces = supported_colorspaces & hdmi_colorspaces;
2447c265f340SHarry Wentland 	else
2448c265f340SHarry Wentland 		colorspaces = hdmi_colorspaces;
2449c265f340SHarry Wentland 
2450c265f340SHarry Wentland 	return drm_mode_create_colorspace_property(connector, colorspaces);
2451d2c6a405SUma Shankar }
24528806cd3aSGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
2453d2c6a405SUma Shankar 
2454d2c6a405SUma Shankar /**
245545cf0e91SGwan-gyeong Mun  * drm_mode_create_dp_colorspace_property - create dp colorspace property
245645cf0e91SGwan-gyeong Mun  * @connector: connector to create the Colorspace property on.
24570c3b063eSLee Jones  * @supported_colorspaces: bitmap of supported color spaces
245845cf0e91SGwan-gyeong Mun  *
245945cf0e91SGwan-gyeong Mun  * Called by a driver the first time it's needed, must be attached to desired
246045cf0e91SGwan-gyeong Mun  * DP connectors.
246145cf0e91SGwan-gyeong Mun  *
246245cf0e91SGwan-gyeong Mun  * Returns:
246384e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
246445cf0e91SGwan-gyeong Mun  */
2465c265f340SHarry Wentland int drm_mode_create_dp_colorspace_property(struct drm_connector *connector,
2466c265f340SHarry Wentland 					   u32 supported_colorspaces)
246745cf0e91SGwan-gyeong Mun {
2468c265f340SHarry Wentland 	u32 colorspaces;
2469c265f340SHarry Wentland 
2470c265f340SHarry Wentland 	if (supported_colorspaces)
2471c265f340SHarry Wentland 		colorspaces = supported_colorspaces & dp_colorspaces;
2472c265f340SHarry Wentland 	else
2473c265f340SHarry Wentland 		colorspaces = dp_colorspaces;
2474c265f340SHarry Wentland 
2475c265f340SHarry Wentland 	return drm_mode_create_colorspace_property(connector, colorspaces);
247645cf0e91SGwan-gyeong Mun }
247745cf0e91SGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
247852217195SDaniel Vetter 
247997e14fbeSDaniel Vetter /**
248052217195SDaniel Vetter  * drm_mode_create_content_type_property - create content type property
248152217195SDaniel Vetter  * @dev: DRM device
248297e14fbeSDaniel Vetter  *
248352217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
248452217195SDaniel Vetter  * connectors.
248552217195SDaniel Vetter  *
248652217195SDaniel Vetter  * Returns:
248752217195SDaniel Vetter  * Zero on success, negative errno on failure.
248852217195SDaniel Vetter  */
248952217195SDaniel Vetter int drm_mode_create_content_type_property(struct drm_device *dev)
249052217195SDaniel Vetter {
249152217195SDaniel Vetter 	if (dev->mode_config.content_type_property)
249297e14fbeSDaniel Vetter 		return 0;
249352217195SDaniel Vetter 
249452217195SDaniel Vetter 	dev->mode_config.content_type_property =
249552217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "content type",
249652217195SDaniel Vetter 					 drm_content_type_enum_list,
249752217195SDaniel Vetter 					 ARRAY_SIZE(drm_content_type_enum_list));
249852217195SDaniel Vetter 
249952217195SDaniel Vetter 	if (dev->mode_config.content_type_property == NULL)
250052217195SDaniel Vetter 		return -ENOMEM;
250152217195SDaniel Vetter 
250252217195SDaniel Vetter 	return 0;
250352217195SDaniel Vetter }
250452217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_content_type_property);
250552217195SDaniel Vetter 
250652217195SDaniel Vetter /**
250752217195SDaniel Vetter  * drm_mode_create_suggested_offset_properties - create suggests offset properties
250852217195SDaniel Vetter  * @dev: DRM device
250952217195SDaniel Vetter  *
251084e543bcSAntonio Borneo  * Create the suggested x/y offset property for connectors.
2511f85d9e59SRandy Dunlap  *
2512f85d9e59SRandy Dunlap  * Returns:
2513f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
251452217195SDaniel Vetter  */
251552217195SDaniel Vetter int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
251652217195SDaniel Vetter {
251752217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
251852217195SDaniel Vetter 		return 0;
251952217195SDaniel Vetter 
252052217195SDaniel Vetter 	dev->mode_config.suggested_x_property =
252152217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
252252217195SDaniel Vetter 
252352217195SDaniel Vetter 	dev->mode_config.suggested_y_property =
252452217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
252552217195SDaniel Vetter 
252652217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property == NULL ||
252752217195SDaniel Vetter 	    dev->mode_config.suggested_y_property == NULL)
252852217195SDaniel Vetter 		return -ENOMEM;
252952217195SDaniel Vetter 	return 0;
253052217195SDaniel Vetter }
253152217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
253252217195SDaniel Vetter 
253352217195SDaniel Vetter /**
253452217195SDaniel Vetter  * drm_connector_set_path_property - set tile property on connector
253552217195SDaniel Vetter  * @connector: connector to set property on.
253652217195SDaniel Vetter  * @path: path to use for property; must not be NULL.
253752217195SDaniel Vetter  *
253852217195SDaniel Vetter  * This creates a property to expose to userspace to specify a
253952217195SDaniel Vetter  * connector path. This is mainly used for DisplayPort MST where
254052217195SDaniel Vetter  * connectors have a topology and we want to allow userspace to give
254152217195SDaniel Vetter  * them more meaningful names.
254252217195SDaniel Vetter  *
254352217195SDaniel Vetter  * Returns:
254452217195SDaniel Vetter  * Zero on success, negative errno on failure.
254552217195SDaniel Vetter  */
254652217195SDaniel Vetter int drm_connector_set_path_property(struct drm_connector *connector,
254752217195SDaniel Vetter 				    const char *path)
254852217195SDaniel Vetter {
254952217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
255052217195SDaniel Vetter 	int ret;
255152217195SDaniel Vetter 
255252217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
255352217195SDaniel Vetter 					       &connector->path_blob_ptr,
255452217195SDaniel Vetter 					       strlen(path) + 1,
255552217195SDaniel Vetter 					       path,
255652217195SDaniel Vetter 					       &connector->base,
255752217195SDaniel Vetter 					       dev->mode_config.path_property);
255852217195SDaniel Vetter 	return ret;
255952217195SDaniel Vetter }
256052217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_set_path_property);
256152217195SDaniel Vetter 
256252217195SDaniel Vetter /**
256352217195SDaniel Vetter  * drm_connector_set_tile_property - set tile property on connector
256452217195SDaniel Vetter  * @connector: connector to set property on.
256552217195SDaniel Vetter  *
256652217195SDaniel Vetter  * This looks up the tile information for a connector, and creates a
256752217195SDaniel Vetter  * property for userspace to parse if it exists. The property is of
256852217195SDaniel Vetter  * the form of 8 integers using ':' as a separator.
25692de3a078SManasi Navare  * This is used for dual port tiled displays with DisplayPort SST
25702de3a078SManasi Navare  * or DisplayPort MST connectors.
257152217195SDaniel Vetter  *
257252217195SDaniel Vetter  * Returns:
257352217195SDaniel Vetter  * Zero on success, errno on failure.
257452217195SDaniel Vetter  */
257552217195SDaniel Vetter int drm_connector_set_tile_property(struct drm_connector *connector)
257652217195SDaniel Vetter {
257752217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
257852217195SDaniel Vetter 	char tile[256];
257952217195SDaniel Vetter 	int ret;
258052217195SDaniel Vetter 
258152217195SDaniel Vetter 	if (!connector->has_tile) {
258252217195SDaniel Vetter 		ret  = drm_property_replace_global_blob(dev,
258352217195SDaniel Vetter 							&connector->tile_blob_ptr,
258452217195SDaniel Vetter 							0,
258552217195SDaniel Vetter 							NULL,
258652217195SDaniel Vetter 							&connector->base,
258752217195SDaniel Vetter 							dev->mode_config.tile_property);
258852217195SDaniel Vetter 		return ret;
258952217195SDaniel Vetter 	}
259052217195SDaniel Vetter 
259152217195SDaniel Vetter 	snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
259252217195SDaniel Vetter 		 connector->tile_group->id, connector->tile_is_single_monitor,
259352217195SDaniel Vetter 		 connector->num_h_tile, connector->num_v_tile,
259452217195SDaniel Vetter 		 connector->tile_h_loc, connector->tile_v_loc,
259552217195SDaniel Vetter 		 connector->tile_h_size, connector->tile_v_size);
259652217195SDaniel Vetter 
259752217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
259852217195SDaniel Vetter 					       &connector->tile_blob_ptr,
259952217195SDaniel Vetter 					       strlen(tile) + 1,
260052217195SDaniel Vetter 					       tile,
260152217195SDaniel Vetter 					       &connector->base,
260252217195SDaniel Vetter 					       dev->mode_config.tile_property);
260352217195SDaniel Vetter 	return ret;
260452217195SDaniel Vetter }
260597e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_tile_property);
260652217195SDaniel Vetter 
260752217195SDaniel Vetter /**
260897e14fbeSDaniel Vetter  * drm_connector_set_link_status_property - Set link status property of a connector
260940ee6fbeSManasi Navare  * @connector: drm connector
261040ee6fbeSManasi Navare  * @link_status: new value of link status property (0: Good, 1: Bad)
261140ee6fbeSManasi Navare  *
261240ee6fbeSManasi Navare  * In usual working scenario, this link status property will always be set to
261340ee6fbeSManasi Navare  * "GOOD". If something fails during or after a mode set, the kernel driver
261440ee6fbeSManasi Navare  * may set this link status property to "BAD". The caller then needs to send a
261540ee6fbeSManasi Navare  * hotplug uevent for userspace to re-check the valid modes through
261640ee6fbeSManasi Navare  * GET_CONNECTOR_IOCTL and retry modeset.
261740ee6fbeSManasi Navare  *
261840ee6fbeSManasi Navare  * Note: Drivers cannot rely on userspace to support this property and
261940ee6fbeSManasi Navare  * issue a modeset. As such, they may choose to handle issues (like
262040ee6fbeSManasi Navare  * re-training a link) without userspace's intervention.
262140ee6fbeSManasi Navare  *
262240ee6fbeSManasi Navare  * The reason for adding this property is to handle link training failures, but
262340ee6fbeSManasi Navare  * it is not limited to DP or link training. For example, if we implement
262440ee6fbeSManasi Navare  * asynchronous setcrtc, this property can be used to report any failures in that.
262540ee6fbeSManasi Navare  */
262697e14fbeSDaniel Vetter void drm_connector_set_link_status_property(struct drm_connector *connector,
262740ee6fbeSManasi Navare 					    uint64_t link_status)
262840ee6fbeSManasi Navare {
262940ee6fbeSManasi Navare 	struct drm_device *dev = connector->dev;
263040ee6fbeSManasi Navare 
263140ee6fbeSManasi Navare 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
263240ee6fbeSManasi Navare 	connector->state->link_status = link_status;
263340ee6fbeSManasi Navare 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
263440ee6fbeSManasi Navare }
263597e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_link_status_property);
263640ee6fbeSManasi Navare 
26378d70f395SHans de Goede /**
263847e22ff1SRadhakrishna Sripada  * drm_connector_attach_max_bpc_property - attach "max bpc" property
263947e22ff1SRadhakrishna Sripada  * @connector: connector to attach max bpc property on.
264047e22ff1SRadhakrishna Sripada  * @min: The minimum bit depth supported by the connector.
264147e22ff1SRadhakrishna Sripada  * @max: The maximum bit depth supported by the connector.
264247e22ff1SRadhakrishna Sripada  *
264347e22ff1SRadhakrishna Sripada  * This is used to add support for limiting the bit depth on a connector.
264447e22ff1SRadhakrishna Sripada  *
264547e22ff1SRadhakrishna Sripada  * Returns:
264647e22ff1SRadhakrishna Sripada  * Zero on success, negative errno on failure.
264747e22ff1SRadhakrishna Sripada  */
264847e22ff1SRadhakrishna Sripada int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
264947e22ff1SRadhakrishna Sripada 					  int min, int max)
265047e22ff1SRadhakrishna Sripada {
265147e22ff1SRadhakrishna Sripada 	struct drm_device *dev = connector->dev;
265247e22ff1SRadhakrishna Sripada 	struct drm_property *prop;
265347e22ff1SRadhakrishna Sripada 
265447e22ff1SRadhakrishna Sripada 	prop = connector->max_bpc_property;
265547e22ff1SRadhakrishna Sripada 	if (!prop) {
265647e22ff1SRadhakrishna Sripada 		prop = drm_property_create_range(dev, 0, "max bpc", min, max);
265747e22ff1SRadhakrishna Sripada 		if (!prop)
265847e22ff1SRadhakrishna Sripada 			return -ENOMEM;
265947e22ff1SRadhakrishna Sripada 
266047e22ff1SRadhakrishna Sripada 		connector->max_bpc_property = prop;
266147e22ff1SRadhakrishna Sripada 	}
266247e22ff1SRadhakrishna Sripada 
266347e22ff1SRadhakrishna Sripada 	drm_object_attach_property(&connector->base, prop, max);
266447e22ff1SRadhakrishna Sripada 	connector->state->max_requested_bpc = max;
266547e22ff1SRadhakrishna Sripada 	connector->state->max_bpc = max;
266647e22ff1SRadhakrishna Sripada 
266747e22ff1SRadhakrishna Sripada 	return 0;
266847e22ff1SRadhakrishna Sripada }
266947e22ff1SRadhakrishna Sripada EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
267047e22ff1SRadhakrishna Sripada 
267147e22ff1SRadhakrishna Sripada /**
2672e057b52cSMaxime Ripard  * drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADA" property
2673e057b52cSMaxime Ripard  * @connector: connector to attach the property on.
2674e057b52cSMaxime Ripard  *
2675e057b52cSMaxime Ripard  * This is used to allow the userspace to send HDR Metadata to the
2676e057b52cSMaxime Ripard  * driver.
2677e057b52cSMaxime Ripard  *
2678e057b52cSMaxime Ripard  * Returns:
2679e057b52cSMaxime Ripard  * Zero on success, negative errno on failure.
2680e057b52cSMaxime Ripard  */
2681e057b52cSMaxime Ripard int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector)
2682e057b52cSMaxime Ripard {
2683e057b52cSMaxime Ripard 	struct drm_device *dev = connector->dev;
2684e057b52cSMaxime Ripard 	struct drm_property *prop = dev->mode_config.hdr_output_metadata_property;
2685e057b52cSMaxime Ripard 
2686e057b52cSMaxime Ripard 	drm_object_attach_property(&connector->base, prop, 0);
2687e057b52cSMaxime Ripard 
2688e057b52cSMaxime Ripard 	return 0;
2689e057b52cSMaxime Ripard }
2690e057b52cSMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property);
2691e057b52cSMaxime Ripard 
2692e057b52cSMaxime Ripard /**
2693ab52af4bSMaxime Ripard  * drm_connector_attach_broadcast_rgb_property - attach "Broadcast RGB" property
2694ab52af4bSMaxime Ripard  * @connector: connector to attach the property on.
2695ab52af4bSMaxime Ripard  *
2696ab52af4bSMaxime Ripard  * This is used to add support for forcing the RGB range on a connector
2697ab52af4bSMaxime Ripard  *
2698ab52af4bSMaxime Ripard  * Returns:
2699ab52af4bSMaxime Ripard  * Zero on success, negative errno on failure.
2700ab52af4bSMaxime Ripard  */
2701ab52af4bSMaxime Ripard int drm_connector_attach_broadcast_rgb_property(struct drm_connector *connector)
2702ab52af4bSMaxime Ripard {
2703ab52af4bSMaxime Ripard 	struct drm_device *dev = connector->dev;
2704ab52af4bSMaxime Ripard 	struct drm_property *prop;
2705ab52af4bSMaxime Ripard 
2706ab52af4bSMaxime Ripard 	prop = connector->broadcast_rgb_property;
2707ab52af4bSMaxime Ripard 	if (!prop) {
2708ab52af4bSMaxime Ripard 		prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
2709ab52af4bSMaxime Ripard 						"Broadcast RGB",
2710ab52af4bSMaxime Ripard 						broadcast_rgb_names,
2711ab52af4bSMaxime Ripard 						ARRAY_SIZE(broadcast_rgb_names));
2712ab52af4bSMaxime Ripard 		if (!prop)
2713ab52af4bSMaxime Ripard 			return -EINVAL;
2714ab52af4bSMaxime Ripard 
2715ab52af4bSMaxime Ripard 		connector->broadcast_rgb_property = prop;
2716ab52af4bSMaxime Ripard 	}
2717ab52af4bSMaxime Ripard 
2718ab52af4bSMaxime Ripard 	drm_object_attach_property(&connector->base, prop,
2719ab52af4bSMaxime Ripard 				   DRM_HDMI_BROADCAST_RGB_AUTO);
2720ab52af4bSMaxime Ripard 
2721ab52af4bSMaxime Ripard 	return 0;
2722ab52af4bSMaxime Ripard }
2723ab52af4bSMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_broadcast_rgb_property);
2724ab52af4bSMaxime Ripard 
2725ab52af4bSMaxime Ripard /**
272621f79128SMaxime Ripard  * drm_connector_attach_colorspace_property - attach "Colorspace" property
272721f79128SMaxime Ripard  * @connector: connector to attach the property on.
272821f79128SMaxime Ripard  *
272921f79128SMaxime Ripard  * This is used to allow the userspace to signal the output colorspace
273021f79128SMaxime Ripard  * to the driver.
273121f79128SMaxime Ripard  *
273221f79128SMaxime Ripard  * Returns:
273321f79128SMaxime Ripard  * Zero on success, negative errno on failure.
273421f79128SMaxime Ripard  */
273521f79128SMaxime Ripard int drm_connector_attach_colorspace_property(struct drm_connector *connector)
273621f79128SMaxime Ripard {
273721f79128SMaxime Ripard 	struct drm_property *prop = connector->colorspace_property;
273821f79128SMaxime Ripard 
273921f79128SMaxime Ripard 	drm_object_attach_property(&connector->base, prop, DRM_MODE_COLORIMETRY_DEFAULT);
274021f79128SMaxime Ripard 
274121f79128SMaxime Ripard 	return 0;
274221f79128SMaxime Ripard }
274321f79128SMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_colorspace_property);
274421f79128SMaxime Ripard 
274521f79128SMaxime Ripard /**
274672921cdfSMaxime Ripard  * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed
274772921cdfSMaxime Ripard  * @old_state: old connector state to compare
274872921cdfSMaxime Ripard  * @new_state: new connector state to compare
274972921cdfSMaxime Ripard  *
275072921cdfSMaxime Ripard  * This is used by HDR-enabled drivers to test whether the HDR metadata
275172921cdfSMaxime Ripard  * have changed between two different connector state (and thus probably
275272921cdfSMaxime Ripard  * requires a full blown mode change).
275372921cdfSMaxime Ripard  *
275472921cdfSMaxime Ripard  * Returns:
275572921cdfSMaxime Ripard  * True if the metadata are equal, False otherwise
275672921cdfSMaxime Ripard  */
275772921cdfSMaxime Ripard bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state,
275872921cdfSMaxime Ripard 					     struct drm_connector_state *new_state)
275972921cdfSMaxime Ripard {
276072921cdfSMaxime Ripard 	struct drm_property_blob *old_blob = old_state->hdr_output_metadata;
276172921cdfSMaxime Ripard 	struct drm_property_blob *new_blob = new_state->hdr_output_metadata;
276272921cdfSMaxime Ripard 
276372921cdfSMaxime Ripard 	if (!old_blob || !new_blob)
276472921cdfSMaxime Ripard 		return old_blob == new_blob;
276572921cdfSMaxime Ripard 
276672921cdfSMaxime Ripard 	if (old_blob->length != new_blob->length)
276772921cdfSMaxime Ripard 		return false;
276872921cdfSMaxime Ripard 
276972921cdfSMaxime Ripard 	return !memcmp(old_blob->data, new_blob->data, old_blob->length);
277072921cdfSMaxime Ripard }
277172921cdfSMaxime Ripard EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal);
277272921cdfSMaxime Ripard 
277372921cdfSMaxime Ripard /**
2774ba1b0f6cSNicholas Kazlauskas  * drm_connector_set_vrr_capable_property - sets the variable refresh rate
2775ba1b0f6cSNicholas Kazlauskas  * capable property for a connector
2776ba1b0f6cSNicholas Kazlauskas  * @connector: drm connector
2777ba1b0f6cSNicholas Kazlauskas  * @capable: True if the connector is variable refresh rate capable
2778ba1b0f6cSNicholas Kazlauskas  *
2779ba1b0f6cSNicholas Kazlauskas  * Should be used by atomic drivers to update the indicated support for
2780ba1b0f6cSNicholas Kazlauskas  * variable refresh rate over a connector.
2781ba1b0f6cSNicholas Kazlauskas  */
2782ba1b0f6cSNicholas Kazlauskas void drm_connector_set_vrr_capable_property(
2783ba1b0f6cSNicholas Kazlauskas 		struct drm_connector *connector, bool capable)
2784ba1b0f6cSNicholas Kazlauskas {
278562929726SManasi Navare 	if (!connector->vrr_capable_property)
278662929726SManasi Navare 		return;
278762929726SManasi Navare 
2788ba1b0f6cSNicholas Kazlauskas 	drm_object_property_set_value(&connector->base,
2789ba1b0f6cSNicholas Kazlauskas 				      connector->vrr_capable_property,
2790ba1b0f6cSNicholas Kazlauskas 				      capable);
2791ba1b0f6cSNicholas Kazlauskas }
2792ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
2793ba1b0f6cSNicholas Kazlauskas 
2794ba1b0f6cSNicholas Kazlauskas /**
279584e543bcSAntonio Borneo  * drm_connector_set_panel_orientation - sets the connector's panel_orientation
279669654c63SDerek Basehore  * @connector: connector for which to set the panel-orientation property.
279769654c63SDerek Basehore  * @panel_orientation: drm_panel_orientation value to set
27988d70f395SHans de Goede  *
279969654c63SDerek Basehore  * This function sets the connector's panel_orientation and attaches
280069654c63SDerek Basehore  * a "panel orientation" property to the connector.
28018d70f395SHans de Goede  *
280269654c63SDerek Basehore  * Calling this function on a connector where the panel_orientation has
280369654c63SDerek Basehore  * already been set is a no-op (e.g. the orientation has been overridden with
280469654c63SDerek Basehore  * a kernel commandline option).
280569654c63SDerek Basehore  *
280669654c63SDerek Basehore  * It is allowed to call this function with a panel_orientation of
280769654c63SDerek Basehore  * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
28088d70f395SHans de Goede  *
28095e41b01aSHsin-Yi Wang  * The function shouldn't be called in panel after drm is registered (i.e.
28105e41b01aSHsin-Yi Wang  * drm_dev_register() is called in drm).
28115e41b01aSHsin-Yi Wang  *
28128d70f395SHans de Goede  * Returns:
28138d70f395SHans de Goede  * Zero on success, negative errno on failure.
28148d70f395SHans de Goede  */
281569654c63SDerek Basehore int drm_connector_set_panel_orientation(
281669654c63SDerek Basehore 	struct drm_connector *connector,
281769654c63SDerek Basehore 	enum drm_panel_orientation panel_orientation)
28188d70f395SHans de Goede {
28198d70f395SHans de Goede 	struct drm_device *dev = connector->dev;
28208d70f395SHans de Goede 	struct drm_display_info *info = &connector->display_info;
28218d70f395SHans de Goede 	struct drm_property *prop;
28228d70f395SHans de Goede 
282369654c63SDerek Basehore 	/* Already set? */
282469654c63SDerek Basehore 	if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
28258d70f395SHans de Goede 		return 0;
28268d70f395SHans de Goede 
282769654c63SDerek Basehore 	/* Don't attach the property if the orientation is unknown */
282869654c63SDerek Basehore 	if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
282969654c63SDerek Basehore 		return 0;
283069654c63SDerek Basehore 
283169654c63SDerek Basehore 	info->panel_orientation = panel_orientation;
283269654c63SDerek Basehore 
28338d70f395SHans de Goede 	prop = dev->mode_config.panel_orientation_property;
28348d70f395SHans de Goede 	if (!prop) {
28358d70f395SHans de Goede 		prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
28368d70f395SHans de Goede 				"panel orientation",
28378d70f395SHans de Goede 				drm_panel_orientation_enum_list,
28388d70f395SHans de Goede 				ARRAY_SIZE(drm_panel_orientation_enum_list));
28398d70f395SHans de Goede 		if (!prop)
28408d70f395SHans de Goede 			return -ENOMEM;
28418d70f395SHans de Goede 
28428d70f395SHans de Goede 		dev->mode_config.panel_orientation_property = prop;
28438d70f395SHans de Goede 	}
28448d70f395SHans de Goede 
28458d70f395SHans de Goede 	drm_object_attach_property(&connector->base, prop,
28468d70f395SHans de Goede 				   info->panel_orientation);
28478d70f395SHans de Goede 	return 0;
28488d70f395SHans de Goede }
284969654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation);
285069654c63SDerek Basehore 
285169654c63SDerek Basehore /**
2852f85d9e59SRandy Dunlap  * drm_connector_set_panel_orientation_with_quirk - set the
2853f85d9e59SRandy Dunlap  *	connector's panel_orientation after checking for quirks
285469654c63SDerek Basehore  * @connector: connector for which to init the panel-orientation property.
285569654c63SDerek Basehore  * @panel_orientation: drm_panel_orientation value to set
285669654c63SDerek Basehore  * @width: width in pixels of the panel, used for panel quirk detection
285769654c63SDerek Basehore  * @height: height in pixels of the panel, used for panel quirk detection
285869654c63SDerek Basehore  *
285969654c63SDerek Basehore  * Like drm_connector_set_panel_orientation(), but with a check for platform
286069654c63SDerek Basehore  * specific (e.g. DMI based) quirks overriding the passed in panel_orientation.
286169654c63SDerek Basehore  *
286269654c63SDerek Basehore  * Returns:
286369654c63SDerek Basehore  * Zero on success, negative errno on failure.
286469654c63SDerek Basehore  */
286569654c63SDerek Basehore int drm_connector_set_panel_orientation_with_quirk(
286669654c63SDerek Basehore 	struct drm_connector *connector,
286769654c63SDerek Basehore 	enum drm_panel_orientation panel_orientation,
286869654c63SDerek Basehore 	int width, int height)
286969654c63SDerek Basehore {
287069654c63SDerek Basehore 	int orientation_quirk;
287169654c63SDerek Basehore 
287269654c63SDerek Basehore 	orientation_quirk = drm_get_panel_orientation_quirk(width, height);
287369654c63SDerek Basehore 	if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
287469654c63SDerek Basehore 		panel_orientation = orientation_quirk;
287569654c63SDerek Basehore 
287669654c63SDerek Basehore 	return drm_connector_set_panel_orientation(connector,
287769654c63SDerek Basehore 						   panel_orientation);
287869654c63SDerek Basehore }
287969654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
28808d70f395SHans de Goede 
28815e41b01aSHsin-Yi Wang /**
28825e41b01aSHsin-Yi Wang  * drm_connector_set_orientation_from_panel -
28835e41b01aSHsin-Yi Wang  *	set the connector's panel_orientation from panel's callback.
28845e41b01aSHsin-Yi Wang  * @connector: connector for which to init the panel-orientation property.
28855e41b01aSHsin-Yi Wang  * @panel: panel that can provide orientation information.
28865e41b01aSHsin-Yi Wang  *
28875e41b01aSHsin-Yi Wang  * Drm drivers should call this function before drm_dev_register().
28885e41b01aSHsin-Yi Wang  * Orientation is obtained from panel's .get_orientation() callback.
28895e41b01aSHsin-Yi Wang  *
28905e41b01aSHsin-Yi Wang  * Returns:
28915e41b01aSHsin-Yi Wang  * Zero on success, negative errno on failure.
28925e41b01aSHsin-Yi Wang  */
28935e41b01aSHsin-Yi Wang int drm_connector_set_orientation_from_panel(
28945e41b01aSHsin-Yi Wang 	struct drm_connector *connector,
28955e41b01aSHsin-Yi Wang 	struct drm_panel *panel)
28965e41b01aSHsin-Yi Wang {
28975e41b01aSHsin-Yi Wang 	enum drm_panel_orientation orientation;
28985e41b01aSHsin-Yi Wang 
28995e41b01aSHsin-Yi Wang 	if (panel && panel->funcs && panel->funcs->get_orientation)
29005e41b01aSHsin-Yi Wang 		orientation = panel->funcs->get_orientation(panel);
29015e41b01aSHsin-Yi Wang 	else
29025e41b01aSHsin-Yi Wang 		orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
29035e41b01aSHsin-Yi Wang 
29045e41b01aSHsin-Yi Wang 	return drm_connector_set_panel_orientation(connector, orientation);
29055e41b01aSHsin-Yi Wang }
29065e41b01aSHsin-Yi Wang EXPORT_SYMBOL(drm_connector_set_orientation_from_panel);
29075e41b01aSHsin-Yi Wang 
2908107fe904SRajat Jain static const struct drm_prop_enum_list privacy_screen_enum[] = {
2909107fe904SRajat Jain 	{ PRIVACY_SCREEN_DISABLED,		"Disabled" },
2910107fe904SRajat Jain 	{ PRIVACY_SCREEN_ENABLED,		"Enabled" },
2911107fe904SRajat Jain 	{ PRIVACY_SCREEN_DISABLED_LOCKED,	"Disabled-locked" },
2912107fe904SRajat Jain 	{ PRIVACY_SCREEN_ENABLED_LOCKED,	"Enabled-locked" },
2913107fe904SRajat Jain };
2914107fe904SRajat Jain 
2915107fe904SRajat Jain /**
2916107fe904SRajat Jain  * drm_connector_create_privacy_screen_properties - create the drm connecter's
2917107fe904SRajat Jain  *    privacy-screen properties.
2918107fe904SRajat Jain  * @connector: connector for which to create the privacy-screen properties
2919107fe904SRajat Jain  *
2920107fe904SRajat Jain  * This function creates the "privacy-screen sw-state" and "privacy-screen
2921107fe904SRajat Jain  * hw-state" properties for the connector. They are not attached.
2922107fe904SRajat Jain  */
2923107fe904SRajat Jain void
2924107fe904SRajat Jain drm_connector_create_privacy_screen_properties(struct drm_connector *connector)
2925107fe904SRajat Jain {
2926107fe904SRajat Jain 	if (connector->privacy_screen_sw_state_property)
2927107fe904SRajat Jain 		return;
2928107fe904SRajat Jain 
2929107fe904SRajat Jain 	/* Note sw-state only supports the first 2 values of the enum */
2930107fe904SRajat Jain 	connector->privacy_screen_sw_state_property =
2931107fe904SRajat Jain 		drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM,
2932107fe904SRajat Jain 				"privacy-screen sw-state",
2933107fe904SRajat Jain 				privacy_screen_enum, 2);
2934107fe904SRajat Jain 
2935107fe904SRajat Jain 	connector->privacy_screen_hw_state_property =
2936107fe904SRajat Jain 		drm_property_create_enum(connector->dev,
2937107fe904SRajat Jain 				DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM,
2938107fe904SRajat Jain 				"privacy-screen hw-state",
2939107fe904SRajat Jain 				privacy_screen_enum,
2940107fe904SRajat Jain 				ARRAY_SIZE(privacy_screen_enum));
2941107fe904SRajat Jain }
2942107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties);
2943107fe904SRajat Jain 
2944107fe904SRajat Jain /**
2945107fe904SRajat Jain  * drm_connector_attach_privacy_screen_properties - attach the drm connecter's
2946107fe904SRajat Jain  *    privacy-screen properties.
2947107fe904SRajat Jain  * @connector: connector on which to attach the privacy-screen properties
2948107fe904SRajat Jain  *
2949107fe904SRajat Jain  * This function attaches the "privacy-screen sw-state" and "privacy-screen
2950107fe904SRajat Jain  * hw-state" properties to the connector. The initial state of both is set
2951107fe904SRajat Jain  * to "Disabled".
2952107fe904SRajat Jain  */
2953107fe904SRajat Jain void
2954107fe904SRajat Jain drm_connector_attach_privacy_screen_properties(struct drm_connector *connector)
2955107fe904SRajat Jain {
2956107fe904SRajat Jain 	if (!connector->privacy_screen_sw_state_property)
2957107fe904SRajat Jain 		return;
2958107fe904SRajat Jain 
2959107fe904SRajat Jain 	drm_object_attach_property(&connector->base,
2960107fe904SRajat Jain 				   connector->privacy_screen_sw_state_property,
2961107fe904SRajat Jain 				   PRIVACY_SCREEN_DISABLED);
2962107fe904SRajat Jain 
2963107fe904SRajat Jain 	drm_object_attach_property(&connector->base,
2964107fe904SRajat Jain 				   connector->privacy_screen_hw_state_property,
2965107fe904SRajat Jain 				   PRIVACY_SCREEN_DISABLED);
2966107fe904SRajat Jain }
2967107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties);
2968107fe904SRajat Jain 
2969334f74eeSHans de Goede static void drm_connector_update_privacy_screen_properties(
2970334f74eeSHans de Goede 	struct drm_connector *connector, bool set_sw_state)
2971334f74eeSHans de Goede {
2972334f74eeSHans de Goede 	enum drm_privacy_screen_status sw_state, hw_state;
2973334f74eeSHans de Goede 
2974334f74eeSHans de Goede 	drm_privacy_screen_get_state(connector->privacy_screen,
2975334f74eeSHans de Goede 				     &sw_state, &hw_state);
2976334f74eeSHans de Goede 
2977334f74eeSHans de Goede 	if (set_sw_state)
2978334f74eeSHans de Goede 		connector->state->privacy_screen_sw_state = sw_state;
2979334f74eeSHans de Goede 	drm_object_property_set_value(&connector->base,
2980334f74eeSHans de Goede 			connector->privacy_screen_hw_state_property, hw_state);
2981334f74eeSHans de Goede }
2982334f74eeSHans de Goede 
2983334f74eeSHans de Goede static int drm_connector_privacy_screen_notifier(
2984334f74eeSHans de Goede 	struct notifier_block *nb, unsigned long action, void *data)
2985334f74eeSHans de Goede {
2986334f74eeSHans de Goede 	struct drm_connector *connector =
2987334f74eeSHans de Goede 		container_of(nb, struct drm_connector, privacy_screen_notifier);
2988334f74eeSHans de Goede 	struct drm_device *dev = connector->dev;
2989334f74eeSHans de Goede 
2990334f74eeSHans de Goede 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2991334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, true);
2992334f74eeSHans de Goede 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
2993334f74eeSHans de Goede 
29940cf8d292SSimon Ser 	drm_sysfs_connector_property_event(connector,
2995334f74eeSHans de Goede 					   connector->privacy_screen_sw_state_property);
29960cf8d292SSimon Ser 	drm_sysfs_connector_property_event(connector,
2997334f74eeSHans de Goede 					   connector->privacy_screen_hw_state_property);
2998334f74eeSHans de Goede 
2999334f74eeSHans de Goede 	return NOTIFY_DONE;
3000334f74eeSHans de Goede }
3001334f74eeSHans de Goede 
3002334f74eeSHans de Goede /**
3003334f74eeSHans de Goede  * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to
3004334f74eeSHans de Goede  *    the connector
3005334f74eeSHans de Goede  * @connector: connector to attach the privacy-screen to
3006334f74eeSHans de Goede  * @priv: drm_privacy_screen to attach
3007334f74eeSHans de Goede  *
3008334f74eeSHans de Goede  * Create and attach the standard privacy-screen properties and register
3009334f74eeSHans de Goede  * a generic notifier for generating sysfs-connector-status-events
3010334f74eeSHans de Goede  * on external changes to the privacy-screen status.
3011334f74eeSHans de Goede  * This function takes ownership of the passed in drm_privacy_screen and will
3012334f74eeSHans de Goede  * call drm_privacy_screen_put() on it when the connector is destroyed.
3013334f74eeSHans de Goede  */
3014334f74eeSHans de Goede void drm_connector_attach_privacy_screen_provider(
3015334f74eeSHans de Goede 	struct drm_connector *connector, struct drm_privacy_screen *priv)
3016334f74eeSHans de Goede {
3017334f74eeSHans de Goede 	connector->privacy_screen = priv;
3018334f74eeSHans de Goede 	connector->privacy_screen_notifier.notifier_call =
3019334f74eeSHans de Goede 		drm_connector_privacy_screen_notifier;
3020334f74eeSHans de Goede 
3021334f74eeSHans de Goede 	drm_connector_create_privacy_screen_properties(connector);
3022334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, true);
3023334f74eeSHans de Goede 	drm_connector_attach_privacy_screen_properties(connector);
3024334f74eeSHans de Goede }
3025334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider);
3026334f74eeSHans de Goede 
3027334f74eeSHans de Goede /**
3028334f74eeSHans de Goede  * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state
3029334f74eeSHans de Goede  * @connector_state: connector-state to update the privacy-screen for
3030334f74eeSHans de Goede  *
3031334f74eeSHans de Goede  * This function calls drm_privacy_screen_set_sw_state() on the connector's
3032334f74eeSHans de Goede  * privacy-screen.
3033334f74eeSHans de Goede  *
3034334f74eeSHans de Goede  * If the connector has no privacy-screen, then this is a no-op.
3035334f74eeSHans de Goede  */
3036334f74eeSHans de Goede void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state)
3037334f74eeSHans de Goede {
3038334f74eeSHans de Goede 	struct drm_connector *connector = connector_state->connector;
3039334f74eeSHans de Goede 	int ret;
3040334f74eeSHans de Goede 
3041334f74eeSHans de Goede 	if (!connector->privacy_screen)
3042334f74eeSHans de Goede 		return;
3043334f74eeSHans de Goede 
3044334f74eeSHans de Goede 	ret = drm_privacy_screen_set_sw_state(connector->privacy_screen,
3045334f74eeSHans de Goede 					      connector_state->privacy_screen_sw_state);
3046334f74eeSHans de Goede 	if (ret) {
3047334f74eeSHans de Goede 		drm_err(connector->dev, "Error updating privacy-screen sw_state\n");
3048334f74eeSHans de Goede 		return;
3049334f74eeSHans de Goede 	}
3050334f74eeSHans de Goede 
3051334f74eeSHans de Goede 	/* The hw_state property value may have changed, update it. */
3052334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, false);
3053334f74eeSHans de Goede }
3054334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_update_privacy_screen);
3055334f74eeSHans de Goede 
305697e14fbeSDaniel Vetter int drm_connector_set_obj_prop(struct drm_mode_object *obj,
305752217195SDaniel Vetter 				    struct drm_property *property,
305852217195SDaniel Vetter 				    uint64_t value)
305952217195SDaniel Vetter {
306052217195SDaniel Vetter 	int ret = -EINVAL;
306152217195SDaniel Vetter 	struct drm_connector *connector = obj_to_connector(obj);
306252217195SDaniel Vetter 
306352217195SDaniel Vetter 	/* Do DPMS ourselves */
306452217195SDaniel Vetter 	if (property == connector->dev->mode_config.dpms_property) {
306552217195SDaniel Vetter 		ret = (*connector->funcs->dpms)(connector, (int)value);
306652217195SDaniel Vetter 	} else if (connector->funcs->set_property)
306752217195SDaniel Vetter 		ret = connector->funcs->set_property(connector, property, value);
306852217195SDaniel Vetter 
3069144a7999SDaniel Vetter 	if (!ret)
307052217195SDaniel Vetter 		drm_object_property_set_value(&connector->base, property, value);
307152217195SDaniel Vetter 	return ret;
307252217195SDaniel Vetter }
307352217195SDaniel Vetter 
307497e14fbeSDaniel Vetter int drm_connector_property_set_ioctl(struct drm_device *dev,
307552217195SDaniel Vetter 				     void *data, struct drm_file *file_priv)
307652217195SDaniel Vetter {
307752217195SDaniel Vetter 	struct drm_mode_connector_set_property *conn_set_prop = data;
307852217195SDaniel Vetter 	struct drm_mode_obj_set_property obj_set_prop = {
307952217195SDaniel Vetter 		.value = conn_set_prop->value,
308052217195SDaniel Vetter 		.prop_id = conn_set_prop->prop_id,
308152217195SDaniel Vetter 		.obj_id = conn_set_prop->connector_id,
308252217195SDaniel Vetter 		.obj_type = DRM_MODE_OBJECT_CONNECTOR
308352217195SDaniel Vetter 	};
308452217195SDaniel Vetter 
308552217195SDaniel Vetter 	/* It does all the locking and checking we need */
308652217195SDaniel Vetter 	return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
308752217195SDaniel Vetter }
308852217195SDaniel Vetter 
308952217195SDaniel Vetter static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
309052217195SDaniel Vetter {
309152217195SDaniel Vetter 	/* For atomic drivers only state objects are synchronously updated and
3092c2ce66daSBeatriz Martins de Carvalho 	 * protected by modeset locks, so check those first.
3093c2ce66daSBeatriz Martins de Carvalho 	 */
309452217195SDaniel Vetter 	if (connector->state)
309552217195SDaniel Vetter 		return connector->state->best_encoder;
309652217195SDaniel Vetter 	return connector->encoder;
309752217195SDaniel Vetter }
309852217195SDaniel Vetter 
3099c3ff0cdbSAnkit Nautiyal static bool
3100c3ff0cdbSAnkit Nautiyal drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
31018445e2c5SVille Syrjälä 			     const struct list_head *modes,
310252217195SDaniel Vetter 			     const struct drm_file *file_priv)
310352217195SDaniel Vetter {
310452217195SDaniel Vetter 	/*
310552217195SDaniel Vetter 	 * If user-space hasn't configured the driver to expose the stereo 3D
310652217195SDaniel Vetter 	 * modes, don't expose them.
310752217195SDaniel Vetter 	 */
310852217195SDaniel Vetter 	if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
310952217195SDaniel Vetter 		return false;
3110c3ff0cdbSAnkit Nautiyal 	/*
3111c3ff0cdbSAnkit Nautiyal 	 * If user-space hasn't configured the driver to expose the modes
3112c3ff0cdbSAnkit Nautiyal 	 * with aspect-ratio, don't expose them. However if such a mode
3113c3ff0cdbSAnkit Nautiyal 	 * is unique, let it be exposed, but reset the aspect-ratio flags
3114c3ff0cdbSAnkit Nautiyal 	 * while preparing the list of user-modes.
3115c3ff0cdbSAnkit Nautiyal 	 */
3116c3ff0cdbSAnkit Nautiyal 	if (!file_priv->aspect_ratio_allowed) {
31178445e2c5SVille Syrjälä 		const struct drm_display_mode *mode_itr;
3118c3ff0cdbSAnkit Nautiyal 
31198445e2c5SVille Syrjälä 		list_for_each_entry(mode_itr, modes, head) {
31208445e2c5SVille Syrjälä 			if (mode_itr->expose_to_userspace &&
31218445e2c5SVille Syrjälä 			    drm_mode_match(mode_itr, mode,
3122c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_TIMINGS |
3123c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_CLOCK |
3124c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_FLAGS |
3125c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_3D_FLAGS))
3126c3ff0cdbSAnkit Nautiyal 				return false;
3127c3ff0cdbSAnkit Nautiyal 		}
31288445e2c5SVille Syrjälä 	}
312952217195SDaniel Vetter 
313052217195SDaniel Vetter 	return true;
313152217195SDaniel Vetter }
313252217195SDaniel Vetter 
313352217195SDaniel Vetter int drm_mode_getconnector(struct drm_device *dev, void *data,
313452217195SDaniel Vetter 			  struct drm_file *file_priv)
313552217195SDaniel Vetter {
313652217195SDaniel Vetter 	struct drm_mode_get_connector *out_resp = data;
313752217195SDaniel Vetter 	struct drm_connector *connector;
313852217195SDaniel Vetter 	struct drm_encoder *encoder;
313952217195SDaniel Vetter 	struct drm_display_mode *mode;
314052217195SDaniel Vetter 	int mode_count = 0;
314152217195SDaniel Vetter 	int encoders_count = 0;
314252217195SDaniel Vetter 	int ret = 0;
314352217195SDaniel Vetter 	int copied = 0;
314452217195SDaniel Vetter 	struct drm_mode_modeinfo u_mode;
314552217195SDaniel Vetter 	struct drm_mode_modeinfo __user *mode_ptr;
314652217195SDaniel Vetter 	uint32_t __user *encoder_ptr;
3147869e76f7SDesmond Cheong Zhi Xi 	bool is_current_master;
314852217195SDaniel Vetter 
314952217195SDaniel Vetter 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
315069fdf420SChris Wilson 		return -EOPNOTSUPP;
315152217195SDaniel Vetter 
315252217195SDaniel Vetter 	memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
315352217195SDaniel Vetter 
3154418da172SKeith Packard 	connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
315591eefc05SDaniel Vetter 	if (!connector)
315691eefc05SDaniel Vetter 		return -ENOENT;
315752217195SDaniel Vetter 
315862afb4adSJosé Roberto de Souza 	encoders_count = hweight32(connector->possible_encoders);
315991eefc05SDaniel Vetter 
316091eefc05SDaniel Vetter 	if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
316191eefc05SDaniel Vetter 		copied = 0;
316291eefc05SDaniel Vetter 		encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
316383aefbb8SVille Syrjälä 
316462afb4adSJosé Roberto de Souza 		drm_connector_for_each_possible_encoder(connector, encoder) {
316583aefbb8SVille Syrjälä 			if (put_user(encoder->base.id, encoder_ptr + copied)) {
316691eefc05SDaniel Vetter 				ret = -EFAULT;
3167e94ac351SDaniel Vetter 				goto out;
316891eefc05SDaniel Vetter 			}
316991eefc05SDaniel Vetter 			copied++;
317091eefc05SDaniel Vetter 		}
317191eefc05SDaniel Vetter 	}
317291eefc05SDaniel Vetter 	out_resp->count_encoders = encoders_count;
317391eefc05SDaniel Vetter 
317491eefc05SDaniel Vetter 	out_resp->connector_id = connector->base.id;
317591eefc05SDaniel Vetter 	out_resp->connector_type = connector->connector_type;
317691eefc05SDaniel Vetter 	out_resp->connector_type_id = connector->connector_type_id;
317791eefc05SDaniel Vetter 
3178869e76f7SDesmond Cheong Zhi Xi 	is_current_master = drm_is_current_master(file_priv);
3179869e76f7SDesmond Cheong Zhi Xi 
318091eefc05SDaniel Vetter 	mutex_lock(&dev->mode_config.mutex);
318191eefc05SDaniel Vetter 	if (out_resp->count_modes == 0) {
3182869e76f7SDesmond Cheong Zhi Xi 		if (is_current_master)
318391eefc05SDaniel Vetter 			connector->funcs->fill_modes(connector,
318491eefc05SDaniel Vetter 						     dev->mode_config.max_width,
318591eefc05SDaniel Vetter 						     dev->mode_config.max_height);
31868f86c82aSSimon Ser 		else
31876897204eSDouglas Anderson 			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\n",
31888f86c82aSSimon Ser 				    connector->base.id, connector->name);
318991eefc05SDaniel Vetter 	}
319091eefc05SDaniel Vetter 
319191eefc05SDaniel Vetter 	out_resp->mm_width = connector->display_info.width_mm;
319291eefc05SDaniel Vetter 	out_resp->mm_height = connector->display_info.height_mm;
319391eefc05SDaniel Vetter 	out_resp->subpixel = connector->display_info.subpixel_order;
319491eefc05SDaniel Vetter 	out_resp->connection = connector->status;
319591eefc05SDaniel Vetter 
319691eefc05SDaniel Vetter 	/* delayed so we get modes regardless of pre-fill_modes state */
31978445e2c5SVille Syrjälä 	list_for_each_entry(mode, &connector->modes, head) {
31988445e2c5SVille Syrjälä 		WARN_ON(mode->expose_to_userspace);
31998445e2c5SVille Syrjälä 
32008445e2c5SVille Syrjälä 		if (drm_mode_expose_to_userspace(mode, &connector->modes,
3201c3ff0cdbSAnkit Nautiyal 						 file_priv)) {
32028445e2c5SVille Syrjälä 			mode->expose_to_userspace = true;
320391eefc05SDaniel Vetter 			mode_count++;
3204c3ff0cdbSAnkit Nautiyal 		}
32058445e2c5SVille Syrjälä 	}
320691eefc05SDaniel Vetter 
320752217195SDaniel Vetter 	/*
320852217195SDaniel Vetter 	 * This ioctl is called twice, once to determine how much space is
320952217195SDaniel Vetter 	 * needed, and the 2nd time to fill it.
321052217195SDaniel Vetter 	 */
321152217195SDaniel Vetter 	if ((out_resp->count_modes >= mode_count) && mode_count) {
321252217195SDaniel Vetter 		copied = 0;
321352217195SDaniel Vetter 		mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
32148445e2c5SVille Syrjälä 		list_for_each_entry(mode, &connector->modes, head) {
32158445e2c5SVille Syrjälä 			if (!mode->expose_to_userspace)
32168445e2c5SVille Syrjälä 				continue;
32178445e2c5SVille Syrjälä 
32188445e2c5SVille Syrjälä 			/* Clear the tag for the next time around */
32198445e2c5SVille Syrjälä 			mode->expose_to_userspace = false;
32208445e2c5SVille Syrjälä 
322152217195SDaniel Vetter 			drm_mode_convert_to_umode(&u_mode, mode);
3222c3ff0cdbSAnkit Nautiyal 			/*
3223c3ff0cdbSAnkit Nautiyal 			 * Reset aspect ratio flags of user-mode, if modes with
3224c3ff0cdbSAnkit Nautiyal 			 * aspect-ratio are not supported.
3225c3ff0cdbSAnkit Nautiyal 			 */
3226c3ff0cdbSAnkit Nautiyal 			if (!file_priv->aspect_ratio_allowed)
3227c3ff0cdbSAnkit Nautiyal 				u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
322852217195SDaniel Vetter 			if (copy_to_user(mode_ptr + copied,
322952217195SDaniel Vetter 					 &u_mode, sizeof(u_mode))) {
323052217195SDaniel Vetter 				ret = -EFAULT;
32318445e2c5SVille Syrjälä 
32328445e2c5SVille Syrjälä 				/*
32338445e2c5SVille Syrjälä 				 * Clear the tag for the rest of
32348445e2c5SVille Syrjälä 				 * the modes for the next time around.
32358445e2c5SVille Syrjälä 				 */
32368445e2c5SVille Syrjälä 				list_for_each_entry_continue(mode, &connector->modes, head)
32378445e2c5SVille Syrjälä 					mode->expose_to_userspace = false;
32388445e2c5SVille Syrjälä 
3239e94ac351SDaniel Vetter 				mutex_unlock(&dev->mode_config.mutex);
3240e94ac351SDaniel Vetter 
324152217195SDaniel Vetter 				goto out;
324252217195SDaniel Vetter 			}
324352217195SDaniel Vetter 			copied++;
324452217195SDaniel Vetter 		}
32458445e2c5SVille Syrjälä 	} else {
32468445e2c5SVille Syrjälä 		/* Clear the tag for the next time around */
32478445e2c5SVille Syrjälä 		list_for_each_entry(mode, &connector->modes, head)
32488445e2c5SVille Syrjälä 			mode->expose_to_userspace = false;
324952217195SDaniel Vetter 	}
32508445e2c5SVille Syrjälä 
325152217195SDaniel Vetter 	out_resp->count_modes = mode_count;
325252217195SDaniel Vetter 	mutex_unlock(&dev->mode_config.mutex);
3253e94ac351SDaniel Vetter 
3254e94ac351SDaniel Vetter 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
3255e94ac351SDaniel Vetter 	encoder = drm_connector_get_encoder(connector);
3256e94ac351SDaniel Vetter 	if (encoder)
3257e94ac351SDaniel Vetter 		out_resp->encoder_id = encoder->base.id;
3258e94ac351SDaniel Vetter 	else
3259e94ac351SDaniel Vetter 		out_resp->encoder_id = 0;
3260e94ac351SDaniel Vetter 
3261e94ac351SDaniel Vetter 	/* Only grab properties after probing, to make sure EDID and other
3262c2ce66daSBeatriz Martins de Carvalho 	 * properties reflect the latest status.
3263c2ce66daSBeatriz Martins de Carvalho 	 */
3264e94ac351SDaniel Vetter 	ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
3265e94ac351SDaniel Vetter 			(uint32_t __user *)(unsigned long)(out_resp->props_ptr),
3266e94ac351SDaniel Vetter 			(uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
3267e94ac351SDaniel Vetter 			&out_resp->count_props);
3268e94ac351SDaniel Vetter 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
3269e94ac351SDaniel Vetter 
3270e94ac351SDaniel Vetter out:
3271ad093607SThierry Reding 	drm_connector_put(connector);
327252217195SDaniel Vetter 
327352217195SDaniel Vetter 	return ret;
327452217195SDaniel Vetter }
327552217195SDaniel Vetter 
32763d3f7c1eSHans de Goede /**
32773d3f7c1eSHans de Goede  * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode
32783d3f7c1eSHans de Goede  * @fwnode: fwnode for which to find the matching drm_connector
32793d3f7c1eSHans de Goede  *
32803d3f7c1eSHans de Goede  * This functions looks up a drm_connector based on its associated fwnode. When
32813d3f7c1eSHans de Goede  * a connector is found a reference to the connector is returned. The caller must
32823d3f7c1eSHans de Goede  * call drm_connector_put() to release this reference when it is done with the
32833d3f7c1eSHans de Goede  * connector.
32843d3f7c1eSHans de Goede  *
32853d3f7c1eSHans de Goede  * Returns: A reference to the found connector or an ERR_PTR().
32863d3f7c1eSHans de Goede  */
32873d3f7c1eSHans de Goede struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode)
32883d3f7c1eSHans de Goede {
32893d3f7c1eSHans de Goede 	struct drm_connector *connector, *found = ERR_PTR(-ENODEV);
32903d3f7c1eSHans de Goede 
32913d3f7c1eSHans de Goede 	if (!fwnode)
32923d3f7c1eSHans de Goede 		return ERR_PTR(-ENODEV);
32933d3f7c1eSHans de Goede 
32943d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
32953d3f7c1eSHans de Goede 
32963d3f7c1eSHans de Goede 	list_for_each_entry(connector, &connector_list, global_connector_list_entry) {
32973d3f7c1eSHans de Goede 		if (connector->fwnode == fwnode ||
32983d3f7c1eSHans de Goede 		    (connector->fwnode && connector->fwnode->secondary == fwnode)) {
32993d3f7c1eSHans de Goede 			drm_connector_get(connector);
33003d3f7c1eSHans de Goede 			found = connector;
33013d3f7c1eSHans de Goede 			break;
33023d3f7c1eSHans de Goede 		}
33033d3f7c1eSHans de Goede 	}
33043d3f7c1eSHans de Goede 
33053d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
33063d3f7c1eSHans de Goede 
33073d3f7c1eSHans de Goede 	return found;
33083d3f7c1eSHans de Goede }
33093d3f7c1eSHans de Goede 
331072ad4968SHans de Goede /**
331172ad4968SHans de Goede  * drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector
3312f85d9e59SRandy Dunlap  * @connector_fwnode: fwnode_handle to report the event on
3313fc93835bSBjorn Andersson  * @status: hot plug detect logical state
331472ad4968SHans de Goede  *
331572ad4968SHans de Goede  * On some hardware a hotplug event notification may come from outside the display
331672ad4968SHans de Goede  * driver / device. An example of this is some USB Type-C setups where the hardware
331772ad4968SHans de Goede  * muxes the DisplayPort data and aux-lines but does not pass the altmode HPD
331872ad4968SHans de Goede  * status bit to the GPU's DP HPD pin.
331972ad4968SHans de Goede  *
332072ad4968SHans de Goede  * This function can be used to report these out-of-band events after obtaining
332172ad4968SHans de Goede  * a drm_connector reference through calling drm_connector_find_by_fwnode().
332272ad4968SHans de Goede  */
3323fc93835bSBjorn Andersson void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode,
3324fc93835bSBjorn Andersson 				     enum drm_connector_status status)
332572ad4968SHans de Goede {
332672ad4968SHans de Goede 	struct drm_connector *connector;
332772ad4968SHans de Goede 
332872ad4968SHans de Goede 	connector = drm_connector_find_by_fwnode(connector_fwnode);
332972ad4968SHans de Goede 	if (IS_ERR(connector))
333072ad4968SHans de Goede 		return;
333172ad4968SHans de Goede 
333272ad4968SHans de Goede 	if (connector->funcs->oob_hotplug_event)
3333fc93835bSBjorn Andersson 		connector->funcs->oob_hotplug_event(connector, status);
333472ad4968SHans de Goede 
333572ad4968SHans de Goede 	drm_connector_put(connector);
333672ad4968SHans de Goede }
333772ad4968SHans de Goede EXPORT_SYMBOL(drm_connector_oob_hotplug_event);
333872ad4968SHans de Goede 
33399498c19bSDaniel Vetter 
33409498c19bSDaniel Vetter /**
33419498c19bSDaniel Vetter  * DOC: Tile group
33429498c19bSDaniel Vetter  *
33439498c19bSDaniel Vetter  * Tile groups are used to represent tiled monitors with a unique integer
33449498c19bSDaniel Vetter  * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
33459498c19bSDaniel Vetter  * we store this in a tile group, so we have a common identifier for all tiles
33469498c19bSDaniel Vetter  * in a monitor group. The property is called "TILE". Drivers can manage tile
33479498c19bSDaniel Vetter  * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
33489498c19bSDaniel Vetter  * drm_mode_get_tile_group(). But this is only needed for internal panels where
33499498c19bSDaniel Vetter  * the tile group information is exposed through a non-standard way.
33509498c19bSDaniel Vetter  */
33519498c19bSDaniel Vetter 
33529498c19bSDaniel Vetter static void drm_tile_group_free(struct kref *kref)
33539498c19bSDaniel Vetter {
33549498c19bSDaniel Vetter 	struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
33559498c19bSDaniel Vetter 	struct drm_device *dev = tg->dev;
3356948de842SSuraj Upadhyay 
33579498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
33589498c19bSDaniel Vetter 	idr_remove(&dev->mode_config.tile_idr, tg->id);
33599498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
33609498c19bSDaniel Vetter 	kfree(tg);
33619498c19bSDaniel Vetter }
33629498c19bSDaniel Vetter 
33639498c19bSDaniel Vetter /**
33649498c19bSDaniel Vetter  * drm_mode_put_tile_group - drop a reference to a tile group.
33659498c19bSDaniel Vetter  * @dev: DRM device
33669498c19bSDaniel Vetter  * @tg: tile group to drop reference to.
33679498c19bSDaniel Vetter  *
33689498c19bSDaniel Vetter  * drop reference to tile group and free if 0.
33699498c19bSDaniel Vetter  */
33709498c19bSDaniel Vetter void drm_mode_put_tile_group(struct drm_device *dev,
33719498c19bSDaniel Vetter 			     struct drm_tile_group *tg)
33729498c19bSDaniel Vetter {
33739498c19bSDaniel Vetter 	kref_put(&tg->refcount, drm_tile_group_free);
33749498c19bSDaniel Vetter }
33759498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_put_tile_group);
33769498c19bSDaniel Vetter 
33779498c19bSDaniel Vetter /**
33789498c19bSDaniel Vetter  * drm_mode_get_tile_group - get a reference to an existing tile group
33799498c19bSDaniel Vetter  * @dev: DRM device
33809498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
33819498c19bSDaniel Vetter  *
33829498c19bSDaniel Vetter  * Use the unique bytes to get a reference to an existing tile group.
33839498c19bSDaniel Vetter  *
33849498c19bSDaniel Vetter  * RETURNS:
33859498c19bSDaniel Vetter  * tile group or NULL if not found.
33869498c19bSDaniel Vetter  */
33879498c19bSDaniel Vetter struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
3388267ea759SVille Syrjälä 					       const char topology[8])
33899498c19bSDaniel Vetter {
33909498c19bSDaniel Vetter 	struct drm_tile_group *tg;
33919498c19bSDaniel Vetter 	int id;
3392948de842SSuraj Upadhyay 
33939498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
33949498c19bSDaniel Vetter 	idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
33959498c19bSDaniel Vetter 		if (!memcmp(tg->group_data, topology, 8)) {
33969498c19bSDaniel Vetter 			if (!kref_get_unless_zero(&tg->refcount))
33979498c19bSDaniel Vetter 				tg = NULL;
33989498c19bSDaniel Vetter 			mutex_unlock(&dev->mode_config.idr_mutex);
33999498c19bSDaniel Vetter 			return tg;
34009498c19bSDaniel Vetter 		}
34019498c19bSDaniel Vetter 	}
34029498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
34039498c19bSDaniel Vetter 	return NULL;
34049498c19bSDaniel Vetter }
34059498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_get_tile_group);
34069498c19bSDaniel Vetter 
34079498c19bSDaniel Vetter /**
34089498c19bSDaniel Vetter  * drm_mode_create_tile_group - create a tile group from a displayid description
34099498c19bSDaniel Vetter  * @dev: DRM device
34109498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
34119498c19bSDaniel Vetter  *
34129498c19bSDaniel Vetter  * Create a tile group for the unique monitor, and get a unique
34139498c19bSDaniel Vetter  * identifier for the tile group.
34149498c19bSDaniel Vetter  *
34159498c19bSDaniel Vetter  * RETURNS:
3416705c8160SDan Carpenter  * new tile group or NULL.
34179498c19bSDaniel Vetter  */
34189498c19bSDaniel Vetter struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
3419267ea759SVille Syrjälä 						  const char topology[8])
34209498c19bSDaniel Vetter {
34219498c19bSDaniel Vetter 	struct drm_tile_group *tg;
34229498c19bSDaniel Vetter 	int ret;
34239498c19bSDaniel Vetter 
34249498c19bSDaniel Vetter 	tg = kzalloc(sizeof(*tg), GFP_KERNEL);
34259498c19bSDaniel Vetter 	if (!tg)
3426705c8160SDan Carpenter 		return NULL;
34279498c19bSDaniel Vetter 
34289498c19bSDaniel Vetter 	kref_init(&tg->refcount);
34299498c19bSDaniel Vetter 	memcpy(tg->group_data, topology, 8);
34309498c19bSDaniel Vetter 	tg->dev = dev;
34319498c19bSDaniel Vetter 
34329498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
34339498c19bSDaniel Vetter 	ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
34349498c19bSDaniel Vetter 	if (ret >= 0) {
34359498c19bSDaniel Vetter 		tg->id = ret;
34369498c19bSDaniel Vetter 	} else {
34379498c19bSDaniel Vetter 		kfree(tg);
3438705c8160SDan Carpenter 		tg = NULL;
34399498c19bSDaniel Vetter 	}
34409498c19bSDaniel Vetter 
34419498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
34429498c19bSDaniel Vetter 	return tg;
34439498c19bSDaniel Vetter }
34449498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tile_group);
3445