xref: /linux/drivers/gpu/drm/drm_connector.c (revision c3292ab5fbd7045f019418b2ce1977891419ad28)
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 
3673289afeSVille Syrjälä #include <linux/fb.h>
3799f45e32SDaniel Vetter #include <linux/uaccess.h>
3852217195SDaniel Vetter 
3952217195SDaniel Vetter #include "drm_crtc_internal.h"
4052217195SDaniel Vetter #include "drm_internal.h"
4152217195SDaniel Vetter 
42ae2a6da8SDaniel Vetter /**
43ae2a6da8SDaniel Vetter  * DOC: overview
44ae2a6da8SDaniel Vetter  *
45ae2a6da8SDaniel Vetter  * In DRM connectors are the general abstraction for display sinks, and include
4684e543bcSAntonio Borneo  * also fixed panels or anything else that can display pixels in some form. As
47ae2a6da8SDaniel Vetter  * opposed to all other KMS objects representing hardware (like CRTC, encoder or
48ae2a6da8SDaniel Vetter  * plane abstractions) connectors can be hotplugged and unplugged at runtime.
49ad093607SThierry Reding  * Hence they are reference-counted using drm_connector_get() and
50ad093607SThierry Reding  * drm_connector_put().
51ae2a6da8SDaniel Vetter  *
52d574528aSDaniel Vetter  * KMS driver must create, initialize, register and attach at a &struct
53d574528aSDaniel Vetter  * drm_connector for each such sink. The instance is created as other KMS
54aec97460SDaniel Vetter  * objects and initialized by setting the following fields. The connector is
55aec97460SDaniel Vetter  * initialized with a call to drm_connector_init() with a pointer to the
56aec97460SDaniel Vetter  * &struct drm_connector_funcs and a connector type, and then exposed to
57aec97460SDaniel Vetter  * userspace with a call to drm_connector_register().
58ae2a6da8SDaniel Vetter  *
59ae2a6da8SDaniel Vetter  * Connectors must be attached to an encoder to be used. For devices that map
60ae2a6da8SDaniel Vetter  * connectors to encoders 1:1, the connector should be attached at
61cde4c44dSDaniel Vetter  * initialization time with a call to drm_connector_attach_encoder(). The
62d574528aSDaniel Vetter  * driver must also set the &drm_connector.encoder field to point to the
63ae2a6da8SDaniel Vetter  * attached encoder.
64ae2a6da8SDaniel Vetter  *
65ae2a6da8SDaniel Vetter  * For connectors which are not fixed (like built-in panels) the driver needs to
66ae2a6da8SDaniel Vetter  * support hotplug notifications. The simplest way to do that is by using the
67ae2a6da8SDaniel Vetter  * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
68ae2a6da8SDaniel Vetter  * hardware support for hotplug interrupts. Connectors with hardware hotplug
69ae2a6da8SDaniel Vetter  * support can instead use e.g. drm_helper_hpd_irq_event().
70ae2a6da8SDaniel Vetter  */
71ae2a6da8SDaniel Vetter 
723d3f7c1eSHans de Goede /*
733d3f7c1eSHans de Goede  * Global connector list for drm_connector_find_by_fwnode().
743d3f7c1eSHans de Goede  * Note drm_connector_[un]register() first take connector->lock and then
753d3f7c1eSHans de Goede  * take the connector_list_lock.
763d3f7c1eSHans de Goede  */
773d3f7c1eSHans de Goede static DEFINE_MUTEX(connector_list_lock);
783d3f7c1eSHans de Goede static LIST_HEAD(connector_list);
793d3f7c1eSHans de Goede 
8052217195SDaniel Vetter struct drm_conn_prop_enum_list {
8152217195SDaniel Vetter 	int type;
8252217195SDaniel Vetter 	const char *name;
8352217195SDaniel Vetter 	struct ida ida;
8452217195SDaniel Vetter };
8552217195SDaniel Vetter 
8652217195SDaniel Vetter /*
8752217195SDaniel Vetter  * Connector and encoder types.
8852217195SDaniel Vetter  */
8952217195SDaniel Vetter static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
9052217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Unknown, "Unknown" },
9152217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
9252217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
9352217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
9452217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
9552217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Composite, "Composite" },
9652217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
9752217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
9852217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_Component, "Component" },
9952217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
10052217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },
10152217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
10252217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
10352217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_TV, "TV" },
10452217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_eDP, "eDP" },
10552217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
10652217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DSI, "DSI" },
10752217195SDaniel Vetter 	{ DRM_MODE_CONNECTOR_DPI, "DPI" },
108935774cdSBrian Starkey 	{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
109fc06bf1dSNoralf Trønnes 	{ DRM_MODE_CONNECTOR_SPI, "SPI" },
110757e2671SNoralf Trønnes 	{ DRM_MODE_CONNECTOR_USB, "USB" },
11152217195SDaniel Vetter };
11252217195SDaniel Vetter 
11352217195SDaniel Vetter void drm_connector_ida_init(void)
11452217195SDaniel Vetter {
11552217195SDaniel Vetter 	int i;
11652217195SDaniel Vetter 
11752217195SDaniel Vetter 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
11852217195SDaniel Vetter 		ida_init(&drm_connector_enum_list[i].ida);
11952217195SDaniel Vetter }
12052217195SDaniel Vetter 
12152217195SDaniel Vetter void drm_connector_ida_destroy(void)
12252217195SDaniel Vetter {
12352217195SDaniel Vetter 	int i;
12452217195SDaniel Vetter 
12552217195SDaniel Vetter 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
12652217195SDaniel Vetter 		ida_destroy(&drm_connector_enum_list[i].ida);
12752217195SDaniel Vetter }
12852217195SDaniel Vetter 
12952217195SDaniel Vetter /**
130b35f90f2SLaurent Pinchart  * drm_get_connector_type_name - return a string for connector type
131b35f90f2SLaurent Pinchart  * @type: The connector type (DRM_MODE_CONNECTOR_*)
132b35f90f2SLaurent Pinchart  *
133b35f90f2SLaurent Pinchart  * Returns: the name of the connector type, or NULL if the type is not valid.
134b35f90f2SLaurent Pinchart  */
135b35f90f2SLaurent Pinchart const char *drm_get_connector_type_name(unsigned int type)
136b35f90f2SLaurent Pinchart {
137b35f90f2SLaurent Pinchart 	if (type < ARRAY_SIZE(drm_connector_enum_list))
138b35f90f2SLaurent Pinchart 		return drm_connector_enum_list[type].name;
139b35f90f2SLaurent Pinchart 
140b35f90f2SLaurent Pinchart 	return NULL;
141b35f90f2SLaurent Pinchart }
142b35f90f2SLaurent Pinchart EXPORT_SYMBOL(drm_get_connector_type_name);
143b35f90f2SLaurent Pinchart 
144b35f90f2SLaurent Pinchart /**
14552217195SDaniel Vetter  * drm_connector_get_cmdline_mode - reads the user's cmdline mode
14684e543bcSAntonio Borneo  * @connector: connector to query
14752217195SDaniel Vetter  *
148ae2a6da8SDaniel Vetter  * The kernel supports per-connector configuration of its consoles through
14952217195SDaniel Vetter  * use of the video= parameter. This function parses that option and
15052217195SDaniel Vetter  * extracts the user's specified mode (or enable/disable status) for a
15152217195SDaniel Vetter  * particular connector. This is typically only used during the early fbdev
15252217195SDaniel Vetter  * setup.
15352217195SDaniel Vetter  */
15452217195SDaniel Vetter static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
15552217195SDaniel Vetter {
15652217195SDaniel Vetter 	struct drm_cmdline_mode *mode = &connector->cmdline_mode;
15752217195SDaniel Vetter 	char *option = NULL;
15852217195SDaniel Vetter 
15952217195SDaniel Vetter 	if (fb_get_options(connector->name, &option))
16052217195SDaniel Vetter 		return;
16152217195SDaniel Vetter 
16252217195SDaniel Vetter 	if (!drm_mode_parse_command_line_for_connector(option,
16352217195SDaniel Vetter 						       connector,
16452217195SDaniel Vetter 						       mode))
16552217195SDaniel Vetter 		return;
16652217195SDaniel Vetter 
16752217195SDaniel Vetter 	if (mode->force) {
1686140cf20SJani Nikula 		DRM_INFO("forcing %s connector %s\n", connector->name,
1696140cf20SJani Nikula 			 drm_get_connector_force_name(mode->force));
17052217195SDaniel Vetter 		connector->force = mode->force;
17152217195SDaniel Vetter 	}
17252217195SDaniel Vetter 
1730980939dSHans de Goede 	if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) {
1740980939dSHans de Goede 		DRM_INFO("cmdline forces connector %s panel_orientation to %d\n",
1750980939dSHans de Goede 			 connector->name, mode->panel_orientation);
1760980939dSHans de Goede 		drm_connector_set_panel_orientation(connector,
1770980939dSHans de Goede 						    mode->panel_orientation);
1780980939dSHans de Goede 	}
1790980939dSHans de Goede 
1803aeeb13dSMaxime Ripard 	DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
18150b0946dSMaxime Ripard 		      connector->name, mode->name,
18252217195SDaniel Vetter 		      mode->xres, mode->yres,
18352217195SDaniel Vetter 		      mode->refresh_specified ? mode->refresh : 60,
18452217195SDaniel Vetter 		      mode->rb ? " reduced blanking" : "",
18552217195SDaniel Vetter 		      mode->margins ? " with margins" : "",
18652217195SDaniel Vetter 		      mode->interlace ?  " interlaced" : "");
18752217195SDaniel Vetter }
18852217195SDaniel Vetter 
18952217195SDaniel Vetter static void drm_connector_free(struct kref *kref)
19052217195SDaniel Vetter {
19152217195SDaniel Vetter 	struct drm_connector *connector =
19252217195SDaniel Vetter 		container_of(kref, struct drm_connector, base.refcount);
19352217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
19452217195SDaniel Vetter 
19552217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
19652217195SDaniel Vetter 	connector->funcs->destroy(connector);
19752217195SDaniel Vetter }
19852217195SDaniel Vetter 
199ea497bb9SDaniel Vetter void drm_connector_free_work_fn(struct work_struct *work)
200a703c550SDaniel Vetter {
201ea497bb9SDaniel Vetter 	struct drm_connector *connector, *n;
202ea497bb9SDaniel Vetter 	struct drm_device *dev =
203ea497bb9SDaniel Vetter 		container_of(work, struct drm_device, mode_config.connector_free_work);
204ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &dev->mode_config;
205ea497bb9SDaniel Vetter 	unsigned long flags;
206ea497bb9SDaniel Vetter 	struct llist_node *freed;
207a703c550SDaniel Vetter 
208ea497bb9SDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
209ea497bb9SDaniel Vetter 	freed = llist_del_all(&config->connector_free_list);
210ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
211ea497bb9SDaniel Vetter 
212ea497bb9SDaniel Vetter 	llist_for_each_entry_safe(connector, n, freed, free_node) {
213a703c550SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
214a703c550SDaniel Vetter 		connector->funcs->destroy(connector);
215a703c550SDaniel Vetter 	}
216ea497bb9SDaniel Vetter }
217a703c550SDaniel Vetter 
218b11af8a2SMaxime Ripard static int __drm_connector_init(struct drm_device *dev,
21952217195SDaniel Vetter 				struct drm_connector *connector,
22052217195SDaniel Vetter 				const struct drm_connector_funcs *funcs,
221b11af8a2SMaxime Ripard 				int connector_type,
222b11af8a2SMaxime Ripard 				struct i2c_adapter *ddc)
22352217195SDaniel Vetter {
22452217195SDaniel Vetter 	struct drm_mode_config *config = &dev->mode_config;
22552217195SDaniel Vetter 	int ret;
22652217195SDaniel Vetter 	struct ida *connector_ida =
22752217195SDaniel Vetter 		&drm_connector_enum_list[connector_type].ida;
22852217195SDaniel Vetter 
229ba1f665fSHaneen Mohammed 	WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
230ba1f665fSHaneen Mohammed 		(!funcs->atomic_destroy_state ||
231ba1f665fSHaneen Mohammed 		 !funcs->atomic_duplicate_state));
232ba1f665fSHaneen Mohammed 
2332135ea7aSThierry Reding 	ret = __drm_mode_object_add(dev, &connector->base,
23452217195SDaniel Vetter 				    DRM_MODE_OBJECT_CONNECTOR,
23552217195SDaniel Vetter 				    false, drm_connector_free);
23652217195SDaniel Vetter 	if (ret)
237613051daSDaniel Vetter 		return ret;
23852217195SDaniel Vetter 
23952217195SDaniel Vetter 	connector->base.properties = &connector->properties;
24052217195SDaniel Vetter 	connector->dev = dev;
24152217195SDaniel Vetter 	connector->funcs = funcs;
24252217195SDaniel Vetter 
2432a8d3eacSVille Syrjälä 	/* connector index is used with 32bit bitmasks */
244e5d6eeeaSBo Liu 	ret = ida_alloc_max(&config->connector_ida, 31, GFP_KERNEL);
2452a8d3eacSVille Syrjälä 	if (ret < 0) {
2462a8d3eacSVille Syrjälä 		DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
2472a8d3eacSVille Syrjälä 			      drm_connector_enum_list[connector_type].name,
2482a8d3eacSVille Syrjälä 			      ret);
24952217195SDaniel Vetter 		goto out_put;
2502a8d3eacSVille Syrjälä 	}
25152217195SDaniel Vetter 	connector->index = ret;
25252217195SDaniel Vetter 	ret = 0;
25352217195SDaniel Vetter 
25452217195SDaniel Vetter 	connector->connector_type = connector_type;
25552217195SDaniel Vetter 	connector->connector_type_id =
256e5d6eeeaSBo Liu 		ida_alloc_min(connector_ida, 1, GFP_KERNEL);
25752217195SDaniel Vetter 	if (connector->connector_type_id < 0) {
25852217195SDaniel Vetter 		ret = connector->connector_type_id;
25952217195SDaniel Vetter 		goto out_put_id;
26052217195SDaniel Vetter 	}
26152217195SDaniel Vetter 	connector->name =
26252217195SDaniel Vetter 		kasprintf(GFP_KERNEL, "%s-%d",
26352217195SDaniel Vetter 			  drm_connector_enum_list[connector_type].name,
26452217195SDaniel Vetter 			  connector->connector_type_id);
26552217195SDaniel Vetter 	if (!connector->name) {
26652217195SDaniel Vetter 		ret = -ENOMEM;
26752217195SDaniel Vetter 		goto out_put_type_id;
26852217195SDaniel Vetter 	}
26952217195SDaniel Vetter 
270b11af8a2SMaxime Ripard 	/* provide ddc symlink in sysfs */
271b11af8a2SMaxime Ripard 	connector->ddc = ddc;
272b11af8a2SMaxime Ripard 
2733d3f7c1eSHans de Goede 	INIT_LIST_HEAD(&connector->global_connector_list_entry);
27452217195SDaniel Vetter 	INIT_LIST_HEAD(&connector->probed_modes);
27552217195SDaniel Vetter 	INIT_LIST_HEAD(&connector->modes);
276e73ab00eSDaniel Vetter 	mutex_init(&connector->mutex);
27790b575f5SJani Nikula 	mutex_init(&connector->edid_override_mutex);
27852217195SDaniel Vetter 	connector->edid_blob_ptr = NULL;
2795186421cSStanislav Lisovskiy 	connector->epoch_counter = 0;
2802de3a078SManasi Navare 	connector->tile_blob_ptr = NULL;
28152217195SDaniel Vetter 	connector->status = connector_status_unknown;
2828d70f395SHans de Goede 	connector->display_info.panel_orientation =
2838d70f395SHans de Goede 		DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
28452217195SDaniel Vetter 
28552217195SDaniel Vetter 	drm_connector_get_cmdline_mode(connector);
28652217195SDaniel Vetter 
28752217195SDaniel Vetter 	/* We should add connectors at the end to avoid upsetting the connector
288c2ce66daSBeatriz Martins de Carvalho 	 * index too much.
289c2ce66daSBeatriz Martins de Carvalho 	 */
290613051daSDaniel Vetter 	spin_lock_irq(&config->connector_list_lock);
29152217195SDaniel Vetter 	list_add_tail(&connector->head, &config->connector_list);
29252217195SDaniel Vetter 	config->num_connector++;
293613051daSDaniel Vetter 	spin_unlock_irq(&config->connector_list_lock);
29452217195SDaniel Vetter 
295935774cdSBrian Starkey 	if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
296935774cdSBrian Starkey 	    connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
2976b7e2d5cSGerd Hoffmann 		drm_connector_attach_edid_property(connector);
29852217195SDaniel Vetter 
29952217195SDaniel Vetter 	drm_object_attach_property(&connector->base,
30052217195SDaniel Vetter 				      config->dpms_property, 0);
30152217195SDaniel Vetter 
30240ee6fbeSManasi Navare 	drm_object_attach_property(&connector->base,
30340ee6fbeSManasi Navare 				   config->link_status_property,
30440ee6fbeSManasi Navare 				   0);
30540ee6fbeSManasi Navare 
30666660d4cSDave Airlie 	drm_object_attach_property(&connector->base,
30766660d4cSDave Airlie 				   config->non_desktop_property,
30866660d4cSDave Airlie 				   0);
3092de3a078SManasi Navare 	drm_object_attach_property(&connector->base,
3102de3a078SManasi Navare 				   config->tile_property,
3112de3a078SManasi Navare 				   0);
31266660d4cSDave Airlie 
31352217195SDaniel Vetter 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
31452217195SDaniel Vetter 		drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
31552217195SDaniel Vetter 	}
31652217195SDaniel Vetter 
31752217195SDaniel Vetter 	connector->debugfs_entry = NULL;
31852217195SDaniel Vetter out_put_type_id:
31952217195SDaniel Vetter 	if (ret)
320e5d6eeeaSBo Liu 		ida_free(connector_ida, connector->connector_type_id);
32152217195SDaniel Vetter out_put_id:
32252217195SDaniel Vetter 	if (ret)
323e5d6eeeaSBo Liu 		ida_free(&config->connector_ida, connector->index);
32452217195SDaniel Vetter out_put:
32552217195SDaniel Vetter 	if (ret)
32652217195SDaniel Vetter 		drm_mode_object_unregister(dev, &connector->base);
32752217195SDaniel Vetter 
32852217195SDaniel Vetter 	return ret;
32952217195SDaniel Vetter }
330b11af8a2SMaxime Ripard 
331b11af8a2SMaxime Ripard /**
332b11af8a2SMaxime Ripard  * drm_connector_init - Init a preallocated connector
333b11af8a2SMaxime Ripard  * @dev: DRM device
334b11af8a2SMaxime Ripard  * @connector: the connector to init
335b11af8a2SMaxime Ripard  * @funcs: callbacks for this connector
336b11af8a2SMaxime Ripard  * @connector_type: user visible type of the connector
337b11af8a2SMaxime Ripard  *
338b11af8a2SMaxime Ripard  * Initialises a preallocated connector. Connectors should be
339b11af8a2SMaxime Ripard  * subclassed as part of driver connector objects.
340b11af8a2SMaxime Ripard  *
341b11af8a2SMaxime Ripard  * At driver unload time the driver's &drm_connector_funcs.destroy hook
342b11af8a2SMaxime Ripard  * should call drm_connector_cleanup() and free the connector structure.
343b11af8a2SMaxime Ripard  * The connector structure should not be allocated with devm_kzalloc().
344b11af8a2SMaxime Ripard  *
34535a3b82fSMaxime Ripard  * Note: consider using drmm_connector_init() instead of
34635a3b82fSMaxime Ripard  * drm_connector_init() to let the DRM managed resource infrastructure
34735a3b82fSMaxime Ripard  * take care of cleanup and deallocation.
34835a3b82fSMaxime Ripard  *
349b11af8a2SMaxime Ripard  * Returns:
350b11af8a2SMaxime Ripard  * Zero on success, error code on failure.
351b11af8a2SMaxime Ripard  */
352b11af8a2SMaxime Ripard int drm_connector_init(struct drm_device *dev,
353b11af8a2SMaxime Ripard 		       struct drm_connector *connector,
354b11af8a2SMaxime Ripard 		       const struct drm_connector_funcs *funcs,
355b11af8a2SMaxime Ripard 		       int connector_type)
356b11af8a2SMaxime Ripard {
357a961b197SMaxime Ripard 	if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
358a961b197SMaxime Ripard 		return -EINVAL;
359a961b197SMaxime Ripard 
360b11af8a2SMaxime Ripard 	return __drm_connector_init(dev, connector, funcs, connector_type, NULL);
361b11af8a2SMaxime Ripard }
36252217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_init);
36352217195SDaniel Vetter 
36452217195SDaniel Vetter /**
365100163dfSAndrzej Pietrasiewicz  * drm_connector_init_with_ddc - Init a preallocated connector
366100163dfSAndrzej Pietrasiewicz  * @dev: DRM device
367100163dfSAndrzej Pietrasiewicz  * @connector: the connector to init
368100163dfSAndrzej Pietrasiewicz  * @funcs: callbacks for this connector
369100163dfSAndrzej Pietrasiewicz  * @connector_type: user visible type of the connector
370100163dfSAndrzej Pietrasiewicz  * @ddc: pointer to the associated ddc adapter
371100163dfSAndrzej Pietrasiewicz  *
372100163dfSAndrzej Pietrasiewicz  * Initialises a preallocated connector. Connectors should be
373100163dfSAndrzej Pietrasiewicz  * subclassed as part of driver connector objects.
374100163dfSAndrzej Pietrasiewicz  *
37500ec947cSMaxime Ripard  * At driver unload time the driver's &drm_connector_funcs.destroy hook
37600ec947cSMaxime Ripard  * should call drm_connector_cleanup() and free the connector structure.
37700ec947cSMaxime Ripard  * The connector structure should not be allocated with devm_kzalloc().
37800ec947cSMaxime Ripard  *
379100163dfSAndrzej Pietrasiewicz  * Ensures that the ddc field of the connector is correctly set.
380100163dfSAndrzej Pietrasiewicz  *
38135a3b82fSMaxime Ripard  * Note: consider using drmm_connector_init() instead of
38235a3b82fSMaxime Ripard  * drm_connector_init_with_ddc() to let the DRM managed resource
38335a3b82fSMaxime Ripard  * infrastructure take care of cleanup and deallocation.
38435a3b82fSMaxime Ripard  *
385100163dfSAndrzej Pietrasiewicz  * Returns:
386100163dfSAndrzej Pietrasiewicz  * Zero on success, error code on failure.
387100163dfSAndrzej Pietrasiewicz  */
388100163dfSAndrzej Pietrasiewicz int drm_connector_init_with_ddc(struct drm_device *dev,
389100163dfSAndrzej Pietrasiewicz 				struct drm_connector *connector,
390100163dfSAndrzej Pietrasiewicz 				const struct drm_connector_funcs *funcs,
391100163dfSAndrzej Pietrasiewicz 				int connector_type,
392100163dfSAndrzej Pietrasiewicz 				struct i2c_adapter *ddc)
393100163dfSAndrzej Pietrasiewicz {
394a961b197SMaxime Ripard 	if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
395a961b197SMaxime Ripard 		return -EINVAL;
396a961b197SMaxime Ripard 
397b11af8a2SMaxime Ripard 	return __drm_connector_init(dev, connector, funcs, connector_type, ddc);
398100163dfSAndrzej Pietrasiewicz }
399100163dfSAndrzej Pietrasiewicz EXPORT_SYMBOL(drm_connector_init_with_ddc);
400100163dfSAndrzej Pietrasiewicz 
40135a3b82fSMaxime Ripard static void drm_connector_cleanup_action(struct drm_device *dev,
40235a3b82fSMaxime Ripard 					 void *ptr)
40335a3b82fSMaxime Ripard {
40435a3b82fSMaxime Ripard 	struct drm_connector *connector = ptr;
40535a3b82fSMaxime Ripard 
40635a3b82fSMaxime Ripard 	drm_connector_cleanup(connector);
40735a3b82fSMaxime Ripard }
40835a3b82fSMaxime Ripard 
40935a3b82fSMaxime Ripard /**
41035a3b82fSMaxime Ripard  * drmm_connector_init - Init a preallocated connector
41135a3b82fSMaxime Ripard  * @dev: DRM device
41235a3b82fSMaxime Ripard  * @connector: the connector to init
41335a3b82fSMaxime Ripard  * @funcs: callbacks for this connector
41435a3b82fSMaxime Ripard  * @connector_type: user visible type of the connector
41535a3b82fSMaxime Ripard  * @ddc: optional pointer to the associated ddc adapter
41635a3b82fSMaxime Ripard  *
41735a3b82fSMaxime Ripard  * Initialises a preallocated connector. Connectors should be
41835a3b82fSMaxime Ripard  * subclassed as part of driver connector objects.
41935a3b82fSMaxime Ripard  *
42035a3b82fSMaxime Ripard  * Cleanup is automatically handled with a call to
42135a3b82fSMaxime Ripard  * drm_connector_cleanup() in a DRM-managed action.
42235a3b82fSMaxime Ripard  *
42335a3b82fSMaxime Ripard  * The connector structure should be allocated with drmm_kzalloc().
42435a3b82fSMaxime Ripard  *
42535a3b82fSMaxime Ripard  * Returns:
42635a3b82fSMaxime Ripard  * Zero on success, error code on failure.
42735a3b82fSMaxime Ripard  */
42835a3b82fSMaxime Ripard int drmm_connector_init(struct drm_device *dev,
42935a3b82fSMaxime Ripard 			struct drm_connector *connector,
43035a3b82fSMaxime Ripard 			const struct drm_connector_funcs *funcs,
43135a3b82fSMaxime Ripard 			int connector_type,
43235a3b82fSMaxime Ripard 			struct i2c_adapter *ddc)
43335a3b82fSMaxime Ripard {
43435a3b82fSMaxime Ripard 	int ret;
43535a3b82fSMaxime Ripard 
43635a3b82fSMaxime Ripard 	if (drm_WARN_ON(dev, funcs && funcs->destroy))
43735a3b82fSMaxime Ripard 		return -EINVAL;
43835a3b82fSMaxime Ripard 
439a91e5e3eSMaxime Ripard 	ret = __drm_connector_init(dev, connector, funcs, connector_type, ddc);
44035a3b82fSMaxime Ripard 	if (ret)
44135a3b82fSMaxime Ripard 		return ret;
44235a3b82fSMaxime Ripard 
44335a3b82fSMaxime Ripard 	ret = drmm_add_action_or_reset(dev, drm_connector_cleanup_action,
44435a3b82fSMaxime Ripard 				       connector);
44535a3b82fSMaxime Ripard 	if (ret)
44635a3b82fSMaxime Ripard 		return ret;
44735a3b82fSMaxime Ripard 
44835a3b82fSMaxime Ripard 	return 0;
44935a3b82fSMaxime Ripard }
45035a3b82fSMaxime Ripard EXPORT_SYMBOL(drmm_connector_init);
45135a3b82fSMaxime Ripard 
452100163dfSAndrzej Pietrasiewicz /**
4536b7e2d5cSGerd Hoffmann  * drm_connector_attach_edid_property - attach edid property.
4546b7e2d5cSGerd Hoffmann  * @connector: the connector
4556b7e2d5cSGerd Hoffmann  *
4566b7e2d5cSGerd Hoffmann  * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
4576b7e2d5cSGerd Hoffmann  * edid property attached by default.  This function can be used to
4586b7e2d5cSGerd Hoffmann  * explicitly enable the edid property in these cases.
4596b7e2d5cSGerd Hoffmann  */
4606b7e2d5cSGerd Hoffmann void drm_connector_attach_edid_property(struct drm_connector *connector)
4616b7e2d5cSGerd Hoffmann {
4626b7e2d5cSGerd Hoffmann 	struct drm_mode_config *config = &connector->dev->mode_config;
4636b7e2d5cSGerd Hoffmann 
4646b7e2d5cSGerd Hoffmann 	drm_object_attach_property(&connector->base,
4656b7e2d5cSGerd Hoffmann 				   config->edid_property,
4666b7e2d5cSGerd Hoffmann 				   0);
4676b7e2d5cSGerd Hoffmann }
4686b7e2d5cSGerd Hoffmann EXPORT_SYMBOL(drm_connector_attach_edid_property);
4696b7e2d5cSGerd Hoffmann 
4706b7e2d5cSGerd Hoffmann /**
471cde4c44dSDaniel Vetter  * drm_connector_attach_encoder - attach a connector to an encoder
47252217195SDaniel Vetter  * @connector: connector to attach
47352217195SDaniel Vetter  * @encoder: encoder to attach @connector to
47452217195SDaniel Vetter  *
47552217195SDaniel Vetter  * This function links up a connector to an encoder. Note that the routing
47652217195SDaniel Vetter  * restrictions between encoders and crtcs are exposed to userspace through the
47752217195SDaniel Vetter  * possible_clones and possible_crtcs bitmasks.
47852217195SDaniel Vetter  *
47952217195SDaniel Vetter  * Returns:
48052217195SDaniel Vetter  * Zero on success, negative errno on failure.
48152217195SDaniel Vetter  */
482cde4c44dSDaniel Vetter int drm_connector_attach_encoder(struct drm_connector *connector,
48352217195SDaniel Vetter 				 struct drm_encoder *encoder)
48452217195SDaniel Vetter {
48552217195SDaniel Vetter 	/*
48652217195SDaniel Vetter 	 * In the past, drivers have attempted to model the static association
48752217195SDaniel Vetter 	 * of connector to encoder in simple connector/encoder devices using a
48852217195SDaniel Vetter 	 * direct assignment of connector->encoder = encoder. This connection
48952217195SDaniel Vetter 	 * is a logical one and the responsibility of the core, so drivers are
49052217195SDaniel Vetter 	 * expected not to mess with this.
49152217195SDaniel Vetter 	 *
49252217195SDaniel Vetter 	 * Note that the error return should've been enough here, but a large
49352217195SDaniel Vetter 	 * majority of drivers ignores the return value, so add in a big WARN
49452217195SDaniel Vetter 	 * to get people's attention.
49552217195SDaniel Vetter 	 */
49652217195SDaniel Vetter 	if (WARN_ON(connector->encoder))
49752217195SDaniel Vetter 		return -EINVAL;
49852217195SDaniel Vetter 
49962afb4adSJosé Roberto de Souza 	connector->possible_encoders |= drm_encoder_mask(encoder);
50062afb4adSJosé Roberto de Souza 
50152217195SDaniel Vetter 	return 0;
50252217195SDaniel Vetter }
503cde4c44dSDaniel Vetter EXPORT_SYMBOL(drm_connector_attach_encoder);
50452217195SDaniel Vetter 
50538cb8d96SVille Syrjälä /**
50662afb4adSJosé Roberto de Souza  * drm_connector_has_possible_encoder - check if the connector and encoder are
50762afb4adSJosé Roberto de Souza  * associated with each other
50838cb8d96SVille Syrjälä  * @connector: the connector
50938cb8d96SVille Syrjälä  * @encoder: the encoder
51038cb8d96SVille Syrjälä  *
51138cb8d96SVille Syrjälä  * Returns:
51238cb8d96SVille Syrjälä  * True if @encoder is one of the possible encoders for @connector.
51338cb8d96SVille Syrjälä  */
51438cb8d96SVille Syrjälä bool drm_connector_has_possible_encoder(struct drm_connector *connector,
51538cb8d96SVille Syrjälä 					struct drm_encoder *encoder)
51638cb8d96SVille Syrjälä {
51762afb4adSJosé Roberto de Souza 	return connector->possible_encoders & drm_encoder_mask(encoder);
51838cb8d96SVille Syrjälä }
51938cb8d96SVille Syrjälä EXPORT_SYMBOL(drm_connector_has_possible_encoder);
52038cb8d96SVille Syrjälä 
52152217195SDaniel Vetter static void drm_mode_remove(struct drm_connector *connector,
52252217195SDaniel Vetter 			    struct drm_display_mode *mode)
52352217195SDaniel Vetter {
52452217195SDaniel Vetter 	list_del(&mode->head);
52552217195SDaniel Vetter 	drm_mode_destroy(connector->dev, mode);
52652217195SDaniel Vetter }
52752217195SDaniel Vetter 
52852217195SDaniel Vetter /**
52952217195SDaniel Vetter  * drm_connector_cleanup - cleans up an initialised connector
53052217195SDaniel Vetter  * @connector: connector to cleanup
53152217195SDaniel Vetter  *
53252217195SDaniel Vetter  * Cleans up the connector but doesn't free the object.
53352217195SDaniel Vetter  */
53452217195SDaniel Vetter void drm_connector_cleanup(struct drm_connector *connector)
53552217195SDaniel Vetter {
53652217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
53752217195SDaniel Vetter 	struct drm_display_mode *mode, *t;
53852217195SDaniel Vetter 
53952217195SDaniel Vetter 	/* The connector should have been removed from userspace long before
54052217195SDaniel Vetter 	 * it is finally destroyed.
54152217195SDaniel Vetter 	 */
54239b50c60SLyude Paul 	if (WARN_ON(connector->registration_state ==
54339b50c60SLyude Paul 		    DRM_CONNECTOR_REGISTERED))
54452217195SDaniel Vetter 		drm_connector_unregister(connector);
54552217195SDaniel Vetter 
546334f74eeSHans de Goede 	if (connector->privacy_screen) {
547334f74eeSHans de Goede 		drm_privacy_screen_put(connector->privacy_screen);
548334f74eeSHans de Goede 		connector->privacy_screen = NULL;
549334f74eeSHans de Goede 	}
550334f74eeSHans de Goede 
55152217195SDaniel Vetter 	if (connector->tile_group) {
55252217195SDaniel Vetter 		drm_mode_put_tile_group(dev, connector->tile_group);
55352217195SDaniel Vetter 		connector->tile_group = NULL;
55452217195SDaniel Vetter 	}
55552217195SDaniel Vetter 
55652217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
55752217195SDaniel Vetter 		drm_mode_remove(connector, mode);
55852217195SDaniel Vetter 
55952217195SDaniel Vetter 	list_for_each_entry_safe(mode, t, &connector->modes, head)
56052217195SDaniel Vetter 		drm_mode_remove(connector, mode);
56152217195SDaniel Vetter 
562e5d6eeeaSBo Liu 	ida_free(&drm_connector_enum_list[connector->connector_type].ida,
56352217195SDaniel Vetter 			  connector->connector_type_id);
56452217195SDaniel Vetter 
565e5d6eeeaSBo Liu 	ida_free(&dev->mode_config.connector_ida, connector->index);
56652217195SDaniel Vetter 
56752217195SDaniel Vetter 	kfree(connector->display_info.bus_formats);
568*c3292ab5SJani Nikula 	kfree(connector->display_info.vics);
56952217195SDaniel Vetter 	drm_mode_object_unregister(dev, &connector->base);
57052217195SDaniel Vetter 	kfree(connector->name);
57152217195SDaniel Vetter 	connector->name = NULL;
57248c429c6SHans de Goede 	fwnode_handle_put(connector->fwnode);
57348c429c6SHans de Goede 	connector->fwnode = NULL;
574613051daSDaniel Vetter 	spin_lock_irq(&dev->mode_config.connector_list_lock);
57552217195SDaniel Vetter 	list_del(&connector->head);
57652217195SDaniel Vetter 	dev->mode_config.num_connector--;
577613051daSDaniel Vetter 	spin_unlock_irq(&dev->mode_config.connector_list_lock);
57852217195SDaniel Vetter 
57952217195SDaniel Vetter 	WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
58052217195SDaniel Vetter 	if (connector->state && connector->funcs->atomic_destroy_state)
58152217195SDaniel Vetter 		connector->funcs->atomic_destroy_state(connector,
58252217195SDaniel Vetter 						       connector->state);
58352217195SDaniel Vetter 
584e73ab00eSDaniel Vetter 	mutex_destroy(&connector->mutex);
585e73ab00eSDaniel Vetter 
58652217195SDaniel Vetter 	memset(connector, 0, sizeof(*connector));
5876fdc2d49SSimon Ser 
5886fdc2d49SSimon Ser 	if (dev->registered)
5896fdc2d49SSimon Ser 		drm_sysfs_hotplug_event(dev);
59052217195SDaniel Vetter }
59152217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_cleanup);
59252217195SDaniel Vetter 
59352217195SDaniel Vetter /**
59452217195SDaniel Vetter  * drm_connector_register - register a connector
59552217195SDaniel Vetter  * @connector: the connector to register
59652217195SDaniel Vetter  *
59769b22f51SDaniel Vetter  * Register userspace interfaces for a connector. Only call this for connectors
59869b22f51SDaniel Vetter  * which can be hotplugged after drm_dev_register() has been called already,
59969b22f51SDaniel Vetter  * e.g. DP MST connectors. All other connectors will be registered automatically
60069b22f51SDaniel Vetter  * when calling drm_dev_register().
60152217195SDaniel Vetter  *
602d87fbea5SMaxime Ripard  * When the connector is no longer available, callers must call
603d87fbea5SMaxime Ripard  * drm_connector_unregister().
604d87fbea5SMaxime Ripard  *
60552217195SDaniel Vetter  * Returns:
60652217195SDaniel Vetter  * Zero on success, error code on failure.
60752217195SDaniel Vetter  */
60852217195SDaniel Vetter int drm_connector_register(struct drm_connector *connector)
60952217195SDaniel Vetter {
610e73ab00eSDaniel Vetter 	int ret = 0;
61152217195SDaniel Vetter 
612e6e7b48bSDaniel Vetter 	if (!connector->dev->registered)
613e6e7b48bSDaniel Vetter 		return 0;
614e6e7b48bSDaniel Vetter 
615e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
61639b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
617e73ab00eSDaniel Vetter 		goto unlock;
61852217195SDaniel Vetter 
61952217195SDaniel Vetter 	ret = drm_sysfs_connector_add(connector);
62052217195SDaniel Vetter 	if (ret)
621e73ab00eSDaniel Vetter 		goto unlock;
62252217195SDaniel Vetter 
623b792e640SGreg Kroah-Hartman 	drm_debugfs_connector_add(connector);
62452217195SDaniel Vetter 
62552217195SDaniel Vetter 	if (connector->funcs->late_register) {
62652217195SDaniel Vetter 		ret = connector->funcs->late_register(connector);
62752217195SDaniel Vetter 		if (ret)
62852217195SDaniel Vetter 			goto err_debugfs;
62952217195SDaniel Vetter 	}
63052217195SDaniel Vetter 
63152217195SDaniel Vetter 	drm_mode_object_register(connector->dev, &connector->base);
63252217195SDaniel Vetter 
63339b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_REGISTERED;
634968d81a6SJeykumar Sankaran 
635968d81a6SJeykumar Sankaran 	/* Let userspace know we have a new connector */
636ad935754SSimon Ser 	drm_sysfs_connector_hotplug_event(connector);
637968d81a6SJeykumar Sankaran 
638334f74eeSHans de Goede 	if (connector->privacy_screen)
639334f74eeSHans de Goede 		drm_privacy_screen_register_notifier(connector->privacy_screen,
640334f74eeSHans de Goede 					   &connector->privacy_screen_notifier);
641334f74eeSHans de Goede 
6423d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
6433d3f7c1eSHans de Goede 	list_add_tail(&connector->global_connector_list_entry, &connector_list);
6443d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
645e73ab00eSDaniel Vetter 	goto unlock;
64652217195SDaniel Vetter 
64752217195SDaniel Vetter err_debugfs:
64852217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
64952217195SDaniel Vetter 	drm_sysfs_connector_remove(connector);
650e73ab00eSDaniel Vetter unlock:
651e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
65252217195SDaniel Vetter 	return ret;
65352217195SDaniel Vetter }
65452217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_register);
65552217195SDaniel Vetter 
65652217195SDaniel Vetter /**
65752217195SDaniel Vetter  * drm_connector_unregister - unregister a connector
65852217195SDaniel Vetter  * @connector: the connector to unregister
65952217195SDaniel Vetter  *
66069b22f51SDaniel Vetter  * Unregister userspace interfaces for a connector. Only call this for
661d87fbea5SMaxime Ripard  * connectors which have been registered explicitly by calling
662d87fbea5SMaxime Ripard  * drm_connector_register().
66352217195SDaniel Vetter  */
66452217195SDaniel Vetter void drm_connector_unregister(struct drm_connector *connector)
66552217195SDaniel Vetter {
666e73ab00eSDaniel Vetter 	mutex_lock(&connector->mutex);
66739b50c60SLyude Paul 	if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
668e73ab00eSDaniel Vetter 		mutex_unlock(&connector->mutex);
66952217195SDaniel Vetter 		return;
670e73ab00eSDaniel Vetter 	}
67152217195SDaniel Vetter 
6723d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
6733d3f7c1eSHans de Goede 	list_del_init(&connector->global_connector_list_entry);
6743d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
6753d3f7c1eSHans de Goede 
676334f74eeSHans de Goede 	if (connector->privacy_screen)
677334f74eeSHans de Goede 		drm_privacy_screen_unregister_notifier(
678334f74eeSHans de Goede 					connector->privacy_screen,
679334f74eeSHans de Goede 					&connector->privacy_screen_notifier);
680334f74eeSHans de Goede 
68152217195SDaniel Vetter 	if (connector->funcs->early_unregister)
68252217195SDaniel Vetter 		connector->funcs->early_unregister(connector);
68352217195SDaniel Vetter 
68452217195SDaniel Vetter 	drm_sysfs_connector_remove(connector);
68552217195SDaniel Vetter 	drm_debugfs_connector_remove(connector);
68652217195SDaniel Vetter 
68739b50c60SLyude Paul 	connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
688e73ab00eSDaniel Vetter 	mutex_unlock(&connector->mutex);
68952217195SDaniel Vetter }
69052217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_unregister);
69152217195SDaniel Vetter 
69252217195SDaniel Vetter void drm_connector_unregister_all(struct drm_device *dev)
69352217195SDaniel Vetter {
69452217195SDaniel Vetter 	struct drm_connector *connector;
695613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
69652217195SDaniel Vetter 
697b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
698613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter)
69952217195SDaniel Vetter 		drm_connector_unregister(connector);
700b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
70152217195SDaniel Vetter }
70252217195SDaniel Vetter 
70352217195SDaniel Vetter int drm_connector_register_all(struct drm_device *dev)
70452217195SDaniel Vetter {
70552217195SDaniel Vetter 	struct drm_connector *connector;
706613051daSDaniel Vetter 	struct drm_connector_list_iter conn_iter;
707613051daSDaniel Vetter 	int ret = 0;
70852217195SDaniel Vetter 
709b982dab1SThierry Reding 	drm_connector_list_iter_begin(dev, &conn_iter);
710613051daSDaniel Vetter 	drm_for_each_connector_iter(connector, &conn_iter) {
71152217195SDaniel Vetter 		ret = drm_connector_register(connector);
71252217195SDaniel Vetter 		if (ret)
713613051daSDaniel Vetter 			break;
71452217195SDaniel Vetter 	}
715b982dab1SThierry Reding 	drm_connector_list_iter_end(&conn_iter);
71652217195SDaniel Vetter 
717613051daSDaniel Vetter 	if (ret)
71852217195SDaniel Vetter 		drm_connector_unregister_all(dev);
71952217195SDaniel Vetter 	return ret;
72052217195SDaniel Vetter }
72152217195SDaniel Vetter 
72252217195SDaniel Vetter /**
72352217195SDaniel Vetter  * drm_get_connector_status_name - return a string for connector status
72452217195SDaniel Vetter  * @status: connector status to compute name of
72552217195SDaniel Vetter  *
72652217195SDaniel Vetter  * In contrast to the other drm_get_*_name functions this one here returns a
72752217195SDaniel Vetter  * const pointer and hence is threadsafe.
728f85d9e59SRandy Dunlap  *
729f85d9e59SRandy Dunlap  * Returns: connector status string
73052217195SDaniel Vetter  */
73152217195SDaniel Vetter const char *drm_get_connector_status_name(enum drm_connector_status status)
73252217195SDaniel Vetter {
73352217195SDaniel Vetter 	if (status == connector_status_connected)
73452217195SDaniel Vetter 		return "connected";
73552217195SDaniel Vetter 	else if (status == connector_status_disconnected)
73652217195SDaniel Vetter 		return "disconnected";
73752217195SDaniel Vetter 	else
73852217195SDaniel Vetter 		return "unknown";
73952217195SDaniel Vetter }
74052217195SDaniel Vetter EXPORT_SYMBOL(drm_get_connector_status_name);
74152217195SDaniel Vetter 
7426140cf20SJani Nikula /**
7436140cf20SJani Nikula  * drm_get_connector_force_name - return a string for connector force
7446140cf20SJani Nikula  * @force: connector force to get name of
7456140cf20SJani Nikula  *
7466140cf20SJani Nikula  * Returns: const pointer to name.
7476140cf20SJani Nikula  */
7486140cf20SJani Nikula const char *drm_get_connector_force_name(enum drm_connector_force force)
7496140cf20SJani Nikula {
7506140cf20SJani Nikula 	switch (force) {
7516140cf20SJani Nikula 	case DRM_FORCE_UNSPECIFIED:
7526140cf20SJani Nikula 		return "unspecified";
7536140cf20SJani Nikula 	case DRM_FORCE_OFF:
7546140cf20SJani Nikula 		return "off";
7556140cf20SJani Nikula 	case DRM_FORCE_ON:
7566140cf20SJani Nikula 		return "on";
7576140cf20SJani Nikula 	case DRM_FORCE_ON_DIGITAL:
7586140cf20SJani Nikula 		return "digital";
7596140cf20SJani Nikula 	default:
7606140cf20SJani Nikula 		return "unknown";
7616140cf20SJani Nikula 	}
7626140cf20SJani Nikula }
7636140cf20SJani Nikula 
764613051daSDaniel Vetter #ifdef CONFIG_LOCKDEP
765613051daSDaniel Vetter static struct lockdep_map connector_list_iter_dep_map = {
766613051daSDaniel Vetter 	.name = "drm_connector_list_iter"
767613051daSDaniel Vetter };
768613051daSDaniel Vetter #endif
769613051daSDaniel Vetter 
770613051daSDaniel Vetter /**
771b982dab1SThierry Reding  * drm_connector_list_iter_begin - initialize a connector_list iterator
772613051daSDaniel Vetter  * @dev: DRM device
773613051daSDaniel Vetter  * @iter: connector_list iterator
774613051daSDaniel Vetter  *
775d574528aSDaniel Vetter  * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
776b982dab1SThierry Reding  * must always be cleaned up again by calling drm_connector_list_iter_end().
777613051daSDaniel Vetter  * Iteration itself happens using drm_connector_list_iter_next() or
778613051daSDaniel Vetter  * drm_for_each_connector_iter().
779613051daSDaniel Vetter  */
780b982dab1SThierry Reding void drm_connector_list_iter_begin(struct drm_device *dev,
781613051daSDaniel Vetter 				   struct drm_connector_list_iter *iter)
782613051daSDaniel Vetter {
783613051daSDaniel Vetter 	iter->dev = dev;
784613051daSDaniel Vetter 	iter->conn = NULL;
785613051daSDaniel Vetter 	lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
786613051daSDaniel Vetter }
787b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_begin);
788613051daSDaniel Vetter 
789a703c550SDaniel Vetter /*
790a703c550SDaniel Vetter  * Extra-safe connector put function that works in any context. Should only be
791a703c550SDaniel Vetter  * used from the connector_iter functions, where we never really expect to
792a703c550SDaniel Vetter  * actually release the connector when dropping our final reference.
793a703c550SDaniel Vetter  */
794a703c550SDaniel Vetter static void
795ea497bb9SDaniel Vetter __drm_connector_put_safe(struct drm_connector *conn)
796a703c550SDaniel Vetter {
797ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &conn->dev->mode_config;
798ea497bb9SDaniel Vetter 
799ea497bb9SDaniel Vetter 	lockdep_assert_held(&config->connector_list_lock);
800ea497bb9SDaniel Vetter 
801ea497bb9SDaniel Vetter 	if (!refcount_dec_and_test(&conn->base.refcount.refcount))
802ea497bb9SDaniel Vetter 		return;
803ea497bb9SDaniel Vetter 
804ea497bb9SDaniel Vetter 	llist_add(&conn->free_node, &config->connector_free_list);
805ea497bb9SDaniel Vetter 	schedule_work(&config->connector_free_work);
806a703c550SDaniel Vetter }
807a703c550SDaniel Vetter 
808613051daSDaniel Vetter /**
809613051daSDaniel Vetter  * drm_connector_list_iter_next - return next connector
8104f45c778SLyude Paul  * @iter: connector_list iterator
811613051daSDaniel Vetter  *
812f85d9e59SRandy Dunlap  * Returns: the next connector for @iter, or NULL when the list walk has
813613051daSDaniel Vetter  * completed.
814613051daSDaniel Vetter  */
815613051daSDaniel Vetter struct drm_connector *
816613051daSDaniel Vetter drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
817613051daSDaniel Vetter {
818613051daSDaniel Vetter 	struct drm_connector *old_conn = iter->conn;
819613051daSDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
820613051daSDaniel Vetter 	struct list_head *lhead;
821613051daSDaniel Vetter 	unsigned long flags;
822613051daSDaniel Vetter 
823613051daSDaniel Vetter 	spin_lock_irqsave(&config->connector_list_lock, flags);
824613051daSDaniel Vetter 	lhead = old_conn ? &old_conn->head : &config->connector_list;
825613051daSDaniel Vetter 
826613051daSDaniel Vetter 	do {
827613051daSDaniel Vetter 		if (lhead->next == &config->connector_list) {
828613051daSDaniel Vetter 			iter->conn = NULL;
829613051daSDaniel Vetter 			break;
830613051daSDaniel Vetter 		}
831613051daSDaniel Vetter 
832613051daSDaniel Vetter 		lhead = lhead->next;
833613051daSDaniel Vetter 		iter->conn = list_entry(lhead, struct drm_connector, head);
834613051daSDaniel Vetter 
835613051daSDaniel Vetter 		/* loop until it's not a zombie connector */
836613051daSDaniel Vetter 	} while (!kref_get_unless_zero(&iter->conn->base.refcount));
837613051daSDaniel Vetter 
838613051daSDaniel Vetter 	if (old_conn)
839ea497bb9SDaniel Vetter 		__drm_connector_put_safe(old_conn);
840ea497bb9SDaniel Vetter 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
841613051daSDaniel Vetter 
842613051daSDaniel Vetter 	return iter->conn;
843613051daSDaniel Vetter }
844613051daSDaniel Vetter EXPORT_SYMBOL(drm_connector_list_iter_next);
845613051daSDaniel Vetter 
846613051daSDaniel Vetter /**
847b982dab1SThierry Reding  * drm_connector_list_iter_end - tear down a connector_list iterator
848613051daSDaniel Vetter  * @iter: connector_list iterator
849613051daSDaniel Vetter  *
850613051daSDaniel Vetter  * Tears down @iter and releases any resources (like &drm_connector references)
851613051daSDaniel Vetter  * acquired while walking the list. This must always be called, both when the
852613051daSDaniel Vetter  * iteration completes fully or when it was aborted without walking the entire
853613051daSDaniel Vetter  * list.
854613051daSDaniel Vetter  */
855b982dab1SThierry Reding void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
856613051daSDaniel Vetter {
857ea497bb9SDaniel Vetter 	struct drm_mode_config *config = &iter->dev->mode_config;
858ea497bb9SDaniel Vetter 	unsigned long flags;
859ea497bb9SDaniel Vetter 
860613051daSDaniel Vetter 	iter->dev = NULL;
861ea497bb9SDaniel Vetter 	if (iter->conn) {
862ea497bb9SDaniel Vetter 		spin_lock_irqsave(&config->connector_list_lock, flags);
863ea497bb9SDaniel Vetter 		__drm_connector_put_safe(iter->conn);
864ea497bb9SDaniel Vetter 		spin_unlock_irqrestore(&config->connector_list_lock, flags);
865ea497bb9SDaniel Vetter 	}
8665facae4fSQian Cai 	lock_release(&connector_list_iter_dep_map, _RET_IP_);
867613051daSDaniel Vetter }
868b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_end);
869613051daSDaniel Vetter 
87052217195SDaniel Vetter static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
87152217195SDaniel Vetter 	{ SubPixelUnknown, "Unknown" },
87252217195SDaniel Vetter 	{ SubPixelHorizontalRGB, "Horizontal RGB" },
87352217195SDaniel Vetter 	{ SubPixelHorizontalBGR, "Horizontal BGR" },
87452217195SDaniel Vetter 	{ SubPixelVerticalRGB, "Vertical RGB" },
87552217195SDaniel Vetter 	{ SubPixelVerticalBGR, "Vertical BGR" },
87652217195SDaniel Vetter 	{ SubPixelNone, "None" },
87752217195SDaniel Vetter };
87852217195SDaniel Vetter 
87952217195SDaniel Vetter /**
88052217195SDaniel Vetter  * drm_get_subpixel_order_name - return a string for a given subpixel enum
88152217195SDaniel Vetter  * @order: enum of subpixel_order
88252217195SDaniel Vetter  *
88352217195SDaniel Vetter  * Note you could abuse this and return something out of bounds, but that
88452217195SDaniel Vetter  * would be a caller error.  No unscrubbed user data should make it here.
885f85d9e59SRandy Dunlap  *
886f85d9e59SRandy Dunlap  * Returns: string describing an enumerated subpixel property
88752217195SDaniel Vetter  */
88852217195SDaniel Vetter const char *drm_get_subpixel_order_name(enum subpixel_order order)
88952217195SDaniel Vetter {
89052217195SDaniel Vetter 	return drm_subpixel_enum_list[order].name;
89152217195SDaniel Vetter }
89252217195SDaniel Vetter EXPORT_SYMBOL(drm_get_subpixel_order_name);
89352217195SDaniel Vetter 
89452217195SDaniel Vetter static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
89552217195SDaniel Vetter 	{ DRM_MODE_DPMS_ON, "On" },
89652217195SDaniel Vetter 	{ DRM_MODE_DPMS_STANDBY, "Standby" },
89752217195SDaniel Vetter 	{ DRM_MODE_DPMS_SUSPEND, "Suspend" },
89852217195SDaniel Vetter 	{ DRM_MODE_DPMS_OFF, "Off" }
89952217195SDaniel Vetter };
90052217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
90152217195SDaniel Vetter 
90240ee6fbeSManasi Navare static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
90340ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_GOOD, "Good" },
90440ee6fbeSManasi Navare 	{ DRM_MODE_LINK_STATUS_BAD, "Bad" },
90540ee6fbeSManasi Navare };
90640ee6fbeSManasi Navare 
907b3c6c8bfSDaniel Vetter /**
908b3c6c8bfSDaniel Vetter  * drm_display_info_set_bus_formats - set the supported bus formats
909b3c6c8bfSDaniel Vetter  * @info: display info to store bus formats in
910b3c6c8bfSDaniel Vetter  * @formats: array containing the supported bus formats
911b3c6c8bfSDaniel Vetter  * @num_formats: the number of entries in the fmts array
912b3c6c8bfSDaniel Vetter  *
913b3c6c8bfSDaniel Vetter  * Store the supported bus formats in display info structure.
914b3c6c8bfSDaniel Vetter  * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
915b3c6c8bfSDaniel Vetter  * a full list of available formats.
916f85d9e59SRandy Dunlap  *
917f85d9e59SRandy Dunlap  * Returns:
918f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
919b3c6c8bfSDaniel Vetter  */
920b3c6c8bfSDaniel Vetter int drm_display_info_set_bus_formats(struct drm_display_info *info,
921b3c6c8bfSDaniel Vetter 				     const u32 *formats,
922b3c6c8bfSDaniel Vetter 				     unsigned int num_formats)
923b3c6c8bfSDaniel Vetter {
924b3c6c8bfSDaniel Vetter 	u32 *fmts = NULL;
925b3c6c8bfSDaniel Vetter 
926b3c6c8bfSDaniel Vetter 	if (!formats && num_formats)
927b3c6c8bfSDaniel Vetter 		return -EINVAL;
928b3c6c8bfSDaniel Vetter 
929b3c6c8bfSDaniel Vetter 	if (formats && num_formats) {
930b3c6c8bfSDaniel Vetter 		fmts = kmemdup(formats, sizeof(*formats) * num_formats,
931b3c6c8bfSDaniel Vetter 			       GFP_KERNEL);
932b3c6c8bfSDaniel Vetter 		if (!fmts)
933b3c6c8bfSDaniel Vetter 			return -ENOMEM;
934b3c6c8bfSDaniel Vetter 	}
935b3c6c8bfSDaniel Vetter 
936b3c6c8bfSDaniel Vetter 	kfree(info->bus_formats);
937b3c6c8bfSDaniel Vetter 	info->bus_formats = fmts;
938b3c6c8bfSDaniel Vetter 	info->num_bus_formats = num_formats;
939b3c6c8bfSDaniel Vetter 
940b3c6c8bfSDaniel Vetter 	return 0;
941b3c6c8bfSDaniel Vetter }
942b3c6c8bfSDaniel Vetter EXPORT_SYMBOL(drm_display_info_set_bus_formats);
943b3c6c8bfSDaniel Vetter 
94452217195SDaniel Vetter /* Optional connector properties. */
94552217195SDaniel Vetter static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
94652217195SDaniel Vetter 	{ DRM_MODE_SCALE_NONE, "None" },
94752217195SDaniel Vetter 	{ DRM_MODE_SCALE_FULLSCREEN, "Full" },
94852217195SDaniel Vetter 	{ DRM_MODE_SCALE_CENTER, "Center" },
94952217195SDaniel Vetter 	{ DRM_MODE_SCALE_ASPECT, "Full aspect" },
95052217195SDaniel Vetter };
95152217195SDaniel Vetter 
95252217195SDaniel Vetter static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
95352217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
95452217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
95552217195SDaniel Vetter 	{ DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
95652217195SDaniel Vetter };
95752217195SDaniel Vetter 
95850525c33SStanislav Lisovskiy static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
95950525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
96050525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
96150525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
96250525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
96350525c33SStanislav Lisovskiy 	{ DRM_MODE_CONTENT_TYPE_GAME, "Game" },
96450525c33SStanislav Lisovskiy };
96550525c33SStanislav Lisovskiy 
9668d70f395SHans de Goede static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
9678d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_NORMAL,	"Normal"	},
9688d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP,	"Upside Down"	},
9698d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_LEFT_UP,	"Left Side Up"	},
9708d70f395SHans de Goede 	{ DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,	"Right Side Up"	},
9718d70f395SHans de Goede };
9728d70f395SHans de Goede 
97352217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
97452217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
97552217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
97652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
97752217195SDaniel Vetter };
97852217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
97952217195SDaniel Vetter 
98052217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
981e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I, TV-out and DP */
98252217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
98352217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
98452217195SDaniel Vetter };
98552217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
98652217195SDaniel Vetter 		 drm_dvi_i_subconnector_enum_list)
98752217195SDaniel Vetter 
9887d63cd85SMaxime Ripard static const struct drm_prop_enum_list drm_tv_mode_enum_list[] = {
9897d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_NTSC, "NTSC" },
9907d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_NTSC_443, "NTSC-443" },
9917d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_NTSC_J, "NTSC-J" },
9927d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_PAL, "PAL" },
9937d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_PAL_M, "PAL-M" },
9947d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_PAL_N, "PAL-N" },
9957d63cd85SMaxime Ripard 	{ DRM_MODE_TV_MODE_SECAM, "SECAM" },
9967d63cd85SMaxime Ripard };
9977d63cd85SMaxime Ripard DRM_ENUM_NAME_FN(drm_get_tv_mode_name, drm_tv_mode_enum_list)
9987d63cd85SMaxime Ripard 
999d4613e3eSMaxime Ripard /**
1000d4613e3eSMaxime Ripard  * drm_get_tv_mode_from_name - Translates a TV mode name into its enum value
1001d4613e3eSMaxime Ripard  * @name: TV Mode name we want to convert
1002d4613e3eSMaxime Ripard  * @len: Length of @name
1003d4613e3eSMaxime Ripard  *
1004d4613e3eSMaxime Ripard  * Translates @name into an enum drm_connector_tv_mode.
1005d4613e3eSMaxime Ripard  *
1006d4613e3eSMaxime Ripard  * Returns: the enum value on success, a negative errno otherwise.
1007d4613e3eSMaxime Ripard  */
1008d4613e3eSMaxime Ripard int drm_get_tv_mode_from_name(const char *name, size_t len)
1009d4613e3eSMaxime Ripard {
1010d4613e3eSMaxime Ripard 	unsigned int i;
1011d4613e3eSMaxime Ripard 
1012d4613e3eSMaxime Ripard 	for (i = 0; i < ARRAY_SIZE(drm_tv_mode_enum_list); i++) {
1013d4613e3eSMaxime Ripard 		const struct drm_prop_enum_list *item = &drm_tv_mode_enum_list[i];
1014d4613e3eSMaxime Ripard 
1015d4613e3eSMaxime Ripard 		if (strlen(item->name) == len && !strncmp(item->name, name, len))
1016d4613e3eSMaxime Ripard 			return item->type;
1017d4613e3eSMaxime Ripard 	}
1018d4613e3eSMaxime Ripard 
1019d4613e3eSMaxime Ripard 	return -EINVAL;
1020d4613e3eSMaxime Ripard }
1021d4613e3eSMaxime Ripard EXPORT_SYMBOL(drm_get_tv_mode_from_name);
1022d4613e3eSMaxime Ripard 
102352217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
102452217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
102552217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
102652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
102752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
102852217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
102952217195SDaniel Vetter };
103052217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
103152217195SDaniel Vetter 
103252217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
1033e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I, TV-out and DP */
103452217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
103552217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
103652217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
103752217195SDaniel Vetter 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
103852217195SDaniel Vetter };
103952217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
104052217195SDaniel Vetter 		 drm_tv_subconnector_enum_list)
104152217195SDaniel Vetter 
1042e5b92773SOleg Vasilev static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = {
1043e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Unknown,     "Unknown"   }, /* DVI-I, TV-out and DP */
1044e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_VGA,	     "VGA"       }, /* DP */
1045e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_DVID,	     "DVI-D"     }, /* DP */
1046e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_HDMIA,	     "HDMI"      }, /* DP */
1047e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_DisplayPort, "DP"        }, /* DP */
1048e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Wireless,    "Wireless"  }, /* DP */
1049e5b92773SOleg Vasilev 	{ DRM_MODE_SUBCONNECTOR_Native,	     "Native"    }, /* DP */
1050e5b92773SOleg Vasilev };
1051e5b92773SOleg Vasilev 
1052e5b92773SOleg Vasilev DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name,
1053e5b92773SOleg Vasilev 		 drm_dp_subconnector_enum_list)
1054e5b92773SOleg Vasilev 
1055d2c6a405SUma Shankar static const struct drm_prop_enum_list hdmi_colorspaces[] = {
1056d2c6a405SUma Shankar 	/* For Default case, driver will set the colorspace */
1057d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
1058d2c6a405SUma Shankar 	/* Standard Definition Colorimetry based on CEA 861 */
1059d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_SMPTE_170M_YCC, "SMPTE_170M_YCC" },
1060d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
1061d2c6a405SUma Shankar 	/* Standard Definition Colorimetry based on IEC 61966-2-4 */
1062d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
1063d2c6a405SUma Shankar 	/* High Definition Colorimetry based on IEC 61966-2-4 */
1064d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
1065d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-1/Amendment 1 */
1066d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
1067d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-5 [33] */
1068d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
1069d2c6a405SUma Shankar 	/* Colorimetry based on IEC 61966-2-5 */
1070d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
1071d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
1072d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
1073d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
1074d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
1075d2c6a405SUma Shankar 	/* Colorimetry based on ITU-R BT.2020 */
1076d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
1077d2c6a405SUma Shankar 	/* Added as part of Additional Colorimetry Extension in 861.G */
1078d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
1079d2c6a405SUma Shankar 	{ DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, "DCI-P3_RGB_Theater" },
1080d2c6a405SUma Shankar };
1081d2c6a405SUma Shankar 
108245cf0e91SGwan-gyeong Mun /*
108345cf0e91SGwan-gyeong Mun  * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
108445cf0e91SGwan-gyeong Mun  * Format Table 2-120
108545cf0e91SGwan-gyeong Mun  */
108645cf0e91SGwan-gyeong Mun static const struct drm_prop_enum_list dp_colorspaces[] = {
108745cf0e91SGwan-gyeong Mun 	/* For Default case, driver will set the colorspace */
108845cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
108945cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED, "RGB_Wide_Gamut_Fixed_Point" },
109045cf0e91SGwan-gyeong Mun 	/* Colorimetry based on scRGB (IEC 61966-2-2) */
109145cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT, "RGB_Wide_Gamut_Floating_Point" },
109245cf0e91SGwan-gyeong Mun 	/* Colorimetry based on IEC 61966-2-5 */
109345cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
109445cf0e91SGwan-gyeong Mun 	/* Colorimetry based on SMPTE RP 431-2 */
109545cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
109645cf0e91SGwan-gyeong Mun 	/* Colorimetry based on ITU-R BT.2020 */
109745cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
109845cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT601_YCC, "BT601_YCC" },
109945cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
110045cf0e91SGwan-gyeong Mun 	/* Standard Definition Colorimetry based on IEC 61966-2-4 */
110145cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
110245cf0e91SGwan-gyeong Mun 	/* High Definition Colorimetry based on IEC 61966-2-4 */
110345cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
110445cf0e91SGwan-gyeong Mun 	/* Colorimetry based on IEC 61966-2-1/Amendment 1 */
110545cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
110645cf0e91SGwan-gyeong Mun 	/* Colorimetry based on IEC 61966-2-5 [33] */
110745cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
110845cf0e91SGwan-gyeong Mun 	/* Colorimetry based on ITU-R BT.2020 */
110945cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
111045cf0e91SGwan-gyeong Mun 	/* Colorimetry based on ITU-R BT.2020 */
111145cf0e91SGwan-gyeong Mun 	{ DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
111245cf0e91SGwan-gyeong Mun };
111345cf0e91SGwan-gyeong Mun 
11144ada6f22SDaniel Vetter /**
11154ada6f22SDaniel Vetter  * DOC: standard connector properties
11164ada6f22SDaniel Vetter  *
11174ada6f22SDaniel Vetter  * DRM connectors have a few standardized properties:
11184ada6f22SDaniel Vetter  *
11194ada6f22SDaniel Vetter  * EDID:
11204ada6f22SDaniel Vetter  * 	Blob property which contains the current EDID read from the sink. This
11214ada6f22SDaniel Vetter  * 	is useful to parse sink identification information like vendor, model
11224ada6f22SDaniel Vetter  * 	and serial. Drivers should update this property by calling
1123c555f023SDaniel Vetter  * 	drm_connector_update_edid_property(), usually after having parsed
11244ada6f22SDaniel Vetter  * 	the EDID using drm_add_edid_modes(). Userspace cannot change this
11254ada6f22SDaniel Vetter  * 	property.
112612767469SSimon Ser  *
112712767469SSimon Ser  * 	User-space should not parse the EDID to obtain information exposed via
112812767469SSimon Ser  * 	other KMS properties (because the kernel might apply limits, quirks or
112912767469SSimon Ser  * 	fixups to the EDID). For instance, user-space should not try to parse
113012767469SSimon Ser  * 	mode lists from the EDID.
11314ada6f22SDaniel Vetter  * DPMS:
11324ada6f22SDaniel Vetter  * 	Legacy property for setting the power state of the connector. For atomic
11334ada6f22SDaniel Vetter  * 	drivers this is only provided for backwards compatibility with existing
11344ada6f22SDaniel Vetter  * 	drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
11354ada6f22SDaniel Vetter  * 	connector is linked to. Drivers should never set this property directly,
1136d574528aSDaniel Vetter  * 	it is handled by the DRM core by calling the &drm_connector_funcs.dpms
1137144a7999SDaniel Vetter  * 	callback. For atomic drivers the remapping to the "ACTIVE" property is
11381e3e4caeSSimon Ser  * 	implemented in the DRM core.
1139d0d1aee5SDaniel Vetter  *
1140d0d1aee5SDaniel Vetter  * 	Note that this property cannot be set through the MODE_ATOMIC ioctl,
1141d0d1aee5SDaniel Vetter  * 	userspace must use "ACTIVE" on the CRTC instead.
1142d0d1aee5SDaniel Vetter  *
1143d0d1aee5SDaniel Vetter  * 	WARNING:
1144d0d1aee5SDaniel Vetter  *
1145d0d1aee5SDaniel Vetter  * 	For userspace also running on legacy drivers the "DPMS" semantics are a
1146d0d1aee5SDaniel Vetter  * 	lot more complicated. First, userspace cannot rely on the "DPMS" value
1147d0d1aee5SDaniel Vetter  * 	returned by the GETCONNECTOR actually reflecting reality, because many
1148d0d1aee5SDaniel Vetter  * 	drivers fail to update it. For atomic drivers this is taken care of in
1149d0d1aee5SDaniel Vetter  * 	drm_atomic_helper_update_legacy_modeset_state().
1150d0d1aee5SDaniel Vetter  *
1151d0d1aee5SDaniel Vetter  * 	The second issue is that the DPMS state is only well-defined when the
1152d0d1aee5SDaniel Vetter  * 	connector is connected to a CRTC. In atomic the DRM core enforces that
1153d0d1aee5SDaniel Vetter  * 	"ACTIVE" is off in such a case, no such checks exists for "DPMS".
1154d0d1aee5SDaniel Vetter  *
1155d0d1aee5SDaniel Vetter  * 	Finally, when enabling an output using the legacy SETCONFIG ioctl then
1156d0d1aee5SDaniel Vetter  * 	"DPMS" is forced to ON. But see above, that might not be reflected in
1157d0d1aee5SDaniel Vetter  * 	the software value on legacy drivers.
1158d0d1aee5SDaniel Vetter  *
1159d0d1aee5SDaniel Vetter  * 	Summarizing: Only set "DPMS" when the connector is known to be enabled,
1160d0d1aee5SDaniel Vetter  * 	assume that a successful SETCONFIG call also sets "DPMS" to on, and
1161d0d1aee5SDaniel Vetter  * 	never read back the value of "DPMS" because it can be incorrect.
11624ada6f22SDaniel Vetter  * PATH:
11634ada6f22SDaniel Vetter  * 	Connector path property to identify how this sink is physically
11644ada6f22SDaniel Vetter  * 	connected. Used by DP MST. This should be set by calling
116597e14fbeSDaniel Vetter  * 	drm_connector_set_path_property(), in the case of DP MST with the
11664ada6f22SDaniel Vetter  * 	path property the MST manager created. Userspace cannot change this
11674ada6f22SDaniel Vetter  * 	property.
11684ada6f22SDaniel Vetter  * TILE:
11694ada6f22SDaniel Vetter  * 	Connector tile group property to indicate how a set of DRM connector
11704ada6f22SDaniel Vetter  * 	compose together into one logical screen. This is used by both high-res
11714ada6f22SDaniel Vetter  * 	external screens (often only using a single cable, but exposing multiple
11724ada6f22SDaniel Vetter  * 	DP MST sinks), or high-res integrated panels (like dual-link DSI) which
11734ada6f22SDaniel Vetter  * 	are not gen-locked. Note that for tiled panels which are genlocked, like
11744ada6f22SDaniel Vetter  * 	dual-link LVDS or dual-link DSI, the driver should try to not expose the
117584e543bcSAntonio Borneo  * 	tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers
117697e14fbeSDaniel Vetter  * 	should update this value using drm_connector_set_tile_property().
11774ada6f22SDaniel Vetter  * 	Userspace cannot change this property.
117840ee6fbeSManasi Navare  * link-status:
1179716719a3SSean Paul  *      Connector link-status property to indicate the status of link. The
1180716719a3SSean Paul  *      default value of link-status is "GOOD". If something fails during or
1181716719a3SSean Paul  *      after modeset, the kernel driver may set this to "BAD" and issue a
1182716719a3SSean Paul  *      hotplug uevent. Drivers should update this value using
118397e14fbeSDaniel Vetter  *      drm_connector_set_link_status_property().
1184a66da873SSimon Ser  *
1185a66da873SSimon Ser  *      When user-space receives the hotplug uevent and detects a "BAD"
1186a66da873SSimon Ser  *      link-status, the sink doesn't receive pixels anymore (e.g. the screen
1187a66da873SSimon Ser  *      becomes completely black). The list of available modes may have
1188a66da873SSimon Ser  *      changed. User-space is expected to pick a new mode if the current one
1189a66da873SSimon Ser  *      has disappeared and perform a new modeset with link-status set to
1190a66da873SSimon Ser  *      "GOOD" to re-enable the connector.
1191a66da873SSimon Ser  *
1192a66da873SSimon Ser  *      If multiple connectors share the same CRTC and one of them gets a "BAD"
1193a66da873SSimon Ser  *      link-status, the other are unaffected (ie. the sinks still continue to
1194a66da873SSimon Ser  *      receive pixels).
1195a66da873SSimon Ser  *
1196a66da873SSimon Ser  *      When user-space performs an atomic commit on a connector with a "BAD"
1197a66da873SSimon Ser  *      link-status without resetting the property to "GOOD", the sink may
1198a66da873SSimon Ser  *      still not receive pixels. When user-space performs an atomic commit
1199a66da873SSimon Ser  *      which resets the link-status property to "GOOD" without the
1200a66da873SSimon Ser  *      ALLOW_MODESET flag set, it might fail because a modeset is required.
1201a66da873SSimon Ser  *
1202a66da873SSimon Ser  *      User-space can only change link-status to "GOOD", changing it to "BAD"
1203a66da873SSimon Ser  *      is a no-op.
1204a66da873SSimon Ser  *
1205a66da873SSimon Ser  *      For backwards compatibility with non-atomic userspace the kernel
1206a66da873SSimon Ser  *      tries to automatically set the link-status back to "GOOD" in the
1207a66da873SSimon Ser  *      SETCRTC IOCTL. This might fail if the mode is no longer valid, similar
1208a66da873SSimon Ser  *      to how it might fail if a different screen has been connected in the
1209a66da873SSimon Ser  *      interim.
121066660d4cSDave Airlie  * non_desktop:
121166660d4cSDave Airlie  * 	Indicates the output should be ignored for purposes of displaying a
121266660d4cSDave Airlie  * 	standard desktop environment or console. This is most likely because
121366660d4cSDave Airlie  * 	the output device is not rectilinear.
121424557865SSean Paul  * Content Protection:
121524557865SSean Paul  *	This property is used by userspace to request the kernel protect future
121624557865SSean Paul  *	content communicated over the link. When requested, kernel will apply
121724557865SSean Paul  *	the appropriate means of protection (most often HDCP), and use the
121824557865SSean Paul  *	property to tell userspace the protection is active.
121924557865SSean Paul  *
122024557865SSean Paul  *	Drivers can set this up by calling
122124557865SSean Paul  *	drm_connector_attach_content_protection_property() on initialization.
122224557865SSean Paul  *
122324557865SSean Paul  *	The value of this property can be one of the following:
122424557865SSean Paul  *
1225bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
122624557865SSean Paul  *		The link is not protected, content is transmitted in the clear.
1227bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
122824557865SSean Paul  *		Userspace has requested content protection, but the link is not
122924557865SSean Paul  *		currently protected. When in this state, kernel should enable
123024557865SSean Paul  *		Content Protection as soon as possible.
1231bbeba09fSDaniel Vetter  *	DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
123224557865SSean Paul  *		Userspace has requested content protection, and the link is
123324557865SSean Paul  *		protected. Only the driver can set the property to this value.
123424557865SSean Paul  *		If userspace attempts to set to ENABLED, kernel will return
123524557865SSean Paul  *		-EINVAL.
123624557865SSean Paul  *
123724557865SSean Paul  *	A few guidelines:
123824557865SSean Paul  *
123924557865SSean Paul  *	- DESIRED state should be preserved until userspace de-asserts it by
124024557865SSean Paul  *	  setting the property to UNDESIRED. This means ENABLED should only
124124557865SSean Paul  *	  transition to UNDESIRED when the user explicitly requests it.
124224557865SSean Paul  *	- If the state is DESIRED, kernel should attempt to re-authenticate the
124324557865SSean Paul  *	  link whenever possible. This includes across disable/enable, dpms,
124424557865SSean Paul  *	  hotplug, downstream device changes, link status failures, etc..
1245bb5a45d4SRamalingam C  *	- Kernel sends uevent with the connector id and property id through
1246bb5a45d4SRamalingam C  *	  @drm_hdcp_update_content_protection, upon below kernel triggered
1247bb5a45d4SRamalingam C  *	  scenarios:
124812db36bcSSean Paul  *
124912db36bcSSean Paul  *		- DESIRED -> ENABLED (authentication success)
125012db36bcSSean Paul  *		- ENABLED -> DESIRED (termination of authentication)
1251bb5a45d4SRamalingam C  *	- Please note no uevents for userspace triggered property state changes,
1252bb5a45d4SRamalingam C  *	  which can't fail such as
125312db36bcSSean Paul  *
125412db36bcSSean Paul  *		- DESIRED/ENABLED -> UNDESIRED
125512db36bcSSean Paul  *		- UNDESIRED -> DESIRED
1256bb5a45d4SRamalingam C  *	- Userspace is responsible for polling the property or listen to uevents
1257bb5a45d4SRamalingam C  *	  to determine when the value transitions from ENABLED to DESIRED.
1258bb5a45d4SRamalingam C  *	  This signifies the link is no longer protected and userspace should
1259bb5a45d4SRamalingam C  *	  take appropriate action (whatever that might be).
12604ada6f22SDaniel Vetter  *
12617672dbbaSRamalingam C  * HDCP Content Type:
12627672dbbaSRamalingam C  *	This Enum property is used by the userspace to declare the content type
12637672dbbaSRamalingam C  *	of the display stream, to kernel. Here display stream stands for any
12647672dbbaSRamalingam C  *	display content that userspace intended to display through HDCP
12657672dbbaSRamalingam C  *	encryption.
12667672dbbaSRamalingam C  *
12677672dbbaSRamalingam C  *	Content Type of a stream is decided by the owner of the stream, as
12687672dbbaSRamalingam C  *	"HDCP Type0" or "HDCP Type1".
12697672dbbaSRamalingam C  *
12707672dbbaSRamalingam C  *	The value of the property can be one of the below:
12717672dbbaSRamalingam C  *	  - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0
12727672dbbaSRamalingam C  *	  - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1
12737672dbbaSRamalingam C  *
12747672dbbaSRamalingam C  *	When kernel starts the HDCP authentication (see "Content Protection"
12757672dbbaSRamalingam C  *	for details), it uses the content type in "HDCP Content Type"
12767672dbbaSRamalingam C  *	for performing the HDCP authentication with the display sink.
12777672dbbaSRamalingam C  *
12787672dbbaSRamalingam C  *	Please note in HDCP spec versions, a link can be authenticated with
12797672dbbaSRamalingam C  *	HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be
12807672dbbaSRamalingam C  *	authenticated with HDCP1.4 only for Content Type 0(though it is implicit
12817672dbbaSRamalingam C  *	in nature. As there is no reference for Content Type in HDCP1.4).
12827672dbbaSRamalingam C  *
12837672dbbaSRamalingam C  *	HDCP2.2 authentication protocol itself takes the "Content Type" as a
12847672dbbaSRamalingam C  *	parameter, which is a input for the DP HDCP2.2 encryption algo.
12857672dbbaSRamalingam C  *
12867672dbbaSRamalingam C  *	In case of Type 0 content protection request, kernel driver can choose
12877672dbbaSRamalingam C  *	either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for
12887672dbbaSRamalingam C  *	"HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send
12897672dbbaSRamalingam C  *	that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).
12907672dbbaSRamalingam C  *	But if the content is classified as "HDCP Type 1", above mentioned
12917672dbbaSRamalingam C  *	HDCP 2.2 repeater wont send the content to the HDCP sink as it can't
12927672dbbaSRamalingam C  *	authenticate the HDCP1.4 capable sink for "HDCP Type 1".
12937672dbbaSRamalingam C  *
12947672dbbaSRamalingam C  *	Please note userspace can be ignorant of the HDCP versions used by the
12957672dbbaSRamalingam C  *	kernel driver to achieve the "HDCP Content Type".
12967672dbbaSRamalingam C  *
12977672dbbaSRamalingam C  *	At current scenario, classifying a content as Type 1 ensures that the
12987672dbbaSRamalingam C  *	content will be displayed only through the HDCP2.2 encrypted link.
12997672dbbaSRamalingam C  *
13007672dbbaSRamalingam C  *	Note that the HDCP Content Type property is introduced at HDCP 2.2, and
13017672dbbaSRamalingam C  *	defaults to type 0. It is only exposed by drivers supporting HDCP 2.2
13027672dbbaSRamalingam C  *	(hence supporting Type 0 and Type 1). Based on how next versions of
13037672dbbaSRamalingam C  *	HDCP specs are defined content Type could be used for higher versions
13047672dbbaSRamalingam C  *	too.
13057672dbbaSRamalingam C  *
13067672dbbaSRamalingam C  *	If content type is changed when "Content Protection" is not UNDESIRED,
13077672dbbaSRamalingam C  *	then kernel will disable the HDCP and re-enable with new type in the
13087672dbbaSRamalingam C  *	same atomic commit. And when "Content Protection" is ENABLED, it means
13097672dbbaSRamalingam C  *	that link is HDCP authenticated and encrypted, for the transmission of
13107672dbbaSRamalingam C  *	the Type of stream mentioned at "HDCP Content Type".
13117672dbbaSRamalingam C  *
1312a09db883SUma Shankar  * HDR_OUTPUT_METADATA:
1313a09db883SUma Shankar  *	Connector property to enable userspace to send HDR Metadata to
1314a09db883SUma Shankar  *	driver. This metadata is based on the composition and blending
1315a09db883SUma Shankar  *	policies decided by user, taking into account the hardware and
1316a09db883SUma Shankar  *	sink capabilities. The driver gets this metadata and creates a
1317a09db883SUma Shankar  *	Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,
1318a09db883SUma Shankar  *	SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then
1319a09db883SUma Shankar  *	sent to sink. This notifies the sink of the upcoming frame's Color
1320a09db883SUma Shankar  *	Encoding and Luminance parameters.
1321a09db883SUma Shankar  *
1322a09db883SUma Shankar  *	Userspace first need to detect the HDR capabilities of sink by
1323a09db883SUma Shankar  *	reading and parsing the EDID. Details of HDR metadata for HDMI
1324a09db883SUma Shankar  *	are added in CTA 861.G spec. For DP , its defined in VESA DP
1325a09db883SUma Shankar  *	Standard v1.4. It needs to then get the metadata information
1326a09db883SUma Shankar  *	of the video/game/app content which are encoded in HDR (basically
1327a09db883SUma Shankar  *	using HDR transfer functions). With this information it needs to
1328a09db883SUma Shankar  *	decide on a blending policy and compose the relevant
1329a09db883SUma Shankar  *	layers/overlays into a common format. Once this blending is done,
1330a09db883SUma Shankar  *	userspace will be aware of the metadata of the composed frame to
1331a09db883SUma Shankar  *	be send to sink. It then uses this property to communicate this
1332a09db883SUma Shankar  *	metadata to driver which then make a Infoframe packet and sends
1333a09db883SUma Shankar  *	to sink based on the type of encoder connected.
1334a09db883SUma Shankar  *
1335a09db883SUma Shankar  *	Userspace will be responsible to do Tone mapping operation in case:
1336a09db883SUma Shankar  *		- Some layers are HDR and others are SDR
1337a09db883SUma Shankar  *		- HDR layers luminance is not same as sink
13389f9b2559SSean Paul  *
1339a09db883SUma Shankar  *	It will even need to do colorspace conversion and get all layers
1340a09db883SUma Shankar  *	to one common colorspace for blending. It can use either GL, Media
134184e543bcSAntonio Borneo  *	or display engine to get this done based on the capabilities of the
1342a09db883SUma Shankar  *	associated hardware.
1343a09db883SUma Shankar  *
1344a09db883SUma Shankar  *	Driver expects metadata to be put in &struct hdr_output_metadata
1345a09db883SUma Shankar  *	structure from userspace. This is received as blob and stored in
1346a09db883SUma Shankar  *	&drm_connector_state.hdr_output_metadata. It parses EDID and saves the
1347a09db883SUma Shankar  *	sink metadata in &struct hdr_sink_metadata, as
1348a09db883SUma Shankar  *	&drm_connector.hdr_sink_metadata.  Driver uses
1349a09db883SUma Shankar  *	drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,
1350a09db883SUma Shankar  *	hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of
1351a09db883SUma Shankar  *	HDMI encoder.
1352a09db883SUma Shankar  *
135347e22ff1SRadhakrishna Sripada  * max bpc:
135447e22ff1SRadhakrishna Sripada  *	This range property is used by userspace to limit the bit depth. When
135547e22ff1SRadhakrishna Sripada  *	used the driver would limit the bpc in accordance with the valid range
135647e22ff1SRadhakrishna Sripada  *	supported by the hardware and sink. Drivers to use the function
135747e22ff1SRadhakrishna Sripada  *	drm_connector_attach_max_bpc_property() to create and attach the
135847e22ff1SRadhakrishna Sripada  *	property to the connector during initialization.
135947e22ff1SRadhakrishna Sripada  *
13604ada6f22SDaniel Vetter  * Connectors also have one standardized atomic property:
13614ada6f22SDaniel Vetter  *
13624ada6f22SDaniel Vetter  * CRTC_ID:
13634ada6f22SDaniel Vetter  * 	Mode object ID of the &drm_crtc this connector should be connected to.
13648d70f395SHans de Goede  *
13658d70f395SHans de Goede  * Connectors for LCD panels may also have one standardized property:
13668d70f395SHans de Goede  *
13678d70f395SHans de Goede  * panel orientation:
13688d70f395SHans de Goede  *	On some devices the LCD panel is mounted in the casing in such a way
13698d70f395SHans de Goede  *	that the up/top side of the panel does not match with the top side of
13708d70f395SHans de Goede  *	the device. Userspace can use this property to check for this.
13718d70f395SHans de Goede  *	Note that input coordinates from touchscreens (input devices with
13728d70f395SHans de Goede  *	INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
13738d70f395SHans de Goede  *	coordinates, so if userspace rotates the picture to adjust for
13748d70f395SHans de Goede  *	the orientation it must also apply the same transformation to the
1375bbeba09fSDaniel Vetter  *	touchscreen input coordinates. This property is initialized by calling
137669654c63SDerek Basehore  *	drm_connector_set_panel_orientation() or
137769654c63SDerek Basehore  *	drm_connector_set_panel_orientation_with_quirk()
1378bbeba09fSDaniel Vetter  *
1379bbeba09fSDaniel Vetter  * scaling mode:
1380bbeba09fSDaniel Vetter  *	This property defines how a non-native mode is upscaled to the native
1381bbeba09fSDaniel Vetter  *	mode of an LCD panel:
1382bbeba09fSDaniel Vetter  *
1383bbeba09fSDaniel Vetter  *	None:
1384bbeba09fSDaniel Vetter  *		No upscaling happens, scaling is left to the panel. Not all
1385bbeba09fSDaniel Vetter  *		drivers expose this mode.
1386bbeba09fSDaniel Vetter  *	Full:
1387bbeba09fSDaniel Vetter  *		The output is upscaled to the full resolution of the panel,
1388bbeba09fSDaniel Vetter  *		ignoring the aspect ratio.
1389bbeba09fSDaniel Vetter  *	Center:
1390bbeba09fSDaniel Vetter  *		No upscaling happens, the output is centered within the native
1391bbeba09fSDaniel Vetter  *		resolution the panel.
1392bbeba09fSDaniel Vetter  *	Full aspect:
1393bbeba09fSDaniel Vetter  *		The output is upscaled to maximize either the width or height
1394bbeba09fSDaniel Vetter  *		while retaining the aspect ratio.
1395bbeba09fSDaniel Vetter  *
1396bbeba09fSDaniel Vetter  *	This property should be set up by calling
1397bbeba09fSDaniel Vetter  *	drm_connector_attach_scaling_mode_property(). Note that drivers
1398bbeba09fSDaniel Vetter  *	can also expose this property to external outputs, in which case they
1399bbeba09fSDaniel Vetter  *	must support "None", which should be the default (since external screens
1400bbeba09fSDaniel Vetter  *	have a built-in scaler).
1401e5b92773SOleg Vasilev  *
1402e5b92773SOleg Vasilev  * subconnector:
1403e5b92773SOleg Vasilev  *	This property is used by DVI-I, TVout and DisplayPort to indicate different
1404e5b92773SOleg Vasilev  *	connector subtypes. Enum values more or less match with those from main
1405e5b92773SOleg Vasilev  *	connector types.
1406e5b92773SOleg Vasilev  *	For DVI-I and TVout there is also a matching property "select subconnector"
1407e5b92773SOleg Vasilev  *	allowing to switch between signal types.
1408e5b92773SOleg Vasilev  *	DP subconnector corresponds to a downstream port.
1409107fe904SRajat Jain  *
1410107fe904SRajat Jain  * privacy-screen sw-state, privacy-screen hw-state:
1411107fe904SRajat Jain  *	These 2 optional properties can be used to query the state of the
1412107fe904SRajat Jain  *	electronic privacy screen that is available on some displays; and in
1413107fe904SRajat Jain  *	some cases also control the state. If a driver implements these
1414107fe904SRajat Jain  *	properties then both properties must be present.
1415107fe904SRajat Jain  *
1416107fe904SRajat Jain  *	"privacy-screen hw-state" is read-only and reflects the actual state
1417107fe904SRajat Jain  *	of the privacy-screen, possible values: "Enabled", "Disabled,
1418107fe904SRajat Jain  *	"Enabled-locked", "Disabled-locked". The locked states indicate
1419107fe904SRajat Jain  *	that the state cannot be changed through the DRM API. E.g. there
1420107fe904SRajat Jain  *	might be devices where the firmware-setup options, or a hardware
1421107fe904SRajat Jain  *	slider-switch, offer always on / off modes.
1422107fe904SRajat Jain  *
1423107fe904SRajat Jain  *	"privacy-screen sw-state" can be set to change the privacy-screen state
1424107fe904SRajat Jain  *	when not locked. In this case the driver must update the hw-state
1425107fe904SRajat Jain  *	property to reflect the new state on completion of the commit of the
1426107fe904SRajat Jain  *	sw-state property. Setting the sw-state property when the hw-state is
1427107fe904SRajat Jain  *	locked must be interpreted by the driver as a request to change the
1428107fe904SRajat Jain  *	state to the set state when the hw-state becomes unlocked. E.g. if
1429107fe904SRajat Jain  *	"privacy-screen hw-state" is "Enabled-locked" and the sw-state
1430107fe904SRajat Jain  *	gets set to "Disabled" followed by the user unlocking the state by
1431107fe904SRajat Jain  *	changing the slider-switch position, then the driver must set the
1432107fe904SRajat Jain  *	state to "Disabled" upon receiving the unlock event.
1433107fe904SRajat Jain  *
1434107fe904SRajat Jain  *	In some cases the privacy-screen's actual state might change outside of
1435107fe904SRajat Jain  *	control of the DRM code. E.g. there might be a firmware handled hotkey
1436107fe904SRajat Jain  *	which toggles the actual state, or the actual state might be changed
1437107fe904SRajat Jain  *	through another userspace API such as writing /proc/acpi/ibm/lcdshadow.
1438107fe904SRajat Jain  *	In this case the driver must update both the hw-state and the sw-state
1439107fe904SRajat Jain  *	to reflect the new value, overwriting any pending state requests in the
1440107fe904SRajat Jain  *	sw-state. Any pending sw-state requests are thus discarded.
1441107fe904SRajat Jain  *
1442107fe904SRajat Jain  *	Note that the ability for the state to change outside of control of
1443107fe904SRajat Jain  *	the DRM master process means that userspace must not cache the value
1444107fe904SRajat Jain  *	of the sw-state. Caching the sw-state value and including it in later
1445107fe904SRajat Jain  *	atomic commits may lead to overriding a state change done through e.g.
1446107fe904SRajat Jain  *	a firmware handled hotkey. Therefor userspace must not include the
1447107fe904SRajat Jain  *	privacy-screen sw-state in an atomic commit unless it wants to change
1448107fe904SRajat Jain  *	its value.
14494ada6f22SDaniel Vetter  */
14504ada6f22SDaniel Vetter 
145152217195SDaniel Vetter int drm_connector_create_standard_properties(struct drm_device *dev)
145252217195SDaniel Vetter {
145352217195SDaniel Vetter 	struct drm_property *prop;
145452217195SDaniel Vetter 
145552217195SDaniel Vetter 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
145652217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
145752217195SDaniel Vetter 				   "EDID", 0);
145852217195SDaniel Vetter 	if (!prop)
145952217195SDaniel Vetter 		return -ENOMEM;
146052217195SDaniel Vetter 	dev->mode_config.edid_property = prop;
146152217195SDaniel Vetter 
146252217195SDaniel Vetter 	prop = drm_property_create_enum(dev, 0,
146352217195SDaniel Vetter 				   "DPMS", drm_dpms_enum_list,
146452217195SDaniel Vetter 				   ARRAY_SIZE(drm_dpms_enum_list));
146552217195SDaniel Vetter 	if (!prop)
146652217195SDaniel Vetter 		return -ENOMEM;
146752217195SDaniel Vetter 	dev->mode_config.dpms_property = prop;
146852217195SDaniel Vetter 
146952217195SDaniel Vetter 	prop = drm_property_create(dev,
147052217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
147152217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
147252217195SDaniel Vetter 				   "PATH", 0);
147352217195SDaniel Vetter 	if (!prop)
147452217195SDaniel Vetter 		return -ENOMEM;
147552217195SDaniel Vetter 	dev->mode_config.path_property = prop;
147652217195SDaniel Vetter 
147752217195SDaniel Vetter 	prop = drm_property_create(dev,
147852217195SDaniel Vetter 				   DRM_MODE_PROP_BLOB |
147952217195SDaniel Vetter 				   DRM_MODE_PROP_IMMUTABLE,
148052217195SDaniel Vetter 				   "TILE", 0);
148152217195SDaniel Vetter 	if (!prop)
148252217195SDaniel Vetter 		return -ENOMEM;
148352217195SDaniel Vetter 	dev->mode_config.tile_property = prop;
148452217195SDaniel Vetter 
148540ee6fbeSManasi Navare 	prop = drm_property_create_enum(dev, 0, "link-status",
148640ee6fbeSManasi Navare 					drm_link_status_enum_list,
148740ee6fbeSManasi Navare 					ARRAY_SIZE(drm_link_status_enum_list));
148840ee6fbeSManasi Navare 	if (!prop)
148940ee6fbeSManasi Navare 		return -ENOMEM;
149040ee6fbeSManasi Navare 	dev->mode_config.link_status_property = prop;
149140ee6fbeSManasi Navare 
149266660d4cSDave Airlie 	prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
149366660d4cSDave Airlie 	if (!prop)
149466660d4cSDave Airlie 		return -ENOMEM;
149566660d4cSDave Airlie 	dev->mode_config.non_desktop_property = prop;
149666660d4cSDave Airlie 
1497fbb5d035SUma Shankar 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
1498fbb5d035SUma Shankar 				   "HDR_OUTPUT_METADATA", 0);
1499fbb5d035SUma Shankar 	if (!prop)
1500fbb5d035SUma Shankar 		return -ENOMEM;
1501fbb5d035SUma Shankar 	dev->mode_config.hdr_output_metadata_property = prop;
1502fbb5d035SUma Shankar 
150352217195SDaniel Vetter 	return 0;
150452217195SDaniel Vetter }
150552217195SDaniel Vetter 
150652217195SDaniel Vetter /**
150752217195SDaniel Vetter  * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
150852217195SDaniel Vetter  * @dev: DRM device
150952217195SDaniel Vetter  *
151052217195SDaniel Vetter  * Called by a driver the first time a DVI-I connector is made.
1511f85d9e59SRandy Dunlap  *
1512f85d9e59SRandy Dunlap  * Returns: %0
151352217195SDaniel Vetter  */
151452217195SDaniel Vetter int drm_mode_create_dvi_i_properties(struct drm_device *dev)
151552217195SDaniel Vetter {
151652217195SDaniel Vetter 	struct drm_property *dvi_i_selector;
151752217195SDaniel Vetter 	struct drm_property *dvi_i_subconnector;
151852217195SDaniel Vetter 
151952217195SDaniel Vetter 	if (dev->mode_config.dvi_i_select_subconnector_property)
152052217195SDaniel Vetter 		return 0;
152152217195SDaniel Vetter 
152252217195SDaniel Vetter 	dvi_i_selector =
152352217195SDaniel Vetter 		drm_property_create_enum(dev, 0,
152452217195SDaniel Vetter 				    "select subconnector",
152552217195SDaniel Vetter 				    drm_dvi_i_select_enum_list,
152652217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_select_enum_list));
152752217195SDaniel Vetter 	dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
152852217195SDaniel Vetter 
152952217195SDaniel Vetter 	dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
153052217195SDaniel Vetter 				    "subconnector",
153152217195SDaniel Vetter 				    drm_dvi_i_subconnector_enum_list,
153252217195SDaniel Vetter 				    ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
153352217195SDaniel Vetter 	dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
153452217195SDaniel Vetter 
153552217195SDaniel Vetter 	return 0;
153652217195SDaniel Vetter }
153752217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
153852217195SDaniel Vetter 
153952217195SDaniel Vetter /**
1540e5b92773SOleg Vasilev  * drm_connector_attach_dp_subconnector_property - create subconnector property for DP
1541e5b92773SOleg Vasilev  * @connector: drm_connector to attach property
1542e5b92773SOleg Vasilev  *
1543e5b92773SOleg Vasilev  * Called by a driver when DP connector is created.
1544e5b92773SOleg Vasilev  */
1545e5b92773SOleg Vasilev void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector)
1546e5b92773SOleg Vasilev {
1547e5b92773SOleg Vasilev 	struct drm_mode_config *mode_config = &connector->dev->mode_config;
1548e5b92773SOleg Vasilev 
1549e5b92773SOleg Vasilev 	if (!mode_config->dp_subconnector_property)
1550e5b92773SOleg Vasilev 		mode_config->dp_subconnector_property =
1551e5b92773SOleg Vasilev 			drm_property_create_enum(connector->dev,
1552e5b92773SOleg Vasilev 				DRM_MODE_PROP_IMMUTABLE,
1553e5b92773SOleg Vasilev 				"subconnector",
1554e5b92773SOleg Vasilev 				drm_dp_subconnector_enum_list,
1555e5b92773SOleg Vasilev 				ARRAY_SIZE(drm_dp_subconnector_enum_list));
1556e5b92773SOleg Vasilev 
1557e5b92773SOleg Vasilev 	drm_object_attach_property(&connector->base,
1558e5b92773SOleg Vasilev 				   mode_config->dp_subconnector_property,
1559e5b92773SOleg Vasilev 				   DRM_MODE_SUBCONNECTOR_Unknown);
1560e5b92773SOleg Vasilev }
1561e5b92773SOleg Vasilev EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property);
1562e5b92773SOleg Vasilev 
1563e5b92773SOleg Vasilev /**
156450525c33SStanislav Lisovskiy  * DOC: HDMI connector properties
156550525c33SStanislav Lisovskiy  *
156650525c33SStanislav Lisovskiy  * content type (HDMI specific):
156750525c33SStanislav Lisovskiy  *	Indicates content type setting to be used in HDMI infoframes to indicate
15681e55a53aSMatt Roper  *	content type for the external device, so that it adjusts its display
156950525c33SStanislav Lisovskiy  *	settings accordingly.
157050525c33SStanislav Lisovskiy  *
157150525c33SStanislav Lisovskiy  *	The value of this property can be one of the following:
157250525c33SStanislav Lisovskiy  *
157350525c33SStanislav Lisovskiy  *	No Data:
157450525c33SStanislav Lisovskiy  *		Content type is unknown
157550525c33SStanislav Lisovskiy  *	Graphics:
157650525c33SStanislav Lisovskiy  *		Content type is graphics
157750525c33SStanislav Lisovskiy  *	Photo:
157850525c33SStanislav Lisovskiy  *		Content type is photo
157950525c33SStanislav Lisovskiy  *	Cinema:
158050525c33SStanislav Lisovskiy  *		Content type is cinema
158150525c33SStanislav Lisovskiy  *	Game:
158250525c33SStanislav Lisovskiy  *		Content type is game
158350525c33SStanislav Lisovskiy  *
1584a0a33067SSimon Ser  *	The meaning of each content type is defined in CTA-861-G table 15.
1585a0a33067SSimon Ser  *
158650525c33SStanislav Lisovskiy  *	Drivers can set up this property by calling
158750525c33SStanislav Lisovskiy  *	drm_connector_attach_content_type_property(). Decoding to
1588ba609631SDaniel Vetter  *	infoframe values is done through drm_hdmi_avi_infoframe_content_type().
158950525c33SStanislav Lisovskiy  */
159050525c33SStanislav Lisovskiy 
15917d63cd85SMaxime Ripard /*
15927d63cd85SMaxime Ripard  * TODO: Document the properties:
15937d63cd85SMaxime Ripard  *   - left margin
15947d63cd85SMaxime Ripard  *   - right margin
15957d63cd85SMaxime Ripard  *   - top margin
15967d63cd85SMaxime Ripard  *   - bottom margin
15977d63cd85SMaxime Ripard  *   - brightness
15987d63cd85SMaxime Ripard  *   - contrast
15997d63cd85SMaxime Ripard  *   - flicker reduction
16007d63cd85SMaxime Ripard  *   - hue
16017d63cd85SMaxime Ripard  *   - mode
16027d63cd85SMaxime Ripard  *   - overscan
16037d63cd85SMaxime Ripard  *   - saturation
16047d63cd85SMaxime Ripard  *   - select subconnector
16057d63cd85SMaxime Ripard  *   - subconnector
16067d63cd85SMaxime Ripard  */
16077d63cd85SMaxime Ripard /**
16087d63cd85SMaxime Ripard  * DOC: Analog TV Connector Properties
16097d63cd85SMaxime Ripard  *
16107d63cd85SMaxime Ripard  * TV Mode:
16117d63cd85SMaxime Ripard  *	Indicates the TV Mode used on an analog TV connector. The value
16127d63cd85SMaxime Ripard  *	of this property can be one of the following:
16137d63cd85SMaxime Ripard  *
16147d63cd85SMaxime Ripard  *	NTSC:
16157d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
16167d63cd85SMaxime Ripard  *		the NTSC Color Encoding.
16177d63cd85SMaxime Ripard  *
16187d63cd85SMaxime Ripard  *	NTSC-443:
16197d63cd85SMaxime Ripard  *
16207d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
16217d63cd85SMaxime Ripard  *		the NTSC Color Encoding, but with a color subcarrier
16227d63cd85SMaxime Ripard  *		frequency of 4.43MHz
16237d63cd85SMaxime Ripard  *
16247d63cd85SMaxime Ripard  *	NTSC-J:
16257d63cd85SMaxime Ripard  *
16267d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
16277d63cd85SMaxime Ripard  *		the NTSC Color Encoding, but with a black level equal to
16287d63cd85SMaxime Ripard  *		the blanking level.
16297d63cd85SMaxime Ripard  *
16307d63cd85SMaxime Ripard  *	PAL:
16317d63cd85SMaxime Ripard  *
16327d63cd85SMaxime Ripard  *		TV Mode is CCIR System B (aka 625-lines) together with
16337d63cd85SMaxime Ripard  *		the PAL Color Encoding.
16347d63cd85SMaxime Ripard  *
16357d63cd85SMaxime Ripard  *	PAL-M:
16367d63cd85SMaxime Ripard  *
16377d63cd85SMaxime Ripard  *		TV Mode is CCIR System M (aka 525-lines) together with
16387d63cd85SMaxime Ripard  *		the PAL Color Encoding.
16397d63cd85SMaxime Ripard  *
16407d63cd85SMaxime Ripard  *	PAL-N:
16417d63cd85SMaxime Ripard  *
16427d63cd85SMaxime Ripard  *		TV Mode is CCIR System N together with the PAL Color
16437d63cd85SMaxime Ripard  *		Encoding, a color subcarrier frequency of 3.58MHz, the
16447d63cd85SMaxime Ripard  *		SECAM color space, and narrower channels than other PAL
16457d63cd85SMaxime Ripard  *		variants.
16467d63cd85SMaxime Ripard  *
16477d63cd85SMaxime Ripard  *	SECAM:
16487d63cd85SMaxime Ripard  *
16497d63cd85SMaxime Ripard  *		TV Mode is CCIR System B (aka 625-lines) together with
16507d63cd85SMaxime Ripard  *		the SECAM Color Encoding.
16517d63cd85SMaxime Ripard  *
16527d63cd85SMaxime Ripard  *	Drivers can set up this property by calling
16537d63cd85SMaxime Ripard  *	drm_mode_create_tv_properties().
16547d63cd85SMaxime Ripard  */
16557d63cd85SMaxime Ripard 
165650525c33SStanislav Lisovskiy /**
165750525c33SStanislav Lisovskiy  * drm_connector_attach_content_type_property - attach content-type property
165850525c33SStanislav Lisovskiy  * @connector: connector to attach content type property on.
165950525c33SStanislav Lisovskiy  *
166050525c33SStanislav Lisovskiy  * Called by a driver the first time a HDMI connector is made.
1661f85d9e59SRandy Dunlap  *
1662f85d9e59SRandy Dunlap  * Returns: %0
166350525c33SStanislav Lisovskiy  */
166450525c33SStanislav Lisovskiy int drm_connector_attach_content_type_property(struct drm_connector *connector)
166550525c33SStanislav Lisovskiy {
166650525c33SStanislav Lisovskiy 	if (!drm_mode_create_content_type_property(connector->dev))
166750525c33SStanislav Lisovskiy 		drm_object_attach_property(&connector->base,
166850525c33SStanislav Lisovskiy 					   connector->dev->mode_config.content_type_property,
166950525c33SStanislav Lisovskiy 					   DRM_MODE_CONTENT_TYPE_NO_DATA);
167050525c33SStanislav Lisovskiy 	return 0;
167150525c33SStanislav Lisovskiy }
167250525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_connector_attach_content_type_property);
167350525c33SStanislav Lisovskiy 
167450525c33SStanislav Lisovskiy /**
1675e9d2871fSMauro Carvalho Chehab  * drm_connector_attach_tv_margin_properties - attach TV connector margin
1676e9d2871fSMauro Carvalho Chehab  * 	properties
16776c4f52dcSBoris Brezillon  * @connector: DRM connector
16786c4f52dcSBoris Brezillon  *
16796c4f52dcSBoris Brezillon  * Called by a driver when it needs to attach TV margin props to a connector.
16806c4f52dcSBoris Brezillon  * Typically used on SDTV and HDMI connectors.
16816c4f52dcSBoris Brezillon  */
16826c4f52dcSBoris Brezillon void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
16836c4f52dcSBoris Brezillon {
16846c4f52dcSBoris Brezillon 	struct drm_device *dev = connector->dev;
16856c4f52dcSBoris Brezillon 
16866c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
16876c4f52dcSBoris Brezillon 				   dev->mode_config.tv_left_margin_property,
16886c4f52dcSBoris Brezillon 				   0);
16896c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
16906c4f52dcSBoris Brezillon 				   dev->mode_config.tv_right_margin_property,
16916c4f52dcSBoris Brezillon 				   0);
16926c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
16936c4f52dcSBoris Brezillon 				   dev->mode_config.tv_top_margin_property,
16946c4f52dcSBoris Brezillon 				   0);
16956c4f52dcSBoris Brezillon 	drm_object_attach_property(&connector->base,
16966c4f52dcSBoris Brezillon 				   dev->mode_config.tv_bottom_margin_property,
16976c4f52dcSBoris Brezillon 				   0);
16986c4f52dcSBoris Brezillon }
16996c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
17006c4f52dcSBoris Brezillon 
17016c4f52dcSBoris Brezillon /**
17026c4f52dcSBoris Brezillon  * drm_mode_create_tv_margin_properties - create TV connector margin properties
17036c4f52dcSBoris Brezillon  * @dev: DRM device
17046c4f52dcSBoris Brezillon  *
17056c4f52dcSBoris Brezillon  * Called by a driver's HDMI connector initialization routine, this function
17066c4f52dcSBoris Brezillon  * creates the TV margin properties for a given device. No need to call this
17076c4f52dcSBoris Brezillon  * function for an SDTV connector, it's already called from
170880ed86d4SMaxime Ripard  * drm_mode_create_tv_properties_legacy().
1709f85d9e59SRandy Dunlap  *
1710f85d9e59SRandy Dunlap  * Returns:
1711f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
17126c4f52dcSBoris Brezillon  */
17136c4f52dcSBoris Brezillon int drm_mode_create_tv_margin_properties(struct drm_device *dev)
17146c4f52dcSBoris Brezillon {
17156c4f52dcSBoris Brezillon 	if (dev->mode_config.tv_left_margin_property)
17166c4f52dcSBoris Brezillon 		return 0;
17176c4f52dcSBoris Brezillon 
17186c4f52dcSBoris Brezillon 	dev->mode_config.tv_left_margin_property =
17196c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "left margin", 0, 100);
17206c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_left_margin_property)
17216c4f52dcSBoris Brezillon 		return -ENOMEM;
17226c4f52dcSBoris Brezillon 
17236c4f52dcSBoris Brezillon 	dev->mode_config.tv_right_margin_property =
17246c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "right margin", 0, 100);
17256c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_right_margin_property)
17266c4f52dcSBoris Brezillon 		return -ENOMEM;
17276c4f52dcSBoris Brezillon 
17286c4f52dcSBoris Brezillon 	dev->mode_config.tv_top_margin_property =
17296c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "top margin", 0, 100);
17306c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_top_margin_property)
17316c4f52dcSBoris Brezillon 		return -ENOMEM;
17326c4f52dcSBoris Brezillon 
17336c4f52dcSBoris Brezillon 	dev->mode_config.tv_bottom_margin_property =
17346c4f52dcSBoris Brezillon 		drm_property_create_range(dev, 0, "bottom margin", 0, 100);
17356c4f52dcSBoris Brezillon 	if (!dev->mode_config.tv_bottom_margin_property)
17366c4f52dcSBoris Brezillon 		return -ENOMEM;
17376c4f52dcSBoris Brezillon 
17386c4f52dcSBoris Brezillon 	return 0;
17396c4f52dcSBoris Brezillon }
17406c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
17416c4f52dcSBoris Brezillon 
17426c4f52dcSBoris Brezillon /**
174380ed86d4SMaxime Ripard  * drm_mode_create_tv_properties_legacy - create TV specific connector properties
174452217195SDaniel Vetter  * @dev: DRM device
174552217195SDaniel Vetter  * @num_modes: number of different TV formats (modes) supported
174652217195SDaniel Vetter  * @modes: array of pointers to strings containing name of each format
174752217195SDaniel Vetter  *
174852217195SDaniel Vetter  * Called by a driver's TV initialization routine, this function creates
174952217195SDaniel Vetter  * the TV specific connector properties for a given device.  Caller is
175052217195SDaniel Vetter  * responsible for allocating a list of format names and passing them to
175152217195SDaniel Vetter  * this routine.
1752f85d9e59SRandy Dunlap  *
17537d63cd85SMaxime Ripard  * NOTE: This functions registers the deprecated "mode" connector
17547d63cd85SMaxime Ripard  * property to select the analog TV mode (ie, NTSC, PAL, etc.). New
17557d63cd85SMaxime Ripard  * drivers must use drm_mode_create_tv_properties() instead.
17567d63cd85SMaxime Ripard  *
1757f85d9e59SRandy Dunlap  * Returns:
1758f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
175952217195SDaniel Vetter  */
176080ed86d4SMaxime Ripard int drm_mode_create_tv_properties_legacy(struct drm_device *dev,
176152217195SDaniel Vetter 					 unsigned int num_modes,
176252217195SDaniel Vetter 					 const char * const modes[])
176352217195SDaniel Vetter {
176452217195SDaniel Vetter 	struct drm_property *tv_selector;
176552217195SDaniel Vetter 	struct drm_property *tv_subconnector;
176652217195SDaniel Vetter 	unsigned int i;
176752217195SDaniel Vetter 
176852217195SDaniel Vetter 	if (dev->mode_config.tv_select_subconnector_property)
176952217195SDaniel Vetter 		return 0;
177052217195SDaniel Vetter 
177152217195SDaniel Vetter 	/*
177252217195SDaniel Vetter 	 * Basic connector properties
177352217195SDaniel Vetter 	 */
177452217195SDaniel Vetter 	tv_selector = drm_property_create_enum(dev, 0,
177552217195SDaniel Vetter 					  "select subconnector",
177652217195SDaniel Vetter 					  drm_tv_select_enum_list,
177752217195SDaniel Vetter 					  ARRAY_SIZE(drm_tv_select_enum_list));
177852217195SDaniel Vetter 	if (!tv_selector)
177952217195SDaniel Vetter 		goto nomem;
178052217195SDaniel Vetter 
178152217195SDaniel Vetter 	dev->mode_config.tv_select_subconnector_property = tv_selector;
178252217195SDaniel Vetter 
178352217195SDaniel Vetter 	tv_subconnector =
178452217195SDaniel Vetter 		drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
178552217195SDaniel Vetter 				    "subconnector",
178652217195SDaniel Vetter 				    drm_tv_subconnector_enum_list,
178752217195SDaniel Vetter 				    ARRAY_SIZE(drm_tv_subconnector_enum_list));
178852217195SDaniel Vetter 	if (!tv_subconnector)
178952217195SDaniel Vetter 		goto nomem;
179052217195SDaniel Vetter 	dev->mode_config.tv_subconnector_property = tv_subconnector;
179152217195SDaniel Vetter 
179252217195SDaniel Vetter 	/*
179352217195SDaniel Vetter 	 * Other, TV specific properties: margins & TV modes.
179452217195SDaniel Vetter 	 */
17956c4f52dcSBoris Brezillon 	if (drm_mode_create_tv_margin_properties(dev))
179652217195SDaniel Vetter 		goto nomem;
179752217195SDaniel Vetter 
1798aab5aaa7SMaxime Ripard 	if (num_modes) {
17991fd4a5a3SMaxime Ripard 		dev->mode_config.legacy_tv_mode_property =
180052217195SDaniel Vetter 			drm_property_create(dev, DRM_MODE_PROP_ENUM,
180152217195SDaniel Vetter 					    "mode", num_modes);
18021fd4a5a3SMaxime Ripard 		if (!dev->mode_config.legacy_tv_mode_property)
180352217195SDaniel Vetter 			goto nomem;
180452217195SDaniel Vetter 
180552217195SDaniel Vetter 		for (i = 0; i < num_modes; i++)
18061fd4a5a3SMaxime Ripard 			drm_property_add_enum(dev->mode_config.legacy_tv_mode_property,
180752217195SDaniel Vetter 					      i, modes[i]);
1808aab5aaa7SMaxime Ripard 	}
180952217195SDaniel Vetter 
181052217195SDaniel Vetter 	dev->mode_config.tv_brightness_property =
181152217195SDaniel Vetter 		drm_property_create_range(dev, 0, "brightness", 0, 100);
181252217195SDaniel Vetter 	if (!dev->mode_config.tv_brightness_property)
181352217195SDaniel Vetter 		goto nomem;
181452217195SDaniel Vetter 
181552217195SDaniel Vetter 	dev->mode_config.tv_contrast_property =
181652217195SDaniel Vetter 		drm_property_create_range(dev, 0, "contrast", 0, 100);
181752217195SDaniel Vetter 	if (!dev->mode_config.tv_contrast_property)
181852217195SDaniel Vetter 		goto nomem;
181952217195SDaniel Vetter 
182052217195SDaniel Vetter 	dev->mode_config.tv_flicker_reduction_property =
182152217195SDaniel Vetter 		drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
182252217195SDaniel Vetter 	if (!dev->mode_config.tv_flicker_reduction_property)
182352217195SDaniel Vetter 		goto nomem;
182452217195SDaniel Vetter 
182552217195SDaniel Vetter 	dev->mode_config.tv_overscan_property =
182652217195SDaniel Vetter 		drm_property_create_range(dev, 0, "overscan", 0, 100);
182752217195SDaniel Vetter 	if (!dev->mode_config.tv_overscan_property)
182852217195SDaniel Vetter 		goto nomem;
182952217195SDaniel Vetter 
183052217195SDaniel Vetter 	dev->mode_config.tv_saturation_property =
183152217195SDaniel Vetter 		drm_property_create_range(dev, 0, "saturation", 0, 100);
183252217195SDaniel Vetter 	if (!dev->mode_config.tv_saturation_property)
183352217195SDaniel Vetter 		goto nomem;
183452217195SDaniel Vetter 
183552217195SDaniel Vetter 	dev->mode_config.tv_hue_property =
183652217195SDaniel Vetter 		drm_property_create_range(dev, 0, "hue", 0, 100);
183752217195SDaniel Vetter 	if (!dev->mode_config.tv_hue_property)
183852217195SDaniel Vetter 		goto nomem;
183952217195SDaniel Vetter 
184052217195SDaniel Vetter 	return 0;
184152217195SDaniel Vetter nomem:
184252217195SDaniel Vetter 	return -ENOMEM;
184352217195SDaniel Vetter }
184480ed86d4SMaxime Ripard EXPORT_SYMBOL(drm_mode_create_tv_properties_legacy);
184552217195SDaniel Vetter 
184652217195SDaniel Vetter /**
18477d63cd85SMaxime Ripard  * drm_mode_create_tv_properties - create TV specific connector properties
18487d63cd85SMaxime Ripard  * @dev: DRM device
18497d63cd85SMaxime Ripard  * @supported_tv_modes: Bitmask of TV modes supported (See DRM_MODE_TV_MODE_*)
185004ee2767SRandy Dunlap  *
18517d63cd85SMaxime Ripard  * Called by a driver's TV initialization routine, this function creates
18527d63cd85SMaxime Ripard  * the TV specific connector properties for a given device.
18537d63cd85SMaxime Ripard  *
18547d63cd85SMaxime Ripard  * Returns:
18557d63cd85SMaxime Ripard  * 0 on success or a negative error code on failure.
18567d63cd85SMaxime Ripard  */
18577d63cd85SMaxime Ripard int drm_mode_create_tv_properties(struct drm_device *dev,
18587d63cd85SMaxime Ripard 				  unsigned int supported_tv_modes)
18597d63cd85SMaxime Ripard {
18607d63cd85SMaxime Ripard 	struct drm_prop_enum_list tv_mode_list[DRM_MODE_TV_MODE_MAX];
18617d63cd85SMaxime Ripard 	struct drm_property *tv_mode;
18627d63cd85SMaxime Ripard 	unsigned int i, len = 0;
18637d63cd85SMaxime Ripard 
18647d63cd85SMaxime Ripard 	if (dev->mode_config.tv_mode_property)
18657d63cd85SMaxime Ripard 		return 0;
18667d63cd85SMaxime Ripard 
18677d63cd85SMaxime Ripard 	for (i = 0; i < DRM_MODE_TV_MODE_MAX; i++) {
18687d63cd85SMaxime Ripard 		if (!(supported_tv_modes & BIT(i)))
18697d63cd85SMaxime Ripard 			continue;
18707d63cd85SMaxime Ripard 
18717d63cd85SMaxime Ripard 		tv_mode_list[len].type = i;
18727d63cd85SMaxime Ripard 		tv_mode_list[len].name = drm_get_tv_mode_name(i);
18737d63cd85SMaxime Ripard 		len++;
18747d63cd85SMaxime Ripard 	}
18757d63cd85SMaxime Ripard 
18767d63cd85SMaxime Ripard 	tv_mode = drm_property_create_enum(dev, 0, "TV mode",
18777d63cd85SMaxime Ripard 					   tv_mode_list, len);
18787d63cd85SMaxime Ripard 	if (!tv_mode)
18797d63cd85SMaxime Ripard 		return -ENOMEM;
18807d63cd85SMaxime Ripard 
18817d63cd85SMaxime Ripard 	dev->mode_config.tv_mode_property = tv_mode;
18827d63cd85SMaxime Ripard 
18837d63cd85SMaxime Ripard 	return drm_mode_create_tv_properties_legacy(dev, 0, NULL);
18847d63cd85SMaxime Ripard }
18857d63cd85SMaxime Ripard EXPORT_SYMBOL(drm_mode_create_tv_properties);
18867d63cd85SMaxime Ripard 
18877d63cd85SMaxime Ripard /**
188852217195SDaniel Vetter  * drm_mode_create_scaling_mode_property - create scaling mode property
188952217195SDaniel Vetter  * @dev: DRM device
189052217195SDaniel Vetter  *
189152217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
189252217195SDaniel Vetter  * connectors.
18938f6e1e22SMaarten Lankhorst  *
18948f6e1e22SMaarten Lankhorst  * Atomic drivers should use drm_connector_attach_scaling_mode_property()
18959c2fce13SVille Syrjälä  * instead to correctly assign &drm_connector_state.scaling_mode
18968f6e1e22SMaarten Lankhorst  * in the atomic state.
1897f85d9e59SRandy Dunlap  *
1898f85d9e59SRandy Dunlap  * Returns: %0
189952217195SDaniel Vetter  */
190052217195SDaniel Vetter int drm_mode_create_scaling_mode_property(struct drm_device *dev)
190152217195SDaniel Vetter {
190252217195SDaniel Vetter 	struct drm_property *scaling_mode;
190352217195SDaniel Vetter 
190452217195SDaniel Vetter 	if (dev->mode_config.scaling_mode_property)
190552217195SDaniel Vetter 		return 0;
190652217195SDaniel Vetter 
190752217195SDaniel Vetter 	scaling_mode =
190852217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "scaling mode",
190952217195SDaniel Vetter 				drm_scaling_mode_enum_list,
191052217195SDaniel Vetter 				    ARRAY_SIZE(drm_scaling_mode_enum_list));
191152217195SDaniel Vetter 
191252217195SDaniel Vetter 	dev->mode_config.scaling_mode_property = scaling_mode;
191352217195SDaniel Vetter 
191452217195SDaniel Vetter 	return 0;
191552217195SDaniel Vetter }
191652217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
191752217195SDaniel Vetter 
191852217195SDaniel Vetter /**
1919ab7a664fSNicholas Kazlauskas  * DOC: Variable refresh properties
1920ab7a664fSNicholas Kazlauskas  *
1921ab7a664fSNicholas Kazlauskas  * Variable refresh rate capable displays can dynamically adjust their
1922ab7a664fSNicholas Kazlauskas  * refresh rate by extending the duration of their vertical front porch
1923ab7a664fSNicholas Kazlauskas  * until page flip or timeout occurs. This can reduce or remove stuttering
1924ab7a664fSNicholas Kazlauskas  * and latency in scenarios where the page flip does not align with the
1925ab7a664fSNicholas Kazlauskas  * vblank interval.
1926ab7a664fSNicholas Kazlauskas  *
1927ab7a664fSNicholas Kazlauskas  * An example scenario would be an application flipping at a constant rate
1928ab7a664fSNicholas Kazlauskas  * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
1929ab7a664fSNicholas Kazlauskas  * interval and the same contents will be displayed twice. This can be
1930ab7a664fSNicholas Kazlauskas  * observed as stuttering for content with motion.
1931ab7a664fSNicholas Kazlauskas  *
1932ab7a664fSNicholas Kazlauskas  * If variable refresh rate was active on a display that supported a
1933ab7a664fSNicholas Kazlauskas  * variable refresh range from 35Hz to 60Hz no stuttering would be observable
1934ab7a664fSNicholas Kazlauskas  * for the example scenario. The minimum supported variable refresh rate of
1935ab7a664fSNicholas Kazlauskas  * 35Hz is below the page flip frequency and the vertical front porch can
1936ab7a664fSNicholas Kazlauskas  * be extended until the page flip occurs. The vblank interval will be
1937ab7a664fSNicholas Kazlauskas  * directly aligned to the page flip rate.
1938ab7a664fSNicholas Kazlauskas  *
1939ab7a664fSNicholas Kazlauskas  * Not all userspace content is suitable for use with variable refresh rate.
1940ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may worsen
1941ab7a664fSNicholas Kazlauskas  * perceived stuttering for input sensitive applications.
1942ab7a664fSNicholas Kazlauskas  *
1943ab7a664fSNicholas Kazlauskas  * Panel brightness will also vary with vertical front porch duration. Some
1944ab7a664fSNicholas Kazlauskas  * panels may have noticeable differences in brightness between the minimum
1945ab7a664fSNicholas Kazlauskas  * vertical front porch duration and the maximum vertical front porch duration.
1946ab7a664fSNicholas Kazlauskas  * Large and frequent changes in vertical front porch duration may produce
1947ab7a664fSNicholas Kazlauskas  * observable flickering for such panels.
1948ab7a664fSNicholas Kazlauskas  *
1949ab7a664fSNicholas Kazlauskas  * Userspace control for variable refresh rate is supported via properties
1950ab7a664fSNicholas Kazlauskas  * on the &drm_connector and &drm_crtc objects.
1951ab7a664fSNicholas Kazlauskas  *
1952ab7a664fSNicholas Kazlauskas  * "vrr_capable":
1953ab7a664fSNicholas Kazlauskas  *	Optional &drm_connector boolean property that drivers should attach
1954ab7a664fSNicholas Kazlauskas  *	with drm_connector_attach_vrr_capable_property() on connectors that
1955ab7a664fSNicholas Kazlauskas  *	could support variable refresh rates. Drivers should update the
1956ab7a664fSNicholas Kazlauskas  *	property value by calling drm_connector_set_vrr_capable_property().
1957ab7a664fSNicholas Kazlauskas  *
1958ab7a664fSNicholas Kazlauskas  *	Absence of the property should indicate absence of support.
1959ab7a664fSNicholas Kazlauskas  *
196077086014SDaniel Vetter  * "VRR_ENABLED":
1961ab7a664fSNicholas Kazlauskas  *	Default &drm_crtc boolean property that notifies the driver that the
1962ab7a664fSNicholas Kazlauskas  *	content on the CRTC is suitable for variable refresh rate presentation.
1963ab7a664fSNicholas Kazlauskas  *	The driver will take this property as a hint to enable variable
1964ab7a664fSNicholas Kazlauskas  *	refresh rate support if the receiver supports it, ie. if the
1965ab7a664fSNicholas Kazlauskas  *	"vrr_capable" property is true on the &drm_connector object. The
1966ab7a664fSNicholas Kazlauskas  *	vertical front porch duration will be extended until page-flip or
1967ab7a664fSNicholas Kazlauskas  *	timeout when enabled.
1968ab7a664fSNicholas Kazlauskas  *
1969ab7a664fSNicholas Kazlauskas  *	The minimum vertical front porch duration is defined as the vertical
1970ab7a664fSNicholas Kazlauskas  *	front porch duration for the current mode.
1971ab7a664fSNicholas Kazlauskas  *
1972ab7a664fSNicholas Kazlauskas  *	The maximum vertical front porch duration is greater than or equal to
1973ab7a664fSNicholas Kazlauskas  *	the minimum vertical front porch duration. The duration is derived
1974ab7a664fSNicholas Kazlauskas  *	from the minimum supported variable refresh rate for the connector.
1975ab7a664fSNicholas Kazlauskas  *
1976ab7a664fSNicholas Kazlauskas  *	The driver may place further restrictions within these minimum
1977ab7a664fSNicholas Kazlauskas  *	and maximum bounds.
1978ab7a664fSNicholas Kazlauskas  */
1979ab7a664fSNicholas Kazlauskas 
1980ab7a664fSNicholas Kazlauskas /**
1981ba1b0f6cSNicholas Kazlauskas  * drm_connector_attach_vrr_capable_property - creates the
1982ba1b0f6cSNicholas Kazlauskas  * vrr_capable property
1983ba1b0f6cSNicholas Kazlauskas  * @connector: connector to create the vrr_capable property on.
1984ba1b0f6cSNicholas Kazlauskas  *
1985ba1b0f6cSNicholas Kazlauskas  * This is used by atomic drivers to add support for querying
1986ba1b0f6cSNicholas Kazlauskas  * variable refresh rate capability for a connector.
1987ba1b0f6cSNicholas Kazlauskas  *
1988ba1b0f6cSNicholas Kazlauskas  * Returns:
198984e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
1990ba1b0f6cSNicholas Kazlauskas  */
1991ba1b0f6cSNicholas Kazlauskas int drm_connector_attach_vrr_capable_property(
1992ba1b0f6cSNicholas Kazlauskas 	struct drm_connector *connector)
1993ba1b0f6cSNicholas Kazlauskas {
1994ba1b0f6cSNicholas Kazlauskas 	struct drm_device *dev = connector->dev;
1995ba1b0f6cSNicholas Kazlauskas 	struct drm_property *prop;
1996ba1b0f6cSNicholas Kazlauskas 
1997ba1b0f6cSNicholas Kazlauskas 	if (!connector->vrr_capable_property) {
1998ba1b0f6cSNicholas Kazlauskas 		prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
1999ba1b0f6cSNicholas Kazlauskas 			"vrr_capable");
2000ba1b0f6cSNicholas Kazlauskas 		if (!prop)
2001ba1b0f6cSNicholas Kazlauskas 			return -ENOMEM;
2002ba1b0f6cSNicholas Kazlauskas 
2003ba1b0f6cSNicholas Kazlauskas 		connector->vrr_capable_property = prop;
2004ba1b0f6cSNicholas Kazlauskas 		drm_object_attach_property(&connector->base, prop, 0);
2005ba1b0f6cSNicholas Kazlauskas 	}
2006ba1b0f6cSNicholas Kazlauskas 
2007ba1b0f6cSNicholas Kazlauskas 	return 0;
2008ba1b0f6cSNicholas Kazlauskas }
2009ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
2010ba1b0f6cSNicholas Kazlauskas 
2011ba1b0f6cSNicholas Kazlauskas /**
20128f6e1e22SMaarten Lankhorst  * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
20138f6e1e22SMaarten Lankhorst  * @connector: connector to attach scaling mode property on.
20148f6e1e22SMaarten Lankhorst  * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
20158f6e1e22SMaarten Lankhorst  *
20168f6e1e22SMaarten Lankhorst  * This is used to add support for scaling mode to atomic drivers.
20179c2fce13SVille Syrjälä  * The scaling mode will be set to &drm_connector_state.scaling_mode
20188f6e1e22SMaarten Lankhorst  * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
20198f6e1e22SMaarten Lankhorst  *
20208f6e1e22SMaarten Lankhorst  * This is the atomic version of drm_mode_create_scaling_mode_property().
20218f6e1e22SMaarten Lankhorst  *
20228f6e1e22SMaarten Lankhorst  * Returns:
20238f6e1e22SMaarten Lankhorst  * Zero on success, negative errno on failure.
20248f6e1e22SMaarten Lankhorst  */
20258f6e1e22SMaarten Lankhorst int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
20268f6e1e22SMaarten Lankhorst 					       u32 scaling_mode_mask)
20278f6e1e22SMaarten Lankhorst {
20288f6e1e22SMaarten Lankhorst 	struct drm_device *dev = connector->dev;
20298f6e1e22SMaarten Lankhorst 	struct drm_property *scaling_mode_property;
203030e9db6dSVille Syrjälä 	int i;
20318f6e1e22SMaarten Lankhorst 	const unsigned valid_scaling_mode_mask =
20328f6e1e22SMaarten Lankhorst 		(1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
20338f6e1e22SMaarten Lankhorst 
20348f6e1e22SMaarten Lankhorst 	if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
20358f6e1e22SMaarten Lankhorst 		    scaling_mode_mask & ~valid_scaling_mode_mask))
20368f6e1e22SMaarten Lankhorst 		return -EINVAL;
20378f6e1e22SMaarten Lankhorst 
20388f6e1e22SMaarten Lankhorst 	scaling_mode_property =
20398f6e1e22SMaarten Lankhorst 		drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
20408f6e1e22SMaarten Lankhorst 				    hweight32(scaling_mode_mask));
20418f6e1e22SMaarten Lankhorst 
20428f6e1e22SMaarten Lankhorst 	if (!scaling_mode_property)
20438f6e1e22SMaarten Lankhorst 		return -ENOMEM;
20448f6e1e22SMaarten Lankhorst 
20458f6e1e22SMaarten Lankhorst 	for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
20468f6e1e22SMaarten Lankhorst 		int ret;
20478f6e1e22SMaarten Lankhorst 
20488f6e1e22SMaarten Lankhorst 		if (!(BIT(i) & scaling_mode_mask))
20498f6e1e22SMaarten Lankhorst 			continue;
20508f6e1e22SMaarten Lankhorst 
205130e9db6dSVille Syrjälä 		ret = drm_property_add_enum(scaling_mode_property,
20528f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].type,
20538f6e1e22SMaarten Lankhorst 					    drm_scaling_mode_enum_list[i].name);
20548f6e1e22SMaarten Lankhorst 
20558f6e1e22SMaarten Lankhorst 		if (ret) {
20568f6e1e22SMaarten Lankhorst 			drm_property_destroy(dev, scaling_mode_property);
20578f6e1e22SMaarten Lankhorst 
20588f6e1e22SMaarten Lankhorst 			return ret;
20598f6e1e22SMaarten Lankhorst 		}
20608f6e1e22SMaarten Lankhorst 	}
20618f6e1e22SMaarten Lankhorst 
20628f6e1e22SMaarten Lankhorst 	drm_object_attach_property(&connector->base,
20638f6e1e22SMaarten Lankhorst 				   scaling_mode_property, 0);
20648f6e1e22SMaarten Lankhorst 
20658f6e1e22SMaarten Lankhorst 	connector->scaling_mode_property = scaling_mode_property;
20668f6e1e22SMaarten Lankhorst 
20678f6e1e22SMaarten Lankhorst 	return 0;
20688f6e1e22SMaarten Lankhorst }
20698f6e1e22SMaarten Lankhorst EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
20708f6e1e22SMaarten Lankhorst 
20718f6e1e22SMaarten Lankhorst /**
207252217195SDaniel Vetter  * drm_mode_create_aspect_ratio_property - create aspect ratio property
207352217195SDaniel Vetter  * @dev: DRM device
207452217195SDaniel Vetter  *
207552217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
207652217195SDaniel Vetter  * connectors.
207752217195SDaniel Vetter  *
207852217195SDaniel Vetter  * Returns:
207952217195SDaniel Vetter  * Zero on success, negative errno on failure.
208052217195SDaniel Vetter  */
208152217195SDaniel Vetter int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
208252217195SDaniel Vetter {
208352217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property)
208452217195SDaniel Vetter 		return 0;
208552217195SDaniel Vetter 
208652217195SDaniel Vetter 	dev->mode_config.aspect_ratio_property =
208752217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "aspect ratio",
208852217195SDaniel Vetter 				drm_aspect_ratio_enum_list,
208952217195SDaniel Vetter 				ARRAY_SIZE(drm_aspect_ratio_enum_list));
209052217195SDaniel Vetter 
209152217195SDaniel Vetter 	if (dev->mode_config.aspect_ratio_property == NULL)
209252217195SDaniel Vetter 		return -ENOMEM;
209352217195SDaniel Vetter 
209452217195SDaniel Vetter 	return 0;
209552217195SDaniel Vetter }
209652217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
209752217195SDaniel Vetter 
209852217195SDaniel Vetter /**
2099d2c6a405SUma Shankar  * DOC: standard connector properties
2100d2c6a405SUma Shankar  *
2101d2c6a405SUma Shankar  * Colorspace:
2102d2c6a405SUma Shankar  *     This property helps select a suitable colorspace based on the sink
2103d2c6a405SUma Shankar  *     capability. Modern sink devices support wider gamut like BT2020.
2104d2c6a405SUma Shankar  *     This helps switch to BT2020 mode if the BT2020 encoded video stream
2105d2c6a405SUma Shankar  *     is being played by the user, same for any other colorspace. Thereby
2106d2c6a405SUma Shankar  *     giving a good visual experience to users.
2107d2c6a405SUma Shankar  *
2108d2c6a405SUma Shankar  *     The expectation from userspace is that it should parse the EDID
2109d2c6a405SUma Shankar  *     and get supported colorspaces. Use this property and switch to the
2110d2c6a405SUma Shankar  *     one supported. Sink supported colorspaces should be retrieved by
2111d2c6a405SUma Shankar  *     userspace from EDID and driver will not explicitly expose them.
2112d2c6a405SUma Shankar  *
2113d2c6a405SUma Shankar  *     Basically the expectation from userspace is:
2114d2c6a405SUma Shankar  *      - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink
2115d2c6a405SUma Shankar  *        colorspace
2116d2c6a405SUma Shankar  *      - Set this new property to let the sink know what it
2117d2c6a405SUma Shankar  *        converted the CRTC output to.
2118d2c6a405SUma Shankar  *      - This property is just to inform sink what colorspace
2119d2c6a405SUma Shankar  *        source is trying to drive.
2120d2c6a405SUma Shankar  *
21218806cd3aSGwan-gyeong Mun  * Because between HDMI and DP have different colorspaces,
212245cf0e91SGwan-gyeong Mun  * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and
212345cf0e91SGwan-gyeong Mun  * drm_mode_create_dp_colorspace_property() is used for DP connector.
2124d2c6a405SUma Shankar  */
21258806cd3aSGwan-gyeong Mun 
21268806cd3aSGwan-gyeong Mun /**
21278806cd3aSGwan-gyeong Mun  * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
21288806cd3aSGwan-gyeong Mun  * @connector: connector to create the Colorspace property on.
21298806cd3aSGwan-gyeong Mun  *
21308806cd3aSGwan-gyeong Mun  * Called by a driver the first time it's needed, must be attached to desired
21318806cd3aSGwan-gyeong Mun  * HDMI connectors.
21328806cd3aSGwan-gyeong Mun  *
21338806cd3aSGwan-gyeong Mun  * Returns:
213484e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
21358806cd3aSGwan-gyeong Mun  */
21368806cd3aSGwan-gyeong Mun int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector)
2137d2c6a405SUma Shankar {
2138d2c6a405SUma Shankar 	struct drm_device *dev = connector->dev;
2139d2c6a405SUma Shankar 
21408806cd3aSGwan-gyeong Mun 	if (connector->colorspace_property)
21418806cd3aSGwan-gyeong Mun 		return 0;
21428806cd3aSGwan-gyeong Mun 
21438806cd3aSGwan-gyeong Mun 	connector->colorspace_property =
21448806cd3aSGwan-gyeong Mun 		drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
2145d2c6a405SUma Shankar 					 hdmi_colorspaces,
2146d2c6a405SUma Shankar 					 ARRAY_SIZE(hdmi_colorspaces));
21478806cd3aSGwan-gyeong Mun 
21488806cd3aSGwan-gyeong Mun 	if (!connector->colorspace_property)
2149d2c6a405SUma Shankar 		return -ENOMEM;
2150d2c6a405SUma Shankar 
2151d2c6a405SUma Shankar 	return 0;
2152d2c6a405SUma Shankar }
21538806cd3aSGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
2154d2c6a405SUma Shankar 
2155d2c6a405SUma Shankar /**
215645cf0e91SGwan-gyeong Mun  * drm_mode_create_dp_colorspace_property - create dp colorspace property
215745cf0e91SGwan-gyeong Mun  * @connector: connector to create the Colorspace property on.
215845cf0e91SGwan-gyeong Mun  *
215945cf0e91SGwan-gyeong Mun  * Called by a driver the first time it's needed, must be attached to desired
216045cf0e91SGwan-gyeong Mun  * DP connectors.
216145cf0e91SGwan-gyeong Mun  *
216245cf0e91SGwan-gyeong Mun  * Returns:
216384e543bcSAntonio Borneo  * Zero on success, negative errno on failure.
216445cf0e91SGwan-gyeong Mun  */
216545cf0e91SGwan-gyeong Mun int drm_mode_create_dp_colorspace_property(struct drm_connector *connector)
216645cf0e91SGwan-gyeong Mun {
216745cf0e91SGwan-gyeong Mun 	struct drm_device *dev = connector->dev;
216845cf0e91SGwan-gyeong Mun 
216945cf0e91SGwan-gyeong Mun 	if (connector->colorspace_property)
217045cf0e91SGwan-gyeong Mun 		return 0;
217145cf0e91SGwan-gyeong Mun 
217245cf0e91SGwan-gyeong Mun 	connector->colorspace_property =
217345cf0e91SGwan-gyeong Mun 		drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
217445cf0e91SGwan-gyeong Mun 					 dp_colorspaces,
217545cf0e91SGwan-gyeong Mun 					 ARRAY_SIZE(dp_colorspaces));
217645cf0e91SGwan-gyeong Mun 
217745cf0e91SGwan-gyeong Mun 	if (!connector->colorspace_property)
217845cf0e91SGwan-gyeong Mun 		return -ENOMEM;
217945cf0e91SGwan-gyeong Mun 
218045cf0e91SGwan-gyeong Mun 	return 0;
218145cf0e91SGwan-gyeong Mun }
218245cf0e91SGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
218352217195SDaniel Vetter 
218497e14fbeSDaniel Vetter /**
218552217195SDaniel Vetter  * drm_mode_create_content_type_property - create content type property
218652217195SDaniel Vetter  * @dev: DRM device
218797e14fbeSDaniel Vetter  *
218852217195SDaniel Vetter  * Called by a driver the first time it's needed, must be attached to desired
218952217195SDaniel Vetter  * connectors.
219052217195SDaniel Vetter  *
219152217195SDaniel Vetter  * Returns:
219252217195SDaniel Vetter  * Zero on success, negative errno on failure.
219352217195SDaniel Vetter  */
219452217195SDaniel Vetter int drm_mode_create_content_type_property(struct drm_device *dev)
219552217195SDaniel Vetter {
219652217195SDaniel Vetter 	if (dev->mode_config.content_type_property)
219797e14fbeSDaniel Vetter 		return 0;
219852217195SDaniel Vetter 
219952217195SDaniel Vetter 	dev->mode_config.content_type_property =
220052217195SDaniel Vetter 		drm_property_create_enum(dev, 0, "content type",
220152217195SDaniel Vetter 					 drm_content_type_enum_list,
220252217195SDaniel Vetter 					 ARRAY_SIZE(drm_content_type_enum_list));
220352217195SDaniel Vetter 
220452217195SDaniel Vetter 	if (dev->mode_config.content_type_property == NULL)
220552217195SDaniel Vetter 		return -ENOMEM;
220652217195SDaniel Vetter 
220752217195SDaniel Vetter 	return 0;
220852217195SDaniel Vetter }
220952217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_content_type_property);
221052217195SDaniel Vetter 
221152217195SDaniel Vetter /**
221252217195SDaniel Vetter  * drm_mode_create_suggested_offset_properties - create suggests offset properties
221352217195SDaniel Vetter  * @dev: DRM device
221452217195SDaniel Vetter  *
221584e543bcSAntonio Borneo  * Create the suggested x/y offset property for connectors.
2216f85d9e59SRandy Dunlap  *
2217f85d9e59SRandy Dunlap  * Returns:
2218f85d9e59SRandy Dunlap  * 0 on success or a negative error code on failure.
221952217195SDaniel Vetter  */
222052217195SDaniel Vetter int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
222152217195SDaniel Vetter {
222252217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
222352217195SDaniel Vetter 		return 0;
222452217195SDaniel Vetter 
222552217195SDaniel Vetter 	dev->mode_config.suggested_x_property =
222652217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
222752217195SDaniel Vetter 
222852217195SDaniel Vetter 	dev->mode_config.suggested_y_property =
222952217195SDaniel Vetter 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
223052217195SDaniel Vetter 
223152217195SDaniel Vetter 	if (dev->mode_config.suggested_x_property == NULL ||
223252217195SDaniel Vetter 	    dev->mode_config.suggested_y_property == NULL)
223352217195SDaniel Vetter 		return -ENOMEM;
223452217195SDaniel Vetter 	return 0;
223552217195SDaniel Vetter }
223652217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
223752217195SDaniel Vetter 
223852217195SDaniel Vetter /**
223952217195SDaniel Vetter  * drm_connector_set_path_property - set tile property on connector
224052217195SDaniel Vetter  * @connector: connector to set property on.
224152217195SDaniel Vetter  * @path: path to use for property; must not be NULL.
224252217195SDaniel Vetter  *
224352217195SDaniel Vetter  * This creates a property to expose to userspace to specify a
224452217195SDaniel Vetter  * connector path. This is mainly used for DisplayPort MST where
224552217195SDaniel Vetter  * connectors have a topology and we want to allow userspace to give
224652217195SDaniel Vetter  * them more meaningful names.
224752217195SDaniel Vetter  *
224852217195SDaniel Vetter  * Returns:
224952217195SDaniel Vetter  * Zero on success, negative errno on failure.
225052217195SDaniel Vetter  */
225152217195SDaniel Vetter int drm_connector_set_path_property(struct drm_connector *connector,
225252217195SDaniel Vetter 				    const char *path)
225352217195SDaniel Vetter {
225452217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
225552217195SDaniel Vetter 	int ret;
225652217195SDaniel Vetter 
225752217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
225852217195SDaniel Vetter 					       &connector->path_blob_ptr,
225952217195SDaniel Vetter 					       strlen(path) + 1,
226052217195SDaniel Vetter 					       path,
226152217195SDaniel Vetter 					       &connector->base,
226252217195SDaniel Vetter 					       dev->mode_config.path_property);
226352217195SDaniel Vetter 	return ret;
226452217195SDaniel Vetter }
226552217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_set_path_property);
226652217195SDaniel Vetter 
226752217195SDaniel Vetter /**
226852217195SDaniel Vetter  * drm_connector_set_tile_property - set tile property on connector
226952217195SDaniel Vetter  * @connector: connector to set property on.
227052217195SDaniel Vetter  *
227152217195SDaniel Vetter  * This looks up the tile information for a connector, and creates a
227252217195SDaniel Vetter  * property for userspace to parse if it exists. The property is of
227352217195SDaniel Vetter  * the form of 8 integers using ':' as a separator.
22742de3a078SManasi Navare  * This is used for dual port tiled displays with DisplayPort SST
22752de3a078SManasi Navare  * or DisplayPort MST connectors.
227652217195SDaniel Vetter  *
227752217195SDaniel Vetter  * Returns:
227852217195SDaniel Vetter  * Zero on success, errno on failure.
227952217195SDaniel Vetter  */
228052217195SDaniel Vetter int drm_connector_set_tile_property(struct drm_connector *connector)
228152217195SDaniel Vetter {
228252217195SDaniel Vetter 	struct drm_device *dev = connector->dev;
228352217195SDaniel Vetter 	char tile[256];
228452217195SDaniel Vetter 	int ret;
228552217195SDaniel Vetter 
228652217195SDaniel Vetter 	if (!connector->has_tile) {
228752217195SDaniel Vetter 		ret  = drm_property_replace_global_blob(dev,
228852217195SDaniel Vetter 							&connector->tile_blob_ptr,
228952217195SDaniel Vetter 							0,
229052217195SDaniel Vetter 							NULL,
229152217195SDaniel Vetter 							&connector->base,
229252217195SDaniel Vetter 							dev->mode_config.tile_property);
229352217195SDaniel Vetter 		return ret;
229452217195SDaniel Vetter 	}
229552217195SDaniel Vetter 
229652217195SDaniel Vetter 	snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
229752217195SDaniel Vetter 		 connector->tile_group->id, connector->tile_is_single_monitor,
229852217195SDaniel Vetter 		 connector->num_h_tile, connector->num_v_tile,
229952217195SDaniel Vetter 		 connector->tile_h_loc, connector->tile_v_loc,
230052217195SDaniel Vetter 		 connector->tile_h_size, connector->tile_v_size);
230152217195SDaniel Vetter 
230252217195SDaniel Vetter 	ret = drm_property_replace_global_blob(dev,
230352217195SDaniel Vetter 					       &connector->tile_blob_ptr,
230452217195SDaniel Vetter 					       strlen(tile) + 1,
230552217195SDaniel Vetter 					       tile,
230652217195SDaniel Vetter 					       &connector->base,
230752217195SDaniel Vetter 					       dev->mode_config.tile_property);
230852217195SDaniel Vetter 	return ret;
230952217195SDaniel Vetter }
231097e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_tile_property);
231152217195SDaniel Vetter 
231252217195SDaniel Vetter /**
231397e14fbeSDaniel Vetter  * drm_connector_set_link_status_property - Set link status property of a connector
231440ee6fbeSManasi Navare  * @connector: drm connector
231540ee6fbeSManasi Navare  * @link_status: new value of link status property (0: Good, 1: Bad)
231640ee6fbeSManasi Navare  *
231740ee6fbeSManasi Navare  * In usual working scenario, this link status property will always be set to
231840ee6fbeSManasi Navare  * "GOOD". If something fails during or after a mode set, the kernel driver
231940ee6fbeSManasi Navare  * may set this link status property to "BAD". The caller then needs to send a
232040ee6fbeSManasi Navare  * hotplug uevent for userspace to re-check the valid modes through
232140ee6fbeSManasi Navare  * GET_CONNECTOR_IOCTL and retry modeset.
232240ee6fbeSManasi Navare  *
232340ee6fbeSManasi Navare  * Note: Drivers cannot rely on userspace to support this property and
232440ee6fbeSManasi Navare  * issue a modeset. As such, they may choose to handle issues (like
232540ee6fbeSManasi Navare  * re-training a link) without userspace's intervention.
232640ee6fbeSManasi Navare  *
232740ee6fbeSManasi Navare  * The reason for adding this property is to handle link training failures, but
232840ee6fbeSManasi Navare  * it is not limited to DP or link training. For example, if we implement
232940ee6fbeSManasi Navare  * asynchronous setcrtc, this property can be used to report any failures in that.
233040ee6fbeSManasi Navare  */
233197e14fbeSDaniel Vetter void drm_connector_set_link_status_property(struct drm_connector *connector,
233240ee6fbeSManasi Navare 					    uint64_t link_status)
233340ee6fbeSManasi Navare {
233440ee6fbeSManasi Navare 	struct drm_device *dev = connector->dev;
233540ee6fbeSManasi Navare 
233640ee6fbeSManasi Navare 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
233740ee6fbeSManasi Navare 	connector->state->link_status = link_status;
233840ee6fbeSManasi Navare 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
233940ee6fbeSManasi Navare }
234097e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_link_status_property);
234140ee6fbeSManasi Navare 
23428d70f395SHans de Goede /**
234347e22ff1SRadhakrishna Sripada  * drm_connector_attach_max_bpc_property - attach "max bpc" property
234447e22ff1SRadhakrishna Sripada  * @connector: connector to attach max bpc property on.
234547e22ff1SRadhakrishna Sripada  * @min: The minimum bit depth supported by the connector.
234647e22ff1SRadhakrishna Sripada  * @max: The maximum bit depth supported by the connector.
234747e22ff1SRadhakrishna Sripada  *
234847e22ff1SRadhakrishna Sripada  * This is used to add support for limiting the bit depth on a connector.
234947e22ff1SRadhakrishna Sripada  *
235047e22ff1SRadhakrishna Sripada  * Returns:
235147e22ff1SRadhakrishna Sripada  * Zero on success, negative errno on failure.
235247e22ff1SRadhakrishna Sripada  */
235347e22ff1SRadhakrishna Sripada int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
235447e22ff1SRadhakrishna Sripada 					  int min, int max)
235547e22ff1SRadhakrishna Sripada {
235647e22ff1SRadhakrishna Sripada 	struct drm_device *dev = connector->dev;
235747e22ff1SRadhakrishna Sripada 	struct drm_property *prop;
235847e22ff1SRadhakrishna Sripada 
235947e22ff1SRadhakrishna Sripada 	prop = connector->max_bpc_property;
236047e22ff1SRadhakrishna Sripada 	if (!prop) {
236147e22ff1SRadhakrishna Sripada 		prop = drm_property_create_range(dev, 0, "max bpc", min, max);
236247e22ff1SRadhakrishna Sripada 		if (!prop)
236347e22ff1SRadhakrishna Sripada 			return -ENOMEM;
236447e22ff1SRadhakrishna Sripada 
236547e22ff1SRadhakrishna Sripada 		connector->max_bpc_property = prop;
236647e22ff1SRadhakrishna Sripada 	}
236747e22ff1SRadhakrishna Sripada 
236847e22ff1SRadhakrishna Sripada 	drm_object_attach_property(&connector->base, prop, max);
236947e22ff1SRadhakrishna Sripada 	connector->state->max_requested_bpc = max;
237047e22ff1SRadhakrishna Sripada 	connector->state->max_bpc = max;
237147e22ff1SRadhakrishna Sripada 
237247e22ff1SRadhakrishna Sripada 	return 0;
237347e22ff1SRadhakrishna Sripada }
237447e22ff1SRadhakrishna Sripada EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
237547e22ff1SRadhakrishna Sripada 
237647e22ff1SRadhakrishna Sripada /**
2377e057b52cSMaxime Ripard  * drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADA" property
2378e057b52cSMaxime Ripard  * @connector: connector to attach the property on.
2379e057b52cSMaxime Ripard  *
2380e057b52cSMaxime Ripard  * This is used to allow the userspace to send HDR Metadata to the
2381e057b52cSMaxime Ripard  * driver.
2382e057b52cSMaxime Ripard  *
2383e057b52cSMaxime Ripard  * Returns:
2384e057b52cSMaxime Ripard  * Zero on success, negative errno on failure.
2385e057b52cSMaxime Ripard  */
2386e057b52cSMaxime Ripard int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector)
2387e057b52cSMaxime Ripard {
2388e057b52cSMaxime Ripard 	struct drm_device *dev = connector->dev;
2389e057b52cSMaxime Ripard 	struct drm_property *prop = dev->mode_config.hdr_output_metadata_property;
2390e057b52cSMaxime Ripard 
2391e057b52cSMaxime Ripard 	drm_object_attach_property(&connector->base, prop, 0);
2392e057b52cSMaxime Ripard 
2393e057b52cSMaxime Ripard 	return 0;
2394e057b52cSMaxime Ripard }
2395e057b52cSMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property);
2396e057b52cSMaxime Ripard 
2397e057b52cSMaxime Ripard /**
239821f79128SMaxime Ripard  * drm_connector_attach_colorspace_property - attach "Colorspace" property
239921f79128SMaxime Ripard  * @connector: connector to attach the property on.
240021f79128SMaxime Ripard  *
240121f79128SMaxime Ripard  * This is used to allow the userspace to signal the output colorspace
240221f79128SMaxime Ripard  * to the driver.
240321f79128SMaxime Ripard  *
240421f79128SMaxime Ripard  * Returns:
240521f79128SMaxime Ripard  * Zero on success, negative errno on failure.
240621f79128SMaxime Ripard  */
240721f79128SMaxime Ripard int drm_connector_attach_colorspace_property(struct drm_connector *connector)
240821f79128SMaxime Ripard {
240921f79128SMaxime Ripard 	struct drm_property *prop = connector->colorspace_property;
241021f79128SMaxime Ripard 
241121f79128SMaxime Ripard 	drm_object_attach_property(&connector->base, prop, DRM_MODE_COLORIMETRY_DEFAULT);
241221f79128SMaxime Ripard 
241321f79128SMaxime Ripard 	return 0;
241421f79128SMaxime Ripard }
241521f79128SMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_colorspace_property);
241621f79128SMaxime Ripard 
241721f79128SMaxime Ripard /**
241872921cdfSMaxime Ripard  * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed
241972921cdfSMaxime Ripard  * @old_state: old connector state to compare
242072921cdfSMaxime Ripard  * @new_state: new connector state to compare
242172921cdfSMaxime Ripard  *
242272921cdfSMaxime Ripard  * This is used by HDR-enabled drivers to test whether the HDR metadata
242372921cdfSMaxime Ripard  * have changed between two different connector state (and thus probably
242472921cdfSMaxime Ripard  * requires a full blown mode change).
242572921cdfSMaxime Ripard  *
242672921cdfSMaxime Ripard  * Returns:
242772921cdfSMaxime Ripard  * True if the metadata are equal, False otherwise
242872921cdfSMaxime Ripard  */
242972921cdfSMaxime Ripard bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state,
243072921cdfSMaxime Ripard 					     struct drm_connector_state *new_state)
243172921cdfSMaxime Ripard {
243272921cdfSMaxime Ripard 	struct drm_property_blob *old_blob = old_state->hdr_output_metadata;
243372921cdfSMaxime Ripard 	struct drm_property_blob *new_blob = new_state->hdr_output_metadata;
243472921cdfSMaxime Ripard 
243572921cdfSMaxime Ripard 	if (!old_blob || !new_blob)
243672921cdfSMaxime Ripard 		return old_blob == new_blob;
243772921cdfSMaxime Ripard 
243872921cdfSMaxime Ripard 	if (old_blob->length != new_blob->length)
243972921cdfSMaxime Ripard 		return false;
244072921cdfSMaxime Ripard 
244172921cdfSMaxime Ripard 	return !memcmp(old_blob->data, new_blob->data, old_blob->length);
244272921cdfSMaxime Ripard }
244372921cdfSMaxime Ripard EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal);
244472921cdfSMaxime Ripard 
244572921cdfSMaxime Ripard /**
2446ba1b0f6cSNicholas Kazlauskas  * drm_connector_set_vrr_capable_property - sets the variable refresh rate
2447ba1b0f6cSNicholas Kazlauskas  * capable property for a connector
2448ba1b0f6cSNicholas Kazlauskas  * @connector: drm connector
2449ba1b0f6cSNicholas Kazlauskas  * @capable: True if the connector is variable refresh rate capable
2450ba1b0f6cSNicholas Kazlauskas  *
2451ba1b0f6cSNicholas Kazlauskas  * Should be used by atomic drivers to update the indicated support for
2452ba1b0f6cSNicholas Kazlauskas  * variable refresh rate over a connector.
2453ba1b0f6cSNicholas Kazlauskas  */
2454ba1b0f6cSNicholas Kazlauskas void drm_connector_set_vrr_capable_property(
2455ba1b0f6cSNicholas Kazlauskas 		struct drm_connector *connector, bool capable)
2456ba1b0f6cSNicholas Kazlauskas {
245762929726SManasi Navare 	if (!connector->vrr_capable_property)
245862929726SManasi Navare 		return;
245962929726SManasi Navare 
2460ba1b0f6cSNicholas Kazlauskas 	drm_object_property_set_value(&connector->base,
2461ba1b0f6cSNicholas Kazlauskas 				      connector->vrr_capable_property,
2462ba1b0f6cSNicholas Kazlauskas 				      capable);
2463ba1b0f6cSNicholas Kazlauskas }
2464ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
2465ba1b0f6cSNicholas Kazlauskas 
2466ba1b0f6cSNicholas Kazlauskas /**
246784e543bcSAntonio Borneo  * drm_connector_set_panel_orientation - sets the connector's panel_orientation
246869654c63SDerek Basehore  * @connector: connector for which to set the panel-orientation property.
246969654c63SDerek Basehore  * @panel_orientation: drm_panel_orientation value to set
24708d70f395SHans de Goede  *
247169654c63SDerek Basehore  * This function sets the connector's panel_orientation and attaches
247269654c63SDerek Basehore  * a "panel orientation" property to the connector.
24738d70f395SHans de Goede  *
247469654c63SDerek Basehore  * Calling this function on a connector where the panel_orientation has
247569654c63SDerek Basehore  * already been set is a no-op (e.g. the orientation has been overridden with
247669654c63SDerek Basehore  * a kernel commandline option).
247769654c63SDerek Basehore  *
247869654c63SDerek Basehore  * It is allowed to call this function with a panel_orientation of
247969654c63SDerek Basehore  * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
24808d70f395SHans de Goede  *
24815e41b01aSHsin-Yi Wang  * The function shouldn't be called in panel after drm is registered (i.e.
24825e41b01aSHsin-Yi Wang  * drm_dev_register() is called in drm).
24835e41b01aSHsin-Yi Wang  *
24848d70f395SHans de Goede  * Returns:
24858d70f395SHans de Goede  * Zero on success, negative errno on failure.
24868d70f395SHans de Goede  */
248769654c63SDerek Basehore int drm_connector_set_panel_orientation(
248869654c63SDerek Basehore 	struct drm_connector *connector,
248969654c63SDerek Basehore 	enum drm_panel_orientation panel_orientation)
24908d70f395SHans de Goede {
24918d70f395SHans de Goede 	struct drm_device *dev = connector->dev;
24928d70f395SHans de Goede 	struct drm_display_info *info = &connector->display_info;
24938d70f395SHans de Goede 	struct drm_property *prop;
24948d70f395SHans de Goede 
249569654c63SDerek Basehore 	/* Already set? */
249669654c63SDerek Basehore 	if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
24978d70f395SHans de Goede 		return 0;
24988d70f395SHans de Goede 
249969654c63SDerek Basehore 	/* Don't attach the property if the orientation is unknown */
250069654c63SDerek Basehore 	if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
250169654c63SDerek Basehore 		return 0;
250269654c63SDerek Basehore 
250369654c63SDerek Basehore 	info->panel_orientation = panel_orientation;
250469654c63SDerek Basehore 
25058d70f395SHans de Goede 	prop = dev->mode_config.panel_orientation_property;
25068d70f395SHans de Goede 	if (!prop) {
25078d70f395SHans de Goede 		prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
25088d70f395SHans de Goede 				"panel orientation",
25098d70f395SHans de Goede 				drm_panel_orientation_enum_list,
25108d70f395SHans de Goede 				ARRAY_SIZE(drm_panel_orientation_enum_list));
25118d70f395SHans de Goede 		if (!prop)
25128d70f395SHans de Goede 			return -ENOMEM;
25138d70f395SHans de Goede 
25148d70f395SHans de Goede 		dev->mode_config.panel_orientation_property = prop;
25158d70f395SHans de Goede 	}
25168d70f395SHans de Goede 
25178d70f395SHans de Goede 	drm_object_attach_property(&connector->base, prop,
25188d70f395SHans de Goede 				   info->panel_orientation);
25198d70f395SHans de Goede 	return 0;
25208d70f395SHans de Goede }
252169654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation);
252269654c63SDerek Basehore 
252369654c63SDerek Basehore /**
2524f85d9e59SRandy Dunlap  * drm_connector_set_panel_orientation_with_quirk - set the
2525f85d9e59SRandy Dunlap  *	connector's panel_orientation after checking for quirks
252669654c63SDerek Basehore  * @connector: connector for which to init the panel-orientation property.
252769654c63SDerek Basehore  * @panel_orientation: drm_panel_orientation value to set
252869654c63SDerek Basehore  * @width: width in pixels of the panel, used for panel quirk detection
252969654c63SDerek Basehore  * @height: height in pixels of the panel, used for panel quirk detection
253069654c63SDerek Basehore  *
253169654c63SDerek Basehore  * Like drm_connector_set_panel_orientation(), but with a check for platform
253269654c63SDerek Basehore  * specific (e.g. DMI based) quirks overriding the passed in panel_orientation.
253369654c63SDerek Basehore  *
253469654c63SDerek Basehore  * Returns:
253569654c63SDerek Basehore  * Zero on success, negative errno on failure.
253669654c63SDerek Basehore  */
253769654c63SDerek Basehore int drm_connector_set_panel_orientation_with_quirk(
253869654c63SDerek Basehore 	struct drm_connector *connector,
253969654c63SDerek Basehore 	enum drm_panel_orientation panel_orientation,
254069654c63SDerek Basehore 	int width, int height)
254169654c63SDerek Basehore {
254269654c63SDerek Basehore 	int orientation_quirk;
254369654c63SDerek Basehore 
254469654c63SDerek Basehore 	orientation_quirk = drm_get_panel_orientation_quirk(width, height);
254569654c63SDerek Basehore 	if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
254669654c63SDerek Basehore 		panel_orientation = orientation_quirk;
254769654c63SDerek Basehore 
254869654c63SDerek Basehore 	return drm_connector_set_panel_orientation(connector,
254969654c63SDerek Basehore 						   panel_orientation);
255069654c63SDerek Basehore }
255169654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
25528d70f395SHans de Goede 
25535e41b01aSHsin-Yi Wang /**
25545e41b01aSHsin-Yi Wang  * drm_connector_set_orientation_from_panel -
25555e41b01aSHsin-Yi Wang  *	set the connector's panel_orientation from panel's callback.
25565e41b01aSHsin-Yi Wang  * @connector: connector for which to init the panel-orientation property.
25575e41b01aSHsin-Yi Wang  * @panel: panel that can provide orientation information.
25585e41b01aSHsin-Yi Wang  *
25595e41b01aSHsin-Yi Wang  * Drm drivers should call this function before drm_dev_register().
25605e41b01aSHsin-Yi Wang  * Orientation is obtained from panel's .get_orientation() callback.
25615e41b01aSHsin-Yi Wang  *
25625e41b01aSHsin-Yi Wang  * Returns:
25635e41b01aSHsin-Yi Wang  * Zero on success, negative errno on failure.
25645e41b01aSHsin-Yi Wang  */
25655e41b01aSHsin-Yi Wang int drm_connector_set_orientation_from_panel(
25665e41b01aSHsin-Yi Wang 	struct drm_connector *connector,
25675e41b01aSHsin-Yi Wang 	struct drm_panel *panel)
25685e41b01aSHsin-Yi Wang {
25695e41b01aSHsin-Yi Wang 	enum drm_panel_orientation orientation;
25705e41b01aSHsin-Yi Wang 
25715e41b01aSHsin-Yi Wang 	if (panel && panel->funcs && panel->funcs->get_orientation)
25725e41b01aSHsin-Yi Wang 		orientation = panel->funcs->get_orientation(panel);
25735e41b01aSHsin-Yi Wang 	else
25745e41b01aSHsin-Yi Wang 		orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
25755e41b01aSHsin-Yi Wang 
25765e41b01aSHsin-Yi Wang 	return drm_connector_set_panel_orientation(connector, orientation);
25775e41b01aSHsin-Yi Wang }
25785e41b01aSHsin-Yi Wang EXPORT_SYMBOL(drm_connector_set_orientation_from_panel);
25795e41b01aSHsin-Yi Wang 
2580107fe904SRajat Jain static const struct drm_prop_enum_list privacy_screen_enum[] = {
2581107fe904SRajat Jain 	{ PRIVACY_SCREEN_DISABLED,		"Disabled" },
2582107fe904SRajat Jain 	{ PRIVACY_SCREEN_ENABLED,		"Enabled" },
2583107fe904SRajat Jain 	{ PRIVACY_SCREEN_DISABLED_LOCKED,	"Disabled-locked" },
2584107fe904SRajat Jain 	{ PRIVACY_SCREEN_ENABLED_LOCKED,	"Enabled-locked" },
2585107fe904SRajat Jain };
2586107fe904SRajat Jain 
2587107fe904SRajat Jain /**
2588107fe904SRajat Jain  * drm_connector_create_privacy_screen_properties - create the drm connecter's
2589107fe904SRajat Jain  *    privacy-screen properties.
2590107fe904SRajat Jain  * @connector: connector for which to create the privacy-screen properties
2591107fe904SRajat Jain  *
2592107fe904SRajat Jain  * This function creates the "privacy-screen sw-state" and "privacy-screen
2593107fe904SRajat Jain  * hw-state" properties for the connector. They are not attached.
2594107fe904SRajat Jain  */
2595107fe904SRajat Jain void
2596107fe904SRajat Jain drm_connector_create_privacy_screen_properties(struct drm_connector *connector)
2597107fe904SRajat Jain {
2598107fe904SRajat Jain 	if (connector->privacy_screen_sw_state_property)
2599107fe904SRajat Jain 		return;
2600107fe904SRajat Jain 
2601107fe904SRajat Jain 	/* Note sw-state only supports the first 2 values of the enum */
2602107fe904SRajat Jain 	connector->privacy_screen_sw_state_property =
2603107fe904SRajat Jain 		drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM,
2604107fe904SRajat Jain 				"privacy-screen sw-state",
2605107fe904SRajat Jain 				privacy_screen_enum, 2);
2606107fe904SRajat Jain 
2607107fe904SRajat Jain 	connector->privacy_screen_hw_state_property =
2608107fe904SRajat Jain 		drm_property_create_enum(connector->dev,
2609107fe904SRajat Jain 				DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM,
2610107fe904SRajat Jain 				"privacy-screen hw-state",
2611107fe904SRajat Jain 				privacy_screen_enum,
2612107fe904SRajat Jain 				ARRAY_SIZE(privacy_screen_enum));
2613107fe904SRajat Jain }
2614107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties);
2615107fe904SRajat Jain 
2616107fe904SRajat Jain /**
2617107fe904SRajat Jain  * drm_connector_attach_privacy_screen_properties - attach the drm connecter's
2618107fe904SRajat Jain  *    privacy-screen properties.
2619107fe904SRajat Jain  * @connector: connector on which to attach the privacy-screen properties
2620107fe904SRajat Jain  *
2621107fe904SRajat Jain  * This function attaches the "privacy-screen sw-state" and "privacy-screen
2622107fe904SRajat Jain  * hw-state" properties to the connector. The initial state of both is set
2623107fe904SRajat Jain  * to "Disabled".
2624107fe904SRajat Jain  */
2625107fe904SRajat Jain void
2626107fe904SRajat Jain drm_connector_attach_privacy_screen_properties(struct drm_connector *connector)
2627107fe904SRajat Jain {
2628107fe904SRajat Jain 	if (!connector->privacy_screen_sw_state_property)
2629107fe904SRajat Jain 		return;
2630107fe904SRajat Jain 
2631107fe904SRajat Jain 	drm_object_attach_property(&connector->base,
2632107fe904SRajat Jain 				   connector->privacy_screen_sw_state_property,
2633107fe904SRajat Jain 				   PRIVACY_SCREEN_DISABLED);
2634107fe904SRajat Jain 
2635107fe904SRajat Jain 	drm_object_attach_property(&connector->base,
2636107fe904SRajat Jain 				   connector->privacy_screen_hw_state_property,
2637107fe904SRajat Jain 				   PRIVACY_SCREEN_DISABLED);
2638107fe904SRajat Jain }
2639107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties);
2640107fe904SRajat Jain 
2641334f74eeSHans de Goede static void drm_connector_update_privacy_screen_properties(
2642334f74eeSHans de Goede 	struct drm_connector *connector, bool set_sw_state)
2643334f74eeSHans de Goede {
2644334f74eeSHans de Goede 	enum drm_privacy_screen_status sw_state, hw_state;
2645334f74eeSHans de Goede 
2646334f74eeSHans de Goede 	drm_privacy_screen_get_state(connector->privacy_screen,
2647334f74eeSHans de Goede 				     &sw_state, &hw_state);
2648334f74eeSHans de Goede 
2649334f74eeSHans de Goede 	if (set_sw_state)
2650334f74eeSHans de Goede 		connector->state->privacy_screen_sw_state = sw_state;
2651334f74eeSHans de Goede 	drm_object_property_set_value(&connector->base,
2652334f74eeSHans de Goede 			connector->privacy_screen_hw_state_property, hw_state);
2653334f74eeSHans de Goede }
2654334f74eeSHans de Goede 
2655334f74eeSHans de Goede static int drm_connector_privacy_screen_notifier(
2656334f74eeSHans de Goede 	struct notifier_block *nb, unsigned long action, void *data)
2657334f74eeSHans de Goede {
2658334f74eeSHans de Goede 	struct drm_connector *connector =
2659334f74eeSHans de Goede 		container_of(nb, struct drm_connector, privacy_screen_notifier);
2660334f74eeSHans de Goede 	struct drm_device *dev = connector->dev;
2661334f74eeSHans de Goede 
2662334f74eeSHans de Goede 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2663334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, true);
2664334f74eeSHans de Goede 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
2665334f74eeSHans de Goede 
2666334f74eeSHans de Goede 	drm_sysfs_connector_status_event(connector,
2667334f74eeSHans de Goede 				connector->privacy_screen_sw_state_property);
2668334f74eeSHans de Goede 	drm_sysfs_connector_status_event(connector,
2669334f74eeSHans de Goede 				connector->privacy_screen_hw_state_property);
2670334f74eeSHans de Goede 
2671334f74eeSHans de Goede 	return NOTIFY_DONE;
2672334f74eeSHans de Goede }
2673334f74eeSHans de Goede 
2674334f74eeSHans de Goede /**
2675334f74eeSHans de Goede  * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to
2676334f74eeSHans de Goede  *    the connector
2677334f74eeSHans de Goede  * @connector: connector to attach the privacy-screen to
2678334f74eeSHans de Goede  * @priv: drm_privacy_screen to attach
2679334f74eeSHans de Goede  *
2680334f74eeSHans de Goede  * Create and attach the standard privacy-screen properties and register
2681334f74eeSHans de Goede  * a generic notifier for generating sysfs-connector-status-events
2682334f74eeSHans de Goede  * on external changes to the privacy-screen status.
2683334f74eeSHans de Goede  * This function takes ownership of the passed in drm_privacy_screen and will
2684334f74eeSHans de Goede  * call drm_privacy_screen_put() on it when the connector is destroyed.
2685334f74eeSHans de Goede  */
2686334f74eeSHans de Goede void drm_connector_attach_privacy_screen_provider(
2687334f74eeSHans de Goede 	struct drm_connector *connector, struct drm_privacy_screen *priv)
2688334f74eeSHans de Goede {
2689334f74eeSHans de Goede 	connector->privacy_screen = priv;
2690334f74eeSHans de Goede 	connector->privacy_screen_notifier.notifier_call =
2691334f74eeSHans de Goede 		drm_connector_privacy_screen_notifier;
2692334f74eeSHans de Goede 
2693334f74eeSHans de Goede 	drm_connector_create_privacy_screen_properties(connector);
2694334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, true);
2695334f74eeSHans de Goede 	drm_connector_attach_privacy_screen_properties(connector);
2696334f74eeSHans de Goede }
2697334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider);
2698334f74eeSHans de Goede 
2699334f74eeSHans de Goede /**
2700334f74eeSHans de Goede  * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state
2701334f74eeSHans de Goede  * @connector_state: connector-state to update the privacy-screen for
2702334f74eeSHans de Goede  *
2703334f74eeSHans de Goede  * This function calls drm_privacy_screen_set_sw_state() on the connector's
2704334f74eeSHans de Goede  * privacy-screen.
2705334f74eeSHans de Goede  *
2706334f74eeSHans de Goede  * If the connector has no privacy-screen, then this is a no-op.
2707334f74eeSHans de Goede  */
2708334f74eeSHans de Goede void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state)
2709334f74eeSHans de Goede {
2710334f74eeSHans de Goede 	struct drm_connector *connector = connector_state->connector;
2711334f74eeSHans de Goede 	int ret;
2712334f74eeSHans de Goede 
2713334f74eeSHans de Goede 	if (!connector->privacy_screen)
2714334f74eeSHans de Goede 		return;
2715334f74eeSHans de Goede 
2716334f74eeSHans de Goede 	ret = drm_privacy_screen_set_sw_state(connector->privacy_screen,
2717334f74eeSHans de Goede 					      connector_state->privacy_screen_sw_state);
2718334f74eeSHans de Goede 	if (ret) {
2719334f74eeSHans de Goede 		drm_err(connector->dev, "Error updating privacy-screen sw_state\n");
2720334f74eeSHans de Goede 		return;
2721334f74eeSHans de Goede 	}
2722334f74eeSHans de Goede 
2723334f74eeSHans de Goede 	/* The hw_state property value may have changed, update it. */
2724334f74eeSHans de Goede 	drm_connector_update_privacy_screen_properties(connector, false);
2725334f74eeSHans de Goede }
2726334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_update_privacy_screen);
2727334f74eeSHans de Goede 
272897e14fbeSDaniel Vetter int drm_connector_set_obj_prop(struct drm_mode_object *obj,
272952217195SDaniel Vetter 				    struct drm_property *property,
273052217195SDaniel Vetter 				    uint64_t value)
273152217195SDaniel Vetter {
273252217195SDaniel Vetter 	int ret = -EINVAL;
273352217195SDaniel Vetter 	struct drm_connector *connector = obj_to_connector(obj);
273452217195SDaniel Vetter 
273552217195SDaniel Vetter 	/* Do DPMS ourselves */
273652217195SDaniel Vetter 	if (property == connector->dev->mode_config.dpms_property) {
273752217195SDaniel Vetter 		ret = (*connector->funcs->dpms)(connector, (int)value);
273852217195SDaniel Vetter 	} else if (connector->funcs->set_property)
273952217195SDaniel Vetter 		ret = connector->funcs->set_property(connector, property, value);
274052217195SDaniel Vetter 
2741144a7999SDaniel Vetter 	if (!ret)
274252217195SDaniel Vetter 		drm_object_property_set_value(&connector->base, property, value);
274352217195SDaniel Vetter 	return ret;
274452217195SDaniel Vetter }
274552217195SDaniel Vetter 
274697e14fbeSDaniel Vetter int drm_connector_property_set_ioctl(struct drm_device *dev,
274752217195SDaniel Vetter 				     void *data, struct drm_file *file_priv)
274852217195SDaniel Vetter {
274952217195SDaniel Vetter 	struct drm_mode_connector_set_property *conn_set_prop = data;
275052217195SDaniel Vetter 	struct drm_mode_obj_set_property obj_set_prop = {
275152217195SDaniel Vetter 		.value = conn_set_prop->value,
275252217195SDaniel Vetter 		.prop_id = conn_set_prop->prop_id,
275352217195SDaniel Vetter 		.obj_id = conn_set_prop->connector_id,
275452217195SDaniel Vetter 		.obj_type = DRM_MODE_OBJECT_CONNECTOR
275552217195SDaniel Vetter 	};
275652217195SDaniel Vetter 
275752217195SDaniel Vetter 	/* It does all the locking and checking we need */
275852217195SDaniel Vetter 	return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
275952217195SDaniel Vetter }
276052217195SDaniel Vetter 
276152217195SDaniel Vetter static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
276252217195SDaniel Vetter {
276352217195SDaniel Vetter 	/* For atomic drivers only state objects are synchronously updated and
2764c2ce66daSBeatriz Martins de Carvalho 	 * protected by modeset locks, so check those first.
2765c2ce66daSBeatriz Martins de Carvalho 	 */
276652217195SDaniel Vetter 	if (connector->state)
276752217195SDaniel Vetter 		return connector->state->best_encoder;
276852217195SDaniel Vetter 	return connector->encoder;
276952217195SDaniel Vetter }
277052217195SDaniel Vetter 
2771c3ff0cdbSAnkit Nautiyal static bool
2772c3ff0cdbSAnkit Nautiyal drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
27738445e2c5SVille Syrjälä 			     const struct list_head *modes,
277452217195SDaniel Vetter 			     const struct drm_file *file_priv)
277552217195SDaniel Vetter {
277652217195SDaniel Vetter 	/*
277752217195SDaniel Vetter 	 * If user-space hasn't configured the driver to expose the stereo 3D
277852217195SDaniel Vetter 	 * modes, don't expose them.
277952217195SDaniel Vetter 	 */
278052217195SDaniel Vetter 	if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
278152217195SDaniel Vetter 		return false;
2782c3ff0cdbSAnkit Nautiyal 	/*
2783c3ff0cdbSAnkit Nautiyal 	 * If user-space hasn't configured the driver to expose the modes
2784c3ff0cdbSAnkit Nautiyal 	 * with aspect-ratio, don't expose them. However if such a mode
2785c3ff0cdbSAnkit Nautiyal 	 * is unique, let it be exposed, but reset the aspect-ratio flags
2786c3ff0cdbSAnkit Nautiyal 	 * while preparing the list of user-modes.
2787c3ff0cdbSAnkit Nautiyal 	 */
2788c3ff0cdbSAnkit Nautiyal 	if (!file_priv->aspect_ratio_allowed) {
27898445e2c5SVille Syrjälä 		const struct drm_display_mode *mode_itr;
2790c3ff0cdbSAnkit Nautiyal 
27918445e2c5SVille Syrjälä 		list_for_each_entry(mode_itr, modes, head) {
27928445e2c5SVille Syrjälä 			if (mode_itr->expose_to_userspace &&
27938445e2c5SVille Syrjälä 			    drm_mode_match(mode_itr, mode,
2794c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_TIMINGS |
2795c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_CLOCK |
2796c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_FLAGS |
2797c3ff0cdbSAnkit Nautiyal 					   DRM_MODE_MATCH_3D_FLAGS))
2798c3ff0cdbSAnkit Nautiyal 				return false;
2799c3ff0cdbSAnkit Nautiyal 		}
28008445e2c5SVille Syrjälä 	}
280152217195SDaniel Vetter 
280252217195SDaniel Vetter 	return true;
280352217195SDaniel Vetter }
280452217195SDaniel Vetter 
280552217195SDaniel Vetter int drm_mode_getconnector(struct drm_device *dev, void *data,
280652217195SDaniel Vetter 			  struct drm_file *file_priv)
280752217195SDaniel Vetter {
280852217195SDaniel Vetter 	struct drm_mode_get_connector *out_resp = data;
280952217195SDaniel Vetter 	struct drm_connector *connector;
281052217195SDaniel Vetter 	struct drm_encoder *encoder;
281152217195SDaniel Vetter 	struct drm_display_mode *mode;
281252217195SDaniel Vetter 	int mode_count = 0;
281352217195SDaniel Vetter 	int encoders_count = 0;
281452217195SDaniel Vetter 	int ret = 0;
281552217195SDaniel Vetter 	int copied = 0;
281652217195SDaniel Vetter 	struct drm_mode_modeinfo u_mode;
281752217195SDaniel Vetter 	struct drm_mode_modeinfo __user *mode_ptr;
281852217195SDaniel Vetter 	uint32_t __user *encoder_ptr;
2819869e76f7SDesmond Cheong Zhi Xi 	bool is_current_master;
282052217195SDaniel Vetter 
282152217195SDaniel Vetter 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
282269fdf420SChris Wilson 		return -EOPNOTSUPP;
282352217195SDaniel Vetter 
282452217195SDaniel Vetter 	memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
282552217195SDaniel Vetter 
2826418da172SKeith Packard 	connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
282791eefc05SDaniel Vetter 	if (!connector)
282891eefc05SDaniel Vetter 		return -ENOENT;
282952217195SDaniel Vetter 
283062afb4adSJosé Roberto de Souza 	encoders_count = hweight32(connector->possible_encoders);
283191eefc05SDaniel Vetter 
283291eefc05SDaniel Vetter 	if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
283391eefc05SDaniel Vetter 		copied = 0;
283491eefc05SDaniel Vetter 		encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
283583aefbb8SVille Syrjälä 
283662afb4adSJosé Roberto de Souza 		drm_connector_for_each_possible_encoder(connector, encoder) {
283783aefbb8SVille Syrjälä 			if (put_user(encoder->base.id, encoder_ptr + copied)) {
283891eefc05SDaniel Vetter 				ret = -EFAULT;
2839e94ac351SDaniel Vetter 				goto out;
284091eefc05SDaniel Vetter 			}
284191eefc05SDaniel Vetter 			copied++;
284291eefc05SDaniel Vetter 		}
284391eefc05SDaniel Vetter 	}
284491eefc05SDaniel Vetter 	out_resp->count_encoders = encoders_count;
284591eefc05SDaniel Vetter 
284691eefc05SDaniel Vetter 	out_resp->connector_id = connector->base.id;
284791eefc05SDaniel Vetter 	out_resp->connector_type = connector->connector_type;
284891eefc05SDaniel Vetter 	out_resp->connector_type_id = connector->connector_type_id;
284991eefc05SDaniel Vetter 
2850869e76f7SDesmond Cheong Zhi Xi 	is_current_master = drm_is_current_master(file_priv);
2851869e76f7SDesmond Cheong Zhi Xi 
285291eefc05SDaniel Vetter 	mutex_lock(&dev->mode_config.mutex);
285391eefc05SDaniel Vetter 	if (out_resp->count_modes == 0) {
2854869e76f7SDesmond Cheong Zhi Xi 		if (is_current_master)
285591eefc05SDaniel Vetter 			connector->funcs->fill_modes(connector,
285691eefc05SDaniel Vetter 						     dev->mode_config.max_width,
285791eefc05SDaniel Vetter 						     dev->mode_config.max_height);
28588f86c82aSSimon Ser 		else
28598f86c82aSSimon 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",
28608f86c82aSSimon Ser 				    connector->base.id, connector->name);
286191eefc05SDaniel Vetter 	}
286291eefc05SDaniel Vetter 
286391eefc05SDaniel Vetter 	out_resp->mm_width = connector->display_info.width_mm;
286491eefc05SDaniel Vetter 	out_resp->mm_height = connector->display_info.height_mm;
286591eefc05SDaniel Vetter 	out_resp->subpixel = connector->display_info.subpixel_order;
286691eefc05SDaniel Vetter 	out_resp->connection = connector->status;
286791eefc05SDaniel Vetter 
286891eefc05SDaniel Vetter 	/* delayed so we get modes regardless of pre-fill_modes state */
28698445e2c5SVille Syrjälä 	list_for_each_entry(mode, &connector->modes, head) {
28708445e2c5SVille Syrjälä 		WARN_ON(mode->expose_to_userspace);
28718445e2c5SVille Syrjälä 
28728445e2c5SVille Syrjälä 		if (drm_mode_expose_to_userspace(mode, &connector->modes,
2873c3ff0cdbSAnkit Nautiyal 						 file_priv)) {
28748445e2c5SVille Syrjälä 			mode->expose_to_userspace = true;
287591eefc05SDaniel Vetter 			mode_count++;
2876c3ff0cdbSAnkit Nautiyal 		}
28778445e2c5SVille Syrjälä 	}
287891eefc05SDaniel Vetter 
287952217195SDaniel Vetter 	/*
288052217195SDaniel Vetter 	 * This ioctl is called twice, once to determine how much space is
288152217195SDaniel Vetter 	 * needed, and the 2nd time to fill it.
288252217195SDaniel Vetter 	 */
288352217195SDaniel Vetter 	if ((out_resp->count_modes >= mode_count) && mode_count) {
288452217195SDaniel Vetter 		copied = 0;
288552217195SDaniel Vetter 		mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
28868445e2c5SVille Syrjälä 		list_for_each_entry(mode, &connector->modes, head) {
28878445e2c5SVille Syrjälä 			if (!mode->expose_to_userspace)
28888445e2c5SVille Syrjälä 				continue;
28898445e2c5SVille Syrjälä 
28908445e2c5SVille Syrjälä 			/* Clear the tag for the next time around */
28918445e2c5SVille Syrjälä 			mode->expose_to_userspace = false;
28928445e2c5SVille Syrjälä 
289352217195SDaniel Vetter 			drm_mode_convert_to_umode(&u_mode, mode);
2894c3ff0cdbSAnkit Nautiyal 			/*
2895c3ff0cdbSAnkit Nautiyal 			 * Reset aspect ratio flags of user-mode, if modes with
2896c3ff0cdbSAnkit Nautiyal 			 * aspect-ratio are not supported.
2897c3ff0cdbSAnkit Nautiyal 			 */
2898c3ff0cdbSAnkit Nautiyal 			if (!file_priv->aspect_ratio_allowed)
2899c3ff0cdbSAnkit Nautiyal 				u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
290052217195SDaniel Vetter 			if (copy_to_user(mode_ptr + copied,
290152217195SDaniel Vetter 					 &u_mode, sizeof(u_mode))) {
290252217195SDaniel Vetter 				ret = -EFAULT;
29038445e2c5SVille Syrjälä 
29048445e2c5SVille Syrjälä 				/*
29058445e2c5SVille Syrjälä 				 * Clear the tag for the rest of
29068445e2c5SVille Syrjälä 				 * the modes for the next time around.
29078445e2c5SVille Syrjälä 				 */
29088445e2c5SVille Syrjälä 				list_for_each_entry_continue(mode, &connector->modes, head)
29098445e2c5SVille Syrjälä 					mode->expose_to_userspace = false;
29108445e2c5SVille Syrjälä 
2911e94ac351SDaniel Vetter 				mutex_unlock(&dev->mode_config.mutex);
2912e94ac351SDaniel Vetter 
291352217195SDaniel Vetter 				goto out;
291452217195SDaniel Vetter 			}
291552217195SDaniel Vetter 			copied++;
291652217195SDaniel Vetter 		}
29178445e2c5SVille Syrjälä 	} else {
29188445e2c5SVille Syrjälä 		/* Clear the tag for the next time around */
29198445e2c5SVille Syrjälä 		list_for_each_entry(mode, &connector->modes, head)
29208445e2c5SVille Syrjälä 			mode->expose_to_userspace = false;
292152217195SDaniel Vetter 	}
29228445e2c5SVille Syrjälä 
292352217195SDaniel Vetter 	out_resp->count_modes = mode_count;
292452217195SDaniel Vetter 	mutex_unlock(&dev->mode_config.mutex);
2925e94ac351SDaniel Vetter 
2926e94ac351SDaniel Vetter 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2927e94ac351SDaniel Vetter 	encoder = drm_connector_get_encoder(connector);
2928e94ac351SDaniel Vetter 	if (encoder)
2929e94ac351SDaniel Vetter 		out_resp->encoder_id = encoder->base.id;
2930e94ac351SDaniel Vetter 	else
2931e94ac351SDaniel Vetter 		out_resp->encoder_id = 0;
2932e94ac351SDaniel Vetter 
2933e94ac351SDaniel Vetter 	/* Only grab properties after probing, to make sure EDID and other
2934c2ce66daSBeatriz Martins de Carvalho 	 * properties reflect the latest status.
2935c2ce66daSBeatriz Martins de Carvalho 	 */
2936e94ac351SDaniel Vetter 	ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
2937e94ac351SDaniel Vetter 			(uint32_t __user *)(unsigned long)(out_resp->props_ptr),
2938e94ac351SDaniel Vetter 			(uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
2939e94ac351SDaniel Vetter 			&out_resp->count_props);
2940e94ac351SDaniel Vetter 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
2941e94ac351SDaniel Vetter 
2942e94ac351SDaniel Vetter out:
2943ad093607SThierry Reding 	drm_connector_put(connector);
294452217195SDaniel Vetter 
294552217195SDaniel Vetter 	return ret;
294652217195SDaniel Vetter }
294752217195SDaniel Vetter 
29483d3f7c1eSHans de Goede /**
29493d3f7c1eSHans de Goede  * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode
29503d3f7c1eSHans de Goede  * @fwnode: fwnode for which to find the matching drm_connector
29513d3f7c1eSHans de Goede  *
29523d3f7c1eSHans de Goede  * This functions looks up a drm_connector based on its associated fwnode. When
29533d3f7c1eSHans de Goede  * a connector is found a reference to the connector is returned. The caller must
29543d3f7c1eSHans de Goede  * call drm_connector_put() to release this reference when it is done with the
29553d3f7c1eSHans de Goede  * connector.
29563d3f7c1eSHans de Goede  *
29573d3f7c1eSHans de Goede  * Returns: A reference to the found connector or an ERR_PTR().
29583d3f7c1eSHans de Goede  */
29593d3f7c1eSHans de Goede struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode)
29603d3f7c1eSHans de Goede {
29613d3f7c1eSHans de Goede 	struct drm_connector *connector, *found = ERR_PTR(-ENODEV);
29623d3f7c1eSHans de Goede 
29633d3f7c1eSHans de Goede 	if (!fwnode)
29643d3f7c1eSHans de Goede 		return ERR_PTR(-ENODEV);
29653d3f7c1eSHans de Goede 
29663d3f7c1eSHans de Goede 	mutex_lock(&connector_list_lock);
29673d3f7c1eSHans de Goede 
29683d3f7c1eSHans de Goede 	list_for_each_entry(connector, &connector_list, global_connector_list_entry) {
29693d3f7c1eSHans de Goede 		if (connector->fwnode == fwnode ||
29703d3f7c1eSHans de Goede 		    (connector->fwnode && connector->fwnode->secondary == fwnode)) {
29713d3f7c1eSHans de Goede 			drm_connector_get(connector);
29723d3f7c1eSHans de Goede 			found = connector;
29733d3f7c1eSHans de Goede 			break;
29743d3f7c1eSHans de Goede 		}
29753d3f7c1eSHans de Goede 	}
29763d3f7c1eSHans de Goede 
29773d3f7c1eSHans de Goede 	mutex_unlock(&connector_list_lock);
29783d3f7c1eSHans de Goede 
29793d3f7c1eSHans de Goede 	return found;
29803d3f7c1eSHans de Goede }
29813d3f7c1eSHans de Goede 
298272ad4968SHans de Goede /**
298372ad4968SHans de Goede  * drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector
2984f85d9e59SRandy Dunlap  * @connector_fwnode: fwnode_handle to report the event on
298572ad4968SHans de Goede  *
298672ad4968SHans de Goede  * On some hardware a hotplug event notification may come from outside the display
298772ad4968SHans de Goede  * driver / device. An example of this is some USB Type-C setups where the hardware
298872ad4968SHans de Goede  * muxes the DisplayPort data and aux-lines but does not pass the altmode HPD
298972ad4968SHans de Goede  * status bit to the GPU's DP HPD pin.
299072ad4968SHans de Goede  *
299172ad4968SHans de Goede  * This function can be used to report these out-of-band events after obtaining
299272ad4968SHans de Goede  * a drm_connector reference through calling drm_connector_find_by_fwnode().
299372ad4968SHans de Goede  */
299472ad4968SHans de Goede void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode)
299572ad4968SHans de Goede {
299672ad4968SHans de Goede 	struct drm_connector *connector;
299772ad4968SHans de Goede 
299872ad4968SHans de Goede 	connector = drm_connector_find_by_fwnode(connector_fwnode);
299972ad4968SHans de Goede 	if (IS_ERR(connector))
300072ad4968SHans de Goede 		return;
300172ad4968SHans de Goede 
300272ad4968SHans de Goede 	if (connector->funcs->oob_hotplug_event)
300372ad4968SHans de Goede 		connector->funcs->oob_hotplug_event(connector);
300472ad4968SHans de Goede 
300572ad4968SHans de Goede 	drm_connector_put(connector);
300672ad4968SHans de Goede }
300772ad4968SHans de Goede EXPORT_SYMBOL(drm_connector_oob_hotplug_event);
300872ad4968SHans de Goede 
30099498c19bSDaniel Vetter 
30109498c19bSDaniel Vetter /**
30119498c19bSDaniel Vetter  * DOC: Tile group
30129498c19bSDaniel Vetter  *
30139498c19bSDaniel Vetter  * Tile groups are used to represent tiled monitors with a unique integer
30149498c19bSDaniel Vetter  * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
30159498c19bSDaniel Vetter  * we store this in a tile group, so we have a common identifier for all tiles
30169498c19bSDaniel Vetter  * in a monitor group. The property is called "TILE". Drivers can manage tile
30179498c19bSDaniel Vetter  * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
30189498c19bSDaniel Vetter  * drm_mode_get_tile_group(). But this is only needed for internal panels where
30199498c19bSDaniel Vetter  * the tile group information is exposed through a non-standard way.
30209498c19bSDaniel Vetter  */
30219498c19bSDaniel Vetter 
30229498c19bSDaniel Vetter static void drm_tile_group_free(struct kref *kref)
30239498c19bSDaniel Vetter {
30249498c19bSDaniel Vetter 	struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
30259498c19bSDaniel Vetter 	struct drm_device *dev = tg->dev;
3026948de842SSuraj Upadhyay 
30279498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
30289498c19bSDaniel Vetter 	idr_remove(&dev->mode_config.tile_idr, tg->id);
30299498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
30309498c19bSDaniel Vetter 	kfree(tg);
30319498c19bSDaniel Vetter }
30329498c19bSDaniel Vetter 
30339498c19bSDaniel Vetter /**
30349498c19bSDaniel Vetter  * drm_mode_put_tile_group - drop a reference to a tile group.
30359498c19bSDaniel Vetter  * @dev: DRM device
30369498c19bSDaniel Vetter  * @tg: tile group to drop reference to.
30379498c19bSDaniel Vetter  *
30389498c19bSDaniel Vetter  * drop reference to tile group and free if 0.
30399498c19bSDaniel Vetter  */
30409498c19bSDaniel Vetter void drm_mode_put_tile_group(struct drm_device *dev,
30419498c19bSDaniel Vetter 			     struct drm_tile_group *tg)
30429498c19bSDaniel Vetter {
30439498c19bSDaniel Vetter 	kref_put(&tg->refcount, drm_tile_group_free);
30449498c19bSDaniel Vetter }
30459498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_put_tile_group);
30469498c19bSDaniel Vetter 
30479498c19bSDaniel Vetter /**
30489498c19bSDaniel Vetter  * drm_mode_get_tile_group - get a reference to an existing tile group
30499498c19bSDaniel Vetter  * @dev: DRM device
30509498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
30519498c19bSDaniel Vetter  *
30529498c19bSDaniel Vetter  * Use the unique bytes to get a reference to an existing tile group.
30539498c19bSDaniel Vetter  *
30549498c19bSDaniel Vetter  * RETURNS:
30559498c19bSDaniel Vetter  * tile group or NULL if not found.
30569498c19bSDaniel Vetter  */
30579498c19bSDaniel Vetter struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
3058267ea759SVille Syrjälä 					       const char topology[8])
30599498c19bSDaniel Vetter {
30609498c19bSDaniel Vetter 	struct drm_tile_group *tg;
30619498c19bSDaniel Vetter 	int id;
3062948de842SSuraj Upadhyay 
30639498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
30649498c19bSDaniel Vetter 	idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
30659498c19bSDaniel Vetter 		if (!memcmp(tg->group_data, topology, 8)) {
30669498c19bSDaniel Vetter 			if (!kref_get_unless_zero(&tg->refcount))
30679498c19bSDaniel Vetter 				tg = NULL;
30689498c19bSDaniel Vetter 			mutex_unlock(&dev->mode_config.idr_mutex);
30699498c19bSDaniel Vetter 			return tg;
30709498c19bSDaniel Vetter 		}
30719498c19bSDaniel Vetter 	}
30729498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
30739498c19bSDaniel Vetter 	return NULL;
30749498c19bSDaniel Vetter }
30759498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_get_tile_group);
30769498c19bSDaniel Vetter 
30779498c19bSDaniel Vetter /**
30789498c19bSDaniel Vetter  * drm_mode_create_tile_group - create a tile group from a displayid description
30799498c19bSDaniel Vetter  * @dev: DRM device
30809498c19bSDaniel Vetter  * @topology: 8-bytes unique per monitor.
30819498c19bSDaniel Vetter  *
30829498c19bSDaniel Vetter  * Create a tile group for the unique monitor, and get a unique
30839498c19bSDaniel Vetter  * identifier for the tile group.
30849498c19bSDaniel Vetter  *
30859498c19bSDaniel Vetter  * RETURNS:
3086705c8160SDan Carpenter  * new tile group or NULL.
30879498c19bSDaniel Vetter  */
30889498c19bSDaniel Vetter struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
3089267ea759SVille Syrjälä 						  const char topology[8])
30909498c19bSDaniel Vetter {
30919498c19bSDaniel Vetter 	struct drm_tile_group *tg;
30929498c19bSDaniel Vetter 	int ret;
30939498c19bSDaniel Vetter 
30949498c19bSDaniel Vetter 	tg = kzalloc(sizeof(*tg), GFP_KERNEL);
30959498c19bSDaniel Vetter 	if (!tg)
3096705c8160SDan Carpenter 		return NULL;
30979498c19bSDaniel Vetter 
30989498c19bSDaniel Vetter 	kref_init(&tg->refcount);
30999498c19bSDaniel Vetter 	memcpy(tg->group_data, topology, 8);
31009498c19bSDaniel Vetter 	tg->dev = dev;
31019498c19bSDaniel Vetter 
31029498c19bSDaniel Vetter 	mutex_lock(&dev->mode_config.idr_mutex);
31039498c19bSDaniel Vetter 	ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
31049498c19bSDaniel Vetter 	if (ret >= 0) {
31059498c19bSDaniel Vetter 		tg->id = ret;
31069498c19bSDaniel Vetter 	} else {
31079498c19bSDaniel Vetter 		kfree(tg);
3108705c8160SDan Carpenter 		tg = NULL;
31099498c19bSDaniel Vetter 	}
31109498c19bSDaniel Vetter 
31119498c19bSDaniel Vetter 	mutex_unlock(&dev->mode_config.idr_mutex);
31129498c19bSDaniel Vetter 	return tg;
31139498c19bSDaniel Vetter }
31149498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tile_group);
3115