xref: /linux/drivers/gpu/drm/drm_connector.c (revision c627087cb164d1675323c7942fa29bded4263dfc)
152217195SDaniel Vetter /*
252217195SDaniel Vetter  * Copyright (c) 2016 Intel Corporation
352217195SDaniel Vetter  *
452217195SDaniel Vetter  * Permission to use, copy, modify, distribute, and sell this software and its
552217195SDaniel Vetter  * documentation for any purpose is hereby granted without fee, provided that
652217195SDaniel Vetter  * the above copyright notice appear in all copies and that both that copyright
752217195SDaniel Vetter  * notice and this permission notice appear in supporting documentation, and
852217195SDaniel Vetter  * that the name of the copyright holders not be used in advertising or
952217195SDaniel Vetter  * publicity pertaining to distribution of the software without specific,
1052217195SDaniel Vetter  * written prior permission.  The copyright holders make no representations
1152217195SDaniel Vetter  * about the suitability of this software for any purpose.  It is provided "as
1252217195SDaniel Vetter  * is" without express or implied warranty.
1352217195SDaniel Vetter  *
1452217195SDaniel Vetter  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1552217195SDaniel Vetter  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1652217195SDaniel Vetter  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1752217195SDaniel Vetter  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1852217195SDaniel Vetter  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1952217195SDaniel Vetter  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2052217195SDaniel Vetter  * OF THIS SOFTWARE.
2152217195SDaniel Vetter  */
2252217195SDaniel Vetter 
238f86c82aSSimon Ser #include <drm/drm_auth.h>
2452217195SDaniel Vetter #include <drm/drm_connector.h>
25d71d8a4bSMaxime Ripard #include <drm/drm_drv.h>
2652217195SDaniel Vetter #include <drm/drm_edid.h>
279338203cSLaurent Pinchart #include <drm/drm_encoder.h>
2899f45e32SDaniel Vetter #include <drm/drm_file.h>
2935a3b82fSMaxime Ripard #include <drm/drm_managed.h>
30d71d8a4bSMaxime Ripard #include <drm/drm_panel.h>
31d71d8a4bSMaxime Ripard #include <drm/drm_print.h>
32334f74eeSHans de Goede #include <drm/drm_privacy_screen_consumer.h>
33968d81a6SJeykumar Sankaran #include <drm/drm_sysfs.h>
34d71d8a4bSMaxime Ripard #include <drm/drm_utils.h>
3599f45e32SDaniel Vetter 
36495e440bSThomas Zimmermann #include <linux/property.h>
3799f45e32SDaniel Vetter #include <linux/uaccess.h>
3852217195SDaniel Vetter 
39495e440bSThomas Zimmermann #include <video/cmdline.h>
40495e440bSThomas Zimmermann 
4152217195SDaniel Vetter #include "drm_crtc_internal.h"
4252217195SDaniel Vetter #include "drm_internal.h"
4352217195SDaniel Vetter 
44ae2a6da8SDaniel Vetter /**
45ae2a6da8SDaniel Vetter  * DOC: overview
46ae2a6da8SDaniel Vetter  *
47ae2a6da8SDaniel Vetter  * In DRM connectors are the general abstraction for display sinks, and include
4884e543bcSAntonio Borneo  * also fixed panels or anything else that can display pixels in some form. As
49ae2a6da8SDaniel Vetter  * opposed to all other KMS objects representing hardware (like CRTC, encoder or
50ae2a6da8SDaniel Vetter  * plane abstractions) connectors can be hotplugged and unplugged at runtime.
51ad093607SThierry Reding  * Hence they are reference-counted using drm_connector_get() and
52ad093607SThierry Reding  * drm_connector_put().
53ae2a6da8SDaniel Vetter  *
54d574528aSDaniel Vetter  * KMS driver must create, initialize, register and attach at a &struct
55d574528aSDaniel Vetter  * drm_connector for each such sink. The instance is created as other KMS
56aec97460SDaniel Vetter  * objects and initialized by setting the following fields. The connector is
57aec97460SDaniel Vetter  * initialized with a call to drm_connector_init() with a pointer to the
58aec97460SDaniel Vetter  * &struct drm_connector_funcs and a connector type, and then exposed to
59aec97460SDaniel Vetter  * userspace with a call to drm_connector_register().
60ae2a6da8SDaniel Vetter  *
61ae2a6da8SDaniel Vetter  * Connectors must be attached to an encoder to be used. For devices that map
62ae2a6da8SDaniel Vetter  * connectors to encoders 1:1, the connector should be attached at
63cde4c44dSDaniel Vetter  * initialization time with a call to drm_connector_attach_encoder(). The
64d574528aSDaniel Vetter  * driver must also set the &drm_connector.encoder field to point to the
65ae2a6da8SDaniel Vetter  * attached encoder.
66ae2a6da8SDaniel Vetter  *
67ae2a6da8SDaniel Vetter  * For connectors which are not fixed (like built-in panels) the driver needs to
68ae2a6da8SDaniel Vetter  * support hotplug notifications. The simplest way to do that is by using the
69ae2a6da8SDaniel Vetter  * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
70ae2a6da8SDaniel Vetter  * hardware support for hotplug interrupts. Connectors with hardware hotplug
71ae2a6da8SDaniel Vetter  * support can instead use e.g. drm_helper_hpd_irq_event().
72ae2a6da8SDaniel Vetter  */
73ae2a6da8SDaniel Vetter 
743d3f7c1eSHans de Goede /*
753d3f7c1eSHans de Goede  * Global connector list for drm_connector_find_by_fwnode().
763d3f7c1eSHans de Goede  * Note drm_connector_[un]register() first take connector->lock and then
773d3f7c1eSHans de Goede  * take the connector_list_lock.
783d3f7c1eSHans de Goede  */
793d3f7c1eSHans de Goede static DEFINE_MUTEX(connector_list_lock);
803d3f7c1eSHans de Goede static LIST_HEAD(connector_list);
813d3f7c1eSHans de Goede 
8252217195SDaniel Vetter struct drm_conn_prop_enum_list {
8352217195SDaniel Vetter 	int type;
8452217195SDaniel Vetter 	const char *name;
8552217195SDaniel Vetter 	struct ida ida;
8652217195SDaniel Vetter };
8752217195SDaniel Vetter 
8852217195SDaniel Vetter /*
8952217195SDaniel Vetter  * Connector and encoder types.
9052217195SDaniel Vetter  */
9152217195SDaniel Vetter static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
9252217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Unknown, "Unknown" },
9352217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
9452217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
9552217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
9652217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
9752217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Composite, "Composite" },
9852217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
9952217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
10052217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Component, "Component" },
10152217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
10252217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },
10352217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
10452217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
10552217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_TV, "TV" },
10652217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_eDP, "eDP" },
10752217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
10852217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DSI, "DSI" },
10952217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DPI, "DPI" },
110935774cdSBrian Starkey 	{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
111fc06bf1dSNoralf Trønnes 	{ DRM_MODE_CONNECTOR_SPI, "SPI" },
112757e2671SNoralf Trønnes 	{ DRM_MODE_CONNECTOR_USB, "USB" },
11352217195SDaniel Vetter };
11452217195SDaniel Vetter 
11552217195SDaniel Vetter void drm_connector_ida_init(void)
11652217195SDaniel Vetter {
11752217195SDaniel Vetter 	int i;
11852217195SDaniel Vetter 
11952217195SDaniel Vetter 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
12052217195SDaniel Vetter 		ida_init(&drm_connector_enum_list[i].ida);
12152217195SDaniel Vetter }
12252217195SDaniel Vetter 
12352217195SDaniel Vetter void drm_connector_ida_destroy(void)
12452217195SDaniel Vetter {
12552217195SDaniel Vetter 	int i;
12652217195SDaniel Vetter 
12752217195SDaniel Vetter 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
12852217195SDaniel Vetter 		ida_destroy(&drm_connector_enum_list[i].ida);
12952217195SDaniel Vetter }
13052217195SDaniel Vetter 
13152217195SDaniel Vetter /**
132b35f90f2SLaurent Pinchart  * drm_get_connector_type_name - return a string for connector type
133b35f90f2SLaurent Pinchart  * @type: The connector type (DRM_MODE_CONNECTOR_*)
134b35f90f2SLaurent Pinchart  *
135b35f90f2SLaurent Pinchart  * Returns: the name of the connector type, or NULL if the type is not valid.
136b35f90f2SLaurent Pinchart  */
137b35f90f2SLaurent Pinchart const char *drm_get_connector_type_name(unsigned int type)
138b35f90f2SLaurent Pinchart {
139b35f90f2SLaurent Pinchart 	if (type < ARRAY_SIZE(drm_connector_enum_list))
140b35f90f2SLaurent Pinchart 		return drm_connector_enum_list[type].name;
141b35f90f2SLaurent Pinchart 
142b35f90f2SLaurent Pinchart 	return NULL;
143b35f90f2SLaurent Pinchart }
144b35f90f2SLaurent Pinchart EXPORT_SYMBOL(drm_get_connector_type_name);
145b35f90f2SLaurent Pinchart 
146b35f90f2SLaurent Pinchart /**
14752217195SDaniel Vetter  * drm_connector_get_cmdline_mode - reads the user's cmdline mode
14884e543bcSAntonio Borneo  * @connector: connector to query
14952217195SDaniel Vetter  *
150ae2a6da8SDaniel Vetter  * The kernel supports per-connector configuration of its consoles through
15152217195SDaniel Vetter  * use of the video= parameter. This function parses that option and
15252217195SDaniel Vetter  * extracts the user's specified mode (or enable/disable status) for a
15352217195SDaniel Vetter  * particular connector. This is typically only used during the early fbdev
15452217195SDaniel Vetter  * setup.
15552217195SDaniel Vetter  */
15652217195SDaniel Vetter static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
15752217195SDaniel Vetter {
15852217195SDaniel Vetter 	struct drm_cmdline_mode *mode = &connector->cmdline_mode;
159495e440bSThomas Zimmermann 	const char *option;
16052217195SDaniel Vetter 
161495e440bSThomas Zimmermann 	option = video_get_options(connector->name);
162495e440bSThomas Zimmermann 	if (!option)
16352217195SDaniel Vetter 		return;
16452217195SDaniel Vetter 
16552217195SDaniel Vetter 	if (!drm_mode_parse_command_line_for_connector(option,
16652217195SDaniel Vetter 						       connector,
16752217195SDaniel Vetter 						       mode))
16852217195SDaniel Vetter 		return;
16952217195SDaniel Vetter 
17052217195SDaniel Vetter 	if (mode->force) {
1716140cf20SJani Nikula 		DRM_INFO("forcing %s connector %s\n", connector->name,
1726140cf20SJani Nikula 			 drm_get_connector_force_name(mode->force));
17352217195SDaniel Vetter 		connector->force = mode->force;
17452217195SDaniel Vetter 	}
17552217195SDaniel Vetter 
1760980939dSHans de Goede 	if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) {
1770980939dSHans de Goede 		DRM_INFO("cmdline forces connector %s panel_orientation to %d\n",
1780980939dSHans de Goede 			 connector->name, mode->panel_orientation);
1790980939dSHans de Goede 		drm_connector_set_panel_orientation(connector,
1800980939dSHans de Goede 						    mode->panel_orientation);
1810980939dSHans de Goede 	}
1820980939dSHans de Goede 
1833aeeb13dSMaxime Ripard 	DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
18450b0946dSMaxime Ripard 		      connector->name, mode->name,
18552217195SDaniel Vetter 		      mode->xres, mode->yres,
18652217195SDaniel Vetter 		      mode->refresh_specified ? mode->refresh : 60,
18752217195SDaniel Vetter 		      mode->rb ? " reduced blanking" : "",
18852217195SDaniel Vetter 		      mode->margins ? " with margins" : "",
18952217195SDaniel Vetter 		      mode->interlace ?  " interlaced" : "");
19052217195SDaniel Vetter }
19152217195SDaniel Vetter 
19252217195SDaniel Vetter static void drm_connector_free(struct kref *kref)
19352217195SDaniel Vetter {
19452217195SDaniel Vetter 	struct drm_connector *connector =
19552217195SDaniel Vetter 		container_of(kref, struct drm_connector, base.refcount);
19652217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
19752217195SDaniel Vetter 
19852217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
19952217195SDaniel Vetter 	connector->funcs->destroy(connector);
20052217195SDaniel Vetter }
20152217195SDaniel Vetter 
202ea497bb9SDaniel Vetter void drm_connector_free_work_fn(struct work_struct *work)
203a703c550SDaniel Vetter {
204ea497bb9SDaniel Vetter 	struct drm_connector *connector, *n;
205ea497bb9SDaniel Vetter 	struct drm_device *dev =
206ea497bb9SDaniel Vetter 		container_of(work, struct drm_device, mode_config.connector_free_work);
207ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &dev->mode_config;
208ea497bb9SDaniel Vetter 	unsigned long flags;
209ea497bb9SDaniel Vetter 	struct llist_node *freed;
210a703c550SDaniel Vetter 
211ea497bb9SDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
212ea497bb9SDaniel Vetter 	freed = llist_del_all(&config->connector_free_list);
213ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
214ea497bb9SDaniel Vetter 
215ea497bb9SDaniel Vetter 	llist_for_each_entry_safe(connector, n, freed, free_node) {
216a703c550SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
217a703c550SDaniel Vetter 		connector->funcs->destroy(connector);
218a703c550SDaniel Vetter 	}
219ea497bb9SDaniel Vetter }
220a703c550SDaniel Vetter 
221b11af8a2SMaxime Ripard static int __drm_connector_init(struct drm_device *dev,
22252217195SDaniel Vetter 				struct drm_connector *connector,
22352217195SDaniel Vetter 				const struct drm_connector_funcs *funcs,
224b11af8a2SMaxime Ripard 				int connector_type,
225b11af8a2SMaxime Ripard 				struct i2c_adapter *ddc)
22652217195SDaniel Vetter {
22752217195SDaniel Vetter 	struct drm_mode_config *config = &dev->mode_config;
22852217195SDaniel Vetter 	int ret;
22952217195SDaniel Vetter 	struct ida *connector_ida =
23052217195SDaniel Vetter 		&drm_connector_enum_list[connector_type].ida;
23152217195SDaniel Vetter 
232ba1f665fSHaneen Mohammed 	WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
233ba1f665fSHaneen Mohammed 		(!funcs->atomic_destroy_state ||
234ba1f665fSHaneen Mohammed 		 !funcs->atomic_duplicate_state));
235ba1f665fSHaneen Mohammed 
2362135ea7aSThierry Reding 	ret = __drm_mode_object_add(dev, &connector->base,
23752217195SDaniel Vetter 				    DRM_MODE_OBJECT_CONNECTOR,
23852217195SDaniel Vetter 				    false, drm_connector_free);
23952217195SDaniel Vetter 	if (ret)
240613051daSDaniel Vetter 		return ret;
24152217195SDaniel Vetter 
24252217195SDaniel Vetter 	connector->base.properties = &connector->properties;
24352217195SDaniel Vetter 	connector->dev = dev;
24452217195SDaniel Vetter 	connector->funcs = funcs;
24552217195SDaniel Vetter 
2462a8d3eacSVille Syrjälä 	/* connector index is used with 32bit bitmasks */
247e5d6eeeaSBo Liu 	ret = ida_alloc_max(&config->connector_ida, 31, GFP_KERNEL);
2482a8d3eacSVille Syrjälä 	if (ret < 0) {
2492a8d3eacSVille Syrjälä 		DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
2502a8d3eacSVille Syrjälä 			      drm_connector_enum_list[connector_type].name,
2512a8d3eacSVille Syrjälä 			      ret);
25252217195SDaniel Vetter 		goto out_put;
2532a8d3eacSVille Syrjälä 	}
25452217195SDaniel Vetter 	connector->index = ret;
25552217195SDaniel Vetter 	ret = 0;
25652217195SDaniel Vetter 
25752217195SDaniel Vetter 	connector->connector_type = connector_type;
25852217195SDaniel Vetter 	connector->connector_type_id =
259e5d6eeeaSBo Liu 		ida_alloc_min(connector_ida, 1, GFP_KERNEL);
26052217195SDaniel Vetter 	if (connector->connector_type_id < 0) {
26152217195SDaniel Vetter 		ret = connector->connector_type_id;
26252217195SDaniel Vetter 		goto out_put_id;
26352217195SDaniel Vetter 	}
26452217195SDaniel Vetter 	connector->name =
26552217195SDaniel Vetter 		kasprintf(GFP_KERNEL, "%s-%d",
26652217195SDaniel Vetter 			  drm_connector_enum_list[connector_type].name,
26752217195SDaniel Vetter 			  connector->connector_type_id);
26852217195SDaniel Vetter 	if (!connector->name) {
26952217195SDaniel Vetter 		ret = -ENOMEM;
27052217195SDaniel Vetter 		goto out_put_type_id;
27152217195SDaniel Vetter 	}
27252217195SDaniel Vetter 
273b11af8a2SMaxime Ripard 	/* provide ddc symlink in sysfs */
274b11af8a2SMaxime Ripard 	connector->ddc = ddc;
275b11af8a2SMaxime Ripard 
2763d3f7c1eSHans de Goede 	INIT_LIST_HEAD(&connector->global_connector_list_entry);
27752217195SDaniel Vetter 	INIT_LIST_HEAD(&connector->probed_modes);
27852217195SDaniel Vetter 	INIT_LIST_HEAD(&connector->modes);
279e73ab00eSDaniel Vetter 	mutex_init(&connector->mutex);
28090b575f5SJani Nikula 	mutex_init(&connector->edid_override_mutex);
28152217195SDaniel Vetter 	connector->edid_blob_ptr = NULL;
2825186421cSStanislav Lisovskiy 	connector->epoch_counter = 0;
2832de3a078SManasi Navare 	connector->tile_blob_ptr = NULL;
28452217195SDaniel Vetter 	connector->status = connector_status_unknown;
2858d70f395SHans de Goede 	connector->display_info.panel_orientation =
2868d70f395SHans de Goede 		DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
28752217195SDaniel Vetter 
28852217195SDaniel Vetter 	drm_connector_get_cmdline_mode(connector);
28952217195SDaniel Vetter 
29052217195SDaniel Vetter 	/* We should add connectors at the end to avoid upsetting the connector
291c2ce66daSBeatriz Martins de Carvalho 	 * index too much.
292c2ce66daSBeatriz Martins de Carvalho 	 */
293613051daSDaniel Vetter 	spin_lock_irq(&config->connector_list_lock);
29452217195SDaniel Vetter 	list_add_tail(&connector->head, &config->connector_list);
29552217195SDaniel Vetter 	config->num_connector++;
296613051daSDaniel Vetter 	spin_unlock_irq(&config->connector_list_lock);
29752217195SDaniel Vetter 
298935774cdSBrian Starkey 	if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
299935774cdSBrian Starkey 	    connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
3006b7e2d5cSGerd Hoffmann 		drm_connector_attach_edid_property(connector);
30152217195SDaniel Vetter 
30252217195SDaniel Vetter 	drm_object_attach_property(&connector->base,
30352217195SDaniel Vetter 				      config->dpms_property, 0);
30452217195SDaniel Vetter 
30540ee6fbeSManasi Navare 	drm_object_attach_property(&connector->base,
30640ee6fbeSManasi Navare 				   config->link_status_property,
30740ee6fbeSManasi Navare 				   0);
30840ee6fbeSManasi Navare 
30966660d4cSDave Airlie 	drm_object_attach_property(&connector->base,
31066660d4cSDave Airlie 				   config->non_desktop_property,
31166660d4cSDave Airlie 				   0);
3122de3a078SManasi Navare 	drm_object_attach_property(&connector->base,
3132de3a078SManasi Navare 				   config->tile_property,
3142de3a078SManasi Navare 				   0);
31566660d4cSDave Airlie 
31652217195SDaniel Vetter 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
31752217195SDaniel Vetter 		drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
31852217195SDaniel Vetter 	}
31952217195SDaniel Vetter 
32052217195SDaniel Vetter 	connector->debugfs_entry = NULL;
32152217195SDaniel Vetter out_put_type_id:
32252217195SDaniel Vetter 	if (ret)
323e5d6eeeaSBo Liu 		ida_free(connector_ida, connector->connector_type_id);
32452217195SDaniel Vetter out_put_id:
32552217195SDaniel Vetter 	if (ret)
326e5d6eeeaSBo Liu 		ida_free(&config->connector_ida, connector->index);
32752217195SDaniel Vetter out_put:
32852217195SDaniel Vetter 	if (ret)
32952217195SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
33052217195SDaniel Vetter 
33152217195SDaniel Vetter 	return ret;
33252217195SDaniel Vetter }
333b11af8a2SMaxime Ripard 
334b11af8a2SMaxime Ripard /**
335b11af8a2SMaxime Ripard  * drm_connector_init - Init a preallocated connector
336b11af8a2SMaxime Ripard  * @dev: DRM device
337b11af8a2SMaxime Ripard  * @connector: the connector to init
338b11af8a2SMaxime Ripard  * @funcs: callbacks for this connector
339b11af8a2SMaxime Ripard  * @connector_type: user visible type of the connector
340b11af8a2SMaxime Ripard  *
341b11af8a2SMaxime Ripard  * Initialises a preallocated connector. Connectors should be
342b11af8a2SMaxime Ripard  * subclassed as part of driver connector objects.
343b11af8a2SMaxime Ripard  *
344b11af8a2SMaxime Ripard  * At driver unload time the driver's &drm_connector_funcs.destroy hook
345b11af8a2SMaxime Ripard  * should call drm_connector_cleanup() and free the connector structure.
346b11af8a2SMaxime Ripard  * The connector structure should not be allocated with devm_kzalloc().
347b11af8a2SMaxime Ripard  *
34835a3b82fSMaxime Ripard  * Note: consider using drmm_connector_init() instead of
34935a3b82fSMaxime Ripard  * drm_connector_init() to let the DRM managed resource infrastructure
35035a3b82fSMaxime Ripard  * take care of cleanup and deallocation.
35135a3b82fSMaxime Ripard  *
352b11af8a2SMaxime Ripard  * Returns:
353b11af8a2SMaxime Ripard  * Zero on success, error code on failure.
354b11af8a2SMaxime Ripard  */
355b11af8a2SMaxime Ripard int drm_connector_init(struct drm_device *dev,
356b11af8a2SMaxime Ripard 		       struct drm_connector *connector,
357b11af8a2SMaxime Ripard 		       const struct drm_connector_funcs *funcs,
358b11af8a2SMaxime Ripard 		       int connector_type)
359b11af8a2SMaxime Ripard {
360a961b197SMaxime Ripard 	if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
361a961b197SMaxime Ripard 		return -EINVAL;
362a961b197SMaxime Ripard 
363b11af8a2SMaxime Ripard 	return __drm_connector_init(dev, connector, funcs, connector_type, NULL);
364b11af8a2SMaxime Ripard }
36552217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_init);
36652217195SDaniel Vetter 
36752217195SDaniel Vetter /**
368100163dfSAndrzej Pietrasiewicz  * drm_connector_init_with_ddc - Init a preallocated connector
369100163dfSAndrzej Pietrasiewicz  * @dev: DRM device
370100163dfSAndrzej Pietrasiewicz  * @connector: the connector to init
371100163dfSAndrzej Pietrasiewicz  * @funcs: callbacks for this connector
372100163dfSAndrzej Pietrasiewicz  * @connector_type: user visible type of the connector
373100163dfSAndrzej Pietrasiewicz  * @ddc: pointer to the associated ddc adapter
374100163dfSAndrzej Pietrasiewicz  *
375100163dfSAndrzej Pietrasiewicz  * Initialises a preallocated connector. Connectors should be
376100163dfSAndrzej Pietrasiewicz  * subclassed as part of driver connector objects.
377100163dfSAndrzej Pietrasiewicz  *
37800ec947cSMaxime Ripard  * At driver unload time the driver's &drm_connector_funcs.destroy hook
37900ec947cSMaxime Ripard  * should call drm_connector_cleanup() and free the connector structure.
38000ec947cSMaxime Ripard  * The connector structure should not be allocated with devm_kzalloc().
38100ec947cSMaxime Ripard  *
382100163dfSAndrzej Pietrasiewicz  * Ensures that the ddc field of the connector is correctly set.
383100163dfSAndrzej Pietrasiewicz  *
38435a3b82fSMaxime Ripard  * Note: consider using drmm_connector_init() instead of
38535a3b82fSMaxime Ripard  * drm_connector_init_with_ddc() to let the DRM managed resource
38635a3b82fSMaxime Ripard  * infrastructure take care of cleanup and deallocation.
38735a3b82fSMaxime Ripard  *
388100163dfSAndrzej Pietrasiewicz  * Returns:
389100163dfSAndrzej Pietrasiewicz  * Zero on success, error code on failure.
390100163dfSAndrzej Pietrasiewicz  */
391100163dfSAndrzej Pietrasiewicz int drm_connector_init_with_ddc(struct drm_device *dev,
392100163dfSAndrzej Pietrasiewicz 				struct drm_connector *connector,
393100163dfSAndrzej Pietrasiewicz 				const struct drm_connector_funcs *funcs,
394100163dfSAndrzej Pietrasiewicz 				int connector_type,
395100163dfSAndrzej Pietrasiewicz 				struct i2c_adapter *ddc)
396100163dfSAndrzej Pietrasiewicz {
397a961b197SMaxime Ripard 	if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
398a961b197SMaxime Ripard 		return -EINVAL;
399a961b197SMaxime Ripard 
400b11af8a2SMaxime Ripard 	return __drm_connector_init(dev, connector, funcs, connector_type, ddc);
401100163dfSAndrzej Pietrasiewicz }
402100163dfSAndrzej Pietrasiewicz EXPORT_SYMBOL(drm_connector_init_with_ddc);
403100163dfSAndrzej Pietrasiewicz 
40435a3b82fSMaxime Ripard static void drm_connector_cleanup_action(struct drm_device *dev,
40535a3b82fSMaxime Ripard 					 void *ptr)
40635a3b82fSMaxime Ripard {
40735a3b82fSMaxime Ripard 	struct drm_connector *connector = ptr;
40835a3b82fSMaxime Ripard 
40935a3b82fSMaxime Ripard 	drm_connector_cleanup(connector);
41035a3b82fSMaxime Ripard }
41135a3b82fSMaxime Ripard 
41235a3b82fSMaxime Ripard /**
41335a3b82fSMaxime Ripard  * drmm_connector_init - Init a preallocated connector
41435a3b82fSMaxime Ripard  * @dev: DRM device
41535a3b82fSMaxime Ripard  * @connector: the connector to init
41635a3b82fSMaxime Ripard  * @funcs: callbacks for this connector
41735a3b82fSMaxime Ripard  * @connector_type: user visible type of the connector
41835a3b82fSMaxime Ripard  * @ddc: optional pointer to the associated ddc adapter
41935a3b82fSMaxime Ripard  *
42035a3b82fSMaxime Ripard  * Initialises a preallocated connector. Connectors should be
42135a3b82fSMaxime Ripard  * subclassed as part of driver connector objects.
42235a3b82fSMaxime Ripard  *
42335a3b82fSMaxime Ripard  * Cleanup is automatically handled with a call to
42435a3b82fSMaxime Ripard  * drm_connector_cleanup() in a DRM-managed action.
42535a3b82fSMaxime Ripard  *
42635a3b82fSMaxime Ripard  * The connector structure should be allocated with drmm_kzalloc().
42735a3b82fSMaxime Ripard  *
42835a3b82fSMaxime Ripard  * Returns:
42935a3b82fSMaxime Ripard  * Zero on success, error code on failure.
43035a3b82fSMaxime Ripard  */
43135a3b82fSMaxime Ripard int drmm_connector_init(struct drm_device *dev,
43235a3b82fSMaxime Ripard 			struct drm_connector *connector,
43335a3b82fSMaxime Ripard 			const struct drm_connector_funcs *funcs,
43435a3b82fSMaxime Ripard 			int connector_type,
43535a3b82fSMaxime Ripard 			struct i2c_adapter *ddc)
43635a3b82fSMaxime Ripard {
43735a3b82fSMaxime Ripard 	int ret;
43835a3b82fSMaxime Ripard 
43935a3b82fSMaxime Ripard 	if (drm_WARN_ON(dev, funcs && funcs->destroy))
44035a3b82fSMaxime Ripard 		return -EINVAL;
44135a3b82fSMaxime Ripard 
442a91e5e3eSMaxime Ripard 	ret = __drm_connector_init(dev, connector, funcs, connector_type, ddc);
44335a3b82fSMaxime Ripard 	if (ret)
44435a3b82fSMaxime Ripard 		return ret;
44535a3b82fSMaxime Ripard 
44635a3b82fSMaxime Ripard 	ret = drmm_add_action_or_reset(dev, drm_connector_cleanup_action,
44735a3b82fSMaxime Ripard 				       connector);
44835a3b82fSMaxime Ripard 	if (ret)
44935a3b82fSMaxime Ripard 		return ret;
45035a3b82fSMaxime Ripard 
45135a3b82fSMaxime Ripard 	return 0;
45235a3b82fSMaxime Ripard }
45335a3b82fSMaxime Ripard EXPORT_SYMBOL(drmm_connector_init);
45435a3b82fSMaxime Ripard 
455100163dfSAndrzej Pietrasiewicz /**
4566b7e2d5cSGerd Hoffmann  * drm_connector_attach_edid_property - attach edid property.
4576b7e2d5cSGerd Hoffmann  * @connector: the connector
4586b7e2d5cSGerd Hoffmann  *
4596b7e2d5cSGerd Hoffmann  * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
4606b7e2d5cSGerd Hoffmann  * edid property attached by default.  This function can be used to
4616b7e2d5cSGerd Hoffmann  * explicitly enable the edid property in these cases.
4626b7e2d5cSGerd Hoffmann  */
4636b7e2d5cSGerd Hoffmann void drm_connector_attach_edid_property(struct drm_connector *connector)
4646b7e2d5cSGerd Hoffmann {
4656b7e2d5cSGerd Hoffmann 	struct drm_mode_config *config = &connector->dev->mode_config;
4666b7e2d5cSGerd Hoffmann 
4676b7e2d5cSGerd Hoffmann 	drm_object_attach_property(&connector->base,
4686b7e2d5cSGerd Hoffmann 				   config->edid_property,
4696b7e2d5cSGerd Hoffmann 				   0);
4706b7e2d5cSGerd Hoffmann }
4716b7e2d5cSGerd Hoffmann EXPORT_SYMBOL(drm_connector_attach_edid_property);
4726b7e2d5cSGerd Hoffmann 
4736b7e2d5cSGerd Hoffmann /**
474cde4c44dSDaniel Vetter  * drm_connector_attach_encoder - attach a connector to an encoder
47552217195SDaniel Vetter  * @connector: connector to attach
47652217195SDaniel Vetter  * @encoder: encoder to attach @connector to
47752217195SDaniel Vetter  *
47852217195SDaniel Vetter  * This function links up a connector to an encoder. Note that the routing
47952217195SDaniel Vetter  * restrictions between encoders and crtcs are exposed to userspace through the
48052217195SDaniel Vetter  * possible_clones and possible_crtcs bitmasks.
48152217195SDaniel Vetter  *
48252217195SDaniel Vetter  * Returns:
48352217195SDaniel Vetter  * Zero on success, negative errno on failure.
48452217195SDaniel Vetter  */
485cde4c44dSDaniel Vetter int drm_connector_attach_encoder(struct drm_connector *connector,
48652217195SDaniel Vetter 				 struct drm_encoder *encoder)
48752217195SDaniel Vetter {
48852217195SDaniel Vetter 	/*
48952217195SDaniel Vetter 	 * In the past, drivers have attempted to model the static association
49052217195SDaniel Vetter 	 * of connector to encoder in simple connector/encoder devices using a
49152217195SDaniel Vetter 	 * direct assignment of connector->encoder = encoder. This connection
49252217195SDaniel Vetter 	 * is a logical one and the responsibility of the core, so drivers are
49352217195SDaniel Vetter 	 * expected not to mess with this.
49452217195SDaniel Vetter 	 *
49552217195SDaniel Vetter 	 * Note that the error return should've been enough here, but a large
49652217195SDaniel Vetter 	 * majority of drivers ignores the return value, so add in a big WARN
49752217195SDaniel Vetter 	 * to get people's attention.
49852217195SDaniel Vetter 	 */
49952217195SDaniel Vetter 	if (WARN_ON(connector->encoder))
50052217195SDaniel Vetter 		return -EINVAL;
50152217195SDaniel Vetter 
50262afb4adSJosé Roberto de Souza 	connector->possible_encoders |= drm_encoder_mask(encoder);
50362afb4adSJosé Roberto de Souza 
50452217195SDaniel Vetter 	return 0;
50552217195SDaniel Vetter }
506cde4c44dSDaniel Vetter EXPORT_SYMBOL(drm_connector_attach_encoder);
50752217195SDaniel Vetter 
50838cb8d96SVille Syrjälä /**
50962afb4adSJosé Roberto de Souza  * drm_connector_has_possible_encoder - check if the connector and encoder are
51062afb4adSJosé Roberto de Souza  * associated with each other
51138cb8d96SVille Syrjälä  * @connector: the connector
51238cb8d96SVille Syrjälä  * @encoder: the encoder
51338cb8d96SVille Syrjälä  *
51438cb8d96SVille Syrjälä  * Returns:
51538cb8d96SVille Syrjälä  * True if @encoder is one of the possible encoders for @connector.
51638cb8d96SVille Syrjälä  */
51738cb8d96SVille Syrjälä bool drm_connector_has_possible_encoder(struct drm_connector *connector,
51838cb8d96SVille Syrjälä 					struct drm_encoder *encoder)
51938cb8d96SVille Syrjälä {
52062afb4adSJosé Roberto de Souza 	return connector->possible_encoders & drm_encoder_mask(encoder);
52138cb8d96SVille Syrjälä }
52238cb8d96SVille Syrjälä EXPORT_SYMBOL(drm_connector_has_possible_encoder);
52338cb8d96SVille Syrjälä 
52452217195SDaniel Vetter static void drm_mode_remove(struct drm_connector *connector,
52552217195SDaniel Vetter 			    struct drm_display_mode *mode)
52652217195SDaniel Vetter {
52752217195SDaniel Vetter 	list_del(&mode->head);
52852217195SDaniel Vetter 	drm_mode_destroy(connector->dev, mode);
52952217195SDaniel Vetter }
53052217195SDaniel Vetter 
53152217195SDaniel Vetter /**
53252217195SDaniel Vetter  * drm_connector_cleanup - cleans up an initialised connector
53352217195SDaniel Vetter  * @connector: connector to cleanup
53452217195SDaniel Vetter  *
53552217195SDaniel Vetter  * Cleans up the connector but doesn't free the object.
53652217195SDaniel Vetter  */
53752217195SDaniel Vetter void drm_connector_cleanup(struct drm_connector *connector)
53852217195SDaniel Vetter {
53952217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
54052217195SDaniel Vetter 	struct drm_display_mode *mode, *t;
54152217195SDaniel Vetter 
54252217195SDaniel Vetter 	/* The connector should have been removed from userspace long before
54352217195SDaniel Vetter 	 * it is finally destroyed.
54452217195SDaniel Vetter 	 */
54539b50c60SLyude Paul 	if (WARN_ON(connector->registration_state ==
54639b50c60SLyude Paul 		    DRM_CONNECTOR_REGISTERED))
54752217195SDaniel Vetter 		drm_connector_unregister(connector);
54852217195SDaniel Vetter 
549334f74eeSHans de Goede 	if (connector->privacy_screen) {
550334f74eeSHans de Goede 		drm_privacy_screen_put(connector->privacy_screen);
551334f74eeSHans de Goede 		connector->privacy_screen = NULL;
552334f74eeSHans de Goede 	}
553334f74eeSHans de Goede 
55452217195SDaniel Vetter 	if (connector->tile_group) {
55552217195SDaniel Vetter 		drm_mode_put_tile_group(dev, connector->tile_group);
55652217195SDaniel Vetter 		connector->tile_group = NULL;
55752217195SDaniel Vetter 	}
55852217195SDaniel Vetter 
55952217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
56052217195SDaniel Vetter 		drm_mode_remove(connector, mode);
56152217195SDaniel Vetter 
56252217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->modes, head)
56352217195SDaniel Vetter 		drm_mode_remove(connector, mode);
56452217195SDaniel Vetter 
565e5d6eeeaSBo Liu 	ida_free(&drm_connector_enum_list[connector->connector_type].ida,
56652217195SDaniel Vetter 			  connector->connector_type_id);
56752217195SDaniel Vetter 
568e5d6eeeaSBo Liu 	ida_free(&dev->mode_config.connector_ida, connector->index);
56952217195SDaniel Vetter 
57052217195SDaniel Vetter 	kfree(connector->display_info.bus_formats);
571c3292ab5SJani Nikula 	kfree(connector->display_info.vics);
57252217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
57352217195SDaniel Vetter 	kfree(connector->name);
57452217195SDaniel Vetter 	connector->name = NULL;
57548c429c6SHans de Goede 	fwnode_handle_put(connector->fwnode);
57648c429c6SHans de Goede 	connector->fwnode = NULL;
577613051daSDaniel Vetter 	spin_lock_irq(&dev->mode_config.connector_list_lock);
57852217195SDaniel Vetter 	list_del(&connector->head);
57952217195SDaniel Vetter 	dev->mode_config.num_connector--;
580613051daSDaniel Vetter 	spin_unlock_irq(&dev->mode_config.connector_list_lock);
58152217195SDaniel Vetter 
58252217195SDaniel Vetter 	WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
58352217195SDaniel Vetter 	if (connector->state && connector->funcs->atomic_destroy_state)
58452217195SDaniel Vetter 		connector->funcs->atomic_destroy_state(connector,
58552217195SDaniel Vetter 						       connector->state);
58652217195SDaniel Vetter 
587e73ab00eSDaniel Vetter 	mutex_destroy(&connector->mutex);
588e73ab00eSDaniel Vetter 
58952217195SDaniel Vetter 	memset(connector, 0, sizeof(*connector));
5906fdc2d49SSimon Ser 
5916fdc2d49SSimon Ser 	if (dev->registered)
5926fdc2d49SSimon Ser 		drm_sysfs_hotplug_event(dev);
59352217195SDaniel Vetter }
59452217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_cleanup);
59552217195SDaniel Vetter 
59652217195SDaniel Vetter /**
59752217195SDaniel Vetter  * drm_connector_register - register a connector
59852217195SDaniel Vetter  * @connector: the connector to register
59952217195SDaniel Vetter  *
60069b22f51SDaniel Vetter  * Register userspace interfaces for a connector. Only call this for connectors
60169b22f51SDaniel Vetter  * which can be hotplugged after drm_dev_register() has been called already,
60269b22f51SDaniel Vetter  * e.g. DP MST connectors. All other connectors will be registered automatically
60369b22f51SDaniel Vetter  * when calling drm_dev_register().
60452217195SDaniel Vetter  *
605d87fbea5SMaxime Ripard  * When the connector is no longer available, callers must call
606d87fbea5SMaxime Ripard  * drm_connector_unregister().
607d87fbea5SMaxime Ripard  *
60852217195SDaniel Vetter  * Returns:
60952217195SDaniel Vetter  * Zero on success, error code on failure.
61052217195SDaniel Vetter  */
61152217195SDaniel Vetter int drm_connector_register(struct drm_connector *connector)
61252217195SDaniel Vetter {
613e73ab00eSDaniel Vetter 	int ret = 0;
61452217195SDaniel Vetter 
615e6e7b48bSDaniel Vetter 	if (!connector->dev->registered)
616e6e7b48bSDaniel Vetter 		return 0;
617e6e7b48bSDaniel Vetter 
618e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
61939b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
620e73ab00eSDaniel Vetter 		goto unlock;
62152217195SDaniel Vetter 
62252217195SDaniel Vetter 	ret = drm_sysfs_connector_add(connector);
62352217195SDaniel Vetter 	if (ret)
624e73ab00eSDaniel Vetter 		goto unlock;
62552217195SDaniel Vetter 
626b792e640SGreg Kroah-Hartman 	drm_debugfs_connector_add(connector);
62752217195SDaniel Vetter 
62852217195SDaniel Vetter 	if (connector->funcs->late_register) {
62952217195SDaniel Vetter 		ret = connector->funcs->late_register(connector);
63052217195SDaniel Vetter 		if (ret)
63152217195SDaniel Vetter 			goto err_debugfs;
63252217195SDaniel Vetter 	}
63352217195SDaniel Vetter 
63452217195SDaniel Vetter 	drm_mode_object_register(connector->dev, &connector->base);
63552217195SDaniel Vetter 
63639b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_REGISTERED;
637968d81a6SJeykumar Sankaran 
638968d81a6SJeykumar Sankaran 	/* Let userspace know we have a new connector */
639ad935754SSimon Ser 	drm_sysfs_connector_hotplug_event(connector);
640968d81a6SJeykumar Sankaran 
641334f74eeSHans de Goede 	if (connector->privacy_screen)
642334f74eeSHans de Goede 		drm_privacy_screen_register_notifier(connector->privacy_screen,
643334f74eeSHans de Goede 					   &connector->privacy_screen_notifier);
644334f74eeSHans de Goede 
6453d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
6463d3f7c1eSHans de Goede 	list_add_tail(&connector->global_connector_list_entry, &connector_list);
6473d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
648e73ab00eSDaniel Vetter 	goto unlock;
64952217195SDaniel Vetter 
65052217195SDaniel Vetter err_debugfs:
65152217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
65252217195SDaniel Vetter 	drm_sysfs_connector_remove(connector);
653e73ab00eSDaniel Vetter unlock:
654e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
65552217195SDaniel Vetter 	return ret;
65652217195SDaniel Vetter }
65752217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_register);
65852217195SDaniel Vetter 
65952217195SDaniel Vetter /**
66052217195SDaniel Vetter  * drm_connector_unregister - unregister a connector
66152217195SDaniel Vetter  * @connector: the connector to unregister
66252217195SDaniel Vetter  *
66369b22f51SDaniel Vetter  * Unregister userspace interfaces for a connector. Only call this for
664d87fbea5SMaxime Ripard  * connectors which have been registered explicitly by calling
665d87fbea5SMaxime Ripard  * drm_connector_register().
66652217195SDaniel Vetter  */
66752217195SDaniel Vetter void drm_connector_unregister(struct drm_connector *connector)
66852217195SDaniel Vetter {
669e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
67039b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
671e73ab00eSDaniel Vetter 		mutex_unlock(&connector->mutex);
67252217195SDaniel Vetter 		return;
673e73ab00eSDaniel Vetter 	}
67452217195SDaniel Vetter 
6753d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
6763d3f7c1eSHans de Goede 	list_del_init(&connector->global_connector_list_entry);
6773d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
6783d3f7c1eSHans de Goede 
679334f74eeSHans de Goede 	if (connector->privacy_screen)
680334f74eeSHans de Goede 		drm_privacy_screen_unregister_notifier(
681334f74eeSHans de Goede 					connector->privacy_screen,
682334f74eeSHans de Goede 					&connector->privacy_screen_notifier);
683334f74eeSHans de Goede 
68452217195SDaniel Vetter 	if (connector->funcs->early_unregister)
68552217195SDaniel Vetter 		connector->funcs->early_unregister(connector);
68652217195SDaniel Vetter 
68752217195SDaniel Vetter 	drm_sysfs_connector_remove(connector);
68852217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
68952217195SDaniel Vetter 
69039b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
691e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
69252217195SDaniel Vetter }
69352217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_unregister);
69452217195SDaniel Vetter 
69552217195SDaniel Vetter void drm_connector_unregister_all(struct drm_device *dev)
69652217195SDaniel Vetter {
69752217195SDaniel Vetter 	struct drm_connector *connector;
698613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
69952217195SDaniel Vetter 
700b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
701613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter)
70252217195SDaniel Vetter 		drm_connector_unregister(connector);
703b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
70452217195SDaniel Vetter }
70552217195SDaniel Vetter 
70652217195SDaniel Vetter int drm_connector_register_all(struct drm_device *dev)
70752217195SDaniel Vetter {
70852217195SDaniel Vetter 	struct drm_connector *connector;
709613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
710613051daSDaniel Vetter 	int ret = 0;
71152217195SDaniel Vetter 
712b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
713613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter) {
71452217195SDaniel Vetter 		ret = drm_connector_register(connector);
71552217195SDaniel Vetter 		if (ret)
716613051daSDaniel Vetter 			break;
71752217195SDaniel Vetter 	}
718b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
71952217195SDaniel Vetter 
720613051daSDaniel Vetter 	if (ret)
72152217195SDaniel Vetter 		drm_connector_unregister_all(dev);
72252217195SDaniel Vetter 	return ret;
72352217195SDaniel Vetter }
72452217195SDaniel Vetter 
72552217195SDaniel Vetter /**
72652217195SDaniel Vetter  * drm_get_connector_status_name - return a string for connector status
72752217195SDaniel Vetter  * @status: connector status to compute name of
72852217195SDaniel Vetter  *
72952217195SDaniel Vetter  * In contrast to the other drm_get_*_name functions this one here returns a
73052217195SDaniel Vetter  * const pointer and hence is threadsafe.
731f85d9e59SRandy Dunlap  *
732f85d9e59SRandy Dunlap  * Returns: connector status string
73352217195SDaniel Vetter  */
73452217195SDaniel Vetter const char *drm_get_connector_status_name(enum drm_connector_status status)
73552217195SDaniel Vetter {
73652217195SDaniel Vetter 	if (status == connector_status_connected)
73752217195SDaniel Vetter 		return "connected";
73852217195SDaniel Vetter 	else if (status == connector_status_disconnected)
73952217195SDaniel Vetter 		return "disconnected";
74052217195SDaniel Vetter 	else
74152217195SDaniel Vetter 		return "unknown";
74252217195SDaniel Vetter }
74352217195SDaniel Vetter EXPORT_SYMBOL(drm_get_connector_status_name);
74452217195SDaniel Vetter 
7456140cf20SJani Nikula /**
7466140cf20SJani Nikula  * drm_get_connector_force_name - return a string for connector force
7476140cf20SJani Nikula  * @force: connector force to get name of
7486140cf20SJani Nikula  *
7496140cf20SJani Nikula  * Returns: const pointer to name.
7506140cf20SJani Nikula  */
7516140cf20SJani Nikula const char *drm_get_connector_force_name(enum drm_connector_force force)
7526140cf20SJani Nikula {
7536140cf20SJani Nikula 	switch (force) {
7546140cf20SJani Nikula 	case DRM_FORCE_UNSPECIFIED:
7556140cf20SJani Nikula 		return "unspecified";
7566140cf20SJani Nikula 	case DRM_FORCE_OFF:
7576140cf20SJani Nikula 		return "off";
7586140cf20SJani Nikula 	case DRM_FORCE_ON:
7596140cf20SJani Nikula 		return "on";
7606140cf20SJani Nikula 	case DRM_FORCE_ON_DIGITAL:
7616140cf20SJani Nikula 		return "digital";
7626140cf20SJani Nikula 	default:
7636140cf20SJani Nikula 		return "unknown";
7646140cf20SJani Nikula 	}
7656140cf20SJani Nikula }
7666140cf20SJani Nikula 
767613051daSDaniel Vetter #ifdef CONFIG_LOCKDEP
768613051daSDaniel Vetter static struct lockdep_map connector_list_iter_dep_map = {
769613051daSDaniel Vetter 	.name = "drm_connector_list_iter"
770613051daSDaniel Vetter };
771613051daSDaniel Vetter #endif
772613051daSDaniel Vetter 
773613051daSDaniel Vetter /**
774b982dab1SThierry Reding  * drm_connector_list_iter_begin - initialize a connector_list iterator
775613051daSDaniel Vetter  * @dev: DRM device
776613051daSDaniel Vetter  * @iter: connector_list iterator
777613051daSDaniel Vetter  *
778d574528aSDaniel Vetter  * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
779b982dab1SThierry Reding  * must always be cleaned up again by calling drm_connector_list_iter_end().
780613051daSDaniel Vetter  * Iteration itself happens using drm_connector_list_iter_next() or
781613051daSDaniel Vetter  * drm_for_each_connector_iter().
782613051daSDaniel Vetter  */
783b982dab1SThierry Reding void drm_connector_list_iter_begin(struct drm_device *dev,
784613051daSDaniel Vetter 				   struct drm_connector_list_iter *iter)
785613051daSDaniel Vetter {
786613051daSDaniel Vetter 	iter->dev = dev;
787613051daSDaniel Vetter 	iter->conn = NULL;
788613051daSDaniel Vetter 	lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
789613051daSDaniel Vetter }
790b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_begin);
791613051daSDaniel Vetter 
792a703c550SDaniel Vetter /*
793a703c550SDaniel Vetter  * Extra-safe connector put function that works in any context. Should only be
794a703c550SDaniel Vetter  * used from the connector_iter functions, where we never really expect to
795a703c550SDaniel Vetter  * actually release the connector when dropping our final reference.
796a703c550SDaniel Vetter  */
797a703c550SDaniel Vetter static void
798ea497bb9SDaniel Vetter __drm_connector_put_safe(struct drm_connector *conn)
799a703c550SDaniel Vetter {
800ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &conn->dev->mode_config;
801ea497bb9SDaniel Vetter 
802ea497bb9SDaniel Vetter 	lockdep_assert_held(&config->connector_list_lock);
803ea497bb9SDaniel Vetter 
804ea497bb9SDaniel Vetter 	if (!refcount_dec_and_test(&conn->base.refcount.refcount))
805ea497bb9SDaniel Vetter 		return;
806ea497bb9SDaniel Vetter 
807ea497bb9SDaniel Vetter 	llist_add(&conn->free_node, &config->connector_free_list);
808ea497bb9SDaniel Vetter 	schedule_work(&config->connector_free_work);
809a703c550SDaniel Vetter }
810a703c550SDaniel Vetter 
811613051daSDaniel Vetter /**
812613051daSDaniel Vetter  * drm_connector_list_iter_next - return next connector
8134f45c778SLyude Paul  * @iter: connector_list iterator
814613051daSDaniel Vetter  *
815f85d9e59SRandy Dunlap  * Returns: the next connector for @iter, or NULL when the list walk has
816613051daSDaniel Vetter  * completed.
817613051daSDaniel Vetter  */
818613051daSDaniel Vetter struct drm_connector *
819613051daSDaniel Vetter drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
820613051daSDaniel Vetter {
821613051daSDaniel Vetter 	struct drm_connector *old_conn = iter->conn;
822613051daSDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
823613051daSDaniel Vetter 	struct list_head *lhead;
824613051daSDaniel Vetter 	unsigned long flags;
825613051daSDaniel Vetter 
826613051daSDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
827613051daSDaniel Vetter 	lhead = old_conn ? &old_conn->head : &config->connector_list;
828613051daSDaniel Vetter 
829613051daSDaniel Vetter 	do {
830613051daSDaniel Vetter 		if (lhead->next == &config->connector_list) {
831613051daSDaniel Vetter 			iter->conn = NULL;
832613051daSDaniel Vetter 			break;
833613051daSDaniel Vetter 		}
834613051daSDaniel Vetter 
835613051daSDaniel Vetter 		lhead = lhead->next;
836613051daSDaniel Vetter 		iter->conn = list_entry(lhead, struct drm_connector, head);
837613051daSDaniel Vetter 
838613051daSDaniel Vetter 		/* loop until it's not a zombie connector */
839613051daSDaniel Vetter 	} while (!kref_get_unless_zero(&iter->conn->base.refcount));
840613051daSDaniel Vetter 
841613051daSDaniel Vetter 	if (old_conn)
842ea497bb9SDaniel Vetter 		__drm_connector_put_safe(old_conn);
843ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
844613051daSDaniel Vetter 
845613051daSDaniel Vetter 	return iter->conn;
846613051daSDaniel Vetter }
847613051daSDaniel Vetter EXPORT_SYMBOL(drm_connector_list_iter_next);
848613051daSDaniel Vetter 
849613051daSDaniel Vetter /**
850b982dab1SThierry Reding  * drm_connector_list_iter_end - tear down a connector_list iterator
851613051daSDaniel Vetter  * @iter: connector_list iterator
852613051daSDaniel Vetter  *
853613051daSDaniel Vetter  * Tears down @iter and releases any resources (like &drm_connector references)
854613051daSDaniel Vetter  * acquired while walking the list. This must always be called, both when the
855613051daSDaniel Vetter  * iteration completes fully or when it was aborted without walking the entire
856613051daSDaniel Vetter  * list.
857613051daSDaniel Vetter  */
858b982dab1SThierry Reding void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
859613051daSDaniel Vetter {
860ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
861ea497bb9SDaniel Vetter 	unsigned long flags;
862ea497bb9SDaniel Vetter 
863613051daSDaniel Vetter 	iter->dev = NULL;
864ea497bb9SDaniel Vetter 	if (iter->conn) {
865ea497bb9SDaniel Vetter 		spin_lock_irqsave(&config->connector_list_lock, flags);
866ea497bb9SDaniel Vetter 		__drm_connector_put_safe(iter->conn);
867ea497bb9SDaniel Vetter 		spin_unlock_irqrestore(&config->connector_list_lock, flags);
868ea497bb9SDaniel Vetter 	}
8695facae4fSQian Cai 	lock_release(&connector_list_iter_dep_map, _RET_IP_);
870613051daSDaniel Vetter }
871b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_end);
872613051daSDaniel Vetter 
87352217195SDaniel Vetter static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
87452217195SDaniel Vetter 	{ SubPixelUnknown, "Unknown" },
87552217195SDaniel Vetter 	{ SubPixelHorizontalRGB, "Horizontal RGB" },
87652217195SDaniel Vetter 	{ SubPixelHorizontalBGR, "Horizontal BGR" },
87752217195SDaniel Vetter 	{ SubPixelVerticalRGB, "Vertical RGB" },
87852217195SDaniel Vetter 	{ SubPixelVerticalBGR, "Vertical BGR" },
87952217195SDaniel Vetter 	{ SubPixelNone, "None" },
88052217195SDaniel Vetter };
88152217195SDaniel Vetter 
88252217195SDaniel Vetter /**
88352217195SDaniel Vetter  * drm_get_subpixel_order_name - return a string for a given subpixel enum
88452217195SDaniel Vetter  * @order: enum of subpixel_order
88552217195SDaniel Vetter  *
88652217195SDaniel Vetter  * Note you could abuse this and return something out of bounds, but that
88752217195SDaniel Vetter  * would be a caller error.  No unscrubbed user data should make it here.
888f85d9e59SRandy Dunlap  *
889f85d9e59SRandy Dunlap  * Returns: string describing an enumerated subpixel property
89052217195SDaniel Vetter  */
89152217195SDaniel Vetter const char *drm_get_subpixel_order_name(enum subpixel_order order)
89252217195SDaniel Vetter {
89352217195SDaniel Vetter 	return drm_subpixel_enum_list[order].name;
89452217195SDaniel Vetter }
89552217195SDaniel Vetter EXPORT_SYMBOL(drm_get_subpixel_order_name);
89652217195SDaniel Vetter 
89752217195SDaniel Vetter static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
89852217195SDaniel Vetter 	{ DRM_MODE_DPMS_ON, "On" },
89952217195SDaniel Vetter 	{ DRM_MODE_DPMS_STANDBY, "Standby" },
90052217195SDaniel Vetter 	{ DRM_MODE_DPMS_SUSPEND, "Suspend" },
90152217195SDaniel Vetter 	{ DRM_MODE_DPMS_OFF, "Off" }
90252217195SDaniel Vetter };
90352217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
90452217195SDaniel Vetter 
90540ee6fbeSManasi Navare static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
90640ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_GOOD, "Good" },
90740ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_BAD, "Bad" },
90840ee6fbeSManasi Navare };
90940ee6fbeSManasi Navare 
910b3c6c8bfSDaniel Vetter /**
911b3c6c8bfSDaniel Vetter  * drm_display_info_set_bus_formats - set the supported bus formats
912b3c6c8bfSDaniel Vetter  * @info: display info to store bus formats in
913b3c6c8bfSDaniel Vetter  * @formats: array containing the supported bus formats
914b3c6c8bfSDaniel Vetter  * @num_formats: the number of entries in the fmts array
915b3c6c8bfSDaniel Vetter  *
916b3c6c8bfSDaniel Vetter  * Store the supported bus formats in display info structure.
917b3c6c8bfSDaniel Vetter  * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
918b3c6c8bfSDaniel Vetter  * a full list of available formats.
919f85d9e59SRandy Dunlap  *
920f85d9e59SRandy Dunlap  * Returns:
921f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
922b3c6c8bfSDaniel Vetter  */
923b3c6c8bfSDaniel Vetter int drm_display_info_set_bus_formats(struct drm_display_info *info,
924b3c6c8bfSDaniel Vetter 				     const u32 *formats,
925b3c6c8bfSDaniel Vetter 				     unsigned int num_formats)
926b3c6c8bfSDaniel Vetter {
927b3c6c8bfSDaniel Vetter 	u32 *fmts = NULL;
928b3c6c8bfSDaniel Vetter 
929b3c6c8bfSDaniel Vetter 	if (!formats && num_formats)
930b3c6c8bfSDaniel Vetter 		return -EINVAL;
931b3c6c8bfSDaniel Vetter 
932b3c6c8bfSDaniel Vetter 	if (formats && num_formats) {
933b3c6c8bfSDaniel Vetter 		fmts = kmemdup(formats, sizeof(*formats) * num_formats,
934b3c6c8bfSDaniel Vetter 			       GFP_KERNEL);
935b3c6c8bfSDaniel Vetter 		if (!fmts)
936b3c6c8bfSDaniel Vetter 			return -ENOMEM;
937b3c6c8bfSDaniel Vetter 	}
938b3c6c8bfSDaniel Vetter 
939b3c6c8bfSDaniel Vetter 	kfree(info->bus_formats);
940b3c6c8bfSDaniel Vetter 	info->bus_formats = fmts;
941b3c6c8bfSDaniel Vetter 	info->num_bus_formats = num_formats;
942b3c6c8bfSDaniel Vetter 
943b3c6c8bfSDaniel Vetter 	return 0;
944b3c6c8bfSDaniel Vetter }
945b3c6c8bfSDaniel Vetter EXPORT_SYMBOL(drm_display_info_set_bus_formats);
946b3c6c8bfSDaniel Vetter 
94752217195SDaniel Vetter /* Optional connector properties. */
94852217195SDaniel Vetter static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
94952217195SDaniel Vetter 	{ DRM_MODE_SCALE_NONE, "None" },
95052217195SDaniel Vetter 	{ DRM_MODE_SCALE_FULLSCREEN, "Full" },
95152217195SDaniel Vetter 	{ DRM_MODE_SCALE_CENTER, "Center" },
95252217195SDaniel Vetter 	{ DRM_MODE_SCALE_ASPECT, "Full aspect" },
95352217195SDaniel Vetter };
95452217195SDaniel Vetter 
95552217195SDaniel Vetter static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
95652217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
95752217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
95852217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
95952217195SDaniel Vetter };
96052217195SDaniel Vetter 
96150525c33SStanislav Lisovskiy static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
96250525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
96350525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
96450525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
96550525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
96650525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GAME, "Game" },
96750525c33SStanislav Lisovskiy };
96850525c33SStanislav Lisovskiy 
9698d70f395SHans de Goede static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
9708d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_NORMAL,	"Normal"	},
9718d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP,	"Upside Down"	},
9728d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_LEFT_UP,	"Left Side Up"	},
9738d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,	"Right Side Up"	},
9748d70f395SHans de Goede };
9758d70f395SHans de Goede 
97652217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
97752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
97852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
97952217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
98052217195SDaniel Vetter };
98152217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
98252217195SDaniel Vetter 
98352217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
984e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I, TV-out and DP */
98552217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
98652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
98752217195SDaniel Vetter };
98852217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
98952217195SDaniel Vetter 		 drm_dvi_i_subconnector_enum_list)
99052217195SDaniel Vetter 
9917d63cd85SMaxime Ripard static const struct drm_prop_enum_list drm_tv_mode_enum_list[] = {
9927d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_NTSC, "NTSC" },
9937d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_NTSC_443, "NTSC-443" },
9947d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_NTSC_J, "NTSC-J" },
9957d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_PAL, "PAL" },
9967d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_PAL_M, "PAL-M" },
9977d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_PAL_N, "PAL-N" },
9987d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_SECAM, "SECAM" },
9997d63cd85SMaxime Ripard };
10007d63cd85SMaxime Ripard DRM_ENUM_NAME_FN(drm_get_tv_mode_name, drm_tv_mode_enum_list)
10017d63cd85SMaxime Ripard 
1002d4613e3eSMaxime Ripard /**
1003d4613e3eSMaxime Ripard  * drm_get_tv_mode_from_name - Translates a TV mode name into its enum value
1004d4613e3eSMaxime Ripard  * @name: TV Mode name we want to convert
1005d4613e3eSMaxime Ripard  * @len: Length of @name
1006d4613e3eSMaxime Ripard  *
1007d4613e3eSMaxime Ripard  * Translates @name into an enum drm_connector_tv_mode.
1008d4613e3eSMaxime Ripard  *
1009d4613e3eSMaxime Ripard  * Returns: the enum value on success, a negative errno otherwise.
1010d4613e3eSMaxime Ripard  */
1011d4613e3eSMaxime Ripard int drm_get_tv_mode_from_name(const char *name, size_t len)
1012d4613e3eSMaxime Ripard {
1013d4613e3eSMaxime Ripard 	unsigned int i;
1014d4613e3eSMaxime Ripard 
1015d4613e3eSMaxime Ripard 	for (i = 0; i < ARRAY_SIZE(drm_tv_mode_enum_list); i++) {
1016d4613e3eSMaxime Ripard 		const struct drm_prop_enum_list *item = &drm_tv_mode_enum_list[i];
1017d4613e3eSMaxime Ripard 
1018d4613e3eSMaxime Ripard 		if (strlen(item->name) == len && !strncmp(item->name, name, len))
1019d4613e3eSMaxime Ripard 			return item->type;
1020d4613e3eSMaxime Ripard 	}
1021d4613e3eSMaxime Ripard 
1022d4613e3eSMaxime Ripard 	return -EINVAL;
1023d4613e3eSMaxime Ripard }
1024d4613e3eSMaxime Ripard EXPORT_SYMBOL(drm_get_tv_mode_from_name);
1025d4613e3eSMaxime Ripard 
102652217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
102752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
102852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
102952217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
103052217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
103152217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
103252217195SDaniel Vetter };
103352217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
103452217195SDaniel Vetter 
103552217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
1036e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I, TV-out and DP */
103752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
103852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
103952217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
104052217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
104152217195SDaniel Vetter };
104252217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
104352217195SDaniel Vetter 		 drm_tv_subconnector_enum_list)
104452217195SDaniel Vetter 
1045e5b92773SOleg Vasilev static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = {
1046e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,     "Unknown"   }, /* DVI-I, TV-out and DP */
1047e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_VGA,	     "VGA"       }, /* DP */
1048e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_DVID,	     "DVI-D"     }, /* DP */
1049e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_HDMIA,	     "HDMI"      }, /* DP */
1050e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_DisplayPort, "DP"        }, /* DP */
1051e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Wireless,    "Wireless"  }, /* DP */
1052e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Native,	     "Native"    }, /* DP */
1053e5b92773SOleg Vasilev };
1054e5b92773SOleg Vasilev 
1055e5b92773SOleg Vasilev DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name,
1056e5b92773SOleg Vasilev 		 drm_dp_subconnector_enum_list)
1057e5b92773SOleg Vasilev 
1058*c627087cSHarry Wentland 
1059*c627087cSHarry Wentland static const char * const colorspace_names[] = {
1060d2c6a405SUma Shankar 	/* For Default case, driver will set the colorspace */
1061*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_DEFAULT] = "Default",
1062d2c6a405SUma Shankar 	/* Standard Definition Colorimetry based on CEA 861 */
1063*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = "SMPTE_170M_YCC",
1064*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT709_YCC] = "BT709_YCC",
1065d2c6a405SUma Shankar 	/* Standard Definition Colorimetry based on IEC 61966-2-4 */
1066*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_XVYCC_601] = "XVYCC_601",
1067d2c6a405SUma Shankar 	/* High Definition Colorimetry based on IEC 61966-2-4 */
1068*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_XVYCC_709] = "XVYCC_709",
1069d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-1/Amendment 1 */
1070*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_SYCC_601] = "SYCC_601",
1071d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-5 [33] */
1072*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_OPYCC_601] = "opYCC_601",
1073d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-5 */
1074*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_OPRGB] = "opRGB",
1075d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
1076*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT2020_CYCC] = "BT2020_CYCC",
1077d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
1078*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT2020_RGB] = "BT2020_RGB",
1079d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
1080*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT2020_YCC] = "BT2020_YCC",
1081d2c6a405SUma Shankar 	/* Added as part of Additional Colorimetry Extension in 861.G */
1082*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65] = "DCI-P3_RGB_D65",
1083*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER] = "DCI-P3_RGB_Theater",
1084*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED] = "RGB_WIDE_FIXED",
1085*c627087cSHarry Wentland 	/* Colorimetry based on scRGB (IEC 61966-2-2) */
1086*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT] = "RGB_WIDE_FLOAT",
1087*c627087cSHarry Wentland 	[DRM_MODE_COLORIMETRY_BT601_YCC] = "BT601_YCC",
1088d2c6a405SUma Shankar };
1089d2c6a405SUma Shankar 
1090*c627087cSHarry Wentland static const u32 hdmi_colorspaces =
1091*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_SMPTE_170M_YCC) |
1092*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |
1093*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_XVYCC_601) |
1094*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_XVYCC_709) |
1095*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_SYCC_601) |
1096*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_OPYCC_601) |
1097*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_OPRGB) |
1098*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) |
1099*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) |
1100*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_YCC) |
1101*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) |
1102*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER);
1103*c627087cSHarry Wentland 
110445cf0e91SGwan-gyeong Mun /*
110545cf0e91SGwan-gyeong Mun  * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
110645cf0e91SGwan-gyeong Mun  * Format Table 2-120
110745cf0e91SGwan-gyeong Mun  */
1108*c627087cSHarry Wentland static const u32 dp_colorspaces =
1109*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED) |
1110*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT) |
1111*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_OPRGB) |
1112*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) |
1113*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) |
1114*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT601_YCC) |
1115*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |
1116*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_XVYCC_601) |
1117*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_XVYCC_709) |
1118*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_SYCC_601) |
1119*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_OPYCC_601) |
1120*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) |
1121*c627087cSHarry Wentland 	BIT(DRM_MODE_COLORIMETRY_BT2020_YCC);
112245cf0e91SGwan-gyeong Mun 
11234ada6f22SDaniel Vetter /**
11244ada6f22SDaniel Vetter  * DOC: standard connector properties
11254ada6f22SDaniel Vetter  *
11264ada6f22SDaniel Vetter  * DRM connectors have a few standardized properties:
11274ada6f22SDaniel Vetter  *
11284ada6f22SDaniel Vetter  * EDID:
11294ada6f22SDaniel Vetter  * 	Blob property which contains the current EDID read from the sink. This
11304ada6f22SDaniel Vetter  * 	is useful to parse sink identification information like vendor, model
11314ada6f22SDaniel Vetter  * 	and serial. Drivers should update this property by calling
1132c555f023SDaniel Vetter  * 	drm_connector_update_edid_property(), usually after having parsed
11334ada6f22SDaniel Vetter  * 	the EDID using drm_add_edid_modes(). Userspace cannot change this
11344ada6f22SDaniel Vetter  * 	property.
113512767469SSimon Ser  *
113612767469SSimon Ser  * 	User-space should not parse the EDID to obtain information exposed via
113712767469SSimon Ser  * 	other KMS properties (because the kernel might apply limits, quirks or
113812767469SSimon Ser  * 	fixups to the EDID). For instance, user-space should not try to parse
113912767469SSimon Ser  * 	mode lists from the EDID.
11404ada6f22SDaniel Vetter  * DPMS:
11414ada6f22SDaniel Vetter  * 	Legacy property for setting the power state of the connector. For atomic
11424ada6f22SDaniel Vetter  * 	drivers this is only provided for backwards compatibility with existing
11434ada6f22SDaniel Vetter  * 	drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
11444ada6f22SDaniel Vetter  * 	connector is linked to. Drivers should never set this property directly,
1145d574528aSDaniel Vetter  * 	it is handled by the DRM core by calling the &drm_connector_funcs.dpms
1146144a7999SDaniel Vetter  * 	callback. For atomic drivers the remapping to the "ACTIVE" property is
11471e3e4caeSSimon Ser  * 	implemented in the DRM core.
1148d0d1aee5SDaniel Vetter  *
1149d0d1aee5SDaniel Vetter  * 	Note that this property cannot be set through the MODE_ATOMIC ioctl,
1150d0d1aee5SDaniel Vetter  * 	userspace must use "ACTIVE" on the CRTC instead.
1151d0d1aee5SDaniel Vetter  *
1152d0d1aee5SDaniel Vetter  * 	WARNING:
1153d0d1aee5SDaniel Vetter  *
1154d0d1aee5SDaniel Vetter  * 	For userspace also running on legacy drivers the "DPMS" semantics are a
1155d0d1aee5SDaniel Vetter  * 	lot more complicated. First, userspace cannot rely on the "DPMS" value
1156d0d1aee5SDaniel Vetter  * 	returned by the GETCONNECTOR actually reflecting reality, because many
1157d0d1aee5SDaniel Vetter  * 	drivers fail to update it. For atomic drivers this is taken care of in
1158d0d1aee5SDaniel Vetter  * 	drm_atomic_helper_update_legacy_modeset_state().
1159d0d1aee5SDaniel Vetter  *
1160d0d1aee5SDaniel Vetter  * 	The second issue is that the DPMS state is only well-defined when the
1161d0d1aee5SDaniel Vetter  * 	connector is connected to a CRTC. In atomic the DRM core enforces that
1162d0d1aee5SDaniel Vetter  * 	"ACTIVE" is off in such a case, no such checks exists for "DPMS".
1163d0d1aee5SDaniel Vetter  *
1164d0d1aee5SDaniel Vetter  * 	Finally, when enabling an output using the legacy SETCONFIG ioctl then
1165d0d1aee5SDaniel Vetter  * 	"DPMS" is forced to ON. But see above, that might not be reflected in
1166d0d1aee5SDaniel Vetter  * 	the software value on legacy drivers.
1167d0d1aee5SDaniel Vetter  *
1168d0d1aee5SDaniel Vetter  * 	Summarizing: Only set "DPMS" when the connector is known to be enabled,
1169d0d1aee5SDaniel Vetter  * 	assume that a successful SETCONFIG call also sets "DPMS" to on, and
1170d0d1aee5SDaniel Vetter  * 	never read back the value of "DPMS" because it can be incorrect.
11714ada6f22SDaniel Vetter  * PATH:
11724ada6f22SDaniel Vetter  * 	Connector path property to identify how this sink is physically
11734ada6f22SDaniel Vetter  * 	connected. Used by DP MST. This should be set by calling
117497e14fbeSDaniel Vetter  * 	drm_connector_set_path_property(), in the case of DP MST with the
11754ada6f22SDaniel Vetter  * 	path property the MST manager created. Userspace cannot change this
11764ada6f22SDaniel Vetter  * 	property.
11774ada6f22SDaniel Vetter  * TILE:
11784ada6f22SDaniel Vetter  * 	Connector tile group property to indicate how a set of DRM connector
11794ada6f22SDaniel Vetter  * 	compose together into one logical screen. This is used by both high-res
11804ada6f22SDaniel Vetter  * 	external screens (often only using a single cable, but exposing multiple
11814ada6f22SDaniel Vetter  * 	DP MST sinks), or high-res integrated panels (like dual-link DSI) which
11824ada6f22SDaniel Vetter  * 	are not gen-locked. Note that for tiled panels which are genlocked, like
11834ada6f22SDaniel Vetter  * 	dual-link LVDS or dual-link DSI, the driver should try to not expose the
118484e543bcSAntonio Borneo  * 	tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers
118597e14fbeSDaniel Vetter  * 	should update this value using drm_connector_set_tile_property().
11864ada6f22SDaniel Vetter  * 	Userspace cannot change this property.
118740ee6fbeSManasi Navare  * link-status:
1188716719a3SSean Paul  *      Connector link-status property to indicate the status of link. The
1189716719a3SSean Paul  *      default value of link-status is "GOOD". If something fails during or
1190716719a3SSean Paul  *      after modeset, the kernel driver may set this to "BAD" and issue a
1191716719a3SSean Paul  *      hotplug uevent. Drivers should update this value using
119297e14fbeSDaniel Vetter  *      drm_connector_set_link_status_property().
1193a66da873SSimon Ser  *
1194a66da873SSimon Ser  *      When user-space receives the hotplug uevent and detects a "BAD"
1195a66da873SSimon Ser  *      link-status, the sink doesn't receive pixels anymore (e.g. the screen
1196a66da873SSimon Ser  *      becomes completely black). The list of available modes may have
1197a66da873SSimon Ser  *      changed. User-space is expected to pick a new mode if the current one
1198a66da873SSimon Ser  *      has disappeared and perform a new modeset with link-status set to
1199a66da873SSimon Ser  *      "GOOD" to re-enable the connector.
1200a66da873SSimon Ser  *
1201a66da873SSimon Ser  *      If multiple connectors share the same CRTC and one of them gets a "BAD"
1202a66da873SSimon Ser  *      link-status, the other are unaffected (ie. the sinks still continue to
1203a66da873SSimon Ser  *      receive pixels).
1204a66da873SSimon Ser  *
1205a66da873SSimon Ser  *      When user-space performs an atomic commit on a connector with a "BAD"
1206a66da873SSimon Ser  *      link-status without resetting the property to "GOOD", the sink may
1207a66da873SSimon Ser  *      still not receive pixels. When user-space performs an atomic commit
1208a66da873SSimon Ser  *      which resets the link-status property to "GOOD" without the
1209a66da873SSimon Ser  *      ALLOW_MODESET flag set, it might fail because a modeset is required.
1210a66da873SSimon Ser  *
1211a66da873SSimon Ser  *      User-space can only change link-status to "GOOD", changing it to "BAD"
1212a66da873SSimon Ser  *      is a no-op.
1213a66da873SSimon Ser  *
1214a66da873SSimon Ser  *      For backwards compatibility with non-atomic userspace the kernel
1215a66da873SSimon Ser  *      tries to automatically set the link-status back to "GOOD" in the
1216a66da873SSimon Ser  *      SETCRTC IOCTL. This might fail if the mode is no longer valid, similar
1217a66da873SSimon Ser  *      to how it might fail if a different screen has been connected in the
1218a66da873SSimon Ser  *      interim.
121966660d4cSDave Airlie  * non_desktop:
122066660d4cSDave Airlie  * 	Indicates the output should be ignored for purposes of displaying a
122166660d4cSDave Airlie  * 	standard desktop environment or console. This is most likely because
122266660d4cSDave Airlie  * 	the output device is not rectilinear.
122324557865SSean Paul  * Content Protection:
122424557865SSean Paul  *	This property is used by userspace to request the kernel protect future
122524557865SSean Paul  *	content communicated over the link. When requested, kernel will apply
122624557865SSean Paul  *	the appropriate means of protection (most often HDCP), and use the
122724557865SSean Paul  *	property to tell userspace the protection is active.
122824557865SSean Paul  *
122924557865SSean Paul  *	Drivers can set this up by calling
123024557865SSean Paul  *	drm_connector_attach_content_protection_property() on initialization.
123124557865SSean Paul  *
123224557865SSean Paul  *	The value of this property can be one of the following:
123324557865SSean Paul  *
1234bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
123524557865SSean Paul  *		The link is not protected, content is transmitted in the clear.
1236bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
123724557865SSean Paul  *		Userspace has requested content protection, but the link is not
123824557865SSean Paul  *		currently protected. When in this state, kernel should enable
123924557865SSean Paul  *		Content Protection as soon as possible.
1240bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
124124557865SSean Paul  *		Userspace has requested content protection, and the link is
124224557865SSean Paul  *		protected. Only the driver can set the property to this value.
124324557865SSean Paul  *		If userspace attempts to set to ENABLED, kernel will return
124424557865SSean Paul  *		-EINVAL.
124524557865SSean Paul  *
124624557865SSean Paul  *	A few guidelines:
124724557865SSean Paul  *
124824557865SSean Paul  *	- DESIRED state should be preserved until userspace de-asserts it by
124924557865SSean Paul  *	  setting the property to UNDESIRED. This means ENABLED should only
125024557865SSean Paul  *	  transition to UNDESIRED when the user explicitly requests it.
125124557865SSean Paul  *	- If the state is DESIRED, kernel should attempt to re-authenticate the
125224557865SSean Paul  *	  link whenever possible. This includes across disable/enable, dpms,
125324557865SSean Paul  *	  hotplug, downstream device changes, link status failures, etc..
1254bb5a45d4SRamalingam C  *	- Kernel sends uevent with the connector id and property id through
1255bb5a45d4SRamalingam C  *	  @drm_hdcp_update_content_protection, upon below kernel triggered
1256bb5a45d4SRamalingam C  *	  scenarios:
125712db36bcSSean Paul  *
125812db36bcSSean Paul  *		- DESIRED -> ENABLED (authentication success)
125912db36bcSSean Paul  *		- ENABLED -> DESIRED (termination of authentication)
1260bb5a45d4SRamalingam C  *	- Please note no uevents for userspace triggered property state changes,
1261bb5a45d4SRamalingam C  *	  which can't fail such as
126212db36bcSSean Paul  *
126312db36bcSSean Paul  *		- DESIRED/ENABLED -> UNDESIRED
126412db36bcSSean Paul  *		- UNDESIRED -> DESIRED
1265bb5a45d4SRamalingam C  *	- Userspace is responsible for polling the property or listen to uevents
1266bb5a45d4SRamalingam C  *	  to determine when the value transitions from ENABLED to DESIRED.
1267bb5a45d4SRamalingam C  *	  This signifies the link is no longer protected and userspace should
1268bb5a45d4SRamalingam C  *	  take appropriate action (whatever that might be).
12694ada6f22SDaniel Vetter  *
12707672dbbaSRamalingam C  * HDCP Content Type:
12717672dbbaSRamalingam C  *	This Enum property is used by the userspace to declare the content type
12727672dbbaSRamalingam C  *	of the display stream, to kernel. Here display stream stands for any
12737672dbbaSRamalingam C  *	display content that userspace intended to display through HDCP
12747672dbbaSRamalingam C  *	encryption.
12757672dbbaSRamalingam C  *
12767672dbbaSRamalingam C  *	Content Type of a stream is decided by the owner of the stream, as
12777672dbbaSRamalingam C  *	"HDCP Type0" or "HDCP Type1".
12787672dbbaSRamalingam C  *
12797672dbbaSRamalingam C  *	The value of the property can be one of the below:
12807672dbbaSRamalingam C  *	  - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0
12817672dbbaSRamalingam C  *	  - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1
12827672dbbaSRamalingam C  *
12837672dbbaSRamalingam C  *	When kernel starts the HDCP authentication (see "Content Protection"
12847672dbbaSRamalingam C  *	for details), it uses the content type in "HDCP Content Type"
12857672dbbaSRamalingam C  *	for performing the HDCP authentication with the display sink.
12867672dbbaSRamalingam C  *
12877672dbbaSRamalingam C  *	Please note in HDCP spec versions, a link can be authenticated with
12887672dbbaSRamalingam C  *	HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be
12897672dbbaSRamalingam C  *	authenticated with HDCP1.4 only for Content Type 0(though it is implicit
12907672dbbaSRamalingam C  *	in nature. As there is no reference for Content Type in HDCP1.4).
12917672dbbaSRamalingam C  *
12927672dbbaSRamalingam C  *	HDCP2.2 authentication protocol itself takes the "Content Type" as a
12937672dbbaSRamalingam C  *	parameter, which is a input for the DP HDCP2.2 encryption algo.
12947672dbbaSRamalingam C  *
12957672dbbaSRamalingam C  *	In case of Type 0 content protection request, kernel driver can choose
12967672dbbaSRamalingam C  *	either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for
12977672dbbaSRamalingam C  *	"HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send
12987672dbbaSRamalingam C  *	that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).
12997672dbbaSRamalingam C  *	But if the content is classified as "HDCP Type 1", above mentioned
13007672dbbaSRamalingam C  *	HDCP 2.2 repeater wont send the content to the HDCP sink as it can't
13017672dbbaSRamalingam C  *	authenticate the HDCP1.4 capable sink for "HDCP Type 1".
13027672dbbaSRamalingam C  *
13037672dbbaSRamalingam C  *	Please note userspace can be ignorant of the HDCP versions used by the
13047672dbbaSRamalingam C  *	kernel driver to achieve the "HDCP Content Type".
13057672dbbaSRamalingam C  *
13067672dbbaSRamalingam C  *	At current scenario, classifying a content as Type 1 ensures that the
13077672dbbaSRamalingam C  *	content will be displayed only through the HDCP2.2 encrypted link.
13087672dbbaSRamalingam C  *
13097672dbbaSRamalingam C  *	Note that the HDCP Content Type property is introduced at HDCP 2.2, and
13107672dbbaSRamalingam C  *	defaults to type 0. It is only exposed by drivers supporting HDCP 2.2
13117672dbbaSRamalingam C  *	(hence supporting Type 0 and Type 1). Based on how next versions of
13127672dbbaSRamalingam C  *	HDCP specs are defined content Type could be used for higher versions
13137672dbbaSRamalingam C  *	too.
13147672dbbaSRamalingam C  *
13157672dbbaSRamalingam C  *	If content type is changed when "Content Protection" is not UNDESIRED,
13167672dbbaSRamalingam C  *	then kernel will disable the HDCP and re-enable with new type in the
13177672dbbaSRamalingam C  *	same atomic commit. And when "Content Protection" is ENABLED, it means
13187672dbbaSRamalingam C  *	that link is HDCP authenticated and encrypted, for the transmission of
13197672dbbaSRamalingam C  *	the Type of stream mentioned at "HDCP Content Type".
13207672dbbaSRamalingam C  *
1321a09db883SUma Shankar  * HDR_OUTPUT_METADATA:
1322a09db883SUma Shankar  *	Connector property to enable userspace to send HDR Metadata to
1323a09db883SUma Shankar  *	driver. This metadata is based on the composition and blending
1324a09db883SUma Shankar  *	policies decided by user, taking into account the hardware and
1325a09db883SUma Shankar  *	sink capabilities. The driver gets this metadata and creates a
1326a09db883SUma Shankar  *	Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,
1327a09db883SUma Shankar  *	SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then
1328a09db883SUma Shankar  *	sent to sink. This notifies the sink of the upcoming frame's Color
1329a09db883SUma Shankar  *	Encoding and Luminance parameters.
1330a09db883SUma Shankar  *
1331a09db883SUma Shankar  *	Userspace first need to detect the HDR capabilities of sink by
1332a09db883SUma Shankar  *	reading and parsing the EDID. Details of HDR metadata for HDMI
1333a09db883SUma Shankar  *	are added in CTA 861.G spec. For DP , its defined in VESA DP
1334a09db883SUma Shankar  *	Standard v1.4. It needs to then get the metadata information
1335a09db883SUma Shankar  *	of the video/game/app content which are encoded in HDR (basically
1336a09db883SUma Shankar  *	using HDR transfer functions). With this information it needs to
1337a09db883SUma Shankar  *	decide on a blending policy and compose the relevant
1338a09db883SUma Shankar  *	layers/overlays into a common format. Once this blending is done,
1339a09db883SUma Shankar  *	userspace will be aware of the metadata of the composed frame to
1340a09db883SUma Shankar  *	be send to sink. It then uses this property to communicate this
1341a09db883SUma Shankar  *	metadata to driver which then make a Infoframe packet and sends
1342a09db883SUma Shankar  *	to sink based on the type of encoder connected.
1343a09db883SUma Shankar  *
1344a09db883SUma Shankar  *	Userspace will be responsible to do Tone mapping operation in case:
1345a09db883SUma Shankar  *		- Some layers are HDR and others are SDR
1346a09db883SUma Shankar  *		- HDR layers luminance is not same as sink
13479f9b2559SSean Paul  *
1348a09db883SUma Shankar  *	It will even need to do colorspace conversion and get all layers
1349a09db883SUma Shankar  *	to one common colorspace for blending. It can use either GL, Media
135084e543bcSAntonio Borneo  *	or display engine to get this done based on the capabilities of the
1351a09db883SUma Shankar  *	associated hardware.
1352a09db883SUma Shankar  *
1353a09db883SUma Shankar  *	Driver expects metadata to be put in &struct hdr_output_metadata
1354a09db883SUma Shankar  *	structure from userspace. This is received as blob and stored in
1355a09db883SUma Shankar  *	&drm_connector_state.hdr_output_metadata. It parses EDID and saves the
1356a09db883SUma Shankar  *	sink metadata in &struct hdr_sink_metadata, as
1357a09db883SUma Shankar  *	&drm_connector.hdr_sink_metadata.  Driver uses
1358a09db883SUma Shankar  *	drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,
1359a09db883SUma Shankar  *	hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of
1360a09db883SUma Shankar  *	HDMI encoder.
1361a09db883SUma Shankar  *
136247e22ff1SRadhakrishna Sripada  * max bpc:
136347e22ff1SRadhakrishna Sripada  *	This range property is used by userspace to limit the bit depth. When
136447e22ff1SRadhakrishna Sripada  *	used the driver would limit the bpc in accordance with the valid range
136547e22ff1SRadhakrishna Sripada  *	supported by the hardware and sink. Drivers to use the function
136647e22ff1SRadhakrishna Sripada  *	drm_connector_attach_max_bpc_property() to create and attach the
136747e22ff1SRadhakrishna Sripada  *	property to the connector during initialization.
136847e22ff1SRadhakrishna Sripada  *
13694ada6f22SDaniel Vetter  * Connectors also have one standardized atomic property:
13704ada6f22SDaniel Vetter  *
13714ada6f22SDaniel Vetter  * CRTC_ID:
13724ada6f22SDaniel Vetter  * 	Mode object ID of the &drm_crtc this connector should be connected to.
13738d70f395SHans de Goede  *
13748d70f395SHans de Goede  * Connectors for LCD panels may also have one standardized property:
13758d70f395SHans de Goede  *
13768d70f395SHans de Goede  * panel orientation:
13778d70f395SHans de Goede  *	On some devices the LCD panel is mounted in the casing in such a way
13788d70f395SHans de Goede  *	that the up/top side of the panel does not match with the top side of
13798d70f395SHans de Goede  *	the device. Userspace can use this property to check for this.
13808d70f395SHans de Goede  *	Note that input coordinates from touchscreens (input devices with
13818d70f395SHans de Goede  *	INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
13828d70f395SHans de Goede  *	coordinates, so if userspace rotates the picture to adjust for
13838d70f395SHans de Goede  *	the orientation it must also apply the same transformation to the
1384bbeba09fSDaniel Vetter  *	touchscreen input coordinates. This property is initialized by calling
138569654c63SDerek Basehore  *	drm_connector_set_panel_orientation() or
138669654c63SDerek Basehore  *	drm_connector_set_panel_orientation_with_quirk()
1387bbeba09fSDaniel Vetter  *
1388bbeba09fSDaniel Vetter  * scaling mode:
1389bbeba09fSDaniel Vetter  *	This property defines how a non-native mode is upscaled to the native
1390bbeba09fSDaniel Vetter  *	mode of an LCD panel:
1391bbeba09fSDaniel Vetter  *
1392bbeba09fSDaniel Vetter  *	None:
1393bbeba09fSDaniel Vetter  *		No upscaling happens, scaling is left to the panel. Not all
1394bbeba09fSDaniel Vetter  *		drivers expose this mode.
1395bbeba09fSDaniel Vetter  *	Full:
1396bbeba09fSDaniel Vetter  *		The output is upscaled to the full resolution of the panel,
1397bbeba09fSDaniel Vetter  *		ignoring the aspect ratio.
1398bbeba09fSDaniel Vetter  *	Center:
1399bbeba09fSDaniel Vetter  *		No upscaling happens, the output is centered within the native
1400bbeba09fSDaniel Vetter  *		resolution the panel.
1401bbeba09fSDaniel Vetter  *	Full aspect:
1402bbeba09fSDaniel Vetter  *		The output is upscaled to maximize either the width or height
1403bbeba09fSDaniel Vetter  *		while retaining the aspect ratio.
1404bbeba09fSDaniel Vetter  *
1405bbeba09fSDaniel Vetter  *	This property should be set up by calling
1406bbeba09fSDaniel Vetter  *	drm_connector_attach_scaling_mode_property(). Note that drivers
1407bbeba09fSDaniel Vetter  *	can also expose this property to external outputs, in which case they
1408bbeba09fSDaniel Vetter  *	must support "None", which should be the default (since external screens
1409bbeba09fSDaniel Vetter  *	have a built-in scaler).
1410e5b92773SOleg Vasilev  *
1411e5b92773SOleg Vasilev  * subconnector:
1412e5b92773SOleg Vasilev  *	This property is used by DVI-I, TVout and DisplayPort to indicate different
1413e5b92773SOleg Vasilev  *	connector subtypes. Enum values more or less match with those from main
1414e5b92773SOleg Vasilev  *	connector types.
1415e5b92773SOleg Vasilev  *	For DVI-I and TVout there is also a matching property "select subconnector"
1416e5b92773SOleg Vasilev  *	allowing to switch between signal types.
1417e5b92773SOleg Vasilev  *	DP subconnector corresponds to a downstream port.
1418107fe904SRajat Jain  *
1419107fe904SRajat Jain  * privacy-screen sw-state, privacy-screen hw-state:
1420107fe904SRajat Jain  *	These 2 optional properties can be used to query the state of the
1421107fe904SRajat Jain  *	electronic privacy screen that is available on some displays; and in
1422107fe904SRajat Jain  *	some cases also control the state. If a driver implements these
1423107fe904SRajat Jain  *	properties then both properties must be present.
1424107fe904SRajat Jain  *
1425107fe904SRajat Jain  *	"privacy-screen hw-state" is read-only and reflects the actual state
1426107fe904SRajat Jain  *	of the privacy-screen, possible values: "Enabled", "Disabled,
1427107fe904SRajat Jain  *	"Enabled-locked", "Disabled-locked". The locked states indicate
1428107fe904SRajat Jain  *	that the state cannot be changed through the DRM API. E.g. there
1429107fe904SRajat Jain  *	might be devices where the firmware-setup options, or a hardware
1430107fe904SRajat Jain  *	slider-switch, offer always on / off modes.
1431107fe904SRajat Jain  *
1432107fe904SRajat Jain  *	"privacy-screen sw-state" can be set to change the privacy-screen state
1433107fe904SRajat Jain  *	when not locked. In this case the driver must update the hw-state
1434107fe904SRajat Jain  *	property to reflect the new state on completion of the commit of the
1435107fe904SRajat Jain  *	sw-state property. Setting the sw-state property when the hw-state is
1436107fe904SRajat Jain  *	locked must be interpreted by the driver as a request to change the
1437107fe904SRajat Jain  *	state to the set state when the hw-state becomes unlocked. E.g. if
1438107fe904SRajat Jain  *	"privacy-screen hw-state" is "Enabled-locked" and the sw-state
1439107fe904SRajat Jain  *	gets set to "Disabled" followed by the user unlocking the state by
1440107fe904SRajat Jain  *	changing the slider-switch position, then the driver must set the
1441107fe904SRajat Jain  *	state to "Disabled" upon receiving the unlock event.
1442107fe904SRajat Jain  *
1443107fe904SRajat Jain  *	In some cases the privacy-screen's actual state might change outside of
1444107fe904SRajat Jain  *	control of the DRM code. E.g. there might be a firmware handled hotkey
1445107fe904SRajat Jain  *	which toggles the actual state, or the actual state might be changed
1446107fe904SRajat Jain  *	through another userspace API such as writing /proc/acpi/ibm/lcdshadow.
1447107fe904SRajat Jain  *	In this case the driver must update both the hw-state and the sw-state
1448107fe904SRajat Jain  *	to reflect the new value, overwriting any pending state requests in the
1449107fe904SRajat Jain  *	sw-state. Any pending sw-state requests are thus discarded.
1450107fe904SRajat Jain  *
1451107fe904SRajat Jain  *	Note that the ability for the state to change outside of control of
1452107fe904SRajat Jain  *	the DRM master process means that userspace must not cache the value
1453107fe904SRajat Jain  *	of the sw-state. Caching the sw-state value and including it in later
1454107fe904SRajat Jain  *	atomic commits may lead to overriding a state change done through e.g.
1455107fe904SRajat Jain  *	a firmware handled hotkey. Therefor userspace must not include the
1456107fe904SRajat Jain  *	privacy-screen sw-state in an atomic commit unless it wants to change
1457107fe904SRajat Jain  *	its value.
1458409f07d3SSimon Ser  *
1459409f07d3SSimon Ser  * left margin, right margin, top margin, bottom margin:
1460409f07d3SSimon Ser  *	Add margins to the connector's viewport. This is typically used to
14613cf15dc2SSimon Ser  *	mitigate overscan on TVs.
1462409f07d3SSimon Ser  *
1463409f07d3SSimon Ser  *	The value is the size in pixels of the black border which will be
1464409f07d3SSimon Ser  *	added. The attached CRTC's content will be scaled to fill the whole
1465409f07d3SSimon Ser  *	area inside the margin.
1466409f07d3SSimon Ser  *
1467409f07d3SSimon Ser  *	The margins configuration might be sent to the sink, e.g. via HDMI AVI
1468409f07d3SSimon Ser  *	InfoFrames.
1469409f07d3SSimon Ser  *
1470409f07d3SSimon Ser  *	Drivers can set up these properties by calling
1471409f07d3SSimon Ser  *	drm_mode_create_tv_margin_properties().
14724ada6f22SDaniel Vetter  */
14734ada6f22SDaniel Vetter 
147452217195SDaniel Vetter int drm_connector_create_standard_properties(struct drm_device *dev)
147552217195SDaniel Vetter {
147652217195SDaniel Vetter 	struct drm_property *prop;
147752217195SDaniel Vetter 
147852217195SDaniel Vetter 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
147952217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
148052217195SDaniel Vetter 				   "EDID", 0);
148152217195SDaniel Vetter 	if (!prop)
148252217195SDaniel Vetter 		return -ENOMEM;
148352217195SDaniel Vetter 	dev->mode_config.edid_property = prop;
148452217195SDaniel Vetter 
148552217195SDaniel Vetter 	prop = drm_property_create_enum(dev, 0,
148652217195SDaniel Vetter 				   "DPMS", drm_dpms_enum_list,
148752217195SDaniel Vetter 				   ARRAY_SIZE(drm_dpms_enum_list));
148852217195SDaniel Vetter 	if (!prop)
148952217195SDaniel Vetter 		return -ENOMEM;
149052217195SDaniel Vetter 	dev->mode_config.dpms_property = prop;
149152217195SDaniel Vetter 
149252217195SDaniel Vetter 	prop = drm_property_create(dev,
149352217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
149452217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
149552217195SDaniel Vetter 				   "PATH", 0);
149652217195SDaniel Vetter 	if (!prop)
149752217195SDaniel Vetter 		return -ENOMEM;
149852217195SDaniel Vetter 	dev->mode_config.path_property = prop;
149952217195SDaniel Vetter 
150052217195SDaniel Vetter 	prop = drm_property_create(dev,
150152217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
150252217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
150352217195SDaniel Vetter 				   "TILE", 0);
150452217195SDaniel Vetter 	if (!prop)
150552217195SDaniel Vetter 		return -ENOMEM;
150652217195SDaniel Vetter 	dev->mode_config.tile_property = prop;
150752217195SDaniel Vetter 
150840ee6fbeSManasi Navare 	prop = drm_property_create_enum(dev, 0, "link-status",
150940ee6fbeSManasi Navare 					drm_link_status_enum_list,
151040ee6fbeSManasi Navare 					ARRAY_SIZE(drm_link_status_enum_list));
151140ee6fbeSManasi Navare 	if (!prop)
151240ee6fbeSManasi Navare 		return -ENOMEM;
151340ee6fbeSManasi Navare 	dev->mode_config.link_status_property = prop;
151440ee6fbeSManasi Navare 
151566660d4cSDave Airlie 	prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
151666660d4cSDave Airlie 	if (!prop)
151766660d4cSDave Airlie 		return -ENOMEM;
151866660d4cSDave Airlie 	dev->mode_config.non_desktop_property = prop;
151966660d4cSDave Airlie 
1520fbb5d035SUma Shankar 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
1521fbb5d035SUma Shankar 				   "HDR_OUTPUT_METADATA", 0);
1522fbb5d035SUma Shankar 	if (!prop)
1523fbb5d035SUma Shankar 		return -ENOMEM;
1524fbb5d035SUma Shankar 	dev->mode_config.hdr_output_metadata_property = prop;
1525fbb5d035SUma Shankar 
152652217195SDaniel Vetter 	return 0;
152752217195SDaniel Vetter }
152852217195SDaniel Vetter 
152952217195SDaniel Vetter /**
153052217195SDaniel Vetter  * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
153152217195SDaniel Vetter  * @dev: DRM device
153252217195SDaniel Vetter  *
153352217195SDaniel Vetter  * Called by a driver the first time a DVI-I connector is made.
1534f85d9e59SRandy Dunlap  *
1535f85d9e59SRandy Dunlap  * Returns: %0
153652217195SDaniel Vetter  */
153752217195SDaniel Vetter int drm_mode_create_dvi_i_properties(struct drm_device *dev)
153852217195SDaniel Vetter {
153952217195SDaniel Vetter 	struct drm_property *dvi_i_selector;
154052217195SDaniel Vetter 	struct drm_property *dvi_i_subconnector;
154152217195SDaniel Vetter 
154252217195SDaniel Vetter 	if (dev->mode_config.dvi_i_select_subconnector_property)
154352217195SDaniel Vetter 		return 0;
154452217195SDaniel Vetter 
154552217195SDaniel Vetter 	dvi_i_selector =
154652217195SDaniel Vetter 		drm_property_create_enum(dev, 0,
154752217195SDaniel Vetter 				    "select subconnector",
154852217195SDaniel Vetter 				    drm_dvi_i_select_enum_list,
154952217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_select_enum_list));
155052217195SDaniel Vetter 	dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
155152217195SDaniel Vetter 
155252217195SDaniel Vetter 	dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
155352217195SDaniel Vetter 				    "subconnector",
155452217195SDaniel Vetter 				    drm_dvi_i_subconnector_enum_list,
155552217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
155652217195SDaniel Vetter 	dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
155752217195SDaniel Vetter 
155852217195SDaniel Vetter 	return 0;
155952217195SDaniel Vetter }
156052217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
156152217195SDaniel Vetter 
156252217195SDaniel Vetter /**
1563e5b92773SOleg Vasilev  * drm_connector_attach_dp_subconnector_property - create subconnector property for DP
1564e5b92773SOleg Vasilev  * @connector: drm_connector to attach property
1565e5b92773SOleg Vasilev  *
1566e5b92773SOleg Vasilev  * Called by a driver when DP connector is created.
1567e5b92773SOleg Vasilev  */
1568e5b92773SOleg Vasilev void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector)
1569e5b92773SOleg Vasilev {
1570e5b92773SOleg Vasilev 	struct drm_mode_config *mode_config = &connector->dev->mode_config;
1571e5b92773SOleg Vasilev 
1572e5b92773SOleg Vasilev 	if (!mode_config->dp_subconnector_property)
1573e5b92773SOleg Vasilev 		mode_config->dp_subconnector_property =
1574e5b92773SOleg Vasilev 			drm_property_create_enum(connector->dev,
1575e5b92773SOleg Vasilev 				DRM_MODE_PROP_IMMUTABLE,
1576e5b92773SOleg Vasilev 				"subconnector",
1577e5b92773SOleg Vasilev 				drm_dp_subconnector_enum_list,
1578e5b92773SOleg Vasilev 				ARRAY_SIZE(drm_dp_subconnector_enum_list));
1579e5b92773SOleg Vasilev 
1580e5b92773SOleg Vasilev 	drm_object_attach_property(&connector->base,
1581e5b92773SOleg Vasilev 				   mode_config->dp_subconnector_property,
1582e5b92773SOleg Vasilev 				   DRM_MODE_SUBCONNECTOR_Unknown);
1583e5b92773SOleg Vasilev }
1584e5b92773SOleg Vasilev EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property);
1585e5b92773SOleg Vasilev 
1586e5b92773SOleg Vasilev /**
158750525c33SStanislav Lisovskiy  * DOC: HDMI connector properties
158850525c33SStanislav Lisovskiy  *
158950525c33SStanislav Lisovskiy  * content type (HDMI specific):
159050525c33SStanislav Lisovskiy  *	Indicates content type setting to be used in HDMI infoframes to indicate
15911e55a53aSMatt Roper  *	content type for the external device, so that it adjusts its display
159250525c33SStanislav Lisovskiy  *	settings accordingly.
159350525c33SStanislav Lisovskiy  *
159450525c33SStanislav Lisovskiy  *	The value of this property can be one of the following:
159550525c33SStanislav Lisovskiy  *
159650525c33SStanislav Lisovskiy  *	No Data:
159750525c33SStanislav Lisovskiy  *		Content type is unknown
159850525c33SStanislav Lisovskiy  *	Graphics:
159950525c33SStanislav Lisovskiy  *		Content type is graphics
160050525c33SStanislav Lisovskiy  *	Photo:
160150525c33SStanislav Lisovskiy  *		Content type is photo
160250525c33SStanislav Lisovskiy  *	Cinema:
160350525c33SStanislav Lisovskiy  *		Content type is cinema
160450525c33SStanislav Lisovskiy  *	Game:
160550525c33SStanislav Lisovskiy  *		Content type is game
160650525c33SStanislav Lisovskiy  *
1607a0a33067SSimon Ser  *	The meaning of each content type is defined in CTA-861-G table 15.
1608a0a33067SSimon Ser  *
160950525c33SStanislav Lisovskiy  *	Drivers can set up this property by calling
161050525c33SStanislav Lisovskiy  *	drm_connector_attach_content_type_property(). Decoding to
1611ba609631SDaniel Vetter  *	infoframe values is done through drm_hdmi_avi_infoframe_content_type().
161250525c33SStanislav Lisovskiy  */
161350525c33SStanislav Lisovskiy 
16147d63cd85SMaxime Ripard /*
16157d63cd85SMaxime Ripard  * TODO: Document the properties:
16167d63cd85SMaxime Ripard  *   - brightness
16177d63cd85SMaxime Ripard  *   - contrast
16187d63cd85SMaxime Ripard  *   - flicker reduction
16197d63cd85SMaxime Ripard  *   - hue
16207d63cd85SMaxime Ripard  *   - mode
16217d63cd85SMaxime Ripard  *   - overscan
16227d63cd85SMaxime Ripard  *   - saturation
16237d63cd85SMaxime Ripard  *   - select subconnector
16247d63cd85SMaxime Ripard  */
16257d63cd85SMaxime Ripard /**
16267d63cd85SMaxime Ripard  * DOC: Analog TV Connector Properties
16277d63cd85SMaxime Ripard  *
16287d63cd85SMaxime Ripard  * TV Mode:
16297d63cd85SMaxime Ripard  *	Indicates the TV Mode used on an analog TV connector. The value
16307d63cd85SMaxime Ripard  *	of this property can be one of the following:
16317d63cd85SMaxime Ripard  *
16327d63cd85SMaxime Ripard  *	NTSC:
16337d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
16347d63cd85SMaxime Ripard  *		the NTSC Color Encoding.
16357d63cd85SMaxime Ripard  *
16367d63cd85SMaxime Ripard  *	NTSC-443:
16377d63cd85SMaxime Ripard  *
16387d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
16397d63cd85SMaxime Ripard  *		the NTSC Color Encoding, but with a color subcarrier
16407d63cd85SMaxime Ripard  *		frequency of 4.43MHz
16417d63cd85SMaxime Ripard  *
16427d63cd85SMaxime Ripard  *	NTSC-J:
16437d63cd85SMaxime Ripard  *
16447d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
16457d63cd85SMaxime Ripard  *		the NTSC Color Encoding, but with a black level equal to
16467d63cd85SMaxime Ripard  *		the blanking level.
16477d63cd85SMaxime Ripard  *
16487d63cd85SMaxime Ripard  *	PAL:
16497d63cd85SMaxime Ripard  *
16507d63cd85SMaxime Ripard  *		TV Mode is CCIR System B (aka 625-lines) together with
16517d63cd85SMaxime Ripard  *		the PAL Color Encoding.
16527d63cd85SMaxime Ripard  *
16537d63cd85SMaxime Ripard  *	PAL-M:
16547d63cd85SMaxime Ripard  *
16557d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
16567d63cd85SMaxime Ripard  *		the PAL Color Encoding.
16577d63cd85SMaxime Ripard  *
16587d63cd85SMaxime Ripard  *	PAL-N:
16597d63cd85SMaxime Ripard  *
16607d63cd85SMaxime Ripard  *		TV Mode is CCIR System N together with the PAL Color
16617d63cd85SMaxime Ripard  *		Encoding, a color subcarrier frequency of 3.58MHz, the
16627d63cd85SMaxime Ripard  *		SECAM color space, and narrower channels than other PAL
16637d63cd85SMaxime Ripard  *		variants.
16647d63cd85SMaxime Ripard  *
16657d63cd85SMaxime Ripard  *	SECAM:
16667d63cd85SMaxime Ripard  *
16677d63cd85SMaxime Ripard  *		TV Mode is CCIR System B (aka 625-lines) together with
16687d63cd85SMaxime Ripard  *		the SECAM Color Encoding.
16697d63cd85SMaxime Ripard  *
16707d63cd85SMaxime Ripard  *	Drivers can set up this property by calling
16717d63cd85SMaxime Ripard  *	drm_mode_create_tv_properties().
16727d63cd85SMaxime Ripard  */
16737d63cd85SMaxime Ripard 
167450525c33SStanislav Lisovskiy /**
167550525c33SStanislav Lisovskiy  * drm_connector_attach_content_type_property - attach content-type property
167650525c33SStanislav Lisovskiy  * @connector: connector to attach content type property on.
167750525c33SStanislav Lisovskiy  *
167850525c33SStanislav Lisovskiy  * Called by a driver the first time a HDMI connector is made.
1679f85d9e59SRandy Dunlap  *
1680f85d9e59SRandy Dunlap  * Returns: %0
168150525c33SStanislav Lisovskiy  */
168250525c33SStanislav Lisovskiy int drm_connector_attach_content_type_property(struct drm_connector *connector)
168350525c33SStanislav Lisovskiy {
168450525c33SStanislav Lisovskiy 	if (!drm_mode_create_content_type_property(connector->dev))
168550525c33SStanislav Lisovskiy 		drm_object_attach_property(&connector->base,
168650525c33SStanislav Lisovskiy 					   connector->dev->mode_config.content_type_property,
168750525c33SStanislav Lisovskiy 					   DRM_MODE_CONTENT_TYPE_NO_DATA);
168850525c33SStanislav Lisovskiy 	return 0;
168950525c33SStanislav Lisovskiy }
169050525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_connector_attach_content_type_property);
169150525c33SStanislav Lisovskiy 
169250525c33SStanislav Lisovskiy /**
1693e9d2871fSMauro Carvalho Chehab  * drm_connector_attach_tv_margin_properties - attach TV connector margin
1694e9d2871fSMauro Carvalho Chehab  * 	properties
16956c4f52dcSBoris Brezillon  * @connector: DRM connector
16966c4f52dcSBoris Brezillon  *
16976c4f52dcSBoris Brezillon  * Called by a driver when it needs to attach TV margin props to a connector.
16986c4f52dcSBoris Brezillon  * Typically used on SDTV and HDMI connectors.
16996c4f52dcSBoris Brezillon  */
17006c4f52dcSBoris Brezillon void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
17016c4f52dcSBoris Brezillon {
17026c4f52dcSBoris Brezillon 	struct drm_device *dev = connector->dev;
17036c4f52dcSBoris Brezillon 
17046c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
17056c4f52dcSBoris Brezillon 				   dev->mode_config.tv_left_margin_property,
17066c4f52dcSBoris Brezillon 				   0);
17076c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
17086c4f52dcSBoris Brezillon 				   dev->mode_config.tv_right_margin_property,
17096c4f52dcSBoris Brezillon 				   0);
17106c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
17116c4f52dcSBoris Brezillon 				   dev->mode_config.tv_top_margin_property,
17126c4f52dcSBoris Brezillon 				   0);
17136c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
17146c4f52dcSBoris Brezillon 				   dev->mode_config.tv_bottom_margin_property,
17156c4f52dcSBoris Brezillon 				   0);
17166c4f52dcSBoris Brezillon }
17176c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
17186c4f52dcSBoris Brezillon 
17196c4f52dcSBoris Brezillon /**
17206c4f52dcSBoris Brezillon  * drm_mode_create_tv_margin_properties - create TV connector margin properties
17216c4f52dcSBoris Brezillon  * @dev: DRM device
17226c4f52dcSBoris Brezillon  *
17236c4f52dcSBoris Brezillon  * Called by a driver's HDMI connector initialization routine, this function
17246c4f52dcSBoris Brezillon  * creates the TV margin properties for a given device. No need to call this
17256c4f52dcSBoris Brezillon  * function for an SDTV connector, it's already called from
172680ed86d4SMaxime Ripard  * drm_mode_create_tv_properties_legacy().
1727f85d9e59SRandy Dunlap  *
1728f85d9e59SRandy Dunlap  * Returns:
1729f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
17306c4f52dcSBoris Brezillon  */
17316c4f52dcSBoris Brezillon int drm_mode_create_tv_margin_properties(struct drm_device *dev)
17326c4f52dcSBoris Brezillon {
17336c4f52dcSBoris Brezillon 	if (dev->mode_config.tv_left_margin_property)
17346c4f52dcSBoris Brezillon 		return 0;
17356c4f52dcSBoris Brezillon 
17366c4f52dcSBoris Brezillon 	dev->mode_config.tv_left_margin_property =
17376c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "left margin", 0, 100);
17386c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_left_margin_property)
17396c4f52dcSBoris Brezillon 		return -ENOMEM;
17406c4f52dcSBoris Brezillon 
17416c4f52dcSBoris Brezillon 	dev->mode_config.tv_right_margin_property =
17426c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "right margin", 0, 100);
17436c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_right_margin_property)
17446c4f52dcSBoris Brezillon 		return -ENOMEM;
17456c4f52dcSBoris Brezillon 
17466c4f52dcSBoris Brezillon 	dev->mode_config.tv_top_margin_property =
17476c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "top margin", 0, 100);
17486c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_top_margin_property)
17496c4f52dcSBoris Brezillon 		return -ENOMEM;
17506c4f52dcSBoris Brezillon 
17516c4f52dcSBoris Brezillon 	dev->mode_config.tv_bottom_margin_property =
17526c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "bottom margin", 0, 100);
17536c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_bottom_margin_property)
17546c4f52dcSBoris Brezillon 		return -ENOMEM;
17556c4f52dcSBoris Brezillon 
17566c4f52dcSBoris Brezillon 	return 0;
17576c4f52dcSBoris Brezillon }
17586c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
17596c4f52dcSBoris Brezillon 
17606c4f52dcSBoris Brezillon /**
176180ed86d4SMaxime Ripard  * drm_mode_create_tv_properties_legacy - create TV specific connector properties
176252217195SDaniel Vetter  * @dev: DRM device
176352217195SDaniel Vetter  * @num_modes: number of different TV formats (modes) supported
176452217195SDaniel Vetter  * @modes: array of pointers to strings containing name of each format
176552217195SDaniel Vetter  *
176652217195SDaniel Vetter  * Called by a driver's TV initialization routine, this function creates
176752217195SDaniel Vetter  * the TV specific connector properties for a given device.  Caller is
176852217195SDaniel Vetter  * responsible for allocating a list of format names and passing them to
176952217195SDaniel Vetter  * this routine.
1770f85d9e59SRandy Dunlap  *
17717d63cd85SMaxime Ripard  * NOTE: This functions registers the deprecated "mode" connector
17727d63cd85SMaxime Ripard  * property to select the analog TV mode (ie, NTSC, PAL, etc.). New
17737d63cd85SMaxime Ripard  * drivers must use drm_mode_create_tv_properties() instead.
17747d63cd85SMaxime Ripard  *
1775f85d9e59SRandy Dunlap  * Returns:
1776f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
177752217195SDaniel Vetter  */
177880ed86d4SMaxime Ripard int drm_mode_create_tv_properties_legacy(struct drm_device *dev,
177952217195SDaniel Vetter 					 unsigned int num_modes,
178052217195SDaniel Vetter 					 const char * const modes[])
178152217195SDaniel Vetter {
178252217195SDaniel Vetter 	struct drm_property *tv_selector;
178352217195SDaniel Vetter 	struct drm_property *tv_subconnector;
178452217195SDaniel Vetter 	unsigned int i;
178552217195SDaniel Vetter 
178652217195SDaniel Vetter 	if (dev->mode_config.tv_select_subconnector_property)
178752217195SDaniel Vetter 		return 0;
178852217195SDaniel Vetter 
178952217195SDaniel Vetter 	/*
179052217195SDaniel Vetter 	 * Basic connector properties
179152217195SDaniel Vetter 	 */
179252217195SDaniel Vetter 	tv_selector = drm_property_create_enum(dev, 0,
179352217195SDaniel Vetter 					  "select subconnector",
179452217195SDaniel Vetter 					  drm_tv_select_enum_list,
179552217195SDaniel Vetter 					  ARRAY_SIZE(drm_tv_select_enum_list));
179652217195SDaniel Vetter 	if (!tv_selector)
179752217195SDaniel Vetter 		goto nomem;
179852217195SDaniel Vetter 
179952217195SDaniel Vetter 	dev->mode_config.tv_select_subconnector_property = tv_selector;
180052217195SDaniel Vetter 
180152217195SDaniel Vetter 	tv_subconnector =
180252217195SDaniel Vetter 		drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
180352217195SDaniel Vetter 				    "subconnector",
180452217195SDaniel Vetter 				    drm_tv_subconnector_enum_list,
180552217195SDaniel Vetter 				    ARRAY_SIZE(drm_tv_subconnector_enum_list));
180652217195SDaniel Vetter 	if (!tv_subconnector)
180752217195SDaniel Vetter 		goto nomem;
180852217195SDaniel Vetter 	dev->mode_config.tv_subconnector_property = tv_subconnector;
180952217195SDaniel Vetter 
181052217195SDaniel Vetter 	/*
181152217195SDaniel Vetter 	 * Other, TV specific properties: margins & TV modes.
181252217195SDaniel Vetter 	 */
18136c4f52dcSBoris Brezillon 	if (drm_mode_create_tv_margin_properties(dev))
181452217195SDaniel Vetter 		goto nomem;
181552217195SDaniel Vetter 
1816aab5aaa7SMaxime Ripard 	if (num_modes) {
18171fd4a5a3SMaxime Ripard 		dev->mode_config.legacy_tv_mode_property =
181852217195SDaniel Vetter 			drm_property_create(dev, DRM_MODE_PROP_ENUM,
181952217195SDaniel Vetter 					    "mode", num_modes);
18201fd4a5a3SMaxime Ripard 		if (!dev->mode_config.legacy_tv_mode_property)
182152217195SDaniel Vetter 			goto nomem;
182252217195SDaniel Vetter 
182352217195SDaniel Vetter 		for (i = 0; i < num_modes; i++)
18241fd4a5a3SMaxime Ripard 			drm_property_add_enum(dev->mode_config.legacy_tv_mode_property,
182552217195SDaniel Vetter 					      i, modes[i]);
1826aab5aaa7SMaxime Ripard 	}
182752217195SDaniel Vetter 
182852217195SDaniel Vetter 	dev->mode_config.tv_brightness_property =
182952217195SDaniel Vetter 		drm_property_create_range(dev, 0, "brightness", 0, 100);
183052217195SDaniel Vetter 	if (!dev->mode_config.tv_brightness_property)
183152217195SDaniel Vetter 		goto nomem;
183252217195SDaniel Vetter 
183352217195SDaniel Vetter 	dev->mode_config.tv_contrast_property =
183452217195SDaniel Vetter 		drm_property_create_range(dev, 0, "contrast", 0, 100);
183552217195SDaniel Vetter 	if (!dev->mode_config.tv_contrast_property)
183652217195SDaniel Vetter 		goto nomem;
183752217195SDaniel Vetter 
183852217195SDaniel Vetter 	dev->mode_config.tv_flicker_reduction_property =
183952217195SDaniel Vetter 		drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
184052217195SDaniel Vetter 	if (!dev->mode_config.tv_flicker_reduction_property)
184152217195SDaniel Vetter 		goto nomem;
184252217195SDaniel Vetter 
184352217195SDaniel Vetter 	dev->mode_config.tv_overscan_property =
184452217195SDaniel Vetter 		drm_property_create_range(dev, 0, "overscan", 0, 100);
184552217195SDaniel Vetter 	if (!dev->mode_config.tv_overscan_property)
184652217195SDaniel Vetter 		goto nomem;
184752217195SDaniel Vetter 
184852217195SDaniel Vetter 	dev->mode_config.tv_saturation_property =
184952217195SDaniel Vetter 		drm_property_create_range(dev, 0, "saturation", 0, 100);
185052217195SDaniel Vetter 	if (!dev->mode_config.tv_saturation_property)
185152217195SDaniel Vetter 		goto nomem;
185252217195SDaniel Vetter 
185352217195SDaniel Vetter 	dev->mode_config.tv_hue_property =
185452217195SDaniel Vetter 		drm_property_create_range(dev, 0, "hue", 0, 100);
185552217195SDaniel Vetter 	if (!dev->mode_config.tv_hue_property)
185652217195SDaniel Vetter 		goto nomem;
185752217195SDaniel Vetter 
185852217195SDaniel Vetter 	return 0;
185952217195SDaniel Vetter nomem:
186052217195SDaniel Vetter 	return -ENOMEM;
186152217195SDaniel Vetter }
186280ed86d4SMaxime Ripard EXPORT_SYMBOL(drm_mode_create_tv_properties_legacy);
186352217195SDaniel Vetter 
186452217195SDaniel Vetter /**
18657d63cd85SMaxime Ripard  * drm_mode_create_tv_properties - create TV specific connector properties
18667d63cd85SMaxime Ripard  * @dev: DRM device
18677d63cd85SMaxime Ripard  * @supported_tv_modes: Bitmask of TV modes supported (See DRM_MODE_TV_MODE_*)
186804ee2767SRandy Dunlap  *
18697d63cd85SMaxime Ripard  * Called by a driver's TV initialization routine, this function creates
18707d63cd85SMaxime Ripard  * the TV specific connector properties for a given device.
18717d63cd85SMaxime Ripard  *
18727d63cd85SMaxime Ripard  * Returns:
18737d63cd85SMaxime Ripard  * 0 on success or a negative error code on failure.
18747d63cd85SMaxime Ripard  */
18757d63cd85SMaxime Ripard int drm_mode_create_tv_properties(struct drm_device *dev,
18767d63cd85SMaxime Ripard 				  unsigned int supported_tv_modes)
18777d63cd85SMaxime Ripard {
18787d63cd85SMaxime Ripard 	struct drm_prop_enum_list tv_mode_list[DRM_MODE_TV_MODE_MAX];
18797d63cd85SMaxime Ripard 	struct drm_property *tv_mode;
18807d63cd85SMaxime Ripard 	unsigned int i, len = 0;
18817d63cd85SMaxime Ripard 
18827d63cd85SMaxime Ripard 	if (dev->mode_config.tv_mode_property)
18837d63cd85SMaxime Ripard 		return 0;
18847d63cd85SMaxime Ripard 
18857d63cd85SMaxime Ripard 	for (i = 0; i < DRM_MODE_TV_MODE_MAX; i++) {
18867d63cd85SMaxime Ripard 		if (!(supported_tv_modes & BIT(i)))
18877d63cd85SMaxime Ripard 			continue;
18887d63cd85SMaxime Ripard 
18897d63cd85SMaxime Ripard 		tv_mode_list[len].type = i;
18907d63cd85SMaxime Ripard 		tv_mode_list[len].name = drm_get_tv_mode_name(i);
18917d63cd85SMaxime Ripard 		len++;
18927d63cd85SMaxime Ripard 	}
18937d63cd85SMaxime Ripard 
18947d63cd85SMaxime Ripard 	tv_mode = drm_property_create_enum(dev, 0, "TV mode",
18957d63cd85SMaxime Ripard 					   tv_mode_list, len);
18967d63cd85SMaxime Ripard 	if (!tv_mode)
18977d63cd85SMaxime Ripard 		return -ENOMEM;
18987d63cd85SMaxime Ripard 
18997d63cd85SMaxime Ripard 	dev->mode_config.tv_mode_property = tv_mode;
19007d63cd85SMaxime Ripard 
19017d63cd85SMaxime Ripard 	return drm_mode_create_tv_properties_legacy(dev, 0, NULL);
19027d63cd85SMaxime Ripard }
19037d63cd85SMaxime Ripard EXPORT_SYMBOL(drm_mode_create_tv_properties);
19047d63cd85SMaxime Ripard 
19057d63cd85SMaxime Ripard /**
190652217195SDaniel Vetter  * drm_mode_create_scaling_mode_property - create scaling mode property
190752217195SDaniel Vetter  * @dev: DRM device
190852217195SDaniel Vetter  *
190952217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
191052217195SDaniel Vetter  * connectors.
19118f6e1e22SMaarten Lankhorst  *
19128f6e1e22SMaarten Lankhorst  * Atomic drivers should use drm_connector_attach_scaling_mode_property()
19139c2fce13SVille Syrjälä  * instead to correctly assign &drm_connector_state.scaling_mode
19148f6e1e22SMaarten Lankhorst  * in the atomic state.
1915f85d9e59SRandy Dunlap  *
1916f85d9e59SRandy Dunlap  * Returns: %0
191752217195SDaniel Vetter  */
191852217195SDaniel Vetter int drm_mode_create_scaling_mode_property(struct drm_device *dev)
191952217195SDaniel Vetter {
192052217195SDaniel Vetter 	struct drm_property *scaling_mode;
192152217195SDaniel Vetter 
192252217195SDaniel Vetter 	if (dev->mode_config.scaling_mode_property)
192352217195SDaniel Vetter 		return 0;
192452217195SDaniel Vetter 
192552217195SDaniel Vetter 	scaling_mode =
192652217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "scaling mode",
192752217195SDaniel Vetter 				drm_scaling_mode_enum_list,
192852217195SDaniel Vetter 				    ARRAY_SIZE(drm_scaling_mode_enum_list));
192952217195SDaniel Vetter 
193052217195SDaniel Vetter 	dev->mode_config.scaling_mode_property = scaling_mode;
193152217195SDaniel Vetter 
193252217195SDaniel Vetter 	return 0;
193352217195SDaniel Vetter }
193452217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
193552217195SDaniel Vetter 
193652217195SDaniel Vetter /**
1937ab7a664fSNicholas Kazlauskas  * DOC: Variable refresh properties
1938ab7a664fSNicholas Kazlauskas  *
1939ab7a664fSNicholas Kazlauskas  * Variable refresh rate capable displays can dynamically adjust their
1940ab7a664fSNicholas Kazlauskas  * refresh rate by extending the duration of their vertical front porch
1941ab7a664fSNicholas Kazlauskas  * until page flip or timeout occurs. This can reduce or remove stuttering
1942ab7a664fSNicholas Kazlauskas  * and latency in scenarios where the page flip does not align with the
1943ab7a664fSNicholas Kazlauskas  * vblank interval.
1944ab7a664fSNicholas Kazlauskas  *
1945ab7a664fSNicholas Kazlauskas  * An example scenario would be an application flipping at a constant rate
1946ab7a664fSNicholas Kazlauskas  * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
1947ab7a664fSNicholas Kazlauskas  * interval and the same contents will be displayed twice. This can be
1948ab7a664fSNicholas Kazlauskas  * observed as stuttering for content with motion.
1949ab7a664fSNicholas Kazlauskas  *
1950ab7a664fSNicholas Kazlauskas  * If variable refresh rate was active on a display that supported a
1951ab7a664fSNicholas Kazlauskas  * variable refresh range from 35Hz to 60Hz no stuttering would be observable
1952ab7a664fSNicholas Kazlauskas  * for the example scenario. The minimum supported variable refresh rate of
1953ab7a664fSNicholas Kazlauskas  * 35Hz is below the page flip frequency and the vertical front porch can
1954ab7a664fSNicholas Kazlauskas  * be extended until the page flip occurs. The vblank interval will be
1955ab7a664fSNicholas Kazlauskas  * directly aligned to the page flip rate.
1956ab7a664fSNicholas Kazlauskas  *
1957ab7a664fSNicholas Kazlauskas  * Not all userspace content is suitable for use with variable refresh rate.
1958ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may worsen
1959ab7a664fSNicholas Kazlauskas  * perceived stuttering for input sensitive applications.
1960ab7a664fSNicholas Kazlauskas  *
1961ab7a664fSNicholas Kazlauskas  * Panel brightness will also vary with vertical front porch duration. Some
1962ab7a664fSNicholas Kazlauskas  * panels may have noticeable differences in brightness between the minimum
1963ab7a664fSNicholas Kazlauskas  * vertical front porch duration and the maximum vertical front porch duration.
1964ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may produce
1965ab7a664fSNicholas Kazlauskas  * observable flickering for such panels.
1966ab7a664fSNicholas Kazlauskas  *
1967ab7a664fSNicholas Kazlauskas  * Userspace control for variable refresh rate is supported via properties
1968ab7a664fSNicholas Kazlauskas  * on the &drm_connector and &drm_crtc objects.
1969ab7a664fSNicholas Kazlauskas  *
1970ab7a664fSNicholas Kazlauskas  * "vrr_capable":
1971ab7a664fSNicholas Kazlauskas  *	Optional &drm_connector boolean property that drivers should attach
1972ab7a664fSNicholas Kazlauskas  *	with drm_connector_attach_vrr_capable_property() on connectors that
1973ab7a664fSNicholas Kazlauskas  *	could support variable refresh rates. Drivers should update the
1974ab7a664fSNicholas Kazlauskas  *	property value by calling drm_connector_set_vrr_capable_property().
1975ab7a664fSNicholas Kazlauskas  *
1976ab7a664fSNicholas Kazlauskas  *	Absence of the property should indicate absence of support.
1977ab7a664fSNicholas Kazlauskas  *
197877086014SDaniel Vetter  * "VRR_ENABLED":
1979ab7a664fSNicholas Kazlauskas  *	Default &drm_crtc boolean property that notifies the driver that the
1980ab7a664fSNicholas Kazlauskas  *	content on the CRTC is suitable for variable refresh rate presentation.
1981ab7a664fSNicholas Kazlauskas  *	The driver will take this property as a hint to enable variable
1982ab7a664fSNicholas Kazlauskas  *	refresh rate support if the receiver supports it, ie. if the
1983ab7a664fSNicholas Kazlauskas  *	"vrr_capable" property is true on the &drm_connector object. The
1984ab7a664fSNicholas Kazlauskas  *	vertical front porch duration will be extended until page-flip or
1985ab7a664fSNicholas Kazlauskas  *	timeout when enabled.
1986ab7a664fSNicholas Kazlauskas  *
1987ab7a664fSNicholas Kazlauskas  *	The minimum vertical front porch duration is defined as the vertical
1988ab7a664fSNicholas Kazlauskas  *	front porch duration for the current mode.
1989ab7a664fSNicholas Kazlauskas  *
1990ab7a664fSNicholas Kazlauskas  *	The maximum vertical front porch duration is greater than or equal to
1991ab7a664fSNicholas Kazlauskas  *	the minimum vertical front porch duration. The duration is derived
1992ab7a664fSNicholas Kazlauskas  *	from the minimum supported variable refresh rate for the connector.
1993ab7a664fSNicholas Kazlauskas  *
1994ab7a664fSNicholas Kazlauskas  *	The driver may place further restrictions within these minimum
1995ab7a664fSNicholas Kazlauskas  *	and maximum bounds.
1996ab7a664fSNicholas Kazlauskas  */
1997ab7a664fSNicholas Kazlauskas 
1998ab7a664fSNicholas Kazlauskas /**
1999ba1b0f6cSNicholas Kazlauskas  * drm_connector_attach_vrr_capable_property - creates the
2000ba1b0f6cSNicholas Kazlauskas  * vrr_capable property
2001ba1b0f6cSNicholas Kazlauskas  * @connector: connector to create the vrr_capable property on.
2002ba1b0f6cSNicholas Kazlauskas  *
2003ba1b0f6cSNicholas Kazlauskas  * This is used by atomic drivers to add support for querying
2004ba1b0f6cSNicholas Kazlauskas  * variable refresh rate capability for a connector.
2005ba1b0f6cSNicholas Kazlauskas  *
2006ba1b0f6cSNicholas Kazlauskas  * Returns:
200784e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
2008ba1b0f6cSNicholas Kazlauskas  */
2009ba1b0f6cSNicholas Kazlauskas int drm_connector_attach_vrr_capable_property(
2010ba1b0f6cSNicholas Kazlauskas 	struct drm_connector *connector)
2011ba1b0f6cSNicholas Kazlauskas {
2012ba1b0f6cSNicholas Kazlauskas 	struct drm_device *dev = connector->dev;
2013ba1b0f6cSNicholas Kazlauskas 	struct drm_property *prop;
2014ba1b0f6cSNicholas Kazlauskas 
2015ba1b0f6cSNicholas Kazlauskas 	if (!connector->vrr_capable_property) {
2016ba1b0f6cSNicholas Kazlauskas 		prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
2017ba1b0f6cSNicholas Kazlauskas 			"vrr_capable");
2018ba1b0f6cSNicholas Kazlauskas 		if (!prop)
2019ba1b0f6cSNicholas Kazlauskas 			return -ENOMEM;
2020ba1b0f6cSNicholas Kazlauskas 
2021ba1b0f6cSNicholas Kazlauskas 		connector->vrr_capable_property = prop;
2022ba1b0f6cSNicholas Kazlauskas 		drm_object_attach_property(&connector->base, prop, 0);
2023ba1b0f6cSNicholas Kazlauskas 	}
2024ba1b0f6cSNicholas Kazlauskas 
2025ba1b0f6cSNicholas Kazlauskas 	return 0;
2026ba1b0f6cSNicholas Kazlauskas }
2027ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
2028ba1b0f6cSNicholas Kazlauskas 
2029ba1b0f6cSNicholas Kazlauskas /**
20308f6e1e22SMaarten Lankhorst  * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
20318f6e1e22SMaarten Lankhorst  * @connector: connector to attach scaling mode property on.
20328f6e1e22SMaarten Lankhorst  * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
20338f6e1e22SMaarten Lankhorst  *
20348f6e1e22SMaarten Lankhorst  * This is used to add support for scaling mode to atomic drivers.
20359c2fce13SVille Syrjälä  * The scaling mode will be set to &drm_connector_state.scaling_mode
20368f6e1e22SMaarten Lankhorst  * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
20378f6e1e22SMaarten Lankhorst  *
20388f6e1e22SMaarten Lankhorst  * This is the atomic version of drm_mode_create_scaling_mode_property().
20398f6e1e22SMaarten Lankhorst  *
20408f6e1e22SMaarten Lankhorst  * Returns:
20418f6e1e22SMaarten Lankhorst  * Zero on success, negative errno on failure.
20428f6e1e22SMaarten Lankhorst  */
20438f6e1e22SMaarten Lankhorst int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
20448f6e1e22SMaarten Lankhorst 					       u32 scaling_mode_mask)
20458f6e1e22SMaarten Lankhorst {
20468f6e1e22SMaarten Lankhorst 	struct drm_device *dev = connector->dev;
20478f6e1e22SMaarten Lankhorst 	struct drm_property *scaling_mode_property;
204830e9db6dSVille Syrjälä 	int i;
20498f6e1e22SMaarten Lankhorst 	const unsigned valid_scaling_mode_mask =
20508f6e1e22SMaarten Lankhorst 		(1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
20518f6e1e22SMaarten Lankhorst 
20528f6e1e22SMaarten Lankhorst 	if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
20538f6e1e22SMaarten Lankhorst 		    scaling_mode_mask & ~valid_scaling_mode_mask))
20548f6e1e22SMaarten Lankhorst 		return -EINVAL;
20558f6e1e22SMaarten Lankhorst 
20568f6e1e22SMaarten Lankhorst 	scaling_mode_property =
20578f6e1e22SMaarten Lankhorst 		drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
20588f6e1e22SMaarten Lankhorst 				    hweight32(scaling_mode_mask));
20598f6e1e22SMaarten Lankhorst 
20608f6e1e22SMaarten Lankhorst 	if (!scaling_mode_property)
20618f6e1e22SMaarten Lankhorst 		return -ENOMEM;
20628f6e1e22SMaarten Lankhorst 
20638f6e1e22SMaarten Lankhorst 	for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
20648f6e1e22SMaarten Lankhorst 		int ret;
20658f6e1e22SMaarten Lankhorst 
20668f6e1e22SMaarten Lankhorst 		if (!(BIT(i) & scaling_mode_mask))
20678f6e1e22SMaarten Lankhorst 			continue;
20688f6e1e22SMaarten Lankhorst 
206930e9db6dSVille Syrjälä 		ret = drm_property_add_enum(scaling_mode_property,
20708f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].type,
20718f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].name);
20728f6e1e22SMaarten Lankhorst 
20738f6e1e22SMaarten Lankhorst 		if (ret) {
20748f6e1e22SMaarten Lankhorst 			drm_property_destroy(dev, scaling_mode_property);
20758f6e1e22SMaarten Lankhorst 
20768f6e1e22SMaarten Lankhorst 			return ret;
20778f6e1e22SMaarten Lankhorst 		}
20788f6e1e22SMaarten Lankhorst 	}
20798f6e1e22SMaarten Lankhorst 
20808f6e1e22SMaarten Lankhorst 	drm_object_attach_property(&connector->base,
20818f6e1e22SMaarten Lankhorst 				   scaling_mode_property, 0);
20828f6e1e22SMaarten Lankhorst 
20838f6e1e22SMaarten Lankhorst 	connector->scaling_mode_property = scaling_mode_property;
20848f6e1e22SMaarten Lankhorst 
20858f6e1e22SMaarten Lankhorst 	return 0;
20868f6e1e22SMaarten Lankhorst }
20878f6e1e22SMaarten Lankhorst EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
20888f6e1e22SMaarten Lankhorst 
20898f6e1e22SMaarten Lankhorst /**
209052217195SDaniel Vetter  * drm_mode_create_aspect_ratio_property - create aspect ratio property
209152217195SDaniel Vetter  * @dev: DRM device
209252217195SDaniel Vetter  *
209352217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
209452217195SDaniel Vetter  * connectors.
209552217195SDaniel Vetter  *
209652217195SDaniel Vetter  * Returns:
209752217195SDaniel Vetter  * Zero on success, negative errno on failure.
209852217195SDaniel Vetter  */
209952217195SDaniel Vetter int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
210052217195SDaniel Vetter {
210152217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property)
210252217195SDaniel Vetter 		return 0;
210352217195SDaniel Vetter 
210452217195SDaniel Vetter 	dev->mode_config.aspect_ratio_property =
210552217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "aspect ratio",
210652217195SDaniel Vetter 				drm_aspect_ratio_enum_list,
210752217195SDaniel Vetter 				ARRAY_SIZE(drm_aspect_ratio_enum_list));
210852217195SDaniel Vetter 
210952217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property == NULL)
211052217195SDaniel Vetter 		return -ENOMEM;
211152217195SDaniel Vetter 
211252217195SDaniel Vetter 	return 0;
211352217195SDaniel Vetter }
211452217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
211552217195SDaniel Vetter 
211652217195SDaniel Vetter /**
2117d2c6a405SUma Shankar  * DOC: standard connector properties
2118d2c6a405SUma Shankar  *
2119d2c6a405SUma Shankar  * Colorspace:
2120d2c6a405SUma Shankar  *     This property helps select a suitable colorspace based on the sink
2121d2c6a405SUma Shankar  *     capability. Modern sink devices support wider gamut like BT2020.
2122d2c6a405SUma Shankar  *     This helps switch to BT2020 mode if the BT2020 encoded video stream
2123d2c6a405SUma Shankar  *     is being played by the user, same for any other colorspace. Thereby
2124d2c6a405SUma Shankar  *     giving a good visual experience to users.
2125d2c6a405SUma Shankar  *
2126d2c6a405SUma Shankar  *     The expectation from userspace is that it should parse the EDID
2127d2c6a405SUma Shankar  *     and get supported colorspaces. Use this property and switch to the
2128d2c6a405SUma Shankar  *     one supported. Sink supported colorspaces should be retrieved by
2129d2c6a405SUma Shankar  *     userspace from EDID and driver will not explicitly expose them.
2130d2c6a405SUma Shankar  *
2131d2c6a405SUma Shankar  *     Basically the expectation from userspace is:
2132d2c6a405SUma Shankar  *      - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink
2133d2c6a405SUma Shankar  *        colorspace
2134d2c6a405SUma Shankar  *      - Set this new property to let the sink know what it
2135d2c6a405SUma Shankar  *        converted the CRTC output to.
2136d2c6a405SUma Shankar  *      - This property is just to inform sink what colorspace
2137d2c6a405SUma Shankar  *        source is trying to drive.
2138d2c6a405SUma Shankar  *
21398806cd3aSGwan-gyeong Mun  * Because between HDMI and DP have different colorspaces,
214045cf0e91SGwan-gyeong Mun  * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and
214145cf0e91SGwan-gyeong Mun  * drm_mode_create_dp_colorspace_property() is used for DP connector.
2142d2c6a405SUma Shankar  */
21438806cd3aSGwan-gyeong Mun 
21446120611aSHarry Wentland static int drm_mode_create_colorspace_property(struct drm_connector *connector,
2145*c627087cSHarry Wentland 					u32 supported_colorspaces)
21466120611aSHarry Wentland {
21476120611aSHarry Wentland 	struct drm_device *dev = connector->dev;
2148*c627087cSHarry Wentland 	u32 colorspaces = supported_colorspaces | BIT(DRM_MODE_COLORIMETRY_DEFAULT);
2149*c627087cSHarry Wentland 	struct drm_prop_enum_list enum_list[DRM_MODE_COLORIMETRY_COUNT];
2150*c627087cSHarry Wentland 	int i, len;
21516120611aSHarry Wentland 
21526120611aSHarry Wentland 	if (connector->colorspace_property)
21536120611aSHarry Wentland 		return 0;
21546120611aSHarry Wentland 
2155*c627087cSHarry Wentland 	if (!supported_colorspaces) {
2156*c627087cSHarry Wentland 		drm_err(dev, "No supported colorspaces provded on [CONNECTOR:%d:%s]\n",
2157*c627087cSHarry Wentland 			    connector->base.id, connector->name);
2158*c627087cSHarry Wentland 		return -EINVAL;
2159*c627087cSHarry Wentland 	}
2160*c627087cSHarry Wentland 
2161*c627087cSHarry Wentland 	if ((supported_colorspaces & -BIT(DRM_MODE_COLORIMETRY_COUNT)) != 0) {
2162*c627087cSHarry Wentland 		drm_err(dev, "Unknown colorspace provded on [CONNECTOR:%d:%s]\n",
2163*c627087cSHarry Wentland 			    connector->base.id, connector->name);
2164*c627087cSHarry Wentland 		return -EINVAL;
2165*c627087cSHarry Wentland 	}
2166*c627087cSHarry Wentland 
2167*c627087cSHarry Wentland 	len = 0;
2168*c627087cSHarry Wentland 	for (i = 0; i < DRM_MODE_COLORIMETRY_COUNT; i++) {
2169*c627087cSHarry Wentland 		if ((colorspaces & BIT(i)) == 0)
2170*c627087cSHarry Wentland 			continue;
2171*c627087cSHarry Wentland 
2172*c627087cSHarry Wentland 		enum_list[len].type = i;
2173*c627087cSHarry Wentland 		enum_list[len].name = colorspace_names[i];
2174*c627087cSHarry Wentland 		len++;
2175*c627087cSHarry Wentland 	}
21766120611aSHarry Wentland 
21776120611aSHarry Wentland 	connector->colorspace_property =
21786120611aSHarry Wentland 		drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
2179*c627087cSHarry Wentland 					enum_list,
2180*c627087cSHarry Wentland 					len);
21816120611aSHarry Wentland 
21826120611aSHarry Wentland 	if (!connector->colorspace_property)
21836120611aSHarry Wentland 		return -ENOMEM;
21846120611aSHarry Wentland 
21856120611aSHarry Wentland 	return 0;
21866120611aSHarry Wentland }
2187*c627087cSHarry Wentland 
21888806cd3aSGwan-gyeong Mun /**
21898806cd3aSGwan-gyeong Mun  * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
21908806cd3aSGwan-gyeong Mun  * @connector: connector to create the Colorspace property on.
21918806cd3aSGwan-gyeong Mun  *
21928806cd3aSGwan-gyeong Mun  * Called by a driver the first time it's needed, must be attached to desired
21938806cd3aSGwan-gyeong Mun  * HDMI connectors.
21948806cd3aSGwan-gyeong Mun  *
21958806cd3aSGwan-gyeong Mun  * Returns:
219684e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
21978806cd3aSGwan-gyeong Mun  */
21988806cd3aSGwan-gyeong Mun int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector)
2199d2c6a405SUma Shankar {
2200*c627087cSHarry Wentland 	return drm_mode_create_colorspace_property(connector, hdmi_colorspaces);
2201d2c6a405SUma Shankar }
22028806cd3aSGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
2203d2c6a405SUma Shankar 
2204d2c6a405SUma Shankar /**
220545cf0e91SGwan-gyeong Mun  * drm_mode_create_dp_colorspace_property - create dp colorspace property
220645cf0e91SGwan-gyeong Mun  * @connector: connector to create the Colorspace property on.
220745cf0e91SGwan-gyeong Mun  *
220845cf0e91SGwan-gyeong Mun  * Called by a driver the first time it's needed, must be attached to desired
220945cf0e91SGwan-gyeong Mun  * DP connectors.
221045cf0e91SGwan-gyeong Mun  *
221145cf0e91SGwan-gyeong Mun  * Returns:
221284e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
221345cf0e91SGwan-gyeong Mun  */
221445cf0e91SGwan-gyeong Mun int drm_mode_create_dp_colorspace_property(struct drm_connector *connector)
221545cf0e91SGwan-gyeong Mun {
2216*c627087cSHarry Wentland 	return drm_mode_create_colorspace_property(connector, dp_colorspaces);
221745cf0e91SGwan-gyeong Mun }
221845cf0e91SGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
221952217195SDaniel Vetter 
222097e14fbeSDaniel Vetter /**
222152217195SDaniel Vetter  * drm_mode_create_content_type_property - create content type property
222252217195SDaniel Vetter  * @dev: DRM device
222397e14fbeSDaniel Vetter  *
222452217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
222552217195SDaniel Vetter  * connectors.
222652217195SDaniel Vetter  *
222752217195SDaniel Vetter  * Returns:
222852217195SDaniel Vetter  * Zero on success, negative errno on failure.
222952217195SDaniel Vetter  */
223052217195SDaniel Vetter int drm_mode_create_content_type_property(struct drm_device *dev)
223152217195SDaniel Vetter {
223252217195SDaniel Vetter 	if (dev->mode_config.content_type_property)
223397e14fbeSDaniel Vetter 		return 0;
223452217195SDaniel Vetter 
223552217195SDaniel Vetter 	dev->mode_config.content_type_property =
223652217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "content type",
223752217195SDaniel Vetter 					 drm_content_type_enum_list,
223852217195SDaniel Vetter 					 ARRAY_SIZE(drm_content_type_enum_list));
223952217195SDaniel Vetter 
224052217195SDaniel Vetter 	if (dev->mode_config.content_type_property == NULL)
224152217195SDaniel Vetter 		return -ENOMEM;
224252217195SDaniel Vetter 
224352217195SDaniel Vetter 	return 0;
224452217195SDaniel Vetter }
224552217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_content_type_property);
224652217195SDaniel Vetter 
224752217195SDaniel Vetter /**
224852217195SDaniel Vetter  * drm_mode_create_suggested_offset_properties - create suggests offset properties
224952217195SDaniel Vetter  * @dev: DRM device
225052217195SDaniel Vetter  *
225184e543bcSAntonio Borneo  * Create the suggested x/y offset property for connectors.
2252f85d9e59SRandy Dunlap  *
2253f85d9e59SRandy Dunlap  * Returns:
2254f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
225552217195SDaniel Vetter  */
225652217195SDaniel Vetter int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
225752217195SDaniel Vetter {
225852217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
225952217195SDaniel Vetter 		return 0;
226052217195SDaniel Vetter 
226152217195SDaniel Vetter 	dev->mode_config.suggested_x_property =
226252217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
226352217195SDaniel Vetter 
226452217195SDaniel Vetter 	dev->mode_config.suggested_y_property =
226552217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
226652217195SDaniel Vetter 
226752217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property == NULL ||
226852217195SDaniel Vetter 	    dev->mode_config.suggested_y_property == NULL)
226952217195SDaniel Vetter 		return -ENOMEM;
227052217195SDaniel Vetter 	return 0;
227152217195SDaniel Vetter }
227252217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
227352217195SDaniel Vetter 
227452217195SDaniel Vetter /**
227552217195SDaniel Vetter  * drm_connector_set_path_property - set tile property on connector
227652217195SDaniel Vetter  * @connector: connector to set property on.
227752217195SDaniel Vetter  * @path: path to use for property; must not be NULL.
227852217195SDaniel Vetter  *
227952217195SDaniel Vetter  * This creates a property to expose to userspace to specify a
228052217195SDaniel Vetter  * connector path. This is mainly used for DisplayPort MST where
228152217195SDaniel Vetter  * connectors have a topology and we want to allow userspace to give
228252217195SDaniel Vetter  * them more meaningful names.
228352217195SDaniel Vetter  *
228452217195SDaniel Vetter  * Returns:
228552217195SDaniel Vetter  * Zero on success, negative errno on failure.
228652217195SDaniel Vetter  */
228752217195SDaniel Vetter int drm_connector_set_path_property(struct drm_connector *connector,
228852217195SDaniel Vetter 				    const char *path)
228952217195SDaniel Vetter {
229052217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
229152217195SDaniel Vetter 	int ret;
229252217195SDaniel Vetter 
229352217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
229452217195SDaniel Vetter 					       &connector->path_blob_ptr,
229552217195SDaniel Vetter 					       strlen(path) + 1,
229652217195SDaniel Vetter 					       path,
229752217195SDaniel Vetter 					       &connector->base,
229852217195SDaniel Vetter 					       dev->mode_config.path_property);
229952217195SDaniel Vetter 	return ret;
230052217195SDaniel Vetter }
230152217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_set_path_property);
230252217195SDaniel Vetter 
230352217195SDaniel Vetter /**
230452217195SDaniel Vetter  * drm_connector_set_tile_property - set tile property on connector
230552217195SDaniel Vetter  * @connector: connector to set property on.
230652217195SDaniel Vetter  *
230752217195SDaniel Vetter  * This looks up the tile information for a connector, and creates a
230852217195SDaniel Vetter  * property for userspace to parse if it exists. The property is of
230952217195SDaniel Vetter  * the form of 8 integers using ':' as a separator.
23102de3a078SManasi Navare  * This is used for dual port tiled displays with DisplayPort SST
23112de3a078SManasi Navare  * or DisplayPort MST connectors.
231252217195SDaniel Vetter  *
231352217195SDaniel Vetter  * Returns:
231452217195SDaniel Vetter  * Zero on success, errno on failure.
231552217195SDaniel Vetter  */
231652217195SDaniel Vetter int drm_connector_set_tile_property(struct drm_connector *connector)
231752217195SDaniel Vetter {
231852217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
231952217195SDaniel Vetter 	char tile[256];
232052217195SDaniel Vetter 	int ret;
232152217195SDaniel Vetter 
232252217195SDaniel Vetter 	if (!connector->has_tile) {
232352217195SDaniel Vetter 		ret  = drm_property_replace_global_blob(dev,
232452217195SDaniel Vetter 							&connector->tile_blob_ptr,
232552217195SDaniel Vetter 							0,
232652217195SDaniel Vetter 							NULL,
232752217195SDaniel Vetter 							&connector->base,
232852217195SDaniel Vetter 							dev->mode_config.tile_property);
232952217195SDaniel Vetter 		return ret;
233052217195SDaniel Vetter 	}
233152217195SDaniel Vetter 
233252217195SDaniel Vetter 	snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
233352217195SDaniel Vetter 		 connector->tile_group->id, connector->tile_is_single_monitor,
233452217195SDaniel Vetter 		 connector->num_h_tile, connector->num_v_tile,
233552217195SDaniel Vetter 		 connector->tile_h_loc, connector->tile_v_loc,
233652217195SDaniel Vetter 		 connector->tile_h_size, connector->tile_v_size);
233752217195SDaniel Vetter 
233852217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
233952217195SDaniel Vetter 					       &connector->tile_blob_ptr,
234052217195SDaniel Vetter 					       strlen(tile) + 1,
234152217195SDaniel Vetter 					       tile,
234252217195SDaniel Vetter 					       &connector->base,
234352217195SDaniel Vetter 					       dev->mode_config.tile_property);
234452217195SDaniel Vetter 	return ret;
234552217195SDaniel Vetter }
234697e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_tile_property);
234752217195SDaniel Vetter 
234852217195SDaniel Vetter /**
234997e14fbeSDaniel Vetter  * drm_connector_set_link_status_property - Set link status property of a connector
235040ee6fbeSManasi Navare  * @connector: drm connector
235140ee6fbeSManasi Navare  * @link_status: new value of link status property (0: Good, 1: Bad)
235240ee6fbeSManasi Navare  *
235340ee6fbeSManasi Navare  * In usual working scenario, this link status property will always be set to
235440ee6fbeSManasi Navare  * "GOOD". If something fails during or after a mode set, the kernel driver
235540ee6fbeSManasi Navare  * may set this link status property to "BAD". The caller then needs to send a
235640ee6fbeSManasi Navare  * hotplug uevent for userspace to re-check the valid modes through
235740ee6fbeSManasi Navare  * GET_CONNECTOR_IOCTL and retry modeset.
235840ee6fbeSManasi Navare  *
235940ee6fbeSManasi Navare  * Note: Drivers cannot rely on userspace to support this property and
236040ee6fbeSManasi Navare  * issue a modeset. As such, they may choose to handle issues (like
236140ee6fbeSManasi Navare  * re-training a link) without userspace's intervention.
236240ee6fbeSManasi Navare  *
236340ee6fbeSManasi Navare  * The reason for adding this property is to handle link training failures, but
236440ee6fbeSManasi Navare  * it is not limited to DP or link training. For example, if we implement
236540ee6fbeSManasi Navare  * asynchronous setcrtc, this property can be used to report any failures in that.
236640ee6fbeSManasi Navare  */
236797e14fbeSDaniel Vetter void drm_connector_set_link_status_property(struct drm_connector *connector,
236840ee6fbeSManasi Navare 					    uint64_t link_status)
236940ee6fbeSManasi Navare {
237040ee6fbeSManasi Navare 	struct drm_device *dev = connector->dev;
237140ee6fbeSManasi Navare 
237240ee6fbeSManasi Navare 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
237340ee6fbeSManasi Navare 	connector->state->link_status = link_status;
237440ee6fbeSManasi Navare 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
237540ee6fbeSManasi Navare }
237697e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_link_status_property);
237740ee6fbeSManasi Navare 
23788d70f395SHans de Goede /**
237947e22ff1SRadhakrishna Sripada  * drm_connector_attach_max_bpc_property - attach "max bpc" property
238047e22ff1SRadhakrishna Sripada  * @connector: connector to attach max bpc property on.
238147e22ff1SRadhakrishna Sripada  * @min: The minimum bit depth supported by the connector.
238247e22ff1SRadhakrishna Sripada  * @max: The maximum bit depth supported by the connector.
238347e22ff1SRadhakrishna Sripada  *
238447e22ff1SRadhakrishna Sripada  * This is used to add support for limiting the bit depth on a connector.
238547e22ff1SRadhakrishna Sripada  *
238647e22ff1SRadhakrishna Sripada  * Returns:
238747e22ff1SRadhakrishna Sripada  * Zero on success, negative errno on failure.
238847e22ff1SRadhakrishna Sripada  */
238947e22ff1SRadhakrishna Sripada int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
239047e22ff1SRadhakrishna Sripada 					  int min, int max)
239147e22ff1SRadhakrishna Sripada {
239247e22ff1SRadhakrishna Sripada 	struct drm_device *dev = connector->dev;
239347e22ff1SRadhakrishna Sripada 	struct drm_property *prop;
239447e22ff1SRadhakrishna Sripada 
239547e22ff1SRadhakrishna Sripada 	prop = connector->max_bpc_property;
239647e22ff1SRadhakrishna Sripada 	if (!prop) {
239747e22ff1SRadhakrishna Sripada 		prop = drm_property_create_range(dev, 0, "max bpc", min, max);
239847e22ff1SRadhakrishna Sripada 		if (!prop)
239947e22ff1SRadhakrishna Sripada 			return -ENOMEM;
240047e22ff1SRadhakrishna Sripada 
240147e22ff1SRadhakrishna Sripada 		connector->max_bpc_property = prop;
240247e22ff1SRadhakrishna Sripada 	}
240347e22ff1SRadhakrishna Sripada 
240447e22ff1SRadhakrishna Sripada 	drm_object_attach_property(&connector->base, prop, max);
240547e22ff1SRadhakrishna Sripada 	connector->state->max_requested_bpc = max;
240647e22ff1SRadhakrishna Sripada 	connector->state->max_bpc = max;
240747e22ff1SRadhakrishna Sripada 
240847e22ff1SRadhakrishna Sripada 	return 0;
240947e22ff1SRadhakrishna Sripada }
241047e22ff1SRadhakrishna Sripada EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
241147e22ff1SRadhakrishna Sripada 
241247e22ff1SRadhakrishna Sripada /**
2413e057b52cSMaxime Ripard  * drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADA" property
2414e057b52cSMaxime Ripard  * @connector: connector to attach the property on.
2415e057b52cSMaxime Ripard  *
2416e057b52cSMaxime Ripard  * This is used to allow the userspace to send HDR Metadata to the
2417e057b52cSMaxime Ripard  * driver.
2418e057b52cSMaxime Ripard  *
2419e057b52cSMaxime Ripard  * Returns:
2420e057b52cSMaxime Ripard  * Zero on success, negative errno on failure.
2421e057b52cSMaxime Ripard  */
2422e057b52cSMaxime Ripard int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector)
2423e057b52cSMaxime Ripard {
2424e057b52cSMaxime Ripard 	struct drm_device *dev = connector->dev;
2425e057b52cSMaxime Ripard 	struct drm_property *prop = dev->mode_config.hdr_output_metadata_property;
2426e057b52cSMaxime Ripard 
2427e057b52cSMaxime Ripard 	drm_object_attach_property(&connector->base, prop, 0);
2428e057b52cSMaxime Ripard 
2429e057b52cSMaxime Ripard 	return 0;
2430e057b52cSMaxime Ripard }
2431e057b52cSMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property);
2432e057b52cSMaxime Ripard 
2433e057b52cSMaxime Ripard /**
243421f79128SMaxime Ripard  * drm_connector_attach_colorspace_property - attach "Colorspace" property
243521f79128SMaxime Ripard  * @connector: connector to attach the property on.
243621f79128SMaxime Ripard  *
243721f79128SMaxime Ripard  * This is used to allow the userspace to signal the output colorspace
243821f79128SMaxime Ripard  * to the driver.
243921f79128SMaxime Ripard  *
244021f79128SMaxime Ripard  * Returns:
244121f79128SMaxime Ripard  * Zero on success, negative errno on failure.
244221f79128SMaxime Ripard  */
244321f79128SMaxime Ripard int drm_connector_attach_colorspace_property(struct drm_connector *connector)
244421f79128SMaxime Ripard {
244521f79128SMaxime Ripard 	struct drm_property *prop = connector->colorspace_property;
244621f79128SMaxime Ripard 
244721f79128SMaxime Ripard 	drm_object_attach_property(&connector->base, prop, DRM_MODE_COLORIMETRY_DEFAULT);
244821f79128SMaxime Ripard 
244921f79128SMaxime Ripard 	return 0;
245021f79128SMaxime Ripard }
245121f79128SMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_colorspace_property);
245221f79128SMaxime Ripard 
245321f79128SMaxime Ripard /**
245472921cdfSMaxime Ripard  * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed
245572921cdfSMaxime Ripard  * @old_state: old connector state to compare
245672921cdfSMaxime Ripard  * @new_state: new connector state to compare
245772921cdfSMaxime Ripard  *
245872921cdfSMaxime Ripard  * This is used by HDR-enabled drivers to test whether the HDR metadata
245972921cdfSMaxime Ripard  * have changed between two different connector state (and thus probably
246072921cdfSMaxime Ripard  * requires a full blown mode change).
246172921cdfSMaxime Ripard  *
246272921cdfSMaxime Ripard  * Returns:
246372921cdfSMaxime Ripard  * True if the metadata are equal, False otherwise
246472921cdfSMaxime Ripard  */
246572921cdfSMaxime Ripard bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state,
246672921cdfSMaxime Ripard 					     struct drm_connector_state *new_state)
246772921cdfSMaxime Ripard {
246872921cdfSMaxime Ripard 	struct drm_property_blob *old_blob = old_state->hdr_output_metadata;
246972921cdfSMaxime Ripard 	struct drm_property_blob *new_blob = new_state->hdr_output_metadata;
247072921cdfSMaxime Ripard 
247172921cdfSMaxime Ripard 	if (!old_blob || !new_blob)
247272921cdfSMaxime Ripard 		return old_blob == new_blob;
247372921cdfSMaxime Ripard 
247472921cdfSMaxime Ripard 	if (old_blob->length != new_blob->length)
247572921cdfSMaxime Ripard 		return false;
247672921cdfSMaxime Ripard 
247772921cdfSMaxime Ripard 	return !memcmp(old_blob->data, new_blob->data, old_blob->length);
247872921cdfSMaxime Ripard }
247972921cdfSMaxime Ripard EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal);
248072921cdfSMaxime Ripard 
248172921cdfSMaxime Ripard /**
2482ba1b0f6cSNicholas Kazlauskas  * drm_connector_set_vrr_capable_property - sets the variable refresh rate
2483ba1b0f6cSNicholas Kazlauskas  * capable property for a connector
2484ba1b0f6cSNicholas Kazlauskas  * @connector: drm connector
2485ba1b0f6cSNicholas Kazlauskas  * @capable: True if the connector is variable refresh rate capable
2486ba1b0f6cSNicholas Kazlauskas  *
2487ba1b0f6cSNicholas Kazlauskas  * Should be used by atomic drivers to update the indicated support for
2488ba1b0f6cSNicholas Kazlauskas  * variable refresh rate over a connector.
2489ba1b0f6cSNicholas Kazlauskas  */
2490ba1b0f6cSNicholas Kazlauskas void drm_connector_set_vrr_capable_property(
2491ba1b0f6cSNicholas Kazlauskas 		struct drm_connector *connector, bool capable)
2492ba1b0f6cSNicholas Kazlauskas {
249362929726SManasi Navare 	if (!connector->vrr_capable_property)
249462929726SManasi Navare 		return;
249562929726SManasi Navare 
2496ba1b0f6cSNicholas Kazlauskas 	drm_object_property_set_value(&connector->base,
2497ba1b0f6cSNicholas Kazlauskas 				      connector->vrr_capable_property,
2498ba1b0f6cSNicholas Kazlauskas 				      capable);
2499ba1b0f6cSNicholas Kazlauskas }
2500ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
2501ba1b0f6cSNicholas Kazlauskas 
2502ba1b0f6cSNicholas Kazlauskas /**
250384e543bcSAntonio Borneo  * drm_connector_set_panel_orientation - sets the connector's panel_orientation
250469654c63SDerek Basehore  * @connector: connector for which to set the panel-orientation property.
250569654c63SDerek Basehore  * @panel_orientation: drm_panel_orientation value to set
25068d70f395SHans de Goede  *
250769654c63SDerek Basehore  * This function sets the connector's panel_orientation and attaches
250869654c63SDerek Basehore  * a "panel orientation" property to the connector.
25098d70f395SHans de Goede  *
251069654c63SDerek Basehore  * Calling this function on a connector where the panel_orientation has
251169654c63SDerek Basehore  * already been set is a no-op (e.g. the orientation has been overridden with
251269654c63SDerek Basehore  * a kernel commandline option).
251369654c63SDerek Basehore  *
251469654c63SDerek Basehore  * It is allowed to call this function with a panel_orientation of
251569654c63SDerek Basehore  * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
25168d70f395SHans de Goede  *
25175e41b01aSHsin-Yi Wang  * The function shouldn't be called in panel after drm is registered (i.e.
25185e41b01aSHsin-Yi Wang  * drm_dev_register() is called in drm).
25195e41b01aSHsin-Yi Wang  *
25208d70f395SHans de Goede  * Returns:
25218d70f395SHans de Goede  * Zero on success, negative errno on failure.
25228d70f395SHans de Goede  */
252369654c63SDerek Basehore int drm_connector_set_panel_orientation(
252469654c63SDerek Basehore 	struct drm_connector *connector,
252569654c63SDerek Basehore 	enum drm_panel_orientation panel_orientation)
25268d70f395SHans de Goede {
25278d70f395SHans de Goede 	struct drm_device *dev = connector->dev;
25288d70f395SHans de Goede 	struct drm_display_info *info = &connector->display_info;
25298d70f395SHans de Goede 	struct drm_property *prop;
25308d70f395SHans de Goede 
253169654c63SDerek Basehore 	/* Already set? */
253269654c63SDerek Basehore 	if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
25338d70f395SHans de Goede 		return 0;
25348d70f395SHans de Goede 
253569654c63SDerek Basehore 	/* Don't attach the property if the orientation is unknown */
253669654c63SDerek Basehore 	if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
253769654c63SDerek Basehore 		return 0;
253869654c63SDerek Basehore 
253969654c63SDerek Basehore 	info->panel_orientation = panel_orientation;
254069654c63SDerek Basehore 
25418d70f395SHans de Goede 	prop = dev->mode_config.panel_orientation_property;
25428d70f395SHans de Goede 	if (!prop) {
25438d70f395SHans de Goede 		prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
25448d70f395SHans de Goede 				"panel orientation",
25458d70f395SHans de Goede 				drm_panel_orientation_enum_list,
25468d70f395SHans de Goede 				ARRAY_SIZE(drm_panel_orientation_enum_list));
25478d70f395SHans de Goede 		if (!prop)
25488d70f395SHans de Goede 			return -ENOMEM;
25498d70f395SHans de Goede 
25508d70f395SHans de Goede 		dev->mode_config.panel_orientation_property = prop;
25518d70f395SHans de Goede 	}
25528d70f395SHans de Goede 
25538d70f395SHans de Goede 	drm_object_attach_property(&connector->base, prop,
25548d70f395SHans de Goede 				   info->panel_orientation);
25558d70f395SHans de Goede 	return 0;
25568d70f395SHans de Goede }
255769654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation);
255869654c63SDerek Basehore 
255969654c63SDerek Basehore /**
2560f85d9e59SRandy Dunlap  * drm_connector_set_panel_orientation_with_quirk - set the
2561f85d9e59SRandy Dunlap  *	connector's panel_orientation after checking for quirks
256269654c63SDerek Basehore  * @connector: connector for which to init the panel-orientation property.
256369654c63SDerek Basehore  * @panel_orientation: drm_panel_orientation value to set
256469654c63SDerek Basehore  * @width: width in pixels of the panel, used for panel quirk detection
256569654c63SDerek Basehore  * @height: height in pixels of the panel, used for panel quirk detection
256669654c63SDerek Basehore  *
256769654c63SDerek Basehore  * Like drm_connector_set_panel_orientation(), but with a check for platform
256869654c63SDerek Basehore  * specific (e.g. DMI based) quirks overriding the passed in panel_orientation.
256969654c63SDerek Basehore  *
257069654c63SDerek Basehore  * Returns:
257169654c63SDerek Basehore  * Zero on success, negative errno on failure.
257269654c63SDerek Basehore  */
257369654c63SDerek Basehore int drm_connector_set_panel_orientation_with_quirk(
257469654c63SDerek Basehore 	struct drm_connector *connector,
257569654c63SDerek Basehore 	enum drm_panel_orientation panel_orientation,
257669654c63SDerek Basehore 	int width, int height)
257769654c63SDerek Basehore {
257869654c63SDerek Basehore 	int orientation_quirk;
257969654c63SDerek Basehore 
258069654c63SDerek Basehore 	orientation_quirk = drm_get_panel_orientation_quirk(width, height);
258169654c63SDerek Basehore 	if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
258269654c63SDerek Basehore 		panel_orientation = orientation_quirk;
258369654c63SDerek Basehore 
258469654c63SDerek Basehore 	return drm_connector_set_panel_orientation(connector,
258569654c63SDerek Basehore 						   panel_orientation);
258669654c63SDerek Basehore }
258769654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
25888d70f395SHans de Goede 
25895e41b01aSHsin-Yi Wang /**
25905e41b01aSHsin-Yi Wang  * drm_connector_set_orientation_from_panel -
25915e41b01aSHsin-Yi Wang  *	set the connector's panel_orientation from panel's callback.
25925e41b01aSHsin-Yi Wang  * @connector: connector for which to init the panel-orientation property.
25935e41b01aSHsin-Yi Wang  * @panel: panel that can provide orientation information.
25945e41b01aSHsin-Yi Wang  *
25955e41b01aSHsin-Yi Wang  * Drm drivers should call this function before drm_dev_register().
25965e41b01aSHsin-Yi Wang  * Orientation is obtained from panel's .get_orientation() callback.
25975e41b01aSHsin-Yi Wang  *
25985e41b01aSHsin-Yi Wang  * Returns:
25995e41b01aSHsin-Yi Wang  * Zero on success, negative errno on failure.
26005e41b01aSHsin-Yi Wang  */
26015e41b01aSHsin-Yi Wang int drm_connector_set_orientation_from_panel(
26025e41b01aSHsin-Yi Wang 	struct drm_connector *connector,
26035e41b01aSHsin-Yi Wang 	struct drm_panel *panel)
26045e41b01aSHsin-Yi Wang {
26055e41b01aSHsin-Yi Wang 	enum drm_panel_orientation orientation;
26065e41b01aSHsin-Yi Wang 
26075e41b01aSHsin-Yi Wang 	if (panel && panel->funcs && panel->funcs->get_orientation)
26085e41b01aSHsin-Yi Wang 		orientation = panel->funcs->get_orientation(panel);
26095e41b01aSHsin-Yi Wang 	else
26105e41b01aSHsin-Yi Wang 		orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
26115e41b01aSHsin-Yi Wang 
26125e41b01aSHsin-Yi Wang 	return drm_connector_set_panel_orientation(connector, orientation);
26135e41b01aSHsin-Yi Wang }
26145e41b01aSHsin-Yi Wang EXPORT_SYMBOL(drm_connector_set_orientation_from_panel);
26155e41b01aSHsin-Yi Wang 
2616107fe904SRajat Jain static const struct drm_prop_enum_list privacy_screen_enum[] = {
2617107fe904SRajat Jain 	{ PRIVACY_SCREEN_DISABLED,		"Disabled" },
2618107fe904SRajat Jain 	{ PRIVACY_SCREEN_ENABLED,		"Enabled" },
2619107fe904SRajat Jain 	{ PRIVACY_SCREEN_DISABLED_LOCKED,	"Disabled-locked" },
2620107fe904SRajat Jain 	{ PRIVACY_SCREEN_ENABLED_LOCKED,	"Enabled-locked" },
2621107fe904SRajat Jain };
2622107fe904SRajat Jain 
2623107fe904SRajat Jain /**
2624107fe904SRajat Jain  * drm_connector_create_privacy_screen_properties - create the drm connecter's
2625107fe904SRajat Jain  *    privacy-screen properties.
2626107fe904SRajat Jain  * @connector: connector for which to create the privacy-screen properties
2627107fe904SRajat Jain  *
2628107fe904SRajat Jain  * This function creates the "privacy-screen sw-state" and "privacy-screen
2629107fe904SRajat Jain  * hw-state" properties for the connector. They are not attached.
2630107fe904SRajat Jain  */
2631107fe904SRajat Jain void
2632107fe904SRajat Jain drm_connector_create_privacy_screen_properties(struct drm_connector *connector)
2633107fe904SRajat Jain {
2634107fe904SRajat Jain 	if (connector->privacy_screen_sw_state_property)
2635107fe904SRajat Jain 		return;
2636107fe904SRajat Jain 
2637107fe904SRajat Jain 	/* Note sw-state only supports the first 2 values of the enum */
2638107fe904SRajat Jain 	connector->privacy_screen_sw_state_property =
2639107fe904SRajat Jain 		drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM,
2640107fe904SRajat Jain 				"privacy-screen sw-state",
2641107fe904SRajat Jain 				privacy_screen_enum, 2);
2642107fe904SRajat Jain 
2643107fe904SRajat Jain 	connector->privacy_screen_hw_state_property =
2644107fe904SRajat Jain 		drm_property_create_enum(connector->dev,
2645107fe904SRajat Jain 				DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM,
2646107fe904SRajat Jain 				"privacy-screen hw-state",
2647107fe904SRajat Jain 				privacy_screen_enum,
2648107fe904SRajat Jain 				ARRAY_SIZE(privacy_screen_enum));
2649107fe904SRajat Jain }
2650107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties);
2651107fe904SRajat Jain 
2652107fe904SRajat Jain /**
2653107fe904SRajat Jain  * drm_connector_attach_privacy_screen_properties - attach the drm connecter's
2654107fe904SRajat Jain  *    privacy-screen properties.
2655107fe904SRajat Jain  * @connector: connector on which to attach the privacy-screen properties
2656107fe904SRajat Jain  *
2657107fe904SRajat Jain  * This function attaches the "privacy-screen sw-state" and "privacy-screen
2658107fe904SRajat Jain  * hw-state" properties to the connector. The initial state of both is set
2659107fe904SRajat Jain  * to "Disabled".
2660107fe904SRajat Jain  */
2661107fe904SRajat Jain void
2662107fe904SRajat Jain drm_connector_attach_privacy_screen_properties(struct drm_connector *connector)
2663107fe904SRajat Jain {
2664107fe904SRajat Jain 	if (!connector->privacy_screen_sw_state_property)
2665107fe904SRajat Jain 		return;
2666107fe904SRajat Jain 
2667107fe904SRajat Jain 	drm_object_attach_property(&connector->base,
2668107fe904SRajat Jain 				   connector->privacy_screen_sw_state_property,
2669107fe904SRajat Jain 				   PRIVACY_SCREEN_DISABLED);
2670107fe904SRajat Jain 
2671107fe904SRajat Jain 	drm_object_attach_property(&connector->base,
2672107fe904SRajat Jain 				   connector->privacy_screen_hw_state_property,
2673107fe904SRajat Jain 				   PRIVACY_SCREEN_DISABLED);
2674107fe904SRajat Jain }
2675107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties);
2676107fe904SRajat Jain 
2677334f74eeSHans de Goede static void drm_connector_update_privacy_screen_properties(
2678334f74eeSHans de Goede 	struct drm_connector *connector, bool set_sw_state)
2679334f74eeSHans de Goede {
2680334f74eeSHans de Goede 	enum drm_privacy_screen_status sw_state, hw_state;
2681334f74eeSHans de Goede 
2682334f74eeSHans de Goede 	drm_privacy_screen_get_state(connector->privacy_screen,
2683334f74eeSHans de Goede 				     &sw_state, &hw_state);
2684334f74eeSHans de Goede 
2685334f74eeSHans de Goede 	if (set_sw_state)
2686334f74eeSHans de Goede 		connector->state->privacy_screen_sw_state = sw_state;
2687334f74eeSHans de Goede 	drm_object_property_set_value(&connector->base,
2688334f74eeSHans de Goede 			connector->privacy_screen_hw_state_property, hw_state);
2689334f74eeSHans de Goede }
2690334f74eeSHans de Goede 
2691334f74eeSHans de Goede static int drm_connector_privacy_screen_notifier(
2692334f74eeSHans de Goede 	struct notifier_block *nb, unsigned long action, void *data)
2693334f74eeSHans de Goede {
2694334f74eeSHans de Goede 	struct drm_connector *connector =
2695334f74eeSHans de Goede 		container_of(nb, struct drm_connector, privacy_screen_notifier);
2696334f74eeSHans de Goede 	struct drm_device *dev = connector->dev;
2697334f74eeSHans de Goede 
2698334f74eeSHans de Goede 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2699334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, true);
2700334f74eeSHans de Goede 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
2701334f74eeSHans de Goede 
2702334f74eeSHans de Goede 	drm_sysfs_connector_status_event(connector,
2703334f74eeSHans de Goede 				connector->privacy_screen_sw_state_property);
2704334f74eeSHans de Goede 	drm_sysfs_connector_status_event(connector,
2705334f74eeSHans de Goede 				connector->privacy_screen_hw_state_property);
2706334f74eeSHans de Goede 
2707334f74eeSHans de Goede 	return NOTIFY_DONE;
2708334f74eeSHans de Goede }
2709334f74eeSHans de Goede 
2710334f74eeSHans de Goede /**
2711334f74eeSHans de Goede  * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to
2712334f74eeSHans de Goede  *    the connector
2713334f74eeSHans de Goede  * @connector: connector to attach the privacy-screen to
2714334f74eeSHans de Goede  * @priv: drm_privacy_screen to attach
2715334f74eeSHans de Goede  *
2716334f74eeSHans de Goede  * Create and attach the standard privacy-screen properties and register
2717334f74eeSHans de Goede  * a generic notifier for generating sysfs-connector-status-events
2718334f74eeSHans de Goede  * on external changes to the privacy-screen status.
2719334f74eeSHans de Goede  * This function takes ownership of the passed in drm_privacy_screen and will
2720334f74eeSHans de Goede  * call drm_privacy_screen_put() on it when the connector is destroyed.
2721334f74eeSHans de Goede  */
2722334f74eeSHans de Goede void drm_connector_attach_privacy_screen_provider(
2723334f74eeSHans de Goede 	struct drm_connector *connector, struct drm_privacy_screen *priv)
2724334f74eeSHans de Goede {
2725334f74eeSHans de Goede 	connector->privacy_screen = priv;
2726334f74eeSHans de Goede 	connector->privacy_screen_notifier.notifier_call =
2727334f74eeSHans de Goede 		drm_connector_privacy_screen_notifier;
2728334f74eeSHans de Goede 
2729334f74eeSHans de Goede 	drm_connector_create_privacy_screen_properties(connector);
2730334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, true);
2731334f74eeSHans de Goede 	drm_connector_attach_privacy_screen_properties(connector);
2732334f74eeSHans de Goede }
2733334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider);
2734334f74eeSHans de Goede 
2735334f74eeSHans de Goede /**
2736334f74eeSHans de Goede  * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state
2737334f74eeSHans de Goede  * @connector_state: connector-state to update the privacy-screen for
2738334f74eeSHans de Goede  *
2739334f74eeSHans de Goede  * This function calls drm_privacy_screen_set_sw_state() on the connector's
2740334f74eeSHans de Goede  * privacy-screen.
2741334f74eeSHans de Goede  *
2742334f74eeSHans de Goede  * If the connector has no privacy-screen, then this is a no-op.
2743334f74eeSHans de Goede  */
2744334f74eeSHans de Goede void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state)
2745334f74eeSHans de Goede {
2746334f74eeSHans de Goede 	struct drm_connector *connector = connector_state->connector;
2747334f74eeSHans de Goede 	int ret;
2748334f74eeSHans de Goede 
2749334f74eeSHans de Goede 	if (!connector->privacy_screen)
2750334f74eeSHans de Goede 		return;
2751334f74eeSHans de Goede 
2752334f74eeSHans de Goede 	ret = drm_privacy_screen_set_sw_state(connector->privacy_screen,
2753334f74eeSHans de Goede 					      connector_state->privacy_screen_sw_state);
2754334f74eeSHans de Goede 	if (ret) {
2755334f74eeSHans de Goede 		drm_err(connector->dev, "Error updating privacy-screen sw_state\n");
2756334f74eeSHans de Goede 		return;
2757334f74eeSHans de Goede 	}
2758334f74eeSHans de Goede 
2759334f74eeSHans de Goede 	/* The hw_state property value may have changed, update it. */
2760334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, false);
2761334f74eeSHans de Goede }
2762334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_update_privacy_screen);
2763334f74eeSHans de Goede 
276497e14fbeSDaniel Vetter int drm_connector_set_obj_prop(struct drm_mode_object *obj,
276552217195SDaniel Vetter 				    struct drm_property *property,
276652217195SDaniel Vetter 				    uint64_t value)
276752217195SDaniel Vetter {
276852217195SDaniel Vetter 	int ret = -EINVAL;
276952217195SDaniel Vetter 	struct drm_connector *connector = obj_to_connector(obj);
277052217195SDaniel Vetter 
277152217195SDaniel Vetter 	/* Do DPMS ourselves */
277252217195SDaniel Vetter 	if (property == connector->dev->mode_config.dpms_property) {
277352217195SDaniel Vetter 		ret = (*connector->funcs->dpms)(connector, (int)value);
277452217195SDaniel Vetter 	} else if (connector->funcs->set_property)
277552217195SDaniel Vetter 		ret = connector->funcs->set_property(connector, property, value);
277652217195SDaniel Vetter 
2777144a7999SDaniel Vetter 	if (!ret)
277852217195SDaniel Vetter 		drm_object_property_set_value(&connector->base, property, value);
277952217195SDaniel Vetter 	return ret;
278052217195SDaniel Vetter }
278152217195SDaniel Vetter 
278297e14fbeSDaniel Vetter int drm_connector_property_set_ioctl(struct drm_device *dev,
278352217195SDaniel Vetter 				     void *data, struct drm_file *file_priv)
278452217195SDaniel Vetter {
278552217195SDaniel Vetter 	struct drm_mode_connector_set_property *conn_set_prop = data;
278652217195SDaniel Vetter 	struct drm_mode_obj_set_property obj_set_prop = {
278752217195SDaniel Vetter 		.value = conn_set_prop->value,
278852217195SDaniel Vetter 		.prop_id = conn_set_prop->prop_id,
278952217195SDaniel Vetter 		.obj_id = conn_set_prop->connector_id,
279052217195SDaniel Vetter 		.obj_type = DRM_MODE_OBJECT_CONNECTOR
279152217195SDaniel Vetter 	};
279252217195SDaniel Vetter 
279352217195SDaniel Vetter 	/* It does all the locking and checking we need */
279452217195SDaniel Vetter 	return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
279552217195SDaniel Vetter }
279652217195SDaniel Vetter 
279752217195SDaniel Vetter static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
279852217195SDaniel Vetter {
279952217195SDaniel Vetter 	/* For atomic drivers only state objects are synchronously updated and
2800c2ce66daSBeatriz Martins de Carvalho 	 * protected by modeset locks, so check those first.
2801c2ce66daSBeatriz Martins de Carvalho 	 */
280252217195SDaniel Vetter 	if (connector->state)
280352217195SDaniel Vetter 		return connector->state->best_encoder;
280452217195SDaniel Vetter 	return connector->encoder;
280552217195SDaniel Vetter }
280652217195SDaniel Vetter 
2807c3ff0cdbSAnkit Nautiyal static bool
2808c3ff0cdbSAnkit Nautiyal drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
28098445e2c5SVille Syrjälä 			     const struct list_head *modes,
281052217195SDaniel Vetter 			     const struct drm_file *file_priv)
281152217195SDaniel Vetter {
281252217195SDaniel Vetter 	/*
281352217195SDaniel Vetter 	 * If user-space hasn't configured the driver to expose the stereo 3D
281452217195SDaniel Vetter 	 * modes, don't expose them.
281552217195SDaniel Vetter 	 */
281652217195SDaniel Vetter 	if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
281752217195SDaniel Vetter 		return false;
2818c3ff0cdbSAnkit Nautiyal 	/*
2819c3ff0cdbSAnkit Nautiyal 	 * If user-space hasn't configured the driver to expose the modes
2820c3ff0cdbSAnkit Nautiyal 	 * with aspect-ratio, don't expose them. However if such a mode
2821c3ff0cdbSAnkit Nautiyal 	 * is unique, let it be exposed, but reset the aspect-ratio flags
2822c3ff0cdbSAnkit Nautiyal 	 * while preparing the list of user-modes.
2823c3ff0cdbSAnkit Nautiyal 	 */
2824c3ff0cdbSAnkit Nautiyal 	if (!file_priv->aspect_ratio_allowed) {
28258445e2c5SVille Syrjälä 		const struct drm_display_mode *mode_itr;
2826c3ff0cdbSAnkit Nautiyal 
28278445e2c5SVille Syrjälä 		list_for_each_entry(mode_itr, modes, head) {
28288445e2c5SVille Syrjälä 			if (mode_itr->expose_to_userspace &&
28298445e2c5SVille Syrjälä 			    drm_mode_match(mode_itr, mode,
2830c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_TIMINGS |
2831c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_CLOCK |
2832c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_FLAGS |
2833c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_3D_FLAGS))
2834c3ff0cdbSAnkit Nautiyal 				return false;
2835c3ff0cdbSAnkit Nautiyal 		}
28368445e2c5SVille Syrjälä 	}
283752217195SDaniel Vetter 
283852217195SDaniel Vetter 	return true;
283952217195SDaniel Vetter }
284052217195SDaniel Vetter 
284152217195SDaniel Vetter int drm_mode_getconnector(struct drm_device *dev, void *data,
284252217195SDaniel Vetter 			  struct drm_file *file_priv)
284352217195SDaniel Vetter {
284452217195SDaniel Vetter 	struct drm_mode_get_connector *out_resp = data;
284552217195SDaniel Vetter 	struct drm_connector *connector;
284652217195SDaniel Vetter 	struct drm_encoder *encoder;
284752217195SDaniel Vetter 	struct drm_display_mode *mode;
284852217195SDaniel Vetter 	int mode_count = 0;
284952217195SDaniel Vetter 	int encoders_count = 0;
285052217195SDaniel Vetter 	int ret = 0;
285152217195SDaniel Vetter 	int copied = 0;
285252217195SDaniel Vetter 	struct drm_mode_modeinfo u_mode;
285352217195SDaniel Vetter 	struct drm_mode_modeinfo __user *mode_ptr;
285452217195SDaniel Vetter 	uint32_t __user *encoder_ptr;
2855869e76f7SDesmond Cheong Zhi Xi 	bool is_current_master;
285652217195SDaniel Vetter 
285752217195SDaniel Vetter 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
285869fdf420SChris Wilson 		return -EOPNOTSUPP;
285952217195SDaniel Vetter 
286052217195SDaniel Vetter 	memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
286152217195SDaniel Vetter 
2862418da172SKeith Packard 	connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
286391eefc05SDaniel Vetter 	if (!connector)
286491eefc05SDaniel Vetter 		return -ENOENT;
286552217195SDaniel Vetter 
286662afb4adSJosé Roberto de Souza 	encoders_count = hweight32(connector->possible_encoders);
286791eefc05SDaniel Vetter 
286891eefc05SDaniel Vetter 	if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
286991eefc05SDaniel Vetter 		copied = 0;
287091eefc05SDaniel Vetter 		encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
287183aefbb8SVille Syrjälä 
287262afb4adSJosé Roberto de Souza 		drm_connector_for_each_possible_encoder(connector, encoder) {
287383aefbb8SVille Syrjälä 			if (put_user(encoder->base.id, encoder_ptr + copied)) {
287491eefc05SDaniel Vetter 				ret = -EFAULT;
2875e94ac351SDaniel Vetter 				goto out;
287691eefc05SDaniel Vetter 			}
287791eefc05SDaniel Vetter 			copied++;
287891eefc05SDaniel Vetter 		}
287991eefc05SDaniel Vetter 	}
288091eefc05SDaniel Vetter 	out_resp->count_encoders = encoders_count;
288191eefc05SDaniel Vetter 
288291eefc05SDaniel Vetter 	out_resp->connector_id = connector->base.id;
288391eefc05SDaniel Vetter 	out_resp->connector_type = connector->connector_type;
288491eefc05SDaniel Vetter 	out_resp->connector_type_id = connector->connector_type_id;
288591eefc05SDaniel Vetter 
2886869e76f7SDesmond Cheong Zhi Xi 	is_current_master = drm_is_current_master(file_priv);
2887869e76f7SDesmond Cheong Zhi Xi 
288891eefc05SDaniel Vetter 	mutex_lock(&dev->mode_config.mutex);
288991eefc05SDaniel Vetter 	if (out_resp->count_modes == 0) {
2890869e76f7SDesmond Cheong Zhi Xi 		if (is_current_master)
289191eefc05SDaniel Vetter 			connector->funcs->fill_modes(connector,
289291eefc05SDaniel Vetter 						     dev->mode_config.max_width,
289391eefc05SDaniel Vetter 						     dev->mode_config.max_height);
28948f86c82aSSimon Ser 		else
28958f86c82aSSimon Ser 			drm_dbg_kms(dev, "User-space requested a forced probe on [CONNECTOR:%d:%s] but is not the DRM master, demoting to read-only probe",
28968f86c82aSSimon Ser 				    connector->base.id, connector->name);
289791eefc05SDaniel Vetter 	}
289891eefc05SDaniel Vetter 
289991eefc05SDaniel Vetter 	out_resp->mm_width = connector->display_info.width_mm;
290091eefc05SDaniel Vetter 	out_resp->mm_height = connector->display_info.height_mm;
290191eefc05SDaniel Vetter 	out_resp->subpixel = connector->display_info.subpixel_order;
290291eefc05SDaniel Vetter 	out_resp->connection = connector->status;
290391eefc05SDaniel Vetter 
290491eefc05SDaniel Vetter 	/* delayed so we get modes regardless of pre-fill_modes state */
29058445e2c5SVille Syrjälä 	list_for_each_entry(mode, &connector->modes, head) {
29068445e2c5SVille Syrjälä 		WARN_ON(mode->expose_to_userspace);
29078445e2c5SVille Syrjälä 
29088445e2c5SVille Syrjälä 		if (drm_mode_expose_to_userspace(mode, &connector->modes,
2909c3ff0cdbSAnkit Nautiyal 						 file_priv)) {
29108445e2c5SVille Syrjälä 			mode->expose_to_userspace = true;
291191eefc05SDaniel Vetter 			mode_count++;
2912c3ff0cdbSAnkit Nautiyal 		}
29138445e2c5SVille Syrjälä 	}
291491eefc05SDaniel Vetter 
291552217195SDaniel Vetter 	/*
291652217195SDaniel Vetter 	 * This ioctl is called twice, once to determine how much space is
291752217195SDaniel Vetter 	 * needed, and the 2nd time to fill it.
291852217195SDaniel Vetter 	 */
291952217195SDaniel Vetter 	if ((out_resp->count_modes >= mode_count) && mode_count) {
292052217195SDaniel Vetter 		copied = 0;
292152217195SDaniel Vetter 		mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
29228445e2c5SVille Syrjälä 		list_for_each_entry(mode, &connector->modes, head) {
29238445e2c5SVille Syrjälä 			if (!mode->expose_to_userspace)
29248445e2c5SVille Syrjälä 				continue;
29258445e2c5SVille Syrjälä 
29268445e2c5SVille Syrjälä 			/* Clear the tag for the next time around */
29278445e2c5SVille Syrjälä 			mode->expose_to_userspace = false;
29288445e2c5SVille Syrjälä 
292952217195SDaniel Vetter 			drm_mode_convert_to_umode(&u_mode, mode);
2930c3ff0cdbSAnkit Nautiyal 			/*
2931c3ff0cdbSAnkit Nautiyal 			 * Reset aspect ratio flags of user-mode, if modes with
2932c3ff0cdbSAnkit Nautiyal 			 * aspect-ratio are not supported.
2933c3ff0cdbSAnkit Nautiyal 			 */
2934c3ff0cdbSAnkit Nautiyal 			if (!file_priv->aspect_ratio_allowed)
2935c3ff0cdbSAnkit Nautiyal 				u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
293652217195SDaniel Vetter 			if (copy_to_user(mode_ptr + copied,
293752217195SDaniel Vetter 					 &u_mode, sizeof(u_mode))) {
293852217195SDaniel Vetter 				ret = -EFAULT;
29398445e2c5SVille Syrjälä 
29408445e2c5SVille Syrjälä 				/*
29418445e2c5SVille Syrjälä 				 * Clear the tag for the rest of
29428445e2c5SVille Syrjälä 				 * the modes for the next time around.
29438445e2c5SVille Syrjälä 				 */
29448445e2c5SVille Syrjälä 				list_for_each_entry_continue(mode, &connector->modes, head)
29458445e2c5SVille Syrjälä 					mode->expose_to_userspace = false;
29468445e2c5SVille Syrjälä 
2947e94ac351SDaniel Vetter 				mutex_unlock(&dev->mode_config.mutex);
2948e94ac351SDaniel Vetter 
294952217195SDaniel Vetter 				goto out;
295052217195SDaniel Vetter 			}
295152217195SDaniel Vetter 			copied++;
295252217195SDaniel Vetter 		}
29538445e2c5SVille Syrjälä 	} else {
29548445e2c5SVille Syrjälä 		/* Clear the tag for the next time around */
29558445e2c5SVille Syrjälä 		list_for_each_entry(mode, &connector->modes, head)
29568445e2c5SVille Syrjälä 			mode->expose_to_userspace = false;
295752217195SDaniel Vetter 	}
29588445e2c5SVille Syrjälä 
295952217195SDaniel Vetter 	out_resp->count_modes = mode_count;
296052217195SDaniel Vetter 	mutex_unlock(&dev->mode_config.mutex);
2961e94ac351SDaniel Vetter 
2962e94ac351SDaniel Vetter 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2963e94ac351SDaniel Vetter 	encoder = drm_connector_get_encoder(connector);
2964e94ac351SDaniel Vetter 	if (encoder)
2965e94ac351SDaniel Vetter 		out_resp->encoder_id = encoder->base.id;
2966e94ac351SDaniel Vetter 	else
2967e94ac351SDaniel Vetter 		out_resp->encoder_id = 0;
2968e94ac351SDaniel Vetter 
2969e94ac351SDaniel Vetter 	/* Only grab properties after probing, to make sure EDID and other
2970c2ce66daSBeatriz Martins de Carvalho 	 * properties reflect the latest status.
2971c2ce66daSBeatriz Martins de Carvalho 	 */
2972e94ac351SDaniel Vetter 	ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
2973e94ac351SDaniel Vetter 			(uint32_t __user *)(unsigned long)(out_resp->props_ptr),
2974e94ac351SDaniel Vetter 			(uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
2975e94ac351SDaniel Vetter 			&out_resp->count_props);
2976e94ac351SDaniel Vetter 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
2977e94ac351SDaniel Vetter 
2978e94ac351SDaniel Vetter out:
2979ad093607SThierry Reding 	drm_connector_put(connector);
298052217195SDaniel Vetter 
298152217195SDaniel Vetter 	return ret;
298252217195SDaniel Vetter }
298352217195SDaniel Vetter 
29843d3f7c1eSHans de Goede /**
29853d3f7c1eSHans de Goede  * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode
29863d3f7c1eSHans de Goede  * @fwnode: fwnode for which to find the matching drm_connector
29873d3f7c1eSHans de Goede  *
29883d3f7c1eSHans de Goede  * This functions looks up a drm_connector based on its associated fwnode. When
29893d3f7c1eSHans de Goede  * a connector is found a reference to the connector is returned. The caller must
29903d3f7c1eSHans de Goede  * call drm_connector_put() to release this reference when it is done with the
29913d3f7c1eSHans de Goede  * connector.
29923d3f7c1eSHans de Goede  *
29933d3f7c1eSHans de Goede  * Returns: A reference to the found connector or an ERR_PTR().
29943d3f7c1eSHans de Goede  */
29953d3f7c1eSHans de Goede struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode)
29963d3f7c1eSHans de Goede {
29973d3f7c1eSHans de Goede 	struct drm_connector *connector, *found = ERR_PTR(-ENODEV);
29983d3f7c1eSHans de Goede 
29993d3f7c1eSHans de Goede 	if (!fwnode)
30003d3f7c1eSHans de Goede 		return ERR_PTR(-ENODEV);
30013d3f7c1eSHans de Goede 
30023d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
30033d3f7c1eSHans de Goede 
30043d3f7c1eSHans de Goede 	list_for_each_entry(connector, &connector_list, global_connector_list_entry) {
30053d3f7c1eSHans de Goede 		if (connector->fwnode == fwnode ||
30063d3f7c1eSHans de Goede 		    (connector->fwnode && connector->fwnode->secondary == fwnode)) {
30073d3f7c1eSHans de Goede 			drm_connector_get(connector);
30083d3f7c1eSHans de Goede 			found = connector;
30093d3f7c1eSHans de Goede 			break;
30103d3f7c1eSHans de Goede 		}
30113d3f7c1eSHans de Goede 	}
30123d3f7c1eSHans de Goede 
30133d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
30143d3f7c1eSHans de Goede 
30153d3f7c1eSHans de Goede 	return found;
30163d3f7c1eSHans de Goede }
30173d3f7c1eSHans de Goede 
301872ad4968SHans de Goede /**
301972ad4968SHans de Goede  * drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector
3020f85d9e59SRandy Dunlap  * @connector_fwnode: fwnode_handle to report the event on
302172ad4968SHans de Goede  *
302272ad4968SHans de Goede  * On some hardware a hotplug event notification may come from outside the display
302372ad4968SHans de Goede  * driver / device. An example of this is some USB Type-C setups where the hardware
302472ad4968SHans de Goede  * muxes the DisplayPort data and aux-lines but does not pass the altmode HPD
302572ad4968SHans de Goede  * status bit to the GPU's DP HPD pin.
302672ad4968SHans de Goede  *
302772ad4968SHans de Goede  * This function can be used to report these out-of-band events after obtaining
302872ad4968SHans de Goede  * a drm_connector reference through calling drm_connector_find_by_fwnode().
302972ad4968SHans de Goede  */
303072ad4968SHans de Goede void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode)
303172ad4968SHans de Goede {
303272ad4968SHans de Goede 	struct drm_connector *connector;
303372ad4968SHans de Goede 
303472ad4968SHans de Goede 	connector = drm_connector_find_by_fwnode(connector_fwnode);
303572ad4968SHans de Goede 	if (IS_ERR(connector))
303672ad4968SHans de Goede 		return;
303772ad4968SHans de Goede 
303872ad4968SHans de Goede 	if (connector->funcs->oob_hotplug_event)
303972ad4968SHans de Goede 		connector->funcs->oob_hotplug_event(connector);
304072ad4968SHans de Goede 
304172ad4968SHans de Goede 	drm_connector_put(connector);
304272ad4968SHans de Goede }
304372ad4968SHans de Goede EXPORT_SYMBOL(drm_connector_oob_hotplug_event);
304472ad4968SHans de Goede 
30459498c19bSDaniel Vetter 
30469498c19bSDaniel Vetter /**
30479498c19bSDaniel Vetter  * DOC: Tile group
30489498c19bSDaniel Vetter  *
30499498c19bSDaniel Vetter  * Tile groups are used to represent tiled monitors with a unique integer
30509498c19bSDaniel Vetter  * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
30519498c19bSDaniel Vetter  * we store this in a tile group, so we have a common identifier for all tiles
30529498c19bSDaniel Vetter  * in a monitor group. The property is called "TILE". Drivers can manage tile
30539498c19bSDaniel Vetter  * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
30549498c19bSDaniel Vetter  * drm_mode_get_tile_group(). But this is only needed for internal panels where
30559498c19bSDaniel Vetter  * the tile group information is exposed through a non-standard way.
30569498c19bSDaniel Vetter  */
30579498c19bSDaniel Vetter 
30589498c19bSDaniel Vetter static void drm_tile_group_free(struct kref *kref)
30599498c19bSDaniel Vetter {
30609498c19bSDaniel Vetter 	struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
30619498c19bSDaniel Vetter 	struct drm_device *dev = tg->dev;
3062948de842SSuraj Upadhyay 
30639498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
30649498c19bSDaniel Vetter 	idr_remove(&dev->mode_config.tile_idr, tg->id);
30659498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
30669498c19bSDaniel Vetter 	kfree(tg);
30679498c19bSDaniel Vetter }
30689498c19bSDaniel Vetter 
30699498c19bSDaniel Vetter /**
30709498c19bSDaniel Vetter  * drm_mode_put_tile_group - drop a reference to a tile group.
30719498c19bSDaniel Vetter  * @dev: DRM device
30729498c19bSDaniel Vetter  * @tg: tile group to drop reference to.
30739498c19bSDaniel Vetter  *
30749498c19bSDaniel Vetter  * drop reference to tile group and free if 0.
30759498c19bSDaniel Vetter  */
30769498c19bSDaniel Vetter void drm_mode_put_tile_group(struct drm_device *dev,
30779498c19bSDaniel Vetter 			     struct drm_tile_group *tg)
30789498c19bSDaniel Vetter {
30799498c19bSDaniel Vetter 	kref_put(&tg->refcount, drm_tile_group_free);
30809498c19bSDaniel Vetter }
30819498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_put_tile_group);
30829498c19bSDaniel Vetter 
30839498c19bSDaniel Vetter /**
30849498c19bSDaniel Vetter  * drm_mode_get_tile_group - get a reference to an existing tile group
30859498c19bSDaniel Vetter  * @dev: DRM device
30869498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
30879498c19bSDaniel Vetter  *
30889498c19bSDaniel Vetter  * Use the unique bytes to get a reference to an existing tile group.
30899498c19bSDaniel Vetter  *
30909498c19bSDaniel Vetter  * RETURNS:
30919498c19bSDaniel Vetter  * tile group or NULL if not found.
30929498c19bSDaniel Vetter  */
30939498c19bSDaniel Vetter struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
3094267ea759SVille Syrjälä 					       const char topology[8])
30959498c19bSDaniel Vetter {
30969498c19bSDaniel Vetter 	struct drm_tile_group *tg;
30979498c19bSDaniel Vetter 	int id;
3098948de842SSuraj Upadhyay 
30999498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
31009498c19bSDaniel Vetter 	idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
31019498c19bSDaniel Vetter 		if (!memcmp(tg->group_data, topology, 8)) {
31029498c19bSDaniel Vetter 			if (!kref_get_unless_zero(&tg->refcount))
31039498c19bSDaniel Vetter 				tg = NULL;
31049498c19bSDaniel Vetter 			mutex_unlock(&dev->mode_config.idr_mutex);
31059498c19bSDaniel Vetter 			return tg;
31069498c19bSDaniel Vetter 		}
31079498c19bSDaniel Vetter 	}
31089498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
31099498c19bSDaniel Vetter 	return NULL;
31109498c19bSDaniel Vetter }
31119498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_get_tile_group);
31129498c19bSDaniel Vetter 
31139498c19bSDaniel Vetter /**
31149498c19bSDaniel Vetter  * drm_mode_create_tile_group - create a tile group from a displayid description
31159498c19bSDaniel Vetter  * @dev: DRM device
31169498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
31179498c19bSDaniel Vetter  *
31189498c19bSDaniel Vetter  * Create a tile group for the unique monitor, and get a unique
31199498c19bSDaniel Vetter  * identifier for the tile group.
31209498c19bSDaniel Vetter  *
31219498c19bSDaniel Vetter  * RETURNS:
3122705c8160SDan Carpenter  * new tile group or NULL.
31239498c19bSDaniel Vetter  */
31249498c19bSDaniel Vetter struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
3125267ea759SVille Syrjälä 						  const char topology[8])
31269498c19bSDaniel Vetter {
31279498c19bSDaniel Vetter 	struct drm_tile_group *tg;
31289498c19bSDaniel Vetter 	int ret;
31299498c19bSDaniel Vetter 
31309498c19bSDaniel Vetter 	tg = kzalloc(sizeof(*tg), GFP_KERNEL);
31319498c19bSDaniel Vetter 	if (!tg)
3132705c8160SDan Carpenter 		return NULL;
31339498c19bSDaniel Vetter 
31349498c19bSDaniel Vetter 	kref_init(&tg->refcount);
31359498c19bSDaniel Vetter 	memcpy(tg->group_data, topology, 8);
31369498c19bSDaniel Vetter 	tg->dev = dev;
31379498c19bSDaniel Vetter 
31389498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
31399498c19bSDaniel Vetter 	ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
31409498c19bSDaniel Vetter 	if (ret >= 0) {
31419498c19bSDaniel Vetter 		tg->id = ret;
31429498c19bSDaniel Vetter 	} else {
31439498c19bSDaniel Vetter 		kfree(tg);
3144705c8160SDan Carpenter 		tg = NULL;
31459498c19bSDaniel Vetter 	}
31469498c19bSDaniel Vetter 
31479498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
31489498c19bSDaniel Vetter 	return tg;
31499498c19bSDaniel Vetter }
31509498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tile_group);
3151