152217195SDaniel Vetter /* 252217195SDaniel Vetter * Copyright (c) 2016 Intel Corporation 352217195SDaniel Vetter * 452217195SDaniel Vetter * Permission to use, copy, modify, distribute, and sell this software and its 552217195SDaniel Vetter * documentation for any purpose is hereby granted without fee, provided that 652217195SDaniel Vetter * the above copyright notice appear in all copies and that both that copyright 752217195SDaniel Vetter * notice and this permission notice appear in supporting documentation, and 852217195SDaniel Vetter * that the name of the copyright holders not be used in advertising or 952217195SDaniel Vetter * publicity pertaining to distribution of the software without specific, 1052217195SDaniel Vetter * written prior permission. The copyright holders make no representations 1152217195SDaniel Vetter * about the suitability of this software for any purpose. It is provided "as 1252217195SDaniel Vetter * is" without express or implied warranty. 1352217195SDaniel Vetter * 1452217195SDaniel Vetter * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 1552217195SDaniel Vetter * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 1652217195SDaniel Vetter * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 1752217195SDaniel Vetter * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 1852217195SDaniel Vetter * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 1952217195SDaniel Vetter * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 2052217195SDaniel Vetter * OF THIS SOFTWARE. 2152217195SDaniel Vetter */ 2252217195SDaniel Vetter 238f86c82aSSimon Ser #include <drm/drm_auth.h> 2452217195SDaniel Vetter #include <drm/drm_connector.h> 25d71d8a4bSMaxime Ripard #include <drm/drm_drv.h> 2652217195SDaniel Vetter #include <drm/drm_edid.h> 279338203cSLaurent Pinchart #include <drm/drm_encoder.h> 2899f45e32SDaniel Vetter #include <drm/drm_file.h> 2935a3b82fSMaxime Ripard #include <drm/drm_managed.h> 30d71d8a4bSMaxime Ripard #include <drm/drm_panel.h> 31d71d8a4bSMaxime Ripard #include <drm/drm_print.h> 32334f74eeSHans de Goede #include <drm/drm_privacy_screen_consumer.h> 33968d81a6SJeykumar Sankaran #include <drm/drm_sysfs.h> 34d71d8a4bSMaxime Ripard #include <drm/drm_utils.h> 3599f45e32SDaniel Vetter 36495e440bSThomas Zimmermann #include <linux/property.h> 3799f45e32SDaniel Vetter #include <linux/uaccess.h> 3852217195SDaniel Vetter 39495e440bSThomas Zimmermann #include <video/cmdline.h> 40495e440bSThomas Zimmermann 4152217195SDaniel Vetter #include "drm_crtc_internal.h" 4252217195SDaniel Vetter #include "drm_internal.h" 4352217195SDaniel Vetter 44ae2a6da8SDaniel Vetter /** 45ae2a6da8SDaniel Vetter * DOC: overview 46ae2a6da8SDaniel Vetter * 47ae2a6da8SDaniel Vetter * In DRM connectors are the general abstraction for display sinks, and include 4884e543bcSAntonio Borneo * also fixed panels or anything else that can display pixels in some form. As 49ae2a6da8SDaniel Vetter * opposed to all other KMS objects representing hardware (like CRTC, encoder or 50ae2a6da8SDaniel Vetter * plane abstractions) connectors can be hotplugged and unplugged at runtime. 51ad093607SThierry Reding * Hence they are reference-counted using drm_connector_get() and 52ad093607SThierry Reding * drm_connector_put(). 53ae2a6da8SDaniel Vetter * 54d574528aSDaniel Vetter * KMS driver must create, initialize, register and attach at a &struct 55d574528aSDaniel Vetter * drm_connector for each such sink. The instance is created as other KMS 56aec97460SDaniel Vetter * objects and initialized by setting the following fields. The connector is 57aec97460SDaniel Vetter * initialized with a call to drm_connector_init() with a pointer to the 58aec97460SDaniel Vetter * &struct drm_connector_funcs and a connector type, and then exposed to 59aec97460SDaniel Vetter * userspace with a call to drm_connector_register(). 60ae2a6da8SDaniel Vetter * 61ae2a6da8SDaniel Vetter * Connectors must be attached to an encoder to be used. For devices that map 62ae2a6da8SDaniel Vetter * connectors to encoders 1:1, the connector should be attached at 63cde4c44dSDaniel Vetter * initialization time with a call to drm_connector_attach_encoder(). The 64d574528aSDaniel Vetter * driver must also set the &drm_connector.encoder field to point to the 65ae2a6da8SDaniel Vetter * attached encoder. 66ae2a6da8SDaniel Vetter * 67ae2a6da8SDaniel Vetter * For connectors which are not fixed (like built-in panels) the driver needs to 68ae2a6da8SDaniel Vetter * support hotplug notifications. The simplest way to do that is by using the 69ae2a6da8SDaniel Vetter * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have 70ae2a6da8SDaniel Vetter * hardware support for hotplug interrupts. Connectors with hardware hotplug 71ae2a6da8SDaniel Vetter * support can instead use e.g. drm_helper_hpd_irq_event(). 72ae2a6da8SDaniel Vetter */ 73ae2a6da8SDaniel Vetter 743d3f7c1eSHans de Goede /* 753d3f7c1eSHans de Goede * Global connector list for drm_connector_find_by_fwnode(). 763d3f7c1eSHans de Goede * Note drm_connector_[un]register() first take connector->lock and then 773d3f7c1eSHans de Goede * take the connector_list_lock. 783d3f7c1eSHans de Goede */ 793d3f7c1eSHans de Goede static DEFINE_MUTEX(connector_list_lock); 803d3f7c1eSHans de Goede static LIST_HEAD(connector_list); 813d3f7c1eSHans de Goede 8252217195SDaniel Vetter struct drm_conn_prop_enum_list { 8352217195SDaniel Vetter int type; 8452217195SDaniel Vetter const char *name; 8552217195SDaniel Vetter struct ida ida; 8652217195SDaniel Vetter }; 8752217195SDaniel Vetter 8852217195SDaniel Vetter /* 8952217195SDaniel Vetter * Connector and encoder types. 9052217195SDaniel Vetter */ 9152217195SDaniel Vetter static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { 9252217195SDaniel Vetter { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, 9352217195SDaniel Vetter { DRM_MODE_CONNECTOR_VGA, "VGA" }, 9452217195SDaniel Vetter { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, 9552217195SDaniel Vetter { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, 9652217195SDaniel Vetter { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, 9752217195SDaniel Vetter { DRM_MODE_CONNECTOR_Composite, "Composite" }, 9852217195SDaniel Vetter { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, 9952217195SDaniel Vetter { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, 10052217195SDaniel Vetter { DRM_MODE_CONNECTOR_Component, "Component" }, 10152217195SDaniel Vetter { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, 10252217195SDaniel Vetter { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, 10352217195SDaniel Vetter { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, 10452217195SDaniel Vetter { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, 10552217195SDaniel Vetter { DRM_MODE_CONNECTOR_TV, "TV" }, 10652217195SDaniel Vetter { DRM_MODE_CONNECTOR_eDP, "eDP" }, 10752217195SDaniel Vetter { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, 10852217195SDaniel Vetter { DRM_MODE_CONNECTOR_DSI, "DSI" }, 10952217195SDaniel Vetter { DRM_MODE_CONNECTOR_DPI, "DPI" }, 110935774cdSBrian Starkey { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" }, 111fc06bf1dSNoralf Trønnes { DRM_MODE_CONNECTOR_SPI, "SPI" }, 112757e2671SNoralf Trønnes { DRM_MODE_CONNECTOR_USB, "USB" }, 11352217195SDaniel Vetter }; 11452217195SDaniel Vetter 11552217195SDaniel Vetter void drm_connector_ida_init(void) 11652217195SDaniel Vetter { 11752217195SDaniel Vetter int i; 11852217195SDaniel Vetter 11952217195SDaniel Vetter for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) 12052217195SDaniel Vetter ida_init(&drm_connector_enum_list[i].ida); 12152217195SDaniel Vetter } 12252217195SDaniel Vetter 12352217195SDaniel Vetter void drm_connector_ida_destroy(void) 12452217195SDaniel Vetter { 12552217195SDaniel Vetter int i; 12652217195SDaniel Vetter 12752217195SDaniel Vetter for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) 12852217195SDaniel Vetter ida_destroy(&drm_connector_enum_list[i].ida); 12952217195SDaniel Vetter } 13052217195SDaniel Vetter 13152217195SDaniel Vetter /** 132b35f90f2SLaurent Pinchart * drm_get_connector_type_name - return a string for connector type 133b35f90f2SLaurent Pinchart * @type: The connector type (DRM_MODE_CONNECTOR_*) 134b35f90f2SLaurent Pinchart * 135b35f90f2SLaurent Pinchart * Returns: the name of the connector type, or NULL if the type is not valid. 136b35f90f2SLaurent Pinchart */ 137b35f90f2SLaurent Pinchart const char *drm_get_connector_type_name(unsigned int type) 138b35f90f2SLaurent Pinchart { 139b35f90f2SLaurent Pinchart if (type < ARRAY_SIZE(drm_connector_enum_list)) 140b35f90f2SLaurent Pinchart return drm_connector_enum_list[type].name; 141b35f90f2SLaurent Pinchart 142b35f90f2SLaurent Pinchart return NULL; 143b35f90f2SLaurent Pinchart } 144b35f90f2SLaurent Pinchart EXPORT_SYMBOL(drm_get_connector_type_name); 145b35f90f2SLaurent Pinchart 146b35f90f2SLaurent Pinchart /** 14752217195SDaniel Vetter * drm_connector_get_cmdline_mode - reads the user's cmdline mode 14884e543bcSAntonio Borneo * @connector: connector to query 14952217195SDaniel Vetter * 150ae2a6da8SDaniel Vetter * The kernel supports per-connector configuration of its consoles through 15152217195SDaniel Vetter * use of the video= parameter. This function parses that option and 15252217195SDaniel Vetter * extracts the user's specified mode (or enable/disable status) for a 15352217195SDaniel Vetter * particular connector. This is typically only used during the early fbdev 15452217195SDaniel Vetter * setup. 15552217195SDaniel Vetter */ 15652217195SDaniel Vetter static void drm_connector_get_cmdline_mode(struct drm_connector *connector) 15752217195SDaniel Vetter { 15852217195SDaniel Vetter struct drm_cmdline_mode *mode = &connector->cmdline_mode; 159495e440bSThomas Zimmermann const char *option; 16052217195SDaniel Vetter 161495e440bSThomas Zimmermann option = video_get_options(connector->name); 162495e440bSThomas Zimmermann if (!option) 16352217195SDaniel Vetter return; 16452217195SDaniel Vetter 16552217195SDaniel Vetter if (!drm_mode_parse_command_line_for_connector(option, 16652217195SDaniel Vetter connector, 16752217195SDaniel Vetter mode)) 16852217195SDaniel Vetter return; 16952217195SDaniel Vetter 17052217195SDaniel Vetter if (mode->force) { 1716140cf20SJani Nikula DRM_INFO("forcing %s connector %s\n", connector->name, 1726140cf20SJani Nikula drm_get_connector_force_name(mode->force)); 17352217195SDaniel Vetter connector->force = mode->force; 17452217195SDaniel Vetter } 17552217195SDaniel Vetter 1760980939dSHans de Goede if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) { 1770980939dSHans de Goede DRM_INFO("cmdline forces connector %s panel_orientation to %d\n", 1780980939dSHans de Goede connector->name, mode->panel_orientation); 1790980939dSHans de Goede drm_connector_set_panel_orientation(connector, 1800980939dSHans de Goede mode->panel_orientation); 1810980939dSHans de Goede } 1820980939dSHans de Goede 1833aeeb13dSMaxime Ripard DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n", 18450b0946dSMaxime Ripard connector->name, mode->name, 18552217195SDaniel Vetter mode->xres, mode->yres, 18652217195SDaniel Vetter mode->refresh_specified ? mode->refresh : 60, 18752217195SDaniel Vetter mode->rb ? " reduced blanking" : "", 18852217195SDaniel Vetter mode->margins ? " with margins" : "", 18952217195SDaniel Vetter mode->interlace ? " interlaced" : ""); 19052217195SDaniel Vetter } 19152217195SDaniel Vetter 19252217195SDaniel Vetter static void drm_connector_free(struct kref *kref) 19352217195SDaniel Vetter { 19452217195SDaniel Vetter struct drm_connector *connector = 19552217195SDaniel Vetter container_of(kref, struct drm_connector, base.refcount); 19652217195SDaniel Vetter struct drm_device *dev = connector->dev; 19752217195SDaniel Vetter 19852217195SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 19952217195SDaniel Vetter connector->funcs->destroy(connector); 20052217195SDaniel Vetter } 20152217195SDaniel Vetter 202ea497bb9SDaniel Vetter void drm_connector_free_work_fn(struct work_struct *work) 203a703c550SDaniel Vetter { 204ea497bb9SDaniel Vetter struct drm_connector *connector, *n; 205ea497bb9SDaniel Vetter struct drm_device *dev = 206ea497bb9SDaniel Vetter container_of(work, struct drm_device, mode_config.connector_free_work); 207ea497bb9SDaniel Vetter struct drm_mode_config *config = &dev->mode_config; 208ea497bb9SDaniel Vetter unsigned long flags; 209ea497bb9SDaniel Vetter struct llist_node *freed; 210a703c550SDaniel Vetter 211ea497bb9SDaniel Vetter spin_lock_irqsave(&config->connector_list_lock, flags); 212ea497bb9SDaniel Vetter freed = llist_del_all(&config->connector_free_list); 213ea497bb9SDaniel Vetter spin_unlock_irqrestore(&config->connector_list_lock, flags); 214ea497bb9SDaniel Vetter 215ea497bb9SDaniel Vetter llist_for_each_entry_safe(connector, n, freed, free_node) { 216a703c550SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 217a703c550SDaniel Vetter connector->funcs->destroy(connector); 218a703c550SDaniel Vetter } 219ea497bb9SDaniel Vetter } 220a703c550SDaniel Vetter 221b11af8a2SMaxime Ripard static int __drm_connector_init(struct drm_device *dev, 22252217195SDaniel Vetter struct drm_connector *connector, 22352217195SDaniel Vetter const struct drm_connector_funcs *funcs, 224b11af8a2SMaxime Ripard int connector_type, 225b11af8a2SMaxime Ripard struct i2c_adapter *ddc) 22652217195SDaniel Vetter { 22752217195SDaniel Vetter struct drm_mode_config *config = &dev->mode_config; 22852217195SDaniel Vetter int ret; 22952217195SDaniel Vetter struct ida *connector_ida = 23052217195SDaniel Vetter &drm_connector_enum_list[connector_type].ida; 23152217195SDaniel Vetter 232ba1f665fSHaneen Mohammed WARN_ON(drm_drv_uses_atomic_modeset(dev) && 233ba1f665fSHaneen Mohammed (!funcs->atomic_destroy_state || 234ba1f665fSHaneen Mohammed !funcs->atomic_duplicate_state)); 235ba1f665fSHaneen Mohammed 2362135ea7aSThierry Reding ret = __drm_mode_object_add(dev, &connector->base, 23752217195SDaniel Vetter DRM_MODE_OBJECT_CONNECTOR, 23852217195SDaniel Vetter false, drm_connector_free); 23952217195SDaniel Vetter if (ret) 240613051daSDaniel Vetter return ret; 24152217195SDaniel Vetter 24252217195SDaniel Vetter connector->base.properties = &connector->properties; 24352217195SDaniel Vetter connector->dev = dev; 24452217195SDaniel Vetter connector->funcs = funcs; 24552217195SDaniel Vetter 2462a8d3eacSVille Syrjälä /* connector index is used with 32bit bitmasks */ 247e5d6eeeaSBo Liu ret = ida_alloc_max(&config->connector_ida, 31, GFP_KERNEL); 2482a8d3eacSVille Syrjälä if (ret < 0) { 2492a8d3eacSVille Syrjälä DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n", 2502a8d3eacSVille Syrjälä drm_connector_enum_list[connector_type].name, 2512a8d3eacSVille Syrjälä ret); 25252217195SDaniel Vetter goto out_put; 2532a8d3eacSVille Syrjälä } 25452217195SDaniel Vetter connector->index = ret; 25552217195SDaniel Vetter ret = 0; 25652217195SDaniel Vetter 25752217195SDaniel Vetter connector->connector_type = connector_type; 25852217195SDaniel Vetter connector->connector_type_id = 259e5d6eeeaSBo Liu ida_alloc_min(connector_ida, 1, GFP_KERNEL); 26052217195SDaniel Vetter if (connector->connector_type_id < 0) { 26152217195SDaniel Vetter ret = connector->connector_type_id; 26252217195SDaniel Vetter goto out_put_id; 26352217195SDaniel Vetter } 26452217195SDaniel Vetter connector->name = 26552217195SDaniel Vetter kasprintf(GFP_KERNEL, "%s-%d", 26652217195SDaniel Vetter drm_connector_enum_list[connector_type].name, 26752217195SDaniel Vetter connector->connector_type_id); 26852217195SDaniel Vetter if (!connector->name) { 26952217195SDaniel Vetter ret = -ENOMEM; 27052217195SDaniel Vetter goto out_put_type_id; 27152217195SDaniel Vetter } 27252217195SDaniel Vetter 273b11af8a2SMaxime Ripard /* provide ddc symlink in sysfs */ 274b11af8a2SMaxime Ripard connector->ddc = ddc; 275b11af8a2SMaxime Ripard 2763d3f7c1eSHans de Goede INIT_LIST_HEAD(&connector->global_connector_list_entry); 27752217195SDaniel Vetter INIT_LIST_HEAD(&connector->probed_modes); 27852217195SDaniel Vetter INIT_LIST_HEAD(&connector->modes); 279e73ab00eSDaniel Vetter mutex_init(&connector->mutex); 28090b575f5SJani Nikula mutex_init(&connector->edid_override_mutex); 281f378b772SMaxime Ripard mutex_init(&connector->hdmi.infoframes.lock); 28252217195SDaniel Vetter connector->edid_blob_ptr = NULL; 2835186421cSStanislav Lisovskiy connector->epoch_counter = 0; 2842de3a078SManasi Navare connector->tile_blob_ptr = NULL; 28552217195SDaniel Vetter connector->status = connector_status_unknown; 2868d70f395SHans de Goede connector->display_info.panel_orientation = 2878d70f395SHans de Goede DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 28852217195SDaniel Vetter 28952217195SDaniel Vetter drm_connector_get_cmdline_mode(connector); 29052217195SDaniel Vetter 29152217195SDaniel Vetter /* We should add connectors at the end to avoid upsetting the connector 292c2ce66daSBeatriz Martins de Carvalho * index too much. 293c2ce66daSBeatriz Martins de Carvalho */ 294613051daSDaniel Vetter spin_lock_irq(&config->connector_list_lock); 29552217195SDaniel Vetter list_add_tail(&connector->head, &config->connector_list); 29652217195SDaniel Vetter config->num_connector++; 297613051daSDaniel Vetter spin_unlock_irq(&config->connector_list_lock); 29852217195SDaniel Vetter 299935774cdSBrian Starkey if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL && 300935774cdSBrian Starkey connector_type != DRM_MODE_CONNECTOR_WRITEBACK) 3016b7e2d5cSGerd Hoffmann drm_connector_attach_edid_property(connector); 30252217195SDaniel Vetter 30352217195SDaniel Vetter drm_object_attach_property(&connector->base, 30452217195SDaniel Vetter config->dpms_property, 0); 30552217195SDaniel Vetter 30640ee6fbeSManasi Navare drm_object_attach_property(&connector->base, 30740ee6fbeSManasi Navare config->link_status_property, 30840ee6fbeSManasi Navare 0); 30940ee6fbeSManasi Navare 31066660d4cSDave Airlie drm_object_attach_property(&connector->base, 31166660d4cSDave Airlie config->non_desktop_property, 31266660d4cSDave Airlie 0); 3132de3a078SManasi Navare drm_object_attach_property(&connector->base, 3142de3a078SManasi Navare config->tile_property, 3152de3a078SManasi Navare 0); 31666660d4cSDave Airlie 31752217195SDaniel Vetter if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { 31852217195SDaniel Vetter drm_object_attach_property(&connector->base, config->prop_crtc_id, 0); 31952217195SDaniel Vetter } 32052217195SDaniel Vetter 32152217195SDaniel Vetter connector->debugfs_entry = NULL; 32252217195SDaniel Vetter out_put_type_id: 32352217195SDaniel Vetter if (ret) 324e5d6eeeaSBo Liu ida_free(connector_ida, connector->connector_type_id); 32552217195SDaniel Vetter out_put_id: 32652217195SDaniel Vetter if (ret) 327e5d6eeeaSBo Liu ida_free(&config->connector_ida, connector->index); 32852217195SDaniel Vetter out_put: 32952217195SDaniel Vetter if (ret) 33052217195SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 33152217195SDaniel Vetter 33252217195SDaniel Vetter return ret; 33352217195SDaniel Vetter } 334b11af8a2SMaxime Ripard 335b11af8a2SMaxime Ripard /** 336b11af8a2SMaxime Ripard * drm_connector_init - Init a preallocated connector 337b11af8a2SMaxime Ripard * @dev: DRM device 338b11af8a2SMaxime Ripard * @connector: the connector to init 339b11af8a2SMaxime Ripard * @funcs: callbacks for this connector 340b11af8a2SMaxime Ripard * @connector_type: user visible type of the connector 341b11af8a2SMaxime Ripard * 342b11af8a2SMaxime Ripard * Initialises a preallocated connector. Connectors should be 343b11af8a2SMaxime Ripard * subclassed as part of driver connector objects. 344b11af8a2SMaxime Ripard * 345b11af8a2SMaxime Ripard * At driver unload time the driver's &drm_connector_funcs.destroy hook 346b11af8a2SMaxime Ripard * should call drm_connector_cleanup() and free the connector structure. 347b11af8a2SMaxime Ripard * The connector structure should not be allocated with devm_kzalloc(). 348b11af8a2SMaxime Ripard * 34935a3b82fSMaxime Ripard * Note: consider using drmm_connector_init() instead of 35035a3b82fSMaxime Ripard * drm_connector_init() to let the DRM managed resource infrastructure 35135a3b82fSMaxime Ripard * take care of cleanup and deallocation. 35235a3b82fSMaxime Ripard * 353b11af8a2SMaxime Ripard * Returns: 354b11af8a2SMaxime Ripard * Zero on success, error code on failure. 355b11af8a2SMaxime Ripard */ 356b11af8a2SMaxime Ripard int drm_connector_init(struct drm_device *dev, 357b11af8a2SMaxime Ripard struct drm_connector *connector, 358b11af8a2SMaxime Ripard const struct drm_connector_funcs *funcs, 359b11af8a2SMaxime Ripard int connector_type) 360b11af8a2SMaxime Ripard { 361a961b197SMaxime Ripard if (drm_WARN_ON(dev, !(funcs && funcs->destroy))) 362a961b197SMaxime Ripard return -EINVAL; 363a961b197SMaxime Ripard 364b11af8a2SMaxime Ripard return __drm_connector_init(dev, connector, funcs, connector_type, NULL); 365b11af8a2SMaxime Ripard } 36652217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_init); 36752217195SDaniel Vetter 36852217195SDaniel Vetter /** 369100163dfSAndrzej Pietrasiewicz * drm_connector_init_with_ddc - Init a preallocated connector 370100163dfSAndrzej Pietrasiewicz * @dev: DRM device 371100163dfSAndrzej Pietrasiewicz * @connector: the connector to init 372100163dfSAndrzej Pietrasiewicz * @funcs: callbacks for this connector 373100163dfSAndrzej Pietrasiewicz * @connector_type: user visible type of the connector 374100163dfSAndrzej Pietrasiewicz * @ddc: pointer to the associated ddc adapter 375100163dfSAndrzej Pietrasiewicz * 376100163dfSAndrzej Pietrasiewicz * Initialises a preallocated connector. Connectors should be 377100163dfSAndrzej Pietrasiewicz * subclassed as part of driver connector objects. 378100163dfSAndrzej Pietrasiewicz * 37900ec947cSMaxime Ripard * At driver unload time the driver's &drm_connector_funcs.destroy hook 38000ec947cSMaxime Ripard * should call drm_connector_cleanup() and free the connector structure. 38100ec947cSMaxime Ripard * The connector structure should not be allocated with devm_kzalloc(). 38200ec947cSMaxime Ripard * 383100163dfSAndrzej Pietrasiewicz * Ensures that the ddc field of the connector is correctly set. 384100163dfSAndrzej Pietrasiewicz * 38535a3b82fSMaxime Ripard * Note: consider using drmm_connector_init() instead of 38635a3b82fSMaxime Ripard * drm_connector_init_with_ddc() to let the DRM managed resource 38735a3b82fSMaxime Ripard * infrastructure take care of cleanup and deallocation. 38835a3b82fSMaxime Ripard * 389100163dfSAndrzej Pietrasiewicz * Returns: 390100163dfSAndrzej Pietrasiewicz * Zero on success, error code on failure. 391100163dfSAndrzej Pietrasiewicz */ 392100163dfSAndrzej Pietrasiewicz int drm_connector_init_with_ddc(struct drm_device *dev, 393100163dfSAndrzej Pietrasiewicz struct drm_connector *connector, 394100163dfSAndrzej Pietrasiewicz const struct drm_connector_funcs *funcs, 395100163dfSAndrzej Pietrasiewicz int connector_type, 396100163dfSAndrzej Pietrasiewicz struct i2c_adapter *ddc) 397100163dfSAndrzej Pietrasiewicz { 398a961b197SMaxime Ripard if (drm_WARN_ON(dev, !(funcs && funcs->destroy))) 399a961b197SMaxime Ripard return -EINVAL; 400a961b197SMaxime Ripard 401b11af8a2SMaxime Ripard return __drm_connector_init(dev, connector, funcs, connector_type, ddc); 402100163dfSAndrzej Pietrasiewicz } 403100163dfSAndrzej Pietrasiewicz EXPORT_SYMBOL(drm_connector_init_with_ddc); 404100163dfSAndrzej Pietrasiewicz 40535a3b82fSMaxime Ripard static void drm_connector_cleanup_action(struct drm_device *dev, 40635a3b82fSMaxime Ripard void *ptr) 40735a3b82fSMaxime Ripard { 40835a3b82fSMaxime Ripard struct drm_connector *connector = ptr; 40935a3b82fSMaxime Ripard 41035a3b82fSMaxime Ripard drm_connector_cleanup(connector); 41135a3b82fSMaxime Ripard } 41235a3b82fSMaxime Ripard 41335a3b82fSMaxime Ripard /** 41435a3b82fSMaxime Ripard * drmm_connector_init - Init a preallocated connector 41535a3b82fSMaxime Ripard * @dev: DRM device 41635a3b82fSMaxime Ripard * @connector: the connector to init 41735a3b82fSMaxime Ripard * @funcs: callbacks for this connector 41835a3b82fSMaxime Ripard * @connector_type: user visible type of the connector 41935a3b82fSMaxime Ripard * @ddc: optional pointer to the associated ddc adapter 42035a3b82fSMaxime Ripard * 42135a3b82fSMaxime Ripard * Initialises a preallocated connector. Connectors should be 42235a3b82fSMaxime Ripard * subclassed as part of driver connector objects. 42335a3b82fSMaxime Ripard * 42435a3b82fSMaxime Ripard * Cleanup is automatically handled with a call to 42535a3b82fSMaxime Ripard * drm_connector_cleanup() in a DRM-managed action. 42635a3b82fSMaxime Ripard * 42735a3b82fSMaxime Ripard * The connector structure should be allocated with drmm_kzalloc(). 42835a3b82fSMaxime Ripard * 429*a99aff26SJosé Expósito * The @drm_connector_funcs.destroy hook must be NULL. 430*a99aff26SJosé Expósito * 43135a3b82fSMaxime Ripard * Returns: 43235a3b82fSMaxime Ripard * Zero on success, error code on failure. 43335a3b82fSMaxime Ripard */ 43435a3b82fSMaxime Ripard int drmm_connector_init(struct drm_device *dev, 43535a3b82fSMaxime Ripard struct drm_connector *connector, 43635a3b82fSMaxime Ripard const struct drm_connector_funcs *funcs, 43735a3b82fSMaxime Ripard int connector_type, 43835a3b82fSMaxime Ripard struct i2c_adapter *ddc) 43935a3b82fSMaxime Ripard { 44035a3b82fSMaxime Ripard int ret; 44135a3b82fSMaxime Ripard 44235a3b82fSMaxime Ripard if (drm_WARN_ON(dev, funcs && funcs->destroy)) 44335a3b82fSMaxime Ripard return -EINVAL; 44435a3b82fSMaxime Ripard 445a91e5e3eSMaxime Ripard ret = __drm_connector_init(dev, connector, funcs, connector_type, ddc); 44635a3b82fSMaxime Ripard if (ret) 44735a3b82fSMaxime Ripard return ret; 44835a3b82fSMaxime Ripard 44935a3b82fSMaxime Ripard ret = drmm_add_action_or_reset(dev, drm_connector_cleanup_action, 45035a3b82fSMaxime Ripard connector); 45135a3b82fSMaxime Ripard if (ret) 45235a3b82fSMaxime Ripard return ret; 45335a3b82fSMaxime Ripard 45435a3b82fSMaxime Ripard return 0; 45535a3b82fSMaxime Ripard } 45635a3b82fSMaxime Ripard EXPORT_SYMBOL(drmm_connector_init); 45735a3b82fSMaxime Ripard 458100163dfSAndrzej Pietrasiewicz /** 459582d79f3SMaxime Ripard * drmm_connector_hdmi_init - Init a preallocated HDMI connector 460582d79f3SMaxime Ripard * @dev: DRM device 461582d79f3SMaxime Ripard * @connector: A pointer to the HDMI connector to init 462f378b772SMaxime Ripard * @vendor: HDMI Controller Vendor name 463f378b772SMaxime Ripard * @product: HDMI Controller Product name 464582d79f3SMaxime Ripard * @funcs: callbacks for this connector 465e5030a74SMaxime Ripard * @hdmi_funcs: HDMI-related callbacks for this connector 466582d79f3SMaxime Ripard * @connector_type: user visible type of the connector 467582d79f3SMaxime Ripard * @ddc: optional pointer to the associated ddc adapter 468948f01d5SMaxime Ripard * @supported_formats: Bitmask of @hdmi_colorspace listing supported output formats 469aadb3e16SMaxime Ripard * @max_bpc: Maximum bits per char the HDMI connector supports 470582d79f3SMaxime Ripard * 471582d79f3SMaxime Ripard * Initialises a preallocated HDMI connector. Connectors can be 472582d79f3SMaxime Ripard * subclassed as part of driver connector objects. 473582d79f3SMaxime Ripard * 474582d79f3SMaxime Ripard * Cleanup is automatically handled with a call to 475582d79f3SMaxime Ripard * drm_connector_cleanup() in a DRM-managed action. 476582d79f3SMaxime Ripard * 477582d79f3SMaxime Ripard * The connector structure should be allocated with drmm_kzalloc(). 478582d79f3SMaxime Ripard * 479*a99aff26SJosé Expósito * The @drm_connector_funcs.destroy hook must be NULL. 480*a99aff26SJosé Expósito * 481582d79f3SMaxime Ripard * Returns: 482582d79f3SMaxime Ripard * Zero on success, error code on failure. 483582d79f3SMaxime Ripard */ 484582d79f3SMaxime Ripard int drmm_connector_hdmi_init(struct drm_device *dev, 485582d79f3SMaxime Ripard struct drm_connector *connector, 486f378b772SMaxime Ripard const char *vendor, const char *product, 487582d79f3SMaxime Ripard const struct drm_connector_funcs *funcs, 488e5030a74SMaxime Ripard const struct drm_connector_hdmi_funcs *hdmi_funcs, 489582d79f3SMaxime Ripard int connector_type, 490aadb3e16SMaxime Ripard struct i2c_adapter *ddc, 491948f01d5SMaxime Ripard unsigned long supported_formats, 492aadb3e16SMaxime Ripard unsigned int max_bpc) 493582d79f3SMaxime Ripard { 494582d79f3SMaxime Ripard int ret; 495582d79f3SMaxime Ripard 496f378b772SMaxime Ripard if (!vendor || !product) 497f378b772SMaxime Ripard return -EINVAL; 498f378b772SMaxime Ripard 499f378b772SMaxime Ripard if ((strlen(vendor) > DRM_CONNECTOR_HDMI_VENDOR_LEN) || 500f378b772SMaxime Ripard (strlen(product) > DRM_CONNECTOR_HDMI_PRODUCT_LEN)) 501f378b772SMaxime Ripard return -EINVAL; 502f378b772SMaxime Ripard 503582d79f3SMaxime Ripard if (!(connector_type == DRM_MODE_CONNECTOR_HDMIA || 504582d79f3SMaxime Ripard connector_type == DRM_MODE_CONNECTOR_HDMIB)) 505582d79f3SMaxime Ripard return -EINVAL; 506582d79f3SMaxime Ripard 507948f01d5SMaxime Ripard if (!supported_formats || !(supported_formats & BIT(HDMI_COLORSPACE_RGB))) 508948f01d5SMaxime Ripard return -EINVAL; 509948f01d5SMaxime Ripard 510aadb3e16SMaxime Ripard if (!(max_bpc == 8 || max_bpc == 10 || max_bpc == 12)) 511aadb3e16SMaxime Ripard return -EINVAL; 512aadb3e16SMaxime Ripard 513582d79f3SMaxime Ripard ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc); 514582d79f3SMaxime Ripard if (ret) 515582d79f3SMaxime Ripard return ret; 516582d79f3SMaxime Ripard 517948f01d5SMaxime Ripard connector->hdmi.supported_formats = supported_formats; 518f378b772SMaxime Ripard strtomem_pad(connector->hdmi.vendor, vendor, 0); 519f378b772SMaxime Ripard strtomem_pad(connector->hdmi.product, product, 0); 520948f01d5SMaxime Ripard 521aadb3e16SMaxime Ripard /* 522aadb3e16SMaxime Ripard * drm_connector_attach_max_bpc_property() requires the 523aadb3e16SMaxime Ripard * connector to have a state. 524aadb3e16SMaxime Ripard */ 525aadb3e16SMaxime Ripard if (connector->funcs->reset) 526aadb3e16SMaxime Ripard connector->funcs->reset(connector); 527aadb3e16SMaxime Ripard 528aadb3e16SMaxime Ripard drm_connector_attach_max_bpc_property(connector, 8, max_bpc); 529aadb3e16SMaxime Ripard connector->max_bpc = max_bpc; 530aadb3e16SMaxime Ripard 531aadb3e16SMaxime Ripard if (max_bpc > 8) 532aadb3e16SMaxime Ripard drm_connector_attach_hdr_output_metadata_property(connector); 533aadb3e16SMaxime Ripard 534e5030a74SMaxime Ripard connector->hdmi.funcs = hdmi_funcs; 535e5030a74SMaxime Ripard 536582d79f3SMaxime Ripard return 0; 537582d79f3SMaxime Ripard } 538582d79f3SMaxime Ripard EXPORT_SYMBOL(drmm_connector_hdmi_init); 539582d79f3SMaxime Ripard 540582d79f3SMaxime Ripard /** 5416b7e2d5cSGerd Hoffmann * drm_connector_attach_edid_property - attach edid property. 5426b7e2d5cSGerd Hoffmann * @connector: the connector 5436b7e2d5cSGerd Hoffmann * 5446b7e2d5cSGerd Hoffmann * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a 5456b7e2d5cSGerd Hoffmann * edid property attached by default. This function can be used to 5466b7e2d5cSGerd Hoffmann * explicitly enable the edid property in these cases. 5476b7e2d5cSGerd Hoffmann */ 5486b7e2d5cSGerd Hoffmann void drm_connector_attach_edid_property(struct drm_connector *connector) 5496b7e2d5cSGerd Hoffmann { 5506b7e2d5cSGerd Hoffmann struct drm_mode_config *config = &connector->dev->mode_config; 5516b7e2d5cSGerd Hoffmann 5526b7e2d5cSGerd Hoffmann drm_object_attach_property(&connector->base, 5536b7e2d5cSGerd Hoffmann config->edid_property, 5546b7e2d5cSGerd Hoffmann 0); 5556b7e2d5cSGerd Hoffmann } 5566b7e2d5cSGerd Hoffmann EXPORT_SYMBOL(drm_connector_attach_edid_property); 5576b7e2d5cSGerd Hoffmann 5586b7e2d5cSGerd Hoffmann /** 559cde4c44dSDaniel Vetter * drm_connector_attach_encoder - attach a connector to an encoder 56052217195SDaniel Vetter * @connector: connector to attach 56152217195SDaniel Vetter * @encoder: encoder to attach @connector to 56252217195SDaniel Vetter * 56352217195SDaniel Vetter * This function links up a connector to an encoder. Note that the routing 56452217195SDaniel Vetter * restrictions between encoders and crtcs are exposed to userspace through the 56552217195SDaniel Vetter * possible_clones and possible_crtcs bitmasks. 56652217195SDaniel Vetter * 56752217195SDaniel Vetter * Returns: 56852217195SDaniel Vetter * Zero on success, negative errno on failure. 56952217195SDaniel Vetter */ 570cde4c44dSDaniel Vetter int drm_connector_attach_encoder(struct drm_connector *connector, 57152217195SDaniel Vetter struct drm_encoder *encoder) 57252217195SDaniel Vetter { 57352217195SDaniel Vetter /* 57452217195SDaniel Vetter * In the past, drivers have attempted to model the static association 57552217195SDaniel Vetter * of connector to encoder in simple connector/encoder devices using a 57652217195SDaniel Vetter * direct assignment of connector->encoder = encoder. This connection 57752217195SDaniel Vetter * is a logical one and the responsibility of the core, so drivers are 57852217195SDaniel Vetter * expected not to mess with this. 57952217195SDaniel Vetter * 58052217195SDaniel Vetter * Note that the error return should've been enough here, but a large 58152217195SDaniel Vetter * majority of drivers ignores the return value, so add in a big WARN 58252217195SDaniel Vetter * to get people's attention. 58352217195SDaniel Vetter */ 58452217195SDaniel Vetter if (WARN_ON(connector->encoder)) 58552217195SDaniel Vetter return -EINVAL; 58652217195SDaniel Vetter 58762afb4adSJosé Roberto de Souza connector->possible_encoders |= drm_encoder_mask(encoder); 58862afb4adSJosé Roberto de Souza 58952217195SDaniel Vetter return 0; 59052217195SDaniel Vetter } 591cde4c44dSDaniel Vetter EXPORT_SYMBOL(drm_connector_attach_encoder); 59252217195SDaniel Vetter 59338cb8d96SVille Syrjälä /** 59462afb4adSJosé Roberto de Souza * drm_connector_has_possible_encoder - check if the connector and encoder are 59562afb4adSJosé Roberto de Souza * associated with each other 59638cb8d96SVille Syrjälä * @connector: the connector 59738cb8d96SVille Syrjälä * @encoder: the encoder 59838cb8d96SVille Syrjälä * 59938cb8d96SVille Syrjälä * Returns: 60038cb8d96SVille Syrjälä * True if @encoder is one of the possible encoders for @connector. 60138cb8d96SVille Syrjälä */ 60238cb8d96SVille Syrjälä bool drm_connector_has_possible_encoder(struct drm_connector *connector, 60338cb8d96SVille Syrjälä struct drm_encoder *encoder) 60438cb8d96SVille Syrjälä { 60562afb4adSJosé Roberto de Souza return connector->possible_encoders & drm_encoder_mask(encoder); 60638cb8d96SVille Syrjälä } 60738cb8d96SVille Syrjälä EXPORT_SYMBOL(drm_connector_has_possible_encoder); 60838cb8d96SVille Syrjälä 60952217195SDaniel Vetter static void drm_mode_remove(struct drm_connector *connector, 61052217195SDaniel Vetter struct drm_display_mode *mode) 61152217195SDaniel Vetter { 61252217195SDaniel Vetter list_del(&mode->head); 61352217195SDaniel Vetter drm_mode_destroy(connector->dev, mode); 61452217195SDaniel Vetter } 61552217195SDaniel Vetter 61652217195SDaniel Vetter /** 61752217195SDaniel Vetter * drm_connector_cleanup - cleans up an initialised connector 61852217195SDaniel Vetter * @connector: connector to cleanup 61952217195SDaniel Vetter * 62052217195SDaniel Vetter * Cleans up the connector but doesn't free the object. 62152217195SDaniel Vetter */ 62252217195SDaniel Vetter void drm_connector_cleanup(struct drm_connector *connector) 62352217195SDaniel Vetter { 62452217195SDaniel Vetter struct drm_device *dev = connector->dev; 62552217195SDaniel Vetter struct drm_display_mode *mode, *t; 62652217195SDaniel Vetter 62752217195SDaniel Vetter /* The connector should have been removed from userspace long before 62852217195SDaniel Vetter * it is finally destroyed. 62952217195SDaniel Vetter */ 63039b50c60SLyude Paul if (WARN_ON(connector->registration_state == 63139b50c60SLyude Paul DRM_CONNECTOR_REGISTERED)) 63252217195SDaniel Vetter drm_connector_unregister(connector); 63352217195SDaniel Vetter 634334f74eeSHans de Goede if (connector->privacy_screen) { 635334f74eeSHans de Goede drm_privacy_screen_put(connector->privacy_screen); 636334f74eeSHans de Goede connector->privacy_screen = NULL; 637334f74eeSHans de Goede } 638334f74eeSHans de Goede 63952217195SDaniel Vetter if (connector->tile_group) { 64052217195SDaniel Vetter drm_mode_put_tile_group(dev, connector->tile_group); 64152217195SDaniel Vetter connector->tile_group = NULL; 64252217195SDaniel Vetter } 64352217195SDaniel Vetter 64452217195SDaniel Vetter list_for_each_entry_safe(mode, t, &connector->probed_modes, head) 64552217195SDaniel Vetter drm_mode_remove(connector, mode); 64652217195SDaniel Vetter 64752217195SDaniel Vetter list_for_each_entry_safe(mode, t, &connector->modes, head) 64852217195SDaniel Vetter drm_mode_remove(connector, mode); 64952217195SDaniel Vetter 650e5d6eeeaSBo Liu ida_free(&drm_connector_enum_list[connector->connector_type].ida, 65152217195SDaniel Vetter connector->connector_type_id); 65252217195SDaniel Vetter 653e5d6eeeaSBo Liu ida_free(&dev->mode_config.connector_ida, connector->index); 65452217195SDaniel Vetter 65552217195SDaniel Vetter kfree(connector->display_info.bus_formats); 656c3292ab5SJani Nikula kfree(connector->display_info.vics); 65752217195SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 65852217195SDaniel Vetter kfree(connector->name); 65952217195SDaniel Vetter connector->name = NULL; 66048c429c6SHans de Goede fwnode_handle_put(connector->fwnode); 66148c429c6SHans de Goede connector->fwnode = NULL; 662613051daSDaniel Vetter spin_lock_irq(&dev->mode_config.connector_list_lock); 66352217195SDaniel Vetter list_del(&connector->head); 66452217195SDaniel Vetter dev->mode_config.num_connector--; 665613051daSDaniel Vetter spin_unlock_irq(&dev->mode_config.connector_list_lock); 66652217195SDaniel Vetter 66752217195SDaniel Vetter WARN_ON(connector->state && !connector->funcs->atomic_destroy_state); 66852217195SDaniel Vetter if (connector->state && connector->funcs->atomic_destroy_state) 66952217195SDaniel Vetter connector->funcs->atomic_destroy_state(connector, 67052217195SDaniel Vetter connector->state); 67152217195SDaniel Vetter 672f378b772SMaxime Ripard mutex_destroy(&connector->hdmi.infoframes.lock); 673e73ab00eSDaniel Vetter mutex_destroy(&connector->mutex); 674e73ab00eSDaniel Vetter 67552217195SDaniel Vetter memset(connector, 0, sizeof(*connector)); 6766fdc2d49SSimon Ser 6776fdc2d49SSimon Ser if (dev->registered) 6786fdc2d49SSimon Ser drm_sysfs_hotplug_event(dev); 67952217195SDaniel Vetter } 68052217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_cleanup); 68152217195SDaniel Vetter 68252217195SDaniel Vetter /** 68352217195SDaniel Vetter * drm_connector_register - register a connector 68452217195SDaniel Vetter * @connector: the connector to register 68552217195SDaniel Vetter * 68669b22f51SDaniel Vetter * Register userspace interfaces for a connector. Only call this for connectors 68769b22f51SDaniel Vetter * which can be hotplugged after drm_dev_register() has been called already, 68869b22f51SDaniel Vetter * e.g. DP MST connectors. All other connectors will be registered automatically 68969b22f51SDaniel Vetter * when calling drm_dev_register(). 69052217195SDaniel Vetter * 691d87fbea5SMaxime Ripard * When the connector is no longer available, callers must call 692d87fbea5SMaxime Ripard * drm_connector_unregister(). 693d87fbea5SMaxime Ripard * 69452217195SDaniel Vetter * Returns: 69552217195SDaniel Vetter * Zero on success, error code on failure. 69652217195SDaniel Vetter */ 69752217195SDaniel Vetter int drm_connector_register(struct drm_connector *connector) 69852217195SDaniel Vetter { 699e73ab00eSDaniel Vetter int ret = 0; 70052217195SDaniel Vetter 701e6e7b48bSDaniel Vetter if (!connector->dev->registered) 702e6e7b48bSDaniel Vetter return 0; 703e6e7b48bSDaniel Vetter 704e73ab00eSDaniel Vetter mutex_lock(&connector->mutex); 70539b50c60SLyude Paul if (connector->registration_state != DRM_CONNECTOR_INITIALIZING) 706e73ab00eSDaniel Vetter goto unlock; 70752217195SDaniel Vetter 70852217195SDaniel Vetter ret = drm_sysfs_connector_add(connector); 70952217195SDaniel Vetter if (ret) 710e73ab00eSDaniel Vetter goto unlock; 71152217195SDaniel Vetter 712b792e640SGreg Kroah-Hartman drm_debugfs_connector_add(connector); 71352217195SDaniel Vetter 71452217195SDaniel Vetter if (connector->funcs->late_register) { 71552217195SDaniel Vetter ret = connector->funcs->late_register(connector); 71652217195SDaniel Vetter if (ret) 71752217195SDaniel Vetter goto err_debugfs; 71852217195SDaniel Vetter } 71952217195SDaniel Vetter 72021b6c281SVille Syrjälä ret = drm_sysfs_connector_add_late(connector); 72121b6c281SVille Syrjälä if (ret) 72221b6c281SVille Syrjälä goto err_late_register; 72321b6c281SVille Syrjälä 72452217195SDaniel Vetter drm_mode_object_register(connector->dev, &connector->base); 72552217195SDaniel Vetter 72639b50c60SLyude Paul connector->registration_state = DRM_CONNECTOR_REGISTERED; 727968d81a6SJeykumar Sankaran 728968d81a6SJeykumar Sankaran /* Let userspace know we have a new connector */ 729ad935754SSimon Ser drm_sysfs_connector_hotplug_event(connector); 730968d81a6SJeykumar Sankaran 731334f74eeSHans de Goede if (connector->privacy_screen) 732334f74eeSHans de Goede drm_privacy_screen_register_notifier(connector->privacy_screen, 733334f74eeSHans de Goede &connector->privacy_screen_notifier); 734334f74eeSHans de Goede 7353d3f7c1eSHans de Goede mutex_lock(&connector_list_lock); 7363d3f7c1eSHans de Goede list_add_tail(&connector->global_connector_list_entry, &connector_list); 7373d3f7c1eSHans de Goede mutex_unlock(&connector_list_lock); 738e73ab00eSDaniel Vetter goto unlock; 73952217195SDaniel Vetter 74021b6c281SVille Syrjälä err_late_register: 74121b6c281SVille Syrjälä if (connector->funcs->early_unregister) 74221b6c281SVille Syrjälä connector->funcs->early_unregister(connector); 74352217195SDaniel Vetter err_debugfs: 74452217195SDaniel Vetter drm_debugfs_connector_remove(connector); 74552217195SDaniel Vetter drm_sysfs_connector_remove(connector); 746e73ab00eSDaniel Vetter unlock: 747e73ab00eSDaniel Vetter mutex_unlock(&connector->mutex); 74852217195SDaniel Vetter return ret; 74952217195SDaniel Vetter } 75052217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_register); 75152217195SDaniel Vetter 75252217195SDaniel Vetter /** 75352217195SDaniel Vetter * drm_connector_unregister - unregister a connector 75452217195SDaniel Vetter * @connector: the connector to unregister 75552217195SDaniel Vetter * 75669b22f51SDaniel Vetter * Unregister userspace interfaces for a connector. Only call this for 757d87fbea5SMaxime Ripard * connectors which have been registered explicitly by calling 758d87fbea5SMaxime Ripard * drm_connector_register(). 75952217195SDaniel Vetter */ 76052217195SDaniel Vetter void drm_connector_unregister(struct drm_connector *connector) 76152217195SDaniel Vetter { 762e73ab00eSDaniel Vetter mutex_lock(&connector->mutex); 76339b50c60SLyude Paul if (connector->registration_state != DRM_CONNECTOR_REGISTERED) { 764e73ab00eSDaniel Vetter mutex_unlock(&connector->mutex); 76552217195SDaniel Vetter return; 766e73ab00eSDaniel Vetter } 76752217195SDaniel Vetter 7683d3f7c1eSHans de Goede mutex_lock(&connector_list_lock); 7693d3f7c1eSHans de Goede list_del_init(&connector->global_connector_list_entry); 7703d3f7c1eSHans de Goede mutex_unlock(&connector_list_lock); 7713d3f7c1eSHans de Goede 772334f74eeSHans de Goede if (connector->privacy_screen) 773334f74eeSHans de Goede drm_privacy_screen_unregister_notifier( 774334f74eeSHans de Goede connector->privacy_screen, 775334f74eeSHans de Goede &connector->privacy_screen_notifier); 776334f74eeSHans de Goede 77721b6c281SVille Syrjälä drm_sysfs_connector_remove_early(connector); 77821b6c281SVille Syrjälä 77952217195SDaniel Vetter if (connector->funcs->early_unregister) 78052217195SDaniel Vetter connector->funcs->early_unregister(connector); 78152217195SDaniel Vetter 78252217195SDaniel Vetter drm_debugfs_connector_remove(connector); 78383a30739SVille Syrjälä drm_sysfs_connector_remove(connector); 78452217195SDaniel Vetter 78539b50c60SLyude Paul connector->registration_state = DRM_CONNECTOR_UNREGISTERED; 786e73ab00eSDaniel Vetter mutex_unlock(&connector->mutex); 78752217195SDaniel Vetter } 78852217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_unregister); 78952217195SDaniel Vetter 79052217195SDaniel Vetter void drm_connector_unregister_all(struct drm_device *dev) 79152217195SDaniel Vetter { 79252217195SDaniel Vetter struct drm_connector *connector; 793613051daSDaniel Vetter struct drm_connector_list_iter conn_iter; 79452217195SDaniel Vetter 795b982dab1SThierry Reding drm_connector_list_iter_begin(dev, &conn_iter); 796613051daSDaniel Vetter drm_for_each_connector_iter(connector, &conn_iter) 79752217195SDaniel Vetter drm_connector_unregister(connector); 798b982dab1SThierry Reding drm_connector_list_iter_end(&conn_iter); 79952217195SDaniel Vetter } 80052217195SDaniel Vetter 80152217195SDaniel Vetter int drm_connector_register_all(struct drm_device *dev) 80252217195SDaniel Vetter { 80352217195SDaniel Vetter struct drm_connector *connector; 804613051daSDaniel Vetter struct drm_connector_list_iter conn_iter; 805613051daSDaniel Vetter int ret = 0; 80652217195SDaniel Vetter 807b982dab1SThierry Reding drm_connector_list_iter_begin(dev, &conn_iter); 808613051daSDaniel Vetter drm_for_each_connector_iter(connector, &conn_iter) { 80952217195SDaniel Vetter ret = drm_connector_register(connector); 81052217195SDaniel Vetter if (ret) 811613051daSDaniel Vetter break; 81252217195SDaniel Vetter } 813b982dab1SThierry Reding drm_connector_list_iter_end(&conn_iter); 81452217195SDaniel Vetter 815613051daSDaniel Vetter if (ret) 81652217195SDaniel Vetter drm_connector_unregister_all(dev); 81752217195SDaniel Vetter return ret; 81852217195SDaniel Vetter } 81952217195SDaniel Vetter 82052217195SDaniel Vetter /** 82152217195SDaniel Vetter * drm_get_connector_status_name - return a string for connector status 82252217195SDaniel Vetter * @status: connector status to compute name of 82352217195SDaniel Vetter * 82452217195SDaniel Vetter * In contrast to the other drm_get_*_name functions this one here returns a 82552217195SDaniel Vetter * const pointer and hence is threadsafe. 826f85d9e59SRandy Dunlap * 827f85d9e59SRandy Dunlap * Returns: connector status string 82852217195SDaniel Vetter */ 82952217195SDaniel Vetter const char *drm_get_connector_status_name(enum drm_connector_status status) 83052217195SDaniel Vetter { 83152217195SDaniel Vetter if (status == connector_status_connected) 83252217195SDaniel Vetter return "connected"; 83352217195SDaniel Vetter else if (status == connector_status_disconnected) 83452217195SDaniel Vetter return "disconnected"; 83552217195SDaniel Vetter else 83652217195SDaniel Vetter return "unknown"; 83752217195SDaniel Vetter } 83852217195SDaniel Vetter EXPORT_SYMBOL(drm_get_connector_status_name); 83952217195SDaniel Vetter 8406140cf20SJani Nikula /** 8416140cf20SJani Nikula * drm_get_connector_force_name - return a string for connector force 8426140cf20SJani Nikula * @force: connector force to get name of 8436140cf20SJani Nikula * 8446140cf20SJani Nikula * Returns: const pointer to name. 8456140cf20SJani Nikula */ 8466140cf20SJani Nikula const char *drm_get_connector_force_name(enum drm_connector_force force) 8476140cf20SJani Nikula { 8486140cf20SJani Nikula switch (force) { 8496140cf20SJani Nikula case DRM_FORCE_UNSPECIFIED: 8506140cf20SJani Nikula return "unspecified"; 8516140cf20SJani Nikula case DRM_FORCE_OFF: 8526140cf20SJani Nikula return "off"; 8536140cf20SJani Nikula case DRM_FORCE_ON: 8546140cf20SJani Nikula return "on"; 8556140cf20SJani Nikula case DRM_FORCE_ON_DIGITAL: 8566140cf20SJani Nikula return "digital"; 8576140cf20SJani Nikula default: 8586140cf20SJani Nikula return "unknown"; 8596140cf20SJani Nikula } 8606140cf20SJani Nikula } 8616140cf20SJani Nikula 862613051daSDaniel Vetter #ifdef CONFIG_LOCKDEP 863613051daSDaniel Vetter static struct lockdep_map connector_list_iter_dep_map = { 864613051daSDaniel Vetter .name = "drm_connector_list_iter" 865613051daSDaniel Vetter }; 866613051daSDaniel Vetter #endif 867613051daSDaniel Vetter 868613051daSDaniel Vetter /** 869b982dab1SThierry Reding * drm_connector_list_iter_begin - initialize a connector_list iterator 870613051daSDaniel Vetter * @dev: DRM device 871613051daSDaniel Vetter * @iter: connector_list iterator 872613051daSDaniel Vetter * 873d574528aSDaniel Vetter * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter 874b982dab1SThierry Reding * must always be cleaned up again by calling drm_connector_list_iter_end(). 875613051daSDaniel Vetter * Iteration itself happens using drm_connector_list_iter_next() or 876613051daSDaniel Vetter * drm_for_each_connector_iter(). 877613051daSDaniel Vetter */ 878b982dab1SThierry Reding void drm_connector_list_iter_begin(struct drm_device *dev, 879613051daSDaniel Vetter struct drm_connector_list_iter *iter) 880613051daSDaniel Vetter { 881613051daSDaniel Vetter iter->dev = dev; 882613051daSDaniel Vetter iter->conn = NULL; 883613051daSDaniel Vetter lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_); 884613051daSDaniel Vetter } 885b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_begin); 886613051daSDaniel Vetter 887a703c550SDaniel Vetter /* 888a703c550SDaniel Vetter * Extra-safe connector put function that works in any context. Should only be 889a703c550SDaniel Vetter * used from the connector_iter functions, where we never really expect to 890a703c550SDaniel Vetter * actually release the connector when dropping our final reference. 891a703c550SDaniel Vetter */ 892a703c550SDaniel Vetter static void 893ea497bb9SDaniel Vetter __drm_connector_put_safe(struct drm_connector *conn) 894a703c550SDaniel Vetter { 895ea497bb9SDaniel Vetter struct drm_mode_config *config = &conn->dev->mode_config; 896ea497bb9SDaniel Vetter 897ea497bb9SDaniel Vetter lockdep_assert_held(&config->connector_list_lock); 898ea497bb9SDaniel Vetter 899ea497bb9SDaniel Vetter if (!refcount_dec_and_test(&conn->base.refcount.refcount)) 900ea497bb9SDaniel Vetter return; 901ea497bb9SDaniel Vetter 902ea497bb9SDaniel Vetter llist_add(&conn->free_node, &config->connector_free_list); 903ea497bb9SDaniel Vetter schedule_work(&config->connector_free_work); 904a703c550SDaniel Vetter } 905a703c550SDaniel Vetter 906613051daSDaniel Vetter /** 907613051daSDaniel Vetter * drm_connector_list_iter_next - return next connector 9084f45c778SLyude Paul * @iter: connector_list iterator 909613051daSDaniel Vetter * 910f85d9e59SRandy Dunlap * Returns: the next connector for @iter, or NULL when the list walk has 911613051daSDaniel Vetter * completed. 912613051daSDaniel Vetter */ 913613051daSDaniel Vetter struct drm_connector * 914613051daSDaniel Vetter drm_connector_list_iter_next(struct drm_connector_list_iter *iter) 915613051daSDaniel Vetter { 916613051daSDaniel Vetter struct drm_connector *old_conn = iter->conn; 917613051daSDaniel Vetter struct drm_mode_config *config = &iter->dev->mode_config; 918613051daSDaniel Vetter struct list_head *lhead; 919613051daSDaniel Vetter unsigned long flags; 920613051daSDaniel Vetter 921613051daSDaniel Vetter spin_lock_irqsave(&config->connector_list_lock, flags); 922613051daSDaniel Vetter lhead = old_conn ? &old_conn->head : &config->connector_list; 923613051daSDaniel Vetter 924613051daSDaniel Vetter do { 925613051daSDaniel Vetter if (lhead->next == &config->connector_list) { 926613051daSDaniel Vetter iter->conn = NULL; 927613051daSDaniel Vetter break; 928613051daSDaniel Vetter } 929613051daSDaniel Vetter 930613051daSDaniel Vetter lhead = lhead->next; 931613051daSDaniel Vetter iter->conn = list_entry(lhead, struct drm_connector, head); 932613051daSDaniel Vetter 933613051daSDaniel Vetter /* loop until it's not a zombie connector */ 934613051daSDaniel Vetter } while (!kref_get_unless_zero(&iter->conn->base.refcount)); 935613051daSDaniel Vetter 936613051daSDaniel Vetter if (old_conn) 937ea497bb9SDaniel Vetter __drm_connector_put_safe(old_conn); 938ea497bb9SDaniel Vetter spin_unlock_irqrestore(&config->connector_list_lock, flags); 939613051daSDaniel Vetter 940613051daSDaniel Vetter return iter->conn; 941613051daSDaniel Vetter } 942613051daSDaniel Vetter EXPORT_SYMBOL(drm_connector_list_iter_next); 943613051daSDaniel Vetter 944613051daSDaniel Vetter /** 945b982dab1SThierry Reding * drm_connector_list_iter_end - tear down a connector_list iterator 946613051daSDaniel Vetter * @iter: connector_list iterator 947613051daSDaniel Vetter * 948613051daSDaniel Vetter * Tears down @iter and releases any resources (like &drm_connector references) 949613051daSDaniel Vetter * acquired while walking the list. This must always be called, both when the 950613051daSDaniel Vetter * iteration completes fully or when it was aborted without walking the entire 951613051daSDaniel Vetter * list. 952613051daSDaniel Vetter */ 953b982dab1SThierry Reding void drm_connector_list_iter_end(struct drm_connector_list_iter *iter) 954613051daSDaniel Vetter { 955ea497bb9SDaniel Vetter struct drm_mode_config *config = &iter->dev->mode_config; 956ea497bb9SDaniel Vetter unsigned long flags; 957ea497bb9SDaniel Vetter 958613051daSDaniel Vetter iter->dev = NULL; 959ea497bb9SDaniel Vetter if (iter->conn) { 960ea497bb9SDaniel Vetter spin_lock_irqsave(&config->connector_list_lock, flags); 961ea497bb9SDaniel Vetter __drm_connector_put_safe(iter->conn); 962ea497bb9SDaniel Vetter spin_unlock_irqrestore(&config->connector_list_lock, flags); 963ea497bb9SDaniel Vetter } 9645facae4fSQian Cai lock_release(&connector_list_iter_dep_map, _RET_IP_); 965613051daSDaniel Vetter } 966b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_end); 967613051daSDaniel Vetter 96852217195SDaniel Vetter static const struct drm_prop_enum_list drm_subpixel_enum_list[] = { 96952217195SDaniel Vetter { SubPixelUnknown, "Unknown" }, 97052217195SDaniel Vetter { SubPixelHorizontalRGB, "Horizontal RGB" }, 97152217195SDaniel Vetter { SubPixelHorizontalBGR, "Horizontal BGR" }, 97252217195SDaniel Vetter { SubPixelVerticalRGB, "Vertical RGB" }, 97352217195SDaniel Vetter { SubPixelVerticalBGR, "Vertical BGR" }, 97452217195SDaniel Vetter { SubPixelNone, "None" }, 97552217195SDaniel Vetter }; 97652217195SDaniel Vetter 97752217195SDaniel Vetter /** 97852217195SDaniel Vetter * drm_get_subpixel_order_name - return a string for a given subpixel enum 97952217195SDaniel Vetter * @order: enum of subpixel_order 98052217195SDaniel Vetter * 98152217195SDaniel Vetter * Note you could abuse this and return something out of bounds, but that 98252217195SDaniel Vetter * would be a caller error. No unscrubbed user data should make it here. 983f85d9e59SRandy Dunlap * 984f85d9e59SRandy Dunlap * Returns: string describing an enumerated subpixel property 98552217195SDaniel Vetter */ 98652217195SDaniel Vetter const char *drm_get_subpixel_order_name(enum subpixel_order order) 98752217195SDaniel Vetter { 98852217195SDaniel Vetter return drm_subpixel_enum_list[order].name; 98952217195SDaniel Vetter } 99052217195SDaniel Vetter EXPORT_SYMBOL(drm_get_subpixel_order_name); 99152217195SDaniel Vetter 99252217195SDaniel Vetter static const struct drm_prop_enum_list drm_dpms_enum_list[] = { 99352217195SDaniel Vetter { DRM_MODE_DPMS_ON, "On" }, 99452217195SDaniel Vetter { DRM_MODE_DPMS_STANDBY, "Standby" }, 99552217195SDaniel Vetter { DRM_MODE_DPMS_SUSPEND, "Suspend" }, 99652217195SDaniel Vetter { DRM_MODE_DPMS_OFF, "Off" } 99752217195SDaniel Vetter }; 99852217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) 99952217195SDaniel Vetter 100040ee6fbeSManasi Navare static const struct drm_prop_enum_list drm_link_status_enum_list[] = { 100140ee6fbeSManasi Navare { DRM_MODE_LINK_STATUS_GOOD, "Good" }, 100240ee6fbeSManasi Navare { DRM_MODE_LINK_STATUS_BAD, "Bad" }, 100340ee6fbeSManasi Navare }; 100440ee6fbeSManasi Navare 1005b3c6c8bfSDaniel Vetter /** 1006b3c6c8bfSDaniel Vetter * drm_display_info_set_bus_formats - set the supported bus formats 1007b3c6c8bfSDaniel Vetter * @info: display info to store bus formats in 1008b3c6c8bfSDaniel Vetter * @formats: array containing the supported bus formats 1009b3c6c8bfSDaniel Vetter * @num_formats: the number of entries in the fmts array 1010b3c6c8bfSDaniel Vetter * 1011b3c6c8bfSDaniel Vetter * Store the supported bus formats in display info structure. 1012b3c6c8bfSDaniel Vetter * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for 1013b3c6c8bfSDaniel Vetter * a full list of available formats. 1014f85d9e59SRandy Dunlap * 1015f85d9e59SRandy Dunlap * Returns: 1016f85d9e59SRandy Dunlap * 0 on success or a negative error code on failure. 1017b3c6c8bfSDaniel Vetter */ 1018b3c6c8bfSDaniel Vetter int drm_display_info_set_bus_formats(struct drm_display_info *info, 1019b3c6c8bfSDaniel Vetter const u32 *formats, 1020b3c6c8bfSDaniel Vetter unsigned int num_formats) 1021b3c6c8bfSDaniel Vetter { 1022b3c6c8bfSDaniel Vetter u32 *fmts = NULL; 1023b3c6c8bfSDaniel Vetter 1024b3c6c8bfSDaniel Vetter if (!formats && num_formats) 1025b3c6c8bfSDaniel Vetter return -EINVAL; 1026b3c6c8bfSDaniel Vetter 1027b3c6c8bfSDaniel Vetter if (formats && num_formats) { 1028b3c6c8bfSDaniel Vetter fmts = kmemdup(formats, sizeof(*formats) * num_formats, 1029b3c6c8bfSDaniel Vetter GFP_KERNEL); 1030b3c6c8bfSDaniel Vetter if (!fmts) 1031b3c6c8bfSDaniel Vetter return -ENOMEM; 1032b3c6c8bfSDaniel Vetter } 1033b3c6c8bfSDaniel Vetter 1034b3c6c8bfSDaniel Vetter kfree(info->bus_formats); 1035b3c6c8bfSDaniel Vetter info->bus_formats = fmts; 1036b3c6c8bfSDaniel Vetter info->num_bus_formats = num_formats; 1037b3c6c8bfSDaniel Vetter 1038b3c6c8bfSDaniel Vetter return 0; 1039b3c6c8bfSDaniel Vetter } 1040b3c6c8bfSDaniel Vetter EXPORT_SYMBOL(drm_display_info_set_bus_formats); 1041b3c6c8bfSDaniel Vetter 104252217195SDaniel Vetter /* Optional connector properties. */ 104352217195SDaniel Vetter static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = { 104452217195SDaniel Vetter { DRM_MODE_SCALE_NONE, "None" }, 104552217195SDaniel Vetter { DRM_MODE_SCALE_FULLSCREEN, "Full" }, 104652217195SDaniel Vetter { DRM_MODE_SCALE_CENTER, "Center" }, 104752217195SDaniel Vetter { DRM_MODE_SCALE_ASPECT, "Full aspect" }, 104852217195SDaniel Vetter }; 104952217195SDaniel Vetter 105052217195SDaniel Vetter static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = { 105152217195SDaniel Vetter { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" }, 105252217195SDaniel Vetter { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" }, 105352217195SDaniel Vetter { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" }, 105452217195SDaniel Vetter }; 105552217195SDaniel Vetter 105650525c33SStanislav Lisovskiy static const struct drm_prop_enum_list drm_content_type_enum_list[] = { 105750525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" }, 105850525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" }, 105950525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" }, 106050525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" }, 106150525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_GAME, "Game" }, 106250525c33SStanislav Lisovskiy }; 106350525c33SStanislav Lisovskiy 10648d70f395SHans de Goede static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = { 10658d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" }, 10668d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" }, 10678d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" }, 10688d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" }, 10698d70f395SHans de Goede }; 10708d70f395SHans de Goede 107152217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = { 107252217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ 107352217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ 107452217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ 107552217195SDaniel Vetter }; 107652217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) 107752217195SDaniel Vetter 107852217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = { 1079e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ 108052217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ 108152217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ 108252217195SDaniel Vetter }; 108352217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, 108452217195SDaniel Vetter drm_dvi_i_subconnector_enum_list) 108552217195SDaniel Vetter 10867d63cd85SMaxime Ripard static const struct drm_prop_enum_list drm_tv_mode_enum_list[] = { 10877d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_NTSC, "NTSC" }, 10887d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_NTSC_443, "NTSC-443" }, 10897d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_NTSC_J, "NTSC-J" }, 10907d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_PAL, "PAL" }, 10917d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_PAL_M, "PAL-M" }, 10927d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_PAL_N, "PAL-N" }, 10937d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_SECAM, "SECAM" }, 109441474d25SNick Hollinghurst { DRM_MODE_TV_MODE_MONOCHROME, "Mono" }, 10957d63cd85SMaxime Ripard }; 10967d63cd85SMaxime Ripard DRM_ENUM_NAME_FN(drm_get_tv_mode_name, drm_tv_mode_enum_list) 10977d63cd85SMaxime Ripard 1098d4613e3eSMaxime Ripard /** 1099d4613e3eSMaxime Ripard * drm_get_tv_mode_from_name - Translates a TV mode name into its enum value 1100d4613e3eSMaxime Ripard * @name: TV Mode name we want to convert 1101d4613e3eSMaxime Ripard * @len: Length of @name 1102d4613e3eSMaxime Ripard * 1103d4613e3eSMaxime Ripard * Translates @name into an enum drm_connector_tv_mode. 1104d4613e3eSMaxime Ripard * 1105d4613e3eSMaxime Ripard * Returns: the enum value on success, a negative errno otherwise. 1106d4613e3eSMaxime Ripard */ 1107d4613e3eSMaxime Ripard int drm_get_tv_mode_from_name(const char *name, size_t len) 1108d4613e3eSMaxime Ripard { 1109d4613e3eSMaxime Ripard unsigned int i; 1110d4613e3eSMaxime Ripard 1111d4613e3eSMaxime Ripard for (i = 0; i < ARRAY_SIZE(drm_tv_mode_enum_list); i++) { 1112d4613e3eSMaxime Ripard const struct drm_prop_enum_list *item = &drm_tv_mode_enum_list[i]; 1113d4613e3eSMaxime Ripard 1114d4613e3eSMaxime Ripard if (strlen(item->name) == len && !strncmp(item->name, name, len)) 1115d4613e3eSMaxime Ripard return item->type; 1116d4613e3eSMaxime Ripard } 1117d4613e3eSMaxime Ripard 1118d4613e3eSMaxime Ripard return -EINVAL; 1119d4613e3eSMaxime Ripard } 1120d4613e3eSMaxime Ripard EXPORT_SYMBOL(drm_get_tv_mode_from_name); 1121d4613e3eSMaxime Ripard 112252217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { 112352217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ 112452217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ 112552217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ 112652217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ 112752217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ 112852217195SDaniel Vetter }; 112952217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) 113052217195SDaniel Vetter 113152217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = { 1132e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ 113352217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ 113452217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ 113552217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ 113652217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ 113752217195SDaniel Vetter }; 113852217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, 113952217195SDaniel Vetter drm_tv_subconnector_enum_list) 114052217195SDaniel Vetter 1141e5b92773SOleg Vasilev static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = { 1142e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ 1143e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_VGA, "VGA" }, /* DP */ 1144e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DP */ 1145e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_HDMIA, "HDMI" }, /* DP */ 1146e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_DisplayPort, "DP" }, /* DP */ 1147e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Wireless, "Wireless" }, /* DP */ 1148e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Native, "Native" }, /* DP */ 1149e5b92773SOleg Vasilev }; 1150e5b92773SOleg Vasilev 1151e5b92773SOleg Vasilev DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name, 1152e5b92773SOleg Vasilev drm_dp_subconnector_enum_list) 1153e5b92773SOleg Vasilev 1154c627087cSHarry Wentland 1155c627087cSHarry Wentland static const char * const colorspace_names[] = { 1156d2c6a405SUma Shankar /* For Default case, driver will set the colorspace */ 1157c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_DEFAULT] = "Default", 1158d2c6a405SUma Shankar /* Standard Definition Colorimetry based on CEA 861 */ 1159c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = "SMPTE_170M_YCC", 1160c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_BT709_YCC] = "BT709_YCC", 1161d2c6a405SUma Shankar /* Standard Definition Colorimetry based on IEC 61966-2-4 */ 1162c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_XVYCC_601] = "XVYCC_601", 1163d2c6a405SUma Shankar /* High Definition Colorimetry based on IEC 61966-2-4 */ 1164c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_XVYCC_709] = "XVYCC_709", 1165d2c6a405SUma Shankar /* Colorimetry based on IEC 61966-2-1/Amendment 1 */ 1166c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_SYCC_601] = "SYCC_601", 1167d2c6a405SUma Shankar /* Colorimetry based on IEC 61966-2-5 [33] */ 1168c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_OPYCC_601] = "opYCC_601", 1169d2c6a405SUma Shankar /* Colorimetry based on IEC 61966-2-5 */ 1170c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_OPRGB] = "opRGB", 1171d2c6a405SUma Shankar /* Colorimetry based on ITU-R BT.2020 */ 1172c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_BT2020_CYCC] = "BT2020_CYCC", 1173d2c6a405SUma Shankar /* Colorimetry based on ITU-R BT.2020 */ 1174c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_BT2020_RGB] = "BT2020_RGB", 1175d2c6a405SUma Shankar /* Colorimetry based on ITU-R BT.2020 */ 1176c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_BT2020_YCC] = "BT2020_YCC", 1177d2c6a405SUma Shankar /* Added as part of Additional Colorimetry Extension in 861.G */ 1178c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65] = "DCI-P3_RGB_D65", 1179c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER] = "DCI-P3_RGB_Theater", 1180c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED] = "RGB_WIDE_FIXED", 1181c627087cSHarry Wentland /* Colorimetry based on scRGB (IEC 61966-2-2) */ 1182c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT] = "RGB_WIDE_FLOAT", 1183c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_BT601_YCC] = "BT601_YCC", 1184d2c6a405SUma Shankar }; 1185d2c6a405SUma Shankar 1186035d53e0SHarry Wentland /** 1187035d53e0SHarry Wentland * drm_get_colorspace_name - return a string for color encoding 1188035d53e0SHarry Wentland * @colorspace: color space to compute name of 1189035d53e0SHarry Wentland * 1190035d53e0SHarry Wentland * In contrast to the other drm_get_*_name functions this one here returns a 1191035d53e0SHarry Wentland * const pointer and hence is threadsafe. 1192035d53e0SHarry Wentland */ 1193035d53e0SHarry Wentland const char *drm_get_colorspace_name(enum drm_colorspace colorspace) 1194035d53e0SHarry Wentland { 1195035d53e0SHarry Wentland if (colorspace < ARRAY_SIZE(colorspace_names) && colorspace_names[colorspace]) 1196035d53e0SHarry Wentland return colorspace_names[colorspace]; 1197035d53e0SHarry Wentland else 1198035d53e0SHarry Wentland return "(null)"; 1199035d53e0SHarry Wentland } 1200035d53e0SHarry Wentland 1201c627087cSHarry Wentland static const u32 hdmi_colorspaces = 1202c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_SMPTE_170M_YCC) | 1203c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT709_YCC) | 1204c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_XVYCC_601) | 1205c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_XVYCC_709) | 1206c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_SYCC_601) | 1207c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_OPYCC_601) | 1208c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_OPRGB) | 1209c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) | 1210c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) | 1211c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT2020_YCC) | 1212c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) | 1213c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER); 1214c627087cSHarry Wentland 121545cf0e91SGwan-gyeong Mun /* 121645cf0e91SGwan-gyeong Mun * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry 121745cf0e91SGwan-gyeong Mun * Format Table 2-120 121845cf0e91SGwan-gyeong Mun */ 1219c627087cSHarry Wentland static const u32 dp_colorspaces = 1220c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED) | 1221c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT) | 1222c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_OPRGB) | 1223c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) | 1224c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) | 1225c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT601_YCC) | 1226c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT709_YCC) | 1227c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_XVYCC_601) | 1228c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_XVYCC_709) | 1229c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_SYCC_601) | 1230c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_OPYCC_601) | 1231c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) | 1232c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT2020_YCC); 123345cf0e91SGwan-gyeong Mun 1234ab52af4bSMaxime Ripard static const struct drm_prop_enum_list broadcast_rgb_names[] = { 1235ab52af4bSMaxime Ripard { DRM_HDMI_BROADCAST_RGB_AUTO, "Automatic" }, 1236ab52af4bSMaxime Ripard { DRM_HDMI_BROADCAST_RGB_FULL, "Full" }, 1237ab52af4bSMaxime Ripard { DRM_HDMI_BROADCAST_RGB_LIMITED, "Limited 16:235" }, 1238ab52af4bSMaxime Ripard }; 1239ab52af4bSMaxime Ripard 1240ab52af4bSMaxime Ripard /* 1241ab52af4bSMaxime Ripard * drm_hdmi_connector_get_broadcast_rgb_name - Return a string for HDMI connector RGB broadcast selection 1242ab52af4bSMaxime Ripard * @broadcast_rgb: Broadcast RGB selection to compute name of 1243ab52af4bSMaxime Ripard * 1244ab52af4bSMaxime Ripard * Returns: the name of the Broadcast RGB selection, or NULL if the type 1245ab52af4bSMaxime Ripard * is not valid. 1246ab52af4bSMaxime Ripard */ 1247ab52af4bSMaxime Ripard const char * 1248ab52af4bSMaxime Ripard drm_hdmi_connector_get_broadcast_rgb_name(enum drm_hdmi_broadcast_rgb broadcast_rgb) 1249ab52af4bSMaxime Ripard { 1250ab52af4bSMaxime Ripard if (broadcast_rgb >= ARRAY_SIZE(broadcast_rgb_names)) 1251ab52af4bSMaxime Ripard return NULL; 1252ab52af4bSMaxime Ripard 1253ab52af4bSMaxime Ripard return broadcast_rgb_names[broadcast_rgb].name; 1254ab52af4bSMaxime Ripard } 1255ab52af4bSMaxime Ripard EXPORT_SYMBOL(drm_hdmi_connector_get_broadcast_rgb_name); 1256ab52af4bSMaxime Ripard 1257948f01d5SMaxime Ripard static const char * const output_format_str[] = { 1258948f01d5SMaxime Ripard [HDMI_COLORSPACE_RGB] = "RGB", 1259948f01d5SMaxime Ripard [HDMI_COLORSPACE_YUV420] = "YUV 4:2:0", 1260948f01d5SMaxime Ripard [HDMI_COLORSPACE_YUV422] = "YUV 4:2:2", 1261948f01d5SMaxime Ripard [HDMI_COLORSPACE_YUV444] = "YUV 4:4:4", 1262948f01d5SMaxime Ripard }; 1263948f01d5SMaxime Ripard 1264948f01d5SMaxime Ripard /* 1265948f01d5SMaxime Ripard * drm_hdmi_connector_get_output_format_name() - Return a string for HDMI connector output format 1266948f01d5SMaxime Ripard * @fmt: Output format to compute name of 1267948f01d5SMaxime Ripard * 1268948f01d5SMaxime Ripard * Returns: the name of the output format, or NULL if the type is not 1269948f01d5SMaxime Ripard * valid. 1270948f01d5SMaxime Ripard */ 1271948f01d5SMaxime Ripard const char * 1272948f01d5SMaxime Ripard drm_hdmi_connector_get_output_format_name(enum hdmi_colorspace fmt) 1273948f01d5SMaxime Ripard { 1274948f01d5SMaxime Ripard if (fmt >= ARRAY_SIZE(output_format_str)) 1275948f01d5SMaxime Ripard return NULL; 1276948f01d5SMaxime Ripard 1277948f01d5SMaxime Ripard return output_format_str[fmt]; 1278948f01d5SMaxime Ripard } 1279948f01d5SMaxime Ripard EXPORT_SYMBOL(drm_hdmi_connector_get_output_format_name); 1280948f01d5SMaxime Ripard 12814ada6f22SDaniel Vetter /** 12824ada6f22SDaniel Vetter * DOC: standard connector properties 12834ada6f22SDaniel Vetter * 12844ada6f22SDaniel Vetter * DRM connectors have a few standardized properties: 12854ada6f22SDaniel Vetter * 12864ada6f22SDaniel Vetter * EDID: 12874ada6f22SDaniel Vetter * Blob property which contains the current EDID read from the sink. This 12884ada6f22SDaniel Vetter * is useful to parse sink identification information like vendor, model 12894ada6f22SDaniel Vetter * and serial. Drivers should update this property by calling 1290c555f023SDaniel Vetter * drm_connector_update_edid_property(), usually after having parsed 12914ada6f22SDaniel Vetter * the EDID using drm_add_edid_modes(). Userspace cannot change this 12924ada6f22SDaniel Vetter * property. 129312767469SSimon Ser * 129412767469SSimon Ser * User-space should not parse the EDID to obtain information exposed via 129512767469SSimon Ser * other KMS properties (because the kernel might apply limits, quirks or 129612767469SSimon Ser * fixups to the EDID). For instance, user-space should not try to parse 129712767469SSimon Ser * mode lists from the EDID. 12984ada6f22SDaniel Vetter * DPMS: 12994ada6f22SDaniel Vetter * Legacy property for setting the power state of the connector. For atomic 13004ada6f22SDaniel Vetter * drivers this is only provided for backwards compatibility with existing 13014ada6f22SDaniel Vetter * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the 13024ada6f22SDaniel Vetter * connector is linked to. Drivers should never set this property directly, 1303d574528aSDaniel Vetter * it is handled by the DRM core by calling the &drm_connector_funcs.dpms 1304144a7999SDaniel Vetter * callback. For atomic drivers the remapping to the "ACTIVE" property is 13051e3e4caeSSimon Ser * implemented in the DRM core. 1306d0d1aee5SDaniel Vetter * 1307d0d1aee5SDaniel Vetter * Note that this property cannot be set through the MODE_ATOMIC ioctl, 1308d0d1aee5SDaniel Vetter * userspace must use "ACTIVE" on the CRTC instead. 1309d0d1aee5SDaniel Vetter * 1310d0d1aee5SDaniel Vetter * WARNING: 1311d0d1aee5SDaniel Vetter * 1312d0d1aee5SDaniel Vetter * For userspace also running on legacy drivers the "DPMS" semantics are a 1313d0d1aee5SDaniel Vetter * lot more complicated. First, userspace cannot rely on the "DPMS" value 1314d0d1aee5SDaniel Vetter * returned by the GETCONNECTOR actually reflecting reality, because many 1315d0d1aee5SDaniel Vetter * drivers fail to update it. For atomic drivers this is taken care of in 1316d0d1aee5SDaniel Vetter * drm_atomic_helper_update_legacy_modeset_state(). 1317d0d1aee5SDaniel Vetter * 1318d0d1aee5SDaniel Vetter * The second issue is that the DPMS state is only well-defined when the 1319d0d1aee5SDaniel Vetter * connector is connected to a CRTC. In atomic the DRM core enforces that 1320d0d1aee5SDaniel Vetter * "ACTIVE" is off in such a case, no such checks exists for "DPMS". 1321d0d1aee5SDaniel Vetter * 1322d0d1aee5SDaniel Vetter * Finally, when enabling an output using the legacy SETCONFIG ioctl then 1323d0d1aee5SDaniel Vetter * "DPMS" is forced to ON. But see above, that might not be reflected in 1324d0d1aee5SDaniel Vetter * the software value on legacy drivers. 1325d0d1aee5SDaniel Vetter * 1326d0d1aee5SDaniel Vetter * Summarizing: Only set "DPMS" when the connector is known to be enabled, 1327d0d1aee5SDaniel Vetter * assume that a successful SETCONFIG call also sets "DPMS" to on, and 1328d0d1aee5SDaniel Vetter * never read back the value of "DPMS" because it can be incorrect. 13294ada6f22SDaniel Vetter * PATH: 13304ada6f22SDaniel Vetter * Connector path property to identify how this sink is physically 13314ada6f22SDaniel Vetter * connected. Used by DP MST. This should be set by calling 133297e14fbeSDaniel Vetter * drm_connector_set_path_property(), in the case of DP MST with the 13334ada6f22SDaniel Vetter * path property the MST manager created. Userspace cannot change this 13344ada6f22SDaniel Vetter * property. 133588b02ebcSSimon Ser * 133688b02ebcSSimon Ser * In the case of DP MST, the property has the format 133788b02ebcSSimon Ser * ``mst:<parent>-<ports>`` where ``<parent>`` is the KMS object ID of the 133888b02ebcSSimon Ser * parent connector and ``<ports>`` is a hyphen-separated list of DP MST 133988b02ebcSSimon Ser * port numbers. Note, KMS object IDs are not guaranteed to be stable 134088b02ebcSSimon Ser * across reboots. 13414ada6f22SDaniel Vetter * TILE: 13424ada6f22SDaniel Vetter * Connector tile group property to indicate how a set of DRM connector 13434ada6f22SDaniel Vetter * compose together into one logical screen. This is used by both high-res 13444ada6f22SDaniel Vetter * external screens (often only using a single cable, but exposing multiple 13454ada6f22SDaniel Vetter * DP MST sinks), or high-res integrated panels (like dual-link DSI) which 13464ada6f22SDaniel Vetter * are not gen-locked. Note that for tiled panels which are genlocked, like 13474ada6f22SDaniel Vetter * dual-link LVDS or dual-link DSI, the driver should try to not expose the 134884e543bcSAntonio Borneo * tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers 134997e14fbeSDaniel Vetter * should update this value using drm_connector_set_tile_property(). 13504ada6f22SDaniel Vetter * Userspace cannot change this property. 135140ee6fbeSManasi Navare * link-status: 1352716719a3SSean Paul * Connector link-status property to indicate the status of link. The 1353716719a3SSean Paul * default value of link-status is "GOOD". If something fails during or 1354716719a3SSean Paul * after modeset, the kernel driver may set this to "BAD" and issue a 1355716719a3SSean Paul * hotplug uevent. Drivers should update this value using 135697e14fbeSDaniel Vetter * drm_connector_set_link_status_property(). 1357a66da873SSimon Ser * 1358a66da873SSimon Ser * When user-space receives the hotplug uevent and detects a "BAD" 1359a66da873SSimon Ser * link-status, the sink doesn't receive pixels anymore (e.g. the screen 1360a66da873SSimon Ser * becomes completely black). The list of available modes may have 1361a66da873SSimon Ser * changed. User-space is expected to pick a new mode if the current one 1362a66da873SSimon Ser * has disappeared and perform a new modeset with link-status set to 1363a66da873SSimon Ser * "GOOD" to re-enable the connector. 1364a66da873SSimon Ser * 1365a66da873SSimon Ser * If multiple connectors share the same CRTC and one of them gets a "BAD" 1366a66da873SSimon Ser * link-status, the other are unaffected (ie. the sinks still continue to 1367a66da873SSimon Ser * receive pixels). 1368a66da873SSimon Ser * 1369a66da873SSimon Ser * When user-space performs an atomic commit on a connector with a "BAD" 1370a66da873SSimon Ser * link-status without resetting the property to "GOOD", the sink may 1371a66da873SSimon Ser * still not receive pixels. When user-space performs an atomic commit 1372a66da873SSimon Ser * which resets the link-status property to "GOOD" without the 1373a66da873SSimon Ser * ALLOW_MODESET flag set, it might fail because a modeset is required. 1374a66da873SSimon Ser * 1375a66da873SSimon Ser * User-space can only change link-status to "GOOD", changing it to "BAD" 1376a66da873SSimon Ser * is a no-op. 1377a66da873SSimon Ser * 1378a66da873SSimon Ser * For backwards compatibility with non-atomic userspace the kernel 1379a66da873SSimon Ser * tries to automatically set the link-status back to "GOOD" in the 1380a66da873SSimon Ser * SETCRTC IOCTL. This might fail if the mode is no longer valid, similar 1381a66da873SSimon Ser * to how it might fail if a different screen has been connected in the 1382a66da873SSimon Ser * interim. 138366660d4cSDave Airlie * non_desktop: 138466660d4cSDave Airlie * Indicates the output should be ignored for purposes of displaying a 138566660d4cSDave Airlie * standard desktop environment or console. This is most likely because 138666660d4cSDave Airlie * the output device is not rectilinear. 138724557865SSean Paul * Content Protection: 138824557865SSean Paul * This property is used by userspace to request the kernel protect future 138924557865SSean Paul * content communicated over the link. When requested, kernel will apply 139024557865SSean Paul * the appropriate means of protection (most often HDCP), and use the 139124557865SSean Paul * property to tell userspace the protection is active. 139224557865SSean Paul * 139324557865SSean Paul * Drivers can set this up by calling 139424557865SSean Paul * drm_connector_attach_content_protection_property() on initialization. 139524557865SSean Paul * 139624557865SSean Paul * The value of this property can be one of the following: 139724557865SSean Paul * 1398bbeba09fSDaniel Vetter * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0 139924557865SSean Paul * The link is not protected, content is transmitted in the clear. 1400bbeba09fSDaniel Vetter * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1 140124557865SSean Paul * Userspace has requested content protection, but the link is not 140224557865SSean Paul * currently protected. When in this state, kernel should enable 140324557865SSean Paul * Content Protection as soon as possible. 1404bbeba09fSDaniel Vetter * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2 140524557865SSean Paul * Userspace has requested content protection, and the link is 140624557865SSean Paul * protected. Only the driver can set the property to this value. 140724557865SSean Paul * If userspace attempts to set to ENABLED, kernel will return 140824557865SSean Paul * -EINVAL. 140924557865SSean Paul * 141024557865SSean Paul * A few guidelines: 141124557865SSean Paul * 141224557865SSean Paul * - DESIRED state should be preserved until userspace de-asserts it by 141324557865SSean Paul * setting the property to UNDESIRED. This means ENABLED should only 141424557865SSean Paul * transition to UNDESIRED when the user explicitly requests it. 141524557865SSean Paul * - If the state is DESIRED, kernel should attempt to re-authenticate the 141624557865SSean Paul * link whenever possible. This includes across disable/enable, dpms, 141724557865SSean Paul * hotplug, downstream device changes, link status failures, etc.. 1418bb5a45d4SRamalingam C * - Kernel sends uevent with the connector id and property id through 1419bb5a45d4SRamalingam C * @drm_hdcp_update_content_protection, upon below kernel triggered 1420bb5a45d4SRamalingam C * scenarios: 142112db36bcSSean Paul * 142212db36bcSSean Paul * - DESIRED -> ENABLED (authentication success) 142312db36bcSSean Paul * - ENABLED -> DESIRED (termination of authentication) 1424bb5a45d4SRamalingam C * - Please note no uevents for userspace triggered property state changes, 1425bb5a45d4SRamalingam C * which can't fail such as 142612db36bcSSean Paul * 142712db36bcSSean Paul * - DESIRED/ENABLED -> UNDESIRED 142812db36bcSSean Paul * - UNDESIRED -> DESIRED 1429bb5a45d4SRamalingam C * - Userspace is responsible for polling the property or listen to uevents 1430bb5a45d4SRamalingam C * to determine when the value transitions from ENABLED to DESIRED. 1431bb5a45d4SRamalingam C * This signifies the link is no longer protected and userspace should 1432bb5a45d4SRamalingam C * take appropriate action (whatever that might be). 14334ada6f22SDaniel Vetter * 14347672dbbaSRamalingam C * HDCP Content Type: 14357672dbbaSRamalingam C * This Enum property is used by the userspace to declare the content type 14367672dbbaSRamalingam C * of the display stream, to kernel. Here display stream stands for any 14377672dbbaSRamalingam C * display content that userspace intended to display through HDCP 14387672dbbaSRamalingam C * encryption. 14397672dbbaSRamalingam C * 14407672dbbaSRamalingam C * Content Type of a stream is decided by the owner of the stream, as 14417672dbbaSRamalingam C * "HDCP Type0" or "HDCP Type1". 14427672dbbaSRamalingam C * 14437672dbbaSRamalingam C * The value of the property can be one of the below: 14447672dbbaSRamalingam C * - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0 14457672dbbaSRamalingam C * - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1 14467672dbbaSRamalingam C * 14477672dbbaSRamalingam C * When kernel starts the HDCP authentication (see "Content Protection" 14487672dbbaSRamalingam C * for details), it uses the content type in "HDCP Content Type" 14497672dbbaSRamalingam C * for performing the HDCP authentication with the display sink. 14507672dbbaSRamalingam C * 14517672dbbaSRamalingam C * Please note in HDCP spec versions, a link can be authenticated with 14527672dbbaSRamalingam C * HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be 14537672dbbaSRamalingam C * authenticated with HDCP1.4 only for Content Type 0(though it is implicit 14547672dbbaSRamalingam C * in nature. As there is no reference for Content Type in HDCP1.4). 14557672dbbaSRamalingam C * 14567672dbbaSRamalingam C * HDCP2.2 authentication protocol itself takes the "Content Type" as a 14577672dbbaSRamalingam C * parameter, which is a input for the DP HDCP2.2 encryption algo. 14587672dbbaSRamalingam C * 14597672dbbaSRamalingam C * In case of Type 0 content protection request, kernel driver can choose 14607672dbbaSRamalingam C * either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for 14617672dbbaSRamalingam C * "HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send 14627672dbbaSRamalingam C * that content to a HDCP 1.4 authenticated HDCP sink (Type0 link). 14637672dbbaSRamalingam C * But if the content is classified as "HDCP Type 1", above mentioned 14647672dbbaSRamalingam C * HDCP 2.2 repeater wont send the content to the HDCP sink as it can't 14657672dbbaSRamalingam C * authenticate the HDCP1.4 capable sink for "HDCP Type 1". 14667672dbbaSRamalingam C * 14677672dbbaSRamalingam C * Please note userspace can be ignorant of the HDCP versions used by the 14687672dbbaSRamalingam C * kernel driver to achieve the "HDCP Content Type". 14697672dbbaSRamalingam C * 14707672dbbaSRamalingam C * At current scenario, classifying a content as Type 1 ensures that the 14717672dbbaSRamalingam C * content will be displayed only through the HDCP2.2 encrypted link. 14727672dbbaSRamalingam C * 14737672dbbaSRamalingam C * Note that the HDCP Content Type property is introduced at HDCP 2.2, and 14747672dbbaSRamalingam C * defaults to type 0. It is only exposed by drivers supporting HDCP 2.2 14757672dbbaSRamalingam C * (hence supporting Type 0 and Type 1). Based on how next versions of 14767672dbbaSRamalingam C * HDCP specs are defined content Type could be used for higher versions 14777672dbbaSRamalingam C * too. 14787672dbbaSRamalingam C * 14797672dbbaSRamalingam C * If content type is changed when "Content Protection" is not UNDESIRED, 14807672dbbaSRamalingam C * then kernel will disable the HDCP and re-enable with new type in the 14817672dbbaSRamalingam C * same atomic commit. And when "Content Protection" is ENABLED, it means 14827672dbbaSRamalingam C * that link is HDCP authenticated and encrypted, for the transmission of 14837672dbbaSRamalingam C * the Type of stream mentioned at "HDCP Content Type". 14847672dbbaSRamalingam C * 1485a09db883SUma Shankar * HDR_OUTPUT_METADATA: 1486a09db883SUma Shankar * Connector property to enable userspace to send HDR Metadata to 1487a09db883SUma Shankar * driver. This metadata is based on the composition and blending 1488a09db883SUma Shankar * policies decided by user, taking into account the hardware and 1489a09db883SUma Shankar * sink capabilities. The driver gets this metadata and creates a 1490a09db883SUma Shankar * Dynamic Range and Mastering Infoframe (DRM) in case of HDMI, 1491a09db883SUma Shankar * SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then 1492a09db883SUma Shankar * sent to sink. This notifies the sink of the upcoming frame's Color 1493a09db883SUma Shankar * Encoding and Luminance parameters. 1494a09db883SUma Shankar * 1495a09db883SUma Shankar * Userspace first need to detect the HDR capabilities of sink by 1496a09db883SUma Shankar * reading and parsing the EDID. Details of HDR metadata for HDMI 1497a09db883SUma Shankar * are added in CTA 861.G spec. For DP , its defined in VESA DP 1498a09db883SUma Shankar * Standard v1.4. It needs to then get the metadata information 1499a09db883SUma Shankar * of the video/game/app content which are encoded in HDR (basically 1500a09db883SUma Shankar * using HDR transfer functions). With this information it needs to 1501a09db883SUma Shankar * decide on a blending policy and compose the relevant 1502a09db883SUma Shankar * layers/overlays into a common format. Once this blending is done, 1503a09db883SUma Shankar * userspace will be aware of the metadata of the composed frame to 1504a09db883SUma Shankar * be send to sink. It then uses this property to communicate this 1505a09db883SUma Shankar * metadata to driver which then make a Infoframe packet and sends 1506a09db883SUma Shankar * to sink based on the type of encoder connected. 1507a09db883SUma Shankar * 1508a09db883SUma Shankar * Userspace will be responsible to do Tone mapping operation in case: 1509a09db883SUma Shankar * - Some layers are HDR and others are SDR 1510a09db883SUma Shankar * - HDR layers luminance is not same as sink 15119f9b2559SSean Paul * 1512a09db883SUma Shankar * It will even need to do colorspace conversion and get all layers 1513a09db883SUma Shankar * to one common colorspace for blending. It can use either GL, Media 151484e543bcSAntonio Borneo * or display engine to get this done based on the capabilities of the 1515a09db883SUma Shankar * associated hardware. 1516a09db883SUma Shankar * 1517a09db883SUma Shankar * Driver expects metadata to be put in &struct hdr_output_metadata 1518a09db883SUma Shankar * structure from userspace. This is received as blob and stored in 1519a09db883SUma Shankar * &drm_connector_state.hdr_output_metadata. It parses EDID and saves the 1520a09db883SUma Shankar * sink metadata in &struct hdr_sink_metadata, as 1521a09db883SUma Shankar * &drm_connector.hdr_sink_metadata. Driver uses 1522a09db883SUma Shankar * drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata, 1523a09db883SUma Shankar * hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of 1524a09db883SUma Shankar * HDMI encoder. 1525a09db883SUma Shankar * 152647e22ff1SRadhakrishna Sripada * max bpc: 152747e22ff1SRadhakrishna Sripada * This range property is used by userspace to limit the bit depth. When 152847e22ff1SRadhakrishna Sripada * used the driver would limit the bpc in accordance with the valid range 152947e22ff1SRadhakrishna Sripada * supported by the hardware and sink. Drivers to use the function 153047e22ff1SRadhakrishna Sripada * drm_connector_attach_max_bpc_property() to create and attach the 153147e22ff1SRadhakrishna Sripada * property to the connector during initialization. 153247e22ff1SRadhakrishna Sripada * 15334ada6f22SDaniel Vetter * Connectors also have one standardized atomic property: 15344ada6f22SDaniel Vetter * 15354ada6f22SDaniel Vetter * CRTC_ID: 15364ada6f22SDaniel Vetter * Mode object ID of the &drm_crtc this connector should be connected to. 15378d70f395SHans de Goede * 15388d70f395SHans de Goede * Connectors for LCD panels may also have one standardized property: 15398d70f395SHans de Goede * 15408d70f395SHans de Goede * panel orientation: 15418d70f395SHans de Goede * On some devices the LCD panel is mounted in the casing in such a way 15428d70f395SHans de Goede * that the up/top side of the panel does not match with the top side of 15438d70f395SHans de Goede * the device. Userspace can use this property to check for this. 15448d70f395SHans de Goede * Note that input coordinates from touchscreens (input devices with 15458d70f395SHans de Goede * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel 15468d70f395SHans de Goede * coordinates, so if userspace rotates the picture to adjust for 15478d70f395SHans de Goede * the orientation it must also apply the same transformation to the 1548bbeba09fSDaniel Vetter * touchscreen input coordinates. This property is initialized by calling 154969654c63SDerek Basehore * drm_connector_set_panel_orientation() or 155069654c63SDerek Basehore * drm_connector_set_panel_orientation_with_quirk() 1551bbeba09fSDaniel Vetter * 1552bbeba09fSDaniel Vetter * scaling mode: 1553bbeba09fSDaniel Vetter * This property defines how a non-native mode is upscaled to the native 1554bbeba09fSDaniel Vetter * mode of an LCD panel: 1555bbeba09fSDaniel Vetter * 1556bbeba09fSDaniel Vetter * None: 1557bbeba09fSDaniel Vetter * No upscaling happens, scaling is left to the panel. Not all 1558bbeba09fSDaniel Vetter * drivers expose this mode. 1559bbeba09fSDaniel Vetter * Full: 1560bbeba09fSDaniel Vetter * The output is upscaled to the full resolution of the panel, 1561bbeba09fSDaniel Vetter * ignoring the aspect ratio. 1562bbeba09fSDaniel Vetter * Center: 1563bbeba09fSDaniel Vetter * No upscaling happens, the output is centered within the native 1564bbeba09fSDaniel Vetter * resolution the panel. 1565bbeba09fSDaniel Vetter * Full aspect: 1566bbeba09fSDaniel Vetter * The output is upscaled to maximize either the width or height 1567bbeba09fSDaniel Vetter * while retaining the aspect ratio. 1568bbeba09fSDaniel Vetter * 1569bbeba09fSDaniel Vetter * This property should be set up by calling 1570bbeba09fSDaniel Vetter * drm_connector_attach_scaling_mode_property(). Note that drivers 1571bbeba09fSDaniel Vetter * can also expose this property to external outputs, in which case they 1572bbeba09fSDaniel Vetter * must support "None", which should be the default (since external screens 1573bbeba09fSDaniel Vetter * have a built-in scaler). 1574e5b92773SOleg Vasilev * 1575e5b92773SOleg Vasilev * subconnector: 1576e5b92773SOleg Vasilev * This property is used by DVI-I, TVout and DisplayPort to indicate different 1577e5b92773SOleg Vasilev * connector subtypes. Enum values more or less match with those from main 1578e5b92773SOleg Vasilev * connector types. 1579e5b92773SOleg Vasilev * For DVI-I and TVout there is also a matching property "select subconnector" 1580e5b92773SOleg Vasilev * allowing to switch between signal types. 1581e5b92773SOleg Vasilev * DP subconnector corresponds to a downstream port. 1582107fe904SRajat Jain * 1583107fe904SRajat Jain * privacy-screen sw-state, privacy-screen hw-state: 1584107fe904SRajat Jain * These 2 optional properties can be used to query the state of the 1585107fe904SRajat Jain * electronic privacy screen that is available on some displays; and in 1586107fe904SRajat Jain * some cases also control the state. If a driver implements these 1587107fe904SRajat Jain * properties then both properties must be present. 1588107fe904SRajat Jain * 1589107fe904SRajat Jain * "privacy-screen hw-state" is read-only and reflects the actual state 1590107fe904SRajat Jain * of the privacy-screen, possible values: "Enabled", "Disabled, 1591107fe904SRajat Jain * "Enabled-locked", "Disabled-locked". The locked states indicate 1592107fe904SRajat Jain * that the state cannot be changed through the DRM API. E.g. there 1593107fe904SRajat Jain * might be devices where the firmware-setup options, or a hardware 1594107fe904SRajat Jain * slider-switch, offer always on / off modes. 1595107fe904SRajat Jain * 1596107fe904SRajat Jain * "privacy-screen sw-state" can be set to change the privacy-screen state 1597107fe904SRajat Jain * when not locked. In this case the driver must update the hw-state 1598107fe904SRajat Jain * property to reflect the new state on completion of the commit of the 1599107fe904SRajat Jain * sw-state property. Setting the sw-state property when the hw-state is 1600107fe904SRajat Jain * locked must be interpreted by the driver as a request to change the 1601107fe904SRajat Jain * state to the set state when the hw-state becomes unlocked. E.g. if 1602107fe904SRajat Jain * "privacy-screen hw-state" is "Enabled-locked" and the sw-state 1603107fe904SRajat Jain * gets set to "Disabled" followed by the user unlocking the state by 1604107fe904SRajat Jain * changing the slider-switch position, then the driver must set the 1605107fe904SRajat Jain * state to "Disabled" upon receiving the unlock event. 1606107fe904SRajat Jain * 1607107fe904SRajat Jain * In some cases the privacy-screen's actual state might change outside of 1608107fe904SRajat Jain * control of the DRM code. E.g. there might be a firmware handled hotkey 1609107fe904SRajat Jain * which toggles the actual state, or the actual state might be changed 1610107fe904SRajat Jain * through another userspace API such as writing /proc/acpi/ibm/lcdshadow. 1611107fe904SRajat Jain * In this case the driver must update both the hw-state and the sw-state 1612107fe904SRajat Jain * to reflect the new value, overwriting any pending state requests in the 1613107fe904SRajat Jain * sw-state. Any pending sw-state requests are thus discarded. 1614107fe904SRajat Jain * 1615107fe904SRajat Jain * Note that the ability for the state to change outside of control of 1616107fe904SRajat Jain * the DRM master process means that userspace must not cache the value 1617107fe904SRajat Jain * of the sw-state. Caching the sw-state value and including it in later 1618107fe904SRajat Jain * atomic commits may lead to overriding a state change done through e.g. 1619107fe904SRajat Jain * a firmware handled hotkey. Therefor userspace must not include the 1620107fe904SRajat Jain * privacy-screen sw-state in an atomic commit unless it wants to change 1621107fe904SRajat Jain * its value. 1622409f07d3SSimon Ser * 1623409f07d3SSimon Ser * left margin, right margin, top margin, bottom margin: 1624409f07d3SSimon Ser * Add margins to the connector's viewport. This is typically used to 16253cf15dc2SSimon Ser * mitigate overscan on TVs. 1626409f07d3SSimon Ser * 1627409f07d3SSimon Ser * The value is the size in pixels of the black border which will be 1628409f07d3SSimon Ser * added. The attached CRTC's content will be scaled to fill the whole 1629409f07d3SSimon Ser * area inside the margin. 1630409f07d3SSimon Ser * 1631409f07d3SSimon Ser * The margins configuration might be sent to the sink, e.g. via HDMI AVI 1632409f07d3SSimon Ser * InfoFrames. 1633409f07d3SSimon Ser * 1634409f07d3SSimon Ser * Drivers can set up these properties by calling 1635409f07d3SSimon Ser * drm_mode_create_tv_margin_properties(). 16364ada6f22SDaniel Vetter */ 16374ada6f22SDaniel Vetter 163852217195SDaniel Vetter int drm_connector_create_standard_properties(struct drm_device *dev) 163952217195SDaniel Vetter { 164052217195SDaniel Vetter struct drm_property *prop; 164152217195SDaniel Vetter 164252217195SDaniel Vetter prop = drm_property_create(dev, DRM_MODE_PROP_BLOB | 164352217195SDaniel Vetter DRM_MODE_PROP_IMMUTABLE, 164452217195SDaniel Vetter "EDID", 0); 164552217195SDaniel Vetter if (!prop) 164652217195SDaniel Vetter return -ENOMEM; 164752217195SDaniel Vetter dev->mode_config.edid_property = prop; 164852217195SDaniel Vetter 164952217195SDaniel Vetter prop = drm_property_create_enum(dev, 0, 165052217195SDaniel Vetter "DPMS", drm_dpms_enum_list, 165152217195SDaniel Vetter ARRAY_SIZE(drm_dpms_enum_list)); 165252217195SDaniel Vetter if (!prop) 165352217195SDaniel Vetter return -ENOMEM; 165452217195SDaniel Vetter dev->mode_config.dpms_property = prop; 165552217195SDaniel Vetter 165652217195SDaniel Vetter prop = drm_property_create(dev, 165752217195SDaniel Vetter DRM_MODE_PROP_BLOB | 165852217195SDaniel Vetter DRM_MODE_PROP_IMMUTABLE, 165952217195SDaniel Vetter "PATH", 0); 166052217195SDaniel Vetter if (!prop) 166152217195SDaniel Vetter return -ENOMEM; 166252217195SDaniel Vetter dev->mode_config.path_property = prop; 166352217195SDaniel Vetter 166452217195SDaniel Vetter prop = drm_property_create(dev, 166552217195SDaniel Vetter DRM_MODE_PROP_BLOB | 166652217195SDaniel Vetter DRM_MODE_PROP_IMMUTABLE, 166752217195SDaniel Vetter "TILE", 0); 166852217195SDaniel Vetter if (!prop) 166952217195SDaniel Vetter return -ENOMEM; 167052217195SDaniel Vetter dev->mode_config.tile_property = prop; 167152217195SDaniel Vetter 167240ee6fbeSManasi Navare prop = drm_property_create_enum(dev, 0, "link-status", 167340ee6fbeSManasi Navare drm_link_status_enum_list, 167440ee6fbeSManasi Navare ARRAY_SIZE(drm_link_status_enum_list)); 167540ee6fbeSManasi Navare if (!prop) 167640ee6fbeSManasi Navare return -ENOMEM; 167740ee6fbeSManasi Navare dev->mode_config.link_status_property = prop; 167840ee6fbeSManasi Navare 167966660d4cSDave Airlie prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop"); 168066660d4cSDave Airlie if (!prop) 168166660d4cSDave Airlie return -ENOMEM; 168266660d4cSDave Airlie dev->mode_config.non_desktop_property = prop; 168366660d4cSDave Airlie 1684fbb5d035SUma Shankar prop = drm_property_create(dev, DRM_MODE_PROP_BLOB, 1685fbb5d035SUma Shankar "HDR_OUTPUT_METADATA", 0); 1686fbb5d035SUma Shankar if (!prop) 1687fbb5d035SUma Shankar return -ENOMEM; 1688fbb5d035SUma Shankar dev->mode_config.hdr_output_metadata_property = prop; 1689fbb5d035SUma Shankar 169052217195SDaniel Vetter return 0; 169152217195SDaniel Vetter } 169252217195SDaniel Vetter 169352217195SDaniel Vetter /** 169452217195SDaniel Vetter * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties 169552217195SDaniel Vetter * @dev: DRM device 169652217195SDaniel Vetter * 169752217195SDaniel Vetter * Called by a driver the first time a DVI-I connector is made. 1698f85d9e59SRandy Dunlap * 1699f85d9e59SRandy Dunlap * Returns: %0 170052217195SDaniel Vetter */ 170152217195SDaniel Vetter int drm_mode_create_dvi_i_properties(struct drm_device *dev) 170252217195SDaniel Vetter { 170352217195SDaniel Vetter struct drm_property *dvi_i_selector; 170452217195SDaniel Vetter struct drm_property *dvi_i_subconnector; 170552217195SDaniel Vetter 170652217195SDaniel Vetter if (dev->mode_config.dvi_i_select_subconnector_property) 170752217195SDaniel Vetter return 0; 170852217195SDaniel Vetter 170952217195SDaniel Vetter dvi_i_selector = 171052217195SDaniel Vetter drm_property_create_enum(dev, 0, 171152217195SDaniel Vetter "select subconnector", 171252217195SDaniel Vetter drm_dvi_i_select_enum_list, 171352217195SDaniel Vetter ARRAY_SIZE(drm_dvi_i_select_enum_list)); 171452217195SDaniel Vetter dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; 171552217195SDaniel Vetter 171652217195SDaniel Vetter dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 171752217195SDaniel Vetter "subconnector", 171852217195SDaniel Vetter drm_dvi_i_subconnector_enum_list, 171952217195SDaniel Vetter ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); 172052217195SDaniel Vetter dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; 172152217195SDaniel Vetter 172252217195SDaniel Vetter return 0; 172352217195SDaniel Vetter } 172452217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); 172552217195SDaniel Vetter 172652217195SDaniel Vetter /** 1727e5b92773SOleg Vasilev * drm_connector_attach_dp_subconnector_property - create subconnector property for DP 1728e5b92773SOleg Vasilev * @connector: drm_connector to attach property 1729e5b92773SOleg Vasilev * 1730e5b92773SOleg Vasilev * Called by a driver when DP connector is created. 1731e5b92773SOleg Vasilev */ 1732e5b92773SOleg Vasilev void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector) 1733e5b92773SOleg Vasilev { 1734e5b92773SOleg Vasilev struct drm_mode_config *mode_config = &connector->dev->mode_config; 1735e5b92773SOleg Vasilev 1736e5b92773SOleg Vasilev if (!mode_config->dp_subconnector_property) 1737e5b92773SOleg Vasilev mode_config->dp_subconnector_property = 1738e5b92773SOleg Vasilev drm_property_create_enum(connector->dev, 1739e5b92773SOleg Vasilev DRM_MODE_PROP_IMMUTABLE, 1740e5b92773SOleg Vasilev "subconnector", 1741e5b92773SOleg Vasilev drm_dp_subconnector_enum_list, 1742e5b92773SOleg Vasilev ARRAY_SIZE(drm_dp_subconnector_enum_list)); 1743e5b92773SOleg Vasilev 1744e5b92773SOleg Vasilev drm_object_attach_property(&connector->base, 1745e5b92773SOleg Vasilev mode_config->dp_subconnector_property, 1746e5b92773SOleg Vasilev DRM_MODE_SUBCONNECTOR_Unknown); 1747e5b92773SOleg Vasilev } 1748e5b92773SOleg Vasilev EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property); 1749e5b92773SOleg Vasilev 1750e5b92773SOleg Vasilev /** 175150525c33SStanislav Lisovskiy * DOC: HDMI connector properties 175250525c33SStanislav Lisovskiy * 1753ab52af4bSMaxime Ripard * Broadcast RGB (HDMI specific) 1754ab52af4bSMaxime Ripard * Indicates the Quantization Range (Full vs Limited) used. The color 1755ab52af4bSMaxime Ripard * processing pipeline will be adjusted to match the value of the 1756ab52af4bSMaxime Ripard * property, and the Infoframes will be generated and sent accordingly. 1757ab52af4bSMaxime Ripard * 1758ab52af4bSMaxime Ripard * This property is only relevant if the HDMI output format is RGB. If 1759ab52af4bSMaxime Ripard * it's one of the YCbCr variant, it will be ignored. 1760ab52af4bSMaxime Ripard * 1761ab52af4bSMaxime Ripard * The CRTC attached to the connector must be configured by user-space to 1762ab52af4bSMaxime Ripard * always produce full-range pixels. 1763ab52af4bSMaxime Ripard * 1764ab52af4bSMaxime Ripard * The value of this property can be one of the following: 1765ab52af4bSMaxime Ripard * 1766ab52af4bSMaxime Ripard * Automatic: 1767ab52af4bSMaxime Ripard * The quantization range is selected automatically based on the 1768ab52af4bSMaxime Ripard * mode according to the HDMI specifications (HDMI 1.4b - Section 1769ab52af4bSMaxime Ripard * 6.6 - Video Quantization Ranges). 1770ab52af4bSMaxime Ripard * 1771ab52af4bSMaxime Ripard * Full: 1772ab52af4bSMaxime Ripard * Full quantization range is forced. 1773ab52af4bSMaxime Ripard * 1774ab52af4bSMaxime Ripard * Limited 16:235: 1775ab52af4bSMaxime Ripard * Limited quantization range is forced. Unlike the name suggests, 1776ab52af4bSMaxime Ripard * this works for any number of bits-per-component. 1777ab52af4bSMaxime Ripard * 1778ab52af4bSMaxime Ripard * Property values other than Automatic can result in colors being off (if 1779ab52af4bSMaxime Ripard * limited is selected but the display expects full), or a black screen 1780ab52af4bSMaxime Ripard * (if full is selected but the display expects limited). 1781ab52af4bSMaxime Ripard * 1782ab52af4bSMaxime Ripard * Drivers can set up this property by calling 1783ab52af4bSMaxime Ripard * drm_connector_attach_broadcast_rgb_property(). 1784ab52af4bSMaxime Ripard * 178550525c33SStanislav Lisovskiy * content type (HDMI specific): 178650525c33SStanislav Lisovskiy * Indicates content type setting to be used in HDMI infoframes to indicate 17871e55a53aSMatt Roper * content type for the external device, so that it adjusts its display 178850525c33SStanislav Lisovskiy * settings accordingly. 178950525c33SStanislav Lisovskiy * 179050525c33SStanislav Lisovskiy * The value of this property can be one of the following: 179150525c33SStanislav Lisovskiy * 179250525c33SStanislav Lisovskiy * No Data: 179350525c33SStanislav Lisovskiy * Content type is unknown 179450525c33SStanislav Lisovskiy * Graphics: 179550525c33SStanislav Lisovskiy * Content type is graphics 179650525c33SStanislav Lisovskiy * Photo: 179750525c33SStanislav Lisovskiy * Content type is photo 179850525c33SStanislav Lisovskiy * Cinema: 179950525c33SStanislav Lisovskiy * Content type is cinema 180050525c33SStanislav Lisovskiy * Game: 180150525c33SStanislav Lisovskiy * Content type is game 180250525c33SStanislav Lisovskiy * 1803a0a33067SSimon Ser * The meaning of each content type is defined in CTA-861-G table 15. 1804a0a33067SSimon Ser * 180550525c33SStanislav Lisovskiy * Drivers can set up this property by calling 180650525c33SStanislav Lisovskiy * drm_connector_attach_content_type_property(). Decoding to 1807ba609631SDaniel Vetter * infoframe values is done through drm_hdmi_avi_infoframe_content_type(). 180850525c33SStanislav Lisovskiy */ 180950525c33SStanislav Lisovskiy 18107d63cd85SMaxime Ripard /* 18117d63cd85SMaxime Ripard * TODO: Document the properties: 18127d63cd85SMaxime Ripard * - brightness 18137d63cd85SMaxime Ripard * - contrast 18147d63cd85SMaxime Ripard * - flicker reduction 18157d63cd85SMaxime Ripard * - hue 18167d63cd85SMaxime Ripard * - mode 18177d63cd85SMaxime Ripard * - overscan 18187d63cd85SMaxime Ripard * - saturation 18197d63cd85SMaxime Ripard * - select subconnector 18207d63cd85SMaxime Ripard */ 18217d63cd85SMaxime Ripard /** 18227d63cd85SMaxime Ripard * DOC: Analog TV Connector Properties 18237d63cd85SMaxime Ripard * 18247d63cd85SMaxime Ripard * TV Mode: 18257d63cd85SMaxime Ripard * Indicates the TV Mode used on an analog TV connector. The value 18267d63cd85SMaxime Ripard * of this property can be one of the following: 18277d63cd85SMaxime Ripard * 18287d63cd85SMaxime Ripard * NTSC: 18297d63cd85SMaxime Ripard * TV Mode is CCIR System M (aka 525-lines) together with 18307d63cd85SMaxime Ripard * the NTSC Color Encoding. 18317d63cd85SMaxime Ripard * 18327d63cd85SMaxime Ripard * NTSC-443: 18337d63cd85SMaxime Ripard * 18347d63cd85SMaxime Ripard * TV Mode is CCIR System M (aka 525-lines) together with 18357d63cd85SMaxime Ripard * the NTSC Color Encoding, but with a color subcarrier 18367d63cd85SMaxime Ripard * frequency of 4.43MHz 18377d63cd85SMaxime Ripard * 18387d63cd85SMaxime Ripard * NTSC-J: 18397d63cd85SMaxime Ripard * 18407d63cd85SMaxime Ripard * TV Mode is CCIR System M (aka 525-lines) together with 18417d63cd85SMaxime Ripard * the NTSC Color Encoding, but with a black level equal to 18427d63cd85SMaxime Ripard * the blanking level. 18437d63cd85SMaxime Ripard * 18447d63cd85SMaxime Ripard * PAL: 18457d63cd85SMaxime Ripard * 18467d63cd85SMaxime Ripard * TV Mode is CCIR System B (aka 625-lines) together with 18477d63cd85SMaxime Ripard * the PAL Color Encoding. 18487d63cd85SMaxime Ripard * 18497d63cd85SMaxime Ripard * PAL-M: 18507d63cd85SMaxime Ripard * 18517d63cd85SMaxime Ripard * TV Mode is CCIR System M (aka 525-lines) together with 18527d63cd85SMaxime Ripard * the PAL Color Encoding. 18537d63cd85SMaxime Ripard * 18547d63cd85SMaxime Ripard * PAL-N: 18557d63cd85SMaxime Ripard * 18567d63cd85SMaxime Ripard * TV Mode is CCIR System N together with the PAL Color 18577d63cd85SMaxime Ripard * Encoding, a color subcarrier frequency of 3.58MHz, the 18587d63cd85SMaxime Ripard * SECAM color space, and narrower channels than other PAL 18597d63cd85SMaxime Ripard * variants. 18607d63cd85SMaxime Ripard * 18617d63cd85SMaxime Ripard * SECAM: 18627d63cd85SMaxime Ripard * 18637d63cd85SMaxime Ripard * TV Mode is CCIR System B (aka 625-lines) together with 18647d63cd85SMaxime Ripard * the SECAM Color Encoding. 18657d63cd85SMaxime Ripard * 186641474d25SNick Hollinghurst * Mono: 186741474d25SNick Hollinghurst * 186841474d25SNick Hollinghurst * Use timings appropriate to the DRM mode, including 186941474d25SNick Hollinghurst * equalizing pulses for a 525-line or 625-line mode, 187041474d25SNick Hollinghurst * with no pedestal or color encoding. 187141474d25SNick Hollinghurst * 18727d63cd85SMaxime Ripard * Drivers can set up this property by calling 18737d63cd85SMaxime Ripard * drm_mode_create_tv_properties(). 18747d63cd85SMaxime Ripard */ 18757d63cd85SMaxime Ripard 187650525c33SStanislav Lisovskiy /** 187750525c33SStanislav Lisovskiy * drm_connector_attach_content_type_property - attach content-type property 187850525c33SStanislav Lisovskiy * @connector: connector to attach content type property on. 187950525c33SStanislav Lisovskiy * 188050525c33SStanislav Lisovskiy * Called by a driver the first time a HDMI connector is made. 1881f85d9e59SRandy Dunlap * 1882f85d9e59SRandy Dunlap * Returns: %0 188350525c33SStanislav Lisovskiy */ 188450525c33SStanislav Lisovskiy int drm_connector_attach_content_type_property(struct drm_connector *connector) 188550525c33SStanislav Lisovskiy { 188650525c33SStanislav Lisovskiy if (!drm_mode_create_content_type_property(connector->dev)) 188750525c33SStanislav Lisovskiy drm_object_attach_property(&connector->base, 188850525c33SStanislav Lisovskiy connector->dev->mode_config.content_type_property, 188950525c33SStanislav Lisovskiy DRM_MODE_CONTENT_TYPE_NO_DATA); 189050525c33SStanislav Lisovskiy return 0; 189150525c33SStanislav Lisovskiy } 189250525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_connector_attach_content_type_property); 189350525c33SStanislav Lisovskiy 189450525c33SStanislav Lisovskiy /** 1895e9d2871fSMauro Carvalho Chehab * drm_connector_attach_tv_margin_properties - attach TV connector margin 1896e9d2871fSMauro Carvalho Chehab * properties 18976c4f52dcSBoris Brezillon * @connector: DRM connector 18986c4f52dcSBoris Brezillon * 18996c4f52dcSBoris Brezillon * Called by a driver when it needs to attach TV margin props to a connector. 19006c4f52dcSBoris Brezillon * Typically used on SDTV and HDMI connectors. 19016c4f52dcSBoris Brezillon */ 19026c4f52dcSBoris Brezillon void drm_connector_attach_tv_margin_properties(struct drm_connector *connector) 19036c4f52dcSBoris Brezillon { 19046c4f52dcSBoris Brezillon struct drm_device *dev = connector->dev; 19056c4f52dcSBoris Brezillon 19066c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 19076c4f52dcSBoris Brezillon dev->mode_config.tv_left_margin_property, 19086c4f52dcSBoris Brezillon 0); 19096c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 19106c4f52dcSBoris Brezillon dev->mode_config.tv_right_margin_property, 19116c4f52dcSBoris Brezillon 0); 19126c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 19136c4f52dcSBoris Brezillon dev->mode_config.tv_top_margin_property, 19146c4f52dcSBoris Brezillon 0); 19156c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 19166c4f52dcSBoris Brezillon dev->mode_config.tv_bottom_margin_property, 19176c4f52dcSBoris Brezillon 0); 19186c4f52dcSBoris Brezillon } 19196c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties); 19206c4f52dcSBoris Brezillon 19216c4f52dcSBoris Brezillon /** 19226c4f52dcSBoris Brezillon * drm_mode_create_tv_margin_properties - create TV connector margin properties 19236c4f52dcSBoris Brezillon * @dev: DRM device 19246c4f52dcSBoris Brezillon * 19256c4f52dcSBoris Brezillon * Called by a driver's HDMI connector initialization routine, this function 19266c4f52dcSBoris Brezillon * creates the TV margin properties for a given device. No need to call this 19276c4f52dcSBoris Brezillon * function for an SDTV connector, it's already called from 192880ed86d4SMaxime Ripard * drm_mode_create_tv_properties_legacy(). 1929f85d9e59SRandy Dunlap * 1930f85d9e59SRandy Dunlap * Returns: 1931f85d9e59SRandy Dunlap * 0 on success or a negative error code on failure. 19326c4f52dcSBoris Brezillon */ 19336c4f52dcSBoris Brezillon int drm_mode_create_tv_margin_properties(struct drm_device *dev) 19346c4f52dcSBoris Brezillon { 19356c4f52dcSBoris Brezillon if (dev->mode_config.tv_left_margin_property) 19366c4f52dcSBoris Brezillon return 0; 19376c4f52dcSBoris Brezillon 19386c4f52dcSBoris Brezillon dev->mode_config.tv_left_margin_property = 19396c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "left margin", 0, 100); 19406c4f52dcSBoris Brezillon if (!dev->mode_config.tv_left_margin_property) 19416c4f52dcSBoris Brezillon return -ENOMEM; 19426c4f52dcSBoris Brezillon 19436c4f52dcSBoris Brezillon dev->mode_config.tv_right_margin_property = 19446c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "right margin", 0, 100); 19456c4f52dcSBoris Brezillon if (!dev->mode_config.tv_right_margin_property) 19466c4f52dcSBoris Brezillon return -ENOMEM; 19476c4f52dcSBoris Brezillon 19486c4f52dcSBoris Brezillon dev->mode_config.tv_top_margin_property = 19496c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "top margin", 0, 100); 19506c4f52dcSBoris Brezillon if (!dev->mode_config.tv_top_margin_property) 19516c4f52dcSBoris Brezillon return -ENOMEM; 19526c4f52dcSBoris Brezillon 19536c4f52dcSBoris Brezillon dev->mode_config.tv_bottom_margin_property = 19546c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "bottom margin", 0, 100); 19556c4f52dcSBoris Brezillon if (!dev->mode_config.tv_bottom_margin_property) 19566c4f52dcSBoris Brezillon return -ENOMEM; 19576c4f52dcSBoris Brezillon 19586c4f52dcSBoris Brezillon return 0; 19596c4f52dcSBoris Brezillon } 19606c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_mode_create_tv_margin_properties); 19616c4f52dcSBoris Brezillon 19626c4f52dcSBoris Brezillon /** 196380ed86d4SMaxime Ripard * drm_mode_create_tv_properties_legacy - create TV specific connector properties 196452217195SDaniel Vetter * @dev: DRM device 196552217195SDaniel Vetter * @num_modes: number of different TV formats (modes) supported 196652217195SDaniel Vetter * @modes: array of pointers to strings containing name of each format 196752217195SDaniel Vetter * 196852217195SDaniel Vetter * Called by a driver's TV initialization routine, this function creates 196952217195SDaniel Vetter * the TV specific connector properties for a given device. Caller is 197052217195SDaniel Vetter * responsible for allocating a list of format names and passing them to 197152217195SDaniel Vetter * this routine. 1972f85d9e59SRandy Dunlap * 19737d63cd85SMaxime Ripard * NOTE: This functions registers the deprecated "mode" connector 19747d63cd85SMaxime Ripard * property to select the analog TV mode (ie, NTSC, PAL, etc.). New 19757d63cd85SMaxime Ripard * drivers must use drm_mode_create_tv_properties() instead. 19767d63cd85SMaxime Ripard * 1977f85d9e59SRandy Dunlap * Returns: 1978f85d9e59SRandy Dunlap * 0 on success or a negative error code on failure. 197952217195SDaniel Vetter */ 198080ed86d4SMaxime Ripard int drm_mode_create_tv_properties_legacy(struct drm_device *dev, 198152217195SDaniel Vetter unsigned int num_modes, 198252217195SDaniel Vetter const char * const modes[]) 198352217195SDaniel Vetter { 198452217195SDaniel Vetter struct drm_property *tv_selector; 198552217195SDaniel Vetter struct drm_property *tv_subconnector; 198652217195SDaniel Vetter unsigned int i; 198752217195SDaniel Vetter 198852217195SDaniel Vetter if (dev->mode_config.tv_select_subconnector_property) 198952217195SDaniel Vetter return 0; 199052217195SDaniel Vetter 199152217195SDaniel Vetter /* 199252217195SDaniel Vetter * Basic connector properties 199352217195SDaniel Vetter */ 199452217195SDaniel Vetter tv_selector = drm_property_create_enum(dev, 0, 199552217195SDaniel Vetter "select subconnector", 199652217195SDaniel Vetter drm_tv_select_enum_list, 199752217195SDaniel Vetter ARRAY_SIZE(drm_tv_select_enum_list)); 199852217195SDaniel Vetter if (!tv_selector) 199952217195SDaniel Vetter goto nomem; 200052217195SDaniel Vetter 200152217195SDaniel Vetter dev->mode_config.tv_select_subconnector_property = tv_selector; 200252217195SDaniel Vetter 200352217195SDaniel Vetter tv_subconnector = 200452217195SDaniel Vetter drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 200552217195SDaniel Vetter "subconnector", 200652217195SDaniel Vetter drm_tv_subconnector_enum_list, 200752217195SDaniel Vetter ARRAY_SIZE(drm_tv_subconnector_enum_list)); 200852217195SDaniel Vetter if (!tv_subconnector) 200952217195SDaniel Vetter goto nomem; 201052217195SDaniel Vetter dev->mode_config.tv_subconnector_property = tv_subconnector; 201152217195SDaniel Vetter 201252217195SDaniel Vetter /* 201352217195SDaniel Vetter * Other, TV specific properties: margins & TV modes. 201452217195SDaniel Vetter */ 20156c4f52dcSBoris Brezillon if (drm_mode_create_tv_margin_properties(dev)) 201652217195SDaniel Vetter goto nomem; 201752217195SDaniel Vetter 2018aab5aaa7SMaxime Ripard if (num_modes) { 20191fd4a5a3SMaxime Ripard dev->mode_config.legacy_tv_mode_property = 202052217195SDaniel Vetter drm_property_create(dev, DRM_MODE_PROP_ENUM, 202152217195SDaniel Vetter "mode", num_modes); 20221fd4a5a3SMaxime Ripard if (!dev->mode_config.legacy_tv_mode_property) 202352217195SDaniel Vetter goto nomem; 202452217195SDaniel Vetter 202552217195SDaniel Vetter for (i = 0; i < num_modes; i++) 20261fd4a5a3SMaxime Ripard drm_property_add_enum(dev->mode_config.legacy_tv_mode_property, 202752217195SDaniel Vetter i, modes[i]); 2028aab5aaa7SMaxime Ripard } 202952217195SDaniel Vetter 203052217195SDaniel Vetter dev->mode_config.tv_brightness_property = 203152217195SDaniel Vetter drm_property_create_range(dev, 0, "brightness", 0, 100); 203252217195SDaniel Vetter if (!dev->mode_config.tv_brightness_property) 203352217195SDaniel Vetter goto nomem; 203452217195SDaniel Vetter 203552217195SDaniel Vetter dev->mode_config.tv_contrast_property = 203652217195SDaniel Vetter drm_property_create_range(dev, 0, "contrast", 0, 100); 203752217195SDaniel Vetter if (!dev->mode_config.tv_contrast_property) 203852217195SDaniel Vetter goto nomem; 203952217195SDaniel Vetter 204052217195SDaniel Vetter dev->mode_config.tv_flicker_reduction_property = 204152217195SDaniel Vetter drm_property_create_range(dev, 0, "flicker reduction", 0, 100); 204252217195SDaniel Vetter if (!dev->mode_config.tv_flicker_reduction_property) 204352217195SDaniel Vetter goto nomem; 204452217195SDaniel Vetter 204552217195SDaniel Vetter dev->mode_config.tv_overscan_property = 204652217195SDaniel Vetter drm_property_create_range(dev, 0, "overscan", 0, 100); 204752217195SDaniel Vetter if (!dev->mode_config.tv_overscan_property) 204852217195SDaniel Vetter goto nomem; 204952217195SDaniel Vetter 205052217195SDaniel Vetter dev->mode_config.tv_saturation_property = 205152217195SDaniel Vetter drm_property_create_range(dev, 0, "saturation", 0, 100); 205252217195SDaniel Vetter if (!dev->mode_config.tv_saturation_property) 205352217195SDaniel Vetter goto nomem; 205452217195SDaniel Vetter 205552217195SDaniel Vetter dev->mode_config.tv_hue_property = 205652217195SDaniel Vetter drm_property_create_range(dev, 0, "hue", 0, 100); 205752217195SDaniel Vetter if (!dev->mode_config.tv_hue_property) 205852217195SDaniel Vetter goto nomem; 205952217195SDaniel Vetter 206052217195SDaniel Vetter return 0; 206152217195SDaniel Vetter nomem: 206252217195SDaniel Vetter return -ENOMEM; 206352217195SDaniel Vetter } 206480ed86d4SMaxime Ripard EXPORT_SYMBOL(drm_mode_create_tv_properties_legacy); 206552217195SDaniel Vetter 206652217195SDaniel Vetter /** 20677d63cd85SMaxime Ripard * drm_mode_create_tv_properties - create TV specific connector properties 20687d63cd85SMaxime Ripard * @dev: DRM device 20697d63cd85SMaxime Ripard * @supported_tv_modes: Bitmask of TV modes supported (See DRM_MODE_TV_MODE_*) 207004ee2767SRandy Dunlap * 20717d63cd85SMaxime Ripard * Called by a driver's TV initialization routine, this function creates 20727d63cd85SMaxime Ripard * the TV specific connector properties for a given device. 20737d63cd85SMaxime Ripard * 20747d63cd85SMaxime Ripard * Returns: 20757d63cd85SMaxime Ripard * 0 on success or a negative error code on failure. 20767d63cd85SMaxime Ripard */ 20777d63cd85SMaxime Ripard int drm_mode_create_tv_properties(struct drm_device *dev, 20787d63cd85SMaxime Ripard unsigned int supported_tv_modes) 20797d63cd85SMaxime Ripard { 20807d63cd85SMaxime Ripard struct drm_prop_enum_list tv_mode_list[DRM_MODE_TV_MODE_MAX]; 20817d63cd85SMaxime Ripard struct drm_property *tv_mode; 20827d63cd85SMaxime Ripard unsigned int i, len = 0; 20837d63cd85SMaxime Ripard 20847d63cd85SMaxime Ripard if (dev->mode_config.tv_mode_property) 20857d63cd85SMaxime Ripard return 0; 20867d63cd85SMaxime Ripard 20877d63cd85SMaxime Ripard for (i = 0; i < DRM_MODE_TV_MODE_MAX; i++) { 20887d63cd85SMaxime Ripard if (!(supported_tv_modes & BIT(i))) 20897d63cd85SMaxime Ripard continue; 20907d63cd85SMaxime Ripard 20917d63cd85SMaxime Ripard tv_mode_list[len].type = i; 20927d63cd85SMaxime Ripard tv_mode_list[len].name = drm_get_tv_mode_name(i); 20937d63cd85SMaxime Ripard len++; 20947d63cd85SMaxime Ripard } 20957d63cd85SMaxime Ripard 20967d63cd85SMaxime Ripard tv_mode = drm_property_create_enum(dev, 0, "TV mode", 20977d63cd85SMaxime Ripard tv_mode_list, len); 20987d63cd85SMaxime Ripard if (!tv_mode) 20997d63cd85SMaxime Ripard return -ENOMEM; 21007d63cd85SMaxime Ripard 21017d63cd85SMaxime Ripard dev->mode_config.tv_mode_property = tv_mode; 21027d63cd85SMaxime Ripard 21037d63cd85SMaxime Ripard return drm_mode_create_tv_properties_legacy(dev, 0, NULL); 21047d63cd85SMaxime Ripard } 21057d63cd85SMaxime Ripard EXPORT_SYMBOL(drm_mode_create_tv_properties); 21067d63cd85SMaxime Ripard 21077d63cd85SMaxime Ripard /** 210852217195SDaniel Vetter * drm_mode_create_scaling_mode_property - create scaling mode property 210952217195SDaniel Vetter * @dev: DRM device 211052217195SDaniel Vetter * 211152217195SDaniel Vetter * Called by a driver the first time it's needed, must be attached to desired 211252217195SDaniel Vetter * connectors. 21138f6e1e22SMaarten Lankhorst * 21148f6e1e22SMaarten Lankhorst * Atomic drivers should use drm_connector_attach_scaling_mode_property() 21159c2fce13SVille Syrjälä * instead to correctly assign &drm_connector_state.scaling_mode 21168f6e1e22SMaarten Lankhorst * in the atomic state. 2117f85d9e59SRandy Dunlap * 2118f85d9e59SRandy Dunlap * Returns: %0 211952217195SDaniel Vetter */ 212052217195SDaniel Vetter int drm_mode_create_scaling_mode_property(struct drm_device *dev) 212152217195SDaniel Vetter { 212252217195SDaniel Vetter struct drm_property *scaling_mode; 212352217195SDaniel Vetter 212452217195SDaniel Vetter if (dev->mode_config.scaling_mode_property) 212552217195SDaniel Vetter return 0; 212652217195SDaniel Vetter 212752217195SDaniel Vetter scaling_mode = 212852217195SDaniel Vetter drm_property_create_enum(dev, 0, "scaling mode", 212952217195SDaniel Vetter drm_scaling_mode_enum_list, 213052217195SDaniel Vetter ARRAY_SIZE(drm_scaling_mode_enum_list)); 213152217195SDaniel Vetter 213252217195SDaniel Vetter dev->mode_config.scaling_mode_property = scaling_mode; 213352217195SDaniel Vetter 213452217195SDaniel Vetter return 0; 213552217195SDaniel Vetter } 213652217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); 213752217195SDaniel Vetter 213852217195SDaniel Vetter /** 2139ab7a664fSNicholas Kazlauskas * DOC: Variable refresh properties 2140ab7a664fSNicholas Kazlauskas * 2141ab7a664fSNicholas Kazlauskas * Variable refresh rate capable displays can dynamically adjust their 2142ab7a664fSNicholas Kazlauskas * refresh rate by extending the duration of their vertical front porch 2143ab7a664fSNicholas Kazlauskas * until page flip or timeout occurs. This can reduce or remove stuttering 2144ab7a664fSNicholas Kazlauskas * and latency in scenarios where the page flip does not align with the 2145ab7a664fSNicholas Kazlauskas * vblank interval. 2146ab7a664fSNicholas Kazlauskas * 2147ab7a664fSNicholas Kazlauskas * An example scenario would be an application flipping at a constant rate 2148ab7a664fSNicholas Kazlauskas * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank 2149ab7a664fSNicholas Kazlauskas * interval and the same contents will be displayed twice. This can be 2150ab7a664fSNicholas Kazlauskas * observed as stuttering for content with motion. 2151ab7a664fSNicholas Kazlauskas * 2152ab7a664fSNicholas Kazlauskas * If variable refresh rate was active on a display that supported a 2153ab7a664fSNicholas Kazlauskas * variable refresh range from 35Hz to 60Hz no stuttering would be observable 2154ab7a664fSNicholas Kazlauskas * for the example scenario. The minimum supported variable refresh rate of 2155ab7a664fSNicholas Kazlauskas * 35Hz is below the page flip frequency and the vertical front porch can 2156ab7a664fSNicholas Kazlauskas * be extended until the page flip occurs. The vblank interval will be 2157ab7a664fSNicholas Kazlauskas * directly aligned to the page flip rate. 2158ab7a664fSNicholas Kazlauskas * 2159ab7a664fSNicholas Kazlauskas * Not all userspace content is suitable for use with variable refresh rate. 2160ab7a664fSNicholas Kazlauskas * Large and frequent changes in vertical front porch duration may worsen 2161ab7a664fSNicholas Kazlauskas * perceived stuttering for input sensitive applications. 2162ab7a664fSNicholas Kazlauskas * 2163ab7a664fSNicholas Kazlauskas * Panel brightness will also vary with vertical front porch duration. Some 2164ab7a664fSNicholas Kazlauskas * panels may have noticeable differences in brightness between the minimum 2165ab7a664fSNicholas Kazlauskas * vertical front porch duration and the maximum vertical front porch duration. 2166ab7a664fSNicholas Kazlauskas * Large and frequent changes in vertical front porch duration may produce 2167ab7a664fSNicholas Kazlauskas * observable flickering for such panels. 2168ab7a664fSNicholas Kazlauskas * 2169ab7a664fSNicholas Kazlauskas * Userspace control for variable refresh rate is supported via properties 2170ab7a664fSNicholas Kazlauskas * on the &drm_connector and &drm_crtc objects. 2171ab7a664fSNicholas Kazlauskas * 2172ab7a664fSNicholas Kazlauskas * "vrr_capable": 2173ab7a664fSNicholas Kazlauskas * Optional &drm_connector boolean property that drivers should attach 2174ab7a664fSNicholas Kazlauskas * with drm_connector_attach_vrr_capable_property() on connectors that 2175ab7a664fSNicholas Kazlauskas * could support variable refresh rates. Drivers should update the 2176ab7a664fSNicholas Kazlauskas * property value by calling drm_connector_set_vrr_capable_property(). 2177ab7a664fSNicholas Kazlauskas * 2178ab7a664fSNicholas Kazlauskas * Absence of the property should indicate absence of support. 2179ab7a664fSNicholas Kazlauskas * 218077086014SDaniel Vetter * "VRR_ENABLED": 2181ab7a664fSNicholas Kazlauskas * Default &drm_crtc boolean property that notifies the driver that the 2182ab7a664fSNicholas Kazlauskas * content on the CRTC is suitable for variable refresh rate presentation. 2183ab7a664fSNicholas Kazlauskas * The driver will take this property as a hint to enable variable 2184ab7a664fSNicholas Kazlauskas * refresh rate support if the receiver supports it, ie. if the 2185ab7a664fSNicholas Kazlauskas * "vrr_capable" property is true on the &drm_connector object. The 2186ab7a664fSNicholas Kazlauskas * vertical front porch duration will be extended until page-flip or 2187ab7a664fSNicholas Kazlauskas * timeout when enabled. 2188ab7a664fSNicholas Kazlauskas * 2189ab7a664fSNicholas Kazlauskas * The minimum vertical front porch duration is defined as the vertical 2190ab7a664fSNicholas Kazlauskas * front porch duration for the current mode. 2191ab7a664fSNicholas Kazlauskas * 2192ab7a664fSNicholas Kazlauskas * The maximum vertical front porch duration is greater than or equal to 2193ab7a664fSNicholas Kazlauskas * the minimum vertical front porch duration. The duration is derived 2194ab7a664fSNicholas Kazlauskas * from the minimum supported variable refresh rate for the connector. 2195ab7a664fSNicholas Kazlauskas * 2196ab7a664fSNicholas Kazlauskas * The driver may place further restrictions within these minimum 2197ab7a664fSNicholas Kazlauskas * and maximum bounds. 2198ab7a664fSNicholas Kazlauskas */ 2199ab7a664fSNicholas Kazlauskas 2200ab7a664fSNicholas Kazlauskas /** 2201ba1b0f6cSNicholas Kazlauskas * drm_connector_attach_vrr_capable_property - creates the 2202ba1b0f6cSNicholas Kazlauskas * vrr_capable property 2203ba1b0f6cSNicholas Kazlauskas * @connector: connector to create the vrr_capable property on. 2204ba1b0f6cSNicholas Kazlauskas * 2205ba1b0f6cSNicholas Kazlauskas * This is used by atomic drivers to add support for querying 2206ba1b0f6cSNicholas Kazlauskas * variable refresh rate capability for a connector. 2207ba1b0f6cSNicholas Kazlauskas * 2208ba1b0f6cSNicholas Kazlauskas * Returns: 220984e543bcSAntonio Borneo * Zero on success, negative errno on failure. 2210ba1b0f6cSNicholas Kazlauskas */ 2211ba1b0f6cSNicholas Kazlauskas int drm_connector_attach_vrr_capable_property( 2212ba1b0f6cSNicholas Kazlauskas struct drm_connector *connector) 2213ba1b0f6cSNicholas Kazlauskas { 2214ba1b0f6cSNicholas Kazlauskas struct drm_device *dev = connector->dev; 2215ba1b0f6cSNicholas Kazlauskas struct drm_property *prop; 2216ba1b0f6cSNicholas Kazlauskas 2217ba1b0f6cSNicholas Kazlauskas if (!connector->vrr_capable_property) { 2218ba1b0f6cSNicholas Kazlauskas prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, 2219ba1b0f6cSNicholas Kazlauskas "vrr_capable"); 2220ba1b0f6cSNicholas Kazlauskas if (!prop) 2221ba1b0f6cSNicholas Kazlauskas return -ENOMEM; 2222ba1b0f6cSNicholas Kazlauskas 2223ba1b0f6cSNicholas Kazlauskas connector->vrr_capable_property = prop; 2224ba1b0f6cSNicholas Kazlauskas drm_object_attach_property(&connector->base, prop, 0); 2225ba1b0f6cSNicholas Kazlauskas } 2226ba1b0f6cSNicholas Kazlauskas 2227ba1b0f6cSNicholas Kazlauskas return 0; 2228ba1b0f6cSNicholas Kazlauskas } 2229ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property); 2230ba1b0f6cSNicholas Kazlauskas 2231ba1b0f6cSNicholas Kazlauskas /** 22328f6e1e22SMaarten Lankhorst * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property 22338f6e1e22SMaarten Lankhorst * @connector: connector to attach scaling mode property on. 22348f6e1e22SMaarten Lankhorst * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*). 22358f6e1e22SMaarten Lankhorst * 22368f6e1e22SMaarten Lankhorst * This is used to add support for scaling mode to atomic drivers. 22379c2fce13SVille Syrjälä * The scaling mode will be set to &drm_connector_state.scaling_mode 22388f6e1e22SMaarten Lankhorst * and can be used from &drm_connector_helper_funcs->atomic_check for validation. 22398f6e1e22SMaarten Lankhorst * 22408f6e1e22SMaarten Lankhorst * This is the atomic version of drm_mode_create_scaling_mode_property(). 22418f6e1e22SMaarten Lankhorst * 22428f6e1e22SMaarten Lankhorst * Returns: 22438f6e1e22SMaarten Lankhorst * Zero on success, negative errno on failure. 22448f6e1e22SMaarten Lankhorst */ 22458f6e1e22SMaarten Lankhorst int drm_connector_attach_scaling_mode_property(struct drm_connector *connector, 22468f6e1e22SMaarten Lankhorst u32 scaling_mode_mask) 22478f6e1e22SMaarten Lankhorst { 22488f6e1e22SMaarten Lankhorst struct drm_device *dev = connector->dev; 22498f6e1e22SMaarten Lankhorst struct drm_property *scaling_mode_property; 225030e9db6dSVille Syrjälä int i; 22518f6e1e22SMaarten Lankhorst const unsigned valid_scaling_mode_mask = 22528f6e1e22SMaarten Lankhorst (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1; 22538f6e1e22SMaarten Lankhorst 22548f6e1e22SMaarten Lankhorst if (WARN_ON(hweight32(scaling_mode_mask) < 2 || 22558f6e1e22SMaarten Lankhorst scaling_mode_mask & ~valid_scaling_mode_mask)) 22568f6e1e22SMaarten Lankhorst return -EINVAL; 22578f6e1e22SMaarten Lankhorst 22588f6e1e22SMaarten Lankhorst scaling_mode_property = 22598f6e1e22SMaarten Lankhorst drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode", 22608f6e1e22SMaarten Lankhorst hweight32(scaling_mode_mask)); 22618f6e1e22SMaarten Lankhorst 22628f6e1e22SMaarten Lankhorst if (!scaling_mode_property) 22638f6e1e22SMaarten Lankhorst return -ENOMEM; 22648f6e1e22SMaarten Lankhorst 22658f6e1e22SMaarten Lankhorst for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) { 22668f6e1e22SMaarten Lankhorst int ret; 22678f6e1e22SMaarten Lankhorst 22688f6e1e22SMaarten Lankhorst if (!(BIT(i) & scaling_mode_mask)) 22698f6e1e22SMaarten Lankhorst continue; 22708f6e1e22SMaarten Lankhorst 227130e9db6dSVille Syrjälä ret = drm_property_add_enum(scaling_mode_property, 22728f6e1e22SMaarten Lankhorst drm_scaling_mode_enum_list[i].type, 22738f6e1e22SMaarten Lankhorst drm_scaling_mode_enum_list[i].name); 22748f6e1e22SMaarten Lankhorst 22758f6e1e22SMaarten Lankhorst if (ret) { 22768f6e1e22SMaarten Lankhorst drm_property_destroy(dev, scaling_mode_property); 22778f6e1e22SMaarten Lankhorst 22788f6e1e22SMaarten Lankhorst return ret; 22798f6e1e22SMaarten Lankhorst } 22808f6e1e22SMaarten Lankhorst } 22818f6e1e22SMaarten Lankhorst 22828f6e1e22SMaarten Lankhorst drm_object_attach_property(&connector->base, 22838f6e1e22SMaarten Lankhorst scaling_mode_property, 0); 22848f6e1e22SMaarten Lankhorst 22858f6e1e22SMaarten Lankhorst connector->scaling_mode_property = scaling_mode_property; 22868f6e1e22SMaarten Lankhorst 22878f6e1e22SMaarten Lankhorst return 0; 22888f6e1e22SMaarten Lankhorst } 22898f6e1e22SMaarten Lankhorst EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property); 22908f6e1e22SMaarten Lankhorst 22918f6e1e22SMaarten Lankhorst /** 229252217195SDaniel Vetter * drm_mode_create_aspect_ratio_property - create aspect ratio property 229352217195SDaniel Vetter * @dev: DRM device 229452217195SDaniel Vetter * 229552217195SDaniel Vetter * Called by a driver the first time it's needed, must be attached to desired 229652217195SDaniel Vetter * connectors. 229752217195SDaniel Vetter * 229852217195SDaniel Vetter * Returns: 229952217195SDaniel Vetter * Zero on success, negative errno on failure. 230052217195SDaniel Vetter */ 230152217195SDaniel Vetter int drm_mode_create_aspect_ratio_property(struct drm_device *dev) 230252217195SDaniel Vetter { 230352217195SDaniel Vetter if (dev->mode_config.aspect_ratio_property) 230452217195SDaniel Vetter return 0; 230552217195SDaniel Vetter 230652217195SDaniel Vetter dev->mode_config.aspect_ratio_property = 230752217195SDaniel Vetter drm_property_create_enum(dev, 0, "aspect ratio", 230852217195SDaniel Vetter drm_aspect_ratio_enum_list, 230952217195SDaniel Vetter ARRAY_SIZE(drm_aspect_ratio_enum_list)); 231052217195SDaniel Vetter 231152217195SDaniel Vetter if (dev->mode_config.aspect_ratio_property == NULL) 231252217195SDaniel Vetter return -ENOMEM; 231352217195SDaniel Vetter 231452217195SDaniel Vetter return 0; 231552217195SDaniel Vetter } 231652217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property); 231752217195SDaniel Vetter 231852217195SDaniel Vetter /** 2319d2c6a405SUma Shankar * DOC: standard connector properties 2320d2c6a405SUma Shankar * 2321d2c6a405SUma Shankar * Colorspace: 2322f592e016SSebastian Wick * This property is used to inform the driver about the color encoding 2323f592e016SSebastian Wick * user space configured the pixel operation properties to produce. 2324f592e016SSebastian Wick * The variants set the colorimetry, transfer characteristics, and which 2325f592e016SSebastian Wick * YCbCr conversion should be used when necessary. 2326f592e016SSebastian Wick * The transfer characteristics from HDR_OUTPUT_METADATA takes precedence 2327f592e016SSebastian Wick * over this property. 2328f592e016SSebastian Wick * User space always configures the pixel operation properties to produce 2329f592e016SSebastian Wick * full quantization range data (see the Broadcast RGB property). 2330d2c6a405SUma Shankar * 2331f592e016SSebastian Wick * Drivers inform the sink about what colorimetry, transfer 2332f592e016SSebastian Wick * characteristics, YCbCr conversion, and quantization range to expect 2333f592e016SSebastian Wick * (this can depend on the output mode, output format and other 2334f592e016SSebastian Wick * properties). Drivers also convert the user space provided data to what 2335f592e016SSebastian Wick * the sink expects. 2336d2c6a405SUma Shankar * 2337f592e016SSebastian Wick * User space has to check if the sink supports all of the possible 2338f592e016SSebastian Wick * colorimetries that the driver is allowed to pick by parsing the EDID. 2339f592e016SSebastian Wick * 2340f592e016SSebastian Wick * For historical reasons this property exposes a number of variants which 2341f592e016SSebastian Wick * result in undefined behavior. 2342f592e016SSebastian Wick * 2343f592e016SSebastian Wick * Default: 2344f592e016SSebastian Wick * The behavior is driver-specific. 2345f592e016SSebastian Wick * BT2020_RGB: 2346f592e016SSebastian Wick * BT2020_YCC: 2347f592e016SSebastian Wick * User space configures the pixel operation properties to produce 2348f592e016SSebastian Wick * RGB content with Rec. ITU-R BT.2020 colorimetry, Rec. 2349f592e016SSebastian Wick * ITU-R BT.2020 (Table 4, RGB) transfer characteristics and full 2350f592e016SSebastian Wick * quantization range. 2351f592e016SSebastian Wick * User space can use the HDR_OUTPUT_METADATA property to set the 2352f592e016SSebastian Wick * transfer characteristics to PQ (Rec. ITU-R BT.2100 Table 4) or 2353f592e016SSebastian Wick * HLG (Rec. ITU-R BT.2100 Table 5) in which case, user space 2354f592e016SSebastian Wick * configures pixel operation properties to produce content with 2355f592e016SSebastian Wick * the respective transfer characteristics. 2356f592e016SSebastian Wick * User space has to make sure the sink supports Rec. 2357f592e016SSebastian Wick * ITU-R BT.2020 R'G'B' and Rec. ITU-R BT.2020 Y'C'BC'R 2358f592e016SSebastian Wick * colorimetry. 2359f592e016SSebastian Wick * Drivers can configure the sink to use an RGB format, tell the 2360f592e016SSebastian Wick * sink to expect Rec. ITU-R BT.2020 R'G'B' colorimetry and convert 2361f592e016SSebastian Wick * to the appropriate quantization range. 2362f592e016SSebastian Wick * Drivers can configure the sink to use a YCbCr format, tell the 2363f592e016SSebastian Wick * sink to expect Rec. ITU-R BT.2020 Y'C'BC'R colorimetry, convert 2364f592e016SSebastian Wick * to YCbCr using the Rec. ITU-R BT.2020 non-constant luminance 2365f592e016SSebastian Wick * conversion matrix and convert to the appropriate quantization 2366f592e016SSebastian Wick * range. 2367f592e016SSebastian Wick * The variants BT2020_RGB and BT2020_YCC are equivalent and the 2368f592e016SSebastian Wick * driver chooses between RGB and YCbCr on its own. 2369f592e016SSebastian Wick * SMPTE_170M_YCC: 2370f592e016SSebastian Wick * BT709_YCC: 2371f592e016SSebastian Wick * XVYCC_601: 2372f592e016SSebastian Wick * XVYCC_709: 2373f592e016SSebastian Wick * SYCC_601: 2374f592e016SSebastian Wick * opYCC_601: 2375f592e016SSebastian Wick * opRGB: 2376f592e016SSebastian Wick * BT2020_CYCC: 2377f592e016SSebastian Wick * DCI-P3_RGB_D65: 2378f592e016SSebastian Wick * DCI-P3_RGB_Theater: 2379f592e016SSebastian Wick * RGB_WIDE_FIXED: 2380f592e016SSebastian Wick * RGB_WIDE_FLOAT: 2381f592e016SSebastian Wick * BT601_YCC: 2382f592e016SSebastian Wick * The behavior is undefined. 2383d2c6a405SUma Shankar * 23848806cd3aSGwan-gyeong Mun * Because between HDMI and DP have different colorspaces, 238545cf0e91SGwan-gyeong Mun * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and 238645cf0e91SGwan-gyeong Mun * drm_mode_create_dp_colorspace_property() is used for DP connector. 2387d2c6a405SUma Shankar */ 23888806cd3aSGwan-gyeong Mun 23896120611aSHarry Wentland static int drm_mode_create_colorspace_property(struct drm_connector *connector, 2390c627087cSHarry Wentland u32 supported_colorspaces) 23916120611aSHarry Wentland { 23926120611aSHarry Wentland struct drm_device *dev = connector->dev; 2393c627087cSHarry Wentland u32 colorspaces = supported_colorspaces | BIT(DRM_MODE_COLORIMETRY_DEFAULT); 2394c627087cSHarry Wentland struct drm_prop_enum_list enum_list[DRM_MODE_COLORIMETRY_COUNT]; 2395c627087cSHarry Wentland int i, len; 23966120611aSHarry Wentland 23976120611aSHarry Wentland if (connector->colorspace_property) 23986120611aSHarry Wentland return 0; 23996120611aSHarry Wentland 2400c627087cSHarry Wentland if (!supported_colorspaces) { 2401c627087cSHarry Wentland drm_err(dev, "No supported colorspaces provded on [CONNECTOR:%d:%s]\n", 2402c627087cSHarry Wentland connector->base.id, connector->name); 2403c627087cSHarry Wentland return -EINVAL; 2404c627087cSHarry Wentland } 2405c627087cSHarry Wentland 2406c627087cSHarry Wentland if ((supported_colorspaces & -BIT(DRM_MODE_COLORIMETRY_COUNT)) != 0) { 2407c627087cSHarry Wentland drm_err(dev, "Unknown colorspace provded on [CONNECTOR:%d:%s]\n", 2408c627087cSHarry Wentland connector->base.id, connector->name); 2409c627087cSHarry Wentland return -EINVAL; 2410c627087cSHarry Wentland } 2411c627087cSHarry Wentland 2412c627087cSHarry Wentland len = 0; 2413c627087cSHarry Wentland for (i = 0; i < DRM_MODE_COLORIMETRY_COUNT; i++) { 2414c627087cSHarry Wentland if ((colorspaces & BIT(i)) == 0) 2415c627087cSHarry Wentland continue; 2416c627087cSHarry Wentland 2417c627087cSHarry Wentland enum_list[len].type = i; 2418c627087cSHarry Wentland enum_list[len].name = colorspace_names[i]; 2419c627087cSHarry Wentland len++; 2420c627087cSHarry Wentland } 24216120611aSHarry Wentland 24226120611aSHarry Wentland connector->colorspace_property = 24236120611aSHarry Wentland drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace", 2424c627087cSHarry Wentland enum_list, 2425c627087cSHarry Wentland len); 24266120611aSHarry Wentland 24276120611aSHarry Wentland if (!connector->colorspace_property) 24286120611aSHarry Wentland return -ENOMEM; 24296120611aSHarry Wentland 24306120611aSHarry Wentland return 0; 24316120611aSHarry Wentland } 2432c627087cSHarry Wentland 24338806cd3aSGwan-gyeong Mun /** 24348806cd3aSGwan-gyeong Mun * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property 24358806cd3aSGwan-gyeong Mun * @connector: connector to create the Colorspace property on. 24360c3b063eSLee Jones * @supported_colorspaces: bitmap of supported color spaces 24378806cd3aSGwan-gyeong Mun * 24388806cd3aSGwan-gyeong Mun * Called by a driver the first time it's needed, must be attached to desired 24398806cd3aSGwan-gyeong Mun * HDMI connectors. 24408806cd3aSGwan-gyeong Mun * 24418806cd3aSGwan-gyeong Mun * Returns: 244284e543bcSAntonio Borneo * Zero on success, negative errno on failure. 24438806cd3aSGwan-gyeong Mun */ 2444c265f340SHarry Wentland int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector, 2445c265f340SHarry Wentland u32 supported_colorspaces) 2446d2c6a405SUma Shankar { 2447c265f340SHarry Wentland u32 colorspaces; 2448c265f340SHarry Wentland 2449c265f340SHarry Wentland if (supported_colorspaces) 2450c265f340SHarry Wentland colorspaces = supported_colorspaces & hdmi_colorspaces; 2451c265f340SHarry Wentland else 2452c265f340SHarry Wentland colorspaces = hdmi_colorspaces; 2453c265f340SHarry Wentland 2454c265f340SHarry Wentland return drm_mode_create_colorspace_property(connector, colorspaces); 2455d2c6a405SUma Shankar } 24568806cd3aSGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property); 2457d2c6a405SUma Shankar 2458d2c6a405SUma Shankar /** 245945cf0e91SGwan-gyeong Mun * drm_mode_create_dp_colorspace_property - create dp colorspace property 246045cf0e91SGwan-gyeong Mun * @connector: connector to create the Colorspace property on. 24610c3b063eSLee Jones * @supported_colorspaces: bitmap of supported color spaces 246245cf0e91SGwan-gyeong Mun * 246345cf0e91SGwan-gyeong Mun * Called by a driver the first time it's needed, must be attached to desired 246445cf0e91SGwan-gyeong Mun * DP connectors. 246545cf0e91SGwan-gyeong Mun * 246645cf0e91SGwan-gyeong Mun * Returns: 246784e543bcSAntonio Borneo * Zero on success, negative errno on failure. 246845cf0e91SGwan-gyeong Mun */ 2469c265f340SHarry Wentland int drm_mode_create_dp_colorspace_property(struct drm_connector *connector, 2470c265f340SHarry Wentland u32 supported_colorspaces) 247145cf0e91SGwan-gyeong Mun { 2472c265f340SHarry Wentland u32 colorspaces; 2473c265f340SHarry Wentland 2474c265f340SHarry Wentland if (supported_colorspaces) 2475c265f340SHarry Wentland colorspaces = supported_colorspaces & dp_colorspaces; 2476c265f340SHarry Wentland else 2477c265f340SHarry Wentland colorspaces = dp_colorspaces; 2478c265f340SHarry Wentland 2479c265f340SHarry Wentland return drm_mode_create_colorspace_property(connector, colorspaces); 248045cf0e91SGwan-gyeong Mun } 248145cf0e91SGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property); 248252217195SDaniel Vetter 248397e14fbeSDaniel Vetter /** 248452217195SDaniel Vetter * drm_mode_create_content_type_property - create content type property 248552217195SDaniel Vetter * @dev: DRM device 248697e14fbeSDaniel Vetter * 248752217195SDaniel Vetter * Called by a driver the first time it's needed, must be attached to desired 248852217195SDaniel Vetter * connectors. 248952217195SDaniel Vetter * 249052217195SDaniel Vetter * Returns: 249152217195SDaniel Vetter * Zero on success, negative errno on failure. 249252217195SDaniel Vetter */ 249352217195SDaniel Vetter int drm_mode_create_content_type_property(struct drm_device *dev) 249452217195SDaniel Vetter { 249552217195SDaniel Vetter if (dev->mode_config.content_type_property) 249697e14fbeSDaniel Vetter return 0; 249752217195SDaniel Vetter 249852217195SDaniel Vetter dev->mode_config.content_type_property = 249952217195SDaniel Vetter drm_property_create_enum(dev, 0, "content type", 250052217195SDaniel Vetter drm_content_type_enum_list, 250152217195SDaniel Vetter ARRAY_SIZE(drm_content_type_enum_list)); 250252217195SDaniel Vetter 250352217195SDaniel Vetter if (dev->mode_config.content_type_property == NULL) 250452217195SDaniel Vetter return -ENOMEM; 250552217195SDaniel Vetter 250652217195SDaniel Vetter return 0; 250752217195SDaniel Vetter } 250852217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_content_type_property); 250952217195SDaniel Vetter 251052217195SDaniel Vetter /** 251152217195SDaniel Vetter * drm_mode_create_suggested_offset_properties - create suggests offset properties 251252217195SDaniel Vetter * @dev: DRM device 251352217195SDaniel Vetter * 251484e543bcSAntonio Borneo * Create the suggested x/y offset property for connectors. 2515f85d9e59SRandy Dunlap * 2516f85d9e59SRandy Dunlap * Returns: 2517f85d9e59SRandy Dunlap * 0 on success or a negative error code on failure. 251852217195SDaniel Vetter */ 251952217195SDaniel Vetter int drm_mode_create_suggested_offset_properties(struct drm_device *dev) 252052217195SDaniel Vetter { 252152217195SDaniel Vetter if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property) 252252217195SDaniel Vetter return 0; 252352217195SDaniel Vetter 252452217195SDaniel Vetter dev->mode_config.suggested_x_property = 252552217195SDaniel Vetter drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff); 252652217195SDaniel Vetter 252752217195SDaniel Vetter dev->mode_config.suggested_y_property = 252852217195SDaniel Vetter drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff); 252952217195SDaniel Vetter 253052217195SDaniel Vetter if (dev->mode_config.suggested_x_property == NULL || 253152217195SDaniel Vetter dev->mode_config.suggested_y_property == NULL) 253252217195SDaniel Vetter return -ENOMEM; 253352217195SDaniel Vetter return 0; 253452217195SDaniel Vetter } 253552217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties); 253652217195SDaniel Vetter 253752217195SDaniel Vetter /** 253852217195SDaniel Vetter * drm_connector_set_path_property - set tile property on connector 253952217195SDaniel Vetter * @connector: connector to set property on. 254052217195SDaniel Vetter * @path: path to use for property; must not be NULL. 254152217195SDaniel Vetter * 254252217195SDaniel Vetter * This creates a property to expose to userspace to specify a 254352217195SDaniel Vetter * connector path. This is mainly used for DisplayPort MST where 254452217195SDaniel Vetter * connectors have a topology and we want to allow userspace to give 254552217195SDaniel Vetter * them more meaningful names. 254652217195SDaniel Vetter * 254752217195SDaniel Vetter * Returns: 254852217195SDaniel Vetter * Zero on success, negative errno on failure. 254952217195SDaniel Vetter */ 255052217195SDaniel Vetter int drm_connector_set_path_property(struct drm_connector *connector, 255152217195SDaniel Vetter const char *path) 255252217195SDaniel Vetter { 255352217195SDaniel Vetter struct drm_device *dev = connector->dev; 255452217195SDaniel Vetter int ret; 255552217195SDaniel Vetter 255652217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 255752217195SDaniel Vetter &connector->path_blob_ptr, 255852217195SDaniel Vetter strlen(path) + 1, 255952217195SDaniel Vetter path, 256052217195SDaniel Vetter &connector->base, 256152217195SDaniel Vetter dev->mode_config.path_property); 256252217195SDaniel Vetter return ret; 256352217195SDaniel Vetter } 256452217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_set_path_property); 256552217195SDaniel Vetter 256652217195SDaniel Vetter /** 256752217195SDaniel Vetter * drm_connector_set_tile_property - set tile property on connector 256852217195SDaniel Vetter * @connector: connector to set property on. 256952217195SDaniel Vetter * 257052217195SDaniel Vetter * This looks up the tile information for a connector, and creates a 257152217195SDaniel Vetter * property for userspace to parse if it exists. The property is of 257252217195SDaniel Vetter * the form of 8 integers using ':' as a separator. 25732de3a078SManasi Navare * This is used for dual port tiled displays with DisplayPort SST 25742de3a078SManasi Navare * or DisplayPort MST connectors. 257552217195SDaniel Vetter * 257652217195SDaniel Vetter * Returns: 257752217195SDaniel Vetter * Zero on success, errno on failure. 257852217195SDaniel Vetter */ 257952217195SDaniel Vetter int drm_connector_set_tile_property(struct drm_connector *connector) 258052217195SDaniel Vetter { 258152217195SDaniel Vetter struct drm_device *dev = connector->dev; 258252217195SDaniel Vetter char tile[256]; 258352217195SDaniel Vetter int ret; 258452217195SDaniel Vetter 258552217195SDaniel Vetter if (!connector->has_tile) { 258652217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 258752217195SDaniel Vetter &connector->tile_blob_ptr, 258852217195SDaniel Vetter 0, 258952217195SDaniel Vetter NULL, 259052217195SDaniel Vetter &connector->base, 259152217195SDaniel Vetter dev->mode_config.tile_property); 259252217195SDaniel Vetter return ret; 259352217195SDaniel Vetter } 259452217195SDaniel Vetter 259552217195SDaniel Vetter snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d", 259652217195SDaniel Vetter connector->tile_group->id, connector->tile_is_single_monitor, 259752217195SDaniel Vetter connector->num_h_tile, connector->num_v_tile, 259852217195SDaniel Vetter connector->tile_h_loc, connector->tile_v_loc, 259952217195SDaniel Vetter connector->tile_h_size, connector->tile_v_size); 260052217195SDaniel Vetter 260152217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 260252217195SDaniel Vetter &connector->tile_blob_ptr, 260352217195SDaniel Vetter strlen(tile) + 1, 260452217195SDaniel Vetter tile, 260552217195SDaniel Vetter &connector->base, 260652217195SDaniel Vetter dev->mode_config.tile_property); 260752217195SDaniel Vetter return ret; 260852217195SDaniel Vetter } 260997e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_tile_property); 261052217195SDaniel Vetter 261152217195SDaniel Vetter /** 261297e14fbeSDaniel Vetter * drm_connector_set_link_status_property - Set link status property of a connector 261340ee6fbeSManasi Navare * @connector: drm connector 261440ee6fbeSManasi Navare * @link_status: new value of link status property (0: Good, 1: Bad) 261540ee6fbeSManasi Navare * 261640ee6fbeSManasi Navare * In usual working scenario, this link status property will always be set to 261740ee6fbeSManasi Navare * "GOOD". If something fails during or after a mode set, the kernel driver 261840ee6fbeSManasi Navare * may set this link status property to "BAD". The caller then needs to send a 261940ee6fbeSManasi Navare * hotplug uevent for userspace to re-check the valid modes through 262040ee6fbeSManasi Navare * GET_CONNECTOR_IOCTL and retry modeset. 262140ee6fbeSManasi Navare * 262240ee6fbeSManasi Navare * Note: Drivers cannot rely on userspace to support this property and 262340ee6fbeSManasi Navare * issue a modeset. As such, they may choose to handle issues (like 262440ee6fbeSManasi Navare * re-training a link) without userspace's intervention. 262540ee6fbeSManasi Navare * 262640ee6fbeSManasi Navare * The reason for adding this property is to handle link training failures, but 262740ee6fbeSManasi Navare * it is not limited to DP or link training. For example, if we implement 262840ee6fbeSManasi Navare * asynchronous setcrtc, this property can be used to report any failures in that. 262940ee6fbeSManasi Navare */ 263097e14fbeSDaniel Vetter void drm_connector_set_link_status_property(struct drm_connector *connector, 263140ee6fbeSManasi Navare uint64_t link_status) 263240ee6fbeSManasi Navare { 263340ee6fbeSManasi Navare struct drm_device *dev = connector->dev; 263440ee6fbeSManasi Navare 263540ee6fbeSManasi Navare drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 263640ee6fbeSManasi Navare connector->state->link_status = link_status; 263740ee6fbeSManasi Navare drm_modeset_unlock(&dev->mode_config.connection_mutex); 263840ee6fbeSManasi Navare } 263997e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_link_status_property); 264040ee6fbeSManasi Navare 26418d70f395SHans de Goede /** 264247e22ff1SRadhakrishna Sripada * drm_connector_attach_max_bpc_property - attach "max bpc" property 264347e22ff1SRadhakrishna Sripada * @connector: connector to attach max bpc property on. 264447e22ff1SRadhakrishna Sripada * @min: The minimum bit depth supported by the connector. 264547e22ff1SRadhakrishna Sripada * @max: The maximum bit depth supported by the connector. 264647e22ff1SRadhakrishna Sripada * 264747e22ff1SRadhakrishna Sripada * This is used to add support for limiting the bit depth on a connector. 264847e22ff1SRadhakrishna Sripada * 264947e22ff1SRadhakrishna Sripada * Returns: 265047e22ff1SRadhakrishna Sripada * Zero on success, negative errno on failure. 265147e22ff1SRadhakrishna Sripada */ 265247e22ff1SRadhakrishna Sripada int drm_connector_attach_max_bpc_property(struct drm_connector *connector, 265347e22ff1SRadhakrishna Sripada int min, int max) 265447e22ff1SRadhakrishna Sripada { 265547e22ff1SRadhakrishna Sripada struct drm_device *dev = connector->dev; 265647e22ff1SRadhakrishna Sripada struct drm_property *prop; 265747e22ff1SRadhakrishna Sripada 265847e22ff1SRadhakrishna Sripada prop = connector->max_bpc_property; 265947e22ff1SRadhakrishna Sripada if (!prop) { 266047e22ff1SRadhakrishna Sripada prop = drm_property_create_range(dev, 0, "max bpc", min, max); 266147e22ff1SRadhakrishna Sripada if (!prop) 266247e22ff1SRadhakrishna Sripada return -ENOMEM; 266347e22ff1SRadhakrishna Sripada 266447e22ff1SRadhakrishna Sripada connector->max_bpc_property = prop; 266547e22ff1SRadhakrishna Sripada } 266647e22ff1SRadhakrishna Sripada 266747e22ff1SRadhakrishna Sripada drm_object_attach_property(&connector->base, prop, max); 266847e22ff1SRadhakrishna Sripada connector->state->max_requested_bpc = max; 266947e22ff1SRadhakrishna Sripada connector->state->max_bpc = max; 267047e22ff1SRadhakrishna Sripada 267147e22ff1SRadhakrishna Sripada return 0; 267247e22ff1SRadhakrishna Sripada } 267347e22ff1SRadhakrishna Sripada EXPORT_SYMBOL(drm_connector_attach_max_bpc_property); 267447e22ff1SRadhakrishna Sripada 267547e22ff1SRadhakrishna Sripada /** 2676e057b52cSMaxime Ripard * drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADA" property 2677e057b52cSMaxime Ripard * @connector: connector to attach the property on. 2678e057b52cSMaxime Ripard * 2679e057b52cSMaxime Ripard * This is used to allow the userspace to send HDR Metadata to the 2680e057b52cSMaxime Ripard * driver. 2681e057b52cSMaxime Ripard * 2682e057b52cSMaxime Ripard * Returns: 2683e057b52cSMaxime Ripard * Zero on success, negative errno on failure. 2684e057b52cSMaxime Ripard */ 2685e057b52cSMaxime Ripard int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector) 2686e057b52cSMaxime Ripard { 2687e057b52cSMaxime Ripard struct drm_device *dev = connector->dev; 2688e057b52cSMaxime Ripard struct drm_property *prop = dev->mode_config.hdr_output_metadata_property; 2689e057b52cSMaxime Ripard 2690e057b52cSMaxime Ripard drm_object_attach_property(&connector->base, prop, 0); 2691e057b52cSMaxime Ripard 2692e057b52cSMaxime Ripard return 0; 2693e057b52cSMaxime Ripard } 2694e057b52cSMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property); 2695e057b52cSMaxime Ripard 2696e057b52cSMaxime Ripard /** 2697ab52af4bSMaxime Ripard * drm_connector_attach_broadcast_rgb_property - attach "Broadcast RGB" property 2698ab52af4bSMaxime Ripard * @connector: connector to attach the property on. 2699ab52af4bSMaxime Ripard * 2700ab52af4bSMaxime Ripard * This is used to add support for forcing the RGB range on a connector 2701ab52af4bSMaxime Ripard * 2702ab52af4bSMaxime Ripard * Returns: 2703ab52af4bSMaxime Ripard * Zero on success, negative errno on failure. 2704ab52af4bSMaxime Ripard */ 2705ab52af4bSMaxime Ripard int drm_connector_attach_broadcast_rgb_property(struct drm_connector *connector) 2706ab52af4bSMaxime Ripard { 2707ab52af4bSMaxime Ripard struct drm_device *dev = connector->dev; 2708ab52af4bSMaxime Ripard struct drm_property *prop; 2709ab52af4bSMaxime Ripard 2710ab52af4bSMaxime Ripard prop = connector->broadcast_rgb_property; 2711ab52af4bSMaxime Ripard if (!prop) { 2712ab52af4bSMaxime Ripard prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, 2713ab52af4bSMaxime Ripard "Broadcast RGB", 2714ab52af4bSMaxime Ripard broadcast_rgb_names, 2715ab52af4bSMaxime Ripard ARRAY_SIZE(broadcast_rgb_names)); 2716ab52af4bSMaxime Ripard if (!prop) 2717ab52af4bSMaxime Ripard return -EINVAL; 2718ab52af4bSMaxime Ripard 2719ab52af4bSMaxime Ripard connector->broadcast_rgb_property = prop; 2720ab52af4bSMaxime Ripard } 2721ab52af4bSMaxime Ripard 2722ab52af4bSMaxime Ripard drm_object_attach_property(&connector->base, prop, 2723ab52af4bSMaxime Ripard DRM_HDMI_BROADCAST_RGB_AUTO); 2724ab52af4bSMaxime Ripard 2725ab52af4bSMaxime Ripard return 0; 2726ab52af4bSMaxime Ripard } 2727ab52af4bSMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_broadcast_rgb_property); 2728ab52af4bSMaxime Ripard 2729ab52af4bSMaxime Ripard /** 273021f79128SMaxime Ripard * drm_connector_attach_colorspace_property - attach "Colorspace" property 273121f79128SMaxime Ripard * @connector: connector to attach the property on. 273221f79128SMaxime Ripard * 273321f79128SMaxime Ripard * This is used to allow the userspace to signal the output colorspace 273421f79128SMaxime Ripard * to the driver. 273521f79128SMaxime Ripard * 273621f79128SMaxime Ripard * Returns: 273721f79128SMaxime Ripard * Zero on success, negative errno on failure. 273821f79128SMaxime Ripard */ 273921f79128SMaxime Ripard int drm_connector_attach_colorspace_property(struct drm_connector *connector) 274021f79128SMaxime Ripard { 274121f79128SMaxime Ripard struct drm_property *prop = connector->colorspace_property; 274221f79128SMaxime Ripard 274321f79128SMaxime Ripard drm_object_attach_property(&connector->base, prop, DRM_MODE_COLORIMETRY_DEFAULT); 274421f79128SMaxime Ripard 274521f79128SMaxime Ripard return 0; 274621f79128SMaxime Ripard } 274721f79128SMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_colorspace_property); 274821f79128SMaxime Ripard 274921f79128SMaxime Ripard /** 275072921cdfSMaxime Ripard * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed 275172921cdfSMaxime Ripard * @old_state: old connector state to compare 275272921cdfSMaxime Ripard * @new_state: new connector state to compare 275372921cdfSMaxime Ripard * 275472921cdfSMaxime Ripard * This is used by HDR-enabled drivers to test whether the HDR metadata 275572921cdfSMaxime Ripard * have changed between two different connector state (and thus probably 275672921cdfSMaxime Ripard * requires a full blown mode change). 275772921cdfSMaxime Ripard * 275872921cdfSMaxime Ripard * Returns: 275972921cdfSMaxime Ripard * True if the metadata are equal, False otherwise 276072921cdfSMaxime Ripard */ 276172921cdfSMaxime Ripard bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state, 276272921cdfSMaxime Ripard struct drm_connector_state *new_state) 276372921cdfSMaxime Ripard { 276472921cdfSMaxime Ripard struct drm_property_blob *old_blob = old_state->hdr_output_metadata; 276572921cdfSMaxime Ripard struct drm_property_blob *new_blob = new_state->hdr_output_metadata; 276672921cdfSMaxime Ripard 276772921cdfSMaxime Ripard if (!old_blob || !new_blob) 276872921cdfSMaxime Ripard return old_blob == new_blob; 276972921cdfSMaxime Ripard 277072921cdfSMaxime Ripard if (old_blob->length != new_blob->length) 277172921cdfSMaxime Ripard return false; 277272921cdfSMaxime Ripard 277372921cdfSMaxime Ripard return !memcmp(old_blob->data, new_blob->data, old_blob->length); 277472921cdfSMaxime Ripard } 277572921cdfSMaxime Ripard EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal); 277672921cdfSMaxime Ripard 277772921cdfSMaxime Ripard /** 2778ba1b0f6cSNicholas Kazlauskas * drm_connector_set_vrr_capable_property - sets the variable refresh rate 2779ba1b0f6cSNicholas Kazlauskas * capable property for a connector 2780ba1b0f6cSNicholas Kazlauskas * @connector: drm connector 2781ba1b0f6cSNicholas Kazlauskas * @capable: True if the connector is variable refresh rate capable 2782ba1b0f6cSNicholas Kazlauskas * 2783ba1b0f6cSNicholas Kazlauskas * Should be used by atomic drivers to update the indicated support for 2784ba1b0f6cSNicholas Kazlauskas * variable refresh rate over a connector. 2785ba1b0f6cSNicholas Kazlauskas */ 2786ba1b0f6cSNicholas Kazlauskas void drm_connector_set_vrr_capable_property( 2787ba1b0f6cSNicholas Kazlauskas struct drm_connector *connector, bool capable) 2788ba1b0f6cSNicholas Kazlauskas { 278962929726SManasi Navare if (!connector->vrr_capable_property) 279062929726SManasi Navare return; 279162929726SManasi Navare 2792ba1b0f6cSNicholas Kazlauskas drm_object_property_set_value(&connector->base, 2793ba1b0f6cSNicholas Kazlauskas connector->vrr_capable_property, 2794ba1b0f6cSNicholas Kazlauskas capable); 2795ba1b0f6cSNicholas Kazlauskas } 2796ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_set_vrr_capable_property); 2797ba1b0f6cSNicholas Kazlauskas 2798ba1b0f6cSNicholas Kazlauskas /** 279984e543bcSAntonio Borneo * drm_connector_set_panel_orientation - sets the connector's panel_orientation 280069654c63SDerek Basehore * @connector: connector for which to set the panel-orientation property. 280169654c63SDerek Basehore * @panel_orientation: drm_panel_orientation value to set 28028d70f395SHans de Goede * 280369654c63SDerek Basehore * This function sets the connector's panel_orientation and attaches 280469654c63SDerek Basehore * a "panel orientation" property to the connector. 28058d70f395SHans de Goede * 280669654c63SDerek Basehore * Calling this function on a connector where the panel_orientation has 280769654c63SDerek Basehore * already been set is a no-op (e.g. the orientation has been overridden with 280869654c63SDerek Basehore * a kernel commandline option). 280969654c63SDerek Basehore * 281069654c63SDerek Basehore * It is allowed to call this function with a panel_orientation of 281169654c63SDerek Basehore * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op. 28128d70f395SHans de Goede * 28135e41b01aSHsin-Yi Wang * The function shouldn't be called in panel after drm is registered (i.e. 28145e41b01aSHsin-Yi Wang * drm_dev_register() is called in drm). 28155e41b01aSHsin-Yi Wang * 28168d70f395SHans de Goede * Returns: 28178d70f395SHans de Goede * Zero on success, negative errno on failure. 28188d70f395SHans de Goede */ 281969654c63SDerek Basehore int drm_connector_set_panel_orientation( 282069654c63SDerek Basehore struct drm_connector *connector, 282169654c63SDerek Basehore enum drm_panel_orientation panel_orientation) 28228d70f395SHans de Goede { 28238d70f395SHans de Goede struct drm_device *dev = connector->dev; 28248d70f395SHans de Goede struct drm_display_info *info = &connector->display_info; 28258d70f395SHans de Goede struct drm_property *prop; 28268d70f395SHans de Goede 282769654c63SDerek Basehore /* Already set? */ 282869654c63SDerek Basehore if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 28298d70f395SHans de Goede return 0; 28308d70f395SHans de Goede 283169654c63SDerek Basehore /* Don't attach the property if the orientation is unknown */ 283269654c63SDerek Basehore if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 283369654c63SDerek Basehore return 0; 283469654c63SDerek Basehore 283569654c63SDerek Basehore info->panel_orientation = panel_orientation; 283669654c63SDerek Basehore 28378d70f395SHans de Goede prop = dev->mode_config.panel_orientation_property; 28388d70f395SHans de Goede if (!prop) { 28398d70f395SHans de Goede prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 28408d70f395SHans de Goede "panel orientation", 28418d70f395SHans de Goede drm_panel_orientation_enum_list, 28428d70f395SHans de Goede ARRAY_SIZE(drm_panel_orientation_enum_list)); 28438d70f395SHans de Goede if (!prop) 28448d70f395SHans de Goede return -ENOMEM; 28458d70f395SHans de Goede 28468d70f395SHans de Goede dev->mode_config.panel_orientation_property = prop; 28478d70f395SHans de Goede } 28488d70f395SHans de Goede 28498d70f395SHans de Goede drm_object_attach_property(&connector->base, prop, 28508d70f395SHans de Goede info->panel_orientation); 28518d70f395SHans de Goede return 0; 28528d70f395SHans de Goede } 285369654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation); 285469654c63SDerek Basehore 285569654c63SDerek Basehore /** 2856f85d9e59SRandy Dunlap * drm_connector_set_panel_orientation_with_quirk - set the 2857f85d9e59SRandy Dunlap * connector's panel_orientation after checking for quirks 285869654c63SDerek Basehore * @connector: connector for which to init the panel-orientation property. 285969654c63SDerek Basehore * @panel_orientation: drm_panel_orientation value to set 286069654c63SDerek Basehore * @width: width in pixels of the panel, used for panel quirk detection 286169654c63SDerek Basehore * @height: height in pixels of the panel, used for panel quirk detection 286269654c63SDerek Basehore * 286369654c63SDerek Basehore * Like drm_connector_set_panel_orientation(), but with a check for platform 286469654c63SDerek Basehore * specific (e.g. DMI based) quirks overriding the passed in panel_orientation. 286569654c63SDerek Basehore * 286669654c63SDerek Basehore * Returns: 286769654c63SDerek Basehore * Zero on success, negative errno on failure. 286869654c63SDerek Basehore */ 286969654c63SDerek Basehore int drm_connector_set_panel_orientation_with_quirk( 287069654c63SDerek Basehore struct drm_connector *connector, 287169654c63SDerek Basehore enum drm_panel_orientation panel_orientation, 287269654c63SDerek Basehore int width, int height) 287369654c63SDerek Basehore { 287469654c63SDerek Basehore int orientation_quirk; 287569654c63SDerek Basehore 287669654c63SDerek Basehore orientation_quirk = drm_get_panel_orientation_quirk(width, height); 287769654c63SDerek Basehore if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 287869654c63SDerek Basehore panel_orientation = orientation_quirk; 287969654c63SDerek Basehore 288069654c63SDerek Basehore return drm_connector_set_panel_orientation(connector, 288169654c63SDerek Basehore panel_orientation); 288269654c63SDerek Basehore } 288369654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk); 28848d70f395SHans de Goede 28855e41b01aSHsin-Yi Wang /** 28865e41b01aSHsin-Yi Wang * drm_connector_set_orientation_from_panel - 28875e41b01aSHsin-Yi Wang * set the connector's panel_orientation from panel's callback. 28885e41b01aSHsin-Yi Wang * @connector: connector for which to init the panel-orientation property. 28895e41b01aSHsin-Yi Wang * @panel: panel that can provide orientation information. 28905e41b01aSHsin-Yi Wang * 28915e41b01aSHsin-Yi Wang * Drm drivers should call this function before drm_dev_register(). 28925e41b01aSHsin-Yi Wang * Orientation is obtained from panel's .get_orientation() callback. 28935e41b01aSHsin-Yi Wang * 28945e41b01aSHsin-Yi Wang * Returns: 28955e41b01aSHsin-Yi Wang * Zero on success, negative errno on failure. 28965e41b01aSHsin-Yi Wang */ 28975e41b01aSHsin-Yi Wang int drm_connector_set_orientation_from_panel( 28985e41b01aSHsin-Yi Wang struct drm_connector *connector, 28995e41b01aSHsin-Yi Wang struct drm_panel *panel) 29005e41b01aSHsin-Yi Wang { 29015e41b01aSHsin-Yi Wang enum drm_panel_orientation orientation; 29025e41b01aSHsin-Yi Wang 29035e41b01aSHsin-Yi Wang if (panel && panel->funcs && panel->funcs->get_orientation) 29045e41b01aSHsin-Yi Wang orientation = panel->funcs->get_orientation(panel); 29055e41b01aSHsin-Yi Wang else 29065e41b01aSHsin-Yi Wang orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 29075e41b01aSHsin-Yi Wang 29085e41b01aSHsin-Yi Wang return drm_connector_set_panel_orientation(connector, orientation); 29095e41b01aSHsin-Yi Wang } 29105e41b01aSHsin-Yi Wang EXPORT_SYMBOL(drm_connector_set_orientation_from_panel); 29115e41b01aSHsin-Yi Wang 2912107fe904SRajat Jain static const struct drm_prop_enum_list privacy_screen_enum[] = { 2913107fe904SRajat Jain { PRIVACY_SCREEN_DISABLED, "Disabled" }, 2914107fe904SRajat Jain { PRIVACY_SCREEN_ENABLED, "Enabled" }, 2915107fe904SRajat Jain { PRIVACY_SCREEN_DISABLED_LOCKED, "Disabled-locked" }, 2916107fe904SRajat Jain { PRIVACY_SCREEN_ENABLED_LOCKED, "Enabled-locked" }, 2917107fe904SRajat Jain }; 2918107fe904SRajat Jain 2919107fe904SRajat Jain /** 2920107fe904SRajat Jain * drm_connector_create_privacy_screen_properties - create the drm connecter's 2921107fe904SRajat Jain * privacy-screen properties. 2922107fe904SRajat Jain * @connector: connector for which to create the privacy-screen properties 2923107fe904SRajat Jain * 2924107fe904SRajat Jain * This function creates the "privacy-screen sw-state" and "privacy-screen 2925107fe904SRajat Jain * hw-state" properties for the connector. They are not attached. 2926107fe904SRajat Jain */ 2927107fe904SRajat Jain void 2928107fe904SRajat Jain drm_connector_create_privacy_screen_properties(struct drm_connector *connector) 2929107fe904SRajat Jain { 2930107fe904SRajat Jain if (connector->privacy_screen_sw_state_property) 2931107fe904SRajat Jain return; 2932107fe904SRajat Jain 2933107fe904SRajat Jain /* Note sw-state only supports the first 2 values of the enum */ 2934107fe904SRajat Jain connector->privacy_screen_sw_state_property = 2935107fe904SRajat Jain drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM, 2936107fe904SRajat Jain "privacy-screen sw-state", 2937107fe904SRajat Jain privacy_screen_enum, 2); 2938107fe904SRajat Jain 2939107fe904SRajat Jain connector->privacy_screen_hw_state_property = 2940107fe904SRajat Jain drm_property_create_enum(connector->dev, 2941107fe904SRajat Jain DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM, 2942107fe904SRajat Jain "privacy-screen hw-state", 2943107fe904SRajat Jain privacy_screen_enum, 2944107fe904SRajat Jain ARRAY_SIZE(privacy_screen_enum)); 2945107fe904SRajat Jain } 2946107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties); 2947107fe904SRajat Jain 2948107fe904SRajat Jain /** 2949107fe904SRajat Jain * drm_connector_attach_privacy_screen_properties - attach the drm connecter's 2950107fe904SRajat Jain * privacy-screen properties. 2951107fe904SRajat Jain * @connector: connector on which to attach the privacy-screen properties 2952107fe904SRajat Jain * 2953107fe904SRajat Jain * This function attaches the "privacy-screen sw-state" and "privacy-screen 2954107fe904SRajat Jain * hw-state" properties to the connector. The initial state of both is set 2955107fe904SRajat Jain * to "Disabled". 2956107fe904SRajat Jain */ 2957107fe904SRajat Jain void 2958107fe904SRajat Jain drm_connector_attach_privacy_screen_properties(struct drm_connector *connector) 2959107fe904SRajat Jain { 2960107fe904SRajat Jain if (!connector->privacy_screen_sw_state_property) 2961107fe904SRajat Jain return; 2962107fe904SRajat Jain 2963107fe904SRajat Jain drm_object_attach_property(&connector->base, 2964107fe904SRajat Jain connector->privacy_screen_sw_state_property, 2965107fe904SRajat Jain PRIVACY_SCREEN_DISABLED); 2966107fe904SRajat Jain 2967107fe904SRajat Jain drm_object_attach_property(&connector->base, 2968107fe904SRajat Jain connector->privacy_screen_hw_state_property, 2969107fe904SRajat Jain PRIVACY_SCREEN_DISABLED); 2970107fe904SRajat Jain } 2971107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties); 2972107fe904SRajat Jain 2973334f74eeSHans de Goede static void drm_connector_update_privacy_screen_properties( 2974334f74eeSHans de Goede struct drm_connector *connector, bool set_sw_state) 2975334f74eeSHans de Goede { 2976334f74eeSHans de Goede enum drm_privacy_screen_status sw_state, hw_state; 2977334f74eeSHans de Goede 2978334f74eeSHans de Goede drm_privacy_screen_get_state(connector->privacy_screen, 2979334f74eeSHans de Goede &sw_state, &hw_state); 2980334f74eeSHans de Goede 2981334f74eeSHans de Goede if (set_sw_state) 2982334f74eeSHans de Goede connector->state->privacy_screen_sw_state = sw_state; 2983334f74eeSHans de Goede drm_object_property_set_value(&connector->base, 2984334f74eeSHans de Goede connector->privacy_screen_hw_state_property, hw_state); 2985334f74eeSHans de Goede } 2986334f74eeSHans de Goede 2987334f74eeSHans de Goede static int drm_connector_privacy_screen_notifier( 2988334f74eeSHans de Goede struct notifier_block *nb, unsigned long action, void *data) 2989334f74eeSHans de Goede { 2990334f74eeSHans de Goede struct drm_connector *connector = 2991334f74eeSHans de Goede container_of(nb, struct drm_connector, privacy_screen_notifier); 2992334f74eeSHans de Goede struct drm_device *dev = connector->dev; 2993334f74eeSHans de Goede 2994334f74eeSHans de Goede drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 2995334f74eeSHans de Goede drm_connector_update_privacy_screen_properties(connector, true); 2996334f74eeSHans de Goede drm_modeset_unlock(&dev->mode_config.connection_mutex); 2997334f74eeSHans de Goede 29980cf8d292SSimon Ser drm_sysfs_connector_property_event(connector, 2999334f74eeSHans de Goede connector->privacy_screen_sw_state_property); 30000cf8d292SSimon Ser drm_sysfs_connector_property_event(connector, 3001334f74eeSHans de Goede connector->privacy_screen_hw_state_property); 3002334f74eeSHans de Goede 3003334f74eeSHans de Goede return NOTIFY_DONE; 3004334f74eeSHans de Goede } 3005334f74eeSHans de Goede 3006334f74eeSHans de Goede /** 3007334f74eeSHans de Goede * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to 3008334f74eeSHans de Goede * the connector 3009334f74eeSHans de Goede * @connector: connector to attach the privacy-screen to 3010334f74eeSHans de Goede * @priv: drm_privacy_screen to attach 3011334f74eeSHans de Goede * 3012334f74eeSHans de Goede * Create and attach the standard privacy-screen properties and register 3013334f74eeSHans de Goede * a generic notifier for generating sysfs-connector-status-events 3014334f74eeSHans de Goede * on external changes to the privacy-screen status. 3015334f74eeSHans de Goede * This function takes ownership of the passed in drm_privacy_screen and will 3016334f74eeSHans de Goede * call drm_privacy_screen_put() on it when the connector is destroyed. 3017334f74eeSHans de Goede */ 3018334f74eeSHans de Goede void drm_connector_attach_privacy_screen_provider( 3019334f74eeSHans de Goede struct drm_connector *connector, struct drm_privacy_screen *priv) 3020334f74eeSHans de Goede { 3021334f74eeSHans de Goede connector->privacy_screen = priv; 3022334f74eeSHans de Goede connector->privacy_screen_notifier.notifier_call = 3023334f74eeSHans de Goede drm_connector_privacy_screen_notifier; 3024334f74eeSHans de Goede 3025334f74eeSHans de Goede drm_connector_create_privacy_screen_properties(connector); 3026334f74eeSHans de Goede drm_connector_update_privacy_screen_properties(connector, true); 3027334f74eeSHans de Goede drm_connector_attach_privacy_screen_properties(connector); 3028334f74eeSHans de Goede } 3029334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider); 3030334f74eeSHans de Goede 3031334f74eeSHans de Goede /** 3032334f74eeSHans de Goede * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state 3033334f74eeSHans de Goede * @connector_state: connector-state to update the privacy-screen for 3034334f74eeSHans de Goede * 3035334f74eeSHans de Goede * This function calls drm_privacy_screen_set_sw_state() on the connector's 3036334f74eeSHans de Goede * privacy-screen. 3037334f74eeSHans de Goede * 3038334f74eeSHans de Goede * If the connector has no privacy-screen, then this is a no-op. 3039334f74eeSHans de Goede */ 3040334f74eeSHans de Goede void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state) 3041334f74eeSHans de Goede { 3042334f74eeSHans de Goede struct drm_connector *connector = connector_state->connector; 3043334f74eeSHans de Goede int ret; 3044334f74eeSHans de Goede 3045334f74eeSHans de Goede if (!connector->privacy_screen) 3046334f74eeSHans de Goede return; 3047334f74eeSHans de Goede 3048334f74eeSHans de Goede ret = drm_privacy_screen_set_sw_state(connector->privacy_screen, 3049334f74eeSHans de Goede connector_state->privacy_screen_sw_state); 3050334f74eeSHans de Goede if (ret) { 3051334f74eeSHans de Goede drm_err(connector->dev, "Error updating privacy-screen sw_state\n"); 3052334f74eeSHans de Goede return; 3053334f74eeSHans de Goede } 3054334f74eeSHans de Goede 3055334f74eeSHans de Goede /* The hw_state property value may have changed, update it. */ 3056334f74eeSHans de Goede drm_connector_update_privacy_screen_properties(connector, false); 3057334f74eeSHans de Goede } 3058334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_update_privacy_screen); 3059334f74eeSHans de Goede 306097e14fbeSDaniel Vetter int drm_connector_set_obj_prop(struct drm_mode_object *obj, 306152217195SDaniel Vetter struct drm_property *property, 306252217195SDaniel Vetter uint64_t value) 306352217195SDaniel Vetter { 306452217195SDaniel Vetter int ret = -EINVAL; 306552217195SDaniel Vetter struct drm_connector *connector = obj_to_connector(obj); 306652217195SDaniel Vetter 306752217195SDaniel Vetter /* Do DPMS ourselves */ 306852217195SDaniel Vetter if (property == connector->dev->mode_config.dpms_property) { 306952217195SDaniel Vetter ret = (*connector->funcs->dpms)(connector, (int)value); 307052217195SDaniel Vetter } else if (connector->funcs->set_property) 307152217195SDaniel Vetter ret = connector->funcs->set_property(connector, property, value); 307252217195SDaniel Vetter 3073144a7999SDaniel Vetter if (!ret) 307452217195SDaniel Vetter drm_object_property_set_value(&connector->base, property, value); 307552217195SDaniel Vetter return ret; 307652217195SDaniel Vetter } 307752217195SDaniel Vetter 307897e14fbeSDaniel Vetter int drm_connector_property_set_ioctl(struct drm_device *dev, 307952217195SDaniel Vetter void *data, struct drm_file *file_priv) 308052217195SDaniel Vetter { 308152217195SDaniel Vetter struct drm_mode_connector_set_property *conn_set_prop = data; 308252217195SDaniel Vetter struct drm_mode_obj_set_property obj_set_prop = { 308352217195SDaniel Vetter .value = conn_set_prop->value, 308452217195SDaniel Vetter .prop_id = conn_set_prop->prop_id, 308552217195SDaniel Vetter .obj_id = conn_set_prop->connector_id, 308652217195SDaniel Vetter .obj_type = DRM_MODE_OBJECT_CONNECTOR 308752217195SDaniel Vetter }; 308852217195SDaniel Vetter 308952217195SDaniel Vetter /* It does all the locking and checking we need */ 309052217195SDaniel Vetter return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv); 309152217195SDaniel Vetter } 309252217195SDaniel Vetter 309352217195SDaniel Vetter static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector) 309452217195SDaniel Vetter { 309552217195SDaniel Vetter /* For atomic drivers only state objects are synchronously updated and 3096c2ce66daSBeatriz Martins de Carvalho * protected by modeset locks, so check those first. 3097c2ce66daSBeatriz Martins de Carvalho */ 309852217195SDaniel Vetter if (connector->state) 309952217195SDaniel Vetter return connector->state->best_encoder; 310052217195SDaniel Vetter return connector->encoder; 310152217195SDaniel Vetter } 310252217195SDaniel Vetter 3103c3ff0cdbSAnkit Nautiyal static bool 3104c3ff0cdbSAnkit Nautiyal drm_mode_expose_to_userspace(const struct drm_display_mode *mode, 31058445e2c5SVille Syrjälä const struct list_head *modes, 310652217195SDaniel Vetter const struct drm_file *file_priv) 310752217195SDaniel Vetter { 310852217195SDaniel Vetter /* 310952217195SDaniel Vetter * If user-space hasn't configured the driver to expose the stereo 3D 311052217195SDaniel Vetter * modes, don't expose them. 311152217195SDaniel Vetter */ 311252217195SDaniel Vetter if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) 311352217195SDaniel Vetter return false; 3114c3ff0cdbSAnkit Nautiyal /* 3115c3ff0cdbSAnkit Nautiyal * If user-space hasn't configured the driver to expose the modes 3116c3ff0cdbSAnkit Nautiyal * with aspect-ratio, don't expose them. However if such a mode 3117c3ff0cdbSAnkit Nautiyal * is unique, let it be exposed, but reset the aspect-ratio flags 3118c3ff0cdbSAnkit Nautiyal * while preparing the list of user-modes. 3119c3ff0cdbSAnkit Nautiyal */ 3120c3ff0cdbSAnkit Nautiyal if (!file_priv->aspect_ratio_allowed) { 31218445e2c5SVille Syrjälä const struct drm_display_mode *mode_itr; 3122c3ff0cdbSAnkit Nautiyal 31238445e2c5SVille Syrjälä list_for_each_entry(mode_itr, modes, head) { 31248445e2c5SVille Syrjälä if (mode_itr->expose_to_userspace && 31258445e2c5SVille Syrjälä drm_mode_match(mode_itr, mode, 3126c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_TIMINGS | 3127c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_CLOCK | 3128c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_FLAGS | 3129c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_3D_FLAGS)) 3130c3ff0cdbSAnkit Nautiyal return false; 3131c3ff0cdbSAnkit Nautiyal } 31328445e2c5SVille Syrjälä } 313352217195SDaniel Vetter 313452217195SDaniel Vetter return true; 313552217195SDaniel Vetter } 313652217195SDaniel Vetter 313752217195SDaniel Vetter int drm_mode_getconnector(struct drm_device *dev, void *data, 313852217195SDaniel Vetter struct drm_file *file_priv) 313952217195SDaniel Vetter { 314052217195SDaniel Vetter struct drm_mode_get_connector *out_resp = data; 314152217195SDaniel Vetter struct drm_connector *connector; 314252217195SDaniel Vetter struct drm_encoder *encoder; 314352217195SDaniel Vetter struct drm_display_mode *mode; 314452217195SDaniel Vetter int mode_count = 0; 314552217195SDaniel Vetter int encoders_count = 0; 314652217195SDaniel Vetter int ret = 0; 314752217195SDaniel Vetter int copied = 0; 314852217195SDaniel Vetter struct drm_mode_modeinfo u_mode; 314952217195SDaniel Vetter struct drm_mode_modeinfo __user *mode_ptr; 315052217195SDaniel Vetter uint32_t __user *encoder_ptr; 3151869e76f7SDesmond Cheong Zhi Xi bool is_current_master; 315252217195SDaniel Vetter 315352217195SDaniel Vetter if (!drm_core_check_feature(dev, DRIVER_MODESET)) 315469fdf420SChris Wilson return -EOPNOTSUPP; 315552217195SDaniel Vetter 315652217195SDaniel Vetter memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); 315752217195SDaniel Vetter 3158418da172SKeith Packard connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id); 315991eefc05SDaniel Vetter if (!connector) 316091eefc05SDaniel Vetter return -ENOENT; 316152217195SDaniel Vetter 316262afb4adSJosé Roberto de Souza encoders_count = hweight32(connector->possible_encoders); 316391eefc05SDaniel Vetter 316491eefc05SDaniel Vetter if ((out_resp->count_encoders >= encoders_count) && encoders_count) { 316591eefc05SDaniel Vetter copied = 0; 316691eefc05SDaniel Vetter encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); 316783aefbb8SVille Syrjälä 316862afb4adSJosé Roberto de Souza drm_connector_for_each_possible_encoder(connector, encoder) { 316983aefbb8SVille Syrjälä if (put_user(encoder->base.id, encoder_ptr + copied)) { 317091eefc05SDaniel Vetter ret = -EFAULT; 3171e94ac351SDaniel Vetter goto out; 317291eefc05SDaniel Vetter } 317391eefc05SDaniel Vetter copied++; 317491eefc05SDaniel Vetter } 317591eefc05SDaniel Vetter } 317691eefc05SDaniel Vetter out_resp->count_encoders = encoders_count; 317791eefc05SDaniel Vetter 317891eefc05SDaniel Vetter out_resp->connector_id = connector->base.id; 317991eefc05SDaniel Vetter out_resp->connector_type = connector->connector_type; 318091eefc05SDaniel Vetter out_resp->connector_type_id = connector->connector_type_id; 318191eefc05SDaniel Vetter 3182869e76f7SDesmond Cheong Zhi Xi is_current_master = drm_is_current_master(file_priv); 3183869e76f7SDesmond Cheong Zhi Xi 318491eefc05SDaniel Vetter mutex_lock(&dev->mode_config.mutex); 318591eefc05SDaniel Vetter if (out_resp->count_modes == 0) { 3186869e76f7SDesmond Cheong Zhi Xi if (is_current_master) 318791eefc05SDaniel Vetter connector->funcs->fill_modes(connector, 318891eefc05SDaniel Vetter dev->mode_config.max_width, 318991eefc05SDaniel Vetter dev->mode_config.max_height); 31908f86c82aSSimon Ser else 31916897204eSDouglas Anderson drm_dbg_kms(dev, "User-space requested a forced probe on [CONNECTOR:%d:%s] but is not the DRM master, demoting to read-only probe\n", 31928f86c82aSSimon Ser connector->base.id, connector->name); 319391eefc05SDaniel Vetter } 319491eefc05SDaniel Vetter 319591eefc05SDaniel Vetter out_resp->mm_width = connector->display_info.width_mm; 319691eefc05SDaniel Vetter out_resp->mm_height = connector->display_info.height_mm; 319791eefc05SDaniel Vetter out_resp->subpixel = connector->display_info.subpixel_order; 319891eefc05SDaniel Vetter out_resp->connection = connector->status; 319991eefc05SDaniel Vetter 320091eefc05SDaniel Vetter /* delayed so we get modes regardless of pre-fill_modes state */ 32018445e2c5SVille Syrjälä list_for_each_entry(mode, &connector->modes, head) { 32028445e2c5SVille Syrjälä WARN_ON(mode->expose_to_userspace); 32038445e2c5SVille Syrjälä 32048445e2c5SVille Syrjälä if (drm_mode_expose_to_userspace(mode, &connector->modes, 3205c3ff0cdbSAnkit Nautiyal file_priv)) { 32068445e2c5SVille Syrjälä mode->expose_to_userspace = true; 320791eefc05SDaniel Vetter mode_count++; 3208c3ff0cdbSAnkit Nautiyal } 32098445e2c5SVille Syrjälä } 321091eefc05SDaniel Vetter 321152217195SDaniel Vetter /* 321252217195SDaniel Vetter * This ioctl is called twice, once to determine how much space is 321352217195SDaniel Vetter * needed, and the 2nd time to fill it. 321452217195SDaniel Vetter */ 321552217195SDaniel Vetter if ((out_resp->count_modes >= mode_count) && mode_count) { 321652217195SDaniel Vetter copied = 0; 321752217195SDaniel Vetter mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr; 32188445e2c5SVille Syrjälä list_for_each_entry(mode, &connector->modes, head) { 32198445e2c5SVille Syrjälä if (!mode->expose_to_userspace) 32208445e2c5SVille Syrjälä continue; 32218445e2c5SVille Syrjälä 32228445e2c5SVille Syrjälä /* Clear the tag for the next time around */ 32238445e2c5SVille Syrjälä mode->expose_to_userspace = false; 32248445e2c5SVille Syrjälä 322552217195SDaniel Vetter drm_mode_convert_to_umode(&u_mode, mode); 3226c3ff0cdbSAnkit Nautiyal /* 3227c3ff0cdbSAnkit Nautiyal * Reset aspect ratio flags of user-mode, if modes with 3228c3ff0cdbSAnkit Nautiyal * aspect-ratio are not supported. 3229c3ff0cdbSAnkit Nautiyal */ 3230c3ff0cdbSAnkit Nautiyal if (!file_priv->aspect_ratio_allowed) 3231c3ff0cdbSAnkit Nautiyal u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK; 323252217195SDaniel Vetter if (copy_to_user(mode_ptr + copied, 323352217195SDaniel Vetter &u_mode, sizeof(u_mode))) { 323452217195SDaniel Vetter ret = -EFAULT; 32358445e2c5SVille Syrjälä 32368445e2c5SVille Syrjälä /* 32378445e2c5SVille Syrjälä * Clear the tag for the rest of 32388445e2c5SVille Syrjälä * the modes for the next time around. 32398445e2c5SVille Syrjälä */ 32408445e2c5SVille Syrjälä list_for_each_entry_continue(mode, &connector->modes, head) 32418445e2c5SVille Syrjälä mode->expose_to_userspace = false; 32428445e2c5SVille Syrjälä 3243e94ac351SDaniel Vetter mutex_unlock(&dev->mode_config.mutex); 3244e94ac351SDaniel Vetter 324552217195SDaniel Vetter goto out; 324652217195SDaniel Vetter } 324752217195SDaniel Vetter copied++; 324852217195SDaniel Vetter } 32498445e2c5SVille Syrjälä } else { 32508445e2c5SVille Syrjälä /* Clear the tag for the next time around */ 32518445e2c5SVille Syrjälä list_for_each_entry(mode, &connector->modes, head) 32528445e2c5SVille Syrjälä mode->expose_to_userspace = false; 325352217195SDaniel Vetter } 32548445e2c5SVille Syrjälä 325552217195SDaniel Vetter out_resp->count_modes = mode_count; 325652217195SDaniel Vetter mutex_unlock(&dev->mode_config.mutex); 3257e94ac351SDaniel Vetter 3258e94ac351SDaniel Vetter drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 3259e94ac351SDaniel Vetter encoder = drm_connector_get_encoder(connector); 3260e94ac351SDaniel Vetter if (encoder) 3261e94ac351SDaniel Vetter out_resp->encoder_id = encoder->base.id; 3262e94ac351SDaniel Vetter else 3263e94ac351SDaniel Vetter out_resp->encoder_id = 0; 3264e94ac351SDaniel Vetter 3265e94ac351SDaniel Vetter /* Only grab properties after probing, to make sure EDID and other 3266c2ce66daSBeatriz Martins de Carvalho * properties reflect the latest status. 3267c2ce66daSBeatriz Martins de Carvalho */ 3268e94ac351SDaniel Vetter ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic, 3269e94ac351SDaniel Vetter (uint32_t __user *)(unsigned long)(out_resp->props_ptr), 3270e94ac351SDaniel Vetter (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr), 3271e94ac351SDaniel Vetter &out_resp->count_props); 3272e94ac351SDaniel Vetter drm_modeset_unlock(&dev->mode_config.connection_mutex); 3273e94ac351SDaniel Vetter 3274e94ac351SDaniel Vetter out: 3275ad093607SThierry Reding drm_connector_put(connector); 327652217195SDaniel Vetter 327752217195SDaniel Vetter return ret; 327852217195SDaniel Vetter } 327952217195SDaniel Vetter 32803d3f7c1eSHans de Goede /** 32813d3f7c1eSHans de Goede * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode 32823d3f7c1eSHans de Goede * @fwnode: fwnode for which to find the matching drm_connector 32833d3f7c1eSHans de Goede * 32843d3f7c1eSHans de Goede * This functions looks up a drm_connector based on its associated fwnode. When 32853d3f7c1eSHans de Goede * a connector is found a reference to the connector is returned. The caller must 32863d3f7c1eSHans de Goede * call drm_connector_put() to release this reference when it is done with the 32873d3f7c1eSHans de Goede * connector. 32883d3f7c1eSHans de Goede * 32893d3f7c1eSHans de Goede * Returns: A reference to the found connector or an ERR_PTR(). 32903d3f7c1eSHans de Goede */ 32913d3f7c1eSHans de Goede struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode) 32923d3f7c1eSHans de Goede { 32933d3f7c1eSHans de Goede struct drm_connector *connector, *found = ERR_PTR(-ENODEV); 32943d3f7c1eSHans de Goede 32953d3f7c1eSHans de Goede if (!fwnode) 32963d3f7c1eSHans de Goede return ERR_PTR(-ENODEV); 32973d3f7c1eSHans de Goede 32983d3f7c1eSHans de Goede mutex_lock(&connector_list_lock); 32993d3f7c1eSHans de Goede 33003d3f7c1eSHans de Goede list_for_each_entry(connector, &connector_list, global_connector_list_entry) { 33013d3f7c1eSHans de Goede if (connector->fwnode == fwnode || 33023d3f7c1eSHans de Goede (connector->fwnode && connector->fwnode->secondary == fwnode)) { 33033d3f7c1eSHans de Goede drm_connector_get(connector); 33043d3f7c1eSHans de Goede found = connector; 33053d3f7c1eSHans de Goede break; 33063d3f7c1eSHans de Goede } 33073d3f7c1eSHans de Goede } 33083d3f7c1eSHans de Goede 33093d3f7c1eSHans de Goede mutex_unlock(&connector_list_lock); 33103d3f7c1eSHans de Goede 33113d3f7c1eSHans de Goede return found; 33123d3f7c1eSHans de Goede } 33133d3f7c1eSHans de Goede 331472ad4968SHans de Goede /** 331572ad4968SHans de Goede * drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector 3316f85d9e59SRandy Dunlap * @connector_fwnode: fwnode_handle to report the event on 3317fc93835bSBjorn Andersson * @status: hot plug detect logical state 331872ad4968SHans de Goede * 331972ad4968SHans de Goede * On some hardware a hotplug event notification may come from outside the display 332072ad4968SHans de Goede * driver / device. An example of this is some USB Type-C setups where the hardware 332172ad4968SHans de Goede * muxes the DisplayPort data and aux-lines but does not pass the altmode HPD 332272ad4968SHans de Goede * status bit to the GPU's DP HPD pin. 332372ad4968SHans de Goede * 332472ad4968SHans de Goede * This function can be used to report these out-of-band events after obtaining 332572ad4968SHans de Goede * a drm_connector reference through calling drm_connector_find_by_fwnode(). 332672ad4968SHans de Goede */ 3327fc93835bSBjorn Andersson void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode, 3328fc93835bSBjorn Andersson enum drm_connector_status status) 332972ad4968SHans de Goede { 333072ad4968SHans de Goede struct drm_connector *connector; 333172ad4968SHans de Goede 333272ad4968SHans de Goede connector = drm_connector_find_by_fwnode(connector_fwnode); 333372ad4968SHans de Goede if (IS_ERR(connector)) 333472ad4968SHans de Goede return; 333572ad4968SHans de Goede 333672ad4968SHans de Goede if (connector->funcs->oob_hotplug_event) 3337fc93835bSBjorn Andersson connector->funcs->oob_hotplug_event(connector, status); 333872ad4968SHans de Goede 333972ad4968SHans de Goede drm_connector_put(connector); 334072ad4968SHans de Goede } 334172ad4968SHans de Goede EXPORT_SYMBOL(drm_connector_oob_hotplug_event); 334272ad4968SHans de Goede 33439498c19bSDaniel Vetter 33449498c19bSDaniel Vetter /** 33459498c19bSDaniel Vetter * DOC: Tile group 33469498c19bSDaniel Vetter * 33479498c19bSDaniel Vetter * Tile groups are used to represent tiled monitors with a unique integer 33489498c19bSDaniel Vetter * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle, 33499498c19bSDaniel Vetter * we store this in a tile group, so we have a common identifier for all tiles 33509498c19bSDaniel Vetter * in a monitor group. The property is called "TILE". Drivers can manage tile 33519498c19bSDaniel Vetter * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and 33529498c19bSDaniel Vetter * drm_mode_get_tile_group(). But this is only needed for internal panels where 33539498c19bSDaniel Vetter * the tile group information is exposed through a non-standard way. 33549498c19bSDaniel Vetter */ 33559498c19bSDaniel Vetter 33569498c19bSDaniel Vetter static void drm_tile_group_free(struct kref *kref) 33579498c19bSDaniel Vetter { 33589498c19bSDaniel Vetter struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); 33599498c19bSDaniel Vetter struct drm_device *dev = tg->dev; 3360948de842SSuraj Upadhyay 33619498c19bSDaniel Vetter mutex_lock(&dev->mode_config.idr_mutex); 33629498c19bSDaniel Vetter idr_remove(&dev->mode_config.tile_idr, tg->id); 33639498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 33649498c19bSDaniel Vetter kfree(tg); 33659498c19bSDaniel Vetter } 33669498c19bSDaniel Vetter 33679498c19bSDaniel Vetter /** 33689498c19bSDaniel Vetter * drm_mode_put_tile_group - drop a reference to a tile group. 33699498c19bSDaniel Vetter * @dev: DRM device 33709498c19bSDaniel Vetter * @tg: tile group to drop reference to. 33719498c19bSDaniel Vetter * 33729498c19bSDaniel Vetter * drop reference to tile group and free if 0. 33739498c19bSDaniel Vetter */ 33749498c19bSDaniel Vetter void drm_mode_put_tile_group(struct drm_device *dev, 33759498c19bSDaniel Vetter struct drm_tile_group *tg) 33769498c19bSDaniel Vetter { 33779498c19bSDaniel Vetter kref_put(&tg->refcount, drm_tile_group_free); 33789498c19bSDaniel Vetter } 33799498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_put_tile_group); 33809498c19bSDaniel Vetter 33819498c19bSDaniel Vetter /** 33829498c19bSDaniel Vetter * drm_mode_get_tile_group - get a reference to an existing tile group 33839498c19bSDaniel Vetter * @dev: DRM device 33849498c19bSDaniel Vetter * @topology: 8-bytes unique per monitor. 33859498c19bSDaniel Vetter * 33869498c19bSDaniel Vetter * Use the unique bytes to get a reference to an existing tile group. 33879498c19bSDaniel Vetter * 33889498c19bSDaniel Vetter * RETURNS: 33899498c19bSDaniel Vetter * tile group or NULL if not found. 33909498c19bSDaniel Vetter */ 33919498c19bSDaniel Vetter struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, 3392267ea759SVille Syrjälä const char topology[8]) 33939498c19bSDaniel Vetter { 33949498c19bSDaniel Vetter struct drm_tile_group *tg; 33959498c19bSDaniel Vetter int id; 3396948de842SSuraj Upadhyay 33979498c19bSDaniel Vetter mutex_lock(&dev->mode_config.idr_mutex); 33989498c19bSDaniel Vetter idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { 33999498c19bSDaniel Vetter if (!memcmp(tg->group_data, topology, 8)) { 34009498c19bSDaniel Vetter if (!kref_get_unless_zero(&tg->refcount)) 34019498c19bSDaniel Vetter tg = NULL; 34029498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 34039498c19bSDaniel Vetter return tg; 34049498c19bSDaniel Vetter } 34059498c19bSDaniel Vetter } 34069498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 34079498c19bSDaniel Vetter return NULL; 34089498c19bSDaniel Vetter } 34099498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_get_tile_group); 34109498c19bSDaniel Vetter 34119498c19bSDaniel Vetter /** 34129498c19bSDaniel Vetter * drm_mode_create_tile_group - create a tile group from a displayid description 34139498c19bSDaniel Vetter * @dev: DRM device 34149498c19bSDaniel Vetter * @topology: 8-bytes unique per monitor. 34159498c19bSDaniel Vetter * 34169498c19bSDaniel Vetter * Create a tile group for the unique monitor, and get a unique 34179498c19bSDaniel Vetter * identifier for the tile group. 34189498c19bSDaniel Vetter * 34199498c19bSDaniel Vetter * RETURNS: 3420705c8160SDan Carpenter * new tile group or NULL. 34219498c19bSDaniel Vetter */ 34229498c19bSDaniel Vetter struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, 3423267ea759SVille Syrjälä const char topology[8]) 34249498c19bSDaniel Vetter { 34259498c19bSDaniel Vetter struct drm_tile_group *tg; 34269498c19bSDaniel Vetter int ret; 34279498c19bSDaniel Vetter 34289498c19bSDaniel Vetter tg = kzalloc(sizeof(*tg), GFP_KERNEL); 34299498c19bSDaniel Vetter if (!tg) 3430705c8160SDan Carpenter return NULL; 34319498c19bSDaniel Vetter 34329498c19bSDaniel Vetter kref_init(&tg->refcount); 34339498c19bSDaniel Vetter memcpy(tg->group_data, topology, 8); 34349498c19bSDaniel Vetter tg->dev = dev; 34359498c19bSDaniel Vetter 34369498c19bSDaniel Vetter mutex_lock(&dev->mode_config.idr_mutex); 34379498c19bSDaniel Vetter ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL); 34389498c19bSDaniel Vetter if (ret >= 0) { 34399498c19bSDaniel Vetter tg->id = ret; 34409498c19bSDaniel Vetter } else { 34419498c19bSDaniel Vetter kfree(tg); 3442705c8160SDan Carpenter tg = NULL; 34439498c19bSDaniel Vetter } 34449498c19bSDaniel Vetter 34459498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 34469498c19bSDaniel Vetter return tg; 34479498c19bSDaniel Vetter } 34489498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tile_group); 3449